@payloadcms/richtext-lexical 4.0.0-beta.1 → 4.0.0-beta.2

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{b as Ie,c as $e,e as K,f as j,h as Fe,i as Ke,j as je,k as ze,l as Pe,m as Re,n as He}from"./chunk-3LRZDIIG.js";import{a as Be,b as R}from"./chunk-RJ5MAOKZ.js";import{jsx as v,jsxs as ce}from"react/jsx-runtime";import{getTranslation as bn}from"@payloadcms/translations";import{BulkUploadProvider as xn,FieldDescription as Cn,FieldError as En,FieldLabel as Nn,isFieldRTL as Sn,RenderCustomComponent as jt,useConfig as wn,useEditDepth as Pn,useEffectEvent as Rn,useField as Tn,useLocale as _n,useTranslation as Dn}from"@payloadcms/ui";import{mergeFieldStyles as kn}from"@payloadcms/ui/shared";import{dequal as vn}from"dequal/lite";import zt,{useCallback as Ht,useEffect as Vt,useMemo as Ln,useState as Wt}from"react";import{ErrorBoundary as An}from"react-error-boundary";import"../../field/bundled.css";import{jsx as H}from"react/jsx-runtime";import{LexicalComposer as cn}from"@lexical/react/LexicalComposer.js";import{useEditDepth as dn}from"@payloadcms/ui";import*as Bt from"react";import{useMemo as un}from"react";import{c as Wr}from"react/compiler-runtime";import{jsx as E,jsxs as ae}from"react/jsx-runtime";import{useLexicalComposerContext as Yr}from"@lexical/react/LexicalComposerContext.js";import{LexicalErrorBoundary as Gr}from"@lexical/react/LexicalErrorBoundary.js";import{HistoryPlugin as Ur}from"@lexical/react/LexicalHistoryPlugin.js";import{OnChangePlugin as qr}from"@lexical/react/LexicalOnChangePlugin.js";import{RichTextPlugin as Jr}from"@lexical/react/LexicalRichTextPlugin.js";import{useLexicalEditable as Qr}from"@lexical/react/useLexicalEditable";import{useTranslation as Xr}from"@payloadcms/ui";import{BLUR_COMMAND as Zr,COMMAND_PRIORITY_LOW as Mt,FOCUS_COMMAND as en}from"lexical";import*as z from"react";import{useEffect as tn,useState as on}from"react";import{jsx as Ve}from"react/jsx-runtime";import"react";var W=({anchorElem:e,clientProps:t,plugin:o})=>o.position==="floatingAnchorElem"&&e?o.Component&&Ve(o.Component,{anchorElem:e,clientProps:t}):o.Component&&Ve(o.Component,{clientProps:t});import{c as Ut}from"react/compiler-runtime";import{copyToClipboard as We}from"@lexical/clipboard";import{useLexicalComposerContext as qt}from"@lexical/react/LexicalComposerContext.js";import{objectKlassEquals as Jt}from"@lexical/utils";import Ye from"bson-objectid";import{$getSelection as Qt,$isNodeSelection as Xt,COMMAND_PRIORITY_LOW as Zt,COPY_COMMAND as eo}from"lexical";import{useEffect as to}from"react";var Te=e=>{if("fields"in e&&typeof e.fields=="object"&&e.fields!==null&&"id"in e.fields?e.fields.id=new Ye.default().toHexString():"id"in e&&(e.id=new Ye.default().toHexString()),e.children)for(let t of e.children)Te(t)};function Ge(){let e=Ut(3),[t]=qt(),o,r;return e[0]!==t?(o=()=>t.registerCommand(eo,n=>{let i=Qt();if(Xt(i)){let l=i.getNodes()[0]?.exportJSON(),d=JSON.parse(JSON.stringify(l));Te(d);let u={namespace:t._config.namespace,nodes:[d]},m=JSON.stringify(u);return We(t,null,{"application/x-lexical-editor":m,"text/plain":""}).catch(oo),!0}return We(t,Jt(n,ClipboardEvent)?n:null).then(()=>{if(!(n instanceof ClipboardEvent)||!n.clipboardData)throw new Error("No clipboard event");let s=n.clipboardData.getData("application/x-lexical-editor");if(!s)return!0;let l=JSON.parse(s);for(let u of l.nodes)Te(u);let d=JSON.stringify(l);n.clipboardData.setData("application/x-lexical-editor",d)}).catch(s=>{throw n instanceof ClipboardEvent&&n.clipboardData?.setData("application/x-lexical-editor",""),s}),!0},Zt),r=[t],e[0]=t,e[1]=o,e[2]=r):(o=e[1],r=e[2]),to(o,r),null}function oo(e){throw e}import{c as ro}from"react/compiler-runtime";import{useLexicalComposerContext as no}from"@lexical/react/LexicalComposerContext";import{$findMatchingParent as fe,mergeRegister as io}from"@lexical/utils";import{$createNodeSelection as so,$getEditor as me,$getNearestNodeFromDOMNode as lo,$getSelection as pe,$isDecoratorNode as Y,$isElementNode as _e,$isLineBreakNode as ao,$isNodeSelection as ge,$isRangeSelection as qe,$isRootOrShadowRoot as co,$isTextNode as uo,$onUpdate as fo,$setSelection as Je,CLICK_COMMAND as mo,COMMAND_PRIORITY_LOW as Q,KEY_ARROW_DOWN_COMMAND as po,KEY_ARROW_UP_COMMAND as go,KEY_BACKSPACE_COMMAND as ho,KEY_DELETE_COMMAND as yo,SELECTION_CHANGE_COMMAND as bo}from"lexical";import{useEffect as xo}from"react";function Qe(){let e=ro(3),[t]=no(),o=Po,r,n;return e[0]!==t?(r=()=>io(t.registerCommand(mo,wo,Q),t.registerCommand(yo,o,Q),t.registerCommand(ho,o,Q),t.registerCommand(bo,(i,s)=>{if(s!==t)return!1;let l=!!Ue();return fo(()=>{s.read("latest",()=>{let d=Ue();document.querySelector(".decorator-selected")?.classList.remove("decorator-selected"),d&&s.getElementByKey(d.getKey())?.classList.add("decorator-selected")})}),l},Q),t.registerCommand(go,No,Q),t.registerCommand(po,Co,Q)),n=[t],e[0]=t,e[1]=r,e[2]=n):(r=e[1],n=e[2]),xo(r,n),null}function Co(e){let t=pe();if(ge(t)){e.preventDefault();let s=t.getNodes()[0]?.getNextSibling();if(Y(s)){let u=me().getElementByKey(s.getKey());return u&&ie({element:u,node:s}),!0}if(!_e(s))return!0;let l=s.getFirstDescendant()??s;return l&&(fe(l,he)?.selectEnd(),e.preventDefault()),!0}if(!qe(t))return!1;let r=(t.isBackward()?t.anchor:t.focus).getNode(),n=fe(r,Eo),i=n?.getNextSibling();if(!n||i!==Xe(n))return!1;if(Y(i)){let s=me().getElementByKey(i.getKey());if(s)return ie({element:s,node:i}),e.preventDefault(),!0}return!1}function Eo(e){return Xe(e)!==null}function No(e){let t=pe();if(ge(t)){let s=t.getNodes()[0]?.getPreviousSibling();if(Y(s)){let u=me().getElementByKey(s.getKey());return u?(ie({element:u,node:s}),e.preventDefault(),!0):!1}if(!_e(s))return!1;let l=s.getLastDescendant()??s;return l?(fe(l,he)?.selectStart(),e.preventDefault(),!0):!1}if(!qe(t))return!1;let r=(t.isBackward()?t.anchor:t.focus).getNode(),n=fe(r,So),i=n?.getPreviousSibling();if(!n||i!==Ze(n))return!1;if(Y(i)){let s=me().getElementByKey(i.getKey());if(s)return ie({element:s,node:i}),e.preventDefault(),!0}return!1}function So(e){return Ze(e)!==null}function wo(e){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let t=To(e);if(!t)return!0;let{target:o}=e;return!(o instanceof HTMLElement)||o.isContentEditable||o.closest('button, textarea, input, .react-select, .code-editor, .no-select-decorator, [role="button"]')?Je(null):ie(t),!0}function Po(e){let t=pe();return ge(t)?(e.preventDefault(),t.getNodes().forEach(Ro),!0):!1}function Ro(e){e.remove()}function To(e){if(!(e.target instanceof HTMLElement))return;let t=e.target.closest('[data-lexical-decorator="true"]');if(!(t instanceof HTMLElement))return;let o=lo(t);return Y(o)?{element:t,node:o}:void 0}function Ue(){let e=pe();if(!ge(e))return;let t=e.getNodes();if(t.length!==1)return;let o=t[0];return Y(o)?o:void 0}function ie({element:e,node:t}){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let o=so();o.add(t.getKey()),Je(o),e.scrollIntoView({behavior:"smooth",block:"nearest"}),e.classList.add("decorator-selected")}function he(e){if(Y(e)&&!e.isInline())return!0;if(!_e(e)||co(e))return!1;let t=e.getFirstChild(),o=t===null||ao(t)||uo(t)||t.isInline();return!e.isInline()&&e.canBeEmpty()!==!1&&o}function Xe(e){let t=e.getNextSibling();for(;t!==null;){if(he(t))return t;t=t.getNextSibling()}return null}function Ze(e){let t=e.getPreviousSibling();for(;t!==null;){if(he(t))return t;t=t.getPreviousSibling()}return null}import{jsx as De}from"react/jsx-runtime";import{useLexicalComposerContext as Ao}from"@lexical/react/LexicalComposerContext.js";import{$createParagraphNode as Mo,isHTMLElement as Oo}from"lexical";import*as rt from"react";import{useCallback as Bo,useEffect as ot,useRef as Io,useState as $o}from"react";import{createPortal as Fo}from"react-dom";var X=(e,t,o,r,n=50,i=25)=>{let s=0;if(e&&!e.contains(r)){let{bottom:l,left:d,right:u,top:m}=e.getBoundingClientRect(),a=m+window.scrollY,c=l+window.scrollY;if(o<a-i||o>c+i||t<d-n||t>u+n)return-1;(t<d||t>u)&&(s=t<d?t-d:t-u)}return s};import{$getNodeByKey as be}from"lexical";function Z(e){let t=e.getBoundingClientRect(),o=getComputedStyle(e).getPropertyValue("transform");if(!o||o==="none")return t;let r=o.split(",").pop();return t.y=t.y-Number(r?.replace(")","")),t}function ye(e){let t=(d,u)=>d?parseFloat(window.getComputedStyle(d)[u]):0,{marginBottom:o,marginTop:r}=window.getComputedStyle(e),n=t(e.previousElementSibling,"marginBottom"),i=t(e.nextElementSibling,"marginTop"),s=Math.max(parseFloat(r),n);return{marginBottom:Math.max(parseFloat(o),i),marginTop:s}}import{$getRoot as _o}from"lexical";function G(e){return e.getEditorState().read(()=>_o().getChildrenKeys())}var Do=1,ko=-1,et=0,M={props:null,result:null};function vo(e,t,o=20){let r=e.x-t.x,n=e.y-t.y;return r*r+n*n<=o*o}function ee(e){let{anchorElem:t,cache_threshold:o=20,editor:r,fuzzy:n=!1,horizontalOffset:i=0,point:{x:s,y:l},startIndex:d=0,useEdgeAsDefault:u=!1}=e;if(o>0&&M.props&&M.result&&M.props.fuzzy===e.fuzzy&&M.props.horizontalOffset===e.horizontalOffset&&M.props.useEdgeAsDefault===e.useEdgeAsDefault&&vo(M.props.point,e.point,o))return M.result;let m=t.getBoundingClientRect(),a=G(r),c={blockElem:null,blockNode:null,distance:1/0,foundAtIndex:-1,isFoundNodeEmptyParagraph:!1};return r.getEditorState().read(()=>{if(u){let f=r.getElementByKey(a[0]),p=r.getElementByKey(a[a.length-1]);if(f&&p){let[h,C]=[Z(f),Z(p)];if(l<h.top?(c.blockElem=f,c.distance=h.top-l,c.blockNode=be(a[0]),c.foundAtIndex=0):l>C.bottom&&(c.distance=l-C.bottom,c.blockNode=be(a[a.length-1]),c.blockElem=p,c.foundAtIndex=a.length-1),c?.blockElem)return{blockElem:null,isFoundNodeEmptyParagraph:!1}}}let g=d,y=et;for(;g>=0&&g<a.length;){let f=a[g],p=r.getElementByKey(f);if(p===null)break;let h=new j(s+i,l),C=ze.fromDOMRect(Z(p)),{marginBottom:x,marginTop:N}=ye(p),b=C.generateNewRect({bottom:C.bottom+x,left:m.left,right:m.right,top:C.top-N}),{distance:S,isOnBottomSide:D,isOnTopSide:_}=b.distanceFromPoint(h);if(S===0){c.blockElem=p,c.blockNode=be(f),c.foundAtIndex=g,c.distance=S,c.blockNode&&c.blockNode.getType()==="paragraph"&&c.blockNode.getTextContent()===""&&(!n&&!e.returnEmptyParagraphs&&(c.blockElem=null,c.blockNode=null),c.isFoundNodeEmptyParagraph=!0);break}else n&&S<c.distance&&(c.blockElem=p,c.blockNode=be(f),c.distance=S,c.foundAtIndex=g);y===et&&(_?y=ko:D?y=Do:y=1/0),g+=y}}),M.props=e,M.result={blockElem:c.blockElem,blockNode:c.blockNode,foundAtIndex:c.foundAtIndex,isFoundNodeEmptyParagraph:c.isFoundNodeEmptyParagraph},{blockElem:c.blockElem,blockNode:c.blockNode,foundAtIndex:c.foundAtIndex,isFoundNodeEmptyParagraph:c.isFoundNodeEmptyParagraph}}function xe(e,t){return!!e.closest(`.${t}`)}var Lo=["IMG","INPUT","TEXTAREA","SELECT","BUTTON","VIDEO","OBJECT","EMBED","IFRAME","HR"];function tt(e){if(!e||Lo.includes(e.tagName)||e.offsetHeight===0||e.offsetWidth===0)return!1;let t=window.getComputedStyle(e);return!(t.display==="table-cell"||t.position==="absolute"||t.visibility==="hidden"||t.opacity==="0")}function Ce(e,t,o,r=0){if(!e){t.style.visibility="hidden",t.style.opacity="0",t.style.transform="translate(-10000px, -10000px)";return}let n=e.getBoundingClientRect(),i=window.getComputedStyle(e),s=t.getBoundingClientRect(),l=o.getBoundingClientRect(),d;if(["LexicalEditorTheme__block","LexicalEditorTheme__upload","LexicalEditorTheme__relationship"].some(a=>e.classList.contains(a)||e.firstElementChild?.classList.contains(a)))d=n.top+8-l.top;else{let a=tt(e)?parseInt(i.lineHeight,10):0;d=n.top+(a-s.height)/2-l.top}let m=r;t.style.opacity="1",t.style.visibility="visible",t.style.transform=`translate(${m}px, ${d}px)`}var Ko="add-block-menu",Ee=1/0;function jo(e){return e===0?1/0:Ee>=0&&Ee<e?Ee:Math.floor(e/2)}function zo(e,t,o){let r=t.parentElement,{editorConfig:n}=R(),i=n?.admin?.hideGutter?-24:12,s=Io(null),[l,d]=$o(null);ot(()=>{function m(a){let c=a.target;if(!Oo(c))return;let g=X(r,a.pageX,a.pageY,c);if(g===-1){d(null);return}if(xe(c,Ko))return;let y=G(e),{blockElem:f,blockNode:p,foundAtIndex:h}=ee({anchorElem:t,cache_threshold:0,editor:e,horizontalOffset:-g,point:new j(a.x,a.y),returnEmptyParagraphs:!0,startIndex:jo(y.length),useEdgeAsDefault:!1});Ee=h,f&&p&&(l?.node!==p||l?.elem!==f)&&d({elem:f,node:p})}return document?.addEventListener("mousemove",m),()=>{document?.removeEventListener("mousemove",m)}},[r,t,e,l]),ot(()=>{s.current&&Ce(l?.elem??null,s.current,t,i)},[t,l,i]);let u=Bo(m=>{let a=l;a?.node&&(e.update(()=>{let c=!0;if((a?.node.getType()!=="paragraph"||a.node.getTextContent()!=="")&&(c=!1),!c){let g=Mo();a?.node.insertAfter(g),setTimeout(()=>{a={elem:e.getElementByKey(g.getKey()),node:g},d(a)},0)}}),setTimeout(()=>{e.update(()=>{e.focus(),a?.node&&"select"in a.node&&typeof a.node.select=="function"&&a.node.select()})},1),setTimeout(()=>{e.dispatchCommand(Ke,{node:a?.node})},2),m.stopPropagation(),m.preventDefault())},[e,l]);return Fo(De(rt.Fragment,{children:De("button",{"aria-label":"Add block",className:"icon add-block-menu",onClick:m=>{u(m)},ref:s,type:"button",children:De("div",{className:o?"icon":""})})}),t)}function nt(e){let{anchorElem:t}=e,o=t===void 0?document.body:t,[r]=Ao();return zo(r,o,r._editable)}import{jsx as Ne,jsxs as dt}from"react/jsx-runtime";import{useLexicalComposerContext as Jo}from"@lexical/react/LexicalComposerContext.js";import{eventFiles as ut}from"@lexical/rich-text";import{useTranslation as Qo}from"@payloadcms/ui";import{$getNearestNodeFromDOMNode as ft,$getNodeByKey as Xo,isHTMLElement as ke}from"lexical";import*as yt from"react";import{useEffect as ve,useId as Zo,useRef as se,useState as mt}from"react";import{createPortal as er}from"react-dom";var it=0,Ho=-24;var U=0;function st(e,t,o,r,n,i,s,l,d,u=!1){let{height:m,top:a}=r.getBoundingClientRect(),{top:c,width:g}=s.getBoundingClientRect(),{marginBottom:y,marginTop:f}=ye(r),p=a,h=i>=a+m/2+window.scrollY,C=!1;if(n?.elem)if(r!==n?.elem)(h&&n?.elem&&n?.elem===r.nextElementSibling||!h&&n?.elem&&n?.elem===r.previousElementSibling)&&(U++,U<200&&(C=!0));else{U++;let S=n?.boundingBox?.y,D=r.getBoundingClientRect().y;(h===n?.isBelow&&S===D||U<200)&&(C=!1)}if(C)return{isBelow:h,willStayInSamePosition:C};u?p+=m/2:h?p+=m+y/2:p-=f/2;let x=0;u||(h?x=-it:x=it);let N=p-c+x,b=Ho-t;return o.style.width=`calc(${g}px - ${e} - var(--spacer-5))`,o.style.opacity=".8",o.style.transform=`translate(${b}px, calc(${N}px - 2px))`,n?.elem&&(n.elem.style.opacity="",n?.elem===r?h?n.elem.style.marginTop="":n.elem.style.marginBottom="":(n.elem.style.marginBottom="",n.elem.style.marginTop="")),U=0,{isBelow:h,willStayInSamePosition:C}}import{mergeRegister as Vo}from"@lexical/utils";import{$getSelection as Wo,$isNodeSelection as Yo,$isRangeSelection as Go,COMMAND_PRIORITY_HIGH as lt,KEY_ARROW_DOWN_COMMAND as Uo,KEY_ARROW_UP_COMMAND as qo}from"lexical";import{useEffect as at}from"react";function ct({editor:e,instructionsID:t}){at(()=>{let o=({direction:r,event:n})=>{if(!e.isEditable()||!n.altKey||!n.shiftKey||n.ctrlKey||n.metaKey)return!1;let i=Wo(),l=(Go(i)&&i.isCollapsed()?i.anchor.getNode():Yo(i)&&i.getNodes().length===1?i.getNodes()[0]:null)?.getTopLevelElement();if(!l)return!1;n.preventDefault();let d=r===-1?l.getPreviousSibling():l.getNextSibling();return d&&(r===-1?d.insertBefore(l):d.insertAfter(l)),!0};return Vo(e.registerCommand(qo,r=>o({direction:-1,event:r}),lt),e.registerCommand(Uo,r=>o({direction:1,event:r}),lt))},[e]),at(()=>{let o,r=e.registerRootListener(n=>{if(o?.(),!n)return;let i=n.getAttribute("aria-describedby");n.setAttribute("aria-describedby",[i,t].filter(Boolean).join(" ")),o=()=>{i===null?n.removeAttribute("aria-describedby"):n.setAttribute("aria-describedby",i)}});return()=>{r(),o?.()}},[e,t])}var tr="draggable-block-menu",pt="application/x-lexical-drag-block",le=1/0;function gt(e){return e===0?1/0:le>=0&&le<e?le:Math.floor(e/2)}function or(e,t){let{transform:o}=t.style;e.setDragImage(t,0,0),setTimeout(()=>{t.style.transform=o})}function ht(e,t){e&&(e.style.opacity="0"),t&&(t.style.opacity="",t.style.marginBottom="",t.style.marginTop="")}function rr(e,t,o){let r=t.parentElement,n=Zo(),{t:i}=Qo();ct({editor:e,instructionsID:n});let s=se(null),l=se(null),d=se(null),u=se(!1),m=se([]),[a,c]=mt(null),[g,y]=mt(null),{editorConfig:f}=R(),p=f?.admin?.hideGutter?-44:-8;ve(()=>{function x(N){let b=N.target;if(!ke(b))return;let S=X(r,N.pageX,N.pageY,b);if(S===-1){c(null);return}if(xe(b,tr))return;let D=G(e),{blockElem:_,foundAtIndex:B,isFoundNodeEmptyParagraph:V}=ee({anchorElem:t,cache_threshold:0,editor:e,horizontalOffset:-S,point:new j(N.x,N.y),startIndex:gt(D.length),useEdgeAsDefault:!1,verbose:!1});le=B,!(!_&&!V)&&a!==_&&c(_)}return document?.addEventListener("mousemove",x),()=>{document?.removeEventListener("mousemove",x)}},[r,t,e,a]),ve(()=>{s.current&&Ce(a,s.current,t,p)},[t,a,p]),ve(()=>{function x(b){if(!u.current)return!1;let[S]=ut(b);if(S)return!1;let{pageY:D,target:_}=b;if(!ke(_))return!1;let B=X(r,b.pageX,b.pageY,_,100,50),V=G(e),{blockElem:w,foundAtIndex:k,isFoundNodeEmptyParagraph:I}=ee({anchorElem:t,editor:e,fuzzy:!0,horizontalOffset:-B,point:new j(b.x,b.y),startIndex:gt(V.length),useEdgeAsDefault:!0,verbose:!0});le=k;let $=l.current;if(w===null||$===null)return!1;if(b.preventDefault(),b.dataTransfer.dropEffect="move",a!==w){let{isBelow:T,willStayInSamePosition:q}=st(f?.admin?.hideGutter?"0px":"var(--spacer-5)",p+(f?.admin?.hideGutter?s?.current?.getBoundingClientRect()?.width??0:-(s?.current?.getBoundingClientRect()?.width??0)),$,w,g,D,t,b,d,I);q||y({boundingBox:w.getBoundingClientRect(),elem:w,isBelow:T})}else g?.elem&&(ht($,g.elem),y({boundingBox:w.getBoundingClientRect(),elem:w,isBelow:!1}));return!0}function N(b){if(!u.current)return!1;let[S]=ut(b);if(S)return!1;let{dataTransfer:D,pageY:_,target:B}=b,V=D?.getData(pt)||"";return e.update(()=>{let w=Xo(V);if(!w||!ke(B))return!1;let k=X(r,b.pageX,b.pageY,B,100,50),{blockElem:I,isFoundNodeEmptyParagraph:$}=ee({anchorElem:t,editor:e,fuzzy:!0,horizontalOffset:-k,point:new j(b.x,b.y),useEdgeAsDefault:!0});if(!I)return!1;let T=ft(I);if(!T)return!1;if(T===w)return!0;let{height:q,top:J}=Z(I),Se=_>=J+q/2+window.scrollY;$?(T.insertBefore(w),T.remove()):Se?T.insertAfter(w):T.insertBefore(w),a!==null&&c(null),document.querySelectorAll(".lexical-block-highlighter").forEach(L=>{L.remove()});let de=e.getElementByKey(w.getKey()),F=setTimeout(()=>{let L=de?.getBoundingClientRect();if(!L)return;let P=document.createElement("div");P.className="lexical-block-highlighter",P.style.backgroundColor="var(--color-bg-inverse)",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=`${L.height+8}px`,P.style.width=`${L.width+8}px`,P.style.top=`${L.top+window.scrollY-4}px`,P.style.left=`${L.left-4}px`;let ue=setTimeout(()=>{P.style.opacity="0";let we=setTimeout(()=>{P.remove()},500);m.current.push(we)},1e3);m.current.push(ue)},120);m.current.push(F)}),!0}return document.addEventListener("dragover",x),document.addEventListener("drop",N),()=>{document.removeEventListener("dragover",x),document.removeEventListener("drop",N),m.current.forEach(clearTimeout),m.current=[]}},[r,p,t,e,g,a,f?.admin?.hideGutter]);function h(x){let N=x.dataTransfer;if(!N||!a)return;or(N,a),N.effectAllowed="move";let b="";e.update(()=>{let S=ft(a);S&&(b=S.getKey())}),u.current=!0,N.setData(pt,b)}function C(){u.current=!1,g?.elem&&ht(l.current,g?.elem)}return er(dt(yt.Fragment,{children:[dt("span",{className:"sr-only",id:n,children:[i("general:moveUp"),": Alt + Shift + \u2191. ",i("general:moveDown"),": Alt + Shift + \u2193."]}),Ne("button",{"aria-label":"Drag to move",className:"icon draggable-block-menu",draggable:!0,onDragEnd:C,onDragStart:h,ref:s,type:"button",children:Ne("div",{className:o?"icon":""})}),Ne("div",{className:"draggable-block-target-line",ref:l}),Ne("div",{className:"debug-highlight",ref:d})]}),t)}function bt(e){let{anchorElem:t}=e,o=t===void 0?document.body:t,[r]=Jo();return rr(r,o,r._editable)}import{c as nr}from"react/compiler-runtime";import{jsx as Le}from"react/jsx-runtime";import{useLexicalComposerContext as ir}from"@lexical/react/LexicalComposerContext";import{useTranslation as sr}from"@payloadcms/ui";import{$createParagraphNode as lr,$getRoot as ar}from"lexical";import"react";var xt="insert-paragraph-at-end",Ct=()=>{let e=nr(5),[t]=ir(),{editorConfig:o}=R(),{t:r}=sr();if(o?.admin?.hideInsertParagraphAtEnd)return null;let n;e[0]!==t?(n=()=>{t.update(cr)},e[0]=t,e[1]=n):n=e[1];let i=n,s;return e[2]!==i||e[3]!==r?(s=Le("button",{"aria-label":r("lexical:general:insertParagraph"),className:xt,onClick:i,type:"button",children:Le("span",{className:`${xt}-inside`,children:Le(Ie,{size:16})})}),e[2]=i,e[3]=r,e[4]=s):s=e[4],s};function cr(){let e=lr();ar().append(e),e.select()}import{c as dr}from"react/compiler-runtime";import{registerMarkdownShortcuts as ur}from"@lexical/markdown";import{useLexicalComposerContext as fr}from"@lexical/react/LexicalComposerContext";import*as Et from"react";var Nt=()=>{let e=dr(4),{editorConfig:t}=R(),[o]=fr(),r,n;return e[0]!==o||e[1]!==t.features.markdownTransformers?(r=()=>ur(o,t.features.markdownTransformers??[]),n=[o,t.features.markdownTransformers],e[0]=o,e[1]=t.features.markdownTransformers,e[2]=r,e[3]=n):(r=e[2],n=e[3]),Et.useEffect(r,n),null};import{c as mr}from"react/compiler-runtime";import{useLexicalComposerContext as pr}from"@lexical/react/LexicalComposerContext.js";import{$getRoot as gr}from"lexical";import{useEffect as hr}from"react";function yr(e){e.update(()=>{let t=o=>{let r=o.getType();if((r==="block"||r==="inlineBlock")&&o.markDirty(),"getChildren"in o&&typeof o.getChildren=="function")for(let n of o.getChildren())t(n)};t(gr())})}function St(){let e=mr(5),[t]=pr(),{currentView:o,views:r}=K(),n,i;return e[0]!==o||e[1]!==t||e[2]!==r?(n=()=>{r&&(o==="default"?r.default?Pe(t,r.default?.nodes):Re(t):r[o]&&(Re(t),Pe(t,r[o]?.nodes)),yr(t))},i=[t,r,o],e[0]=o,e[1]=t,e[2]=r,e[3]=n,e[4]=i):(n=e[3],i=e[4]),hr(n,i),null}import{useLexicalComposerContext as br}from"@lexical/react/LexicalComposerContext";import{$getSelection as xr,$isRangeSelection as Cr,RootNode as Er}from"lexical";import{useEffect as Nr}from"react";function wt(){let[e]=br();return Nr(()=>e.registerNodeTransform(Er,t=>{let o=xr();if(Cr(o)){let r=o.anchor.getNode(),n=o.focus.getNode();(!r.isAttached()||!n.isAttached())&&(t.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}),[e]),null}import{useLexicalComposerContext as Sr}from"@lexical/react/LexicalComposerContext";import{$getSelection as wr,COMMAND_PRIORITY_LOW as Pr,SELECT_ALL_COMMAND as Rr}from"lexical";import{useEffect as Tr}from"react";function Pt(){let[e]=Sr();return Tr(()=>e.registerCommand(Rr,()=>{if(wr())return!1;let o=document.activeElement;return o instanceof HTMLInputElement&&o.select(),!0},Pr),[e]),null}import{jsx as te,jsxs as Tt}from"react/jsx-runtime";import{useLexicalComposerContext as Dr}from"@lexical/react/LexicalComposerContext.js";import{useTranslation as _t}from"@payloadcms/ui";import{useCallback as kr,useMemo as vr,useState as Lr}from"react";import"react";import*as Dt from"react-dom";import{c as _r}from"react/compiler-runtime";import"react";function Rt(e,t){let o=_r(4),{maxLength:r,minLength:n}=t,i=r===void 0?75:r,s=n===void 0?1:n,l;return o[0]!==i||o[1]!==s||o[2]!==e?(l=d=>{let{query:u}=d,m="[^"+e+Fe+"\\s]",c=new RegExp("(^|\\s|\\()(["+e+"]((?:"+m+"){0,"+i+"}))$").exec(u);if(c!==null){let g=c[1],y=c[3];if(y.length>=s)return{leadOffset:c.index+g.length,matchingString:y,replaceableString:c[2]}}return null},o[0]=i,o[1]=s,o[2]=e,o[3]=l):l=o[3],l}var O="slash-menu-popup";function Ar({isSelected:e,item:t,onClick:o,onMouseEnter:r,ref:n}){let{fieldProps:{featureClientSchemaMap:i,schemaPath:s}}=R(),{i18n:l}=_t(),d=`${O}__item ${O}__item-${t.key}`;e&&(d+=` ${O}__item--selected`);let u=t.key;return t.label&&(u=typeof t.label=="function"?t.label({featureClientSchemaMap:i,i18n:l,schemaPath:s}):t.label),u.length>25&&(u=u.substring(0,25)+"..."),Tt("button",{"aria-selected":e,className:d,id:O+"__item-"+t.key,onClick:o,onMouseEnter:r,ref:n,role:"option",tabIndex:-1,type:"button",children:[t?.Icon&&te(t.Icon,{}),te("span",{className:`${O}__item-text`,children:u})]},t.key)}function kt({anchorElem:e=document.body}){let[t]=Dr(),[o,r]=Lr(null),{editorConfig:n}=R(),{i18n:i}=_t(),{fieldProps:{featureClientSchemaMap:s,schemaPath:l}}=R(),d=Rt("/",{minLength:0}),u=kr(()=>{let a=[];for(let c of n.features.slashMenu.dynamicGroups)if(o){let g=c({editor:t,queryString:o});a=a.concat(g)}return a},[t,o,n?.features]),m=vr(()=>{let a=[];for(let c of n?.features.slashMenu.groups??[])a.push(c);if(o){let c=o.toLowerCase().replace(/[\s\-_]/g,"");a=a.map(y=>{let f=y.items.filter(p=>{let h=p.key;return p.label&&(h=typeof p.label=="function"?p.label({featureClientSchemaMap:s,i18n:i,schemaPath:l}):p.label),new RegExp(o,"gi").exec(h)||h.toLowerCase().replace(/[\s\-_]/g,"").includes(c)?!0:p.keywords!=null?p.keywords.some(x=>new RegExp(o,"gi").exec(x)?!0:x.toLowerCase().replace(/[\s\-_]/g,"").includes(c)):!1});return f.length?{...y,items:f}:null}),a=a.filter(y=>y!=null);let g=u();for(let y of g){let f=a.find(p=>p.key===y.key);f?a=a.filter(p=>p.key!==y.key):f={...y,items:[]},f?.items?.length&&(f.items=f.items.concat(f.items)),a.push(f)}}return a},[o,n?.features.slashMenu.groups,u,s,i,l]);return te(je,{anchorElem:e,groups:m,menuRenderFn:(a,{selectedItemKey:c,selectItemAndCleanUp:g,setSelectedItemKey:y})=>a.current&&m.length?Dt.createPortal(te("div",{className:O,"data-theme":"dark",children:m.map(f=>{let p=f.key;return f.label&&s&&(p=typeof f.label=="function"?f.label({featureClientSchemaMap:s,i18n:i,schemaPath:l}):f.label),Tt("div",{className:`${O}__group ${O}__group-${f.key}`,children:[te("div",{className:`${O}__group-title`,children:p}),f.items.map((h,C)=>te(Ar,{index:C,isSelected:c===h.key,item:h,onClick:()=>{y(h.key),g(h)},onMouseEnter:()=>{y(h.key)},ref:x=>{h.ref={current:x}}},h.key))]},f.key)})}),a.current):null,onQueryChange:r,triggerFn:d})}import{c as Mr}from"react/compiler-runtime";import{useLexicalComposerContext as Or}from"@lexical/react/LexicalComposerContext";import{TEXT_TYPE_TO_FORMAT as Br,TextNode as Ir}from"lexical";import{useEffect as $r}from"react";function vt(e){let t=Mr(6),{features:o}=e,[r]=Or(),n;t[0]!==r||t[1]!==o.enabledFormats?(n=()=>{let s=Fr(o.enabledFormats);if(s.length!==0)return r.registerNodeTransform(Ir,l=>{s.forEach(d=>{l.hasFormat(d)&&l.toggleFormat(d)})})},t[0]=r,t[1]=o.enabledFormats,t[2]=n):n=t[2];let i;return t[3]!==r||t[4]!==o?(i=[r,o],t[3]=r,t[4]=o,t[5]=i):i=t[5],$r(n,i),null}function Fr(e){let t=Object.keys(Br),o=new Set(e);return t.filter(r=>!o.has(r))}import{c as Kr}from"react/compiler-runtime";import{jsx as Lt}from"react/jsx-runtime";import{useLexicalComposerContext as jr}from"@lexical/react/LexicalComposerContext";import{ContentEditable as zr}from"@lexical/react/LexicalContentEditable.js";import{getTranslation as Hr}from"@payloadcms/translations";import{useTranslation as Vr}from"@payloadcms/ui";import"react";function At(e){let t=Kr(9),{className:o,editorConfig:r,instructionsID:n}=e,{fieldProps:i}=R(),{i18n:s,t:l}=Vr(),[,d]=jr(),{getTheme:u}=d,m;if(t[0]!==o||t[1]!==r?.admin?.placeholder||t[2]!==i.field.label||t[3]!==i.field.required||t[4]!==u||t[5]!==s||t[6]!==n||t[7]!==l){let a=u();m=Lt(zr,{"aria-describedby":n,"aria-label":Hr(i.field.label||"",s),"aria-placeholder":l("lexical:general:placeholder"),"aria-required":i.field.required||void 0,className:o??"ContentEditable__root",placeholder:Lt("p",{className:a?.placeholder,children:r?.admin?.placeholder??l("lexical:general:placeholder")})}),t[0]=o,t[1]=r?.admin?.placeholder,t[2]=i.field.label,t[3]=i.field.required,t[4]=u,t[5]=s,t[6]=n,t[7]=l,t[8]=m}else m=t[8];return m}var Ot=e=>{let t=Wr(5),{editorConfig:o,editorContainerRef:r,isSmallWidthViewport:n,onChange:i,rtl:s}=e,l=R(),[d]=Yr(),u=Qr(),{t:m}=Xr(),a=z.useId(),c=u&&o.features.enabledFeatures.includes("indent"),[g,y]=on(null),f;t[0]===Symbol.for("react.memo_cache_sentinel")?(f=x=>{x!==null&&y(x)},t[0]=f):f=t[0];let p=f,h,C;return t[1]!==d||t[2]!==l?(h=()=>{if(!l?.uuid){console.error("Lexical Editor must be used within an EditorConfigProvider");return}l?.parentEditor?.uuid&&l.parentEditor?.registerChild(l.uuid,l);let x=()=>{l.focusEditor(l)},N=()=>{l.blurEditor(l)},b=d.registerCommand(en,()=>(x(),!0),Mt),S=d.registerCommand(Zr,()=>(N(),!0),Mt);return()=>{b(),S(),l.parentEditor?.unregisterChild?.(l.uuid)}},C=[d,l],t[1]=d,t[2]=l,t[3]=h,t[4]=C):(h=t[3],C=t[4]),tn(h,C),ae(z.Fragment,{children:[o.features.plugins?.map(rn),ae("div",{className:"editor-container",dir:s?"rtl":void 0,ref:r,children:[o.features.plugins?.map(nn),E(Jr,{contentEditable:E("div",{className:"editor-scroller",children:E("div",{className:"editor",ref:p,children:E(At,{editorConfig:o,instructionsID:c?a:void 0})})}),ErrorBoundary:Gr}),E(wt,{}),u&&E(Ct,{}),E(Qe,{}),E(Ge,{}),E(vt,{features:o.features}),E(Pt,{}),E(St,{}),u&&E(qr,{ignoreSelectionChange:!0,onChange:(x,N,b)=>{(!b.has("focus")||b.size>1)&&i?.(x,N,b)}}),g&&ae(z.Fragment,{children:[!n&&u&&ae(z.Fragment,{children:[o.admin?.hideDraggableBlockElement?null:E(bt,{anchorElem:g}),o.admin?.hideAddBlockButton?null:E(nt,{anchorElem:g})]}),o.features.plugins?.map(x=>{if(x.position==="floatingAnchorElem"&&!(x.desktopOnly===!0&&n))return E(W,{anchorElem:g,clientProps:x.clientProps,plugin:x},x.key)}),u&&E(z.Fragment,{children:E(kt,{anchorElem:g})})]}),u&&ae(z.Fragment,{children:[E(Ur,{}),o?.features?.markdownTransformers?.length>0&&E(Nt,{})]}),o.features.plugins?.map(sn),o.features.plugins?.map(ln)]}),c&&E("p",{className:"ContentEditable__keyboard-hint",id:a,children:m("lexical:indent:keyboardHint")}),o.features.plugins?.map(an)]})};function rn(e){if(e.position==="aboveContainer")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}function nn(e){if(e.position==="top")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}function sn(e){if(e.position==="normal")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}function ln(e){if(e.position==="bottom")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}function an(e){if(e.position==="belowContainer")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}var It=({children:e,providers:t})=>{if(!t?.length)return e;let o=t[0];return t.length>1?H(o,{children:H(It,{providers:t.slice(1),children:e})}):H(o,{children:e})},$t=e=>{let{composerKey:t,editorConfig:o,fieldProps:r,isSmallWidthViewport:n,onChange:i,readOnly:s,rtl:l,value:d}=e,{currentView:u,views:m}=K(),a=R(),c=dn(),g=Bt.useRef(null),y=un(()=>{if(d&&typeof d!="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(d));if(d&&Array.isArray(d)&&!("root"in d))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(d&&"jsonContent"in d)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");let f=m?.[u]?.nodes;return{editable:s!==!0,editorState:d!=null?JSON.stringify(d):void 0,namespace:o.lexical.namespace,nodes:He({editorConfig:o,nodeViews:f}),onError:p=>{throw p},theme:o.lexical.theme}},[o,m,u]);return y?H(cn,{initialConfig:y,children:H(Be,{editorConfig:o,editorContainerRef:g,fieldProps:r,parentContext:a?.editDepth===c?a:void 0,children:H(It,{providers:o.features.providers,children:H(Ot,{editorConfig:o,editorContainerRef:g,isSmallWidthViewport:n,onChange:i,rtl:l})})})},t+y.editable+u):H("p",{children:"Loading..."})};import{c as fn}from"react/compiler-runtime";import{jsx as oe,jsxs as mn}from"react/jsx-runtime";import{ChevronIcon as pn,Popup as gn,PopupList as Ft}from"@payloadcms/ui";import"react";function Kt(){let e=fn(5),{currentView:t,setCurrentView:o,views:r}=K();if(!r||Object.keys(r).length===0)return null;let n,i;if(e[0]!==t||e[1]!==o||e[2]!==r){i=Symbol.for("react.early_return_sentinel");e:{let s=Object.keys(r);if(!s.some(yn)){i=null;break e}let d=["default",...s.filter(hn)],u=t.charAt(0).toUpperCase()+t.slice(1);n=oe("div",{className:"lexical-view-selector",children:oe(gn,{button:mn("button",{className:"lexical-view-selector__button",type:"button",children:[oe("span",{className:"lexical-view-selector__label",children:u}),oe(pn,{className:"lexical-view-selector__icon"})]}),buttonType:"custom",horizontalAlign:"left",popupType:"menu",render:m=>{let{close:a}=m;return oe(Ft.ButtonGroup,{children:d.map(c=>{let g=c.charAt(0).toUpperCase()+c.slice(1);return oe(Ft.Button,{active:c===t,disabled:c===t,onClick:()=>{o?.(c),a()},children:g},c)})})},size:"large"})})}e[0]=t,e[1]=o,e[2]=r,e[3]=n,e[4]=i}else n=e[3],i=e[4];return i!==Symbol.for("react.early_return_sentinel")?i:n}function hn(e){return e!=="default"}function yn(e){return e!=="default"}var re="rich-text-lexical",Mn=e=>{let{editorConfig:t,field:o,field:{admin:{className:r,description:n,readOnly:i}={},label:s,localized:l,required:d},path:u,readOnly:m,schemaPath:a,validate:c}=e,{i18n:g}=Dn(),y=m||i,f=_n(),{config:{localization:p}}=wn(),h=Sn({fieldLocalized:l,locale:f,localizationConfig:p||void 0}),C=Pn(),{isControlledByParent:x}=K(),N=Ht((A,ne)=>typeof c=="function"?c(A,{...ne,required:d}):!0,[c,d]),{customComponents:{AfterInput:b,BeforeInput:S,Description:D,Error:_,Label:B}={},disabled:V,initialValue:w,path:k,setValue:I,showError:$,value:T}=Tn({potentiallyStalePath:u,validate:N}),q=y||V,[J,Ae]=Wt(!1),[Se,Me]=Wt(),de=zt.useRef(w),F=zt.useRef(T);Vt(()=>{let A=()=>{let ne=window.matchMedia("(max-width: 768px)").matches;ne!==J&&Ae(ne)};return A(),window.addEventListener("resize",A),()=>{window.removeEventListener("resize",A)}},[J]);let L=["field-type",re,r,$&&"error",q&&`${re}--read-only`,t?.admin?.hideGutter!==!0&&!J?`${re}--show-gutter`:null].filter(Boolean).join(" "),P=`${k}.${C}`,ue=$e(),we=Ht(A=>{ue(()=>{let Oe=A.toJSON();F.current=Oe,I(Oe)})},[I,ue]),Yt=Ln(()=>kn(o),[o]),Gt=Rn(A=>{F.current!==T&&!vn(F.current!=null?JSON.parse(JSON.stringify(F.current)):F.current,T)&&(de.current=A,F.current=T,Me(new Date))});return Vt(()=>{Object.is(w,de.current)||Gt(w)},[w]),ce("div",{"aria-label":bn(s||"",g),className:L,"data-field-path":k,"data-field-schemapath":a,"data-lexical-view":t?.view,role:"group",style:Yt,children:[ce("div",{className:`${re}__label-row`,children:[B||v(Nn,{hasRequiredAccessibleState:!0,label:s,localized:l,path:k,required:d}),!x&&v(Kt,{})]}),ce("div",{className:`${re}__wrap`,children:[v(jt,{CustomComponent:_,Fallback:v(En,{path:k,showError:$})}),ce(An,{fallbackRender:On,onReset:()=>{},children:[S,v("div",{className:`${re}__editor-content`,children:v(xn,{modalSlugPrefix:`lexical-${k}`,children:v($t,{composerKey:P,editorConfig:t,fieldProps:e,isSmallWidthViewport:J,onChange:we,readOnly:q,rtl:h,value:T},JSON.stringify({path:k,rerenderProviderKey:Se}))})}),b]}),v(jt,{CustomComponent:D,Fallback:v(Cn,{description:n,path:k})})]})]},P)};function On({error:e}){return ce("div",{className:"errorBoundary",role:"alert",children:[v("p",{children:"Something went wrong:"}),v("pre",{style:{color:"red"},children:e instanceof Error?e.message:String(e)})]})}var na=Mn;export{na as RichText};
2
- //# sourceMappingURL=Field-MT4FK3IP.js.map
1
+ "use client";import{b as Ie,c as $e,e as K,f as j,h as Fe,i as Ke,j as je,k as ze,l as Pe,m as Re,n as He}from"./chunk-3LRZDIIG.js";import{a as Be,b as R}from"./chunk-RJ5MAOKZ.js";import{jsx as v,jsxs as ce}from"react/jsx-runtime";import{getTranslation as xn}from"@payloadcms/translations";import{BulkUploadProvider as Cn,FieldDescription as En,FieldError as Nn,FieldLabel as Sn,isFieldRTL as wn,RenderCustomComponent as jt,useConfig as Pn,useEditDepth as Rn,useEffectEvent as Tn,useField as _n,useLocale as Dn,useTranslation as kn}from"@payloadcms/ui";import{mergeFieldStyles as vn}from"@payloadcms/ui/shared";import{dequal as Ln}from"dequal/lite";import zt,{useCallback as Ht,useEffect as Vt,useMemo as An,useState as Wt}from"react";import{ErrorBoundary as Mn}from"react-error-boundary";import"../../field/bundled.css";import{jsx as H}from"react/jsx-runtime";import{LexicalComposer as dn}from"@lexical/react/LexicalComposer.js";import{useEditDepth as un}from"@payloadcms/ui";import*as Bt from"react";import{useMemo as fn}from"react";import{c as Yr}from"react/compiler-runtime";import{jsx as E,jsxs as ae}from"react/jsx-runtime";import{useLexicalComposerContext as Gr}from"@lexical/react/LexicalComposerContext.js";import{LexicalErrorBoundary as Ur}from"@lexical/react/LexicalErrorBoundary.js";import{HistoryPlugin as qr}from"@lexical/react/LexicalHistoryPlugin.js";import{OnChangePlugin as Jr}from"@lexical/react/LexicalOnChangePlugin.js";import{RichTextPlugin as Qr}from"@lexical/react/LexicalRichTextPlugin.js";import{useLexicalEditable as Xr}from"@lexical/react/useLexicalEditable";import{useTranslation as Zr}from"@payloadcms/ui";import{BLUR_COMMAND as en,COMMAND_PRIORITY_LOW as Mt,FOCUS_COMMAND as tn}from"lexical";import*as z from"react";import{useEffect as on,useState as rn}from"react";import{jsx as Ve}from"react/jsx-runtime";import"react";var W=({anchorElem:e,clientProps:t,plugin:o})=>o.position==="floatingAnchorElem"&&e?o.Component&&Ve(o.Component,{anchorElem:e,clientProps:t}):o.Component&&Ve(o.Component,{clientProps:t});import{c as Ut}from"react/compiler-runtime";import{copyToClipboard as We}from"@lexical/clipboard";import{useLexicalComposerContext as qt}from"@lexical/react/LexicalComposerContext.js";import{objectKlassEquals as Jt}from"@lexical/utils";import Ye from"bson-objectid";import{$getSelection as Qt,$isNodeSelection as Xt,COMMAND_PRIORITY_LOW as Zt,COPY_COMMAND as eo}from"lexical";import{useEffect as to}from"react";var Te=e=>{if("fields"in e&&typeof e.fields=="object"&&e.fields!==null&&"id"in e.fields?e.fields.id=new Ye.default().toHexString():"id"in e&&(e.id=new Ye.default().toHexString()),e.children)for(let t of e.children)Te(t)};function Ge(){let e=Ut(3),[t]=qt(),o,r;return e[0]!==t?(o=()=>t.registerCommand(eo,n=>{let i=Qt();if(Xt(i)){let l=i.getNodes()[0]?.exportJSON(),d=JSON.parse(JSON.stringify(l));Te(d);let u={namespace:t._config.namespace,nodes:[d]},m=JSON.stringify(u);return We(t,null,{"application/x-lexical-editor":m,"text/plain":""}).catch(oo),!0}return We(t,Jt(n,ClipboardEvent)?n:null).then(()=>{if(!(n instanceof ClipboardEvent)||!n.clipboardData)throw new Error("No clipboard event");let s=n.clipboardData.getData("application/x-lexical-editor");if(!s)return!0;let l=JSON.parse(s);for(let u of l.nodes)Te(u);let d=JSON.stringify(l);n.clipboardData.setData("application/x-lexical-editor",d)}).catch(s=>{throw n instanceof ClipboardEvent&&n.clipboardData?.setData("application/x-lexical-editor",""),s}),!0},Zt),r=[t],e[0]=t,e[1]=o,e[2]=r):(o=e[1],r=e[2]),to(o,r),null}function oo(e){throw e}import{c as ro}from"react/compiler-runtime";import{useLexicalComposerContext as no}from"@lexical/react/LexicalComposerContext";import{$findMatchingParent as fe,mergeRegister as io}from"@lexical/utils";import{$createNodeSelection as so,$getEditor as me,$getNearestNodeFromDOMNode as lo,$getSelection as pe,$isDecoratorNode as Y,$isElementNode as _e,$isLineBreakNode as ao,$isNodeSelection as ge,$isRangeSelection as qe,$isRootOrShadowRoot as co,$isTextNode as uo,$onUpdate as fo,$setSelection as Je,CLICK_COMMAND as mo,COMMAND_PRIORITY_LOW as Q,KEY_ARROW_DOWN_COMMAND as po,KEY_ARROW_UP_COMMAND as go,KEY_BACKSPACE_COMMAND as ho,KEY_DELETE_COMMAND as yo,SELECTION_CHANGE_COMMAND as bo}from"lexical";import{useEffect as xo}from"react";function Qe(){let e=ro(3),[t]=no(),o=Po,r,n;return e[0]!==t?(r=()=>io(t.registerCommand(mo,wo,Q),t.registerCommand(yo,o,Q),t.registerCommand(ho,o,Q),t.registerCommand(bo,(i,s)=>{if(s!==t)return!1;let l=!!Ue();return fo(()=>{s.read("latest",()=>{let d=Ue();document.querySelector(".decorator-selected")?.classList.remove("decorator-selected"),d&&s.getElementByKey(d.getKey())?.classList.add("decorator-selected")})}),l},Q),t.registerCommand(go,No,Q),t.registerCommand(po,Co,Q)),n=[t],e[0]=t,e[1]=r,e[2]=n):(r=e[1],n=e[2]),xo(r,n),null}function Co(e){let t=pe();if(ge(t)){e.preventDefault();let s=t.getNodes()[0]?.getNextSibling();if(Y(s)){let u=me().getElementByKey(s.getKey());return u&&ie({element:u,node:s}),!0}if(!_e(s))return!0;let l=s.getFirstDescendant()??s;return l&&(fe(l,he)?.selectEnd(),e.preventDefault()),!0}if(!qe(t))return!1;let r=(t.isBackward()?t.anchor:t.focus).getNode(),n=fe(r,Eo),i=n?.getNextSibling();if(!n||i!==Xe(n))return!1;if(Y(i)){let s=me().getElementByKey(i.getKey());if(s)return ie({element:s,node:i}),e.preventDefault(),!0}return!1}function Eo(e){return Xe(e)!==null}function No(e){let t=pe();if(ge(t)){let s=t.getNodes()[0]?.getPreviousSibling();if(Y(s)){let u=me().getElementByKey(s.getKey());return u?(ie({element:u,node:s}),e.preventDefault(),!0):!1}if(!_e(s))return!1;let l=s.getLastDescendant()??s;return l?(fe(l,he)?.selectStart(),e.preventDefault(),!0):!1}if(!qe(t))return!1;let r=(t.isBackward()?t.anchor:t.focus).getNode(),n=fe(r,So),i=n?.getPreviousSibling();if(!n||i!==Ze(n))return!1;if(Y(i)){let s=me().getElementByKey(i.getKey());if(s)return ie({element:s,node:i}),e.preventDefault(),!0}return!1}function So(e){return Ze(e)!==null}function wo(e){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let t=To(e);if(!t)return!0;let{target:o}=e;return!(o instanceof HTMLElement)||o.isContentEditable||o.closest('button, textarea, input, .react-select, .code-editor, .no-select-decorator, [role="button"]')?Je(null):ie(t),!0}function Po(e){let t=pe();return ge(t)?(e.preventDefault(),t.getNodes().forEach(Ro),!0):!1}function Ro(e){e.remove()}function To(e){if(!(e.target instanceof HTMLElement))return;let t=e.target.closest('[data-lexical-decorator="true"]');if(!(t instanceof HTMLElement))return;let o=lo(t);return Y(o)?{element:t,node:o}:void 0}function Ue(){let e=pe();if(!ge(e))return;let t=e.getNodes();if(t.length!==1)return;let o=t[0];return Y(o)?o:void 0}function ie({element:e,node:t}){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let o=so();o.add(t.getKey()),Je(o),e.scrollIntoView({behavior:"smooth",block:"nearest"}),e.classList.add("decorator-selected")}function he(e){if(Y(e)&&!e.isInline())return!0;if(!_e(e)||co(e))return!1;let t=e.getFirstChild(),o=t===null||ao(t)||uo(t)||t.isInline();return!e.isInline()&&e.canBeEmpty()!==!1&&o}function Xe(e){let t=e.getNextSibling();for(;t!==null;){if(he(t))return t;t=t.getNextSibling()}return null}function Ze(e){let t=e.getPreviousSibling();for(;t!==null;){if(he(t))return t;t=t.getPreviousSibling()}return null}import{jsx as De}from"react/jsx-runtime";import{useLexicalComposerContext as Ao}from"@lexical/react/LexicalComposerContext.js";import{$createParagraphNode as Mo,isHTMLElement as Oo}from"lexical";import*as rt from"react";import{useCallback as Bo,useEffect as ot,useRef as Io,useState as $o}from"react";import{createPortal as Fo}from"react-dom";var X=(e,t,o,r,n=50,i=25)=>{let s=0;if(e&&!e.contains(r)){let{bottom:l,left:d,right:u,top:m}=e.getBoundingClientRect(),a=m+window.scrollY,c=l+window.scrollY;if(o<a-i||o>c+i||t<d-n||t>u+n)return-1;(t<d||t>u)&&(s=t<d?t-d:t-u)}return s};import{$getNodeByKey as be}from"lexical";function Z(e){let t=e.getBoundingClientRect(),o=getComputedStyle(e).getPropertyValue("transform");if(!o||o==="none")return t;let r=o.split(",").pop();return t.y=t.y-Number(r?.replace(")","")),t}function ye(e){let t=(d,u)=>d?parseFloat(window.getComputedStyle(d)[u]):0,{marginBottom:o,marginTop:r}=window.getComputedStyle(e),n=t(e.previousElementSibling,"marginBottom"),i=t(e.nextElementSibling,"marginTop"),s=Math.max(parseFloat(r),n);return{marginBottom:Math.max(parseFloat(o),i),marginTop:s}}import{$getRoot as _o}from"lexical";function G(e){return e.getEditorState().read(()=>_o().getChildrenKeys())}var Do=1,ko=-1,et=0,M={props:null,result:null};function vo(e,t,o=20){let r=e.x-t.x,n=e.y-t.y;return r*r+n*n<=o*o}function ee(e){let{anchorElem:t,cache_threshold:o=20,editor:r,fuzzy:n=!1,horizontalOffset:i=0,point:{x:s,y:l},startIndex:d=0,useEdgeAsDefault:u=!1}=e;if(o>0&&M.props&&M.result&&M.props.fuzzy===e.fuzzy&&M.props.horizontalOffset===e.horizontalOffset&&M.props.useEdgeAsDefault===e.useEdgeAsDefault&&vo(M.props.point,e.point,o))return M.result;let m=t.getBoundingClientRect(),a=G(r),c={blockElem:null,blockNode:null,distance:1/0,foundAtIndex:-1,isFoundNodeEmptyParagraph:!1};return r.getEditorState().read(()=>{if(u){let f=r.getElementByKey(a[0]),p=r.getElementByKey(a[a.length-1]);if(f&&p){let[h,C]=[Z(f),Z(p)];if(l<h.top?(c.blockElem=f,c.distance=h.top-l,c.blockNode=be(a[0]),c.foundAtIndex=0):l>C.bottom&&(c.distance=l-C.bottom,c.blockNode=be(a[a.length-1]),c.blockElem=p,c.foundAtIndex=a.length-1),c?.blockElem)return{blockElem:null,isFoundNodeEmptyParagraph:!1}}}let g=d,y=et;for(;g>=0&&g<a.length;){let f=a[g],p=r.getElementByKey(f);if(p===null)break;let h=new j(s+i,l),C=ze.fromDOMRect(Z(p)),{marginBottom:x,marginTop:N}=ye(p),b=C.generateNewRect({bottom:C.bottom+x,left:m.left,right:m.right,top:C.top-N}),{distance:S,isOnBottomSide:D,isOnTopSide:_}=b.distanceFromPoint(h);if(S===0){c.blockElem=p,c.blockNode=be(f),c.foundAtIndex=g,c.distance=S,c.blockNode&&c.blockNode.getType()==="paragraph"&&c.blockNode.getTextContent()===""&&(!n&&!e.returnEmptyParagraphs&&(c.blockElem=null,c.blockNode=null),c.isFoundNodeEmptyParagraph=!0);break}else n&&S<c.distance&&(c.blockElem=p,c.blockNode=be(f),c.distance=S,c.foundAtIndex=g);y===et&&(_?y=ko:D?y=Do:y=1/0),g+=y}}),M.props=e,M.result={blockElem:c.blockElem,blockNode:c.blockNode,foundAtIndex:c.foundAtIndex,isFoundNodeEmptyParagraph:c.isFoundNodeEmptyParagraph},{blockElem:c.blockElem,blockNode:c.blockNode,foundAtIndex:c.foundAtIndex,isFoundNodeEmptyParagraph:c.isFoundNodeEmptyParagraph}}function xe(e,t){return!!e.closest(`.${t}`)}var Lo=["IMG","INPUT","TEXTAREA","SELECT","BUTTON","VIDEO","OBJECT","EMBED","IFRAME","HR"];function tt(e){if(!e||Lo.includes(e.tagName)||e.offsetHeight===0||e.offsetWidth===0)return!1;let t=window.getComputedStyle(e);return!(t.display==="table-cell"||t.position==="absolute"||t.visibility==="hidden"||t.opacity==="0")}function Ce(e,t,o,r=0){if(!e){t.style.visibility="hidden",t.style.opacity="0",t.style.transform="translate(-10000px, -10000px)";return}let n=e.getBoundingClientRect(),i=window.getComputedStyle(e),s=t.getBoundingClientRect(),l=o.getBoundingClientRect(),d;if(["LexicalEditorTheme__block","LexicalEditorTheme__upload","LexicalEditorTheme__relationship"].some(a=>e.classList.contains(a)||e.firstElementChild?.classList.contains(a)))d=n.top+8-l.top;else{let a=tt(e)?parseInt(i.lineHeight,10):0;d=n.top+(a-s.height)/2-l.top}let m=r;t.style.opacity="1",t.style.visibility="visible",t.style.transform=`translate(${m}px, ${d}px)`}var Ko="add-block-menu",Ee=1/0;function jo(e){return e===0?1/0:Ee>=0&&Ee<e?Ee:Math.floor(e/2)}function zo(e,t,o){let r=t.parentElement,{editorConfig:n}=R(),i=n?.admin?.hideGutter?-24:12,s=Io(null),[l,d]=$o(null);ot(()=>{function m(a){let c=a.target;if(!Oo(c))return;let g=X(r,a.pageX,a.pageY,c);if(g===-1){d(null);return}if(xe(c,Ko))return;let y=G(e),{blockElem:f,blockNode:p,foundAtIndex:h}=ee({anchorElem:t,cache_threshold:0,editor:e,horizontalOffset:-g,point:new j(a.x,a.y),returnEmptyParagraphs:!0,startIndex:jo(y.length),useEdgeAsDefault:!1});Ee=h,f&&p&&(l?.node!==p||l?.elem!==f)&&d({elem:f,node:p})}return document?.addEventListener("mousemove",m),()=>{document?.removeEventListener("mousemove",m)}},[r,t,e,l]),ot(()=>{s.current&&Ce(l?.elem??null,s.current,t,i)},[t,l,i]);let u=Bo(m=>{let a=l;a?.node&&(e.update(()=>{let c=!0;if((a?.node.getType()!=="paragraph"||a.node.getTextContent()!=="")&&(c=!1),!c){let g=Mo();a?.node.insertAfter(g),setTimeout(()=>{a={elem:e.getElementByKey(g.getKey()),node:g},d(a)},0)}}),setTimeout(()=>{e.update(()=>{e.focus(),a?.node&&"select"in a.node&&typeof a.node.select=="function"&&a.node.select()})},1),setTimeout(()=>{e.dispatchCommand(Ke,{node:a?.node})},2),m.stopPropagation(),m.preventDefault())},[e,l]);return Fo(De(rt.Fragment,{children:De("button",{"aria-label":"Add block",className:"icon add-block-menu",onClick:m=>{u(m)},ref:s,type:"button",children:De("div",{className:o?"icon":""})})}),t)}function nt(e){let{anchorElem:t}=e,o=t===void 0?document.body:t,[r]=Ao();return zo(r,o,r._editable)}import{jsx as Ne,jsxs as dt}from"react/jsx-runtime";import{useLexicalComposerContext as Jo}from"@lexical/react/LexicalComposerContext.js";import{eventFiles as ut}from"@lexical/rich-text";import{useTranslation as Qo}from"@payloadcms/ui";import{$getNearestNodeFromDOMNode as ft,$getNodeByKey as Xo,isHTMLElement as ke}from"lexical";import*as yt from"react";import{useEffect as ve,useId as Zo,useRef as se,useState as mt}from"react";import{createPortal as er}from"react-dom";var it=0,Ho=-24;var U=0;function st(e,t,o,r,n,i,s,l,d,u=!1){let{height:m,top:a}=r.getBoundingClientRect(),{top:c,width:g}=s.getBoundingClientRect(),{marginBottom:y,marginTop:f}=ye(r),p=a,h=i>=a+m/2+window.scrollY,C=!1;if(n?.elem)if(r!==n?.elem)(h&&n?.elem&&n?.elem===r.nextElementSibling||!h&&n?.elem&&n?.elem===r.previousElementSibling)&&(U++,U<200&&(C=!0));else{U++;let S=n?.boundingBox?.y,D=r.getBoundingClientRect().y;(h===n?.isBelow&&S===D||U<200)&&(C=!1)}if(C)return{isBelow:h,willStayInSamePosition:C};u?p+=m/2:h?p+=m+y/2:p-=f/2;let x=0;u||(h?x=-it:x=it);let N=p-c+x,b=Ho-t;return o.style.width=`calc(${g}px - ${e} - var(--spacer-5))`,o.style.opacity=".8",o.style.transform=`translate(${b}px, calc(${N}px - 2px))`,n?.elem&&(n.elem.style.opacity="",n?.elem===r?h?n.elem.style.marginTop="":n.elem.style.marginBottom="":(n.elem.style.marginBottom="",n.elem.style.marginTop="")),U=0,{isBelow:h,willStayInSamePosition:C}}import{mergeRegister as Vo}from"@lexical/utils";import{$getSelection as Wo,$isNodeSelection as Yo,$isRangeSelection as Go,COMMAND_PRIORITY_HIGH as lt,KEY_ARROW_DOWN_COMMAND as Uo,KEY_ARROW_UP_COMMAND as qo}from"lexical";import{useEffect as at}from"react";function ct({editor:e,instructionsID:t}){at(()=>{let o=({direction:r,event:n})=>{if(!e.isEditable()||!n.altKey||!n.shiftKey||n.ctrlKey||n.metaKey)return!1;let i=Wo(),l=(Go(i)&&i.isCollapsed()?i.anchor.getNode():Yo(i)&&i.getNodes().length===1?i.getNodes()[0]:null)?.getTopLevelElement();if(!l)return!1;n.preventDefault();let d=r===-1?l.getPreviousSibling():l.getNextSibling();return d&&(r===-1?d.insertBefore(l):d.insertAfter(l)),!0};return Vo(e.registerCommand(qo,r=>o({direction:-1,event:r}),lt),e.registerCommand(Uo,r=>o({direction:1,event:r}),lt))},[e]),at(()=>{let o,r=e.registerRootListener(n=>{if(o?.(),!n)return;let i=n.getAttribute("aria-describedby");n.setAttribute("aria-describedby",[i,t].filter(Boolean).join(" ")),o=()=>{i===null?n.removeAttribute("aria-describedby"):n.setAttribute("aria-describedby",i)}});return()=>{r(),o?.()}},[e,t])}var tr="draggable-block-menu",pt="application/x-lexical-drag-block",le=1/0;function gt(e){return e===0?1/0:le>=0&&le<e?le:Math.floor(e/2)}function or(e,t){let{transform:o}=t.style;e.setDragImage(t,0,0),setTimeout(()=>{t.style.transform=o})}function ht(e,t){e&&(e.style.opacity="0"),t&&(t.style.opacity="",t.style.marginBottom="",t.style.marginTop="")}function rr(e,t,o){let r=t.parentElement,n=Zo(),{t:i}=Qo();ct({editor:e,instructionsID:n});let s=se(null),l=se(null),d=se(null),u=se(!1),m=se([]),[a,c]=mt(null),[g,y]=mt(null),{editorConfig:f}=R(),p=f?.admin?.hideGutter?-44:-8;ve(()=>{function x(N){let b=N.target;if(!ke(b))return;let S=X(r,N.pageX,N.pageY,b);if(S===-1){c(null);return}if(xe(b,tr))return;let D=G(e),{blockElem:_,foundAtIndex:B,isFoundNodeEmptyParagraph:V}=ee({anchorElem:t,cache_threshold:0,editor:e,horizontalOffset:-S,point:new j(N.x,N.y),startIndex:gt(D.length),useEdgeAsDefault:!1,verbose:!1});le=B,!(!_&&!V)&&a!==_&&c(_)}return document?.addEventListener("mousemove",x),()=>{document?.removeEventListener("mousemove",x)}},[r,t,e,a]),ve(()=>{s.current&&Ce(a,s.current,t,p)},[t,a,p]),ve(()=>{function x(b){if(!u.current)return!1;let[S]=ut(b);if(S)return!1;let{pageY:D,target:_}=b;if(!ke(_))return!1;let B=X(r,b.pageX,b.pageY,_,100,50),V=G(e),{blockElem:w,foundAtIndex:k,isFoundNodeEmptyParagraph:I}=ee({anchorElem:t,editor:e,fuzzy:!0,horizontalOffset:-B,point:new j(b.x,b.y),startIndex:gt(V.length),useEdgeAsDefault:!0,verbose:!0});le=k;let $=l.current;if(w===null||$===null)return!1;if(b.preventDefault(),b.dataTransfer.dropEffect="move",a!==w){let{isBelow:T,willStayInSamePosition:q}=st(f?.admin?.hideGutter?"0px":"var(--spacer-5)",p+(f?.admin?.hideGutter?s?.current?.getBoundingClientRect()?.width??0:-(s?.current?.getBoundingClientRect()?.width??0)),$,w,g,D,t,b,d,I);q||y({boundingBox:w.getBoundingClientRect(),elem:w,isBelow:T})}else g?.elem&&(ht($,g.elem),y({boundingBox:w.getBoundingClientRect(),elem:w,isBelow:!1}));return!0}function N(b){if(!u.current)return!1;let[S]=ut(b);if(S)return!1;let{dataTransfer:D,pageY:_,target:B}=b,V=D?.getData(pt)||"";return e.update(()=>{let w=Xo(V);if(!w||!ke(B))return!1;let k=X(r,b.pageX,b.pageY,B,100,50),{blockElem:I,isFoundNodeEmptyParagraph:$}=ee({anchorElem:t,editor:e,fuzzy:!0,horizontalOffset:-k,point:new j(b.x,b.y),useEdgeAsDefault:!0});if(!I)return!1;let T=ft(I);if(!T)return!1;if(T===w)return!0;let{height:q,top:J}=Z(I),Se=_>=J+q/2+window.scrollY;$?(T.insertBefore(w),T.remove()):Se?T.insertAfter(w):T.insertBefore(w),a!==null&&c(null),document.querySelectorAll(".lexical-block-highlighter").forEach(L=>{L.remove()});let de=e.getElementByKey(w.getKey()),F=setTimeout(()=>{let L=de?.getBoundingClientRect();if(!L)return;let P=document.createElement("div");P.className="lexical-block-highlighter",P.style.backgroundColor="var(--color-bg-inverse)",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=`${L.height+8}px`,P.style.width=`${L.width+8}px`,P.style.top=`${L.top+window.scrollY-4}px`,P.style.left=`${L.left-4}px`;let ue=setTimeout(()=>{P.style.opacity="0";let we=setTimeout(()=>{P.remove()},500);m.current.push(we)},1e3);m.current.push(ue)},120);m.current.push(F)}),!0}return document.addEventListener("dragover",x),document.addEventListener("drop",N),()=>{document.removeEventListener("dragover",x),document.removeEventListener("drop",N),m.current.forEach(clearTimeout),m.current=[]}},[r,p,t,e,g,a,f?.admin?.hideGutter]);function h(x){let N=x.dataTransfer;if(!N||!a)return;or(N,a),N.effectAllowed="move";let b="";e.update(()=>{let S=ft(a);S&&(b=S.getKey())}),u.current=!0,N.setData(pt,b)}function C(){u.current=!1,g?.elem&&ht(l.current,g?.elem)}return er(dt(yt.Fragment,{children:[dt("span",{className:"sr-only",id:n,children:[i("general:moveUp"),": Alt + Shift + \u2191. ",i("general:moveDown"),": Alt + Shift + \u2193."]}),Ne("button",{"aria-label":"Drag to move",className:"icon draggable-block-menu",draggable:!0,onDragEnd:C,onDragStart:h,ref:s,type:"button",children:Ne("div",{className:o?"icon":""})}),Ne("div",{className:"draggable-block-target-line",ref:l}),Ne("div",{className:"debug-highlight",ref:d})]}),t)}function bt(e){let{anchorElem:t}=e,o=t===void 0?document.body:t,[r]=Jo();return rr(r,o,r._editable)}import{c as nr}from"react/compiler-runtime";import{jsx as Le}from"react/jsx-runtime";import{useLexicalComposerContext as ir}from"@lexical/react/LexicalComposerContext";import{useTranslation as sr}from"@payloadcms/ui";import{$createParagraphNode as lr,$getRoot as ar}from"lexical";import"react";var xt="insert-paragraph-at-end",Ct=()=>{let e=nr(5),[t]=ir(),{editorConfig:o}=R(),{t:r}=sr();if(o?.admin?.hideInsertParagraphAtEnd)return null;let n;e[0]!==t?(n=()=>{t.update(cr)},e[0]=t,e[1]=n):n=e[1];let i=n,s;return e[2]!==i||e[3]!==r?(s=Le("button",{"aria-label":r("lexical:general:insertParagraph"),className:xt,onClick:i,type:"button",children:Le("span",{className:`${xt}-inside`,children:Le(Ie,{size:16})})}),e[2]=i,e[3]=r,e[4]=s):s=e[4],s};function cr(){let e=lr();ar().append(e),e.select()}import{c as dr}from"react/compiler-runtime";import{registerMarkdownShortcuts as ur}from"@lexical/markdown";import{useLexicalComposerContext as fr}from"@lexical/react/LexicalComposerContext";import*as Et from"react";var Nt=()=>{let e=dr(4),{editorConfig:t}=R(),[o]=fr(),r,n;return e[0]!==o||e[1]!==t.features.markdownTransformers?(r=()=>ur(o,t.features.markdownTransformers??[]),n=[o,t.features.markdownTransformers],e[0]=o,e[1]=t.features.markdownTransformers,e[2]=r,e[3]=n):(r=e[2],n=e[3]),Et.useEffect(r,n),null};import{c as mr}from"react/compiler-runtime";import{useLexicalComposerContext as pr}from"@lexical/react/LexicalComposerContext.js";import{$getRoot as gr}from"lexical";import{useEffect as hr}from"react";function yr(e){e.update(()=>{let t=o=>{let r=o.getType();if((r==="block"||r==="inlineBlock")&&o.markDirty(),"getChildren"in o&&typeof o.getChildren=="function")for(let n of o.getChildren())t(n)};t(gr())})}function St(){let e=mr(5),[t]=pr(),{currentView:o,views:r}=K(),n,i;return e[0]!==o||e[1]!==t||e[2]!==r?(n=()=>{r&&(o==="default"?r.default?Pe(t,r.default?.nodes):Re(t):r[o]&&(Re(t),Pe(t,r[o]?.nodes)),yr(t))},i=[t,r,o],e[0]=o,e[1]=t,e[2]=r,e[3]=n,e[4]=i):(n=e[3],i=e[4]),hr(n,i),null}import{useLexicalComposerContext as br}from"@lexical/react/LexicalComposerContext";import{$getSelection as xr,$isRangeSelection as Cr,RootNode as Er}from"lexical";import{useEffect as Nr}from"react";function wt(){let[e]=br();return Nr(()=>e.registerNodeTransform(Er,t=>{let o=xr();if(Cr(o)){let r=o.anchor.getNode(),n=o.focus.getNode();(!r.isAttached()||!n.isAttached())&&(t.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}),[e]),null}import{useLexicalComposerContext as Sr}from"@lexical/react/LexicalComposerContext";import{$getSelection as wr,COMMAND_PRIORITY_LOW as Pr,SELECT_ALL_COMMAND as Rr}from"lexical";import{useEffect as Tr}from"react";function Pt(){let[e]=Sr();return Tr(()=>e.registerCommand(Rr,()=>{if(wr())return!1;let o=document.activeElement;return o instanceof HTMLInputElement&&o.select(),!0},Pr),[e]),null}import{jsx as te,jsxs as Tt}from"react/jsx-runtime";import{useLexicalComposerContext as Dr}from"@lexical/react/LexicalComposerContext.js";import{useTranslation as _t}from"@payloadcms/ui";import{useCallback as kr,useMemo as vr,useState as Lr}from"react";import"react";import*as Dt from"react-dom";import{c as _r}from"react/compiler-runtime";import"react";function Rt(e,t){let o=_r(4),{maxLength:r,minLength:n}=t,i=r===void 0?75:r,s=n===void 0?1:n,l;return o[0]!==i||o[1]!==s||o[2]!==e?(l=d=>{let{query:u}=d,m="[^"+e+Fe+"\\s]",c=new RegExp("(^|\\s|\\()(["+e+"]((?:"+m+"){0,"+i+"}))$").exec(u);if(c!==null){let g=c[1],y=c[3];if(y.length>=s)return{leadOffset:c.index+g.length,matchingString:y,replaceableString:c[2]}}return null},o[0]=i,o[1]=s,o[2]=e,o[3]=l):l=o[3],l}var O="slash-menu-popup";function Ar({isSelected:e,item:t,onClick:o,onMouseEnter:r,ref:n}){let{fieldProps:{featureClientSchemaMap:i,schemaPath:s}}=R(),{i18n:l}=_t(),d=`${O}__item ${O}__item-${t.key}`;e&&(d+=` ${O}__item--selected`);let u=t.key;return t.label&&(u=typeof t.label=="function"?t.label({featureClientSchemaMap:i,i18n:l,schemaPath:s}):t.label),u.length>25&&(u=u.substring(0,25)+"..."),Tt("button",{"aria-selected":e,className:d,id:O+"__item-"+t.key,onClick:o,onMouseEnter:r,ref:n,role:"option",tabIndex:-1,type:"button",children:[t?.Icon&&te(t.Icon,{}),te("span",{className:`${O}__item-text`,children:u})]},t.key)}function kt({anchorElem:e=document.body}){let[t]=Dr(),[o,r]=Lr(null),{editorConfig:n}=R(),{i18n:i}=_t(),{fieldProps:{featureClientSchemaMap:s,schemaPath:l}}=R(),d=Rt("/",{minLength:0}),u=kr(()=>{let a=[];for(let c of n.features.slashMenu.dynamicGroups)if(o){let g=c({editor:t,queryString:o});a=a.concat(g)}return a},[t,o,n?.features]),m=vr(()=>{let a=[];for(let c of n?.features.slashMenu.groups??[])a.push(c);if(o){let c=o.toLowerCase().replace(/[\s\-_]/g,"");a=a.map(y=>{let f=y.items.filter(p=>{let h=p.key;return p.label&&(h=typeof p.label=="function"?p.label({featureClientSchemaMap:s,i18n:i,schemaPath:l}):p.label),new RegExp(o,"gi").exec(h)||h.toLowerCase().replace(/[\s\-_]/g,"").includes(c)?!0:p.keywords!=null?p.keywords.some(x=>new RegExp(o,"gi").exec(x)?!0:x.toLowerCase().replace(/[\s\-_]/g,"").includes(c)):!1});return f.length?{...y,items:f}:null}),a=a.filter(y=>y!=null);let g=u();for(let y of g){let f=a.find(p=>p.key===y.key);f?a=a.filter(p=>p.key!==y.key):f={...y,items:[]},f?.items?.length&&(f.items=f.items.concat(f.items)),a.push(f)}}return a},[o,n?.features.slashMenu.groups,u,s,i,l]);return te(je,{anchorElem:e,groups:m,menuRenderFn:(a,{selectedItemKey:c,selectItemAndCleanUp:g,setSelectedItemKey:y})=>a.current&&m.length?Dt.createPortal(te("div",{className:O,"data-theme":"dark",children:m.map(f=>{let p=f.key;return f.label&&s&&(p=typeof f.label=="function"?f.label({featureClientSchemaMap:s,i18n:i,schemaPath:l}):f.label),Tt("div",{className:`${O}__group ${O}__group-${f.key}`,children:[te("div",{className:`${O}__group-title`,children:p}),f.items.map((h,C)=>te(Ar,{index:C,isSelected:c===h.key,item:h,onClick:()=>{y(h.key),g(h)},onMouseEnter:()=>{y(h.key)},ref:x=>{h.ref={current:x}}},h.key))]},f.key)})}),a.current):null,onQueryChange:r,triggerFn:d})}import{c as Mr}from"react/compiler-runtime";import{useLexicalComposerContext as Or}from"@lexical/react/LexicalComposerContext";import{TEXT_TYPE_TO_FORMAT as Br,TextNode as Ir}from"lexical";import{useEffect as $r}from"react";function vt(e){let t=Mr(6),{features:o}=e,[r]=Or(),n;t[0]!==r||t[1]!==o.enabledFormats?(n=()=>{let s=Fr(o.enabledFormats);if(s.length!==0)return r.registerNodeTransform(Ir,l=>{s.forEach(d=>{l.hasFormat(d)&&l.toggleFormat(d)})})},t[0]=r,t[1]=o.enabledFormats,t[2]=n):n=t[2];let i;return t[3]!==r||t[4]!==o?(i=[r,o],t[3]=r,t[4]=o,t[5]=i):i=t[5],$r(n,i),null}function Fr(e){let t=Object.keys(Br),o=new Set(e);return t.filter(r=>!o.has(r))}import{c as Kr}from"react/compiler-runtime";import{jsx as Lt}from"react/jsx-runtime";import{useLexicalComposerContext as jr}from"@lexical/react/LexicalComposerContext";import{ContentEditable as zr}from"@lexical/react/LexicalContentEditable.js";import{useLexicalEditable as Hr}from"@lexical/react/useLexicalEditable";import{getTranslation as Vr}from"@payloadcms/translations";import{useTranslation as Wr}from"@payloadcms/ui";import"react";function At(e){let t=Kr(10),{className:o,editorConfig:r,instructionsID:n}=e,{fieldProps:i}=R(),{i18n:s,t:l}=Wr(),[,d]=jr(),{getTheme:u}=d,m=Hr(),a;if(t[0]!==o||t[1]!==r?.admin?.placeholder||t[2]!==i.field.label||t[3]!==i.field.required||t[4]!==u||t[5]!==s||t[6]!==n||t[7]!==m||t[8]!==l){let c=u();a=Lt(zr,{"aria-describedby":n,"aria-label":Vr(i.field.label||"",s),"aria-required":i.field.required||void 0,className:o??"ContentEditable__root",...m?{"aria-placeholder":l("lexical:general:placeholder"),placeholder:Lt("p",{className:c?.placeholder,children:r?.admin?.placeholder??l("lexical:general:placeholder")})}:{placeholder:null}}),t[0]=o,t[1]=r?.admin?.placeholder,t[2]=i.field.label,t[3]=i.field.required,t[4]=u,t[5]=s,t[6]=n,t[7]=m,t[8]=l,t[9]=a}else a=t[9];return a}var Ot=e=>{let t=Yr(5),{editorConfig:o,editorContainerRef:r,isSmallWidthViewport:n,onChange:i,rtl:s}=e,l=R(),[d]=Gr(),u=Xr(),{t:m}=Zr(),a=z.useId(),c=u&&o.features.enabledFeatures.includes("indent"),[g,y]=rn(null),f;t[0]===Symbol.for("react.memo_cache_sentinel")?(f=x=>{x!==null&&y(x)},t[0]=f):f=t[0];let p=f,h,C;return t[1]!==d||t[2]!==l?(h=()=>{if(!l?.uuid){console.error("Lexical Editor must be used within an EditorConfigProvider");return}l?.parentEditor?.uuid&&l.parentEditor?.registerChild(l.uuid,l);let x=()=>{l.focusEditor(l)},N=()=>{l.blurEditor(l)},b=d.registerCommand(tn,()=>(x(),!0),Mt),S=d.registerCommand(en,()=>(N(),!0),Mt);return()=>{b(),S(),l.parentEditor?.unregisterChild?.(l.uuid)}},C=[d,l],t[1]=d,t[2]=l,t[3]=h,t[4]=C):(h=t[3],C=t[4]),on(h,C),ae(z.Fragment,{children:[o.features.plugins?.map(nn),ae("div",{className:"editor-container",dir:s?"rtl":void 0,ref:r,children:[o.features.plugins?.map(sn),E(Qr,{contentEditable:E("div",{className:"editor-scroller",children:E("div",{className:"editor",ref:p,children:E(At,{editorConfig:o,instructionsID:c?a:void 0})})}),ErrorBoundary:Ur}),E(wt,{}),u&&E(Ct,{}),E(Qe,{}),E(Ge,{}),E(vt,{features:o.features}),E(Pt,{}),E(St,{}),u&&E(Jr,{ignoreSelectionChange:!0,onChange:(x,N,b)=>{(!b.has("focus")||b.size>1)&&i?.(x,N,b)}}),g&&ae(z.Fragment,{children:[!n&&u&&ae(z.Fragment,{children:[o.admin?.hideDraggableBlockElement?null:E(bt,{anchorElem:g}),o.admin?.hideAddBlockButton?null:E(nt,{anchorElem:g})]}),o.features.plugins?.map(x=>{if(x.position==="floatingAnchorElem"&&!(x.desktopOnly===!0&&n))return E(W,{anchorElem:g,clientProps:x.clientProps,plugin:x},x.key)}),u&&E(z.Fragment,{children:E(kt,{anchorElem:g})})]}),u&&ae(z.Fragment,{children:[E(qr,{}),o?.features?.markdownTransformers?.length>0&&E(Nt,{})]}),o.features.plugins?.map(ln),o.features.plugins?.map(an)]}),c&&E("p",{className:"ContentEditable__keyboard-hint",id:a,children:m("lexical:indent:keyboardHint")}),o.features.plugins?.map(cn)]})};function nn(e){if(e.position==="aboveContainer")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}function sn(e){if(e.position==="top")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}function ln(e){if(e.position==="normal")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}function an(e){if(e.position==="bottom")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}function cn(e){if(e.position==="belowContainer")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}var It=({children:e,providers:t})=>{if(!t?.length)return e;let o=t[0];return t.length>1?H(o,{children:H(It,{providers:t.slice(1),children:e})}):H(o,{children:e})},$t=e=>{let{composerKey:t,editorConfig:o,fieldProps:r,isSmallWidthViewport:n,onChange:i,readOnly:s,rtl:l,value:d}=e,{currentView:u,views:m}=K(),a=R(),c=un(),g=Bt.useRef(null),y=fn(()=>{if(d&&typeof d!="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(d));if(d&&Array.isArray(d)&&!("root"in d))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(d&&"jsonContent"in d)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");let f=m?.[u]?.nodes;return{editable:s!==!0,editorState:d!=null?JSON.stringify(d):void 0,namespace:o.lexical.namespace,nodes:He({editorConfig:o,nodeViews:f}),onError:p=>{throw p},theme:o.lexical.theme}},[o,m,u]);return y?H(dn,{initialConfig:y,children:H(Be,{editorConfig:o,editorContainerRef:g,fieldProps:r,parentContext:a?.editDepth===c?a:void 0,children:H(It,{providers:o.features.providers,children:H(Ot,{editorConfig:o,editorContainerRef:g,isSmallWidthViewport:n,onChange:i,rtl:l})})})},t+y.editable+u):H("p",{children:"Loading..."})};import{c as mn}from"react/compiler-runtime";import{jsx as oe,jsxs as pn}from"react/jsx-runtime";import{ChevronIcon as gn,Popup as hn,PopupList as Ft}from"@payloadcms/ui";import"react";function Kt(){let e=mn(5),{currentView:t,setCurrentView:o,views:r}=K();if(!r||Object.keys(r).length===0)return null;let n,i;if(e[0]!==t||e[1]!==o||e[2]!==r){i=Symbol.for("react.early_return_sentinel");e:{let s=Object.keys(r);if(!s.some(bn)){i=null;break e}let d=["default",...s.filter(yn)],u=t.charAt(0).toUpperCase()+t.slice(1);n=oe("div",{className:"lexical-view-selector",children:oe(hn,{button:pn("button",{className:"lexical-view-selector__button",type:"button",children:[oe("span",{className:"lexical-view-selector__label",children:u}),oe(gn,{className:"lexical-view-selector__icon"})]}),buttonType:"custom",horizontalAlign:"left",popupType:"menu",render:m=>{let{close:a}=m;return oe(Ft.ButtonGroup,{children:d.map(c=>{let g=c.charAt(0).toUpperCase()+c.slice(1);return oe(Ft.Button,{active:c===t,disabled:c===t,onClick:()=>{o?.(c),a()},children:g},c)})})},size:"large"})})}e[0]=t,e[1]=o,e[2]=r,e[3]=n,e[4]=i}else n=e[3],i=e[4];return i!==Symbol.for("react.early_return_sentinel")?i:n}function yn(e){return e!=="default"}function bn(e){return e!=="default"}var re="rich-text-lexical",On=e=>{let{editorConfig:t,field:o,field:{admin:{className:r,description:n,readOnly:i}={},label:s,localized:l,required:d},path:u,readOnly:m,schemaPath:a,validate:c}=e,{i18n:g}=kn(),y=m||i,f=Dn(),{config:{localization:p}}=Pn(),h=wn({fieldLocalized:l,locale:f,localizationConfig:p||void 0}),C=Rn(),{isControlledByParent:x}=K(),N=Ht((A,ne)=>typeof c=="function"?c(A,{...ne,required:d}):!0,[c,d]),{customComponents:{AfterInput:b,BeforeInput:S,Description:D,Error:_,Label:B}={},disabled:V,initialValue:w,path:k,setValue:I,showError:$,value:T}=_n({potentiallyStalePath:u,validate:N}),q=y||V,[J,Ae]=Wt(!1),[Se,Me]=Wt(),de=zt.useRef(w),F=zt.useRef(T);Vt(()=>{let A=()=>{let ne=window.matchMedia("(max-width: 768px)").matches;ne!==J&&Ae(ne)};return A(),window.addEventListener("resize",A),()=>{window.removeEventListener("resize",A)}},[J]);let L=["field-type",re,r,$&&"error",q&&`${re}--read-only`,t?.admin?.hideGutter!==!0&&!J?`${re}--show-gutter`:null].filter(Boolean).join(" "),P=`${k}.${C}`,ue=$e(),we=Ht(A=>{ue(()=>{let Oe=A.toJSON();F.current=Oe,I(Oe)})},[I,ue]),Yt=An(()=>vn(o),[o]),Gt=Tn(A=>{F.current!==T&&!Ln(F.current!=null?JSON.parse(JSON.stringify(F.current)):F.current,T)&&(de.current=A,F.current=T,Me(new Date))});return Vt(()=>{Object.is(w,de.current)||Gt(w)},[w]),ce("div",{"aria-label":xn(s||"",g),className:L,"data-field-path":k,"data-field-schemapath":a,"data-lexical-view":t?.view,role:"group",style:Yt,children:[ce("div",{className:`${re}__label-row`,children:[B||v(Sn,{hasRequiredAccessibleState:!0,label:s,localized:l,path:k,required:d}),!x&&v(Kt,{})]}),ce("div",{className:`${re}__wrap`,children:[v(jt,{CustomComponent:_,Fallback:v(Nn,{path:k,showError:$})}),ce(Mn,{fallbackRender:Bn,onReset:()=>{},children:[S,v("div",{className:`${re}__editor-content`,children:v(Cn,{modalSlugPrefix:`lexical-${k}`,children:v($t,{composerKey:P,editorConfig:t,fieldProps:e,isSmallWidthViewport:J,onChange:we,readOnly:q,rtl:h,value:T},JSON.stringify({path:k,rerenderProviderKey:Se}))})}),b]}),v(jt,{CustomComponent:D,Fallback:v(En,{description:n,path:k})})]})]},P)};function Bn({error:e}){return ce("div",{className:"errorBoundary",role:"alert",children:[v("p",{children:"Something went wrong:"}),v("pre",{style:{color:"red"},children:e instanceof Error?e.message:String(e)})]})}var sa=On;export{sa as RichText};
2
+ //# sourceMappingURL=Field-W2ABOM7M.js.map