noteloom 0.2.0 → 0.3.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 +193 -5
- package/dist/index.d.ts +232 -3
- package/dist/noteloom.cjs +402 -8
- package/dist/noteloom.cjs.map +1 -1
- package/dist/noteloom.es.js +6918 -5629
- package/dist/noteloom.es.js.map +1 -1
- package/dist/style.css +394 -0
- package/package.json +6 -1
package/dist/noteloom.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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
|
|
1
|
+
"use strict";var tu=Object.defineProperty;var nu=(t,e,n)=>e in t?tu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var _s=(t,e,n)=>nu(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react"),l=require("react/jsx-runtime"),Ve=require("react-dom"),Z={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",EDIT_RUN_CHARS:"editRunChars",ADD_FIELD_TYPE:"addFieldType",UPDATE_FIELD_TYPE:"updateFieldType",REMOVE_FIELD_TYPE:"removeFieldType",ADD_COMMENT_THREAD:"addCommentThread",REMOVE_COMMENT_THREAD:"removeCommentThread",ADD_COMMENT_REPLY:"addCommentReply",REMOVE_COMMENT_REPLY:"removeCommentReply",RESOLVE_COMMENT:"resolveComment"};function me(t,e,n,r){return{type:Z.INSERT_BLOCK,block:t,parentId:e,index:n,subtree:r}}function ee(t){return{type:Z.REMOVE_BLOCK,id:t}}function ct(t,e,n){return{type:Z.MOVE_BLOCK,id:t,toParentId:e,toIndex:n}}function J(t,e){return{type:Z.UPDATE_BLOCK_PROPS,id:t,patch:e}}function fo(t,e,n){return{type:Z.CHANGE_BLOCK_TYPE,id:t,blockType:e,props:n}}function ue(t,e){return{type:Z.UPDATE_RUN,id:t,patch:e}}function Zr(t,e,n,r){return{type:Z.EDIT_RUN_CHARS,id:t,tombstoneIds:e,restoreIds:n,previousValue:r}}function nn(t,e){return{type:Z.SET_BLOCK_CONTENT_IDS,blockId:t,contentIds:e}}function _t(t,e,n){return{type:Z.REPLACE_RUN_SPAN,blockId:t,oldRunIds:e,newRuns:n}}function Me(t,e){return{type:Z.SET_BLOCK_RUNS,blockId:t,runs:e}}function ho(t){return{type:Z.ADD_FIELD_TYPE,fieldType:t}}function mo(t,e){return{type:Z.UPDATE_FIELD_TYPE,id:t,patch:e}}function bo(t){return{type:Z.REMOVE_FIELD_TYPE,id:t}}function Cn(t){return{type:Z.ADD_COMMENT_THREAD,thread:t}}function go(t){return{type:Z.REMOVE_COMMENT_THREAD,commentId:t}}function xo(t,e){return{type:Z.ADD_COMMENT_REPLY,commentId:t,message:e}}function ga(t,e){return{type:Z.REMOVE_COMMENT_REPLY,commentId:t,messageId:e}}function yo(t,e){return{type:Z.RESOLVE_COMMENT,commentId:t,resolved:e}}const ru=Object.freeze(Object.defineProperty({__proto__:null,OP:Z,addCommentReply:xo,addCommentThread:Cn,addFieldType:ho,changeBlockType:fo,editRunChars:Zr,insertBlock:me,moveBlock:ct,removeBlock:ee,removeCommentReply:ga,removeCommentThread:go,removeFieldType:bo,replaceRunSpan:_t,resolveComment:yo,setBlockContentIds:nn,setBlockRuns:Me,updateBlockProps:J,updateFieldType:mo,updateRun:ue},Symbol.toStringTag,{value:"Module"}));class Sn{constructor(e){this.peerId=e,this.wallTime=0,this.counter=0}tick(){const e=Date.now();return e>this.wallTime?(this.wallTime=e,this.counter=0):this.counter+=1,{wallTime:this.wallTime,counter:this.counter,peerId:this.peerId}}receive(e){const n=Date.now(),r=Math.max(n,this.wallTime,e.wallTime);return r===this.wallTime&&r===e.wallTime?this.counter=Math.max(this.counter,e.counter)+1:r===this.wallTime?this.counter+=1:r===e.wallTime?this.counter=e.counter+1:this.counter=0,this.wallTime=r,{wallTime:this.wallTime,counter:this.counter,peerId:this.peerId}}static compare(e,n){return e.wallTime!==n.wallTime?e.wallTime-n.wallTime:e.counter!==n.counter?e.counter-n.counter:e.peerId===n.peerId?0:e.peerId<n.peerId?-1:1}}function xa(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`peer-${Date.now()}-${Math.random().toString(36).slice(2)}`}class Qt{constructor(){this.slots=new Map}static fromArray(e,{peerId:n="legacy"}={}){const r=new Qt;let o=null;for(const s of e)r.slots.set(s,{id:s,originId:o,peerId:n,clock:{wallTime:0,counter:0,peerId:n},deleted:!1}),o=s;return r}has(e){return this.slots.has(e)}getSlot(e){return this.slots.get(e)}isDeleted(e){const n=this.slots.get(e);return!n||n.deleted}insert(e,n,r,o){this.slots.has(e)||this.slots.set(e,{id:e,originId:n,peerId:o,clock:r,deleted:!1})}delete(e,n){const r=this.slots.get(e);r&&(r.deleted=!0,n&&(r.deletedClock=n))}restore(e){const n=this.slots.get(e);n&&(n.deleted=!1)}move(e,n,r,o){if(n===e)return;const s=this.slots.get(e);if(!s)return;const a=s.originId;for(const i of this.slots.values())i.originId===e&&(i.originId=a);s.originId=n,s.peerId=o,s.clock=r,s.deleted=!1}merge(e){for(const n of e){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 e=0;for(const n of this.slots.values())n.deleted&&(e+=1);return e}pruneTombstones(e){let n=0;for(const[r,o]of this.slots){if(!o.deleted)continue;const s=o.deletedClock??o.clock;if(!(Sn.compare(s,e)>=0)){for(const a of this.slots.values())a.originId===r&&(a.originId=o.originId);this.slots.delete(r),n+=1}}return n}toArray(){const e=new Map;for(const o of this.slots.values()){const s=e.get(o.originId);s?s.push(o):e.set(o.originId,[o])}for(const o of e.values())o.sort((s,a)=>Sn.compare(a.clock,s.clock));const n=[],r=[...e.get(null)??[]].reverse();for(;r.length>0;){const o=r.pop();o.deleted||n.push(o.id);const s=e.get(o.id);if(s)for(let a=s.length-1;a>=0;a-=1)r.push(s[a])}return n}}class en{constructor(){this.clocks=new Map}static compositeKey(e,n){return`${e}:${n}`}get(e,n){return this.clocks.get(en.compositeKey(e,n))??null}recordLocal(e,n,r){this.clocks.set(en.compositeKey(e,n),r)}shouldApplyRemote(e,n,r){const o=this.get(e,n);return o?Sn.compare(r,o)>0:!0}recordRemote(e,n,r){this.clocks.set(en.compositeKey(e,n),r)}}function ou(t,e){const n=Array.from(t??""),r=Array.from(e??"");let o=0;const s=Math.min(n.length,r.length);for(;o<s&&n[o]===r[o];)o+=1;let a=n.length,i=r.length;for(;a>o&&i>o&&n[a-1]===r[i-1];)a-=1,i-=1;return{start:o,oldEnd:a,newEnd:i,oldChars:n,newChars:r}}function E(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`id-${Date.now()}-${Math.random().toString(36).slice(2)}`}const $r="$fieldTypes",Xe="$comments";class ur{constructor(e){this.blocks=new Map(((e==null?void 0:e.blocks)??[]).map(n=>[n.id,n])),this.runs=new Map(((e==null?void 0:e.runs)??[]).map(n=>[n.id,n])),this.rootId=(e==null?void 0:e.rootId)??null,this.fieldTypes=new Map(((e==null?void 0:e.fieldTypes)??[]).map(n=>[n.id,n])),this._fieldTypesSnapshot=null,this.comments=new Map(((e==null?void 0:e.comments)??[]).map(n=>[n.id,n])),this._commentsSnapshot=null,this._listeners=new Map,this._globalListeners=new Set,this._peerId=xa(),this._clock=new Sn(this._peerId),this._fieldClocks=new en,this._orders=new Map,this._runOrders=new Map,this._runChars=new Map,this._runValueSnapshots=new Map}_getOrder(e){let n=this._orders.get(e);if(!n){const r=this.blocks.get(e);n=Qt.fromArray((r==null?void 0:r.contentIds)??[],{peerId:"legacy"}),this._orders.set(e,n)}return n}_getRunOrder(e){let n=this._runOrders.get(e);if(!n){const r=this.runs.get(e),o=new Map;n=new Qt;let s=null,a=0;for(const i of Array.from((r==null?void 0:r.value)??"")){const u=`${e}:legacyChar:${a}`;o.set(u,i),n.insert(u,s,{wallTime:0,counter:0,peerId:"legacy"},"legacy"),s=u,a+=1}this._runOrders.set(e,n),this._runChars.set(e,o)}return n}_materializeRunValue(e){let n=this._runValueSnapshots.get(e);if(n===void 0){const r=this._getRunOrder(e),o=this._runChars.get(e);n=r.toArray().map(s=>o.get(s)).join(""),this._runValueSnapshots.set(e,n)}return n}_editRunText(e,n){const r=this._materializeRunValue(e),{start:o,oldEnd:s,newEnd:a,newChars:i}=ou(r,n),u=this._getRunOrder(e),c=this._runChars.get(e),f=u.toArray(),d=this._clock.tick(),h=[];for(let x=o;x<s;x+=1){const y=f[x];u.delete(y,d),h.push({id:y,clock:d})}const m=[];let g=o>0?f[o-1]:null;for(let x=o;x<a;x+=1){const y=E(),k=i[x];c.set(y,k),u.insert(y,g,d,this._peerId),m.push({id:y,char:k,afterId:g,clock:d}),g=y}return this._runValueSnapshots.delete(e),{oldValue:r,insertedChars:m,deletedCharIds:h,clock:d}}_replayRunTextEdit(e,n){const r=this._getRunOrder(e),o=this._runChars.get(e);for(const s of n.insertedChars)r.has(s.id)?r.restore(s.id):(o.set(s.id,s.char),r.insert(s.id,s.afterId,s.clock,this._peerId));for(const s of n.deletedCharIds)r.delete(s.id,s.clock);this._runValueSnapshots.delete(e)}getBlock(e){return this.blocks.get(e)}getRun(e){return this.runs.get(e)}getFieldTypes(){return this._fieldTypesSnapshot||(this._fieldTypesSnapshot=[...this.fieldTypes.values()]),this._fieldTypesSnapshot}getFieldType(e){return this.fieldTypes.get(e)}getComments(){return this._commentsSnapshot||(this._commentsSnapshot=[...this.comments.values()]),this._commentsSnapshot}getComment(e){return this.comments.get(e)}getAllRunIds(){return[...this.runs.keys()]}getRootId(){return this.rootId}subscribe(e,n){let r=this._listeners.get(e);return r||(r=new Set,this._listeners.set(e,r)),r.add(n),()=>{r.delete(n),r.size===0&&this._listeners.delete(e)}}subscribeAll(e){return this._globalListeners.add(e),()=>this._globalListeners.delete(e)}_notify(e){for(const n of e){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(e){const n=[],r=[],o=s=>{var i;if(this.runs.has(s)){r.push(this.runs.get(s));return}const a=this.blocks.get(s);if(a){n.push(a);for(const u of a.contentIds)o(u);for(const u of((i=a.props)==null?void 0:i.titleRunIds)??[])o(u)}};return o(e),{blocks:n,runs:r}}_deleteSubtree(e){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 a of o.contentIds)n(a);for(const a of((s=o.props)==null?void 0:s.titleRunIds)??[])n(a);this.blocks.delete(r)}};n(e)}applyOperation(e){var n;switch(e.type){case Z.UPDATE_RUN:{const r=this.runs.get(e.id),o=Object.keys(e.patch);if(o.length===1&&o[0]==="value"){let i=e._charEdit;if(i)this._replayRunTextEdit(e.id,i);else{const{oldValue:c,insertedChars:f,deletedCharIds:d,clock:h}=this._editRunText(e.id,e.patch.value);i={oldValue:c,insertedChars:f,deletedCharIds:d,clock:h},e._charEdit=i}const u=this._materializeRunValue(e.id);return this.runs.set(e.id,{...r,value:u}),this._lastEnvelope={kind:"runTextEdit",runId:e.id,insertedChars:i.insertedChars,deletedCharIds:i.deletedCharIds,clock:i.clock},this._notify([e.id]),Zr(e.id,i.insertedChars.map(c=>c.id),i.deletedCharIds.map(c=>c.id),i.oldValue)}const s={},a={};for(const i of o)s[i]=r[i],a[i]=this._clock.tick(),this._fieldClocks.recordLocal(e.id,i,a[i]);return this.runs.set(e.id,{...r,...e.patch}),this._lastEnvelope={kind:"fieldWrite",target:"run",id:e.id,patch:e.patch,clocks:a},this._notify([e.id]),ue(e.id,s)}case Z.EDIT_RUN_CHARS:{const r=this._getRunOrder(e.id),o=this._clock.tick();for(const i of e.tombstoneIds)r.delete(i,o);for(const i of e.restoreIds)r.restore(i);this._runValueSnapshots.delete(e.id);const s=this.runs.get(e.id),a=this._materializeRunValue(e.id);return this.runs.set(e.id,{...s,value:a}),this._lastEnvelope={kind:"runCharEdit",runId:e.id,tombstoneIds:e.tombstoneIds,restoreIds:e.restoreIds,clock:o},this._notify([e.id]),Zr(e.id,e.restoreIds,e.tombstoneIds)}case Z.UPDATE_BLOCK_PROPS:{const r=this.blocks.get(e.id),o={},s={};for(const a of Object.keys(e.patch))o[a]=r.props[a],s[a]=this._clock.tick(),this._fieldClocks.recordLocal(e.id,`props.${a}`,s[a]);return this.blocks.set(e.id,{...r,props:{...r.props,...e.patch}}),this._lastEnvelope={kind:"fieldWrite",target:"blockProps",id:e.id,patch:e.patch,clocks:s},this._notify([e.id]),J(e.id,o)}case Z.CHANGE_BLOCK_TYPE:{const r=this.blocks.get(e.id),o=r.type,s=r.props,a=this._clock.tick();return this._fieldClocks.recordLocal(e.id,"type",a),this.blocks.set(e.id,{...r,type:e.blockType,props:e.props}),this._lastEnvelope={kind:"fieldWrite",target:"blockType",id:e.id,blockType:e.blockType,props:e.props,clock:a},this._notify([e.id]),fo(e.id,o,s)}case Z.INSERT_BLOCK:{if(e.subtree){for(const s of e.subtree.blocks)this.blocks.set(s.id,s);for(const s of e.subtree.runs)this.runs.set(s.id,s)}else this.blocks.set(e.block.id,e.block);const r=this.blocks.get(e.parentId),o=this._getOrder(e.parentId);if(o.has(e.block.id))o.restore(e.block.id);else{const s=o.toArray(),a=e.index??s.length,i=a>0?s[a-1]:null;o.insert(e.block.id,i,this._clock.tick(),this._peerId)}return this.blocks.set(e.parentId,{...r,contentIds:o.toArray()}),this._lastEnvelope={kind:"insertSlot",parentId:e.parentId,blockId:e.block.id,slot:o.getSlot(e.block.id),subtree:e.subtree??{blocks:[e.block],runs:[]}},this._notify([e.block.id,e.parentId]),ee(e.block.id)}case Z.REMOVE_BLOCK:{const r=this.blocks.get(e.id),o=r.parentId,s=this.blocks.get(o),a=this._getOrder(o),i=a.toArray().indexOf(e.id),u=this._captureSubtree(e.id);this._deleteSubtree(e.id);const c=this._clock.tick();return a.delete(e.id,c),this.blocks.set(o,{...s,contentIds:a.toArray()}),this._lastEnvelope={kind:"deleteSlot",parentId:o,blockId:e.id,clock:c},this._notify([o]),{type:Z.INSERT_BLOCK,block:r,parentId:o,index:i,subtree:u}}case Z.MOVE_BLOCK:{const o=this.blocks.get(e.id).parentId,s=this._getOrder(o),a=s.toArray().indexOf(e.id);s.delete(e.id,this._clock.tick()),this.blocks.set(o,{...this.blocks.get(o),contentIds:s.toArray()});const i=this._getOrder(e.toParentId),u=i.toArray(),c=e.toIndex??u.length,f=c>0?u[c-1]:null,d=this._clock.tick();i.has(e.id)?i.move(e.id,f,d,this._peerId):i.insert(e.id,f,d,this._peerId),this.blocks.set(e.toParentId,{...this.blocks.get(e.toParentId),contentIds:i.toArray()}),this.blocks.set(e.id,{...this.blocks.get(e.id),parentId:e.toParentId}),this._lastEnvelope={kind:"moveSlot",fromParentId:o,toParentId:e.toParentId,blockId:e.id,slot:i.getSlot(e.id)};const h=new Set([e.id,o,e.toParentId]);return this._notify(h),ct(e.id,o,a)}case Z.SET_BLOCK_CONTENT_IDS:{const r=this.blocks.get(e.blockId),o=r.contentIds;return this.blocks.set(e.blockId,{...r,contentIds:e.contentIds}),this._orders.set(e.blockId,Qt.fromArray(e.contentIds,{peerId:"legacy"})),this._lastEnvelope=null,this._notify([e.blockId]),nn(e.blockId,o)}case Z.REPLACE_RUN_SPAN:{const r=this.blocks.get(e.blockId),o=r.contentIds.indexOf(e.oldRunIds[0])!==-1,s=o?r.contentIds:((n=r.props)==null?void 0:n.titleRunIds)??[],a=s.indexOf(e.oldRunIds[0]),i=e.oldRunIds.map(c=>this.runs.get(c));for(const c of e.oldRunIds)this.runs.delete(c);for(const c of e.newRuns)this.runs.set(c.id,c);const u=[...s];return u.splice(a,e.oldRunIds.length,...e.newRuns.map(c=>c.id)),o?this.blocks.set(e.blockId,{...r,contentIds:u}):this.blocks.set(e.blockId,{...r,props:{...r.props,titleRunIds:u}}),this._lastEnvelope=null,this._notify([e.blockId,...e.oldRunIds,...e.newRuns.map(c=>c.id)]),_t(e.blockId,e.newRuns.map(c=>c.id),i)}case Z.SET_BLOCK_RUNS:{const r=this.blocks.get(e.blockId),o=r.props&&"titleRunIds"in r.props,s=o?r.props.titleRunIds:r.contentIds,a=s.map(u=>this.runs.get(u)).filter(Boolean);for(const u of s)this.runs.delete(u);for(const u of e.runs)this.runs.set(u.id,u);const i=e.runs.map(u=>u.id);return o?this.blocks.set(e.blockId,{...r,props:{...r.props,titleRunIds:i}}):this.blocks.set(e.blockId,{...r,contentIds:i}),this._lastEnvelope=null,this._notify([e.blockId,...s,...i]),Me(e.blockId,a)}case Z.ADD_FIELD_TYPE:return this.fieldTypes.set(e.fieldType.id,e.fieldType),this._fieldTypesSnapshot=null,this._notify([$r]),bo(e.fieldType.id);case Z.UPDATE_FIELD_TYPE:{const r=this.fieldTypes.get(e.id),o={};for(const s of Object.keys(e.patch))o[s]=r[s];return this.fieldTypes.set(e.id,{...r,...e.patch}),this._fieldTypesSnapshot=null,this._notify([$r]),mo(e.id,o)}case Z.REMOVE_FIELD_TYPE:{const r=this.fieldTypes.get(e.id);return this.fieldTypes.delete(e.id),this._fieldTypesSnapshot=null,this._notify([$r]),ho(r)}case Z.ADD_COMMENT_THREAD:return this.comments.set(e.thread.id,e.thread),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"addThread",thread:e.thread},this._notify([Xe]),go(e.thread.id);case Z.REMOVE_COMMENT_THREAD:{const r=this.comments.get(e.commentId);return this.comments.delete(e.commentId),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"removeThread",commentId:e.commentId},this._notify([Xe]),Cn(r)}case Z.ADD_COMMENT_REPLY:{const r=this.comments.get(e.commentId);return this.comments.set(e.commentId,{...r,messages:[...r.messages,e.message]}),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"addReply",commentId:e.commentId,message:e.message},this._notify([Xe]),ga(e.commentId,e.message.id)}case Z.REMOVE_COMMENT_REPLY:{const r=this.comments.get(e.commentId),o=r.messages.find(s=>s.id===e.messageId);return this.comments.set(e.commentId,{...r,messages:r.messages.filter(s=>s.id!==e.messageId)}),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"removeReply",commentId:e.commentId,messageId:e.messageId},this._notify([Xe]),xo(e.commentId,o)}case Z.RESOLVE_COMMENT:{const r=this.comments.get(e.commentId),o=r.resolved;return this.comments.set(e.commentId,{...r,resolved:e.resolved}),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"resolve",commentId:e.commentId,resolved:e.resolved},this._notify([Xe]),yo(e.commentId,o)}default:throw new Error(`Unknown operation type: ${e.type}`)}}applyOperations(e){return e.map(n=>this.applyOperation(n))}getLastEnvelope(){return this._lastEnvelope}applyRemoteOperation(e){var n,r;if(e)switch(e.kind){case"insertSlot":{for(const a of e.subtree.blocks)this.blocks.has(a.id)||this.blocks.set(a.id,a);for(const a of e.subtree.runs)this.runs.has(a.id)||this.runs.set(a.id,a);const o=this._getOrder(e.parentId);o.merge([e.slot]);const s=this.blocks.get(e.parentId);this.blocks.set(e.parentId,{...s,contentIds:o.toArray()}),this._clock.receive(e.slot.clock),this._notify([e.blockId,e.parentId]);return}case"deleteSlot":{const o=this._getOrder(e.parentId);this.blocks.has(e.blockId)&&this._deleteSubtree(e.blockId),o.delete(e.blockId,e.clock),e.clock&&this._clock.receive(e.clock);const s=this.blocks.get(e.parentId);this.blocks.set(e.parentId,{...s,contentIds:o.toArray()}),this._notify([e.parentId]);return}case"moveSlot":{const o=this._getOrder(e.fromParentId);o.delete(e.blockId,(n=e.slot)==null?void 0:n.clock),this.blocks.set(e.fromParentId,{...this.blocks.get(e.fromParentId),contentIds:o.toArray()});const s=this._getOrder(e.toParentId),a=s.has(e.blockId);s.merge([e.slot]),a&&s.move(e.blockId,e.slot.originId,e.slot.clock,e.slot.peerId),this.blocks.set(e.toParentId,{...this.blocks.get(e.toParentId),contentIds:s.toArray()}),this.blocks.has(e.blockId)&&this.blocks.set(e.blockId,{...this.blocks.get(e.blockId),parentId:e.toParentId}),this._clock.receive(e.slot.clock),this._notify([e.blockId,e.fromParentId,e.toParentId]);return}case"fieldWrite":{if(e.target==="run"){const o=this.runs.get(e.id);if(o){const s={};for(const a of Object.keys(e.patch)){const i=e.clocks[a];this._fieldClocks.shouldApplyRemote(e.id,a,i)&&(s[a]=e.patch[a],this._fieldClocks.recordRemote(e.id,a,i))}Object.keys(s).length>0&&(this.runs.set(e.id,{...o,...s}),this._notify([e.id]))}}else if(e.target==="blockProps"){const o=this.blocks.get(e.id);if(o){const s={};for(const a of Object.keys(e.patch)){const i=e.clocks[a];this._fieldClocks.shouldApplyRemote(e.id,`props.${a}`,i)&&(s[a]=e.patch[a],this._fieldClocks.recordRemote(e.id,`props.${a}`,i))}Object.keys(s).length>0&&(this.blocks.set(e.id,{...o,props:{...o.props,...s}}),this._notify([e.id]))}}else if(e.target==="blockType"){const o=this.blocks.get(e.id);o&&this._fieldClocks.shouldApplyRemote(e.id,"type",e.clock)&&(this._fieldClocks.recordRemote(e.id,"type",e.clock),this.blocks.set(e.id,{...o,type:e.blockType,props:e.props}),this._notify([e.id]))}for(const o of Object.values(e.clocks??{}))this._clock.receive(o);e.clock&&this._clock.receive(e.clock);return}case"runTextEdit":{const o=this._getRunOrder(e.runId),s=this._runChars.get(e.runId);for(const i of e.insertedChars)o.has(i.id)||s.set(i.id,i.char),o.insert(i.id,i.afterId,i.clock,(r=i.clock)==null?void 0:r.peerId);for(const i of e.deletedCharIds)o.delete(i.id,i.clock);this._runValueSnapshots.delete(e.runId);const a=this.runs.get(e.runId);a&&(this.runs.set(e.runId,{...a,value:this._materializeRunValue(e.runId)}),this._notify([e.runId])),this._clock.receive(e.clock);return}case"runCharEdit":{const o=this._getRunOrder(e.runId);for(const a of e.tombstoneIds)o.delete(a,e.clock);for(const a of e.restoreIds)o.restore(a);this._runValueSnapshots.delete(e.runId);const s=this.runs.get(e.runId);s&&(this.runs.set(e.runId,{...s,value:this._materializeRunValue(e.runId)}),this._notify([e.runId])),this._clock.receive(e.clock);return}case"commentWrite":{if(e.op==="addThread")this.comments.has(e.thread.id)||(this.comments.set(e.thread.id,e.thread),this._commentsSnapshot=null,this._notify([Xe]));else if(e.op==="removeThread")this.comments.delete(e.commentId)&&(this._commentsSnapshot=null,this._notify([Xe]));else if(e.op==="addReply"){const o=this.comments.get(e.commentId);o&&!o.messages.some(s=>s.id===e.message.id)&&(this.comments.set(e.commentId,{...o,messages:[...o.messages,e.message]}),this._commentsSnapshot=null,this._notify([Xe]))}else if(e.op==="removeReply"){const o=this.comments.get(e.commentId);o&&o.messages.some(s=>s.id===e.messageId)&&(this.comments.set(e.commentId,{...o,messages:o.messages.filter(s=>s.id!==e.messageId)}),this._commentsSnapshot=null,this._notify([Xe]))}else if(e.op==="resolve"){const o=this.comments.get(e.commentId);o&&(this.comments.set(e.commentId,{...o,resolved:e.resolved}),this._commentsSnapshot=null,this._notify([Xe]))}return}default:throw new Error(`Unknown remote envelope kind: ${e.kind}`)}}getTombstoneCount(){let e=0;for(const n of this._orders.values())e+=n.tombstoneCount();for(const n of this._runOrders.values())e+=n.tombstoneCount();return e}pruneTombstones({maxAgeMs:e=24*60*60*1e3,now:n=Date.now()}={}){const r={wallTime:n-e,counter:0,peerId:""};let o=0;for(const s of this._orders.values())o+=s.pruneTombstones(r);for(const s of this._runOrders.values())o+=s.pruneTombstones(r);return o}toJSON(){return{blocks:[...this.blocks.values()],runs:[...this.runs.values()],rootId:this.rootId,fieldTypes:[...this.fieldTypes.values()],comments:[...this.comments.values()]}}static fromJSON(e){return new ur(e)}}const su=500;function au(t,e){const n=t??"",r=e??"";let o=0;const s=Math.min(n.length,r.length);for(;o<s&&n[o]===r[o];)o+=1;let a=n.length,i=r.length;for(;a>o&&i>o&&n[a-1]===r[i-1];)a-=1,i-=1;return{beforeOffset:a,afterOffset:i}}function ya(t){var e;if((t==null?void 0:t.type)==="updateRun"&&typeof((e=t.patch)==null?void 0:e.value)=="string")return t.patch.value;if((t==null?void 0:t.type)==="editRunChars"&&typeof t.previousValue=="string")return t.previousValue}function Os(t){var i;if(!t.ops.length||!t.inverses.length)return null;const e=t.ops[0],n=t.ops[t.ops.length-1];if(e.type!=="updateRun"||n.type!=="updateRun"||e.id!==n.id||typeof((i=n.patch)==null?void 0:i.value)!="string")return null;const r=t.inverses[t.inverses.length-1],o=ya(r);if(o===void 0)return null;const{beforeOffset:s,afterOffset:a}=au(o,n.patch.value);return{runId:e.id,beforeOffset:s,afterOffset:a}}function Ms(t){const e=[],n=r=>{var o;r&&((o=r.block)!=null&&o.id&&e.push(r.block.id),r.blockId&&e.push(r.blockId),r.id&&e.push(r.id),r.parentId&&e.push(r.parentId),r.toParentId&&e.push(r.toParentId))};for(const r of t.ops)n(r);for(const r of t.inverses)n(r);return[...new Set(e)]}class ka{constructor(e,{idleMs:n=su,trackChanges:r=!1,maxChangeLogSize:o=500}={}){this.store=e,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(e,n,r){var a;if(!this.trackChanges)return;const o=e.patch!==void 0&&(n==null?void 0:n.patch)!==void 0,s=o?void 0:ya(n);this.changeLog.push({opType:e.type,id:e.id??e.blockId??((a=e.block)==null?void 0:a.id),before:o?n.patch:s!==void 0?{value:s}:void 0,after:o||s!==void 0?e.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 e=this.canUndo(),n=this.canRedo();return(this._undoRedoSnapshot.canUndo!==e||this._undoRedoSnapshot.canRedo!==n)&&(this._undoRedoSnapshot={canUndo:e,canRedo:n}),this._undoRedoSnapshot}getBlock(e){return this.store.getBlock(e)}getRun(e){return this.store.getRun(e)}getRootId(){return this.store.getRootId()}getFieldTypes(){return this.store.getFieldTypes()}getFieldType(e){return this.store.getFieldType(e)}getComments(){return this.store.getComments()}getComment(e){return this.store.getComment(e)}getAllRunIds(){return this.store.getAllRunIds()}subscribe(e,n){return this.store.subscribe(e,n)}subscribeAll(e){return this.store.subscribeAll(e)}getTombstoneCount(){return this.store.getTombstoneCount()}pruneTombstones(e){return this.store.pruneTombstones(e)}toJSON(){return this.store.toJSON()}applyOperation(e,n={}){return this.perform(e,n)}applyOperations(e,n={}){return e.map(r=>this.perform(r,n))}performBatch(e,n={}){var a;const r=n.actorId??null,o=n.timestamp??Date.now();this._commitCurrentBatch();const s=[];for(const i of e){const u=this.store.applyOperation(i);s.unshift(u),this.historyLog.push({opType:i.type,id:i.id??i.blockId??((a=i.block)==null?void 0:a.id),actorId:r,timestamp:o}),this._recordChange(i,u,{actorId:r,timestamp:o})}this.redoStack=[],this.undoStack.push({ops:[...e],inverses:s,batchKey:null,actorId:r,timestamp:o,lastTimestamp:o,boundaryHit:!0}),this._notify()}perform(e,n={}){const r=n.actorId??null,o=n.timestamp??Date.now(),s=this.store.applyOperation(e);return this._record(e,s,{actorId:r,timestamp:o}),s}_batchKeyFor(e){return e.type==="updateRun"?`run:${e.id}`:null}_isWordBoundary(e){var r;if(e.type!=="updateRun")return!1;const n=(r=e.patch)==null?void 0:r.value;return typeof n!="string"||n.length===0?!1:/\s/.test(n[n.length-1])}_record(e,n,r){var i;this.redoStack=[];const o=this._batchKeyFor(e),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(e),this.currentBatch.inverses.unshift(n),this.currentBatch.lastTimestamp=r.timestamp,this._isWordBoundary(e)&&(this.currentBatch.boundaryHit=!0)):(this._commitCurrentBatch(),this.currentBatch={ops:[e],inverses:[n],batchKey:o,actorId:r.actorId,timestamp:r.timestamp,lastTimestamp:r.timestamp,boundaryHit:this._isWordBoundary(e)}),this._resetIdleTimer(),this.historyLog.push({opType:e.type,id:e.id??((i=e.block)==null?void 0:i.id),actorId:r.actorId,timestamp:r.timestamp}),this._recordChange(e,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 e=this.undoStack.pop();if(!e)return!1;for(const r of e.inverses)this.store.applyOperation(r);this.redoStack.push(e);const n=Os(e);return this._pendingSelection=n?{runId:n.runId,offset:n.beforeOffset}:null,this._pendingAffectedBlockIds=Ms(e),this._notify(),!0}redo(){const e=this.redoStack.pop();if(!e)return!1;for(const r of e.ops)this.store.applyOperation(r);this.undoStack.push(e);const n=Os(e);return this._pendingSelection=n?{runId:n.runId,offset:n.afterOffset}:null,this._pendingAffectedBlockIds=Ms(e),this._notify(),!0}canUndo(){return this.undoStack.length>0||this.currentBatch!==null}canRedo(){return this.redoStack.length>0}getHistoryLog(){return[...this.historyLog]}subscribeToHistory(e){return this._listeners.add(e),()=>this._listeners.delete(e)}_notify(){for(const e of this._listeners)e()}}const lu=60*60*1e3,iu=24*60*60*1e3;function cu({store:t,intervalMs:e=lu,maxAgeMs:n=iu,onPrune:r,onError:o}){const s=setInterval(()=>{try{const a=t.pruneTombstones({maxAgeMs:n});a>0&&(r==null||r(a))}catch(a){o==null||o(a)}},e);return{stop(){clearInterval(s)}}}const Ge={HELLO:"hello",OP:"op",SYNC_REQUEST:"syncRequest",SYNC_RESPONSE:"syncResponse",PRESENCE:"presence"};function Jt(t){return JSON.stringify(t)}function va(t){const e=JSON.parse(t);if(!e||typeof e.type!="string")throw new Error("Invalid sync message: missing type");return e}function uu(t){return{type:Ge.HELLO,peerId:t}}function du(t){return{type:Ge.OP,envelope:t}}function pu(){return{type:Ge.SYNC_REQUEST}}function fu(t){return{type:Ge.SYNC_RESPONSE,doc:t}}function Ls(t,e){return{type:Ge.PRESENCE,peerId:t,data:e}}const hu="noteloom-sync",mu={iceServers:[{urls:"stun:stun.l.google.com:19302"}]},Fn=16e3,bu=1e6,gu=256e3;function xu(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}class wa{constructor({signaling:e,remotePeerId:n,initiator:r,rtcConfig:o=mu}){this.remotePeerId=n,this._signaling=e,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(hu)),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=e.onMessage((s,a)=>{s===n&&this._handleSignal(a)})}async _handleSignal(e){if(e.kind==="offer"){await this._pc.setRemoteDescription(e.sdp);const n=await this._pc.createAnswer();await this._pc.setLocalDescription(n),this._signaling.send(this.remotePeerId,{kind:"answer",sdp:n})}else if(e.kind==="answer")await this._pc.setRemoteDescription(e.sdp);else if(e.kind==="ice")try{await this._pc.addIceCandidate(e.candidate)}catch{}}_wireChannel(e){this._channel=e,e.bufferedAmountLowThreshold=gu,e.onopen=()=>{for(const n of this._openListeners)n()},e.onclose=()=>{for(const n of this._closeListeners)n()},e.onmessage=n=>this._handleRawMessage(n.data)}_handleRawMessage(e){if(typeof e!="string"||e.length===0)return;const n=e[0];if(n==="S"){for(const m of this._messageListeners)m(e.slice(1));return}if(n!=="C")return;const r=e.slice(1),o=r.indexOf(":"),s=r.indexOf(":",o+1),a=r.indexOf(":",s+1);if(o===-1||s===-1||a===-1)return;const i=r.slice(0,o),u=Number(r.slice(o+1,s)),c=Number(r.slice(s+1,a)),f=r.slice(a+1);let d=this._chunkBuffers.get(i);if(d||(d={total:c,received:new Map},this._chunkBuffers.set(i,d)),d.received.set(u,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(e){var n;if(((n=this._channel)==null?void 0:n.readyState)==="open"){if(e.length<=Fn)this._sendQueue.push(`S${e}`);else{const r=xu(),o=Math.ceil(e.length/Fn);for(let s=0;s<o;s+=1){const a=e.slice(s*Fn,(s+1)*Fn);this._sendQueue.push(`C${r}:${s}:${o}:${a}`)}}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>bu){await this._waitForBufferedAmountLow();continue}const e=this._sendQueue.shift();try{this._channel.send(e)}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(e=>{if(!this._channel){e();return}const n=()=>{this._channel.removeEventListener("bufferedamountlow",n),e()};this._channel.addEventListener("bufferedamountlow",n)})}onOpen(e){return this._openListeners.add(e),()=>this._openListeners.delete(e)}onClose(e){return this._closeListeners.add(e),()=>this._closeListeners.delete(e)}onMessage(e){return this._messageListeners.add(e),()=>this._messageListeners.delete(e)}close(){var e,n;this._chunkBuffers.clear(),this._sendQueue.length=0,(e=this._unsubscribeSignaling)==null||e.call(this),(n=this._channel)==null||n.close(),this._pc.close()}}const yu=100;class ku{constructor({history:e,signaling:n,presenceThrottleMs:r=yu}){this._history=e,this._store=e.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 e=this._store.applyOperation.bind(this._store);this._pendingEnvelopes=[],this._store.applyOperation=r=>{const o=e(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 a=o(...s);return this._flushPendingEnvelopes(),a}}return()=>{for(const r of Object.keys(n))this._history[r]=n[r];this._store.applyOperation=e}}_flushPendingEnvelopes(){const e=this._pendingEnvelopes;this._pendingEnvelopes=[];for(const n of e)this._broadcast(du(n))}_broadcast(e){const n=Jt(e);for(const r of this._peers.values())r.send(n)}connect(e,{initiator:n}){var o;(o=this._peers.get(e))==null||o.close();const r=new wa({signaling:this._signaling,remotePeerId:e,initiator:n});return r.onOpen(()=>{r.send(Jt(uu(this._signaling.localPeerId))),r.send(Jt(pu())),this._localPresence!==null&&r.send(Jt(Ls(this._signaling.localPeerId,this._localPresence)))}),r.onMessage(s=>this._handleMessage(r,s)),r.onClose(()=>{this._peers.delete(e),this._remotePresence.delete(e)&&this._notifyPresenceListeners()}),this._peers.set(e,r),r}setLocalPresence(e){this._localPresence=e,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(Ls(this._signaling.localPeerId,this._localPresence))}getPresence(){return new Map(this._remotePresence)}onPresenceChange(e){return this._presenceListeners.add(e),()=>this._presenceListeners.delete(e)}_notifyPresenceListeners(){const e=this.getPresence();for(const n of this._presenceListeners)n(e)}_handleMessage(e,n){let r;try{r=va(n)}catch{return}r.type===Ge.OP?(this._store.applyRemoteOperation(r.envelope),this._history.flush()):r.type===Ge.SYNC_REQUEST?e.send(Jt(fu(this._store.toJSON()))):r.type===Ge.SYNC_RESPONSE?this._adoptSnapshotIfEmpty(r.doc):r.type===Ge.PRESENCE&&(this._remotePresence.set(r.peerId,r.data),this._notifyPresenceListeners())}_adoptSnapshotIfEmpty(e){const n=this._store.getRootId();n&&this._store.getBlock(n)||(this._store.blocks=new Map((e.blocks??[]).map(r=>[r.id,r])),this._store.runs=new Map((e.runs??[]).map(r=>[r.id,r])),this._store.rootId=e.rootId??null,this._store._orders=new Map,this._store._notify([...this._store.blocks.keys(),...this._store.runs.keys()]))}disconnect(e){var n;(n=this._peers.get(e))==null||n.close(),this._peers.delete(e)}destroy(){this._unsubscribeLocal(),this._presenceThrottleTimer&&clearTimeout(this._presenceThrottleTimer);for(const e of this._peers.values())e.close();this._peers.clear(),this._remotePresence.clear(),this._presenceListeners.clear()}}function vu({url:t,roomId:e,peerId:n,WebSocketImpl:r=WebSocket}){const o=new Set,s=new Set,a=new Set,i=[],u=`${t}${t.includes("?")?"&":"?"}room=${encodeURIComponent(e)}&peerId=${encodeURIComponent(n)}`,c=new r(u);c.addEventListener("open",()=>{for(const{toPeerId:d,payload:h}of i)f(d,h);i.length=0}),c.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 a)m(h.peerId);else if(h.type==="signal")for(const m of o)m(h.fromPeerId,h.payload)});function f(d,h){if(c.readyState!==r.OPEN){i.push({toPeerId:d,payload:h});return}c.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 a.add(d),()=>a.delete(d)},close(){i.length=0,c.close()}}}const wu="noteloom-documents",Ze="documents",Qe="templates",et="versions",Iu=3;let Un=null;function De(){return Un||(Un=new Promise((t,e)=>{const n=indexedDB.open(wu,Iu);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(Ze)||n.result.createObjectStore(Ze),n.result.objectStoreNames.contains(Qe)||n.result.createObjectStore(Qe,{keyPath:"id"}),n.result.objectStoreNames.contains(et)||n.result.createObjectStore(et,{keyPath:"id"})},n.onsuccess=()=>t(n.result),n.onerror=()=>e(n.error)}),Un)}async function Ia(t,e){const n=await De();return new Promise((r,o)=>{const s=n.transaction(Ze,"readwrite");s.objectStore(Ze).put(e,t),s.oncomplete=()=>r(),s.onerror=()=>o(s.error)})}async function Ca(t){const e=await De();return new Promise((n,r)=>{const s=e.transaction(Ze,"readonly").objectStore(Ze).get(t);s.onsuccess=()=>n(s.result??null),s.onerror=()=>r(s.error)})}async function Cu(t){const e=await De();return new Promise((n,r)=>{const o=e.transaction(Ze,"readwrite");o.objectStore(Ze).delete(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function Su(){const t=await De();return new Promise((e,n)=>{const o=t.transaction(Ze,"readonly").objectStore(Ze).getAllKeys();o.onsuccess=()=>e(o.result),o.onerror=()=>n(o.error)})}async function Ru(t){const e=await De();return new Promise((n,r)=>{const o=e.transaction(Qe,"readwrite");o.objectStore(Qe).put(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function Tu(t){const e=await De();return new Promise((n,r)=>{const s=e.transaction(Qe,"readonly").objectStore(Qe).get(t);s.onsuccess=()=>n(s.result??null),s.onerror=()=>r(s.error)})}async function ju(t){const e=await De();return new Promise((n,r)=>{const o=e.transaction(Qe,"readwrite");o.objectStore(Qe).delete(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function Qr(){const t=await De();return new Promise((e,n)=>{const o=t.transaction(Qe,"readonly").objectStore(Qe).getAll();o.onsuccess=()=>e(o.result),o.onerror=()=>n(o.error)})}async function Sa(t){const e=await De();return new Promise((n,r)=>{const o=e.transaction(et,"readwrite");o.objectStore(et).put(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function Eu(t){const e=await De();return new Promise((n,r)=>{const s=e.transaction(et,"readonly").objectStore(et).get(t);s.onsuccess=()=>n(s.result??null),s.onerror=()=>r(s.error)})}async function Ra(t){const e=await De();return new Promise((n,r)=>{const o=e.transaction(et,"readwrite");o.objectStore(et).delete(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function rr(t){const e=await De();return new Promise((n,r)=>{const s=e.transaction(et,"readonly").objectStore(et).getAll();s.onsuccess=()=>{const a=s.result.filter(i=>i.docId===t);a.sort((i,u)=>u.timestamp-i.timestamp),n(a)},s.onerror=()=>r(s.error)})}const Bu=500;function Ta({store:t,docId:e,debounceMs:n=Bu,onError:r}){let o=null;function s(){Ia(e,t.toJSON()).catch(c=>r==null?void 0:r(c))}function a(){o&&(clearTimeout(o),o=null,s())}const i=t.subscribeAll(()=>{o&&clearTimeout(o),o=setTimeout(()=>{o=null,s()},n)});function u(){o&&clearTimeout(o),o=null,i()}return{stop:u,flush:a}}function En(t,e,n,r){const o={store:t,registry:e,inlineRegistry:r};return{html:_u(t,e,n,o),text:n.map(s=>{const a=t.getBlock(s);return e.get(a.type).toPlainText(a,o)}).join(`
|
|
2
|
+
`),json:JSON.stringify({version:1,blocks:n.map(s=>Bn(t,s))})}}function _u(t,e,n,r){let o="",s=0;for(;s<n.length;){const a=t.getBlock(n[s]);if(a.type==="listItem"){const i=!!a.props.ordered;let u="",c=s;for(;c<n.length;){const d=t.getBlock(n[c]);if(d.type!=="listItem"||!!d.props.ordered!==i)break;u+=e.get("listItem").toHTML(d,r),c+=1}const f=i?"ol":"ul";o+=`<${f}>${u}</${f}>`,s=c}else if(a.type==="blockquote"){let i="",u=s;for(;u<n.length;){const c=t.getBlock(n[u]);if(c.type!=="blockquote")break;i+=e.get("blockquote").toHTML(c,r),u+=1}o+=`<blockquote>${i}</blockquote>`,s=u}else o+=e.get(a.type).toHTML(a,r),s+=1}return o}function Bn(t,e){const n=[],r=[],o=s=>{var u;const a=t.getRun(s);if(a){r.push(a);return}const i=t.getBlock(s);if(i){n.push(i);for(const c of i.contentIds)o(c);for(const c of((u=i.props)==null?void 0:u.titleRunIds)??[])o(c)}};return o(e),{rootId:e,blocks:n,runs:r}}function dr({rootId:t,blocks:e,runs:n}){const r=new Map;for(const u of e)r.set(u.id,E());for(const u of n)r.set(u.id,E());const o=u=>r.get(u)??u,s=e.map(u=>{var c;return{...u,id:o(u.id),parentId:u.parentId?o(u.parentId):u.parentId,contentIds:u.contentIds.map(o),props:{...u.props,...(c=u.props)!=null&&c.titleRunIds?{titleRunIds:u.props.titleRunIds.map(o)}:{}}}}),a=n.map(u=>({...u,id:o(u.id)})),i=o(t);return{block:s.find(u=>u.id===i),runs:a,subtreeBlocks:s.filter(u=>u.id!==i)}}function Ou(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Mu(t,e){return{roots:e.map(n=>Bn(t,n))}}function ja(t,e,{parentId:n,index:r}){const o=[];let s=r;for(const a of e.roots){const{block:i,runs:u,subtreeBlocks:c}=dr(a);i.parentId=n,o.push(me(i,n,s,{blocks:[i,...c],runs:u})),s+=1}Ou(t,o)}function Lu(t,e){const n=t.store??t;n.blocks=new Map((e.blocks??[]).map(r=>[r.id,r])),n.runs=new Map((e.runs??[]).map(r=>[r.id,r])),n.rootId=e.rootId??null,n.fieldTypes=new Map((e.fieldTypes??[]).map(r=>[r.id,r])),n._fieldTypesSnapshot=null,n.comments=new Map((e.comments??[]).map(r=>[r.id,r])),n._commentsSnapshot=null,n._orders=new Map,n._notify([...n.blocks.keys(),...n.runs.keys(),"$fieldTypes","$comments"])}function Nu(t,e){for(const n of e)t.register(`__blockTemplate:${n.id}`,{component:()=>null,isLeaf:!0,slashCommand:{label:n.label,icon:n.icon,keywords:n.keywords??[n.label],run(r,{blockId:o,runId:s,sliceStart:a,sliceEnd:i}){const u=r.getRun(s),c=(u==null?void 0:u.value)??"";r.applyOperation(ue(s,{value:c.slice(0,a)+c.slice(i)}));const f=r.getBlock(o),h=r.getBlock(f.parentId).contentIds.indexOf(o)+1;ja(r,n,{parentId:f.parentId,index:h})}}})}function Au({scope:t}={}){const[e,n]=p.useState([]),[r,o]=p.useState(!1),s=p.useCallback(()=>(o(!1),Qr().then(a=>{n(t?a.filter(i=>i.scope===t):a),o(!0)})),[t]);return p.useEffect(()=>{let a=!1;return o(!1),Qr().then(i=>{a||(n(t?i.filter(u=>u.scope===t):i),o(!0))}),()=>{a=!0}},[t]),{templates:e,isLoaded:r,refresh:s}}function Du({templates:t,onSelect:e,emptyLabel:n="No templates yet."}){return t.length===0?l.jsx("p",{className:"be-template-picker-empty",children:n}):l.jsx("ul",{className:"be-template-picker",role:"list",children:t.map(r=>l.jsxs("li",{className:"be-template-card",children:[l.jsxs("div",{className:"be-template-card-body",children:[l.jsx("span",{className:"be-template-card-name",children:r.name}),r.description&&l.jsx("span",{className:"be-template-card-description",children:r.description})]}),l.jsx("button",{type:"button",className:"be-template-card-select",onClick:()=>e(r),children:"Use"})]},r.id))})}function ko(t,{pretty:e=!0}={}){const n=t.getRootId(),{blocks:r,runs:o}=Bn(t,n);return JSON.stringify({version:1,rootId:n,blocks:r,runs:o},null,e?2:0)}function Ea(t,e,n){const r=t.getBlock(t.getRootId());return r?En(t,e,r.contentIds,n).html:""}function Ba(t,e,n){const r=t.getBlock(t.getRootId());return r?En(t,e,r.contentIds,n).text:""}const Pu=5*60*1e3,$u=50;function zu({store:t,docId:e,intervalMs:n=Pu,label:r,maxVersions:o=$u,onSnapshot:s,onError:a}){const i=setInterval(async()=>{try{const u=JSON.parse(ko(t)),c={id:crypto.randomUUID(),docId:e,timestamp:Date.now(),label:r,doc:u};await Sa(c),s==null||s(c);const f=await rr(e);if(f.length>o){const d=f.slice(o);await Promise.all(d.map(h=>Ra(h.id)))}}catch(u){a==null||a(u)}},n);return{stop(){clearInterval(i)}}}function Hu(t){const[e,n]=p.useState([]),[r,o]=p.useState(!1),s=p.useCallback(()=>t?(o(!1),rr(t).then(a=>{n(a),o(!0)})):Promise.resolve(),[t]);return p.useEffect(()=>{if(!t){n([]),o(!0);return}let a=!1;return o(!1),rr(t).then(i=>{a||(n(i),o(!0))}),()=>{a=!0}},[t]),{versions:e,isLoaded:r,refresh:s}}function Fu(t,e){var r;const n=t.getBlock(e);return((r=n.props)==null?void 0:r.titleRunIds)??n.contentIds}function _a(t,e){const n=(t==null?void 0:t.commentIds)??[];return n.includes(e)?t??{}:{...t,commentIds:[...n,e]}}function Uu(t,e){const n=(t==null?void 0:t.commentIds)??[];if(!n.includes(e))return t??{};const r={...t},o=n.filter(s=>s!==e);return o.length>0?r.commentIds=o:delete r.commentIds,r}function Vu(t,e,n,r,o){const s=_a(e.marks,o);if(n===0&&r===e.value.length)return{type:"updateRun",id:e.id,patch:{marks:s}};const a=e.value.slice(0,n),i=e.value.slice(n,r),u=e.value.slice(r),c=[];return a&&c.push({id:E(),type:"text",value:a,marks:{...e.marks}}),c.push({id:E(),type:"text",value:i,marks:s}),u&&c.push({id:E(),type:"text",value:u,marks:{...e.marks}}),_t(t,[e.id],c)}function vo(t,{blockId:e,startRunId:n,startOffset:r,endRunId:o,endOffset:s},a){const i=Fu(t,e),u=i.indexOf(n),c=i.indexOf(o);if(u===-1||c===-1)return null;const[f,d]=u<=c?[u,c]:[c,u],h=u<=c?r:s,m=u<=c?s:r,g=i.slice(f,d+1),x=g.map(k=>t.getRun(k));if(f===d){const k=x[0];if(k.type!=="text")return null;const w=Math.max(0,Math.min(h,m)),v=Math.min(k.value.length,Math.max(h,m));return w===v?null:Vu(e,k,w,v,a)}const y=[];return x.forEach((k,w)=>{if(k.type!=="text"){y.push(k);return}const v=w===0,j=w===x.length-1,I=v?h:0,C=j?m:k.value.length,T=k.value.slice(0,I),M=k.value.slice(I,C),B=k.value.slice(C);T&&y.push({id:E(),type:"text",value:T,marks:{...k.marks}}),y.push({id:E(),type:"text",value:M,marks:_a(k.marks,a)}),B&&y.push({id:E(),type:"text",value:B,marks:{...k.marks}})}),_t(e,g,y)}function wo(t,e){var r,o;const n=[];for(const s of t.getAllRunIds()){const a=t.getRun(s);(o=(r=a==null?void 0:a.marks)==null?void 0:r.commentIds)!=null&&o.includes(e)&&n.push({type:"updateRun",id:s,patch:{marks:Uu(a.marks,e)}})}return n}function Oa(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Yu(t,e,{authorId:n,text:r}){const o=E(),s=vo(t,e,o),a={id:o,blockId:e.blockId,anchorRunIds:[e.startRunId,e.endRunId],resolved:!1,messages:[{id:E(),authorId:n,text:r,createdAt:Date.now()}]},i=s?[s,Cn(a)]:[Cn(a)];return Oa(t,i),o}function Ma(t,e,{authorId:n,text:r}){const o={id:E(),authorId:n,text:r,createdAt:Date.now()};return t.applyOperation(xo(e,o)),o.id}function La(t,e,n=!0){t.applyOperation(yo(e,n))}function Na(t,e){const n=wo(t,e);Oa(t,[...n,go(e)])}const Ku=`/*\r
|
|
2
3
|
* noteloom's default theme — minimal, clean, modern SaaS-adjacent.\r
|
|
3
4
|
*\r
|
|
4
5
|
* Ships as plain CSS custom properties on :root (not scoped to a wrapper\r
|
|
@@ -116,6 +117,20 @@
|
|
|
116
117
|
outline: none;\r
|
|
117
118
|
}\r
|
|
118
119
|
\r
|
|
120
|
+
/* A run with marks.commentIds set (see src/comments/commentMarks.js) --\r
|
|
121
|
+
presence/absence only, no per-comment value to vary the color by.\r
|
|
122
|
+
cursor: pointer hints that it opens CommentPopover on click. */\r
|
|
123
|
+
.be-comment-highlight {\r
|
|
124
|
+
background: rgba(234, 179, 8, 0.2);\r
|
|
125
|
+
border-bottom: 2px solid rgba(234, 179, 8, 0.6);\r
|
|
126
|
+
cursor: pointer;\r
|
|
127
|
+
}\r
|
|
128
|
+
\r
|
|
129
|
+
/* Echoes a hover from the panel/popover back onto the actual text -- see useHoveredComment. */\r
|
|
130
|
+
.be-comment-highlight-active {\r
|
|
131
|
+
background: rgba(234, 179, 8, 0.4);\r
|
|
132
|
+
}\r
|
|
133
|
+
\r
|
|
119
134
|
/* --- basic leaf blocks --- */\r
|
|
120
135
|
\r
|
|
121
136
|
.be-paragraph {\r
|
|
@@ -1703,6 +1718,67 @@ tr.be-table-row:hover .be-table-delete-row {\r
|
|
|
1703
1718
|
color: var(--noteloom-danger);\r
|
|
1704
1719
|
}\r
|
|
1705
1720
|
\r
|
|
1721
|
+
/* --- template picker (see TemplatePicker.jsx) --- */\r
|
|
1722
|
+
\r
|
|
1723
|
+
.be-template-picker {\r
|
|
1724
|
+
list-style: none;\r
|
|
1725
|
+
margin: 0;\r
|
|
1726
|
+
padding: 0;\r
|
|
1727
|
+
display: flex;\r
|
|
1728
|
+
flex-direction: column;\r
|
|
1729
|
+
gap: 6px;\r
|
|
1730
|
+
}\r
|
|
1731
|
+
\r
|
|
1732
|
+
.be-template-picker-empty {\r
|
|
1733
|
+
color: var(--noteloom-text-faint);\r
|
|
1734
|
+
font-size: 0.88rem;\r
|
|
1735
|
+
}\r
|
|
1736
|
+
\r
|
|
1737
|
+
.be-template-card {\r
|
|
1738
|
+
display: flex;\r
|
|
1739
|
+
align-items: center;\r
|
|
1740
|
+
justify-content: space-between;\r
|
|
1741
|
+
gap: 12px;\r
|
|
1742
|
+
padding: 10px 12px;\r
|
|
1743
|
+
border: 1px solid var(--noteloom-border);\r
|
|
1744
|
+
border-radius: var(--noteloom-radius-md);\r
|
|
1745
|
+
background: var(--noteloom-bg);\r
|
|
1746
|
+
}\r
|
|
1747
|
+
\r
|
|
1748
|
+
.be-template-card-body {\r
|
|
1749
|
+
display: flex;\r
|
|
1750
|
+
flex-direction: column;\r
|
|
1751
|
+
gap: 2px;\r
|
|
1752
|
+
min-width: 0;\r
|
|
1753
|
+
}\r
|
|
1754
|
+
\r
|
|
1755
|
+
.be-template-card-name {\r
|
|
1756
|
+
font-weight: 600;\r
|
|
1757
|
+
font-size: 0.92rem;\r
|
|
1758
|
+
color: var(--noteloom-text);\r
|
|
1759
|
+
}\r
|
|
1760
|
+
\r
|
|
1761
|
+
.be-template-card-description {\r
|
|
1762
|
+
font-size: 0.82rem;\r
|
|
1763
|
+
color: var(--noteloom-text-muted);\r
|
|
1764
|
+
}\r
|
|
1765
|
+
\r
|
|
1766
|
+
.be-template-card-select {\r
|
|
1767
|
+
flex: none;\r
|
|
1768
|
+
border: 1px solid var(--noteloom-border);\r
|
|
1769
|
+
background: var(--noteloom-bg-subtle);\r
|
|
1770
|
+
color: var(--noteloom-text);\r
|
|
1771
|
+
border-radius: var(--noteloom-radius-sm);\r
|
|
1772
|
+
padding: 5px 12px;\r
|
|
1773
|
+
font-size: 0.85rem;\r
|
|
1774
|
+
font-weight: 500;\r
|
|
1775
|
+
cursor: pointer;\r
|
|
1776
|
+
}\r
|
|
1777
|
+
\r
|
|
1778
|
+
.be-template-card-select:hover {\r
|
|
1779
|
+
background: var(--noteloom-bg-hover);\r
|
|
1780
|
+
}\r
|
|
1781
|
+
\r
|
|
1706
1782
|
/* --- mobile action bar (pinned above the on-screen keyboard) --- */\r
|
|
1707
1783
|
\r
|
|
1708
1784
|
.be-mobile-action-bar {\r
|
|
@@ -2375,6 +2451,323 @@ tr.be-table-row:hover .be-table-delete-row {\r
|
|
|
2375
2451
|
color: var(--noteloom-text);\r
|
|
2376
2452
|
}\r
|
|
2377
2453
|
\r
|
|
2454
|
+
/* --- comments: avatar, header, composer, thread card, click/hover popover, right-side panel --- */\r
|
|
2455
|
+
\r
|
|
2456
|
+
.be-comment-avatar {\r
|
|
2457
|
+
flex: none;\r
|
|
2458
|
+
display: flex;\r
|
|
2459
|
+
align-items: center;\r
|
|
2460
|
+
justify-content: center;\r
|
|
2461
|
+
border-radius: 50%;\r
|
|
2462
|
+
color: #fff;\r
|
|
2463
|
+
font-weight: 700;\r
|
|
2464
|
+
line-height: 1;\r
|
|
2465
|
+
}\r
|
|
2466
|
+
\r
|
|
2467
|
+
/* Shared by CommentPopover and FloatingToolbar's standalone composer (see\r
|
|
2468
|
+
CommentPopoverHeader.jsx) -- title on the left, an explicit close button\r
|
|
2469
|
+
on the right so dismissing doesn't rely solely on Escape/outside-click. */\r
|
|
2470
|
+
.be-comment-popover-header {\r
|
|
2471
|
+
display: flex;\r
|
|
2472
|
+
align-items: center;\r
|
|
2473
|
+
justify-content: space-between;\r
|
|
2474
|
+
gap: 8px;\r
|
|
2475
|
+
margin-bottom: 10px;\r
|
|
2476
|
+
padding-bottom: 10px;\r
|
|
2477
|
+
border-bottom: 1px solid var(--noteloom-border);\r
|
|
2478
|
+
}\r
|
|
2479
|
+
\r
|
|
2480
|
+
.be-comment-popover-title {\r
|
|
2481
|
+
font-weight: 700;\r
|
|
2482
|
+
font-size: 0.9rem;\r
|
|
2483
|
+
}\r
|
|
2484
|
+
\r
|
|
2485
|
+
.be-comment-popover-close {\r
|
|
2486
|
+
flex: none;\r
|
|
2487
|
+
border: none;\r
|
|
2488
|
+
background: transparent;\r
|
|
2489
|
+
color: var(--noteloom-text-muted);\r
|
|
2490
|
+
width: 22px;\r
|
|
2491
|
+
height: 22px;\r
|
|
2492
|
+
display: flex;\r
|
|
2493
|
+
align-items: center;\r
|
|
2494
|
+
justify-content: center;\r
|
|
2495
|
+
border-radius: var(--noteloom-radius-sm);\r
|
|
2496
|
+
cursor: pointer;\r
|
|
2497
|
+
}\r
|
|
2498
|
+
\r
|
|
2499
|
+
.be-comment-popover-close:hover {\r
|
|
2500
|
+
background: var(--noteloom-bg-hover);\r
|
|
2501
|
+
color: var(--noteloom-text);\r
|
|
2502
|
+
}\r
|
|
2503
|
+
\r
|
|
2504
|
+
/* Overrides the dark \`.be-floating-toolbar\` chrome it also carries (see\r
|
|
2505
|
+
FloatingToolbar.jsx's own comment on why that base class stays) -- a\r
|
|
2506
|
+
comment composer reads better as a light card than white text on the\r
|
|
2507
|
+
toolbar's own near-black background. */\r
|
|
2508
|
+
.be-floating-toolbar.be-floating-toolbar-comment-standalone {\r
|
|
2509
|
+
display: block;\r
|
|
2510
|
+
background: var(--noteloom-bg);\r
|
|
2511
|
+
border: 1px solid var(--noteloom-border);\r
|
|
2512
|
+
padding: 10px 12px 12px;\r
|
|
2513
|
+
width: 300px;\r
|
|
2514
|
+
}\r
|
|
2515
|
+
\r
|
|
2516
|
+
.be-comment-composer {\r
|
|
2517
|
+
display: flex;\r
|
|
2518
|
+
flex-direction: column;\r
|
|
2519
|
+
gap: 10px;\r
|
|
2520
|
+
margin-top: 10px;\r
|
|
2521
|
+
}\r
|
|
2522
|
+
\r
|
|
2523
|
+
.be-comment-composer-input-row {\r
|
|
2524
|
+
display: flex;\r
|
|
2525
|
+
align-items: flex-start;\r
|
|
2526
|
+
gap: 8px;\r
|
|
2527
|
+
}\r
|
|
2528
|
+
\r
|
|
2529
|
+
.be-comment-composer-textarea {\r
|
|
2530
|
+
flex: 1;\r
|
|
2531
|
+
min-width: 0;\r
|
|
2532
|
+
box-sizing: border-box;\r
|
|
2533
|
+
resize: none;\r
|
|
2534
|
+
/* ~2 lines to start, grows with content (see CommentComposer's own\r
|
|
2535
|
+
resizeToContent) up to ~5 lines, then scrolls. */\r
|
|
2536
|
+
min-height: 2.8em;\r
|
|
2537
|
+
max-height: 7.2em;\r
|
|
2538
|
+
overflow-y: auto;\r
|
|
2539
|
+
padding: 8px 10px;\r
|
|
2540
|
+
font: inherit;\r
|
|
2541
|
+
font-size: 0.85rem;\r
|
|
2542
|
+
line-height: 1.4;\r
|
|
2543
|
+
color: var(--noteloom-text);\r
|
|
2544
|
+
background: var(--noteloom-bg-subtle);\r
|
|
2545
|
+
border: 1px solid var(--noteloom-border);\r
|
|
2546
|
+
border-radius: var(--noteloom-radius-md);\r
|
|
2547
|
+
}\r
|
|
2548
|
+
\r
|
|
2549
|
+
.be-comment-composer-textarea:focus {\r
|
|
2550
|
+
outline: none;\r
|
|
2551
|
+
border-color: var(--noteloom-accent);\r
|
|
2552
|
+
}\r
|
|
2553
|
+
\r
|
|
2554
|
+
.be-comment-composer-actions {\r
|
|
2555
|
+
display: flex;\r
|
|
2556
|
+
justify-content: flex-end;\r
|
|
2557
|
+
gap: 8px;\r
|
|
2558
|
+
}\r
|
|
2559
|
+
\r
|
|
2560
|
+
.be-comment-composer-cancel,\r
|
|
2561
|
+
.be-comment-composer-submit {\r
|
|
2562
|
+
display: flex;\r
|
|
2563
|
+
align-items: center;\r
|
|
2564
|
+
gap: 6px;\r
|
|
2565
|
+
border: none;\r
|
|
2566
|
+
border-radius: var(--noteloom-radius-md);\r
|
|
2567
|
+
padding: 6px 12px;\r
|
|
2568
|
+
font-size: 0.8rem;\r
|
|
2569
|
+
font-weight: 600;\r
|
|
2570
|
+
cursor: pointer;\r
|
|
2571
|
+
}\r
|
|
2572
|
+
\r
|
|
2573
|
+
.be-comment-composer-cancel {\r
|
|
2574
|
+
background: var(--noteloom-bg-hover);\r
|
|
2575
|
+
color: var(--noteloom-text-muted);\r
|
|
2576
|
+
}\r
|
|
2577
|
+
\r
|
|
2578
|
+
.be-comment-composer-submit {\r
|
|
2579
|
+
background: var(--noteloom-accent);\r
|
|
2580
|
+
color: #fff;\r
|
|
2581
|
+
}\r
|
|
2582
|
+
\r
|
|
2583
|
+
.be-comment-composer-submit:disabled {\r
|
|
2584
|
+
opacity: 0.4;\r
|
|
2585
|
+
cursor: not-allowed;\r
|
|
2586
|
+
}\r
|
|
2587
|
+
\r
|
|
2588
|
+
.be-comment-thread {\r
|
|
2589
|
+
font-size: 0.85rem;\r
|
|
2590
|
+
}\r
|
|
2591
|
+
\r
|
|
2592
|
+
.be-comment-thread + .be-comment-thread {\r
|
|
2593
|
+
margin-top: 16px;\r
|
|
2594
|
+
padding-top: 16px;\r
|
|
2595
|
+
border-top: 1px solid var(--noteloom-border);\r
|
|
2596
|
+
}\r
|
|
2597
|
+
\r
|
|
2598
|
+
.be-comment-thread-resolved {\r
|
|
2599
|
+
opacity: 0.6;\r
|
|
2600
|
+
}\r
|
|
2601
|
+
\r
|
|
2602
|
+
/* Echoes a hover from the highlighted text back onto this card -- see useHoveredComment. */\r
|
|
2603
|
+
.be-comment-thread-hovered {\r
|
|
2604
|
+
background: var(--noteloom-bg-hover);\r
|
|
2605
|
+
border-radius: var(--noteloom-radius-md);\r
|
|
2606
|
+
margin: -6px;\r
|
|
2607
|
+
padding: 6px;\r
|
|
2608
|
+
}\r
|
|
2609
|
+
\r
|
|
2610
|
+
.be-comment-message {\r
|
|
2611
|
+
display: flex;\r
|
|
2612
|
+
align-items: flex-start;\r
|
|
2613
|
+
gap: 10px;\r
|
|
2614
|
+
}\r
|
|
2615
|
+
\r
|
|
2616
|
+
.be-comment-message + .be-comment-message {\r
|
|
2617
|
+
margin-top: 10px;\r
|
|
2618
|
+
}\r
|
|
2619
|
+
\r
|
|
2620
|
+
.be-comment-message-body {\r
|
|
2621
|
+
flex: 1;\r
|
|
2622
|
+
min-width: 0;\r
|
|
2623
|
+
}\r
|
|
2624
|
+
\r
|
|
2625
|
+
.be-comment-message-header {\r
|
|
2626
|
+
display: flex;\r
|
|
2627
|
+
align-items: baseline;\r
|
|
2628
|
+
gap: 6px;\r
|
|
2629
|
+
}\r
|
|
2630
|
+
\r
|
|
2631
|
+
.be-comment-message-author {\r
|
|
2632
|
+
font-weight: 600;\r
|
|
2633
|
+
font-size: 0.78rem;\r
|
|
2634
|
+
}\r
|
|
2635
|
+
\r
|
|
2636
|
+
.be-comment-message-time {\r
|
|
2637
|
+
font-size: 0.72rem;\r
|
|
2638
|
+
color: var(--noteloom-text-muted);\r
|
|
2639
|
+
}\r
|
|
2640
|
+
\r
|
|
2641
|
+
.be-comment-message-text {\r
|
|
2642
|
+
margin: 3px 0 0;\r
|
|
2643
|
+
line-height: 1.45;\r
|
|
2644
|
+
white-space: pre-wrap;\r
|
|
2645
|
+
word-break: break-word;\r
|
|
2646
|
+
}\r
|
|
2647
|
+
\r
|
|
2648
|
+
/* Replies (every message after the thread's first) get a connecting\r
|
|
2649
|
+
vertical line + indent, chat-thread style -- our data model has no\r
|
|
2650
|
+
deeper nesting than "root message + flat replies", so one indent level\r
|
|
2651
|
+
is all this needs. */\r
|
|
2652
|
+
.be-comment-thread-replies {\r
|
|
2653
|
+
margin: 10px 0 0 13px;\r
|
|
2654
|
+
padding-left: 14px;\r
|
|
2655
|
+
border-left: 2px solid var(--noteloom-border);\r
|
|
2656
|
+
}\r
|
|
2657
|
+
\r
|
|
2658
|
+
.be-comment-thread-actions {\r
|
|
2659
|
+
display: flex;\r
|
|
2660
|
+
align-items: center;\r
|
|
2661
|
+
gap: 4px;\r
|
|
2662
|
+
margin-top: 10px;\r
|
|
2663
|
+
opacity: 0;\r
|
|
2664
|
+
transition: opacity 0.1s ease;\r
|
|
2665
|
+
}\r
|
|
2666
|
+
\r
|
|
2667
|
+
.be-comment-thread:hover .be-comment-thread-actions,\r
|
|
2668
|
+
.be-comment-thread:focus-within .be-comment-thread-actions {\r
|
|
2669
|
+
opacity: 1;\r
|
|
2670
|
+
}\r
|
|
2671
|
+
\r
|
|
2672
|
+
.be-comment-thread-actions button {\r
|
|
2673
|
+
display: flex;\r
|
|
2674
|
+
align-items: center;\r
|
|
2675
|
+
gap: 4px;\r
|
|
2676
|
+
border: none;\r
|
|
2677
|
+
background: transparent;\r
|
|
2678
|
+
color: var(--noteloom-text-muted);\r
|
|
2679
|
+
font-size: 0.78rem;\r
|
|
2680
|
+
padding: 4px 8px;\r
|
|
2681
|
+
border-radius: var(--noteloom-radius-sm);\r
|
|
2682
|
+
cursor: pointer;\r
|
|
2683
|
+
}\r
|
|
2684
|
+
\r
|
|
2685
|
+
.be-comment-thread-actions button:hover {\r
|
|
2686
|
+
background: var(--noteloom-bg-hover);\r
|
|
2687
|
+
color: var(--noteloom-text);\r
|
|
2688
|
+
}\r
|
|
2689
|
+
\r
|
|
2690
|
+
.be-comment-thread-delete {\r
|
|
2691
|
+
margin-left: auto;\r
|
|
2692
|
+
}\r
|
|
2693
|
+
\r
|
|
2694
|
+
/* --- comments: click/hover popover over existing highlighted text --- */\r
|
|
2695
|
+
\r
|
|
2696
|
+
.be-comment-popover {\r
|
|
2697
|
+
z-index: 1000;\r
|
|
2698
|
+
width: 300px;\r
|
|
2699
|
+
max-width: calc(100vw - 24px);\r
|
|
2700
|
+
background: var(--noteloom-bg);\r
|
|
2701
|
+
border: 1px solid var(--noteloom-border);\r
|
|
2702
|
+
border-radius: var(--noteloom-radius-lg);\r
|
|
2703
|
+
padding: 12px 14px 14px;\r
|
|
2704
|
+
box-shadow: var(--noteloom-shadow);\r
|
|
2705
|
+
}\r
|
|
2706
|
+
\r
|
|
2707
|
+
/* --- comments: opt-in right-side panel (NoteloomEditor showCommentsPanel) --- */\r
|
|
2708
|
+
\r
|
|
2709
|
+
/* Deliberately no border/shadow/box background here, or on\r
|
|
2710
|
+
.be-comments-panel-item below -- comments float directly on the page\r
|
|
2711
|
+
like margin notes, not a boxed widget, matching how most other editors'\r
|
|
2712
|
+
own comment sidebars read. */\r
|
|
2713
|
+
/* No overflow/scrolling of its own on purpose -- each card's position\r
|
|
2714
|
+
already tracks the PAGE's scroll (see CommentsPanel's recompute()), so\r
|
|
2715
|
+
the panel scrolling independently would fight that: a wheel gesture over\r
|
|
2716
|
+
it needs to fall through and scroll the page, not the panel's own box,\r
|
|
2717
|
+
or cards visually detach from the text they're anchored to. Cards whose\r
|
|
2718
|
+
anchor has scrolled off-screen just go negative/beyond the viewport and\r
|
|
2719
|
+
aren't painted -- no clipping box needed for that. */\r
|
|
2720
|
+
.be-comments-panel {\r
|
|
2721
|
+
position: fixed;\r
|
|
2722
|
+
top: 80px;\r
|
|
2723
|
+
right: 24px;\r
|
|
2724
|
+
width: 320px;\r
|
|
2725
|
+
overflow: visible;\r
|
|
2726
|
+
background: transparent;\r
|
|
2727
|
+
padding: 0 12px;\r
|
|
2728
|
+
font-size: 0.85rem;\r
|
|
2729
|
+
z-index: 500;\r
|
|
2730
|
+
pointer-events: none;\r
|
|
2731
|
+
}\r
|
|
2732
|
+
\r
|
|
2733
|
+
.be-comments-panel-item,\r
|
|
2734
|
+
.be-comments-panel-empty {\r
|
|
2735
|
+
pointer-events: auto;\r
|
|
2736
|
+
}\r
|
|
2737
|
+
\r
|
|
2738
|
+
.be-comments-panel-empty {\r
|
|
2739
|
+
color: var(--noteloom-text-muted);\r
|
|
2740
|
+
font-size: 0.82rem;\r
|
|
2741
|
+
margin: 0;\r
|
|
2742
|
+
}\r
|
|
2743
|
+
\r
|
|
2744
|
+
/* Each .be-comments-panel-item is absolutely positioned (top set inline by\r
|
|
2745
|
+
CommentsPanel, aligned with its thread's own anchored text, margin-comment\r
|
|
2746
|
+
style) inside this relatively-positioned container -- height is also set\r
|
|
2747
|
+
inline, sized to fit the lowest card. */\r
|
|
2748
|
+
.be-comments-panel-list {\r
|
|
2749
|
+
position: relative;\r
|
|
2750
|
+
}\r
|
|
2751
|
+
\r
|
|
2752
|
+
.be-comments-panel-item {\r
|
|
2753
|
+
position: absolute;\r
|
|
2754
|
+
left: 0;\r
|
|
2755
|
+
right: 0;\r
|
|
2756
|
+
padding: 8px 12px;\r
|
|
2757
|
+
border-radius: var(--noteloom-radius-md);\r
|
|
2758
|
+
transition: top 0.15s ease, background-color 0.1s ease;\r
|
|
2759
|
+
}\r
|
|
2760
|
+
\r
|
|
2761
|
+
.be-comments-panel-item:hover {\r
|
|
2762
|
+
background: var(--noteloom-bg-hover);\r
|
|
2763
|
+
}\r
|
|
2764
|
+
\r
|
|
2765
|
+
@media (max-width: 900px) {\r
|
|
2766
|
+
.be-comments-panel {\r
|
|
2767
|
+
display: none;\r
|
|
2768
|
+
}\r
|
|
2769
|
+
}\r
|
|
2770
|
+
\r
|
|
2378
2771
|
/* --- voice typing: caret-anchored listening/processing indicator --- */\r
|
|
2379
2772
|
\r
|
|
2380
2773
|
.be-voice-indicator {\r
|
|
@@ -2458,6 +2851,8 @@ tr.be-table-row:hover .be-table-delete-row {\r
|
|
|
2458
2851
|
#be-at-menu,\r
|
|
2459
2852
|
.be-floating-toolbar,\r
|
|
2460
2853
|
.be-link-hover-card,\r
|
|
2854
|
+
.be-comment-popover,\r
|
|
2855
|
+
.be-comments-panel,\r
|
|
2461
2856
|
.be-voice-indicator,\r
|
|
2462
2857
|
.be-table-header-menu-trigger,\r
|
|
2463
2858
|
.be-table-header-menu,\r
|
|
@@ -2522,12 +2917,11 @@ tr.be-table-row:hover .be-table-delete-row {\r
|
|
|
2522
2917
|
break-inside: avoid;\r
|
|
2523
2918
|
}\r
|
|
2524
2919
|
}\r
|
|
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
|
-
`)}
|
|
2528
|
-
`)}const
|
|
2529
|
-
`)
|
|
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(`
|
|
2920
|
+
`,Ns="noteloom-default-styles";function Aa(){if(typeof document>"u"||document.getElementById(Ns))return;const t=document.createElement("style");t.id=Ns,t.textContent=Ku,document.head.appendChild(t)}const Da=p.createContext(null);function Pa({store:t,registry:e,inlineRegistry:n=null,history:r=null,className:o,style:s,theme:a="default",getBlockClassName:i,commentAuthorId:u,children:c}){p.useEffect(()=>{a!=="none"&&Aa()},[a]);const[f,d]=p.useState(!1),[h,m]=p.useState(null),[g,x]=p.useState([]),[y,k]=p.useState(!1),[w,v]=p.useState(null),j=p.useCallback(()=>v("new"),[]),I=p.useCallback(N=>v(N),[]),C=p.useCallback(()=>v(null),[]),T=p.useRef(null),M=p.useCallback(()=>T.current,[]),B=p.useCallback(N=>{var V,K;const $=T.current;$!==N&&($&&((V=document.querySelector(`[data-block-id="${$}"]`))==null||V.classList.remove("be-block-selected")),T.current=N,N&&((K=document.querySelector(`[data-block-id="${N}"]`))==null||K.classList.add("be-block-selected")))},[]),L=p.useMemo(()=>({store:t,registry:e,inlineRegistry:n,history:r,isWholeDocumentSelected:f,setIsWholeDocumentSelected:d,selectedBlockRange:g,setSelectedBlockRange:x,getSelectedBlockId:M,setSelectedBlockId:B,isPreviewMode:y,setIsPreviewMode:k,fieldTypeEditorTarget:w,openCreateFieldType:j,openEditFieldType:I,closeFieldTypeEditor:C,getBlockClassName:i,commentAuthorId:u,hoveredCommentId:h,setHoveredCommentId:m}),[t,e,n,r,f,g,M,B,y,w,j,I,C,i,u,h]),S=o||s?l.jsx("div",{className:o?`be-root ${o}`:"be-root",style:s,children:c}):c;return l.jsx(Da.Provider,{value:L,children:S})}function Pe(){const t=p.useContext(Da);if(!t)throw new Error("Editor hooks must be used within an <EditorProvider>");return t}function G(){return Pe().store}function vt(){return Pe().registry}function tt(){return Pe().inlineRegistry}function Io(){const{isWholeDocumentSelected:t,setIsWholeDocumentSelected:e}=Pe();return[t,e]}function _n(){const{selectedBlockRange:t,setSelectedBlockRange:e}=Pe();return[t,e]}function ut(){const{getSelectedBlockId:t,setSelectedBlockId:e}=Pe();return{getSelectedBlockId:t,setSelectedBlockId:e}}function Co(){const{isPreviewMode:t,setIsPreviewMode:e}=Pe();return[t,e]}function Ie(t,e){const{getBlockClassName:n}=Pe(),r=e&&n?n(e):void 0;return r?`${t} ${r}`:t}function $a(){return Pe().commentAuthorId}function pr(){const{hoveredCommentId:t,setHoveredCommentId:e}=Pe();return[t,e]}function So(){const{fieldTypeEditorTarget:t,openCreateFieldType:e,openEditFieldType:n,closeFieldTypeEditor:r}=Pe();return{target:t,openCreate:e,openEdit:n,close:r}}const Wu="$comments";function za(){const t=G(),e=p.useCallback(r=>t.subscribe(Wu,r),[t]),n=p.useCallback(()=>t.getComments(),[t]);return p.useSyncExternalStore(e,n)}const As=["#e03131","#e8590c","#2f9e44","#1971c2","#9c36b5"];function Xu(t){let e=0;const n=String(t??"");for(let r=0;r<n.length;r+=1)e=e*31+n.charCodeAt(r)|0;return As[Math.abs(e)%As.length]}function qu(t){const e=String(t??"").trim();if(!e)return"?";const n=e.split(/\s+/).filter(Boolean);return n.length>=2?(n[0][0]+n[1][0]).toUpperCase():e.slice(0,2).toUpperCase()}const eo=60*1e3,to=60*eo,zr=24*to;function Gu(t,e=Date.now()){const n=e-t;if(n<eo)return"just now";if(n<to){const r=Math.floor(n/eo);return`${r} min${r===1?"":"s"} ago`}if(n<zr){const r=Math.floor(n/to);return`${r} hour${r===1?"":"s"} ago`}if(n<7*zr){const r=Math.floor(n/zr);return`${r} day${r===1?"":"s"} ago`}return new Date(t).toLocaleDateString()}function Ro({authorId:t,size:e=26}){return l.jsx("span",{className:"be-comment-avatar",style:{width:e,height:e,fontSize:Math.max(10,e*.4),background:Xu(t)},"aria-hidden":"true",children:qu(t)})}function Y({children:t,size:e=16,strokeWidth:n=2,...r}){return l.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",...r,children:t})}function jt(t){return l.jsx(Y,{...t,children:l.jsx("polyline",{points:"9 18 15 12 9 6"})})}function fr(t){return l.jsx(Y,{...t,children:l.jsx("polyline",{points:"6 9 12 15 18 9"})})}function Ot(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),l.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Ju(t){return l.jsxs(Y,{...t,fill:"currentColor",stroke:"none",children:[l.jsx("circle",{cx:"5",cy:"12",r:"1.6"}),l.jsx("circle",{cx:"12",cy:"12",r:"1.6"}),l.jsx("circle",{cx:"19",cy:"12",r:"1.6"})]})}function Ha(t){return l.jsx(Y,{...t,children:l.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 To(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),l.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function Fa(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"}),l.jsx("path",{d:"M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"})]})}function Ua(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"19",y1:"4",x2:"10",y2:"4"}),l.jsx("line",{x1:"14",y1:"20",x2:"5",y2:"20"}),l.jsx("line",{x1:"15",y1:"4",x2:"9",y2:"20"})]})}function Va(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M6 3v7a6 6 0 0 0 12 0V3"}),l.jsx("line",{x1:"4",y1:"21",x2:"20",y2:"21"})]})}function Ya(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M12 20h9"}),l.jsx("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]})}function Zu(t){return l.jsx(Y,{...t,children:l.jsx("path",{d:"M3 17c2-4 4-4 6 0s4 4 6 0 4-4 6 0"})})}function Ka(t){return l.jsxs(Y,{...t,children:[l.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"}),l.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 Wa(t){return l.jsx(Y,{...t,children:l.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})})}function Qu(t){return l.jsx(Y,{...t,children:l.jsx("polyline",{points:"20 6 9 17 4 12"})})}function ed(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),l.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function td(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M16 4H9a3 3 0 0 0-2.83 4"}),l.jsx("path",{d:"M14 12a4 4 0 0 1 0 8H6"}),l.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}function Xa(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),l.jsx("line",{x1:"17",y1:"10",x2:"3",y2:"10"}),l.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),l.jsx("line",{x1:"17",y1:"18",x2:"3",y2:"18"})]})}function nd(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),l.jsx("line",{x1:"18",y1:"10",x2:"6",y2:"10"}),l.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),l.jsx("line",{x1:"18",y1:"18",x2:"6",y2:"18"})]})}function qa(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),l.jsx("line",{x1:"21",y1:"10",x2:"7",y2:"10"}),l.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),l.jsx("line",{x1:"21",y1:"18",x2:"7",y2:"18"})]})}function rd(t){return l.jsx(Y,{...t,children:[5,12,19].flatMap(e=>[9,15].map(n=>l.jsx("circle",{cx:n,cy:e,r:"1.3",fill:"currentColor",stroke:"none"},`${n}-${e}`)))})}function On(t){return l.jsxs(Y,{...t,children:[l.jsx("polyline",{points:"3 6 5 6 21 6"}),l.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"}),l.jsx("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),l.jsx("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function jo(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"9",y:"9",width:"12",height:"12",rx:"2"}),l.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function hr(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),l.jsx("polyline",{points:"5 12 12 5 19 12"})]})}function mr(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),l.jsx("polyline",{points:"19 12 12 19 5 12"})]})}function Ga(t){return l.jsx(Y,{...t,children:l.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"1"})})}function od(t){return l.jsx(Y,{...t,children:l.jsx("circle",{cx:"12",cy:"12",r:"8"})})}function sd(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"6",y1:"18",x2:"18",y2:"6"}),l.jsx("polyline",{points:"9 6 18 6 18 15"})]})}function ad(t){return l.jsx(Y,{...t,children:l.jsx("polygon",{points:"12 3 21 12 12 21 3 12"})})}function ld(t){return l.jsx(Y,{...t,children:l.jsx("polygon",{points:"12 4 20 20 4 20"})})}function id(t){return l.jsx(Y,{...t,children:l.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 cd(t){return l.jsx(Y,{...t,children:l.jsx("path",{d:"M5 3l14 8-6 2-2 6-6-16z"})})}function Ja(t){return l.jsxs(Y,{...t,children:[l.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"}),l.jsx("path",{d:"M6.5 12.5 13 19"})]})}function ud(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M12 3v12"}),l.jsx("path",{d:"M7 10l5 5 5-5"}),l.jsx("path",{d:"M4 19h16"})]})}function dd(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M6 15V9a6 6 0 0 1 12 0v6"}),l.jsx("path",{d:"M6 15a3 3 0 0 0 6 0v-4"}),l.jsx("path",{d:"M18 15a3 3 0 0 1-6 0v-4"}),l.jsx("line",{x1:"3",y1:"9",x2:"6",y2:"9"}),l.jsx("line",{x1:"3",y1:"15",x2:"6",y2:"15"}),l.jsx("line",{x1:"18",y1:"9",x2:"21",y2:"9"}),l.jsx("line",{x1:"18",y1:"15",x2:"21",y2:"15"})]})}function pd(t){return l.jsxs(Y,{...t,children:[l.jsx("circle",{cx:"6",cy:"6",r:"3"}),l.jsx("circle",{cx:"6",cy:"18",r:"3"}),l.jsx("line",{x1:"20",y1:"4",x2:"8.12",y2:"15.88"}),l.jsx("line",{x1:"14.47",y1:"14.48",x2:"20",y2:"20"}),l.jsx("line",{x1:"8.12",y1:"8.12",x2:"12",y2:"12"})]})}function Eo(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"17",y1:"6",x2:"3",y2:"6"}),l.jsx("line",{x1:"21",y1:"12",x2:"3",y2:"12"}),l.jsx("line",{x1:"15",y1:"18",x2:"3",y2:"18"})]})}function Bo({level:t=1,size:e=16,...n}){return l.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",...n,children:l.jsxs("text",{x:"2",y:"18",fontSize:"14",fontWeight:"700",fill:"currentColor",fontFamily:"inherit",children:["H",t]})})}function Za(t){return l.jsx(Bo,{level:1,...t})}function Qa(t){return l.jsx(Bo,{level:2,...t})}function el(t){return l.jsx(Bo,{level:3,...t})}function tl(t){return l.jsxs(Y,{...t,children:[l.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"}),l.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 _o(t){return l.jsxs(Y,{...t,children:[l.jsx("polyline",{points:"9 8 4 12 9 16"}),l.jsx("polyline",{points:"15 8 20 12 15 16"})]})}function fd(t){return l.jsx(Y,{...t,children:l.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})})}function nl(t){return l.jsxs(Y,{...t,children:[l.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"}),l.jsx("line",{x1:"7",y1:"9",x2:"17",y2:"9"}),l.jsx("line",{x1:"7",y1:"12.5",x2:"13",y2:"12.5"})]})}function hd(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"3",y:"8",width:"18",height:"8",rx:"3"}),l.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function md(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"1"}),l.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"}),l.jsx("line",{x1:"3",y1:"16",x2:"21",y2:"16"}),l.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),l.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function bd(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"1"}),l.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),l.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function rl(t){return l.jsxs(Y,{...t,children:[l.jsx("circle",{cx:"4.5",cy:"6",r:"1.2",fill:"currentColor",stroke:"none"}),l.jsx("circle",{cx:"4.5",cy:"12",r:"1.2",fill:"currentColor",stroke:"none"}),l.jsx("circle",{cx:"4.5",cy:"18",r:"1.2",fill:"currentColor",stroke:"none"}),l.jsx("line",{x1:"9",y1:"6",x2:"21",y2:"6"}),l.jsx("line",{x1:"9",y1:"12",x2:"21",y2:"12"}),l.jsx("line",{x1:"9",y1:"18",x2:"21",y2:"18"})]})}function ol(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"10",y1:"6",x2:"21",y2:"6"}),l.jsx("line",{x1:"10",y1:"12",x2:"21",y2:"12"}),l.jsx("line",{x1:"10",y1:"18",x2:"21",y2:"18"}),l.jsx("text",{x:"2",y:"8.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"1"}),l.jsx("text",{x:"2",y:"14.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"2"}),l.jsx("text",{x:"2",y:"20.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"3"})]})}function Oo(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"3"}),l.jsx("polyline",{points:"8 12 11 15 16 9"})]})}function gd(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"3",y:"5",width:"18",height:"16",rx:"2"}),l.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"}),l.jsx("line",{x1:"8",y1:"3",x2:"8",y2:"7"}),l.jsx("line",{x1:"16",y1:"3",x2:"16",y2:"7"})]})}function sl(t){return l.jsxs(Y,{...t,children:[l.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"}),l.jsx("circle",{cx:"15.5",cy:"8.5",r:"1.2",fill:"currentColor",stroke:"none"})]})}function xd(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),l.jsx("circle",{cx:"9",cy:"10",r:"1.5",fill:"currentColor",stroke:"none"}),l.jsx("path",{d:"M4 17l5-5 4 4 4-5 4 6"})]})}function yd(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"3",y:"5",width:"14",height:"14",rx:"2"}),l.jsx("path",{d:"M17 10l4-2.5v9L17 14"})]})}function Mo(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7z"}),l.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function Lo(t){return l.jsxs(Y,{...t,children:[l.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"}),l.jsx("path",{d:"M14.12 14.12a3 3 0 1 1-4.24-4.24"}),l.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function kd(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"4",y1:"10",x2:"4",y2:"14"}),l.jsx("line",{x1:"8",y1:"7",x2:"8",y2:"17"}),l.jsx("line",{x1:"12",y1:"4",x2:"12",y2:"20"}),l.jsx("line",{x1:"16",y1:"7",x2:"16",y2:"17"}),l.jsx("line",{x1:"20",y1:"10",x2:"20",y2:"14"})]})}function vd(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),l.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),l.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),l.jsx("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}function No({authorId:t,placeholder:e="Add a comment…",autoFocus:n=!1,onSubmit:r,onCancel:o}){const[s,a]=p.useState(""),i=p.useRef(null),u=s.trim();function c(){const h=i.current;h&&(h.style.height="auto",h.style.height=`${h.scrollHeight}px`)}function f(h){a(h.target.value),c()}function d(h){h.preventDefault(),u&&(r(u),a(""),i.current&&(i.current.style.height=""))}return l.jsxs("form",{className:"be-comment-composer",onSubmit:d,children:[l.jsxs("div",{className:"be-comment-composer-input-row",children:[l.jsx(Ro,{authorId:t,size:26}),l.jsx("textarea",{ref:i,className:"be-comment-composer-textarea",value:s,onChange:f,placeholder:e,rows:2,autoFocus:n,onKeyDown:h=>{h.key==="Enter"&&(h.metaKey||h.ctrlKey)?d(h):h.key==="Escape"&&o&&o()}})]}),l.jsxs("div",{className:"be-comment-composer-actions",children:[o&&l.jsx("button",{type:"button",className:"be-comment-composer-cancel",onClick:o,children:"Cancel"}),l.jsxs("button",{type:"submit",className:"be-comment-composer-submit",disabled:!u,children:[l.jsx(ed,{size:13}),"Send"]})]})]})}function Ds({message:t,size:e=26}){return l.jsxs("div",{className:"be-comment-message",children:[l.jsx(Ro,{authorId:t.authorId,size:e}),l.jsxs("div",{className:"be-comment-message-body",children:[l.jsxs("div",{className:"be-comment-message-header",children:[l.jsx("span",{className:"be-comment-message-author",children:t.authorId}),l.jsx("span",{className:"be-comment-message-time",children:Gu(t.createdAt)})]}),l.jsx("p",{className:"be-comment-message-text",children:t.text})]})]})}function Ao({store:t,thread:e,authorId:n,onJumpToText:r}){const[o,s]=p.useState(!1),[a,i]=pr(),[u,...c]=e.messages;function f(d){Ma(t,e.id,{authorId:n,text:d}),s(!1)}return l.jsxs("div",{className:`be-comment-thread${e.resolved?" be-comment-thread-resolved":""}${a===e.id?" be-comment-thread-hovered":""}`,onMouseEnter:()=>i(e.id),onMouseLeave:()=>i(null),children:[l.jsx("div",{onClick:r?()=>r(e.id):void 0,style:r?{cursor:"pointer"}:void 0,children:l.jsx(Ds,{message:u})}),c.length>0&&l.jsx("div",{className:"be-comment-thread-replies",children:c.map(d=>l.jsx(Ds,{message:d,size:22},d.id))}),o?l.jsx(No,{authorId:n,placeholder:"Reply…",autoFocus:!0,onSubmit:f,onCancel:()=>s(!1)}):l.jsxs("div",{className:"be-comment-thread-actions",children:[n&&l.jsxs("button",{type:"button",onClick:()=>s(!0),children:[l.jsx(Wa,{size:13}),"Reply"]}),l.jsxs("button",{type:"button",onClick:()=>La(t,e.id,!e.resolved),children:[l.jsx(Qu,{size:13}),e.resolved?"Reopen":"Resolve"]}),l.jsx("button",{type:"button",className:"be-comment-thread-delete",onClick:()=>Na(t,e.id),"aria-label":"Delete comment",title:"Delete comment",children:l.jsx(On,{size:13})})]})]})}function al(t,e){var n,r,o;for(const s of e.anchorRunIds??[]){const a=document.querySelector(`[data-run-id="${s}"]`);if(a)return a}for(const s of t.getAllRunIds())if((o=(r=(n=t.getRun(s))==null?void 0:n.marks)==null?void 0:r.commentIds)!=null&&o.includes(e.id)){const a=document.querySelector(`[data-run-id="${s}"]`);if(a)return a}return null}function wd(t,e,n){const r=t.getComment(e);if(!r)return;const o=al(t,r);o&&(o.scrollIntoView({behavior:"smooth",block:"center"}),n(e),setTimeout(()=>n(s=>s===e?null:s),1500))}function ll({authorId:t}){const e=G(),n=za(),[,r]=pr(),o=p.useRef(null),[s,a]=p.useState({}),i=[...n].sort((c,f)=>Number(c.resolved)-Number(f.resolved));p.useLayoutEffect(()=>{function c(){const f=o.current;if(!f)return;const d=f.getBoundingClientRect().top,h={};let m=-1/0;for(const g of i){const x=al(e,g),y=x?x.getBoundingClientRect().top-d:Number.isFinite(m)?m+90:0,k=Math.max(m,y);h[g.id]=k,m=k+90}a(h)}return c(),window.addEventListener("scroll",c,!0),window.addEventListener("resize",c),()=>{window.removeEventListener("scroll",c,!0),window.removeEventListener("resize",c)}},[n,e]);const u=Object.values(s).reduce((c,f)=>Math.max(c,f+120),0);return i.length===0?null:l.jsx("div",{className:"be-comments-panel",contentEditable:!1,children:l.jsx("div",{ref:o,className:"be-comments-panel-list",style:{height:u},children:i.map(c=>l.jsx("div",{className:"be-comments-panel-item",style:{top:s[c.id]??0},children:l.jsx(Ao,{store:e,thread:c,authorId:t,onJumpToText:f=>wd(e,f,r)})},c.id))})})}class il{constructor(){this._types=new Map}register(e,n){this._types.set(e,n)}get(e){return this._types.get(e)}isLeaf(e){var n;return!!((n=this._types.get(e))!=null&&n.isLeaf)}listSlashCommands(){const e=[];for(const n of this._types.values())n.slashCommand&&e.push(n.slashCommand),n.slashCommands&&e.push(...n.slashCommands);return e}listHtmlMatchers(){return[...this._types.values()].filter(e=>e.fromHTML)}}function cl(){return new il}class ul{constructor(){this._types=new Map}register(e,n){this._types.set(e,n)}unregister(e){this._types.delete(e)}get(e){return this._types.get(e)}listHtmlMatchers(){return[...this._types.values()].filter(e=>e.fromHTML)}listSlashCommands(){const e=[];for(const n of this._types.values())n.slashCommand&&e.push(n.slashCommand),n.slashCommands&&e.push(...n.slashCommands);return e}listAtCommands(){const e=[];for(const n of this._types.values())n.atCommand&&e.push(n.atCommand),n.atCommands&&e.push(...n.atCommands);return e}}function dl(){return new ul}function be(t){const e=G(),n=p.useCallback(o=>e.subscribe(t,o),[e,t]),r=p.useCallback(()=>e.getBlock(t),[e,t]);return p.useSyncExternalStore(n,r)}function wt(t){const e=G(),n=p.useCallback(o=>e.subscribe(t,o),[e,t]),r=p.useCallback(()=>e.getRun(t),[e,t]);return p.useSyncExternalStore(n,r)}const pl="",Id=//g;function at(t){return(t??"").replace(Id,"")}function Ps(t){return at(t.textContent)}function Cd(t,e){var i;const n=new Map(e.map(u=>[u.id,u])),r=new Set,o=[];let s=!0;for(const u of t.childNodes){const c=u.nodeType===1?(i=u.dataset)==null?void 0:i.runId:void 0;if(c&&n.has(c)){r.add(c);const d=n.get(c);if(d.type!=="text"){o.push(d);continue}const h=Ps(u);o.push(h===d.value?d:{...d,value:h});continue}s=!1;const f=Ps(u);f&&o.push({id:E(),type:"text",value:f,marks:{}})}if(e.some(u=>!r.has(u.id))&&(s=!1),o.length!==e.length&&(s=!1),s){for(let u=0;u<o.length;u+=1)if(o[u].id!==e[u].id){s=!1;break}}const a=!s||o.some((u,c)=>u!==e[c]);return{runs:o,changed:a,onlyValueChanges:s}}function fl(t){return t?t.type!=="text"?!1:(t.value??"")==="":!0}function Le(t,e){return!e||e.length===0?!0:e.every(n=>fl(t.getRun(n)))}function Mn(t,e){var o,s;if(!e)return!1;const n=e.contentIds.length>0,r=(((s=(o=e.props)==null?void 0:o.titleRunIds)==null?void 0:s.length)??0)>0;return!n&&!r}function hl(t,e){const n=document.querySelector(`[data-run-id="${t}"]`);if(!n)return;n.focus();const r=n.firstChild,o=document.createRange();if(r&&r.nodeType===3){const a=Math.max(0,Math.min(e,r.length));o.setStart(r,a),o.setEnd(r,a)}else o.selectNodeContents(n),o.collapse(e<=0);const s=window.getSelection();s==null||s.removeAllRanges(),s==null||s.addRange(o)}function ml(t,e){requestAnimationFrame(()=>{const n=document.querySelector(`[data-run-id="${t}"]`);if(!n)return;n.focus();const r=document.createRange();r.selectNodeContents(n),r.collapse(e);const o=window.getSelection();o==null||o.removeAllRanges(),o==null||o.addRange(r)})}function ye(t){ml(t,!1)}function br(t){ml(t,!0)}function Je(t,e){requestAnimationFrame(()=>hl(t,e))}function $s(t,e){hl(t,e)}const Sd='button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';function dt({isOpen:t,onClose:e,title:n,size:r="default",variant:o="dialog",children:s}){const a=p.useRef(null),i=p.useRef(null);if(p.useEffect(()=>{if(!t)return;const c=f=>{f.key==="Escape"&&e()};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[t,e]),p.useEffect(()=>{var c,f,d;if(t){i.current=document.activeElement;const h=a.current;(c=(h==null?void 0:h.querySelector(Sd))??h)==null||c.focus();return}(d=(f=i.current)==null?void 0:f.focus)==null||d.call(f),i.current=null},[t]),!t)return null;const u=o==="sheet";return l.jsx("div",{className:`be-modal-overlay${u?" be-modal-overlay-sheet":""}`,onMouseDown:c=>{c.target===c.currentTarget&&e()},children:l.jsxs("div",{ref:a,className:`be-modal${r==="large"?" be-modal-large":""}${u?" be-modal-sheet":""}`,role:"dialog","aria-modal":"true","aria-label":n,tabIndex:-1,children:[n&&l.jsx("div",{className:"be-modal-title",children:n}),s]})})}function bl({isOpen:t,initialHref:e,initialTarget:n,hasExistingLink:r,onSave:o,onRemove:s,onClose:a}){const[i,u]=p.useState(""),[c,f]=p.useState("_self");p.useEffect(()=>{t&&(u(e),f(n))},[t]);const d=i.trim(),h=p.useCallback(m=>{m.preventDefault(),d&&o(d,c)},[d,c,o]);return l.jsx(dt,{isOpen:t,onClose:a,title:r?"Edit link":"Add link",children:l.jsxs("form",{onSubmit:h,children:[l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"URL"}),l.jsx("input",{type:"text",value:i,onChange:m=>u(m.target.value),placeholder:"https://example.com",autoFocus:!0})]}),l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Open in"}),l.jsxs("select",{value:c,onChange:m=>f(m.target.value),children:[l.jsx("option",{value:"_self",children:"Same tab"}),l.jsx("option",{value:"_blank",children:"New tab"})]})]}),l.jsxs("div",{className:"be-modal-actions",children:[r&&l.jsx("button",{type:"button",className:"be-modal-delete",onClick:s,children:"Remove link"}),l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:a,children:"Cancel"}),l.jsx("button",{type:"submit",className:"be-modal-save",disabled:!d,children:"Save"})]})]})})}const tn=8;function gr(t,e){const n=Math.max(tn,window.innerWidth-e-tn);return Math.min(Math.max(t,tn),n)}function Rd(t,e){const n=Math.max(tn,window.innerHeight-e-tn);return Math.min(Math.max(t,tn),n)}function Ln(t,e,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(!e||!t.current||!o)return;const a=t.current.getBoundingClientRect(),i=gr(o.left,a.width),u=Rd(o.top,a.height);(i!==o.left||u!==o.top)&&s({top:u,left:i})},[e,t,o]),o}function Td({containerRef:t,store:e}){var w;const[n,r]=p.useState(null),[o,s]=p.useState(!1),a=p.useRef(null),i=p.useRef(null),u=p.useCallback(()=>{a.current&&(clearTimeout(a.current),a.current=null)},[]),c=p.useCallback(()=>{u(),a.current=setTimeout(()=>{r(v=>o?v:null)},250)},[u,o]);p.useEffect(()=>{const v=t.current;if(!v)return;const j=C=>{var L,S,N;const T=(S=(L=C.target).closest)==null?void 0:S.call(L,"[data-run-id]");if(!T||!v.contains(T))return;const M=T.dataset.runId,B=e.getRun(M);(N=B==null?void 0:B.marks)!=null&&N.link&&(u(),r($=>($==null?void 0:$.runId)===M?$:{runId:M,rect:T.getBoundingClientRect()}))},I=()=>c();return v.addEventListener("mouseover",j),v.addEventListener("mouseout",I),()=>{v.removeEventListener("mouseover",j),v.removeEventListener("mouseout",I)}},[t,e,u,c]),p.useEffect(()=>()=>u(),[u]);const f=p.useCallback(()=>s(!0),[]),d=p.useCallback(()=>{s(!1),r(null)},[]),h=p.useCallback((v,j)=>{if(!n)return;const I=e.getRun(n.runId);I&&(e.applyOperation(ue(n.runId,{marks:{...I.marks,link:{href:v,target:j}}})),d())},[n,e,d]),m=p.useCallback(()=>{if(!n)return;const v=e.getRun(n.runId);if(!v)return;const j={...v.marks};delete j.link,e.applyOperation(ue(n.runId,{marks:j})),d()},[n,e,d]),g=n&&e.getRun(n.runId),x=(w=g==null?void 0:g.marks)==null?void 0:w.link,y=!!(n&&x&&!o),k=Ln(i,y,n?n.rect.bottom+6:null,n?n.rect.left:null);return l.jsxs(l.Fragment,{children:[y&&k?Ve.createPortal(l.jsxs("div",{ref:i,className:"be-link-hover-card",contentEditable:!1,style:{position:"fixed",top:k.top,left:k.left},onMouseEnter:u,onMouseLeave:c,children:[l.jsx("a",{className:"be-link-hover-card-url",href:x.href,target:x.target==="_blank"?"_blank":"_self",rel:"noopener noreferrer",children:x.href}),l.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:f,"aria-label":"Edit link",title:"Edit link",children:l.jsx(Ya,{size:13})}),l.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:m,"aria-label":"Remove link",title:"Remove link",children:l.jsx(Ot,{size:13})})]}),document.body):null,l.jsx(bl,{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 gl({title:t,onClose:e}){return l.jsxs("div",{className:"be-comment-popover-header",children:[l.jsx("span",{className:"be-comment-popover-title",children:t}),l.jsx("button",{type:"button",className:"be-comment-popover-close",onClick:e,"aria-label":"Close",children:l.jsx(Ot,{size:14})})]})}function jd({containerRef:t,store:e,authorId:n}){const[r,o]=p.useState(null),[s,a]=p.useState(!1),i=p.useRef(null),u=p.useRef(null),[,c]=pr(),f=p.useCallback(()=>{i.current&&(clearTimeout(i.current),i.current=null)},[]),d=p.useCallback(()=>{f(),i.current=setTimeout(()=>{o(y=>s?y:null)},250)},[f,s]);p.useEffect(()=>{const y=t.current;if(!y)return;const k=I=>{var M,B,L;const C=(M=I==null?void 0:I.closest)==null?void 0:M.call(I,"[data-run-id]");if(!C||!y.contains(C))return null;const T=(L=(B=e.getRun(C.dataset.runId))==null?void 0:B.marks)==null?void 0:L.commentIds;return T!=null&&T.length?{runEl:C,commentIds:T}:null},w=I=>{const C=k(I.target);C&&(f(),o(T=>T&&T.runEl===C.runEl?T:{rect:C.runEl.getBoundingClientRect(),commentIds:C.commentIds,runEl:C.runEl}))},v=()=>d(),j=I=>{const C=k(I.target);if(!C){a(!1),o(null);return}f(),a(!0),o({rect:C.runEl.getBoundingClientRect(),commentIds:C.commentIds,runEl:C.runEl})};return y.addEventListener("mouseover",w),y.addEventListener("mouseout",v),y.addEventListener("click",j),()=>{y.removeEventListener("mouseover",w),y.removeEventListener("mouseout",v),y.removeEventListener("click",j)}},[t,e,f,d]),p.useEffect(()=>{if(!r)return;const y=w=>{var v,j;(v=u.current)!=null&&v.contains(w.target)||(j=t.current)!=null&&j.contains(w.target)||(a(!1),o(null))},k=w=>{w.key==="Escape"&&(a(!1),o(null))};return document.addEventListener("mousedown",y),document.addEventListener("keydown",k),()=>{document.removeEventListener("mousedown",y),document.removeEventListener("keydown",k)}},[r,t]),p.useEffect(()=>()=>f(),[f]),p.useEffect(()=>{var y;c(((y=r==null?void 0:r.commentIds)==null?void 0:y[0])??null)},[r,c]);const h=p.useCallback(()=>{a(!1),o(null)},[]),m=!!r,g=Ln(u,m,r?r.rect.bottom+6:null,r?r.rect.left:null);if(!m||!g)return null;const x=r.commentIds.map(y=>e.getComment(y)).filter(Boolean);return x.length===0?null:Ve.createPortal(l.jsxs("div",{ref:u,className:"be-comment-popover",contentEditable:!1,style:{position:"fixed",top:g.top,left:g.left},onMouseEnter:f,onMouseLeave:d,children:[l.jsx(gl,{title:`Comments (${x.length})`,onClose:h}),x.map(y=>l.jsx(Ao,{store:e,thread:y,authorId:n},y.id))]}),document.body)}function zs(t,e){const n=t==null?void 0:t.parentElement;if(!n||!n.hasAttribute("data-placeholder"))return;e.length===0||e.every(fl)?n.setAttribute("data-empty",""):n.removeAttribute("data-empty")}function Ed(t={}){return{fontWeight:t.bold?"bold":void 0,fontStyle:t.italic?"italic":void 0,textDecoration:[(t.underline||t.link)&&"underline",t.strike&&"line-through"].filter(Boolean).join(" ")||void 0,verticalAlign:t.subscript?"sub":t.superscript?"super":void 0,fontSize:t.subscript||t.superscript?"smaller":void 0,color:t.color||(t.link?"var(--noteloom-accent)":void 0),backgroundColor:t.highlight||void 0,cursor:t.link?"pointer":void 0}}function Bd(t,e){const n=t.childNodes.length===1?t.firstChild:null;n&&n.nodeType===3?n.nodeValue!==e&&(n.nodeValue=e):t.textContent=e}function _d({id:t,host:e,onValueSynced:n}){const r=wt(t),[o]=pr();return p.useLayoutEffect(()=>{var f,d,h,m,g;if(!e||!r)return;const s=r.value??"";(at(e.textContent)!==s||s===""&&e.textContent==="")&&Bd(e,s===""?pl:s);const u=Ed(r.marks);e.style.fontWeight=u.fontWeight??"",e.style.fontStyle=u.fontStyle??"",e.style.textDecoration=u.textDecoration??"",e.style.verticalAlign=u.verticalAlign??"",e.style.fontSize=u.fontSize??"",e.style.color=u.color??"",e.style.backgroundColor=u.backgroundColor??"",e.style.cursor=u.cursor??"",e.classList.toggle("be-comment-highlight",(((d=(f=r.marks)==null?void 0:f.commentIds)==null?void 0:d.length)??0)>0),e.classList.toggle("be-comment-highlight-active",!!o&&!!((m=(h=r.marks)==null?void 0:h.commentIds)!=null&&m.includes(o)));const c=(g=r.marks)==null?void 0:g.link;e.title=c!=null&&c.href?`${c.href} — Ctrl+Click to open`:"",e.onclick=c!=null&&c.href?x=>{!x.ctrlKey&&!x.metaKey||(x.preventDefault(),window.open(c.href,c.target==="_blank"?"_blank":"_self","noopener,noreferrer"))}:null,n==null||n()},[e,r,n,o]),null}function Hs(t,e,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:a}=o;if(!s||!t.contains(s))return null;const i=g=>{const x=e.indexOf(g);if(x===-1)return null;const y=r?e[x-1]:e[x+1];if(!y)return null;const k=n(y);return k&&k.type!=="text"?y:null};if(s===t){const g=r?a-1:a,x=t.childNodes[g],y=(x==null?void 0:x.nodeType)===1?(h=x.dataset)==null?void 0:h.runId:void 0;if(!y||e.indexOf(y)===-1)return null;const k=n(y);return k&&k.type!=="text"?y:null}const u=s.nodeType===1?s:s.parentElement,c=(m=u==null?void 0:u.closest)==null?void 0:m.call(u,"[data-run-id]");return!c||!t.contains(c)||!(r?a===0:a===(s.textContent??"").length)?null:i(c.getAttribute("data-run-id"))}function Fs(t,e,n){var u,c;const r=(u=window.getSelection)==null?void 0:u.call(window);if(!r||r.isCollapsed||r.rangeCount===0)return null;const o=r.getRangeAt(0);if(o.startContainer!==o.endContainer||!t.contains(o.startContainer)||o.endOffset!==o.startOffset+1)return null;const s=o.startContainer.childNodes[o.startOffset],a=(s==null?void 0:s.nodeType)===1?(c=s.dataset)==null?void 0:c.runId:void 0;if(!a||e.indexOf(a)===-1)return null;const i=n(a);return i&&i.type!=="text"?a:null}function Us(t,e,n){var i;if(e===t)return{childIndex:n,charOffset:null};const r=e.nodeType===1?e:e.parentElement,o=(i=r==null?void 0:r.closest)==null?void 0:i.call(r,"[data-run-id]");if(!o||!t.contains(o))return null;const s=Array.prototype.indexOf.call(t.childNodes,o),a=e===o?n===0?0:(o.textContent??"").length:n;return{childIndex:s,charOffset:a}}function Od(t,e,n,r){const o=Us(t,r.startContainer,r.startOffset),s=Us(t,r.endContainer,r.endOffset);if(!o||!s)return null;const a=Array.from(t.childNodes).filter(f=>{var d;return f.nodeType===1&&((d=f.dataset)==null?void 0:d.runId)&&e.indexOf(f.dataset.runId)!==-1});let i=!1;const u=[];let c=null;return a.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){u.push(m);return}const y=o.charOffset!==null&&d===o.childIndex,k=s.charOffset!==null&&d===s.childIndex;if(m.type!=="text"){i=!0,c===null&&(c=u.length);return}const w=m.value??"";if(y&&k){const v=w.slice(0,o.charOffset)+w.slice(s.charOffset);v&&u.push({...m,value:v}),c=u.length}else if(y){const v=w.slice(0,o.charOffset);v&&u.push({...m,value:v}),c===null&&(c=u.length)}else if(k){const v=w.slice(s.charOffset);v&&u.push({id:E(),type:"text",value:v,marks:m.marks})}}),i?{nextRuns:u,insertionIndex:c??u.length}:null}function Md(t){var s;const e=(s=window.getSelection)==null?void 0:s.call(window);if(!e||!e.isCollapsed)return!1;const n=t.firstChild;if(!n)return!0;if(e.anchorNode===t)return e.anchorOffset===0;let r=n;for(;r&&r.firstChild;)r=r.firstChild;if(e.anchorNode!==r&&e.anchorNode!==n)return!1;const o=r.nodeType===3&&r.textContent===pl?1:0;return e.anchorOffset<=o}function Ld(t){var s;const e=(s=window.getSelection)==null?void 0:s.call(window);if(!e||!e.isCollapsed)return!1;const n=t.lastChild;if(!n)return!0;if(e.anchorNode===t)return e.anchorOffset>=t.childNodes.length;let r=n;for(;r&&r.lastChild;)r=r.lastChild;if(e.anchorNode!==r&&e.anchorNode!==n)return!1;const o=r.nodeType===3?(r.textContent??"").length:0;return e.anchorOffset>=o}function Vs(t,e,n){const r=t.getBlock(e),o=t.getBlock(r==null?void 0:r.parentId);if(!o)return null;const s=o.contentIds.indexOf(e),a=n==="backward"?s-1:s+1;if(a<0||a>=o.contentIds.length)return null;const i=o.contentIds[a];return Mn(t,t.getBlock(i))?i:null}function Nd({id:t,blockId:e,host:n,inlineRegistry:r,onValueSynced:o}){const s=wt(t);if(!s)return null;if(s.type==="text")return l.jsx(_d,{id:t,host:n,onValueSynced:o});const a=r==null?void 0:r.get(s.type);if(!a)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No inline type registered for "${s.type}" (run: ${t})`),null;const i=a.component;return l.jsx(i,{id:t,blockId:e})}function Ad(t,e,n){let r=t.get(n);if(!r){r=document.createElement("span"),r.dataset.runId=n;const o=e.getRun(n);o&&o.type!=="text"&&r.setAttribute("contenteditable","false"),t.set(n,r)}return r}function pt({blockId:t,runIds:e,dir:n="auto",onEnter:r,onBackspaceAtStart:o,onDeleteAtEnd:s,onArrowUp:a,onArrowDown:i,onTab:u,onShiftTab:c,onAutoformat:f}){const d=G(),h=tt(),m=$a(),{getSelectedBlockId:g,setSelectedBlockId:x}=ut(),y=p.useRef(null),k=p.useRef(!1),w=p.useRef(new Map);p.useLayoutEffect(()=>{const S=y.current;if(!S)return;const N=new Set(e);for(const[V,K]of w.current)N.has(V)||(K.remove(),w.current.delete(V));let $=null;for(const V of e){const K=w.current.get(V);if(!K)continue;const Q=$?$.nextSibling:S.firstChild;Q!==K&&S.insertBefore(K,Q),$=K}},[e]);const v=p.useCallback(()=>{if(k.current)return;const S=y.current;if(!S)return;const N=e.map(Q=>d.getRun(Q)).filter(Boolean),{runs:$,changed:V,onlyValueChanges:K}=Cd(S,N);if(V){if(K){if($.forEach((Q,D)=>{Q!==N[D]&&d.applyOperation(ue(Q.id,{value:Q.value}))}),f!=null&&f($))return}else d.applyOperation(Me(t,$.length?$:[{id:E(),type:"text",value:"",marks:{}}]));zs(S,$)}},[d,t,e,f]),j=p.useCallback(()=>{zs(y.current,e.map(S=>d.getRun(S)).filter(Boolean))},[d,e]),I=p.useCallback(()=>{k.current=!0},[]),C=p.useCallback(()=>{k.current=!1,v()},[v]),T=p.useCallback(S=>{const $=e.map(V=>d.getRun(V)).filter(Boolean).filter(V=>V.id!==S);d.applyOperation(Me(t,$.length?$:[{id:E(),type:"text",value:"",marks:{}}]))},[d,t,e]),M=p.useCallback(S=>{g()===S?(d.applyOperation(ee(S)),x(null)):x(S)},[d,g,x]),B=p.useCallback(S=>{var ce,ke,he,U;if(k.current)return;if(S.target instanceof Node){const ae=S.target.nodeType===1?S.target:S.target.parentElement;if((ce=ae==null?void 0:ae.closest)!=null&&ce.call(ae,'[contenteditable="false"]'))return}const N=S.inputType??"",$=N.startsWith("delete"),V=N==="insertText"||N==="insertReplacementText";if(!$&&!V)return;const K=y.current;if(!K)return;const Q=(ke=S.getTargetRanges)==null?void 0:ke.call(S),D=(he=window.getSelection)==null?void 0:he.call(window),F=(Q==null?void 0:Q[0])??(D!=null&&D.rangeCount?D.getRangeAt(0):null);if(!F||!K.contains(F.startContainer)||!K.contains(F.endContainer))return;const re=Od(K,e,ae=>d.getRun(ae),F);if(!re)return;S.preventDefault();let{nextRuns:H,insertionIndex:ne}=re,se=null,oe=!1;if(V&&S.data){const ae={id:E(),type:"text",value:S.data,marks:{}};H=[...H.slice(0,ne),ae,...H.slice(ne)],se=ae.id,oe=!1}else ne>0?(se=(U=H[ne-1])==null?void 0:U.id,oe=!1):H.length>0&&(se=H[0].id,oe=!0);const ge=H.length?H:[{id:E(),type:"text",value:"",marks:{}}];d.applyOperation(Me(t,ge));const Te=se??ge[0].id;oe?br(Te):ye(Te)},[d,t,e]);p.useEffect(()=>{const S=y.current;if(S)return S.addEventListener("beforeinput",B),()=>S.removeEventListener("beforeinput",B)},[B]);const L=p.useCallback(S=>{if(!k.current){if(S.key==="Enter"&&r){S.preventDefault(),r(S);return}if(S.key==="Backspace"){const N=y.current,$=N&&Fs(N,e,d.getRun.bind(d));if($){S.preventDefault(),T($);return}const V=N&&Hs(N,e,d.getRun.bind(d),!0);if(V){S.preventDefault(),T(V);return}if(N&&Md(N)){if(!Le(d,e)){const Q=Vs(d,t,"backward");if(Q){S.preventDefault(),M(Q);return}}S.preventDefault(),o&&o(S)}return}if(S.key==="Delete"){const N=y.current,$=N&&Fs(N,e,d.getRun.bind(d));if($){S.preventDefault(),T($);return}const V=N&&Hs(N,e,d.getRun.bind(d),!1);if(V){S.preventDefault(),T(V);return}if(N&&Ld(N)){const K=Vs(d,t,"forward");if(K){S.preventDefault(),M(K);return}s&&s(S)}return}if(S.key==="ArrowUp"&&a){S.preventDefault(),a(S);return}if(S.key==="ArrowDown"&&i){S.preventDefault(),i(S);return}S.key==="Tab"&&(S.shiftKey&&c?(S.preventDefault(),c(S)):!S.shiftKey&&u&&(S.preventDefault(),u(S)))}},[r,o,s,a,i,u,c,T,M,e,t,d]);return l.jsxs(l.Fragment,{children:[l.jsx("span",{ref:y,className:"be-editable",dir:n,contentEditable:!0,suppressContentEditableWarning:!0,onInput:v,onCompositionStart:I,onCompositionEnd:C,onKeyDown:L,children:e.map(S=>{const N=Ad(w.current,d,S);return Ve.createPortal(l.jsx(Nd,{id:S,blockId:t,host:N,inlineRegistry:h,onValueSynced:j},S),N)})}),l.jsx(Td,{containerRef:y,store:d}),l.jsx(jd,{containerRef:y,store:d,authorId:m})]})}function Dd(t,e,n){const r=t.getBlock(e),o=r&&t.getBlock(r.parentId);if(!o)return null;const s=o.contentIds.indexOf(e),a=n==="up"?s-1:s+1;return a<0||a>=o.contentIds.length?null:o.contentIds[a]}function xl(t,e,n){let r=e;for(;;){const o=Dd(t,r,n);if(!o)return null;const s=n==="up"?xr(t,o):Do(t,o);if(s)return s;r=o}}function _e(t,e,n){const r=xl(t,e,n);r&&ye(r)}function Do(t,e){var s;const n=t.getBlock(e);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 t.getRun(o)?o:Do(t,o)}function Re(t,e){const n=Do(t,e);n&&ye(n)}function xr(t,e){var s;const n=t.getBlock(e);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 t.getRun(o)?o:xr(t,o)}function Ys(t,e){const n=xr(t,e);n&&ye(n)}function Pd(){var i,u;const t=(i=window.getSelection)==null?void 0:i.call(window);if(!t||t.rangeCount===0)return null;const e=t.getRangeAt(0);if(e.collapsed||e.startContainer!==e.endContainer)return null;const n=e.startContainer,r=n.nodeType===1?n:n.parentElement,o=(u=r==null?void 0:r.closest)==null?void 0:u.call(r,"[data-run-id]");if(!o)return null;const s=o.closest("[data-block-id]");if(!s)return null;const a=n.textContent??"";return{runId:o.getAttribute("data-run-id"),blockId:s.getAttribute("data-block-id"),startOffset:at(a.slice(0,e.startOffset)).length,endOffset:at(a.slice(0,e.endOffset)).length}}function $d(t,e){var i,u;if((t==null?void 0:t.nodeType)!==1||((i=t.getAttribute)==null?void 0:i.call(t,"contenteditable"))!=="true")return null;const n=t.childNodes;if(n.length===0)return null;const r=e>=n.length,o=n[r?n.length-1:Math.max(0,e)],s=(o==null?void 0:o.nodeType)===1?(u=o.dataset)==null?void 0:u.runId:void 0;if(!s)return null;const a=o.closest("[data-block-id]");return a?{runId:s,blockId:a.getAttribute("data-block-id"),offset:r?at(o.textContent??"").length:0}:null}function Rn(t,e){var i;const n=$d(t,e);if(n)return n;let r=(t==null?void 0:t.nodeType)===1?t:t==null?void 0:t.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 a=at((t.textContent??"").slice(0,e)).length;if(t===o){a=0;for(let u=0;u<e&&u<o.childNodes.length;u+=1)a+=at(o.childNodes[u].textContent??"").length}return{runId:o.getAttribute("data-run-id"),blockId:s.getAttribute("data-block-id"),offset:a}}function lt(){var e;const t=(e=window.getSelection)==null?void 0:e.call(window);return!t||t.rangeCount===0||!t.isCollapsed?null:Rn(t.anchorNode,t.anchorOffset)}function ln(){var r;const t=(r=window.getSelection)==null?void 0:r.call(window);if(!t||t.rangeCount===0||t.isCollapsed)return null;const e=Rn(t.anchorNode,t.anchorOffset),n=Rn(t.focusNode,t.focusOffset);return!e||!n||e.blockId!==n.blockId?null:{blockId:e.blockId,startRunId:e.runId,startOffset:e.offset,endRunId:n.runId,endOffset:n.offset}}function rn(t){var d;const e=(d=window.getSelection)==null?void 0:d.call(window);if(!e||e.rangeCount===0||e.isCollapsed)return null;const n=Rn(e.anchorNode,e.anchorOffset),r=Rn(e.focusNode,e.focusOffset);if(!n||!r||n.blockId===r.blockId)return null;const o=t.getBlock(n.blockId),s=o&&t.getBlock(o.parentId);if(!s)return null;const a=s.contentIds,i=a.indexOf(n.blockId),u=a.indexOf(r.blockId);if(i===-1||u===-1)return null;const[c,f]=i<=u?[i,u]:[u,i];return{blockIds:a.slice(c,f+1),startBlockId:n.blockId,startRunId:n.runId,startOffset:n.offset,endBlockId:r.blockId,endRunId:r.runId,endOffset:r.offset}}function yr(t,e,n){const o=t.getBlock(e).parentId,a=t.getBlock(o).contentIds.indexOf(e)+1,{block:i,runs:u=[],subtreeBlocks:c=[]}=n(o);return t.applyOperation(me(i,o,a,{blocks:[i,...c],runs:u})),i.id}function nt(t,e,n){const r=yr(t,e,n);return Re(t,r),r}function zd(t,e,n){const{block:r,runs:o=[],subtreeBlocks:s=[]}=n(e);return t.applyOperation(me(r,e,0,{blocks:[r,...s],runs:o})),Re(t,r.id),r.id}function yl(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Hd(t,e,n){const r=t.findIndex(c=>c.id===e);if(r===-1)return null;const o=t[r],s=t.slice(0,r),a=t.slice(r+1);if(o.type==="text"){const c=o.value??"",f=c.slice(0,n),d=c.slice(n);f&&d?(s.push({...o,value:f}),a.unshift({...o,id:E(),value:d})):d?a.unshift(o):s.push(o)}else n>0?s.push(o):a.unshift(o);const i=s.length?s:[{id:E(),type:"text",value:"",marks:{}}],u=a.length?a:[{id:E(),type:"text",value:"",marks:{}}];return{leftRuns:i,rightRuns:u}}function cn(t,e,n,r){const o=t.getBlock(e),s=t.getBlock(o.parentId),a=s.contentIds.indexOf(e)+1;return vl(t,e,n,r,{insertParentId:s.id,insertIndex:a,fallback:()=>nt(t,e,r)})}function kl(t,e,n,r){return vl(t,e,n,r,{insertParentId:e,insertIndex:0,fallback:()=>zd(t,e,r)})}function vl(t,e,n,r,{insertParentId:o,insertIndex:s,fallback:a}){const i=lt();if(!i||i.blockId!==e)return a();const u=n.map(y=>t.getRun(y)).filter(Boolean),c=Hd(u,i.runId,i.offset);if(!c)return a();const{leftRuns:f,rightRuns:d}=c,{block:h,runs:m=d,subtreeBlocks:g=[]}=r(o,d),x=f.length?f:[{id:E(),type:"text",value:"",marks:{}}];return yl(t,[Me(e,x),me(h,o,s,{blocks:[h,...g],runs:m})]),Re(t,h.id),h.id}function Fd(t){var e;return((e=t==null?void 0:t.props)==null?void 0:e.titleRunIds)??(t==null?void 0:t.contentIds)??[]}function Ud(t){var e,n;return!!((e=t==null?void 0:t.props)!=null&&e.titleRunIds)&&(((n=t.contentIds)==null?void 0:n.length)??0)>0}function Vd(t,e,n){const o=t.getBlock(e).parentId,a=t.getBlock(o).contentIds.indexOf(e),{block:i,runs:u=[],subtreeBlocks:c=[]}=n(o);return yl(t,[ee(e),me(i,o,a,{blocks:[i,...c],runs:u})]),Re(t,i.id),i.id}function Be(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},s){const a=t.getRun(n),i=(a==null?void 0:a.value)??"",u=i.slice(0,r)+i.slice(o),c=t.getBlock(e),f=Fd(c);return f.length===1&&f[0]===n&&u===""&&!Ud(c)?Vd(t,e,s):(t.applyOperation(ue(n,{value:u})),nt(t,e,s))}function te(t,e={}){return function(r,o){const s=E(),a=o!=null&&o.length?o:[{id:E(),type:"text",value:"",marks:{}}];return{block:{id:s,type:t,parentId:r,contentIds:a.map(i=>i.id),props:e},runs:a}}}function un(t){const e=t.getRootId(),n=t.getBlock(e);if(!n||n.contentIds.length>0)return null;const{block:r,runs:o}=te("paragraph")(e);return t.applyOperation(me(r,e,0,{blocks:[r],runs:o})),r.id}const Yd=new Set(["callout"]),Ks=new Set(["paragraph","heading","blockquote"]);function wl(t,e){return t===e||Ks.has(t)&&Ks.has(e)}function Nn(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=n.contentIds.length===0||n.contentIds.length===1&&Kd(t,n.contentIds[0]);if(o<=0){if(!s)return null;if(r.contentIds.length>1)return Zt(t,[ee(e)]),t.getBlock(r.id).contentIds[0];if(Yd.has(r.type))return Wd(t,r);if(n.type==="paragraph")return null;const{block:c,runs:f}=te("paragraph")(r.id);return Zt(t,[me(c,r.id,o,{blocks:[c],runs:f}),ee(e)]),c.id}const a=r.contentIds[o-1],i=t.getBlock(a);if(s)return Zt(t,[ee(e)]),a;if(Mn(t,i))return Zt(t,[ee(a)]),e;if(!i||!wl(i.type,n.type))return null;const u=[...i.contentIds,...n.contentIds];return Zt(t,[nn(a,u),nn(e,[]),ee(e)]),a}function Kd(t,e){const n=t.getRun(e);return!n||(n.value??"")===""}function Wd(t,e){const n=t.getBlock(e.parentId);if(!n)return null;const r=n.contentIds.indexOf(e.id),o=r>0?n.contentIds[r-1]:null,s=r!==-1&&r<n.contentIds.length-1?n.contentIds[r+1]:null;Zt(t,[ee(e.id)]);const a=un(t);return o??s??a}function Zt(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function dn(t,e,n,r){if(!e||e===n)return;const o=xr(t,e);if(o){ye(o);return}r(e),requestAnimationFrame(()=>{var s;(s=document.querySelector(`[data-block-id="${e}"]`))==null||s.focus()})}function it(t,e){var r,o;if(!e)return"auto";if((r=e.props)!=null&&r.dir)return e.props.dir;const n=t.getBlock(t.getRootId());return((o=n==null?void 0:n.props)==null?void 0:o.dir)??"auto"}function Po(t,e,n,r,o,s){const a=t.getBlock(e),u=t.getBlock(a.parentId).contentIds.indexOf(e),c="titleRunIds"in r,f="titleRunIds"in(a.props??{}),d=s?!s.isLeaf(a.type)&&a.contentIds.length>0:!1,h=s?!s.isLeaf(n):!1,m=[];if(d&&!h&&a.contentIds.forEach((g,x)=>m.push(ct(g,a.parentId,u+1+x))),m.push(fo(e,n,r)),c)m.push(J(e,{titleRunIds:o})),!f&&!d&&m.push(nn(e,[]));else{const g=d&&h?a.contentIds:[];m.push(nn(e,[...g,...o]))}return{newBlockId:e,ops:m}}function Xd(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}const qd=[{re:/^(#{1,3})[ ]$/,type:"heading",props:t=>({level:t[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 Gd(t,e,n){if(n.length!==1||n[0].type!=="text")return!1;const r=n[0].value??"";for(const o of qd){const s=o.re.exec(r);if(!s)continue;const a=r.slice(s[0].length),{ops:i}=Po(t,e,o.type,o.props(s),[n[0].id]);return Xd(t,[ue(n[0].id,{value:a}),...i]),br(n[0].id),!0}return!1}const Jd=new Set(["callout","toggleHeading"]);function Zd({id:t}){const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=p.useCallback(()=>{const h=e.getBlock(n==null?void 0:n.parentId),m=Le(e,(n==null?void 0:n.contentIds)??[]),g=!!h&&h.contentIds[h.contentIds.length-1]===t;if(m&&g&&Jd.has(h==null?void 0:h.type)){nt(e,h.id,te("paragraph"));return}cn(e,t,(n==null?void 0:n.contentIds)??[],te("paragraph"))},[e,t,n]),s=p.useCallback(()=>{var y,k;const h=e.getBlock(n==null?void 0:n.parentId),m=Le(e,(n==null?void 0:n.contentIds)??[]),g=((y=h==null?void 0:h.contentIds)==null?void 0:y.length)===1&&h.contentIds[0]===t;if(m&&g&&(h==null?void 0:h.type)==="toggleHeading"){const w=((k=h.props)==null?void 0:k.titleRunIds)??[],v=w[w.length-1];v&&ye(v);return}const x=Nn(e,t);dn(e,x,t,r)},[e,t,n,r]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),u=p.useCallback(h=>Gd(e,t,h),[e,t]),c=Ie("be-paragraph",n);if(!n)return null;const f=Le(e,n.contentIds),d=it(e,n);return l.jsx("div",{className:c,"data-block-id":t,"data-empty":f?"":void 0,"data-placeholder":"Type '/' for commands",dir:d,children:l.jsx(pt,{blockId:t,runIds:n.contentIds,dir:d,onEnter:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i,onAutoformat:u})})}function Et(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Ee(t){return Et(t).replace(/"/g,""")}function ft(t,e){var o,s;if(!t)return"";if(t.type!=="text"){const a=(o=e==null?void 0:e.inlineRegistry)==null?void 0:o.get(t.type);return a?a.toHTML(t,e):Et(t.value??"")}const n=t.marks??{};let r=Et(t.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:${Ee(n.color)}">${r}</span>`),n.highlight&&(r=`<span style="background-color:${Ee(n.highlight)}">${r}</span>`),(s=n.link)!=null&&s.href){const a=n.link.target==="_blank"?' target="_blank" rel="noopener noreferrer"':"";r=`<a href="${Ee(n.link.href)}"${a}>${r}</a>`}return r}function Hr(t,e){return(t??[]).map(n=>ft(n,e)).join("")}function It(t,e){var n;if(!t)return"";if(t.type!=="text"){const r=(n=e==null?void 0:e.inlineRegistry)==null?void 0:n.get(t.type);return r?r.toPlainText(t,e):t.value??""}return t.value??""}const Qd={STRONG:"bold",B:"bold",EM:"italic",I:"italic",U:"underline",S:"strike",STRIKE:"strike",DEL:"strike",CODE:"code",SUB:"subscript",SUP:"superscript"};function Ye(t,e,n={}){const r=[],o=(s,a)=>{var c,f;if(s.nodeType===3){const d=s.textContent;d&&r.push({id:E(),type:"text",value:d,marks:{...a}});return}if(s.nodeType!==1)return;if(e!=null&&e.inlineRegistry)for(const d of e.inlineRegistry.listHtmlMatchers()){const h=d.fromHTML(s,e);if(h){r.push(h);return}}let i=a;const u=Qd[s.tagName];u&&(i={...i,[u]:!0}),s.tagName==="A"&&s.getAttribute("href")&&(i={...i,link:{href:s.getAttribute("href"),target:s.getAttribute("target")==="_blank"?"_blank":"_self"}}),(c=s.style)!=null&&c.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(t,n),r.length?r:[{id:E(),type:"text",value:"",marks:{}}]}function ep(t,e){return`<p>${t.contentIds.map(r=>e.store.getRun(r)).map(r=>ft(r,e)).join("")}</p>`}function tp(t,e){return t.contentIds.map(n=>It(e.store.getRun(n),e)).join("")}function np(t,e){if(t.tagName!=="P")return null;const n=Ye(t,e);return{block:{id:E(),type:"paragraph",parentId:null,contentIds:n.map(o=>o.id),props:{}},runs:n}}const Il={component:Zd,isLeaf:!0,defaultProps:{},toHTML:ep,toPlainText:tp,fromHTML:np,slashCommand:{label:"Text",icon:Eo,keywords:["paragraph","text","p"],run:(t,e)=>Be(t,e,te("paragraph"))}};function rp({id:t}){var m;const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=p.useCallback(()=>{cn(e,t,(n==null?void 0:n.contentIds)??[],te("paragraph"))},[e,t,n]),s=p.useCallback(()=>{const g=Nn(e,t);dn(e,g,t,r)},[e,t,r]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),u=((m=n==null?void 0:n.props)==null?void 0:m.level)??3,c=Ie(`be-heading be-heading-${u}`,n);if(!n)return null;const f=`h${u}`,d=Le(e,n.contentIds),h=it(e,n);return l.jsx(f,{className:c,"data-block-id":t,"data-empty":d?"":void 0,"data-placeholder":`Heading ${u}`,dir:h,children:l.jsx(pt,{blockId:t,runIds:n.contentIds,dir:h,onEnter:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i})})}const Fr={1:Za,2:Qa,3:el},op={H1:1,H2:2,H3:3};function sp(t,e){var o;const n=((o=t.props)==null?void 0:o.level)??3,r=t.contentIds.map(s=>e.store.getRun(s));return`<h${n}>${r.map(s=>ft(s,e)).join("")}</h${n}>`}function ap(t,e){return t.contentIds.map(n=>It(e.store.getRun(n),e)).join("")}function lp(t,e){const n=op[t.tagName];if(!n)return null;const r=Ye(t,e);return{block:{id:E(),type:"heading",parentId:null,contentIds:r.map(s=>s.id),props:{level:n}},runs:r}}const Cl={component:rp,isLeaf:!0,defaultProps:{level:3},toHTML:sp,toPlainText:ap,fromHTML:lp,slashCommands:[{label:"Heading 1",icon:Fr[1],keywords:["heading","h1","title"],run:(t,e)=>Be(t,e,te("heading",{level:1}))},{label:"Heading 2",icon:Fr[2],keywords:["heading","h2","subtitle"],run:(t,e)=>Be(t,e,te("heading",{level:2}))},{label:"Heading 3",icon:Fr[3],keywords:["heading","h3","title"],run:(t,e)=>Be(t,e,te("heading",{level:3}))}]},ip=[];function $o(t){const e=G(),n=p.useCallback(o=>e.subscribe(t,o),[e,t]),r=p.useCallback(()=>{const o=e.getBlock(t);return o?o.contentIds:ip},[e,t]);return p.useSyncExternalStore(n,r)}class Sl extends p.Component{constructor(){super(...arguments);_s(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(a=>({hasError:!1,nonce:a.nonce+1})))}render(){return this.state.hasError?null:l.jsx(p.Fragment,{children:this.props.children},this.state.nonce)}}const zo=p.memo(function({id:e}){const n=be(e),r=vt();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: ${e})`),null;const s=o.component;return l.jsx(Sl,{children:l.jsx(s,{id:e})})});function Ue(t,e,n){p.useEffect(()=>{if(!e)return;const r=Array.isArray(t)?t:[t],o=a=>{r.some(u=>u.current&&u.current.contains(a.target))||n()},s=a=>{a.key==="Escape"&&n()};return document.addEventListener("mousedown",o),document.addEventListener("keydown",s),()=>{document.removeEventListener("mousedown",o),document.removeEventListener("keydown",s)}},[e,n,t])}function kr(t,e,n,r){const o=p.useRef(!1),s=p.useRef(!1);p.useEffect(()=>{var f,d;if(!e){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 a=t.current;if(!a)return;const i=()=>Array.from(a.querySelectorAll('[role="menuitem"]')),u=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,u(0));const c=h=>{if(h.key==="Escape"){h.preventDefault(),n();return}const m=i(),g=m.indexOf(document.activeElement);g!==-1&&(h.key==="ArrowDown"?(h.preventDefault(),u(g+1)):h.key==="ArrowUp"?(h.preventDefault(),u(g-1)):h.key==="Home"?(h.preventDefault(),u(0)):h.key==="End"&&(h.preventDefault(),u(m.length-1)))};return a.addEventListener("keydown",c),()=>a.removeEventListener("keydown",c)})}const Ws="be-live-region";function cp(){if(typeof document>"u")return null;let t=document.getElementById(Ws);return t||(t=document.createElement("div"),t.id=Ws,t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),Object.assign(t.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(t),t)}function xe(t){const e=cp();e&&(e.textContent="",setTimeout(()=>{e.textContent=t},0))}const pn="💡",Rl="gray";function up({icon:t=pn,color:e=Rl}={}){return function(r){const o=E(),{block:s,runs:a}=te("paragraph")(o);return{block:{id:o,type:"callout",parentId:r,contentIds:[s.id],props:{icon:t,color:e}},runs:a,subtreeBlocks:[s]}}}const Tl=[{type:"paragraph",props:{},label:"Text",icon:Eo},{type:"heading",props:{level:1},label:"Heading 1",icon:Za},{type:"heading",props:{level:2},label:"Heading 2",icon:Qa},{type:"heading",props:{level:3},label:"Heading 3",icon:el},{type:"listItem",props:{ordered:!1,titleRunIds:[]},label:"Bulleted list",icon:rl},{type:"listItem",props:{ordered:!0,titleRunIds:[]},label:"Numbered list",icon:ol},{type:"listItem",props:{ordered:!1,checked:!1,titleRunIds:[]},label:"To-do list",icon:Oo},{type:"listItem",props:{ordered:!1,collapsed:!1,titleRunIds:[]},label:"Toggle list",icon:jt},{type:"toggleHeading",props:{level:2,collapsed:!1,titleRunIds:[]},label:"Toggle heading",icon:jt},{type:"blockquote",props:{},label:"Quote",icon:tl},{type:"callout",props:{icon:pn},label:"Callout",icon:nl},{type:"code",props:{language:"plaintext"},label:"Code",icon:_o}],dp=new Set(Tl.map(t=>t.type));function Ho(t){return dp.has(t)}function pp(t,e){return t!=null&&t.props&&"titleRunIds"in t.props?t.props.titleRunIds:e&&!e.isLeaf(t==null?void 0:t.type)?[]:(t==null?void 0:t.contentIds)??[]}function jl(t,e,n,r){const o=t.getBlock(n),s=pp(o,e),a=[];if(r.type==="code")for(const f of s){const d=t.getRun(f);d!=null&&d.marks&&Object.keys(d.marks).length>0&&a.push(ue(f,{marks:{}}))}const i={...r.props},{ops:u,newBlockId:c}=Po(t,n,r.type,i,s,e);return{ops:[...a,...u],newBlockId:c}}function El({onSelect:t,onClose:e,containerRef:n,menuClassName:r="be-block-gutter-menu",itemClassName:o="be-block-gutter-menu-item"}){const[s,a]=p.useState(!1),[i,u]=p.useState(null),c=p.useRef(null),f=p.useRef(null),d=p.useCallback(w=>{f.current=w,n&&(n.current=w)},[n]),h=p.useCallback(()=>{a(!1),e==null||e()},[e]);Ue([c,f],s,h),kr(f,s,h,c);const m=Ln(f,s,i==null?void 0:i.top,i?i.right+4:null),g=p.useCallback(()=>{var w;u(((w=c.current)==null?void 0:w.getBoundingClientRect())??null),a(!0)},[]),x=p.useCallback(w=>{t(w),h()},[t,h]),y=p.useCallback(w=>{w.key==="ArrowRight"&&!s&&(w.preventDefault(),g())},[s,g]),k=p.useCallback(w=>{w.key==="ArrowLeft"&&(w.preventDefault(),h())},[h]);return l.jsxs(l.Fragment,{children:[l.jsxs("button",{ref:c,type:"button",role:"menuitem",className:o,"aria-haspopup":"menu","aria-expanded":s,onClick:()=>s?h():g(),onKeyDown:y,children:[l.jsx(jt,{size:15})," Turn into"]}),s&&m&&Ve.createPortal(l.jsx("div",{ref:d,role:"menu","aria-label":"Turn into",className:r,style:{position:"fixed",top:m.top,left:m.left},onKeyDown:k,children:Tl.map((w,v)=>{const j=w.icon;return l.jsxs("button",{type:"button",role:"menuitem",className:o,onClick:()=>x(w),children:[l.jsx(j,{size:15})," ",w.label]},`${w.type}-${v}`)})}),document.body)]})}function Fo(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=Bn(t,e),{block:a,runs:i,subtreeBlocks:u}=dr(s);return t.applyOperation(me(a,r.id,o+1,{blocks:[a,...u],runs:i})),Re(t,a.id),a.id}function Uo(t,e){const n=t.getBlock(e),r=n&&t.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(e);return o<=0?!1:(t.applyOperation(ct(e,r.id,o-1)),!0)}function Vo(t,e){const n=t.getBlock(e),r=n&&t.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(e);return o===-1||o>=r.contentIds.length-1?!1:(t.applyOperation(ct(e,r.id,o+1)),!0)}function vr(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=o>0?r.contentIds[o-1]:null,a=o!==-1&&o<r.contentIds.length-1?r.contentIds[o+1]:null;t.applyOperation(ee(e));const i=un(t),u=s??a??i;return u&&Re(t,u),u??null}function fp(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Bl({id:t}){var S;const e=G(),n=vt(),r=be(t),[o,s]=p.useState(!1),[a,i]=p.useState(null),u=p.useRef(null),c=p.useRef(null),f=p.useRef(null),d=p.useMemo(()=>[u,c,f],[]),[h]=_n(),m=h.includes(t),g=p.useCallback(()=>s(!1),[]);Ue(d,o,g),kr(c,o,g,u);const x=p.useCallback(()=>{var N;i(((N=u.current)==null?void 0:N.getBoundingClientRect())??null),s(!0)},[]),y=Ln(c,o,(a==null?void 0:a.bottom)!=null?a.bottom+4:null,a==null?void 0:a.left),k=p.useCallback(()=>{nt(e,t,te("paragraph"))},[e,t]),w=p.useCallback(()=>{Fo(e,t),xe("Block duplicated"),g()},[e,t,g]),v=p.useCallback(()=>{Uo(e,t)&&xe("Block moved up"),g()},[e,t,g]),j=p.useCallback(()=>{Vo(e,t)&&xe("Block moved down"),g()},[e,t,g]),I=p.useCallback(()=>{vr(e,t),xe("Block deleted"),g()},[e,t,g]),C=!!((S=r==null?void 0:r.props)!=null&&S.hidden),T=p.useCallback(()=>{e.applyOperation(J(t,{hidden:!C})),xe(C?"Block shown in preview":"Block hidden in preview"),g()},[e,t,C,g]),M=it(e,r)==="rtl",B=p.useCallback(()=>{e.applyOperation(J(t,{dir:M?"ltr":"rtl"})),xe(M?"Block set to left-to-right":"Block set to right-to-left"),g()},[e,t,M,g]),L=p.useCallback(N=>{const{ops:$}=jl(e,n,t,N);fp(e,$),xe(`Turned into ${N.label}`),g()},[e,n,t,g]);return r?l.jsxs("div",{className:`be-block-row${C?" be-block-row-hidden":""}${m?" be-block-row-range-selected":""}`,"data-block-row-id":t,dir:it(e,r),children:[l.jsxs("div",{className:`be-block-gutter${o?" be-block-gutter-active":""}`,contentEditable:!1,children:[l.jsx("button",{type:"button",className:"be-block-gutter-btn",onClick:k,"aria-label":"Add block below",children:l.jsx(To,{size:16})}),l.jsx("button",{ref:u,type:"button",className:"be-block-gutter-btn","aria-label":"More options","aria-haspopup":"menu","aria-expanded":o,onClick:()=>o?g():x(),children:l.jsx(rd,{size:16})})]}),l.jsx("div",{className:"be-block-row-content",children:l.jsx(zo,{id:t})}),o&&y&&Ve.createPortal(l.jsxs("div",{ref:c,role:"menu","aria-label":"Block options",className:"be-block-gutter-menu",style:{position:"fixed",top:y.top,left:y.left},children:[l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:w,children:[l.jsx(jo,{size:15})," Duplicate"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:v,children:[l.jsx(hr,{size:15})," Move up"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:j,children:[l.jsx(mr,{size:15})," Move down"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:T,children:[C?l.jsx(Mo,{size:15}):l.jsx(Lo,{size:15}),C?"Show in preview":"Hide in preview"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:B,children:[M?l.jsx(Xa,{size:15}):l.jsx(qa,{size:15}),M?"Switch to left-to-right":"Switch to right-to-left"]}),Ho(r.type)&&l.jsx(El,{onSelect:L,onClose:()=>{},containerRef:f}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item be-block-gutter-menu-item-danger",onClick:I,children:[l.jsx(On,{size:15})," Delete"]})]}),document.body)]}):null}function ht({parentId:t,isTopLevel:e=!1}){const n=$o(t),r=G(),[o]=Co(),s=o?n.filter(a=>{var i,u;return!((u=(i=r.getBlock(a))==null?void 0:i.props)!=null&&u.hidden)}):n;return e&&!o?s.map(a=>l.jsx(Bl,{id:a},a)):s.map(a=>l.jsx(zo,{id:a},a))}const hp=97,mp=[[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 bp(t){let e="";for(;t>0;)t-=1,e=String.fromCharCode(hp+t%26)+e,t=Math.floor(t/26);return e}function gp(t){let e="",n=t;for(const[r,o]of mp)for(;n>=r;)e+=o,n-=r;return e}function xp(t){var e,n;return(t==null?void 0:t.type)==="listItem"&&((e=t.props)==null?void 0:e.checked)===void 0&&((n=t.props)==null?void 0:n.collapsed)===void 0}function Xs(t,e){let n=0,r=e;for(;r;){const o=t.getBlock(r.parentId);if(!o||o.type!=="listItem")break;n+=1,r=o}return n}function yp(t,e,n){const r=n.indexOf(e.id);let o=1;for(let s=r-1;s>=0;s-=1){const a=t.getBlock(n[s]);if(!xp(a)||!a.props.ordered)break;o+=1}return o}function kp(t,e){const n=(t%3+3)%3;return n===0?`${e}.`:n===1?`${bp(e)}.`:`${gp(e)}.`}const vp=["•","◦","▪"];function wp(t){const e=(t%3+3)%3;return vp[e]}function vn({ordered:t=!1,checked:e,collapsed:n}={}){return function(o,s){const a=E(),i=s!=null&&s.length?s:[{id:E(),type:"text",value:"",marks:{}}],u={ordered:t,titleRunIds:i.map(h=>h.id)};e!==void 0&&(u.checked=e);let c=[],f=[],d=i;if(n!==void 0){u.collapsed=n;const{block:h,runs:m}=te("paragraph")(a);c=[h.id],f=[h],d=[...i,...m]}return{block:{id:a,type:"listItem",parentId:o,contentIds:c,props:u},runs:d,subtreeBlocks:f}}}function Ip(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=o>0?r.contentIds[o-1]:null,a=s?t.getBlock(s):null;if(!a||a.type!=="listItem"){_e(t,e,"down");return}t.applyOperation(ct(e,s,a.contentIds.length)),Re(t,e)}function no(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId);if(!r||r.type!=="listItem")return;const o=r.parentId,a=t.getBlock(o).contentIds.indexOf(r.id);t.applyOperation(ct(e,o,a+1)),Re(t,e)}function mn(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function _l(t,e){var n;return e.length===0||e.length===1&&(((n=t.getRun(e[0]))==null?void 0:n.value)??"")===""}function Cp(t,e){const n=e.contentIds??[];if(n.length===0)return!0;if(n.length>1)return!1;const r=t.getBlock(n[0]);return!!r&&r.type==="paragraph"&&Le(t,r.contentIds)}function Sp(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=n.props.titleRunIds??[],i=_l(t,s)&&Cp(t,n);if(o>0){const f=r.contentIds[o-1],d=t.getBlock(f);if(i)return mn(t,[ee(e)]),{focusBlockId:f,needsRefocus:!0};if(Mn(t,d))return mn(t,[ee(f)]),{focusBlockId:e,needsRefocus:!1};if((d==null?void 0:d.type)==="listItem"&&n.contentIds.length===0){const h=[...d.props.titleRunIds??[],...s];return mn(t,[J(f,{titleRunIds:h}),J(e,{titleRunIds:[]}),ee(e)]),{focusBlockId:f,needsRefocus:!0}}return null}if(r.type==="listItem")return no(t,e),{focusBlockId:e,needsRefocus:!0};if(!i)return null;if(r.contentIds.length>1)return mn(t,[ee(e)]),{focusBlockId:t.getBlock(r.id).contentIds[0],needsRefocus:!0};const{block:u,runs:c}=te("paragraph")(r.id);return mn(t,[me(u,r.id,o,{blocks:[u],runs:c}),ee(e)]),{focusBlockId:u.id,needsRefocus:!0}}function Rp(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Tp(t,e){const r=t.getBlock(e).parentId,s=t.getBlock(r).contentIds.indexOf(e),{block:a,runs:i}=te("paragraph")(r);return Rp(t,[me(a,r,s,{blocks:[a],runs:i}),J(e,{titleRunIds:[]}),ee(e)]),Re(t,a.id),a.id}function jp(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Ep({id:t}){var T,M;const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=$o(n==null?void 0:n.parentId),s=p.useCallback(()=>{var Q,D,F,re,H;const B=((Q=n==null?void 0:n.props)==null?void 0:Q.titleRunIds)??[],L=e.getBlock(n==null?void 0:n.parentId),S=_l(e,B);if(S&&(L==null?void 0:L.type)==="listItem"){no(e,t);return}const N=(((D=n==null?void 0:n.contentIds)==null?void 0:D.length)??0)>0;if(S&&(L==null?void 0:L.type)!=="listItem"&&!N){Tp(e,t);return}const $=((F=n==null?void 0:n.props)==null?void 0:F.checked)!==void 0,V=((re=n==null?void 0:n.props)==null?void 0:re.collapsed)!==void 0,K=vn({ordered:(H=n==null?void 0:n.props)==null?void 0:H.ordered,checked:$?!1:void 0,collapsed:V?!1:void 0});N&&!V?kl(e,t,B,K):cn(e,t,B,K)},[e,t,n]),a=p.useCallback(()=>Ip(e,t),[e,t]),i=p.useCallback(()=>no(e,t),[e,t]),u=p.useCallback(()=>{const B=Sp(e,t);!B||!B.needsRefocus||dn(e,B.focusBlockId,t,r)},[e,t,r]),c=p.useCallback(()=>_e(e,t,"up"),[e,t]),f=p.useCallback(()=>_e(e,t,"down"),[e,t]),d=p.useCallback(()=>{var B;e.applyOperation(J(t,{checked:!((B=n==null?void 0:n.props)!=null&&B.checked)}))},[e,t,(T=n==null?void 0:n.props)==null?void 0:T.checked]),h=p.useCallback(()=>{var L,S;if(!((((L=n==null?void 0:n.contentIds)==null?void 0:L.length)??0)>0)){const{block:N,runs:$}=te("paragraph")(t);jp(e,[me(N,t,0,{blocks:[N],runs:$}),J(t,{collapsed:!1})]),ye(N.contentIds[0]);return}e.applyOperation(J(t,{collapsed:!((S=n==null?void 0:n.props)!=null&&S.collapsed)}))},[e,t,n==null?void 0:n.contentIds,(M=n==null?void 0:n.props)==null?void 0:M.collapsed]),m=Ie("be-list-item",n);if(!n)return null;const{ordered:g,checked:x,collapsed:y,titleRunIds:k=[]}=n.props,w=x!==void 0,v=!w&&y!==void 0,j=n.contentIds.length>0,I=k.map(B=>e.getRun(B)).filter(B=>(B==null?void 0:B.type)==="text").map(B=>B.value).join("").trim(),C=it(e,n);return l.jsxs("div",{className:m,"data-block-id":t,dir:C,children:[l.jsxs("div",{className:"be-list-item-row",children:[w?l.jsx("input",{type:"checkbox",className:"be-list-checkbox",checked:!!x,onChange:d,"aria-label":I||"To-do item"}):v?l.jsx("button",{type:"button",className:"be-list-toggle-marker",onClick:h,"aria-expanded":!y,"aria-label":j?y?"Expand toggle":"Collapse toggle":"Add content to toggle",children:y?l.jsx(jt,{}):l.jsx(fr,{})}):l.jsx("span",{className:"be-list-marker","aria-hidden":"true",children:g?kp(Xs(e,n),yp(e,n,o)):wp(Xs(e,n))}),l.jsx("div",{className:"be-list-item-title","data-empty":Le(e,k)?"":void 0,"data-placeholder":w?"To-do":v?"Toggle":"List item",style:x?{textDecoration:"line-through",opacity:.6}:void 0,children:l.jsx(pt,{blockId:t,runIds:k,dir:C,onEnter:s,onTab:a,onShiftTab:i,onBackspaceAtStart:u,onArrowUp:c,onArrowDown:f})})]}),(!v||!y)&&l.jsx("div",{className:"be-list-item-children",children:l.jsx(ht,{parentId:t})})]})}function Bp(t,e){const{titleRunIds:n=[],ordered:r}=t.props,o=n.map(i=>ft(e.store.getRun(i),e)).join(""),s=t.contentIds.map(i=>e.registry.get(e.store.getBlock(i).type).toHTML(e.store.getBlock(i),e)).join(""),a=s?`<${r?"ol":"ul"}>${s}</${r?"ol":"ul"}>`:"";return`<li>${o}${a}</li>`}function _p(t,e){const{titleRunIds:n=[]}=t.props;return n.map(r=>It(e.store.getRun(r),e)).join("")}function Ol(t,e){const n=[],r=[];for(const d of t.childNodes)d.nodeType===1&&(d.tagName==="UL"||d.tagName==="OL")?r.push(d):n.push(d);const o=t.ownerDocument.createElement("span");for(const d of n)o.appendChild(d.cloneNode(!0));const s=Ye(o,e),a=E(),i=[...s],u=[],c=[];for(const d of r){const h=d.tagName==="OL";for(const m of d.children){if(m.tagName!=="LI")continue;const g=Ol(m,e);g.block.parentId=a,g.block.props.ordered=h,u.push(g.block,...g.childBlocks),i.push(...g.runs),c.push(g.block.id)}}return{block:{id:a,type:"listItem",parentId:null,contentIds:c,props:{ordered:!1,titleRunIds:s.map(d=>d.id)}},runs:i,childBlocks:u}}function Op(t,e){if(t.tagName!=="LI")return null;const{block:n,runs:r,childBlocks:o}=Ol(t,e);return{block:n,runs:r,subtreeBlocks:o}}const Ml={component:Ep,isLeaf:!1,defaultProps:{ordered:!1,titleRunIds:[]},toHTML:Bp,toPlainText:_p,fromHTML:Op,slashCommands:[{label:"Bulleted list",icon:rl,keywords:["list","bullet","ul"],run:(t,e)=>Be(t,e,vn({ordered:!1}))},{label:"Numbered list",icon:ol,keywords:["list","number","ordered","ol"],run:(t,e)=>Be(t,e,vn({ordered:!0}))},{label:"To-do list",icon:Oo,keywords:["todo","checkbox","task","checklist"],run:(t,e)=>Be(t,e,vn({ordered:!1,checked:!1}))},{label:"Toggle list",icon:jt,keywords:["toggle","collapse","expand","dropdown","accordion"],run:(t,e)=>Be(t,e,vn({ordered:!1,collapsed:!1}))}]},Ll=["text","date","checkbox","select"],wr="text",Ir=160,or=80;function Mp(t){return`Column ${t+1}`}function Yo(t){return Array.from({length:t},(e,n)=>({id:E(),label:Mp(n),type:wr,width:Ir}))}function $e(t,e){var r;const n=(r=t.props)==null?void 0:r.columns;return!Array.isArray(n)||n.length!==e?Yo(e):n.map(o=>{const s=o.type??wr,a=o.width??Ir;return s===o.type&&a===o.width?o:{...o,type:s,width:a}})}function Nl(t){switch(t){case"date":return{id:E(),type:"date",value:"",marks:{},data:{isoDate:""}};case"checkbox":return{id:E(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}};case"select":return{id:E(),type:"tableSelect",value:"",marks:{},data:{selectedValue:"",selectedLabel:""}};default:return{id:E(),type:"text",value:"",marks:{}}}}function Cr(t,e){const n=Nl(e==null?void 0:e.type);return{block:{id:E(),type:"tableCell",parentId:t,contentIds:[n.id],props:{}},run:n}}function Al(t,e,n){if(t.type===e)return t;let r;if(t.type==="text")r=t.value??"";else{const o=n==null?void 0:n.get(t.type);r=o!=null&&o.toPlainText?o.toPlainText(t):""}if(e==="date"){const o=r?new Date(r):null,s=o&&!Number.isNaN(o.getTime())?o.toISOString().slice(0,10):"";return{id:E(),type:"date",value:"",marks:{},data:{isoDate:s}}}return e==="checkbox"?{id:E(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:r}}:{id:E(),type:"text",value:r,marks:{}}}function Bt(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Dl(t,e){const r=t.getBlock(e.parentId).contentIds.indexOf(e.id);Bt(t,[ee(e.id)]);const o=un(t);if(o)return Re(t,o),null;const s=t.getBlock(e.parentId),a=s.contentIds[r]??s.contentIds[r-1];return a&&Re(t,a),null}function Ko(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=$e(r,n.contentIds.length),a=E(),i=[],u=[],c=[];for(const d of s){const h=Cr(a,d);i.push(h.block),u.push(h.run),c.push(h.block.id)}const f={id:a,type:"tableRow",parentId:r.id,contentIds:c,props:{}};return t.applyOperation(me(f,r.id,o+1,{blocks:[f,...i],runs:u})),Re(t,a),a}function Pl(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId);if(r.contentIds.length<=1)return Dl(t,r);const o=r.contentIds.indexOf(e);Bt(t,[ee(e)]);const s=t.getBlock(r.id),a=Math.min(o,s.contentIds.length-1),i=s.contentIds[a];return i&&Re(t,i),i??null}function sr(t,e,n){const r=t.getBlock(e),o=$e(r,r.contentIds[0]?t.getBlock(r.contentIds[0]).contentIds.length:0),s={id:E(),label:"New Column",type:wr,width:Ir},a=[];let i=null;for(const c of r.contentIds){const f=Cr(c,s);i===null&&(i=f.block.id),a.push(me(f.block,c,n+1,{blocks:[f.block],runs:[f.run]}))}const u=[...o];return u.splice(n+1,0,s),a.push(J(e,{columns:u})),Bt(t,a),i&&Re(t,i),i}function $l(t,e,n){const r=t.getBlock(e),o=t.getBlock(r.contentIds[0]);if(!o||o.contentIds.length<=1)return Dl(t,r);const s=$e(r,o.contentIds.length),a=r.contentIds.map(d=>{const h=t.getBlock(d);return ee(h.contentIds[n])}),i=s.filter((d,h)=>h!==n);a.push(J(e,{columns:i})),Bt(t,a);const u=t.getBlock(r.contentIds[0]),c=Math.min(n,u.contentIds.length-1),f=u.contentIds[c];return f&&Re(t,f),f??null}function zl(t,e,n,r){const o=t.getBlock(e),s=t.getBlock(o.contentIds[0]),a=$e(o,s?s.contentIds.length:0);if(!a[n])return;const i=[...a];i[n]={...a[n],width:Math.max(or,Math.round(r))},t.applyOperation(J(e,{columns:i}))}function Hl(t,e,n,r){const o=t.getBlock(e),s=t.getBlock(o.contentIds[0]),i=[...$e(o,s?s.contentIds.length:0)];i[n]&&(i[n]={...i[n],label:r},t.applyOperation(J(e,{columns:i})))}function Wo(t,e,n){return e.contentIds.map(r=>{const s=t.getBlock(r).contentIds[n],a=t.getBlock(s);return{cellId:s,run:t.getRun(a.contentIds[0])}})}function qs(t,e){if(!t)return"";if(t.type==="text")return t.value??"";const n=e==null?void 0:e.get(t.type);return n!=null&&n.toPlainText?n.toPlainText(t):""}function Lp(t,e,n,r){const o=Wo(t,e,n),s=[],a=new Map;for(const{run:u}of o){const c=qs(u,r).trim();if(!c||a.has(c))continue;const f={value:E(),label:c};a.set(c,f),s.push(f)}const i=o.map(({cellId:u,run:c})=>{const f=qs(c,r).trim(),d=a.get(f);return{cellId:u,run:{id:E(),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 Fl(t,e,n,r,o){const s=t.getBlock(e),a=t.getBlock(s.contentIds[0]),i=$e(s,a?a.contentIds.length:0),u=i[n];if(!u||u.type===r)return;const c=[...i];if(r==="select"){const{options:d,newRuns:h}=Lp(t,s,n,o);c[n]={...u,type:r,options:d};const m=[J(e,{columns:c})];for(const{cellId:g,run:x}of h)m.push(Me(g,[x]));Bt(t,m);return}c[n]={...u,type:r};const f=[J(e,{columns:c})];for(const{cellId:d,run:h}of Wo(t,s,n)){if(!h)continue;const m=Al(h,r,o);f.push(Me(d,[m]))}Bt(t,f)}function Zn(t,e,n,r){var d,h;const o=t.getBlock(e),s=t.getBlock(o.contentIds[0]),a=$e(o,s?s.contentIds.length:0),i=a[n];if(!i)return;const u=[...a];u[n]={...i,options:r};const c=[J(e,{columns:u})],f=new Map(r.map(m=>[m.value,m]));for(const{run:m}of Wo(t,o,n)){if(!m||m.type!=="tableSelect")continue;const g=((d=m.data)==null?void 0:d.selectedValue)??"",x=f.get(g),y=x?g:"",k=x?x.label:"";(y!==g||k!==(((h=m.data)==null?void 0:h.selectedLabel)??""))&&c.push(ue(m.id,{data:{selectedValue:y,selectedLabel:k}}))}Bt(t,c)}function Ul(t,e,n){const[r,o]=p.useState(null);return p.useLayoutEffect(()=>{o(n??null)},[n]),p.useLayoutEffect(()=>{if(!e||!t.current||r==null)return;const s=t.current.getBoundingClientRect(),a=gr(r,s.width);a!==r&&o(a)},[e,t,r]),r}function Vl(t,e,n){const[r,o]=p.useState(null);return p.useLayoutEffect(()=>{o(n??null)},[n]),p.useLayoutEffect(()=>{if(!e||!t.current||r==null)return;const s=t.current.getBoundingClientRect(),a=s.width/2,u=gr(r-a,s.width)+a;u!==r&&o(u)},[e,t,r]),r}function Np(t,e,n){const[r,o]=p.useState(null);return p.useLayoutEffect(()=>{o(n??null)},[n]),p.useLayoutEffect(()=>{if(!e||!t.current||r==null)return;const s=t.current.getBoundingClientRect(),i=gr(r-s.width,s.width)+s.width;i!==r&&o(i)},[e,t,r]),r}function Gs(){if(typeof window>"u"||!window.visualViewport)return 0;const t=window.visualViewport,e=window.innerHeight-(t.height+t.offsetTop);return e>0?Math.round(e):0}function Sr(){const[t,e]=p.useState(Gs);return p.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const n=window.visualViewport,r=()=>e(Gs());return r(),n.addEventListener("resize",r),n.addEventListener("scroll",r),()=>{n.removeEventListener("resize",r),n.removeEventListener("scroll",r)}},[]),t}const Ap=280;function Dp(t,e){return e?t.label.toLowerCase().includes(e.toLowerCase()):!0}function Mt({value:t,options:e,onChange:n,placeholder:r="Select…",ariaLabel:o,className:s="",variant:a="default",selectedLabel:i,selectedColor:u,onManageOptions:c,manageOptionsLabel:f="Manage options…",mention:d=!1}){var ke,he;const[h,m]=p.useState(!1),[g,x]=p.useState(""),[y,k]=p.useState(0),[w,v]=p.useState(null),j=Sr(),[I,C]=p.useState([]),[T,M]=p.useState(!1),[B,L]=p.useState(!1),S=p.useRef(null),N=p.useRef(null),$=p.useRef(null),V=p.useRef(null),K=p.useRef(null),Q=p.useMemo(()=>[S,$],[]),D=a==="tag",F=typeof e=="function",re=F?void 0:e.find(U=>U.value===t),H=t?re??(i?{label:i,color:u}:void 0):void 0,ne=p.useMemo(()=>F?I:e.filter(U=>Dp(U,g)),[F,I,e,g]);p.useEffect(()=>{if(!F||!h)return;let U=!1;M(!0),L(!1);const ae=setTimeout(()=>{Promise.resolve(e(g)).then(Ke=>{U||(C(Ke??[]),M(!1))}).catch(()=>{U||(C([]),M(!1),L(!0))})},250);return()=>{U=!0,clearTimeout(ae)}},[F,h,e,g]);const se=p.useCallback(()=>m(!1),[]);Ue(Q,h,se);const oe=Ul($,h,w==null?void 0:w.left),ge=p.useCallback(()=>{var U;v(((U=N.current)==null?void 0:U.getBoundingClientRect())??null),x(""),k(0),m(!0)},[]);p.useEffect(()=>{var U;h&&((U=V.current)==null||U.focus())},[h]),p.useEffect(()=>{var U,ae;(ae=(U=K.current)==null?void 0:U.scrollIntoView)==null||ae.call(U,{block:"nearest"})},[y]);const Te=p.useCallback(U=>{var ae;n(U.value,U),se(),(ae=N.current)==null||ae.focus()},[n,se]),ce=p.useCallback(U=>{var ae;U.key==="ArrowDown"?(U.preventDefault(),k(Ke=>Math.min(Ke+1,Math.max(ne.length-1,0)))):U.key==="ArrowUp"?(U.preventDefault(),k(Ke=>Math.max(Ke-1,0))):U.key==="Enter"?(U.preventDefault(),ne[y]&&Te(ne[y])):U.key==="Escape"&&(U.preventDefault(),se(),(ae=N.current)==null||ae.focus())},[ne,y,Te,se]);return l.jsxs("span",{className:`be-select ${s}`.trim(),ref:S,children:[l.jsx("button",{type:"button",ref:N,className:`be-select-trigger${D?" be-select-trigger-tag":""}${d?" be-select-trigger-mention":""}`,"aria-haspopup":"listbox","aria-expanded":h,"aria-label":o,onClick:()=>h?se():ge(),children:D?H?l.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:(he=H.color)==null?void 0:he.text},children:d?`@${H.label}`:H.label}):l.jsx("span",{className:"be-select-value be-select-value-placeholder",children:r}):l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"be-select-value",children:H?H.label:r}),l.jsx(fr,{size:14,className:"be-select-chevron"})]})}),h&&w&&oe!=null&&Ve.createPortal(l.jsxs("div",{ref:$,className:"be-select-popover",style:{position:"fixed",left:oe,minWidth:w.width,...w.bottom+Ap>window.innerHeight-j?{bottom:window.innerHeight-w.top+4}:{top:w.bottom+4}},children:[l.jsx("input",{ref:V,type:"text",className:"be-select-search",value:g,onChange:U=>{x(U.target.value),k(0)},onKeyDown:ce,placeholder:"Search…","aria-label":o?`Search ${o}`:"Search options"}),l.jsxs("div",{className:"be-select-options",role:"listbox",children:[F&&T&&l.jsx("div",{className:"be-select-empty",children:"Loading…"}),F&&!T&&B&&l.jsx("div",{className:"be-select-empty be-select-error",children:"Couldn't load options"}),!T&&!B&&ne.length===0&&l.jsx("div",{className:"be-select-empty",children:"No results"}),!T&&!B&&ne.map((U,ae)=>{var Ke,An;return l.jsx("div",{ref:ae===y?K:void 0,role:"option","aria-selected":U.value===t,className:`be-select-option${ae===y?" be-select-option-active":""}${U.value===t?" be-select-option-selected":""}`,onMouseDown:jr=>{jr.preventDefault(),Te(U)},onMouseEnter:()=>k(ae),children:D?l.jsx("span",{className:"be-select-tag",style:{background:(Ke=U.color)==null?void 0:Ke.bg,color:(An=U.color)==null?void 0:An.text},children:U.label}):U.label},U.value)})]}),c&&l.jsx("button",{type:"button",className:"be-select-manage-options",onMouseDown:U=>{U.preventDefault(),se(),c()},children:f})]}),document.body)]})}const Vn=[{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 Tn(t){return Vn[(t%Vn.length+Vn.length)%Vn.length]}const Pp={text:"Text",date:"Date",checkbox:"Checkbox",select:"Select"},$p=Ll.map(t=>({value:t,label:Pp[t]})),zp=800;function Hp({tableId:t,colIndex:e,options:n}){const r=G(),[o,s]=p.useState(""),a=p.useCallback((c,f)=>{Zn(r,t,e,n.map(d=>d.value===c?{...d,label:f}:d))},[r,t,e,n]),i=p.useCallback(c=>Zn(r,t,e,n.filter(f=>f.value!==c)),[r,t,e,n]),u=p.useCallback(()=>{const c=o.trim();s(""),c&&Zn(r,t,e,[...n,{value:E(),label:c,color:Tn(n.length)}])},[r,t,e,n,o]);return l.jsxs("div",{className:"be-table-header-menu-options",children:[l.jsx("div",{className:"be-table-header-menu-options-label",children:"Options"}),n.map((c,f)=>l.jsxs("div",{className:"be-table-header-menu-option-row",children:[l.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(c.color??Tn(f)).bg},"aria-hidden":"true"}),l.jsx("input",{className:"be-table-header-menu-option-input",value:c.label,onChange:d=>a(c.value,d.target.value),"aria-label":`Rename option ${c.label}`}),l.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>i(c.value),"aria-label":`Remove option ${c.label}`,children:l.jsx(Ot,{size:14})})]},c.value)),l.jsxs("div",{className:"be-table-header-menu-option-row",children:[l.jsx("input",{className:"be-table-header-menu-option-input",value:o,onChange:c=>s(c.target.value),placeholder:"New option…",onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),u())}}),l.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:u,"aria-label":"Add option",children:"+"})]})]})}function Fp({tableId:t,column:e,colIndex:n,colCount:r}){const o=G(),s=tt(),[a,i]=p.useState(!1),[u,c]=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],[]),y=p.useCallback(()=>i(!1),[]);Ue(x,a,y),kr(m,a,y,h);const k=Np(m,a,u==null?void 0:u.right),w=p.useCallback(()=>{var B;c(((B=g.current)==null?void 0:B.getBoundingClientRect())??null),i(!0)},[]),v=p.useCallback(B=>Hl(o,t,n,B.target.value),[o,t,n]),j=p.useCallback(()=>{sr(o,t,n-1),y()},[o,t,n,y]),I=p.useCallback(()=>{sr(o,t,n),y()},[o,t,n,y]),C=p.useCallback(()=>{$l(o,t,n),y()},[o,t,n,y]),T=p.useCallback(B=>Fl(o,t,n,B,s),[o,t,n,s]),M=p.useCallback(B=>{var D;B.preventDefault();const L=(D=g.current)==null?void 0:D.closest("table"),S=L==null?void 0:L.querySelector(`col[data-col-index="${n}"]`);if(!S)return;const N=g.current.getBoundingClientRect().width,$=B.clientX,V=F=>Math.max(or,Math.round(N+(F.clientX-$))),K=F=>{const re=V(F);S.style.width=`${re}px`,d(re)},Q=F=>{document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",Q),zl(o,t,n,V(F)),d(null)};document.addEventListener("mousemove",K),document.addEventListener("mouseup",Q)},[o,t,n]);return l.jsxs("th",{ref:g,scope:"col",className:"be-table-header-cell",contentEditable:!1,children:[l.jsx("input",{className:"be-table-header-label",value:e.label,onChange:v,"aria-label":`Column ${n+1} name`}),l.jsx("button",{ref:h,type:"button",className:"be-table-header-menu-trigger","aria-label":`Column ${n+1} options`,"aria-haspopup":"menu","aria-expanded":a,onClick:()=>a?y():w(),children:"⋮"}),l.jsx("div",{className:"be-table-col-resize-handle",onMouseDown:M,role:"slider","aria-label":`Resize column ${n+1}`,"aria-valuemin":or,"aria-valuemax":zp,"aria-valuenow":f??e.width}),a&&u&&k!=null&&Ve.createPortal(l.jsxs("div",{ref:m,role:"menu","aria-label":`Column ${n+1} options`,className:"be-table-header-menu",style:{position:"fixed",top:u.bottom+4,left:k,transform:"translateX(-100%)"},children:[l.jsxs("div",{className:"be-table-header-menu-type",children:[l.jsx("span",{id:`be-table-col-type-${e.id}`,children:"Type"}),l.jsx(Mt,{value:e.type,options:$p,onChange:T,ariaLabel:"Column type",className:""})]}),e.type==="select"&&l.jsx(Hp,{tableId:t,colIndex:n,options:e.options??[]}),l.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:j,children:"Insert column left"}),l.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:I,children:"Insert column right"}),l.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item be-table-header-menu-item-danger",onClick:C,disabled:r<=1,children:"Delete column"})]}),document.body)]})}function Yl({tableId:t,columns:e}){return l.jsx("thead",{children:l.jsxs("tr",{className:"be-table-header-row",children:[e.map((n,r)=>l.jsx(Fp,{tableId:t,column:n,colIndex:r,colCount:e.length},n.id)),l.jsx("th",{className:"be-table-header-spacer","aria-hidden":"true"})]})})}function Up({id:t}){var i;const e=G(),n=be(t),r=p.useCallback(()=>{var c;const u=(c=n==null?void 0:n.contentIds)==null?void 0:c[n.contentIds.length-1];u&&Ko(e,u)},[e,n]),o=Ie("be-table-wrapper",n);if(!n)return null;const s=e.getBlock(n.contentIds[0]),a=$e(n,((i=s==null?void 0:s.contentIds)==null?void 0:i.length)??0);return l.jsx("div",{className:"be-table-scroll",children:l.jsxs("div",{className:o,"data-block-id":t,children:[l.jsxs("table",{className:"be-table",children:[l.jsxs("colgroup",{children:[a.map((u,c)=>l.jsx("col",{"data-col-index":c,style:{width:u.width}},u.id)),l.jsx("col",{className:"be-table-header-spacer-col"})]}),l.jsx(Yl,{tableId:t,columns:a}),l.jsx("tbody",{children:l.jsx(ht,{parentId:t})})]}),l.jsxs("button",{type:"button",className:"be-table-add-row",contentEditable:!1,onClick:r,children:[l.jsx(To,{size:14})," Add row"]})]})})}function Vp({id:t}){const e=G(),n=be(t),r=Ie("be-table-row",n),o=p.useCallback(()=>Pl(e,t),[e,t]);return l.jsxs("tr",{className:r,"data-block-id":t,children:[l.jsx(ht,{parentId:t}),l.jsx("td",{className:"be-table-row-actions",contentEditable:!1,children:l.jsx("button",{type:"button",className:"be-table-delete-row",onClick:o,"aria-label":"Delete row",title:"Delete row",children:l.jsx(Ot,{size:14})})})]})}function Kl(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId),o=t.getBlock(r.parentId);return{table:o,row:r,rowIndex:o.contentIds.indexOf(r.id),colIndex:r.contentIds.indexOf(e)}}function Yp(t,e,n){const{table:r,row:o,rowIndex:s,colIndex:a}=Kl(t,e);if(n==="left"||n==="right"){const f=n==="right"?1:-1,d=a+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=t.getBlock(r.contentIds[h]),g=n==="right"?0:m.contentIds.length-1;return m.contentIds[g]}const u=s+(n==="down"?1:-1);if(u<0||u>=r.contentIds.length)return null;const c=t.getBlock(r.contentIds[u]);return c.contentIds[a]??c.contentIds[c.contentIds.length-1]??null}function Kp(t,e){const n=xl(t,e,"down");if(n){ye(n);return}nt(t,e,te("paragraph"))}function bn(t,e,n){var o;const r=Yp(t,e,n);if(r){const s=t.getBlock(r),a=(o=s==null?void 0:s.contentIds)==null?void 0:o[0];a&&ye(a);return}if(n==="right"){const{table:s}=Kl(t,e);Kp(t,s.id)}}function Wp({id:t}){const e=G(),n=be(t),r=p.useCallback(()=>bn(e,t,"right"),[e,t]),o=p.useCallback(()=>bn(e,t,"left"),[e,t]),s=p.useCallback(()=>bn(e,t,"up"),[e,t]),a=p.useCallback(()=>bn(e,t,"down"),[e,t]),i=p.useCallback(()=>bn(e,t,"down"),[e,t]),u=Ie("be-table-cell",n);if(!n)return null;const c=it(e,n);return l.jsx("td",{className:u,"data-block-id":t,dir:c,children:l.jsx(pt,{blockId:t,runIds:n.contentIds,dir:c,onTab:r,onShiftTab:o,onArrowUp:s,onArrowDown:a,onEnter:i})})}function Xp(t,e){const n=E(),r=[],o=[],s=[];for(const a of e){const i=Cr(n,a);r.push(i.block),o.push(i.run),s.push(i.block.id)}return{block:{id:n,type:"tableRow",parentId:t,contentIds:s,props:{}},blocks:r,runs:o}}function qp({rows:t=2,cols:e=2}={}){return function(r){const o=E(),s=Yo(e),a=[],i=[],u=[];for(let f=0;f<t;f+=1){const d=Xp(o,s);a.push(d.block,...d.blocks),i.push(...d.runs),u.push(d.block.id)}return{block:{id:o,type:"table",parentId:r,contentIds:u,props:{columns:s}},runs:i,subtreeBlocks:a}}}function Gp(t,e){return`<td>${t.contentIds.map(r=>e.store.getRun(r)).map(r=>ft(r,e)).join("")}</td>`}function Jp(t,e){return t.contentIds.map(n=>It(e.store.getRun(n),e)).join("")}function Zp(t,e){if(t.tagName!=="TD"&&t.tagName!=="TH")return null;const n=Ye(t,e);return{block:{id:E(),type:"tableCell",parentId:null,contentIds:n.map(o=>o.id),props:{}},runs:n}}function Qp(t,e){return`<tr>${t.contentIds.map(r=>{const o=e.store.getBlock(r);return e.registry.get(o.type).toHTML(o,e)}).join("")}</tr>`}function ef(t,e){return t.contentIds.map(n=>{const r=e.store.getBlock(n);return e.registry.get(r.type).toPlainText(r,e)}).join(" ")}function tf(t,e){if(t.tagName!=="TR")return null;const n=[...t.children].filter(u=>u.tagName==="TD"||u.tagName==="TH"),r=E(),o=[],s=[],a=[];for(const u of n){const c=e.registry.get("tableCell").fromHTML(u,e);c&&(c.block.parentId=r,o.push(c.block),s.push(...c.runs),a.push(c.block.id))}return{block:{id:r,type:"tableRow",parentId:null,contentIds:a,props:{}},runs:s,subtreeBlocks:o}}function nf(t,e){var a;const n=t.contentIds[0]&&e.store.getBlock(t.contentIds[0]),r=$e(t,((a=n==null?void 0:n.contentIds)==null?void 0:a.length)??0),o=r.length?`<thead><tr>${r.map(i=>`<th>${Et(i.label??"")}</th>`).join("")}</tr></thead>`:"",s=t.contentIds.map(i=>{const u=e.store.getBlock(i);return e.registry.get(u.type).toHTML(u,e)}).join("");return`<table>${o}<tbody>${s}</tbody></table>`}function rf(t,e){return t.contentIds.map(n=>{const r=e.store.getBlock(n);return e.registry.get(r.type).toPlainText(r,e)}).join(`
|
|
2921
|
+
`)}function of(t,e){if(t.tagName!=="TABLE")return null;const n=t.querySelector("thead tr"),r=t.querySelector("tbody")?[...t.querySelectorAll("tbody tr")]:[...t.querySelectorAll("tr")].filter(f=>f!==n),o=E(),s=[],a=[],i=[];for(const f of r){const d=e.registry.get("tableRow").fromHTML(f,e);if(d){d.block.parentId=o;for(const h of d.subtreeBlocks)h.parentId=d.block.id;s.push(d.block,...d.subtreeBlocks),a.push(...d.runs),i.push(d.block.id)}}const u={};if(n){const f=[...n.children].filter(d=>d.tagName==="TH"||d.tagName==="TD");u.columns=f.map(d=>({id:E(),label:d.textContent??""}))}return{block:{id:o,type:"table",parentId:null,contentIds:i,props:u},runs:a,subtreeBlocks:s}}const Wl={component:Wp,isLeaf:!0,defaultProps:{},toHTML:Gp,toPlainText:Jp,fromHTML:Zp},Xl={component:Vp,isLeaf:!1,defaultProps:{},toHTML:Qp,toPlainText:ef,fromHTML:tf},ql={component:Up,isLeaf:!1,defaultProps:{},toHTML:nf,toPlainText:rf,fromHTML:of,slashCommand:{label:"Table",icon:md,keywords:["table","grid"],run:(t,e)=>Be(t,e,qp({rows:2,cols:2}))}};function sf({id:t}){const e=be(t),n=Ie("be-layout",e);return l.jsx("div",{className:n,"data-block-id":t,style:{display:"flex",gap:"1em"},children:l.jsx(ht,{parentId:t})})}function af({id:t}){const e=be(t),n=Ie("be-layout-column",e);return l.jsx("div",{className:n,"data-block-id":t,children:l.jsx(ht,{parentId:t})})}function lf({columns:t=2}={}){return function(n){const r=E(),o=[],s=[],a=[];for(let u=0;u<t;u+=1){const c=E(),{block:f,runs:d}=te("paragraph")(c),h={id:c,type:"layoutColumn",parentId:r,contentIds:[f.id],props:{}};o.push(h,f),s.push(...d),a.push(c)}return{block:{id:r,type:"layout",parentId:n,contentIds:a,props:{}},runs:s,subtreeBlocks:o}}}function Gl(t,e){return(n,r)=>`${t}${n.contentIds.map(o=>{const s=r.store.getBlock(o);return r.registry.get(s.type).toHTML(s,r)}).join("")}${e}`}function Jl(t,e){return t.contentIds.map(n=>{const r=e.store.getBlock(n);return e.registry.get(r.type).toPlainText(r,e)}).join(`
|
|
2922
|
+
`)}const Zl={component:af,isLeaf:!1,defaultProps:{},toHTML:Gl("<div>","</div>"),toPlainText:Jl},Ql={component:sf,isLeaf:!1,defaultProps:{},toHTML:Gl('<div style="display:flex;gap:1em">',"</div>"),toPlainText:Jl,slashCommands:[2,3,4,5].map(t=>({label:`${t} columns`,icon:bd,keywords:["layout","columns","column",String(t)],run:(e,n)=>Be(e,n,lf({columns:t}))}))};function cf({id:t}){const e=be(t),n=Ie("be-divider",e);return l.jsx("hr",{className:n,"data-block-id":t,contentEditable:!1,tabIndex:-1})}function uf(){return function(e){return{block:{id:E(),type:"divider",parentId:e,contentIds:[],props:{}},runs:[]}}}function df(){return"<hr />"}function pf(){return"---"}function ff(t){return t.tagName!=="HR"?null:{block:{id:E(),type:"divider",parentId:null,contentIds:[],props:{}},runs:[]}}const ei={component:cf,isLeaf:!0,defaultProps:{},toHTML:df,toPlainText:pf,fromHTML:ff,slashCommand:{label:"Divider",icon:fd,keywords:["divider","hr","separator","line"],run:(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o})=>{const s=t.getRun(n),a=(s==null?void 0:s.value)??"";t.applyOperation(ue(n,{value:a.slice(0,r)+a.slice(o)}));const i=yr(t,e,uf());return nt(t,i,te("paragraph")),i}}},ti=[{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 hf({id:t}){var k,w;const e=G(),n=be(t),[r,o]=p.useState(!1),[s,a]=p.useState(!1),i=p.useRef(null),u=p.useRef(null),c=p.useMemo(()=>[i,u],[]),f=p.useCallback(()=>a(!1),[]);Ue(c,s,f);const d=((k=n==null?void 0:n.props)==null?void 0:k.icon)??pn,h=((w=n==null?void 0:n.props)==null?void 0:w.color)??Rl,m=p.useCallback(v=>{const j=v.target.value.trim();j&&e.applyOperation(J(t,{icon:j})),o(!1)},[e,t]),g=p.useCallback(v=>{v.key==="Enter"&&v.currentTarget.blur(),v.key==="Escape"&&o(!1)},[]),x=p.useCallback(v=>{e.applyOperation(J(t,{color:v})),a(!1)},[e,t]),y=Ie("be-callout",n);return n?l.jsxs("div",{className:y,"data-block-id":t,"data-color":h,children:[l.jsx("div",{className:"be-callout-icon-wrap",children:r?l.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)"}):l.jsx("button",{type:"button",className:"be-callout-icon",onClick:()=>o(!0),"aria-label":"Change callout icon",title:"Change icon",children:d})}),l.jsx("div",{className:"be-callout-content",children:l.jsx(ht,{parentId:t})}),l.jsxs("div",{className:"be-callout-color-wrap",contentEditable:!1,children:[l.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:()=>a(v=>!v),children:l.jsx("span",{className:`be-callout-color-dot be-callout-color-dot-${h}`})}),s&&l.jsx("div",{ref:u,className:"be-callout-color-picker",role:"menu","aria-label":"Callout color",children:ti.map(v=>l.jsx("button",{type:"button",role:"menuitem",className:`be-callout-color-option be-callout-color-option-${v.value}${v.value===h?" be-callout-color-option-active":""}`,title:v.label,"aria-label":v.label,onClick:()=>x(v.value)},v.value))})]})]}):null}function mf(t,e){return t.contentIds.map(n=>{const r=e.store.getBlock(n);return e.registry.get(r.type).toHTML(r,e)}).join("")}function bf(t,e){var r;const n=((r=t.props)==null?void 0:r.icon)??pn;return`<div class="callout" data-icon="${n}"><div class="callout-icon">${n}</div><div class="callout-content">${mf(t,e)}</div></div>`}function gf(t,e){var o;const n=((o=t.props)==null?void 0:o.icon)??pn,r=t.contentIds.map(s=>{const a=e.store.getBlock(s);return e.registry.get(a.type).toPlainText(a,e)}).join(`
|
|
2923
|
+
`);return`${n} ${r}`}const ni={component:hf,isLeaf:!1,defaultProps:{icon:pn},toHTML:bf,toPlainText:gf,slashCommand:{label:"Callout",icon:nl,keywords:["callout","aside","note","info","tip","warning"],run:(t,e)=>Be(t,e,up())}};function xf({id:t}){const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=p.useCallback(()=>{cn(e,t,(n==null?void 0:n.contentIds)??[],te("paragraph"))},[e,t,n]),s=p.useCallback(()=>{const d=Nn(e,t);dn(e,d,t,r)},[e,t,r]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),u=Ie("be-blockquote",n);if(!n)return null;const c=Le(e,n.contentIds),f=it(e,n);return l.jsx("blockquote",{className:u,"data-block-id":t,"data-empty":c?"":void 0,"data-placeholder":"Empty quote",dir:f,children:l.jsx(pt,{blockId:t,runIds:n.contentIds,dir:f,onEnter:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i})})}function yf(t,e){return`<p>${t.contentIds.map(r=>e.store.getRun(r)).map(r=>ft(r,e)).join("")}</p>`}function kf(t,e){return t.contentIds.map(n=>It(e.store.getRun(n),e)).join("")}function vf(t,e){if(t.tagName!=="BLOCKQUOTE")return null;const n=Ye(t,e);return{block:{id:E(),type:"blockquote",parentId:null,contentIds:n.map(o=>o.id),props:{}},runs:n}}const ri={component:xf,isLeaf:!0,defaultProps:{},toHTML:yf,toPlainText:kf,fromHTML:vf,slashCommand:{label:"Quote",icon:tl,keywords:["quote","blockquote","citation"],run:(t,e)=>Be(t,e,te("blockquote"))}},oi=["plaintext","javascript","python","html","css","json","bash","sql"],wf=oi.map(t=>({value:t,label:t}));function Js(t,e,n){const r=lt();if(!r||r.blockId!==e)return;const o=t.getRun(r.runId);if(!o||o.type!=="text")return;const s=o.value??"",a=s.slice(0,r.offset)+n+s.slice(r.offset);t.applyOperation(ue(o.id,{value:a})),Je(o.id,r.offset+n.length)}function If({id:t}){var m;const e=G(),n=be(t),r=p.useCallback(()=>Js(e,t,`
|
|
2924
|
+
`),[e,t]),o=p.useCallback(()=>Js(e,t," "),[e,t]),s=p.useCallback(()=>{var k;const g=Nn(e,t);if(!g||g===t)return;const x=e.getBlock(g),y=(k=x==null?void 0:x.contentIds)==null?void 0:k[x.contentIds.length-1];y&&ye(y)},[e,t]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),u=p.useCallback(g=>e.applyOperation(J(t,{language:g})),[e,t]),c=p.useCallback(()=>vr(e,t),[e,t]),f=Ie("be-code-block",n);if(!n)return null;const d=((m=n.props)==null?void 0:m.language)??"plaintext",h=Le(e,n.contentIds);return l.jsxs("div",{className:f,"data-block-id":t,children:[l.jsxs("div",{className:"be-code-block-header",contentEditable:!1,children:[l.jsx(Mt,{className:"be-code-block-language",value:d,options:wf,onChange:u,ariaLabel:"Code language"}),l.jsx("button",{type:"button",className:"be-code-block-delete",onClick:c,"aria-label":"Delete code block",title:"Delete code block",children:l.jsx(On,{size:14})})]}),l.jsx("pre",{className:"be-code-block-pre",dir:"ltr",children:l.jsx("code",{"data-empty":h?"":void 0,"data-placeholder":"Empty code block",children:l.jsx(pt,{blockId:t,runIds:n.contentIds,dir:"ltr",onEnter:r,onTab:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i})})})]})}function Cf(t,e){var s;const n=t.contentIds.map(a=>e.store.getRun(a)),r=(s=t.props)==null?void 0:s.language;return`<pre><code${r&&r!=="plaintext"?` data-language="${Et(r)}"`:""}>${n.map(a=>ft(a,e)).join("")}</code></pre>`}function Sf(t,e){return t.contentIds.map(n=>It(e.store.getRun(n),e)).join("")}function Rf(t,e){var a;if(t.tagName!=="PRE")return null;const n=t.querySelector("code")??t,r=(a=n.getAttribute)==null?void 0:a.call(n,"data-language"),o=E();return{block:{id:E(),type:"code",parentId:null,contentIds:[o],props:r?{language:r}:{}},runs:[{id:o,type:"text",value:n.textContent??"",marks:{}}]}}const si={component:If,isLeaf:!0,defaultProps:{language:"plaintext"},toHTML:Cf,toPlainText:Sf,fromHTML:Rf,slashCommand:{label:"Code",icon:_o,keywords:["code","codeblock","snippet","pre"],run:(t,e)=>Be(t,e,te("code"))}};function Tf(t,e){var n;return e.length===0||e.length===1&&(((n=t.getRun(e[0]))==null?void 0:n.value)??"")===""}function jf(t,e){const n=e.contentIds??[];if(n.length===0)return!0;if(n.length>1)return!1;const r=t.getBlock(n[0]);return!!r&&r.type==="paragraph"&&Le(t,r.contentIds)}function Yn(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Ef(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=n.props.titleRunIds??[],a=Tf(t,s)&&jf(t,n);if(o<=0){if(!a)return null;if(r.contentIds.length>1)return Yn(t,[ee(e)]),{focusBlockId:t.getBlock(r.id).contentIds[0],needsRefocus:!0};const{block:c,runs:f}=te("paragraph")(r.id);return Yn(t,[me(c,r.id,o,{blocks:[c],runs:f}),ee(e)]),{focusBlockId:c.id,needsRefocus:!0}}const i=r.contentIds[o-1],u=t.getBlock(i);return a?(Yn(t,[ee(e)]),{focusBlockId:i,needsRefocus:!0}):Mn(t,u)?(Yn(t,[ee(i)]),{focusBlockId:e,needsRefocus:!1}):null}function Bf(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function _f({id:t}){var y;const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=p.useCallback(()=>{var j,I;const k=((j=n==null?void 0:n.props)==null?void 0:j.titleRunIds)??[],w=(((I=n==null?void 0:n.contentIds)==null?void 0:I.length)??0)>0,v=te("paragraph");w?kl(e,t,k,v):cn(e,t,k,v)},[e,t,n]),s=p.useCallback(()=>{const k=Ef(e,t);!k||!k.needsRefocus||dn(e,k.focusBlockId,t,r)},[e,t,r]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),u=p.useCallback(()=>{var w,v;if(!((((w=n==null?void 0:n.contentIds)==null?void 0:w.length)??0)>0)){const{block:j,runs:I}=te("paragraph")(t);Bf(e,[me(j,t,0,{blocks:[j],runs:I}),J(t,{collapsed:!1})]),ye(j.contentIds[0]);return}e.applyOperation(J(t,{collapsed:!((v=n==null?void 0:n.props)!=null&&v.collapsed)}))},[e,t,n==null?void 0:n.contentIds,(y=n==null?void 0:n.props)==null?void 0:y.collapsed]),c=Ie("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=it(e,n);return l.jsxs("div",{className:c,"data-block-id":t,dir:x,children:[l.jsxs("div",{className:"be-toggle-heading-row",children:[l.jsx("button",{type:"button",className:"be-toggle-heading-marker",onClick:u,"aria-expanded":!d,"aria-label":m?d?"Expand section":"Collapse section":"Add content to section",children:d?l.jsx(jt,{}):l.jsx(fr,{})}),l.jsx(g,{className:`be-heading be-heading-${f} be-toggle-heading-title`,"data-empty":Le(e,h)?"":void 0,"data-placeholder":`Toggle heading ${f}`,children:l.jsx(pt,{blockId:t,runIds:h,dir:x,onEnter:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i})})]}),!d&&l.jsx("div",{className:"be-toggle-heading-children",children:l.jsx(ht,{parentId:t})})]})}function Of({level:t=2,collapsed:e=!1}={}){return function(r,o){const s=E(),a=o!=null&&o.length?o:[{id:E(),type:"text",value:"",marks:{}}],{block:i,runs:u}=te("paragraph")(s);return{block:{id:s,type:"toggleHeading",parentId:r,contentIds:[i.id],props:{level:t,collapsed:e,titleRunIds:a.map(c=>c.id)}},runs:[...a,...u],subtreeBlocks:[i]}}}function Mf(t,e){const{titleRunIds:n=[],level:r=2,collapsed:o}=t.props,s=n.map(i=>ft(e.store.getRun(i),e)).join(""),a=t.contentIds.map(i=>{const u=e.store.getBlock(i);return e.registry.get(u.type).toHTML(u,e)}).join("");return`<details${o?"":" open"}><summary><h${r}>${s}</h${r}></summary>${a}</details>`}function Lf(t,e){const{titleRunIds:n=[]}=t.props,r=n.map(s=>It(e.store.getRun(s),e)).join(""),o=t.contentIds.map(s=>{const a=e.store.getBlock(s);return e.registry.get(a.type).toPlainText(a,e)}).join(`
|
|
2531
2925
|
`);return o?`${r}
|
|
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;
|
|
2926
|
+
${o}`:r}function Nf(t,e){if(t.tagName!=="DETAILS")return null;const n=[...t.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?Ye(r,e):[{id:E(),type:"text",value:"",marks:{}}],a=E(),i=[],u=[],c=[];for(const d of t.children){if(d===n||d.tagName!=="P")continue;const h=Ye(d,e),m={id:E(),type:"paragraph",parentId:a,contentIds:h.map(g=>g.id),props:{}};i.push(m),u.push(...h),c.push(m.id)}if(c.length===0){const{block:d,runs:h}=te("paragraph")(a);i.push(d),u.push(...h),c.push(d.id)}return{block:{id:a,type:"toggleHeading",parentId:null,contentIds:c,props:{level:o,collapsed:!t.hasAttribute("open"),titleRunIds:s.map(d=>d.id)}},runs:[...s,...u],subtreeBlocks:i}}const ai={component:_f,isLeaf:!1,defaultProps:{level:2,collapsed:!1,titleRunIds:[]},toHTML:Mf,toPlainText:Lf,fromHTML:Nf,slashCommands:[1,2,3].map(t=>({label:`Toggle heading ${t}`,icon:jt,keywords:["toggle","heading","collapse","section"],run:(e,n)=>Be(e,n,Of({level:t}))}))},Ur=[{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 Af(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Df({isOpen:t,onClose:e,store:n,blockId:r}){const[o,s]=p.useState(""),[a,i]=p.useState(""),[u,c]=p.useState(Ur[0].value),[f,d]=p.useState([{key:"",value:""}]);p.useEffect(()=>{var w,v,j;if(!t)return;const x=n.getBlock(r);if(!x)return;const y=x.contentIds.map(I=>{var C;return((C=n.getRun(I))==null?void 0:C.value)??""}).join(""),k=((w=x.props)==null?void 0:w.customAttrs)??[];s(y),i(((v=x.props)==null?void 0:v.href)??""),c(((j=x.props)==null?void 0:j.color)??Ur[0].value),d([...k,{key:"",value:""}])},[t,r,n]);const h=p.useCallback((x,y)=>{d(k=>{const w=k.map((j,I)=>I===x?{...j,...y}:j),v=w[w.length-1];return(v.key.trim()||v.value.trim())&&w.push({key:"",value:""}),w})},[]),m=p.useCallback(x=>{d(y=>y.filter((k,w)=>w!==x))},[]),g=p.useCallback(()=>{const x={id:E(),type:"text",value:o,marks:{}},y=f.filter(k=>k.key.trim());Af(n,[Me(r,[x]),J(r,{href:a.trim(),color:u,customAttrs:y})]),e()},[n,r,o,a,u,f,e]);return l.jsxs(dt,{isOpen:t,onClose:e,title:"Edit button",children:[l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Label"}),l.jsx("input",{type:"text",value:o,onChange:x=>s(x.target.value),placeholder:"Button"})]}),l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Link URL"}),l.jsx("input",{type:"url",value:a,onChange:x=>i(x.target.value),placeholder:"https://example.com"})]}),l.jsxs("div",{className:"be-modal-field",children:[l.jsx("span",{children:"Color"}),l.jsx("div",{className:"be-modal-color-row",children:Ur.map(x=>l.jsx("button",{type:"button",className:`be-modal-color-swatch${u===x.value?" be-modal-color-swatch-active":""}`,style:{backgroundColor:x.value},title:x.label,"aria-label":x.label,onClick:()=>c(x.value)},x.value))})]}),l.jsxs("div",{className:"be-modal-field",children:[l.jsx("span",{children:"Custom attributes"}),f.map((x,y)=>l.jsxs("div",{className:"be-modal-attr-row",children:[l.jsx("input",{type:"text",placeholder:"name",value:x.key,onChange:k=>h(y,{key:k.target.value})}),l.jsx("input",{type:"text",placeholder:"value",value:x.value,onChange:k=>h(y,{value:k.target.value})}),(x.key||x.value)&&l.jsx("button",{type:"button",className:"be-modal-attr-remove",onClick:()=>m(y),"aria-label":"Remove attribute",children:l.jsx(Ot,{size:14})})]},y))]}),l.jsxs("div",{className:"be-modal-actions",children:[l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:e,children:"Cancel"}),l.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:"Save"})]})]})}const Pf="#2b6fd6";function $f({id:t}){var w,v,j,I;const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),[o,s]=p.useState(!1),a=p.useCallback(()=>{cn(e,t,(n==null?void 0:n.contentIds)??[],te("paragraph"))},[e,t,n]),i=p.useCallback(()=>{const C=Nn(e,t);dn(e,C,t,r)},[e,t,r]),u=p.useCallback(()=>_e(e,t,"up"),[e,t]),c=p.useCallback(()=>_e(e,t,"down"),[e,t]),f=p.useCallback(()=>{var T;const C=(T=n==null?void 0:n.props)==null?void 0:T.href;C&&window.open(C,"_blank","noopener,noreferrer")},[(w=n==null?void 0:n.props)==null?void 0:w.href]),d=Ie("be-button-block",n);if(!n)return null;const h=((v=n.props)==null?void 0:v.href)??"",m=((j=n.props)==null?void 0:j.color)??Pf,g=((I=n.props)==null?void 0:I.customAttrs)??[],x=Le(e,n.contentIds),y={};for(const{key:C,value:T}of g)C.trim()&&(y[`data-${C.trim()}`]=T);const k=it(e,n);return l.jsxs("div",{className:d,"data-block-id":t,dir:k,children:[l.jsxs("div",{className:"be-button-block-pill",style:{backgroundColor:m},...y,children:[l.jsx("span",{className:"be-button-block-label","data-empty":x?"":void 0,"data-placeholder":"Button",children:l.jsx(pt,{blockId:t,runIds:n.contentIds,dir:k,onEnter:a,onBackspaceAtStart:i,onArrowUp:u,onArrowDown:c})}),l.jsx("button",{type:"button",className:"be-button-block-open",onClick:f,disabled:!h,title:h||"No link set","aria-label":"Open link",children:"↗"}),l.jsx("button",{type:"button",className:"be-button-block-settings",onClick:()=>s(!0),"aria-label":"Edit button",title:"Edit label, link, color…",children:"⚙"})]}),l.jsx(Df,{isOpen:o,onClose:()=>s(!1),store:e,blockId:t})]})}function zf({href:t="",label:e="Button",color:n="",customAttrs:r=[]}={}){return function(s,a){const i=E(),u=a!=null&&a.length?a:[{id:E(),type:"text",value:e,marks:{}}];return{block:{id:i,type:"button",parentId:s,contentIds:u.map(c=>c.id),props:{href:t,color:n,customAttrs:r}},runs:u}}}const li="be-button-block-link";function Hf(t,e){var u,c,f;const n=t.contentIds.map(d=>e.store.getRun(d)),r=((u=t.props)==null?void 0:u.href)??"",o=(c=t.props)==null?void 0:c.color,s=o?` style="background-color:${Ee(o)}"`:"",i=(((f=t.props)==null?void 0:f.customAttrs)??[]).filter(d=>{var h;return(h=d.key)==null?void 0:h.trim()}).map(d=>` data-${Ee(d.key.trim())}="${Ee(d.value??"")}"`).join("");return`<a class="${li}" href="${Ee(r)}"${s}${i}>${n.map(d=>ft(d,e)).join("")}</a>`}function Ff(t,e){return t.contentIds.map(n=>It(e.store.getRun(n),e)).join("")}function Uf(t,e){var s;if(t.tagName!=="A"||!t.classList.contains(li))return null;const n=Ye(t,e),r=[];for(const a of t.attributes)a.name.startsWith("data-")&&r.push({key:a.name.slice(5),value:a.value});return{block:{id:E(),type:"button",parentId:null,contentIds:n.map(a=>a.id),props:{href:t.getAttribute("href")??"",color:((s=t.style)==null?void 0:s.backgroundColor)||void 0,customAttrs:r}},runs:n}}const ii={component:$f,isLeaf:!0,defaultProps:{href:"",color:"",customAttrs:[]},toHTML:Hf,toPlainText:Ff,fromHTML:Uf,slashCommand:{label:"Button",icon:hd,keywords:["button","link","cta","action"],run:(t,e)=>Be(t,e,zf())}};function Zs(t){return new Promise((e,n)=>{const r=new FileReader;r.onload=()=>e(r.result),r.onerror=()=>n(r.error),r.readAsDataURL(t)})}const Kn={image:"image",video:"video",audio:"audio",file:"file"},Vf={image:"image/*",video:"video/*",audio:"audio/*",file:"*/*"},ci=20,ui=100,Yf=[{value:"left",Icon:Xa,label:"Align left"},{value:"center",Icon:nd,label:"Align center"},{value:"right",Icon:qa,label:"Align right"}];function Kf(t){return Math.min(ui,Math.max(ci,Math.round(t)))}function Wf({kind:t,src:e,name:n,alt:r}){return t==="image"?l.jsx("img",{className:"be-embed-image",src:e,alt:r||""}):t==="video"?l.jsx("video",{className:"be-embed-video",src:e,controls:!0}):t==="audio"?l.jsx("audio",{className:"be-embed-audio",src:e,controls:!0}):l.jsxs("a",{className:"be-embed-file-link",href:e,download:n||void 0,target:"_blank",rel:"noopener noreferrer",children:[l.jsx(Ha,{size:14})," ",n||e]})}function Xf({id:t}){var re;const e=G(),n=be(t),[r,o]=p.useState(""),[s,a]=p.useState(!1),[i,u]=p.useState(null),[c,f]=p.useState(!1),[d,h]=p.useState(""),m=p.useRef(null),g=p.useRef(null),x=p.useCallback(H=>e.applyOperation(J(t,H)),[e,t]),y=p.useCallback(()=>{var H;h(((H=n==null?void 0:n.props)==null?void 0:H.alt)??""),f(!0)},[(re=n==null?void 0:n.props)==null?void 0:re.alt]),k=p.useCallback(()=>f(!1),[]),w=p.useCallback(H=>{H.preventDefault(),x({alt:d.trim()}),f(!1)},[d,x]),v=p.useCallback(async H=>{var oe;const ne=(oe=H.target.files)==null?void 0:oe[0];if(!ne)return;const se=await Zs(ne);x({src:se,name:ne.name,mimeType:ne.type})},[x]),j=p.useCallback(async H=>{var oe;H.preventDefault(),a(!1);const ne=(oe=H.dataTransfer.files)==null?void 0:oe[0];if(!ne)return;const se=await Zs(ne);x({src:se,name:ne.name,mimeType:ne.type})},[x]),I=p.useCallback(H=>{H.preventDefault(),a(!0)},[]),C=p.useCallback(()=>a(!1),[]),T=p.useCallback(()=>{const H=r.trim();H&&(x({src:H,name:H}),o(""))},[r,x]),M=p.useCallback(()=>x({src:"",name:"",mimeType:""}),[x]),B=p.useCallback(H=>{H.preventDefault();const ne=m.current,se=g.current;if(!ne||!se)return;const oe=ne.getBoundingClientRect().width,ge=se.getBoundingClientRect().width,Te=H.clientX,ce=U=>Kf((ge+(U.clientX-Te))/oe*100),ke=U=>u(ce(U)),he=U=>{document.removeEventListener("mousemove",ke),document.removeEventListener("mouseup",he),x({width:ce(U)}),u(null)};document.addEventListener("mousemove",ke),document.addEventListener("mouseup",he)},[x]),L=Ie("be-embed",n);if(!n)return null;const{kind:S="file",src:N,name:$,alt:V="",align:K="left",width:Q=100}=n.props,D=S==="image"||S==="video",F=i??Q;return l.jsxs("div",{className:L,"data-block-id":t,"data-kind":S,contentEditable:!1,tabIndex:-1,children:[N?l.jsx("div",{ref:m,className:`be-embed-preview be-embed-align-${K}`,children:l.jsxs("div",{ref:g,className:"be-embed-frame",style:D?{width:`${F}%`}:void 0,children:[l.jsxs("div",{className:"be-embed-toolbar",contentEditable:!1,children:[Yf.map(({value:H,Icon:ne,label:se})=>l.jsx("button",{type:"button",className:`be-embed-toolbar-btn${K===H?" be-embed-toolbar-btn-active":""}`,title:se,"aria-label":se,"aria-pressed":K===H,onClick:()=>x({align:H}),children:l.jsx(ne,{size:14})},H)),S==="image"&&l.jsx("button",{type:"button",className:"be-embed-toolbar-btn be-embed-alt-text-btn",onClick:y,children:"Alt text"}),l.jsx("button",{type:"button",className:"be-embed-remove",onClick:M,"aria-label":`Remove ${Kn[S]}`,children:"Remove"})]}),l.jsx(Wf,{kind:S,src:N,name:$,alt:V}),D&&l.jsx("div",{className:"be-embed-resize-handle",onMouseDown:B,role:"slider","aria-label":`Resize ${Kn[S]}`,"aria-valuemin":ci,"aria-valuemax":ui,"aria-valuenow":F})]})}):l.jsxs("div",{className:`be-embed-dropzone${s?" be-embed-dropzone-active":""}`,onDrop:j,onDragOver:I,onDragLeave:C,children:[l.jsxs("label",{className:"be-embed-upload-btn",children:["Upload ",Kn[S],l.jsx("input",{type:"file",accept:Vf[S],onChange:v,hidden:!0})]}),l.jsx("span",{className:"be-embed-dropzone-hint",children:"or drop a file, or paste a URL below"}),l.jsxs("div",{className:"be-embed-url-row",children:[l.jsx("input",{type:"text",className:"be-embed-url-input",placeholder:`https://... ${Kn[S]} URL`,value:r,onChange:H=>o(H.target.value),onKeyDown:H=>H.key==="Enter"&&T()}),l.jsx("button",{type:"button",className:"be-embed-url-commit",onClick:T,children:"Embed"})]})]}),l.jsx(dt,{isOpen:c,onClose:k,title:"Alt text",children:l.jsxs("form",{onSubmit:w,children:[l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Describe this image for screen readers"}),l.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})]}),l.jsxs("div",{className:"be-modal-actions",children:[l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:k,children:"Cancel"}),l.jsx("button",{type:"submit",className:"be-modal-save",children:"Save"})]})]})})]})}function qf({kind:t="file",src:e="",name:n="",alt:r="",mimeType:o="",align:s="left",width:a=100}={}){return function(u){return{block:{id:E(),type:"embed",parentId:u,contentIds:[],props:{kind:t,src:e,name:n,alt:r,mimeType:o,align:s,width:a}},runs:[]}}}const Gf={image:xd,video:yd,audio:kd,file:Ha},di="be-embed-file-link";function Jf(t,e,n){if(t!=="image"&&t!=="video")return"";const r=[];return n!==100&&r.push(`width:${n}%`),e==="center"?r.push("display:block","margin-left:auto","margin-right:auto"):e==="right"&&r.push("display:block","margin-left:auto"),r.length?` style="${r.join(";")}"`:""}function Qs(t){var o,s,a,i;const e=(o=t.style)==null?void 0:o.width,n=e&&e.endsWith("%")?parseInt(e,10):100;let r="left";return((s=t.style)==null?void 0:s.marginLeft)==="auto"&&((a=t.style)==null?void 0:a.marginRight)==="auto"?r="center":((i=t.style)==null?void 0:i.marginLeft)==="auto"&&(r="right"),{align:r,width:Number.isFinite(n)?n:100}}function Zf(t){const{kind:e,src:n,name:r,alt:o="",align:s="left",width:a=100}=t.props;if(!n)return"<p></p>";const i=Jf(e,s,a);return e==="image"?`<img src="${Ee(n)}" alt="${Ee(o)}"${i}>`:e==="video"?`<video src="${Ee(n)}" controls${i}></video>`:e==="audio"?`<audio src="${Ee(n)}" controls></audio>`:`<a class="${di}" href="${Ee(n)}">${Et(r||n)}</a>`}function Qf(t){const{kind:e,src:n,name:r}=t.props;return n?`[${e}: ${r||n}]`:""}function eh(t){return t.tagName==="IMG"?Wn("image",t.getAttribute("src")??"","",{...Qs(t),alt:t.getAttribute("alt")??""}):t.tagName==="VIDEO"?Wn("video",t.getAttribute("src")??"","",Qs(t)):t.tagName==="AUDIO"?Wn("audio",t.getAttribute("src")??"",""):t.tagName==="A"&&t.classList.contains(di)?Wn("file",t.getAttribute("href")??"",t.textContent??""):null}function Wn(t,e,n,{align:r="left",width:o=100,alt:s=""}={}){return{block:{id:E(),type:"embed",parentId:null,contentIds:[],props:{kind:t,src:e,name:n,alt:s,align:r,width:o}},runs:[]}}function th(t){return(e,{blockId:n,runId:r,sliceStart:o,sliceEnd:s})=>{const a=e.getRun(r),i=(a==null?void 0:a.value)??"";e.applyOperation(ue(r,{value:i.slice(0,o)+i.slice(s)}));const u=yr(e,n,qf({kind:t}));return nt(e,u,te("paragraph")),u}}const pi={component:Xf,isLeaf:!0,defaultProps:{kind:"file",src:"",name:"",alt:"",mimeType:"",align:"left",width:100},toHTML:Zf,toPlainText:Qf,fromHTML:eh,slashCommands:["image","video","audio","file"].map(t=>({label:t.charAt(0).toUpperCase()+t.slice(1),icon:Gf[t],keywords:["embed","upload","insert",t],run:th(t)}))},fi=8,hi=.5,nh=.5,rh=4,Vr=.15,oh=8;function mi(t,e){return Math.hypot(t[0]-e[0],t[1]-e[1])}function Qn(t,e,n){return Math.min(n,Math.max(e,t))}function Xn(t){return Math.round(t*100)/100}const bi=.5;function sh(t){return t.some(([,,e])=>e!==void 0&&e!==bi)}function ah(t,{size:e=fi,thinning:n=hi}={}){const r=e/2,o=t.length;if(!sh(t))return new Array(o).fill(r);const a=new Array(o);let i=0;for(let c=0;c<o;c+=1){if(c>0){const g=mi(t[c],t[c-1]);i=i*.8+g*.2}const f=Qn(i/oh,0,1),d=t[c][2]??bi,h=.4+.6*Qn(d,0,1),m=Qn(r*h*(1-n*f),r*Vr,r);a[c]=m}const u=Math.min(rh,Math.floor(o/2));for(let c=0;c<u;c+=1){const f=(c+1)/(u+1),d=Vr+(1-Vr)*f;a[c]*=d,a[o-1-c]*=d}return a}function lh(t,e){const n=t.length;if(n<3||e<=0)return t;const r=new Array(n);r[0]=t[0],r[n-1]=t[n-1];for(let o=1;o<n-1;o+=1){const s=(t[o-1][0]+t[o+1][0])/2,a=(t[o-1][1]+t[o+1][1])/2,i=t[o][0]+(s-t[o][0])*e,u=t[o][1]+(a-t[o][1])*e;r[o]=[i,u,t[o][2]]}return r}function ih(t,e){const n=t.length,r=new Array(n),o=new Array(n);for(let s=0;s<n;s+=1){const a=t[Math.max(0,s-1)],i=t[Math.min(n-1,s+1)];let u=i[0]-a[0],c=i[1]-a[1];const f=Math.hypot(u,c)||1;u/=f,c/=f;const d=-c,h=u,m=e[s];r[s]=[t[s][0]+d*m,t[s][1]+h*m],o[s]=[t[s][0]-d*m,t[s][1]-h*m]}return{left:r,right:o}}function gi(t){if(t.length===0)return"";let e=`M${Xn(t[0][0])},${Xn(t[0][1])}`;for(let n=1;n<t.length;n+=1)e+=` L${Xn(t[n][0])},${Xn(t[n][1])}`;return e}function ch([t,e],n){const o=[];for(let s=0;s<12;s+=1){const a=s/12*Math.PI*2;o.push([t+Math.cos(a)*n,e+Math.sin(a)*n])}return`${gi(o)} Z`}function ar(t,e={}){const{size:n=fi,thinning:r=hi,smoothing:o=nh}=e;if(!t||t.length===0)return"";const s=[t[0]];for(let d=1;d<t.length;d+=1)mi(t[d],s[s.length-1])>.1&&s.push(t[d]);if(s.length===1){const d=s[0][2]??.5,h=n/2*(.4+.6*Qn(d,0,1));return ch(s[0],h)}const a=ah(s,{size:n,thinning:r}),i=lh(s,o),{left:u,right:c}=ih(i,a),f=[...u,...c.slice().reverse()];return`${gi(f)} Z`}function er(t){if(!t||t.length===0)return{minX:0,minY:0,maxX:0,maxY:0};let e=1/0,n=1/0,r=-1/0,o=-1/0;for(const[s,a]of t)s<e&&(e=s),a<n&&(n=a),s>r&&(r=s),a>o&&(o=a);return{minX:e,minY:n,maxX:r,maxY:o}}function Xo(t,e){const n=t.getBoundingClientRect(),r=n.width||1,o=n.height||1,s=Math.min(r/e,o/e),a=(r-e*s)/2,i=(o-e*s)/2;return{rect:n,scale:s,offsetX:a,offsetY:i}}function qe(t,e,n={x:0,y:0,size:1e3}){const{rect:r,scale:o,offsetX:s,offsetY:a}=Xo(e,n.size),i=n.x+(t.clientX-r.left-s)/o,u=n.y+(t.clientY-r.top-a)/o;return[i,u]}function Yr(t,e){return Xo(t,e).scale}function uh(t,e,n,r){const[o,s]=qe(t,e,n),{rect:a,scale:i,offsetX:u,offsetY:c}=Xo(e,r),f=o-(t.clientX-a.left-u)/i,d=s-(t.clientY-a.top-c)/i;return{x:f,y:d}}function ea(t,e){const n=t.x+t.size/2,r=t.y+t.size/2;return{x:n-e/2,y:r-e/2}}function gn(t,e,n=0){return t.minX-n<=e.maxX&&t.maxX+n>=e.minX&&t.minY-n<=e.maxY&&t.maxY+n>=e.minY}function wn(t,e,n,r){const o=Math.min(t,n),s=Math.min(e,r),a=Math.abs(n-t),i=Math.abs(r-e);return{x:o,y:s,width:a,height:i}}function xi(t,e,n,r,o){const s=o*Math.PI/180,a=Math.cos(s),i=Math.sin(s),u=t-n,c=e-r;return[n+u*a-c*i,r+u*i+c*a]}function yi(t,e,n){return t>=n.x&&t<=n.x+n.width&&e>=n.y&&e<=n.y+n.height}function dh(t,e,n){const r=n.width/2,o=n.height/2;if(r===0||o===0)return!1;const s=n.x+r,a=n.y+o,i=(t-s)/r,u=(e-a)/o;return i*i+u*u<=1}function ph(t,e,n,r,o,s){const a=o-n,i=s-r,u=a*a+i*i;if(u===0)return Math.hypot(t-n,e-r);let c=((t-n)*a+(e-r)*i)/u;c=Math.min(1,Math.max(0,c));const f=n+c*a,d=r+c*i;return Math.hypot(t-f,e-d)}function ki(t,e,n,r,o,s,a){return ph(t,e,n,r,o,s)<=a}function vi(t){const{x:e,y:n,width:r,height:o}=t;return[[e+r/2,n],[e+r,n+o/2],[e+r/2,n+o],[e,n+o/2]]}function wi(t){const{x:e,y:n,width:r,height:o}=t;return[[e+r/2,n],[e+r,n+o],[e,n+o]]}function Ii(t,e=5){const{x:n,y:r,width:o,height:s}=t,a=n+o/2,i=r+s/2,u=o/2,c=s/2,f=.4,d=[],h=Math.PI/e;let m=-Math.PI/2;for(let g=0;g<e*2;g+=1){const x=g%2===0,y=x?u:u*f,k=x?c:c*f;d.push([a+Math.cos(m)*y,i+Math.sin(m)*k]),m+=h}return d}function fh(t,e,n){let r=!1;for(let o=0,s=n.length-1;o<n.length;s=o,o+=1){const[a,i]=n[o],[u,c]=n[s];i>e!=c>e&&t<(u-a)*(e-i)/(c-i)+a&&(r=!r)}return r}function Ci(t,e,n,r,o=24){const s=n-t,a=r-e,i=Math.hypot(s,a),[u,c]=i===0?[1,0]:[s/i,a/i],f=n-u*o,d=r-c*o,h=-c,m=u,g=o/2;return[[n,r],[f+h*g,d+m*g],[f-h*g,d-m*g]]}function hh({compute:t,onCommit:e}){const[n,r]=p.useState(null),o=p.useCallback((s,a)=>{s.preventDefault();const i=c=>r(t(c,a)),u=c=>{document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",u),e(t(c,a)),r(null)};document.addEventListener("mousemove",i),document.addEventListener("mouseup",u)},[t,e]);return{dragValue:n,startDrag:o}}const qo=480,Go=320;function mh({strokes:t=[],shapes:e=[],width:n=qo,height:r=Go}={}){return function(s){return{block:{id:E(),type:"canvas",parentId:s,contentIds:[],props:{strokes:t,shapes:e,width:n,height:r}},runs:[]}}}const bh={diamond:vi,triangle:wi,star:Ii};function gh(t){const e=t.strokeWidth??8,n=Ee(t.color);if(t.type==="arrow"){const i=Math.max(16,e*3),c=Ci(t.x1,t.y1,t.x2,t.y2,i).map(([f,d])=>`${f},${d}`).join(" ");return`<line x1="${t.x1}" y1="${t.y1}" x2="${t.x2}" y2="${t.y2}" stroke="${n}" stroke-width="${e}"></line><polygon points="${c}" fill="${n}"></polygon>`}const r=t.fillColor?Ee(t.fillColor):"none";let o;if(t.type==="rectangle")o=`<rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" fill="${r}" stroke="${n}" stroke-width="${e}"></rect>`;else if(t.type==="ellipse"){const i=t.x+t.width/2,u=t.y+t.height/2;o=`<ellipse cx="${i}" cy="${u}" rx="${t.width/2}" ry="${t.height/2}" fill="${r}" stroke="${n}" stroke-width="${e}"></ellipse>`}else if(t.type==="text"){const i=t.fontSize??28,u=Et(t.text??"");o=`<foreignObject x="${t.x}" y="${t.y}" width="${t.width}" height="${t.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;">${u}</div></foreignObject>`}else{const i=bh[t.type];if(!i)return"";const u={x:t.x,y:t.y,width:t.width,height:t.height};o=`<polygon points="${i(u).map(([f,d])=>`${f},${d}`).join(" ")}" fill="${r}" stroke="${n}" stroke-width="${e}"></polygon>`}if(!t.rotation)return o;const s=t.x+t.width/2,a=t.y+t.height/2;return`<g transform="rotate(${t.rotation} ${s} ${a})">${o}</g>`}function Si(t){const{strokes:e=[],shapes:n=[],width:r,height:o}=t.props,s=e.map(i=>`<path fill="${Ee(i.color)}" d="${ar(i.points,{size:i.size})}"></path>`).join(""),a=n.map(gh).join("");return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000" width="${r}" height="${o}">${s}${a}</svg>`}const Tt=1e3,ta="#1a1a1a",Ri=8,na=["#1a1a1a","#e03131","#2f9e44","#1971c2","#f08c00"],xh=2,yh=40,kh=24,vh=6,ra=160,wh=120,Kr=.5,Wr=4,qn=1.1,oa=4,Gn=24,Ih=1,Ch=10,sa={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},Sh=220,Rh=60,ro=28,Th=12,jh=96,oo=10,aa=15,la=oo*5;function Ae(t){return Math.round(t/oo)*oo}function Eh(t){return Math.round(t/aa)*aa}function Bh(){const t=p.useRef(new WeakMap);return e=>{const n=t.current;let r=n.get(e);return r===void 0&&(r=ar(e.points,{size:e.size}),n.set(e,r)),r}}function _h(t,e,n){return{minX:t-n,minY:e-n,maxX:t+n,maxY:e+n}}function ia(t){let e=0,n=0;for(const o of t.values())e+=o.x,n+=o.y;const r=t.size||1;return{x:e/r,y:n/r}}function Oh(t,e,n,r){const o=t.points;if(o.length===1){const[s,a]=o[0];return Math.hypot(e-s,n-a)<=r}for(let s=0;s<o.length-1;s+=1){const[a,i]=o[s],[u,c]=o[s+1];if(ki(e,n,a,i,u,c,r))return!0}return!1}const Xr=new Set(["rectangle","ellipse","arrow","diamond","triangle","star"]),Ti={diamond:vi,triangle:wi,star:Ii},ca=[{type:"rectangle",label:"Rectangle",Icon:Ga},{type:"ellipse",label:"Ellipse",Icon:od},{type:"arrow",label:"Arrow",Icon:sd},{type:"diamond",label:"Diamond",Icon:ad},{type:"triangle",label:"Triangle",Icon:ld},{type:"star",label:"Star",Icon:id}],ua=[{mode:"object",label:"Object Eraser",Icon:Ja},{mode:"precise",label:"Precise Eraser",Icon:Ot}];function qr(t,e,n,r){return t.type==="arrow"?{type:"arrow",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,color:e,strokeWidth:n}:{type:t.type,...wn(t.x1,t.y1,t.x2,t.y2),color:e,strokeWidth:n,fillColor:r}}const Mh=16;function ji(t,e,n){for(let r=n.length-1;r>=0;r-=1){const o=n[r];if(o.type==="arrow"){if(ki(t,e,o.x1,o.y1,o.x2,o.y2,Mh))return o.id;continue}const s={x:o.x,y:o.y,width:o.width,height:o.height};let[a,i]=[t,e];if(o.rotation){const{cx:f,cy:d}=Rr(o);[a,i]=xi(t,e,f,d,-o.rotation)}const u=Ti[o.type];let c;if(u?c=fh(a,i,u(s)):c=o.type==="ellipse"?dh(a,i,s):yi(a,i,s),c)return o.id}return null}function xn(t,e,n){return t.type==="arrow"?{...t,x1:t.x1+e,y1:t.y1+n,x2:t.x2+e,y2:t.y2+n}:{...t,x:t.x+e,y:t.y+n}}function jn(t){return t.type==="arrow"?{x:Math.min(t.x1,t.x2),y:Math.min(t.y1,t.y2),width:Math.abs(t.x2-t.x1),height:Math.abs(t.y2-t.y1)}:{x:t.x,y:t.y,width:t.width,height:t.height}}function Rr(t){const e=jn(t);return{cx:e.x+e.width/2,cy:e.y+e.height/2}}function yn(t,e,n){return{...t,points:t.points.map(([r,o,s])=>[r+e,o+n,s])}}function Lh(t,e){const n=[];let r=[];for(let o=0;o<t.length;o+=1)e.has(o)?(r.length>0&&n.push(r),r=[]):r.push(t[o]);return r.length>0&&n.push(r),n}function Ei(t){const e=er(t.points);return{x:e.minX,y:e.minY,width:e.maxX-e.minX,height:e.maxY-e.minY}}function Nh(t,e){return t==="stroke"?Ei(e):jn(e)}function da(t,e){var a,i;const n=((a=t==null?void 0:t.props)==null?void 0:a.strokes)??[],r=((i=t==null?void 0:t.props)==null?void 0:i.shapes)??[],o=n.find(u=>u.id===e);if(o)return{kind:"stroke",item:o};const s=r.find(u=>u.id===e);return s?{kind:"shape",item:s}:null}function Ah(t,e,n,r){const o=ji(t,e,r);if(o)return{kind:"shape",id:o};for(let s=n.length-1;s>=0;s-=1){const a=n[s];if(yi(t,e,Ei(a)))return{kind:"stroke",id:a.id}}return null}const Jn=24,kn=14;function so(t){return{nw:[t.x,t.y],ne:[t.x+t.width,t.y],sw:[t.x,t.y+t.height],se:[t.x+t.width,t.y+t.height]}}const Dh={nw:"se",ne:"sw",sw:"ne",se:"nw"},Ph=32;function Bi(t){const e=jn(t),n=e.x+e.width/2,r=e.y-Ph;if(!t.rotation)return[n,r];const{cx:o,cy:s}=Rr(t);return xi(n,r,o,s,t.rotation)}function $h(t,e,n){if(!n)return null;if(n.type==="arrow")return Math.hypot(t-n.x1,e-n.y1)<=Jn?"start":Math.hypot(t-n.x2,e-n.y2)<=Jn?"end":null;const[r,o]=Bi(n);if(Math.hypot(t-r,e-o)<=Jn)return"rotate";if(n.rotation)return null;for(const[s,[a,i]]of Object.entries(so(n)))if(Math.hypot(t-a,e-i)<=Jn)return s;return null}function Gr(t,e){return e.mode==="arrow-endpoint"?e.endpoint==="start"?{...t,x1:e.x,y1:e.y}:{...t,x2:e.x,y2:e.y}:e.mode==="rotate"?{...t,rotation:e.rotation}:{...t,...wn(e.fixedX,e.fixedY,e.x,e.y)}}function pa({shape:t,opacity:e=1}){const n=t.strokeWidth??Ri;let r;if(t.type==="rectangle")r=l.jsx("rect",{x:t.x,y:t.y,width:t.width,height:t.height,fill:t.fillColor??"none",stroke:t.color,strokeWidth:n,opacity:e});else if(t.type==="ellipse")r=l.jsx("ellipse",{cx:t.x+t.width/2,cy:t.y+t.height/2,rx:t.width/2,ry:t.height/2,fill:t.fillColor??"none",stroke:t.color,strokeWidth:n,opacity:e});else if(t.type==="arrow"){const a=Math.max(16,n*3),i=Ci(t.x1,t.y1,t.x2,t.y2,a);return l.jsxs("g",{opacity:e,children:[l.jsx("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.color,strokeWidth:n}),l.jsx("polygon",{points:i.map(([u,c])=>`${u},${c}`).join(" "),fill:t.color})]})}else if(t.type==="text")r=l.jsx("foreignObject",{x:t.x,y:t.y,width:t.width,height:t.height,opacity:e,children:l.jsx("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{width:"100%",height:"100%",overflow:"hidden",color:t.color,fontSize:t.fontSize??ro,lineHeight:1.3,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"inherit"},children:t.text})});else{const a=Ti[t.type];if(!a)return null;const i={x:t.x,y:t.y,width:t.width,height:t.height},u=a(i).map(([c,f])=>`${c},${f}`).join(" ");r=l.jsx("polygon",{points:u,fill:t.fillColor??"none",stroke:t.color,strokeWidth:n,opacity:e})}if(!t.rotation)return r;const{cx:o,cy:s}=Rr(t);return l.jsx("g",{transform:`rotate(${t.rotation} ${o} ${s})`,children:r})}function zh({id:t}){const e=G(),n=be(t),r=Ie("be-canvas",n),o=Bh(),[s,a]=p.useState("pen"),[i,u]=p.useState("object"),[c,f]=p.useState(ta),[d,h]=p.useState(Ri),[m,g]=p.useState(null),[x,y]=p.useState(!0),[k,w]=p.useState(ro),[v,j]=p.useState("rectangle"),[I,C]=p.useState(!1),[T,M]=p.useState(!1),[B,L]=p.useState(!1),[S,N]=p.useState(!1),[$,V]=p.useState(!1),[K,Q]=p.useState(!1),D=p.useRef(null),F=p.useRef(null),re=p.useRef(null),H=p.useRef(null),ne=p.useRef(null),se=p.useRef(null),oe=p.useRef(null),ge=p.useRef(null),Te=p.useRef(null),ce=p.useRef(null),ke=p.useRef(null),he=p.useRef(null),U=p.useMemo(()=>[D,F],[]),ae=p.useMemo(()=>[re,H],[]),Ke=p.useMemo(()=>[ne,se],[]),An=p.useMemo(()=>[oe,ge],[]),jr=p.useMemo(()=>[Te,ce],[]),_c=p.useMemo(()=>[ke,he],[]),is=p.useCallback(()=>C(!1),[]),Er=p.useCallback(()=>M(!1),[]),Oc=p.useCallback(()=>L(!1),[]),cs=p.useCallback(()=>N(!1),[]),Mc=p.useCallback(()=>V(!1),[]),us=p.useCallback(()=>Q(!1),[]);Ue(U,I,is),Ue(ae,T,Er),Ue(Ke,B,Oc),Ue(An,S,cs),Ue(jr,$,Mc),Ue(_c,K,us);const We=p.useRef(null),fn=p.useRef([]),Lt=p.useRef(!1),Nt=p.useRef(null),[ds,ps]=p.useState(null),mt=p.useRef(new Set),Ct=p.useRef(new Set),At=p.useRef(new Map),Dt=p.useRef(!1),Pt=p.useRef(null),[Lc,fs]=p.useState(()=>new Set),[Nc,hs]=p.useState(()=>new Set),ze=p.useRef(null),[ms,Br]=p.useState(null),[le,rt]=p.useState(()=>new Set),bt=p.useRef(null),[we,bs]=p.useState(null),gt=p.useRef(null),[hn,gs]=p.useState(null),_r=p.useRef([]),[pe,$t]=p.useState(null),He=p.useRef(null),[xt,Or]=p.useState(null),[de,St]=p.useState({x:0,y:0,zoom:1}),Oe=Tt/de.zoom,Rt=p.useRef(null),Fe=p.useRef(new Map),yt=p.useRef(null),{dragValue:zt,startDrag:xs}=hh({compute:(b,R)=>({width:Math.max(ra,Math.round(R.startWidth+(b.clientX-R.startX))),height:Math.max(wh,Math.round(R.startHeight+(b.clientY-R.startY)))}),onCommit:b=>e.applyOperation(J(t,b))}),ys=p.useCallback(b=>{Nt.current==null&&(Nt.current=requestAnimationFrame(()=>{Nt.current=null,ps(ar(fn.current,{size:b}))}))},[]),Ht=p.useCallback(()=>{Lt.current=!1,Nt.current!=null&&(cancelAnimationFrame(Nt.current),Nt.current=null),fn.current=[],ps(null)},[]),ks=p.useCallback(()=>{var O;const b=fn.current;if(b.length===0)return;const R={id:E(),points:b,color:c,size:d},_=((O=n==null?void 0:n.props)==null?void 0:O.strokes)??[];e.applyOperation(J(t,{strokes:[..._,R]}))},[e,t,n,c,d]),vs=p.useCallback(()=>{Pt.current==null&&(Pt.current=requestAnimationFrame(()=>{Pt.current=null,fs(new Set(mt.current)),hs(new Set(Ct.current))}))},[]),Dn=p.useCallback((b,R)=>{var q,W;const _=i==="precise"?vh:kh,O=_h(b,R,_),P=((q=n==null?void 0:n.props)==null?void 0:q.strokes)??[];for(const z of P){if(i==="precise"){const ot=er(z.points);if(!gn(ot,O,z.size/2))continue;let Ce=At.current.get(z.id);z.points.forEach(([je,Se],fe)=>{Ce!=null&&Ce.has(fe)||Math.hypot(je-b,Se-R)>_||(Ce||(Ce=new Set,At.current.set(z.id,Ce)),Ce.add(fe))}),Ce!=null&&Ce.size&&mt.current.add(z.id);continue}if(mt.current.has(z.id))continue;const X=z.size/2,ie=er(z.points);gn(ie,O,X)&&Oh(z,b,R,_+X)&&mt.current.add(z.id)}const A=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[];for(const z of A){if(Ct.current.has(z.id))continue;const X=jn(z),ie={minX:X.x,minY:X.y,maxX:X.x+X.width,maxY:X.y+X.height};gn(ie,O)&&Ct.current.add(z.id)}vs()},[n,i,vs]),Ft=p.useCallback(()=>{Dt.current=!1,Pt.current!=null&&(cancelAnimationFrame(Pt.current),Pt.current=null),mt.current=new Set,Ct.current=new Set,At.current=new Map,fs(new Set),hs(new Set)},[]),ws=p.useCallback(()=>{var A,q;const b=i!=="precise"&&mt.current.size>0,R=i==="precise"&&At.current.size>0;if(!b&&!R&&Ct.current.size===0)return;const _=((A=n==null?void 0:n.props)==null?void 0:A.strokes)??[],O=((q=n==null?void 0:n.props)==null?void 0:q.shapes)??[];let P;if(b)P=_.filter(W=>!mt.current.has(W.id));else if(R){P=[];for(const W of _){const z=At.current.get(W.id);if(!z||z.size===0){P.push(W);continue}Lh(W.points,z).forEach((X,ie)=>{P.push({...W,id:ie===0?W.id:E(),points:X})})}}else P=_;e.applyOperation(J(t,{strokes:P,shapes:O.filter(W=>!Ct.current.has(W.id))}))},[e,t,n,i]),Ut=p.useCallback(()=>{ze.current=null,Br(null)},[]),Is=p.useCallback(()=>{var O;const b=ze.current;if(!b)return;if(b.type==="arrow"){if(b.x1===b.x2&&b.y1===b.y2)return}else{const P=wn(b.x1,b.y1,b.x2,b.y2);if(P.width===0||P.height===0)return}const R={id:E(),...qr(b,c,d,m)},_=((O=n==null?void 0:n.props)==null?void 0:O.shapes)??[];e.applyOperation(J(t,{shapes:[..._,R]}))},[e,t,n,c,d,m]),Vt=p.useCallback(()=>{bt.current=null,bs(null)},[]),Cs=p.useCallback(()=>{var q,W;const b=bt.current;if(!b||b.dx===0&&b.dy===0)return;const R=new Set(b.ids),_=((q=n==null?void 0:n.props)==null?void 0:q.strokes)??[],O=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[],P=_.map(z=>R.has(z.id)?yn(z,b.dx,b.dy):z),A=O.map(z=>R.has(z.id)?xn(z,b.dx,b.dy):z);e.applyOperation(J(t,{strokes:P,shapes:A}))},[e,t,n]),Yt=p.useCallback(()=>{gt.current=null,gs(null)},[]),Ss=p.useCallback(()=>{var q,W;const b=gt.current;if(!b)return;const R=wn(b.startX,b.startY,b.x,b.y);if(R.width<oa&&R.height<oa){rt(new Set);return}const _={minX:R.x,minY:R.y,maxX:R.x+R.width,maxY:R.y+R.height},O=((q=n==null?void 0:n.props)==null?void 0:q.strokes)??[],P=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[],A=[];for(const z of O)gn(er(z.points),_)&&A.push(z.id);for(const z of P){const X=jn(z),ie={minX:X.x,minY:X.y,maxX:X.x+X.width,maxY:X.y+X.height};gn(ie,_)&&A.push(z.id)}rt(new Set(A))},[n]),Mr=p.useCallback(()=>{le.size!==0&&(_r.current=[...le].map(b=>da(n,b)).filter(Boolean))},[n,le]),Lr=p.useCallback(()=>{var q,W;const b=_r.current;if(b.length===0)return;const R=((q=n==null?void 0:n.props)==null?void 0:q.strokes)??[],_=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[],O=[],P=[],A=[];for(const{kind:z,item:X}of b){const ie=E();A.push(ie),z==="stroke"?O.push({...yn(X,Gn,Gn),id:ie}):P.push({...xn(X,Gn,Gn),id:ie})}e.applyOperation(J(t,{strokes:[...R,...O],shapes:[..._,...P]})),rt(new Set(A)),a("select")},[e,t,n]),Kt=p.useCallback(b=>{var P,A;if(le.size===0)return;const R=q=>{const W=q.filter(X=>le.has(X.id));if(W.length===0)return q;const z=q.filter(X=>!le.has(X.id));return b?[...z,...W]:[...W,...z]},_=((P=n==null?void 0:n.props)==null?void 0:P.strokes)??[],O=((A=n==null?void 0:n.props)==null?void 0:A.shapes)??[];e.applyOperation(J(t,{strokes:R(_),shapes:R(O)}))},[e,t,n,le]),Ac=p.useCallback(()=>Kt(!0),[Kt]),Dc=p.useCallback(()=>Kt(!1),[Kt]),Nr=p.useCallback((b,R)=>{$t({id:null,x:b,y:R,width:Sh,height:Rh,text:"",color:c,fontSize:k})},[c,k]),Pn=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??ro})},[]),Pc=p.useCallback(()=>{$t(null)},[]),$c=p.useCallback(()=>{var q,W,z;const b=pe;if(!b)return;$t(null);const R=((q=n==null?void 0:n.props)==null?void 0:q.shapes)??[],_=b.text;if(!_.trim()){b.id&&(e.applyOperation(J(t,{shapes:R.filter(X=>X.id!==b.id)})),rt(new Set)),(W=We.current)==null||W.focus();return}const O=b.id??E(),P={id:O,type:"text",x:b.x,y:b.y,width:b.width,height:b.height,text:_,color:b.color,fontSize:b.fontSize},A=b.id?R.map(X=>X.id===b.id?P:X):[...R,P];e.applyOperation(J(t,{shapes:A})),rt(new Set([O])),a("select"),(z=We.current)==null||z.focus()},[e,t,n,pe]),Wt=p.useCallback(()=>{He.current=null,Or(null)},[]),Rs=p.useCallback(()=>{var A;const b=He.current;if(!b)return;const R=((A=n==null?void 0:n.props)==null?void 0:A.shapes)??[],_=R.find(q=>q.id===b.shapeId);if(!_)return;const O=Gr(_,b);if(O.type!=="arrow"&&(O.width===0||O.height===0))return;const P=R.map(q=>q.id===b.shapeId?O:q);e.applyOperation(J(t,{shapes:P}))},[e,t,n]),Ts=p.useCallback(b=>{var _;const R=We.current;if((_=R==null?void 0:R.hasPointerCapture)!=null&&_.call(R,b)&&R.releasePointerCapture(b),ze.current){Ut();return}if(bt.current){Vt();return}if(gt.current){Yt();return}if(He.current){Wt();return}if(Lt.current){Ht();return}Dt.current&&Ft()},[Ut,Vt,Yt,Wt,Ht,Ft]),zc=p.useCallback(b=>{var O,P,A,q,W;if(b.key==="Backspace"||b.key==="Delete"){if(le.size===0)return;b.preventDefault();const z=((O=n==null?void 0:n.props)==null?void 0:O.strokes)??[],X=((P=n==null?void 0:n.props)==null?void 0:P.shapes)??[];e.applyOperation(J(t,{strokes:z.filter(ie=>!le.has(ie.id)),shapes:X.filter(ie=>!le.has(ie.id))})),rt(new Set);return}if(sa[b.key]&&!b.ctrlKey&&!b.metaKey){if(le.size===0)return;b.preventDefault();const z=b.shiftKey?Ch:Ih,[X,ie]=sa[b.key],ot=X*z,Ce=ie*z,je=((A=n==null?void 0:n.props)==null?void 0:A.strokes)??[],Se=((q=n==null?void 0:n.props)==null?void 0:q.shapes)??[];e.applyOperation(J(t,{strokes:je.map(fe=>le.has(fe.id)?yn(fe,ot,Ce):fe),shapes:Se.map(fe=>le.has(fe.id)?xn(fe,ot,Ce):fe)}));return}if(b.key==="Enter"&&!b.ctrlKey&&!b.metaKey){if(le.size!==1)return;const[z]=le,X=(((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[]).find(ie=>ie.id===z&&ie.type==="text");if(!X)return;b.preventDefault(),Pn(X);return}if(!(b.ctrlKey||b.metaKey))return;const _=b.key.toLowerCase();if(_==="c"){if(le.size===0)return;b.preventDefault(),Mr()}else if(_==="v"){if(_r.current.length===0)return;b.preventDefault(),Lr()}else if(_==="d"){if(le.size===0)return;b.preventDefault(),Mr(),Lr()}else if(b.shiftKey&&(_==="]"||_==="[")){if(le.size===0)return;b.preventDefault(),Kt(_==="]")}},[e,t,n,le,Mr,Lr,Kt,Pn]),kt={x:de.x,y:de.y,size:Oe},Ar=p.useCallback(b=>{const R=We.current;if(!R)return;if(b.preventDefault(),b.ctrlKey||b.metaKey){St(O=>{const P=b.deltaY<0?qn:1/qn,A=Math.min(Wr,Math.max(Kr,O.zoom*P)),q=Tt/A,{x:W,y:z}=uh(b,R,{x:O.x,y:O.y,size:Tt/O.zoom},q);return{x:W,y:z,zoom:A}});return}const _=Yr(R,Oe);St(O=>({...O,x:O.x+b.deltaX/_,y:O.y+b.deltaY/_}))},[Oe]);p.useEffect(()=>{const b=We.current;if(b)return b.addEventListener("wheel",Ar,{passive:!1}),()=>b.removeEventListener("wheel",Ar)},[Ar]);const Hc=p.useCallback(()=>{St(b=>{const R=Math.min(Wr,b.zoom*qn),_=Tt/R,{x:O,y:P}=ea({x:b.x,y:b.y,size:Tt/b.zoom},_);return{x:O,y:P,zoom:R}})},[]),Fc=p.useCallback(()=>{St(b=>{const R=Math.max(Kr,b.zoom/qn),_=Tt/R,{x:O,y:P}=ea({x:b.x,y:b.y,size:Tt/b.zoom},_);return{x:O,y:P,zoom:R}})},[]),Uc=p.useCallback(()=>{St({x:0,y:0,zoom:1})},[]),Vc=p.useCallback(()=>{if(!n)return;const b=Si(n),R=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(b)}`,_=new Image;_.onload=()=>{const O=document.createElement("canvas");O.width=n.props.width,O.height=n.props.height;const P=O.getContext("2d");if(!P)return;P.drawImage(_,0,0,O.width,O.height);const A=document.createElement("a");A.href=O.toDataURL("image/png"),A.download="canvas.png",document.body.appendChild(A),A.click(),document.body.removeChild(A)},_.src=R},[n]),Yc=p.useCallback(b=>{var W;if(s!=="select")return;const R=We.current;if(!R)return;const[_,O]=qe(b,R,{x:de.x,y:de.y,size:Oe}),P=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[],A=ji(_,O,P),q=P.find(z=>z.id===A);(q==null?void 0:q.type)==="text"&&(rt(new Set([q.id])),Pn(q))},[s,de.x,de.y,Oe,n,Pn]),Kc=p.useCallback(b=>{var P,A,q,W,z,X,ie,ot,Ce;const R=We.current;if(!R)return;if(b.pointerType==="touch"&&(Fe.current.set(b.pointerId,{x:b.clientX,y:b.clientY}),Fe.current.size>=2)){if(b.preventDefault(),(P=R.setPointerCapture)==null||P.call(R,b.pointerId),!yt.current){for(const Se of Fe.current.keys())Se!==b.pointerId&&Ts(Se);const je=ia(Fe.current);yt.current={startCenterX:je.x,startCenterY:je.y,startViewX:de.x,startViewY:de.y}}return}if(pe){if((q=(A=b.target)==null?void 0:A.closest)!=null&&q.call(A,".be-canvas-text-editor"))return;if((z=(W=document.activeElement)==null?void 0:W.blur)==null||z.call(W),s==="text"){let[je,Se]=qe(b,R,kt);x&&([je,Se]=[Ae(je),Ae(Se)]),Nr(je,Se),a("text");return}}if(b.button===1){b.preventDefault(),(X=R.setPointerCapture)==null||X.call(R,b.pointerId),Rt.current={startClientX:b.clientX,startClientY:b.clientY,startViewX:de.x,startViewY:de.y};return}if(!b.isPrimary||b.button!==void 0&&b.button!==0)return;b.preventDefault(),(ie=R.setPointerCapture)==null||ie.call(R,b.pointerId);const[_,O]=qe(b,R,kt);if(s==="eraser")mt.current=new Set,Ct.current=new Set,At.current=new Map,Dt.current=!0,Dn(_,O);else if(Xr.has(s)){const je=x?Ae(_):_,Se=x?Ae(O):O;ze.current={type:s,x1:je,y1:Se,x2:je,y2:Se},Br(qr(ze.current,c,d,m))}else if(s==="select"){const je=((ot=n==null?void 0:n.props)==null?void 0:ot.strokes)??[],Se=((Ce=n==null?void 0:n.props)==null?void 0:Ce.shapes)??[],fe=le.size===1?Se.find(st=>le.has(st.id))??null:null,Hn=$h(_,O,fe);if(Hn){if(Hn==="rotate"){const{cx:st,cy:qt}=Rr(fe),Gt=Math.atan2(O-qt,_-st)*180/Math.PI;He.current={mode:"rotate",shapeId:fe.id,cx:st,cy:qt,startAngle:Gt,startRotation:fe.rotation??0,rotation:fe.rotation??0}}else if(fe.type==="arrow")He.current={mode:"arrow-endpoint",shapeId:fe.id,endpoint:Hn,x:_,y:O};else{const[st,qt]=so(fe)[Dh[Hn]];He.current={mode:"rect-corner",shapeId:fe.id,fixedX:st,fixedY:qt,x:_,y:O}}Or(Gr(fe,He.current));return}const Xt=Ah(_,O,je,Se);if(Xt){if(b.shiftKey){rt(qt=>{const Gt=new Set(qt);return Gt.has(Xt.id)?Gt.delete(Xt.id):Gt.add(Xt.id),Gt});return}const st=le.has(Xt.id)?le:new Set([Xt.id]);rt(st),bt.current={ids:[...st],startX:_,startY:O,dx:0,dy:0},R.focus()}else gt.current={startX:_,startY:O,x:_,y:O}}else s==="text"?Nr(x?Ae(_):_,x?Ae(O):O):s==="pen"&&(fn.current=[[_,O,b.pressure||.5]],Lt.current=!0)},[s,Dn,de.x,de.y,Oe,c,d,m,x,n,le,Nr,pe,Ts]),Wc=p.useCallback(b=>{var _;const R=We.current;if(R){if(b.pointerType==="touch"&&Fe.current.has(b.pointerId)&&(Fe.current.set(b.pointerId,{x:b.clientX,y:b.clientY}),yt.current)){b.preventDefault();const O=Yr(R,Oe),P=ia(Fe.current),{startCenterX:A,startCenterY:q,startViewX:W,startViewY:z}=yt.current,X=(P.x-A)/O,ie=(P.y-q)/O;St(ot=>({...ot,x:W-X,y:z-ie}));return}if(Rt.current){const O=Yr(R,Oe),{startClientX:P,startClientY:A,startViewX:q,startViewY:W}=Rt.current,z=(b.clientX-P)/O,X=(b.clientY-A)/O;St(ie=>({...ie,x:q-z,y:W-X}));return}if(ze.current){let[O,P]=qe(b,R,kt);x&&([O,P]=[Ae(O),Ae(P)]),ze.current={...ze.current,x2:O,y2:P},Br(qr(ze.current,c,d,m));return}if(bt.current){const[O,P]=qe(b,R,kt),A=bt.current;A.dx=x?Ae(O-A.startX):O-A.startX,A.dy=x?Ae(P-A.startY):P-A.startY,bs({ids:A.ids,dx:A.dx,dy:A.dy});return}if(gt.current){const[O,P]=qe(b,R,kt),A=gt.current;A.x=O,A.y=P,gs(wn(A.startX,A.startY,A.x,A.y));return}if(He.current){let[O,P]=qe(b,R,kt);const A=He.current;if(A.mode==="rotate"){const z=Math.atan2(P-A.cy,O-A.cx)*180/Math.PI,X=A.startRotation+(z-A.startAngle);A.rotation=x?Eh(X):X}else x&&([O,P]=[Ae(O),Ae(P)]),A.x=O,A.y=P;const W=(((_=n==null?void 0:n.props)==null?void 0:_.shapes)??[]).find(z=>z.id===A.shapeId);W&&Or(Gr(W,A));return}if(Lt.current){const[O,P]=qe(b,R,kt);fn.current.push([O,P,b.pressure||.5]),ys(d)}else if(Dt.current){const[O,P]=qe(b,R,kt);Dn(O,P)}}},[ys,Dn,de.x,de.y,Oe,d,c,m,x,n]),ve=p.useCallback(b=>{var _;const R=We.current;(_=R==null?void 0:R.hasPointerCapture)!=null&&_.call(R,b.pointerId)&&R.releasePointerCapture(b.pointerId)},[]),Xc=p.useCallback(b=>{if(b.pointerType==="touch"&&(Fe.current.delete(b.pointerId),yt.current)){ve(b),Fe.current.size<2&&(yt.current=null);return}if(Rt.current){ve(b),Rt.current=null;return}if(ze.current){ve(b),Is(),Ut();return}if(bt.current){ve(b),Cs(),Vt();return}if(gt.current){ve(b),Ss(),Yt();return}if(He.current){ve(b),Rs(),Wt();return}Lt.current?(ve(b),ks(),Ht()):Dt.current&&(ve(b),ws(),Ft())},[ve,Is,Ut,Cs,Vt,Ss,Yt,Rs,Wt,ks,Ht,ws,Ft]),qc=p.useCallback(b=>{if(b.pointerType==="touch"&&(Fe.current.delete(b.pointerId),yt.current)){ve(b),Fe.current.size<2&&(yt.current=null);return}if(Rt.current){ve(b),Rt.current=null;return}if(ze.current){ve(b),Ut();return}if(bt.current){ve(b),Vt();return}if(gt.current){ve(b),Yt();return}if(He.current){ve(b),Wt();return}Lt.current?(ve(b),Ht()):Dt.current&&(ve(b),Ft())},[ve,Ut,Vt,Yt,Wt,Ht,Ft]),Gc=p.useCallback(b=>{var R,_;xs(b,{startX:b.clientX,startY:b.clientY,startWidth:((R=n==null?void 0:n.props)==null?void 0:R.width)??qo,startHeight:((_=n==null?void 0:n.props)==null?void 0:_.height)??Go})},[xs,n]);if(!n)return null;const{strokes:js=[],shapes:Es=[],width:Jc,height:Zc}=n.props,Bs=(zt==null?void 0:zt.width)??Jc,Qc=(zt==null?void 0:zt.height)??Zc,$n=6,zn=[...le].map(b=>{var P;const R=da(n,b);if(!R)return null;let{kind:_,item:O}=R;return(P=we==null?void 0:we.ids)!=null&&P.includes(b)?O=_==="stroke"?yn(O,we.dx,we.dy):xn(O,we.dx,we.dy):_==="shape"&&(xt==null?void 0:xt.id)===b&&(O=xt),{id:b,kind:_,item:O,box:Nh(_,O),rotation:_==="shape"?O.rotation:0}}).filter(Boolean),Dr=zn.length===1&&zn[0].kind==="shape"?zn[0]:null,Ne=(Dr==null?void 0:Dr.item)??null,eu=Ne&&Ne.type==="arrow"?[["start",Ne.x1,Ne.y1],["end",Ne.x2,Ne.y2]]:Ne&&!Ne.rotation?Object.entries(so(Ne)).map(([b,[R,_]])=>[b,R,_]):[],Pr=Ne&&Ne.type!=="arrow"?Bi(Ne):null;return l.jsxs("div",{className:r,"data-block-id":t,"data-tool":s,contentEditable:!1,tabIndex:-1,children:[l.jsxs("div",{className:"be-canvas-toolbar",contentEditable:!1,children:[l.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:()=>a("pen"),children:l.jsx(Ya,{size:14})}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:ke,type:"button",className:`be-canvas-toolbar-btn${s==="eraser"?" be-canvas-toolbar-btn-active":""}`,"aria-haspopup":"true","aria-expanded":K,"aria-pressed":s==="eraser","aria-label":"Eraser",title:"Eraser",onClick:()=>Q(b=>!b),children:(()=>{var R;const b=((R=ua.find(_=>_.mode===i))==null?void 0:R.Icon)??Ja;return l.jsx(b,{size:14})})()}),K&&l.jsx("div",{ref:he,className:"be-canvas-picker be-canvas-shape-picker",role:"menu","aria-label":"Eraser",children:ua.map(({mode:b,label:R,Icon:_})=>l.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":R,title:R,onClick:()=>{a("eraser"),u(b),us()},children:l.jsx(_,{size:14})},b))})]}),l.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:()=>a("select"),children:l.jsx(cd,{size:14})}),l.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:()=>a("text"),children:l.jsx(Eo,{size:14})}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:Te,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":$,"aria-label":`Font size: ${pe?pe.fontSize:k}`,title:"Font size",onClick:()=>V(b=>!b),children:l.jsx("span",{className:"be-canvas-font-size-trigger",children:"A"})}),$&&l.jsxs("div",{ref:ce,className:"be-canvas-picker be-canvas-size-picker",role:"dialog","aria-label":"Font size",children:[l.jsx("span",{className:"be-canvas-size-preview","aria-hidden":"true",children:l.jsx("span",{className:"be-canvas-font-size-preview-letter",style:{fontSize:pe?pe.fontSize:k},children:"A"})}),l.jsx("input",{type:"range",className:"be-canvas-size-slider",min:Th,max:jh,value:pe?pe.fontSize:k,onChange:b=>{const R=Number(b.target.value);w(R),pe&&$t(_=>_&&{..._,fontSize:R})},"aria-label":"Font size"}),l.jsxs("span",{className:"be-canvas-size-value",children:[pe?pe.fontSize:k,"px"]})]})]}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Bring to front",title:"Bring to front",onClick:Ac,disabled:le.size===0,children:l.jsx(hr,{size:14})}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Send to back",title:"Send to back",onClick:Dc,disabled:le.size===0,children:l.jsx(mr,{size:14})}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:oe,type:"button",className:`be-canvas-toolbar-btn${Xr.has(s)?" be-canvas-toolbar-btn-active":""}`,"aria-haspopup":"true","aria-expanded":S,"aria-label":"Shape",title:"Shape",onClick:()=>N(b=>!b),children:(()=>{var R;const b=((R=ca.find(_=>_.type===(Xr.has(s)?s:v)))==null?void 0:R.Icon)??Ga;return l.jsx(b,{size:14})})()}),S&&l.jsx("div",{ref:ge,className:"be-canvas-picker be-canvas-shape-picker",role:"menu","aria-label":"Shape",children:ca.map(({type:b,label:R,Icon:_})=>l.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-btn${s===b?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s===b,"aria-label":R,title:R,onClick:()=>{a(b),j(b),cs()},children:l.jsx(_,{size:14})},b))})]}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:D,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":I,"aria-label":`Color: ${c}`,title:"Color",onClick:()=>C(b=>!b),children:l.jsx("span",{className:"be-canvas-color-trigger-dot",style:{backgroundColor:c}})}),I&&l.jsxs("div",{ref:F,className:"be-canvas-picker be-canvas-color-picker",role:"menu","aria-label":"Pen color",children:[na.map(b=>l.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-swatch${c===b?" be-canvas-toolbar-swatch-active":""}`,style:{backgroundColor:b},"aria-pressed":c===b,"aria-label":`Color ${b}`,title:`Color ${b}`,onClick:()=>{f(b),is()}},b)),l.jsx("label",{className:"be-canvas-custom-swatch",title:"Custom color","aria-label":"Custom color",children:l.jsx("input",{type:"color",value:c,onChange:b=>f(b.target.value)})})]})]}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:re,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":T,"aria-label":`Fill: ${m??"none"}`,title:"Fill",onClick:()=>M(b=>!b),children:l.jsx("span",{className:`be-canvas-fill-trigger-dot${m?"":" be-canvas-fill-trigger-dot-none"}`,style:m?{backgroundColor:m}:void 0})}),T&&l.jsxs("div",{ref:H,className:"be-canvas-picker be-canvas-color-picker",role:"menu","aria-label":"Shape fill",children:[l.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),Er()}}),na.map(b=>l.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),Er()}},b)),l.jsx("label",{className:"be-canvas-custom-swatch",title:"Custom fill","aria-label":"Custom fill",children:l.jsx("input",{type:"color",value:m??ta,onChange:b=>g(b.target.value)})})]})]}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:ne,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":B,"aria-label":`Stroke size: ${d}`,title:"Stroke size",onClick:()=>L(b=>!b),children:l.jsx("span",{className:"be-canvas-size-trigger-dot",style:{width:Math.min(d,16),height:Math.min(d,16)}})}),B&&l.jsxs("div",{ref:se,className:"be-canvas-picker be-canvas-size-picker",role:"dialog","aria-label":"Stroke size",children:[l.jsx("span",{className:"be-canvas-size-preview","aria-hidden":"true",children:l.jsx("span",{className:"be-canvas-size-preview-dot",style:{width:d,height:d}})}),l.jsx("input",{type:"range",className:"be-canvas-size-slider",min:xh,max:yh,value:d,onChange:b=>h(Number(b.target.value)),"aria-label":"Stroke size"}),l.jsxs("span",{className:"be-canvas-size-value",children:[d,"px"]})]})]}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.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:()=>y(b=>!b),children:l.jsx(dd,{size:14})}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Zoom out",title:"Zoom out",onClick:Fc,disabled:de.zoom<=Kr,children:"−"}),l.jsxs("button",{type:"button",className:"be-canvas-zoom-label","aria-label":`Zoom: ${Math.round(de.zoom*100)}%. Click to reset to 100%.`,title:"Reset zoom to 100%",onClick:Uc,children:[Math.round(de.zoom*100),"%"]}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Zoom in",title:"Zoom in",onClick:Hc,disabled:de.zoom>=Wr,children:"+"}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Export PNG",title:"Export as PNG",onClick:Vc,disabled:js.length===0&&Es.length===0,children:l.jsx(ud,{size:14})})]}),l.jsxs("svg",{ref:We,className:"be-canvas-surface",viewBox:`${de.x} ${de.y} ${Oe} ${Oe}`,width:Bs,height:Qc,tabIndex:-1,onPointerDown:Kc,onPointerMove:Wc,onPointerUp:Xc,onPointerCancel:qc,onDoubleClick:Yc,onKeyDown:zc,children:[x&&l.jsxs(l.Fragment,{children:[l.jsx("defs",{children:l.jsx("pattern",{id:`be-canvas-grid-${t}`,width:la,height:la,patternUnits:"userSpaceOnUse",children:l.jsx("circle",{cx:1,cy:1,r:1.5,className:"be-canvas-grid-dot"})})}),l.jsx("rect",{className:"be-canvas-grid-background",x:de.x,y:de.y,width:Oe,height:Oe,fill:`url(#be-canvas-grid-${t})`})]}),js.map(b=>{var O;const _=((O=we==null?void 0:we.ids)==null?void 0:O.includes(b.id))?ar(yn(b,we.dx,we.dy).points,{size:b.size}):o(b);return l.jsx("path",{d:_,fill:b.color,fillRule:"nonzero",opacity:Lc.has(b.id)?.25:1},b.id)}),ds&&l.jsx("path",{d:ds,fill:c,fillRule:"nonzero"}),Es.map(b=>{var _;let R=b;return(_=we==null?void 0:we.ids)!=null&&_.includes(b.id)?R=xn(b,we.dx,we.dy):(xt==null?void 0:xt.id)===b.id&&(R=xt),l.jsx(pa,{shape:R,opacity:Nc.has(b.id)?.25:1},b.id)}),ms&&l.jsx(pa,{shape:ms,opacity:.6}),zn.map(({id:b,box:R,rotation:_})=>l.jsx("g",{transform:_?`rotate(${_} ${R.x+R.width/2} ${R.y+R.height/2})`:void 0,children:l.jsx("rect",{className:"be-canvas-selection-box",x:R.x-$n,y:R.y-$n,width:R.width+$n*2,height:R.height+$n*2,fill:"none"})},b)),eu.map(([b,R,_])=>l.jsx("rect",{className:"be-canvas-selection-handle",x:R-kn/2,y:_-kn/2,width:kn,height:kn},b)),Pr&&l.jsx("circle",{className:"be-canvas-rotate-handle",cx:Pr[0],cy:Pr[1],r:kn/2}),hn&&l.jsx("rect",{className:"be-canvas-marquee",x:hn.x,y:hn.y,width:hn.width,height:hn.height}),pe&&l.jsx("foreignObject",{x:pe.x,y:pe.y,width:pe.width,height:pe.height,children:l.jsx("textarea",{xmlns:"http://www.w3.org/1999/xhtml",ref:b=>b==null?void 0:b.focus(),className:"be-canvas-text-editor",value:pe.text,style:{color:pe.color,fontSize:pe.fontSize},onChange:b=>$t(R=>R&&{...R,text:b.target.value}),onBlur:()=>$c(),onKeyDown:b=>{b.key==="Escape"&&(b.preventDefault(),Pc()),b.stopPropagation()}})})]}),l.jsx("div",{className:"be-canvas-resize-handle",onMouseDown:Gc,role:"slider","aria-label":"Resize canvas","aria-valuemin":ra,"aria-valuenow":Bs,contentEditable:!1})]})}function Hh(t){const{strokes:e=[],shapes:n=[]}=t.props;return!e.length&&!n.length?"<p></p>":Si(t)}function Fh(){return""}function Uh(){return null}function Vh(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o}){const s=t.getRun(n),a=(s==null?void 0:s.value)??"";t.applyOperation(ue(n,{value:a.slice(0,r)+a.slice(o)}));const i=yr(t,e,mh());return nt(t,i,te("paragraph")),i}const _i={component:zh,isLeaf:!0,defaultProps:{strokes:[],shapes:[],width:qo,height:Go},toHTML:Hh,toPlainText:Fh,fromHTML:Uh,slashCommand:{label:"Canvas",icon:Zu,keywords:["canvas","draw","drawing","sketch","freehand"],run:Vh}};function Oi(t){Mi(t,{paragraph:Il,heading:Cl,listItem:Ml,...Li,...Ni,divider:ei,callout:ni,blockquote:ri,code:si,toggleHeading:ai,button:ii,embed:pi,canvas:_i})}function Mi(t,e){for(const[n,r]of Object.entries(e))t.register(n,r)}const Li={table:ql,tableRow:Xl,tableCell:Wl},Ni={layout:Ql,layoutColumn:Zl};function Yh({id:t}){const e=G(),n=wt(t),r=p.useCallback(i=>{e.applyOperation(ue(t,{data:{...n==null?void 0:n.data,selectedValue:i}}))},[e,t,n==null?void 0:n.data]);if(!n)return null;const{options:o=[],selectedValue:s="",placeholder:a="Select…"}=n.data??{};return l.jsx("span",{className:"be-inline-select",onMouseDown:i=>{i.preventDefault(),i.stopPropagation()},onKeyDown:i=>i.stopPropagation(),children:l.jsx(Mt,{value:s,options:o,onChange:r,placeholder:a,ariaLabel:"Select an option"})})}function Tr(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},s){const a=t.getRun(n),i=(a==null?void 0:a.value)??"",u=i.slice(0,r),c=i.slice(o),f=s(),d={...a,value:u},h={id:E(),type:"text",value:c,marks:{...a==null?void 0:a.marks}};t.applyOperation(_t(e,[n],[d,f,h])),ye(h.id)}function Kh(t){return String(t).replace(/&/g,"&").replace(/"/g,""")}function Ai(t){var r;const{options:e=[],selectedValue:n=""}=t.data??{};return((r=e.find(o=>o.value===n))==null?void 0:r.label)??""}function Wh(t){var n,r;const e=Ai(t)||((n=t.data)==null?void 0:n.placeholder)||"";return`<span data-inline-type="select" data-selected-value="${Kh(((r=t.data)==null?void 0:r.selectedValue)??"")}">${e}</span>`}function Xh(t){return Ai(t)}function qh(t){var e;return((e=t.getAttribute)==null?void 0:e.call(t,"data-inline-type"))!=="select"?null:{id:E(),type:"select",value:"",marks:{},data:{options:[],selectedValue:t.getAttribute("data-selected-value")??""}}}const Di={component:Yh,isAtomic:!0,toHTML:Wh,toPlainText:Xh,fromHTML:qh,slashCommand:{label:"Select",icon:sl,keywords:["select","dropdown","choice","picker"],run:(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o})=>Tr(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},()=>({id:E(),type:"select",value:"",marks:{},data:{options:[],selectedValue:"",placeholder:"Select…"}}))}};function Gh({id:t}){const e=G(),n=wt(t),r=p.useCallback(s=>{e.applyOperation(ue(t,{data:{...n==null?void 0:n.data,isoDate:s.target.value}}))},[e,t,n==null?void 0:n.data]);if(!n)return null;const{isoDate:o=""}=n.data??{};return l.jsx("span",{className:"be-inline-date",onMouseDown:s=>s.stopPropagation(),onKeyDown:s=>s.stopPropagation(),children:l.jsx("input",{type:"date",value:o,onChange:r})})}function Jh(t){return String(t).replace(/&/g,"&").replace(/"/g,""")}function Pi(t){if(!t)return"";const e=new Date(`${t}T00:00:00`);return Number.isNaN(e.getTime())?t:e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Zh(t){var n;const e=((n=t.data)==null?void 0:n.isoDate)??"";return`<span data-inline-type="date" data-iso-date="${Jh(e)}">${Pi(e)}</span>`}function Qh(t){var e;return Pi(((e=t.data)==null?void 0:e.isoDate)??"")}function em(t){var e;return((e=t.getAttribute)==null?void 0:e.call(t,"data-inline-type"))!=="date"?null:{id:E(),type:"date",value:"",marks:{},data:{isoDate:t.getAttribute("data-iso-date")??""}}}function tm(){return new Date().toISOString().slice(0,10)}const $i={component:Gh,isAtomic:!0,toHTML:Zh,toPlainText:Qh,fromHTML:em,slashCommand:{label:"Date",icon:gd,keywords:["date","when","schedule","calendar"],run:(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o})=>Tr(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},()=>({id:E(),type:"date",value:"",marks:{},data:{isoDate:tm()}}))}};function nm({id:t}){const e=G(),n=wt(t),r=p.useCallback(i=>{e.applyOperation(ue(t,{data:{...n==null?void 0:n.data,checked:i.target.checked}}))},[e,t,n==null?void 0:n.data]),o=p.useCallback(i=>{e.applyOperation(ue(t,{data:{...n==null?void 0:n.data,label:i.target.value}}))},[e,t,n==null?void 0:n.data]);if(!n)return null;const{checked:s=!1,label:a=""}=n.data??{};return l.jsxs("span",{className:"be-inline-checkbox",onMouseDown:i=>i.stopPropagation(),onKeyDown:i=>i.stopPropagation(),children:[l.jsx("input",{type:"checkbox",className:"be-inline-checkbox-input",checked:s,onChange:r}),l.jsx("input",{type:"text",className:"be-inline-checkbox-label",value:a,onChange:o,placeholder:"Label…"})]})}function rm(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function om(t){const{checked:e=!1,label:n=""}=t.data??{};return`<span data-inline-type="checkbox" data-checked="${e}">${e?"☑":"☐"} ${rm(n)}</span>`}function sm(t){const{checked:e=!1,label:n=""}=t.data??{};return`${e?"[x]":"[ ]"} ${n}`.trim()}function am(t){var e;return((e=t.getAttribute)==null?void 0:e.call(t,"data-inline-type"))!=="checkbox"?null:{id:E(),type:"checkbox",value:"",marks:{},data:{checked:t.getAttribute("data-checked")==="true",label:(t.textContent??"").replace(/^[☑☐]\s*/,"")}}}const zi={component:nm,isAtomic:!0,toHTML:om,toPlainText:sm,fromHTML:am,slashCommand:{label:"Checkbox",icon:Oo,keywords:["checkbox","todo","check","toggle"],run:(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o})=>Tr(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},()=>({id:E(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}}))}};function lm({id:t,blockId:e}){var m;const n=G(),r=wt(t),o=e?n.getBlock(e):null,s=o?n.getBlock(o.parentId):null,a=(s==null?void 0:s.parentId)??null,i=be(a),u=s?s.contentIds.indexOf(e):-1,f=(((m=(i&&s?$e(i,s.contentIds.length):[])[u])==null?void 0:m.options)??[]).map((g,x)=>({...g,color:g.color??Tn(x)})),d=p.useCallback((g,x)=>{n.applyOperation(ue(t,{data:{selectedValue:g,selectedLabel:(x==null?void 0:x.label)??""}}))},[n,t]);if(!r)return null;const{selectedValue:h=""}=r.data??{};return l.jsx("span",{className:"be-inline-table-select",onMouseDown:g=>{g.preventDefault(),g.stopPropagation()},onKeyDown:g=>g.stopPropagation(),children:l.jsx(Mt,{value:h,options:f,onChange:d,placeholder:"Select…",ariaLabel:"Select an option",variant:"tag"})})}function Hi(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function im(t){return Hi(t).replace(/"/g,""")}function cm(t){const{selectedValue:e="",selectedLabel:n=""}=t.data??{};return`<span data-inline-type="tableSelect" data-selected-value="${im(e)}">${Hi(n)}</span>`}function um(t){var e;return((e=t.data)==null?void 0:e.selectedLabel)??""}function dm(t){var e;return((e=t.getAttribute)==null?void 0:e.call(t,"data-inline-type"))!=="tableSelect"?null:{id:E(),type:"tableSelect",value:"",marks:{},data:{selectedValue:t.getAttribute("data-selected-value")??"",selectedLabel:t.textContent??""}}}const Fi={component:lm,isAtomic:!0,toHTML:cm,toPlainText:um,fromHTML:dm},Ui={};function Vi(t){Yi(t,{select:Di,date:$i,checkbox:zi,...Ki,emoji:Ui})}function Yi(t,e){for(const[n,r]of Object.entries(e))t.register(n,r)}const Ki={tableSelect:Fi};function pm(){const t="root",e=E(),n=E();return{rootId:t,blocks:[{id:t,type:"page",parentId:null,contentIds:[e],props:{}},{id:e,type:"paragraph",parentId:t,contentIds:[n],props:{}}],runs:[{id:n,type:"text",value:"",marks:{}}]}}function fm({doc:t,history:e=!0,registerBlocks:n,registerInlineTypes:r}={}){return p.useMemo(()=>{const o=cl();(n??Oi)(o);const s=dl();(r??Vi)(s);const a=new ur(t??pm());return{store:e?new ka(a):a,registry:o,inlineRegistry:s}},[])}function Wi({minHeight:t=180,className:e="be-trailing-space"}){const n=G(),[r]=Co(),o=p.useCallback(()=>{var c;if(r)return;const s=n.getRootId(),a=n.getBlock(s),i=(c=a==null?void 0:a.contentIds)==null?void 0:c[a.contentIds.length-1];if(!i){const f=un(n);f&&Ys(n,f);return}const u=n.getBlock(i);(u==null?void 0:u.type)==="paragraph"?Ys(n,i):nt(n,i,te("paragraph"))},[n,r]);return l.jsx("div",{className:e,style:{minHeight:t},onClick:o})}async function ao(t,e,n,r){var a,i,u;const{html:o,text:s}=En(t,e,r,n);if(typeof ClipboardItem<"u"&&((a=navigator.clipboard)!=null&&a.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((u=(i=navigator.clipboard)==null?void 0:i.writeText)==null?void 0:u.call(i,s))}function Jo(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function In(t,e){e.length!==0&&Jo(t,e.map(n=>ee(n)))}function Xi(t,e){if(e.length===0)return!1;const n=t.getBlock(e[0]);if(!n)return!1;const r=t.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(e[0]),s=r.contentIds.indexOf(e[e.length-1]);if(o<=0)return!1;const a=r.contentIds[o-1];return t.applyOperation(ct(a,n.parentId,s)),!0}function qi(t,e){if(e.length===0)return!1;const n=t.getBlock(e[0]);if(!n)return!1;const r=t.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(e[0]),s=r.contentIds.indexOf(e[e.length-1]);if(s===-1||s>=r.contentIds.length-1)return!1;const a=r.contentIds[s+1];return t.applyOperation(ct(a,n.parentId,o)),!0}function Gi(t,e){return e.length>0&&e.every(n=>{var r,o;return!!((o=(r=t.getBlock(n))==null?void 0:r.props)!=null&&o.hidden)})}function Ji(t,e,n){e.length!==0&&Jo(t,e.map(r=>J(r,{hidden:n})))}function hm(t,e,n,r){const o=n.filter(a=>{var i;return Ho((i=t.getBlock(a))==null?void 0:i.type)});if(o.length===0)return;const s=o.flatMap(a=>jl(t,e,a,r).ops);Jo(t,s)}function mm(t,e){if(e.length===0)return[];const n=t.getBlock(e[0]),r=n&&t.getBlock(n.parentId);if(!r)return e;const o=new Set(e);return r.contentIds.filter(s=>o.has(s))}function Zi(){const t=G(),e=vt(),n=tt(),[r,o]=_n(),[s,a]=p.useState(null),i=p.useRef(null),u=p.useRef(null),c=r.length>0,f=Ln(i,c,(s==null?void 0:s.bottom)!=null?s.bottom+4:null,s==null?void 0:s.left),d=p.useCallback(()=>o([]),[o]);kr(i,c,d,void 0),p.useEffect(()=>{if(!c){a(null);return}const C=()=>{const T=r[r.length-1],M=document.querySelector(`[data-block-row-id="${T}"]`);a((M==null?void 0:M.getBoundingClientRect())??null)};return C(),window.addEventListener("scroll",C,!0),window.addEventListener("resize",C),()=>{window.removeEventListener("scroll",C,!0),window.removeEventListener("resize",C)}},[c,r]),p.useEffect(()=>{if(!c)return;const C=M=>{var B,L,S,N;(B=i.current)!=null&&B.contains(M.target)||(L=u.current)!=null&&L.contains(M.target)||(N=(S=M.target).closest)!=null&&N.call(S,".be-block-gutter")||d()},T=M=>{M.key==="Escape"?d():(M.key==="Delete"||M.key==="Backspace")&&(M.preventDefault(),In(t,r),d())};return document.addEventListener("mousedown",C),document.addEventListener("keydown",T),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("keydown",T)}},[c,t,r,d]);const h=C=>C===1?"block":"blocks",m=p.useCallback(()=>{ao(t,e,n,r),xe(`${r.length} ${h(r.length)} copied`),d()},[t,e,n,r,d]),g=p.useCallback(async()=>{await ao(t,e,n,r);const C=r.length;In(t,r),xe(`${C} ${h(C)} cut`),d()},[t,e,n,r,d]),x=p.useCallback(()=>{const C=r.length;In(t,r),xe(`${C} ${h(C)} deleted`),d()},[t,r,d]),y=p.useCallback(()=>{Xi(t,r)&&xe(`${r.length} ${h(r.length)} moved up`),d()},[t,r,d]),k=p.useCallback(()=>{qi(t,r)&&xe(`${r.length} ${h(r.length)} moved down`),d()},[t,r,d]),w=Gi(t,r),v=p.useCallback(()=>{Ji(t,r,!w),xe(w?`${r.length} ${h(r.length)} shown in preview`:`${r.length} ${h(r.length)} hidden in preview`),d()},[t,r,w,d]),j=r.some(C=>{var T;return Ho((T=t.getBlock(C))==null?void 0:T.type)}),I=p.useCallback(C=>{const T=r.length;hm(t,e,r,C),xe(`${T} ${h(T)} turned into ${C.label}`),d()},[t,e,r,d]);return!c||!f?null:Ve.createPortal(l.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:[l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:m,children:[l.jsx(jo,{size:15})," Copy"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:g,children:[l.jsx(pd,{size:15})," Cut"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:y,children:[l.jsx(hr,{size:15})," Move up"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:k,children:[l.jsx(mr,{size:15})," Move down"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:v,children:[w?l.jsx(Mo,{size:15}):l.jsx(Lo,{size:15}),w?"Show in preview":"Hide in preview"]}),j&&l.jsx(El,{onSelect:I,onClose:()=>{},containerRef:u,menuClassName:"be-block-range-menu",itemClassName:"be-block-range-menu-item"}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item be-block-range-menu-item-danger",onClick:x,children:[l.jsx(On,{size:15})," Delete"]})]}),document.body)}const lr="application/x-block-editor-blocks+json";function Zo(t){return t.split(/\r\n|\r|\n/).filter(e=>e.length>0).map(e=>{const n=E();return{block:{id:E(),type:"paragraph",parentId:null,contentIds:[n],props:{}},runs:[{id:n,type:"text",value:e,marks:{}}]}})}function Qi(t,e,n){const r=new DOMParser().parseFromString(t,"text/html"),o={registry:e,inlineRegistry:n},s=e.listHtmlMatchers(),a=[],i=c=>{var h;const f=c.tagName==="OL",d=[];for(const m of c.children){if(m.tagName!=="LI")continue;const g=(h=e.get("listItem"))==null?void 0:h.fromHTML(m,o);g&&(g.block.props.ordered=f,d.push(g))}return d},u=c=>{var d;const f=Array.from(c.children).filter(h=>h.tagName==="P");if(f.length===0){const h=(d=e.get("blockquote"))==null?void 0:d.fromHTML(c,o);return h?[h]:[]}return f.map(h=>{const m=Ye(h,o);return{block:{id:E(),type:"blockquote",parentId:null,contentIds:m.map(g=>g.id),props:{}},runs:m}})};for(const c of r.body.childNodes){if(c.nodeType===3){const d=c.textContent.trim();d&&a.push(...Zo(d));continue}if(c.nodeType!==1)continue;if(c.tagName==="UL"||c.tagName==="OL"){a.push(...i(c));continue}if(c.tagName==="BLOCKQUOTE"){a.push(...u(c));continue}let f=null;for(const d of s){const h=d.fromHTML(c,o);if(h){f=h;break}}if(f)a.push(f);else if(c.textContent.trim()){const d=Ye(c,o);a.push({block:{id:E(),type:"paragraph",parentId:null,contentIds:d.map(h=>h.id),props:{}},runs:d})}}return a}function ec(t,e,n){const r=t.types??[];if(r.includes(lr)){const s=t.getData(lr);if(s)return bm(s)}if(r.includes("text/html")){const s=t.getData("text/html");if(s)return Qi(s,e,n)}const o=t.getData("text/plain")??"";return Zo(o)}function bm(t){return JSON.parse(t).blocks.map(n=>dr(n))}function lo(t,e){var r;const n=t.getBlock(e);return((r=n.props)==null?void 0:r.titleRunIds)??n.contentIds}function tr(){return{id:E(),type:"text",value:"",marks:{}}}function io(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Qo(t,e,n){const{startRunId:r,startOffset:o,endRunId:s,endOffset:a}=n,i=lo(t,e),u=i.indexOf(r),c=i.indexOf(s);if(u===-1||c===-1)return null;const[f,d]=u<=c?[u,c]:[c,u],h=u<=c?o:a,m=u<=c?a:o,g=i.slice(0,f).map(I=>t.getRun(I)),x=i.slice(d+1).map(I=>t.getRun(I)),y=i.slice(f,d+1).map(I=>t.getRun(I)),k=[];let w=null,v=0;if(f===d){const I=y[0];if(I.type==="text"){const C=Math.max(0,Math.min(h,m)),T=Math.min(I.value.length,Math.max(h,m)),M={...I,value:I.value.slice(0,C)+I.value.slice(T)};k.push(M),w=M.id,v=C}}else y.forEach((I,C)=>{if(I.type!=="text")return;const T=C===0,M=C===y.length-1,B=T?I.value.slice(0,h):"";if(T&&B){const L={...I,value:B};k.push(L),w=L.id,v=B.length}if(M&&!T){const L=I.value.slice(m);if(L){const S={id:E(),type:"text",value:L,marks:I.marks};k.push(S),w===null&&(w=S.id,v=0)}}});let j=[...g,...k,...x];if(j.length===0){const I=tr();j=[I],w=I.id,v=0}else if(w===null){const I=g[g.length-1];I?(w=I.id,v=I.type==="text"?I.value.length:0):x[0]&&(w=x[0].id,v=0)}return t.applyOperation(Me(e,j)),{blockId:e,runId:w,offset:v}}function es(t,e){const{blockIds:n,startBlockId:r,startRunId:o,startOffset:s,endBlockId:a,endRunId:i,endOffset:u}=e;if(!n||n.length===0)return null;const c=n.indexOf(r),f=n.indexOf(a);if(c===-1||f===-1)return null;const[d,h]=c<=f?[c,f]:[f,c],m=c<=f,g=m?o:i,x=m?s:u,y=m?i:o,k=m?u:s;if(d===h)return Qo(t,n[d],{startRunId:g,startOffset:x,endRunId:y,endOffset:k});const w=n[d],v=n[h],j=t.getBlock(w),I=t.getBlock(v),C=lo(t,w),T=C.indexOf(g),M=C.slice(0,T).map(ce=>t.getRun(ce)),B=t.getRun(g),L=B.type==="text"&&x>0?{...B,value:B.value.slice(0,x)}:null,S=lo(t,v),N=S.indexOf(y),$=S.slice(N+1).map(ce=>t.getRun(ce)),V=t.getRun(y),K=V.type==="text"&&k<V.value.length?{id:E(),type:"text",value:V.value.slice(k),marks:V.marks}:null,Q=[...M,...L?[L]:[]],D=[...K?[K]:[],...$],F=[];for(let ce=d+1;ce<h;ce+=1)F.push(ee(n[ce]));const re=wl(j.type,I.type),H=t.getBlock(j.parentId),ne=h-d-1+(re?1:0),se=H&&H.contentIds.length-ne===1;let oe,ge,Te;if(re){const ce=[...Q,...D];if(ce.length===0&&se&&j.type!=="paragraph"){const{block:he,runs:U}=te("paragraph")(H.id);return F.push({type:"insertBlock",block:he,parentId:H.id,index:0,subtree:{blocks:[he],runs:U}}),F.push(ee(w)),F.push(ee(v)),io(t,F),{blockId:he.id,runId:he.contentIds[0],offset:0}}const ke=ce.length?ce:[tr()];if(F.push(Me(w,ke)),F.push(ee(v)),Te=w,L)oe=L.id,ge=L.value.length;else if(M.length){const he=M[M.length-1];oe=he.id,ge=he.type==="text"?he.value.length:0}else K?(oe=K.id,ge=0):$.length?(oe=$[0].id,ge=0):(oe=ke[0].id,ge=0)}else{const ce=Q.length?Q:[tr()];if(F.push(Me(w,ce)),F.push(Me(v,D.length?D:[tr()])),Te=w,L)oe=L.id,ge=L.value.length;else if(M.length){const ke=M[M.length-1];oe=ke.id,ge=ke.type==="text"?ke.value.length:0}else oe=ce[0].id,ge=0}return io(t,F),{blockId:Te,runId:oe,offset:ge}}function ir(t,e=""){var i;const n=t.getRootId(),r=((i=t.getBlock(n))==null?void 0:i.contentIds)??[];if(r.length===0)return null;const o=r.map(u=>ee(u)),{block:s,runs:a}=te("paragraph")(n);return e&&(a[0].value=e),o.push(me(s,n,0,{blocks:[s],runs:a})),io(t,o),{blockId:s.id,runId:s.contentIds[0],offset:e.length}}function co(t){var n;let e=(t==null?void 0:t.nodeType)===1?t:t==null?void 0:t.parentElement;for(;e&&typeof e.hasAttribute=="function"&&!e.hasAttribute("data-block-id");)e=e.parentElement;return((n=e==null?void 0:e.getAttribute)==null?void 0:n.call(e,"data-block-id"))??null}function gm(t){var d;const e=(d=window.getSelection)==null?void 0:d.call(window);if(!e||e.rangeCount===0)return[];const n=co(e.anchorNode),r=co(e.focusNode);if(!n)return[];if(!r||n===r)return[n];const o=t.getBlock(n),s=o&&t.getBlock(o.parentId);if(!s)return[n];const a=s.contentIds,i=a.indexOf(n),u=a.indexOf(r);if(i===-1||u===-1)return[n];const[c,f]=i<=u?[i,u]:[u,i];return a.slice(c,f+1)}function fa(t){const e=ln();if(e)return Qo(t,e.blockId,e);const n=rn(t);return n?es(t,n):null}function xm(t,e,n){const r=t.getRun(e.runId);if(!r||r.type!=="text")return null;const o=r.value??"",s=o.slice(0,e.offset)+n+o.slice(e.offset);return t.applyOperation(ue(r.id,{value:s})),{blockId:e.blockId,runId:r.id,offset:e.offset+n.length}}function Jr(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function tc(){const t=G(),e=vt(),n=tt(),[r,o]=Io(),[s,a]=_n(),i=p.useCallback(f=>{var x;const d=r?((x=t.getBlock(t.getRootId()))==null?void 0:x.contentIds)??[]:s.length>0?s:gm(t);if(d.length===0)return;const{html:h,text:m,json:g}=En(t,e,d,n);f.clipboardData.setData("text/plain",m),f.clipboardData.setData("text/html",h),f.clipboardData.setData(lr,g),f.preventDefault()},[t,e,n,r,s]),u=p.useCallback(f=>{if(i(f),r){const h=ir(t);o(!1),h!=null&&h.runId&&Je(h.runId,h.offset);return}if(s.length>0){In(t,s),a([]);return}const d=fa(t);d!=null&&d.runId&&Je(d.runId,d.offset)},[i,t,r,o,s,a]),c=p.useCallback(f=>{var v,j,I;const d=ec(f.clipboardData,e,n);if(d.length===0)return;if(r){const C=t.getRootId(),M=(((v=t.getBlock(C))==null?void 0:v.contentIds)??[]).map(L=>ee(L));let B=0;for(const{block:L,runs:S,subtreeBlocks:N=[]}of d)L.parentId=C,M.push(me(L,C,B,{blocks:[L,...N],runs:S})),B+=1;Jr(t,M),o(!1),f.preventDefault();return}if(s.length>0){const C=t.getBlock(s[0]),T=(C==null?void 0:C.parentId)??null,M=T&&t.getBlock(T);let B=M?M.contentIds.indexOf(s[0]):0;const L=s.map(S=>ee(S));for(const{block:S,runs:N,subtreeBlocks:$=[]}of d)S.parentId=T,L.push(me(S,T,B,{blocks:[S,...$],runs:N})),B+=1;Jr(t,L),a([]),f.preventDefault();return}const h=fa(t);if(d.length===1&&d[0].runs.every(C=>C.type==="text")&&(d[0].subtreeBlocks??[]).length===0){const C=h?{blockId:h.blockId,runId:h.runId,offset:h.offset}:lt();if(C){const T=d[0].runs.map(B=>B.value).join(""),M=xm(t,C,T);if(M){Je(M.runId,M.offset),f.preventDefault();return}}}const g=(h==null?void 0:h.blockId)??co((I=(j=window.getSelection)==null?void 0:j.call(window))==null?void 0:I.anchorNode);if(!g)return;const x=t.getBlock(g);if(!x)return;let k=t.getBlock(x.parentId).contentIds.indexOf(g)+1;const w=[];for(const{block:C,runs:T,subtreeBlocks:M=[]}of d)C.parentId=x.parentId,w.push(me(C,x.parentId,k,{blocks:[C,...M],runs:T})),k+=1;Jr(t,w),f.preventDefault()},[t,e,n,r,o,s,a]);return{onCopy:i,onCut:u,onPaste:c}}const ym=["bold","italic","underline","strike","subscript","superscript","code"],km=["color","highlight","link"];function on(t,e){var r;const n=t.getBlock(e);return((r=n.props)==null?void 0:r.titleRunIds)??n.contentIds}function vm(t,e){return t===e?!0:t&&e&&typeof t=="object"?JSON.stringify(t)===JSON.stringify(e):!1}function nc(t){var n;const e={};if(t.length===0)return e;for(const r of ym)e[r]=t.every(o=>{var s;return(s=o.marks)==null?void 0:s[r]});for(const r of km){const o=((n=t[0].marks)==null?void 0:n[r])??null;e[r]=t.every(s=>{var a;return vm(((a=s.marks)==null?void 0:a[r])??null,o)})?o:null}return e}function ts(t,e,n){const{startRunId:r,startOffset:o,endRunId:s,endOffset:a}=n,i=on(t,e),u=i.indexOf(r),c=i.indexOf(s);if(u===-1||c===-1)return{};const[f,d]=u<=c?[u,c]:[c,u],h=i.slice(f,d+1).map(m=>t.getRun(m)).filter(m=>m&&m.type==="text");return nc(h)}function ns(t,e){const{blockIds:n,startBlockId:r,endBlockId:o}=e,s=n.indexOf(r),a=n.indexOf(o);if(s===-1||a===-1)return{};const[i,u]=s<=a?[s,a]:[a,s],c=[];for(let f=i;f<=u;f+=1)for(const d of on(t,n[f])){const h=t.getRun(d);h&&h.type==="text"&&c.push(h)}return nc(c)}function rc(t,e){const n={...t};for(const[r,o]of Object.entries(e))o!=null?n[r]=o:delete n[r];return n}function oc(t,e,n,r,o,s){const a=rc(n.marks,s);if(r===0&&o===n.value.length)return t.applyOperation({type:"updateRun",id:n.id,patch:{marks:a}}),n.id;const i=n.value.slice(0,r),u=n.value.slice(r,o),c=n.value.slice(o),f=[];i&&f.push({id:E(),type:"text",value:i,marks:{...n.marks}});const d={id:E(),type:"text",value:u,marks:a};return f.push(d),c&&f.push({id:E(),type:"text",value:c,marks:{...n.marks}}),t.applyOperation(_t(e,[n.id],f)),d.id}function wm(t,e,n,r){const{startRunId:o,startOffset:s,endRunId:a,endOffset:i}=n,u=on(t,e),c=u.indexOf(o),f=u.indexOf(a);if(c===-1||f===-1)return null;const[d,h]=c<=f?[c,f]:[f,c],m=c<=f?s:i,g=c<=f?i:s,x=u.slice(d,h+1),y=x.map(v=>t.getRun(v));if(d===h){const v=y[0];if(v.type!=="text")return v.id;const j=Math.max(0,Math.min(m,g)),I=Math.min(v.value.length,Math.max(m,g));return j===I?v.id:oc(t,e,v,j,I,r)}const k=[];let w=null;return y.forEach((v,j)=>{if(v.type!=="text"){k.push(v),w=v.id;return}const I=j===0,C=j===y.length-1,T=I?m:0,M=C?g:v.value.length,B=v.value.slice(0,T),L=v.value.slice(T,M),S=v.value.slice(M);B&&k.push({id:E(),type:"text",value:B,marks:{...v.marks}});const N={id:E(),type:"text",value:L,marks:rc(v.marks,r)};k.push(N),w=N.id,S&&k.push({id:E(),type:"text",value:S,marks:{...v.marks}})}),t.applyOperation(_t(e,x,k)),w}function Im(t,e,n,r){var g;const{startRunId:o,startOffset:s,endRunId:a,endOffset:i}=n,u=on(t,e),c=u.indexOf(o),f=u.indexOf(a);if(c===-1||f===-1)return!0;const[d,h]=c<=f?[c,f]:[f,c],m=u.slice(d,h+1).map(x=>t.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)),y=Math.min(m[0].value.length,Math.max(s,i));if(x===y)return!((g=m[0].marks)!=null&&g[r])}return!m.every(x=>{var y;return(y=x.marks)==null?void 0:y[r]})}function Cm(t,e,n,r,o,s){var d;const a=t.getRun(n),i=a.value??"",u=Math.max(0,Math.min(r,o)),c=Math.min(i.length,Math.max(r,o));if(u===c)return n;const f=!((d=a.marks)!=null&&d[s]);return oc(t,e,a,u,c,{[s]:f?!0:null})}function sn(t,e,n,r){return wm(t,e,n,r)}function rs(t,e,n,r){const o=Im(t,e,n,r);return sn(t,e,n,{[r]:o?!0:null})}function os(t,e,n){return cr(t,e,r=>({[n]:r?null:!0}),n)}function cr(t,e,n,r){var C;const{blockIds:o,startBlockId:s,startRunId:a,startOffset:i,endBlockId:u,endRunId:c,endOffset:f}=e;if(!o||o.length===0)return null;const d=o.indexOf(s),h=o.indexOf(u);if(d===-1||h===-1)return null;const[m,g]=d<=h?[d,h]:[h,d],x=d<=h,y=x?a:c,k=x?i:f,w=x?c:a,v=x?f:i;let j=n;if(typeof n=="function"){let T=!1,M=!0;for(let B=m;B<=g;B+=1){const L=on(t,o[B]).map(S=>t.getRun(S)).filter(S=>S.type==="text");L.length!==0&&(T=!0,L.every(S=>{var N;return(N=S.marks)==null?void 0:N[r]})||(M=!1))}j=n(T&&M)}if(m===g)return sn(t,o[m],{startRunId:y,startOffset:k,endRunId:w,endOffset:v},j);let I=null;for(let T=m;T<=g;T+=1){const M=o[T],B=on(t,M),L=B[0],S=B[B.length-1],N=t.getRun(S),$=((C=N==null?void 0:N.value)==null?void 0:C.length)??0;let V;T===m&&T===g?V={startRunId:y,startOffset:k,endRunId:w,endOffset:v}:T===m?V={startRunId:y,startOffset:k,endRunId:S,endOffset:$}:T===g?V={startRunId:L,startOffset:0,endRunId:w,endOffset:v}:V={startRunId:L,startOffset:0,endRunId:S,endOffset:$},I=sn(t,M,V,j)}return I}function sc(t,e){var r;const n=t.getBlock(e);return((r=n==null?void 0:n.props)==null?void 0:r.titleRunIds)??(n==null?void 0:n.contentIds)??[]}function ac(t){const e=ln();if(!e)return!1;const{blockId:n,startRunId:r,startOffset:o,endRunId:s,endOffset:a}=e,i=sc(t,n);if(i.length===0)return!1;const u=i.indexOf(r),c=i.indexOf(s);if(u===-1||c===-1)return!1;const[f,d]=u<=c?[u,c]:[c,u],h=u<=c?o:a,m=u<=c?a:o;if(f!==0||d!==i.length-1||h!==0)return!1;const g=t.getRun(i[i.length-1]),x=(g==null?void 0:g.type)==="text"?(g.value??"").length:1;return m===x}function Sm(t){const e=lt();return e?Le(t,sc(t,e.blockId)):!1}function Rm(t,e,n){var m,g;const r=t.getBlock(e);if(!r){n(null);return}const o=t.getBlock(r.parentId),s=o?o.contentIds.indexOf(e):-1,a=s>0?o.contentIds[s-1]:null,i=s!==-1&&s<o.contentIds.length-1?o.contentIds[s+1]:null;t.applyOperation(ee(e)),n(null);const u=un(t),c=a??i??u;if(!c)return;const f=t.getBlock(c);if(Mn(t,f)){n(c),requestAnimationFrame(()=>{var x;return(x=document.querySelector(`[data-block-id="${c}"]`))==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&&ye(h)}function an(t){var o,s;const e=(o=t.getPendingSelection)==null?void 0:o.call(t);if(e){Je(e.runId,e.offset);return}const r=(((s=t.getPendingAffectedBlockIds)==null?void 0:s.call(t))??[]).find(a=>t.getBlock(a));r&&Re(t,r)}const ha={b:"bold",i:"italic",u:"underline"};function lc(t){const e=G(),[n,r]=Io(),{getSelectedBlockId:o,setSelectedBlockId:s}=ut();p.useEffect(()=>{const a=t.current;if(!a)return;const i=c=>{var d,h;if(o()&&(c.key==="Backspace"||c.key==="Delete")&&!c.defaultPrevented){c.preventDefault(),c.stopPropagation(),Rm(e,o(),s);return}if(o()&&c.key!=="Backspace"&&c.key!=="Delete"&&s(null),c.metaKey||c.ctrlKey){const m=c.key.toLowerCase();if(m==="z"&&!c.shiftKey){c.preventDefault(),(d=e.undo)!=null&&d.call(e)&&an(e);return}if(m==="z"&&c.shiftKey||m==="y"){c.preventDefault(),(h=e.redo)!=null&&h.call(e)&&an(e);return}if(m==="a"){if(n)return;(ac(e)||Sm(e))&&(c.preventDefault(),r(!0));return}if(ha[m]){if(n)return;c.preventDefault();const g=ha[m],x=ln();if(x){const k=rs(e,x.blockId,x,g);k&&ye(k);return}const y=rn(e);if(y){const k=os(e,y,g);k&&ye(k)}}return}if(n){if(c.key==="Backspace"||c.key==="Delete"){c.preventDefault(),c.stopPropagation();const m=ir(e);r(!1),m!=null&&m.runId&&Je(m.runId,m.offset);return}if(c.key.length===1){c.preventDefault(),c.stopPropagation();const m=ir(e,c.key);r(!1),m!=null&&m.runId&&Je(m.runId,m.offset);return}if(r(!1),c.key==="Escape")return}if(c.key==="Backspace"||c.key==="Delete"){const m=rn(e);if(!m)return;c.preventDefault(),c.stopPropagation();const g=es(e,m);g!=null&&g.runId&&Je(g.runId,g.offset)}},u=()=>{n&&r(!1),o()&&s(null)};return a.addEventListener("keydown",i),a.addEventListener("mousedown",u),()=>{a.removeEventListener("keydown",i),a.removeEventListener("mousedown",u)}},[t,e,n,r,o,s])}const Tm=4;function jm(t,e,n){const r=t.getBlock(e);if(!r)return[];const o=t.getBlock(r.parentId);if(!o)return[e];const s=o.contentIds,a=s.indexOf(e),i=n?s.indexOf(n):a;if(a===-1)return[e];const[u,c]=i===-1?[a,a]:[Math.min(a,i),Math.max(a,i)];return s.slice(u,c+1)}function Em(){var t,e;return typeof window<"u"&&((e=(t=window.matchMedia)==null?void 0:t.call(window,"(pointer: coarse)"))==null?void 0:e.matches)===!0}function ic(t){const e=G(),[,n]=_n(),r=p.useRef(null),o=p.useRef(!1),s=p.useRef(null),a=p.useCallback(f=>{var m,g,x,y,k;if(!r.current)return;if(!o.current){const{x:w,y:v}=s.current??{x:f.clientX,y:f.clientY};if(Math.hypot(f.clientX-w,f.clientY-v)<Tm)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()}(y=(x=window.getSelection)==null?void 0:x.call(window))==null||y.removeAllRanges(),f.preventDefault();const d=(k=document.elementFromPoint(f.clientX,f.clientY))==null?void 0:k.closest("[data-block-row-id]"),h=(d==null?void 0:d.getAttribute("data-block-row-id"))??null;n(jm(e,r.current,h))},[e,n]),i=p.useCallback(()=>{r.current=null,o.current=!1,s.current=null,document.documentElement.classList.remove("be-block-range-dragging")},[]),u=p.useCallback((f,d)=>{r.current=f,o.current=!1,s.current={x:d.clientX,y:d.clientY}},[]),c=p.useCallback(f=>{var x,y;if(f.button!==0||Em()||(y=(x=f.target).closest)!=null&&y.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;u(d.getAttribute("data-block-row-id"),f);return}const h=t==null?void 0:t.current;if(!h)return;const g=[...h.querySelectorAll("[data-block-row-id]")].find(k=>{const w=k.getBoundingClientRect();return f.clientY>=w.top&&f.clientY<=w.bottom});g&&u(g.getAttribute("data-block-row-id"),f)},[t,u]);p.useEffect(()=>(document.addEventListener("mousedown",c),document.addEventListener("mousemove",a),document.addEventListener("mouseup",i),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",i),document.documentElement.classList.remove("be-block-range-dragging")}),[c,a,i])}const Bm=340;function _m(t,e,n,r){p.useEffect(()=>{if(!t||!e)return;const o=document.querySelector(`[data-run-id="${e}"]`);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")}},[t,e,n,r])}function nr({isOpen:t,rect:e,commands:n,runId:r,onSelect:o,onClose:s,menuId:a="be-slash-menu",ariaLabel:i="Slash commands"}){const[u,c]=p.useState(0),f=p.useRef(null),d=p.useRef(null),h=Sr(),m=Ul(d,t&&n.length>0&&!!e,e==null?void 0:e.left);p.useEffect(()=>{c(0)},[n.length]),p.useEffect(()=>{var v,j;(j=(v=f.current)==null?void 0:v.scrollIntoView)==null||j.call(v,{block:"nearest"})},[u]),p.useEffect(()=>{if(!t)return;const v=j=>{j.key==="ArrowDown"?(j.preventDefault(),j.stopPropagation(),c(I=>Math.min(I+1,Math.max(n.length-1,0)))):j.key==="ArrowUp"?(j.preventDefault(),j.stopPropagation(),c(I=>Math.max(I-1,0))):j.key==="Enter"?(j.preventDefault(),j.stopPropagation(),n[u]&&o(n[u])):j.key==="Escape"&&(j.preventDefault(),j.stopPropagation(),s())};return document.addEventListener("keydown",v,!0),()=>document.removeEventListener("keydown",v,!0)},[t,n,u,o,s]);const x=n[u]?`${a}-option-${u}`:null;if(_m(t,r,x,a),!t||n.length===0||!e||m==null)return null;const y=window.innerHeight-h,w=e.bottom+Bm>y?{bottom:window.innerHeight-e.top+4}:{top:e.bottom+4};return l.jsx("div",{ref:d,id:a,role:"listbox","aria-label":i,className:"be-slash-menu",style:{position:"fixed",left:m,zIndex:1e3,...w},children:n.map((v,j)=>{const I=v.icon;return l.jsxs("div",{ref:j===u?f:void 0,id:`${a}-option-${j}`,role:"option","aria-selected":j===u,className:`be-slash-menu-item${j===u?" be-slash-menu-item-active":""}`,onMouseDown:C=>{C.preventDefault(),o(v)},onMouseEnter:()=>c(j),children:[I&&l.jsx("span",{className:"be-slash-menu-item-icon",children:l.jsx(I,{size:16})}),l.jsx("span",{className:"be-slash-menu-item-label",children:v.label})]},v.label)})})}function Om(t,e){var r;if(!e)return!0;const n=e.toLowerCase();return t.label.toLowerCase().includes(n)||((r=t.keywords)==null?void 0:r.some(o=>o.toLowerCase().includes(n)))}function Mm(t,e){const n=e.anchorNode,r=e.anchorOffset;let o;if(n===t){o="";for(let s=0;s<r&&s<t.childNodes.length;s+=1)o+=t.childNodes[s].textContent??""}else n&&n.parentElement===t?o=(n.textContent??"").slice(0,r):o=t.textContent??"";return at(o).length}function ss(t,e,n){const r=G(),[o,s]=p.useState(null);p.useEffect(()=>{const c=t.current;if(!c)return;const f=()=>{var I,C,T,M;const h=(I=window.getSelection)==null?void 0:I.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=(C=g==null?void 0:g.getAttribute)==null?void 0:C.call(g,"data-run-id");if(!x||!h){s(null);return}const y=Mm(g,h),k=at(g.textContent).slice(0,y),w=e.exec(k);if(!w){s(null);return}const v=(M=(T=g.closest)==null?void 0:T.call(g,"[data-block-id]"))==null?void 0:M.getAttribute("data-block-id");if(!v){s(null);return}const j=w.index+w[1].length;s({query:w[2],blockId:v,runId:x,sliceStart:j,sliceEnd:y,rect:g.getBoundingClientRect()})},d=h=>{h.key==="Escape"&&s(null)};return c.addEventListener("input",f),c.addEventListener("keydown",d),()=>{c.removeEventListener("input",f),c.removeEventListener("keydown",d)}},[t,e]);const a=o?n().filter(c=>Om(c,o.query)):[],i=p.useCallback(c=>{o&&(c.run(r,{blockId:o.blockId,runId:o.runId,sliceStart:o.sliceStart,sliceEnd:o.sliceEnd}),s(null))},[o,r]),u=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:a,selectCommand:i,close:u}}const Lm=/(^|\s)\/(\w*)$/;function cc(t){const e=vt(),n=tt(),r=p.useCallback(()=>[...e.listSlashCommands(),...(n==null?void 0:n.listSlashCommands())??[]],[e,n]);return ss(t,Lm,r)}const Nm=[{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 Am(t,{runId:e,sliceStart:n,sliceEnd:r},o){const s=t.getRun(e),a=(s==null?void 0:s.value)??"",i=a.slice(0,n)+o+a.slice(r);t.applyOperation(ue(e,{value:i})),Je(e,n+o.length)}const Dm=Nm.map(({char:t,name:e,keywords:n})=>({label:`${t} ${e}`,keywords:n,run:(r,o)=>Am(r,o,t)})),Pm=/(^|\s):(\w*)$/,$m=()=>Dm;function uc(t){return ss(t,Pm,$m)}const zm=/(^|\s)@(\w*)$/;function dc(t){const e=tt(),n=p.useCallback(()=>(e==null?void 0:e.listAtCommands())??[],[e]);return ss(t,zm,n)}function as(t,e,n,r,o){const[s,a]=p.useState(!1),i=p.useCallback(y=>{const k=e==="same-block"?sn(t,n.blockId,n,y):cr(t,r,y);return k&&ye(k),k},[t,e,n,r]),u=p.useCallback(y=>{const k=e==="same-block"?rs(t,n.blockId,n,y):os(t,r,y);k&&ye(k)},[t,e,n,r]),c=p.useCallback(y=>{const k=y==="subscript"?"superscript":"subscript",w=!o[y];i({[y]:w?!0:null,[k]:null})},[o,i]),f=p.useRef(null),d=p.useCallback(()=>{f.current={kind:e,selection:n,crossSelection:r},a(!0)},[e,n,r]),h=p.useCallback(()=>a(!1),[]),m=p.useCallback(y=>{const k=f.current;if(!k)return;const w=k.kind==="same-block"?sn(t,k.selection.blockId,k.selection,y):cr(t,k.crossSelection,y);w&&ye(w),a(!1)},[t]),g=p.useCallback((y,k)=>m({link:{href:y,target:k}}),[m]),x=p.useCallback(()=>m({link:null}),[m]);return{applyPatch:i,toggleBoolean:u,setSubSuper:c,isLinkModalOpen:s,openLinkModal:d,closeLinkModal:h,handleSaveLink:g,handleRemoveLink:x}}const Hm="be-touch-input";function Fm(){var t,e;return typeof window<"u"&&((e=(t=window.matchMedia)==null?void 0:t.call(window,"(pointer: coarse)"))==null?void 0:e.matches)===!0}function ls(){const[t,e]=p.useState(Fm);return p.useEffect(()=>{if(typeof window>"u")return;const n=r=>{e(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(Hm,t)},[t]),t}const Um=[{markName:"bold",Icon:Fa,title:"Bold (Ctrl+B)"},{markName:"italic",Icon:Ua,title:"Italic (Ctrl+I)"},{markName:"underline",Icon:Va,title:"Underline (Ctrl+U)"},{markName:"strike",Icon:td,title:"Strikethrough"}],Vm=[{label:"Default",value:null},{label:"Red",value:"#e03131"},{label:"Orange",value:"#e8590c"},{label:"Green",value:"#2f9e44"},{label:"Blue",value:"#1971c2"},{label:"Purple",value:"#9c36b5"}],Ym=[{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 pc({isOpen:t,rect:e,kind:n,selection:r,crossSelection:o,marks:s,store:a,onComment:i,commentAuthorId:u}){var K,Q;const c=ls(),[f,d]=p.useState(null),[h,m]=p.useState(null),g=p.useRef(null),{applyPatch:x,toggleBoolean:y,setSubSuper:k,isLinkModalOpen:w,openLinkModal:v,closeLinkModal:j,handleSaveLink:I,handleRemoveLink:C}=as(a,n,r,o,s),T=p.useRef(null);T.current=h;function M(){var D,F,re,H;(F=(D=document.activeElement)==null?void 0:D.blur)==null||F.call(D),(H=(re=window.getSelection)==null?void 0:re.call(window))==null||H.removeAllRanges()}function B(){if(!r)return;const D=E(),F=vo(a,r,D);F&&a.applyOperation(F),m({commentId:D}),d("comment")}function L(){const D=T.current;if(D){for(const F of wo(a,D.commentId))a.applyOperation(F);m(null),M()}}function S(D){!h||!r||(a.applyOperation(Cn({id:h.commentId,blockId:r.blockId,anchorRunIds:[r.startRunId,r.endRunId],resolved:!1,messages:[{id:E(),authorId:u,text:D,createdAt:Date.now()}]})),m(null),d(null),M())}function N(){L(),d(null)}p.useEffect(()=>{if(!t||n!=="same-block"||!(i||u))return;const D=F=>{(F.metaKey||F.ctrlKey)&&F.altKey&&F.code==="KeyM"&&(F.preventDefault(),i?i(r):B())};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[t,n,i,u,r]),p.useEffect(()=>{if(!f)return;const D=re=>{g.current&&!g.current.contains(re.target)&&(L(),d(null))},F=re=>{re.key==="Escape"&&(L(),d(null))};return document.addEventListener("mousedown",D),document.addEventListener("keydown",F),()=>{document.removeEventListener("mousedown",D),document.removeEventListener("keydown",F)}},[f]),p.useEffect(()=>{L(),d(null)},[e,n]);const $=Vl(g,!!(t&&e),e?e.left+e.width/2:null);if(c||(!t||!e)&&!w)return null;const V=!i&&f==="comment";return l.jsxs(l.Fragment,{children:[t&&e&&$!=null&&V&&l.jsxs("div",{ref:g,className:"be-floating-toolbar be-floating-toolbar-comment-standalone",role:"dialog","aria-label":"Add comment",style:{position:"fixed",top:e.top-44,left:$,transform:"translateX(-50%)"},onMouseDown:D=>{D.target.tagName!=="TEXTAREA"&&D.preventDefault()},children:[l.jsx(gl,{title:"Add comment",onClose:N}),l.jsx(No,{authorId:u,autoFocus:!0,onSubmit:S,onCancel:N})]}),t&&e&&$!=null&&!V&&l.jsxs("div",{ref:g,className:"be-floating-toolbar",role:"toolbar","aria-label":"Text formatting",style:{position:"fixed",top:e.top-44,left:$,transform:"translateX(-50%)"},onMouseDown:D=>{D.target.tagName!=="TEXTAREA"&&D.preventDefault()},children:[Um.map(({markName:D,Icon:F,title:re})=>l.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s[D]?" be-floating-toolbar-btn-active":""}`,title:re,"aria-label":re,"aria-pressed":!!s[D],onClick:()=>y(D),children:l.jsx(F,{})},D)),l.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.subscript?" be-floating-toolbar-btn-active":""}`,title:"Subscript","aria-pressed":!!s.subscript,onClick:()=>k("subscript"),children:"X₂"}),l.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.superscript?" be-floating-toolbar-btn-active":""}`,title:"Superscript","aria-pressed":!!s.superscript,onClick:()=>k("superscript"),children:"X²"}),l.jsx("span",{className:"be-floating-toolbar-divider"}),l.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[l.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Text color","aria-haspopup":"true","aria-expanded":f==="color",onClick:()=>d(D=>D==="color"?null:"color"),children:l.jsx("span",{style:{color:s.color||"inherit",fontWeight:700},children:"A"})}),f==="color"&&l.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Text color",children:Vm.map(D=>l.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",title:D.label,onClick:()=>{x({color:D.value}),d(null)},children:l.jsx("span",{style:{color:D.value||"#1a1a1a",fontWeight:700},children:"A"})},D.label))})]}),l.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[l.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Highlight","aria-haspopup":"true","aria-expanded":f==="highlight",onClick:()=>d(D=>D==="highlight"?null:"highlight"),children:l.jsx("span",{style:{backgroundColor:s.highlight||"transparent",padding:"0 2px",borderRadius:2},children:"H"})}),f==="highlight"&&l.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Highlight color",children:Ym.map(D=>l.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",style:{backgroundColor:D.value||"transparent"},title:D.label,onClick:()=>{x({highlight:D.value}),d(null)}},D.label))})]}),l.jsx("span",{className:"be-floating-toolbar-divider"}),l.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:v,children:l.jsx(Ka,{})}),(i||u)&&n==="same-block"&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"be-floating-toolbar-divider"}),l.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Comment (Ctrl+Alt+M)","aria-label":"Comment",onClick:()=>i?i(r):B(),children:l.jsx(Wa,{})})]})]}),l.jsx(bl,{isOpen:w,initialHref:((K=s.link)==null?void 0:K.href)??"",initialTarget:((Q=s.link)==null?void 0:Q.target)??"_self",hasExistingLink:!!s.link,onSave:I,onRemove:C,onClose:j})]})}function fc(t){const e=G(),[n,r]=p.useState(null);return p.useEffect(()=>{const o=t.current;if(!o)return;const s=()=>{var f,d,h,m,g;if((d=(f=document.activeElement)==null?void 0:f.closest)!=null&&d.call(f,".be-floating-toolbar"))return;const a=(h=window.getSelection)==null?void 0:h.call(window);if(!a||a.rangeCount===0||a.isCollapsed){r(null);return}if(!o.contains(a.anchorNode)||!o.contains(a.focusNode)){r(null);return}const i=((g=(m=a.getRangeAt(0)).getBoundingClientRect)==null?void 0:g.call(m))??{top:0,left:0,right:0,bottom:0,width:0,height:0},u=ln();if(u){r({kind:"same-block",rect:i,selection:u,marks:ts(e,u.blockId,u)});return}const c=rn(e);if(c){r({kind:"cross-block",rect:i,crossSelection:c,marks:ns(e,c)});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)}},[t,e]),{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 Km({store:t,rootId:e,onComment:n,commentAuthorId:r}){const o=p.useRef(null),{onCopy:s,onCut:a,onPaste:i}=tc(),u=cc(o),c=uc(o),f=dc(o),d=fc(o);return lc(o),ic(o),l.jsxs("div",{ref:o,role:"document","aria-label":"Document editor",onCopy:s,onCut:a,onPaste:i,children:[l.jsx(Zi,{}),l.jsx(ht,{parentId:e,isTopLevel:!0}),l.jsx(Wi,{}),l.jsx(nr,{isOpen:u.isOpen,rect:u.rect,commands:u.commands,runId:u.runId,onSelect:u.selectCommand,onClose:u.close}),l.jsx(nr,{isOpen:c.isOpen,rect:c.rect,commands:c.commands,runId:c.runId,onSelect:c.selectCommand,onClose:c.close,menuId:"be-emoji-menu",ariaLabel:"Emoji"}),l.jsx(nr,{isOpen:f.isOpen,rect:f.rect,commands:f.commands,runId:f.runId,onSelect:f.selectCommand,onClose:f.close,menuId:"be-at-menu",ariaLabel:"Mention"}),l.jsx(pc,{isOpen:d.isOpen,rect:d.rect,kind:d.kind,selection:d.selection,crossSelection:d.crossSelection,marks:d.marks,store:t,onComment:n,commentAuthorId:r})]})}function Wm({editor:t,className:e,style:n,theme:r,getBlockClassName:o,onComment:s,commentAuthorId:a,showCommentsPanel:i,children:u}){const{store:c,registry:f,inlineRegistry:d}=t,h=c.getRootId();return l.jsxs(Pa,{store:c,registry:f,inlineRegistry:d,history:c,className:e,style:n,theme:r,getBlockClassName:o,commentAuthorId:a,children:[l.jsx(Km,{store:c,rootId:h,onComment:s,commentAuthorId:a}),i&&l.jsx(ll,{authorId:a}),u]})}const Xm="$fieldTypes";function hc(){const t=G(),e=p.useCallback(r=>t.subscribe(Xm,r),[t]),n=p.useCallback(()=>t.getFieldTypes(),[t]);return p.useSyncExternalStore(e,n)}const qm={canUndo:!1,canRedo:!1};function mc(){const{history:t}=Pe(),e=p.useCallback(o=>t?t.subscribeToHistory(o):()=>{},[t]),n=p.useCallback(()=>t?t.getUndoRedoSnapshot():qm,[t]),r=p.useSyncExternalStore(e,n);return t?{...r,undo:()=>{const o=t.undo();return o&&an(t),o},redo:()=>{const o=t.redo();return o&&an(t),o},getHistoryLog:()=>t.getHistoryLog()}:null}function Gm({store:t,docId:e,debounceMs:n,onError:r}){const[o,s]=p.useState(!1);return p.useEffect(()=>{let a=!1;s(!1),Ca(e).then(c=>{if(!a&&c){const f=t.store??t;f.blocks=new Map((c.blocks??[]).map(d=>[d.id,d])),f.runs=new Map((c.runs??[]).map(d=>[d.id,d])),f.rootId=c.rootId??null,f.fieldTypes=new Map((c.fieldTypes??[]).map(d=>[d.id,d])),f._fieldTypesSnapshot=null,f._orders=new Map,f._notify([...f.blocks.keys(),...f.runs.keys()])}}).catch(c=>r==null?void 0:r(c)).finally(()=>{a||s(!0)});const{stop:i,flush:u}=Ta({store:t,docId:e,debounceMs:n,onError:r});return()=>{a=!0,u(),i()}},[e]),{isLoaded:o}}function Jm(t){const[e,n]=p.useState(()=>(t==null?void 0:t.getPresence())??new Map);return p.useEffect(()=>{if(!t){n(new Map);return}return n(t.getPresence()),t.onPresenceChange(n)},[t]),e}function Zm(){const[t,e]=p.useState(!1),[n,r]=p.useState(null);p.useEffect(()=>{if(!navigator.serviceWorker)return;let s=!1;function a(i){if(!i)return;const u=()=>{i.waiting&&(r(i.waiting),e(!0))};u(),i.addEventListener("updatefound",()=>{const c=i.installing;c&&c.addEventListener("statechange",()=>{c.state==="installed"&&navigator.serviceWorker.controller&&u()})})}return navigator.serviceWorker.getRegistration().then(i=>{s||a(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:t,applyUpdate:o}}const bc=[{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"}}],gc=new Map;for(const{phrases:t,action:e}of bc)for(const n of t)gc.set(n,e);function Qm(t){return(t??"").toLowerCase().trim().replace(/\s+/g," ").replace(/[.,!?]+$/,"")}function eb(t){return gc.get(Qm(t))??null}function tb(){return bc.map(({phrases:t,description:e})=>({phrases:[...t],description:e}))}function nb(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function rb(t){var e;return((e=t==null?void 0:t.props)==null?void 0:e.titleRunIds)??(t==null?void 0:t.contentIds)??[]}function ob(t,e,n){var r,o;if(n.type==="insertParagraph"){nt(t,e,te("paragraph"));return}if(n.type==="convertBlock"){const s=t.getBlock(e);if(!s)return;const a=rb(s),{ops:i}=Po(t,e,n.blockType,n.props,a);nb(t,i),a[0]&&br(a[0]);return}if(n.type==="undo"){(r=t.undo)!=null&&r.call(t)&&an(t);return}n.type==="redo"&&(o=t.redo)!=null&&o.call(t)&&an(t)}function ma(){return typeof window>"u"?null:window.SpeechRecognition??window.webkitSpeechRecognition??null}const sb="Microphone access is blocked. Enable it in your browser's site settings, then try again.";function ab({shortcut:t=!0}={}){const e=G(),[n,r]=p.useState(!1),[o,s]=p.useState("idle"),[a,i]=p.useState("unknown"),[u,c]=p.useState(null),f=p.useRef(null),d=p.useRef(null),h=p.useRef(null),m=p.useRef(0),g=ma()!==null;p.useEffect(()=>{var T;if(!((T=navigator.permissions)!=null&&T.query))return;let I,C=!1;return navigator.permissions.query({name:"microphone"}).then(M=>{C||(I=M,i(M.state),I.onchange=()=>i(I.state))}).catch(()=>{}),()=>{C=!0,I&&(I.onchange=null)}},[]);const x=p.useCallback(()=>{if(!d.current){const I=lt();if(!I)return null;d.current=I}return{runId:d.current.runId,blockId:d.current.blockId,startOffset:d.current.offset,insertedLength:0}},[]),y=p.useCallback((I,C)=>{const T=e.getRun(I.runId);if(!T||T.type!=="text")return;const M=T.value??"",B=M.slice(0,I.startOffset);if(I.needsLeadingSpace===void 0){const N=B[B.length-1];I.needsLeadingSpace=I.startOffset>0&&N!==void 0&&!/\s/.test(N)}const L=(I.needsLeadingSpace?" ":"")+C,S=M.slice(I.startOffset+I.insertedLength);Ve.flushSync(()=>e.applyOperation(ue(I.runId,{value:B+L+S}))),I.insertedLength=L.length,$s(I.runId,I.startOffset+L.length),d.current={runId:I.runId,blockId:I.blockId,offset:I.startOffset+L.length}},[e]),k=p.useCallback(I=>{const C=e.getRun(I.runId);if(!C||C.type!=="text")return;const T=C.value??"",M=T.slice(0,I.startOffset)+T.slice(I.startOffset+I.insertedLength);Ve.flushSync(()=>e.applyOperation(ue(I.runId,{value:M}))),$s(I.runId,I.startOffset),d.current={runId:I.runId,blockId:I.blockId,offset:I.startOffset}},[e]),w=p.useCallback(I=>{var B,L;let C="",T=!1;const M=Math.max(I.resultIndex,m.current);for(let S=M;S<I.results.length;S+=1){const N=I.results[S],$=((B=N[0])==null?void 0:B.transcript)??"";if(!N.isFinal){C+=(C?" ":"")+$,T=!0;continue}const V=h.current??x();if(h.current=null,m.current=S+1,!V)continue;const K=eb($);K?(k(V),K.type==="stopDictation"?(L=f.current)==null||L.stop():(ob(e,V.blockId,K),d.current=null,s("listening"))):(y(V,$),s("listening"))}if(T){const S=h.current??x();S&&(h.current=S,y(S,C))}},[e,x,y,k]),v=p.useCallback(()=>{if(!g||f.current)return;c(null),d.current=lt(),h.current=null,m.current=0;const I=ma(),C=new I;C.continuous=!0,C.interimResults=!0,C.onresult=w,C.onstart=()=>s("listening"),C.onspeechstart=()=>s("listening"),C.onspeechend=()=>s("processing"),C.onerror=T=>{T.error==="not-allowed"||T.error==="service-not-allowed"?(i("denied"),c(sb)):c(T.error??"Voice typing stopped unexpectedly.")},C.onend=()=>{f.current=null,d.current=null,h.current=null,m.current=0,r(!1),s("idle")},f.current=C,C.start(),r(!0)},[g,w]),j=p.useCallback(()=>{var I;(I=f.current)==null||I.stop()},[]);return p.useEffect(()=>()=>{var I;return(I=f.current)==null?void 0:I.stop()},[]),p.useEffect(()=>{if(!t||!g)return;const I=C=>{!(C.metaKey||C.ctrlKey)||!C.shiftKey||C.key.toLowerCase()!=="m"||(C.preventDefault(),f.current?j():v())};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[t,g,v,j]),{isSupported:g,isListening:n,status:o,permissionState:a,error:u,start:v,stop:j}}function lb({voice:t}){const[e,n]=p.useState(!1);p.useEffect(()=>{n(!1)},[t==null?void 0:t.error]);const r=(t==null?void 0:t.permissionState)==="denied"&&!e;return l.jsxs(dt,{isOpen:r,onClose:()=>n(!0),title:"Microphone access blocked",children:[l.jsx("p",{children:(t==null?void 0:t.error)||"Microphone access is blocked. Enable it in your browser's site settings, then try again."}),l.jsxs("div",{className:"be-modal-actions",children:[l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:()=>n(!0),children:"Dismiss"}),l.jsx("button",{type:"button",className:"be-modal-save",onClick:()=>{var o;return(o=t==null?void 0:t.start)==null?void 0:o.call(t)},children:"Try again"})]})]})}function xc(t){const[e,n]=p.useState(null);return p.useEffect(()=>{if(!t){n(null);return}const r=()=>{var u,c,f,d;const o=(u=window.getSelection)==null?void 0:u.call(window);if(!o||o.rangeCount===0||!o.isCollapsed){n(null);return}const s=o.anchorNode,a=(s==null?void 0:s.nodeType)===1?s:s==null?void 0:s.parentElement;if(!((c=a==null?void 0:a.closest)!=null&&c.call(a,"[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)}},[t]),e}function ib({voice:t}){const e=!!(t!=null&&t.isListening),n=xc(e),r=p.useRef(null),o=Vl(r,!!(e&&n),n==null?void 0:n.left);if(!e||!n||o==null)return null;const s=t.status==="processing";return Ve.createPortal(l.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:[l.jsx("span",{className:"be-voice-indicator-dot"}),l.jsx(vd,{size:12}),l.jsx("span",{className:"be-voice-indicator-label",children:s?"Processing…":"Listening…"})]}),document.body)}function yc({isOpen:t,onClose:e,onSelectCommand:n}){const r=vt(),o=tt(),s=p.useMemo(()=>[...(r==null?void 0:r.listSlashCommands())??[],...(o==null?void 0:o.listSlashCommands())??[]],[r,o]);return l.jsx(dt,{isOpen:t,onClose:e,title:"Add a block",variant:"sheet",children:l.jsx("div",{className:"be-mobile-picker-list",role:"listbox","aria-label":"Insertable blocks",children:s.map(a=>{const i=a.icon;return l.jsxs("button",{type:"button",role:"option",className:"be-mobile-picker-item",onClick:()=>n(a),children:[i&&l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(i,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:a.label})]},a.label)})})})}function kc({isOpen:t,onClose:e,store:n,blockId:r}){var i;const o=r?n.getBlock(r):null,s=!!((i=o==null?void 0:o.props)!=null&&i.hidden),a=p.useCallback(u=>{u(),e()},[e]);return l.jsx(dt,{isOpen:t,onClose:e,title:"Block options",variant:"sheet",children:l.jsxs("div",{className:"be-mobile-picker-list",role:"menu","aria-label":"Block options",children:[l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{Fo(n,r),xe("Block duplicated")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(jo,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:"Duplicate"})]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{Uo(n,r)&&xe("Block moved up")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(hr,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:"Move up"})]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{Vo(n,r)&&xe("Block moved down")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(mr,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:"Move down"})]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{n.applyOperation(J(r,{hidden:!s})),xe(s?"Block shown in preview":"Block hidden in preview")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:s?l.jsx(Mo,{size:18}):l.jsx(Lo,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:s?"Show in preview":"Hide in preview"})]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item be-mobile-picker-item-danger",onClick:()=>a(()=>{vr(n,r),xe("Block deleted")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(On,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:"Delete"})]})]})})}const cb=oi.map(t=>({value:t,label:t}));function ub(t,e){const[n,r]=p.useState(!1),[o,s]=p.useState(null),[a,i]=p.useState(null),[u,c]=p.useState(null);return p.useEffect(()=>{const f=t.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)}},[t]),p.useEffect(()=>{if(!n){s(null);return}const f=()=>{var g;const d=t.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=ln();if(x){i({kind:"same-block",selection:x,crossSelection:null,marks:ts(e,x.blockId,x)}),s("selection");return}const y=rn(e);if(y){i({kind:"cross-block",selection:null,crossSelection:y,marks:ns(e,y)}),s("selection");return}s(null);return}const m=lt();if(!m||!d.contains(h.anchorNode)){s(null);return}c(m),s("caret")};return f(),document.addEventListener("selectionchange",f),()=>document.removeEventListener("selectionchange",f)},[n,e,t]),{isFocused:n,mode:o,selectionState:a,caretState:u}}function db({store:t,selectionState:e}){const{kind:n,selection:r,crossSelection:o,marks:s}=e,{toggleBoolean:a,openLinkModal:i}=as(t,n,r,o,s);return l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.bold?" be-mobile-bar-btn-active":""}`,"aria-label":"Bold",onClick:()=>a("bold"),children:l.jsx(Fa,{size:18})}),l.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.italic?" be-mobile-bar-btn-active":""}`,"aria-label":"Italic",onClick:()=>a("italic"),children:l.jsx(Ua,{size:18})}),l.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.underline?" be-mobile-bar-btn-active":""}`,"aria-label":"Underline",onClick:()=>a("underline"),children:l.jsx(Va,{size:18})}),l.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.link?" be-mobile-bar-btn-active":""}`,"aria-label":"Link",onClick:i,children:l.jsx(Ka,{size:18})})]})}function pb({store:t,blockId:e}){const n=p.useCallback(()=>{const o=t.getBlock(e),s=o&&t.getBlock(o.parentId);s&&Ko(t,s.id)},[t,e]),r=p.useCallback(()=>{const o=t.getBlock(e),s=o&&t.getBlock(o.parentId),a=s&&t.getBlock(s.parentId);if(!a||!s)return;const i=s.contentIds.indexOf(e);i!==-1&&sr(t,a.id,i)},[t,e]);return l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert row below",onClick:n,children:"+ Row"}),l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert column right",onClick:r,children:"+ Column"})]})}function fb({store:t,blockId:e}){var o;const n=t.getBlock(e),r=p.useCallback(s=>t.applyOperation(J(e,{language:s})),[t,e]);return l.jsx(Mt,{className:"be-mobile-bar-select",value:((o=n==null?void 0:n.props)==null?void 0:o.language)??"plaintext",options:cb,onChange:r,ariaLabel:"Code language"})}function hb({store:t,blockId:e}){var o;const n=t.getBlock(e),r=(o=n==null?void 0:n.props)==null?void 0:o.color;return l.jsx("div",{className:"be-mobile-bar-swatches",children:ti.map(s=>l.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:()=>t.applyOperation(J(e,{color:s.value}))},s.value))})}const vc={tableCell:pb,code:fb,callout:hb};function mb(t,e){let n=t.getBlock(e);for(;n;){if(vc[n.type])return n;n=n.parentId?t.getBlock(n.parentId):null}return null}function bb(t,e){const n=t.getRootId();let r=t.getBlock(e);for(;r&&r.parentId!==n;)r=t.getBlock(r.parentId);return r}function gb({containerRef:t}){var T,M;const e=G(),n=mc(),r=ls(),o=Sr(),{isFocused:s,mode:a,selectionState:i,caretState:u}=ub(t,e),[c,f]=p.useState(!1),[d,h]=p.useState(!1),m=p.useCallback(()=>f(!0),[]),g=p.useCallback(()=>f(!1),[]),x=p.useCallback(()=>h(!0),[]),y=p.useCallback(()=>h(!1),[]),k=p.useCallback(B=>{const L=lt()??u;L&&(B.run(e,{blockId:L.blockId,runId:L.runId,sliceStart:L.offset,sliceEnd:L.offset}),g())},[e,u,g]),w=p.useCallback(()=>{var B,L;(L=(B=document.activeElement)==null?void 0:B.blur)==null||L.call(B)},[]);if(!r||!s)return null;const v=a==="caret"&&u?mb(e,u.blockId):null,j=v?vc[v.type]:null,I=a==="caret"&&u?u.blockId:((T=i==null?void 0:i.selection)==null?void 0:T.blockId)??((M=i==null?void 0:i.crossSelection)==null?void 0:M.startBlockId)??null,C=I?bb(e,I):null;return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"be-mobile-action-bar",role:"toolbar","aria-label":"Editor actions",style:{bottom:o},onMouseDown:B=>B.preventDefault(),children:[a==="selection"&&i&&l.jsx(db,{store:e,selectionState:i}),a!=="selection"&&l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Add block",onClick:m,children:l.jsx(To,{size:18})}),j&&v&&l.jsx(j,{store:e,blockId:v.id}),n&&l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Undo",disabled:!n.canUndo,onClick:n.undo,children:"↶"}),l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Redo",disabled:!n.canRedo,onClick:n.redo,children:"↷"})]})]}),l.jsx("span",{className:"be-mobile-bar-spacer"}),C&&l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Block options",onClick:x,children:l.jsx(Ju,{size:18})}),l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Dismiss keyboard",onClick:w,children:l.jsx(fr,{size:18})})]}),l.jsx(yc,{isOpen:c,onClose:g,onSelectCommand:k}),l.jsx(kc,{isOpen:d,onClose:y,store:e,blockId:C==null?void 0:C.id})]})}const wc={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"]},Ic=new Set(["listItem","toggleHeading"]),Cc=new Set(["divider","embed"]);function Sc(t,e,n,r){var i,u,c;const o=n.type,s={};for(const f of wc[o]??[])((i=n.props)==null?void 0:i[f])!==void 0&&(s[f]=n.props[f]);if(o==="table"){const f=n.contentIds[0]&&t.getBlock(n.contentIds[0]);return s.columns=$e(n,((u=f==null?void 0:f.contentIds)==null?void 0:u.length)??0),s.rows=n.contentIds.map(d=>t.getBlock(d).contentIds.map(m=>{const g=t.getBlock(m);return Hr(g.contentIds.map(x=>t.getRun(x)),r)})),{id:n.id,type:o,data:s}}if(Ic.has(o)){const f=((c=n.props)==null?void 0:c.titleRunIds)??[];s.text=Hr(f.map(d=>t.getRun(d)),r)}else e.isLeaf(o)&&!Cc.has(o)&&(s.text=Hr(n.contentIds.map(f=>t.getRun(f)),r));const a={id:n.id,type:o,data:s};return e.isLeaf(o)||(a.children=n.contentIds.map(f=>Sc(t,e,t.getBlock(f),r))),a}function Rc(t,e,n,{pretty:r=!0}={}){const o={store:t,registry:e,inlineRegistry:n},a=t.getBlock(t.getRootId()).contentIds.map(i=>Sc(t,e,t.getBlock(i),o));return JSON.stringify({version:1,blocks:a},null,r?2:0)}function uo(t,e){const n=new DOMParser().parseFromString(`<div>${t??""}</div>`,"text/html");return Ye(n.body.firstChild,e)}function xb(t,e,n,r,o){const{id:s=E(),data:a={}}=t,i=(a.rows??[]).map(c=>{const f=E(),d=c.map(h=>{const m=E(),g=uo(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:e,contentIds:d,props:{}}),f}),u={id:s,type:"table",parentId:e,contentIds:i,props:{columns:a.columns??[]}};return n.push(u),u}function po(t,e,n,r,o,s){const{id:a=E(),type:i,data:u={},children:c=[]}=t;if(i==="table")return xb(t,e,o,s,r);const f={};for(const h of wc[i]??[])u[h]!==void 0&&(f[h]=u[h]);const d={id:a,type:i,parentId:e,contentIds:[],props:f};if(o.push(d),Ic.has(i)){const h=uo(u.text,r);s.push(...h),d.props.titleRunIds=h.map(m=>m.id),d.contentIds=c.map(m=>po(m,a,n,r,o,s).id)}else if(n.isLeaf(i)){if(!Cc.has(i)){const h=uo(u.text,r);s.push(...h),d.contentIds=h.map(m=>m.id)}}else d.contentIds=c.map(h=>po(h,a,n,r,o,s).id);return d}function yb(t,e,n){const r=typeof t=="string"?JSON.parse(t):t,o={registry:e,inlineRegistry:n},s=E(),a=[],i=[],u=(r.blocks??[]).map(c=>po(c,s,e,o,a,i).id);return a.push({id:s,type:"page",parentId:null,contentIds:u,props:{}}),{rootId:s,blocks:a,runs:i}}const kb=[{value:"json",label:"JSON"},{value:"simpleJson",label:"Simple JSON"},{value:"html",label:"HTML"},{value:"text",label:"Text"}];function vb({label:t="View source",className:e=""}){const n=G(),r=vt(),o=tt(),[s,a]=p.useState(!1),[i,u]=p.useState("json"),[c,f]=p.useState(!1),d=p.useCallback(()=>{f(!1),a(!0)},[]),h=p.useCallback(()=>a(!1),[]),m=p.useMemo(()=>s?i==="json"?ko(n):i==="simpleJson"?Rc(n,r,o):i==="html"?Ea(n,r,o):Ba(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 l.jsxs(l.Fragment,{children:[l.jsxs("button",{type:"button",className:`be-export-trigger ${e}`.trim(),onClick:d,children:[l.jsx(_o,{size:14})," ",t]}),l.jsxs(dt,{isOpen:s,onClose:h,title:"Document source",size:"large",children:[l.jsx("div",{className:"be-export-tabs",role:"tablist",children:kb.map(x=>l.jsx("button",{type:"button",role:"tab","aria-selected":i===x.value,className:`be-export-tab${i===x.value?" be-export-tab-active":""}`,onClick:()=>u(x.value),children:x.label},x.value))}),l.jsx("pre",{className:"be-export-pre",children:l.jsx("code",{children:m})}),l.jsxs("div",{className:"be-modal-actions",children:[l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:h,children:"Close"}),l.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:c?"Copied!":"Copy"})]})]})]})}function wb({id:t,label:e,placeholder:n,variant:r,options:o,onManage:s,mention:a=!1}){const i=G(),u=wt(t),c=p.useCallback((m,g)=>{i.applyOperation(ue(t,{data:{selectedValue:m,selectedLabel:(g==null?void 0:g.label)??"",selectedColor:g==null?void 0:g.color}}))},[i,t]);if(!u)return null;const{selectedValue:f="",selectedLabel:d="",selectedColor:h}=u.data??{};return l.jsx("span",{className:"be-inline-select",onMouseDown:m=>{m.preventDefault(),m.stopPropagation()},onKeyDown:m=>m.stopPropagation(),children:l.jsx(Mt,{value:f,selectedLabel:d,selectedColor:h,options:o,onChange:c,placeholder:n,variant:r,ariaLabel:e,onManageOptions:s,mention:a})})}function Tc(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function ba(t){return Tc(t).replace(/"/g,""")}function jc({type:t,label:e,placeholder:n="Select…",variant:r="default",icon:o,options:s,onManage:a,triggers:i=["slash"],mention:u=i.includes("at")}){function c(g){var k,w;const x=((k=g.data)==null?void 0:k.selectedLabel)||"",y=u&&x?`@${x}`:x;return`<span data-inline-type="${ba(t)}" data-selected-value="${ba(((w=g.data)==null?void 0:w.selectedValue)??"")}">${Tc(y)}</span>`}function f(g){var y;const x=((y=g.data)==null?void 0:y.selectedLabel)??"";return u&&x?`@${x}`:x}function d(g){var k;if(((k=g.getAttribute)==null?void 0:k.call(g,"data-inline-type"))!==t)return null;const x=g.textContent??"",y=u&&x.startsWith("@")?x.slice(1):x;return{id:E(),type:t,value:"",marks:{},data:{selectedValue:g.getAttribute("data-selected-value")??"",selectedLabel:y}}}function h({id:g}){return l.jsx(wb,{id:g,label:e,placeholder:n,variant:r,options:s,onManage:a,mention:u})}const m={label:e,icon:o??sl,keywords:[e.toLowerCase(),"select","field"],run:(g,{blockId:x,runId:y,sliceStart:k,sliceEnd:w})=>Tr(g,{blockId:x,runId:y,sliceStart:k,sliceEnd:w},()=>({id:E(),type:t,value:"",marks:{},data:{selectedValue:"",selectedLabel:"",selectedColor:void 0}}))};return{component:h,isAtomic:!0,toHTML:c,toPlainText:f,fromHTML:d,slashCommand:i.includes("slash")?m:void 0,atCommand:i.includes("at")?m:void 0}}function Ec(t,e,{onManage:n}={}){for(const r of t.getFieldTypes())e.register(r.id,jc({type:r.id,label:r.label,placeholder:r.placeholder,variant:r.variant,options:r.options??[],onManage:n?()=>n(r.id):void 0}))}function Bc(){const t=G(),e=tt(),n=hc(),{openEdit:r}=So(),o=p.useRef([]);p.useEffect(()=>{if(!e)return;const s=new Set(n.map(a=>a.id));for(const a of o.current)s.has(a)||e.unregister(a);Ec(t,e,{onManage:r}),o.current=[...s]},[t,e,n,r])}function Ib(){Bc();const t=G(),{target:e,close:n}=So(),r=e!==null,o=r&&e!=="new",[s,a]=p.useState(""),[i,u]=p.useState([]),[c,f]=p.useState("");p.useEffect(()=>{if(r){if(o){const y=t.getFieldType(e);a((y==null?void 0:y.label)??""),u((y==null?void 0:y.options)??[])}else a(""),u([]);f("")}},[r,o,e,t]);const d=p.useCallback((y,k)=>{u(w=>w.map(v=>v.value===y?{...v,label:k}:v))},[]),h=p.useCallback(y=>{u(k=>k.filter(w=>w.value!==y))},[]),m=p.useCallback(()=>{const y=c.trim();f(""),y&&u(k=>[...k,{value:E(),label:y,color:Tn(k.length)}])},[c]),g=p.useCallback(()=>{const y=s.trim();y&&(o?t.applyOperation(mo(e,{label:y,options:i})):t.applyOperation(ho({id:E(),label:y,placeholder:"Select…",variant:"tag",options:i})),n())},[t,o,e,s,i,n]),x=p.useCallback(()=>{o&&t.applyOperation(bo(e)),n()},[t,o,e,n]);return l.jsxs(dt,{isOpen:r,onClose:n,title:o?"Edit field type":"New field type",children:[l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Name"}),l.jsx("input",{type:"text",value:s,onChange:y=>a(y.target.value),placeholder:"e.g. Priority, Status…",autoFocus:!0})]}),l.jsxs("div",{className:"be-modal-field",children:[l.jsx("span",{children:"Options"}),i.map((y,k)=>l.jsxs("div",{className:"be-table-header-menu-option-row",children:[l.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(y.color??Tn(k)).bg},"aria-hidden":"true"}),l.jsx("input",{className:"be-table-header-menu-option-input",value:y.label,onChange:w=>d(y.value,w.target.value),"aria-label":`Rename option ${y.label}`}),l.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>h(y.value),"aria-label":`Remove option ${y.label}`,children:l.jsx(Ot,{size:14})})]},y.value)),l.jsxs("div",{className:"be-table-header-menu-option-row",children:[l.jsx("input",{className:"be-table-header-menu-option-input",value:c,onChange:y=>f(y.target.value),placeholder:"New option…",onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),m())}}),l.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:m,"aria-label":"Add option",children:"+"})]})]}),l.jsxs("div",{className:"be-modal-actions",children:[o&&l.jsx("button",{type:"button",className:"be-modal-delete",onClick:x,children:"Delete field type"}),l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:n,children:"Cancel"}),l.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:"Save"})]})]})}exports.APP_MIME=lr;exports.BlockChildren=ht;exports.BlockErrorBoundary=Sl;exports.BlockGutterRow=Bl;exports.BlockRangeActionMenu=Zi;exports.BlockRegistry=il;exports.BlockRenderer=zo;exports.COLUMN_TYPES=Ll;exports.CollabSession=ku;exports.CommentAvatar=Ro;exports.CommentComposer=No;exports.CommentThreadCard=Ao;exports.CommentsPanel=ll;exports.DEFAULT_COLUMN_TYPE=wr;exports.DEFAULT_COLUMN_WIDTH=Ir;exports.DocumentExportButton=vb;exports.EditableBlockContent=pt;exports.EditorProvider=Pa;exports.EditorStore=ur;exports.EditorTrailingSpace=Wi;exports.FieldClockRegistry=en;exports.FieldTypeEditorModal=Ib;exports.FloatingToolbar=pc;exports.HLC=Sn;exports.History=ka;exports.InlineRegistry=ul;exports.LAYOUT_BLOCKS=Ni;exports.ListCrdtState=Qt;exports.MESSAGE_TYPE=Ge;exports.MIN_COLUMN_WIDTH=or;exports.MobileActionBar=gb;exports.MobileBlockOptionsSheet=kc;exports.MobileBlockPickerSheet=yc;exports.Modal=dt;exports.NoteloomEditor=Wm;exports.PeerConnection=wa;exports.Select=Mt;exports.SlashMenu=nr;exports.TABLE_BLOCKS=Li;exports.TABLE_SELECT_INLINE_TYPES=Ki;exports.TableHeaderRow=Yl;exports.TemplatePicker=Du;exports.VoiceListeningIndicator=ib;exports.VoicePermissionModal=lb;exports.addComment=Yu;exports.addCommentMarkOverRange=vo;exports.applyDocumentTemplate=Lu;exports.blankRunForType=Nl;exports.blockquoteBlockType=ri;exports.buttonBlockType=ii;exports.calloutBlockType=ni;exports.canvasBlockType=_i;exports.captureBlockTemplate=Mu;exports.captureSubtree=Bn;exports.checkboxInlineType=zi;exports.codeBlockType=si;exports.convertRunToType=Al;exports.copyBlockRangeToClipboard=ao;exports.createAutoPersistence=Ta;exports.createBlockRegistry=cl;exports.createCellForColumn=Cr;exports.createDefaultColumns=Yo;exports.createInlineRegistry=dl;exports.createPeriodicTombstoneGC=cu;exports.createPeriodicVersionSnapshotter=zu;exports.createSelectFieldType=jc;exports.createWebSocketSignaling=vu;exports.dateInlineType=$i;exports.decodeMessage=va;exports.deleteBlockAndFocusSibling=vr;exports.deleteBlockRange=In;exports.deleteColumn=$l;exports.deleteComment=Na;exports.deleteDocumentVersion=Ra;exports.deleteEntireDocument=ir;exports.deleteOverBlockRange=es;exports.deletePersistedDocument=Cu;exports.deleteRow=Pl;exports.deleteRunRangeInBlock=Qo;exports.deleteTemplate=ju;exports.deserializeClipboard=ec;exports.dividerBlockType=ei;exports.duplicateBlock=Fo;exports.embedBlockType=pi;exports.emojiInlineType=Ui;exports.encodeMessage=Jt;exports.ensureRootNonEmpty=un;exports.exportDocumentHTML=Ea;exports.exportDocumentJSON=ko;exports.exportDocumentSimpleJSON=Rc;exports.exportDocumentText=Ba;exports.focusRunAtOffset=Je;exports.focusRunEnd=ye;exports.focusRunStart=br;exports.genPeerId=xa;exports.getMarksSummaryOverBlockRange=ns;exports.getMarksSummaryOverSelection=ts;exports.headingBlockType=Cl;exports.importDocumentSimpleJSON=yb;exports.injectDefaultStyles=Aa;exports.insertBlockTemplate=ja;exports.insertColumnAfter=sr;exports.insertRowAfter=Ko;exports.isEntireBlockRangeHidden=Gi;exports.isEntireBlockSelected=ac;exports.layoutBlockType=Ql;exports.layoutColumnBlockType=Zl;exports.listDocumentVersions=rr;exports.listItemBlockType=Ml;exports.listPersistedDocumentIds=Su;exports.listTemplates=Qr;exports.listVoiceCommands=tb;exports.loadDocumentVersion=Eu;exports.loadPersistedDocument=Ca;exports.loadTemplate=Tu;exports.moveBlockDown=Vo;exports.moveBlockRangeDown=qi;exports.moveBlockRangeUp=Xi;exports.moveBlockUp=Uo;exports.operations=ru;exports.paragraphBlockType=Il;exports.registerBlockTemplates=Nu;exports.registerBlocks=Mi;exports.registerBuiltInBlocks=Oi;exports.registerBuiltInInlineTypes=Vi;exports.registerInlineTypes=Yi;exports.registerStoredFieldTypes=Ec;exports.remapSubtreeIds=dr;exports.removeCommentMarkEverywhere=wo;exports.renameColumn=Hl;exports.reorderBlockRangeFromStore=mm;exports.replyToComment=Ma;exports.resolveCollapsedCaret=lt;exports.resolveColumns=$e;exports.resolveComment=La;exports.resolveCrossBlockSelection=rn;exports.resolveMultiRunSelection=ln;exports.resolveRunSelection=Pd;exports.saveDocumentVersion=Sa;exports.savePersistedDocument=Ia;exports.saveTemplate=Ru;exports.selectInlineType=Di;exports.serializeBlockRange=En;exports.setBlockRangeHidden=Ji;exports.setColumnOptions=Zn;exports.setColumnType=Fl;exports.setColumnWidth=zl;exports.setMarksOverBlockRange=cr;exports.setMarksOverSelection=sn;exports.tableBlockType=ql;exports.tableCellBlockType=Wl;exports.tableRowBlockType=Xl;exports.tableSelectInlineType=Fi;exports.textToParagraphs=Zo;exports.toggleHeadingBlockType=ai;exports.toggleMarkOnRunRange=Cm;exports.toggleMarkOverBlockRange=os;exports.toggleMarkOverSelection=rs;exports.useAtMenuTrigger=dc;exports.useBlock=be;exports.useBlockChildren=$o;exports.useBlockClassName=Ie;exports.useBlockRangeDrag=ic;exports.useBlockRangeSelection=_n;exports.useBlockRegistry=vt;exports.useCaretRect=xc;exports.useClipboardHandlers=tc;exports.useCoarsePointer=ls;exports.useCommentAuthorId=$a;exports.useComments=za;exports.useDocumentVersions=Hu;exports.useEditor=fm;exports.useEditorKeyboardShortcuts=lc;exports.useEditorStore=G;exports.useEmojiMenuTrigger=uc;exports.useFieldTypeEditor=So;exports.useFieldTypes=hc;exports.useFloatingToolbarTrigger=fc;exports.useHistory=mc;exports.useInlineRegistry=tt;exports.usePersistedDocument=Gm;exports.usePresence=Jm;exports.usePreviewMode=Co;exports.useRegisterFieldTypes=Bc;exports.useRun=wt;exports.useSelectedBlock=ut;exports.useServiceWorkerUpdate=Zm;exports.useSlashMenuTrigger=cc;exports.useTemplates=Au;exports.useTextFormattingActions=as;exports.useVirtualKeyboardInset=Sr;exports.useVoiceTyping=ab;exports.useWholeDocumentSelection=Io;exports.walkDomToBlocks=Qi;
|
|
2533
2927
|
//# sourceMappingURL=noteloom.cjs.map
|