@payloadcms/richtext-lexical 3.28.0 → 3.28.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.
- package/dist/exports/client/{Field-FLAQN6LU.js → Field-IUDF2DGI.js} +2 -2
- package/dist/exports/client/{RelationshipComponent-JPESGV4Q.js → RelationshipComponent-APF3CN47.js} +2 -2
- package/dist/exports/client/chunk-46KMRCKV.js +2 -0
- package/dist/exports/client/chunk-46KMRCKV.js.map +7 -0
- package/dist/exports/client/chunk-BZZVLW4U.js +2 -0
- package/dist/exports/client/chunk-BZZVLW4U.js.map +7 -0
- package/dist/exports/client/{chunk-PUXDVIHC.js → chunk-Y2GOLUGU.js} +2 -2
- package/dist/exports/client/{component-P5K7Z5NW.js → component-Y3OSWJM5.js} +2 -2
- package/dist/exports/client/componentInline-ZB4EY7EQ.js +2 -0
- package/dist/exports/client/index.js +4 -4
- package/dist/exports/client/index.js.map +3 -3
- package/dist/features/blocks/client/component/BlockContent.d.ts.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.js +2 -4
- package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +2 -4
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.js +3 -3
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js +2 -2
- package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -1
- package/dist/lexical/config/client/EditorConfigProvider.js +4 -4
- package/dist/lexical/config/client/EditorConfigProvider.js.map +1 -1
- package/package.json +7 -7
- package/dist/exports/client/chunk-3LGFOM34.js +0 -2
- package/dist/exports/client/chunk-3LGFOM34.js.map +0 -7
- package/dist/exports/client/chunk-QBDC3MVG.js +0 -2
- package/dist/exports/client/chunk-QBDC3MVG.js.map +0 -7
- package/dist/exports/client/componentInline-IBB73SHH.js +0 -2
- /package/dist/exports/client/{Field-FLAQN6LU.js.map → Field-IUDF2DGI.js.map} +0 -0
- /package/dist/exports/client/{RelationshipComponent-JPESGV4Q.js.map → RelationshipComponent-APF3CN47.js.map} +0 -0
- /package/dist/exports/client/{chunk-PUXDVIHC.js.map → chunk-Y2GOLUGU.js.map} +0 -0
- /package/dist/exports/client/{component-P5K7Z5NW.js.map → component-Y3OSWJM5.js.map} +0 -0
- /package/dist/exports/client/{componentInline-IBB73SHH.js.map → componentInline-ZB4EY7EQ.js.map} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{c as Re,f as _,h as ke,i as we,j as Te,k as ve,l as De}from"./chunk-XO6X2M3F.js";import{a as Se,b as P}from"./chunk-3LGFOM34.js";import{jsx as F,jsxs as pe}from"react/jsx-runtime";import{FieldDescription as rn,FieldError as sn,FieldLabel as ln,RenderCustomComponent as gt,useEditDepth as an,useEffectEvent as cn,useField as un}from"@payloadcms/ui";import{mergeFieldStyles as dn}from"@payloadcms/ui/shared";import ht,{useCallback as yt,useEffect as xt,useMemo as mn,useState as Et}from"react";import{ErrorBoundary as fn}from"react-error-boundary";import"./bundled.css";import{jsx as O}from"react/jsx-runtime";import{LexicalComposer as tn}from"@lexical/react/LexicalComposer.js";import{useEditDepth as on}from"@payloadcms/ui";import*as mt from"react";import{useMemo as nn}from"react";import{c as Ko}from"react/compiler-runtime";import{jsx as b,jsxs as te}from"react/jsx-runtime";import{useLexicalComposerContext as Ho}from"@lexical/react/LexicalComposerContext.js";import{LexicalErrorBoundary as jo}from"@lexical/react/LexicalErrorBoundary.js";import{HistoryPlugin as zo}from"@lexical/react/LexicalHistoryPlugin.js";import{OnChangePlugin as Wo}from"@lexical/react/LexicalOnChangePlugin.js";import{RichTextPlugin as Yo}from"@lexical/react/LexicalRichTextPlugin.js";import{BLUR_COMMAND as Go,COMMAND_PRIORITY_LOW as ut,FOCUS_COMMAND as Vo}from"lexical";import*as Q from"react";import{useEffect as Uo,useState as qo}from"react";import{jsx as Me}from"react/jsx-runtime";import"react";var K=({anchorElem:t,clientProps:e,plugin:o})=>o.position==="floatingAnchorElem"&&t?o.Component&&Me(o.Component,{anchorElem:t,clientProps:e}):o.Component&&Me(o.Component,{clientProps:e});import{c as Pt}from"react/compiler-runtime";import{useLexicalComposerContext as St}from"@lexical/react/LexicalComposerContext";import{$findMatchingParent as oe,mergeRegister as Rt}from"@lexical/utils";import{$createNodeSelection as kt,$getEditor as X,$getNearestNodeFromDOMNode as wt,$getSelection as ne,$isDecoratorNode as H,$isElementNode as xe,$isLineBreakNode as Tt,$isNodeSelection as re,$isRangeSelection as Be,$isRootOrShadowRoot as vt,$isTextNode as Dt,$setSelection as Le,CLICK_COMMAND as Mt,COMMAND_PRIORITY_LOW as G,KEY_ARROW_DOWN_COMMAND as Bt,KEY_ARROW_UP_COMMAND as Lt,KEY_BACKSPACE_COMMAND as It,KEY_DELETE_COMMAND as At,SELECTION_CHANGE_COMMAND as _t}from"lexical";import{useEffect as Ot}from"react";function Ie(){let t=Pt(3),[e]=St(),o=Wt,r,n;return t[0]!==e?(r=()=>Rt(e.registerCommand(Mt,zt,G),e.registerCommand(At,o,G),e.registerCommand(It,o,G),e.registerCommand(_t,jt,G),e.registerCommand(Lt,Kt,G),e.registerCommand(Bt,Ft,G)),n=[e],t[0]=e,t[1]=r,t[2]=n):(r=t[1],n=t[2]),Ot(r,n),null}function Ft(t){let e=ne();if(re(e)){t.preventDefault();let i=e.getNodes()[0]?.getNextSibling();if(H(i)){let p=X().getElementByKey(i.getKey());return p&&Z({element:p,node:i}),!0}if(!xe(i))return!0;let l=i.getFirstDescendant()??i;return l&&(oe(l,ie)?.selectEnd(),t.preventDefault()),!0}if(!Be(e))return!1;let r=(e.isBackward()?e.anchor:e.focus).getNode(),n=oe(r,$t),c=n?.getNextSibling();if(!n||c!==Ae(n))return!1;if(H(c)){let i=X().getElementByKey(c.getKey());if(i)return Z({element:i,node:c}),t.preventDefault(),!0}return!1}function $t(t){return Ae(t)!==null}function Kt(t){let e=ne();if(re(e)){let i=e.getNodes()[0]?.getPreviousSibling();if(H(i)){let p=X().getElementByKey(i.getKey());return p?(Z({element:p,node:i}),t.preventDefault(),!0):!1}if(!xe(i))return!1;let l=i.getLastDescendant()??i;return l?(oe(l,ie)?.selectStart(),t.preventDefault(),!0):!1}if(!Be(e))return!1;let r=(e.isBackward()?e.anchor:e.focus).getNode(),n=oe(r,Ht),c=n?.getPreviousSibling();if(!n||c!==_e(n))return!1;if(H(c)){let i=X().getElementByKey(c.getKey());if(i)return Z({element:i,node:c}),t.preventDefault(),!0}return!1}function Ht(t){return _e(t)!==null}function jt(){let t=Vt();return document.querySelector(".decorator-selected")?.classList.remove("decorator-selected"),t?(t.element?.classList.add("decorator-selected"),!0):!1}function zt(t){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let e=Gt(t);if(!e)return!0;let{target:o}=t;return!(o instanceof HTMLElement)||o.isContentEditable||o.closest('button, textarea, input, .react-select, .code-editor, .no-select-decorator, [role="button"]')?Le(null):Z(e),!0}function Wt(t){let e=ne();return re(e)?(t.preventDefault(),e.getNodes().forEach(Yt),!0):!1}function Yt(t){t.remove()}function Gt(t){if(!(t.target instanceof HTMLElement))return;let e=t.target.closest('[data-lexical-decorator="true"]');if(!(e instanceof HTMLElement))return;let o=wt(e);return H(o)?{element:e,node:o}:void 0}function Vt(){let t=ne();if(!re(t))return;let e=t.getNodes();if(e.length!==1)return;let o=e[0];return H(o)?{decorator:o,element:X().getElementByKey(o.getKey())}:void 0}function Z({element:t,node:e}){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let o=kt();o.add(e.getKey()),Le(o),t.scrollIntoView({behavior:"smooth",block:"nearest"}),t.classList.add("decorator-selected")}function ie(t){if(H(t)&&!t.isInline())return!0;if(!xe(t)||vt(t))return!1;let e=t.getFirstChild(),o=e===null||Tt(e)||Dt(e)||e.isInline();return!t.isInline()&&t.canBeEmpty()!==!1&&o}function Ae(t){let e=t.getNextSibling();for(;e!==null;){if(ie(e))return e;e=e.getNextSibling()}return null}function _e(t){let e=t.getPreviousSibling();for(;e!==null;){if(ie(e))return e;e=e.getPreviousSibling()}return null}import{jsx as Ee}from"react/jsx-runtime";import{useLexicalComposerContext as Zt}from"@lexical/react/LexicalComposerContext.js";import{$createParagraphNode as eo,isHTMLElement as to}from"lexical";import*as Ke from"react";import{useCallback as oo,useEffect as $e,useRef as no,useState as ro}from"react";import{createPortal as io}from"react-dom";var V=(t,e,o,r,n=50,c=25)=>{let i=0;if(t&&!t.contains(r)){let{bottom:l,left:u,right:p,top:h}=t.getBoundingClientRect(),a=h+window.scrollY,s=l+window.scrollY;if(o<a-c||o>s+c||e<u-n||e>p+n)return-1;(e<u||e>p)&&(i=e<u?e-u:e-p)}return i};import{$getNodeByKey as le}from"lexical";function U(t){let e=t.getBoundingClientRect(),o=getComputedStyle(t).getPropertyValue("transform");if(!o||o==="none")return e;let r=o.split(",").pop();return e.y=e.y-Number(r?.replace(")","")),e}function se(t){let e=(u,p)=>u?parseFloat(window.getComputedStyle(u)[p]):0,{marginBottom:o,marginTop:r}=window.getComputedStyle(t),n=e(t.previousElementSibling,"marginBottom"),c=e(t.nextElementSibling,"marginTop"),i=Math.max(parseFloat(r),n);return{marginBottom:Math.max(parseFloat(o),c),marginTop:i}}import{$getRoot as Ut}from"lexical";function j(t){return t.getEditorState().read(()=>Ut().getChildrenKeys())}var qt=1,Jt=-1,Oe=0,B={props:null,result:null};function Qt(t,e,o=20){let r=t.x-e.x,n=t.y-e.y;return r*r+n*n<=o*o}function q(t){let{anchorElem:e,cache_threshold:o=20,editor:r,fuzzy:n=!1,horizontalOffset:c=0,point:{x:i,y:l},startIndex:u=0,useEdgeAsDefault:p=!1}=t;if(o>0&&B.props&&B.result&&B.props.fuzzy===t.fuzzy&&B.props.horizontalOffset===t.horizontalOffset&&B.props.useEdgeAsDefault===t.useEdgeAsDefault&&Qt(B.props.point,t.point,o))return B.result;let h=e.getBoundingClientRect(),a=j(r),s={blockElem:null,blockNode:null,distance:1/0,foundAtIndex:-1,isFoundNodeEmptyParagraph:!1};return r.getEditorState().read(()=>{if(p){let m=r.getElementByKey(a[0]),y=r.getElementByKey(a[a.length-1]);if(m&&y){let[d,f]=[U(m),U(y)];if(l<d.top?(s.blockElem=m,s.distance=d.top-l,s.blockNode=le(a[0]),s.foundAtIndex=0):l>f.bottom&&(s.distance=l-f.bottom,s.blockNode=le(a[a.length-1]),s.blockElem=y,s.foundAtIndex=a.length-1),s?.blockElem)return{blockElem:null,isFoundNodeEmptyParagraph:!1}}}let g=u,x=Oe;for(;g>=0&&g<a.length;){let m=a[g],y=r.getElementByKey(m);if(y===null)break;let d=new _(i+c,l),f=ve.fromDOMRect(U(y)),{marginBottom:E,marginTop:k}=se(y),R=f.generateNewRect({bottom:f.bottom+E,left:h.left,right:h.right,top:f.top-k}),{distance:S,isOnBottomSide:w,isOnTopSide:C}=R.distanceFromPoint(d);if(S===0){s.blockElem=y,s.blockNode=le(m),s.foundAtIndex=g,s.distance=S,s.blockNode&&s.blockNode.getType()==="paragraph"&&s.blockNode.getTextContent()===""&&(!n&&!t.returnEmptyParagraphs&&(s.blockElem=null,s.blockNode=null),s.isFoundNodeEmptyParagraph=!0);break}else n&&S<s.distance&&(s.blockElem=y,s.blockNode=le(m),s.distance=S,s.foundAtIndex=g);x===Oe&&(C?x=Jt:w?x=qt:x=1/0),g+=x}}),B.props=t,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 ae(t,e){return!!t.closest(`.${e}`)}var Xt=["IMG","INPUT","TEXTAREA","SELECT","BUTTON","VIDEO","OBJECT","EMBED","IFRAME","HR"];function Fe(t){if(!t||Xt.includes(t.tagName)||t.offsetHeight===0||t.offsetWidth===0)return!1;let e=window.getComputedStyle(t);return!(e.display==="table-cell"||e.position==="absolute"||e.visibility==="hidden"||e.opacity==="0")}function ce(t,e,o,r=0){if(!t){e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)";return}let n=t.getBoundingClientRect(),c=window.getComputedStyle(t),i=e.getBoundingClientRect(),l=o.getBoundingClientRect(),u;if(["lexical-block","lexical-upload","lexical-relationship"].some(a=>t.firstElementChild?.classList.contains(a)))u=n.top+8-l.top;else{let a=Fe(t)?parseInt(c.lineHeight,10):0;u=n.top+(a-i.height)/2-l.top}let h=r;e.style.opacity="1",e.style.transform=`translate(${h}px, ${u}px)`}var so="add-block-menu",ue=1/0;function lo(t){return t===0?1/0:ue>=0&&ue<t?ue:Math.floor(t/2)}function ao(t,e,o){let r=e.parentElement,{editorConfig:n}=P(),c=n?.admin?.hideGutter?-24:12,i=no(null),[l,u]=ro(null);$e(()=>{function h(a){let s=a.target;if(!to(s))return;let g=V(r,a.pageX,a.pageY,s);if(g===-1){u(null);return}if(ae(s,so))return;let x=j(t),{blockElem:m,blockNode:y,foundAtIndex:d}=q({anchorElem:e,cache_threshold:0,editor:t,horizontalOffset:-g,point:new _(a.x,a.y),returnEmptyParagraphs:!0,startIndex:lo(x.length),useEdgeAsDefault:!1});ue=d,m&&y&&(l?.node!==y||l?.elem!==m)&&u({elem:m,node:y})}return document?.addEventListener("mousemove",h),()=>{document?.removeEventListener("mousemove",h)}},[r,e,t,l]),$e(()=>{i.current&&l?.node&&ce(l?.elem,i.current,e,c)},[e,l,c]);let p=oo(h=>{let a=l;a?.node&&(t.update(()=>{let s=!0;if((a?.node.getType()!=="paragraph"||a.node.getTextContent()!=="")&&(s=!1),!s){let g=eo();a?.node.insertAfter(g),setTimeout(()=>{a={elem:t.getElementByKey(g.getKey()),node:g},u(a)},0)}}),setTimeout(()=>{t.update(()=>{t.focus(),a?.node&&"select"in a.node&&typeof a.node.select=="function"&&a.node.select()})},1),setTimeout(()=>{t.dispatchCommand(we,{node:a?.node})},2),h.stopPropagation(),h.preventDefault())},[t,l]);return io(Ee(Ke.Fragment,{children:Ee("button",{"aria-label":"Add block",className:"icon add-block-menu",onClick:h=>{p(h)},ref:i,type:"button",children:Ee("div",{className:o?"icon":""})})}),e)}function He(t){let{anchorElem:e}=t,o=e===void 0?document.body:e,[r]=Zt();return ao(r,o,r._editable)}import{jsx as de,jsxs as uo}from"react/jsx-runtime";import{useLexicalComposerContext as mo}from"@lexical/react/LexicalComposerContext.js";import{eventFiles as We}from"@lexical/rich-text";import{$getNearestNodeFromDOMNode as Ye,$getNodeByKey as fo,isHTMLElement as Ce}from"lexical";import*as Je from"react";import{useEffect as be,useRef as me,useState as Ge}from"react";import{createPortal as po}from"react-dom";var je=0,co=-24;var z=0;function ze(t,e,o,r,n,c,i,l,u,p=!1){let{height:h,top:a}=r.getBoundingClientRect(),{top:s,width:g}=i.getBoundingClientRect(),{marginBottom:x,marginTop:m}=se(r),y=a,d=c>=a+h/2+window.scrollY,f=!1;if(n?.elem)if(r!==n?.elem)(d&&n?.elem&&n?.elem===r.nextElementSibling||!d&&n?.elem&&n?.elem===r.previousElementSibling)&&(z++,z<200&&(f=!0));else{z++;let S=n?.boundingBox?.y,w=r.getBoundingClientRect().y;(d===n?.isBelow&&S===w||z<200)&&(f=!1)}if(f)return{isBelow:d,willStayInSamePosition:f};p?y+=h/2:d?y+=h+x/2:y-=m/2;let E=0;p||(d?E=-je:E=je);let k=y-s+E,R=co-e;return o.style.width=`calc(${g}px - ${t})`,o.style.opacity=".8",o.style.transform=`translate(${R}px, calc(${k}px - 2px))`,n?.elem&&(n.elem.style.opacity="",n?.elem===r?d?n.elem.style.marginTop="":n.elem.style.marginBottom="":(n.elem.style.marginBottom="",n.elem.style.marginTop="")),z=0,{isBelow:d,willStayInSamePosition:f}}var go="draggable-block-menu",Ve="application/x-lexical-drag-block",ee=1/0;function Ue(t){return t===0?1/0:ee>=0&&ee<t?ee:Math.floor(t/2)}function ho(t,e){let{transform:o}=e.style;t.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=o})}function qe(t,e){t&&(t.style.opacity="0"),e&&(e.style.opacity="",e.style.marginBottom="",e.style.marginTop="")}function yo(t,e,o){let r=e.parentElement,n=me(null),c=me(null),i=me(null),l=me(!1),[u,p]=Ge(null),[h,a]=Ge(null),{editorConfig:s}=P(),g=s?.admin?.hideGutter?-44:-8;be(()=>{function y(d){let f=d.target;if(!Ce(f))return;let E=V(r,d.pageX,d.pageY,f);if(E===-1){p(null);return}if(ae(f,go))return;let k=j(t),{blockElem:R,foundAtIndex:S,isFoundNodeEmptyParagraph:w}=q({anchorElem:e,cache_threshold:0,editor:t,horizontalOffset:-E,point:new _(d.x,d.y),startIndex:Ue(k.length),useEdgeAsDefault:!1,verbose:!1});ee=S,!(!R&&!w)&&u!==R&&p(R)}return document?.addEventListener("mousemove",y),()=>{document?.removeEventListener("mousemove",y)}},[r,e,t,u]),be(()=>{n.current&&ce(u,n.current,e,g)},[e,u,g]),be(()=>{function y(f){if(!l.current)return!1;let[E]=We(f);if(E)return!1;let{pageY:k,target:R}=f;if(!Ce(R))return!1;let S=V(r,f.pageX,f.pageY,R,100,50),w=j(t),{blockElem:C,foundAtIndex:W,isFoundNodeEmptyParagraph:I}=q({anchorElem:e,editor:t,fuzzy:!0,horizontalOffset:-S,point:new _(f.x,f.y),startIndex:Ue(w.length),useEdgeAsDefault:!0,verbose:!0});ee=W;let T=c.current;if(C===null||T===null)return!1;if(u!==C){let{isBelow:v,willStayInSamePosition:A}=ze(s?.admin?.hideGutter?"0px":"3rem",g+(s?.admin?.hideGutter?n?.current?.getBoundingClientRect()?.width??0:-(n?.current?.getBoundingClientRect()?.width??0)),T,C,h,k,e,f,i,I);f.preventDefault(),A||a({boundingBox:C.getBoundingClientRect(),elem:C,isBelow:v})}else h?.elem&&(qe(T,h.elem),a({boundingBox:C.getBoundingClientRect(),elem:C,isBelow:!1}));return!0}function d(f){if(!l.current)return!1;let[E]=We(f);if(E)return!1;let{dataTransfer:k,pageY:R,target:S}=f,w=k?.getData(Ve)||"";return t.update(()=>{let C=fo(w);if(!C||!Ce(S))return!1;let W=V(r,f.pageX,f.pageY,S,100,50),{blockElem:I,isFoundNodeEmptyParagraph:T}=q({anchorElem:e,editor:t,fuzzy:!0,horizontalOffset:-W,point:new _(f.x,f.y),useEdgeAsDefault:!0});if(!I)return!1;let v=Ye(I);if(!v)return!1;if(v===C)return!0;let{height:A,top:ge}=U(I),he=R>=ge+A/2+window.scrollY;T?(v.insertBefore(C),v.remove()):he?v.insertAfter(C):v.insertBefore(C),u!==null&&p(null),document.querySelectorAll(".lexical-block-highlighter").forEach(D=>{D.remove()});let Y=t.getElementByKey(C.getKey());setTimeout(()=>{let D=Y?.getBoundingClientRect();if(!D)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=`${D.height+8}px`,N.style.width=`${D.width+8}px`,N.style.top=`${D.top+window.scrollY-4}px`,N.style.left=`${D.left-4}px`,setTimeout(()=>{N.style.opacity="0",setTimeout(()=>{N.remove()},500)},1e3)},120)}),!0}return document.addEventListener("dragover",y),document.addEventListener("drop",d),()=>{document.removeEventListener("dragover",y),document.removeEventListener("drop",d)}},[r,g,e,t,h,u,s?.admin?.hideGutter]);function x(y){let d=y.dataTransfer;if(!d||!u)return;ho(d,u);let f="";t.update(()=>{let E=Ye(u);E&&(f=E.getKey())}),l.current=!0,d.setData(Ve,f)}function m(){l.current=!1,h?.elem&&qe(c.current,h?.elem)}return po(uo(Je.Fragment,{children:[de("div",{className:"icon draggable-block-menu",draggable:!0,onDragEnd:m,onDragStart:x,ref:n,children:de("div",{className:o?"icon":""})}),de("div",{className:"draggable-block-target-line",ref:c}),de("div",{className:"debug-highlight",ref:i})]}),e)}function Qe(t){let{anchorElem:e}=t,o=e===void 0?document.body:e,[r]=mo();return yo(r,o,r._editable)}import{c as xo}from"react/compiler-runtime";import{jsx as Ne}from"react/jsx-runtime";import{useLexicalComposerContext as Eo}from"@lexical/react/LexicalComposerContext";import{$createParagraphNode as Co,$getRoot as bo}from"lexical";import"react";var Xe="insert-paragraph-at-end",Ze=()=>{let t=xo(4),[e]=Eo(),{editorConfig:o}=P();if(o?.admin?.hideInsertParagraphAtEnd)return null;let r;t[0]!==e?(r=()=>{e.update(No)},t[0]=e,t[1]=r):r=t[1];let n=r,c;return t[2]!==n?(c=Ne("div",{"aria-label":"Insert Paragraph",className:Xe,onClick:n,role:"button",tabIndex:0,children:Ne("div",{className:`${Xe}-inside`,children:Ne("span",{children:"+"})})}),t[2]=n,t[3]=c):c=t[3],c};function No(){let t=Co();bo().append(t),t.select()}import{c as Po}from"react/compiler-runtime";import{useLexicalComposerContext as So}from"@lexical/react/LexicalComposerContext";import*as et from"react";var tt=()=>{let t=Po(4),{editorConfig:e}=P(),[o]=So(),r,n;return t[0]!==o||t[1]!==e.features.markdownTransformers?(r=()=>Re(o,e.features.markdownTransformers??[]),n=[o,e.features.markdownTransformers],t[0]=o,t[1]=e.features.markdownTransformers,t[2]=r,t[3]=n):(r=t[2],n=t[3]),et.useEffect(r,n),null};import{jsx as J,jsxs as nt}from"react/jsx-runtime";import{useLexicalComposerContext as ko}from"@lexical/react/LexicalComposerContext.js";import{useTranslation as rt}from"@payloadcms/ui";import{useCallback as wo,useMemo as To,useState as vo}from"react";import"react";import*as it from"react-dom";import{c as Ro}from"react/compiler-runtime";import"react";function ot(t,e){let o=Ro(4),{maxLength:r,minLength:n}=e,c=r===void 0?75:r,i=n===void 0?1:n,l;return o[0]!==c||o[1]!==i||o[2]!==t?(l=u=>{let{query:p}=u,h="[^"+t+ke+"\\s]",s=new RegExp("(^|\\s|\\()(["+t+"]((?:"+h+"){0,"+c+"}))$").exec(p);if(s!==null){let g=s[1],x=s[3];if(x.length>=i)return{leadOffset:s.index+g.length,matchingString:x,replaceableString:s[2]}}return null},o[0]=c,o[1]=i,o[2]=t,o[3]=l):l=o[3],l}var L="slash-menu-popup";function Do({isSelected:t,item:e,onClick:o,onMouseEnter:r,ref:n}){let{fieldProps:{featureClientSchemaMap:c,schemaPath:i}}=P(),{i18n:l}=rt(),u=`${L}__item ${L}__item-${e.key}`;t&&(u+=` ${L}__item--selected`);let p=e.key;return e.label&&(p=typeof e.label=="function"?e.label({featureClientSchemaMap:c,i18n:l,schemaPath:i}):e.label),p.length>25&&(p=p.substring(0,25)+"..."),nt("button",{"aria-selected":t,className:u,id:L+"__item-"+e.key,onClick:o,onMouseEnter:r,ref:n,role:"option",tabIndex:-1,type:"button",children:[e?.Icon&&J(e.Icon,{}),J("span",{className:`${L}__item-text`,children:p})]},e.key)}function st({anchorElem:t=document.body}){let[e]=ko(),[o,r]=vo(null),{editorConfig:n}=P(),{i18n:c}=rt(),{fieldProps:{featureClientSchemaMap:i,schemaPath:l}}=P(),u=ot("/",{minLength:0}),p=wo(()=>{let a=[];for(let s of n.features.slashMenu.dynamicGroups)if(o){let g=s({editor:e,queryString:o});a=a.concat(g)}return a},[e,o,n?.features]),h=To(()=>{let a=[];for(let s of n?.features.slashMenu.groups??[])a.push(s);if(o){a=a.map(g=>{let x=g.items.filter(m=>{let y=m.key;return m.label&&(y=typeof m.label=="function"?m.label({featureClientSchemaMap:i,i18n:c,schemaPath:l}):m.label),new RegExp(o,"gi").exec(y)?!0:m.keywords!=null?m.keywords.some(d=>new RegExp(o,"gi").exec(d)):!1});return x.length?{...g,items:x}:null}),a=a.filter(g=>g!=null);let s=p();for(let g of s){let x=a.find(m=>m.key===g.key);x?a=a.filter(m=>m.key!==g.key):x={...g,items:[]},x?.items?.length&&(x.items=x.items.concat(x.items)),a.push(x)}}return a},[o,n?.features.slashMenu.groups,p,i,c,l]);return J(Te,{anchorElem:t,groups:h,menuRenderFn:(a,{selectedItemKey:s,selectItemAndCleanUp:g,setSelectedItemKey:x})=>a.current&&h.length?it.createPortal(J("div",{className:L,children:h.map(m=>{let y=m.key;return m.label&&i&&(y=typeof m.label=="function"?m.label({featureClientSchemaMap:i,i18n:c,schemaPath:l}):m.label),nt("div",{className:`${L}__group ${L}__group-${m.key}`,children:[J("div",{className:`${L}__group-title`,children:y}),m.items.map((d,f)=>J(Do,{index:f,isSelected:s===d.key,item:d,onClick:()=>{x(d.key),g(d)},onMouseEnter:()=>{x(d.key)},ref:E=>{d.ref={current:E}}},d.key))]},m.key)})}),a.current):null,onQueryChange:r,triggerFn:u})}import{c as Mo}from"react/compiler-runtime";import{useLexicalComposerContext as Bo}from"@lexical/react/LexicalComposerContext";import{TEXT_TYPE_TO_FORMAT as Lo,TextNode as Io}from"lexical";import{useEffect as Ao}from"react";function lt(t){let e=Mo(6),{features:o}=t,[r]=Bo(),n;e[0]!==r||e[1]!==o.enabledFormats?(n=()=>{let i=_o(o.enabledFormats);if(i.length!==0)return r.registerNodeTransform(Io,l=>{i.forEach(u=>{l.hasFormat(u)&&l.toggleFormat(u)})})},e[0]=r,e[1]=o.enabledFormats,e[2]=n):n=e[2];let c;return e[3]!==r||e[4]!==o?(c=[r,o],e[3]=r,e[4]=o,e[5]=c):c=e[5],Ao(n,c),null}function _o(t){let e=Object.keys(Lo),o=new Set(t);return e.filter(r=>!o.has(r))}import{c as Oo}from"react/compiler-runtime";import{jsx as at}from"react/jsx-runtime";import{ContentEditable as Fo}from"@lexical/react/LexicalContentEditable.js";import{useTranslation as $o}from"@payloadcms/ui";import"react";function ct(t){let e=Oo(7),{className:o,editorConfig:r}=t,{t:n}=$o(),c;if(e[0]!==o||e[1]!==r?.admin?.placeholder||e[2]!==n){let i;e[4]!==r?.admin?.placeholder||e[5]!==n?(i=r?.admin?.placeholder??n("lexical:general:placeholder"),e[4]=r?.admin?.placeholder,e[5]=n,e[6]=i):i=e[6],c=at(Fo,{"aria-placeholder":n("lexical:general:placeholder"),className:o??"ContentEditable__root",placeholder:at("p",{className:"editor-placeholder",children:i})}),e[0]=o,e[1]=r?.admin?.placeholder,e[2]=n,e[3]=c}else c=e[3];return c}var dt=t=>{let e=Ko(19),{editorConfig:o,editorContainerRef:r,isSmallWidthViewport:n,onChange:c}=t,i=P(),[l]=Ho(),[u,p]=qo(null),h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=m=>{m!==null&&p(m)},e[0]=h):h=e[0];let a=h,s,g;e[1]!==l||e[2]!==i?(s=()=>{if(!i?.uuid){console.error("Lexical Editor must be used within an EditorConfigProvider");return}i?.parentEditor?.uuid&&i.parentEditor?.registerChild(i.uuid,i);let m=()=>{i.focusEditor(i)},y=()=>{i.blurEditor(i)},d=l.registerCommand(Vo,()=>(m(),!0),ut),f=l.registerCommand(Go,()=>(y(),!0),ut);return()=>{d(),f(),i.parentEditor?.unregisterChild?.(i.uuid)}},g=[l,i],e[1]=l,e[2]=i,e[3]=s,e[4]=g):(s=e[3],g=e[4]),Uo(s,g);let x;if(e[5]!==l||e[6]!==o||e[7]!==r||e[8]!==u||e[9]!==n||e[10]!==c){let m;e[12]!==c?(m=(d,f,E)=>{(!E.has("focus")||E.size>1)&&c?.(d,f,E)},e[12]=c,e[13]=m):m=e[13];let y;e[14]!==l||e[15]!==o.features.plugins||e[16]!==u||e[17]!==n?(y=u&&te(Q.Fragment,{children:[!n&&l.isEditable()&&te(Q.Fragment,{children:[b(Qe,{anchorElem:u}),b(He,{anchorElem:u})]}),o.features.plugins?.map(d=>{if(d.position==="floatingAnchorElem"&&!(d.desktopOnly===!0&&n))return b(K,{anchorElem:u,clientProps:d.clientProps,plugin:d},d.key)}),l.isEditable()&&b(Q.Fragment,{children:b(st,{anchorElem:u})})]}),e[14]=l,e[15]=o.features.plugins,e[16]=u,e[17]=n,e[18]=y):y=e[18],x=te(Q.Fragment,{children:[o.features.plugins?.map(Jo),te("div",{className:"editor-container",ref:r,children:[o.features.plugins?.map(Qo),b(Yo,{contentEditable:b("div",{className:"editor-scroller",children:b("div",{className:"editor",ref:a,children:b(ct,{editorConfig:o})})}),ErrorBoundary:jo}),b(Ze,{}),b(Ie,{}),b(lt,{features:o.features}),b(Wo,{ignoreSelectionChange:!0,onChange:m}),y,l.isEditable()&&te(Q.Fragment,{children:[b(zo,{}),o?.features?.markdownTransformers?.length>0&&b(tt,{})]}),o.features.plugins?.map(Xo),o.features.plugins?.map(Zo)]}),o.features.plugins?.map(en)]}),e[5]=l,e[6]=o,e[7]=r,e[8]=u,e[9]=n,e[10]=c,e[11]=x}else x=e[11];return x};function Jo(t){if(t.position==="aboveContainer")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}function Qo(t){if(t.position==="top")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}function Xo(t){if(t.position==="normal")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}function Zo(t){if(t.position==="bottom")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}function en(t){if(t.position==="belowContainer")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}var ft=({children:t,providers:e})=>{if(!e?.length)return t;let o=e[0];return e.length>1?O(o,{children:O(ft,{providers:e.slice(1),children:t})}):O(o,{children:t})},pt=t=>{let{composerKey:e,editorConfig:o,fieldProps:r,isSmallWidthViewport:n,onChange:c,readOnly:i,value:l}=t,u=P(),p=on(),h=mt.useRef(null),a=nn(()=>{if(l&&typeof l!="object")throw new Error("The value passed to the Lexical editor is not an object. This is not supported. Please remove the data from the field and start again. This is the value that was passed in: "+JSON.stringify(l));if(l&&Array.isArray(l)&&!("root"in l))throw new Error("You have tried to pass in data from the old Slate editor to the new Lexical editor. The data structure is different, thus you will have to migrate your data. We offer a one-line migration script which migrates all your rich text fields: https://payloadcms.com/docs/lexical/migration#migration-via-migration-script-recommended");if(l&&"jsonContent"in l)throw new Error("You have tried to pass in data from payload-plugin-lexical. The data structure is different, thus you will have to migrate your data. Migration guide: https://payloadcms.com/docs/lexical/migration#migrating-from-payload-plugin-lexical");return{editable:i!==!0,editorState:l!=null?JSON.stringify(l):void 0,namespace:o.lexical.namespace,nodes:De({editorConfig:o}),onError:s=>{throw s},theme:o.lexical.theme}},[o]);return a?O(tn,{initialConfig:a,children:O(Se,{editorConfig:o,editorContainerRef:h,fieldProps:r,parentContext:u?.editDepth===p?u:void 0,children:O(ft,{providers:o.features.providers,children:O(dt,{editorConfig:o,editorContainerRef:h,isSmallWidthViewport:n,onChange:c})})})},e+a.editable):O("p",{children:"Loading..."})};var fe="rich-text-lexical",pn=t=>{let{editorConfig:e,field:o,field:{name:r,admin:{className:n,description:c,readOnly:i}={},label:l,localized:u,required:p},path:h,readOnly:a,validate:s}=t,g=a||i,x=h??r,m=an(),y=yt((M,$)=>typeof s=="function"?s(M,{...$,required:p}):!0,[s,p]),{customComponents:{AfterInput:d,BeforeInput:f,Description:E,Error:k,Label:R}={},formInitializing:S,formProcessing:w,initialValue:C,setValue:W,showError:I,value:T}=un({path:x,validate:y}),v=g||w||S,[A,ge]=Et(!1),[Pe,he]=Et(),ye=ht.useRef(C),Y=ht.useRef(T);xt(()=>{let M=()=>{let $=window.matchMedia("(max-width: 768px)").matches;$!==A&&ge($)};return M(),window.addEventListener("resize",M),()=>{window.removeEventListener("resize",M)}},[A]);let D=[fe,"field-type",n,I&&"error",v&&`${fe}--read-only`,e?.admin?.hideGutter!==!0&&!A?`${fe}--show-gutter`:null].filter(Boolean).join(" "),N=`${x}.${m}`,Ct=yt(M=>{let $=M.toJSON();Y.current=$,W($)},[W]),bt=mn(()=>dn(o),[o]),Nt=cn(M=>{Y.current!==T&&JSON.stringify(Y.current)!==JSON.stringify(T)&&(ye.current=M,Y.current=T,he(new Date))});return xt(()=>{Object.is(C,ye.current)||Nt(C)},[C]),pe("div",{className:D,style:bt,children:[F(gt,{CustomComponent:k,Fallback:F(sn,{path:x,showError:I})}),R||F(ln,{label:l,localized:u,path:x,required:p}),pe("div",{className:`${fe}__wrap`,children:[pe(fn,{fallbackRender:gn,onReset:()=>{},children:[f,F(pt,{composerKey:N,editorConfig:e,fieldProps:t,isSmallWidthViewport:A,onChange:Ct,readOnly:v,value:T},JSON.stringify({path:x,rerenderProviderKey:Pe})),d]}),E,F(gt,{CustomComponent:E,Fallback:F(rn,{description:c,path:x})})]})]},N)};function gn({error:t}){return pe("div",{className:"errorBoundary",role:"alert",children:[F("p",{children:"Something went wrong:"}),F("pre",{style:{color:"red"},children:t.message})]})}var $i=pn;export{$i as RichText};
|
|
2
|
-
//# sourceMappingURL=Field-
|
|
1
|
+
"use client";import{c as Re,f as _,h as ke,i as we,j as Te,k as ve,l as De}from"./chunk-XO6X2M3F.js";import{a as Se,b as P}from"./chunk-BZZVLW4U.js";import{jsx as F,jsxs as pe}from"react/jsx-runtime";import{FieldDescription as rn,FieldError as sn,FieldLabel as ln,RenderCustomComponent as gt,useEditDepth as an,useEffectEvent as cn,useField as un}from"@payloadcms/ui";import{mergeFieldStyles as dn}from"@payloadcms/ui/shared";import ht,{useCallback as yt,useEffect as xt,useMemo as mn,useState as Et}from"react";import{ErrorBoundary as fn}from"react-error-boundary";import"./bundled.css";import{jsx as O}from"react/jsx-runtime";import{LexicalComposer as tn}from"@lexical/react/LexicalComposer.js";import{useEditDepth as on}from"@payloadcms/ui";import*as mt from"react";import{useMemo as nn}from"react";import{c as Ko}from"react/compiler-runtime";import{jsx as b,jsxs as te}from"react/jsx-runtime";import{useLexicalComposerContext as Ho}from"@lexical/react/LexicalComposerContext.js";import{LexicalErrorBoundary as jo}from"@lexical/react/LexicalErrorBoundary.js";import{HistoryPlugin as zo}from"@lexical/react/LexicalHistoryPlugin.js";import{OnChangePlugin as Wo}from"@lexical/react/LexicalOnChangePlugin.js";import{RichTextPlugin as Yo}from"@lexical/react/LexicalRichTextPlugin.js";import{BLUR_COMMAND as Go,COMMAND_PRIORITY_LOW as ut,FOCUS_COMMAND as Vo}from"lexical";import*as Q from"react";import{useEffect as Uo,useState as qo}from"react";import{jsx as Me}from"react/jsx-runtime";import"react";var K=({anchorElem:t,clientProps:e,plugin:o})=>o.position==="floatingAnchorElem"&&t?o.Component&&Me(o.Component,{anchorElem:t,clientProps:e}):o.Component&&Me(o.Component,{clientProps:e});import{c as Pt}from"react/compiler-runtime";import{useLexicalComposerContext as St}from"@lexical/react/LexicalComposerContext";import{$findMatchingParent as oe,mergeRegister as Rt}from"@lexical/utils";import{$createNodeSelection as kt,$getEditor as X,$getNearestNodeFromDOMNode as wt,$getSelection as ne,$isDecoratorNode as H,$isElementNode as xe,$isLineBreakNode as Tt,$isNodeSelection as re,$isRangeSelection as Be,$isRootOrShadowRoot as vt,$isTextNode as Dt,$setSelection as Le,CLICK_COMMAND as Mt,COMMAND_PRIORITY_LOW as G,KEY_ARROW_DOWN_COMMAND as Bt,KEY_ARROW_UP_COMMAND as Lt,KEY_BACKSPACE_COMMAND as It,KEY_DELETE_COMMAND as At,SELECTION_CHANGE_COMMAND as _t}from"lexical";import{useEffect as Ot}from"react";function Ie(){let t=Pt(3),[e]=St(),o=Wt,r,n;return t[0]!==e?(r=()=>Rt(e.registerCommand(Mt,zt,G),e.registerCommand(At,o,G),e.registerCommand(It,o,G),e.registerCommand(_t,jt,G),e.registerCommand(Lt,Kt,G),e.registerCommand(Bt,Ft,G)),n=[e],t[0]=e,t[1]=r,t[2]=n):(r=t[1],n=t[2]),Ot(r,n),null}function Ft(t){let e=ne();if(re(e)){t.preventDefault();let i=e.getNodes()[0]?.getNextSibling();if(H(i)){let p=X().getElementByKey(i.getKey());return p&&Z({element:p,node:i}),!0}if(!xe(i))return!0;let l=i.getFirstDescendant()??i;return l&&(oe(l,ie)?.selectEnd(),t.preventDefault()),!0}if(!Be(e))return!1;let r=(e.isBackward()?e.anchor:e.focus).getNode(),n=oe(r,$t),c=n?.getNextSibling();if(!n||c!==Ae(n))return!1;if(H(c)){let i=X().getElementByKey(c.getKey());if(i)return Z({element:i,node:c}),t.preventDefault(),!0}return!1}function $t(t){return Ae(t)!==null}function Kt(t){let e=ne();if(re(e)){let i=e.getNodes()[0]?.getPreviousSibling();if(H(i)){let p=X().getElementByKey(i.getKey());return p?(Z({element:p,node:i}),t.preventDefault(),!0):!1}if(!xe(i))return!1;let l=i.getLastDescendant()??i;return l?(oe(l,ie)?.selectStart(),t.preventDefault(),!0):!1}if(!Be(e))return!1;let r=(e.isBackward()?e.anchor:e.focus).getNode(),n=oe(r,Ht),c=n?.getPreviousSibling();if(!n||c!==_e(n))return!1;if(H(c)){let i=X().getElementByKey(c.getKey());if(i)return Z({element:i,node:c}),t.preventDefault(),!0}return!1}function Ht(t){return _e(t)!==null}function jt(){let t=Vt();return document.querySelector(".decorator-selected")?.classList.remove("decorator-selected"),t?(t.element?.classList.add("decorator-selected"),!0):!1}function zt(t){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let e=Gt(t);if(!e)return!0;let{target:o}=t;return!(o instanceof HTMLElement)||o.isContentEditable||o.closest('button, textarea, input, .react-select, .code-editor, .no-select-decorator, [role="button"]')?Le(null):Z(e),!0}function Wt(t){let e=ne();return re(e)?(t.preventDefault(),e.getNodes().forEach(Yt),!0):!1}function Yt(t){t.remove()}function Gt(t){if(!(t.target instanceof HTMLElement))return;let e=t.target.closest('[data-lexical-decorator="true"]');if(!(e instanceof HTMLElement))return;let o=wt(e);return H(o)?{element:e,node:o}:void 0}function Vt(){let t=ne();if(!re(t))return;let e=t.getNodes();if(e.length!==1)return;let o=e[0];return H(o)?{decorator:o,element:X().getElementByKey(o.getKey())}:void 0}function Z({element:t,node:e}){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let o=kt();o.add(e.getKey()),Le(o),t.scrollIntoView({behavior:"smooth",block:"nearest"}),t.classList.add("decorator-selected")}function ie(t){if(H(t)&&!t.isInline())return!0;if(!xe(t)||vt(t))return!1;let e=t.getFirstChild(),o=e===null||Tt(e)||Dt(e)||e.isInline();return!t.isInline()&&t.canBeEmpty()!==!1&&o}function Ae(t){let e=t.getNextSibling();for(;e!==null;){if(ie(e))return e;e=e.getNextSibling()}return null}function _e(t){let e=t.getPreviousSibling();for(;e!==null;){if(ie(e))return e;e=e.getPreviousSibling()}return null}import{jsx as Ee}from"react/jsx-runtime";import{useLexicalComposerContext as Zt}from"@lexical/react/LexicalComposerContext.js";import{$createParagraphNode as eo,isHTMLElement as to}from"lexical";import*as Ke from"react";import{useCallback as oo,useEffect as $e,useRef as no,useState as ro}from"react";import{createPortal as io}from"react-dom";var V=(t,e,o,r,n=50,c=25)=>{let i=0;if(t&&!t.contains(r)){let{bottom:l,left:u,right:p,top:h}=t.getBoundingClientRect(),a=h+window.scrollY,s=l+window.scrollY;if(o<a-c||o>s+c||e<u-n||e>p+n)return-1;(e<u||e>p)&&(i=e<u?e-u:e-p)}return i};import{$getNodeByKey as le}from"lexical";function U(t){let e=t.getBoundingClientRect(),o=getComputedStyle(t).getPropertyValue("transform");if(!o||o==="none")return e;let r=o.split(",").pop();return e.y=e.y-Number(r?.replace(")","")),e}function se(t){let e=(u,p)=>u?parseFloat(window.getComputedStyle(u)[p]):0,{marginBottom:o,marginTop:r}=window.getComputedStyle(t),n=e(t.previousElementSibling,"marginBottom"),c=e(t.nextElementSibling,"marginTop"),i=Math.max(parseFloat(r),n);return{marginBottom:Math.max(parseFloat(o),c),marginTop:i}}import{$getRoot as Ut}from"lexical";function j(t){return t.getEditorState().read(()=>Ut().getChildrenKeys())}var qt=1,Jt=-1,Oe=0,B={props:null,result:null};function Qt(t,e,o=20){let r=t.x-e.x,n=t.y-e.y;return r*r+n*n<=o*o}function q(t){let{anchorElem:e,cache_threshold:o=20,editor:r,fuzzy:n=!1,horizontalOffset:c=0,point:{x:i,y:l},startIndex:u=0,useEdgeAsDefault:p=!1}=t;if(o>0&&B.props&&B.result&&B.props.fuzzy===t.fuzzy&&B.props.horizontalOffset===t.horizontalOffset&&B.props.useEdgeAsDefault===t.useEdgeAsDefault&&Qt(B.props.point,t.point,o))return B.result;let h=e.getBoundingClientRect(),a=j(r),s={blockElem:null,blockNode:null,distance:1/0,foundAtIndex:-1,isFoundNodeEmptyParagraph:!1};return r.getEditorState().read(()=>{if(p){let m=r.getElementByKey(a[0]),y=r.getElementByKey(a[a.length-1]);if(m&&y){let[d,f]=[U(m),U(y)];if(l<d.top?(s.blockElem=m,s.distance=d.top-l,s.blockNode=le(a[0]),s.foundAtIndex=0):l>f.bottom&&(s.distance=l-f.bottom,s.blockNode=le(a[a.length-1]),s.blockElem=y,s.foundAtIndex=a.length-1),s?.blockElem)return{blockElem:null,isFoundNodeEmptyParagraph:!1}}}let g=u,x=Oe;for(;g>=0&&g<a.length;){let m=a[g],y=r.getElementByKey(m);if(y===null)break;let d=new _(i+c,l),f=ve.fromDOMRect(U(y)),{marginBottom:E,marginTop:k}=se(y),R=f.generateNewRect({bottom:f.bottom+E,left:h.left,right:h.right,top:f.top-k}),{distance:S,isOnBottomSide:w,isOnTopSide:C}=R.distanceFromPoint(d);if(S===0){s.blockElem=y,s.blockNode=le(m),s.foundAtIndex=g,s.distance=S,s.blockNode&&s.blockNode.getType()==="paragraph"&&s.blockNode.getTextContent()===""&&(!n&&!t.returnEmptyParagraphs&&(s.blockElem=null,s.blockNode=null),s.isFoundNodeEmptyParagraph=!0);break}else n&&S<s.distance&&(s.blockElem=y,s.blockNode=le(m),s.distance=S,s.foundAtIndex=g);x===Oe&&(C?x=Jt:w?x=qt:x=1/0),g+=x}}),B.props=t,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 ae(t,e){return!!t.closest(`.${e}`)}var Xt=["IMG","INPUT","TEXTAREA","SELECT","BUTTON","VIDEO","OBJECT","EMBED","IFRAME","HR"];function Fe(t){if(!t||Xt.includes(t.tagName)||t.offsetHeight===0||t.offsetWidth===0)return!1;let e=window.getComputedStyle(t);return!(e.display==="table-cell"||e.position==="absolute"||e.visibility==="hidden"||e.opacity==="0")}function ce(t,e,o,r=0){if(!t){e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)";return}let n=t.getBoundingClientRect(),c=window.getComputedStyle(t),i=e.getBoundingClientRect(),l=o.getBoundingClientRect(),u;if(["lexical-block","lexical-upload","lexical-relationship"].some(a=>t.firstElementChild?.classList.contains(a)))u=n.top+8-l.top;else{let a=Fe(t)?parseInt(c.lineHeight,10):0;u=n.top+(a-i.height)/2-l.top}let h=r;e.style.opacity="1",e.style.transform=`translate(${h}px, ${u}px)`}var so="add-block-menu",ue=1/0;function lo(t){return t===0?1/0:ue>=0&&ue<t?ue:Math.floor(t/2)}function ao(t,e,o){let r=e.parentElement,{editorConfig:n}=P(),c=n?.admin?.hideGutter?-24:12,i=no(null),[l,u]=ro(null);$e(()=>{function h(a){let s=a.target;if(!to(s))return;let g=V(r,a.pageX,a.pageY,s);if(g===-1){u(null);return}if(ae(s,so))return;let x=j(t),{blockElem:m,blockNode:y,foundAtIndex:d}=q({anchorElem:e,cache_threshold:0,editor:t,horizontalOffset:-g,point:new _(a.x,a.y),returnEmptyParagraphs:!0,startIndex:lo(x.length),useEdgeAsDefault:!1});ue=d,m&&y&&(l?.node!==y||l?.elem!==m)&&u({elem:m,node:y})}return document?.addEventListener("mousemove",h),()=>{document?.removeEventListener("mousemove",h)}},[r,e,t,l]),$e(()=>{i.current&&l?.node&&ce(l?.elem,i.current,e,c)},[e,l,c]);let p=oo(h=>{let a=l;a?.node&&(t.update(()=>{let s=!0;if((a?.node.getType()!=="paragraph"||a.node.getTextContent()!=="")&&(s=!1),!s){let g=eo();a?.node.insertAfter(g),setTimeout(()=>{a={elem:t.getElementByKey(g.getKey()),node:g},u(a)},0)}}),setTimeout(()=>{t.update(()=>{t.focus(),a?.node&&"select"in a.node&&typeof a.node.select=="function"&&a.node.select()})},1),setTimeout(()=>{t.dispatchCommand(we,{node:a?.node})},2),h.stopPropagation(),h.preventDefault())},[t,l]);return io(Ee(Ke.Fragment,{children:Ee("button",{"aria-label":"Add block",className:"icon add-block-menu",onClick:h=>{p(h)},ref:i,type:"button",children:Ee("div",{className:o?"icon":""})})}),e)}function He(t){let{anchorElem:e}=t,o=e===void 0?document.body:e,[r]=Zt();return ao(r,o,r._editable)}import{jsx as de,jsxs as uo}from"react/jsx-runtime";import{useLexicalComposerContext as mo}from"@lexical/react/LexicalComposerContext.js";import{eventFiles as We}from"@lexical/rich-text";import{$getNearestNodeFromDOMNode as Ye,$getNodeByKey as fo,isHTMLElement as Ce}from"lexical";import*as Je from"react";import{useEffect as be,useRef as me,useState as Ge}from"react";import{createPortal as po}from"react-dom";var je=0,co=-24;var z=0;function ze(t,e,o,r,n,c,i,l,u,p=!1){let{height:h,top:a}=r.getBoundingClientRect(),{top:s,width:g}=i.getBoundingClientRect(),{marginBottom:x,marginTop:m}=se(r),y=a,d=c>=a+h/2+window.scrollY,f=!1;if(n?.elem)if(r!==n?.elem)(d&&n?.elem&&n?.elem===r.nextElementSibling||!d&&n?.elem&&n?.elem===r.previousElementSibling)&&(z++,z<200&&(f=!0));else{z++;let S=n?.boundingBox?.y,w=r.getBoundingClientRect().y;(d===n?.isBelow&&S===w||z<200)&&(f=!1)}if(f)return{isBelow:d,willStayInSamePosition:f};p?y+=h/2:d?y+=h+x/2:y-=m/2;let E=0;p||(d?E=-je:E=je);let k=y-s+E,R=co-e;return o.style.width=`calc(${g}px - ${t})`,o.style.opacity=".8",o.style.transform=`translate(${R}px, calc(${k}px - 2px))`,n?.elem&&(n.elem.style.opacity="",n?.elem===r?d?n.elem.style.marginTop="":n.elem.style.marginBottom="":(n.elem.style.marginBottom="",n.elem.style.marginTop="")),z=0,{isBelow:d,willStayInSamePosition:f}}var go="draggable-block-menu",Ve="application/x-lexical-drag-block",ee=1/0;function Ue(t){return t===0?1/0:ee>=0&&ee<t?ee:Math.floor(t/2)}function ho(t,e){let{transform:o}=e.style;t.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=o})}function qe(t,e){t&&(t.style.opacity="0"),e&&(e.style.opacity="",e.style.marginBottom="",e.style.marginTop="")}function yo(t,e,o){let r=e.parentElement,n=me(null),c=me(null),i=me(null),l=me(!1),[u,p]=Ge(null),[h,a]=Ge(null),{editorConfig:s}=P(),g=s?.admin?.hideGutter?-44:-8;be(()=>{function y(d){let f=d.target;if(!Ce(f))return;let E=V(r,d.pageX,d.pageY,f);if(E===-1){p(null);return}if(ae(f,go))return;let k=j(t),{blockElem:R,foundAtIndex:S,isFoundNodeEmptyParagraph:w}=q({anchorElem:e,cache_threshold:0,editor:t,horizontalOffset:-E,point:new _(d.x,d.y),startIndex:Ue(k.length),useEdgeAsDefault:!1,verbose:!1});ee=S,!(!R&&!w)&&u!==R&&p(R)}return document?.addEventListener("mousemove",y),()=>{document?.removeEventListener("mousemove",y)}},[r,e,t,u]),be(()=>{n.current&&ce(u,n.current,e,g)},[e,u,g]),be(()=>{function y(f){if(!l.current)return!1;let[E]=We(f);if(E)return!1;let{pageY:k,target:R}=f;if(!Ce(R))return!1;let S=V(r,f.pageX,f.pageY,R,100,50),w=j(t),{blockElem:C,foundAtIndex:W,isFoundNodeEmptyParagraph:I}=q({anchorElem:e,editor:t,fuzzy:!0,horizontalOffset:-S,point:new _(f.x,f.y),startIndex:Ue(w.length),useEdgeAsDefault:!0,verbose:!0});ee=W;let T=c.current;if(C===null||T===null)return!1;if(u!==C){let{isBelow:v,willStayInSamePosition:A}=ze(s?.admin?.hideGutter?"0px":"3rem",g+(s?.admin?.hideGutter?n?.current?.getBoundingClientRect()?.width??0:-(n?.current?.getBoundingClientRect()?.width??0)),T,C,h,k,e,f,i,I);f.preventDefault(),A||a({boundingBox:C.getBoundingClientRect(),elem:C,isBelow:v})}else h?.elem&&(qe(T,h.elem),a({boundingBox:C.getBoundingClientRect(),elem:C,isBelow:!1}));return!0}function d(f){if(!l.current)return!1;let[E]=We(f);if(E)return!1;let{dataTransfer:k,pageY:R,target:S}=f,w=k?.getData(Ve)||"";return t.update(()=>{let C=fo(w);if(!C||!Ce(S))return!1;let W=V(r,f.pageX,f.pageY,S,100,50),{blockElem:I,isFoundNodeEmptyParagraph:T}=q({anchorElem:e,editor:t,fuzzy:!0,horizontalOffset:-W,point:new _(f.x,f.y),useEdgeAsDefault:!0});if(!I)return!1;let v=Ye(I);if(!v)return!1;if(v===C)return!0;let{height:A,top:ge}=U(I),he=R>=ge+A/2+window.scrollY;T?(v.insertBefore(C),v.remove()):he?v.insertAfter(C):v.insertBefore(C),u!==null&&p(null),document.querySelectorAll(".lexical-block-highlighter").forEach(D=>{D.remove()});let Y=t.getElementByKey(C.getKey());setTimeout(()=>{let D=Y?.getBoundingClientRect();if(!D)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=`${D.height+8}px`,N.style.width=`${D.width+8}px`,N.style.top=`${D.top+window.scrollY-4}px`,N.style.left=`${D.left-4}px`,setTimeout(()=>{N.style.opacity="0",setTimeout(()=>{N.remove()},500)},1e3)},120)}),!0}return document.addEventListener("dragover",y),document.addEventListener("drop",d),()=>{document.removeEventListener("dragover",y),document.removeEventListener("drop",d)}},[r,g,e,t,h,u,s?.admin?.hideGutter]);function x(y){let d=y.dataTransfer;if(!d||!u)return;ho(d,u);let f="";t.update(()=>{let E=Ye(u);E&&(f=E.getKey())}),l.current=!0,d.setData(Ve,f)}function m(){l.current=!1,h?.elem&&qe(c.current,h?.elem)}return po(uo(Je.Fragment,{children:[de("div",{className:"icon draggable-block-menu",draggable:!0,onDragEnd:m,onDragStart:x,ref:n,children:de("div",{className:o?"icon":""})}),de("div",{className:"draggable-block-target-line",ref:c}),de("div",{className:"debug-highlight",ref:i})]}),e)}function Qe(t){let{anchorElem:e}=t,o=e===void 0?document.body:e,[r]=mo();return yo(r,o,r._editable)}import{c as xo}from"react/compiler-runtime";import{jsx as Ne}from"react/jsx-runtime";import{useLexicalComposerContext as Eo}from"@lexical/react/LexicalComposerContext";import{$createParagraphNode as Co,$getRoot as bo}from"lexical";import"react";var Xe="insert-paragraph-at-end",Ze=()=>{let t=xo(4),[e]=Eo(),{editorConfig:o}=P();if(o?.admin?.hideInsertParagraphAtEnd)return null;let r;t[0]!==e?(r=()=>{e.update(No)},t[0]=e,t[1]=r):r=t[1];let n=r,c;return t[2]!==n?(c=Ne("div",{"aria-label":"Insert Paragraph",className:Xe,onClick:n,role:"button",tabIndex:0,children:Ne("div",{className:`${Xe}-inside`,children:Ne("span",{children:"+"})})}),t[2]=n,t[3]=c):c=t[3],c};function No(){let t=Co();bo().append(t),t.select()}import{c as Po}from"react/compiler-runtime";import{useLexicalComposerContext as So}from"@lexical/react/LexicalComposerContext";import*as et from"react";var tt=()=>{let t=Po(4),{editorConfig:e}=P(),[o]=So(),r,n;return t[0]!==o||t[1]!==e.features.markdownTransformers?(r=()=>Re(o,e.features.markdownTransformers??[]),n=[o,e.features.markdownTransformers],t[0]=o,t[1]=e.features.markdownTransformers,t[2]=r,t[3]=n):(r=t[2],n=t[3]),et.useEffect(r,n),null};import{jsx as J,jsxs as nt}from"react/jsx-runtime";import{useLexicalComposerContext as ko}from"@lexical/react/LexicalComposerContext.js";import{useTranslation as rt}from"@payloadcms/ui";import{useCallback as wo,useMemo as To,useState as vo}from"react";import"react";import*as it from"react-dom";import{c as Ro}from"react/compiler-runtime";import"react";function ot(t,e){let o=Ro(4),{maxLength:r,minLength:n}=e,c=r===void 0?75:r,i=n===void 0?1:n,l;return o[0]!==c||o[1]!==i||o[2]!==t?(l=u=>{let{query:p}=u,h="[^"+t+ke+"\\s]",s=new RegExp("(^|\\s|\\()(["+t+"]((?:"+h+"){0,"+c+"}))$").exec(p);if(s!==null){let g=s[1],x=s[3];if(x.length>=i)return{leadOffset:s.index+g.length,matchingString:x,replaceableString:s[2]}}return null},o[0]=c,o[1]=i,o[2]=t,o[3]=l):l=o[3],l}var L="slash-menu-popup";function Do({isSelected:t,item:e,onClick:o,onMouseEnter:r,ref:n}){let{fieldProps:{featureClientSchemaMap:c,schemaPath:i}}=P(),{i18n:l}=rt(),u=`${L}__item ${L}__item-${e.key}`;t&&(u+=` ${L}__item--selected`);let p=e.key;return e.label&&(p=typeof e.label=="function"?e.label({featureClientSchemaMap:c,i18n:l,schemaPath:i}):e.label),p.length>25&&(p=p.substring(0,25)+"..."),nt("button",{"aria-selected":t,className:u,id:L+"__item-"+e.key,onClick:o,onMouseEnter:r,ref:n,role:"option",tabIndex:-1,type:"button",children:[e?.Icon&&J(e.Icon,{}),J("span",{className:`${L}__item-text`,children:p})]},e.key)}function st({anchorElem:t=document.body}){let[e]=ko(),[o,r]=vo(null),{editorConfig:n}=P(),{i18n:c}=rt(),{fieldProps:{featureClientSchemaMap:i,schemaPath:l}}=P(),u=ot("/",{minLength:0}),p=wo(()=>{let a=[];for(let s of n.features.slashMenu.dynamicGroups)if(o){let g=s({editor:e,queryString:o});a=a.concat(g)}return a},[e,o,n?.features]),h=To(()=>{let a=[];for(let s of n?.features.slashMenu.groups??[])a.push(s);if(o){a=a.map(g=>{let x=g.items.filter(m=>{let y=m.key;return m.label&&(y=typeof m.label=="function"?m.label({featureClientSchemaMap:i,i18n:c,schemaPath:l}):m.label),new RegExp(o,"gi").exec(y)?!0:m.keywords!=null?m.keywords.some(d=>new RegExp(o,"gi").exec(d)):!1});return x.length?{...g,items:x}:null}),a=a.filter(g=>g!=null);let s=p();for(let g of s){let x=a.find(m=>m.key===g.key);x?a=a.filter(m=>m.key!==g.key):x={...g,items:[]},x?.items?.length&&(x.items=x.items.concat(x.items)),a.push(x)}}return a},[o,n?.features.slashMenu.groups,p,i,c,l]);return J(Te,{anchorElem:t,groups:h,menuRenderFn:(a,{selectedItemKey:s,selectItemAndCleanUp:g,setSelectedItemKey:x})=>a.current&&h.length?it.createPortal(J("div",{className:L,children:h.map(m=>{let y=m.key;return m.label&&i&&(y=typeof m.label=="function"?m.label({featureClientSchemaMap:i,i18n:c,schemaPath:l}):m.label),nt("div",{className:`${L}__group ${L}__group-${m.key}`,children:[J("div",{className:`${L}__group-title`,children:y}),m.items.map((d,f)=>J(Do,{index:f,isSelected:s===d.key,item:d,onClick:()=>{x(d.key),g(d)},onMouseEnter:()=>{x(d.key)},ref:E=>{d.ref={current:E}}},d.key))]},m.key)})}),a.current):null,onQueryChange:r,triggerFn:u})}import{c as Mo}from"react/compiler-runtime";import{useLexicalComposerContext as Bo}from"@lexical/react/LexicalComposerContext";import{TEXT_TYPE_TO_FORMAT as Lo,TextNode as Io}from"lexical";import{useEffect as Ao}from"react";function lt(t){let e=Mo(6),{features:o}=t,[r]=Bo(),n;e[0]!==r||e[1]!==o.enabledFormats?(n=()=>{let i=_o(o.enabledFormats);if(i.length!==0)return r.registerNodeTransform(Io,l=>{i.forEach(u=>{l.hasFormat(u)&&l.toggleFormat(u)})})},e[0]=r,e[1]=o.enabledFormats,e[2]=n):n=e[2];let c;return e[3]!==r||e[4]!==o?(c=[r,o],e[3]=r,e[4]=o,e[5]=c):c=e[5],Ao(n,c),null}function _o(t){let e=Object.keys(Lo),o=new Set(t);return e.filter(r=>!o.has(r))}import{c as Oo}from"react/compiler-runtime";import{jsx as at}from"react/jsx-runtime";import{ContentEditable as Fo}from"@lexical/react/LexicalContentEditable.js";import{useTranslation as $o}from"@payloadcms/ui";import"react";function ct(t){let e=Oo(7),{className:o,editorConfig:r}=t,{t:n}=$o(),c;if(e[0]!==o||e[1]!==r?.admin?.placeholder||e[2]!==n){let i;e[4]!==r?.admin?.placeholder||e[5]!==n?(i=r?.admin?.placeholder??n("lexical:general:placeholder"),e[4]=r?.admin?.placeholder,e[5]=n,e[6]=i):i=e[6],c=at(Fo,{"aria-placeholder":n("lexical:general:placeholder"),className:o??"ContentEditable__root",placeholder:at("p",{className:"editor-placeholder",children:i})}),e[0]=o,e[1]=r?.admin?.placeholder,e[2]=n,e[3]=c}else c=e[3];return c}var dt=t=>{let e=Ko(19),{editorConfig:o,editorContainerRef:r,isSmallWidthViewport:n,onChange:c}=t,i=P(),[l]=Ho(),[u,p]=qo(null),h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=m=>{m!==null&&p(m)},e[0]=h):h=e[0];let a=h,s,g;e[1]!==l||e[2]!==i?(s=()=>{if(!i?.uuid){console.error("Lexical Editor must be used within an EditorConfigProvider");return}i?.parentEditor?.uuid&&i.parentEditor?.registerChild(i.uuid,i);let m=()=>{i.focusEditor(i)},y=()=>{i.blurEditor(i)},d=l.registerCommand(Vo,()=>(m(),!0),ut),f=l.registerCommand(Go,()=>(y(),!0),ut);return()=>{d(),f(),i.parentEditor?.unregisterChild?.(i.uuid)}},g=[l,i],e[1]=l,e[2]=i,e[3]=s,e[4]=g):(s=e[3],g=e[4]),Uo(s,g);let x;if(e[5]!==l||e[6]!==o||e[7]!==r||e[8]!==u||e[9]!==n||e[10]!==c){let m;e[12]!==c?(m=(d,f,E)=>{(!E.has("focus")||E.size>1)&&c?.(d,f,E)},e[12]=c,e[13]=m):m=e[13];let y;e[14]!==l||e[15]!==o.features.plugins||e[16]!==u||e[17]!==n?(y=u&&te(Q.Fragment,{children:[!n&&l.isEditable()&&te(Q.Fragment,{children:[b(Qe,{anchorElem:u}),b(He,{anchorElem:u})]}),o.features.plugins?.map(d=>{if(d.position==="floatingAnchorElem"&&!(d.desktopOnly===!0&&n))return b(K,{anchorElem:u,clientProps:d.clientProps,plugin:d},d.key)}),l.isEditable()&&b(Q.Fragment,{children:b(st,{anchorElem:u})})]}),e[14]=l,e[15]=o.features.plugins,e[16]=u,e[17]=n,e[18]=y):y=e[18],x=te(Q.Fragment,{children:[o.features.plugins?.map(Jo),te("div",{className:"editor-container",ref:r,children:[o.features.plugins?.map(Qo),b(Yo,{contentEditable:b("div",{className:"editor-scroller",children:b("div",{className:"editor",ref:a,children:b(ct,{editorConfig:o})})}),ErrorBoundary:jo}),b(Ze,{}),b(Ie,{}),b(lt,{features:o.features}),b(Wo,{ignoreSelectionChange:!0,onChange:m}),y,l.isEditable()&&te(Q.Fragment,{children:[b(zo,{}),o?.features?.markdownTransformers?.length>0&&b(tt,{})]}),o.features.plugins?.map(Xo),o.features.plugins?.map(Zo)]}),o.features.plugins?.map(en)]}),e[5]=l,e[6]=o,e[7]=r,e[8]=u,e[9]=n,e[10]=c,e[11]=x}else x=e[11];return x};function Jo(t){if(t.position==="aboveContainer")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}function Qo(t){if(t.position==="top")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}function Xo(t){if(t.position==="normal")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}function Zo(t){if(t.position==="bottom")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}function en(t){if(t.position==="belowContainer")return b(K,{clientProps:t.clientProps,plugin:t},t.key)}var ft=({children:t,providers:e})=>{if(!e?.length)return t;let o=e[0];return e.length>1?O(o,{children:O(ft,{providers:e.slice(1),children:t})}):O(o,{children:t})},pt=t=>{let{composerKey:e,editorConfig:o,fieldProps:r,isSmallWidthViewport:n,onChange:c,readOnly:i,value:l}=t,u=P(),p=on(),h=mt.useRef(null),a=nn(()=>{if(l&&typeof l!="object")throw new Error("The value passed to the Lexical editor is not an object. This is not supported. Please remove the data from the field and start again. This is the value that was passed in: "+JSON.stringify(l));if(l&&Array.isArray(l)&&!("root"in l))throw new Error("You have tried to pass in data from the old Slate editor to the new Lexical editor. The data structure is different, thus you will have to migrate your data. We offer a one-line migration script which migrates all your rich text fields: https://payloadcms.com/docs/lexical/migration#migration-via-migration-script-recommended");if(l&&"jsonContent"in l)throw new Error("You have tried to pass in data from payload-plugin-lexical. The data structure is different, thus you will have to migrate your data. Migration guide: https://payloadcms.com/docs/lexical/migration#migrating-from-payload-plugin-lexical");return{editable:i!==!0,editorState:l!=null?JSON.stringify(l):void 0,namespace:o.lexical.namespace,nodes:De({editorConfig:o}),onError:s=>{throw s},theme:o.lexical.theme}},[o]);return a?O(tn,{initialConfig:a,children:O(Se,{editorConfig:o,editorContainerRef:h,fieldProps:r,parentContext:u?.editDepth===p?u:void 0,children:O(ft,{providers:o.features.providers,children:O(dt,{editorConfig:o,editorContainerRef:h,isSmallWidthViewport:n,onChange:c})})})},e+a.editable):O("p",{children:"Loading..."})};var fe="rich-text-lexical",pn=t=>{let{editorConfig:e,field:o,field:{name:r,admin:{className:n,description:c,readOnly:i}={},label:l,localized:u,required:p},path:h,readOnly:a,validate:s}=t,g=a||i,x=h??r,m=an(),y=yt((M,$)=>typeof s=="function"?s(M,{...$,required:p}):!0,[s,p]),{customComponents:{AfterInput:d,BeforeInput:f,Description:E,Error:k,Label:R}={},formInitializing:S,formProcessing:w,initialValue:C,setValue:W,showError:I,value:T}=un({path:x,validate:y}),v=g||w||S,[A,ge]=Et(!1),[Pe,he]=Et(),ye=ht.useRef(C),Y=ht.useRef(T);xt(()=>{let M=()=>{let $=window.matchMedia("(max-width: 768px)").matches;$!==A&&ge($)};return M(),window.addEventListener("resize",M),()=>{window.removeEventListener("resize",M)}},[A]);let D=[fe,"field-type",n,I&&"error",v&&`${fe}--read-only`,e?.admin?.hideGutter!==!0&&!A?`${fe}--show-gutter`:null].filter(Boolean).join(" "),N=`${x}.${m}`,Ct=yt(M=>{let $=M.toJSON();Y.current=$,W($)},[W]),bt=mn(()=>dn(o),[o]),Nt=cn(M=>{Y.current!==T&&JSON.stringify(Y.current)!==JSON.stringify(T)&&(ye.current=M,Y.current=T,he(new Date))});return xt(()=>{Object.is(C,ye.current)||Nt(C)},[C]),pe("div",{className:D,style:bt,children:[F(gt,{CustomComponent:k,Fallback:F(sn,{path:x,showError:I})}),R||F(ln,{label:l,localized:u,path:x,required:p}),pe("div",{className:`${fe}__wrap`,children:[pe(fn,{fallbackRender:gn,onReset:()=>{},children:[f,F(pt,{composerKey:N,editorConfig:e,fieldProps:t,isSmallWidthViewport:A,onChange:Ct,readOnly:v,value:T},JSON.stringify({path:x,rerenderProviderKey:Pe})),d]}),E,F(gt,{CustomComponent:E,Fallback:F(rn,{description:c,path:x})})]})]},N)};function gn({error:t}){return pe("div",{className:"errorBoundary",role:"alert",children:[F("p",{children:"Something went wrong:"}),F("pre",{style:{color:"red"},children:t.message})]})}var $i=pn;export{$i as RichText};
|
|
2
|
+
//# sourceMappingURL=Field-IUDF2DGI.js.map
|
package/dist/exports/client/{RelationshipComponent-JPESGV4Q.js → RelationshipComponent-APF3CN47.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{a as b}from"./chunk-DBWINSQN.js";import{a as _}from"./chunk-F26IQ5RE.js";import{b as f}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=RelationshipComponent-
|
|
1
|
+
"use client";import{a as b}from"./chunk-DBWINSQN.js";import{a as _}from"./chunk-F26IQ5RE.js";import{b as f}from"./chunk-BZZVLW4U.js";import{jsx as o,jsxs as c}from"react/jsx-runtime";import{useLexicalComposerContext as j}from"@lexical/react/LexicalComposerContext.js";import{getTranslation as B}from"@payloadcms/translations";import{Button as g,useConfig as P,usePayloadAPI as A,useTranslation as I}from"@payloadcms/ui";import{$getNodeByKey as L}from"lexical";import k,{useCallback as O,useReducer as H,useRef as K,useState as M}from"react";var e="lexical-relationship",C={depth:0},W=i=>{let{data:{relationTo:R,value:s},nodeKey:l}=i;if(typeof s=="object")throw new Error("Relationship value should be a string or number. The Lexical Relationship component should not receive the populated value object.");let v=K(null),[a]=j(),{fieldProps:{readOnly:u}}=f(),{config:{routes:{api:x},serverURL:N},getEntityConfig:$}=P(),[t]=M(()=>$({collectionSlug:R})),{i18n:w,t:n}=I(),[d,D]=H(r=>r+1,0),[{data:m},{setParams:p}]=A(`${N}${x}/${t.slug}/${s}`,{initialParams:C}),{closeDocumentDrawer:h,DocumentDrawer:y,DocumentDrawerToggler:E}=_({id:s,collectionSlug:t.slug}),T=O(()=>{a.update(()=>{L(l)?.remove()})},[a,l]),S=k.useCallback(()=>{p({...C,cacheBust:d}),h(),D()},[d,p,h]);return c("div",{className:e,contentEditable:!1,ref:v,children:[c("div",{className:`${e}__wrap`,children:[o("p",{className:`${e}__label`,children:n("fields:labelRelationship",{label:t.labels?.singular?B(t.labels?.singular,w):t.slug})}),o(E,{className:`${e}__doc-drawer-toggler`,children:o("p",{className:`${e}__title`,children:m?m[t?.admin?.useAsTitle||"id"]:s})})]}),a.isEditable()&&c("div",{className:`${e}__actions`,children:[o(g,{buttonStyle:"icon-label",className:`${e}__swapButton`,disabled:u,el:"button",icon:"swap",onClick:()=>{l&&a.dispatchCommand(b,{replace:{nodeKey:l}})},round:!0,tooltip:n("fields:swapRelationship")}),o(g,{buttonStyle:"icon-label",className:`${e}__removeButton`,disabled:u,icon:"x",onClick:r=>{r.preventDefault(),T()},round:!0,tooltip:n("fields:removeRelationship")})]}),!!s&&o(y,{onSave:S})]})},Y=i=>o(W,{...i});export{Y as RelationshipComponent};
|
|
2
|
+
//# sourceMappingURL=RelationshipComponent-APF3CN47.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as ie}from"./chunk-INBEEENE.js";import{b as se}from"./chunk-BZZVLW4U.js";import{jsx as o,jsxs as p,Fragment as Ie}from"react/jsx-runtime";import T,{createContext as Ne,useCallback as j,useEffect as N,useMemo as v,useRef as _}from"react";import{useLexicalComposerContext as ve}from"@lexical/react/LexicalComposerContext";import{getTranslation as ce}from"@payloadcms/translations";import{Button as ae,Drawer as Te,EditDepthProvider as $e,Form as Oe,formatDrawerSlug as Pe,FormSubmit as Re,RenderFields as Ee,ShimmerEffect as Le,useConfig as Me,useDocumentForm as je,useDocumentInfo as Ae,useEditDepth as Je,useServerFunctions as Ke,useTranslation as ze}from"@payloadcms/ui";import{abortAndIgnore as A}from"@payloadcms/ui/shared";import{$getNodeByKey as J}from"lexical";import{deepCopyObjectSimpleWithoutReactComponents as K,reduceFieldsToValues as He}from"payload/shared";import{v4 as Ve}from"uuid";import{jsx as Ce}from"react/jsx-runtime";import ye from"bson-objectid";import Fe from"react";import _e from"bson-objectid";import{DecoratorNode as xe}from"lexical";var B=class extends xe{__cacheBuster;__fields;constructor({cacheBuster:e,fields:t,key:r}){super(r),this.__fields=t,this.__cacheBuster=e||0}static clone(e){return new this({cacheBuster:e.__cacheBuster,fields:e.__fields,key:e.__key})}static getType(){return"inlineBlock"}static importDOM(){return{}}static importJSON(e){return Se(e.fields)}static isInline(){return!1}canIndent(){return!0}createDOM(){let e=document.createElement("span");return e.classList.add("inline-block-container"),e}decorate(e,t){return null}exportDOM(){let e=document.createElement("span");e.classList.add("inline-block-container");let t=document.createTextNode(this.getTextContent());return e.append(t),{element:e}}exportJSON(){return{type:"inlineBlock",fields:this.getFields(),version:1}}getCacheBuster(){return this.getLatest().__cacheBuster}getFields(){return this.getLatest().__fields}getTextContent(){return"Block Field"}isInline(){return!0}setFields(e,t){let r=this.getWritable();r.__fields=e,t||r.__cacheBuster++}updateDOM(){return!1}};function Se(l){return new B({fields:{...l,id:l?.id||new _e.default().toHexString()}})}var De=Fe.lazy(()=>import("./componentInline-ZB4EY7EQ.js").then(l=>({default:l.InlineBlockComponent}))),I=class extends B{static clone(e){return super.clone(e)}static getType(){return super.getType()}static importJSON(e){return we(e.fields)}decorate(e,t){return Ce(De,{cacheBuster:this.getCacheBuster(),formData:this.getFields(),nodeKey:this.getKey()})}exportJSON(){return super.exportJSON()}};function we(l){return new I({fields:{...l,id:l?.id||new ye.default().toHexString()}})}function M(l){return l instanceof I}var m="inline-block",ue=Ne({initialState:!1}),ft=()=>T.use(ue),pt=l=>{let{cacheBuster:e,formData:t,nodeKey:r}=l,[a]=ve(),{i18n:$,t:d}=ze(),{createdInlineBlock:z,fieldProps:{featureClientSchemaMap:de,initialLexicalFormState:me,permissions:fe,readOnly:x,schemaPath:H},setCreatedInlineBlock:V,uuid:pe}=se(),{fields:S}=je(),{getFormState:C}=Ke(),be=Je(),W=_(!1),[u,q]=T.useState(()=>me?.[t.id]?.formState),G=_(!1),Q=_(e);N(()=>{G.current?(Q.current!==e&&q(!1),Q.current=e):G.current=!0},[e]);let[O,U]=T.useState(u?._components?.customComponents?.BlockLabel),[X,Y]=T.useState(u?._components?.customComponents?.Block),Z=Pe({slug:`lexical-inlineBlocks-create-${pe}-${t.id}`,depth:be}),{toggleDrawer:b}=ie(Z,!0),ke=_(null),{id:y,collectionSlug:F,getDocPreferences:D,globalSlug:w}=Ae(),{config:he}=Me(),ge=`${H}.lexical_internal_feature.blocks.lexical_inline_blocks.${t.blockType}`,k=de.blocks?.[ge]?.[0],i=k.blockReferences?typeof k?.blockReferences?.[0]=="string"?he.blocksMap[k?.blockReferences?.[0]]:k?.blockReferences?.[0]:k?.blocks?.[0],ee=i?.fields??[];N(()=>{!W.current&&z?.getKey()===r&&(ee.length>2&&b(),V?.(void 0),W.current=!0)},[ee.length,z,r,V,b]);let te=j(()=>{a.update(()=>{J(r)?.remove()})},[a,r]),h=i?.labels?.singular?ce(i?.labels.singular,$):i?.slug,P=_(new AbortController),g=`${H}.lexical_internal_feature.blocks.lexical_inline_blocks.${i?.slug}.fields`;N(()=>{let n=new AbortController;return t&&!u&&(async()=>{let{state:s}=await C({id:y,collectionSlug:F,data:t,docPermissions:{fields:!0},docPreferences:await D(),documentFormState:K(S),globalSlug:w,initialBlockData:t,initialBlockFormState:t,operation:"update",renderAllFields:!0,schemaPath:g,signal:n.signal});if(s){let f=He(K(s),!0);a.update(()=>{let L=J(r);if(L&&M(L)){let le=f;le.blockType=t.blockType,L.setFields(le,!0)}}),q(s),U(s._components?.customComponents?.BlockLabel),Y(s._components?.customComponents?.Block)}})(),()=>{A(n)}},[C,a,r,g,y,t,u,F,w,D,S]);let ne=j(async({formState:n,submit:c})=>{A(P.current);let s=new AbortController;P.current=s;let{state:f}=await C({id:y,collectionSlug:F,docPermissions:{fields:!0},docPreferences:await D(),documentFormState:K(S),formState:n,globalSlug:w,initialBlockFormState:n,operation:"update",renderAllFields:!!c,schemaPath:g,signal:s.signal});return f?(c&&(U(f._components?.customComponents?.BlockLabel),Y(f._components?.customComponents?.Block)),f):n},[C,y,F,D,S,w,g]);N(()=>()=>{A(P.current)},[]);let Be=j((n,c)=>{c.blockType=t.blockType,a.update(()=>{let s=J(r);s&&M(s)&&s.setFields(c,!0)})},[a,r,t]),R=v(()=>()=>o(ae,{buttonStyle:"icon-label",className:`${m}__removeButton`,disabled:x,icon:"x",onClick:n=>{n.preventDefault(),te()},round:!0,size:"small",tooltip:d("lexical:blocks:inlineBlocks:remove",{label:h})}),[h,x,te,d]),oe=v(()=>()=>o(ae,{buttonStyle:"icon-label",className:`${m}__editButton`,disabled:x,el:"button",icon:"edit",onClick:()=>{b()},round:!0,size:"small",tooltip:d("lexical:blocks:inlineBlocks:edit",{label:h})}),[h,x,d,b]),E=v(()=>({children:n,className:c})=>o("div",{className:[m,m+"-"+t.blockType,c].filter(Boolean).join(" "),ref:ke,children:n}),[t.blockType]),re=v(()=>O?()=>O:()=>o("div",{children:i?.labels?ce(i?.labels.singular,$):""}),[O,i?.labels,$]);return i?p(Oe,{beforeSubmit:[async({formState:n})=>await ne({formState:n,submit:!0})],disableValidationOnSubmit:!0,el:"div",fields:i?.fields,initialState:u||{},onChange:[ne],onSubmit:(n,c)=>{Be(n,c),b()},uuid:Ve(),children:[o($e,{children:o(Te,{className:"",slug:Z,title:d(`lexical:blocks:inlineBlocks:${t?.id?"edit":"create"}`,{label:h??d("lexical:blocks:inlineBlocks:label")}),children:u?p(Ie,{children:[o(Ee,{fields:i?.fields,forceRender:!0,parentIndexPath:"",parentPath:"",parentSchemaPath:g,permissions:fe,readOnly:!1}),o(Re,{programmaticSubmit:!0,children:d("fields:saveChanges")})]}):null})}),X?o(ue,{value:{EditButton:oe,initialState:u,InlineBlockContainer:E,Label:re,nodeKey:r,RemoveButton:R},children:X}):p(E,{children:[u?o(re,{}):o(Le,{height:"15px",width:"40px"}),a.isEditable()?p("div",{className:`${m}__actions`,children:[o(oe,{}),o(R,{})]}):null]})]}):p(E,{className:`${m}-not-found`,children:[p("span",{children:["Error: Block '",t.blockType,"' not found"]}),a.isEditable()?o("div",{className:`${m}__actions`,children:o(R,{})}):null]})};export{ft as a,pt as b,I as c,we as d,M as e};
|
|
2
|
+
//# sourceMappingURL=chunk-46KMRCKV.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/features/blocks/client/componentInline/index.tsx", "../../../src/features/blocks/client/nodes/InlineBlocksNode.tsx", "../../../src/features/blocks/server/nodes/InlineBlocksNode.tsx"],
|
|
4
|
+
"sourcesContent": ["'use client'\n\nimport React, { createContext, useCallback, useEffect, useMemo, useRef } from 'react'\nconst baseClass = 'inline-block'\n\nimport type { BlocksFieldClient, ClientBlock, Data, FormState } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n Drawer,\n EditDepthProvider,\n Form,\n formatDrawerSlug,\n FormSubmit,\n RenderFields,\n ShimmerEffect,\n useConfig,\n useDocumentForm,\n useDocumentInfo,\n useEditDepth,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport { abortAndIgnore } from '@payloadcms/ui/shared'\nimport { $getNodeByKey } from 'lexical'\n\nimport './index.scss'\n\nimport { deepCopyObjectSimpleWithoutReactComponents, reduceFieldsToValues } from 'payload/shared'\nimport { v4 as uuid } from 'uuid'\n\nimport type { InlineBlockFields } from '../../server/nodes/InlineBlocksNode.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { $isInlineBlockNode } from '../nodes/InlineBlocksNode.js'\n\ntype Props = {\n /**\n * Can be modified by the node in order to trigger the re-fetch of the initial state based on the\n * formData. This is useful when node.setFields() is explicitly called from outside of the form - in\n * this case, the new field state is likely not reflected in the form state, so we need to re-fetch\n */\n readonly cacheBuster: number\n readonly formData: InlineBlockFields\n readonly nodeKey: string\n}\n\ntype InlineBlockComponentContextType = {\n EditButton?: React.FC\n initialState: false | FormState | undefined\n InlineBlockContainer?: React.FC<{ children: React.ReactNode }>\n Label?: React.FC\n nodeKey?: string\n RemoveButton?: React.FC\n}\n\nconst InlineBlockComponentContext = createContext<InlineBlockComponentContextType>({\n initialState: false,\n})\n\nexport const useInlineBlockComponentContext = () => React.use(InlineBlockComponentContext)\n\nexport const InlineBlockComponent: React.FC<Props> = (props) => {\n const { cacheBuster, formData, nodeKey } = props\n\n const [editor] = useLexicalComposerContext()\n const { i18n, t } = useTranslation<object, string>()\n const {\n createdInlineBlock,\n fieldProps: {\n featureClientSchemaMap,\n initialLexicalFormState,\n permissions,\n readOnly,\n schemaPath,\n },\n setCreatedInlineBlock,\n uuid: uuidFromContext,\n } = useEditorConfigContext()\n const { fields: parentDocumentFields } = useDocumentForm()\n\n const { getFormState } = useServerFunctions()\n const editDepth = useEditDepth()\n const firstTimeDrawer = useRef(false)\n\n const [initialState, setInitialState] = React.useState<false | FormState | undefined>(\n () => initialLexicalFormState?.[formData.id]?.formState,\n )\n\n const hasMounted = useRef(false)\n const prevCacheBuster = useRef(cacheBuster)\n useEffect(() => {\n if (hasMounted.current) {\n if (prevCacheBuster.current !== cacheBuster) {\n setInitialState(false)\n }\n prevCacheBuster.current = cacheBuster\n } else {\n hasMounted.current = true\n }\n }, [cacheBuster])\n\n const [CustomLabel, setCustomLabel] = React.useState<React.ReactNode | undefined>(\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n initialState?.['_components']?.customComponents?.BlockLabel,\n )\n\n const [CustomBlock, setCustomBlock] = React.useState<React.ReactNode | undefined>(\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n initialState?.['_components']?.customComponents?.Block,\n )\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-inlineBlocks-create-${uuidFromContext}-${formData.id}`,\n depth: editDepth,\n })\n const { toggleDrawer } = useLexicalDrawer(drawerSlug, true)\n\n const inlineBlockElemElemRef = useRef<HTMLDivElement | null>(null)\n const { id, collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo()\n const { config } = useConfig()\n\n const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${formData.blockType}`\n\n const clientSchemaMap = featureClientSchemaMap['blocks']\n\n const blocksField: BlocksFieldClient = clientSchemaMap?.[\n componentMapRenderedBlockPath\n ]?.[0] as BlocksFieldClient\n\n const clientBlock: ClientBlock | undefined = blocksField.blockReferences\n ? typeof blocksField?.blockReferences?.[0] === 'string'\n ? config.blocksMap[blocksField?.blockReferences?.[0]]\n : blocksField?.blockReferences?.[0]\n : blocksField?.blocks?.[0]\n\n const clientBlockFields = clientBlock?.fields ?? []\n\n // Open drawer on \"mount\"\n useEffect(() => {\n if (!firstTimeDrawer.current && createdInlineBlock?.getKey() === nodeKey) {\n // > 2 because they always have \"id\" and \"blockName\" fields\n if (clientBlockFields.length > 2) {\n toggleDrawer()\n }\n setCreatedInlineBlock?.(undefined)\n firstTimeDrawer.current = true\n }\n }, [clientBlockFields.length, createdInlineBlock, nodeKey, setCreatedInlineBlock, toggleDrawer])\n\n const removeInlineBlock = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey)?.remove()\n })\n }, [editor, nodeKey])\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock?.labels.singular, i18n)\n : clientBlock?.slug\n\n const onChangeAbortControllerRef = useRef(new AbortController())\n const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${clientBlock?.slug}.fields`\n\n // Initial state for newly created blocks\n useEffect(() => {\n const abortController = new AbortController()\n\n const awaitInitialState = async () => {\n /*\n * This will only run if a new block is created. For all existing blocks that are loaded when the document is loaded, or when the form is saved,\n * this is not run, as the lexical field RSC will fetch the state server-side and pass it to the client. That way, we avoid unnecessary client-side\n * requests. Though for newly created blocks, we need to fetch the state client-side, as the server doesn't know about the block yet.\n */\n const { state } = await getFormState({\n id,\n collectionSlug,\n data: formData,\n docPermissions: { fields: true },\n docPreferences: await getDocPreferences(),\n documentFormState: deepCopyObjectSimpleWithoutReactComponents(parentDocumentFields),\n globalSlug,\n initialBlockData: formData,\n initialBlockFormState: formData,\n operation: 'update',\n renderAllFields: true,\n schemaPath: schemaFieldsPath,\n signal: abortController.signal,\n })\n\n if (state) {\n const newFormStateData: InlineBlockFields = reduceFieldsToValues(\n deepCopyObjectSimpleWithoutReactComponents(state),\n true,\n ) as InlineBlockFields\n\n // Things like default values may come back from the server => update the node with the new data\n editor.update(() => {\n const node = $getNodeByKey(nodeKey)\n if (node && $isInlineBlockNode(node)) {\n const newData = newFormStateData\n newData.blockType = formData.blockType\n\n node.setFields(newData, true)\n }\n })\n\n setInitialState(state)\n setCustomLabel(state['_components']?.customComponents?.BlockLabel)\n setCustomBlock(state['_components']?.customComponents?.Block)\n }\n }\n\n if (formData && !initialState) {\n void awaitInitialState()\n }\n\n return () => {\n abortAndIgnore(abortController)\n }\n }, [\n getFormState,\n editor,\n nodeKey,\n schemaFieldsPath,\n id,\n formData,\n initialState,\n collectionSlug,\n globalSlug,\n getDocPreferences,\n parentDocumentFields,\n ])\n\n /**\n * HANDLE ONCHANGE\n */\n const onChange = useCallback(\n async ({ formState: prevFormState, submit }: { formState: FormState; submit?: boolean }) => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n\n const controller = new AbortController()\n onChangeAbortControllerRef.current = controller\n\n const { state } = await getFormState({\n id,\n collectionSlug,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n documentFormState: deepCopyObjectSimpleWithoutReactComponents(parentDocumentFields),\n formState: prevFormState,\n globalSlug,\n initialBlockFormState: prevFormState,\n operation: 'update',\n renderAllFields: submit ? true : false,\n schemaPath: schemaFieldsPath,\n signal: controller.signal,\n })\n\n if (!state) {\n return prevFormState\n }\n\n if (submit) {\n setCustomLabel(state['_components']?.customComponents?.BlockLabel)\n setCustomBlock(state['_components']?.customComponents?.Block)\n }\n\n return state\n },\n [\n getFormState,\n id,\n collectionSlug,\n getDocPreferences,\n parentDocumentFields,\n globalSlug,\n schemaFieldsPath,\n ],\n )\n // cleanup effect\n useEffect(() => {\n return () => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n }\n }, [])\n\n /**\n * HANDLE FORM SUBMIT\n */\n const onFormSubmit = useCallback(\n (formState: FormState, newData: Data) => {\n newData.blockType = formData.blockType\n\n editor.update(() => {\n const node = $getNodeByKey(nodeKey)\n if (node && $isInlineBlockNode(node)) {\n node.setFields(newData as InlineBlockFields, true)\n }\n })\n },\n [editor, nodeKey, formData],\n )\n\n const RemoveButton = useMemo(\n () => () => (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeInlineBlock()\n }}\n round\n size=\"small\"\n tooltip={t('lexical:blocks:inlineBlocks:remove', { label: blockDisplayName })}\n />\n ),\n [blockDisplayName, readOnly, removeInlineBlock, t],\n )\n\n const EditButton = useMemo(\n () => () => (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__editButton`}\n disabled={readOnly}\n el=\"button\"\n icon=\"edit\"\n onClick={() => {\n toggleDrawer()\n }}\n round\n size=\"small\"\n tooltip={t('lexical:blocks:inlineBlocks:edit', { label: blockDisplayName })}\n />\n ),\n [blockDisplayName, readOnly, t, toggleDrawer],\n )\n\n const InlineBlockContainer = useMemo(\n () =>\n ({ children, className }: { children: React.ReactNode; className?: string }) => (\n <div\n className={[baseClass, baseClass + '-' + formData.blockType, className]\n .filter(Boolean)\n .join(' ')}\n ref={inlineBlockElemElemRef}\n >\n {children}\n </div>\n ),\n [formData.blockType],\n )\n\n const Label = useMemo(() => {\n if (CustomLabel) {\n return () => CustomLabel\n } else {\n return () => (\n <div>{clientBlock?.labels ? getTranslation(clientBlock?.labels.singular, i18n) : ''}</div>\n )\n }\n }, [CustomLabel, clientBlock?.labels, i18n])\n\n if (!clientBlock) {\n return (\n <InlineBlockContainer className={`${baseClass}-not-found`}>\n <span>Error: Block '{formData.blockType}' not found</span>\n {editor.isEditable() ? (\n <div className={`${baseClass}__actions`}>\n <RemoveButton />\n </div>\n ) : null}\n </InlineBlockContainer>\n )\n }\n\n return (\n <Form\n beforeSubmit={[\n async ({ formState }) => {\n // This is only called when form is submitted from drawer\n return await onChange({ formState, submit: true })\n },\n ]}\n disableValidationOnSubmit\n el=\"div\"\n fields={clientBlock?.fields}\n initialState={initialState || {}}\n onChange={[onChange]}\n onSubmit={(formState, data) => {\n onFormSubmit(formState, data)\n toggleDrawer()\n }}\n uuid={uuid()}\n >\n <EditDepthProvider>\n <Drawer\n className={''}\n slug={drawerSlug}\n title={t(`lexical:blocks:inlineBlocks:${formData?.id ? 'edit' : 'create'}`, {\n label: blockDisplayName ?? t('lexical:blocks:inlineBlocks:label'),\n })}\n >\n {initialState ? (\n <>\n <RenderFields\n fields={clientBlock?.fields}\n forceRender\n parentIndexPath=\"\"\n parentPath=\"\" // See Blocks feature path for details as for why this is empty\n parentSchemaPath={schemaFieldsPath}\n permissions={permissions}\n readOnly={false}\n />\n <FormSubmit programmaticSubmit={true}>{t('fields:saveChanges')}</FormSubmit>\n </>\n ) : null}\n </Drawer>\n </EditDepthProvider>\n {CustomBlock ? (\n <InlineBlockComponentContext\n value={{\n EditButton,\n initialState,\n InlineBlockContainer,\n Label,\n nodeKey,\n RemoveButton,\n }}\n >\n {CustomBlock}\n </InlineBlockComponentContext>\n ) : (\n <InlineBlockContainer>\n {initialState ? <Label /> : <ShimmerEffect height=\"15px\" width=\"40px\" />}\n {editor.isEditable() ? (\n <div className={`${baseClass}__actions`}>\n <EditButton />\n <RemoveButton />\n </div>\n ) : null}\n </InlineBlockContainer>\n )}\n </Form>\n )\n}\n", "'use client'\nimport type { EditorConfig, LexicalEditor, LexicalNode } from 'lexical'\n\nimport ObjectID from 'bson-objectid'\nimport React, { type JSX } from 'react'\n\nimport type {\n InlineBlockFields,\n SerializedInlineBlockNode,\n} from '../../server/nodes/InlineBlocksNode.js'\n\nimport { ServerInlineBlockNode } from '../../server/nodes/InlineBlocksNode.js'\n\nconst InlineBlockComponent = React.lazy(() =>\n import('../componentInline/index.js').then((module) => ({\n default: module.InlineBlockComponent,\n })),\n)\n\nexport class InlineBlockNode extends ServerInlineBlockNode {\n static override clone(node: ServerInlineBlockNode): ServerInlineBlockNode {\n return super.clone(node)\n }\n\n static override getType(): string {\n return super.getType()\n }\n\n static override importJSON(serializedNode: SerializedInlineBlockNode): InlineBlockNode {\n const node = $createInlineBlockNode(serializedNode.fields)\n return node\n }\n\n override decorate(editor: LexicalEditor, config: EditorConfig): JSX.Element {\n return (\n <InlineBlockComponent\n cacheBuster={this.getCacheBuster()}\n formData={this.getFields()}\n nodeKey={this.getKey()}\n />\n )\n }\n\n override exportJSON(): SerializedInlineBlockNode {\n return super.exportJSON()\n }\n}\n\nexport function $createInlineBlockNode(fields: Exclude<InlineBlockFields, 'id'>): InlineBlockNode {\n return new InlineBlockNode({\n fields: {\n ...fields,\n id: fields?.id || new ObjectID.default().toHexString(),\n },\n })\n}\n\nexport function $isInlineBlockNode(\n node: InlineBlockNode | LexicalNode | null | undefined,\n): node is InlineBlockNode {\n return node instanceof InlineBlockNode\n}\n", "import type {\n DOMConversionMap,\n DOMExportOutput,\n EditorConfig,\n LexicalEditor,\n LexicalNode,\n NodeKey,\n SerializedLexicalNode,\n Spread,\n} from 'lexical'\nimport type { JsonObject } from 'payload'\nimport type React from 'react'\nimport type { JSX } from 'react'\n\nimport ObjectID from 'bson-objectid'\nimport { DecoratorNode } from 'lexical'\n\nexport type InlineBlockFields<TInlineBlockFields extends JsonObject = JsonObject> = {\n blockType: string\n id: string\n} & TInlineBlockFields\n\nexport type SerializedInlineBlockNode<TBlockFields extends JsonObject = JsonObject> = Spread<\n {\n children?: never // required so that our typed editor state doesn't automatically add children\n fields: InlineBlockFields<TBlockFields>\n type: 'inlineBlock'\n },\n SerializedLexicalNode\n>\n\nexport class ServerInlineBlockNode extends DecoratorNode<null | React.ReactElement> {\n __cacheBuster: number\n __fields: InlineBlockFields\n\n constructor({\n cacheBuster,\n fields,\n key,\n }: {\n cacheBuster?: number\n fields: InlineBlockFields\n key?: NodeKey\n }) {\n super(key)\n this.__fields = fields\n this.__cacheBuster = cacheBuster || 0\n }\n\n static override clone(node: ServerInlineBlockNode): ServerInlineBlockNode {\n return new this({\n cacheBuster: node.__cacheBuster,\n fields: node.__fields,\n key: node.__key,\n })\n }\n\n static override getType(): string {\n return 'inlineBlock'\n }\n\n static override importDOM(): DOMConversionMap<HTMLDivElement> | null {\n return {}\n }\n\n static override importJSON(serializedNode: SerializedInlineBlockNode): ServerInlineBlockNode {\n const node = $createServerInlineBlockNode(serializedNode.fields)\n return node\n }\n\n static isInline(): false {\n return false\n }\n\n canIndent() {\n return true\n }\n override createDOM() {\n const element = document.createElement('span')\n element.classList.add('inline-block-container')\n\n return element\n }\n\n override decorate(editor: LexicalEditor, config: EditorConfig): JSX.Element | null {\n return null\n }\n\n override exportDOM(): DOMExportOutput {\n const element = document.createElement('span')\n element.classList.add('inline-block-container')\n\n const text = document.createTextNode(this.getTextContent())\n element.append(text)\n return { element }\n }\n\n override exportJSON(): SerializedInlineBlockNode {\n return {\n type: 'inlineBlock',\n fields: this.getFields(),\n version: 1,\n }\n }\n\n getCacheBuster(): number {\n return this.getLatest().__cacheBuster\n }\n\n getFields(): InlineBlockFields {\n return this.getLatest().__fields\n }\n\n override getTextContent(): string {\n return `Block Field`\n }\n\n override isInline() {\n return true\n }\n\n setFields(fields: InlineBlockFields, preventFormStateUpdate?: boolean): void {\n const writable = this.getWritable()\n writable.__fields = fields\n if (!preventFormStateUpdate) {\n writable.__cacheBuster++\n }\n }\n\n override updateDOM(): boolean {\n return false\n }\n}\n\nexport function $createServerInlineBlockNode(\n fields: Exclude<InlineBlockFields, 'id'>,\n): ServerInlineBlockNode {\n return new ServerInlineBlockNode({\n fields: {\n ...fields,\n id: fields?.id || new ObjectID.default().toHexString(),\n },\n })\n}\n\nexport function $isServerInlineBlockNode(\n node: LexicalNode | null | ServerInlineBlockNode | undefined,\n): node is ServerInlineBlockNode {\n return node instanceof ServerInlineBlockNode\n}\n"],
|
|
5
|
+
"mappings": "mJAEA,OAAOA,GAASC,iBAAAA,GAAeC,eAAAA,EAAaC,aAAAA,EAAWC,WAAAA,EAASC,UAAAA,MAAc,QAK9E,OAASC,6BAAAA,OAAiC,wCAC1C,OAASC,kBAAAA,OAAsB,2BAC/B,OACEC,UAAAA,GACAC,UAAAA,GACAC,qBAAAA,GACAC,QAAAA,GACAC,oBAAAA,GACAC,cAAAA,GACAC,gBAAAA,GACAC,iBAAAA,GACAC,aAAAA,GACAC,mBAAAA,GACAC,mBAAAA,GACAC,gBAAAA,GACAC,sBAAAA,GACAC,kBAAAA,OACK,iBACP,OAASC,kBAAAA,MAAsB,wBAC/B,OAASC,iBAAAA,MAAqB,UAI9B,OAASC,8CAAAA,EAA4CC,wBAAAA,OAA4B,iBACjF,OAASC,MAAMC,OAAY,gDC5B3B,OAAOC,OAAc,gBACrB,OAAOC,OAAyB,QCUhC,OAAOC,OAAc,gBACrB,OAASC,iBAAAA,OAAqB,UAgBvB,IAAMC,EAAN,cAAoCD,EAAA,CACzCE,cACAC,SAEAC,YAAY,CACVC,YAAAA,EACAC,OAAAA,EACAC,IAAAA,CAAG,EAKF,CACD,MAAMA,CAAA,EACN,KAAKJ,SAAWG,EAChB,KAAKJ,cAAgBG,GAAe,CACtC,CAEA,OAAgBG,MAAMC,EAAoD,CACxE,OAAO,IAAI,KAAK,CACdJ,YAAaI,EAAKP,cAClBI,OAAQG,EAAKN,SACbI,IAAKE,EAAKC,KACZ,CAAA,CACF,CAEA,OAAgBC,SAAkB,CAChC,MAAO,aACT,CAEA,OAAgBC,WAAqD,CACnE,MAAO,CAAC,CACV,CAEA,OAAgBC,WAAWC,EAAkE,CAE3F,OADaC,GAA6BD,EAAeR,MAAM,CAEjE,C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kD,CAAA,EACxBlC,EAAA,CACF,EACA/B,KAAMA,GAAA,YAENyF,EAAC2B,GAAA,UACC3B,EAAC4B,GAAA,CACCzB,UAAW,GACX/D,KAAMF,EACN2F,MAAOhI,EAAE,+BAA+BL,GAAU6B,GAAK,OAAS,QAAA,GAAY,CAC1EuF,MAAO7C,GAAoBlE,EAAE,mCAAA,CAC/B,CAAA,WAECZ,EACCqI,EAAAQ,GAAA,WACE9B,EAAC+B,GAAA,CACCrH,OAAQwC,GAAaxC,OACrBsH,YAAW,GACXC,gBAAgB,GAChBC,WAAW,GACXC,iBAAkB9D,EAClBlE,YAAaA,GACbC,SAAU,KAEZ4F,EAACoC,GAAA,CAAWC,mBAAoB,YAAOxI,EAAE,oBAAA,OAEzC,SAGPkC,EACCiE,EAACjH,GAAA,CACCuJ,MAAO,CACLzB,WAAAA,GACA5H,aAAAA,EACA8H,qBAAAA,EACAM,MAAAA,GACA5H,QAAAA,EACAqG,aAAAA,CACF,WAEC/D,IAGHuF,EAACP,EAAA,WACE9H,EAAe+G,EAACqB,GAAA,CAAA,CAAA,EAAWrB,EAACuC,GAAA,CAAcC,OAAO,OAAOC,MAAM,SAC9D/I,EAAOgJ,WAAU,EAChBpB,EAAC,MAAA,CAAInB,UAAW,GAAGrH,CAAA,sBACjBkH,EAACa,GAAA,CAAA,CAAA,EACDb,EAACF,EAAA,CAAA,CAAA,CAAA,IAED,IAAA,OA3ERwB,EAACP,EAAA,CAAqBZ,UAAW,GAAGrH,CAAA,uBAClCwI,EAAC,OAAA,WAAK,iBAAe9H,EAASwD,UAAU,aAAA,IACvCtD,EAAOgJ,WAAU,EAChB1C,EAAC,MAAA,CAAIG,UAAW,GAAGrH,CAAA,qBACjBkH,EAACF,EAAA,CAAA,CAAA,IAED,IAAA,GA0EZ",
|
|
6
|
+
"names": ["React", "createContext", "useCallback", "useEffect", "useMemo", "useRef", "useLexicalComposerContext", "getTranslation", "Button", "Drawer", "EditDepthProvider", "Form", "formatDrawerSlug", "FormSubmit", "RenderFields", "ShimmerEffect", "useConfig", "useDocumentForm", "useDocumentInfo", "useEditDepth", "useServerFunctions", "useTranslation", "abortAndIgnore", "$getNodeByKey", "deepCopyObjectSimpleWithoutReactComponents", "reduceFieldsToValues", "v4", "uuid", "ObjectID", "React", "ObjectID", "DecoratorNode", "ServerInlineBlockNode", "__cacheBuster", "__fields", "constructor", "cacheBuster", "fields", "key", "clone", "node", "__key", "getType", "importDOM", "importJSON", "serializedNode", "$createServerInlineBlockNode", "isInline", "canIndent", "createDOM", "element", "document", "createElement", "classList", "add", "decorate", "editor", "config", "exportDOM", "text", "createTextNode", "getTextContent", "append", "exportJSON", "type", "getFields", "version", "getCacheBuster", "getLatest", "setFields", "preventFormStateUpdate", "writable", "getWritable", "updateDOM", "id", "default", "toHexString", "InlineBlockComponent", "React", "lazy", "then", "module", "default", "InlineBlockNode", "ServerInlineBlockNode", "clone", "node", "getType", "importJSON", "serializedNode", "$createInlineBlockNode", "fields", "decorate", "editor", "config", "_jsx", "cacheBuster", "getCacheBuster", "formData", "getFields", "nodeKey", "getKey", "exportJSON", "id", "ObjectID", "toHexString", "$isInlineBlockNode", "baseClass", "InlineBlockComponentContext", "createContext", "initialState", "useInlineBlockComponentContext", "React", "use", "InlineBlockComponent", "props", "cacheBuster", "formData", "nodeKey", "editor", "useLexicalComposerContext", "i18n", "t", "useTranslation", "createdInlineBlock", "fieldProps", "featureClientSchemaMap", "initialLexicalFormState", "permissions", "readOnly", "schemaPath", "setCreatedInlineBlock", "uuid", "uuidFromContext", "useEditorConfigContext", "fields", "parentDocumentFields", "useDocumentForm", "getFormState", "useServerFunctions", "editDepth", "useEditDepth", "firstTimeDrawer", "useRef", "setInitialState", "useState", "id", "formState", "hasMounted", "prevCacheBuster", "useEffect", "current", "CustomLabel", "setCustomLabel", "customComponents", "BlockLabel", "CustomBlock", "setCustomBlock", "Block", "drawerSlug", "formatDrawerSlug", "slug", "depth", "toggleDrawer", "useLexicalDrawer", "inlineBlockElemElemRef", "collectionSlug", "getDocPreferences", "globalSlug", "useDocumentInfo", "config", "useConfig", "componentMapRenderedBlockPath", "blockType", "blocksField", "clientBlock", "blockReferences", "blocksMap", "blocks", "clientBlockFields", "getKey", "length", "undefined", "removeInlineBlock", "useCallback", "update", "$getNodeByKey", "remove", "blockDisplayName", "labels", "singular", "getTranslation", "onChangeAbortControllerRef", "AbortController", "schemaFieldsPath", "abortController", "state", "data", "docPermissions", "docPreferences", "documentFormState", "deepCopyObjectSimpleWithoutReactComponents", "initialBlockData", "initialBlockFormState", "operation", "renderAllFields", "signal", "newFormStateData", "reduceFieldsToValues", "node", "$isInlineBlockNode", "newData", "setFields", "abortAndIgnore", "onChange", "prevFormState", "submit", "controller", "onFormSubmit", "RemoveButton", "useMemo", "_jsx", "Button", "buttonStyle", "className", "disabled", "icon", "onClick", "e", "preventDefault", "round", "size", "tooltip", "label", "EditButton", "el", "InlineBlockContainer", "children", "filter", "Boolean", "join", "ref", "Label", "_jsxs", "Form", "beforeSubmit", "disableValidationOnSubmit", "onSubmit", "EditDepthProvider", "Drawer", "title", "_Fragment", "RenderFields", "forceRender", "parentIndexPath", "parentPath", "parentSchemaPath", "FormSubmit", "programmaticSubmit", "value", "ShimmerEffect", "height", "width", "isEditable"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsx as x}from"react/jsx-runtime";import{useLexicalComposerContext as b}from"@lexical/react/LexicalComposerContext.js";import{useEditDepth as S}from"@payloadcms/ui";import"react";import{createContext as k,use as v,useMemo as j,useRef as g,useState as s}from"react";function B(){return Math.random().toString(36).substring(2,12)+Math.random().toString(36).substring(2,12)}var w=k({editorConfig:null,fieldProps:null,uuid:null}),H=({children:o,editorConfig:c,editorContainerRef:d,fieldProps:a,parentContext:n})=>{let[f]=b(),[l]=s(()=>B()),r=g(new Map),[m,C]=s(null),u=g(new Set),[E,p]=s(),h=S(),M=j(()=>({blurEditor:t=>{u.current.clear()},childrenEditors:r,createdInlineBlock:E,editDepth:h,editor:f,editorConfig:c,editorContainerRef:d,fieldProps:a,focusedEditor:m,focusEditor:t=>{let e=t.uuid;u.current.has(e)||(u.current.add(e),C(t),n?.uuid&&n.focusEditor(t),r.current.forEach(i=>{i.focusEditor(t)}),u.current.clear())},parentEditor:n,registerChild:(t,e)=>{if(!r.current.has(t)){let i=new Map(r.current);i.set(t,e),r.current=i}},setCreatedInlineBlock:p,unregisterChild:t=>{if(r.current.has(t)){let e=new Map(r.current);e.delete(t),r.current=e}},uuid:l}),[E,p,f,r,c,d,h,a,m,n,l]);return x(w,{value:M,children:o})},I=()=>{let o=v(w);if(o===void 0)throw new Error("useEditorConfigContext must be used within an EditorConfigProvider");return o};export{H as a,I as b};
|
|
2
|
+
//# sourceMappingURL=chunk-BZZVLW4U.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lexical/config/client/EditorConfigProvider.tsx"],
|
|
4
|
+
"sourcesContent": ["'use client'\n\nimport type { LexicalEditor } from 'lexical'\nimport type { MarkRequired } from 'ts-essentials'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useEditDepth } from '@payloadcms/ui'\nimport * as React from 'react'\nimport { createContext, use, useMemo, useRef, useState } from 'react'\n\nimport type { InlineBlockNode } from '../../../features/blocks/client/nodes/InlineBlocksNode.js'\nimport type { LexicalRichTextFieldProps } from '../../../types.js'\nimport type { SanitizedClientEditorConfig } from '../types.js'\n\n// Should always produce a 20 character pseudo-random string\nfunction generateQuickGuid(): string {\n return Math.random().toString(36).substring(2, 12) + Math.random().toString(36).substring(2, 12)\n}\n\nexport interface EditorConfigContextType {\n // Editor focus handling\n blurEditor: (editorContext: EditorConfigContextType) => void\n childrenEditors: React.RefObject<Map<string, EditorConfigContextType>>\n createdInlineBlock?: InlineBlockNode\n editDepth: number\n editor: LexicalEditor\n editorConfig: SanitizedClientEditorConfig\n editorContainerRef: React.RefObject<HTMLDivElement>\n fieldProps: MarkRequired<LexicalRichTextFieldProps, 'path' | 'schemaPath'>\n focusedEditor: EditorConfigContextType | null\n // Editor focus handling\n focusEditor: (editorContext: EditorConfigContextType) => void\n parentEditor: EditorConfigContextType\n registerChild: (uuid: string, editorContext: EditorConfigContextType) => void\n setCreatedInlineBlock?: React.Dispatch<React.SetStateAction<InlineBlockNode | undefined>>\n unregisterChild?: (uuid: string) => void\n uuid: string\n}\n\n// @ts-expect-error: TODO: Fix this\nconst Context: React.Context<EditorConfigContextType> = createContext({\n editorConfig: null,\n fieldProps: null,\n uuid: null,\n})\n\nexport const EditorConfigProvider = ({\n children,\n editorConfig,\n editorContainerRef,\n fieldProps,\n parentContext,\n}: {\n children: React.ReactNode\n editorConfig: SanitizedClientEditorConfig\n editorContainerRef: React.RefObject<HTMLDivElement | null>\n\n fieldProps: LexicalRichTextFieldProps\n parentContext?: EditorConfigContextType\n}): React.ReactNode => {\n const [editor] = useLexicalComposerContext()\n // State to store the UUID\n const [uuid] = useState(() => generateQuickGuid())\n\n const childrenEditors = useRef<Map<string, EditorConfigContextType>>(new Map())\n const [focusedEditor, setFocusedEditor] = useState<EditorConfigContextType | null>(null)\n const focusHistory = useRef<Set<string>>(new Set())\n const [createdInlineBlock, setCreatedInlineBlock] = useState<InlineBlockNode>()\n\n const editDepth = useEditDepth()\n\n const editorContext = useMemo(\n () =>\n ({\n blurEditor: (editorContext: EditorConfigContextType) => {\n //setFocusedEditor(null) // Clear focused editor\n focusHistory.current.clear() // Reset focus history when focus is lost\n },\n childrenEditors,\n createdInlineBlock,\n editDepth,\n editor,\n editorConfig,\n editorContainerRef,\n fieldProps,\n focusedEditor,\n focusEditor: (editorContext: EditorConfigContextType) => {\n const editorUUID = editorContext.uuid\n\n // Avoid recursion by checking if this editor is already focused in this cycle\n if (focusHistory.current.has(editorUUID)) {\n return\n }\n\n // Add this editor to the history to prevent future recursions in this cycle\n focusHistory.current.add(editorUUID)\n setFocusedEditor(editorContext)\n\n // Propagate focus event to parent and children, ensuring they do not refocus this editor\n if (parentContext?.uuid) {\n parentContext.focusEditor(editorContext)\n }\n childrenEditors.current.forEach((childEditor) => {\n childEditor.focusEditor(editorContext)\n })\n\n focusHistory.current.clear()\n },\n parentEditor: parentContext,\n registerChild: (childUUID, childEditorContext) => {\n if (!childrenEditors.current.has(childUUID)) {\n const newMap = new Map(childrenEditors.current)\n newMap.set(childUUID, childEditorContext)\n childrenEditors.current = newMap\n }\n },\n setCreatedInlineBlock,\n unregisterChild: (childUUID) => {\n if (childrenEditors.current.has(childUUID)) {\n const newMap = new Map(childrenEditors.current)\n newMap.delete(childUUID)\n childrenEditors.current = newMap\n }\n },\n\n uuid,\n }) as EditorConfigContextType,\n [\n createdInlineBlock,\n setCreatedInlineBlock,\n editor,\n childrenEditors,\n editorConfig,\n editorContainerRef,\n editDepth,\n fieldProps,\n focusedEditor,\n parentContext,\n uuid,\n ],\n )\n\n return <Context value={editorContext}>{children}</Context>\n}\n\nexport const useEditorConfigContext = (): EditorConfigContextType => {\n const context = use(Context)\n if (context === undefined) {\n throw new Error('useEditorConfigContext must be used within an EditorConfigProvider')\n }\n return context\n}\n"],
|
|
5
|
+
"mappings": "wCAKA,OAASA,6BAAAA,MAAiC,2CAC1C,OAASC,gBAAAA,MAAoB,iBAC7B,MAAuB,QACvB,OAASC,iBAAAA,EAAeC,OAAAA,EAAKC,WAAAA,EAASC,UAAAA,EAAQC,YAAAA,MAAgB,QAO9D,SAASC,GAAA,CACP,OAAOC,KAAKC,OAAM,EAAGC,SAAS,EAAA,EAAIC,UAAU,EAAG,EAAA,EAAMH,KAAKC,OAAM,EAAGC,SAAS,EAAA,EAAIC,UAAU,EAAG,EAAA,CAC/F,CAuBA,IAAMC,EAAkDV,EAAc,CACpEW,aAAc,KACdC,WAAY,KACZC,KAAM,IACR,CAAA,EAEaC,EAAuBA,CAAC,CACnCC,SAAAA,EACAJ,aAAAA,EACAK,mBAAAA,EACAJ,WAAAA,EACAK,cAAAA,CA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ACEY,EACAC,EACAR,EACAC,EACAR,EACAK,EACAW,EACAf,EACAS,EACAJ,EACAJ,CAAA,CACD,EAGH,OAAOiC,EAACpC,EAAA,CAAQqC,MAAOnB,WAAgBb,GACzC,EAEaiC,EAAyBA,IAAA,CACpC,IAAMC,EAAUhD,EAAIS,CAAA,EACpB,GAAIuC,IAAYC,OACd,MAAM,IAAIC,MAAM,oEAAA,EAElB,OAAOF,CACT",
|
|
6
|
+
"names": ["useLexicalComposerContext", "useEditDepth", "createContext", "use", "useMemo", "useRef", "useState", "generateQuickGuid", "Math", "random", "toString", "substring", "Context", "editorConfig", "fieldProps", "uuid", "EditorConfigProvider", "children", "editorContainerRef", "parentContext", "editor", "childrenEditors", "Map", "focusedEditor", "setFocusedEditor", "focusHistory", "Set", "createdInlineBlock", "setCreatedInlineBlock", "editDepth", "editorContext", "blurEditor", "current", "clear", "focusEditor", "editorUUID", "has", "add", "forEach", "childEditor", "parentEditor", "registerChild", "childUUID", "childEditorContext", "newMap", "set", "unregisterChild", "delete", "_jsx", "value", "useEditorConfigContext", "context", "undefined", "Error"]
|
|
7
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as E}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{b as E}from"./chunk-BZZVLW4U.js";import{c as q}from"react/compiler-runtime";import{jsx as x}from"react/jsx-runtime";import{Drawer as z,EditDepthProvider as G,useModal as J}from"@payloadcms/ui";import"react";import{jsx as y,jsxs as M}from"react/jsx-runtime";import{Form as v,FormSubmit as T,RenderFields as $,useDocumentForm as N,useDocumentInfo as W,useServerFunctions as k,useTranslation as B}from"@payloadcms/ui";import{abortAndIgnore as R}from"@payloadcms/ui/shared";import{deepCopyObjectSimpleWithoutReactComponents as I}from"payload/shared";import{useCallback as H,useEffect as j,useRef as L,useState as U}from"react";import{v4 as V}from"uuid";var O=({data:i,featureKey:e,fieldMapOverride:o,handleDrawerSubmit:n,schemaFieldsPathOverride:t,schemaPath:d,schemaPathSuffix:f})=>{let{t:p}=B(),{id:l,collectionSlug:c,getDocPreferences:u,globalSlug:a}=W(),{fields:s}=N(),m=L(new AbortController),[r,h]=U(!1),{fieldProps:{featureClientSchemaMap:w,permissions:A}}=E(),{getFormState:g}=k(),S=t??`${d}.lexical_internal_feature.${e}${f?`.${f}`:""}`,b=o??w[e]?.[S];j(()=>{let C=new AbortController;return(async()=>{let{state:_}=await g({id:l,collectionSlug:c,data:i??{},docPermissions:{fields:!0},docPreferences:await u(),documentFormState:I(s),globalSlug:a,initialBlockData:i,operation:"update",renderAllFields:!0,schemaPath:S,signal:C.signal});h(_)})(),()=>{R(C)}},[S,l,i,g,c,a,u,s]);let F=H(async({formState:C})=>{R(m.current);let P=new AbortController;m.current=P;let{state:_}=await g({id:l,collectionSlug:c,docPermissions:{fields:!0},docPreferences:await u(),documentFormState:I(s),formState:C,globalSlug:a,initialBlockFormState:C,operation:"update",schemaPath:S,signal:P.signal});return _||C},[g,l,c,u,s,a,S]);return j(()=>()=>{R(m.current)},[]),r===!1?null:M(v,{beforeSubmit:[F],disableValidationOnSubmit:!0,fields:Array.isArray(b)?b:[],initialState:r,onChange:[F],onSubmit:n,uuid:V(),children:[y($,{fields:Array.isArray(b)?b:[],forceRender:!0,parentIndexPath:"",parentPath:"",parentSchemaPath:S,permissions:A,readOnly:!1}),y(T,{children:p("fields:saveChanges")})]})};var ge=i=>{let e=q(15),{className:o,data:n,drawerSlug:t,drawerTitle:d,featureKey:f,fieldMapOverride:p,handleDrawerSubmit:l,schemaFieldsPathOverride:c,schemaPath:u,schemaPathSuffix:a}=i,{closeModal:s}=J(),m=d??"",r;e[0]!==s||e[1]!==t||e[2]!==l?(r=(w,A)=>{s(t),setTimeout(()=>{l(w,A)},1)},e[0]=s,e[1]=t,e[2]=l,e[3]=r):r=e[3];let h;return e[4]!==o||e[5]!==n||e[6]!==t||e[7]!==f||e[8]!==p||e[9]!==c||e[10]!==u||e[11]!==a||e[12]!==m||e[13]!==r?(h=x(G,{children:x(z,{className:o,slug:t,title:m,children:x(O,{data:n,featureKey:f,fieldMapOverride:p,handleDrawerSubmit:r,schemaFieldsPathOverride:c,schemaPath:u,schemaPathSuffix:a})})}),e[4]=o,e[5]=n,e[6]=t,e[7]=f,e[8]=p,e[9]=c,e[10]=u,e[11]=a,e[12]=m,e[13]=r,e[14]=h):h=e[14],h};import{c as K}from"react/compiler-runtime";import{jsx as Q}from"react/jsx-runtime";import{useAuth as X,useConfig as Y,useEntityVisibility as Z}from"@payloadcms/ui";import*as D from"react";var ee=(i,e)=>i.filter(({slug:o,admin:{enableRichTextRelationship:n},upload:t})=>e?.visibleEntities.collections.includes(o)?e?.uploads?n&&!!t:t?!1:n:!1),Ae=i=>{let e=K(20),o,n,t,d;e[0]!==i?({children:n,FallbackComponent:o,uploads:d,...t}=i,e[0]=i,e[1]=o,e[2]=n,e[3]=t,e[4]=d):(o=e[1],n=e[2],t=e[3],d=e[4]);let f=d===void 0?!1:d,{config:p}=Y(),{collections:l}=p,{user:c}=X(),{visibleEntities:u}=Z(),a;e[5]!==l||e[6]!==f||e[7]!==c||e[8]!==u?(a=()=>ee(l,{uploads:f,user:c,visibleEntities:u}).map(te),e[5]=l,e[6]=f,e[7]=c,e[8]=u,e[9]=a):a=e[9];let[s]=D.useState(a);if(!s.length){let r;return e[10]!==o||e[11]!==t?(r=o?Q(o,{...t}):null,e[10]=o,e[11]=t,e[12]=r):r=e[12],r}let m;if(e[13]!==n||e[14]!==s||e[15]!==t){let r;e[17]!==s||e[18]!==t?(r={...t,enabledCollectionSlugs:s},e[17]=s,e[18]=t,e[19]=r):r=e[19],m=D.cloneElement(n,r),e[13]=n,e[14]=s,e[15]=t,e[16]=m}else m=e[16];return m};function te(i){let{slug:e}=i;return e}import{createCommand as re}from"lexical";var xe=re("INSERT_UPLOAD_WITH_DRAWER_COMMAND");export{ge as a,Ae as b,xe as c};
|
|
2
|
+
//# sourceMappingURL=chunk-Y2GOLUGU.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{a as R,b as S,c as E}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=component-
|
|
1
|
+
"use client";import{a as R,b as S,c as E}from"./chunk-Y2GOLUGU.js";import{a as N}from"./chunk-INBEEENE.js";import{a as $}from"./chunk-F26IQ5RE.js";import{b as p}from"./chunk-BZZVLW4U.js";import{jsx as e,jsxs as i}from"react/jsx-runtime";import{useLexicalComposerContext as X}from"@lexical/react/LexicalComposerContext.js";import{getTranslation as y}from"@payloadcms/translations";import{Button as h,File as Y,formatDrawerSlug as Z,useConfig as ee,useEditDepth as te,usePayloadAPI as oe,useTranslation as ae}from"@payloadcms/ui";import{$getNodeByKey as P}from"lexical";import{useCallback as f,useId as le,useReducer as se,useRef as re,useState as ie}from"react";var t="lexical-upload",U={depth:0},ne=n=>{let{data:{fields:L,relationTo:g,value:l},nodeKey:s}=n;if(typeof l=="object")throw new Error("Upload value should be a string or number. The Lexical Upload component should not receive the populated value object.");let{config:{routes:{api:F},serverURL:T},getEntityConfig:j}=ee(),B=re(null),{uuid:I}=p(),k=te(),[o]=X(),{editorConfig:A,fieldProps:{readOnly:u,schemaPath:K}}=p(),{i18n:b,t:d}=ae(),[_,M]=se(r=>r+1,0),[a]=ie(()=>j({collectionSlug:g})),O=le(),w=Z({slug:"lexical-upload-drawer-"+I+O,depth:k}),{toggleDrawer:W}=N(w,!0),{closeDocumentDrawer:D,DocumentDrawer:z,DocumentDrawerToggler:H}=$({id:l,collectionSlug:a.slug}),[{data:c},{setParams:x}]=oe(`${T}${F}/${a.slug}/${l}`,{initialParams:U}),C=c?.thumbnailURL||c?.url,q=f(()=>{o.update(()=>{P(s)?.remove()})},[o,s]),G=f(r=>{x({...U,cacheBust:_}),M(),D()},[x,_,D]),v=A?.resolvedFeatureMap?.get("upload")?.sanitizedClientFeatureProps.collections?.[a.slug]?.hasExtraFields,J=f((r,Q)=>{o.update(()=>{let m=P(s);if(m){let V={...m.getData(),fields:Q};m.setData(V)}})},[o,s]);return i("div",{className:t,contentEditable:!1,ref:B,children:[i("div",{className:`${t}__card`,children:[i("div",{className:`${t}__topRow`,children:[e("div",{className:`${t}__thumbnail`,children:C?e("img",{alt:c?.filename,"data-lexical-upload-id":l,"data-lexical-upload-relation-to":g,src:C}):e(Y,{})}),i("div",{className:`${t}__topRowRightPanel`,children:[e("div",{className:`${t}__collectionLabel`,children:y(a.labels.singular,b)}),o.isEditable()&&i("div",{className:`${t}__actions`,children:[v?e(h,{buttonStyle:"icon-label",className:`${t}__upload-drawer-toggler`,disabled:u,el:"button",icon:"edit",onClick:()=>{W()},round:!0,tooltip:d("fields:editRelationship")}):null,e(h,{buttonStyle:"icon-label",className:`${t}__swap-drawer-toggler`,disabled:u,el:"button",icon:"swap",onClick:()=>{o.dispatchCommand(E,{replace:{nodeKey:s}})},round:!0,tooltip:d("fields:swapUpload")}),e(h,{buttonStyle:"icon-label",className:`${t}__removeButton`,disabled:u,icon:"x",onClick:r=>{r.preventDefault(),q()},round:!0,tooltip:d("fields:removeUpload")})]})]})]}),e("div",{className:`${t}__bottomRow`,children:e(H,{className:`${t}__doc-drawer-toggler`,children:e("strong",{children:c?.filename})})})]}),l?e(z,{onSave:G}):null,v?e(R,{data:L,drawerSlug:w,drawerTitle:d("general:editLabel",{label:y(a.labels.singular,b)}),featureKey:"upload",handleDrawerSubmit:J,schemaPath:K,schemaPathSuffix:a.slug}):null]})},Ce=n=>e(S,{...n,uploads:!0,children:e(ne,{...n})});export{Ce as UploadComponent};
|
|
2
|
+
//# sourceMappingURL=component-Y3OSWJM5.js.map
|