@payloadcms/richtext-lexical 4.0.0-internal.293e026 → 4.0.0-internal.2fddfc0

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