noteloom 0.3.2 → 0.4.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/README.md +344 -53
- package/bin/noteloom.mjs +139 -0
- package/dist/canvas.cjs +2 -0
- package/dist/canvas.cjs.map +1 -0
- package/dist/canvas.d.ts +2 -0
- package/dist/canvas.js +5 -0
- package/dist/canvas.js.map +1 -0
- package/dist/collab.cjs +2 -0
- package/dist/collab.cjs.map +1 -0
- package/dist/collab.d.ts +19 -0
- package/dist/collab.js +379 -0
- package/dist/collab.js.map +1 -0
- package/dist/comments.cjs +2 -0
- package/dist/comments.cjs.map +1 -0
- package/dist/comments.d.ts +17 -0
- package/dist/comments.js +19 -0
- package/dist/comments.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +392 -32
- package/dist/index.js +3983 -0
- package/dist/index.js.map +1 -0
- package/dist/persistence.cjs +2 -0
- package/dist/persistence.cjs.map +1 -0
- package/dist/persistence.d.ts +11 -0
- package/dist/persistence.js +12 -0
- package/dist/persistence.js.map +1 -0
- package/dist/shared/CommentAvatar-TKqsM8vG.js +53 -0
- package/dist/shared/CommentAvatar-TKqsM8vG.js.map +1 -0
- package/dist/shared/CommentAvatar-V457IgoQ.cjs +2 -0
- package/dist/shared/CommentAvatar-V457IgoQ.cjs.map +1 -0
- package/dist/shared/CommentThreadCard-CAJ3oPdr.cjs +2 -0
- package/dist/shared/CommentThreadCard-CAJ3oPdr.cjs.map +1 -0
- package/dist/shared/CommentThreadCard-Cxf8GwHJ.js +213 -0
- package/dist/shared/CommentThreadCard-Cxf8GwHJ.js.map +1 -0
- package/dist/shared/CommentsPanel-BwVVyMOC.js +76 -0
- package/dist/shared/CommentsPanel-BwVVyMOC.js.map +1 -0
- package/dist/shared/CommentsPanel-CES4uzye.cjs +2 -0
- package/dist/shared/CommentsPanel-CES4uzye.cjs.map +1 -0
- package/dist/shared/VersionHistory-Bg6fufP5.js +1120 -0
- package/dist/shared/VersionHistory-Bg6fufP5.js.map +1 -0
- package/dist/shared/VersionHistory-DELa2Wbq.cjs +12 -0
- package/dist/shared/VersionHistory-DELa2Wbq.cjs.map +1 -0
- package/dist/shared/VoiceListeningIndicator-BOfVmLK0.js +338 -0
- package/dist/shared/VoiceListeningIndicator-BOfVmLK0.js.map +1 -0
- package/dist/shared/VoiceListeningIndicator-DNX8JlQM.cjs +2 -0
- package/dist/shared/VoiceListeningIndicator-DNX8JlQM.cjs.map +1 -0
- package/dist/shared/fieldRegistry-BoYyW3GH.cjs +2 -0
- package/dist/shared/fieldRegistry-BoYyW3GH.cjs.map +1 -0
- package/dist/shared/fieldRegistry-PjJWXFoB.js +223 -0
- package/dist/shared/fieldRegistry-PjJWXFoB.js.map +1 -0
- package/dist/shared/icons-C1_s0jKK.js +4269 -0
- package/dist/shared/icons-C1_s0jKK.js.map +1 -0
- package/dist/shared/icons-DtCsXuU6.cjs +3531 -0
- package/dist/shared/icons-DtCsXuU6.cjs.map +1 -0
- package/dist/shared/index-B9jyyL8u.js +2145 -0
- package/dist/shared/index-B9jyyL8u.js.map +1 -0
- package/dist/shared/index-D9WEXpYM.cjs +2 -0
- package/dist/shared/index-D9WEXpYM.cjs.map +1 -0
- package/dist/shared/indexedDbPersistence-BKlGPFTP.js +112 -0
- package/dist/shared/indexedDbPersistence-BKlGPFTP.js.map +1 -0
- package/dist/shared/indexedDbPersistence-BWJ1h5Vp.cjs +2 -0
- package/dist/shared/indexedDbPersistence-BWJ1h5Vp.cjs.map +1 -0
- package/dist/shared/leafBlockFactory-A9eUhSe-.js +335 -0
- package/dist/shared/leafBlockFactory-A9eUhSe-.js.map +1 -0
- package/dist/shared/leafBlockFactory-Dp382eP8.cjs +2 -0
- package/dist/shared/leafBlockFactory-Dp382eP8.cjs.map +1 -0
- package/dist/shared/serialize-DWEfk0vU.cjs +3 -0
- package/dist/shared/serialize-DWEfk0vU.cjs.map +1 -0
- package/dist/shared/serialize-T9Odwx24.js +86 -0
- package/dist/shared/serialize-T9Odwx24.js.map +1 -0
- package/dist/shared/starter-kit-CY5wzYDf.js +4980 -0
- package/dist/shared/starter-kit-CY5wzYDf.js.map +1 -0
- package/dist/shared/starter-kit-lPN-NpJ5.cjs +27 -0
- package/dist/shared/starter-kit-lPN-NpJ5.cjs.map +1 -0
- package/dist/shared/usePopoverEdgeClamp-CDG26jBM.cjs +2 -0
- package/dist/shared/usePopoverEdgeClamp-CDG26jBM.cjs.map +1 -0
- package/dist/shared/usePopoverEdgeClamp-gmFm0CnI.js +109 -0
- package/dist/shared/usePopoverEdgeClamp-gmFm0CnI.js.map +1 -0
- package/dist/shared/useServiceWorkerUpdate-BduabXv6.js +94 -0
- package/dist/shared/useServiceWorkerUpdate-BduabXv6.js.map +1 -0
- package/dist/shared/useServiceWorkerUpdate-DQboGesi.cjs +2 -0
- package/dist/shared/useServiceWorkerUpdate-DQboGesi.cjs.map +1 -0
- package/dist/starter-kit.cjs +2 -0
- package/dist/starter-kit.cjs.map +1 -0
- package/dist/starter-kit.d.ts +9 -0
- package/dist/starter-kit.js +10 -0
- package/dist/starter-kit.js.map +1 -0
- package/dist/style.css +3529 -3200
- package/dist/versions.cjs +2 -0
- package/dist/versions.cjs.map +1 -0
- package/dist/versions.d.ts +11 -0
- package/dist/versions.js +13 -0
- package/dist/versions.js.map +1 -0
- package/dist/voice.cjs +2 -0
- package/dist/voice.cjs.map +1 -0
- package/dist/voice.d.ts +7 -0
- package/dist/voice.js +8 -0
- package/dist/voice.js.map +1 -0
- package/package.json +159 -92
- package/dist/noteloom.cjs +0 -3209
- package/dist/noteloom.cjs.map +0 -1
- package/dist/noteloom.es.js +0 -14622
- package/dist/noteloom.es.js.map +0 -1
|
@@ -0,0 +1,27 @@
|
|
|
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 v=require("./index-D9WEXpYM.cjs"),a=require("react/jsx-runtime"),u=require("react"),be=require("react-dom"),c=require("./icons-DtCsXuU6.cjs"),C=require("./leafBlockFactory-Dp382eP8.cjs"),ae=require("./usePopoverEdgeClamp-CDG26jBM.cjs"),Wn=require("./CommentThreadCard-CAJ3oPdr.cjs"),ht=require("./serialize-DWEfk0vU.cjs");function Nt(e){return e?e.type!=="text"?!1:(e.value??"")==="":!0}function te(e,t){return!t||t.length===0?!0:t.every(n=>Nt(e.getRun(n)))}function Me(e,t){var l,s;if(!t)return!1;const n=t.contentIds.length>0,o=(((s=(l=t.props)==null?void 0:l.titleRunIds)==null?void 0:s.length)??0)>0;return!n&&!o}function Et({isOpen:e,initialHref:t,initialTarget:n,hasExistingLink:o,onSave:l,onRemove:s,onClose:r}){const[i,d]=u.useState(""),[f,m]=u.useState("_self");u.useEffect(()=>{e&&(d(t),m(n))},[e]);const p=i.trim(),h=u.useCallback(k=>{k.preventDefault(),p&&l(p,f)},[p,f,l]);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:i,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:s,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 $e(e,t,n,o){const[l,s]=u.useState(null);return u.useLayoutEffect(()=>{if(n==null||o==null){s(null);return}s({top:n,left:o})},[n,o]),u.useLayoutEffect(()=>{if(!t||!e.current||!l)return;const r=e.current.getBoundingClientRect(),i=ae.clampLeftToViewport(l.left,r.width),d=ae.clampTopToViewport(l.top,r.height);(i!==l.left||d!==l.top)&&s({top:d,left:i})},[t,e,l]),l}function Qn({containerRef:e,store:t}){var g;const[n,o]=u.useState(null),[l,s]=u.useState(!1),r=u.useRef(null),i=u.useRef(null),d=u.useCallback(()=>{r.current&&(clearTimeout(r.current),r.current=null)},[]),f=u.useCallback(()=>{d(),r.current=setTimeout(()=>{o(y=>l?y:null)},250)},[d,l]);u.useEffect(()=>{const y=e.current;if(!y)return;const w=O=>{var _,T,A;const $=(T=(_=O.target).closest)==null?void 0:T.call(_,"[data-run-id]");if(!$||!y.contains($))return;const S=$.dataset.runId,L=t.getRun(S);(A=L==null?void 0:L.marks)!=null&&A.link&&(d(),o(M=>(M==null?void 0:M.runId)===S?M:{runId:S,rect:$.getBoundingClientRect()}))},j=()=>f();return y.addEventListener("mouseover",w),y.addEventListener("mouseout",j),()=>{y.removeEventListener("mouseover",w),y.removeEventListener("mouseout",j)}},[e,t,d,f]),u.useEffect(()=>()=>d(),[d]);const m=u.useCallback(()=>s(!0),[]),p=u.useCallback(()=>{s(!1),o(null)},[]),h=u.useCallback((y,w)=>{if(!n)return;const j=t.getRun(n.runId);j&&(t.applyOperation(c.updateRun(n.runId,{marks:{...j.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(c.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&&!l),B=$e(i,I,n?n.rect.bottom+6:null,n?n.rect.left:null);return a.jsxs(a.Fragment,{children:[I&&B?be.createPortal(a.jsxs("div",{ref:i,className:"be-link-hover-card",contentEditable:!1,style:{position:"fixed",top:B.top,left:B.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(c.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(c.XIcon,{size:13})})]}),document.body):null,a.jsx(Et,{isOpen:l,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(c.XIcon,{size:14})})]})}const Yn='button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';function Xn({containerRef:e,store:t,authorId:n}){const[o,l]=u.useState(null),[s,r]=u.useState(!1),i=u.useRef(null),d=u.useRef(null),f=u.useRef(null),[,m]=c.useHoveredComment(),p=u.useCallback(()=>{i.current&&(clearTimeout(i.current),i.current=null)},[]),h=u.useCallback(()=>{p(),i.current=setTimeout(()=>{l(g=>s?g:null)},250)},[p,s]);u.useEffect(()=>{const g=e.current;if(!g)return;const y=$=>{var _,T,A;const S=(_=$==null?void 0:$.closest)==null?void 0:_.call($,"[data-run-id]");if(!S||!g.contains(S))return null;const L=(A=(T=t.getRun(S.dataset.runId))==null?void 0:T.marks)==null?void 0:A.commentIds;return L!=null&&L.length?{runEl:S,commentIds:L}:null},w=$=>{const S=y($.target);S&&(p(),l(L=>L&&L.runEl===S.runEl?L:{rect:S.runEl.getBoundingClientRect(),commentIds:S.commentIds,runEl:S.runEl}))},j=()=>h(),O=$=>{const S=y($.target);if(!S){r(!1),l(null);return}p(),r(!0),l({rect:S.runEl.getBoundingClientRect(),commentIds:S.commentIds,runEl:S.runEl})};return g.addEventListener("mouseover",w),g.addEventListener("mouseout",j),g.addEventListener("click",O),()=>{g.removeEventListener("mouseover",w),g.removeEventListener("mouseout",j),g.removeEventListener("click",O)}},[e,t,p,h]),u.useEffect(()=>{if(!o)return;const g=w=>{var j,O;(j=d.current)!=null&&j.contains(w.target)||(O=e.current)!=null&&O.contains(w.target)||(r(!1),l(null))},y=w=>{w.key==="Escape"&&(r(!1),l(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),l(null)},[]),x=!!o,b=$e(d,x,o?o.rect.bottom+6:null,o?o.rect.left:null),I=u.useRef(!1);if(u.useEffect(()=>{var g,y;s&&d.current&&!I.current?(I.current=!0,f.current=document.activeElement,(d.current.querySelector(Yn)??d.current).focus()):!s&&I.current&&(I.current=!1,(y=(g=f.current)==null?void 0:g.focus)==null||y.call(g),f.current=null)},[s,b]),!x||!b)return null;const B=o.commentIds.map(g=>t.getComment(g)).filter(Boolean);return B.length===0?null:be.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":s||void 0,"aria-label":`Comments (${B.length})`,tabIndex:-1,children:[a.jsx(St,{title:`Comments (${B.length})`,onClose:k}),B.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=v.useRun(e),[l]=c.useHoveredComment();return u.useLayoutEffect(()=>{var m,p,h,k,x;if(!t||!o)return;const s=o.value??"";(C.stripEmptyRunPlaceholder(t.textContent)!==s||s===""&&t.textContent==="")&&Zn(t,s===""?C.EMPTY_RUN_PLACEHOLDER:s);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",!!l&&!!((k=(h=o.marks)==null?void 0:h.commentIds)!=null&&k.includes(l)));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,l]),null}function bt(e,t,n,o){var p,h,k;const l=(p=window.getSelection)==null?void 0:p.call(window);if(!l||!l.isCollapsed||l.rangeCount===0)return null;const{anchorNode:s,anchorOffset:r}=l;if(!s||!e.contains(s))return null;const i=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 B=n(I);return B&&B.type!=="text"?I:null};if(s===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 B=n(I);return B&&B.type!=="text"?I:null}const d=s.nodeType===1?s:s.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===(s.textContent??"").length)?null:i(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 l=o.getRangeAt(0);if(l.startContainer!==l.endContainer||!e.contains(l.startContainer)||l.endOffset!==l.startOffset+1)return null;const s=l.startContainer.childNodes[l.startOffset],r=(s==null?void 0:s.nodeType)===1?(f=s.dataset)==null?void 0:f.runId:void 0;if(!r||t.indexOf(r)===-1)return null;const i=n(r);return i&&i.type!=="text"?r:null}function yt(e,t,n){var i;if(t===e)return{childIndex:n,charOffset:null};const o=t.nodeType===1?t:t.parentElement,l=(i=o==null?void 0:o.closest)==null?void 0:i.call(o,"[data-run-id]");if(!l||!e.contains(l))return null;const s=Array.prototype.indexOf.call(e.childNodes,l),r=t===l?n===0?0:(l.textContent??"").length:n;return{childIndex:s,charOffset:r}}function to(e,t,n,o){const l=yt(e,o.startContainer,o.startOffset),s=yt(e,o.endContainer,o.endOffset);if(!l||!s)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 i=!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<l.childIndex,b=s.charOffset===null?p>=s.childIndex:p>s.childIndex;if(x||b){d.push(k);return}const I=l.charOffset!==null&&p===l.childIndex,B=s.charOffset!==null&&p===s.childIndex;if(k.type!=="text"){i=!0,f===null&&(f=d.length);return}const g=k.value??"";if(I&&B){const y=g.slice(0,l.charOffset)+g.slice(s.charOffset);y&&d.push({...k,value:y}),f=d.length}else if(I){const y=g.slice(0,l.charOffset);y&&d.push({...k,value:y}),f===null&&(f=d.length)}else if(B){const y=g.slice(s.charOffset);y&&d.push({id:c.genId(),type:"text",value:y,marks:k.marks})}}),i?{nextRuns:d,insertionIndex:f??d.length}:null}function no(e){var s;const t=(s=window.getSelection)==null?void 0:s.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 l=o.nodeType===3&&o.textContent===C.EMPTY_RUN_PLACEHOLDER?1:0;return t.anchorOffset<=l}function oo(e){var s;const t=(s=window.getSelection)==null?void 0:s.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 l=o.nodeType===3?(o.textContent??"").length:0;return t.anchorOffset>=l}function It(e,t,n){const o=e.getBlock(t),l=e.getBlock(o==null?void 0:o.parentId);if(!l)return null;const s=l.contentIds.indexOf(t),r=n==="backward"?s-1:s+1;if(r<0||r>=l.contentIds.length)return null;const i=l.contentIds[r];return Me(e,e.getBlock(i))?i:null}function lo({id:e,blockId:t,host:n,inlineRegistry:o,onValueSynced:l}){const s=v.useRun(e);if(!s)return null;if(s.type==="text")return a.jsx(eo,{id:e,host:n,onValueSynced:l});const r=o==null?void 0:o.get(s.type);if(!r)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No inline type registered for "${s.type}" (run: ${e})`),null;const i=r.component;return a.jsx(i,{id:e,blockId:t})}function so(e,t,n){let o=e.get(n);if(!o){o=document.createElement("span"),o.dataset.runId=n;const l=t.getRun(n);l&&l.type!=="text"&&o.setAttribute("contenteditable","false"),e.set(n,o)}return o}function ue({blockId:e,runIds:t,dir:n="auto",onEnter:o,onBackspaceAtStart:l,onDeleteAtEnd:s,onArrowUp:r,onArrowDown:i,onTab:d,onShiftTab:f,onAutoformat:m}){const p=c.useEditorStore(),h=c.useInlineRegistry(),k=c.useCommentAuthorId(),{getSelectedBlockId:x,setSelectedBlockId:b}=c.useSelectedBlock(),I=u.useRef(null),B=u.useRef(!1),g=u.useRef(new Map);u.useLayoutEffect(()=>{const T=I.current;if(!T)return;const A=new Set(t);for(const[D,E]of g.current)A.has(D)||(E.remove(),g.current.delete(D));let M=null;for(const D of t){const E=g.current.get(D);if(!E)continue;const P=M?M.nextSibling:T.firstChild;P!==E&&T.insertBefore(E,P),M=E}},[t]);const y=u.useCallback(()=>{if(B.current)return;const T=I.current;if(!T)return;const A=t.map(P=>p.getRun(P)).filter(Boolean),{runs:M,changed:D,onlyValueChanges:E}=C.reconcileDomToRuns(T,A);if(D){if(E){if(M.forEach((P,z)=>{P!==A[z]&&p.applyOperation(c.updateRun(P.id,{value:P.value}))}),m!=null&&m(M))return}else p.applyOperation(c.setBlockRuns(e,M.length?M:[{id:c.genId(),type:"text",value:"",marks:{}}]));gt(T,M)}},[p,e,t,m]),w=u.useCallback(()=>{gt(I.current,t.map(T=>p.getRun(T)).filter(Boolean))},[p,t]),j=u.useCallback(()=>{B.current=!0},[]),O=u.useCallback(()=>{B.current=!1,y()},[y]),$=u.useCallback(T=>{const M=t.map(D=>p.getRun(D)).filter(Boolean).filter(D=>D.id!==T);p.applyOperation(c.setBlockRuns(e,M.length?M:[{id:c.genId(),type:"text",value:"",marks:{}}]))},[p,e,t]),S=u.useCallback(T=>{x()===T?(p.applyOperation(c.removeBlock(T)),b(null)):b(T)},[p,x,b]),L=u.useCallback(T=>{var ee,Q,fe,le;if(B.current)return;if(T.target instanceof Node){const W=T.target.nodeType===1?T.target:T.target.parentElement;if((ee=W==null?void 0:W.closest)!=null&&ee.call(W,'[contenteditable="false"]'))return}const A=T.inputType??"",M=A.startsWith("delete"),D=A==="insertText"||A==="insertReplacementText";if(!M&&!D)return;const E=I.current;if(!E)return;const P=(Q=T.getTargetRanges)==null?void 0:Q.call(T),z=(fe=window.getSelection)==null?void 0:fe.call(window),G=(P==null?void 0:P[0])??(z!=null&&z.rangeCount?z.getRangeAt(0):null);if(!G||!E.contains(G.startContainer)||!E.contains(G.endContainer))return;const U=to(E,t,W=>p.getRun(W),G);if(!U)return;T.preventDefault();let{nextRuns:F,insertionIndex:V}=U,ne=null,Z=!1;if(D&&T.data){const W={id:c.genId(),type:"text",value:T.data,marks:{}};F=[...F.slice(0,V),W,...F.slice(V)],ne=W.id,Z=!1}else V>0?(ne=(le=F[V-1])==null?void 0:le.id,Z=!1):F.length>0&&(ne=F[0].id,Z=!0);const X=F.length?F:[{id:c.genId(),type:"text",value:"",marks:{}}];p.applyOperation(c.setBlockRuns(e,X));const se=ne??X[0].id;Z?C.focusRunStart(se):C.focusRunEnd(se)},[p,e,t]);u.useEffect(()=>{const T=I.current;if(T)return T.addEventListener("beforeinput",L),()=>T.removeEventListener("beforeinput",L)},[L]);const _=u.useCallback(T=>{if(!B.current){if(T.key==="Enter"&&o){T.preventDefault(),o(T);return}if(T.key==="Backspace"){const A=I.current,M=A&&kt(A,t,p.getRun.bind(p));if(M){T.preventDefault(),$(M);return}const D=A&&bt(A,t,p.getRun.bind(p),!0);if(D){T.preventDefault(),$(D);return}if(A&&no(A)){if(!te(p,t)){const P=It(p,e,"backward");if(P){T.preventDefault(),S(P);return}}T.preventDefault(),l&&l(T)}return}if(T.key==="Delete"){const A=I.current,M=A&&kt(A,t,p.getRun.bind(p));if(M){T.preventDefault(),$(M);return}const D=A&&bt(A,t,p.getRun.bind(p),!1);if(D){T.preventDefault(),$(D);return}if(A&&oo(A)){const E=It(p,e,"forward");if(E){T.preventDefault(),S(E);return}s&&s(T)}return}if(T.key==="ArrowUp"&&r){T.preventDefault(),r(T);return}if(T.key==="ArrowDown"&&i){T.preventDefault(),i(T);return}T.key==="Tab"&&(T.shiftKey&&f?(T.preventDefault(),f(T)):!T.shiftKey&&d&&(T.preventDefault(),d(T)))}},[o,l,s,r,i,d,f,$,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:j,onCompositionEnd:O,onKeyDown:_,children:t.map(T=>{const A=so(g.current,p,T);return be.createPortal(a.jsx(lo,{id:T,blockId:e,host:A,inlineRegistry:h,onValueSynced:w},T),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:l}=C.createTextLeafBlock("paragraph")(t);return e.applyOperation(c.insertBlock(o,t,0,{blocks:[o],runs:l})),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 Oe(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),l=o.contentIds.indexOf(t),s=n.contentIds.length===0||n.contentIds.length===1&&ao(e,n.contentIds[0]);if(l<=0){if(!s)return null;if(o.contentIds.length>1)return ye(e,[c.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 ye(e,[c.insertBlock(f,o.id,l,{blocks:[f],runs:m}),c.removeBlock(t)]),f.id}const r=o.contentIds[l-1],i=e.getBlock(r);if(s)return ye(e,[c.removeBlock(t)]),r;if(Me(e,i))return ye(e,[c.removeBlock(r)]),t;if(!i||!Mt(i.type,n.type))return null;const d=[...i.contentIds,...n.contentIds];return ye(e,[c.setBlockContentIds(r,d),c.setBlockContentIds(t,[]),c.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),l=o>0?n.contentIds[o-1]:null,s=o!==-1&&o<n.contentIds.length-1?n.contentIds[o+1]:null;ye(e,[c.removeBlock(t.id)]);const r=Ge(e);return l??s??r}function ye(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Ie(e,t,n,o){if(!t||t===n)return;const l=C.resolveBlockLastRun(e,t);if(l){C.focusRunEnd(l);return}o(t),requestAnimationFrame(()=>{var s;(s=document.querySelector(`[data-block-id="${t}"]`))==null||s.focus()})}function ce(e,t){var o,l;if(!t)return"auto";if((o=t.props)!=null&&o.dir)return t.props.dir;const n=e.getBlock(e.getRootId());return((l=n==null?void 0:n.props)==null?void 0:l.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 l of uo){const s=l.re.exec(o);if(!s)continue;const r=o.slice(s[0].length),{ops:i}=ae.convertBlockType(e,t,l.type,l.props(s),[n[0].id]);return io(e,[c.updateRun(n[0].id,{value:r}),...i]),C.focusRunStart(n[0].id),!0}return!1}const fo=new Set(["callout","toggleHeading"]);function mo({id:e}){const t=c.useEditorStore(),n=v.useBlock(e),{setSelectedBlockId:o}=c.useSelectedBlock(),l=u.useCallback(()=>{const h=t.getBlock(n==null?void 0:n.parentId),k=te(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]),s=u.useCallback(()=>{var I,B;const h=t.getBlock(n==null?void 0:n.parentId),k=te(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=((B=h.props)==null?void 0:B.titleRunIds)??[],y=g[g.length-1];y&&C.focusRunEnd(y);return}const b=Oe(t,e);Ie(t,b,e,o)},[t,e,n,o]),r=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),i=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),d=u.useCallback(h=>po(t,e,h),[t,e]),f=c.useBlockClassName("be-paragraph",n);if(!n)return null;const m=te(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:l,onBackspaceAtStart:s,onArrowUp:r,onArrowDown:i,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=[],l=(s,r)=>{var f,m;if(s.nodeType===3){const p=s.textContent;p&&o.push({id:c.genId(),type:"text",value:p,marks:{...r}});return}if(s.nodeType!==1)return;if(t!=null&&t.inlineRegistry)for(const p of t.inlineRegistry.listHtmlMatchers()){const h=p.fromHTML(s,t);if(h){o.push(h);return}}let i=r;const d=ho[s.tagName];d&&(i={...i,[d]:!0}),s.tagName==="A"&&s.getAttribute("href")&&(i={...i,link:{href:s.getAttribute("href"),target:s.getAttribute("target")==="_blank"?"_blank":"_self"}}),(f=s.style)!=null&&f.color&&(i={...i,color:s.style.color}),(m=s.style)!=null&&m.backgroundColor&&(i={...i,highlight:s.style.backgroundColor});for(const p of s.childNodes)l(p,i)};return l(e,n),o.length?o:[{id:c.genId(),type:"text",value:"",marks:{}}]}function go(e,t){return`<p>${e.contentIds.map(o=>t.store.getRun(o)).map(o=>v.runToHTML(o,t)).join("")}</p>`}function bo(e,t){return e.contentIds.map(n=>v.runToPlainText(t.store.getRun(n),t)).join("")}function ko(e,t){return v.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:c.genId(),type:"paragraph",parentId:null,contentIds:n.map(l=>l.id),props:{}},runs:n}}const $t=v.defineBlock({name:"paragraph",component:mo,contentModel:"runs",defaultProps:{},toHTML:go,toPlainText:bo,toMarkdown:ko,fromHTML:yo,slashCommand:{label:"Text",icon:c.TextIcon,keywords:["paragraph","text","p"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("paragraph"))}});function Io({id:e}){var k;const t=c.useEditorStore(),n=v.useBlock(e),{setSelectedBlockId:o}=c.useSelectedBlock(),l=u.useCallback(()=>{C.insertSiblingSplitAtCaretAndFocus(t,e,(n==null?void 0:n.contentIds)??[],C.createTextLeafBlock("paragraph"))},[t,e,n]),s=u.useCallback(()=>{const x=Oe(t,e);Ie(t,x,e,o)},[t,e,o]),r=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),i=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),d=((k=n==null?void 0:n.props)==null?void 0:k.level)??3,f=c.useBlockClassName(`be-heading be-heading-${d}`,n);if(!n)return null;const m=`h${d}`,p=te(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:l,onBackspaceAtStart:s,onArrowUp:r,onArrowDown:i})})}const Xe={1:c.Heading1Icon,2:c.Heading2Icon,3:c.Heading3Icon},Co={H1:1,H2:2,H3:3};function xo(e,t){var l;const n=((l=e.props)==null?void 0:l.level)??3,o=e.contentIds.map(s=>t.store.getRun(s));return`<h${n}>${o.map(s=>v.runToHTML(s,t)).join("")}</h${n}>`}function Bo(e,t){return e.contentIds.map(n=>v.runToPlainText(t.store.getRun(n),t)).join("")}function vo(e,t){var l;const n=((l=e.props)==null?void 0:l.level)??3,o=v.runsToMarkdown(e.contentIds.map(s=>t.store.getRun(s)),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:c.genId(),type:"heading",parentId:null,contentIds:o.map(s=>s.id),props:{level:n}},runs:o}}const Ot=v.defineBlock({name:"heading",contentModel:"runs",component:Io,defaultProps:{level:3},toHTML:xo,toPlainText:Bo,toMarkdown:vo,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=c.useEditorStore(),n=u.useCallback(l=>t.subscribe(e,l),[t,e]),o=u.useCallback(()=>{const l=t.getBlock(e);return l?l.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 l,s;process.env.NODE_ENV!=="production"&&console.error("[block-editor] a block failed to render; recovering by remounting it:",n,o),(s=(l=this.props).onError)==null||s.call(l,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=v.useBlock(t),o=c.useBlockRegistry();if(!n)return null;const l=o.get(n.type);if(!l)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No block type registered for "${n.type}" (id: ${t})`),null;const s=l.component;return a.jsx(Dt,{children:a.jsx(s,{id:t})})});function Ve(e,t,n,o){const l=u.useRef(!1),s=u.useRef(!1);u.useEffect(()=>{var m,p;if(!t){s.current=!1,l.current&&(l.current=!1,(p=(m=o==null?void 0:o.current)==null?void 0:m.focus)==null||p.call(m));return}l.current=!0;const r=e.current;if(!r)return;const i=()=>Array.from(r.querySelectorAll('[role="menuitem"]')),d=h=>{var b;const k=i();if(k.length===0)return;const x=(h%k.length+k.length)%k.length;(b=k[x])==null||b.focus()};s.current||(s.current=!0,d(0));const f=h=>{if(h.key==="Escape"){h.preventDefault(),n();return}const k=i(),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 de(e){const t=Ro();t&&(t.textContent="",setTimeout(()=>{t.textContent=e},0))}const ke="💡",Pt="gray";function Ao({icon:e=ke,color:t=Pt}={}){return function(o){const l=c.genId(),{block:s,runs:r}=C.createTextLeafBlock("paragraph")(l);return{block:{id:l,type:"callout",parentId:o,contentIds:[s.id],props:{icon:e,color:t}},runs:r,subtreeBlocks:[s]}}}const Ht=[{type:"paragraph",props:{},label:"Text",icon:c.TextIcon},{type:"heading",props:{level:1},label:"Heading 1",icon:c.Heading1Icon},{type:"heading",props:{level:2},label:"Heading 2",icon:c.Heading2Icon},{type:"heading",props:{level:3},label:"Heading 3",icon:c.Heading3Icon},{type:"listItem",props:{ordered:!1,titleRunIds:[]},label:"Bulleted list",icon:c.BulletedListIcon},{type:"listItem",props:{ordered:!0,titleRunIds:[]},label:"Numbered list",icon:c.NumberedListIcon},{type:"listItem",props:{ordered:!1,checked:!1,titleRunIds:[]},label:"To-do list",icon:c.CheckboxIcon},{type:"listItem",props:{ordered:!1,collapsed:!1,titleRunIds:[]},label:"Toggle list",icon:c.ChevronRightIcon},{type:"toggleHeading",props:{level:2,collapsed:!1,titleRunIds:[]},label:"Toggle heading",icon:c.ChevronRightIcon},{type:"blockquote",props:{},label:"Quote",icon:c.QuoteIcon},{type:"callout",props:{icon:ke},label:"Callout",icon:c.CalloutIcon},{type:"code",props:{language:"plaintext"},label:"Code",icon:c.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 l=e.getBlock(n),s=Lo(l,t),r=[];if(o.type==="code")for(const m of s){const p=e.getRun(m);p!=null&&p.marks&&Object.keys(p.marks).length>0&&r.push(c.updateRun(m,{marks:{}}))}const i={...o.props},{ops:d,newBlockId:f}=ae.convertBlockType(e,n,o.type,i,s,t);return{ops:[...r,...d],newBlockId:f}}function Ut({onSelect:e,onClose:t,containerRef:n,menuClassName:o="be-block-gutter-menu",itemClassName:l="be-block-gutter-menu-item"}){const[s,r]=u.useState(!1),[i,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]);v.useOutsideClickAndEscape([f,m],s,h),Ve(m,s,h,f);const k=$e(m,s,i==null?void 0:i.top,i?i.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"&&!s&&(g.preventDefault(),x())},[s,x]),B=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:l,"aria-haspopup":"menu","aria-expanded":s,onClick:()=>s?h():x(),onKeyDown:I,children:[a.jsx(c.ChevronRightIcon,{size:15})," Turn into"]}),s&&k&&be.createPortal(a.jsx("div",{ref:p,role:"menu","aria-label":"Turn into",className:o,style:{position:"fixed",top:k.top,left:k.left},onKeyDown:B,children:Ht.map((g,y)=>{const w=g.icon;return a.jsxs("button",{type:"button",role:"menuitem",className:l,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),l=o.contentIds.indexOf(t),s=ht.captureSubtree(e,t),{block:r,runs:i,subtreeBlocks:d}=ht.remapSubtreeIds(s);return e.applyOperation(c.insertBlock(r,o.id,l+1,{blocks:[r,...d],runs:i})),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 l=o.contentIds.indexOf(t);return l<=0?!1:(e.applyOperation(c.moveBlock(t,o.id,l-1)),!0)}function Gt(e,t){const n=e.getBlock(t),o=n&&e.getBlock(n.parentId);if(!o)return!1;const l=o.contentIds.indexOf(t);return l===-1||l>=o.contentIds.length-1?!1:(e.applyOperation(c.moveBlock(t,o.id,l+1)),!0)}function dt(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),l=o.contentIds.indexOf(t),s=l>0?o.contentIds[l-1]:null,r=l!==-1&&l<o.contentIds.length-1?o.contentIds[l+1]:null;e.applyOperation(c.removeBlock(t));const i=Ge(e),d=s??r??i;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 T;const t=c.useEditorStore(),n=c.useBlockRegistry(),o=v.useBlock(e),[l,s]=u.useState(!1),[r,i]=u.useState(null),d=u.useRef(null),f=u.useRef(null),m=u.useRef(null),p=u.useMemo(()=>[d,f,m],[]),[h]=c.useBlockRangeSelection(),k=h.includes(e),x=u.useCallback(()=>s(!1),[]);v.useOutsideClickAndEscape(p,l,x),Ve(f,l,x,d);const b=u.useCallback(()=>{var A;i(((A=d.current)==null?void 0:A.getBoundingClientRect())??null),s(!0)},[]),I=$e(f,l,(r==null?void 0:r.bottom)!=null?r.bottom+4:null,r==null?void 0:r.left),B=u.useCallback(()=>{C.insertSiblingAfterAndFocus(t,e,C.createTextLeafBlock("paragraph"))},[t,e]),g=u.useCallback(()=>{Kt(t,e),de("Block duplicated"),x()},[t,e,x]),y=u.useCallback(()=>{zt(t,e)&&de("Block moved up"),x()},[t,e,x]),w=u.useCallback(()=>{Gt(t,e)&&de("Block moved down"),x()},[t,e,x]),j=u.useCallback(()=>{dt(t,e),de("Block deleted"),x()},[t,e,x]),O=!!((T=o==null?void 0:o.props)!=null&&T.hidden),$=u.useCallback(()=>{t.applyOperation(c.updateBlockProps(e,{hidden:!O})),de(O?"Block shown in preview":"Block hidden in preview"),x()},[t,e,O,x]),S=ce(t,o)==="rtl",L=u.useCallback(()=>{t.applyOperation(c.updateBlockProps(e,{dir:S?"ltr":"rtl"})),de(S?"Block set to left-to-right":"Block set to right-to-left"),x()},[t,e,S,x]),_=u.useCallback(A=>{const{ops:M}=Ft(t,n,e,A);No(t,M),de(`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${l?" be-block-gutter-active":""}`,contentEditable:!1,children:[a.jsx("button",{type:"button",className:"be-block-gutter-btn",onClick:B,"aria-label":"Add block below",children:a.jsx(c.PlusIcon,{size:16})}),a.jsx("button",{ref:d,type:"button",className:"be-block-gutter-btn","aria-label":"More options","aria-haspopup":"menu","aria-expanded":l,onClick:()=>l?x():b(),children:a.jsx(c.GripVerticalIcon,{size:16})})]}),a.jsx("div",{className:"be-block-row-content",children:a.jsx(ut,{id:e})}),l&&I&&be.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(c.CopyIcon,{size:15})," Duplicate"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:y,children:[a.jsx(c.ArrowUpIcon,{size:15})," Move up"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:w,children:[a.jsx(c.ArrowDownIcon,{size:15})," Move down"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:$,children:[O?a.jsx(c.EyeIcon,{size:15}):a.jsx(c.EyeOffIcon,{size:15}),O?"Show in preview":"Hide in preview"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:L,children:[S?a.jsx(c.AlignLeftIcon,{size:15}):a.jsx(c.AlignRightIcon,{size:15}),S?"Switch to left-to-right":"Switch to right-to-left"]}),_t(o.type)&&a.jsx(Ut,{onSelect:_,onClose:()=>{},containerRef:m}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item be-block-gutter-menu-item-danger",onClick:j,children:[a.jsx(c.TrashIcon,{size:15})," Delete"]})]}),document.body)]}):null}function pe({parentId:e,isTopLevel:t=!1,filterIds:n}){const o=it(e),l=c.useEditorStore(),[s]=c.usePreviewMode(),r=n??o,i=s?r.filter(d=>{var f,m;return!((m=(f=l.getBlock(d))==null?void 0:f.props)!=null&&m.hidden)}):r;return t&&!s?i.map(d=>a.jsx(Vt,{id:d},d)):i.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,l]of So)for(;n>=o;)t+=l,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 Bt(e,t){let n=0,o=t;for(;o;){const l=e.getBlock(o.parentId);if(!l||l.type!=="listItem")break;n+=1,o=l}return n}function Do(e,t,n){const o=n.indexOf(t.id);let l=1;for(let s=o-1;s>=0;s-=1){const r=e.getBlock(n[s]);if(!Oo(r)||!r.props.ordered)break;l+=1}return l}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 Ne({ordered:e=!1,checked:t,collapsed:n}={}){return function(l,s){const r=c.genId(),i=s!=null&&s.length?s:[{id:c.genId(),type:"text",value:"",marks:{}}],d={ordered:e,titleRunIds:i.map(h=>h.id)};t!==void 0&&(d.checked=t);let f=[],m=[],p=i;if(n!==void 0){d.collapsed=n;const{block:h,runs:k}=C.createTextLeafBlock("paragraph")(r);f=[h.id],m=[h],p=[...i,...k]}return{block:{id:r,type:"listItem",parentId:l,contentIds:f,props:d},runs:p,subtreeBlocks:m}}}function Fo(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId),l=o.contentIds.indexOf(t),s=l>0?o.contentIds[l-1]:null,r=s?e.getBlock(s):null;if(!r||r.type!=="listItem"){C.focusAdjacentBlock(e,t,"down");return}e.applyOperation(c.moveBlock(t,s,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 l=o.parentId,r=e.getBlock(l).contentIds.indexOf(o.id);e.applyOperation(c.moveBlock(t,l,r+1)),C.focusBlockStart(e,t)}function Ae(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"&&te(e,o.contentIds)}function Ko(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),l=o.contentIds.indexOf(t),s=n.props.titleRunIds??[],i=qt(e,s)&&Uo(e,n);if(l>0){const m=o.contentIds[l-1],p=e.getBlock(m);if(i)return Ae(e,[c.removeBlock(t)]),{focusBlockId:m,needsRefocus:!0};if(Me(e,p))return Ae(e,[c.removeBlock(m)]),{focusBlockId:t,needsRefocus:!1};if((p==null?void 0:p.type)==="listItem"&&n.contentIds.length===0){const h=[...p.props.titleRunIds??[],...s];return Ae(e,[c.updateBlockProps(m,{titleRunIds:h}),c.updateBlockProps(t,{titleRunIds:[]}),c.removeBlock(t)]),{focusBlockId:m,needsRefocus:!0}}return null}if(o.type==="listItem")return nt(e,t),{focusBlockId:t,needsRefocus:!0};if(!i)return null;if(o.contentIds.length>1)return Ae(e,[c.removeBlock(t)]),{focusBlockId:e.getBlock(o.id).contentIds[0],needsRefocus:!0};const{block:d,runs:f}=C.createTextLeafBlock("paragraph")(o.id);return Ae(e,[c.insertBlock(d,o.id,l,{blocks:[d],runs:f}),c.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,s=e.getBlock(o).contentIds.indexOf(t),{block:r,runs:i}=C.createTextLeafBlock("paragraph")(o);return zo(e,[c.insertBlock(r,o,s,{blocks:[r],runs:i}),c.updateBlockProps(t,{titleRunIds:[]}),c.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 $,S;const t=c.useEditorStore(),n=v.useBlock(e),{setSelectedBlockId:o}=c.useSelectedBlock(),l=it(n==null?void 0:n.parentId),s=u.useCallback(()=>{var P,z,G,U,F;const L=((P=n==null?void 0:n.props)==null?void 0:P.titleRunIds)??[],_=t.getBlock(n==null?void 0:n.parentId),T=qt(t,L);if(T&&(_==null?void 0:_.type)==="listItem"){nt(t,e);return}const A=(((z=n==null?void 0:n.contentIds)==null?void 0:z.length)??0)>0;if(T&&(_==null?void 0:_.type)!=="listItem"&&!A){Go(t,e);return}const M=((G=n==null?void 0:n.props)==null?void 0:G.checked)!==void 0,D=((U=n==null?void 0:n.props)==null?void 0:U.collapsed)!==void 0,E=Ne({ordered:(F=n==null?void 0:n.props)==null?void 0:F.ordered,checked:M?!1:void 0,collapsed:D?!1:void 0});A&&!D?C.insertFirstChildSplitAtCaretAndFocus(t,e,L,E):C.insertSiblingSplitAtCaretAndFocus(t,e,L,E)},[t,e,n]),r=u.useCallback(()=>Fo(t,e),[t,e]),i=u.useCallback(()=>nt(t,e),[t,e]),d=u.useCallback(()=>{const L=Ko(t,e);!L||!L.needsRefocus||Ie(t,L.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 L;t.applyOperation(c.updateBlockProps(e,{checked:!((L=n==null?void 0:n.props)!=null&&L.checked)}))},[t,e,($=n==null?void 0:n.props)==null?void 0:$.checked]),h=u.useCallback(()=>{var _,T;if(!((((_=n==null?void 0:n.contentIds)==null?void 0:_.length)??0)>0)){const{block:A,runs:M}=C.createTextLeafBlock("paragraph")(e);Vo(t,[c.insertBlock(A,e,0,{blocks:[A],runs:M}),c.updateBlockProps(e,{collapsed:!1})]),C.focusRunEnd(A.contentIds[0]);return}t.applyOperation(c.updateBlockProps(e,{collapsed:!((T=n==null?void 0:n.props)!=null&&T.collapsed)}))},[t,e,n==null?void 0:n.contentIds,(S=n==null?void 0:n.props)==null?void 0:S.collapsed]),k=c.useBlockClassName("be-list-item",n);if(!n)return null;const{ordered:x,checked:b,collapsed:I,titleRunIds:B=[]}=n.props,g=b!==void 0,y=!g&&I!==void 0,w=n.contentIds.length>0,j=B.map(L=>t.getRun(L)).filter(L=>(L==null?void 0:L.type)==="text").map(L=>L.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":j||"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(c.ChevronRightIcon,{}):a.jsx(c.ChevronDownIcon,{})}):a.jsx("span",{className:"be-list-marker","aria-hidden":"true",children:x?Po(Bt(t,n),Do(t,n,l)):_o(Bt(t,n))}),a.jsx("div",{className:"be-list-item-title","data-empty":te(t,B)?"":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:B,dir:O,onEnter:s,onTab:r,onShiftTab:i,onBackspaceAtStart:d,onArrowUp:f,onArrowDown:m})})]}),(!y||!I)&&a.jsx("div",{className:"be-list-item-children",children:a.jsx(pe,{parentId:e})})]})}function Wo(e,t){const{titleRunIds:n=[],ordered:o}=e.props,l=n.map(i=>v.runToHTML(t.store.getRun(i),t)).join(""),s=e.contentIds.map(i=>t.registry.get(t.store.getBlock(i).type).toHTML(t.store.getBlock(i),t)).join(""),r=s?`<${o?"ol":"ul"}>${s}</${o?"ol":"ul"}>`:"";return`<li>${l}${r}</li>`}function Qo(e,t){const{titleRunIds:n=[]}=e.props;return n.map(o=>v.runToPlainText(t.store.getRun(o),t)).join("")}function Yo(e,t){const{titleRunIds:n=[],ordered:o,checked:l}=e.props,s=l!==void 0?l?"- [x] ":"- [ ] ":o?"1. ":"- ",r=v.runsToMarkdown(n.map(d=>t.store.getRun(d)),t),i=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 i?`${s}${r}
|
|
5
|
+
${i}`:`${s}${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 l=e.ownerDocument.createElement("span");for(const p of n)l.appendChild(p.cloneNode(!0));const s=ie(l,t),r=c.genId(),i=[...s],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),i.push(...x.runs),f.push(x.block.id)}}return{block:{id:r,type:"listItem",parentId:null,contentIds:f,props:{ordered:!1,titleRunIds:s.map(p=>p.id)}},runs:i,childBlocks:d}}function Xo(e,t){if(e.tagName!=="LI")return null;const{block:n,runs:o,childBlocks:l}=Wt(e,t);return{block:n,runs:o,subtreeBlocks:l}}const Qt=v.defineBlock({name:"listItem",contentModel:"blocks",component:qo,defaultProps:{ordered:!1,titleRunIds:[]},toHTML:Wo,toPlainText:Qo,toMarkdown:Yo,fromHTML:Xo,slashCommands:[{label:"Bulleted list",icon:c.BulletedListIcon,keywords:["list","bullet","ul"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Ne({ordered:!1}))},{label:"Numbered list",icon:c.NumberedListIcon,keywords:["list","number","ordered","ol"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Ne({ordered:!0}))},{label:"To-do list",icon:c.CheckboxIcon,keywords:["todo","checkbox","task","checklist"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Ne({ordered:!1,checked:!1}))},{label:"Toggle list",icon:c.ChevronRightIcon,keywords:["toggle","collapse","expand","dropdown","accordion"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Ne({ordered:!1,collapsed:!1}))}]}),Yt=["text","date","checkbox","select"],De="text",qe=160,me=80;function Jo(e){return`Column ${e+1}`}function pt(e){return Array.from({length:e},(t,n)=>({id:c.genId(),label:Jo(n),type:De,width:qe}))}function J(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(l=>{const s=l.type??De,r=l.width??qe;return s===l.type&&r===l.width?l:{...l,type:s,width:r}})}function Xt(e){switch(e){case"date":return{id:c.genId(),type:"date",value:"",marks:{},data:{isoDate:""}};case"checkbox":return{id:c.genId(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}};case"select":return{id:c.genId(),type:"tableSelect",value:"",marks:{},data:{selectedValue:"",selectedLabel:""}};default:return{id:c.genId(),type:"text",value:"",marks:{}}}}function We(e,t){const n=Xt(t==null?void 0:t.type);return{block:{id:c.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 l=n==null?void 0:n.get(e.type);o=l!=null&&l.toPlainText?l.toPlainText(e):""}if(t==="date"){const l=o?new Date(o):null,s=l&&!Number.isNaN(l.getTime())?l.toISOString().slice(0,10):"";return{id:c.genId(),type:"date",value:"",marks:{},data:{isoDate:s}}}return t==="checkbox"?{id:c.genId(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:o}}:{id:c.genId(),type:"text",value:o,marks:{}}}function Se(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,l,s;return t==="date"?((o=e==null?void 0:e.data)==null?void 0:o.isoDate)??"":t==="checkbox"?(l=e==null?void 0:e.data)!=null&&l.checked?1:0:t==="select"?(((s=e==null?void 0:e.data)==null?void 0:s.selectedLabel)??"").trim():Se(e,n).trim()}function el(e,t,n){if(n==="checkbox")return e-t;const o=Number(e),l=Number(t);return e!==""&&t!==""&&!Number.isNaN(o)&&!Number.isNaN(l)?o-l:String(e).localeCompare(String(t),void 0,{sensitivity:"base"})}function tl(e,t,n,o){const l=e.map(({rowId:r,run:i})=>({rowId:r,key:Zo(i,t,o)})),s=r=>r===""||r==null;return l.sort((r,i)=>{const d=s(r.key),f=s(i.key);if(d&&f)return 0;if(d)return 1;if(f)return-1;const m=el(r.key,i.key,t);return n==="desc"?-m:m}),l.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"},nl={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 l=e.map(r=>Se(r,o).trim());if(n==="count-values")return l.filter(r=>r!=="").length;if(n==="count-empty")return l.filter(r=>r==="").length;const s=l.map(Number).filter((r,i)=>l[i]!==""&&!Number.isNaN(r));return s.length===0?null:n==="sum"?s.reduce((r,i)=>r+i,0):n==="average"?s.reduce((r,i)=>r+i,0)/s.length:n==="min"?Math.min(...s):n==="max"?Math.max(...s):null}function nn(e){return e==null?"":Number.isInteger(e)?String(e):e.toFixed(2)}function he(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);he(e,[c.removeBlock(t.id)]);const l=Ge(e);if(l)return C.focusBlockStart(e,l),null;const s=e.getBlock(t.parentId),r=s.contentIds[o]??s.contentIds[o-1];return r&&C.focusBlockStart(e,r),null}function ln(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId),l=o.contentIds.indexOf(t),s=J(o,n.contentIds.length),r=c.genId(),i=[],d=[],f=[];for(const p of s){const h=We(r,p);i.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(c.insertBlock(m,o.id,l+1,{blocks:[m,...i],runs:d})),C.focusBlockStart(e,r),r}function sn(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId);if(o.contentIds.length<=1)return on(e,o);const l=o.contentIds.indexOf(t);he(e,[c.removeBlock(t)]);const s=e.getBlock(o.id),r=Math.min(l,s.contentIds.length-1),i=s.contentIds[r];return i&&C.focusBlockStart(e,i),i??null}function ot(e,t,n){const o=e.getBlock(t),l=J(o,o.contentIds[0]?e.getBlock(o.contentIds[0]).contentIds.length:0),s={id:c.genId(),label:"New Column",type:De,width:qe},r=[];let i=null;for(const f of o.contentIds){const m=We(f,s);i===null&&(i=m.block.id),r.push(c.insertBlock(m.block,f,n+1,{blocks:[m.block],runs:[m.run]}))}const d=[...l];return d.splice(n+1,0,s),r.push(c.updateBlockProps(t,{columns:d})),he(e,r),i&&C.focusBlockStart(e,i),i}function rn(e,t,n){const o=e.getBlock(t),l=e.getBlock(o.contentIds[0]);if(!l||l.contentIds.length<=1)return on(e,o);const s=J(o,l.contentIds.length),r=o.contentIds.map(p=>{const h=e.getBlock(p);return c.removeBlock(h.contentIds[n])}),i=s.filter((p,h)=>h!==n);r.push(c.updateBlockProps(t,{columns:i})),he(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 lt(e,t,n,o){const l=e.getBlock(t),s=e.getBlock(l.contentIds[0]),r=J(l,s?s.contentIds.length:0);if(!r[n])return;const i=[...r];i[n]={...r[n],width:Math.max(me,Math.round(o))},e.applyOperation(c.updateBlockProps(t,{columns:i}))}function an(e,t,n,o){const l=e.getBlock(t),s=e.getBlock(l.contentIds[0]),i=[...J(l,s?s.contentIds.length:0)];i[n]&&(i[n]={...i[n],label:o},e.applyOperation(c.updateBlockProps(t,{columns:i})))}function st(e,t,n,o,l){var m;const s=e.getBlock(t),r=s.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=J(s,r.length?e.getBlock(s.contentIds[0]).contentIds.length:0)[n])==null?void 0:m.type)??De,f=tl(r,d,o,l);e.applyOperation(c.setBlockContentIds(t,f))}function cn(e,t,n,o){const l=e.getBlock(t),s=e.getBlock(l.contentIds[0]),r=J(l,s?s.contentIds.length:0);if(!r[n])return;const i=[...r];i[n]={...r[n],aggregate:o},e.applyOperation(c.updateBlockProps(t,{columns:i}))}function ft(e,t,n){return t.contentIds.map(o=>{const s=e.getBlock(o).contentIds[n],r=e.getBlock(s);return{cellId:s,run:e.getRun(r.contentIds[0])}})}function ol(e,t,n,o){const l=ft(e,t,n),s=[],r=new Map;for(const{run:d}of l){const f=Se(d,o).trim();if(!f||r.has(f))continue;const m={value:c.genId(),label:f};r.set(f,m),s.push(m)}const i=l.map(({cellId:d,run:f})=>{const m=Se(f,o).trim(),p=r.get(m);return{cellId:d,run:{id:c.genId(),type:"tableSelect",value:"",marks:{},data:{selectedValue:(p==null?void 0:p.value)??"",selectedLabel:(p==null?void 0:p.label)??""}}}});return{options:s,newRuns:i}}function un(e,t,n,o,l){const s=e.getBlock(t),r=e.getBlock(s.contentIds[0]),i=J(s,r?r.contentIds.length:0),d=i[n];if(!d||d.type===o)return;const f=[...i];if(o==="select"){const{options:p,newRuns:h}=ol(e,s,n,l);f[n]={...d,type:o,options:p};const k=[c.updateBlockProps(t,{columns:f})];for(const{cellId:x,run:b}of h)k.push(c.setBlockRuns(x,[b]));he(e,k);return}f[n]={...d,type:o};const m=[c.updateBlockProps(t,{columns:f})];for(const{cellId:p,run:h}of ft(e,s,n)){if(!h)continue;const k=Jt(h,o,l);m.push(c.setBlockRuns(p,[k]))}he(e,m)}function Ee(e,t,n,o){var p,h;const l=e.getBlock(t),s=e.getBlock(l.contentIds[0]),r=J(l,s?s.contentIds.length:0),i=r[n];if(!i)return;const d=[...r];d[n]={...i,options:o};const f=[c.updateBlockProps(t,{columns:d})],m=new Map(o.map(k=>[k.value,k]));for(const{run:k}of ft(e,l,n)){if(!k||k.type!=="tableSelect")continue;const x=((p=k.data)==null?void 0:p.selectedValue)??"",b=m.get(x),I=b?x:"",B=b?b.label:"";(I!==x||B!==(((h=k.data)==null?void 0:h.selectedLabel)??""))&&f.push(c.updateRun(k.id,{data:{selectedValue:I,selectedLabel:B}}))}he(e,f)}const ll="$fieldTypes";function dn(){const e=c.useEditorStore(),t=u.useCallback(o=>e.subscribe(ll,o),[e]),n=u.useCallback(()=>e.getFieldTypes(),[e]);return u.useSyncExternalStore(t,n)}function vt(){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(vt);return u.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const n=window.visualViewport,o=()=>t(vt());return o(),n.addEventListener("resize",o),n.addEventListener("scroll",o),()=>{n.removeEventListener("resize",o),n.removeEventListener("scroll",o)}},[]),e}const sl=280,Tt=220,rl=32,wt=6;function al(e,t){return t?e.label.toLowerCase().includes(t.toLowerCase()):!0}function ge({value:e,options:t,onChange:n,placeholder:o="Select…",ariaLabel:l,className:s="",variant:r="default",selectedLabel:i,selectedColor:d,onManageOptions:f,manageOptionsLabel:m="Manage options…",mention:p=!1,autoOpen:h=!1}){var Be,ve;const[k,x]=u.useState(!1),[b,I]=u.useState(""),[B,g]=u.useState(0),[y,w]=u.useState(null),j=pn(),[O,$]=u.useState([]),[S,L]=u.useState(!1),[_,T]=u.useState(!1),A=u.useRef(null),M=u.useRef(null),D=u.useRef(null),E=u.useRef(null),P=u.useRef(null),z=u.useRef(null),G=u.useMemo(()=>[A,D],[]),U=r==="tag",F=typeof t=="function",[V,ne]=u.useState(rl),[Z,X]=u.useState(0),se=F?void 0:t.find(R=>R.value===e),ee=e?se??(i?{label:i,color:d}:void 0):void 0,Q=u.useMemo(()=>F?O:t.filter(R=>al(R,b)),[F,O,t,b]),fe=Math.max(0,(Q.length-1)*V),le=Math.min(Z,fe),W=Q.length?Math.max(0,Math.floor(le/V)-wt):0,Pe=Math.ceil(Tt/V)+wt*2,Ce=Math.min(Q.length,W+Pe),He=Q.slice(W,Ce),N=W*V,K=Math.max(0,(Q.length-Ce)*V);u.useLayoutEffect(()=>{var Y;const R=(Y=z.current)==null?void 0:Y.getBoundingClientRect().height;R&&Math.abs(R-V)>.5&&ne(R)}),u.useEffect(()=>{if(!F||!k)return;let R=!1;L(!0),T(!1);const Y=setTimeout(()=>{Promise.resolve(t(b)).then(oe=>{R||($(oe??[]),L(!1))}).catch(()=>{R||($([]),L(!1),T(!0))})},250);return()=>{R=!0,clearTimeout(Y)}},[F,k,t,b]);const H=u.useCallback(()=>x(!1),[]);v.useOutsideClickAndEscape(G,k,H);const q=ae.useHorizontalAutoAdjustedLeft(D,k,y==null?void 0:y.left),re=u.useCallback(()=>{var R;w(((R=M.current)==null?void 0:R.getBoundingClientRect())??null),I(""),g(0),X(0),x(!0)},[]);u.useEffect(()=>{h&&re()},[]),u.useEffect(()=>{var R;k&&((R=E.current)==null||R.focus())},[k,q]),u.useEffect(()=>{const R=P.current;if(!R)return;const Y=B*V,oe=Y+V,Te=R.scrollTop,we=R.clientHeight||Tt,Ye=Te+we;let Re=null;Y<Te?Re=Y:oe>Ye&&(Re=oe-we),Re!==null&&(R.scrollTop=Re,X(Re))},[B,V]);const xe=u.useCallback(R=>{var Y;n(R.value,R),H(),(Y=M.current)==null||Y.focus()},[n,H]),_e=u.useCallback(R=>{var Y;R.key==="ArrowDown"?(R.preventDefault(),g(oe=>Math.min(oe+1,Math.max(Q.length-1,0)))):R.key==="ArrowUp"?(R.preventDefault(),g(oe=>Math.max(oe-1,0))):R.key==="Enter"?(R.preventDefault(),Q[B]&&xe(Q[B])):R.key==="Escape"&&(R.preventDefault(),H(),(Y=M.current)==null||Y.focus())},[Q,B,xe,H]);return a.jsxs("span",{className:`be-select ${s}`.trim(),ref:A,children:[a.jsx("button",{type:"button",ref:M,className:`be-select-trigger${U?" be-select-trigger-tag":""}${p?" be-select-trigger-mention":""}`,"aria-haspopup":"listbox","aria-expanded":k,"aria-label":l,onClick:()=>k?H():re(),children:U?ee?a.jsx("span",{className:`be-select-tag${p?" be-select-tag-mention":""}`,style:p?void 0:{background:(Be=ee.color)==null?void 0:Be.bg,color:(ve=ee.color)==null?void 0:ve.text},children:p?`@${ee.label}`:ee.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:ee?ee.label:o}),a.jsx(c.ChevronDownIcon,{size:14,className:"be-select-chevron"})]})}),k&&y&&q!=null&&be.createPortal(a.jsxs("div",{ref:D,className:"be-select-popover",style:{position:"fixed",left:q,minWidth:y.width,...y.bottom+sl>window.innerHeight-j?{bottom:window.innerHeight-y.top+4}:{top:y.bottom+4}},children:[a.jsx("input",{ref:E,type:"text",className:"be-select-search",value:b,onChange:R=>{I(R.target.value),g(0)},onKeyDown:_e,placeholder:"Search…","aria-label":l?`Search ${l}`:"Search options"}),a.jsxs("div",{className:"be-select-options",role:"listbox",ref:P,onScroll:R=>X(R.currentTarget.scrollTop),children:[F&&S&&a.jsx("div",{className:"be-select-empty",children:"Loading…"}),F&&!S&&_&&a.jsx("div",{className:"be-select-empty be-select-error",children:"Couldn't load options"}),!S&&!_&&Q.length===0&&a.jsx("div",{className:"be-select-empty",children:"No results"}),!S&&!_&&Q.length>0&&a.jsxs(a.Fragment,{children:[N>0&&a.jsx("div",{style:{height:N},"aria-hidden":"true"}),He.map((R,Y)=>{var Te,we;const oe=W+Y;return a.jsx("div",{ref:Y===0?z:void 0,role:"option","aria-selected":R.value===e,className:`be-select-option${oe===B?" be-select-option-active":""}${R.value===e?" be-select-option-selected":""}`,onMouseDown:Ye=>{Ye.preventDefault(),xe(R)},onMouseEnter:()=>g(oe),children:U?a.jsx("span",{className:"be-select-tag",style:{background:(Te=R.color)==null?void 0:Te.bg,color:(we=R.color)==null?void 0:we.text},children:R.label}):R.label},R.value)}),K>0&&a.jsx("div",{style:{height:K},"aria-hidden":"true"})]})]}),f&&a.jsx("button",{type:"button",className:"be-select-manage-options",onMouseDown:R=>{R.preventDefault(),H(),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 cl={text:"Text",date:"Date",checkbox:"Checkbox",select:"Select"},il=Zt.map(e=>({value:e,label:en[e]})),ul=Yt.map(e=>({value:e,label:cl[e]})),Je=800;function dl({tableId:e,colIndex:t}){const n=c.useEditorStore(),o=dn(),{openCreate:l}=c.useFieldTypeEditor(),s=u.useCallback(r=>{const i=n.getFieldType(r);i&&Ee(n,e,t,i.options??[])},[n,e,t]);return a.jsxs("div",{className:"be-table-header-menu-field-type",children:[o.length>0&&a.jsx(ge,{value:"",options:o.map(r=>({value:r.id,label:r.label})),onChange:s,placeholder:"Copy options from…",ariaLabel:"Copy options from an existing field type"}),a.jsx("button",{type:"button",className:"be-table-header-menu-item",onClick:l,children:"+ New field type"})]})}function pl({tableId:e,colIndex:t,options:n}){const o=c.useEditorStore(),[l,s]=u.useState(""),r=u.useCallback((f,m)=>{Ee(o,e,t,n.map(p=>p.value===f?{...p,label:m}:p))},[o,e,t,n]),i=u.useCallback(f=>Ee(o,e,t,n.filter(m=>m.value!==f)),[o,e,t,n]),d=u.useCallback(()=>{const f=l.trim();s(""),f&&Ee(o,e,t,[...n,{value:c.genId(),label:f,color:ze(n.length)}])},[o,e,t,n,l]);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:()=>i(f.value),"aria-label":`Remove option ${f.label}`,children:a.jsx(c.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:l,onChange:f=>s(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 fl({tableId:e,column:t,colIndex:n,colCount:o,filterValue:l,onFilterChange:s}){const r=c.useEditorStore(),i=c.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),B=u.useMemo(()=>[x,b],[]),g=u.useCallback(()=>f(!1),[]);v.useOutsideClickAndEscape(B,d,g),Ve(b,d,g,x);const y=ae.useAutoAdjustedRightLeft(b,d,m==null?void 0:m.right),w=u.useCallback(()=>{var E;p(((E=I.current)==null?void 0:E.getBoundingClientRect())??null),f(!0)},[]),j=u.useCallback(E=>an(r,e,n,E.target.value),[r,e,n]),O=u.useCallback(()=>{ot(r,e,n-1),g()},[r,e,n,g]),$=u.useCallback(()=>{ot(r,e,n),g()},[r,e,n,g]),S=u.useCallback(()=>{rn(r,e,n),g()},[r,e,n,g]),L=u.useCallback(E=>un(r,e,n,E,i),[r,e,n,i]),_=u.useCallback(()=>{st(r,e,n,"asc",i),g()},[r,e,n,i,g]),T=u.useCallback(()=>{st(r,e,n,"desc",i),g()},[r,e,n,i,g]),A=u.useCallback(E=>cn(r,e,n,E),[r,e,n]),M=u.useCallback(E=>{var Z;E.preventDefault();const P=(Z=I.current)==null?void 0:Z.closest("table"),z=P==null?void 0:P.querySelector(`col[data-col-index="${n}"]`);if(!z)return;const G=I.current.getBoundingClientRect().width,U=E.clientX,F=X=>Math.max(me,Math.round(G+(X.clientX-U))),V=X=>{const se=F(X);z.style.width=`${se}px`,k(se)},ne=X=>{document.removeEventListener("mousemove",V),document.removeEventListener("mouseup",ne),lt(r,e,n,F(X)),k(null)};document.addEventListener("mousemove",V),document.addEventListener("mouseup",ne)},[r,e,n]),D=u.useCallback(E=>{const P=t.width??me,z=E.shiftKey?1:16;let G;if(E.key==="ArrowLeft"||E.key==="ArrowDown")G=Math.max(me,P-z);else if(E.key==="ArrowRight"||E.key==="ArrowUp")G=Math.min(Je,P+z);else if(E.key==="Home")G=me;else if(E.key==="End")G=Je;else return;E.preventDefault(),lt(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:j,"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:D,role:"slider",tabIndex:0,"aria-label":`Resize column ${n+1}`,"aria-valuemin":me,"aria-valuemax":Je,"aria-valuenow":h??t.width}),d&&m&&y!=null&&be.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(ge,{value:t.type,options:ul,onChange:L,ariaLabel:"Column type",className:""})]}),t.type==="select"&&a.jsxs(a.Fragment,{children:[a.jsx(dl,{tableId:e,colIndex:n}),a.jsx(pl,{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:_,children:[a.jsx(c.ArrowUpIcon,{size:13})," Sort ascending"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:T,children:[a.jsx(c.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:l??"",onChange:E=>s(t.id,E.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(ge,{value:t.aggregate??"none",options:il,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:$,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((l,s)=>a.jsx(fl,{tableId:e,column:l,colIndex:s,colCount:t.length,filterValue:n==null?void 0:n[l.id],onFilterChange:o},l.id)),a.jsx("th",{className:"be-table-header-spacer","aria-hidden":"true"})]})})}function ml({id:e}){var b;const t=c.useEditorStore(),n=c.useInlineRegistry(),o=v.useBlock(e),[l,s]=u.useState({}),r=u.useCallback((I,B)=>{s(g=>B?{...g,[I]:B}:Object.fromEntries(Object.entries(g).filter(([y])=>y!==I)))},[]),i=u.useCallback(()=>{var B;const I=(B=o==null?void 0:o.contentIds)==null?void 0:B[o.contentIds.length-1];I&&ln(t,I)},[t,o]),d=c.useBlockClassName("be-table-wrapper",o),f=u.useMemo(()=>Object.entries(l).filter(([,I])=>I),[l]),m=u.useCallback((I,B)=>{const g=t.getBlock(I),y=g&&t.getBlock(g.contentIds[B]);return y?t.getRun(y.contentIds[0]):null},[t]);if(!o)return null;const p=t.getBlock(o.contentIds[0]),h=J(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(([B,g])=>{const y=h.findIndex(j=>j.id===B);return y===-1?!0:Se(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,B)=>a.jsx("col",{"data-col-index":B,style:{width:I.width}},I.id)),a.jsx("col",{className:"be-table-header-spacer-col"})]}),a.jsx(fn,{tableId:e,columns:h,filters:l,onFilterChange:r}),a.jsx("tbody",{children:a.jsx(pe,{parentId:e,filterIds:k})}),x&&a.jsx("tfoot",{children:a.jsxs("tr",{className:"be-table-footer-row",children:[h.map((I,B)=>{const g=k.map(w=>m(w,B)),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:nl[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:i,children:[a.jsx(c.PlusIcon,{size:14})," Add row"]})]})})}function hl({id:e}){const t=c.useEditorStore(),n=v.useBlock(e),o=c.useBlockClassName("be-table-row",n),l=u.useCallback(()=>sn(t,e),[t,e]);return a.jsxs("tr",{className:o,"data-block-id":e,children:[a.jsx(pe,{parentId:e}),a.jsx("td",{className:"be-table-row-actions",contentEditable:!1,children:a.jsx("button",{type:"button",className:"be-table-delete-row",onClick:l,"aria-label":"Delete row",title:"Delete row",children:a.jsx(c.XIcon,{size:14})})})]})}function mn(e,t){const n=e.getBlock(t),o=e.getBlock(n.parentId),l=e.getBlock(o.parentId);return{table:l,row:o,rowIndex:l.contentIds.indexOf(o.id),colIndex:o.contentIds.indexOf(t)}}function gl(e,t,n){const{table:o,row:l,rowIndex:s,colIndex:r}=mn(e,t);if(n==="left"||n==="right"){const m=n==="right"?1:-1,p=r+m;if(p>=0&&p<l.contentIds.length)return l.contentIds[p];const h=s+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=s+(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 bl(e,t){const n=C.resolveAdjacentFocusTarget(e,t,"down");if(n){C.focusRunEnd(n);return}C.insertSiblingAfterAndFocus(e,t,C.createTextLeafBlock("paragraph"))}function je(e,t,n){var l;const o=gl(e,t,n);if(o){const s=e.getBlock(o),r=(l=s==null?void 0:s.contentIds)==null?void 0:l[0];r&&C.focusRunEnd(r);return}if(n==="right"){const{table:s}=mn(e,t);bl(e,s.id)}}function kl({id:e}){const t=c.useEditorStore(),n=v.useBlock(e),o=u.useCallback(()=>je(t,e,"right"),[t,e]),l=u.useCallback(()=>je(t,e,"left"),[t,e]),s=u.useCallback(()=>je(t,e,"up"),[t,e]),r=u.useCallback(()=>je(t,e,"down"),[t,e]),i=u.useCallback(()=>je(t,e,"down"),[t,e]),d=c.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:l,onArrowUp:s,onArrowDown:r,onEnter:i})})}function yl(e,t){const n=c.genId(),o=[],l=[],s=[];for(const r of t){const i=We(n,r);o.push(i.block),l.push(i.run),s.push(i.block.id)}return{block:{id:n,type:"tableRow",parentId:e,contentIds:s,props:{}},blocks:o,runs:l}}function Il({rows:e=2,cols:t=2}={}){return function(o){const l=c.genId(),s=pt(t),r=[],i=[],d=[];for(let m=0;m<e;m+=1){const p=yl(l,s);r.push(p.block,...p.blocks),i.push(...p.runs),d.push(p.block.id)}return{block:{id:l,type:"table",parentId:o,contentIds:d,props:{columns:s}},runs:i,subtreeBlocks:r}}}function Cl(e,t){return`<td>${e.contentIds.map(o=>t.store.getRun(o)).map(o=>v.runToHTML(o,t)).join("")}</td>`}function xl(e,t){return e.contentIds.map(n=>v.runToPlainText(t.store.getRun(n),t)).join("")}function Bl(e,t){return v.runsToMarkdown(e.contentIds.map(o=>t.store.getRun(o)),t).replace(/\|/g,"\\|").replace(/\r?\n/g,"<br>")}function vl(e,t){if(e.tagName!=="TD"&&e.tagName!=="TH")return null;const n=ie(e,t);return{block:{id:c.genId(),type:"tableCell",parentId:null,contentIds:n.map(l=>l.id),props:{}},runs:n}}function Tl(e,t){return`<tr>${e.contentIds.map(o=>{const l=t.store.getBlock(o);return t.registry.get(l.type).toHTML(l,t)}).join("")}</tr>`}function wl(e,t){return e.contentIds.map(n=>{const o=t.store.getBlock(n);return t.registry.get(o.type).toPlainText(o,t)}).join(" ")}function Rl(e,t){return`| ${e.contentIds.map(o=>{const l=t.store.getBlock(o);return t.registry.get(l.type).toMarkdown(l,t)}).join(" | ")} |`}function Al(e,t){if(e.tagName!=="TR")return null;const n=[...e.children].filter(d=>d.tagName==="TD"||d.tagName==="TH"),o=c.genId(),l=[],s=[],r=[];for(const d of n){const f=t.registry.get("tableCell").fromHTML(d,t);f&&(f.block.parentId=o,l.push(f.block),s.push(...f.runs),r.push(f.block.id))}return{block:{id:o,type:"tableRow",parentId:null,contentIds:r,props:{}},runs:s,subtreeBlocks:l}}function jl(e,t){var r;const n=e.contentIds[0]&&t.store.getBlock(e.contentIds[0]),o=J(e,((r=n==null?void 0:n.contentIds)==null?void 0:r.length)??0),l=o.length?`<thead><tr>${o.map(i=>`<th>${v.escapeHTML(i.label??"")}</th>`).join("")}</tr></thead>`:"",s=e.contentIds.map(i=>{const d=t.store.getBlock(i);return t.registry.get(d.type).toHTML(d,t)}).join("");return`<table>${l}<tbody>${s}</tbody></table>`}function Ll(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 Nl(e,t){var i;const n=e.contentIds[0]&&t.store.getBlock(e.contentIds[0]),o=J(e,((i=n==null?void 0:n.contentIds)==null?void 0:i.length)??0);if(o.length===0)return"";const l=`| ${o.map(d=>(d.label??"").replace(/\|/g,"\\|")).join(" | ")} |`,s=`| ${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?`${l}
|
|
8
|
+
${s}
|
|
9
|
+
${r}`:`${l}
|
|
10
|
+
${s}`}function El(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),l=c.genId(),s=[],r=[],i=[];for(const m of o){const p=t.registry.get("tableRow").fromHTML(m,t);if(p){p.block.parentId=l;for(const h of p.subtreeBlocks)h.parentId=p.block.id;s.push(p.block,...p.subtreeBlocks),r.push(...p.runs),i.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:c.genId(),label:p.textContent??""}))}return{block:{id:l,type:"table",parentId:null,contentIds:i,props:d},runs:r,subtreeBlocks:s}}const hn=v.defineBlock({name:"tableCell",contentModel:"runs",component:kl,defaultProps:{},toHTML:Cl,toPlainText:xl,toMarkdown:Bl,fromHTML:vl}),gn=v.defineBlock({name:"tableRow",contentModel:"blocks",component:hl,defaultProps:{},toHTML:Tl,toPlainText:wl,toMarkdown:Rl,fromHTML:Al}),bn=v.defineBlock({name:"table",contentModel:"blocks",component:ml,defaultProps:{},toHTML:jl,toPlainText:Ll,toMarkdown:Nl,fromHTML:El,slashCommand:{label:"Table",icon:c.TableIcon,keywords:["table","grid"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Il({rows:2,cols:2}))}});function Sl({id:e}){const t=v.useBlock(e),n=c.useBlockClassName("be-layout",t);return a.jsx("div",{className:n,"data-block-id":e,style:{display:"flex",gap:"1em"},children:a.jsx(pe,{parentId:e})})}function Ml({id:e}){const t=v.useBlock(e),n=c.useBlockClassName("be-layout-column",t);return a.jsx("div",{className:n,"data-block-id":e,children:a.jsx(pe,{parentId:e})})}function $l({columns:e=2}={}){return function(n){const o=c.genId(),l=[],s=[],r=[];for(let d=0;d<e;d+=1){const f=c.genId(),{block:m,runs:p}=C.createTextLeafBlock("paragraph")(f),h={id:f,type:"layoutColumn",parentId:o,contentIds:[m.id],props:{}};l.push(h,m),s.push(...p),r.push(f)}return{block:{id:o,type:"layout",parentId:n,contentIds:r,props:{}},runs:s,subtreeBlocks:l}}}function kn(e,t){return(n,o)=>`${e}${n.contentIds.map(l=>{const s=o.store.getBlock(l);return o.registry.get(s.type).toHTML(s,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),l=t.registry.get(o.type);return(l.toMarkdown??l.toPlainText)(o,t)}).join(`
|
|
12
|
+
|
|
13
|
+
`)}const Cn=v.defineBlock({name:"layoutColumn",contentModel:"blocks",component:Ml,defaultProps:{},toHTML:kn("<div>","</div>"),toPlainText:yn,toMarkdown:In}),xn=v.defineBlock({name:"layout",contentModel:"blocks",component:Sl,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:c.ColumnsIcon,keywords:["layout","columns","column",String(e)],run:(t,n)=>C.trimSlashQueryAndInsertAfter(t,n,$l({columns:e}))}))});function Ol({id:e}){const t=v.useBlock(e),n=c.useBlockClassName("be-divider",t);return a.jsx("hr",{className:n,"data-block-id":e,contentEditable:!1,tabIndex:-1})}function Dl(){return function(t){return{block:{id:c.genId(),type:"divider",parentId:t,contentIds:[],props:{}},runs:[]}}}function Pl(){return"<hr />"}function Hl(){return"---"}function _l(){return"---"}function Fl(e){return e.tagName!=="HR"?null:{block:{id:c.genId(),type:"divider",parentId:null,contentIds:[],props:{}},runs:[]}}const Bn=v.defineBlock({name:"divider",contentModel:"void",component:Ol,defaultProps:{},toHTML:Pl,toPlainText:Hl,toMarkdown:_l,fromHTML:Fl,slashCommand:{label:"Divider",icon:c.DividerIcon,keywords:["divider","hr","separator","line"],run:(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l})=>{const s=e.getRun(n),r=(s==null?void 0:s.value)??"";e.applyOperation(c.updateRun(n,{value:r.slice(0,o)+r.slice(l)}));const i=C.insertSiblingAfter(e,t,Dl());return C.insertSiblingAfterAndFocus(e,i,C.createTextLeafBlock("paragraph")),i}}}),vn=[{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 Ul({id:e}){var B,g;const t=c.useEditorStore(),n=v.useBlock(e),[o,l]=u.useState(!1),[s,r]=u.useState(!1),i=u.useRef(null),d=u.useRef(null),f=u.useMemo(()=>[i,d],[]),m=u.useCallback(()=>r(!1),[]);v.useOutsideClickAndEscape(f,s,m);const p=((B=n==null?void 0:n.props)==null?void 0:B.icon)??ke,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(c.updateBlockProps(e,{icon:w})),l(!1)},[t,e]),x=u.useCallback(y=>{y.key==="Enter"&&y.currentTarget.blur(),y.key==="Escape"&&l(!1)},[]),b=u.useCallback(y=>{t.applyOperation(c.updateBlockProps(e,{color:y})),r(!1)},[t,e]),I=c.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:()=>l(!0),"aria-label":"Change callout icon",title:"Change icon",children:p})}),a.jsx("div",{className:"be-callout-content",children:a.jsx(pe,{parentId:e})}),a.jsxs("div",{className:"be-callout-color-wrap",contentEditable:!1,children:[a.jsx("button",{ref:i,type:"button",className:"be-callout-color-trigger","aria-label":"Callout color","aria-haspopup":"true","aria-expanded":s,title:"Callout color",onClick:()=>r(y=>!y),children:a.jsx("span",{className:`be-callout-color-dot be-callout-color-dot-${h}`})}),s&&a.jsx("div",{ref:d,className:"be-callout-color-picker",role:"menu","aria-label":"Callout color",children:vn.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 Kl(e,t){return e.contentIds.map(n=>{const o=t.store.getBlock(n);return t.registry.get(o.type).toHTML(o,t)}).join("")}function zl(e,t){var o;const n=((o=e.props)==null?void 0:o.icon)??ke;return`<div class="callout" data-icon="${n}"><div class="callout-icon">${n}</div><div class="callout-content">${Kl(e,t)}</div></div>`}function Gl(e,t){var l;const n=((l=e.props)==null?void 0:l.icon)??ke,o=e.contentIds.map(s=>{const r=t.store.getBlock(s);return t.registry.get(r.type).toPlainText(r,t)}).join(`
|
|
14
|
+
`);return`${n} ${o}`}function Vl(e,t){var l;const n=((l=e.props)==null?void 0:l.icon)??ke;return e.contentIds.map(s=>{const r=t.store.getBlock(s),i=t.registry.get(r.type);return(i.toMarkdown??i.toPlainText)(r,t)}).join(`
|
|
15
|
+
`).split(`
|
|
16
|
+
`).map((s,r)=>`> ${r===0?`${n} `:""}${s}`).join(`
|
|
17
|
+
`)}const Tn=v.defineBlock({name:"callout",contentModel:"blocks",component:Ul,defaultProps:{icon:ke},toHTML:zl,toPlainText:Gl,toMarkdown:Vl,slashCommand:{label:"Callout",icon:c.CalloutIcon,keywords:["callout","aside","note","info","tip","warning"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,Ao())}});function ql({id:e}){const t=c.useEditorStore(),n=v.useBlock(e),{setSelectedBlockId:o}=c.useSelectedBlock(),l=u.useCallback(()=>{C.insertSiblingSplitAtCaretAndFocus(t,e,(n==null?void 0:n.contentIds)??[],C.createTextLeafBlock("paragraph"))},[t,e,n]),s=u.useCallback(()=>{const p=Oe(t,e);Ie(t,p,e,o)},[t,e,o]),r=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),i=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),d=c.useBlockClassName("be-blockquote",n);if(!n)return null;const f=te(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:l,onBackspaceAtStart:s,onArrowUp:r,onArrowDown:i})})}function Wl(e,t){return`<p>${e.contentIds.map(o=>t.store.getRun(o)).map(o=>v.runToHTML(o,t)).join("")}</p>`}function Ql(e,t){return e.contentIds.map(n=>v.runToPlainText(t.store.getRun(n),t)).join("")}function Yl(e,t){return`> ${v.runsToMarkdown(e.contentIds.map(o=>t.store.getRun(o)),t)}`}function Xl(e,t){if(e.tagName!=="BLOCKQUOTE")return null;const n=ie(e,t);return{block:{id:c.genId(),type:"blockquote",parentId:null,contentIds:n.map(l=>l.id),props:{}},runs:n}}const wn=v.defineBlock({name:"blockquote",contentModel:"runs",component:ql,defaultProps:{},toHTML:Wl,toPlainText:Ql,toMarkdown:Yl,fromHTML:Xl,slashCommand:{label:"Quote",icon:c.QuoteIcon,keywords:["quote","blockquote","citation"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("blockquote"))}}),Rn=["plaintext","javascript","python","html","css","json","bash","sql"],Jl=Rn.map(e=>({value:e,label:e}));function Rt(e,t,n){const o=C.resolveCollapsedCaret();if(!o||o.blockId!==t)return;const l=e.getRun(o.runId);if(!l||l.type!=="text")return;const s=l.value??"",r=s.slice(0,o.offset)+n+s.slice(o.offset);e.applyOperation(c.updateRun(l.id,{value:r})),C.focusRunAtOffset(l.id,o.offset+n.length)}function Zl({id:e}){var b,I;const t=c.useEditorStore(),n=v.useBlock(e),o=c.useShowLineNumbers(),l=u.useCallback(()=>Rt(t,e,`
|
|
18
|
+
`),[t,e]),s=u.useCallback(()=>Rt(t,e," "),[t,e]),r=u.useCallback(()=>{var w;const B=Oe(t,e);if(!B||B===e)return;const g=t.getBlock(B),y=(w=g==null?void 0:g.contentIds)==null?void 0:w[g.contentIds.length-1];y&&C.focusRunEnd(y)},[t,e]),i=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),d=u.useCallback(()=>C.focusAdjacentBlock(t,e,"down"),[t,e]),f=u.useCallback(B=>t.applyOperation(c.updateBlockProps(e,{language:B})),[t,e]),m=u.useCallback(()=>dt(t,e),[t,e]),p=c.useBlockClassName("be-code-block",n);if(!n)return null;const h=((b=n.props)==null?void 0:b.language)??"plaintext",k=te(t,n.contentIds),x=o?(((I=n.contentIds.map(B=>{var g;return((g=t.getRun(B))==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(ge,{className:"be-code-block-language",value:h,options:Jl,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(c.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},(B,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:l,onTab:s,onBackspaceAtStart:r,onArrowUp:i,onArrowDown:d})})})]})]})}function es(e,t){var s;const n=e.contentIds.map(r=>t.store.getRun(r)),o=(s=e.props)==null?void 0:s.language;return`<pre><code${o&&o!=="plaintext"?` data-language="${v.escapeHTML(o)}"`:""}>${n.map(r=>v.runToHTML(r,t)).join("")}</code></pre>`}function ts(e,t){return e.contentIds.map(n=>v.runToPlainText(t.store.getRun(n),t)).join("")}function ns(e,t){var s;const n=(s=e.props)==null?void 0:s.language,o=n&&n!=="plaintext"?n:"",l=e.contentIds.map(r=>{var i;return((i=t.store.getRun(r))==null?void 0:i.value)??""}).join("");return`\`\`\`${o}
|
|
19
|
+
${l}
|
|
20
|
+
\`\`\``}function os(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"),l=c.genId();return{block:{id:c.genId(),type:"code",parentId:null,contentIds:[l],props:o?{language:o}:{}},runs:[{id:l,type:"text",value:n.textContent??"",marks:{}}]}}const An=v.defineBlock({name:"code",contentModel:"runs",component:Zl,defaultProps:{language:"plaintext"},toHTML:es,toPlainText:ts,toMarkdown:ns,fromHTML:os,slashCommand:{label:"Code",icon:c.CodeIcon,keywords:["code","codeblock","snippet","pre"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,C.createTextLeafBlock("code"))}});function ls(e,t){var n;return t.length===0||t.length===1&&(((n=e.getRun(t[0]))==null?void 0:n.value)??"")===""}function ss(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"&&te(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 rs(e,t){const n=e.getBlock(t);if(!n)return null;const o=e.getBlock(n.parentId),l=o.contentIds.indexOf(t),s=n.props.titleRunIds??[],r=ls(e,s)&&ss(e,n);if(l<=0){if(!r)return null;if(o.contentIds.length>1)return Ue(e,[c.removeBlock(t)]),{focusBlockId:e.getBlock(o.id).contentIds[0],needsRefocus:!0};const{block:f,runs:m}=C.createTextLeafBlock("paragraph")(o.id);return Ue(e,[c.insertBlock(f,o.id,l,{blocks:[f],runs:m}),c.removeBlock(t)]),{focusBlockId:f.id,needsRefocus:!0}}const i=o.contentIds[l-1],d=e.getBlock(i);return r?(Ue(e,[c.removeBlock(t)]),{focusBlockId:i,needsRefocus:!0}):Me(e,d)?(Ue(e,[c.removeBlock(i)]),{focusBlockId:t,needsRefocus:!1}):null}function as(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function cs({id:e}){var I;const t=c.useEditorStore(),n=v.useBlock(e),{setSelectedBlockId:o}=c.useSelectedBlock(),l=u.useCallback(()=>{var w,j;const B=((w=n==null?void 0:n.props)==null?void 0:w.titleRunIds)??[],g=(((j=n==null?void 0:n.contentIds)==null?void 0:j.length)??0)>0,y=C.createTextLeafBlock("paragraph");g?C.insertFirstChildSplitAtCaretAndFocus(t,e,B,y):C.insertSiblingSplitAtCaretAndFocus(t,e,B,y)},[t,e,n]),s=u.useCallback(()=>{const B=rs(t,e);!B||!B.needsRefocus||Ie(t,B.focusBlockId,e,o)},[t,e,o]),r=u.useCallback(()=>C.focusAdjacentBlock(t,e,"up"),[t,e]),i=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:j}=C.createTextLeafBlock("paragraph")(e);as(t,[c.insertBlock(w,e,0,{blocks:[w],runs:j}),c.updateBlockProps(e,{collapsed:!1})]),C.focusRunEnd(w.contentIds[0]);return}t.applyOperation(c.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=c.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(c.ChevronRightIcon,{}):a.jsx(c.ChevronDownIcon,{})}),a.jsx(x,{className:`be-heading be-heading-${m} be-toggle-heading-title`,"data-empty":te(t,h)?"":void 0,"data-placeholder":`Toggle heading ${m}`,children:a.jsx(ue,{blockId:e,runIds:h,dir:b,onEnter:l,onBackspaceAtStart:s,onArrowUp:r,onArrowDown:i})})]}),!p&&a.jsx("div",{className:"be-toggle-heading-children",children:a.jsx(pe,{parentId:e})})]})}function is({level:e=2,collapsed:t=!1}={}){return function(o,l){const s=c.genId(),r=l!=null&&l.length?l:[{id:c.genId(),type:"text",value:"",marks:{}}],{block:i,runs:d}=C.createTextLeafBlock("paragraph")(s);return{block:{id:s,type:"toggleHeading",parentId:o,contentIds:[i.id],props:{level:e,collapsed:t,titleRunIds:r.map(f=>f.id)}},runs:[...r,...d],subtreeBlocks:[i]}}}function us(e,t){const{titleRunIds:n=[],level:o=2,collapsed:l}=e.props,s=n.map(i=>v.runToHTML(t.store.getRun(i),t)).join(""),r=e.contentIds.map(i=>{const d=t.store.getBlock(i);return t.registry.get(d.type).toHTML(d,t)}).join("");return`<details${l?"":" open"}><summary><h${o}>${s}</h${o}></summary>${r}</details>`}function ds(e,t){const{titleRunIds:n=[]}=e.props,o=n.map(s=>v.runToPlainText(t.store.getRun(s),t)).join(""),l=e.contentIds.map(s=>{const r=t.store.getBlock(s);return t.registry.get(r.type).toPlainText(r,t)}).join(`
|
|
21
|
+
`);return l?`${o}
|
|
22
|
+
${l}`:o}function ps(e,t){const{titleRunIds:n=[],level:o=2}=e.props,l=v.runsToMarkdown(n.map(i=>t.store.getRun(i)),t),s=`${"#".repeat(Math.min(6,o))} ${l}`,r=e.contentIds.map(i=>{const d=t.store.getBlock(i),f=t.registry.get(d.type);return(f.toMarkdown??f.toPlainText)(d,t)}).join(`
|
|
23
|
+
|
|
24
|
+
`);return r?`${s}
|
|
25
|
+
|
|
26
|
+
${r}`:s}function fs(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"),l=o?Math.min(6,Math.max(1,Number(o.tagName[1]))):2,s=o?ie(o,t):[{id:c.genId(),type:"text",value:"",marks:{}}],r=c.genId(),i=[],d=[],f=[];for(const p of e.children){if(p===n||p.tagName!=="P")continue;const h=ie(p,t),k={id:c.genId(),type:"paragraph",parentId:r,contentIds:h.map(x=>x.id),props:{}};i.push(k),d.push(...h),f.push(k.id)}if(f.length===0){const{block:p,runs:h}=C.createTextLeafBlock("paragraph")(r);i.push(p),d.push(...h),f.push(p.id)}return{block:{id:r,type:"toggleHeading",parentId:null,contentIds:f,props:{level:l,collapsed:!e.hasAttribute("open"),titleRunIds:s.map(p=>p.id)}},runs:[...s,...d],subtreeBlocks:i}}const jn=v.defineBlock({name:"toggleHeading",contentModel:"blocks",component:cs,defaultProps:{level:2,collapsed:!1,titleRunIds:[]},toHTML:us,toPlainText:ds,toMarkdown:ps,fromHTML:fs,slashCommands:[1,2,3].map(e=>({label:`Toggle heading ${e}`,icon:c.ChevronRightIcon,keywords:["toggle","heading","collapse","section"],run:(t,n)=>C.trimSlashQueryAndInsertAfter(t,n,is({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 ms(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function hs({isOpen:e,onClose:t,store:n,blockId:o}){const[l,s]=u.useState(""),[r,i]=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(j=>{var O;return((O=n.getRun(j))==null?void 0:O.value)??""}).join(""),B=((g=b.props)==null?void 0:g.customAttrs)??[];s(I),i(((y=b.props)==null?void 0:y.href)??""),f(((w=b.props)==null?void 0:w.color)??Ze[0].value),p([...B,{key:"",value:""}])},[e,o,n]);const h=u.useCallback((b,I)=>{p(B=>{const g=B.map((w,j)=>j===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((B,g)=>g!==b))},[]),x=u.useCallback(()=>{const b={id:c.genId(),type:"text",value:l,marks:{}},I=m.filter(B=>B.key.trim());ms(n,[c.setBlockRuns(o,[b]),c.updateBlockProps(o,{href:r.trim(),color:d,customAttrs:I})]),t()},[n,o,l,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:l,onChange:b=>s(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=>i(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:B=>h(I,{key:B.target.value})}),a.jsx("input",{type:"text",placeholder:"value",value:b.value,onChange:B=>h(I,{value:B.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(c.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 gs="#2b6fd6";function bs({id:e}){var g,y,w,j;const t=c.useEditorStore(),n=v.useBlock(e),{setSelectedBlockId:o}=c.useSelectedBlock(),[l,s]=u.useState(!1),r=u.useCallback(()=>{C.insertSiblingSplitAtCaretAndFocus(t,e,(n==null?void 0:n.contentIds)??[],C.createTextLeafBlock("paragraph"))},[t,e,n]),i=u.useCallback(()=>{const O=Oe(t,e);Ie(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 $;const O=($=n==null?void 0:n.props)==null?void 0:$.href;O&&window.open(O,"_blank","noopener,noreferrer")},[(g=n==null?void 0:n.props)==null?void 0:g.href]),p=c.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)??gs,x=((j=n.props)==null?void 0:j.customAttrs)??[],b=te(t,n.contentIds),I={};for(const{key:O,value:$}of x)O.trim()&&(I[`data-${O.trim()}`]=$);const B=ce(t,n);return a.jsxs("div",{className:p,"data-block-id":e,dir:B,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:B,onEnter:r,onBackspaceAtStart:i,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:()=>s(!0),"aria-label":"Edit button",title:"Edit label, link, color…",children:"⚙"})]}),a.jsx(hs,{isOpen:l,onClose:()=>s(!1),store:t,blockId:e})]})}function ks({href:e="",label:t="Button",color:n="",customAttrs:o=[]}={}){return function(s,r){const i=c.genId(),d=r!=null&&r.length?r:[{id:c.genId(),type:"text",value:t,marks:{}}];return{block:{id:i,type:"button",parentId:s,contentIds:d.map(f=>f.id),props:{href:e,color:n,customAttrs:o}},runs:d}}}const Ln="be-button-block-link";function ys(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)??"",l=(f=e.props)==null?void 0:f.color,s=l?` style="background-color:${v.escapeAttr(l)}"`:"",i=(((m=e.props)==null?void 0:m.customAttrs)??[]).filter(p=>{var h;return(h=p.key)==null?void 0:h.trim()}).map(p=>` data-${v.escapeAttr(p.key.trim())}="${v.escapeAttr(p.value??"")}"`).join("");return`<a class="${Ln}" href="${v.escapeAttr(o)}"${s}${i}>${n.map(p=>v.runToHTML(p,t)).join("")}</a>`}function Is(e,t){return e.contentIds.map(n=>v.runToPlainText(t.store.getRun(n),t)).join("")}function Cs(e,t){var l;const n=((l=e.props)==null?void 0:l.href)??"";return`[${v.runsToMarkdown(e.contentIds.map(s=>t.store.getRun(s)),t)||n}](${n})`}function xs(e,t){var s;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:c.genId(),type:"button",parentId:null,contentIds:n.map(r=>r.id),props:{href:e.getAttribute("href")??"",color:((s=e.style)==null?void 0:s.backgroundColor)||void 0,customAttrs:o}},runs:n}}const Nn=v.defineBlock({name:"button",contentModel:"runs",component:bs,defaultProps:{href:"",color:"",customAttrs:[]},toHTML:ys,toPlainText:Is,toMarkdown:Cs,fromHTML:xs,slashCommand:{label:"Button",icon:c.ButtonIcon,keywords:["button","link","cta","action"],run:(e,t)=>C.trimSlashQueryAndInsertAfter(e,t,ks())}});function Bs(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 vs(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 s=await t(e,{kind:o});return{src:s.src,name:s.name??e.name,mimeType:s.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 Bs(e),name:e.name,mimeType:e.type}}async function Ts(e,t){const n=vs(e.type),{src:o,name:l,mimeType:s}=await En(e,{...t,kind:n});return{block:{id:c.genId(),type:"embed",parentId:null,contentIds:[],props:{kind:n,src:o,name:l,mimeType:s,align:"left",width:100}},runs:[],subtreeBlocks:[]}}const ws=[{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 Rs(e){if(!e)return null;for(const t of ws){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"},As={image:"image/*",video:"video/*",audio:"audio/*",file:"*/*"},rt=20,at=100,js=[{value:"left",Icon:c.AlignLeftIcon,label:"Align left"},{value:"center",Icon:c.AlignCenterIcon,label:"Align center"},{value:"right",Icon:c.AlignRightIcon,label:"Align right"}];function et(e){return Math.min(at,Math.max(rt,Math.round(e)))}function Ls({kind:e,src:t,name:n,alt:o,provider:l}){return e==="image"?a.jsx("img",{className:"be-embed-image",src:t,alt:o||""}):e==="video"?a.jsx("video",{className:"be-embed-video",src:t,controls:!0}):e==="audio"?a.jsx("audio",{className:"be-embed-audio",src:t,controls:!0}):e==="oembed"?a.jsx("iframe",{className:"be-embed-oembed",src:t,title:l?`${l} 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(c.PaperclipIcon,{size:14})," ",n||t]})}function Ns({id:e}){var W,Pe,Ce,He;const t=c.useEditorStore(),n=v.useBlock(e),{uploadFile:o,maxFileSize:l}=c.useFileUpload(),[s,r]=u.useState(""),[i,d]=u.useState(!1),[f,m]=u.useState(null),[p,h]=u.useState(!1),[k,x]=u.useState(""),[b,I]=u.useState(!1),[B,g]=u.useState(null),y=u.useRef(null),w=u.useRef(null),j=u.useCallback(N=>t.applyOperation(c.updateBlockProps(e,N)),[t,e]),O=u.useCallback(()=>{var N;x(((N=n==null?void 0:n.props)==null?void 0:N.alt)??""),h(!0)},[(W=n==null?void 0:n.props)==null?void 0:W.alt]),$=u.useCallback(()=>h(!1),[]),S=u.useCallback(N=>{N.preventDefault(),j({alt:k.trim()}),h(!1)},[k,j]),L=u.useCallback(async(N,K)=>{g(null),I(!0);try{const{src:H,name:q,mimeType:re}=await En(N,{uploadFile:o,maxFileSize:l,kind:K});j({src:H,name:q,mimeType:re})}catch(H){g((H==null?void 0:H.message)||"Upload failed. Please try again.")}finally{I(!1)}},[o,l,j]),_=u.useCallback(N=>{var H,q;const K=(H=N.target.files)==null?void 0:H[0];N.target.value="",K&&L(K,((q=n==null?void 0:n.props)==null?void 0:q.kind)??"file")},[L,(Pe=n==null?void 0:n.props)==null?void 0:Pe.kind]),T=u.useCallback(N=>{var H,q;N.preventDefault(),d(!1);const K=(H=N.dataTransfer.files)==null?void 0:H[0];K&&L(K,((q=n==null?void 0:n.props)==null?void 0:q.kind)??"file")},[L,(Ce=n==null?void 0:n.props)==null?void 0:Ce.kind]),A=u.useCallback(N=>{N.preventDefault(),d(!0)},[]),M=u.useCallback(()=>d(!1),[]),D=u.useCallback(()=>{const N=s.trim();if(!N)return;const K=Rs(N);j(K?{kind:"oembed",src:K.embedUrl,name:N,mimeType:"",provider:K.provider,originalUrl:N}:{src:N,name:N}),r("")},[s,j]),E=u.useCallback(()=>j({src:"",name:"",mimeType:"",provider:"",originalUrl:""}),[j]),P=u.useCallback(N=>{N.preventDefault();const K=y.current,H=w.current;if(!K||!H)return;const q=K.getBoundingClientRect().width,re=H.getBoundingClientRect().width,xe=N.clientX,_e=R=>et((re+(R.clientX-xe))/q*100),Be=R=>m(_e(R)),ve=R=>{document.removeEventListener("mousemove",Be),document.removeEventListener("mouseup",ve),j({width:_e(R)}),m(null)};document.addEventListener("mousemove",Be),document.addEventListener("mouseup",ve)},[j]),z=u.useCallback(N=>{var re;const K=((re=n==null?void 0:n.props)==null?void 0:re.width)??100,H=N.shiftKey?1:5;let q;if(N.key==="ArrowLeft"||N.key==="ArrowDown")q=et(K-H);else if(N.key==="ArrowRight"||N.key==="ArrowUp")q=et(K+H);else if(N.key==="Home")q=rt;else if(N.key==="End")q=at;else return;N.preventDefault(),j({width:q})},[(He=n==null?void 0:n.props)==null?void 0:He.width,j]),G=c.useBlockClassName("be-embed",n);if(!n)return null;const{kind:U="file",src:F,name:V,alt:ne="",align:Z="left",width:X=100,provider:se="",originalUrl:ee=""}=n.props,Q=U==="image"||U==="video"||U==="oembed",fe=f??X,le=U==="oembed";return a.jsxs("div",{className:G,"data-block-id":e,"data-kind":U,contentEditable:!1,tabIndex:-1,children:[F?a.jsx("div",{ref:y,className:`be-embed-preview be-embed-align-${Z}`,children:a.jsxs("div",{ref:w,className:"be-embed-frame",style:Q?{width:`${fe}%`}:void 0,children:[a.jsxs("div",{className:"be-embed-toolbar",contentEditable:!1,children:[js.map(({value:N,Icon:K,label:H})=>a.jsx("button",{type:"button",className:`be-embed-toolbar-btn${Z===N?" be-embed-toolbar-btn-active":""}`,title:H,"aria-label":H,"aria-pressed":Z===N,onClick:()=>j({align:N}),children:a.jsx(K,{size:14})},N)),U==="image"&&a.jsx("button",{type:"button",className:"be-embed-toolbar-btn be-embed-alt-text-btn",onClick:O,children:"Alt text"}),le&&ee&&a.jsx("a",{className:"be-embed-toolbar-btn be-embed-open-original",href:ee,target:"_blank",rel:"noopener noreferrer",title:"Open original link","aria-label":"Open original link",children:a.jsx(c.LinkIcon,{size:14})}),a.jsx("button",{type:"button",className:"be-embed-remove",onClick:E,"aria-label":`Remove ${Ke[U]}`,children:"Remove"})]}),a.jsx(Ls,{kind:U,src:F,name:V,alt:ne,provider:se}),Q&&a.jsx("div",{className:"be-embed-resize-handle",onMouseDown:P,onKeyDown:z,role:"slider",tabIndex:0,"aria-label":`Resize ${Ke[U]}`,"aria-valuemin":rt,"aria-valuemax":at,"aria-valuenow":fe})]})}):a.jsxs("div",{className:`be-embed-dropzone${i?" be-embed-dropzone-active":""}`,onDrop:le||b?void 0:T,onDragOver:le||b?void 0:A,onDragLeave:M,children:[b?a.jsx("span",{className:"be-embed-uploading",children:"Uploading…"}):a.jsxs(a.Fragment,{children:[!le&&a.jsxs(a.Fragment,{children:[a.jsxs("label",{className:"be-embed-upload-btn",children:["Upload ",Ke[U],a.jsx("input",{type:"file",accept:As[U],onChange:_,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:le?"Paste a YouTube, Vimeo, Loom, Figma, CodePen, or Spotify link":`https://... ${Ke[U]} URL`,value:s,onChange:N=>r(N.target.value),onKeyDown:N=>N.key==="Enter"&&D()}),a.jsx("button",{type:"button",className:"be-embed-url-commit",onClick:D,children:"Embed"})]})]}),B&&a.jsxs("div",{className:"be-embed-upload-error",role:"alert",children:[B,a.jsx("button",{type:"button",onClick:()=>g(null),"aria-label":"Dismiss error",children:"×"})]})]}),a.jsx(ae.Modal,{isOpen:p,onClose:$,title:"Alt text",children:a.jsxs("form",{onSubmit:S,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:k,onChange:N=>x(N.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:$,children:"Cancel"}),a.jsx("button",{type:"submit",className:"be-modal-save",children:"Save"})]})]})})]})}function Es({kind:e="file",src:t="",name:n="",alt:o="",mimeType:l="",align:s="left",width:r=100,provider:i="",originalUrl:d=""}={}){return function(m){return{block:{id:c.genId(),type:"embed",parentId:m,contentIds:[],props:{kind:e,src:t,name:n,alt:o,mimeType:l,align:s,width:r,provider:i,originalUrl:d}},runs:[]}}}const jt={image:c.ImageIcon,video:c.VideoIcon,audio:c.AudioIcon,file:c.PaperclipIcon,oembed:c.LinkIcon},Sn="be-embed-file-link",Mn="be-embed-oembed-link";function Ss(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 l,s,r,i;const t=(l=e.style)==null?void 0:l.width,n=t&&t.endsWith("%")?parseInt(t,10):100;let o="left";return((s=e.style)==null?void 0:s.marginLeft)==="auto"&&((r=e.style)==null?void 0:r.marginRight)==="auto"?o="center":((i=e.style)==null?void 0:i.marginLeft)==="auto"&&(o="right"),{align:o,width:Number.isFinite(n)?n:100}}function Ms(e){const{kind:t,src:n,name:o,alt:l="",align:s="left",width:r=100,provider:i="",originalUrl:d=""}=e.props;if(!n)return"<p></p>";const f=Ss(t,s,r);return t==="image"?`<img src="${v.escapeAttr(n)}" alt="${v.escapeAttr(l)}"${f}>`:t==="video"?`<video src="${v.escapeAttr(n)}" controls${f}></video>`:t==="audio"?`<audio src="${v.escapeAttr(n)}" controls></audio>`:t==="oembed"?`<a class="${Mn}" href="${v.escapeAttr(d||n)}" data-embed-url="${v.escapeAttr(n)}" data-embed-provider="${v.escapeAttr(i)}">${v.escapeHTML(d||n)}</a>`:`<a class="${Sn}" href="${v.escapeAttr(n)}">${v.escapeHTML(o||n)}</a>`}function $s(e){const{kind:t,src:n,name:o,originalUrl:l=""}=e.props;return n?t==="oembed"?`[embed: ${l||n}]`:`[${t}: ${o||n}]`:""}function Os(e){const{kind:t,src:n,name:o,alt:l="",originalUrl:s=""}=e.props;return n?t==="image"?``:t==="oembed"?`[${s||n}](${s||n})`:`[${o||n}](${n})`:""}function Ds(e){return e.tagName==="IMG"?Le("image",e.getAttribute("src")??"","",{...tt(e),alt:e.getAttribute("alt")??""}):e.tagName==="VIDEO"?Le("video",e.getAttribute("src")??"","",tt(e)):e.tagName==="AUDIO"?Le("audio",e.getAttribute("src")??"",""):e.tagName==="A"&&e.classList.contains(Mn)?Le("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)?Le("file",e.getAttribute("href")??"",e.textContent??""):null}function Le(e,t,n,{align:o="left",width:l=100,alt:s="",provider:r="",originalUrl:i=""}={}){return{block:{id:c.genId(),type:"embed",parentId:null,contentIds:[],props:{kind:e,src:t,name:n,alt:s,align:o,width:l,provider:r,originalUrl:i}},runs:[]}}function Lt(e){return(t,{blockId:n,runId:o,sliceStart:l,sliceEnd:s})=>{const r=t.getRun(o),i=(r==null?void 0:r.value)??"";t.applyOperation(c.updateRun(o,{value:i.slice(0,l)+i.slice(s)}));const d=C.insertSiblingAfter(t,n,Es({kind:e}));return C.insertSiblingAfterAndFocus(t,d,C.createTextLeafBlock("paragraph")),d}}const $n=v.defineBlock({name:"embed",contentModel:"void",component:Ns,defaultProps:{kind:"file",src:"",name:"",alt:"",mimeType:"",align:"left",width:100,provider:"",originalUrl:""},toHTML:Ms,toPlainText:$s,toMarkdown:Os,fromHTML:Ds,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 Ps(e){ct.add(e)}function On(e){return ct.has(e)?(ct.delete(e),!0):!1}function Dn(e,t,n){var i;const o=e.getBlock(t),l=((i=o==null?void 0:o.props)==null?void 0:i.titleRunIds)??(o==null?void 0:o.contentIds)??[],s=l.indexOf(n),r=s>=0?l[s+1]:void 0;if(r){C.focusRunEnd(r);return}C.insertSiblingAfterAndFocus(e,t,C.createTextLeafBlock("paragraph"))}function Hs({id:e,blockId:t}){const n=c.useEditorStore(),o=v.useRun(e),l=u.useRef(null);l.current===null&&(l.current=On(e));const s=u.useCallback(f=>{n.applyOperation(c.updateRun(e,{data:{...o==null?void 0:o.data,selectedValue:f}})),l.current&&Dn(n,t,e)},[n,e,o==null?void 0:o.data,t]);if(!o)return null;const{options:r=[],selectedValue:i="",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(ge,{value:i,options:r,onChange:s,placeholder:d,ariaLabel:"Select an option",autoOpen:l.current})})}function Qe(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l},s,{autoOpen:r=!1}={}){const i=e.getRun(n),d=(i==null?void 0:i.value)??"",f=d.slice(0,o),m=d.slice(l),p=s(),h={...i,value:f},k={id:c.genId(),type:"text",value:m,marks:{...i==null?void 0:i.marks}};e.applyOperation(c.replaceRunSpan(t,[n],[h,p,k])),r?Ps(p.id):C.focusRunEnd(k.id)}function _s(e){return String(e).replace(/&/g,"&").replace(/"/g,""")}function Pn(e){var o;const{options:t=[],selectedValue:n=""}=e.data??{};return((o=t.find(l=>l.value===n))==null?void 0:o.label)??""}function Fs(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="${_s(((o=e.data)==null?void 0:o.selectedValue)??"")}">${t}</span>`}function Us(e){return Pn(e)}function Ks(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="select"?null:{id:c.genId(),type:"select",value:"",marks:{},data:{options:[],selectedValue:e.getAttribute("data-selected-value")??""}}}const Hn=v.defineInline({name:"select",component:Hs,toHTML:Fs,toPlainText:Us,fromHTML:Ks,slashCommand:{label:"Select",icon:c.SelectIcon,keywords:["select","dropdown","choice","picker"],run:(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l})=>Qe(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l},()=>({id:c.genId(),type:"select",value:"",marks:{},data:{options:[],selectedValue:"",placeholder:"Select…"}}),{autoOpen:!0})}});function zs({id:e}){const t=c.useEditorStore(),n=v.useRun(e),o=u.useCallback(s=>{t.applyOperation(c.updateRun(e,{data:{...n==null?void 0:n.data,isoDate:s.target.value}}))},[t,e,n==null?void 0:n.data]);if(!n)return null;const{isoDate:l=""}=n.data??{};return a.jsx("span",{className:"be-inline-date",onMouseDown:s=>s.stopPropagation(),onKeyDown:s=>s.stopPropagation(),children:a.jsx("input",{type:"date",value:l,onChange:o})})}function Gs(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 Vs(e){var n;const t=((n=e.data)==null?void 0:n.isoDate)??"";return`<span data-inline-type="date" data-iso-date="${Gs(t)}">${_n(t)}</span>`}function qs(e){var t;return _n(((t=e.data)==null?void 0:t.isoDate)??"")}function Ws(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="date"?null:{id:c.genId(),type:"date",value:"",marks:{},data:{isoDate:e.getAttribute("data-iso-date")??""}}}function Qs(){return new Date().toISOString().slice(0,10)}const Fn=v.defineInline({name:"date",component:zs,toHTML:Vs,toPlainText:qs,fromHTML:Ws,slashCommand:{label:"Date",icon:c.DateIcon,keywords:["date","when","schedule","calendar"],run:(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l})=>Qe(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l},()=>({id:c.genId(),type:"date",value:"",marks:{},data:{isoDate:Qs()}}))}});function Ys({id:e}){const t=c.useEditorStore(),n=v.useRun(e),o=u.useCallback(i=>{t.applyOperation(c.updateRun(e,{data:{...n==null?void 0:n.data,checked:i.target.checked}}))},[t,e,n==null?void 0:n.data]),l=u.useCallback(i=>{t.applyOperation(c.updateRun(e,{data:{...n==null?void 0:n.data,label:i.target.value}}))},[t,e,n==null?void 0:n.data]);if(!n)return null;const{checked:s=!1,label:r=""}=n.data??{};return a.jsxs("span",{className:"be-inline-checkbox",onMouseDown:i=>i.stopPropagation(),onKeyDown:i=>i.stopPropagation(),children:[a.jsx("input",{type:"checkbox",className:"be-inline-checkbox-input",checked:s,onChange:o}),a.jsx("input",{type:"text",className:"be-inline-checkbox-label",value:r,onChange:l,placeholder:"Label…"})]})}function Xs(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Js(e){const{checked:t=!1,label:n=""}=e.data??{};return`<span data-inline-type="checkbox" data-checked="${t}">${t?"☑":"☐"} ${Xs(n)}</span>`}function Zs(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:c.genId(),type:"checkbox",value:"",marks:{},data:{checked:e.getAttribute("data-checked")==="true",label:(e.textContent??"").replace(/^[☑☐]\s*/,"")}}}const Un=v.defineInline({name:"checkbox",component:Ys,toHTML:Js,toPlainText:Zs,fromHTML:er,slashCommand:{label:"Checkbox",icon:c.CheckboxIcon,keywords:["checkbox","todo","check","toggle"],run:(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l})=>Qe(e,{blockId:t,runId:n,sliceStart:o,sliceEnd:l},()=>({id:c.genId(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}}))}});function tr({id:e,blockId:t}){var k;const n=c.useEditorStore(),o=v.useRun(e),l=t?n.getBlock(t):null,s=l?n.getBlock(l.parentId):null,r=(s==null?void 0:s.parentId)??null,i=v.useBlock(r),d=s?s.contentIds.indexOf(t):-1,m=(((k=(i&&s?J(i,s.contentIds.length):[])[d])==null?void 0:k.options)??[]).map((x,b)=>({...x,color:x.color??ze(b)})),p=u.useCallback((x,b)=>{n.applyOperation(c.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(ge,{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 lr(e){var t;return((t=e.data)==null?void 0:t.selectedLabel)??""}function sr(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="tableSelect"?null:{id:c.genId(),type:"tableSelect",value:"",marks:{},data:{selectedValue:e.getAttribute("data-selected-value")??"",selectedLabel:e.textContent??""}}}const zn=v.defineInline({name:"tableSelect",component:tr,toHTML:or,toPlainText:lr,fromHTML:sr}),Gn={name:"emoji",kind:"inline"},rr=[$t,Ot,Qt,bn,gn,hn,xn,Cn,Bn,Tn,wn,An,jn,Nn,$n,v.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=pe;exports.BlockErrorBoundary=Dt;exports.BlockGutterRow=Vt;exports.BlockRenderer=ut;exports.CALLOUT_COLORS=vn;exports.COLUMN_TYPES=Yt;exports.CommentPopoverHeader=St;exports.DEFAULT_COLUMN_TYPE=De;exports.DEFAULT_COLUMN_WIDTH=qe;exports.EditableBlockContent=ue;exports.LANGUAGES=Rn;exports.LinkEditModal=Et;exports.MIN_COLUMN_WIDTH=me;exports.Select=ge;exports.TableHeaderRow=fn;exports.TurnIntoSubmenu=Ut;exports.announce=de;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=sn;exports.dividerBlockType=Bn;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=ln;exports.isContentlessBlock=Me;exports.isRunsEmpty=te;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=J;exports.resolveFileToEmbedInsert=Ts;exports.selectInlineType=Hn;exports.setColumnAggregate=cn;exports.setColumnOptions=Ee;exports.setColumnType=un;exports.setColumnWidth=lt;exports.sortTableByColumn=st;exports.starterKit=ar;exports.tableBlockType=bn;exports.tableCellBlockType=hn;exports.tableRowBlockType=gn;exports.tableSelectInlineType=zn;exports.toggleHeadingBlockType=jn;exports.turnBlockInto=Ft;exports.useAutoAdjustedPosition=$e;exports.useBlockChildren=it;exports.useFieldTypes=dn;exports.useMenuKeyboardNav=Ve;exports.useVirtualKeyboardInset=pn;
|
|
27
|
+
//# sourceMappingURL=starter-kit-lPN-NpJ5.cjs.map
|