bridgerte 0.9.2 → 0.9.3

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.
@@ -1,3 +0,0 @@
1
- "use strict";var gn=Object.defineProperty;var mn=(e,t,n)=>t in e?gn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Me=(e,t,n)=>mn(e,typeof t!="symbol"?t+"":t,n);const we=require("./bridge.cjs"),G=require("./index-GaS65GL0.cjs"),g=require("lexical"),Q=require("@lexical/rich-text"),H=require("@lexical/code"),U=require("@lexical/list"),B=require("@lexical/table"),z=require("@lexical/link"),$t=require("@lexical/history"),Be=require("@lexical/html"),K=require("@lexical/selection"),De=require("@lexical/utils"),W=require("./native-spec.cjs"),At=require("./core.cjs"),te=require("@floating-ui/dom"),Je="bridgerte-media",Qe=(e,t)=>`${e}:${t}`,ne=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?Math.floor(e):void 0,Ze=e=>typeof e=="number"&&Number.isFinite(e)?Math.min(Math.max(e,0),100):void 0,hn=e=>e===20||e===50||e===100,et=e=>hn(e)?e:void 0,tt=e=>e==="center"||e==="right"?e:void 0,pn=e=>e.status==="error"?e.errorMessage??"媒体加载失败":e.status==="uploading"?`上传中 ${e.progress??0}%`:e.mediaType==="image"?"图片加载中":"视频加载中",ke=(e,t,n)=>{n&&e.setAttribute(t,n)},nt=(e,t,n)=>{n!==void 0&&e.setAttribute(t,String(n))};class ae extends g.DecoratorNode{constructor(n,r){super(r);Me(this,"__payload");this.__payload={...n,assetId:n.assetId??Qe(n.mediaType,n.url),width:ne(n.width),height:ne(n.height),duration:ne(n.duration),progress:Ze(n.progress),displayWidthPercent:et(n.displayWidthPercent),align:tt(n.align)},this.__payload.displayWidthPercent===void 0&&delete this.__payload.displayWidthPercent,this.__payload.align===void 0&&delete this.__payload.align}static getType(){return Je}static clone(n){return new ae(n.__payload,n.__key)}createDOM(n){return this.createMediaElement(!0)}updateDOM(n,r){if(n.__payload===this.__payload)return!1;const o=this.createMediaElement(!0);return r.replaceWith(o),!0}exportDOM(n){return{element:this.createMediaElement(!1)}}static importDOM(){return{img:()=>({conversion:fn,priority:1}),video:()=>({conversion:bn,priority:1})}}static importJSON(n){return se(n).updateFromJSON(n)}exportJSON(){return{...super.exportJSON(),...this.__payload,type:Je}}getTextContent(){return this.__payload.title??this.__payload.alt??this.__payload.url}isInline(){return!1}getAsset(){const n=this.__payload,r={id:n.assetId??Qe(n.mediaType,n.url),type:n.mediaType,url:n.url,status:n.status,progress:n.progress,poster:n.poster,width:n.width,height:n.height,duration:n.duration,mimeType:n.mimeType,size:n.size,errorMessage:n.errorMessage,external:!0};return n.displayWidthPercent!==void 0&&(r.displayWidthPercent=n.displayWidthPercent),n.align!==void 0&&(r.align=n.align),r}updatePayload(n){const r=this.getWritable();r.__payload={...r.__payload,...n,width:ne(n.width??r.__payload.width),height:ne(n.height??r.__payload.height),duration:ne(n.duration??r.__payload.duration),progress:Ze(n.progress??r.__payload.progress),displayWidthPercent:Object.prototype.hasOwnProperty.call(n,"displayWidthPercent")?et(n.displayWidthPercent):r.__payload.displayWidthPercent,align:Object.prototype.hasOwnProperty.call(n,"align")?tt(n.align):r.__payload.align},r.__payload.displayWidthPercent===void 0&&delete r.__payload.displayWidthPercent,r.__payload.align===void 0&&delete r.__payload.align}createMediaElement(n){const r=this.__payload,o=document.createElement("figure"),a=r.mediaType==="image"?document.createElement("img"):document.createElement("video"),s=()=>{o.dataset.loadState="loaded"};if(o.className=`bridgerte__media bridgerte__media--${r.mediaType}`,o.contentEditable="false",o.dataset.assetId=r.assetId,o.dataset.mediaType=r.mediaType,o.dataset.status=r.status??"success",n&&(o.dataset.loadState=r.status==="error"?"error":"loading"),r.progress!==void 0&&(o.dataset.progress=String(r.progress)),r.align!==void 0&&(o.dataset.align=r.align),r.displayWidthPercent!==void 0&&(o.dataset.displayWidthPercent=String(r.displayWidthPercent),o.style.setProperty("--bridgerte-media-display-width",`${r.displayWidthPercent}%`)),r.width!==void 0&&r.height!==void 0&&o.style.setProperty("--bridgerte-media-aspect-ratio",`${r.width} / ${r.height}`),a.className="bridgerte__media-element",n&&(a.addEventListener(r.mediaType==="image"?"load":"loadedmetadata",s,{once:!0}),a.addEventListener("error",()=>{o.dataset.loadState="error"},{once:!0})),r.mediaType==="image"?(a.setAttribute("src",r.url),a.setAttribute("loading","lazy"),ke(a,"alt",r.alt??r.title)):(a.setAttribute("src",r.url),a.setAttribute("controls","true"),a.setAttribute("preload","metadata"),ke(a,"poster",r.poster)),ke(a,"title",r.title),nt(a,"width",r.width),nt(a,"height",r.height),n){const l=document.createElement("div"),c=document.createElement("span"),i=document.createElement("span");l.className="bridgerte__media-placeholder",l.setAttribute("aria-hidden","true"),c.className="bridgerte__media-placeholder-icon",c.textContent=r.mediaType==="image"?"IMG":"VIDEO",i.className="bridgerte__media-placeholder-text",i.textContent=pn(r),l.append(c,i),o.append(l)}if(o.append(a),r.status==="uploading"||r.status==="error"){const l=document.createElement("figcaption");l.className="bridgerte__media-status",l.textContent=r.status==="error"?r.errorMessage??"上传失败":`上传中 ${r.progress??0}%`,o.append(l)}return o}}const fn=e=>{const t=e instanceof HTMLImageElement?e:null;return{node:t!=null&&t.src?se({mediaType:"image",url:t.src,alt:t.alt,title:t.title,width:t.width,height:t.height,status:"success"}):null}},bn=e=>{const t=e instanceof HTMLVideoElement?e:null;return{node:t!=null&&t.src?se({mediaType:"video",url:t.src,poster:t.poster,title:t.title,width:t.videoWidth||t.width,height:t.videoHeight||t.height,status:"success"}):null}},se=e=>g.$applyNodeReplacement(new ae(e)),yn=e=>se({mediaType:"image",url:e.url,alt:e.alt,title:e.title,width:e.width,height:e.height,displayWidthPercent:e.displayWidthPercent,align:e.align,assetId:e.assetId,status:"success"}),vn=e=>se({mediaType:"video",url:e.url,poster:e.poster,title:e.title,width:e.width,height:e.height,displayWidthPercent:e.displayWidthPercent,align:e.align,assetId:e.assetId,status:"success"}),Bt=e=>e instanceof ae,de=e=>{const t=n=>{if(Bt(n)&&n.getAsset().id===e)return n;if(!g.$isElementNode(n))return null;for(const r of n.getChildren()){const o=t(r);if(o)return o}return null};return t(g.$getRoot())},Dt={root:{type:"root",version:1,children:[]}};function Le(e={}){return{html:e.html??"",json:e.json??Dt,plainText:e.plainText??"",assets:e.assets??[],version:e.version??G.BRIDGERTE_CONTENT_VERSION}}const wn=e=>e.toJSON(),Cn=e=>{var t;return((t=e.root.children)==null?void 0:t.length)===0},_n=e=>e.read(()=>{const t=new Map,n=r=>{g.$isElementNode(r)&&r.getChildren().forEach(o=>{if(Bt(o)){const a=o.getAsset();t.set(a.id,a);return}g.$isElementNode(o)&&n(o)})};return n(g.$getRoot()),[...t.values()]}),Ot=(e,t)=>{const n=t.read(()=>Be.$generateHtmlFromNodes(t)),r=e.read(()=>g.$getRoot().getTextContent()),o=_n(e);return{html:n,json:wn(e),plainText:r,assets:o,version:G.BRIDGERTE_CONTENT_VERSION}},En=(e,t)=>{const n=Le(t);return Ht(e,n),Ot(e.getEditorState(),e)},Ht=(e,t)=>{if(t.json!==Dt&&!Cn(t.json)){const o=t.json;e.setEditorState(e.parseEditorState(o));return}if(!t.html){e.update(()=>{const o=g.$getRoot();o.clear(),o.append(g.$createParagraphNode())},{discrete:!0});return}const r=new DOMParser().parseFromString(t.html,"text/html");e.update(()=>{const o=g.$getRoot(),a=Be.$generateNodesFromDOM(e,r);o.clear(),o.append(...a)},{discrete:!0})};class ue extends g.DecoratorNode{static getType(){return"bridgerte-divider"}static clone(t){return new ue(t.__key)}constructor(t){super(t)}createDOM(t){const n=document.createElement("hr");return n.className="bridgerte__divider",n}updateDOM(){return!1}exportDOM(t){const n=document.createElement("hr");return n.className="bridgerte__divider",{element:n}}static importDOM(){return{hr:()=>({conversion:Mn,priority:0})}}static importJSON(t){return Oe().updateFromJSON(t)}exportJSON(){return{...super.exportJSON(),type:ue.getType()}}getTextContent(){return`
2
- `}isInline(){return!1}}const Mn=e=>({node:Oe()}),Oe=()=>g.$applyNodeReplacement(new ue),rt="bridgerte-mention",He="mention",Ft=e=>e.label.startsWith("@")?e.label:`@${e.label}`,kn=e=>{const t=document.createElement("span");return t.className="bridgerte__mention",t.dataset.type=He,t.dataset.id=e.id,t.dataset.value=e.value,t.contentEditable="false",t.textContent=Ft(e),e.description&&(t.dataset.description=e.description),t};class ge extends g.TextNode{constructor(n,r=Ft(n),o){super(r,o);Me(this,"__item");this.__item=n}static getType(){return rt}static clone(n){return new ge(n.__item,n.__text,n.__key)}createDOM(n){const r=super.createDOM(n);return r.className="bridgerte__mention",r.dataset.type=He,r.dataset.id=this.__item.id,r.dataset.value=this.__item.value,r.contentEditable="false",this.__item.description&&(r.dataset.description=this.__item.description),r}updateDOM(n,r,o){return super.updateDOM(n,r,o)?!0:(r.dataset.id=this.__item.id,r.dataset.value=this.__item.value,this.__item.description?r.dataset.description=this.__item.description:delete r.dataset.description,!1)}exportDOM(n){return{element:kn(this.__item)}}static importDOM(){return{span:()=>({conversion:xn,priority:2})}}static importJSON(n){return Fe(n).updateFromJSON(n)}exportJSON(){return{...super.exportJSON(),...this.__item,type:rt}}isTextEntity(){return!0}isToken(){return!0}getMentionItem(){return this.__item}}const xn=e=>{var a;const t=e instanceof HTMLElement?e:null;if(!t||t.dataset.type!==He)return{node:null};const n=((a=t.textContent)==null?void 0:a.replace(/^@/,""))||t.dataset.value||"",r=t.dataset.id||t.dataset.value||n,o=t.dataset.value||r;return!n||!r||!o?{node:null}:{node:Fe({id:r,label:n,value:o,description:t.dataset.description})}},Fe=e=>g.$applyNodeReplacement(new ge(e).setMode("token")),ot=e=>e instanceof ge,Tn="请输入内容",Nn=()=>{const t=g.$getRoot().getChildren();if(t.length===0)return!0;if(t.length>1)return!1;const n=t[0];return g.$isParagraphNode(n)&&n.getChildrenSize()===0},Sn=({editor:e,contentElement:t})=>{const n=e.getEditorState().read(Nn);t.dataset.empty=String(n)},Ln=({editor:e,contentElement:t,isReadonly:n})=>{const r=o=>{n()||t.dataset.empty!=="true"||o.button===0&&(o.preventDefault(),e.focus(()=>{e.update(()=>{g.$getRoot().selectStart()})}))};return t.addEventListener("pointerdown",r),()=>{t.removeEventListener("pointerdown",r)}},Rn=[{command:"format.bold",format:"bold"},{command:"format.italic",format:"italic"},{command:"format.underline",format:"underline"},{command:"format.strike",format:"strikethrough"},{command:"format.inlineCode",format:"code"},{command:"format.superscript",format:"superscript"},{command:"format.subscript",format:"subscript"}],Pn=[{command:"format.color",property:"color"},{command:"format.backgroundColor",property:"background-color"},{command:"format.fontSize",property:"font-size"},{command:"format.fontFamily",property:"font-family"},{command:"format.lineHeight",property:"line-height"}],In=[{command:"list.ordered",listType:"ordered"},{command:"list.unordered",listType:"unordered"},{command:"list.todo",listType:"todo"}],$n=["media.pickImage","media.pickVideo"],zt=()=>{const e=g.$getSelection();if(!g.$isRangeSelection(e))return null;const t=e.anchor.getNode();return t.getKey()==="root"?t:t.getTopLevelElementOrThrow()},An=()=>{const e=zt();if(!e)return null;if(Q.$isHeadingNode(e)){const t=Number(e.getTag().replace("h",""));return{command:"block.heading",value:Number.isNaN(t)?void 0:t}}if(Q.$isQuoteNode(e))return{command:"block.quote"};if(H.$isCodeNode(e)){const t=e.getLatest();return{command:"block.code",value:H.$isCodeNode(t)?t.getLanguage()??"":""}}return{command:"block.paragraph"}},Bn=()=>{const e=zt();if(!e||!("getFormatType"in e))return;const t=e.getFormatType();return t===""?void 0:t},Dn=()=>{const e=g.$getSelection();if(!g.$isRangeSelection(e))return null;const t=e.anchor.getNode(),n=U.$isListNode(t)?t:De.$getNearestNodeOfType(t,U.ListNode);return n?n.getListType()==="check"?"todo":n.getTag()==="ol"?"ordered":"unordered":null},On=e=>{const t=g.$getSelection();if(!g.$isRangeSelection(t))return;const n=K.$getSelectionStyleValueForProperty(t,e);return n===""?void 0:n},Hn=()=>{const e=g.$getSelection();if(!g.$isRangeSelection(e))return!1;const t=e.anchor.getNode(),n=t.getParent();return z.$isLinkNode(t)||z.$isLinkNode(n)},Fn=e=>{const t=g.$getSelection(),n=g.$isRangeSelection(t),r=An(),o=Dn(),a=Bn(),s=Hn(),l=e.readonly||!n,c=Rn.map(E=>({command:E.command,active:n&&t.hasFormat(E.format),disabled:l})),i=Pn.map(E=>{const T=On(E.property);return{command:E.command,active:T!==void 0,disabled:l,value:T}}),m=In.map(E=>({command:E.command,active:o===E.listType,disabled:l})),_=$n.map(E=>({command:E,active:!1,disabled:e.readonly||!e.canUploadMedia}));return[...c,{command:"format.clear",active:!1,disabled:l},...i,{command:"block.heading",active:(r==null?void 0:r.command)==="block.heading",disabled:l,value:(r==null?void 0:r.command)==="block.heading"?r.value:void 0},{command:"block.paragraph",active:(r==null?void 0:r.command)==="block.paragraph",disabled:l},{command:"block.quote",active:(r==null?void 0:r.command)==="block.quote",disabled:l},{command:"block.divider",active:!1,disabled:e.readonly},{command:"block.code",active:(r==null?void 0:r.command)==="block.code",disabled:e.readonly,value:(r==null?void 0:r.command)==="block.code"?r.value:void 0},...m,{command:"align",active:a!==void 0,disabled:l,value:a},{command:"link.set",active:s,disabled:l},{command:"link.unset",active:!1,disabled:l||!s},{command:"link.open",active:!1,disabled:e.readonly||!s},{command:"indent.increase",active:!1,disabled:l},{command:"indent.decrease",active:!1,disabled:l},{command:"history.undo",active:!1,disabled:e.readonly||!e.canUndo},{command:"history.redo",active:!1,disabled:e.readonly||!e.canRedo},{command:"content.clear",active:!1,disabled:e.readonly},..._,{command:"table.insert",active:!1,disabled:e.readonly},{command:"fullscreen.toggle",active:!1,disabled:!1}]},zn=(e,t)=>e.length===t.length&&e.every((n,r)=>{const o=t[r];return o!==void 0&&n.command===o.command&&n.active===o.active&&n.disabled===o.disabled&&n.value===o.value}),q=(e,t,n,r)=>{var o;try{(o=e.onError)==null||o.call(e,{code:t,message:n,cause:r})}catch(a){console.error("[BridgeRTE] onError callback failed.",a)}},Wn=(e,t)=>{var n;try{(n=e.onChange)==null||n.call(e,t)}catch(r){q(e,"callback.onChange","onChange callback failed.",r)}},Vn=(e,t)=>{var n;try{(n=e.onContentChange)==null||n.call(e,t)}catch(r){q(e,"callback.onContentChange","onContentChange callback failed.",r)}},Un=(e,t)=>{var n;try{(n=e.onCommandStateChange)==null||n.call(e,[...t])}catch(r){q(e,"callback.onCommandStateChange","onCommandStateChange callback failed.",r)}},qn=e=>{var t;try{(t=e.onFocus)==null||t.call(e)}catch(n){q(e,"callback.onFocus","onFocus callback failed.",n)}},jn=e=>{var t;try{(t=e.onBlur)==null||t.call(e)}catch(n){q(e,"callback.onBlur","onBlur callback failed.",n)}},Kn=(e,t)=>{var n;try{(n=e.onReady)==null||n.call(e,t)}catch(r){q(e,"callback.onReady","onReady callback failed.",r)}},Gn=({lexicalEditor:e,options:t,isDestroyed:n,canUploadMedia:r,isReadonly:o})=>{let a=!1,s=!1,l=[];const c=new Set,i=()=>{const _=[...l];c.forEach(E=>{try{E(_)}catch(T){q(t,"callback.commandStateSubscriber","Command state subscriber failed.",T)}})},m=(_=!0)=>{if(n())return;const E=l;e.getEditorState().read(()=>{l=Fn({canUndo:a,canRedo:s,readonly:o(),canUploadMedia:r()})}),_&&!zn(E,l)&&(Un(t,l),i())};return{refreshCommandStates:m,getCommandStates(){return m(!1),[...l]},subscribeCommandStateChange(_){return n()?()=>{}:(c.add(_),_([...l]),()=>{c.delete(_)})},setCanUndo(_){a=_,m()},setCanRedo(_){s=_,m()},setHistoryAvailability(_,E){a=_,s=E,m()},destroy(){c.clear()}}},Yn=e=>`upload:${e}:${Date.now()}:${Math.random().toString(36).slice(2)}`,Xn=e=>typeof URL.createObjectURL=="function"?URL.createObjectURL(e):e.name,me=e=>{typeof URL.revokeObjectURL=="function"&&e.startsWith("blob:")&&URL.revokeObjectURL(e)},at=e=>({name:e.name,mimeType:e.type||void 0,size:e.size,data:e}),Jn=e=>typeof DOMException<"u"&&e instanceof DOMException&&e.name==="AbortError",Qn=({container:e,lexicalEditor:t,options:n,isDestroyed:r})=>{const o=new Map;let a=0;const s=(h,w)=>{t.update(()=>{var S;(S=de(h))==null||S.updatePayload(w)})},l=h=>{let w=null;return t.update(()=>{const S=de(h);if(!S)return;const k=S.getAsset();w={mediaType:k.type,url:k.url,assetId:k.id,status:k.status,progress:k.progress,poster:k.poster,width:k.width,height:k.height,duration:k.duration,mimeType:k.mimeType,size:k.size,displayWidthPercent:k.displayWidthPercent,align:k.align,errorMessage:k.errorMessage},S.remove()}),w},c=(h,w)=>{const S=o.get(h);return(S==null?void 0:S.runId)===w},i=h=>{var w;(w=h.abortController)==null||w.abort()},m=(h,w)=>{const S=o.get(h);return S?(i(S),me(S.previewUrl),o.delete(h),!0):!1},_=(h,w,S,k)=>{t.update(()=>{const P=se({mediaType:h,url:k,assetId:S,status:"uploading",progress:0,title:w.name,mimeType:w.type||void 0,size:w.size}),I=g.$createParagraphNode();g.$getSelection()||g.$getRoot().selectEnd(),g.$insertNodes([P,I]),I.selectStart()},{discrete:!0})},E=(h,w,S,k)=>{s(w,{mediaType:h,url:k.url,poster:k.poster,width:k.width,height:k.height,duration:k.duration,mimeType:k.mimeType,size:k.size,status:"success",progress:100,errorMessage:void 0}),me(S)},T=(h,w,S)=>{var k;Jn(S)||(s(w,{mediaType:h,status:"error",errorMessage:"上传失败"}),(k=n.onUploadError)==null||k.call(n,{assetId:w,type:h,cause:S}))},p=h=>{const w=n.uploadAdapter;if(!w)return;const S=typeof AbortController=="function"?new AbortController:null,k=a+1;a=k,h.runId=k,h.abortController=S,o.set(h.assetId,h);const P={assetId:h.assetId,signal:S==null?void 0:S.signal,onProgress:M=>{!c(h.assetId,k)||r()||s(h.assetId,{mediaType:h.type,status:"uploading",progress:M})}};let I;try{I=h.type==="image"?w.uploadImage(at(h.file),P):w.uploadVideo(at(h.file),P)}catch(M){c(h.assetId,k)&&T(h.type,h.assetId,M);return}I.then(M=>{r()||!c(h.assetId,k)||(E(h.type,h.assetId,h.previewUrl,M),o.delete(h.assetId))}).catch(M=>{r()||!c(h.assetId,k)||T(h.type,h.assetId,M)})},y=(h,w)=>{if(!n.uploadAdapter)return;const S=Yn(h),k=Xn(w),P={assetId:S,type:h,file:w,previewUrl:k,runId:0,abortController:null};_(h,w,S,k),p(P)};return{pickMediaFile:h=>{if(!n.uploadAdapter)return;const w=e.ownerDocument.createElement("input");w.type="file",w.accept=h==="image"?"image/*":"video/*",w.style.display="none",w.addEventListener("change",()=>{var k;const S=(k=w.files)==null?void 0:k[0];w.remove(),S&&y(h,S)},{once:!0}),e.append(w),w.click()},uploadMediaFile:y,removeMedia(h){const w=l(h);!m(h)&&(w!=null&&w.url.startsWith("blob:"))&&me(w.url)},retryMedia(h){const w=o.get(h);!w||!n.uploadAdapter||(i(w),s(h,{mediaType:w.type,url:w.previewUrl,status:"uploading",progress:0,errorMessage:void 0}),p(w))},destroy(){o.forEach(h=>{i(h),me(h.previewUrl)}),o.clear()}}},Zn=e=>H.$createCodeNode(e),er={1:"h1",2:"h2",3:"h3",4:"h4",5:"h5",6:"h6"},tr={code:"bridgerte__code-block",codeHighlight:{attr:"bridgerte__code-token bridgerte__code-token--attr","attr-name":"bridgerte__code-token bridgerte__code-token--attr-name","attr-value":"bridgerte__code-token bridgerte__code-token--attr-value",boolean:"bridgerte__code-token bridgerte__code-token--boolean",builtin:"bridgerte__code-token bridgerte__code-token--builtin","class-name":"bridgerte__code-token bridgerte__code-token--class-name",comment:"bridgerte__code-token bridgerte__code-token--comment",constant:"bridgerte__code-token bridgerte__code-token--constant",deleted:"bridgerte__code-token bridgerte__code-token--deleted",function:"bridgerte__code-token bridgerte__code-token--function",inserted:"bridgerte__code-token bridgerte__code-token--inserted",keyword:"bridgerte__code-token bridgerte__code-token--keyword",namespace:"bridgerte__code-token bridgerte__code-token--namespace",number:"bridgerte__code-token bridgerte__code-token--number",operator:"bridgerte__code-token bridgerte__code-token--operator",prefix:"bridgerte__code-token bridgerte__code-token--prefix",property:"bridgerte__code-token bridgerte__code-token--property",punctuation:"bridgerte__code-token bridgerte__code-token--punctuation",regex:"bridgerte__code-token bridgerte__code-token--regex",selector:"bridgerte__code-token bridgerte__code-token--selector",string:"bridgerte__code-token bridgerte__code-token--string",tag:"bridgerte__code-token bridgerte__code-token--tag",unchanged:"bridgerte__code-token bridgerte__code-token--unchanged",url:"bridgerte__code-token bridgerte__code-token--url",variable:"bridgerte__code-token bridgerte__code-token--variable"},heading:{h1:"bridgerte__heading bridgerte__heading--h1",h2:"bridgerte__heading bridgerte__heading--h2",h3:"bridgerte__heading bridgerte__heading--h3",h4:"bridgerte__heading bridgerte__heading--h4",h5:"bridgerte__heading bridgerte__heading--h5",h6:"bridgerte__heading bridgerte__heading--h6"},list:{checklist:"bridgerte__list bridgerte__list--todo",ol:"bridgerte__list",ul:"bridgerte__list",listitem:"bridgerte__list-item",listitemChecked:"bridgerte__list-item bridgerte__list-item--checked",listitemUnchecked:"bridgerte__list-item bridgerte__list-item--unchecked"},paragraph:"bridgerte__paragraph",quote:"bridgerte__quote",root:"bridgerte__content-root",text:{bold:"bridgerte__text--bold",code:"bridgerte__code",italic:"bridgerte__text--italic",strikethrough:"bridgerte__text--strike",underline:"bridgerte__text--underline",underlineStrikethrough:"bridgerte__text--underline-strike"},table:"bridgerte__table",tableCell:"bridgerte__table-cell",tableCellHeader:"bridgerte__table-cell bridgerte__table-cell--header",tableRow:"bridgerte__table-row",tableScrollableWrapper:"bridgerte__table-wrapper"},nr=e=>({setBlockHeading:i=>{e.update(()=>{const m=g.$getSelection();g.$isRangeSelection(m)&&K.$setBlocksType(m,()=>Q.$createHeadingNode(er[i]))})},setParagraphBlock:()=>{e.update(()=>{const i=g.$getSelection();g.$isRangeSelection(i)&&K.$setBlocksType(i,()=>g.$createParagraphNode())})},setQuoteBlock:()=>{e.update(()=>{const i=g.$getSelection();g.$isRangeSelection(i)&&K.$setBlocksType(i,()=>Q.$createQuoteNode())})},insertDividerBlock:()=>{e.update(()=>{const i=g.$createParagraphNode();g.$insertNodes([Oe(),i]),i.selectStart()})},insertCodeBlock:i=>{e.update(()=>{const m=Zn(i),_=g.$createParagraphNode();g.$insertNodes([m,_]),m.selectEnd()})},setSelectedCodeBlockLanguage:i=>{e.update(()=>{const m=g.$getSelection();if(!g.$isRangeSelection(m))return;const _=m.anchor.getNode(),E=_.getKey()==="root"?_:_.getTopLevelElementOrThrow();H.$isCodeNode(E)&&E.setLanguage(i)})},clearContent:()=>{e.update(()=>{const i=g.$getRoot();i.clear(),i.append(g.$createParagraphNode())})},formatAlign:i=>{e.dispatchCommand(g.FORMAT_ELEMENT_COMMAND,i)}}),rr=e=>({setLink:(o,a)=>{e.update(()=>{const s=g.$getSelection(),l=z.formatUrl(o),c=(a==null?void 0:a.trim())||o.trim();if(!(!g.$isRangeSelection(s)||!o.trim())){if(s.isCollapsed()){const i=z.$createLinkNode(l,{rel:"noreferrer noopener",target:"_blank"});i.append(g.$createTextNode(c)),g.$insertNodes([i]);return}z.$toggleLink(l,{rel:"noreferrer noopener",target:"_blank"})}})},unsetLink:()=>{e.update(()=>{z.$toggleLink(null)})},openSelectedLink:()=>{if(typeof window>"u")return;const o=e.getEditorState().read(()=>{const a=g.$getSelection();if(!g.$isRangeSelection(a))return null;const s=a.anchor.getNode(),l=z.$isLinkNode(s)?s:De.$findMatchingParent(s,z.$isLinkNode);return l?{target:l.getTarget()??"_blank",url:l.sanitizeUrl(l.getURL())}:null});o&&window.open(o.url,o.target,"noopener,noreferrer")}}),or=e=>({insertImage:s=>{s.url.trim()&&e.update(()=>{const l=g.$createParagraphNode();g.$insertNodes([yn(s),l]),l.selectStart()})},insertVideo:s=>{s.url.trim()&&e.update(()=>{const l=g.$createParagraphNode();g.$insertNodes([vn(s),l]),l.selectStart()})},resizeMedia:s=>{e.update(()=>{var l;(l=de(s.assetId))==null||l.updatePayload({displayWidthPercent:s.widthPercent})})},resetMediaSize:s=>{e.update(()=>{var l;(l=de(s))==null||l.updatePayload({displayWidthPercent:void 0})})},alignMedia:s=>{e.update(()=>{var l;(l=de(s.assetId))==null||l.updatePayload({align:s.value==="left"?void 0:s.value})})}}),ar=e=>({insertMention:n=>{e.update(()=>{const r=g.$getSelection();g.$isRangeSelection(r)&&g.$insertNodes([Fe(n),g.$createTextNode(" ")])})}}),sr=e=>({clearSelectionFormat:()=>{e.update(()=>{const r=g.$getSelection();g.$isRangeSelection(r)&&(r.setFormat(0),K.$patchStyleText(r,{color:null,"background-color":null,"font-size":null,"font-family":null,"line-height":null}))})},setSelectionStyle:(r,o)=>{e.update(()=>{const a=g.$getSelection();g.$isRangeSelection(a)&&K.$patchStyleText(a,{[r]:o===""?null:o})})}}),ir=20,st=(e,t)=>Number.isFinite(e)&&e>0?Math.min(Math.floor(e),t):1,he=e=>Number.isFinite(e)&&(e??0)>0?Math.min(Math.floor(e??1),ir):1,pe=()=>{const e=g.$getSelection();return!g.$isRangeSelection(e)&&!B.$isTableSelection(e)?!1:B.$findCellNode(e.anchor.getNode())!==null},lr=e=>({insertTable:(l,c)=>{const i=st(l,G.BRIDGERTE_TABLE_INSERT_MAX_ROWS),m=st(c,G.BRIDGERTE_TABLE_INSERT_MAX_COLS);e.dispatchCommand(B.INSERT_TABLE_COMMAND,{rows:String(i),columns:String(m),includeHeaders:{rows:!0,columns:!1}})},insertTableRow:l=>{e.update(()=>{if(!pe())return;const c=he(l.count);for(let i=0;i<c;i+=1)B.$insertTableRowAtSelection(l.direction!=="before")})},insertTableColumn:l=>{e.update(()=>{if(!pe())return;const c=he(l.count);for(let i=0;i<c;i+=1)B.$insertTableColumnAtSelection(l.direction!=="before")})},deleteTableRow:l=>{e.update(()=>{const c=he(l.count);for(let i=0;i<c;i+=1){if(!pe())return;B.$deleteTableRowAtSelection()}})},deleteTableColumn:l=>{e.update(()=>{const c=he(l.count);for(let i=0;i<c;i+=1){if(!pe())return;B.$deleteTableColumnAtSelection()}})},deleteTable:()=>{e.update(()=>{const l=g.$getSelection();if(!g.$isRangeSelection(l)&&!B.$isTableSelection(l))return;const c=B.$findTableNode(l.anchor.getNode());if(!c)return;const i=g.$createParagraphNode();c.insertAfter(i),c.remove(),i.selectStart()})}}),cr=e=>{const t=lr(e);return{insertTable:n=>{t.insertTable(n.rows,n.cols)},insertTableRow:n=>{t.insertTableRow(n)},insertTableColumn:n=>{t.insertTableColumn(n)},deleteTableRow:n=>{t.deleteTableRow(n)},deleteTableColumn:n=>{t.deleteTableColumn(n)},deleteTable:()=>{t.deleteTable()}}},dr={"format.bold":"bold","format.italic":"italic","format.underline":"underline","format.strike":"strikethrough","format.inlineCode":"code","format.superscript":"superscript","format.subscript":"subscript"},ur={"list.ordered":U.INSERT_ORDERED_LIST_COMMAND,"list.unordered":U.INSERT_UNORDERED_LIST_COMMAND,"list.todo":U.INSERT_CHECK_LIST_COMMAND},gr={"indent.increase":g.INDENT_CONTENT_COMMAND,"indent.decrease":g.OUTDENT_CONTENT_COMMAND,"history.undo":g.UNDO_COMMAND,"history.redo":g.REDO_COMMAND},mr={"format.color":"color","format.backgroundColor":"background-color","format.fontSize":"font-size","format.fontFamily":"font-family","format.lineHeight":"line-height"},hr=({container:e,lexicalEditor:t,options:n,isDestroyed:r,isReadonly:o,reportError:a})=>{const s=Qn({container:e,lexicalEditor:t,options:n,isDestroyed:r}),l=nr(t),c=rr(t),i=or(t),m=ar(t),_=sr(t),E=cr(t),T=()=>{var N,h;if(document.fullscreenElement){(N=document.exitFullscreen)==null||N.call(document).catch(w=>{a(n,"fullscreen.exit","Exit fullscreen failed.",w)});return}(h=e.requestFullscreen)==null||h.call(e).catch(w=>{a(n,"fullscreen.enter","Enter fullscreen failed.",w)})},p=(y=>{if(r()||o())return;const N=dr[y.type];if(N){t.dispatchCommand(g.FORMAT_TEXT_COMMAND,N);return}const h=ur[y.type];if(h){t.dispatchCommand(h,void 0);return}const w=gr[y.type];if(w){t.dispatchCommand(w,void 0);return}const S=mr[y.type];if(S&&"value"in y){_.setSelectionStyle(S,y.value);return}switch(y.type){case"format.clear":_.clearSelectionFormat();return;case"block.heading":l.setBlockHeading(y.level);return;case"block.paragraph":l.setParagraphBlock();return;case"block.quote":l.setQuoteBlock();return;case"block.divider":l.insertDividerBlock();return;case"block.code":l.insertCodeBlock(y.language);return;case"block.setCodeLanguage":l.setSelectedCodeBlockLanguage(y.language);return;case"align":l.formatAlign(y.value);return;case"link.set":c.setLink(y.href,y.text);return;case"link.unset":c.unsetLink();return;case"link.open":c.openSelectedLink();return;case"mention.insert":m.insertMention(y.item);return;case"content.clear":l.clearContent();return;case"table.insert":E.insertTable(y);return;case"table.insertRow":E.insertTableRow(y);return;case"table.insertColumn":E.insertTableColumn(y);return;case"table.deleteRow":E.deleteTableRow(y);return;case"table.deleteColumn":E.deleteTableColumn(y);return;case"table.delete":E.deleteTable();return;case"media.insertImage":i.insertImage(y);return;case"media.insertVideo":i.insertVideo(y);return;case"media.pickImage":s.pickMediaFile("image");return;case"media.pickVideo":s.pickMediaFile("video");return;case"media.retry":s.retryMedia(y.assetId);return;case"media.remove":s.removeMedia(y.assetId);return;case"media.resize":i.resizeMedia(y);return;case"media.align":i.alignMedia(y);return;case"media.resetSize":i.resetMediaSize(y.assetId);return;case"fullscreen.toggle":T();return}});return p.uploadMediaFile=s.uploadMediaFile,p.destroy=()=>{s.destroy()},p},pr=300,fr="BridgeRTE",it=({editor:e,overflowLength:t})=>{if(t<=0)return!1;const n=g.$getSelection();if(g.$isRangeSelection(n))return K.$trimTextContentFromAnchor(e,n.anchor,t),!0;g.$getRoot().selectEnd();const r=g.$getSelection();return g.$isRangeSelection(r)?(K.$trimTextContentFromAnchor(e,r.anchor,t),!0):!1},br=({lexicalEditor:e,options:t,isDestroyed:n,setContent:r,syncPlaceholder:o})=>{let a=0,s=null;const l=()=>{s&&(clearTimeout(s),s=null)},c=h=>{if(n())return;const w=Ot(e.getEditorState(),e);r(w),h&&Wn(t,w)},i=h=>{const w=t.maxLength!==void 0&&t.maxLength>=0?t.maxLength:void 0;return{dirty:!0,plainTextLength:h,version:G.BRIDGERTE_CONTENT_VERSION,maxLength:w,isOverMaxLength:w===void 0?!1:h>w}},m=h=>{Vn(t,i(h))},_=()=>{t.onChange&&(l(),s=setTimeout(()=>{c(!0)},we.BRIDGE_CONTENT_CHANGE_DEBOUNCE_MS))},E=h=>{if(a>0){a-=1;return}m(h),_()},T=()=>e.getEditorState().read(()=>g.$getRoot().getTextContent().length),p=h=>t.maxLength===void 0||t.maxLength<0?0:h-t.maxLength,y=h=>h<=0?!1:(e.update(()=>{it({editor:e,overflowLength:h})},{discrete:!0}),!0);return{clearContentChangeTimer:l,enforceCurrentMaxLength:()=>{t.maxLength===void 0||t.maxLength<0||e.update(()=>{const h=g.$getRoot().getTextContent().length-(t.maxLength??0);it({editor:e,overflowLength:h})},{discrete:!0})},syncContent:c,suppressNextChange(){a+=1},syncAfterEditorUpdate(){const h=T();if(y(p(h))){o();return}o(),E(h)}}},Ce="data-language",Wt="纯文本",yr="language",vr=new Set(["plain","plaintext","text","txt"]),wr=[Ce,"data-lang","data-code-language","data-highlight-language","lang","language"],Cr=/^[a-z][a-z0-9_+#.-]{0,31}$/i,_r=/^(?:language|lang)-([a-z][a-z0-9_+#.-]{0,31})$/i,Er=/^brush:\s*([a-z][a-z0-9_+#.-]{0,31})$/i,Mr=new Map([["js","javascript"],["jsx","javascript"],["py","python"],["rs","rust"],["ts","typescript"],["tsx","typescript"]]),kr=e=>e.type==="select",xr=e=>e.find(t=>t.name===yr&&kr(t)),Z=e=>{const t=e==null?void 0:e.trim().toLowerCase();return!t||!Cr.test(t)?null:Mr.get(t)??t},Tr=e=>{for(const t of wr){const n=Z(e.getAttribute(t));if(n)return n}return null},Nr=e=>{const[,t]=e.match(Er)??[],n=Z(t);if(n)return n;for(const r of e.split(/\s+/)){const[,o]=r.match(_r)??[],a=Z(o);if(a)return a}return null},Sr=()=>{const e=H.getCodeLanguageOptions().filter(([t])=>!vr.has(t)).map(([t,n])=>({label:n,value:Z(t)??t}));return[{label:Wt,value:""},...e]},lt=Sr(),Vt=(e=W.codeBlockLanguagePanel)=>{var t;return e===W.codeBlockLanguagePanel?lt:((t=xr(e.fields))==null?void 0:t.options)??lt},Ut=(e,t)=>{var n,r,o;return((n=e.find(a=>a.value===t))==null?void 0:n.label)??((r=e.find(a=>Z(a.value)===Z(t)))==null?void 0:r.label)??((o=e[0])==null?void 0:o.label)??Wt};Vt();const Lr=e=>{[...e.querySelectorAll("pre,code")].forEach(t=>{const n=Tr(t)??Nr(t.className),r=t.tagName==="PRE"?t:t.closest("pre");r&&n&&r.setAttribute(Ce,n)})},Rr=e=>{e.querySelectorAll("pre").forEach(t=>{[...t.children].forEach(r=>{r.tagName==="CODE"&&r.replaceWith(...r.childNodes)})})},Pr=(e,t)=>{const n=[...t.querySelectorAll("pre[data-language]")];let r=0;e.forEach(o=>{if(!H.$isCodeNode(o))return;const a=n[r];if(r+=1,!a)return;const s=a.getAttribute(Ce);s&&!o.getLanguage()&&o.setLanguage(s)})},re=12,ct=6,dt=(e,t,n)=>Math.min(Math.max(e,t),Math.max(t,n)),Ir=()=>{const e=window.visualViewport;return{left:(e==null?void 0:e.offsetLeft)??0,top:(e==null?void 0:e.offsetTop)??0,width:(e==null?void 0:e.width)??window.innerWidth,height:(e==null?void 0:e.height)??window.innerHeight}},$r=e=>{const t=e.style.visibility,n=e.style.pointerEvents,r=e.style.display;e.style.visibility="hidden",e.style.pointerEvents="none",e.style.display="grid";const o=e.getBoundingClientRect();return e.style.visibility=t,e.style.pointerEvents=n,e.style.display=r,o},Ar=(e,t,n)=>{const r=$r(e),o=Ir(),a=t.getBoundingClientRect(),s=a.left+re,l=a.top+re,c=n?n.x:s,i=n?n.y+n.height+ct:l,m=n?n.y-r.height-ct:i,_=o.left+re,E=o.top+re,T=o.left+o.width-r.width-re,p=o.top+o.height-r.height-re,y=i>p?m:i;return{left:dt(c,_,T),top:dt(y,E,p),viewportHeight:o.height}},qt=e=>{var c,i;const t=document.createElement("div"),n=document.createElement("div"),r=document.createElement("div");let o;const a=()=>{t.dataset.visible="false",n.dataset.visible="false",o=void 0},s=()=>{const m=Ar(n,e.root,o);n.style.left=`${m.left}px`,n.style.top=`${m.top}px`,n.style.setProperty("--bridgerte-dialog-visible-height",`${m.viewportHeight}px`)},l=m=>{o=m,m?n.style.setProperty("--bridgerte-dialog-anchor-width",`${m.width}px`):n.style.removeProperty("--bridgerte-dialog-anchor-width"),s(),t.dataset.visible="true",n.dataset.visible="true"};return t.className="bridgerte__dialog-backdrop",t.dataset.visible="false",n.className=`bridgerte__dialog ${e.className}`,n.dataset.visible="false",r.className="bridgerte__dialog-content",n.append(r),e.root.append(t,n),t.addEventListener("click",()=>{var m;(m=e.onBackdropClick)==null||m.call(e),a()}),(c=window.visualViewport)==null||c.addEventListener("resize",s),(i=window.visualViewport)==null||i.addEventListener("scroll",s),window.addEventListener("resize",s),{element:n,content:r,open:l,close:a,destroy(){var m,_;a(),(m=window.visualViewport)==null||m.removeEventListener("resize",s),(_=window.visualViewport)==null||_.removeEventListener("scroll",s),window.removeEventListener("resize",s),t.remove(),n.remove()}}},ve=e=>typeof requestAnimationFrame=="function"?requestAnimationFrame(e):window.setTimeout(e,0),ze=e=>{if(typeof cancelAnimationFrame=="function"){cancelAnimationFrame(e);return}window.clearTimeout(e)},V=(e,t={})=>{let n=null;const r=s=>{const l=n??e;if(!(!s&&!n)){if(s){l.dataset.pressed="true";return}delete l.dataset.pressed,n=null}},o=s=>{if(s.pointerType==="mouse")return;const l=s.target;n=l instanceof HTMLElement&&t.targetSelector?l.closest(t.targetSelector):e,n&&r(!0)},a=()=>{r(!1)};return e.addEventListener("pointerdown",o),e.addEventListener("pointerup",a),e.addEventListener("pointercancel",a),e.addEventListener("lostpointercapture",a),()=>{a(),e.removeEventListener("pointerdown",o),e.removeEventListener("pointerup",a),e.removeEventListener("pointercancel",a),e.removeEventListener("lostpointercapture",a)}},ut="language",Br="bridgerte-code-block-language",gt=8;let mt=0;const Dr=()=>(mt+=1,`${Br}-${mt}`),Or=(e,t,n)=>{const r=e.querySelector(".bridgerte__code-block-control-label");e.dataset.language=n??"",r&&(r.textContent=Ut(t,n))},Hr=(e,t)=>{const n=document.createElement("button"),r=document.createElement("span"),o=document.createElement("span");return n.type="button",n.className="bridgerte__code-block-control",n.contentEditable="false",n.dataset.language=t??"",n.setAttribute("aria-label","选择代码块语言"),r.className="bridgerte__code-block-control-label",r.textContent=Ut(e,t),o.className="bridgerte__code-block-control-arrow",n.append(r,o),n},Fr=e=>e.querySelector(".bridgerte__content")??e,zr=e=>{const t=document.createElement("div"),n=Fr(e.root),r=At.resolvePayloadPanelSchema(e.languagePanel??W.codeBlockLanguagePanel,e.payloadPanelConfig),o=Vt(r);let a=null,s=null;const l=new Map,c=new Map,i=()=>{a==null||a.close()},m=(M,f)=>{e.isReadonly()||e.editor.update(()=>{const u=g.$getNodeByKey(M);H.$isCodeNode(u)&&u.setLanguage(f)})},_=(M,f)=>{ve(()=>{m(M,f)})},E=(M,f,u)=>{var d;return((d=e.onRequest)==null?void 0:d.call(e,{id:Dr(),readonly:e.isReadonly(),menuId:"code-block-language",command:{type:"block.setCodeLanguage",language:u},panel:r,anchorRect:{x:f.left,y:f.top,width:f.width,height:f.height},currentValues:{[ut]:u},submit:b=>{i(),_(M,b[ut]??"")},cancel:i}))===!0},T=(M,f)=>{const u=e.root.getBoundingClientRect(),d=f.getBoundingClientRect(),b=d.bottom<u.top||d.top>u.bottom;M.hidden=b,M.style.transform=`translate(${d.left-u.left+gt}px, ${d.top-u.top+gt}px)`},p=M=>{var C;const f=e.editor.getElementByKey(M);if(!f){(C=l.get(M))==null||C.remove(),l.delete(M);return}f.dataset.lexicalKey=M;const u=f.getAttribute("data-language"),d=l.get(M);if(d){Or(d,o,u),T(d,f);return}const b=Hr(o,u),v=V(b);b.dataset.lexicalKey=M,l.set(M,b),c.set(b,v),t.append(b),T(b,f)},y=()=>{s=null,l.forEach((M,f)=>{p(f)})},N=()=>{s===null&&(s=ve(y))},h=(M,f)=>{const u=M.getBoundingClientRect(),d=M.dataset.language??"";if(E(f,u,d))return;if(e.isReadonly()){i();return}a||(a=qt({root:e.root,className:"bridgerte__code-block-menu",onBackdropClick:i}));const b=document.createElement("div");a.content.replaceChildren(),a.element.style.minWidth="180px",b.className="bridgerte__code-block-menu-list",o.forEach(v=>{const C=document.createElement("button");C.type="button",C.className="bridgerte__code-block-menu-item",C.textContent=v.label,V(C),C.addEventListener("click",()=>{i(),_(f,v.value)}),b.append(C)}),a.content.append(b),a.open({x:u.left,y:u.top,width:180,height:u.height})};t.className="bridgerte__code-block-controls-layer",e.root.append(t);const w=e.editor.registerMutationListener(H.CodeNode,M=>{M.forEach((f,u)=>{if(f==="destroyed"){const d=l.get(u);if(d){const b=c.get(d);b==null||b(),c.delete(d),d.remove()}l.delete(u);return}p(u)})}),S=e.editor.registerUpdateListener(N),k=M=>{const f=M.target;if(!(f instanceof HTMLElement))return;const u=f.closest(".bridgerte__code-block-control");if(!(u instanceof HTMLElement))return;const d=u.dataset.lexicalKey;d&&(M.preventDefault(),M.stopPropagation(),h(u,d))},P=M=>{const f=M.target;f instanceof HTMLElement&&f.closest(".bridgerte__code-block-control")&&M.preventDefault()},I=M=>{const f=M.target;if(!(f instanceof HTMLElement))return;if(!f.closest(".bridgerte__code-block")){i();return}const u=f.closest(".bridgerte__code-block");if(!u||u.textContent)return;const d=u.dataset.lexicalKey;d&&(e.editor.update(()=>{const b=g.$getNodeByKey(d);H.$isCodeNode(b)&&b.selectEnd()}),e.editor.focus())};return t.addEventListener("pointerdown",P),t.addEventListener("click",k),n.addEventListener("pointerdown",I),n.addEventListener("scroll",N,{passive:!0}),window.addEventListener("resize",N),{destroy(){w(),S(),s!==null&&(ze(s),s=null),t.removeEventListener("pointerdown",P),t.removeEventListener("click",k),n.removeEventListener("pointerdown",I),n.removeEventListener("scroll",N),window.removeEventListener("resize",N),l.forEach(M=>{var f;(f=c.get(M))==null||f(),M.remove()}),l.clear(),c.clear(),t.remove(),a==null||a.destroy(),a=null}}},_e=(e,t={})=>e.map(n=>{var a;const r=(a=t.menuLabels)==null?void 0:a[n.id],o=n.payloadPanel?At.resolvePayloadPanelSchema(n.payloadPanel,t.payloadPanelConfig):void 0;return{...n,...r===void 0?{}:{label:r},...o===void 0?{}:{payloadPanel:o}}}),jt=(e,t)=>{const n=t.find(r=>r.command===e.command.type);return(n==null?void 0:n.value)===void 0?void 0:{value:String(n.value)}},Kt=(e,t)=>{const n=t.find(o=>W.isCommandStateForCommand(e.command,o)),r=t.find(o=>o.command===e.command.type);return{active:(n==null?void 0:n.active)===!0,disabled:e.payloadPanel?(r==null?void 0:r.disabled)===!0:(n==null?void 0:n.disabled)===!0||(r==null?void 0:r.disabled)===!0}},We=["media-resize-20","media-resize-50","media-resize-100"],Wr=["media-align-left","media-align-center","media-align-right","|",...We,"|","media-remove"],Vr=["media-retry","|","media-remove"],Ur=[{id:"media-align-left",command:{type:"media.align",assetId:"",value:"left"},label:"左",icon:"align-left",group:"media"},{id:"media-align-center",command:{type:"media.align",assetId:"",value:"center"},label:"中",icon:"align-center",group:"media"},{id:"media-align-right",command:{type:"media.align",assetId:"",value:"right"},label:"右",icon:"align-right",group:"media"},{id:"media-resize-20",command:{type:"media.resize",assetId:"",widthPercent:20},label:"20%",icon:"media-resize-20",group:"media"},{id:"media-resize-50",command:{type:"media.resize",assetId:"",widthPercent:50},label:"50%",icon:"media-resize-50",group:"media"},{id:"media-resize-100",command:{type:"media.resize",assetId:"",widthPercent:100},label:"100%",icon:"media-resize-100",group:"media"},{id:"media-retry",command:{type:"media.retry",assetId:""},label:"重试",icon:"refresh-cw",group:"media"},{id:"media-remove",command:{type:"media.remove",assetId:""},label:"删除",icon:"trash-2",group:"media"}],qr=e=>We.includes(e),jr=e=>typeof e=="object"&&Array.isArray(e.menuKeys),Kr=e=>new Set(e.flatMap(t=>t==="|"?[]:typeof t=="string"?[t]:jr(t)?[t.key,...t.menuKeys]:[])),Gr=e=>{const t=Kr(e),n=We.filter(r=>!t.has(r));return n.length===0?e:[...e,"|",...n]},Yr=e=>{var r;const t=(e==null?void 0:e.toolbarKeys)??Wr;return{...e,toolbarKeys:Gr(t),excludeKeys:(r=e==null?void 0:e.excludeKeys)==null?void 0:r.filter(o=>!qr(o))}},Xr=(e,t)=>{switch(e.command.type){case"media.retry":return{...e.command,assetId:t};case"media.remove":return{...e.command,assetId:t};case"media.resize":return{...e.command,assetId:t};case"media.align":return{...e.command,assetId:t};default:return null}},Jr=(e,t,n)=>e.command.type==="media.resize"?e.command.widthPercent===t:e.command.type==="media.align"&&e.command.value===n,Gt=(e,t={})=>{const n=_e(Ur,{menuLabels:t.menuLabels}),r=e==="error"?{toolbarKeys:Vr}:Yr(t.config);return W.resolveToolbarMenu(r,n)},oe=8,ie="bridgerte__media-controls-button",Qr=e=>e.querySelector(".bridgerte__content")??e,ht=e=>e instanceof Element?e.closest(".bridgerte__media"):null,Zr=(e,t=!1)=>{const n=document.createElement("button");return n.type="button",n.className=ie,n.textContent=e.label,n.dataset.menuItemId=e.id,n.dataset.action=e.id.replace(/^media-/,""),t&&(n.dataset.active="true"),n.setAttribute("aria-label",e.label),n},Yt=e=>e.flatMap(t=>t.type==="button"?[t.item]:t.type==="group"?t.items:[]),eo=(e,t,n,r)=>{if(t.type==="separator"){const a=document.createElement("span");a.className="bridgerte__media-controls-separator",a.dataset.separatorId=t.key,a.setAttribute("aria-hidden","true"),e.append(a);return}(t.type==="button"?[t.item]:t.items).forEach(a=>{e.append(Zr(a,Jr(a,n,r)))})},to=(e,t,n)=>{const r=document.createElement("div"),o=e.dataset.status,a=Number(e.dataset.displayWidthPercent??t),s=e.dataset.align??"left",l=Gt(o,{config:n.mediaControlsConfig,menuLabels:n.menuLabels});return r.className="bridgerte__media-controls",r.contentEditable="false",r.setAttribute("aria-label","媒体操作"),r.dataset.status=o??"success",r.dataset.displayWidthPercent=e.dataset.displayWidthPercent??"",r.dataset.align=e.dataset.align??"",r.dataset.menuItemIds=Yt(l).map(c=>c.id).join("|"),l.forEach(c=>{eo(r,c,a,s)}),r},no=e=>{const t=document.createElement("div"),n=Qr(e.root),r=new Map,o=new Map,a=new Map;let s=null,l=null,c=!1,i=null;const m=d=>{var v;const b=r.get(d);b&&((v=o.get(b))==null||v(),o.delete(b),b.remove(),r.delete(d),i===d&&(i=null))},_=(d,b)=>b.dataset.status==="error"||i===d,E=(d,b)=>{const v=e.root.getBoundingClientRect(),C=b.getBoundingClientRect(),L=C.bottom<v.top||C.top>v.bottom,$=Math.max(oe,v.width-d.offsetWidth-oe),O=Math.min(Math.max(C.left-v.left+oe,oe),$),D=Math.max(oe,C.top-v.top-d.offsetHeight-oe);d.hidden=L,d.style.transform=`translate(${O}px, ${D}px)`},T=d=>{const b=e.editor.getElementByKey(d);if(!b){m(d);return}b.dataset.lexicalKey=d,a.set(b,d);const v=r.get(d);if(!_(d,b)){m(d);return}if(v){const $=b.dataset.status==="error",O=v.querySelector('[data-action="retry"]')!==null,D=b.dataset.displayWidthPercent??"",R=b.dataset.align??"";if($===O&&v.dataset.displayWidthPercent===D&&v.dataset.align===R){E(v,b);return}m(d)}const C=to(b,e.defaultWidthPercent,e),L=V(C,{targetSelector:`.${ie}`});C.dataset.lexicalKey=d,C.dataset.assetId=b.dataset.assetId,r.set(d,C),o.set(C,L),t.append(C),E(C,b)},p=()=>{s=null,a.forEach((d,b)=>{e.root.contains(b)||(a.delete(b),m(d))}),e.root.querySelectorAll(".bridgerte__media").forEach(d=>{const b=d.dataset.lexicalKey;b&&(a.set(d,b),T(b))}),r.forEach((d,b)=>{T(b)}),i!==null&&T(i)},y=()=>{s===null&&(s=ve(p))},N=(d,b)=>{const v=b.dataset.assetId,C=Yt(Gt(b.dataset.status,{config:e.mediaControlsConfig,menuLabels:e.menuLabels})).find($=>$.id===d.dataset.menuItemId);if(!v||!C)return;const L=Xr(C,v);L&&e.executeCommand(L)},h=d=>{if(!d){const C=i;i=null,C!==null&&T(C);return}const b=d.dataset.lexicalKey?d.dataset.lexicalKey:a.get(d)??null;if(!b||i===b)return;const v=i;i=b,v!==null&&T(v),T(b)},w=d=>{const b=ht(d.target);h(b)},S=d=>{h(ht(d.target))},k=d=>{const b=d.target;if(!(b instanceof HTMLElement))return;const v=b.closest(`.${ie}`);v&&(d.preventDefault(),l=d.pointerType==="mouse"?null:v)},P=d=>{if(d.pointerType==="mouse"||!l)return;const b=d.target,v=b instanceof HTMLElement?b.closest(".bridgerte__media-controls"):null,C=b instanceof HTMLElement?b.closest(`.${ie}`):null;C===l&&v&&(d.preventDefault(),d.stopPropagation(),N(C,v),c=!0),l=null},I=()=>{l=null},M=d=>{if(c){c=!1,d.preventDefault(),d.stopPropagation();return}const b=d.target;if(!(b instanceof HTMLElement))return;const v=b.closest(`.${ie}`),C=b.closest(".bridgerte__media-controls");!v||!C||(d.preventDefault(),d.stopPropagation(),N(v,C))},f=e.editor.registerMutationListener(ae,d=>{d.forEach((b,v)=>{if(b==="destroyed"){m(v);return}T(v)})}),u=e.editor.registerUpdateListener(y);return t.className="bridgerte__media-controls-layer",e.root.append(t),t.addEventListener("pointerdown",k),t.addEventListener("pointerup",P),t.addEventListener("pointercancel",I),t.addEventListener("click",M),n.addEventListener("pointerdown",w),n.addEventListener("focusin",S),n.addEventListener("scroll",y,{passive:!0}),window.addEventListener("resize",y),{destroy(){f(),u(),s!==null&&(ze(s),s=null),t.removeEventListener("pointerdown",k),t.removeEventListener("pointerup",P),t.removeEventListener("pointercancel",I),t.removeEventListener("click",M),n.removeEventListener("pointerdown",w),n.removeEventListener("focusin",S),n.removeEventListener("scroll",y),window.removeEventListener("resize",y),r.forEach(d=>{var b;(b=o.get(d))==null||b(),d.remove()}),r.clear(),o.clear(),a.clear(),t.remove()}}},ro=["width","height"],j=(e,t)=>{var r;const n=(r=e[t])==null?void 0:r.trim();return n||void 0},Re=(e,t)=>{const n=Number.parseInt(e[t]??"",10);return Number.isFinite(n)&&n>0?n:void 0},pt=(e,t)=>ro.reduce((n,r)=>{const o=Re(t,r);return o===void 0?n:{...n,[r]:o}},e),oo=(e,t)=>{if(e.type==="format.color"||e.type==="format.backgroundColor"||e.type==="format.fontSize"||e.type==="format.fontFamily"||e.type==="format.lineHeight")return t.value!==void 0?{...e,value:t.value}:e;if(e.type==="link.set"){const n=j(t,"href"),r=j(t,"text");return n?{...e,href:n,text:r}:null}if(e.type==="block.code")return t.language?{type:"block.code",language:t.language}:e;if(e.type==="block.setCodeLanguage")return t.language!==void 0?{...e,language:t.language}:e;if(e.type==="table.insert"){const n=Re(t,"rows"),r=Re(t,"cols");return n&&r?{type:"table.insert",rows:n,cols:r}:null}if(e.type==="media.insertImage"){const n=j(t,"url");return n?pt({...e,url:n,alt:j(t,"alt"),title:j(t,"title")},t):null}if(e.type==="media.insertVideo"){const n=j(t,"url");return n?pt({...e,url:n,poster:j(t,"poster"),title:j(t,"title")},t):null}return e},X=e=>Math.min(Math.max(Math.round(e),0),255),Pe=({r:e,g:t,b:n})=>`#${[e,t,n].map(r=>X(r).toString(16).padStart(2,"0")).join("")}`,Xt=e=>{const n=e.trim().match(/^#([0-9a-f]{6})$/i);if(!n)return null;const r=n[1]??"";return{r:Number.parseInt(r.slice(0,2),16),g:Number.parseInt(r.slice(2,4),16),b:Number.parseInt(r.slice(4,6),16)}},ao=e=>{const t=e.trim().match(/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i);return t?{r:X(Number(t[1])),g:X(Number(t[2])),b:X(Number(t[3]))}:null},so=e=>{const t=Xt(e)??ao(e);return t?Pe(t):null},Jt=e=>Math.min(Math.max(e,0),1),io=({r:e,g:t,b:n})=>{const r=X(e)/255,o=X(t)/255,a=X(n)/255,s=Math.max(r,o,a),l=Math.min(r,o,a),c=s-l;let i=0;return c!==0&&(s===r?i=60*((o-a)/c%6):s===o?i=60*((a-r)/c+2):i=60*((r-o)/c+4)),{h:i<0?i+360:i,s:s===0?0:c/s,v:s}},ft=({h:e,s:t,v:n})=>{const r=n*t,o=r*(1-Math.abs(e/60%2-1)),a=n-r;let s=0,l=0,c=0;return e<60?(s=r,l=o):e<120?(s=o,l=r):e<180?(l=r,c=o):e<240?(l=o,c=r):e<300?(s=o,c=r):(s=r,c=o),{r:(s+a)*255,g:(l+a)*255,b:(c+a)*255}},lo=({h:e,s:t})=>{const n=e*Math.PI/180,r=Jt(t)*50;return{x:50+Math.cos(n)*r,y:50+Math.sin(n)*r}},bt=(e,t)=>{const n=t.getBoundingClientRect(),r=n.left+n.width/2,o=n.top+n.height/2,a=e.clientX-r,s=e.clientY-o,l=Math.min(Math.sqrt(a*a+s*s),n.width/2),c=Math.atan2(s,a)*180/Math.PI;return{h:c<0?c+360:c,s:Jt(l/(n.width/2)),v:1}},co=["#000000","#ffffff"],uo=e=>{var t;return(t=e.options)!=null&&t.length?e.options:co.map(n=>({label:n,value:n}))},Qt=()=>{const e=document.createElement("section");return e.className="bridgerte__payload-panel-field",e},go=(e,t,n)=>{const r=Qt(),o=document.createElement("div");return o.className="bridgerte__payload-panel-option-list",e.options.forEach(a=>{const s=document.createElement("button");s.type="button",s.className="bridgerte__payload-panel-option",s.textContent=a.label,s.dataset.bridgertePayloadOption=a.value,s.dataset.active=t[e.name]===a.value?"true":"false",V(s),s.addEventListener("pointerdown",l=>{l.preventDefault()}),s.addEventListener("click",()=>{n({...t,[e.name]:a.value})}),o.append(s)}),r.append(o),r},mo=(e,t,n)=>{const r=Qt(),o=document.createElement("div"),a=document.createElement("span"),s=document.createElement("div"),l=document.createElement("div");let c={h:0,s:0,v:1},i=null;const m=T=>{const p=so(T);if(!p)return;t[e.name]=p,l.style.background=p,c=io(Xt(p)??{r:255,g:255,b:255});const y=lo(c);o.dataset.active="true",l.dataset.empty="false",a.style.left=`${y.x}%`,a.style.top=`${y.y}%`},_=()=>{const T=t[e.name];T&&n({...t,[e.name]:T})};r.className="bridgerte__payload-panel-field",o.className="bridgerte__payload-panel-color-wheel",o.setAttribute("aria-label",`${e.label}选择区域`),a.className="bridgerte__payload-panel-color-wheel-handle",s.className="bridgerte__payload-panel-color-actions",l.className="bridgerte__payload-panel-color-preview",l.dataset.empty="true",o.append(a),uo(e).forEach(T=>{const p=document.createElement("button"),y=T.value;p.type="button",p.className="bridgerte__payload-panel-color-swatch",p.dataset.value=y,p.style.background=y,p.setAttribute("aria-label",`选择颜色 ${T.label}`),V(p),p.addEventListener("pointerdown",N=>{N.preventDefault()}),p.addEventListener("click",()=>{m(y),_()}),s.append(p)}),o.addEventListener("pointerdown",T=>{i=T.pointerId,o.setPointerCapture(T.pointerId),c=bt(T,o),m(Pe(ft(c))),T.preventDefault()}),o.addEventListener("pointermove",T=>{i===T.pointerId&&(c=bt(T,o),m(Pe(ft(c))))}),o.addEventListener("pointerup",T=>{i===T.pointerId&&(i=null,o.releasePointerCapture(T.pointerId),_())}),o.addEventListener("pointercancel",T=>{i===T.pointerId&&(i=null,o.releasePointerCapture(T.pointerId))});const E=t[e.name];return E&&m(E),r.append(o,l,s),r},ho=(e,t,n)=>{const r=document.createElement("label"),o=document.createElement("input");return r.className="bridgerte__payload-panel-text-field",r.textContent=e.label,o.type=e.name==="href"||e.name==="url"?"url":"text",o.className="bridgerte__payload-panel-text-input",o.value=t[e.name]??"",o.placeholder=e.placeholder??"",o.spellcheck=!1,o.addEventListener("input",()=>{t[e.name]=o.value}),o.addEventListener("keydown",a=>{a.key==="Enter"&&(a.preventDefault(),n(t))}),r.append(o),r},po=(e,t,n)=>{const r=document.createElement("label"),o=document.createElement("input");return r.className="bridgerte__payload-panel-text-field",r.textContent=e.label,o.type="number",o.className="bridgerte__payload-panel-text-input",o.value=t[e.name]??"",o.placeholder=e.placeholder??"",e.min!==void 0&&(o.min=String(e.min)),e.max!==void 0&&(o.max=String(e.max)),e.step!==void 0&&(o.step=String(e.step)),o.addEventListener("input",()=>{t[e.name]=o.value}),o.addEventListener("keydown",a=>{a.key==="Enter"&&(a.preventDefault(),n(t))}),r.append(o),r},fo=({field:e,values:t,onSubmit:n})=>e.type==="color"?mo(e,t,n):e.type==="text"?ho(e,t,n):e.type==="number"?po(e,t,n):go(e,t,n),bo=e=>{var t,n,r;return e.defaultValue??(e.type==="select"?(t=e.options[0])==null?void 0:t.value:void 0)??(e.type==="color"?(r=(n=e.options)==null?void 0:n[0])==null?void 0:r.value:void 0)??""},yo=(e,t)=>(t==null?void 0:t[e.name])??(e.type==="color"?"":bo(e)),yt=e=>e.some(t=>t.type==="text"||t.type==="number"),vo=e=>{const t=e.querySelector(".bridgerte__payload-panel-text-input");queueMicrotask(()=>{t==null||t.focus(),t==null||t.select()})},wo=(e,t,n)=>{const r=document.createElement("div"),o=document.createElement("span"),a=(n==null?void 0:n(e))??null;if(r.className="bridgerte__payload-panel-title",o.textContent=e.panel.title,r.append(o),a){const s=document.createElement("button");s.type="button",s.className="bridgerte__payload-panel-clear",s.textContent="清除",s.setAttribute("aria-label",`清除${e.panel.title}`),V(s),s.addEventListener("pointerdown",l=>{l.preventDefault()}),s.addEventListener("click",()=>{t(a)}),r.append(s)}return r},Co=e=>e==="font-size"||e==="font-family"||e==="line-height"?"180px":"220px",_o=3,Eo=3,Mo=10,Zt=10,ko=16,xo=2,To=24,No=()=>{var e;return typeof window<"u"&&((e=window.matchMedia)==null?void 0:e.call(window,"(hover: hover) and (pointer: fine)").matches)===!0},le=(e,t)=>{const n=Number.parseInt(e??"",10);return Number.isFinite(n)?Math.min(Math.max(n,t.min),t.max):t.defaultValue},So=(e,t)=>e.type==="number"&&e.name===t,vt=(e,t)=>typeof e=="number"&&Number.isFinite(e)&&e>0?Math.floor(e):t,wt=(e,t,n,r)=>{const o=e.find(m=>So(m,t)),a=vt(o==null?void 0:o.min,1),s=vt(o==null?void 0:o.max,n),l=Math.max(a,s),c=Math.min(Math.max(r,a),l),i=le(o==null?void 0:o.defaultValue,{min:a,max:l,defaultValue:c});return{min:a,max:l,defaultValue:i}},en=e=>({rows:wt(e,"rows",G.BRIDGERTE_TABLE_INSERT_MAX_ROWS,_o),cols:wt(e,"cols",G.BRIDGERTE_TABLE_INSERT_MAX_COLS,Eo)}),Lo=e=>{const t=Math.min(e.cols.max,Zt);return`${t*ko+Math.max(t-1,0)*xo+To}px`},Ro=({fields:e,values:t,onSubmit:n})=>{const r=en(e),o=document.createElement("section"),a=document.createElement("div"),s=document.createElement("div"),l=[],c=No(),i=Math.min(r.rows.max,Mo),m=Math.min(r.cols.max,Zt),_={...r.rows,max:i,defaultValue:Math.min(r.rows.defaultValue,i)},E={...r.cols,max:m,defaultValue:Math.min(r.cols.defaultValue,m)};let T=le(t.rows,_),p=le(t.cols,E),y=null;const N=(M,f)=>{T=M,p=f,t.rows=String(M),t.cols=String(f),s.textContent=`${M} x ${f}`,l.forEach(u=>{const d=Number.parseInt(u.dataset.rows??"0",10),b=Number.parseInt(u.dataset.cols??"0",10);u.dataset.active=String(d<=M&&b<=f)})},h=M=>{var f;return((f=document.elementFromPoint(M.clientX,M.clientY))==null?void 0:f.closest(".bridgerte__payload-panel-table-cell"))??null},w=M=>{if(!M)return;const f=le(M.dataset.rows,_),u=le(M.dataset.cols,E);N(f,u)},S=()=>{n({...t,rows:String(T),cols:String(p)})},k=()=>{y=null},P=()=>{window.setTimeout(k,0)},I=(M,f)=>{if(M.detail>0&&y!==f){M.preventDefault(),M.stopPropagation();return}k(),w(f),S()};for(let M=1;M<=i;M+=1)for(let f=1;f<=m;f+=1){const u=document.createElement("button");u.type="button",u.className="bridgerte__payload-panel-table-cell",u.dataset.rows=String(M),u.dataset.cols=String(f),u.setAttribute("aria-label",`插入 ${M} 行 ${f} 列表格`),V(u),u.addEventListener("pointerdown",d=>{y=u,w(u),d.preventDefault()}),u.addEventListener("pointerup",P),u.addEventListener("pointercancel",k),u.addEventListener("click",d=>{I(d,u)}),c&&u.addEventListener("pointerenter",()=>{w(u)}),l.push(u),a.append(u)}return o.className="bridgerte__payload-panel-field",a.className="bridgerte__payload-panel-table-grid",a.setAttribute("aria-label","选择表格行列"),a.style.setProperty("--bridgerte-payload-panel-table-cols",String(m)),s.className="bridgerte__payload-panel-table-status",s.setAttribute("aria-live","polite"),a.addEventListener("pointermove",M=>{c||w(h(M))}),N(T,p),o.append(a,s),o},Po="bridgerte-payload-panel";let Ct=0;const Io=()=>(Ct+=1,`${Po}-${Ct}`),fe=e=>e.panel.id==="table-insert",$o=(e,t)=>{const n=document.createElement("button");return n.type="button",n.className="bridgerte__payload-panel-submit",n.textContent="应用",V(n),n.addEventListener("pointerdown",r=>{r.preventDefault()}),n.addEventListener("click",()=>{t(e)}),n},Ao=e=>{let t=null,n={};const r=qt({root:e.editorRoot,className:"bridgerte__payload-panel",onBackdropClick:()=>{o()}});function o(){t=null,n={},r.close(),r.content.replaceChildren()}const a=i=>{var _;if(!t||t.readonly||e.isReadonly())return;const m=oo(t.command,i);m&&((_=e.restoreEditorFocus)==null||_.call(e,()=>{o(),e.isReadonly()||e.executeCommand(m)}))},s=i=>{var m;!t||t.readonly||e.isReadonly()||(m=e.restoreEditorFocus)==null||m.call(e,()=>{o(),e.isReadonly()||e.executeCommand(i)})},l=i=>{n=i.panel.fields.reduce((_,E)=>(_[E.name]=yo(E,i.currentValues),_),{});const m=fe(i)?Lo(en(i.panel.fields)):Co(i.panel.id);r.element.style.width=`min(${m}, calc(100vw - 24px))`,r.content.append(wo(i,s,e.getClearCommand)),fe(i)?r.content.append(Ro({fields:i.panel.fields,values:n,onSubmit:a})):i.panel.fields.forEach(_=>{r.content.append(fo({field:_,values:n,onSubmit:a}))}),!fe(i)&&yt(i.panel.fields)&&r.content.append($o(n,a)),r.open(i.anchorRect),!fe(i)&&yt(i.panel.fields)&&vo(r.content)};return{open:i=>{var E;o();const m={...i,id:Io(),readonly:e.isReadonly(),submit:a,cancel:o};if(t=m,((E=e.onRequest)==null?void 0:E.call(e,m))!==!0){if(m.readonly){o();return}l(i)}},close:o,destroy(){o(),r.destroy()}}},ce="bridgerte__table-controls-button",Bo=["table-insert-row-after","table-delete-row","table-insert-column-after","table-delete-column","table-delete"],Do=()=>{const e=new Map(W.defaultMenuSchema.map(t=>[t.id,t]));return Bo.map(t=>W.tableHeaderMenuItems.find(n=>n.id===t)??e.get(t)).filter(t=>t!==void 0)},tn=Do(),Oo=new Map(tn.map(e=>[e.id,e])),Ho=e=>e.matches(".bridgerte__table")?e:e.querySelector(".bridgerte__table")??e,Fo=(e,t)=>e.classList.contains("bridgerte__table-wrapper")?e:t.parentElement instanceof HTMLElement?t.parentElement:t,zo=e=>e.querySelector(".bridgerte__content")??e,_t=e=>e instanceof Element?e.closest(".bridgerte__table-wrapper"):null,Wo=e=>{const t=e.getFirstChild();if(!B.$isTableRowNode(t))return null;const n=t.getFirstChild();return B.$isTableCellNode(n)?n:null},Vo=e=>{const t=document.createElement("button");return t.type="button",t.className=ce,t.textContent=e.label,t.dataset.menuItemId=e.id,t.setAttribute("aria-label",e.label),t},Uo=()=>{const e=document.createElement("div");return e.className="bridgerte__table-controls",e.contentEditable="false",e.setAttribute("aria-label","表格操作"),tn.forEach(t=>{e.append(Vo(t))}),e},qo=e=>{const t=document.createElement("div"),n=zo(e.root),r=new Map,o=new Map,a=new Map;let s=null,l=null,c=!1,i=null;const m=(v,C)=>{const L=e.root.getBoundingClientRect(),$=C.getBoundingClientRect(),O=$.bottom<L.top||$.top>L.bottom,D=Math.max(8,L.width-v.offsetWidth-8),R=Math.min(Math.max($.left-L.left+8,8),D),x=Math.max(8,$.top-L.top-v.offsetHeight-8);v.hidden=O,v.style.transform=`translate(${R}px, ${x}px)`},_=v=>i===v,E=v=>{const C=e.editor.getElementByKey(v);if(!C){T(v);return}C.dataset.lexicalKey=v;const L=Ho(C),$=Fo(C,L);a.set($,v);const O=r.get(v);if(!_(v)){T(v);return}if(O){m(O,$);return}const D=Uo(),R=V(D,{targetSelector:`.${ce}`});D.dataset.lexicalKey=v,r.set(v,D),o.set(D,R),t.append(D),m(D,$)},T=v=>{var L;const C=r.get(v);C&&((L=o.get(C))==null||L(),o.delete(C),C.remove(),r.delete(v),i===v&&(i=null))},p=()=>{s=null,a.forEach((v,C)=>{e.root.contains(C)||(a.delete(C),T(v))}),e.root.querySelectorAll(".bridgerte__table-wrapper").forEach(v=>{const C=v.dataset.lexicalKey;C&&(a.set(v,C),E(C))}),r.forEach((v,C)=>{E(C)}),i!==null&&E(i)},y=()=>{s===null&&(s=ve(p))},N=v=>{e.editor.update(()=>{var L;const C=g.$getNodeByKey(v);C instanceof B.TableNode&&((L=Wo(C))==null||L.selectStart())}),e.editor.focus()},h=(v,C)=>{N(v),e.executeCommand(C)},w=(v,C)=>{const L=C.dataset.lexicalKey,$=v.dataset.menuItemId,O=$?Oo.get($):void 0;!L||!O||h(L,O.command)},S=v=>{if(!v){const $=i;i=null,$!==null&&E($);return}const C=v.dataset.lexicalKey?v.dataset.lexicalKey:a.get(v)??null;if(!C||i===C)return;const L=i;i=C,L!==null&&E(L),E(C)},k=v=>{S(_t(v.target))},P=v=>{S(_t(v.target))},I=v=>{const C=v.target;if(!(C instanceof HTMLElement))return;const L=C.closest(`.${ce}`);L&&(v.preventDefault(),l=v.pointerType==="mouse"?null:L)},M=v=>{if(v.pointerType==="mouse"||!l)return;const C=v.target,L=C instanceof HTMLElement?C.closest(".bridgerte__table-controls"):null,$=C instanceof HTMLElement?C.closest(`.${ce}`):null;$===l&&L&&(v.preventDefault(),v.stopPropagation(),w($,L),c=!0),l=null},f=()=>{l=null},u=v=>{if(c){c=!1,v.preventDefault(),v.stopPropagation();return}const C=v.target;if(!(C instanceof HTMLElement))return;const L=C.closest(`.${ce}`),$=C.closest(".bridgerte__table-controls");!L||!$||(v.preventDefault(),v.stopPropagation(),w(L,$))},d=e.editor.registerMutationListener(B.TableNode,v=>{v.forEach((C,L)=>{if(C==="destroyed"){T(L);return}E(L)})}),b=e.editor.registerUpdateListener(y);return t.className="bridgerte__table-controls-layer",e.root.append(t),t.addEventListener("pointerdown",I),t.addEventListener("pointerup",M),t.addEventListener("pointercancel",f),t.addEventListener("click",u),n.addEventListener("pointerdown",k),n.addEventListener("focusin",P),n.addEventListener("scroll",y,{passive:!0}),window.addEventListener("resize",y),{destroy(){d(),b(),s!==null&&(ze(s),s=null),t.removeEventListener("pointerdown",I),t.removeEventListener("pointerup",M),t.removeEventListener("pointercancel",f),t.removeEventListener("click",u),n.removeEventListener("pointerdown",k),n.removeEventListener("focusin",P),n.removeEventListener("scroll",y),window.removeEventListener("resize",y),r.forEach(v=>{var C;(C=o.get(v))==null||C(),v.remove()}),r.clear(),o.clear(),a.clear(),t.remove()}}},jo=e=>{const t=Ao({editorRoot:e.editorRoot,isReadonly:e.isReadonly,restoreEditorFocus:e.restoreEditorFocus,executeCommand:e.executeCommand,getClearCommand:e.getClearCommand,onRequest:e.onRequest}),n=zr({editor:e.lexicalEditor,root:e.editorRoot,isReadonly:e.isReadonly,languagePanel:e.codeBlockLanguagePanel,payloadPanelConfig:e.payloadPanelConfig,onRequest:e.onRequest}),r=qo({editor:e.lexicalEditor,root:e.editorRoot,executeCommand:e.executeCommand}),o=no({editor:e.lexicalEditor,root:e.editorRoot,defaultWidthPercent:e.defaultMediaWidthPercent,executeCommand:e.executeCommand,mediaControlsConfig:e.mediaControlsConfig,menuLabels:e.menuLabels});return{payloadPanelController:t,codeBlockController:n,tableHeaderController:r,mediaControlsController:o,destroy(){t.destroy(),n.destroy(),r.destroy(),o.destroy()}}},Ko=(e,t)=>{const n=document.createElement("div"),r=document.createElement("div"),o=document.createElement("div");return e.classList.add("bridgerte"),e.textContent="",n.className="bridgerte__editor",r.className="bridgerte__body",o.className="bridgerte__content",o.dataset.placeholder=t.placeholder,o.setAttribute("role","textbox"),o.setAttribute("aria-multiline","true"),r.append(o),n.append(r),e.append(n),{rootElement:n,bodyElement:r,contentElement:o}},Go=({editor:e})=>{let t=null;return{capture(){e.getEditorState().read(()=>{var n;t=((n=g.$getSelection())==null?void 0:n.clone())??null})},restore(){t&&e.update(()=>{g.$setSelection((t==null?void 0:t.clone())??null)})},clear(){t=null}}},Yo=/((https?:\/\/|www\.)[^\s<>()]+[^\s<>().,;:!?])/i,Xo=/([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,})/i,Jo={changeHandlers:[],excludeParents:[],matchers:[z.createLinkMatcherWithRegExp(Yo,e=>e.startsWith("http://")||e.startsWith("https://")?e:`https://${e}`),z.createLinkMatcherWithRegExp(Xo,e=>`mailto:${e}`)]},Qo=({editor:e})=>z.registerAutoLink(e,Jo),Zo=[".bridgerte__code-header",".bridgerte__code-block-control",".bridgerte__code-block-controls-layer",".bridgerte__code-block-menu",".bridgerte__table-controls-layer",".bridgerte__table-controls",".bridgerte__media-controls-layer",".bridgerte__media-controls",".bridgerte__dialog-backdrop",".bridgerte__dialog",".bridgerte__payload-panel"].join(","),ea=(e,t)=>{const n=e.anchorNode,r=e.focusNode;return n!==null&&r!==null&&t.contains(n)&&t.contains(r)},ta=e=>{e.querySelectorAll(Zo).forEach(t=>{t.remove()}),e.querySelectorAll('[contenteditable="false"]').forEach(t=>{t.classList.contains("bridgerte__media")||t.remove()})},na=e=>{const t=e.ownerDocument.getSelection();if(!t||t.rangeCount===0||!ea(t,e))return null;const n=t.getRangeAt(0).cloneContents();ta(n);const r=e.ownerDocument.createElement("div");return r.append(n),{html:r.innerHTML,text:r.textContent??""}},ra=({target:e,isReadonly:t})=>{const n=o=>{const a=na(e);!a||!o.clipboardData||(o.clipboardData.setData("text/html",a.html),o.clipboardData.setData("text/plain",a.text),o.preventDefault(),o.stopImmediatePropagation())},r=o=>{if(t()){n(o);return}n(o)};return e.addEventListener("copy",n,{capture:!0}),e.addEventListener("cut",r,{capture:!0}),()=>{e.removeEventListener("copy",n,{capture:!0}),e.removeEventListener("cut",r,{capture:!0})}},be=8,oa=()=>{const e=window.visualViewport;return{left:(e==null?void 0:e.offsetLeft)??0,top:(e==null?void 0:e.offsetTop)??0,width:(e==null?void 0:e.width)??window.innerWidth,height:(e==null?void 0:e.height)??window.innerHeight}},Et=(e,t,n)=>Math.min(Math.max(e,t),Math.max(t,n));function Ve(e,t,n={}){const r=n.placement??"bottom-start",o=n.offset??8,a=n.shiftPadding??8,s=n.strategy??"absolute";let l=null,c=!1;const i=()=>{t.style.position=s,t.style.left="0px",t.style.top="0px",t.style.opacity="0",t.style.pointerEvents="none"},m=(p,y)=>{const N=oa(),h=t.getBoundingClientRect(),w=N.left+be,S=N.top+be,k=N.left+N.width-h.width-be,P=N.top+N.height-h.height-be;t.style.left=`${Et(p,w,k)}px`,t.style.top=`${Et(y,S,P)}px`,t.style.opacity="",t.style.pointerEvents=""},_=async()=>{const p=await te.computePosition(e,t,{placement:r,strategy:s,platform:te.platform,middleware:[te.offset(o),te.flip(),te.shift({padding:a})]});m(p.x,p.y)},E=()=>{l==null||l(),l=null},T=p=>{if(c!==p){if(c=p,E(),c){i(),t.hidden=!1,l=te.autoUpdate(e,t,_),_();return}t.hidden=!0,t.style.opacity="",t.style.pointerEvents=""}};return i(),t.hidden=!0,{update:_,setOpen:T,destroy(){E(),t.hidden=!0}}}const Ue={"align-center":'<svg aria-hidden="true" class="lucide lucide-align-center" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M21 5H3" /> <path d="M17 12H7" /> <path d="M19 19H5" /> </svg>',"align-justify":'<svg aria-hidden="true" class="lucide lucide-align-justify" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M3 5h18" /> <path d="M3 12h18" /> <path d="M3 19h18" /> </svg>',"align-left":'<svg aria-hidden="true" class="lucide lucide-align-left" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M21 5H3" /> <path d="M15 12H3" /> <path d="M17 19H3" /> </svg>',"align-right":'<svg aria-hidden="true" class="lucide lucide-align-right" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M21 5H3" /> <path d="M21 12H9" /> <path d="M21 19H7" /> </svg>',"at-sign":'<svg aria-hidden="true" class="lucide lucide-at-sign" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <circle cx="12" cy="12" r="4" /> <path d="M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8" /> </svg>',bold:'<svg aria-hidden="true" class="lucide lucide-bold" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8" /> </svg>',"case-sensitive":'<svg aria-hidden="true" class="lucide lucide-case-sensitive" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16" /> <path d="M22 9v7" /> <path d="M3.304 13h6.392" /> <circle cx="18.5" cy="12.5" r="3.5" /> </svg>',code:'<svg aria-hidden="true" class="lucide lucide-code" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m16 18 6-6-6-6" /> <path d="m8 6-6 6 6 6" /> </svg>',"columns-minus":'<svg aria-hidden="true" class="lucide lucide-between-vertical-end" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <rect width="7" height="13" x="3" y="3" rx="1" /> <path d="m9 22 3-3 3 3" /> <rect width="7" height="13" x="14" y="3" rx="1" /> </svg>',"columns-plus":'<svg aria-hidden="true" class="lucide lucide-between-vertical-start" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <rect width="7" height="13" x="3" y="8" rx="1" /> <path d="m15 2-3 3-3-3" /> <rect width="7" height="13" x="14" y="8" rx="1" /> </svg>',"heading-1":'<svg aria-hidden="true" class="lucide lucide-heading-1" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M4 12h8" /> <path d="M4 18V6" /> <path d="M12 18V6" /> <path d="m17 12 3-2v8" /> </svg>',"heading-2":'<svg aria-hidden="true" class="lucide lucide-heading-2" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M4 12h8" /> <path d="M4 18V6" /> <path d="M12 18V6" /> <path d="M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1" /> </svg>',"heading-3":'<svg aria-hidden="true" class="lucide lucide-heading-3" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M4 12h8" /> <path d="M4 18V6" /> <path d="M12 18V6" /> <path d="M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2" /> <path d="M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2" /> </svg>',"heading-4":'<svg aria-hidden="true" class="lucide lucide-heading-4" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M12 18V6" /> <path d="M17 10v3a1 1 0 0 0 1 1h3" /> <path d="M21 10v8" /> <path d="M4 12h8" /> <path d="M4 18V6" /> </svg>',"heading-5":'<svg aria-hidden="true" class="lucide lucide-heading-5" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M4 12h8" /> <path d="M4 18V6" /> <path d="M12 18V6" /> <path d="M17 13v-3h4" /> <path d="M17 17.7c.4.2.8.3 1.3.3 1.5 0 2.7-1.1 2.7-2.5S19.8 13 18.3 13H17" /> </svg>',"heading-6":'<svg aria-hidden="true" class="lucide lucide-heading-6" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M4 12h8" /> <path d="M4 18V6" /> <path d="M12 18V6" /> <circle cx="19" cy="16" r="2" /> <path d="M20 10c-2 2-3 3.5-3 6" /> </svg>',"indent-decrease":'<svg aria-hidden="true" class="lucide lucide-indent-decrease" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M21 5H11" /> <path d="M21 12H11" /> <path d="M21 19H11" /> <path d="m7 8-4 4 4 4" /> </svg>',"indent-increase":'<svg aria-hidden="true" class="lucide lucide-indent-increase" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M21 5H11" /> <path d="M21 12H11" /> <path d="M21 19H11" /> <path d="m3 8 4 4-4 4" /> </svg>',italic:'<svg aria-hidden="true" class="lucide lucide-italic" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <line x1="19" x2="10" y1="4" y2="4" /> <line x1="14" x2="5" y1="20" y2="20" /> <line x1="15" x2="9" y1="4" y2="20" /> </svg>',"list-ordered":'<svg aria-hidden="true" class="lucide lucide-list-ordered" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M11 5h10" /> <path d="M11 12h10" /> <path d="M11 19h10" /> <path d="M4 4h1v5" /> <path d="M4 9h2" /> <path d="M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02" /> </svg>',"list-plus":'<svg aria-hidden="true" class="lucide lucide-list-plus" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M16 5H3" /> <path d="M11 12H3" /> <path d="M16 19H3" /> <path d="M18 9v6" /> <path d="M21 12h-6" /> </svg>',"list-todo":'<svg aria-hidden="true" class="lucide lucide-list-todo" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M13 5h8" /> <path d="M13 12h8" /> <path d="M13 19h8" /> <path d="m3 17 2 2 4-4" /> <rect x="3" y="4" width="6" height="6" rx="1" /> </svg>',list:'<svg aria-hidden="true" class="lucide lucide-list" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M3 5h.01" /> <path d="M3 12h.01" /> <path d="M3 19h.01" /> <path d="M8 5h13" /> <path d="M8 12h13" /> <path d="M8 19h13" /> </svg>',maximize:'<svg aria-hidden="true" class="lucide lucide-maximize" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M8 3H5a2 2 0 0 0-2 2v3" /> <path d="M21 8V5a2 2 0 0 0-2-2h-3" /> <path d="M3 16v3a2 2 0 0 0 2 2h3" /> <path d="M16 21h3a2 2 0 0 0 2-2v-3" /> </svg>',minus:'<svg aria-hidden="true" class="lucide lucide-minus" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M5 12h14" /> </svg>',"paint-bucket":'<svg aria-hidden="true" class="lucide lucide-paint-bucket" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M11 7 6 2" /> <path d="M18.992 12H2.041" /> <path d="M21.145 18.38A3.34 3.34 0 0 1 20 16.5a3.3 3.3 0 0 1-1.145 1.88c-.575.46-.855 1.02-.855 1.595A2 2 0 0 0 20 22a2 2 0 0 0 2-2.025c0-.58-.285-1.13-.855-1.595" /> <path d="m8.5 4.5 2.148-2.148a1.205 1.205 0 0 1 1.704 0l7.296 7.296a1.205 1.205 0 0 1 0 1.704l-7.592 7.592a3.615 3.615 0 0 1-5.112 0l-3.888-3.888a3.615 3.615 0 0 1 0-5.112L5.67 7.33" /> </svg>',palette:'<svg aria-hidden="true" class="lucide lucide-palette" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z" /> <circle cx="13.5" cy="6.5" r=".5" fill="currentColor" /> <circle cx="17.5" cy="10.5" r=".5" fill="currentColor" /> <circle cx="6.5" cy="12.5" r=".5" fill="currentColor" /> <circle cx="8.5" cy="7.5" r=".5" fill="currentColor" /> </svg>',pilcrow:'<svg aria-hidden="true" class="lucide lucide-pilcrow" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M13 4v16" /> <path d="M17 4v16" /> <path d="M19 4H9.5a4.5 4.5 0 0 0 0 9H13" /> </svg>',quote:'<svg aria-hidden="true" class="lucide lucide-quote" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" /> <path d="M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" /> </svg>',redo:'<svg aria-hidden="true" class="lucide lucide-redo" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M21 7v6h-6" /> <path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7" /> </svg>',"remove-formatting":'<svg aria-hidden="true" class="lucide lucide-remove-formatting" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M4 7V4h16v3" /> <path d="M5 20h6" /> <path d="M13 4 8 20" /> <path d="m15 15 5 5" /> <path d="m20 15-5 5" /> </svg>',"rows-minus":'<svg aria-hidden="true" class="lucide lucide-between-horizontal-end" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <rect width="13" height="7" x="3" y="3" rx="1" /> <path d="m22 15-3-3 3-3" /> <rect width="13" height="7" x="3" y="14" rx="1" /> </svg>',"rows-plus":'<svg aria-hidden="true" class="lucide lucide-between-horizontal-start" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <rect width="13" height="7" x="8" y="3" rx="1" /> <path d="m2 9 3 3-3 3" /> <rect width="13" height="7" x="8" y="14" rx="1" /> </svg>',"square-code":'<svg aria-hidden="true" class="lucide lucide-square-code" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m10 9-3 3 3 3" /> <path d="m14 15 3-3-3-3" /> <rect x="3" y="3" width="18" height="18" rx="2" /> </svg>',strikethrough:'<svg aria-hidden="true" class="lucide lucide-strikethrough" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M16 4H9a3 3 0 0 0-2.83 4" /> <path d="M14 12a4 4 0 0 1 0 8H6" /> <line x1="4" x2="20" y1="12" y2="12" /> </svg>',subscript:'<svg aria-hidden="true" class="lucide lucide-subscript" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m4 5 8 8" /> <path d="m12 5-8 8" /> <path d="M20 19h-4c0-1.5.44-2 1.5-2.5S20 15.33 20 14c0-.47-.17-.93-.48-1.29a2.11 2.11 0 0 0-2.62-.44c-.42.24-.74.62-.9 1.07" /> </svg>',superscript:'<svg aria-hidden="true" class="lucide lucide-superscript" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m4 19 8-8" /> <path d="m12 19-8-8" /> <path d="M20 12h-4c0-1.5.442-2 1.5-2.5S20 8.334 20 7.002c0-.472-.17-.93-.484-1.29a2.105 2.105 0 0 0-2.617-.436c-.42.239-.738.614-.899 1.06" /> </svg>',"table-delete":'<svg aria-hidden="true" class="lucide lucide-table" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M12 3v18" /> <rect width="18" height="18" x="3" y="3" rx="2" /> <path d="M3 9h18" /> <path d="M3 15h18" /> </svg>',table:'<svg aria-hidden="true" class="lucide lucide-table" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M12 3v18" /> <rect width="18" height="18" x="3" y="3" rx="2" /> <path d="M3 9h18" /> <path d="M3 15h18" /> </svg>',"trash-2":'<svg aria-hidden="true" class="lucide lucide-trash-2" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M10 11v6" /> <path d="M14 11v6" /> <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" /> <path d="M3 6h18" /> <path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" /> </svg>',type:'<svg aria-hidden="true" class="lucide lucide-type" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M12 4v16" /> <path d="M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2" /> <path d="M9 20h6" /> </svg>',underline:'<svg aria-hidden="true" class="lucide lucide-underline" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M6 4v6a6 6 0 0 0 12 0V4" /> <line x1="4" x2="20" y1="20" y2="20" /> </svg>',undo:'<svg aria-hidden="true" class="lucide lucide-undo" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M3 7v6h6" /> <path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13" /> </svg>',"upload-image":'<svg aria-hidden="true" class="lucide lucide-image" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <rect width="18" height="18" x="3" y="3" rx="2" ry="2" /> <circle cx="9" cy="9" r="2" /> <path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" /> </svg>',"upload-video":'<svg aria-hidden="true" class="lucide lucide-video" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5" /> <rect x="2" y="6" width="14" height="12" rx="2" /> </svg>',"wrap-text":'<svg aria-hidden="true" class="lucide lucide-wrap-text" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m16 16-3 3 3 3" /> <path d="M3 12h14.5a1 1 0 0 1 0 7H13" /> <path d="M3 19h6" /> <path d="M3 5h18" /> </svg>'},aa=e=>{const t=document.createElement("span");return t.className="bridgerte__menu-icon-text",t.textContent=e,t},qe=(e,t,n)=>{if(t){e.innerHTML=t;return}e.append(aa(n))},Ie=()=>{const e=window.getSelection(),t=e!=null&&e.rangeCount?e.getRangeAt(0):null,n=t==null?void 0:t.getBoundingClientRect();return!n||n.width===0&&n.height===0?null:n},sa=160,ia={toolbarKeys:["bold","italic","underline","strike","inline-code","clear-style","|","color","background-color","font-size","font-family","line-height"]},la=()=>{const e=g.$getSelection();return g.$isRangeSelection(e)&&!e.isCollapsed()},Mt=(e,t)=>e.target instanceof Node&&t.contains(e.target),kt=e=>e instanceof Element?e.closest(".bridgerte__hoverbar-button"):null,ca=e=>e.flatMap(t=>t.type==="button"?[t.item]:t.type==="group"?t.items:[]),da=e=>{const t=document.createElement("span");return t.className="bridgerte__hoverbar-separator",t.dataset.separatorId=e.key,t.setAttribute("aria-hidden","true"),t},ua=(e,t,n)=>{const r=Kt(e,t),o=document.createElement("button");return o.type="button",o.className="bridgerte__hoverbar-button",o.dataset.hoverbarItemId=e.id,o.dataset.active=String(r.active),o.disabled=r.disabled,o.setAttribute("aria-label",e.label),o.setAttribute("aria-pressed",String(r.active)),qe(o,n[e.icon]??Ue[e.icon],e.label),o},ga=({editorRoot:e,contentElement:t,editor:n,isReadonly:r,executeCommand:o,requestPayloadPanel:a,getCommandStates:s,menuSchema:l,hoverbarConfig:c,menuLabels:i,payloadPanelConfig:m,icons:_={}})=>{const E=_e(l??W.defaultMenuSchema,{menuLabels:i,payloadPanelConfig:m}),T=W.resolveToolbarMenu(c??ia,E),p=ca(T),y=document.createElement("span"),N=document.createElement("div");let h=null,w=!1,S=null;const k=V(N,{targetSelector:".bridgerte__hoverbar-button"});y.className="bridgerte__hoverbar-anchor",y.setAttribute("aria-hidden","true"),N.className="bridgerte__floating-menu bridgerte__hoverbar",N.setAttribute("role","toolbar"),N.setAttribute("aria-label","BridgeRTE hoverbar"),e.append(y,N),h=Ve(y,N,{placement:"top",offset:8,strategy:"fixed"});const P=()=>{S&&(window.clearTimeout(S),S=null)},I=()=>{P(),w=!1,N.replaceChildren(),N.dataset.visible="false",h==null||h.setOpen(!1)},M=()=>{const R=Ie(),x=t.getBoundingClientRect();y.style.left=`${(R==null?void 0:R.left)??x.left}px`,y.style.top=`${(R==null?void 0:R.top)??x.top}px`,y.style.width=`${(R==null?void 0:R.width)||1}px`,y.style.height=`${(R==null?void 0:R.height)||1}px`},f=()=>{const R=s();N.replaceChildren(...T.flatMap(x=>x.type==="separator"?[da(x)]:(x.type==="button"?[x.item]:x.items).map(F=>ua(F,R,_)))),M(),w=!0,N.dataset.visible="true",h==null||h.setOpen(!0),h==null||h.update()},u=()=>r()?!1:n.getEditorState().read(la),d=(R=!1)=>{if(P(),!u()){I();return}if(R){f();return}w&&I(),S=window.setTimeout(()=>{S=null,u()&&f()},sa)},b=R=>{const x=p.find(A=>A.id===R.dataset.hoverbarItemId);if(!(!x||R.disabled)){if(x.payloadPanel){const A=R.getBoundingClientRect();a({menuId:x.id,command:x.command,panel:x.payloadPanel,currentValues:jt(x,s()),anchorRect:{x:A.left,y:A.top,width:A.width,height:A.height}}),d(!0);return}o(x.command),d(!0)}},v=R=>{kt(R.target)&&R.preventDefault()},C=R=>{const x=kt(R.target);x&&(R.preventDefault(),b(x))},L=R=>{!w||Mt(R,N)||Mt(R,t)||I()},$=n.registerCommand(g.SELECTION_CHANGE_COMMAND,()=>(d(),!1),g.COMMAND_PRIORITY_LOW),O=n.registerUpdateListener(()=>{d()}),D=n.registerCommand(g.KEY_ESCAPE_COMMAND,R=>w?(R==null||R.preventDefault(),I(),!0):!1,g.COMMAND_PRIORITY_LOW);return N.addEventListener("pointerdown",v),N.addEventListener("click",C),document.addEventListener("pointerdown",L,!0),()=>{P(),$(),O(),D(),N.removeEventListener("pointerdown",v),N.removeEventListener("click",C),document.removeEventListener("pointerdown",L,!0),k(),h==null||h.destroy(),y.remove(),N.remove()}},ma=e=>e.metaKey||e.ctrlKey,ha={b:{type:"format.bold"},i:{type:"format.italic"},u:{type:"format.underline"},"\\":{type:"format.clear"}},pa={x:{type:"format.strike"},l:{type:"align",value:"left"},e:{type:"align",value:"center"},r:{type:"align",value:"right"},j:{type:"align",value:"justify"}},fa={0:{type:"block.paragraph"},1:{type:"block.heading",level:1},2:{type:"block.heading",level:2},3:{type:"block.heading",level:3},4:{type:"block.heading",level:4},5:{type:"block.heading",level:5},6:{type:"block.heading",level:6}},ba=e=>{const t=e.key.toLowerCase(),n=e.code;if(!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey||!ma(e))return null;if(e.altKey){if(e.shiftKey)return null;if(t==="c"||n==="KeyC")return{type:"block.code"};const r=n.startsWith("Digit")?n.slice(5):t;return fa[r]??null}return e.shiftKey?t==="z"?{type:"history.redo"}:t==="."||t===">"||n==="Period"?{type:"block.quote"}:t==="7"||t==="&"||n==="Digit7"?{type:"list.ordered"}:t==="8"||t==="*"||n==="Digit8"?{type:"list.unordered"}:t==="9"||t==="("||n==="Digit9"?{type:"list.todo"}:t==="-"||t==="_"||n==="Minus"?{type:"block.divider"}:pa[t]??null:t==="z"?{type:"history.undo"}:t==="y"&&e.ctrlKey&&!e.metaKey?{type:"history.redo"}:t==="`"||t==="~"||n==="Backquote"?{type:"format.inlineCode"}:ha[t]??null},ya=({target:e,isReadonly:t,executeCommand:n})=>{const r=o=>{if(t())return;const a=ba(o);a&&(o.preventDefault(),n(a))};return e.addEventListener("keydown",r),()=>{e.removeEventListener("keydown",r)}},va=(e,t)=>{const n=t.offsetTop,r=n+t.offsetHeight,o=e.scrollTop,a=o+e.clientHeight;if(n<o){e.scrollTop=n;return}r>a&&(e.scrollTop=r-e.clientHeight)},je=(e,t)=>{var n;if(e instanceof Text&&t<=(((n=e.textContent)==null?void 0:n.length)??0))return e;for(const r of Array.from((e==null?void 0:e.childNodes)??[])){const o=je(r,t);if(o)return o}return null},nn=({editorRoot:e,contentElement:t,editor:n,isReadonly:r,menu:o,anchor:a,itemSelector:s,getCurrentTrigger:l,getTriggerRect:c,resolveItems:i,renderItem:m,renderStatus:_,onStateChange:E,onSelect:T})=>{let p=null,y=0;const N=V(o,{targetSelector:s}),h=Ve(a,o,{placement:"bottom-start",offset:2,strategy:"fixed"});e.append(a,o);const w=()=>{const x=p?c(p.trigger)??Ie():Ie(),A=t.getBoundingClientRect();return x??A},S=()=>{const x=w();a.style.left=`${x.left}px`,a.style.top=`${x.top}px`,a.style.height=`${x.height||1}px`},k=(x=!0)=>{p=null,o.dataset.visible="false",x&&o.replaceChildren(),h.setOpen(!1)},P=()=>{const x=o.querySelector(`${s}[data-active="true"]`);x&&va(o,x)},I=(x,A)=>{!p||p.requestId!==A.requestId||(k(),T(x,A.trigger))},M=()=>{if(!p){k();return}const x=p,A=w();if((E==null?void 0:E(x,{anchorRect:A,close:k,selectItem:ee=>I(ee,x)}))===!0){o.replaceChildren(),o.dataset.visible="false",h.setOpen(!1);return}if(x.status==="success")o.replaceChildren(...x.items.map((ee,Xe)=>m(ee,Xe,Xe===x.activeIndex)));else{const ee=_==null?void 0:_(x.status,x.trigger.query,x.error);o.replaceChildren(...ee?[ee]:[])}const Y=o.children.length>0;o.dataset.visible=String(Y),S(),h.setOpen(Y),P(),h.update()},f=async(x,A)=>{let F;try{F=await Promise.resolve(i(x))}catch(Y){(p==null?void 0:p.requestId)===A&&(p={...p,items:[],activeIndex:0,status:"error",error:Y},M());return}!p||A!==p.requestId||(p={...p,items:F,activeIndex:Math.min(p.activeIndex,Math.max(F.length-1,0)),status:F.length>0?"success":"empty",error:void 0},M())},u=()=>{if(r()){k();return}const x=n.getEditorState().read(l);if(!x){k(!1);return}y+=1,p={trigger:x,items:[],activeIndex:0,requestId:y,status:"loading",error:void 0},M(),f(x.query,y)},d=()=>{if(!p||p.status!=="success")return!1;const x=p.items[p.activeIndex],A=p.trigger;return x?(k(),T(x,A),!0):!1},b=x=>!p||p.status!=="success"||p.items.length===0?!1:(p={...p,activeIndex:(p.activeIndex+x+p.items.length)%p.items.length},M(),!0),v=x=>{const A=x.target,F=A instanceof HTMLElement?A.closest(s):null,Y=F!=null&&F.dataset.index?Number.parseInt(F.dataset.index,10):Number.NaN;!p||p.status!=="success"||Number.isNaN(Y)||(p={...p,activeIndex:Y},x.preventDefault(),d())},C=x=>{const A=x.target;A instanceof HTMLElement&&A.closest(s)&&x.preventDefault()},L=n.registerUpdateListener(()=>{u()}),$=n.registerCommand(g.KEY_ARROW_DOWN_COMMAND,x=>b(1)?(x==null||x.preventDefault(),!0):!1,g.COMMAND_PRIORITY_LOW),O=n.registerCommand(g.KEY_ARROW_UP_COMMAND,x=>b(-1)?(x==null||x.preventDefault(),!0):!1,g.COMMAND_PRIORITY_LOW),D=n.registerCommand(g.KEY_ENTER_COMMAND,x=>d()?(x==null||x.preventDefault(),!0):!1,g.COMMAND_PRIORITY_LOW),R=n.registerCommand(g.KEY_ESCAPE_COMMAND,x=>p?(x==null||x.preventDefault(),k(),!0):!1,g.COMMAND_PRIORITY_LOW);return o.addEventListener("click",v),o.addEventListener("pointerdown",C),{close:k,destroy(){L(),$(),O(),D(),R(),o.removeEventListener("click",v),o.removeEventListener("pointerdown",C),N(),h.destroy(),a.remove(),o.remove()}}},wa={labelField:"label",descriptionField:"description",avatarField:"avatar",iconField:"data.icon",showAvatar:!0,showIcon:!0,showDescription:!0,loadingText:"加载中",emptyText:"没有匹配的提及",errorText:"提及加载失败"},Ca=e=>({...wa,...e}),_a=(e,t)=>{var o;const n=t.slice(5),r=(o=e.data)==null?void 0:o[n];return typeof r=="string"&&r?r:void 0},ye=(e,t)=>{if(t.startsWith("data."))return _a(e,t);const n=t==="id"?e.id:t==="label"?e.label:t==="value"?e.value:t==="avatar"?e.avatar:e.description;return typeof n=="string"&&n?n:void 0},Ea=e=>e.startsWith("@")?e:`@${e}`,rn=(e,t)=>{const n=ye(e,t.labelField)??e.label??e.value??e.id,r=t.showDescription?ye(e,t.descriptionField)??e.description:void 0,o=t.showAvatar?ye(e,t.avatarField)??e.avatar:void 0,a=t.showIcon&&!o?ye(e,t.iconField):void 0;return{item:e,label:Ea(n),...r?{description:r}:{},...o?{avatar:o}:{},...a?{icon:a}:{}}},Ma=(e,t)=>e.map(n=>rn(n,t)),$e=e=>e instanceof g.TextNode&&e.getTextContent().startsWith(" "),ka=e=>{const n=e.getTextContent().slice(1);if(!n){e.remove();return}e.setTextContent(n)},xa=(e,t)=>{const n=e.getPreviousSibling(),r=e.getNextSibling(),o=$e(r)?r.getNextSibling():r;if($e(r)&&ka(r),e.remove(),t){n==null||n.selectEnd();return}o==null||o.selectStart()},Ta=e=>{const t=g.$getSelection();if(!g.$isRangeSelection(t)||!t.isCollapsed())return null;const n=t.anchor,r=n.getNode();if(ot(r))return r;if(!(r instanceof g.TextNode))return null;const o=r.getTextContentSize(),a=r.getPreviousSibling(),s=r.getNextSibling(),l=$e(r)&&n.offset===1,c=e?n.offset===0||l?a:null:n.offset===o?s:null;return ot(c)?c:null},Na=(e,t,n)=>{const r=a=>{if(t())return!1;const s=Ta(a);return s?(xa(s,a),n(),!0):!1},o=(a,s)=>{const l=r(s);return l&&a.preventDefault(),l};return[e.registerCommand(g.KEY_BACKSPACE_COMMAND,a=>o(a,!0),g.COMMAND_PRIORITY_HIGH),e.registerCommand(g.KEY_DELETE_COMMAND,a=>o(a,!1),g.COMMAND_PRIORITY_HIGH),e.registerCommand(g.DELETE_CHARACTER_COMMAND,a=>r(a),g.COMMAND_PRIORITY_HIGH)]},Sa=/(?:^|\s)@([\p{L}\p{N}_-]*)$/u,xt=[{id:"bridgerte-team",label:"BridgeRTE Team",value:"bridgerte-team"},{id:"frontend",label:"Frontend",value:"frontend"},{id:"designer",label:"Designer",value:"designer"}],La=e=>e.trim().toLowerCase(),Ra=e=>[e.label,e.value,e.description].filter(Boolean).join(" ").toLowerCase(),Pa=e=>{const t=La(e);return t?xt.filter(n=>Ra(n).includes(t)):xt},Ia=()=>{const e=g.$getSelection();if(!g.$isRangeSelection(e)||!e.isCollapsed())return null;const t=e.anchor,n=t.getNode();if(!(n instanceof g.TextNode))return null;const o=n.getTextContent().slice(0,t.offset).match(Sa);if(!o)return null;const a=o[1]??"",s=o[0]??"",l=s.startsWith("@")?0:1,c=t.offset-s.length+l;return{query:a,nodeKey:n.getKey(),startOffset:c,endOffset:t.offset}},$a=()=>{const e=document.createElement("div");return e.className="bridgerte__floating-menu bridgerte__mention-menu",e.dataset.visible="false",e},Aa=()=>{const e=document.createElement("span");return e.className="bridgerte__mention-anchor",e.setAttribute("aria-hidden","true"),e},Ba=(e,t)=>{var s;const n=e.getElementByKey(t.nodeKey),r=je(n,t.startOffset+1);if(!(r instanceof Text))return null;const o=document.createRange(),a=Math.min(t.startOffset+1,((s=r.textContent)==null?void 0:s.length)??0);return a<=t.startOffset?null:(o.setStart(r,t.startOffset),o.setEnd(r,a),o.getBoundingClientRect())},Da=(e,t,n)=>{const r=document.createElement("button"),o=document.createElement("span");if(r.type="button",r.className="bridgerte__menu-item bridgerte__mention-item",r.dataset.mentionId=e.item.id,r.dataset.index=String(t),r.dataset.active=String(n),e.avatar){const a=document.createElement("img");a.className="bridgerte__mention-item-avatar",a.src=e.avatar,a.alt="",a.setAttribute("aria-hidden","true"),r.append(a)}else if(e.icon){const a=document.createElement("span");a.className="bridgerte__mention-item-icon",a.setAttribute("aria-hidden","true"),a.textContent=e.icon,r.append(a)}if(o.className="bridgerte__mention-item-title",o.textContent=e.label,r.append(o),e.description){const a=document.createElement("span");a.className="bridgerte__mention-item-description",a.textContent=e.description,r.append(a)}return r},Oa=(e,t)=>{const n=document.createElement("div");return n.className="bridgerte__mention-status",n.dataset.status=e,n.textContent=t,n},Ha=(e,t)=>{switch(e){case"loading":return t.loadingText;case"empty":return t.emptyText;case"error":return t.errorText}},Fa=e=>e?{x:e.x,y:e.y,width:e.width,height:e.height}:void 0,za=({editorRoot:e,contentElement:t,editor:n,isReadonly:r,executeCommand:o,mentionProvider:a,mentionMenuConfig:s,onMentionMenuRequest:l})=>{const c=$a(),i=Aa(),m=Ca(s),_=(p,y)=>{n.update(()=>{const N=g.$getNodeByKey(y.nodeKey);N instanceof g.TextNode&&(N.spliceText(y.startOffset,y.endOffset-y.startOffset,""),N.select(y.startOffset,y.startOffset))}),o({type:"mention.insert",item:p})},E=nn({editorRoot:e,contentElement:t,editor:n,isReadonly:r,menu:c,anchor:i,itemSelector:".bridgerte__mention-item",getCurrentTrigger:Ia,getTriggerRect:p=>Ba(n,p),resolveItems:async p=>{const y=await Promise.resolve(a?a(p):Pa(p));return Ma(y,m)},renderItem:Da,renderStatus:p=>Oa(p,Ha(p,m)),onStateChange:l?(p,y)=>l({id:`bridgerte-mention-menu-${p.requestId}`,query:p.trigger.query,status:p.status,items:p.items,config:m,readonly:r(),anchorRect:Fa(y.anchorRect),...p.error?{error:p.error}:{},submit:N=>y.selectItem(rn(N,m)),cancel:y.close}):void 0,onSelect:(p,y)=>_(p.item,y)}),T=g.mergeRegister(...Na(n,r,()=>E.close(!1)));return()=>{T(),E.destroy()}},Wa=["script","style","iframe","object","embed","meta","link","xml","svg","math","canvas","form","input","button","select","textarea"].join(","),Va=[".bridgerte__code-header",".bridgerte__code-block-control",".bridgerte__code-block-controls-layer",".bridgerte__code-block-menu",".bridgerte__table-controls-layer",".bridgerte__table-controls",".bridgerte__media-controls-layer",".bridgerte__media-controls",".bridgerte__dialog-backdrop",".bridgerte__dialog",".bridgerte__payload-panel",'[data-bridgerte-clipboard-ui="true"]'].join(","),Ua=new Set(["A","B","BLOCKQUOTE","BR","CODE","DEL","DIV","EM","H1","H2","H3","H4","H5","H6","FONT","I","LI","OL","P","PRE","S","SPAN","STRIKE","STRONG","SUB","SUP","TABLE","TBODY","TFOOT","TD","TH","THEAD","TR","TT","U","UL"]),qa=new Set(["http:","https:","mailto:"]),ja="p,div,blockquote,pre,h1,h2,h3,h4,h5,h6,ul,ol,table",Ka="p,blockquote,pre,h1,h2,h3,h4,h5,h6,ul,ol,table",Ga=new Set(["colspan","rowspan"]),Ya=new Set(["TD","TH"]),Xa=new Set(["M","O","V","W"]),Ja=new Set(["SPAN"]),Qa=new Set(["color","background-color"]),Za=/^#([\da-f]{3}|[\da-f]{6}|[\da-f]{8})$/i,Tt=new Map([["B","strong"],["DEL","s"],["I","em"],["STRIKE","s"],["TT","code"]]),es=e=>{try{const t=new URL(e,window.location.href);return qa.has(t.protocol)}catch{return!1}},Ke=e=>{e.replaceWith(...e.childNodes)},Ge=(e,t)=>{const n=e.ownerDocument.createElement(t);return n.append(...e.childNodes),e.replaceWith(n),n},ts=e=>{const t=e.tagName.split(":")[0]??"";return e.tagName.includes(":")&&Xa.has(t)},on=e=>{[...e.childNodes].forEach(t=>{if(t.nodeType===Node.COMMENT_NODE){t.remove();return}on(t)})},an=e=>{[...e.childNodes].forEach(t=>{if(t.nodeType===Node.TEXT_NODE){const n=t.parentElement,r=!!(n!=null&&n.closest("pre,code,textarea")),o=(t.textContent??"").replace(/[\u200B-\u200D\uFEFF]/g,"").replace(/\u00A0/g,r?" ":" ");if(r){t.textContent=o;return}let a=o.replace(/\s+/g," ");t.previousSibling||(a=a.trimStart()),t.nextSibling||(a=a.trimEnd()),t.textContent=a;return}an(t)})},ns=e=>/^[1-9]\d*$/.test(e.trim()),Ye=e=>{const t=e.trim().toLowerCase(),[,n]=t.match(Za)??[];return n?n.length===8?`#${n.slice(2)}`:t:null},rs=(e,t)=>{if(!Ja.has(e))return null;const n=t.split(";").flatMap(r=>{const[o,...a]=r.split(":"),s=o==null?void 0:o.trim().toLowerCase(),l=Ye(a.join(":"));return!s||!l||!Qa.has(s)?[]:[`${s}: ${l}`]});return n.length>0?`${n.join("; ")};`:null},os=e=>{if(ts(e)){e.remove();return}if(!Ua.has(e.tagName)){Ke(e);return}[...e.attributes].forEach(t=>{const n=t.name.toLowerCase();if(n.startsWith("on")){e.removeAttribute(t.name);return}if(n==="style"){const r=rs(e.tagName,t.value);if(r){e.setAttribute(t.name,r);return}e.removeAttribute(t.name);return}if(e.tagName==="A"&&n==="href"){if(es(t.value))return;e.removeAttribute(t.name);return}if(!(e.tagName==="A"&&["target","rel","title"].includes(n))){if(e.tagName==="PRE"&&n===Ce){const r=Z(t.value);if(r){e.setAttribute(t.name,r);return}e.removeAttribute(t.name);return}if(e.tagName==="FONT"&&n==="color"){if(Ye(t.value))return;e.removeAttribute(t.name);return}Ya.has(e.tagName)&&Ga.has(n)&&ns(t.value)||e.removeAttribute(t.name)}})},as=e=>{[...e.querySelectorAll("font")].forEach(t=>{const n=t.getAttribute("color"),r=n?Ye(n):null,o=Ge(t,"span");r&&o.setAttribute("style",`color: ${r};`)})},ss=e=>{[...e.querySelectorAll([...Tt.keys()].join(","))].forEach(t=>{const n=Tt.get(t.tagName);n&&Ge(t,n)})},is=e=>{[...e.querySelectorAll("div")].reverse().forEach(t=>{if(t.querySelector(Ka)){Ke(t);return}Ge(t,"p")})},ls=e=>{[...e.querySelectorAll("span")].forEach(t=>{t.attributes.length===0&&Ke(t)})},cs=e=>!["P","DIV","SPAN"].includes(e.tagName)||e.querySelector("br,table,ul,ol")?!1:!(e.textContent??"").trim(),Nt=e=>{[...e.querySelectorAll("p,div,span")].reverse().forEach(t=>{cs(t)&&t.remove()})},ds=e=>{var t;return e.nodeType===Node.TEXT_NODE?!!((t=e.textContent)!=null&&t.trim()):e.nodeType!==Node.ELEMENT_NODE?!1:!e.matches(ja)},us=e=>{let t=[];const n=()=>{if(t.length===0)return;const r=e.ownerDocument.createElement("p"),o=t[0];o&&(e.insertBefore(r,o),t.forEach(a=>{r.append(a)}),t=[])};[...e.childNodes].forEach(r=>{var o;if(r.nodeType===Node.TEXT_NODE&&!((o=r.textContent)!=null&&o.trim())){r.remove();return}if(ds(r)){t.push(r);return}n()}),n()},gs=e=>{const t=document.createElement("template");t.innerHTML=e,t.content.querySelectorAll(Wa).forEach(r=>{r.remove()}),t.content.querySelectorAll(Va).forEach(r=>{r.remove()}),on(t.content),Lr(t.content),[...t.content.querySelectorAll("*")].forEach(os),an(t.content),as(t.content),ss(t.content),is(t.content),ls(t.content),Nt(t.content);const n=document.createElement("div");return n.append(t.content.cloneNode(!0)),us(n),Nt(n),n.innerHTML},ms=/^https?:\/\/[^\s<>"']+\.[^\s<>"']+$/i,hs=/^www\.[^\s<>"']+\.[^\s<>"']+$/i,ps=new RegExp(`^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+(?:/[^\\s<>"']*)?$`,"i"),fs=/^[^\s@]+@[^\s@]+\.[^\s@]+$/i,bs=e=>e.type.startsWith("image/")?"image":e.type.startsWith("video/")?"video":null,sn=e=>e?[...e].flatMap(t=>{const n=bs(t);return n?[{type:n,file:t}]:[]}):[],Ee=e=>({text:(e==null?void 0:e.getData("text/plain"))??"",html:(e==null?void 0:e.getData("text/html"))??"",files:e!=null&&e.files?[...e.files]:[]}),ys=e=>({name:e.name,mimeType:e.type||void 0,size:e.size,data:e}),vs=e=>{const t=e.trim();return!t||/\s/.test(t)||t.includes("<")||t.includes(">")||/^[a-z][a-z0-9+.-]*:/i.test(t)&&!/^https?:\/\//i.test(t)||fs.test(t)?!1:ms.test(t)||hs.test(t)||ps.test(t)},ln=(e,{isReadonly:t,executeCommand:n})=>t()||!vs(e.text)?!1:(n({type:"link.set",href:e.text.trim()}),!0),Ae=(e,{isReadonly:t,canUploadMedia:n,uploadMediaFile:r})=>{if(t()||!n())return!1;const o=sn(e.files);return o.length===0?!1:(o.forEach(({type:a,file:s})=>{r(a,s)}),!0)},ws=(e,t)=>{const r=new DOMParser().parseFromString(t,"text/html");Rr(r.body);const o=Be.$generateNodesFromDOM(e,r);return Pr(o,r.body),o},Cs=(e,t)=>{const n=ws(e,t);if(n.length===0)return!1;if(g.$getSelection()||g.$getRoot().selectEnd(),n.some(H.$isCodeNode)){n.forEach(o=>{De.$insertNodeToNearestRoot(o)});const r=n[n.length-1];return r&&H.$isCodeNode(r)&&g.$insertNodes([g.$createParagraphNode()]),!0}return g.$insertNodes(n),!0},cn=(e,{editor:t,isReadonly:n})=>{if(n())return!1;if(!e.html.trim())return _s(e,{editor:t,isReadonly:n});const r=gs(e.html);return r.trim()?(t.update(()=>{Cs(t,r)}),!0):!1},_s=(e,{editor:t,isReadonly:n})=>n()||e.html.trim()||!e.text?!1:(t.update(()=>{g.$getSelection()||g.$getRoot().selectEnd(),g.$insertNodes([g.$createTextNode(e.text)])}),!0),J=e=>{e.preventDefault(),e.stopImmediatePropagation()},Es=(e,t)=>Ae(e,t)||ln(e,t)||cn(e,t),Ms=e=>{const t=n=>{n.defaultPrevented||ln(Ee(n.clipboardData),e)&&J(n)};return e.target.addEventListener("paste",t,{capture:!0}),()=>{e.target.removeEventListener("paste",t,{capture:!0})}},ks=e=>{const t=o=>{o.defaultPrevented||Ae(Ee(o.clipboardData),e)&&J(o)},n=o=>{var s;if(e.isReadonly()||!e.canUploadMedia())return;const a=(s=o.dataTransfer)!=null&&s.files?[...o.dataTransfer.files]:[];sn(a).length!==0&&(o.preventDefault(),o.dataTransfer&&(o.dataTransfer.dropEffect="copy"))},r=o=>{var s;const a={files:(s=o.dataTransfer)!=null&&s.files?[...o.dataTransfer.files]:[]};Ae(a,e)&&J(o)};return e.target.addEventListener("paste",t,{capture:!0}),e.target.addEventListener("dragover",n),e.target.addEventListener("drop",r),()=>{e.target.removeEventListener("paste",t,{capture:!0}),e.target.removeEventListener("dragover",n),e.target.removeEventListener("drop",r)}},xs=e=>{const t=n=>{n.defaultPrevented||!cn(Ee(n.clipboardData),e)||J(n)};return e.target.addEventListener("paste",t,{capture:!0}),()=>{e.target.removeEventListener("paste",t,{capture:!0})}},Ts=({target:e,isReadonly:t,onPaste:n,canUploadMedia:r,uploadMediaFile:o,executeCommand:a,editor:s})=>{const l=(i,m)=>Es({text:m.text??i.text,html:m.html??i.html,files:i.files},{isReadonly:t,canUploadMedia:r,uploadMediaFile:o,executeCommand:a,editor:s}),c=i=>{if(t()||!n)return;const m=Ee(i.clipboardData),_=n({text:m.text,html:m.html,files:m.files.map(ys)});if(_ instanceof Promise){J(i),_.then(E=>{E!==!0&&E&&l(m,E)});return}if(_===!0){J(i);return}_&&(J(i),l(m,_))};return e.addEventListener("paste",c,{capture:!0}),()=>{e.removeEventListener("paste",c,{capture:!0})}},Ns=["paragraph","heading-1","heading-2","heading-3","quote","code-block","ordered-list","unordered-list","todo-list","divider","upload-image","upload-video","table"],Ss={loadingText:"加载中",emptyText:"没有匹配的命令",errorText:"命令加载失败"},Ls=e=>({...Ss,...e}),Rs=e=>e.flatMap(t=>t.type==="button"?[t.item]:t.type==="group"?t.items:[]),Ps=e=>({...e,toolbarKeys:(e==null?void 0:e.toolbarKeys)??Ns}),Is=e=>({id:e.id,label:e.label,command:e.command,icon:e.icon,requiresPayload:e.requiresPayload,payloadPanel:e.payloadPanel,group:e.group,source:"schema"}),$s=(e,t)=>Rs(W.resolveToolbarMenu(Ps(t),e)).map(Is),dn=e=>({...e,source:"provider"}),As=/(?:^|\s)\/([\p{L}\p{N}_-]*)$/u,Bs=e=>e.trim().toLowerCase(),Ds=e=>[e.label,e.id,e.description,e.group,...e.keywords??[]].filter(Boolean).join(" ").toLowerCase(),Os=(e,t)=>{const n=Bs(t);return n?e.filter(r=>Ds(r).includes(n)):e},Hs=async(e,t)=>(await Promise.resolve((t==null?void 0:t(e))??[])).map(dn),Fs=e=>"source"in e?e:dn(e),zs=({menuSchema:e,slashCommandConfig:t})=>e!==void 0||t!==void 0,Ws=()=>{const e=g.$getSelection();if(!g.$isRangeSelection(e)||!e.isCollapsed())return null;const t=e.anchor,n=t.getNode();if(!(n instanceof g.TextNode))return null;const o=n.getTextContent().slice(0,t.offset).match(As);if(!o)return null;const a=o[1]??"",s=o[0]??"",l=s.startsWith("/")?0:1,c=t.offset-s.length+l;return{query:a,nodeKey:n.getKey(),startOffset:c,endOffset:t.offset}},Vs=()=>{const e=document.createElement("div");return e.className="bridgerte__floating-menu bridgerte__slash-command-menu",e.dataset.visible="false",e},Us=()=>{const e=document.createElement("span");return e.className="bridgerte__slash-command-anchor",e.setAttribute("aria-hidden","true"),e},St=(e,t)=>{var s;const n=e.getElementByKey(t.nodeKey),r=je(n,t.startOffset+1);if(!(r instanceof Text))return null;const o=document.createRange(),a=Math.min(t.startOffset+1,((s=r.textContent)==null?void 0:s.length)??0);return a<=t.startOffset?null:(o.setStart(r,t.startOffset),o.setEnd(r,a),o.getBoundingClientRect())},qs=(e,t,n,r)=>{const o=document.createElement("button"),a=document.createElement("span");if(o.type="button",o.className="bridgerte__menu-item bridgerte__slash-command-item",o.dataset.commandId=e.id,o.dataset.index=String(t),o.dataset.active=String(n),e.icon){const s=document.createElement("span");s.className="bridgerte__slash-command-item-icon",s.setAttribute("aria-hidden","true"),qe(s,r[e.icon]??Ue[e.icon],e.label),o.append(s)}if(a.className="bridgerte__slash-command-item-title",a.textContent=e.label,o.append(a),e.description){const s=document.createElement("span");s.className="bridgerte__slash-command-item-description",s.textContent=e.description,o.append(s)}return o},js=(e,t)=>{const n=document.createElement("div");return n.className="bridgerte__slash-command-status",n.dataset.status=e,n.textContent=t,n},Ks=(e,t)=>{switch(e){case"loading":return t.loadingText;case"empty":return t.emptyText;case"error":return t.errorText}},Lt=e=>e?{x:e.x,y:e.y,width:e.width,height:e.height}:void 0,Gs=({editorRoot:e,contentElement:t,editor:n,isReadonly:r,executeCommand:o,requestPayloadPanel:a,menuSchema:s,slashCommandConfig:l,icons:c={},menuLabels:i,payloadPanelConfig:m,slashCommandMenuConfig:_,onSlashCommandMenuRequest:E,slashCommandProvider:T})=>{const p=Vs(),y=Us(),N=Ls(_),h=_e(s??W.defaultMenuSchema,{menuLabels:i,payloadPanelConfig:m}),w=$s(h,l),S=new Map(h.map(u=>[u.id,u])),k=zs({menuSchema:s,slashCommandConfig:l}),P=u=>{n.update(()=>{const d=g.$getNodeByKey(u.nodeKey);d instanceof g.TextNode&&(d.spliceText(u.startOffset,u.endOffset-u.startOffset,""),d.select(u.startOffset,u.startOffset))})};return nn({editorRoot:e,contentElement:t,editor:n,isReadonly:r,menu:p,anchor:y,itemSelector:".bridgerte__slash-command-item",getCurrentTrigger:Ws,getTriggerRect:u=>St(n,u),resolveItems:async u=>{const d=k||!T?Os(w,u):[];try{const b=await Hs(u,T);return[...d,...b]}catch(b){if(d.length>0)return d;throw b}},renderItem:(u,d,b)=>qs(u,d,b,c),renderStatus:u=>js(u,Ks(u,N)),onStateChange:E?(u,d)=>E({id:`bridgerte-slash-command-menu-${u.requestId}`,query:u.trigger.query,status:u.status,items:u.items,config:N,readonly:r(),anchorRect:Lt(d.anchorRect),...u.error?{error:u.error}:{},submit:b=>d.selectItem(Fs(b)),cancel:d.close}):void 0,onSelect:(u,d)=>{P(d);const b=u.source==="schema"?S.get(u.id):void 0;if(b!=null&&b.payloadPanel){const v=St(n,d);a({menuId:b.id,command:b.command,panel:b.payloadPanel,anchorRect:Lt(v??void 0)});return}o(u.command)}}).destroy},Rt=32,xe=e=>{var t;return e instanceof HTMLElement&&e.getAttribute("role")==="checkbox"&&((t=e.parentElement)==null?void 0:t.classList.contains("bridgerte__list--todo"))===!0},Te=e=>e instanceof HTMLElement?e.closest('[role="checkbox"]'):null,Ys=e=>g.$getNearestNodeFromDOMNode(e),Pt=e=>e.button===0,Ne=(e,t)=>{const n=t.getBoundingClientRect();return t.dir==="rtl"?e.clientX>=n.right-Rt&&e.clientX<=n.right:e.clientX>=n.left&&e.clientX<=n.left+Rt},It=e=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},Xs=({contentElement:e,editor:t,isReadonly:n})=>{let r=0;const o=c=>{if(n()||!Pt(c))return;const i=Te(c.target);!i||!xe(i)||Ne(c,i)&&It(c)},a=(c,i)=>{It(c),t.update(()=>{const m=Ys(i);U.$isListItemNode(m)&&m.toggleChecked()})},s=c=>{if(n()||!Pt(c)||Date.now()-r<700)return;const i=Te(c.target);!i||!xe(i)||Ne(c,i)&&a(c,i)},l=c=>{if(n()||c.pointerType!=="touch")return;const i=Te(c.target);!i||!xe(i)||Ne(c,i)&&(r=Date.now(),a(c,i))};return e.addEventListener("pointerdown",o,!0),e.addEventListener("pointerup",l,!0),e.addEventListener("click",s,!0),()=>{e.removeEventListener("pointerdown",o,!0),e.removeEventListener("pointerup",l,!0),e.removeEventListener("click",s,!0)}},Js={...H.PrismTokenizer,defaultLanguage:null},Se=(e,t)=>{var n;return((n=e.floatingMenus)==null?void 0:n[t])!==!1},Qs=({options:e,lexicalEditor:t,editorRoot:n,contentElement:r,historyState:o,isReadonly:a,executeCommand:s,requestPayloadPanel:l,uploadMediaFile:c,canUploadMedia:i,syncAfterEditorUpdate:m,refreshCommandStates:_,getCommandStates:E,setCanUndo:T,setCanRedo:p,enableKeyboardShortcuts:y})=>{const N=Se(e,"mention"),h=Se(e,"slash"),w=Se(e,"hoverbar"),S=g.mergeRegister(Ts({target:r,isReadonly:a,onPaste:e.onPaste,canUploadMedia:i,uploadMediaFile:c,executeCommand:s,editor:t}),ks({target:r,isReadonly:a,canUploadMedia:i,uploadMediaFile:c}),Ms({target:r,isReadonly:a,executeCommand:s}),xs({target:r,editor:t,isReadonly:a}),ra({target:r,isReadonly:a}),Q.registerRichText(t),H.registerCodeHighlighting(t,Js),$t.registerHistory(t,o,pr),U.registerList(t),U.registerCheckList(t),Xs({contentElement:r,editor:t,isReadonly:a}),N?za({editorRoot:n,contentElement:r,editor:t,isReadonly:a,executeCommand:s,mentionProvider:e.mentionProvider,mentionMenuConfig:e.mentionMenuConfig,onMentionMenuRequest:e.onMentionMenuRequest}):()=>{},w?ga({editorRoot:n,contentElement:r,editor:t,isReadonly:a,executeCommand:s,requestPayloadPanel:l,getCommandStates:E,menuSchema:e.menuSchema,hoverbarConfig:e.hoverbarConfig,icons:e.icons,menuLabels:e.menuLabels,payloadPanelConfig:e.payloadPanelConfig}):()=>{},B.registerTablePlugin(t),Qo({editor:t}),h?Gs({editorRoot:n,contentElement:r,editor:t,isReadonly:a,executeCommand:s,requestPayloadPanel:l,menuSchema:e.menuSchema,slashCommandConfig:e.slashCommandConfig,icons:e.icons,menuLabels:e.menuLabels,payloadPanelConfig:e.payloadPanelConfig,slashCommandMenuConfig:e.slashCommandMenuConfig,onSlashCommandMenuRequest:e.onSlashCommandMenuRequest,slashCommandProvider:e.slashCommandProvider}):()=>{},Ln({editor:t,contentElement:r,isReadonly:a}),y?ya({target:r,isReadonly:a,executeCommand:s}):()=>{},t.registerUpdateListener(()=>{m(),_()}),t.registerCommand(g.SELECTION_CHANGE_COMMAND,()=>(_(),!1),g.COMMAND_PRIORITY_LOW),t.registerCommand(g.CAN_UNDO_COMMAND,k=>(T(k),!1),g.COMMAND_PRIORITY_LOW),t.registerCommand(g.CAN_REDO_COMMAND,k=>(p(k),!1),g.COMMAND_PRIORITY_LOW));return{destroy(){S()}}};function un(e,t={}){const n=$t.createEmptyHistoryState(),r=t.mediaDefaultWidthPercent??50,{contentElement:o}=Ko(e,{placeholder:t.placeholder??Tn}),a=t.keyboardShortcuts===!0;let s=t.readonly??!1,l=!1,c=Le(t.value);const i=g.createEditor({namespace:fr,editable:!s,nodes:[Q.HeadingNode,Q.QuoteNode,H.CodeNode,H.CodeHighlightNode,U.ListNode,U.ListItemNode,B.TableNode,B.TableRowNode,B.TableCellNode,z.LinkNode,z.AutoLinkNode,ue,ae,ge],theme:tr,onError:u=>{q(t,"lexical.runtime","Lexical runtime error.",u)}});B.setScrollableTablesActive(i,!0);const m=()=>l,_=()=>s,E=()=>{m()||Sn({editor:i,contentElement:o})},T=Go({editor:i}),p=br({lexicalEditor:i,options:t,isDestroyed:m,setContent:u=>{c=u},syncPlaceholder:E}),y=Gn({lexicalEditor:i,options:t,isDestroyed:m,canUploadMedia:()=>t.uploadAdapter!==void 0,isReadonly:_}),N=hr({container:e,lexicalEditor:i,options:t,isDestroyed:m,isReadonly:_,reportError:q}),h=()=>{o.contentEditable=String(!s),i.setEditable(!s)},S=jo({editorRoot:e,lexicalEditor:i,isReadonly:_,restoreEditorFocus:u=>{T.restore(),i.focus(u)},executeCommand:N,getClearCommand:u=>{switch(u.command.type){case"format.color":case"format.backgroundColor":case"format.fontSize":case"format.fontFamily":case"format.lineHeight":return{...u.command,value:""};default:return null}},codeBlockLanguagePanel:t.codeBlockLanguagePanel,payloadPanelConfig:t.payloadPanelConfig,mediaControlsConfig:t.mediaControlsConfig,menuLabels:t.menuLabels,onRequest:t.onPayloadPanelRequest,defaultMediaWidthPercent:r}),k=()=>qn(t),P=()=>jn(t),I=u=>{m()||(T.capture(),S.payloadPanelController.open(u))};e.dataset.readonly=String(s),e.addEventListener("focusin",k),e.addEventListener("focusout",P),e.style.setProperty("--bridgerte-media-display-width",`${r}%`);const M=Qs({options:t,lexicalEditor:i,editorRoot:e,contentElement:o,historyState:n,isReadonly:_,executeCommand:N,requestPayloadPanel:I,uploadMediaFile:N.uploadMediaFile,canUploadMedia:()=>t.uploadAdapter!==void 0,syncAfterEditorUpdate:p.syncAfterEditorUpdate,refreshCommandStates:y.refreshCommandStates,getCommandStates:y.getCommandStates,setCanUndo:y.setCanUndo,setCanRedo:y.setCanRedo,enableKeyboardShortcuts:a});i.setRootElement(o),p.suppressNextChange(),c=En(i,t.value),h();const f={getContent(){return m()||(p.clearContentChangeTimer(),p.syncContent(!1)),c},setContent(u){m()||(p.clearContentChangeTimer(),c=Le(u),p.suppressNextChange(),Ht(i,c),p.enforceCurrentMaxLength(),E(),i.dispatchCommand(g.CLEAR_HISTORY_COMMAND,void 0),y.setHistoryAvailability(!1,!1),p.syncContent(!0))},executeCommand(u){N(u)},requestPayloadPanel:I,getCommandStates:y.getCommandStates,subscribeCommandStateChange:y.subscribeCommandStateChange,setReadonly(u){m()||(s=u,e.dataset.readonly=String(s),h(),y.refreshCommandStates())},focus(){m()||i.focus()},blur(){m()||o.blur()},destroy(){m()||(l=!0,p.clearContentChangeTimer(),S.destroy(),N.destroy(),y.destroy(),T.clear(),M.destroy(),i.setRootElement(null),e.removeEventListener("focusin",k),e.removeEventListener("focusout",P),e.classList.remove("bridgerte"),e.textContent="",delete e.dataset.readonly)}};return p.syncContent(!1),E(),y.refreshCommandStates(),Kn(t,f),f}const Zs=e=>!we.isBridgeMessage(e)||!("id"in e)?!1:e.type==="editor.init"||e.type==="editor.executeCommand"||e.type==="editor.setContent"||e.type==="editor.setReadonly"||e.type==="editor.requestContent"||e.type==="editor.payloadPanelResolved"||e.type==="editor.payloadPanelCanceled"||e.type==="editor.uploadResolved"||e.type==="editor.uploadRejected",ei=e=>({id:e,type:"editor.ready",payload:{menuSchema:W.defaultMenuSchema,eventTiming:we.defaultBridgeEventTiming,version:G.BRIDGERTE_CONTENT_VERSION}}),ti=e=>`native-upload:${e}:${Date.now()}:${Math.random().toString(36).slice(2)}`,ni=({container:e,transport:t})=>{var M;let n=null,r=!1,o=null,a=null,s=null,l=0;const c=new Map,i=new Map,m=f=>{r||t.postMessage(f)},_=()=>{s&&(clearTimeout(s),s=null)},E=()=>{_(),s=setTimeout(()=>{if(r)return;const f=Math.ceil(e.getBoundingClientRect().height);f!==l&&(l=f,m({type:"editor.heightChange",payload:{height:f}}))},we.BRIDGE_HEIGHT_CHANGE_THROTTLE_MS)},T=f=>{if(!n)return;const u=n.getContent();m({id:f,type:"editor.content",payload:u}),m({id:f,type:"editor.contentChange",payload:u})},p=f=>{const u=f.payload,d=c.get(u.assetId);if(d){if(c.delete(u.assetId),d.source==="uploadAdapter"){d.resolve(u.result);return}n==null||n.executeCommand({type:d.type==="image"?"media.insertImage":"media.insertVideo",url:u.result.url,poster:u.result.poster,width:u.result.width,height:u.result.height,displayWidthPercent:50,assetId:u.assetId})}},y=f=>{const u=f.payload,d=c.get(u.assetId);if(d){if(c.delete(u.assetId),d.source==="uploadAdapter"){d.reject(new Error(u.message));return}m({id:f.id,type:"editor.error",payload:{code:"bridge.uploadRejected",message:u.message}})}},N=(f,u)=>new Promise((d,b)=>{c.set(u,{type:f,assetId:u,source:"uploadAdapter",resolve:d,reject:b}),m({type:"editor.uploadRequest",payload:{assetId:u,type:f,accept:f==="image"?"image/*":"video/*"}})}),h=f=>{const u=ti(f);c.set(u,{type:f,assetId:u,source:"nativePicker"}),m({type:"editor.uploadRequest",payload:{assetId:u,type:f,accept:f==="image"?"image/*":"video/*"}})},w=f=>{const u=i.get(f.payload.requestId);u&&(i.delete(f.payload.requestId),u.request.submit(f.payload.values))},S=f=>{const u=i.get(f.payload.requestId);u&&(i.delete(f.payload.requestId),u.request.cancel())},k=(f,u)=>{n==null||n.destroy(),o==null||o(),c.clear(),i.clear(),n=un(e,{...u,uploadAdapter:{uploadImage(d,b){return N("image",b.assetId)},uploadVideo(d,b){return N("video",b.assetId)}},onContentChange:d=>{m({type:"editor.contentChange",payload:d}),E()},onCommandStateChange:d=>{m({type:"editor.commandStateChange",payload:d})},onPayloadPanelRequest:d=>(i.set(d.id,{request:d}),m({type:"editor.payloadPanelRequest",payload:{menuId:d.menuId,command:d.command,panel:d.panel,anchorRect:d.anchorRect,currentValues:d.currentValues,id:d.id,readonly:d.readonly}}),!0),onError:d=>{m({type:"editor.error",payload:d})}}),o=n.subscribeCommandStateChange(d=>{m({type:"editor.commandStateChange",payload:d})}),m(ei(f)),E()},P=f=>{if(f.type==="media.pickImage"){h("image");return}if(f.type==="media.pickVideo"){h("video");return}n==null||n.executeCommand(f)},I=f=>{if(!(r||!Zs(f)))switch(f.type){case"editor.init":k(f.id,f.payload);return;case"editor.executeCommand":P(f.payload);return;case"editor.setContent":n==null||n.setContent(f.payload);return;case"editor.setReadonly":n==null||n.setReadonly(f.payload.readonly);return;case"editor.requestContent":T(f.id);return;case"editor.payloadPanelResolved":w(f);return;case"editor.payloadPanelCanceled":S(f);return;case"editor.uploadResolved":p(f);return;case"editor.uploadRejected":y(f);return}};return a=((M=t.addMessageListener)==null?void 0:M.call(t,I))??null,{receive:I,destroy(){r||(r=!0,_(),a==null||a(),o==null||o(),c.clear(),i.clear(),n==null||n.destroy(),n=null)}}};exports.appendMenuIcon=qe;exports.bindTouchPressedState=V;exports.createFloatingLayer=Ve;exports.createRichTextEditor=un;exports.createWebViewBridgeRuntime=ni;exports.defaultMenuIcons=Ue;exports.getMenuStateForItem=Kt;exports.getPayloadPanelCurrentValues=jt;exports.resolveMenuSchemaForDom=_e;
3
- //# sourceMappingURL=index-CkgUKPh3.cjs.map