noteloom 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +639 -438
- package/dist/index.d.ts +620 -0
- package/dist/noteloom.cjs +24 -12
- package/dist/noteloom.cjs.map +1 -1
- package/dist/noteloom.es.js +6995 -5937
- package/dist/noteloom.es.js.map +1 -1
- package/dist/style.css +16 -4
- package/package.json +26 -6
package/dist/noteloom.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var Ni=Object.defineProperty;var Oi=(e,n,t)=>n in e?Ni(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var Wo=(e,n,t)=>Oi(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),d=require("react"),Ve=require("react-dom"),ae={INSERT_BLOCK:"insertBlock",REMOVE_BLOCK:"removeBlock",MOVE_BLOCK:"moveBlock",UPDATE_BLOCK_PROPS:"updateBlockProps",UPDATE_RUN:"updateRun",SET_BLOCK_CONTENT_IDS:"setBlockContentIds",REPLACE_RUN_SPAN:"replaceRunSpan",SET_BLOCK_RUNS:"setBlockRuns",ADD_FIELD_TYPE:"addFieldType",UPDATE_FIELD_TYPE:"updateFieldType",REMOVE_FIELD_TYPE:"removeFieldType"};function he(e,n,t,r){return{type:ae.INSERT_BLOCK,block:e,parentId:n,index:t,subtree:r}}function Z(e){return{type:ae.REMOVE_BLOCK,id:e}}function Xe(e,n,t){return{type:ae.MOVE_BLOCK,id:e,toParentId:n,toIndex:t}}function X(e,n){return{type:ae.UPDATE_BLOCK_PROPS,id:e,patch:n}}function ce(e,n){return{type:ae.UPDATE_RUN,id:e,patch:n}}function An(e,n){return{type:ae.SET_BLOCK_CONTENT_IDS,blockId:e,contentIds:n}}function ct(e,n,t){return{type:ae.REPLACE_RUN_SPAN,blockId:e,oldRunIds:n,newRuns:t}}function Oe(e,n){return{type:ae.SET_BLOCK_RUNS,blockId:e,runs:n}}function $r(e){return{type:ae.ADD_FIELD_TYPE,fieldType:e}}function _r(e,n){return{type:ae.UPDATE_FIELD_TYPE,id:e,patch:n}}function zr(e){return{type:ae.REMOVE_FIELD_TYPE,id:e}}const Li=Object.freeze(Object.defineProperty({__proto__:null,OP:ae,addFieldType:$r,insertBlock:he,moveBlock:Xe,removeBlock:Z,removeFieldType:zr,replaceRunSpan:ct,setBlockContentIds:An,setBlockRuns:Oe,updateBlockProps:X,updateFieldType:_r,updateRun:ce},Symbol.toStringTag,{value:"Module"})),gr="$fieldTypes";class Hr{constructor(n){this.blocks=new Map(((n==null?void 0:n.blocks)??[]).map(t=>[t.id,t])),this.runs=new Map(((n==null?void 0:n.runs)??[]).map(t=>[t.id,t])),this.rootId=(n==null?void 0:n.rootId)??null,this.fieldTypes=new Map(((n==null?void 0:n.fieldTypes)??[]).map(t=>[t.id,t])),this._fieldTypesSnapshot=null,this._listeners=new Map}getBlock(n){return this.blocks.get(n)}getRun(n){return this.runs.get(n)}getFieldTypes(){return this._fieldTypesSnapshot||(this._fieldTypesSnapshot=[...this.fieldTypes.values()]),this._fieldTypesSnapshot}getFieldType(n){return this.fieldTypes.get(n)}getRootId(){return this.rootId}subscribe(n,t){let r=this._listeners.get(n);return r||(r=new Set,this._listeners.set(n,r)),r.add(t),()=>{r.delete(t),r.size===0&&this._listeners.delete(n)}}_notify(n){for(const t of n){const r=this._listeners.get(t);if(r)for(const o of[...r])o()}}_captureSubtree(n){const t=[],r=[],o=s=>{var i;if(this.runs.has(s)){r.push(this.runs.get(s));return}const l=this.blocks.get(s);if(l){t.push(l);for(const c of l.contentIds)o(c);for(const c of((i=l.props)==null?void 0:i.titleRunIds)??[])o(c)}};return o(n),{blocks:t,runs:r}}_deleteSubtree(n){const t=r=>{var s;if(this.runs.has(r)){this.runs.delete(r);return}const o=this.blocks.get(r);if(o){for(const l of o.contentIds)t(l);for(const l of((s=o.props)==null?void 0:s.titleRunIds)??[])t(l);this.blocks.delete(r)}};t(n)}applyOperation(n){var t;switch(n.type){case ae.UPDATE_RUN:{const r=this.runs.get(n.id),o={};for(const s of Object.keys(n.patch))o[s]=r[s];return this.runs.set(n.id,{...r,...n.patch}),this._notify([n.id]),ce(n.id,o)}case ae.UPDATE_BLOCK_PROPS:{const r=this.blocks.get(n.id),o={};for(const s of Object.keys(n.patch))o[s]=r.props[s];return this.blocks.set(n.id,{...r,props:{...r.props,...n.patch}}),this._notify([n.id]),X(n.id,o)}case ae.INSERT_BLOCK:{if(n.subtree){for(const l of n.subtree.blocks)this.blocks.set(l.id,l);for(const l of n.subtree.runs)this.runs.set(l.id,l)}else this.blocks.set(n.block.id,n.block);const r=this.blocks.get(n.parentId),o=[...r.contentIds],s=n.index??o.length;return o.splice(s,0,n.block.id),this.blocks.set(n.parentId,{...r,contentIds:o}),this._notify([n.block.id,n.parentId]),Z(n.block.id)}case ae.REMOVE_BLOCK:{const r=this.blocks.get(n.id),o=r.parentId,s=this.blocks.get(o),l=s.contentIds.indexOf(n.id),i=this._captureSubtree(n.id);this._deleteSubtree(n.id);const c=s.contentIds.filter(u=>u!==n.id);return this.blocks.set(o,{...s,contentIds:c}),this._notify([o]),{type:ae.INSERT_BLOCK,block:r,parentId:o,index:l,subtree:i}}case ae.MOVE_BLOCK:{const o=this.blocks.get(n.id).parentId,s=this.blocks.get(o),l=s.contentIds.indexOf(n.id),i=s.contentIds.filter(p=>p!==n.id);this.blocks.set(o,{...s,contentIds:i});const c=n.toParentId===o?this.blocks.get(o):this.blocks.get(n.toParentId),u=[...c.contentIds];u.splice(n.toIndex??u.length,0,n.id),this.blocks.set(n.toParentId,{...c,contentIds:u}),this.blocks.set(n.id,{...this.blocks.get(n.id),parentId:n.toParentId});const f=new Set([n.id,o,n.toParentId]);return this._notify(f),Xe(n.id,o,l)}case ae.SET_BLOCK_CONTENT_IDS:{const r=this.blocks.get(n.blockId),o=r.contentIds;return this.blocks.set(n.blockId,{...r,contentIds:n.contentIds}),this._notify([n.blockId]),An(n.blockId,o)}case ae.REPLACE_RUN_SPAN:{const r=this.blocks.get(n.blockId),o=r.contentIds.indexOf(n.oldRunIds[0])!==-1,s=o?r.contentIds:((t=r.props)==null?void 0:t.titleRunIds)??[],l=s.indexOf(n.oldRunIds[0]),i=n.oldRunIds.map(u=>this.runs.get(u));for(const u of n.oldRunIds)this.runs.delete(u);for(const u of n.newRuns)this.runs.set(u.id,u);const c=[...s];return c.splice(l,n.oldRunIds.length,...n.newRuns.map(u=>u.id)),o?this.blocks.set(n.blockId,{...r,contentIds:c}):this.blocks.set(n.blockId,{...r,props:{...r.props,titleRunIds:c}}),this._notify([n.blockId,...n.oldRunIds,...n.newRuns.map(u=>u.id)]),ct(n.blockId,n.newRuns.map(u=>u.id),i)}case ae.SET_BLOCK_RUNS:{const r=this.blocks.get(n.blockId),o=r.props&&"titleRunIds"in r.props,s=o?r.props.titleRunIds:r.contentIds,l=s.map(c=>this.runs.get(c)).filter(Boolean);for(const c of s)this.runs.delete(c);for(const c of n.runs)this.runs.set(c.id,c);const i=n.runs.map(c=>c.id);return o?this.blocks.set(n.blockId,{...r,props:{...r.props,titleRunIds:i}}):this.blocks.set(n.blockId,{...r,contentIds:i}),this._notify([n.blockId,...s,...i]),Oe(n.blockId,l)}case ae.ADD_FIELD_TYPE:return this.fieldTypes.set(n.fieldType.id,n.fieldType),this._fieldTypesSnapshot=null,this._notify([gr]),zr(n.fieldType.id);case ae.UPDATE_FIELD_TYPE:{const r=this.fieldTypes.get(n.id),o={};for(const s of Object.keys(n.patch))o[s]=r[s];return this.fieldTypes.set(n.id,{...r,...n.patch}),this._fieldTypesSnapshot=null,this._notify([gr]),_r(n.id,o)}case ae.REMOVE_FIELD_TYPE:{const r=this.fieldTypes.get(n.id);return this.fieldTypes.delete(n.id),this._fieldTypesSnapshot=null,this._notify([gr]),$r(r)}default:throw new Error(`Unknown operation type: ${n.type}`)}}applyOperations(n){return n.map(t=>this.applyOperation(t))}toJSON(){return{blocks:[...this.blocks.values()],runs:[...this.runs.values()],rootId:this.rootId,fieldTypes:[...this.fieldTypes.values()]}}static fromJSON(n){return new Hr(n)}}const Mi=500;function Ai(e,n){const t=e??"",r=n??"";let o=0;const s=Math.min(t.length,r.length);for(;o<s&&t[o]===r[o];)o+=1;let l=t.length,i=r.length;for(;l>o&&i>o&&t[l-1]===r[i-1];)l-=1,i-=1;return{beforeOffset:l,afterOffset:i}}function Go(e){var l,i;if(!e.ops.length||!e.inverses.length)return null;const n=e.ops[0],t=e.ops[e.ops.length-1];if(n.type!=="updateRun"||t.type!=="updateRun"||n.id!==t.id||typeof((l=t.patch)==null?void 0:l.value)!="string")return null;const r=e.inverses[e.inverses.length-1];if((r==null?void 0:r.type)!=="updateRun"||typeof((i=r.patch)==null?void 0:i.value)!="string")return null;const{beforeOffset:o,afterOffset:s}=Ai(r.patch.value,t.patch.value);return{runId:n.id,beforeOffset:o,afterOffset:s}}function Zo(e){const n=[],t=r=>{var o;r&&((o=r.block)!=null&&o.id&&n.push(r.block.id),r.blockId&&n.push(r.blockId),r.id&&n.push(r.id),r.parentId&&n.push(r.parentId),r.toParentId&&n.push(r.toParentId))};for(const r of e.ops)t(r);for(const r of e.inverses)t(r);return[...new Set(n)]}class Di{constructor(n,{idleMs:t=Mi,trackChanges:r=!1,maxChangeLogSize:o=500}={}){this.store=n,this.idleMs=t,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=r,this.maxChangeLogSize=o,this.changeLog=[]}_recordChange(n,t,r){var s;if(!this.trackChanges)return;const o=n.patch!==void 0&&(t==null?void 0:t.patch)!==void 0;this.changeLog.push({opType:n.type,id:n.id??n.blockId??((s=n.block)==null?void 0:s.id),before:o?t.patch:void 0,after:o?n.patch:void 0,actorId:r.actorId??null,timestamp:r.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 n=this.canUndo(),t=this.canRedo();return(this._undoRedoSnapshot.canUndo!==n||this._undoRedoSnapshot.canRedo!==t)&&(this._undoRedoSnapshot={canUndo:n,canRedo:t}),this._undoRedoSnapshot}getBlock(n){return this.store.getBlock(n)}getRun(n){return this.store.getRun(n)}getRootId(){return this.store.getRootId()}getFieldTypes(){return this.store.getFieldTypes()}getFieldType(n){return this.store.getFieldType(n)}subscribe(n,t){return this.store.subscribe(n,t)}toJSON(){return this.store.toJSON()}applyOperation(n,t={}){return this.perform(n,t)}applyOperations(n,t={}){return n.map(r=>this.perform(r,t))}performBatch(n,t={}){var l;const r=t.actorId??null,o=t.timestamp??Date.now();this._commitCurrentBatch();const s=[];for(const i of n){const c=this.store.applyOperation(i);s.unshift(c),this.historyLog.push({opType:i.type,id:i.id??i.blockId??((l=i.block)==null?void 0:l.id),actorId:r,timestamp:o}),this._recordChange(i,c,{actorId:r,timestamp:o})}this.redoStack=[],this.undoStack.push({ops:[...n],inverses:s,batchKey:null,actorId:r,timestamp:o,lastTimestamp:o,boundaryHit:!0}),this._notify()}perform(n,t={}){const r=t.actorId??null,o=t.timestamp??Date.now(),s=this.store.applyOperation(n);return this._record(n,s,{actorId:r,timestamp:o}),s}_batchKeyFor(n){return n.type==="updateRun"?`run:${n.id}`:null}_isWordBoundary(n){var r;if(n.type!=="updateRun")return!1;const t=(r=n.patch)==null?void 0:r.value;return typeof t!="string"||t.length===0?!1:/\s/.test(t[t.length-1])}_record(n,t,r){var i;this.redoStack=[];const o=this._batchKeyFor(n),s=this.currentBatch&&r.timestamp-this.currentBatch.lastTimestamp<=this.idleMs;this.currentBatch&&o!==null&&this.currentBatch.batchKey===o&&s&&!this.currentBatch.boundaryHit?(this.currentBatch.ops.push(n),this.currentBatch.inverses.unshift(t),this.currentBatch.lastTimestamp=r.timestamp,this._isWordBoundary(n)&&(this.currentBatch.boundaryHit=!0)):(this._commitCurrentBatch(),this.currentBatch={ops:[n],inverses:[t],batchKey:o,actorId:r.actorId,timestamp:r.timestamp,lastTimestamp:r.timestamp,boundaryHit:this._isWordBoundary(n)}),this._resetIdleTimer(),this.historyLog.push({opType:n.type,id:n.id??((i=n.block)==null?void 0:i.id),actorId:r.actorId,timestamp:r.timestamp}),this._recordChange(n,t,r),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 n=this.undoStack.pop();if(!n)return!1;for(const r of n.inverses)this.store.applyOperation(r);this.redoStack.push(n);const t=Go(n);return this._pendingSelection=t?{runId:t.runId,offset:t.beforeOffset}:null,this._pendingAffectedBlockIds=Zo(n),this._notify(),!0}redo(){const n=this.redoStack.pop();if(!n)return!1;for(const r of n.ops)this.store.applyOperation(r);this.undoStack.push(n);const t=Go(n);return this._pendingSelection=t?{runId:t.runId,offset:t.afterOffset}:null,this._pendingAffectedBlockIds=Zo(n),this._notify(),!0}canUndo(){return this.undoStack.length>0||this.currentBatch!==null}canRedo(){return this.redoStack.length>0}getHistoryLog(){return[...this.historyLog]}subscribeToHistory(n){return this._listeners.add(n),()=>this._listeners.delete(n)}_notify(){for(const n of this._listeners)n()}}class Ns{constructor(){this._types=new Map}register(n,t){this._types.set(n,t)}get(n){return this._types.get(n)}isLeaf(n){var t;return!!((t=this._types.get(n))!=null&&t.isLeaf)}listSlashCommands(){const n=[];for(const t of this._types.values())t.slashCommand&&n.push(t.slashCommand),t.slashCommands&&n.push(...t.slashCommands);return n}listHtmlMatchers(){return[...this._types.values()].filter(n=>n.fromHTML)}}function Pi(){return new Ns}class Os{constructor(){this._types=new Map}register(n,t){this._types.set(n,t)}unregister(n){this._types.delete(n)}get(n){return this._types.get(n)}listHtmlMatchers(){return[...this._types.values()].filter(n=>n.fromHTML)}listSlashCommands(){const n=[];for(const t of this._types.values())t.slashCommand&&n.push(t.slashCommand),t.slashCommands&&n.push(...t.slashCommands);return n}listAtCommands(){const n=[];for(const t of this._types.values())t.atCommand&&n.push(t.atCommand),t.atCommands&&n.push(...t.atCommands);return n}}function $i(){return new Os}const _i=`/*\r
|
|
2
|
-
* noteloom's default theme — minimal, clean,
|
|
1
|
+
"use strict";var gc=Object.defineProperty;var xc=(e,t,n)=>t in e?gc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var ds=(e,t,n)=>xc(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),p=require("react"),Xe=require("react-dom"),oe={INSERT_BLOCK:"insertBlock",REMOVE_BLOCK:"removeBlock",MOVE_BLOCK:"moveBlock",CHANGE_BLOCK_TYPE:"changeBlockType",UPDATE_BLOCK_PROPS:"updateBlockProps",UPDATE_RUN:"updateRun",SET_BLOCK_CONTENT_IDS:"setBlockContentIds",REPLACE_RUN_SPAN:"replaceRunSpan",SET_BLOCK_RUNS:"setBlockRuns",ADD_FIELD_TYPE:"addFieldType",UPDATE_FIELD_TYPE:"updateFieldType",REMOVE_FIELD_TYPE:"removeFieldType"};function ge(e,t,n,r){return{type:oe.INSERT_BLOCK,block:e,parentId:t,index:n,subtree:r}}function J(e){return{type:oe.REMOVE_BLOCK,id:e}}function st(e,t,n){return{type:oe.MOVE_BLOCK,id:e,toParentId:t,toIndex:n}}function X(e,t){return{type:oe.UPDATE_BLOCK_PROPS,id:e,patch:t}}function Qr(e,t,n){return{type:oe.CHANGE_BLOCK_TYPE,id:e,blockType:t,props:n}}function ue(e,t){return{type:oe.UPDATE_RUN,id:e,patch:t}}function qt(e,t){return{type:oe.SET_BLOCK_CONTENT_IDS,blockId:e,contentIds:t}}function In(e,t,n){return{type:oe.REPLACE_RUN_SPAN,blockId:e,oldRunIds:t,newRuns:n}}function _e(e,t){return{type:oe.SET_BLOCK_RUNS,blockId:e,runs:t}}function eo(e){return{type:oe.ADD_FIELD_TYPE,fieldType:e}}function to(e,t){return{type:oe.UPDATE_FIELD_TYPE,id:e,patch:t}}function no(e){return{type:oe.REMOVE_FIELD_TYPE,id:e}}const kc=Object.freeze(Object.defineProperty({__proto__:null,OP:oe,addFieldType:eo,changeBlockType:Qr,insertBlock:ge,moveBlock:st,removeBlock:J,removeFieldType:no,replaceRunSpan:In,setBlockContentIds:qt,setBlockRuns:_e,updateBlockProps:X,updateFieldType:to,updateRun:ue},Symbol.toStringTag,{value:"Module"}));class xn{constructor(t){this.peerId=t,this.wallTime=0,this.counter=0}tick(){const t=Date.now();return t>this.wallTime?(this.wallTime=t,this.counter=0):this.counter+=1,{wallTime:this.wallTime,counter:this.counter,peerId:this.peerId}}receive(t){const n=Date.now(),r=Math.max(n,this.wallTime,t.wallTime);return r===this.wallTime&&r===t.wallTime?this.counter=Math.max(this.counter,t.counter)+1:r===this.wallTime?this.counter+=1:r===t.wallTime?this.counter=t.counter+1:this.counter=0,this.wallTime=r,{wallTime:this.wallTime,counter:this.counter,peerId:this.peerId}}static compare(t,n){return t.wallTime!==n.wallTime?t.wallTime-n.wallTime:t.counter!==n.counter?t.counter-n.counter:t.peerId===n.peerId?0:t.peerId<n.peerId?-1:1}}function qs(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`peer-${Date.now()}-${Math.random().toString(36).slice(2)}`}class kn{constructor(){this.slots=new Map}static fromArray(t,{peerId:n="legacy"}={}){const r=new kn;let o=null;for(const s of t)r.slots.set(s,{id:s,originId:o,peerId:n,clock:{wallTime:0,counter:0,peerId:n},deleted:!1}),o=s;return r}has(t){return this.slots.has(t)}getSlot(t){return this.slots.get(t)}isDeleted(t){const n=this.slots.get(t);return!n||n.deleted}insert(t,n,r,o){this.slots.has(t)||this.slots.set(t,{id:t,originId:n,peerId:o,clock:r,deleted:!1})}delete(t,n){const r=this.slots.get(t);r&&(r.deleted=!0,n&&(r.deletedClock=n))}restore(t){const n=this.slots.get(t);n&&(n.deleted=!1)}move(t,n,r,o){if(n===t)return;const s=this.slots.get(t);if(!s)return;const l=s.originId;for(const i of this.slots.values())i.originId===t&&(i.originId=l);s.originId=n,s.peerId=o,s.clock=r,s.deleted=!1}merge(t){for(const n of t){const r=this.slots.get(n.id);r?n.deleted&&!r.deleted&&(r.deleted=!0):this.slots.set(n.id,{...n})}}toSlotArray(){return Array.from(this.slots.values())}tombstoneCount(){let t=0;for(const n of this.slots.values())n.deleted&&(t+=1);return t}pruneTombstones(t){let n=0;for(const[r,o]of this.slots){if(!o.deleted)continue;const s=o.deletedClock??o.clock;if(!(xn.compare(s,t)>=0)){for(const l of this.slots.values())l.originId===r&&(l.originId=o.originId);this.slots.delete(r),n+=1}}return n}toArray(){const t=new Map;for(const o of this.slots.values()){const s=t.get(o.originId);s?s.push(o):t.set(o.originId,[o])}for(const o of t.values())o.sort((s,l)=>xn.compare(l.clock,s.clock));const n=[],r=[...t.get(null)??[]].reverse();for(;r.length>0;){const o=r.pop();o.deleted||n.push(o.id);const s=t.get(o.id);if(s)for(let l=s.length-1;l>=0;l-=1)r.push(s[l])}return n}}class Wt{constructor(){this.clocks=new Map}static compositeKey(t,n){return`${t}:${n}`}get(t,n){return this.clocks.get(Wt.compositeKey(t,n))??null}recordLocal(t,n,r){this.clocks.set(Wt.compositeKey(t,n),r)}shouldApplyRemote(t,n,r){const o=this.get(t,n);return o?xn.compare(r,o)>0:!0}recordRemote(t,n,r){this.clocks.set(Wt.compositeKey(t,n),r)}}const Lr="$fieldTypes";class tr{constructor(t){this.blocks=new Map(((t==null?void 0:t.blocks)??[]).map(n=>[n.id,n])),this.runs=new Map(((t==null?void 0:t.runs)??[]).map(n=>[n.id,n])),this.rootId=(t==null?void 0:t.rootId)??null,this.fieldTypes=new Map(((t==null?void 0:t.fieldTypes)??[]).map(n=>[n.id,n])),this._fieldTypesSnapshot=null,this._listeners=new Map,this._globalListeners=new Set,this._peerId=qs(),this._clock=new xn(this._peerId),this._fieldClocks=new Wt,this._orders=new Map}_getOrder(t){let n=this._orders.get(t);if(!n){const r=this.blocks.get(t);n=kn.fromArray((r==null?void 0:r.contentIds)??[],{peerId:"legacy"}),this._orders.set(t,n)}return n}getBlock(t){return this.blocks.get(t)}getRun(t){return this.runs.get(t)}getFieldTypes(){return this._fieldTypesSnapshot||(this._fieldTypesSnapshot=[...this.fieldTypes.values()]),this._fieldTypesSnapshot}getFieldType(t){return this.fieldTypes.get(t)}getRootId(){return this.rootId}subscribe(t,n){let r=this._listeners.get(t);return r||(r=new Set,this._listeners.set(t,r)),r.add(n),()=>{r.delete(n),r.size===0&&this._listeners.delete(t)}}subscribeAll(t){return this._globalListeners.add(t),()=>this._globalListeners.delete(t)}_notify(t){for(const n of t){const r=this._listeners.get(n);if(r)for(const o of[...r])o()}if(this._globalListeners.size>0)for(const n of[...this._globalListeners])n()}_captureSubtree(t){const n=[],r=[],o=s=>{var i;if(this.runs.has(s)){r.push(this.runs.get(s));return}const l=this.blocks.get(s);if(l){n.push(l);for(const c of l.contentIds)o(c);for(const c of((i=l.props)==null?void 0:i.titleRunIds)??[])o(c)}};return o(t),{blocks:n,runs:r}}_deleteSubtree(t){const n=r=>{var s;if(this.runs.has(r)){this.runs.delete(r);return}const o=this.blocks.get(r);if(o){for(const l of o.contentIds)n(l);for(const l of((s=o.props)==null?void 0:s.titleRunIds)??[])n(l);this.blocks.delete(r)}};n(t)}applyOperation(t){var n;switch(t.type){case oe.UPDATE_RUN:{const r=this.runs.get(t.id),o={},s={};for(const l of Object.keys(t.patch))o[l]=r[l],s[l]=this._clock.tick(),this._fieldClocks.recordLocal(t.id,l,s[l]);return this.runs.set(t.id,{...r,...t.patch}),this._lastEnvelope={kind:"fieldWrite",target:"run",id:t.id,patch:t.patch,clocks:s},this._notify([t.id]),ue(t.id,o)}case oe.UPDATE_BLOCK_PROPS:{const r=this.blocks.get(t.id),o={},s={};for(const l of Object.keys(t.patch))o[l]=r.props[l],s[l]=this._clock.tick(),this._fieldClocks.recordLocal(t.id,`props.${l}`,s[l]);return this.blocks.set(t.id,{...r,props:{...r.props,...t.patch}}),this._lastEnvelope={kind:"fieldWrite",target:"blockProps",id:t.id,patch:t.patch,clocks:s},this._notify([t.id]),X(t.id,o)}case oe.CHANGE_BLOCK_TYPE:{const r=this.blocks.get(t.id),o=r.type,s=r.props,l=this._clock.tick();return this._fieldClocks.recordLocal(t.id,"type",l),this.blocks.set(t.id,{...r,type:t.blockType,props:t.props}),this._lastEnvelope={kind:"fieldWrite",target:"blockType",id:t.id,blockType:t.blockType,props:t.props,clock:l},this._notify([t.id]),Qr(t.id,o,s)}case oe.INSERT_BLOCK:{if(t.subtree){for(const s of t.subtree.blocks)this.blocks.set(s.id,s);for(const s of t.subtree.runs)this.runs.set(s.id,s)}else this.blocks.set(t.block.id,t.block);const r=this.blocks.get(t.parentId),o=this._getOrder(t.parentId);if(o.has(t.block.id))o.restore(t.block.id);else{const s=o.toArray(),l=t.index??s.length,i=l>0?s[l-1]:null;o.insert(t.block.id,i,this._clock.tick(),this._peerId)}return this.blocks.set(t.parentId,{...r,contentIds:o.toArray()}),this._lastEnvelope={kind:"insertSlot",parentId:t.parentId,blockId:t.block.id,slot:o.getSlot(t.block.id),subtree:t.subtree??{blocks:[t.block],runs:[]}},this._notify([t.block.id,t.parentId]),J(t.block.id)}case oe.REMOVE_BLOCK:{const r=this.blocks.get(t.id),o=r.parentId,s=this.blocks.get(o),l=this._getOrder(o),i=l.toArray().indexOf(t.id),c=this._captureSubtree(t.id);this._deleteSubtree(t.id);const u=this._clock.tick();return l.delete(t.id,u),this.blocks.set(o,{...s,contentIds:l.toArray()}),this._lastEnvelope={kind:"deleteSlot",parentId:o,blockId:t.id,clock:u},this._notify([o]),{type:oe.INSERT_BLOCK,block:r,parentId:o,index:i,subtree:c}}case oe.MOVE_BLOCK:{const o=this.blocks.get(t.id).parentId,s=this._getOrder(o),l=s.toArray().indexOf(t.id);s.delete(t.id,this._clock.tick()),this.blocks.set(o,{...this.blocks.get(o),contentIds:s.toArray()});const i=this._getOrder(t.toParentId),c=i.toArray(),u=t.toIndex??c.length,f=u>0?c[u-1]:null,d=this._clock.tick();i.has(t.id)?i.move(t.id,f,d,this._peerId):i.insert(t.id,f,d,this._peerId),this.blocks.set(t.toParentId,{...this.blocks.get(t.toParentId),contentIds:i.toArray()}),this.blocks.set(t.id,{...this.blocks.get(t.id),parentId:t.toParentId}),this._lastEnvelope={kind:"moveSlot",fromParentId:o,toParentId:t.toParentId,blockId:t.id,slot:i.getSlot(t.id)};const h=new Set([t.id,o,t.toParentId]);return this._notify(h),st(t.id,o,l)}case oe.SET_BLOCK_CONTENT_IDS:{const r=this.blocks.get(t.blockId),o=r.contentIds;return this.blocks.set(t.blockId,{...r,contentIds:t.contentIds}),this._orders.set(t.blockId,kn.fromArray(t.contentIds,{peerId:"legacy"})),this._lastEnvelope=null,this._notify([t.blockId]),qt(t.blockId,o)}case oe.REPLACE_RUN_SPAN:{const r=this.blocks.get(t.blockId),o=r.contentIds.indexOf(t.oldRunIds[0])!==-1,s=o?r.contentIds:((n=r.props)==null?void 0:n.titleRunIds)??[],l=s.indexOf(t.oldRunIds[0]),i=t.oldRunIds.map(u=>this.runs.get(u));for(const u of t.oldRunIds)this.runs.delete(u);for(const u of t.newRuns)this.runs.set(u.id,u);const c=[...s];return c.splice(l,t.oldRunIds.length,...t.newRuns.map(u=>u.id)),o?this.blocks.set(t.blockId,{...r,contentIds:c}):this.blocks.set(t.blockId,{...r,props:{...r.props,titleRunIds:c}}),this._lastEnvelope=null,this._notify([t.blockId,...t.oldRunIds,...t.newRuns.map(u=>u.id)]),In(t.blockId,t.newRuns.map(u=>u.id),i)}case oe.SET_BLOCK_RUNS:{const r=this.blocks.get(t.blockId),o=r.props&&"titleRunIds"in r.props,s=o?r.props.titleRunIds:r.contentIds,l=s.map(c=>this.runs.get(c)).filter(Boolean);for(const c of s)this.runs.delete(c);for(const c of t.runs)this.runs.set(c.id,c);const i=t.runs.map(c=>c.id);return o?this.blocks.set(t.blockId,{...r,props:{...r.props,titleRunIds:i}}):this.blocks.set(t.blockId,{...r,contentIds:i}),this._lastEnvelope=null,this._notify([t.blockId,...s,...i]),_e(t.blockId,l)}case oe.ADD_FIELD_TYPE:return this.fieldTypes.set(t.fieldType.id,t.fieldType),this._fieldTypesSnapshot=null,this._notify([Lr]),no(t.fieldType.id);case oe.UPDATE_FIELD_TYPE:{const r=this.fieldTypes.get(t.id),o={};for(const s of Object.keys(t.patch))o[s]=r[s];return this.fieldTypes.set(t.id,{...r,...t.patch}),this._fieldTypesSnapshot=null,this._notify([Lr]),to(t.id,o)}case oe.REMOVE_FIELD_TYPE:{const r=this.fieldTypes.get(t.id);return this.fieldTypes.delete(t.id),this._fieldTypesSnapshot=null,this._notify([Lr]),eo(r)}default:throw new Error(`Unknown operation type: ${t.type}`)}}applyOperations(t){return t.map(n=>this.applyOperation(n))}getLastEnvelope(){return this._lastEnvelope}applyRemoteOperation(t){var n;if(t)switch(t.kind){case"insertSlot":{for(const s of t.subtree.blocks)this.blocks.has(s.id)||this.blocks.set(s.id,s);for(const s of t.subtree.runs)this.runs.has(s.id)||this.runs.set(s.id,s);const r=this._getOrder(t.parentId);r.merge([t.slot]);const o=this.blocks.get(t.parentId);this.blocks.set(t.parentId,{...o,contentIds:r.toArray()}),this._clock.receive(t.slot.clock),this._notify([t.blockId,t.parentId]);return}case"deleteSlot":{const r=this._getOrder(t.parentId);this.blocks.has(t.blockId)&&this._deleteSubtree(t.blockId),r.delete(t.blockId,t.clock),t.clock&&this._clock.receive(t.clock);const o=this.blocks.get(t.parentId);this.blocks.set(t.parentId,{...o,contentIds:r.toArray()}),this._notify([t.parentId]);return}case"moveSlot":{const r=this._getOrder(t.fromParentId);r.delete(t.blockId,(n=t.slot)==null?void 0:n.clock),this.blocks.set(t.fromParentId,{...this.blocks.get(t.fromParentId),contentIds:r.toArray()});const o=this._getOrder(t.toParentId),s=o.has(t.blockId);o.merge([t.slot]),s&&o.move(t.blockId,t.slot.originId,t.slot.clock,t.slot.peerId),this.blocks.set(t.toParentId,{...this.blocks.get(t.toParentId),contentIds:o.toArray()}),this.blocks.has(t.blockId)&&this.blocks.set(t.blockId,{...this.blocks.get(t.blockId),parentId:t.toParentId}),this._clock.receive(t.slot.clock),this._notify([t.blockId,t.fromParentId,t.toParentId]);return}case"fieldWrite":{if(t.target==="run"){const r=this.runs.get(t.id);if(r){const o={};for(const s of Object.keys(t.patch)){const l=t.clocks[s];this._fieldClocks.shouldApplyRemote(t.id,s,l)&&(o[s]=t.patch[s],this._fieldClocks.recordRemote(t.id,s,l))}Object.keys(o).length>0&&(this.runs.set(t.id,{...r,...o}),this._notify([t.id]))}}else if(t.target==="blockProps"){const r=this.blocks.get(t.id);if(r){const o={};for(const s of Object.keys(t.patch)){const l=t.clocks[s];this._fieldClocks.shouldApplyRemote(t.id,`props.${s}`,l)&&(o[s]=t.patch[s],this._fieldClocks.recordRemote(t.id,`props.${s}`,l))}Object.keys(o).length>0&&(this.blocks.set(t.id,{...r,props:{...r.props,...o}}),this._notify([t.id]))}}else if(t.target==="blockType"){const r=this.blocks.get(t.id);r&&this._fieldClocks.shouldApplyRemote(t.id,"type",t.clock)&&(this._fieldClocks.recordRemote(t.id,"type",t.clock),this.blocks.set(t.id,{...r,type:t.blockType,props:t.props}),this._notify([t.id]))}for(const r of Object.values(t.clocks??{}))this._clock.receive(r);t.clock&&this._clock.receive(t.clock);return}default:throw new Error(`Unknown remote envelope kind: ${t.kind}`)}}getTombstoneCount(){let t=0;for(const n of this._orders.values())t+=n.tombstoneCount();return t}pruneTombstones({maxAgeMs:t=24*60*60*1e3,now:n=Date.now()}={}){const r={wallTime:n-t,counter:0,peerId:""};let o=0;for(const s of this._orders.values())o+=s.pruneTombstones(r);return o}toJSON(){return{blocks:[...this.blocks.values()],runs:[...this.runs.values()],rootId:this.rootId,fieldTypes:[...this.fieldTypes.values()]}}static fromJSON(t){return new tr(t)}}const yc=500;function vc(e,t){const n=e??"",r=t??"";let o=0;const s=Math.min(n.length,r.length);for(;o<s&&n[o]===r[o];)o+=1;let l=n.length,i=r.length;for(;l>o&&i>o&&n[l-1]===r[i-1];)l-=1,i-=1;return{beforeOffset:l,afterOffset:i}}function ps(e){var l,i;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 r=e.inverses[e.inverses.length-1];if((r==null?void 0:r.type)!=="updateRun"||typeof((i=r.patch)==null?void 0:i.value)!="string")return null;const{beforeOffset:o,afterOffset:s}=vc(r.patch.value,n.patch.value);return{runId:t.id,beforeOffset:o,afterOffset:s}}function fs(e){const t=[],n=r=>{var o;r&&((o=r.block)!=null&&o.id&&t.push(r.block.id),r.blockId&&t.push(r.blockId),r.id&&t.push(r.id),r.parentId&&t.push(r.parentId),r.toParentId&&t.push(r.toParentId))};for(const r of e.ops)n(r);for(const r of e.inverses)n(r);return[...new Set(t)]}class Gs{constructor(t,{idleMs:n=yc,trackChanges:r=!1,maxChangeLogSize:o=500}={}){this.store=t,this.idleMs=n,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=r,this.maxChangeLogSize=o,this.changeLog=[]}_recordChange(t,n,r){var s;if(!this.trackChanges)return;const o=t.patch!==void 0&&(n==null?void 0:n.patch)!==void 0;this.changeLog.push({opType:t.type,id:t.id??t.blockId??((s=t.block)==null?void 0:s.id),before:o?n.patch:void 0,after:o?t.patch:void 0,actorId:r.actorId??null,timestamp:r.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)}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(r=>this.perform(r,n))}performBatch(t,n={}){var l;const r=n.actorId??null,o=n.timestamp??Date.now();this._commitCurrentBatch();const s=[];for(const i of t){const c=this.store.applyOperation(i);s.unshift(c),this.historyLog.push({opType:i.type,id:i.id??i.blockId??((l=i.block)==null?void 0:l.id),actorId:r,timestamp:o}),this._recordChange(i,c,{actorId:r,timestamp:o})}this.redoStack=[],this.undoStack.push({ops:[...t],inverses:s,batchKey:null,actorId:r,timestamp:o,lastTimestamp:o,boundaryHit:!0}),this._notify()}perform(t,n={}){const r=n.actorId??null,o=n.timestamp??Date.now(),s=this.store.applyOperation(t);return this._record(t,s,{actorId:r,timestamp:o}),s}_batchKeyFor(t){return t.type==="updateRun"?`run:${t.id}`:null}_isWordBoundary(t){var r;if(t.type!=="updateRun")return!1;const n=(r=t.patch)==null?void 0:r.value;return typeof n!="string"||n.length===0?!1:/\s/.test(n[n.length-1])}_record(t,n,r){var i;this.redoStack=[];const o=this._batchKeyFor(t),s=this.currentBatch&&r.timestamp-this.currentBatch.lastTimestamp<=this.idleMs;this.currentBatch&&o!==null&&this.currentBatch.batchKey===o&&s&&!this.currentBatch.boundaryHit?(this.currentBatch.ops.push(t),this.currentBatch.inverses.unshift(n),this.currentBatch.lastTimestamp=r.timestamp,this._isWordBoundary(t)&&(this.currentBatch.boundaryHit=!0)):(this._commitCurrentBatch(),this.currentBatch={ops:[t],inverses:[n],batchKey:o,actorId:r.actorId,timestamp:r.timestamp,lastTimestamp:r.timestamp,boundaryHit:this._isWordBoundary(t)}),this._resetIdleTimer(),this.historyLog.push({opType:t.type,id:t.id??((i=t.block)==null?void 0:i.id),actorId:r.actorId,timestamp:r.timestamp}),this._recordChange(t,n,r),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 r of t.inverses)this.store.applyOperation(r);this.redoStack.push(t);const n=ps(t);return this._pendingSelection=n?{runId:n.runId,offset:n.beforeOffset}:null,this._pendingAffectedBlockIds=fs(t),this._notify(),!0}redo(){const t=this.redoStack.pop();if(!t)return!1;for(const r of t.ops)this.store.applyOperation(r);this.undoStack.push(t);const n=ps(t);return this._pendingSelection=n?{runId:n.runId,offset:n.afterOffset}:null,this._pendingAffectedBlockIds=fs(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()}}const wc=60*60*1e3,Ic=24*60*60*1e3;function Cc({store:e,intervalMs:t=wc,maxAgeMs:n=Ic,onPrune:r,onError:o}){const s=setInterval(()=>{try{const l=e.pruneTombstones({maxAgeMs:n});l>0&&(r==null||r(l))}catch(l){o==null||o(l)}},t);return{stop(){clearInterval(s)}}}const Ve={HELLO:"hello",OP:"op",SYNC_REQUEST:"syncRequest",SYNC_RESPONSE:"syncResponse",PRESENCE:"presence"};function Kt(e){return JSON.stringify(e)}function Js(e){const t=JSON.parse(e);if(!t||typeof t.type!="string")throw new Error("Invalid sync message: missing type");return t}function Sc(e){return{type:Ve.HELLO,peerId:e}}function Tc(e){return{type:Ve.OP,envelope:e}}function Rc(){return{type:Ve.SYNC_REQUEST}}function jc(e){return{type:Ve.SYNC_RESPONSE,doc:e}}function hs(e,t){return{type:Ve.PRESENCE,peerId:e,data:t}}const Bc="noteloom-sync",Ec={iceServers:[{urls:"stun:stun.l.google.com:19302"}]},Nn=16e3,Lc=1e6,Oc=256e3;function _c(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}class Zs{constructor({signaling:t,remotePeerId:n,initiator:r,rtcConfig:o=Ec}){this.remotePeerId=n,this._signaling=t,this._pc=new RTCPeerConnection(o),this._channel=null,this._openListeners=new Set,this._closeListeners=new Set,this._messageListeners=new Set,this._chunkBuffers=new Map,this._sendQueue=[],this._pumping=!1,this._pc.onicecandidate=s=>{s.candidate&&this._signaling.send(n,{kind:"ice",candidate:s.candidate.toJSON()})},r?(this._wireChannel(this._pc.createDataChannel(Bc)),this._pc.createOffer().then(s=>this._pc.setLocalDescription(s).then(()=>s)).then(s=>this._signaling.send(n,{kind:"offer",sdp:s}))):this._pc.ondatachannel=s=>this._wireChannel(s.channel),this._unsubscribeSignaling=t.onMessage((s,l)=>{s===n&&this._handleSignal(l)})}async _handleSignal(t){if(t.kind==="offer"){await this._pc.setRemoteDescription(t.sdp);const n=await this._pc.createAnswer();await this._pc.setLocalDescription(n),this._signaling.send(this.remotePeerId,{kind:"answer",sdp:n})}else if(t.kind==="answer")await this._pc.setRemoteDescription(t.sdp);else if(t.kind==="ice")try{await this._pc.addIceCandidate(t.candidate)}catch{}}_wireChannel(t){this._channel=t,t.bufferedAmountLowThreshold=Oc,t.onopen=()=>{for(const n of this._openListeners)n()},t.onclose=()=>{for(const n of this._closeListeners)n()},t.onmessage=n=>this._handleRawMessage(n.data)}_handleRawMessage(t){if(typeof t!="string"||t.length===0)return;const n=t[0];if(n==="S"){for(const m of this._messageListeners)m(t.slice(1));return}if(n!=="C")return;const r=t.slice(1),o=r.indexOf(":"),s=r.indexOf(":",o+1),l=r.indexOf(":",s+1);if(o===-1||s===-1||l===-1)return;const i=r.slice(0,o),c=Number(r.slice(o+1,s)),u=Number(r.slice(s+1,l)),f=r.slice(l+1);let d=this._chunkBuffers.get(i);if(d||(d={total:u,received:new Map},this._chunkBuffers.set(i,d)),d.received.set(c,f),d.received.size<d.total)return;this._chunkBuffers.delete(i);let h="";for(let m=0;m<d.total;m+=1)h+=d.received.get(m);for(const m of this._messageListeners)m(h)}send(t){var n;if(((n=this._channel)==null?void 0:n.readyState)==="open"){if(t.length<=Nn)this._sendQueue.push(`S${t}`);else{const r=_c(),o=Math.ceil(t.length/Nn);for(let s=0;s<o;s+=1){const l=t.slice(s*Nn,(s+1)*Nn);this._sendQueue.push(`C${r}:${s}:${o}:${l}`)}}this._pumpSendQueue()}}async _pumpSendQueue(){if(!this._pumping){this._pumping=!0;try{for(;this._sendQueue.length>0;){if(!this._channel||this._channel.readyState!=="open"){this._sendQueue.length=0;break}if(this._channel.bufferedAmount>Lc){await this._waitForBufferedAmountLow();continue}const t=this._sendQueue.shift();try{this._channel.send(t)}catch(n){console.warn("[noteloom] failed to send a sync message to peer",this.remotePeerId,n),this._sendQueue.length=0;break}}}finally{this._pumping=!1}}}_waitForBufferedAmountLow(){return new Promise(t=>{if(!this._channel){t();return}const n=()=>{this._channel.removeEventListener("bufferedamountlow",n),t()};this._channel.addEventListener("bufferedamountlow",n)})}onOpen(t){return this._openListeners.add(t),()=>this._openListeners.delete(t)}onClose(t){return this._closeListeners.add(t),()=>this._closeListeners.delete(t)}onMessage(t){return this._messageListeners.add(t),()=>this._messageListeners.delete(t)}close(){var t,n;this._chunkBuffers.clear(),this._sendQueue.length=0,(t=this._unsubscribeSignaling)==null||t.call(this),(n=this._channel)==null||n.close(),this._pc.close()}}const Nc=100;class Mc{constructor({history:t,signaling:n,presenceThrottleMs:r=Nc}){this._history=t,this._store=t.store,this._signaling=n,this._peers=new Map,this._unsubscribeLocal=this._attachLocalBroadcast(),this._localPresence=null,this._remotePresence=new Map,this._presenceListeners=new Set,this._presenceThrottleMs=r,this._presenceThrottleTimer=null,this._presenceDirty=!1}_attachLocalBroadcast(){const t=this._store.applyOperation.bind(this._store);this._pendingEnvelopes=[],this._store.applyOperation=r=>{const o=t(r),s=this._store.getLastEnvelope();return s&&this._pendingEnvelopes.push(s),o};const n={};for(const r of["perform","performBatch","undo","redo"]){const o=this._history[r].bind(this._history);n[r]=o,this._history[r]=(...s)=>{const l=o(...s);return this._flushPendingEnvelopes(),l}}return()=>{for(const r of Object.keys(n))this._history[r]=n[r];this._store.applyOperation=t}}_flushPendingEnvelopes(){const t=this._pendingEnvelopes;this._pendingEnvelopes=[];for(const n of t)this._broadcast(Tc(n))}_broadcast(t){const n=Kt(t);for(const r of this._peers.values())r.send(n)}connect(t,{initiator:n}){var o;(o=this._peers.get(t))==null||o.close();const r=new Zs({signaling:this._signaling,remotePeerId:t,initiator:n});return r.onOpen(()=>{r.send(Kt(Sc(this._signaling.localPeerId))),r.send(Kt(Rc())),this._localPresence!==null&&r.send(Kt(hs(this._signaling.localPeerId,this._localPresence)))}),r.onMessage(s=>this._handleMessage(r,s)),r.onClose(()=>{this._peers.delete(t),this._remotePresence.delete(t)&&this._notifyPresenceListeners()}),this._peers.set(t,r),r}setLocalPresence(t){this._localPresence=t,this._presenceDirty=!0,!this._presenceThrottleTimer&&(this._flushLocalPresence(),this._presenceThrottleTimer=setTimeout(()=>{this._presenceThrottleTimer=null,this._presenceDirty&&this._flushLocalPresence()},this._presenceThrottleMs))}_flushLocalPresence(){this._presenceDirty=!1,this._broadcast(hs(this._signaling.localPeerId,this._localPresence))}getPresence(){return new Map(this._remotePresence)}onPresenceChange(t){return this._presenceListeners.add(t),()=>this._presenceListeners.delete(t)}_notifyPresenceListeners(){const t=this.getPresence();for(const n of this._presenceListeners)n(t)}_handleMessage(t,n){let r;try{r=Js(n)}catch{return}r.type===Ve.OP?(this._store.applyRemoteOperation(r.envelope),this._history.flush()):r.type===Ve.SYNC_REQUEST?t.send(Kt(jc(this._store.toJSON()))):r.type===Ve.SYNC_RESPONSE?this._adoptSnapshotIfEmpty(r.doc):r.type===Ve.PRESENCE&&(this._remotePresence.set(r.peerId,r.data),this._notifyPresenceListeners())}_adoptSnapshotIfEmpty(t){const n=this._store.getRootId();n&&this._store.getBlock(n)||(this._store.blocks=new Map((t.blocks??[]).map(r=>[r.id,r])),this._store.runs=new Map((t.runs??[]).map(r=>[r.id,r])),this._store.rootId=t.rootId??null,this._store._orders=new Map,this._store._notify([...this._store.blocks.keys(),...this._store.runs.keys()]))}disconnect(t){var n;(n=this._peers.get(t))==null||n.close(),this._peers.delete(t)}destroy(){this._unsubscribeLocal(),this._presenceThrottleTimer&&clearTimeout(this._presenceThrottleTimer);for(const t of this._peers.values())t.close();this._peers.clear(),this._remotePresence.clear(),this._presenceListeners.clear()}}function Ac({url:e,roomId:t,peerId:n,WebSocketImpl:r=WebSocket}){const o=new Set,s=new Set,l=new Set,i=[],c=`${e}${e.includes("?")?"&":"?"}room=${encodeURIComponent(t)}&peerId=${encodeURIComponent(n)}`,u=new r(c);u.addEventListener("open",()=>{for(const{toPeerId:d,payload:h}of i)f(d,h);i.length=0}),u.addEventListener("message",d=>{let h;try{h=JSON.parse(d.data)}catch{return}if(h.type==="roster")for(const m of h.peerIds??[])for(const g of s)g(m);else if(h.type==="peer-joined")for(const m of s)m(h.peerId);else if(h.type==="peer-left")for(const m of l)m(h.peerId);else if(h.type==="signal")for(const m of o)m(h.fromPeerId,h.payload)});function f(d,h){if(u.readyState!==r.OPEN){i.push({toPeerId:d,payload:h});return}u.send(JSON.stringify({type:"signal",toPeerId:d,payload:h}))}return{localPeerId:n,send(d,h){f(d,h)},onMessage(d){return o.add(d),()=>o.delete(d)},onPeerDiscovered(d){return s.add(d),()=>s.delete(d)},onPeerLeft(d){return l.add(d),()=>l.delete(d)},close(){i.length=0,u.close()}}}const Dc="noteloom-documents",qe="documents",Pc=1;let Mn=null;function nr(){return Mn||(Mn=new Promise((e,t)=>{const n=indexedDB.open(Dc,Pc);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(qe)||n.result.createObjectStore(qe)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}),Mn)}async function Qs(e,t){const n=await nr();return new Promise((r,o)=>{const s=n.transaction(qe,"readwrite");s.objectStore(qe).put(t,e),s.oncomplete=()=>r(),s.onerror=()=>o(s.error)})}async function el(e){const t=await nr();return new Promise((n,r)=>{const s=t.transaction(qe,"readonly").objectStore(qe).get(e);s.onsuccess=()=>n(s.result??null),s.onerror=()=>r(s.error)})}async function $c(e){const t=await nr();return new Promise((n,r)=>{const o=t.transaction(qe,"readwrite");o.objectStore(qe).delete(e),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function zc(){const e=await nr();return new Promise((t,n)=>{const o=e.transaction(qe,"readonly").objectStore(qe).getAllKeys();o.onsuccess=()=>t(o.result),o.onerror=()=>n(o.error)})}const Hc=500;function tl({store:e,docId:t,debounceMs:n=Hc,onError:r}){let o=null;function s(){Qs(t,e.toJSON()).catch(u=>r==null?void 0:r(u))}function l(){o&&(clearTimeout(o),o=null,s())}const i=e.subscribeAll(()=>{o&&clearTimeout(o),o=setTimeout(()=>{o=null,s()},n)});function c(){o&&clearTimeout(o),o=null,i()}return{stop:c,flush:l}}class nl{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 rl(){return new nl}class ol{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 sl(){return new ol}const Fc=`/*\r
|
|
2
|
+
* noteloom's default theme — minimal, clean, modern SaaS-adjacent.\r
|
|
3
3
|
*\r
|
|
4
4
|
* Ships as plain CSS custom properties on :root (not scoped to a wrapper\r
|
|
5
5
|
* element) deliberately: several of this package's own pieces — Select's\r
|
|
@@ -101,6 +101,18 @@
|
|
|
101
101
|
}\r
|
|
102
102
|
\r
|
|
103
103
|
.be-editable {\r
|
|
104
|
+
/* Block-level and full-width so the whole line (including the blank\r
|
|
105
|
+
trailing space after short text, and an empty line's full height) is\r
|
|
106
|
+
part of the actual contentEditable hit-test box. Left inline/sized to\r
|
|
107
|
+
content, a click on that blank area lands on the non-editable wrapper\r
|
|
108
|
+
div instead of this element: the browser's native "nothing focused\r
|
|
109
|
+
yet" resolution still finds it on a first click, but re-clicking the\r
|
|
110
|
+
same dead-zone point while this element already holds the selection\r
|
|
111
|
+
collapses/clears it instead, since there's nothing here to re-anchor\r
|
|
112
|
+
the caret onto. */\r
|
|
113
|
+
display: block;\r
|
|
114
|
+
width: 100%;\r
|
|
115
|
+
min-height: 1em;\r
|
|
104
116
|
outline: none;\r
|
|
105
117
|
}\r
|
|
106
118
|
\r
|
|
@@ -797,7 +809,7 @@
|
|
|
797
809
|
.be-canvas-toolbar-btn {\r
|
|
798
810
|
border: none;\r
|
|
799
811
|
background: transparent;\r
|
|
800
|
-
width:
|
|
812
|
+
width: 28px;\r
|
|
801
813
|
height: 24px;\r
|
|
802
814
|
display: flex;\r
|
|
803
815
|
align-items: center;\r
|
|
@@ -2183,8 +2195,8 @@ tr.be-table-row:hover .be-table-delete-row {\r
|
|
|
2183
2195
|
}\r
|
|
2184
2196
|
\r
|
|
2185
2197
|
/* A mention chip always uses this one fixed color, not each option's own\r
|
|
2186
|
-
tag color —
|
|
2187
|
-
|
|
2198
|
+
tag color — "@mentions are one consistent color" is the common\r
|
|
2199
|
+
convention rather than a per-person palette. */\r
|
|
2188
2200
|
.be-select-tag-mention {\r
|
|
2189
2201
|
background: var(--noteloom-accent-soft);\r
|
|
2190
2202
|
color: var(--noteloom-accent);\r
|
|
@@ -2510,12 +2522,12 @@ tr.be-table-row:hover .be-table-delete-row {\r
|
|
|
2510
2522
|
break-inside: avoid;\r
|
|
2511
2523
|
}\r
|
|
2512
2524
|
}\r
|
|
2513
|
-
`,Jo="noteloom-default-styles";function Ls(){if(typeof document>"u"||document.getElementById(Jo))return;const e=document.createElement("style");e.id=Jo,e.textContent=_i,document.head.appendChild(e)}const Ms=d.createContext(null);function zi({store:e,registry:n,inlineRegistry:t=null,history:r=null,className:o,style:s,theme:l="default",getBlockClassName:i,children:c}){d.useEffect(()=>{l!=="none"&&Ls()},[l]);const[u,f]=d.useState(!1),[p,h]=d.useState([]),[b,g]=d.useState(!1),[x,k]=d.useState(null),y=d.useCallback(()=>k("new"),[]),I=d.useCallback(N=>k(N),[]),w=d.useCallback(()=>k(null),[]),T=d.useRef(null),S=d.useCallback(()=>T.current,[]),v=d.useCallback(N=>{var B,A;const C=T.current;C!==N&&(C&&((B=document.querySelector(`[data-block-id="${C}"]`))==null||B.classList.remove("be-block-selected")),T.current=N,N&&((A=document.querySelector(`[data-block-id="${N}"]`))==null||A.classList.add("be-block-selected")))},[]),R=d.useMemo(()=>({store:e,registry:n,inlineRegistry:t,history:r,isWholeDocumentSelected:u,setIsWholeDocumentSelected:f,selectedBlockRange:p,setSelectedBlockRange:h,getSelectedBlockId:S,setSelectedBlockId:v,isPreviewMode:b,setIsPreviewMode:g,fieldTypeEditorTarget:x,openCreateFieldType:y,openEditFieldType:I,closeFieldTypeEditor:w,getBlockClassName:i}),[e,n,t,r,u,p,S,v,b,x,y,I,w,i]),O=o||s?a.jsx("div",{className:o?`be-root ${o}`:"be-root",style:s,children:c}):c;return a.jsx(Ms.Provider,{value:R,children:O})}function qe(){const e=d.useContext(Ms);if(!e)throw new Error("Editor hooks must be used within an <EditorProvider>");return e}function W(){return qe().store}function dn(){return qe().registry}function We(){return qe().inlineRegistry}function Fr(){const{isWholeDocumentSelected:e,setIsWholeDocumentSelected:n}=qe();return[e,n]}function ut(){const{selectedBlockRange:e,setSelectedBlockRange:n}=qe();return[e,n]}function rn(){const{getSelectedBlockId:e,setSelectedBlockId:n}=qe();return{getSelectedBlockId:e,setSelectedBlockId:n}}function Ur(){const{isPreviewMode:e,setIsPreviewMode:n}=qe();return[e,n]}function ve(e,n){const{getBlockClassName:t}=qe(),r=n&&t?t(n):void 0;return r?`${e} ${r}`:e}function Yr(){const{fieldTypeEditorTarget:e,openCreateFieldType:n,openEditFieldType:t,closeFieldTypeEditor:r}=qe();return{target:e,openCreate:n,openEdit:t,close:r}}function be(e){const n=W(),t=d.useCallback(o=>n.subscribe(e,o),[n,e]),r=d.useCallback(()=>n.getBlock(e),[n,e]);return d.useSyncExternalStore(t,r)}function pn(e){const n=W(),t=d.useCallback(o=>n.subscribe(e,o),[n,e]),r=d.useCallback(()=>n.getRun(e),[n,e]);return d.useSyncExternalStore(t,r)}function L(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`id-${Date.now()}-${Math.random().toString(36).slice(2)}`}const As="",Hi=//g;function en(e){return(e??"").replace(Hi,"")}function Qo(e){return en(e.textContent)}function Fi(e,n){var i;const t=new Map(n.map(c=>[c.id,c])),r=new Set,o=[];let s=!0;for(const c of e.childNodes){const u=c.nodeType===1?(i=c.dataset)==null?void 0:i.runId:void 0;if(u&&t.has(u)){r.add(u);const p=t.get(u);if(p.type!=="text"){o.push(p);continue}const h=Qo(c);o.push(h===p.value?p:{...p,value:h});continue}s=!1;const f=Qo(c);f&&o.push({id:L(),type:"text",value:f,marks:{}})}if(n.some(c=>!r.has(c.id))&&(s=!1),o.length!==n.length&&(s=!1),s){for(let c=0;c<o.length;c+=1)if(o[c].id!==n[c].id){s=!1;break}}const l=!s||o.some((c,u)=>c!==n[u]);return{runs:o,changed:l,onlyValueChanges:s}}function Ds(e){return e?e.type!=="text"?!1:(e.value??"")==="":!0}function Le(e,n){return!n||n.length===0?!0:n.every(t=>Ds(e.getRun(t)))}function dt(e,n){var o,s;if(!n)return!1;const t=n.contentIds.length>0,r=(((s=(o=n.props)==null?void 0:o.titleRunIds)==null?void 0:s.length)??0)>0;return!t&&!r}function Ps(e,n){const t=document.querySelector(`[data-run-id="${e}"]`);if(!t)return;t.focus();const r=t.firstChild,o=document.createRange();if(r&&r.nodeType===3){const l=Math.max(0,Math.min(n,r.length));o.setStart(r,l),o.setEnd(r,l)}else o.selectNodeContents(t),o.collapse(n<=0);const s=window.getSelection();s==null||s.removeAllRanges(),s==null||s.addRange(o)}function $s(e,n){requestAnimationFrame(()=>{const t=document.querySelector(`[data-run-id="${e}"]`);if(!t)return;t.focus();const r=document.createRange();r.selectNodeContents(t),r.collapse(n);const o=window.getSelection();o==null||o.removeAllRanges(),o==null||o.addRange(r)})}function xe(e){$s(e,!1)}function Ut(e){$s(e,!0)}function Ke(e,n){requestAnimationFrame(()=>Ps(e,n))}function es(e,n){Ps(e,n)}const Ui='button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';function on({isOpen:e,onClose:n,title:t,size:r="default",variant:o="dialog",children:s}){const l=d.useRef(null),i=d.useRef(null);if(d.useEffect(()=>{if(!e)return;const u=f=>{f.key==="Escape"&&n()};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[e,n]),d.useEffect(()=>{var u,f,p;if(e){i.current=document.activeElement;const h=l.current;(u=(h==null?void 0:h.querySelector(Ui))??h)==null||u.focus();return}(p=(f=i.current)==null?void 0:f.focus)==null||p.call(f),i.current=null},[e]),!e)return null;const c=o==="sheet";return a.jsx("div",{className:`be-modal-overlay${c?" be-modal-overlay-sheet":""}`,onMouseDown:u=>{u.target===u.currentTarget&&n()},children:a.jsxs("div",{ref:l,className:`be-modal${r==="large"?" be-modal-large":""}${c?" be-modal-sheet":""}`,role:"dialog","aria-modal":"true","aria-label":t,tabIndex:-1,children:[t&&a.jsx("div",{className:"be-modal-title",children:t}),s]})})}function _s({isOpen:e,initialHref:n,initialTarget:t,hasExistingLink:r,onSave:o,onRemove:s,onClose:l}){const[i,c]=d.useState(""),[u,f]=d.useState("_self");d.useEffect(()=>{e&&(c(n),f(t))},[e]);const p=i.trim(),h=d.useCallback(b=>{b.preventDefault(),p&&o(p,u)},[p,u,o]);return a.jsx(on,{isOpen:e,onClose:l,title:r?"Edit link":"Add link",children:a.jsxs("form",{onSubmit:h,children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"URL"}),a.jsx("input",{type:"text",value:i,onChange:b=>c(b.target.value),placeholder:"https://example.com",autoFocus:!0})]}),a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Open in"}),a.jsxs("select",{value:u,onChange:b=>f(b.target.value),children:[a.jsx("option",{value:"_self",children:"Same tab"}),a.jsx("option",{value:"_blank",children:"New tab"})]})]}),a.jsxs("div",{className:"be-modal-actions",children:[r&&a.jsx("button",{type:"button",className:"be-modal-delete",onClick:s,children:"Remove link"}),a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:l,children:"Cancel"}),a.jsx("button",{type:"submit",className:"be-modal-save",disabled:!p,children:"Save"})]})]})})}const Mn=8;function Yt(e,n){const t=Math.max(Mn,window.innerWidth-n-Mn);return Math.min(Math.max(e,Mn),t)}function Yi(e,n){const t=Math.max(Mn,window.innerHeight-n-Mn);return Math.min(Math.max(e,Mn),t)}function Kt(e,n,t,r){const[o,s]=d.useState(null);return d.useLayoutEffect(()=>{if(t==null||r==null){s(null);return}s({top:t,left:r})},[t,r]),d.useLayoutEffect(()=>{if(!n||!e.current||!o)return;const l=e.current.getBoundingClientRect(),i=Yt(o.left,l.width),c=Yi(o.top,l.height);(i!==o.left||c!==o.top)&&s({top:c,left:i})},[n,e,o]),o}function F({children:e,size:n=16,strokeWidth:t=2,...r}){return a.jsx("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:t,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",...r,children:e})}function yn(e){return a.jsx(F,{...e,children:a.jsx("polyline",{points:"9 18 15 12 9 6"})})}function Vt(e){return a.jsx(F,{...e,children:a.jsx("polyline",{points:"6 9 12 15 18 9"})})}function zn(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),a.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Ki(e){return a.jsxs(F,{...e,fill:"currentColor",stroke:"none",children:[a.jsx("circle",{cx:"5",cy:"12",r:"1.6"}),a.jsx("circle",{cx:"12",cy:"12",r:"1.6"}),a.jsx("circle",{cx:"19",cy:"12",r:"1.6"})]})}function zs(e){return a.jsx(F,{...e,children:a.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}function Kr(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),a.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function Hs(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"}),a.jsx("path",{d:"M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"})]})}function Fs(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"19",y1:"4",x2:"10",y2:"4"}),a.jsx("line",{x1:"14",y1:"20",x2:"5",y2:"20"}),a.jsx("line",{x1:"15",y1:"4",x2:"9",y2:"20"})]})}function Us(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M6 3v7a6 6 0 0 0 12 0V3"}),a.jsx("line",{x1:"4",y1:"21",x2:"20",y2:"21"})]})}function Ys(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M12 20h9"}),a.jsx("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]})}function Vi(e){return a.jsx(F,{...e,children:a.jsx("path",{d:"M3 17c2-4 4-4 6 0s4 4 6 0 4-4 6 0"})})}function Ks(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),a.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})}function Xi(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M16 4H9a3 3 0 0 0-2.83 4"}),a.jsx("path",{d:"M14 12a4 4 0 0 1 0 8H6"}),a.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}function Vs(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),a.jsx("line",{x1:"17",y1:"10",x2:"3",y2:"10"}),a.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),a.jsx("line",{x1:"17",y1:"18",x2:"3",y2:"18"})]})}function qi(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),a.jsx("line",{x1:"18",y1:"10",x2:"6",y2:"10"}),a.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),a.jsx("line",{x1:"18",y1:"18",x2:"6",y2:"18"})]})}function Xs(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),a.jsx("line",{x1:"21",y1:"10",x2:"7",y2:"10"}),a.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),a.jsx("line",{x1:"21",y1:"18",x2:"7",y2:"18"})]})}function Wi(e){return a.jsx(F,{...e,children:[5,12,19].flatMap(n=>[9,15].map(t=>a.jsx("circle",{cx:t,cy:n,r:"1.3",fill:"currentColor",stroke:"none"},`${t}-${n}`)))})}function Xt(e){return a.jsxs(F,{...e,children:[a.jsx("polyline",{points:"3 6 5 6 21 6"}),a.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),a.jsx("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),a.jsx("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function Vr(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"9",y:"9",width:"12",height:"12",rx:"2"}),a.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function qt(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),a.jsx("polyline",{points:"5 12 12 5 19 12"})]})}function Wt(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),a.jsx("polyline",{points:"19 12 12 19 5 12"})]})}function qs(e){return a.jsx(F,{...e,children:a.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"1"})})}function Gi(e){return a.jsx(F,{...e,children:a.jsx("circle",{cx:"12",cy:"12",r:"8"})})}function Zi(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"6",y1:"18",x2:"18",y2:"6"}),a.jsx("polyline",{points:"9 6 18 6 18 15"})]})}function Ji(e){return a.jsx(F,{...e,children:a.jsx("polygon",{points:"12 3 21 12 12 21 3 12"})})}function Qi(e){return a.jsx(F,{...e,children:a.jsx("polygon",{points:"12 4 20 20 4 20"})})}function ec(e){return a.jsx(F,{...e,children:a.jsx("polygon",{points:"12 3 14.7 9.4 21.5 9.9 16.3 14.4 17.9 21 12 17.4 6.1 21 7.7 14.4 2.5 9.9 9.3 9.4"})})}function nc(e){return a.jsx(F,{...e,children:a.jsx("path",{d:"M5 3l14 8-6 2-2 6-6-16z"})})}function Ws(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M19 20H9l-6-6a1.5 1.5 0 0 1 0-2l9-9a1.5 1.5 0 0 1 2 0l7 7a1.5 1.5 0 0 1 0 2l-7 7"}),a.jsx("path",{d:"M6.5 12.5 13 19"})]})}function tc(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M12 3v12"}),a.jsx("path",{d:"M7 10l5 5 5-5"}),a.jsx("path",{d:"M4 19h16"})]})}function rc(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M6 15V9a6 6 0 0 1 12 0v6"}),a.jsx("path",{d:"M6 15a3 3 0 0 0 6 0v-4"}),a.jsx("path",{d:"M18 15a3 3 0 0 1-6 0v-4"}),a.jsx("line",{x1:"3",y1:"9",x2:"6",y2:"9"}),a.jsx("line",{x1:"3",y1:"15",x2:"6",y2:"15"}),a.jsx("line",{x1:"18",y1:"9",x2:"21",y2:"9"}),a.jsx("line",{x1:"18",y1:"15",x2:"21",y2:"15"})]})}function oc(e){return a.jsxs(F,{...e,children:[a.jsx("circle",{cx:"6",cy:"6",r:"3"}),a.jsx("circle",{cx:"6",cy:"18",r:"3"}),a.jsx("line",{x1:"20",y1:"4",x2:"8.12",y2:"15.88"}),a.jsx("line",{x1:"14.47",y1:"14.48",x2:"20",y2:"20"}),a.jsx("line",{x1:"8.12",y1:"8.12",x2:"12",y2:"12"})]})}function Xr(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"17",y1:"6",x2:"3",y2:"6"}),a.jsx("line",{x1:"21",y1:"12",x2:"3",y2:"12"}),a.jsx("line",{x1:"15",y1:"18",x2:"3",y2:"18"})]})}function qr({level:e=1,size:n=16,...t}){return a.jsx("svg",{width:n,height:n,viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",...t,children:a.jsxs("text",{x:"2",y:"18",fontSize:"14",fontWeight:"700",fill:"currentColor",fontFamily:"inherit",children:["H",e]})})}function Gs(e){return a.jsx(qr,{level:1,...e})}function Zs(e){return a.jsx(qr,{level:2,...e})}function Js(e){return a.jsx(qr,{level:3,...e})}function Qs(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M7 7a3 3 0 0 0-3 3v3a2 2 0 0 0 2 2h2a1 1 0 0 0 1-1v-4a1 1 0 0 0-1-1H6a3 3 0 0 1 3-3z"}),a.jsx("path",{d:"M17 7a3 3 0 0 0-3 3v3a2 2 0 0 0 2 2h2a1 1 0 0 0 1-1v-4a1 1 0 0 0-1-1h-2a3 3 0 0 1 3-3z"})]})}function Wr(e){return a.jsxs(F,{...e,children:[a.jsx("polyline",{points:"9 8 4 12 9 16"}),a.jsx("polyline",{points:"15 8 20 12 15 16"})]})}function sc(e){return a.jsx(F,{...e,children:a.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})})}function ea(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M4 5h16a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H9l-4 4v-4H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z"}),a.jsx("line",{x1:"7",y1:"9",x2:"17",y2:"9"}),a.jsx("line",{x1:"7",y1:"12.5",x2:"13",y2:"12.5"})]})}function ac(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"3",y:"8",width:"18",height:"8",rx:"3"}),a.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function lc(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"1"}),a.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"}),a.jsx("line",{x1:"3",y1:"16",x2:"21",y2:"16"}),a.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),a.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function ic(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"1"}),a.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),a.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function na(e){return a.jsxs(F,{...e,children:[a.jsx("circle",{cx:"4.5",cy:"6",r:"1.2",fill:"currentColor",stroke:"none"}),a.jsx("circle",{cx:"4.5",cy:"12",r:"1.2",fill:"currentColor",stroke:"none"}),a.jsx("circle",{cx:"4.5",cy:"18",r:"1.2",fill:"currentColor",stroke:"none"}),a.jsx("line",{x1:"9",y1:"6",x2:"21",y2:"6"}),a.jsx("line",{x1:"9",y1:"12",x2:"21",y2:"12"}),a.jsx("line",{x1:"9",y1:"18",x2:"21",y2:"18"})]})}function ta(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"10",y1:"6",x2:"21",y2:"6"}),a.jsx("line",{x1:"10",y1:"12",x2:"21",y2:"12"}),a.jsx("line",{x1:"10",y1:"18",x2:"21",y2:"18"}),a.jsx("text",{x:"2",y:"8.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"1"}),a.jsx("text",{x:"2",y:"14.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"2"}),a.jsx("text",{x:"2",y:"20.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"3"})]})}function Gr(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"3"}),a.jsx("polyline",{points:"8 12 11 15 16 9"})]})}function cc(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"3",y:"5",width:"18",height:"16",rx:"2"}),a.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"}),a.jsx("line",{x1:"8",y1:"3",x2:"8",y2:"7"}),a.jsx("line",{x1:"16",y1:"3",x2:"16",y2:"7"})]})}function ra(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M12 3h7a2 2 0 0 1 2 2v7a2 2 0 0 1-.59 1.41l-8 8a2 2 0 0 1-2.82 0l-7-7a2 2 0 0 1 0-2.82l8-8A2 2 0 0 1 12 3z"}),a.jsx("circle",{cx:"15.5",cy:"8.5",r:"1.2",fill:"currentColor",stroke:"none"})]})}function uc(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),a.jsx("circle",{cx:"9",cy:"10",r:"1.5",fill:"currentColor",stroke:"none"}),a.jsx("path",{d:"M4 17l5-5 4 4 4-5 4 6"})]})}function dc(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"3",y:"5",width:"14",height:"14",rx:"2"}),a.jsx("path",{d:"M17 10l4-2.5v9L17 14"})]})}function Zr(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7z"}),a.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function Jr(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 19c-6.5 0-10-7-10-7a18.5 18.5 0 0 1 5.06-5.94M9.9 4.24A10.94 10.94 0 0 1 12 4c6.5 0 10 7 10 7a18.5 18.5 0 0 1-2.16 3.19"}),a.jsx("path",{d:"M14.12 14.12a3 3 0 1 1-4.24-4.24"}),a.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function pc(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"4",y1:"10",x2:"4",y2:"14"}),a.jsx("line",{x1:"8",y1:"7",x2:"8",y2:"17"}),a.jsx("line",{x1:"12",y1:"4",x2:"12",y2:"20"}),a.jsx("line",{x1:"16",y1:"7",x2:"16",y2:"17"}),a.jsx("line",{x1:"20",y1:"10",x2:"20",y2:"14"})]})}function fc(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),a.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),a.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),a.jsx("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}function hc({containerRef:e,store:n}){var I;const[t,r]=d.useState(null),[o,s]=d.useState(!1),l=d.useRef(null),i=d.useRef(null),c=d.useCallback(()=>{l.current&&(clearTimeout(l.current),l.current=null)},[]),u=d.useCallback(()=>{c(),l.current=setTimeout(()=>{r(w=>o?w:null)},250)},[c,o]);d.useEffect(()=>{const w=e.current;if(!w)return;const T=v=>{var C,B,A;const R=(B=(C=v.target).closest)==null?void 0:B.call(C,"[data-run-id]");if(!R||!w.contains(R))return;const O=R.dataset.runId,N=n.getRun(O);(A=N==null?void 0:N.marks)!=null&&A.link&&(c(),r(z=>(z==null?void 0:z.runId)===O?z:{runId:O,rect:R.getBoundingClientRect()}))},S=()=>u();return w.addEventListener("mouseover",T),w.addEventListener("mouseout",S),()=>{w.removeEventListener("mouseover",T),w.removeEventListener("mouseout",S)}},[e,n,c,u]),d.useEffect(()=>()=>c(),[c]);const f=d.useCallback(()=>s(!0),[]),p=d.useCallback(()=>{s(!1),r(null)},[]),h=d.useCallback((w,T)=>{if(!t)return;const S=n.getRun(t.runId);S&&(n.applyOperation(ce(t.runId,{marks:{...S.marks,link:{href:w,target:T}}})),p())},[t,n,p]),b=d.useCallback(()=>{if(!t)return;const w=n.getRun(t.runId);if(!w)return;const T={...w.marks};delete T.link,n.applyOperation(ce(t.runId,{marks:T})),p()},[t,n,p]),g=t&&n.getRun(t.runId),x=(I=g==null?void 0:g.marks)==null?void 0:I.link,k=!!(t&&x&&!o),y=Kt(i,k,t?t.rect.bottom+6:null,t?t.rect.left:null);return a.jsxs(a.Fragment,{children:[k&&y?Ve.createPortal(a.jsxs("div",{ref:i,className:"be-link-hover-card",contentEditable:!1,style:{position:"fixed",top:y.top,left:y.left},onMouseEnter:c,onMouseLeave:u,children:[a.jsx("a",{className:"be-link-hover-card-url",href:x.href,target:x.target==="_blank"?"_blank":"_self",rel:"noopener noreferrer",children:x.href}),a.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:f,"aria-label":"Edit link",title:"Edit link",children:a.jsx(Ys,{size:13})}),a.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:b,"aria-label":"Remove link",title:"Remove link",children:a.jsx(zn,{size:13})})]}),document.body):null,a.jsx(_s,{isOpen:o,initialHref:(x==null?void 0:x.href)??"",initialTarget:(x==null?void 0:x.target)??"_self",hasExistingLink:!!x,onSave:h,onRemove:b,onClose:p})]})}function ns(e,n){const t=e==null?void 0:e.parentElement;if(!t||!t.hasAttribute("data-placeholder"))return;n.length===0||n.every(Ds)?t.setAttribute("data-empty",""):t.removeAttribute("data-empty")}function bc(e={}){return{fontWeight:e.bold?"bold":void 0,fontStyle:e.italic?"italic":void 0,textDecoration:[(e.underline||e.link)&&"underline",e.strike&&"line-through"].filter(Boolean).join(" ")||void 0,verticalAlign:e.subscript?"sub":e.superscript?"super":void 0,fontSize:e.subscript||e.superscript?"smaller":void 0,color:e.color||(e.link?"var(--noteloom-accent)":void 0),backgroundColor:e.highlight||void 0,cursor:e.link?"pointer":void 0}}function mc(e,n){const t=e.childNodes.length===1?e.firstChild:null;t&&t.nodeType===3?t.nodeValue!==n&&(t.nodeValue=n):e.textContent=n}function gc({id:e,host:n,onValueSynced:t}){const r=pn(e);return d.useLayoutEffect(()=>{var u;if(!n||!r)return;const o=r.value??"";(en(n.textContent)!==o||o===""&&n.textContent==="")&&mc(n,o===""?As:o);const i=bc(r.marks);n.style.fontWeight=i.fontWeight??"",n.style.fontStyle=i.fontStyle??"",n.style.textDecoration=i.textDecoration??"",n.style.verticalAlign=i.verticalAlign??"",n.style.fontSize=i.fontSize??"",n.style.color=i.color??"",n.style.backgroundColor=i.backgroundColor??"",n.style.cursor=i.cursor??"";const c=(u=r.marks)==null?void 0:u.link;n.title=c!=null&&c.href?`${c.href} — Ctrl+Click to open`:"",n.onclick=c!=null&&c.href?f=>{!f.ctrlKey&&!f.metaKey||(f.preventDefault(),window.open(c.href,c.target==="_blank"?"_blank":"_self","noopener,noreferrer"))}:null,t==null||t()},[n,r,t]),null}function ts(e,n,t,r){var p,h,b;const o=(p=window.getSelection)==null?void 0:p.call(window);if(!o||!o.isCollapsed||o.rangeCount===0)return null;const{anchorNode:s,anchorOffset:l}=o;if(!s||!e.contains(s))return null;const i=g=>{const x=n.indexOf(g);if(x===-1)return null;const k=r?n[x-1]:n[x+1];if(!k)return null;const y=t(k);return y&&y.type!=="text"?k:null};if(s===e){const g=r?l-1:l,x=e.childNodes[g],k=(x==null?void 0:x.nodeType)===1?(h=x.dataset)==null?void 0:h.runId:void 0;if(!k||n.indexOf(k)===-1)return null;const y=t(k);return y&&y.type!=="text"?k:null}const c=s.nodeType===1?s:s.parentElement,u=(b=c==null?void 0:c.closest)==null?void 0:b.call(c,"[data-run-id]");return!u||!e.contains(u)||!(r?l===0:l===(s.textContent??"").length)?null:i(u.getAttribute("data-run-id"))}function rs(e,n,t){var c,u;const r=(c=window.getSelection)==null?void 0:c.call(window);if(!r||r.isCollapsed||r.rangeCount===0)return null;const o=r.getRangeAt(0);if(o.startContainer!==o.endContainer||!e.contains(o.startContainer)||o.endOffset!==o.startOffset+1)return null;const s=o.startContainer.childNodes[o.startOffset],l=(s==null?void 0:s.nodeType)===1?(u=s.dataset)==null?void 0:u.runId:void 0;if(!l||n.indexOf(l)===-1)return null;const i=t(l);return i&&i.type!=="text"?l:null}function os(e,n,t){var i;if(n===e)return{childIndex:t,charOffset:null};const r=n.nodeType===1?n:n.parentElement,o=(i=r==null?void 0:r.closest)==null?void 0:i.call(r,"[data-run-id]");if(!o||!e.contains(o))return null;const s=Array.prototype.indexOf.call(e.childNodes,o),l=n===o?t===0?0:(o.textContent??"").length:t;return{childIndex:s,charOffset:l}}function xc(e,n,t,r){const o=os(e,r.startContainer,r.startOffset),s=os(e,r.endContainer,r.endOffset);if(!o||!s)return null;const l=Array.from(e.childNodes).filter(f=>{var p;return f.nodeType===1&&((p=f.dataset)==null?void 0:p.runId)&&n.indexOf(f.dataset.runId)!==-1});let i=!1;const c=[];let u=null;return l.forEach((f,p)=>{const h=f.dataset.runId,b=t(h);if(!b)return;const g=p<o.childIndex,x=s.charOffset===null?p>=s.childIndex:p>s.childIndex;if(g||x){c.push(b);return}const k=o.charOffset!==null&&p===o.childIndex,y=s.charOffset!==null&&p===s.childIndex;if(b.type!=="text"){i=!0,u===null&&(u=c.length);return}const I=b.value??"";if(k&&y){const w=I.slice(0,o.charOffset)+I.slice(s.charOffset);w&&c.push({...b,value:w}),u=c.length}else if(k){const w=I.slice(0,o.charOffset);w&&c.push({...b,value:w}),u===null&&(u=c.length)}else if(y){const w=I.slice(s.charOffset);w&&c.push({id:L(),type:"text",value:w,marks:b.marks})}}),i?{nextRuns:c,insertionIndex:u??c.length}:null}function kc(e){var s;const n=(s=window.getSelection)==null?void 0:s.call(window);if(!n||!n.isCollapsed)return!1;const t=e.firstChild;if(!t)return!0;if(n.anchorNode===e)return n.anchorOffset===0;let r=t;for(;r&&r.firstChild;)r=r.firstChild;if(n.anchorNode!==r&&n.anchorNode!==t)return!1;const o=r.nodeType===3&&r.textContent===As?1:0;return n.anchorOffset<=o}function yc(e){var s;const n=(s=window.getSelection)==null?void 0:s.call(window);if(!n||!n.isCollapsed)return!1;const t=e.lastChild;if(!t)return!0;if(n.anchorNode===e)return n.anchorOffset>=e.childNodes.length;let r=t;for(;r&&r.lastChild;)r=r.lastChild;if(n.anchorNode!==r&&n.anchorNode!==t)return!1;const o=r.nodeType===3?(r.textContent??"").length:0;return n.anchorOffset>=o}function ss(e,n,t){const r=e.getBlock(n),o=e.getBlock(r==null?void 0:r.parentId);if(!o)return null;const s=o.contentIds.indexOf(n),l=t==="backward"?s-1:s+1;if(l<0||l>=o.contentIds.length)return null;const i=o.contentIds[l];return dt(e,e.getBlock(i))?i:null}function vc({id:e,blockId:n,host:t,inlineRegistry:r,onValueSynced:o}){const s=pn(e);if(!s)return null;if(s.type==="text")return a.jsx(gc,{id:e,host:t,onValueSynced:o});const l=r==null?void 0:r.get(s.type);if(!l)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No inline type registered for "${s.type}" (run: ${e})`),null;const i=l.component;return a.jsx(i,{id:e,blockId:n})}function wc(e,n,t){let r=e.get(t);if(!r){r=document.createElement("span"),r.dataset.runId=t;const o=n.getRun(t);o&&o.type!=="text"&&r.setAttribute("contenteditable","false"),e.set(t,r)}return r}function sn({blockId:e,runIds:n,dir:t="auto",onEnter:r,onBackspaceAtStart:o,onDeleteAtEnd:s,onArrowUp:l,onArrowDown:i,onTab:c,onShiftTab:u,onAutoformat:f}){const p=W(),h=We(),{getSelectedBlockId:b,setSelectedBlockId:g}=rn(),x=d.useRef(null),k=d.useRef(!1),y=d.useRef(new Map);d.useLayoutEffect(()=>{const C=x.current;if(!C)return;const B=new Set(n);for(const[z,U]of y.current)B.has(z)||(U.remove(),y.current.delete(z));let A=null;for(const z of n){const U=y.current.get(z);if(!U)continue;const q=A?A.nextSibling:C.firstChild;q!==U&&C.insertBefore(U,q),A=U}},[n]);const I=d.useCallback(()=>{if(k.current)return;const C=x.current;if(!C)return;const B=n.map(q=>p.getRun(q)).filter(Boolean),{runs:A,changed:z,onlyValueChanges:U}=Fi(C,B);if(z){if(U){if(A.forEach((q,le)=>{q!==B[le]&&p.applyOperation(ce(q.id,{value:q.value}))}),f!=null&&f(A))return}else p.applyOperation(Oe(e,A.length?A:[{id:L(),type:"text",value:"",marks:{}}]));ns(C,A)}},[p,e,n,f]),w=d.useCallback(()=>{ns(x.current,n.map(C=>p.getRun(C)).filter(Boolean))},[p,n]),T=d.useCallback(()=>{k.current=!0},[]),S=d.useCallback(()=>{k.current=!1,I()},[I]),v=d.useCallback(C=>{const A=n.map(z=>p.getRun(z)).filter(Boolean).filter(z=>z.id!==C);p.applyOperation(Oe(e,A.length?A:[{id:L(),type:"text",value:"",marks:{}}]))},[p,e,n]),R=d.useCallback(C=>{b()===C?(p.applyOperation(Z(C)),g(null)):g(C)},[p,b,g]),O=d.useCallback(C=>{var Se,oe,ke,fe;if(k.current)return;if(C.target instanceof Node){const $=C.target.nodeType===1?C.target:C.target.parentElement;if((Se=$==null?void 0:$.closest)!=null&&Se.call($,'[contenteditable="false"]'))return}const B=C.inputType??"",A=B.startsWith("delete"),z=B==="insertText"||B==="insertReplacementText";if(!A&&!z)return;const U=x.current;if(!U)return;const q=(oe=C.getTargetRanges)==null?void 0:oe.call(C),le=(ke=window.getSelection)==null?void 0:ke.call(window),se=(q==null?void 0:q[0])??(le!=null&&le.rangeCount?le.getRangeAt(0):null);if(!se||!U.contains(se.startContainer)||!U.contains(se.endContainer))return;const G=xc(U,n,$=>p.getRun($),se);if(!G)return;C.preventDefault();let{nextRuns:re,insertionIndex:H}=G,Q=null,ee=!1;if(z&&C.data){const $={id:L(),type:"text",value:C.data,marks:{}};re=[...re.slice(0,H),$,...re.slice(H)],Q=$.id,ee=!1}else H>0?(Q=(fe=re[H-1])==null?void 0:fe.id,ee=!1):re.length>0&&(Q=re[0].id,ee=!0);const te=re.length?re:[{id:L(),type:"text",value:"",marks:{}}];p.applyOperation(Oe(e,te));const me=Q??te[0].id;ee?Ut(me):xe(me)},[p,e,n]);d.useEffect(()=>{const C=x.current;if(C)return C.addEventListener("beforeinput",O),()=>C.removeEventListener("beforeinput",O)},[O]);const N=d.useCallback(C=>{if(!k.current){if(C.key==="Enter"&&r){C.preventDefault(),r(C);return}if(C.key==="Backspace"){const B=x.current,A=B&&rs(B,n,p.getRun.bind(p));if(A){C.preventDefault(),v(A);return}const z=B&&ts(B,n,p.getRun.bind(p),!0);if(z){C.preventDefault(),v(z);return}if(B&&kc(B)){if(!Le(p,n)){const q=ss(p,e,"backward");if(q){C.preventDefault(),R(q);return}}C.preventDefault(),o&&o(C)}return}if(C.key==="Delete"){const B=x.current,A=B&&rs(B,n,p.getRun.bind(p));if(A){C.preventDefault(),v(A);return}const z=B&&ts(B,n,p.getRun.bind(p),!1);if(z){C.preventDefault(),v(z);return}if(B&&yc(B)){const U=ss(p,e,"forward");if(U){C.preventDefault(),R(U);return}s&&s(C)}return}if(C.key==="ArrowUp"&&l){C.preventDefault(),l(C);return}if(C.key==="ArrowDown"&&i){C.preventDefault(),i(C);return}C.key==="Tab"&&(C.shiftKey&&u?(C.preventDefault(),u(C)):!C.shiftKey&&c&&(C.preventDefault(),c(C)))}},[r,o,s,l,i,c,u,v,R,n,e,p]);return a.jsxs(a.Fragment,{children:[a.jsx("span",{ref:x,className:"be-editable",dir:t,contentEditable:!0,suppressContentEditableWarning:!0,onInput:I,onCompositionStart:T,onCompositionEnd:S,onKeyDown:N,children:n.map(C=>{const B=wc(y.current,p,C);return Ve.createPortal(a.jsx(vc,{id:C,blockId:e,host:B,inlineRegistry:h,onValueSynced:w},C),B)})}),a.jsx(hc,{containerRef:x,store:p})]})}function Ic(e,n,t){const r=e.getBlock(n),o=r&&e.getBlock(r.parentId);if(!o)return null;const s=o.contentIds.indexOf(n),l=t==="up"?s-1:s+1;return l<0||l>=o.contentIds.length?null:o.contentIds[l]}function oa(e,n,t){let r=n;for(;;){const o=Ic(e,r,t);if(!o)return null;const s=t==="up"?Gt(e,o):Qr(e,o);if(s)return s;r=o}}function Be(e,n,t){const r=oa(e,n,t);r&&xe(r)}function Qr(e,n){var s;const t=e.getBlock(n);if(!t)return null;const r=((s=t.props)==null?void 0:s.titleRunIds)??t.contentIds;if(!r||r.length===0)return null;const o=r[0];return e.getRun(o)?o:Qr(e,o)}function Ce(e,n){const t=Qr(e,n);t&&xe(t)}function Gt(e,n){var s;const t=e.getBlock(n);if(!t)return null;const r=((s=t.props)==null?void 0:s.titleRunIds)??t.contentIds;if(!r||r.length===0)return null;const o=r[r.length-1];return e.getRun(o)?o:Gt(e,o)}function as(e,n){const t=Gt(e,n);t&&xe(t)}function Cc(){var i,c;const e=(i=window.getSelection)==null?void 0:i.call(window);if(!e||e.rangeCount===0)return null;const n=e.getRangeAt(0);if(n.collapsed||n.startContainer!==n.endContainer)return null;const t=n.startContainer,r=t.nodeType===1?t:t.parentElement,o=(c=r==null?void 0:r.closest)==null?void 0:c.call(r,"[data-run-id]");if(!o)return null;const s=o.closest("[data-block-id]");if(!s)return null;const l=t.textContent??"";return{runId:o.getAttribute("data-run-id"),blockId:s.getAttribute("data-block-id"),startOffset:en(l.slice(0,n.startOffset)).length,endOffset:en(l.slice(0,n.endOffset)).length}}function Sc(e,n){var i,c;if((e==null?void 0:e.nodeType)!==1||((i=e.getAttribute)==null?void 0:i.call(e,"contenteditable"))!=="true")return null;const t=e.childNodes;if(t.length===0)return null;const r=n>=t.length,o=t[r?t.length-1:Math.max(0,n)],s=(o==null?void 0:o.nodeType)===1?(c=o.dataset)==null?void 0:c.runId:void 0;if(!s)return null;const l=o.closest("[data-block-id]");return l?{runId:s,blockId:l.getAttribute("data-block-id"),offset:r?en(o.textContent??"").length:0}:null}function at(e,n){var i;const t=Sc(e,n);if(t)return t;let r=(e==null?void 0:e.nodeType)===1?e:e==null?void 0:e.parentElement;const o=(i=r==null?void 0:r.closest)==null?void 0:i.call(r,"[data-run-id]");if(!o)return null;const s=o.closest("[data-block-id]");if(!s)return null;let l=en((e.textContent??"").slice(0,n)).length;if(e===o){l=0;for(let c=0;c<n&&c<o.childNodes.length;c+=1)l+=en(o.childNodes[c].textContent??"").length}return{runId:o.getAttribute("data-run-id"),blockId:s.getAttribute("data-block-id"),offset:l}}function nn(){var n;const e=(n=window.getSelection)==null?void 0:n.call(window);return!e||e.rangeCount===0||!e.isCollapsed?null:at(e.anchorNode,e.anchorOffset)}function Hn(){var r;const e=(r=window.getSelection)==null?void 0:r.call(window);if(!e||e.rangeCount===0||e.isCollapsed)return null;const n=at(e.anchorNode,e.anchorOffset),t=at(e.focusNode,e.focusOffset);return!n||!t||n.blockId!==t.blockId?null:{blockId:n.blockId,startRunId:n.runId,startOffset:n.offset,endRunId:t.runId,endOffset:t.offset}}function Dn(e){var p;const n=(p=window.getSelection)==null?void 0:p.call(window);if(!n||n.rangeCount===0||n.isCollapsed)return null;const t=at(n.anchorNode,n.anchorOffset),r=at(n.focusNode,n.focusOffset);if(!t||!r||t.blockId===r.blockId)return null;const o=e.getBlock(t.blockId),s=o&&e.getBlock(o.parentId);if(!s)return null;const l=s.contentIds,i=l.indexOf(t.blockId),c=l.indexOf(r.blockId);if(i===-1||c===-1)return null;const[u,f]=i<=c?[i,c]:[c,i];return{blockIds:l.slice(u,f+1),startBlockId:t.blockId,startRunId:t.runId,startOffset:t.offset,endBlockId:r.blockId,endRunId:r.runId,endOffset:r.offset}}function Zt(e,n,t){const o=e.getBlock(n).parentId,l=e.getBlock(o).contentIds.indexOf(n)+1,{block:i,runs:c=[],subtreeBlocks:u=[]}=t(o);return e.applyOperation(he(i,o,l,{blocks:[i,...u],runs:c})),i.id}function Ge(e,n,t){const r=Zt(e,n,t);return Ce(e,r),r}function jc(e,n,t){const{block:r,runs:o=[],subtreeBlocks:s=[]}=t(n);return e.applyOperation(he(r,n,0,{blocks:[r,...s],runs:o})),Ce(e,r.id),r.id}function sa(e,n){if(typeof e.performBatch=="function")e.performBatch(n);else for(const t of n)e.applyOperation(t)}function Rc(e,n,t){const r=e.findIndex(u=>u.id===n);if(r===-1)return null;const o=e[r],s=e.slice(0,r),l=e.slice(r+1);if(o.type==="text"){const u=o.value??"",f=u.slice(0,t),p=u.slice(t);f&&p?(s.push({...o,value:f}),l.unshift({...o,id:L(),value:p})):p?l.unshift(o):s.push(o)}else t>0?s.push(o):l.unshift(o);const i=s.length?s:[{id:L(),type:"text",value:"",marks:{}}],c=l.length?l:[{id:L(),type:"text",value:"",marks:{}}];return{leftRuns:i,rightRuns:c}}function Fn(e,n,t,r){const o=e.getBlock(n),s=e.getBlock(o.parentId),l=s.contentIds.indexOf(n)+1;return la(e,n,t,r,{insertParentId:s.id,insertIndex:l,fallback:()=>Ge(e,n,r)})}function aa(e,n,t,r){return la(e,n,t,r,{insertParentId:n,insertIndex:0,fallback:()=>jc(e,n,r)})}function la(e,n,t,r,{insertParentId:o,insertIndex:s,fallback:l}){const i=nn();if(!i||i.blockId!==n)return l();const c=t.map(k=>e.getRun(k)).filter(Boolean),u=Rc(c,i.runId,i.offset);if(!u)return l();const{leftRuns:f,rightRuns:p}=u,{block:h,runs:b=p,subtreeBlocks:g=[]}=r(o,p),x=f.length?f:[{id:L(),type:"text",value:"",marks:{}}];return sa(e,[Oe(n,x),he(h,o,s,{blocks:[h,...g],runs:b})]),Ce(e,h.id),h.id}function Tc(e){var n;return((n=e==null?void 0:e.props)==null?void 0:n.titleRunIds)??(e==null?void 0:e.contentIds)??[]}function Bc(e){var n,t;return!!((n=e==null?void 0:e.props)!=null&&n.titleRunIds)&&(((t=e.contentIds)==null?void 0:t.length)??0)>0}function Ec(e,n,t){const o=e.getBlock(n).parentId,l=e.getBlock(o).contentIds.indexOf(n),{block:i,runs:c=[],subtreeBlocks:u=[]}=t(o);return sa(e,[Z(n),he(i,o,l,{blocks:[i,...u],runs:c})]),Ce(e,i.id),i.id}function Te(e,{blockId:n,runId:t,sliceStart:r,sliceEnd:o},s){const l=e.getRun(t),i=(l==null?void 0:l.value)??"",c=i.slice(0,r)+i.slice(o),u=e.getBlock(n),f=Tc(u);return f.length===1&&f[0]===t&&c===""&&!Bc(u)?Ec(e,n,s):(e.applyOperation(ce(t,{value:c})),Ge(e,n,s))}function J(e,n={}){return function(r,o){const s=L(),l=o!=null&&o.length?o:[{id:L(),type:"text",value:"",marks:{}}];return{block:{id:s,type:e,parentId:r,contentIds:l.map(i=>i.id),props:n},runs:l}}}function Un(e){const n=e.getRootId(),t=e.getBlock(n);if(!t||t.contentIds.length>0)return null;const{block:r,runs:o}=J("paragraph")(n);return e.applyOperation(he(r,n,0,{blocks:[r],runs:o})),r.id}const Nc=new Set(["callout"]),ls=new Set(["paragraph","heading","blockquote"]);function ia(e,n){return e===n||ls.has(e)&&ls.has(n)}function pt(e,n){const t=e.getBlock(n);if(!t)return null;const r=e.getBlock(t.parentId),o=r.contentIds.indexOf(n),s=t.contentIds.length===0||t.contentIds.length===1&&Oc(e,t.contentIds[0]);if(o<=0){if(!s)return null;if(r.contentIds.length>1)return Ln(e,[Z(n)]),e.getBlock(r.id).contentIds[0];if(Nc.has(r.type))return Lc(e,r);if(t.type==="paragraph")return null;const{block:u,runs:f}=J("paragraph")(r.id);return Ln(e,[he(u,r.id,o,{blocks:[u],runs:f}),Z(n)]),u.id}const l=r.contentIds[o-1],i=e.getBlock(l);if(s)return Ln(e,[Z(n)]),l;if(dt(e,i))return Ln(e,[Z(l)]),n;if(!i||!ia(i.type,t.type))return null;const c=[...i.contentIds,...t.contentIds];return Ln(e,[An(l,c),An(n,[]),Z(n)]),l}function Oc(e,n){const t=e.getRun(n);return!t||(t.value??"")===""}function Lc(e,n){const t=e.getBlock(n.parentId);if(!t)return null;const r=t.contentIds.indexOf(n.id),o=r>0?t.contentIds[r-1]:null,s=r!==-1&&r<t.contentIds.length-1?t.contentIds[r+1]:null;Ln(e,[Z(n.id)]);const l=Un(e);return o??s??l}function Ln(e,n){if(typeof e.performBatch=="function")e.performBatch(n);else for(const t of n)e.applyOperation(t)}function Yn(e,n,t,r){if(!n||n===t)return;const o=Gt(e,n);if(o){xe(o);return}r(n),requestAnimationFrame(()=>{var s;(s=document.querySelector(`[data-block-id="${n}"]`))==null||s.focus()})}function tn(e,n){var r,o;if(!n)return"auto";if((r=n.props)!=null&&r.dir)return n.props.dir;const t=e.getBlock(e.getRootId());return((o=t==null?void 0:t.props)==null?void 0:o.dir)??"auto"}function eo(e,n,t,r,o,s){const l=e.getBlock(n),c=e.getBlock(l.parentId).contentIds.indexOf(n),u="titleRunIds"in r,f="titleRunIds"in(l.props??{}),p=s?!s.isLeaf(l.type)&&l.contentIds.length>0:!1,h={id:L(),type:t,parentId:l.parentId,contentIds:[],props:r},b=u?X(h.id,{titleRunIds:o}):An(h.id,o),g=[he(h,l.parentId,c,{blocks:[h],runs:[]}),b];return p&&(!s.isLeaf(t)?l.contentIds.forEach((k,y)=>g.push(Xe(k,h.id,y))):l.contentIds.forEach((k,y)=>g.push(Xe(k,l.parentId,c+1+y)))),f?g.push(X(n,{titleRunIds:[]})):p||g.push(An(n,[])),g.push(Z(n)),{newBlockId:h.id,ops:g}}function Mc(e,n){if(typeof e.performBatch=="function")e.performBatch(n);else for(const t of n)e.applyOperation(t)}const Ac=[{re:/^(#{1,3})[ ]$/,type:"heading",props:e=>({level:e[1].length})},{re:/^[-*][ ]$/,type:"listItem",props:()=>({ordered:!1,titleRunIds:[]})},{re:/^\d+\.[ ]$/,type:"listItem",props:()=>({ordered:!0,titleRunIds:[]})},{re:/^\[\][ ]$/,type:"listItem",props:()=>({ordered:!1,checked:!1,titleRunIds:[]})},{re:/^>[ ]$/,type:"blockquote",props:()=>({})},{re:/^```$/,type:"code",props:()=>({language:"plaintext"})}];function Dc(e,n,t){if(t.length!==1||t[0].type!=="text")return!1;const r=t[0].value??"";for(const o of Ac){const s=o.re.exec(r);if(!s)continue;const l=r.slice(s[0].length),{ops:i}=eo(e,n,o.type,o.props(s),[t[0].id]);return Mc(e,[ce(t[0].id,{value:l}),...i]),Ut(t[0].id),!0}return!1}const Pc=new Set(["callout","toggleHeading"]);function $c({id:e}){const n=W(),t=be(e),{setSelectedBlockId:r}=rn(),o=d.useCallback(()=>{const h=n.getBlock(t==null?void 0:t.parentId),b=Le(n,(t==null?void 0:t.contentIds)??[]),g=!!h&&h.contentIds[h.contentIds.length-1]===e;if(b&&g&&Pc.has(h==null?void 0:h.type)){Ge(n,h.id,J("paragraph"));return}Fn(n,e,(t==null?void 0:t.contentIds)??[],J("paragraph"))},[n,e,t]),s=d.useCallback(()=>{var k,y;const h=n.getBlock(t==null?void 0:t.parentId),b=Le(n,(t==null?void 0:t.contentIds)??[]),g=((k=h==null?void 0:h.contentIds)==null?void 0:k.length)===1&&h.contentIds[0]===e;if(b&&g&&(h==null?void 0:h.type)==="toggleHeading"){const I=((y=h.props)==null?void 0:y.titleRunIds)??[],w=I[I.length-1];w&&xe(w);return}const x=pt(n,e);Yn(n,x,e,r)},[n,e,t,r]),l=d.useCallback(()=>Be(n,e,"up"),[n,e]),i=d.useCallback(()=>Be(n,e,"down"),[n,e]),c=d.useCallback(h=>Dc(n,e,h),[n,e]),u=ve("be-paragraph",t);if(!t)return null;const f=Le(n,t.contentIds),p=tn(n,t);return a.jsx("div",{className:u,"data-block-id":e,"data-empty":f?"":void 0,"data-placeholder":"Type '/' for commands",dir:p,children:a.jsx(sn,{blockId:e,runIds:t.contentIds,dir:p,onEnter:o,onBackspaceAtStart:s,onArrowUp:l,onArrowDown:i,onAutoformat:c})})}function vn(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Re(e){return vn(e).replace(/"/g,""")}function an(e,n){var o,s;if(!e)return"";if(e.type!=="text"){const l=(o=n==null?void 0:n.inlineRegistry)==null?void 0:o.get(e.type);return l?l.toHTML(e,n):vn(e.value??"")}const t=e.marks??{};let r=vn(e.value??"");if(t.code&&(r=`<code>${r}</code>`),t.bold&&(r=`<strong>${r}</strong>`),t.italic&&(r=`<em>${r}</em>`),t.underline&&(r=`<u>${r}</u>`),t.strike&&(r=`<s>${r}</s>`),t.subscript&&(r=`<sub>${r}</sub>`),t.superscript&&(r=`<sup>${r}</sup>`),t.color&&(r=`<span style="color:${Re(t.color)}">${r}</span>`),t.highlight&&(r=`<span style="background-color:${Re(t.highlight)}">${r}</span>`),(s=t.link)!=null&&s.href){const l=t.link.target==="_blank"?' target="_blank" rel="noopener noreferrer"':"";r=`<a href="${Re(t.link.href)}"${l}>${r}</a>`}return r}function xr(e,n){return(e??[]).map(t=>an(t,n)).join("")}function fn(e,n){var t;if(!e)return"";if(e.type!=="text"){const r=(t=n==null?void 0:n.inlineRegistry)==null?void 0:t.get(e.type);return r?r.toPlainText(e,n):e.value??""}return e.value??""}const _c={STRONG:"bold",B:"bold",EM:"italic",I:"italic",U:"underline",S:"strike",STRIKE:"strike",DEL:"strike",CODE:"code",SUB:"subscript",SUP:"superscript"};function $e(e,n,t={}){const r=[],o=(s,l)=>{var u,f;if(s.nodeType===3){const p=s.textContent;p&&r.push({id:L(),type:"text",value:p,marks:{...l}});return}if(s.nodeType!==1)return;if(n!=null&&n.inlineRegistry)for(const p of n.inlineRegistry.listHtmlMatchers()){const h=p.fromHTML(s,n);if(h){r.push(h);return}}let i=l;const c=_c[s.tagName];c&&(i={...i,[c]:!0}),s.tagName==="A"&&s.getAttribute("href")&&(i={...i,link:{href:s.getAttribute("href"),target:s.getAttribute("target")==="_blank"?"_blank":"_self"}}),(u=s.style)!=null&&u.color&&(i={...i,color:s.style.color}),(f=s.style)!=null&&f.backgroundColor&&(i={...i,highlight:s.style.backgroundColor});for(const p of s.childNodes)o(p,i)};return o(e,t),r.length?r:[{id:L(),type:"text",value:"",marks:{}}]}function zc(e,n){return`<p>${e.contentIds.map(r=>n.store.getRun(r)).map(r=>an(r,n)).join("")}</p>`}function Hc(e,n){return e.contentIds.map(t=>fn(n.store.getRun(t),n)).join("")}function Fc(e,n){if(e.tagName!=="P")return null;const t=$e(e,n);return{block:{id:L(),type:"paragraph",parentId:null,contentIds:t.map(o=>o.id),props:{}},runs:t}}const ca={component:$c,isLeaf:!0,defaultProps:{},toHTML:zc,toPlainText:Hc,fromHTML:Fc,slashCommand:{label:"Text",icon:Xr,keywords:["paragraph","text","p"],run:(e,n)=>Te(e,n,J("paragraph"))}};function Uc({id:e}){var b;const n=W(),t=be(e),{setSelectedBlockId:r}=rn(),o=d.useCallback(()=>{Fn(n,e,(t==null?void 0:t.contentIds)??[],J("paragraph"))},[n,e,t]),s=d.useCallback(()=>{const g=pt(n,e);Yn(n,g,e,r)},[n,e,r]),l=d.useCallback(()=>Be(n,e,"up"),[n,e]),i=d.useCallback(()=>Be(n,e,"down"),[n,e]),c=((b=t==null?void 0:t.props)==null?void 0:b.level)??3,u=ve(`be-heading be-heading-${c}`,t);if(!t)return null;const f=`h${c}`,p=Le(n,t.contentIds),h=tn(n,t);return a.jsx(f,{className:u,"data-block-id":e,"data-empty":p?"":void 0,"data-placeholder":`Heading ${c}`,dir:h,children:a.jsx(sn,{blockId:e,runIds:t.contentIds,dir:h,onEnter:o,onBackspaceAtStart:s,onArrowUp:l,onArrowDown:i})})}const kr={1:Gs,2:Zs,3:Js},Yc={H1:1,H2:2,H3:3};function Kc(e,n){var o;const t=((o=e.props)==null?void 0:o.level)??3,r=e.contentIds.map(s=>n.store.getRun(s));return`<h${t}>${r.map(s=>an(s,n)).join("")}</h${t}>`}function Vc(e,n){return e.contentIds.map(t=>fn(n.store.getRun(t),n)).join("")}function Xc(e,n){const t=Yc[e.tagName];if(!t)return null;const r=$e(e,n);return{block:{id:L(),type:"heading",parentId:null,contentIds:r.map(s=>s.id),props:{level:t}},runs:r}}const ua={component:Uc,isLeaf:!0,defaultProps:{level:3},toHTML:Kc,toPlainText:Vc,fromHTML:Xc,slashCommands:[{label:"Heading 1",icon:kr[1],keywords:["heading","h1","title"],run:(e,n)=>Te(e,n,J("heading",{level:1}))},{label:"Heading 2",icon:kr[2],keywords:["heading","h2","subtitle"],run:(e,n)=>Te(e,n,J("heading",{level:2}))},{label:"Heading 3",icon:kr[3],keywords:["heading","h3","title"],run:(e,n)=>Te(e,n,J("heading",{level:3}))}]},qc=[];function no(e){const n=W(),t=d.useCallback(o=>n.subscribe(e,o),[n,e]),r=d.useCallback(()=>{const o=n.getBlock(e);return o?o.contentIds:qc},[n,e]);return d.useSyncExternalStore(t,r)}class da extends d.Component{constructor(){super(...arguments);Wo(this,"state",{hasError:!1,nonce:0})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t,r){var o,s;process.env.NODE_ENV!=="production"&&console.error("[block-editor] a block failed to render; recovering by remounting it:",t,r),(s=(o=this.props).onError)==null||s.call(o,t,r),queueMicrotask(()=>this.setState(l=>({hasError:!1,nonce:l.nonce+1})))}render(){return this.state.hasError?null:a.jsx(d.Fragment,{children:this.props.children},this.state.nonce)}}const to=d.memo(function({id:n}){const t=be(n),r=dn();if(!t)return null;const o=r.get(t.type);if(!o)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No block type registered for "${t.type}" (id: ${n})`),null;const s=o.component;return a.jsx(da,{children:a.jsx(s,{id:n})})});function Pe(e,n,t){d.useEffect(()=>{if(!n)return;const r=Array.isArray(e)?e:[e],o=l=>{r.some(c=>c.current&&c.current.contains(l.target))||t()},s=l=>{l.key==="Escape"&&t()};return document.addEventListener("mousedown",o),document.addEventListener("keydown",s),()=>{document.removeEventListener("mousedown",o),document.removeEventListener("keydown",s)}},[n,t,e])}function Jt(e,n,t,r){const o=d.useRef(!1),s=d.useRef(!1);d.useEffect(()=>{var f,p;if(!n){s.current=!1,o.current&&(o.current=!1,(p=(f=r==null?void 0:r.current)==null?void 0:f.focus)==null||p.call(f));return}o.current=!0;const l=e.current;if(!l)return;const i=()=>Array.from(l.querySelectorAll('[role="menuitem"]')),c=h=>{var x;const b=i();if(b.length===0)return;const g=(h%b.length+b.length)%b.length;(x=b[g])==null||x.focus()};s.current||(s.current=!0,c(0));const u=h=>{if(h.key==="Escape"){h.preventDefault(),t();return}const b=i(),g=b.indexOf(document.activeElement);g!==-1&&(h.key==="ArrowDown"?(h.preventDefault(),c(g+1)):h.key==="ArrowUp"?(h.preventDefault(),c(g-1)):h.key==="Home"?(h.preventDefault(),c(0)):h.key==="End"&&(h.preventDefault(),c(b.length-1)))};return l.addEventListener("keydown",u),()=>l.removeEventListener("keydown",u)})}const is="be-live-region";function Wc(){if(typeof document>"u")return null;let e=document.getElementById(is);return e||(e=document.createElement("div"),e.id=is,e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.setAttribute("aria-atomic","true"),Object.assign(e.style,{position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:"0",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:"0"}),document.body.appendChild(e),e)}function ge(e){const n=Wc();n&&(n.textContent="",setTimeout(()=>{n.textContent=e},0))}const Kn="💡",pa="gray";function Gc({icon:e=Kn,color:n=pa}={}){return function(r){const o=L(),{block:s,runs:l}=J("paragraph")(o);return{block:{id:o,type:"callout",parentId:r,contentIds:[s.id],props:{icon:e,color:n}},runs:l,subtreeBlocks:[s]}}}const fa=[{type:"paragraph",props:{},label:"Text",icon:Xr},{type:"heading",props:{level:1},label:"Heading 1",icon:Gs},{type:"heading",props:{level:2},label:"Heading 2",icon:Zs},{type:"heading",props:{level:3},label:"Heading 3",icon:Js},{type:"listItem",props:{ordered:!1,titleRunIds:[]},label:"Bulleted list",icon:na},{type:"listItem",props:{ordered:!0,titleRunIds:[]},label:"Numbered list",icon:ta},{type:"listItem",props:{ordered:!1,checked:!1,titleRunIds:[]},label:"To-do list",icon:Gr},{type:"listItem",props:{ordered:!1,collapsed:!1,titleRunIds:[]},label:"Toggle list",icon:yn},{type:"toggleHeading",props:{level:2,collapsed:!1,titleRunIds:[]},label:"Toggle heading",icon:yn},{type:"blockquote",props:{},label:"Quote",icon:Qs},{type:"callout",props:{icon:Kn},label:"Callout",icon:ea},{type:"code",props:{language:"plaintext"},label:"Code",icon:Wr}],Zc=new Set(fa.map(e=>e.type));function ro(e){return Zc.has(e)}function Jc(e){var n;return((n=e==null?void 0:e.props)==null?void 0:n.titleRunIds)??(e==null?void 0:e.contentIds)??[]}function ha(e,n,t,r){const o=e.getBlock(t),s=Jc(o),l=[];if(r.type==="code")for(const f of s){const p=e.getRun(f);p!=null&&p.marks&&Object.keys(p.marks).length>0&&l.push(ce(f,{marks:{}}))}const i={...r.props},{ops:c,newBlockId:u}=eo(e,t,r.type,i,s,n);return{ops:[...l,...c],newBlockId:u}}function ba({onSelect:e,onClose:n,containerRef:t,menuClassName:r="be-block-gutter-menu",itemClassName:o="be-block-gutter-menu-item"}){const[s,l]=d.useState(!1),[i,c]=d.useState(null),u=d.useRef(null),f=d.useRef(null),p=d.useCallback(I=>{f.current=I,t&&(t.current=I)},[t]),h=d.useCallback(()=>{l(!1),n==null||n()},[n]);Pe([u,f],s,h),Jt(f,s,h,u);const b=Kt(f,s,i==null?void 0:i.top,i?i.right+4:null),g=d.useCallback(()=>{var I;c(((I=u.current)==null?void 0:I.getBoundingClientRect())??null),l(!0)},[]),x=d.useCallback(I=>{e(I),h()},[e,h]),k=d.useCallback(I=>{I.key==="ArrowRight"&&!s&&(I.preventDefault(),g())},[s,g]),y=d.useCallback(I=>{I.key==="ArrowLeft"&&(I.preventDefault(),h())},[h]);return a.jsxs(a.Fragment,{children:[a.jsxs("button",{ref:u,type:"button",role:"menuitem",className:o,"aria-haspopup":"menu","aria-expanded":s,onClick:()=>s?h():g(),onKeyDown:k,children:[a.jsx(yn,{size:15})," Turn into"]}),s&&b&&Ve.createPortal(a.jsx("div",{ref:p,role:"menu","aria-label":"Turn into",className:r,style:{position:"fixed",top:b.top,left:b.left},onKeyDown:y,children:fa.map((I,w)=>{const T=I.icon;return a.jsxs("button",{type:"button",role:"menuitem",className:o,onClick:()=>x(I),children:[a.jsx(T,{size:15})," ",I.label]},`${I.type}-${w}`)})}),document.body)]})}function ft(e,n,t,r){const o={store:e,registry:n,inlineRegistry:r};return{html:Qc(e,n,t,o),text:t.map(s=>{const l=e.getBlock(s);return n.get(l.type).toPlainText(l,o)}).join(`
|
|
2514
|
-
`),json:JSON.stringify({version:1,blocks:t.map(s=>oo(e,s))})}}function Qc(e,n,t,r){let o="",s=0;for(;s<t.length;){const l=e.getBlock(t[s]);if(l.type==="listItem"){const i=!!l.props.ordered;let c="",u=s;for(;u<t.length;){const p=e.getBlock(t[u]);if(p.type!=="listItem"||!!p.props.ordered!==i)break;c+=n.get("listItem").toHTML(p,r),u+=1}const f=i?"ol":"ul";o+=`<${f}>${c}</${f}>`,s=u}else if(l.type==="blockquote"){let i="",c=s;for(;c<t.length;){const u=e.getBlock(t[c]);if(u.type!=="blockquote")break;i+=n.get("blockquote").toHTML(u,r),c+=1}o+=`<blockquote>${i}</blockquote>`,s=c}else o+=n.get(l.type).toHTML(l,r),s+=1}return o}function oo(e,n){const t=[],r=[],o=s=>{var c;const l=e.getRun(s);if(l){r.push(l);return}const i=e.getBlock(s);if(i){t.push(i);for(const u of i.contentIds)o(u);for(const u of((c=i.props)==null?void 0:c.titleRunIds)??[])o(u)}};return o(n),{rootId:n,blocks:t,runs:r}}function so({rootId:e,blocks:n,runs:t}){const r=new Map;for(const c of n)r.set(c.id,L());for(const c of t)r.set(c.id,L());const o=c=>r.get(c)??c,s=n.map(c=>{var u;return{...c,id:o(c.id),parentId:c.parentId?o(c.parentId):c.parentId,contentIds:c.contentIds.map(o),props:{...c.props,...(u=c.props)!=null&&u.titleRunIds?{titleRunIds:c.props.titleRunIds.map(o)}:{}}}}),l=t.map(c=>({...c,id:o(c.id)})),i=o(e);return{block:s.find(c=>c.id===i),runs:l,subtreeBlocks:s.filter(c=>c.id!==i)}}function ao(e,n){const t=e.getBlock(n);if(!t)return null;const r=e.getBlock(t.parentId),o=r.contentIds.indexOf(n),s=oo(e,n),{block:l,runs:i,subtreeBlocks:c}=so(s);return e.applyOperation(he(l,r.id,o+1,{blocks:[l,...c],runs:i})),Ce(e,l.id),l.id}function lo(e,n){const t=e.getBlock(n),r=t&&e.getBlock(t.parentId);if(!r)return!1;const o=r.contentIds.indexOf(n);return o<=0?!1:(e.applyOperation(Xe(n,r.id,o-1)),!0)}function io(e,n){const t=e.getBlock(n),r=t&&e.getBlock(t.parentId);if(!r)return!1;const o=r.contentIds.indexOf(n);return o===-1||o>=r.contentIds.length-1?!1:(e.applyOperation(Xe(n,r.id,o+1)),!0)}function Qt(e,n){const t=e.getBlock(n);if(!t)return null;const r=e.getBlock(t.parentId),o=r.contentIds.indexOf(n),s=o>0?r.contentIds[o-1]:null,l=o!==-1&&o<r.contentIds.length-1?r.contentIds[o+1]:null;e.applyOperation(Z(n));const i=Un(e),c=s??l??i;return c&&Ce(e,c),c??null}function eu(e,n){if(typeof e.performBatch=="function")e.performBatch(n);else for(const t of n)e.applyOperation(t)}function ma({id:e}){var B;const n=W(),t=dn(),r=be(e),[o,s]=d.useState(!1),[l,i]=d.useState(null),c=d.useRef(null),u=d.useRef(null),f=d.useRef(null),p=d.useMemo(()=>[c,u,f],[]),[h]=ut(),b=h.includes(e),g=d.useCallback(()=>s(!1),[]);Pe(p,o,g),Jt(u,o,g,c);const x=d.useCallback(()=>{var A;i(((A=c.current)==null?void 0:A.getBoundingClientRect())??null),s(!0)},[]),k=Kt(u,o,(l==null?void 0:l.bottom)!=null?l.bottom+4:null,l==null?void 0:l.left),y=d.useCallback(()=>{Ge(n,e,J("paragraph"))},[n,e]),I=d.useCallback(()=>{ao(n,e),ge("Block duplicated"),g()},[n,e,g]),w=d.useCallback(()=>{lo(n,e)&&ge("Block moved up"),g()},[n,e,g]),T=d.useCallback(()=>{io(n,e)&&ge("Block moved down"),g()},[n,e,g]),S=d.useCallback(()=>{Qt(n,e),ge("Block deleted"),g()},[n,e,g]),v=!!((B=r==null?void 0:r.props)!=null&&B.hidden),R=d.useCallback(()=>{n.applyOperation(X(e,{hidden:!v})),ge(v?"Block shown in preview":"Block hidden in preview"),g()},[n,e,v,g]),O=tn(n,r)==="rtl",N=d.useCallback(()=>{n.applyOperation(X(e,{dir:O?"ltr":"rtl"})),ge(O?"Block set to left-to-right":"Block set to right-to-left"),g()},[n,e,O,g]),C=d.useCallback(A=>{const{ops:z}=ha(n,t,e,A);eu(n,z),ge(`Turned into ${A.label}`),g()},[n,t,e,g]);return r?a.jsxs("div",{className:`be-block-row${v?" be-block-row-hidden":""}${b?" be-block-row-range-selected":""}`,"data-block-row-id":e,dir:tn(n,r),children:[a.jsxs("div",{className:`be-block-gutter${o?" be-block-gutter-active":""}`,contentEditable:!1,children:[a.jsx("button",{type:"button",className:"be-block-gutter-btn",onClick:y,"aria-label":"Add block below",children:a.jsx(Kr,{size:16})}),a.jsx("button",{ref:c,type:"button",className:"be-block-gutter-btn","aria-label":"More options","aria-haspopup":"menu","aria-expanded":o,onClick:()=>o?g():x(),children:a.jsx(Wi,{size:16})})]}),a.jsx("div",{className:"be-block-row-content",children:a.jsx(to,{id:e})}),o&&k&&Ve.createPortal(a.jsxs("div",{ref:u,role:"menu","aria-label":"Block options",className:"be-block-gutter-menu",style:{position:"fixed",top:k.top,left:k.left},children:[a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:I,children:[a.jsx(Vr,{size:15})," Duplicate"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:w,children:[a.jsx(qt,{size:15})," Move up"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:T,children:[a.jsx(Wt,{size:15})," Move down"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:R,children:[v?a.jsx(Zr,{size:15}):a.jsx(Jr,{size:15}),v?"Show in preview":"Hide in preview"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:N,children:[O?a.jsx(Vs,{size:15}):a.jsx(Xs,{size:15}),O?"Switch to left-to-right":"Switch to right-to-left"]}),ro(r.type)&&a.jsx(ba,{onSelect:C,onClose:()=>{},containerRef:f}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item be-block-gutter-menu-item-danger",onClick:S,children:[a.jsx(Xt,{size:15})," Delete"]})]}),document.body)]}):null}function hn({parentId:e,isTopLevel:n=!1}){const t=no(e),r=W(),[o]=Ur(),s=o?t.filter(l=>{var i,c;return!((c=(i=r.getBlock(l))==null?void 0:i.props)!=null&&c.hidden)}):t;return n&&!o?s.map(l=>a.jsx(ma,{id:l},l)):s.map(l=>a.jsx(to,{id:l},l))}const nu=97,tu=[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]];function ru(e){let n="";for(;e>0;)e-=1,n=String.fromCharCode(nu+e%26)+n,e=Math.floor(e/26);return n}function ou(e){let n="",t=e;for(const[r,o]of tu)for(;t>=r;)n+=o,t-=r;return n}function su(e){var n,t;return(e==null?void 0:e.type)==="listItem"&&((n=e.props)==null?void 0:n.checked)===void 0&&((t=e.props)==null?void 0:t.collapsed)===void 0}function cs(e,n){let t=0,r=n;for(;r;){const o=e.getBlock(r.parentId);if(!o||o.type!=="listItem")break;t+=1,r=o}return t}function au(e,n,t){const r=t.indexOf(n.id);let o=1;for(let s=r-1;s>=0;s-=1){const l=e.getBlock(t[s]);if(!su(l)||!l.props.ordered)break;o+=1}return o}function lu(e,n){const t=(e%3+3)%3;return t===0?`${n}.`:t===1?`${ru(n)}.`:`${ou(n)}.`}const iu=["•","◦","▪"];function cu(e){const n=(e%3+3)%3;return iu[n]}function rt({ordered:e=!1,checked:n,collapsed:t}={}){return function(o,s){const l=L(),i=s!=null&&s.length?s:[{id:L(),type:"text",value:"",marks:{}}],c={ordered:e,titleRunIds:i.map(h=>h.id)};n!==void 0&&(c.checked=n);let u=[],f=[],p=i;if(t!==void 0){c.collapsed=t;const{block:h,runs:b}=J("paragraph")(l);u=[h.id],f=[h],p=[...i,...b]}return{block:{id:l,type:"listItem",parentId:o,contentIds:u,props:c},runs:p,subtreeBlocks:f}}}function uu(e,n){const t=e.getBlock(n),r=e.getBlock(t.parentId),o=r.contentIds.indexOf(n),s=o>0?r.contentIds[o-1]:null,l=s?e.getBlock(s):null;if(!l||l.type!=="listItem"){Be(e,n,"down");return}e.applyOperation(Xe(n,s,l.contentIds.length)),Ce(e,n)}function Tr(e,n){const t=e.getBlock(n),r=e.getBlock(t.parentId);if(!r||r.type!=="listItem")return;const o=r.parentId,l=e.getBlock(o).contentIds.indexOf(r.id);e.applyOperation(Xe(n,o,l+1)),Ce(e,n)}function Zn(e,n){if(typeof e.performBatch=="function")e.performBatch(n);else for(const t of n)e.applyOperation(t)}function ga(e,n){var t;return n.length===0||n.length===1&&(((t=e.getRun(n[0]))==null?void 0:t.value)??"")===""}function du(e,n){const t=n.contentIds??[];if(t.length===0)return!0;if(t.length>1)return!1;const r=e.getBlock(t[0]);return!!r&&r.type==="paragraph"&&Le(e,r.contentIds)}function pu(e,n){const t=e.getBlock(n);if(!t)return null;const r=e.getBlock(t.parentId),o=r.contentIds.indexOf(n),s=t.props.titleRunIds??[],i=ga(e,s)&&du(e,t);if(o>0){const f=r.contentIds[o-1],p=e.getBlock(f);if(i)return Zn(e,[Z(n)]),{focusBlockId:f,needsRefocus:!0};if(dt(e,p))return Zn(e,[Z(f)]),{focusBlockId:n,needsRefocus:!1};if((p==null?void 0:p.type)==="listItem"&&t.contentIds.length===0){const h=[...p.props.titleRunIds??[],...s];return Zn(e,[X(f,{titleRunIds:h}),X(n,{titleRunIds:[]}),Z(n)]),{focusBlockId:f,needsRefocus:!0}}return null}if(r.type==="listItem")return Tr(e,n),{focusBlockId:n,needsRefocus:!0};if(!i)return null;if(r.contentIds.length>1)return Zn(e,[Z(n)]),{focusBlockId:e.getBlock(r.id).contentIds[0],needsRefocus:!0};const{block:c,runs:u}=J("paragraph")(r.id);return Zn(e,[he(c,r.id,o,{blocks:[c],runs:u}),Z(n)]),{focusBlockId:c.id,needsRefocus:!0}}function fu(e,n){if(typeof e.performBatch=="function")e.performBatch(n);else for(const t of n)e.applyOperation(t)}function hu(e,n){const r=e.getBlock(n).parentId,s=e.getBlock(r).contentIds.indexOf(n),{block:l,runs:i}=J("paragraph")(r);return fu(e,[he(l,r,s,{blocks:[l],runs:i}),X(n,{titleRunIds:[]}),Z(n)]),Ce(e,l.id),l.id}function bu(e,n){if(typeof e.performBatch=="function")e.performBatch(n);else for(const t of n)e.applyOperation(t)}function mu({id:e}){var R,O;const n=W(),t=be(e),{setSelectedBlockId:r}=rn(),o=no(t==null?void 0:t.parentId),s=d.useCallback(()=>{var le,se,G,re,H;const N=((le=t==null?void 0:t.props)==null?void 0:le.titleRunIds)??[],C=n.getBlock(t==null?void 0:t.parentId),B=ga(n,N);if(B&&(C==null?void 0:C.type)==="listItem"){Tr(n,e);return}const A=(((se=t==null?void 0:t.contentIds)==null?void 0:se.length)??0)>0;if(B&&(C==null?void 0:C.type)!=="listItem"&&!A){hu(n,e);return}const z=((G=t==null?void 0:t.props)==null?void 0:G.checked)!==void 0,U=((re=t==null?void 0:t.props)==null?void 0:re.collapsed)!==void 0,q=rt({ordered:(H=t==null?void 0:t.props)==null?void 0:H.ordered,checked:z?!1:void 0,collapsed:U?!1:void 0});A&&!U?aa(n,e,N,q):Fn(n,e,N,q)},[n,e,t]),l=d.useCallback(()=>uu(n,e),[n,e]),i=d.useCallback(()=>Tr(n,e),[n,e]),c=d.useCallback(()=>{const N=pu(n,e);!N||!N.needsRefocus||Yn(n,N.focusBlockId,e,r)},[n,e,r]),u=d.useCallback(()=>Be(n,e,"up"),[n,e]),f=d.useCallback(()=>Be(n,e,"down"),[n,e]),p=d.useCallback(()=>{var N;n.applyOperation(X(e,{checked:!((N=t==null?void 0:t.props)!=null&&N.checked)}))},[n,e,(R=t==null?void 0:t.props)==null?void 0:R.checked]),h=d.useCallback(()=>{var C,B;if(!((((C=t==null?void 0:t.contentIds)==null?void 0:C.length)??0)>0)){const{block:A,runs:z}=J("paragraph")(e);bu(n,[he(A,e,0,{blocks:[A],runs:z}),X(e,{collapsed:!1})]),xe(A.contentIds[0]);return}n.applyOperation(X(e,{collapsed:!((B=t==null?void 0:t.props)!=null&&B.collapsed)}))},[n,e,t==null?void 0:t.contentIds,(O=t==null?void 0:t.props)==null?void 0:O.collapsed]),b=ve("be-list-item",t);if(!t)return null;const{ordered:g,checked:x,collapsed:k,titleRunIds:y=[]}=t.props,I=x!==void 0,w=!I&&k!==void 0,T=t.contentIds.length>0,S=y.map(N=>n.getRun(N)).filter(N=>(N==null?void 0:N.type)==="text").map(N=>N.value).join("").trim(),v=tn(n,t);return a.jsxs("div",{className:b,"data-block-id":e,dir:v,children:[a.jsxs("div",{className:"be-list-item-row",children:[I?a.jsx("input",{type:"checkbox",className:"be-list-checkbox",checked:!!x,onChange:p,"aria-label":S||"To-do item"}):w?a.jsx("button",{type:"button",className:"be-list-toggle-marker",onClick:h,"aria-expanded":!k,"aria-label":T?k?"Expand toggle":"Collapse toggle":"Add content to toggle",children:k?a.jsx(yn,{}):a.jsx(Vt,{})}):a.jsx("span",{className:"be-list-marker","aria-hidden":"true",children:g?lu(cs(n,t),au(n,t,o)):cu(cs(n,t))}),a.jsx("div",{className:"be-list-item-title","data-empty":Le(n,y)?"":void 0,"data-placeholder":I?"To-do":w?"Toggle":"List item",style:x?{textDecoration:"line-through",opacity:.6}:void 0,children:a.jsx(sn,{blockId:e,runIds:y,dir:v,onEnter:s,onTab:l,onShiftTab:i,onBackspaceAtStart:c,onArrowUp:u,onArrowDown:f})})]}),(!w||!k)&&a.jsx("div",{className:"be-list-item-children",children:a.jsx(hn,{parentId:e})})]})}function gu(e,n){const{titleRunIds:t=[],ordered:r}=e.props,o=t.map(i=>an(n.store.getRun(i),n)).join(""),s=e.contentIds.map(i=>n.registry.get(n.store.getBlock(i).type).toHTML(n.store.getBlock(i),n)).join(""),l=s?`<${r?"ol":"ul"}>${s}</${r?"ol":"ul"}>`:"";return`<li>${o}${l}</li>`}function xu(e,n){const{titleRunIds:t=[]}=e.props;return t.map(r=>fn(n.store.getRun(r),n)).join("")}function xa(e,n){const t=[],r=[];for(const p of e.childNodes)p.nodeType===1&&(p.tagName==="UL"||p.tagName==="OL")?r.push(p):t.push(p);const o=e.ownerDocument.createElement("span");for(const p of t)o.appendChild(p.cloneNode(!0));const s=$e(o,n),l=L(),i=[...s],c=[],u=[];for(const p of r){const h=p.tagName==="OL";for(const b of p.children){if(b.tagName!=="LI")continue;const g=xa(b,n);g.block.parentId=l,g.block.props.ordered=h,c.push(g.block,...g.childBlocks),i.push(...g.runs),u.push(g.block.id)}}return{block:{id:l,type:"listItem",parentId:null,contentIds:u,props:{ordered:!1,titleRunIds:s.map(p=>p.id)}},runs:i,childBlocks:c}}function ku(e,n){if(e.tagName!=="LI")return null;const{block:t,runs:r,childBlocks:o}=xa(e,n);return{block:t,runs:r,subtreeBlocks:o}}const ka={component:mu,isLeaf:!1,defaultProps:{ordered:!1,titleRunIds:[]},toHTML:gu,toPlainText:xu,fromHTML:ku,slashCommands:[{label:"Bulleted list",icon:na,keywords:["list","bullet","ul"],run:(e,n)=>Te(e,n,rt({ordered:!1}))},{label:"Numbered list",icon:ta,keywords:["list","number","ordered","ol"],run:(e,n)=>Te(e,n,rt({ordered:!0}))},{label:"To-do list",icon:Gr,keywords:["todo","checkbox","task","checklist"],run:(e,n)=>Te(e,n,rt({ordered:!1,checked:!1}))},{label:"Toggle list",icon:yn,keywords:["toggle","collapse","expand","dropdown","accordion"],run:(e,n)=>Te(e,n,rt({ordered:!1,collapsed:!1}))}]},ya=["text","date","checkbox","select"],er="text",nr=160,Pt=80;function yu(e){return`Column ${e+1}`}function co(e){return Array.from({length:e},(n,t)=>({id:L(),label:yu(t),type:er,width:nr}))}function De(e,n){var r;const t=(r=e.props)==null?void 0:r.columns;return!Array.isArray(t)||t.length!==n?co(n):t.map(o=>{const s=o.type??er,l=o.width??nr;return s===o.type&&l===o.width?o:{...o,type:s,width:l}})}function va(e){switch(e){case"date":return{id:L(),type:"date",value:"",marks:{},data:{isoDate:""}};case"checkbox":return{id:L(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}};case"select":return{id:L(),type:"tableSelect",value:"",marks:{},data:{selectedValue:"",selectedLabel:""}};default:return{id:L(),type:"text",value:"",marks:{}}}}function tr(e,n){const t=va(n==null?void 0:n.type);return{block:{id:L(),type:"tableCell",parentId:e,contentIds:[t.id],props:{}},run:t}}function wa(e,n,t){if(e.type===n)return e;let r;if(e.type==="text")r=e.value??"";else{const o=t==null?void 0:t.get(e.type);r=o!=null&&o.toPlainText?o.toPlainText(e):""}if(n==="date"){const o=r?new Date(r):null,s=o&&!Number.isNaN(o.getTime())?o.toISOString().slice(0,10):"";return{id:L(),type:"date",value:"",marks:{},data:{isoDate:s}}}return n==="checkbox"?{id:L(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:r}}:{id:L(),type:"text",value:r,marks:{}}}function wn(e,n){if(typeof e.performBatch=="function")e.performBatch(n);else for(const t of n)e.applyOperation(t)}function Ia(e,n){const r=e.getBlock(n.parentId).contentIds.indexOf(n.id);wn(e,[Z(n.id)]);const o=Un(e);if(o)return Ce(e,o),null;const s=e.getBlock(n.parentId),l=s.contentIds[r]??s.contentIds[r-1];return l&&Ce(e,l),null}function uo(e,n){const t=e.getBlock(n),r=e.getBlock(t.parentId),o=r.contentIds.indexOf(n),s=De(r,t.contentIds.length),l=L(),i=[],c=[],u=[];for(const p of s){const h=tr(l,p);i.push(h.block),c.push(h.run),u.push(h.block.id)}const f={id:l,type:"tableRow",parentId:r.id,contentIds:u,props:{}};return e.applyOperation(he(f,r.id,o+1,{blocks:[f,...i],runs:c})),Ce(e,l),l}function Ca(e,n){const t=e.getBlock(n),r=e.getBlock(t.parentId);if(r.contentIds.length<=1)return Ia(e,r);const o=r.contentIds.indexOf(n);wn(e,[Z(n)]);const s=e.getBlock(r.id),l=Math.min(o,s.contentIds.length-1),i=s.contentIds[l];return i&&Ce(e,i),i??null}function $t(e,n,t){const r=e.getBlock(n),o=De(r,r.contentIds[0]?e.getBlock(r.contentIds[0]).contentIds.length:0),s={id:L(),label:"New Column",type:er,width:nr},l=[];let i=null;for(const u of r.contentIds){const f=tr(u,s);i===null&&(i=f.block.id),l.push(he(f.block,u,t+1,{blocks:[f.block],runs:[f.run]}))}const c=[...o];return c.splice(t+1,0,s),l.push(X(n,{columns:c})),wn(e,l),i&&Ce(e,i),i}function Sa(e,n,t){const r=e.getBlock(n),o=e.getBlock(r.contentIds[0]);if(!o||o.contentIds.length<=1)return Ia(e,r);const s=De(r,o.contentIds.length),l=r.contentIds.map(p=>{const h=e.getBlock(p);return Z(h.contentIds[t])}),i=s.filter((p,h)=>h!==t);l.push(X(n,{columns:i})),wn(e,l);const c=e.getBlock(r.contentIds[0]),u=Math.min(t,c.contentIds.length-1),f=c.contentIds[u];return f&&Ce(e,f),f??null}function ja(e,n,t,r){const o=e.getBlock(n),s=e.getBlock(o.contentIds[0]),l=De(o,s?s.contentIds.length:0);if(!l[t])return;const i=[...l];i[t]={...l[t],width:Math.max(Pt,Math.round(r))},e.applyOperation(X(n,{columns:i}))}function Ra(e,n,t,r){const o=e.getBlock(n),s=e.getBlock(o.contentIds[0]),i=[...De(o,s?s.contentIds.length:0)];i[t]&&(i[t]={...i[t],label:r},e.applyOperation(X(n,{columns:i})))}function po(e,n,t){return n.contentIds.map(r=>{const s=e.getBlock(r).contentIds[t],l=e.getBlock(s);return{cellId:s,run:e.getRun(l.contentIds[0])}})}function us(e,n){if(!e)return"";if(e.type==="text")return e.value??"";const t=n==null?void 0:n.get(e.type);return t!=null&&t.toPlainText?t.toPlainText(e):""}function vu(e,n,t,r){const o=po(e,n,t),s=[],l=new Map;for(const{run:c}of o){const u=us(c,r).trim();if(!u||l.has(u))continue;const f={value:L(),label:u};l.set(u,f),s.push(f)}const i=o.map(({cellId:c,run:u})=>{const f=us(u,r).trim(),p=l.get(f);return{cellId:c,run:{id:L(),type:"tableSelect",value:"",marks:{},data:{selectedValue:(p==null?void 0:p.value)??"",selectedLabel:(p==null?void 0:p.label)??""}}}});return{options:s,newRuns:i}}function Ta(e,n,t,r,o){const s=e.getBlock(n),l=e.getBlock(s.contentIds[0]),i=De(s,l?l.contentIds.length:0),c=i[t];if(!c||c.type===r)return;const u=[...i];if(r==="select"){const{options:p,newRuns:h}=vu(e,s,t,o);u[t]={...c,type:r,options:p};const b=[X(n,{columns:u})];for(const{cellId:g,run:x}of h)b.push(Oe(g,[x]));wn(e,b);return}u[t]={...c,type:r};const f=[X(n,{columns:u})];for(const{cellId:p,run:h}of po(e,s,t)){if(!h)continue;const b=wa(h,r,o);f.push(Oe(p,[b]))}wn(e,f)}function Lt(e,n,t,r){var p,h;const o=e.getBlock(n),s=e.getBlock(o.contentIds[0]),l=De(o,s?s.contentIds.length:0),i=l[t];if(!i)return;const c=[...l];c[t]={...i,options:r};const u=[X(n,{columns:c})],f=new Map(r.map(b=>[b.value,b]));for(const{run:b}of po(e,o,t)){if(!b||b.type!=="tableSelect")continue;const g=((p=b.data)==null?void 0:p.selectedValue)??"",x=f.get(g),k=x?g:"",y=x?x.label:"";(k!==g||y!==(((h=b.data)==null?void 0:h.selectedLabel)??""))&&u.push(ce(b.id,{data:{selectedValue:k,selectedLabel:y}}))}wn(e,u)}function Ba(e,n,t){const[r,o]=d.useState(null);return d.useLayoutEffect(()=>{o(t??null)},[t]),d.useLayoutEffect(()=>{if(!n||!e.current||r==null)return;const s=e.current.getBoundingClientRect(),l=Yt(r,s.width);l!==r&&o(l)},[n,e,r]),r}function Ea(e,n,t){const[r,o]=d.useState(null);return d.useLayoutEffect(()=>{o(t??null)},[t]),d.useLayoutEffect(()=>{if(!n||!e.current||r==null)return;const s=e.current.getBoundingClientRect(),l=s.width/2,c=Yt(r-l,s.width)+l;c!==r&&o(c)},[n,e,r]),r}function wu(e,n,t){const[r,o]=d.useState(null);return d.useLayoutEffect(()=>{o(t??null)},[t]),d.useLayoutEffect(()=>{if(!n||!e.current||r==null)return;const s=e.current.getBoundingClientRect(),i=Yt(r-s.width,s.width)+s.width;i!==r&&o(i)},[n,e,r]),r}function ds(){if(typeof window>"u"||!window.visualViewport)return 0;const e=window.visualViewport,n=window.innerHeight-(e.height+e.offsetTop);return n>0?Math.round(n):0}function rr(){const[e,n]=d.useState(ds);return d.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const t=window.visualViewport,r=()=>n(ds());return r(),t.addEventListener("resize",r),t.addEventListener("scroll",r),()=>{t.removeEventListener("resize",r),t.removeEventListener("scroll",r)}},[]),e}const Iu=280;function Cu(e,n){return n?e.label.toLowerCase().includes(n.toLowerCase()):!0}function In({value:e,options:n,onChange:t,placeholder:r="Select…",ariaLabel:o,className:s="",variant:l="default",selectedLabel:i,selectedColor:c,onManageOptions:u,manageOptionsLabel:f="Manage options…",mention:p=!1}){var ke,fe;const[h,b]=d.useState(!1),[g,x]=d.useState(""),[k,y]=d.useState(0),[I,w]=d.useState(null),T=rr(),[S,v]=d.useState([]),[R,O]=d.useState(!1),[N,C]=d.useState(!1),B=d.useRef(null),A=d.useRef(null),z=d.useRef(null),U=d.useRef(null),q=d.useRef(null),le=d.useMemo(()=>[B,z],[]),se=l==="tag",G=typeof n=="function",re=G?void 0:n.find($=>$.value===e),H=e?re??(i?{label:i,color:c}:void 0):void 0,Q=d.useMemo(()=>G?S:n.filter($=>Cu($,g)),[G,S,n,g]);d.useEffect(()=>{if(!G||!h)return;let $=!1;O(!0),C(!1);const we=setTimeout(()=>{Promise.resolve(n(g)).then(_e=>{$||(v(_e??[]),O(!1))}).catch(()=>{$||(v([]),O(!1),C(!0))})},250);return()=>{$=!0,clearTimeout(we)}},[G,h,n,g]);const ee=d.useCallback(()=>b(!1),[]);Pe(le,h,ee);const te=Ba(z,h,I==null?void 0:I.left),me=d.useCallback(()=>{var $;w((($=A.current)==null?void 0:$.getBoundingClientRect())??null),x(""),y(0),b(!0)},[]);d.useEffect(()=>{var $;h&&(($=U.current)==null||$.focus())},[h]),d.useEffect(()=>{var $,we;(we=($=q.current)==null?void 0:$.scrollIntoView)==null||we.call($,{block:"nearest"})},[k]);const Se=d.useCallback($=>{var we;t($.value,$),ee(),(we=A.current)==null||we.focus()},[t,ee]),oe=d.useCallback($=>{var we;$.key==="ArrowDown"?($.preventDefault(),y(_e=>Math.min(_e+1,Math.max(Q.length-1,0)))):$.key==="ArrowUp"?($.preventDefault(),y(_e=>Math.max(_e-1,0))):$.key==="Enter"?($.preventDefault(),Q[k]&&Se(Q[k])):$.key==="Escape"&&($.preventDefault(),ee(),(we=A.current)==null||we.focus())},[Q,k,Se,ee]);return a.jsxs("span",{className:`be-select ${s}`.trim(),ref:B,children:[a.jsx("button",{type:"button",ref:A,className:`be-select-trigger${se?" be-select-trigger-tag":""}${p?" be-select-trigger-mention":""}`,"aria-haspopup":"listbox","aria-expanded":h,"aria-label":o,onClick:()=>h?ee():me(),children:se?H?a.jsx("span",{className:`be-select-tag${p?" be-select-tag-mention":""}`,style:p?void 0:{background:(ke=H.color)==null?void 0:ke.bg,color:(fe=H.color)==null?void 0:fe.text},children:p?`@${H.label}`:H.label}):a.jsx("span",{className:"be-select-value be-select-value-placeholder",children:r}):a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"be-select-value",children:H?H.label:r}),a.jsx(Vt,{size:14,className:"be-select-chevron"})]})}),h&&I&&te!=null&&Ve.createPortal(a.jsxs("div",{ref:z,className:"be-select-popover",style:{position:"fixed",left:te,minWidth:I.width,...I.bottom+Iu>window.innerHeight-T?{bottom:window.innerHeight-I.top+4}:{top:I.bottom+4}},children:[a.jsx("input",{ref:U,type:"text",className:"be-select-search",value:g,onChange:$=>{x($.target.value),y(0)},onKeyDown:oe,placeholder:"Search…","aria-label":o?`Search ${o}`:"Search options"}),a.jsxs("div",{className:"be-select-options",role:"listbox",children:[G&&R&&a.jsx("div",{className:"be-select-empty",children:"Loading…"}),G&&!R&&N&&a.jsx("div",{className:"be-select-empty be-select-error",children:"Couldn't load options"}),!R&&!N&&Q.length===0&&a.jsx("div",{className:"be-select-empty",children:"No results"}),!R&&!N&&Q.map(($,we)=>{var _e,ht;return a.jsx("div",{ref:we===k?q:void 0,role:"option","aria-selected":$.value===e,className:`be-select-option${we===k?" be-select-option-active":""}${$.value===e?" be-select-option-selected":""}`,onMouseDown:ar=>{ar.preventDefault(),Se($)},onMouseEnter:()=>y(we),children:se?a.jsx("span",{className:"be-select-tag",style:{background:(_e=$.color)==null?void 0:_e.bg,color:(ht=$.color)==null?void 0:ht.text},children:$.label}):$.label},$.value)})]}),u&&a.jsx("button",{type:"button",className:"be-select-manage-options",onMouseDown:$=>{$.preventDefault(),ee(),u()},children:f})]}),document.body)]})}const St=[{bg:"#e9e9e7",text:"#32302c"},{bg:"#eee0da",text:"#64473a"},{bg:"#fadec9",text:"#8a4b23"},{bg:"#fdecc8",text:"#8a6116"},{bg:"#dbeddb",text:"#256029"},{bg:"#d3e5ef",text:"#1a5f8a"},{bg:"#e8deee",text:"#5b3a8a"},{bg:"#f5e0e9",text:"#8a3a5f"},{bg:"#ffe2dd",text:"#a13a2f"}];function lt(e){return St[(e%St.length+St.length)%St.length]}const Su={text:"Text",date:"Date",checkbox:"Checkbox",select:"Select"},ju=ya.map(e=>({value:e,label:Su[e]})),Ru=800;function Tu({tableId:e,colIndex:n,options:t}){const r=W(),[o,s]=d.useState(""),l=d.useCallback((u,f)=>{Lt(r,e,n,t.map(p=>p.value===u?{...p,label:f}:p))},[r,e,n,t]),i=d.useCallback(u=>Lt(r,e,n,t.filter(f=>f.value!==u)),[r,e,n,t]),c=d.useCallback(()=>{const u=o.trim();s(""),u&&Lt(r,e,n,[...t,{value:L(),label:u,color:lt(t.length)}])},[r,e,n,t,o]);return a.jsxs("div",{className:"be-table-header-menu-options",children:[a.jsx("div",{className:"be-table-header-menu-options-label",children:"Options"}),t.map((u,f)=>a.jsxs("div",{className:"be-table-header-menu-option-row",children:[a.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(u.color??lt(f)).bg},"aria-hidden":"true"}),a.jsx("input",{className:"be-table-header-menu-option-input",value:u.label,onChange:p=>l(u.value,p.target.value),"aria-label":`Rename option ${u.label}`}),a.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>i(u.value),"aria-label":`Remove option ${u.label}`,children:a.jsx(zn,{size:14})})]},u.value)),a.jsxs("div",{className:"be-table-header-menu-option-row",children:[a.jsx("input",{className:"be-table-header-menu-option-input",value:o,onChange:u=>s(u.target.value),placeholder:"New option…",onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),c())}}),a.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:c,"aria-label":"Add option",children:"+"})]})]})}function Bu({tableId:e,column:n,colIndex:t,colCount:r}){const o=W(),s=We(),[l,i]=d.useState(!1),[c,u]=d.useState(null),[f,p]=d.useState(null),h=d.useRef(null),b=d.useRef(null),g=d.useRef(null),x=d.useMemo(()=>[h,b],[]),k=d.useCallback(()=>i(!1),[]);Pe(x,l,k),Jt(b,l,k,h);const y=wu(b,l,c==null?void 0:c.right),I=d.useCallback(()=>{var N;u(((N=g.current)==null?void 0:N.getBoundingClientRect())??null),i(!0)},[]),w=d.useCallback(N=>Ra(o,e,t,N.target.value),[o,e,t]),T=d.useCallback(()=>{$t(o,e,t-1),k()},[o,e,t,k]),S=d.useCallback(()=>{$t(o,e,t),k()},[o,e,t,k]),v=d.useCallback(()=>{Sa(o,e,t),k()},[o,e,t,k]),R=d.useCallback(N=>Ta(o,e,t,N,s),[o,e,t,s]),O=d.useCallback(N=>{var se;N.preventDefault();const C=(se=g.current)==null?void 0:se.closest("table"),B=C==null?void 0:C.querySelector(`col[data-col-index="${t}"]`);if(!B)return;const A=g.current.getBoundingClientRect().width,z=N.clientX,U=G=>Math.max(Pt,Math.round(A+(G.clientX-z))),q=G=>{const re=U(G);B.style.width=`${re}px`,p(re)},le=G=>{document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",le),ja(o,e,t,U(G)),p(null)};document.addEventListener("mousemove",q),document.addEventListener("mouseup",le)},[o,e,t]);return a.jsxs("th",{ref:g,scope:"col",className:"be-table-header-cell",contentEditable:!1,children:[a.jsx("input",{className:"be-table-header-label",value:n.label,onChange:w,"aria-label":`Column ${t+1} name`}),a.jsx("button",{ref:h,type:"button",className:"be-table-header-menu-trigger","aria-label":`Column ${t+1} options`,"aria-haspopup":"menu","aria-expanded":l,onClick:()=>l?k():I(),children:"⋮"}),a.jsx("div",{className:"be-table-col-resize-handle",onMouseDown:O,role:"slider","aria-label":`Resize column ${t+1}`,"aria-valuemin":Pt,"aria-valuemax":Ru,"aria-valuenow":f??n.width}),l&&c&&y!=null&&Ve.createPortal(a.jsxs("div",{ref:b,role:"menu","aria-label":`Column ${t+1} options`,className:"be-table-header-menu",style:{position:"fixed",top:c.bottom+4,left:y,transform:"translateX(-100%)"},children:[a.jsxs("div",{className:"be-table-header-menu-type",children:[a.jsx("span",{id:`be-table-col-type-${n.id}`,children:"Type"}),a.jsx(In,{value:n.type,options:ju,onChange:R,ariaLabel:"Column type",className:""})]}),n.type==="select"&&a.jsx(Tu,{tableId:e,colIndex:t,options:n.options??[]}),a.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:T,children:"Insert column left"}),a.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:S,children:"Insert column right"}),a.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item be-table-header-menu-item-danger",onClick:v,disabled:r<=1,children:"Delete column"})]}),document.body)]})}function Na({tableId:e,columns:n}){return a.jsx("thead",{children:a.jsxs("tr",{className:"be-table-header-row",children:[n.map((t,r)=>a.jsx(Bu,{tableId:e,column:t,colIndex:r,colCount:n.length},t.id)),a.jsx("th",{className:"be-table-header-spacer","aria-hidden":"true"})]})})}function Eu({id:e}){var i;const n=W(),t=be(e),r=d.useCallback(()=>{var u;const c=(u=t==null?void 0:t.contentIds)==null?void 0:u[t.contentIds.length-1];c&&uo(n,c)},[n,t]),o=ve("be-table-wrapper",t);if(!t)return null;const s=n.getBlock(t.contentIds[0]),l=De(t,((i=s==null?void 0:s.contentIds)==null?void 0:i.length)??0);return a.jsx("div",{className:"be-table-scroll",children:a.jsxs("div",{className:o,"data-block-id":e,children:[a.jsxs("table",{className:"be-table",children:[a.jsxs("colgroup",{children:[l.map((c,u)=>a.jsx("col",{"data-col-index":u,style:{width:c.width}},c.id)),a.jsx("col",{className:"be-table-header-spacer-col"})]}),a.jsx(Na,{tableId:e,columns:l}),a.jsx("tbody",{children:a.jsx(hn,{parentId:e})})]}),a.jsxs("button",{type:"button",className:"be-table-add-row",contentEditable:!1,onClick:r,children:[a.jsx(Kr,{size:14})," Add row"]})]})})}function Nu({id:e}){const n=W(),t=be(e),r=ve("be-table-row",t),o=d.useCallback(()=>Ca(n,e),[n,e]);return a.jsxs("tr",{className:r,"data-block-id":e,children:[a.jsx(hn,{parentId:e}),a.jsx("td",{className:"be-table-row-actions",contentEditable:!1,children:a.jsx("button",{type:"button",className:"be-table-delete-row",onClick:o,"aria-label":"Delete row",title:"Delete row",children:a.jsx(zn,{size:14})})})]})}function Oa(e,n){const t=e.getBlock(n),r=e.getBlock(t.parentId),o=e.getBlock(r.parentId);return{table:o,row:r,rowIndex:o.contentIds.indexOf(r.id),colIndex:r.contentIds.indexOf(n)}}function Ou(e,n,t){const{table:r,row:o,rowIndex:s,colIndex:l}=Oa(e,n);if(t==="left"||t==="right"){const f=t==="right"?1:-1,p=l+f;if(p>=0&&p<o.contentIds.length)return o.contentIds[p];const h=s+f;if(h<0||h>=r.contentIds.length)return null;const b=e.getBlock(r.contentIds[h]),g=t==="right"?0:b.contentIds.length-1;return b.contentIds[g]}const c=s+(t==="down"?1:-1);if(c<0||c>=r.contentIds.length)return null;const u=e.getBlock(r.contentIds[c]);return u.contentIds[l]??u.contentIds[u.contentIds.length-1]??null}function Lu(e,n){const t=oa(e,n,"down");if(t){xe(t);return}Ge(e,n,J("paragraph"))}function Jn(e,n,t){var o;const r=Ou(e,n,t);if(r){const s=e.getBlock(r),l=(o=s==null?void 0:s.contentIds)==null?void 0:o[0];l&&xe(l);return}if(t==="right"){const{table:s}=Oa(e,n);Lu(e,s.id)}}function Mu({id:e}){const n=W(),t=be(e),r=d.useCallback(()=>Jn(n,e,"right"),[n,e]),o=d.useCallback(()=>Jn(n,e,"left"),[n,e]),s=d.useCallback(()=>Jn(n,e,"up"),[n,e]),l=d.useCallback(()=>Jn(n,e,"down"),[n,e]),i=d.useCallback(()=>Jn(n,e,"down"),[n,e]),c=ve("be-table-cell",t);if(!t)return null;const u=tn(n,t);return a.jsx("td",{className:c,"data-block-id":e,dir:u,children:a.jsx(sn,{blockId:e,runIds:t.contentIds,dir:u,onTab:r,onShiftTab:o,onArrowUp:s,onArrowDown:l,onEnter:i})})}function Au(e,n){const t=L(),r=[],o=[],s=[];for(const l of n){const i=tr(t,l);r.push(i.block),o.push(i.run),s.push(i.block.id)}return{block:{id:t,type:"tableRow",parentId:e,contentIds:s,props:{}},blocks:r,runs:o}}function Du({rows:e=2,cols:n=2}={}){return function(r){const o=L(),s=co(n),l=[],i=[],c=[];for(let f=0;f<e;f+=1){const p=Au(o,s);l.push(p.block,...p.blocks),i.push(...p.runs),c.push(p.block.id)}return{block:{id:o,type:"table",parentId:r,contentIds:c,props:{columns:s}},runs:i,subtreeBlocks:l}}}function Pu(e,n){return`<td>${e.contentIds.map(r=>n.store.getRun(r)).map(r=>an(r,n)).join("")}</td>`}function $u(e,n){return e.contentIds.map(t=>fn(n.store.getRun(t),n)).join("")}function _u(e,n){if(e.tagName!=="TD"&&e.tagName!=="TH")return null;const t=$e(e,n);return{block:{id:L(),type:"tableCell",parentId:null,contentIds:t.map(o=>o.id),props:{}},runs:t}}function zu(e,n){return`<tr>${e.contentIds.map(r=>{const o=n.store.getBlock(r);return n.registry.get(o.type).toHTML(o,n)}).join("")}</tr>`}function Hu(e,n){return e.contentIds.map(t=>{const r=n.store.getBlock(t);return n.registry.get(r.type).toPlainText(r,n)}).join(" ")}function Fu(e,n){if(e.tagName!=="TR")return null;const t=[...e.children].filter(c=>c.tagName==="TD"||c.tagName==="TH"),r=L(),o=[],s=[],l=[];for(const c of t){const u=n.registry.get("tableCell").fromHTML(c,n);u&&(u.block.parentId=r,o.push(u.block),s.push(...u.runs),l.push(u.block.id))}return{block:{id:r,type:"tableRow",parentId:null,contentIds:l,props:{}},runs:s,subtreeBlocks:o}}function Uu(e,n){var l;const t=e.contentIds[0]&&n.store.getBlock(e.contentIds[0]),r=De(e,((l=t==null?void 0:t.contentIds)==null?void 0:l.length)??0),o=r.length?`<thead><tr>${r.map(i=>`<th>${vn(i.label??"")}</th>`).join("")}</tr></thead>`:"",s=e.contentIds.map(i=>{const c=n.store.getBlock(i);return n.registry.get(c.type).toHTML(c,n)}).join("");return`<table>${o}<tbody>${s}</tbody></table>`}function Yu(e,n){return e.contentIds.map(t=>{const r=n.store.getBlock(t);return n.registry.get(r.type).toPlainText(r,n)}).join(`
|
|
2515
|
-
`)}function
|
|
2516
|
-
`)}const
|
|
2517
|
-
`);return`${
|
|
2518
|
-
`),[
|
|
2525
|
+
`,bs="noteloom-default-styles";function ll(){if(typeof document>"u"||document.getElementById(bs))return;const e=document.createElement("style");e.id=bs,e.textContent=Fc,document.head.appendChild(e)}const al=p.createContext(null);function il({store:e,registry:t,inlineRegistry:n=null,history:r=null,className:o,style:s,theme:l="default",getBlockClassName:i,children:c}){p.useEffect(()=>{l!=="none"&&ll()},[l]);const[u,f]=p.useState(!1),[d,h]=p.useState([]),[m,g]=p.useState(!1),[x,k]=p.useState(null),y=p.useCallback(()=>k("new"),[]),I=p.useCallback(O=>k(O),[]),w=p.useCallback(()=>k(null),[]),j=p.useRef(null),S=p.useCallback(()=>j.current,[]),v=p.useCallback(O=>{var B,M;const C=j.current;C!==O&&(C&&((B=document.querySelector(`[data-block-id="${C}"]`))==null||B.classList.remove("be-block-selected")),j.current=O,O&&((M=document.querySelector(`[data-block-id="${O}"]`))==null||M.classList.add("be-block-selected")))},[]),R=p.useMemo(()=>({store:e,registry:t,inlineRegistry:n,history:r,isWholeDocumentSelected:u,setIsWholeDocumentSelected:f,selectedBlockRange:d,setSelectedBlockRange:h,getSelectedBlockId:S,setSelectedBlockId:v,isPreviewMode:m,setIsPreviewMode:g,fieldTypeEditorTarget:x,openCreateFieldType:y,openEditFieldType:I,closeFieldTypeEditor:w,getBlockClassName:i}),[e,t,n,r,u,d,S,v,m,x,y,I,w,i]),_=o||s?a.jsx("div",{className:o?`be-root ${o}`:"be-root",style:s,children:c}):c;return a.jsx(al.Provider,{value:R,children:_})}function Ge(){const e=p.useContext(al);if(!e)throw new Error("Editor hooks must be used within an <EditorProvider>");return e}function q(){return Ge().store}function gt(){return Ge().registry}function Je(){return Ge().inlineRegistry}function ro(){const{isWholeDocumentSelected:e,setIsWholeDocumentSelected:t}=Ge();return[e,t]}function Cn(){const{selectedBlockRange:e,setSelectedBlockRange:t}=Ge();return[e,t]}function lt(){const{getSelectedBlockId:e,setSelectedBlockId:t}=Ge();return{getSelectedBlockId:e,setSelectedBlockId:t}}function oo(){const{isPreviewMode:e,setIsPreviewMode:t}=Ge();return[e,t]}function we(e,t){const{getBlockClassName:n}=Ge(),r=t&&n?n(t):void 0;return r?`${e} ${r}`:e}function so(){const{fieldTypeEditorTarget:e,openCreateFieldType:t,openEditFieldType:n,closeFieldTypeEditor:r}=Ge();return{target:e,openCreate:t,openEdit:n,close:r}}function he(e){const t=q(),n=p.useCallback(o=>t.subscribe(e,o),[t,e]),r=p.useCallback(()=>t.getBlock(e),[t,e]);return p.useSyncExternalStore(n,r)}function xt(e){const t=q(),n=p.useCallback(o=>t.subscribe(e,o),[t,e]),r=p.useCallback(()=>t.getRun(e),[t,e]);return p.useSyncExternalStore(n,r)}function N(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`id-${Date.now()}-${Math.random().toString(36).slice(2)}`}const cl="",Uc=//g;function nt(e){return(e??"").replace(Uc,"")}function ms(e){return nt(e.textContent)}function Yc(e,t){var i;const n=new Map(t.map(c=>[c.id,c])),r=new Set,o=[];let s=!0;for(const c of e.childNodes){const u=c.nodeType===1?(i=c.dataset)==null?void 0:i.runId:void 0;if(u&&n.has(u)){r.add(u);const d=n.get(u);if(d.type!=="text"){o.push(d);continue}const h=ms(c);o.push(h===d.value?d:{...d,value:h});continue}s=!1;const f=ms(c);f&&o.push({id:N(),type:"text",value:f,marks:{}})}if(t.some(c=>!r.has(c.id))&&(s=!1),o.length!==t.length&&(s=!1),s){for(let c=0;c<o.length;c+=1)if(o[c].id!==t[c].id){s=!1;break}}const l=!s||o.some((c,u)=>c!==t[u]);return{runs:o,changed:l,onlyValueChanges:s}}function ul(e){return e?e.type!=="text"?!1:(e.value??"")==="":!0}function Ne(e,t){return!t||t.length===0?!0:t.every(n=>ul(e.getRun(n)))}function Sn(e,t){var o,s;if(!t)return!1;const n=t.contentIds.length>0,r=(((s=(o=t.props)==null?void 0:o.titleRunIds)==null?void 0:s.length)??0)>0;return!n&&!r}function dl(e,t){const n=document.querySelector(`[data-run-id="${e}"]`);if(!n)return;n.focus();const r=n.firstChild,o=document.createRange();if(r&&r.nodeType===3){const l=Math.max(0,Math.min(t,r.length));o.setStart(r,l),o.setEnd(r,l)}else o.selectNodeContents(n),o.collapse(t<=0);const s=window.getSelection();s==null||s.removeAllRanges(),s==null||s.addRange(o)}function pl(e,t){requestAnimationFrame(()=>{const n=document.querySelector(`[data-run-id="${e}"]`);if(!n)return;n.focus();const r=document.createRange();r.selectNodeContents(n),r.collapse(t);const o=window.getSelection();o==null||o.removeAllRanges(),o==null||o.addRange(r)})}function xe(e){pl(e,!1)}function rr(e){pl(e,!0)}function We(e,t){requestAnimationFrame(()=>dl(e,t))}function gs(e,t){dl(e,t)}const Kc='button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';function at({isOpen:e,onClose:t,title:n,size:r="default",variant:o="dialog",children:s}){const l=p.useRef(null),i=p.useRef(null);if(p.useEffect(()=>{if(!e)return;const u=f=>{f.key==="Escape"&&t()};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[e,t]),p.useEffect(()=>{var u,f,d;if(e){i.current=document.activeElement;const h=l.current;(u=(h==null?void 0:h.querySelector(Kc))??h)==null||u.focus();return}(d=(f=i.current)==null?void 0:f.focus)==null||d.call(f),i.current=null},[e]),!e)return null;const c=o==="sheet";return a.jsx("div",{className:`be-modal-overlay${c?" be-modal-overlay-sheet":""}`,onMouseDown:u=>{u.target===u.currentTarget&&t()},children:a.jsxs("div",{ref:l,className:`be-modal${r==="large"?" be-modal-large":""}${c?" be-modal-sheet":""}`,role:"dialog","aria-modal":"true","aria-label":n,tabIndex:-1,children:[n&&a.jsx("div",{className:"be-modal-title",children:n}),s]})})}function fl({isOpen:e,initialHref:t,initialTarget:n,hasExistingLink:r,onSave:o,onRemove:s,onClose:l}){const[i,c]=p.useState(""),[u,f]=p.useState("_self");p.useEffect(()=>{e&&(c(t),f(n))},[e]);const d=i.trim(),h=p.useCallback(m=>{m.preventDefault(),d&&o(d,u)},[d,u,o]);return a.jsx(at,{isOpen:e,onClose:l,title:r?"Edit link":"Add link",children:a.jsxs("form",{onSubmit:h,children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"URL"}),a.jsx("input",{type:"text",value:i,onChange:m=>c(m.target.value),placeholder:"https://example.com",autoFocus:!0})]}),a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Open in"}),a.jsxs("select",{value:u,onChange:m=>f(m.target.value),children:[a.jsx("option",{value:"_self",children:"Same tab"}),a.jsx("option",{value:"_blank",children:"New tab"})]})]}),a.jsxs("div",{className:"be-modal-actions",children:[r&&a.jsx("button",{type:"button",className:"be-modal-delete",onClick:s,children:"Remove link"}),a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:l,children:"Cancel"}),a.jsx("button",{type:"submit",className:"be-modal-save",disabled:!d,children:"Save"})]})]})})}const Xt=8;function or(e,t){const n=Math.max(Xt,window.innerWidth-t-Xt);return Math.min(Math.max(e,Xt),n)}function Vc(e,t){const n=Math.max(Xt,window.innerHeight-t-Xt);return Math.min(Math.max(e,Xt),n)}function sr(e,t,n,r){const[o,s]=p.useState(null);return p.useLayoutEffect(()=>{if(n==null||r==null){s(null);return}s({top:n,left:r})},[n,r]),p.useLayoutEffect(()=>{if(!t||!e.current||!o)return;const l=e.current.getBoundingClientRect(),i=or(o.left,l.width),c=Vc(o.top,l.height);(i!==o.left||c!==o.top)&&s({top:c,left:i})},[t,e,o]),o}function F({children:e,size:t=16,strokeWidth:n=2,...r}){return a.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",...r,children:e})}function Ct(e){return a.jsx(F,{...e,children:a.jsx("polyline",{points:"9 18 15 12 9 6"})})}function lr(e){return a.jsx(F,{...e,children:a.jsx("polyline",{points:"6 9 12 15 18 9"})})}function en(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),a.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Wc(e){return a.jsxs(F,{...e,fill:"currentColor",stroke:"none",children:[a.jsx("circle",{cx:"5",cy:"12",r:"1.6"}),a.jsx("circle",{cx:"12",cy:"12",r:"1.6"}),a.jsx("circle",{cx:"19",cy:"12",r:"1.6"})]})}function hl(e){return a.jsx(F,{...e,children:a.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}function lo(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),a.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function bl(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"}),a.jsx("path",{d:"M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"})]})}function ml(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"19",y1:"4",x2:"10",y2:"4"}),a.jsx("line",{x1:"14",y1:"20",x2:"5",y2:"20"}),a.jsx("line",{x1:"15",y1:"4",x2:"9",y2:"20"})]})}function gl(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M6 3v7a6 6 0 0 0 12 0V3"}),a.jsx("line",{x1:"4",y1:"21",x2:"20",y2:"21"})]})}function xl(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M12 20h9"}),a.jsx("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]})}function Xc(e){return a.jsx(F,{...e,children:a.jsx("path",{d:"M3 17c2-4 4-4 6 0s4 4 6 0 4-4 6 0"})})}function kl(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),a.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})}function qc(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M16 4H9a3 3 0 0 0-2.83 4"}),a.jsx("path",{d:"M14 12a4 4 0 0 1 0 8H6"}),a.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}function yl(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),a.jsx("line",{x1:"17",y1:"10",x2:"3",y2:"10"}),a.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),a.jsx("line",{x1:"17",y1:"18",x2:"3",y2:"18"})]})}function Gc(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),a.jsx("line",{x1:"18",y1:"10",x2:"6",y2:"10"}),a.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),a.jsx("line",{x1:"18",y1:"18",x2:"6",y2:"18"})]})}function vl(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),a.jsx("line",{x1:"21",y1:"10",x2:"7",y2:"10"}),a.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),a.jsx("line",{x1:"21",y1:"18",x2:"7",y2:"18"})]})}function Jc(e){return a.jsx(F,{...e,children:[5,12,19].flatMap(t=>[9,15].map(n=>a.jsx("circle",{cx:n,cy:t,r:"1.3",fill:"currentColor",stroke:"none"},`${n}-${t}`)))})}function ar(e){return a.jsxs(F,{...e,children:[a.jsx("polyline",{points:"3 6 5 6 21 6"}),a.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),a.jsx("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),a.jsx("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function ao(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"9",y:"9",width:"12",height:"12",rx:"2"}),a.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function ir(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),a.jsx("polyline",{points:"5 12 12 5 19 12"})]})}function cr(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),a.jsx("polyline",{points:"19 12 12 19 5 12"})]})}function wl(e){return a.jsx(F,{...e,children:a.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"1"})})}function Zc(e){return a.jsx(F,{...e,children:a.jsx("circle",{cx:"12",cy:"12",r:"8"})})}function Qc(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"6",y1:"18",x2:"18",y2:"6"}),a.jsx("polyline",{points:"9 6 18 6 18 15"})]})}function eu(e){return a.jsx(F,{...e,children:a.jsx("polygon",{points:"12 3 21 12 12 21 3 12"})})}function tu(e){return a.jsx(F,{...e,children:a.jsx("polygon",{points:"12 4 20 20 4 20"})})}function nu(e){return a.jsx(F,{...e,children:a.jsx("polygon",{points:"12 3 14.7 9.4 21.5 9.9 16.3 14.4 17.9 21 12 17.4 6.1 21 7.7 14.4 2.5 9.9 9.3 9.4"})})}function ru(e){return a.jsx(F,{...e,children:a.jsx("path",{d:"M5 3l14 8-6 2-2 6-6-16z"})})}function Il(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M19 20H9l-6-6a1.5 1.5 0 0 1 0-2l9-9a1.5 1.5 0 0 1 2 0l7 7a1.5 1.5 0 0 1 0 2l-7 7"}),a.jsx("path",{d:"M6.5 12.5 13 19"})]})}function ou(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M12 3v12"}),a.jsx("path",{d:"M7 10l5 5 5-5"}),a.jsx("path",{d:"M4 19h16"})]})}function su(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M6 15V9a6 6 0 0 1 12 0v6"}),a.jsx("path",{d:"M6 15a3 3 0 0 0 6 0v-4"}),a.jsx("path",{d:"M18 15a3 3 0 0 1-6 0v-4"}),a.jsx("line",{x1:"3",y1:"9",x2:"6",y2:"9"}),a.jsx("line",{x1:"3",y1:"15",x2:"6",y2:"15"}),a.jsx("line",{x1:"18",y1:"9",x2:"21",y2:"9"}),a.jsx("line",{x1:"18",y1:"15",x2:"21",y2:"15"})]})}function lu(e){return a.jsxs(F,{...e,children:[a.jsx("circle",{cx:"6",cy:"6",r:"3"}),a.jsx("circle",{cx:"6",cy:"18",r:"3"}),a.jsx("line",{x1:"20",y1:"4",x2:"8.12",y2:"15.88"}),a.jsx("line",{x1:"14.47",y1:"14.48",x2:"20",y2:"20"}),a.jsx("line",{x1:"8.12",y1:"8.12",x2:"12",y2:"12"})]})}function io(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"17",y1:"6",x2:"3",y2:"6"}),a.jsx("line",{x1:"21",y1:"12",x2:"3",y2:"12"}),a.jsx("line",{x1:"15",y1:"18",x2:"3",y2:"18"})]})}function co({level:e=1,size:t=16,...n}){return a.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",...n,children:a.jsxs("text",{x:"2",y:"18",fontSize:"14",fontWeight:"700",fill:"currentColor",fontFamily:"inherit",children:["H",e]})})}function Cl(e){return a.jsx(co,{level:1,...e})}function Sl(e){return a.jsx(co,{level:2,...e})}function Tl(e){return a.jsx(co,{level:3,...e})}function Rl(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M7 7a3 3 0 0 0-3 3v3a2 2 0 0 0 2 2h2a1 1 0 0 0 1-1v-4a1 1 0 0 0-1-1H6a3 3 0 0 1 3-3z"}),a.jsx("path",{d:"M17 7a3 3 0 0 0-3 3v3a2 2 0 0 0 2 2h2a1 1 0 0 0 1-1v-4a1 1 0 0 0-1-1h-2a3 3 0 0 1 3-3z"})]})}function uo(e){return a.jsxs(F,{...e,children:[a.jsx("polyline",{points:"9 8 4 12 9 16"}),a.jsx("polyline",{points:"15 8 20 12 15 16"})]})}function au(e){return a.jsx(F,{...e,children:a.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})})}function jl(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M4 5h16a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H9l-4 4v-4H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z"}),a.jsx("line",{x1:"7",y1:"9",x2:"17",y2:"9"}),a.jsx("line",{x1:"7",y1:"12.5",x2:"13",y2:"12.5"})]})}function iu(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"3",y:"8",width:"18",height:"8",rx:"3"}),a.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function cu(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"1"}),a.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"}),a.jsx("line",{x1:"3",y1:"16",x2:"21",y2:"16"}),a.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),a.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function uu(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"1"}),a.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),a.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function Bl(e){return a.jsxs(F,{...e,children:[a.jsx("circle",{cx:"4.5",cy:"6",r:"1.2",fill:"currentColor",stroke:"none"}),a.jsx("circle",{cx:"4.5",cy:"12",r:"1.2",fill:"currentColor",stroke:"none"}),a.jsx("circle",{cx:"4.5",cy:"18",r:"1.2",fill:"currentColor",stroke:"none"}),a.jsx("line",{x1:"9",y1:"6",x2:"21",y2:"6"}),a.jsx("line",{x1:"9",y1:"12",x2:"21",y2:"12"}),a.jsx("line",{x1:"9",y1:"18",x2:"21",y2:"18"})]})}function El(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"10",y1:"6",x2:"21",y2:"6"}),a.jsx("line",{x1:"10",y1:"12",x2:"21",y2:"12"}),a.jsx("line",{x1:"10",y1:"18",x2:"21",y2:"18"}),a.jsx("text",{x:"2",y:"8.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"1"}),a.jsx("text",{x:"2",y:"14.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"2"}),a.jsx("text",{x:"2",y:"20.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"3"})]})}function po(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"3"}),a.jsx("polyline",{points:"8 12 11 15 16 9"})]})}function du(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"3",y:"5",width:"18",height:"16",rx:"2"}),a.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"}),a.jsx("line",{x1:"8",y1:"3",x2:"8",y2:"7"}),a.jsx("line",{x1:"16",y1:"3",x2:"16",y2:"7"})]})}function Ll(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M12 3h7a2 2 0 0 1 2 2v7a2 2 0 0 1-.59 1.41l-8 8a2 2 0 0 1-2.82 0l-7-7a2 2 0 0 1 0-2.82l8-8A2 2 0 0 1 12 3z"}),a.jsx("circle",{cx:"15.5",cy:"8.5",r:"1.2",fill:"currentColor",stroke:"none"})]})}function pu(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),a.jsx("circle",{cx:"9",cy:"10",r:"1.5",fill:"currentColor",stroke:"none"}),a.jsx("path",{d:"M4 17l5-5 4 4 4-5 4 6"})]})}function fu(e){return a.jsxs(F,{...e,children:[a.jsx("rect",{x:"3",y:"5",width:"14",height:"14",rx:"2"}),a.jsx("path",{d:"M17 10l4-2.5v9L17 14"})]})}function fo(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7z"}),a.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function ho(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 19c-6.5 0-10-7-10-7a18.5 18.5 0 0 1 5.06-5.94M9.9 4.24A10.94 10.94 0 0 1 12 4c6.5 0 10 7 10 7a18.5 18.5 0 0 1-2.16 3.19"}),a.jsx("path",{d:"M14.12 14.12a3 3 0 1 1-4.24-4.24"}),a.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function hu(e){return a.jsxs(F,{...e,children:[a.jsx("line",{x1:"4",y1:"10",x2:"4",y2:"14"}),a.jsx("line",{x1:"8",y1:"7",x2:"8",y2:"17"}),a.jsx("line",{x1:"12",y1:"4",x2:"12",y2:"20"}),a.jsx("line",{x1:"16",y1:"7",x2:"16",y2:"17"}),a.jsx("line",{x1:"20",y1:"10",x2:"20",y2:"14"})]})}function bu(e){return a.jsxs(F,{...e,children:[a.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),a.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),a.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),a.jsx("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}function mu({containerRef:e,store:t}){var I;const[n,r]=p.useState(null),[o,s]=p.useState(!1),l=p.useRef(null),i=p.useRef(null),c=p.useCallback(()=>{l.current&&(clearTimeout(l.current),l.current=null)},[]),u=p.useCallback(()=>{c(),l.current=setTimeout(()=>{r(w=>o?w:null)},250)},[c,o]);p.useEffect(()=>{const w=e.current;if(!w)return;const j=v=>{var C,B,M;const R=(B=(C=v.target).closest)==null?void 0:B.call(C,"[data-run-id]");if(!R||!w.contains(R))return;const _=R.dataset.runId,O=t.getRun(_);(M=O==null?void 0:O.marks)!=null&&M.link&&(c(),r(z=>(z==null?void 0:z.runId)===_?z:{runId:_,rect:R.getBoundingClientRect()}))},S=()=>u();return w.addEventListener("mouseover",j),w.addEventListener("mouseout",S),()=>{w.removeEventListener("mouseover",j),w.removeEventListener("mouseout",S)}},[e,t,c,u]),p.useEffect(()=>()=>c(),[c]);const f=p.useCallback(()=>s(!0),[]),d=p.useCallback(()=>{s(!1),r(null)},[]),h=p.useCallback((w,j)=>{if(!n)return;const S=t.getRun(n.runId);S&&(t.applyOperation(ue(n.runId,{marks:{...S.marks,link:{href:w,target:j}}})),d())},[n,t,d]),m=p.useCallback(()=>{if(!n)return;const w=t.getRun(n.runId);if(!w)return;const j={...w.marks};delete j.link,t.applyOperation(ue(n.runId,{marks:j})),d()},[n,t,d]),g=n&&t.getRun(n.runId),x=(I=g==null?void 0:g.marks)==null?void 0:I.link,k=!!(n&&x&&!o),y=sr(i,k,n?n.rect.bottom+6:null,n?n.rect.left:null);return a.jsxs(a.Fragment,{children:[k&&y?Xe.createPortal(a.jsxs("div",{ref:i,className:"be-link-hover-card",contentEditable:!1,style:{position:"fixed",top:y.top,left:y.left},onMouseEnter:c,onMouseLeave:u,children:[a.jsx("a",{className:"be-link-hover-card-url",href:x.href,target:x.target==="_blank"?"_blank":"_self",rel:"noopener noreferrer",children:x.href}),a.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:f,"aria-label":"Edit link",title:"Edit link",children:a.jsx(xl,{size:13})}),a.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:m,"aria-label":"Remove link",title:"Remove link",children:a.jsx(en,{size:13})})]}),document.body):null,a.jsx(fl,{isOpen:o,initialHref:(x==null?void 0:x.href)??"",initialTarget:(x==null?void 0:x.target)??"_self",hasExistingLink:!!x,onSave:h,onRemove:m,onClose:d})]})}function xs(e,t){const n=e==null?void 0:e.parentElement;if(!n||!n.hasAttribute("data-placeholder"))return;t.length===0||t.every(ul)?n.setAttribute("data-empty",""):n.removeAttribute("data-empty")}function gu(e={}){return{fontWeight:e.bold?"bold":void 0,fontStyle:e.italic?"italic":void 0,textDecoration:[(e.underline||e.link)&&"underline",e.strike&&"line-through"].filter(Boolean).join(" ")||void 0,verticalAlign:e.subscript?"sub":e.superscript?"super":void 0,fontSize:e.subscript||e.superscript?"smaller":void 0,color:e.color||(e.link?"var(--noteloom-accent)":void 0),backgroundColor:e.highlight||void 0,cursor:e.link?"pointer":void 0}}function xu(e,t){const n=e.childNodes.length===1?e.firstChild:null;n&&n.nodeType===3?n.nodeValue!==t&&(n.nodeValue=t):e.textContent=t}function ku({id:e,host:t,onValueSynced:n}){const r=xt(e);return p.useLayoutEffect(()=>{var u;if(!t||!r)return;const o=r.value??"";(nt(t.textContent)!==o||o===""&&t.textContent==="")&&xu(t,o===""?cl:o);const i=gu(r.marks);t.style.fontWeight=i.fontWeight??"",t.style.fontStyle=i.fontStyle??"",t.style.textDecoration=i.textDecoration??"",t.style.verticalAlign=i.verticalAlign??"",t.style.fontSize=i.fontSize??"",t.style.color=i.color??"",t.style.backgroundColor=i.backgroundColor??"",t.style.cursor=i.cursor??"";const c=(u=r.marks)==null?void 0:u.link;t.title=c!=null&&c.href?`${c.href} — Ctrl+Click to open`:"",t.onclick=c!=null&&c.href?f=>{!f.ctrlKey&&!f.metaKey||(f.preventDefault(),window.open(c.href,c.target==="_blank"?"_blank":"_self","noopener,noreferrer"))}:null,n==null||n()},[t,r,n]),null}function ks(e,t,n,r){var d,h,m;const o=(d=window.getSelection)==null?void 0:d.call(window);if(!o||!o.isCollapsed||o.rangeCount===0)return null;const{anchorNode:s,anchorOffset:l}=o;if(!s||!e.contains(s))return null;const i=g=>{const x=t.indexOf(g);if(x===-1)return null;const k=r?t[x-1]:t[x+1];if(!k)return null;const y=n(k);return y&&y.type!=="text"?k:null};if(s===e){const g=r?l-1:l,x=e.childNodes[g],k=(x==null?void 0:x.nodeType)===1?(h=x.dataset)==null?void 0:h.runId:void 0;if(!k||t.indexOf(k)===-1)return null;const y=n(k);return y&&y.type!=="text"?k:null}const c=s.nodeType===1?s:s.parentElement,u=(m=c==null?void 0:c.closest)==null?void 0:m.call(c,"[data-run-id]");return!u||!e.contains(u)||!(r?l===0:l===(s.textContent??"").length)?null:i(u.getAttribute("data-run-id"))}function ys(e,t,n){var c,u;const r=(c=window.getSelection)==null?void 0:c.call(window);if(!r||r.isCollapsed||r.rangeCount===0)return null;const o=r.getRangeAt(0);if(o.startContainer!==o.endContainer||!e.contains(o.startContainer)||o.endOffset!==o.startOffset+1)return null;const s=o.startContainer.childNodes[o.startOffset],l=(s==null?void 0:s.nodeType)===1?(u=s.dataset)==null?void 0:u.runId:void 0;if(!l||t.indexOf(l)===-1)return null;const i=n(l);return i&&i.type!=="text"?l:null}function vs(e,t,n){var i;if(t===e)return{childIndex:n,charOffset:null};const r=t.nodeType===1?t:t.parentElement,o=(i=r==null?void 0:r.closest)==null?void 0:i.call(r,"[data-run-id]");if(!o||!e.contains(o))return null;const s=Array.prototype.indexOf.call(e.childNodes,o),l=t===o?n===0?0:(o.textContent??"").length:n;return{childIndex:s,charOffset:l}}function yu(e,t,n,r){const o=vs(e,r.startContainer,r.startOffset),s=vs(e,r.endContainer,r.endOffset);if(!o||!s)return null;const l=Array.from(e.childNodes).filter(f=>{var d;return f.nodeType===1&&((d=f.dataset)==null?void 0:d.runId)&&t.indexOf(f.dataset.runId)!==-1});let i=!1;const c=[];let u=null;return l.forEach((f,d)=>{const h=f.dataset.runId,m=n(h);if(!m)return;const g=d<o.childIndex,x=s.charOffset===null?d>=s.childIndex:d>s.childIndex;if(g||x){c.push(m);return}const k=o.charOffset!==null&&d===o.childIndex,y=s.charOffset!==null&&d===s.childIndex;if(m.type!=="text"){i=!0,u===null&&(u=c.length);return}const I=m.value??"";if(k&&y){const w=I.slice(0,o.charOffset)+I.slice(s.charOffset);w&&c.push({...m,value:w}),u=c.length}else if(k){const w=I.slice(0,o.charOffset);w&&c.push({...m,value:w}),u===null&&(u=c.length)}else if(y){const w=I.slice(s.charOffset);w&&c.push({id:N(),type:"text",value:w,marks:m.marks})}}),i?{nextRuns:c,insertionIndex:u??c.length}:null}function vu(e){var s;const t=(s=window.getSelection)==null?void 0:s.call(window);if(!t||!t.isCollapsed)return!1;const n=e.firstChild;if(!n)return!0;if(t.anchorNode===e)return t.anchorOffset===0;let r=n;for(;r&&r.firstChild;)r=r.firstChild;if(t.anchorNode!==r&&t.anchorNode!==n)return!1;const o=r.nodeType===3&&r.textContent===cl?1:0;return t.anchorOffset<=o}function wu(e){var s;const t=(s=window.getSelection)==null?void 0:s.call(window);if(!t||!t.isCollapsed)return!1;const n=e.lastChild;if(!n)return!0;if(t.anchorNode===e)return t.anchorOffset>=e.childNodes.length;let r=n;for(;r&&r.lastChild;)r=r.lastChild;if(t.anchorNode!==r&&t.anchorNode!==n)return!1;const o=r.nodeType===3?(r.textContent??"").length:0;return t.anchorOffset>=o}function ws(e,t,n){const r=e.getBlock(t),o=e.getBlock(r==null?void 0:r.parentId);if(!o)return null;const s=o.contentIds.indexOf(t),l=n==="backward"?s-1:s+1;if(l<0||l>=o.contentIds.length)return null;const i=o.contentIds[l];return Sn(e,e.getBlock(i))?i:null}function Iu({id:e,blockId:t,host:n,inlineRegistry:r,onValueSynced:o}){const s=xt(e);if(!s)return null;if(s.type==="text")return a.jsx(ku,{id:e,host:n,onValueSynced:o});const l=r==null?void 0:r.get(s.type);if(!l)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No inline type registered for "${s.type}" (run: ${e})`),null;const i=l.component;return a.jsx(i,{id:e,blockId:t})}function Cu(e,t,n){let r=e.get(n);if(!r){r=document.createElement("span"),r.dataset.runId=n;const o=t.getRun(n);o&&o.type!=="text"&&r.setAttribute("contenteditable","false"),e.set(n,r)}return r}function it({blockId:e,runIds:t,dir:n="auto",onEnter:r,onBackspaceAtStart:o,onDeleteAtEnd:s,onArrowUp:l,onArrowDown:i,onTab:c,onShiftTab:u,onAutoformat:f}){const d=q(),h=Je(),{getSelectedBlockId:m,setSelectedBlockId:g}=lt(),x=p.useRef(null),k=p.useRef(!1),y=p.useRef(new Map);p.useLayoutEffect(()=>{const C=x.current;if(!C)return;const B=new Set(t);for(const[z,Y]of y.current)B.has(z)||(Y.remove(),y.current.delete(z));let M=null;for(const z of t){const Y=y.current.get(z);if(!Y)continue;const W=M?M.nextSibling:C.firstChild;W!==Y&&C.insertBefore(Y,W),M=Y}},[t]);const I=p.useCallback(()=>{if(k.current)return;const C=x.current;if(!C)return;const B=t.map(W=>d.getRun(W)).filter(Boolean),{runs:M,changed:z,onlyValueChanges:Y}=Yc(C,B);if(z){if(Y){if(M.forEach((W,ie)=>{W!==B[ie]&&d.applyOperation(ue(W.id,{value:W.value}))}),f!=null&&f(M))return}else d.applyOperation(_e(e,M.length?M:[{id:N(),type:"text",value:"",marks:{}}]));xs(C,M)}},[d,e,t,f]),w=p.useCallback(()=>{xs(x.current,t.map(C=>d.getRun(C)).filter(Boolean))},[d,t]),j=p.useCallback(()=>{k.current=!0},[]),S=p.useCallback(()=>{k.current=!1,I()},[I]),v=p.useCallback(C=>{const M=t.map(z=>d.getRun(z)).filter(Boolean).filter(z=>z.id!==C);d.applyOperation(_e(e,M.length?M:[{id:N(),type:"text",value:"",marks:{}}]))},[d,e,t]),R=p.useCallback(C=>{m()===C?(d.applyOperation(J(C)),g(null)):g(C)},[d,m,g]),_=p.useCallback(C=>{var Re,le,ke,fe;if(k.current)return;if(C.target instanceof Node){const P=C.target.nodeType===1?C.target:C.target.parentElement;if((Re=P==null?void 0:P.closest)!=null&&Re.call(P,'[contenteditable="false"]'))return}const B=C.inputType??"",M=B.startsWith("delete"),z=B==="insertText"||B==="insertReplacementText";if(!M&&!z)return;const Y=x.current;if(!Y)return;const W=(le=C.getTargetRanges)==null?void 0:le.call(C),ie=(ke=window.getSelection)==null?void 0:ke.call(window),ae=(W==null?void 0:W[0])??(ie!=null&&ie.rangeCount?ie.getRangeAt(0):null);if(!ae||!Y.contains(ae.startContainer)||!Y.contains(ae.endContainer))return;const G=yu(Y,t,P=>d.getRun(P),ae);if(!G)return;C.preventDefault();let{nextRuns:se,insertionIndex:H}=G,Q=null,ee=!1;if(z&&C.data){const P={id:N(),type:"text",value:C.data,marks:{}};se=[...se.slice(0,H),P,...se.slice(H)],Q=P.id,ee=!1}else H>0?(Q=(fe=se[H-1])==null?void 0:fe.id,ee=!1):se.length>0&&(Q=se[0].id,ee=!0);const re=se.length?se:[{id:N(),type:"text",value:"",marks:{}}];d.applyOperation(_e(e,re));const be=Q??re[0].id;ee?rr(be):xe(be)},[d,e,t]);p.useEffect(()=>{const C=x.current;if(C)return C.addEventListener("beforeinput",_),()=>C.removeEventListener("beforeinput",_)},[_]);const O=p.useCallback(C=>{if(!k.current){if(C.key==="Enter"&&r){C.preventDefault(),r(C);return}if(C.key==="Backspace"){const B=x.current,M=B&&ys(B,t,d.getRun.bind(d));if(M){C.preventDefault(),v(M);return}const z=B&&ks(B,t,d.getRun.bind(d),!0);if(z){C.preventDefault(),v(z);return}if(B&&vu(B)){if(!Ne(d,t)){const W=ws(d,e,"backward");if(W){C.preventDefault(),R(W);return}}C.preventDefault(),o&&o(C)}return}if(C.key==="Delete"){const B=x.current,M=B&&ys(B,t,d.getRun.bind(d));if(M){C.preventDefault(),v(M);return}const z=B&&ks(B,t,d.getRun.bind(d),!1);if(z){C.preventDefault(),v(z);return}if(B&&wu(B)){const Y=ws(d,e,"forward");if(Y){C.preventDefault(),R(Y);return}s&&s(C)}return}if(C.key==="ArrowUp"&&l){C.preventDefault(),l(C);return}if(C.key==="ArrowDown"&&i){C.preventDefault(),i(C);return}C.key==="Tab"&&(C.shiftKey&&u?(C.preventDefault(),u(C)):!C.shiftKey&&c&&(C.preventDefault(),c(C)))}},[r,o,s,l,i,c,u,v,R,t,e,d]);return a.jsxs(a.Fragment,{children:[a.jsx("span",{ref:x,className:"be-editable",dir:n,contentEditable:!0,suppressContentEditableWarning:!0,onInput:I,onCompositionStart:j,onCompositionEnd:S,onKeyDown:O,children:t.map(C=>{const B=Cu(y.current,d,C);return Xe.createPortal(a.jsx(Iu,{id:C,blockId:e,host:B,inlineRegistry:h,onValueSynced:w},C),B)})}),a.jsx(mu,{containerRef:x,store:d})]})}function Su(e,t,n){const r=e.getBlock(t),o=r&&e.getBlock(r.parentId);if(!o)return null;const s=o.contentIds.indexOf(t),l=n==="up"?s-1:s+1;return l<0||l>=o.contentIds.length?null:o.contentIds[l]}function Ol(e,t,n){let r=t;for(;;){const o=Su(e,r,n);if(!o)return null;const s=n==="up"?ur(e,o):bo(e,o);if(s)return s;r=o}}function Le(e,t,n){const r=Ol(e,t,n);r&&xe(r)}function bo(e,t){var s;const n=e.getBlock(t);if(!n)return null;const r=((s=n.props)==null?void 0:s.titleRunIds)??n.contentIds;if(!r||r.length===0)return null;const o=r[0];return e.getRun(o)?o:bo(e,o)}function Te(e,t){const n=bo(e,t);n&&xe(n)}function ur(e,t){var s;const n=e.getBlock(t);if(!n)return null;const r=((s=n.props)==null?void 0:s.titleRunIds)??n.contentIds;if(!r||r.length===0)return null;const o=r[r.length-1];return e.getRun(o)?o:ur(e,o)}function Is(e,t){const n=ur(e,t);n&&xe(n)}function Tu(){var i,c;const e=(i=window.getSelection)==null?void 0:i.call(window);if(!e||e.rangeCount===0)return null;const t=e.getRangeAt(0);if(t.collapsed||t.startContainer!==t.endContainer)return null;const n=t.startContainer,r=n.nodeType===1?n:n.parentElement,o=(c=r==null?void 0:r.closest)==null?void 0:c.call(r,"[data-run-id]");if(!o)return null;const s=o.closest("[data-block-id]");if(!s)return null;const l=n.textContent??"";return{runId:o.getAttribute("data-run-id"),blockId:s.getAttribute("data-block-id"),startOffset:nt(l.slice(0,t.startOffset)).length,endOffset:nt(l.slice(0,t.endOffset)).length}}function Ru(e,t){var i,c;if((e==null?void 0:e.nodeType)!==1||((i=e.getAttribute)==null?void 0:i.call(e,"contenteditable"))!=="true")return null;const n=e.childNodes;if(n.length===0)return null;const r=t>=n.length,o=n[r?n.length-1:Math.max(0,t)],s=(o==null?void 0:o.nodeType)===1?(c=o.dataset)==null?void 0:c.runId:void 0;if(!s)return null;const l=o.closest("[data-block-id]");return l?{runId:s,blockId:l.getAttribute("data-block-id"),offset:r?nt(o.textContent??"").length:0}:null}function yn(e,t){var i;const n=Ru(e,t);if(n)return n;let r=(e==null?void 0:e.nodeType)===1?e:e==null?void 0:e.parentElement;const o=(i=r==null?void 0:r.closest)==null?void 0:i.call(r,"[data-run-id]");if(!o)return null;const s=o.closest("[data-block-id]");if(!s)return null;let l=nt((e.textContent??"").slice(0,t)).length;if(e===o){l=0;for(let c=0;c<t&&c<o.childNodes.length;c+=1)l+=nt(o.childNodes[c].textContent??"").length}return{runId:o.getAttribute("data-run-id"),blockId:s.getAttribute("data-block-id"),offset:l}}function rt(){var t;const e=(t=window.getSelection)==null?void 0:t.call(window);return!e||e.rangeCount===0||!e.isCollapsed?null:yn(e.anchorNode,e.anchorOffset)}function tn(){var r;const e=(r=window.getSelection)==null?void 0:r.call(window);if(!e||e.rangeCount===0||e.isCollapsed)return null;const t=yn(e.anchorNode,e.anchorOffset),n=yn(e.focusNode,e.focusOffset);return!t||!n||t.blockId!==n.blockId?null:{blockId:t.blockId,startRunId:t.runId,startOffset:t.offset,endRunId:n.runId,endOffset:n.offset}}function Gt(e){var d;const t=(d=window.getSelection)==null?void 0:d.call(window);if(!t||t.rangeCount===0||t.isCollapsed)return null;const n=yn(t.anchorNode,t.anchorOffset),r=yn(t.focusNode,t.focusOffset);if(!n||!r||n.blockId===r.blockId)return null;const o=e.getBlock(n.blockId),s=o&&e.getBlock(o.parentId);if(!s)return null;const l=s.contentIds,i=l.indexOf(n.blockId),c=l.indexOf(r.blockId);if(i===-1||c===-1)return null;const[u,f]=i<=c?[i,c]:[c,i];return{blockIds:l.slice(u,f+1),startBlockId:n.blockId,startRunId:n.runId,startOffset:n.offset,endBlockId:r.blockId,endRunId:r.runId,endOffset:r.offset}}function dr(e,t,n){const o=e.getBlock(t).parentId,l=e.getBlock(o).contentIds.indexOf(t)+1,{block:i,runs:c=[],subtreeBlocks:u=[]}=n(o);return e.applyOperation(ge(i,o,l,{blocks:[i,...u],runs:c})),i.id}function Ze(e,t,n){const r=dr(e,t,n);return Te(e,r),r}function ju(e,t,n){const{block:r,runs:o=[],subtreeBlocks:s=[]}=n(t);return e.applyOperation(ge(r,t,0,{blocks:[r,...s],runs:o})),Te(e,r.id),r.id}function _l(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Bu(e,t,n){const r=e.findIndex(u=>u.id===t);if(r===-1)return null;const o=e[r],s=e.slice(0,r),l=e.slice(r+1);if(o.type==="text"){const u=o.value??"",f=u.slice(0,n),d=u.slice(n);f&&d?(s.push({...o,value:f}),l.unshift({...o,id:N(),value:d})):d?l.unshift(o):s.push(o)}else n>0?s.push(o):l.unshift(o);const i=s.length?s:[{id:N(),type:"text",value:"",marks:{}}],c=l.length?l:[{id:N(),type:"text",value:"",marks:{}}];return{leftRuns:i,rightRuns:c}}function nn(e,t,n,r){const o=e.getBlock(t),s=e.getBlock(o.parentId),l=s.contentIds.indexOf(t)+1;return Ml(e,t,n,r,{insertParentId:s.id,insertIndex:l,fallback:()=>Ze(e,t,r)})}function Nl(e,t,n,r){return Ml(e,t,n,r,{insertParentId:t,insertIndex:0,fallback:()=>ju(e,t,r)})}function Ml(e,t,n,r,{insertParentId:o,insertIndex:s,fallback:l}){const i=rt();if(!i||i.blockId!==t)return l();const c=n.map(k=>e.getRun(k)).filter(Boolean),u=Bu(c,i.runId,i.offset);if(!u)return l();const{leftRuns:f,rightRuns:d}=u,{block:h,runs:m=d,subtreeBlocks:g=[]}=r(o,d),x=f.length?f:[{id:N(),type:"text",value:"",marks:{}}];return _l(e,[_e(t,x),ge(h,o,s,{blocks:[h,...g],runs:m})]),Te(e,h.id),h.id}function Eu(e){var t;return((t=e==null?void 0:e.props)==null?void 0:t.titleRunIds)??(e==null?void 0:e.contentIds)??[]}function Lu(e){var t,n;return!!((t=e==null?void 0:e.props)!=null&&t.titleRunIds)&&(((n=e.contentIds)==null?void 0:n.length)??0)>0}function Ou(e,t,n){const o=e.getBlock(t).parentId,l=e.getBlock(o).contentIds.indexOf(t),{block:i,runs:c=[],subtreeBlocks:u=[]}=n(o);return _l(e,[J(t),ge(i,o,l,{blocks:[i,...u],runs:c})]),Te(e,i.id),i.id}function Ee(e,{blockId:t,runId:n,sliceStart:r,sliceEnd:o},s){const l=e.getRun(n),i=(l==null?void 0:l.value)??"",c=i.slice(0,r)+i.slice(o),u=e.getBlock(t),f=Eu(u);return f.length===1&&f[0]===n&&c===""&&!Lu(u)?Ou(e,t,s):(e.applyOperation(ue(n,{value:c})),Ze(e,t,s))}function Z(e,t={}){return function(r,o){const s=N(),l=o!=null&&o.length?o:[{id:N(),type:"text",value:"",marks:{}}];return{block:{id:s,type:e,parentId:r,contentIds:l.map(i=>i.id),props:t},runs:l}}}function rn(e){const t=e.getRootId(),n=e.getBlock(t);if(!n||n.contentIds.length>0)return null;const{block:r,runs:o}=Z("paragraph")(t);return e.applyOperation(ge(r,t,0,{blocks:[r],runs:o})),r.id}const _u=new Set(["callout"]),Cs=new Set(["paragraph","heading","blockquote"]);function Al(e,t){return e===t||Cs.has(e)&&Cs.has(t)}function Tn(e,t){const n=e.getBlock(t);if(!n)return null;const r=e.getBlock(n.parentId),o=r.contentIds.indexOf(t),s=n.contentIds.length===0||n.contentIds.length===1&&Nu(e,n.contentIds[0]);if(o<=0){if(!s)return null;if(r.contentIds.length>1)return Vt(e,[J(t)]),e.getBlock(r.id).contentIds[0];if(_u.has(r.type))return Mu(e,r);if(n.type==="paragraph")return null;const{block:u,runs:f}=Z("paragraph")(r.id);return Vt(e,[ge(u,r.id,o,{blocks:[u],runs:f}),J(t)]),u.id}const l=r.contentIds[o-1],i=e.getBlock(l);if(s)return Vt(e,[J(t)]),l;if(Sn(e,i))return Vt(e,[J(l)]),t;if(!i||!Al(i.type,n.type))return null;const c=[...i.contentIds,...n.contentIds];return Vt(e,[qt(l,c),qt(t,[]),J(t)]),l}function Nu(e,t){const n=e.getRun(t);return!n||(n.value??"")===""}function Mu(e,t){const n=e.getBlock(t.parentId);if(!n)return null;const r=n.contentIds.indexOf(t.id),o=r>0?n.contentIds[r-1]:null,s=r!==-1&&r<n.contentIds.length-1?n.contentIds[r+1]:null;Vt(e,[J(t.id)]);const l=rn(e);return o??s??l}function Vt(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function on(e,t,n,r){if(!t||t===n)return;const o=ur(e,t);if(o){xe(o);return}r(t),requestAnimationFrame(()=>{var s;(s=document.querySelector(`[data-block-id="${t}"]`))==null||s.focus()})}function ot(e,t){var r,o;if(!t)return"auto";if((r=t.props)!=null&&r.dir)return t.props.dir;const n=e.getBlock(e.getRootId());return((o=n==null?void 0:n.props)==null?void 0:o.dir)??"auto"}function mo(e,t,n,r,o,s){const l=e.getBlock(t),c=e.getBlock(l.parentId).contentIds.indexOf(t),u="titleRunIds"in r,f="titleRunIds"in(l.props??{}),d=s?!s.isLeaf(l.type)&&l.contentIds.length>0:!1,h=s?!s.isLeaf(n):!1,m=[];if(d&&!h&&l.contentIds.forEach((g,x)=>m.push(st(g,l.parentId,c+1+x))),m.push(Qr(t,n,r)),u)m.push(X(t,{titleRunIds:o})),!f&&!d&&m.push(qt(t,[]));else{const g=d&&h?l.contentIds:[];m.push(qt(t,[...g,...o]))}return{newBlockId:t,ops:m}}function Au(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}const Du=[{re:/^(#{1,3})[ ]$/,type:"heading",props:e=>({level:e[1].length})},{re:/^[-*][ ]$/,type:"listItem",props:()=>({ordered:!1,titleRunIds:[]})},{re:/^\d+\.[ ]$/,type:"listItem",props:()=>({ordered:!0,titleRunIds:[]})},{re:/^\[\][ ]$/,type:"listItem",props:()=>({ordered:!1,checked:!1,titleRunIds:[]})},{re:/^>[ ]$/,type:"blockquote",props:()=>({})},{re:/^```$/,type:"code",props:()=>({language:"plaintext"})}];function Pu(e,t,n){if(n.length!==1||n[0].type!=="text")return!1;const r=n[0].value??"";for(const o of Du){const s=o.re.exec(r);if(!s)continue;const l=r.slice(s[0].length),{ops:i}=mo(e,t,o.type,o.props(s),[n[0].id]);return Au(e,[ue(n[0].id,{value:l}),...i]),rr(n[0].id),!0}return!1}const $u=new Set(["callout","toggleHeading"]);function zu({id:e}){const t=q(),n=he(e),{setSelectedBlockId:r}=lt(),o=p.useCallback(()=>{const h=t.getBlock(n==null?void 0:n.parentId),m=Ne(t,(n==null?void 0:n.contentIds)??[]),g=!!h&&h.contentIds[h.contentIds.length-1]===e;if(m&&g&&$u.has(h==null?void 0:h.type)){Ze(t,h.id,Z("paragraph"));return}nn(t,e,(n==null?void 0:n.contentIds)??[],Z("paragraph"))},[t,e,n]),s=p.useCallback(()=>{var k,y;const h=t.getBlock(n==null?void 0:n.parentId),m=Ne(t,(n==null?void 0:n.contentIds)??[]),g=((k=h==null?void 0:h.contentIds)==null?void 0:k.length)===1&&h.contentIds[0]===e;if(m&&g&&(h==null?void 0:h.type)==="toggleHeading"){const I=((y=h.props)==null?void 0:y.titleRunIds)??[],w=I[I.length-1];w&&xe(w);return}const x=Tn(t,e);on(t,x,e,r)},[t,e,n,r]),l=p.useCallback(()=>Le(t,e,"up"),[t,e]),i=p.useCallback(()=>Le(t,e,"down"),[t,e]),c=p.useCallback(h=>Pu(t,e,h),[t,e]),u=we("be-paragraph",n);if(!n)return null;const f=Ne(t,n.contentIds),d=ot(t,n);return a.jsx("div",{className:u,"data-block-id":e,"data-empty":f?"":void 0,"data-placeholder":"Type '/' for commands",dir:d,children:a.jsx(it,{blockId:e,runIds:n.contentIds,dir:d,onEnter:o,onBackspaceAtStart:s,onArrowUp:l,onArrowDown:i,onAutoformat:c})})}function St(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Be(e){return St(e).replace(/"/g,""")}function ct(e,t){var o,s;if(!e)return"";if(e.type!=="text"){const l=(o=t==null?void 0:t.inlineRegistry)==null?void 0:o.get(e.type);return l?l.toHTML(e,t):St(e.value??"")}const n=e.marks??{};let r=St(e.value??"");if(n.code&&(r=`<code>${r}</code>`),n.bold&&(r=`<strong>${r}</strong>`),n.italic&&(r=`<em>${r}</em>`),n.underline&&(r=`<u>${r}</u>`),n.strike&&(r=`<s>${r}</s>`),n.subscript&&(r=`<sub>${r}</sub>`),n.superscript&&(r=`<sup>${r}</sup>`),n.color&&(r=`<span style="color:${Be(n.color)}">${r}</span>`),n.highlight&&(r=`<span style="background-color:${Be(n.highlight)}">${r}</span>`),(s=n.link)!=null&&s.href){const l=n.link.target==="_blank"?' target="_blank" rel="noopener noreferrer"':"";r=`<a href="${Be(n.link.href)}"${l}>${r}</a>`}return r}function Or(e,t){return(e??[]).map(n=>ct(n,t)).join("")}function kt(e,t){var n;if(!e)return"";if(e.type!=="text"){const r=(n=t==null?void 0:t.inlineRegistry)==null?void 0:n.get(e.type);return r?r.toPlainText(e,t):e.value??""}return e.value??""}const Hu={STRONG:"bold",B:"bold",EM:"italic",I:"italic",U:"underline",S:"strike",STRIKE:"strike",DEL:"strike",CODE:"code",SUB:"subscript",SUP:"superscript"};function Fe(e,t,n={}){const r=[],o=(s,l)=>{var u,f;if(s.nodeType===3){const d=s.textContent;d&&r.push({id:N(),type:"text",value:d,marks:{...l}});return}if(s.nodeType!==1)return;if(t!=null&&t.inlineRegistry)for(const d of t.inlineRegistry.listHtmlMatchers()){const h=d.fromHTML(s,t);if(h){r.push(h);return}}let i=l;const c=Hu[s.tagName];c&&(i={...i,[c]:!0}),s.tagName==="A"&&s.getAttribute("href")&&(i={...i,link:{href:s.getAttribute("href"),target:s.getAttribute("target")==="_blank"?"_blank":"_self"}}),(u=s.style)!=null&&u.color&&(i={...i,color:s.style.color}),(f=s.style)!=null&&f.backgroundColor&&(i={...i,highlight:s.style.backgroundColor});for(const d of s.childNodes)o(d,i)};return o(e,n),r.length?r:[{id:N(),type:"text",value:"",marks:{}}]}function Fu(e,t){return`<p>${e.contentIds.map(r=>t.store.getRun(r)).map(r=>ct(r,t)).join("")}</p>`}function Uu(e,t){return e.contentIds.map(n=>kt(t.store.getRun(n),t)).join("")}function Yu(e,t){if(e.tagName!=="P")return null;const n=Fe(e,t);return{block:{id:N(),type:"paragraph",parentId:null,contentIds:n.map(o=>o.id),props:{}},runs:n}}const Dl={component:zu,isLeaf:!0,defaultProps:{},toHTML:Fu,toPlainText:Uu,fromHTML:Yu,slashCommand:{label:"Text",icon:io,keywords:["paragraph","text","p"],run:(e,t)=>Ee(e,t,Z("paragraph"))}};function Ku({id:e}){var m;const t=q(),n=he(e),{setSelectedBlockId:r}=lt(),o=p.useCallback(()=>{nn(t,e,(n==null?void 0:n.contentIds)??[],Z("paragraph"))},[t,e,n]),s=p.useCallback(()=>{const g=Tn(t,e);on(t,g,e,r)},[t,e,r]),l=p.useCallback(()=>Le(t,e,"up"),[t,e]),i=p.useCallback(()=>Le(t,e,"down"),[t,e]),c=((m=n==null?void 0:n.props)==null?void 0:m.level)??3,u=we(`be-heading be-heading-${c}`,n);if(!n)return null;const f=`h${c}`,d=Ne(t,n.contentIds),h=ot(t,n);return a.jsx(f,{className:u,"data-block-id":e,"data-empty":d?"":void 0,"data-placeholder":`Heading ${c}`,dir:h,children:a.jsx(it,{blockId:e,runIds:n.contentIds,dir:h,onEnter:o,onBackspaceAtStart:s,onArrowUp:l,onArrowDown:i})})}const _r={1:Cl,2:Sl,3:Tl},Vu={H1:1,H2:2,H3:3};function Wu(e,t){var o;const n=((o=e.props)==null?void 0:o.level)??3,r=e.contentIds.map(s=>t.store.getRun(s));return`<h${n}>${r.map(s=>ct(s,t)).join("")}</h${n}>`}function Xu(e,t){return e.contentIds.map(n=>kt(t.store.getRun(n),t)).join("")}function qu(e,t){const n=Vu[e.tagName];if(!n)return null;const r=Fe(e,t);return{block:{id:N(),type:"heading",parentId:null,contentIds:r.map(s=>s.id),props:{level:n}},runs:r}}const Pl={component:Ku,isLeaf:!0,defaultProps:{level:3},toHTML:Wu,toPlainText:Xu,fromHTML:qu,slashCommands:[{label:"Heading 1",icon:_r[1],keywords:["heading","h1","title"],run:(e,t)=>Ee(e,t,Z("heading",{level:1}))},{label:"Heading 2",icon:_r[2],keywords:["heading","h2","subtitle"],run:(e,t)=>Ee(e,t,Z("heading",{level:2}))},{label:"Heading 3",icon:_r[3],keywords:["heading","h3","title"],run:(e,t)=>Ee(e,t,Z("heading",{level:3}))}]},Gu=[];function go(e){const t=q(),n=p.useCallback(o=>t.subscribe(e,o),[t,e]),r=p.useCallback(()=>{const o=t.getBlock(e);return o?o.contentIds:Gu},[t,e]);return p.useSyncExternalStore(n,r)}class $l extends p.Component{constructor(){super(...arguments);ds(this,"state",{hasError:!1,nonce:0})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n,r){var o,s;process.env.NODE_ENV!=="production"&&console.error("[block-editor] a block failed to render; recovering by remounting it:",n,r),(s=(o=this.props).onError)==null||s.call(o,n,r),queueMicrotask(()=>this.setState(l=>({hasError:!1,nonce:l.nonce+1})))}render(){return this.state.hasError?null:a.jsx(p.Fragment,{children:this.props.children},this.state.nonce)}}const xo=p.memo(function({id:t}){const n=he(t),r=gt();if(!n)return null;const o=r.get(n.type);if(!o)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No block type registered for "${n.type}" (id: ${t})`),null;const s=o.component;return a.jsx($l,{children:a.jsx(s,{id:t})})});function He(e,t,n){p.useEffect(()=>{if(!t)return;const r=Array.isArray(e)?e:[e],o=l=>{r.some(c=>c.current&&c.current.contains(l.target))||n()},s=l=>{l.key==="Escape"&&n()};return document.addEventListener("mousedown",o),document.addEventListener("keydown",s),()=>{document.removeEventListener("mousedown",o),document.removeEventListener("keydown",s)}},[t,n,e])}function pr(e,t,n,r){const o=p.useRef(!1),s=p.useRef(!1);p.useEffect(()=>{var f,d;if(!t){s.current=!1,o.current&&(o.current=!1,(d=(f=r==null?void 0:r.current)==null?void 0:f.focus)==null||d.call(f));return}o.current=!0;const l=e.current;if(!l)return;const i=()=>Array.from(l.querySelectorAll('[role="menuitem"]')),c=h=>{var x;const m=i();if(m.length===0)return;const g=(h%m.length+m.length)%m.length;(x=m[g])==null||x.focus()};s.current||(s.current=!0,c(0));const u=h=>{if(h.key==="Escape"){h.preventDefault(),n();return}const m=i(),g=m.indexOf(document.activeElement);g!==-1&&(h.key==="ArrowDown"?(h.preventDefault(),c(g+1)):h.key==="ArrowUp"?(h.preventDefault(),c(g-1)):h.key==="Home"?(h.preventDefault(),c(0)):h.key==="End"&&(h.preventDefault(),c(m.length-1)))};return l.addEventListener("keydown",u),()=>l.removeEventListener("keydown",u)})}const Ss="be-live-region";function Ju(){if(typeof document>"u")return null;let e=document.getElementById(Ss);return e||(e=document.createElement("div"),e.id=Ss,e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.setAttribute("aria-atomic","true"),Object.assign(e.style,{position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:"0",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:"0"}),document.body.appendChild(e),e)}function me(e){const t=Ju();t&&(t.textContent="",setTimeout(()=>{t.textContent=e},0))}const sn="💡",zl="gray";function Zu({icon:e=sn,color:t=zl}={}){return function(r){const o=N(),{block:s,runs:l}=Z("paragraph")(o);return{block:{id:o,type:"callout",parentId:r,contentIds:[s.id],props:{icon:e,color:t}},runs:l,subtreeBlocks:[s]}}}const Hl=[{type:"paragraph",props:{},label:"Text",icon:io},{type:"heading",props:{level:1},label:"Heading 1",icon:Cl},{type:"heading",props:{level:2},label:"Heading 2",icon:Sl},{type:"heading",props:{level:3},label:"Heading 3",icon:Tl},{type:"listItem",props:{ordered:!1,titleRunIds:[]},label:"Bulleted list",icon:Bl},{type:"listItem",props:{ordered:!0,titleRunIds:[]},label:"Numbered list",icon:El},{type:"listItem",props:{ordered:!1,checked:!1,titleRunIds:[]},label:"To-do list",icon:po},{type:"listItem",props:{ordered:!1,collapsed:!1,titleRunIds:[]},label:"Toggle list",icon:Ct},{type:"toggleHeading",props:{level:2,collapsed:!1,titleRunIds:[]},label:"Toggle heading",icon:Ct},{type:"blockquote",props:{},label:"Quote",icon:Rl},{type:"callout",props:{icon:sn},label:"Callout",icon:jl},{type:"code",props:{language:"plaintext"},label:"Code",icon:uo}],Qu=new Set(Hl.map(e=>e.type));function ko(e){return Qu.has(e)}function ed(e,t){return e!=null&&e.props&&"titleRunIds"in e.props?e.props.titleRunIds:t&&!t.isLeaf(e==null?void 0:e.type)?[]:(e==null?void 0:e.contentIds)??[]}function Fl(e,t,n,r){const o=e.getBlock(n),s=ed(o,t),l=[];if(r.type==="code")for(const f of s){const d=e.getRun(f);d!=null&&d.marks&&Object.keys(d.marks).length>0&&l.push(ue(f,{marks:{}}))}const i={...r.props},{ops:c,newBlockId:u}=mo(e,n,r.type,i,s,t);return{ops:[...l,...c],newBlockId:u}}function Ul({onSelect:e,onClose:t,containerRef:n,menuClassName:r="be-block-gutter-menu",itemClassName:o="be-block-gutter-menu-item"}){const[s,l]=p.useState(!1),[i,c]=p.useState(null),u=p.useRef(null),f=p.useRef(null),d=p.useCallback(I=>{f.current=I,n&&(n.current=I)},[n]),h=p.useCallback(()=>{l(!1),t==null||t()},[t]);He([u,f],s,h),pr(f,s,h,u);const m=sr(f,s,i==null?void 0:i.top,i?i.right+4:null),g=p.useCallback(()=>{var I;c(((I=u.current)==null?void 0:I.getBoundingClientRect())??null),l(!0)},[]),x=p.useCallback(I=>{e(I),h()},[e,h]),k=p.useCallback(I=>{I.key==="ArrowRight"&&!s&&(I.preventDefault(),g())},[s,g]),y=p.useCallback(I=>{I.key==="ArrowLeft"&&(I.preventDefault(),h())},[h]);return a.jsxs(a.Fragment,{children:[a.jsxs("button",{ref:u,type:"button",role:"menuitem",className:o,"aria-haspopup":"menu","aria-expanded":s,onClick:()=>s?h():g(),onKeyDown:k,children:[a.jsx(Ct,{size:15})," Turn into"]}),s&&m&&Xe.createPortal(a.jsx("div",{ref:d,role:"menu","aria-label":"Turn into",className:r,style:{position:"fixed",top:m.top,left:m.left},onKeyDown:y,children:Hl.map((I,w)=>{const j=I.icon;return a.jsxs("button",{type:"button",role:"menuitem",className:o,onClick:()=>x(I),children:[a.jsx(j,{size:15})," ",I.label]},`${I.type}-${w}`)})}),document.body)]})}function Rn(e,t,n,r){const o={store:e,registry:t,inlineRegistry:r};return{html:td(e,t,n,o),text:n.map(s=>{const l=e.getBlock(s);return t.get(l.type).toPlainText(l,o)}).join(`
|
|
2526
|
+
`),json:JSON.stringify({version:1,blocks:n.map(s=>yo(e,s))})}}function td(e,t,n,r){let o="",s=0;for(;s<n.length;){const l=e.getBlock(n[s]);if(l.type==="listItem"){const i=!!l.props.ordered;let c="",u=s;for(;u<n.length;){const d=e.getBlock(n[u]);if(d.type!=="listItem"||!!d.props.ordered!==i)break;c+=t.get("listItem").toHTML(d,r),u+=1}const f=i?"ol":"ul";o+=`<${f}>${c}</${f}>`,s=u}else if(l.type==="blockquote"){let i="",c=s;for(;c<n.length;){const u=e.getBlock(n[c]);if(u.type!=="blockquote")break;i+=t.get("blockquote").toHTML(u,r),c+=1}o+=`<blockquote>${i}</blockquote>`,s=c}else o+=t.get(l.type).toHTML(l,r),s+=1}return o}function yo(e,t){const n=[],r=[],o=s=>{var c;const l=e.getRun(s);if(l){r.push(l);return}const i=e.getBlock(s);if(i){n.push(i);for(const u of i.contentIds)o(u);for(const u of((c=i.props)==null?void 0:c.titleRunIds)??[])o(u)}};return o(t),{rootId:t,blocks:n,runs:r}}function vo({rootId:e,blocks:t,runs:n}){const r=new Map;for(const c of t)r.set(c.id,N());for(const c of n)r.set(c.id,N());const o=c=>r.get(c)??c,s=t.map(c=>{var u;return{...c,id:o(c.id),parentId:c.parentId?o(c.parentId):c.parentId,contentIds:c.contentIds.map(o),props:{...c.props,...(u=c.props)!=null&&u.titleRunIds?{titleRunIds:c.props.titleRunIds.map(o)}:{}}}}),l=n.map(c=>({...c,id:o(c.id)})),i=o(e);return{block:s.find(c=>c.id===i),runs:l,subtreeBlocks:s.filter(c=>c.id!==i)}}function wo(e,t){const n=e.getBlock(t);if(!n)return null;const r=e.getBlock(n.parentId),o=r.contentIds.indexOf(t),s=yo(e,t),{block:l,runs:i,subtreeBlocks:c}=vo(s);return e.applyOperation(ge(l,r.id,o+1,{blocks:[l,...c],runs:i})),Te(e,l.id),l.id}function Io(e,t){const n=e.getBlock(t),r=n&&e.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(t);return o<=0?!1:(e.applyOperation(st(t,r.id,o-1)),!0)}function Co(e,t){const n=e.getBlock(t),r=n&&e.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(t);return o===-1||o>=r.contentIds.length-1?!1:(e.applyOperation(st(t,r.id,o+1)),!0)}function fr(e,t){const n=e.getBlock(t);if(!n)return null;const r=e.getBlock(n.parentId),o=r.contentIds.indexOf(t),s=o>0?r.contentIds[o-1]:null,l=o!==-1&&o<r.contentIds.length-1?r.contentIds[o+1]:null;e.applyOperation(J(t));const i=rn(e),c=s??l??i;return c&&Te(e,c),c??null}function nd(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Yl({id:e}){var B;const t=q(),n=gt(),r=he(e),[o,s]=p.useState(!1),[l,i]=p.useState(null),c=p.useRef(null),u=p.useRef(null),f=p.useRef(null),d=p.useMemo(()=>[c,u,f],[]),[h]=Cn(),m=h.includes(e),g=p.useCallback(()=>s(!1),[]);He(d,o,g),pr(u,o,g,c);const x=p.useCallback(()=>{var M;i(((M=c.current)==null?void 0:M.getBoundingClientRect())??null),s(!0)},[]),k=sr(u,o,(l==null?void 0:l.bottom)!=null?l.bottom+4:null,l==null?void 0:l.left),y=p.useCallback(()=>{Ze(t,e,Z("paragraph"))},[t,e]),I=p.useCallback(()=>{wo(t,e),me("Block duplicated"),g()},[t,e,g]),w=p.useCallback(()=>{Io(t,e)&&me("Block moved up"),g()},[t,e,g]),j=p.useCallback(()=>{Co(t,e)&&me("Block moved down"),g()},[t,e,g]),S=p.useCallback(()=>{fr(t,e),me("Block deleted"),g()},[t,e,g]),v=!!((B=r==null?void 0:r.props)!=null&&B.hidden),R=p.useCallback(()=>{t.applyOperation(X(e,{hidden:!v})),me(v?"Block shown in preview":"Block hidden in preview"),g()},[t,e,v,g]),_=ot(t,r)==="rtl",O=p.useCallback(()=>{t.applyOperation(X(e,{dir:_?"ltr":"rtl"})),me(_?"Block set to left-to-right":"Block set to right-to-left"),g()},[t,e,_,g]),C=p.useCallback(M=>{const{ops:z}=Fl(t,n,e,M);nd(t,z),me(`Turned into ${M.label}`),g()},[t,n,e,g]);return r?a.jsxs("div",{className:`be-block-row${v?" be-block-row-hidden":""}${m?" be-block-row-range-selected":""}`,"data-block-row-id":e,dir:ot(t,r),children:[a.jsxs("div",{className:`be-block-gutter${o?" be-block-gutter-active":""}`,contentEditable:!1,children:[a.jsx("button",{type:"button",className:"be-block-gutter-btn",onClick:y,"aria-label":"Add block below",children:a.jsx(lo,{size:16})}),a.jsx("button",{ref:c,type:"button",className:"be-block-gutter-btn","aria-label":"More options","aria-haspopup":"menu","aria-expanded":o,onClick:()=>o?g():x(),children:a.jsx(Jc,{size:16})})]}),a.jsx("div",{className:"be-block-row-content",children:a.jsx(xo,{id:e})}),o&&k&&Xe.createPortal(a.jsxs("div",{ref:u,role:"menu","aria-label":"Block options",className:"be-block-gutter-menu",style:{position:"fixed",top:k.top,left:k.left},children:[a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:I,children:[a.jsx(ao,{size:15})," Duplicate"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:w,children:[a.jsx(ir,{size:15})," Move up"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:j,children:[a.jsx(cr,{size:15})," Move down"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:R,children:[v?a.jsx(fo,{size:15}):a.jsx(ho,{size:15}),v?"Show in preview":"Hide in preview"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:O,children:[_?a.jsx(yl,{size:15}):a.jsx(vl,{size:15}),_?"Switch to left-to-right":"Switch to right-to-left"]}),ko(r.type)&&a.jsx(Ul,{onSelect:C,onClose:()=>{},containerRef:f}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item be-block-gutter-menu-item-danger",onClick:S,children:[a.jsx(ar,{size:15})," Delete"]})]}),document.body)]}):null}function ut({parentId:e,isTopLevel:t=!1}){const n=go(e),r=q(),[o]=oo(),s=o?n.filter(l=>{var i,c;return!((c=(i=r.getBlock(l))==null?void 0:i.props)!=null&&c.hidden)}):n;return t&&!o?s.map(l=>a.jsx(Yl,{id:l},l)):s.map(l=>a.jsx(xo,{id:l},l))}const rd=97,od=[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]];function sd(e){let t="";for(;e>0;)e-=1,t=String.fromCharCode(rd+e%26)+t,e=Math.floor(e/26);return t}function ld(e){let t="",n=e;for(const[r,o]of od)for(;n>=r;)t+=o,n-=r;return t}function ad(e){var t,n;return(e==null?void 0:e.type)==="listItem"&&((t=e.props)==null?void 0:t.checked)===void 0&&((n=e.props)==null?void 0:n.collapsed)===void 0}function Ts(e,t){let n=0,r=t;for(;r;){const o=e.getBlock(r.parentId);if(!o||o.type!=="listItem")break;n+=1,r=o}return n}function id(e,t,n){const r=n.indexOf(t.id);let o=1;for(let s=r-1;s>=0;s-=1){const l=e.getBlock(n[s]);if(!ad(l)||!l.props.ordered)break;o+=1}return o}function cd(e,t){const n=(e%3+3)%3;return n===0?`${t}.`:n===1?`${sd(t)}.`:`${ld(t)}.`}const ud=["•","◦","▪"];function dd(e){const t=(e%3+3)%3;return ud[t]}function bn({ordered:e=!1,checked:t,collapsed:n}={}){return function(o,s){const l=N(),i=s!=null&&s.length?s:[{id:N(),type:"text",value:"",marks:{}}],c={ordered:e,titleRunIds:i.map(h=>h.id)};t!==void 0&&(c.checked=t);let u=[],f=[],d=i;if(n!==void 0){c.collapsed=n;const{block:h,runs:m}=Z("paragraph")(l);u=[h.id],f=[h],d=[...i,...m]}return{block:{id:l,type:"listItem",parentId:o,contentIds:u,props:c},runs:d,subtreeBlocks:f}}}function pd(e,t){const n=e.getBlock(t),r=e.getBlock(n.parentId),o=r.contentIds.indexOf(t),s=o>0?r.contentIds[o-1]:null,l=s?e.getBlock(s):null;if(!l||l.type!=="listItem"){Le(e,t,"down");return}e.applyOperation(st(t,s,l.contentIds.length)),Te(e,t)}function Ur(e,t){const n=e.getBlock(t),r=e.getBlock(n.parentId);if(!r||r.type!=="listItem")return;const o=r.parentId,l=e.getBlock(o).contentIds.indexOf(r.id);e.applyOperation(st(t,o,l+1)),Te(e,t)}function cn(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Kl(e,t){var n;return t.length===0||t.length===1&&(((n=e.getRun(t[0]))==null?void 0:n.value)??"")===""}function fd(e,t){const n=t.contentIds??[];if(n.length===0)return!0;if(n.length>1)return!1;const r=e.getBlock(n[0]);return!!r&&r.type==="paragraph"&&Ne(e,r.contentIds)}function hd(e,t){const n=e.getBlock(t);if(!n)return null;const r=e.getBlock(n.parentId),o=r.contentIds.indexOf(t),s=n.props.titleRunIds??[],i=Kl(e,s)&&fd(e,n);if(o>0){const f=r.contentIds[o-1],d=e.getBlock(f);if(i)return cn(e,[J(t)]),{focusBlockId:f,needsRefocus:!0};if(Sn(e,d))return cn(e,[J(f)]),{focusBlockId:t,needsRefocus:!1};if((d==null?void 0:d.type)==="listItem"&&n.contentIds.length===0){const h=[...d.props.titleRunIds??[],...s];return cn(e,[X(f,{titleRunIds:h}),X(t,{titleRunIds:[]}),J(t)]),{focusBlockId:f,needsRefocus:!0}}return null}if(r.type==="listItem")return Ur(e,t),{focusBlockId:t,needsRefocus:!0};if(!i)return null;if(r.contentIds.length>1)return cn(e,[J(t)]),{focusBlockId:e.getBlock(r.id).contentIds[0],needsRefocus:!0};const{block:c,runs:u}=Z("paragraph")(r.id);return cn(e,[ge(c,r.id,o,{blocks:[c],runs:u}),J(t)]),{focusBlockId:c.id,needsRefocus:!0}}function bd(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function md(e,t){const r=e.getBlock(t).parentId,s=e.getBlock(r).contentIds.indexOf(t),{block:l,runs:i}=Z("paragraph")(r);return bd(e,[ge(l,r,s,{blocks:[l],runs:i}),X(t,{titleRunIds:[]}),J(t)]),Te(e,l.id),l.id}function gd(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function xd({id:e}){var R,_;const t=q(),n=he(e),{setSelectedBlockId:r}=lt(),o=go(n==null?void 0:n.parentId),s=p.useCallback(()=>{var ie,ae,G,se,H;const O=((ie=n==null?void 0:n.props)==null?void 0:ie.titleRunIds)??[],C=t.getBlock(n==null?void 0:n.parentId),B=Kl(t,O);if(B&&(C==null?void 0:C.type)==="listItem"){Ur(t,e);return}const M=(((ae=n==null?void 0:n.contentIds)==null?void 0:ae.length)??0)>0;if(B&&(C==null?void 0:C.type)!=="listItem"&&!M){md(t,e);return}const z=((G=n==null?void 0:n.props)==null?void 0:G.checked)!==void 0,Y=((se=n==null?void 0:n.props)==null?void 0:se.collapsed)!==void 0,W=bn({ordered:(H=n==null?void 0:n.props)==null?void 0:H.ordered,checked:z?!1:void 0,collapsed:Y?!1:void 0});M&&!Y?Nl(t,e,O,W):nn(t,e,O,W)},[t,e,n]),l=p.useCallback(()=>pd(t,e),[t,e]),i=p.useCallback(()=>Ur(t,e),[t,e]),c=p.useCallback(()=>{const O=hd(t,e);!O||!O.needsRefocus||on(t,O.focusBlockId,e,r)},[t,e,r]),u=p.useCallback(()=>Le(t,e,"up"),[t,e]),f=p.useCallback(()=>Le(t,e,"down"),[t,e]),d=p.useCallback(()=>{var O;t.applyOperation(X(e,{checked:!((O=n==null?void 0:n.props)!=null&&O.checked)}))},[t,e,(R=n==null?void 0:n.props)==null?void 0:R.checked]),h=p.useCallback(()=>{var C,B;if(!((((C=n==null?void 0:n.contentIds)==null?void 0:C.length)??0)>0)){const{block:M,runs:z}=Z("paragraph")(e);gd(t,[ge(M,e,0,{blocks:[M],runs:z}),X(e,{collapsed:!1})]),xe(M.contentIds[0]);return}t.applyOperation(X(e,{collapsed:!((B=n==null?void 0:n.props)!=null&&B.collapsed)}))},[t,e,n==null?void 0:n.contentIds,(_=n==null?void 0:n.props)==null?void 0:_.collapsed]),m=we("be-list-item",n);if(!n)return null;const{ordered:g,checked:x,collapsed:k,titleRunIds:y=[]}=n.props,I=x!==void 0,w=!I&&k!==void 0,j=n.contentIds.length>0,S=y.map(O=>t.getRun(O)).filter(O=>(O==null?void 0:O.type)==="text").map(O=>O.value).join("").trim(),v=ot(t,n);return a.jsxs("div",{className:m,"data-block-id":e,dir:v,children:[a.jsxs("div",{className:"be-list-item-row",children:[I?a.jsx("input",{type:"checkbox",className:"be-list-checkbox",checked:!!x,onChange:d,"aria-label":S||"To-do item"}):w?a.jsx("button",{type:"button",className:"be-list-toggle-marker",onClick:h,"aria-expanded":!k,"aria-label":j?k?"Expand toggle":"Collapse toggle":"Add content to toggle",children:k?a.jsx(Ct,{}):a.jsx(lr,{})}):a.jsx("span",{className:"be-list-marker","aria-hidden":"true",children:g?cd(Ts(t,n),id(t,n,o)):dd(Ts(t,n))}),a.jsx("div",{className:"be-list-item-title","data-empty":Ne(t,y)?"":void 0,"data-placeholder":I?"To-do":w?"Toggle":"List item",style:x?{textDecoration:"line-through",opacity:.6}:void 0,children:a.jsx(it,{blockId:e,runIds:y,dir:v,onEnter:s,onTab:l,onShiftTab:i,onBackspaceAtStart:c,onArrowUp:u,onArrowDown:f})})]}),(!w||!k)&&a.jsx("div",{className:"be-list-item-children",children:a.jsx(ut,{parentId:e})})]})}function kd(e,t){const{titleRunIds:n=[],ordered:r}=e.props,o=n.map(i=>ct(t.store.getRun(i),t)).join(""),s=e.contentIds.map(i=>t.registry.get(t.store.getBlock(i).type).toHTML(t.store.getBlock(i),t)).join(""),l=s?`<${r?"ol":"ul"}>${s}</${r?"ol":"ul"}>`:"";return`<li>${o}${l}</li>`}function yd(e,t){const{titleRunIds:n=[]}=e.props;return n.map(r=>kt(t.store.getRun(r),t)).join("")}function Vl(e,t){const n=[],r=[];for(const d of e.childNodes)d.nodeType===1&&(d.tagName==="UL"||d.tagName==="OL")?r.push(d):n.push(d);const o=e.ownerDocument.createElement("span");for(const d of n)o.appendChild(d.cloneNode(!0));const s=Fe(o,t),l=N(),i=[...s],c=[],u=[];for(const d of r){const h=d.tagName==="OL";for(const m of d.children){if(m.tagName!=="LI")continue;const g=Vl(m,t);g.block.parentId=l,g.block.props.ordered=h,c.push(g.block,...g.childBlocks),i.push(...g.runs),u.push(g.block.id)}}return{block:{id:l,type:"listItem",parentId:null,contentIds:u,props:{ordered:!1,titleRunIds:s.map(d=>d.id)}},runs:i,childBlocks:c}}function vd(e,t){if(e.tagName!=="LI")return null;const{block:n,runs:r,childBlocks:o}=Vl(e,t);return{block:n,runs:r,subtreeBlocks:o}}const Wl={component:xd,isLeaf:!1,defaultProps:{ordered:!1,titleRunIds:[]},toHTML:kd,toPlainText:yd,fromHTML:vd,slashCommands:[{label:"Bulleted list",icon:Bl,keywords:["list","bullet","ul"],run:(e,t)=>Ee(e,t,bn({ordered:!1}))},{label:"Numbered list",icon:El,keywords:["list","number","ordered","ol"],run:(e,t)=>Ee(e,t,bn({ordered:!0}))},{label:"To-do list",icon:po,keywords:["todo","checkbox","task","checklist"],run:(e,t)=>Ee(e,t,bn({ordered:!1,checked:!1}))},{label:"Toggle list",icon:Ct,keywords:["toggle","collapse","expand","dropdown","accordion"],run:(e,t)=>Ee(e,t,bn({ordered:!1,collapsed:!1}))}]},Xl=["text","date","checkbox","select"],hr="text",br=160,qn=80;function wd(e){return`Column ${e+1}`}function So(e){return Array.from({length:e},(t,n)=>({id:N(),label:wd(n),type:hr,width:br}))}function De(e,t){var r;const n=(r=e.props)==null?void 0:r.columns;return!Array.isArray(n)||n.length!==t?So(t):n.map(o=>{const s=o.type??hr,l=o.width??br;return s===o.type&&l===o.width?o:{...o,type:s,width:l}})}function ql(e){switch(e){case"date":return{id:N(),type:"date",value:"",marks:{},data:{isoDate:""}};case"checkbox":return{id:N(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}};case"select":return{id:N(),type:"tableSelect",value:"",marks:{},data:{selectedValue:"",selectedLabel:""}};default:return{id:N(),type:"text",value:"",marks:{}}}}function mr(e,t){const n=ql(t==null?void 0:t.type);return{block:{id:N(),type:"tableCell",parentId:e,contentIds:[n.id],props:{}},run:n}}function Gl(e,t,n){if(e.type===t)return e;let r;if(e.type==="text")r=e.value??"";else{const o=n==null?void 0:n.get(e.type);r=o!=null&&o.toPlainText?o.toPlainText(e):""}if(t==="date"){const o=r?new Date(r):null,s=o&&!Number.isNaN(o.getTime())?o.toISOString().slice(0,10):"";return{id:N(),type:"date",value:"",marks:{},data:{isoDate:s}}}return t==="checkbox"?{id:N(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:r}}:{id:N(),type:"text",value:r,marks:{}}}function Tt(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Jl(e,t){const r=e.getBlock(t.parentId).contentIds.indexOf(t.id);Tt(e,[J(t.id)]);const o=rn(e);if(o)return Te(e,o),null;const s=e.getBlock(t.parentId),l=s.contentIds[r]??s.contentIds[r-1];return l&&Te(e,l),null}function To(e,t){const n=e.getBlock(t),r=e.getBlock(n.parentId),o=r.contentIds.indexOf(t),s=De(r,n.contentIds.length),l=N(),i=[],c=[],u=[];for(const d of s){const h=mr(l,d);i.push(h.block),c.push(h.run),u.push(h.block.id)}const f={id:l,type:"tableRow",parentId:r.id,contentIds:u,props:{}};return e.applyOperation(ge(f,r.id,o+1,{blocks:[f,...i],runs:c})),Te(e,l),l}function Zl(e,t){const n=e.getBlock(t),r=e.getBlock(n.parentId);if(r.contentIds.length<=1)return Jl(e,r);const o=r.contentIds.indexOf(t);Tt(e,[J(t)]);const s=e.getBlock(r.id),l=Math.min(o,s.contentIds.length-1),i=s.contentIds[l];return i&&Te(e,i),i??null}function Gn(e,t,n){const r=e.getBlock(t),o=De(r,r.contentIds[0]?e.getBlock(r.contentIds[0]).contentIds.length:0),s={id:N(),label:"New Column",type:hr,width:br},l=[];let i=null;for(const u of r.contentIds){const f=mr(u,s);i===null&&(i=f.block.id),l.push(ge(f.block,u,n+1,{blocks:[f.block],runs:[f.run]}))}const c=[...o];return c.splice(n+1,0,s),l.push(X(t,{columns:c})),Tt(e,l),i&&Te(e,i),i}function Ql(e,t,n){const r=e.getBlock(t),o=e.getBlock(r.contentIds[0]);if(!o||o.contentIds.length<=1)return Jl(e,r);const s=De(r,o.contentIds.length),l=r.contentIds.map(d=>{const h=e.getBlock(d);return J(h.contentIds[n])}),i=s.filter((d,h)=>h!==n);l.push(X(t,{columns:i})),Tt(e,l);const c=e.getBlock(r.contentIds[0]),u=Math.min(n,c.contentIds.length-1),f=c.contentIds[u];return f&&Te(e,f),f??null}function ea(e,t,n,r){const o=e.getBlock(t),s=e.getBlock(o.contentIds[0]),l=De(o,s?s.contentIds.length:0);if(!l[n])return;const i=[...l];i[n]={...l[n],width:Math.max(qn,Math.round(r))},e.applyOperation(X(t,{columns:i}))}function ta(e,t,n,r){const o=e.getBlock(t),s=e.getBlock(o.contentIds[0]),i=[...De(o,s?s.contentIds.length:0)];i[n]&&(i[n]={...i[n],label:r},e.applyOperation(X(t,{columns:i})))}function Ro(e,t,n){return t.contentIds.map(r=>{const s=e.getBlock(r).contentIds[n],l=e.getBlock(s);return{cellId:s,run:e.getRun(l.contentIds[0])}})}function Rs(e,t){if(!e)return"";if(e.type==="text")return e.value??"";const n=t==null?void 0:t.get(e.type);return n!=null&&n.toPlainText?n.toPlainText(e):""}function Id(e,t,n,r){const o=Ro(e,t,n),s=[],l=new Map;for(const{run:c}of o){const u=Rs(c,r).trim();if(!u||l.has(u))continue;const f={value:N(),label:u};l.set(u,f),s.push(f)}const i=o.map(({cellId:c,run:u})=>{const f=Rs(u,r).trim(),d=l.get(f);return{cellId:c,run:{id:N(),type:"tableSelect",value:"",marks:{},data:{selectedValue:(d==null?void 0:d.value)??"",selectedLabel:(d==null?void 0:d.label)??""}}}});return{options:s,newRuns:i}}function na(e,t,n,r,o){const s=e.getBlock(t),l=e.getBlock(s.contentIds[0]),i=De(s,l?l.contentIds.length:0),c=i[n];if(!c||c.type===r)return;const u=[...i];if(r==="select"){const{options:d,newRuns:h}=Id(e,s,n,o);u[n]={...c,type:r,options:d};const m=[X(t,{columns:u})];for(const{cellId:g,run:x}of h)m.push(_e(g,[x]));Tt(e,m);return}u[n]={...c,type:r};const f=[X(t,{columns:u})];for(const{cellId:d,run:h}of Ro(e,s,n)){if(!h)continue;const m=Gl(h,r,o);f.push(_e(d,[m]))}Tt(e,f)}function Yn(e,t,n,r){var d,h;const o=e.getBlock(t),s=e.getBlock(o.contentIds[0]),l=De(o,s?s.contentIds.length:0),i=l[n];if(!i)return;const c=[...l];c[n]={...i,options:r};const u=[X(t,{columns:c})],f=new Map(r.map(m=>[m.value,m]));for(const{run:m}of Ro(e,o,n)){if(!m||m.type!=="tableSelect")continue;const g=((d=m.data)==null?void 0:d.selectedValue)??"",x=f.get(g),k=x?g:"",y=x?x.label:"";(k!==g||y!==(((h=m.data)==null?void 0:h.selectedLabel)??""))&&u.push(ue(m.id,{data:{selectedValue:k,selectedLabel:y}}))}Tt(e,u)}function ra(e,t,n){const[r,o]=p.useState(null);return p.useLayoutEffect(()=>{o(n??null)},[n]),p.useLayoutEffect(()=>{if(!t||!e.current||r==null)return;const s=e.current.getBoundingClientRect(),l=or(r,s.width);l!==r&&o(l)},[t,e,r]),r}function oa(e,t,n){const[r,o]=p.useState(null);return p.useLayoutEffect(()=>{o(n??null)},[n]),p.useLayoutEffect(()=>{if(!t||!e.current||r==null)return;const s=e.current.getBoundingClientRect(),l=s.width/2,c=or(r-l,s.width)+l;c!==r&&o(c)},[t,e,r]),r}function Cd(e,t,n){const[r,o]=p.useState(null);return p.useLayoutEffect(()=>{o(n??null)},[n]),p.useLayoutEffect(()=>{if(!t||!e.current||r==null)return;const s=e.current.getBoundingClientRect(),i=or(r-s.width,s.width)+s.width;i!==r&&o(i)},[t,e,r]),r}function js(){if(typeof window>"u"||!window.visualViewport)return 0;const e=window.visualViewport,t=window.innerHeight-(e.height+e.offsetTop);return t>0?Math.round(t):0}function gr(){const[e,t]=p.useState(js);return p.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const n=window.visualViewport,r=()=>t(js());return r(),n.addEventListener("resize",r),n.addEventListener("scroll",r),()=>{n.removeEventListener("resize",r),n.removeEventListener("scroll",r)}},[]),e}const Sd=280;function Td(e,t){return t?e.label.toLowerCase().includes(t.toLowerCase()):!0}function Rt({value:e,options:t,onChange:n,placeholder:r="Select…",ariaLabel:o,className:s="",variant:l="default",selectedLabel:i,selectedColor:c,onManageOptions:u,manageOptionsLabel:f="Manage options…",mention:d=!1}){var ke,fe;const[h,m]=p.useState(!1),[g,x]=p.useState(""),[k,y]=p.useState(0),[I,w]=p.useState(null),j=gr(),[S,v]=p.useState([]),[R,_]=p.useState(!1),[O,C]=p.useState(!1),B=p.useRef(null),M=p.useRef(null),z=p.useRef(null),Y=p.useRef(null),W=p.useRef(null),ie=p.useMemo(()=>[B,z],[]),ae=l==="tag",G=typeof t=="function",se=G?void 0:t.find(P=>P.value===e),H=e?se??(i?{label:i,color:c}:void 0):void 0,Q=p.useMemo(()=>G?S:t.filter(P=>Td(P,g)),[G,S,t,g]);p.useEffect(()=>{if(!G||!h)return;let P=!1;_(!0),C(!1);const Ie=setTimeout(()=>{Promise.resolve(t(g)).then(Ue=>{P||(v(Ue??[]),_(!1))}).catch(()=>{P||(v([]),_(!1),C(!0))})},250);return()=>{P=!0,clearTimeout(Ie)}},[G,h,t,g]);const ee=p.useCallback(()=>m(!1),[]);He(ie,h,ee);const re=ra(z,h,I==null?void 0:I.left),be=p.useCallback(()=>{var P;w(((P=M.current)==null?void 0:P.getBoundingClientRect())??null),x(""),y(0),m(!0)},[]);p.useEffect(()=>{var P;h&&((P=Y.current)==null||P.focus())},[h]),p.useEffect(()=>{var P,Ie;(Ie=(P=W.current)==null?void 0:P.scrollIntoView)==null||Ie.call(P,{block:"nearest"})},[k]);const Re=p.useCallback(P=>{var Ie;n(P.value,P),ee(),(Ie=M.current)==null||Ie.focus()},[n,ee]),le=p.useCallback(P=>{var Ie;P.key==="ArrowDown"?(P.preventDefault(),y(Ue=>Math.min(Ue+1,Math.max(Q.length-1,0)))):P.key==="ArrowUp"?(P.preventDefault(),y(Ue=>Math.max(Ue-1,0))):P.key==="Enter"?(P.preventDefault(),Q[k]&&Re(Q[k])):P.key==="Escape"&&(P.preventDefault(),ee(),(Ie=M.current)==null||Ie.focus())},[Q,k,Re,ee]);return a.jsxs("span",{className:`be-select ${s}`.trim(),ref:B,children:[a.jsx("button",{type:"button",ref:M,className:`be-select-trigger${ae?" be-select-trigger-tag":""}${d?" be-select-trigger-mention":""}`,"aria-haspopup":"listbox","aria-expanded":h,"aria-label":o,onClick:()=>h?ee():be(),children:ae?H?a.jsx("span",{className:`be-select-tag${d?" be-select-tag-mention":""}`,style:d?void 0:{background:(ke=H.color)==null?void 0:ke.bg,color:(fe=H.color)==null?void 0:fe.text},children:d?`@${H.label}`:H.label}):a.jsx("span",{className:"be-select-value be-select-value-placeholder",children:r}):a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"be-select-value",children:H?H.label:r}),a.jsx(lr,{size:14,className:"be-select-chevron"})]})}),h&&I&&re!=null&&Xe.createPortal(a.jsxs("div",{ref:z,className:"be-select-popover",style:{position:"fixed",left:re,minWidth:I.width,...I.bottom+Sd>window.innerHeight-j?{bottom:window.innerHeight-I.top+4}:{top:I.bottom+4}},children:[a.jsx("input",{ref:Y,type:"text",className:"be-select-search",value:g,onChange:P=>{x(P.target.value),y(0)},onKeyDown:le,placeholder:"Search…","aria-label":o?`Search ${o}`:"Search options"}),a.jsxs("div",{className:"be-select-options",role:"listbox",children:[G&&R&&a.jsx("div",{className:"be-select-empty",children:"Loading…"}),G&&!R&&O&&a.jsx("div",{className:"be-select-empty be-select-error",children:"Couldn't load options"}),!R&&!O&&Q.length===0&&a.jsx("div",{className:"be-select-empty",children:"No results"}),!R&&!O&&Q.map((P,Ie)=>{var Ue,jn;return a.jsx("div",{ref:Ie===k?W:void 0,role:"option","aria-selected":P.value===e,className:`be-select-option${Ie===k?" be-select-option-active":""}${P.value===e?" be-select-option-selected":""}`,onMouseDown:yr=>{yr.preventDefault(),Re(P)},onMouseEnter:()=>y(Ie),children:ae?a.jsx("span",{className:"be-select-tag",style:{background:(Ue=P.color)==null?void 0:Ue.bg,color:(jn=P.color)==null?void 0:jn.text},children:P.label}):P.label},P.value)})]}),u&&a.jsx("button",{type:"button",className:"be-select-manage-options",onMouseDown:P=>{P.preventDefault(),ee(),u()},children:f})]}),document.body)]})}const An=[{bg:"#e9e9e7",text:"#32302c"},{bg:"#eee0da",text:"#64473a"},{bg:"#fadec9",text:"#8a4b23"},{bg:"#fdecc8",text:"#8a6116"},{bg:"#dbeddb",text:"#256029"},{bg:"#d3e5ef",text:"#1a5f8a"},{bg:"#e8deee",text:"#5b3a8a"},{bg:"#f5e0e9",text:"#8a3a5f"},{bg:"#ffe2dd",text:"#a13a2f"}];function vn(e){return An[(e%An.length+An.length)%An.length]}const Rd={text:"Text",date:"Date",checkbox:"Checkbox",select:"Select"},jd=Xl.map(e=>({value:e,label:Rd[e]})),Bd=800;function Ed({tableId:e,colIndex:t,options:n}){const r=q(),[o,s]=p.useState(""),l=p.useCallback((u,f)=>{Yn(r,e,t,n.map(d=>d.value===u?{...d,label:f}:d))},[r,e,t,n]),i=p.useCallback(u=>Yn(r,e,t,n.filter(f=>f.value!==u)),[r,e,t,n]),c=p.useCallback(()=>{const u=o.trim();s(""),u&&Yn(r,e,t,[...n,{value:N(),label:u,color:vn(n.length)}])},[r,e,t,n,o]);return a.jsxs("div",{className:"be-table-header-menu-options",children:[a.jsx("div",{className:"be-table-header-menu-options-label",children:"Options"}),n.map((u,f)=>a.jsxs("div",{className:"be-table-header-menu-option-row",children:[a.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(u.color??vn(f)).bg},"aria-hidden":"true"}),a.jsx("input",{className:"be-table-header-menu-option-input",value:u.label,onChange:d=>l(u.value,d.target.value),"aria-label":`Rename option ${u.label}`}),a.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>i(u.value),"aria-label":`Remove option ${u.label}`,children:a.jsx(en,{size:14})})]},u.value)),a.jsxs("div",{className:"be-table-header-menu-option-row",children:[a.jsx("input",{className:"be-table-header-menu-option-input",value:o,onChange:u=>s(u.target.value),placeholder:"New option…",onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),c())}}),a.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:c,"aria-label":"Add option",children:"+"})]})]})}function Ld({tableId:e,column:t,colIndex:n,colCount:r}){const o=q(),s=Je(),[l,i]=p.useState(!1),[c,u]=p.useState(null),[f,d]=p.useState(null),h=p.useRef(null),m=p.useRef(null),g=p.useRef(null),x=p.useMemo(()=>[h,m],[]),k=p.useCallback(()=>i(!1),[]);He(x,l,k),pr(m,l,k,h);const y=Cd(m,l,c==null?void 0:c.right),I=p.useCallback(()=>{var O;u(((O=g.current)==null?void 0:O.getBoundingClientRect())??null),i(!0)},[]),w=p.useCallback(O=>ta(o,e,n,O.target.value),[o,e,n]),j=p.useCallback(()=>{Gn(o,e,n-1),k()},[o,e,n,k]),S=p.useCallback(()=>{Gn(o,e,n),k()},[o,e,n,k]),v=p.useCallback(()=>{Ql(o,e,n),k()},[o,e,n,k]),R=p.useCallback(O=>na(o,e,n,O,s),[o,e,n,s]),_=p.useCallback(O=>{var ae;O.preventDefault();const C=(ae=g.current)==null?void 0:ae.closest("table"),B=C==null?void 0:C.querySelector(`col[data-col-index="${n}"]`);if(!B)return;const M=g.current.getBoundingClientRect().width,z=O.clientX,Y=G=>Math.max(qn,Math.round(M+(G.clientX-z))),W=G=>{const se=Y(G);B.style.width=`${se}px`,d(se)},ie=G=>{document.removeEventListener("mousemove",W),document.removeEventListener("mouseup",ie),ea(o,e,n,Y(G)),d(null)};document.addEventListener("mousemove",W),document.addEventListener("mouseup",ie)},[o,e,n]);return a.jsxs("th",{ref:g,scope:"col",className:"be-table-header-cell",contentEditable:!1,children:[a.jsx("input",{className:"be-table-header-label",value:t.label,onChange:w,"aria-label":`Column ${n+1} name`}),a.jsx("button",{ref:h,type:"button",className:"be-table-header-menu-trigger","aria-label":`Column ${n+1} options`,"aria-haspopup":"menu","aria-expanded":l,onClick:()=>l?k():I(),children:"⋮"}),a.jsx("div",{className:"be-table-col-resize-handle",onMouseDown:_,role:"slider","aria-label":`Resize column ${n+1}`,"aria-valuemin":qn,"aria-valuemax":Bd,"aria-valuenow":f??t.width}),l&&c&&y!=null&&Xe.createPortal(a.jsxs("div",{ref:m,role:"menu","aria-label":`Column ${n+1} options`,className:"be-table-header-menu",style:{position:"fixed",top:c.bottom+4,left:y,transform:"translateX(-100%)"},children:[a.jsxs("div",{className:"be-table-header-menu-type",children:[a.jsx("span",{id:`be-table-col-type-${t.id}`,children:"Type"}),a.jsx(Rt,{value:t.type,options:jd,onChange:R,ariaLabel:"Column type",className:""})]}),t.type==="select"&&a.jsx(Ed,{tableId:e,colIndex:n,options:t.options??[]}),a.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:j,children:"Insert column left"}),a.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:S,children:"Insert column right"}),a.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item be-table-header-menu-item-danger",onClick:v,disabled:r<=1,children:"Delete column"})]}),document.body)]})}function sa({tableId:e,columns:t}){return a.jsx("thead",{children:a.jsxs("tr",{className:"be-table-header-row",children:[t.map((n,r)=>a.jsx(Ld,{tableId:e,column:n,colIndex:r,colCount:t.length},n.id)),a.jsx("th",{className:"be-table-header-spacer","aria-hidden":"true"})]})})}function Od({id:e}){var i;const t=q(),n=he(e),r=p.useCallback(()=>{var u;const c=(u=n==null?void 0:n.contentIds)==null?void 0:u[n.contentIds.length-1];c&&To(t,c)},[t,n]),o=we("be-table-wrapper",n);if(!n)return null;const s=t.getBlock(n.contentIds[0]),l=De(n,((i=s==null?void 0:s.contentIds)==null?void 0:i.length)??0);return a.jsx("div",{className:"be-table-scroll",children:a.jsxs("div",{className:o,"data-block-id":e,children:[a.jsxs("table",{className:"be-table",children:[a.jsxs("colgroup",{children:[l.map((c,u)=>a.jsx("col",{"data-col-index":u,style:{width:c.width}},c.id)),a.jsx("col",{className:"be-table-header-spacer-col"})]}),a.jsx(sa,{tableId:e,columns:l}),a.jsx("tbody",{children:a.jsx(ut,{parentId:e})})]}),a.jsxs("button",{type:"button",className:"be-table-add-row",contentEditable:!1,onClick:r,children:[a.jsx(lo,{size:14})," Add row"]})]})})}function _d({id:e}){const t=q(),n=he(e),r=we("be-table-row",n),o=p.useCallback(()=>Zl(t,e),[t,e]);return a.jsxs("tr",{className:r,"data-block-id":e,children:[a.jsx(ut,{parentId:e}),a.jsx("td",{className:"be-table-row-actions",contentEditable:!1,children:a.jsx("button",{type:"button",className:"be-table-delete-row",onClick:o,"aria-label":"Delete row",title:"Delete row",children:a.jsx(en,{size:14})})})]})}function la(e,t){const n=e.getBlock(t),r=e.getBlock(n.parentId),o=e.getBlock(r.parentId);return{table:o,row:r,rowIndex:o.contentIds.indexOf(r.id),colIndex:r.contentIds.indexOf(t)}}function Nd(e,t,n){const{table:r,row:o,rowIndex:s,colIndex:l}=la(e,t);if(n==="left"||n==="right"){const f=n==="right"?1:-1,d=l+f;if(d>=0&&d<o.contentIds.length)return o.contentIds[d];const h=s+f;if(h<0||h>=r.contentIds.length)return null;const m=e.getBlock(r.contentIds[h]),g=n==="right"?0:m.contentIds.length-1;return m.contentIds[g]}const c=s+(n==="down"?1:-1);if(c<0||c>=r.contentIds.length)return null;const u=e.getBlock(r.contentIds[c]);return u.contentIds[l]??u.contentIds[u.contentIds.length-1]??null}function Md(e,t){const n=Ol(e,t,"down");if(n){xe(n);return}Ze(e,t,Z("paragraph"))}function un(e,t,n){var o;const r=Nd(e,t,n);if(r){const s=e.getBlock(r),l=(o=s==null?void 0:s.contentIds)==null?void 0:o[0];l&&xe(l);return}if(n==="right"){const{table:s}=la(e,t);Md(e,s.id)}}function Ad({id:e}){const t=q(),n=he(e),r=p.useCallback(()=>un(t,e,"right"),[t,e]),o=p.useCallback(()=>un(t,e,"left"),[t,e]),s=p.useCallback(()=>un(t,e,"up"),[t,e]),l=p.useCallback(()=>un(t,e,"down"),[t,e]),i=p.useCallback(()=>un(t,e,"down"),[t,e]),c=we("be-table-cell",n);if(!n)return null;const u=ot(t,n);return a.jsx("td",{className:c,"data-block-id":e,dir:u,children:a.jsx(it,{blockId:e,runIds:n.contentIds,dir:u,onTab:r,onShiftTab:o,onArrowUp:s,onArrowDown:l,onEnter:i})})}function Dd(e,t){const n=N(),r=[],o=[],s=[];for(const l of t){const i=mr(n,l);r.push(i.block),o.push(i.run),s.push(i.block.id)}return{block:{id:n,type:"tableRow",parentId:e,contentIds:s,props:{}},blocks:r,runs:o}}function Pd({rows:e=2,cols:t=2}={}){return function(r){const o=N(),s=So(t),l=[],i=[],c=[];for(let f=0;f<e;f+=1){const d=Dd(o,s);l.push(d.block,...d.blocks),i.push(...d.runs),c.push(d.block.id)}return{block:{id:o,type:"table",parentId:r,contentIds:c,props:{columns:s}},runs:i,subtreeBlocks:l}}}function $d(e,t){return`<td>${e.contentIds.map(r=>t.store.getRun(r)).map(r=>ct(r,t)).join("")}</td>`}function zd(e,t){return e.contentIds.map(n=>kt(t.store.getRun(n),t)).join("")}function Hd(e,t){if(e.tagName!=="TD"&&e.tagName!=="TH")return null;const n=Fe(e,t);return{block:{id:N(),type:"tableCell",parentId:null,contentIds:n.map(o=>o.id),props:{}},runs:n}}function Fd(e,t){return`<tr>${e.contentIds.map(r=>{const o=t.store.getBlock(r);return t.registry.get(o.type).toHTML(o,t)}).join("")}</tr>`}function Ud(e,t){return e.contentIds.map(n=>{const r=t.store.getBlock(n);return t.registry.get(r.type).toPlainText(r,t)}).join(" ")}function Yd(e,t){if(e.tagName!=="TR")return null;const n=[...e.children].filter(c=>c.tagName==="TD"||c.tagName==="TH"),r=N(),o=[],s=[],l=[];for(const c of n){const u=t.registry.get("tableCell").fromHTML(c,t);u&&(u.block.parentId=r,o.push(u.block),s.push(...u.runs),l.push(u.block.id))}return{block:{id:r,type:"tableRow",parentId:null,contentIds:l,props:{}},runs:s,subtreeBlocks:o}}function Kd(e,t){var l;const n=e.contentIds[0]&&t.store.getBlock(e.contentIds[0]),r=De(e,((l=n==null?void 0:n.contentIds)==null?void 0:l.length)??0),o=r.length?`<thead><tr>${r.map(i=>`<th>${St(i.label??"")}</th>`).join("")}</tr></thead>`:"",s=e.contentIds.map(i=>{const c=t.store.getBlock(i);return t.registry.get(c.type).toHTML(c,t)}).join("");return`<table>${o}<tbody>${s}</tbody></table>`}function Vd(e,t){return e.contentIds.map(n=>{const r=t.store.getBlock(n);return t.registry.get(r.type).toPlainText(r,t)}).join(`
|
|
2527
|
+
`)}function Wd(e,t){if(e.tagName!=="TABLE")return null;const n=e.querySelector("thead tr"),r=e.querySelector("tbody")?[...e.querySelectorAll("tbody tr")]:[...e.querySelectorAll("tr")].filter(f=>f!==n),o=N(),s=[],l=[],i=[];for(const f of r){const d=t.registry.get("tableRow").fromHTML(f,t);if(d){d.block.parentId=o;for(const h of d.subtreeBlocks)h.parentId=d.block.id;s.push(d.block,...d.subtreeBlocks),l.push(...d.runs),i.push(d.block.id)}}const c={};if(n){const f=[...n.children].filter(d=>d.tagName==="TH"||d.tagName==="TD");c.columns=f.map(d=>({id:N(),label:d.textContent??""}))}return{block:{id:o,type:"table",parentId:null,contentIds:i,props:c},runs:l,subtreeBlocks:s}}const aa={component:Ad,isLeaf:!0,defaultProps:{},toHTML:$d,toPlainText:zd,fromHTML:Hd},ia={component:_d,isLeaf:!1,defaultProps:{},toHTML:Fd,toPlainText:Ud,fromHTML:Yd},ca={component:Od,isLeaf:!1,defaultProps:{},toHTML:Kd,toPlainText:Vd,fromHTML:Wd,slashCommand:{label:"Table",icon:cu,keywords:["table","grid"],run:(e,t)=>Ee(e,t,Pd({rows:2,cols:2}))}};function Xd({id:e}){const t=he(e),n=we("be-layout",t);return a.jsx("div",{className:n,"data-block-id":e,style:{display:"flex",gap:"1em"},children:a.jsx(ut,{parentId:e})})}function qd({id:e}){const t=he(e),n=we("be-layout-column",t);return a.jsx("div",{className:n,"data-block-id":e,children:a.jsx(ut,{parentId:e})})}function Gd({columns:e=2}={}){return function(n){const r=N(),o=[],s=[],l=[];for(let c=0;c<e;c+=1){const u=N(),{block:f,runs:d}=Z("paragraph")(u),h={id:u,type:"layoutColumn",parentId:r,contentIds:[f.id],props:{}};o.push(h,f),s.push(...d),l.push(u)}return{block:{id:r,type:"layout",parentId:n,contentIds:l,props:{}},runs:s,subtreeBlocks:o}}}function ua(e,t){return(n,r)=>`${e}${n.contentIds.map(o=>{const s=r.store.getBlock(o);return r.registry.get(s.type).toHTML(s,r)}).join("")}${t}`}function da(e,t){return e.contentIds.map(n=>{const r=t.store.getBlock(n);return t.registry.get(r.type).toPlainText(r,t)}).join(`
|
|
2528
|
+
`)}const pa={component:qd,isLeaf:!1,defaultProps:{},toHTML:ua("<div>","</div>"),toPlainText:da},fa={component:Xd,isLeaf:!1,defaultProps:{},toHTML:ua('<div style="display:flex;gap:1em">',"</div>"),toPlainText:da,slashCommands:[2,3,4,5].map(e=>({label:`${e} columns`,icon:uu,keywords:["layout","columns","column",String(e)],run:(t,n)=>Ee(t,n,Gd({columns:e}))}))};function Jd({id:e}){const t=he(e),n=we("be-divider",t);return a.jsx("hr",{className:n,"data-block-id":e,contentEditable:!1,tabIndex:-1})}function Zd(){return function(t){return{block:{id:N(),type:"divider",parentId:t,contentIds:[],props:{}},runs:[]}}}function Qd(){return"<hr />"}function ep(){return"---"}function tp(e){return e.tagName!=="HR"?null:{block:{id:N(),type:"divider",parentId:null,contentIds:[],props:{}},runs:[]}}const ha={component:Jd,isLeaf:!0,defaultProps:{},toHTML:Qd,toPlainText:ep,fromHTML:tp,slashCommand:{label:"Divider",icon:au,keywords:["divider","hr","separator","line"],run:(e,{blockId:t,runId:n,sliceStart:r,sliceEnd:o})=>{const s=e.getRun(n),l=(s==null?void 0:s.value)??"";e.applyOperation(ue(n,{value:l.slice(0,r)+l.slice(o)}));const i=dr(e,t,Zd());return Ze(e,i,Z("paragraph")),i}}},ba=[{value:"gray",label:"Gray"},{value:"blue",label:"Blue"},{value:"green",label:"Green"},{value:"yellow",label:"Yellow"},{value:"orange",label:"Orange"},{value:"red",label:"Red"},{value:"purple",label:"Purple"},{value:"pink",label:"Pink"}];function np({id:e}){var y,I;const t=q(),n=he(e),[r,o]=p.useState(!1),[s,l]=p.useState(!1),i=p.useRef(null),c=p.useRef(null),u=p.useMemo(()=>[i,c],[]),f=p.useCallback(()=>l(!1),[]);He(u,s,f);const d=((y=n==null?void 0:n.props)==null?void 0:y.icon)??sn,h=((I=n==null?void 0:n.props)==null?void 0:I.color)??zl,m=p.useCallback(w=>{const j=w.target.value.trim();j&&t.applyOperation(X(e,{icon:j})),o(!1)},[t,e]),g=p.useCallback(w=>{w.key==="Enter"&&w.currentTarget.blur(),w.key==="Escape"&&o(!1)},[]),x=p.useCallback(w=>{t.applyOperation(X(e,{color:w})),l(!1)},[t,e]),k=we("be-callout",n);return n?a.jsxs("div",{className:k,"data-block-id":e,"data-color":h,children:[a.jsx("div",{className:"be-callout-icon-wrap",children:r?a.jsx("input",{type:"text",className:"be-callout-icon-input",defaultValue:d,autoFocus:!0,onBlur:m,onKeyDown:g,"aria-label":"Callout icon (paste or type an emoji)"}):a.jsx("button",{type:"button",className:"be-callout-icon",onClick:()=>o(!0),"aria-label":"Change callout icon",title:"Change icon",children:d})}),a.jsx("div",{className:"be-callout-content",children:a.jsx(ut,{parentId:e})}),a.jsxs("div",{className:"be-callout-color-wrap",contentEditable:!1,children:[a.jsx("button",{ref:i,type:"button",className:"be-callout-color-trigger","aria-label":"Callout color","aria-haspopup":"true","aria-expanded":s,title:"Callout color",onClick:()=>l(w=>!w),children:a.jsx("span",{className:`be-callout-color-dot be-callout-color-dot-${h}`})}),s&&a.jsx("div",{ref:c,className:"be-callout-color-picker",role:"menu","aria-label":"Callout color",children:ba.map(w=>a.jsx("button",{type:"button",role:"menuitem",className:`be-callout-color-option be-callout-color-option-${w.value}${w.value===h?" be-callout-color-option-active":""}`,title:w.label,"aria-label":w.label,onClick:()=>x(w.value)},w.value))})]})]}):null}function rp(e,t){return e.contentIds.map(n=>{const r=t.store.getBlock(n);return t.registry.get(r.type).toHTML(r,t)}).join("")}function op(e,t){var r;const n=((r=e.props)==null?void 0:r.icon)??sn;return`<div class="callout" data-icon="${n}"><div class="callout-icon">${n}</div><div class="callout-content">${rp(e,t)}</div></div>`}function sp(e,t){var o;const n=((o=e.props)==null?void 0:o.icon)??sn,r=e.contentIds.map(s=>{const l=t.store.getBlock(s);return t.registry.get(l.type).toPlainText(l,t)}).join(`
|
|
2529
|
+
`);return`${n} ${r}`}const ma={component:np,isLeaf:!1,defaultProps:{icon:sn},toHTML:op,toPlainText:sp,slashCommand:{label:"Callout",icon:jl,keywords:["callout","aside","note","info","tip","warning"],run:(e,t)=>Ee(e,t,Zu())}};function lp({id:e}){const t=q(),n=he(e),{setSelectedBlockId:r}=lt(),o=p.useCallback(()=>{nn(t,e,(n==null?void 0:n.contentIds)??[],Z("paragraph"))},[t,e,n]),s=p.useCallback(()=>{const d=Tn(t,e);on(t,d,e,r)},[t,e,r]),l=p.useCallback(()=>Le(t,e,"up"),[t,e]),i=p.useCallback(()=>Le(t,e,"down"),[t,e]),c=we("be-blockquote",n);if(!n)return null;const u=Ne(t,n.contentIds),f=ot(t,n);return a.jsx("blockquote",{className:c,"data-block-id":e,"data-empty":u?"":void 0,"data-placeholder":"Empty quote",dir:f,children:a.jsx(it,{blockId:e,runIds:n.contentIds,dir:f,onEnter:o,onBackspaceAtStart:s,onArrowUp:l,onArrowDown:i})})}function ap(e,t){return`<p>${e.contentIds.map(r=>t.store.getRun(r)).map(r=>ct(r,t)).join("")}</p>`}function ip(e,t){return e.contentIds.map(n=>kt(t.store.getRun(n),t)).join("")}function cp(e,t){if(e.tagName!=="BLOCKQUOTE")return null;const n=Fe(e,t);return{block:{id:N(),type:"blockquote",parentId:null,contentIds:n.map(o=>o.id),props:{}},runs:n}}const ga={component:lp,isLeaf:!0,defaultProps:{},toHTML:ap,toPlainText:ip,fromHTML:cp,slashCommand:{label:"Quote",icon:Rl,keywords:["quote","blockquote","citation"],run:(e,t)=>Ee(e,t,Z("blockquote"))}},xa=["plaintext","javascript","python","html","css","json","bash","sql"],up=xa.map(e=>({value:e,label:e}));function Bs(e,t,n){const r=rt();if(!r||r.blockId!==t)return;const o=e.getRun(r.runId);if(!o||o.type!=="text")return;const s=o.value??"",l=s.slice(0,r.offset)+n+s.slice(r.offset);e.applyOperation(ue(o.id,{value:l})),We(o.id,r.offset+n.length)}function dp({id:e}){var m;const t=q(),n=he(e),r=p.useCallback(()=>Bs(t,e,`
|
|
2530
|
+
`),[t,e]),o=p.useCallback(()=>Bs(t,e," "),[t,e]),s=p.useCallback(()=>{var y;const g=Tn(t,e);if(!g||g===e)return;const x=t.getBlock(g),k=(y=x==null?void 0:x.contentIds)==null?void 0:y[x.contentIds.length-1];k&&xe(k)},[t,e]),l=p.useCallback(()=>Le(t,e,"up"),[t,e]),i=p.useCallback(()=>Le(t,e,"down"),[t,e]),c=p.useCallback(g=>t.applyOperation(X(e,{language:g})),[t,e]),u=p.useCallback(()=>fr(t,e),[t,e]),f=we("be-code-block",n);if(!n)return null;const d=((m=n.props)==null?void 0:m.language)??"plaintext",h=Ne(t,n.contentIds);return a.jsxs("div",{className:f,"data-block-id":e,children:[a.jsxs("div",{className:"be-code-block-header",contentEditable:!1,children:[a.jsx(Rt,{className:"be-code-block-language",value:d,options:up,onChange:c,ariaLabel:"Code language"}),a.jsx("button",{type:"button",className:"be-code-block-delete",onClick:u,"aria-label":"Delete code block",title:"Delete code block",children:a.jsx(ar,{size:14})})]}),a.jsx("pre",{className:"be-code-block-pre",dir:"ltr",children:a.jsx("code",{"data-empty":h?"":void 0,"data-placeholder":"Empty code block",children:a.jsx(it,{blockId:e,runIds:n.contentIds,dir:"ltr",onEnter:r,onTab:o,onBackspaceAtStart:s,onArrowUp:l,onArrowDown:i})})})]})}function pp(e,t){var s;const n=e.contentIds.map(l=>t.store.getRun(l)),r=(s=e.props)==null?void 0:s.language;return`<pre><code${r&&r!=="plaintext"?` data-language="${St(r)}"`:""}>${n.map(l=>ct(l,t)).join("")}</code></pre>`}function fp(e,t){return e.contentIds.map(n=>kt(t.store.getRun(n),t)).join("")}function hp(e,t){var l;if(e.tagName!=="PRE")return null;const n=e.querySelector("code")??e,r=(l=n.getAttribute)==null?void 0:l.call(n,"data-language"),o=N();return{block:{id:N(),type:"code",parentId:null,contentIds:[o],props:r?{language:r}:{}},runs:[{id:o,type:"text",value:n.textContent??"",marks:{}}]}}const ka={component:dp,isLeaf:!0,defaultProps:{language:"plaintext"},toHTML:pp,toPlainText:fp,fromHTML:hp,slashCommand:{label:"Code",icon:uo,keywords:["code","codeblock","snippet","pre"],run:(e,t)=>Ee(e,t,Z("code"))}};function bp(e,t){var n;return t.length===0||t.length===1&&(((n=e.getRun(t[0]))==null?void 0:n.value)??"")===""}function mp(e,t){const n=t.contentIds??[];if(n.length===0)return!0;if(n.length>1)return!1;const r=e.getBlock(n[0]);return!!r&&r.type==="paragraph"&&Ne(e,r.contentIds)}function Dn(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function gp(e,t){const n=e.getBlock(t);if(!n)return null;const r=e.getBlock(n.parentId),o=r.contentIds.indexOf(t),s=n.props.titleRunIds??[],l=bp(e,s)&&mp(e,n);if(o<=0){if(!l)return null;if(r.contentIds.length>1)return Dn(e,[J(t)]),{focusBlockId:e.getBlock(r.id).contentIds[0],needsRefocus:!0};const{block:u,runs:f}=Z("paragraph")(r.id);return Dn(e,[ge(u,r.id,o,{blocks:[u],runs:f}),J(t)]),{focusBlockId:u.id,needsRefocus:!0}}const i=r.contentIds[o-1],c=e.getBlock(i);return l?(Dn(e,[J(t)]),{focusBlockId:i,needsRefocus:!0}):Sn(e,c)?(Dn(e,[J(i)]),{focusBlockId:t,needsRefocus:!1}):null}function xp(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function kp({id:e}){var k;const t=q(),n=he(e),{setSelectedBlockId:r}=lt(),o=p.useCallback(()=>{var j,S;const y=((j=n==null?void 0:n.props)==null?void 0:j.titleRunIds)??[],I=(((S=n==null?void 0:n.contentIds)==null?void 0:S.length)??0)>0,w=Z("paragraph");I?Nl(t,e,y,w):nn(t,e,y,w)},[t,e,n]),s=p.useCallback(()=>{const y=gp(t,e);!y||!y.needsRefocus||on(t,y.focusBlockId,e,r)},[t,e,r]),l=p.useCallback(()=>Le(t,e,"up"),[t,e]),i=p.useCallback(()=>Le(t,e,"down"),[t,e]),c=p.useCallback(()=>{var I,w;if(!((((I=n==null?void 0:n.contentIds)==null?void 0:I.length)??0)>0)){const{block:j,runs:S}=Z("paragraph")(e);xp(t,[ge(j,e,0,{blocks:[j],runs:S}),X(e,{collapsed:!1})]),xe(j.contentIds[0]);return}t.applyOperation(X(e,{collapsed:!((w=n==null?void 0:n.props)!=null&&w.collapsed)}))},[t,e,n==null?void 0:n.contentIds,(k=n==null?void 0:n.props)==null?void 0:k.collapsed]),u=we("be-toggle-heading",n);if(!n)return null;const{level:f=2,collapsed:d,titleRunIds:h=[]}=n.props,m=n.contentIds.length>0,g=`h${f}`,x=ot(t,n);return a.jsxs("div",{className:u,"data-block-id":e,dir:x,children:[a.jsxs("div",{className:"be-toggle-heading-row",children:[a.jsx("button",{type:"button",className:"be-toggle-heading-marker",onClick:c,"aria-expanded":!d,"aria-label":m?d?"Expand section":"Collapse section":"Add content to section",children:d?a.jsx(Ct,{}):a.jsx(lr,{})}),a.jsx(g,{className:`be-heading be-heading-${f} be-toggle-heading-title`,"data-empty":Ne(t,h)?"":void 0,"data-placeholder":`Toggle heading ${f}`,children:a.jsx(it,{blockId:e,runIds:h,dir:x,onEnter:o,onBackspaceAtStart:s,onArrowUp:l,onArrowDown:i})})]}),!d&&a.jsx("div",{className:"be-toggle-heading-children",children:a.jsx(ut,{parentId:e})})]})}function yp({level:e=2,collapsed:t=!1}={}){return function(r,o){const s=N(),l=o!=null&&o.length?o:[{id:N(),type:"text",value:"",marks:{}}],{block:i,runs:c}=Z("paragraph")(s);return{block:{id:s,type:"toggleHeading",parentId:r,contentIds:[i.id],props:{level:e,collapsed:t,titleRunIds:l.map(u=>u.id)}},runs:[...l,...c],subtreeBlocks:[i]}}}function vp(e,t){const{titleRunIds:n=[],level:r=2,collapsed:o}=e.props,s=n.map(i=>ct(t.store.getRun(i),t)).join(""),l=e.contentIds.map(i=>{const c=t.store.getBlock(i);return t.registry.get(c.type).toHTML(c,t)}).join("");return`<details${o?"":" open"}><summary><h${r}>${s}</h${r}></summary>${l}</details>`}function wp(e,t){const{titleRunIds:n=[]}=e.props,r=n.map(s=>kt(t.store.getRun(s),t)).join(""),o=e.contentIds.map(s=>{const l=t.store.getBlock(s);return t.registry.get(l.type).toPlainText(l,t)}).join(`
|
|
2519
2531
|
`);return o?`${r}
|
|
2520
|
-
${o}`:r}function vd(e,n){if(e.tagName!=="DETAILS")return null;const t=[...e.children].find(p=>p.tagName==="SUMMARY"),r=t==null?void 0:t.querySelector("h1,h2,h3,h4,h5,h6"),o=r?Math.min(6,Math.max(1,Number(r.tagName[1]))):2,s=r?$e(r,n):[{id:L(),type:"text",value:"",marks:{}}],l=L(),i=[],c=[],u=[];for(const p of e.children){if(p===t||p.tagName!=="P")continue;const h=$e(p,n),b={id:L(),type:"paragraph",parentId:l,contentIds:h.map(g=>g.id),props:{}};i.push(b),c.push(...h),u.push(b.id)}if(u.length===0){const{block:p,runs:h}=J("paragraph")(l);i.push(p),c.push(...h),u.push(p.id)}return{block:{id:l,type:"toggleHeading",parentId:null,contentIds:u,props:{level:o,collapsed:!e.hasAttribute("open"),titleRunIds:s.map(p=>p.id)}},runs:[...s,...c],subtreeBlocks:i}}const Va={component:gd,isLeaf:!1,defaultProps:{level:2,collapsed:!1,titleRunIds:[]},toHTML:kd,toPlainText:yd,fromHTML:vd,slashCommands:[1,2,3].map(e=>({label:`Toggle heading ${e}`,icon:yn,keywords:["toggle","heading","collapse","section"],run:(n,t)=>Te(n,t,xd({level:e}))}))},yr=[{label:"Blue",value:"#2b6fd6"},{label:"Green",value:"#2f9e44"},{label:"Red",value:"#e03131"},{label:"Purple",value:"#9c36b5"},{label:"Gray",value:"#495057"},{label:"Black",value:"#1a1a1a"}];function wd(e,n){if(typeof e.performBatch=="function")e.performBatch(n);else for(const t of n)e.applyOperation(t)}function Id({isOpen:e,onClose:n,store:t,blockId:r}){const[o,s]=d.useState(""),[l,i]=d.useState(""),[c,u]=d.useState(yr[0].value),[f,p]=d.useState([{key:"",value:""}]);d.useEffect(()=>{var I,w,T;if(!e)return;const x=t.getBlock(r);if(!x)return;const k=x.contentIds.map(S=>{var v;return((v=t.getRun(S))==null?void 0:v.value)??""}).join(""),y=((I=x.props)==null?void 0:I.customAttrs)??[];s(k),i(((w=x.props)==null?void 0:w.href)??""),u(((T=x.props)==null?void 0:T.color)??yr[0].value),p([...y,{key:"",value:""}])},[e,r,t]);const h=d.useCallback((x,k)=>{p(y=>{const I=y.map((T,S)=>S===x?{...T,...k}:T),w=I[I.length-1];return(w.key.trim()||w.value.trim())&&I.push({key:"",value:""}),I})},[]),b=d.useCallback(x=>{p(k=>k.filter((y,I)=>I!==x))},[]),g=d.useCallback(()=>{const x={id:L(),type:"text",value:o,marks:{}},k=f.filter(y=>y.key.trim());wd(t,[Oe(r,[x]),X(r,{href:l.trim(),color:c,customAttrs:k})]),n()},[t,r,o,l,c,f,n]);return a.jsxs(on,{isOpen:e,onClose:n,title:"Edit button",children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Label"}),a.jsx("input",{type:"text",value:o,onChange:x=>s(x.target.value),placeholder:"Button"})]}),a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Link URL"}),a.jsx("input",{type:"url",value:l,onChange:x=>i(x.target.value),placeholder:"https://example.com"})]}),a.jsxs("div",{className:"be-modal-field",children:[a.jsx("span",{children:"Color"}),a.jsx("div",{className:"be-modal-color-row",children:yr.map(x=>a.jsx("button",{type:"button",className:`be-modal-color-swatch${c===x.value?" be-modal-color-swatch-active":""}`,style:{backgroundColor:x.value},title:x.label,"aria-label":x.label,onClick:()=>u(x.value)},x.value))})]}),a.jsxs("div",{className:"be-modal-field",children:[a.jsx("span",{children:"Custom attributes"}),f.map((x,k)=>a.jsxs("div",{className:"be-modal-attr-row",children:[a.jsx("input",{type:"text",placeholder:"name",value:x.key,onChange:y=>h(k,{key:y.target.value})}),a.jsx("input",{type:"text",placeholder:"value",value:x.value,onChange:y=>h(k,{value:y.target.value})}),(x.key||x.value)&&a.jsx("button",{type:"button",className:"be-modal-attr-remove",onClick:()=>b(k),"aria-label":"Remove attribute",children:a.jsx(zn,{size:14})})]},k))]}),a.jsxs("div",{className:"be-modal-actions",children:[a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:n,children:"Cancel"}),a.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:"Save"})]})]})}const Cd="#2b6fd6";function Sd({id:e}){var I,w,T,S;const n=W(),t=be(e),{setSelectedBlockId:r}=rn(),[o,s]=d.useState(!1),l=d.useCallback(()=>{Fn(n,e,(t==null?void 0:t.contentIds)??[],J("paragraph"))},[n,e,t]),i=d.useCallback(()=>{const v=pt(n,e);Yn(n,v,e,r)},[n,e,r]),c=d.useCallback(()=>Be(n,e,"up"),[n,e]),u=d.useCallback(()=>Be(n,e,"down"),[n,e]),f=d.useCallback(()=>{var R;const v=(R=t==null?void 0:t.props)==null?void 0:R.href;v&&window.open(v,"_blank","noopener,noreferrer")},[(I=t==null?void 0:t.props)==null?void 0:I.href]),p=ve("be-button-block",t);if(!t)return null;const h=((w=t.props)==null?void 0:w.href)??"",b=((T=t.props)==null?void 0:T.color)??Cd,g=((S=t.props)==null?void 0:S.customAttrs)??[],x=Le(n,t.contentIds),k={};for(const{key:v,value:R}of g)v.trim()&&(k[`data-${v.trim()}`]=R);const y=tn(n,t);return a.jsxs("div",{className:p,"data-block-id":e,dir:y,children:[a.jsxs("div",{className:"be-button-block-pill",style:{backgroundColor:b},...k,children:[a.jsx("span",{className:"be-button-block-label","data-empty":x?"":void 0,"data-placeholder":"Button",children:a.jsx(sn,{blockId:e,runIds:t.contentIds,dir:y,onEnter:l,onBackspaceAtStart:i,onArrowUp:c,onArrowDown:u})}),a.jsx("button",{type:"button",className:"be-button-block-open",onClick:f,disabled:!h,title:h||"No link set","aria-label":"Open link",children:"↗"}),a.jsx("button",{type:"button",className:"be-button-block-settings",onClick:()=>s(!0),"aria-label":"Edit button",title:"Edit label, link, color…",children:"⚙"})]}),a.jsx(Id,{isOpen:o,onClose:()=>s(!1),store:n,blockId:e})]})}function jd({href:e="",label:n="Button",color:t="",customAttrs:r=[]}={}){return function(s,l){const i=L(),c=l!=null&&l.length?l:[{id:L(),type:"text",value:n,marks:{}}];return{block:{id:i,type:"button",parentId:s,contentIds:c.map(u=>u.id),props:{href:e,color:t,customAttrs:r}},runs:c}}}const Xa="be-button-block-link";function Rd(e,n){var c,u,f;const t=e.contentIds.map(p=>n.store.getRun(p)),r=((c=e.props)==null?void 0:c.href)??"",o=(u=e.props)==null?void 0:u.color,s=o?` style="background-color:${Re(o)}"`:"",i=(((f=e.props)==null?void 0:f.customAttrs)??[]).filter(p=>{var h;return(h=p.key)==null?void 0:h.trim()}).map(p=>` data-${Re(p.key.trim())}="${Re(p.value??"")}"`).join("");return`<a class="${Xa}" href="${Re(r)}"${s}${i}>${t.map(p=>an(p,n)).join("")}</a>`}function Td(e,n){return e.contentIds.map(t=>fn(n.store.getRun(t),n)).join("")}function Bd(e,n){var s;if(e.tagName!=="A"||!e.classList.contains(Xa))return null;const t=$e(e,n),r=[];for(const l of e.attributes)l.name.startsWith("data-")&&r.push({key:l.name.slice(5),value:l.value});return{block:{id:L(),type:"button",parentId:null,contentIds:t.map(l=>l.id),props:{href:e.getAttribute("href")??"",color:((s=e.style)==null?void 0:s.backgroundColor)||void 0,customAttrs:r}},runs:t}}const qa={component:Sd,isLeaf:!0,defaultProps:{href:"",color:"",customAttrs:[]},toHTML:Rd,toPlainText:Td,fromHTML:Bd,slashCommand:{label:"Button",icon:ac,keywords:["button","link","cta","action"],run:(e,n)=>Te(e,n,jd())}};function fs(e){return new Promise((n,t)=>{const r=new FileReader;r.onload=()=>n(r.result),r.onerror=()=>t(r.error),r.readAsDataURL(e)})}const Rt={image:"image",video:"video",audio:"audio",file:"file"},Ed={image:"image/*",video:"video/*",audio:"audio/*",file:"*/*"},Wa=20,Ga=100,Nd=[{value:"left",Icon:Vs,label:"Align left"},{value:"center",Icon:qi,label:"Align center"},{value:"right",Icon:Xs,label:"Align right"}];function Od(e){return Math.min(Ga,Math.max(Wa,Math.round(e)))}function Ld({kind:e,src:n,name:t,alt:r}){return e==="image"?a.jsx("img",{className:"be-embed-image",src:n,alt:r||""}):e==="video"?a.jsx("video",{className:"be-embed-video",src:n,controls:!0}):e==="audio"?a.jsx("audio",{className:"be-embed-audio",src:n,controls:!0}):a.jsxs("a",{className:"be-embed-file-link",href:n,download:t||void 0,target:"_blank",rel:"noopener noreferrer",children:[a.jsx(zs,{size:14})," ",t||n]})}function Md({id:e}){var re;const n=W(),t=be(e),[r,o]=d.useState(""),[s,l]=d.useState(!1),[i,c]=d.useState(null),[u,f]=d.useState(!1),[p,h]=d.useState(""),b=d.useRef(null),g=d.useRef(null),x=d.useCallback(H=>n.applyOperation(X(e,H)),[n,e]),k=d.useCallback(()=>{var H;h(((H=t==null?void 0:t.props)==null?void 0:H.alt)??""),f(!0)},[(re=t==null?void 0:t.props)==null?void 0:re.alt]),y=d.useCallback(()=>f(!1),[]),I=d.useCallback(H=>{H.preventDefault(),x({alt:p.trim()}),f(!1)},[p,x]),w=d.useCallback(async H=>{var te;const Q=(te=H.target.files)==null?void 0:te[0];if(!Q)return;const ee=await fs(Q);x({src:ee,name:Q.name,mimeType:Q.type})},[x]),T=d.useCallback(async H=>{var te;H.preventDefault(),l(!1);const Q=(te=H.dataTransfer.files)==null?void 0:te[0];if(!Q)return;const ee=await fs(Q);x({src:ee,name:Q.name,mimeType:Q.type})},[x]),S=d.useCallback(H=>{H.preventDefault(),l(!0)},[]),v=d.useCallback(()=>l(!1),[]),R=d.useCallback(()=>{const H=r.trim();H&&(x({src:H,name:H}),o(""))},[r,x]),O=d.useCallback(()=>x({src:"",name:"",mimeType:""}),[x]),N=d.useCallback(H=>{H.preventDefault();const Q=b.current,ee=g.current;if(!Q||!ee)return;const te=Q.getBoundingClientRect().width,me=ee.getBoundingClientRect().width,Se=H.clientX,oe=$=>Od((me+($.clientX-Se))/te*100),ke=$=>c(oe($)),fe=$=>{document.removeEventListener("mousemove",ke),document.removeEventListener("mouseup",fe),x({width:oe($)}),c(null)};document.addEventListener("mousemove",ke),document.addEventListener("mouseup",fe)},[x]),C=ve("be-embed",t);if(!t)return null;const{kind:B="file",src:A,name:z,alt:U="",align:q="left",width:le=100}=t.props,se=B==="image"||B==="video",G=i??le;return a.jsxs("div",{className:C,"data-block-id":e,"data-kind":B,contentEditable:!1,tabIndex:-1,children:[A?a.jsx("div",{ref:b,className:`be-embed-preview be-embed-align-${q}`,children:a.jsxs("div",{ref:g,className:"be-embed-frame",style:se?{width:`${G}%`}:void 0,children:[a.jsxs("div",{className:"be-embed-toolbar",contentEditable:!1,children:[Nd.map(({value:H,Icon:Q,label:ee})=>a.jsx("button",{type:"button",className:`be-embed-toolbar-btn${q===H?" be-embed-toolbar-btn-active":""}`,title:ee,"aria-label":ee,"aria-pressed":q===H,onClick:()=>x({align:H}),children:a.jsx(Q,{size:14})},H)),B==="image"&&a.jsx("button",{type:"button",className:"be-embed-toolbar-btn be-embed-alt-text-btn",onClick:k,children:"Alt text"}),a.jsx("button",{type:"button",className:"be-embed-remove",onClick:O,"aria-label":`Remove ${Rt[B]}`,children:"Remove"})]}),a.jsx(Ld,{kind:B,src:A,name:z,alt:U}),se&&a.jsx("div",{className:"be-embed-resize-handle",onMouseDown:N,role:"slider","aria-label":`Resize ${Rt[B]}`,"aria-valuemin":Wa,"aria-valuemax":Ga,"aria-valuenow":G})]})}):a.jsxs("div",{className:`be-embed-dropzone${s?" be-embed-dropzone-active":""}`,onDrop:T,onDragOver:S,onDragLeave:v,children:[a.jsxs("label",{className:"be-embed-upload-btn",children:["Upload ",Rt[B],a.jsx("input",{type:"file",accept:Ed[B],onChange:w,hidden:!0})]}),a.jsx("span",{className:"be-embed-dropzone-hint",children:"or drop a file, or paste a URL below"}),a.jsxs("div",{className:"be-embed-url-row",children:[a.jsx("input",{type:"text",className:"be-embed-url-input",placeholder:`https://... ${Rt[B]} URL`,value:r,onChange:H=>o(H.target.value),onKeyDown:H=>H.key==="Enter"&&R()}),a.jsx("button",{type:"button",className:"be-embed-url-commit",onClick:R,children:"Embed"})]})]}),a.jsx(on,{isOpen:u,onClose:y,title:"Alt text",children:a.jsxs("form",{onSubmit:I,children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Describe this image for screen readers"}),a.jsx("input",{type:"text",value:p,onChange:H=>h(H.target.value),placeholder:"e.g. A hand-drawn diagram of the release process",autoFocus:!0})]}),a.jsxs("div",{className:"be-modal-actions",children:[a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:y,children:"Cancel"}),a.jsx("button",{type:"submit",className:"be-modal-save",children:"Save"})]})]})})]})}function Ad({kind:e="file",src:n="",name:t="",alt:r="",mimeType:o="",align:s="left",width:l=100}={}){return function(c){return{block:{id:L(),type:"embed",parentId:c,contentIds:[],props:{kind:e,src:n,name:t,alt:r,mimeType:o,align:s,width:l}},runs:[]}}}const Dd={image:uc,video:dc,audio:pc,file:zs},Za="be-embed-file-link";function Pd(e,n,t){if(e!=="image"&&e!=="video")return"";const r=[];return t!==100&&r.push(`width:${t}%`),n==="center"?r.push("display:block","margin-left:auto","margin-right:auto"):n==="right"&&r.push("display:block","margin-left:auto"),r.length?` style="${r.join(";")}"`:""}function hs(e){var o,s,l,i;const n=(o=e.style)==null?void 0:o.width,t=n&&n.endsWith("%")?parseInt(n,10):100;let r="left";return((s=e.style)==null?void 0:s.marginLeft)==="auto"&&((l=e.style)==null?void 0:l.marginRight)==="auto"?r="center":((i=e.style)==null?void 0:i.marginLeft)==="auto"&&(r="right"),{align:r,width:Number.isFinite(t)?t:100}}function $d(e){const{kind:n,src:t,name:r,alt:o="",align:s="left",width:l=100}=e.props;if(!t)return"<p></p>";const i=Pd(n,s,l);return n==="image"?`<img src="${Re(t)}" alt="${Re(o)}"${i}>`:n==="video"?`<video src="${Re(t)}" controls${i}></video>`:n==="audio"?`<audio src="${Re(t)}" controls></audio>`:`<a class="${Za}" href="${Re(t)}">${vn(r||t)}</a>`}function _d(e){const{kind:n,src:t,name:r}=e.props;return t?`[${n}: ${r||t}]`:""}function zd(e){return e.tagName==="IMG"?Tt("image",e.getAttribute("src")??"","",{...hs(e),alt:e.getAttribute("alt")??""}):e.tagName==="VIDEO"?Tt("video",e.getAttribute("src")??"","",hs(e)):e.tagName==="AUDIO"?Tt("audio",e.getAttribute("src")??"",""):e.tagName==="A"&&e.classList.contains(Za)?Tt("file",e.getAttribute("href")??"",e.textContent??""):null}function Tt(e,n,t,{align:r="left",width:o=100,alt:s=""}={}){return{block:{id:L(),type:"embed",parentId:null,contentIds:[],props:{kind:e,src:n,name:t,alt:s,align:r,width:o}},runs:[]}}function Hd(e){return(n,{blockId:t,runId:r,sliceStart:o,sliceEnd:s})=>{const l=n.getRun(r),i=(l==null?void 0:l.value)??"";n.applyOperation(ce(r,{value:i.slice(0,o)+i.slice(s)}));const c=Zt(n,t,Ad({kind:e}));return Ge(n,c,J("paragraph")),c}}const Ja={component:Md,isLeaf:!0,defaultProps:{kind:"file",src:"",name:"",alt:"",mimeType:"",align:"left",width:100},toHTML:$d,toPlainText:_d,fromHTML:zd,slashCommands:["image","video","audio","file"].map(e=>({label:e.charAt(0).toUpperCase()+e.slice(1),icon:Dd[e],keywords:["embed","upload","insert",e],run:Hd(e)}))},Qa=8,el=.5,Fd=.5,Ud=4,vr=.15,Yd=8;function nl(e,n){return Math.hypot(e[0]-n[0],e[1]-n[1])}function Mt(e,n,t){return Math.min(t,Math.max(n,e))}function Bt(e){return Math.round(e*100)/100}const tl=.5;function Kd(e){return e.some(([,,n])=>n!==void 0&&n!==tl)}function Vd(e,{size:n=Qa,thinning:t=el}={}){const r=n/2,o=e.length;if(!Kd(e))return new Array(o).fill(r);const l=new Array(o);let i=0;for(let u=0;u<o;u+=1){if(u>0){const g=nl(e[u],e[u-1]);i=i*.8+g*.2}const f=Mt(i/Yd,0,1),p=e[u][2]??tl,h=.4+.6*Mt(p,0,1),b=Mt(r*h*(1-t*f),r*vr,r);l[u]=b}const c=Math.min(Ud,Math.floor(o/2));for(let u=0;u<c;u+=1){const f=(u+1)/(c+1),p=vr+(1-vr)*f;l[u]*=p,l[o-1-u]*=p}return l}function Xd(e,n){const t=e.length;if(t<3||n<=0)return e;const r=new Array(t);r[0]=e[0],r[t-1]=e[t-1];for(let o=1;o<t-1;o+=1){const s=(e[o-1][0]+e[o+1][0])/2,l=(e[o-1][1]+e[o+1][1])/2,i=e[o][0]+(s-e[o][0])*n,c=e[o][1]+(l-e[o][1])*n;r[o]=[i,c,e[o][2]]}return r}function qd(e,n){const t=e.length,r=new Array(t),o=new Array(t);for(let s=0;s<t;s+=1){const l=e[Math.max(0,s-1)],i=e[Math.min(t-1,s+1)];let c=i[0]-l[0],u=i[1]-l[1];const f=Math.hypot(c,u)||1;c/=f,u/=f;const p=-u,h=c,b=n[s];r[s]=[e[s][0]+p*b,e[s][1]+h*b],o[s]=[e[s][0]-p*b,e[s][1]-h*b]}return{left:r,right:o}}function rl(e){if(e.length===0)return"";let n=`M${Bt(e[0][0])},${Bt(e[0][1])}`;for(let t=1;t<e.length;t+=1)n+=` L${Bt(e[t][0])},${Bt(e[t][1])}`;return n}function Wd([e,n],t){const o=[];for(let s=0;s<12;s+=1){const l=s/12*Math.PI*2;o.push([e+Math.cos(l)*t,n+Math.sin(l)*t])}return`${rl(o)} Z`}function _t(e,n={}){const{size:t=Qa,thinning:r=el,smoothing:o=Fd}=n;if(!e||e.length===0)return"";const s=[e[0]];for(let p=1;p<e.length;p+=1)nl(e[p],s[s.length-1])>.1&&s.push(e[p]);if(s.length===1){const p=s[0][2]??.5,h=t/2*(.4+.6*Mt(p,0,1));return Wd(s[0],h)}const l=Vd(s,{size:t,thinning:r}),i=Xd(s,o),{left:c,right:u}=qd(i,l),f=[...c,...u.slice().reverse()];return`${rl(f)} Z`}function At(e){if(!e||e.length===0)return{minX:0,minY:0,maxX:0,maxY:0};let n=1/0,t=1/0,r=-1/0,o=-1/0;for(const[s,l]of e)s<n&&(n=s),l<t&&(t=l),s>r&&(r=s),l>o&&(o=l);return{minX:n,minY:t,maxX:r,maxY:o}}function fo(e,n){const t=e.getBoundingClientRect(),r=t.width||1,o=t.height||1,s=Math.min(r/n,o/n),l=(r-n*s)/2,i=(o-n*s)/2;return{rect:t,scale:s,offsetX:l,offsetY:i}}function Ye(e,n,t={x:0,y:0,size:1e3}){const{rect:r,scale:o,offsetX:s,offsetY:l}=fo(n,t.size),i=t.x+(e.clientX-r.left-s)/o,c=t.y+(e.clientY-r.top-l)/o;return[i,c]}function Gd(e,n){return fo(e,n).scale}function Zd(e,n,t,r){const[o,s]=Ye(e,n,t),{rect:l,scale:i,offsetX:c,offsetY:u}=fo(n,r),f=o-(e.clientX-l.left-c)/i,p=s-(e.clientY-l.top-u)/i;return{x:f,y:p}}function bs(e,n){const t=e.x+e.size/2,r=e.y+e.size/2;return{x:t-n/2,y:r-n/2}}function Qn(e,n,t=0){return e.minX-t<=n.maxX&&e.maxX+t>=n.minX&&e.minY-t<=n.maxY&&e.maxY+t>=n.minY}function ot(e,n,t,r){const o=Math.min(e,t),s=Math.min(n,r),l=Math.abs(t-e),i=Math.abs(r-n);return{x:o,y:s,width:l,height:i}}function ol(e,n,t,r,o){const s=o*Math.PI/180,l=Math.cos(s),i=Math.sin(s),c=e-t,u=n-r;return[t+c*l-u*i,r+c*i+u*l]}function sl(e,n,t){return e>=t.x&&e<=t.x+t.width&&n>=t.y&&n<=t.y+t.height}function Jd(e,n,t){const r=t.width/2,o=t.height/2;if(r===0||o===0)return!1;const s=t.x+r,l=t.y+o,i=(e-s)/r,c=(n-l)/o;return i*i+c*c<=1}function Qd(e,n,t,r,o,s){const l=o-t,i=s-r,c=l*l+i*i;if(c===0)return Math.hypot(e-t,n-r);let u=((e-t)*l+(n-r)*i)/c;u=Math.min(1,Math.max(0,u));const f=t+u*l,p=r+u*i;return Math.hypot(e-f,n-p)}function al(e,n,t,r,o,s,l){return Qd(e,n,t,r,o,s)<=l}function ll(e){const{x:n,y:t,width:r,height:o}=e;return[[n+r/2,t],[n+r,t+o/2],[n+r/2,t+o],[n,t+o/2]]}function il(e){const{x:n,y:t,width:r,height:o}=e;return[[n+r/2,t],[n+r,t+o],[n,t+o]]}function cl(e,n=5){const{x:t,y:r,width:o,height:s}=e,l=t+o/2,i=r+s/2,c=o/2,u=s/2,f=.4,p=[],h=Math.PI/n;let b=-Math.PI/2;for(let g=0;g<n*2;g+=1){const x=g%2===0,k=x?c:c*f,y=x?u:u*f;p.push([l+Math.cos(b)*k,i+Math.sin(b)*y]),b+=h}return p}function ep(e,n,t){let r=!1;for(let o=0,s=t.length-1;o<t.length;s=o,o+=1){const[l,i]=t[o],[c,u]=t[s];i>n!=u>n&&e<(c-l)*(n-i)/(u-i)+l&&(r=!r)}return r}function ul(e,n,t,r,o=24){const s=t-e,l=r-n,i=Math.hypot(s,l),[c,u]=i===0?[1,0]:[s/i,l/i],f=t-c*o,p=r-u*o,h=-u,b=c,g=o/2;return[[t,r],[f+h*g,p+b*g],[f-h*g,p-b*g]]}function np({compute:e,onCommit:n}){const[t,r]=d.useState(null),o=d.useCallback((s,l)=>{s.preventDefault();const i=u=>r(e(u,l)),c=u=>{document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",c),n(e(u,l)),r(null)};document.addEventListener("mousemove",i),document.addEventListener("mouseup",c)},[e,n]);return{dragValue:t,startDrag:o}}const ho=480,bo=320;function tp({strokes:e=[],shapes:n=[],width:t=ho,height:r=bo}={}){return function(s){return{block:{id:L(),type:"canvas",parentId:s,contentIds:[],props:{strokes:e,shapes:n,width:t,height:r}},runs:[]}}}const rp={diamond:ll,triangle:il,star:cl};function op(e){const n=e.strokeWidth??8,t=Re(e.color);if(e.type==="arrow"){const i=Math.max(16,n*3),u=ul(e.x1,e.y1,e.x2,e.y2,i).map(([f,p])=>`${f},${p}`).join(" ");return`<line x1="${e.x1}" y1="${e.y1}" x2="${e.x2}" y2="${e.y2}" stroke="${t}" stroke-width="${n}"></line><polygon points="${u}" fill="${t}"></polygon>`}const r=e.fillColor?Re(e.fillColor):"none";let o;if(e.type==="rectangle")o=`<rect x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}" fill="${r}" stroke="${t}" stroke-width="${n}"></rect>`;else if(e.type==="ellipse"){const i=e.x+e.width/2,c=e.y+e.height/2;o=`<ellipse cx="${i}" cy="${c}" rx="${e.width/2}" ry="${e.height/2}" fill="${r}" stroke="${t}" stroke-width="${n}"></ellipse>`}else if(e.type==="text"){const i=e.fontSize??28,c=vn(e.text??"");o=`<foreignObject x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}"><div xmlns="http://www.w3.org/1999/xhtml" style="width:100%;height:100%;overflow:hidden;color:${t};font-size:${i}px;line-height:1.3;white-space:pre-wrap;word-break:break-word;">${c}</div></foreignObject>`}else{const i=rp[e.type];if(!i)return"";const c={x:e.x,y:e.y,width:e.width,height:e.height};o=`<polygon points="${i(c).map(([f,p])=>`${f},${p}`).join(" ")}" fill="${r}" stroke="${t}" stroke-width="${n}"></polygon>`}if(!e.rotation)return o;const s=e.x+e.width/2,l=e.y+e.height/2;return`<g transform="rotate(${e.rotation} ${s} ${l})">${o}</g>`}function dl(e){const{strokes:n=[],shapes:t=[],width:r,height:o}=e.props,s=n.map(i=>`<path fill="${Re(i.color)}" d="${_t(i.points,{size:i.size})}"></path>`).join(""),l=t.map(op).join("");return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000" width="${r}" height="${o}">${s}${l}</svg>`}const kn=1e3,ms="#1a1a1a",pl=8,gs=["#1a1a1a","#e03131","#2f9e44","#1971c2","#f08c00"],sp=2,ap=40,lp=24,ip=6,xs=160,cp=120,wr=.5,Ir=4,Et=1.1,ks=4,Nt=24,up=1,dp=10,ys={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},pp=220,fp=60,Br=28,hp=12,bp=96,Er=10,vs=15,ws=Er*5;function Ae(e){return Math.round(e/Er)*Er}function mp(e){return Math.round(e/vs)*vs}function gp(){const e=d.useRef(new WeakMap);return n=>{const t=e.current;let r=t.get(n);return r===void 0&&(r=_t(n.points,{size:n.size}),t.set(n,r)),r}}function xp(e,n,t){return{minX:e-t,minY:n-t,maxX:e+t,maxY:n+t}}function kp(e,n,t,r){const o=e.points;if(o.length===1){const[s,l]=o[0];return Math.hypot(n-s,t-l)<=r}for(let s=0;s<o.length-1;s+=1){const[l,i]=o[s],[c,u]=o[s+1];if(al(n,t,l,i,c,u,r))return!0}return!1}const Cr=new Set(["rectangle","ellipse","arrow","diamond","triangle","star"]),fl={diamond:ll,triangle:il,star:cl},Is=[{type:"rectangle",label:"Rectangle",Icon:qs},{type:"ellipse",label:"Ellipse",Icon:Gi},{type:"arrow",label:"Arrow",Icon:Zi},{type:"diamond",label:"Diamond",Icon:Ji},{type:"triangle",label:"Triangle",Icon:Qi},{type:"star",label:"Star",Icon:ec}],Cs=[{mode:"object",label:"Object Eraser",Icon:Ws},{mode:"precise",label:"Precise Eraser",Icon:zn}];function Sr(e,n,t,r){return e.type==="arrow"?{type:"arrow",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,color:n,strokeWidth:t}:{type:e.type,...ot(e.x1,e.y1,e.x2,e.y2),color:n,strokeWidth:t,fillColor:r}}const yp=16;function hl(e,n,t){for(let r=t.length-1;r>=0;r-=1){const o=t[r];if(o.type==="arrow"){if(al(e,n,o.x1,o.y1,o.x2,o.y2,yp))return o.id;continue}const s={x:o.x,y:o.y,width:o.width,height:o.height};let[l,i]=[e,n];if(o.rotation){const{cx:f,cy:p}=or(o);[l,i]=ol(e,n,f,p,-o.rotation)}const c=fl[o.type];let u;if(c?u=ep(l,i,c(s)):u=o.type==="ellipse"?Jd(l,i,s):sl(l,i,s),u)return o.id}return null}function et(e,n,t){return e.type==="arrow"?{...e,x1:e.x1+n,y1:e.y1+t,x2:e.x2+n,y2:e.y2+t}:{...e,x:e.x+n,y:e.y+t}}function it(e){return e.type==="arrow"?{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x2-e.x1),height:Math.abs(e.y2-e.y1)}:{x:e.x,y:e.y,width:e.width,height:e.height}}function or(e){const n=it(e);return{cx:n.x+n.width/2,cy:n.y+n.height/2}}function nt(e,n,t){return{...e,points:e.points.map(([r,o,s])=>[r+n,o+t,s])}}function vp(e,n){const t=[];let r=[];for(let o=0;o<e.length;o+=1)n.has(o)?(r.length>0&&t.push(r),r=[]):r.push(e[o]);return r.length>0&&t.push(r),t}function bl(e){const n=At(e.points);return{x:n.minX,y:n.minY,width:n.maxX-n.minX,height:n.maxY-n.minY}}function wp(e,n){return e==="stroke"?bl(n):it(n)}function Ss(e,n){var l,i;const t=((l=e==null?void 0:e.props)==null?void 0:l.strokes)??[],r=((i=e==null?void 0:e.props)==null?void 0:i.shapes)??[],o=t.find(c=>c.id===n);if(o)return{kind:"stroke",item:o};const s=r.find(c=>c.id===n);return s?{kind:"shape",item:s}:null}function Ip(e,n,t,r){const o=hl(e,n,r);if(o)return{kind:"shape",id:o};for(let s=t.length-1;s>=0;s-=1){const l=t[s];if(sl(e,n,bl(l)))return{kind:"stroke",id:l.id}}return null}const Ot=24,tt=14;function Nr(e){return{nw:[e.x,e.y],ne:[e.x+e.width,e.y],sw:[e.x,e.y+e.height],se:[e.x+e.width,e.y+e.height]}}const Cp={nw:"se",ne:"sw",sw:"ne",se:"nw"},Sp=32;function ml(e){const n=it(e),t=n.x+n.width/2,r=n.y-Sp;if(!e.rotation)return[t,r];const{cx:o,cy:s}=or(e);return ol(t,r,o,s,e.rotation)}function jp(e,n,t){if(!t)return null;if(t.type==="arrow")return Math.hypot(e-t.x1,n-t.y1)<=Ot?"start":Math.hypot(e-t.x2,n-t.y2)<=Ot?"end":null;const[r,o]=ml(t);if(Math.hypot(e-r,n-o)<=Ot)return"rotate";if(t.rotation)return null;for(const[s,[l,i]]of Object.entries(Nr(t)))if(Math.hypot(e-l,n-i)<=Ot)return s;return null}function jr(e,n){return n.mode==="arrow-endpoint"?n.endpoint==="start"?{...e,x1:n.x,y1:n.y}:{...e,x2:n.x,y2:n.y}:n.mode==="rotate"?{...e,rotation:n.rotation}:{...e,...ot(n.fixedX,n.fixedY,n.x,n.y)}}function js({shape:e,opacity:n=1}){const t=e.strokeWidth??pl;let r;if(e.type==="rectangle")r=a.jsx("rect",{x:e.x,y:e.y,width:e.width,height:e.height,fill:e.fillColor??"none",stroke:e.color,strokeWidth:t,opacity:n});else if(e.type==="ellipse")r=a.jsx("ellipse",{cx:e.x+e.width/2,cy:e.y+e.height/2,rx:e.width/2,ry:e.height/2,fill:e.fillColor??"none",stroke:e.color,strokeWidth:t,opacity:n});else if(e.type==="arrow"){const l=Math.max(16,t*3),i=ul(e.x1,e.y1,e.x2,e.y2,l);return a.jsxs("g",{opacity:n,children:[a.jsx("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:e.color,strokeWidth:t}),a.jsx("polygon",{points:i.map(([c,u])=>`${c},${u}`).join(" "),fill:e.color})]})}else if(e.type==="text")r=a.jsx("foreignObject",{x:e.x,y:e.y,width:e.width,height:e.height,opacity:n,children:a.jsx("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{width:"100%",height:"100%",overflow:"hidden",color:e.color,fontSize:e.fontSize??Br,lineHeight:1.3,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"inherit"},children:e.text})});else{const l=fl[e.type];if(!l)return null;const i={x:e.x,y:e.y,width:e.width,height:e.height},c=l(i).map(([u,f])=>`${u},${f}`).join(" ");r=a.jsx("polygon",{points:c,fill:e.fillColor??"none",stroke:e.color,strokeWidth:t,opacity:n})}if(!e.rotation)return r;const{cx:o,cy:s}=or(e);return a.jsx("g",{transform:`rotate(${e.rotation} ${o} ${s})`,children:r})}function Rp({id:e}){const n=W(),t=be(e),r=ve("be-canvas",t),o=gp(),[s,l]=d.useState("pen"),[i,c]=d.useState("object"),[u,f]=d.useState(ms),[p,h]=d.useState(pl),[b,g]=d.useState(null),[x,k]=d.useState(!0),[y,I]=d.useState(Br),[w,T]=d.useState("rectangle"),[S,v]=d.useState(!1),[R,O]=d.useState(!1),[N,C]=d.useState(!1),[B,A]=d.useState(!1),[z,U]=d.useState(!1),[q,le]=d.useState(!1),se=d.useRef(null),G=d.useRef(null),re=d.useRef(null),H=d.useRef(null),Q=d.useRef(null),ee=d.useRef(null),te=d.useRef(null),me=d.useRef(null),Se=d.useRef(null),oe=d.useRef(null),ke=d.useRef(null),fe=d.useRef(null),$=d.useMemo(()=>[se,G],[]),we=d.useMemo(()=>[re,H],[]),_e=d.useMemo(()=>[Q,ee],[]),ht=d.useMemo(()=>[te,me],[]),ar=d.useMemo(()=>[Se,oe],[]),li=d.useMemo(()=>[ke,fe],[]),Ro=d.useCallback(()=>v(!1),[]),lr=d.useCallback(()=>O(!1),[]),ii=d.useCallback(()=>C(!1),[]),To=d.useCallback(()=>A(!1),[]),ci=d.useCallback(()=>U(!1),[]),Bo=d.useCallback(()=>le(!1),[]);Pe($,S,Ro),Pe(we,R,lr),Pe(_e,N,ii),Pe(ht,B,To),Pe(ar,z,ci),Pe(li,q,Bo);const Ze=d.useRef(null),Vn=d.useRef([]),Xn=d.useRef(!1),Cn=d.useRef(null),[Eo,No]=d.useState(null),ln=d.useRef(new Set),bn=d.useRef(new Set),Sn=d.useRef(new Map),qn=d.useRef(!1),jn=d.useRef(null),[ui,Oo]=d.useState(()=>new Set),[di,Lo]=d.useState(()=>new Set),ze=d.useRef(null),[Mo,ir]=d.useState(null),[ne,Je]=d.useState(()=>new Set),mn=d.useRef(null),[ye,Ao]=d.useState(null),gn=d.useRef(null),[Wn,Do]=d.useState(null),cr=d.useRef([]),[de,Rn]=d.useState(null),He=d.useRef(null),[cn,ur]=d.useState(null),[pe,Gn]=d.useState({x:0,y:0,zoom:1}),Fe=kn/pe.zoom,Ue=d.useRef(null),{dragValue:Tn,startDrag:Po}=np({compute:(m,j)=>({width:Math.max(xs,Math.round(j.startWidth+(m.clientX-j.startX))),height:Math.max(cp,Math.round(j.startHeight+(m.clientY-j.startY)))}),onCommit:m=>n.applyOperation(X(e,m))}),$o=d.useCallback(m=>{Cn.current==null&&(Cn.current=requestAnimationFrame(()=>{Cn.current=null,No(_t(Vn.current,{size:m}))}))},[]),bt=d.useCallback(()=>{Xn.current=!1,Cn.current!=null&&(cancelAnimationFrame(Cn.current),Cn.current=null),Vn.current=[],No(null)},[]),_o=d.useCallback(()=>{var M;const m=Vn.current;if(m.length===0)return;const j={id:L(),points:m,color:u,size:p},E=((M=t==null?void 0:t.props)==null?void 0:M.strokes)??[];n.applyOperation(X(e,{strokes:[...E,j]}))},[n,e,t,u,p]),zo=d.useCallback(()=>{jn.current==null&&(jn.current=requestAnimationFrame(()=>{jn.current=null,Oo(new Set(ln.current)),Lo(new Set(bn.current))}))},[]),mt=d.useCallback((m,j)=>{var Y,V;const E=i==="precise"?ip:lp,M=xp(m,j,E),D=((Y=t==null?void 0:t.props)==null?void 0:Y.strokes)??[];for(const _ of D){if(i==="precise"){const xn=At(_.points);if(!Qn(xn,M,_.size/2))continue;let ue=Sn.current.get(_.id);_.points.forEach(([Ne,Ee],je)=>{ue!=null&&ue.has(je)||Math.hypot(Ne-m,Ee-j)>E||(ue||(ue=new Set,Sn.current.set(_.id,ue)),ue.add(je))}),ue!=null&&ue.size&&ln.current.add(_.id);continue}if(ln.current.has(_.id))continue;const K=_.size/2,ie=At(_.points);Qn(ie,M,K)&&kp(_,m,j,E+K)&&ln.current.add(_.id)}const P=((V=t==null?void 0:t.props)==null?void 0:V.shapes)??[];for(const _ of P){if(bn.current.has(_.id))continue;const K=it(_),ie={minX:K.x,minY:K.y,maxX:K.x+K.width,maxY:K.y+K.height};Qn(ie,M)&&bn.current.add(_.id)}zo()},[t,i,zo]),gt=d.useCallback(()=>{qn.current=!1,jn.current!=null&&(cancelAnimationFrame(jn.current),jn.current=null),ln.current=new Set,bn.current=new Set,Sn.current=new Map,Oo(new Set),Lo(new Set)},[]),Ho=d.useCallback(()=>{var P,Y;const m=i!=="precise"&&ln.current.size>0,j=i==="precise"&&Sn.current.size>0;if(!m&&!j&&bn.current.size===0)return;const E=((P=t==null?void 0:t.props)==null?void 0:P.strokes)??[],M=((Y=t==null?void 0:t.props)==null?void 0:Y.shapes)??[];let D;if(m)D=E.filter(V=>!ln.current.has(V.id));else if(j){D=[];for(const V of E){const _=Sn.current.get(V.id);if(!_||_.size===0){D.push(V);continue}vp(V.points,_).forEach((K,ie)=>{D.push({...V,id:ie===0?V.id:L(),points:K})})}}else D=E;n.applyOperation(X(e,{strokes:D,shapes:M.filter(V=>!bn.current.has(V.id))}))},[n,e,t,i]),xt=d.useCallback(()=>{ze.current=null,ir(null)},[]),Fo=d.useCallback(()=>{var M;const m=ze.current;if(!m)return;if(m.type==="arrow"){if(m.x1===m.x2&&m.y1===m.y2)return}else{const D=ot(m.x1,m.y1,m.x2,m.y2);if(D.width===0||D.height===0)return}const j={id:L(),...Sr(m,u,p,b)},E=((M=t==null?void 0:t.props)==null?void 0:M.shapes)??[];n.applyOperation(X(e,{shapes:[...E,j]}))},[n,e,t,u,p,b]),kt=d.useCallback(()=>{mn.current=null,Ao(null)},[]),Uo=d.useCallback(()=>{var Y,V;const m=mn.current;if(!m||m.dx===0&&m.dy===0)return;const j=new Set(m.ids),E=((Y=t==null?void 0:t.props)==null?void 0:Y.strokes)??[],M=((V=t==null?void 0:t.props)==null?void 0:V.shapes)??[],D=E.map(_=>j.has(_.id)?nt(_,m.dx,m.dy):_),P=M.map(_=>j.has(_.id)?et(_,m.dx,m.dy):_);n.applyOperation(X(e,{strokes:D,shapes:P}))},[n,e,t]),yt=d.useCallback(()=>{gn.current=null,Do(null)},[]),Yo=d.useCallback(()=>{var Y,V;const m=gn.current;if(!m)return;const j=ot(m.startX,m.startY,m.x,m.y);if(j.width<ks&&j.height<ks){Je(new Set);return}const E={minX:j.x,minY:j.y,maxX:j.x+j.width,maxY:j.y+j.height},M=((Y=t==null?void 0:t.props)==null?void 0:Y.strokes)??[],D=((V=t==null?void 0:t.props)==null?void 0:V.shapes)??[],P=[];for(const _ of M)Qn(At(_.points),E)&&P.push(_.id);for(const _ of D){const K=it(_),ie={minX:K.x,minY:K.y,maxX:K.x+K.width,maxY:K.y+K.height};Qn(ie,E)&&P.push(_.id)}Je(new Set(P))},[t]),dr=d.useCallback(()=>{ne.size!==0&&(cr.current=[...ne].map(m=>Ss(t,m)).filter(Boolean))},[t,ne]),pr=d.useCallback(()=>{var Y,V;const m=cr.current;if(m.length===0)return;const j=((Y=t==null?void 0:t.props)==null?void 0:Y.strokes)??[],E=((V=t==null?void 0:t.props)==null?void 0:V.shapes)??[],M=[],D=[],P=[];for(const{kind:_,item:K}of m){const ie=L();P.push(ie),_==="stroke"?M.push({...nt(K,Nt,Nt),id:ie}):D.push({...et(K,Nt,Nt),id:ie})}n.applyOperation(X(e,{strokes:[...j,...M],shapes:[...E,...D]})),Je(new Set(P)),l("select")},[n,e,t]),Bn=d.useCallback(m=>{var D,P;if(ne.size===0)return;const j=Y=>{const V=Y.filter(K=>ne.has(K.id));if(V.length===0)return Y;const _=Y.filter(K=>!ne.has(K.id));return m?[..._,...V]:[...V,..._]},E=((D=t==null?void 0:t.props)==null?void 0:D.strokes)??[],M=((P=t==null?void 0:t.props)==null?void 0:P.shapes)??[];n.applyOperation(X(e,{strokes:j(E),shapes:j(M)}))},[n,e,t,ne]),pi=d.useCallback(()=>Bn(!0),[Bn]),fi=d.useCallback(()=>Bn(!1),[Bn]),fr=d.useCallback((m,j)=>{Rn({id:null,x:m,y:j,width:pp,height:fp,text:"",color:u,fontSize:y})},[u,y]),vt=d.useCallback(m=>{Rn({id:m.id,x:m.x,y:m.y,width:m.width,height:m.height,text:m.text,color:m.color,fontSize:m.fontSize??Br})},[]),hi=d.useCallback(()=>{Rn(null)},[]),bi=d.useCallback(()=>{var Y,V,_;const m=de;if(!m)return;Rn(null);const j=((Y=t==null?void 0:t.props)==null?void 0:Y.shapes)??[],E=m.text;if(!E.trim()){m.id&&(n.applyOperation(X(e,{shapes:j.filter(K=>K.id!==m.id)})),Je(new Set)),(V=Ze.current)==null||V.focus();return}const M=m.id??L(),D={id:M,type:"text",x:m.x,y:m.y,width:m.width,height:m.height,text:E,color:m.color,fontSize:m.fontSize},P=m.id?j.map(K=>K.id===m.id?D:K):[...j,D];n.applyOperation(X(e,{shapes:P})),Je(new Set([M])),l("select"),(_=Ze.current)==null||_.focus()},[n,e,t,de]),wt=d.useCallback(()=>{He.current=null,ur(null)},[]),Ko=d.useCallback(()=>{var P;const m=He.current;if(!m)return;const j=((P=t==null?void 0:t.props)==null?void 0:P.shapes)??[],E=j.find(Y=>Y.id===m.shapeId);if(!E)return;const M=jr(E,m);if(M.type!=="arrow"&&(M.width===0||M.height===0))return;const D=j.map(Y=>Y.id===m.shapeId?M:Y);n.applyOperation(X(e,{shapes:D}))},[n,e,t]),mi=d.useCallback(m=>{var M,D,P,Y,V;if(m.key==="Backspace"||m.key==="Delete"){if(ne.size===0)return;m.preventDefault();const _=((M=t==null?void 0:t.props)==null?void 0:M.strokes)??[],K=((D=t==null?void 0:t.props)==null?void 0:D.shapes)??[];n.applyOperation(X(e,{strokes:_.filter(ie=>!ne.has(ie.id)),shapes:K.filter(ie=>!ne.has(ie.id))})),Je(new Set);return}if(ys[m.key]&&!m.ctrlKey&&!m.metaKey){if(ne.size===0)return;m.preventDefault();const _=m.shiftKey?dp:up,[K,ie]=ys[m.key],xn=K*_,ue=ie*_,Ne=((P=t==null?void 0:t.props)==null?void 0:P.strokes)??[],Ee=((Y=t==null?void 0:t.props)==null?void 0:Y.shapes)??[];n.applyOperation(X(e,{strokes:Ne.map(je=>ne.has(je.id)?nt(je,xn,ue):je),shapes:Ee.map(je=>ne.has(je.id)?et(je,xn,ue):je)}));return}if(m.key==="Enter"&&!m.ctrlKey&&!m.metaKey){if(ne.size!==1)return;const[_]=ne,K=(((V=t==null?void 0:t.props)==null?void 0:V.shapes)??[]).find(ie=>ie.id===_&&ie.type==="text");if(!K)return;m.preventDefault(),vt(K);return}if(!(m.ctrlKey||m.metaKey))return;const E=m.key.toLowerCase();if(E==="c"){if(ne.size===0)return;m.preventDefault(),dr()}else if(E==="v"){if(cr.current.length===0)return;m.preventDefault(),pr()}else if(E==="d"){if(ne.size===0)return;m.preventDefault(),dr(),pr()}else if(m.shiftKey&&(E==="]"||E==="[")){if(ne.size===0)return;m.preventDefault(),Bn(E==="]")}},[n,e,t,ne,dr,pr,Bn,vt]),un={x:pe.x,y:pe.y,size:Fe},hr=d.useCallback(m=>{if(!m.ctrlKey&&!m.metaKey)return;m.preventDefault();const j=Ze.current;j&&Gn(E=>{const M=m.deltaY<0?Et:1/Et,D=Math.min(Ir,Math.max(wr,E.zoom*M)),P=kn/D,{x:Y,y:V}=Zd(m,j,{x:E.x,y:E.y,size:kn/E.zoom},P);return{x:Y,y:V,zoom:D}})},[]);d.useEffect(()=>{const m=Ze.current;if(m)return m.addEventListener("wheel",hr,{passive:!1}),()=>m.removeEventListener("wheel",hr)},[hr]);const gi=d.useCallback(()=>{Gn(m=>{const j=Math.min(Ir,m.zoom*Et),E=kn/j,{x:M,y:D}=bs({x:m.x,y:m.y,size:kn/m.zoom},E);return{x:M,y:D,zoom:j}})},[]),xi=d.useCallback(()=>{Gn(m=>{const j=Math.max(wr,m.zoom/Et),E=kn/j,{x:M,y:D}=bs({x:m.x,y:m.y,size:kn/m.zoom},E);return{x:M,y:D,zoom:j}})},[]),ki=d.useCallback(()=>{Gn({x:0,y:0,zoom:1})},[]),yi=d.useCallback(()=>{if(!t)return;const m=dl(t),j=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(m)}`,E=new Image;E.onload=()=>{const M=document.createElement("canvas");M.width=t.props.width,M.height=t.props.height;const D=M.getContext("2d");if(!D)return;D.drawImage(E,0,0,M.width,M.height);const P=document.createElement("a");P.href=M.toDataURL("image/png"),P.download="canvas.png",document.body.appendChild(P),P.click(),document.body.removeChild(P)},E.src=j},[t]),vi=d.useCallback(m=>{var V;if(s!=="select")return;const j=Ze.current;if(!j)return;const[E,M]=Ye(m,j,{x:pe.x,y:pe.y,size:Fe}),D=((V=t==null?void 0:t.props)==null?void 0:V.shapes)??[],P=hl(E,M,D),Y=D.find(_=>_.id===P);(Y==null?void 0:Y.type)==="text"&&(Je(new Set([Y.id])),vt(Y))},[s,pe.x,pe.y,Fe,t,vt]),wi=d.useCallback(m=>{var D,P,Y,V,_,K,ie,xn;const j=Ze.current;if(!j)return;if(de){if((P=(D=m.target)==null?void 0:D.closest)!=null&&P.call(D,".be-canvas-text-editor"))return;if((V=(Y=document.activeElement)==null?void 0:Y.blur)==null||V.call(Y),s==="text"){let[ue,Ne]=Ye(m,j,un);x&&([ue,Ne]=[Ae(ue),Ae(Ne)]),fr(ue,Ne),l("text");return}}if(m.button===1){m.preventDefault(),(_=j.setPointerCapture)==null||_.call(j,m.pointerId),Ue.current={startClientX:m.clientX,startClientY:m.clientY,startViewX:pe.x,startViewY:pe.y};return}if(!m.isPrimary||m.button!==void 0&&m.button!==0)return;m.preventDefault(),(K=j.setPointerCapture)==null||K.call(j,m.pointerId);const[E,M]=Ye(m,j,un);if(s==="eraser")ln.current=new Set,bn.current=new Set,Sn.current=new Map,qn.current=!0,mt(E,M);else if(Cr.has(s)){const ue=x?Ae(E):E,Ne=x?Ae(M):M;ze.current={type:s,x1:ue,y1:Ne,x2:ue,y2:Ne},ir(Sr(ze.current,u,p,b))}else if(s==="select"){const ue=((ie=t==null?void 0:t.props)==null?void 0:ie.strokes)??[],Ne=((xn=t==null?void 0:t.props)==null?void 0:xn.shapes)??[],Ee=ne.size===1?Ne.find(Qe=>ne.has(Qe.id))??null:null,je=jp(E,M,Ee);if(je){if(je==="rotate"){const{cx:Qe,cy:Nn}=or(Ee),On=Math.atan2(M-Nn,E-Qe)*180/Math.PI;He.current={mode:"rotate",shapeId:Ee.id,cx:Qe,cy:Nn,startAngle:On,startRotation:Ee.rotation??0,rotation:Ee.rotation??0}}else if(Ee.type==="arrow")He.current={mode:"arrow-endpoint",shapeId:Ee.id,endpoint:je,x:E,y:M};else{const[Qe,Nn]=Nr(Ee)[Cp[je]];He.current={mode:"rect-corner",shapeId:Ee.id,fixedX:Qe,fixedY:Nn,x:E,y:M}}ur(jr(Ee,He.current));return}const En=Ip(E,M,ue,Ne);if(En){if(m.shiftKey){Je(Nn=>{const On=new Set(Nn);return On.has(En.id)?On.delete(En.id):On.add(En.id),On});return}const Qe=ne.has(En.id)?ne:new Set([En.id]);Je(Qe),mn.current={ids:[...Qe],startX:E,startY:M,dx:0,dy:0},j.focus()}else gn.current={startX:E,startY:M,x:E,y:M}}else s==="text"?fr(x?Ae(E):E,x?Ae(M):M):s==="pen"&&(Vn.current=[[E,M,m.pressure||.5]],Xn.current=!0)},[s,mt,pe.x,pe.y,Fe,u,p,b,x,t,ne,fr,de]),Ii=d.useCallback(m=>{var E;const j=Ze.current;if(j){if(Ue.current){const M=Gd(j,Fe),D=(m.clientX-Ue.current.startClientX)/M,P=(m.clientY-Ue.current.startClientY)/M;Gn(Y=>({...Y,x:Ue.current.startViewX-D,y:Ue.current.startViewY-P}));return}if(ze.current){let[M,D]=Ye(m,j,un);x&&([M,D]=[Ae(M),Ae(D)]),ze.current={...ze.current,x2:M,y2:D},ir(Sr(ze.current,u,p,b));return}if(mn.current){const[M,D]=Ye(m,j,un),P=mn.current;P.dx=x?Ae(M-P.startX):M-P.startX,P.dy=x?Ae(D-P.startY):D-P.startY,Ao({ids:P.ids,dx:P.dx,dy:P.dy});return}if(gn.current){const[M,D]=Ye(m,j,un),P=gn.current;P.x=M,P.y=D,Do(ot(P.startX,P.startY,P.x,P.y));return}if(He.current){let[M,D]=Ye(m,j,un);const P=He.current;if(P.mode==="rotate"){const _=Math.atan2(D-P.cy,M-P.cx)*180/Math.PI,K=P.startRotation+(_-P.startAngle);P.rotation=x?mp(K):K}else x&&([M,D]=[Ae(M),Ae(D)]),P.x=M,P.y=D;const V=(((E=t==null?void 0:t.props)==null?void 0:E.shapes)??[]).find(_=>_.id===P.shapeId);V&&ur(jr(V,P));return}if(Xn.current){const[M,D]=Ye(m,j,un);Vn.current.push([M,D,m.pressure||.5]),$o(p)}else if(qn.current){const[M,D]=Ye(m,j,un);mt(M,D)}}},[$o,mt,pe.x,pe.y,Fe,p,u,b,x,t]),Ie=d.useCallback(m=>{var E;const j=Ze.current;(E=j==null?void 0:j.hasPointerCapture)!=null&&E.call(j,m.pointerId)&&j.releasePointerCapture(m.pointerId)},[]),Ci=d.useCallback(m=>{if(Ue.current){Ie(m),Ue.current=null;return}if(ze.current){Ie(m),Fo(),xt();return}if(mn.current){Ie(m),Uo(),kt();return}if(gn.current){Ie(m),Yo(),yt();return}if(He.current){Ie(m),Ko(),wt();return}Xn.current?(Ie(m),_o(),bt()):qn.current&&(Ie(m),Ho(),gt())},[Ie,Fo,xt,Uo,kt,Yo,yt,Ko,wt,_o,bt,Ho,gt]),Si=d.useCallback(m=>{if(Ue.current){Ie(m),Ue.current=null;return}if(ze.current){Ie(m),xt();return}if(mn.current){Ie(m),kt();return}if(gn.current){Ie(m),yt();return}if(He.current){Ie(m),wt();return}Xn.current?(Ie(m),bt()):qn.current&&(Ie(m),gt())},[Ie,xt,kt,yt,wt,bt,gt]),ji=d.useCallback(m=>{var j,E;Po(m,{startX:m.clientX,startY:m.clientY,startWidth:((j=t==null?void 0:t.props)==null?void 0:j.width)??ho,startHeight:((E=t==null?void 0:t.props)==null?void 0:E.height)??bo})},[Po,t]);if(!t)return null;const{strokes:Vo=[],shapes:Xo=[],width:Ri,height:Ti}=t.props,qo=(Tn==null?void 0:Tn.width)??Ri,Bi=(Tn==null?void 0:Tn.height)??Ti,It=6,Ct=[...ne].map(m=>{var D;const j=Ss(t,m);if(!j)return null;let{kind:E,item:M}=j;return(D=ye==null?void 0:ye.ids)!=null&&D.includes(m)?M=E==="stroke"?nt(M,ye.dx,ye.dy):et(M,ye.dx,ye.dy):E==="shape"&&(cn==null?void 0:cn.id)===m&&(M=cn),{id:m,kind:E,item:M,box:wp(E,M),rotation:E==="shape"?M.rotation:0}}).filter(Boolean),br=Ct.length===1&&Ct[0].kind==="shape"?Ct[0]:null,Me=(br==null?void 0:br.item)??null,Ei=Me&&Me.type==="arrow"?[["start",Me.x1,Me.y1],["end",Me.x2,Me.y2]]:Me&&!Me.rotation?Object.entries(Nr(Me)).map(([m,[j,E]])=>[m,j,E]):[],mr=Me&&Me.type!=="arrow"?ml(Me):null;return a.jsxs("div",{className:r,"data-block-id":e,"data-tool":s,contentEditable:!1,tabIndex:-1,children:[a.jsxs("div",{className:"be-canvas-toolbar",contentEditable:!1,children:[a.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${s==="pen"?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="pen","aria-label":"Pen",title:"Pen",onClick:()=>l("pen"),children:a.jsx(Ys,{size:14})}),a.jsxs("div",{className:"be-canvas-picker-wrap",children:[a.jsx("button",{ref:ke,type:"button",className:`be-canvas-toolbar-btn${s==="eraser"?" be-canvas-toolbar-btn-active":""}`,"aria-haspopup":"true","aria-expanded":q,"aria-pressed":s==="eraser","aria-label":"Eraser",title:"Eraser",onClick:()=>le(m=>!m),children:(()=>{var j;const m=((j=Cs.find(E=>E.mode===i))==null?void 0:j.Icon)??Ws;return a.jsx(m,{size:14})})()}),q&&a.jsx("div",{ref:fe,className:"be-canvas-picker be-canvas-shape-picker",role:"menu","aria-label":"Eraser",children:Cs.map(({mode:m,label:j,Icon:E})=>a.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-btn${s==="eraser"&&i===m?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="eraser"&&i===m,"aria-label":j,title:j,onClick:()=>{l("eraser"),c(m),Bo()},children:a.jsx(E,{size:14})},m))})]}),a.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${s==="select"?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="select","aria-label":"Select",title:"Select",onClick:()=>l("select"),children:a.jsx(nc,{size:14})}),a.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${s==="text"?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="text","aria-label":"Text",title:"Text",onClick:()=>l("text"),children:a.jsx(Xr,{size:14})}),a.jsxs("div",{className:"be-canvas-picker-wrap",children:[a.jsx("button",{ref:Se,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":z,"aria-label":`Font size: ${de?de.fontSize:y}`,title:"Font size",onClick:()=>U(m=>!m),children:a.jsx("span",{className:"be-canvas-font-size-trigger",children:"A"})}),z&&a.jsxs("div",{ref:oe,className:"be-canvas-picker be-canvas-size-picker",role:"dialog","aria-label":"Font size",children:[a.jsx("span",{className:"be-canvas-size-preview","aria-hidden":"true",children:a.jsx("span",{className:"be-canvas-font-size-preview-letter",style:{fontSize:de?de.fontSize:y},children:"A"})}),a.jsx("input",{type:"range",className:"be-canvas-size-slider",min:hp,max:bp,value:de?de.fontSize:y,onChange:m=>{const j=Number(m.target.value);I(j),de&&Rn(E=>E&&{...E,fontSize:j})},"aria-label":"Font size"}),a.jsxs("span",{className:"be-canvas-size-value",children:[de?de.fontSize:y,"px"]})]})]}),a.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Bring to front",title:"Bring to front",onClick:pi,disabled:ne.size===0,children:a.jsx(qt,{size:14})}),a.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Send to back",title:"Send to back",onClick:fi,disabled:ne.size===0,children:a.jsx(Wt,{size:14})}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsxs("div",{className:"be-canvas-picker-wrap",children:[a.jsx("button",{ref:te,type:"button",className:`be-canvas-toolbar-btn${Cr.has(s)?" be-canvas-toolbar-btn-active":""}`,"aria-haspopup":"true","aria-expanded":B,"aria-label":"Shape",title:"Shape",onClick:()=>A(m=>!m),children:(()=>{var j;const m=((j=Is.find(E=>E.type===(Cr.has(s)?s:w)))==null?void 0:j.Icon)??qs;return a.jsx(m,{size:14})})()}),B&&a.jsx("div",{ref:me,className:"be-canvas-picker be-canvas-shape-picker",role:"menu","aria-label":"Shape",children:Is.map(({type:m,label:j,Icon:E})=>a.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-btn${s===m?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s===m,"aria-label":j,title:j,onClick:()=>{l(m),T(m),To()},children:a.jsx(E,{size:14})},m))})]}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsxs("div",{className:"be-canvas-picker-wrap",children:[a.jsx("button",{ref:se,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":S,"aria-label":`Color: ${u}`,title:"Color",onClick:()=>v(m=>!m),children:a.jsx("span",{className:"be-canvas-color-trigger-dot",style:{backgroundColor:u}})}),S&&a.jsxs("div",{ref:G,className:"be-canvas-picker be-canvas-color-picker",role:"menu","aria-label":"Pen color",children:[gs.map(m=>a.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-swatch${u===m?" be-canvas-toolbar-swatch-active":""}`,style:{backgroundColor:m},"aria-pressed":u===m,"aria-label":`Color ${m}`,title:`Color ${m}`,onClick:()=>{f(m),Ro()}},m)),a.jsx("label",{className:"be-canvas-custom-swatch",title:"Custom color","aria-label":"Custom color",children:a.jsx("input",{type:"color",value:u,onChange:m=>f(m.target.value)})})]})]}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsxs("div",{className:"be-canvas-picker-wrap",children:[a.jsx("button",{ref:re,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":R,"aria-label":`Fill: ${b??"none"}`,title:"Fill",onClick:()=>O(m=>!m),children:a.jsx("span",{className:`be-canvas-fill-trigger-dot${b?"":" be-canvas-fill-trigger-dot-none"}`,style:b?{backgroundColor:b}:void 0})}),R&&a.jsxs("div",{ref:H,className:"be-canvas-picker be-canvas-color-picker",role:"menu","aria-label":"Shape fill",children:[a.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-swatch be-canvas-fill-swatch-none${b===null?" be-canvas-toolbar-swatch-active":""}`,"aria-pressed":b===null,"aria-label":"No fill",title:"No fill",onClick:()=>{g(null),lr()}}),gs.map(m=>a.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-swatch${b===m?" be-canvas-toolbar-swatch-active":""}`,style:{backgroundColor:m},"aria-pressed":b===m,"aria-label":`Fill ${m}`,title:`Fill ${m}`,onClick:()=>{g(m),lr()}},m)),a.jsx("label",{className:"be-canvas-custom-swatch",title:"Custom fill","aria-label":"Custom fill",children:a.jsx("input",{type:"color",value:b??ms,onChange:m=>g(m.target.value)})})]})]}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsxs("div",{className:"be-canvas-picker-wrap",children:[a.jsx("button",{ref:Q,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":N,"aria-label":`Stroke size: ${p}`,title:"Stroke size",onClick:()=>C(m=>!m),children:a.jsx("span",{className:"be-canvas-size-trigger-dot",style:{width:Math.min(p,16),height:Math.min(p,16)}})}),N&&a.jsxs("div",{ref:ee,className:"be-canvas-picker be-canvas-size-picker",role:"dialog","aria-label":"Stroke size",children:[a.jsx("span",{className:"be-canvas-size-preview","aria-hidden":"true",children:a.jsx("span",{className:"be-canvas-size-preview-dot",style:{width:p,height:p}})}),a.jsx("input",{type:"range",className:"be-canvas-size-slider",min:sp,max:ap,value:p,onChange:m=>h(Number(m.target.value)),"aria-label":"Stroke size"}),a.jsxs("span",{className:"be-canvas-size-value",children:[p,"px"]})]})]}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${x?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":x,"aria-label":"Snap to grid",title:x?"Snap to grid: ON — drawing, moving, resizing and rotating align to the dotted grid. Click to turn off.":"Snap to grid: OFF — click to turn on (aligns drawing, moving, resizing and rotating to a grid)",onClick:()=>k(m=>!m),children:a.jsx(rc,{size:14})}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Zoom out",title:"Zoom out",onClick:xi,disabled:pe.zoom<=wr,children:"−"}),a.jsxs("button",{type:"button",className:"be-canvas-zoom-label","aria-label":`Zoom: ${Math.round(pe.zoom*100)}%. Click to reset to 100%.`,title:"Reset zoom to 100%",onClick:ki,children:[Math.round(pe.zoom*100),"%"]}),a.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Zoom in",title:"Zoom in",onClick:gi,disabled:pe.zoom>=Ir,children:"+"}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Export PNG",title:"Export as PNG",onClick:yi,disabled:Vo.length===0&&Xo.length===0,children:a.jsx(tc,{size:14})})]}),a.jsxs("svg",{ref:Ze,className:"be-canvas-surface",viewBox:`${pe.x} ${pe.y} ${Fe} ${Fe}`,width:qo,height:Bi,tabIndex:-1,onPointerDown:wi,onPointerMove:Ii,onPointerUp:Ci,onPointerCancel:Si,onDoubleClick:vi,onKeyDown:mi,children:[x&&a.jsxs(a.Fragment,{children:[a.jsx("defs",{children:a.jsx("pattern",{id:`be-canvas-grid-${e}`,width:ws,height:ws,patternUnits:"userSpaceOnUse",children:a.jsx("circle",{cx:1,cy:1,r:1.5,className:"be-canvas-grid-dot"})})}),a.jsx("rect",{className:"be-canvas-grid-background",x:pe.x,y:pe.y,width:Fe,height:Fe,fill:`url(#be-canvas-grid-${e})`})]}),Vo.map(m=>{var M;const E=((M=ye==null?void 0:ye.ids)==null?void 0:M.includes(m.id))?_t(nt(m,ye.dx,ye.dy).points,{size:m.size}):o(m);return a.jsx("path",{d:E,fill:m.color,fillRule:"nonzero",opacity:ui.has(m.id)?.25:1},m.id)}),Eo&&a.jsx("path",{d:Eo,fill:u,fillRule:"nonzero"}),Xo.map(m=>{var E;let j=m;return(E=ye==null?void 0:ye.ids)!=null&&E.includes(m.id)?j=et(m,ye.dx,ye.dy):(cn==null?void 0:cn.id)===m.id&&(j=cn),a.jsx(js,{shape:j,opacity:di.has(m.id)?.25:1},m.id)}),Mo&&a.jsx(js,{shape:Mo,opacity:.6}),Ct.map(({id:m,box:j,rotation:E})=>a.jsx("g",{transform:E?`rotate(${E} ${j.x+j.width/2} ${j.y+j.height/2})`:void 0,children:a.jsx("rect",{className:"be-canvas-selection-box",x:j.x-It,y:j.y-It,width:j.width+It*2,height:j.height+It*2,fill:"none"})},m)),Ei.map(([m,j,E])=>a.jsx("rect",{className:"be-canvas-selection-handle",x:j-tt/2,y:E-tt/2,width:tt,height:tt},m)),mr&&a.jsx("circle",{className:"be-canvas-rotate-handle",cx:mr[0],cy:mr[1],r:tt/2}),Wn&&a.jsx("rect",{className:"be-canvas-marquee",x:Wn.x,y:Wn.y,width:Wn.width,height:Wn.height}),de&&a.jsx("foreignObject",{x:de.x,y:de.y,width:de.width,height:de.height,children:a.jsx("textarea",{xmlns:"http://www.w3.org/1999/xhtml",ref:m=>m==null?void 0:m.focus(),className:"be-canvas-text-editor",value:de.text,style:{color:de.color,fontSize:de.fontSize},onChange:m=>Rn(j=>j&&{...j,text:m.target.value}),onBlur:()=>bi(),onKeyDown:m=>{m.key==="Escape"&&(m.preventDefault(),hi()),m.stopPropagation()}})})]}),a.jsx("div",{className:"be-canvas-resize-handle",onMouseDown:ji,role:"slider","aria-label":"Resize canvas","aria-valuemin":xs,"aria-valuenow":qo,contentEditable:!1})]})}function Tp(e){const{strokes:n=[],shapes:t=[]}=e.props;return!n.length&&!t.length?"<p></p>":dl(e)}function Bp(){return""}function Ep(){return null}function Np(e,{blockId:n,runId:t,sliceStart:r,sliceEnd:o}){const s=e.getRun(t),l=(s==null?void 0:s.value)??"";e.applyOperation(ce(t,{value:l.slice(0,r)+l.slice(o)}));const i=Zt(e,n,tp());return Ge(e,i,J("paragraph")),i}const Op={component:Rp,isLeaf:!0,defaultProps:{strokes:[],shapes:[],width:ho,height:bo},toHTML:Tp,toPlainText:Bp,fromHTML:Ep,slashCommand:{label:"Canvas",icon:Vi,keywords:["canvas","draw","drawing","sketch","freehand"],run:Np}};function Lp(e){gl(e,{paragraph:ca,heading:ua,listItem:ka,...xl,...kl,divider:za,callout:Fa,blockquote:Ua,code:Ka,toggleHeading:Va,button:qa,embed:Ja,canvas:Op})}function gl(e,n){for(const[t,r]of Object.entries(n))e.register(t,r)}const xl={table:Aa,tableRow:Ma,tableCell:La},kl={layout:_a,layoutColumn:$a};function Mp({id:e}){const n=W(),t=pn(e),r=d.useCallback(i=>{n.applyOperation(ce(e,{data:{...t==null?void 0:t.data,selectedValue:i}}))},[n,e,t==null?void 0:t.data]);if(!t)return null;const{options:o=[],selectedValue:s="",placeholder:l="Select…"}=t.data??{};return a.jsx("span",{className:"be-inline-select",onMouseDown:i=>{i.preventDefault(),i.stopPropagation()},onKeyDown:i=>i.stopPropagation(),children:a.jsx(In,{value:s,options:o,onChange:r,placeholder:l,ariaLabel:"Select an option"})})}function sr(e,{blockId:n,runId:t,sliceStart:r,sliceEnd:o},s){const l=e.getRun(t),i=(l==null?void 0:l.value)??"",c=i.slice(0,r),u=i.slice(o),f=s(),p={...l,value:c},h={id:L(),type:"text",value:u,marks:{...l==null?void 0:l.marks}};e.applyOperation(ct(n,[t],[p,f,h])),xe(h.id)}function Ap(e){return String(e).replace(/&/g,"&").replace(/"/g,""")}function yl(e){var r;const{options:n=[],selectedValue:t=""}=e.data??{};return((r=n.find(o=>o.value===t))==null?void 0:r.label)??""}function Dp(e){var t,r;const n=yl(e)||((t=e.data)==null?void 0:t.placeholder)||"";return`<span data-inline-type="select" data-selected-value="${Ap(((r=e.data)==null?void 0:r.selectedValue)??"")}">${n}</span>`}function Pp(e){return yl(e)}function $p(e){var n;return((n=e.getAttribute)==null?void 0:n.call(e,"data-inline-type"))!=="select"?null:{id:L(),type:"select",value:"",marks:{},data:{options:[],selectedValue:e.getAttribute("data-selected-value")??""}}}const vl={component:Mp,isAtomic:!0,toHTML:Dp,toPlainText:Pp,fromHTML:$p,slashCommand:{label:"Select",icon:ra,keywords:["select","dropdown","choice","picker"],run:(e,{blockId:n,runId:t,sliceStart:r,sliceEnd:o})=>sr(e,{blockId:n,runId:t,sliceStart:r,sliceEnd:o},()=>({id:L(),type:"select",value:"",marks:{},data:{options:[],selectedValue:"",placeholder:"Select…"}}))}};function _p({id:e}){const n=W(),t=pn(e),r=d.useCallback(s=>{n.applyOperation(ce(e,{data:{...t==null?void 0:t.data,isoDate:s.target.value}}))},[n,e,t==null?void 0:t.data]);if(!t)return null;const{isoDate:o=""}=t.data??{};return a.jsx("span",{className:"be-inline-date",onMouseDown:s=>s.stopPropagation(),onKeyDown:s=>s.stopPropagation(),children:a.jsx("input",{type:"date",value:o,onChange:r})})}function zp(e){return String(e).replace(/&/g,"&").replace(/"/g,""")}function wl(e){if(!e)return"";const n=new Date(`${e}T00:00:00`);return Number.isNaN(n.getTime())?e:n.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Hp(e){var t;const n=((t=e.data)==null?void 0:t.isoDate)??"";return`<span data-inline-type="date" data-iso-date="${zp(n)}">${wl(n)}</span>`}function Fp(e){var n;return wl(((n=e.data)==null?void 0:n.isoDate)??"")}function Up(e){var n;return((n=e.getAttribute)==null?void 0:n.call(e,"data-inline-type"))!=="date"?null:{id:L(),type:"date",value:"",marks:{},data:{isoDate:e.getAttribute("data-iso-date")??""}}}function Yp(){return new Date().toISOString().slice(0,10)}const Il={component:_p,isAtomic:!0,toHTML:Hp,toPlainText:Fp,fromHTML:Up,slashCommand:{label:"Date",icon:cc,keywords:["date","when","schedule","calendar"],run:(e,{blockId:n,runId:t,sliceStart:r,sliceEnd:o})=>sr(e,{blockId:n,runId:t,sliceStart:r,sliceEnd:o},()=>({id:L(),type:"date",value:"",marks:{},data:{isoDate:Yp()}}))}};function Kp({id:e}){const n=W(),t=pn(e),r=d.useCallback(i=>{n.applyOperation(ce(e,{data:{...t==null?void 0:t.data,checked:i.target.checked}}))},[n,e,t==null?void 0:t.data]),o=d.useCallback(i=>{n.applyOperation(ce(e,{data:{...t==null?void 0:t.data,label:i.target.value}}))},[n,e,t==null?void 0:t.data]);if(!t)return null;const{checked:s=!1,label:l=""}=t.data??{};return a.jsxs("span",{className:"be-inline-checkbox",onMouseDown:i=>i.stopPropagation(),onKeyDown:i=>i.stopPropagation(),children:[a.jsx("input",{type:"checkbox",className:"be-inline-checkbox-input",checked:s,onChange:r}),a.jsx("input",{type:"text",className:"be-inline-checkbox-label",value:l,onChange:o,placeholder:"Label…"})]})}function Vp(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Xp(e){const{checked:n=!1,label:t=""}=e.data??{};return`<span data-inline-type="checkbox" data-checked="${n}">${n?"☑":"☐"} ${Vp(t)}</span>`}function qp(e){const{checked:n=!1,label:t=""}=e.data??{};return`${n?"[x]":"[ ]"} ${t}`.trim()}function Wp(e){var n;return((n=e.getAttribute)==null?void 0:n.call(e,"data-inline-type"))!=="checkbox"?null:{id:L(),type:"checkbox",value:"",marks:{},data:{checked:e.getAttribute("data-checked")==="true",label:(e.textContent??"").replace(/^[☑☐]\s*/,"")}}}const Cl={component:Kp,isAtomic:!0,toHTML:Xp,toPlainText:qp,fromHTML:Wp,slashCommand:{label:"Checkbox",icon:Gr,keywords:["checkbox","todo","check","toggle"],run:(e,{blockId:n,runId:t,sliceStart:r,sliceEnd:o})=>sr(e,{blockId:n,runId:t,sliceStart:r,sliceEnd:o},()=>({id:L(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}}))}};function Gp({id:e,blockId:n}){var b;const t=W(),r=pn(e),o=n?t.getBlock(n):null,s=o?t.getBlock(o.parentId):null,l=(s==null?void 0:s.parentId)??null,i=be(l),c=s?s.contentIds.indexOf(n):-1,f=(((b=(i&&s?De(i,s.contentIds.length):[])[c])==null?void 0:b.options)??[]).map((g,x)=>({...g,color:g.color??lt(x)})),p=d.useCallback((g,x)=>{t.applyOperation(ce(e,{data:{selectedValue:g,selectedLabel:(x==null?void 0:x.label)??""}}))},[t,e]);if(!r)return null;const{selectedValue:h=""}=r.data??{};return a.jsx("span",{className:"be-inline-table-select",onMouseDown:g=>{g.preventDefault(),g.stopPropagation()},onKeyDown:g=>g.stopPropagation(),children:a.jsx(In,{value:h,options:f,onChange:p,placeholder:"Select…",ariaLabel:"Select an option",variant:"tag"})})}function Sl(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Zp(e){return Sl(e).replace(/"/g,""")}function Jp(e){const{selectedValue:n="",selectedLabel:t=""}=e.data??{};return`<span data-inline-type="tableSelect" data-selected-value="${Zp(n)}">${Sl(t)}</span>`}function Qp(e){var n;return((n=e.data)==null?void 0:n.selectedLabel)??""}function ef(e){var n;return((n=e.getAttribute)==null?void 0:n.call(e,"data-inline-type"))!=="tableSelect"?null:{id:L(),type:"tableSelect",value:"",marks:{},data:{selectedValue:e.getAttribute("data-selected-value")??"",selectedLabel:e.textContent??""}}}const jl={component:Gp,isAtomic:!0,toHTML:Jp,toPlainText:Qp,fromHTML:ef},Rl={};function nf(e){Tl(e,{select:vl,date:Il,checkbox:Cl,...Bl,emoji:Rl})}function Tl(e,n){for(const[t,r]of Object.entries(n))e.register(t,r)}const Bl={tableSelect:jl},tf="$fieldTypes";function El(){const e=W(),n=d.useCallback(r=>e.subscribe(tf,r),[e]),t=d.useCallback(()=>e.getFieldTypes(),[e]);return d.useSyncExternalStore(n,t)}function Pn(e){var o,s;const n=(o=e.getPendingSelection)==null?void 0:o.call(e);if(n){Ke(n.runId,n.offset);return}const r=(((s=e.getPendingAffectedBlockIds)==null?void 0:s.call(e))??[]).find(l=>e.getBlock(l));r&&Ce(e,r)}const rf={canUndo:!1,canRedo:!1};function Nl(){const{history:e}=qe(),n=d.useCallback(o=>e?e.subscribeToHistory(o):()=>{},[e]),t=d.useCallback(()=>e?e.getUndoRedoSnapshot():rf,[e]),r=d.useSyncExternalStore(n,t);return e?{...r,undo:()=>{const o=e.undo();return o&&Pn(e),o},redo:()=>{const o=e.redo();return o&&Pn(e),o},getHistoryLog:()=>e.getHistoryLog()}:null}const Ol=[{phrases:["new paragraph","next paragraph"],description:"Start a new paragraph",action:{type:"insertParagraph"}},{phrases:["heading one","heading 1"],description:"Convert the current block to a heading 1",action:{type:"convertBlock",blockType:"heading",props:{level:1}}},{phrases:["heading two","heading 2"],description:"Convert the current block to a heading 2",action:{type:"convertBlock",blockType:"heading",props:{level:2}}},{phrases:["heading three","heading 3"],description:"Convert the current block to a heading 3",action:{type:"convertBlock",blockType:"heading",props:{level:3}}},{phrases:["bulleted list","bullet point","bullet list"],description:"Convert the current block to a bulleted list item",action:{type:"convertBlock",blockType:"listItem",props:{ordered:!1,titleRunIds:[]}}},{phrases:["numbered list","ordered list"],description:"Convert the current block to a numbered list item",action:{type:"convertBlock",blockType:"listItem",props:{ordered:!0,titleRunIds:[]}}},{phrases:["checklist","to-do","to do","to-do list","to do list"],description:"Convert the current block to a to-do item",action:{type:"convertBlock",blockType:"listItem",props:{ordered:!1,checked:!1,titleRunIds:[]}}},{phrases:["quote"],description:"Convert the current block to a quote",action:{type:"convertBlock",blockType:"blockquote",props:{}}},{phrases:["code block","code"],description:"Convert the current block to a code block",action:{type:"convertBlock",blockType:"code",props:{language:"plaintext"}}},{phrases:["undo"],description:"Undo the last edit",action:{type:"undo"}},{phrases:["redo"],description:"Redo the last undone edit",action:{type:"redo"}},{phrases:["stop dictation","stop listening","stop"],description:"Stop dictation",action:{type:"stopDictation"}}],Ll=new Map;for(const{phrases:e,action:n}of Ol)for(const t of e)Ll.set(t,n);function of(e){return(e??"").toLowerCase().trim().replace(/\s+/g," ").replace(/[.,!?]+$/,"")}function sf(e){return Ll.get(of(e))??null}function af(){return Ol.map(({phrases:e,description:n})=>({phrases:[...e],description:n}))}function lf(e,n){if(typeof e.performBatch=="function")e.performBatch(n);else for(const t of n)e.applyOperation(t)}function cf(e){var n;return((n=e==null?void 0:e.props)==null?void 0:n.titleRunIds)??(e==null?void 0:e.contentIds)??[]}function uf(e,n,t){var r,o;if(t.type==="insertParagraph"){Ge(e,n,J("paragraph"));return}if(t.type==="convertBlock"){const s=e.getBlock(n);if(!s)return;const l=cf(s),{ops:i}=eo(e,n,t.blockType,t.props,l);lf(e,i),l[0]&&Ut(l[0]);return}if(t.type==="undo"){(r=e.undo)!=null&&r.call(e)&&Pn(e);return}t.type==="redo"&&(o=e.redo)!=null&&o.call(e)&&Pn(e)}function Rs(){return typeof window>"u"?null:window.SpeechRecognition??window.webkitSpeechRecognition??null}const df="Microphone access is blocked. Enable it in your browser's site settings, then try again.";function pf({shortcut:e=!0}={}){const n=W(),[t,r]=d.useState(!1),[o,s]=d.useState("idle"),[l,i]=d.useState("unknown"),[c,u]=d.useState(null),f=d.useRef(null),p=d.useRef(null),h=d.useRef(null),b=d.useRef(0),g=Rs()!==null;d.useEffect(()=>{var R;if(!((R=navigator.permissions)!=null&&R.query))return;let S,v=!1;return navigator.permissions.query({name:"microphone"}).then(O=>{v||(S=O,i(O.state),S.onchange=()=>i(S.state))}).catch(()=>{}),()=>{v=!0,S&&(S.onchange=null)}},[]);const x=d.useCallback(()=>{if(!p.current){const S=nn();if(!S)return null;p.current=S}return{runId:p.current.runId,blockId:p.current.blockId,startOffset:p.current.offset,insertedLength:0}},[]),k=d.useCallback((S,v)=>{const R=n.getRun(S.runId);if(!R||R.type!=="text")return;const O=R.value??"",N=O.slice(0,S.startOffset);if(S.needsLeadingSpace===void 0){const A=N[N.length-1];S.needsLeadingSpace=S.startOffset>0&&A!==void 0&&!/\s/.test(A)}const C=(S.needsLeadingSpace?" ":"")+v,B=O.slice(S.startOffset+S.insertedLength);Ve.flushSync(()=>n.applyOperation(ce(S.runId,{value:N+C+B}))),S.insertedLength=C.length,es(S.runId,S.startOffset+C.length),p.current={runId:S.runId,blockId:S.blockId,offset:S.startOffset+C.length}},[n]),y=d.useCallback(S=>{const v=n.getRun(S.runId);if(!v||v.type!=="text")return;const R=v.value??"",O=R.slice(0,S.startOffset)+R.slice(S.startOffset+S.insertedLength);Ve.flushSync(()=>n.applyOperation(ce(S.runId,{value:O}))),es(S.runId,S.startOffset),p.current={runId:S.runId,blockId:S.blockId,offset:S.startOffset}},[n]),I=d.useCallback(S=>{var N,C;let v="",R=!1;const O=Math.max(S.resultIndex,b.current);for(let B=O;B<S.results.length;B+=1){const A=S.results[B],z=((N=A[0])==null?void 0:N.transcript)??"";if(!A.isFinal){v+=(v?" ":"")+z,R=!0;continue}const U=h.current??x();if(h.current=null,b.current=B+1,!U)continue;const q=sf(z);q?(y(U),q.type==="stopDictation"?(C=f.current)==null||C.stop():(uf(n,U.blockId,q),p.current=null,s("listening"))):(k(U,z),s("listening"))}if(R){const B=h.current??x();B&&(h.current=B,k(B,v))}},[n,x,k,y]),w=d.useCallback(()=>{if(!g||f.current)return;u(null),p.current=nn(),h.current=null,b.current=0;const S=Rs(),v=new S;v.continuous=!0,v.interimResults=!0,v.onresult=I,v.onstart=()=>s("listening"),v.onspeechstart=()=>s("listening"),v.onspeechend=()=>s("processing"),v.onerror=R=>{R.error==="not-allowed"||R.error==="service-not-allowed"?(i("denied"),u(df)):u(R.error??"Voice typing stopped unexpectedly.")},v.onend=()=>{f.current=null,p.current=null,h.current=null,b.current=0,r(!1),s("idle")},f.current=v,v.start(),r(!0)},[g,I]),T=d.useCallback(()=>{var S;(S=f.current)==null||S.stop()},[]);return d.useEffect(()=>()=>{var S;return(S=f.current)==null?void 0:S.stop()},[]),d.useEffect(()=>{if(!e||!g)return;const S=v=>{!(v.metaKey||v.ctrlKey)||!v.shiftKey||v.key.toLowerCase()!=="m"||(v.preventDefault(),f.current?T():w())};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[e,g,w,T]),{isSupported:g,isListening:t,status:o,permissionState:l,error:c,start:w,stop:T}}function ff({voice:e}){const[n,t]=d.useState(!1);d.useEffect(()=>{t(!1)},[e==null?void 0:e.error]);const r=(e==null?void 0:e.permissionState)==="denied"&&!n;return a.jsxs(on,{isOpen:r,onClose:()=>t(!0),title:"Microphone access blocked",children:[a.jsx("p",{children:(e==null?void 0:e.error)||"Microphone access is blocked. Enable it in your browser's site settings, then try again."}),a.jsxs("div",{className:"be-modal-actions",children:[a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:()=>t(!0),children:"Dismiss"}),a.jsx("button",{type:"button",className:"be-modal-save",onClick:()=>{var o;return(o=e==null?void 0:e.start)==null?void 0:o.call(e)},children:"Try again"})]})]})}function Ml(e){const[n,t]=d.useState(null);return d.useEffect(()=>{if(!e){t(null);return}const r=()=>{var c,u,f,p;const o=(c=window.getSelection)==null?void 0:c.call(window);if(!o||o.rangeCount===0||!o.isCollapsed){t(null);return}const s=o.anchorNode,l=(s==null?void 0:s.nodeType)===1?s:s==null?void 0:s.parentElement;if(!((u=l==null?void 0:l.closest)!=null&&u.call(l,"[data-run-id]"))){t(null);return}const i=((p=(f=o.getRangeAt(0)).getBoundingClientRect)==null?void 0:p.call(f))??{top:0,left:0,right:0,bottom:0,width:0,height:0};t(i)};return r(),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]),n}function hf({voice:e}){const n=!!(e!=null&&e.isListening),t=Ml(n),r=d.useRef(null),o=Ea(r,!!(n&&t),t==null?void 0:t.left);if(!n||!t||o==null)return null;const s=e.status==="processing";return Ve.createPortal(a.jsxs("div",{ref:r,className:`be-voice-indicator${s?" be-voice-indicator-processing":""}`,contentEditable:!1,style:{position:"fixed",top:t.top-8,left:o,transform:"translate(-50%, -100%)"},children:[a.jsx("span",{className:"be-voice-indicator-dot"}),a.jsx(fc,{size:12}),a.jsx("span",{className:"be-voice-indicator-label",children:s?"Processing…":"Listening…"})]}),document.body)}const zt="application/x-block-editor-blocks+json";function mo(e){return e.split(/\r\n|\r|\n/).filter(n=>n.length>0).map(n=>{const t=L();return{block:{id:L(),type:"paragraph",parentId:null,contentIds:[t],props:{}},runs:[{id:t,type:"text",value:n,marks:{}}]}})}function Al(e,n,t){const r=new DOMParser().parseFromString(e,"text/html"),o={registry:n,inlineRegistry:t},s=n.listHtmlMatchers(),l=[],i=u=>{var h;const f=u.tagName==="OL",p=[];for(const b of u.children){if(b.tagName!=="LI")continue;const g=(h=n.get("listItem"))==null?void 0:h.fromHTML(b,o);g&&(g.block.props.ordered=f,p.push(g))}return p},c=u=>{var p;const f=Array.from(u.children).filter(h=>h.tagName==="P");if(f.length===0){const h=(p=n.get("blockquote"))==null?void 0:p.fromHTML(u,o);return h?[h]:[]}return f.map(h=>{const b=$e(h,o);return{block:{id:L(),type:"blockquote",parentId:null,contentIds:b.map(g=>g.id),props:{}},runs:b}})};for(const u of r.body.childNodes){if(u.nodeType===3){const p=u.textContent.trim();p&&l.push(...mo(p));continue}if(u.nodeType!==1)continue;if(u.tagName==="UL"||u.tagName==="OL"){l.push(...i(u));continue}if(u.tagName==="BLOCKQUOTE"){l.push(...c(u));continue}let f=null;for(const p of s){const h=p.fromHTML(u,o);if(h){f=h;break}}if(f)l.push(f);else if(u.textContent.trim()){const p=$e(u,o);l.push({block:{id:L(),type:"paragraph",parentId:null,contentIds:p.map(h=>h.id),props:{}},runs:p})}}return l}function Dl(e,n,t){const r=e.types??[];if(r.includes(zt)){const s=e.getData(zt);if(s)return bf(s)}if(r.includes("text/html")){const s=e.getData("text/html");if(s)return Al(s,n,t)}const o=e.getData("text/plain")??"";return mo(o)}function bf(e){return JSON.parse(e).blocks.map(t=>so(t))}function Or(e,n){var r;const t=e.getBlock(n);return((r=t.props)==null?void 0:r.titleRunIds)??t.contentIds}function Dt(){return{id:L(),type:"text",value:"",marks:{}}}function Lr(e,n){if(typeof e.performBatch=="function")e.performBatch(n);else for(const t of n)e.applyOperation(t)}function go(e,n,t){const{startRunId:r,startOffset:o,endRunId:s,endOffset:l}=t,i=Or(e,n),c=i.indexOf(r),u=i.indexOf(s);if(c===-1||u===-1)return null;const[f,p]=c<=u?[c,u]:[u,c],h=c<=u?o:l,b=c<=u?l:o,g=i.slice(0,f).map(S=>e.getRun(S)),x=i.slice(p+1).map(S=>e.getRun(S)),k=i.slice(f,p+1).map(S=>e.getRun(S)),y=[];let I=null,w=0;if(f===p){const S=k[0];if(S.type==="text"){const v=Math.max(0,Math.min(h,b)),R=Math.min(S.value.length,Math.max(h,b)),O={...S,value:S.value.slice(0,v)+S.value.slice(R)};y.push(O),I=O.id,w=v}}else k.forEach((S,v)=>{if(S.type!=="text")return;const R=v===0,O=v===k.length-1,N=R?S.value.slice(0,h):"";if(R&&N){const C={...S,value:N};y.push(C),I=C.id,w=N.length}if(O&&!R){const C=S.value.slice(b);if(C){const B={id:L(),type:"text",value:C,marks:S.marks};y.push(B),I===null&&(I=B.id,w=0)}}});let T=[...g,...y,...x];if(T.length===0){const S=Dt();T=[S],I=S.id,w=0}else if(I===null){const S=g[g.length-1];S?(I=S.id,w=S.type==="text"?S.value.length:0):x[0]&&(I=x[0].id,w=0)}return e.applyOperation(Oe(n,T)),{blockId:n,runId:I,offset:w}}function xo(e,n){const{blockIds:t,startBlockId:r,startRunId:o,startOffset:s,endBlockId:l,endRunId:i,endOffset:c}=n;if(!t||t.length===0)return null;const u=t.indexOf(r),f=t.indexOf(l);if(u===-1||f===-1)return null;const[p,h]=u<=f?[u,f]:[f,u],b=u<=f,g=b?o:i,x=b?s:c,k=b?i:o,y=b?c:s;if(p===h)return go(e,t[p],{startRunId:g,startOffset:x,endRunId:k,endOffset:y});const I=t[p],w=t[h],T=e.getBlock(I),S=e.getBlock(w),v=Or(e,I),R=v.indexOf(g),O=v.slice(0,R).map(oe=>e.getRun(oe)),N=e.getRun(g),C=N.type==="text"&&x>0?{...N,value:N.value.slice(0,x)}:null,B=Or(e,w),A=B.indexOf(k),z=B.slice(A+1).map(oe=>e.getRun(oe)),U=e.getRun(k),q=U.type==="text"&&y<U.value.length?{id:L(),type:"text",value:U.value.slice(y),marks:U.marks}:null,le=[...O,...C?[C]:[]],se=[...q?[q]:[],...z],G=[];for(let oe=p+1;oe<h;oe+=1)G.push(Z(t[oe]));const re=ia(T.type,S.type),H=e.getBlock(T.parentId),Q=h-p-1+(re?1:0),ee=H&&H.contentIds.length-Q===1;let te,me,Se;if(re){const oe=[...le,...se];if(oe.length===0&&ee&&T.type!=="paragraph"){const{block:fe,runs:$}=J("paragraph")(H.id);return G.push({type:"insertBlock",block:fe,parentId:H.id,index:0,subtree:{blocks:[fe],runs:$}}),G.push(Z(I)),G.push(Z(w)),Lr(e,G),{blockId:fe.id,runId:fe.contentIds[0],offset:0}}const ke=oe.length?oe:[Dt()];if(G.push(Oe(I,ke)),G.push(Z(w)),Se=I,C)te=C.id,me=C.value.length;else if(O.length){const fe=O[O.length-1];te=fe.id,me=fe.type==="text"?fe.value.length:0}else q?(te=q.id,me=0):z.length?(te=z[0].id,me=0):(te=ke[0].id,me=0)}else{const oe=le.length?le:[Dt()];if(G.push(Oe(I,oe)),G.push(Oe(w,se.length?se:[Dt()])),Se=I,C)te=C.id,me=C.value.length;else if(O.length){const ke=O[O.length-1];te=ke.id,me=ke.type==="text"?ke.value.length:0}else te=oe[0].id,me=0}return Lr(e,G),{blockId:Se,runId:te,offset:me}}function Ht(e,n=""){var i;const t=e.getRootId(),r=((i=e.getBlock(t))==null?void 0:i.contentIds)??[];if(r.length===0)return null;const o=r.map(c=>Z(c)),{block:s,runs:l}=J("paragraph")(t);return n&&(l[0].value=n),o.push(he(s,t,0,{blocks:[s],runs:l})),Lr(e,o),{blockId:s.id,runId:s.contentIds[0],offset:n.length}}function ko(e,n){if(typeof e.performBatch=="function")e.performBatch(n);else for(const t of n)e.applyOperation(t)}function st(e,n){n.length!==0&&ko(e,n.map(t=>Z(t)))}function Pl(e,n){if(n.length===0)return!1;const t=e.getBlock(n[0]);if(!t)return!1;const r=e.getBlock(t.parentId);if(!r)return!1;const o=r.contentIds.indexOf(n[0]),s=r.contentIds.indexOf(n[n.length-1]);if(o<=0)return!1;const l=r.contentIds[o-1];return e.applyOperation(Xe(l,t.parentId,s)),!0}function $l(e,n){if(n.length===0)return!1;const t=e.getBlock(n[0]);if(!t)return!1;const r=e.getBlock(t.parentId);if(!r)return!1;const o=r.contentIds.indexOf(n[0]),s=r.contentIds.indexOf(n[n.length-1]);if(s===-1||s>=r.contentIds.length-1)return!1;const l=r.contentIds[s+1];return e.applyOperation(Xe(l,t.parentId,o)),!0}function _l(e,n){return n.length>0&&n.every(t=>{var r,o;return!!((o=(r=e.getBlock(t))==null?void 0:r.props)!=null&&o.hidden)})}function zl(e,n,t){n.length!==0&&ko(e,n.map(r=>X(r,{hidden:t})))}function mf(e,n,t,r){const o=t.filter(l=>{var i;return ro((i=e.getBlock(l))==null?void 0:i.type)});if(o.length===0)return;const s=o.flatMap(l=>ha(e,n,l,r).ops);ko(e,s)}function gf(e,n){if(n.length===0)return[];const t=e.getBlock(n[0]),r=t&&e.getBlock(t.parentId);if(!r)return n;const o=new Set(n);return r.contentIds.filter(s=>o.has(s))}function Mr(e){var t;let n=(e==null?void 0:e.nodeType)===1?e:e==null?void 0:e.parentElement;for(;n&&typeof n.hasAttribute=="function"&&!n.hasAttribute("data-block-id");)n=n.parentElement;return((t=n==null?void 0:n.getAttribute)==null?void 0:t.call(n,"data-block-id"))??null}function xf(e){var p;const n=(p=window.getSelection)==null?void 0:p.call(window);if(!n||n.rangeCount===0)return[];const t=Mr(n.anchorNode),r=Mr(n.focusNode);if(!t)return[];if(!r||t===r)return[t];const o=e.getBlock(t),s=o&&e.getBlock(o.parentId);if(!s)return[t];const l=s.contentIds,i=l.indexOf(t),c=l.indexOf(r);if(i===-1||c===-1)return[t];const[u,f]=i<=c?[i,c]:[c,i];return l.slice(u,f+1)}function Ts(e){const n=Hn();if(n)return go(e,n.blockId,n);const t=Dn(e);return t?xo(e,t):null}function kf(e,n,t){const r=e.getRun(n.runId);if(!r||r.type!=="text")return null;const o=r.value??"",s=o.slice(0,n.offset)+t+o.slice(n.offset);return e.applyOperation(ce(r.id,{value:s})),{blockId:n.blockId,runId:r.id,offset:n.offset+t.length}}function Rr(e,n){if(typeof e.performBatch=="function")e.performBatch(n);else for(const t of n)e.applyOperation(t)}function yf(){const e=W(),n=dn(),t=We(),[r,o]=Fr(),[s,l]=ut(),i=d.useCallback(f=>{var x;const p=r?((x=e.getBlock(e.getRootId()))==null?void 0:x.contentIds)??[]:s.length>0?s:xf(e);if(p.length===0)return;const{html:h,text:b,json:g}=ft(e,n,p,t);f.clipboardData.setData("text/plain",b),f.clipboardData.setData("text/html",h),f.clipboardData.setData(zt,g),f.preventDefault()},[e,n,t,r,s]),c=d.useCallback(f=>{if(i(f),r){const h=Ht(e);o(!1),h!=null&&h.runId&&Ke(h.runId,h.offset);return}if(s.length>0){st(e,s),l([]);return}const p=Ts(e);p!=null&&p.runId&&Ke(p.runId,p.offset)},[i,e,r,o,s,l]),u=d.useCallback(f=>{var w,T,S;const p=Dl(f.clipboardData,n,t);if(p.length===0)return;if(r){const v=e.getRootId(),O=(((w=e.getBlock(v))==null?void 0:w.contentIds)??[]).map(C=>Z(C));let N=0;for(const{block:C,runs:B,subtreeBlocks:A=[]}of p)C.parentId=v,O.push(he(C,v,N,{blocks:[C,...A],runs:B})),N+=1;Rr(e,O),o(!1),f.preventDefault();return}if(s.length>0){const v=e.getBlock(s[0]),R=(v==null?void 0:v.parentId)??null,O=R&&e.getBlock(R);let N=O?O.contentIds.indexOf(s[0]):0;const C=s.map(B=>Z(B));for(const{block:B,runs:A,subtreeBlocks:z=[]}of p)B.parentId=R,C.push(he(B,R,N,{blocks:[B,...z],runs:A})),N+=1;Rr(e,C),l([]),f.preventDefault();return}const h=Ts(e);if(p.length===1&&p[0].runs.every(v=>v.type==="text")&&(p[0].subtreeBlocks??[]).length===0){const v=h?{blockId:h.blockId,runId:h.runId,offset:h.offset}:nn();if(v){const R=p[0].runs.map(N=>N.value).join(""),O=kf(e,v,R);if(O){Ke(O.runId,O.offset),f.preventDefault();return}}}const g=(h==null?void 0:h.blockId)??Mr((S=(T=window.getSelection)==null?void 0:T.call(window))==null?void 0:S.anchorNode);if(!g)return;const x=e.getBlock(g);if(!x)return;let y=e.getBlock(x.parentId).contentIds.indexOf(g)+1;const I=[];for(const{block:v,runs:R,subtreeBlocks:O=[]}of p)v.parentId=x.parentId,I.push(he(v,x.parentId,y,{blocks:[v,...O],runs:R})),y+=1;Rr(e,I),f.preventDefault()},[e,n,t,r,o,s,l]);return{onCopy:i,onCut:c,onPaste:u}}const vf=["bold","italic","underline","strike","subscript","superscript","code"],wf=["color","highlight","link"];function $n(e,n){var r;const t=e.getBlock(n);return((r=t.props)==null?void 0:r.titleRunIds)??t.contentIds}function If(e,n){return e===n?!0:e&&n&&typeof e=="object"?JSON.stringify(e)===JSON.stringify(n):!1}function Hl(e){var t;const n={};if(e.length===0)return n;for(const r of vf)n[r]=e.every(o=>{var s;return(s=o.marks)==null?void 0:s[r]});for(const r of wf){const o=((t=e[0].marks)==null?void 0:t[r])??null;n[r]=e.every(s=>{var l;return If(((l=s.marks)==null?void 0:l[r])??null,o)})?o:null}return n}function yo(e,n,t){const{startRunId:r,startOffset:o,endRunId:s,endOffset:l}=t,i=$n(e,n),c=i.indexOf(r),u=i.indexOf(s);if(c===-1||u===-1)return{};const[f,p]=c<=u?[c,u]:[u,c],h=i.slice(f,p+1).map(b=>e.getRun(b)).filter(b=>b&&b.type==="text");return Hl(h)}function vo(e,n){const{blockIds:t,startBlockId:r,endBlockId:o}=n,s=t.indexOf(r),l=t.indexOf(o);if(s===-1||l===-1)return{};const[i,c]=s<=l?[s,l]:[l,s],u=[];for(let f=i;f<=c;f+=1)for(const p of $n(e,t[f])){const h=e.getRun(p);h&&h.type==="text"&&u.push(h)}return Hl(u)}function Fl(e,n){const t={...e};for(const[r,o]of Object.entries(n))o!=null?t[r]=o:delete t[r];return t}function Ul(e,n,t,r,o,s){const l=Fl(t.marks,s);if(r===0&&o===t.value.length)return e.applyOperation({type:"updateRun",id:t.id,patch:{marks:l}}),t.id;const i=t.value.slice(0,r),c=t.value.slice(r,o),u=t.value.slice(o),f=[];i&&f.push({id:L(),type:"text",value:i,marks:{...t.marks}});const p={id:L(),type:"text",value:c,marks:l};return f.push(p),u&&f.push({id:L(),type:"text",value:u,marks:{...t.marks}}),e.applyOperation(ct(n,[t.id],f)),p.id}function Cf(e,n,t,r){const{startRunId:o,startOffset:s,endRunId:l,endOffset:i}=t,c=$n(e,n),u=c.indexOf(o),f=c.indexOf(l);if(u===-1||f===-1)return null;const[p,h]=u<=f?[u,f]:[f,u],b=u<=f?s:i,g=u<=f?i:s,x=c.slice(p,h+1),k=x.map(w=>e.getRun(w));if(p===h){const w=k[0];if(w.type!=="text")return w.id;const T=Math.max(0,Math.min(b,g)),S=Math.min(w.value.length,Math.max(b,g));return T===S?w.id:Ul(e,n,w,T,S,r)}const y=[];let I=null;return k.forEach((w,T)=>{if(w.type!=="text"){y.push(w),I=w.id;return}const S=T===0,v=T===k.length-1,R=S?b:0,O=v?g:w.value.length,N=w.value.slice(0,R),C=w.value.slice(R,O),B=w.value.slice(O);N&&y.push({id:L(),type:"text",value:N,marks:{...w.marks}});const A={id:L(),type:"text",value:C,marks:Fl(w.marks,r)};y.push(A),I=A.id,B&&y.push({id:L(),type:"text",value:B,marks:{...w.marks}})}),e.applyOperation(ct(n,x,y)),I}function Sf(e,n,t,r){var g;const{startRunId:o,startOffset:s,endRunId:l,endOffset:i}=t,c=$n(e,n),u=c.indexOf(o),f=c.indexOf(l);if(u===-1||f===-1)return!0;const[p,h]=u<=f?[u,f]:[f,u],b=c.slice(p,h+1).map(x=>e.getRun(x)).filter(x=>x.type==="text");if(b.length===0)return!0;if(p===h){const x=Math.max(0,Math.min(s,i)),k=Math.min(b[0].value.length,Math.max(s,i));if(x===k)return!((g=b[0].marks)!=null&&g[r])}return!b.every(x=>{var k;return(k=x.marks)==null?void 0:k[r]})}function jf(e,n,t,r,o,s){var p;const l=e.getRun(t),i=l.value??"",c=Math.max(0,Math.min(r,o)),u=Math.min(i.length,Math.max(r,o));if(c===u)return t;const f=!((p=l.marks)!=null&&p[s]);return Ul(e,n,l,c,u,{[s]:f?!0:null})}function _n(e,n,t,r){return Cf(e,n,t,r)}function wo(e,n,t,r){const o=Sf(e,n,t,r);return _n(e,n,t,{[r]:o?!0:null})}function Io(e,n,t){return Ft(e,n,r=>({[t]:r?null:!0}),t)}function Ft(e,n,t,r){var v;const{blockIds:o,startBlockId:s,startRunId:l,startOffset:i,endBlockId:c,endRunId:u,endOffset:f}=n;if(!o||o.length===0)return null;const p=o.indexOf(s),h=o.indexOf(c);if(p===-1||h===-1)return null;const[b,g]=p<=h?[p,h]:[h,p],x=p<=h,k=x?l:u,y=x?i:f,I=x?u:l,w=x?f:i;let T=t;if(typeof t=="function"){let R=!1,O=!0;for(let N=b;N<=g;N+=1){const C=$n(e,o[N]).map(B=>e.getRun(B)).filter(B=>B.type==="text");C.length!==0&&(R=!0,C.every(B=>{var A;return(A=B.marks)==null?void 0:A[r]})||(O=!1))}T=t(R&&O)}if(b===g)return _n(e,o[b],{startRunId:k,startOffset:y,endRunId:I,endOffset:w},T);let S=null;for(let R=b;R<=g;R+=1){const O=o[R],N=$n(e,O),C=N[0],B=N[N.length-1],A=e.getRun(B),z=((v=A==null?void 0:A.value)==null?void 0:v.length)??0;let U;R===b&&R===g?U={startRunId:k,startOffset:y,endRunId:I,endOffset:w}:R===b?U={startRunId:k,startOffset:y,endRunId:B,endOffset:z}:R===g?U={startRunId:C,startOffset:0,endRunId:I,endOffset:w}:U={startRunId:C,startOffset:0,endRunId:B,endOffset:z},S=_n(e,O,U,T)}return S}function Yl(e,n){var r;const t=e.getBlock(n);return((r=t==null?void 0:t.props)==null?void 0:r.titleRunIds)??(t==null?void 0:t.contentIds)??[]}function Kl(e){const n=Hn();if(!n)return!1;const{blockId:t,startRunId:r,startOffset:o,endRunId:s,endOffset:l}=n,i=Yl(e,t);if(i.length===0)return!1;const c=i.indexOf(r),u=i.indexOf(s);if(c===-1||u===-1)return!1;const[f,p]=c<=u?[c,u]:[u,c],h=c<=u?o:l,b=c<=u?l:o;if(f!==0||p!==i.length-1||h!==0)return!1;const g=e.getRun(i[i.length-1]),x=(g==null?void 0:g.type)==="text"?(g.value??"").length:1;return b===x}function Rf(e){const n=nn();return n?Le(e,Yl(e,n.blockId)):!1}function Tf(e,n,t){var b,g;const r=e.getBlock(n);if(!r){t(null);return}const o=e.getBlock(r.parentId),s=o?o.contentIds.indexOf(n):-1,l=s>0?o.contentIds[s-1]:null,i=s!==-1&&s<o.contentIds.length-1?o.contentIds[s+1]:null;e.applyOperation(Z(n)),t(null);const c=Un(e),u=l??i??c;if(!u)return;const f=e.getBlock(u);if(dt(e,f)){t(u),requestAnimationFrame(()=>{var x;return(x=document.querySelector(`[data-block-id="${u}"]`))==null?void 0:x.focus()});return}const p=(b=f==null?void 0:f.props)==null?void 0:b.titleRunIds,h=((g=f==null?void 0:f.contentIds)==null?void 0:g[f.contentIds.length-1])??(p==null?void 0:p[p.length-1]);h&&xe(h)}const Bs={b:"bold",i:"italic",u:"underline"};function Bf(e){const n=W(),[t,r]=Fr(),{getSelectedBlockId:o,setSelectedBlockId:s}=rn();d.useEffect(()=>{const l=e.current;if(!l)return;const i=u=>{var p,h;if(o()&&(u.key==="Backspace"||u.key==="Delete")&&!u.defaultPrevented){u.preventDefault(),u.stopPropagation(),Tf(n,o(),s);return}if(o()&&u.key!=="Backspace"&&u.key!=="Delete"&&s(null),u.metaKey||u.ctrlKey){const b=u.key.toLowerCase();if(b==="z"&&!u.shiftKey){u.preventDefault(),(p=n.undo)!=null&&p.call(n)&&Pn(n);return}if(b==="z"&&u.shiftKey||b==="y"){u.preventDefault(),(h=n.redo)!=null&&h.call(n)&&Pn(n);return}if(b==="a"){if(t)return;(Kl(n)||Rf(n))&&(u.preventDefault(),r(!0));return}if(Bs[b]){if(t)return;u.preventDefault();const g=Bs[b],x=Hn();if(x){const y=wo(n,x.blockId,x,g);y&&xe(y);return}const k=Dn(n);if(k){const y=Io(n,k,g);y&&xe(y)}}return}if(t){if(u.key==="Backspace"||u.key==="Delete"){u.preventDefault(),u.stopPropagation();const b=Ht(n);r(!1),b!=null&&b.runId&&Ke(b.runId,b.offset);return}if(u.key.length===1){u.preventDefault(),u.stopPropagation();const b=Ht(n,u.key);r(!1),b!=null&&b.runId&&Ke(b.runId,b.offset);return}if(r(!1),u.key==="Escape")return}if(u.key==="Backspace"||u.key==="Delete"){const b=Dn(n);if(!b)return;u.preventDefault(),u.stopPropagation();const g=xo(n,b);g!=null&&g.runId&&Ke(g.runId,g.offset)}},c=()=>{t&&r(!1),o()&&s(null)};return l.addEventListener("keydown",i),l.addEventListener("mousedown",c),()=>{l.removeEventListener("keydown",i),l.removeEventListener("mousedown",c)}},[e,n,t,r,o,s])}async function Ar(e,n,t,r){var l,i,c;const{html:o,text:s}=ft(e,n,r,t);if(typeof ClipboardItem<"u"&&((l=navigator.clipboard)!=null&&l.write)){await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([s],{type:"text/plain"}),"text/html":new Blob([o],{type:"text/html"})})]);return}await((c=(i=navigator.clipboard)==null?void 0:i.writeText)==null?void 0:c.call(i,s))}function Ef(){const e=W(),n=dn(),t=We(),[r,o]=ut(),[s,l]=d.useState(null),i=d.useRef(null),c=d.useRef(null),u=r.length>0,f=Kt(i,u,(s==null?void 0:s.bottom)!=null?s.bottom+4:null,s==null?void 0:s.left),p=d.useCallback(()=>o([]),[o]);Jt(i,u,p,void 0),d.useEffect(()=>{if(!u){l(null);return}const v=()=>{const R=r[r.length-1],O=document.querySelector(`[data-block-row-id="${R}"]`);l((O==null?void 0:O.getBoundingClientRect())??null)};return v(),window.addEventListener("scroll",v,!0),window.addEventListener("resize",v),()=>{window.removeEventListener("scroll",v,!0),window.removeEventListener("resize",v)}},[u,r]),d.useEffect(()=>{if(!u)return;const v=O=>{var N,C,B,A;(N=i.current)!=null&&N.contains(O.target)||(C=c.current)!=null&&C.contains(O.target)||(A=(B=O.target).closest)!=null&&A.call(B,".be-block-gutter")||p()},R=O=>{O.key==="Escape"?p():(O.key==="Delete"||O.key==="Backspace")&&(O.preventDefault(),st(e,r),p())};return document.addEventListener("mousedown",v),document.addEventListener("keydown",R),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",R)}},[u,e,r,p]);const h=v=>v===1?"block":"blocks",b=d.useCallback(()=>{Ar(e,n,t,r),ge(`${r.length} ${h(r.length)} copied`),p()},[e,n,t,r,p]),g=d.useCallback(async()=>{await Ar(e,n,t,r);const v=r.length;st(e,r),ge(`${v} ${h(v)} cut`),p()},[e,n,t,r,p]),x=d.useCallback(()=>{const v=r.length;st(e,r),ge(`${v} ${h(v)} deleted`),p()},[e,r,p]),k=d.useCallback(()=>{Pl(e,r)&&ge(`${r.length} ${h(r.length)} moved up`),p()},[e,r,p]),y=d.useCallback(()=>{$l(e,r)&&ge(`${r.length} ${h(r.length)} moved down`),p()},[e,r,p]),I=_l(e,r),w=d.useCallback(()=>{zl(e,r,!I),ge(I?`${r.length} ${h(r.length)} shown in preview`:`${r.length} ${h(r.length)} hidden in preview`),p()},[e,r,I,p]),T=r.some(v=>{var R;return ro((R=e.getBlock(v))==null?void 0:R.type)}),S=d.useCallback(v=>{const R=r.length;mf(e,n,r,v),ge(`${R} ${h(R)} turned into ${v.label}`),p()},[e,n,r,p]);return!u||!f?null:Ve.createPortal(a.jsxs("div",{ref:i,role:"menu","aria-label":"Selected blocks options",className:"be-block-range-menu",style:{position:"fixed",top:f.top,left:f.left},children:[a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:b,children:[a.jsx(Vr,{size:15})," Copy"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:g,children:[a.jsx(oc,{size:15})," Cut"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:k,children:[a.jsx(qt,{size:15})," Move up"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:y,children:[a.jsx(Wt,{size:15})," Move down"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:w,children:[I?a.jsx(Zr,{size:15}):a.jsx(Jr,{size:15}),I?"Show in preview":"Hide in preview"]}),T&&a.jsx(ba,{onSelect:S,onClose:()=>{},containerRef:c,menuClassName:"be-block-range-menu",itemClassName:"be-block-range-menu-item"}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item be-block-range-menu-item-danger",onClick:x,children:[a.jsx(Xt,{size:15})," Delete"]})]}),document.body)}const Nf=4;function Of(e,n,t){const r=e.getBlock(n);if(!r)return[];const o=e.getBlock(r.parentId);if(!o)return[n];const s=o.contentIds,l=s.indexOf(n),i=t?s.indexOf(t):l;if(l===-1)return[n];const[c,u]=i===-1?[l,l]:[Math.min(l,i),Math.max(l,i)];return s.slice(c,u+1)}function Lf(){var e,n;return typeof window<"u"&&((n=(e=window.matchMedia)==null?void 0:e.call(window,"(pointer: coarse)"))==null?void 0:n.matches)===!0}function Mf(e){const n=W(),[,t]=ut(),r=d.useRef(null),o=d.useRef(!1),s=d.useRef(null),l=d.useCallback(f=>{var b,g,x,k,y;if(!r.current)return;if(!o.current){const{x:I,y:w}=s.current??{x:f.clientX,y:f.clientY};if(Math.hypot(f.clientX-I,f.clientY-w)<Nf)return;o.current=!0,document.documentElement.classList.add("be-block-range-dragging"),(g=(b=window.getSelection)==null?void 0:b.call(window))==null||g.removeAllRanges()}(k=(x=window.getSelection)==null?void 0:x.call(window))==null||k.removeAllRanges(),f.preventDefault();const p=(y=document.elementFromPoint(f.clientX,f.clientY))==null?void 0:y.closest("[data-block-row-id]"),h=(p==null?void 0:p.getAttribute("data-block-row-id"))??null;t(Of(n,r.current,h))},[n,t]),i=d.useCallback(()=>{r.current=null,o.current=!1,s.current=null,document.documentElement.classList.remove("be-block-range-dragging")},[]),c=d.useCallback((f,p)=>{r.current=f,o.current=!1,s.current={x:p.clientX,y:p.clientY}},[]),u=d.useCallback(f=>{var x,k;if(f.button!==0||Lf()||(k=(x=f.target).closest)!=null&&k.call(x,"button, input, textarea, select"))return;const p=f.target.closest("[data-block-row-id]");if(p){if(f.target.closest(".be-block-row-content"))return;c(p.getAttribute("data-block-row-id"),f);return}const h=e==null?void 0:e.current;if(!h)return;const g=[...h.querySelectorAll("[data-block-row-id]")].find(y=>{const I=y.getBoundingClientRect();return f.clientY>=I.top&&f.clientY<=I.bottom});g&&c(g.getAttribute("data-block-row-id"),f)},[e,c]);d.useEffect(()=>(document.addEventListener("mousedown",u),document.addEventListener("mousemove",l),document.addEventListener("mouseup",i),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("mousemove",l),document.removeEventListener("mouseup",i),document.documentElement.classList.remove("be-block-range-dragging")}),[u,l,i])}const Af="be-touch-input";function Df(){var e,n;return typeof window<"u"&&((n=(e=window.matchMedia)==null?void 0:e.call(window,"(pointer: coarse)"))==null?void 0:n.matches)===!0}function Co(){const[e,n]=d.useState(Df);return d.useEffect(()=>{if(typeof window>"u")return;const t=r=>{n(r.pointerType==="touch"||r.pointerType==="pen")};return window.addEventListener("pointerdown",t,{passive:!0}),()=>window.removeEventListener("pointerdown",t)},[]),d.useEffect(()=>{var t;(t=document.documentElement)==null||t.classList.toggle(Af,e)},[e]),e}function So(e,n,t,r,o){const[s,l]=d.useState(!1),i=d.useCallback(k=>{const y=n==="same-block"?_n(e,t.blockId,t,k):Ft(e,r,k);return y&&xe(y),y},[e,n,t,r]),c=d.useCallback(k=>{const y=n==="same-block"?wo(e,t.blockId,t,k):Io(e,r,k);y&&xe(y)},[e,n,t,r]),u=d.useCallback(k=>{const y=k==="subscript"?"superscript":"subscript",I=!o[k];i({[k]:I?!0:null,[y]:null})},[o,i]),f=d.useRef(null),p=d.useCallback(()=>{f.current={kind:n,selection:t,crossSelection:r},l(!0)},[n,t,r]),h=d.useCallback(()=>l(!1),[]),b=d.useCallback(k=>{const y=f.current;if(!y)return;const I=y.kind==="same-block"?_n(e,y.selection.blockId,y.selection,k):Ft(e,y.crossSelection,k);I&&xe(I),l(!1)},[e]),g=d.useCallback((k,y)=>b({link:{href:k,target:y}}),[b]),x=d.useCallback(()=>b({link:null}),[b]);return{applyPatch:i,toggleBoolean:c,setSubSuper:u,isLinkModalOpen:s,openLinkModal:p,closeLinkModal:h,handleSaveLink:g,handleRemoveLink:x}}function Vl({isOpen:e,onClose:n,onSelectCommand:t}){const r=dn(),o=We(),s=d.useMemo(()=>[...(r==null?void 0:r.listSlashCommands())??[],...(o==null?void 0:o.listSlashCommands())??[]],[r,o]);return a.jsx(on,{isOpen:e,onClose:n,title:"Add a block",variant:"sheet",children:a.jsx("div",{className:"be-mobile-picker-list",role:"listbox","aria-label":"Insertable blocks",children:s.map(l=>{const i=l.icon;return a.jsxs("button",{type:"button",role:"option",className:"be-mobile-picker-item",onClick:()=>t(l),children:[i&&a.jsx("span",{className:"be-mobile-picker-item-icon",children:a.jsx(i,{size:18})}),a.jsx("span",{className:"be-mobile-picker-item-label",children:l.label})]},l.label)})})})}function Xl({isOpen:e,onClose:n,store:t,blockId:r}){var i;const o=r?t.getBlock(r):null,s=!!((i=o==null?void 0:o.props)!=null&&i.hidden),l=d.useCallback(c=>{c(),n()},[n]);return a.jsx(on,{isOpen:e,onClose:n,title:"Block options",variant:"sheet",children:a.jsxs("div",{className:"be-mobile-picker-list",role:"menu","aria-label":"Block options",children:[a.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>l(()=>{ao(t,r),ge("Block duplicated")}),children:[a.jsx("span",{className:"be-mobile-picker-item-icon",children:a.jsx(Vr,{size:18})}),a.jsx("span",{className:"be-mobile-picker-item-label",children:"Duplicate"})]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>l(()=>{lo(t,r)&&ge("Block moved up")}),children:[a.jsx("span",{className:"be-mobile-picker-item-icon",children:a.jsx(qt,{size:18})}),a.jsx("span",{className:"be-mobile-picker-item-label",children:"Move up"})]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>l(()=>{io(t,r)&&ge("Block moved down")}),children:[a.jsx("span",{className:"be-mobile-picker-item-icon",children:a.jsx(Wt,{size:18})}),a.jsx("span",{className:"be-mobile-picker-item-label",children:"Move down"})]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>l(()=>{t.applyOperation(X(r,{hidden:!s})),ge(s?"Block shown in preview":"Block hidden in preview")}),children:[a.jsx("span",{className:"be-mobile-picker-item-icon",children:s?a.jsx(Zr,{size:18}):a.jsx(Jr,{size:18})}),a.jsx("span",{className:"be-mobile-picker-item-label",children:s?"Show in preview":"Hide in preview"})]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item be-mobile-picker-item-danger",onClick:()=>l(()=>{Qt(t,r),ge("Block deleted")}),children:[a.jsx("span",{className:"be-mobile-picker-item-icon",children:a.jsx(Xt,{size:18})}),a.jsx("span",{className:"be-mobile-picker-item-label",children:"Delete"})]})]})})}const Pf=Ya.map(e=>({value:e,label:e}));function $f(e,n){const[t,r]=d.useState(!1),[o,s]=d.useState(null),[l,i]=d.useState(null),[c,u]=d.useState(null);return d.useEffect(()=>{const f=e.current;if(!f)return;const p=()=>r(!0),h=b=>{f.contains(b.relatedTarget)||r(!1)};return f.addEventListener("focusin",p),f.addEventListener("focusout",h),()=>{f.removeEventListener("focusin",p),f.removeEventListener("focusout",h)}},[e]),d.useEffect(()=>{if(!t){s(null);return}const f=()=>{var g;const p=e.current,h=(g=window.getSelection)==null?void 0:g.call(window);if(!p||!h||h.rangeCount===0){s(null);return}if(!h.isCollapsed){if(!p.contains(h.anchorNode)||!p.contains(h.focusNode)){s(null);return}const x=Hn();if(x){i({kind:"same-block",selection:x,crossSelection:null,marks:yo(n,x.blockId,x)}),s("selection");return}const k=Dn(n);if(k){i({kind:"cross-block",selection:null,crossSelection:k,marks:vo(n,k)}),s("selection");return}s(null);return}const b=nn();if(!b||!p.contains(h.anchorNode)){s(null);return}u(b),s("caret")};return f(),document.addEventListener("selectionchange",f),()=>document.removeEventListener("selectionchange",f)},[t,n,e]),{isFocused:t,mode:o,selectionState:l,caretState:c}}function _f({store:e,selectionState:n}){const{kind:t,selection:r,crossSelection:o,marks:s}=n,{toggleBoolean:l,openLinkModal:i}=So(e,t,r,o,s);return a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.bold?" be-mobile-bar-btn-active":""}`,"aria-label":"Bold",onClick:()=>l("bold"),children:a.jsx(Hs,{size:18})}),a.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.italic?" be-mobile-bar-btn-active":""}`,"aria-label":"Italic",onClick:()=>l("italic"),children:a.jsx(Fs,{size:18})}),a.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.underline?" be-mobile-bar-btn-active":""}`,"aria-label":"Underline",onClick:()=>l("underline"),children:a.jsx(Us,{size:18})}),a.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.link?" be-mobile-bar-btn-active":""}`,"aria-label":"Link",onClick:i,children:a.jsx(Ks,{size:18})})]})}function zf({store:e,blockId:n}){const t=d.useCallback(()=>{const o=e.getBlock(n),s=o&&e.getBlock(o.parentId);s&&uo(e,s.id)},[e,n]),r=d.useCallback(()=>{const o=e.getBlock(n),s=o&&e.getBlock(o.parentId),l=s&&e.getBlock(s.parentId);if(!l||!s)return;const i=s.contentIds.indexOf(n);i!==-1&&$t(e,l.id,i)},[e,n]);return a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert row below",onClick:t,children:"+ Row"}),a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert column right",onClick:r,children:"+ Column"})]})}function Hf({store:e,blockId:n}){var o;const t=e.getBlock(n),r=d.useCallback(s=>e.applyOperation(X(n,{language:s})),[e,n]);return a.jsx(In,{className:"be-mobile-bar-select",value:((o=t==null?void 0:t.props)==null?void 0:o.language)??"plaintext",options:Pf,onChange:r,ariaLabel:"Code language"})}function Ff({store:e,blockId:n}){var o;const t=e.getBlock(n),r=(o=t==null?void 0:t.props)==null?void 0:o.color;return a.jsx("div",{className:"be-mobile-bar-swatches",children:Ha.map(s=>a.jsx("button",{type:"button",className:`be-callout-color-option be-callout-color-option-${s.value}${s.value===r?" be-callout-color-option-active":""}`,"aria-label":s.label,title:s.label,onClick:()=>e.applyOperation(X(n,{color:s.value}))},s.value))})}const ql={tableCell:zf,code:Hf,callout:Ff};function Uf(e,n){let t=e.getBlock(n);for(;t;){if(ql[t.type])return t;t=t.parentId?e.getBlock(t.parentId):null}return null}function Yf(e,n){const t=e.getRootId();let r=e.getBlock(n);for(;r&&r.parentId!==t;)r=e.getBlock(r.parentId);return r}function Kf({containerRef:e}){var R,O;const n=W(),t=Nl(),r=Co(),o=rr(),{isFocused:s,mode:l,selectionState:i,caretState:c}=$f(e,n),[u,f]=d.useState(!1),[p,h]=d.useState(!1),b=d.useCallback(()=>f(!0),[]),g=d.useCallback(()=>f(!1),[]),x=d.useCallback(()=>h(!0),[]),k=d.useCallback(()=>h(!1),[]),y=d.useCallback(N=>{const C=nn()??c;C&&(N.run(n,{blockId:C.blockId,runId:C.runId,sliceStart:C.offset,sliceEnd:C.offset}),g())},[n,c,g]),I=d.useCallback(()=>{var N,C;(C=(N=document.activeElement)==null?void 0:N.blur)==null||C.call(N)},[]);if(!r||!s)return null;const w=l==="caret"&&c?Uf(n,c.blockId):null,T=w?ql[w.type]:null,S=l==="caret"&&c?c.blockId:((R=i==null?void 0:i.selection)==null?void 0:R.blockId)??((O=i==null?void 0:i.crossSelection)==null?void 0:O.startBlockId)??null,v=S?Yf(n,S):null;return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"be-mobile-action-bar",role:"toolbar","aria-label":"Editor actions",style:{bottom:o},onMouseDown:N=>N.preventDefault(),children:[l==="selection"&&i&&a.jsx(_f,{store:n,selectionState:i}),l!=="selection"&&a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Add block",onClick:b,children:a.jsx(Kr,{size:18})}),T&&w&&a.jsx(T,{store:n,blockId:w.id}),t&&a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Undo",disabled:!t.canUndo,onClick:t.undo,children:"↶"}),a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Redo",disabled:!t.canRedo,onClick:t.redo,children:"↷"})]})]}),a.jsx("span",{className:"be-mobile-bar-spacer"}),v&&a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Block options",onClick:x,children:a.jsx(Ki,{size:18})}),a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Dismiss keyboard",onClick:I,children:a.jsx(Vt,{size:18})})]}),a.jsx(Vl,{isOpen:u,onClose:g,onSelectCommand:y}),a.jsx(Xl,{isOpen:p,onClose:k,store:n,blockId:v==null?void 0:v.id})]})}function Vf({minHeight:e=180,className:n="be-trailing-space"}){const t=W(),[r]=Ur(),o=d.useCallback(()=>{var u;if(r)return;const s=t.getRootId(),l=t.getBlock(s),i=(u=l==null?void 0:l.contentIds)==null?void 0:u[l.contentIds.length-1];if(!i){const f=Un(t);f&&as(t,f);return}const c=t.getBlock(i);(c==null?void 0:c.type)==="paragraph"?as(t,i):Ge(t,i,J("paragraph"))},[t,r]);return a.jsx("div",{className:n,style:{minHeight:e},onClick:o})}function Wl(e,{pretty:n=!0}={}){const t=e.getRootId(),{blocks:r,runs:o}=oo(e,t);return JSON.stringify({version:1,rootId:t,blocks:r,runs:o},null,n?2:0)}function Gl(e,n,t){const r=e.getBlock(e.getRootId());return r?ft(e,n,r.contentIds,t).html:""}function Zl(e,n,t){const r=e.getBlock(e.getRootId());return r?ft(e,n,r.contentIds,t).text:""}const Jl={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"]},Ql=new Set(["listItem","toggleHeading"]),ei=new Set(["divider","embed"]);function ni(e,n,t,r){var i,c,u;const o=t.type,s={};for(const f of Jl[o]??[])((i=t.props)==null?void 0:i[f])!==void 0&&(s[f]=t.props[f]);if(o==="table"){const f=t.contentIds[0]&&e.getBlock(t.contentIds[0]);return s.columns=De(t,((c=f==null?void 0:f.contentIds)==null?void 0:c.length)??0),s.rows=t.contentIds.map(p=>e.getBlock(p).contentIds.map(b=>{const g=e.getBlock(b);return xr(g.contentIds.map(x=>e.getRun(x)),r)})),{id:t.id,type:o,data:s}}if(Ql.has(o)){const f=((u=t.props)==null?void 0:u.titleRunIds)??[];s.text=xr(f.map(p=>e.getRun(p)),r)}else n.isLeaf(o)&&!ei.has(o)&&(s.text=xr(t.contentIds.map(f=>e.getRun(f)),r));const l={id:t.id,type:o,data:s};return n.isLeaf(o)||(l.children=t.contentIds.map(f=>ni(e,n,e.getBlock(f),r))),l}function ti(e,n,t,{pretty:r=!0}={}){const o={store:e,registry:n,inlineRegistry:t},l=e.getBlock(e.getRootId()).contentIds.map(i=>ni(e,n,e.getBlock(i),o));return JSON.stringify({version:1,blocks:l},null,r?2:0)}function Dr(e,n){const t=new DOMParser().parseFromString(`<div>${e??""}</div>`,"text/html");return $e(t.body.firstChild,n)}function Xf(e,n,t,r,o){const{id:s=L(),data:l={}}=e,i=(l.rows??[]).map(u=>{const f=L(),p=u.map(h=>{const b=L(),g=Dr(h,o);return r.push(...g),t.push({id:b,type:"tableCell",parentId:f,contentIds:g.map(x=>x.id),props:{}}),b});return t.push({id:f,type:"tableRow",parentId:n,contentIds:p,props:{}}),f}),c={id:s,type:"table",parentId:n,contentIds:i,props:{columns:l.columns??[]}};return t.push(c),c}function Pr(e,n,t,r,o,s){const{id:l=L(),type:i,data:c={},children:u=[]}=e;if(i==="table")return Xf(e,n,o,s,r);const f={};for(const h of Jl[i]??[])c[h]!==void 0&&(f[h]=c[h]);const p={id:l,type:i,parentId:n,contentIds:[],props:f};if(o.push(p),Ql.has(i)){const h=Dr(c.text,r);s.push(...h),p.props.titleRunIds=h.map(b=>b.id),p.contentIds=u.map(b=>Pr(b,l,t,r,o,s).id)}else if(t.isLeaf(i)){if(!ei.has(i)){const h=Dr(c.text,r);s.push(...h),p.contentIds=h.map(b=>b.id)}}else p.contentIds=u.map(h=>Pr(h,l,t,r,o,s).id);return p}function qf(e,n,t){const r=typeof e=="string"?JSON.parse(e):e,o={registry:n,inlineRegistry:t},s=L(),l=[],i=[],c=(r.blocks??[]).map(u=>Pr(u,s,n,o,l,i).id);return l.push({id:s,type:"page",parentId:null,contentIds:c,props:{}}),{rootId:s,blocks:l,runs:i}}const Wf=[{value:"json",label:"JSON"},{value:"simpleJson",label:"Simple JSON"},{value:"html",label:"HTML"},{value:"text",label:"Text"}];function Gf({label:e="View source",className:n=""}){const t=W(),r=dn(),o=We(),[s,l]=d.useState(!1),[i,c]=d.useState("json"),[u,f]=d.useState(!1),p=d.useCallback(()=>{f(!1),l(!0)},[]),h=d.useCallback(()=>l(!1),[]),b=d.useMemo(()=>s?i==="json"?Wl(t):i==="simpleJson"?ti(t,r,o):i==="html"?Gl(t,r,o):Zl(t,r,o):"",[s,i,t,r,o]),g=d.useCallback(async()=>{try{await navigator.clipboard.writeText(b),f(!0),setTimeout(()=>f(!1),1500)}catch{}},[b]);return a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:`be-export-trigger ${n}`.trim(),onClick:p,children:[a.jsx(Wr,{size:14})," ",e]}),a.jsxs(on,{isOpen:s,onClose:h,title:"Document source",size:"large",children:[a.jsx("div",{className:"be-export-tabs",role:"tablist",children:Wf.map(x=>a.jsx("button",{type:"button",role:"tab","aria-selected":i===x.value,className:`be-export-tab${i===x.value?" be-export-tab-active":""}`,onClick:()=>c(x.value),children:x.label},x.value))}),a.jsx("pre",{className:"be-export-pre",children:a.jsx("code",{children:b})}),a.jsxs("div",{className:"be-modal-actions",children:[a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:h,children:"Close"}),a.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:u?"Copied!":"Copy"})]})]})]})}const Zf=340;function Jf(e,n,t,r){d.useEffect(()=>{if(!e||!n)return;const o=document.querySelector(`[data-run-id="${n}"]`);if(o)return o.setAttribute("aria-expanded","true"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-controls",r),t&&o.setAttribute("aria-activedescendant",t),()=>{o.removeAttribute("aria-expanded"),o.removeAttribute("aria-haspopup"),o.removeAttribute("aria-controls"),o.removeAttribute("aria-activedescendant")}},[e,n,t,r])}function Qf({isOpen:e,rect:n,commands:t,runId:r,onSelect:o,onClose:s,menuId:l="be-slash-menu",ariaLabel:i="Slash commands"}){const[c,u]=d.useState(0),f=d.useRef(null),p=d.useRef(null),h=rr(),b=Ba(p,e&&t.length>0&&!!n,n==null?void 0:n.left);d.useEffect(()=>{u(0)},[t.length]),d.useEffect(()=>{var w,T;(T=(w=f.current)==null?void 0:w.scrollIntoView)==null||T.call(w,{block:"nearest"})},[c]),d.useEffect(()=>{if(!e)return;const w=T=>{T.key==="ArrowDown"?(T.preventDefault(),T.stopPropagation(),u(S=>Math.min(S+1,Math.max(t.length-1,0)))):T.key==="ArrowUp"?(T.preventDefault(),T.stopPropagation(),u(S=>Math.max(S-1,0))):T.key==="Enter"?(T.preventDefault(),T.stopPropagation(),t[c]&&o(t[c])):T.key==="Escape"&&(T.preventDefault(),T.stopPropagation(),s())};return document.addEventListener("keydown",w,!0),()=>document.removeEventListener("keydown",w,!0)},[e,t,c,o,s]);const x=t[c]?`${l}-option-${c}`:null;if(Jf(e,r,x,l),!e||t.length===0||!n||b==null)return null;const k=window.innerHeight-h,I=n.bottom+Zf>k?{bottom:window.innerHeight-n.top+4}:{top:n.bottom+4};return a.jsx("div",{ref:p,id:l,role:"listbox","aria-label":i,className:"be-slash-menu",style:{position:"fixed",left:b,zIndex:1e3,...I},children:t.map((w,T)=>{const S=w.icon;return a.jsxs("div",{ref:T===c?f:void 0,id:`${l}-option-${T}`,role:"option","aria-selected":T===c,className:`be-slash-menu-item${T===c?" be-slash-menu-item-active":""}`,onMouseDown:v=>{v.preventDefault(),o(w)},onMouseEnter:()=>u(T),children:[S&&a.jsx("span",{className:"be-slash-menu-item-icon",children:a.jsx(S,{size:16})}),a.jsx("span",{className:"be-slash-menu-item-label",children:w.label})]},w.label)})})}function eh(e,n){var r;if(!n)return!0;const t=n.toLowerCase();return e.label.toLowerCase().includes(t)||((r=e.keywords)==null?void 0:r.some(o=>o.toLowerCase().includes(t)))}function nh(e,n){const t=n.anchorNode,r=n.anchorOffset;let o;if(t===e){o="";for(let s=0;s<r&&s<e.childNodes.length;s+=1)o+=e.childNodes[s].textContent??""}else t&&t.parentElement===e?o=(t.textContent??"").slice(0,r):o=e.textContent??"";return en(o).length}function jo(e,n,t){const r=W(),[o,s]=d.useState(null);d.useEffect(()=>{const u=e.current;if(!u)return;const f=()=>{var S,v,R,O;const h=(S=window.getSelection)==null?void 0:S.call(window),b=h==null?void 0:h.anchorNode;let g=(b==null?void 0:b.nodeType)===1?b:b==null?void 0:b.parentElement;for(;g&&typeof g.hasAttribute=="function"&&!g.hasAttribute("data-run-id");)g=g.parentElement;const x=(v=g==null?void 0:g.getAttribute)==null?void 0:v.call(g,"data-run-id");if(!x||!h){s(null);return}const k=nh(g,h),y=en(g.textContent).slice(0,k),I=n.exec(y);if(!I){s(null);return}const w=(O=(R=g.closest)==null?void 0:R.call(g,"[data-block-id]"))==null?void 0:O.getAttribute("data-block-id");if(!w){s(null);return}const T=I.index+I[1].length;s({query:I[2],blockId:w,runId:x,sliceStart:T,sliceEnd:k,rect:g.getBoundingClientRect()})},p=h=>{h.key==="Escape"&&s(null)};return u.addEventListener("input",f),u.addEventListener("keydown",p),()=>{u.removeEventListener("input",f),u.removeEventListener("keydown",p)}},[e,n]);const l=o?t().filter(u=>eh(u,o.query)):[],i=d.useCallback(u=>{o&&(u.run(r,{blockId:o.blockId,runId:o.runId,sliceStart:o.sliceStart,sliceEnd:o.sliceEnd}),s(null))},[o,r]),c=d.useCallback(()=>s(null),[]);return{isOpen:!!o,query:(o==null?void 0:o.query)??"",rect:(o==null?void 0:o.rect)??null,runId:(o==null?void 0:o.runId)??null,commands:l,selectCommand:i,close:c}}const th=/(^|\s)\/(\w*)$/;function rh(e){const n=dn(),t=We(),r=d.useCallback(()=>[...n.listSlashCommands(),...(t==null?void 0:t.listSlashCommands())??[]],[n,t]);return jo(e,th,r)}const oh=[{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 sh(e,{runId:n,sliceStart:t,sliceEnd:r},o){const s=e.getRun(n),l=(s==null?void 0:s.value)??"",i=l.slice(0,t)+o+l.slice(r);e.applyOperation(ce(n,{value:i})),Ke(n,t+o.length)}const ah=oh.map(({char:e,name:n,keywords:t})=>({label:`${e} ${n}`,keywords:t,run:(r,o)=>sh(r,o,e)})),lh=/(^|\s):(\w*)$/,ih=()=>ah;function ch(e){return jo(e,lh,ih)}const uh=/(^|\s)@(\w*)$/;function dh(e){const n=We(),t=d.useCallback(()=>(n==null?void 0:n.listAtCommands())??[],[n]);return jo(e,uh,t)}const ph=[{markName:"bold",Icon:Hs,title:"Bold (Ctrl+B)"},{markName:"italic",Icon:Fs,title:"Italic (Ctrl+I)"},{markName:"underline",Icon:Us,title:"Underline (Ctrl+U)"},{markName:"strike",Icon:Xi,title:"Strikethrough"}],fh=[{label:"Default",value:null},{label:"Red",value:"#e03131"},{label:"Orange",value:"#e8590c"},{label:"Green",value:"#2f9e44"},{label:"Blue",value:"#1971c2"},{label:"Purple",value:"#9c36b5"}],hh=[{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 bh({isOpen:e,rect:n,kind:t,selection:r,crossSelection:o,marks:s,store:l}){var T,S;const i=Co(),[c,u]=d.useState(null),f=d.useRef(null),{applyPatch:p,toggleBoolean:h,setSubSuper:b,isLinkModalOpen:g,openLinkModal:x,closeLinkModal:k,handleSaveLink:y,handleRemoveLink:I}=So(l,t,r,o,s);d.useEffect(()=>{if(!c)return;const v=O=>{f.current&&!f.current.contains(O.target)&&u(null)},R=O=>{O.key==="Escape"&&u(null)};return document.addEventListener("mousedown",v),document.addEventListener("keydown",R),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",R)}},[c]),d.useEffect(()=>{u(null)},[n,t]);const w=Ea(f,!!(e&&n),n?n.left+n.width/2:null);return i||(!e||!n)&&!g?null:a.jsxs(a.Fragment,{children:[e&&n&&w!=null&&a.jsxs("div",{ref:f,className:"be-floating-toolbar",role:"toolbar","aria-label":"Text formatting",style:{position:"fixed",top:n.top-44,left:w,transform:"translateX(-50%)"},onMouseDown:v=>v.preventDefault(),children:[ph.map(({markName:v,Icon:R,title:O})=>a.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s[v]?" be-floating-toolbar-btn-active":""}`,title:O,"aria-label":O,"aria-pressed":!!s[v],onClick:()=>h(v),children:a.jsx(R,{})},v)),a.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.subscript?" be-floating-toolbar-btn-active":""}`,title:"Subscript","aria-pressed":!!s.subscript,onClick:()=>b("subscript"),children:"X₂"}),a.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.superscript?" be-floating-toolbar-btn-active":""}`,title:"Superscript","aria-pressed":!!s.superscript,onClick:()=>b("superscript"),children:"X²"}),a.jsx("span",{className:"be-floating-toolbar-divider"}),a.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[a.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Text color","aria-haspopup":"true","aria-expanded":c==="color",onClick:()=>u(v=>v==="color"?null:"color"),children:a.jsx("span",{style:{color:s.color||"inherit",fontWeight:700},children:"A"})}),c==="color"&&a.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Text color",children:fh.map(v=>a.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",title:v.label,onClick:()=>{p({color:v.value}),u(null)},children:a.jsx("span",{style:{color:v.value||"#1a1a1a",fontWeight:700},children:"A"})},v.label))})]}),a.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[a.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Highlight","aria-haspopup":"true","aria-expanded":c==="highlight",onClick:()=>u(v=>v==="highlight"?null:"highlight"),children:a.jsx("span",{style:{backgroundColor:s.highlight||"transparent",padding:"0 2px",borderRadius:2},children:"H"})}),c==="highlight"&&a.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Highlight color",children:hh.map(v=>a.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",style:{backgroundColor:v.value||"transparent"},title:v.label,onClick:()=>{p({highlight:v.value}),u(null)}},v.label))})]}),a.jsx("span",{className:"be-floating-toolbar-divider"}),a.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.link?" be-floating-toolbar-btn-active":""}`,title:"Link","aria-label":"Link","aria-pressed":!!s.link,onClick:x,children:a.jsx(Ks,{})})]}),a.jsx(_s,{isOpen:g,initialHref:((T=s.link)==null?void 0:T.href)??"",initialTarget:((S=s.link)==null?void 0:S.target)??"_self",hasExistingLink:!!s.link,onSave:y,onRemove:I,onClose:k})]})}function mh(e){const n=W(),[t,r]=d.useState(null);return d.useEffect(()=>{const o=e.current;if(!o)return;const s=()=>{var f,p,h;const l=(f=window.getSelection)==null?void 0:f.call(window);if(!l||l.rangeCount===0||l.isCollapsed){r(null);return}if(!o.contains(l.anchorNode)||!o.contains(l.focusNode)){r(null);return}const i=((h=(p=l.getRangeAt(0)).getBoundingClientRect)==null?void 0:h.call(p))??{top:0,left:0,right:0,bottom:0,width:0,height:0},c=Hn();if(c){r({kind:"same-block",rect:i,selection:c,marks:yo(n,c.blockId,c)});return}const u=Dn(n);if(u){r({kind:"cross-block",rect:i,crossSelection:u,marks:vo(n,u)});return}r(null)};return document.addEventListener("selectionchange",s),window.addEventListener("scroll",s,!0),window.addEventListener("resize",s),()=>{document.removeEventListener("selectionchange",s),window.removeEventListener("scroll",s,!0),window.removeEventListener("resize",s)}},[e,n]),{isOpen:!!t,rect:(t==null?void 0:t.rect)??null,kind:(t==null?void 0:t.kind)??null,selection:(t==null?void 0:t.selection)??null,crossSelection:(t==null?void 0:t.crossSelection)??null,marks:(t==null?void 0:t.marks)??{},close:()=>r(null)}}function gh({id:e,label:n,placeholder:t,variant:r,options:o,onManage:s,mention:l=!1}){const i=W(),c=pn(e),u=d.useCallback((b,g)=>{i.applyOperation(ce(e,{data:{selectedValue:b,selectedLabel:(g==null?void 0:g.label)??"",selectedColor:g==null?void 0:g.color}}))},[i,e]);if(!c)return null;const{selectedValue:f="",selectedLabel:p="",selectedColor:h}=c.data??{};return a.jsx("span",{className:"be-inline-select",onMouseDown:b=>{b.preventDefault(),b.stopPropagation()},onKeyDown:b=>b.stopPropagation(),children:a.jsx(In,{value:f,selectedLabel:p,selectedColor:h,options:o,onChange:u,placeholder:t,variant:r,ariaLabel:n,onManageOptions:s,mention:l})})}function ri(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Es(e){return ri(e).replace(/"/g,""")}function oi({type:e,label:n,placeholder:t="Select…",variant:r="default",icon:o,options:s,onManage:l,triggers:i=["slash"],mention:c=i.includes("at")}){function u(g){var y,I;const x=((y=g.data)==null?void 0:y.selectedLabel)||"",k=c&&x?`@${x}`:x;return`<span data-inline-type="${Es(e)}" data-selected-value="${Es(((I=g.data)==null?void 0:I.selectedValue)??"")}">${ri(k)}</span>`}function f(g){var k;const x=((k=g.data)==null?void 0:k.selectedLabel)??"";return c&&x?`@${x}`:x}function p(g){var y;if(((y=g.getAttribute)==null?void 0:y.call(g,"data-inline-type"))!==e)return null;const x=g.textContent??"",k=c&&x.startsWith("@")?x.slice(1):x;return{id:L(),type:e,value:"",marks:{},data:{selectedValue:g.getAttribute("data-selected-value")??"",selectedLabel:k}}}function h({id:g}){return a.jsx(gh,{id:g,label:n,placeholder:t,variant:r,options:s,onManage:l,mention:c})}const b={label:n,icon:o??ra,keywords:[n.toLowerCase(),"select","field"],run:(g,{blockId:x,runId:k,sliceStart:y,sliceEnd:I})=>sr(g,{blockId:x,runId:k,sliceStart:y,sliceEnd:I},()=>({id:L(),type:e,value:"",marks:{},data:{selectedValue:"",selectedLabel:"",selectedColor:void 0}}))};return{component:h,isAtomic:!0,toHTML:u,toPlainText:f,fromHTML:p,slashCommand:i.includes("slash")?b:void 0,atCommand:i.includes("at")?b:void 0}}function si(e,n,{onManage:t}={}){for(const r of e.getFieldTypes())n.register(r.id,oi({type:r.id,label:r.label,placeholder:r.placeholder,variant:r.variant,options:r.options??[],onManage:t?()=>t(r.id):void 0}))}function ai(){const e=W(),n=We(),t=El(),{openEdit:r}=Yr(),o=d.useRef([]);d.useEffect(()=>{if(!n)return;const s=new Set(t.map(l=>l.id));for(const l of o.current)s.has(l)||n.unregister(l);si(e,n,{onManage:r}),o.current=[...s]},[e,n,t,r])}function xh(){ai();const e=W(),{target:n,close:t}=Yr(),r=n!==null,o=r&&n!=="new",[s,l]=d.useState(""),[i,c]=d.useState([]),[u,f]=d.useState("");d.useEffect(()=>{if(r){if(o){const k=e.getFieldType(n);l((k==null?void 0:k.label)??""),c((k==null?void 0:k.options)??[])}else l(""),c([]);f("")}},[r,o,n,e]);const p=d.useCallback((k,y)=>{c(I=>I.map(w=>w.value===k?{...w,label:y}:w))},[]),h=d.useCallback(k=>{c(y=>y.filter(I=>I.value!==k))},[]),b=d.useCallback(()=>{const k=u.trim();f(""),k&&c(y=>[...y,{value:L(),label:k,color:lt(y.length)}])},[u]),g=d.useCallback(()=>{const k=s.trim();k&&(o?e.applyOperation(_r(n,{label:k,options:i})):e.applyOperation($r({id:L(),label:k,placeholder:"Select…",variant:"tag",options:i})),t())},[e,o,n,s,i,t]),x=d.useCallback(()=>{o&&e.applyOperation(zr(n)),t()},[e,o,n,t]);return a.jsxs(on,{isOpen:r,onClose:t,title:o?"Edit field type":"New field type",children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Name"}),a.jsx("input",{type:"text",value:s,onChange:k=>l(k.target.value),placeholder:"e.g. Priority, Status…",autoFocus:!0})]}),a.jsxs("div",{className:"be-modal-field",children:[a.jsx("span",{children:"Options"}),i.map((k,y)=>a.jsxs("div",{className:"be-table-header-menu-option-row",children:[a.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(k.color??lt(y)).bg},"aria-hidden":"true"}),a.jsx("input",{className:"be-table-header-menu-option-input",value:k.label,onChange:I=>p(k.value,I.target.value),"aria-label":`Rename option ${k.label}`}),a.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>h(k.value),"aria-label":`Remove option ${k.label}`,children:a.jsx(zn,{size:14})})]},k.value)),a.jsxs("div",{className:"be-table-header-menu-option-row",children:[a.jsx("input",{className:"be-table-header-menu-option-input",value:u,onChange:k=>f(k.target.value),placeholder:"New option…",onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),b())}}),a.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:b,"aria-label":"Add option",children:"+"})]})]}),a.jsxs("div",{className:"be-modal-actions",children:[o&&a.jsx("button",{type:"button",className:"be-modal-delete",onClick:x,children:"Delete field type"}),a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:t,children:"Cancel"}),a.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:"Save"})]})]})}exports.APP_MIME=zt;exports.BlockChildren=hn;exports.BlockErrorBoundary=da;exports.BlockGutterRow=ma;exports.BlockRangeActionMenu=Ef;exports.BlockRegistry=Ns;exports.BlockRenderer=to;exports.COLUMN_TYPES=ya;exports.DEFAULT_COLUMN_TYPE=er;exports.DEFAULT_COLUMN_WIDTH=nr;exports.DocumentExportButton=Gf;exports.EditableBlockContent=sn;exports.EditorProvider=zi;exports.EditorStore=Hr;exports.EditorTrailingSpace=Vf;exports.FieldTypeEditorModal=xh;exports.FloatingToolbar=bh;exports.History=Di;exports.InlineRegistry=Os;exports.LAYOUT_BLOCKS=kl;exports.MIN_COLUMN_WIDTH=Pt;exports.MobileActionBar=Kf;exports.MobileBlockOptionsSheet=Xl;exports.MobileBlockPickerSheet=Vl;exports.Modal=on;exports.Select=In;exports.SlashMenu=Qf;exports.TABLE_BLOCKS=xl;exports.TABLE_SELECT_INLINE_TYPES=Bl;exports.TableHeaderRow=Na;exports.VoiceListeningIndicator=hf;exports.VoicePermissionModal=ff;exports.blankRunForType=va;exports.blockquoteBlockType=Ua;exports.buttonBlockType=qa;exports.calloutBlockType=Fa;exports.checkboxInlineType=Cl;exports.codeBlockType=Ka;exports.convertRunToType=wa;exports.copyBlockRangeToClipboard=Ar;exports.createBlockRegistry=Pi;exports.createCellForColumn=tr;exports.createDefaultColumns=co;exports.createInlineRegistry=$i;exports.createSelectFieldType=oi;exports.dateInlineType=Il;exports.deleteBlockAndFocusSibling=Qt;exports.deleteBlockRange=st;exports.deleteColumn=Sa;exports.deleteEntireDocument=Ht;exports.deleteOverBlockRange=xo;exports.deleteRow=Ca;exports.deleteRunRangeInBlock=go;exports.deserializeClipboard=Dl;exports.dividerBlockType=za;exports.duplicateBlock=ao;exports.embedBlockType=Ja;exports.emojiInlineType=Rl;exports.ensureRootNonEmpty=Un;exports.exportDocumentHTML=Gl;exports.exportDocumentJSON=Wl;exports.exportDocumentSimpleJSON=ti;exports.exportDocumentText=Zl;exports.focusRunAtOffset=Ke;exports.focusRunEnd=xe;exports.focusRunStart=Ut;exports.getMarksSummaryOverBlockRange=vo;exports.getMarksSummaryOverSelection=yo;exports.headingBlockType=ua;exports.importDocumentSimpleJSON=qf;exports.injectDefaultStyles=Ls;exports.insertColumnAfter=$t;exports.insertRowAfter=uo;exports.isEntireBlockRangeHidden=_l;exports.isEntireBlockSelected=Kl;exports.layoutBlockType=_a;exports.layoutColumnBlockType=$a;exports.listItemBlockType=ka;exports.listVoiceCommands=af;exports.moveBlockDown=io;exports.moveBlockRangeDown=$l;exports.moveBlockRangeUp=Pl;exports.moveBlockUp=lo;exports.operations=Li;exports.paragraphBlockType=ca;exports.registerBlocks=gl;exports.registerBuiltInBlocks=Lp;exports.registerBuiltInInlineTypes=nf;exports.registerInlineTypes=Tl;exports.registerStoredFieldTypes=si;exports.remapSubtreeIds=so;exports.renameColumn=Ra;exports.reorderBlockRangeFromStore=gf;exports.resolveCollapsedCaret=nn;exports.resolveColumns=De;exports.resolveCrossBlockSelection=Dn;exports.resolveMultiRunSelection=Hn;exports.resolveRunSelection=Cc;exports.selectInlineType=vl;exports.serializeBlockRange=ft;exports.setBlockRangeHidden=zl;exports.setColumnOptions=Lt;exports.setColumnType=Ta;exports.setColumnWidth=ja;exports.setMarksOverBlockRange=Ft;exports.setMarksOverSelection=_n;exports.tableBlockType=Aa;exports.tableCellBlockType=La;exports.tableRowBlockType=Ma;exports.tableSelectInlineType=jl;exports.textToParagraphs=mo;exports.toggleHeadingBlockType=Va;exports.toggleMarkOnRunRange=jf;exports.toggleMarkOverBlockRange=Io;exports.toggleMarkOverSelection=wo;exports.useAtMenuTrigger=dh;exports.useBlock=be;exports.useBlockChildren=no;exports.useBlockClassName=ve;exports.useBlockRangeDrag=Mf;exports.useBlockRangeSelection=ut;exports.useBlockRegistry=dn;exports.useCaretRect=Ml;exports.useClipboardHandlers=yf;exports.useCoarsePointer=Co;exports.useEditorKeyboardShortcuts=Bf;exports.useEditorStore=W;exports.useEmojiMenuTrigger=ch;exports.useFieldTypeEditor=Yr;exports.useFieldTypes=El;exports.useFloatingToolbarTrigger=mh;exports.useHistory=Nl;exports.useInlineRegistry=We;exports.usePreviewMode=Ur;exports.useRegisterFieldTypes=ai;exports.useRun=pn;exports.useSelectedBlock=rn;exports.useSlashMenuTrigger=rh;exports.useTextFormattingActions=So;exports.useVirtualKeyboardInset=rr;exports.useVoiceTyping=pf;exports.useWholeDocumentSelection=Fr;exports.walkDomToBlocks=Al;
|
|
2532
|
+
${o}`:r}function Ip(e,t){if(e.tagName!=="DETAILS")return null;const n=[...e.children].find(d=>d.tagName==="SUMMARY"),r=n==null?void 0:n.querySelector("h1,h2,h3,h4,h5,h6"),o=r?Math.min(6,Math.max(1,Number(r.tagName[1]))):2,s=r?Fe(r,t):[{id:N(),type:"text",value:"",marks:{}}],l=N(),i=[],c=[],u=[];for(const d of e.children){if(d===n||d.tagName!=="P")continue;const h=Fe(d,t),m={id:N(),type:"paragraph",parentId:l,contentIds:h.map(g=>g.id),props:{}};i.push(m),c.push(...h),u.push(m.id)}if(u.length===0){const{block:d,runs:h}=Z("paragraph")(l);i.push(d),c.push(...h),u.push(d.id)}return{block:{id:l,type:"toggleHeading",parentId:null,contentIds:u,props:{level:o,collapsed:!e.hasAttribute("open"),titleRunIds:s.map(d=>d.id)}},runs:[...s,...c],subtreeBlocks:i}}const ya={component:kp,isLeaf:!1,defaultProps:{level:2,collapsed:!1,titleRunIds:[]},toHTML:vp,toPlainText:wp,fromHTML:Ip,slashCommands:[1,2,3].map(e=>({label:`Toggle heading ${e}`,icon:Ct,keywords:["toggle","heading","collapse","section"],run:(t,n)=>Ee(t,n,yp({level:e}))}))},Nr=[{label:"Blue",value:"#2b6fd6"},{label:"Green",value:"#2f9e44"},{label:"Red",value:"#e03131"},{label:"Purple",value:"#9c36b5"},{label:"Gray",value:"#495057"},{label:"Black",value:"#1a1a1a"}];function Cp(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Sp({isOpen:e,onClose:t,store:n,blockId:r}){const[o,s]=p.useState(""),[l,i]=p.useState(""),[c,u]=p.useState(Nr[0].value),[f,d]=p.useState([{key:"",value:""}]);p.useEffect(()=>{var I,w,j;if(!e)return;const x=n.getBlock(r);if(!x)return;const k=x.contentIds.map(S=>{var v;return((v=n.getRun(S))==null?void 0:v.value)??""}).join(""),y=((I=x.props)==null?void 0:I.customAttrs)??[];s(k),i(((w=x.props)==null?void 0:w.href)??""),u(((j=x.props)==null?void 0:j.color)??Nr[0].value),d([...y,{key:"",value:""}])},[e,r,n]);const h=p.useCallback((x,k)=>{d(y=>{const I=y.map((j,S)=>S===x?{...j,...k}:j),w=I[I.length-1];return(w.key.trim()||w.value.trim())&&I.push({key:"",value:""}),I})},[]),m=p.useCallback(x=>{d(k=>k.filter((y,I)=>I!==x))},[]),g=p.useCallback(()=>{const x={id:N(),type:"text",value:o,marks:{}},k=f.filter(y=>y.key.trim());Cp(n,[_e(r,[x]),X(r,{href:l.trim(),color:c,customAttrs:k})]),t()},[n,r,o,l,c,f,t]);return a.jsxs(at,{isOpen:e,onClose:t,title:"Edit button",children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Label"}),a.jsx("input",{type:"text",value:o,onChange:x=>s(x.target.value),placeholder:"Button"})]}),a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Link URL"}),a.jsx("input",{type:"url",value:l,onChange:x=>i(x.target.value),placeholder:"https://example.com"})]}),a.jsxs("div",{className:"be-modal-field",children:[a.jsx("span",{children:"Color"}),a.jsx("div",{className:"be-modal-color-row",children:Nr.map(x=>a.jsx("button",{type:"button",className:`be-modal-color-swatch${c===x.value?" be-modal-color-swatch-active":""}`,style:{backgroundColor:x.value},title:x.label,"aria-label":x.label,onClick:()=>u(x.value)},x.value))})]}),a.jsxs("div",{className:"be-modal-field",children:[a.jsx("span",{children:"Custom attributes"}),f.map((x,k)=>a.jsxs("div",{className:"be-modal-attr-row",children:[a.jsx("input",{type:"text",placeholder:"name",value:x.key,onChange:y=>h(k,{key:y.target.value})}),a.jsx("input",{type:"text",placeholder:"value",value:x.value,onChange:y=>h(k,{value:y.target.value})}),(x.key||x.value)&&a.jsx("button",{type:"button",className:"be-modal-attr-remove",onClick:()=>m(k),"aria-label":"Remove attribute",children:a.jsx(en,{size:14})})]},k))]}),a.jsxs("div",{className:"be-modal-actions",children:[a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:t,children:"Cancel"}),a.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:"Save"})]})]})}const Tp="#2b6fd6";function Rp({id:e}){var I,w,j,S;const t=q(),n=he(e),{setSelectedBlockId:r}=lt(),[o,s]=p.useState(!1),l=p.useCallback(()=>{nn(t,e,(n==null?void 0:n.contentIds)??[],Z("paragraph"))},[t,e,n]),i=p.useCallback(()=>{const v=Tn(t,e);on(t,v,e,r)},[t,e,r]),c=p.useCallback(()=>Le(t,e,"up"),[t,e]),u=p.useCallback(()=>Le(t,e,"down"),[t,e]),f=p.useCallback(()=>{var R;const v=(R=n==null?void 0:n.props)==null?void 0:R.href;v&&window.open(v,"_blank","noopener,noreferrer")},[(I=n==null?void 0:n.props)==null?void 0:I.href]),d=we("be-button-block",n);if(!n)return null;const h=((w=n.props)==null?void 0:w.href)??"",m=((j=n.props)==null?void 0:j.color)??Tp,g=((S=n.props)==null?void 0:S.customAttrs)??[],x=Ne(t,n.contentIds),k={};for(const{key:v,value:R}of g)v.trim()&&(k[`data-${v.trim()}`]=R);const y=ot(t,n);return a.jsxs("div",{className:d,"data-block-id":e,dir:y,children:[a.jsxs("div",{className:"be-button-block-pill",style:{backgroundColor:m},...k,children:[a.jsx("span",{className:"be-button-block-label","data-empty":x?"":void 0,"data-placeholder":"Button",children:a.jsx(it,{blockId:e,runIds:n.contentIds,dir:y,onEnter:l,onBackspaceAtStart:i,onArrowUp:c,onArrowDown:u})}),a.jsx("button",{type:"button",className:"be-button-block-open",onClick:f,disabled:!h,title:h||"No link set","aria-label":"Open link",children:"↗"}),a.jsx("button",{type:"button",className:"be-button-block-settings",onClick:()=>s(!0),"aria-label":"Edit button",title:"Edit label, link, color…",children:"⚙"})]}),a.jsx(Sp,{isOpen:o,onClose:()=>s(!1),store:t,blockId:e})]})}function jp({href:e="",label:t="Button",color:n="",customAttrs:r=[]}={}){return function(s,l){const i=N(),c=l!=null&&l.length?l:[{id:N(),type:"text",value:t,marks:{}}];return{block:{id:i,type:"button",parentId:s,contentIds:c.map(u=>u.id),props:{href:e,color:n,customAttrs:r}},runs:c}}}const va="be-button-block-link";function Bp(e,t){var c,u,f;const n=e.contentIds.map(d=>t.store.getRun(d)),r=((c=e.props)==null?void 0:c.href)??"",o=(u=e.props)==null?void 0:u.color,s=o?` style="background-color:${Be(o)}"`:"",i=(((f=e.props)==null?void 0:f.customAttrs)??[]).filter(d=>{var h;return(h=d.key)==null?void 0:h.trim()}).map(d=>` data-${Be(d.key.trim())}="${Be(d.value??"")}"`).join("");return`<a class="${va}" href="${Be(r)}"${s}${i}>${n.map(d=>ct(d,t)).join("")}</a>`}function Ep(e,t){return e.contentIds.map(n=>kt(t.store.getRun(n),t)).join("")}function Lp(e,t){var s;if(e.tagName!=="A"||!e.classList.contains(va))return null;const n=Fe(e,t),r=[];for(const l of e.attributes)l.name.startsWith("data-")&&r.push({key:l.name.slice(5),value:l.value});return{block:{id:N(),type:"button",parentId:null,contentIds:n.map(l=>l.id),props:{href:e.getAttribute("href")??"",color:((s=e.style)==null?void 0:s.backgroundColor)||void 0,customAttrs:r}},runs:n}}const wa={component:Rp,isLeaf:!0,defaultProps:{href:"",color:"",customAttrs:[]},toHTML:Bp,toPlainText:Ep,fromHTML:Lp,slashCommand:{label:"Button",icon:iu,keywords:["button","link","cta","action"],run:(e,t)=>Ee(e,t,jp())}};function Es(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>n(r.error),r.readAsDataURL(e)})}const Pn={image:"image",video:"video",audio:"audio",file:"file"},Op={image:"image/*",video:"video/*",audio:"audio/*",file:"*/*"},Ia=20,Ca=100,_p=[{value:"left",Icon:yl,label:"Align left"},{value:"center",Icon:Gc,label:"Align center"},{value:"right",Icon:vl,label:"Align right"}];function Np(e){return Math.min(Ca,Math.max(Ia,Math.round(e)))}function Mp({kind:e,src:t,name:n,alt:r}){return e==="image"?a.jsx("img",{className:"be-embed-image",src:t,alt:r||""}):e==="video"?a.jsx("video",{className:"be-embed-video",src:t,controls:!0}):e==="audio"?a.jsx("audio",{className:"be-embed-audio",src:t,controls:!0}):a.jsxs("a",{className:"be-embed-file-link",href:t,download:n||void 0,target:"_blank",rel:"noopener noreferrer",children:[a.jsx(hl,{size:14})," ",n||t]})}function Ap({id:e}){var se;const t=q(),n=he(e),[r,o]=p.useState(""),[s,l]=p.useState(!1),[i,c]=p.useState(null),[u,f]=p.useState(!1),[d,h]=p.useState(""),m=p.useRef(null),g=p.useRef(null),x=p.useCallback(H=>t.applyOperation(X(e,H)),[t,e]),k=p.useCallback(()=>{var H;h(((H=n==null?void 0:n.props)==null?void 0:H.alt)??""),f(!0)},[(se=n==null?void 0:n.props)==null?void 0:se.alt]),y=p.useCallback(()=>f(!1),[]),I=p.useCallback(H=>{H.preventDefault(),x({alt:d.trim()}),f(!1)},[d,x]),w=p.useCallback(async H=>{var re;const Q=(re=H.target.files)==null?void 0:re[0];if(!Q)return;const ee=await Es(Q);x({src:ee,name:Q.name,mimeType:Q.type})},[x]),j=p.useCallback(async H=>{var re;H.preventDefault(),l(!1);const Q=(re=H.dataTransfer.files)==null?void 0:re[0];if(!Q)return;const ee=await Es(Q);x({src:ee,name:Q.name,mimeType:Q.type})},[x]),S=p.useCallback(H=>{H.preventDefault(),l(!0)},[]),v=p.useCallback(()=>l(!1),[]),R=p.useCallback(()=>{const H=r.trim();H&&(x({src:H,name:H}),o(""))},[r,x]),_=p.useCallback(()=>x({src:"",name:"",mimeType:""}),[x]),O=p.useCallback(H=>{H.preventDefault();const Q=m.current,ee=g.current;if(!Q||!ee)return;const re=Q.getBoundingClientRect().width,be=ee.getBoundingClientRect().width,Re=H.clientX,le=P=>Np((be+(P.clientX-Re))/re*100),ke=P=>c(le(P)),fe=P=>{document.removeEventListener("mousemove",ke),document.removeEventListener("mouseup",fe),x({width:le(P)}),c(null)};document.addEventListener("mousemove",ke),document.addEventListener("mouseup",fe)},[x]),C=we("be-embed",n);if(!n)return null;const{kind:B="file",src:M,name:z,alt:Y="",align:W="left",width:ie=100}=n.props,ae=B==="image"||B==="video",G=i??ie;return a.jsxs("div",{className:C,"data-block-id":e,"data-kind":B,contentEditable:!1,tabIndex:-1,children:[M?a.jsx("div",{ref:m,className:`be-embed-preview be-embed-align-${W}`,children:a.jsxs("div",{ref:g,className:"be-embed-frame",style:ae?{width:`${G}%`}:void 0,children:[a.jsxs("div",{className:"be-embed-toolbar",contentEditable:!1,children:[_p.map(({value:H,Icon:Q,label:ee})=>a.jsx("button",{type:"button",className:`be-embed-toolbar-btn${W===H?" be-embed-toolbar-btn-active":""}`,title:ee,"aria-label":ee,"aria-pressed":W===H,onClick:()=>x({align:H}),children:a.jsx(Q,{size:14})},H)),B==="image"&&a.jsx("button",{type:"button",className:"be-embed-toolbar-btn be-embed-alt-text-btn",onClick:k,children:"Alt text"}),a.jsx("button",{type:"button",className:"be-embed-remove",onClick:_,"aria-label":`Remove ${Pn[B]}`,children:"Remove"})]}),a.jsx(Mp,{kind:B,src:M,name:z,alt:Y}),ae&&a.jsx("div",{className:"be-embed-resize-handle",onMouseDown:O,role:"slider","aria-label":`Resize ${Pn[B]}`,"aria-valuemin":Ia,"aria-valuemax":Ca,"aria-valuenow":G})]})}):a.jsxs("div",{className:`be-embed-dropzone${s?" be-embed-dropzone-active":""}`,onDrop:j,onDragOver:S,onDragLeave:v,children:[a.jsxs("label",{className:"be-embed-upload-btn",children:["Upload ",Pn[B],a.jsx("input",{type:"file",accept:Op[B],onChange:w,hidden:!0})]}),a.jsx("span",{className:"be-embed-dropzone-hint",children:"or drop a file, or paste a URL below"}),a.jsxs("div",{className:"be-embed-url-row",children:[a.jsx("input",{type:"text",className:"be-embed-url-input",placeholder:`https://... ${Pn[B]} URL`,value:r,onChange:H=>o(H.target.value),onKeyDown:H=>H.key==="Enter"&&R()}),a.jsx("button",{type:"button",className:"be-embed-url-commit",onClick:R,children:"Embed"})]})]}),a.jsx(at,{isOpen:u,onClose:y,title:"Alt text",children:a.jsxs("form",{onSubmit:I,children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Describe this image for screen readers"}),a.jsx("input",{type:"text",value:d,onChange:H=>h(H.target.value),placeholder:"e.g. A hand-drawn diagram of the release process",autoFocus:!0})]}),a.jsxs("div",{className:"be-modal-actions",children:[a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:y,children:"Cancel"}),a.jsx("button",{type:"submit",className:"be-modal-save",children:"Save"})]})]})})]})}function Dp({kind:e="file",src:t="",name:n="",alt:r="",mimeType:o="",align:s="left",width:l=100}={}){return function(c){return{block:{id:N(),type:"embed",parentId:c,contentIds:[],props:{kind:e,src:t,name:n,alt:r,mimeType:o,align:s,width:l}},runs:[]}}}const Pp={image:pu,video:fu,audio:hu,file:hl},Sa="be-embed-file-link";function $p(e,t,n){if(e!=="image"&&e!=="video")return"";const r=[];return n!==100&&r.push(`width:${n}%`),t==="center"?r.push("display:block","margin-left:auto","margin-right:auto"):t==="right"&&r.push("display:block","margin-left:auto"),r.length?` style="${r.join(";")}"`:""}function Ls(e){var o,s,l,i;const t=(o=e.style)==null?void 0:o.width,n=t&&t.endsWith("%")?parseInt(t,10):100;let r="left";return((s=e.style)==null?void 0:s.marginLeft)==="auto"&&((l=e.style)==null?void 0:l.marginRight)==="auto"?r="center":((i=e.style)==null?void 0:i.marginLeft)==="auto"&&(r="right"),{align:r,width:Number.isFinite(n)?n:100}}function zp(e){const{kind:t,src:n,name:r,alt:o="",align:s="left",width:l=100}=e.props;if(!n)return"<p></p>";const i=$p(t,s,l);return t==="image"?`<img src="${Be(n)}" alt="${Be(o)}"${i}>`:t==="video"?`<video src="${Be(n)}" controls${i}></video>`:t==="audio"?`<audio src="${Be(n)}" controls></audio>`:`<a class="${Sa}" href="${Be(n)}">${St(r||n)}</a>`}function Hp(e){const{kind:t,src:n,name:r}=e.props;return n?`[${t}: ${r||n}]`:""}function Fp(e){return e.tagName==="IMG"?$n("image",e.getAttribute("src")??"","",{...Ls(e),alt:e.getAttribute("alt")??""}):e.tagName==="VIDEO"?$n("video",e.getAttribute("src")??"","",Ls(e)):e.tagName==="AUDIO"?$n("audio",e.getAttribute("src")??"",""):e.tagName==="A"&&e.classList.contains(Sa)?$n("file",e.getAttribute("href")??"",e.textContent??""):null}function $n(e,t,n,{align:r="left",width:o=100,alt:s=""}={}){return{block:{id:N(),type:"embed",parentId:null,contentIds:[],props:{kind:e,src:t,name:n,alt:s,align:r,width:o}},runs:[]}}function Up(e){return(t,{blockId:n,runId:r,sliceStart:o,sliceEnd:s})=>{const l=t.getRun(r),i=(l==null?void 0:l.value)??"";t.applyOperation(ue(r,{value:i.slice(0,o)+i.slice(s)}));const c=dr(t,n,Dp({kind:e}));return Ze(t,c,Z("paragraph")),c}}const Ta={component:Ap,isLeaf:!0,defaultProps:{kind:"file",src:"",name:"",alt:"",mimeType:"",align:"left",width:100},toHTML:zp,toPlainText:Hp,fromHTML:Fp,slashCommands:["image","video","audio","file"].map(e=>({label:e.charAt(0).toUpperCase()+e.slice(1),icon:Pp[e],keywords:["embed","upload","insert",e],run:Up(e)}))},Ra=8,ja=.5,Yp=.5,Kp=4,Mr=.15,Vp=8;function Ba(e,t){return Math.hypot(e[0]-t[0],e[1]-t[1])}function Kn(e,t,n){return Math.min(n,Math.max(t,e))}function zn(e){return Math.round(e*100)/100}const Ea=.5;function Wp(e){return e.some(([,,t])=>t!==void 0&&t!==Ea)}function Xp(e,{size:t=Ra,thinning:n=ja}={}){const r=t/2,o=e.length;if(!Wp(e))return new Array(o).fill(r);const l=new Array(o);let i=0;for(let u=0;u<o;u+=1){if(u>0){const g=Ba(e[u],e[u-1]);i=i*.8+g*.2}const f=Kn(i/Vp,0,1),d=e[u][2]??Ea,h=.4+.6*Kn(d,0,1),m=Kn(r*h*(1-n*f),r*Mr,r);l[u]=m}const c=Math.min(Kp,Math.floor(o/2));for(let u=0;u<c;u+=1){const f=(u+1)/(c+1),d=Mr+(1-Mr)*f;l[u]*=d,l[o-1-u]*=d}return l}function qp(e,t){const n=e.length;if(n<3||t<=0)return e;const r=new Array(n);r[0]=e[0],r[n-1]=e[n-1];for(let o=1;o<n-1;o+=1){const s=(e[o-1][0]+e[o+1][0])/2,l=(e[o-1][1]+e[o+1][1])/2,i=e[o][0]+(s-e[o][0])*t,c=e[o][1]+(l-e[o][1])*t;r[o]=[i,c,e[o][2]]}return r}function Gp(e,t){const n=e.length,r=new Array(n),o=new Array(n);for(let s=0;s<n;s+=1){const l=e[Math.max(0,s-1)],i=e[Math.min(n-1,s+1)];let c=i[0]-l[0],u=i[1]-l[1];const f=Math.hypot(c,u)||1;c/=f,u/=f;const d=-u,h=c,m=t[s];r[s]=[e[s][0]+d*m,e[s][1]+h*m],o[s]=[e[s][0]-d*m,e[s][1]-h*m]}return{left:r,right:o}}function La(e){if(e.length===0)return"";let t=`M${zn(e[0][0])},${zn(e[0][1])}`;for(let n=1;n<e.length;n+=1)t+=` L${zn(e[n][0])},${zn(e[n][1])}`;return t}function Jp([e,t],n){const o=[];for(let s=0;s<12;s+=1){const l=s/12*Math.PI*2;o.push([e+Math.cos(l)*n,t+Math.sin(l)*n])}return`${La(o)} Z`}function Jn(e,t={}){const{size:n=Ra,thinning:r=ja,smoothing:o=Yp}=t;if(!e||e.length===0)return"";const s=[e[0]];for(let d=1;d<e.length;d+=1)Ba(e[d],s[s.length-1])>.1&&s.push(e[d]);if(s.length===1){const d=s[0][2]??.5,h=n/2*(.4+.6*Kn(d,0,1));return Jp(s[0],h)}const l=Xp(s,{size:n,thinning:r}),i=qp(s,o),{left:c,right:u}=Gp(i,l),f=[...c,...u.slice().reverse()];return`${La(f)} Z`}function Vn(e){if(!e||e.length===0)return{minX:0,minY:0,maxX:0,maxY:0};let t=1/0,n=1/0,r=-1/0,o=-1/0;for(const[s,l]of e)s<t&&(t=s),l<n&&(n=l),s>r&&(r=s),l>o&&(o=l);return{minX:t,minY:n,maxX:r,maxY:o}}function jo(e,t){const n=e.getBoundingClientRect(),r=n.width||1,o=n.height||1,s=Math.min(r/t,o/t),l=(r-t*s)/2,i=(o-t*s)/2;return{rect:n,scale:s,offsetX:l,offsetY:i}}function Ke(e,t,n={x:0,y:0,size:1e3}){const{rect:r,scale:o,offsetX:s,offsetY:l}=jo(t,n.size),i=n.x+(e.clientX-r.left-s)/o,c=n.y+(e.clientY-r.top-l)/o;return[i,c]}function Ar(e,t){return jo(e,t).scale}function Zp(e,t,n,r){const[o,s]=Ke(e,t,n),{rect:l,scale:i,offsetX:c,offsetY:u}=jo(t,r),f=o-(e.clientX-l.left-c)/i,d=s-(e.clientY-l.top-u)/i;return{x:f,y:d}}function Os(e,t){const n=e.x+e.size/2,r=e.y+e.size/2;return{x:n-t/2,y:r-t/2}}function dn(e,t,n=0){return e.minX-n<=t.maxX&&e.maxX+n>=t.minX&&e.minY-n<=t.maxY&&e.maxY+n>=t.minY}function mn(e,t,n,r){const o=Math.min(e,n),s=Math.min(t,r),l=Math.abs(n-e),i=Math.abs(r-t);return{x:o,y:s,width:l,height:i}}function Oa(e,t,n,r,o){const s=o*Math.PI/180,l=Math.cos(s),i=Math.sin(s),c=e-n,u=t-r;return[n+c*l-u*i,r+c*i+u*l]}function _a(e,t,n){return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function Qp(e,t,n){const r=n.width/2,o=n.height/2;if(r===0||o===0)return!1;const s=n.x+r,l=n.y+o,i=(e-s)/r,c=(t-l)/o;return i*i+c*c<=1}function ef(e,t,n,r,o,s){const l=o-n,i=s-r,c=l*l+i*i;if(c===0)return Math.hypot(e-n,t-r);let u=((e-n)*l+(t-r)*i)/c;u=Math.min(1,Math.max(0,u));const f=n+u*l,d=r+u*i;return Math.hypot(e-f,t-d)}function Na(e,t,n,r,o,s,l){return ef(e,t,n,r,o,s)<=l}function Ma(e){const{x:t,y:n,width:r,height:o}=e;return[[t+r/2,n],[t+r,n+o/2],[t+r/2,n+o],[t,n+o/2]]}function Aa(e){const{x:t,y:n,width:r,height:o}=e;return[[t+r/2,n],[t+r,n+o],[t,n+o]]}function Da(e,t=5){const{x:n,y:r,width:o,height:s}=e,l=n+o/2,i=r+s/2,c=o/2,u=s/2,f=.4,d=[],h=Math.PI/t;let m=-Math.PI/2;for(let g=0;g<t*2;g+=1){const x=g%2===0,k=x?c:c*f,y=x?u:u*f;d.push([l+Math.cos(m)*k,i+Math.sin(m)*y]),m+=h}return d}function tf(e,t,n){let r=!1;for(let o=0,s=n.length-1;o<n.length;s=o,o+=1){const[l,i]=n[o],[c,u]=n[s];i>t!=u>t&&e<(c-l)*(t-i)/(u-i)+l&&(r=!r)}return r}function Pa(e,t,n,r,o=24){const s=n-e,l=r-t,i=Math.hypot(s,l),[c,u]=i===0?[1,0]:[s/i,l/i],f=n-c*o,d=r-u*o,h=-u,m=c,g=o/2;return[[n,r],[f+h*g,d+m*g],[f-h*g,d-m*g]]}function nf({compute:e,onCommit:t}){const[n,r]=p.useState(null),o=p.useCallback((s,l)=>{s.preventDefault();const i=u=>r(e(u,l)),c=u=>{document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",c),t(e(u,l)),r(null)};document.addEventListener("mousemove",i),document.addEventListener("mouseup",c)},[e,t]);return{dragValue:n,startDrag:o}}const Bo=480,Eo=320;function rf({strokes:e=[],shapes:t=[],width:n=Bo,height:r=Eo}={}){return function(s){return{block:{id:N(),type:"canvas",parentId:s,contentIds:[],props:{strokes:e,shapes:t,width:n,height:r}},runs:[]}}}const of={diamond:Ma,triangle:Aa,star:Da};function sf(e){const t=e.strokeWidth??8,n=Be(e.color);if(e.type==="arrow"){const i=Math.max(16,t*3),u=Pa(e.x1,e.y1,e.x2,e.y2,i).map(([f,d])=>`${f},${d}`).join(" ");return`<line x1="${e.x1}" y1="${e.y1}" x2="${e.x2}" y2="${e.y2}" stroke="${n}" stroke-width="${t}"></line><polygon points="${u}" fill="${n}"></polygon>`}const r=e.fillColor?Be(e.fillColor):"none";let o;if(e.type==="rectangle")o=`<rect x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}" fill="${r}" stroke="${n}" stroke-width="${t}"></rect>`;else if(e.type==="ellipse"){const i=e.x+e.width/2,c=e.y+e.height/2;o=`<ellipse cx="${i}" cy="${c}" rx="${e.width/2}" ry="${e.height/2}" fill="${r}" stroke="${n}" stroke-width="${t}"></ellipse>`}else if(e.type==="text"){const i=e.fontSize??28,c=St(e.text??"");o=`<foreignObject x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}"><div xmlns="http://www.w3.org/1999/xhtml" style="width:100%;height:100%;overflow:hidden;color:${n};font-size:${i}px;line-height:1.3;white-space:pre-wrap;word-break:break-word;">${c}</div></foreignObject>`}else{const i=of[e.type];if(!i)return"";const c={x:e.x,y:e.y,width:e.width,height:e.height};o=`<polygon points="${i(c).map(([f,d])=>`${f},${d}`).join(" ")}" fill="${r}" stroke="${n}" stroke-width="${t}"></polygon>`}if(!e.rotation)return o;const s=e.x+e.width/2,l=e.y+e.height/2;return`<g transform="rotate(${e.rotation} ${s} ${l})">${o}</g>`}function $a(e){const{strokes:t=[],shapes:n=[],width:r,height:o}=e.props,s=t.map(i=>`<path fill="${Be(i.color)}" d="${Jn(i.points,{size:i.size})}"></path>`).join(""),l=n.map(sf).join("");return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000" width="${r}" height="${o}">${s}${l}</svg>`}const It=1e3,_s="#1a1a1a",za=8,Ns=["#1a1a1a","#e03131","#2f9e44","#1971c2","#f08c00"],lf=2,af=40,cf=24,uf=6,Ms=160,df=120,Dr=.5,Pr=4,Hn=1.1,As=4,Fn=24,pf=1,ff=10,Ds={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},hf=220,bf=60,Yr=28,mf=12,gf=96,Kr=10,Ps=15,$s=Kr*5;function Ae(e){return Math.round(e/Kr)*Kr}function xf(e){return Math.round(e/Ps)*Ps}function kf(){const e=p.useRef(new WeakMap);return t=>{const n=e.current;let r=n.get(t);return r===void 0&&(r=Jn(t.points,{size:t.size}),n.set(t,r)),r}}function yf(e,t,n){return{minX:e-n,minY:t-n,maxX:e+n,maxY:t+n}}function zs(e){let t=0,n=0;for(const o of e.values())t+=o.x,n+=o.y;const r=e.size||1;return{x:t/r,y:n/r}}function vf(e,t,n,r){const o=e.points;if(o.length===1){const[s,l]=o[0];return Math.hypot(t-s,n-l)<=r}for(let s=0;s<o.length-1;s+=1){const[l,i]=o[s],[c,u]=o[s+1];if(Na(t,n,l,i,c,u,r))return!0}return!1}const $r=new Set(["rectangle","ellipse","arrow","diamond","triangle","star"]),Ha={diamond:Ma,triangle:Aa,star:Da},Hs=[{type:"rectangle",label:"Rectangle",Icon:wl},{type:"ellipse",label:"Ellipse",Icon:Zc},{type:"arrow",label:"Arrow",Icon:Qc},{type:"diamond",label:"Diamond",Icon:eu},{type:"triangle",label:"Triangle",Icon:tu},{type:"star",label:"Star",Icon:nu}],Fs=[{mode:"object",label:"Object Eraser",Icon:Il},{mode:"precise",label:"Precise Eraser",Icon:en}];function zr(e,t,n,r){return e.type==="arrow"?{type:"arrow",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,color:t,strokeWidth:n}:{type:e.type,...mn(e.x1,e.y1,e.x2,e.y2),color:t,strokeWidth:n,fillColor:r}}const wf=16;function Fa(e,t,n){for(let r=n.length-1;r>=0;r-=1){const o=n[r];if(o.type==="arrow"){if(Na(e,t,o.x1,o.y1,o.x2,o.y2,wf))return o.id;continue}const s={x:o.x,y:o.y,width:o.width,height:o.height};let[l,i]=[e,t];if(o.rotation){const{cx:f,cy:d}=xr(o);[l,i]=Oa(e,t,f,d,-o.rotation)}const c=Ha[o.type];let u;if(c?u=tf(l,i,c(s)):u=o.type==="ellipse"?Qp(l,i,s):_a(l,i,s),u)return o.id}return null}function pn(e,t,n){return e.type==="arrow"?{...e,x1:e.x1+t,y1:e.y1+n,x2:e.x2+t,y2:e.y2+n}:{...e,x:e.x+t,y:e.y+n}}function wn(e){return e.type==="arrow"?{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x2-e.x1),height:Math.abs(e.y2-e.y1)}:{x:e.x,y:e.y,width:e.width,height:e.height}}function xr(e){const t=wn(e);return{cx:t.x+t.width/2,cy:t.y+t.height/2}}function fn(e,t,n){return{...e,points:e.points.map(([r,o,s])=>[r+t,o+n,s])}}function If(e,t){const n=[];let r=[];for(let o=0;o<e.length;o+=1)t.has(o)?(r.length>0&&n.push(r),r=[]):r.push(e[o]);return r.length>0&&n.push(r),n}function Ua(e){const t=Vn(e.points);return{x:t.minX,y:t.minY,width:t.maxX-t.minX,height:t.maxY-t.minY}}function Cf(e,t){return e==="stroke"?Ua(t):wn(t)}function Us(e,t){var l,i;const n=((l=e==null?void 0:e.props)==null?void 0:l.strokes)??[],r=((i=e==null?void 0:e.props)==null?void 0:i.shapes)??[],o=n.find(c=>c.id===t);if(o)return{kind:"stroke",item:o};const s=r.find(c=>c.id===t);return s?{kind:"shape",item:s}:null}function Sf(e,t,n,r){const o=Fa(e,t,r);if(o)return{kind:"shape",id:o};for(let s=n.length-1;s>=0;s-=1){const l=n[s];if(_a(e,t,Ua(l)))return{kind:"stroke",id:l.id}}return null}const Un=24,hn=14;function Vr(e){return{nw:[e.x,e.y],ne:[e.x+e.width,e.y],sw:[e.x,e.y+e.height],se:[e.x+e.width,e.y+e.height]}}const Tf={nw:"se",ne:"sw",sw:"ne",se:"nw"},Rf=32;function Ya(e){const t=wn(e),n=t.x+t.width/2,r=t.y-Rf;if(!e.rotation)return[n,r];const{cx:o,cy:s}=xr(e);return Oa(n,r,o,s,e.rotation)}function jf(e,t,n){if(!n)return null;if(n.type==="arrow")return Math.hypot(e-n.x1,t-n.y1)<=Un?"start":Math.hypot(e-n.x2,t-n.y2)<=Un?"end":null;const[r,o]=Ya(n);if(Math.hypot(e-r,t-o)<=Un)return"rotate";if(n.rotation)return null;for(const[s,[l,i]]of Object.entries(Vr(n)))if(Math.hypot(e-l,t-i)<=Un)return s;return null}function Hr(e,t){return t.mode==="arrow-endpoint"?t.endpoint==="start"?{...e,x1:t.x,y1:t.y}:{...e,x2:t.x,y2:t.y}:t.mode==="rotate"?{...e,rotation:t.rotation}:{...e,...mn(t.fixedX,t.fixedY,t.x,t.y)}}function Ys({shape:e,opacity:t=1}){const n=e.strokeWidth??za;let r;if(e.type==="rectangle")r=a.jsx("rect",{x:e.x,y:e.y,width:e.width,height:e.height,fill:e.fillColor??"none",stroke:e.color,strokeWidth:n,opacity:t});else if(e.type==="ellipse")r=a.jsx("ellipse",{cx:e.x+e.width/2,cy:e.y+e.height/2,rx:e.width/2,ry:e.height/2,fill:e.fillColor??"none",stroke:e.color,strokeWidth:n,opacity:t});else if(e.type==="arrow"){const l=Math.max(16,n*3),i=Pa(e.x1,e.y1,e.x2,e.y2,l);return a.jsxs("g",{opacity:t,children:[a.jsx("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:e.color,strokeWidth:n}),a.jsx("polygon",{points:i.map(([c,u])=>`${c},${u}`).join(" "),fill:e.color})]})}else if(e.type==="text")r=a.jsx("foreignObject",{x:e.x,y:e.y,width:e.width,height:e.height,opacity:t,children:a.jsx("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{width:"100%",height:"100%",overflow:"hidden",color:e.color,fontSize:e.fontSize??Yr,lineHeight:1.3,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"inherit"},children:e.text})});else{const l=Ha[e.type];if(!l)return null;const i={x:e.x,y:e.y,width:e.width,height:e.height},c=l(i).map(([u,f])=>`${u},${f}`).join(" ");r=a.jsx("polygon",{points:c,fill:e.fillColor??"none",stroke:e.color,strokeWidth:n,opacity:t})}if(!e.rotation)return r;const{cx:o,cy:s}=xr(e);return a.jsx("g",{transform:`rotate(${e.rotation} ${o} ${s})`,children:r})}function Bf({id:e}){const t=q(),n=he(e),r=we("be-canvas",n),o=kf(),[s,l]=p.useState("pen"),[i,c]=p.useState("object"),[u,f]=p.useState(_s),[d,h]=p.useState(za),[m,g]=p.useState(null),[x,k]=p.useState(!0),[y,I]=p.useState(Yr),[w,j]=p.useState("rectangle"),[S,v]=p.useState(!1),[R,_]=p.useState(!1),[O,C]=p.useState(!1),[B,M]=p.useState(!1),[z,Y]=p.useState(!1),[W,ie]=p.useState(!1),ae=p.useRef(null),G=p.useRef(null),se=p.useRef(null),H=p.useRef(null),Q=p.useRef(null),ee=p.useRef(null),re=p.useRef(null),be=p.useRef(null),Re=p.useRef(null),le=p.useRef(null),ke=p.useRef(null),fe=p.useRef(null),P=p.useMemo(()=>[ae,G],[]),Ie=p.useMemo(()=>[se,H],[]),Ue=p.useMemo(()=>[Q,ee],[]),jn=p.useMemo(()=>[re,be],[]),yr=p.useMemo(()=>[Re,le],[]),Wi=p.useMemo(()=>[ke,fe],[]),Fo=p.useCallback(()=>v(!1),[]),vr=p.useCallback(()=>_(!1),[]),Xi=p.useCallback(()=>C(!1),[]),Uo=p.useCallback(()=>M(!1),[]),qi=p.useCallback(()=>Y(!1),[]),Yo=p.useCallback(()=>ie(!1),[]);He(P,S,Fo),He(Ie,R,vr),He(Ue,O,Xi),He(jn,B,Uo),He(yr,z,qi),He(Wi,W,Yo);const Ye=p.useRef(null),ln=p.useRef([]),jt=p.useRef(!1),Bt=p.useRef(null),[Ko,Vo]=p.useState(null),dt=p.useRef(new Set),yt=p.useRef(new Set),Et=p.useRef(new Map),Lt=p.useRef(!1),Ot=p.useRef(null),[Gi,Wo]=p.useState(()=>new Set),[Ji,Xo]=p.useState(()=>new Set),Pe=p.useRef(null),[qo,wr]=p.useState(null),[te,Qe]=p.useState(()=>new Set),pt=p.useRef(null),[ve,Go]=p.useState(null),ft=p.useRef(null),[an,Jo]=p.useState(null),Ir=p.useRef([]),[de,_t]=p.useState(null),$e=p.useRef(null),[ht,Cr]=p.useState(null),[ce,vt]=p.useState({x:0,y:0,zoom:1}),Oe=It/ce.zoom,wt=p.useRef(null),ze=p.useRef(new Map),bt=p.useRef(null),{dragValue:Nt,startDrag:Zo}=nf({compute:(b,T)=>({width:Math.max(Ms,Math.round(T.startWidth+(b.clientX-T.startX))),height:Math.max(df,Math.round(T.startHeight+(b.clientY-T.startY)))}),onCommit:b=>t.applyOperation(X(e,b))}),Qo=p.useCallback(b=>{Bt.current==null&&(Bt.current=requestAnimationFrame(()=>{Bt.current=null,Vo(Jn(ln.current,{size:b}))}))},[]),Mt=p.useCallback(()=>{jt.current=!1,Bt.current!=null&&(cancelAnimationFrame(Bt.current),Bt.current=null),ln.current=[],Vo(null)},[]),es=p.useCallback(()=>{var L;const b=ln.current;if(b.length===0)return;const T={id:N(),points:b,color:u,size:d},E=((L=n==null?void 0:n.props)==null?void 0:L.strokes)??[];t.applyOperation(X(e,{strokes:[...E,T]}))},[t,e,n,u,d]),ts=p.useCallback(()=>{Ot.current==null&&(Ot.current=requestAnimationFrame(()=>{Ot.current=null,Wo(new Set(dt.current)),Xo(new Set(yt.current))}))},[]),Bn=p.useCallback((b,T)=>{var V,U;const E=i==="precise"?uf:cf,L=yf(b,T,E),D=((V=n==null?void 0:n.props)==null?void 0:V.strokes)??[];for(const $ of D){if(i==="precise"){const et=Vn($.points);if(!dn(et,L,$.size/2))continue;let Ce=Et.current.get($.id);$.points.forEach(([je,Se],pe)=>{Ce!=null&&Ce.has(pe)||Math.hypot(je-b,Se-T)>E||(Ce||(Ce=new Set,Et.current.set($.id,Ce)),Ce.add(pe))}),Ce!=null&&Ce.size&&dt.current.add($.id);continue}if(dt.current.has($.id))continue;const K=$.size/2,ne=Vn($.points);dn(ne,L,K)&&vf($,b,T,E+K)&&dt.current.add($.id)}const A=((U=n==null?void 0:n.props)==null?void 0:U.shapes)??[];for(const $ of A){if(yt.current.has($.id))continue;const K=wn($),ne={minX:K.x,minY:K.y,maxX:K.x+K.width,maxY:K.y+K.height};dn(ne,L)&&yt.current.add($.id)}ts()},[n,i,ts]),At=p.useCallback(()=>{Lt.current=!1,Ot.current!=null&&(cancelAnimationFrame(Ot.current),Ot.current=null),dt.current=new Set,yt.current=new Set,Et.current=new Map,Wo(new Set),Xo(new Set)},[]),ns=p.useCallback(()=>{var A,V;const b=i!=="precise"&&dt.current.size>0,T=i==="precise"&&Et.current.size>0;if(!b&&!T&&yt.current.size===0)return;const E=((A=n==null?void 0:n.props)==null?void 0:A.strokes)??[],L=((V=n==null?void 0:n.props)==null?void 0:V.shapes)??[];let D;if(b)D=E.filter(U=>!dt.current.has(U.id));else if(T){D=[];for(const U of E){const $=Et.current.get(U.id);if(!$||$.size===0){D.push(U);continue}If(U.points,$).forEach((K,ne)=>{D.push({...U,id:ne===0?U.id:N(),points:K})})}}else D=E;t.applyOperation(X(e,{strokes:D,shapes:L.filter(U=>!yt.current.has(U.id))}))},[t,e,n,i]),Dt=p.useCallback(()=>{Pe.current=null,wr(null)},[]),rs=p.useCallback(()=>{var L;const b=Pe.current;if(!b)return;if(b.type==="arrow"){if(b.x1===b.x2&&b.y1===b.y2)return}else{const D=mn(b.x1,b.y1,b.x2,b.y2);if(D.width===0||D.height===0)return}const T={id:N(),...zr(b,u,d,m)},E=((L=n==null?void 0:n.props)==null?void 0:L.shapes)??[];t.applyOperation(X(e,{shapes:[...E,T]}))},[t,e,n,u,d,m]),Pt=p.useCallback(()=>{pt.current=null,Go(null)},[]),os=p.useCallback(()=>{var V,U;const b=pt.current;if(!b||b.dx===0&&b.dy===0)return;const T=new Set(b.ids),E=((V=n==null?void 0:n.props)==null?void 0:V.strokes)??[],L=((U=n==null?void 0:n.props)==null?void 0:U.shapes)??[],D=E.map($=>T.has($.id)?fn($,b.dx,b.dy):$),A=L.map($=>T.has($.id)?pn($,b.dx,b.dy):$);t.applyOperation(X(e,{strokes:D,shapes:A}))},[t,e,n]),$t=p.useCallback(()=>{ft.current=null,Jo(null)},[]),ss=p.useCallback(()=>{var V,U;const b=ft.current;if(!b)return;const T=mn(b.startX,b.startY,b.x,b.y);if(T.width<As&&T.height<As){Qe(new Set);return}const E={minX:T.x,minY:T.y,maxX:T.x+T.width,maxY:T.y+T.height},L=((V=n==null?void 0:n.props)==null?void 0:V.strokes)??[],D=((U=n==null?void 0:n.props)==null?void 0:U.shapes)??[],A=[];for(const $ of L)dn(Vn($.points),E)&&A.push($.id);for(const $ of D){const K=wn($),ne={minX:K.x,minY:K.y,maxX:K.x+K.width,maxY:K.y+K.height};dn(ne,E)&&A.push($.id)}Qe(new Set(A))},[n]),Sr=p.useCallback(()=>{te.size!==0&&(Ir.current=[...te].map(b=>Us(n,b)).filter(Boolean))},[n,te]),Tr=p.useCallback(()=>{var V,U;const b=Ir.current;if(b.length===0)return;const T=((V=n==null?void 0:n.props)==null?void 0:V.strokes)??[],E=((U=n==null?void 0:n.props)==null?void 0:U.shapes)??[],L=[],D=[],A=[];for(const{kind:$,item:K}of b){const ne=N();A.push(ne),$==="stroke"?L.push({...fn(K,Fn,Fn),id:ne}):D.push({...pn(K,Fn,Fn),id:ne})}t.applyOperation(X(e,{strokes:[...T,...L],shapes:[...E,...D]})),Qe(new Set(A)),l("select")},[t,e,n]),zt=p.useCallback(b=>{var D,A;if(te.size===0)return;const T=V=>{const U=V.filter(K=>te.has(K.id));if(U.length===0)return V;const $=V.filter(K=>!te.has(K.id));return b?[...$,...U]:[...U,...$]},E=((D=n==null?void 0:n.props)==null?void 0:D.strokes)??[],L=((A=n==null?void 0:n.props)==null?void 0:A.shapes)??[];t.applyOperation(X(e,{strokes:T(E),shapes:T(L)}))},[t,e,n,te]),Zi=p.useCallback(()=>zt(!0),[zt]),Qi=p.useCallback(()=>zt(!1),[zt]),Rr=p.useCallback((b,T)=>{_t({id:null,x:b,y:T,width:hf,height:bf,text:"",color:u,fontSize:y})},[u,y]),En=p.useCallback(b=>{_t({id:b.id,x:b.x,y:b.y,width:b.width,height:b.height,text:b.text,color:b.color,fontSize:b.fontSize??Yr})},[]),ec=p.useCallback(()=>{_t(null)},[]),tc=p.useCallback(()=>{var V,U,$;const b=de;if(!b)return;_t(null);const T=((V=n==null?void 0:n.props)==null?void 0:V.shapes)??[],E=b.text;if(!E.trim()){b.id&&(t.applyOperation(X(e,{shapes:T.filter(K=>K.id!==b.id)})),Qe(new Set)),(U=Ye.current)==null||U.focus();return}const L=b.id??N(),D={id:L,type:"text",x:b.x,y:b.y,width:b.width,height:b.height,text:E,color:b.color,fontSize:b.fontSize},A=b.id?T.map(K=>K.id===b.id?D:K):[...T,D];t.applyOperation(X(e,{shapes:A})),Qe(new Set([L])),l("select"),($=Ye.current)==null||$.focus()},[t,e,n,de]),Ht=p.useCallback(()=>{$e.current=null,Cr(null)},[]),ls=p.useCallback(()=>{var A;const b=$e.current;if(!b)return;const T=((A=n==null?void 0:n.props)==null?void 0:A.shapes)??[],E=T.find(V=>V.id===b.shapeId);if(!E)return;const L=Hr(E,b);if(L.type!=="arrow"&&(L.width===0||L.height===0))return;const D=T.map(V=>V.id===b.shapeId?L:V);t.applyOperation(X(e,{shapes:D}))},[t,e,n]),as=p.useCallback(b=>{var E;const T=Ye.current;if((E=T==null?void 0:T.hasPointerCapture)!=null&&E.call(T,b)&&T.releasePointerCapture(b),Pe.current){Dt();return}if(pt.current){Pt();return}if(ft.current){$t();return}if($e.current){Ht();return}if(jt.current){Mt();return}Lt.current&&At()},[Dt,Pt,$t,Ht,Mt,At]),nc=p.useCallback(b=>{var L,D,A,V,U;if(b.key==="Backspace"||b.key==="Delete"){if(te.size===0)return;b.preventDefault();const $=((L=n==null?void 0:n.props)==null?void 0:L.strokes)??[],K=((D=n==null?void 0:n.props)==null?void 0:D.shapes)??[];t.applyOperation(X(e,{strokes:$.filter(ne=>!te.has(ne.id)),shapes:K.filter(ne=>!te.has(ne.id))})),Qe(new Set);return}if(Ds[b.key]&&!b.ctrlKey&&!b.metaKey){if(te.size===0)return;b.preventDefault();const $=b.shiftKey?ff:pf,[K,ne]=Ds[b.key],et=K*$,Ce=ne*$,je=((A=n==null?void 0:n.props)==null?void 0:A.strokes)??[],Se=((V=n==null?void 0:n.props)==null?void 0:V.shapes)??[];t.applyOperation(X(e,{strokes:je.map(pe=>te.has(pe.id)?fn(pe,et,Ce):pe),shapes:Se.map(pe=>te.has(pe.id)?pn(pe,et,Ce):pe)}));return}if(b.key==="Enter"&&!b.ctrlKey&&!b.metaKey){if(te.size!==1)return;const[$]=te,K=(((U=n==null?void 0:n.props)==null?void 0:U.shapes)??[]).find(ne=>ne.id===$&&ne.type==="text");if(!K)return;b.preventDefault(),En(K);return}if(!(b.ctrlKey||b.metaKey))return;const E=b.key.toLowerCase();if(E==="c"){if(te.size===0)return;b.preventDefault(),Sr()}else if(E==="v"){if(Ir.current.length===0)return;b.preventDefault(),Tr()}else if(E==="d"){if(te.size===0)return;b.preventDefault(),Sr(),Tr()}else if(b.shiftKey&&(E==="]"||E==="[")){if(te.size===0)return;b.preventDefault(),zt(E==="]")}},[t,e,n,te,Sr,Tr,zt,En]),mt={x:ce.x,y:ce.y,size:Oe},jr=p.useCallback(b=>{const T=Ye.current;if(!T)return;if(b.preventDefault(),b.ctrlKey||b.metaKey){vt(L=>{const D=b.deltaY<0?Hn:1/Hn,A=Math.min(Pr,Math.max(Dr,L.zoom*D)),V=It/A,{x:U,y:$}=Zp(b,T,{x:L.x,y:L.y,size:It/L.zoom},V);return{x:U,y:$,zoom:A}});return}const E=Ar(T,Oe);vt(L=>({...L,x:L.x+b.deltaX/E,y:L.y+b.deltaY/E}))},[Oe]);p.useEffect(()=>{const b=Ye.current;if(b)return b.addEventListener("wheel",jr,{passive:!1}),()=>b.removeEventListener("wheel",jr)},[jr]);const rc=p.useCallback(()=>{vt(b=>{const T=Math.min(Pr,b.zoom*Hn),E=It/T,{x:L,y:D}=Os({x:b.x,y:b.y,size:It/b.zoom},E);return{x:L,y:D,zoom:T}})},[]),oc=p.useCallback(()=>{vt(b=>{const T=Math.max(Dr,b.zoom/Hn),E=It/T,{x:L,y:D}=Os({x:b.x,y:b.y,size:It/b.zoom},E);return{x:L,y:D,zoom:T}})},[]),sc=p.useCallback(()=>{vt({x:0,y:0,zoom:1})},[]),lc=p.useCallback(()=>{if(!n)return;const b=$a(n),T=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(b)}`,E=new Image;E.onload=()=>{const L=document.createElement("canvas");L.width=n.props.width,L.height=n.props.height;const D=L.getContext("2d");if(!D)return;D.drawImage(E,0,0,L.width,L.height);const A=document.createElement("a");A.href=L.toDataURL("image/png"),A.download="canvas.png",document.body.appendChild(A),A.click(),document.body.removeChild(A)},E.src=T},[n]),ac=p.useCallback(b=>{var U;if(s!=="select")return;const T=Ye.current;if(!T)return;const[E,L]=Ke(b,T,{x:ce.x,y:ce.y,size:Oe}),D=((U=n==null?void 0:n.props)==null?void 0:U.shapes)??[],A=Fa(E,L,D),V=D.find($=>$.id===A);(V==null?void 0:V.type)==="text"&&(Qe(new Set([V.id])),En(V))},[s,ce.x,ce.y,Oe,n,En]),ic=p.useCallback(b=>{var D,A,V,U,$,K,ne,et,Ce;const T=Ye.current;if(!T)return;if(b.pointerType==="touch"&&(ze.current.set(b.pointerId,{x:b.clientX,y:b.clientY}),ze.current.size>=2)){if(b.preventDefault(),(D=T.setPointerCapture)==null||D.call(T,b.pointerId),!bt.current){for(const Se of ze.current.keys())Se!==b.pointerId&&as(Se);const je=zs(ze.current);bt.current={startCenterX:je.x,startCenterY:je.y,startViewX:ce.x,startViewY:ce.y}}return}if(de){if((V=(A=b.target)==null?void 0:A.closest)!=null&&V.call(A,".be-canvas-text-editor"))return;if(($=(U=document.activeElement)==null?void 0:U.blur)==null||$.call(U),s==="text"){let[je,Se]=Ke(b,T,mt);x&&([je,Se]=[Ae(je),Ae(Se)]),Rr(je,Se),l("text");return}}if(b.button===1){b.preventDefault(),(K=T.setPointerCapture)==null||K.call(T,b.pointerId),wt.current={startClientX:b.clientX,startClientY:b.clientY,startViewX:ce.x,startViewY:ce.y};return}if(!b.isPrimary||b.button!==void 0&&b.button!==0)return;b.preventDefault(),(ne=T.setPointerCapture)==null||ne.call(T,b.pointerId);const[E,L]=Ke(b,T,mt);if(s==="eraser")dt.current=new Set,yt.current=new Set,Et.current=new Map,Lt.current=!0,Bn(E,L);else if($r.has(s)){const je=x?Ae(E):E,Se=x?Ae(L):L;Pe.current={type:s,x1:je,y1:Se,x2:je,y2:Se},wr(zr(Pe.current,u,d,m))}else if(s==="select"){const je=((et=n==null?void 0:n.props)==null?void 0:et.strokes)??[],Se=((Ce=n==null?void 0:n.props)==null?void 0:Ce.shapes)??[],pe=te.size===1?Se.find(tt=>te.has(tt.id))??null:null,_n=jf(E,L,pe);if(_n){if(_n==="rotate"){const{cx:tt,cy:Ut}=xr(pe),Yt=Math.atan2(L-Ut,E-tt)*180/Math.PI;$e.current={mode:"rotate",shapeId:pe.id,cx:tt,cy:Ut,startAngle:Yt,startRotation:pe.rotation??0,rotation:pe.rotation??0}}else if(pe.type==="arrow")$e.current={mode:"arrow-endpoint",shapeId:pe.id,endpoint:_n,x:E,y:L};else{const[tt,Ut]=Vr(pe)[Tf[_n]];$e.current={mode:"rect-corner",shapeId:pe.id,fixedX:tt,fixedY:Ut,x:E,y:L}}Cr(Hr(pe,$e.current));return}const Ft=Sf(E,L,je,Se);if(Ft){if(b.shiftKey){Qe(Ut=>{const Yt=new Set(Ut);return Yt.has(Ft.id)?Yt.delete(Ft.id):Yt.add(Ft.id),Yt});return}const tt=te.has(Ft.id)?te:new Set([Ft.id]);Qe(tt),pt.current={ids:[...tt],startX:E,startY:L,dx:0,dy:0},T.focus()}else ft.current={startX:E,startY:L,x:E,y:L}}else s==="text"?Rr(x?Ae(E):E,x?Ae(L):L):s==="pen"&&(ln.current=[[E,L,b.pressure||.5]],jt.current=!0)},[s,Bn,ce.x,ce.y,Oe,u,d,m,x,n,te,Rr,de,as]),cc=p.useCallback(b=>{var E;const T=Ye.current;if(T){if(b.pointerType==="touch"&&ze.current.has(b.pointerId)&&(ze.current.set(b.pointerId,{x:b.clientX,y:b.clientY}),bt.current)){b.preventDefault();const L=Ar(T,Oe),D=zs(ze.current),{startCenterX:A,startCenterY:V,startViewX:U,startViewY:$}=bt.current,K=(D.x-A)/L,ne=(D.y-V)/L;vt(et=>({...et,x:U-K,y:$-ne}));return}if(wt.current){const L=Ar(T,Oe),{startClientX:D,startClientY:A,startViewX:V,startViewY:U}=wt.current,$=(b.clientX-D)/L,K=(b.clientY-A)/L;vt(ne=>({...ne,x:V-$,y:U-K}));return}if(Pe.current){let[L,D]=Ke(b,T,mt);x&&([L,D]=[Ae(L),Ae(D)]),Pe.current={...Pe.current,x2:L,y2:D},wr(zr(Pe.current,u,d,m));return}if(pt.current){const[L,D]=Ke(b,T,mt),A=pt.current;A.dx=x?Ae(L-A.startX):L-A.startX,A.dy=x?Ae(D-A.startY):D-A.startY,Go({ids:A.ids,dx:A.dx,dy:A.dy});return}if(ft.current){const[L,D]=Ke(b,T,mt),A=ft.current;A.x=L,A.y=D,Jo(mn(A.startX,A.startY,A.x,A.y));return}if($e.current){let[L,D]=Ke(b,T,mt);const A=$e.current;if(A.mode==="rotate"){const $=Math.atan2(D-A.cy,L-A.cx)*180/Math.PI,K=A.startRotation+($-A.startAngle);A.rotation=x?xf(K):K}else x&&([L,D]=[Ae(L),Ae(D)]),A.x=L,A.y=D;const U=(((E=n==null?void 0:n.props)==null?void 0:E.shapes)??[]).find($=>$.id===A.shapeId);U&&Cr(Hr(U,A));return}if(jt.current){const[L,D]=Ke(b,T,mt);ln.current.push([L,D,b.pressure||.5]),Qo(d)}else if(Lt.current){const[L,D]=Ke(b,T,mt);Bn(L,D)}}},[Qo,Bn,ce.x,ce.y,Oe,d,u,m,x,n]),ye=p.useCallback(b=>{var E;const T=Ye.current;(E=T==null?void 0:T.hasPointerCapture)!=null&&E.call(T,b.pointerId)&&T.releasePointerCapture(b.pointerId)},[]),uc=p.useCallback(b=>{if(b.pointerType==="touch"&&(ze.current.delete(b.pointerId),bt.current)){ye(b),ze.current.size<2&&(bt.current=null);return}if(wt.current){ye(b),wt.current=null;return}if(Pe.current){ye(b),rs(),Dt();return}if(pt.current){ye(b),os(),Pt();return}if(ft.current){ye(b),ss(),$t();return}if($e.current){ye(b),ls(),Ht();return}jt.current?(ye(b),es(),Mt()):Lt.current&&(ye(b),ns(),At())},[ye,rs,Dt,os,Pt,ss,$t,ls,Ht,es,Mt,ns,At]),dc=p.useCallback(b=>{if(b.pointerType==="touch"&&(ze.current.delete(b.pointerId),bt.current)){ye(b),ze.current.size<2&&(bt.current=null);return}if(wt.current){ye(b),wt.current=null;return}if(Pe.current){ye(b),Dt();return}if(pt.current){ye(b),Pt();return}if(ft.current){ye(b),$t();return}if($e.current){ye(b),Ht();return}jt.current?(ye(b),Mt()):Lt.current&&(ye(b),At())},[ye,Dt,Pt,$t,Ht,Mt,At]),pc=p.useCallback(b=>{var T,E;Zo(b,{startX:b.clientX,startY:b.clientY,startWidth:((T=n==null?void 0:n.props)==null?void 0:T.width)??Bo,startHeight:((E=n==null?void 0:n.props)==null?void 0:E.height)??Eo})},[Zo,n]);if(!n)return null;const{strokes:is=[],shapes:cs=[],width:fc,height:hc}=n.props,us=(Nt==null?void 0:Nt.width)??fc,bc=(Nt==null?void 0:Nt.height)??hc,Ln=6,On=[...te].map(b=>{var D;const T=Us(n,b);if(!T)return null;let{kind:E,item:L}=T;return(D=ve==null?void 0:ve.ids)!=null&&D.includes(b)?L=E==="stroke"?fn(L,ve.dx,ve.dy):pn(L,ve.dx,ve.dy):E==="shape"&&(ht==null?void 0:ht.id)===b&&(L=ht),{id:b,kind:E,item:L,box:Cf(E,L),rotation:E==="shape"?L.rotation:0}}).filter(Boolean),Br=On.length===1&&On[0].kind==="shape"?On[0]:null,Me=(Br==null?void 0:Br.item)??null,mc=Me&&Me.type==="arrow"?[["start",Me.x1,Me.y1],["end",Me.x2,Me.y2]]:Me&&!Me.rotation?Object.entries(Vr(Me)).map(([b,[T,E]])=>[b,T,E]):[],Er=Me&&Me.type!=="arrow"?Ya(Me):null;return a.jsxs("div",{className:r,"data-block-id":e,"data-tool":s,contentEditable:!1,tabIndex:-1,children:[a.jsxs("div",{className:"be-canvas-toolbar",contentEditable:!1,children:[a.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${s==="pen"?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="pen","aria-label":"Pen",title:"Pen",onClick:()=>l("pen"),children:a.jsx(xl,{size:14})}),a.jsxs("div",{className:"be-canvas-picker-wrap",children:[a.jsx("button",{ref:ke,type:"button",className:`be-canvas-toolbar-btn${s==="eraser"?" be-canvas-toolbar-btn-active":""}`,"aria-haspopup":"true","aria-expanded":W,"aria-pressed":s==="eraser","aria-label":"Eraser",title:"Eraser",onClick:()=>ie(b=>!b),children:(()=>{var T;const b=((T=Fs.find(E=>E.mode===i))==null?void 0:T.Icon)??Il;return a.jsx(b,{size:14})})()}),W&&a.jsx("div",{ref:fe,className:"be-canvas-picker be-canvas-shape-picker",role:"menu","aria-label":"Eraser",children:Fs.map(({mode:b,label:T,Icon:E})=>a.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-btn${s==="eraser"&&i===b?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="eraser"&&i===b,"aria-label":T,title:T,onClick:()=>{l("eraser"),c(b),Yo()},children:a.jsx(E,{size:14})},b))})]}),a.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${s==="select"?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="select","aria-label":"Select",title:"Select",onClick:()=>l("select"),children:a.jsx(ru,{size:14})}),a.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${s==="text"?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="text","aria-label":"Text",title:"Text",onClick:()=>l("text"),children:a.jsx(io,{size:14})}),a.jsxs("div",{className:"be-canvas-picker-wrap",children:[a.jsx("button",{ref:Re,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":z,"aria-label":`Font size: ${de?de.fontSize:y}`,title:"Font size",onClick:()=>Y(b=>!b),children:a.jsx("span",{className:"be-canvas-font-size-trigger",children:"A"})}),z&&a.jsxs("div",{ref:le,className:"be-canvas-picker be-canvas-size-picker",role:"dialog","aria-label":"Font size",children:[a.jsx("span",{className:"be-canvas-size-preview","aria-hidden":"true",children:a.jsx("span",{className:"be-canvas-font-size-preview-letter",style:{fontSize:de?de.fontSize:y},children:"A"})}),a.jsx("input",{type:"range",className:"be-canvas-size-slider",min:mf,max:gf,value:de?de.fontSize:y,onChange:b=>{const T=Number(b.target.value);I(T),de&&_t(E=>E&&{...E,fontSize:T})},"aria-label":"Font size"}),a.jsxs("span",{className:"be-canvas-size-value",children:[de?de.fontSize:y,"px"]})]})]}),a.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Bring to front",title:"Bring to front",onClick:Zi,disabled:te.size===0,children:a.jsx(ir,{size:14})}),a.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Send to back",title:"Send to back",onClick:Qi,disabled:te.size===0,children:a.jsx(cr,{size:14})}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsxs("div",{className:"be-canvas-picker-wrap",children:[a.jsx("button",{ref:re,type:"button",className:`be-canvas-toolbar-btn${$r.has(s)?" be-canvas-toolbar-btn-active":""}`,"aria-haspopup":"true","aria-expanded":B,"aria-label":"Shape",title:"Shape",onClick:()=>M(b=>!b),children:(()=>{var T;const b=((T=Hs.find(E=>E.type===($r.has(s)?s:w)))==null?void 0:T.Icon)??wl;return a.jsx(b,{size:14})})()}),B&&a.jsx("div",{ref:be,className:"be-canvas-picker be-canvas-shape-picker",role:"menu","aria-label":"Shape",children:Hs.map(({type:b,label:T,Icon:E})=>a.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-btn${s===b?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s===b,"aria-label":T,title:T,onClick:()=>{l(b),j(b),Uo()},children:a.jsx(E,{size:14})},b))})]}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsxs("div",{className:"be-canvas-picker-wrap",children:[a.jsx("button",{ref:ae,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":S,"aria-label":`Color: ${u}`,title:"Color",onClick:()=>v(b=>!b),children:a.jsx("span",{className:"be-canvas-color-trigger-dot",style:{backgroundColor:u}})}),S&&a.jsxs("div",{ref:G,className:"be-canvas-picker be-canvas-color-picker",role:"menu","aria-label":"Pen color",children:[Ns.map(b=>a.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-swatch${u===b?" be-canvas-toolbar-swatch-active":""}`,style:{backgroundColor:b},"aria-pressed":u===b,"aria-label":`Color ${b}`,title:`Color ${b}`,onClick:()=>{f(b),Fo()}},b)),a.jsx("label",{className:"be-canvas-custom-swatch",title:"Custom color","aria-label":"Custom color",children:a.jsx("input",{type:"color",value:u,onChange:b=>f(b.target.value)})})]})]}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsxs("div",{className:"be-canvas-picker-wrap",children:[a.jsx("button",{ref:se,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":R,"aria-label":`Fill: ${m??"none"}`,title:"Fill",onClick:()=>_(b=>!b),children:a.jsx("span",{className:`be-canvas-fill-trigger-dot${m?"":" be-canvas-fill-trigger-dot-none"}`,style:m?{backgroundColor:m}:void 0})}),R&&a.jsxs("div",{ref:H,className:"be-canvas-picker be-canvas-color-picker",role:"menu","aria-label":"Shape fill",children:[a.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-swatch be-canvas-fill-swatch-none${m===null?" be-canvas-toolbar-swatch-active":""}`,"aria-pressed":m===null,"aria-label":"No fill",title:"No fill",onClick:()=>{g(null),vr()}}),Ns.map(b=>a.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-swatch${m===b?" be-canvas-toolbar-swatch-active":""}`,style:{backgroundColor:b},"aria-pressed":m===b,"aria-label":`Fill ${b}`,title:`Fill ${b}`,onClick:()=>{g(b),vr()}},b)),a.jsx("label",{className:"be-canvas-custom-swatch",title:"Custom fill","aria-label":"Custom fill",children:a.jsx("input",{type:"color",value:m??_s,onChange:b=>g(b.target.value)})})]})]}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsxs("div",{className:"be-canvas-picker-wrap",children:[a.jsx("button",{ref:Q,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":O,"aria-label":`Stroke size: ${d}`,title:"Stroke size",onClick:()=>C(b=>!b),children:a.jsx("span",{className:"be-canvas-size-trigger-dot",style:{width:Math.min(d,16),height:Math.min(d,16)}})}),O&&a.jsxs("div",{ref:ee,className:"be-canvas-picker be-canvas-size-picker",role:"dialog","aria-label":"Stroke size",children:[a.jsx("span",{className:"be-canvas-size-preview","aria-hidden":"true",children:a.jsx("span",{className:"be-canvas-size-preview-dot",style:{width:d,height:d}})}),a.jsx("input",{type:"range",className:"be-canvas-size-slider",min:lf,max:af,value:d,onChange:b=>h(Number(b.target.value)),"aria-label":"Stroke size"}),a.jsxs("span",{className:"be-canvas-size-value",children:[d,"px"]})]})]}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${x?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":x,"aria-label":"Snap to grid",title:x?"Snap to grid: ON — drawing, moving, resizing and rotating align to the dotted grid. Click to turn off.":"Snap to grid: OFF — click to turn on (aligns drawing, moving, resizing and rotating to a grid)",onClick:()=>k(b=>!b),children:a.jsx(su,{size:14})}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Zoom out",title:"Zoom out",onClick:oc,disabled:ce.zoom<=Dr,children:"−"}),a.jsxs("button",{type:"button",className:"be-canvas-zoom-label","aria-label":`Zoom: ${Math.round(ce.zoom*100)}%. Click to reset to 100%.`,title:"Reset zoom to 100%",onClick:sc,children:[Math.round(ce.zoom*100),"%"]}),a.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Zoom in",title:"Zoom in",onClick:rc,disabled:ce.zoom>=Pr,children:"+"}),a.jsx("span",{className:"be-canvas-toolbar-divider"}),a.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Export PNG",title:"Export as PNG",onClick:lc,disabled:is.length===0&&cs.length===0,children:a.jsx(ou,{size:14})})]}),a.jsxs("svg",{ref:Ye,className:"be-canvas-surface",viewBox:`${ce.x} ${ce.y} ${Oe} ${Oe}`,width:us,height:bc,tabIndex:-1,onPointerDown:ic,onPointerMove:cc,onPointerUp:uc,onPointerCancel:dc,onDoubleClick:ac,onKeyDown:nc,children:[x&&a.jsxs(a.Fragment,{children:[a.jsx("defs",{children:a.jsx("pattern",{id:`be-canvas-grid-${e}`,width:$s,height:$s,patternUnits:"userSpaceOnUse",children:a.jsx("circle",{cx:1,cy:1,r:1.5,className:"be-canvas-grid-dot"})})}),a.jsx("rect",{className:"be-canvas-grid-background",x:ce.x,y:ce.y,width:Oe,height:Oe,fill:`url(#be-canvas-grid-${e})`})]}),is.map(b=>{var L;const E=((L=ve==null?void 0:ve.ids)==null?void 0:L.includes(b.id))?Jn(fn(b,ve.dx,ve.dy).points,{size:b.size}):o(b);return a.jsx("path",{d:E,fill:b.color,fillRule:"nonzero",opacity:Gi.has(b.id)?.25:1},b.id)}),Ko&&a.jsx("path",{d:Ko,fill:u,fillRule:"nonzero"}),cs.map(b=>{var E;let T=b;return(E=ve==null?void 0:ve.ids)!=null&&E.includes(b.id)?T=pn(b,ve.dx,ve.dy):(ht==null?void 0:ht.id)===b.id&&(T=ht),a.jsx(Ys,{shape:T,opacity:Ji.has(b.id)?.25:1},b.id)}),qo&&a.jsx(Ys,{shape:qo,opacity:.6}),On.map(({id:b,box:T,rotation:E})=>a.jsx("g",{transform:E?`rotate(${E} ${T.x+T.width/2} ${T.y+T.height/2})`:void 0,children:a.jsx("rect",{className:"be-canvas-selection-box",x:T.x-Ln,y:T.y-Ln,width:T.width+Ln*2,height:T.height+Ln*2,fill:"none"})},b)),mc.map(([b,T,E])=>a.jsx("rect",{className:"be-canvas-selection-handle",x:T-hn/2,y:E-hn/2,width:hn,height:hn},b)),Er&&a.jsx("circle",{className:"be-canvas-rotate-handle",cx:Er[0],cy:Er[1],r:hn/2}),an&&a.jsx("rect",{className:"be-canvas-marquee",x:an.x,y:an.y,width:an.width,height:an.height}),de&&a.jsx("foreignObject",{x:de.x,y:de.y,width:de.width,height:de.height,children:a.jsx("textarea",{xmlns:"http://www.w3.org/1999/xhtml",ref:b=>b==null?void 0:b.focus(),className:"be-canvas-text-editor",value:de.text,style:{color:de.color,fontSize:de.fontSize},onChange:b=>_t(T=>T&&{...T,text:b.target.value}),onBlur:()=>tc(),onKeyDown:b=>{b.key==="Escape"&&(b.preventDefault(),ec()),b.stopPropagation()}})})]}),a.jsx("div",{className:"be-canvas-resize-handle",onMouseDown:pc,role:"slider","aria-label":"Resize canvas","aria-valuemin":Ms,"aria-valuenow":us,contentEditable:!1})]})}function Ef(e){const{strokes:t=[],shapes:n=[]}=e.props;return!t.length&&!n.length?"<p></p>":$a(e)}function Lf(){return""}function Of(){return null}function _f(e,{blockId:t,runId:n,sliceStart:r,sliceEnd:o}){const s=e.getRun(n),l=(s==null?void 0:s.value)??"";e.applyOperation(ue(n,{value:l.slice(0,r)+l.slice(o)}));const i=dr(e,t,rf());return Ze(e,i,Z("paragraph")),i}const Nf={component:Bf,isLeaf:!0,defaultProps:{strokes:[],shapes:[],width:Bo,height:Eo},toHTML:Ef,toPlainText:Lf,fromHTML:Of,slashCommand:{label:"Canvas",icon:Xc,keywords:["canvas","draw","drawing","sketch","freehand"],run:_f}};function Ka(e){Va(e,{paragraph:Dl,heading:Pl,listItem:Wl,...Wa,...Xa,divider:ha,callout:ma,blockquote:ga,code:ka,toggleHeading:ya,button:wa,embed:Ta,canvas:Nf})}function Va(e,t){for(const[n,r]of Object.entries(t))e.register(n,r)}const Wa={table:ca,tableRow:ia,tableCell:aa},Xa={layout:fa,layoutColumn:pa};function Mf({id:e}){const t=q(),n=xt(e),r=p.useCallback(i=>{t.applyOperation(ue(e,{data:{...n==null?void 0:n.data,selectedValue:i}}))},[t,e,n==null?void 0:n.data]);if(!n)return null;const{options:o=[],selectedValue:s="",placeholder:l="Select…"}=n.data??{};return a.jsx("span",{className:"be-inline-select",onMouseDown:i=>{i.preventDefault(),i.stopPropagation()},onKeyDown:i=>i.stopPropagation(),children:a.jsx(Rt,{value:s,options:o,onChange:r,placeholder:l,ariaLabel:"Select an option"})})}function kr(e,{blockId:t,runId:n,sliceStart:r,sliceEnd:o},s){const l=e.getRun(n),i=(l==null?void 0:l.value)??"",c=i.slice(0,r),u=i.slice(o),f=s(),d={...l,value:c},h={id:N(),type:"text",value:u,marks:{...l==null?void 0:l.marks}};e.applyOperation(In(t,[n],[d,f,h])),xe(h.id)}function Af(e){return String(e).replace(/&/g,"&").replace(/"/g,""")}function qa(e){var r;const{options:t=[],selectedValue:n=""}=e.data??{};return((r=t.find(o=>o.value===n))==null?void 0:r.label)??""}function Df(e){var n,r;const t=qa(e)||((n=e.data)==null?void 0:n.placeholder)||"";return`<span data-inline-type="select" data-selected-value="${Af(((r=e.data)==null?void 0:r.selectedValue)??"")}">${t}</span>`}function Pf(e){return qa(e)}function $f(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="select"?null:{id:N(),type:"select",value:"",marks:{},data:{options:[],selectedValue:e.getAttribute("data-selected-value")??""}}}const Ga={component:Mf,isAtomic:!0,toHTML:Df,toPlainText:Pf,fromHTML:$f,slashCommand:{label:"Select",icon:Ll,keywords:["select","dropdown","choice","picker"],run:(e,{blockId:t,runId:n,sliceStart:r,sliceEnd:o})=>kr(e,{blockId:t,runId:n,sliceStart:r,sliceEnd:o},()=>({id:N(),type:"select",value:"",marks:{},data:{options:[],selectedValue:"",placeholder:"Select…"}}))}};function zf({id:e}){const t=q(),n=xt(e),r=p.useCallback(s=>{t.applyOperation(ue(e,{data:{...n==null?void 0:n.data,isoDate:s.target.value}}))},[t,e,n==null?void 0:n.data]);if(!n)return null;const{isoDate:o=""}=n.data??{};return a.jsx("span",{className:"be-inline-date",onMouseDown:s=>s.stopPropagation(),onKeyDown:s=>s.stopPropagation(),children:a.jsx("input",{type:"date",value:o,onChange:r})})}function Hf(e){return String(e).replace(/&/g,"&").replace(/"/g,""")}function Ja(e){if(!e)return"";const t=new Date(`${e}T00:00:00`);return Number.isNaN(t.getTime())?e:t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Ff(e){var n;const t=((n=e.data)==null?void 0:n.isoDate)??"";return`<span data-inline-type="date" data-iso-date="${Hf(t)}">${Ja(t)}</span>`}function Uf(e){var t;return Ja(((t=e.data)==null?void 0:t.isoDate)??"")}function Yf(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="date"?null:{id:N(),type:"date",value:"",marks:{},data:{isoDate:e.getAttribute("data-iso-date")??""}}}function Kf(){return new Date().toISOString().slice(0,10)}const Za={component:zf,isAtomic:!0,toHTML:Ff,toPlainText:Uf,fromHTML:Yf,slashCommand:{label:"Date",icon:du,keywords:["date","when","schedule","calendar"],run:(e,{blockId:t,runId:n,sliceStart:r,sliceEnd:o})=>kr(e,{blockId:t,runId:n,sliceStart:r,sliceEnd:o},()=>({id:N(),type:"date",value:"",marks:{},data:{isoDate:Kf()}}))}};function Vf({id:e}){const t=q(),n=xt(e),r=p.useCallback(i=>{t.applyOperation(ue(e,{data:{...n==null?void 0:n.data,checked:i.target.checked}}))},[t,e,n==null?void 0:n.data]),o=p.useCallback(i=>{t.applyOperation(ue(e,{data:{...n==null?void 0:n.data,label:i.target.value}}))},[t,e,n==null?void 0:n.data]);if(!n)return null;const{checked:s=!1,label:l=""}=n.data??{};return a.jsxs("span",{className:"be-inline-checkbox",onMouseDown:i=>i.stopPropagation(),onKeyDown:i=>i.stopPropagation(),children:[a.jsx("input",{type:"checkbox",className:"be-inline-checkbox-input",checked:s,onChange:r}),a.jsx("input",{type:"text",className:"be-inline-checkbox-label",value:l,onChange:o,placeholder:"Label…"})]})}function Wf(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Xf(e){const{checked:t=!1,label:n=""}=e.data??{};return`<span data-inline-type="checkbox" data-checked="${t}">${t?"☑":"☐"} ${Wf(n)}</span>`}function qf(e){const{checked:t=!1,label:n=""}=e.data??{};return`${t?"[x]":"[ ]"} ${n}`.trim()}function Gf(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="checkbox"?null:{id:N(),type:"checkbox",value:"",marks:{},data:{checked:e.getAttribute("data-checked")==="true",label:(e.textContent??"").replace(/^[☑☐]\s*/,"")}}}const Qa={component:Vf,isAtomic:!0,toHTML:Xf,toPlainText:qf,fromHTML:Gf,slashCommand:{label:"Checkbox",icon:po,keywords:["checkbox","todo","check","toggle"],run:(e,{blockId:t,runId:n,sliceStart:r,sliceEnd:o})=>kr(e,{blockId:t,runId:n,sliceStart:r,sliceEnd:o},()=>({id:N(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}}))}};function Jf({id:e,blockId:t}){var m;const n=q(),r=xt(e),o=t?n.getBlock(t):null,s=o?n.getBlock(o.parentId):null,l=(s==null?void 0:s.parentId)??null,i=he(l),c=s?s.contentIds.indexOf(t):-1,f=(((m=(i&&s?De(i,s.contentIds.length):[])[c])==null?void 0:m.options)??[]).map((g,x)=>({...g,color:g.color??vn(x)})),d=p.useCallback((g,x)=>{n.applyOperation(ue(e,{data:{selectedValue:g,selectedLabel:(x==null?void 0:x.label)??""}}))},[n,e]);if(!r)return null;const{selectedValue:h=""}=r.data??{};return a.jsx("span",{className:"be-inline-table-select",onMouseDown:g=>{g.preventDefault(),g.stopPropagation()},onKeyDown:g=>g.stopPropagation(),children:a.jsx(Rt,{value:h,options:f,onChange:d,placeholder:"Select…",ariaLabel:"Select an option",variant:"tag"})})}function ei(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Zf(e){return ei(e).replace(/"/g,""")}function Qf(e){const{selectedValue:t="",selectedLabel:n=""}=e.data??{};return`<span data-inline-type="tableSelect" data-selected-value="${Zf(t)}">${ei(n)}</span>`}function eh(e){var t;return((t=e.data)==null?void 0:t.selectedLabel)??""}function th(e){var t;return((t=e.getAttribute)==null?void 0:t.call(e,"data-inline-type"))!=="tableSelect"?null:{id:N(),type:"tableSelect",value:"",marks:{},data:{selectedValue:e.getAttribute("data-selected-value")??"",selectedLabel:e.textContent??""}}}const ti={component:Jf,isAtomic:!0,toHTML:Qf,toPlainText:eh,fromHTML:th},ni={};function ri(e){oi(e,{select:Ga,date:Za,checkbox:Qa,...si,emoji:ni})}function oi(e,t){for(const[n,r]of Object.entries(t))e.register(n,r)}const si={tableSelect:ti};function nh(){const e="root",t=N(),n=N();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 rh({doc:e,history:t=!0,registerBlocks:n,registerInlineTypes:r}={}){return p.useMemo(()=>{const o=rl();(n??Ka)(o);const s=sl();(r??ri)(s);const l=new tr(e??nh());return{store:t?new Gs(l):l,registry:o,inlineRegistry:s}},[])}function li({minHeight:e=180,className:t="be-trailing-space"}){const n=q(),[r]=oo(),o=p.useCallback(()=>{var u;if(r)return;const s=n.getRootId(),l=n.getBlock(s),i=(u=l==null?void 0:l.contentIds)==null?void 0:u[l.contentIds.length-1];if(!i){const f=rn(n);f&&Is(n,f);return}const c=n.getBlock(i);(c==null?void 0:c.type)==="paragraph"?Is(n,i):Ze(n,i,Z("paragraph"))},[n,r]);return a.jsx("div",{className:t,style:{minHeight:e},onClick:o})}async function Wr(e,t,n,r){var l,i,c;const{html:o,text:s}=Rn(e,t,r,n);if(typeof ClipboardItem<"u"&&((l=navigator.clipboard)!=null&&l.write)){await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([s],{type:"text/plain"}),"text/html":new Blob([o],{type:"text/html"})})]);return}await((c=(i=navigator.clipboard)==null?void 0:i.writeText)==null?void 0:c.call(i,s))}function Lo(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function gn(e,t){t.length!==0&&Lo(e,t.map(n=>J(n)))}function ai(e,t){if(t.length===0)return!1;const n=e.getBlock(t[0]);if(!n)return!1;const r=e.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(t[0]),s=r.contentIds.indexOf(t[t.length-1]);if(o<=0)return!1;const l=r.contentIds[o-1];return e.applyOperation(st(l,n.parentId,s)),!0}function ii(e,t){if(t.length===0)return!1;const n=e.getBlock(t[0]);if(!n)return!1;const r=e.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(t[0]),s=r.contentIds.indexOf(t[t.length-1]);if(s===-1||s>=r.contentIds.length-1)return!1;const l=r.contentIds[s+1];return e.applyOperation(st(l,n.parentId,o)),!0}function ci(e,t){return t.length>0&&t.every(n=>{var r,o;return!!((o=(r=e.getBlock(n))==null?void 0:r.props)!=null&&o.hidden)})}function ui(e,t,n){t.length!==0&&Lo(e,t.map(r=>X(r,{hidden:n})))}function oh(e,t,n,r){const o=n.filter(l=>{var i;return ko((i=e.getBlock(l))==null?void 0:i.type)});if(o.length===0)return;const s=o.flatMap(l=>Fl(e,t,l,r).ops);Lo(e,s)}function sh(e,t){if(t.length===0)return[];const n=e.getBlock(t[0]),r=n&&e.getBlock(n.parentId);if(!r)return t;const o=new Set(t);return r.contentIds.filter(s=>o.has(s))}function di(){const e=q(),t=gt(),n=Je(),[r,o]=Cn(),[s,l]=p.useState(null),i=p.useRef(null),c=p.useRef(null),u=r.length>0,f=sr(i,u,(s==null?void 0:s.bottom)!=null?s.bottom+4:null,s==null?void 0:s.left),d=p.useCallback(()=>o([]),[o]);pr(i,u,d,void 0),p.useEffect(()=>{if(!u){l(null);return}const v=()=>{const R=r[r.length-1],_=document.querySelector(`[data-block-row-id="${R}"]`);l((_==null?void 0:_.getBoundingClientRect())??null)};return v(),window.addEventListener("scroll",v,!0),window.addEventListener("resize",v),()=>{window.removeEventListener("scroll",v,!0),window.removeEventListener("resize",v)}},[u,r]),p.useEffect(()=>{if(!u)return;const v=_=>{var O,C,B,M;(O=i.current)!=null&&O.contains(_.target)||(C=c.current)!=null&&C.contains(_.target)||(M=(B=_.target).closest)!=null&&M.call(B,".be-block-gutter")||d()},R=_=>{_.key==="Escape"?d():(_.key==="Delete"||_.key==="Backspace")&&(_.preventDefault(),gn(e,r),d())};return document.addEventListener("mousedown",v),document.addEventListener("keydown",R),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",R)}},[u,e,r,d]);const h=v=>v===1?"block":"blocks",m=p.useCallback(()=>{Wr(e,t,n,r),me(`${r.length} ${h(r.length)} copied`),d()},[e,t,n,r,d]),g=p.useCallback(async()=>{await Wr(e,t,n,r);const v=r.length;gn(e,r),me(`${v} ${h(v)} cut`),d()},[e,t,n,r,d]),x=p.useCallback(()=>{const v=r.length;gn(e,r),me(`${v} ${h(v)} deleted`),d()},[e,r,d]),k=p.useCallback(()=>{ai(e,r)&&me(`${r.length} ${h(r.length)} moved up`),d()},[e,r,d]),y=p.useCallback(()=>{ii(e,r)&&me(`${r.length} ${h(r.length)} moved down`),d()},[e,r,d]),I=ci(e,r),w=p.useCallback(()=>{ui(e,r,!I),me(I?`${r.length} ${h(r.length)} shown in preview`:`${r.length} ${h(r.length)} hidden in preview`),d()},[e,r,I,d]),j=r.some(v=>{var R;return ko((R=e.getBlock(v))==null?void 0:R.type)}),S=p.useCallback(v=>{const R=r.length;oh(e,t,r,v),me(`${R} ${h(R)} turned into ${v.label}`),d()},[e,t,r,d]);return!u||!f?null:Xe.createPortal(a.jsxs("div",{ref:i,role:"menu","aria-label":"Selected blocks options",className:"be-block-range-menu",style:{position:"fixed",top:f.top,left:f.left},children:[a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:m,children:[a.jsx(ao,{size:15})," Copy"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:g,children:[a.jsx(lu,{size:15})," Cut"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:k,children:[a.jsx(ir,{size:15})," Move up"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:y,children:[a.jsx(cr,{size:15})," Move down"]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:w,children:[I?a.jsx(fo,{size:15}):a.jsx(ho,{size:15}),I?"Show in preview":"Hide in preview"]}),j&&a.jsx(Ul,{onSelect:S,onClose:()=>{},containerRef:c,menuClassName:"be-block-range-menu",itemClassName:"be-block-range-menu-item"}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item be-block-range-menu-item-danger",onClick:x,children:[a.jsx(ar,{size:15})," Delete"]})]}),document.body)}const Zn="application/x-block-editor-blocks+json";function Oo(e){return e.split(/\r\n|\r|\n/).filter(t=>t.length>0).map(t=>{const n=N();return{block:{id:N(),type:"paragraph",parentId:null,contentIds:[n],props:{}},runs:[{id:n,type:"text",value:t,marks:{}}]}})}function pi(e,t,n){const r=new DOMParser().parseFromString(e,"text/html"),o={registry:t,inlineRegistry:n},s=t.listHtmlMatchers(),l=[],i=u=>{var h;const f=u.tagName==="OL",d=[];for(const m of u.children){if(m.tagName!=="LI")continue;const g=(h=t.get("listItem"))==null?void 0:h.fromHTML(m,o);g&&(g.block.props.ordered=f,d.push(g))}return d},c=u=>{var d;const f=Array.from(u.children).filter(h=>h.tagName==="P");if(f.length===0){const h=(d=t.get("blockquote"))==null?void 0:d.fromHTML(u,o);return h?[h]:[]}return f.map(h=>{const m=Fe(h,o);return{block:{id:N(),type:"blockquote",parentId:null,contentIds:m.map(g=>g.id),props:{}},runs:m}})};for(const u of r.body.childNodes){if(u.nodeType===3){const d=u.textContent.trim();d&&l.push(...Oo(d));continue}if(u.nodeType!==1)continue;if(u.tagName==="UL"||u.tagName==="OL"){l.push(...i(u));continue}if(u.tagName==="BLOCKQUOTE"){l.push(...c(u));continue}let f=null;for(const d of s){const h=d.fromHTML(u,o);if(h){f=h;break}}if(f)l.push(f);else if(u.textContent.trim()){const d=Fe(u,o);l.push({block:{id:N(),type:"paragraph",parentId:null,contentIds:d.map(h=>h.id),props:{}},runs:d})}}return l}function fi(e,t,n){const r=e.types??[];if(r.includes(Zn)){const s=e.getData(Zn);if(s)return lh(s)}if(r.includes("text/html")){const s=e.getData("text/html");if(s)return pi(s,t,n)}const o=e.getData("text/plain")??"";return Oo(o)}function lh(e){return JSON.parse(e).blocks.map(n=>vo(n))}function Xr(e,t){var r;const n=e.getBlock(t);return((r=n.props)==null?void 0:r.titleRunIds)??n.contentIds}function Wn(){return{id:N(),type:"text",value:"",marks:{}}}function qr(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function _o(e,t,n){const{startRunId:r,startOffset:o,endRunId:s,endOffset:l}=n,i=Xr(e,t),c=i.indexOf(r),u=i.indexOf(s);if(c===-1||u===-1)return null;const[f,d]=c<=u?[c,u]:[u,c],h=c<=u?o:l,m=c<=u?l:o,g=i.slice(0,f).map(S=>e.getRun(S)),x=i.slice(d+1).map(S=>e.getRun(S)),k=i.slice(f,d+1).map(S=>e.getRun(S)),y=[];let I=null,w=0;if(f===d){const S=k[0];if(S.type==="text"){const v=Math.max(0,Math.min(h,m)),R=Math.min(S.value.length,Math.max(h,m)),_={...S,value:S.value.slice(0,v)+S.value.slice(R)};y.push(_),I=_.id,w=v}}else k.forEach((S,v)=>{if(S.type!=="text")return;const R=v===0,_=v===k.length-1,O=R?S.value.slice(0,h):"";if(R&&O){const C={...S,value:O};y.push(C),I=C.id,w=O.length}if(_&&!R){const C=S.value.slice(m);if(C){const B={id:N(),type:"text",value:C,marks:S.marks};y.push(B),I===null&&(I=B.id,w=0)}}});let j=[...g,...y,...x];if(j.length===0){const S=Wn();j=[S],I=S.id,w=0}else if(I===null){const S=g[g.length-1];S?(I=S.id,w=S.type==="text"?S.value.length:0):x[0]&&(I=x[0].id,w=0)}return e.applyOperation(_e(t,j)),{blockId:t,runId:I,offset:w}}function No(e,t){const{blockIds:n,startBlockId:r,startRunId:o,startOffset:s,endBlockId:l,endRunId:i,endOffset:c}=t;if(!n||n.length===0)return null;const u=n.indexOf(r),f=n.indexOf(l);if(u===-1||f===-1)return null;const[d,h]=u<=f?[u,f]:[f,u],m=u<=f,g=m?o:i,x=m?s:c,k=m?i:o,y=m?c:s;if(d===h)return _o(e,n[d],{startRunId:g,startOffset:x,endRunId:k,endOffset:y});const I=n[d],w=n[h],j=e.getBlock(I),S=e.getBlock(w),v=Xr(e,I),R=v.indexOf(g),_=v.slice(0,R).map(le=>e.getRun(le)),O=e.getRun(g),C=O.type==="text"&&x>0?{...O,value:O.value.slice(0,x)}:null,B=Xr(e,w),M=B.indexOf(k),z=B.slice(M+1).map(le=>e.getRun(le)),Y=e.getRun(k),W=Y.type==="text"&&y<Y.value.length?{id:N(),type:"text",value:Y.value.slice(y),marks:Y.marks}:null,ie=[..._,...C?[C]:[]],ae=[...W?[W]:[],...z],G=[];for(let le=d+1;le<h;le+=1)G.push(J(n[le]));const se=Al(j.type,S.type),H=e.getBlock(j.parentId),Q=h-d-1+(se?1:0),ee=H&&H.contentIds.length-Q===1;let re,be,Re;if(se){const le=[...ie,...ae];if(le.length===0&&ee&&j.type!=="paragraph"){const{block:fe,runs:P}=Z("paragraph")(H.id);return G.push({type:"insertBlock",block:fe,parentId:H.id,index:0,subtree:{blocks:[fe],runs:P}}),G.push(J(I)),G.push(J(w)),qr(e,G),{blockId:fe.id,runId:fe.contentIds[0],offset:0}}const ke=le.length?le:[Wn()];if(G.push(_e(I,ke)),G.push(J(w)),Re=I,C)re=C.id,be=C.value.length;else if(_.length){const fe=_[_.length-1];re=fe.id,be=fe.type==="text"?fe.value.length:0}else W?(re=W.id,be=0):z.length?(re=z[0].id,be=0):(re=ke[0].id,be=0)}else{const le=ie.length?ie:[Wn()];if(G.push(_e(I,le)),G.push(_e(w,ae.length?ae:[Wn()])),Re=I,C)re=C.id,be=C.value.length;else if(_.length){const ke=_[_.length-1];re=ke.id,be=ke.type==="text"?ke.value.length:0}else re=le[0].id,be=0}return qr(e,G),{blockId:Re,runId:re,offset:be}}function Qn(e,t=""){var i;const n=e.getRootId(),r=((i=e.getBlock(n))==null?void 0:i.contentIds)??[];if(r.length===0)return null;const o=r.map(c=>J(c)),{block:s,runs:l}=Z("paragraph")(n);return t&&(l[0].value=t),o.push(ge(s,n,0,{blocks:[s],runs:l})),qr(e,o),{blockId:s.id,runId:s.contentIds[0],offset:t.length}}function Gr(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 ah(e){var d;const t=(d=window.getSelection)==null?void 0:d.call(window);if(!t||t.rangeCount===0)return[];const n=Gr(t.anchorNode),r=Gr(t.focusNode);if(!n)return[];if(!r||n===r)return[n];const o=e.getBlock(n),s=o&&e.getBlock(o.parentId);if(!s)return[n];const l=s.contentIds,i=l.indexOf(n),c=l.indexOf(r);if(i===-1||c===-1)return[n];const[u,f]=i<=c?[i,c]:[c,i];return l.slice(u,f+1)}function Ks(e){const t=tn();if(t)return _o(e,t.blockId,t);const n=Gt(e);return n?No(e,n):null}function ih(e,t,n){const r=e.getRun(t.runId);if(!r||r.type!=="text")return null;const o=r.value??"",s=o.slice(0,t.offset)+n+o.slice(t.offset);return e.applyOperation(ue(r.id,{value:s})),{blockId:t.blockId,runId:r.id,offset:t.offset+n.length}}function Fr(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function hi(){const e=q(),t=gt(),n=Je(),[r,o]=ro(),[s,l]=Cn(),i=p.useCallback(f=>{var x;const d=r?((x=e.getBlock(e.getRootId()))==null?void 0:x.contentIds)??[]:s.length>0?s:ah(e);if(d.length===0)return;const{html:h,text:m,json:g}=Rn(e,t,d,n);f.clipboardData.setData("text/plain",m),f.clipboardData.setData("text/html",h),f.clipboardData.setData(Zn,g),f.preventDefault()},[e,t,n,r,s]),c=p.useCallback(f=>{if(i(f),r){const h=Qn(e);o(!1),h!=null&&h.runId&&We(h.runId,h.offset);return}if(s.length>0){gn(e,s),l([]);return}const d=Ks(e);d!=null&&d.runId&&We(d.runId,d.offset)},[i,e,r,o,s,l]),u=p.useCallback(f=>{var w,j,S;const d=fi(f.clipboardData,t,n);if(d.length===0)return;if(r){const v=e.getRootId(),_=(((w=e.getBlock(v))==null?void 0:w.contentIds)??[]).map(C=>J(C));let O=0;for(const{block:C,runs:B,subtreeBlocks:M=[]}of d)C.parentId=v,_.push(ge(C,v,O,{blocks:[C,...M],runs:B})),O+=1;Fr(e,_),o(!1),f.preventDefault();return}if(s.length>0){const v=e.getBlock(s[0]),R=(v==null?void 0:v.parentId)??null,_=R&&e.getBlock(R);let O=_?_.contentIds.indexOf(s[0]):0;const C=s.map(B=>J(B));for(const{block:B,runs:M,subtreeBlocks:z=[]}of d)B.parentId=R,C.push(ge(B,R,O,{blocks:[B,...z],runs:M})),O+=1;Fr(e,C),l([]),f.preventDefault();return}const h=Ks(e);if(d.length===1&&d[0].runs.every(v=>v.type==="text")&&(d[0].subtreeBlocks??[]).length===0){const v=h?{blockId:h.blockId,runId:h.runId,offset:h.offset}:rt();if(v){const R=d[0].runs.map(O=>O.value).join(""),_=ih(e,v,R);if(_){We(_.runId,_.offset),f.preventDefault();return}}}const g=(h==null?void 0:h.blockId)??Gr((S=(j=window.getSelection)==null?void 0:j.call(window))==null?void 0:S.anchorNode);if(!g)return;const x=e.getBlock(g);if(!x)return;let y=e.getBlock(x.parentId).contentIds.indexOf(g)+1;const I=[];for(const{block:v,runs:R,subtreeBlocks:_=[]}of d)v.parentId=x.parentId,I.push(ge(v,x.parentId,y,{blocks:[v,..._],runs:R})),y+=1;Fr(e,I),f.preventDefault()},[e,t,n,r,o,s,l]);return{onCopy:i,onCut:c,onPaste:u}}const ch=["bold","italic","underline","strike","subscript","superscript","code"],uh=["color","highlight","link"];function Jt(e,t){var r;const n=e.getBlock(t);return((r=n.props)==null?void 0:r.titleRunIds)??n.contentIds}function dh(e,t){return e===t?!0:e&&t&&typeof e=="object"?JSON.stringify(e)===JSON.stringify(t):!1}function bi(e){var n;const t={};if(e.length===0)return t;for(const r of ch)t[r]=e.every(o=>{var s;return(s=o.marks)==null?void 0:s[r]});for(const r of uh){const o=((n=e[0].marks)==null?void 0:n[r])??null;t[r]=e.every(s=>{var l;return dh(((l=s.marks)==null?void 0:l[r])??null,o)})?o:null}return t}function Mo(e,t,n){const{startRunId:r,startOffset:o,endRunId:s,endOffset:l}=n,i=Jt(e,t),c=i.indexOf(r),u=i.indexOf(s);if(c===-1||u===-1)return{};const[f,d]=c<=u?[c,u]:[u,c],h=i.slice(f,d+1).map(m=>e.getRun(m)).filter(m=>m&&m.type==="text");return bi(h)}function Ao(e,t){const{blockIds:n,startBlockId:r,endBlockId:o}=t,s=n.indexOf(r),l=n.indexOf(o);if(s===-1||l===-1)return{};const[i,c]=s<=l?[s,l]:[l,s],u=[];for(let f=i;f<=c;f+=1)for(const d of Jt(e,n[f])){const h=e.getRun(d);h&&h.type==="text"&&u.push(h)}return bi(u)}function mi(e,t){const n={...e};for(const[r,o]of Object.entries(t))o!=null?n[r]=o:delete n[r];return n}function gi(e,t,n,r,o,s){const l=mi(n.marks,s);if(r===0&&o===n.value.length)return e.applyOperation({type:"updateRun",id:n.id,patch:{marks:l}}),n.id;const i=n.value.slice(0,r),c=n.value.slice(r,o),u=n.value.slice(o),f=[];i&&f.push({id:N(),type:"text",value:i,marks:{...n.marks}});const d={id:N(),type:"text",value:c,marks:l};return f.push(d),u&&f.push({id:N(),type:"text",value:u,marks:{...n.marks}}),e.applyOperation(In(t,[n.id],f)),d.id}function ph(e,t,n,r){const{startRunId:o,startOffset:s,endRunId:l,endOffset:i}=n,c=Jt(e,t),u=c.indexOf(o),f=c.indexOf(l);if(u===-1||f===-1)return null;const[d,h]=u<=f?[u,f]:[f,u],m=u<=f?s:i,g=u<=f?i:s,x=c.slice(d,h+1),k=x.map(w=>e.getRun(w));if(d===h){const w=k[0];if(w.type!=="text")return w.id;const j=Math.max(0,Math.min(m,g)),S=Math.min(w.value.length,Math.max(m,g));return j===S?w.id:gi(e,t,w,j,S,r)}const y=[];let I=null;return k.forEach((w,j)=>{if(w.type!=="text"){y.push(w),I=w.id;return}const S=j===0,v=j===k.length-1,R=S?m:0,_=v?g:w.value.length,O=w.value.slice(0,R),C=w.value.slice(R,_),B=w.value.slice(_);O&&y.push({id:N(),type:"text",value:O,marks:{...w.marks}});const M={id:N(),type:"text",value:C,marks:mi(w.marks,r)};y.push(M),I=M.id,B&&y.push({id:N(),type:"text",value:B,marks:{...w.marks}})}),e.applyOperation(In(t,x,y)),I}function fh(e,t,n,r){var g;const{startRunId:o,startOffset:s,endRunId:l,endOffset:i}=n,c=Jt(e,t),u=c.indexOf(o),f=c.indexOf(l);if(u===-1||f===-1)return!0;const[d,h]=u<=f?[u,f]:[f,u],m=c.slice(d,h+1).map(x=>e.getRun(x)).filter(x=>x.type==="text");if(m.length===0)return!0;if(d===h){const x=Math.max(0,Math.min(s,i)),k=Math.min(m[0].value.length,Math.max(s,i));if(x===k)return!((g=m[0].marks)!=null&&g[r])}return!m.every(x=>{var k;return(k=x.marks)==null?void 0:k[r]})}function hh(e,t,n,r,o,s){var d;const l=e.getRun(n),i=l.value??"",c=Math.max(0,Math.min(r,o)),u=Math.min(i.length,Math.max(r,o));if(c===u)return n;const f=!((d=l.marks)!=null&&d[s]);return gi(e,t,l,c,u,{[s]:f?!0:null})}function Zt(e,t,n,r){return ph(e,t,n,r)}function Do(e,t,n,r){const o=fh(e,t,n,r);return Zt(e,t,n,{[r]:o?!0:null})}function Po(e,t,n){return er(e,t,r=>({[n]:r?null:!0}),n)}function er(e,t,n,r){var v;const{blockIds:o,startBlockId:s,startRunId:l,startOffset:i,endBlockId:c,endRunId:u,endOffset:f}=t;if(!o||o.length===0)return null;const d=o.indexOf(s),h=o.indexOf(c);if(d===-1||h===-1)return null;const[m,g]=d<=h?[d,h]:[h,d],x=d<=h,k=x?l:u,y=x?i:f,I=x?u:l,w=x?f:i;let j=n;if(typeof n=="function"){let R=!1,_=!0;for(let O=m;O<=g;O+=1){const C=Jt(e,o[O]).map(B=>e.getRun(B)).filter(B=>B.type==="text");C.length!==0&&(R=!0,C.every(B=>{var M;return(M=B.marks)==null?void 0:M[r]})||(_=!1))}j=n(R&&_)}if(m===g)return Zt(e,o[m],{startRunId:k,startOffset:y,endRunId:I,endOffset:w},j);let S=null;for(let R=m;R<=g;R+=1){const _=o[R],O=Jt(e,_),C=O[0],B=O[O.length-1],M=e.getRun(B),z=((v=M==null?void 0:M.value)==null?void 0:v.length)??0;let Y;R===m&&R===g?Y={startRunId:k,startOffset:y,endRunId:I,endOffset:w}:R===m?Y={startRunId:k,startOffset:y,endRunId:B,endOffset:z}:R===g?Y={startRunId:C,startOffset:0,endRunId:I,endOffset:w}:Y={startRunId:C,startOffset:0,endRunId:B,endOffset:z},S=Zt(e,_,Y,j)}return S}function xi(e,t){var r;const n=e.getBlock(t);return((r=n==null?void 0:n.props)==null?void 0:r.titleRunIds)??(n==null?void 0:n.contentIds)??[]}function ki(e){const t=tn();if(!t)return!1;const{blockId:n,startRunId:r,startOffset:o,endRunId:s,endOffset:l}=t,i=xi(e,n);if(i.length===0)return!1;const c=i.indexOf(r),u=i.indexOf(s);if(c===-1||u===-1)return!1;const[f,d]=c<=u?[c,u]:[u,c],h=c<=u?o:l,m=c<=u?l:o;if(f!==0||d!==i.length-1||h!==0)return!1;const g=e.getRun(i[i.length-1]),x=(g==null?void 0:g.type)==="text"?(g.value??"").length:1;return m===x}function bh(e){const t=rt();return t?Ne(e,xi(e,t.blockId)):!1}function mh(e,t,n){var m,g;const r=e.getBlock(t);if(!r){n(null);return}const o=e.getBlock(r.parentId),s=o?o.contentIds.indexOf(t):-1,l=s>0?o.contentIds[s-1]:null,i=s!==-1&&s<o.contentIds.length-1?o.contentIds[s+1]:null;e.applyOperation(J(t)),n(null);const c=rn(e),u=l??i??c;if(!u)return;const f=e.getBlock(u);if(Sn(e,f)){n(u),requestAnimationFrame(()=>{var x;return(x=document.querySelector(`[data-block-id="${u}"]`))==null?void 0:x.focus()});return}const d=(m=f==null?void 0:f.props)==null?void 0:m.titleRunIds,h=((g=f==null?void 0:f.contentIds)==null?void 0:g[f.contentIds.length-1])??(d==null?void 0:d[d.length-1]);h&&xe(h)}function Qt(e){var o,s;const t=(o=e.getPendingSelection)==null?void 0:o.call(e);if(t){We(t.runId,t.offset);return}const r=(((s=e.getPendingAffectedBlockIds)==null?void 0:s.call(e))??[]).find(l=>e.getBlock(l));r&&Te(e,r)}const Vs={b:"bold",i:"italic",u:"underline"};function yi(e){const t=q(),[n,r]=ro(),{getSelectedBlockId:o,setSelectedBlockId:s}=lt();p.useEffect(()=>{const l=e.current;if(!l)return;const i=u=>{var d,h;if(o()&&(u.key==="Backspace"||u.key==="Delete")&&!u.defaultPrevented){u.preventDefault(),u.stopPropagation(),mh(t,o(),s);return}if(o()&&u.key!=="Backspace"&&u.key!=="Delete"&&s(null),u.metaKey||u.ctrlKey){const m=u.key.toLowerCase();if(m==="z"&&!u.shiftKey){u.preventDefault(),(d=t.undo)!=null&&d.call(t)&&Qt(t);return}if(m==="z"&&u.shiftKey||m==="y"){u.preventDefault(),(h=t.redo)!=null&&h.call(t)&&Qt(t);return}if(m==="a"){if(n)return;(ki(t)||bh(t))&&(u.preventDefault(),r(!0));return}if(Vs[m]){if(n)return;u.preventDefault();const g=Vs[m],x=tn();if(x){const y=Do(t,x.blockId,x,g);y&&xe(y);return}const k=Gt(t);if(k){const y=Po(t,k,g);y&&xe(y)}}return}if(n){if(u.key==="Backspace"||u.key==="Delete"){u.preventDefault(),u.stopPropagation();const m=Qn(t);r(!1),m!=null&&m.runId&&We(m.runId,m.offset);return}if(u.key.length===1){u.preventDefault(),u.stopPropagation();const m=Qn(t,u.key);r(!1),m!=null&&m.runId&&We(m.runId,m.offset);return}if(r(!1),u.key==="Escape")return}if(u.key==="Backspace"||u.key==="Delete"){const m=Gt(t);if(!m)return;u.preventDefault(),u.stopPropagation();const g=No(t,m);g!=null&&g.runId&&We(g.runId,g.offset)}},c=()=>{n&&r(!1),o()&&s(null)};return l.addEventListener("keydown",i),l.addEventListener("mousedown",c),()=>{l.removeEventListener("keydown",i),l.removeEventListener("mousedown",c)}},[e,t,n,r,o,s])}const gh=4;function xh(e,t,n){const r=e.getBlock(t);if(!r)return[];const o=e.getBlock(r.parentId);if(!o)return[t];const s=o.contentIds,l=s.indexOf(t),i=n?s.indexOf(n):l;if(l===-1)return[t];const[c,u]=i===-1?[l,l]:[Math.min(l,i),Math.max(l,i)];return s.slice(c,u+1)}function kh(){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 vi(e){const t=q(),[,n]=Cn(),r=p.useRef(null),o=p.useRef(!1),s=p.useRef(null),l=p.useCallback(f=>{var m,g,x,k,y;if(!r.current)return;if(!o.current){const{x:I,y:w}=s.current??{x:f.clientX,y:f.clientY};if(Math.hypot(f.clientX-I,f.clientY-w)<gh)return;o.current=!0,document.documentElement.classList.add("be-block-range-dragging"),(g=(m=window.getSelection)==null?void 0:m.call(window))==null||g.removeAllRanges()}(k=(x=window.getSelection)==null?void 0:x.call(window))==null||k.removeAllRanges(),f.preventDefault();const d=(y=document.elementFromPoint(f.clientX,f.clientY))==null?void 0:y.closest("[data-block-row-id]"),h=(d==null?void 0:d.getAttribute("data-block-row-id"))??null;n(xh(t,r.current,h))},[t,n]),i=p.useCallback(()=>{r.current=null,o.current=!1,s.current=null,document.documentElement.classList.remove("be-block-range-dragging")},[]),c=p.useCallback((f,d)=>{r.current=f,o.current=!1,s.current={x:d.clientX,y:d.clientY}},[]),u=p.useCallback(f=>{var x,k;if(f.button!==0||kh()||(k=(x=f.target).closest)!=null&&k.call(x,"button, input, textarea, select"))return;const d=f.target.closest("[data-block-row-id]");if(d){if(f.target.closest(".be-block-row-content"))return;c(d.getAttribute("data-block-row-id"),f);return}const h=e==null?void 0:e.current;if(!h)return;const g=[...h.querySelectorAll("[data-block-row-id]")].find(y=>{const I=y.getBoundingClientRect();return f.clientY>=I.top&&f.clientY<=I.bottom});g&&c(g.getAttribute("data-block-row-id"),f)},[e,c]);p.useEffect(()=>(document.addEventListener("mousedown",u),document.addEventListener("mousemove",l),document.addEventListener("mouseup",i),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("mousemove",l),document.removeEventListener("mouseup",i),document.documentElement.classList.remove("be-block-range-dragging")}),[u,l,i])}const yh=340;function vh(e,t,n,r){p.useEffect(()=>{if(!e||!t)return;const o=document.querySelector(`[data-run-id="${t}"]`);if(o)return o.setAttribute("aria-expanded","true"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-controls",r),n&&o.setAttribute("aria-activedescendant",n),()=>{o.removeAttribute("aria-expanded"),o.removeAttribute("aria-haspopup"),o.removeAttribute("aria-controls"),o.removeAttribute("aria-activedescendant")}},[e,t,n,r])}function Xn({isOpen:e,rect:t,commands:n,runId:r,onSelect:o,onClose:s,menuId:l="be-slash-menu",ariaLabel:i="Slash commands"}){const[c,u]=p.useState(0),f=p.useRef(null),d=p.useRef(null),h=gr(),m=ra(d,e&&n.length>0&&!!t,t==null?void 0:t.left);p.useEffect(()=>{u(0)},[n.length]),p.useEffect(()=>{var w,j;(j=(w=f.current)==null?void 0:w.scrollIntoView)==null||j.call(w,{block:"nearest"})},[c]),p.useEffect(()=>{if(!e)return;const w=j=>{j.key==="ArrowDown"?(j.preventDefault(),j.stopPropagation(),u(S=>Math.min(S+1,Math.max(n.length-1,0)))):j.key==="ArrowUp"?(j.preventDefault(),j.stopPropagation(),u(S=>Math.max(S-1,0))):j.key==="Enter"?(j.preventDefault(),j.stopPropagation(),n[c]&&o(n[c])):j.key==="Escape"&&(j.preventDefault(),j.stopPropagation(),s())};return document.addEventListener("keydown",w,!0),()=>document.removeEventListener("keydown",w,!0)},[e,n,c,o,s]);const x=n[c]?`${l}-option-${c}`:null;if(vh(e,r,x,l),!e||n.length===0||!t||m==null)return null;const k=window.innerHeight-h,I=t.bottom+yh>k?{bottom:window.innerHeight-t.top+4}:{top:t.bottom+4};return a.jsx("div",{ref:d,id:l,role:"listbox","aria-label":i,className:"be-slash-menu",style:{position:"fixed",left:m,zIndex:1e3,...I},children:n.map((w,j)=>{const S=w.icon;return a.jsxs("div",{ref:j===c?f:void 0,id:`${l}-option-${j}`,role:"option","aria-selected":j===c,className:`be-slash-menu-item${j===c?" be-slash-menu-item-active":""}`,onMouseDown:v=>{v.preventDefault(),o(w)},onMouseEnter:()=>u(j),children:[S&&a.jsx("span",{className:"be-slash-menu-item-icon",children:a.jsx(S,{size:16})}),a.jsx("span",{className:"be-slash-menu-item-label",children:w.label})]},w.label)})})}function wh(e,t){var r;if(!t)return!0;const n=t.toLowerCase();return e.label.toLowerCase().includes(n)||((r=e.keywords)==null?void 0:r.some(o=>o.toLowerCase().includes(n)))}function Ih(e,t){const n=t.anchorNode,r=t.anchorOffset;let o;if(n===e){o="";for(let s=0;s<r&&s<e.childNodes.length;s+=1)o+=e.childNodes[s].textContent??""}else n&&n.parentElement===e?o=(n.textContent??"").slice(0,r):o=e.textContent??"";return nt(o).length}function $o(e,t,n){const r=q(),[o,s]=p.useState(null);p.useEffect(()=>{const u=e.current;if(!u)return;const f=()=>{var S,v,R,_;const h=(S=window.getSelection)==null?void 0:S.call(window),m=h==null?void 0:h.anchorNode;let g=(m==null?void 0:m.nodeType)===1?m:m==null?void 0:m.parentElement;for(;g&&typeof g.hasAttribute=="function"&&!g.hasAttribute("data-run-id");)g=g.parentElement;const x=(v=g==null?void 0:g.getAttribute)==null?void 0:v.call(g,"data-run-id");if(!x||!h){s(null);return}const k=Ih(g,h),y=nt(g.textContent).slice(0,k),I=t.exec(y);if(!I){s(null);return}const w=(_=(R=g.closest)==null?void 0:R.call(g,"[data-block-id]"))==null?void 0:_.getAttribute("data-block-id");if(!w){s(null);return}const j=I.index+I[1].length;s({query:I[2],blockId:w,runId:x,sliceStart:j,sliceEnd:k,rect:g.getBoundingClientRect()})},d=h=>{h.key==="Escape"&&s(null)};return u.addEventListener("input",f),u.addEventListener("keydown",d),()=>{u.removeEventListener("input",f),u.removeEventListener("keydown",d)}},[e,t]);const l=o?n().filter(u=>wh(u,o.query)):[],i=p.useCallback(u=>{o&&(u.run(r,{blockId:o.blockId,runId:o.runId,sliceStart:o.sliceStart,sliceEnd:o.sliceEnd}),s(null))},[o,r]),c=p.useCallback(()=>s(null),[]);return{isOpen:!!o,query:(o==null?void 0:o.query)??"",rect:(o==null?void 0:o.rect)??null,runId:(o==null?void 0:o.runId)??null,commands:l,selectCommand:i,close:c}}const Ch=/(^|\s)\/(\w*)$/;function wi(e){const t=gt(),n=Je(),r=p.useCallback(()=>[...t.listSlashCommands(),...(n==null?void 0:n.listSlashCommands())??[]],[t,n]);return $o(e,Ch,r)}const Sh=[{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 Th(e,{runId:t,sliceStart:n,sliceEnd:r},o){const s=e.getRun(t),l=(s==null?void 0:s.value)??"",i=l.slice(0,n)+o+l.slice(r);e.applyOperation(ue(t,{value:i})),We(t,n+o.length)}const Rh=Sh.map(({char:e,name:t,keywords:n})=>({label:`${e} ${t}`,keywords:n,run:(r,o)=>Th(r,o,e)})),jh=/(^|\s):(\w*)$/,Bh=()=>Rh;function Ii(e){return $o(e,jh,Bh)}const Eh=/(^|\s)@(\w*)$/;function Ci(e){const t=Je(),n=p.useCallback(()=>(t==null?void 0:t.listAtCommands())??[],[t]);return $o(e,Eh,n)}function zo(e,t,n,r,o){const[s,l]=p.useState(!1),i=p.useCallback(k=>{const y=t==="same-block"?Zt(e,n.blockId,n,k):er(e,r,k);return y&&xe(y),y},[e,t,n,r]),c=p.useCallback(k=>{const y=t==="same-block"?Do(e,n.blockId,n,k):Po(e,r,k);y&&xe(y)},[e,t,n,r]),u=p.useCallback(k=>{const y=k==="subscript"?"superscript":"subscript",I=!o[k];i({[k]:I?!0:null,[y]:null})},[o,i]),f=p.useRef(null),d=p.useCallback(()=>{f.current={kind:t,selection:n,crossSelection:r},l(!0)},[t,n,r]),h=p.useCallback(()=>l(!1),[]),m=p.useCallback(k=>{const y=f.current;if(!y)return;const I=y.kind==="same-block"?Zt(e,y.selection.blockId,y.selection,k):er(e,y.crossSelection,k);I&&xe(I),l(!1)},[e]),g=p.useCallback((k,y)=>m({link:{href:k,target:y}}),[m]),x=p.useCallback(()=>m({link:null}),[m]);return{applyPatch:i,toggleBoolean:c,setSubSuper:u,isLinkModalOpen:s,openLinkModal:d,closeLinkModal:h,handleSaveLink:g,handleRemoveLink:x}}const Lh="be-touch-input";function Oh(){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 Ho(){const[e,t]=p.useState(Oh);return p.useEffect(()=>{if(typeof window>"u")return;const n=r=>{t(r.pointerType==="touch"||r.pointerType==="pen")};return window.addEventListener("pointerdown",n,{passive:!0}),()=>window.removeEventListener("pointerdown",n)},[]),p.useEffect(()=>{var n;(n=document.documentElement)==null||n.classList.toggle(Lh,e)},[e]),e}const _h=[{markName:"bold",Icon:bl,title:"Bold (Ctrl+B)"},{markName:"italic",Icon:ml,title:"Italic (Ctrl+I)"},{markName:"underline",Icon:gl,title:"Underline (Ctrl+U)"},{markName:"strike",Icon:qc,title:"Strikethrough"}],Nh=[{label:"Default",value:null},{label:"Red",value:"#e03131"},{label:"Orange",value:"#e8590c"},{label:"Green",value:"#2f9e44"},{label:"Blue",value:"#1971c2"},{label:"Purple",value:"#9c36b5"}],Mh=[{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 Si({isOpen:e,rect:t,kind:n,selection:r,crossSelection:o,marks:s,store:l}){var j,S;const i=Ho(),[c,u]=p.useState(null),f=p.useRef(null),{applyPatch:d,toggleBoolean:h,setSubSuper:m,isLinkModalOpen:g,openLinkModal:x,closeLinkModal:k,handleSaveLink:y,handleRemoveLink:I}=zo(l,n,r,o,s);p.useEffect(()=>{if(!c)return;const v=_=>{f.current&&!f.current.contains(_.target)&&u(null)},R=_=>{_.key==="Escape"&&u(null)};return document.addEventListener("mousedown",v),document.addEventListener("keydown",R),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",R)}},[c]),p.useEffect(()=>{u(null)},[t,n]);const w=oa(f,!!(e&&t),t?t.left+t.width/2:null);return i||(!e||!t)&&!g?null:a.jsxs(a.Fragment,{children:[e&&t&&w!=null&&a.jsxs("div",{ref:f,className:"be-floating-toolbar",role:"toolbar","aria-label":"Text formatting",style:{position:"fixed",top:t.top-44,left:w,transform:"translateX(-50%)"},onMouseDown:v=>v.preventDefault(),children:[_h.map(({markName:v,Icon:R,title:_})=>a.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s[v]?" be-floating-toolbar-btn-active":""}`,title:_,"aria-label":_,"aria-pressed":!!s[v],onClick:()=>h(v),children:a.jsx(R,{})},v)),a.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.subscript?" be-floating-toolbar-btn-active":""}`,title:"Subscript","aria-pressed":!!s.subscript,onClick:()=>m("subscript"),children:"X₂"}),a.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.superscript?" be-floating-toolbar-btn-active":""}`,title:"Superscript","aria-pressed":!!s.superscript,onClick:()=>m("superscript"),children:"X²"}),a.jsx("span",{className:"be-floating-toolbar-divider"}),a.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[a.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Text color","aria-haspopup":"true","aria-expanded":c==="color",onClick:()=>u(v=>v==="color"?null:"color"),children:a.jsx("span",{style:{color:s.color||"inherit",fontWeight:700},children:"A"})}),c==="color"&&a.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Text color",children:Nh.map(v=>a.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",title:v.label,onClick:()=>{d({color:v.value}),u(null)},children:a.jsx("span",{style:{color:v.value||"#1a1a1a",fontWeight:700},children:"A"})},v.label))})]}),a.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[a.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Highlight","aria-haspopup":"true","aria-expanded":c==="highlight",onClick:()=>u(v=>v==="highlight"?null:"highlight"),children:a.jsx("span",{style:{backgroundColor:s.highlight||"transparent",padding:"0 2px",borderRadius:2},children:"H"})}),c==="highlight"&&a.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Highlight color",children:Mh.map(v=>a.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",style:{backgroundColor:v.value||"transparent"},title:v.label,onClick:()=>{d({highlight:v.value}),u(null)}},v.label))})]}),a.jsx("span",{className:"be-floating-toolbar-divider"}),a.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.link?" be-floating-toolbar-btn-active":""}`,title:"Link","aria-label":"Link","aria-pressed":!!s.link,onClick:x,children:a.jsx(kl,{})})]}),a.jsx(fl,{isOpen:g,initialHref:((j=s.link)==null?void 0:j.href)??"",initialTarget:((S=s.link)==null?void 0:S.target)??"_self",hasExistingLink:!!s.link,onSave:y,onRemove:I,onClose:k})]})}function Ti(e){const t=q(),[n,r]=p.useState(null);return p.useEffect(()=>{const o=e.current;if(!o)return;const s=()=>{var f,d,h;const l=(f=window.getSelection)==null?void 0:f.call(window);if(!l||l.rangeCount===0||l.isCollapsed){r(null);return}if(!o.contains(l.anchorNode)||!o.contains(l.focusNode)){r(null);return}const i=((h=(d=l.getRangeAt(0)).getBoundingClientRect)==null?void 0:h.call(d))??{top:0,left:0,right:0,bottom:0,width:0,height:0},c=tn();if(c){r({kind:"same-block",rect:i,selection:c,marks:Mo(t,c.blockId,c)});return}const u=Gt(t);if(u){r({kind:"cross-block",rect:i,crossSelection:u,marks:Ao(t,u)});return}r(null)};return document.addEventListener("selectionchange",s),window.addEventListener("scroll",s,!0),window.addEventListener("resize",s),()=>{document.removeEventListener("selectionchange",s),window.removeEventListener("scroll",s,!0),window.removeEventListener("resize",s)}},[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:()=>r(null)}}function Ah({store:e,rootId:t}){const n=p.useRef(null),{onCopy:r,onCut:o,onPaste:s}=hi(),l=wi(n),i=Ii(n),c=Ci(n),u=Ti(n);return yi(n),vi(n),a.jsxs("div",{ref:n,role:"document","aria-label":"Document editor",onCopy:r,onCut:o,onPaste:s,children:[a.jsx(di,{}),a.jsx(ut,{parentId:t,isTopLevel:!0}),a.jsx(li,{}),a.jsx(Xn,{isOpen:l.isOpen,rect:l.rect,commands:l.commands,runId:l.runId,onSelect:l.selectCommand,onClose:l.close}),a.jsx(Xn,{isOpen:i.isOpen,rect:i.rect,commands:i.commands,runId:i.runId,onSelect:i.selectCommand,onClose:i.close,menuId:"be-emoji-menu",ariaLabel:"Emoji"}),a.jsx(Xn,{isOpen:c.isOpen,rect:c.rect,commands:c.commands,runId:c.runId,onSelect:c.selectCommand,onClose:c.close,menuId:"be-at-menu",ariaLabel:"Mention"}),a.jsx(Si,{isOpen:u.isOpen,rect:u.rect,kind:u.kind,selection:u.selection,crossSelection:u.crossSelection,marks:u.marks,store:e})]})}function Dh({editor:e,className:t,style:n,theme:r,getBlockClassName:o,children:s}){const{store:l,registry:i,inlineRegistry:c}=e,u=l.getRootId();return a.jsxs(il,{store:l,registry:i,inlineRegistry:c,history:l,className:t,style:n,theme:r,getBlockClassName:o,children:[a.jsx(Ah,{store:l,rootId:u}),s]})}const Ph="$fieldTypes";function Ri(){const e=q(),t=p.useCallback(r=>e.subscribe(Ph,r),[e]),n=p.useCallback(()=>e.getFieldTypes(),[e]);return p.useSyncExternalStore(t,n)}const $h={canUndo:!1,canRedo:!1};function ji(){const{history:e}=Ge(),t=p.useCallback(o=>e?e.subscribeToHistory(o):()=>{},[e]),n=p.useCallback(()=>e?e.getUndoRedoSnapshot():$h,[e]),r=p.useSyncExternalStore(t,n);return e?{...r,undo:()=>{const o=e.undo();return o&&Qt(e),o},redo:()=>{const o=e.redo();return o&&Qt(e),o},getHistoryLog:()=>e.getHistoryLog()}:null}function zh({store:e,docId:t,debounceMs:n,onError:r}){const[o,s]=p.useState(!1);return p.useEffect(()=>{let l=!1;s(!1),el(t).then(u=>{if(!l&&u){const f=e.store??e;f.blocks=new Map((u.blocks??[]).map(d=>[d.id,d])),f.runs=new Map((u.runs??[]).map(d=>[d.id,d])),f.rootId=u.rootId??null,f.fieldTypes=new Map((u.fieldTypes??[]).map(d=>[d.id,d])),f._fieldTypesSnapshot=null,f._orders=new Map,f._notify([...f.blocks.keys(),...f.runs.keys()])}}).catch(u=>r==null?void 0:r(u)).finally(()=>{l||s(!0)});const{stop:i,flush:c}=tl({store:e,docId:t,debounceMs:n,onError:r});return()=>{l=!0,c(),i()}},[t]),{isLoaded:o}}function Hh(e){const[t,n]=p.useState(()=>(e==null?void 0:e.getPresence())??new Map);return p.useEffect(()=>{if(!e){n(new Map);return}return n(e.getPresence()),e.onPresenceChange(n)},[e]),t}function Fh(){const[e,t]=p.useState(!1),[n,r]=p.useState(null);p.useEffect(()=>{if(!navigator.serviceWorker)return;let s=!1;function l(i){if(!i)return;const c=()=>{i.waiting&&(r(i.waiting),t(!0))};c(),i.addEventListener("updatefound",()=>{const u=i.installing;u&&u.addEventListener("statechange",()=>{u.state==="installed"&&navigator.serviceWorker.controller&&c()})})}return navigator.serviceWorker.getRegistration().then(i=>{s||l(i)}),()=>{s=!0}},[]);const o=p.useCallback(()=>{if(!n)return;const s=()=>window.location.reload();navigator.serviceWorker.addEventListener("controllerchange",s,{once:!0}),n.postMessage({type:"SKIP_WAITING"})},[n]);return{updateAvailable:e,applyUpdate:o}}const Bi=[{phrases:["new paragraph","next paragraph"],description:"Start a new paragraph",action:{type:"insertParagraph"}},{phrases:["heading one","heading 1"],description:"Convert the current block to a heading 1",action:{type:"convertBlock",blockType:"heading",props:{level:1}}},{phrases:["heading two","heading 2"],description:"Convert the current block to a heading 2",action:{type:"convertBlock",blockType:"heading",props:{level:2}}},{phrases:["heading three","heading 3"],description:"Convert the current block to a heading 3",action:{type:"convertBlock",blockType:"heading",props:{level:3}}},{phrases:["bulleted list","bullet point","bullet list"],description:"Convert the current block to a bulleted list item",action:{type:"convertBlock",blockType:"listItem",props:{ordered:!1,titleRunIds:[]}}},{phrases:["numbered list","ordered list"],description:"Convert the current block to a numbered list item",action:{type:"convertBlock",blockType:"listItem",props:{ordered:!0,titleRunIds:[]}}},{phrases:["checklist","to-do","to do","to-do list","to do list"],description:"Convert the current block to a to-do item",action:{type:"convertBlock",blockType:"listItem",props:{ordered:!1,checked:!1,titleRunIds:[]}}},{phrases:["quote"],description:"Convert the current block to a quote",action:{type:"convertBlock",blockType:"blockquote",props:{}}},{phrases:["code block","code"],description:"Convert the current block to a code block",action:{type:"convertBlock",blockType:"code",props:{language:"plaintext"}}},{phrases:["undo"],description:"Undo the last edit",action:{type:"undo"}},{phrases:["redo"],description:"Redo the last undone edit",action:{type:"redo"}},{phrases:["stop dictation","stop listening","stop"],description:"Stop dictation",action:{type:"stopDictation"}}],Ei=new Map;for(const{phrases:e,action:t}of Bi)for(const n of e)Ei.set(n,t);function Uh(e){return(e??"").toLowerCase().trim().replace(/\s+/g," ").replace(/[.,!?]+$/,"")}function Yh(e){return Ei.get(Uh(e))??null}function Kh(){return Bi.map(({phrases:e,description:t})=>({phrases:[...e],description:t}))}function Vh(e,t){if(typeof e.performBatch=="function")e.performBatch(t);else for(const n of t)e.applyOperation(n)}function Wh(e){var t;return((t=e==null?void 0:e.props)==null?void 0:t.titleRunIds)??(e==null?void 0:e.contentIds)??[]}function Xh(e,t,n){var r,o;if(n.type==="insertParagraph"){Ze(e,t,Z("paragraph"));return}if(n.type==="convertBlock"){const s=e.getBlock(t);if(!s)return;const l=Wh(s),{ops:i}=mo(e,t,n.blockType,n.props,l);Vh(e,i),l[0]&&rr(l[0]);return}if(n.type==="undo"){(r=e.undo)!=null&&r.call(e)&&Qt(e);return}n.type==="redo"&&(o=e.redo)!=null&&o.call(e)&&Qt(e)}function Ws(){return typeof window>"u"?null:window.SpeechRecognition??window.webkitSpeechRecognition??null}const qh="Microphone access is blocked. Enable it in your browser's site settings, then try again.";function Gh({shortcut:e=!0}={}){const t=q(),[n,r]=p.useState(!1),[o,s]=p.useState("idle"),[l,i]=p.useState("unknown"),[c,u]=p.useState(null),f=p.useRef(null),d=p.useRef(null),h=p.useRef(null),m=p.useRef(0),g=Ws()!==null;p.useEffect(()=>{var R;if(!((R=navigator.permissions)!=null&&R.query))return;let S,v=!1;return navigator.permissions.query({name:"microphone"}).then(_=>{v||(S=_,i(_.state),S.onchange=()=>i(S.state))}).catch(()=>{}),()=>{v=!0,S&&(S.onchange=null)}},[]);const x=p.useCallback(()=>{if(!d.current){const S=rt();if(!S)return null;d.current=S}return{runId:d.current.runId,blockId:d.current.blockId,startOffset:d.current.offset,insertedLength:0}},[]),k=p.useCallback((S,v)=>{const R=t.getRun(S.runId);if(!R||R.type!=="text")return;const _=R.value??"",O=_.slice(0,S.startOffset);if(S.needsLeadingSpace===void 0){const M=O[O.length-1];S.needsLeadingSpace=S.startOffset>0&&M!==void 0&&!/\s/.test(M)}const C=(S.needsLeadingSpace?" ":"")+v,B=_.slice(S.startOffset+S.insertedLength);Xe.flushSync(()=>t.applyOperation(ue(S.runId,{value:O+C+B}))),S.insertedLength=C.length,gs(S.runId,S.startOffset+C.length),d.current={runId:S.runId,blockId:S.blockId,offset:S.startOffset+C.length}},[t]),y=p.useCallback(S=>{const v=t.getRun(S.runId);if(!v||v.type!=="text")return;const R=v.value??"",_=R.slice(0,S.startOffset)+R.slice(S.startOffset+S.insertedLength);Xe.flushSync(()=>t.applyOperation(ue(S.runId,{value:_}))),gs(S.runId,S.startOffset),d.current={runId:S.runId,blockId:S.blockId,offset:S.startOffset}},[t]),I=p.useCallback(S=>{var O,C;let v="",R=!1;const _=Math.max(S.resultIndex,m.current);for(let B=_;B<S.results.length;B+=1){const M=S.results[B],z=((O=M[0])==null?void 0:O.transcript)??"";if(!M.isFinal){v+=(v?" ":"")+z,R=!0;continue}const Y=h.current??x();if(h.current=null,m.current=B+1,!Y)continue;const W=Yh(z);W?(y(Y),W.type==="stopDictation"?(C=f.current)==null||C.stop():(Xh(t,Y.blockId,W),d.current=null,s("listening"))):(k(Y,z),s("listening"))}if(R){const B=h.current??x();B&&(h.current=B,k(B,v))}},[t,x,k,y]),w=p.useCallback(()=>{if(!g||f.current)return;u(null),d.current=rt(),h.current=null,m.current=0;const S=Ws(),v=new S;v.continuous=!0,v.interimResults=!0,v.onresult=I,v.onstart=()=>s("listening"),v.onspeechstart=()=>s("listening"),v.onspeechend=()=>s("processing"),v.onerror=R=>{R.error==="not-allowed"||R.error==="service-not-allowed"?(i("denied"),u(qh)):u(R.error??"Voice typing stopped unexpectedly.")},v.onend=()=>{f.current=null,d.current=null,h.current=null,m.current=0,r(!1),s("idle")},f.current=v,v.start(),r(!0)},[g,I]),j=p.useCallback(()=>{var S;(S=f.current)==null||S.stop()},[]);return p.useEffect(()=>()=>{var S;return(S=f.current)==null?void 0:S.stop()},[]),p.useEffect(()=>{if(!e||!g)return;const S=v=>{!(v.metaKey||v.ctrlKey)||!v.shiftKey||v.key.toLowerCase()!=="m"||(v.preventDefault(),f.current?j():w())};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[e,g,w,j]),{isSupported:g,isListening:n,status:o,permissionState:l,error:c,start:w,stop:j}}function Jh({voice:e}){const[t,n]=p.useState(!1);p.useEffect(()=>{n(!1)},[e==null?void 0:e.error]);const r=(e==null?void 0:e.permissionState)==="denied"&&!t;return a.jsxs(at,{isOpen:r,onClose:()=>n(!0),title:"Microphone access blocked",children:[a.jsx("p",{children:(e==null?void 0:e.error)||"Microphone access is blocked. Enable it in your browser's site settings, then try again."}),a.jsxs("div",{className:"be-modal-actions",children:[a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:()=>n(!0),children:"Dismiss"}),a.jsx("button",{type:"button",className:"be-modal-save",onClick:()=>{var o;return(o=e==null?void 0:e.start)==null?void 0:o.call(e)},children:"Try again"})]})]})}function Li(e){const[t,n]=p.useState(null);return p.useEffect(()=>{if(!e){n(null);return}const r=()=>{var c,u,f,d;const o=(c=window.getSelection)==null?void 0:c.call(window);if(!o||o.rangeCount===0||!o.isCollapsed){n(null);return}const s=o.anchorNode,l=(s==null?void 0:s.nodeType)===1?s:s==null?void 0:s.parentElement;if(!((u=l==null?void 0:l.closest)!=null&&u.call(l,"[data-run-id]"))){n(null);return}const i=((d=(f=o.getRangeAt(0)).getBoundingClientRect)==null?void 0:d.call(f))??{top:0,left:0,right:0,bottom:0,width:0,height:0};n(i)};return r(),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}function Zh({voice:e}){const t=!!(e!=null&&e.isListening),n=Li(t),r=p.useRef(null),o=oa(r,!!(t&&n),n==null?void 0:n.left);if(!t||!n||o==null)return null;const s=e.status==="processing";return Xe.createPortal(a.jsxs("div",{ref:r,className:`be-voice-indicator${s?" be-voice-indicator-processing":""}`,contentEditable:!1,style:{position:"fixed",top:n.top-8,left:o,transform:"translate(-50%, -100%)"},children:[a.jsx("span",{className:"be-voice-indicator-dot"}),a.jsx(bu,{size:12}),a.jsx("span",{className:"be-voice-indicator-label",children:s?"Processing…":"Listening…"})]}),document.body)}function Oi({isOpen:e,onClose:t,onSelectCommand:n}){const r=gt(),o=Je(),s=p.useMemo(()=>[...(r==null?void 0:r.listSlashCommands())??[],...(o==null?void 0:o.listSlashCommands())??[]],[r,o]);return a.jsx(at,{isOpen:e,onClose:t,title:"Add a block",variant:"sheet",children:a.jsx("div",{className:"be-mobile-picker-list",role:"listbox","aria-label":"Insertable blocks",children:s.map(l=>{const i=l.icon;return a.jsxs("button",{type:"button",role:"option",className:"be-mobile-picker-item",onClick:()=>n(l),children:[i&&a.jsx("span",{className:"be-mobile-picker-item-icon",children:a.jsx(i,{size:18})}),a.jsx("span",{className:"be-mobile-picker-item-label",children:l.label})]},l.label)})})})}function _i({isOpen:e,onClose:t,store:n,blockId:r}){var i;const o=r?n.getBlock(r):null,s=!!((i=o==null?void 0:o.props)!=null&&i.hidden),l=p.useCallback(c=>{c(),t()},[t]);return a.jsx(at,{isOpen:e,onClose:t,title:"Block options",variant:"sheet",children:a.jsxs("div",{className:"be-mobile-picker-list",role:"menu","aria-label":"Block options",children:[a.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>l(()=>{wo(n,r),me("Block duplicated")}),children:[a.jsx("span",{className:"be-mobile-picker-item-icon",children:a.jsx(ao,{size:18})}),a.jsx("span",{className:"be-mobile-picker-item-label",children:"Duplicate"})]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>l(()=>{Io(n,r)&&me("Block moved up")}),children:[a.jsx("span",{className:"be-mobile-picker-item-icon",children:a.jsx(ir,{size:18})}),a.jsx("span",{className:"be-mobile-picker-item-label",children:"Move up"})]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>l(()=>{Co(n,r)&&me("Block moved down")}),children:[a.jsx("span",{className:"be-mobile-picker-item-icon",children:a.jsx(cr,{size:18})}),a.jsx("span",{className:"be-mobile-picker-item-label",children:"Move down"})]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>l(()=>{n.applyOperation(X(r,{hidden:!s})),me(s?"Block shown in preview":"Block hidden in preview")}),children:[a.jsx("span",{className:"be-mobile-picker-item-icon",children:s?a.jsx(fo,{size:18}):a.jsx(ho,{size:18})}),a.jsx("span",{className:"be-mobile-picker-item-label",children:s?"Show in preview":"Hide in preview"})]}),a.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item be-mobile-picker-item-danger",onClick:()=>l(()=>{fr(n,r),me("Block deleted")}),children:[a.jsx("span",{className:"be-mobile-picker-item-icon",children:a.jsx(ar,{size:18})}),a.jsx("span",{className:"be-mobile-picker-item-label",children:"Delete"})]})]})})}const Qh=xa.map(e=>({value:e,label:e}));function eb(e,t){const[n,r]=p.useState(!1),[o,s]=p.useState(null),[l,i]=p.useState(null),[c,u]=p.useState(null);return p.useEffect(()=>{const f=e.current;if(!f)return;const d=()=>r(!0),h=m=>{f.contains(m.relatedTarget)||r(!1)};return f.addEventListener("focusin",d),f.addEventListener("focusout",h),()=>{f.removeEventListener("focusin",d),f.removeEventListener("focusout",h)}},[e]),p.useEffect(()=>{if(!n){s(null);return}const f=()=>{var g;const d=e.current,h=(g=window.getSelection)==null?void 0:g.call(window);if(!d||!h||h.rangeCount===0){s(null);return}if(!h.isCollapsed){if(!d.contains(h.anchorNode)||!d.contains(h.focusNode)){s(null);return}const x=tn();if(x){i({kind:"same-block",selection:x,crossSelection:null,marks:Mo(t,x.blockId,x)}),s("selection");return}const k=Gt(t);if(k){i({kind:"cross-block",selection:null,crossSelection:k,marks:Ao(t,k)}),s("selection");return}s(null);return}const m=rt();if(!m||!d.contains(h.anchorNode)){s(null);return}u(m),s("caret")};return f(),document.addEventListener("selectionchange",f),()=>document.removeEventListener("selectionchange",f)},[n,t,e]),{isFocused:n,mode:o,selectionState:l,caretState:c}}function tb({store:e,selectionState:t}){const{kind:n,selection:r,crossSelection:o,marks:s}=t,{toggleBoolean:l,openLinkModal:i}=zo(e,n,r,o,s);return a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.bold?" be-mobile-bar-btn-active":""}`,"aria-label":"Bold",onClick:()=>l("bold"),children:a.jsx(bl,{size:18})}),a.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.italic?" be-mobile-bar-btn-active":""}`,"aria-label":"Italic",onClick:()=>l("italic"),children:a.jsx(ml,{size:18})}),a.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.underline?" be-mobile-bar-btn-active":""}`,"aria-label":"Underline",onClick:()=>l("underline"),children:a.jsx(gl,{size:18})}),a.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.link?" be-mobile-bar-btn-active":""}`,"aria-label":"Link",onClick:i,children:a.jsx(kl,{size:18})})]})}function nb({store:e,blockId:t}){const n=p.useCallback(()=>{const o=e.getBlock(t),s=o&&e.getBlock(o.parentId);s&&To(e,s.id)},[e,t]),r=p.useCallback(()=>{const o=e.getBlock(t),s=o&&e.getBlock(o.parentId),l=s&&e.getBlock(s.parentId);if(!l||!s)return;const i=s.contentIds.indexOf(t);i!==-1&&Gn(e,l.id,i)},[e,t]);return a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert row below",onClick:n,children:"+ Row"}),a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert column right",onClick:r,children:"+ Column"})]})}function rb({store:e,blockId:t}){var o;const n=e.getBlock(t),r=p.useCallback(s=>e.applyOperation(X(t,{language:s})),[e,t]);return a.jsx(Rt,{className:"be-mobile-bar-select",value:((o=n==null?void 0:n.props)==null?void 0:o.language)??"plaintext",options:Qh,onChange:r,ariaLabel:"Code language"})}function ob({store:e,blockId:t}){var o;const n=e.getBlock(t),r=(o=n==null?void 0:n.props)==null?void 0:o.color;return a.jsx("div",{className:"be-mobile-bar-swatches",children:ba.map(s=>a.jsx("button",{type:"button",className:`be-callout-color-option be-callout-color-option-${s.value}${s.value===r?" be-callout-color-option-active":""}`,"aria-label":s.label,title:s.label,onClick:()=>e.applyOperation(X(t,{color:s.value}))},s.value))})}const Ni={tableCell:nb,code:rb,callout:ob};function sb(e,t){let n=e.getBlock(t);for(;n;){if(Ni[n.type])return n;n=n.parentId?e.getBlock(n.parentId):null}return null}function lb(e,t){const n=e.getRootId();let r=e.getBlock(t);for(;r&&r.parentId!==n;)r=e.getBlock(r.parentId);return r}function ab({containerRef:e}){var R,_;const t=q(),n=ji(),r=Ho(),o=gr(),{isFocused:s,mode:l,selectionState:i,caretState:c}=eb(e,t),[u,f]=p.useState(!1),[d,h]=p.useState(!1),m=p.useCallback(()=>f(!0),[]),g=p.useCallback(()=>f(!1),[]),x=p.useCallback(()=>h(!0),[]),k=p.useCallback(()=>h(!1),[]),y=p.useCallback(O=>{const C=rt()??c;C&&(O.run(t,{blockId:C.blockId,runId:C.runId,sliceStart:C.offset,sliceEnd:C.offset}),g())},[t,c,g]),I=p.useCallback(()=>{var O,C;(C=(O=document.activeElement)==null?void 0:O.blur)==null||C.call(O)},[]);if(!r||!s)return null;const w=l==="caret"&&c?sb(t,c.blockId):null,j=w?Ni[w.type]:null,S=l==="caret"&&c?c.blockId:((R=i==null?void 0:i.selection)==null?void 0:R.blockId)??((_=i==null?void 0:i.crossSelection)==null?void 0:_.startBlockId)??null,v=S?lb(t,S):null;return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"be-mobile-action-bar",role:"toolbar","aria-label":"Editor actions",style:{bottom:o},onMouseDown:O=>O.preventDefault(),children:[l==="selection"&&i&&a.jsx(tb,{store:t,selectionState:i}),l!=="selection"&&a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Add block",onClick:m,children:a.jsx(lo,{size:18})}),j&&w&&a.jsx(j,{store:t,blockId:w.id}),n&&a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Undo",disabled:!n.canUndo,onClick:n.undo,children:"↶"}),a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Redo",disabled:!n.canRedo,onClick:n.redo,children:"↷"})]})]}),a.jsx("span",{className:"be-mobile-bar-spacer"}),v&&a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Block options",onClick:x,children:a.jsx(Wc,{size:18})}),a.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Dismiss keyboard",onClick:I,children:a.jsx(lr,{size:18})})]}),a.jsx(Oi,{isOpen:u,onClose:g,onSelectCommand:y}),a.jsx(_i,{isOpen:d,onClose:k,store:t,blockId:v==null?void 0:v.id})]})}function Mi(e,{pretty:t=!0}={}){const n=e.getRootId(),{blocks:r,runs:o}=yo(e,n);return JSON.stringify({version:1,rootId:n,blocks:r,runs:o},null,t?2:0)}function Ai(e,t,n){const r=e.getBlock(e.getRootId());return r?Rn(e,t,r.contentIds,n).html:""}function Di(e,t,n){const r=e.getBlock(e.getRootId());return r?Rn(e,t,r.contentIds,n).text:""}const Pi={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"]},$i=new Set(["listItem","toggleHeading"]),zi=new Set(["divider","embed"]);function Hi(e,t,n,r){var i,c,u;const o=n.type,s={};for(const f of Pi[o]??[])((i=n.props)==null?void 0:i[f])!==void 0&&(s[f]=n.props[f]);if(o==="table"){const f=n.contentIds[0]&&e.getBlock(n.contentIds[0]);return s.columns=De(n,((c=f==null?void 0:f.contentIds)==null?void 0:c.length)??0),s.rows=n.contentIds.map(d=>e.getBlock(d).contentIds.map(m=>{const g=e.getBlock(m);return Or(g.contentIds.map(x=>e.getRun(x)),r)})),{id:n.id,type:o,data:s}}if($i.has(o)){const f=((u=n.props)==null?void 0:u.titleRunIds)??[];s.text=Or(f.map(d=>e.getRun(d)),r)}else t.isLeaf(o)&&!zi.has(o)&&(s.text=Or(n.contentIds.map(f=>e.getRun(f)),r));const l={id:n.id,type:o,data:s};return t.isLeaf(o)||(l.children=n.contentIds.map(f=>Hi(e,t,e.getBlock(f),r))),l}function Fi(e,t,n,{pretty:r=!0}={}){const o={store:e,registry:t,inlineRegistry:n},l=e.getBlock(e.getRootId()).contentIds.map(i=>Hi(e,t,e.getBlock(i),o));return JSON.stringify({version:1,blocks:l},null,r?2:0)}function Jr(e,t){const n=new DOMParser().parseFromString(`<div>${e??""}</div>`,"text/html");return Fe(n.body.firstChild,t)}function ib(e,t,n,r,o){const{id:s=N(),data:l={}}=e,i=(l.rows??[]).map(u=>{const f=N(),d=u.map(h=>{const m=N(),g=Jr(h,o);return r.push(...g),n.push({id:m,type:"tableCell",parentId:f,contentIds:g.map(x=>x.id),props:{}}),m});return n.push({id:f,type:"tableRow",parentId:t,contentIds:d,props:{}}),f}),c={id:s,type:"table",parentId:t,contentIds:i,props:{columns:l.columns??[]}};return n.push(c),c}function Zr(e,t,n,r,o,s){const{id:l=N(),type:i,data:c={},children:u=[]}=e;if(i==="table")return ib(e,t,o,s,r);const f={};for(const h of Pi[i]??[])c[h]!==void 0&&(f[h]=c[h]);const d={id:l,type:i,parentId:t,contentIds:[],props:f};if(o.push(d),$i.has(i)){const h=Jr(c.text,r);s.push(...h),d.props.titleRunIds=h.map(m=>m.id),d.contentIds=u.map(m=>Zr(m,l,n,r,o,s).id)}else if(n.isLeaf(i)){if(!zi.has(i)){const h=Jr(c.text,r);s.push(...h),d.contentIds=h.map(m=>m.id)}}else d.contentIds=u.map(h=>Zr(h,l,n,r,o,s).id);return d}function cb(e,t,n){const r=typeof e=="string"?JSON.parse(e):e,o={registry:t,inlineRegistry:n},s=N(),l=[],i=[],c=(r.blocks??[]).map(u=>Zr(u,s,t,o,l,i).id);return l.push({id:s,type:"page",parentId:null,contentIds:c,props:{}}),{rootId:s,blocks:l,runs:i}}const ub=[{value:"json",label:"JSON"},{value:"simpleJson",label:"Simple JSON"},{value:"html",label:"HTML"},{value:"text",label:"Text"}];function db({label:e="View source",className:t=""}){const n=q(),r=gt(),o=Je(),[s,l]=p.useState(!1),[i,c]=p.useState("json"),[u,f]=p.useState(!1),d=p.useCallback(()=>{f(!1),l(!0)},[]),h=p.useCallback(()=>l(!1),[]),m=p.useMemo(()=>s?i==="json"?Mi(n):i==="simpleJson"?Fi(n,r,o):i==="html"?Ai(n,r,o):Di(n,r,o):"",[s,i,n,r,o]),g=p.useCallback(async()=>{try{await navigator.clipboard.writeText(m),f(!0),setTimeout(()=>f(!1),1500)}catch{}},[m]);return a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:`be-export-trigger ${t}`.trim(),onClick:d,children:[a.jsx(uo,{size:14})," ",e]}),a.jsxs(at,{isOpen:s,onClose:h,title:"Document source",size:"large",children:[a.jsx("div",{className:"be-export-tabs",role:"tablist",children:ub.map(x=>a.jsx("button",{type:"button",role:"tab","aria-selected":i===x.value,className:`be-export-tab${i===x.value?" be-export-tab-active":""}`,onClick:()=>c(x.value),children:x.label},x.value))}),a.jsx("pre",{className:"be-export-pre",children:a.jsx("code",{children:m})}),a.jsxs("div",{className:"be-modal-actions",children:[a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:h,children:"Close"}),a.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:u?"Copied!":"Copy"})]})]})]})}function pb({id:e,label:t,placeholder:n,variant:r,options:o,onManage:s,mention:l=!1}){const i=q(),c=xt(e),u=p.useCallback((m,g)=>{i.applyOperation(ue(e,{data:{selectedValue:m,selectedLabel:(g==null?void 0:g.label)??"",selectedColor:g==null?void 0:g.color}}))},[i,e]);if(!c)return null;const{selectedValue:f="",selectedLabel:d="",selectedColor:h}=c.data??{};return a.jsx("span",{className:"be-inline-select",onMouseDown:m=>{m.preventDefault(),m.stopPropagation()},onKeyDown:m=>m.stopPropagation(),children:a.jsx(Rt,{value:f,selectedLabel:d,selectedColor:h,options:o,onChange:u,placeholder:n,variant:r,ariaLabel:t,onManageOptions:s,mention:l})})}function Ui(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Xs(e){return Ui(e).replace(/"/g,""")}function Yi({type:e,label:t,placeholder:n="Select…",variant:r="default",icon:o,options:s,onManage:l,triggers:i=["slash"],mention:c=i.includes("at")}){function u(g){var y,I;const x=((y=g.data)==null?void 0:y.selectedLabel)||"",k=c&&x?`@${x}`:x;return`<span data-inline-type="${Xs(e)}" data-selected-value="${Xs(((I=g.data)==null?void 0:I.selectedValue)??"")}">${Ui(k)}</span>`}function f(g){var k;const x=((k=g.data)==null?void 0:k.selectedLabel)??"";return c&&x?`@${x}`:x}function d(g){var y;if(((y=g.getAttribute)==null?void 0:y.call(g,"data-inline-type"))!==e)return null;const x=g.textContent??"",k=c&&x.startsWith("@")?x.slice(1):x;return{id:N(),type:e,value:"",marks:{},data:{selectedValue:g.getAttribute("data-selected-value")??"",selectedLabel:k}}}function h({id:g}){return a.jsx(pb,{id:g,label:t,placeholder:n,variant:r,options:s,onManage:l,mention:c})}const m={label:t,icon:o??Ll,keywords:[t.toLowerCase(),"select","field"],run:(g,{blockId:x,runId:k,sliceStart:y,sliceEnd:I})=>kr(g,{blockId:x,runId:k,sliceStart:y,sliceEnd:I},()=>({id:N(),type:e,value:"",marks:{},data:{selectedValue:"",selectedLabel:"",selectedColor:void 0}}))};return{component:h,isAtomic:!0,toHTML:u,toPlainText:f,fromHTML:d,slashCommand:i.includes("slash")?m:void 0,atCommand:i.includes("at")?m:void 0}}function Ki(e,t,{onManage:n}={}){for(const r of e.getFieldTypes())t.register(r.id,Yi({type:r.id,label:r.label,placeholder:r.placeholder,variant:r.variant,options:r.options??[],onManage:n?()=>n(r.id):void 0}))}function Vi(){const e=q(),t=Je(),n=Ri(),{openEdit:r}=so(),o=p.useRef([]);p.useEffect(()=>{if(!t)return;const s=new Set(n.map(l=>l.id));for(const l of o.current)s.has(l)||t.unregister(l);Ki(e,t,{onManage:r}),o.current=[...s]},[e,t,n,r])}function fb(){Vi();const e=q(),{target:t,close:n}=so(),r=t!==null,o=r&&t!=="new",[s,l]=p.useState(""),[i,c]=p.useState([]),[u,f]=p.useState("");p.useEffect(()=>{if(r){if(o){const k=e.getFieldType(t);l((k==null?void 0:k.label)??""),c((k==null?void 0:k.options)??[])}else l(""),c([]);f("")}},[r,o,t,e]);const d=p.useCallback((k,y)=>{c(I=>I.map(w=>w.value===k?{...w,label:y}:w))},[]),h=p.useCallback(k=>{c(y=>y.filter(I=>I.value!==k))},[]),m=p.useCallback(()=>{const k=u.trim();f(""),k&&c(y=>[...y,{value:N(),label:k,color:vn(y.length)}])},[u]),g=p.useCallback(()=>{const k=s.trim();k&&(o?e.applyOperation(to(t,{label:k,options:i})):e.applyOperation(eo({id:N(),label:k,placeholder:"Select…",variant:"tag",options:i})),n())},[e,o,t,s,i,n]),x=p.useCallback(()=>{o&&e.applyOperation(no(t)),n()},[e,o,t,n]);return a.jsxs(at,{isOpen:r,onClose:n,title:o?"Edit field type":"New field type",children:[a.jsxs("label",{className:"be-modal-field",children:[a.jsx("span",{children:"Name"}),a.jsx("input",{type:"text",value:s,onChange:k=>l(k.target.value),placeholder:"e.g. Priority, Status…",autoFocus:!0})]}),a.jsxs("div",{className:"be-modal-field",children:[a.jsx("span",{children:"Options"}),i.map((k,y)=>a.jsxs("div",{className:"be-table-header-menu-option-row",children:[a.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(k.color??vn(y)).bg},"aria-hidden":"true"}),a.jsx("input",{className:"be-table-header-menu-option-input",value:k.label,onChange:I=>d(k.value,I.target.value),"aria-label":`Rename option ${k.label}`}),a.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>h(k.value),"aria-label":`Remove option ${k.label}`,children:a.jsx(en,{size:14})})]},k.value)),a.jsxs("div",{className:"be-table-header-menu-option-row",children:[a.jsx("input",{className:"be-table-header-menu-option-input",value:u,onChange:k=>f(k.target.value),placeholder:"New option…",onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),m())}}),a.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:m,"aria-label":"Add option",children:"+"})]})]}),a.jsxs("div",{className:"be-modal-actions",children:[o&&a.jsx("button",{type:"button",className:"be-modal-delete",onClick:x,children:"Delete field type"}),a.jsx("button",{type:"button",className:"be-modal-cancel",onClick:n,children:"Cancel"}),a.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:"Save"})]})]})}exports.APP_MIME=Zn;exports.BlockChildren=ut;exports.BlockErrorBoundary=$l;exports.BlockGutterRow=Yl;exports.BlockRangeActionMenu=di;exports.BlockRegistry=nl;exports.BlockRenderer=xo;exports.COLUMN_TYPES=Xl;exports.CollabSession=Mc;exports.DEFAULT_COLUMN_TYPE=hr;exports.DEFAULT_COLUMN_WIDTH=br;exports.DocumentExportButton=db;exports.EditableBlockContent=it;exports.EditorProvider=il;exports.EditorStore=tr;exports.EditorTrailingSpace=li;exports.FieldClockRegistry=Wt;exports.FieldTypeEditorModal=fb;exports.FloatingToolbar=Si;exports.HLC=xn;exports.History=Gs;exports.InlineRegistry=ol;exports.LAYOUT_BLOCKS=Xa;exports.ListCrdtState=kn;exports.MESSAGE_TYPE=Ve;exports.MIN_COLUMN_WIDTH=qn;exports.MobileActionBar=ab;exports.MobileBlockOptionsSheet=_i;exports.MobileBlockPickerSheet=Oi;exports.Modal=at;exports.NoteloomEditor=Dh;exports.PeerConnection=Zs;exports.Select=Rt;exports.SlashMenu=Xn;exports.TABLE_BLOCKS=Wa;exports.TABLE_SELECT_INLINE_TYPES=si;exports.TableHeaderRow=sa;exports.VoiceListeningIndicator=Zh;exports.VoicePermissionModal=Jh;exports.blankRunForType=ql;exports.blockquoteBlockType=ga;exports.buttonBlockType=wa;exports.calloutBlockType=ma;exports.checkboxInlineType=Qa;exports.codeBlockType=ka;exports.convertRunToType=Gl;exports.copyBlockRangeToClipboard=Wr;exports.createAutoPersistence=tl;exports.createBlockRegistry=rl;exports.createCellForColumn=mr;exports.createDefaultColumns=So;exports.createInlineRegistry=sl;exports.createPeriodicTombstoneGC=Cc;exports.createSelectFieldType=Yi;exports.createWebSocketSignaling=Ac;exports.dateInlineType=Za;exports.decodeMessage=Js;exports.deleteBlockAndFocusSibling=fr;exports.deleteBlockRange=gn;exports.deleteColumn=Ql;exports.deleteEntireDocument=Qn;exports.deleteOverBlockRange=No;exports.deletePersistedDocument=$c;exports.deleteRow=Zl;exports.deleteRunRangeInBlock=_o;exports.deserializeClipboard=fi;exports.dividerBlockType=ha;exports.duplicateBlock=wo;exports.embedBlockType=Ta;exports.emojiInlineType=ni;exports.encodeMessage=Kt;exports.ensureRootNonEmpty=rn;exports.exportDocumentHTML=Ai;exports.exportDocumentJSON=Mi;exports.exportDocumentSimpleJSON=Fi;exports.exportDocumentText=Di;exports.focusRunAtOffset=We;exports.focusRunEnd=xe;exports.focusRunStart=rr;exports.genPeerId=qs;exports.getMarksSummaryOverBlockRange=Ao;exports.getMarksSummaryOverSelection=Mo;exports.headingBlockType=Pl;exports.importDocumentSimpleJSON=cb;exports.injectDefaultStyles=ll;exports.insertColumnAfter=Gn;exports.insertRowAfter=To;exports.isEntireBlockRangeHidden=ci;exports.isEntireBlockSelected=ki;exports.layoutBlockType=fa;exports.layoutColumnBlockType=pa;exports.listItemBlockType=Wl;exports.listPersistedDocumentIds=zc;exports.listVoiceCommands=Kh;exports.loadPersistedDocument=el;exports.moveBlockDown=Co;exports.moveBlockRangeDown=ii;exports.moveBlockRangeUp=ai;exports.moveBlockUp=Io;exports.operations=kc;exports.paragraphBlockType=Dl;exports.registerBlocks=Va;exports.registerBuiltInBlocks=Ka;exports.registerBuiltInInlineTypes=ri;exports.registerInlineTypes=oi;exports.registerStoredFieldTypes=Ki;exports.remapSubtreeIds=vo;exports.renameColumn=ta;exports.reorderBlockRangeFromStore=sh;exports.resolveCollapsedCaret=rt;exports.resolveColumns=De;exports.resolveCrossBlockSelection=Gt;exports.resolveMultiRunSelection=tn;exports.resolveRunSelection=Tu;exports.savePersistedDocument=Qs;exports.selectInlineType=Ga;exports.serializeBlockRange=Rn;exports.setBlockRangeHidden=ui;exports.setColumnOptions=Yn;exports.setColumnType=na;exports.setColumnWidth=ea;exports.setMarksOverBlockRange=er;exports.setMarksOverSelection=Zt;exports.tableBlockType=ca;exports.tableCellBlockType=aa;exports.tableRowBlockType=ia;exports.tableSelectInlineType=ti;exports.textToParagraphs=Oo;exports.toggleHeadingBlockType=ya;exports.toggleMarkOnRunRange=hh;exports.toggleMarkOverBlockRange=Po;exports.toggleMarkOverSelection=Do;exports.useAtMenuTrigger=Ci;exports.useBlock=he;exports.useBlockChildren=go;exports.useBlockClassName=we;exports.useBlockRangeDrag=vi;exports.useBlockRangeSelection=Cn;exports.useBlockRegistry=gt;exports.useCaretRect=Li;exports.useClipboardHandlers=hi;exports.useCoarsePointer=Ho;exports.useEditor=rh;exports.useEditorKeyboardShortcuts=yi;exports.useEditorStore=q;exports.useEmojiMenuTrigger=Ii;exports.useFieldTypeEditor=so;exports.useFieldTypes=Ri;exports.useFloatingToolbarTrigger=Ti;exports.useHistory=ji;exports.useInlineRegistry=Je;exports.usePersistedDocument=zh;exports.usePresence=Hh;exports.usePreviewMode=oo;exports.useRegisterFieldTypes=Vi;exports.useRun=xt;exports.useSelectedBlock=lt;exports.useServiceWorkerUpdate=Fh;exports.useSlashMenuTrigger=wi;exports.useTextFormattingActions=zo;exports.useVirtualKeyboardInset=gr;exports.useVoiceTyping=Gh;exports.useWholeDocumentSelection=ro;exports.walkDomToBlocks=pi;
|
|
2521
2533
|
//# sourceMappingURL=noteloom.cjs.map
|