noteloom 0.6.0 → 0.7.0
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/canvas.cjs +1 -1
- package/dist/canvas.js +1 -1
- package/dist/comments.cjs +1 -1
- package/dist/comments.js +3 -3
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1529 -1488
- package/dist/index.js.map +1 -1
- package/dist/shared/{CommentThreadCard-DcCHq2Dy.cjs → CommentThreadCard-CIB6nZEA.cjs} +2 -2
- package/dist/shared/{CommentThreadCard-DcCHq2Dy.cjs.map → CommentThreadCard-CIB6nZEA.cjs.map} +1 -1
- package/dist/shared/{CommentThreadCard-DwtE85Xx.js → CommentThreadCard-lW_lbI74.js} +2 -2
- package/dist/shared/{CommentThreadCard-DwtE85Xx.js.map → CommentThreadCard-lW_lbI74.js.map} +1 -1
- package/dist/shared/{CommentsPanel-BRgACUu_.cjs → CommentsPanel-CRxb3RWi.cjs} +2 -2
- package/dist/shared/{CommentsPanel-BRgACUu_.cjs.map → CommentsPanel-CRxb3RWi.cjs.map} +1 -1
- package/dist/shared/{CommentsPanel-D4eP-K_f.js → CommentsPanel-Dg0k_XNU.js} +3 -3
- package/dist/shared/{CommentsPanel-D4eP-K_f.js.map → CommentsPanel-Dg0k_XNU.js.map} +1 -1
- package/dist/shared/{VersionHistory-BRBYQgj5.cjs → VersionHistory-BsSwOq_k.cjs} +2 -2
- package/dist/shared/{VersionHistory-BRBYQgj5.cjs.map → VersionHistory-BsSwOq_k.cjs.map} +1 -1
- package/dist/shared/{VersionHistory-D9sIIAYN.js → VersionHistory-BzMnJpbc.js} +3 -3
- package/dist/shared/{VersionHistory-D9sIIAYN.js.map → VersionHistory-BzMnJpbc.js.map} +1 -1
- package/dist/shared/{VoiceListeningIndicator-Dw0fggpE.cjs → VoiceListeningIndicator-B_7-6Mq4.cjs} +2 -2
- package/dist/shared/{VoiceListeningIndicator-Dw0fggpE.cjs.map → VoiceListeningIndicator-B_7-6Mq4.cjs.map} +1 -1
- package/dist/shared/{VoiceListeningIndicator-DgLMmGSP.js → VoiceListeningIndicator-DeA3hb33.js} +4 -4
- package/dist/shared/{VoiceListeningIndicator-DgLMmGSP.js.map → VoiceListeningIndicator-DeA3hb33.js.map} +1 -1
- package/dist/shared/{icons-Bdptdx1e.js → icons-CmfXmn13.js} +307 -259
- package/dist/shared/icons-CmfXmn13.js.map +1 -0
- package/dist/shared/{icons-DabR_JDW.cjs → icons-DQ7j_-ZK.cjs} +44 -3
- package/dist/shared/icons-DQ7j_-ZK.cjs.map +1 -0
- package/dist/shared/{index-DOIEccLM.js → index-DUigqWQn.js} +3 -3
- package/dist/shared/{index-DOIEccLM.js.map → index-DUigqWQn.js.map} +1 -1
- package/dist/shared/{index-B7_F6NA9.cjs → index-vWtS1iyt.cjs} +2 -2
- package/dist/shared/{index-B7_F6NA9.cjs.map → index-vWtS1iyt.cjs.map} +1 -1
- package/dist/shared/{leafBlockFactory-D3SCDvzc.cjs → leafBlockFactory-6GFBveaC.cjs} +2 -2
- package/dist/shared/{leafBlockFactory-D3SCDvzc.cjs.map → leafBlockFactory-6GFBveaC.cjs.map} +1 -1
- package/dist/shared/{leafBlockFactory-ChlzpKIn.js → leafBlockFactory-Dm6cd2NY.js} +5 -5
- package/dist/shared/{leafBlockFactory-ChlzpKIn.js.map → leafBlockFactory-Dm6cd2NY.js.map} +1 -1
- package/dist/shared/{serialize-C1rjLsIz.js → serialize-R4V4gmHs.js} +2 -2
- package/dist/shared/{serialize-C1rjLsIz.js.map → serialize-R4V4gmHs.js.map} +1 -1
- package/dist/shared/{serialize-k0zXqwEM.cjs → serialize-vLXz0cze.cjs} +2 -2
- package/dist/shared/{serialize-k0zXqwEM.cjs.map → serialize-vLXz0cze.cjs.map} +1 -1
- package/dist/shared/starter-kit-BQUaaql0.cjs +29 -0
- package/dist/shared/starter-kit-BQUaaql0.cjs.map +1 -0
- package/dist/shared/{starter-kit-CJzWMyF8.js → starter-kit-Bp30PiE4.js} +1246 -1188
- package/dist/shared/starter-kit-Bp30PiE4.js.map +1 -0
- package/dist/shared/{usePopoverEdgeClamp-gRlLQeVG.cjs → usePopoverEdgeClamp-BJLbbANB.cjs} +2 -2
- package/dist/shared/{usePopoverEdgeClamp-gRlLQeVG.cjs.map → usePopoverEdgeClamp-BJLbbANB.cjs.map} +1 -1
- package/dist/shared/{usePopoverEdgeClamp-B9KNv9SE.js → usePopoverEdgeClamp-DSpz-6xR.js} +2 -2
- package/dist/shared/{usePopoverEdgeClamp-B9KNv9SE.js.map → usePopoverEdgeClamp-DSpz-6xR.js.map} +1 -1
- package/dist/starter-kit.cjs +1 -1
- package/dist/starter-kit.js +2 -2
- package/dist/style.css +41 -0
- package/dist/versions.cjs +1 -1
- package/dist/versions.js +1 -1
- package/dist/voice.cjs +1 -1
- package/dist/voice.js +1 -1
- package/package.json +1 -1
- package/dist/shared/icons-Bdptdx1e.js.map +0 -1
- package/dist/shared/icons-DabR_JDW.cjs.map +0 -1
- package/dist/shared/starter-kit-CJzWMyF8.js.map +0 -1
- package/dist/shared/starter-kit-Ch2LEpzF.cjs +0 -27
- package/dist/shared/starter-kit-Ch2LEpzF.cjs.map +0 -1
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";var Vn=Object.defineProperty;var qn=(e,t,n)=>t in e?Vn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var mt=(e,t,n)=>qn(e,typeof t!="symbol"?t+"":t,n);const T=require("./index-B7_F6NA9.cjs"),a=require("react/jsx-runtime"),u=require("react"),Ie=require("react-dom"),i=require("./icons-DabR_JDW.cjs"),C=require("./leafBlockFactory-D3SCDvzc.cjs"),ae=require("./usePopoverEdgeClamp-gRlLQeVG.cjs"),Wn=require("./CommentThreadCard-DcCHq2Dy.cjs"),ht=require("./serialize-k0zXqwEM.cjs");function Nt(e){return e?e.type!=="text"?!1:(e.value??"")==="":!0}function ne(e,t){return!t||t.length===0?!0:t.every(n=>Nt(e.getRun(n)))}function Oe(e,t){var s,l;if(!t)return!1;const n=t.contentIds.length>0,o=(((l=(s=t.props)==null?void 0:s.titleRunIds)==null?void 0:l.length)??0)>0;return!n&&!o}function Et({isOpen:e,initialHref:t,initialTarget:n,hasExistingLink:o,onSave:s,onRemove:l,onClose:r}){const[c,d]=u.useState(""),[f,m]=u.useState("_self");u.useEffect(()=>{e&&(d(t),m(n))},[e]);const p=c.trim(),h=u.useCallback(k=>{k.preventDefault(),p&&s(p,f)},[p,f,s]);return a.jsx(ae.Modal,{isOpen:e,onClose:r,title:o?"Edit link":"Add link",children:a.jsxs("form",{onSubmit:h,children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"URL"}),a.jsx("input",{type:"text",value:c,onChange:k=>d(k.target.value),placeholder:"https://example.com",autoFocus:!0})]}),a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Open in"}),a.jsxs("select",{value:f,onChange:k=>m(k.target.value),children:[a.jsx("option",{value:"_self",children:"Same tab"}),a.jsx("option",{value:"_blank",children:"New tab"})]})]}),a.jsxs("div",{className:"be-modal-actions",children:[o&&a.jsx("button",{type:"button",className:"be-modal-delete",onClick:l,children:"Remove link"}),a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:r,children:"Cancel"}),a.jsx("button",{type:"submit",className:"be-modal-save",disabled:!p,children:"Save"})]})]})})}function De(e,t,n,o){const[s,l]=u.useState(null);return u.useLayoutEffect(()=>{if(n==null||o==null){l(null);return}l({top:n,left:o})},[n,o]),u.useLayoutEffect(()=>{if(!t||!e.current||!s)return;const r=e.current.getBoundingClientRect(),c=ae.clampLeftToViewport(s.left,r.width),d=ae.clampTopToViewport(s.top,r.height);(c!==s.left||d!==s.top)&&l({top:d,left:c})},[t,e,s]),s}function Qn({containerRef:e,store:t}){var g;const[n,o]=u.useState(null),[s,l]=u.useState(!1),r=u.useRef(null),c=u.useRef(null),d=u.useCallback(()=>{r.current&&(clearTimeout(r.current),r.current=null)},[]),f=u.useCallback(()=>{d(),r.current=setTimeout(()=>{o(y=>s?y:null)},250)},[d,s]);u.useEffect(()=>{const y=e.current;if(!y)return;const w=O=>{var H,B,A;const j=(B=(H=O.target).closest)==null?void 0:B.call(H,"[data-run-id]");if(!j||!y.contains(j))return;const S=j.dataset.runId,E=t.getRun(S);(A=E==null?void 0:E.marks)!=null&&A.link&&(d(),o(M=>(M==null?void 0:M.runId)===S?M:{runId:S,rect:j.getBoundingClientRect()}))},$=()=>f();return y.addEventListener("mouseover",w),y.addEventListener("mouseout",$),()=>{y.removeEventListener("mouseover",w),y.removeEventListener("mouseout",$)}},[e,t,d,f]),u.useEffect(()=>()=>d(),[d]);const m=u.useCallback(()=>l(!0),[]),p=u.useCallback(()=>{l(!1),o(null)},[]),h=u.useCallback((y,w)=>{if(!n)return;const $=t.getRun(n.runId);$&&(t.applyOperation(i.updateRun(n.runId,{marks:{...$.marks,link:{href:y,target:w}}})),p())},[n,t,p]),k=u.useCallback(()=>{if(!n)return;const y=t.getRun(n.runId);if(!y)return;const w={...y.marks};delete w.link,t.applyOperation(i.updateRun(n.runId,{marks:w})),p()},[n,t,p]),x=n&&t.getRun(n.runId),b=(g=x==null?void 0:x.marks)==null?void 0:g.link,I=!!(n&&b&&!s),v=De(c,I,n?n.rect.bottom+6:null,n?n.rect.left:null);return a.jsxs(a.Fragment,{children:[I&&v?Ie.createPortal(a.jsxs("div",{ref:c,className:"be-link-hover-card",contentEditable:!1,style:{position:"fixed",top:v.top,left:v.left},onMouseEnter:d,onMouseLeave:f,children:[a.jsx("a",{className:"be-link-hover-card-url",href:b.href,target:b.target==="_blank"?"_blank":"_self",rel:"noopener noreferrer",children:b.href}),a.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:m,"aria-label":"Edit link",title:"Edit link",children:a.jsx(i.PencilIcon,{size:13})}),a.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:k,"aria-label":"Remove link",title:"Remove link",children:a.jsx(i.XIcon,{size:13})})]}),document.body):null,a.jsx(Et,{isOpen:s,initialHref:(b==null?void 0:b.href)??"",initialTarget:(b==null?void 0:b.target)??"_self",hasExistingLink:!!b,onSave:h,onRemove:k,onClose:p})]})}function St({title:e,onClose:t}){return a.jsxs("div",{className:"be-comment-popover-header",children:[a.jsx("span",{className:"be-comment-popover-title",children:e}),a.jsx("button",{type:"button",className:"be-comment-popover-close",onClick:t,"aria-label":"Close",children:a.jsx(i.XIcon,{size:14})})]})}const Yn='button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';function Xn({containerRef:e,store:t,authorId:n}){const[o,s]=u.useState(null),[l,r]=u.useState(!1),c=u.useRef(null),d=u.useRef(null),f=u.useRef(null),[,m]=i.useHoveredComment(),p=u.useCallback(()=>{c.current&&(clearTimeout(c.current),c.current=null)},[]),h=u.useCallback(()=>{p(),c.current=setTimeout(()=>{s(g=>l?g:null)},250)},[p,l]);u.useEffect(()=>{const g=e.current;if(!g)return;const y=j=>{var H,B,A;const S=(H=j==null?void 0:j.closest)==null?void 0:H.call(j,"[data-run-id]");if(!S||!g.contains(S))return null;const E=(A=(B=t.getRun(S.dataset.runId))==null?void 0:B.marks)==null?void 0:A.commentIds;return E!=null&&E.length?{runEl:S,commentIds:E}:null},w=j=>{const S=y(j.target);S&&(p(),s(E=>E&&E.runEl===S.runEl?E:{rect:S.runEl.getBoundingClientRect(),commentIds:S.commentIds,runEl:S.runEl}))},$=()=>h(),O=j=>{const S=y(j.target);if(!S){r(!1),s(null);return}p(),r(!0),s({rect:S.runEl.getBoundingClientRect(),commentIds:S.commentIds,runEl:S.runEl})};return g.addEventListener("mouseover",w),g.addEventListener("mouseout",$),g.addEventListener("click",O),()=>{g.removeEventListener("mouseover",w),g.removeEventListener("mouseout",$),g.removeEventListener("click",O)}},[e,t,p,h]),u.useEffect(()=>{if(!o)return;const g=w=>{var $,O;($=d.current)!=null&&$.contains(w.target)||(O=e.current)!=null&&O.contains(w.target)||(r(!1),s(null))},y=w=>{w.key==="Escape"&&(r(!1),s(null))};return document.addEventListener("mousedown",g),document.addEventListener("keydown",y),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",y)}},[o,e]),u.useEffect(()=>()=>p(),[p]),u.useEffect(()=>{var g;m(((g=o==null?void 0:o.commentIds)==null?void 0:g[0])??null)},[o,m]);const k=u.useCallback(()=>{r(!1),s(null)},[]),x=!!o,b=De(d,x,o?o.rect.bottom+6:null,o?o.rect.left:null),I=u.useRef(!1);if(u.useEffect(()=>{var g,y;l&&d.current&&!I.current?(I.current=!0,f.current=document.activeElement,(d.current.querySelector(Yn)??d.current).focus()):!l&&I.current&&(I.current=!1,(y=(g=f.current)==null?void 0:g.focus)==null||y.call(g),f.current=null)},[l,b]),!x||!b)return null;const v=o.commentIds.map(g=>t.getComment(g)).filter(Boolean);return v.length===0?null:Ie.createPortal(a.jsxs("div",{ref:d,className:"be-comment-popover",contentEditable:!1,style:{position:"fixed",top:b.top,left:b.left},onMouseEnter:p,onMouseLeave:h,role:"dialog","aria-modal":l||void 0,"aria-label":`Comments (${v.length})`,tabIndex:-1,children:[a.jsx(St,{title:`Comments (${v.length})`,onClose:k}),v.map(g=>a.jsx(Wn.CommentThreadCard,{store:t,thread:g,authorId:n},g.id))]}),document.body)}function gt(e,t){const n=e==null?void 0:e.parentElement;if(!n||!n.hasAttribute("data-placeholder"))return;t.length===0||t.every(Nt)?n.setAttribute("data-empty",""):n.removeAttribute("data-empty")}function Jn(e={}){return{fontWeight:e.bold?"bold":void 0,fontStyle:e.italic?"italic":void 0,textDecoration:[(e.underline||e.link)&&"underline",e.strike&&"line-through"].filter(Boolean).join(" ")||void 0,verticalAlign:e.subscript?"sub":e.superscript?"super":void 0,fontSize:e.subscript||e.superscript?"smaller":void 0,color:e.color||(e.link?"var(--noteloom-accent)":void 0),backgroundColor:e.highlight||void 0,cursor:e.link?"pointer":void 0}}function Zn(e,t){const n=e.childNodes.length===1?e.firstChild:null;n&&n.nodeType===3?n.nodeValue!==t&&(n.nodeValue=t):e.textContent=t}function eo({id:e,host:t,onValueSynced:n}){const o=T.useRun(e),[s]=i.useHoveredComment();return u.useLayoutEffect(()=>{var m,p,h,k,x;if(!t||!o)return;const l=o.value??"";(C.stripEmptyRunPlaceholder(t.textContent)!==l||l===""&&t.textContent==="")&&Zn(t,l===""?C.EMPTY_RUN_PLACEHOLDER:l);const d=Jn(o.marks);t.style.fontWeight=d.fontWeight??"",t.style.fontStyle=d.fontStyle??"",t.style.textDecoration=d.textDecoration??"",t.style.verticalAlign=d.verticalAlign??"",t.style.fontSize=d.fontSize??"",t.style.color=d.color??"",t.style.backgroundColor=d.backgroundColor??"",t.style.cursor=d.cursor??"",t.classList.toggle("be-comment-highlight",(((p=(m=o.marks)==null?void 0:m.commentIds)==null?void 0:p.length)??0)>0),t.classList.toggle("be-comment-highlight-active",!!s&&!!((k=(h=o.marks)==null?void 0:h.commentIds)!=null&&k.includes(s)));const f=(x=o.marks)==null?void 0:x.link;t.title=f!=null&&f.href?`${f.href} — Ctrl+Click to open`:"",t.onclick=f!=null&&f.href?b=>{!b.ctrlKey&&!b.metaKey||(b.preventDefault(),window.open(f.href,f.target==="_blank"?"_blank":"_self","noopener,noreferrer"))}:null,n==null||n()},[t,o,n,s]),null}function bt(e,t,n,o){var p,h,k;const s=(p=window.getSelection)==null?void 0:p.call(window);if(!s||!s.isCollapsed||s.rangeCount===0)return null;const{anchorNode:l,anchorOffset:r}=s;if(!l||!e.contains(l))return null;const c=x=>{const b=t.indexOf(x);if(b===-1)return null;const I=o?t[b-1]:t[b+1];if(!I)return null;const v=n(I);return v&&v.type!=="text"?I:null};if(l===e){const x=o?r-1:r,b=e.childNodes[x],I=(b==null?void 0:b.nodeType)===1?(h=b.dataset)==null?void 0:h.runId:void 0;if(!I||t.indexOf(I)===-1)return null;const v=n(I);return v&&v.type!=="text"?I:null}const d=l.nodeType===1?l:l.parentElement,f=(k=d==null?void 0:d.closest)==null?void 0:k.call(d,"[data-run-id]");return!f||!e.contains(f)||!(o?r===0:r===(l.textContent??"").length)?null:c(f.getAttribute("data-run-id"))}function kt(e,t,n){var d,f;const o=(d=window.getSelection)==null?void 0:d.call(window);if(!o||o.isCollapsed||o.rangeCount===0)return null;const s=o.getRangeAt(0);if(s.startContainer!==s.endContainer||!e.contains(s.startContainer)||s.endOffset!==s.startOffset+1)return null;const l=s.startContainer.childNodes[s.startOffset],r=(l==null?void 0:l.nodeType)===1?(f=l.dataset)==null?void 0:f.runId:void 0;if(!r||t.indexOf(r)===-1)return null;const c=n(r);return c&&c.type!=="text"?r:null}function yt(e,t,n){var c;if(t===e)return{childIndex:n,charOffset:null};const o=t.nodeType===1?t:t.parentElement,s=(c=o==null?void 0:o.closest)==null?void 0:c.call(o,"[data-run-id]");if(!s||!e.contains(s))return null;const l=Array.prototype.indexOf.call(e.childNodes,s),r=t===s?n===0?0:(s.textContent??"").length:n;return{childIndex:l,charOffset:r}}function to(e,t,n,o){const s=yt(e,o.startContainer,o.startOffset),l=yt(e,o.endContainer,o.endOffset);if(!s||!l)return null;const r=Array.from(e.childNodes).filter(m=>{var p;return m.nodeType===1&&((p=m.dataset)==null?void 0:p.runId)&&t.indexOf(m.dataset.runId)!==-1});let c=!1;const d=[];let f=null;return r.forEach((m,p)=>{const h=m.dataset.runId,k=n(h);if(!k)return;const x=p<s.childIndex,b=l.charOffset===null?p>=l.childIndex:p>l.childIndex;if(x||b){d.push(k);return}const I=s.charOffset!==null&&p===s.childIndex,v=l.charOffset!==null&&p===l.childIndex;if(k.type!=="text"){c=!0,f===null&&(f=d.length);return}const g=k.value??"";if(I&&v){const y=g.slice(0,s.charOffset)+g.slice(l.charOffset);y&&d.push({...k,value:y}),f=d.length}else if(I){const y=g.slice(0,s.charOffset);y&&d.push({...k,value:y}),f===null&&(f=d.length)}else if(v){const y=g.slice(l.charOffset);y&&d.push({id:i.genId(),type:"text",value:y,marks:k.marks})}}),c?{nextRuns:d,insertionIndex:f??d.length}:null}function no(e){var l;const t=(l=window.getSelection)==null?void 0:l.call(window);if(!t||!t.isCollapsed)return!1;const n=e.firstChild;if(!n)return!0;if(t.anchorNode===e)return t.anchorOffset===0;let o=n;for(;o&&o.firstChild;)o=o.firstChild;if(t.anchorNode!==o&&t.anchorNode!==n)return!1;const s=o.nodeType===3&&o.textContent===C.EMPTY_RUN_PLACEHOLDER?1:0;return t.anchorOffset<=s}function oo(e){var l;const t=(l=window.getSelection)==null?void 0:l.call(window);if(!t||!t.isCollapsed)return!1;const n=e.lastChild;if(!n)return!0;if(t.anchorNode===e)return t.anchorOffset>=e.childNodes.length;let o=n;for(;o&&o.lastChild;)o=o.lastChild;if(t.anchorNode!==o&&t.anchorNode!==n)return!1;const s=o.nodeType===3?(o.textContent??"").length:0;return t.anchorOffset>=s}function It(e,t,n){const o=e.getBlock(t),s=e.getBlock(o==null?void 0:o.parentId);if(!s)return null;const l=s.contentIds.indexOf(t),r=n==="backward"?l-1:l+1;if(r<0||r>=s.contentIds.length)return null;const c=s.contentIds[r];return Oe(e,e.getBlock(c))?c:null}function so({id:e,blockId:t,host:n,inlineRegistry:o,onValueSynced:s}){const l=T.useRun(e);if(!l)return null;if(l.type==="text")return a.jsx(eo,{id:e,host:n,onValueSynced:s});const r=o==null?void 0:o.get(l.type);if(!r)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No inline type registered for "${l.type}" (run: ${e})`),null;const c=r.component;return a.jsx(c,{id:e,blockId:t})}function lo(e,t,n){let o=e.get(n);if(!o){o=document.createElement("span"),o.dataset.runId=n;const s=t.getRun(n);s&&s.type!=="text"&&o.setAttribute("contenteditable","false"),e.set(n,o)}return o}function ue({blockId:e,runIds:t,dir:n="auto",onEnter:o,onBackspaceAtStart:s,onDeleteAtEnd:l,onArrowUp:r,onArrowDown:c,onTab:d,onShiftTab:f,onAutoformat:m}){const p=i.useEditorStore(),h=i.useInlineRegistry(),k=i.useCommentAuthorId(),{getSelectedBlockId:x,setSelectedBlockId:b}=i.useSelectedBlock(),I=u.useRef(null),v=u.useRef(!1),g=u.useRef(new Map);u.useLayoutEffect(()=>{const B=I.current;if(!B)return;const A=new Set(t);for(const[P,N]of g.current)A.has(P)||(N.remove(),g.current.delete(P));let M=null;for(const P of t){const N=g.current.get(P);if(!N)continue;const D=M?M.nextSibling:B.firstChild;D!==N&&B.insertBefore(N,D),M=N}},[t]);const y=u.useCallback(()=>{if(v.current)return;const B=I.current;if(!B)return;const A=t.map(D=>p.getRun(D)).filter(Boolean),{runs:M,changed:P,onlyValueChanges:N}=C.reconcileDomToRuns(B,A);if(P){if(N){if(M.forEach((D,z)=>{D!==A[z]&&p.applyOperation(i.updateRun(D.id,{value:D.value}))}),m!=null&&m(M))return}else p.applyOperation(i.setBlockRuns(e,M.length?M:[{id:i.genId(),type:"text",value:"",marks:{}}]));gt(B,M)}},[p,e,t,m]),w=u.useCallback(()=>{gt(I.current,t.map(B=>p.getRun(B)).filter(Boolean))},[p,t]),$=u.useCallback(()=>{v.current=!0},[]),O=u.useCallback(()=>{v.current=!1,y()},[y]),j=u.useCallback(B=>{const M=t.map(P=>p.getRun(P)).filter(Boolean).filter(P=>P.id!==B);p.applyOperation(i.setBlockRuns(e,M.length?M:[{id:i.genId(),type:"text",value:"",marks:{}}]))},[p,e,t]),S=u.useCallback(B=>{x()===B?(p.applyOperation(i.removeBlock(B)),b(null)):b(B)},[p,x,b]),E=u.useCallback(B=>{var J,Y,xe,ge;if(v.current)return;if(B.target instanceof Node){const W=B.target.nodeType===1?B.target:B.target.parentElement;if((J=W==null?void 0:W.closest)!=null&&J.call(W,'[contenteditable="false"]'))return}const A=B.inputType??"",M=A.startsWith("delete"),P=A==="insertText"||A==="insertReplacementText";if(!M&&!P)return;const N=I.current;if(!N)return;const D=(Y=B.getTargetRanges)==null?void 0:Y.call(B),z=(xe=window.getSelection)==null?void 0:xe.call(window),G=(D==null?void 0:D[0])??(z!=null&&z.rangeCount?z.getRangeAt(0):null);if(!G||!N.contains(G.startContainer)||!N.contains(G.endContainer))return;const te=to(N,t,W=>p.getRun(W),G);if(!te)return;B.preventDefault();let{nextRuns:_,insertionIndex:V}=te,U=null,oe=!1;if(P&&B.data){const W={id:i.genId(),type:"text",value:B.data,marks:{}};_=[..._.slice(0,V),W,..._.slice(V)],U=W.id,oe=!1}else V>0?(U=(ge=_[V-1])==null?void 0:ge.id,oe=!1):_.length>0&&(U=_[0].id,oe=!0);const X=_.length?_:[{id:i.genId(),type:"text",value:"",marks:{}}];p.applyOperation(i.setBlockRuns(e,X));const le=U??X[0].id;oe?C.focusRunStart(le):C.focusRunEnd(le)},[p,e,t]);u.useEffect(()=>{const B=I.current;if(B)return B.addEventListener("beforeinput",E),()=>B.removeEventListener("beforeinput",E)},[E]);const H=u.useCallback(B=>{if(!v.current){if(B.key==="Enter"&&o){B.preventDefault(),o(B);return}if(B.key==="Backspace"){const A=I.current,M=A&&kt(A,t,p.getRun.bind(p));if(M){B.preventDefault(),j(M);return}const P=A&&bt(A,t,p.getRun.bind(p),!0);if(P){B.preventDefault(),j(P);return}if(A&&no(A)){if(!ne(p,t)){const D=It(p,e,"backward");if(D){B.preventDefault(),S(D);return}}B.preventDefault(),s&&s(B)}return}if(B.key==="Delete"){const A=I.current,M=A&&kt(A,t,p.getRun.bind(p));if(M){B.preventDefault(),j(M);return}const P=A&&bt(A,t,p.getRun.bind(p),!1);if(P){B.preventDefault(),j(P);return}if(A&&oo(A)){const N=It(p,e,"forward");if(N){B.preventDefault(),S(N);return}l&&l(B)}return}if(B.key==="ArrowUp"&&r){B.preventDefault(),r(B);return}if(B.key==="ArrowDown"&&c){B.preventDefault(),c(B);return}B.key==="Tab"&&(B.shiftKey&&f?(B.preventDefault(),f(B)):!B.shiftKey&&d&&(B.preventDefault(),d(B)))}},[o,s,l,r,c,d,f,j,S,t,e,p]);return a.jsxs(a.Fragment,{children:[a.jsx("span",{ref:I,className:"be-editable",dir:n,contentEditable:!0,suppressContentEditableWarning:!0,onInput:y,onCompositionStart:$,onCompositionEnd:O,onKeyDown:H,children:t.map(B=>{const A=lo(g.current,p,B);return Ie.createPortal(a.jsx(so,{id:B,blockId:e,host:A,inlineRegistry:h,onValueSynced:w},B),A)})}),a.jsx(Qn,{containerRef:I,store:p}),a.jsx(Xn,{containerRef:I,store:p,authorId:k})]})}function Ge(e){const t=e.getRootId(),n=e.getBlock(t);if(!n||n.contentIds.length>0)return null;const{block:o,runs:s}=C.createTextLeafBlock("paragraph")(t);return e.applyOperation(i.insertBlock(o,t,0,{blocks:[o],runs:s})),o.id}const ro=new Set(["callout"]),Ct=new Set(["paragraph","heading","blockquote"]);function Mt(e,t){return e===t||Ct.has(e)&&Ct.has(t)}function Pe(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),s=o.contentIds.indexOf(t),l=n.contentIds.length===0||n.contentIds.length===1&&ao(e,n.contentIds[0]);if(s<=0){if(!l)return null;if(o.contentIds.length>1)return Be(e,[i.removeBlock(t)]),e.getBlock(o.id).contentIds[0];if(ro.has(o.type))return co(e,o);if(n.type==="paragraph")return null;const{block:f,runs:m}=C.createTextLeafBlock("paragraph")(o.id);return Be(e,[i.insertBlock(f,o.id,s,{blocks:[f],runs:m}),i.removeBlock(t)]),f.id}const r=o.contentIds[s-1],c=e.getBlock(r);if(l)return Be(e,[i.removeBlock(t)]),r;if(Oe(e,c))return Be(e,[i.removeBlock(r)]),t;if(!c||!Mt(c.type,n.type))return null;const d=[...c.contentIds,...n.contentIds];return Be(e,[i.setBlockContentIds(r,d),i.setBlockContentIds(t,[]),i.removeBlock(t)]),r}function ao(e,t){const n=e.getRun(t);return!n||(n.value??"")===""}function co(e,t){const n=e.getBlock(t.parentId);if(!n)return null;const o=n.contentIds.indexOf(t.id),s=o>0?n.contentIds[o-1]:null,l=o!==-1&&o<n.contentIds.length-1?n.contentIds[o+1]:null;Be(e,[i.removeBlock(t.id)]);const r=Ge(e);return s??l??r}function Be(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Te(e,t,n,o){if(!t||t===n)return;const s=C.resolveBlockLastRun(e,t);if(s){C.focusRunEnd(s);return}o(t),requestAnimationFrame(()=>{var l;(l=document.querySelector(`[data-block-id="${t}"]`))==null||l.focus()})}function ce(e,t){var o,s;if(!t)return"auto";if((o=t.props)!=null&&o.dir)return t.props.dir;const n=e.getBlock(e.getRootId());return((s=n==null?void 0:n.props)==null?void 0:s.dir)??"auto"}function io(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}const uo=[{re:/^(#{1,3})[ ]$/,type:"heading",props:e=>({level:e[1].length})},{re:/^[-*][ ]$/,type:"listItem",props:()=>({ordered:!1,titleRunIds:[]})},{re:/^\d+\.[ ]$/,type:"listItem",props:()=>({ordered:!0,titleRunIds:[]})},{re:/^\[\][ ]$/,type:"listItem",props:()=>({ordered:!1,checked:!1,titleRunIds:[]})},{re:/^>[ ]$/,type:"blockquote",props:()=>({})},{re:/^```$/,type:"code",props:()=>({language:"plaintext"})}];function po(e,t,n){if(n.length!==1||n[0].type!=="text")return!1;const o=n[0].value??"";for(const s of uo){const l=s.re.exec(o);if(!l)continue;const r=o.slice(l[0].length),{ops:c}=ae.convertBlockType(e,t,s.type,s.props(l),[n[0].id]);return io(e,[i.updateRun(n[0].id,{value:r}),...c]),C.focusRunStart(n[0].id),!0}return!1}const fo=new Set(["callout","toggleHeading"]);function mo({id:e}){const t=i.useEditorStore(),n=T.useBlock(e),{setSelectedBlockId:o}=i.useSelectedBlock(),s=u.useCallback(()=>{const h=t.getBlock(n==null?void 0:n.parentId),k=ne(t,(n==null?void 0:n.contentIds)??[]),x=!!h&&h.contentIds[h.contentIds.length-1]===e;if(k&&x&&fo.has(h==null?void 0:h.type)){C.insertSiblingAfterAndFocus(t,h.id,C.createTextLeafBlock("paragraph"));return}C.insertSiblingSplitAtCaretAndFocus(t,e,(n==null?void 0:n.contentIds)??[],C.createTextLeafBlock("paragraph"))},[t,e,n]),l=u.useCallback(()=>{var I,v;const h=t.getBlock(n==null?void 0:n.parentId),k=ne(t,(n==null?void 0:n.contentIds)??[]),x=((I=h==null?void 0:h.contentIds)==null?void 0:I.length)===1&&h.contentIds[0]===e;if(k&&x&&(h==null?void 0:h.type)==="toggleHeading"){const g=((v=h.props)==null?void 0:v.titleRunIds)??[],y=g[g.length-1];y&&C.focusRunEnd(y);return}const b=Pe(t,e);Te(t,b,e,o)},[t,e,n,o]),r=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),c=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),d=u.useCallback(h=>po(t,e,h),[t,e]),f=i.useBlockClassName("be-paragraph",n);if(!n)return null;const m=ne(t,n.contentIds),p=ce(t,n);return a.jsx("div",{className:f,"data-block-id":e,"data-empty":m?"":void 0,"data-placeholder":"Type '/' for commands",dir:p,children:a.jsx(ue,{blockId:e,runIds:n.contentIds,dir:p,onEnter:s,onBackspaceAtStart:l,onArrowUp:r,onArrowDown:c,onAutoformat:d})})}const ho={STRONG:"bold",B:"bold",EM:"italic",I:"italic",U:"underline",S:"strike",STRIKE:"strike",DEL:"strike",CODE:"code",SUB:"subscript",SUP:"superscript"};function ie(e,t,n={}){const o=[],s=(l,r)=>{var f,m;if(l.nodeType===3){const p=l.textContent;p&&o.push({id:i.genId(),type:"text",value:p,marks:{...r}});return}if(l.nodeType!==1)return;if(t!=null&&t.inlineRegistry)for(const p of t.inlineRegistry.listHtmlMatchers()){const h=p.fromHTML(l,t);if(h){o.push(h);return}}let c=r;const d=ho[l.tagName];d&&(c={...c,[d]:!0}),l.tagName==="A"&&l.getAttribute("href")&&(c={...c,link:{href:l.getAttribute("href"),target:l.getAttribute("target")==="_blank"?"_blank":"_self"}}),(f=l.style)!=null&&f.color&&(c={...c,color:l.style.color}),(m=l.style)!=null&&m.backgroundColor&&(c={...c,highlight:l.style.backgroundColor});for(const p of l.childNodes)s(p,c)};return s(e,n),o.length?o:[{id:i.genId(),type:"text",value:"",marks:{}}]}function go(e,t){return`<p>${e.contentIds.map(o=>t.store.getRun(o)).map(o=>T.runToHTML(o,t)).join("")}</p>`}function bo(e,t){return e.contentIds.map(n=>T.runToPlainText(t.store.getRun(n),t)).join("")}function ko(e,t){return T.runsToMarkdown(e.contentIds.map(n=>t.store.getRun(n)),t)}function yo(e,t){if(e.tagName!=="P")return null;const n=ie(e,t);return{block:{id:i.genId(),type:"paragraph",parentId:null,contentIds:n.map(s=>s.id),props:{}},runs:n}}const $t=T.defineBlock({name:"paragraph",component:mo,contentModel:"runs",defaultProps:{},toHTML:go,toPlainText:bo,toMarkdown:ko,fromHTML:yo,slashCommand:{label:"Text",icon:i.TextIcon,keywords:["paragraph","text","p"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("paragraph"))}});function Io({id:e}){var k;const t=i.useEditorStore(),n=T.useBlock(e),{setSelectedBlockId:o}=i.useSelectedBlock(),s=u.useCallback(()=>{C.insertSiblingSplitAtCaretAndFocus(t,e,(n==null?void 0:n.contentIds)??[],C.createTextLeafBlock("paragraph"))},[t,e,n]),l=u.useCallback(()=>{const x=Pe(t,e);Te(t,x,e,o)},[t,e,o]),r=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),c=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),d=((k=n==null?void 0:n.props)==null?void 0:k.level)??3,f=i.useBlockClassName(`be-heading be-heading-${d}`,n);if(!n)return null;const m=`h${d}`,p=ne(t,n.contentIds),h=ce(t,n);return a.jsx(m,{className:f,"data-block-id":e,"data-empty":p?"":void 0,"data-placeholder":`Heading ${d}`,dir:h,children:a.jsx(ue,{blockId:e,runIds:n.contentIds,dir:h,onEnter:s,onBackspaceAtStart:l,onArrowUp:r,onArrowDown:c})})}const Xe={1:i.Heading1Icon,2:i.Heading2Icon,3:i.Heading3Icon},Co={H1:1,H2:2,H3:3};function xo(e,t){var s;const n=((s=e.props)==null?void 0:s.level)??3,o=e.contentIds.map(l=>t.store.getRun(l));return`<h${n}>${o.map(l=>T.runToHTML(l,t)).join("")}</h${n}>`}function vo(e,t){return e.contentIds.map(n=>T.runToPlainText(t.store.getRun(n),t)).join("")}function Bo(e,t){var s;const n=((s=e.props)==null?void 0:s.level)??3,o=T.runsToMarkdown(e.contentIds.map(l=>t.store.getRun(l)),t);return`${"#".repeat(n)} ${o}`}function To(e,t){const n=Co[e.tagName];if(!n)return null;const o=ie(e,t);return{block:{id:i.genId(),type:"heading",parentId:null,contentIds:o.map(l=>l.id),props:{level:n}},runs:o}}const Ot=T.defineBlock({name:"heading",contentModel:"runs",component:Io,defaultProps:{level:3},toHTML:xo,toPlainText:vo,toMarkdown:Bo,fromHTML:To,slashCommands:[{label:"Heading 1",icon:Xe[1],keywords:["heading","h1","title"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("heading",{level:1}))},{label:"Heading 2",icon:Xe[2],keywords:["heading","h2","subtitle"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("heading",{level:2}))},{label:"Heading 3",icon:Xe[3],keywords:["heading","h3","title"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("heading",{level:3}))}]}),wo=[];function it(e){const t=i.useEditorStore(),n=u.useCallback(s=>t.subscribe(e,s),[t,e]),o=u.useCallback(()=>{const s=t.getBlock(e);return s?s.contentIds:wo},[t,e]);return u.useSyncExternalStore(n,o)}class Dt extends u.Component{constructor(){super(...arguments);mt(this,"state",{hasError:!1,nonce:0})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n,o){var s,l;process.env.NODE_ENV!=="production"&&console.error("[block-editor] a block failed to render; recovering by remounting it:",n,o),(l=(s=this.props).onError)==null||l.call(s,n,o),queueMicrotask(()=>this.setState(r=>({hasError:!1,nonce:r.nonce+1})))}render(){return this.state.hasError?null:a.jsx(u.Fragment,{children:this.props.children},this.state.nonce)}}const ut=u.memo(function({id:t}){const n=T.useBlock(t),o=i.useBlockRegistry();if(!n)return null;const s=o.get(n.type);if(!s)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No block type registered for "${n.type}" (id: ${t})`),null;const l=s.component;return a.jsx(Dt,{children:a.jsx(l,{id:t})})});function Ve(e,t,n,o){const s=u.useRef(!1),l=u.useRef(!1);u.useEffect(()=>{var m,p;if(!t){l.current=!1,s.current&&(s.current=!1,(p=(m=o==null?void 0:o.current)==null?void 0:m.focus)==null||p.call(m));return}s.current=!0;const r=e.current;if(!r)return;const c=()=>Array.from(r.querySelectorAll('[role="menuitem"]')),d=h=>{var b;const k=c();if(k.length===0)return;const x=(h%k.length+k.length)%k.length;(b=k[x])==null||b.focus()};l.current||(l.current=!0,d(0));const f=h=>{if(h.key==="Escape"){h.preventDefault(),n();return}const k=c(),x=k.indexOf(document.activeElement);x!==-1&&(h.key==="ArrowDown"?(h.preventDefault(),d(x+1)):h.key==="ArrowUp"?(h.preventDefault(),d(x-1)):h.key==="Home"?(h.preventDefault(),d(0)):h.key==="End"&&(h.preventDefault(),d(k.length-1)))};return r.addEventListener("keydown",f),()=>r.removeEventListener("keydown",f)})}const xt="be-live-region";function Ro(){if(typeof document>"u")return null;let e=document.getElementById(xt);return e||(e=document.createElement("div"),e.id=xt,e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.setAttribute("aria-atomic","true"),Object.assign(e.style,{position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:"0",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:"0"}),document.body.appendChild(e),e)}function me(e){const t=Ro();t&&(t.textContent="",setTimeout(()=>{t.textContent=e},0))}const Ce="💡",Pt="gray";function Ao({icon:e=Ce,color:t=Pt}={}){return function(o){const s=i.genId(),{block:l,runs:r}=C.createTextLeafBlock("paragraph")(s);return{block:{id:s,type:"callout",parentId:o,contentIds:[l.id],props:{icon:e,color:t}},runs:r,subtreeBlocks:[l]}}}const Ht=[{type:"paragraph",props:{},label:"Text",icon:i.TextIcon},{type:"heading",props:{level:1},label:"Heading 1",icon:i.Heading1Icon},{type:"heading",props:{level:2},label:"Heading 2",icon:i.Heading2Icon},{type:"heading",props:{level:3},label:"Heading 3",icon:i.Heading3Icon},{type:"listItem",props:{ordered:!1,titleRunIds:[]},label:"Bulleted list",icon:i.BulletedListIcon},{type:"listItem",props:{ordered:!0,titleRunIds:[]},label:"Numbered list",icon:i.NumberedListIcon},{type:"listItem",props:{ordered:!1,checked:!1,titleRunIds:[]},label:"To-do list",icon:i.CheckboxIcon},{type:"listItem",props:{ordered:!1,collapsed:!1,titleRunIds:[]},label:"Toggle list",icon:i.ChevronRightIcon},{type:"toggleHeading",props:{level:2,collapsed:!1,titleRunIds:[]},label:"Toggle heading",icon:i.ChevronRightIcon},{type:"blockquote",props:{},label:"Quote",icon:i.QuoteIcon},{type:"callout",props:{icon:Ce},label:"Callout",icon:i.CalloutIcon},{type:"code",props:{language:"plaintext"},label:"Code",icon:i.CodeIcon}],jo=new Set(Ht.map(e=>e.type));function _t(e){return jo.has(e)}function Lo(e,t){return e!=null&&e.props&&"titleRunIds"in e.props?e.props.titleRunIds:t&&!t.isLeaf(e==null?void 0:e.type)?[]:(e==null?void 0:e.contentIds)??[]}function Ft(e,t,n,o){const s=e.getBlock(n),l=Lo(s,t),r=[];if(o.type==="code")for(const m of l){const p=e.getRun(m);p!=null&&p.marks&&Object.keys(p.marks).length>0&&r.push(i.updateRun(m,{marks:{}}))}const c={...o.props},{ops:d,newBlockId:f}=ae.convertBlockType(e,n,o.type,c,l,t);return{ops:[...r,...d],newBlockId:f}}function Ut({onSelect:e,onClose:t,containerRef:n,menuClassName:o="be-block-gutter-menu",itemClassName:s="be-block-gutter-menu-item"}){const[l,r]=u.useState(!1),[c,d]=u.useState(null),f=u.useRef(null),m=u.useRef(null),p=u.useCallback(g=>{m.current=g,n&&(n.current=g)},[n]),h=u.useCallback(()=>{r(!1),t==null||t()},[t]);T.useOutsideClickAndEscape([f,m],l,h),Ve(m,l,h,f);const k=De(m,l,c==null?void 0:c.top,c?c.right+4:null),x=u.useCallback(()=>{var g;d(((g=f.current)==null?void 0:g.getBoundingClientRect())??null),r(!0)},[]),b=u.useCallback(g=>{e(g),h()},[e,h]),I=u.useCallback(g=>{g.key==="ArrowRight"&&!l&&(g.preventDefault(),x())},[l,x]),v=u.useCallback(g=>{g.key==="ArrowLeft"&&(g.preventDefault(),h())},[h]);return a.jsxs(a.Fragment,{children:[a.jsxs("button",{ref:f,type:"button",role:"menuitem",className:s,"aria-haspopup":"menu","aria-expanded":l,onClick:()=>l?h():x(),onKeyDown:I,children:[a.jsx(i.ChevronRightIcon,{size:15})," Turn into"]}),l&&k&&Ie.createPortal(a.jsx("div",{ref:p,role:"menu","aria-label":"Turn into",className:o,style:{position:"fixed",top:k.top,left:k.left},onKeyDown:v,children:Ht.map((g,y)=>{const w=g.icon;return a.jsxs("button",{type:"button",role:"menuitem",className:s,onClick:()=>b(g),children:[a.jsx(w,{size:15})," ",g.label]},`${g.type}-${y}`)})}),document.body)]})}function Kt(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),s=o.contentIds.indexOf(t),l=ht.captureSubtree(e,t),{block:r,runs:c,subtreeBlocks:d}=ht.remapSubtreeIds(l);return e.applyOperation(i.insertBlock(r,o.id,s+1,{blocks:[r,...d],runs:c})),C.focusBlockStart(e,r.id),r.id}function zt(e,t){const n=e.getBlock(t),o=n&&e.getBlock(n.parentId);if(!o)return!1;const s=o.contentIds.indexOf(t);return s<=0?!1:(e.applyOperation(i.moveBlock(t,o.id,s-1)),!0)}function Gt(e,t){const n=e.getBlock(t),o=n&&e.getBlock(n.parentId);if(!o)return!1;const s=o.contentIds.indexOf(t);return s===-1||s>=o.contentIds.length-1?!1:(e.applyOperation(i.moveBlock(t,o.id,s+1)),!0)}function dt(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),s=o.contentIds.indexOf(t),l=s>0?o.contentIds[s-1]:null,r=s!==-1&&s<o.contentIds.length-1?o.contentIds[s+1]:null;e.applyOperation(i.removeBlock(t));const c=Ge(e),d=l??r??c;return d&&C.focusBlockStart(e,d),d??null}function No(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Vt({id:e}){var B;const t=i.useEditorStore(),n=i.useBlockRegistry(),o=T.useBlock(e),[s,l]=u.useState(!1),[r,c]=u.useState(null),d=u.useRef(null),f=u.useRef(null),m=u.useRef(null),p=u.useMemo(()=>[d,f,m],[]),[h]=i.useBlockRangeSelection(),k=h.includes(e),x=u.useCallback(()=>l(!1),[]);T.useOutsideClickAndEscape(p,s,x),Ve(f,s,x,d);const b=u.useCallback(()=>{var A;c(((A=d.current)==null?void 0:A.getBoundingClientRect())??null),l(!0)},[]),I=De(f,s,(r==null?void 0:r.bottom)!=null?r.bottom+4:null,r==null?void 0:r.left),v=u.useCallback(()=>{C.insertSiblingAfterAndFocus(t,e,C.createTextLeafBlock("paragraph"))},[t,e]),g=u.useCallback(()=>{Kt(t,e),me("Block duplicated"),x()},[t,e,x]),y=u.useCallback(()=>{zt(t,e)&&me("Block moved up"),x()},[t,e,x]),w=u.useCallback(()=>{Gt(t,e)&&me("Block moved down"),x()},[t,e,x]),$=u.useCallback(()=>{dt(t,e),me("Block deleted"),x()},[t,e,x]),O=!!((B=o==null?void 0:o.props)!=null&&B.hidden),j=u.useCallback(()=>{t.applyOperation(i.updateBlockProps(e,{hidden:!O})),me(O?"Block shown in preview":"Block hidden in preview"),x()},[t,e,O,x]),S=ce(t,o)==="rtl",E=u.useCallback(()=>{t.applyOperation(i.updateBlockProps(e,{dir:S?"ltr":"rtl"})),me(S?"Block set to left-to-right":"Block set to right-to-left"),x()},[t,e,S,x]),H=u.useCallback(A=>{const{ops:M}=Ft(t,n,e,A);No(t,M),me(`Turned into ${A.label}`),x()},[t,n,e,x]);return o?a.jsxs("div",{className:`be-block-row${O?" be-block-row-hidden":""}${k?" be-block-row-range-selected":""}`,"data-block-row-id":e,dir:ce(t,o),children:[a.jsxs("div",{className:`be-block-gutter${s?" be-block-gutter-active":""}`,contentEditable:!1,children:[a.jsx("button",{type:"button",className:"be-block-gutter-btn",onClick:v,"aria-label":"Add block below",children:a.jsx(i.PlusIcon,{size:16})}),a.jsx("button",{ref:d,type:"button",className:"be-block-gutter-btn","aria-label":"More options","aria-haspopup":"menu","aria-expanded":s,onClick:()=>s?x():b(),children:a.jsx(i.GripVerticalIcon,{size:16})})]}),a.jsx("div",{className:"be-block-row-content",children:a.jsx(ut,{id:e})}),s&&I&&Ie.createPortal(a.jsxs("div",{ref:f,role:"menu","aria-label":"Block options",className:"be-block-gutter-menu",style:{position:"fixed",top:I.top,left:I.left},children:[a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:g,children:[a.jsx(i.CopyIcon,{size:15})," Duplicate"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:y,children:[a.jsx(i.ArrowUpIcon,{size:15})," Move up"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:w,children:[a.jsx(i.ArrowDownIcon,{size:15})," Move down"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:j,children:[O?a.jsx(i.EyeIcon,{size:15}):a.jsx(i.EyeOffIcon,{size:15}),O?"Show in preview":"Hide in preview"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:E,children:[S?a.jsx(i.AlignLeftIcon,{size:15}):a.jsx(i.AlignRightIcon,{size:15}),S?"Switch to left-to-right":"Switch to right-to-left"]}),_t(o.type)&&a.jsx(Ut,{onSelect:H,onClose:()=>{},containerRef:m}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item be-block-gutter-menu-item-danger",onClick:$,children:[a.jsx(i.TrashIcon,{size:15})," Delete"]})]}),document.body)]}):null}function he({parentId:e,isTopLevel:t=!1,filterIds:n}){const o=it(e),s=i.useEditorStore(),[l]=i.usePreviewMode(),r=n??o,c=l?r.filter(d=>{var f,m;return!((m=(f=s.getBlock(d))==null?void 0:f.props)!=null&&m.hidden)}):r;return t&&!l?c.map(d=>a.jsx(Vt,{id:d},d)):c.map(d=>a.jsx(ut,{id:d},d))}const Eo=97,So=[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]];function Mo(e){let t="";for(;e>0;)e-=1,t=String.fromCharCode(Eo+e%26)+t,e=Math.floor(e/26);return t}function $o(e){let t="",n=e;for(const[o,s]of So)for(;n>=o;)t+=s,n-=o;return t}function Oo(e){var t,n;return(e==null?void 0:e.type)==="listItem"&&((t=e.props)==null?void 0:t.checked)===void 0&&((n=e.props)==null?void 0:n.collapsed)===void 0}function vt(e,t){let n=0,o=t;for(;o;){const s=e.getBlock(o.parentId);if(!s||s.type!=="listItem")break;n+=1,o=s}return n}function Do(e,t,n){const o=n.indexOf(t.id);let s=1;for(let l=o-1;l>=0;l-=1){const r=e.getBlock(n[l]);if(!Oo(r)||!r.props.ordered)break;s+=1}return s}function Po(e,t){const n=(e%3+3)%3;return n===0?`${t}.`:n===1?`${Mo(t)}.`:`${$o(t)}.`}const Ho=["•","◦","▪"];function _o(e){const t=(e%3+3)%3;return Ho[t]}function Se({ordered:e=!1,checked:t,collapsed:n}={}){return function(s,l){const r=i.genId(),c=l!=null&&l.length?l:[{id:i.genId(),type:"text",value:"",marks:{}}],d={ordered:e,titleRunIds:c.map(h=>h.id)};t!==void 0&&(d.checked=t);let f=[],m=[],p=c;if(n!==void 0){d.collapsed=n;const{block:h,runs:k}=C.createTextLeafBlock("paragraph")(r);f=[h.id],m=[h],p=[...c,...k]}return{block:{id:r,type:"listItem",parentId:s,contentIds:f,props:d},runs:p,subtreeBlocks:m}}}function Fo(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId),s=o.contentIds.indexOf(t),l=s>0?o.contentIds[s-1]:null,r=l?e.getBlock(l):null;if(!r||r.type!=="listItem"){C.focusAdjacentBlock(e,t,"down");return}e.applyOperation(i.moveBlock(t,l,r.contentIds.length)),C.focusBlockStart(e,t)}function nt(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId);if(!o||o.type!=="listItem")return;const s=o.parentId,r=e.getBlock(s).contentIds.indexOf(o.id);e.applyOperation(i.moveBlock(t,s,r+1)),C.focusBlockStart(e,t)}function Le(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function qt(e,t){var n;return t.length===0||t.length===1&&(((n=e.getRun(t[0]))==null?void 0:n.value)??"")===""}function Uo(e,t){const n=t.contentIds??[];if(n.length===0)return!0;if(n.length>1)return!1;const o=e.getBlock(n[0]);return!!o&&o.type==="paragraph"&&ne(e,o.contentIds)}function Ko(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),s=o.contentIds.indexOf(t),l=n.props.titleRunIds??[],c=qt(e,l)&&Uo(e,n);if(s>0){const m=o.contentIds[s-1],p=e.getBlock(m);if(c)return Le(e,[i.removeBlock(t)]),{focusBlockId:m,needsRefocus:!0};if(Oe(e,p))return Le(e,[i.removeBlock(m)]),{focusBlockId:t,needsRefocus:!1};if((p==null?void 0:p.type)==="listItem"&&n.contentIds.length===0){const h=[...p.props.titleRunIds??[],...l];return Le(e,[i.updateBlockProps(m,{titleRunIds:h}),i.updateBlockProps(t,{titleRunIds:[]}),i.removeBlock(t)]),{focusBlockId:m,needsRefocus:!0}}return null}if(o.type==="listItem")return nt(e,t),{focusBlockId:t,needsRefocus:!0};if(!c)return null;if(o.contentIds.length>1)return Le(e,[i.removeBlock(t)]),{focusBlockId:e.getBlock(o.id).contentIds[0],needsRefocus:!0};const{block:d,runs:f}=C.createTextLeafBlock("paragraph")(o.id);return Le(e,[i.insertBlock(d,o.id,s,{blocks:[d],runs:f}),i.removeBlock(t)]),{focusBlockId:d.id,needsRefocus:!0}}function zo(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Go(e,t){const o=e.getBlock(t).parentId,l=e.getBlock(o).contentIds.indexOf(t),{block:r,runs:c}=C.createTextLeafBlock("paragraph")(o);return zo(e,[i.insertBlock(r,o,l,{blocks:[r],runs:c}),i.updateBlockProps(t,{titleRunIds:[]}),i.removeBlock(t)]),C.focusBlockStart(e,r.id),r.id}function Vo(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function qo({id:e}){var j,S;const t=i.useEditorStore(),n=T.useBlock(e),{setSelectedBlockId:o}=i.useSelectedBlock(),s=it(n==null?void 0:n.parentId),l=u.useCallback(()=>{var D,z,G,te,_;const E=((D=n==null?void 0:n.props)==null?void 0:D.titleRunIds)??[],H=t.getBlock(n==null?void 0:n.parentId),B=qt(t,E);if(B&&(H==null?void 0:H.type)==="listItem"){nt(t,e);return}const A=(((z=n==null?void 0:n.contentIds)==null?void 0:z.length)??0)>0;if(B&&(H==null?void 0:H.type)!=="listItem"&&!A){Go(t,e);return}const M=((G=n==null?void 0:n.props)==null?void 0:G.checked)!==void 0,P=((te=n==null?void 0:n.props)==null?void 0:te.collapsed)!==void 0,N=Se({ordered:(_=n==null?void 0:n.props)==null?void 0:_.ordered,checked:M?!1:void 0,collapsed:P?!1:void 0});A&&!P?C.insertFirstChildSplitAtCaretAndFocus(t,e,E,N):C.insertSiblingSplitAtCaretAndFocus(t,e,E,N)},[t,e,n]),r=u.useCallback(()=>Fo(t,e),[t,e]),c=u.useCallback(()=>nt(t,e),[t,e]),d=u.useCallback(()=>{const E=Ko(t,e);!E||!E.needsRefocus||Te(t,E.focusBlockId,e,o)},[t,e,o]),f=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),m=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),p=u.useCallback(()=>{var E;t.applyOperation(i.updateBlockProps(e,{checked:!((E=n==null?void 0:n.props)!=null&&E.checked)}))},[t,e,(j=n==null?void 0:n.props)==null?void 0:j.checked]),h=u.useCallback(()=>{var H,B;if(!((((H=n==null?void 0:n.contentIds)==null?void 0:H.length)??0)>0)){const{block:A,runs:M}=C.createTextLeafBlock("paragraph")(e);Vo(t,[i.insertBlock(A,e,0,{blocks:[A],runs:M}),i.updateBlockProps(e,{collapsed:!1})]),C.focusRunEnd(A.contentIds[0]);return}t.applyOperation(i.updateBlockProps(e,{collapsed:!((B=n==null?void 0:n.props)!=null&&B.collapsed)}))},[t,e,n==null?void 0:n.contentIds,(S=n==null?void 0:n.props)==null?void 0:S.collapsed]),k=i.useBlockClassName("be-list-item",n);if(!n)return null;const{ordered:x,checked:b,collapsed:I,titleRunIds:v=[]}=n.props,g=b!==void 0,y=!g&&I!==void 0,w=n.contentIds.length>0,$=v.map(E=>t.getRun(E)).filter(E=>(E==null?void 0:E.type)==="text").map(E=>E.value).join("").trim(),O=ce(t,n);return a.jsxs("div",{className:k,"data-block-id":e,dir:O,children:[a.jsxs("div",{className:"be-list-item-row",children:[g?a.jsx("input",{type:"checkbox",className:"be-list-checkbox",checked:!!b,onChange:p,"aria-label":$||"To-do item"}):y?a.jsx("button",{type:"button",className:"be-list-toggle-marker",onClick:h,"aria-expanded":!I,"aria-label":w?I?"Expand toggle":"Collapse toggle":"Add content to toggle",children:I?a.jsx(i.ChevronRightIcon,{}):a.jsx(i.ChevronDownIcon,{})}):a.jsx("span",{className:"be-list-marker","aria-hidden":"true",children:x?Po(vt(t,n),Do(t,n,s)):_o(vt(t,n))}),a.jsx("div",{className:"be-list-item-title","data-empty":ne(t,v)?"":void 0,"data-placeholder":g?"To-do":y?"Toggle":"List item",style:b?{textDecoration:"line-through",opacity:.6}:void 0,children:a.jsx(ue,{blockId:e,runIds:v,dir:O,onEnter:l,onTab:r,onShiftTab:c,onBackspaceAtStart:d,onArrowUp:f,onArrowDown:m})})]}),(!y||!I)&&a.jsx("div",{className:"be-list-item-children",children:a.jsx(he,{parentId:e})})]})}function Wo(e,t){const{titleRunIds:n=[],ordered:o}=e.props,s=n.map(c=>T.runToHTML(t.store.getRun(c),t)).join(""),l=e.contentIds.map(c=>t.registry.get(t.store.getBlock(c).type).toHTML(t.store.getBlock(c),t)).join(""),r=l?`<${o?"ol":"ul"}>${l}</${o?"ol":"ul"}>`:"";return`<li>${s}${r}</li>`}function Qo(e,t){const{titleRunIds:n=[]}=e.props;return n.map(o=>T.runToPlainText(t.store.getRun(o),t)).join("")}function Yo(e,t){const{titleRunIds:n=[],ordered:o,checked:s}=e.props,l=s!==void 0?s?"- [x] ":"- [ ] ":o?"1. ":"- ",r=T.runsToMarkdown(n.map(d=>t.store.getRun(d)),t),c=e.contentIds.map(d=>{const f=t.store.getBlock(d),m=t.registry.get(f.type);return(m.toMarkdown??m.toPlainText)(f,t).split(`
|
|
2
|
-
`).map(h=>h&&` ${h}`).join(`
|
|
3
|
-
`)}).join(`
|
|
4
|
-
`);return c?`${l}${r}
|
|
5
|
-
${c}`:`${l}${r}`}function Wt(e,t){const n=[],o=[];for(const p of e.childNodes)p.nodeType===1&&(p.tagName==="UL"||p.tagName==="OL")?o.push(p):n.push(p);const s=e.ownerDocument.createElement("span");for(const p of n)s.appendChild(p.cloneNode(!0));const l=ie(s,t),r=i.genId(),c=[...l],d=[],f=[];for(const p of o){const h=p.tagName==="OL";for(const k of p.children){if(k.tagName!=="LI")continue;const x=Wt(k,t);x.block.parentId=r,x.block.props.ordered=h,d.push(x.block,...x.childBlocks),c.push(...x.runs),f.push(x.block.id)}}return{block:{id:r,type:"listItem",parentId:null,contentIds:f,props:{ordered:!1,titleRunIds:l.map(p=>p.id)}},runs:c,childBlocks:d}}function Xo(e,t){if(e.tagName!=="LI")return null;const{block:n,runs:o,childBlocks:s}=Wt(e,t);return{block:n,runs:o,subtreeBlocks:s}}const Qt=T.defineBlock({name:"listItem",contentModel:"blocks",component:qo,defaultProps:{ordered:!1,titleRunIds:[]},toHTML:Wo,toPlainText:Qo,toMarkdown:Yo,fromHTML:Xo,slashCommands:[{label:"Bulleted list",icon:i.BulletedListIcon,keywords:["list","bullet","ul"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Se({ordered:!1}))},{label:"Numbered list",icon:i.NumberedListIcon,keywords:["list","number","ordered","ol"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Se({ordered:!0}))},{label:"To-do list",icon:i.CheckboxIcon,keywords:["todo","checkbox","task","checklist"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Se({ordered:!1,checked:!1}))},{label:"Toggle list",icon:i.ChevronRightIcon,keywords:["toggle","collapse","expand","dropdown","accordion"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Se({ordered:!1,collapsed:!1}))}]}),Yt=["text","date","checkbox","select"],He="text",qe=160,be=80;function Jo(e){return`Column ${e+1}`}function pt(e){return Array.from({length:e},(t,n)=>({id:i.genId(),label:Jo(n),type:He,width:qe}))}function ee(e,t){var o;const n=(o=e.props)==null?void 0:o.columns;return!Array.isArray(n)||n.length!==t?pt(t):n.map(s=>{const l=s.type??He,r=s.width??qe;return l===s.type&&r===s.width?s:{...s,type:l,width:r}})}function Xt(e){switch(e){case"date":return{id:i.genId(),type:"date",value:"",marks:{},data:{isoDate:""}};case"checkbox":return{id:i.genId(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}};case"select":return{id:i.genId(),type:"tableSelect",value:"",marks:{},data:{selectedValue:"",selectedLabel:""}};default:return{id:i.genId(),type:"text",value:"",marks:{}}}}function We(e,t){const n=Xt(t==null?void 0:t.type);return{block:{id:i.genId(),type:"tableCell",parentId:e,contentIds:[n.id],props:{}},run:n}}function Jt(e,t,n){if(e.type===t)return e;let o;if(e.type==="text")o=e.value??"";else{const s=n==null?void 0:n.get(e.type);o=s!=null&&s.toPlainText?s.toPlainText(e):""}if(t==="date"){const s=o?new Date(o):null,l=s&&!Number.isNaN(s.getTime())?s.toISOString().slice(0,10):"";return{id:i.genId(),type:"date",value:"",marks:{},data:{isoDate:l}}}return t==="checkbox"?{id:i.genId(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:o}}:{id:i.genId(),type:"text",value:o,marks:{}}}function $e(e,t){if(!e)return"";if(e.type==="text")return e.value??"";const n=t==null?void 0:t.get(e.type);return n!=null&&n.toPlainText?n.toPlainText(e):""}function Zo(e,t,n){var o,s,l;return t==="date"?((o=e==null?void 0:e.data)==null?void 0:o.isoDate)??"":t==="checkbox"?(s=e==null?void 0:e.data)!=null&&s.checked?1:0:t==="select"?(((l=e==null?void 0:e.data)==null?void 0:l.selectedLabel)??"").trim():$e(e,n).trim()}function es(e,t,n){if(n==="checkbox")return e-t;const o=Number(e),s=Number(t);return e!==""&&t!==""&&!Number.isNaN(o)&&!Number.isNaN(s)?o-s:String(e).localeCompare(String(t),void 0,{sensitivity:"base"})}function ts(e,t,n,o){const s=e.map(({rowId:r,run:c})=>({rowId:r,key:Zo(c,t,o)})),l=r=>r===""||r==null;return s.sort((r,c)=>{const d=l(r.key),f=l(c.key);if(d&&f)return 0;if(d)return 1;if(f)return-1;const m=es(r.key,c.key,t);return n==="desc"?-m:m}),s.map(r=>r.rowId)}const Zt=["none","count","count-values","count-empty","sum","average","min","max"],en={none:"None",count:"Count all","count-values":"Count filled","count-empty":"Count empty",sum:"Sum",average:"Average",min:"Min",max:"Max"},ns={count:"Count","count-values":"Filled","count-empty":"Empty",sum:"Sum",average:"Avg",min:"Min",max:"Max"};function tn(e,t,n,o){if(!n||n==="none")return null;if(n==="count")return e.length;const s=e.map(r=>$e(r,o).trim());if(n==="count-values")return s.filter(r=>r!=="").length;if(n==="count-empty")return s.filter(r=>r==="").length;const l=s.map(Number).filter((r,c)=>s[c]!==""&&!Number.isNaN(r));return l.length===0?null:n==="sum"?l.reduce((r,c)=>r+c,0):n==="average"?l.reduce((r,c)=>r+c,0)/l.length:n==="min"?Math.min(...l):n==="max"?Math.max(...l):null}function nn(e){return e==null?"":Number.isInteger(e)?String(e):e.toFixed(2)}function ke(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function on(e,t){const o=e.getBlock(t.parentId).contentIds.indexOf(t.id);ke(e,[i.removeBlock(t.id)]);const s=Ge(e);if(s)return C.focusBlockStart(e,s),null;const l=e.getBlock(t.parentId),r=l.contentIds[o]??l.contentIds[o-1];return r&&C.focusBlockStart(e,r),null}function sn(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId),s=o.contentIds.indexOf(t),l=ee(o,n.contentIds.length),r=i.genId(),c=[],d=[],f=[];for(const p of l){const h=We(r,p);c.push(h.block),d.push(h.run),f.push(h.block.id)}const m={id:r,type:"tableRow",parentId:o.id,contentIds:f,props:{}};return e.applyOperation(i.insertBlock(m,o.id,s+1,{blocks:[m,...c],runs:d})),C.focusBlockStart(e,r),r}function ln(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId);if(o.contentIds.length<=1)return on(e,o);const s=o.contentIds.indexOf(t);ke(e,[i.removeBlock(t)]);const l=e.getBlock(o.id),r=Math.min(s,l.contentIds.length-1),c=l.contentIds[r];return c&&C.focusBlockStart(e,c),c??null}function ot(e,t,n){const o=e.getBlock(t),s=ee(o,o.contentIds[0]?e.getBlock(o.contentIds[0]).contentIds.length:0),l={id:i.genId(),label:"New Column",type:He,width:qe},r=[];let c=null;for(const f of o.contentIds){const m=We(f,l);c===null&&(c=m.block.id),r.push(i.insertBlock(m.block,f,n+1,{blocks:[m.block],runs:[m.run]}))}const d=[...s];return d.splice(n+1,0,l),r.push(i.updateBlockProps(t,{columns:d})),ke(e,r),c&&C.focusBlockStart(e,c),c}function rn(e,t,n){const o=e.getBlock(t),s=e.getBlock(o.contentIds[0]);if(!s||s.contentIds.length<=1)return on(e,o);const l=ee(o,s.contentIds.length),r=o.contentIds.map(p=>{const h=e.getBlock(p);return i.removeBlock(h.contentIds[n])}),c=l.filter((p,h)=>h!==n);r.push(i.updateBlockProps(t,{columns:c})),ke(e,r);const d=e.getBlock(o.contentIds[0]),f=Math.min(n,d.contentIds.length-1),m=d.contentIds[f];return m&&C.focusBlockStart(e,m),m??null}function st(e,t,n,o){const s=e.getBlock(t),l=e.getBlock(s.contentIds[0]),r=ee(s,l?l.contentIds.length:0);if(!r[n])return;const c=[...r];c[n]={...r[n],width:Math.max(be,Math.round(o))},e.applyOperation(i.updateBlockProps(t,{columns:c}))}function an(e,t,n,o){const s=e.getBlock(t),l=e.getBlock(s.contentIds[0]),c=[...ee(s,l?l.contentIds.length:0)];c[n]&&(c[n]={...c[n],label:o},e.applyOperation(i.updateBlockProps(t,{columns:c})))}function lt(e,t,n,o,s){var m;const l=e.getBlock(t),r=l.contentIds.map(p=>{const h=e.getBlock(p),k=e.getBlock(h.contentIds[n]);return{rowId:p,run:k?e.getRun(k.contentIds[0]):null}}),d=((m=ee(l,r.length?e.getBlock(l.contentIds[0]).contentIds.length:0)[n])==null?void 0:m.type)??He,f=ts(r,d,o,s);e.applyOperation(i.setBlockContentIds(t,f))}function cn(e,t,n,o){const s=e.getBlock(t),l=e.getBlock(s.contentIds[0]),r=ee(s,l?l.contentIds.length:0);if(!r[n])return;const c=[...r];c[n]={...r[n],aggregate:o},e.applyOperation(i.updateBlockProps(t,{columns:c}))}function ft(e,t,n){return t.contentIds.map(o=>{const l=e.getBlock(o).contentIds[n],r=e.getBlock(l);return{cellId:l,run:e.getRun(r.contentIds[0])}})}function os(e,t,n,o){const s=ft(e,t,n),l=[],r=new Map;for(const{run:d}of s){const f=$e(d,o).trim();if(!f||r.has(f))continue;const m={value:i.genId(),label:f};r.set(f,m),l.push(m)}const c=s.map(({cellId:d,run:f})=>{const m=$e(f,o).trim(),p=r.get(m);return{cellId:d,run:{id:i.genId(),type:"tableSelect",value:"",marks:{},data:{selectedValue:(p==null?void 0:p.value)??"",selectedLabel:(p==null?void 0:p.label)??""}}}});return{options:l,newRuns:c}}function un(e,t,n,o,s){const l=e.getBlock(t),r=e.getBlock(l.contentIds[0]),c=ee(l,r?r.contentIds.length:0),d=c[n];if(!d||d.type===o)return;const f=[...c];if(o==="select"){const{options:p,newRuns:h}=os(e,l,n,s);f[n]={...d,type:o,options:p};const k=[i.updateBlockProps(t,{columns:f})];for(const{cellId:x,run:b}of h)k.push(i.setBlockRuns(x,[b]));ke(e,k);return}f[n]={...d,type:o};const m=[i.updateBlockProps(t,{columns:f})];for(const{cellId:p,run:h}of ft(e,l,n)){if(!h)continue;const k=Jt(h,o,s);m.push(i.setBlockRuns(p,[k]))}ke(e,m)}function Me(e,t,n,o){var p,h;const s=e.getBlock(t),l=e.getBlock(s.contentIds[0]),r=ee(s,l?l.contentIds.length:0),c=r[n];if(!c)return;const d=[...r];d[n]={...c,options:o};const f=[i.updateBlockProps(t,{columns:d})],m=new Map(o.map(k=>[k.value,k]));for(const{run:k}of ft(e,s,n)){if(!k||k.type!=="tableSelect")continue;const x=((p=k.data)==null?void 0:p.selectedValue)??"",b=m.get(x),I=b?x:"",v=b?b.label:"";(I!==x||v!==(((h=k.data)==null?void 0:h.selectedLabel)??""))&&f.push(i.updateRun(k.id,{data:{selectedValue:I,selectedLabel:v}}))}ke(e,f)}const ss="$fieldTypes";function dn(){const e=i.useEditorStore(),t=u.useCallback(o=>e.subscribe(ss,o),[e]),n=u.useCallback(()=>e.getFieldTypes(),[e]);return u.useSyncExternalStore(t,n)}function Bt(){if(typeof window>"u"||!window.visualViewport)return 0;const e=window.visualViewport,t=window.innerHeight-(e.height+e.offsetTop);return t>0?Math.round(t):0}function pn(){const[e,t]=u.useState(Bt);return u.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const n=window.visualViewport,o=()=>t(Bt());return o(),n.addEventListener("resize",o),n.addEventListener("scroll",o),()=>{n.removeEventListener("resize",o),n.removeEventListener("scroll",o)}},[]),e}const ls=280,Tt=220,rs=32,wt=6;function as(e,t){return t?e.label.toLowerCase().includes(t.toLowerCase()):!0}function ye({value:e,options:t,onChange:n,placeholder:o="Select…",ariaLabel:s,className:l="",variant:r="default",selectedLabel:c,selectedColor:d,onManageOptions:f,manageOptionsLabel:m="Manage options…",mention:p=!1,autoOpen:h=!1}){var F,Q;const[k,x]=u.useState(!1),[b,I]=u.useState(""),[v,g]=u.useState(0),[y,w]=u.useState(null),$=pn(),[O,j]=u.useState([]),[S,E]=u.useState(!1),[H,B]=u.useState(!1),A=u.useRef(null),M=u.useRef(null),P=u.useRef(null),N=u.useRef(null),D=u.useRef(null),z=u.useRef(null),G=u.useMemo(()=>[A,P],[]),te=r==="tag",_=typeof t=="function",[V,U]=u.useState(rs),[oe,X]=u.useState(0),le=_?void 0:t.find(R=>R.value===e),J=e?le??(c?{label:c,color:d}:void 0):void 0,Y=u.useMemo(()=>_?O:t.filter(R=>as(R,b)),[_,O,t,b]),xe=Math.max(0,(Y.length-1)*V),ge=Math.min(oe,xe),W=Y.length?Math.max(0,Math.floor(ge/V)-wt):0,_e=Math.ceil(Tt/V)+wt*2,de=Math.min(Y.length,W+_e),Ye=Y.slice(W,de),we=W*V,Re=Math.max(0,(Y.length-de)*V);u.useLayoutEffect(()=>{var q;const R=(q=z.current)==null?void 0:q.getBoundingClientRect().height;R&&Math.abs(R-V)>.5&&U(R)}),u.useEffect(()=>{if(!_||!k)return;let R=!1;E(!0),B(!1);const q=setTimeout(()=>{Promise.resolve(t(b)).then(Z=>{R||(j(Z??[]),E(!1))}).catch(()=>{R||(j([]),E(!1),B(!0))})},250);return()=>{R=!0,clearTimeout(q)}},[_,k,t,b]);const se=u.useCallback(()=>x(!1),[]);T.useOutsideClickAndEscape(G,k,se);const ve=ae.useHorizontalAutoAdjustedLeft(P,k,y==null?void 0:y.left),Ae=u.useCallback(()=>{var R;w(((R=M.current)==null?void 0:R.getBoundingClientRect())??null),I(""),g(0),X(0),x(!0)},[]);u.useEffect(()=>{h&&Ae()},[]),u.useEffect(()=>{var R;k&&((R=N.current)==null||R.focus())},[k,ve]),u.useEffect(()=>{const R=D.current;if(!R)return;const q=v*V,Z=q+V,pe=R.scrollTop,fe=R.clientHeight||Tt,re=pe+fe;let je=null;q<pe?je=q:Z>re&&(je=Z-fe),je!==null&&(R.scrollTop=je,X(je))},[v,V]);const L=u.useCallback(R=>{var q;n(R.value,R),se(),(q=M.current)==null||q.focus()},[n,se]),K=u.useCallback(R=>{var q;R.key==="ArrowDown"?(R.preventDefault(),g(Z=>Math.min(Z+1,Math.max(Y.length-1,0)))):R.key==="ArrowUp"?(R.preventDefault(),g(Z=>Math.max(Z-1,0))):R.key==="Enter"?(R.preventDefault(),Y[v]&&L(Y[v])):R.key==="Escape"&&(R.preventDefault(),se(),(q=M.current)==null||q.focus())},[Y,v,L,se]);return a.jsxs("span",{className:`be-select ${l}`.trim(),ref:A,children:[a.jsx("button",{type:"button",ref:M,className:`be-select-trigger${te?" be-select-trigger-tag":""}${p?" be-select-trigger-mention":""}`,"aria-haspopup":"listbox","aria-expanded":k,"aria-label":s,onClick:()=>k?se():Ae(),children:te?J?a.jsx("span",{className:`be-select-tag${p?" be-select-tag-mention":""}`,style:p?void 0:{background:(F=J.color)==null?void 0:F.bg,color:(Q=J.color)==null?void 0:Q.text},children:p?`@${J.label}`:J.label}):a.jsx("span",{className:"be-select-value be-select-value-placeholder",children:o}):a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"be-select-value",children:J?J.label:o}),a.jsx(i.ChevronDownIcon,{size:14,className:"be-select-chevron"})]})}),k&&y&&ve!=null&&Ie.createPortal(a.jsxs("div",{ref:P,className:"be-select-popover",style:{position:"fixed",left:ve,minWidth:y.width,...y.bottom+ls>window.innerHeight-$?{bottom:window.innerHeight-y.top+4}:{top:y.bottom+4}},children:[a.jsx("input",{ref:N,type:"text",className:"be-select-search",value:b,onChange:R=>{I(R.target.value),g(0)},onKeyDown:K,placeholder:"Search…","aria-label":s?`Search ${s}`:"Search options"}),a.jsxs("div",{className:"be-select-options",role:"listbox",ref:D,onScroll:R=>X(R.currentTarget.scrollTop),children:[_&&S&&a.jsx("div",{className:"be-select-empty",children:"Loading…"}),_&&!S&&H&&a.jsx("div",{className:"be-select-empty be-select-error",children:"Couldn't load options"}),!S&&!H&&Y.length===0&&a.jsx("div",{className:"be-select-empty",children:"No results"}),!S&&!H&&Y.length>0&&a.jsxs(a.Fragment,{children:[we>0&&a.jsx("div",{style:{height:we},"aria-hidden":"true"}),Ye.map((R,q)=>{var pe,fe;const Z=W+q;return a.jsx("div",{ref:q===0?z:void 0,role:"option","aria-selected":R.value===e,className:`be-select-option${Z===v?" be-select-option-active":""}${R.value===e?" be-select-option-selected":""}`,onMouseDown:re=>{re.preventDefault(),L(R)},onMouseEnter:()=>g(Z),children:te?a.jsx("span",{className:"be-select-tag",style:{background:(pe=R.color)==null?void 0:pe.bg,color:(fe=R.color)==null?void 0:fe.text},children:R.label}):R.label},R.value)}),Re>0&&a.jsx("div",{style:{height:Re},"aria-hidden":"true"})]})]}),f&&a.jsx("button",{type:"button",className:"be-select-manage-options",onMouseDown:R=>{R.preventDefault(),se(),f()},children:m})]}),document.body)]})}const Fe=[{bg:"#e9e9e7",text:"#32302c"},{bg:"#eee0da",text:"#64473a"},{bg:"#fadec9",text:"#8a4b23"},{bg:"#fdecc8",text:"#8a6116"},{bg:"#dbeddb",text:"#256029"},{bg:"#d3e5ef",text:"#1a5f8a"},{bg:"#e8deee",text:"#5b3a8a"},{bg:"#f5e0e9",text:"#8a3a5f"},{bg:"#ffe2dd",text:"#a13a2f"}];function ze(e){return Fe[(e%Fe.length+Fe.length)%Fe.length]}const cs={text:"Text",date:"Date",checkbox:"Checkbox",select:"Select"},is=Zt.map(e=>({value:e,label:en[e]})),us=Yt.map(e=>({value:e,label:cs[e]})),Je=800;function ds({tableId:e,colIndex:t}){const n=i.useEditorStore(),o=dn(),{openCreate:s}=i.useFieldTypeEditor(),l=u.useCallback(r=>{const c=n.getFieldType(r);c&&Me(n,e,t,c.options??[])},[n,e,t]);return a.jsxs("div",{className:"be-table-header-menu-field-type",children:[o.length>0&&a.jsx(ye,{value:"",options:o.map(r=>({value:r.id,label:r.label})),onChange:l,placeholder:"Copy options from…",ariaLabel:"Copy options from an existing field type"}),a.jsx("button",{type:"button",className:"be-table-header-menu-item",onClick:s,children:"+ New field type"})]})}function ps({tableId:e,colIndex:t,options:n}){const o=i.useEditorStore(),[s,l]=u.useState(""),r=u.useCallback((f,m)=>{Me(o,e,t,n.map(p=>p.value===f?{...p,label:m}:p))},[o,e,t,n]),c=u.useCallback(f=>Me(o,e,t,n.filter(m=>m.value!==f)),[o,e,t,n]),d=u.useCallback(()=>{const f=s.trim();l(""),f&&Me(o,e,t,[...n,{value:i.genId(),label:f,color:ze(n.length)}])},[o,e,t,n,s]);return a.jsxs("div",{className:"be-table-header-menu-options",children:[a.jsx("div",{className:"be-table-header-menu-options-label",children:"Options"}),n.map((f,m)=>a.jsxs("div",{className:"be-table-header-menu-option-row",children:[a.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(f.color??ze(m)).bg},"aria-hidden":"true"}),a.jsx("input",{className:"be-table-header-menu-option-input",value:f.label,onChange:p=>r(f.value,p.target.value),"aria-label":`Rename option ${f.label}`}),a.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>c(f.value),"aria-label":`Remove option ${f.label}`,children:a.jsx(i.XIcon,{size:14})})]},f.value)),a.jsxs("div",{className:"be-table-header-menu-option-row",children:[a.jsx("input",{className:"be-table-header-menu-option-input",value:s,onChange:f=>l(f.target.value),placeholder:"New option…",onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),d())}}),a.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:d,"aria-label":"Add option",children:"+"})]})]})}function fs({tableId:e,column:t,colIndex:n,colCount:o,filterValue:s,onFilterChange:l}){const r=i.useEditorStore(),c=i.useInlineRegistry(),[d,f]=u.useState(!1),[m,p]=u.useState(null),[h,k]=u.useState(null),x=u.useRef(null),b=u.useRef(null),I=u.useRef(null),v=u.useMemo(()=>[x,b],[]),g=u.useCallback(()=>f(!1),[]);T.useOutsideClickAndEscape(v,d,g),Ve(b,d,g,x);const y=ae.useAutoAdjustedRightLeft(b,d,m==null?void 0:m.right),w=u.useCallback(()=>{var N;p(((N=I.current)==null?void 0:N.getBoundingClientRect())??null),f(!0)},[]),$=u.useCallback(N=>an(r,e,n,N.target.value),[r,e,n]),O=u.useCallback(()=>{ot(r,e,n-1),g()},[r,e,n,g]),j=u.useCallback(()=>{ot(r,e,n),g()},[r,e,n,g]),S=u.useCallback(()=>{rn(r,e,n),g()},[r,e,n,g]),E=u.useCallback(N=>un(r,e,n,N,c),[r,e,n,c]),H=u.useCallback(()=>{lt(r,e,n,"asc",c),g()},[r,e,n,c,g]),B=u.useCallback(()=>{lt(r,e,n,"desc",c),g()},[r,e,n,c,g]),A=u.useCallback(N=>cn(r,e,n,N),[r,e,n]),M=u.useCallback(N=>{var oe;N.preventDefault();const D=(oe=I.current)==null?void 0:oe.closest("table"),z=D==null?void 0:D.querySelector(`col[data-col-index="${n}"]`);if(!z)return;const G=I.current.getBoundingClientRect().width,te=N.clientX,_=X=>Math.max(be,Math.round(G+(X.clientX-te))),V=X=>{const le=_(X);z.style.width=`${le}px`,k(le)},U=X=>{document.removeEventListener("mousemove",V),document.removeEventListener("mouseup",U),st(r,e,n,_(X)),k(null)};document.addEventListener("mousemove",V),document.addEventListener("mouseup",U)},[r,e,n]),P=u.useCallback(N=>{const D=t.width??be,z=N.shiftKey?1:16;let G;if(N.key==="ArrowLeft"||N.key==="ArrowDown")G=Math.max(be,D-z);else if(N.key==="ArrowRight"||N.key==="ArrowUp")G=Math.min(Je,D+z);else if(N.key==="Home")G=be;else if(N.key==="End")G=Je;else return;N.preventDefault(),st(r,e,n,G)},[r,e,n,t.width]);return a.jsxs("th",{ref:I,scope:"col",className:"be-table-header-cell",contentEditable:!1,children:[a.jsx("input",{className:"be-table-header-label",value:t.label,onChange:$,"aria-label":`Column ${n+1} name`}),a.jsx("button",{ref:x,type:"button",className:"be-table-header-menu-trigger","aria-label":`Column ${n+1} options`,"aria-haspopup":"menu","aria-expanded":d,onClick:()=>d?g():w(),children:"⋮"}),a.jsx("div",{className:"be-table-col-resize-handle",onMouseDown:M,onKeyDown:P,role:"slider",tabIndex:0,"aria-label":`Resize column ${n+1}`,"aria-valuemin":be,"aria-valuemax":Je,"aria-valuenow":h??t.width}),d&&m&&y!=null&&Ie.createPortal(a.jsxs("div",{ref:b,role:"menu","aria-label":`Column ${n+1} options`,className:"be-table-header-menu",style:{position:"fixed",top:m.bottom+4,left:y,transform:"translateX(-100%)"},children:[a.jsxs("div",{className:"be-table-header-menu-type",children:[a.jsx("span",{id:`be-table-col-type-${t.id}`,children:"Type"}),a.jsx(ye,{value:t.type,options:us,onChange:E,ariaLabel:"Column type",className:""})]}),t.type==="select"&&a.jsxs(a.Fragment,{children:[a.jsx(ds,{tableId:e,colIndex:n}),a.jsx(ps,{tableId:e,colIndex:n,options:t.options??[]})]}),a.jsxs("div",{className:"be-table-header-menu-sort",children:[a.jsxs("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:H,children:[a.jsx(i.ArrowUpIcon,{size:13})," Sort ascending"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:B,children:[a.jsx(i.ArrowDownIcon,{size:13})," Sort descending"]})]}),a.jsxs("label",{className:"be-table-header-menu-filter",children:[a.jsx("span",{children:"Filter"}),a.jsx("input",{type:"text",className:"be-table-header-menu-filter-input",placeholder:"Rows containing…",value:s??"",onChange:N=>l(t.id,N.target.value),"aria-label":`Filter column ${n+1}`})]}),a.jsxs("div",{className:"be-table-header-menu-type be-table-header-menu-aggregate",children:[a.jsx("span",{id:`be-table-col-aggregate-${t.id}`,children:"Footer"}),a.jsx(ye,{value:t.aggregate??"none",options:is,onChange:A,ariaLabel:"Column footer aggregate",className:""})]}),a.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:O,children:"Insert column left"}),a.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:j,children:"Insert column right"}),a.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item be-table-header-menu-item-danger",onClick:S,disabled:o<=1,children:"Delete column"})]}),document.body)]})}function fn({tableId:e,columns:t,filters:n,onFilterChange:o}){return a.jsx("thead",{children:a.jsxs("tr",{className:"be-table-header-row",children:[t.map((s,l)=>a.jsx(fs,{tableId:e,column:s,colIndex:l,colCount:t.length,filterValue:n==null?void 0:n[s.id],onFilterChange:o},s.id)),a.jsx("th",{className:"be-table-header-spacer","aria-hidden":"true"})]})})}function ms({id:e}){var b;const t=i.useEditorStore(),n=i.useInlineRegistry(),o=T.useBlock(e),[s,l]=u.useState({}),r=u.useCallback((I,v)=>{l(g=>v?{...g,[I]:v}:Object.fromEntries(Object.entries(g).filter(([y])=>y!==I)))},[]),c=u.useCallback(()=>{var v;const I=(v=o==null?void 0:o.contentIds)==null?void 0:v[o.contentIds.length-1];I&&sn(t,I)},[t,o]),d=i.useBlockClassName("be-table-wrapper",o),f=u.useMemo(()=>Object.entries(s).filter(([,I])=>I),[s]),m=u.useCallback((I,v)=>{const g=t.getBlock(I),y=g&&t.getBlock(g.contentIds[v]);return y?t.getRun(y.contentIds[0]):null},[t]);if(!o)return null;const p=t.getBlock(o.contentIds[0]),h=ee(o,((b=p==null?void 0:p.contentIds)==null?void 0:b.length)??0),k=f.length===0?o.contentIds:o.contentIds.filter(I=>f.every(([v,g])=>{const y=h.findIndex($=>$.id===v);return y===-1?!0:$e(m(I,y),n).toLowerCase().includes(g.toLowerCase())})),x=h.some(I=>I.aggregate&&I.aggregate!=="none");return a.jsx("div",{className:"be-table-scroll",children:a.jsxs("div",{className:d,"data-block-id":e,children:[a.jsxs("table",{className:"be-table",children:[a.jsxs("colgroup",{children:[h.map((I,v)=>a.jsx("col",{"data-col-index":v,style:{width:I.width}},I.id)),a.jsx("col",{className:"be-table-header-spacer-col"})]}),a.jsx(fn,{tableId:e,columns:h,filters:s,onFilterChange:r}),a.jsx("tbody",{children:a.jsx(he,{parentId:e,filterIds:k})}),x&&a.jsx("tfoot",{children:a.jsxs("tr",{className:"be-table-footer-row",children:[h.map((I,v)=>{const g=k.map(w=>m(w,v)),y=tn(g,I.type,I.aggregate,n);return a.jsx("td",{className:"be-table-footer-cell",children:y!=null&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"be-table-footer-label",children:ns[I.aggregate]}),nn(y)]})},I.id)}),a.jsx("td",{className:"be-table-footer-spacer","aria-hidden":"true"})]})})]}),a.jsxs("button",{type:"button",className:"be-table-add-row",contentEditable:!1,onClick:c,children:[a.jsx(i.PlusIcon,{size:14})," Add row"]})]})})}function hs({id:e}){const t=i.useEditorStore(),n=T.useBlock(e),o=i.useBlockClassName("be-table-row",n),s=u.useCallback(()=>ln(t,e),[t,e]);return a.jsxs("tr",{className:o,"data-block-id":e,children:[a.jsx(he,{parentId:e}),a.jsx("td",{className:"be-table-row-actions",contentEditable:!1,children:a.jsx("button",{type:"button",className:"be-table-delete-row",onClick:s,"aria-label":"Delete row",title:"Delete row",children:a.jsx(i.XIcon,{size:14})})})]})}function mn(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId),s=e.getBlock(o.parentId);return{table:s,row:o,rowIndex:s.contentIds.indexOf(o.id),colIndex:o.contentIds.indexOf(t)}}function gs(e,t,n){const{table:o,row:s,rowIndex:l,colIndex:r}=mn(e,t);if(n==="left"||n==="right"){const m=n==="right"?1:-1,p=r+m;if(p>=0&&p<s.contentIds.length)return s.contentIds[p];const h=l+m;if(h<0||h>=o.contentIds.length)return null;const k=e.getBlock(o.contentIds[h]),x=n==="right"?0:k.contentIds.length-1;return k.contentIds[x]}const d=l+(n==="down"?1:-1);if(d<0||d>=o.contentIds.length)return null;const f=e.getBlock(o.contentIds[d]);return f.contentIds[r]??f.contentIds[f.contentIds.length-1]??null}function bs(e,t){const n=C.resolveAdjacentFocusTarget(e,t,"down");if(n){C.focusRunEnd(n);return}C.insertSiblingAfterAndFocus(e,t,C.createTextLeafBlock("paragraph"))}function Ne(e,t,n){var s;const o=gs(e,t,n);if(o){const l=e.getBlock(o),r=(s=l==null?void 0:l.contentIds)==null?void 0:s[0];r&&C.focusRunEnd(r);return}if(n==="right"){const{table:l}=mn(e,t);bs(e,l.id)}}function ks({id:e}){const t=i.useEditorStore(),n=T.useBlock(e),o=u.useCallback(()=>Ne(t,e,"right"),[t,e]),s=u.useCallback(()=>Ne(t,e,"left"),[t,e]),l=u.useCallback(()=>Ne(t,e,"up"),[t,e]),r=u.useCallback(()=>Ne(t,e,"down"),[t,e]),c=u.useCallback(()=>Ne(t,e,"down"),[t,e]),d=i.useBlockClassName("be-table-cell",n);if(!n)return null;const f=ce(t,n);return a.jsx("td",{className:d,"data-block-id":e,dir:f,children:a.jsx(ue,{blockId:e,runIds:n.contentIds,dir:f,onTab:o,onShiftTab:s,onArrowUp:l,onArrowDown:r,onEnter:c})})}function ys(e,t){const n=i.genId(),o=[],s=[],l=[];for(const r of t){const c=We(n,r);o.push(c.block),s.push(c.run),l.push(c.block.id)}return{block:{id:n,type:"tableRow",parentId:e,contentIds:l,props:{}},blocks:o,runs:s}}function Is({rows:e=2,cols:t=2}={}){return function(o){const s=i.genId(),l=pt(t),r=[],c=[],d=[];for(let m=0;m<e;m+=1){const p=ys(s,l);r.push(p.block,...p.blocks),c.push(...p.runs),d.push(p.block.id)}return{block:{id:s,type:"table",parentId:o,contentIds:d,props:{columns:l}},runs:c,subtreeBlocks:r}}}function Cs(e,t){return`<td>${e.contentIds.map(o=>t.store.getRun(o)).map(o=>T.runToHTML(o,t)).join("")}</td>`}function xs(e,t){return e.contentIds.map(n=>T.runToPlainText(t.store.getRun(n),t)).join("")}function vs(e,t){return T.runsToMarkdown(e.contentIds.map(o=>t.store.getRun(o)),t).replace(/\|/g,"\\|").replace(/\r?\n/g,"<br>")}function Bs(e,t){if(e.tagName!=="TD"&&e.tagName!=="TH")return null;const n=ie(e,t);return{block:{id:i.genId(),type:"tableCell",parentId:null,contentIds:n.map(s=>s.id),props:{}},runs:n}}function Ts(e,t){return`<tr>${e.contentIds.map(o=>{const s=t.store.getBlock(o);return t.registry.get(s.type).toHTML(s,t)}).join("")}</tr>`}function ws(e,t){return e.contentIds.map(n=>{const o=t.store.getBlock(n);return t.registry.get(o.type).toPlainText(o,t)}).join(" ")}function Rs(e,t){return`| ${e.contentIds.map(o=>{const s=t.store.getBlock(o);return t.registry.get(s.type).toMarkdown(s,t)}).join(" | ")} |`}function As(e,t){if(e.tagName!=="TR")return null;const n=[...e.children].filter(d=>d.tagName==="TD"||d.tagName==="TH"),o=i.genId(),s=[],l=[],r=[];for(const d of n){const f=t.registry.get("tableCell").fromHTML(d,t);f&&(f.block.parentId=o,s.push(f.block),l.push(...f.runs),r.push(f.block.id))}return{block:{id:o,type:"tableRow",parentId:null,contentIds:r,props:{}},runs:l,subtreeBlocks:s}}function js(e,t){var r;const n=e.contentIds[0]&&t.store.getBlock(e.contentIds[0]),o=ee(e,((r=n==null?void 0:n.contentIds)==null?void 0:r.length)??0),s=o.length?`<thead><tr>${o.map(c=>`<th>${T.escapeHTML(c.label??"")}</th>`).join("")}</tr></thead>`:"",l=e.contentIds.map(c=>{const d=t.store.getBlock(c);return t.registry.get(d.type).toHTML(d,t)}).join("");return`<table>${s}<tbody>${l}</tbody></table>`}function Ls(e,t){return e.contentIds.map(n=>{const o=t.store.getBlock(n);return t.registry.get(o.type).toPlainText(o,t)}).join(`
|
|
6
|
-
`)}function Ns(e,t){var c;const n=e.contentIds[0]&&t.store.getBlock(e.contentIds[0]),o=ee(e,((c=n==null?void 0:n.contentIds)==null?void 0:c.length)??0);if(o.length===0)return"";const s=`| ${o.map(d=>(d.label??"").replace(/\|/g,"\\|")).join(" | ")} |`,l=`| ${o.map(()=>"---").join(" | ")} |`,r=e.contentIds.map(d=>{const f=t.store.getBlock(d);return t.registry.get(f.type).toMarkdown(f,t)}).join(`
|
|
7
|
-
`);return r?`${s}
|
|
8
|
-
${l}
|
|
9
|
-
${r}`:`${s}
|
|
10
|
-
${l}`}function Es(e,t){if(e.tagName!=="TABLE")return null;const n=e.querySelector("thead tr"),o=e.querySelector("tbody")?[...e.querySelectorAll("tbody tr")]:[...e.querySelectorAll("tr")].filter(m=>m!==n),s=i.genId(),l=[],r=[],c=[];for(const m of o){const p=t.registry.get("tableRow").fromHTML(m,t);if(p){p.block.parentId=s;for(const h of p.subtreeBlocks)h.parentId=p.block.id;l.push(p.block,...p.subtreeBlocks),r.push(...p.runs),c.push(p.block.id)}}const d={};if(n){const m=[...n.children].filter(p=>p.tagName==="TH"||p.tagName==="TD");d.columns=m.map(p=>({id:i.genId(),label:p.textContent??""}))}return{block:{id:s,type:"table",parentId:null,contentIds:c,props:d},runs:r,subtreeBlocks:l}}const hn=T.defineBlock({name:"tableCell",contentModel:"runs",component:ks,defaultProps:{},toHTML:Cs,toPlainText:xs,toMarkdown:vs,fromHTML:Bs}),gn=T.defineBlock({name:"tableRow",contentModel:"blocks",component:hs,defaultProps:{},toHTML:Ts,toPlainText:ws,toMarkdown:Rs,fromHTML:As}),bn=T.defineBlock({name:"table",contentModel:"blocks",component:ms,defaultProps:{},toHTML:js,toPlainText:Ls,toMarkdown:Ns,fromHTML:Es,slashCommand:{label:"Table",icon:i.TableIcon,keywords:["table","grid"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Is({rows:2,cols:2}))}});function Ss({id:e}){const t=T.useBlock(e),n=i.useBlockClassName("be-layout",t);return a.jsx("div",{className:n,"data-block-id":e,style:{display:"flex",gap:"1em"},children:a.jsx(he,{parentId:e})})}function Ms({id:e}){const t=T.useBlock(e),n=i.useBlockClassName("be-layout-column",t);return a.jsx("div",{className:n,"data-block-id":e,children:a.jsx(he,{parentId:e})})}function $s({columns:e=2}={}){return function(n){const o=i.genId(),s=[],l=[],r=[];for(let d=0;d<e;d+=1){const f=i.genId(),{block:m,runs:p}=C.createTextLeafBlock("paragraph")(f),h={id:f,type:"layoutColumn",parentId:o,contentIds:[m.id],props:{}};s.push(h,m),l.push(...p),r.push(f)}return{block:{id:o,type:"layout",parentId:n,contentIds:r,props:{}},runs:l,subtreeBlocks:s}}}function kn(e,t){return(n,o)=>`${e}${n.contentIds.map(s=>{const l=o.store.getBlock(s);return o.registry.get(l.type).toHTML(l,o)}).join("")}${t}`}function yn(e,t){return e.contentIds.map(n=>{const o=t.store.getBlock(n);return t.registry.get(o.type).toPlainText(o,t)}).join(`
|
|
11
|
-
`)}function In(e,t){return e.contentIds.map(n=>{const o=t.store.getBlock(n),s=t.registry.get(o.type);return(s.toMarkdown??s.toPlainText)(o,t)}).join(`
|
|
12
|
-
|
|
13
|
-
`)}const Cn=T.defineBlock({name:"layoutColumn",contentModel:"blocks",component:Ms,defaultProps:{},toHTML:kn("<div>","</div>"),toPlainText:yn,toMarkdown:In}),xn=T.defineBlock({name:"layout",contentModel:"blocks",component:Ss,defaultProps:{},toHTML:kn('<div style="display:flex;gap:1em">',"</div>"),toPlainText:yn,toMarkdown:In,slashCommands:[2,3,4,5].map(e=>({label:`${e} columns`,icon:i.ColumnsIcon,keywords:["layout","columns","column",String(e)],run:(t,n)=>C.trimSlashQueryAndInsertAfter(t,n,$s({columns:e}))}))});function Os({id:e}){const t=T.useBlock(e),n=i.useBlockClassName("be-divider",t);return a.jsx("hr",{className:n,"data-block-id":e,contentEditable:!1,tabIndex:-1})}function Ds(){return function(t){return{block:{id:i.genId(),type:"divider",parentId:t,contentIds:[],props:{}},runs:[]}}}function Ps(){return"<hr />"}function Hs(){return"---"}function _s(){return"---"}function Fs(e){return e.tagName!=="HR"?null:{block:{id:i.genId(),type:"divider",parentId:null,contentIds:[],props:{}},runs:[]}}const vn=T.defineBlock({name:"divider",contentModel:"void",component:Os,defaultProps:{},toHTML:Ps,toPlainText:Hs,toMarkdown:_s,fromHTML:Fs,slashCommand:{label:"Divider",icon:i.DividerIcon,keywords:["divider","hr","separator","line"],run:(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:s})=>{const l=e.getRun(n),r=(l==null?void 0:l.value)??"";e.applyOperation(i.updateRun(n,{value:r.slice(0,o)+r.slice(s)}));const c=C.insertSiblingAfter(e,t,Ds());return C.insertSiblingAfterAndFocus(e,c,C.createTextLeafBlock("paragraph")),c}}}),Bn=[{value:"gray",label:"Gray"},{value:"blue",label:"Blue"},{value:"green",label:"Green"},{value:"yellow",label:"Yellow"},{value:"orange",label:"Orange"},{value:"red",label:"Red"},{value:"purple",label:"Purple"},{value:"pink",label:"Pink"}];function Us({id:e}){var v,g;const t=i.useEditorStore(),n=T.useBlock(e),[o,s]=u.useState(!1),[l,r]=u.useState(!1),c=u.useRef(null),d=u.useRef(null),f=u.useMemo(()=>[c,d],[]),m=u.useCallback(()=>r(!1),[]);T.useOutsideClickAndEscape(f,l,m);const p=((v=n==null?void 0:n.props)==null?void 0:v.icon)??Ce,h=((g=n==null?void 0:n.props)==null?void 0:g.color)??Pt,k=u.useCallback(y=>{const w=y.target.value.trim();w&&t.applyOperation(i.updateBlockProps(e,{icon:w})),s(!1)},[t,e]),x=u.useCallback(y=>{y.key==="Enter"&&y.currentTarget.blur(),y.key==="Escape"&&s(!1)},[]),b=u.useCallback(y=>{t.applyOperation(i.updateBlockProps(e,{color:y})),r(!1)},[t,e]),I=i.useBlockClassName("be-callout",n);return n?a.jsxs("div",{className:I,"data-block-id":e,"data-color":h,children:[a.jsx("div",{className:"be-callout-icon-wrap",children:o?a.jsx("input",{type:"text",className:"be-callout-icon-input",defaultValue:p,autoFocus:!0,onBlur:k,onKeyDown:x,"aria-label":"Callout icon (paste or type an emoji)"}):a.jsx("button",{type:"button",className:"be-callout-icon",onClick:()=>s(!0),"aria-label":"Change callout icon",title:"Change icon",children:p})}),a.jsx("div",{className:"be-callout-content",children:a.jsx(he,{parentId:e})}),a.jsxs("div",{className:"be-callout-color-wrap",contentEditable:!1,children:[a.jsx("button",{ref:c,type:"button",className:"be-callout-color-trigger","aria-label":"Callout color","aria-haspopup":"true","aria-expanded":l,title:"Callout color",onClick:()=>r(y=>!y),children:a.jsx("span",{className:`be-callout-color-dot be-callout-color-dot-${h}`})}),l&&a.jsx("div",{ref:d,className:"be-callout-color-picker",role:"menu","aria-label":"Callout color",children:Bn.map(y=>a.jsx("button",{type:"button",role:"menuitem",className:`be-callout-color-option be-callout-color-option-${y.value}${y.value===h?" be-callout-color-option-active":""}`,title:y.label,"aria-label":y.label,onClick:()=>b(y.value)},y.value))})]})]}):null}function Ks(e,t){return e.contentIds.map(n=>{const o=t.store.getBlock(n);return t.registry.get(o.type).toHTML(o,t)}).join("")}function zs(e,t){var o;const n=((o=e.props)==null?void 0:o.icon)??Ce;return`<div class="callout" data-icon="${n}"><div class="callout-icon">${n}</div><div class="callout-content">${Ks(e,t)}</div></div>`}function Gs(e,t){var s;const n=((s=e.props)==null?void 0:s.icon)??Ce,o=e.contentIds.map(l=>{const r=t.store.getBlock(l);return t.registry.get(r.type).toPlainText(r,t)}).join(`
|
|
14
|
-
`);return`${n} ${o}`}function Vs(e,t){var s;const n=((s=e.props)==null?void 0:s.icon)??Ce;return e.contentIds.map(l=>{const r=t.store.getBlock(l),c=t.registry.get(r.type);return(c.toMarkdown??c.toPlainText)(r,t)}).join(`
|
|
15
|
-
`).split(`
|
|
16
|
-
`).map((l,r)=>`> ${r===0?`${n} `:""}${l}`).join(`
|
|
17
|
-
`)}const Tn=T.defineBlock({name:"callout",contentModel:"blocks",component:Us,defaultProps:{icon:Ce},toHTML:zs,toPlainText:Gs,toMarkdown:Vs,slashCommand:{label:"Callout",icon:i.CalloutIcon,keywords:["callout","aside","note","info","tip","warning"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Ao())}});function qs({id:e}){const t=i.useEditorStore(),n=T.useBlock(e),{setSelectedBlockId:o}=i.useSelectedBlock(),s=u.useCallback(()=>{C.insertSiblingSplitAtCaretAndFocus(t,e,(n==null?void 0:n.contentIds)??[],C.createTextLeafBlock("paragraph"))},[t,e,n]),l=u.useCallback(()=>{const p=Pe(t,e);Te(t,p,e,o)},[t,e,o]),r=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),c=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),d=i.useBlockClassName("be-blockquote",n);if(!n)return null;const f=ne(t,n.contentIds),m=ce(t,n);return a.jsx("blockquote",{className:d,"data-block-id":e,"data-empty":f?"":void 0,"data-placeholder":"Empty quote",dir:m,children:a.jsx(ue,{blockId:e,runIds:n.contentIds,dir:m,onEnter:s,onBackspaceAtStart:l,onArrowUp:r,onArrowDown:c})})}function Ws(e,t){return`<p>${e.contentIds.map(o=>t.store.getRun(o)).map(o=>T.runToHTML(o,t)).join("")}</p>`}function Qs(e,t){return e.contentIds.map(n=>T.runToPlainText(t.store.getRun(n),t)).join("")}function Ys(e,t){return`> ${T.runsToMarkdown(e.contentIds.map(o=>t.store.getRun(o)),t)}`}function Xs(e,t){if(e.tagName!=="BLOCKQUOTE")return null;const n=ie(e,t);return{block:{id:i.genId(),type:"blockquote",parentId:null,contentIds:n.map(s=>s.id),props:{}},runs:n}}const wn=T.defineBlock({name:"blockquote",contentModel:"runs",component:qs,defaultProps:{},toHTML:Ws,toPlainText:Qs,toMarkdown:Ys,fromHTML:Xs,slashCommand:{label:"Quote",icon:i.QuoteIcon,keywords:["quote","blockquote","citation"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("blockquote"))}}),Rn=["plaintext","javascript","python","html","css","json","bash","sql"],Js=Rn.map(e=>({value:e,label:e}));function Rt(e,t,n){const o=C.resolveCollapsedCaret();if(!o||o.blockId!==t)return;const s=e.getRun(o.runId);if(!s||s.type!=="text")return;const l=s.value??"",r=l.slice(0,o.offset)+n+l.slice(o.offset);e.applyOperation(i.updateRun(s.id,{value:r})),C.focusRunAtOffset(s.id,o.offset+n.length)}function Zs({id:e}){var b,I;const t=i.useEditorStore(),n=T.useBlock(e),o=i.useShowLineNumbers(),s=u.useCallback(()=>Rt(t,e,`
|
|
18
|
-
`),[t,e]),l=u.useCallback(()=>Rt(t,e," "),[t,e]),r=u.useCallback(()=>{var w;const v=Pe(t,e);if(!v||v===e)return;const g=t.getBlock(v),y=(w=g==null?void 0:g.contentIds)==null?void 0:w[g.contentIds.length-1];y&&C.focusRunEnd(y)},[t,e]),c=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),d=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),f=u.useCallback(v=>t.applyOperation(i.updateBlockProps(e,{language:v})),[t,e]),m=u.useCallback(()=>dt(t,e),[t,e]),p=i.useBlockClassName("be-code-block",n);if(!n)return null;const h=((b=n.props)==null?void 0:b.language)??"plaintext",k=ne(t,n.contentIds),x=o?(((I=n.contentIds.map(v=>{var g;return((g=t.getRun(v))==null?void 0:g.value)??""}).join("").match(/\n/g))==null?void 0:I.length)??0)+1:0;return a.jsxs("div",{className:p,"data-block-id":e,children:[a.jsxs("div",{className:"be-code-block-header",contentEditable:!1,children:[a.jsx(ye,{className:"be-code-block-language",value:h,options:Js,onChange:f,ariaLabel:"Code language"}),a.jsx("button",{type:"button",className:"be-code-block-delete",onClick:m,"aria-label":"Delete code block",title:"Delete code block",children:a.jsx(i.TrashIcon,{size:14})})]}),a.jsxs("div",{className:"be-code-block-body",children:[o&&a.jsx("div",{className:"be-code-block-gutter",contentEditable:!1,"aria-hidden":"true",children:Array.from({length:x},(v,g)=>a.jsx("span",{children:g+1},g))}),a.jsx("pre",{className:"be-code-block-pre",dir:"ltr",children:a.jsx("code",{"data-empty":k?"":void 0,"data-placeholder":"Empty code block",children:a.jsx(ue,{blockId:e,runIds:n.contentIds,dir:"ltr",onEnter:s,onTab:l,onBackspaceAtStart:r,onArrowUp:c,onArrowDown:d})})})]})]})}function el(e,t){var l;const n=e.contentIds.map(r=>t.store.getRun(r)),o=(l=e.props)==null?void 0:l.language;return`<pre><code${o&&o!=="plaintext"?` data-language="${T.escapeHTML(o)}"`:""}>${n.map(r=>T.runToHTML(r,t)).join("")}</code></pre>`}function tl(e,t){return e.contentIds.map(n=>T.runToPlainText(t.store.getRun(n),t)).join("")}function nl(e,t){var l;const n=(l=e.props)==null?void 0:l.language,o=n&&n!=="plaintext"?n:"",s=e.contentIds.map(r=>{var c;return((c=t.store.getRun(r))==null?void 0:c.value)??""}).join("");return`\`\`\`${o}
|
|
19
|
-
${s}
|
|
20
|
-
\`\`\``}function ol(e,t){var r;if(e.tagName!=="PRE")return null;const n=e.querySelector("code")??e,o=(r=n.getAttribute)==null?void 0:r.call(n,"data-language"),s=i.genId();return{block:{id:i.genId(),type:"code",parentId:null,contentIds:[s],props:o?{language:o}:{}},runs:[{id:s,type:"text",value:n.textContent??"",marks:{}}]}}const An=T.defineBlock({name:"code",contentModel:"runs",component:Zs,defaultProps:{language:"plaintext"},toHTML:el,toPlainText:tl,toMarkdown:nl,fromHTML:ol,slashCommand:{label:"Code",icon:i.CodeIcon,keywords:["code","codeblock","snippet","pre"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("code"))}});function sl(e,t){var n;return t.length===0||t.length===1&&(((n=e.getRun(t[0]))==null?void 0:n.value)??"")===""}function ll(e,t){const n=t.contentIds??[];if(n.length===0)return!0;if(n.length>1)return!1;const o=e.getBlock(n[0]);return!!o&&o.type==="paragraph"&&ne(e,o.contentIds)}function Ue(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function rl(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),s=o.contentIds.indexOf(t),l=n.props.titleRunIds??[],r=sl(e,l)&&ll(e,n);if(s<=0){if(!r)return null;if(o.contentIds.length>1)return Ue(e,[i.removeBlock(t)]),{focusBlockId:e.getBlock(o.id).contentIds[0],needsRefocus:!0};const{block:f,runs:m}=C.createTextLeafBlock("paragraph")(o.id);return Ue(e,[i.insertBlock(f,o.id,s,{blocks:[f],runs:m}),i.removeBlock(t)]),{focusBlockId:f.id,needsRefocus:!0}}const c=o.contentIds[s-1],d=e.getBlock(c);return r?(Ue(e,[i.removeBlock(t)]),{focusBlockId:c,needsRefocus:!0}):Oe(e,d)?(Ue(e,[i.removeBlock(c)]),{focusBlockId:t,needsRefocus:!1}):null}function al(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function cl({id:e}){var I;const t=i.useEditorStore(),n=T.useBlock(e),{setSelectedBlockId:o}=i.useSelectedBlock(),s=u.useCallback(()=>{var w,$;const v=((w=n==null?void 0:n.props)==null?void 0:w.titleRunIds)??[],g=((($=n==null?void 0:n.contentIds)==null?void 0:$.length)??0)>0,y=C.createTextLeafBlock("paragraph");g?C.insertFirstChildSplitAtCaretAndFocus(t,e,v,y):C.insertSiblingSplitAtCaretAndFocus(t,e,v,y)},[t,e,n]),l=u.useCallback(()=>{const v=rl(t,e);!v||!v.needsRefocus||Te(t,v.focusBlockId,e,o)},[t,e,o]),r=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),c=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),d=u.useCallback(()=>{var g,y;if(!((((g=n==null?void 0:n.contentIds)==null?void 0:g.length)??0)>0)){const{block:w,runs:$}=C.createTextLeafBlock("paragraph")(e);al(t,[i.insertBlock(w,e,0,{blocks:[w],runs:$}),i.updateBlockProps(e,{collapsed:!1})]),C.focusRunEnd(w.contentIds[0]);return}t.applyOperation(i.updateBlockProps(e,{collapsed:!((y=n==null?void 0:n.props)!=null&&y.collapsed)}))},[t,e,n==null?void 0:n.contentIds,(I=n==null?void 0:n.props)==null?void 0:I.collapsed]),f=i.useBlockClassName("be-toggle-heading",n);if(!n)return null;const{level:m=2,collapsed:p,titleRunIds:h=[]}=n.props,k=n.contentIds.length>0,x=`h${m}`,b=ce(t,n);return a.jsxs("div",{className:f,"data-block-id":e,dir:b,children:[a.jsxs("div",{className:"be-toggle-heading-row",children:[a.jsx("button",{type:"button",className:"be-toggle-heading-marker",onClick:d,"aria-expanded":!p,"aria-label":k?p?"Expand section":"Collapse section":"Add content to section",children:p?a.jsx(i.ChevronRightIcon,{}):a.jsx(i.ChevronDownIcon,{})}),a.jsx(x,{className:`be-heading be-heading-${m} be-toggle-heading-title`,"data-empty":ne(t,h)?"":void 0,"data-placeholder":`Toggle heading ${m}`,children:a.jsx(ue,{blockId:e,runIds:h,dir:b,onEnter:s,onBackspaceAtStart:l,onArrowUp:r,onArrowDown:c})})]}),!p&&a.jsx("div",{className:"be-toggle-heading-children",children:a.jsx(he,{parentId:e})})]})}function il({level:e=2,collapsed:t=!1}={}){return function(o,s){const l=i.genId(),r=s!=null&&s.length?s:[{id:i.genId(),type:"text",value:"",marks:{}}],{block:c,runs:d}=C.createTextLeafBlock("paragraph")(l);return{block:{id:l,type:"toggleHeading",parentId:o,contentIds:[c.id],props:{level:e,collapsed:t,titleRunIds:r.map(f=>f.id)}},runs:[...r,...d],subtreeBlocks:[c]}}}function ul(e,t){const{titleRunIds:n=[],level:o=2,collapsed:s}=e.props,l=n.map(c=>T.runToHTML(t.store.getRun(c),t)).join(""),r=e.contentIds.map(c=>{const d=t.store.getBlock(c);return t.registry.get(d.type).toHTML(d,t)}).join("");return`<details${s?"":" open"}><summary><h${o}>${l}</h${o}></summary>${r}</details>`}function dl(e,t){const{titleRunIds:n=[]}=e.props,o=n.map(l=>T.runToPlainText(t.store.getRun(l),t)).join(""),s=e.contentIds.map(l=>{const r=t.store.getBlock(l);return t.registry.get(r.type).toPlainText(r,t)}).join(`
|
|
21
|
-
`);return s?`${o}
|
|
22
|
-
${s}`:o}function pl(e,t){const{titleRunIds:n=[],level:o=2}=e.props,s=T.runsToMarkdown(n.map(c=>t.store.getRun(c)),t),l=`${"#".repeat(Math.min(6,o))} ${s}`,r=e.contentIds.map(c=>{const d=t.store.getBlock(c),f=t.registry.get(d.type);return(f.toMarkdown??f.toPlainText)(d,t)}).join(`
|
|
23
|
-
|
|
24
|
-
`);return r?`${l}
|
|
25
|
-
|
|
26
|
-
${r}`:l}function fl(e,t){if(e.tagName!=="DETAILS")return null;const n=[...e.children].find(p=>p.tagName==="SUMMARY"),o=n==null?void 0:n.querySelector("h1,h2,h3,h4,h5,h6"),s=o?Math.min(6,Math.max(1,Number(o.tagName[1]))):2,l=o?ie(o,t):[{id:i.genId(),type:"text",value:"",marks:{}}],r=i.genId(),c=[],d=[],f=[];for(const p of e.children){if(p===n||p.tagName!=="P")continue;const h=ie(p,t),k={id:i.genId(),type:"paragraph",parentId:r,contentIds:h.map(x=>x.id),props:{}};c.push(k),d.push(...h),f.push(k.id)}if(f.length===0){const{block:p,runs:h}=C.createTextLeafBlock("paragraph")(r);c.push(p),d.push(...h),f.push(p.id)}return{block:{id:r,type:"toggleHeading",parentId:null,contentIds:f,props:{level:s,collapsed:!e.hasAttribute("open"),titleRunIds:l.map(p=>p.id)}},runs:[...l,...d],subtreeBlocks:c}}const jn=T.defineBlock({name:"toggleHeading",contentModel:"blocks",component:cl,defaultProps:{level:2,collapsed:!1,titleRunIds:[]},toHTML:ul,toPlainText:dl,toMarkdown:pl,fromHTML:fl,slashCommands:[1,2,3].map(e=>({label:`Toggle heading ${e}`,icon:i.ChevronRightIcon,keywords:["toggle","heading","collapse","section"],run:(t,n)=>C.trimSlashQueryAndInsertAfter(t,n,il({level:e}))}))}),Ze=[{label:"Blue",value:"#2b6fd6"},{label:"Green",value:"#2f9e44"},{label:"Red",value:"#e03131"},{label:"Purple",value:"#9c36b5"},{label:"Gray",value:"#495057"},{label:"Black",value:"#1a1a1a"}];function ml(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function hl({isOpen:e,onClose:t,store:n,blockId:o}){const[s,l]=u.useState(""),[r,c]=u.useState(""),[d,f]=u.useState(Ze[0].value),[m,p]=u.useState([{key:"",value:""}]);u.useEffect(()=>{var g,y,w;if(!e)return;const b=n.getBlock(o);if(!b)return;const I=b.contentIds.map($=>{var O;return((O=n.getRun($))==null?void 0:O.value)??""}).join(""),v=((g=b.props)==null?void 0:g.customAttrs)??[];l(I),c(((y=b.props)==null?void 0:y.href)??""),f(((w=b.props)==null?void 0:w.color)??Ze[0].value),p([...v,{key:"",value:""}])},[e,o,n]);const h=u.useCallback((b,I)=>{p(v=>{const g=v.map((w,$)=>$===b?{...w,...I}:w),y=g[g.length-1];return(y.key.trim()||y.value.trim())&&g.push({key:"",value:""}),g})},[]),k=u.useCallback(b=>{p(I=>I.filter((v,g)=>g!==b))},[]),x=u.useCallback(()=>{const b={id:i.genId(),type:"text",value:s,marks:{}},I=m.filter(v=>v.key.trim());ml(n,[i.setBlockRuns(o,[b]),i.updateBlockProps(o,{href:r.trim(),color:d,customAttrs:I})]),t()},[n,o,s,r,d,m,t]);return a.jsxs(ae.Modal,{isOpen:e,onClose:t,title:"Edit button",children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Label"}),a.jsx("input",{type:"text",value:s,onChange:b=>l(b.target.value),placeholder:"Button"})]}),a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Link URL"}),a.jsx("input",{type:"url",value:r,onChange:b=>c(b.target.value),placeholder:"https://example.com"})]}),a.jsxs("div",{className:"be-modal-field",children:[a.jsx("span",{children:"Color"}),a.jsx("div",{className:"be-modal-color-row",children:Ze.map(b=>a.jsx("button",{type:"button",className:`be-modal-color-swatch${d===b.value?" be-modal-color-swatch-active":""}`,style:{backgroundColor:b.value},title:b.label,"aria-label":b.label,onClick:()=>f(b.value)},b.value))})]}),a.jsxs("div",{className:"be-modal-field",children:[a.jsx("span",{children:"Custom attributes"}),m.map((b,I)=>a.jsxs("div",{className:"be-modal-attr-row",children:[a.jsx("input",{type:"text",placeholder:"name",value:b.key,onChange:v=>h(I,{key:v.target.value})}),a.jsx("input",{type:"text",placeholder:"value",value:b.value,onChange:v=>h(I,{value:v.target.value})}),(b.key||b.value)&&a.jsx("button",{type:"button",className:"be-modal-attr-remove",onClick:()=>k(I),"aria-label":"Remove attribute",children:a.jsx(i.XIcon,{size:14})})]},I))]}),a.jsxs("div",{className:"be-modal-actions",children:[a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:t,children:"Cancel"}),a.jsx("button",{type:"button",className:"be-modal-save",onClick:x,children:"Save"})]})]})}const gl="#2b6fd6";function bl({id:e}){var g,y,w,$;const t=i.useEditorStore(),n=T.useBlock(e),{setSelectedBlockId:o}=i.useSelectedBlock(),[s,l]=u.useState(!1),r=u.useCallback(()=>{C.insertSiblingSplitAtCaretAndFocus(t,e,(n==null?void 0:n.contentIds)??[],C.createTextLeafBlock("paragraph"))},[t,e,n]),c=u.useCallback(()=>{const O=Pe(t,e);Te(t,O,e,o)},[t,e,o]),d=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),f=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),m=u.useCallback(()=>{var j;const O=(j=n==null?void 0:n.props)==null?void 0:j.href;O&&window.open(O,"_blank","noopener,noreferrer")},[(g=n==null?void 0:n.props)==null?void 0:g.href]),p=i.useBlockClassName("be-button-block",n);if(!n)return null;const h=((y=n.props)==null?void 0:y.href)??"",k=((w=n.props)==null?void 0:w.color)??gl,x=(($=n.props)==null?void 0:$.customAttrs)??[],b=ne(t,n.contentIds),I={};for(const{key:O,value:j}of x)O.trim()&&(I[`data-${O.trim()}`]=j);const v=ce(t,n);return a.jsxs("div",{className:p,"data-block-id":e,dir:v,children:[a.jsxs("div",{className:"be-button-block-pill",style:{backgroundColor:k},...I,children:[a.jsx("span",{className:"be-button-block-label","data-empty":b?"":void 0,"data-placeholder":"Button",children:a.jsx(ue,{blockId:e,runIds:n.contentIds,dir:v,onEnter:r,onBackspaceAtStart:c,onArrowUp:d,onArrowDown:f})}),a.jsx("button",{type:"button",className:"be-button-block-open",onClick:m,disabled:!h,title:h||"No link set","aria-label":"Open link",children:"↗"}),a.jsx("button",{type:"button",className:"be-button-block-settings",onClick:()=>l(!0),"aria-label":"Edit button",title:"Edit label, link, color…",children:"⚙"})]}),a.jsx(hl,{isOpen:s,onClose:()=>l(!1),store:t,blockId:e})]})}function kl({href:e="",label:t="Button",color:n="",customAttrs:o=[]}={}){return function(l,r){const c=i.genId(),d=r!=null&&r.length?r:[{id:i.genId(),type:"text",value:t,marks:{}}];return{block:{id:c,type:"button",parentId:l,contentIds:d.map(f=>f.id),props:{href:e,color:n,customAttrs:o}},runs:d}}}const Ln="be-button-block-link";function yl(e,t){var d,f,m;const n=e.contentIds.map(p=>t.store.getRun(p)),o=((d=e.props)==null?void 0:d.href)??"",s=(f=e.props)==null?void 0:f.color,l=s?` style="background-color:${T.escapeAttr(s)}"`:"",c=(((m=e.props)==null?void 0:m.customAttrs)??[]).filter(p=>{var h;return(h=p.key)==null?void 0:h.trim()}).map(p=>` data-${T.escapeAttr(p.key.trim())}="${T.escapeAttr(p.value??"")}"`).join("");return`<a class="${Ln}" href="${T.escapeAttr(o)}"${l}${c}>${n.map(p=>T.runToHTML(p,t)).join("")}</a>`}function Il(e,t){return e.contentIds.map(n=>T.runToPlainText(t.store.getRun(n),t)).join("")}function Cl(e,t){var s;const n=((s=e.props)==null?void 0:s.href)??"";return`[${T.runsToMarkdown(e.contentIds.map(l=>t.store.getRun(l)),t)||n}](${n})`}function xl(e,t){var l;if(e.tagName!=="A"||!e.classList.contains(Ln))return null;const n=ie(e,t),o=[];for(const r of e.attributes)r.name.startsWith("data-")&&o.push({key:r.name.slice(5),value:r.value});return{block:{id:i.genId(),type:"button",parentId:null,contentIds:n.map(r=>r.id),props:{href:e.getAttribute("href")??"",color:((l=e.style)==null?void 0:l.backgroundColor)||void 0,customAttrs:o}},runs:n}}const Nn=T.defineBlock({name:"button",contentModel:"runs",component:bl,defaultProps:{href:"",color:"",customAttrs:[]},toHTML:yl,toPlainText:Il,toMarkdown:Cl,fromHTML:xl,slashCommand:{label:"Button",icon:i.ButtonIcon,keywords:["button","link","cta","action"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,kl())}});function vl(e){return new Promise((t,n)=>{const o=new FileReader;o.onload=()=>t(o.result),o.onerror=()=>n(o.error),o.readAsDataURL(e)})}function At(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Bl(e){return e!=null&&e.startsWith("image/")?"image":e!=null&&e.startsWith("video/")?"video":e!=null&&e.startsWith("audio/")?"audio":"file"}async function En(e,{uploadFile:t,maxFileSize:n,kind:o}){if(t){const l=await t(e,{kind:o});return{src:l.src,name:l.name??e.name,mimeType:l.mimeType??e.type}}if(n&&e.size>n)throw new Error(`This file is ${At(e.size)} — larger than the ${At(n)} limit.`);return{src:await vl(e),name:e.name,mimeType:e.type}}async function Tl(e,t){const n=Bl(e.type),{src:o,name:s,mimeType:l}=await En(e,{...t,kind:n});return{block:{id:i.genId(),type:"embed",parentId:null,contentIds:[],props:{kind:n,src:o,name:s,mimeType:l,align:"left",width:100}},runs:[],subtreeBlocks:[]}}const wl=[{name:"youtube",test:/(?:youtube\.com\/watch\?(?:.*&)?v=|youtu\.be\/|youtube\.com\/shorts\/|youtube\.com\/embed\/)([\w-]{6,})/,embed:e=>`https://www.youtube.com/embed/${e[1]}`},{name:"vimeo",test:/vimeo\.com\/(?:video\/)?(\d+)/,embed:e=>`https://player.vimeo.com/video/${e[1]}`},{name:"loom",test:/loom\.com\/share\/([\w-]+)/,embed:e=>`https://www.loom.com/embed/${e[1]}`},{name:"figma",test:/figma\.com\/(?:file|design|proto)\/[\w-]+/,embed:(e,t)=>`https://www.figma.com/embed?embed_host=noteloom&url=${encodeURIComponent(t)}`},{name:"codepen",test:/codepen\.io\/([\w-]+)\/pen\/([\w-]+)/,embed:e=>`https://codepen.io/${e[1]}/embed/${e[2]}?default-tab=result`},{name:"spotify",test:/open\.spotify\.com\/(track|album|playlist|episode|show)\/([\w]+)/,embed:e=>`https://open.spotify.com/embed/${e[1]}/${e[2]}`}];function Rl(e){if(!e)return null;for(const t of wl){const n=e.match(t.test);if(n)return{provider:t.name,embedUrl:t.embed(n,e)}}return null}const Ke={image:"image",video:"video",audio:"audio",file:"file",oembed:"embed"},Al={image:"image/*",video:"video/*",audio:"audio/*",file:"*/*"},rt=20,at=100,jl=[{value:"left",Icon:i.AlignLeftIcon,label:"Align left"},{value:"center",Icon:i.AlignCenterIcon,label:"Align center"},{value:"right",Icon:i.AlignRightIcon,label:"Align right"}];function et(e){return Math.min(at,Math.max(rt,Math.round(e)))}function Ll({kind:e,src:t,name:n,alt:o,provider:s,onError:l}){return e==="image"?a.jsx("img",{className:"be-embed-image",src:t,alt:o||"",onError:l}):e==="video"?a.jsx("video",{className:"be-embed-video",src:t,controls:!0,onError:l}):e==="audio"?a.jsx("audio",{className:"be-embed-audio",src:t,controls:!0,onError:l}):e==="oembed"?a.jsx("iframe",{className:"be-embed-oembed",src:t,title:s?`${s} embed`:"embed",sandbox:"allow-scripts allow-same-origin allow-presentation allow-popups",allow:"autoplay; encrypted-media; picture-in-picture; fullscreen",allowFullScreen:!0,loading:"lazy"}):a.jsxs("a",{className:"be-embed-file-link",href:t,download:n||void 0,target:"_blank",rel:"noopener noreferrer",children:[a.jsx(i.PaperclipIcon,{size:14})," ",n||t]})}function Nl({id:e}){var we,Re,se,ve,Ae;const t=i.useEditorStore(),n=T.useBlock(e),{uploadFile:o,maxFileSize:s,resolveEmbedSrc:l,onEmbedError:r}=i.useFileUpload(),[c,d]=u.useState(""),[f,m]=u.useState(!1),[p,h]=u.useState(null),[k,x]=u.useState(!1),[b,I]=u.useState(""),[v,g]=u.useState(!1),[y,w]=u.useState(null),$=u.useRef(null),O=u.useRef(null),j=u.useCallback(L=>t.applyOperation(i.updateBlockProps(e,L)),[t,e]),S=u.useCallback(()=>{var L;I(((L=n==null?void 0:n.props)==null?void 0:L.alt)??""),x(!0)},[(we=n==null?void 0:n.props)==null?void 0:we.alt]),E=u.useCallback(()=>x(!1),[]),H=u.useCallback(L=>{L.preventDefault(),j({alt:b.trim()}),x(!1)},[b,j]),B=u.useCallback(async(L,K)=>{w(null),g(!0);try{const{src:F,name:Q,mimeType:R}=await En(L,{uploadFile:o,maxFileSize:s,kind:K});j({src:F,name:Q,mimeType:R})}catch(F){w((F==null?void 0:F.message)||"Upload failed. Please try again.")}finally{g(!1)}},[o,s,j]),A=u.useCallback(L=>{var F,Q;const K=(F=L.target.files)==null?void 0:F[0];L.target.value="",K&&B(K,((Q=n==null?void 0:n.props)==null?void 0:Q.kind)??"file")},[B,(Re=n==null?void 0:n.props)==null?void 0:Re.kind]),M=u.useCallback(L=>{var F,Q;L.preventDefault(),m(!1);const K=(F=L.dataTransfer.files)==null?void 0:F[0];K&&B(K,((Q=n==null?void 0:n.props)==null?void 0:Q.kind)??"file")},[B,(se=n==null?void 0:n.props)==null?void 0:se.kind]),P=u.useCallback(L=>{L.preventDefault(),m(!0)},[]),N=u.useCallback(()=>m(!1),[]),D=u.useCallback(()=>{const L=c.trim();if(!L)return;const K=Rl(L);j(K?{kind:"oembed",src:K.embedUrl,name:L,mimeType:"",provider:K.provider,originalUrl:L}:{src:L,name:L}),d("")},[c,j]),z=u.useCallback(()=>j({src:"",name:"",mimeType:"",provider:"",originalUrl:""}),[j]),G=u.useCallback(L=>{L.preventDefault();const K=$.current,F=O.current;if(!K||!F)return;const Q=K.getBoundingClientRect().width,R=F.getBoundingClientRect().width,q=L.clientX,Z=re=>et((R+(re.clientX-q))/Q*100),pe=re=>h(Z(re)),fe=re=>{document.removeEventListener("mousemove",pe),document.removeEventListener("mouseup",fe),j({width:Z(re)}),h(null)};document.addEventListener("mousemove",pe),document.addEventListener("mouseup",fe)},[j]),te=u.useCallback(L=>{var R;const K=((R=n==null?void 0:n.props)==null?void 0:R.width)??100,F=L.shiftKey?1:5;let Q;if(L.key==="ArrowLeft"||L.key==="ArrowDown")Q=et(K-F);else if(L.key==="ArrowRight"||L.key==="ArrowUp")Q=et(K+F);else if(L.key==="Home")Q=rt;else if(L.key==="End")Q=at;else return;L.preventDefault(),j({width:Q})},[(ve=n==null?void 0:n.props)==null?void 0:ve.width,j]),_=i.useBlockClassName("be-embed",n),V=l((Ae=n==null?void 0:n.props)==null?void 0:Ae.src);if(!n)return null;const{kind:U="file",src:oe,name:X,alt:le="",align:J="left",width:Y=100,provider:xe="",originalUrl:ge=""}=n.props,W=U==="image"||U==="video"||U==="oembed",_e=p??Y,de=U==="oembed",Ye=()=>r==null?void 0:r(oe);return a.jsxs("div",{className:_,"data-block-id":e,"data-kind":U,contentEditable:!1,tabIndex:-1,children:[oe?a.jsx("div",{ref:$,className:`be-embed-preview be-embed-align-${J}`,children:a.jsxs("div",{ref:O,className:"be-embed-frame",style:W?{width:`${_e}%`}:void 0,children:[a.jsxs("div",{className:"be-embed-toolbar",contentEditable:!1,children:[jl.map(({value:L,Icon:K,label:F})=>a.jsx("button",{type:"button",className:`be-embed-toolbar-btn${J===L?" be-embed-toolbar-btn-active":""}`,title:F,"aria-label":F,"aria-pressed":J===L,onClick:()=>j({align:L}),children:a.jsx(K,{size:14})},L)),U==="image"&&a.jsx("button",{type:"button",className:"be-embed-toolbar-btn be-embed-alt-text-btn",onClick:S,children:"Alt text"}),de&&ge&&a.jsx("a",{className:"be-embed-toolbar-btn be-embed-open-original",href:ge,target:"_blank",rel:"noopener noreferrer",title:"Open original link","aria-label":"Open original link",children:a.jsx(i.LinkIcon,{size:14})}),a.jsx("button",{type:"button",className:"be-embed-remove",onClick:z,"aria-label":`Remove ${Ke[U]}`,children:"Remove"})]}),a.jsx(Ll,{kind:U,src:V,name:X,alt:le,provider:xe,onError:Ye}),W&&a.jsx("div",{className:"be-embed-resize-handle",onMouseDown:G,onKeyDown:te,role:"slider",tabIndex:0,"aria-label":`Resize ${Ke[U]}`,"aria-valuemin":rt,"aria-valuemax":at,"aria-valuenow":_e})]})}):a.jsxs("div",{className:`be-embed-dropzone${f?" be-embed-dropzone-active":""}`,onDrop:de||v?void 0:M,onDragOver:de||v?void 0:P,onDragLeave:N,children:[v?a.jsx("span",{className:"be-embed-uploading",children:"Uploading…"}):a.jsxs(a.Fragment,{children:[!de&&a.jsxs(a.Fragment,{children:[a.jsxs("label",{className:"be-embed-upload-btn",children:["Upload ",Ke[U],a.jsx("input",{type:"file",accept:Al[U],onChange:A,hidden:!0})]}),a.jsx("span",{className:"be-embed-dropzone-hint",children:"or drop a file, or paste a URL below"})]}),a.jsxs("div",{className:"be-embed-url-row",children:[a.jsx("input",{type:"text",className:"be-embed-url-input",placeholder:de?"Paste a YouTube, Vimeo, Loom, Figma, CodePen, or Spotify link":`https://... ${Ke[U]} URL`,value:c,onChange:L=>d(L.target.value),onKeyDown:L=>L.key==="Enter"&&D()}),a.jsx("button",{type:"button",className:"be-embed-url-commit",onClick:D,children:"Embed"})]})]}),y&&a.jsxs("div",{className:"be-embed-upload-error",role:"alert",children:[y,a.jsx("button",{type:"button",onClick:()=>w(null),"aria-label":"Dismiss error",children:"×"})]})]}),a.jsx(ae.Modal,{isOpen:k,onClose:E,title:"Alt text",children:a.jsxs("form",{onSubmit:H,children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Describe this image for screen readers"}),a.jsx("input",{type:"text",value:b,onChange:L=>I(L.target.value),placeholder:"e.g. A hand-drawn diagram of the release process",autoFocus:!0})]}),a.jsxs("div",{className:"be-modal-actions",children:[a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:E,children:"Cancel"}),a.jsx("button",{type:"submit",className:"be-modal-save",children:"Save"})]})]})})]})}function El({kind:e="file",src:t="",name:n="",alt:o="",mimeType:s="",align:l="left",width:r=100,provider:c="",originalUrl:d=""}={}){return function(m){return{block:{id:i.genId(),type:"embed",parentId:m,contentIds:[],props:{kind:e,src:t,name:n,alt:o,mimeType:s,align:l,width:r,provider:c,originalUrl:d}},runs:[]}}}const jt={image:i.ImageIcon,video:i.VideoIcon,audio:i.AudioIcon,file:i.PaperclipIcon,oembed:i.LinkIcon},Sn="be-embed-file-link",Mn="be-embed-oembed-link";function Sl(e,t,n){if(e!=="image"&&e!=="video"&&e!=="oembed")return"";const o=[];return n!==100&&o.push(`width:${n}%`),t==="center"?o.push("display:block","margin-left:auto","margin-right:auto"):t==="right"&&o.push("display:block","margin-left:auto"),o.length?` style="${o.join(";")}"`:""}function tt(e){var s,l,r,c;const t=(s=e.style)==null?void 0:s.width,n=t&&t.endsWith("%")?parseInt(t,10):100;let o="left";return((l=e.style)==null?void 0:l.marginLeft)==="auto"&&((r=e.style)==null?void 0:r.marginRight)==="auto"?o="center":((c=e.style)==null?void 0:c.marginLeft)==="auto"&&(o="right"),{align:o,width:Number.isFinite(n)?n:100}}function Ml(e){const{kind:t,src:n,name:o,alt:s="",align:l="left",width:r=100,provider:c="",originalUrl:d=""}=e.props;if(!n)return"<p></p>";const f=Sl(t,l,r);return t==="image"?`<img src="${T.escapeAttr(n)}" alt="${T.escapeAttr(s)}"${f}>`:t==="video"?`<video src="${T.escapeAttr(n)}" controls${f}></video>`:t==="audio"?`<audio src="${T.escapeAttr(n)}" controls></audio>`:t==="oembed"?`<a class="${Mn}" href="${T.escapeAttr(d||n)}" data-embed-url="${T.escapeAttr(n)}" data-embed-provider="${T.escapeAttr(c)}">${T.escapeHTML(d||n)}</a>`:`<a class="${Sn}" href="${T.escapeAttr(n)}">${T.escapeHTML(o||n)}</a>`}function $l(e){const{kind:t,src:n,name:o,originalUrl:s=""}=e.props;return n?t==="oembed"?`[embed: ${s||n}]`:`[${t}: ${o||n}]`:""}function Ol(e){const{kind:t,src:n,name:o,alt:s="",originalUrl:l=""}=e.props;return n?t==="image"?``:t==="oembed"?`[${l||n}](${l||n})`:`[${o||n}](${n})`:""}function Dl(e){return e.tagName==="IMG"?Ee("image",e.getAttribute("src")??"","",{...tt(e),alt:e.getAttribute("alt")??""}):e.tagName==="VIDEO"?Ee("video",e.getAttribute("src")??"","",tt(e)):e.tagName==="AUDIO"?Ee("audio",e.getAttribute("src")??"",""):e.tagName==="A"&&e.classList.contains(Mn)?Ee("oembed",e.getAttribute("data-embed-url")??"","",{...tt(e),provider:e.getAttribute("data-embed-provider")??"",originalUrl:e.getAttribute("href")??""}):e.tagName==="A"&&e.classList.contains(Sn)?Ee("file",e.getAttribute("href")??"",e.textContent??""):null}function Ee(e,t,n,{align:o="left",width:s=100,alt:l="",provider:r="",originalUrl:c=""}={}){return{block:{id:i.genId(),type:"embed",parentId:null,contentIds:[],props:{kind:e,src:t,name:n,alt:l,align:o,width:s,provider:r,originalUrl:c}},runs:[]}}function Lt(e){return(t,{blockId:n,runId:o,sliceStart:s,sliceEnd:l})=>{const r=t.getRun(o),c=(r==null?void 0:r.value)??"";t.applyOperation(i.updateRun(o,{value:c.slice(0,s)+c.slice(l)}));const d=C.insertSiblingAfter(t,n,El({kind:e}));return C.insertSiblingAfterAndFocus(t,d,C.createTextLeafBlock("paragraph")),d}}const $n=T.defineBlock({name:"embed",contentModel:"void",component:Nl,defaultProps:{kind:"file",src:"",name:"",alt:"",mimeType:"",align:"left",width:100,provider:"",originalUrl:""},toHTML:Ml,toPlainText:$l,toMarkdown:Ol,fromHTML:Dl,slashCommands:[...["image","video","audio","file"].map(e=>({label:e.charAt(0).toUpperCase()+e.slice(1),icon:jt[e],keywords:["embed","upload","insert",e],run:Lt(e)})),{label:"Embed link",icon:jt.oembed,keywords:["embed","link","youtube","vimeo","loom","figma","codepen","spotify"],run:Lt("oembed")}]}),ct=new Set;function Pl(e){ct.add(e)}function On(e){return ct.has(e)?(ct.delete(e),!0):!1}function Dn(e,t,n){var c;const o=e.getBlock(t),s=((c=o==null?void 0:o.props)==null?void 0:c.titleRunIds)??(o==null?void 0:o.contentIds)??[],l=s.indexOf(n),r=l>=0?s[l+1]:void 0;if(r){C.focusRunEnd(r);return}C.insertSiblingAfterAndFocus(e,t,C.createTextLeafBlock("paragraph"))}function Hl({id:e,blockId:t}){const n=i.useEditorStore(),o=T.useRun(e),s=u.useRef(null);s.current===null&&(s.current=On(e));const l=u.useCallback(f=>{n.applyOperation(i.updateRun(e,{data:{...o==null?void 0:o.data,selectedValue:f}})),s.current&&Dn(n,t,e)},[n,e,o==null?void 0:o.data,t]);if(!o)return null;const{options:r=[],selectedValue:c="",placeholder:d="Select…"}=o.data??{};return a.jsx("span",{className:"be-inline-select",onMouseDown:f=>{f.preventDefault(),f.stopPropagation()},onKeyDown:f=>f.stopPropagation(),children:a.jsx(ye,{value:c,options:r,onChange:l,placeholder:d,ariaLabel:"Select an option",autoOpen:s.current})})}function Qe(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:s},l,{autoOpen:r=!1}={}){const c=e.getRun(n),d=(c==null?void 0:c.value)??"",f=d.slice(0,o),m=d.slice(s),p=l(),h={...c,value:f},k={id:i.genId(),type:"text",value:m,marks:{...c==null?void 0:c.marks}};e.applyOperation(i.replaceRunSpan(t,[n],[h,p,k])),r?Pl(p.id):C.focusRunEnd(k.id)}function _l(e){return String(e).replace(/&/g,"&").replace(/"/g,""")}function Pn(e){var o;const{options:t=[],selectedValue:n=""}=e.data??{};return((o=t.find(s=>s.value===n))==null?void 0:o.label)??""}function Fl(e){var n,o;const t=Pn(e)||((n=e.data)==null?void 0:n.placeholder)||"";return`<span data-inline-type="select" data-selected-value="${_l(((o=e.data)==null?void 0:o.selectedValue)??"")}">${t}</span>`}function Ul(e){return Pn(e)}function Kl(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="select"?null:{id:i.genId(),type:"select",value:"",marks:{},data:{options:[],selectedValue:e.getAttribute("data-selected-value")??""}}}const Hn=T.defineInline({name:"select",component:Hl,toHTML:Fl,toPlainText:Ul,fromHTML:Kl,slashCommand:{label:"Select",icon:i.SelectIcon,keywords:["select","dropdown","choice","picker"],run:(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:s})=>Qe(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:s},()=>({id:i.genId(),type:"select",value:"",marks:{},data:{options:[],selectedValue:"",placeholder:"Select…"}}),{autoOpen:!0})}});function zl({id:e}){const t=i.useEditorStore(),n=T.useRun(e),o=u.useCallback(l=>{t.applyOperation(i.updateRun(e,{data:{...n==null?void 0:n.data,isoDate:l.target.value}}))},[t,e,n==null?void 0:n.data]);if(!n)return null;const{isoDate:s=""}=n.data??{};return a.jsx("span",{className:"be-inline-date",onMouseDown:l=>l.stopPropagation(),onKeyDown:l=>l.stopPropagation(),children:a.jsx("input",{type:"date",value:s,onChange:o})})}function Gl(e){return String(e).replace(/&/g,"&").replace(/"/g,""")}function _n(e){if(!e)return"";const t=new Date(`${e}T00:00:00`);return Number.isNaN(t.getTime())?e:t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Vl(e){var n;const t=((n=e.data)==null?void 0:n.isoDate)??"";return`<span data-inline-type="date" data-iso-date="${Gl(t)}">${_n(t)}</span>`}function ql(e){var t;return _n(((t=e.data)==null?void 0:t.isoDate)??"")}function Wl(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="date"?null:{id:i.genId(),type:"date",value:"",marks:{},data:{isoDate:e.getAttribute("data-iso-date")??""}}}function Ql(){return new Date().toISOString().slice(0,10)}const Fn=T.defineInline({name:"date",component:zl,toHTML:Vl,toPlainText:ql,fromHTML:Wl,slashCommand:{label:"Date",icon:i.DateIcon,keywords:["date","when","schedule","calendar"],run:(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:s})=>Qe(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:s},()=>({id:i.genId(),type:"date",value:"",marks:{},data:{isoDate:Ql()}}))}});function Yl({id:e}){const t=i.useEditorStore(),n=T.useRun(e),o=u.useCallback(c=>{t.applyOperation(i.updateRun(e,{data:{...n==null?void 0:n.data,checked:c.target.checked}}))},[t,e,n==null?void 0:n.data]),s=u.useCallback(c=>{t.applyOperation(i.updateRun(e,{data:{...n==null?void 0:n.data,label:c.target.value}}))},[t,e,n==null?void 0:n.data]);if(!n)return null;const{checked:l=!1,label:r=""}=n.data??{};return a.jsxs("span",{className:"be-inline-checkbox",onMouseDown:c=>c.stopPropagation(),onKeyDown:c=>c.stopPropagation(),children:[a.jsx("input",{type:"checkbox",className:"be-inline-checkbox-input",checked:l,onChange:o}),a.jsx("input",{type:"text",className:"be-inline-checkbox-label",value:r,onChange:s,placeholder:"Label…"})]})}function Xl(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Jl(e){const{checked:t=!1,label:n=""}=e.data??{};return`<span data-inline-type="checkbox" data-checked="${t}">${t?"☑":"☐"} ${Xl(n)}</span>`}function Zl(e){const{checked:t=!1,label:n=""}=e.data??{};return`${t?"[x]":"[ ]"} ${n}`.trim()}function er(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="checkbox"?null:{id:i.genId(),type:"checkbox",value:"",marks:{},data:{checked:e.getAttribute("data-checked")==="true",label:(e.textContent??"").replace(/^[☑☐]\s*/,"")}}}const Un=T.defineInline({name:"checkbox",component:Yl,toHTML:Jl,toPlainText:Zl,fromHTML:er,slashCommand:{label:"Checkbox",icon:i.CheckboxIcon,keywords:["checkbox","todo","check","toggle"],run:(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:s})=>Qe(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:s},()=>({id:i.genId(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}}))}});function tr({id:e,blockId:t}){var k;const n=i.useEditorStore(),o=T.useRun(e),s=t?n.getBlock(t):null,l=s?n.getBlock(s.parentId):null,r=(l==null?void 0:l.parentId)??null,c=T.useBlock(r),d=l?l.contentIds.indexOf(t):-1,m=(((k=(c&&l?ee(c,l.contentIds.length):[])[d])==null?void 0:k.options)??[]).map((x,b)=>({...x,color:x.color??ze(b)})),p=u.useCallback((x,b)=>{n.applyOperation(i.updateRun(e,{data:{selectedValue:x,selectedLabel:(b==null?void 0:b.label)??""}}))},[n,e]);if(!o)return null;const{selectedValue:h=""}=o.data??{};return a.jsx("span",{className:"be-inline-table-select",onMouseDown:x=>{x.preventDefault(),x.stopPropagation()},onKeyDown:x=>x.stopPropagation(),children:a.jsx(ye,{value:h,options:m,onChange:p,placeholder:"Select…",ariaLabel:"Select an option",variant:"tag"})})}function Kn(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function nr(e){return Kn(e).replace(/"/g,""")}function or(e){const{selectedValue:t="",selectedLabel:n=""}=e.data??{};return`<span data-inline-type="tableSelect" data-selected-value="${nr(t)}">${Kn(n)}</span>`}function sr(e){var t;return((t=e.data)==null?void 0:t.selectedLabel)??""}function lr(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="tableSelect"?null:{id:i.genId(),type:"tableSelect",value:"",marks:{},data:{selectedValue:e.getAttribute("data-selected-value")??"",selectedLabel:e.textContent??""}}}const zn=T.defineInline({name:"tableSelect",component:tr,toHTML:or,toPlainText:sr,fromHTML:lr}),Gn={name:"emoji",kind:"inline"},rr=[$t,Ot,Qt,bn,gn,hn,xn,Cn,vn,Tn,wn,An,jn,Nn,$n,T.canvasBlockType,Hn,Fn,Un,zn,Gn];function ar({exclude:e=[]}={}){const t=new Set(e);return rr.filter(n=>!t.has(n.name))}exports.AGGREGATE_LABELS=en;exports.AGGREGATE_TYPES=Zt;exports.BlockChildren=he;exports.BlockErrorBoundary=Dt;exports.BlockGutterRow=Vt;exports.BlockRenderer=ut;exports.CALLOUT_COLORS=Bn;exports.COLUMN_TYPES=Yt;exports.CommentPopoverHeader=St;exports.DEFAULT_COLUMN_TYPE=He;exports.DEFAULT_COLUMN_WIDTH=qe;exports.EditableBlockContent=ue;exports.LANGUAGES=Rn;exports.LinkEditModal=Et;exports.MIN_COLUMN_WIDTH=be;exports.Select=ye;exports.TableHeaderRow=fn;exports.TurnIntoSubmenu=Ut;exports.announce=me;exports.blankRunForType=Xt;exports.blockquoteBlockType=wn;exports.buttonBlockType=Nn;exports.calloutBlockType=Tn;exports.canMergeTypes=Mt;exports.checkboxInlineType=Un;exports.codeBlockType=An;exports.computeColumnAggregate=tn;exports.consumePendingAutoOpen=On;exports.convertRunToType=Jt;exports.createCellForColumn=We;exports.createDefaultColumns=pt;exports.dateInlineType=Fn;exports.deleteBlockAndFocusSibling=dt;exports.deleteColumn=rn;exports.deleteRow=ln;exports.dividerBlockType=vn;exports.domInlineToRuns=ie;exports.duplicateBlock=Kt;exports.embedBlockType=$n;exports.emojiInlineType=Gn;exports.ensureRootNonEmpty=Ge;exports.focusAfterChip=Dn;exports.formatAggregateValue=nn;exports.headingBlockType=Ot;exports.insertColumnAfter=ot;exports.insertInlineRunAtCursor=Qe;exports.insertRowAfter=sn;exports.isContentlessBlock=Oe;exports.isRunsEmpty=ne;exports.isTurnIntoEligible=_t;exports.layoutBlockType=xn;exports.layoutColumnBlockType=Cn;exports.listItemBlockType=Qt;exports.moveBlockDown=Gt;exports.moveBlockUp=zt;exports.paragraphBlockType=$t;exports.pickTagColor=ze;exports.renameColumn=an;exports.resolveColumns=ee;exports.resolveFileToEmbedInsert=Tl;exports.selectInlineType=Hn;exports.setColumnAggregate=cn;exports.setColumnOptions=Me;exports.setColumnType=un;exports.setColumnWidth=st;exports.sortTableByColumn=lt;exports.starterKit=ar;exports.tableBlockType=bn;exports.tableCellBlockType=hn;exports.tableRowBlockType=gn;exports.tableSelectInlineType=zn;exports.toggleHeadingBlockType=jn;exports.turnBlockInto=Ft;exports.useAutoAdjustedPosition=De;exports.useBlockChildren=it;exports.useFieldTypes=dn;exports.useMenuKeyboardNav=Ve;exports.useVirtualKeyboardInset=pn;
|
|
27
|
-
//# sourceMappingURL=starter-kit-Ch2LEpzF.cjs.map
|