noteloom 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +1 -1
  2. package/dist/canvas.cjs +1 -1
  3. package/dist/canvas.js +1 -1
  4. package/dist/collab.cjs +1 -1
  5. package/dist/collab.cjs.map +1 -1
  6. package/dist/collab.js +157 -102
  7. package/dist/collab.js.map +1 -1
  8. package/dist/comments.cjs +1 -1
  9. package/dist/comments.js +3 -3
  10. package/dist/index.cjs +2 -1
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.ts +33 -0
  13. package/dist/index.js +1691 -1592
  14. package/dist/index.js.map +1 -1
  15. package/dist/shared/{CommentThreadCard-YziIa8My.cjs → CommentThreadCard-CIB6nZEA.cjs} +2 -2
  16. package/dist/shared/{CommentThreadCard-YziIa8My.cjs.map → CommentThreadCard-CIB6nZEA.cjs.map} +1 -1
  17. package/dist/shared/{CommentThreadCard-CwKd6fp3.js → CommentThreadCard-lW_lbI74.js} +2 -2
  18. package/dist/shared/{CommentThreadCard-CwKd6fp3.js.map → CommentThreadCard-lW_lbI74.js.map} +1 -1
  19. package/dist/shared/{CommentsPanel-DezejDdE.cjs → CommentsPanel-CRxb3RWi.cjs} +2 -2
  20. package/dist/shared/{CommentsPanel-DezejDdE.cjs.map → CommentsPanel-CRxb3RWi.cjs.map} +1 -1
  21. package/dist/shared/{CommentsPanel-dx7IaoqS.js → CommentsPanel-Dg0k_XNU.js} +3 -3
  22. package/dist/shared/{CommentsPanel-dx7IaoqS.js.map → CommentsPanel-Dg0k_XNU.js.map} +1 -1
  23. package/dist/shared/VersionHistory-BsSwOq_k.cjs +12 -0
  24. package/dist/shared/VersionHistory-BsSwOq_k.cjs.map +1 -0
  25. package/dist/shared/{VersionHistory-DhYb8C2e.js → VersionHistory-BzMnJpbc.js} +221 -206
  26. package/dist/shared/VersionHistory-BzMnJpbc.js.map +1 -0
  27. package/dist/shared/VoiceListeningIndicator-B_7-6Mq4.cjs +2 -0
  28. package/dist/shared/VoiceListeningIndicator-B_7-6Mq4.cjs.map +1 -0
  29. package/dist/shared/VoiceListeningIndicator-DeA3hb33.js +342 -0
  30. package/dist/shared/VoiceListeningIndicator-DeA3hb33.js.map +1 -0
  31. package/dist/shared/{icons-D5Ctow8R.js → icons-CmfXmn13.js} +350 -282
  32. package/dist/shared/icons-CmfXmn13.js.map +1 -0
  33. package/dist/shared/{icons-BCseh2pt.cjs → icons-DQ7j_-ZK.cjs} +44 -3
  34. package/dist/shared/icons-DQ7j_-ZK.cjs.map +1 -0
  35. package/dist/shared/{index-D_8hJpI7.js → index-DUigqWQn.js} +52 -52
  36. package/dist/shared/{index-D_8hJpI7.js.map → index-DUigqWQn.js.map} +1 -1
  37. package/dist/shared/{index-CbIBsFmI.cjs → index-vWtS1iyt.cjs} +2 -2
  38. package/dist/shared/{index-CbIBsFmI.cjs.map → index-vWtS1iyt.cjs.map} +1 -1
  39. package/dist/shared/{leafBlockFactory-CaLWUcfa.cjs → leafBlockFactory-6GFBveaC.cjs} +2 -2
  40. package/dist/shared/{leafBlockFactory-CaLWUcfa.cjs.map → leafBlockFactory-6GFBveaC.cjs.map} +1 -1
  41. package/dist/shared/{leafBlockFactory-DSa1XCox.js → leafBlockFactory-Dm6cd2NY.js} +5 -5
  42. package/dist/shared/{leafBlockFactory-DSa1XCox.js.map → leafBlockFactory-Dm6cd2NY.js.map} +1 -1
  43. package/dist/shared/{serialize-BqKU9EZy.js → serialize-R4V4gmHs.js} +2 -2
  44. package/dist/shared/{serialize-BqKU9EZy.js.map → serialize-R4V4gmHs.js.map} +1 -1
  45. package/dist/shared/{serialize-CqwX55uK.cjs → serialize-vLXz0cze.cjs} +2 -2
  46. package/dist/shared/{serialize-CqwX55uK.cjs.map → serialize-vLXz0cze.cjs.map} +1 -1
  47. package/dist/shared/starter-kit-BQUaaql0.cjs +29 -0
  48. package/dist/shared/starter-kit-BQUaaql0.cjs.map +1 -0
  49. package/dist/shared/{starter-kit-mfeNxqFn.js → starter-kit-Bp30PiE4.js} +1545 -1477
  50. package/dist/shared/starter-kit-Bp30PiE4.js.map +1 -0
  51. package/dist/shared/{usePopoverEdgeClamp-CPRWQtZV.cjs → usePopoverEdgeClamp-BJLbbANB.cjs} +2 -2
  52. package/dist/shared/{usePopoverEdgeClamp-CPRWQtZV.cjs.map → usePopoverEdgeClamp-BJLbbANB.cjs.map} +1 -1
  53. package/dist/shared/{usePopoverEdgeClamp-D_hB5t60.js → usePopoverEdgeClamp-DSpz-6xR.js} +2 -2
  54. package/dist/shared/{usePopoverEdgeClamp-D_hB5t60.js.map → usePopoverEdgeClamp-DSpz-6xR.js.map} +1 -1
  55. package/dist/starter-kit.cjs +1 -1
  56. package/dist/starter-kit.js +2 -2
  57. package/dist/style.css +41 -0
  58. package/dist/versions.cjs +1 -1
  59. package/dist/versions.js +1 -1
  60. package/dist/voice.cjs +1 -1
  61. package/dist/voice.js +1 -1
  62. package/package.json +2 -2
  63. package/dist/shared/VersionHistory-DhYb8C2e.js.map +0 -1
  64. package/dist/shared/VersionHistory-DuSxis_7.cjs +0 -12
  65. package/dist/shared/VersionHistory-DuSxis_7.cjs.map +0 -1
  66. package/dist/shared/VoiceListeningIndicator-BXByLZwO.cjs +0 -2
  67. package/dist/shared/VoiceListeningIndicator-BXByLZwO.cjs.map +0 -1
  68. package/dist/shared/VoiceListeningIndicator-bv285FSY.js +0 -338
  69. package/dist/shared/VoiceListeningIndicator-bv285FSY.js.map +0 -1
  70. package/dist/shared/icons-BCseh2pt.cjs.map +0 -1
  71. package/dist/shared/icons-D5Ctow8R.js.map +0 -1
  72. package/dist/shared/starter-kit-DyX1U84W.cjs +0 -27
  73. package/dist/shared/starter-kit-DyX1U84W.cjs.map +0 -1
  74. package/dist/shared/starter-kit-mfeNxqFn.js.map +0 -1
package/dist/comments.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./shared/CommentThreadCard-YziIa8My.cjs"),m=require("./shared/CommentsPanel-DezejDdE.cjs"),o=require("./shared/icons-BCseh2pt.cjs"),t=require("./shared/CommentAvatar-V457IgoQ.cjs");exports.CommentComposer=e.CommentComposer;exports.CommentThreadCard=e.CommentThreadCard;exports.addComment=e.addComment;exports.addCommentMarkOverRange=e.addCommentMarkOverRange;exports.deleteComment=e.deleteComment;exports.removeCommentMarkEverywhere=e.removeCommentMarkEverywhere;exports.replyToComment=e.replyToComment;exports.resolveComment=e.resolveComment;exports.CommentsPanel=m.CommentsPanel;exports.useComments=m.useComments;exports.useCommentAuthorId=o.useCommentAuthorId;exports.CommentAvatar=t.CommentAvatar;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./shared/CommentThreadCard-CIB6nZEA.cjs"),m=require("./shared/CommentsPanel-CRxb3RWi.cjs"),o=require("./shared/icons-DQ7j_-ZK.cjs"),t=require("./shared/CommentAvatar-V457IgoQ.cjs");exports.CommentComposer=e.CommentComposer;exports.CommentThreadCard=e.CommentThreadCard;exports.addComment=e.addComment;exports.addCommentMarkOverRange=e.addCommentMarkOverRange;exports.deleteComment=e.deleteComment;exports.removeCommentMarkEverywhere=e.removeCommentMarkEverywhere;exports.replyToComment=e.replyToComment;exports.resolveComment=e.resolveComment;exports.CommentsPanel=m.CommentsPanel;exports.useComments=m.useComments;exports.useCommentAuthorId=o.useCommentAuthorId;exports.CommentAvatar=t.CommentAvatar;
2
2
  //# sourceMappingURL=comments.cjs.map
package/dist/comments.js CHANGED
@@ -1,6 +1,6 @@
1
- import { C as o, a, b as r, c as t, d as s, r as C, e as n, f as d } from "./shared/CommentThreadCard-CwKd6fp3.js";
2
- import { C as f, u } from "./shared/CommentsPanel-dx7IaoqS.js";
3
- import { u as l } from "./shared/icons-D5Ctow8R.js";
1
+ import { C as o, a, b as r, c as t, d as s, r as C, e as n, f as d } from "./shared/CommentThreadCard-lW_lbI74.js";
2
+ import { C as f, u } from "./shared/CommentsPanel-Dg0k_XNU.js";
3
+ import { u as l } from "./shared/icons-CmfXmn13.js";
4
4
  import { C as h } from "./shared/CommentAvatar-TKqsM8vG.js";
5
5
  export {
6
6
  h as CommentAvatar,
package/dist/index.cjs CHANGED
@@ -1,2 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("./shared/VersionHistory-DuSxis_7.cjs"),m=require("./shared/icons-BCseh2pt.cjs"),pe=require("./shared/fieldRegistry-BoYyW3GH.cjs"),Q=require("./collab.cjs"),K=require("./shared/indexedDbPersistence-BWJ1h5Vp.cjs"),Be=require("./shared/useServiceWorkerUpdate-DQboGesi.cjs"),g=require("react"),d=require("react/jsx-runtime"),z=require("./shared/CommentThreadCard-YziIa8My.cjs"),xe=require("./shared/CommentsPanel-DezejDdE.cjs"),Jt=require("./shared/CommentAvatar-V457IgoQ.cjs"),$=require("./shared/index-CbIBsFmI.cjs"),y=require("./shared/starter-kit-DyX1U84W.cjs"),E=require("./shared/leafBlockFactory-CaLWUcfa.cjs"),X=require("react-dom"),se=require("./shared/serialize-CqwX55uK.cjs"),G=require("./shared/VoiceListeningIndicator-BXByLZwO.cjs"),Z=require("./shared/usePopoverEdgeClamp-CPRWQtZV.cjs"),Xt=500;function Qt(e,t){const n=e??"",o=t??"";let s=0;const r=Math.min(n.length,o.length);for(;s<r&&n[s]===o[s];)s+=1;let a=n.length,l=o.length;for(;a>s&&l>s&&n[a-1]===o[l-1];)a-=1,l-=1;return{beforeOffset:a,afterOffset:l}}function Ke(e){var t;if((e==null?void 0:e.type)==="updateRun"&&typeof((t=e.patch)==null?void 0:t.value)=="string")return e.patch.value;if((e==null?void 0:e.type)==="editRunChars"&&typeof e.previousValue=="string")return e.previousValue}function Pe(e){var l;if(!e.ops.length||!e.inverses.length)return null;const t=e.ops[0],n=e.ops[e.ops.length-1];if(t.type!=="updateRun"||n.type!=="updateRun"||t.id!==n.id||typeof((l=n.patch)==null?void 0:l.value)!="string")return null;const o=e.inverses[e.inverses.length-1],s=Ke(o);if(s===void 0)return null;const{beforeOffset:r,afterOffset:a}=Qt(s,n.patch.value);return{runId:t.id,beforeOffset:r,afterOffset:a}}function _e(e){const t=[],n=o=>{var s;o&&((s=o.block)!=null&&s.id&&t.push(o.block.id),o.blockId&&t.push(o.blockId),o.id&&t.push(o.id),o.parentId&&t.push(o.parentId),o.toParentId&&t.push(o.toParentId))};for(const o of e.ops)n(o);for(const o of e.inverses)n(o);return[...new Set(t)]}class Ve{constructor(t,{idleMs:n=Xt,trackChanges:o=!1,maxChangeLogSize:s=500,defaultActorId:r=null}={}){this.store=t,this.idleMs=n,this.defaultActorId=r,this.undoStack=[],this.redoStack=[],this.currentBatch=null,this.idleTimer=null,this.historyLog=[],this._listeners=new Set,this._undoRedoSnapshot={canUndo:!1,canRedo:!1},this._pendingSelection=null,this._pendingAffectedBlockIds=[],this.trackChanges=o,this.maxChangeLogSize=s,this.changeLog=[]}_recordChange(t,n,o){var a;if(!this.trackChanges)return;const s=t.patch!==void 0&&(n==null?void 0:n.patch)!==void 0,r=s?void 0:Ke(n);this.changeLog.push({opType:t.type,id:t.id??t.blockId??((a=t.block)==null?void 0:a.id),before:s?n.patch:r!==void 0?{value:r}:void 0,after:s||r!==void 0?t.patch:void 0,actorId:o.actorId??null,timestamp:o.timestamp??Date.now()}),this.changeLog.length>this.maxChangeLogSize&&this.changeLog.shift()}getChangeLog(){return[...this.changeLog]}getPendingSelection(){return this._pendingSelection}getPendingAffectedBlockIds(){return this._pendingAffectedBlockIds}getUndoRedoSnapshot(){const t=this.canUndo(),n=this.canRedo();return(this._undoRedoSnapshot.canUndo!==t||this._undoRedoSnapshot.canRedo!==n)&&(this._undoRedoSnapshot={canUndo:t,canRedo:n}),this._undoRedoSnapshot}getBlock(t){return this.store.getBlock(t)}getRun(t){return this.store.getRun(t)}getRootId(){return this.store.getRootId()}getFieldTypes(){return this.store.getFieldTypes()}getFieldType(t){return this.store.getFieldType(t)}getComments(){return this.store.getComments()}getComment(t){return this.store.getComment(t)}getPeople(){return this.store.getPeople()}getPerson(t){return this.store.getPerson(t)}getAllRunIds(){return this.store.getAllRunIds()}subscribe(t,n){return this.store.subscribe(t,n)}subscribeAll(t){return this.store.subscribeAll(t)}getTombstoneCount(){return this.store.getTombstoneCount()}pruneTombstones(t){return this.store.pruneTombstones(t)}toJSON(){return this.store.toJSON()}applyOperation(t,n={}){return this.perform(t,n)}applyOperations(t,n={}){return t.map(o=>this.perform(o,n))}setDefaultActorId(t){this.defaultActorId=t}performBatch(t,n={}){var a;const o=n.actorId??this.defaultActorId,s=n.timestamp??Date.now();this._commitCurrentBatch();const r=[];for(const l of t){const u=this.store.applyOperation(l);r.unshift(u),this.historyLog.push({opType:l.type,id:l.id??l.blockId??((a=l.block)==null?void 0:a.id),actorId:o,timestamp:s}),this._recordChange(l,u,{actorId:o,timestamp:s})}this.redoStack=[],this.undoStack.push({ops:[...t],inverses:r,batchKey:null,actorId:o,timestamp:s,lastTimestamp:s,boundaryHit:!0}),this._notify()}perform(t,n={}){const o=n.actorId??this.defaultActorId,s=n.timestamp??Date.now(),r=this.store.applyOperation(t);return this._record(t,r,{actorId:o,timestamp:s}),r}_batchKeyFor(t){return t.type==="updateRun"?`run:${t.id}`:null}_isWordBoundary(t){var o;if(t.type!=="updateRun")return!1;const n=(o=t.patch)==null?void 0:o.value;return typeof n!="string"||n.length===0?!1:/\s/.test(n[n.length-1])}_record(t,n,o){var l;this.redoStack=[];const s=this._batchKeyFor(t),r=this.currentBatch&&o.timestamp-this.currentBatch.lastTimestamp<=this.idleMs;this.currentBatch&&s!==null&&this.currentBatch.batchKey===s&&r&&!this.currentBatch.boundaryHit?(this.currentBatch.ops.push(t),this.currentBatch.inverses.unshift(n),this.currentBatch.lastTimestamp=o.timestamp,this._isWordBoundary(t)&&(this.currentBatch.boundaryHit=!0)):(this._commitCurrentBatch(),this.currentBatch={ops:[t],inverses:[n],batchKey:s,actorId:o.actorId,timestamp:o.timestamp,lastTimestamp:o.timestamp,boundaryHit:this._isWordBoundary(t)}),this._resetIdleTimer(),this.historyLog.push({opType:t.type,id:t.id??((l=t.block)==null?void 0:l.id),actorId:o.actorId,timestamp:o.timestamp}),this._recordChange(t,n,o),this._notify()}_resetIdleTimer(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this._commitCurrentBatch(),this._notify()},this.idleMs)}_commitCurrentBatch(){this.currentBatch&&(this.undoStack.push(this.currentBatch),this.currentBatch=null,this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null))}flush(){this._commitCurrentBatch(),this._notify()}undo(){this._commitCurrentBatch();const t=this.undoStack.pop();if(!t)return!1;for(const o of t.inverses)this.store.applyOperation(o);this.redoStack.push(t);const n=Pe(t);return this._pendingSelection=n?{runId:n.runId,offset:n.beforeOffset}:null,this._pendingAffectedBlockIds=_e(t),this._notify(),!0}redo(){const t=this.redoStack.pop();if(!t)return!1;for(const o of t.ops)this.store.applyOperation(o);this.undoStack.push(t);const n=Pe(t);return this._pendingSelection=n?{runId:n.runId,offset:n.afterOffset}:null,this._pendingAffectedBlockIds=_e(t),this._notify(),!0}canUndo(){return this.undoStack.length>0||this.currentBatch!==null}canRedo(){return this.redoStack.length>0}getHistoryLog(){return[...this.historyLog]}subscribeToHistory(t){return this._listeners.add(t),()=>this._listeners.delete(t)}_notify(){for(const t of this._listeners)t()}}function Zt({scope:e}={}){const[t,n]=g.useState([]),[o,s]=g.useState(!1),r=g.useCallback(()=>(s(!1),K.listTemplates().then(a=>{n(e?a.filter(l=>l.scope===e):a),s(!0)})),[e]);return g.useEffect(()=>{let a=!1;return s(!1),K.listTemplates().then(l=>{a||(n(e?l.filter(u=>u.scope===e):l),s(!0))}),()=>{a=!0}},[e]),{templates:t,isLoaded:o,refresh:r}}function en({templates:e,onSelect:t,emptyLabel:n="No templates yet."}){return e.length===0?d.jsx("p",{className:"be-template-picker-empty",children:n}):d.jsx("ul",{className:"be-template-picker",role:"list",children:e.map(o=>d.jsxs("li",{className:"be-template-card",children:[d.jsxs("div",{className:"be-template-card-body",children:[d.jsx("span",{className:"be-template-card-name",children:o.name}),o.description&&d.jsx("span",{className:"be-template-card-description",children:o.description})]}),d.jsx("button",{type:"button",className:"be-template-card-select",onClick:()=>t(o),children:"Use"})]},o.id))})}function tn(e,{name:t,color:n}){const o=m.genId();return e.applyOperation(m.addPerson({id:o,name:t,color:n})),o}function nn(e,t,n){e.applyOperation(m.updatePerson(t,n))}function on(e,t){e.applyOperation(m.removePerson(t))}const sn="$people";function rn(){const e=m.useEditorStore(),t=g.useCallback(o=>e.subscribe(sn,o),[e]),n=g.useCallback(()=>e.getPeople(),[e]);return g.useSyncExternalStore(t,n)}class ze{constructor(){this._types=new Map}register(t,n){this._types.set(t,n)}get(t){return this._types.get(t)}isLeaf(t){var n;return!!((n=this._types.get(t))!=null&&n.isLeaf)}listSlashCommands(){const t=[];for(const n of this._types.values())n.slashCommand&&t.push(n.slashCommand),n.slashCommands&&t.push(...n.slashCommands);return t}listHtmlMatchers(){return[...this._types.values()].filter(t=>t.fromHTML)}}function qe(){return new ze}class We{constructor(){this._types=new Map}register(t,n){this._types.set(t,n)}unregister(t){this._types.delete(t)}get(t){return this._types.get(t)}listHtmlMatchers(){return[...this._types.values()].filter(t=>t.fromHTML)}listSlashCommands(){const t=[];for(const n of this._types.values())n.slashCommand&&t.push(n.slashCommand),n.slashCommands&&t.push(...n.slashCommands);return t}listAtCommands(){const t=[];for(const n of this._types.values())n.atCommand&&t.push(n.atCommand),n.atCommands&&t.push(...n.atCommands);return t}}function Ge(){return new We}function Ye(e){Je(e,{paragraph:y.paragraphBlockType,heading:y.headingBlockType,listItem:y.listItemBlockType,...Xe,...Qe,divider:y.dividerBlockType,callout:y.calloutBlockType,blockquote:y.blockquoteBlockType,code:y.codeBlockType,toggleHeading:y.toggleHeadingBlockType,button:y.buttonBlockType,embed:y.embedBlockType,canvas:$.canvasBlockType})}function Je(e,t){for(const[n,o]of Object.entries(t))e.register(n,o)}const Xe={table:y.tableBlockType,tableRow:y.tableRowBlockType,tableCell:y.tableCellBlockType},Qe={layout:y.layoutBlockType,layoutColumn:y.layoutColumnBlockType};function Ze(e){et(e,{select:y.selectInlineType,date:y.dateInlineType,checkbox:y.checkboxInlineType,...tt,emoji:y.emojiInlineType})}function et(e,t){for(const[n,o]of Object.entries(t))e.register(n,o)}const tt={tableSelect:y.tableSelectInlineType},ge={'"':{open:"“",close:"”"},"'":{open:"‘",close:"’"}};function ln(e,t){const n=ge[e];return t===void 0||/[\s([{“‘]/.test(t)?n.open:n.close}function nt(e){return e.inputType!=="insertText"||!e.data||e.data.length!==1?null:e.data}function re(e,t,n){var o;return((o=e.getBlock(t))==null?void 0:o.type)===n}function an(){return $.defineExtension({name:"smart-quotes",onBeforeInput(e,t){const n=nt(t);if(!n||!ge[n])return!1;const o=ge[n],s=e.getSelection();if(s){if(re(e,s.blockId,"code"))return!1;const c=e.getRun(s.runId);if(!c||c.type!=="text")return!1;const i=c.value??"",f=i.slice(0,s.startOffset)+o.open+i.slice(s.startOffset,s.endOffset)+o.close+i.slice(s.endOffset);return e.applyOperation(m.updateRun(c.id,{value:f})),e.setCaret(c.id,s.endOffset+2),!0}const r=e.getCaret();if(!r||re(e,r.blockId,"code"))return!1;const a=e.getRun(r.runId);if(!a||a.type!=="text")return!1;const l=a.value??"",u=ln(n,l[r.offset-1]);return e.applyOperation(m.updateRun(a.id,{value:l.slice(0,r.offset)+u+l.slice(r.offset)})),e.setCaret(a.id,r.offset+1),!0}})}const ot={"(":")","[":"]","{":"}"},cn=new Set(Object.values(ot));function un(){return $.defineExtension({name:"auto-pair-brackets",onBeforeInput(e,t){const n=nt(t);if(!n)return!1;const o=ot[n];if(o){const s=e.getSelection();if(s){if(re(e,s.blockId,"code"))return!1;const u=e.getRun(s.runId);if(!u||u.type!=="text")return!1;const c=u.value??"",i=c.slice(0,s.startOffset)+n+c.slice(s.startOffset,s.endOffset)+o+c.slice(s.endOffset);return e.applyOperation(m.updateRun(u.id,{value:i})),e.setCaret(u.id,s.endOffset+2),!0}const r=e.getCaret();if(!r||re(e,r.blockId,"code"))return!1;const a=e.getRun(r.runId);if(!a||a.type!=="text")return!1;const l=a.value??"";return e.applyOperation(m.updateRun(a.id,{value:l.slice(0,r.offset)+n+o+l.slice(r.offset)})),e.setCaret(a.id,r.offset+1),!0}if(cn.has(n)){const s=e.getCaret();if(!s||re(e,s.blockId,"code"))return!1;const r=e.getRun(s.runId);if(!r||r.type!=="text")return!1;if((r.value??"")[s.offset]===n)return e.setCaret(r.id,s.offset+1),!0}return!1}})}const st={heading:["level"],listItem:["ordered","checked","collapsed"],toggleHeading:["level","collapsed"],code:["language"],button:["href","color","customAttrs"],embed:["kind","src","name","alt","mimeType","align","width"],callout:["icon"]},rt=new Set(["listItem","toggleHeading"]),lt=new Set(["divider","embed"]);function at(e,t,n,o){var l,u,c;const s=n.type,r={};for(const i of st[s]??[])((l=n.props)==null?void 0:l[i])!==void 0&&(r[i]=n.props[i]);if(s==="table"){const i=n.contentIds[0]&&e.getBlock(n.contentIds[0]);return r.columns=y.resolveColumns(n,((u=i==null?void 0:i.contentIds)==null?void 0:u.length)??0),r.rows=n.contentIds.map(f=>e.getBlock(f).contentIds.map(b=>{const p=e.getBlock(b);return $.runsToHTML(p.contentIds.map(k=>e.getRun(k)),o)})),{id:n.id,type:s,data:r}}if(rt.has(s)){const i=((c=n.props)==null?void 0:c.titleRunIds)??[];r.text=$.runsToHTML(i.map(f=>e.getRun(f)),o)}else t.isLeaf(s)&&!lt.has(s)&&(r.text=$.runsToHTML(n.contentIds.map(i=>e.getRun(i)),o));const a={id:n.id,type:s,data:r};return t.isLeaf(s)||(a.children=n.contentIds.map(i=>at(e,t,e.getBlock(i),o))),a}function Se(e,t,n,{pretty:o=!0}={}){const s={store:e,registry:t,inlineRegistry:n},a=e.getBlock(e.getRootId()).contentIds.map(l=>at(e,t,e.getBlock(l),s));return JSON.stringify({version:1,blocks:a},null,o?2:0)}function ke(e,t){const n=new DOMParser().parseFromString(`<div>${e??""}</div>`,"text/html");return y.domInlineToRuns(n.body.firstChild,t)}function dn(e,t,n,o,s){const{id:r=m.genId(),data:a={}}=e,l=(a.rows??[]).map(c=>{const i=m.genId(),f=c.map(h=>{const b=m.genId(),p=ke(h,s);return o.push(...p),n.push({id:b,type:"tableCell",parentId:i,contentIds:p.map(k=>k.id),props:{}}),b});return n.push({id:i,type:"tableRow",parentId:t,contentIds:f,props:{}}),i}),u={id:r,type:"table",parentId:t,contentIds:l,props:{columns:a.columns??[]}};return n.push(u),u}function ye(e,t,n,o,s,r){const{id:a=m.genId(),type:l,data:u={},children:c=[]}=e;if(l==="table")return dn(e,t,s,r,o);const i={};for(const h of st[l]??[])u[h]!==void 0&&(i[h]=u[h]);const f={id:a,type:l,parentId:t,contentIds:[],props:i};if(s.push(f),rt.has(l)){const h=ke(u.text,o);r.push(...h),f.props.titleRunIds=h.map(b=>b.id),f.contentIds=c.map(b=>ye(b,a,n,o,s,r).id)}else if(n.isLeaf(l)){if(!lt.has(l)){const h=ke(u.text,o);r.push(...h),f.contentIds=h.map(b=>b.id)}}else f.contentIds=c.map(h=>ye(h,a,n,o,s,r).id);return f}function ct(e){return!!e&&typeof e=="object"&&Array.isArray(e.blocks)&&e.rootId===void 0&&e.runs===void 0}function it(e,t,n){const o=typeof e=="string"?JSON.parse(e):e,s={registry:t,inlineRegistry:n},r=m.genId(),a=[],l=[],u=(o.blocks??[]).map(c=>ye(c,r,t,s,a,l).id);return a.push({id:r,type:"page",parentId:null,contentIds:u,props:{}}),{rootId:r,blocks:a,runs:l}}function fn(){const e="root",t=m.genId(),n=m.genId();return{rootId:e,blocks:[{id:e,type:"page",parentId:null,contentIds:[t],props:{}},{id:t,type:"paragraph",parentId:e,contentIds:[n],props:{}}],runs:[{id:n,type:"text",value:"",marks:{}}]}}function pn({doc:e,history:t=!0,currentUserId:n=null,extensions:o,registerBlocks:s,registerInlineTypes:r}={}){return g.useMemo(()=>{const a=qe(),l=Ge();o!=null&&$.registerExtensions(o,{registry:a,inlineRegistry:l}),s?s(a):o==null&&Ye(a),r?r(l):o==null&&Ze(l);const u=e==null?fn():ct(e)?it(e,a,l):e,c=new H.EditorStore(u),i=t?new Ve(c,{defaultActorId:n}):c;return{store:i,registry:a,inlineRegistry:l,extensions:o!=null?o.flat(1/0):[],toJSON:({format:f="simple"}={})=>f==="internal"?i.toJSON():JSON.parse(Se(i,a,l))}},[])}function ut({minHeight:e=180,className:t="be-trailing-space"}){const n=m.useEditorStore(),[o]=m.usePreviewMode(),s=g.useCallback(()=>{var c;if(o)return;const r=n.getRootId(),a=n.getBlock(r),l=(c=a==null?void 0:a.contentIds)==null?void 0:c[a.contentIds.length-1];if(!l){const i=y.ensureRootNonEmpty(n);i&&E.focusBlockEnd(n,i);return}const u=n.getBlock(l);(u==null?void 0:u.type)==="paragraph"?E.focusBlockEnd(n,l):E.insertSiblingAfterAndFocus(n,l,E.createTextLeafBlock("paragraph"))},[n,o]);return d.jsx("div",{className:t,style:{minHeight:e},onClick:s})}async function Ie(e,t,n,o){var a,l,u;const{html:s,text:r}=se.serializeBlockRange(e,t,o,n);if(typeof ClipboardItem<"u"&&((a=navigator.clipboard)!=null&&a.write)){await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([r],{type:"text/plain"}),"text/html":new Blob([s],{type:"text/html"})})]);return}await((u=(l=navigator.clipboard)==null?void 0:l.writeText)==null?void 0:u.call(l,r))}function Re(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function le(e,t){t.length!==0&&Re(e,t.map(n=>m.removeBlock(n)))}function dt(e,t){if(t.length===0)return!1;const n=e.getBlock(t[0]);if(!n)return!1;const o=e.getBlock(n.parentId);if(!o)return!1;const s=o.contentIds.indexOf(t[0]),r=o.contentIds.indexOf(t[t.length-1]);if(s<=0)return!1;const a=o.contentIds[s-1];return e.applyOperation(m.moveBlock(a,n.parentId,r)),!0}function ft(e,t){if(t.length===0)return!1;const n=e.getBlock(t[0]);if(!n)return!1;const o=e.getBlock(n.parentId);if(!o)return!1;const s=o.contentIds.indexOf(t[0]),r=o.contentIds.indexOf(t[t.length-1]);if(r===-1||r>=o.contentIds.length-1)return!1;const a=o.contentIds[r+1];return e.applyOperation(m.moveBlock(a,n.parentId,s)),!0}function pt(e,t){return t.length>0&&t.every(n=>{var o,s;return!!((s=(o=e.getBlock(n))==null?void 0:o.props)!=null&&s.hidden)})}function mt(e,t,n){t.length!==0&&Re(e,t.map(o=>m.updateBlockProps(o,{hidden:n})))}function mn(e,t,n,o){const s=n.filter(a=>{var l;return y.isTurnIntoEligible((l=e.getBlock(a))==null?void 0:l.type)});if(s.length===0)return;const r=s.flatMap(a=>y.turnBlockInto(e,t,a,o).ops);Re(e,r)}function hn(e,t){if(t.length===0)return[];const n=e.getBlock(t[0]),o=n&&e.getBlock(n.parentId);if(!o)return t;const s=new Set(t);return o.contentIds.filter(r=>s.has(r))}function ht(){const e=m.useEditorStore(),t=m.useBlockRegistry(),n=m.useInlineRegistry(),[o,s]=m.useBlockRangeSelection(),[r,a]=g.useState(null),l=g.useRef(null),u=g.useRef(null),c=o.length>0,i=y.useAutoAdjustedPosition(l,c,(r==null?void 0:r.bottom)!=null?r.bottom+4:null,r==null?void 0:r.left),f=g.useCallback(()=>s([]),[s]);y.useMenuKeyboardNav(l,c,f,void 0),g.useEffect(()=>{if(!c){a(null);return}const T=()=>{const j=o[o.length-1],L=document.querySelector(`[data-block-row-id="${j}"]`);a((L==null?void 0:L.getBoundingClientRect())??null)};return T(),window.addEventListener("scroll",T,!0),window.addEventListener("resize",T),()=>{window.removeEventListener("scroll",T,!0),window.removeEventListener("resize",T)}},[c,o]),g.useEffect(()=>{if(!c)return;const T=L=>{var w,O,x,A;(w=l.current)!=null&&w.contains(L.target)||(O=u.current)!=null&&O.contains(L.target)||(A=(x=L.target).closest)!=null&&A.call(x,".be-block-gutter")||f()},j=L=>{L.key==="Escape"?f():(L.key==="Delete"||L.key==="Backspace")&&(L.preventDefault(),le(e,o),f())};return document.addEventListener("mousedown",T),document.addEventListener("keydown",j),()=>{document.removeEventListener("mousedown",T),document.removeEventListener("keydown",j)}},[c,e,o,f]);const h=T=>T===1?"block":"blocks",b=g.useCallback(()=>{Ie(e,t,n,o),y.announce(`${o.length} ${h(o.length)} copied`),f()},[e,t,n,o,f]),p=g.useCallback(async()=>{await Ie(e,t,n,o);const T=o.length;le(e,o),y.announce(`${T} ${h(T)} cut`),f()},[e,t,n,o,f]),k=g.useCallback(()=>{const T=o.length;le(e,o),y.announce(`${T} ${h(T)} deleted`),f()},[e,o,f]),C=g.useCallback(()=>{dt(e,o)&&y.announce(`${o.length} ${h(o.length)} moved up`),f()},[e,o,f]),v=g.useCallback(()=>{ft(e,o)&&y.announce(`${o.length} ${h(o.length)} moved down`),f()},[e,o,f]),I=pt(e,o),B=g.useCallback(()=>{mt(e,o,!I),y.announce(I?`${o.length} ${h(o.length)} shown in preview`:`${o.length} ${h(o.length)} hidden in preview`),f()},[e,o,I,f]),R=o.some(T=>{var j;return y.isTurnIntoEligible((j=e.getBlock(T))==null?void 0:j.type)}),S=g.useCallback(T=>{const j=o.length;mn(e,t,o,T),y.announce(`${j} ${h(j)} turned into ${T.label}`),f()},[e,t,o,f]);return!c||!i?null:X.createPortal(d.jsxs("div",{ref:l,role:"menu","aria-label":"Selected blocks options",className:"be-block-range-menu",style:{position:"fixed",top:i.top,left:i.left},children:[d.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:b,children:[d.jsx(m.CopyIcon,{size:15})," Copy"]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:p,children:[d.jsx(m.ScissorsIcon,{size:15})," Cut"]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:C,children:[d.jsx(m.ArrowUpIcon,{size:15})," Move up"]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:v,children:[d.jsx(m.ArrowDownIcon,{size:15})," Move down"]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:B,children:[I?d.jsx(m.EyeIcon,{size:15}):d.jsx(m.EyeOffIcon,{size:15}),I?"Show in preview":"Hide in preview"]}),R&&d.jsx(y.TurnIntoSubmenu,{onSelect:S,onClose:()=>{},containerRef:u,menuClassName:"be-block-range-menu",itemClassName:"be-block-range-menu-item"}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item be-block-range-menu-item-danger",onClick:k,children:[d.jsx(m.TrashIcon,{size:15})," Delete"]})]}),document.body)}const ie="application/x-block-editor-blocks+json";function we(e){return e.split(/\r\n|\r|\n/).filter(t=>t.length>0).map(t=>{const n=m.genId();return{block:{id:m.genId(),type:"paragraph",parentId:null,contentIds:[n],props:{}},runs:[{id:n,type:"text",value:t,marks:{}}]}})}function bt(e,t,n){const o=new DOMParser().parseFromString(e,"text/html"),s={registry:t,inlineRegistry:n},r=t.listHtmlMatchers(),a=[],l=c=>{var h;const i=c.tagName==="OL",f=[];for(const b of c.children){if(b.tagName!=="LI")continue;const p=(h=t.get("listItem"))==null?void 0:h.fromHTML(b,s);p&&(p.block.props.ordered=i,f.push(p))}return f},u=c=>{var f;const i=Array.from(c.children).filter(h=>h.tagName==="P");if(i.length===0){const h=(f=t.get("blockquote"))==null?void 0:f.fromHTML(c,s);return h?[h]:[]}return i.map(h=>{const b=y.domInlineToRuns(h,s);return{block:{id:m.genId(),type:"blockquote",parentId:null,contentIds:b.map(p=>p.id),props:{}},runs:b}})};for(const c of o.body.childNodes){if(c.nodeType===3){const f=c.textContent.trim();f&&a.push(...we(f));continue}if(c.nodeType!==1)continue;if(c.tagName==="UL"||c.tagName==="OL"){a.push(...l(c));continue}if(c.tagName==="BLOCKQUOTE"){a.push(...u(c));continue}let i=null;for(const f of r){const h=f.fromHTML(c,s);if(h){i=h;break}}if(i)a.push(i);else if(c.textContent.trim()){const f=y.domInlineToRuns(c,s);a.push({block:{id:m.genId(),type:"paragraph",parentId:null,contentIds:f.map(h=>h.id),props:{}},runs:f})}}return a}function gt(e,t,n){const o=e.types??[];if(o.includes(ie)){const r=e.getData(ie);if(r)return bn(r)}if(o.includes("text/html")){const r=e.getData("text/html");if(r)return bt(r,t,n)}const s=e.getData("text/plain")??"";return we(s)}function bn(e){return JSON.parse(e).blocks.map(n=>se.remapSubtreeIds(n))}function Ce(e,t){var o;const n=e.getBlock(t);return((o=n.props)==null?void 0:o.titleRunIds)??n.contentIds}function ae(){return{id:m.genId(),type:"text",value:"",marks:{}}}function ve(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Te(e,t,n){const{startRunId:o,startOffset:s,endRunId:r,endOffset:a}=n,l=Ce(e,t),u=l.indexOf(o),c=l.indexOf(r);if(u===-1||c===-1)return null;const[i,f]=u<=c?[u,c]:[c,u],h=u<=c?s:a,b=u<=c?a:s,p=l.slice(0,i).map(S=>e.getRun(S)),k=l.slice(f+1).map(S=>e.getRun(S)),C=l.slice(i,f+1).map(S=>e.getRun(S)),v=[];let I=null,B=0;if(i===f){const S=C[0];if(S.type==="text"){const T=Math.max(0,Math.min(h,b)),j=Math.min(S.value.length,Math.max(h,b)),L={...S,value:S.value.slice(0,T)+S.value.slice(j)};v.push(L),I=L.id,B=T}}else C.forEach((S,T)=>{if(S.type!=="text")return;const j=T===0,L=T===C.length-1,w=j?S.value.slice(0,h):"";if(j&&w){const O={...S,value:w};v.push(O),I=O.id,B=w.length}if(L&&!j){const O=S.value.slice(b);if(O){const x={id:m.genId(),type:"text",value:O,marks:S.marks};v.push(x),I===null&&(I=x.id,B=0)}}});let R=[...p,...v,...k];if(R.length===0){const S=ae();R=[S],I=S.id,B=0}else if(I===null){const S=p[p.length-1];S?(I=S.id,B=S.type==="text"?S.value.length:0):k[0]&&(I=k[0].id,B=0)}return e.applyOperation(m.setBlockRuns(t,R)),{blockId:t,runId:I,offset:B}}function Ee(e,t){const{blockIds:n,startBlockId:o,startRunId:s,startOffset:r,endBlockId:a,endRunId:l,endOffset:u}=t;if(!n||n.length===0)return null;const c=n.indexOf(o),i=n.indexOf(a);if(c===-1||i===-1)return null;const[f,h]=c<=i?[c,i]:[i,c],b=c<=i,p=b?s:l,k=b?r:u,C=b?l:s,v=b?u:r;if(f===h)return Te(e,n[f],{startRunId:p,startOffset:k,endRunId:C,endOffset:v});const I=n[f],B=n[h],R=e.getBlock(I),S=e.getBlock(B),T=Ce(e,I),j=T.indexOf(p),L=T.slice(0,j).map(U=>e.getRun(U)),w=e.getRun(p),O=w.type==="text"&&k>0?{...w,value:w.value.slice(0,k)}:null,x=Ce(e,B),A=x.indexOf(C),D=x.slice(A+1).map(U=>e.getRun(U)),N=e.getRun(C),_=N.type==="text"&&v<N.value.length?{id:m.genId(),type:"text",value:N.value.slice(v),marks:N.marks}:null,F=[...L,...O?[O]:[]],M=[..._?[_]:[],...D],P=[];for(let U=f+1;U<h;U+=1)P.push(m.removeBlock(n[U]));const V=y.canMergeTypes(R.type,S.type),J=e.getBlock(R.parentId),Wt=h-f-1+(V?1:0),Gt=J&&J.contentIds.length-Wt===1;let q,W,me;if(V){const U=[...F,...M];if(U.length===0&&Gt&&R.type!=="paragraph"){const{block:Y,runs:Yt}=E.createTextLeafBlock("paragraph")(J.id);return P.push({type:"insertBlock",block:Y,parentId:J.id,index:0,subtree:{blocks:[Y],runs:Yt}}),P.push(m.removeBlock(I)),P.push(m.removeBlock(B)),ve(e,P),{blockId:Y.id,runId:Y.contentIds[0],offset:0}}const ee=U.length?U:[ae()];if(P.push(m.setBlockRuns(I,ee)),P.push(m.removeBlock(B)),me=I,O)q=O.id,W=O.value.length;else if(L.length){const Y=L[L.length-1];q=Y.id,W=Y.type==="text"?Y.value.length:0}else _?(q=_.id,W=0):D.length?(q=D[0].id,W=0):(q=ee[0].id,W=0)}else{const U=F.length?F:[ae()];if(P.push(m.setBlockRuns(I,U)),P.push(m.setBlockRuns(B,M.length?M:[ae()])),me=I,O)q=O.id,W=O.value.length;else if(L.length){const ee=L[L.length-1];q=ee.id,W=ee.type==="text"?ee.value.length:0}else q=U[0].id,W=0}return ve(e,P),{blockId:me,runId:q,offset:W}}function ue(e,t=""){var l;const n=e.getRootId(),o=((l=e.getBlock(n))==null?void 0:l.contentIds)??[];if(o.length===0)return null;const s=o.map(u=>m.removeBlock(u)),{block:r,runs:a}=E.createTextLeafBlock("paragraph")(n);return t&&(a[0].value=t),s.push(m.insertBlock(r,n,0,{blocks:[r],runs:a})),ve(e,s),{blockId:r.id,runId:r.contentIds[0],offset:t.length}}function he(e){return(e==null?void 0:e.tagName)==="INPUT"||(e==null?void 0:e.tagName)==="TEXTAREA"}function de(e){var n;let t=(e==null?void 0:e.nodeType)===1?e:e==null?void 0:e.parentElement;for(;t&&typeof t.hasAttribute=="function"&&!t.hasAttribute("data-block-id");)t=t.parentElement;return((n=t==null?void 0:t.getAttribute)==null?void 0:n.call(t,"data-block-id"))??null}function gn(e){var f;const t=(f=window.getSelection)==null?void 0:f.call(window);if(!t||t.rangeCount===0)return[];const n=de(t.anchorNode),o=de(t.focusNode);if(!n)return[];if(!o||n===o)return[n];const s=e.getBlock(n),r=s&&e.getBlock(s.parentId);if(!r)return[n];const a=r.contentIds,l=a.indexOf(n),u=a.indexOf(o);if(l===-1||u===-1)return[n];const[c,i]=l<=u?[l,u]:[u,l];return a.slice(c,i+1)}function be(e){const t=E.resolveMultiRunSelection();if(t)return Te(e,t.blockId,t);const n=E.resolveCrossBlockSelection(e);return n?Ee(e,n):null}function kn(e,t,n){const o=e.getRun(t.runId);if(!o||o.type!=="text")return null;const s=o.value??"",r=s.slice(0,t.offset)+n+s.slice(t.offset);return e.applyOperation(m.updateRun(o.id,{value:r})),{blockId:t.blockId,runId:o.id,offset:t.offset+n.length}}function te(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function kt(){const e=m.useEditorStore(),t=m.useBlockRegistry(),n=m.useInlineRegistry(),{uploadFile:o,maxFileSize:s}=m.useFileUpload(),[r,a]=m.useWholeDocumentSelection(),[l,u]=m.useBlockRangeSelection(),c=g.useCallback(b=>{var I;if(he(b.target))return;const p=r?((I=e.getBlock(e.getRootId()))==null?void 0:I.contentIds)??[]:l.length>0?l:gn(e);if(p.length===0)return;const{html:k,text:C,json:v}=se.serializeBlockRange(e,t,p,n);b.clipboardData.setData("text/plain",C),b.clipboardData.setData("text/html",k),b.clipboardData.setData(ie,v),b.preventDefault()},[e,t,n,r,l]),i=g.useCallback(b=>{if(he(b.target))return;if(c(b),r){const k=ue(e);a(!1),k!=null&&k.runId&&E.focusRunAtOffset(k.runId,k.offset);return}if(l.length>0){le(e,l),u([]);return}const p=be(e);p!=null&&p.runId&&E.focusRunAtOffset(p.runId,p.offset)},[c,e,r,a,l,u]),f=g.useCallback(async b=>{var T,j,L;const k=(await Promise.allSettled(b.map(w=>y.resolveFileToEmbedInsert(w,{uploadFile:o,maxFileSize:s})))).filter(w=>w.status==="fulfilled").map(w=>w.value);if(k.length===0)return;if(r){const w=e.getRootId(),x=(((T=e.getBlock(w))==null?void 0:T.contentIds)??[]).map(D=>m.removeBlock(D));let A=0;for(const{block:D,runs:N,subtreeBlocks:_=[]}of k)D.parentId=w,x.push(m.insertBlock(D,w,A,{blocks:[D,..._],runs:N})),A+=1;te(e,x),a(!1);return}if(l.length>0){const w=e.getBlock(l[0]),O=(w==null?void 0:w.parentId)??null,x=O&&e.getBlock(O);let A=x?x.contentIds.indexOf(l[0]):0;const D=l.map(N=>m.removeBlock(N));for(const{block:N,runs:_,subtreeBlocks:F=[]}of k)N.parentId=O,D.push(m.insertBlock(N,O,A,{blocks:[N,...F],runs:_})),A+=1;te(e,D),u([]);return}const C=be(e),v=(C==null?void 0:C.blockId)??de((L=(j=window.getSelection)==null?void 0:j.call(window))==null?void 0:L.anchorNode);if(!v)return;const I=e.getBlock(v);if(!I)return;let R=e.getBlock(I.parentId).contentIds.indexOf(v)+1;const S=[];for(const{block:w,runs:O,subtreeBlocks:x=[]}of k)w.parentId=I.parentId,S.push(m.insertBlock(w,I.parentId,R,{blocks:[w,...x],runs:O})),R+=1;te(e,S)},[e,o,s,r,a,l,u]),h=g.useCallback(b=>{var j,L,w,O;if(he(b.target))return;const p=Array.from(((j=b.clipboardData)==null?void 0:j.files)??[]);if(p.length>0){b.preventDefault(),f(p);return}const k=gt(b.clipboardData,t,n);if(k.length===0)return;if(r){const x=e.getRootId(),D=(((L=e.getBlock(x))==null?void 0:L.contentIds)??[]).map(_=>m.removeBlock(_));let N=0;for(const{block:_,runs:F,subtreeBlocks:M=[]}of k)_.parentId=x,D.push(m.insertBlock(_,x,N,{blocks:[_,...M],runs:F})),N+=1;te(e,D),a(!1),b.preventDefault();return}if(l.length>0){const x=e.getBlock(l[0]),A=(x==null?void 0:x.parentId)??null,D=A&&e.getBlock(A);let N=D?D.contentIds.indexOf(l[0]):0;const _=l.map(F=>m.removeBlock(F));for(const{block:F,runs:M,subtreeBlocks:P=[]}of k)F.parentId=A,_.push(m.insertBlock(F,A,N,{blocks:[F,...P],runs:M})),N+=1;te(e,_),u([]),b.preventDefault();return}const C=be(e);if(k.length===1&&k[0].runs.every(x=>x.type==="text")&&(k[0].subtreeBlocks??[]).length===0){const x=C?{blockId:C.blockId,runId:C.runId,offset:C.offset}:E.resolveCollapsedCaret();if(x){const A=k[0].runs.map(N=>N.value).join(""),D=kn(e,x,A);if(D){E.focusRunAtOffset(D.runId,D.offset),b.preventDefault();return}}}const I=(C==null?void 0:C.blockId)??de((O=(w=window.getSelection)==null?void 0:w.call(window))==null?void 0:O.anchorNode);if(!I)return;const B=e.getBlock(I);if(!B)return;let S=e.getBlock(B.parentId).contentIds.indexOf(I)+1;const T=[];for(const{block:x,runs:A,subtreeBlocks:D=[]}of k)x.parentId=B.parentId,T.push(m.insertBlock(x,B.parentId,S,{blocks:[x,...D],runs:A})),S+=1;te(e,T),b.preventDefault()},[e,t,n,r,a,l,u,f]);return{onCopy:c,onCut:i,onPaste:h}}const yn=["bold","italic","underline","strike","subscript","superscript","code"],In=["color","highlight","link"];function ne(e,t){var o;const n=e.getBlock(t);return((o=n.props)==null?void 0:o.titleRunIds)??n.contentIds}function Cn(e,t){return e===t?!0:e&&t&&typeof e=="object"?JSON.stringify(e)===JSON.stringify(t):!1}function yt(e){var n;const t={};if(e.length===0)return t;for(const o of yn)t[o]=e.every(s=>{var r;return(r=s.marks)==null?void 0:r[o]});for(const o of In){const s=((n=e[0].marks)==null?void 0:n[o])??null;t[o]=e.every(r=>{var a;return Cn(((a=r.marks)==null?void 0:a[o])??null,s)})?s:null}return t}function Oe(e,t,n){const{startRunId:o,startOffset:s,endRunId:r,endOffset:a}=n,l=ne(e,t),u=l.indexOf(o),c=l.indexOf(r);if(u===-1||c===-1)return{};const[i,f]=u<=c?[u,c]:[c,u],h=l.slice(i,f+1).map(b=>e.getRun(b)).filter(b=>b&&b.type==="text");return yt(h)}function Le(e,t){const{blockIds:n,startBlockId:o,endBlockId:s}=t,r=n.indexOf(o),a=n.indexOf(s);if(r===-1||a===-1)return{};const[l,u]=r<=a?[r,a]:[a,r],c=[];for(let i=l;i<=u;i+=1)for(const f of ne(e,n[i])){const h=e.getRun(f);h&&h.type==="text"&&c.push(h)}return yt(c)}function It(e,t){const n={...e};for(const[o,s]of Object.entries(t))s!=null?n[o]=s:delete n[o];return n}function Ct(e,t,n,o,s,r){const a=It(n.marks,r);if(o===0&&s===n.value.length)return e.applyOperation({type:"updateRun",id:n.id,patch:{marks:a}}),n.id;const l=n.value.slice(0,o),u=n.value.slice(o,s),c=n.value.slice(s),i=[];l&&i.push({id:m.genId(),type:"text",value:l,marks:{...n.marks}});const f={id:m.genId(),type:"text",value:u,marks:a};return i.push(f),c&&i.push({id:m.genId(),type:"text",value:c,marks:{...n.marks}}),e.applyOperation(m.replaceRunSpan(t,[n.id],i)),f.id}function vn(e,t,n,o){const{startRunId:s,startOffset:r,endRunId:a,endOffset:l}=n,u=ne(e,t),c=u.indexOf(s),i=u.indexOf(a);if(c===-1||i===-1)return null;const[f,h]=c<=i?[c,i]:[i,c],b=c<=i?r:l,p=c<=i?l:r,k=u.slice(f,h+1),C=k.map(B=>e.getRun(B));if(f===h){const B=C[0];if(B.type!=="text")return B.id;const R=Math.max(0,Math.min(b,p)),S=Math.min(B.value.length,Math.max(b,p));return R===S?B.id:Ct(e,t,B,R,S,o)}const v=[];let I=null;return C.forEach((B,R)=>{if(B.type!=="text"){v.push(B),I=B.id;return}const S=R===0,T=R===C.length-1,j=S?b:0,L=T?p:B.value.length,w=B.value.slice(0,j),O=B.value.slice(j,L),x=B.value.slice(L);w&&v.push({id:m.genId(),type:"text",value:w,marks:{...B.marks}});const A={id:m.genId(),type:"text",value:O,marks:It(B.marks,o)};v.push(A),I=A.id,x&&v.push({id:m.genId(),type:"text",value:x,marks:{...B.marks}})}),e.applyOperation(m.replaceRunSpan(t,k,v)),I}function Bn(e,t,n,o){var p;const{startRunId:s,startOffset:r,endRunId:a,endOffset:l}=n,u=ne(e,t),c=u.indexOf(s),i=u.indexOf(a);if(c===-1||i===-1)return!0;const[f,h]=c<=i?[c,i]:[i,c],b=u.slice(f,h+1).map(k=>e.getRun(k)).filter(k=>k.type==="text");if(b.length===0)return!0;if(f===h){const k=Math.max(0,Math.min(r,l)),C=Math.min(b[0].value.length,Math.max(r,l));if(k===C)return!((p=b[0].marks)!=null&&p[o])}return!b.every(k=>{var C;return(C=k.marks)==null?void 0:C[o]})}function xn(e,t,n,o,s,r){var f;const a=e.getRun(n),l=a.value??"",u=Math.max(0,Math.min(o,s)),c=Math.min(l.length,Math.max(o,s));if(u===c)return n;const i=!((f=a.marks)!=null&&f[r]);return Ct(e,t,a,u,c,{[r]:i?!0:null})}function oe(e,t,n,o){return vn(e,t,n,o)}function Me(e,t,n,o){const s=Bn(e,t,n,o);return oe(e,t,n,{[o]:s?!0:null})}function je(e,t,n){return fe(e,t,o=>({[n]:o?null:!0}),n)}function fe(e,t,n,o){var T;const{blockIds:s,startBlockId:r,startRunId:a,startOffset:l,endBlockId:u,endRunId:c,endOffset:i}=t;if(!s||s.length===0)return null;const f=s.indexOf(r),h=s.indexOf(u);if(f===-1||h===-1)return null;const[b,p]=f<=h?[f,h]:[h,f],k=f<=h,C=k?a:c,v=k?l:i,I=k?c:a,B=k?i:l;let R=n;if(typeof n=="function"){let j=!1,L=!0;for(let w=b;w<=p;w+=1){const O=ne(e,s[w]).map(x=>e.getRun(x)).filter(x=>x.type==="text");O.length!==0&&(j=!0,O.every(x=>{var A;return(A=x.marks)==null?void 0:A[o]})||(L=!1))}R=n(j&&L)}if(b===p)return oe(e,s[b],{startRunId:C,startOffset:v,endRunId:I,endOffset:B},R);let S=null;for(let j=b;j<=p;j+=1){const L=s[j],w=ne(e,L),O=w[0],x=w[w.length-1],A=e.getRun(x),D=((T=A==null?void 0:A.value)==null?void 0:T.length)??0;let N;j===b&&j===p?N={startRunId:C,startOffset:v,endRunId:I,endOffset:B}:j===b?N={startRunId:C,startOffset:v,endRunId:x,endOffset:D}:j===p?N={startRunId:O,startOffset:0,endRunId:I,endOffset:B}:N={startRunId:O,startOffset:0,endRunId:x,endOffset:D},S=oe(e,L,N,R)}return S}function vt(e,t){var o;const n=e.getBlock(t);return((o=n==null?void 0:n.props)==null?void 0:o.titleRunIds)??(n==null?void 0:n.contentIds)??[]}function Bt(e){const t=E.resolveMultiRunSelection();if(!t)return!1;const{blockId:n,startRunId:o,startOffset:s,endRunId:r,endOffset:a}=t,l=vt(e,n);if(l.length===0)return!1;const u=l.indexOf(o),c=l.indexOf(r);if(u===-1||c===-1)return!1;const[i,f]=u<=c?[u,c]:[c,u],h=u<=c?s:a,b=u<=c?a:s;if(i!==0||f!==l.length-1||h!==0)return!1;const p=e.getRun(l[l.length-1]),k=(p==null?void 0:p.type)==="text"?(p.value??"").length:1;return b===k}function Sn(e){const t=E.resolveCollapsedCaret();return t?y.isRunsEmpty(e,vt(e,t.blockId)):!1}function Rn(e,t,n){var b,p;const o=e.getBlock(t);if(!o){n(null);return}const s=e.getBlock(o.parentId),r=s?s.contentIds.indexOf(t):-1,a=r>0?s.contentIds[r-1]:null,l=r!==-1&&r<s.contentIds.length-1?s.contentIds[r+1]:null;e.applyOperation(m.removeBlock(t)),n(null);const u=y.ensureRootNonEmpty(e),c=a??l??u;if(!c)return;const i=e.getBlock(c);if(y.isContentlessBlock(e,i)){n(c),requestAnimationFrame(()=>{var k;return(k=document.querySelector(`[data-block-id="${c}"]`))==null?void 0:k.focus()});return}const f=(b=i==null?void 0:i.props)==null?void 0:b.titleRunIds,h=((p=i==null?void 0:i.contentIds)==null?void 0:p[i.contentIds.length-1])??(f==null?void 0:f[f.length-1]);h&&E.focusRunEnd(h)}const Fe={b:"bold",i:"italic",u:"underline"};function xt(e){const t=m.useEditorStore(),[n,o]=m.useWholeDocumentSelection(),{getSelectedBlockId:s,setSelectedBlockId:r}=m.useSelectedBlock();g.useEffect(()=>{const a=e.current;if(!a)return;const l=c=>{var f,h;if(s()&&(c.key==="Backspace"||c.key==="Delete")&&!c.defaultPrevented){c.preventDefault(),c.stopPropagation(),Rn(t,s(),r);return}if(s()&&c.key!=="Backspace"&&c.key!=="Delete"&&r(null),c.metaKey||c.ctrlKey){const b=c.key.toLowerCase();if(b==="z"&&!c.shiftKey){c.preventDefault(),(f=t.undo)!=null&&f.call(t)&&G.restoreSelectionAfterHistoryChange(t);return}if(b==="z"&&c.shiftKey||b==="y"){c.preventDefault(),(h=t.redo)!=null&&h.call(t)&&G.restoreSelectionAfterHistoryChange(t);return}if(b==="a"){if(n)return;(Bt(t)||Sn(t))&&(c.preventDefault(),o(!0));return}if(Fe[b]){if(n)return;c.preventDefault();const p=Fe[b],k=E.resolveMultiRunSelection();if(k){const v=Me(t,k.blockId,k,p);v&&E.focusRunEnd(v);return}const C=E.resolveCrossBlockSelection(t);if(C){const v=je(t,C,p);v&&E.focusRunEnd(v)}}return}if(n){if(c.key==="Backspace"||c.key==="Delete"){c.preventDefault(),c.stopPropagation();const b=ue(t);o(!1),b!=null&&b.runId&&E.focusRunAtOffset(b.runId,b.offset);return}if(c.key.length===1){c.preventDefault(),c.stopPropagation();const b=ue(t,c.key);o(!1),b!=null&&b.runId&&E.focusRunAtOffset(b.runId,b.offset);return}if(o(!1),c.key==="Escape")return}if(c.key==="Backspace"||c.key==="Delete"){const b=E.resolveCrossBlockSelection(t);if(!b)return;c.preventDefault(),c.stopPropagation();const p=Ee(t,b);p!=null&&p.runId&&E.focusRunAtOffset(p.runId,p.offset)}},u=()=>{n&&o(!1),s()&&r(null)};return a.addEventListener("keydown",l),a.addEventListener("mousedown",u),()=>{a.removeEventListener("keydown",l),a.removeEventListener("mousedown",u)}},[e,t,n,o,s,r])}function wn(e,t){const n=m.useEditorStore(),o=m.useBlockRegistry(),s=m.useInlineRegistry(),r=g.useMemo(()=>(e??[]).filter(l=>l&&(l.keymap||l.onBeforeInput||l.onPaste||l.setup)),[e]),a=g.useMemo(()=>({store:n,registry:o,inlineRegistry:s,get container(){return t.current},getBlock:l=>n.getBlock(l),getRun:l=>n.getRun(l),getRootId:()=>n.getRootId(),applyOperation:l=>X.flushSync(()=>n.applyOperation(l)),applyOperations:l=>X.flushSync(()=>{if(typeof n.performBatch=="function")n.performBatch(l);else for(const u of l)n.applyOperation(u)}),getSelection:()=>E.resolveRunSelection(),getCaret:()=>E.resolveCollapsedCaret(),setCaret:(l,u)=>E.setCaretSync(l,u),subscribe:l=>n.subscribeAll(l)}),[n,o,s,t]);g.useEffect(()=>{const l=t.current;if(!l||r.length===0)return;const u=r.filter(p=>p.keymap),c=r.filter(p=>p.onBeforeInput),i=r.filter(p=>p.onPaste),f=p=>{for(const k of u)for(const[C,v]of Object.entries(k.keymap))if(Tn(p,C)&&v(a,p)){p.preventDefault(),p.stopImmediatePropagation();return}},h=p=>{for(const k of c)if(k.onBeforeInput(a,p)){p.preventDefault(),p.stopImmediatePropagation();return}},b=p=>{for(const k of i)if(k.onPaste(a,p)){p.preventDefault(),p.stopImmediatePropagation();return}};return u.length&&l.addEventListener("keydown",f),c.length&&l.addEventListener("beforeinput",h),i.length&&l.addEventListener("paste",b),()=>{l.removeEventListener("keydown",f),l.removeEventListener("beforeinput",h),l.removeEventListener("paste",b)}},[r,t,a]),g.useEffect(()=>{const l=r.filter(u=>u.setup).map(u=>u.setup(a)).filter(u=>typeof u=="function");return()=>{for(const u of l)u()}},[r,a])}function Tn(e,t){const n=String(t).split("-"),o=n.pop().toLowerCase(),s=new Set(n.map(a=>a.toLowerCase())),r=e.metaKey||e.ctrlKey;return s.has("mod")!==r||s.has("shift")!==e.shiftKey||s.has("alt")!==e.altKey?!1:e.key.toLowerCase()===o}const En=4;function On(e,t,n){const o=e.getBlock(t);if(!o)return[];const s=e.getBlock(o.parentId);if(!s)return[t];const r=s.contentIds,a=r.indexOf(t),l=n?r.indexOf(n):a;if(a===-1)return[t];const[u,c]=l===-1?[a,a]:[Math.min(a,l),Math.max(a,l)];return r.slice(u,c+1)}function Ln(){var e,t;return typeof window<"u"&&((t=(e=window.matchMedia)==null?void 0:e.call(window,"(pointer: coarse)"))==null?void 0:t.matches)===!0}function St(e){const t=m.useEditorStore(),[,n]=m.useBlockRangeSelection(),o=g.useRef(null),s=g.useRef(!1),r=g.useRef(null),a=g.useCallback(i=>{var b,p,k,C,v;if(!o.current)return;if(!s.current){const{x:I,y:B}=r.current??{x:i.clientX,y:i.clientY};if(Math.hypot(i.clientX-I,i.clientY-B)<En)return;s.current=!0,document.documentElement.classList.add("be-block-range-dragging"),(p=(b=window.getSelection)==null?void 0:b.call(window))==null||p.removeAllRanges()}(C=(k=window.getSelection)==null?void 0:k.call(window))==null||C.removeAllRanges(),i.preventDefault();const f=(v=document.elementFromPoint(i.clientX,i.clientY))==null?void 0:v.closest("[data-block-row-id]"),h=(f==null?void 0:f.getAttribute("data-block-row-id"))??null;n(On(t,o.current,h))},[t,n]),l=g.useCallback(()=>{o.current=null,s.current=!1,r.current=null,document.documentElement.classList.remove("be-block-range-dragging")},[]),u=g.useCallback((i,f)=>{o.current=i,s.current=!1,r.current={x:f.clientX,y:f.clientY}},[]),c=g.useCallback(i=>{var k,C;if(i.button!==0||Ln()||(C=(k=i.target).closest)!=null&&C.call(k,"button, input, textarea, select"))return;const f=i.target.closest("[data-block-row-id]");if(f){if(i.target.closest(".be-block-row-content"))return;u(f.getAttribute("data-block-row-id"),i);return}const h=e==null?void 0:e.current;if(!h)return;const p=[...h.querySelectorAll("[data-block-row-id]")].find(v=>{const I=v.getBoundingClientRect();return i.clientY>=I.top&&i.clientY<=I.bottom});p&&u(p.getAttribute("data-block-row-id"),i)},[e,u]);g.useEffect(()=>(document.addEventListener("mousedown",c),document.addEventListener("mousemove",a),document.addEventListener("mouseup",l),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",l),document.documentElement.classList.remove("be-block-range-dragging")}),[c,a,l])}const Mn=340;function jn(e,t,n,o){g.useEffect(()=>{if(!e||!t)return;const s=document.querySelector(`[data-run-id="${t}"]`);if(s)return s.setAttribute("aria-expanded","true"),s.setAttribute("aria-haspopup","listbox"),s.setAttribute("aria-controls",o),n&&s.setAttribute("aria-activedescendant",n),()=>{s.removeAttribute("aria-expanded"),s.removeAttribute("aria-haspopup"),s.removeAttribute("aria-controls"),s.removeAttribute("aria-activedescendant")}},[e,t,n,o])}function ce({isOpen:e,rect:t,commands:n,runId:o,onSelect:s,onClose:r,menuId:a="be-slash-menu",ariaLabel:l="Slash commands"}){const[u,c]=g.useState(0),i=g.useRef(null),f=g.useRef(null),h=y.useVirtualKeyboardInset(),b=Z.useHorizontalAutoAdjustedLeft(f,e&&n.length>0&&!!t,t==null?void 0:t.left);g.useEffect(()=>{c(0)},[n.length]),g.useEffect(()=>{var B,R;(R=(B=i.current)==null?void 0:B.scrollIntoView)==null||R.call(B,{block:"nearest"})},[u]),g.useEffect(()=>{if(!e)return;const B=R=>{R.key==="ArrowDown"?(R.preventDefault(),R.stopPropagation(),c(S=>Math.min(S+1,Math.max(n.length-1,0)))):R.key==="ArrowUp"?(R.preventDefault(),R.stopPropagation(),c(S=>Math.max(S-1,0))):R.key==="Enter"?(R.preventDefault(),R.stopPropagation(),n[u]&&s(n[u])):R.key==="Escape"&&(R.preventDefault(),R.stopPropagation(),r())};return document.addEventListener("keydown",B,!0),()=>document.removeEventListener("keydown",B,!0)},[e,n,u,s,r]);const k=n[u]?`${a}-option-${u}`:null;if(jn(e,o,k,a),!e||n.length===0||!t||b==null)return null;const C=window.innerHeight-h,I=t.bottom+Mn>C?{bottom:window.innerHeight-t.top+4}:{top:t.bottom+4};return d.jsx("div",{ref:f,id:a,role:"listbox","aria-label":l,className:"be-slash-menu",style:{position:"fixed",left:b,zIndex:1e3,...I},children:n.map((B,R)=>{const S=B.icon;return d.jsxs("div",{ref:R===u?i:void 0,id:`${a}-option-${R}`,role:"option","aria-selected":R===u,className:`be-slash-menu-item${R===u?" be-slash-menu-item-active":""}`,onMouseDown:T=>{T.preventDefault(),s(B)},onMouseEnter:()=>c(R),children:[S&&d.jsx("span",{className:"be-slash-menu-item-icon",children:d.jsx(S,{size:16})}),d.jsx("span",{className:"be-slash-menu-item-label",children:B.label})]},B.label)})})}function An(e,t){var o;if(!t)return!0;const n=t.toLowerCase();return e.label.toLowerCase().includes(n)||((o=e.keywords)==null?void 0:o.some(s=>s.toLowerCase().includes(n)))}function Dn(e,t){const n=t.anchorNode,o=t.anchorOffset;let s;if(n===e){s="";for(let r=0;r<o&&r<e.childNodes.length;r+=1)s+=e.childNodes[r].textContent??""}else n&&n.parentElement===e?s=(n.textContent??"").slice(0,o):s=e.textContent??"";return E.stripEmptyRunPlaceholder(s).length}function Ae(e,t,n){const o=m.useEditorStore(),[s,r]=g.useState(null);g.useEffect(()=>{const c=e.current;if(!c)return;const i=()=>{var S,T,j,L;const h=(S=window.getSelection)==null?void 0:S.call(window),b=h==null?void 0:h.anchorNode;let p=(b==null?void 0:b.nodeType)===1?b:b==null?void 0:b.parentElement;for(;p&&typeof p.hasAttribute=="function"&&!p.hasAttribute("data-run-id");)p=p.parentElement;const k=(T=p==null?void 0:p.getAttribute)==null?void 0:T.call(p,"data-run-id");if(!k||!h){r(null);return}const C=Dn(p,h),v=E.stripEmptyRunPlaceholder(p.textContent).slice(0,C),I=t.exec(v);if(!I){r(null);return}const B=(L=(j=p.closest)==null?void 0:j.call(p,"[data-block-id]"))==null?void 0:L.getAttribute("data-block-id");if(!B){r(null);return}const R=I.index+I[1].length;r({query:I[2],blockId:B,runId:k,sliceStart:R,sliceEnd:C,rect:p.getBoundingClientRect()})},f=h=>{h.key==="Escape"&&r(null)};return c.addEventListener("input",i),c.addEventListener("keydown",f),()=>{c.removeEventListener("input",i),c.removeEventListener("keydown",f)}},[e,t]);const a=s?n().filter(c=>An(c,s.query)):[],l=g.useCallback(c=>{s&&(c.run(o,{blockId:s.blockId,runId:s.runId,sliceStart:s.sliceStart,sliceEnd:s.sliceEnd}),r(null))},[s,o]),u=g.useCallback(()=>r(null),[]);return{isOpen:!!s,query:(s==null?void 0:s.query)??"",rect:(s==null?void 0:s.rect)??null,runId:(s==null?void 0:s.runId)??null,commands:a,selectCommand:l,close:u}}const Nn=/(^|\s)\/(\w*)$/;function Rt(e){const t=m.useBlockRegistry(),n=m.useInlineRegistry(),o=g.useCallback(()=>[...t.listSlashCommands(),...(n==null?void 0:n.listSlashCommands())??[]],[t,n]);return Ae(e,Nn,o)}const Pn=[{char:"😀",name:"grinning face",keywords:["smile","happy"]},{char:"😂",name:"face with tears of joy",keywords:["laugh","lol"]},{char:"😍",name:"heart eyes",keywords:["love","crush"]},{char:"😎",name:"cool",keywords:["sunglasses"]},{char:"🤔",name:"thinking face",keywords:["hmm"]},{char:"😉",name:"winking face",keywords:["wink"]},{char:"😢",name:"crying face",keywords:["sad","tear"]},{char:"😡",name:"angry face",keywords:["mad","rage"]},{char:"😱",name:"screaming face",keywords:["shock","scared"]},{char:"🥳",name:"party face",keywords:["celebrate","birthday"]},{char:"🙏",name:"folded hands",keywords:["please","pray","thanks"]},{char:"👍",name:"thumbs up",keywords:["approve","yes","like"]},{char:"👎",name:"thumbs down",keywords:["disapprove","no"]},{char:"👏",name:"clapping hands",keywords:["applause","congrats"]},{char:"🙌",name:"raised hands",keywords:["hooray","yay"]},{char:"👋",name:"waving hand",keywords:["hello","bye"]},{char:"✌️",name:"victory hand",keywords:["peace"]},{char:"💪",name:"flexed biceps",keywords:["strong","muscle"]},{char:"🤝",name:"handshake",keywords:["deal","agree"]},{char:"❤️",name:"red heart",keywords:["love"]},{char:"🔥",name:"fire",keywords:["hot","lit"]},{char:"⭐",name:"star",keywords:["favorite"]},{char:"✨",name:"sparkles",keywords:["shiny","magic"]},{char:"🎉",name:"party popper",keywords:["celebrate","congrats"]},{char:"🎊",name:"confetti ball",keywords:["celebrate"]},{char:"💡",name:"light bulb",keywords:["idea","tip"]},{char:"✅",name:"check mark",keywords:["done","yes","complete"]},{char:"❌",name:"cross mark",keywords:["no","wrong","delete"]},{char:"⚠️",name:"warning",keywords:["caution","alert"]},{char:"❓",name:"question mark",keywords:["question","help"]},{char:"❗",name:"exclamation mark",keywords:["important","alert"]},{char:"🚀",name:"rocket",keywords:["launch","fast","ship"]},{char:"🐛",name:"bug",keywords:["bug","issue"]},{char:"🔧",name:"wrench",keywords:["fix","tool","settings"]},{char:"📌",name:"pushpin",keywords:["pin","note"]},{char:"📎",name:"paperclip",keywords:["attachment","clip"]},{char:"📅",name:"calendar",keywords:["date","schedule"]},{char:"⏰",name:"alarm clock",keywords:["time","reminder"]},{char:"📈",name:"chart increasing",keywords:["growth","stats"]},{char:"📉",name:"chart decreasing",keywords:["decline","stats"]},{char:"💰",name:"money bag",keywords:["money","cash"]},{char:"💬",name:"speech balloon",keywords:["comment","chat"]},{char:"📝",name:"memo",keywords:["note","write"]},{char:"📚",name:"books",keywords:["reading","docs"]},{char:"🔗",name:"link",keywords:["url","chain"]},{char:"🔒",name:"locked",keywords:["private","secure"]},{char:"🔑",name:"key",keywords:["password","access"]},{char:"☕",name:"coffee",keywords:["coffee","break"]},{char:"🍕",name:"pizza",keywords:["food"]},{char:"🎂",name:"birthday cake",keywords:["birthday","cake"]},{char:"🎁",name:"gift",keywords:["present"]},{char:"🌟",name:"glowing star",keywords:["star","shiny"]},{char:"🌈",name:"rainbow",keywords:["colorful"]},{char:"☀️",name:"sun",keywords:["sunny","weather"]},{char:"🌧️",name:"rain cloud",keywords:["rainy","weather"]},{char:"🐶",name:"dog face",keywords:["dog","pet"]},{char:"🐱",name:"cat face",keywords:["cat","pet"]},{char:"🌍",name:"globe",keywords:["world","earth"]},{char:"🎯",name:"direct hit",keywords:["target","goal"]},{char:"🏆",name:"trophy",keywords:["win","award"]},{char:"🕐",name:"clock",keywords:["time"]},{char:"📣",name:"megaphone",keywords:["announce","shout"]},{char:"🧠",name:"brain",keywords:["smart","idea","mind"]},{char:"👀",name:"eyes",keywords:["look","watching"]}];function _n(e,{runId:t,sliceStart:n,sliceEnd:o},s){const r=e.getRun(t),a=(r==null?void 0:r.value)??"",l=a.slice(0,n)+s+a.slice(o);e.applyOperation(m.updateRun(t,{value:l})),E.focusRunAtOffset(t,n+s.length)}const Fn=Pn.map(({char:e,name:t,keywords:n})=>({label:`${e} ${t}`,keywords:n,run:(o,s)=>_n(o,s,e)})),Hn=/(^|\s):(\w*)$/,$n=()=>Fn;function wt(e){return Ae(e,Hn,$n)}const Un=/(^|\s)@(\w*)$/;function Tt(e){const t=m.useInlineRegistry(),n=g.useCallback(()=>(t==null?void 0:t.listAtCommands())??[],[t]);return Ae(e,Un,n)}function De(e,t,n,o,s){const[r,a]=g.useState(!1),l=g.useCallback(C=>{const v=t==="same-block"?oe(e,n.blockId,n,C):fe(e,o,C);return v&&E.focusRunEnd(v),v},[e,t,n,o]),u=g.useCallback(C=>{const v=t==="same-block"?Me(e,n.blockId,n,C):je(e,o,C);v&&E.focusRunEnd(v)},[e,t,n,o]),c=g.useCallback(C=>{const v=C==="subscript"?"superscript":"subscript",I=!s[C];l({[C]:I?!0:null,[v]:null})},[s,l]),i=g.useRef(null),f=g.useCallback(()=>{i.current={kind:t,selection:n,crossSelection:o},a(!0)},[t,n,o]),h=g.useCallback(()=>a(!1),[]),b=g.useCallback(C=>{const v=i.current;if(!v)return;const I=v.kind==="same-block"?oe(e,v.selection.blockId,v.selection,C):fe(e,v.crossSelection,C);I&&E.focusRunEnd(I),a(!1)},[e]),p=g.useCallback((C,v)=>b({link:{href:C,target:v}}),[b]),k=g.useCallback(()=>b({link:null}),[b]);return{applyPatch:l,toggleBoolean:u,setSubSuper:c,isLinkModalOpen:r,openLinkModal:f,closeLinkModal:h,handleSaveLink:p,handleRemoveLink:k}}const Kn="be-touch-input";function Vn(){var e,t;return typeof window<"u"&&((t=(e=window.matchMedia)==null?void 0:e.call(window,"(pointer: coarse)"))==null?void 0:t.matches)===!0}function Ne(){const[e,t]=g.useState(Vn);return g.useEffect(()=>{if(typeof window>"u")return;const n=o=>{t(o.pointerType==="touch"||o.pointerType==="pen")};return window.addEventListener("pointerdown",n,{passive:!0}),()=>window.removeEventListener("pointerdown",n)},[]),g.useEffect(()=>{var n;(n=document.documentElement)==null||n.classList.toggle(Kn,e)},[e]),e}const zn=[{markName:"bold",Icon:m.BoldIcon,title:"Bold (Ctrl+B)"},{markName:"italic",Icon:m.ItalicIcon,title:"Italic (Ctrl+I)"},{markName:"underline",Icon:m.UnderlineIcon,title:"Underline (Ctrl+U)"},{markName:"strike",Icon:m.StrikethroughIcon,title:"Strikethrough"}],qn=[{label:"Default",value:null},{label:"Red",value:"#e03131"},{label:"Orange",value:"#e8590c"},{label:"Green",value:"#2f9e44"},{label:"Blue",value:"#1971c2"},{label:"Purple",value:"#9c36b5"}],Wn=[{label:"None",value:null},{label:"Yellow",value:"#fff3bf"},{label:"Green",value:"#d3f9d8"},{label:"Blue",value:"#d0ebff"},{label:"Pink",value:"#ffdeeb"},{label:"Gray",value:"#e9ecef"}];function Et({isOpen:e,rect:t,kind:n,selection:o,crossSelection:s,marks:r,store:a,onComment:l,commentAuthorId:u}){var _,F;const c=Ne(),[i,f]=g.useState(null),[h,b]=g.useState(null),p=g.useRef(null),{applyPatch:k,toggleBoolean:C,setSubSuper:v,isLinkModalOpen:I,openLinkModal:B,closeLinkModal:R,handleSaveLink:S,handleRemoveLink:T}=De(a,n,o,s,r),j=g.useRef(null);j.current=h;function L(){var M,P,V,J;(P=(M=document.activeElement)==null?void 0:M.blur)==null||P.call(M),(J=(V=window.getSelection)==null?void 0:V.call(window))==null||J.removeAllRanges()}function w(){if(!o)return;const M=m.genId(),P=z.addCommentMarkOverRange(a,o,M);P&&a.applyOperation(P),b({commentId:M}),f("comment")}function O(){const M=j.current;if(M){for(const P of z.removeCommentMarkEverywhere(a,M.commentId))a.applyOperation(P);b(null),L()}}function x(M){!h||!o||(a.applyOperation(m.addCommentThread({id:h.commentId,blockId:o.blockId,anchorRunIds:[o.startRunId,o.endRunId],resolved:!1,messages:[{id:m.genId(),authorId:u,text:M,createdAt:Date.now()}]})),b(null),f(null),L())}function A(){O(),f(null)}g.useEffect(()=>{if(!e||n!=="same-block"||!(l||u))return;const M=P=>{(P.metaKey||P.ctrlKey)&&P.altKey&&P.code==="KeyM"&&(P.preventDefault(),l?l(o):w())};return document.addEventListener("keydown",M),()=>document.removeEventListener("keydown",M)},[e,n,l,u,o]),g.useEffect(()=>{if(!i)return;const M=V=>{p.current&&!p.current.contains(V.target)&&(O(),f(null))},P=V=>{V.key==="Escape"&&(O(),f(null))};return document.addEventListener("mousedown",M),document.addEventListener("keydown",P),()=>{document.removeEventListener("mousedown",M),document.removeEventListener("keydown",P)}},[i]),g.useEffect(()=>{O(),f(null)},[t,n]);const D=Z.useAutoAdjustedCenteredLeft(p,!!(e&&t),t?t.left+t.width/2:null);if(c||(!e||!t)&&!I)return null;const N=!l&&i==="comment";return d.jsxs(d.Fragment,{children:[e&&t&&D!=null&&N&&d.jsxs("div",{ref:p,className:"be-floating-toolbar be-floating-toolbar-comment-standalone",role:"dialog","aria-label":"Add comment",style:{position:"fixed",top:t.top-44,left:D,transform:"translateX(-50%)"},onMouseDown:M=>{M.target.tagName!=="TEXTAREA"&&M.preventDefault()},children:[d.jsx(y.CommentPopoverHeader,{title:"Add comment",onClose:A}),d.jsx(z.CommentComposer,{authorId:u,autoFocus:!0,onSubmit:x,onCancel:A})]}),e&&t&&D!=null&&!N&&d.jsxs("div",{ref:p,className:"be-floating-toolbar",role:"toolbar","aria-label":"Text formatting",style:{position:"fixed",top:t.top-44,left:D,transform:"translateX(-50%)"},onMouseDown:M=>{M.target.tagName!=="TEXTAREA"&&M.preventDefault()},children:[zn.map(({markName:M,Icon:P,title:V})=>d.jsx("button",{type:"button",className:`be-floating-toolbar-btn${r[M]?" be-floating-toolbar-btn-active":""}`,title:V,"aria-label":V,"aria-pressed":!!r[M],onClick:()=>C(M),children:d.jsx(P,{})},M)),d.jsx("button",{type:"button",className:`be-floating-toolbar-btn${r.subscript?" be-floating-toolbar-btn-active":""}`,title:"Subscript","aria-pressed":!!r.subscript,onClick:()=>v("subscript"),children:"X₂"}),d.jsx("button",{type:"button",className:`be-floating-toolbar-btn${r.superscript?" be-floating-toolbar-btn-active":""}`,title:"Superscript","aria-pressed":!!r.superscript,onClick:()=>v("superscript"),children:"X²"}),d.jsx("span",{className:"be-floating-toolbar-divider"}),d.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[d.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Text color","aria-haspopup":"true","aria-expanded":i==="color",onClick:()=>f(M=>M==="color"?null:"color"),children:d.jsx("span",{style:{color:r.color||"inherit",fontWeight:700},children:"A"})}),i==="color"&&d.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Text color",children:qn.map(M=>d.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",title:M.label,onClick:()=>{k({color:M.value}),f(null)},children:d.jsx("span",{style:{color:M.value||"#1a1a1a",fontWeight:700},children:"A"})},M.label))})]}),d.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[d.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Highlight","aria-haspopup":"true","aria-expanded":i==="highlight",onClick:()=>f(M=>M==="highlight"?null:"highlight"),children:d.jsx("span",{style:{backgroundColor:r.highlight||"transparent",padding:"0 2px",borderRadius:2},children:"H"})}),i==="highlight"&&d.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Highlight color",children:Wn.map(M=>d.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",style:{backgroundColor:M.value||"transparent"},title:M.label,onClick:()=>{k({highlight:M.value}),f(null)}},M.label))})]}),d.jsx("span",{className:"be-floating-toolbar-divider"}),d.jsx("button",{type:"button",className:`be-floating-toolbar-btn${r.link?" be-floating-toolbar-btn-active":""}`,title:"Link","aria-label":"Link","aria-pressed":!!r.link,onClick:B,children:d.jsx(m.LinkIcon,{})}),(l||u)&&n==="same-block"&&d.jsxs(d.Fragment,{children:[d.jsx("span",{className:"be-floating-toolbar-divider"}),d.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Comment (Ctrl+Alt+M)","aria-label":"Comment",onClick:()=>l?l(o):w(),children:d.jsx(m.CommentIcon,{})})]})]}),d.jsx(y.LinkEditModal,{isOpen:I,initialHref:((_=r.link)==null?void 0:_.href)??"",initialTarget:((F=r.link)==null?void 0:F.target)??"_self",hasExistingLink:!!r.link,onSave:S,onRemove:T,onClose:R})]})}function Ot(e){const t=m.useEditorStore(),[n,o]=g.useState(null);return g.useEffect(()=>{const s=e.current;if(!s)return;const r=()=>{var i,f,h,b,p;if((f=(i=document.activeElement)==null?void 0:i.closest)!=null&&f.call(i,".be-floating-toolbar"))return;const a=(h=window.getSelection)==null?void 0:h.call(window);if(!a||a.rangeCount===0||a.isCollapsed){o(null);return}if(!s.contains(a.anchorNode)||!s.contains(a.focusNode)){o(null);return}const l=((p=(b=a.getRangeAt(0)).getBoundingClientRect)==null?void 0:p.call(b))??{top:0,left:0,right:0,bottom:0,width:0,height:0},u=E.resolveMultiRunSelection();if(u){o({kind:"same-block",rect:l,selection:u,marks:Oe(t,u.blockId,u)});return}const c=E.resolveCrossBlockSelection(t);if(c){o({kind:"cross-block",rect:l,crossSelection:c,marks:Le(t,c)});return}o(null)};return document.addEventListener("selectionchange",r),window.addEventListener("scroll",r,!0),window.addEventListener("resize",r),()=>{document.removeEventListener("selectionchange",r),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r)}},[e,t]),{isOpen:!!n,rect:(n==null?void 0:n.rect)??null,kind:(n==null?void 0:n.kind)??null,selection:(n==null?void 0:n.selection)??null,crossSelection:(n==null?void 0:n.crossSelection)??null,marks:(n==null?void 0:n.marks)??{},close:()=>o(null)}}function Lt({isOpen:e,close:t,query:n,setQuery:o,caseSensitive:s,setCaseSensitive:r,wholeWord:a,setWholeWord:l,isReplaceOpen:u,setIsReplaceOpen:c,replacement:i,setReplacement:f,matches:h,currentIndex:b,next:p,prev:k,replaceCurrent:C,replaceAll:v,queryInputRef:I}){if(!e)return null;const B=S=>{S.key==="Enter"?(S.preventDefault(),S.shiftKey?k():p()):S.key==="Escape"&&(S.preventDefault(),t())},R=S=>{S.key==="Enter"?(S.preventDefault(),C()):S.key==="Escape"&&(S.preventDefault(),t())};return d.jsxs("div",{className:"be-find-bar",contentEditable:!1,children:[d.jsxs("div",{className:"be-find-bar-row",children:[d.jsx("button",{type:"button",className:`be-find-bar-replace-toggle${u?" be-find-bar-replace-toggle-open":""}`,onClick:()=>c(!u),"aria-expanded":u,"aria-label":"Toggle replace",children:d.jsx(m.ChevronRightIcon,{size:12})}),d.jsx("input",{ref:I,type:"text",className:"be-find-bar-input",placeholder:"Find",value:n,onChange:S=>o(S.target.value),onKeyDown:B,"aria-label":"Find in document"}),d.jsx("span",{className:"be-find-bar-count",children:h.length===0?"0/0":`${b+1}/${h.length}`}),d.jsx("button",{type:"button",className:`be-find-bar-toggle${s?" be-find-bar-toggle-active":""}`,onClick:()=>r(!s),"aria-pressed":s,title:"Match case","aria-label":"Match case",children:"Aa"}),d.jsx("button",{type:"button",className:`be-find-bar-toggle${a?" be-find-bar-toggle-active":""}`,onClick:()=>l(!a),"aria-pressed":a,title:"Whole word","aria-label":"Whole word",children:"[Ab]"}),d.jsx("button",{type:"button",className:"be-find-bar-nav",onClick:k,disabled:h.length===0,"aria-label":"Previous match",children:d.jsx(m.ArrowUpIcon,{size:14})}),d.jsx("button",{type:"button",className:"be-find-bar-nav",onClick:p,disabled:h.length===0,"aria-label":"Next match",children:d.jsx(m.ArrowDownIcon,{size:14})}),d.jsx("button",{type:"button",className:"be-find-bar-close",onClick:t,"aria-label":"Close find bar",children:d.jsx(m.XIcon,{size:14})})]}),u&&d.jsxs("div",{className:"be-find-bar-row be-find-bar-replace-row",children:[d.jsx("input",{type:"text",className:"be-find-bar-input",placeholder:"Replace",value:i,onChange:S=>f(S.target.value),onKeyDown:R,"aria-label":"Replace with"}),d.jsx("button",{type:"button",className:"be-find-bar-replace-btn",onClick:C,disabled:h.length===0,children:"Replace"}),d.jsx("button",{type:"button",className:"be-find-bar-replace-btn",onClick:v,disabled:h.length===0,children:"Replace All"})]})]})}function He(e){return e!=null&&/[\w]/.test(e)}function Gn(e,t,n){const o=e[t-1],s=e[t+n];return!He(o)&&!He(s)}function $e(e,t,n,o,s,r,a){const l=a??e.getRun(n);if(!l||l.type!=="text"||!l.value)return;const u=s.caseSensitive?l.value:l.value.toLowerCase();let c=0;for(;;){const i=u.indexOf(o,c);if(i===-1)break;(!s.wholeWord||Gn(u,i,o.length))&&r.push({blockId:t,runId:n,offset:i,length:o.length}),c=i+o.length}}function Mt(e,t,n,o,s){var a;const r=e.getBlock(t);if(r){for(const l of((a=r.props)==null?void 0:a.titleRunIds)??[])$e(e,t,l,n,o,s);for(const l of r.contentIds){const u=e.getRun(l);u?$e(e,t,l,n,o,s,u):Mt(e,l,n,o,s)}}}function jt(e,t,{caseSensitive:n=!1,wholeWord:o=!1}={}){const s=[];if(!t)return s;const r=n?t:t.toLowerCase();return Mt(e,e.getRootId(),r,{caseSensitive:n,wholeWord:o},s),s}function At(e,t,n){const o=e.getRun(t.runId);if(!o)return;const s=o.value??"",r=s.slice(0,t.offset)+n+s.slice(t.offset+t.length);e.applyOperation(m.updateRun(t.runId,{value:r}))}function Dt(e,t,n){const o=new Map;for(const r of t)o.has(r.runId)||o.set(r.runId,[]),o.get(r.runId).push(r);const s=[];for(const[r,a]of o){const l=e.getRun(r);if(!l)continue;let u=l.value??"";const c=[...a].sort((i,f)=>f.offset-i.offset);for(const i of c)u=u.slice(0,i.offset)+n+u.slice(i.offset+i.length);s.push(m.updateRun(r,{value:u}))}if(s.length!==0)if(typeof e.performBatch=="function")e.performBatch(s);else for(const r of s)e.applyOperation(r)}const Yn=200;function Jn(e){const t=document.querySelector(`[data-run-id="${e.runId}"]`),n=t==null?void 0:t.firstChild;if(!n||n.nodeType!==3)return null;const o=Math.min(e.offset,n.length),s=Math.min(e.offset+e.length,n.length);if(o>=s)return null;const r=document.createRange();return r.setStart(n,o),r.setEnd(n,s),r}function Nt(e){const t=m.useEditorStore(),[n,o]=g.useState(!1),[s,r]=g.useState(""),[a,l]=g.useState(!1),[u,c]=g.useState(!1),[i,f]=g.useState(!1),[h,b]=g.useState(""),[p,k]=g.useState([]),[C,v]=g.useState(0),I=g.useRef(null),B=g.useRef(null),R=g.useCallback(()=>{const x=jt(t,s,{caseSensitive:a,wholeWord:u});k(x),v(A=>x.length===0?0:Math.min(A,x.length-1))},[t,s,a,u]);g.useEffect(()=>{n&&(v(0),R())},[n,s,a,u]),g.useEffect(()=>{if(!n)return;let x=null;const A=t.subscribeAll(()=>{x&&clearTimeout(x),x=setTimeout(R,Yn)});return()=>{x&&clearTimeout(x),A()}},[n,t,R]),g.useEffect(()=>{var D;if(!n||typeof Highlight>"u"||!CSS.highlights)return;const x=[];let A=null;if(p.forEach((N,_)=>{const F=Jn(N);F&&(_===C?A=F:x.push(F))}),CSS.highlights.set("be-find-match",new Highlight(...x)),A){CSS.highlights.set("be-find-current",new Highlight(A));const N=document.querySelector(`[data-run-id="${(D=p[C])==null?void 0:D.runId}"]`);N==null||N.scrollIntoView({block:"center",behavior:"smooth"})}else CSS.highlights.delete("be-find-current");return()=>{CSS.highlights.delete("be-find-match"),CSS.highlights.delete("be-find-current")}},[n,p,C]);const S=g.useCallback(()=>{var x;if(n){(x=B.current)==null||x.select();return}I.current=document.activeElement,o(!0)},[n]),T=g.useCallback(()=>{var x,A;o(!1),f(!1),typeof Highlight<"u"&&CSS.highlights&&(CSS.highlights.delete("be-find-match"),CSS.highlights.delete("be-find-current")),(A=(x=I.current)==null?void 0:x.focus)==null||A.call(x),I.current=null},[]);g.useEffect(()=>{var x;n&&((x=B.current)==null||x.focus())},[n]),g.useEffect(()=>{const x=e.current;if(!x)return;const A=D=>{(D.metaKey||D.ctrlKey)&&D.key.toLowerCase()==="f"&&(D.preventDefault(),S())};return x.addEventListener("keydown",A),()=>x.removeEventListener("keydown",A)},[e,S]);const j=g.useCallback(()=>{p.length!==0&&v(x=>(x+1)%p.length)},[p.length]),L=g.useCallback(()=>{p.length!==0&&v(x=>(x-1+p.length)%p.length)},[p.length]),w=g.useCallback(()=>{const x=p[C];x&&At(t,x,h)},[t,p,C,h]),O=g.useCallback(()=>{p.length!==0&&Dt(t,p,h)},[t,p,h]);return{isOpen:n,open:S,close:T,query:s,setQuery:r,caseSensitive:a,setCaseSensitive:l,wholeWord:u,setWholeWord:c,isReplaceOpen:i,setIsReplaceOpen:f,replacement:h,setReplacement:b,matches:p,currentIndex:C,next:j,prev:L,replaceCurrent:w,replaceAll:O,queryInputRef:B}}function Xn({store:e,rootId:t,extensions:n,onComment:o,commentAuthorId:s}){const r=g.useRef(null),{onCopy:a,onCut:l,onPaste:u}=kt(),c=Rt(r),i=wt(r),f=Tt(r),h=Ot(r),b=Nt(r);return wn(n,r),xt(r),St(r),d.jsxs("div",{ref:r,role:"document","aria-label":"Document editor",onCopy:a,onCut:l,onPaste:u,children:[d.jsx(Lt,{...b}),d.jsx(ht,{}),d.jsx(y.BlockChildren,{parentId:t,isTopLevel:!0}),d.jsx(ut,{}),d.jsx(ce,{isOpen:c.isOpen,rect:c.rect,commands:c.commands,runId:c.runId,onSelect:c.selectCommand,onClose:c.close}),d.jsx(ce,{isOpen:i.isOpen,rect:i.rect,commands:i.commands,runId:i.runId,onSelect:i.selectCommand,onClose:i.close,menuId:"be-emoji-menu",ariaLabel:"Emoji"}),d.jsx(ce,{isOpen:f.isOpen,rect:f.rect,commands:f.commands,runId:f.runId,onSelect:f.selectCommand,onClose:f.close,menuId:"be-at-menu",ariaLabel:"Mention"}),d.jsx(Et,{isOpen:h.isOpen,rect:h.rect,kind:h.kind,selection:h.selection,crossSelection:h.crossSelection,marks:h.marks,store:e,onComment:o,commentAuthorId:s})]})}function Qn({editor:e,className:t,style:n,theme:o,getBlockClassName:s,onComment:r,commentAuthorId:a,showCommentsPanel:l,uploadFile:u,maxFileSize:c,children:i}){const{store:f,registry:h,inlineRegistry:b,extensions:p}=e,k=f.getRootId();return d.jsxs(m.EditorProvider,{store:f,registry:h,inlineRegistry:b,history:f,className:t,style:n,theme:o,getBlockClassName:s,commentAuthorId:a,uploadFile:u,maxFileSize:c,children:[d.jsx(Xn,{store:f,rootId:k,extensions:p,onComment:r,commentAuthorId:a}),l&&d.jsx(xe.CommentsPanel,{authorId:a}),i]})}const Zn={canUndo:!1,canRedo:!1};function Pt(){const{history:e}=m.useEditorContext(),t=g.useCallback(s=>e?e.subscribeToHistory(s):()=>{},[e]),n=g.useCallback(()=>e?e.getUndoRedoSnapshot():Zn,[e]),o=g.useSyncExternalStore(t,n);return e?{...o,undo:()=>{const s=e.undo();return s&&G.restoreSelectionAfterHistoryChange(e),s},redo:()=>{const s=e.redo();return s&&G.restoreSelectionAfterHistoryChange(e),s},getHistoryLog:()=>e.getHistoryLog()}:null}function eo(e){const[t,n]=g.useState(()=>(e==null?void 0:e.getPresence())??new Map);return g.useEffect(()=>{if(!e){n(new Map);return}return n(e.getPresence()),e.onPresenceChange(n)},[e]),t}const _t={'"':{open:"“",close:"”"},"'":{open:"‘",close:"’"}};function to(e,t){const n=_t[e];return t===void 0||/[\s([{“‘]/.test(t)?n.open:n.close}function no(e,{enabled:t=!0}={}){const n=m.useEditorStore();g.useEffect(()=>{if(!t)return;const o=e.current;if(!o)return;function s(a){var l;return((l=n.getBlock(a))==null?void 0:l.type)==="code"}function r(a){if(a.inputType!=="insertText"||!a.data||a.data.length!==1)return;const l=a.data,u=_t[l];if(!u)return;const c=E.resolveRunSelection();if(c){if(s(c.blockId))return;const k=n.getRun(c.runId);if(!k||k.type!=="text")return;a.preventDefault();const C=k.value??"",v=C.slice(0,c.startOffset)+u.open+C.slice(c.startOffset,c.endOffset)+u.close+C.slice(c.endOffset);X.flushSync(()=>n.applyOperation(m.updateRun(k.id,{value:v}))),E.setCaretSync(k.id,c.endOffset+2);return}const i=E.resolveCollapsedCaret();if(!i||s(i.blockId))return;const f=n.getRun(i.runId);if(!f||f.type!=="text")return;a.preventDefault();const h=f.value??"",b=to(l,h[i.offset-1]),p=h.slice(0,i.offset)+b+h.slice(i.offset);X.flushSync(()=>n.applyOperation(m.updateRun(f.id,{value:p}))),E.setCaretSync(f.id,i.offset+1)}return o.addEventListener("beforeinput",r),()=>o.removeEventListener("beforeinput",r)},[e,n,t])}const Ft={"(":")","[":"]","{":"}"},oo=new Set(Object.values(Ft));function so(e,{enabled:t=!0}={}){const n=m.useEditorStore();g.useEffect(()=>{if(!t)return;const o=e.current;if(!o)return;function s(a){var l;return((l=n.getBlock(a))==null?void 0:l.type)==="code"}function r(a){if(a.inputType!=="insertText"||!a.data||a.data.length!==1)return;const l=a.data,u=Ft[l];if(u){const c=E.resolveRunSelection();if(c){if(s(c.blockId))return;const p=n.getRun(c.runId);if(!p||p.type!=="text")return;a.preventDefault();const k=p.value??"",C=k.slice(0,c.startOffset)+l+k.slice(c.startOffset,c.endOffset)+u+k.slice(c.endOffset);X.flushSync(()=>n.applyOperation(m.updateRun(p.id,{value:C}))),E.setCaretSync(p.id,c.endOffset+2);return}const i=E.resolveCollapsedCaret();if(!i||s(i.blockId))return;const f=n.getRun(i.runId);if(!f||f.type!=="text")return;a.preventDefault();const h=f.value??"",b=h.slice(0,i.offset)+l+u+h.slice(i.offset);X.flushSync(()=>n.applyOperation(m.updateRun(f.id,{value:b}))),E.setCaretSync(f.id,i.offset+1);return}if(oo.has(l)){const c=E.resolveCollapsedCaret();if(!c||s(c.blockId))return;const i=n.getRun(c.runId);if(!i||i.type!=="text")return;(i.value??"")[c.offset]===l&&(a.preventDefault(),E.setCaretSync(i.id,c.offset+1))}}return o.addEventListener("beforeinput",r),()=>o.removeEventListener("beforeinput",r)},[e,n,t])}function Ht({isOpen:e,onClose:t,onSelectCommand:n}){const o=m.useBlockRegistry(),s=m.useInlineRegistry(),r=g.useMemo(()=>[...(o==null?void 0:o.listSlashCommands())??[],...(s==null?void 0:s.listSlashCommands())??[]],[o,s]);return d.jsx(Z.Modal,{isOpen:e,onClose:t,title:"Add a block",variant:"sheet",children:d.jsx("div",{className:"be-mobile-picker-list",role:"listbox","aria-label":"Insertable blocks",children:r.map(a=>{const l=a.icon;return d.jsxs("button",{type:"button",role:"option",className:"be-mobile-picker-item",onClick:()=>n(a),children:[l&&d.jsx("span",{className:"be-mobile-picker-item-icon",children:d.jsx(l,{size:18})}),d.jsx("span",{className:"be-mobile-picker-item-label",children:a.label})]},a.label)})})})}function $t({isOpen:e,onClose:t,store:n,blockId:o}){var l;const s=o?n.getBlock(o):null,r=!!((l=s==null?void 0:s.props)!=null&&l.hidden),a=g.useCallback(u=>{u(),t()},[t]);return d.jsx(Z.Modal,{isOpen:e,onClose:t,title:"Block options",variant:"sheet",children:d.jsxs("div",{className:"be-mobile-picker-list",role:"menu","aria-label":"Block options",children:[d.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{y.duplicateBlock(n,o),y.announce("Block duplicated")}),children:[d.jsx("span",{className:"be-mobile-picker-item-icon",children:d.jsx(m.CopyIcon,{size:18})}),d.jsx("span",{className:"be-mobile-picker-item-label",children:"Duplicate"})]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{y.moveBlockUp(n,o)&&y.announce("Block moved up")}),children:[d.jsx("span",{className:"be-mobile-picker-item-icon",children:d.jsx(m.ArrowUpIcon,{size:18})}),d.jsx("span",{className:"be-mobile-picker-item-label",children:"Move up"})]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{y.moveBlockDown(n,o)&&y.announce("Block moved down")}),children:[d.jsx("span",{className:"be-mobile-picker-item-icon",children:d.jsx(m.ArrowDownIcon,{size:18})}),d.jsx("span",{className:"be-mobile-picker-item-label",children:"Move down"})]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{n.applyOperation(m.updateBlockProps(o,{hidden:!r})),y.announce(r?"Block shown in preview":"Block hidden in preview")}),children:[d.jsx("span",{className:"be-mobile-picker-item-icon",children:r?d.jsx(m.EyeIcon,{size:18}):d.jsx(m.EyeOffIcon,{size:18})}),d.jsx("span",{className:"be-mobile-picker-item-label",children:r?"Show in preview":"Hide in preview"})]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item be-mobile-picker-item-danger",onClick:()=>a(()=>{y.deleteBlockAndFocusSibling(n,o),y.announce("Block deleted")}),children:[d.jsx("span",{className:"be-mobile-picker-item-icon",children:d.jsx(m.TrashIcon,{size:18})}),d.jsx("span",{className:"be-mobile-picker-item-label",children:"Delete"})]})]})})}const ro=y.LANGUAGES.map(e=>({value:e,label:e}));function lo(e,t){const[n,o]=g.useState(!1),[s,r]=g.useState(null),[a,l]=g.useState(null),[u,c]=g.useState(null);return g.useEffect(()=>{const i=e.current;if(!i)return;const f=()=>o(!0),h=b=>{i.contains(b.relatedTarget)||o(!1)};return i.addEventListener("focusin",f),i.addEventListener("focusout",h),()=>{i.removeEventListener("focusin",f),i.removeEventListener("focusout",h)}},[e]),g.useEffect(()=>{if(!n){r(null);return}const i=()=>{var p;const f=e.current,h=(p=window.getSelection)==null?void 0:p.call(window);if(!f||!h||h.rangeCount===0){r(null);return}if(!h.isCollapsed){if(!f.contains(h.anchorNode)||!f.contains(h.focusNode)){r(null);return}const k=E.resolveMultiRunSelection();if(k){l({kind:"same-block",selection:k,crossSelection:null,marks:Oe(t,k.blockId,k)}),r("selection");return}const C=E.resolveCrossBlockSelection(t);if(C){l({kind:"cross-block",selection:null,crossSelection:C,marks:Le(t,C)}),r("selection");return}r(null);return}const b=E.resolveCollapsedCaret();if(!b||!f.contains(h.anchorNode)){r(null);return}c(b),r("caret")};return i(),document.addEventListener("selectionchange",i),()=>document.removeEventListener("selectionchange",i)},[n,t,e]),{isFocused:n,mode:s,selectionState:a,caretState:u}}function ao({store:e,selectionState:t}){const{kind:n,selection:o,crossSelection:s,marks:r}=t,{toggleBoolean:a,openLinkModal:l}=De(e,n,o,s,r);return d.jsxs(d.Fragment,{children:[d.jsx("button",{type:"button",className:`be-mobile-bar-btn${r.bold?" be-mobile-bar-btn-active":""}`,"aria-label":"Bold",onClick:()=>a("bold"),children:d.jsx(m.BoldIcon,{size:18})}),d.jsx("button",{type:"button",className:`be-mobile-bar-btn${r.italic?" be-mobile-bar-btn-active":""}`,"aria-label":"Italic",onClick:()=>a("italic"),children:d.jsx(m.ItalicIcon,{size:18})}),d.jsx("button",{type:"button",className:`be-mobile-bar-btn${r.underline?" be-mobile-bar-btn-active":""}`,"aria-label":"Underline",onClick:()=>a("underline"),children:d.jsx(m.UnderlineIcon,{size:18})}),d.jsx("button",{type:"button",className:`be-mobile-bar-btn${r.link?" be-mobile-bar-btn-active":""}`,"aria-label":"Link",onClick:l,children:d.jsx(m.LinkIcon,{size:18})})]})}function co({store:e,blockId:t}){const n=g.useCallback(()=>{const s=e.getBlock(t),r=s&&e.getBlock(s.parentId);r&&y.insertRowAfter(e,r.id)},[e,t]),o=g.useCallback(()=>{const s=e.getBlock(t),r=s&&e.getBlock(s.parentId),a=r&&e.getBlock(r.parentId);if(!a||!r)return;const l=r.contentIds.indexOf(t);l!==-1&&y.insertColumnAfter(e,a.id,l)},[e,t]);return d.jsxs(d.Fragment,{children:[d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert row below",onClick:n,children:"+ Row"}),d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert column right",onClick:o,children:"+ Column"})]})}function io({store:e,blockId:t}){var s;const n=e.getBlock(t),o=g.useCallback(r=>e.applyOperation(m.updateBlockProps(t,{language:r})),[e,t]);return d.jsx(y.Select,{className:"be-mobile-bar-select",value:((s=n==null?void 0:n.props)==null?void 0:s.language)??"plaintext",options:ro,onChange:o,ariaLabel:"Code language"})}function uo({store:e,blockId:t}){var s;const n=e.getBlock(t),o=(s=n==null?void 0:n.props)==null?void 0:s.color;return d.jsx("div",{className:"be-mobile-bar-swatches",children:y.CALLOUT_COLORS.map(r=>d.jsx("button",{type:"button",className:`be-callout-color-option be-callout-color-option-${r.value}${r.value===o?" be-callout-color-option-active":""}`,"aria-label":r.label,title:r.label,onClick:()=>e.applyOperation(m.updateBlockProps(t,{color:r.value}))},r.value))})}const Ut={tableCell:co,code:io,callout:uo};function fo(e,t){let n=e.getBlock(t);for(;n;){if(Ut[n.type])return n;n=n.parentId?e.getBlock(n.parentId):null}return null}function po(e,t){const n=e.getRootId();let o=e.getBlock(t);for(;o&&o.parentId!==n;)o=e.getBlock(o.parentId);return o}function mo({containerRef:e}){var j,L;const t=m.useEditorStore(),n=Pt(),o=Ne(),s=y.useVirtualKeyboardInset(),{isFocused:r,mode:a,selectionState:l,caretState:u}=lo(e,t),[c,i]=g.useState(!1),[f,h]=g.useState(!1),b=g.useCallback(()=>i(!0),[]),p=g.useCallback(()=>i(!1),[]),k=g.useCallback(()=>h(!0),[]),C=g.useCallback(()=>h(!1),[]),v=g.useCallback(w=>{const O=E.resolveCollapsedCaret()??u;O&&(w.run(t,{blockId:O.blockId,runId:O.runId,sliceStart:O.offset,sliceEnd:O.offset}),p())},[t,u,p]),I=g.useCallback(()=>{var w,O;(O=(w=document.activeElement)==null?void 0:w.blur)==null||O.call(w)},[]);if(!o||!r)return null;const B=a==="caret"&&u?fo(t,u.blockId):null,R=B?Ut[B.type]:null,S=a==="caret"&&u?u.blockId:((j=l==null?void 0:l.selection)==null?void 0:j.blockId)??((L=l==null?void 0:l.crossSelection)==null?void 0:L.startBlockId)??null,T=S?po(t,S):null;return d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"be-mobile-action-bar",role:"toolbar","aria-label":"Editor actions",style:{bottom:s},onMouseDown:w=>w.preventDefault(),children:[a==="selection"&&l&&d.jsx(ao,{store:t,selectionState:l}),a!=="selection"&&d.jsxs(d.Fragment,{children:[d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Add block",onClick:b,children:d.jsx(m.PlusIcon,{size:18})}),R&&B&&d.jsx(R,{store:t,blockId:B.id}),n&&d.jsxs(d.Fragment,{children:[d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Undo",disabled:!n.canUndo,onClick:n.undo,children:"↶"}),d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Redo",disabled:!n.canRedo,onClick:n.redo,children:"↷"})]})]}),d.jsx("span",{className:"be-mobile-bar-spacer"}),T&&d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Block options",onClick:k,children:d.jsx(m.MoreHorizontalIcon,{size:18})}),d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Dismiss keyboard",onClick:I,children:d.jsx(m.ChevronDownIcon,{size:18})})]}),d.jsx(Ht,{isOpen:c,onClose:p,onSelectCommand:v}),d.jsx($t,{isOpen:f,onClose:C,store:t,blockId:T==null?void 0:T.id})]})}const ho=[{value:"json",label:"JSON"},{value:"simpleJson",label:"Simple JSON"},{value:"html",label:"HTML"},{value:"markdown",label:"Markdown"},{value:"text",label:"Text"}];function bo({label:e="View source",className:t=""}){const n=m.useEditorStore(),o=m.useBlockRegistry(),s=m.useInlineRegistry(),[r,a]=g.useState(!1),[l,u]=g.useState("json"),[c,i]=g.useState(!1),f=g.useCallback(()=>{i(!1),a(!0)},[]),h=g.useCallback(()=>a(!1),[]),b=g.useMemo(()=>r?l==="json"?H.exportDocumentJSON(n):l==="simpleJson"?Se(n,o,s):l==="html"?H.exportDocumentHTML(n,o,s):l==="markdown"?H.exportDocumentMarkdown(n,o,s):H.exportDocumentText(n,o,s):"",[r,l,n,o,s]),p=g.useCallback(async()=>{try{await navigator.clipboard.writeText(b),i(!0),setTimeout(()=>i(!1),1500)}catch{}},[b]),k=g.useCallback(()=>{const v=H.exportDocumentWordHTML(n,o,s),I=document.createElement("a");I.href=`data:application/msword;charset=utf-8,${encodeURIComponent(v)}`,I.download="document.doc",document.body.appendChild(I),I.click(),document.body.removeChild(I)},[n,o,s]),C=g.useCallback(()=>{window.print()},[]);return d.jsxs(d.Fragment,{children:[d.jsxs("button",{type:"button",className:`be-export-trigger ${t}`.trim(),onClick:f,children:[d.jsx(m.CodeIcon,{size:14})," ",e]}),d.jsxs(Z.Modal,{isOpen:r,onClose:h,title:"Document source",size:"large",children:[d.jsx("div",{className:"be-export-tabs",role:"tablist",children:ho.map(v=>d.jsx("button",{type:"button",role:"tab","aria-selected":l===v.value,className:`be-export-tab${l===v.value?" be-export-tab-active":""}`,onClick:()=>u(v.value),children:v.label},v.value))}),d.jsx("pre",{className:"be-export-pre",children:d.jsx("code",{children:b})}),d.jsxs("div",{className:"be-modal-actions",children:[d.jsx("button",{type:"button",className:"be-modal-cancel",onClick:h,children:"Close"}),d.jsx("button",{type:"button",className:"be-export-download",onClick:C,children:"Print / Save as PDF"}),d.jsx("button",{type:"button",className:"be-export-download",onClick:k,children:"Download Word (.doc)"}),d.jsx("button",{type:"button",className:"be-modal-save",onClick:p,children:c?"Copied!":"Copy"})]})]})]})}function go({id:e,blockId:t,label:n,placeholder:o,variant:s,options:r,onManage:a,mention:l=!1}){const u=m.useEditorStore(),c=$.useRun(e),i=g.useRef(null);i.current===null&&(i.current=y.consumePendingAutoOpen(e));const f=g.useCallback((k,C)=>{u.applyOperation(m.updateRun(e,{data:{selectedValue:k,selectedLabel:(C==null?void 0:C.label)??"",selectedColor:C==null?void 0:C.color}})),i.current&&y.focusAfterChip(u,t,e)},[u,e,t]);if(!c)return null;const{selectedValue:h="",selectedLabel:b="",selectedColor:p}=c.data??{};return d.jsx("span",{className:"be-inline-select",onMouseDown:k=>{k.preventDefault(),k.stopPropagation()},onKeyDown:k=>k.stopPropagation(),children:d.jsx(y.Select,{value:h,selectedLabel:b,selectedColor:p,options:r,onChange:f,placeholder:o,variant:s,ariaLabel:n,onManageOptions:a,mention:l,autoOpen:i.current})})}function Kt(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Ue(e){return Kt(e).replace(/"/g,"&quot;")}function Vt({type:e,label:t,placeholder:n="Select…",variant:o="default",icon:s,options:r,onManage:a,triggers:l=["slash"],mention:u=l.includes("at")}){function c(p){var v,I;const k=((v=p.data)==null?void 0:v.selectedLabel)||"",C=u&&k?`@${k}`:k;return`<span data-inline-type="${Ue(e)}" data-selected-value="${Ue(((I=p.data)==null?void 0:I.selectedValue)??"")}">${Kt(C)}</span>`}function i(p){var C;const k=((C=p.data)==null?void 0:C.selectedLabel)??"";return u&&k?`@${k}`:k}function f(p){var v;if(((v=p.getAttribute)==null?void 0:v.call(p,"data-inline-type"))!==e)return null;const k=p.textContent??"",C=u&&k.startsWith("@")?k.slice(1):k;return{id:m.genId(),type:e,value:"",marks:{},data:{selectedValue:p.getAttribute("data-selected-value")??"",selectedLabel:C}}}function h({id:p,blockId:k}){return d.jsx(go,{id:p,blockId:k,label:t,placeholder:n,variant:o,options:r,onManage:a,mention:u})}const b={label:t,icon:s??m.SelectIcon,keywords:[t.toLowerCase(),"select","field"],run:(p,{blockId:k,runId:C,sliceStart:v,sliceEnd:I})=>y.insertInlineRunAtCursor(p,{blockId:k,runId:C,sliceStart:v,sliceEnd:I},()=>({id:m.genId(),type:e,value:"",marks:{},data:{selectedValue:"",selectedLabel:"",selectedColor:void 0}}),{autoOpen:!0})};return{component:h,isAtomic:!0,toHTML:c,toPlainText:i,fromHTML:f,slashCommand:l.includes("slash")?b:void 0,atCommand:l.includes("at")?b:void 0}}function zt(e,t,{onManage:n}={}){for(const o of e.getFieldTypes())t.register(o.id,Vt({type:o.id,label:o.label,placeholder:o.placeholder,variant:o.variant,options:o.options??[],triggers:o.mentionable?["slash","at"]:["slash"],onManage:n?()=>n(o.id):void 0}))}function qt(){const e=m.useEditorStore(),t=m.useInlineRegistry(),n=y.useFieldTypes(),{openEdit:o}=m.useFieldTypeEditor(),s=g.useRef([]);g.useEffect(()=>{if(!t)return;const r=new Set(n.map(a=>a.id));for(const a of s.current)r.has(a)||t.unregister(a);zt(e,t,{onManage:o}),s.current=[...r]},[e,t,n,o])}function ko(){qt();const e=m.useEditorStore(),{target:t,close:n}=m.useFieldTypeEditor(),o=t!==null,s=o&&t!=="new",[r,a]=g.useState(""),[l,u]=g.useState([]),[c,i]=g.useState(""),[f,h]=g.useState(!1);g.useEffect(()=>{if(o){if(s){const I=e.getFieldType(t);a((I==null?void 0:I.label)??""),u((I==null?void 0:I.options)??[]),h(!!(I!=null&&I.mentionable))}else a(""),u([]),h(!1);i("")}},[o,s,t,e]);const b=g.useCallback((I,B)=>{u(R=>R.map(S=>S.value===I?{...S,label:B}:S))},[]),p=g.useCallback(I=>{u(B=>B.filter(R=>R.value!==I))},[]),k=g.useCallback(()=>{const I=c.trim();i(""),I&&u(B=>[...B,{value:m.genId(),label:I,color:y.pickTagColor(B.length)}])},[c]),C=g.useCallback(()=>{const I=r.trim();I&&(s?e.applyOperation(m.updateFieldType(t,{label:I,options:l,mentionable:f})):e.applyOperation(m.addFieldType({id:m.genId(),label:I,placeholder:"Select…",variant:"tag",options:l,mentionable:f})),n())},[e,s,t,r,l,f,n]),v=g.useCallback(()=>{s&&e.applyOperation(m.removeFieldType(t)),n()},[e,s,t,n]);return d.jsxs(Z.Modal,{isOpen:o,onClose:n,title:s?"Edit field type":"New field type",children:[d.jsxs("label",{className:"be-modal-field",children:[d.jsx("span",{children:"Name"}),d.jsx("input",{type:"text",value:r,onChange:I=>a(I.target.value),placeholder:"e.g. Priority, Status…",autoFocus:!0})]}),d.jsxs("div",{className:"be-modal-field",children:[d.jsx("span",{children:"Options"}),l.map((I,B)=>d.jsxs("div",{className:"be-table-header-menu-option-row",children:[d.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(I.color??y.pickTagColor(B)).bg},"aria-hidden":"true"}),d.jsx("input",{className:"be-table-header-menu-option-input",value:I.label,onChange:R=>b(I.value,R.target.value),"aria-label":`Rename option ${I.label}`}),d.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>p(I.value),"aria-label":`Remove option ${I.label}`,children:d.jsx(m.XIcon,{size:14})})]},I.value)),d.jsxs("div",{className:"be-table-header-menu-option-row",children:[d.jsx("input",{className:"be-table-header-menu-option-input",value:c,onChange:I=>i(I.target.value),placeholder:"New option…",onKeyDown:I=>{I.key==="Enter"&&(I.preventDefault(),k())}}),d.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:k,"aria-label":"Add option",children:"+"})]})]}),d.jsxs("label",{className:"be-modal-field be-modal-field-checkbox",children:[d.jsx("input",{type:"checkbox",checked:f,onChange:I=>h(I.target.checked)}),d.jsx("span",{children:"Also show in @ mentions"})]}),d.jsxs("div",{className:"be-modal-actions",children:[s&&d.jsx("button",{type:"button",className:"be-modal-delete",onClick:v,children:"Delete field type"}),d.jsx("button",{type:"button",className:"be-modal-cancel",onClick:n,children:"Cancel"}),d.jsx("button",{type:"button",className:"be-modal-save",onClick:C,children:"Save"})]})]})}exports.EditorStore=H.EditorStore;exports.VersionHistory=H.VersionHistory;exports.applyDocumentTemplate=H.applyDocumentTemplate;exports.captureBlockTemplate=H.captureBlockTemplate;exports.createAutoVersionHistory=H.createAutoVersionHistory;exports.diffDocumentsHTML=H.diffDocumentsHTML;exports.exportDocumentHTML=H.exportDocumentHTML;exports.exportDocumentJSON=H.exportDocumentJSON;exports.exportDocumentMarkdown=H.exportDocumentMarkdown;exports.exportDocumentText=H.exportDocumentText;exports.exportDocumentWordHTML=H.exportDocumentWordHTML;exports.insertBlockTemplate=H.insertBlockTemplate;exports.registerBlockTemplates=H.registerBlockTemplates;exports.useDocumentVersions=H.useDocumentVersions;exports.EditorProvider=m.EditorProvider;exports.injectDefaultStyles=m.injectDefaultStyles;exports.operations=m.operations;exports.useBlockClassName=m.useBlockClassName;exports.useBlockRangeSelection=m.useBlockRangeSelection;exports.useBlockRegistry=m.useBlockRegistry;exports.useCommentAuthorId=m.useCommentAuthorId;exports.useEditorStore=m.useEditorStore;exports.useFieldTypeEditor=m.useFieldTypeEditor;exports.useFileUpload=m.useFileUpload;exports.useInlineRegistry=m.useInlineRegistry;exports.usePreviewMode=m.usePreviewMode;exports.useSelectedBlock=m.useSelectedBlock;exports.useShowLineNumbers=m.useShowLineNumbers;exports.useWholeDocumentSelection=m.useWholeDocumentSelection;exports.FieldClockRegistry=pe.FieldClockRegistry;exports.HLC=pe.HLC;exports.ListCrdtState=pe.ListCrdtState;exports.genPeerId=pe.genPeerId;exports.CollabSession=Q.CollabSession;exports.MESSAGE_TYPE=Q.MESSAGE_TYPE;exports.PeerConnection=Q.PeerConnection;exports.createPeriodicTombstoneGC=Q.createPeriodicTombstoneGC;exports.createWebSocketSignaling=Q.createWebSocketSignaling;exports.decodeMessage=Q.decodeMessage;exports.encodeMessage=Q.encodeMessage;exports.deleteDocumentVersion=K.deleteDocumentVersion;exports.deletePersistedDocument=K.deletePersistedDocument;exports.deleteTemplate=K.deleteTemplate;exports.listDocumentVersions=K.listDocumentVersions;exports.listPersistedDocumentIds=K.listPersistedDocumentIds;exports.listTemplates=K.listTemplates;exports.loadDocumentVersion=K.loadDocumentVersion;exports.loadPersistedDocument=K.loadPersistedDocument;exports.loadTemplate=K.loadTemplate;exports.saveDocumentVersion=K.saveDocumentVersion;exports.savePersistedDocument=K.savePersistedDocument;exports.saveTemplate=K.saveTemplate;exports.createAutoPersistence=Be.createAutoPersistence;exports.usePersistedDocument=Be.usePersistedDocument;exports.useServiceWorkerUpdate=Be.useServiceWorkerUpdate;exports.CommentComposer=z.CommentComposer;exports.CommentThreadCard=z.CommentThreadCard;exports.addComment=z.addComment;exports.addCommentMarkOverRange=z.addCommentMarkOverRange;exports.deleteComment=z.deleteComment;exports.removeCommentMarkEverywhere=z.removeCommentMarkEverywhere;exports.replyToComment=z.replyToComment;exports.resolveComment=z.resolveComment;exports.CommentsPanel=xe.CommentsPanel;exports.useComments=xe.useComments;exports.CommentAvatar=Jt.CommentAvatar;exports.canvasBlockType=$.canvasBlockType;exports.defineBlock=$.defineBlock;exports.defineExtension=$.defineExtension;exports.defineInline=$.defineInline;exports.registerExtensions=$.registerExtensions;exports.useBlock=$.useBlock;exports.useRun=$.useRun;exports.AGGREGATE_LABELS=y.AGGREGATE_LABELS;exports.AGGREGATE_TYPES=y.AGGREGATE_TYPES;exports.BlockChildren=y.BlockChildren;exports.BlockErrorBoundary=y.BlockErrorBoundary;exports.BlockGutterRow=y.BlockGutterRow;exports.BlockRenderer=y.BlockRenderer;exports.COLUMN_TYPES=y.COLUMN_TYPES;exports.DEFAULT_COLUMN_TYPE=y.DEFAULT_COLUMN_TYPE;exports.DEFAULT_COLUMN_WIDTH=y.DEFAULT_COLUMN_WIDTH;exports.EditableBlockContent=y.EditableBlockContent;exports.MIN_COLUMN_WIDTH=y.MIN_COLUMN_WIDTH;exports.Select=y.Select;exports.TableHeaderRow=y.TableHeaderRow;exports.blankRunForType=y.blankRunForType;exports.blockquoteBlockType=y.blockquoteBlockType;exports.buttonBlockType=y.buttonBlockType;exports.calloutBlockType=y.calloutBlockType;exports.checkboxInlineType=y.checkboxInlineType;exports.codeBlockType=y.codeBlockType;exports.computeColumnAggregate=y.computeColumnAggregate;exports.convertRunToType=y.convertRunToType;exports.createCellForColumn=y.createCellForColumn;exports.createDefaultColumns=y.createDefaultColumns;exports.dateInlineType=y.dateInlineType;exports.deleteBlockAndFocusSibling=y.deleteBlockAndFocusSibling;exports.deleteColumn=y.deleteColumn;exports.deleteRow=y.deleteRow;exports.dividerBlockType=y.dividerBlockType;exports.duplicateBlock=y.duplicateBlock;exports.embedBlockType=y.embedBlockType;exports.emojiInlineType=y.emojiInlineType;exports.ensureRootNonEmpty=y.ensureRootNonEmpty;exports.formatAggregateValue=y.formatAggregateValue;exports.headingBlockType=y.headingBlockType;exports.insertColumnAfter=y.insertColumnAfter;exports.insertRowAfter=y.insertRowAfter;exports.layoutBlockType=y.layoutBlockType;exports.layoutColumnBlockType=y.layoutColumnBlockType;exports.listItemBlockType=y.listItemBlockType;exports.moveBlockDown=y.moveBlockDown;exports.moveBlockUp=y.moveBlockUp;exports.paragraphBlockType=y.paragraphBlockType;exports.renameColumn=y.renameColumn;exports.resolveColumns=y.resolveColumns;exports.selectInlineType=y.selectInlineType;exports.setColumnAggregate=y.setColumnAggregate;exports.setColumnOptions=y.setColumnOptions;exports.setColumnType=y.setColumnType;exports.setColumnWidth=y.setColumnWidth;exports.sortTableByColumn=y.sortTableByColumn;exports.starterKit=y.starterKit;exports.tableBlockType=y.tableBlockType;exports.tableCellBlockType=y.tableCellBlockType;exports.tableRowBlockType=y.tableRowBlockType;exports.tableSelectInlineType=y.tableSelectInlineType;exports.toggleHeadingBlockType=y.toggleHeadingBlockType;exports.useBlockChildren=y.useBlockChildren;exports.useFieldTypes=y.useFieldTypes;exports.useVirtualKeyboardInset=y.useVirtualKeyboardInset;exports.focusRunAtOffset=E.focusRunAtOffset;exports.focusRunEnd=E.focusRunEnd;exports.focusRunStart=E.focusRunStart;exports.resolveCollapsedCaret=E.resolveCollapsedCaret;exports.resolveCrossBlockSelection=E.resolveCrossBlockSelection;exports.resolveMultiRunSelection=E.resolveMultiRunSelection;exports.resolveRunSelection=E.resolveRunSelection;exports.captureSubtree=se.captureSubtree;exports.remapSubtreeIds=se.remapSubtreeIds;exports.serializeBlockRange=se.serializeBlockRange;exports.VoiceListeningIndicator=G.VoiceListeningIndicator;exports.VoicePermissionModal=G.VoicePermissionModal;exports.listVoiceCommands=G.listVoiceCommands;exports.useCaretRect=G.useCaretRect;exports.useVoiceTyping=G.useVoiceTyping;exports.Modal=Z.Modal;exports.APP_MIME=ie;exports.BlockRangeActionMenu=ht;exports.BlockRegistry=ze;exports.DocumentExportButton=bo;exports.EditorTrailingSpace=ut;exports.FieldTypeEditorModal=ko;exports.FindBar=Lt;exports.FloatingToolbar=Et;exports.History=Ve;exports.InlineRegistry=We;exports.LAYOUT_BLOCKS=Qe;exports.MobileActionBar=mo;exports.MobileBlockOptionsSheet=$t;exports.MobileBlockPickerSheet=Ht;exports.NoteloomEditor=Qn;exports.SlashMenu=ce;exports.TABLE_BLOCKS=Xe;exports.TABLE_SELECT_INLINE_TYPES=tt;exports.TemplatePicker=en;exports.addPerson=tn;exports.autoPairBrackets=un;exports.copyBlockRangeToClipboard=Ie;exports.createBlockRegistry=qe;exports.createInlineRegistry=Ge;exports.createSelectFieldType=Vt;exports.deleteBlockRange=le;exports.deleteEntireDocument=ue;exports.deleteOverBlockRange=Ee;exports.deleteRunRangeInBlock=Te;exports.deserializeClipboard=gt;exports.exportDocumentSimpleJSON=Se;exports.findMatches=jt;exports.getMarksSummaryOverBlockRange=Le;exports.getMarksSummaryOverSelection=Oe;exports.importDocumentSimpleJSON=it;exports.isEntireBlockRangeHidden=pt;exports.isEntireBlockSelected=Bt;exports.isSimpleDocument=ct;exports.moveBlockRangeDown=ft;exports.moveBlockRangeUp=dt;exports.registerBlocks=Je;exports.registerBuiltInBlocks=Ye;exports.registerBuiltInInlineTypes=Ze;exports.registerInlineTypes=et;exports.registerStoredFieldTypes=zt;exports.removePerson=on;exports.reorderBlockRangeFromStore=hn;exports.replaceAllMatches=Dt;exports.replaceMatch=At;exports.setBlockRangeHidden=mt;exports.setMarksOverBlockRange=fe;exports.setMarksOverSelection=oe;exports.smartQuotes=an;exports.textToParagraphs=we;exports.toggleMarkOnRunRange=xn;exports.toggleMarkOverBlockRange=je;exports.toggleMarkOverSelection=Me;exports.updatePerson=nn;exports.useAtMenuTrigger=Tt;exports.useAutoPairBrackets=so;exports.useBlockRangeDrag=St;exports.useClipboardHandlers=kt;exports.useCoarsePointer=Ne;exports.useEditor=pn;exports.useEditorKeyboardShortcuts=xt;exports.useEmojiMenuTrigger=wt;exports.useFindInDocument=Nt;exports.useFloatingToolbarTrigger=Ot;exports.useHistory=Pt;exports.usePeople=rn;exports.usePresence=eo;exports.useRegisterFieldTypes=qt;exports.useSlashMenuTrigger=Rt;exports.useSmartQuotes=no;exports.useTemplates=Zt;exports.useTextFormattingActions=De;exports.walkDomToBlocks=bt;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("./shared/VersionHistory-BsSwOq_k.cjs"),h=require("./shared/icons-DQ7j_-ZK.cjs"),be=require("./shared/fieldRegistry-BoYyW3GH.cjs"),ee=require("./collab.cjs"),q=require("./shared/indexedDbPersistence-BWJ1h5Vp.cjs"),Se=require("./shared/useServiceWorkerUpdate-DQboGesi.cjs"),k=require("react"),d=require("react/jsx-runtime"),Y=require("./shared/CommentThreadCard-CIB6nZEA.cjs"),we=require("./shared/CommentsPanel-CRxb3RWi.cjs"),Qt=require("./shared/CommentAvatar-V457IgoQ.cjs"),K=require("./shared/index-vWtS1iyt.cjs"),I=require("./shared/starter-kit-BQUaaql0.cjs"),O=require("./shared/leafBlockFactory-6GFBveaC.cjs"),Z=require("react-dom"),le=require("./shared/serialize-vLXz0cze.cjs"),X=require("./shared/VoiceListeningIndicator-B_7-6Mq4.cjs"),te=require("./shared/usePopoverEdgeClamp-BJLbbANB.cjs"),Zt=500;function en(e,t){const n=e??"",o=t??"";let s=0;const r=Math.min(n.length,o.length);for(;s<r&&n[s]===o[s];)s+=1;let a=n.length,l=o.length;for(;a>s&&l>s&&n[a-1]===o[l-1];)a-=1,l-=1;return{beforeOffset:a,afterOffset:l}}function qe(e){var t;if((e==null?void 0:e.type)==="updateRun"&&typeof((t=e.patch)==null?void 0:t.value)=="string")return e.patch.value;if((e==null?void 0:e.type)==="editRunChars"&&typeof e.previousValue=="string")return e.previousValue}function Fe(e){var l;if(!e.ops.length||!e.inverses.length)return null;const t=e.ops[0],n=e.ops[e.ops.length-1];if(t.type!=="updateRun"||n.type!=="updateRun"||t.id!==n.id||typeof((l=n.patch)==null?void 0:l.value)!="string")return null;const o=e.inverses[e.inverses.length-1],s=qe(o);if(s===void 0)return null;const{beforeOffset:r,afterOffset:a}=en(s,n.patch.value);return{runId:t.id,beforeOffset:r,afterOffset:a}}function He(e){const t=[],n=o=>{var s;o&&((s=o.block)!=null&&s.id&&t.push(o.block.id),o.blockId&&t.push(o.blockId),o.id&&t.push(o.id),o.parentId&&t.push(o.parentId),o.toParentId&&t.push(o.toParentId))};for(const o of e.ops)n(o);for(const o of e.inverses)n(o);return[...new Set(t)]}class We{constructor(t,{idleMs:n=Zt,trackChanges:o=!1,maxChangeLogSize:s=500,defaultActorId:r=null}={}){this.store=t,this.idleMs=n,this.defaultActorId=r,this.undoStack=[],this.redoStack=[],this.currentBatch=null,this.idleTimer=null,this.historyLog=[],this._listeners=new Set,this._undoRedoSnapshot={canUndo:!1,canRedo:!1},this._pendingSelection=null,this._pendingAffectedBlockIds=[],this.trackChanges=o,this.maxChangeLogSize=s,this.changeLog=[]}_recordChange(t,n,o){var a;if(!this.trackChanges)return;const s=t.patch!==void 0&&(n==null?void 0:n.patch)!==void 0,r=s?void 0:qe(n);this.changeLog.push({opType:t.type,id:t.id??t.blockId??((a=t.block)==null?void 0:a.id),before:s?n.patch:r!==void 0?{value:r}:void 0,after:s||r!==void 0?t.patch:void 0,actorId:o.actorId??null,timestamp:o.timestamp??Date.now()}),this.changeLog.length>this.maxChangeLogSize&&this.changeLog.shift()}getChangeLog(){return[...this.changeLog]}getPendingSelection(){return this._pendingSelection}getPendingAffectedBlockIds(){return this._pendingAffectedBlockIds}getUndoRedoSnapshot(){const t=this.canUndo(),n=this.canRedo();return(this._undoRedoSnapshot.canUndo!==t||this._undoRedoSnapshot.canRedo!==n)&&(this._undoRedoSnapshot={canUndo:t,canRedo:n}),this._undoRedoSnapshot}getBlock(t){return this.store.getBlock(t)}getRun(t){return this.store.getRun(t)}getRootId(){return this.store.getRootId()}getFieldTypes(){return this.store.getFieldTypes()}getFieldType(t){return this.store.getFieldType(t)}getComments(){return this.store.getComments()}getComment(t){return this.store.getComment(t)}getPeople(){return this.store.getPeople()}getPerson(t){return this.store.getPerson(t)}getTitle(){return this.store.getTitle()}getAllRunIds(){return this.store.getAllRunIds()}subscribe(t,n){return this.store.subscribe(t,n)}subscribeAll(t){return this.store.subscribeAll(t)}getTombstoneCount(){return this.store.getTombstoneCount()}pruneTombstones(t){return this.store.pruneTombstones(t)}toJSON(){return this.store.toJSON()}applyOperation(t,n={}){return this.perform(t,n)}applyOperations(t,n={}){return t.map(o=>this.perform(o,n))}setDefaultActorId(t){this.defaultActorId=t}performBatch(t,n={}){var a;const o=n.actorId??this.defaultActorId,s=n.timestamp??Date.now();this._commitCurrentBatch();const r=[];for(const l of t){const u=this.store.applyOperation(l);r.unshift(u),this.historyLog.push({opType:l.type,id:l.id??l.blockId??((a=l.block)==null?void 0:a.id),actorId:o,timestamp:s}),this._recordChange(l,u,{actorId:o,timestamp:s})}this.redoStack=[],this.undoStack.push({ops:[...t],inverses:r,batchKey:null,actorId:o,timestamp:s,lastTimestamp:s,boundaryHit:!0}),this._notify()}perform(t,n={}){const o=n.actorId??this.defaultActorId,s=n.timestamp??Date.now(),r=this.store.applyOperation(t);return this._record(t,r,{actorId:o,timestamp:s}),r}_batchKeyFor(t){return t.type==="updateRun"?`run:${t.id}`:null}_isWordBoundary(t){var o;if(t.type!=="updateRun")return!1;const n=(o=t.patch)==null?void 0:o.value;return typeof n!="string"||n.length===0?!1:/\s/.test(n[n.length-1])}_record(t,n,o){var l;this.redoStack=[];const s=this._batchKeyFor(t),r=this.currentBatch&&o.timestamp-this.currentBatch.lastTimestamp<=this.idleMs;this.currentBatch&&s!==null&&this.currentBatch.batchKey===s&&r&&!this.currentBatch.boundaryHit?(this.currentBatch.ops.push(t),this.currentBatch.inverses.unshift(n),this.currentBatch.lastTimestamp=o.timestamp,this._isWordBoundary(t)&&(this.currentBatch.boundaryHit=!0)):(this._commitCurrentBatch(),this.currentBatch={ops:[t],inverses:[n],batchKey:s,actorId:o.actorId,timestamp:o.timestamp,lastTimestamp:o.timestamp,boundaryHit:this._isWordBoundary(t)}),this._resetIdleTimer(),this.historyLog.push({opType:t.type,id:t.id??((l=t.block)==null?void 0:l.id),actorId:o.actorId,timestamp:o.timestamp}),this._recordChange(t,n,o),this._notify()}_resetIdleTimer(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this._commitCurrentBatch(),this._notify()},this.idleMs)}_commitCurrentBatch(){this.currentBatch&&(this.undoStack.push(this.currentBatch),this.currentBatch=null,this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null))}flush(){this._commitCurrentBatch(),this._notify()}undo(){this._commitCurrentBatch();const t=this.undoStack.pop();if(!t)return!1;for(const o of t.inverses)this.store.applyOperation(o);this.redoStack.push(t);const n=Fe(t);return this._pendingSelection=n?{runId:n.runId,offset:n.beforeOffset}:null,this._pendingAffectedBlockIds=He(t),this._notify(),!0}redo(){const t=this.redoStack.pop();if(!t)return!1;for(const o of t.ops)this.store.applyOperation(o);this.undoStack.push(t);const n=Fe(t);return this._pendingSelection=n?{runId:n.runId,offset:n.afterOffset}:null,this._pendingAffectedBlockIds=He(t),this._notify(),!0}canUndo(){return this.undoStack.length>0||this.currentBatch!==null}canRedo(){return this.redoStack.length>0}getHistoryLog(){return[...this.historyLog]}subscribeToHistory(t){return this._listeners.add(t),()=>this._listeners.delete(t)}_notify(){for(const t of this._listeners)t()}}function tn({scope:e}={}){const[t,n]=k.useState([]),[o,s]=k.useState(!1),r=k.useCallback(()=>(s(!1),q.listTemplates().then(a=>{n(e?a.filter(l=>l.scope===e):a),s(!0)})),[e]);return k.useEffect(()=>{let a=!1;return s(!1),q.listTemplates().then(l=>{a||(n(e?l.filter(u=>u.scope===e):l),s(!0))}),()=>{a=!0}},[e]),{templates:t,isLoaded:o,refresh:r}}function nn({templates:e,onSelect:t,emptyLabel:n="No templates yet."}){return e.length===0?d.jsx("p",{className:"be-template-picker-empty",children:n}):d.jsx("ul",{className:"be-template-picker",role:"list",children:e.map(o=>d.jsxs("li",{className:"be-template-card",children:[d.jsxs("div",{className:"be-template-card-body",children:[d.jsx("span",{className:"be-template-card-name",children:o.name}),o.description&&d.jsx("span",{className:"be-template-card-description",children:o.description})]}),d.jsx("button",{type:"button",className:"be-template-card-select",onClick:()=>t(o),children:"Use"})]},o.id))})}function on(e,{name:t,color:n}){const o=h.genId();return e.applyOperation(h.addPerson({id:o,name:t,color:n})),o}function sn(e,t,n){e.applyOperation(h.updatePerson(t,n))}function rn(e,t){e.applyOperation(h.removePerson(t))}const ln="$people";function an(){const e=h.useEditorStore(),t=k.useCallback(o=>e.subscribe(ln,o),[e]),n=k.useCallback(()=>e.getPeople(),[e]);return k.useSyncExternalStore(t,n)}function cn(e,t){e.applyOperation(h.setTitle(t))}const un="$title";function dn(){const e=h.useEditorStore(),t=k.useCallback(o=>e.subscribe(un,o),[e]),n=k.useCallback(()=>e.getTitle(),[e]);return k.useSyncExternalStore(t,n)}class Ge{constructor(){this._types=new Map}register(t,n){this._types.set(t,n)}get(t){return this._types.get(t)}isLeaf(t){var n;return!!((n=this._types.get(t))!=null&&n.isLeaf)}listSlashCommands(){const t=[];for(const n of this._types.values())n.slashCommand&&t.push(n.slashCommand),n.slashCommands&&t.push(...n.slashCommands);return t}listHtmlMatchers(){return[...this._types.values()].filter(t=>t.fromHTML)}}function Ye(){return new Ge}class Je{constructor(){this._types=new Map}register(t,n){this._types.set(t,n)}unregister(t){this._types.delete(t)}get(t){return this._types.get(t)}listHtmlMatchers(){return[...this._types.values()].filter(t=>t.fromHTML)}listSlashCommands(){const t=[];for(const n of this._types.values())n.slashCommand&&t.push(n.slashCommand),n.slashCommands&&t.push(...n.slashCommands);return t}listAtCommands(){const t=[];for(const n of this._types.values())n.atCommand&&t.push(n.atCommand),n.atCommands&&t.push(...n.atCommands);return t}}function Xe(){return new Je}function Qe(e){Ze(e,{paragraph:I.paragraphBlockType,heading:I.headingBlockType,listItem:I.listItemBlockType,...et,...tt,divider:I.dividerBlockType,callout:I.calloutBlockType,blockquote:I.blockquoteBlockType,code:I.codeBlockType,toggleHeading:I.toggleHeadingBlockType,button:I.buttonBlockType,embed:I.embedBlockType,canvas:K.canvasBlockType})}function Ze(e,t){for(const[n,o]of Object.entries(t))e.register(n,o)}const et={table:I.tableBlockType,tableRow:I.tableRowBlockType,tableCell:I.tableCellBlockType},tt={layout:I.layoutBlockType,layoutColumn:I.layoutColumnBlockType};function nt(e){ot(e,{select:I.selectInlineType,date:I.dateInlineType,checkbox:I.checkboxInlineType,...st,emoji:I.emojiInlineType})}function ot(e,t){for(const[n,o]of Object.entries(t))e.register(n,o)}const st={tableSelect:I.tableSelectInlineType},ye={'"':{open:"“",close:"”"},"'":{open:"‘",close:"’"}};function fn(e,t){const n=ye[e];return t===void 0||/[\s([{“‘]/.test(t)?n.open:n.close}function rt(e){return e.inputType!=="insertText"||!e.data||e.data.length!==1?null:e.data}function ce(e,t,n){var o;return((o=e.getBlock(t))==null?void 0:o.type)===n}function pn(){return K.defineExtension({name:"smart-quotes",onBeforeInput(e,t){const n=rt(t);if(!n||!ye[n])return!1;const o=ye[n],s=e.getSelection();if(s){if(ce(e,s.blockId,"code"))return!1;const c=e.getRun(s.runId);if(!c||c.type!=="text")return!1;const i=c.value??"",f=i.slice(0,s.startOffset)+o.open+i.slice(s.startOffset,s.endOffset)+o.close+i.slice(s.endOffset);return e.applyOperation(h.updateRun(c.id,{value:f})),e.setCaret(c.id,s.endOffset+2),!0}const r=e.getCaret();if(!r||ce(e,r.blockId,"code"))return!1;const a=e.getRun(r.runId);if(!a||a.type!=="text")return!1;const l=a.value??"",u=fn(n,l[r.offset-1]);return e.applyOperation(h.updateRun(a.id,{value:l.slice(0,r.offset)+u+l.slice(r.offset)})),e.setCaret(a.id,r.offset+1),!0}})}const lt={"(":")","[":"]","{":"}"},mn=new Set(Object.values(lt));function hn(){return K.defineExtension({name:"auto-pair-brackets",onBeforeInput(e,t){const n=rt(t);if(!n)return!1;const o=lt[n];if(o){const s=e.getSelection();if(s){if(ce(e,s.blockId,"code"))return!1;const u=e.getRun(s.runId);if(!u||u.type!=="text")return!1;const c=u.value??"",i=c.slice(0,s.startOffset)+n+c.slice(s.startOffset,s.endOffset)+o+c.slice(s.endOffset);return e.applyOperation(h.updateRun(u.id,{value:i})),e.setCaret(u.id,s.endOffset+2),!0}const r=e.getCaret();if(!r||ce(e,r.blockId,"code"))return!1;const a=e.getRun(r.runId);if(!a||a.type!=="text")return!1;const l=a.value??"";return e.applyOperation(h.updateRun(a.id,{value:l.slice(0,r.offset)+n+o+l.slice(r.offset)})),e.setCaret(a.id,r.offset+1),!0}if(mn.has(n)){const s=e.getCaret();if(!s||ce(e,s.blockId,"code"))return!1;const r=e.getRun(s.runId);if(!r||r.type!=="text")return!1;if((r.value??"")[s.offset]===n)return e.setCaret(r.id,s.offset+1),!0}return!1}})}const at={heading:["level"],listItem:["ordered","checked","collapsed"],toggleHeading:["level","collapsed"],code:["language"],button:["href","color","customAttrs"],embed:["kind","src","name","alt","mimeType","align","width"],callout:["icon"]},ct=new Set(["listItem","toggleHeading"]),it=new Set(["divider","embed"]);function ut(e,t,n,o){var l,u,c;const s=n.type,r={};for(const i of at[s]??[])((l=n.props)==null?void 0:l[i])!==void 0&&(r[i]=n.props[i]);if(s==="table"){const i=n.contentIds[0]&&e.getBlock(n.contentIds[0]);return r.columns=I.resolveColumns(n,((u=i==null?void 0:i.contentIds)==null?void 0:u.length)??0),r.rows=n.contentIds.map(f=>e.getBlock(f).contentIds.map(m=>{const p=e.getBlock(m);return K.runsToHTML(p.contentIds.map(b=>e.getRun(b)),o)})),{id:n.id,type:s,data:r}}if(ct.has(s)){const i=((c=n.props)==null?void 0:c.titleRunIds)??[];r.text=K.runsToHTML(i.map(f=>e.getRun(f)),o)}else t.isLeaf(s)&&!it.has(s)&&(r.text=K.runsToHTML(n.contentIds.map(i=>e.getRun(i)),o));const a={id:n.id,type:s,data:r};return t.isLeaf(s)||(a.children=n.contentIds.map(i=>ut(e,t,e.getBlock(i),o))),a}function Re(e,t,n,{pretty:o=!0}={}){const s={store:e,registry:t,inlineRegistry:n},a=e.getBlock(e.getRootId()).contentIds.map(l=>ut(e,t,e.getBlock(l),s));return JSON.stringify({version:1,blocks:a},null,o?2:0)}function Ie(e,t){const n=new DOMParser().parseFromString(`<div>${e??""}</div>`,"text/html");return I.domInlineToRuns(n.body.firstChild,t)}function bn(e,t,n,o,s){const{id:r=h.genId(),data:a={}}=e,l=(a.rows??[]).map(c=>{const i=h.genId(),f=c.map(g=>{const m=h.genId(),p=Ie(g,s);return o.push(...p),n.push({id:m,type:"tableCell",parentId:i,contentIds:p.map(b=>b.id),props:{}}),m});return n.push({id:i,type:"tableRow",parentId:t,contentIds:f,props:{}}),i}),u={id:r,type:"table",parentId:t,contentIds:l,props:{columns:a.columns??[]}};return n.push(u),u}function Ce(e,t,n,o,s,r){const{id:a=h.genId(),type:l,data:u={},children:c=[]}=e;if(l==="table")return bn(e,t,s,r,o);const i={};for(const g of at[l]??[])u[g]!==void 0&&(i[g]=u[g]);const f={id:a,type:l,parentId:t,contentIds:[],props:i};if(s.push(f),ct.has(l)){const g=Ie(u.text,o);r.push(...g),f.props.titleRunIds=g.map(m=>m.id),f.contentIds=c.map(m=>Ce(m,a,n,o,s,r).id)}else if(n.isLeaf(l)){if(!it.has(l)){const g=Ie(u.text,o);r.push(...g),f.contentIds=g.map(m=>m.id)}}else f.contentIds=c.map(g=>Ce(g,a,n,o,s,r).id);return f}function dt(e){return!!e&&typeof e=="object"&&Array.isArray(e.blocks)&&e.rootId===void 0&&e.runs===void 0}function ft(e,t,n){const o=typeof e=="string"?JSON.parse(e):e,s={registry:t,inlineRegistry:n},r=h.genId(),a=[],l=[],u=(o.blocks??[]).map(c=>Ce(c,r,t,s,a,l).id);return a.push({id:r,type:"page",parentId:null,contentIds:u,props:{}}),{rootId:r,blocks:a,runs:l}}function gn(){const e="root",t=h.genId(),n=h.genId();return{rootId:e,blocks:[{id:e,type:"page",parentId:null,contentIds:[t],props:{}},{id:t,type:"paragraph",parentId:e,contentIds:[n],props:{}}],runs:[{id:n,type:"text",value:"",marks:{}}]}}function kn({doc:e,history:t=!0,currentUserId:n=null,extensions:o,registerBlocks:s,registerInlineTypes:r}={}){return k.useMemo(()=>{const a=Ye(),l=Xe();o!=null&&K.registerExtensions(o,{registry:a,inlineRegistry:l}),s?s(a):o==null&&Qe(a),r?r(l):o==null&&nt(l);const u=e==null?gn():dt(e)?ft(e,a,l):e,c=new F.EditorStore(u),i=t?new We(c,{defaultActorId:n}):c;return{store:i,registry:a,inlineRegistry:l,extensions:o!=null?o.flat(1/0):[],toJSON:({format:f="simple"}={})=>f==="internal"?i.toJSON():JSON.parse(Re(i,a,l))}},[])}function pt({minHeight:e=180,className:t="be-trailing-space"}){const n=h.useEditorStore(),[o]=h.usePreviewMode(),s=k.useCallback(()=>{var c;if(o)return;const r=n.getRootId(),a=n.getBlock(r),l=(c=a==null?void 0:a.contentIds)==null?void 0:c[a.contentIds.length-1];if(!l){const i=I.ensureRootNonEmpty(n);i&&O.focusBlockEnd(n,i);return}const u=n.getBlock(l);(u==null?void 0:u.type)==="paragraph"?O.focusBlockEnd(n,l):O.insertSiblingAfterAndFocus(n,l,O.createTextLeafBlock("paragraph"))},[n,o]);return d.jsx("div",{className:t,style:{minHeight:e},onClick:s})}async function ve(e,t,n,o){var a,l,u;const{html:s,text:r}=le.serializeBlockRange(e,t,o,n);if(typeof ClipboardItem<"u"&&((a=navigator.clipboard)!=null&&a.write)){await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([r],{type:"text/plain"}),"text/html":new Blob([s],{type:"text/html"})})]);return}await((u=(l=navigator.clipboard)==null?void 0:l.writeText)==null?void 0:u.call(l,r))}function Te(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function ie(e,t){t.length!==0&&Te(e,t.map(n=>h.removeBlock(n)))}function mt(e,t){if(t.length===0)return!1;const n=e.getBlock(t[0]);if(!n)return!1;const o=e.getBlock(n.parentId);if(!o)return!1;const s=o.contentIds.indexOf(t[0]),r=o.contentIds.indexOf(t[t.length-1]);if(s<=0)return!1;const a=o.contentIds[s-1];return e.applyOperation(h.moveBlock(a,n.parentId,r)),!0}function ht(e,t){if(t.length===0)return!1;const n=e.getBlock(t[0]);if(!n)return!1;const o=e.getBlock(n.parentId);if(!o)return!1;const s=o.contentIds.indexOf(t[0]),r=o.contentIds.indexOf(t[t.length-1]);if(r===-1||r>=o.contentIds.length-1)return!1;const a=o.contentIds[r+1];return e.applyOperation(h.moveBlock(a,n.parentId,s)),!0}function bt(e,t){return t.length>0&&t.every(n=>{var o,s;return!!((s=(o=e.getBlock(n))==null?void 0:o.props)!=null&&s.hidden)})}function gt(e,t,n){t.length!==0&&Te(e,t.map(o=>h.updateBlockProps(o,{hidden:n})))}function yn(e,t,n,o){const s=n.filter(a=>{var l;return I.isTurnIntoEligible((l=e.getBlock(a))==null?void 0:l.type)});if(s.length===0)return;const r=s.flatMap(a=>I.turnBlockInto(e,t,a,o).ops);Te(e,r)}function In(e,t){if(t.length===0)return[];const n=e.getBlock(t[0]),o=n&&e.getBlock(n.parentId);if(!o)return t;const s=new Set(t);return o.contentIds.filter(r=>s.has(r))}function kt(){const e=h.useEditorStore(),t=h.useBlockRegistry(),n=h.useInlineRegistry(),[o,s]=h.useBlockRangeSelection(),[r,a]=k.useState(null),l=k.useRef(null),u=k.useRef(null),c=o.length>0,i=I.useAutoAdjustedPosition(l,c,(r==null?void 0:r.bottom)!=null?r.bottom+4:null,r==null?void 0:r.left),f=k.useCallback(()=>s([]),[s]);I.useMenuKeyboardNav(l,c,f,void 0),k.useEffect(()=>{if(!c){a(null);return}const T=()=>{const j=o[o.length-1],M=document.querySelector(`[data-block-row-id="${j}"]`);a((M==null?void 0:M.getBoundingClientRect())??null)};return T(),window.addEventListener("scroll",T,!0),window.addEventListener("resize",T),()=>{window.removeEventListener("scroll",T,!0),window.removeEventListener("resize",T)}},[c,o]),k.useEffect(()=>{if(!c)return;const T=M=>{var E,L,R,A;(E=l.current)!=null&&E.contains(M.target)||(L=u.current)!=null&&L.contains(M.target)||(A=(R=M.target).closest)!=null&&A.call(R,".be-block-gutter")||f()},j=M=>{M.key==="Escape"?f():(M.key==="Delete"||M.key==="Backspace")&&(M.preventDefault(),ie(e,o),f())};return document.addEventListener("mousedown",T),document.addEventListener("keydown",j),()=>{document.removeEventListener("mousedown",T),document.removeEventListener("keydown",j)}},[c,e,o,f]);const g=T=>T===1?"block":"blocks",m=k.useCallback(()=>{ve(e,t,n,o),I.announce(`${o.length} ${g(o.length)} copied`),f()},[e,t,n,o,f]),p=k.useCallback(async()=>{await ve(e,t,n,o);const T=o.length;ie(e,o),I.announce(`${T} ${g(T)} cut`),f()},[e,t,n,o,f]),b=k.useCallback(()=>{const T=o.length;ie(e,o),I.announce(`${T} ${g(T)} deleted`),f()},[e,o,f]),y=k.useCallback(()=>{mt(e,o)&&I.announce(`${o.length} ${g(o.length)} moved up`),f()},[e,o,f]),v=k.useCallback(()=>{ht(e,o)&&I.announce(`${o.length} ${g(o.length)} moved down`),f()},[e,o,f]),C=bt(e,o),S=k.useCallback(()=>{gt(e,o,!C),I.announce(C?`${o.length} ${g(o.length)} shown in preview`:`${o.length} ${g(o.length)} hidden in preview`),f()},[e,o,C,f]),x=o.some(T=>{var j;return I.isTurnIntoEligible((j=e.getBlock(T))==null?void 0:j.type)}),B=k.useCallback(T=>{const j=o.length;yn(e,t,o,T),I.announce(`${j} ${g(j)} turned into ${T.label}`),f()},[e,t,o,f]);return!c||!i?null:Z.createPortal(d.jsxs("div",{ref:l,role:"menu","aria-label":"Selected blocks options",className:"be-block-range-menu",style:{position:"fixed",top:i.top,left:i.left},children:[d.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:m,children:[d.jsx(h.CopyIcon,{size:15})," Copy"]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:p,children:[d.jsx(h.ScissorsIcon,{size:15})," Cut"]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:y,children:[d.jsx(h.ArrowUpIcon,{size:15})," Move up"]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:v,children:[d.jsx(h.ArrowDownIcon,{size:15})," Move down"]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:S,children:[C?d.jsx(h.EyeIcon,{size:15}):d.jsx(h.EyeOffIcon,{size:15}),C?"Show in preview":"Hide in preview"]}),x&&d.jsx(I.TurnIntoSubmenu,{onSelect:B,onClose:()=>{},containerRef:u,menuClassName:"be-block-range-menu",itemClassName:"be-block-range-menu-item"}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item be-block-range-menu-item-danger",onClick:b,children:[d.jsx(h.TrashIcon,{size:15})," Delete"]})]}),document.body)}const pe="application/x-block-editor-blocks+json";function Ee(e){return e.split(/\r\n|\r|\n/).filter(t=>t.length>0).map(t=>{const n=h.genId();return{block:{id:h.genId(),type:"paragraph",parentId:null,contentIds:[n],props:{}},runs:[{id:n,type:"text",value:t,marks:{}}]}})}function yt(e,t,n){var c,i;const o=new DOMParser().parseFromString(e,"text/html"),s={registry:t,inlineRegistry:n},r=t.listHtmlMatchers(),a=[],l=f=>{var p;const g=f.tagName==="OL",m=[];for(const b of f.children){if(b.tagName!=="LI")continue;const y=(p=t.get("listItem"))==null?void 0:p.fromHTML(b,s);y&&(y.block.props.ordered=g,m.push(y))}return m},u=f=>{var m;const g=Array.from(f.children).filter(p=>p.tagName==="P");if(g.length===0){const p=(m=t.get("blockquote"))==null?void 0:m.fromHTML(f,s);return p?[p]:[]}return g.map(p=>{const b=I.domInlineToRuns(p,s);return{block:{id:h.genId(),type:"blockquote",parentId:null,contentIds:b.map(y=>y.id),props:{}},runs:b}})};for(const f of o.body.childNodes){if(f.nodeType===3){const m=f.textContent.trim();m&&a.push(...Ee(m));continue}if(f.nodeType!==1)continue;if(f.tagName==="UL"||f.tagName==="OL"){a.push(...l(f));continue}if(f.tagName==="BLOCKQUOTE"){a.push(...u(f));continue}let g=null;for(const m of r){const p=m.fromHTML(f,s);if(p){g=p;break}}if(!g){const m=(c=f.querySelector)==null?void 0:c.call(f,"pre");m&&(g=((i=t.get("code"))==null?void 0:i.fromHTML(m,s))??null)}if(g)a.push(g);else if(f.textContent.trim()){const m=I.domInlineToRuns(f,s);a.push({block:{id:h.genId(),type:"paragraph",parentId:null,contentIds:m.map(p=>p.id),props:{}},runs:m})}}return a}function It(e,t,n){const o=e.types??[];if(o.includes(pe)){const r=e.getData(pe);if(r)return Cn(r)}if(o.includes("text/html")){const r=e.getData("text/html");if(r)return yt(r,t,n)}const s=e.getData("text/plain")??"";return Ee(s)}function Cn(e){return JSON.parse(e).blocks.map(n=>le.remapSubtreeIds(n))}function Be(e,t){var o;const n=e.getBlock(t);return((o=n.props)==null?void 0:o.titleRunIds)??n.contentIds}function de(){return{id:h.genId(),type:"text",value:"",marks:{}}}function xe(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Oe(e,t,n){const{startRunId:o,startOffset:s,endRunId:r,endOffset:a}=n,l=Be(e,t),u=l.indexOf(o),c=l.indexOf(r);if(u===-1||c===-1)return null;const[i,f]=u<=c?[u,c]:[c,u],g=u<=c?s:a,m=u<=c?a:s,p=l.slice(0,i).map(B=>e.getRun(B)),b=l.slice(f+1).map(B=>e.getRun(B)),y=l.slice(i,f+1).map(B=>e.getRun(B)),v=[];let C=null,S=0;if(i===f){const B=y[0];if(B.type==="text"){const T=Math.max(0,Math.min(g,m)),j=Math.min(B.value.length,Math.max(g,m)),M={...B,value:B.value.slice(0,T)+B.value.slice(j)};v.push(M),C=M.id,S=T}}else y.forEach((B,T)=>{if(B.type!=="text")return;const j=T===0,M=T===y.length-1,E=j?B.value.slice(0,g):"";if(j&&E){const L={...B,value:E};v.push(L),C=L.id,S=E.length}if(M&&!j){const L=B.value.slice(m);if(L){const R={id:h.genId(),type:"text",value:L,marks:B.marks};v.push(R),C===null&&(C=R.id,S=0)}}});let x=[...p,...v,...b];if(x.length===0){const B=de();x=[B],C=B.id,S=0}else if(C===null){const B=p[p.length-1];B?(C=B.id,S=B.type==="text"?B.value.length:0):b[0]&&(C=b[0].id,S=0)}return e.applyOperation(h.setBlockRuns(t,x)),{blockId:t,runId:C,offset:S}}function Le(e,t){const{blockIds:n,startBlockId:o,startRunId:s,startOffset:r,endBlockId:a,endRunId:l,endOffset:u}=t;if(!n||n.length===0)return null;const c=n.indexOf(o),i=n.indexOf(a);if(c===-1||i===-1)return null;const[f,g]=c<=i?[c,i]:[i,c],m=c<=i,p=m?s:l,b=m?r:u,y=m?l:s,v=m?u:r;if(f===g)return Oe(e,n[f],{startRunId:p,startOffset:b,endRunId:y,endOffset:v});const C=n[f],S=n[g],x=e.getBlock(C),B=e.getBlock(S),T=Be(e,C),j=T.indexOf(p),M=T.slice(0,j).map(z=>e.getRun(z)),E=e.getRun(p),L=E.type==="text"&&b>0?{...E,value:E.value.slice(0,b)}:null,R=Be(e,S),A=R.indexOf(y),P=R.slice(A+1).map(z=>e.getRun(z)),N=e.getRun(y),$=N.type==="text"&&v<N.value.length?{id:h.genId(),type:"text",value:N.value.slice(v),marks:N.marks}:null,U=[...M,...L?[L]:[]],J=[...$?[$]:[],...P],w=[];for(let z=f+1;z<g;z+=1)w.push(h.removeBlock(n[z]));const D=I.canMergeTypes(x.type,B.type),_=e.getBlock(x.parentId),G=g-f-1+(D?1:0),V=_&&_.contentIds.length-G===1;let H,W,ae;if(D){const z=[...U,...J];if(z.length===0&&V&&x.type!=="paragraph"){const{block:Q,runs:Xt}=O.createTextLeafBlock("paragraph")(_.id);return w.push({type:"insertBlock",block:Q,parentId:_.id,index:0,subtree:{blocks:[Q],runs:Xt}}),w.push(h.removeBlock(C)),w.push(h.removeBlock(S)),xe(e,w),{blockId:Q.id,runId:Q.contentIds[0],offset:0}}const ne=z.length?z:[de()];if(w.push(h.setBlockRuns(C,ne)),w.push(h.removeBlock(S)),ae=C,L)H=L.id,W=L.value.length;else if(M.length){const Q=M[M.length-1];H=Q.id,W=Q.type==="text"?Q.value.length:0}else $?(H=$.id,W=0):P.length?(H=P[0].id,W=0):(H=ne[0].id,W=0)}else{const z=U.length?U:[de()];if(w.push(h.setBlockRuns(C,z)),w.push(h.setBlockRuns(S,J.length?J:[de()])),ae=C,L)H=L.id,W=L.value.length;else if(M.length){const ne=M[M.length-1];H=ne.id,W=ne.type==="text"?ne.value.length:0}else H=z[0].id,W=0}return xe(e,w),{blockId:ae,runId:H,offset:W}}function me(e,t=""){var l;const n=e.getRootId(),o=((l=e.getBlock(n))==null?void 0:l.contentIds)??[];if(o.length===0)return null;const s=o.map(u=>h.removeBlock(u)),{block:r,runs:a}=O.createTextLeafBlock("paragraph")(n);return t&&(a[0].value=t),s.push(h.insertBlock(r,n,0,{blocks:[r],runs:a})),xe(e,s),{blockId:r.id,runId:r.contentIds[0],offset:t.length}}function ge(e){return(e==null?void 0:e.tagName)==="INPUT"||(e==null?void 0:e.tagName)==="TEXTAREA"}function ue(e){var n;let t=(e==null?void 0:e.nodeType)===1?e:e==null?void 0:e.parentElement;for(;t&&typeof t.hasAttribute=="function"&&!t.hasAttribute("data-block-id");)t=t.parentElement;return((n=t==null?void 0:t.getAttribute)==null?void 0:n.call(t,"data-block-id"))??null}function vn(e){var f;const t=(f=window.getSelection)==null?void 0:f.call(window);if(!t||t.rangeCount===0)return[];const n=ue(t.anchorNode),o=ue(t.focusNode);if(!n)return[];if(!o||n===o)return[n];const s=e.getBlock(n),r=s&&e.getBlock(s.parentId);if(!r)return[n];const a=r.contentIds,l=a.indexOf(n),u=a.indexOf(o);if(l===-1||u===-1)return[n];const[c,i]=l<=u?[l,u]:[u,l];return a.slice(c,i+1)}function ke(e){const t=O.resolveMultiRunSelection();if(t)return Oe(e,t.blockId,t);const n=O.resolveCrossBlockSelection(e);return n?Le(e,n):null}function $e(e,t,n){const o=e.getRun(t.runId);if(!o||o.type!=="text")return null;const s=o.value??"",r=s.slice(0,t.offset)+n+s.slice(t.offset);return e.applyOperation(h.updateRun(o.id,{value:r})),{blockId:t.blockId,runId:o.id,offset:t.offset+n.length}}function oe(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Ct(){const e=h.useEditorStore(),t=h.useBlockRegistry(),n=h.useInlineRegistry(),{uploadFile:o,maxFileSize:s}=h.useFileUpload(),[r,a]=h.useWholeDocumentSelection(),[l,u]=h.useBlockRangeSelection(),c=k.useCallback(m=>{var C;if(ge(m.target))return;const p=r?((C=e.getBlock(e.getRootId()))==null?void 0:C.contentIds)??[]:l.length>0?l:vn(e);if(p.length===0)return;const{html:b,text:y,json:v}=le.serializeBlockRange(e,t,p,n);m.clipboardData.setData("text/plain",y),m.clipboardData.setData("text/html",b),m.clipboardData.setData(pe,v),m.preventDefault()},[e,t,n,r,l]),i=k.useCallback(m=>{if(ge(m.target))return;if(c(m),r){const b=me(e);a(!1),b!=null&&b.runId&&O.focusRunAtOffset(b.runId,b.offset);return}if(l.length>0){ie(e,l),u([]);return}const p=ke(e);p!=null&&p.runId&&O.focusRunAtOffset(p.runId,p.offset)},[c,e,r,a,l,u]),f=k.useCallback(async m=>{var T,j,M;const b=(await Promise.allSettled(m.map(E=>I.resolveFileToEmbedInsert(E,{uploadFile:o,maxFileSize:s})))).filter(E=>E.status==="fulfilled").map(E=>E.value);if(b.length===0)return;if(r){const E=e.getRootId(),R=(((T=e.getBlock(E))==null?void 0:T.contentIds)??[]).map(P=>h.removeBlock(P));let A=0;for(const{block:P,runs:N,subtreeBlocks:$=[]}of b)P.parentId=E,R.push(h.insertBlock(P,E,A,{blocks:[P,...$],runs:N})),A+=1;oe(e,R),a(!1);return}if(l.length>0){const E=e.getBlock(l[0]),L=(E==null?void 0:E.parentId)??null,R=L&&e.getBlock(L);let A=R?R.contentIds.indexOf(l[0]):0;const P=l.map(N=>h.removeBlock(N));for(const{block:N,runs:$,subtreeBlocks:U=[]}of b)N.parentId=L,P.push(h.insertBlock(N,L,A,{blocks:[N,...U],runs:$})),A+=1;oe(e,P),u([]);return}const y=ke(e),v=(y==null?void 0:y.blockId)??ue((M=(j=window.getSelection)==null?void 0:j.call(window))==null?void 0:M.anchorNode);if(!v)return;const C=e.getBlock(v);if(!C)return;let x=e.getBlock(C.parentId).contentIds.indexOf(v)+1;const B=[];for(const{block:E,runs:L,subtreeBlocks:R=[]}of b)E.parentId=C.parentId,B.push(h.insertBlock(E,C.parentId,x,{blocks:[E,...R],runs:L})),x+=1;oe(e,B)},[e,o,s,r,a,l,u]),g=k.useCallback(m=>{var A,P,N,$,U,J;if(ge(m.target))return;const p=Array.from(((A=m.clipboardData)==null?void 0:A.files)??[]);if(p.length>0){m.preventDefault(),f(p);return}const b=It(m.clipboardData,t,n);if(b.length===0)return;if(r){const w=e.getRootId(),_=(((P=e.getBlock(w))==null?void 0:P.contentIds)??[]).map(V=>h.removeBlock(V));let G=0;for(const{block:V,runs:H,subtreeBlocks:W=[]}of b)V.parentId=w,_.push(h.insertBlock(V,w,G,{blocks:[V,...W],runs:H})),G+=1;oe(e,_),a(!1),m.preventDefault();return}if(l.length>0){const w=e.getBlock(l[0]),D=(w==null?void 0:w.parentId)??null,_=D&&e.getBlock(D);let G=_?_.contentIds.indexOf(l[0]):0;const V=l.map(H=>h.removeBlock(H));for(const{block:H,runs:W,subtreeBlocks:ae=[]}of b)H.parentId=D,V.push(h.insertBlock(H,D,G,{blocks:[H,...ae],runs:W})),G+=1;oe(e,V),u([]),m.preventDefault();return}const y=ke(e),v=(y==null?void 0:y.blockId)??ue(($=(N=window.getSelection)==null?void 0:N.call(window))==null?void 0:$.anchorNode),C=v&&e.getBlock(v);if((C==null?void 0:C.type)==="code"){const w=y?{blockId:y.blockId,runId:y.runId,offset:y.offset}:O.resolveCollapsedCaret();if(w){const D=b.map(({runs:G})=>G.filter(V=>V.type==="text").map(V=>V.value).join("")).join(`
2
+ `),_=$e(e,w,D);if(_){O.focusRunAtOffset(_.runId,_.offset),m.preventDefault();return}}}const S=b.length===1?b[0].runs[0]:null;if(b.length===1&&b[0].block.type==="paragraph"&&b[0].runs.length===1&&(S==null?void 0:S.type)==="text"&&Object.keys((S==null?void 0:S.marks)??{}).length===0&&(b[0].subtreeBlocks??[]).length===0){const w=y?{blockId:y.blockId,runId:y.runId,offset:y.offset}:O.resolveCollapsedCaret();if(w){const D=$e(e,w,S.value);if(D){O.focusRunAtOffset(D.runId,D.offset),m.preventDefault();return}}}const B=(y==null?void 0:y.blockId)??ue((J=(U=window.getSelection)==null?void 0:U.call(window))==null?void 0:J.anchorNode);if(!B)return;const T=e.getBlock(B);if(!T)return;let M=e.getBlock(T.parentId).contentIds.indexOf(B)+1;const E=[];for(const{block:w,runs:D,subtreeBlocks:_=[]}of b)w.parentId=T.parentId,E.push(h.insertBlock(w,T.parentId,M,{blocks:[w,..._],runs:D})),M+=1;oe(e,E);const L=[...b].reverse().find(w=>(w.runs??[]).length>0),R=L==null?void 0:L.runs[L.runs.length-1];R&&O.focusRunEnd(R.id),m.preventDefault()},[e,t,n,r,a,l,u,f]);return{onCopy:c,onCut:i,onPaste:g}}const Bn=["bold","italic","underline","strike","subscript","superscript","code"],xn=["color","highlight","link"];function se(e,t){var o;const n=e.getBlock(t);return((o=n.props)==null?void 0:o.titleRunIds)??n.contentIds}function Sn(e,t){return e===t?!0:e&&t&&typeof e=="object"?JSON.stringify(e)===JSON.stringify(t):!1}function vt(e){var n;const t={};if(e.length===0)return t;for(const o of Bn)t[o]=e.every(s=>{var r;return(r=s.marks)==null?void 0:r[o]});for(const o of xn){const s=((n=e[0].marks)==null?void 0:n[o])??null;t[o]=e.every(r=>{var a;return Sn(((a=r.marks)==null?void 0:a[o])??null,s)})?s:null}return t}function Me(e,t,n){const{startRunId:o,startOffset:s,endRunId:r,endOffset:a}=n,l=se(e,t),u=l.indexOf(o),c=l.indexOf(r);if(u===-1||c===-1)return{};const[i,f]=u<=c?[u,c]:[c,u],g=l.slice(i,f+1).map(m=>e.getRun(m)).filter(m=>m&&m.type==="text");return vt(g)}function je(e,t){const{blockIds:n,startBlockId:o,endBlockId:s}=t,r=n.indexOf(o),a=n.indexOf(s);if(r===-1||a===-1)return{};const[l,u]=r<=a?[r,a]:[a,r],c=[];for(let i=l;i<=u;i+=1)for(const f of se(e,n[i])){const g=e.getRun(f);g&&g.type==="text"&&c.push(g)}return vt(c)}function Bt(e,t){const n={...e};for(const[o,s]of Object.entries(t))s!=null?n[o]=s:delete n[o];return n}function xt(e,t,n,o,s,r){const a=Bt(n.marks,r);if(o===0&&s===n.value.length)return e.applyOperation({type:"updateRun",id:n.id,patch:{marks:a}}),n.id;const l=n.value.slice(0,o),u=n.value.slice(o,s),c=n.value.slice(s),i=[];l&&i.push({id:h.genId(),type:"text",value:l,marks:{...n.marks}});const f={id:h.genId(),type:"text",value:u,marks:a};return i.push(f),c&&i.push({id:h.genId(),type:"text",value:c,marks:{...n.marks}}),e.applyOperation(h.replaceRunSpan(t,[n.id],i)),f.id}function wn(e,t,n,o){var S;if(((S=e.getBlock(t))==null?void 0:S.type)==="code")return null;const{startRunId:s,startOffset:r,endRunId:a,endOffset:l}=n,u=se(e,t),c=u.indexOf(s),i=u.indexOf(a);if(c===-1||i===-1)return null;const[f,g]=c<=i?[c,i]:[i,c],m=c<=i?r:l,p=c<=i?l:r,b=u.slice(f,g+1),y=b.map(x=>e.getRun(x));if(f===g){const x=y[0];if(x.type!=="text")return x.id;const B=Math.max(0,Math.min(m,p)),T=Math.min(x.value.length,Math.max(m,p));return B===T?x.id:xt(e,t,x,B,T,o)}const v=[];let C=null;return y.forEach((x,B)=>{if(x.type!=="text"){v.push(x),C=x.id;return}const T=B===0,j=B===y.length-1,M=T?m:0,E=j?p:x.value.length,L=x.value.slice(0,M),R=x.value.slice(M,E),A=x.value.slice(E);L&&v.push({id:h.genId(),type:"text",value:L,marks:{...x.marks}});const P={id:h.genId(),type:"text",value:R,marks:Bt(x.marks,o)};v.push(P),C=P.id,A&&v.push({id:h.genId(),type:"text",value:A,marks:{...x.marks}})}),e.applyOperation(h.replaceRunSpan(t,b,v)),C}function Rn(e,t,n,o){var p;const{startRunId:s,startOffset:r,endRunId:a,endOffset:l}=n,u=se(e,t),c=u.indexOf(s),i=u.indexOf(a);if(c===-1||i===-1)return!0;const[f,g]=c<=i?[c,i]:[i,c],m=u.slice(f,g+1).map(b=>e.getRun(b)).filter(b=>b.type==="text");if(m.length===0)return!0;if(f===g){const b=Math.max(0,Math.min(r,l)),y=Math.min(m[0].value.length,Math.max(r,l));if(b===y)return!((p=m[0].marks)!=null&&p[o])}return!m.every(b=>{var y;return(y=b.marks)==null?void 0:y[o]})}function Tn(e,t,n,o,s,r){var f,g;if(((f=e.getBlock(t))==null?void 0:f.type)==="code")return n;const a=e.getRun(n),l=a.value??"",u=Math.max(0,Math.min(o,s)),c=Math.min(l.length,Math.max(o,s));if(u===c)return n;const i=!((g=a.marks)!=null&&g[r]);return xt(e,t,a,u,c,{[r]:i?!0:null})}function re(e,t,n,o){return wn(e,t,n,o)}function Ae(e,t,n,o){const s=Rn(e,t,n,o);return re(e,t,n,{[o]:s?!0:null})}function De(e,t,n){return he(e,t,o=>({[n]:o?null:!0}),n)}function he(e,t,n,o){var T;const{blockIds:s,startBlockId:r,startRunId:a,startOffset:l,endBlockId:u,endRunId:c,endOffset:i}=t;if(!s||s.length===0)return null;const f=s.indexOf(r),g=s.indexOf(u);if(f===-1||g===-1)return null;const[m,p]=f<=g?[f,g]:[g,f],b=f<=g,y=b?a:c,v=b?l:i,C=b?c:a,S=b?i:l;let x=n;if(typeof n=="function"){let j=!1,M=!0;for(let E=m;E<=p;E+=1){const L=se(e,s[E]).map(R=>e.getRun(R)).filter(R=>R.type==="text");L.length!==0&&(j=!0,L.every(R=>{var A;return(A=R.marks)==null?void 0:A[o]})||(M=!1))}x=n(j&&M)}if(m===p)return re(e,s[m],{startRunId:y,startOffset:v,endRunId:C,endOffset:S},x);let B=null;for(let j=m;j<=p;j+=1){const M=s[j],E=se(e,M),L=E[0],R=E[E.length-1],A=e.getRun(R),P=((T=A==null?void 0:A.value)==null?void 0:T.length)??0;let N;j===m&&j===p?N={startRunId:y,startOffset:v,endRunId:C,endOffset:S}:j===m?N={startRunId:y,startOffset:v,endRunId:R,endOffset:P}:j===p?N={startRunId:L,startOffset:0,endRunId:C,endOffset:S}:N={startRunId:L,startOffset:0,endRunId:R,endOffset:P},B=re(e,M,N,x)}return B}function St(e,t){var o;const n=e.getBlock(t);return((o=n==null?void 0:n.props)==null?void 0:o.titleRunIds)??(n==null?void 0:n.contentIds)??[]}function wt(e){const t=O.resolveMultiRunSelection();if(!t)return!1;const{blockId:n,startRunId:o,startOffset:s,endRunId:r,endOffset:a}=t,l=St(e,n);if(l.length===0)return!1;const u=l.indexOf(o),c=l.indexOf(r);if(u===-1||c===-1)return!1;const[i,f]=u<=c?[u,c]:[c,u],g=u<=c?s:a,m=u<=c?a:s;if(i!==0||f!==l.length-1||g!==0)return!1;const p=e.getRun(l[l.length-1]),b=(p==null?void 0:p.type)==="text"?(p.value??"").length:1;return m===b}function En(e){const t=O.resolveCollapsedCaret();return t?I.isRunsEmpty(e,St(e,t.blockId)):!1}function On(e,t,n){var m,p;const o=e.getBlock(t);if(!o){n(null);return}const s=e.getBlock(o.parentId),r=s?s.contentIds.indexOf(t):-1,a=r>0?s.contentIds[r-1]:null,l=r!==-1&&r<s.contentIds.length-1?s.contentIds[r+1]:null;e.applyOperation(h.removeBlock(t)),n(null);const u=I.ensureRootNonEmpty(e),c=a??l??u;if(!c)return;const i=e.getBlock(c);if(I.isContentlessBlock(e,i)){n(c),requestAnimationFrame(()=>{var b;return(b=document.querySelector(`[data-block-id="${c}"]`))==null?void 0:b.focus()});return}const f=(m=i==null?void 0:i.props)==null?void 0:m.titleRunIds,g=((p=i==null?void 0:i.contentIds)==null?void 0:p[i.contentIds.length-1])??(f==null?void 0:f[f.length-1]);g&&O.focusRunEnd(g)}const Ue={b:"bold",i:"italic",u:"underline"};function Rt(e){const t=h.useEditorStore(),[n,o]=h.useWholeDocumentSelection(),{getSelectedBlockId:s,setSelectedBlockId:r}=h.useSelectedBlock();k.useEffect(()=>{const a=e.current;if(!a)return;const l=c=>{var f,g;if(s()&&(c.key==="Backspace"||c.key==="Delete")&&!c.defaultPrevented){c.preventDefault(),c.stopPropagation(),On(t,s(),r);return}if(s()&&c.key!=="Backspace"&&c.key!=="Delete"&&r(null),c.metaKey||c.ctrlKey){const m=c.key.toLowerCase();if(m==="z"&&!c.shiftKey){c.preventDefault(),(f=t.undo)!=null&&f.call(t)&&X.restoreSelectionAfterHistoryChange(t);return}if(m==="z"&&c.shiftKey||m==="y"){c.preventDefault(),(g=t.redo)!=null&&g.call(t)&&X.restoreSelectionAfterHistoryChange(t);return}if(m==="a"){if(n)return;(wt(t)||En(t))&&(c.preventDefault(),o(!0));return}if(Ue[m]){if(n)return;c.preventDefault();const p=Ue[m],b=O.resolveMultiRunSelection();if(b){const v=Ae(t,b.blockId,b,p);v&&O.focusRunEnd(v);return}const y=O.resolveCrossBlockSelection(t);if(y){const v=De(t,y,p);v&&O.focusRunEnd(v)}}return}if(n){if(c.key==="Backspace"||c.key==="Delete"){c.preventDefault(),c.stopPropagation();const m=me(t);o(!1),m!=null&&m.runId&&O.focusRunAtOffset(m.runId,m.offset);return}if(c.key.length===1){c.preventDefault(),c.stopPropagation();const m=me(t,c.key);o(!1),m!=null&&m.runId&&O.focusRunAtOffset(m.runId,m.offset);return}if(o(!1),c.key==="Escape")return}if(c.key==="Backspace"||c.key==="Delete"){const m=O.resolveCrossBlockSelection(t);if(!m)return;c.preventDefault(),c.stopPropagation();const p=Le(t,m);p!=null&&p.runId&&O.focusRunAtOffset(p.runId,p.offset)}},u=()=>{n&&o(!1),s()&&r(null)};return a.addEventListener("keydown",l),a.addEventListener("mousedown",u),()=>{a.removeEventListener("keydown",l),a.removeEventListener("mousedown",u)}},[e,t,n,o,s,r])}function Ln(e,t){const n=h.useEditorStore(),o=h.useBlockRegistry(),s=h.useInlineRegistry(),r=k.useMemo(()=>(e??[]).filter(l=>l&&(l.keymap||l.onBeforeInput||l.onPaste||l.setup)),[e]),a=k.useMemo(()=>({store:n,registry:o,inlineRegistry:s,get container(){return t.current},getBlock:l=>n.getBlock(l),getRun:l=>n.getRun(l),getRootId:()=>n.getRootId(),applyOperation:l=>Z.flushSync(()=>n.applyOperation(l)),applyOperations:l=>Z.flushSync(()=>{if(typeof n.performBatch=="function")n.performBatch(l);else for(const u of l)n.applyOperation(u)}),getSelection:()=>O.resolveRunSelection(),getCaret:()=>O.resolveCollapsedCaret(),setCaret:(l,u)=>O.setCaretSync(l,u),subscribe:l=>n.subscribeAll(l)}),[n,o,s,t]);k.useEffect(()=>{const l=t.current;if(!l||r.length===0)return;const u=r.filter(p=>p.keymap),c=r.filter(p=>p.onBeforeInput),i=r.filter(p=>p.onPaste),f=p=>{for(const b of u)for(const[y,v]of Object.entries(b.keymap))if(Mn(p,y)&&v(a,p)){p.preventDefault(),p.stopImmediatePropagation();return}},g=p=>{for(const b of c)if(b.onBeforeInput(a,p)){p.preventDefault(),p.stopImmediatePropagation();return}},m=p=>{for(const b of i)if(b.onPaste(a,p)){p.preventDefault(),p.stopImmediatePropagation();return}};return u.length&&l.addEventListener("keydown",f),c.length&&l.addEventListener("beforeinput",g),i.length&&l.addEventListener("paste",m),()=>{l.removeEventListener("keydown",f),l.removeEventListener("beforeinput",g),l.removeEventListener("paste",m)}},[r,t,a]),k.useEffect(()=>{const l=r.filter(u=>u.setup).map(u=>u.setup(a)).filter(u=>typeof u=="function");return()=>{for(const u of l)u()}},[r,a])}function Mn(e,t){const n=String(t).split("-"),o=n.pop().toLowerCase(),s=new Set(n.map(a=>a.toLowerCase())),r=e.metaKey||e.ctrlKey;return s.has("mod")!==r||s.has("shift")!==e.shiftKey||s.has("alt")!==e.altKey?!1:e.key.toLowerCase()===o}const jn=4;function An(e,t,n){const o=e.getBlock(t);if(!o)return[];const s=e.getBlock(o.parentId);if(!s)return[t];const r=s.contentIds,a=r.indexOf(t),l=n?r.indexOf(n):a;if(a===-1)return[t];const[u,c]=l===-1?[a,a]:[Math.min(a,l),Math.max(a,l)];return r.slice(u,c+1)}function Dn(){var e,t;return typeof window<"u"&&((t=(e=window.matchMedia)==null?void 0:e.call(window,"(pointer: coarse)"))==null?void 0:t.matches)===!0}function Tt(e){const t=h.useEditorStore(),[,n]=h.useBlockRangeSelection(),o=k.useRef(null),s=k.useRef(!1),r=k.useRef(null),a=k.useCallback(i=>{var m,p,b,y,v;if(!o.current)return;if(!s.current){const{x:C,y:S}=r.current??{x:i.clientX,y:i.clientY};if(Math.hypot(i.clientX-C,i.clientY-S)<jn)return;s.current=!0,document.documentElement.classList.add("be-block-range-dragging"),(p=(m=window.getSelection)==null?void 0:m.call(window))==null||p.removeAllRanges()}(y=(b=window.getSelection)==null?void 0:b.call(window))==null||y.removeAllRanges(),i.preventDefault();const f=(v=document.elementFromPoint(i.clientX,i.clientY))==null?void 0:v.closest("[data-block-row-id]"),g=(f==null?void 0:f.getAttribute("data-block-row-id"))??null;n(An(t,o.current,g))},[t,n]),l=k.useCallback(()=>{o.current=null,s.current=!1,r.current=null,document.documentElement.classList.remove("be-block-range-dragging")},[]),u=k.useCallback((i,f)=>{l(),o.current=i,s.current=!1,r.current={x:f.clientX,y:f.clientY}},[l]),c=k.useCallback(i=>{var b,y;if(i.button!==0||Dn()||(y=(b=i.target).closest)!=null&&y.call(b,"button, input, textarea, select"))return;const f=i.target.closest("[data-block-row-id]");if(f){if(i.target.closest(".be-block-row-content"))return;u(f.getAttribute("data-block-row-id"),i);return}const g=e==null?void 0:e.current;if(!g)return;const p=[...g.querySelectorAll("[data-block-row-id]")].find(v=>{const C=v.getBoundingClientRect();return i.clientY>=C.top&&i.clientY<=C.bottom});p&&u(p.getAttribute("data-block-row-id"),i)},[e,u]);k.useEffect(()=>(document.addEventListener("mousedown",c),document.addEventListener("mousemove",a),document.addEventListener("mouseup",l),window.addEventListener("blur",l),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",l),window.removeEventListener("blur",l),document.documentElement.classList.remove("be-block-range-dragging")}),[c,a,l])}const Nn=340;function Pn(e,t,n,o){k.useEffect(()=>{if(!e||!t)return;const s=document.querySelector(`[data-run-id="${t}"]`);if(s)return s.setAttribute("aria-expanded","true"),s.setAttribute("aria-haspopup","listbox"),s.setAttribute("aria-controls",o),n&&s.setAttribute("aria-activedescendant",n),()=>{s.removeAttribute("aria-expanded"),s.removeAttribute("aria-haspopup"),s.removeAttribute("aria-controls"),s.removeAttribute("aria-activedescendant")}},[e,t,n,o])}function fe({isOpen:e,rect:t,commands:n,runId:o,onSelect:s,onClose:r,menuId:a="be-slash-menu",ariaLabel:l="Slash commands"}){const[u,c]=k.useState(0),i=k.useRef(null),f=k.useRef(null),g=I.useVirtualKeyboardInset(),m=te.useHorizontalAutoAdjustedLeft(f,e&&n.length>0&&!!t,t==null?void 0:t.left);k.useEffect(()=>{c(0)},[n.length]),k.useEffect(()=>{var S,x;(x=(S=i.current)==null?void 0:S.scrollIntoView)==null||x.call(S,{block:"nearest"})},[u]),k.useEffect(()=>{if(!e)return;const S=x=>{x.key==="ArrowDown"?(x.preventDefault(),x.stopPropagation(),c(B=>Math.min(B+1,Math.max(n.length-1,0)))):x.key==="ArrowUp"?(x.preventDefault(),x.stopPropagation(),c(B=>Math.max(B-1,0))):x.key==="Enter"?(x.preventDefault(),x.stopPropagation(),n[u]&&s(n[u])):x.key==="Escape"&&(x.preventDefault(),x.stopPropagation(),r())};return document.addEventListener("keydown",S,!0),()=>document.removeEventListener("keydown",S,!0)},[e,n,u,s,r]);const b=n[u]?`${a}-option-${u}`:null;if(Pn(e,o,b,a),!e||n.length===0||!t||m==null)return null;const y=window.innerHeight-g,C=t.bottom+Nn>y?{bottom:window.innerHeight-t.top+4}:{top:t.bottom+4};return d.jsx("div",{ref:f,id:a,role:"listbox","aria-label":l,className:"be-slash-menu",style:{position:"fixed",left:m,zIndex:1e3,...C},children:n.map((S,x)=>{const B=S.icon;return d.jsxs("div",{ref:x===u?i:void 0,id:`${a}-option-${x}`,role:"option","aria-selected":x===u,className:`be-slash-menu-item${x===u?" be-slash-menu-item-active":""}`,onMouseDown:T=>{T.preventDefault(),s(S)},onMouseEnter:()=>c(x),children:[B&&d.jsx("span",{className:"be-slash-menu-item-icon",children:d.jsx(B,{size:16})}),d.jsx("span",{className:"be-slash-menu-item-label",children:S.label})]},S.label)})})}function _n(){var e,t;return typeof window<"u"&&((t=(e=window.matchMedia)==null?void 0:e.call(window,"(hover: none) and (pointer: coarse)"))==null?void 0:t.matches)===!0}function Et(){const[e,t]=k.useState(_n);return k.useEffect(()=>{var s;if(typeof window>"u"||!window.matchMedia)return;const n=window.matchMedia("(hover: none) and (pointer: coarse)"),o=()=>t(n.matches);return o(),(s=n.addEventListener)==null||s.call(n,"change",o),()=>{var r;return(r=n.removeEventListener)==null?void 0:r.call(n,"change",o)}},[]),e}function Fn(e,t){var o;if(!t)return!0;const n=t.toLowerCase();return e.label.toLowerCase().includes(n)||((o=e.keywords)==null?void 0:o.some(s=>s.toLowerCase().includes(n)))}function Hn(e,t){const n=t.anchorNode,o=t.anchorOffset;let s;if(n===e){s="";for(let r=0;r<o&&r<e.childNodes.length;r+=1)s+=e.childNodes[r].textContent??""}else n&&n.parentElement===e?s=(n.textContent??"").slice(0,o):s=e.textContent??"";return O.stripEmptyRunPlaceholder(s).length}function Ne(e,t,n,o=!1){const s=h.useEditorStore(),[r,a]=k.useState(null);k.useEffect(()=>{const i=e.current;if(!i||o)return;const f=()=>{var T,j,M,E;const m=(T=window.getSelection)==null?void 0:T.call(window),p=m==null?void 0:m.anchorNode;let b=(p==null?void 0:p.nodeType)===1?p:p==null?void 0:p.parentElement;for(;b&&typeof b.hasAttribute=="function"&&!b.hasAttribute("data-run-id");)b=b.parentElement;const y=(j=b==null?void 0:b.getAttribute)==null?void 0:j.call(b,"data-run-id");if(!y||!m){a(null);return}const v=Hn(b,m),C=O.stripEmptyRunPlaceholder(b.textContent).slice(0,v),S=t.exec(C);if(!S){a(null);return}const x=(E=(M=b.closest)==null?void 0:M.call(b,"[data-block-id]"))==null?void 0:E.getAttribute("data-block-id");if(!x){a(null);return}const B=S.index+S[1].length;a({query:S[2],blockId:x,runId:y,sliceStart:B,sliceEnd:v,rect:b.getBoundingClientRect()})},g=m=>{m.key==="Escape"&&a(null)};return i.addEventListener("input",f),i.addEventListener("keydown",g),()=>{i.removeEventListener("input",f),i.removeEventListener("keydown",g)}},[e,t,o]),k.useEffect(()=>{o&&a(null)},[o]);const l=r?n().filter(i=>Fn(i,r.query)):[],u=k.useCallback(i=>{r&&(i.run(s,{blockId:r.blockId,runId:r.runId,sliceStart:r.sliceStart,sliceEnd:r.sliceEnd}),a(null))},[r,s]),c=k.useCallback(()=>a(null),[]);return{isOpen:!!r,query:(r==null?void 0:r.query)??"",rect:(r==null?void 0:r.rect)??null,runId:(r==null?void 0:r.runId)??null,commands:l,selectCommand:u,close:c}}const $n=/(^|\s)\/(\w*)$/;function Ot(e){const t=h.useBlockRegistry(),n=h.useInlineRegistry(),o=Et(),s=k.useCallback(()=>[...t.listSlashCommands(),...(n==null?void 0:n.listSlashCommands())??[]],[t,n]);return Ne(e,$n,s,o)}const Un=[{char:"😀",name:"grinning face",keywords:["smile","happy"]},{char:"😂",name:"face with tears of joy",keywords:["laugh","lol"]},{char:"😍",name:"heart eyes",keywords:["love","crush"]},{char:"😎",name:"cool",keywords:["sunglasses"]},{char:"🤔",name:"thinking face",keywords:["hmm"]},{char:"😉",name:"winking face",keywords:["wink"]},{char:"😢",name:"crying face",keywords:["sad","tear"]},{char:"😡",name:"angry face",keywords:["mad","rage"]},{char:"😱",name:"screaming face",keywords:["shock","scared"]},{char:"🥳",name:"party face",keywords:["celebrate","birthday"]},{char:"🙏",name:"folded hands",keywords:["please","pray","thanks"]},{char:"👍",name:"thumbs up",keywords:["approve","yes","like"]},{char:"👎",name:"thumbs down",keywords:["disapprove","no"]},{char:"👏",name:"clapping hands",keywords:["applause","congrats"]},{char:"🙌",name:"raised hands",keywords:["hooray","yay"]},{char:"👋",name:"waving hand",keywords:["hello","bye"]},{char:"✌️",name:"victory hand",keywords:["peace"]},{char:"💪",name:"flexed biceps",keywords:["strong","muscle"]},{char:"🤝",name:"handshake",keywords:["deal","agree"]},{char:"❤️",name:"red heart",keywords:["love"]},{char:"🔥",name:"fire",keywords:["hot","lit"]},{char:"⭐",name:"star",keywords:["favorite"]},{char:"✨",name:"sparkles",keywords:["shiny","magic"]},{char:"🎉",name:"party popper",keywords:["celebrate","congrats"]},{char:"🎊",name:"confetti ball",keywords:["celebrate"]},{char:"💡",name:"light bulb",keywords:["idea","tip"]},{char:"✅",name:"check mark",keywords:["done","yes","complete"]},{char:"❌",name:"cross mark",keywords:["no","wrong","delete"]},{char:"⚠️",name:"warning",keywords:["caution","alert"]},{char:"❓",name:"question mark",keywords:["question","help"]},{char:"❗",name:"exclamation mark",keywords:["important","alert"]},{char:"🚀",name:"rocket",keywords:["launch","fast","ship"]},{char:"🐛",name:"bug",keywords:["bug","issue"]},{char:"🔧",name:"wrench",keywords:["fix","tool","settings"]},{char:"📌",name:"pushpin",keywords:["pin","note"]},{char:"📎",name:"paperclip",keywords:["attachment","clip"]},{char:"📅",name:"calendar",keywords:["date","schedule"]},{char:"⏰",name:"alarm clock",keywords:["time","reminder"]},{char:"📈",name:"chart increasing",keywords:["growth","stats"]},{char:"📉",name:"chart decreasing",keywords:["decline","stats"]},{char:"💰",name:"money bag",keywords:["money","cash"]},{char:"💬",name:"speech balloon",keywords:["comment","chat"]},{char:"📝",name:"memo",keywords:["note","write"]},{char:"📚",name:"books",keywords:["reading","docs"]},{char:"🔗",name:"link",keywords:["url","chain"]},{char:"🔒",name:"locked",keywords:["private","secure"]},{char:"🔑",name:"key",keywords:["password","access"]},{char:"☕",name:"coffee",keywords:["coffee","break"]},{char:"🍕",name:"pizza",keywords:["food"]},{char:"🎂",name:"birthday cake",keywords:["birthday","cake"]},{char:"🎁",name:"gift",keywords:["present"]},{char:"🌟",name:"glowing star",keywords:["star","shiny"]},{char:"🌈",name:"rainbow",keywords:["colorful"]},{char:"☀️",name:"sun",keywords:["sunny","weather"]},{char:"🌧️",name:"rain cloud",keywords:["rainy","weather"]},{char:"🐶",name:"dog face",keywords:["dog","pet"]},{char:"🐱",name:"cat face",keywords:["cat","pet"]},{char:"🌍",name:"globe",keywords:["world","earth"]},{char:"🎯",name:"direct hit",keywords:["target","goal"]},{char:"🏆",name:"trophy",keywords:["win","award"]},{char:"🕐",name:"clock",keywords:["time"]},{char:"📣",name:"megaphone",keywords:["announce","shout"]},{char:"🧠",name:"brain",keywords:["smart","idea","mind"]},{char:"👀",name:"eyes",keywords:["look","watching"]}];function Kn(e,{runId:t,sliceStart:n,sliceEnd:o},s){const r=e.getRun(t),a=(r==null?void 0:r.value)??"",l=a.slice(0,n)+s+a.slice(o);e.applyOperation(h.updateRun(t,{value:l})),O.focusRunAtOffset(t,n+s.length)}const Vn=Un.map(({char:e,name:t,keywords:n})=>({label:`${e} ${t}`,keywords:n,run:(o,s)=>Kn(o,s,e)})),zn=/(^|\s):(\w*)$/,qn=()=>Vn;function Lt(e){return Ne(e,zn,qn)}const Wn=/(^|\s)@(\w*)$/;function Mt(e){const t=h.useInlineRegistry(),n=k.useCallback(()=>(t==null?void 0:t.listAtCommands())??[],[t]);return Ne(e,Wn,n)}function Pe(e,t,n,o,s){const[r,a]=k.useState(!1),l=k.useCallback(y=>{const v=t==="same-block"?re(e,n.blockId,n,y):he(e,o,y);return v&&O.focusRunEnd(v),v},[e,t,n,o]),u=k.useCallback(y=>{const v=t==="same-block"?Ae(e,n.blockId,n,y):De(e,o,y);v&&O.focusRunEnd(v)},[e,t,n,o]),c=k.useCallback(y=>{const v=y==="subscript"?"superscript":"subscript",C=!s[y];l({[y]:C?!0:null,[v]:null})},[s,l]),i=k.useRef(null),f=k.useCallback(()=>{i.current={kind:t,selection:n,crossSelection:o},a(!0)},[t,n,o]),g=k.useCallback(()=>a(!1),[]),m=k.useCallback(y=>{const v=i.current;if(!v)return;const C=v.kind==="same-block"?re(e,v.selection.blockId,v.selection,y):he(e,v.crossSelection,y);C&&O.focusRunEnd(C),a(!1)},[e]),p=k.useCallback((y,v)=>m({link:{href:y,target:v}}),[m]),b=k.useCallback(()=>m({link:null}),[m]);return{applyPatch:l,toggleBoolean:u,setSubSuper:c,isLinkModalOpen:r,openLinkModal:f,closeLinkModal:g,handleSaveLink:p,handleRemoveLink:b}}const Gn="be-touch-input";function Yn(){var e,t;return typeof window<"u"&&((t=(e=window.matchMedia)==null?void 0:e.call(window,"(pointer: coarse)"))==null?void 0:t.matches)===!0}function _e(){const[e,t]=k.useState(Yn);return k.useEffect(()=>{if(typeof window>"u")return;const n=o=>{t(o.pointerType==="touch"||o.pointerType==="pen")};return window.addEventListener("pointerdown",n,{passive:!0}),()=>window.removeEventListener("pointerdown",n)},[]),k.useEffect(()=>{var n;(n=document.documentElement)==null||n.classList.toggle(Gn,e)},[e]),e}const Jn=[{markName:"bold",Icon:h.BoldIcon,title:"Bold (Ctrl+B)"},{markName:"italic",Icon:h.ItalicIcon,title:"Italic (Ctrl+I)"},{markName:"underline",Icon:h.UnderlineIcon,title:"Underline (Ctrl+U)"},{markName:"strike",Icon:h.StrikethroughIcon,title:"Strikethrough"}],Xn=[{label:"Default",value:null},{label:"Red",value:"#e03131"},{label:"Orange",value:"#e8590c"},{label:"Green",value:"#2f9e44"},{label:"Blue",value:"#1971c2"},{label:"Purple",value:"#9c36b5"}],Qn=[{label:"None",value:null},{label:"Yellow",value:"#fff3bf"},{label:"Green",value:"#d3f9d8"},{label:"Blue",value:"#d0ebff"},{label:"Pink",value:"#ffdeeb"},{label:"Gray",value:"#e9ecef"}];function jt({isOpen:e,rect:t,kind:n,selection:o,crossSelection:s,marks:r,store:a,onComment:l,commentAuthorId:u,voice:c}){var U,J;const i=_e(),[f,g]=k.useState(null),[m,p]=k.useState(null),b=k.useRef(null),{applyPatch:y,toggleBoolean:v,setSubSuper:C,isLinkModalOpen:S,openLinkModal:x,closeLinkModal:B,handleSaveLink:T,handleRemoveLink:j}=Pe(a,n,o,s,r),M=k.useRef(null);M.current=m;function E(){var w,D,_,G;(D=(w=document.activeElement)==null?void 0:w.blur)==null||D.call(w),(G=(_=window.getSelection)==null?void 0:_.call(window))==null||G.removeAllRanges()}function L(){if(!o)return;const w=h.genId(),D=Y.addCommentMarkOverRange(a,o,w);D&&a.applyOperation(D),p({commentId:w}),g("comment")}function R(){const w=M.current;if(w){for(const D of Y.removeCommentMarkEverywhere(a,w.commentId))a.applyOperation(D);p(null),E()}}function A(w){!m||!o||(a.applyOperation(h.addCommentThread({id:m.commentId,blockId:o.blockId,anchorRunIds:[o.startRunId,o.endRunId],resolved:!1,messages:[{id:h.genId(),authorId:u,text:w,createdAt:Date.now()}]})),p(null),g(null),E())}function P(){R(),g(null)}k.useEffect(()=>{if(!e||n!=="same-block"||!(l||u))return;const w=D=>{(D.metaKey||D.ctrlKey)&&D.altKey&&D.code==="KeyM"&&(D.preventDefault(),l?l(o):L())};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[e,n,l,u,o]),k.useEffect(()=>{if(!f)return;const w=_=>{b.current&&!b.current.contains(_.target)&&(R(),g(null))},D=_=>{_.key==="Escape"&&(R(),g(null))};return document.addEventListener("mousedown",w),document.addEventListener("keydown",D),()=>{document.removeEventListener("mousedown",w),document.removeEventListener("keydown",D)}},[f]),k.useEffect(()=>{R(),g(null)},[t,n]);const N=te.useAutoAdjustedCenteredLeft(b,!!(e&&t),t?t.left+t.width/2:null);if(i||(!e||!t)&&!S)return null;const $=!l&&f==="comment";return d.jsxs(d.Fragment,{children:[e&&t&&N!=null&&$&&d.jsxs("div",{ref:b,className:"be-floating-toolbar be-floating-toolbar-comment-standalone",role:"dialog","aria-label":"Add comment",style:{position:"fixed",top:t.top-44,left:N,transform:"translateX(-50%)"},onMouseDown:w=>{w.target.tagName!=="TEXTAREA"&&w.preventDefault()},children:[d.jsx(I.CommentPopoverHeader,{title:"Add comment",onClose:P}),d.jsx(Y.CommentComposer,{authorId:u,autoFocus:!0,onSubmit:A,onCancel:P})]}),e&&t&&N!=null&&!$&&d.jsxs("div",{ref:b,className:"be-floating-toolbar",role:"toolbar","aria-label":"Text formatting",style:{position:"fixed",top:t.top-44,left:N,transform:"translateX(-50%)"},onMouseDown:w=>{w.target.tagName!=="TEXTAREA"&&w.preventDefault()},children:[Jn.map(({markName:w,Icon:D,title:_})=>d.jsx("button",{type:"button",className:`be-floating-toolbar-btn${r[w]?" be-floating-toolbar-btn-active":""}`,title:_,"aria-label":_,"aria-pressed":!!r[w],onClick:()=>v(w),children:d.jsx(D,{})},w)),d.jsx("button",{type:"button",className:`be-floating-toolbar-btn${r.subscript?" be-floating-toolbar-btn-active":""}`,title:"Subscript","aria-pressed":!!r.subscript,onClick:()=>C("subscript"),children:"X₂"}),d.jsx("button",{type:"button",className:`be-floating-toolbar-btn${r.superscript?" be-floating-toolbar-btn-active":""}`,title:"Superscript","aria-pressed":!!r.superscript,onClick:()=>C("superscript"),children:"X²"}),d.jsx("span",{className:"be-floating-toolbar-divider"}),d.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[d.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Text color","aria-haspopup":"true","aria-expanded":f==="color",onClick:()=>g(w=>w==="color"?null:"color"),children:d.jsx("span",{style:{color:r.color||"inherit",fontWeight:700},children:"A"})}),f==="color"&&d.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Text color",children:Xn.map(w=>d.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",title:w.label,onClick:()=>{y({color:w.value}),g(null)},children:d.jsx("span",{style:{color:w.value||"#1a1a1a",fontWeight:700},children:"A"})},w.label))})]}),d.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[d.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Highlight","aria-haspopup":"true","aria-expanded":f==="highlight",onClick:()=>g(w=>w==="highlight"?null:"highlight"),children:d.jsx("span",{style:{backgroundColor:r.highlight||"transparent",padding:"0 2px",borderRadius:2},children:"H"})}),f==="highlight"&&d.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Highlight color",children:Qn.map(w=>d.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",style:{backgroundColor:w.value||"transparent"},title:w.label,onClick:()=>{y({highlight:w.value}),g(null)}},w.label))})]}),d.jsx("span",{className:"be-floating-toolbar-divider"}),d.jsx("button",{type:"button",className:`be-floating-toolbar-btn${r.link?" be-floating-toolbar-btn-active":""}`,title:"Link","aria-label":"Link","aria-pressed":!!r.link,onClick:x,children:d.jsx(h.LinkIcon,{})}),(l||u)&&n==="same-block"&&d.jsxs(d.Fragment,{children:[d.jsx("span",{className:"be-floating-toolbar-divider"}),d.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Comment (Ctrl+Alt+M)","aria-label":"Comment",onClick:()=>l?l(o):L(),children:d.jsx(h.CommentIcon,{})})]}),(c==null?void 0:c.isSupported)&&d.jsxs(d.Fragment,{children:[d.jsx("span",{className:"be-floating-toolbar-divider"}),d.jsx("button",{type:"button",className:`be-floating-toolbar-btn${c.isListening?" be-floating-toolbar-btn-active":""}`,title:c.isListening?"Pause dictation":"Start dictation","aria-label":c.isListening?"Pause dictation":"Start dictation","aria-pressed":c.isListening,onClick:()=>c.isListening?c.stop():c.start(),children:d.jsx(h.MicIcon,{})})]})]}),d.jsx(I.LinkEditModal,{isOpen:S,initialHref:((U=r.link)==null?void 0:U.href)??"",initialTarget:((J=r.link)==null?void 0:J.target)??"_self",hasExistingLink:!!r.link,onSave:T,onRemove:j,onClose:B})]})}function At(e){const t=h.useEditorStore(),[n,o]=k.useState(null);return k.useEffect(()=>{const s=e.current;if(!s)return;const r=()=>{var i,f,g,m,p,b;if((f=(i=document.activeElement)==null?void 0:i.closest)!=null&&f.call(i,".be-floating-toolbar"))return;const a=(g=window.getSelection)==null?void 0:g.call(window);if(!a||a.rangeCount===0||a.isCollapsed){o(null);return}if(!s.contains(a.anchorNode)||!s.contains(a.focusNode)){o(null);return}const l=((p=(m=a.getRangeAt(0)).getBoundingClientRect)==null?void 0:p.call(m))??{top:0,left:0,right:0,bottom:0,width:0,height:0},u=O.resolveMultiRunSelection();if(u){if(((b=t.getBlock(u.blockId))==null?void 0:b.type)==="code"){o(null);return}o({kind:"same-block",rect:l,selection:u,marks:Me(t,u.blockId,u)});return}const c=O.resolveCrossBlockSelection(t);if(c){if(c.blockIds.some(y=>{var v;return((v=t.getBlock(y))==null?void 0:v.type)==="code"})){o(null);return}o({kind:"cross-block",rect:l,crossSelection:c,marks:je(t,c)});return}o(null)};return document.addEventListener("selectionchange",r),window.addEventListener("scroll",r,!0),window.addEventListener("resize",r),()=>{document.removeEventListener("selectionchange",r),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r)}},[e,t]),{isOpen:!!n,rect:(n==null?void 0:n.rect)??null,kind:(n==null?void 0:n.kind)??null,selection:(n==null?void 0:n.selection)??null,crossSelection:(n==null?void 0:n.crossSelection)??null,marks:(n==null?void 0:n.marks)??{},close:()=>o(null)}}function Dt({isOpen:e,close:t,query:n,setQuery:o,caseSensitive:s,setCaseSensitive:r,wholeWord:a,setWholeWord:l,isReplaceOpen:u,setIsReplaceOpen:c,replacement:i,setReplacement:f,matches:g,currentIndex:m,next:p,prev:b,replaceCurrent:y,replaceAll:v,queryInputRef:C}){if(!e)return null;const S=B=>{B.key==="Enter"?(B.preventDefault(),B.shiftKey?b():p()):B.key==="Escape"&&(B.preventDefault(),t())},x=B=>{B.key==="Enter"?(B.preventDefault(),y()):B.key==="Escape"&&(B.preventDefault(),t())};return d.jsxs("div",{className:"be-find-bar",contentEditable:!1,children:[d.jsxs("div",{className:"be-find-bar-row",children:[d.jsx("button",{type:"button",className:`be-find-bar-replace-toggle${u?" be-find-bar-replace-toggle-open":""}`,onClick:()=>c(!u),"aria-expanded":u,"aria-label":"Toggle replace",children:d.jsx(h.ChevronRightIcon,{size:12})}),d.jsx("input",{ref:C,type:"text",className:"be-find-bar-input",placeholder:"Find",value:n,onChange:B=>o(B.target.value),onKeyDown:S,"aria-label":"Find in document"}),d.jsx("span",{className:"be-find-bar-count",children:g.length===0?"0/0":`${m+1}/${g.length}`}),d.jsx("button",{type:"button",className:`be-find-bar-toggle${s?" be-find-bar-toggle-active":""}`,onClick:()=>r(!s),"aria-pressed":s,title:"Match case","aria-label":"Match case",children:"Aa"}),d.jsx("button",{type:"button",className:`be-find-bar-toggle${a?" be-find-bar-toggle-active":""}`,onClick:()=>l(!a),"aria-pressed":a,title:"Whole word","aria-label":"Whole word",children:"[Ab]"}),d.jsx("button",{type:"button",className:"be-find-bar-nav",onClick:b,disabled:g.length===0,"aria-label":"Previous match",children:d.jsx(h.ArrowUpIcon,{size:14})}),d.jsx("button",{type:"button",className:"be-find-bar-nav",onClick:p,disabled:g.length===0,"aria-label":"Next match",children:d.jsx(h.ArrowDownIcon,{size:14})}),d.jsx("button",{type:"button",className:"be-find-bar-close",onClick:t,"aria-label":"Close find bar",children:d.jsx(h.XIcon,{size:14})})]}),u&&d.jsxs("div",{className:"be-find-bar-row be-find-bar-replace-row",children:[d.jsx("input",{type:"text",className:"be-find-bar-input",placeholder:"Replace",value:i,onChange:B=>f(B.target.value),onKeyDown:x,"aria-label":"Replace with"}),d.jsx("button",{type:"button",className:"be-find-bar-replace-btn",onClick:y,disabled:g.length===0,children:"Replace"}),d.jsx("button",{type:"button",className:"be-find-bar-replace-btn",onClick:v,disabled:g.length===0,children:"Replace All"})]})]})}function Ke(e){return e!=null&&/[\w]/.test(e)}function Zn(e,t,n){const o=e[t-1],s=e[t+n];return!Ke(o)&&!Ke(s)}function Ve(e,t,n,o,s,r,a){const l=a??e.getRun(n);if(!l||l.type!=="text"||!l.value)return;const u=s.caseSensitive?l.value:l.value.toLowerCase();let c=0;for(;;){const i=u.indexOf(o,c);if(i===-1)break;(!s.wholeWord||Zn(u,i,o.length))&&r.push({blockId:t,runId:n,offset:i,length:o.length}),c=i+o.length}}function Nt(e,t,n,o,s){var a;const r=e.getBlock(t);if(r){for(const l of((a=r.props)==null?void 0:a.titleRunIds)??[])Ve(e,t,l,n,o,s);for(const l of r.contentIds){const u=e.getRun(l);u?Ve(e,t,l,n,o,s,u):Nt(e,l,n,o,s)}}}function Pt(e,t,{caseSensitive:n=!1,wholeWord:o=!1}={}){const s=[];if(!t)return s;const r=n?t:t.toLowerCase();return Nt(e,e.getRootId(),r,{caseSensitive:n,wholeWord:o},s),s}function _t(e,t,n){const o=e.getRun(t.runId);if(!o)return;const s=o.value??"",r=s.slice(0,t.offset)+n+s.slice(t.offset+t.length);e.applyOperation(h.updateRun(t.runId,{value:r}))}function Ft(e,t,n){const o=new Map;for(const r of t)o.has(r.runId)||o.set(r.runId,[]),o.get(r.runId).push(r);const s=[];for(const[r,a]of o){const l=e.getRun(r);if(!l)continue;let u=l.value??"";const c=[...a].sort((i,f)=>f.offset-i.offset);for(const i of c)u=u.slice(0,i.offset)+n+u.slice(i.offset+i.length);s.push(h.updateRun(r,{value:u}))}if(s.length!==0)if(typeof e.performBatch=="function")e.performBatch(s);else for(const r of s)e.applyOperation(r)}const eo=200;function to(e){const t=document.querySelector(`[data-run-id="${e.runId}"]`),n=t==null?void 0:t.firstChild;if(!n||n.nodeType!==3)return null;const o=Math.min(e.offset,n.length),s=Math.min(e.offset+e.length,n.length);if(o>=s)return null;const r=document.createRange();return r.setStart(n,o),r.setEnd(n,s),r}function Ht(e){const t=h.useEditorStore(),[n,o]=k.useState(!1),[s,r]=k.useState(""),[a,l]=k.useState(!1),[u,c]=k.useState(!1),[i,f]=k.useState(!1),[g,m]=k.useState(""),[p,b]=k.useState([]),[y,v]=k.useState(0),C=k.useRef(null),S=k.useRef(null),x=k.useCallback(()=>{const R=Pt(t,s,{caseSensitive:a,wholeWord:u});b(R),v(A=>R.length===0?0:Math.min(A,R.length-1))},[t,s,a,u]);k.useEffect(()=>{n&&(v(0),x())},[n,s,a,u]),k.useEffect(()=>{if(!n)return;let R=null;const A=t.subscribeAll(()=>{R&&clearTimeout(R),R=setTimeout(x,eo)});return()=>{R&&clearTimeout(R),A()}},[n,t,x]),k.useEffect(()=>{var P;if(!n||typeof Highlight>"u"||!CSS.highlights)return;const R=[];let A=null;if(p.forEach((N,$)=>{const U=to(N);U&&($===y?A=U:R.push(U))}),CSS.highlights.set("be-find-match",new Highlight(...R)),A){CSS.highlights.set("be-find-current",new Highlight(A));const N=document.querySelector(`[data-run-id="${(P=p[y])==null?void 0:P.runId}"]`);N==null||N.scrollIntoView({block:"center",behavior:"smooth"})}else CSS.highlights.delete("be-find-current");return()=>{CSS.highlights.delete("be-find-match"),CSS.highlights.delete("be-find-current")}},[n,p,y]);const B=k.useCallback(()=>{var R;if(n){(R=S.current)==null||R.select();return}C.current=document.activeElement,o(!0)},[n]),T=k.useCallback(()=>{var R,A;o(!1),f(!1),typeof Highlight<"u"&&CSS.highlights&&(CSS.highlights.delete("be-find-match"),CSS.highlights.delete("be-find-current")),(A=(R=C.current)==null?void 0:R.focus)==null||A.call(R),C.current=null},[]);k.useEffect(()=>{var R;n&&((R=S.current)==null||R.focus())},[n]),k.useEffect(()=>{const R=e.current;if(!R)return;const A=P=>{(P.metaKey||P.ctrlKey)&&P.key.toLowerCase()==="f"&&(P.preventDefault(),B())};return R.addEventListener("keydown",A),()=>R.removeEventListener("keydown",A)},[e,B]);const j=k.useCallback(()=>{p.length!==0&&v(R=>(R+1)%p.length)},[p.length]),M=k.useCallback(()=>{p.length!==0&&v(R=>(R-1+p.length)%p.length)},[p.length]),E=k.useCallback(()=>{const R=p[y];R&&_t(t,R,g)},[t,p,y,g]),L=k.useCallback(()=>{p.length!==0&&Ft(t,p,g)},[t,p,g]);return{isOpen:n,open:B,close:T,query:s,setQuery:r,caseSensitive:a,setCaseSensitive:l,wholeWord:u,setWholeWord:c,isReplaceOpen:i,setIsReplaceOpen:f,replacement:g,setReplacement:m,matches:p,currentIndex:y,next:j,prev:M,replaceCurrent:E,replaceAll:L,queryInputRef:S}}function no({store:e,rootId:t,extensions:n,onComment:o,commentAuthorId:s,voice:r}){const a=k.useRef(null),{onCopy:l,onCut:u,onPaste:c}=Ct(),i=Ot(a),f=Lt(a),g=Mt(a),m=At(a),p=Ht(a);return Ln(n,a),Rt(a),Tt(a),d.jsxs("div",{ref:a,role:"document","aria-label":"Document editor",onCopy:l,onCut:u,onPaste:c,children:[d.jsx(Dt,{...p}),d.jsx(kt,{}),d.jsx(I.BlockChildren,{parentId:t,isTopLevel:!0}),d.jsx(pt,{}),d.jsx(fe,{isOpen:i.isOpen,rect:i.rect,commands:i.commands,runId:i.runId,onSelect:i.selectCommand,onClose:i.close}),d.jsx(fe,{isOpen:f.isOpen,rect:f.rect,commands:f.commands,runId:f.runId,onSelect:f.selectCommand,onClose:f.close,menuId:"be-emoji-menu",ariaLabel:"Emoji"}),d.jsx(fe,{isOpen:g.isOpen,rect:g.rect,commands:g.commands,runId:g.runId,onSelect:g.selectCommand,onClose:g.close,menuId:"be-at-menu",ariaLabel:"Mention"}),d.jsx(jt,{isOpen:m.isOpen,rect:m.rect,kind:m.kind,selection:m.selection,crossSelection:m.crossSelection,marks:m.marks,store:e,onComment:o,commentAuthorId:s,voice:r})]})}function oo({editor:e,className:t,style:n,theme:o,getBlockClassName:s,onComment:r,commentAuthorId:a,showCommentsPanel:l,uploadFile:u,maxFileSize:c,resolveEmbedSrc:i,onEmbedError:f,highlightCode:g,voice:m,children:p}){const{store:b,registry:y,inlineRegistry:v,extensions:C}=e,S=b.getRootId();return d.jsxs(h.EditorProvider,{store:b,registry:y,inlineRegistry:v,history:b,className:t,style:n,theme:o,getBlockClassName:s,commentAuthorId:a,uploadFile:u,maxFileSize:c,resolveEmbedSrc:i,onEmbedError:f,highlightCode:g,children:[d.jsx(no,{store:b,rootId:S,extensions:C,onComment:r,commentAuthorId:a,voice:m}),l&&d.jsx(we.CommentsPanel,{authorId:a}),p]})}const so={canUndo:!1,canRedo:!1};function $t(){const{history:e}=h.useEditorContext(),t=k.useCallback(s=>e?e.subscribeToHistory(s):()=>{},[e]),n=k.useCallback(()=>e?e.getUndoRedoSnapshot():so,[e]),o=k.useSyncExternalStore(t,n);return e?{...o,undo:()=>{const s=e.undo();return s&&X.restoreSelectionAfterHistoryChange(e),s},redo:()=>{const s=e.redo();return s&&X.restoreSelectionAfterHistoryChange(e),s},getHistoryLog:()=>e.getHistoryLog()}:null}function ro(e){const[t,n]=k.useState(()=>(e==null?void 0:e.getPresence())??new Map);return k.useEffect(()=>{if(!e){n(new Map);return}return n(e.getPresence()),e.onPresenceChange(n)},[e]),t}const Ut={'"':{open:"“",close:"”"},"'":{open:"‘",close:"’"}};function lo(e,t){const n=Ut[e];return t===void 0||/[\s([{“‘]/.test(t)?n.open:n.close}function ao(e,{enabled:t=!0}={}){const n=h.useEditorStore();k.useEffect(()=>{if(!t)return;const o=e.current;if(!o)return;function s(a){var l;return((l=n.getBlock(a))==null?void 0:l.type)==="code"}function r(a){if(a.inputType!=="insertText"||!a.data||a.data.length!==1)return;const l=a.data,u=Ut[l];if(!u)return;const c=O.resolveRunSelection();if(c){if(s(c.blockId))return;const b=n.getRun(c.runId);if(!b||b.type!=="text")return;a.preventDefault();const y=b.value??"",v=y.slice(0,c.startOffset)+u.open+y.slice(c.startOffset,c.endOffset)+u.close+y.slice(c.endOffset);Z.flushSync(()=>n.applyOperation(h.updateRun(b.id,{value:v}))),O.setCaretSync(b.id,c.endOffset+2);return}const i=O.resolveCollapsedCaret();if(!i||s(i.blockId))return;const f=n.getRun(i.runId);if(!f||f.type!=="text")return;a.preventDefault();const g=f.value??"",m=lo(l,g[i.offset-1]),p=g.slice(0,i.offset)+m+g.slice(i.offset);Z.flushSync(()=>n.applyOperation(h.updateRun(f.id,{value:p}))),O.setCaretSync(f.id,i.offset+1)}return o.addEventListener("beforeinput",r),()=>o.removeEventListener("beforeinput",r)},[e,n,t])}const Kt={"(":")","[":"]","{":"}"},co=new Set(Object.values(Kt));function io(e,{enabled:t=!0}={}){const n=h.useEditorStore();k.useEffect(()=>{if(!t)return;const o=e.current;if(!o)return;function s(a){var l;return((l=n.getBlock(a))==null?void 0:l.type)==="code"}function r(a){if(a.inputType!=="insertText"||!a.data||a.data.length!==1)return;const l=a.data,u=Kt[l];if(u){const c=O.resolveRunSelection();if(c){if(s(c.blockId))return;const p=n.getRun(c.runId);if(!p||p.type!=="text")return;a.preventDefault();const b=p.value??"",y=b.slice(0,c.startOffset)+l+b.slice(c.startOffset,c.endOffset)+u+b.slice(c.endOffset);Z.flushSync(()=>n.applyOperation(h.updateRun(p.id,{value:y}))),O.setCaretSync(p.id,c.endOffset+2);return}const i=O.resolveCollapsedCaret();if(!i||s(i.blockId))return;const f=n.getRun(i.runId);if(!f||f.type!=="text")return;a.preventDefault();const g=f.value??"",m=g.slice(0,i.offset)+l+u+g.slice(i.offset);Z.flushSync(()=>n.applyOperation(h.updateRun(f.id,{value:m}))),O.setCaretSync(f.id,i.offset+1);return}if(co.has(l)){const c=O.resolveCollapsedCaret();if(!c||s(c.blockId))return;const i=n.getRun(c.runId);if(!i||i.type!=="text")return;(i.value??"")[c.offset]===l&&(a.preventDefault(),O.setCaretSync(i.id,c.offset+1))}}return o.addEventListener("beforeinput",r),()=>o.removeEventListener("beforeinput",r)},[e,n,t])}function Vt({isOpen:e,onClose:t,onSelectCommand:n}){const o=h.useBlockRegistry(),s=h.useInlineRegistry(),r=k.useMemo(()=>[...(o==null?void 0:o.listSlashCommands())??[],...(s==null?void 0:s.listSlashCommands())??[]],[o,s]);return d.jsx(te.Modal,{isOpen:e,onClose:t,title:"Add a block",variant:"sheet",children:d.jsx("div",{className:"be-mobile-picker-list",role:"listbox","aria-label":"Insertable blocks",children:r.map(a=>{const l=a.icon;return d.jsxs("button",{type:"button",role:"option",className:"be-mobile-picker-item",onClick:()=>n(a),children:[l&&d.jsx("span",{className:"be-mobile-picker-item-icon",children:d.jsx(l,{size:18})}),d.jsx("span",{className:"be-mobile-picker-item-label",children:a.label})]},a.label)})})})}function zt({isOpen:e,onClose:t,store:n,blockId:o}){var l;const s=o?n.getBlock(o):null,r=!!((l=s==null?void 0:s.props)!=null&&l.hidden),a=k.useCallback(u=>{u(),t()},[t]);return d.jsx(te.Modal,{isOpen:e,onClose:t,title:"Block options",variant:"sheet",children:d.jsxs("div",{className:"be-mobile-picker-list",role:"menu","aria-label":"Block options",children:[d.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{I.duplicateBlock(n,o),I.announce("Block duplicated")}),children:[d.jsx("span",{className:"be-mobile-picker-item-icon",children:d.jsx(h.CopyIcon,{size:18})}),d.jsx("span",{className:"be-mobile-picker-item-label",children:"Duplicate"})]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{I.moveBlockUp(n,o)&&I.announce("Block moved up")}),children:[d.jsx("span",{className:"be-mobile-picker-item-icon",children:d.jsx(h.ArrowUpIcon,{size:18})}),d.jsx("span",{className:"be-mobile-picker-item-label",children:"Move up"})]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{I.moveBlockDown(n,o)&&I.announce("Block moved down")}),children:[d.jsx("span",{className:"be-mobile-picker-item-icon",children:d.jsx(h.ArrowDownIcon,{size:18})}),d.jsx("span",{className:"be-mobile-picker-item-label",children:"Move down"})]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{n.applyOperation(h.updateBlockProps(o,{hidden:!r})),I.announce(r?"Block shown in preview":"Block hidden in preview")}),children:[d.jsx("span",{className:"be-mobile-picker-item-icon",children:r?d.jsx(h.EyeIcon,{size:18}):d.jsx(h.EyeOffIcon,{size:18})}),d.jsx("span",{className:"be-mobile-picker-item-label",children:r?"Show in preview":"Hide in preview"})]}),d.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item be-mobile-picker-item-danger",onClick:()=>a(()=>{I.deleteBlockAndFocusSibling(n,o),I.announce("Block deleted")}),children:[d.jsx("span",{className:"be-mobile-picker-item-icon",children:d.jsx(h.TrashIcon,{size:18})}),d.jsx("span",{className:"be-mobile-picker-item-label",children:"Delete"})]})]})})}const uo=I.LANGUAGES.map(e=>({value:e,label:e}));function fo(e,t){const[n,o]=k.useState(!1),[s,r]=k.useState(null),[a,l]=k.useState(null),[u,c]=k.useState(null);return k.useEffect(()=>{const i=e.current;if(!i)return;const f=()=>o(!0),g=m=>{i.contains(m.relatedTarget)||o(!1)};return i.addEventListener("focusin",f),i.addEventListener("focusout",g),()=>{i.removeEventListener("focusin",f),i.removeEventListener("focusout",g)}},[e]),k.useEffect(()=>{if(!n){r(null);return}const i=()=>{var p;const f=e.current,g=(p=window.getSelection)==null?void 0:p.call(window);if(!f||!g||g.rangeCount===0){r(null);return}if(!g.isCollapsed){if(!f.contains(g.anchorNode)||!f.contains(g.focusNode)){r(null);return}const b=O.resolveMultiRunSelection();if(b){l({kind:"same-block",selection:b,crossSelection:null,marks:Me(t,b.blockId,b)}),r("selection");return}const y=O.resolveCrossBlockSelection(t);if(y){l({kind:"cross-block",selection:null,crossSelection:y,marks:je(t,y)}),r("selection");return}r(null);return}const m=O.resolveCollapsedCaret();if(!m||!f.contains(g.anchorNode)){r(null);return}c(m),r("caret")};return i(),document.addEventListener("selectionchange",i),()=>document.removeEventListener("selectionchange",i)},[n,t,e]),{isFocused:n,mode:s,selectionState:a,caretState:u}}function po({store:e,selectionState:t}){const{kind:n,selection:o,crossSelection:s,marks:r}=t,{toggleBoolean:a,openLinkModal:l}=Pe(e,n,o,s,r);return d.jsxs(d.Fragment,{children:[d.jsx("button",{type:"button",className:`be-mobile-bar-btn${r.bold?" be-mobile-bar-btn-active":""}`,"aria-label":"Bold",onClick:()=>a("bold"),children:d.jsx(h.BoldIcon,{size:18})}),d.jsx("button",{type:"button",className:`be-mobile-bar-btn${r.italic?" be-mobile-bar-btn-active":""}`,"aria-label":"Italic",onClick:()=>a("italic"),children:d.jsx(h.ItalicIcon,{size:18})}),d.jsx("button",{type:"button",className:`be-mobile-bar-btn${r.underline?" be-mobile-bar-btn-active":""}`,"aria-label":"Underline",onClick:()=>a("underline"),children:d.jsx(h.UnderlineIcon,{size:18})}),d.jsx("button",{type:"button",className:`be-mobile-bar-btn${r.link?" be-mobile-bar-btn-active":""}`,"aria-label":"Link",onClick:l,children:d.jsx(h.LinkIcon,{size:18})})]})}function mo({store:e,blockId:t}){const n=k.useCallback(()=>{const s=e.getBlock(t),r=s&&e.getBlock(s.parentId);r&&I.insertRowAfter(e,r.id)},[e,t]),o=k.useCallback(()=>{const s=e.getBlock(t),r=s&&e.getBlock(s.parentId),a=r&&e.getBlock(r.parentId);if(!a||!r)return;const l=r.contentIds.indexOf(t);l!==-1&&I.insertColumnAfter(e,a.id,l)},[e,t]);return d.jsxs(d.Fragment,{children:[d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert row below",onClick:n,children:"+ Row"}),d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert column right",onClick:o,children:"+ Column"})]})}function ho({store:e,blockId:t}){var s;const n=e.getBlock(t),o=k.useCallback(r=>e.applyOperation(h.updateBlockProps(t,{language:r})),[e,t]);return d.jsx(I.Select,{className:"be-mobile-bar-select",value:((s=n==null?void 0:n.props)==null?void 0:s.language)??"plaintext",options:uo,onChange:o,ariaLabel:"Code language"})}function bo({store:e,blockId:t}){var s;const n=e.getBlock(t),o=(s=n==null?void 0:n.props)==null?void 0:s.color;return d.jsx("div",{className:"be-mobile-bar-swatches",children:I.CALLOUT_COLORS.map(r=>d.jsx("button",{type:"button",className:`be-callout-color-option be-callout-color-option-${r.value}${r.value===o?" be-callout-color-option-active":""}`,"aria-label":r.label,title:r.label,onClick:()=>e.applyOperation(h.updateBlockProps(t,{color:r.value}))},r.value))})}const qt={tableCell:mo,code:ho,callout:bo};function go(e,t){let n=e.getBlock(t);for(;n;){if(qt[n.type])return n;n=n.parentId?e.getBlock(n.parentId):null}return null}function ko(e,t){const n=e.getRootId();let o=e.getBlock(t);for(;o&&o.parentId!==n;)o=e.getBlock(o.parentId);return o}function yo({containerRef:e}){var j,M;const t=h.useEditorStore(),n=$t(),o=_e(),s=I.useVirtualKeyboardInset(),{isFocused:r,mode:a,selectionState:l,caretState:u}=fo(e,t),[c,i]=k.useState(!1),[f,g]=k.useState(!1),m=k.useCallback(()=>i(!0),[]),p=k.useCallback(()=>i(!1),[]),b=k.useCallback(()=>g(!0),[]),y=k.useCallback(()=>g(!1),[]),v=k.useCallback(E=>{const L=O.resolveCollapsedCaret()??u;L&&(E.run(t,{blockId:L.blockId,runId:L.runId,sliceStart:L.offset,sliceEnd:L.offset}),p())},[t,u,p]),C=k.useCallback(()=>{var E,L;(L=(E=document.activeElement)==null?void 0:E.blur)==null||L.call(E)},[]);if(!o||!r)return null;const S=a==="caret"&&u?go(t,u.blockId):null,x=S?qt[S.type]:null,B=a==="caret"&&u?u.blockId:((j=l==null?void 0:l.selection)==null?void 0:j.blockId)??((M=l==null?void 0:l.crossSelection)==null?void 0:M.startBlockId)??null,T=B?ko(t,B):null;return d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"be-mobile-action-bar",role:"toolbar","aria-label":"Editor actions",style:{bottom:s},onMouseDown:E=>E.preventDefault(),children:[a==="selection"&&l&&d.jsx(po,{store:t,selectionState:l}),a!=="selection"&&d.jsxs(d.Fragment,{children:[d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Add block",onClick:m,children:d.jsx(h.PlusIcon,{size:18})}),x&&S&&d.jsx(x,{store:t,blockId:S.id}),n&&d.jsxs(d.Fragment,{children:[d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Undo",disabled:!n.canUndo,onClick:n.undo,children:"↶"}),d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Redo",disabled:!n.canRedo,onClick:n.redo,children:"↷"})]})]}),d.jsx("span",{className:"be-mobile-bar-spacer"}),T&&d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Block options",onClick:b,children:d.jsx(h.MoreHorizontalIcon,{size:18})}),d.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Dismiss keyboard",onClick:C,children:d.jsx(h.ChevronDownIcon,{size:18})})]}),d.jsx(Vt,{isOpen:c,onClose:p,onSelectCommand:v}),d.jsx(zt,{isOpen:f,onClose:y,store:t,blockId:T==null?void 0:T.id})]})}const Io=[{value:"json",label:"JSON"},{value:"simpleJson",label:"Simple JSON"},{value:"html",label:"HTML"},{value:"markdown",label:"Markdown"},{value:"text",label:"Text"}];function Co({label:e="View source",className:t=""}){const n=h.useEditorStore(),o=h.useBlockRegistry(),s=h.useInlineRegistry(),[r,a]=k.useState(!1),[l,u]=k.useState("json"),[c,i]=k.useState(!1),f=k.useCallback(()=>{i(!1),a(!0)},[]),g=k.useCallback(()=>a(!1),[]),m=k.useMemo(()=>r?l==="json"?F.exportDocumentJSON(n):l==="simpleJson"?Re(n,o,s):l==="html"?F.exportDocumentHTML(n,o,s):l==="markdown"?F.exportDocumentMarkdown(n,o,s):F.exportDocumentText(n,o,s):"",[r,l,n,o,s]),p=k.useCallback(async()=>{try{await navigator.clipboard.writeText(m),i(!0),setTimeout(()=>i(!1),1500)}catch{}},[m]),b=k.useCallback(()=>{const v=F.exportDocumentWordHTML(n,o,s),C=document.createElement("a");C.href=`data:application/msword;charset=utf-8,${encodeURIComponent(v)}`,C.download="document.doc",document.body.appendChild(C),C.click(),document.body.removeChild(C)},[n,o,s]),y=k.useCallback(()=>{window.print()},[]);return d.jsxs(d.Fragment,{children:[d.jsxs("button",{type:"button",className:`be-export-trigger ${t}`.trim(),onClick:f,children:[d.jsx(h.CodeIcon,{size:14})," ",e]}),d.jsxs(te.Modal,{isOpen:r,onClose:g,title:"Document source",size:"large",children:[d.jsx("div",{className:"be-export-tabs",role:"tablist",children:Io.map(v=>d.jsx("button",{type:"button",role:"tab","aria-selected":l===v.value,className:`be-export-tab${l===v.value?" be-export-tab-active":""}`,onClick:()=>u(v.value),children:v.label},v.value))}),d.jsx("pre",{className:"be-export-pre",children:d.jsx("code",{children:m})}),d.jsxs("div",{className:"be-modal-actions",children:[d.jsx("button",{type:"button",className:"be-modal-cancel",onClick:g,children:"Close"}),d.jsx("button",{type:"button",className:"be-export-download",onClick:y,children:"Print / Save as PDF"}),d.jsx("button",{type:"button",className:"be-export-download",onClick:b,children:"Download Word (.doc)"}),d.jsx("button",{type:"button",className:"be-modal-save",onClick:p,children:c?"Copied!":"Copy"})]})]})]})}function vo({id:e,blockId:t,label:n,placeholder:o,variant:s,options:r,onManage:a,mention:l=!1}){const u=h.useEditorStore(),c=K.useRun(e),i=k.useRef(null);i.current===null&&(i.current=I.consumePendingAutoOpen(e));const f=k.useCallback((b,y)=>{u.applyOperation(h.updateRun(e,{data:{selectedValue:b,selectedLabel:(y==null?void 0:y.label)??"",selectedColor:y==null?void 0:y.color}})),i.current&&I.focusAfterChip(u,t,e)},[u,e,t]);if(!c)return null;const{selectedValue:g="",selectedLabel:m="",selectedColor:p}=c.data??{};return d.jsx("span",{className:"be-inline-select",onMouseDown:b=>{b.preventDefault(),b.stopPropagation()},onKeyDown:b=>b.stopPropagation(),children:d.jsx(I.Select,{value:g,selectedLabel:m,selectedColor:p,options:r,onChange:f,placeholder:o,variant:s,ariaLabel:n,onManageOptions:a,mention:l,autoOpen:i.current})})}function Wt(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function ze(e){return Wt(e).replace(/"/g,"&quot;")}function Gt({type:e,label:t,placeholder:n="Select…",variant:o="default",icon:s,options:r,onManage:a,triggers:l=["slash"],mention:u=l.includes("at")}){function c(p){var v,C;const b=((v=p.data)==null?void 0:v.selectedLabel)||"",y=u&&b?`@${b}`:b;return`<span data-inline-type="${ze(e)}" data-selected-value="${ze(((C=p.data)==null?void 0:C.selectedValue)??"")}">${Wt(y)}</span>`}function i(p){var y;const b=((y=p.data)==null?void 0:y.selectedLabel)??"";return u&&b?`@${b}`:b}function f(p){var v;if(((v=p.getAttribute)==null?void 0:v.call(p,"data-inline-type"))!==e)return null;const b=p.textContent??"",y=u&&b.startsWith("@")?b.slice(1):b;return{id:h.genId(),type:e,value:"",marks:{},data:{selectedValue:p.getAttribute("data-selected-value")??"",selectedLabel:y}}}function g({id:p,blockId:b}){return d.jsx(vo,{id:p,blockId:b,label:t,placeholder:n,variant:o,options:r,onManage:a,mention:u})}const m={label:t,icon:s??h.SelectIcon,keywords:[t.toLowerCase(),"select","field"],run:(p,{blockId:b,runId:y,sliceStart:v,sliceEnd:C})=>I.insertInlineRunAtCursor(p,{blockId:b,runId:y,sliceStart:v,sliceEnd:C},()=>({id:h.genId(),type:e,value:"",marks:{},data:{selectedValue:"",selectedLabel:"",selectedColor:void 0}}),{autoOpen:!0})};return{component:g,isAtomic:!0,toHTML:c,toPlainText:i,fromHTML:f,slashCommand:l.includes("slash")?m:void 0,atCommand:l.includes("at")?m:void 0}}function Yt(e,t,{onManage:n}={}){for(const o of e.getFieldTypes())t.register(o.id,Gt({type:o.id,label:o.label,placeholder:o.placeholder,variant:o.variant,options:o.options??[],triggers:o.mentionable?["slash","at"]:["slash"],onManage:n?()=>n(o.id):void 0}))}function Jt(){const e=h.useEditorStore(),t=h.useInlineRegistry(),n=I.useFieldTypes(),{openEdit:o}=h.useFieldTypeEditor(),s=k.useRef([]);k.useEffect(()=>{if(!t)return;const r=new Set(n.map(a=>a.id));for(const a of s.current)r.has(a)||t.unregister(a);Yt(e,t,{onManage:o}),s.current=[...r]},[e,t,n,o])}function Bo(){Jt();const e=h.useEditorStore(),{target:t,close:n}=h.useFieldTypeEditor(),o=t!==null,s=o&&t!=="new",[r,a]=k.useState(""),[l,u]=k.useState([]),[c,i]=k.useState(""),[f,g]=k.useState(!1);k.useEffect(()=>{if(o){if(s){const C=e.getFieldType(t);a((C==null?void 0:C.label)??""),u((C==null?void 0:C.options)??[]),g(!!(C!=null&&C.mentionable))}else a(""),u([]),g(!1);i("")}},[o,s,t,e]);const m=k.useCallback((C,S)=>{u(x=>x.map(B=>B.value===C?{...B,label:S}:B))},[]),p=k.useCallback(C=>{u(S=>S.filter(x=>x.value!==C))},[]),b=k.useCallback(()=>{const C=c.trim();i(""),C&&u(S=>[...S,{value:h.genId(),label:C,color:I.pickTagColor(S.length)}])},[c]),y=k.useCallback(()=>{const C=r.trim();C&&(s?e.applyOperation(h.updateFieldType(t,{label:C,options:l,mentionable:f})):e.applyOperation(h.addFieldType({id:h.genId(),label:C,placeholder:"Select…",variant:"tag",options:l,mentionable:f})),n())},[e,s,t,r,l,f,n]),v=k.useCallback(()=>{s&&e.applyOperation(h.removeFieldType(t)),n()},[e,s,t,n]);return d.jsxs(te.Modal,{isOpen:o,onClose:n,title:s?"Edit field type":"New field type",children:[d.jsxs("label",{className:"be-modal-field",children:[d.jsx("span",{children:"Name"}),d.jsx("input",{type:"text",value:r,onChange:C=>a(C.target.value),placeholder:"e.g. Priority, Status…",autoFocus:!0})]}),d.jsxs("div",{className:"be-modal-field",children:[d.jsx("span",{children:"Options"}),l.map((C,S)=>d.jsxs("div",{className:"be-table-header-menu-option-row",children:[d.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(C.color??I.pickTagColor(S)).bg},"aria-hidden":"true"}),d.jsx("input",{className:"be-table-header-menu-option-input",value:C.label,onChange:x=>m(C.value,x.target.value),"aria-label":`Rename option ${C.label}`}),d.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>p(C.value),"aria-label":`Remove option ${C.label}`,children:d.jsx(h.XIcon,{size:14})})]},C.value)),d.jsxs("div",{className:"be-table-header-menu-option-row",children:[d.jsx("input",{className:"be-table-header-menu-option-input",value:c,onChange:C=>i(C.target.value),placeholder:"New option…",onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),b())}}),d.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:b,"aria-label":"Add option",children:"+"})]})]}),d.jsxs("label",{className:"be-modal-field be-modal-field-checkbox",children:[d.jsx("input",{type:"checkbox",checked:f,onChange:C=>g(C.target.checked)}),d.jsx("span",{children:"Also show in @ mentions"})]}),d.jsxs("div",{className:"be-modal-actions",children:[s&&d.jsx("button",{type:"button",className:"be-modal-delete",onClick:v,children:"Delete field type"}),d.jsx("button",{type:"button",className:"be-modal-cancel",onClick:n,children:"Cancel"}),d.jsx("button",{type:"button",className:"be-modal-save",onClick:y,children:"Save"})]})]})}exports.EditorStore=F.EditorStore;exports.VersionHistory=F.VersionHistory;exports.applyDocumentTemplate=F.applyDocumentTemplate;exports.captureBlockTemplate=F.captureBlockTemplate;exports.createAutoVersionHistory=F.createAutoVersionHistory;exports.diffDocumentsHTML=F.diffDocumentsHTML;exports.exportDocumentHTML=F.exportDocumentHTML;exports.exportDocumentJSON=F.exportDocumentJSON;exports.exportDocumentMarkdown=F.exportDocumentMarkdown;exports.exportDocumentText=F.exportDocumentText;exports.exportDocumentWordHTML=F.exportDocumentWordHTML;exports.insertBlockTemplate=F.insertBlockTemplate;exports.registerBlockTemplates=F.registerBlockTemplates;exports.useDocumentVersions=F.useDocumentVersions;exports.EditorProvider=h.EditorProvider;exports.injectDefaultStyles=h.injectDefaultStyles;exports.operations=h.operations;exports.useBlockClassName=h.useBlockClassName;exports.useBlockRangeSelection=h.useBlockRangeSelection;exports.useBlockRegistry=h.useBlockRegistry;exports.useCommentAuthorId=h.useCommentAuthorId;exports.useEditorStore=h.useEditorStore;exports.useFieldTypeEditor=h.useFieldTypeEditor;exports.useFileUpload=h.useFileUpload;exports.useInlineRegistry=h.useInlineRegistry;exports.usePreviewMode=h.usePreviewMode;exports.useSelectedBlock=h.useSelectedBlock;exports.useShowLineNumbers=h.useShowLineNumbers;exports.useWholeDocumentSelection=h.useWholeDocumentSelection;exports.FieldClockRegistry=be.FieldClockRegistry;exports.HLC=be.HLC;exports.ListCrdtState=be.ListCrdtState;exports.genPeerId=be.genPeerId;exports.CollabSession=ee.CollabSession;exports.MESSAGE_TYPE=ee.MESSAGE_TYPE;exports.PeerConnection=ee.PeerConnection;exports.createPeriodicTombstoneGC=ee.createPeriodicTombstoneGC;exports.createWebSocketSignaling=ee.createWebSocketSignaling;exports.decodeMessage=ee.decodeMessage;exports.encodeMessage=ee.encodeMessage;exports.deleteDocumentVersion=q.deleteDocumentVersion;exports.deletePersistedDocument=q.deletePersistedDocument;exports.deleteTemplate=q.deleteTemplate;exports.listDocumentVersions=q.listDocumentVersions;exports.listPersistedDocumentIds=q.listPersistedDocumentIds;exports.listTemplates=q.listTemplates;exports.loadDocumentVersion=q.loadDocumentVersion;exports.loadPersistedDocument=q.loadPersistedDocument;exports.loadTemplate=q.loadTemplate;exports.saveDocumentVersion=q.saveDocumentVersion;exports.savePersistedDocument=q.savePersistedDocument;exports.saveTemplate=q.saveTemplate;exports.createAutoPersistence=Se.createAutoPersistence;exports.usePersistedDocument=Se.usePersistedDocument;exports.useServiceWorkerUpdate=Se.useServiceWorkerUpdate;exports.CommentComposer=Y.CommentComposer;exports.CommentThreadCard=Y.CommentThreadCard;exports.addComment=Y.addComment;exports.addCommentMarkOverRange=Y.addCommentMarkOverRange;exports.deleteComment=Y.deleteComment;exports.removeCommentMarkEverywhere=Y.removeCommentMarkEverywhere;exports.replyToComment=Y.replyToComment;exports.resolveComment=Y.resolveComment;exports.CommentsPanel=we.CommentsPanel;exports.useComments=we.useComments;exports.CommentAvatar=Qt.CommentAvatar;exports.canvasBlockType=K.canvasBlockType;exports.defineBlock=K.defineBlock;exports.defineExtension=K.defineExtension;exports.defineInline=K.defineInline;exports.registerExtensions=K.registerExtensions;exports.useBlock=K.useBlock;exports.useRun=K.useRun;exports.AGGREGATE_LABELS=I.AGGREGATE_LABELS;exports.AGGREGATE_TYPES=I.AGGREGATE_TYPES;exports.BlockChildren=I.BlockChildren;exports.BlockErrorBoundary=I.BlockErrorBoundary;exports.BlockGutterRow=I.BlockGutterRow;exports.BlockRenderer=I.BlockRenderer;exports.COLUMN_TYPES=I.COLUMN_TYPES;exports.DEFAULT_COLUMN_TYPE=I.DEFAULT_COLUMN_TYPE;exports.DEFAULT_COLUMN_WIDTH=I.DEFAULT_COLUMN_WIDTH;exports.EditableBlockContent=I.EditableBlockContent;exports.MIN_COLUMN_WIDTH=I.MIN_COLUMN_WIDTH;exports.Select=I.Select;exports.TableHeaderRow=I.TableHeaderRow;exports.blankRunForType=I.blankRunForType;exports.blockquoteBlockType=I.blockquoteBlockType;exports.buttonBlockType=I.buttonBlockType;exports.calloutBlockType=I.calloutBlockType;exports.checkboxInlineType=I.checkboxInlineType;exports.codeBlockType=I.codeBlockType;exports.computeColumnAggregate=I.computeColumnAggregate;exports.convertRunToType=I.convertRunToType;exports.createCellForColumn=I.createCellForColumn;exports.createDefaultColumns=I.createDefaultColumns;exports.dateInlineType=I.dateInlineType;exports.deleteBlockAndFocusSibling=I.deleteBlockAndFocusSibling;exports.deleteColumn=I.deleteColumn;exports.deleteRow=I.deleteRow;exports.dividerBlockType=I.dividerBlockType;exports.duplicateBlock=I.duplicateBlock;exports.embedBlockType=I.embedBlockType;exports.emojiInlineType=I.emojiInlineType;exports.ensureRootNonEmpty=I.ensureRootNonEmpty;exports.formatAggregateValue=I.formatAggregateValue;exports.headingBlockType=I.headingBlockType;exports.insertColumnAfter=I.insertColumnAfter;exports.insertRowAfter=I.insertRowAfter;exports.layoutBlockType=I.layoutBlockType;exports.layoutColumnBlockType=I.layoutColumnBlockType;exports.listItemBlockType=I.listItemBlockType;exports.moveBlockDown=I.moveBlockDown;exports.moveBlockUp=I.moveBlockUp;exports.paragraphBlockType=I.paragraphBlockType;exports.renameColumn=I.renameColumn;exports.resolveColumns=I.resolveColumns;exports.selectInlineType=I.selectInlineType;exports.setColumnAggregate=I.setColumnAggregate;exports.setColumnOptions=I.setColumnOptions;exports.setColumnType=I.setColumnType;exports.setColumnWidth=I.setColumnWidth;exports.sortTableByColumn=I.sortTableByColumn;exports.starterKit=I.starterKit;exports.tableBlockType=I.tableBlockType;exports.tableCellBlockType=I.tableCellBlockType;exports.tableRowBlockType=I.tableRowBlockType;exports.tableSelectInlineType=I.tableSelectInlineType;exports.toggleHeadingBlockType=I.toggleHeadingBlockType;exports.useBlockChildren=I.useBlockChildren;exports.useFieldTypes=I.useFieldTypes;exports.useVirtualKeyboardInset=I.useVirtualKeyboardInset;exports.focusRunAtOffset=O.focusRunAtOffset;exports.focusRunEnd=O.focusRunEnd;exports.focusRunStart=O.focusRunStart;exports.resolveCollapsedCaret=O.resolveCollapsedCaret;exports.resolveCrossBlockSelection=O.resolveCrossBlockSelection;exports.resolveMultiRunSelection=O.resolveMultiRunSelection;exports.resolveRunSelection=O.resolveRunSelection;exports.captureSubtree=le.captureSubtree;exports.remapSubtreeIds=le.remapSubtreeIds;exports.serializeBlockRange=le.serializeBlockRange;exports.VoiceListeningIndicator=X.VoiceListeningIndicator;exports.VoicePermissionModal=X.VoicePermissionModal;exports.listVoiceCommands=X.listVoiceCommands;exports.useCaretRect=X.useCaretRect;exports.useVoiceTyping=X.useVoiceTyping;exports.Modal=te.Modal;exports.APP_MIME=pe;exports.BlockRangeActionMenu=kt;exports.BlockRegistry=Ge;exports.DocumentExportButton=Co;exports.EditorTrailingSpace=pt;exports.FieldTypeEditorModal=Bo;exports.FindBar=Dt;exports.FloatingToolbar=jt;exports.History=We;exports.InlineRegistry=Je;exports.LAYOUT_BLOCKS=tt;exports.MobileActionBar=yo;exports.MobileBlockOptionsSheet=zt;exports.MobileBlockPickerSheet=Vt;exports.NoteloomEditor=oo;exports.SlashMenu=fe;exports.TABLE_BLOCKS=et;exports.TABLE_SELECT_INLINE_TYPES=st;exports.TemplatePicker=nn;exports.addPerson=on;exports.autoPairBrackets=hn;exports.copyBlockRangeToClipboard=ve;exports.createBlockRegistry=Ye;exports.createInlineRegistry=Xe;exports.createSelectFieldType=Gt;exports.deleteBlockRange=ie;exports.deleteEntireDocument=me;exports.deleteOverBlockRange=Le;exports.deleteRunRangeInBlock=Oe;exports.deserializeClipboard=It;exports.exportDocumentSimpleJSON=Re;exports.findMatches=Pt;exports.getMarksSummaryOverBlockRange=je;exports.getMarksSummaryOverSelection=Me;exports.importDocumentSimpleJSON=ft;exports.isEntireBlockRangeHidden=bt;exports.isEntireBlockSelected=wt;exports.isSimpleDocument=dt;exports.moveBlockRangeDown=ht;exports.moveBlockRangeUp=mt;exports.registerBlocks=Ze;exports.registerBuiltInBlocks=Qe;exports.registerBuiltInInlineTypes=nt;exports.registerInlineTypes=ot;exports.registerStoredFieldTypes=Yt;exports.removePerson=rn;exports.reorderBlockRangeFromStore=In;exports.replaceAllMatches=Ft;exports.replaceMatch=_t;exports.setBlockRangeHidden=gt;exports.setMarksOverBlockRange=he;exports.setMarksOverSelection=re;exports.setTitle=cn;exports.smartQuotes=pn;exports.textToParagraphs=Ee;exports.toggleMarkOnRunRange=Tn;exports.toggleMarkOverBlockRange=De;exports.toggleMarkOverSelection=Ae;exports.updatePerson=sn;exports.useAtMenuTrigger=Mt;exports.useAutoPairBrackets=io;exports.useBlockRangeDrag=Tt;exports.useClipboardHandlers=Ct;exports.useCoarsePointer=_e;exports.useEditor=kn;exports.useEditorKeyboardShortcuts=Rt;exports.useEmojiMenuTrigger=Lt;exports.useFindInDocument=Ht;exports.useFloatingToolbarTrigger=At;exports.useHistory=$t;exports.usePeople=an;exports.usePresence=ro;exports.useRegisterFieldTypes=Jt;exports.useSlashMenuTrigger=Ot;exports.useSmartQuotes=ao;exports.useTemplates=tn;exports.useTextFormattingActions=Pe;exports.useTitle=dn;exports.useTouchOnlyDevice=Et;exports.walkDomToBlocks=yt;
2
3
  //# sourceMappingURL=index.cjs.map