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