bridgerte 0.9.13 → 0.9.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +864 -864
- package/dist/bridge.cjs.map +1 -1
- package/dist/bridge.js.map +1 -1
- package/dist/dom.cjs +1 -1
- package/dist/dom.js +2 -2
- package/dist/{index-DDfgjstx.js → index-09ZQ5n0I.js} +1243 -1201
- package/dist/index-09ZQ5n0I.js.map +1 -0
- package/dist/index-CKIFd9T9.cjs +4 -0
- package/dist/index-CKIFd9T9.cjs.map +1 -0
- package/dist/{index-DZnoOnKI.cjs → index-ClgxmJNW.cjs} +3 -3
- package/dist/index-ClgxmJNW.cjs.map +1 -0
- package/dist/index-CuNKUHed.js.map +1 -1
- package/dist/index-DF8OhKI4.cjs.map +1 -1
- package/dist/index-GaS65GL0.cjs.map +1 -1
- package/dist/{index-CXVSZZ93.js → index-PixgfP7_.js} +3 -3
- package/dist/index-PixgfP7_.js.map +1 -0
- package/dist/index-sbZNOcCB.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/native-spec.cjs.map +1 -1
- package/dist/native-spec.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/webview.cjs +1 -1
- package/dist/webview.js +1 -1
- package/package.json +1 -1
- package/dist/index-BBzHVrSi.cjs +0 -4
- package/dist/index-BBzHVrSi.cjs.map +0 -1
- package/dist/index-CXVSZZ93.js.map +0 -1
- package/dist/index-DDfgjstx.js.map +0 -1
- package/dist/index-DZnoOnKI.cjs.map +0 -1
package/dist/index-BBzHVrSi.cjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
"use strict";var Sn=Object.defineProperty;var Ln=(e,t,n)=>t in e?Sn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Ae=(e,t,n)=>Ln(e,typeof t!="symbol"?t+"":t,n);const Le=require("./bridge.cjs"),Y=require("./index-GaS65GL0.cjs"),d=require("lexical"),te=require("@lexical/rich-text"),O=require("@lexical/code"),V=require("@lexical/list"),D=require("@lexical/table"),F=require("@lexical/link"),Ut=require("@lexical/history"),Xe=require("@lexical/html"),G=require("@lexical/selection"),Re=require("@lexical/utils"),z=require("./native-spec.cjs"),jt=require("./index-DF8OhKI4.cjs"),U=require("@lexical/code-shiki"),oe=require("@floating-ui/dom"),ct="bridgerte-media",Kt="Loading",dt=(e,t)=>`${e}:${t}`,ae=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?Math.floor(e):void 0,ut=e=>typeof e=="number"&&Number.isFinite(e)?Math.min(Math.max(e,0),100):void 0,Rn=e=>e===20||e===50||e===100,gt=e=>Rn(e)?e:void 0,mt=e=>e==="center"||e==="right"?e:void 0,In=e=>e.status==="error"?e.errorMessage??"媒体加载失败":Kt,Pn=(e,t)=>!t||e.status===void 0||e.status==="success",Be=(e,t,n)=>{n&&e.setAttribute(t,n)},ht=(e,t,n)=>{n!==void 0&&e.setAttribute(t,String(n))};class ce extends d.DecoratorNode{constructor(n,r){super(r);Ae(this,"__payload");this.__payload={...n,assetId:n.assetId??dt(n.mediaType,n.url),width:ae(n.width),height:ae(n.height),duration:ae(n.duration),progress:ut(n.progress),displayWidthPercent:gt(n.displayWidthPercent),align:mt(n.align)},this.__payload.displayWidthPercent===void 0&&delete this.__payload.displayWidthPercent,this.__payload.align===void 0&&delete this.__payload.align}static getType(){return ct}static clone(n){return new ce(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:$n,priority:1}),video:()=>({conversion:An,priority:1})}}static importJSON(n){return de(n).updateFromJSON(n)}exportJSON(){return{...super.exportJSON(),...this.__payload,type:ct}}getTextContent(){return this.__payload.title??this.__payload.alt??this.__payload.url}isInline(){return!1}getAsset(){const n=this.__payload,r={id:n.assetId??dt(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:ae(n.width??r.__payload.width),height:ae(n.height??r.__payload.height),duration:ae(n.duration??r.__payload.duration),progress:ut(n.progress??r.__payload.progress),displayWidthPercent:Object.prototype.hasOwnProperty.call(n,"displayWidthPercent")?gt(n.displayWidthPercent):r.__payload.displayWidthPercent,align:Object.prototype.hasOwnProperty.call(n,"align")?mt(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"};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}));const c=Pn(r,n);if(r.mediaType==="image"?(c&&a.setAttribute("src",r.url),a.setAttribute("loading","lazy"),Be(a,"alt",r.alt??r.title)):(c&&a.setAttribute("src",r.url),a.setAttribute("controls","true"),a.setAttribute("preload","metadata"),Be(a,"poster",r.poster)),Be(a,"title",r.title),ht(a,"width",r.width),ht(a,"height",r.height),n){const u=document.createElement("div"),l=document.createElement("span"),p=document.createElement("span");u.className="bridgerte__media-placeholder",u.setAttribute("aria-hidden","true"),l.className="bridgerte__media-placeholder-icon",l.textContent=r.mediaType==="image"?"IMG":"VIDEO",p.className="bridgerte__media-placeholder-text",p.textContent=In(r),u.append(l,p),o.append(u)}if(o.append(a),r.status==="uploading"||r.status==="error"){const u=document.createElement("figcaption");u.className="bridgerte__media-status",u.textContent=r.status==="error"?r.errorMessage??"上传失败":Kt,o.append(u)}return o}}const $n=e=>{const t=e instanceof HTMLImageElement?e:null;return{node:t!=null&&t.src?de({mediaType:"image",url:t.src,alt:t.alt,title:t.title,width:t.width,height:t.height,status:"success"}):null}},An=e=>{const t=e instanceof HTMLVideoElement?e:null;return{node:t!=null&&t.src?de({mediaType:"video",url:t.src,poster:t.poster,title:t.title,width:t.videoWidth||t.width,height:t.videoHeight||t.height,status:"success"}):null}},de=e=>d.$applyNodeReplacement(new ce(e)),Bn=e=>de({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"}),Dn=e=>de({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"}),Gt=e=>e instanceof ce,he=e=>{const t=n=>{if(Gt(n)&&n.getAsset().id===e)return n;if(!d.$isElementNode(n))return null;for(const r of n.getChildren()){const o=t(r);if(o)return o}return null};return t(d.$getRoot())},Yt={root:{type:"root",version:1,children:[]}};function Ve(e={}){return{html:e.html??"",json:e.json??Yt,plainText:e.plainText??"",assets:e.assets??[],version:e.version??Y.BRIDGERTE_CONTENT_VERSION}}const On=e=>e.toJSON(),Hn=e=>{var t;return((t=e.root.children)==null?void 0:t.length)===0},Fn=e=>e.read(()=>{const t=new Map,n=r=>{d.$isElementNode(r)&&r.getChildren().forEach(o=>{if(Gt(o)){const a=o.getAsset();t.set(a.id,a);return}d.$isElementNode(o)&&n(o)})};return n(d.$getRoot()),[...t.values()]}),Xt=(e,t)=>{const n=t.read(()=>Xe.$generateHtmlFromNodes(t)),r=e.read(()=>d.$getRoot().getTextContent()),o=Fn(e);return{html:n,json:On(e),plainText:r,assets:o,version:Y.BRIDGERTE_CONTENT_VERSION}},zn=(e,t)=>{const n=Ve(t);return Jt(e,n),Xt(e.getEditorState(),e)},Jt=(e,t)=>{if(t.json!==Yt&&!Hn(t.json)){const o=t.json;e.setEditorState(e.parseEditorState(o));return}if(!t.html){e.update(()=>{const o=d.$getRoot();o.clear(),o.append(d.$createParagraphNode())},{discrete:!0});return}const r=new DOMParser().parseFromString(t.html,"text/html");e.update(()=>{const o=d.$getRoot(),a=Xe.$generateNodesFromDOM(e,r);o.clear(),o.append(...a)},{discrete:!0})},Wn="bridgerte-divider",Qt=e=>(e==null?void 0:e.getType())===Wn,Vn=(e,t,n)=>{const r=d.$getRoot();if(r.getChildrenSize()===0){const o=d.$createParagraphNode();r.append(o),o.selectStart();return}if(n){e==null||e.selectEnd(),e||t==null||t.selectStart();return}t==null||t.selectStart(),t||e==null||e.selectEnd()},qn=(e,t)=>{const n=e.getPreviousSibling(),r=e.getNextSibling();e.remove(),Vn(n,r,t)},Un=()=>{const e=d.$getSelection();if(!d.$isNodeSelection(e))return null;const t=e.getNodes();return t.length===1&&Qt(t[0])?t[0]:null},jn=e=>e.getKey()==="root"?null:e.getTopLevelElement(),Kn=e=>{const t=d.$getSelection();if(!d.$isRangeSelection(t)||!t.isCollapsed())return null;const n=t.anchor,r=n.getNode(),o=jn(r);if(!o||!d.$isElementNode(o))return null;if(d.$isElementNode(r)){const c=r.isEmpty()&&n.offset===0,u=r===o&&n.offset===0,l=r===o&&n.offset===o.getChildrenSize();return c||(e?u:l)?o:null}if(!(r instanceof d.TextNode))return null;const a=e?o.getFirstDescendant():o.getLastDescendant(),s=e?0:r.getTextContentSize();return a===r&&n.offset===s?o:null},Gn=e=>{const t=Kn(e),n=e?t==null?void 0:t.getPreviousSibling():t==null?void 0:t.getNextSibling();return Qt(n)?n:null},Yn=(e,t)=>{const n=o=>{if(t())return!1;const a=Un()??Gn(o);return a?(qn(a,o),!0):!1},r=(o,a)=>{const s=n(a);return s&&o.preventDefault(),s};return[e.registerCommand(d.KEY_BACKSPACE_COMMAND,o=>r(o,!0),d.COMMAND_PRIORITY_HIGH),e.registerCommand(d.KEY_DELETE_COMMAND,o=>r(o,!1),d.COMMAND_PRIORITY_HIGH),e.registerCommand(d.DELETE_CHARACTER_COMMAND,o=>n(o),d.COMMAND_PRIORITY_HIGH)]};class pe extends d.DecoratorNode{static getType(){return"bridgerte-divider"}static clone(t){return new pe(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:Xn,priority:0})}}static importJSON(t){return Je().updateFromJSON(t)}exportJSON(){return{...super.exportJSON(),type:pe.getType()}}getTextContent(){return`
|
|
2
|
-
`}isInline(){return!1}}const Xn=e=>({node:Je()}),Je=()=>d.$applyNodeReplacement(new pe),pt="bridgerte-mention",Qe="mention",Zt=e=>e.label.startsWith("@")?e.label:`@${e.label}`,Jn=e=>{const t=document.createElement("span");return t.className="bridgerte__mention",t.dataset.type=Qe,t.dataset.id=e.id,t.dataset.value=e.value,t.contentEditable="false",t.textContent=Zt(e),e.description&&(t.dataset.description=e.description),t};class ye extends d.TextNode{constructor(n,r=Zt(n),o){super(r,o);Ae(this,"__item");this.__item=n}static getType(){return pt}static clone(n){return new ye(n.__item,n.__text,n.__key)}createDOM(n){const r=super.createDOM(n);return r.className="bridgerte__mention",r.dataset.type=Qe,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:Jn(this.__item)}}static importDOM(){return{span:()=>({conversion:Qn,priority:2})}}static importJSON(n){return Ze(n).updateFromJSON(n)}exportJSON(){return{...super.exportJSON(),...this.__item,type:pt}}isTextEntity(){return!0}isToken(){return!0}getMentionItem(){return this.__item}}const Qn=e=>{var a;const t=e instanceof HTMLElement?e:null;if(!t||t.dataset.type!==Qe)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:Ze({id:r,label:n,value:o,description:t.dataset.description})}},Ze=e=>d.$applyNodeReplacement(new ye(e).setMode("token")),ft=e=>e instanceof ye,Zn="请输入内容",er=()=>{const t=d.$getRoot().getChildren();if(t.length===0)return!0;if(t.length>1)return!1;const n=t[0];return d.$isParagraphNode(n)&&n.getChildrenSize()===0},tr=({editor:e,contentElement:t})=>{const n=e.getEditorState().read(er);t.dataset.empty=String(n)},nr=({editor:e,contentElement:t,isReadonly:n})=>{const r=o=>{n()||t.dataset.empty!=="true"||o.button===0&&(o.preventDefault(),e.focus(()=>{e.update(()=>{d.$getRoot().selectStart()})}))};return t.addEventListener("pointerdown",r),()=>{t.removeEventListener("pointerdown",r)}},rr=[{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"}],or=[{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"}],ar=[{command:"list.ordered",listType:"ordered"},{command:"list.unordered",listType:"unordered"},{command:"list.todo",listType:"todo"}],sr=["media.pickImage","media.pickVideo"],en=()=>{const e=d.$getSelection();if(!d.$isRangeSelection(e))return null;const t=e.anchor.getNode();return t.getKey()==="root"?t:t.getTopLevelElementOrThrow()},ir=()=>{const e=en();if(!e)return null;if(te.$isHeadingNode(e)){const t=Number(e.getTag().replace("h",""));return{command:"block.heading",value:Number.isNaN(t)?void 0:t}}if(te.$isQuoteNode(e))return{command:"block.quote"};if(O.$isCodeNode(e)){const t=e.getLatest();return{command:"block.code",value:O.$isCodeNode(t)?t.getLanguage()??"":""}}return{command:"block.paragraph"}},lr=()=>{const e=en();if(!e||!("getFormatType"in e))return;const t=e.getFormatType();return t===""?void 0:t},cr=()=>{const e=d.$getSelection();if(!d.$isRangeSelection(e))return null;const t=e.anchor.getNode(),n=V.$isListNode(t)?t:Re.$getNearestNodeOfType(t,V.ListNode);return n?n.getListType()==="check"?"todo":n.getTag()==="ol"?"ordered":"unordered":null},dr=e=>{const t=d.$getSelection();if(!d.$isRangeSelection(t))return;const n=G.$getSelectionStyleValueForProperty(t,e);return n===""?void 0:n},ur=()=>{const e=d.$getSelection();if(!d.$isRangeSelection(e))return!1;const t=e.anchor.getNode(),n=t.getParent();return F.$isLinkNode(t)||F.$isLinkNode(n)},gr=e=>{const t=d.$getSelection(),n=d.$isRangeSelection(t),r=ir(),o=cr(),a=lr(),s=ur(),c=e.readonly||!n,u=rr.map(C=>({command:C.command,active:n&&t.hasFormat(C.format),disabled:c})),l=or.map(C=>{const N=dr(C.property);return{command:C.command,active:N!==void 0,disabled:c,value:N}}),p=ar.map(C=>({command:C.command,active:o===C.listType,disabled:c})),w=sr.map(C=>({command:C,active:!1,disabled:e.readonly||!e.canUploadMedia}));return[...u,{command:"format.clear",active:!1,disabled:c},...l,{command:"block.heading",active:(r==null?void 0:r.command)==="block.heading",disabled:c,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:c},{command:"block.quote",active:(r==null?void 0:r.command)==="block.quote",disabled:c},{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},...p,{command:"align",active:a!==void 0,disabled:c,value:a},{command:"link.set",active:s,disabled:c},{command:"link.unset",active:!1,disabled:c||!s},{command:"link.open",active:!1,disabled:e.readonly||!s},{command:"indent.increase",active:!1,disabled:c},{command:"indent.decrease",active:!1,disabled:c},{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},...w,{command:"table.insert",active:!1,disabled:e.readonly},{command:"fullscreen.toggle",active:!1,disabled:!1}]},mr=(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}),j=(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)}},hr=(e,t)=>{var n;try{(n=e.onChange)==null||n.call(e,t)}catch(r){j(e,"callback.onChange","onChange callback failed.",r)}},pr=(e,t)=>{var n;try{(n=e.onContentChange)==null||n.call(e,t)}catch(r){j(e,"callback.onContentChange","onContentChange callback failed.",r)}},fr=(e,t)=>{var n;try{(n=e.onCommandStateChange)==null||n.call(e,[...t])}catch(r){j(e,"callback.onCommandStateChange","onCommandStateChange callback failed.",r)}},br=e=>{var t;try{(t=e.onFocus)==null||t.call(e)}catch(n){j(e,"callback.onFocus","onFocus callback failed.",n)}},yr=e=>{var t;try{(t=e.onBlur)==null||t.call(e)}catch(n){j(e,"callback.onBlur","onBlur callback failed.",n)}},vr=(e,t)=>{var n;try{(n=e.onReady)==null||n.call(e,t)}catch(r){j(e,"callback.onReady","onReady callback failed.",r)}},wr=({lexicalEditor:e,options:t,isDestroyed:n,canUploadMedia:r,isReadonly:o})=>{let a=!1,s=!1,c=[];const u=new Set,l=()=>{const w=[...c];u.forEach(C=>{try{C(w)}catch(N){j(t,"callback.commandStateSubscriber","Command state subscriber failed.",N)}})},p=(w=!0)=>{if(n())return;const C=c;e.getEditorState().read(()=>{c=gr({canUndo:a,canRedo:s,readonly:o(),canUploadMedia:r()})}),w&&!mr(C,c)&&(fr(t,c),l())};return{refreshCommandStates:p,getCommandStates(){return p(!1),[...c]},subscribeCommandStateChange(w){return n()?()=>{}:(u.add(w),w([...c]),()=>{u.delete(w)})},setCanUndo(w){a=w,p()},setCanRedo(w){s=w,p()},setHistoryAvailability(w,C){a=w,s=C,p()},destroy(){u.clear()}}},Cr=e=>`upload:${e}:${Date.now()}:${Math.random().toString(36).slice(2)}`,_r=e=>typeof URL.createObjectURL=="function"?URL.createObjectURL(e):e.name,ve=e=>{typeof URL.revokeObjectURL=="function"&&e.startsWith("blob:")&&URL.revokeObjectURL(e)},bt=e=>({name:e.name,mimeType:e.type||void 0,size:e.size,data:e}),Er=e=>typeof DOMException<"u"&&e instanceof DOMException&&e.name==="AbortError",kr=e=>new Promise(t=>{const n=new Image,r=()=>{n.onload=null,n.onerror=null};n.onload=()=>{const o={width:n.naturalWidth||void 0,height:n.naturalHeight||void 0};r(),t(o)},n.onerror=()=>{r(),t({})},n.src=e}),Mr=e=>new Promise(t=>{const n=document.createElement("video"),r=()=>{n.removeAttribute("src"),n.load(),n.onloadedmetadata=null,n.onerror=null};n.preload="metadata",n.onloadedmetadata=()=>{const o={width:n.videoWidth||void 0,height:n.videoHeight||void 0,duration:Number.isFinite(n.duration)?n.duration:void 0};r(),t(o)},n.onerror=()=>{r(),t({})},n.src=e,n.load()}),xr=(e,t)=>t.startsWith("blob:")?e==="image"?kr(t):Mr(t):Promise.resolve({}),Tr=(e,t)=>({...e,width:e.width??t.width,height:e.height??t.height,duration:e.duration??t.duration}),Nr=({container:e,lexicalEditor:t,options:n,isDestroyed:r})=>{const o=new Map;let a=0;const s=(m,f)=>{t.update(()=>{var k;(k=he(m))==null||k.updatePayload(f)})},c=m=>{let f=null;return t.update(()=>{const k=he(m);if(!k)return;const E=k.getAsset();f={mediaType:E.type,url:E.url,assetId:E.id,status:E.status,progress:E.progress,poster:E.poster,width:E.width,height:E.height,duration:E.duration,mimeType:E.mimeType,size:E.size,displayWidthPercent:E.displayWidthPercent,align:E.align,errorMessage:E.errorMessage},k.remove()}),f},u=(m,f)=>{const k=o.get(m);return(k==null?void 0:k.runId)===f},l=m=>{var f;(f=m.abortController)==null||f.abort()},p=(m,f)=>{const k=o.get(m);return k?(l(k),ve(k.previewUrl),o.delete(m),!0):!1},w=(m,f,k,E)=>{t.update(()=>{const I=de({mediaType:m,url:E,assetId:k,status:"uploading",progress:0,title:f.name,mimeType:f.type||void 0,size:f.size}),P=d.$createParagraphNode();d.$getSelection()||d.$getRoot().selectEnd(),d.$insertNodes([I,P]),P.selectStart()},{discrete:!0})},C=(m,f,k,E)=>{s(f,{mediaType:m,url:E.url,poster:E.poster,width:E.width,height:E.height,duration:E.duration,mimeType:E.mimeType,size:E.size,status:"success",progress:100,errorMessage:void 0}),ve(k)},N=(m,f,k)=>{var E;Er(k)||(s(f,{mediaType:m,status:"error",errorMessage:"上传失败"}),(E=n.onUploadError)==null||E.call(n,{assetId:f,type:m,cause:k}))},b=m=>{const f=n.uploadAdapter;if(!f)return;const k=typeof AbortController=="function"?new AbortController:null,E=a+1;a=E,m.runId=E,m.abortController=k,o.set(m.assetId,m);const I={assetId:m.assetId,signal:k==null?void 0:k.signal,onProgress:i=>{!u(m.assetId,E)||r()||s(m.assetId,{mediaType:m.type,status:"uploading",progress:i})}};let P={};const S=xr(m.type,m.previewUrl);let _;try{_=m.type==="image"?f.uploadImage(bt(m.file),I):f.uploadVideo(bt(m.file),I)}catch(i){u(m.assetId,E)&&N(m.type,m.assetId,i);return}S.then(i=>{P=i,!(r()||!u(m.assetId,E))&&(i.width===void 0&&i.height===void 0||s(m.assetId,{mediaType:m.type,width:i.width,height:i.height,duration:i.duration}))}),_.then(i=>{r()||!u(m.assetId,E)||(C(m.type,m.assetId,m.previewUrl,Tr(i,P)),o.delete(m.assetId))}).catch(i=>{r()||!u(m.assetId,E)||N(m.type,m.assetId,i)})},v=(m,f)=>{if(!n.uploadAdapter)return;const k=Cr(m),E=_r(f),I={assetId:k,type:m,file:f,previewUrl:E,runId:0,abortController:null};w(m,f,k,E),b(I)};return{pickMediaFile:m=>{if(!n.uploadAdapter)return;const f=e.ownerDocument.createElement("input");f.type="file",f.accept=m==="image"?"image/*":"video/*",f.style.display="none",f.addEventListener("change",()=>{var E;const k=(E=f.files)==null?void 0:E[0];f.remove(),k&&v(m,k)},{once:!0}),e.append(f),f.click()},uploadMediaFile:v,removeMedia(m){const f=c(m);!p(m)&&(f!=null&&f.url.startsWith("blob:"))&&ve(f.url)},retryMedia(m){const f=o.get(m);!f||!n.uploadAdapter||(l(f),s(m,{mediaType:f.type,url:f.previewUrl,status:"uploading",progress:0,errorMessage:void 0}),b(f))},destroy(){o.forEach(m=>{l(m),ve(m.previewUrl)}),o.clear()}}},tn=e=>O.$createCodeNode(e),Sr={1:"h1",2:"h2",3:"h3",4:"h4",5:"h5",6:"h6"},Lr={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"},Rr=e=>({setBlockHeading:l=>{e.update(()=>{const p=d.$getSelection();d.$isRangeSelection(p)&&G.$setBlocksType(p,()=>te.$createHeadingNode(Sr[l]))})},setParagraphBlock:()=>{e.update(()=>{const l=d.$getSelection();d.$isRangeSelection(l)&&G.$setBlocksType(l,()=>d.$createParagraphNode())})},setQuoteBlock:()=>{e.update(()=>{const l=d.$getSelection();d.$isRangeSelection(l)&&G.$setBlocksType(l,()=>te.$createQuoteNode())})},insertDividerBlock:()=>{e.update(()=>{const l=d.$createParagraphNode();d.$insertNodes([Je(),l]),l.selectStart()})},insertCodeBlock:l=>{e.update(()=>{const p=tn(l),w=d.$createParagraphNode();d.$insertNodes([p,w]),p.selectEnd()})},setSelectedCodeBlockLanguage:l=>{e.update(()=>{const p=d.$getSelection();if(!d.$isRangeSelection(p))return;const w=p.anchor.getNode(),C=w.getKey()==="root"?w:w.getTopLevelElementOrThrow();O.$isCodeNode(C)&&C.setLanguage(l)})},clearContent:()=>{e.update(()=>{const l=d.$getRoot();l.clear(),l.append(d.$createParagraphNode())})},formatAlign:l=>{e.dispatchCommand(d.FORMAT_ELEMENT_COMMAND,l)}}),Ir=e=>({setLink:(o,a)=>{e.update(()=>{const s=d.$getSelection(),c=F.formatUrl(o),u=(a==null?void 0:a.trim())||o.trim();if(!(!d.$isRangeSelection(s)||!o.trim())){if(s.isCollapsed()){const l=F.$createLinkNode(c,{rel:"noreferrer noopener",target:"_blank"});l.append(d.$createTextNode(u)),d.$insertNodes([l]);return}F.$toggleLink(c,{rel:"noreferrer noopener",target:"_blank"})}})},unsetLink:()=>{e.update(()=>{F.$toggleLink(null)})},openSelectedLink:()=>{if(typeof window>"u")return;const o=e.getEditorState().read(()=>{const a=d.$getSelection();if(!d.$isRangeSelection(a))return null;const s=a.anchor.getNode(),c=F.$isLinkNode(s)?s:Re.$findMatchingParent(s,F.$isLinkNode);return c?{target:c.getTarget()??"_blank",url:c.sanitizeUrl(c.getURL())}:null});o&&window.open(o.url,o.target,"noopener,noreferrer")}}),Pr=e=>({insertImage:s=>{s.url.trim()&&e.update(()=>{const c=d.$createParagraphNode();d.$insertNodes([Bn(s),c]),c.selectStart()})},insertVideo:s=>{s.url.trim()&&e.update(()=>{const c=d.$createParagraphNode();d.$insertNodes([Dn(s),c]),c.selectStart()})},resizeMedia:s=>{e.update(()=>{var c;(c=he(s.assetId))==null||c.updatePayload({displayWidthPercent:s.widthPercent})})},resetMediaSize:s=>{e.update(()=>{var c;(c=he(s))==null||c.updatePayload({displayWidthPercent:void 0})})},alignMedia:s=>{e.update(()=>{var c;(c=he(s.assetId))==null||c.updatePayload({align:s.value==="left"?void 0:s.value})})}}),$r=e=>({insertMention:n=>{e.update(()=>{const r=d.$getSelection();d.$isRangeSelection(r)&&d.$insertNodes([Ze(n),d.$createTextNode(" ")])})}}),Ar=e=>({clearSelectionFormat:()=>{e.update(()=>{const r=d.$getSelection();d.$isRangeSelection(r)&&(r.setFormat(0),G.$patchStyleText(r,{color:null,"background-color":null,"font-size":null,"font-family":null,"line-height":null}))})},setSelectionStyle:(r,o)=>{e.update(()=>{const a=d.$getSelection();d.$isRangeSelection(a)&&G.$patchStyleText(a,{[r]:o===""?null:o})})}}),Br=20,yt=(e,t)=>Number.isFinite(e)&&e>0?Math.min(Math.floor(e),t):1,we=e=>Number.isFinite(e)&&(e??0)>0?Math.min(Math.floor(e??1),Br):1,Ce=()=>{const e=d.$getSelection();return!d.$isRangeSelection(e)&&!D.$isTableSelection(e)?!1:D.$findCellNode(e.anchor.getNode())!==null},Dr=e=>({insertTable:(c,u)=>{const l=yt(c,Y.BRIDGERTE_TABLE_INSERT_MAX_ROWS),p=yt(u,Y.BRIDGERTE_TABLE_INSERT_MAX_COLS);e.dispatchCommand(D.INSERT_TABLE_COMMAND,{rows:String(l),columns:String(p),includeHeaders:{rows:!0,columns:!1}})},insertTableRow:c=>{e.update(()=>{if(!Ce())return;const u=we(c.count);for(let l=0;l<u;l+=1)D.$insertTableRowAtSelection(c.direction!=="before")})},insertTableColumn:c=>{e.update(()=>{if(!Ce())return;const u=we(c.count);for(let l=0;l<u;l+=1)D.$insertTableColumnAtSelection(c.direction!=="before")})},deleteTableRow:c=>{e.update(()=>{const u=we(c.count);for(let l=0;l<u;l+=1){if(!Ce())return;D.$deleteTableRowAtSelection()}})},deleteTableColumn:c=>{e.update(()=>{const u=we(c.count);for(let l=0;l<u;l+=1){if(!Ce())return;D.$deleteTableColumnAtSelection()}})},deleteTable:()=>{e.update(()=>{const c=d.$getSelection();if(!d.$isRangeSelection(c)&&!D.$isTableSelection(c))return;const u=D.$findTableNode(c.anchor.getNode());if(!u)return;const l=d.$createParagraphNode();u.insertAfter(l),u.remove(),l.selectStart()})}}),Or=e=>{const t=Dr(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()}}},Hr={"format.bold":"bold","format.italic":"italic","format.underline":"underline","format.strike":"strikethrough","format.inlineCode":"code","format.superscript":"superscript","format.subscript":"subscript"},Fr={"list.ordered":V.INSERT_ORDERED_LIST_COMMAND,"list.unordered":V.INSERT_UNORDERED_LIST_COMMAND,"list.todo":V.INSERT_CHECK_LIST_COMMAND},zr={"indent.increase":d.INDENT_CONTENT_COMMAND,"indent.decrease":d.OUTDENT_CONTENT_COMMAND,"history.undo":d.UNDO_COMMAND,"history.redo":d.REDO_COMMAND},Wr={"format.color":"color","format.backgroundColor":"background-color","format.fontSize":"font-size","format.fontFamily":"font-family","format.lineHeight":"line-height"},Vr=({container:e,lexicalEditor:t,options:n,isDestroyed:r,isReadonly:o,reportError:a})=>{const s=Nr({container:e,lexicalEditor:t,options:n,isDestroyed:r}),c=Rr(t),u=Ir(t),l=Pr(t),p=$r(t),w=Ar(t),C=Or(t),N=()=>{var x,m;if(document.fullscreenElement){(x=document.exitFullscreen)==null||x.call(document).catch(f=>{a(n,"fullscreen.exit","Exit fullscreen failed.",f)});return}(m=e.requestFullscreen)==null||m.call(e).catch(f=>{a(n,"fullscreen.enter","Enter fullscreen failed.",f)})},b=(v=>{if(r()||o())return;const x=Hr[v.type];if(x){t.dispatchCommand(d.FORMAT_TEXT_COMMAND,x);return}const m=Fr[v.type];if(m){t.dispatchCommand(m,void 0);return}const f=zr[v.type];if(f){t.dispatchCommand(f,void 0);return}const k=Wr[v.type];if(k&&"value"in v){w.setSelectionStyle(k,v.value);return}switch(v.type){case"format.clear":w.clearSelectionFormat();return;case"block.heading":c.setBlockHeading(v.level);return;case"block.paragraph":c.setParagraphBlock();return;case"block.quote":c.setQuoteBlock();return;case"block.divider":c.insertDividerBlock();return;case"block.code":c.insertCodeBlock(v.language);return;case"block.setCodeLanguage":c.setSelectedCodeBlockLanguage(v.language);return;case"align":c.formatAlign(v.value);return;case"link.set":u.setLink(v.href,v.text);return;case"link.unset":u.unsetLink();return;case"link.open":u.openSelectedLink();return;case"mention.insert":p.insertMention(v.item);return;case"content.clear":c.clearContent();return;case"table.insert":C.insertTable(v);return;case"table.insertRow":C.insertTableRow(v);return;case"table.insertColumn":C.insertTableColumn(v);return;case"table.deleteRow":C.deleteTableRow(v);return;case"table.deleteColumn":C.deleteTableColumn(v);return;case"table.delete":C.deleteTable();return;case"media.insertImage":l.insertImage(v);return;case"media.insertVideo":l.insertVideo(v);return;case"media.pickImage":s.pickMediaFile("image");return;case"media.pickVideo":s.pickMediaFile("video");return;case"media.retry":s.retryMedia(v.assetId);return;case"media.remove":s.removeMedia(v.assetId);return;case"media.resize":l.resizeMedia(v);return;case"media.align":l.alignMedia(v);return;case"media.resetSize":l.resetMediaSize(v.assetId);return;case"fullscreen.toggle":N();return}});return b.uploadMediaFile=s.uploadMediaFile,b.destroy=()=>{s.destroy()},b},qr=300,Ur="BridgeRTE",vt=({editor:e,overflowLength:t})=>{if(t<=0)return!1;const n=d.$getSelection();if(d.$isRangeSelection(n))return G.$trimTextContentFromAnchor(e,n.anchor,t),!0;d.$getRoot().selectEnd();const r=d.$getSelection();return d.$isRangeSelection(r)?(G.$trimTextContentFromAnchor(e,r.anchor,t),!0):!1},jr=({lexicalEditor:e,options:t,isDestroyed:n,setContent:r,syncPlaceholder:o})=>{let a=0,s=null;const c=()=>{s&&(clearTimeout(s),s=null)},u=m=>{if(n())return;const f=Xt(e.getEditorState(),e);r(f),m&&hr(t,f)},l=m=>{const f=t.maxLength!==void 0&&t.maxLength>=0?t.maxLength:void 0;return{dirty:!0,plainTextLength:m,version:Y.BRIDGERTE_CONTENT_VERSION,maxLength:f,isOverMaxLength:f===void 0?!1:m>f}},p=m=>{pr(t,l(m))},w=()=>{t.onChange&&(c(),s=setTimeout(()=>{u(!0)},Le.BRIDGE_CONTENT_CHANGE_DEBOUNCE_MS))},C=m=>{if(a>0){a-=1;return}p(m),w()},N=()=>e.getEditorState().read(()=>d.$getRoot().getTextContent().length),b=m=>t.maxLength===void 0||t.maxLength<0?0:m-t.maxLength,v=m=>m<=0?!1:(e.update(()=>{vt({editor:e,overflowLength:m})},{discrete:!0}),!0);return{clearContentChangeTimer:c,enforceCurrentMaxLength:()=>{t.maxLength===void 0||t.maxLength<0||e.update(()=>{const m=d.$getRoot().getTextContent().length-(t.maxLength??0);vt({editor:e,overflowLength:m})},{discrete:!0})},syncContent:u,suppressNextChange(){a+=1},syncAfterEditorUpdate(){const m=N();if(v(b(m))){o();return}o(),C(m)}}},Ie="data-language",nn="纯文本",Kr="language",Gr=new Set(["plain","plaintext","text","txt"]),Yr=new Set(U.getCodeLanguageOptions().map(([e])=>e)),Xr=[Ie,"data-lang","data-code-language","data-highlight-language","lang","language"],Jr=/^[a-z][a-z0-9_+#.-]{0,31}$/i,Qr=/^(?:language|lang)-([a-z][a-z0-9_+#.-]{0,31})$/i,Zr=/^brush:\s*([a-z][a-z0-9_+#.-]{0,31})$/i,eo=new Map([["dockerfile","docker"],["shell","shellscript"],["sh","shellscript"],["bash","shellscript"],["js","javascript"],["jsx","jsx"],["py","python"],["rb","ruby"],["rs","rust"],["ts","typescript"],["tsx","tsx"],["yml","yaml"]]),to=e=>e.type==="select",wt=e=>e.find(t=>t.name===Kr&&to(t)),ne=e=>{const t=e==null?void 0:e.trim().toLowerCase();if(!t||!Jr.test(t))return null;if(Gr.has(t))return"";const n=eo.get(t)??U.normalizeCodeLanguage(t);return Yr.has(n)?n:null},no=e=>{for(const t of Xr){const n=ne(e.getAttribute(t));if(n)return n}return null},ro=e=>{const[,t]=e.match(Zr)??[],n=ne(t);if(n)return n;for(const r of e.split(/\s+/)){const[,o]=r.match(Qr)??[],a=ne(o);if(a)return a}return null},rn=(e=z.codeBlockLanguagePanel)=>{var t,n;return((t=wt(e.fields))==null?void 0:t.options)??((n=wt(z.codeBlockLanguagePanel.fields))==null?void 0:n.options)??[{label:nn,value:""}]},on=(e,t)=>{var n,r,o;return((n=e.find(a=>a.value===t))==null?void 0:n.label)??((r=e.find(a=>ne(a.value)===ne(t)))==null?void 0:r.label)??((o=e[0])==null?void 0:o.label)??nn};rn();const oo=e=>{[...e.querySelectorAll("pre,code")].forEach(t=>{const n=no(t)??ro(t.className),r=t.tagName==="PRE"?t:t.closest("pre");r&&n&&r.setAttribute(Ie,n)})},ao=e=>{e.querySelectorAll("pre").forEach(t=>{[...t.children].forEach(r=>{r.tagName==="CODE"&&r.replaceWith(...r.childNodes)})})},so=(e,t)=>{const n=[...t.querySelectorAll("pre[data-language]")];let r=0;e.forEach(o=>{if(!O.$isCodeNode(o))return;const a=n[r];if(r+=1,!a)return;const s=a.getAttribute(Ie);s&&!o.getLanguage()&&o.setLanguage(s)})},an="one-light",J={keyword:"#a626a4",function:"#4078f2",operator:"#0184bc",tag:"#c18401",property:"#e45649",string:"#50a14f",attrName:"#986801"},io={[J.keyword]:"keyword",[J.function]:"function",[J.operator]:"operator",[J.tag]:"tag",[J.property]:"property",[J.string]:"string",[J.attrName]:"attr-name"},lo=e=>{const[,t]=e.match(/(?:^|;)color:\s*(#[0-9a-f]{3,8})/i)??[];return t?io[t.toLowerCase()]:void 0},co={...U.ShikiTokenizer,defaultLanguage:null,defaultTheme:an,$tokenize(e,t){const n=U.ShikiTokenizer.$tokenize.call(this,e,t);return e.getStyle()&&e.setStyle(""),n.map(r=>O.$isCodeHighlightNode(r)?O.$createCodeHighlightNode(r.getTextContent(),lo(r.getStyle())):r)}},uo=1200,fe=new Set,Te=new Set,qe=new Set,Ne=[];let Q=0,se=null,_e=!1,Ee=null,Ct=!1;const go=e=>"requestIdleCallback"in window?{id:window.requestIdleCallback(e,{timeout:uo}),kind:"idle"}:{id:globalThis.setTimeout(()=>{e({didTimeout:!0,timeRemaining:()=>0})},0),kind:"timeout"},mo=e=>{if(e.kind==="idle"){window.cancelIdleCallback(e.id);return}globalThis.clearTimeout(e.id)},ho=e=>e.map(t=>t.value).filter(t=>t!==""),po=e=>{ho(e).forEach(t=>{if(fe.has(t)||Te.has(t)||qe.has(t)||U.isCodeLanguageLoaded(t)){fe.add(t);return}qe.add(t),Ne.push(t)})},fo=()=>{for(;Ne.length>0;){const e=Ne.shift();if(e&&(qe.delete(e),!(fe.has(e)||Te.has(e)))){if(U.isCodeLanguageLoaded(e)){fe.add(e);continue}return e}}},bo=async()=>{if(!Ct){if(!Ee){const e=U.loadCodeTheme(an);Ee=Promise.resolve(e??void 0).then(()=>{Ct=!0}).catch(()=>{}).finally(()=>{Ee=null})}await Ee}},yo=e=>{Q+=1,po(e);const t=async()=>{if(!(Q<=0||_e)){_e=!0;try{if(await bo(),Q<=0)return;const r=fo();if(!r)return;Te.add(r),await Promise.resolve(U.loadCodeLanguage(r)??void 0).then(()=>{fe.add(r)}).catch(()=>{}).finally(()=>{Te.delete(r)})}finally{_e=!1,n()}}},n=()=>{Q<=0||se!==null||_e||Ne.length===0||(se=go(()=>{se=null,t()}))};return n(),()=>{Q=Math.max(0,Q-1),Q===0&&se!==null&&(mo(se),se=null)}},ie=12,_t=6,Et=(e,t,n)=>Math.min(Math.max(e,t),Math.max(t,n)),vo=()=>{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}},wo=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},Co=(e,t,n)=>{const r=wo(e),o=vo(),a=t.getBoundingClientRect(),s=a.left+ie,c=a.top+ie,u=n?n.x:s,l=n?n.y+n.height+_t:c,p=n?n.y-r.height-_t:l,w=o.left+ie,C=o.top+ie,N=o.left+o.width-r.width-ie,b=o.top+o.height-r.height-ie,v=l>b?p:l;return{left:Et(u,w,N),top:Et(v,C,b),viewportHeight:o.height}},sn=e=>{var u,l;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 p=Co(n,e.root,o);n.style.left=`${p.left}px`,n.style.top=`${p.top}px`,n.style.setProperty("--bridgerte-dialog-visible-height",`${p.viewportHeight}px`)},c=p=>{o=p,p?n.style.setProperty("--bridgerte-dialog-anchor-width",`${p.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 p;(p=e.onBackdropClick)==null||p.call(e),a()}),(u=window.visualViewport)==null||u.addEventListener("resize",s),(l=window.visualViewport)==null||l.addEventListener("scroll",s),window.addEventListener("resize",s),{element:n,content:r,open:c,close:a,destroy(){var p,w;a(),(p=window.visualViewport)==null||p.removeEventListener("resize",s),(w=window.visualViewport)==null||w.removeEventListener("scroll",s),window.removeEventListener("resize",s),t.remove(),n.remove()}}},Se=e=>typeof requestAnimationFrame=="function"?requestAnimationFrame(e):window.setTimeout(e,0),et=e=>{if(typeof cancelAnimationFrame=="function"){cancelAnimationFrame(e);return}window.clearTimeout(e)},W=(e,t={})=>{let n=null;const r=s=>{const c=n??e;if(!(!s&&!n)){if(s){c.dataset.pressed="true";return}delete c.dataset.pressed,n=null}},o=s=>{if(s.pointerType==="mouse")return;const c=s.target;n=c instanceof HTMLElement&&t.targetSelector?c.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)}},_o=(e,t,n)=>{e.update(t,{tag:d.SKIP_SCROLL_INTO_VIEW_TAG,onUpdate:n})},kt="language",Eo="bridgerte-code-block-language",Mt=8;let xt=0;const ko=()=>(xt+=1,`${Eo}-${xt}`),Mo=(e,t,n)=>{const r=e.querySelector(".bridgerte__code-block-control-label");e.dataset.language=n??"",r&&(r.textContent=on(t,n))},xo=(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=on(e,t),o.className="bridgerte__code-block-control-arrow",n.append(r,o),n},To=e=>{const t=document.createElement("div"),n=e.root.querySelector(".bridgerte__content")??e.root,r=jt.resolvePayloadPanelSchema(e.languagePanel??z.codeBlockLanguagePanel,e.payloadPanelConfig),o=rn(r);let a=null,s=null,c=null;const u=new Map,l=new Map,p=()=>{c??(c=yo(o))},w=()=>{a==null||a.close()},C=(i,g)=>{e.isReadonly()||_o(e.editor,()=>{const h=d.$getNodeByKey(i);O.$isCodeNode(h)&&h.setLanguage(g)})},N=(i,g)=>{Se(()=>{C(i,g)})},b=(i,g,h)=>{var y;return((y=e.onRequest)==null?void 0:y.call(e,{id:ko(),readonly:e.isReadonly(),menuId:"code-block-language",command:{type:"block.setCodeLanguage",language:h},panel:r,anchorRect:{x:g.left,y:g.top,width:g.width,height:g.height},currentValues:{[kt]:h},submit:T=>{w(),N(i,T[kt]??"")},cancel:w}))===!0},v=(i,g)=>{const h=e.root.getBoundingClientRect(),y=g.getBoundingClientRect(),T=y.bottom<h.top||y.top>h.bottom;i.hidden=T,i.style.transform=`translate(${y.left-h.left+Mt}px, ${y.top-h.top+Mt}px)`},x=i=>{var $;const g=e.editor.getElementByKey(i);if(!g){($=u.get(i))==null||$.remove(),u.delete(i);return}p(),g.dataset.lexicalKey=i;const h=g.getAttribute("data-language"),y=u.get(i);if(y){Mo(y,o,h),v(y,g);return}const T=xo(o,h),R=W(T);T.dataset.lexicalKey=i,u.set(i,T),l.set(T,R),t.append(T),v(T,g)},m=()=>{s=null,u.forEach((i,g)=>{x(g)})},f=()=>{s===null&&(s=Se(m))},k=(i,g)=>{const h=i.getBoundingClientRect(),y=i.dataset.language??"";if(b(g,h,y))return;if(e.isReadonly()){w();return}a||(a=sn({root:e.root,className:"bridgerte__code-block-menu",onBackdropClick:w}));const T=document.createElement("div");a.content.replaceChildren(),a.element.style.minWidth="180px",T.className="bridgerte__code-block-menu-list",o.forEach(R=>{const $=document.createElement("button");$.type="button",$.className="bridgerte__menu-item bridgerte__code-block-menu-item",$.textContent=R.label,W($),$.addEventListener("pointerdown",B=>{B.preventDefault()}),$.addEventListener("click",()=>{w(),N(g,R.value)}),T.append($)}),a.content.append(T),a.open({x:h.left,y:h.top,width:180,height:h.height})};t.className="bridgerte__code-block-controls-layer",e.root.append(t);const E=e.editor.registerMutationListener(O.CodeNode,i=>{i.forEach((g,h)=>{if(g==="destroyed"){const y=u.get(h);if(y){const T=l.get(y);T==null||T(),l.delete(y),y.remove()}u.delete(h);return}x(h)})}),I=e.editor.registerUpdateListener(f),P=i=>{const g=i.target;if(!(g instanceof HTMLElement))return;const h=g.closest(".bridgerte__code-block-control");if(!(h instanceof HTMLElement))return;const y=h.dataset.lexicalKey;y&&(i.preventDefault(),i.stopPropagation(),k(h,y))},S=i=>{const g=i.target;g instanceof HTMLElement&&g.closest(".bridgerte__code-block-control")&&i.preventDefault()},_=i=>{const g=i.target;if(!(g instanceof HTMLElement))return;if(!g.closest(".bridgerte__code-block")){w();return}const h=g.closest(".bridgerte__code-block");if(!h||h.textContent)return;const y=h.dataset.lexicalKey;y&&(e.editor.update(()=>{const T=d.$getNodeByKey(y);O.$isCodeNode(T)&&T.selectEnd()}),e.editor.focus())};return t.addEventListener("pointerdown",S),t.addEventListener("click",P),n.addEventListener("pointerdown",_),n.addEventListener("scroll",f,{passive:!0}),window.addEventListener("resize",f),{destroy(){E(),I(),c==null||c(),c=null,s!==null&&(et(s),s=null),t.removeEventListener("pointerdown",S),t.removeEventListener("click",P),n.removeEventListener("pointerdown",_),n.removeEventListener("scroll",f),window.removeEventListener("resize",f),u.forEach(i=>{var g;(g=l.get(i))==null||g(),i.remove()}),u.clear(),l.clear(),t.remove(),a==null||a.destroy(),a=null}}},ln=e=>{const t=o=>{const a=e.getBlockFromTarget(o.target);if(a){e.activateBlock(a);return}e.clearBlock()},n=o=>{const a=e.getBlockFromTarget(o.target);a&&e.activateBlock(a)},r=o=>{const a=o.target;a instanceof Node&&e.root.contains(a)||e.clearBlock()};return e.content.addEventListener("pointerdown",t),e.content.addEventListener("focusin",n),document.addEventListener("pointerdown",r),{destroy(){e.content.removeEventListener("pointerdown",t),e.content.removeEventListener("focusin",n),document.removeEventListener("pointerdown",r)}}},Pe=(e,t={})=>e.map(n=>{var a;const r=(a=t.menuLabels)==null?void 0:a[n.id],o=n.payloadPanel?jt.resolvePayloadPanelSchema(n.payloadPanel,t.payloadPanelConfig):void 0;return{...n,...r===void 0?{}:{label:r},...o===void 0?{}:{payloadPanel:o}}}),cn=(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)}},dn=(e,t)=>{const n=t.find(o=>z.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}},be=["media-resize-20","media-resize-50","media-resize-100"],No=["media-align-left","media-align-center","media-align-right","|",...be,"|","media-remove"],So=["media-retry","|","media-remove"],Lo=[{id:"media-align-left",command:{type:"media.align",assetId:"",value:"left"},label:"左",icon:"align-left"},{id:"media-align-center",command:{type:"media.align",assetId:"",value:"center"},label:"中",icon:"align-center"},{id:"media-align-right",command:{type:"media.align",assetId:"",value:"right"},label:"右",icon:"align-right"},{id:"media-resize-20",command:{type:"media.resize",assetId:"",widthPercent:20},label:"20%",icon:"media-resize-20"},{id:"media-resize-50",command:{type:"media.resize",assetId:"",widthPercent:50},label:"50%",icon:"media-resize-50"},{id:"media-resize-100",command:{type:"media.resize",assetId:"",widthPercent:100},label:"100%",icon:"media-resize-100"},{id:"media-retry",command:{type:"media.retry",assetId:""},label:"重试",icon:"refresh-cw"},{id:"media-remove",command:{type:"media.remove",assetId:""},label:"删除",icon:"trash-2"}],un=e=>be.includes(e),Ro=e=>typeof e=="object"&&Array.isArray(e.menuKeys),Io=e=>new Set(e.flatMap(t=>t==="|"?[]:typeof t=="string"?[t]:Ro(t)?[t.key,...t.menuKeys]:[])),De=e=>typeof e=="string"&&un(e),Po=e=>{const t=e.findIndex(r=>r==="media-remove"),n=t===-1?e.length:t;return[...e.slice(0,n),"|",...be,"|",...e.slice(n)]},$o=e=>{const t=Io(e);if(be.filter(o=>!t.has(o)).length===0)return e;const r=e.findIndex(De);return r===-1?Po(e):[...e.slice(0,r).filter(o=>!De(o)),...be,...e.slice(r+1).filter(o=>!De(o))]},Ao=e=>{var r;const t=(e==null?void 0:e.toolbarKeys)??No;return{...e,toolbarKeys:$o(t),excludeKeys:(r=e==null?void 0:e.excludeKeys)==null?void 0:r.filter(o=>!un(o))}},Bo=(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}},Do=(e,t,n)=>e.command.type==="media.resize"?e.command.widthPercent===t:e.command.type==="media.align"&&e.command.value===n,gn=(e,t={})=>{const n=Pe(Lo,{menuLabels:t.menuLabels}),r=e==="error"?{toolbarKeys:So}:Ao(t.config);return z.resolveToolbarMenu(r,n)},le=8,ue="bridgerte__media-controls-button",Oo=e=>e.querySelector(".bridgerte__content")??e,Ho=e=>e instanceof Element?e.closest(".bridgerte__media"):null,Fo=(e,t=!1)=>{const n=document.createElement("button");return n.type="button",n.className=ue,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},mn=e=>e.flatMap(t=>t.type==="button"?[t.item]:t.type==="group"?t.items:[]),zo=(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(Fo(a,Do(a,n,r)))})},Wo=(e,t,n)=>{const r=document.createElement("div"),o=e.dataset.status,a=Number(e.dataset.displayWidthPercent??t),s=e.dataset.align??"left",c=gn(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=mn(c).map(u=>u.id).join("|"),c.forEach(u=>{zo(r,u,a,s)}),r},Vo=e=>{const t=document.createElement("div"),n=Oo(e.root),r=new Map,o=new Map,a=new Map;let s=null,c=null,u=!1,l=null;const p=i=>{var h;const g=r.get(i);g&&((h=o.get(g))==null||h(),o.delete(g),g.remove(),r.delete(i),l===i&&(l=null))},w=(i,g)=>g.dataset.status==="error"||l===i,C=(i,g)=>{const h=e.root.getBoundingClientRect(),y=g.getBoundingClientRect(),T=y.bottom<h.top||y.top>h.bottom,R=Math.max(le,h.width-i.offsetWidth-le),$=Math.min(Math.max(y.left-h.left+le,le),R),B=Math.max(le,y.top-h.top-i.offsetHeight-le);i.hidden=T,i.style.transform=`translate(${$}px, ${B}px)`},N=i=>{const g=e.editor.getElementByKey(i);if(!g){p(i);return}g.dataset.lexicalKey=i,a.set(g,i);const h=r.get(i);if(!w(i,g)){p(i);return}if(h){const R=g.dataset.status==="error",$=h.querySelector('[data-action="retry"]')!==null,B=g.dataset.displayWidthPercent??"",q=g.dataset.align??"";if(R===$&&h.dataset.displayWidthPercent===B&&h.dataset.align===q){C(h,g);return}p(i)}const y=Wo(g,e.defaultWidthPercent,e),T=W(y,{targetSelector:`.${ue}`});y.dataset.lexicalKey=i,y.dataset.assetId=g.dataset.assetId,r.set(i,y),o.set(y,T),t.append(y),C(y,g)},b=()=>{s=null,a.forEach((i,g)=>{e.root.contains(g)||(a.delete(g),p(i))}),e.root.querySelectorAll(".bridgerte__media").forEach(i=>{const g=i.dataset.lexicalKey;g&&(a.set(i,g),N(g))}),r.forEach((i,g)=>{N(g)}),l!==null&&N(l)},v=()=>{s===null&&(s=Se(b))},x=(i,g)=>{const h=g.dataset.assetId,y=mn(gn(g.dataset.status,{config:e.mediaControlsConfig,menuLabels:e.menuLabels})).find(R=>R.id===i.dataset.menuItemId);if(!h||!y)return;const T=Bo(y,h);T&&e.executeCommand(T)},m=i=>{if(!i){const y=l;l=null,y!==null&&N(y);return}const g=i.dataset.lexicalKey?i.dataset.lexicalKey:a.get(i)??null;if(!g||l===g)return;const h=l;l=g,h!==null&&N(h),N(g)},f=i=>{const g=i.target;if(!(g instanceof HTMLElement))return;const h=g.closest(`.${ue}`);h&&(i.preventDefault(),c=i.pointerType==="mouse"?null:h)},k=i=>{if(i.pointerType==="mouse"||!c)return;const g=i.target,h=g instanceof HTMLElement?g.closest(".bridgerte__media-controls"):null,y=g instanceof HTMLElement?g.closest(`.${ue}`):null;y===c&&h&&(i.preventDefault(),i.stopPropagation(),x(y,h),u=!0),c=null},E=()=>{c=null},I=i=>{if(u){u=!1,i.preventDefault(),i.stopPropagation();return}const g=i.target;if(!(g instanceof HTMLElement))return;const h=g.closest(`.${ue}`),y=g.closest(".bridgerte__media-controls");!h||!y||(i.preventDefault(),i.stopPropagation(),x(h,y))},P=e.editor.registerMutationListener(ce,i=>{i.forEach((g,h)=>{if(g==="destroyed"){p(h);return}N(h)})}),S=e.editor.registerUpdateListener(v),_=ln({root:e.root,content:n,getBlockFromTarget:Ho,activateBlock:m,clearBlock:()=>m(null)});return t.className="bridgerte__media-controls-layer",e.root.append(t),t.addEventListener("pointerdown",f),t.addEventListener("pointerup",k),t.addEventListener("pointercancel",E),t.addEventListener("click",I),n.addEventListener("scroll",v,{passive:!0}),window.addEventListener("resize",v),{destroy(){P(),S(),s!==null&&(et(s),s=null),t.removeEventListener("pointerdown",f),t.removeEventListener("pointerup",k),t.removeEventListener("pointercancel",E),t.removeEventListener("click",I),_.destroy(),n.removeEventListener("scroll",v),window.removeEventListener("resize",v),r.forEach(i=>{var g;(g=o.get(i))==null||g(),i.remove()}),r.clear(),o.clear(),a.clear(),t.remove()}}},qo=["width","height"],K=(e,t)=>{var r;const n=(r=e[t])==null?void 0:r.trim();return n||void 0},Ue=(e,t)=>{const n=Number.parseInt(e[t]??"",10);return Number.isFinite(n)&&n>0?n:void 0},Tt=(e,t)=>qo.reduce((n,r)=>{const o=Ue(t,r);return o===void 0?n:{...n,[r]:o}},e),Uo=(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=K(t,"href"),r=K(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=Ue(t,"rows"),r=Ue(t,"cols");return n&&r?{type:"table.insert",rows:n,cols:r}:null}if(e.type==="media.insertImage"){const n=K(t,"url");return n?Tt({...e,url:n,alt:K(t,"alt"),title:K(t,"title")},t):null}if(e.type==="media.insertVideo"){const n=K(t,"url");return n?Tt({...e,url:n,poster:K(t,"poster"),title:K(t,"title")},t):null}return e},Z=e=>Math.min(Math.max(Math.round(e),0),255),je=({r:e,g:t,b:n})=>`#${[e,t,n].map(r=>Z(r).toString(16).padStart(2,"0")).join("")}`,hn=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)}},jo=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:Z(Number(t[1])),g:Z(Number(t[2])),b:Z(Number(t[3]))}:null},Oe=e=>{const t=hn(e)??jo(e);return t?je(t):null},pn=e=>Math.min(Math.max(e,0),1),Ko=({r:e,g:t,b:n})=>{const r=Z(e)/255,o=Z(t)/255,a=Z(n)/255,s=Math.max(r,o,a),c=Math.min(r,o,a),u=s-c;let l=0;return u!==0&&(s===r?l=60*((o-a)/u%6):s===o?l=60*((a-r)/u+2):l=60*((r-o)/u+4)),{h:l<0?l+360:l,s:s===0?0:u/s,v:s}},Nt=({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,c=0,u=0;return e<60?(s=r,c=o):e<120?(s=o,c=r):e<180?(c=r,u=o):e<240?(c=o,u=r):e<300?(s=o,u=r):(s=r,u=o),{r:(s+a)*255,g:(c+a)*255,b:(u+a)*255}},Go=({h:e,s:t})=>{const n=e*Math.PI/180,r=pn(t)*50;return{x:50+Math.cos(n)*r,y:50+Math.sin(n)*r}},St=(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,c=Math.min(Math.sqrt(a*a+s*s),n.width/2),u=Math.atan2(s,a)*180/Math.PI;return{h:u<0?u+360:u,s:pn(c/(n.width/2)),v:1}},Yo=["#000000","#ffffff"],Xo=e=>{var t;return(t=e.options)!=null&&t.length?e.options:Yo.map(n=>({label:n,value:n}))},fn=()=>{const e=document.createElement("section");return e.className="bridgerte__payload-panel-field",e},Jo=(e,t,n)=>{const r=fn(),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",W(s),s.addEventListener("pointerdown",c=>{c.preventDefault()}),s.addEventListener("click",()=>{n({...t,[e.name]:a.value})}),o.append(s)}),r.append(o),r},Qo=(e,t,n)=>{const r=fn(),o=document.createElement("div"),a=document.createElement("div"),s=document.createElement("span"),c=document.createElement("div"),u=document.createElement("div"),l=Xo(e),p=l.length===2;let w={h:0,s:0,v:1},C=null;const N=m=>{const f=Oe(m);return!!(f&&l.some(k=>Oe(k.value)===f))},b=(m,f=!0)=>{const k=Oe(m);if(!k)return;t[e.name]=k,u.style.background=k,w=Ko(hn(k)??{r:255,g:255,b:255});const E=Go(w);a.dataset.active=f?"true":"false",u.dataset.empty="false",f&&(s.style.left=`${E.x}%`,s.style.top=`${E.y}%`)},v=()=>{const m=t[e.name];m&&n({...t,[e.name]:m})};r.className="bridgerte__payload-panel-field",o.className="bridgerte__payload-panel-color-picker",a.className="bridgerte__payload-panel-color-wheel",a.setAttribute("aria-label",`${e.label}选择区域`),s.className="bridgerte__payload-panel-color-wheel-handle",c.className="bridgerte__payload-panel-color-actions",c.dataset.layout=p?"sides":"grid",u.className="bridgerte__payload-panel-color-preview",u.dataset.empty="true",a.append(s),l.forEach(m=>{const f=document.createElement("button"),k=m.value;f.type="button",f.className="bridgerte__payload-panel-color-swatch",f.dataset.value=k,f.style.background=k,f.setAttribute("aria-label",`选择颜色 ${m.label}`),W(f),f.addEventListener("pointerdown",E=>{E.preventDefault()}),f.addEventListener("click",()=>{b(k,!1),v()}),c.append(f)}),a.addEventListener("pointerdown",m=>{C=m.pointerId,a.setPointerCapture(m.pointerId),w=St(m,a),b(je(Nt(w))),m.preventDefault()}),a.addEventListener("pointermove",m=>{C===m.pointerId&&(w=St(m,a),b(je(Nt(w))))}),a.addEventListener("pointerup",m=>{C===m.pointerId&&(C=null,a.releasePointerCapture(m.pointerId),v())}),a.addEventListener("pointercancel",m=>{C===m.pointerId&&(C=null,a.releasePointerCapture(m.pointerId))});const x=t[e.name];return x&&b(x,!(p&&N(x))),o.append(a,c),r.append(o,u),r},Zo=(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},ea=(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},ta=({field:e,values:t,onSubmit:n})=>e.type==="color"?Qo(e,t,n):e.type==="text"?Zo(e,t,n):e.type==="number"?ea(e,t,n):Jo(e,t,n),na=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)??""},ra=(e,t)=>(t==null?void 0:t[e.name])??(e.type==="color"?"":na(e)),Lt=e=>e.some(t=>t.type==="text"||t.type==="number"),oa=e=>{const t=e.querySelector(".bridgerte__payload-panel-text-input");queueMicrotask(()=>{t==null||t.focus(),t==null||t.select()})},aa=(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}`),W(s),s.addEventListener("pointerdown",c=>{c.preventDefault()}),s.addEventListener("click",()=>{t(a)}),r.append(s)}return r},sa=e=>e==="font-size"||e==="font-family"||e==="line-height"?"180px":"220px",ia=3,la=3,ca=10,bn=10,da=16,ua=2,ga=24,ma=()=>{var e;return typeof window<"u"&&((e=window.matchMedia)==null?void 0:e.call(window,"(hover: hover) and (pointer: fine)").matches)===!0},ge=(e,t)=>{const n=Number.parseInt(e??"",10);return Number.isFinite(n)?Math.min(Math.max(n,t.min),t.max):t.defaultValue},ha=(e,t)=>e.type==="number"&&e.name===t,Rt=(e,t)=>typeof e=="number"&&Number.isFinite(e)&&e>0?Math.floor(e):t,It=(e,t,n,r)=>{const o=e.find(p=>ha(p,t)),a=Rt(o==null?void 0:o.min,1),s=Rt(o==null?void 0:o.max,n),c=Math.max(a,s),u=Math.min(Math.max(r,a),c),l=ge(o==null?void 0:o.defaultValue,{min:a,max:c,defaultValue:u});return{min:a,max:c,defaultValue:l}},yn=e=>({rows:It(e,"rows",Y.BRIDGERTE_TABLE_INSERT_MAX_ROWS,ia),cols:It(e,"cols",Y.BRIDGERTE_TABLE_INSERT_MAX_COLS,la)}),pa=e=>{const t=Math.min(e.cols.max,bn);return`${t*da+Math.max(t-1,0)*ua+ga}px`},fa=({fields:e,values:t,onSubmit:n})=>{const r=yn(e),o=document.createElement("section"),a=document.createElement("div"),s=document.createElement("div"),c=[],u=ma(),l=Math.min(r.rows.max,ca),p=Math.min(r.cols.max,bn),w={...r.rows,max:l,defaultValue:Math.min(r.rows.defaultValue,l)},C={...r.cols,max:p,defaultValue:Math.min(r.cols.defaultValue,p)};let N=ge(t.rows,w),b=ge(t.cols,C),v=null;const x=(S,_)=>{N=S,b=_,t.rows=String(S),t.cols=String(_),s.textContent=`${S} x ${_}`,c.forEach(i=>{const g=Number.parseInt(i.dataset.rows??"0",10),h=Number.parseInt(i.dataset.cols??"0",10);i.dataset.active=String(g<=S&&h<=_)})},m=S=>{var _;return((_=document.elementFromPoint(S.clientX,S.clientY))==null?void 0:_.closest(".bridgerte__payload-panel-table-cell"))??null},f=S=>{if(!S)return;const _=ge(S.dataset.rows,w),i=ge(S.dataset.cols,C);x(_,i)},k=()=>{n({...t,rows:String(N),cols:String(b)})},E=()=>{v=null},I=()=>{window.setTimeout(E,0)},P=(S,_)=>{if(S.detail>0&&v!==_){S.preventDefault(),S.stopPropagation();return}E(),f(_),k()};for(let S=1;S<=l;S+=1)for(let _=1;_<=p;_+=1){const i=document.createElement("button");i.type="button",i.className="bridgerte__payload-panel-table-cell",i.dataset.rows=String(S),i.dataset.cols=String(_),i.setAttribute("aria-label",`插入 ${S} 行 ${_} 列表格`),W(i),i.addEventListener("pointerdown",g=>{v=i,f(i),g.preventDefault()}),i.addEventListener("pointerup",I),i.addEventListener("pointercancel",E),i.addEventListener("click",g=>{P(g,i)}),u&&i.addEventListener("pointerenter",()=>{f(i)}),c.push(i),a.append(i)}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(p)),s.className="bridgerte__payload-panel-table-status",s.setAttribute("aria-live","polite"),a.addEventListener("pointermove",S=>{u||f(m(S))}),x(N,b),o.append(a,s),o},ba="bridgerte-payload-panel";let Pt=0;const ya=()=>(Pt+=1,`${ba}-${Pt}`),ke=e=>e.panel.id==="table-insert",va=(e,t)=>{const n=document.createElement("button");return n.type="button",n.className="bridgerte__payload-panel-submit",n.textContent="应用",W(n),n.addEventListener("pointerdown",r=>{r.preventDefault()}),n.addEventListener("click",()=>{t(e)}),n},wa=e=>{let t=null,n={};const r=sn({root:e.editorRoot,className:"bridgerte__payload-panel",onBackdropClick:()=>{o()}});function o(){t=null,n={},r.close(),r.content.replaceChildren()}const a=l=>{var w;if(!t||t.readonly||e.isReadonly())return;const p=Uo(t.command,l);p&&((w=e.restoreEditorFocus)==null||w.call(e,()=>{o(),e.isReadonly()||e.executeCommand(p)}))},s=l=>{var p;!t||t.readonly||e.isReadonly()||(p=e.restoreEditorFocus)==null||p.call(e,()=>{o(),e.isReadonly()||e.executeCommand(l)})},c=l=>{n=l.panel.fields.reduce((w,C)=>(w[C.name]=ra(C,l.currentValues),w),{});const p=ke(l)?pa(yn(l.panel.fields)):sa(l.panel.id);r.element.style.width=`min(${p}, calc(100vw - 24px))`,r.content.append(aa(l,s,e.getClearCommand)),ke(l)?r.content.append(fa({fields:l.panel.fields,values:n,onSubmit:a})):l.panel.fields.forEach(w=>{r.content.append(ta({field:w,values:n,onSubmit:a}))}),!ke(l)&&Lt(l.panel.fields)&&r.content.append(va(n,a)),r.open(l.anchorRect),!ke(l)&&Lt(l.panel.fields)&&oa(r.content)};return{open:l=>{var C;o();const p={...l,id:ya(),readonly:e.isReadonly(),submit:a,cancel:o};if(t=p,((C=e.onRequest)==null?void 0:C.call(e,p))!==!0){if(p.readonly){o();return}c(l)}},close:o,destroy(){o(),r.destroy()}}},me="bridgerte__table-controls-button",Ca=["table-insert-row-after","table-delete-row","table-insert-column-after","table-delete-column","table-delete"],_a=()=>{const e=new Map(z.defaultMenuSchema.map(t=>[t.id,t]));return Ca.map(t=>z.tableHeaderMenuItems.find(n=>n.id===t)??e.get(t)).filter(t=>t!==void 0)},vn=_a(),Ea=new Map(vn.map(e=>[e.id,e])),ka=e=>e.matches(".bridgerte__table")?e:e.querySelector(".bridgerte__table")??e,Ma=(e,t)=>e.classList.contains("bridgerte__table-wrapper")?e:t.parentElement instanceof HTMLElement?t.parentElement:t,xa=e=>e.querySelector(".bridgerte__content")??e,Ta=e=>e instanceof Element?e.closest(".bridgerte__table-wrapper"):null,Na=e=>{const t=e.getFirstChild();if(!D.$isTableRowNode(t))return null;const n=t.getFirstChild();return D.$isTableCellNode(n)?n:null},Sa=e=>{const t=document.createElement("button");return t.type="button",t.className=me,t.textContent=e.label,t.dataset.menuItemId=e.id,t.setAttribute("aria-label",e.label),t},La=()=>{const e=document.createElement("div");return e.className="bridgerte__table-controls",e.contentEditable="false",e.setAttribute("aria-label","表格操作"),vn.forEach(t=>{e.append(Sa(t))}),e},Ra=e=>{const t=document.createElement("div"),n=xa(e.root),r=new Map,o=new Map,a=new Map;let s=null,c=null,u=!1,l=null;const p=(h,y)=>{const T=e.root.getBoundingClientRect(),R=y.getBoundingClientRect(),$=R.bottom<T.top||R.top>T.bottom,B=Math.max(8,T.width-h.offsetWidth-8),q=Math.min(Math.max(R.left-T.left+8,8),B),L=Math.max(8,R.top-T.top-h.offsetHeight-8);h.hidden=$,h.style.transform=`translate(${q}px, ${L}px)`},w=h=>l===h,C=h=>{const y=e.editor.getElementByKey(h);if(!y){N(h);return}y.dataset.lexicalKey=h;const T=ka(y),R=Ma(y,T);a.set(R,h);const $=r.get(h);if(!w(h)){N(h);return}if($){p($,R);return}const B=La(),q=W(B,{targetSelector:`.${me}`});B.dataset.lexicalKey=h,r.set(h,B),o.set(B,q),t.append(B),p(B,R)},N=h=>{var T;const y=r.get(h);y&&((T=o.get(y))==null||T(),o.delete(y),y.remove(),r.delete(h),l===h&&(l=null))},b=()=>{s=null,a.forEach((h,y)=>{e.root.contains(y)||(a.delete(y),N(h))}),e.root.querySelectorAll(".bridgerte__table-wrapper").forEach(h=>{const y=h.dataset.lexicalKey;y&&(a.set(h,y),C(y))}),r.forEach((h,y)=>{C(y)}),l!==null&&C(l)},v=()=>{s===null&&(s=Se(b))},x=h=>{e.editor.update(()=>{var T;const y=d.$getNodeByKey(h);y instanceof D.TableNode&&((T=Na(y))==null||T.selectStart())}),e.editor.focus()},m=(h,y)=>{x(h),e.executeCommand(y)},f=(h,y)=>{const T=y.dataset.lexicalKey,R=h.dataset.menuItemId,$=R?Ea.get(R):void 0;!T||!$||m(T,$.command)},k=h=>{if(!h){const R=l;l=null,R!==null&&C(R);return}const y=h.dataset.lexicalKey?h.dataset.lexicalKey:a.get(h)??null;if(!y||l===y)return;const T=l;l=y,T!==null&&C(T),C(y)},E=h=>{const y=h.target;if(!(y instanceof HTMLElement))return;const T=y.closest(`.${me}`);T&&(h.preventDefault(),c=h.pointerType==="mouse"?null:T)},I=h=>{if(h.pointerType==="mouse"||!c)return;const y=h.target,T=y instanceof HTMLElement?y.closest(".bridgerte__table-controls"):null,R=y instanceof HTMLElement?y.closest(`.${me}`):null;R===c&&T&&(h.preventDefault(),h.stopPropagation(),f(R,T),u=!0),c=null},P=()=>{c=null},S=h=>{if(u){u=!1,h.preventDefault(),h.stopPropagation();return}const y=h.target;if(!(y instanceof HTMLElement))return;const T=y.closest(`.${me}`),R=y.closest(".bridgerte__table-controls");!T||!R||(h.preventDefault(),h.stopPropagation(),f(T,R))},_=e.editor.registerMutationListener(D.TableNode,h=>{h.forEach((y,T)=>{if(y==="destroyed"){N(T);return}C(T)})}),i=e.editor.registerUpdateListener(v),g=ln({root:e.root,content:n,getBlockFromTarget:Ta,activateBlock:k,clearBlock:()=>k(null)});return t.className="bridgerte__table-controls-layer",e.root.append(t),t.addEventListener("pointerdown",E),t.addEventListener("pointerup",I),t.addEventListener("pointercancel",P),t.addEventListener("click",S),n.addEventListener("scroll",v,{passive:!0}),window.addEventListener("resize",v),{destroy(){_(),i(),s!==null&&(et(s),s=null),t.removeEventListener("pointerdown",E),t.removeEventListener("pointerup",I),t.removeEventListener("pointercancel",P),t.removeEventListener("click",S),g.destroy(),n.removeEventListener("scroll",v),window.removeEventListener("resize",v),r.forEach(h=>{var y;(y=o.get(h))==null||y(),h.remove()}),r.clear(),o.clear(),a.clear(),t.remove()}}},Ia=e=>{const t=wa({editorRoot:e.editorRoot,isReadonly:e.isReadonly,restoreEditorFocus:e.restoreEditorFocus,executeCommand:e.executeCommand,getClearCommand:e.getClearCommand,onRequest:e.onRequest}),n=To({editor:e.lexicalEditor,root:e.editorRoot,isReadonly:e.isReadonly,languagePanel:e.codeBlockLanguagePanel,payloadPanelConfig:e.payloadPanelConfig,onRequest:e.onRequest}),r=Ra({editor:e.lexicalEditor,root:e.editorRoot,executeCommand:e.executeCommand}),o=Vo({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()}}},Pa=(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}},$a=({editor:e})=>{let t=null;return{capture(){e.getEditorState().read(()=>{var n;t=((n=d.$getSelection())==null?void 0:n.clone())??null})},restore(){t&&e.update(()=>{d.$setSelection((t==null?void 0:t.clone())??null)})},clear(){t=null}}},Aa=/((https?:\/\/|www\.)[^\s<>()]+[^\s<>().,;:!?])/i,Ba=/([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,})/i,Da={changeHandlers:[],excludeParents:[],matchers:[F.createLinkMatcherWithRegExp(Aa,e=>e.startsWith("http://")||e.startsWith("https://")?e:`https://${e}`),F.createLinkMatcherWithRegExp(Ba,e=>`mailto:${e}`)]},Oa=({editor:e})=>F.registerAutoLink(e,Da),Ha=[".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(","),Fa=(e,t)=>{const n=e.anchorNode,r=e.focusNode;return n!==null&&r!==null&&t.contains(n)&&t.contains(r)},za=e=>{e.querySelectorAll(Ha).forEach(t=>{t.remove()}),e.querySelectorAll('[contenteditable="false"]').forEach(t=>{t.classList.contains("bridgerte__media")||t.remove()})},Wa=e=>{const t=e.ownerDocument.getSelection();if(!t||t.rangeCount===0||!Fa(t,e))return null;const n=t.getRangeAt(0).cloneContents();za(n);const r=e.ownerDocument.createElement("div");return r.append(n),{html:r.innerHTML,text:r.textContent??""}},Va=({target:e,isReadonly:t})=>{const n=o=>{const a=Wa(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})}},Me=8,qa=()=>{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}},$t=(e,t,n)=>Math.min(Math.max(e,t),Math.max(t,n));function tt(e,t,n={}){const r=n.placement??"bottom-start",o=n.offset??8,a=n.shiftPadding??8,s=n.strategy??"absolute";let c=null,u=!1;const l=()=>{t.style.position=s,t.style.left="0px",t.style.top="0px",t.style.opacity="0",t.style.pointerEvents="none"},p=(b,v)=>{const x=qa(),m=t.getBoundingClientRect(),f=x.left+Me,k=x.top+Me,E=x.left+x.width-m.width-Me,I=x.top+x.height-m.height-Me;t.style.left=`${$t(b,f,E)}px`,t.style.top=`${$t(v,k,I)}px`,t.style.opacity="",t.style.pointerEvents=""},w=async()=>{const b=await oe.computePosition(e,t,{placement:r,strategy:s,platform:oe.platform,middleware:[oe.offset(o),oe.flip(),oe.shift({padding:a})]});p(b.x,b.y)},C=()=>{c==null||c(),c=null},N=b=>{if(u!==b){if(u=b,C(),u){l(),t.hidden=!1,c=oe.autoUpdate(e,t,w),w();return}t.hidden=!0,t.style.opacity="",t.style.pointerEvents=""}};return l(),t.hidden=!0,{update:w,setOpen:N,destroy(){C(),t.hidden=!0}}}const nt={"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>'},Ua=e=>{const t=document.createElement("span");return t.className="bridgerte__menu-icon-text",t.textContent=e,t},rt=(e,t,n)=>{if(t){e.innerHTML=t;return}e.append(Ua(n))},Ke=()=>{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},ja=160,Ka={toolbarKeys:["bold","italic","underline","strike","inline-code","clear-style","|","color","background-color","font-size","font-family","line-height"]},Ga=()=>{const e=d.$getSelection();return d.$isRangeSelection(e)&&!e.isCollapsed()},At=(e,t)=>e.target instanceof Node&&t.contains(e.target),Bt=e=>e instanceof Element?e.closest(".bridgerte__hoverbar-button"):null,Ya=e=>e.flatMap(t=>t.type==="button"?[t.item]:t.type==="group"?t.items:[]),Xa=e=>{const t=document.createElement("span");return t.className="bridgerte__hoverbar-separator",t.dataset.separatorId=e.key,t.setAttribute("aria-hidden","true"),t},Ja=(e,t,n)=>{const r=dn(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)),rt(o,n[e.icon]??nt[e.icon],e.label),o},Qa=({editorRoot:e,contentElement:t,editor:n,isReadonly:r,executeCommand:o,requestPayloadPanel:a,getCommandStates:s,menuSchema:c,hoverbarConfig:u,menuLabels:l,payloadPanelConfig:p,icons:w={}})=>{const C=Pe(c??z.defaultMenuSchema,{menuLabels:l,payloadPanelConfig:p}),N=z.resolveToolbarMenu(u??Ka,C),b=Ya(N),v=document.createElement("span"),x=document.createElement("div");let m=null,f=!1,k=null;const E=W(x,{targetSelector:".bridgerte__hoverbar-button"});v.className="bridgerte__hoverbar-anchor",v.setAttribute("aria-hidden","true"),x.className="bridgerte__floating-menu bridgerte__hoverbar",x.setAttribute("role","toolbar"),x.setAttribute("aria-label","BridgeRTE hoverbar"),e.append(v,x),m=tt(v,x,{placement:"top",offset:8,strategy:"fixed"});const I=()=>{k&&(window.clearTimeout(k),k=null)},P=()=>{I(),f=!1,x.replaceChildren(),x.dataset.visible="false",m==null||m.setOpen(!1)},S=()=>{const L=Ke(),M=t.getBoundingClientRect();v.style.left=`${(L==null?void 0:L.left)??M.left}px`,v.style.top=`${(L==null?void 0:L.top)??M.top}px`,v.style.width=`${(L==null?void 0:L.width)||1}px`,v.style.height=`${(L==null?void 0:L.height)||1}px`},_=()=>{const L=s();x.replaceChildren(...N.flatMap(M=>M.type==="separator"?[Xa(M)]:(M.type==="button"?[M.item]:M.items).map(H=>Ja(H,L,w)))),S(),f=!0,x.dataset.visible="true",m==null||m.setOpen(!0),m==null||m.update()},i=()=>r()?!1:n.getEditorState().read(Ga),g=(L=!1)=>{if(I(),!i()){P();return}if(L){_();return}f&&P(),k=window.setTimeout(()=>{k=null,i()&&_()},ja)},h=L=>{const M=b.find(A=>A.id===L.dataset.hoverbarItemId);if(!(!M||L.disabled)){if(M.payloadPanel){const A=L.getBoundingClientRect();a({menuId:M.id,command:M.command,panel:M.payloadPanel,currentValues:cn(M,s()),anchorRect:{x:A.left,y:A.top,width:A.width,height:A.height}}),g(!0);return}o(M.command),g(!0)}},y=L=>{Bt(L.target)&&L.preventDefault()},T=L=>{const M=Bt(L.target);M&&(L.preventDefault(),h(M))},R=L=>{!f||At(L,x)||At(L,t)||P()},$=n.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(g(),!1),d.COMMAND_PRIORITY_LOW),B=n.registerUpdateListener(()=>{g()}),q=n.registerCommand(d.KEY_ESCAPE_COMMAND,L=>f?(L==null||L.preventDefault(),P(),!0):!1,d.COMMAND_PRIORITY_LOW);return x.addEventListener("pointerdown",y),x.addEventListener("click",T),document.addEventListener("pointerdown",R,!0),()=>{I(),$(),B(),q(),x.removeEventListener("pointerdown",y),x.removeEventListener("click",T),document.removeEventListener("pointerdown",R,!0),E(),m==null||m.destroy(),v.remove(),x.remove()}},Za=e=>e.metaKey||e.ctrlKey,es={b:{type:"format.bold"},i:{type:"format.italic"},u:{type:"format.underline"},"\\":{type:"format.clear"}},ts={x:{type:"format.strike"},l:{type:"align",value:"left"},e:{type:"align",value:"center"},r:{type:"align",value:"right"},j:{type:"align",value:"justify"}},ns={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}},rs=e=>{const t=e.key.toLowerCase(),n=e.code;if(!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey||!Za(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 ns[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"}:ts[t]??null:t==="z"?{type:"history.undo"}:t==="y"&&e.ctrlKey&&!e.metaKey?{type:"history.redo"}:t==="`"||t==="~"||n==="Backquote"?{type:"format.inlineCode"}:es[t]??null},os=({target:e,isReadonly:t,executeCommand:n})=>{const r=o=>{if(t())return;const a=rs(o);a&&(o.preventDefault(),n(a))};return e.addEventListener("keydown",r),()=>{e.removeEventListener("keydown",r)}},as=(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)},ot=(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=ot(r,t);if(o)return o}return null},wn=({editorRoot:e,contentElement:t,editor:n,isReadonly:r,menu:o,anchor:a,itemSelector:s,getCurrentTrigger:c,getTriggerRect:u,resolveItems:l,renderItem:p,renderStatus:w,onStateChange:C,onSelect:N})=>{let b=null,v=0;const x=W(o,{targetSelector:s}),m=tt(a,o,{placement:"bottom-start",offset:2,strategy:"fixed"});e.append(a,o);const f=()=>{const M=b?u(b.trigger)??Ke():Ke(),A=t.getBoundingClientRect();return M??A},k=()=>{const M=f();a.style.left=`${M.left}px`,a.style.top=`${M.top}px`,a.style.height=`${M.height||1}px`},E=(M=!0)=>{b=null,o.dataset.visible="false",M&&o.replaceChildren(),m.setOpen(!1)},I=()=>{const M=o.querySelector(`${s}[data-active="true"]`);M&&as(o,M)},P=(M,A)=>{!b||b.requestId!==A.requestId||(E(),N(M,A.trigger))},S=()=>{if(!b){E();return}const M=b,A=f();if((C==null?void 0:C(M,{anchorRect:A,close:E,selectItem:re=>P(re,M)}))===!0){o.replaceChildren(),o.dataset.visible="false",m.setOpen(!1);return}if(M.status==="success")o.replaceChildren(...M.items.map((re,lt)=>p(re,lt,lt===M.activeIndex)));else{const re=w==null?void 0:w(M.status,M.trigger.query,M.error);o.replaceChildren(...re?[re]:[])}const X=o.children.length>0;o.dataset.visible=String(X),k(),m.setOpen(X),I(),m.update()},_=async(M,A)=>{let H;try{H=await Promise.resolve(l(M))}catch(X){(b==null?void 0:b.requestId)===A&&(b={...b,items:[],activeIndex:0,status:"error",error:X},S());return}!b||A!==b.requestId||(b={...b,items:H,activeIndex:Math.min(b.activeIndex,Math.max(H.length-1,0)),status:H.length>0?"success":"empty",error:void 0},S())},i=()=>{if(r()){E();return}const M=n.getEditorState().read(c);if(!M){E(!1);return}v+=1,b={trigger:M,items:[],activeIndex:0,requestId:v,status:"loading",error:void 0},S(),_(M.query,v)},g=()=>{if(!b||b.status!=="success")return!1;const M=b.items[b.activeIndex],A=b.trigger;return M?(E(),N(M,A),!0):!1},h=M=>!b||b.status!=="success"||b.items.length===0?!1:(b={...b,activeIndex:(b.activeIndex+M+b.items.length)%b.items.length},S(),!0),y=M=>{const A=M.target,H=A instanceof HTMLElement?A.closest(s):null,X=H!=null&&H.dataset.index?Number.parseInt(H.dataset.index,10):Number.NaN;!b||b.status!=="success"||Number.isNaN(X)||(b={...b,activeIndex:X},M.preventDefault(),g())},T=M=>{const A=M.target;A instanceof HTMLElement&&A.closest(s)&&M.preventDefault()},R=n.registerUpdateListener(()=>{i()}),$=n.registerCommand(d.KEY_ARROW_DOWN_COMMAND,M=>h(1)?(M==null||M.preventDefault(),!0):!1,d.COMMAND_PRIORITY_LOW),B=n.registerCommand(d.KEY_ARROW_UP_COMMAND,M=>h(-1)?(M==null||M.preventDefault(),!0):!1,d.COMMAND_PRIORITY_LOW),q=n.registerCommand(d.KEY_ENTER_COMMAND,M=>g()?(M==null||M.preventDefault(),!0):!1,d.COMMAND_PRIORITY_LOW),L=n.registerCommand(d.KEY_ESCAPE_COMMAND,M=>b?(M==null||M.preventDefault(),E(),!0):!1,d.COMMAND_PRIORITY_LOW);return o.addEventListener("click",y),o.addEventListener("pointerdown",T),{close:E,destroy(){R(),$(),B(),q(),L(),o.removeEventListener("click",y),o.removeEventListener("pointerdown",T),x(),m.destroy(),a.remove(),o.remove()}}},ss={labelField:"label",descriptionField:"description",avatarField:"avatar",iconField:"data.icon",showAvatar:!0,showIcon:!0,showDescription:!0,loadingText:"加载中",emptyText:"没有匹配的提及",errorText:"提及加载失败"},is=e=>({...ss,...e}),ls=(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},xe=(e,t)=>{if(t.startsWith("data."))return ls(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},cs=e=>e.startsWith("@")?e:`@${e}`,Cn=(e,t)=>{const n=xe(e,t.labelField)??e.label??e.value??e.id,r=t.showDescription?xe(e,t.descriptionField)??e.description:void 0,o=t.showAvatar?xe(e,t.avatarField)??e.avatar:void 0,a=t.showIcon&&!o?xe(e,t.iconField):void 0;return{item:e,label:cs(n),...r?{description:r}:{},...o?{avatar:o}:{},...a?{icon:a}:{}}},ds=(e,t)=>e.map(n=>Cn(n,t)),Ge=e=>e instanceof d.TextNode&&e.getTextContent().startsWith(" "),us=e=>{const n=e.getTextContent().slice(1);if(!n){e.remove();return}e.setTextContent(n)},gs=(e,t)=>{const n=e.getPreviousSibling(),r=e.getNextSibling(),o=Ge(r)?r.getNextSibling():r;if(Ge(r)&&us(r),e.remove(),t){n==null||n.selectEnd();return}o==null||o.selectStart()},ms=e=>{const t=d.$getSelection();if(!d.$isRangeSelection(t)||!t.isCollapsed())return null;const n=t.anchor,r=n.getNode();if(ft(r))return r;if(!(r instanceof d.TextNode))return null;const o=r.getTextContentSize(),a=r.getPreviousSibling(),s=r.getNextSibling(),c=Ge(r)&&n.offset===1,u=e?n.offset===0||c?a:null:n.offset===o?s:null;return ft(u)?u:null},hs=(e,t,n)=>{const r=a=>{if(t())return!1;const s=ms(a);return s?(gs(s,a),n(),!0):!1},o=(a,s)=>{const c=r(s);return c&&a.preventDefault(),c};return[e.registerCommand(d.KEY_BACKSPACE_COMMAND,a=>o(a,!0),d.COMMAND_PRIORITY_HIGH),e.registerCommand(d.KEY_DELETE_COMMAND,a=>o(a,!1),d.COMMAND_PRIORITY_HIGH),e.registerCommand(d.DELETE_CHARACTER_COMMAND,a=>r(a),d.COMMAND_PRIORITY_HIGH)]},ps=/(?:^|\s)@([\p{L}\p{N}_-]*)$/u,Dt=[{id:"bridgerte-team",label:"BridgeRTE Team",value:"bridgerte-team"},{id:"frontend",label:"Frontend",value:"frontend"},{id:"designer",label:"Designer",value:"designer"}],fs=e=>e.trim().toLowerCase(),bs=e=>[e.label,e.value,e.description].filter(Boolean).join(" ").toLowerCase(),ys=e=>{const t=fs(e);return t?Dt.filter(n=>bs(n).includes(t)):Dt},vs=()=>{const e=d.$getSelection();if(!d.$isRangeSelection(e)||!e.isCollapsed())return null;const t=e.anchor,n=t.getNode();if(!(n instanceof d.TextNode))return null;const o=n.getTextContent().slice(0,t.offset).match(ps);if(!o)return null;const a=o[1]??"",s=o[0]??"",c=s.startsWith("@")?0:1,u=t.offset-s.length+c;return{query:a,nodeKey:n.getKey(),startOffset:u,endOffset:t.offset}},ws=()=>{const e=document.createElement("div");return e.className="bridgerte__floating-menu bridgerte__mention-menu",e.dataset.visible="false",e},Cs=()=>{const e=document.createElement("span");return e.className="bridgerte__mention-anchor",e.setAttribute("aria-hidden","true"),e},_s=(e,t)=>{var s;const n=e.getElementByKey(t.nodeKey),r=ot(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())},Es=(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},ks=(e,t)=>{const n=document.createElement("div");return n.className="bridgerte__mention-status",n.dataset.status=e,n.textContent=t,n},Ms=(e,t)=>{switch(e){case"loading":return t.loadingText;case"empty":return t.emptyText;case"error":return t.errorText}},xs=e=>e?{x:e.x,y:e.y,width:e.width,height:e.height}:void 0,Ts=({editorRoot:e,contentElement:t,editor:n,isReadonly:r,executeCommand:o,mentionProvider:a,mentionMenuConfig:s,onMentionMenuRequest:c})=>{const u=ws(),l=Cs(),p=is(s),w=(b,v)=>{n.update(()=>{const x=d.$getNodeByKey(v.nodeKey);x instanceof d.TextNode&&(x.spliceText(v.startOffset,v.endOffset-v.startOffset,""),x.select(v.startOffset,v.startOffset))}),o({type:"mention.insert",item:b})},C=wn({editorRoot:e,contentElement:t,editor:n,isReadonly:r,menu:u,anchor:l,itemSelector:".bridgerte__mention-item",getCurrentTrigger:vs,getTriggerRect:b=>_s(n,b),resolveItems:async b=>{const v=await Promise.resolve(a?a(b):ys(b));return ds(v,p)},renderItem:Es,renderStatus:b=>ks(b,Ms(b,p)),onStateChange:c?(b,v)=>c({id:`bridgerte-mention-menu-${b.requestId}`,query:b.trigger.query,status:b.status,items:b.items,config:p,readonly:r(),anchorRect:xs(v.anchorRect),...b.error?{error:b.error}:{},submit:x=>v.selectItem(Cn(x,p)),cancel:v.close}):void 0,onSelect:(b,v)=>w(b.item,v)}),N=d.mergeRegister(...hs(n,r,()=>C.close(!1)));return()=>{N(),C.destroy()}},Ns=["script","style","iframe","object","embed","meta","link","xml","svg","math","canvas","form","input","button","select","textarea"].join(","),Ss=[".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(","),Ls=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"]),Rs=new Set(["http:","https:","mailto:"]),Is="p,div,blockquote,pre,h1,h2,h3,h4,h5,h6,ul,ol,table",Ps="p,blockquote,pre,h1,h2,h3,h4,h5,h6,ul,ol,table",$s=new Set(["colspan","rowspan"]),As=new Set(["TD","TH"]),Bs=new Set(["M","O","V","W"]),Ds=new Set(["SPAN"]),Os=new Set(["color","background-color"]),Hs=/^#([\da-f]{3}|[\da-f]{6}|[\da-f]{8})$/i,Ot=new Map([["B","strong"],["DEL","s"],["I","em"],["STRIKE","s"],["TT","code"]]),Fs=e=>{try{const t=new URL(e,window.location.href);return Rs.has(t.protocol)}catch{return!1}},at=e=>{e.replaceWith(...e.childNodes)},st=(e,t)=>{const n=e.ownerDocument.createElement(t);return n.append(...e.childNodes),e.replaceWith(n),n},zs=e=>{const t=e.tagName.split(":")[0]??"";return e.tagName.includes(":")&&Bs.has(t)},_n=e=>{[...e.childNodes].forEach(t=>{if(t.nodeType===Node.COMMENT_NODE){t.remove();return}_n(t)})},En=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}En(t)})},Ws=e=>/^[1-9]\d*$/.test(e.trim()),it=e=>{const t=e.trim().toLowerCase(),[,n]=t.match(Hs)??[];return n?n.length===8?`#${n.slice(2)}`:t:null},Vs=(e,t)=>{if(!Ds.has(e))return null;const n=t.split(";").flatMap(r=>{const[o,...a]=r.split(":"),s=o==null?void 0:o.trim().toLowerCase(),c=it(a.join(":"));return!s||!c||!Os.has(s)?[]:[`${s}: ${c}`]});return n.length>0?`${n.join("; ")};`:null},qs=e=>{if(zs(e)){e.remove();return}if(!Ls.has(e.tagName)){at(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=Vs(e.tagName,t.value);if(r){e.setAttribute(t.name,r);return}e.removeAttribute(t.name);return}if(e.tagName==="A"&&n==="href"){if(Fs(t.value))return;e.removeAttribute(t.name);return}if(!(e.tagName==="A"&&["target","rel","title"].includes(n))){if(e.tagName==="PRE"&&n===Ie){const r=ne(t.value);if(r){e.setAttribute(t.name,r);return}e.removeAttribute(t.name);return}if(e.tagName==="FONT"&&n==="color"){if(it(t.value))return;e.removeAttribute(t.name);return}As.has(e.tagName)&&$s.has(n)&&Ws(t.value)||e.removeAttribute(t.name)}})},Us=e=>{[...e.querySelectorAll("font")].forEach(t=>{const n=t.getAttribute("color"),r=n?it(n):null,o=st(t,"span");r&&o.setAttribute("style",`color: ${r};`)})},js=e=>{[...e.querySelectorAll([...Ot.keys()].join(","))].forEach(t=>{const n=Ot.get(t.tagName);n&&st(t,n)})},Ks=e=>{[...e.querySelectorAll("div")].reverse().forEach(t=>{if(t.querySelector(Ps)){at(t);return}st(t,"p")})},Gs=e=>{[...e.querySelectorAll("span")].forEach(t=>{t.attributes.length===0&&at(t)})},Ys=e=>!["P","DIV","SPAN"].includes(e.tagName)||e.querySelector("br,table,ul,ol")?!1:!(e.textContent??"").trim(),Ht=e=>{[...e.querySelectorAll("p,div,span")].reverse().forEach(t=>{Ys(t)&&t.remove()})},Xs=e=>{var t;return e.nodeType===Node.TEXT_NODE?!!((t=e.textContent)!=null&&t.trim()):e.nodeType!==Node.ELEMENT_NODE?!1:!e.matches(Is)},Js=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(Xs(r)){t.push(r);return}n()}),n()},Qs=e=>{const t=document.createElement("template");t.innerHTML=e,t.content.querySelectorAll(Ns).forEach(r=>{r.remove()}),t.content.querySelectorAll(Ss).forEach(r=>{r.remove()}),_n(t.content),oo(t.content),[...t.content.querySelectorAll("*")].forEach(qs),En(t.content),Us(t.content),js(t.content),Ks(t.content),Gs(t.content),Ht(t.content);const n=document.createElement("div");return n.append(t.content.cloneNode(!0)),Js(n),Ht(n),n.innerHTML},Zs=/^https?:\/\/[^\s<>"']+\.[^\s<>"']+$/i,ei=/^www\.[^\s<>"']+\.[^\s<>"']+$/i,ti=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"),ni=/^[^\s@]+@[^\s@]+\.[^\s@]+$/i,ri=/^\s*```([a-z0-9_+#.-]+)\s*\n([\s\S]*?)\n?```\s*$/i,oi=e=>e.type.startsWith("image/")?"image":e.type.startsWith("video/")?"video":null,kn=e=>e?[...e].flatMap(t=>{const n=oi(t);return n?[{type:n,file:t}]:[]}):[],$e=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]:[]}),ai=e=>({name:e.name,mimeType:e.type||void 0,size:e.size,data:e}),si=e=>{const[,t,n]=e.replace(/\r\n/g,`
|
|
3
|
-
`).match(ri)??[],r=ne(t);return n!==void 0&&r!==null?{code:n,language:r}:null},ii=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)||ni.test(t)?!1:Zs.test(t)||ei.test(t)||ti.test(t)},Mn=(e,{isReadonly:t,executeCommand:n})=>t()||!ii(e.text)?!1:(n({type:"link.set",href:e.text.trim()}),!0),Ye=(e,{isReadonly:t,canUploadMedia:n,uploadMediaFile:r})=>{if(t()||!n())return!1;const o=kn(e.files);return o.length===0?!1:(o.forEach(({type:a,file:s})=>{r(a,s)}),!0)},li=(e,t)=>{const r=new DOMParser().parseFromString(t,"text/html");ao(r.body);const o=Xe.$generateNodesFromDOM(e,r);return so(o,r.body),o},ci=(e,t)=>{const n=li(e,t);if(n.length===0)return!1;if(d.$getSelection()||d.$getRoot().selectEnd(),n.some(O.$isCodeNode)){n.forEach(o=>{Re.$insertNodeToNearestRoot(o)});const r=n[n.length-1];return r&&O.$isCodeNode(r)&&d.$insertNodes([d.$createParagraphNode()]),!0}return d.$insertNodes(n),!0},di=(e,{editor:t,isReadonly:n})=>{if(n())return!1;if(!e.html.trim())return gi(e,{editor:t,isReadonly:n});const r=Qs(e.html);return r.trim()?(t.update(()=>{ci(t,r)}),!0):!1},ui=(e,{editor:t,isReadonly:n})=>{if(n()||e.html.trim()||!e.text.trim())return!1;const r=si(e.text);return r?(t.update(()=>{const o=tn(r.language||void 0),a=d.$createParagraphNode();d.$getSelection()||d.$getRoot().selectEnd(),o.append(d.$createTextNode(r.code)),Re.$insertNodeToNearestRoot(o),d.$insertNodes([a]),a.selectStart()}),!0):!1},gi=(e,{editor:t,isReadonly:n})=>n()||e.html.trim()||!e.text?!1:(t.update(()=>{d.$getSelection()||d.$getRoot().selectEnd(),d.$insertNodes([d.$createTextNode(e.text)])}),!0),xn=(e,t)=>ui(e,t)||di(e,t),ee=e=>{e.preventDefault(),e.stopImmediatePropagation()},mi=(e,t)=>Ye(e,t)||Mn(e,t)||xn(e,t),hi=e=>{const t=n=>{n.defaultPrevented||Mn($e(n.clipboardData),e)&&ee(n)};return e.target.addEventListener("paste",t,{capture:!0}),()=>{e.target.removeEventListener("paste",t,{capture:!0})}},pi=e=>{const t=o=>{o.defaultPrevented||Ye($e(o.clipboardData),e)&&ee(o)},n=o=>{var s;if(e.isReadonly()||!e.canUploadMedia())return;const a=(s=o.dataTransfer)!=null&&s.files?[...o.dataTransfer.files]:[];kn(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]:[]};Ye(a,e)&&ee(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)}},fi=e=>{const t=n=>{n.defaultPrevented||!xn($e(n.clipboardData),e)||ee(n)};return e.target.addEventListener("paste",t,{capture:!0}),()=>{e.target.removeEventListener("paste",t,{capture:!0})}},bi=({target:e,isReadonly:t,onPaste:n,canUploadMedia:r,uploadMediaFile:o,executeCommand:a,editor:s})=>{const c=(l,p)=>mi({text:p.text??l.text,html:p.html??l.html,files:l.files},{isReadonly:t,canUploadMedia:r,uploadMediaFile:o,executeCommand:a,editor:s}),u=l=>{if(t()||!n)return;const p=$e(l.clipboardData),w=n({text:p.text,html:p.html,files:p.files.map(ai)});if(w instanceof Promise){ee(l),w.then(C=>{C!==!0&&C&&c(p,C)});return}if(w===!0){ee(l);return}w&&(ee(l),c(p,w))};return e.addEventListener("paste",u,{capture:!0}),()=>{e.removeEventListener("paste",u,{capture:!0})}},yi=["paragraph","heading-1","heading-2","heading-3","quote","code-block","ordered-list","unordered-list","todo-list","divider","upload-image","upload-video","table"],vi={showIcon:!0,loadingText:"加载中",emptyText:"没有匹配的命令",errorText:"命令加载失败"},wi=e=>({...vi,...e}),Ci=e=>e.flatMap(t=>t.type==="button"?[t.item]:t.type==="group"?t.items:[]),_i=e=>({...e,toolbarKeys:(e==null?void 0:e.toolbarKeys)??yi}),Ei=e=>({id:e.id,label:e.label,command:e.command,icon:e.icon,requiresPayload:e.requiresPayload,payloadPanel:e.payloadPanel,source:"schema"}),ki=(e,t)=>Ci(z.resolveToolbarMenu(_i(t),e)).map(Ei),Tn=e=>({...e,source:"provider"}),Mi=/(?:^|\s)\/([\p{L}\p{N}_-]*)$/u,xi=e=>e.trim().toLowerCase(),Ti=e=>[e.label,e.id,e.description,...e.keywords??[]].filter(Boolean).join(" ").toLowerCase(),Ni=(e,t)=>{const n=xi(t);return n?e.filter(r=>Ti(r).includes(n)):e},Si=async(e,t)=>(await Promise.resolve((t==null?void 0:t(e))??[])).map(Tn),Li=e=>"source"in e?e:Tn(e),Ri=({menuSchema:e,slashCommandConfig:t})=>e!==void 0||t!==void 0,Ii=()=>{const e=d.$getSelection();if(!d.$isRangeSelection(e)||!e.isCollapsed())return null;const t=e.anchor,n=t.getNode();if(!(n instanceof d.TextNode))return null;const o=n.getTextContent().slice(0,t.offset).match(Mi);if(!o)return null;const a=o[1]??"",s=o[0]??"",c=s.startsWith("/")?0:1,u=t.offset-s.length+c;return{query:a,nodeKey:n.getKey(),startOffset:u,endOffset:t.offset}},Pi=()=>{const e=document.createElement("div");return e.className="bridgerte__floating-menu bridgerte__slash-command-menu",e.dataset.visible="false",e},$i=()=>{const e=document.createElement("span");return e.className="bridgerte__slash-command-anchor",e.setAttribute("aria-hidden","true"),e},Ft=(e,t)=>{var s;const n=e.getElementByKey(t.nodeKey),r=ot(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())},Ai=(e,t,n,r,o)=>{const a=document.createElement("button"),s=document.createElement("span");if(a.type="button",a.className="bridgerte__menu-item bridgerte__slash-command-item",a.dataset.commandId=e.id,a.dataset.index=String(t),a.dataset.active=String(n),r.showIcon&&e.icon){const c=document.createElement("span");c.className="bridgerte__slash-command-item-icon",c.setAttribute("aria-hidden","true"),rt(c,o[e.icon]??nt[e.icon],e.label),a.append(c)}if(s.className="bridgerte__slash-command-item-title",s.textContent=e.label,a.append(s),e.description){const c=document.createElement("span");c.className="bridgerte__slash-command-item-description",c.textContent=e.description,a.append(c)}return a},Bi=(e,t)=>{const n=document.createElement("div");return n.className="bridgerte__slash-command-status",n.dataset.status=e,n.textContent=t,n},Di=(e,t)=>{switch(e){case"loading":return t.loadingText;case"empty":return t.emptyText;case"error":return t.errorText}},zt=e=>e?{x:e.x,y:e.y,width:e.width,height:e.height}:void 0,Oi=({editorRoot:e,contentElement:t,editor:n,isReadonly:r,executeCommand:o,requestPayloadPanel:a,menuSchema:s,slashCommandConfig:c,icons:u={},menuLabels:l,payloadPanelConfig:p,slashCommandMenuConfig:w,onSlashCommandMenuRequest:C,slashCommandProvider:N})=>{const b=Pi(),v=$i(),x=wi(w),m=Pe(s??z.defaultMenuSchema,{menuLabels:l,payloadPanelConfig:p}),f=ki(m,c),k=new Map(m.map(i=>[i.id,i])),E=Ri({menuSchema:s,slashCommandConfig:c}),I=i=>{n.update(()=>{const g=d.$getNodeByKey(i.nodeKey);g instanceof d.TextNode&&(g.spliceText(i.startOffset,i.endOffset-i.startOffset,""),g.select(i.startOffset,i.startOffset))})};return wn({editorRoot:e,contentElement:t,editor:n,isReadonly:r,menu:b,anchor:v,itemSelector:".bridgerte__slash-command-item",getCurrentTrigger:Ii,getTriggerRect:i=>Ft(n,i),resolveItems:async i=>{const g=E||!N?Ni(f,i):[];try{const h=await Si(i,N);return[...g,...h]}catch(h){if(g.length>0)return g;throw h}},renderItem:(i,g,h)=>Ai(i,g,h,x,u),renderStatus:i=>Bi(i,Di(i,x)),onStateChange:C?(i,g)=>C({id:`bridgerte-slash-command-menu-${i.requestId}`,query:i.trigger.query,status:i.status,items:i.items,config:x,readonly:r(),anchorRect:zt(g.anchorRect),...i.error?{error:i.error}:{},submit:h=>g.selectItem(Li(h)),cancel:g.close}):void 0,onSelect:(i,g)=>{I(g);const h=i.source==="schema"?k.get(i.id):void 0;if(h!=null&&h.payloadPanel){const y=Ft(n,g);a({menuId:h.id,command:h.command,panel:h.payloadPanel,anchorRect:zt(y??void 0)});return}o(i.command)}}).destroy},Wt=32,He=e=>{var t;return e instanceof HTMLElement&&e.getAttribute("role")==="checkbox"&&((t=e.parentElement)==null?void 0:t.classList.contains("bridgerte__list--todo"))===!0},Fe=e=>e instanceof HTMLElement?e.closest('[role="checkbox"]'):null,Hi=e=>d.$getNearestNodeFromDOMNode(e),Vt=e=>e.button===0,ze=(e,t)=>{const n=t.getBoundingClientRect();return t.dir==="rtl"?e.clientX>=n.right-Wt&&e.clientX<=n.right:e.clientX>=n.left&&e.clientX<=n.left+Wt},qt=e=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},Fi=({contentElement:e,editor:t,isReadonly:n})=>{let r=0;const o=u=>{if(n()||!Vt(u))return;const l=Fe(u.target);!l||!He(l)||ze(u,l)&&qt(u)},a=(u,l)=>{qt(u),t.update(()=>{const p=Hi(l);V.$isListItemNode(p)&&p.toggleChecked()})},s=u=>{if(n()||!Vt(u)||Date.now()-r<700)return;const l=Fe(u.target);!l||!He(l)||ze(u,l)&&a(u,l)},c=u=>{if(n()||u.pointerType!=="touch")return;const l=Fe(u.target);!l||!He(l)||ze(u,l)&&(r=Date.now(),a(u,l))};return e.addEventListener("pointerdown",o,!0),e.addEventListener("pointerup",c,!0),e.addEventListener("click",s,!0),()=>{e.removeEventListener("pointerdown",o,!0),e.removeEventListener("pointerup",c,!0),e.removeEventListener("click",s,!0)}},We=(e,t)=>{var n;return((n=e.floatingMenus)==null?void 0:n[t])!==!1},zi=({options:e,lexicalEditor:t,editorRoot:n,contentElement:r,historyState:o,isReadonly:a,executeCommand:s,requestPayloadPanel:c,uploadMediaFile:u,canUploadMedia:l,syncAfterEditorUpdate:p,refreshCommandStates:w,getCommandStates:C,setCanUndo:N,setCanRedo:b,enableKeyboardShortcuts:v})=>{const x=We(e,"mention"),m=We(e,"slash"),f=We(e,"hoverbar"),k=d.mergeRegister(bi({target:r,isReadonly:a,onPaste:e.onPaste,canUploadMedia:l,uploadMediaFile:u,executeCommand:s,editor:t}),pi({target:r,isReadonly:a,canUploadMedia:l,uploadMediaFile:u}),hi({target:r,isReadonly:a,executeCommand:s}),fi({target:r,editor:t,isReadonly:a}),Va({target:r,isReadonly:a}),te.registerRichText(t),U.registerCodeHighlighting(t,co),Ut.registerHistory(t,o,qr),V.registerList(t),V.registerCheckList(t),...Yn(t,a),Fi({contentElement:r,editor:t,isReadonly:a}),x?Ts({editorRoot:n,contentElement:r,editor:t,isReadonly:a,executeCommand:s,mentionProvider:e.mentionProvider,mentionMenuConfig:e.mentionMenuConfig,onMentionMenuRequest:e.onMentionMenuRequest}):()=>{},f?Qa({editorRoot:n,contentElement:r,editor:t,isReadonly:a,executeCommand:s,requestPayloadPanel:c,getCommandStates:C,menuSchema:e.menuSchema,hoverbarConfig:e.hoverbarConfig,icons:e.icons,menuLabels:e.menuLabels,payloadPanelConfig:e.payloadPanelConfig}):()=>{},D.registerTablePlugin(t),Oa({editor:t}),m?Oi({editorRoot:n,contentElement:r,editor:t,isReadonly:a,executeCommand:s,requestPayloadPanel:c,menuSchema:e.menuSchema,slashCommandConfig:e.slashCommandConfig,icons:e.icons,menuLabels:e.menuLabels,payloadPanelConfig:e.payloadPanelConfig,slashCommandMenuConfig:e.slashCommandMenuConfig,onSlashCommandMenuRequest:e.onSlashCommandMenuRequest,slashCommandProvider:e.slashCommandProvider}):()=>{},nr({editor:t,contentElement:r,isReadonly:a}),v?os({target:r,isReadonly:a,executeCommand:s}):()=>{},t.registerUpdateListener(()=>{p(),w()}),t.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>(w(),!1),d.COMMAND_PRIORITY_LOW),t.registerCommand(d.CAN_UNDO_COMMAND,E=>(N(E),!1),d.COMMAND_PRIORITY_LOW),t.registerCommand(d.CAN_REDO_COMMAND,E=>(b(E),!1),d.COMMAND_PRIORITY_LOW));return{destroy(){k()}}};function Nn(e,t={}){const n=Ut.createEmptyHistoryState(),r=t.mediaDefaultWidthPercent??50,{contentElement:o}=Pa(e,{placeholder:t.placeholder??Zn}),a=t.keyboardShortcuts===!0;let s=t.readonly??!1,c=!1,u=Ve(t.value);const l=d.createEditor({namespace:Ur,editable:!s,nodes:[te.HeadingNode,te.QuoteNode,O.CodeNode,O.CodeHighlightNode,V.ListNode,V.ListItemNode,D.TableNode,D.TableRowNode,D.TableCellNode,F.LinkNode,F.AutoLinkNode,pe,ce,ye],theme:Lr,onError:i=>{j(t,"lexical.runtime","Lexical runtime error.",i)}});D.setScrollableTablesActive(l,!0);const p=()=>c,w=()=>s,C=()=>{p()||tr({editor:l,contentElement:o})},N=$a({editor:l}),b=jr({lexicalEditor:l,options:t,isDestroyed:p,setContent:i=>{u=i},syncPlaceholder:C}),v=wr({lexicalEditor:l,options:t,isDestroyed:p,canUploadMedia:()=>t.uploadAdapter!==void 0,isReadonly:w}),x=Vr({container:e,lexicalEditor:l,options:t,isDestroyed:p,isReadonly:w,reportError:j}),m=()=>{o.contentEditable=String(!s),l.setEditable(!s)},k=Ia({editorRoot:e,lexicalEditor:l,isReadonly:w,restoreEditorFocus:i=>{N.restore(),l.focus(i)},executeCommand:x,getClearCommand:i=>{switch(i.command.type){case"format.color":case"format.backgroundColor":case"format.fontSize":case"format.fontFamily":case"format.lineHeight":return{...i.command,value:""};default:return null}},codeBlockLanguagePanel:t.codeBlockLanguagePanel,payloadPanelConfig:t.payloadPanelConfig,mediaControlsConfig:t.mediaControlsConfig,menuLabels:t.menuLabels,onRequest:t.onPayloadPanelRequest,defaultMediaWidthPercent:r}),E=()=>br(t),I=()=>yr(t),P=i=>{p()||(N.capture(),k.payloadPanelController.open(i))};e.dataset.readonly=String(s),e.addEventListener("focusin",E),e.addEventListener("focusout",I),e.style.setProperty("--bridgerte-media-display-width",`${r}%`);const S=zi({options:t,lexicalEditor:l,editorRoot:e,contentElement:o,historyState:n,isReadonly:w,executeCommand:x,requestPayloadPanel:P,uploadMediaFile:x.uploadMediaFile,canUploadMedia:()=>t.uploadAdapter!==void 0,syncAfterEditorUpdate:b.syncAfterEditorUpdate,refreshCommandStates:v.refreshCommandStates,getCommandStates:v.getCommandStates,setCanUndo:v.setCanUndo,setCanRedo:v.setCanRedo,enableKeyboardShortcuts:a});l.setRootElement(o),b.suppressNextChange(),u=zn(l,t.value),m();const _={getContent(){return p()||(b.clearContentChangeTimer(),b.syncContent(!1)),u},setContent(i){p()||(b.clearContentChangeTimer(),u=Ve(i),b.suppressNextChange(),Jt(l,u),b.enforceCurrentMaxLength(),C(),l.dispatchCommand(d.CLEAR_HISTORY_COMMAND,void 0),v.setHistoryAvailability(!1,!1),b.syncContent(!0))},executeCommand(i){x(i)},requestPayloadPanel:P,getCommandStates:v.getCommandStates,subscribeCommandStateChange:v.subscribeCommandStateChange,setReadonly(i){p()||(s=i,e.dataset.readonly=String(s),m(),v.refreshCommandStates())},focus(){p()||l.focus()},blur(){p()||o.blur()},destroy(){p()||(c=!0,b.clearContentChangeTimer(),k.destroy(),x.destroy(),v.destroy(),N.clear(),S.destroy(),l.setRootElement(null),e.removeEventListener("focusin",E),e.removeEventListener("focusout",I),e.classList.remove("bridgerte"),e.textContent="",delete e.dataset.readonly)}};return b.syncContent(!1),C(),v.refreshCommandStates(),vr(t,_),_}const Wi=e=>!Le.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",Vi=e=>({id:e,type:"editor.ready",payload:{menuSchema:z.defaultMenuSchema,eventTiming:Le.defaultBridgeEventTiming,version:Y.BRIDGERTE_CONTENT_VERSION}}),qi=e=>`native-upload:${e}:${Date.now()}:${Math.random().toString(36).slice(2)}`,Ui=({container:e,transport:t})=>{var S;let n=null,r=!1,o=null,a=null,s=null,c=0;const u=new Map,l=new Map,p=_=>{r||t.postMessage(_)},w=()=>{s&&(clearTimeout(s),s=null)},C=()=>{w(),s=setTimeout(()=>{if(r)return;const _=Math.ceil(e.getBoundingClientRect().height);_!==c&&(c=_,p({type:"editor.heightChange",payload:{height:_}}))},Le.BRIDGE_HEIGHT_CHANGE_THROTTLE_MS)},N=_=>{if(!n)return;const i=n.getContent();p({id:_,type:"editor.content",payload:i}),p({id:_,type:"editor.contentChange",payload:i})},b=_=>{const i=_.payload,g=u.get(i.assetId);if(g){if(u.delete(i.assetId),g.source==="uploadAdapter"){g.resolve(i.result);return}n==null||n.executeCommand({type:g.type==="image"?"media.insertImage":"media.insertVideo",url:i.result.url,poster:i.result.poster,width:i.result.width,height:i.result.height,displayWidthPercent:50,assetId:i.assetId})}},v=_=>{const i=_.payload,g=u.get(i.assetId);if(g){if(u.delete(i.assetId),g.source==="uploadAdapter"){g.reject(new Error(i.message));return}p({id:_.id,type:"editor.error",payload:{code:"bridge.uploadRejected",message:i.message}})}},x=(_,i)=>new Promise((g,h)=>{u.set(i,{type:_,assetId:i,source:"uploadAdapter",resolve:g,reject:h}),p({type:"editor.uploadRequest",payload:{assetId:i,type:_,accept:_==="image"?"image/*":"video/*"}})}),m=_=>{const i=qi(_);u.set(i,{type:_,assetId:i,source:"nativePicker"}),p({type:"editor.uploadRequest",payload:{assetId:i,type:_,accept:_==="image"?"image/*":"video/*"}})},f=_=>{const i=l.get(_.payload.requestId);i&&(l.delete(_.payload.requestId),i.request.submit(_.payload.values))},k=_=>{const i=l.get(_.payload.requestId);i&&(l.delete(_.payload.requestId),i.request.cancel())},E=(_,i)=>{n==null||n.destroy(),o==null||o(),u.clear(),l.clear(),n=Nn(e,{...i,uploadAdapter:{uploadImage(g,h){return x("image",h.assetId)},uploadVideo(g,h){return x("video",h.assetId)}},onContentChange:g=>{p({type:"editor.contentChange",payload:g}),C()},onCommandStateChange:g=>{p({type:"editor.commandStateChange",payload:g})},onPayloadPanelRequest:g=>(l.set(g.id,{request:g}),p({type:"editor.payloadPanelRequest",payload:{menuId:g.menuId,command:g.command,panel:g.panel,anchorRect:g.anchorRect,currentValues:g.currentValues,id:g.id,readonly:g.readonly}}),!0),onError:g=>{p({type:"editor.error",payload:g})}}),o=n.subscribeCommandStateChange(g=>{p({type:"editor.commandStateChange",payload:g})}),p(Vi(_)),C()},I=_=>{if(_.type==="media.pickImage"){m("image");return}if(_.type==="media.pickVideo"){m("video");return}n==null||n.executeCommand(_)},P=_=>{if(!(r||!Wi(_)))switch(_.type){case"editor.init":E(_.id,_.payload);return;case"editor.executeCommand":I(_.payload);return;case"editor.setContent":n==null||n.setContent(_.payload);return;case"editor.setReadonly":n==null||n.setReadonly(_.payload.readonly);return;case"editor.requestContent":N(_.id);return;case"editor.payloadPanelResolved":f(_);return;case"editor.payloadPanelCanceled":k(_);return;case"editor.uploadResolved":b(_);return;case"editor.uploadRejected":v(_);return}};return a=((S=t.addMessageListener)==null?void 0:S.call(t,P))??null,{receive:P,destroy(){r||(r=!0,w(),a==null||a(),o==null||o(),u.clear(),l.clear(),n==null||n.destroy(),n=null)}}};exports.appendMenuIcon=rt;exports.bindTouchPressedState=W;exports.createFloatingLayer=tt;exports.createRichTextEditor=Nn;exports.createWebViewBridgeRuntime=Ui;exports.defaultMenuIcons=nt;exports.getMenuStateForItem=dn;exports.getPayloadPanelCurrentValues=cn;exports.resolveMenuSchemaForDom=Pe;
|
|
4
|
-
//# sourceMappingURL=index-BBzHVrSi.cjs.map
|