wendang-react 0.6.4 → 0.6.6

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/dist/document.js CHANGED
@@ -1,120 +1,113 @@
1
- "use client";import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{c as o,a as l,p as r,u as i}from"./chunks/i18n-B0kCsIjc.js";import{getMarkRange as a,Editor as c,getSchema as s}from"@tiptap/core";import{TextSelection as u,Selection as d,NodeSelection as m}from"@tiptap/pm/state";import{createPortal as p}from"react-dom";import{useRef as h,useState as v,useLayoutEffect as g,useEffect as f,useMemo as b,useId as w,forwardRef as y,useCallback as k,useImperativeHandle as C}from"react";import{ContentSchemaService as x,requiredSchemaVersion as E,SCHEMA_VERSION as M}from"wendang/schema";import{safeHref as N,TEXT_COLORS as L,HIGHLIGHT_COLORS as D,documentColorAttributes as S,parseVideoUrl as A}from"wendang/shared";import{b as T,d as B,u as I,h as P,T as R,c as z,r as H,t as O,a as q,s as $,i as F,e as V,f as W,g as Y,j,k as U,l as _,m as J,n as X,o as G,p as Q,q as K,v as Z,B as ee,w as te,x as ne,y as oe,z as le,A as re,D as ie,E as ae,F as ce,G as se,H as ue,I as de}from"./chunks/extensions-C1fCBnEs.js";import{C as me}from"./chunks/extensions-C1fCBnEs.js";import{c as pe}from"./chunks/mind-map-controller-Ce76mETT.js";import{M as he}from"./chunks/MindMapViewer-BI8zbQM1.js";import{p as ve,I as ge,V as fe}from"./chunks/mind-topic-text-Bn1waxff.js";import{u as be,a as we,b as ye}from"./chunks/hooks-C53Dp0pr.js";import{a as ke,b as Ce,p as xe,l as Ee,t as Me,c as Ne}from"./chunks/index-COeA2QcQ.js";import{p as Le}from"./chunks/popover-placement-D3xVYdkt.js";import{A as De,a as Se,b as Ae}from"./chunks/popover-placement-D3xVYdkt.js";import{isSafeHref as Te}from"wendang/internal/safe-href";import{createMindMap as Be}from"wendang/internal/mind-map";import{s as Ie}from"./chunks/composition-state-Bl-U1R_2.js";import{DOMSerializer as Pe,Fragment as Re}from"@tiptap/pm/model";import{createTable as ze}from"@tiptap/extension-table";import{createMindMap as He}from"wendang/mindmap";import{closeHistory as Oe}from"@tiptap/pm/history";import{yUndoPluginKey as qe,ySyncPluginKey as $e}from"@tiptap/y-tiptap";import{CellSelection as Fe,TableMap as Ve}from"@tiptap/pm/tables";import{CELL_BACKGROUNDS as We}from"wendang/internal/table-cell-format";import{r as Ye}from"./chunks/fuzzy-match-DYQR-4w2.js";import{inspectVideoUrl as je,VIDEO_PROVIDER_LABELS as Ue,videoSourceUrl as _e}from"wendang/internal/video-embed";import{createI18n as Je}from"wendang/i18n";import{D as Xe}from"./chunks/DocumentExportMenu-CUMsgq3w.js";function createLinkEditTarget(e,t=e.selection){if(!(t instanceof u))return null;const n=e.schema.marks.link;if(!n)return null;let{from:o,to:l}=t;const r=a(t.$from,n);if(r&&l<=r.to&&({from:o,to:l}=r),o===l)return null;let i="";return e.doc.nodesBetween(o,l,e=>{var t;const o=null==(t=e.marks.find(e=>e.type===n))?void 0:t.attrs.href;i||"string"!=typeof o||(i=o)}),{from:o,to:l,valid:!0,href:i,hasLink:e.doc.rangeHasMark(o,l,n),contentJSON:JSON.stringify(e.doc.slice(o,l).toJSON())}}function LinkPopover({target:n,onEdit:r,onSave:i,onRemove:a,onClose:c}){const s=o().text,{portal:u}=l(),d=h(null),[m,b]=v(n.href),[w,y]=v(""),[k,C]=v({left:n.anchor.left,top:n.anchor.top+n.anchor.height+8});return g(()=>{const measure=()=>{var e;const t=null==(e=d.current)?void 0:e.getBoundingClientRect();t&&C(Le({align:"preview"===n.mode?"center":"start",prefer:"preview"===n.mode?"above":"below",anchor:n.anchor,host:{left:0,top:0},card:t,bounds:{left:0,top:0,width:innerWidth,height:innerHeight}}))};measure();const e=new ResizeObserver(measure);return d.current&&e.observe(d.current),()=>e.disconnect()},[n.mode,n.anchor,u]),f(()=>{const outside=e=>{var t;e.target instanceof Node&&!(null==(t=d.current)?void 0:t.contains(e.target))&&c()},escape=e=>{"Escape"===e.key&&(e.stopPropagation(),c())};return document.addEventListener("pointerdown",outside),document.addEventListener("keydown",escape),window.addEventListener("scroll",c,!0),()=>{document.removeEventListener("pointerdown",outside),document.removeEventListener("keydown",escape),window.removeEventListener("scroll",c,!0)}},[]),f(()=>{if("preview"!==n.mode)return;let e;const move=t=>{var o;const l=n.anchor;(null==(o=d.current)?void 0:o.contains(t.target))||t.clientX>=l.left-5&&t.clientX<=l.left+l.width+5&&t.clientY>=l.top-5&&t.clientY<=l.top+l.height+5?(clearTimeout(e),e=void 0):e||(e=setTimeout(c,180))};return document.addEventListener("mousemove",move),()=>{clearTimeout(e),document.removeEventListener("mousemove",move)}},[n.mode,n.anchor,c]),u?p(/* @__PURE__ */e("div",{ref:d,className:"wr-link-popover",style:k,role:"edit"===n.mode?"dialog":"toolbar","aria-label":"edit"===n.mode?s("编辑链接"):s("链接预览"),children:"preview"===n.mode?/* @__PURE__ */t("div",{className:"wr-toolbar",children:[
2
- /* @__PURE__ */e("a",{href:N(n.href),target:"_blank",rel:"noopener noreferrer",children:n.href}),
3
- /* @__PURE__ */e(ke,{onClick:r,children:s("编辑链接")}),
4
- /* @__PURE__ */e(ke,{onClick:a,children:s("取消链接")})]}):/* @__PURE__ */t("form",{onSubmit:e=>{e.preventDefault();const t=function linkHrefProblem(e){const t=e.trim();if(!t)return"请输入链接地址。";if(t.length>2048||/[\u0000-\u0020\u007f]/.test(t)||!Te(t))return"请输入有效的网页、邮箱或站内链接。";if(/^https?:/i.test(t))try{const e=new URL(t);if(!/^https?:\/\//i.test(t)||!e.hostname)return"请输入完整的网址,例如 https://example.com。"}catch{return"请输入完整的网址,例如 https://example.com。"}return/^mailto:$/i.test(t)?"请输入完整的邮箱链接,例如 mailto:name@example.com。":""}(m);t?y(t):i(m.trim())},children:[
1
+ "use client";import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{c as o,a as r,p as l,u as i}from"./chunks/i18n-B0kCsIjc.js";import{getMarkRange as a,Editor as s,getSchema as c}from"@tiptap/core";import{TextSelection as u,Selection as d,NodeSelection as m}from"@tiptap/pm/state";import{createPortal as p}from"react-dom";import{useRef as h,useState as v,useLayoutEffect as f,useEffect as g,useMemo as b,useId as w,forwardRef as y,useCallback as k,useImperativeHandle as x}from"react";import{ContentSchemaService as C,requiredSchemaVersion as E,SCHEMA_VERSION as M}from"wendang/schema";import{safeHref as L,TEXT_COLORS as N,HIGHLIGHT_COLORS as D,documentColorAttributes as S,parseVideoUrl as A}from"wendang/shared";import{b as T,d as B,u as I,h as P,T as R,c as z,r as H,t as O,a as q,s as $,i as F,e as V,f as W,g as j,j as Y,k as U,l as _,m as J,n as X,o as G,p as Q,q as K,v as Z,B as ee,w as te,x as ne,y as oe,z as re,A as le,D as ie,E as ae,F as se,G as ce,H as ue,I as de}from"./chunks/extensions-D4JlN-IP.js";import{C as me}from"./chunks/extensions-D4JlN-IP.js";import{c as pe,a as he}from"./chunks/mind-map-defaults-B9SSENmK.js";import{M as ve}from"./chunks/MindMapViewer-B1_uaMHB.js";import{p as fe,I as ge,V as be}from"./chunks/mind-topic-text-C7pIS6L9.js";import{u as we,a as ye,b as ke}from"./chunks/hooks-C53Dp0pr.js";import{a as xe,b as Ce,p as Ee,l as Me,t as Le,c as Ne}from"./chunks/index-COeA2QcQ.js";import{p as De}from"./chunks/popover-placement-D3xVYdkt.js";import{A as Se,a as Ae,b as Te}from"./chunks/popover-placement-D3xVYdkt.js";import{isSafeHref as Be}from"wendang/internal/safe-href";import{documentColorAttributes as Ie}from"wendang/internal/document-colors";import{A as Pe}from"./chunks/AnchoredPanel-C7jMoPze.js";import{readI18n as Re,createI18n as ze}from"wendang/i18n";import{s as He}from"./chunks/composition-state-Bl-U1R_2.js";import{DOMSerializer as Oe,Fragment as qe}from"@tiptap/pm/model";import{createTable as $e}from"@tiptap/extension-table";import{createMindMap as Fe}from"wendang/mindmap";import{closeHistory as Ve}from"@tiptap/pm/history";import{yUndoPluginKey as We,ySyncPluginKey as je}from"@tiptap/y-tiptap";import{CellSelection as Ye,TableMap as Ue}from"@tiptap/pm/tables";import{CELL_BACKGROUNDS as _e}from"wendang/internal/table-cell-format";import{r as Je}from"./chunks/fuzzy-match-DYQR-4w2.js";import{inspectVideoUrl as Xe,VIDEO_PROVIDER_LABELS as Ge,videoSourceUrl as Qe,videoLoadsAutomatically as Ke,normalizeVideoEmbed as Ze}from"wendang/internal/video-embed";import{D as et}from"./chunks/DocumentExportMenu-CUMsgq3w.js";function createLinkEditTarget(e,t=e.selection){if(!(t instanceof u))return null;const n=e.schema.marks.link;if(!n)return null;let{from:o,to:r}=t;const l=a(t.$from,n);if(l&&r<=l.to&&({from:o,to:r}=l),o===r)return null;let i="";return e.doc.nodesBetween(o,r,e=>{var t;const o=null==(t=e.marks.find(e=>e.type===n))?void 0:t.attrs.href;i||"string"!=typeof o||(i=o)}),{from:o,to:r,valid:!0,href:i,hasLink:e.doc.rangeHasMark(o,r,n),contentJSON:JSON.stringify(e.doc.slice(o,r).toJSON())}}function LinkPopover({target:n,onEdit:l,onSave:i,onRemove:a,onClose:s}){const c=o().text,{portal:u}=r(),d=h(null),m=h(null),[b,w]=v(n.href),[y,k]=v(""),[x,C]=v({left:n.anchor.left,top:n.anchor.top+n.anchor.height+8});return f(()=>{const measure=()=>{var e;const t=null==(e=d.current)?void 0:e.getBoundingClientRect();t&&C(De({align:"preview"===n.mode?"center":"start",prefer:"preview"===n.mode?"above":"below",anchor:n.anchor,host:{left:0,top:0},card:t,bounds:{left:0,top:0,width:innerWidth,height:innerHeight}}))};measure();const e=new ResizeObserver(measure);return d.current&&e.observe(d.current),()=>e.disconnect()},[n.mode,n.anchor,u]),f(()=>{var e,t;"edit"===n.mode&&u&&(null==(e=m.current)||e.focus({preventScroll:!0}),null==(t=m.current)||t.select())},[n.mode,u]),g(()=>{const outside=e=>{var t;e.target instanceof Node&&!(null==(t=d.current)?void 0:t.contains(e.target))&&s()},escape=e=>{"Escape"===e.key&&(e.stopPropagation(),s())};return document.addEventListener("pointerdown",outside),document.addEventListener("keydown",escape),window.addEventListener("scroll",s,!0),()=>{document.removeEventListener("pointerdown",outside),document.removeEventListener("keydown",escape),window.removeEventListener("scroll",s,!0)}},[]),g(()=>{if("preview"!==n.mode)return;let e;const move=t=>{var o;const r=n.anchor;(null==(o=d.current)?void 0:o.contains(t.target))||t.clientX>=r.left-5&&t.clientX<=r.left+r.width+5&&t.clientY>=r.top-5&&t.clientY<=r.top+r.height+5?(clearTimeout(e),e=void 0):e||(e=setTimeout(s,180))};return document.addEventListener("mousemove",move),()=>{clearTimeout(e),document.removeEventListener("mousemove",move)}},[n.mode,n.anchor,s]),u?p(/* @__PURE__ */e("div",{ref:d,className:"wr-link-popover",style:x,role:"edit"===n.mode?"dialog":"toolbar","aria-label":"edit"===n.mode?c("编辑链接"):c("链接预览"),children:"preview"===n.mode?/* @__PURE__ */t("div",{className:"wr-toolbar",children:[
2
+ /* @__PURE__ */e("a",{href:L(n.href),target:"_blank",rel:"noopener noreferrer",children:n.href}),
3
+ /* @__PURE__ */e(xe,{onClick:l,children:c("编辑链接")}),
4
+ /* @__PURE__ */e(xe,{onClick:a,children:c("取消链接")})]}):/* @__PURE__ */t("form",{onSubmit:e=>{e.preventDefault();const t=function linkHrefProblem(e){const t=e.trim();if(!t)return"请输入链接地址。";if(t.length>2048||/[\u0000-\u0020\u007f]/.test(t)||!Be(t))return"请输入有效的网页、邮箱或站内链接。";if(/^https?:/i.test(t))try{const e=new URL(t);if(!/^https?:\/\//i.test(t)||!e.hostname)return"请输入完整的网址,例如 https://example.com。"}catch{return"请输入完整的网址,例如 https://example.com。"}return/^mailto:$/i.test(t)?"请输入完整的邮箱链接,例如 mailto:name@example.com。":""}(b);t?k(t):i(b.trim())},children:[
5
5
  /* @__PURE__ */t("div",{className:"wr-toolbar",children:[
6
- /* @__PURE__ */e("input",{autoFocus:!0,"aria-label":s("链接地址"),value:m,onChange:e=>{b(e.target.value),y("")},placeholder:s("粘贴或输入链接")}),
7
- /* @__PURE__ */e(ke,{htmlType:"submit",children:s("确认")}),
8
- /* @__PURE__ */e(ke,{onClick:a,children:s("取消链接")})]}),w&&/* @__PURE__ */e("p",{role:"alert",children:w})]})}),u):null}function DocumentColorPanel({textColor:n,highlightColor:l,onTextColor:r,onHighlightColor:i,onReset:a,onClose:c}){const s=o().text;/* @__PURE__ */
9
- return t("div",{className:"document-color-panel",role:"group","aria-label":s("文档颜色"),onMouseDown:e=>e.preventDefault(),children:[
6
+ /* @__PURE__ */e("input",{ref:m,"aria-label":c("链接地址"),value:b,onChange:e=>{w(e.target.value),k("")},placeholder:c("粘贴或输入链接")}),
7
+ /* @__PURE__ */e(xe,{htmlType:"submit",children:c("确认")}),
8
+ /* @__PURE__ */e(xe,{onClick:a,children:c("取消链接")})]}),y&&/* @__PURE__ */e("p",{role:"alert",children:y})]})}),u):null}function documentSwatchStyle(e,t){const n=Ie(e,t).style;return n?{["text"===e?"color":"backgroundColor"]:n.slice(n.indexOf(":")+1).trim()}:"text"===e?{color:"var(--content-text-color, var(--color-text, #1f2937))"}:{}}function DocumentColorPanel({textColor:n,highlightColor:r,onTextColor:l,onHighlightColor:i,onReset:a,onClose:s}){const c=o().text;/* @__PURE__ */
9
+ return t("div",{className:"document-color-panel",role:"group","aria-label":c("文档颜色"),onMouseDown:e=>e.preventDefault(),children:[
10
10
  /* @__PURE__ */t("div",{className:"color-section",children:[
11
- /* @__PURE__ */e("div",{className:"color-label",children:s("字体颜色")}),
12
- /* @__PURE__ */e("div",{className:"color-grid",role:"group","aria-label":s("字体颜色"),children:L.map(t=>/* @__PURE__ */e("button",{type:"button",className:"color-choice"+(n===t.value?" selected":""),"aria-label":s("字体颜色:{0}",{0:s(t.name)}),title:s("字体颜色:{0}",{0:s(t.name)}),"aria-pressed":n===t.value,onClick:()=>r(t.value),children:/* @__PURE__ */e("span",{className:"font-sample",style:textColorStyle(t.value),children:"A"})},t.name))})]}),
11
+ /* @__PURE__ */e("div",{className:"color-label",children:c("字体颜色")}),
12
+ /* @__PURE__ */e("div",{className:"color-grid",role:"group","aria-label":c("字体颜色"),children:N.map(t=>/* @__PURE__ */e("button",{type:"button",className:"color-choice"+(n===t.value?" selected":""),"aria-label":c("字体颜色:{0}",{0:c(t.name)}),title:c("字体颜色:{0}",{0:c(t.name)}),"aria-pressed":n===t.value,onClick:()=>l(t.value),children:/* @__PURE__ */e("span",{className:"font-sample",style:documentSwatchStyle("text",t.value),children:"A"})},t.name))})]}),
13
13
  /* @__PURE__ */t("div",{className:"color-section",children:[
14
- /* @__PURE__ */e("div",{className:"color-label",children:s("背景颜色")}),
15
- /* @__PURE__ */e("div",{className:"color-grid",role:"group","aria-label":s("背景颜色"),children:D.map(t=>/* @__PURE__ */e("button",{type:"button",className:`color-choice background-choice${l===t.value?" selected":""}${null===t.value?" no-background":""}`,style:t.value?{background:t.value}:void 0,"aria-label":s("背景颜色:{0}",{0:s(t.name)}),title:s("背景颜色:{0}",{0:s(t.name)}),"aria-pressed":l===t.value,onClick:()=>i(t.value),children:null===t.value&&/* @__PURE__ */e("span",{className:"clear-stroke","aria-hidden":"true"})},t.name))})]}),
16
- /* @__PURE__ */e(ke,{variant:"outline",block:!0,onClick:a,children:s("恢复默认")}),c&&/* @__PURE__ */e(ke,{variant:"text",block:!0,onClick:c,children:s("关闭")})]})}function textColorStyle(e){const t=S("text",e).style;if(!t)return{};const n=t.indexOf(":");return{color:t.slice(n+1).trim()}}function SelectionToolbar({editor:l,x:r,y:i,canComment:a,onRequestComment:c,onRequestLink:s,onRemoveLink:u}){const d=o().text,[m,p]=v("none"),active=e=>l.isActive(e),h="string"==typeof l.getAttributes("textStyle").color?l.getAttributes("textStyle").color:null,g="string"==typeof l.getAttributes("highlight").color?l.getAttributes("highlight").color:null,f=active("link")||(()=>{const{from:e,to:t}=l.state.selection;try{return l.state.doc.rangeHasMark(e,t,l.schema.marks.link)}catch{return!1}})(),chain=()=>l.chain().focus(),b=[{name:"bold",icon:"bold",label:d("加粗")},{name:"italic",icon:"italic",label:d("斜体")},{name:"strike",icon:"strike",label:d("删除线")},{name:"underline",icon:"underline",label:d("下划线")},{name:"code",icon:"inline-code",label:d("行内代码")}];/* @__PURE__ */
17
- return t("div",{className:"sel-toolbar",role:"toolbar","aria-label":d("文字格式"),style:{left:r,top:i},onMouseDown:e=>e.preventDefault(),children:[b.map(t=>/* @__PURE__ */e("button",{type:"button",className:"tb-btn"+(active(t.name)?" on":""),"aria-label":t.label,"aria-pressed":active(t.name),title:t.label,onClick:()=>function toggleMark(e){const t=chain();"bold"===e?t.toggleBold().run():"italic"===e?t.toggleItalic().run():"strike"===e?t.toggleStrike().run():"underline"===e?t.toggleUnderline().run():t.toggleCode().run(),p("none")}(t.name),children:/* @__PURE__ */e(Ce,{name:t.icon,size:20})},t.name)),
18
- /* @__PURE__ */e("button",{type:"button",className:"tb-btn"+(f?" on":""),"aria-label":d(f?"编辑链接":"添加链接"),title:d(f?"编辑链接":"添加链接"),"aria-haspopup":"dialog",onClick:()=>null==s?void 0:s(),children:/* @__PURE__ */e(Ce,{name:"format-link",size:20})}),f&&/* @__PURE__ */e("button",{type:"button",className:"tb-btn","aria-label":d("取消链接"),title:d("取消链接"),onClick:()=>null==u?void 0:u(),children:/* @__PURE__ */e(Ce,{name:"unlink",size:20})}),
14
+ /* @__PURE__ */e("div",{className:"color-label",children:c("背景颜色")}),
15
+ /* @__PURE__ */e("div",{className:"color-grid",role:"group","aria-label":c("背景颜色"),children:D.map(t=>/* @__PURE__ */e("button",{type:"button",className:`color-choice background-choice${r===t.value?" selected":""}${null===t.value?" no-background":""}`,style:documentSwatchStyle("highlight",t.value),"aria-label":c("背景颜色:{0}",{0:c(t.name)}),title:c("背景颜色:{0}",{0:c(t.name)}),"aria-pressed":r===t.value,onClick:()=>i(t.value),children:null===t.value&&/* @__PURE__ */e("span",{className:"color-transparency-grid","aria-hidden":"true"})},t.name))})]}),
16
+ /* @__PURE__ */e(xe,{variant:"outline",block:!0,onClick:a,children:c("恢复默认")}),s&&/* @__PURE__ */e(xe,{variant:"text",block:!0,onClick:s,children:c("关闭")})]})}function SelectionToolbar({editor:r,x:l,y:i,canComment:a,onRequestComment:s,onRequestLink:c,onRemoveLink:u}){const d=o().text,[m,p]=v("none"),g=h(null),b=h(null),[w,y]=v(l);f(()=>{const measure=()=>{const e=b.current,t=null==e?void 0:e.closest(".editor-shell");if(!e||!t)return;const n=t.getBoundingClientRect(),o=e.getBoundingClientRect().width;y(Math.max(8-n.left,Math.min(l,innerWidth-8-o-n.left)))};return measure(),window.addEventListener("resize",measure),()=>window.removeEventListener("resize",measure)},[l,i]);const active=e=>r.isActive(e),k="string"==typeof r.getAttributes("textStyle").color?r.getAttributes("textStyle").color:null,x="string"==typeof r.getAttributes("highlight").color?r.getAttributes("highlight").color:null,C=active("link")||(()=>{const{from:e,to:t}=r.state.selection;try{return r.state.doc.rangeHasMark(e,t,r.schema.marks.link)}catch{return!1}})(),chain=()=>r.chain().focus(),E=[{name:"bold",icon:"bold",label:d("加粗")},{name:"italic",icon:"italic",label:d("斜体")},{name:"strike",icon:"strike",label:d("删除线")},{name:"underline",icon:"underline",label:d("下划线")},{name:"code",icon:"inline-code",label:d("行内代码")}];/* @__PURE__ */
17
+ return t("div",{ref:b,className:"sel-toolbar",role:"toolbar","aria-label":d("文字格式"),style:{left:w,top:i},onMouseDown:e=>e.preventDefault(),children:[E.map(t=>/* @__PURE__ */e("button",{type:"button",className:"tb-btn"+(active(t.name)?" on":""),"aria-label":t.label,"aria-pressed":active(t.name),title:t.label,onClick:()=>function toggleMark(e){const t=chain();"bold"===e?t.toggleBold().run():"italic"===e?t.toggleItalic().run():"strike"===e?t.toggleStrike().run():"underline"===e?t.toggleUnderline().run():t.toggleCode().run(),p("none")}(t.name),children:/* @__PURE__ */e(Ce,{name:t.icon,size:20})},t.name)),
18
+ /* @__PURE__ */e("button",{type:"button",className:"tb-btn"+(C?" on":""),"aria-label":d(C?"编辑链接":"添加链接"),title:d(C?"编辑链接":"添加链接"),"aria-haspopup":"dialog",onClick:()=>null==c?void 0:c(),children:/* @__PURE__ */e(Ce,{name:"format-link",size:20})}),C&&/* @__PURE__ */e("button",{type:"button",className:"tb-btn","aria-label":d("取消链接"),title:d("取消链接"),onClick:()=>null==u?void 0:u(),children:/* @__PURE__ */e(Ce,{name:"unlink",size:20})}),
19
19
  /* @__PURE__ */e("span",{className:"tb-sep","aria-hidden":"true"}),
20
20
  /* @__PURE__ */t("div",{className:"tb-color-wrap",children:[
21
- /* @__PURE__ */e("button",{type:"button",className:"tb-btn"+("color"===m?" on":""),title:d("文字与背景颜色"),"aria-label":d("文字与背景颜色"),"aria-expanded":"color"===m,onClick:()=>p("color"===m?"none":"color"),children:/* @__PURE__ */e(Ce,{name:"text-color",size:20,style:colorLetterStyle(h)})}),"color"===m&&/* @__PURE__ */e("div",{className:"tb-panel",children:/* @__PURE__ */e(DocumentColorPanel,{textColor:h,highlightColor:g,onTextColor:e=>{const t=chain();e?t.setMark("textStyle",{color:e}).run():t.unsetMark("textStyle").run()},onHighlightColor:e=>{const t=chain();e?t.setMark("highlight",{color:e}).run():t.unsetMark("highlight").run()},onReset:()=>{chain().unsetMark("textStyle").unsetMark("highlight").run(),p("none")},onClose:()=>p("none")})})]}),a&&/* @__PURE__ */t(n,{children:[
21
+ /* @__PURE__ */e("button",{ref:g,type:"button",className:"tb-btn"+("color"===m?" on":""),title:d("文字与背景颜色"),"aria-label":d("文字与背景颜色"),"aria-expanded":"color"===m,onClick:()=>p("color"===m?"none":"color"),children:/* @__PURE__ */e(Ce,{name:"text-color",size:20,style:colorLetterStyle(k)})}),"color"===m&&/* @__PURE__ */e(Pe,{anchor:g.current,label:d("文档颜色"),className:"document-color-popover",onClose:()=>p("none"),gap:8,children:/* @__PURE__ */e(DocumentColorPanel,{textColor:k,highlightColor:x,onTextColor:e=>{const t=chain();e?t.setMark("textStyle",{color:e}).run():t.unsetMark("textStyle").run()},onHighlightColor:e=>{const t=chain();e?t.setMark("highlight",{color:e}).run():t.unsetMark("highlight").run()},onReset:()=>{chain().unsetMark("textStyle").unsetMark("highlight").run(),p("none")}})})]}),a&&/* @__PURE__ */t(n,{children:[
22
22
  /* @__PURE__ */e("span",{className:"tb-sep","aria-hidden":"true"}),
23
- /* @__PURE__ */e("button",{type:"button",className:"tb-btn","aria-label":d("评论选中的文字"),title:d("评论选中的文字"),onClick:()=>null==c?void 0:c(),children:/* @__PURE__ */e(Ce,{name:"comment",size:20})})]})]})}function colorLetterStyle(e){const t=S("text",e).style;if(!t)return{};const n=t.indexOf(":");return{[t.slice(0,n).trim()]:t.slice(n+1).trim()}}function clampGrid(e){const t=Math.floor(Number(e));return Number.isNaN(t)?1:Math.min(Math.max(t,1),8)}function fitRange(e,t,n=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY){let l=e;return Number.isFinite(o)&&l+t>o&&(l=o-t),Number.isFinite(n)&&l<n&&(l=n),Math.round(l)}const Ge=[{id:"text",label:"正文",hint:"/text",group:"basic",icon:"text",convertible:!0,keywords:["text","paragraph","正文","zhengwen","普通文本"],run:({chain:e})=>e().setParagraph().run()},{id:"h1",convertible:!0,label:"一级标题",hint:"/h1",group:"basic",icon:"h1",keywords:["h1","标题","biaoti","heading","yijibiaoti"],run:({chain:e})=>e().setHeading({level:1}).run()},{id:"h2",convertible:!0,label:"二级标题",hint:"/h2",group:"basic",icon:"h2",keywords:["h2","标题","biaoti","erjibiaoti"],run:({chain:e})=>e().setHeading({level:2}).run()},{id:"h3",convertible:!0,label:"三级标题",hint:"/h3",group:"basic",icon:"h3",keywords:["h3","标题","biaoti","sanjibiaoti"],run:({chain:e})=>e().setHeading({level:3}).run()},{id:"h4",convertible:!0,label:"四级标题",hint:"/h4",group:"basic",icon:"h4",keywords:["h4","标题","biaoti","sijibiaoti"],run:({chain:e})=>e().setHeading({level:4}).run()},{id:"h5",convertible:!0,label:"五级标题",hint:"/h5",group:"basic",icon:"h5",keywords:["h5","标题","biaoti","wujibiaoti"],run:({chain:e})=>e().setHeading({level:5}).run()},{id:"h6",convertible:!0,label:"六级标题",hint:"/h6",group:"basic",icon:"h6",keywords:["h6","标题","biaoti","liujibiaoti"],run:({chain:e})=>e().setHeading({level:6}).run()},{id:"ordered",convertible:!0,label:"有序列表",hint:"/ol",group:"basic",icon:"ordered-list",keywords:["list","ol","列表","liebiao","youxuliebiao"],run:({chain:e})=>e().toggleOrderedList().run()},{id:"bullet",convertible:!0,label:"无序列表",hint:"/ul",group:"basic",icon:"bullet-list",keywords:["list","ul","列表","liebiao","wuxuliebiao"],run:({chain:e})=>e().toggleBulletList().run()},{id:"quote",convertible:!0,label:"引用",hint:"/quote",group:"basic",icon:"quote",keywords:["quote","引用","yinyong"],run:({chain:e})=>e().toggleBlockquote().run()},{id:"code",convertible:!0,label:"代码块",hint:"/code",group:"basic",icon:"code",keywords:["code","代码","daima","daimakuai"],run:({chain:e})=>e().toggleCodeBlock().run()},{id:"hr",label:"分割线",hint:"/hr",group:"basic",icon:"divider",keywords:["hr","divider","分割线","fengexian"],run:({chain:e})=>e().setHorizontalRule().run()},{id:"link",label:"链接",hint:"/link",group:"basic",icon:"link",keywords:["link","链接","lianjie","url"],run:({chain:e})=>{const t="https://";e().insertContent({type:"text",text:t,marks:[{type:"link",attrs:{href:t}}]}).run()}},{id:"mindmap",label:"思维导图",hint:"/mindmap",group:"common",icon:"mind-map",keywords:["mindmap","mind","思维导图","导图","siweidaotu","脑图"],run:({chain:e})=>e().insertContent([Be(),{type:"paragraph"}]).run()},{id:"task",convertible:!0,label:"任务",hint:"/todo",group:"common",icon:"task",keywords:["task","todo","待办","daiban","renwu","checkbox"],run:({chain:e})=>e().toggleTaskList().run()},{id:"image",label:"图片",hint:"/image",group:"common",icon:"image",keywords:["image","img","图片","tupian","photo"],run:({requestPickFile:e})=>null==e?void 0:e("image")},{id:"file",label:"上传文件",hint:"/file",group:"common",icon:"file",keywords:["file","文件","wenjian","上传","attachment"],run:({requestPickFile:e})=>null==e?void 0:e("file")},{id:"video",label:"嵌入视频",hint:"/video",group:"common",icon:"file",keywords:["video","youtube","bilibili","视频","shipin","b站"],run:({requestVideo:e})=>null==e?void 0:e()},{id:"table",label:"表格",hint:"/table",group:"common",icon:"table",keywords:["table","表格","biaoge"],panel:"table",run:({chain:e,panelValue:t})=>e().insertTable({rows:clampGrid((null==t?void 0:t.rows)??3),cols:clampGrid((null==t?void 0:t.cols)??3),withHeaderRow:!0}).run()},{id:"columns",label:"分栏",hint:"/columns",group:"common",icon:"columns",keywords:["columns","column","分栏","fenlan","多栏","duolan","layout"],panel:"columns",run:({chain:e,panelValue:t})=>{e().insertContent(T((null==t?void 0:t.count)??2)).run()}},{id:"callout",convertible:!0,label:"高亮块",hint:"/callout",group:"common",icon:"callout",keywords:["callout","highlight","高亮","gaoliang","提示块","tishikuai"],run:({chain:e})=>{e().insertContent({type:"callout",attrs:{tone:"info"},content:[{type:"paragraph"}]}).run()}},{id:"math",label:"公式",hint:"/math",group:"common",icon:"math",keywords:["math","formula","公式","gongshi","latex","katex"],run:({chain:e})=>{e().insertContent({type:"mathBlock",attrs:{latex:"E = mc^2"}}).run()}},{id:"page",label:"子文档",hint:"/page",group:"common",icon:"page",keywords:["page","子文档","ziwendang","页面","yemian","link","引用"],run:({requestPickPage:e})=>null==e?void 0:e()}],Qe=[{id:"basic",label:"基础"},{id:"common",label:"常用"}];function InsertPicker({mode:n,x:l,y:r,yBottom:i,boundTop:a,boundBottom:c,onPick:s,onClose:u}){const d=o().text,m=h(null),[p,g]=v(r),[b,w]=v({rows:3,cols:3}),[y,k]=v(2);f(()=>{const e=m.current;e&&g(function computePanelTop(e,t,n=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,l=e+t){const fits=e=>(!Number.isFinite(n)||e>=n)&&(!Number.isFinite(o)||e+t<=o),r=e;if(fits(r))return Math.round(r);const i=l-t;return fits(i)?Math.round(i):Math.round(fitRange(r,t,n,o))}(r,e.offsetHeight,a,c,i??r+e.offsetHeight))},[n,r,i,a,c]);const C=function buildGridCells(e,t){const n=[];for(let o=1;o<=8;o+=1)for(let l=1;l<=8;l+=1)n.push({row:o,col:l,on:o<=e&&l<=t});return n}(b.rows,b.cols);/* @__PURE__ */
24
- return t("div",{ref:m,className:"insert-picker",role:"dialog","aria-label":d("table"===n?"选择表格尺寸":"选择分栏栏数"),style:{left:l,top:p},onMouseDown:e=>e.preventDefault(),children:[
23
+ /* @__PURE__ */e("button",{type:"button",className:"tb-btn","aria-label":d("评论选中的文字"),title:d("评论选中的文字"),onClick:()=>null==s?void 0:s(),children:/* @__PURE__ */e(Ce,{name:"comment",size:20})})]})]})}function colorLetterStyle(e){const t=S("text",e).style;if(!t)return{};const n=t.indexOf(":");return{[t.slice(0,n).trim()]:t.slice(n+1).trim()}}function clampGrid(e){const t=Math.floor(Number(e));return Number.isNaN(t)?1:Math.min(Math.max(t,1),8)}function fitRange(e,t,n=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY){let r=e;return Number.isFinite(o)&&r+t>o&&(r=o-t),Number.isFinite(n)&&r<n&&(r=n),Math.round(r)}const tt=[{id:"text",label:"正文",hint:"/text",group:"basic",icon:"text",convertible:!0,keywords:["text","paragraph","正文","zhengwen","普通文本"],run:({chain:e})=>e().setParagraph().run()},{id:"h1",convertible:!0,label:"一级标题",hint:"/h1",group:"basic",icon:"h1",keywords:["h1","标题","biaoti","heading","yijibiaoti"],run:({chain:e})=>e().setHeading({level:1}).run()},{id:"h2",convertible:!0,label:"二级标题",hint:"/h2",group:"basic",icon:"h2",keywords:["h2","标题","biaoti","erjibiaoti"],run:({chain:e})=>e().setHeading({level:2}).run()},{id:"h3",convertible:!0,label:"三级标题",hint:"/h3",group:"basic",icon:"h3",keywords:["h3","标题","biaoti","sanjibiaoti"],run:({chain:e})=>e().setHeading({level:3}).run()},{id:"h4",convertible:!0,label:"四级标题",hint:"/h4",group:"basic",icon:"h4",keywords:["h4","标题","biaoti","sijibiaoti"],run:({chain:e})=>e().setHeading({level:4}).run()},{id:"h5",convertible:!0,label:"五级标题",hint:"/h5",group:"basic",icon:"h5",keywords:["h5","标题","biaoti","wujibiaoti"],run:({chain:e})=>e().setHeading({level:5}).run()},{id:"h6",convertible:!0,label:"六级标题",hint:"/h6",group:"basic",icon:"h6",keywords:["h6","标题","biaoti","liujibiaoti"],run:({chain:e})=>e().setHeading({level:6}).run()},{id:"ordered",convertible:!0,label:"有序列表",hint:"/ol",group:"basic",icon:"ordered-list",keywords:["list","ol","列表","liebiao","youxuliebiao"],run:({chain:e})=>e().toggleOrderedList().run()},{id:"bullet",convertible:!0,label:"无序列表",hint:"/ul",group:"basic",icon:"bullet-list",keywords:["list","ul","列表","liebiao","wuxuliebiao"],run:({chain:e})=>e().toggleBulletList().run()},{id:"quote",convertible:!0,label:"引用",hint:"/quote",group:"basic",icon:"quote",keywords:["quote","引用","yinyong"],run:({chain:e})=>e().toggleBlockquote().run()},{id:"code",convertible:!0,label:"代码块",hint:"/code",group:"basic",icon:"code",keywords:["code","代码","daima","daimakuai"],run:({chain:e})=>e().toggleCodeBlock().run()},{id:"hr",label:"分割线",hint:"/hr",group:"basic",icon:"divider",keywords:["hr","divider","分割线","fengexian"],run:({chain:e})=>e().setHorizontalRule().run()},{id:"link",label:"链接",hint:"/link",group:"basic",icon:"link",keywords:["link","链接","lianjie","url"],run:({chain:e})=>{const t="https://";e().insertContent({type:"text",text:t,marks:[{type:"link",attrs:{href:t}}]}).run()}},{id:"mindmap",label:"思维导图",hint:"/mindmap",group:"common",icon:"mind-map",keywords:["mindmap","mind","思维导图","导图","siweidaotu","脑图"],run:({chain:e})=>e().command(({editor:e,commands:t})=>t.insertContent([pe(Re(e)),{type:"paragraph"}])).run()},{id:"task",convertible:!0,label:"任务",hint:"/todo",group:"common",icon:"task",keywords:["task","todo","待办","daiban","renwu","checkbox"],run:({chain:e})=>e().toggleTaskList().run()},{id:"image",label:"图片",hint:"/image",group:"common",icon:"image",keywords:["image","img","图片","tupian","photo"],run:({requestPickFile:e})=>null==e?void 0:e("image")},{id:"file",label:"上传文件",hint:"/file",group:"common",icon:"file",keywords:["file","文件","wenjian","上传","attachment"],run:({requestPickFile:e})=>null==e?void 0:e("file")},{id:"video",label:"嵌入视频",hint:"/video",group:"common",icon:"file",keywords:["video","youtube","bilibili","视频","shipin","b站"],run:({requestVideo:e})=>null==e?void 0:e()},{id:"table",label:"表格",hint:"/table",group:"common",icon:"table",keywords:["table","表格","biaoge"],panel:"table",run:({chain:e,panelValue:t})=>e().insertTable({rows:clampGrid((null==t?void 0:t.rows)??3),cols:clampGrid((null==t?void 0:t.cols)??3),withHeaderRow:!0}).run()},{id:"columns",label:"分栏",hint:"/columns",group:"common",icon:"columns",keywords:["columns","column","分栏","fenlan","多栏","duolan","layout"],panel:"columns",run:({chain:e,panelValue:t})=>{e().insertContent(T((null==t?void 0:t.count)??2)).run()}},{id:"callout",convertible:!0,label:"高亮块",hint:"/callout",group:"common",icon:"callout",keywords:["callout","highlight","高亮","gaoliang","提示块","tishikuai"],run:({chain:e})=>{e().insertContent({type:"callout",attrs:{tone:"info"},content:[{type:"paragraph"}]}).run()}},{id:"math",label:"公式",hint:"/math",group:"common",icon:"math",keywords:["math","formula","公式","gongshi","latex","katex"],run:({chain:e})=>{e().insertContent({type:"mathBlock",attrs:{latex:"E = mc^2"}}).run()}},{id:"page",label:"子文档",hint:"/page",group:"common",icon:"page",keywords:["page","子文档","ziwendang","页面","yemian","link","引用"],run:({requestPickPage:e})=>null==e?void 0:e()}],nt=[{id:"basic",label:"基础"},{id:"common",label:"常用"}];function InsertPicker({mode:n,x:r,y:l,yBottom:i,boundTop:a,boundBottom:s,onPick:c,onClose:u}){const d=o().text,m=h(null),[p,f]=v(l),[b,w]=v({rows:3,cols:3}),[y,k]=v(2);g(()=>{const e=m.current;e&&f(function computePanelTop(e,t,n=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,r=e+t){const fits=e=>(!Number.isFinite(n)||e>=n)&&(!Number.isFinite(o)||e+t<=o),l=e;if(fits(l))return Math.round(l);const i=r-t;return fits(i)?Math.round(i):Math.round(fitRange(l,t,n,o))}(l,e.offsetHeight,a,s,i??l+e.offsetHeight))},[n,l,i,a,s]);const x=function buildGridCells(e,t){const n=[];for(let o=1;o<=8;o+=1)for(let r=1;r<=8;r+=1)n.push({row:o,col:r,on:o<=e&&r<=t});return n}(b.rows,b.cols);/* @__PURE__ */
24
+ return t("div",{ref:m,className:"insert-picker",role:"dialog","aria-label":d("table"===n?"选择表格尺寸":"选择分栏栏数"),style:{left:r,top:p},onMouseDown:e=>e.preventDefault(),children:[
25
25
  /* @__PURE__ */t("div",{className:"ip-head",children:[
26
26
  /* @__PURE__ */e("span",{children:d("table"===n?"插入表格":"选择栏数")}),
27
- /* @__PURE__ */e("span",{className:"ip-dim",children:"table"===n?`${b.rows} x ${b.cols}`:d("{0} 栏",{0:y})})]}),/* @__PURE__ */e("div","table"===n?{className:"ip-grid",children:C.map(t=>/* @__PURE__ */e("button",{type:"button",className:"ip-cell"+(t.on?" on":""),"aria-label":d("{0} 行 {1} 列",{0:t.row,1:t.col}),onMouseEnter:()=>w({rows:t.row,cols:t.col}),onFocus:()=>w({rows:t.row,cols:t.col}),onClick:()=>s({rows:t.row,cols:t.col})},`${t.row}-${t.col}`))}:{className:"ip-counts",children:Array.from({length:5},(e,t)=>t+1).map(n=>/* @__PURE__ */t("button",{type:"button",className:"ip-count"+(y===n?" on":""),"aria-label":d("{0} 栏",{0:n}),onMouseEnter:()=>k(n),onClick:()=>s({count:n}),children:[
27
+ /* @__PURE__ */e("span",{className:"ip-dim",children:"table"===n?`${b.rows} x ${b.cols}`:d("{0} 栏",{0:y})})]}),/* @__PURE__ */e("div","table"===n?{className:"ip-grid",children:x.map(t=>/* @__PURE__ */e("button",{type:"button",className:"ip-cell"+(t.on?" on":""),"aria-label":d("{0} 行 {1} 列",{0:t.row,1:t.col}),onMouseEnter:()=>w({rows:t.row,cols:t.col}),onFocus:()=>w({rows:t.row,cols:t.col}),onClick:()=>c({rows:t.row,cols:t.col})},`${t.row}-${t.col}`))}:{className:"ip-counts",children:Array.from({length:5},(e,t)=>t+1).map(n=>/* @__PURE__ */t("button",{type:"button",className:"ip-count"+(y===n?" on":""),"aria-label":d("{0} 栏",{0:n}),onMouseEnter:()=>k(n),onClick:()=>c({count:n}),children:[
28
28
  /* @__PURE__ */e("span",{className:"ip-count-box",children:Array.from({length:n},(t,n)=>/* @__PURE__ */e("span",{className:"ip-count-bar"},n))}),
29
29
  /* @__PURE__ */e("span",{className:"ip-count-num",children:n})]},n))}),
30
- /* @__PURE__ */e("button",{type:"button",className:"ip-close","aria-label":d("关闭参数面板"),onClick:u,children:/* @__PURE__ */e(Ce,{name:"x",size:14})})]})}function SlashMenu({editor:n,from:l,query:r,x:i,y:a,onClose:c,onPickFile:s,onPickPage:u,onPickVideo:d}){const m=o(),p=m.text,g=b(()=>function filterBlockCommands(e,t=e=>e){const n=e.trim().toLowerCase();return n?Ge.filter(e=>e.label.toLowerCase().includes(n)||t(e.label).toLowerCase().includes(n)||e.hint.toLowerCase().includes(n)||e.keywords.some(e=>e.includes(n)||e.startsWith(n))):Ge}(r,p),[r,m.version]),w=b(()=>function groupOf(e){return Qe.map(t=>({...t,items:e.filter(e=>e.group===t.id)})).filter(e=>e.items.length>0)}(g),[g]),[y,k]=v(0),[C,x]=v(null),[E,M]=v(0),[N,L]=v(0),[D,S]=v(274),[A,T]=v({top:0,bottom:0}),[I,P]=v(a),R=h(null),z=h(null),H=h(null),O=h(null),q=h(!1),flatIndex=e=>g.findIndex(t=>t.id===e.id);function openPanel(e){var t,n,o;if(!(null==e?void 0:e.panel))return void x(null);if((null==C?void 0:C.id)===e.id)return;x(e);const l=null==(t=z.current)?void 0:t.querySelectorAll("li")[flatIndex(e)],r=null==(n=H.current)?void 0:n.getBoundingClientRect();if(!l||!r)return;const i=l.getBoundingClientRect();if(i.bottom<=r.top||i.top>=r.bottom)return void x(null);if(!R.current)return;const a=i.top-R.current.getBoundingClientRect().top;M(a),L(a+i.height),S(((null==(o=O.current)?void 0:o.getBoundingClientRect().width)??268)+6)}function choose(e,t){if(!n.isEditable||n.isDestroyed)return;if(l<0||l>n.state.selection.from)return;const o={from:l,to:n.state.selection.from};["image","file","page","video"].includes(e.id)&&o.to>o.from&&n.chain().deleteRange(o).run(),e.run({chain:()=>{const e=n.chain().focus();return o.to>o.from?e.deleteRange(o):e},requestPickFile:s,requestPickPage:u,requestVideo:d,panelValue:t}),B(n.view),c()}function activate(e){e.panel?openPanel(e):choose(e)}function keydown(e){var t;if(!Ie(e)&&n.view.dom.contains(e.target)){if("Escape"===e.key)return e.preventDefault(),e.stopImmediatePropagation(),void(C?x(null):(B(n.view),c()));if(g.length)if((["ArrowDown","ArrowUp","Enter"].includes(e.key)||"ArrowRight"===e.key&&(null==(t=g[y])?void 0:t.panel))&&e.stopImmediatePropagation(),"ArrowDown"===e.key)e.preventDefault(),q.current=!0,x(null),k((y+1)%g.length);else if("ArrowUp"===e.key)e.preventDefault(),q.current=!0,x(null),k((y-1+g.length)%g.length);else if("Enter"===e.key){e.preventDefault();const t=g[y];t&&(null==C?void 0:C.id)===t.id?choose(t):t&&activate(t)}else if("ArrowRight"===e.key){const t=g[y];(null==t?void 0:t.panel)&&(e.preventDefault(),openPanel(t))}}}return f(()=>{k(0),x(null)},[r]),f(()=>{const measure=()=>{var e;const t=R.current,n=z.current;if(!t||!n)return;const o=(null==(e=t.parentElement)?void 0:e.getBoundingClientRect().top)??0,l=o+a,r=Math.round(Math.max(8,Math.min(l,window.innerHeight-8-n.offsetHeight)));P(r-o),T({top:8-r,bottom:window.innerHeight-8-r})},e=requestAnimationFrame(measure);return window.addEventListener("resize",measure),window.addEventListener("scroll",measure,!0),()=>{cancelAnimationFrame(e),window.removeEventListener("resize",measure),window.removeEventListener("scroll",measure,!0)}},[a,r,g.length]),f(()=>{var e;if(!q.current)return;q.current=!1;const t=null==(e=z.current)?void 0:e.querySelectorAll("li")[y],n=O.current;if(!t||!n)return;const o=t.offsetTop,l=o+t.offsetHeight;o<n.scrollTop?n.scrollTop=o:l>n.scrollTop+n.clientHeight&&(n.scrollTop=l-n.clientHeight)},[y,g]),f(()=>{const e=n.view.dom;return e.addEventListener("keydown",keydown,!0),()=>e.removeEventListener("keydown",keydown,!0)}),f(()=>{const outside=e=>{var t;e.target instanceof Node&&!(null==(t=R.current)?void 0:t.contains(e.target))&&!n.view.dom.contains(e.target)&&c()};return document.addEventListener("pointerdown",outside),()=>document.removeEventListener("pointerdown",outside)},[c,n]),/* @__PURE__ */t("div",{ref:R,className:"slash-anchor",style:{left:i,top:I},children:[
30
+ /* @__PURE__ */e("button",{type:"button",className:"ip-close","aria-label":d("关闭参数面板"),onClick:u,children:/* @__PURE__ */e(Ce,{name:"x",size:14})})]})}function SlashMenu({editor:n,from:r,query:l,x:i,y:a,onClose:s,onPickFile:c,onPickPage:u,onPickVideo:d}){const m=o(),p=m.text,f=b(()=>function filterBlockCommands(e,t=e=>e){const n=e.trim().toLowerCase();return n?tt.filter(e=>e.label.toLowerCase().includes(n)||t(e.label).toLowerCase().includes(n)||e.hint.toLowerCase().includes(n)||e.keywords.some(e=>e.includes(n)||e.startsWith(n))):tt}(l,p),[l,m.version]),w=b(()=>function groupOf(e){return nt.map(t=>({...t,items:e.filter(e=>e.group===t.id)})).filter(e=>e.items.length>0)}(f),[f]),[y,k]=v(0),[x,C]=v(null),[E,M]=v(0),[L,N]=v(0),[D,S]=v(274),[A,T]=v({top:0,bottom:0}),[I,P]=v(a),R=h(null),z=h(null),H=h(null),O=h(null),q=h(!1),flatIndex=e=>f.findIndex(t=>t.id===e.id);function openPanel(e){var t,n,o;if(!(null==e?void 0:e.panel))return void C(null);if((null==x?void 0:x.id)===e.id)return;C(e);const r=null==(t=z.current)?void 0:t.querySelectorAll("li")[flatIndex(e)],l=null==(n=H.current)?void 0:n.getBoundingClientRect();if(!r||!l)return;const i=r.getBoundingClientRect();if(i.bottom<=l.top||i.top>=l.bottom)return void C(null);if(!R.current)return;const a=i.top-R.current.getBoundingClientRect().top;M(a),N(a+i.height),S(((null==(o=O.current)?void 0:o.getBoundingClientRect().width)??268)+6)}function choose(e,t){if(!n.isEditable||n.isDestroyed)return;if(r<0||r>n.state.selection.from)return;const o={from:r,to:n.state.selection.from};["image","file","page","video"].includes(e.id)&&o.to>o.from&&n.chain().deleteRange(o).run(),e.run({chain:()=>{const e=n.chain().focus();return o.to>o.from?e.deleteRange(o):e},requestPickFile:c,requestPickPage:u,requestVideo:d,panelValue:t}),B(n.view),s()}function activate(e){e.panel?openPanel(e):choose(e)}function keydown(e){var t;if(!He(e)&&n.view.dom.contains(e.target)){if("Escape"===e.key)return e.preventDefault(),e.stopImmediatePropagation(),void(x?C(null):(B(n.view),s()));if(f.length)if((["ArrowDown","ArrowUp","Enter"].includes(e.key)||"ArrowRight"===e.key&&(null==(t=f[y])?void 0:t.panel))&&e.stopImmediatePropagation(),"ArrowDown"===e.key)e.preventDefault(),q.current=!0,C(null),k((y+1)%f.length);else if("ArrowUp"===e.key)e.preventDefault(),q.current=!0,C(null),k((y-1+f.length)%f.length);else if("Enter"===e.key){e.preventDefault();const t=f[y];t&&(null==x?void 0:x.id)===t.id?choose(t):t&&activate(t)}else if("ArrowRight"===e.key){const t=f[y];(null==t?void 0:t.panel)&&(e.preventDefault(),openPanel(t))}}}return g(()=>{k(0),C(null)},[l]),g(()=>{const measure=()=>{var e;const t=R.current,n=z.current;if(!t||!n)return;const o=(null==(e=t.parentElement)?void 0:e.getBoundingClientRect().top)??0,r=o+a,l=Math.round(Math.max(8,Math.min(r,window.innerHeight-8-n.offsetHeight)));P(l-o),T({top:8-l,bottom:window.innerHeight-8-l})},e=requestAnimationFrame(measure);return window.addEventListener("resize",measure),window.addEventListener("scroll",measure,!0),()=>{cancelAnimationFrame(e),window.removeEventListener("resize",measure),window.removeEventListener("scroll",measure,!0)}},[a,l,f.length]),g(()=>{var e;if(!q.current)return;q.current=!1;const t=null==(e=z.current)?void 0:e.querySelectorAll("li")[y],n=O.current;if(!t||!n)return;const o=t.offsetTop,r=o+t.offsetHeight;o<n.scrollTop?n.scrollTop=o:r>n.scrollTop+n.clientHeight&&(n.scrollTop=r-n.clientHeight)},[y,f]),g(()=>{const e=n.view.dom;return e.addEventListener("keydown",keydown,!0),()=>e.removeEventListener("keydown",keydown,!0)}),g(()=>{const outside=e=>{var t;e.target instanceof Node&&!(null==(t=R.current)?void 0:t.contains(e.target))&&!n.view.dom.contains(e.target)&&s()};return document.addEventListener("pointerdown",outside),()=>document.removeEventListener("pointerdown",outside)},[s,n]),/* @__PURE__ */t("div",{ref:R,className:"slash-anchor",style:{left:i,top:I},children:[
31
31
  /* @__PURE__ */e("div",{ref:z,className:"slash-menu",role:"listbox","aria-label":p("插入内容"),children:/* @__PURE__ */e("div",{ref:H,children:/* @__PURE__ */t("div",{ref:O,className:"slash-content",children:[w.map(n=>/* @__PURE__ */t("div",{children:[
32
32
  /* @__PURE__ */e("div",{className:"slash-group",children:p(n.label)}),
33
33
  /* @__PURE__ */e("ul",{children:n.items.map(n=>{const o=flatIndex(n);/* @__PURE__ */
34
34
  return t("li",{role:"option","aria-selected":o===y,className:o===y?"active":void 0,onMouseMove:()=>{k(o),openPanel(n)},onMouseDown:e=>{e.preventDefault(),activate(n)},children:[
35
35
  /* @__PURE__ */e(Ce,{name:n.icon,size:18}),
36
36
  /* @__PURE__ */e("span",{className:"slash-label",children:p(n.label)}),
37
- /* @__PURE__ */e("span",{className:"slash-hint",children:p(n.hint)}),n.panel&&/* @__PURE__ */e(Ce,{name:"chevron",size:16,className:"slash-chevron"})]},n.id)})})]},n.id)),!g.length&&/* @__PURE__ */e("div",{className:"slash-empty",children:p("无匹配命令")})]})})}),(null==C?void 0:C.panel)&&/* @__PURE__ */e(InsertPicker,{mode:C.panel,x:D,y:E,yBottom:N,boundTop:A.top,boundBottom:A.bottom,onPick:e=>choose(C,e),onClose:()=>x(null)})]})}const Ke=["paragraph","heading","blockquote","codeBlock","bulletList","orderedList","taskList","callout"];function menuBlockRange(e,t){const n=[];e.doc.forEach((e,t)=>n.push({from:t,to:t+e.nodeSize,node:e}));const o=n.find(e=>e.from===t);if(!o)return null;const{from:l,to:r,empty:i}=e.selection,a=!i&&l<o.to&&r>o.from?n.filter(e=>l<e.to&&r>e.from):[o];return{from:a[0].from,to:a.at(-1).to,nodes:a.map(e=>e.node)}}function containerContent(e){const t=1===e.nodes.length?e.nodes[0]:null;return t&&["callout","blockquote"].includes(t.type.name)?t.content:e.nodes}function canConvertMenuBlocks(e,t,n){const o=menuBlockRange(e,t);if(!o)return!1;if("callout"===n||"quote"===n){const t=e.schema.nodes["callout"===n?"callout":"blockquote"];return!!(null==t?void 0:t.validContent(t.create(null,containerContent(o)).content))}if("text"===n&&1===o.nodes.length&&["callout","blockquote"].includes(o.nodes[0].type.name))return!0;if(!["text","h1","h2","h3","h4","h5","h6","bullet","ordered","task","code"].includes(n))return!1;const l=["paragraph","heading","blockquote","codeBlock","bulletList","orderedList","taskList","callout","listItem","taskItem","text","hardBreak"];return o.nodes.every(e=>{if(!l.includes(e.type.name))return!1;let t=!0;return e.descendants(e=>(l.includes(e.type.name)||(t=!1),t)),t})}function deleteTopLevelBlock(e,t){let n=!1;e.doc.forEach((e,o)=>{o===t&&(n=!0)});const o=n?e.doc.nodeAt(t):null;return o?1===e.doc.childCount?e.tr.replaceWith(0,e.doc.content.size,e.schema.nodes.paragraph.create()):e.tr.delete(t,t+o.nodeSize):null}const Ze={width:28,height:28},et={width:48,height:28};function BlockPlus({style:t,expanded:n,onClick:l,onMouseEnter:r,onMouseLeave:i}){const a=o().text;/* @__PURE__ */
38
- return e("button",{type:"button",className:"block-plus","aria-label":a("插入内容"),title:a("在此空行插入内容(表格 / 分栏 / 图片…)"),"aria-expanded":n,"aria-haspopup":"menu",style:t,onMouseEnter:r,onMouseLeave:i,onClick:l,children:/* @__PURE__ */e(Ce,{name:"plus",size:17})})}function typeIcon(e,t){var n;if("heading"===t.type){const o=Number((null==(n=e.state.doc.nodeAt(t.pos))?void 0:n.attrs.level)??1);return`h${Math.min(Math.max(Number.isFinite(o)?o:1,1),6)}`}return{paragraph:"text",image:"image",imageGallery:"image",table:"table",blockquote:"quote",codeBlock:"code",bulletList:"bullet-list",orderedList:"ordered-list",taskList:"task",callout:"callout",columns:"columns",mindMap:"mind-map",fileAttachment:"file",videoEmbed:"file",mathBlock:"math",horizontalRule:"divider",pageLink:"page"}[t.type]??"text"}function BlockChip({editor:n,info:l,style:r,expanded:i,onOpen:a,onOpenFull:c,onMouseEnter:s,onMouseLeave:u,onHandleMouseDown:d}){const m=o().text;/* @__PURE__ */
39
- return t("div",{className:"block-chip",role:"toolbar","aria-label":m("块快捷操作"),style:r,onMouseEnter:s,onMouseLeave:u,children:[
40
- /* @__PURE__ */e("button",{type:"button",className:"chip-btn","aria-label":m("转换为"),title:m("转换为…"),"aria-expanded":i,"aria-haspopup":"menu",onClick:a,children:/* @__PURE__ */e(Ce,{name:typeIcon(n,l),size:17})}),
41
- /* @__PURE__ */e("button",{type:"button",className:"chip-btn chip-grip","aria-label":m("拖动或打开块菜单"),title:i?void 0:m("按住拖动可移动整段;单击打开块菜单"),"aria-expanded":i,"aria-haspopup":"menu",draggable:!1,onMouseDown:e=>d?d(e):e.preventDefault(),onClick:c,children:/* @__PURE__ */e(Ce,{name:"handle",size:17})})]})}function BlockMenu(l){var r,i,a,c,s,m;const p=o().text,{editor:b,info:w}=l,[y,k]=v(l.panelOnly??null),[C,x]=v(!1),[E,M]=v(null),N=b.state.doc.nodeAt(w.pos),chain=()=>{const e=menuBlockRange(b.state,w.pos),t=b.state.selection,n=t instanceof u&&!t.empty&&N&&t.from>=w.pos+1&&t.to<=w.pos+N.nodeSize-1;return b.chain().focus().command(({tr:o})=>(o.setSelection(u.between(o.doc.resolve(n?t.from:((null==e?void 0:e.from)??w.pos)+1),o.doc.resolve(n?t.to:((null==e?void 0:e.to)??w.pos+N.nodeSize)-1))),!0))},S=Ge.filter(e=>e.convertible),A=Ge.filter(e=>"link"!==e.id),B=String((null==(r=null==N?void 0:N.attrs)?void 0:r.textAlign)??"left"),z=!!N&&["paragraph","heading","blockquote","codeBlock","bulletList","orderedList","taskList","callout"].includes(N.type.name),H=h(null),O=h(null),q=h(null),$=h(null),F=h(y);F.current=y;const V=h(E);V.current=E;const W=h(void 0);function cancelSubmenuClose(){clearTimeout(W.current),W.current=void 0}function openSubmenu(e,t){cancelSubmenuClose(),$.current=t,M(null),k(e)}function scheduleSubmenuClose(){l.panelOnly||(cancelSubmenuClose(),W.current=setTimeout(()=>{k(null),M(null)},180))}f(()=>()=>cancelSubmenuClose(),[]);const[Y,j]=v(),[U,_]=v({left:0,top:0});function insertCommand(e,t){if(!N||!b.isEditable||b.isDestroyed)return;const n="insert-below"===l.panelOnly&&N.isTextblock&&0===N.content.size,o=w.pos+N.nodeSize,r=n?{from:w.pos,to:o}:o;if(["image","file","page","video"].includes(e.id))return n?b.commands.setTextSelection(w.pos+1):b.chain().insertContentAt(o,{type:"paragraph"}).setTextSelection(o+1).run(),l.onClose(),void("page"===e.id?l.onPickPage():"video"===e.id?l.onPickVideo():l.onPickFile("image"===e.id?"image":"file"));let i;i=/^h[1-6]$/.test(e.id)?{type:"heading",attrs:{level:Number(e.id.slice(1))}}:"table"===e.id?ze(b.schema,(null==t?void 0:t.rows)??3,(null==t?void 0:t.cols)??3,!0).toJSON():"columns"===e.id?T((null==t?void 0:t.count)??2):"mindmap"===e.id?[He(),{type:"paragraph"}]:["bullet","ordered","task"].includes(e.id)?{type:"bullet"===e.id?"bulletList":"ordered"===e.id?"orderedList":"taskList",content:[{type:"task"===e.id?"taskItem":"listItem",attrs:"task"===e.id?{checked:!1}:void 0,content:[{type:"paragraph"}]}]}:{text:{type:"paragraph"},quote:{type:"blockquote",content:[{type:"paragraph"}]},code:{type:"codeBlock"},hr:{type:"horizontalRule"},callout:{type:"callout",attrs:{tone:"info"},content:[{type:"paragraph"}]},math:{type:"mathBlock",attrs:{latex:"E = mc^2"}}}[e.id],i&&b.chain().focus().insertContentAt(r,i).run(),l.onClose()}async function writeBlockClipboard(){var e;if(!N)return;if("undefined"==typeof ClipboardItem||!(null==(e=navigator.clipboard)?void 0:e.write)){if(!N.isTextblock)throw new Error(p("当前浏览器不支持复制此块的富文本结构"));return void await navigator.clipboard.writeText(N.textContent)}const t=document.createElement("div");t.append(Pe.fromSchema(b.schema).serializeFragment(Re.from(N))),await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([t.innerHTML],{type:"text/html"}),"text/plain":new Blob([N.textContent],{type:"text/plain"})})])}f(()=>{P(b.view,w.pos);const outside=e=>{var t;e.target instanceof Element&&!(null==(t=H.current)?void 0:t.contains(e.target))&&(e.target.closest(".block-chip,.block-plus")||l.onClose())},key=e=>{var t,n,o,r;if(e.isComposing)return;const i=document.activeElement;if("Escape"===e.key&&V.current)return e.preventDefault(),e.stopPropagation(),M(null),void(null==(t=$.current)||t.focus());if("ArrowRight"===e.key&&(null==i?void 0:i.dataset.submenu))return e.preventDefault(),openSubmenu(i.dataset.submenu,i),void requestAnimationFrame(()=>{var e,t;return null==(t=null==(e=q.current)?void 0:e.querySelector('[role="menuitem"]:not(:disabled)'))?void 0:t.focus()});if(!l.panelOnly&&F.current&&("Escape"===e.key||"ArrowLeft"===e.key&&(null==(n=q.current)?void 0:n.contains(i))))return e.preventDefault(),e.stopPropagation(),k(null),M(null),void(null==(o=$.current)||o.focus());if("Escape"===e.key)return e.preventDefault(),e.stopPropagation(),void l.onClose();if(!["ArrowDown","ArrowUp","Home","End"].includes(e.key))return;const a=(null==i?void 0:i.closest('[role="menu"]'))??O.current??q.current,c=Array.from((null==a?void 0:a.querySelectorAll('[role="menuitem"]:not(:disabled)'))??[]);if(!c.length)return;e.preventDefault();const s=c.indexOf(document.activeElement);null==(r=c["Home"===e.key?0:"End"===e.key?c.length-1:(s+("ArrowUp"===e.key?-1:1)+c.length)%c.length])||r.focus()},changed=({transaction:e})=>{e.docChanged&&l.onClose()};return document.addEventListener("pointerdown",outside,!0),document.addEventListener("keydown",key,!0),b.on("transaction",changed),()=>{document.removeEventListener("pointerdown",outside,!0),document.removeEventListener("keydown",key,!0),b.off("transaction",changed),b.isDestroyed||P(b.view,null)}},[b,w.pos,l.panelOnly]),g(()=>{const e=H.current,t=l.panelOnly?q.current:O.current,n=b.view.dom.closest(".editor-shell");if(!e||!t||!n)return;const measure=()=>{var o;const r=n.getBoundingClientRect(),i=t.offsetWidth,a=t.offsetHeight,c=Math.min(Math.max(r.left+w.contentLeft,8),Math.max(8,innerWidth-8-i))-r.left,s=Math.min(Math.max(r.top+w.top,8),Math.max(8,innerHeight-8-a))-r.top;if(_({left:c,top:s}),!l.panelOnly&&q.current){const n=t.getBoundingClientRect(),l=e.getBoundingClientRect(),r=q.current.getBoundingClientRect(),i=function placeBlockSubmenu(e,t,n,o){const l=Math.max(0,o.height-16),r=e.right+6,i=e.left-6-n.width,a=r+n.width<=o.width-8||i<8?r:i;return{left:Math.max(8,Math.min(a,o.width-8-n.width)),top:fitRange(t,Math.min(n.height,l),8,o.height-8),maxHeight:l}}(n,(null==(o=$.current)?void 0:o.getBoundingClientRect().top)??n.top,r,{width:innerWidth,height:innerHeight});j({left:i.left-l.left,top:i.top-l.top,maxHeight:i.maxHeight})}else j(void 0)};measure();const o=new ResizeObserver(measure);return o.observe(t),q.current&&q.current!==t&&o.observe(q.current),window.addEventListener("resize",measure),window.addEventListener("scroll",measure,!0),()=>{o.disconnect(),window.removeEventListener("resize",measure),window.removeEventListener("scroll",measure,!0)}},[b,w.contentLeft,w.top,l.panelOnly,y,U.left,U.top]),f(()=>{k(l.panelOnly??null)},[l.panelOnly,w.pos]);const item=(n,o,l,r={})=>/* @__PURE__ */t("button",{type:"button",role:"menuitem",className:`bm-item${r.active?" active":""}${r.disabled?" disabled":""}${r.danger?" danger":""}`,"aria-haspopup":r.submenu?"menu":void 0,"aria-expanded":r.submenu?y===r.submenu:void 0,"data-submenu":r.submenu,disabled:r.disabled,"aria-disabled":r.disabled||void 0,onMouseEnter:e=>{cancelSubmenuClose(),r.submenu?openSubmenu(r.submenu,e.currentTarget):e.currentTarget.parentElement===O.current?(k(null),M(null)):"insert-below"===y&&($.current=e.currentTarget)},onClick:e=>r.submenu?openSubmenu(r.submenu,e.currentTarget):l(),children:[
37
+ /* @__PURE__ */e("span",{className:"slash-hint",children:p(n.hint)}),n.panel&&/* @__PURE__ */e(Ce,{name:"chevron",size:16,className:"slash-chevron"})]},n.id)})})]},n.id)),!f.length&&/* @__PURE__ */e("div",{className:"slash-empty",children:p("无匹配命令")})]})})}),(null==x?void 0:x.panel)&&/* @__PURE__ */e(InsertPicker,{mode:x.panel,x:D,y:E,yBottom:L,boundTop:A.top,boundBottom:A.bottom,onPick:e=>choose(x,e),onClose:()=>C(null)})]})}const ot=["paragraph","heading","blockquote","codeBlock","bulletList","orderedList","taskList","callout"];function menuBlockRange(e,t){const n=[];e.doc.forEach((e,t)=>n.push({from:t,to:t+e.nodeSize,node:e}));const o=n.find(e=>e.from===t);if(!o)return null;const{from:r,to:l,empty:i}=e.selection,a=!i&&r<o.to&&l>o.from?n.filter(e=>r<e.to&&l>e.from):[o];return{from:a[0].from,to:a.at(-1).to,nodes:a.map(e=>e.node)}}function containerContent(e){const t=1===e.nodes.length?e.nodes[0]:null;return t&&["callout","blockquote"].includes(t.type.name)?t.content:e.nodes}function canConvertMenuBlocks(e,t,n){const o=menuBlockRange(e,t);if(!o)return!1;if("callout"===n||"quote"===n){const t=e.schema.nodes["callout"===n?"callout":"blockquote"];return!!(null==t?void 0:t.validContent(t.create(null,containerContent(o)).content))}if("text"===n&&1===o.nodes.length&&["callout","blockquote"].includes(o.nodes[0].type.name))return!0;if(!["text","h1","h2","h3","h4","h5","h6","bullet","ordered","task","code"].includes(n))return!1;const r=["paragraph","heading","blockquote","codeBlock","bulletList","orderedList","taskList","callout","listItem","taskItem","text","hardBreak"];return o.nodes.every(e=>{if(!r.includes(e.type.name))return!1;let t=!0;return e.descendants(e=>(r.includes(e.type.name)||(t=!1),t)),t})}function deleteTopLevelBlock(e,t){let n=!1;e.doc.forEach((e,o)=>{o===t&&(n=!0)});const o=n?e.doc.nodeAt(t):null;return o?1===e.doc.childCount?e.tr.replaceWith(0,e.doc.content.size,e.schema.nodes.paragraph.create()):e.tr.delete(t,t+o.nodeSize):null}const rt={width:28,height:28},lt={width:48,height:28};function BlockPlus({style:t,expanded:n,onClick:r,onMouseEnter:l,onMouseLeave:i}){const a=o().text;/* @__PURE__ */
38
+ return e("button",{type:"button",className:"block-plus","aria-label":a("插入内容"),title:a("在此空行插入内容(表格 / 分栏 / 图片…)"),"aria-expanded":n,"aria-haspopup":"menu",style:t,onMouseEnter:l,onMouseLeave:i,onClick:r,children:/* @__PURE__ */e(Ce,{name:"plus",size:17})})}function typeIcon(e,t){var n;if("heading"===t.type){const o=Number((null==(n=e.state.doc.nodeAt(t.pos))?void 0:n.attrs.level)??1);return`h${Math.min(Math.max(Number.isFinite(o)?o:1,1),6)}`}return{paragraph:"text",image:"image",imageGallery:"image",table:"table",blockquote:"quote",codeBlock:"code",bulletList:"bullet-list",orderedList:"ordered-list",taskList:"task",callout:"callout",columns:"columns",mindMap:"mind-map",fileAttachment:"file",videoEmbed:"file",mathBlock:"math",horizontalRule:"divider",pageLink:"page"}[t.type]??"text"}function BlockChip({editor:n,info:r,style:l,expanded:i,onOpen:a,onOpenFull:s,onMouseEnter:c,onMouseLeave:u,onHandleMouseDown:d}){const m=o().text;/* @__PURE__ */
39
+ return t("div",{className:"block-chip",role:"toolbar","aria-label":m("块快捷操作"),style:l,onMouseEnter:c,onMouseLeave:u,children:[
40
+ /* @__PURE__ */e("button",{type:"button",className:"chip-btn","aria-label":m("转换为"),title:m("转换为…"),"aria-expanded":i,"aria-haspopup":"menu",onClick:a,children:/* @__PURE__ */e(Ce,{name:typeIcon(n,r),size:17})}),
41
+ /* @__PURE__ */e("button",{type:"button",className:"chip-btn chip-grip","aria-label":m("拖动或打开块菜单"),title:i?void 0:m("按住拖动可移动整段;单击打开块菜单"),"aria-expanded":i,"aria-haspopup":"menu",draggable:!1,onMouseDown:e=>d?d(e):e.preventDefault(),onClick:s,children:/* @__PURE__ */e(Ce,{name:"handle",size:17})})]})}function BlockMenu(r){var l,i,a,s,c,m;const p=o().text,{editor:b,info:w}=r,[y,k]=v(r.panelOnly??null),[x,C]=v(!1),[E,M]=v(null),L=b.state.doc.nodeAt(w.pos),chain=()=>{const e=menuBlockRange(b.state,w.pos),t=b.state.selection,n=t instanceof u&&!t.empty&&L&&t.from>=w.pos+1&&t.to<=w.pos+L.nodeSize-1;return b.chain().focus().command(({tr:o})=>(o.setSelection(u.between(o.doc.resolve(n?t.from:((null==e?void 0:e.from)??w.pos)+1),o.doc.resolve(n?t.to:((null==e?void 0:e.to)??w.pos+L.nodeSize)-1))),!0))},N=tt.filter(e=>e.convertible),D=tt.filter(e=>"link"!==e.id),S=String((null==(l=null==L?void 0:L.attrs)?void 0:l.textAlign)??"left"),A=!!L&&["paragraph","heading","blockquote","codeBlock","bulletList","orderedList","taskList","callout"].includes(L.type.name),B=h(null),z=h(null),H=h(null),O=h(null),q=h(y);q.current=y;const $=h(E);$.current=E;const F=h(void 0);function cancelSubmenuClose(){clearTimeout(F.current),F.current=void 0}function openSubmenu(e,t){cancelSubmenuClose(),O.current=t,M(null),k(e)}function scheduleSubmenuClose(){r.panelOnly||(cancelSubmenuClose(),F.current=setTimeout(()=>{k(null),M(null)},180))}g(()=>()=>cancelSubmenuClose(),[]);const[V,W]=v(),[j,Y]=v({left:0,top:0});function insertCommand(e,t){if(!L||!b.isEditable||b.isDestroyed)return;const n="insert-below"===r.panelOnly&&L.isTextblock&&0===L.content.size,o=w.pos+L.nodeSize,l=n?{from:w.pos,to:o}:o;if(["image","file","page","video"].includes(e.id))return n?b.commands.setTextSelection(w.pos+1):b.chain().insertContentAt(o,{type:"paragraph"}).setTextSelection(o+1).run(),r.onClose(),void("page"===e.id?r.onPickPage():"video"===e.id?r.onPickVideo():r.onPickFile("image"===e.id?"image":"file"));let i;i=/^h[1-6]$/.test(e.id)?{type:"heading",attrs:{level:Number(e.id.slice(1))}}:"table"===e.id?$e(b.schema,(null==t?void 0:t.rows)??3,(null==t?void 0:t.cols)??3,!0).toJSON():"columns"===e.id?T((null==t?void 0:t.count)??2):"mindmap"===e.id?[Fe(),{type:"paragraph"}]:["bullet","ordered","task"].includes(e.id)?{type:"bullet"===e.id?"bulletList":"ordered"===e.id?"orderedList":"taskList",content:[{type:"task"===e.id?"taskItem":"listItem",attrs:"task"===e.id?{checked:!1}:void 0,content:[{type:"paragraph"}]}]}:{text:{type:"paragraph"},quote:{type:"blockquote",content:[{type:"paragraph"}]},code:{type:"codeBlock"},hr:{type:"horizontalRule"},callout:{type:"callout",attrs:{tone:"info"},content:[{type:"paragraph"}]},math:{type:"mathBlock",attrs:{latex:"E = mc^2"}}}[e.id],i&&b.chain().focus().insertContentAt(l,i).run(),r.onClose()}async function writeBlockClipboard(){var e;if(!L)return;if("undefined"==typeof ClipboardItem||!(null==(e=navigator.clipboard)?void 0:e.write)){if(!L.isTextblock)throw new Error(p("当前浏览器不支持复制此块的富文本结构"));return void await navigator.clipboard.writeText(L.textContent)}const t=document.createElement("div");t.append(Oe.fromSchema(b.schema).serializeFragment(qe.from(L))),await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([t.innerHTML],{type:"text/html"}),"text/plain":new Blob([L.textContent],{type:"text/plain"})})])}g(()=>{P(b.view,w.pos);const outside=e=>{var t;e.target instanceof Element&&!(null==(t=B.current)?void 0:t.contains(e.target))&&(e.target.closest(".block-chip,.block-plus")||r.onClose())},key=e=>{var t,n,o,l;if(e.isComposing)return;const i=document.activeElement;if("Escape"===e.key&&$.current)return e.preventDefault(),e.stopPropagation(),M(null),void(null==(t=O.current)||t.focus());if("ArrowRight"===e.key&&(null==i?void 0:i.dataset.submenu))return e.preventDefault(),openSubmenu(i.dataset.submenu,i),void requestAnimationFrame(()=>{var e,t;return null==(t=null==(e=H.current)?void 0:e.querySelector('[role="menuitem"]:not(:disabled)'))?void 0:t.focus()});if(!r.panelOnly&&q.current&&("Escape"===e.key||"ArrowLeft"===e.key&&(null==(n=H.current)?void 0:n.contains(i))))return e.preventDefault(),e.stopPropagation(),k(null),M(null),void(null==(o=O.current)||o.focus());if("Escape"===e.key)return e.preventDefault(),e.stopPropagation(),void r.onClose();if(!["ArrowDown","ArrowUp","Home","End"].includes(e.key))return;const a=(null==i?void 0:i.closest('[role="menu"]'))??z.current??H.current,s=Array.from((null==a?void 0:a.querySelectorAll('[role="menuitem"]:not(:disabled)'))??[]);if(!s.length)return;e.preventDefault();const c=s.indexOf(document.activeElement);null==(l=s["Home"===e.key?0:"End"===e.key?s.length-1:(c+("ArrowUp"===e.key?-1:1)+s.length)%s.length])||l.focus()},changed=({transaction:e})=>{e.docChanged&&r.onClose()};return document.addEventListener("pointerdown",outside,!0),document.addEventListener("keydown",key,!0),b.on("transaction",changed),()=>{document.removeEventListener("pointerdown",outside,!0),document.removeEventListener("keydown",key,!0),b.off("transaction",changed),b.isDestroyed||P(b.view,null)}},[b,w.pos,r.panelOnly]),f(()=>{const e=B.current,t=r.panelOnly?H.current:z.current,n=b.view.dom.closest(".editor-shell");if(!e||!t||!n)return;const measure=()=>{var o;const l=n.getBoundingClientRect(),i=t.offsetWidth,a=t.offsetHeight,s=Math.min(Math.max(l.left+w.contentLeft,8),Math.max(8,innerWidth-8-i))-l.left,c=Math.min(Math.max(l.top+w.top,8),Math.max(8,innerHeight-8-a))-l.top;if(Y({left:s,top:c}),!r.panelOnly&&H.current){const n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),l=H.current.getBoundingClientRect(),i=function placeBlockSubmenu(e,t,n,o){const r=Math.max(0,o.height-16),l=e.right+6,i=e.left-6-n.width,a=l+n.width<=o.width-8||i<8?l:i;return{left:Math.max(8,Math.min(a,o.width-8-n.width)),top:fitRange(t,Math.min(n.height,r),8,o.height-8),maxHeight:r}}(n,(null==(o=O.current)?void 0:o.getBoundingClientRect().top)??n.top,l,{width:innerWidth,height:innerHeight});W({left:i.left-r.left,top:i.top-r.top,maxHeight:i.maxHeight})}else W(void 0)};measure();const o=new ResizeObserver(measure);return o.observe(t),H.current&&H.current!==t&&o.observe(H.current),window.addEventListener("resize",measure),window.addEventListener("scroll",measure,!0),()=>{o.disconnect(),window.removeEventListener("resize",measure),window.removeEventListener("scroll",measure,!0)}},[b,w.contentLeft,w.top,r.panelOnly,y,j.left,j.top]),g(()=>{k(r.panelOnly??null)},[r.panelOnly,w.pos]);const item=(n,o,r,l={})=>/* @__PURE__ */t("button",{type:"button",role:"menuitem",className:`bm-item${l.active?" active":""}${l.disabled?" disabled":""}${l.danger?" danger":""}`,"aria-haspopup":l.submenu?"menu":void 0,"aria-expanded":l.submenu?y===l.submenu:void 0,"data-submenu":l.submenu,disabled:l.disabled,"aria-disabled":l.disabled||void 0,onMouseEnter:e=>{cancelSubmenuClose(),l.submenu?openSubmenu(l.submenu,e.currentTarget):e.currentTarget.parentElement===z.current?(k(null),M(null)):"insert-below"===y&&(O.current=e.currentTarget)},onClick:e=>l.submenu?openSubmenu(l.submenu,e.currentTarget):r(),children:[
42
42
  /* @__PURE__ */e(Ce,{name:n,size:18}),
43
- /* @__PURE__ */e("span",{children:o}),r.submenu&&/* @__PURE__ */e(Ce,{name:"chevron",size:16,className:"bm-chevron"})]},o);/* @__PURE__ */
44
- return t("div",{ref:H,className:"block-anchor",role:"menu","aria-label":p("块操作菜单"),style:U,onMouseDown:e=>e.preventDefault(),onMouseEnter:()=>{var e;cancelSubmenuClose(),null==(e=l.onRegion)||e.call(l,!0)},onMouseLeave:()=>{var e,t;scheduleSubmenuClose(),null==(t=l.onRegion)||t.call(l,!0===(null==(e=H.current)?void 0:e.contains(document.activeElement)))},onFocusCapture:()=>{var e;cancelSubmenuClose(),null==(e=l.onRegion)||e.call(l,!0)},onBlurCapture:()=>queueMicrotask(()=>{var e,t,n;return null==(n=l.onRegion)?void 0:n.call(l,!0===(null==(e=H.current)?void 0:e.contains(document.activeElement))||!0===(null==(t=H.current)?void 0:t.matches(":hover")))}),children:[!l.panelOnly&&/* @__PURE__ */t("div",{ref:O,className:"block-menu",role:"menu",onMouseLeave:scheduleSubmenuClose,children:[item("h1",p("转换为"),()=>k("format"===y?null:"format"),{submenu:"format"}),item("indent",p("缩进和对齐"),()=>k("indent-align"===y?null:"indent-align"),{submenu:"indent-align"}),item("palette",p("颜色"),()=>k("color"===y?null:"color"),{submenu:"color"}),item("plus",p("在下方添加"),()=>k("insert-below"===y?null:"insert-below"),{submenu:"insert-below"}),l.canComment&&/* @__PURE__ */e("div",{className:"bm-sep"}),l.canComment&&item("comment",p("评论"),()=>{var e;null==(e=l.onRequestComment)||e.call(l),l.onClose()}),item("cut",p("剪切"),async function cutBlock(){var e,t;if(!N)return;const n=b.state.doc,o=N;try{await writeBlockClipboard()}catch{return void(null==(e=l.onNotice)||e.call(l,p("无法访问剪贴板,已取消剪切(内容未删除)。")))}if(b.isDestroyed||!b.isEditable||b.state.doc!==n||b.state.doc.nodeAt(w.pos)!==o)return void(null==(t=l.onNotice)||t.call(l,p("复制期间正文发生了变化,已取消删除,请重新剪切。")));const r=deleteTopLevelBlock(b.state,w.pos);r&&b.view.dispatch(r),l.onClose()}),item(C?"check":"copy",p(C?"已复制":"复制"),()=>{!async function copyBlock(){var e;try{await writeBlockClipboard(),x(!0),setTimeout(()=>x(!1),1600)}catch{null==(e=l.onNotice)||e.call(l,p("无法完整复制该块,请选中后使用 Cmd/Ctrl+C。"))}}()}),item("copy-link",p("复制本页链接"),()=>{var e;null==(e=l.onCopyLink)||e.call(l),l.onClose()}),
45
- /* @__PURE__ */e("div",{className:"bm-sep"}),item("share",p("分享此页面"),()=>{var e;null==(e=l.onSharePage)||e.call(l),l.onClose()}),item("page",p("转换为子文档"),()=>{var e;N&&(null==(e=l.onConvertToSubpage)||e.call(l,N.toJSON())),l.onClose()}),item("file",p("保存为模板"),()=>{var e;N&&(null==(e=l.onSaveAsTemplate)||e.call(l,N.toJSON())),l.onClose()}),
46
- /* @__PURE__ */e("div",{className:"bm-sep"}),item("trash",p("删除"),()=>function action(){if(N){{const e=deleteTopLevelBlock(b.state,w.pos);e&&b.view.dispatch(e)}l.onClose()}}(),{danger:!0})]}),y&&/* @__PURE__ */t("div",{ref:q,className:"block-submenu"+("color"===y?" block-submenu-color":""),role:"color"===y?"dialog":"menu",style:l.panelOnly?{position:"relative"}:{position:"absolute",...Y,visibility:Y?"visible":"hidden"},"aria-label":"color"===y?p("块颜色"):void 0,onMouseEnter:cancelSubmenuClose,onMouseLeave:scheduleSubmenuClose,children:["format"===y&&S.map(n=>{const o=canConvertMenuBlocks(b.state,w.pos,n.id),r=function editableActive(e,t,n){const o=menuBlockRange(e.state,t);if(!o)return!1;const l=o.nodes[0];return!!l&&("text"===n?"paragraph"===l.type.name:"h1"===n?"heading"===l.type.name&&1===l.attrs.level:"h2"===n?"heading"===l.type.name&&2===l.attrs.level:"h3"===n?"heading"===l.type.name&&3===l.attrs.level:"h4"===n?"heading"===l.type.name&&4===l.attrs.level:"h5"===n?"heading"===l.type.name&&5===l.attrs.level:"h6"===n?"heading"===l.type.name&&6===l.attrs.level:l.type.name==={ordered:"orderedList",bullet:"bulletList",quote:"blockquote",code:"codeBlock",task:"taskList",callout:"callout"}[n])}(b,w.pos,n.id);/* @__PURE__ */
47
- return t("button",{type:"button",role:"menuitem",className:`bm-item${r?" active":""}${o?"":" disabled"}`,disabled:!o,"aria-disabled":!o,onClick:()=>{(function convertMenuBlocks(e,t,n){var o,l;if(e.isDestroyed||!e.isEditable||!canConvertMenuBlocks(e.state,t,n))return!1;const r=menuBlockRange(e.state,t);if("callout"===n||"quote"===n)return function dispatchContainer(e,t,n){var o;if(1===t.nodes.length&&t.nodes[0].type.name===n)return!0;const l=e.schema.nodes[n].create("callout"===n?{tone:"info"}:null,containerContent(t)),r=e.state.tr.replaceWith(t.from,t.to,l);r.setSelection(d.near(r.doc.resolve(t.from+1)));const i=null==(o=qe.getState(e.state))?void 0:o.undoManager;return null==i||i.stopCapturing(),e.view.dispatch(Oe(r)),null==i||i.stopCapturing(),e.view.focus(),!0}(e,r,"callout"===n?"callout":"blockquote");if("text"===n&&1===r.nodes.length&&"callout"===r.nodes[0].type.name){const t=I(e,r.from);return t&&e.view.focus(),t}if("text"===n&&1===r.nodes.length&&"blockquote"===r.nodes[0].type.name){const t=e.state.tr.replaceWith(r.from,r.to,r.nodes[0].content),n=null==(o=qe.getState(e.state))?void 0:o.undoManager;return null==n||n.stopCapturing(),e.view.dispatch(Oe(t)),null==n||n.stopCapturing(),e.view.focus(),!0}const i={text:"paragraph",bullet:"bulletList",ordered:"orderedList",task:"taskList",code:"codeBlock"}[n];if(1===r.nodes.length&&r.nodes[0].type.name===i)return!0;const a=null==(l=qe.getState(e.state))?void 0:l.undoManager;null==a||a.stopCapturing();const c=e.chain().focus().command(({tr:e})=>{let t=r.to;return 1===r.nodes.length&&["callout","blockquote"].includes(r.nodes[0].type.name)&&(e.replaceWith(r.from,r.to,r.nodes[0].content),t-=2),e.setSelection(u.between(e.doc.resolve(r.from+1),e.doc.resolve(t-1))),Oe(e),!0}).clearNodes();"text"===n?c.setParagraph():/^h[1-6]$/.test(n)?c.setHeading({level:Number(n.slice(1))}):"bullet"===n?c.toggleBulletList():"ordered"===n?c.toggleOrderedList():"task"===n?c.toggleTaskList():"code"===n&&c.toggleCodeBlock();const s=c.command(({tr:e})=>(e.setSelection(d.near(e.doc.resolve(e.selection.from))),!0)).run();return null==a||a.stopCapturing(),s})(b,w.pos,n.id),l.onClose()},children:[
43
+ /* @__PURE__ */e("span",{children:o}),l.submenu&&/* @__PURE__ */e(Ce,{name:"chevron",size:16,className:"bm-chevron"})]},o);/* @__PURE__ */
44
+ return t("div",{ref:B,className:"block-anchor",role:"menu","aria-label":p("块操作菜单"),style:j,onMouseDown:e=>e.preventDefault(),onMouseEnter:()=>{var e;cancelSubmenuClose(),null==(e=r.onRegion)||e.call(r,!0)},onMouseLeave:()=>{var e,t;scheduleSubmenuClose(),null==(t=r.onRegion)||t.call(r,!0===(null==(e=B.current)?void 0:e.contains(document.activeElement)))},onFocusCapture:()=>{var e;cancelSubmenuClose(),null==(e=r.onRegion)||e.call(r,!0)},onBlurCapture:()=>queueMicrotask(()=>{var e,t,n;return null==(n=r.onRegion)?void 0:n.call(r,!0===(null==(e=B.current)?void 0:e.contains(document.activeElement))||!0===(null==(t=B.current)?void 0:t.matches(":hover")))}),children:[!r.panelOnly&&/* @__PURE__ */t("div",{ref:z,className:"block-menu",role:"menu",onMouseLeave:scheduleSubmenuClose,children:[item("h1",p("转换为"),()=>k("format"===y?null:"format"),{submenu:"format"}),item("indent",p("缩进和对齐"),()=>k("indent-align"===y?null:"indent-align"),{submenu:"indent-align"}),item("palette",p("颜色"),()=>k("color"===y?null:"color"),{submenu:"color"}),item("plus",p("在下方添加"),()=>k("insert-below"===y?null:"insert-below"),{submenu:"insert-below"}),r.canComment&&/* @__PURE__ */e("div",{className:"bm-sep"}),r.canComment&&item("comment",p("评论"),()=>{var e;null==(e=r.onRequestComment)||e.call(r),r.onClose()}),item("cut",p("剪切"),async function cutBlock(){var e,t;if(!L)return;const n=b.state.doc,o=L;try{await writeBlockClipboard()}catch{return void(null==(e=r.onNotice)||e.call(r,p("无法访问剪贴板,已取消剪切(内容未删除)。")))}if(b.isDestroyed||!b.isEditable||b.state.doc!==n||b.state.doc.nodeAt(w.pos)!==o)return void(null==(t=r.onNotice)||t.call(r,p("复制期间正文发生了变化,已取消删除,请重新剪切。")));const l=deleteTopLevelBlock(b.state,w.pos);l&&b.view.dispatch(l),r.onClose()}),item(x?"check":"copy",p(x?"已复制":"复制"),()=>{!async function copyBlock(){var e;try{await writeBlockClipboard(),C(!0),setTimeout(()=>C(!1),1600)}catch{null==(e=r.onNotice)||e.call(r,p("无法完整复制该块,请选中后使用 Cmd/Ctrl+C。"))}}()}),item("copy-link",p("复制本页链接"),()=>{var e;null==(e=r.onCopyLink)||e.call(r),r.onClose()}),
45
+ /* @__PURE__ */e("div",{className:"bm-sep"}),item("share",p("分享此页面"),()=>{var e;null==(e=r.onSharePage)||e.call(r),r.onClose()}),item("page",p("转换为子文档"),()=>{var e;L&&(null==(e=r.onConvertToSubpage)||e.call(r,L.toJSON())),r.onClose()}),item("file",p("保存为模板"),()=>{var e;L&&(null==(e=r.onSaveAsTemplate)||e.call(r,L.toJSON())),r.onClose()}),
46
+ /* @__PURE__ */e("div",{className:"bm-sep"}),item("trash",p("删除"),()=>function action(){if(L){{const e=deleteTopLevelBlock(b.state,w.pos);e&&b.view.dispatch(e)}r.onClose()}}(),{danger:!0})]}),y&&/* @__PURE__ */t("div",{ref:H,className:"block-submenu"+("color"===y?" block-submenu-color":""),role:"color"===y?"dialog":"menu",style:r.panelOnly?{position:"relative"}:{position:"absolute",...V,visibility:V?"visible":"hidden"},"aria-label":"color"===y?p("块颜色"):void 0,onMouseEnter:cancelSubmenuClose,onMouseLeave:scheduleSubmenuClose,children:["format"===y&&N.map(n=>{const o=canConvertMenuBlocks(b.state,w.pos,n.id),l=function editableActive(e,t,n){const o=menuBlockRange(e.state,t);if(!o)return!1;const r=o.nodes[0];return!!r&&("text"===n?"paragraph"===r.type.name:"h1"===n?"heading"===r.type.name&&1===r.attrs.level:"h2"===n?"heading"===r.type.name&&2===r.attrs.level:"h3"===n?"heading"===r.type.name&&3===r.attrs.level:"h4"===n?"heading"===r.type.name&&4===r.attrs.level:"h5"===n?"heading"===r.type.name&&5===r.attrs.level:"h6"===n?"heading"===r.type.name&&6===r.attrs.level:r.type.name==={ordered:"orderedList",bullet:"bulletList",quote:"blockquote",code:"codeBlock",task:"taskList",callout:"callout"}[n])}(b,w.pos,n.id);/* @__PURE__ */
47
+ return t("button",{type:"button",role:"menuitem",className:`bm-item${l?" active":""}${o?"":" disabled"}`,disabled:!o,"aria-disabled":!o,onClick:()=>{(function convertMenuBlocks(e,t,n){var o,r;if(e.isDestroyed||!e.isEditable||!canConvertMenuBlocks(e.state,t,n))return!1;const l=menuBlockRange(e.state,t);if("callout"===n||"quote"===n)return function dispatchContainer(e,t,n){var o;if(1===t.nodes.length&&t.nodes[0].type.name===n)return!0;const r=e.schema.nodes[n].create("callout"===n?{tone:"info"}:null,containerContent(t)),l=e.state.tr.replaceWith(t.from,t.to,r);l.setSelection(d.near(l.doc.resolve(t.from+1)));const i=null==(o=We.getState(e.state))?void 0:o.undoManager;return null==i||i.stopCapturing(),e.view.dispatch(Ve(l)),null==i||i.stopCapturing(),e.view.focus(),!0}(e,l,"callout"===n?"callout":"blockquote");if("text"===n&&1===l.nodes.length&&"callout"===l.nodes[0].type.name){const t=I(e,l.from);return t&&e.view.focus(),t}if("text"===n&&1===l.nodes.length&&"blockquote"===l.nodes[0].type.name){const t=e.state.tr.replaceWith(l.from,l.to,l.nodes[0].content),n=null==(o=We.getState(e.state))?void 0:o.undoManager;return null==n||n.stopCapturing(),e.view.dispatch(Ve(t)),null==n||n.stopCapturing(),e.view.focus(),!0}const i={text:"paragraph",bullet:"bulletList",ordered:"orderedList",task:"taskList",code:"codeBlock"}[n];if(1===l.nodes.length&&l.nodes[0].type.name===i)return!0;const a=null==(r=We.getState(e.state))?void 0:r.undoManager;null==a||a.stopCapturing();const s=e.chain().focus().command(({tr:e})=>{let t=l.to;return 1===l.nodes.length&&["callout","blockquote"].includes(l.nodes[0].type.name)&&(e.replaceWith(l.from,l.to,l.nodes[0].content),t-=2),e.setSelection(u.between(e.doc.resolve(l.from+1),e.doc.resolve(t-1))),Ve(e),!0}).clearNodes();"text"===n?s.setParagraph():/^h[1-6]$/.test(n)?s.setHeading({level:Number(n.slice(1))}):"bullet"===n?s.toggleBulletList():"ordered"===n?s.toggleOrderedList():"task"===n?s.toggleTaskList():"code"===n&&s.toggleCodeBlock();const c=s.command(({tr:e})=>(e.setSelection(d.near(e.doc.resolve(e.selection.from))),!0)).run();return null==a||a.stopCapturing(),c})(b,w.pos,n.id),r.onClose()},children:[
48
48
  /* @__PURE__ */e(Ce,{name:n.icon,size:18}),
49
- /* @__PURE__ */e("span",{children:p(n.label)}),r&&/* @__PURE__ */e(Ce,{name:"check",size:16,className:"bm-chevron"})]},n.id)}),"indent-align"===y&&/* @__PURE__ */t(n,{children:[item("indent",p("增加缩进"),()=>{chain().indentBlock().run(),l.onClose()},{disabled:!z}),item("outdent",p("减少缩进"),()=>{chain().outdentBlock().run(),l.onClose()},{disabled:!z}),
50
- /* @__PURE__ */e("div",{className:"bm-sep"}),R.map(e=>item(`align-${e}`,p("left"===e?"左对齐":"center"===e?"居中对齐":"right"===e?"右对齐":"两端对齐"),()=>{chain().setTextAlign(e).run(),l.onClose()},{active:B===e,disabled:!z}))]}),"color"===y&&/* @__PURE__ */t("div",{className:"block-color-panel",role:"group","aria-label":p("文档颜色"),children:[
51
- /* @__PURE__ */t("div",{className:"color-section",children:[
52
- /* @__PURE__ */e("div",{className:"color-label",children:p("字体颜色")}),
53
- /* @__PURE__ */e("div",{className:"color-grid",role:"group","aria-label":p("字体颜色"),children:L.map(t=>/* @__PURE__ */e("button",{type:"button",className:"color-choice"+(textColorActive(b,t.value)?" selected":""),"aria-label":p("字体颜色:{0}",{0:t.name}),title:p("字体颜色:{0}",{0:t.name}),"aria-pressed":textColorActive(b,t.value),onClick:()=>{const e=t.value?{color:t.value}:null;e?chain().setMark("textStyle",e).run():chain().unsetMark("textStyle").run()},children:/* @__PURE__ */e("span",{className:"font-sample",style:t.value?{color:t.value}:void 0,children:"A"})},t.name))})]}),
54
- /* @__PURE__ */t("div",{className:"color-section",children:[
55
- /* @__PURE__ */e("div",{className:"color-label",children:p("背景颜色")}),
56
- /* @__PURE__ */e("div",{className:"color-grid",role:"group","aria-label":p("背景颜色"),children:D.map(t=>/* @__PURE__ */e("button",{type:"button",className:`color-choice background-choice${highlightActive(b,t.value)?" selected":""}${null===t.value?" no-background":""}`,"aria-label":p("背景颜色:{0}",{0:t.name}),title:p("背景颜色:{0}",{0:t.name}),"aria-pressed":highlightActive(b,t.value),style:t.value?{background:t.value}:void 0,onClick:()=>{const e=t.value?{color:t.value}:null;e?chain().setMark("highlight",e).run():chain().unsetMark("highlight").run()},children:null===t.value&&/* @__PURE__ */e("span",{className:"clear-stroke","aria-hidden":"true"})},t.name))})]}),
57
- /* @__PURE__ */e(ke,{variant:"outline",block:!0,onClick:()=>{chain().unsetMark("textStyle").unsetMark("highlight").run(),l.onClose()},children:p("恢复默认")})]}),"insert-below"===y&&A.map(e=>item(e.icon,e.label,()=>function runInsert(e){e.panel?M({mode:e.panel,x:0,y:0}):insertCommand(e)}(e)))]}),E&&/* @__PURE__ */e(InsertPicker,{mode:E.mode,x:((null==Y?void 0:Y.left)??0)+((null==(i=q.current)?void 0:i.offsetWidth)??240)+6,y:Math.max(0,((null==(a=$.current)?void 0:a.getBoundingClientRect().top)??0)-((null==(c=H.current)?void 0:c.getBoundingClientRect().top)??0)),boundTop:8-((null==(s=H.current)?void 0:s.getBoundingClientRect().top)??0),boundBottom:innerHeight-8-((null==(m=H.current)?void 0:m.getBoundingClientRect().top)??0),onPick:function insertWithPanel(e){const t=A.find(e=>e.panel===(null==E?void 0:E.mode));M(null),t&&insertCommand(t,e)},onClose:()=>M(null)})]})}function textColorActive(e,t){const n=e.getAttributes("textStyle").color;return null===t?"string"!=typeof n:n===t}function highlightActive(e,t){const n=e.getAttributes("highlight").color;return null===t?"string"!=typeof n:n===t}async function writeRichTable(e,t){var n;if("undefined"==typeof ClipboardItem||!(null==(n=navigator.clipboard)?void 0:n.write))throw new Error("rich clipboard unavailable");const o=document.createElement("div");o.appendChild(Pe.fromSchema(t).serializeFragment(Re.from(e))),await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([o.innerHTML],{type:"text/html"}),"text/plain":new Blob([e.textBetween(0,e.content.size,"\n")],{type:"text/plain"})})])}async function copyTableToClipboard(e,t,n,o=writeRichTable){if(e.isDestroyed||!e.isEditable)return null;const l=e.state.doc,r=l.nodeAt(t);return"table"!==(null==r?void 0:r.type.spec.tableRole)?null:(await o(r,e.state.schema),n?e.isDestroyed||!e.isEditable||e.state.doc!==l||e.state.doc.nodeAt(t)!==r?"changed":(e.view.dispatch(e.state.tr.deleteRange(t,t+r.nodeSize)),e.view.focus(),"cut"):"copied")}const anchorOf=e=>{const t=e.currentTarget.getBoundingClientRect();return{left:t.left,top:t.top,right:t.right,bottom:t.bottom}};function TableControls({editor:r,hover:i,revision:a,onNotice:c,onBlockDrag:s}){var u,d,m;const b=o().text,{portal:w}=l(),y=h(null),[k,C]=v(!1),[x,E]=v("none"),[M,N]=v(!1),[S,A]=v("table"),[T,B]=v(!1),[I,P]=v(!1),[R,Z]=v(!1),[ee,te]=v(""),[ne,oe]=v(!1),[le,re]=v({width:0,height:0}),[,ie]=v(0),[ae,ce]=v(null),[se,ue]=v(null),de=h(null),me=h(null),pe=h(null),he=h(null),ve=h(null),ge=h(null),[fe,be]=v({left:0,top:0,maxHeight:480}),[we,ye]=v({left:0,top:0});g(()=>{var e;if(!M||!ae)return;const t=de.current;t&&be(function placeTableMenu(e,t,n){const o=n.topInset,l=Math.max(o,Math.min(e.top,n.height-12)),r=Math.max(l,Math.min(e.bottom,n.height-12)),i=Math.max(0,n.height-12-r-6),a=Math.max(0,l-6-o),c=t.height<=i||t.height>a&&i>=a,s=c?i:a,u=Math.min(t.height,s);return{left:Math.max(12,Math.min(e.left,n.width-t.width-12)),top:c?r+6:l-6-u,maxHeight:s}}(ae,{width:t.offsetWidth,height:((null==(e=pe.current)?void 0:e.scrollHeight)??t.scrollHeight)+2},{width:innerWidth,height:innerHeight,topInset:12}))},[M,ae,R,I,S]),f(()=>{var e;if(!(M&&de.current&&pe.current&&he.current))return;const t=function attachOverlayScrollbar(e,t,n){const o=document.createElement("div"),l=document.createElement("div");o.className="w-overlay-scrollbar__track",l.className="w-overlay-scrollbar__thumb";const r=t.id;let i,a;t.id||(t.id=`wd-scroll-${crypto.randomUUID()}`),l.tabIndex=0,l.setAttribute("role","scrollbar"),l.setAttribute("aria-label","菜单滚动条"),l.setAttribute("aria-orientation","vertical"),l.setAttribute("aria-controls",t.id),l.setAttribute("aria-valuemin","0"),o.append(l),e.append(o);let c=0;const s=new AbortController;function active(){e.classList.add("is-scrolling"),clearTimeout(i),i=setTimeout(()=>{a||e.classList.remove("is-scrolling")},700)}function update(){const e=Math.max(0,t.scrollHeight-t.clientHeight);o.hidden=e<=1;const n=o.clientHeight;c=Math.min(n,Math.max(28,n*t.clientHeight/Math.max(1,t.scrollHeight))),l.style.height=`${c}px`,l.style.transform=`translateY(${e?(n-c)*t.scrollTop/e:0}px)`,l.setAttribute("aria-valuemax",String(Math.round(e))),l.setAttribute("aria-valuenow",String(Math.round(t.scrollTop)))}function finish(){a&&(a=void 0,e.classList.remove("is-dragging-scrollbar"),active())}t.addEventListener("scroll",()=>{update(),active()},{passive:!0,signal:s.signal}),l.addEventListener("pointerdown",n=>{0===n.button&&(n.preventDefault(),n.stopPropagation(),l.focus({preventScroll:!0}),a={y:n.clientY,top:t.scrollTop,maximum:t.scrollHeight-t.clientHeight,travel:Math.max(1,o.clientHeight-c)},e.classList.add("is-dragging-scrollbar"),active())},{signal:s.signal}),window.addEventListener("pointermove",e=>{a&&(e.preventDefault(),t.scrollTop=Math.max(0,Math.min(a.maximum,a.top+(e.clientY-a.y)*a.maximum/a.travel)),update())},{signal:s.signal}),window.addEventListener("pointerup",finish,{signal:s.signal}),window.addEventListener("pointercancel",finish,{signal:s.signal}),window.addEventListener("blur",finish,{signal:s.signal}),o.addEventListener("pointerdown",e=>{if(e.target!==o||0!==e.button)return;e.preventDefault(),e.stopPropagation();const n=o.getBoundingClientRect().top;t.scrollTop=(e.clientY-n-c/2)/Math.max(1,o.clientHeight-c)*(t.scrollHeight-t.clientHeight),update(),active()},{signal:s.signal}),l.addEventListener("keydown",e=>{const n={ArrowDown:32,ArrowUp:-32,PageDown:.8*t.clientHeight,PageUp:.8*-t.clientHeight}[e.key];void 0===n&&"Home"!==e.key&&"End"!==e.key||(e.preventDefault(),e.stopPropagation(),t.scrollTop="Home"===e.key?0:"End"===e.key?t.scrollHeight:t.scrollTop+n,update(),active())},{signal:s.signal});const u=new ResizeObserver(update);return u.observe(t),u.observe(n),u.observe(e),update(),{update:update,destroy(){s.abort(),u.disconnect(),clearTimeout(i),o.remove(),e.classList.remove("is-scrolling","is-dragging-scrollbar"),r||t.removeAttribute("id")}}}(de.current,pe.current,he.current);return null==(e=de.current.querySelector('[role="menuitem"]'))||e.focus({preventScroll:!0}),()=>t.destroy()},[M,w]),g(()=>{if("none"===x||!se)return;const measure=()=>{var e;const t=me.current,n=null==(e=ge.current)?void 0:e.getBoundingClientRect();if(!t||!n)return;const o=xe({trigger:n,panel:{width:t.offsetWidth,height:t.offsetHeight},position:"bl",gap:6,viewport:{width:innerWidth,height:innerHeight}});ye(e=>e.left===o.left&&e.top===o.top?e:{left:o.left,top:o.top})};measure();const e=new ResizeObserver(measure);me.current&&e.observe(me.current);let t=0;const scroll=()=>{cancelAnimationFrame(t),t=requestAnimationFrame(measure)};return window.addEventListener("scroll",scroll,!0),()=>{e.disconnect(),cancelAnimationFrame(t),window.removeEventListener("scroll",scroll,!0)}}),f(()=>{const update=e=>{var t,n;e.target instanceof Node&&((null==(t=de.current)?void 0:t.contains(e.target))||(null==(n=me.current)?void 0:n.contains(e.target)))||ie(e=>e+1)};return window.addEventListener("scroll",update,!0),window.addEventListener("resize",update),()=>{window.removeEventListener("scroll",update,!0),window.removeEventListener("resize",update)}},[]);const ke=h(r.state.selection),Ee=h(r.state.doc);f(()=>{ke.current.eq(r.state.selection)&&Ee.current===r.state.doc||(E("none"),C(!1),Z(!1),ke.current=r.state.selection,Ee.current=r.state.doc)},[a,r]);const Me=z(r.view),Ne=(null==i?void 0:i.cellPos)??Me,Le=null==Ne?null:H(r.view,Ne),De=Le&&i?{...Le,rowIndex:i.rowIndex,colIndex:i.colIndex}:Le,Se=r.state.selection instanceof Fe?r.state.selection:null,Ae=!!i||!!Se||M,Te=r.can().mergeCells(),Be=r.can().splitCell(),Ie=O(r,"row"),Pe=O(r,"column"),Re=r.getAttributes("tableCell").align??r.getAttributes("tableHeader").align,ze="string"==typeof r.getAttributes("textStyle").color?r.getAttributes("textStyle").color:null,He="string"==typeof r.getAttributes("highlight").color?r.getAttributes("highlight").color:null,Oe="string"==typeof(r.getAttributes("tableCell").backgroundColor??r.getAttributes("tableHeader").backgroundColor)?r.getAttributes("tableCell").backgroundColor??r.getAttributes("tableHeader").backgroundColor:null,chain=()=>r.chain().focus(),qe=r.view.dom.closest(".editor-shell");function axisDown(e,t,n){var o;if(!De||0!==n.button)return;n.preventDefault(),null==(o=y.current)||o.call(y);const l=r.view,i=l.state.doc,a=l.state.selection,c=i.resolve(De.cellPos),s=c.node(-1),u=c.start(-1),d=Ve.get(s),m="row"===e?De.rows:De.columns,p=null==qe?void 0:qe.getBoundingClientRect();if(!p)return;const select=n=>{const o=Math.min(t,n),r=Math.max(t,n),a="row"===e?o*d.width:o,c="row"===e?(r+1)*d.width-1:(d.height-1)*d.width+r;l.dispatch(l.state.tr.setSelection(Fe.create(i,u+d.map[a],u+d.map[c]))),l.focus()};select(t);const move=t=>{var n;if(!r.isEditable||l.state.doc!==i)return void(null==(n=y.current)||n.call(y));const o="row"===e?t.clientY-p.top:t.clientX-p.left,a=m.reduce((e,t)=>Math.abs(t.start+t.size/2-o)<Math.abs(e.start+e.size/2-o)?t:e);select(a.index),t.preventDefault()},key=e=>{var t;"Escape"===e.key&&(l.state.doc===i&&l.dispatch(l.state.tr.setSelection(a)),e.preventDefault(),null==(t=y.current)||t.call(y))},done=()=>{var e;return null==(e=y.current)?void 0:e.call(y)};y.current=()=>{window.removeEventListener("mousemove",move,!0),window.removeEventListener("mouseup",done,!0),window.removeEventListener("keydown",key,!0),window.removeEventListener("blur",done),y.current=null},window.addEventListener("mousemove",move,!0),window.addEventListener("mouseup",done,!0),window.addEventListener("keydown",key,!0),window.addEventListener("blur",done)}f(()=>{const context=e=>{if(!(r.isEditable&&e.target instanceof Element))return;const t=e.target.closest("td,th");if(!t)return;const n=W(r.view,t);null!==n&&(e.preventDefault(),Y(r.view,n),E("none"),A("cell"),B(!1),ve.current=null,P(!1),ce({left:e.clientX,right:e.clientX,top:e.clientY,bottom:e.clientY}),N(!0))};return r.view.dom.addEventListener("contextmenu",context,!0),()=>{var e;r.isDestroyed||r.view.dom.removeEventListener("contextmenu",context,!0),null==(e=y.current)||e.call(y)}},[r]),f(()=>{if(!M&&"none"===x)return;const close=e=>{var t,n;e.target instanceof Element&&((null==(t=de.current)?void 0:t.contains(e.target))||(null==(n=me.current)?void 0:n.contains(e.target))||e.target.closest(".tbl-ui-host"))||(N(!1),E("none"))},resize=()=>{N(!1),E("none")},scroll=e=>{var t,n;e.target instanceof Node&&((null==(t=de.current)?void 0:t.contains(e.target))||(null==(n=me.current)?void 0:n.contains(e.target)))||N(!1)};return document.addEventListener("pointerdown",close,!0),window.addEventListener("resize",resize),window.addEventListener("scroll",scroll,!0),()=>{document.removeEventListener("pointerdown",close,!0),window.removeEventListener("resize",resize),window.removeEventListener("scroll",scroll,!0)}},[M,x]),f(()=>{const escape=e=>{var t,n;"Escape"!==e.key||e.isComposing||("none"!==x?(e.preventDefault(),E("none"),null==(t=ge.current)||t.focus({preventScroll:!0})):M?(e.preventDefault(),N(!1),null==(n=ve.current)||n.focus({preventScroll:!0})):Se&&(e.preventDefault(),C(!0),r.view.focus()))};return document.addEventListener("keydown",escape),()=>document.removeEventListener("keydown",escape)});const $e=function selectedBounds(){var e;if(!qe||!Se)return null;const t=[];Se.forEachCell((e,n)=>{const o=r.view.nodeDOM(n);o instanceof HTMLElement&&t.push(o.getBoundingClientRect())});const n=De?null==(e=r.view.nodeDOM(De.cellPos))?void 0:e.closest("table"):null;if(!n)return null;const o=j(t,(n.closest(".tableWrapper")??n).getBoundingClientRect());if(!o)return null;const l=qe.getBoundingClientRect(),i=function placeTableToolbar(e,t,n){const o=Math.min(t.width,Math.max(0,n.width-24)),l=e.top-14-t.height;return{left:Math.max(12,Math.min((e.left+e.right-o)/2,n.width-o-12)),top:l>=n.topInset?l:Math.max(n.topInset,Math.min(e.top+40,n.height-t.height-12))}}(o,le,{width:innerWidth,height:innerHeight,topInset:66});return{left:o.left-l.left,top:o.top-l.top,width:o.right-o.left,height:o.bottom-o.top,toolbarLeft:i.left,toolbarTop:i.top}}();function mark(e){return U(r,e)}function toggleMark(e){_(r,e,mark(e)?null:{})}function showContext(e,t="table"){var n;if(!e)return;const o=e.currentTarget;if(M&&ve.current===o)return void N(!1);ve.current=o;const l=null==(n=o.closest(".tbl-cellbar"))?void 0:n.getBoundingClientRect();"table"===t&&De&&$(r.view,De.cellPos,"table");const i=anchorOf(e);E("none"),P(!1),A(t),B(!!l),ce({...i,top:(null==l?void 0:l.top)??i.top,bottom:(null==l?void 0:l.bottom)??i.bottom}),N(!0)}async function copyTable(e){const t=tableTarget();if(t&&!ne&&r.isEditable){oe(!0);try{const n=await copyTableToClipboard(r,t.pos,e);"changed"===n?null==c||c("表格已复制;内容发生变化,未执行剪切。"):n&&(null==c||c("cut"===n?"表格已剪切。":"表格已复制。")),N(!1)}catch{null==c||c(b("无法写入剪贴板,请允许浏览器访问剪贴板后重试。"))}finally{oe(!1)}}}function showPanel(e,t){x!==e?(ge.current=t.currentTarget,N(!1),ue(anchorOf(t)),E(e)):E("none")}function tableTarget(){const e=null==Ne?null:q(r.view,Ne),t=null===e?null:r.state.doc.nodeAt(e);return null!==e&&t?{pos:e,node:t}:null}function applyWidth(){var e;const t=null==(e=X(r))?void 0:e.col,n=Math.round(Number(ee));null==t||!Number.isFinite(n)||n<40||n>2e3||(G(r,t,n),Z(!1),N(!1))}const Ye=[{key:"color",label:b("表格文字颜色"),tip:b("文字颜色"),hint:b("只改文字本身的颜色,不影响格子底色"),colors:L,current:ze},{key:"highlight",label:b("表格文字高亮"),tip:b("文字高亮"),hint:b("只给文字加荧光底色,格子仍是原本的底色"),colors:D,current:He},{key:"background",label:b("单元格底色"),tip:b("单元格底色"),hint:b("给整个单元格铺底色,与文字高亮互不影响"),colors:We,current:Oe}],menuItem=(n,o,l,r={})=>/* @__PURE__ */t("button",{type:"button",role:"menuitem",className:"ctx-item"+(r.danger?" danger":""),disabled:r.disabled,"aria-checked":r.checked,"aria-expanded":r.expanded,onMouseDown:e=>e.preventDefault(),onClick:l,children:[
49
+ /* @__PURE__ */e("span",{children:p(n.label)}),l&&/* @__PURE__ */e(Ce,{name:"check",size:16,className:"bm-chevron"})]},n.id)}),"indent-align"===y&&/* @__PURE__ */t(n,{children:[item("indent",p("增加缩进"),()=>{chain().indentBlock().run(),r.onClose()},{disabled:!A}),item("outdent",p("减少缩进"),()=>{chain().outdentBlock().run(),r.onClose()},{disabled:!A}),
50
+ /* @__PURE__ */e("div",{className:"bm-sep"}),R.map(e=>item(`align-${e}`,p("left"===e?"左对齐":"center"===e?"居中对齐":"right"===e?"右对齐":"两端对齐"),()=>{chain().setTextAlign(e).run(),r.onClose()},{active:S===e,disabled:!A}))]}),"color"===y&&/* @__PURE__ */e(DocumentColorPanel,{textColor:"string"==typeof b.getAttributes("textStyle").color?b.getAttributes("textStyle").color:null,highlightColor:"string"==typeof b.getAttributes("highlight").color?b.getAttributes("highlight").color:null,onTextColor:e=>{e?chain().setMark("textStyle",{color:e}).run():chain().unsetMark("textStyle").run()},onHighlightColor:e=>{e?chain().setMark("highlight",{color:e}).run():chain().unsetMark("highlight").run()},onReset:()=>{chain().unsetMark("textStyle").unsetMark("highlight").run(),r.onClose()}}),"insert-below"===y&&D.map(e=>item(e.icon,e.label,()=>function runInsert(e){e.panel?M({mode:e.panel,x:0,y:0}):insertCommand(e)}(e)))]}),E&&/* @__PURE__ */e(InsertPicker,{mode:E.mode,x:((null==V?void 0:V.left)??0)+((null==(i=H.current)?void 0:i.offsetWidth)??240)+6,y:Math.max(0,((null==(a=O.current)?void 0:a.getBoundingClientRect().top)??0)-((null==(s=B.current)?void 0:s.getBoundingClientRect().top)??0)),boundTop:8-((null==(c=B.current)?void 0:c.getBoundingClientRect().top)??0),boundBottom:innerHeight-8-((null==(m=B.current)?void 0:m.getBoundingClientRect().top)??0),onPick:function insertWithPanel(e){const t=D.find(e=>e.panel===(null==E?void 0:E.mode));M(null),t&&insertCommand(t,e)},onClose:()=>M(null)})]})}async function writeRichTable(e,t){var n;if("undefined"==typeof ClipboardItem||!(null==(n=navigator.clipboard)?void 0:n.write))throw new Error("rich clipboard unavailable");const o=document.createElement("div");o.appendChild(Oe.fromSchema(t).serializeFragment(qe.from(e))),await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([o.innerHTML],{type:"text/html"}),"text/plain":new Blob([e.textBetween(0,e.content.size,"\n")],{type:"text/plain"})})])}async function copyTableToClipboard(e,t,n,o=writeRichTable){if(e.isDestroyed||!e.isEditable)return null;const r=e.state.doc,l=r.nodeAt(t);return"table"!==(null==l?void 0:l.type.spec.tableRole)?null:(await o(l,e.state.schema),n?e.isDestroyed||!e.isEditable||e.state.doc!==r||e.state.doc.nodeAt(t)!==l?"changed":(e.view.dispatch(e.state.tr.deleteRange(t,t+l.nodeSize)),e.view.focus(),"cut"):"copied")}const anchorOf=e=>{const t=e.currentTarget.getBoundingClientRect();return{left:t.left,top:t.top,right:t.right,bottom:t.bottom}};function TableControls({editor:l,hover:i,revision:a,onNotice:s,onBlockDrag:c}){var u,d,m;const b=o().text,{portal:w}=r(),y=h(null),[k,x]=v(!1),[C,E]=v("none"),[M,L]=v(!1),[S,A]=v("table"),[T,B]=v(!1),[I,P]=v(!1),[R,Z]=v(!1),[ee,te]=v(""),[ne,oe]=v(!1),[re,le]=v({width:0,height:0}),[,ie]=v(0),[ae,se]=v(null),[ce,ue]=v(null),de=h(null),me=h(null),pe=h(null),he=h(null),ve=h(null),fe=h(null),[ge,be]=v({left:0,top:0,maxHeight:480}),[we,ye]=v({left:0,top:0});f(()=>{var e;if(!M||!ae)return;const t=de.current;t&&be(function placeTableMenu(e,t,n){const o=n.topInset,r=Math.max(o,Math.min(e.top,n.height-12)),l=Math.max(r,Math.min(e.bottom,n.height-12)),i=Math.max(0,n.height-12-l-6),a=Math.max(0,r-6-o),s=t.height<=i||t.height>a&&i>=a,c=s?i:a,u=Math.min(t.height,c);return{left:Math.max(12,Math.min(e.left,n.width-t.width-12)),top:s?l+6:r-6-u,maxHeight:c}}(ae,{width:t.offsetWidth,height:((null==(e=pe.current)?void 0:e.scrollHeight)??t.scrollHeight)+2},{width:innerWidth,height:innerHeight,topInset:12}))},[M,ae,R,I,S]),g(()=>{var e;if(!(M&&de.current&&pe.current&&he.current))return;const t=function attachOverlayScrollbar(e,t,n){const o=document.createElement("div"),r=document.createElement("div");o.className="w-overlay-scrollbar__track",r.className="w-overlay-scrollbar__thumb";const l=t.id;let i,a;t.id||(t.id=`wd-scroll-${crypto.randomUUID()}`),r.tabIndex=0,r.setAttribute("role","scrollbar"),r.setAttribute("aria-label","菜单滚动条"),r.setAttribute("aria-orientation","vertical"),r.setAttribute("aria-controls",t.id),r.setAttribute("aria-valuemin","0"),o.append(r),e.append(o);let s=0;const c=new AbortController;function active(){e.classList.add("is-scrolling"),clearTimeout(i),i=setTimeout(()=>{a||e.classList.remove("is-scrolling")},700)}function update(){const e=Math.max(0,t.scrollHeight-t.clientHeight);o.hidden=e<=1;const n=o.clientHeight;s=Math.min(n,Math.max(28,n*t.clientHeight/Math.max(1,t.scrollHeight))),r.style.height=`${s}px`,r.style.transform=`translateY(${e?(n-s)*t.scrollTop/e:0}px)`,r.setAttribute("aria-valuemax",String(Math.round(e))),r.setAttribute("aria-valuenow",String(Math.round(t.scrollTop)))}function finish(){a&&(a=void 0,e.classList.remove("is-dragging-scrollbar"),active())}t.addEventListener("scroll",()=>{update(),active()},{passive:!0,signal:c.signal}),r.addEventListener("pointerdown",n=>{0===n.button&&(n.preventDefault(),n.stopPropagation(),r.focus({preventScroll:!0}),a={y:n.clientY,top:t.scrollTop,maximum:t.scrollHeight-t.clientHeight,travel:Math.max(1,o.clientHeight-s)},e.classList.add("is-dragging-scrollbar"),active())},{signal:c.signal}),window.addEventListener("pointermove",e=>{a&&(e.preventDefault(),t.scrollTop=Math.max(0,Math.min(a.maximum,a.top+(e.clientY-a.y)*a.maximum/a.travel)),update())},{signal:c.signal}),window.addEventListener("pointerup",finish,{signal:c.signal}),window.addEventListener("pointercancel",finish,{signal:c.signal}),window.addEventListener("blur",finish,{signal:c.signal}),o.addEventListener("pointerdown",e=>{if(e.target!==o||0!==e.button)return;e.preventDefault(),e.stopPropagation();const n=o.getBoundingClientRect().top;t.scrollTop=(e.clientY-n-s/2)/Math.max(1,o.clientHeight-s)*(t.scrollHeight-t.clientHeight),update(),active()},{signal:c.signal}),r.addEventListener("keydown",e=>{const n={ArrowDown:32,ArrowUp:-32,PageDown:.8*t.clientHeight,PageUp:.8*-t.clientHeight}[e.key];void 0===n&&"Home"!==e.key&&"End"!==e.key||(e.preventDefault(),e.stopPropagation(),t.scrollTop="Home"===e.key?0:"End"===e.key?t.scrollHeight:t.scrollTop+n,update(),active())},{signal:c.signal});const u=new ResizeObserver(update);return u.observe(t),u.observe(n),u.observe(e),update(),{update:update,destroy(){c.abort(),u.disconnect(),clearTimeout(i),o.remove(),e.classList.remove("is-scrolling","is-dragging-scrollbar"),l||t.removeAttribute("id")}}}(de.current,pe.current,he.current);return null==(e=de.current.querySelector('[role="menuitem"]'))||e.focus({preventScroll:!0}),()=>t.destroy()},[M,w]),f(()=>{if("none"===C||!ce)return;const measure=()=>{var e;const t=me.current,n=null==(e=fe.current)?void 0:e.getBoundingClientRect();if(!t||!n)return;const o=Ee({trigger:n,panel:{width:t.offsetWidth,height:t.offsetHeight},position:"bl",gap:6,viewport:{width:innerWidth,height:innerHeight}});ye(e=>e.left===o.left&&e.top===o.top?e:{left:o.left,top:o.top})};measure();const e=new ResizeObserver(measure);me.current&&e.observe(me.current);let t=0;const scroll=()=>{cancelAnimationFrame(t),t=requestAnimationFrame(measure)};return window.addEventListener("scroll",scroll,!0),()=>{e.disconnect(),cancelAnimationFrame(t),window.removeEventListener("scroll",scroll,!0)}}),g(()=>{const update=e=>{var t,n;e.target instanceof Node&&((null==(t=de.current)?void 0:t.contains(e.target))||(null==(n=me.current)?void 0:n.contains(e.target)))||ie(e=>e+1)};return window.addEventListener("scroll",update,!0),window.addEventListener("resize",update),()=>{window.removeEventListener("scroll",update,!0),window.removeEventListener("resize",update)}},[]);const ke=h(l.state.selection),xe=h(l.state.doc);g(()=>{ke.current.eq(l.state.selection)&&xe.current===l.state.doc||(E("none"),x(!1),Z(!1),ke.current=l.state.selection,xe.current=l.state.doc)},[a,l]);const Me=z(l.view),Le=(null==i?void 0:i.cellPos)??Me,Ne=null==Le?null:H(l.view,Le),De=Ne&&i?{...Ne,rowIndex:i.rowIndex,colIndex:i.colIndex}:Ne,Se=l.state.selection instanceof Ye?l.state.selection:null,Ae=!!i||!!Se||M,Te=l.can().mergeCells(),Be=l.can().splitCell(),Ie=O(l,"row"),Pe=O(l,"column"),Re=l.getAttributes("tableCell").align??l.getAttributes("tableHeader").align,ze="string"==typeof l.getAttributes("textStyle").color?l.getAttributes("textStyle").color:null,He="string"==typeof l.getAttributes("highlight").color?l.getAttributes("highlight").color:null,Oe="string"==typeof(l.getAttributes("tableCell").backgroundColor??l.getAttributes("tableHeader").backgroundColor)?l.getAttributes("tableCell").backgroundColor??l.getAttributes("tableHeader").backgroundColor:null,chain=()=>l.chain().focus(),qe=l.view.dom.closest(".editor-shell");function axisDown(e,t,n){var o;if(!De||0!==n.button)return;n.preventDefault(),null==(o=y.current)||o.call(y);const r=l.view,i=r.state.doc,a=r.state.selection,s=i.resolve(De.cellPos),c=s.node(-1),u=s.start(-1),d=Ue.get(c),m="row"===e?De.rows:De.columns,p=null==qe?void 0:qe.getBoundingClientRect();if(!p)return;const select=n=>{const o=Math.min(t,n),l=Math.max(t,n),a="row"===e?o*d.width:o,s="row"===e?(l+1)*d.width-1:(d.height-1)*d.width+l;r.dispatch(r.state.tr.setSelection(Ye.create(i,u+d.map[a],u+d.map[s]))),r.focus()};select(t);const move=t=>{var n;if(!l.isEditable||r.state.doc!==i)return void(null==(n=y.current)||n.call(y));const o="row"===e?t.clientY-p.top:t.clientX-p.left,a=m.reduce((e,t)=>Math.abs(t.start+t.size/2-o)<Math.abs(e.start+e.size/2-o)?t:e);select(a.index),t.preventDefault()},key=e=>{var t;"Escape"===e.key&&(r.state.doc===i&&r.dispatch(r.state.tr.setSelection(a)),e.preventDefault(),null==(t=y.current)||t.call(y))},done=()=>{var e;return null==(e=y.current)?void 0:e.call(y)};y.current=()=>{window.removeEventListener("mousemove",move,!0),window.removeEventListener("mouseup",done,!0),window.removeEventListener("keydown",key,!0),window.removeEventListener("blur",done),y.current=null},window.addEventListener("mousemove",move,!0),window.addEventListener("mouseup",done,!0),window.addEventListener("keydown",key,!0),window.addEventListener("blur",done)}g(()=>{const context=e=>{if(!(l.isEditable&&e.target instanceof Element))return;const t=e.target.closest("td,th");if(!t)return;const n=W(l.view,t);null!==n&&(e.preventDefault(),j(l.view,n),E("none"),A("cell"),B(!1),ve.current=null,P(!1),se({left:e.clientX,right:e.clientX,top:e.clientY,bottom:e.clientY}),L(!0))};return l.view.dom.addEventListener("contextmenu",context,!0),()=>{var e;l.isDestroyed||l.view.dom.removeEventListener("contextmenu",context,!0),null==(e=y.current)||e.call(y)}},[l]),g(()=>{if(!M&&"none"===C)return;const close=e=>{var t,n;e.target instanceof Element&&((null==(t=de.current)?void 0:t.contains(e.target))||(null==(n=me.current)?void 0:n.contains(e.target))||e.target.closest(".tbl-ui-host"))||(L(!1),E("none"))},resize=()=>{L(!1),E("none")},scroll=e=>{var t,n;e.target instanceof Node&&((null==(t=de.current)?void 0:t.contains(e.target))||(null==(n=me.current)?void 0:n.contains(e.target)))||L(!1)};return document.addEventListener("pointerdown",close,!0),window.addEventListener("resize",resize),window.addEventListener("scroll",scroll,!0),()=>{document.removeEventListener("pointerdown",close,!0),window.removeEventListener("resize",resize),window.removeEventListener("scroll",scroll,!0)}},[M,C]),g(()=>{const escape=e=>{var t,n;"Escape"!==e.key||e.isComposing||("none"!==C?(e.preventDefault(),E("none"),null==(t=fe.current)||t.focus({preventScroll:!0})):M?(e.preventDefault(),L(!1),null==(n=ve.current)||n.focus({preventScroll:!0})):Se&&(e.preventDefault(),x(!0),l.view.focus()))};return document.addEventListener("keydown",escape),()=>document.removeEventListener("keydown",escape)});const $e=function selectedBounds(){var e;if(!qe||!Se)return null;const t=[];Se.forEachCell((e,n)=>{const o=l.view.nodeDOM(n);o instanceof HTMLElement&&t.push(o.getBoundingClientRect())});const n=De?null==(e=l.view.nodeDOM(De.cellPos))?void 0:e.closest("table"):null;if(!n)return null;const o=Y(t,(n.closest(".tableWrapper")??n).getBoundingClientRect());if(!o)return null;const r=qe.getBoundingClientRect(),i=function placeTableToolbar(e,t,n){const o=Math.min(t.width,Math.max(0,n.width-24)),r=e.top-14-t.height;return{left:Math.max(12,Math.min((e.left+e.right-o)/2,n.width-o-12)),top:r>=n.topInset?r:Math.max(n.topInset,Math.min(e.top+40,n.height-t.height-12))}}(o,re,{width:innerWidth,height:innerHeight,topInset:66});return{left:o.left-r.left,top:o.top-r.top,width:o.right-o.left,height:o.bottom-o.top,toolbarLeft:i.left,toolbarTop:i.top}}();function mark(e){return U(l,e)}function toggleMark(e){_(l,e,mark(e)?null:{})}function showContext(e,t="table"){var n;if(!e)return;const o=e.currentTarget;if(M&&ve.current===o)return void L(!1);ve.current=o;const r=null==(n=o.closest(".tbl-cellbar"))?void 0:n.getBoundingClientRect();"table"===t&&De&&$(l.view,De.cellPos,"table");const i=anchorOf(e);E("none"),P(!1),A(t),B(!!r),se({...i,top:(null==r?void 0:r.top)??i.top,bottom:(null==r?void 0:r.bottom)??i.bottom}),L(!0)}async function copyTable(e){const t=tableTarget();if(t&&!ne&&l.isEditable){oe(!0);try{const n=await copyTableToClipboard(l,t.pos,e);"changed"===n?null==s||s("表格已复制;内容发生变化,未执行剪切。"):n&&(null==s||s("cut"===n?"表格已剪切。":"表格已复制。")),L(!1)}catch{null==s||s(b("无法写入剪贴板,请允许浏览器访问剪贴板后重试。"))}finally{oe(!1)}}}function showPanel(e,t){C!==e?(fe.current=t.currentTarget,L(!1),ue(anchorOf(t)),E(e)):E("none")}function tableTarget(){const e=null==Le?null:q(l.view,Le),t=null===e?null:l.state.doc.nodeAt(e);return null!==e&&t?{pos:e,node:t}:null}function applyWidth(){var e;const t=null==(e=X(l))?void 0:e.col,n=Math.round(Number(ee));null==t||!Number.isFinite(n)||n<40||n>2e3||(G(l,t,n),Z(!1),L(!1))}const Fe=[{key:"color",label:b("表格文字颜色"),tip:b("文字颜色"),hint:b("只改文字本身的颜色,不影响格子底色"),colors:N,current:ze},{key:"highlight",label:b("表格文字高亮"),tip:b("文字高亮"),hint:b("只给文字加荧光底色,格子仍是原本的底色"),colors:D,current:He},{key:"background",label:b("单元格底色"),tip:b("单元格底色"),hint:b("给整个单元格铺底色,与文字高亮互不影响"),colors:_e,current:Oe}],menuItem=(n,o,r,l={})=>/* @__PURE__ */t("button",{type:"button",role:"menuitem",className:"ctx-item"+(l.danger?" danger":""),disabled:l.disabled,"aria-checked":l.checked,"aria-expanded":l.expanded,onMouseDown:e=>e.preventDefault(),onClick:r,children:[
58
51
  /* @__PURE__ */e(Ce,{name:n,size:16}),
59
- /* @__PURE__ */e("span",{children:o}),r.checked&&/* @__PURE__ */e(Ce,{name:"check",size:16,className:"ctx-chevron"}),void 0!==r.expanded&&/* @__PURE__ */e(Ce,{name:"chevron-down",size:14,className:"ctx-chevron"})]}),tool=(n,o,l,r=!1,i=!1,a)=>/* @__PURE__ */t("button",{type:"button",className:"tool"+(r?" on":""),"aria-label":n,title:n,"aria-pressed":r,"aria-disabled":i||void 0,onClick:()=>{i||l()},children:[
52
+ /* @__PURE__ */e("span",{children:o}),l.checked&&/* @__PURE__ */e(Ce,{name:"check",size:16,className:"ctx-chevron"}),void 0!==l.expanded&&/* @__PURE__ */e(Ce,{name:"chevron-down",size:14,className:"ctx-chevron"})]}),tool=(n,o,r,l=!1,i=!1,a)=>/* @__PURE__ */t("button",{type:"button",className:"tool"+(l?" on":""),"aria-label":n,title:n,"aria-pressed":l,"aria-disabled":i||void 0,onClick:()=>{i||r()},children:[
60
53
  /* @__PURE__ */e(Ce,{name:o,size:["bold","italic","strike","underline"].includes(o)?20:18}),a]});/* @__PURE__ */
61
54
  return t(n,{children:[
62
55
  /* @__PURE__ */t("div",{className:"tbl-ui-host",children:[De&&Ae&&/* @__PURE__ */t(n,{children:[
63
56
  /* @__PURE__ */t("div",{className:"tbl-corner",style:{left:function cornerLeft(){return De&&qe?Math.max(De.contentLeft-8-44,8-qe.getBoundingClientRect().left):0}(),top:De.tableTop+((null==(u=De.rows[0])?void 0:u.size)??26)/2-13},children:[
64
57
  /* @__PURE__ */e("button",{type:"button","aria-label":b("表格操作"),"aria-haspopup":"menu",title:b("表格操作"),onMouseDown:e=>e.preventDefault(),onClick:e=>showContext(e,"table"),children:/* @__PURE__ */e(Ce,{name:"table",size:18})}),
65
- /* @__PURE__ */e("button",{type:"button",className:"tbl-grip","aria-label":b("拖动或打开表格菜单"),"aria-haspopup":"menu",title:b("拖动表格"),draggable:!1,onMouseDown:e=>{const t=q(r.view,De.cellPos),n=anchorOf(e);null!==t&&(null==s||s(t,e.nativeEvent,()=>{$(r.view,De.cellPos,"table"),A("table"),B(!1),P(!1),ce(n),N(!0)}))},onClick:e=>{0===e.detail&&showContext(e,"table")},children:/* @__PURE__ */e(Ce,{name:"handle",size:16})})]}),De.rows.map(t=>/* @__PURE__ */e("button",{type:"button",className:"tbl-axis tbl-row-axis"+(t.index===De.rowIndex?" current":""),"aria-label":b("选择第 {0} 行",{0:t.index+1}),title:b("选择第 {0} 行",{0:t.index+1}),style:{left:De.tableLeft-10,top:t.start+t.size/2-12},onMouseDown:e=>axisDown("row",t.index,e),onClick:e=>{0===e.detail&&$(r.view,De.cellPos,"row",t.index)}},`row-${t.index}`)),De.columns.map(t=>/* @__PURE__ */e("button",{type:"button",className:"tbl-axis tbl-col-axis"+(t.index===De.colIndex?" current":""),"aria-label":b("选择第 {0} 列",{0:t.index+1}),title:b("选择第 {0} 列",{0:t.index+1}),style:{left:t.start+t.size/2-12,top:De.tableTop-10},onMouseDown:e=>axisDown("column",t.index,e),onClick:e=>{0===e.detail&&$(r.view,De.cellPos,"column",t.index)}},`col-${t.index}`)),[...De.rows.map(e=>({index:e.index,start:e.start})),{index:De.rows.length,start:De.tableTop+De.tableHeight}].map(t=>/* @__PURE__ */e("button",{type:"button",className:"tbl-boundary tbl-boundary-row","aria-label":b("在第 {0} 行位置添加一行",{0:t.index+1}),title:b("添加一行"),style:{left:De.tableLeft-14,top:t.start-10,"--insert-length":`${De.tableWidth}px`},onMouseDown:e=>e.preventDefault(),onClick:()=>F(r,De.cellPos,"row",t.index),children:/* @__PURE__ */e(Ce,{name:"plus",size:14})},`row-boundary-${t.index}`)),[...De.columns.map(e=>({index:e.index,start:e.start})),{index:De.columns.length,start:((null==(d=De.columns.at(-1))?void 0:d.start)??0)+((null==(m=De.columns.at(-1))?void 0:m.size)??0)}].map(t=>/* @__PURE__ */e("button",{type:"button",className:"tbl-boundary tbl-boundary-col","aria-label":b("在第 {0} 列位置添加一列",{0:t.index+1}),title:b("添加一列"),style:{left:t.start-10,top:De.tableTop-14,"--insert-length":`${De.tableHeight}px`},onMouseDown:e=>e.preventDefault(),onClick:()=>F(r,De.cellPos,"column",t.index),children:/* @__PURE__ */e(Ce,{name:"plus",size:14})},`col-boundary-${t.index}`))]}),$e&&/* @__PURE__ */t(n,{children:[
66
- /* @__PURE__ */e("div",{className:"tbl-selection",style:{left:$e.left,top:$e.top,width:$e.width,height:$e.height}}),(!M||T)&&/* @__PURE__ */e("button",{type:"button",className:"tbl-selection-more","aria-label":b("打开单元格格式"),"aria-expanded":!!Se&&!k,style:{left:$e.left+$e.width/2-16,top:$e.top-10},onMouseDown:e=>e.preventDefault(),onClick:()=>{null!=Me&&(Se?C(!k):(r.view.dispatch(r.state.tr.setSelection(Fe.create(r.state.doc,Me))),r.view.focus(),C(!1)))},children:/* @__PURE__ */e(Ce,{name:"ellipsis",size:20})}),Se&&!k&&(!M||T)&&/* @__PURE__ */e("div",{className:"tbl-cellbar",role:"toolbar","aria-label":b("表格选区格式"),ref:e=>{if(e){const{width:t,height:n}=e.getBoundingClientRect();t===le.width&&n===le.height||re({width:t,height:n})}},style:{left:$e.toolbarLeft,top:$e.toolbarTop},onMouseDown:e=>e.preventDefault(),children:/* @__PURE__ */t("div",{className:"tbl-tools",children:[tool(b("标题列"),"table-header-column",()=>chain().toggleHeaderColumn().run(),Pe),tool(b("标题行"),"table-header-row",()=>chain().toggleHeaderRow().run(),Ie),
58
+ /* @__PURE__ */e("button",{type:"button",className:"tbl-grip","aria-label":b("拖动或打开表格菜单"),"aria-haspopup":"menu",title:b("拖动表格"),draggable:!1,onMouseDown:e=>{const t=q(l.view,De.cellPos),n=anchorOf(e);null!==t&&(null==c||c(t,e.nativeEvent,()=>{$(l.view,De.cellPos,"table"),A("table"),B(!1),P(!1),se(n),L(!0)}))},onClick:e=>{0===e.detail&&showContext(e,"table")},children:/* @__PURE__ */e(Ce,{name:"handle",size:16})})]}),De.rows.map(t=>/* @__PURE__ */e("button",{type:"button",className:"tbl-axis tbl-row-axis"+(t.index===De.rowIndex?" current":""),"aria-label":b("选择第 {0} 行",{0:t.index+1}),title:b("选择第 {0} 行",{0:t.index+1}),style:{left:De.tableLeft-10,top:t.start+t.size/2-12},onMouseDown:e=>axisDown("row",t.index,e),onClick:e=>{0===e.detail&&$(l.view,De.cellPos,"row",t.index)}},`row-${t.index}`)),De.columns.map(t=>/* @__PURE__ */e("button",{type:"button",className:"tbl-axis tbl-col-axis"+(t.index===De.colIndex?" current":""),"aria-label":b("选择第 {0} 列",{0:t.index+1}),title:b("选择第 {0} 列",{0:t.index+1}),style:{left:t.start+t.size/2-12,top:De.tableTop-10},onMouseDown:e=>axisDown("column",t.index,e),onClick:e=>{0===e.detail&&$(l.view,De.cellPos,"column",t.index)}},`col-${t.index}`)),[...De.rows.map(e=>({index:e.index,start:e.start})),{index:De.rows.length,start:De.tableTop+De.tableHeight}].map(t=>/* @__PURE__ */e("button",{type:"button",className:"tbl-boundary tbl-boundary-row","aria-label":b("在第 {0} 行位置添加一行",{0:t.index+1}),title:b("添加一行"),style:{left:De.tableLeft-14,top:t.start-10,"--insert-length":`${De.tableWidth}px`},onMouseDown:e=>e.preventDefault(),onClick:()=>F(l,De.cellPos,"row",t.index),children:/* @__PURE__ */e(Ce,{name:"plus",size:14})},`row-boundary-${t.index}`)),[...De.columns.map(e=>({index:e.index,start:e.start})),{index:De.columns.length,start:((null==(d=De.columns.at(-1))?void 0:d.start)??0)+((null==(m=De.columns.at(-1))?void 0:m.size)??0)}].map(t=>/* @__PURE__ */e("button",{type:"button",className:"tbl-boundary tbl-boundary-col","aria-label":b("在第 {0} 列位置添加一列",{0:t.index+1}),title:b("添加一列"),style:{left:t.start-10,top:De.tableTop-14,"--insert-length":`${De.tableHeight}px`},onMouseDown:e=>e.preventDefault(),onClick:()=>F(l,De.cellPos,"column",t.index),children:/* @__PURE__ */e(Ce,{name:"plus",size:14})},`col-boundary-${t.index}`))]}),$e&&/* @__PURE__ */t(n,{children:[
59
+ /* @__PURE__ */e("div",{className:"tbl-selection",style:{left:$e.left,top:$e.top,width:$e.width,height:$e.height}}),(!M||T)&&/* @__PURE__ */e("button",{type:"button",className:"tbl-selection-more","aria-label":b("打开单元格格式"),"aria-expanded":!!Se&&!k,style:{left:$e.left+$e.width/2-16,top:$e.top-10},onMouseDown:e=>e.preventDefault(),onClick:()=>{null!=Me&&(Se?x(!k):(l.view.dispatch(l.state.tr.setSelection(Ye.create(l.state.doc,Me))),l.view.focus(),x(!1)))},children:/* @__PURE__ */e(Ce,{name:"ellipsis",size:20})}),Se&&!k&&(!M||T)&&/* @__PURE__ */e("div",{className:"tbl-cellbar",role:"toolbar","aria-label":b("表格选区格式"),ref:e=>{if(e){const{width:t,height:n}=e.getBoundingClientRect();t===re.width&&n===re.height||le({width:t,height:n})}},style:{left:$e.toolbarLeft,top:$e.toolbarTop},onMouseDown:e=>e.preventDefault(),children:/* @__PURE__ */t("div",{className:"tbl-tools",children:[tool(b("标题列"),"table-header-column",()=>chain().toggleHeaderColumn().run(),Pe),tool(b("标题行"),"table-header-row",()=>chain().toggleHeaderRow().run(),Ie),
67
60
  /* @__PURE__ */e("span",{className:"tool-sep","aria-hidden":"true"}),tool(b("合并单元格"),"merge",()=>chain().mergeCells().run(),!1,!Te),tool(b("拆分单元格"),"split",()=>chain().splitCell().run(),!1,!Be),
68
61
  /* @__PURE__ */e("span",{className:"tool-sep","aria-hidden":"true"}),
69
- /* @__PURE__ */t("button",{type:"button",className:"tool"+("align"===x?" on":""),"aria-label":b("单元格对齐"),onClick:e=>showPanel("align",e),children:[
62
+ /* @__PURE__ */t("button",{type:"button",className:"tool"+("align"===C?" on":""),"aria-label":b("单元格对齐"),onClick:e=>showPanel("align",e),children:[
70
63
  /* @__PURE__ */e(Ce,{name:`align-${Re??"left"}`,size:18}),
71
64
  /* @__PURE__ */e(Ce,{name:"chevron-down",size:12})]}),
72
- /* @__PURE__ */e("span",{className:"tool-sep","aria-hidden":"true"}),tool(b("表格文字加粗"),"bold",()=>toggleMark("bold"),mark("bold")),tool(b("表格文字斜体"),"italic",()=>toggleMark("italic"),mark("italic")),tool(b("表格文字删除线"),"strike",()=>toggleMark("strike"),mark("strike")),tool(b("表格文字下划线"),"underline",()=>toggleMark("underline"),mark("underline")),Ye.map(n=>/* @__PURE__ */t("button",{type:"button",className:"tool color-tool"+(x===n.key?" on":""),"aria-label":b(n.label),title:b(n.tip),"aria-haspopup":"dialog","aria-expanded":x===n.key,onClick:e=>showPanel(n.key,e),children:[
65
+ /* @__PURE__ */e("span",{className:"tool-sep","aria-hidden":"true"}),tool(b("表格文字加粗"),"bold",()=>toggleMark("bold"),mark("bold")),tool(b("表格文字斜体"),"italic",()=>toggleMark("italic"),mark("italic")),tool(b("表格文字删除线"),"strike",()=>toggleMark("strike"),mark("strike")),tool(b("表格文字下划线"),"underline",()=>toggleMark("underline"),mark("underline")),Fe.map(n=>/* @__PURE__ */t("button",{type:"button",className:"tool color-tool"+(C===n.key?" on":""),"aria-label":b(n.label),title:b(n.tip),"aria-haspopup":"dialog","aria-expanded":C===n.key,onClick:e=>showPanel(n.key,e),children:[
73
66
  /* @__PURE__ */e(Ce,{name:"color"===n.key?"text-color":"highlight"===n.key?"marker":"cell-fill",size:20}),
74
67
  /* @__PURE__ */e("span",{className:"color-bar",style:{background:n.current??"transparent"},"aria-hidden":"true"})]},n.key)),
75
68
  /* @__PURE__ */e("span",{className:"tool-sep","aria-hidden":"true"}),
76
- /* @__PURE__ */e("button",{type:"button",className:"tool","aria-label":b("选择整个表格"),onClick:()=>$(r.view,De.cellPos,"table"),children:b("全选")}),
77
- /* @__PURE__ */e("button",{type:"button",className:"tool","aria-label":b("更多表格操作"),"aria-haspopup":"menu","aria-expanded":M,onClick:e=>showContext(e,"cell"),children:/* @__PURE__ */e(Ce,{name:"ellipsis",size:20})})]})})]})]}),w&&p(/* @__PURE__ */t(n,{children:["align"===x&&/* @__PURE__ */e("div",{ref:me,className:"tbl-align-menu",style:{position:"fixed",left:we.left,top:we.top},role:"menu","aria-label":b("单元格对齐菜单"),onMouseDown:e=>e.preventDefault(),children:V.map(n=>/* @__PURE__ */t("button",{type:"button",role:"menuitemradio","aria-checked":(Re??"left")===n,onClick:()=>{chain().setCellAttribute("align",n).run(),E("none")},children:[
69
+ /* @__PURE__ */e("button",{type:"button",className:"tool","aria-label":b("选择整个表格"),onClick:()=>$(l.view,De.cellPos,"table"),children:b("全选")}),
70
+ /* @__PURE__ */e("button",{type:"button",className:"tool","aria-label":b("更多表格操作"),"aria-haspopup":"menu","aria-expanded":M,onClick:e=>showContext(e,"cell"),children:/* @__PURE__ */e(Ce,{name:"ellipsis",size:20})})]})})]})]}),w&&p(/* @__PURE__ */t(n,{children:["align"===C&&/* @__PURE__ */e("div",{ref:me,className:"tbl-align-menu",style:{position:"fixed",left:we.left,top:we.top},role:"menu","aria-label":b("单元格对齐菜单"),onMouseDown:e=>e.preventDefault(),children:V.map(n=>/* @__PURE__ */t("button",{type:"button",role:"menuitemradio","aria-checked":(Re??"left")===n,onClick:()=>{chain().setCellAttribute("align",n).run(),E("none")},children:[
78
71
  /* @__PURE__ */e(Ce,{name:`align-${n}`,size:18}),
79
- /* @__PURE__ */e("span",{children:b("left"===n?"左对齐":"center"===n?"居中对齐":"右对齐")}),(Re??"left")===n&&/* @__PURE__ */e(Ce,{name:"check",size:16})]},n))}),Ye.map(n=>x===n.key&&/* @__PURE__ */t("div",{ref:me,className:"tbl-palette",style:{position:"fixed",left:we.left,top:we.top},role:"dialog","aria-label":b("{0}选择",{0:n.tip}),onMouseDown:e=>e.preventDefault(),children:[
72
+ /* @__PURE__ */e("span",{children:b("left"===n?"左对齐":"center"===n?"居中对齐":"右对齐")}),(Re??"left")===n&&/* @__PURE__ */e(Ce,{name:"check",size:16})]},n))}),Fe.map(n=>C===n.key&&/* @__PURE__ */t("div",{ref:me,className:"tbl-palette",style:{position:"fixed",left:we.left,top:we.top},role:"dialog","aria-label":b("{0}选择",{0:n.tip}),onMouseDown:e=>e.preventDefault(),children:[
80
73
  /* @__PURE__ */t("div",{className:"palette-head",children:[
81
74
  /* @__PURE__ */e("span",{className:"palette-title",children:b(n.tip)}),
82
75
  /* @__PURE__ */e("span",{className:"palette-hint",children:b(n.hint)})]}),
83
- /* @__PURE__ */e("div",{className:"palette-grid",children:n.colors.map(t=>/* @__PURE__ */e("button",{type:"button",className:"swatch"+(n.current===t.value?" selected":""),"aria-label":`${b(n.tip)}:${t.value?b(t.name):b("默认颜色")}`,"aria-pressed":n.current===t.value,onClick:()=>function applySwatch(e){"background"===x?(chain().setCellAttribute("backgroundColor",e).run(),E("none")):function setColor(e,t){_(r,e,t?{color:t}:null),E("none")}("color"===x?"textStyle":"highlight",e)}(t.value),children:t.value&&"color"===n.key?/* @__PURE__ */e("span",{className:"glyph",style:{color:t.value},children:"A"}):t.value?/* @__PURE__ */e("span",{style:{background:t.value}}):/* @__PURE__ */e("span",{children:"/"})},t.name))})]},n.key)),M&&/* @__PURE__ */e("div",{ref:de,className:"tbl-ctx w-overlay-scrollbar",style:{position:"fixed",left:fe.left,top:fe.top,maxHeight:fe.maxHeight,width:216},role:"menu","aria-label":b("表格操作菜单"),onMouseDown:e=>{e.target instanceof HTMLInputElement||e.preventDefault()},onContextMenu:e=>e.preventDefault(),onKeyDown:e=>{var t;if(!["ArrowDown","ArrowUp","Home","End"].includes(e.key)||e.target instanceof HTMLInputElement)return;const n=[...(null==(t=de.current)?void 0:t.querySelectorAll('[role^="menuitem"]:not(:disabled)'))??[]];if(!n.length)return;e.preventDefault();const o=n.indexOf(document.activeElement);n["Home"===e.key?0:"End"===e.key?n.length-1:(o+("ArrowDown"===e.key?1:-1)+n.length)%n.length].focus()},children:/* @__PURE__ */e("div",{ref:pe,className:"w-overlay-scrollbar__viewport",style:{maxHeight:Math.max(0,fe.maxHeight-2)},children:/* @__PURE__ */e("div",{ref:he,children:/* @__PURE__ */t(n,"table"===S?{children:[menuItem("columns",b("均分列宽"),function distribute(){const e=tableTarget(),t=e?r.view.nodeDOM(e.pos):null,n=t instanceof HTMLElement?t.matches("table")?t:t.querySelector("table"):null,o=(null==n?void 0:n.closest(".tableWrapper"))??n;o&&K(r,o.clientWidth-2),N(!1)}),menuItem("palette",b("表格样式"),()=>P(!I),{expanded:I}),I&&/* @__PURE__ */t("div",{className:"ctx-styles","aria-label":b("表头样式"),children:[[{label:b("浅灰表头"),color:null},{label:b("蓝色表头"),color:"#d0ebff"},{label:b("绿色表头"),color:"#d3f9d8"}].map(n=>/* @__PURE__ */t("button",{type:"button",className:"ctx-item",role:"menuitem",onMouseDown:e=>e.preventDefault(),onClick:()=>function applyStyle(e){J(r,e),N(!1),r.view.focus()}(n.color),children:[
76
+ /* @__PURE__ */e("div",{className:"palette-grid",children:n.colors.map(t=>/* @__PURE__ */e("button",{type:"button",className:"swatch"+(n.current===t.value?" selected":""),"aria-label":`${b(n.tip)}:${t.value?b(t.name):"color"===n.key?b("默认颜色"):b("无")}`,"aria-pressed":n.current===t.value,onClick:()=>function applySwatch(e){"background"===C?(chain().setCellAttribute("backgroundColor",e).run(),E("none")):function setColor(e,t){_(l,e,t?{color:t}:null),E("none")}("color"===C?"textStyle":"highlight",e)}(t.value),children:"color"===n.key?/* @__PURE__ */e("span",{className:"glyph",style:documentSwatchStyle("text",t.value),children:"A"}):t.value?/* @__PURE__ */e("span",{style:"background"===n.key?{backgroundColor:t.value}:documentSwatchStyle("highlight",t.value)}):/* @__PURE__ */e("span",{className:"color-transparency-grid","aria-hidden":"true"})},t.name))})]},n.key)),M&&/* @__PURE__ */e("div",{ref:de,className:"tbl-ctx w-overlay-scrollbar",style:{position:"fixed",left:ge.left,top:ge.top,maxHeight:ge.maxHeight,width:216},role:"menu","aria-label":b("表格操作菜单"),onMouseDown:e=>{e.target instanceof HTMLInputElement||e.preventDefault()},onContextMenu:e=>e.preventDefault(),onKeyDown:e=>{var t;if(!["ArrowDown","ArrowUp","Home","End"].includes(e.key)||e.target instanceof HTMLInputElement)return;const n=[...(null==(t=de.current)?void 0:t.querySelectorAll('[role^="menuitem"]:not(:disabled)'))??[]];if(!n.length)return;e.preventDefault();const o=n.indexOf(document.activeElement);n["Home"===e.key?0:"End"===e.key?n.length-1:(o+("ArrowDown"===e.key?1:-1)+n.length)%n.length].focus()},children:/* @__PURE__ */e("div",{ref:pe,className:"w-overlay-scrollbar__viewport",style:{maxHeight:Math.max(0,ge.maxHeight-2)},children:/* @__PURE__ */e("div",{ref:he,children:/* @__PURE__ */t(n,"table"===S?{children:[menuItem("columns",b("均分列宽"),function distribute(){const e=tableTarget(),t=e?l.view.nodeDOM(e.pos):null,n=t instanceof HTMLElement?t.matches("table")?t:t.querySelector("table"):null,o=(null==n?void 0:n.closest(".tableWrapper"))??n;o&&K(l,o.clientWidth-2),L(!1)}),menuItem("palette",b("表格样式"),()=>P(!I),{expanded:I}),I&&/* @__PURE__ */t("div",{className:"ctx-styles","aria-label":b("表头样式"),children:[[{label:b("浅灰表头"),color:null},{label:b("蓝色表头"),color:"#d0ebff"},{label:b("绿色表头"),color:"#d3f9d8"}].map(n=>/* @__PURE__ */t("button",{type:"button",className:"ctx-item",role:"menuitem",onMouseDown:e=>e.preventDefault(),onClick:()=>function applyStyle(e){J(l,e),L(!1),l.view.focus()}(n.color),children:[
84
77
  /* @__PURE__ */e("span",{className:"ctx-style-swatch",style:{background:n.color??"var(--color-surface-subtle)"}}),n.label]},n.label)),
85
- /* @__PURE__ */e("div",{className:"ctx-sep"}),menuItem("table-header-row",b("标题行"),()=>{chain().toggleHeaderRow().run(),N(!1)},{checked:Ie}),menuItem("table-header-column",b("标题列"),()=>{chain().toggleHeaderColumn().run(),N(!1)},{checked:Pe})]}),
86
- /* @__PURE__ */e("div",{className:"ctx-sep"}),menuItem("cut",b("剪切表格"),()=>{copyTable(!0)},{disabled:ne}),menuItem("copy",b("复制表格"),()=>{copyTable(!1)},{disabled:ne}),menuItem("trash",b("删除表格"),()=>{chain().deleteTable().run(),N(!1)},{danger:!0}),
87
- /* @__PURE__ */e("div",{className:"ctx-sep"}),menuItem("add-below",b("在下方插入段落"),function insertParagraphBelow(){const e=tableTarget();if(!e)return;const t=e.pos+e.node.nodeSize;r.chain().focus().insertContentAt(t,{type:"paragraph"}).setTextSelection(t+1).run(),N(!1)})]}:{children:[menuItem("table-row-plus",b("在上方插入行"),()=>{chain().addRowBefore().run(),N(!1)}),menuItem("table-row-plus",b("在下方插入行"),()=>{chain().addRowAfter().run(),N(!1)}),menuItem("table-col-plus",b("在左侧插入列"),()=>{chain().addColumnBefore().run(),N(!1)}),menuItem("table-col-plus",b("在右侧插入列"),()=>{chain().addColumnAfter().run(),N(!1)}),
88
- /* @__PURE__ */e("div",{className:"ctx-sep"}),menuItem("table",b("切换首行表头"),()=>{chain().toggleHeaderRow().run(),N(!1)}),menuItem("table",b("切换首列表头"),()=>{chain().toggleHeaderColumn().run(),N(!1)}),
89
- /* @__PURE__ */e("div",{className:"ctx-sep"}),Te&&menuItem("merge",b("合并单元格"),()=>{chain().mergeCells().run(),N(!1)}),Be&&menuItem("split",b("拆分单元格"),()=>{chain().splitCell().run(),N(!1)}),
78
+ /* @__PURE__ */e("div",{className:"ctx-sep"}),menuItem("table-header-row",b("标题行"),()=>{chain().toggleHeaderRow().run(),L(!1)},{checked:Ie}),menuItem("table-header-column",b("标题列"),()=>{chain().toggleHeaderColumn().run(),L(!1)},{checked:Pe})]}),
79
+ /* @__PURE__ */e("div",{className:"ctx-sep"}),menuItem("cut",b("剪切表格"),()=>{copyTable(!0)},{disabled:ne}),menuItem("copy",b("复制表格"),()=>{copyTable(!1)},{disabled:ne}),menuItem("trash",b("删除表格"),()=>{chain().deleteTable().run(),L(!1)},{danger:!0}),
80
+ /* @__PURE__ */e("div",{className:"ctx-sep"}),menuItem("add-below",b("在下方插入段落"),function insertParagraphBelow(){const e=tableTarget();if(!e)return;const t=e.pos+e.node.nodeSize;l.chain().focus().insertContentAt(t,{type:"paragraph"}).setTextSelection(t+1).run(),L(!1)})]}:{children:[menuItem("table-row-plus",b("在上方插入行"),()=>{chain().addRowBefore().run(),L(!1)}),menuItem("table-row-plus",b("在下方插入行"),()=>{chain().addRowAfter().run(),L(!1)}),menuItem("table-col-plus",b("在左侧插入列"),()=>{chain().addColumnBefore().run(),L(!1)}),menuItem("table-col-plus",b("在右侧插入列"),()=>{chain().addColumnAfter().run(),L(!1)}),
81
+ /* @__PURE__ */e("div",{className:"ctx-sep"}),menuItem("table",b("切换首行表头"),()=>{chain().toggleHeaderRow().run(),L(!1)}),menuItem("table",b("切换首列表头"),()=>{chain().toggleHeaderColumn().run(),L(!1)}),
82
+ /* @__PURE__ */e("div",{className:"ctx-sep"}),Te&&menuItem("merge",b("合并单元格"),()=>{chain().mergeCells().run(),L(!1)}),Be&&menuItem("split",b("拆分单元格"),()=>{chain().splitCell().run(),L(!1)}),
90
83
  /* @__PURE__ */e("div",{className:"ctx-label",children:b("对齐")}),
91
- /* @__PURE__ */t("div",{className:"ctx-align",children:[V.map(t=>/* @__PURE__ */e("button",{type:"button",className:"al-btn"+(Re===t?" on":""),title:b("left"===t?"左对齐":"center"===t?"居中":"右对齐"),onClick:()=>{chain().setCellAttribute("align",t).run(),N(!1)},children:/* @__PURE__ */e(Ce,{name:`align-${t}`,size:16})},t)),
92
- /* @__PURE__ */e("button",{type:"button",className:"al-btn"+(null===Re?" on":""),title:b("清除对齐"),onClick:()=>{chain().setCellAttribute("align",null).run(),N(!1)},children:b("默认")})]}),
84
+ /* @__PURE__ */t("div",{className:"ctx-align",children:[V.map(t=>/* @__PURE__ */e("button",{type:"button",className:"al-btn"+(Re===t?" on":""),title:b("left"===t?"左对齐":"center"===t?"居中":"右对齐"),onClick:()=>{chain().setCellAttribute("align",t).run(),L(!1)},children:/* @__PURE__ */e(Ce,{name:`align-${t}`,size:16})},t)),
85
+ /* @__PURE__ */e("button",{type:"button",className:"al-btn"+(null===Re?" on":""),title:b("清除对齐"),onClick:()=>{chain().setCellAttribute("align",null).run(),L(!1)},children:b("默认")})]}),
93
86
  /* @__PURE__ */e("div",{className:"ctx-sep"}),R?/* @__PURE__ */t("div",{className:"ctx-width",children:[
94
87
  /* @__PURE__ */e("span",{className:"ctx-label-inline",children:b("列宽")}),
95
88
  /* @__PURE__ */e("input",{className:"ctx-num",type:"number",min:40,max:2e3,placeholder:b("像素"),value:ee,"aria-label":b("列宽像素"),onChange:e=>te(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),applyWidth())}}),
96
89
  /* @__PURE__ */e("span",{className:"faint small",children:b("像素")}),
97
- /* @__PURE__ */e("button",{type:"button",className:"ctx-mini primary",onClick:applyWidth,children:b("应用")})]}):menuItem("columns",b("列宽…"),()=>Z(!0)),menuItem("columns",b("列宽自适应"),()=>{var e;const t=null==(e=X(r))?void 0:e.col;null!=t&&(Q(r,t),N(!1))}),
98
- /* @__PURE__ */e("div",{className:"ctx-sep"}),menuItem("trash",b("删除行"),()=>{chain().deleteRow().run(),N(!1)}),menuItem("trash",b("删除列"),()=>{chain().deleteColumn().run(),N(!1)}),menuItem("table",b("删除表格"),()=>{chain().deleteTable().run(),N(!1)},{danger:!0})]})})})})]}),w)]})}function advanceTarget(e,t){if(!e.valid||!t.docChanged)return;const n=e.from===e.to,o=t.mapping.mapResult(e.from,1),l=t.mapping.mapResult(e.to,-1);if(o.deleted||e.to>e.from&&l.deleted){if(e.nodeJSON&&t.getMeta("y-sync$")){const n=[];if(t.doc.descendants((t,o)=>{JSON.stringify(t.toJSON())===e.nodeJSON&&n.push({pos:o,node:t})}),1===n.length)return e.from=n[0].pos,void(e.to=e.from+n[0].node.nodeSize)}e.valid=!1}else e.from=o.pos,e.to=n?o.pos:Math.max(o.pos,l.pos)}function isRemoteDocumentChange(e){const t=e.getMeta($e);return!!(null==t?void 0:t.isChangeOrigin)&&!t.isUndoRedoOperation}function PagePicker({spaceId:n,excludeId:r,title:i,onClose:a,onPick:c}){const s=o().text,u=i??s("选择页面"),{host:d,portal:m}=l(),g=h(null),y=h(null),[k,C]=v([]),[x,E]=v([]),[M,N]=v(""),[L,D]=v(""),[S,A]=v(!0),[T,B]=v(0),[I,P]=v(0),R=w(),z=h(a);z.current=a,f(()=>{var e;let t=!0;return A(!0),D(""),((null==(e=d.references)?void 0:e.search("",{spaceId:n,excludeId:r}))??Promise.resolve([])).then(e=>{t&&C(e)}).catch(e=>{t&&D(e instanceof Error?e.message:s("页面加载失败"))}).finally(()=>{t&&A(!1)}),()=>{t=!1}},[d.references,n,r,T]),f(()=>{let e=!0;if(E([]),!M.trim())return;const t=setTimeout(()=>{var t;null==(t=d.references)||t.search(M.trim(),{spaceId:n,excludeId:r}).then(t=>{e&&E(t)}).catch(()=>{})},180);return()=>{e=!1,clearTimeout(t)}},[M,d.references,n,r]),f(()=>{var e;if(!m)return;const t=document.activeElement,n=Ee();function keydown(e){e.isComposing||229===e.keyCode||("Escape"===e.key?(e.preventDefault(),e.stopImmediatePropagation(),z.current()):g.current&&Me(g.current,e)&&e.preventDefault())}return null==(e=y.current)||e.focus(),document.addEventListener("keydown",keydown,!0),()=>{n.release(),document.removeEventListener("keydown",keydown,!0),(null==t?void 0:t.isConnected)&&t.focus()}},[m]);const H=b(()=>function pageCandidates(e,t,n,o){const l=[...new Map([...e,...t].map(e=>[e.id,e])).values()].filter(e=>e.id!==o);return n.trim()?Ye(l,n.trim()).map(e=>e.page):l.sort((e,t)=>(t.updatedAt??"").localeCompare(e.updatedAt??""))}(k,x,M,r).slice(0,20),[k,x,M,r]);f(()=>{P(0)},[H]),f(()=>{var e,t;null==(t=null==(e=g.current)?void 0:e.querySelector(`[id="${R}-${I}"]`))||t.scrollIntoView({block:"nearest"})},[I,R]);const O=!!H.length&&!S&&!L;function choose(e){S||L||c(e.id,e.title)}return m?p(/* @__PURE__ */e("div",{className:"picker-backdrop",onMouseDown:e=>{e.target===e.currentTarget&&a()},children:/* @__PURE__ */t("div",{ref:g,className:"picker",role:"dialog","aria-modal":"true","aria-label":u,children:[
99
- /* @__PURE__ */e("input",{ref:y,className:"picker-input",type:"text",role:"combobox","aria-label":u,"aria-autocomplete":"list","aria-controls":O?R:void 0,"aria-expanded":!!O,"aria-activedescendant":O?`${R}-${I}`:void 0,placeholder:s("搜索页面标题(支持拼音)…"),value:M,onChange:e=>{N(e.target.value),P(0)},onKeyDown:e=>{if(!e.nativeEvent.isComposing&&229!==e.keyCode&&O)if("ArrowDown"===e.key||"ArrowUp"===e.key)e.preventDefault(),P(t=>(t+("ArrowDown"===e.key?1:-1)+H.length)%H.length);else if("Enter"===e.key){e.preventDefault();const t=H[I];t&&choose(t)}}}),L?/* @__PURE__ */t("p",{role:"alert",children:[L," ",
100
- /* @__PURE__ */e("button",{type:"button",onClick:()=>B(e=>e+1),children:s("重试")})]}):S?/* @__PURE__ */e("p",{role:"status",children:s("加载中…")}):H.length?/* @__PURE__ */e("ul",{id:R,className:"picker-list",role:"listbox","aria-label":s("页面候选"),children:H.map((t,n)=>/* @__PURE__ */e("li",{id:`${R}-${n}`,role:"option","aria-selected":n===I,className:n===I?"active":void 0,onMouseEnter:()=>P(n),onMouseDown:e=>{e.preventDefault(),choose(t)},children:/* @__PURE__ */e("span",{className:"picker-title",children:t.title})},t.id))}):/* @__PURE__ */e("p",{className:"picker-empty",children:s("没有匹配的页面")})]})}),m):null}function VideoEmbedDialog({initialUrl:n="",onClose:r,onInsert:i}){var a;const c=o(),s=c.text,[u,d]=v(n),[m,p]=v(!1),g=w(),b=h(null);f(()=>{var e;null==(e=b.current)||e.focus()},[]);const y=je(u).data,k=l().video,[C,x]=v("auto"===(null==k?void 0:k.load)),E=!y||((null==(a=null==k?void 0:k.providers)?void 0:a.includes(y.provider))??!0),M=E?y:null,N=E?function videoProblem(e,t=!1,n=Je().text){const o=je(e);return o.data?"":"empty"===o.issue?t?n("请粘贴视频链接。"):"":"short-link"===o.issue?n("B站短链(b23.tv)不能在正文里直接播放,请先在浏览器打开,再复制地址栏里的完整链接。"):"missing-id"===o.issue?n("链接里没有识别到视频 ID,请确认复制的是单个视频的播放页,而不是首页或频道页。"):"unsupported"===o.issue?n("暂不支持该平台的视频链接。目前支持 {0}。",{0:Object.values(Ue).join("、")}):n("链接格式不正确,请粘贴以 http:// 或 https:// 开头的完整地址。")}(u,m,s):c.t("video.notEnabled");function submit(){p(!0),M&&i({...M,autoLoad:C})}/* @__PURE__ */
101
- return e(Ne,{workspace:!0,title:s("嵌入视频"),onClose:r,className:"video-dialog",footer:/* @__PURE__ */t("div",{className:"wr-toolbar",children:[
102
- /* @__PURE__ */e(ke,{onClick:r,children:s("取消")}),
103
- /* @__PURE__ */e(ke,{variant:"primary",disabled:!M,onClick:submit,children:s("插入视频")})]}),children:/* @__PURE__ */t("form",{className:"video-form",onSubmit:e=>{e.preventDefault(),submit()},children:[
90
+ /* @__PURE__ */e("button",{type:"button",className:"ctx-mini primary",onClick:applyWidth,children:b("应用")})]}):menuItem("columns",b("列宽…"),()=>Z(!0)),menuItem("columns",b("列宽自适应"),()=>{var e;const t=null==(e=X(l))?void 0:e.col;null!=t&&(Q(l,t),L(!1))}),
91
+ /* @__PURE__ */e("div",{className:"ctx-sep"}),menuItem("trash",b("删除行"),()=>{chain().deleteRow().run(),L(!1)}),menuItem("trash",b("删除列"),()=>{chain().deleteColumn().run(),L(!1)}),menuItem("table",b("删除表格"),()=>{chain().deleteTable().run(),L(!1)},{danger:!0})]})})})})]}),w)]})}function advanceTarget(e,t){if(!e.valid||!t.docChanged)return;const n=e.from===e.to,o=t.mapping.mapResult(e.from,1),r=t.mapping.mapResult(e.to,-1);if(o.deleted||e.to>e.from&&r.deleted){if(e.nodeJSON&&t.getMeta("y-sync$")){const n=[];if(t.doc.descendants((t,o)=>{JSON.stringify(t.toJSON())===e.nodeJSON&&n.push({pos:o,node:t})}),1===n.length)return e.from=n[0].pos,void(e.to=e.from+n[0].node.nodeSize)}e.valid=!1}else e.from=o.pos,e.to=n?o.pos:Math.max(o.pos,r.pos)}function isRemoteDocumentChange(e){const t=e.getMeta(je);return!!(null==t?void 0:t.isChangeOrigin)&&!t.isUndoRedoOperation}function PagePicker({spaceId:n,excludeId:l,title:i,onClose:a,onPick:s}){const c=o().text,u=i??c("选择页面"),{host:d,portal:m}=r(),f=h(null),y=h(null),[k,x]=v([]),[C,E]=v([]),[M,L]=v(""),[N,D]=v(""),[S,A]=v(!0),[T,B]=v(0),[I,P]=v(0),R=w(),z=h(a);z.current=a,g(()=>{var e;let t=!0;return A(!0),D(""),((null==(e=d.references)?void 0:e.search("",{spaceId:n,excludeId:l}))??Promise.resolve([])).then(e=>{t&&x(e)}).catch(e=>{t&&D(e instanceof Error?e.message:c("页面加载失败"))}).finally(()=>{t&&A(!1)}),()=>{t=!1}},[d.references,n,l,T]),g(()=>{let e=!0;if(E([]),!M.trim())return;const t=setTimeout(()=>{var t;null==(t=d.references)||t.search(M.trim(),{spaceId:n,excludeId:l}).then(t=>{e&&E(t)}).catch(()=>{})},180);return()=>{e=!1,clearTimeout(t)}},[M,d.references,n,l]),g(()=>{var e;if(!m)return;const t=document.activeElement,n=Me();function keydown(e){e.isComposing||229===e.keyCode||("Escape"===e.key?(e.preventDefault(),e.stopImmediatePropagation(),z.current()):f.current&&Le(f.current,e)&&e.preventDefault())}return null==(e=y.current)||e.focus(),document.addEventListener("keydown",keydown,!0),()=>{n.release(),document.removeEventListener("keydown",keydown,!0),(null==t?void 0:t.isConnected)&&t.focus()}},[m]);const H=b(()=>function pageCandidates(e,t,n,o){const r=[...new Map([...e,...t].map(e=>[e.id,e])).values()].filter(e=>e.id!==o);return n.trim()?Je(r,n.trim()).map(e=>e.page):r.sort((e,t)=>(t.updatedAt??"").localeCompare(e.updatedAt??""))}(k,C,M,l).slice(0,20),[k,C,M,l]);g(()=>{P(0)},[H]),g(()=>{var e,t;null==(t=null==(e=f.current)?void 0:e.querySelector(`[id="${R}-${I}"]`))||t.scrollIntoView({block:"nearest"})},[I,R]);const O=!!H.length&&!S&&!N;function choose(e){S||N||s(e.id,e.title)}return m?p(/* @__PURE__ */e("div",{className:"picker-backdrop",onMouseDown:e=>{e.target===e.currentTarget&&a()},children:/* @__PURE__ */t("div",{ref:f,className:"picker",role:"dialog","aria-modal":"true","aria-label":u,children:[
92
+ /* @__PURE__ */e("input",{ref:y,className:"picker-input",type:"text",role:"combobox","aria-label":u,"aria-autocomplete":"list","aria-controls":O?R:void 0,"aria-expanded":!!O,"aria-activedescendant":O?`${R}-${I}`:void 0,placeholder:c("搜索页面标题(支持拼音)…"),value:M,onChange:e=>{L(e.target.value),P(0)},onKeyDown:e=>{if(!e.nativeEvent.isComposing&&229!==e.keyCode&&O)if("ArrowDown"===e.key||"ArrowUp"===e.key)e.preventDefault(),P(t=>(t+("ArrowDown"===e.key?1:-1)+H.length)%H.length);else if("Enter"===e.key){e.preventDefault();const t=H[I];t&&choose(t)}}}),N?/* @__PURE__ */t("p",{role:"alert",children:[N," ",
93
+ /* @__PURE__ */e("button",{type:"button",onClick:()=>B(e=>e+1),children:c("重试")})]}):S?/* @__PURE__ */e("p",{role:"status",children:c("加载中…")}):H.length?/* @__PURE__ */e("ul",{id:R,className:"picker-list",role:"listbox","aria-label":c("页面候选"),children:H.map((t,n)=>/* @__PURE__ */e("li",{id:`${R}-${n}`,role:"option","aria-selected":n===I,className:n===I?"active":void 0,onMouseEnter:()=>P(n),onMouseDown:e=>{e.preventDefault(),choose(t)},children:/* @__PURE__ */e("span",{className:"picker-title",children:t.title})},t.id))}):/* @__PURE__ */e("p",{className:"picker-empty",children:c("没有匹配的页面")})]})}),m):null}function videoProblem(e,t=!1,n=ze().text){const o=Xe(e);return o.data?"":"empty"===o.issue?t?n("请粘贴视频链接。"):"":"short-link"===o.issue?n("B站短链(b23.tv)不能在正文里直接播放,请先在浏览器打开,再复制地址栏里的完整链接。"):"missing-id"===o.issue?n("链接里没有识别到视频 ID,请确认复制的是单个视频的播放页,而不是首页或频道页。"):"unsupported"===o.issue?n("暂不支持该平台的视频链接。目前支持 {0}。",{0:Object.values(Ge).join("、")}):n("链接格式不正确,请粘贴以 http:// 或 https:// 开头的完整地址。")}function VideoEmbedDialog({initialUrl:n="",onClose:l,onInsert:i}){var a;const s=o(),c=s.text,[u,d]=v(n),[m,p]=v(!1),f=w(),b=h(null);g(()=>{var e;null==(e=b.current)||e.focus()},[]);const y=Xe(u).data,k=r().video,[x,C]=v("auto"===(null==k?void 0:k.load)),E=!y||((null==(a=null==k?void 0:k.providers)?void 0:a.includes(y.provider))??!0),M=E?y:null,L=E?videoProblem(u,m,c):s.t("video.notEnabled");function submit(){p(!0),M&&i({...M,autoLoad:x})}/* @__PURE__ */
94
+ return e(Ne,{workspace:!0,title:c("嵌入视频"),onClose:l,className:"video-dialog",footer:/* @__PURE__ */t("div",{className:"wr-toolbar",children:[
95
+ /* @__PURE__ */e(xe,{onClick:l,children:c("取消")}),
96
+ /* @__PURE__ */e(xe,{variant:"primary",disabled:!M,onClick:submit,children:c("插入视频")})]}),children:/* @__PURE__ */t("form",{className:"video-form",onSubmit:e=>{e.preventDefault(),submit()},children:[
104
97
  /* @__PURE__ */t("div",{className:"video-field",children:[
105
- /* @__PURE__ */e("label",{htmlFor:g,children:s("视频链接")}),
106
- /* @__PURE__ */e("input",{ref:b,id:g,type:"url",maxLength:2048,placeholder:s("粘贴视频播放页链接"),autoComplete:"off",spellCheck:!1,value:u,onChange:e=>d(e.target.value)})]}),M?/* @__PURE__ */t("p",{className:"video-status video-status--ok",role:"status",children:[s("已识别"),Ue[M.provider]," ",s("视频"),
107
- /* @__PURE__ */e("span",{className:"video-status-meta",children:M.videoId}),M.page>1?c.t("video.part",{0:M.page}):"",M.startSeconds?c.t("video.from",{0:M.startSeconds}):""]}):N?/* @__PURE__ */e("p",{className:"video-status video-status--error",role:"alert",children:N}):null,M&&/* @__PURE__ */e("p",{className:"video-source",children:_e(M)}),
98
+ /* @__PURE__ */e("label",{htmlFor:f,children:c("视频链接")}),
99
+ /* @__PURE__ */e("input",{ref:b,id:f,type:"url",maxLength:2048,placeholder:c("粘贴视频播放页链接"),autoComplete:"off",spellCheck:!1,value:u,onChange:e=>d(e.target.value)})]}),M?/* @__PURE__ */t("p",{className:"video-status video-status--ok",role:"status",children:[c("已识别"),Ge[M.provider]," ",c("视频"),
100
+ /* @__PURE__ */e("span",{className:"video-status-meta",children:M.videoId}),M.page>1?s.t("video.part",{0:M.page}):"",M.startSeconds?s.t("video.from",{0:M.startSeconds}):""]}):L?/* @__PURE__ */e("p",{className:"video-status video-status--error",role:"alert",children:L}):null,M&&/* @__PURE__ */e("p",{className:"video-source",children:Qe(M)}),
108
101
  /* @__PURE__ */t("div",{className:"video-loading-option",children:[
109
102
  /* @__PURE__ */t("label",{className:"video-loading-choice",children:[
110
- /* @__PURE__ */e("input",{type:"checkbox",checked:C,"aria-describedby":`${g}-loading`,onChange:e=>x(e.target.checked)}),
111
- /* @__PURE__ */e("span",{children:c.t("video.autoLoad")})]}),
112
- /* @__PURE__ */e("p",{id:`${g}-loading`,className:"video-hint",children:c.t("video.autoLoadHint")})]})]})})}const tt={type:"doc",content:[{type:"paragraph"}]},nt=y(function DocumentEditor2(n,s){const g=o(),b=g.text,w=h(null),y=h(null),N=h(null),L=l(),D=L.host,S=be(n),T=be(D),I=h(null),P=be(L),[R,z]=v(0),[H,O]=v(""),[q,$]=v(""),[F,V]=v(null),[W,Y]=v(null),[j,U]=v(null),[_,J]=v(!1),[X,G]=v(void 0),[Q,K]=v(null),[me,ke]=v(null),xe=be(me),[Ee,Me]=v(!1),[Ne,Le]=v(""),[De,Se]=v(!1),[Ae,Te]=v([]),Be=h(!1),Ie=h(0),Pe=h(null),Re=h("image"),[ze,He]=v(null),Oe=h(null),qe=h(null),$e=h(null),Fe=h(null),Ve=h(/* @__PURE__ */new Set),[We,Ye]=v(!1),[je,Ue]=v(null),_e=be(_),Je=h(!1),Xe=h(void 0),Ge=h(!1),Qe=h("explicit"),nt=h(null),ot=be({dragging:We,slash:F,link:me,preview:ze}),lt=h({openId:null,maps:{}}),rt=we();f(()=>()=>{Oe.current&&clearTimeout(Oe.current)},[]),f(()=>{const e=function createBlockMenuHover(e){const t=/* @__PURE__ */new Set;let n,o,l=!1;function clearOpen(){clearTimeout(n),n=void 0}function clearClose(){clearTimeout(o),o=void 0}function reset(){clearOpen(),clearClose(),t.clear()}return{enter:function enter(o){l||(t.add(o),clearClose(),"trigger"!==o||e.isOpen()||n||(n=setTimeout(()=>{n=void 0,!l&&t.has("trigger")&&!e.isOpen()&&e.canOpen()&&e.open()},e.openDelay??120)))},leave:function leave(n){t.delete(n),l||t.size||(clearOpen(),clearClose(),e.isOpen()&&(o=setTimeout(()=>{o=void 0,!l&&!t.size&&e.isOpen()&&e.canClose()&&e.close()},e.closeDelay??240)))},reset:reset,dispose:function dispose(){l=!0,reset()}}}({isOpen:()=>_e.current,canOpen:()=>!(S.current.disabled||Ge.current||ot.current.dragging||ot.current.slash||ot.current.link||ot.current.preview||!qe.current),canClose:()=>{var e,t;return"hover"===Qe.current&&!(null==(t=null==(e=y.current)?void 0:e.querySelector(".block-anchor"))?void 0:t.contains(document.activeElement))},open:()=>{qe.current&&openQuickMenu(qe.current,Xe.current,"hover")},close:closeBlockMenu});return nt.current=e,()=>{e.dispose(),nt.current=null}},[]),f(()=>{const e=Pe.current,cancel=()=>{Fe.current=null};return null==e||e.addEventListener("cancel",cancel),()=>null==e?void 0:e.removeEventListener("cancel",cancel)},[]);const it=k(e=>{var t,n;$(ye(e).message),null==(n=(t=S.current).onError)||n.call(t,ye(e))},[S]),at=k(e=>{var t,n;O(e),null==(n=(t=S.current).onNotice)||n.call(t,e)},[S]);function onBlockHover(e){if(Oe.current&&(clearTimeout(Oe.current),Oe.current=null),e)return qe.current=e,void Y(e);Oe.current=setTimeout(()=>{Oe.current=null,Y(null),_e.current||U(null)},220)}function openQuickMenu(e,t,n="explicit"){Je.current=!0,Qe.current=n,U(e),G(t),J(!0),Y(e)}function enterQuickMenu(e){var t;onBlockHover(e),Xe.current=e.isEmpty?"insert-below":void 0,null==(t=nt.current)||t.enter("trigger")}f(()=>{var t,n,o;const l=w.current;if(!l)return;Be.current=!1;let s=!0;const p=document.createElement("div");let h;l.append(p);const atom=({node:t,editor:n,getPos:o})=>{const l=document.createElement("div");l.contentEditable="false",l.dataset.blockChrome="";const r=crypto.randomUUID();let a=t;"mindMap"===t.type.name&&(l.dataset.mindMapNode="");const c="mindMap"===t.type.name?pe(n,()=>{const e=o();return"number"==typeof e?e:void 0},{get pageId(){return S.current.pageId},canComment:()=>!!S.current.canComment,canExport:()=>!!S.current.allowExport,status:()=>S.current.saveStatus??"",fetchAttachment:e=>{var t;return((null==(t=T.current.attachments)?void 0:t.fetch)??i)(e)},get uploadImage(){var e;return S.current.uploadImage??(null==(e=T.current.attachments)?void 0:e.uploadImage)},viewState:S.current.mindMapViewState??lt.current,awareness:S.current.collabAwareness}):void 0,render=()=>{let t;t="mindMap"===a.type.name?/* @__PURE__ */e(he,{node:a.toJSON(),controller:c,pageId:S.current.pageId,canComment:S.current.canComment,onCommentsChanged:S.current.onCommentsChanged}):/* @__PURE__ */e(fe,{attrs:a.attrs}),Te(e=>[...e.filter(e=>e.id!==r),{id:r,dom:l,content:t}])};return queueMicrotask(()=>{s&&render()}),{dom:l,update:e=>e.type===a.type&&("mindMap"!==a.type.name||e.attrs.id===a.attrs.id)&&(a=e,s&&render(),!0),stopEvent:()=>!0,ignoreMutation:()=>!0,destroy(){null==c||c.dispose(),s&&queueMicrotask(()=>{s&&Te(e=>e.filter(e=>e.id!==r))})}}},menuCoords=e=>{var t;try{const n=h.view.coordsAtPos(e),o=(null==(t=y.current)?void 0:t.getBoundingClientRect())??{left:0,top:0};return{x:n.left-o.left,y:n.bottom-o.top+6}}catch{return{x:0,y:0}}};try{const e=S.current.value??S.current.defaultValue??tt,l=(new x).validate(e,S.current.schemaVersion??E(e,M));h=new c({element:p,editable:!S.current.disabled,content:S.current.collabDoc?void 0:l.doc,extensions:re({i18n:g,placeholder:()=>S.current.placeholder??b("输入 / 唤起命令,开始记录…"),collabDoc:S.current.collabDoc,collabAwareness:S.current.collabAwareness,canCopyCode:()=>!!S.current.allowExport,contentContext:()=>P.current,attachmentFetcher:null==(t=T.current.attachments)?void 0:t.fetch,attachmentScope:T.current.scope,attachmentPortal:()=>P.current.portal,inlineComments:{getComments:()=>S.current.inlineComments??[],getActiveId:()=>S.current.activeCommentId??null,onMarkClick:e=>{var t,n;return null==(n=(t=S.current).onInlineMarkClick)?void 0:n.call(t,e)}},slash:{onOpen:e=>{V({...e,...menuCoords(e.from)}),J(!1),Y(null)},onUpdate:e=>V(t=>t?{...t,query:e}:null),onClose:()=>V(null)},blockHandle:{onHover:onBlockHover},uploadPlaceholder:{onLost:()=>at(b("上传目标已移除,附件未插入。"))},tableInteraction:{onHover:e=>K(e)},mindMapRenderer:atom,videoRenderer:atom}),editorProps:{attributes:{role:"textbox","aria-label":b("文档正文"),"aria-multiline":"true",class:"editor-canvas ywiki-prose ywiki-content"},handleKeyDown:(e,t)=>!(!t.ctrlKey&&!t.metaKey||"k"!==t.key.toLowerCase()||(t.preventDefault(),openLink(h),0)),handlePaste:(e,t)=>{var n,o;if(!e.editable)return!1;const l=oe(t);if(l.length)return upload(l),!0;const i=(null==(o=null==(n=t.clipboardData)?void 0:n.getData("text/plain"))?void 0:o.trim())??"";if(e.state.selection.empty&&!e.state.selection.$from.parent.content.size&&A(i)){const t=e.state.selection.from,n=e.state.tr.insertText(i);return n.addMark(t,t+i.length,e.state.schema.marks.link.create({href:i})),e.dispatch(n),Fe.current={from:t,to:t+i.length,valid:!0},Le(i),Me(!0),!0}return le(t).length&&setTimeout(()=>{s&&async function upgradeRemoteImages(e){var t,n,o;const l=T.current.scope,i=null==(t=T.current.attachments)?void 0:t.fetch,a=S.current.uploadImage??(null==(n=T.current.attachments)?void 0:n.uploadImage);if(!a)return void at(b("未配置图片上传服务,无法保存粘贴的外链图片"));const c=[];e.state.doc.descendants((e,t)=>{if("image"===e.type.name&&!e.attrs.attachmentId&&/^https?:\/\//i.test(String(e.attrs.src))){const n={from:t,to:t+e.nodeSize,valid:!0};Ve.current.add(n),c.push({target:n,src:e.attrs.src})}}),Ie.current+=c.length,z(e=>e+1);for(const{target:t,src:n}of c)try{const c=await fetch(n,{credentials:"omit",signal:AbortSignal.timeout(15e3)});if(!c.ok||Number(c.headers.get("content-length"))>20971520)throw new Error(b("外链图片读取失败或超过 20 MB"));const s=await c.blob();if(!s.type.startsWith("image/")||s.size>20971520)throw new Error(b("外链图片格式无效或超过 20 MB"));const u=await a(new File([s],b("粘贴图片"),{type:s.type}));if(e.isDestroyed||!e.isEditable||!t.valid||(null==(o=e.state.doc.nodeAt(t.from))?void 0:o.attrs.src)!==n)continue;const d=e.state.doc.nodeAt(t.from);r(u.id,s,l,i),e.view.dispatch(e.state.tr.setNodeMarkup(t.from,void 0,{...d.attrs,src:null,attachmentId:u.id,alt:u.alt}))}catch(t){e.isDestroyed||it(t)}finally{Ve.current.delete(t),Ie.current--,e.isDestroyed||z(e=>e+1)}}(h)},0),!1},handleDrop:(e,t)=>{var n;if(!e.editable||!(null==(n=t.dataTransfer)?void 0:n.files.length))return!1;const o=e.posAtCoords({left:t.clientX,top:t.clientY});return!!o&&(t.preventDefault(),upload([...t.dataTransfer.files],o.pos),!0)},handleDOMEvents:{contextmenu:(e,t)=>{var n,o;if(!(e.editable&&t.target instanceof Element))return!1;if(t.target.closest("td,th"))return!1;const l=t.target.closest(".ProseMirror > *"),r=null==(n=y.current)?void 0:n.getBoundingClientRect();if(!l||l.parentElement!==e.dom||!r)return!1;let i=-1;e.state.doc.forEach((t,n)=>{e.nodeDOM(n)===l&&(i=n)});const a=e.state.doc.nodeAt(i);return!!a&&(t.preventDefault(),ke(null),V(null),Je.current=!1,Qe.current="explicit",null==(o=nt.current)||o.reset(),U({pos:i,type:a.type.name,top:t.clientY-r.top,contentLeft:t.clientX-r.left,isEmpty:a.isTextblock&&!a.content.size}),G(void 0),J(!0),!0)},mouseover:(e,t)=>{var n;if(xe.current||!e.editable)return!1;const o=null==(n=t.target)?void 0:n.closest("a[href]");if(!o||!e.dom.contains(o))return!1;const l=e.posAtDOM(o,0),r=a(e.state.doc.resolve(l),e.state.schema.marks.link);if(!r)return!1;const i=o.getBoundingClientRect(),c=createLinkEditTarget(e.state,u.create(e.state.doc,r.from,r.to));return c&&ke({...c,tracked:c,mode:"preview",anchor:{left:i.left,top:i.top,width:i.width,height:i.height}}),!1}}},onUpdate:({editor:e,transaction:t})=>{var n,o;I.current=e.getJSON(),z(e=>e+1),null==(o=(n=S.current).onChange)||o.call(n,I.current,{remote:isRemoteDocumentChange(t)})},onSelectionUpdate:()=>z(e=>e+1),onTransaction:({transaction:e})=>{Fe.current&&advanceTarget(Fe.current,e);for(const t of Ve.current)advanceTarget(t,e);const t=xe.current;(null==t?void 0:t.tracked)&&(advanceTarget(t.tracked,e),t.from=t.tracked.from,t.to=t.tracked.to),z(e=>e+1)},onBlur:()=>{var e,t;return null==(t=(e=S.current).onBlur)?void 0:t.call(e)}}),N.current=h,y.current&&($e.current=function documentGestures(e,t,n){const o=e.view;let l=null,r=0,i=null;const writable=()=>!e.isDestroyed&&e.isEditable;function pickedImage(e){i=e,n.onImagePick(e)}function cancel(){null==l||l(),l=null}function start(t,i,a){if(!writable()||0!==i.button||o.composing)return;cancel();let c=Z(o);if(!c.some(e=>e.from===t)){const e=o.state.doc.nodeAt(t);if(!e)return;c=[{from:t,to:t+e.nodeSize}]}if(!c.length)return;const s=o.state.doc,d=c[0].from,m=c.at(-1).to,p=c.some(e=>{var t;return null==(t=e.images)?void 0:t.length}),h=o.state.selection,v={x:i.clientX,y:i.clientY};let g=!1,f=v,b=null,w=0;const y=document.createElement("div");y.className="wr-block-drop-line block-drop-line",y.setAttribute("aria-hidden","true");const k=document.documentElement.style.cursor,C=document.body.style.userSelect;function paint(){if(!writable()||o.state.doc!==s)return void cancel();b=function pickNearestGap(e,t){if(0===e.length)return null;let n=e[0],o=Math.abs(e[0].y-t);for(const l of e){const e=Math.abs(l.y-t);e<o&&(n=l,o=e)}return n}(function gaps(){const e=[];return o.state.doc.forEach((t,n)=>{const l=o.nodeDOM(n);if(!(l instanceof HTMLElement))return;const r=l.getBoundingClientRect();e.push({pos:n,y:r.top}),n+t.nodeSize===o.state.doc.content.size&&e.push({pos:n+t.nodeSize,y:r.bottom})}),e}(),f.y);const e=o.dom.getBoundingClientRect();b&&Object.assign(y.style,{left:`${e.left}px`,top:`${b.y}px`,width:`${e.width}px`}),y.hidden=!b||b.pos>=d&&b.pos<=m}const scroll=()=>{if(!g)return;let e=o.dom.parentElement;for(;e&&!(e.scrollHeight>e.clientHeight&&/auto|scroll/.test(getComputedStyle(e).overflowY));)e=e.parentElement;const t=(null==e?void 0:e.getBoundingClientRect())??{top:0,bottom:innerHeight},n=f.y<t.top+42?-14:f.y>t.bottom-42?14:0;n&&(e?e.scrollTop+=n:window.scrollBy(0,n),paint()),w=requestAnimationFrame(scroll)},move=e=>{f={x:e.clientX,y:e.clientY},!g&&Math.hypot(f.x-v.x,f.y-v.y)<4||(g||(Z(o).some(e=>e.from===t)||te(o,t,t),g=!0,n.onStart(),n.layer().append(y),o.dom.classList.add("is-block-dragging"),document.documentElement.style.cursor="grabbing",document.body.style.userSelect="none",w=requestAnimationFrame(scroll)),paint(),e.preventDefault())},up=e=>{const t=b,n=g;if(cancel(),!writable()||o.state.doc!==s)return;if(!n){if(a)a();else{const t=o.posAtCoords({left:e.clientX,top:e.clientY});t&&o.dispatch(o.state.tr.setSelection(u.near(o.state.doc.resolve(t.pos)))),o.focus()}return}if(r=Date.now()+400,!t||t.pos>=d&&t.pos<=m)return;const l=o.state.selection;if(p&&(!(l instanceof ee)||!l.eq(h)))return;const i=p?l.content():o.state.doc.slice(d,m),c=o.state.tr;p?l.replace(c):c.delete(d,m);const v=c.mapping.map(t.pos),f=c.steps.length;c.insert(v,i.content),c.steps.length!==f&&(o.dispatch(c.scrollIntoView()),o.focus())},key=e=>{"Escape"!==e.key||e.isComposing||(e.preventDefault(),e.stopImmediatePropagation(),r=Date.now()+400,cancel())},change2=()=>{o.state.doc===s&&writable()||cancel()};l=()=>{window.removeEventListener("mousemove",move,!0),window.removeEventListener("mouseup",up,!0),window.removeEventListener("keydown",key,!0),window.removeEventListener("blur",cancel),window.removeEventListener("pointercancel",cancel),e.off("transaction",change2),cancelAnimationFrame(w),y.remove(),o.dom.classList.remove("is-block-dragging"),document.documentElement.style.cursor=k,document.body.style.userSelect=C,n.onEnd()},window.addEventListener("mousemove",move,!0),window.addEventListener("mouseup",up,!0),window.addEventListener("keydown",key,!0),window.addEventListener("blur",cancel),window.addEventListener("pointercancel",cancel),e.on("transaction",change2),i.preventDefault()}function pickImage(e){var t;try{const n=o.posAtDOM(e,0);if("image"!==(null==(t=o.state.doc.nodeAt(n))?void 0:t.type.name))return;pickedImage(n),o.dispatch(o.state.tr.setSelection(m.create(o.state.doc,n))),o.focus()}catch{}}function down(e){if(!writable()||o.composing||0!==e.button||!(e.target instanceof Element))return;const t=e.target;if(t.closest("button,input,textarea,select,a,video,audio,.math-node"))return;const r=Z(o),a=t.closest(".ywiki-image-gallery");if(a&&!t.closest(".ywiki-image-frame")&&!a.matches(".is-block-selected,.is-block-image-selected"))return void function gallerySelect(e,t){cancel(),t.preventDefault(),t.stopPropagation();const r=o.state.doc,i={x:t.clientX,y:t.clientY},a=Array.from(e.children).filter(e=>e instanceof HTMLElement&&e.classList.contains("ywiki-image-frame")),c=document.createElement("div");c.className="ywiki-gallery-marquee",c.hidden=!0,n.layer().append(c);let s=!1;const u=document.body.style.userSelect;document.body.style.userSelect="none";const move=e=>{if(!writable()||o.state.doc!==r)return void cancel();if(!s&&Math.hypot(e.clientX-i.x,e.clientY-i.y)<6)return;s=!0,c.hidden=!1;const t=Math.min(i.x,e.clientX),n=Math.min(i.y,e.clientY),l=Math.max(i.x,e.clientX),u=Math.max(i.y,e.clientY);Object.assign(c.style,{left:`${t}px`,top:`${n}px`,width:l-t+"px",height:u-n+"px"});for(const e of a){const o=e.getBoundingClientRect();e.classList.toggle("is-multi-picked",o.right>t&&o.left<l&&o.bottom>n&&o.top<u)}e.preventDefault()},up=()=>{const t=a.filter(e=>e.classList.contains("is-multi-picked"));if(cancel(),writable()&&o.state.doc===r)if(s){if(1===t.length)pickImage(t[0]);else if(t.length>1){const n=o.posAtDOM(e,0),l=o.state.doc.resolve(n),r=l.depth?l.before():n,i=t.map(e=>{const t=o.posAtDOM(e,0);return{from:t,to:t+o.state.doc.nodeAt(t).nodeSize}});ne(o,r,i),o.focus()}}else{const e=a.sort((e,t)=>Math.abs(i.x-(e.getBoundingClientRect().left+e.getBoundingClientRect().right)/2)-Math.abs(i.x-(t.getBoundingClientRect().left+t.getBoundingClientRect().right)/2))[0];e&&pickImage(e)}},key=e=>{"Escape"!==e.key||e.isComposing||(e.preventDefault(),cancel())};l=()=>{window.removeEventListener("mousemove",move,!0),window.removeEventListener("mouseup",up,!0),window.removeEventListener("keydown",key,!0),window.removeEventListener("blur",cancel),window.removeEventListener("pointercancel",cancel),c.remove(),document.body.style.userSelect=u;for(const e of a)e.classList.remove("is-multi-picked")},window.addEventListener("mousemove",move,!0),window.addEventListener("mouseup",up,!0),window.addEventListener("keydown",key,!0),window.addEventListener("blur",cancel),window.addEventListener("pointercancel",cancel)}(a,e);if(e.detail<2&&r.length){let n=t.closest(".ProseMirror > *");if((null==n?void 0:n.parentElement)!==o.dom&&(n=null),n){let l=-1;o.state.doc.forEach((e,t)=>{o.nodeDOM(t)===n&&(l=t)});const i=t.closest(".ywiki-image-frame"),a=r.find(e=>{var t;return e.from===l&&(!(null==(t=e.images)?void 0:t.length)||i&&e.images.some(e=>o.posAtDOM(i,0)===e.from))});if(a)return start(a.from,e),void e.stopPropagation()}}const c=t.closest("img.ywiki-image"),s=null==c?void 0:c.closest(".ywiki-image-frame");if(c&&s){const t=o.posAtDOM(s,0),r=i;pickedImage(t);{cancel();const o={x:e.clientX,y:e.clientY,time:Date.now()};let i=0;const move=e=>{i=Math.max(i,Math.hypot(e.clientX-o.x,e.clientY-o.y))},up=()=>{cancel(),i>=6?pickedImage(null):r===t&&writable()&&c.isConnected&&function isImagePreviewTap(e,t){return!(!Number.isFinite(e)||!Number.isFinite(t))&&!(e>=6)&&t<450}(i,Date.now()-o.time)&&n.onPreview(c)};l=()=>{window.removeEventListener("mousemove",move,!0),window.removeEventListener("mouseup",up,!0),window.removeEventListener("blur",cancel)},window.addEventListener("mousemove",move,!0),window.addEventListener("mouseup",up,!0),window.addEventListener("blur",cancel)}}else pickedImage(null);if(t===o.dom){const t=o.state.doc.lastChild,n=t?o.nodeDOM(o.state.doc.content.size-t.nodeSize):null;n instanceof HTMLElement&&e.clientY>=n.getBoundingClientRect().bottom-4&&(e.preventDefault(),o.dispatch(function focusTrailingParagraph(e){const t=e.tr,n=t.doc.lastChild;return"paragraph"===(null==n?void 0:n.type.name)&&0===n.content.size||t.insert(t.doc.content.size,e.schema.nodes.paragraph.create()),t.setSelection(d.atEnd(t.doc)).setStoredMarks(null)}(o.state)),o.focus())}}const nativeDrag=e=>{l&&o.state.selection instanceof ee&&e.preventDefault()},outside=e=>{e.target instanceof Element&&!t.contains(e.target)&&!e.target.closest(".img-toolbar,.img-preview-mask,.w-popover")&&pickedImage(null)},change=({transaction:e})=>{(e.docChanged||o.state.selection instanceof m&&o.state.selection.from!==i)&&pickedImage(null)};return e.on("transaction",change),document.addEventListener("mousedown",outside,!0),o.dom.addEventListener("mousedown",down,!0),o.dom.addEventListener("dragstart",nativeDrag,!0),{start:start,consumeClick:function consumeClick(){const e=Date.now()<r;return r=0,e},cancel:cancel,destroy(){cancel(),o.dom.removeEventListener("mousedown",down,!0),o.dom.removeEventListener("dragstart",nativeDrag,!0),e.off("transaction",change),document.removeEventListener("mousedown",outside,!0)}}}(h,y.current,{layer:()=>P.current.portal??y.current??document.body,onStart:()=>{Ye(!0),closeBlockMenu(),B(h.view),V(null),ke(null)},onEnd:()=>{Ge.current=!1,Ye(!1),z(e=>e+1)},onImagePick:Ue,onPreview:e=>{const t=e.getAttribute("src")??"";if(!t)return;const n=ve(e,b("图片预览"));He({src:t,label:e.alt||b("图片预览"),items:n.items.length?n.items:[{src:t,label:e.alt||b("图片预览")}],index:n.items.length?n.index:0})}})),rt.markReady(),null==(o=(n=S.current).onReady)||o.call(n)}catch(e){it(e)}return()=>{var e;s=!1,Be.current=!0,null==(e=$e.current)||e.destroy(),$e.current=null,Fe.current=null,N.current=null,null==h||h.destroy(),p.remove(),Te([])}},[n.collabDoc,n.collabAwareness]),f(()=>{const e=N.current;e&&!e.isDestroyed&&e.view.dispatch(e.state.tr.setMeta("content-context",!0))},[L.portal,L.theme,L.accent,D.preferences,n.allowExport,g.version]),f(()=>{var e;const t=N.current;t&&(t.setEditable(!n.disabled,!1),t.view.dispatch(t.state.tr.setMeta("content-capabilities",!0))),n.disabled&&(null==(e=$e.current)||e.cancel(),closeBlockMenu(),ke(null),V(null),Y(null),U(null),Fe.current=null,Se(!1),Me(!1),K(null))},[n.disabled]),f(()=>{const e=N.current;if(e&&n.value&&!n.collabDoc&&n.value!==I.current)try{const t=(new x).validate(n.value,n.schemaVersion??E(n.value,M));e.schema.nodeFromJSON(t.doc).eq(e.state.doc)||e.commands.setContent(t.doc,{emitUpdate:!1}),$("")}catch(e){it(e)}},[n.value,n.collabDoc,it]),f(()=>{N.current&&ie(N.current,n.inlineComments??[])},[n.inlineComments,n.activeCommentId]);const snapshot=()=>{var e;return(null==(e=N.current)?void 0:e.getJSON())??S.current.value??S.current.defaultValue??tt};function hasPendingTasks(){var e;const t=N.current;return!!t&&(Ie.current>0||Ve.current.size>0||!!Fe.current||De||Ee||t.view.composing||!!(null==(e=t.storage.mindMap)?void 0:e.composing)||!!t.view.dom.querySelector(".math-latex-input"))}function selectionRect(){const e=N.current;if(!e||e.state.selection.empty)return null;try{const t=e.view.coordsAtPos(e.state.selection.from);return{left:t.left,top:t.top,width:Math.max(1,t.right-t.left),height:Math.max(1,t.bottom-t.top)}}catch{return null}}function openLink(e=N.current){if(!e||!e.isEditable)return;const t=createLinkEditTarget(e.state);if(!t)return void at(b("请先选中要添加链接的文字"));const n=e.view.coordsAtPos(t.from);ke({...t,tracked:t,mode:"edit",anchor:{left:n.left,top:n.top,width:Math.max(1,n.right-n.left),height:n.bottom-n.top}})}function rememberInsert(){const e=N.current;(null==e?void 0:e.isEditable)&&(Fe.current={from:e.state.selection.from,to:e.state.selection.from,valid:!0})}function requestPage(){T.current.references?(rememberInsert(),Se(!0)):at(b("未配置资源选择服务"))}function requestVideo(){rememberInsert(),Le(""),Me(!0)}function insertPending(e){const t=N.current,n=Fe.current;Fe.current=null,!(null==t?void 0:t.isEditable)||!(null==n?void 0:n.valid)||n.from>t.state.doc.content.size?at(b("插入目标已移除,请重新选择位置")):t.chain().focus().insertContentAt({from:n.from,to:n.to},e).run()}function requestFile(e){rememberInsert(),Re.current=e,Pe.current&&(Pe.current.accept="image"===e?"image/*":"",Pe.current.click())}async function upload(e,t,n="auto"){var o,l,i,a;const c=N.current;if(!c||!c.isEditable)return;const s=T.current.scope,u=null==(o=T.current.attachments)?void 0:o.fetch,d=t??c.state.selection.from,m=S.current.uploadImage??(null==(l=T.current.attachments)?void 0:l.uploadImage);if("file"!==n&&e.length>1&&e.every(e=>e.type.startsWith("image/"))&&m){const t=crypto.randomUUID();Ie.current++,ae(c.view,{id:t,pos:d,kind:"image",label:b("{0} 张图片",{0:e.length}),file:e[0]});try{if(e.some(e=>e.size>20971520))throw new Error(b("图片不能超过 20 MB"));const n=await Promise.all(e.map(async e=>{const t=await m(e);return!c.isDestroyed&&c.isEditable&&T.current.scope===s&&r(t.id,e,s,u),c.schema.nodes.image.create({attachmentId:t.id,alt:t.alt})}));if(Be.current||c.isDestroyed||!c.isEditable)return;const o=ce(c.view,t);if(null===o)return;const l=c.state.tr;let i=o;for(let e=0;e<n.length;e+=10){const t=n.slice(e,e+10),o=1===t.length?t[0]:c.schema.nodes.imageGallery.create({height:120},t),r=l.mapping.maps.length,a=i;se(l,a,o),i=l.mapping.slice(r).map(a,1)}c.view.dispatch(l),ue(c.view,t)}catch(e){Be.current||c.isDestroyed||(ue(c.view,t),it(e))}finally{c.isDestroyed||ue(c.view,t),Ie.current--,Be.current||z(e=>e+1)}return}const p=e.map(e=>({file:e,id:crypto.randomUUID()}));for(const{file:e,id:t}of p)ae(c.view,{id:t,pos:d,kind:e.type.startsWith("image/")&&"file"!==n?"image":"file",label:e.name,file:e});Ie.current+=p.length,z(e=>e+1);for(const{file:e,id:t}of p){if(c.isDestroyed){Ie.current--;continue}const o=e.type.startsWith("image/")&&"file"!==n,l=o?S.current.uploadImage??(null==(i=T.current.attachments)?void 0:i.uploadImage):S.current.uploadFile??(null==(a=T.current.attachments)?void 0:a.uploadFile);try{if(!l)throw new Error(b("未配置附件上传服务"));if(e.size>20971520)throw new Error(b("附件不能超过 20 MB"));const n=await l(e);if(Be.current||c.isDestroyed||!c.isEditable||null===ce(c.view,t))continue;r(n.id,e,s,u);const i=o?{attachmentId:n.id,alt:"alt"in n?n.alt:e.name}:{attachmentId:n.id,filename:e.name,mimeType:e.type,size:e.size};de(c.view,t,{type:o?"image":"fileAttachment",attrs:i})}catch(e){c.isDestroyed||Be.current||(ue(c.view,t),it(e))}finally{c.isDestroyed||ue(c.view,t),Ie.current--,Be.current||z(e=>e+1)}}}C(s,()=>({isReady:rt.isReady,whenReady:rt.whenReady,getJSON:snapshot,getSnapshot:snapshot,async prepareSnapshot(){if(!N.current)throw new Error(b("文档尚未就绪"));if(hasPendingTasks())throw new Error(b("请先完成上传、公式或组合输入"));const e=snapshot(),t=E(e,S.current.schemaVersion??M);return(new x).validate(e,t),{doc:e,schemaVersion:t}},hasPendingTasks:hasPendingTasks,focus:()=>{var e;null==(e=N.current)||e.commands.focus()},undo:()=>{var e;return(null==(e=N.current)?void 0:e.commands.undo())??!1},redo:()=>{var e;return(null==(e=N.current)?void 0:e.commands.redo())??!1},hasSelection:()=>!!N.current&&!N.current.state.selection.empty,getSelectionRect:selectionRect,getSelectionForAnchor(){const e=N.current;if(!e||e.state.selection.empty)return null;const{from:t,to:n}=e.state.selection,o=e.state.doc.textBetween(t,n,"\n");return o.trim()?{quote:o,prefix:e.state.doc.textBetween(Math.max(0,t-64),t,"\n"),suffix:e.state.doc.textBetween(n,Math.min(e.state.doc.content.size,n+64),"\n"),start:e.state.doc.textBetween(0,t,"\n").length}:null},setSelection(e,t=e){var n;null==(n=N.current)||n.commands.setTextSelection({from:e,to:t})},setContent(e){var t;if(!S.current.collabDoc)try{const n=e??tt,o=(new x).validate(n,S.current.schemaVersion??E(n,M));null==(t=N.current)||t.commands.setContent(o.doc,{emitUpdate:!1}),$("")}catch(e){it(e)}}}));const ct=N.current,st=null==ct?void 0:ct.state.selection,ut=st instanceof m&&"image"===st.node.type.name?{pos:st.from,node:st.node}:null,dt=!!F;let mt=null,pt=null;if(ct&&y.current&&!n.disabled&&!dt&&!_&&!me&&!We){const e=y.current.getBoundingClientRect();if(st instanceof u&&!st.empty)try{const t=ct.view.coordsAtPos(st.from),n=ct.view.coordsAtPos(st.to);mt={x:(t.left+n.right)/2-e.left,y:Math.min(t.top,n.top)-e.top-8}}catch{mt=null}if(ut&&je===ut.pos)try{const t=ct.view.nodeDOM(ut.pos);if(t instanceof HTMLElement){const n=t.getBoundingClientRect(),o=n.top-e.top-44;pt={x:n.left-e.left+n.width/2,y:o<4?n.bottom-e.top+10:o}}}catch{pt=null}}const ht=_?j??W:W,vt=ht&&y.current?function blockAffordanceStyle(e,t,n){const o="plus"===n?Ze:et,l=e.contentLeft-8-o.width,r=t?8-t.getBoundingClientRect().left:8;return{left:Math.max(l,r),top:e.top+(26-o.height)/2}}(ht,y.current,ht.isEmpty?"plus":"chip"):{left:0,top:0},gt=!!ht&&!n.disabled&&(!_||Je.current)&&!We&&(!Q||_)&&"table"!==ht.type&&!F&&!mt&&!ze&&!me;/* @__PURE__ */
113
- return t("div",{ref:y,className:`wr-document editor-shell${ut&&je===ut.pos?" img-pick-active":""}${n.className?` ${n.className}`:""}`,"data-block-select-band":!0,children:[H&&/* @__PURE__ */e("p",{role:"status",children:H}),q&&/* @__PURE__ */e("p",{role:"alert",children:q}),
114
- /* @__PURE__ */e("div",{ref:w,className:"wr-document-mount"}),mt&&ct&&!ut&&/* @__PURE__ */e(SelectionToolbar,{editor:ct,x:mt.x,y:mt.y,canComment:n.canComment,onRequestComment:()=>{var e,t;return null==(t=(e=S.current).onRequestComment)?void 0:t.call(e)},onRequestLink:()=>openLink(ct),onRemoveLink:()=>{ct.chain().focus().unsetLink().run()}}),pt&&ut&&ct&&/* @__PURE__ */t("div",{className:"img-toolbar",role:"toolbar","aria-label":b("图片操作"),style:{left:pt.x,top:pt.y},onMouseDown:e=>e.preventDefault(),children:[["left","center","right"].map(t=>/* @__PURE__ */e("button",{type:"button",className:"it-btn"+(ut.node.attrs.align===t?" on":""),"aria-label":b("图片{0}对齐",{0:b("left"===t?"左":"center"===t?"居中":"右")}),title:b("图片{0}对齐",{0:b("left"===t?"左":"center"===t?"居中":"右")}),"aria-pressed":ut.node.attrs.align===t,onClick:()=>function imageAlign(e){ct&&ut&&ct.isEditable&&(ct.view.dispatch(ct.state.tr.setNodeMarkup(ut.pos,void 0,{...ut.node.attrs,align:e})),ct.commands.focus())}(t),children:/* @__PURE__ */e(Ce,{name:`align-${t}`,size:16})},t)),
103
+ /* @__PURE__ */e("input",{type:"checkbox",checked:x,"aria-describedby":`${f}-loading`,onChange:e=>C(e.target.checked)}),
104
+ /* @__PURE__ */e("span",{children:s.t("video.autoLoad")})]}),
105
+ /* @__PURE__ */e("p",{id:`${f}-loading`,className:"video-hint",children:s.t("video.autoLoadHint")})]})]})})}const it=/* @__PURE__ */new WeakMap,at={type:"doc",content:[{type:"paragraph"}]},st=y(function DocumentEditor2(n,c){const f=o(),b=f.text,w=h(null),y=h(null),L=h(null),N=r(),D=N.host,S=we(n),T=we(D),I=h(null),P=we(N),[R,z]=v(0),[H,O]=v(""),[q,$]=v(""),[F,V]=v(null),[W,j]=v(null),[Y,U]=v(null),[_,J]=v(!1),[X,G]=v(void 0),[Q,K]=v(null),[me,pe]=v(null),xe=we(me),[Ee,Me]=v(!1),[Le,Ne]=v(""),[Se,Ae]=v(!1),[Te,Be]=v([]),Ie=h(!1),Pe=h(0),ze=h(null),He=h("image"),[Oe,qe]=v(null),$e=h(null),Fe=h(null),We=h(null),je=h(null),Ye=h(/* @__PURE__ */new Set),[Ue,_e]=v(!1),[Je,Ge]=v(null),et=we(_),tt=h(!1),nt=h(void 0),st=h(!1),ct=h("explicit"),ut=h(null),dt=we({dragging:Ue,slash:F,link:me,preview:Oe}),mt=h({openId:null,maps:{}}),pt=ye();g(()=>()=>{$e.current&&clearTimeout($e.current)},[]),g(()=>{const e=function createBlockMenuHover(e){const t=/* @__PURE__ */new Set;let n,o,r=!1;function clearOpen(){clearTimeout(n),n=void 0}function clearClose(){clearTimeout(o),o=void 0}function reset(){clearOpen(),clearClose(),t.clear()}return{enter:function enter(o){r||(t.add(o),clearClose(),"trigger"!==o||e.isOpen()||n||(n=setTimeout(()=>{n=void 0,!r&&t.has("trigger")&&!e.isOpen()&&e.canOpen()&&e.open()},e.openDelay??120)))},leave:function leave(n){t.delete(n),r||t.size||(clearOpen(),clearClose(),e.isOpen()&&(o=setTimeout(()=>{o=void 0,!r&&!t.size&&e.isOpen()&&e.canClose()&&e.close()},e.closeDelay??240)))},reset:reset,dispose:function dispose(){r=!0,reset()}}}({isOpen:()=>et.current,canOpen:()=>!(S.current.disabled||st.current||dt.current.dragging||dt.current.slash||dt.current.link||dt.current.preview||!Fe.current),canClose:()=>{var e,t;return"hover"===ct.current&&!(null==(t=null==(e=y.current)?void 0:e.querySelector(".block-anchor"))?void 0:t.contains(document.activeElement))},open:()=>{Fe.current&&openQuickMenu(Fe.current,nt.current,"hover")},close:closeBlockMenu});return ut.current=e,()=>{e.dispose(),ut.current=null}},[]),g(()=>{const e=ze.current,cancel=()=>{je.current=null};return null==e||e.addEventListener("cancel",cancel),()=>null==e?void 0:e.removeEventListener("cancel",cancel)},[]);const ht=k(e=>{var t,n;$(ke(e).message),null==(n=(t=S.current).onError)||n.call(t,ke(e))},[S]),vt=k(e=>{var t,n;O(e),null==(n=(t=S.current).onNotice)||n.call(t,e)},[S]);function onBlockHover(e){if($e.current&&(clearTimeout($e.current),$e.current=null),e)return Fe.current=e,void j(e);$e.current=setTimeout(()=>{$e.current=null,j(null),et.current||U(null)},220)}function openQuickMenu(e,t,n="explicit"){tt.current=!0,ct.current=n,U(e),G(t),J(!0),j(e)}function enterQuickMenu(e){var t;onBlockHover(e),nt.current=e.isEmpty?"insert-below":void 0,null==(t=ut.current)||t.enter("trigger")}g(()=>{var t,n,o;const r=w.current;if(!r)return;Ie.current=!1;let c=!0;const p=document.createElement("div");let h;r.append(p);const atom=({node:t,editor:n,getPos:o})=>{const r=document.createElement("div");r.contentEditable="false",r.dataset.blockChrome="";const l=crypto.randomUUID(),a="videoEmbed"===t.type.name?document.createElement("div"):r;a!==r&&r.append(a);let s=t,u=0;"mindMap"===t.type.name&&(r.dataset.mindMapNode="");const d="mindMap"===t.type.name?he(n,()=>{const e=o();return"number"==typeof e?e:void 0},{get pageId(){return S.current.pageId},canComment:()=>!!S.current.canComment,canExport:()=>!!S.current.allowExport,status:()=>S.current.saveStatus??"",fetchAttachment:e=>{var t;return((null==(t=T.current.attachments)?void 0:t.fetch)??i)(e)},get uploadImage(){var e;return S.current.uploadImage??(null==(e=T.current.attachments)?void 0:e.uploadImage)},viewState:S.current.mindMapViewState??mt.current,awareness:S.current.collabAwareness}):void 0,render=()=>{let t;t="mindMap"===s.type.name?/* @__PURE__ */e(ve,{node:s.toJSON(),controller:d,pageId:S.current.pageId,canComment:S.current.canComment,onCommentsChanged:S.current.onCommentsChanged}):/* @__PURE__ */e(be,{attrs:s.attrs,reloadKey:u}),Be(e=>[...e.filter(e=>e.id!==l),{id:l,dom:a,content:t}])},p="videoEmbed"===t.type.name?function createVideoBlockControls(e){const{editor:t,dom:n,getPos:o}=e,r=Re(t),l=document.createElement("div");l.className="video-block-tools",l.contentEditable="false",l.hidden=!0;const i=document.createElement("div");i.className="video-block-toolbar",i.setAttribute("role","toolbar"),l.append(i),n.classList.add("video-editor-node"),n.setAttribute("role","group"),n.setAttribute("aria-keyshortcuts","Enter"),n.tabIndex=0;let a,s,c=!1,u=!1,d=!1,p=!1,h=!1,v=0,f=NaN,g=NaN;const b=[],current=()=>{if(c||t.isDestroyed)return null;const e=o();if("number"!=typeof e||e<0||e>=t.state.doc.content.size)return null;const n=t.state.doc.nodeAt(e);return"videoEmbed"===(null==n?void 0:n.type.name)?{pos:e,node:n}:null},data=()=>{var e;return Ze(null==(e=current())?void 0:e.node.attrs)},allowed=()=>{var t,n,o;const r=data();return!!r&&((null==(o=null==(n=null==(t=e.policy)?void 0:t.call(e))?void 0:n.providers)?void 0:o.includes(r.provider))??!0)};function select(){const e=current();if(e&&t.isEditable&&!(t.state.selection instanceof m&&t.state.selection.from===e.pos)){const o=document.activeElement;t.view.dispatch(t.state.tr.setSelection(m.create(t.state.doc,e.pos))),t.view.focus(),o instanceof HTMLElement&&(o===n||l.contains(o))&&o.focus({preventScroll:!0})}}function iconButton(e,n,o){const r=document.createElement("button");r.type="button";const l=document.createElementNS("http://www.w3.org/2000/svg","svg");for(const[e,t]of Object.entries({width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"}))l.setAttribute(e,t);for(const e of n){const t=document.createElementNS(l.namespaceURI,"path");t.setAttribute("d",e),l.append(t)}return r.append(l),b.push({element:r,key:e}),r.addEventListener("mousedown",e=>e.preventDefault()),r.addEventListener("click",()=>{t.isEditable&&current()&&(p=!1,select(),o())}),i.append(r),r}const w=iconButton("video.reload",["M20 7v5h-5","M20 12a8 8 0 1 1-2-5.3L20 9"],()=>{allowed()&&e.reload()}),y=iconButton("video.copySource",["M9 9h12v12H9z","M5 15H3V3h12v2"],()=>{const e=data();e&&(async()=>{try{await navigator.clipboard.writeText(Qe(e)),E.textContent=r.t("code.copied")}catch{E.textContent=r.t("error.clipboardPermission")}c||(clearTimeout(s),s=setTimeout(()=>{E.textContent="",sync()},3e3),sync())})()}),k=iconButton("video.autoLoad",["M3 4h18v13H3z","m10 8 5 3-5 3Z","M8 21h8m-4-4v4"],()=>{var n;const o=current();o&&t.view.dispatch(Ve(t.state.tr.setNodeMarkup(o.pos,void 0,{...o.node.attrs,autoLoad:!Ke(data(),null==(n=e.policy)?void 0:n.call(e))})))}),x=document.createElement("span");k.append(x),k.className="video-block-loading",iconButton("video.openOriginal",["M14 3h7v7m0-7L10 14","M10 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-5"],()=>{const e=data();e&&window.open(Qe(e),"_blank","noopener,noreferrer")});const C=iconButton("video.editLink",["M10 13a5 5 0 0 0 7 .1l3-3a5 5 0 0 0-7-7l-2 2","M14 11a5 5 0 0 0-7-.1l-3 3a5 5 0 0 0 7 7l2-2"],()=>{if(d)return closeEdit(),void C.focus();clearTimeout(s),E.textContent="",d=!0,M.hidden=!1,S.value=data()?Qe(data()):"",C.setAttribute("aria-expanded","true"),validate(),sync(),S.focus(),S.select()});C.setAttribute("aria-haspopup","dialog"),C.setAttribute("aria-expanded","false"),iconButton("video.delete",["M3 6h18M9 6V3h6v3","m5 6 1 15h12l1-15M10 10v7m4-7v7"],()=>{const e=current();e&&(t.view.dispatch(Ve(t.state.tr.delete(e.pos,e.pos+e.node.nodeSize)).scrollIntoView()),t.view.focus())}).className="video-block-delete";const E=document.createElement("div");E.className="video-block-feedback",E.setAttribute("role","status"),l.append(E);const M=document.createElement("form");M.className="video-block-link-form",M.hidden=!0,M.setAttribute("role","dialog"),M.noValidate=!0;const L=document.createElement("span");L.className="video-block-link-arrow",L.setAttribute("aria-hidden","true");const N=document.createElement("div"),D=document.createElement("div"),S=document.createElement("textarea");N.className="video-block-link-row",D.className="video-block-link-field";const A=C.querySelector("svg").cloneNode(!0);A.classList.add("video-block-link-icon"),A.setAttribute("width","16"),A.setAttribute("height","16");const T=`video-link-${crypto.randomUUID()}`;S.id=T,S.rows=1,S.wrap="soft",S.inputMode="url",S.maxLength=2048,S.autocomplete="off",S.autocapitalize="off",S.spellcheck=!1;const B=document.createElement("p");B.id=`${T}-problem`,B.setAttribute("role","status"),S.setAttribute("aria-describedby",B.id);const I=document.createElement("button");function resizeInput(){if(!d||l.hidden||!l.isConnected)return;S.style.height="34px";const e=Math.max(34,Math.min(110,S.scrollHeight+2));S.style.height=`${e}px`,S.style.overflowY=S.scrollHeight>108?"auto":"hidden"}function validate(){var n,o,l;const i=Xe(S.value).data,a=!i||((null==(l=null==(o=null==(n=e.policy)?void 0:n.call(e))?void 0:o.providers)?void 0:l.includes(i.provider))??!0);B.textContent=a?videoProblem(S.value,!0,r.text):r.t("video.notEnabled"),I.disabled=!i||!a||!t.isEditable,S.setAttribute("aria-invalid",String(!!B.textContent)),resizeInput(),schedule()}function closeEdit(){d=!1,M.hidden=!0,C.setAttribute("aria-expanded","false"),sync()}I.type="submit",I.className="video-block-link-confirm",D.append(A,S),N.append(D,I),M.append(L,N,B),l.append(M);const P={isEditing:()=>d,isFocused:()=>n.contains(document.activeElement)||l.contains(document.activeElement),hide(){p=!0,u=!1,d=!1,l.hidden=!0,M.hidden=!0,C.setAttribute("aria-expanded","false")}};function activate(e=!1){const n=it.get(t);return n===P||!((null==n?void 0:n.isEditing())&&!e)&&(null==n||n.hide(),it.set(t,P),!0)}function localize(){i.setAttribute("aria-label",r.t("video.actions")),n.setAttribute("aria-label",r.t("video.actions")),M.setAttribute("aria-label",r.t("video.editLink"));for(const{element:e,key:t}of b)e.title=r.t(t),e.setAttribute("aria-label",r.t(t));S.setAttribute("aria-label",r.t("video.link")),S.placeholder=r.t("link.placeholder"),I.textContent=r.t("common.confirm"),d&&validate(),sync()}function place(){if(v=0,l.hidden||c)return;const e=n.getBoundingClientRect(),t=De({align:"center",prefer:"above",anchor:{left:e.left,top:Math.max(8,e.top),width:e.width,height:0},host:{left:0,top:0},card:{width:i.offsetWidth,height:i.offsetHeight},bounds:{left:0,top:0,width:document.documentElement.clientWidth,height:window.innerHeight}});if(l.style.left=`${t.left}px`,l.style.top=`${t.top}px`,d){resizeInput();const e=C.getBoundingClientRect(),t=De({align:"start",prefer:"below",anchor:{left:e.left,top:e.top,width:e.width,height:e.height},host:{left:0,top:0},card:{width:M.offsetWidth,height:M.offsetHeight},bounds:{left:0,top:0,width:document.documentElement.clientWidth,height:window.innerHeight}});M.style.left=`${t.left}px`,M.style.top=`${t.top}px`,L.dataset.side=t.side,L.style.left=`${t.arrowLeft}px`}}function schedule(){v||(v=requestAnimationFrame(place))}function sync(){var o,i;if(c||t.isDestroyed)return;const a=current(),s=t.state.selection,v=!!a&&s instanceof m&&s.from===a.pos;v&&!h&&(p=!1,activate(!0)),h=v,n.classList.toggle("is-video-selected",t.isEditable&&v),n.tabIndex=t.isEditable?0:-1,t.isEditable&&a||(d=!1,M.hidden=!0,C.setAttribute("aria-expanded","false"));const f=n.contains(document.activeElement)||l.contains(document.activeElement),g=n.getBoundingClientRect(),b=g.bottom>8&&g.top<window.innerHeight-8&&g.right>0&&g.left<window.innerWidth;if(l.hidden=it.get(t)!==P||!t.isEditable||!a||!b||p||!(u||v&&t.view.hasFocus()||d||f),!l.hidden){const t=(null==(o=e.portal)?void 0:o.call(e))??document.body;l.parentElement!==t&&t.append(l);const n=Ke(data(),null==(i=e.policy)?void 0:i.call(e));k.setAttribute("aria-pressed",String(n)),x.textContent=r.t(n?"video.automatic":"video.manual"),w.disabled=!allowed(),k.disabled=!data(),y.disabled=!data(),E.hidden=!E.textContent,place()}}function enter(e){const n=it.get(t);n!==P&&(null==n?void 0:n.isFocused())&&e.clientX===f&&e.clientY===g||activate()&&(clearTimeout(a),u=!0,p=!1,sync())}function pointerMove(e){f=e.clientX,g=e.clientY}function leave(){clearTimeout(a),a=setTimeout(()=>{u=!1,sync()},160)}function focus(){activate(!0),p=!1,document.activeElement===n&&select(),sync()}function blur(){queueMicrotask(()=>{c||sync()})}function keydown(e){return e.target!==S||"Enter"!==e.key||e.isComposing||e.shiftKey?e.target!==n||!t.isEditable||e.isComposing||"Enter"!==e.key&&" "!==e.key?void("Escape"!==e.key||e.isComposing||(e.preventDefault(),e.stopPropagation(),d?(closeEdit(),C.focus()):(p=!0,t.view.focus(),sync()))):(e.preventDefault(),e.stopPropagation(),activate(!0),select(),p=!1,sync(),void(w.disabled?C:w).focus()):(e.preventDefault(),e.stopPropagation(),void M.requestSubmit())}function outside(e){n.contains(e.target)||l.contains(e.target)||(u=!1,d=!1,M.hidden=!0,C.setAttribute("aria-expanded","false"),p=!0,sync())}function click(e){var t;(null==(t=e.target)?void 0:t.closest("button,a,iframe"))||(p=!1,select(),sync())}function viewport(){sync()}S.addEventListener("input",validate),M.addEventListener("submit",e=>{e.preventDefault(),validate();const n=current(),o=Xe(S.value).data;n&&o&&!I.disabled&&t.isEditable&&(t.view.dispatch(Ve(t.state.tr.setNodeMarkup(n.pos,void 0,{...n.node.attrs,...o}))),closeEdit(),C.focus())});for(const e of[n,l])e.addEventListener("pointerenter",enter),e.addEventListener("pointerleave",leave),e.addEventListener("focusin",focus),e.addEventListener("focusout",blur),e.addEventListener("keydown",keydown);n.addEventListener("click",click),document.addEventListener("pointerdown",outside,!0),document.addEventListener("pointermove",pointerMove,!0),window.addEventListener("scroll",viewport,!0),window.addEventListener("resize",viewport),t.on("transaction",sync),t.on("update",sync);const R="undefined"==typeof ResizeObserver?void 0:new ResizeObserver(schedule);null==R||R.observe(n),null==R||R.observe(l);const z=r.subscribe(localize);return localize(),{update:sync,destroy(){c=!0,clearTimeout(a),clearTimeout(s),cancelAnimationFrame(v),z(),null==R||R.disconnect(),t.off("transaction",sync),t.off("update",sync),document.removeEventListener("pointerdown",outside,!0),document.removeEventListener("pointermove",pointerMove,!0),window.removeEventListener("scroll",viewport,!0),window.removeEventListener("resize",viewport),n.removeEventListener("click",click);for(const e of[n,l])e.removeEventListener("pointerenter",enter),e.removeEventListener("pointerleave",leave),e.removeEventListener("focusin",focus),e.removeEventListener("focusout",blur),e.removeEventListener("keydown",keydown);l.remove(),it.get(t)===P&&it.delete(t)}}}({editor:n,dom:r,getPos:()=>o(),policy:()=>P.current.video,portal:()=>P.current.portal,reload:()=>{u++,c&&render()}}):void 0;return queueMicrotask(()=>{c&&render()}),{dom:r,update:e=>e.type===s.type&&("mindMap"!==s.type.name||e.attrs.id===s.attrs.id)&&(s=e,c&&render(),null==p||p.update(),!0),stopEvent:()=>!0,ignoreMutation:()=>!0,destroy(){null==d||d.dispose(),null==p||p.destroy(),c&&queueMicrotask(()=>{c&&Be(e=>e.filter(e=>e.id!==l))})}}},menuCoords=e=>{var t;try{const n=h.view.coordsAtPos(e),o=(null==(t=y.current)?void 0:t.getBoundingClientRect())??{left:0,top:0};return{x:n.left-o.left,y:n.bottom-o.top+6}}catch{return{x:0,y:0}}};try{const e=S.current.value??S.current.defaultValue??at,r=(new C).validate(e,S.current.schemaVersion??E(e,M));h=new s({element:p,editable:!S.current.disabled,content:S.current.collabDoc?void 0:r.doc,extensions:le({i18n:f,placeholder:()=>S.current.placeholder??b("输入 / 唤起命令,开始记录…"),collabDoc:S.current.collabDoc,collabAwareness:S.current.collabAwareness,canCopyCode:()=>!!S.current.allowExport,contentContext:()=>P.current,attachmentFetcher:null==(t=T.current.attachments)?void 0:t.fetch,attachmentScope:T.current.scope,attachmentPortal:()=>P.current.portal,inlineComments:{getComments:()=>S.current.inlineComments??[],getActiveId:()=>S.current.activeCommentId??null,onMarkClick:e=>{var t,n;return null==(n=(t=S.current).onInlineMarkClick)?void 0:n.call(t,e)}},slash:{onOpen:e=>{V({...e,...menuCoords(e.from)}),J(!1),j(null)},onUpdate:e=>V(t=>t?{...t,query:e}:null),onClose:()=>V(null)},blockHandle:{onHover:onBlockHover},uploadPlaceholder:{onLost:()=>vt(b("上传目标已移除,附件未插入。"))},tableInteraction:{onHover:e=>K(e)},mindMapRenderer:atom,videoRenderer:atom}),editorProps:{attributes:{role:"textbox","aria-label":b("文档正文"),"aria-multiline":"true",class:"editor-canvas ywiki-prose ywiki-content"},handleKeyDown:(e,t)=>!(!t.ctrlKey&&!t.metaKey||"k"!==t.key.toLowerCase()||(t.preventDefault(),openLink(h),0)),handlePaste:(e,t)=>{var n,o;if(!e.editable)return!1;const r=oe(t);if(r.length)return upload(r),!0;const i=(null==(o=null==(n=t.clipboardData)?void 0:n.getData("text/plain"))?void 0:o.trim())??"";if(e.state.selection.empty&&!e.state.selection.$from.parent.content.size&&A(i)){const t=e.state.selection.from,n=e.state.tr.insertText(i);return n.addMark(t,t+i.length,e.state.schema.marks.link.create({href:i})),e.dispatch(n),je.current={from:t,to:t+i.length,valid:!0},Ne(i),Me(!0),!0}return re(t).length&&setTimeout(()=>{c&&async function upgradeRemoteImages(e){var t,n,o;const r=T.current.scope,i=null==(t=T.current.attachments)?void 0:t.fetch,a=S.current.uploadImage??(null==(n=T.current.attachments)?void 0:n.uploadImage);if(!a)return void vt(b("未配置图片上传服务,无法保存粘贴的外链图片"));const s=[];e.state.doc.descendants((e,t)=>{if("image"===e.type.name&&!e.attrs.attachmentId&&/^https?:\/\//i.test(String(e.attrs.src))){const n={from:t,to:t+e.nodeSize,valid:!0};Ye.current.add(n),s.push({target:n,src:e.attrs.src})}}),Pe.current+=s.length,z(e=>e+1);for(const{target:t,src:n}of s)try{const s=await fetch(n,{credentials:"omit",signal:AbortSignal.timeout(15e3)});if(!s.ok||Number(s.headers.get("content-length"))>20971520)throw new Error(b("外链图片读取失败或超过 20 MB"));const c=await s.blob();if(!c.type.startsWith("image/")||c.size>20971520)throw new Error(b("外链图片格式无效或超过 20 MB"));const u=await a(new File([c],b("粘贴图片"),{type:c.type}));if(e.isDestroyed||!e.isEditable||!t.valid||(null==(o=e.state.doc.nodeAt(t.from))?void 0:o.attrs.src)!==n)continue;const d=e.state.doc.nodeAt(t.from);l(u.id,c,r,i),e.view.dispatch(e.state.tr.setNodeMarkup(t.from,void 0,{...d.attrs,src:null,attachmentId:u.id,alt:u.alt}))}catch(t){e.isDestroyed||ht(t)}finally{Ye.current.delete(t),Pe.current--,e.isDestroyed||z(e=>e+1)}}(h)},0),!1},handleDrop:(e,t)=>{var n;if(!e.editable||!(null==(n=t.dataTransfer)?void 0:n.files.length))return!1;const o=e.posAtCoords({left:t.clientX,top:t.clientY});return!!o&&(t.preventDefault(),upload([...t.dataTransfer.files],o.pos),!0)},handleDOMEvents:{contextmenu:(e,t)=>{var n,o;if(!(e.editable&&t.target instanceof Element))return!1;if(t.target.closest("td,th"))return!1;const r=t.target.closest(".ProseMirror > *"),l=null==(n=y.current)?void 0:n.getBoundingClientRect();if(!r||r.parentElement!==e.dom||!l)return!1;let i=-1;e.state.doc.forEach((t,n)=>{e.nodeDOM(n)===r&&(i=n)});const a=e.state.doc.nodeAt(i);return!!a&&(t.preventDefault(),pe(null),V(null),tt.current=!1,ct.current="explicit",null==(o=ut.current)||o.reset(),U({pos:i,type:a.type.name,top:t.clientY-l.top,contentLeft:t.clientX-l.left,isEmpty:a.isTextblock&&!a.content.size}),G(void 0),J(!0),!0)},mouseover:(e,t)=>{var n;if(xe.current||!e.editable)return!1;const o=null==(n=t.target)?void 0:n.closest("a[href]");if(!o||!e.dom.contains(o))return!1;const r=e.posAtDOM(o,0),l=a(e.state.doc.resolve(r),e.state.schema.marks.link);if(!l)return!1;const i=o.getBoundingClientRect(),s=createLinkEditTarget(e.state,u.create(e.state.doc,l.from,l.to));return s&&pe({...s,tracked:s,mode:"preview",anchor:{left:i.left,top:i.top,width:i.width,height:i.height}}),!1}}},onUpdate:({editor:e,transaction:t})=>{var n,o;I.current=e.getJSON(),z(e=>e+1),null==(o=(n=S.current).onChange)||o.call(n,I.current,{remote:isRemoteDocumentChange(t)})},onSelectionUpdate:()=>z(e=>e+1),onTransaction:({transaction:e})=>{je.current&&advanceTarget(je.current,e);for(const t of Ye.current)advanceTarget(t,e);const t=xe.current;(null==t?void 0:t.tracked)&&(advanceTarget(t.tracked,e),t.from=t.tracked.from,t.to=t.tracked.to),z(e=>e+1)},onBlur:()=>{var e,t;return null==(t=(e=S.current).onBlur)?void 0:t.call(e)}}),L.current=h,y.current&&(We.current=function documentGestures(e,t,n){const o=e.view;let r=null,l=0,i=null;const writable=()=>!e.isDestroyed&&e.isEditable;function pickedImage(e){i=e,n.onImagePick(e)}function cancel(){null==r||r(),r=null}function start(t,i,a){if(!writable()||0!==i.button||o.composing)return;cancel();let s=Z(o);if(!s.some(e=>e.from===t)){const e=o.state.doc.nodeAt(t);if(!e)return;s=[{from:t,to:t+e.nodeSize}]}if(!s.length)return;const c=o.state.doc,d=s[0].from,m=s.at(-1).to,p=s.some(e=>{var t;return null==(t=e.images)?void 0:t.length}),h=o.state.selection,v={x:i.clientX,y:i.clientY};let f=!1,g=v,b=null,w=0;const y=document.createElement("div");y.className="wr-block-drop-line block-drop-line",y.setAttribute("aria-hidden","true");const k=document.documentElement.style.cursor,x=document.body.style.userSelect;function paint(){if(!writable()||o.state.doc!==c)return void cancel();b=function pickNearestGap(e,t){if(0===e.length)return null;let n=e[0],o=Math.abs(e[0].y-t);for(const r of e){const e=Math.abs(r.y-t);e<o&&(n=r,o=e)}return n}(function gaps(){const e=[];return o.state.doc.forEach((t,n)=>{const r=o.nodeDOM(n);if(!(r instanceof HTMLElement))return;const l=r.getBoundingClientRect();e.push({pos:n,y:l.top}),n+t.nodeSize===o.state.doc.content.size&&e.push({pos:n+t.nodeSize,y:l.bottom})}),e}(),g.y);const e=o.dom.getBoundingClientRect();b&&Object.assign(y.style,{left:`${e.left}px`,top:`${b.y}px`,width:`${e.width}px`}),y.hidden=!b||b.pos>=d&&b.pos<=m}const scroll=()=>{if(!f)return;let e=o.dom.parentElement;for(;e&&!(e.scrollHeight>e.clientHeight&&/auto|scroll/.test(getComputedStyle(e).overflowY));)e=e.parentElement;const t=(null==e?void 0:e.getBoundingClientRect())??{top:0,bottom:innerHeight},n=g.y<t.top+42?-14:g.y>t.bottom-42?14:0;n&&(e?e.scrollTop+=n:window.scrollBy(0,n),paint()),w=requestAnimationFrame(scroll)},move=e=>{g={x:e.clientX,y:e.clientY},!f&&Math.hypot(g.x-v.x,g.y-v.y)<4||(f||(Z(o).some(e=>e.from===t)||te(o,t,t),f=!0,n.onStart(),n.layer().append(y),o.dom.classList.add("is-block-dragging"),document.documentElement.style.cursor="grabbing",document.body.style.userSelect="none",w=requestAnimationFrame(scroll)),paint(),e.preventDefault())},up=e=>{const t=b,n=f;if(cancel(),!writable()||o.state.doc!==c)return;if(!n){if(a)a();else{const t=o.posAtCoords({left:e.clientX,top:e.clientY});t&&o.dispatch(o.state.tr.setSelection(u.near(o.state.doc.resolve(t.pos)))),o.focus()}return}if(l=Date.now()+400,!t||t.pos>=d&&t.pos<=m)return;const r=o.state.selection;if(p&&(!(r instanceof ee)||!r.eq(h)))return;const i=p?r.content():o.state.doc.slice(d,m),s=o.state.tr;p?r.replace(s):s.delete(d,m);const v=s.mapping.map(t.pos),g=s.steps.length;s.insert(v,i.content),s.steps.length!==g&&(o.dispatch(s.scrollIntoView()),o.focus())},key=e=>{"Escape"!==e.key||e.isComposing||(e.preventDefault(),e.stopImmediatePropagation(),l=Date.now()+400,cancel())},change2=()=>{o.state.doc===c&&writable()||cancel()};r=()=>{window.removeEventListener("mousemove",move,!0),window.removeEventListener("mouseup",up,!0),window.removeEventListener("keydown",key,!0),window.removeEventListener("blur",cancel),window.removeEventListener("pointercancel",cancel),e.off("transaction",change2),cancelAnimationFrame(w),y.remove(),o.dom.classList.remove("is-block-dragging"),document.documentElement.style.cursor=k,document.body.style.userSelect=x,n.onEnd()},window.addEventListener("mousemove",move,!0),window.addEventListener("mouseup",up,!0),window.addEventListener("keydown",key,!0),window.addEventListener("blur",cancel),window.addEventListener("pointercancel",cancel),e.on("transaction",change2),i.preventDefault()}function pickImage(e){var t;try{const n=o.posAtDOM(e,0);if("image"!==(null==(t=o.state.doc.nodeAt(n))?void 0:t.type.name))return;pickedImage(n),o.dispatch(o.state.tr.setSelection(m.create(o.state.doc,n))),o.focus()}catch{}}function down(e){if(!writable()||o.composing||0!==e.button||!(e.target instanceof Element))return;const t=e.target;if(t.closest("button,input,textarea,select,a,video,audio,.math-node"))return;const l=Z(o),a=t.closest(".ywiki-image-gallery");if(a&&!t.closest(".ywiki-image-frame")&&!a.matches(".is-block-selected,.is-block-image-selected"))return void function gallerySelect(e,t){cancel(),t.preventDefault(),t.stopPropagation();const l=o.state.doc,i={x:t.clientX,y:t.clientY},a=Array.from(e.children).filter(e=>e instanceof HTMLElement&&e.classList.contains("ywiki-image-frame")),s=document.createElement("div");s.className="ywiki-gallery-marquee",s.hidden=!0,n.layer().append(s);let c=!1;const u=document.body.style.userSelect;document.body.style.userSelect="none";const move=e=>{if(!writable()||o.state.doc!==l)return void cancel();if(!c&&Math.hypot(e.clientX-i.x,e.clientY-i.y)<6)return;c=!0,s.hidden=!1;const t=Math.min(i.x,e.clientX),n=Math.min(i.y,e.clientY),r=Math.max(i.x,e.clientX),u=Math.max(i.y,e.clientY);Object.assign(s.style,{left:`${t}px`,top:`${n}px`,width:r-t+"px",height:u-n+"px"});for(const e of a){const o=e.getBoundingClientRect();e.classList.toggle("is-multi-picked",o.right>t&&o.left<r&&o.bottom>n&&o.top<u)}e.preventDefault()},up=()=>{const t=a.filter(e=>e.classList.contains("is-multi-picked"));if(cancel(),writable()&&o.state.doc===l)if(c){if(1===t.length)pickImage(t[0]);else if(t.length>1){const n=o.posAtDOM(e,0),r=o.state.doc.resolve(n),l=r.depth?r.before():n,i=t.map(e=>{const t=o.posAtDOM(e,0);return{from:t,to:t+o.state.doc.nodeAt(t).nodeSize}});ne(o,l,i),o.focus()}}else{const e=a.sort((e,t)=>Math.abs(i.x-(e.getBoundingClientRect().left+e.getBoundingClientRect().right)/2)-Math.abs(i.x-(t.getBoundingClientRect().left+t.getBoundingClientRect().right)/2))[0];e&&pickImage(e)}},key=e=>{"Escape"!==e.key||e.isComposing||(e.preventDefault(),cancel())};r=()=>{window.removeEventListener("mousemove",move,!0),window.removeEventListener("mouseup",up,!0),window.removeEventListener("keydown",key,!0),window.removeEventListener("blur",cancel),window.removeEventListener("pointercancel",cancel),s.remove(),document.body.style.userSelect=u;for(const e of a)e.classList.remove("is-multi-picked")},window.addEventListener("mousemove",move,!0),window.addEventListener("mouseup",up,!0),window.addEventListener("keydown",key,!0),window.addEventListener("blur",cancel),window.addEventListener("pointercancel",cancel)}(a,e);if(e.detail<2&&l.length){let n=t.closest(".ProseMirror > *");if((null==n?void 0:n.parentElement)!==o.dom&&(n=null),n){let r=-1;o.state.doc.forEach((e,t)=>{o.nodeDOM(t)===n&&(r=t)});const i=t.closest(".ywiki-image-frame"),a=l.find(e=>{var t;return e.from===r&&(!(null==(t=e.images)?void 0:t.length)||i&&e.images.some(e=>o.posAtDOM(i,0)===e.from))});if(a)return start(a.from,e),void e.stopPropagation()}}const s=t.closest("img.ywiki-image"),c=null==s?void 0:s.closest(".ywiki-image-frame");if(s&&c){const t=o.posAtDOM(c,0),l=i;pickedImage(t);{cancel();const o={x:e.clientX,y:e.clientY,time:Date.now()};let i=0;const move=e=>{i=Math.max(i,Math.hypot(e.clientX-o.x,e.clientY-o.y))},up=()=>{cancel(),i>=6?pickedImage(null):l===t&&writable()&&s.isConnected&&function isImagePreviewTap(e,t){return!(!Number.isFinite(e)||!Number.isFinite(t))&&!(e>=6)&&t<450}(i,Date.now()-o.time)&&n.onPreview(s)};r=()=>{window.removeEventListener("mousemove",move,!0),window.removeEventListener("mouseup",up,!0),window.removeEventListener("blur",cancel)},window.addEventListener("mousemove",move,!0),window.addEventListener("mouseup",up,!0),window.addEventListener("blur",cancel)}}else pickedImage(null);if(t===o.dom){const t=o.state.doc.lastChild,n=t?o.nodeDOM(o.state.doc.content.size-t.nodeSize):null;n instanceof HTMLElement&&e.clientY>=n.getBoundingClientRect().bottom-4&&(e.preventDefault(),o.dispatch(function focusTrailingParagraph(e){const t=e.tr,n=t.doc.lastChild;return"paragraph"===(null==n?void 0:n.type.name)&&0===n.content.size||t.insert(t.doc.content.size,e.schema.nodes.paragraph.create()),t.setSelection(d.atEnd(t.doc)).setStoredMarks(null)}(o.state)),o.focus())}}const nativeDrag=e=>{r&&o.state.selection instanceof ee&&e.preventDefault()},outside=e=>{e.target instanceof Element&&!t.contains(e.target)&&!e.target.closest(".img-toolbar,.img-preview-mask,.w-popover")&&pickedImage(null)},change=({transaction:e})=>{(e.docChanged||o.state.selection instanceof m&&o.state.selection.from!==i)&&pickedImage(null)};return e.on("transaction",change),document.addEventListener("mousedown",outside,!0),o.dom.addEventListener("mousedown",down,!0),o.dom.addEventListener("dragstart",nativeDrag,!0),{start:start,consumeClick:function consumeClick(){const e=Date.now()<l;return l=0,e},cancel:cancel,destroy(){cancel(),o.dom.removeEventListener("mousedown",down,!0),o.dom.removeEventListener("dragstart",nativeDrag,!0),e.off("transaction",change),document.removeEventListener("mousedown",outside,!0)}}}(h,y.current,{layer:()=>P.current.portal??y.current??document.body,onStart:()=>{_e(!0),closeBlockMenu(),B(h.view),V(null),pe(null)},onEnd:()=>{st.current=!1,_e(!1),z(e=>e+1)},onImagePick:Ge,onPreview:e=>{const t=e.getAttribute("src")??"";if(!t)return;const n=fe(e,b("图片预览"));qe({src:t,label:e.alt||b("图片预览"),items:n.items.length?n.items:[{src:t,label:e.alt||b("图片预览")}],index:n.items.length?n.index:0})}})),pt.markReady(),null==(o=(n=S.current).onReady)||o.call(n)}catch(e){ht(e)}return()=>{var e;c=!1,Ie.current=!0,null==(e=We.current)||e.destroy(),We.current=null,je.current=null,L.current=null,null==h||h.destroy(),p.remove(),Be([])}},[n.collabDoc,n.collabAwareness]),g(()=>{const e=L.current;e&&!e.isDestroyed&&e.view.dispatch(e.state.tr.setMeta("content-context",!0))},[N.portal,N.theme,N.accent,D.preferences,n.allowExport,f.version]),g(()=>{var e;const t=L.current;t&&(t.setEditable(!n.disabled,!1),t.view.dispatch(t.state.tr.setMeta("content-capabilities",!0))),n.disabled&&(null==(e=We.current)||e.cancel(),closeBlockMenu(),pe(null),V(null),j(null),U(null),je.current=null,Ae(!1),Me(!1),K(null))},[n.disabled]),g(()=>{const e=L.current;if(e&&n.value&&!n.collabDoc&&n.value!==I.current)try{const t=(new C).validate(n.value,n.schemaVersion??E(n.value,M));e.schema.nodeFromJSON(t.doc).eq(e.state.doc)||e.commands.setContent(t.doc,{emitUpdate:!1}),$("")}catch(e){ht(e)}},[n.value,n.collabDoc,ht]),g(()=>{L.current&&ie(L.current,n.inlineComments??[])},[n.inlineComments,n.activeCommentId]);const snapshot=()=>{var e;return(null==(e=L.current)?void 0:e.getJSON())??S.current.value??S.current.defaultValue??at};function hasPendingTasks(){var e;const t=L.current;return!!t&&(Pe.current>0||Ye.current.size>0||!!je.current||Se||Ee||t.view.composing||!!(null==(e=t.storage.mindMap)?void 0:e.composing)||!!t.view.dom.querySelector(".math-latex-input"))}function selectionRect(){const e=L.current;if(!e||e.state.selection.empty)return null;try{const t=e.view.coordsAtPos(e.state.selection.from);return{left:t.left,top:t.top,width:Math.max(1,t.right-t.left),height:Math.max(1,t.bottom-t.top)}}catch{return null}}function openLink(e=L.current){if(!e||!e.isEditable)return;const t=createLinkEditTarget(e.state);if(!t)return void vt(b("请先选中要添加链接的文字"));const n=e.view.coordsAtPos(t.from);pe({...t,tracked:t,mode:"edit",anchor:{left:n.left,top:n.top,width:Math.max(1,n.right-n.left),height:n.bottom-n.top}})}function rememberInsert(){const e=L.current;(null==e?void 0:e.isEditable)&&(je.current={from:e.state.selection.from,to:e.state.selection.from,valid:!0})}function requestPage(){T.current.references?(rememberInsert(),Ae(!0)):vt(b("未配置资源选择服务"))}function requestVideo(){rememberInsert(),Ne(""),Me(!0)}function insertPending(e){const t=L.current,n=je.current;je.current=null,!(null==t?void 0:t.isEditable)||!(null==n?void 0:n.valid)||n.from>t.state.doc.content.size?vt(b("插入目标已移除,请重新选择位置")):t.chain().focus().insertContentAt({from:n.from,to:n.to},e).run()}function requestFile(e){rememberInsert(),He.current=e,ze.current&&(ze.current.accept="image"===e?"image/*":"",ze.current.click())}async function upload(e,t,n="auto"){var o,r,i,a;const s=L.current;if(!s||!s.isEditable)return;const c=T.current.scope,u=null==(o=T.current.attachments)?void 0:o.fetch,d=t??s.state.selection.from,m=S.current.uploadImage??(null==(r=T.current.attachments)?void 0:r.uploadImage);if("file"!==n&&e.length>1&&e.every(e=>e.type.startsWith("image/"))&&m){const t=crypto.randomUUID();Pe.current++,ae(s.view,{id:t,pos:d,kind:"image",label:b("{0} 张图片",{0:e.length}),file:e[0]});try{if(e.some(e=>e.size>20971520))throw new Error(b("图片不能超过 20 MB"));const n=await Promise.all(e.map(async e=>{const t=await m(e);return!s.isDestroyed&&s.isEditable&&T.current.scope===c&&l(t.id,e,c,u),s.schema.nodes.image.create({attachmentId:t.id,alt:t.alt})}));if(Ie.current||s.isDestroyed||!s.isEditable)return;const o=se(s.view,t);if(null===o)return;const r=s.state.tr;let i=o;for(let e=0;e<n.length;e+=10){const t=n.slice(e,e+10),o=1===t.length?t[0]:s.schema.nodes.imageGallery.create({height:120},t),l=r.mapping.maps.length,a=i;ce(r,a,o),i=r.mapping.slice(l).map(a,1)}s.view.dispatch(r),ue(s.view,t)}catch(e){Ie.current||s.isDestroyed||(ue(s.view,t),ht(e))}finally{s.isDestroyed||ue(s.view,t),Pe.current--,Ie.current||z(e=>e+1)}return}const p=e.map(e=>({file:e,id:crypto.randomUUID()}));for(const{file:e,id:t}of p)ae(s.view,{id:t,pos:d,kind:e.type.startsWith("image/")&&"file"!==n?"image":"file",label:e.name,file:e});Pe.current+=p.length,z(e=>e+1);for(const{file:e,id:t}of p){if(s.isDestroyed){Pe.current--;continue}const o=e.type.startsWith("image/")&&"file"!==n,r=o?S.current.uploadImage??(null==(i=T.current.attachments)?void 0:i.uploadImage):S.current.uploadFile??(null==(a=T.current.attachments)?void 0:a.uploadFile);try{if(!r)throw new Error(b("未配置附件上传服务"));if(e.size>20971520)throw new Error(b("附件不能超过 20 MB"));const n=await r(e);if(Ie.current||s.isDestroyed||!s.isEditable||null===se(s.view,t))continue;l(n.id,e,c,u);const i=o?{attachmentId:n.id,alt:"alt"in n?n.alt:e.name}:{attachmentId:n.id,filename:e.name,mimeType:e.type,size:e.size};de(s.view,t,{type:o?"image":"fileAttachment",attrs:i})}catch(e){s.isDestroyed||Ie.current||(ue(s.view,t),ht(e))}finally{s.isDestroyed||ue(s.view,t),Pe.current--,Ie.current||z(e=>e+1)}}}x(c,()=>({isReady:pt.isReady,whenReady:pt.whenReady,getJSON:snapshot,getSnapshot:snapshot,async prepareSnapshot(){if(!L.current)throw new Error(b("文档尚未就绪"));if(hasPendingTasks())throw new Error(b("请先完成上传、公式或组合输入"));const e=snapshot(),t=E(e,S.current.schemaVersion??M);return(new C).validate(e,t),{doc:e,schemaVersion:t}},hasPendingTasks:hasPendingTasks,focus:()=>{var e;null==(e=L.current)||e.commands.focus()},undo:()=>{var e;return(null==(e=L.current)?void 0:e.commands.undo())??!1},redo:()=>{var e;return(null==(e=L.current)?void 0:e.commands.redo())??!1},hasSelection:()=>!!L.current&&!L.current.state.selection.empty,getSelectionRect:selectionRect,getSelectionForAnchor(){const e=L.current;if(!e||e.state.selection.empty)return null;const{from:t,to:n}=e.state.selection,o=e.state.doc.textBetween(t,n,"\n");return o.trim()?{quote:o,prefix:e.state.doc.textBetween(Math.max(0,t-64),t,"\n"),suffix:e.state.doc.textBetween(n,Math.min(e.state.doc.content.size,n+64),"\n"),start:e.state.doc.textBetween(0,t,"\n").length}:null},setSelection(e,t=e){var n;null==(n=L.current)||n.commands.setTextSelection({from:e,to:t})},setContent(e){var t;if(!S.current.collabDoc)try{const n=e??at,o=(new C).validate(n,S.current.schemaVersion??E(n,M));null==(t=L.current)||t.commands.setContent(o.doc,{emitUpdate:!1}),$("")}catch(e){ht(e)}}}));const ft=L.current,gt=null==ft?void 0:ft.state.selection,bt=gt instanceof m&&"image"===gt.node.type.name?{pos:gt.from,node:gt.node}:null,wt=!!F;let yt=null,kt=null;if(ft&&y.current&&!n.disabled&&!wt&&!_&&!me&&!Ue){const e=y.current.getBoundingClientRect();if(gt instanceof u&&!gt.empty)try{const t=ft.view.coordsAtPos(gt.from),n=ft.view.coordsAtPos(gt.to);yt={x:(t.left+n.right)/2-e.left,y:Math.min(t.top,n.top)-e.top-8}}catch{yt=null}if(bt&&Je===bt.pos)try{const t=ft.view.nodeDOM(bt.pos);if(t instanceof HTMLElement){const n=t.getBoundingClientRect(),o=n.top-e.top-44;kt={x:n.left-e.left+n.width/2,y:o<4?n.bottom-e.top+10:o}}}catch{kt=null}}const xt=_?Y??W:W,Ct=xt&&y.current?function blockAffordanceStyle(e,t,n){const o="plus"===n?rt:lt,r=e.contentLeft-8-o.width,l=t?8-t.getBoundingClientRect().left:8;return{left:Math.max(r,l),top:e.top+(26-o.height)/2}}(xt,y.current,xt.isEmpty?"plus":"chip"):{left:0,top:0},Et=!!xt&&!n.disabled&&(!_||tt.current)&&!Ue&&(!Q||_)&&"table"!==xt.type&&!F&&!yt&&!Oe&&!me;/* @__PURE__ */
106
+ return t("div",{ref:y,className:`wr-document editor-shell${bt&&Je===bt.pos?" img-pick-active":""}${n.className?` ${n.className}`:""}`,"data-block-select-band":!0,children:[H&&/* @__PURE__ */e("p",{role:"status",children:H}),q&&/* @__PURE__ */e("p",{role:"alert",children:q}),
107
+ /* @__PURE__ */e("div",{ref:w,className:"wr-document-mount"}),yt&&ft&&!bt&&/* @__PURE__ */e(SelectionToolbar,{editor:ft,x:yt.x,y:yt.y,canComment:n.canComment,onRequestComment:()=>{var e,t;return null==(t=(e=S.current).onRequestComment)?void 0:t.call(e)},onRequestLink:()=>openLink(ft),onRemoveLink:()=>{ft.chain().focus().unsetLink().run()}}),kt&&bt&&ft&&/* @__PURE__ */t("div",{className:"img-toolbar",role:"toolbar","aria-label":b("图片操作"),style:{left:kt.x,top:kt.y},onMouseDown:e=>e.preventDefault(),children:[["left","center","right"].map(t=>/* @__PURE__ */e("button",{type:"button",className:"it-btn"+(bt.node.attrs.align===t?" on":""),"aria-label":b("图片{0}对齐",{0:b("left"===t?"左":"center"===t?"居中":"右")}),title:b("图片{0}对齐",{0:b("left"===t?"左":"center"===t?"居中":"右")}),"aria-pressed":bt.node.attrs.align===t,onClick:()=>function imageAlign(e){ft&&bt&&ft.isEditable&&(ft.view.dispatch(ft.state.tr.setNodeMarkup(bt.pos,void 0,{...bt.node.attrs,align:e})),ft.commands.focus())}(t),children:/* @__PURE__ */e(Ce,{name:`align-${t}`,size:16})},t)),
115
108
  /* @__PURE__ */e("span",{className:"it-sep","aria-hidden":"true"}),
116
- /* @__PURE__ */e("button",{type:"button",className:"it-btn","aria-label":b("编辑图注"),title:b("编辑图注"),onClick:()=>{const e=ct.view.nodeDOM(ut.pos);e instanceof HTMLElement&&e.dispatchEvent(new CustomEvent("ywiki-caption-edit"))},children:/* @__PURE__ */e(Ce,{name:"text",size:16})}),
117
- /* @__PURE__ */e("button",{type:"button",className:"it-btn","aria-label":b("查看大图"),title:b("查看大图"),onClick:function previewImage(){if(!ct||!ut)return;const e=ct.view.nodeDOM(ut.pos),t=e instanceof HTMLElement?e.querySelector("img"):null,n=(null==t?void 0:t.getAttribute("src"))??"";if(!n)return;const{items:o,index:l}=ve(t,b("图片预览"));He({src:n,label:ut.node.attrs.alt?String(ut.node.attrs.alt):b("图片预览"),items:o.length?o:[{src:n,label:b("图片预览")}],index:o.length?l:0})},children:/* @__PURE__ */e(Ce,{name:"zoom-in",size:16})}),
109
+ /* @__PURE__ */e("button",{type:"button",className:"it-btn","aria-label":b("编辑图注"),title:b("编辑图注"),onClick:()=>{const e=ft.view.nodeDOM(bt.pos);e instanceof HTMLElement&&e.dispatchEvent(new CustomEvent("ywiki-caption-edit"))},children:/* @__PURE__ */e(Ce,{name:"text",size:16})}),
110
+ /* @__PURE__ */e("button",{type:"button",className:"it-btn","aria-label":b("查看大图"),title:b("查看大图"),onClick:function previewImage(){if(!ft||!bt)return;const e=ft.view.nodeDOM(bt.pos),t=e instanceof HTMLElement?e.querySelector("img"):null,n=(null==t?void 0:t.getAttribute("src"))??"";if(!n)return;const{items:o,index:r}=fe(t,b("图片预览"));qe({src:n,label:bt.node.attrs.alt?String(bt.node.attrs.alt):b("图片预览"),items:o.length?o:[{src:n,label:b("图片预览")}],index:o.length?r:0})},children:/* @__PURE__ */e(Ce,{name:"zoom-in",size:16})}),
118
111
  /* @__PURE__ */e("span",{className:"it-sep","aria-hidden":"true"}),
119
- /* @__PURE__ */e("button",{type:"button",className:"it-btn danger","aria-label":b("删除图片"),title:b("删除图片"),onClick:function removeImage(){if(!ct||!ut||!ct.isEditable)return;const e=ct.state.doc.resolve(ut.pos);if("imageGallery"===e.parent.type.name){const t=e.before(),n=t+e.parent.nodeSize,o=new ee(ct.state.doc.resolve(t),ct.state.doc.resolve(n),[{kind:"images",from:t,to:n,images:[{from:ut.pos,to:ut.pos+ut.node.nodeSize}]}]),l=ct.state.tr;return o.replace(l),ct.view.dispatch(l),void ct.view.focus()}ct.chain().focus().deleteRange({from:ut.pos,to:ut.pos+ut.node.nodeSize}).run()},children:/* @__PURE__ */e(Ce,{name:"trash",size:16})})]}),ht&&gt&&(ht.isEmpty?/* @__PURE__ */e(BlockPlus,{info:ht,style:vt,expanded:_,onMouseEnter:()=>enterQuickMenu(ht),onMouseLeave:()=>{var e;return null==(e=nt.current)?void 0:e.leave("trigger")},onClick:()=>openQuickMenu(ht,"insert-below")}):/* @__PURE__ */e(BlockChip,{editor:ct,info:ht,style:vt,expanded:_,onMouseEnter:()=>enterQuickMenu(ht),onMouseLeave:()=>{var e;return null==(e=nt.current)?void 0:e.leave("trigger")},onOpen:()=>openQuickMenu(ht,Ke.some(e=>e===ht.type)?"format":void 0),onOpenFull:()=>{var e;(null==(e=$e.current)?void 0:e.consumeClick())||openQuickMenu(ht,void 0)},onHandleMouseDown:e=>{var t;0===e.button&&(null==ct?void 0:ct.isEditable)&&!ct.view.composing&&(Ge.current=!0,null==(t=$e.current)||t.start(ht.pos,e.nativeEvent,()=>{}))}})),_&&j&&ct&&/* @__PURE__ */e("div",{style:{position:"absolute",inset:0,zIndex:45,pointerEvents:"none"},children:/* @__PURE__ */e(BlockMenu,{editor:ct,info:j,canComment:n.canComment,panelOnly:X,onClose:closeBlockMenu,onRegion:e=>{var t,n;return e?null==(t=nt.current)?void 0:t.enter("menu"):null==(n=nt.current)?void 0:n.leave("menu")},onPickFile:e=>{closeBlockMenu(),requestFile(e)},onPickPage:()=>{closeBlockMenu(),requestPage()},onPickVideo:()=>{closeBlockMenu(),requestVideo()},onRequestComment:()=>{var e,t;const n=ct.state.doc.nodeAt(j.pos);n&&ct.commands.setTextSelection({from:j.pos+1,to:j.pos+n.nodeSize-1}),null==(t=(e=S.current).onRequestComment)||t.call(e)},onNotice:at,onCopyLink:()=>{var e;const t=n.pageId?null==(e=D.references)?void 0:e.resolve(n.pageId,"当前内容"):null;(null==t?void 0:t.href)?navigator.clipboard.writeText(t.href).catch(()=>at(b("无法写入剪贴板"))):at(b("宿主未配置当前内容链接"))},onSharePage:n.onSharePage,onConvertToSubpage:n.onConvertToSubpage,onSaveAsTemplate:n.onSaveAsTemplate})}),F&&ct&&/* @__PURE__ */e(SlashMenu,{editor:ct,from:F.from,query:F.query,x:F.x,y:F.y,onClose:()=>V(null),onPickFile:requestFile,onPickPage:requestPage,onPickVideo:requestVideo}),ct&&!n.disabled&&!We&&/* @__PURE__ */e(TableControls,{editor:ct,hover:Q,revision:R,onNotice:at,onBlockDrag:(e,t,n)=>{var o;return null==(o=$e.current)?void 0:o.start(e,t,n)}}),
120
- /* @__PURE__ */e("input",{ref:Pe,hidden:!0,type:"file",multiple:!0,onChange:e=>{const t=Fe.current;Fe.current=null,(null==t?void 0:t.valid)?e.target.files&&upload([...e.target.files],t.from,Re.current):at(b("插入目标已移除,请重新选择位置")),e.target.value=""}}),me&&/* @__PURE__ */e(LinkPopover,{target:me,onClose:()=>ke(null),onEdit:()=>ke({...me,mode:"edit"}),onSave:e=>applyLink(e),onRemove:()=>applyLink(null)},me.mode),Ee&&/* @__PURE__ */e(VideoEmbedDialog,{initialUrl:Ne,onClose:()=>{Fe.current=null,Me(!1)},onInsert:e=>{insertPending({type:"videoEmbed",attrs:e}),Me(!1)}}),De&&/* @__PURE__ */e(PagePicker,{spaceId:n.spaceId,excludeId:n.pageId,title:b("选择要引用的页面"),onClose:()=>{Fe.current=null,Se(!1)},onPick:(e,t)=>{insertPending({type:"pageLink",attrs:{pageId:e,label:t}}),Se(!1)}}),ze&&/* @__PURE__ */e(ge,{src:ze.src,label:ze.label,items:ze.items,index:ze.index,onClose:()=>He(null)}),Ae.map(e=>p(e.content,e.dom,e.id))]});function closeBlockMenu(){var e;null==(e=nt.current)||e.reset(),Je.current=!1,J(!1),U(null),G(void 0)}function applyLink(e){var t;const n=N.current,o=null==(t=xe.current)?void 0:t.tracked;if(!(null==n?void 0:n.isEditable)||!o||!function linkEditTargetCurrent(e,t){return t.valid&&t.from<t.to&&t.from>=0&&t.to<=e.doc.content.size&&JSON.stringify(e.doc.slice(t.from,t.to).toJSON())===t.contentJSON}(n.state,o))return at(b("目标文字或链接已变化,请重新选择")),void ke(null);const l=n.chain().focus().setTextSelection({from:o.from,to:o.to});e?l.setLink({href:e}).run():l.unsetLink().run(),ke(null)}});let ot;function sameDocument(e,t){if(!e||!t)return e===t;try{return ot??(ot=s(re())),ot.nodeFromJSON(e).eq(ot.nodeFromJSON(t))}catch{return!1}}export{De as ANCHORED_POPOVER_ARROW_INSET,Se as ANCHORED_POPOVER_GAP,Ae as ANCHORED_POPOVER_VIEW_MARGIN,me as COLLAB_FIELD,nt as DocumentEditor,Xe as DocumentExportMenu,re as coreExtensions,Le as placeAnchoredPopover,sameDocument};
112
+ /* @__PURE__ */e("button",{type:"button",className:"it-btn danger","aria-label":b("删除图片"),title:b("删除图片"),onClick:function removeImage(){if(!ft||!bt||!ft.isEditable)return;const e=ft.state.doc.resolve(bt.pos);if("imageGallery"===e.parent.type.name){const t=e.before(),n=t+e.parent.nodeSize,o=new ee(ft.state.doc.resolve(t),ft.state.doc.resolve(n),[{kind:"images",from:t,to:n,images:[{from:bt.pos,to:bt.pos+bt.node.nodeSize}]}]),r=ft.state.tr;return o.replace(r),ft.view.dispatch(r),void ft.view.focus()}ft.chain().focus().deleteRange({from:bt.pos,to:bt.pos+bt.node.nodeSize}).run()},children:/* @__PURE__ */e(Ce,{name:"trash",size:16})})]}),xt&&Et&&(xt.isEmpty?/* @__PURE__ */e(BlockPlus,{info:xt,style:Ct,expanded:_,onMouseEnter:()=>enterQuickMenu(xt),onMouseLeave:()=>{var e;return null==(e=ut.current)?void 0:e.leave("trigger")},onClick:()=>openQuickMenu(xt,"insert-below")}):/* @__PURE__ */e(BlockChip,{editor:ft,info:xt,style:Ct,expanded:_,onMouseEnter:()=>enterQuickMenu(xt),onMouseLeave:()=>{var e;return null==(e=ut.current)?void 0:e.leave("trigger")},onOpen:()=>openQuickMenu(xt,ot.some(e=>e===xt.type)?"format":void 0),onOpenFull:()=>{var e;(null==(e=We.current)?void 0:e.consumeClick())||openQuickMenu(xt,void 0)},onHandleMouseDown:e=>{var t;0===e.button&&(null==ft?void 0:ft.isEditable)&&!ft.view.composing&&(st.current=!0,null==(t=We.current)||t.start(xt.pos,e.nativeEvent,()=>{}))}})),_&&Y&&ft&&/* @__PURE__ */e("div",{style:{position:"absolute",inset:0,zIndex:45,pointerEvents:"none"},children:/* @__PURE__ */e(BlockMenu,{editor:ft,info:Y,canComment:n.canComment,panelOnly:X,onClose:closeBlockMenu,onRegion:e=>{var t,n;return e?null==(t=ut.current)?void 0:t.enter("menu"):null==(n=ut.current)?void 0:n.leave("menu")},onPickFile:e=>{closeBlockMenu(),requestFile(e)},onPickPage:()=>{closeBlockMenu(),requestPage()},onPickVideo:()=>{closeBlockMenu(),requestVideo()},onRequestComment:()=>{var e,t;const n=ft.state.doc.nodeAt(Y.pos);n&&ft.commands.setTextSelection({from:Y.pos+1,to:Y.pos+n.nodeSize-1}),null==(t=(e=S.current).onRequestComment)||t.call(e)},onNotice:vt,onCopyLink:()=>{var e;const t=n.pageId?null==(e=D.references)?void 0:e.resolve(n.pageId,"当前内容"):null;(null==t?void 0:t.href)?navigator.clipboard.writeText(t.href).catch(()=>vt(b("无法写入剪贴板"))):vt(b("宿主未配置当前内容链接"))},onSharePage:n.onSharePage,onConvertToSubpage:n.onConvertToSubpage,onSaveAsTemplate:n.onSaveAsTemplate})}),F&&ft&&/* @__PURE__ */e(SlashMenu,{editor:ft,from:F.from,query:F.query,x:F.x,y:F.y,onClose:()=>V(null),onPickFile:requestFile,onPickPage:requestPage,onPickVideo:requestVideo}),ft&&!n.disabled&&!Ue&&/* @__PURE__ */e(TableControls,{editor:ft,hover:Q,revision:R,onNotice:vt,onBlockDrag:(e,t,n)=>{var o;return null==(o=We.current)?void 0:o.start(e,t,n)}}),
113
+ /* @__PURE__ */e("input",{ref:ze,hidden:!0,type:"file",multiple:!0,onChange:e=>{const t=je.current;je.current=null,(null==t?void 0:t.valid)?e.target.files&&upload([...e.target.files],t.from,He.current):vt(b("插入目标已移除,请重新选择位置")),e.target.value=""}}),me&&/* @__PURE__ */e(LinkPopover,{target:me,onClose:()=>pe(null),onEdit:()=>pe({...me,mode:"edit"}),onSave:e=>applyLink(e),onRemove:()=>applyLink(null)},me.mode),Ee&&/* @__PURE__ */e(VideoEmbedDialog,{initialUrl:Le,onClose:()=>{je.current=null,Me(!1)},onInsert:e=>{insertPending({type:"videoEmbed",attrs:e}),Me(!1)}}),Se&&/* @__PURE__ */e(PagePicker,{spaceId:n.spaceId,excludeId:n.pageId,title:b("选择要引用的页面"),onClose:()=>{je.current=null,Ae(!1)},onPick:(e,t)=>{insertPending({type:"pageLink",attrs:{pageId:e,label:t}}),Ae(!1)}}),Oe&&/* @__PURE__ */e(ge,{src:Oe.src,label:Oe.label,items:Oe.items,index:Oe.index,onClose:()=>qe(null)}),Te.map(e=>p(e.content,e.dom,e.id))]});function closeBlockMenu(){var e;null==(e=ut.current)||e.reset(),tt.current=!1,J(!1),U(null),G(void 0)}function applyLink(e){var t;const n=L.current,o=null==(t=xe.current)?void 0:t.tracked;if(!(null==n?void 0:n.isEditable)||!o||!function linkEditTargetCurrent(e,t){return t.valid&&t.from<t.to&&t.from>=0&&t.to<=e.doc.content.size&&JSON.stringify(e.doc.slice(t.from,t.to).toJSON())===t.contentJSON}(n.state,o))return vt(b("目标文字或链接已变化,请重新选择")),void pe(null);const r=n.chain().setTextSelection({from:o.from,to:o.to}).focus(void 0,{scrollIntoView:!1});e?r.setLink({href:e}).run():r.unsetLink().run(),pe(null)}});let ct;function sameDocument(e,t){if(!e||!t)return e===t;try{return ct??(ct=c(le())),ct.nodeFromJSON(e).eq(ct.nodeFromJSON(t))}catch{return!1}}export{Se as ANCHORED_POPOVER_ARROW_INSET,Ae as ANCHORED_POPOVER_GAP,Te as ANCHORED_POPOVER_VIEW_MARGIN,me as COLLAB_FIELD,st as DocumentEditor,et as DocumentExportMenu,le as coreExtensions,De as placeAnchoredPopover,sameDocument};