wendang-react 0.6.6 → 0.6.8
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/NOTICE.md +1 -1
- package/README.md +1 -0
- package/dist/bindings/yjs.js +1 -1
- package/dist/chunks/extensions-CreWnubi.js +16 -0
- package/dist/document.js +59 -58
- package/dist/styles/editor-interaction.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/types/engine/editor/extensions/block-selection.d.ts +1 -1
- package/dist/types/engine/editor/leading-paragraph.d.ts +9 -0
- package/dist/types/engine/editor/table-geometry.d.ts +12 -0
- package/integrity.json +29 -24
- package/package.json +3 -3
- package/dist/chunks/extensions-D4JlN-IP.js +0 -16
- /package/third-party-notices/{wendang-export@0.6.5-LICENSE.txt → wendang-export@0.6.6-LICENSE.txt} +0 -0
- /package/third-party-notices/{wendang-export@0.6.5-NOTICE.md.txt → wendang-export@0.6.6-NOTICE.md.txt} +0 -0
package/NOTICE.md
CHANGED
|
@@ -410,7 +410,7 @@ Wendang is licensed under the MIT License; see LICENSE. Third-party components r
|
|
|
410
410
|
| util-deprecate | 1.0.2 | MIT | LICENSE |
|
|
411
411
|
| uuid | 8.3.2 | MIT | LICENSE.md |
|
|
412
412
|
| w3c-keyname | 2.2.8 | MIT | LICENSE |
|
|
413
|
-
| wendang-export | 0.6.
|
|
413
|
+
| wendang-export | 0.6.6 | MIT | LICENSE, NOTICE.md |
|
|
414
414
|
| which-boxed-primitive | 1.1.1 | MIT | LICENSE |
|
|
415
415
|
| which-builtin-type | 1.2.1 | MIT | LICENSE |
|
|
416
416
|
| which-collection | 1.0.2 | MIT | LICENSE |
|
package/README.md
CHANGED
|
@@ -108,6 +108,7 @@ export default function App() {
|
|
|
108
108
|
| 想做什么 | 操作 |
|
|
109
109
|
| --- | --- |
|
|
110
110
|
| 插入标题、表格、图片、代码等 | 空行输入 `/`,或悬停空行后点左侧蓝色「+」;表格先选行列数 |
|
|
111
|
+
| 在文档最上方添加内容 | 点击第一块上方的留白,出现空行与左侧「+」;可直接输入或选择插入内容,重复点击复用已有空行 |
|
|
111
112
|
| 修改文字格式 | 选中文字,在浮动工具栏中选择格式、链接或颜色 |
|
|
112
113
|
| 转换、移动一个块 | 悬停块左侧,点类型图标或抓手打开菜单;按住抓手拖动 |
|
|
113
114
|
| 移动多个块 | 从正文两侧留白拖动框选,再拖动选中区域;Esc 取消,撤销恢复 |
|
package/dist/bindings/yjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{C as
|
|
1
|
+
"use client";import{C as e}from"../chunks/extensions-CreWnubi.js";export{e as COLLAB_FIELD};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";var t=Object.defineProperty,__publicField=(e,n,o)=>((e,n,o)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[n]=o)(e,"symbol"!=typeof n?n+"":n,o);import e from"@tiptap/starter-kit";import n from"@tiptap/extension-link";import o from"@tiptap/extension-placeholder";import{Table as a}from"@tiptap/extension-table";import r from"@tiptap/extension-table-row";import l from"@tiptap/extension-task-list";import i from"@tiptap/extension-task-item";import s from"@tiptap/extension-collaboration";import{a as c,b as d,c as u,d as m,T as p,H as f,l as h,V as g,M as v,C as b}from"./locale-DWpIJ_9X.js";import{readI18n as y}from"wendang/i18n";import{u as w,d as k,e as M,f as x,g as C,c as E}from"./i18n-B0kCsIjc.js";import{Fragment as A,Slice as L}from"@tiptap/pm/model";import{w as S,e as N,r as T}from"./katex-WjrodtTU.js";import{IMAGE_GALLERY_DEFAULT_HEIGHT as P,normalizeGalleryHeight as B,normalizeImageAspectRatio as R,IMAGE_GALLERY_MAX_IMAGES as H,imageAspectRatioFromSize as I}from"wendang/internal/image-gallery";import{jsx as D,jsxs as z}from"react/jsx-runtime";import{useState as $,useRef as O}from"react";import{createRoot as F}from"react-dom/client";import{calloutDOMAttributes as W,effectiveCallout as U,CALLOUT_COLORS as Y,CALLOUT_FILLS as X,CALLOUT_TONES as j,calloutSwatchStyle as q,CALLOUT_ICONS as G}from"wendang/shared";import{closeHistory as J}from"@tiptap/pm/history";import{yUndoPluginKey as V,yCursorPlugin as _}from"@tiptap/y-tiptap";import{validCalloutAttrs as K}from"wendang/internal/callout";import{A as Q}from"./AnchoredPanel-C7jMoPze.js";import{a as Z,b as tt}from"./index-COeA2QcQ.js";import{W as et}from"./Dropdown-D98tXfe0.js";import{C as nt,s as ot,h as at}from"./comment-hint-BhUxKjKK.js";import rt from"@tiptap/extension-code-block";import{codeBlockDisplay as lt,codeLineNumbers as it,codeBlockClass as st}from"wendang/internal/code-block";import{Node as ct,mergeAttributes as dt,Extension as ut}from"@tiptap/core";import{Plugin as mt,PluginKey as pt,Selection as ft,TextSelection as ht,SelectionRange as gt,NodeSelection as vt}from"@tiptap/pm/state";import{r as bt,e as yt,b as wt,s as kt}from"./composition-state-Bl-U1R_2.js";import{Decoration as Mt,DecorationSet as xt}from"@tiptap/pm/view";import{e as Ct,c as Et}from"./code-highlight-BmaqTe1m.js";import{resolveInlineComments as At}from"wendang/internal/inline-comments";import{readableTextColor as Lt}from"wendang/internal/presence";import{CellSelection as St,TableMap as Nt,addRow as Tt,addColumn as Pt,selectedRect as Bt}from"@tiptap/pm/tables";import{cellBackground as Rt,CELL_BACKGROUNDS as Ht}from"wendang/internal/table-cell-format";import{TABLE_CELL_MIN_WIDTH as It}from"wendang/internal/table-layout";import Dt from"@tiptap/extension-table-cell";import zt from"@tiptap/extension-table-header";import{paletteColor as $t}from"wendang/internal/document-colors";import Ot from"@tiptap/extension-image";const Ft=ct.create({name:"columns",group:"block",content:"column+",defining:!0,parseHTML:()=>[{tag:"div[data-columns]"}],renderHTML:({HTMLAttributes:t})=>["div",dt(t,{"data-columns":"true","data-block-chrome":"",class:"doc-columns"}),0]}),Wt=ct.create({name:"column",content:"block+",defining:!0,parseHTML:()=>[{tag:"div[data-column]"}],renderHTML:({HTMLAttributes:t})=>["div",dt(t,{"data-column":"true",class:"doc-column"}),0]});function buildColumnsJson(t){const e=Math.min(Math.max(Math.round(t),1),5);return{type:"columns",content:Array.from({length:e},()=>({type:"column",content:[{type:"paragraph"}]}))}}const Ut=ct.create({name:"fileAttachment",group:"block",atom:!0,selectable:!0,draggable:!1,addAttributes:()=>({attachmentId:{default:null},filename:{default:""},mimeType:{default:""},size:{default:0}}),parseHTML:()=>[{tag:"div[data-file-attachment]"}],renderHTML({HTMLAttributes:t,node:e}){const n=e.attrs.filename||"附件";return["div",dt(t,{"data-file-attachment":"true","data-attachment-id":e.attrs.attachmentId??"","data-block-chrome":"",class:"doc-file-attachment"}),`[附件]${n}`]},renderText:({node:t})=>t.attrs.filename||"附件"}),Yt=Ot.extend({addAttributes(){var t;return{...null==(t=this.parent)?void 0:t.call(this),attachmentId:{default:null,parseHTML:t=>t.getAttribute("data-attachment-id"),renderHTML:t=>t.attachmentId?{"data-attachment-id":t.attachmentId}:{}},width:{default:null,parseHTML:t=>{const e=t.getAttribute("data-width")??t.getAttribute("width"),n=Number(e);return Number.isFinite(n)&&n>0?Math.round(n):null},renderHTML:t=>{const e=Number(t.width);return Number.isFinite(e)&&e>0?{"data-width":String(Math.round(e)),width:String(Math.round(e))}:{}}},align:{default:null,parseHTML:t=>{const e=t.getAttribute("data-align");return"left"===e||"center"===e||"right"===e?e:null},renderHTML:t=>{const e=t.align;return"left"===e||"center"===e||"right"===e?{"data-align":e}:{}}},aspectRatio:{default:null,parseHTML:t=>{const e=Number(t.getAttribute("data-aspect-ratio"));return Number.isFinite(e)&&e>0?e:null},renderHTML:t=>{const e=Number(t.aspectRatio);return Number.isFinite(e)&&e>0?{"data-aspect-ratio":String(e)}:{}}},galleryScale:{default:null,parseHTML:t=>{const e=Number(t.getAttribute("data-gallery-scale"));return Number.isFinite(e)&&e>0?e:null},renderHTML:t=>{const e=Number(t.galleryScale);return Number.isFinite(e)&&e>0&&1!==e?{"data-gallery-scale":String(e)}:{}}},caption:{default:null,parseHTML:t=>t.getAttribute("data-caption")||null,renderHTML:t=>t.caption?{"data-caption":String(t.caption)}:{}}}},parseHTML(){var t;return[{tag:"img[data-attachment-id]"},...(null==(t=this.parent)?void 0:t.call(this))??[]]}}),Xt=ct.create({name:"imageGallery",group:"block",content:"image{2,10}",defining:!0,addAttributes:()=>({height:{default:P,parseHTML:t=>B(t.getAttribute("data-gallery-height")),renderHTML:t=>{const e=B(t.height);return{"data-gallery-height":String(e),style:`--image-gallery-height:${e}px`}}}}),parseHTML:()=>[{tag:"div[data-image-gallery]"}],renderHTML:({HTMLAttributes:t})=>["div",dt(t,{"data-image-gallery":"true",class:"ywiki-image-gallery"}),0]}),jt=ct.create({name:"mathInline",group:"inline",inline:!0,atom:!0,selectable:!0,addAttributes:()=>({latex:{default:"",parseHTML:t=>t.getAttribute("data-latex")??"",renderHTML:t=>({"data-latex":t.latex})}}),parseHTML:()=>[{tag:"span[data-math-inline]"}],renderHTML:({HTMLAttributes:t,node:e})=>["span",dt(t,{"data-math-inline":"true",class:"doc-math-inline"}),`$${e.attrs.latex}$`],renderText:({node:t})=>`$${t.attrs.latex}$`}),qt=ct.create({name:"mathBlock",group:"block",atom:!0,selectable:!0,addAttributes:()=>({latex:{default:"",parseHTML:t=>t.getAttribute("data-latex")??"",renderHTML:t=>({"data-latex":t.latex})}}),parseHTML:()=>[{tag:"div[data-math-block]"}],renderHTML:({HTMLAttributes:t,node:e})=>["div",dt(t,{"data-math-block":"true","data-block-chrome":"",class:"doc-math-block"}),`$$${e.attrs.latex}$$`],renderText:({node:t})=>`$$\n${t.attrs.latex}\n$$`}),Gt=ct.create({name:"pageLink",group:"inline",inline:!0,atom:!0,selectable:!0,addAttributes:()=>({pageId:{default:null},label:{default:""}}),parseHTML:()=>[{tag:"span[data-page-link]",getAttrs:t=>{const e=t;return{pageId:e.getAttribute("data-page-id")??null,label:e.textContent??""}}}],renderHTML:({HTMLAttributes:t,node:e})=>["span",dt(t,{"data-page-link":"true","data-page-id":e.attrs.pageId,class:"doc-page-link"}),e.attrs.label||"页面"],renderText:({node:t})=>t.attrs.label||"页面"}),Jt=ct.create({name:"mention",group:"inline",inline:!0,atom:!0,selectable:!0,addAttributes:()=>({userId:{default:null},label:{default:""}}),parseHTML:()=>[{tag:"span[data-mention]",getAttrs:t=>{var e;const n=t;return{userId:n.getAttribute("data-user-id")??null,label:(null==(e=n.textContent)?void 0:e.replace(/^@/,""))??""}}}],renderHTML:({HTMLAttributes:t,node:e})=>["span",dt(t,{"data-mention":"true","data-user-id":e.attrs.userId,class:"doc-mention"}),`@${e.attrs.label||"用户"}`],renderText:({node:t})=>`@${t.attrs.label||"用户"}`}),Vt=["left","center","right"],isCellAlign=t=>"string"==typeof t&&Vt.includes(t),_t={default:null,parseHTML:t=>{var e;const n=null==(e=t.style)?void 0:e.textAlign;if(isCellAlign(n))return n;const o=t.getAttribute("data-align");return isCellAlign(o)?o:null},renderHTML:t=>isCellAlign(t.align)?{"data-align":t.align,style:`text-align: ${t.align}`}:{}},Kt={default:null,parseHTML:t=>$t(t.getAttribute("data-cell-background")??t.style.backgroundColor,Ht),renderHTML:t=>{const e=Rt(t.backgroundColor);return e?{"data-cell-background":e,style:`background-color: ${e}; color: #202124`}:{}}},Qt=Dt.extend({addAttributes(){var t;return{...null==(t=this.parent)?void 0:t.call(this),align:_t,backgroundColor:Kt}}}),Zt=zt.extend({addAttributes(){var t;return{...null==(t=this.parent)?void 0:t.call(this),align:_t,backgroundColor:Kt}}}),te=/* @__PURE__ */new WeakMap,ee=/* @__PURE__ */new WeakMap,createImageNodeView=(t=w,e,n)=>({node:o,getPos:a,editor:r})=>{var l,i,s,c,d,u,m;y(r).text;let p=ee.get(r);p||(p=crypto.randomUUID(),ee.set(r,p));const f=`ywiki-image-drop-line-${p}`,imageDragLayer=()=>(null==n?void 0:n())??r.view.dom.closest(".editor-shell")??document.body,clearImageDropTargets=()=>{var t;for(const t of r.view.dom.querySelectorAll(".is-image-drop-target"))t.classList.remove("is-image-drop-target");null==(t=document.getElementById(f))||t.remove()},h={get value(){return te.get(r)??null},set value(t){t?te.set(r,t):te.delete(r)}},g=document.createElement("div");g.className="ywiki-image-frame";const v=document.createElement("div");v.className="ywiki-image-inner",g.appendChild(v);const b=document.createElement("img");b.className="ywiki-image",b.setAttribute("draggable","false");let w=String((null==(l=o.attrs)?void 0:l.attachmentId)??"");const inImageGallery=()=>{const t="function"==typeof a?a():null;if(null==t||r.isDestroyed||t>=r.state.doc.content.size)return!1;try{return"imageGallery"===r.state.doc.resolve(t).parent.type.name}catch{return!1}};let M=String((null==(i=o.attrs)?void 0:i.alt)??""),x=o;const aspectCloseEnough=(t,e)=>!(!Number.isFinite(t)||!Number.isFinite(e)||e<=0)&&Math.abs(t-e)/e<=.02,backfillAspectRatio=()=>{var t,e;const n=I(b.naturalWidth,b.naturalHeight);if(null===n)return;const o=R(null==(t=x.attrs)?void 0:t.aspectRatio);if(null!==o&&aspectCloseEnough(o,n))return;const l="function"==typeof a?a():null;if(null==l||r.isDestroyed||!r.isEditable)return;const i=r.state.doc.nodeAt(l);if(!i||"image"!==i.type.name)return;const s=R(null==(e=i.attrs)?void 0:e.aspectRatio);null!==s&&aspectCloseEnough(s,n)||r.view.dispatch(r.state.tr.setNodeMarkup(l,void 0,{...i.attrs,aspectRatio:n}))},markLoaded=()=>{b.removeAttribute("data-image-loading"),M&&(b.alt=M,b.title=M),backfillAspectRatio()};b.setAttribute("data-image-loading","true");const applyWidth=t=>{if(inImageGallery())return b.style.removeProperty("width"),void g.removeAttribute("data-sized");const e=Number(t);Number.isFinite(e)&&e>0?(b.style.width=`${Math.round(e)}px`,g.setAttribute("data-sized","true")):(b.style.removeProperty("width"),g.removeAttribute("data-sized"))};applyWidth(null==(s=o.attrs)?void 0:s.width);const applyAspectRatio=t=>{const e=R(t);null===e?(g.style.removeProperty("--ywiki-image-ratio"),g.removeAttribute("data-aspect-ratio")):(g.style.setProperty("--ywiki-image-ratio",String(e)),g.setAttribute("data-aspect-ratio",String(e)))},applyGalleryScale=t=>{const e=Number(t);Number.isFinite(e)&&e>0&&1!==e?(g.style.setProperty("--ywiki-image-weight",String(e)),g.setAttribute("data-gallery-scale",String(e))):(g.style.removeProperty("--ywiki-image-weight"),g.removeAttribute("data-gallery-scale"))};applyAspectRatio(null==(c=o.attrs)?void 0:c.aspectRatio),applyGalleryScale(null==(d=o.attrs)?void 0:d.galleryScale);const C=document.createElement("div");C.className="ywiki-image-caption",C.setAttribute("contenteditable","false");let E=!1;const applyCaption=t=>{const e="string"==typeof t?t:"";E||(C.textContent=e,C.hidden=0===e.length,g.classList.toggle("has-caption",e.length>0),C.title=e)};function commitCaption(t){var e;E=!1,C.setAttribute("contenteditable","false"),C.classList.remove("is-editing");const n="function"==typeof a?a():null;if(null==n||r.isDestroyed)return;const o=r.state.doc.nodeAt(n);if(!o||"image"!==o.type.name)return;const l=t.trim().slice(0,500);((null==(e=o.attrs)?void 0:e.caption)??"")!==(l||null)?r.view.dispatch(r.state.tr.setNodeMarkup(n,void 0,{...o.attrs,caption:l||null})):applyCaption(l)}function startCaptionEdit(){var t;if(!r.isEditable)return;E=!0,C.hidden=!1,g.classList.add("has-caption"),C.textContent=String((null==(t=x.attrs)?void 0:t.caption)??""),C.setAttribute("contenteditable","true"),C.classList.add("is-editing"),C.focus();const e=document.createRange();e.selectNodeContents(C),e.collapse(!1);const n=window.getSelection();null==n||n.removeAllRanges(),null==n||n.addRange(e)}applyCaption(null==(u=o.attrs)?void 0:u.caption),C.addEventListener("dblclick",t=>{t.preventDefault(),t.stopPropagation(),startCaptionEdit()}),C.addEventListener("keydown",t=>{var e;if(E&&(t.stopPropagation(),!t.isComposing&&229!==t.keyCode))if((t.metaKey||t.ctrlKey)&&"a"===t.key.toLowerCase()){t.preventDefault();const e=document.createRange();e.selectNodeContents(C);const n=window.getSelection();null==n||n.removeAllRanges(),null==n||n.addRange(e)}else"Escape"===t.key?(t.preventDefault(),commitCaption(String((null==(e=x.attrs)?void 0:e.caption)??""))):"Enter"===t.key&&(t.preventDefault(),commitCaption(C.textContent??""))}),C.addEventListener("blur",()=>{E&&commitCaption(C.textContent??"")}),g.addEventListener("ywiki-caption-edit",startCaptionEdit);const applyAlign=t=>{"left"===t||"center"===t||"right"===t?g.setAttribute("data-align",t):g.removeAttribute("data-align")};applyAlign(null==(m=o.attrs)?void 0:m.align);let L,N=null;const load=n=>{if(null==L||L(),null==N||N(),N=null,!n)return b.removeAttribute("src"),b.removeAttribute("data-image-loading"),void b.setAttribute("data-image-missing","true");b.removeAttribute("data-image-missing"),b.removeAttribute("data-image-error"),b.getAttribute("src")?markLoaded():b.setAttribute("data-image-loading","true"),N=S(b,()=>(n=>{null==L||L(),L=k(n,t=>{w===n&&(b.src=t,b.complete&&b.naturalWidth>0?markLoaded():b.addEventListener("load",()=>markLoaded(),{once:!0}))},t,()=>{w===n&&(b.removeAttribute("data-image-loading"),M&&(b.alt=M,b.title=M),b.setAttribute("data-image-error","true"))},e)})(n))};load(w);const T={nw:"nwse-resize",ne:"nesw-resize",sw:"nesw-resize",se:"nwse-resize"},B=[];for(const t of["nw","ne","sw","se"]){const e=document.createElement("div");e.className=`ywiki-image-handle handle-${t}`,e.setAttribute("aria-hidden","true"),e.setAttribute("contenteditable","false"),e.addEventListener("mousedown",e=>startResize(e,t)),v.appendChild(e),B.push(e)}const syncGalleryMode=()=>{const t=inImageGallery();g.classList.toggle("is-in-gallery",t),g.setAttribute("draggable",t?"false":"true");for(const e of B)e.hidden=t};syncGalleryMode(),requestAnimationFrame(()=>syncGalleryMode());const setSelected=t=>{g.classList.toggle("is-selected",t)};let D=null,z=null;const galleryContainerOf=t=>{if(r.isDestroyed)return null;try{const e=r.state.doc.resolve(t),n=e.parent;return"imageGallery"!==n.type.name||0===e.depth?null:{node:n,pos:e.before()}}catch{return null}},onGalleryMove=t=>{const e=D;if(!e)return;e.lastX=t.clientX,e.lastY=t.clientY;const n=g.closest(".ywiki-image-gallery");if(!(n instanceof HTMLElement))return;const o=n.getBoundingClientRect(),a=Array.from(n.children).filter(t=>t instanceof HTMLElement&&t!==z);if(e.outside=t.clientX<o.left-24||t.clientX>o.right+24||t.clientY<o.top-24||t.clientY>o.bottom+24,e.outside)return void(z&&(z.style.opacity="0"));const r=a.filter(t=>t!==g);let l=r.length;for(let e=0;e<r.length;e+=1){const n=r[e].getBoundingClientRect();if(t.clientX<n.left+n.width/2){l=e;break}}e.dropIndex=e.index<=l?l+1:l;const i=r[Math.min(l,r.length-1)];let s=o.left;if(i){const t=i.getBoundingClientRect();s=l>=r.length?t.right:t.left}!function showIndicator(t,e,n){if(!z){z=document.createElement("div"),z.className="ywiki-gallery-drop-line",z.setAttribute("aria-hidden","true");const t=getComputedStyle(g).getPropertyValue("--color-accent").trim()||getComputedStyle(document.documentElement).getPropertyValue("--color-accent").trim()||"#2f6feb";z.style.background=t,z.style.width="3px",z.style.borderRadius="999px",z.style.border="1px solid rgba(255, 255, 255, 0.9)",z.style.boxShadow="0 0 0 1px rgba(0, 0, 0, 0.06), 0 2px 10px rgba(0, 0, 0, 0.18)",imageDragLayer().appendChild(z)}z.style.left=Math.round(t)-1+"px",z.style.top=`${Math.round(e)}px`,z.style.height=`${Math.round(n)}px`,z.style.opacity="1"}(s,o.top,o.height)},onGalleryUp=()=>{const t=D;if(function clearGalleryDrag(){D=null,z&&(z.remove(),z=null),document.removeEventListener("mousemove",onGalleryMove,!0),document.removeEventListener("mouseup",onGalleryUp,!0),g.classList.remove("is-gallery-dragging"),document.documentElement.style.cursor=""}(),!t||!r.isEditable)return;const e="function"==typeof a?a():null;if(null==e)return;const n=galleryContainerOf(e);if(!n)return;const o=r.state.doc.nodeAt(e);if(!o||"image"!==o.type.name)return;if(!t.outside&&t.dropIndex===t.index)return;const l=r.state.tr,i=n.node,s=r.schema.nodes.image,c=r.schema.nodes.imageGallery;if(!s||!c)return;const d=[];if(i.forEach(t=>{d.push(t)}),d.length!==t.childPositions.length)return;const u=n.pos,m=u+i.nodeSize;if(t.outside){const e=function imageHitTest(t,e){if(r.isDestroyed)return null;const n=g.style.pointerEvents;g.style.pointerEvents="none";const o=document.elementFromPoint(t,e);if(g.style.pointerEvents=n,!(o instanceof Element))return null;const a=o.closest(".ywiki-image-frame");if(!(a instanceof HTMLElement)||a===g)return null;const l=g.closest(".ywiki-image-gallery"),i=a.closest(".ywiki-image-gallery");if(i instanceof HTMLElement){if(i===l)return null;let t=null;return r.state.doc.descendants((e,n)=>{if(!t&&"imageGallery"===e.type.name)try{r.view.nodeDOM(n)===i&&(t={kind:"gallery",pos:n,node:e})}catch{}}),t}if(!a.querySelector("img"))return null;let s=null;try{const t=r.view.posAtDOM(a,0),e=[t,t-1,t+1].filter(t=>t>=0&&t<=r.state.doc.content.size);for(const t of e){const e=r.state.doc.nodeAt(t);if("image"===(null==e?void 0:e.type.name)){s=t;break}}}catch(t){s=null}if(null===s)return null;const c=r.state.doc.nodeAt(s);return c?{kind:"image",pos:s,node:c}:null}(t.lastX,t.lastY);if(e&&e.pos!==u)if("image"===e.kind){const n=function mergeIntoStandalone(t,e,n,o,a){const{state:l}=r,i=l.schema.nodes.imageGallery;if(!i)return!1;if(a.pos===t)return!1;const s=[];e.forEach((t,e,n)=>{n!==o&&s.push(t)});const c=s.length>=2?[i.create(e.attrs,A.fromArray(s))]:1===s.length?[s[0]]:[],d=i.create({height:P},A.fromArray([a.node,n])),u=topLevelIndexOf(t),m=topLevelIndexOf(a.pos);return!(u<0||m<0)&&replaceTopLevelBlocks(u,c,m,[d])}(u,i,o,t.index,e);if(n)return}else if(function moveImageIntoGalleryAt(t,e,n,o,a,l){const{state:i}=r,s=i.schema.nodes.imageGallery;if(!s)return!1;if(a.pos===t)return!1;if(a.node.content.childCount>=H)return!1;const c=[];a.node.forEach(t=>{c.push(t)});const d=r.view.nodeDOM(a.pos),u=d instanceof HTMLElement?[...d.querySelectorAll(".ywiki-image-frame")]:[];let m=c.length-1;for(let t=0;t<u.length&&t<c.length;t+=1){const e=u[t].getBoundingClientRect();if(l.x<e.left+e.width/2){m=t;break}m=t+1}const p=Math.max(0,Math.min(m,c.length));c.splice(p,0,n);const f=[];e.forEach((t,e,n)=>{n!==o&&f.push(t)});const h=f.length>=2?[s.create(e.attrs,A.fromArray(f))]:1===f.length?[f[0]]:[],g=topLevelIndexOf(t),v=topLevelIndexOf(a.pos);return!(g<0||v<0)&&replaceTopLevelBlocks(g,h,v,[s.create(a.node.attrs,A.fromArray(c))])}(u,i,o,t.index,e,{x:t.lastX,y:t.lastY}))return;d.splice(t.index,1);const n=d.length>=2?[c.create(i.attrs,A.fromArray(d)),o]:1===d.length?[d[0],o]:[o];return l.replaceWith(u,m,A.fromArray(n)),r.view.dispatch(l),void r.commands.focus()}const p=t.index,f=t.dropIndex>p?t.dropIndex-1:t.dropIndex;if(f===p)return;const[h]=d.splice(p,1);d.splice(f,0,h),l.replaceWith(u,m,c.create(i.attrs,A.fromArray(d))),r.view.dispatch(l),r.commands.focus()};g.addEventListener("mousedown",t=>{if(t.target instanceof Node&&C.contains(t.target))return;if(!inImageGallery())return;const e=g.closest(".ywiki-image-gallery");e instanceof HTMLElement&&(e.classList.contains("is-block-selected")||e.classList.contains("is-block-image-selected"))||function startGalleryDrag(t){if(0!==t.button||!r.isEditable||t.altKey)return;const e="function"==typeof a?a():null;if(null==e)return;const n=galleryContainerOf(e);if(!n)return;const o=[];n.node.forEach((t,e)=>{o.push(n.pos+1+e)});const l=o.indexOf(e);if(l<0)return;const i=t.clientX,s=t.clientY;let c=!1;const arm=e=>{if(c)return;const a=e.clientX-i,r=e.clientY-s;Math.hypot(a,r)<32||(c=!0,document.removeEventListener("mousemove",arm,!0),g.classList.add("is-gallery-dragging"),document.documentElement.style.cursor="grabbing",D={galleryPos:n.pos,galleryEnd:n.pos+n.node.nodeSize,childPositions:o,index:l,dropIndex:l,outside:!1,element:g,lastX:t.clientX,lastY:t.clientY},document.addEventListener("mousemove",onGalleryMove,!0),document.addEventListener("mouseup",onGalleryUp,!0))},blockNativeDrag=t=>{t.preventDefault()};g.addEventListener("dragstart",blockNativeDrag,!0);const stopBlockingDrag=()=>{g.removeEventListener("dragstart",blockNativeDrag,!0),document.removeEventListener("mouseup",stopBlockingDrag,!0)};document.addEventListener("mouseup",stopBlockingDrag,!0),document.addEventListener("mousemove",arm,!0);const cancelArm=()=>{document.removeEventListener("mousemove",arm,!0),document.removeEventListener("mouseup",cancelArm,!0)};document.addEventListener("mouseup",cancelArm,!0)}(t)});const ownPos=()=>{const t="function"==typeof a?a():null;return"number"==typeof t?t:null},visibleRect=()=>{const t=v.getBoundingClientRect();return t.width>1&&t.height>1?t:g.getBoundingClientRect()},dropAfter=t=>{const e=visibleRect();return t.clientX>=e.left+e.width/2},hideMergeHint=()=>{var t;g.classList.remove("is-image-drop-target"),null==(t=document.getElementById(f))||t.remove()};function topLevelIndexOf(t){let e=0,n=0,o=-1;return r.state.doc.forEach(a=>{o<0&&e===t&&(o=n),e+=a.nodeSize,n+=1}),o}function replaceTopLevelBlocks(t,e,n,o){const{state:a}=r,l=[];if(a.doc.forEach(t=>{l.push(t)}),t<0||t>=l.length)return!1;if(n<0||n>=l.length)return!1;if(t===n)return!1;const i=[];for(let a=0;a<l.length;a+=1)a===t?i.push(...e):a===n?i.push(...o):i.push(l[a]);const s=a.tr;try{const a=[];t<=n?(a.push({index:n,nodes:o}),a.push({index:t,nodes:e})):(a.push({index:t,nodes:e}),a.push({index:n,nodes:o}));let i=[],c=0;for(const t of l)i.push(c),c+=t.nodeSize;for(const t of a){const e=s.mapping.map(i[t.index],1),n=s.mapping.map(i[t.index]+l[t.index].nodeSize,-1);s.replaceWith(e,Math.max(e,n),A.fromArray(t.nodes))}r.view.dispatch(s)}catch{return!1}return r.commands.focus(),!0}function startResize(t,e){const n="nw"===e||"sw"===e?-1:1;if(0!==t.button||!r.isEditable)return;if(t.preventDefault(),t.stopPropagation(),inImageGallery())return void function resizeInGallery(t,e){var n;const o="function"==typeof a?a():null;if(null==o)return;const l=r.state.doc.nodeAt(o);if(!l||"image"!==l.type.name)return;const i=t.clientX,s=g.getBoundingClientRect().width,c=Number(null==(n=l.attrs)?void 0:n.galleryScale)||1,d=document.documentElement.style.cursor;g.classList.add("is-resizing"),document.documentElement.style.cursor=T.nw,document.body.style.userSelect="none";let u=c;const onMove=t=>{const n=(t.clientX-i)*e,o=Math.max(24,s+n);var a;a=c*(o/Math.max(1,s)),u=Math.max(.25,Math.min(4,a)),g.style.setProperty("--ywiki-image-weight",String(u))},onUp=()=>{if(window.removeEventListener("mousemove",onMove),window.removeEventListener("mouseup",onUp),window.removeEventListener("blur",onUp),g.classList.remove("is-resizing"),document.documentElement.style.cursor=d,document.body.style.userSelect="",r.isDestroyed)return;const t=r.state.doc.nodeAt(o);if(!t||"image"!==t.type.name)return;const e=Math.round(1e3*u)/1e3;Math.abs(e-c)<.001?g.style.removeProperty("--ywiki-image-weight"):r.view.dispatch(r.state.tr.setNodeMarkup(o,void 0,{...t.attrs,galleryScale:1===e?null:e}))};window.addEventListener("mousemove",onMove),window.addEventListener("mouseup",onUp),window.addEventListener("blur",onUp)}(t,n);g.classList.add("is-resizing");const o=T[e],l=document.documentElement.style.cursor;document.documentElement.style.cursor=o;const i=t.clientX,s=b.getBoundingClientRect().width,c=r.view.dom.clientWidth||Number.POSITIVE_INFINITY,onMove=t=>{const e=(t.clientX-i)*n,o=Math.max(40,Math.min(c,Math.round(s+e)));b.style.width=`${o}px`,g.setAttribute("data-sized","true")},onUp=()=>{window.removeEventListener("mousemove",onMove),window.removeEventListener("mouseup",onUp),window.removeEventListener("blur",onUp),g.classList.remove("is-resizing"),document.documentElement.style.cursor=l;const t=Math.round(b.getBoundingClientRect().width),e="function"==typeof a?a():null;if(null==e||r.isDestroyed)return;const n=r.state.doc.nodeAt(e);n&&"image"===n.type.name&&Number(n.attrs.width)!==t&&r.view.dispatch(r.state.tr.setNodeMarkup(e,void 0,{...n.attrs,width:t}))};window.addEventListener("mousemove",onMove),window.addEventListener("mouseup",onUp),window.addEventListener("blur",onUp)}return g.addEventListener("dragstart",t=>{var e,n;if(inImageGallery())return;const o=ownPos();if(null===o||!r.isEditable)return;const a=r.state.doc.nodeAt(o);if(a&&"image"===a.type.name){h.value={pos:o,node:a},null==(e=t.dataTransfer)||e.setData("text/plain",""),t.dataTransfer&&(t.dataTransfer.effectAllowed="move");try{null==(n=t.dataTransfer)||n.setDragImage(b,b.width/2,Math.min(b.height/2,40))}catch{}}}),g.addEventListener("dragend",()=>{h.value=null,hideMergeHint(),clearImageDropTargets(),queueMicrotask(clearImageDropTargets)}),g.addEventListener("dragover",t=>{if(!h.value)return;const e=ownPos();null!==e&&h.value.pos!==e&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer&&(t.dataTransfer.dropEffect="move"),(t=>{const e=visibleRect();g.classList.add("is-image-drop-target");let n=document.getElementById(f);if(!n){n=document.createElement("div"),n.id=f,n.className="ywiki-image-drop-line",n.setAttribute("aria-hidden","true");const t=getComputedStyle(g).getPropertyValue("--color-accent").trim()||getComputedStyle(document.documentElement).getPropertyValue("--color-accent").trim()||"#2f6feb";n.style.background=t,n.style.width="3px",n.style.borderRadius="999px",n.style.border="1px solid rgba(255, 255, 255, 0.9)",n.style.boxShadow="0 0 0 1px rgba(0, 0, 0, 0.06), 0 2px 10px rgba(0, 0, 0, 0.18)",imageDragLayer().appendChild(n)}const o=dropAfter(t);n.style.top=`${Math.round(e.top)}px`,n.style.height=`${Math.round(e.height)}px`,n.style.left=`${Math.round(o?e.right+4:e.left-4)}px`,n.style.opacity="1"})(t))}),g.addEventListener("dragleave",t=>{if(!h.value)return;const e=t.relatedTarget;e instanceof Node&&g.contains(e)||hideMergeHint()}),g.addEventListener("drop",t=>{var e;const n=h.value;if(!n)return;const o=ownPos();if(null===o)return;if(hideMergeHint(),clearImageDropTargets(),h.value=null,queueMicrotask(clearImageDropTargets),n.pos===o)return;t.preventDefault(),t.stopPropagation();const a=galleryContainerOf(o);if(a){const o=[];a.node.forEach(t=>{o.push(t)}),dropAfter(t)&&o.length;const l=[...(null==(e=g.parentElement)?void 0:e.children)??[]].filter(t=>t instanceof HTMLElement&&t.classList.contains("ywiki-image-frame"));let i=l.length;for(let e=0;e<l.length;e+=1){const n=l[e].getBoundingClientRect();if(t.clientX<n.left+n.width/2){i=e;break}}return void function insertIntoGallery(t,e,n,o){const{state:a}=r,l=a.doc.nodeAt(t);if(!l||"image"!==l.type.name)return!1;const i=a.schema.nodes.imageGallery;if(!i)return!1;if(n.content.content.slice().length>=H)return!1;const s=t<e?l.nodeSize:0,c=[];n.forEach(t=>{c.push(t)}),c.splice(o,0,l);const d=a.tr;d.delete(t,t+l.nodeSize);const u=e-s;d.replaceWith(u,u+n.nodeSize,i.create(n.attrs,A.fromArray(c))),r.view.dispatch(d),r.commands.focus()}(n.pos,a.pos,a.node,i)}!function mergeTwoImages(t,e,n){const{state:o}=r,a=o.doc.nodeAt(t),l=o.doc.nodeAt(e);if(!a||!l||"image"!==a.type.name||"image"!==l.type.name)return!1;const i=o.schema.nodes.imageGallery;if(!i)return!1;const s=n?[l,a]:[a,l],c=Math.min(t,e),d=Math.max(t,e),u=c===t?a:l,m=d===t?a:l,p=o.doc.slice(c+u.nodeSize,d).content,f=i.create({height:P},A.fromArray(s)),h=o.tr.replaceWith(c,d+m.nodeSize,A.fromArray([f]).append(p));r.view.dispatch(h),r.commands.focus()}(n.pos,o,dropAfter(t))}),v.appendChild(b),g.appendChild(C),{dom:g,stopEvent:t=>t.target instanceof Node&&C.contains(t.target),ignoreMutation:t=>"selection"!==t.type||C.contains(t.target),update:t=>{var e,n,o,a,r,l,i,s;if("image"!==t.type.name)return!1;const c=String((null==(e=t.attrs)?void 0:e.alt)??"");c!==M&&(M=c,b.getAttribute("data-image-loading")||(b.alt=M,b.title=M));const d=null==(n=t.attrs)?void 0:n.aspectRatio,u=String(d??"")!==String((null==(o=x.attrs)?void 0:o.aspectRatio)??"");x=t,applyAspectRatio(d),u&&queueMicrotask(backfillAspectRatio),applyGalleryScale(null==(a=t.attrs)?void 0:a.galleryScale),applyCaption(null==(r=t.attrs)?void 0:r.caption),syncGalleryMode(),applyWidth(null==(l=t.attrs)?void 0:l.width),applyAlign(null==(i=t.attrs)?void 0:i.align);const m=String((null==(s=t.attrs)?void 0:s.attachmentId)??"");return m!==w&&(w=m,load(m)),!0},selectNode:()=>{setSelected(!0),syncGalleryMode()},deselectNode:()=>{setSelected(!1),syncGalleryMode()},destroy:()=>{setSelected(!1),w="",hideMergeHint(),clearImageDropTargets(),null==L||L(),null==N||N(),N=null}}};function dispatch(t,e){var n;const o=null==(n=V.getState(t.state))?void 0:n.undoManager;null==o||o.stopCapturing(),t.view.dispatch(J(e)),null==o||o.stopCapturing()}function unwrapCallout(t,e){if(!t.isEditable||t.isDestroyed)return!1;const n=t.state.doc.nodeAt(e);if("callout"!==(null==n?void 0:n.type.name))return!1;const o=t.state.doc.resolve(e);return!!o.parent.canReplace(o.index(),o.index()+1,n.content)&&(dispatch(t,t.state.tr.replaceWith(e,e+n.nodeSize,n.content)),!0)}const ne={info:"💡 提示",success:"✅ 成功",warning:"⚠️ 注意",danger:"❗ 警告"},oe={gray:"灰",red:"红",orange:"橙",yellow:"黄",green:"绿",blue:"蓝",purple:"紫"};function swatchName(t,e,n){if(null===t)return n.t("common.default");if("none"===t)return n.t("common.none");const o=n.text(oe[t.replace("-strong","")]??t);return"backgroundColor"!==e?o:n.t("color.tone",{tone:n.text(t.endsWith("-strong")?"浓":"浅"),color:o})}function CalloutControls({attrs:t,editable:e,portal:n,onPatch:o,onUnwrap:a}){const r=E(),l=r.text,[i,s]=$("none"),[c,d]=$(!1),u=O(null),m=O(null),p=O(null),f=O(null),h=U(t),g="color"===i?m.current:"icon"===i?f.current:null,v=[{key:"textColor",label:l("字体颜色"),values:[null,...Y]},{key:"borderColor",label:l("边框颜色"),values:["none",...Y]},{key:"backgroundColor",label:l("填充颜色"),values:["none",...X]}],selected=(t,e)=>h[t]===e;/* @__PURE__ */
|
|
2
|
+
return z("div",{className:"callout-controls",contentEditable:!1,onPointerDown:t=>t.stopPropagation(),onKeyDown:t=>{"Escape"!==t.key&&t.stopPropagation()},children:[h.icon&&/* @__PURE__ */D(Z,{ref:u,variant:"text",className:"callout-icon callout-icon-button","aria-label":l("更换高亮块图标"),"aria-expanded":"icon"===i,disabled:!e,onClick:t=>{f.current=t.currentTarget,s("icon"===i?"none":"icon")},children:h.icon}),e&&/* @__PURE__ */z("div",{className:"callout-toolbar"+("none"!==i||c?" is-open":""),"aria-label":l("高亮块操作"),children:[
|
|
3
|
+
/* @__PURE__ */D(Z,{ref:m,variant:"text",size:"small",className:"callout-toolbar-button callout-palette-button","aria-label":l("高亮块颜色设置"),"aria-expanded":"color"===i,onClick:()=>s("color"===i?"none":"color"),children:/* @__PURE__ */D(tt,{name:"palette",size:22})}),
|
|
4
|
+
/* @__PURE__ */D(Z,{ref:p,variant:"text",size:"small",className:"callout-toolbar-button","aria-label":l("高亮块图标设置"),"aria-expanded":"icon"===i,onClick:t=>{f.current=t.currentTarget,s("icon"===i?"none":"icon")},children:l("图标")}),
|
|
5
|
+
/* @__PURE__ */D(et,{label:l("预设"),buttonProps:{variant:"text",size:"small",className:"callout-toolbar-button","aria-label":l("高亮块预设")},groups:[{items:j.map(t=>({value:t,label:l(ne[t])}))}],onOpenChange:t=>{d(t),t&&s("none")},onSelect:t=>o({tone:t,icon:null,textColor:null,borderColor:null,backgroundColor:null})}),
|
|
6
|
+
/* @__PURE__ */D("span",{className:"callout-toolbar-divider","aria-hidden":"true"}),
|
|
7
|
+
/* @__PURE__ */D(Z,{variant:"text",size:"small",className:"callout-toolbar-button",onClick:a,children:l("取消高亮块")})]}),"color"===i&&/* @__PURE__ */D(Q,{anchor:g,portal:n,label:l("高亮块颜色"),className:"callout-color-popover",onClose:()=>s("none"),align:"start",prefer:"below",gap:12,children:/* @__PURE__ */z("div",{className:"callout-color-panel",role:"group","aria-label":l("高亮块颜色"),children:[v.map(t=>/* @__PURE__ */z("section",{children:[
|
|
8
|
+
/* @__PURE__ */D("div",{className:"callout-color-heading",children:/* @__PURE__ */D("div",{className:"callout-color-label",children:t.label})}),
|
|
9
|
+
/* @__PURE__ */D("div",{className:"callout-color-grid",role:"group","aria-label":t.label,children:t.values.map(e=>/* @__PURE__ */D("button",{type:"button",className:`callout-color-choice${selected(t.key,e)?" is-selected":""}${"none"===e?" is-none":""}`,style:"textColor"===t.key&&null===e?{color:"var(--content-text-color, var(--color-text, #1f2937))"}:q(t.key,e),"aria-label":`${t.label}:${swatchName(e,t.key,r)}`,title:`${t.label}:${swatchName(e,t.key,r)}`,"aria-pressed":selected(t.key,e),onClick:()=>o({[t.key]:e}),children:"none"===e?/* @__PURE__ */D("span",{className:"color-transparency-grid","aria-hidden":"true"}):"textColor"===t.key?/* @__PURE__ */D("span",{className:"callout-font-sample",children:"A"}):null},e??"default"))})]},t.key)),
|
|
10
|
+
/* @__PURE__ */z("div",{className:"callout-color-footer",children:[
|
|
11
|
+
/* @__PURE__ */D(Z,{variant:"outline",size:"small",block:!0,className:"callout-reset",title:r.t("callout.resetColorsHint"),onClick:()=>o({textColor:null,borderColor:null,backgroundColor:null}),children:l("恢复默认颜色")}),
|
|
12
|
+
/* @__PURE__ */D("p",{className:"callout-color-hint",children:r.t("callout.resetColorsHint")})]})]})}),"icon"===i&&/* @__PURE__ */D(Q,{anchor:g,portal:n,label:l("高亮块图标"),onClose:()=>s("none"),align:"center",prefer:"below",gap:6,children:/* @__PURE__ */z("div",{className:"callout-icon-picker",role:"group","aria-label":l("高亮块图标"),children:[
|
|
13
|
+
/* @__PURE__ */D("div",{className:"callout-icon-grid",children:G.map(t=>/* @__PURE__ */D("button",{type:"button",className:"callout-icon-choice","aria-label":l("高亮块图标:{0}",{0:t}),"aria-pressed":h.icon===t,onClick:()=>{o({icon:t}),s("none")},children:t},t))}),
|
|
14
|
+
/* @__PURE__ */z("div",{className:"callout-icon-footer",children:[
|
|
15
|
+
/* @__PURE__ */D(Z,{size:"small",variant:"text",onClick:()=>{o({icon:""}),s("none")},children:l("隐藏图标")}),
|
|
16
|
+
/* @__PURE__ */D(Z,{size:"small",variant:"text",onClick:()=>{o({icon:null}),s("none")},children:l("默认图标")})]})]})})]})}const ae=rt.extend({addOptions(){var t;return{...null==(t=this.parent)?void 0:t.call(this),canCopy:void 0}},addAttributes(){var t;return{...null==(t=this.parent)?void 0:t.call(this),language:{default:null,parseHTML:t=>function parseLanguage(t){var e;const n=t.getAttribute("data-language");if(n)return n;const o=/(?:^|\s)language-([\w+#-]+)/.exec((null==(e=t.querySelector("code"))?void 0:e.className)||t.className);return o?o[1]:null}(t),renderHTML:t=>t.language?{"data-language":t.language}:{}}}},addNodeView(){return t=this.options.canCopy,e=this.options.contentContext,({node:n,editor:o,getPos:a,extension:r})=>{const l=document.createElement("div"),i=document.createElement("div");l.dataset.blockChrome="";const s=document.createElement("div"),c=document.createElement("div"),d=document.createElement("pre"),u=document.createElement("code");i.className="code-toolbar-host",i.contentEditable="false",s.className="code-scroll",s.setAttribute("aria-label","代码内容"),c.className="code-line-numbers",c.contentEditable="false",c.setAttribute("aria-hidden","true"),d.className="doc-code",d.append(u),s.append(c,d),l.append(i,s);let m=lt(),p=n,f=n.textContent,h=F(i);const paintClass=()=>{const t=["code-block-wrap",...st(m)];for(const e of["code-theme-auto","code-theme-paper","code-theme-soft","code-theme-night","is-collapsed","without-line-numbers","is-unlimited"])l.classList.toggle(e,t.includes(e));l.classList.add("code-block-wrap","ywiki-code-panel"),s.hidden=m.collapsed,c.hidden=!m.lineNumbers},chooseLanguage=t=>{if(!o.isEditable||o.isDestroyed)return;const e=a();if("number"!=typeof e)return;const r=o.state.doc.nodeAt(e);(null==r?void 0:r.type)===n.type&&o.view.dispatch(o.state.tr.setNodeMarkup(e,void 0,{...r.attrs,language:t||null}))},paintToolbar=()=>{const n=null==e?void 0:e(),a=/* @__PURE__ */D(nt,{text:p.textContent,language:String(p.attrs.language??""),editable:o.isEditable,canCopy:(null==t?void 0:t())??!1,display:m,onLanguage:chooseLanguage,onDisplay:t=>{m=t,paintClass(),paintToolbar()}});null==h||h.render(n?/* @__PURE__ */D(C,{value:n,children:a}):a)};c.textContent=it(f),paintClass(),paintToolbar();const syncMode=()=>paintToolbar();o.on("transaction",syncMode),o.on("update",syncMode);const revealSelection=()=>{if(!m.collapsed||!o.isFocused)return;const t=a();if("number"!=typeof t)return;const{from:e,to:n}=o.state.selection;e>t&&n<t+p.nodeSize&&(m={...m,collapsed:!1},paintClass(),paintToolbar())};return o.on("selectionUpdate",revealSelection),{dom:l,contentDOM:u,update:t=>"codeBlock"===t.type.name&&(p=t,t.textContent!==f&&(f=t.textContent,c.textContent=it(f)),paintToolbar(),!0),stopEvent:t=>i.contains(t.target)||c.contains(t.target),ignoreMutation:t=>"selection"!==t.type&&!u.contains(t.target),destroy(){o.off("selectionUpdate",revealSelection),o.off("transaction",syncMode),o.off("update",syncMode);const t=h;h=null,queueMicrotask(()=>null==t?void 0:t.unmount())}}};var t,e}}),re=new pt("ywiki-ime"),le=ut.create({name:"ywikiImeGuard",addProseMirrorPlugins:()=>[new mt({key:re,props:{handleDOMEvents:{compositionstart:()=>(wt(),!1),compositionend:()=>(yt(),!1)}}})],onDestroy(){bt()}}),mathNodeView=({node:t,editor:e,getPos:n})=>{var o;const a=y(e),r=a.text,l="mathBlock"===t.type.name,i=document.createElement(l?"div":"span");i.className=l?"doc-math-block math-node":"doc-math-inline math-node",i.setAttribute("data-math-node",l?"block":"inline"),l&&i.setAttribute("data-block-chrome","");const s=document.createElement("span");s.className="math-render",i.appendChild(s);let c=String((null==(o=t.attrs)?void 0:o.latex)??""),d=null,u=!1,m=!1,p=0;function paint(){const t=++p;s.replaceChildren(),i.classList.remove("doc-math-error","doc-math-pending"),i.removeAttribute("title"),c?(s.textContent=l?`$$${c}$$`:`$${c}$`,i.classList.add("doc-math-pending"),T(c,l).then(e=>{if(!m&&t===p)if(i.classList.remove("doc-math-pending"),e.html&&!e.error)!function setRenderedHtml(t,e){const n=document.createElement("template");n.innerHTML=e,t.replaceChildren(n.content)}(s,e.html);else{i.classList.add("doc-math-error"),i.title=e.error||r("公式渲染失败"),s.textContent=l?`$$${c}$$`:`$${c}$`;const t=document.createElement("span");t.className="doc-math-error-hint",t.textContent=r("(公式渲染失败)"),s.appendChild(t)}})):s.textContent=r("空公式")}function closeEdit(){if(u)return;u=!0;const t=d;d=null,null==t||t.remove(),i.classList.remove("is-editing"),s.style.display="",u=!1}function commit(){var o;if(u)return;if(!d||m||!e.isEditable)return void closeEdit();const a=d.value,r="function"==typeof n?n():void 0;closeEdit(),a!==c&&(c=a,"number"==typeof r&&(null==(o=e.state.doc.nodeAt(r))?void 0:o.type)===t.type?(e.view.dispatch(e.view.state.tr.setNodeMarkup(r,void 0,{...t.attrs,latex:a})),paint()):paint())}i.addEventListener("click",t=>{e.isEditable&&(t.preventDefault(),function beginEdit(){e.isEditable&&!d&&(d=document.createElement("input"),d.type="text",d.className="math-latex-input",d.value=c,d.spellcheck=!1,d.setAttribute("aria-label",r("编辑公式")),d.addEventListener("keydown",t=>{t.stopPropagation(),kt(t)||("Enter"===t.key?(t.preventDefault(),commit()):"Escape"===t.key&&(t.preventDefault(),closeEdit()))}),d.addEventListener("blur",()=>commit()),d.addEventListener("mousedown",t=>t.stopPropagation()),s.style.display="none",i.classList.add("is-editing"),i.appendChild(d),N(),setTimeout(()=>null==d?void 0:d.focus(),0))}())}),paint(),N();const f=a.subscribe(()=>{null==d||d.setAttribute("aria-label",r("编辑公式")),paint()});return{dom:i,update:e=>{var n;if(e.type.name!==t.type.name)return!1;t=e;const o=String((null==(n=e.attrs)?void 0:n.latex)??"");return o!==c&&(c=o,paint()),!0},stopEvent:t=>{var e;const n=t.target;return!!(null==(e=null==n?void 0:n.classList)?void 0:e.contains("math-latex-input"))},ignoreMutation:()=>!0,destroy:()=>{f(),m=!0,p+=1,closeEdit()}}},ie=["left","center","right","justify"],se=ut.create({name:"blockFormat",addOptions:()=>({types:["paragraph","heading"]}),addGlobalAttributes(){return[{types:this.options.types??["paragraph","heading"],attributes:{textAlign:{default:null,parseHTML:t=>{const e=t.getAttribute("data-text-align")??t.style.textAlign;return ie.includes(e)?e:null},renderHTML:t=>{const e=t.textAlign;return e&&ie.includes(e)?{"data-text-align":e,style:`text-align: ${e}`}:{}}},indent:{default:0,parseHTML:t=>{const e=t.getAttribute("data-indent"),n=Number(e);return Number.isFinite(n)&&n>0?Math.min(Math.floor(n),6):0},renderHTML:t=>{const e=Number(t.indent??0);return!Number.isFinite(e)||e<=0?{}:{"data-indent":String(Math.min(Math.floor(e),6)),style:`margin-left: ${24*Math.min(Math.floor(e),6)}px`}}}}}]},addCommands(){return{setTextAlign:t=>({tr:e,state:n,dispatch:o})=>{const a=this.options.types??["paragraph","heading"],{from:r,to:l}=n.selection;let i=!1;return n.doc.nodesBetween(r,l,(n,r)=>{a.includes(n.type.name)&&(o&&e.setNodeMarkup(r,void 0,{...n.attrs,textAlign:t}),i=!0)}),!!i&&(null==o||o(e),!0)},setIndent:t=>({tr:e,state:n,dispatch:o})=>{const a=this.options.types??["paragraph","heading"],r=Math.max(0,Math.min(Math.floor(t),6)),{from:l,to:i}=n.selection;let s=!1;return n.doc.nodesBetween(l,i,(t,n)=>{a.includes(t.type.name)&&Number(t.attrs.indent??0)!==r&&(o&&e.setNodeMarkup(n,void 0,{...t.attrs,indent:r}),s=!0)}),!!s&&(null==o||o(e),!0)},indentBlock:()=>({tr:t,state:e,dispatch:n})=>{const o=this.options.types??["paragraph","heading"],{from:a,to:r}=e.selection;let l=!1;return e.doc.nodesBetween(a,r,(e,a)=>{if(!o.includes(e.type.name))return;const r=Number(e.attrs.indent??0);r>=6||(n&&t.setNodeMarkup(a,void 0,{...e.attrs,indent:r+1}),l=!0)}),!!l&&(null==n||n(t),!0)},outdentBlock:()=>({tr:t,state:e,dispatch:n})=>{const o=this.options.types??["paragraph","heading"],{from:a,to:r}=e.selection;let l=!1;return e.doc.nodesBetween(a,r,(e,a)=>{if(!o.includes(e.type.name))return;const r=Number(e.attrs.indent??0);r<=0||(n&&t.setNodeMarkup(a,void 0,{...e.attrs,indent:r-1}),l=!0)}),!!l&&(null==n||n(t),!0)}}}}),ce=new pt("ywikiBlockSelection");function blockSelectionBand(t){const e=t.dom;if(!e||"function"!=typeof e.getBoundingClientRect)return{left:0,right:0};const n=e.getBoundingClientRect(),o=blockSelectionBandRect(t);return{left:Math.min((null==o?void 0:o.left)??n.left,n.left-48),right:Math.max((null==o?void 0:o.right)??n.right,n.right+48)}}function blockSelectionBandRect(t){var e,n;const o=t.dom;if(!o||"function"!=typeof o.getBoundingClientRect)return null;const a=null==(e=o.closest)?void 0:e.call(o,"[data-block-select-band]"),r=(a instanceof HTMLElement?a:null)??(null==(n=o.closest)?void 0:n.call(o,".editor-shell"))??null;return(null==r?void 0:r.getBoundingClientRect())??null}function autoScrollDelta(t,e,n,o=60,a=16){if(!Number.isFinite(t)||n<=e)return 0;if(t<e+o){const n=Math.min(o,e+o-t);return-Math.ceil(n/o*a)}if(t>n-o){const e=Math.min(o,t-(n-o));return Math.ceil(e/o*a)}return 0}class BlockRangeSelection extends ft{constructor(t,e,n){super(t,e,(null==n?void 0:n.length)?function expandParts(t,e){const n=[];for(const o of e)if("block"!==o.kind)for(const e of o.images)n.push(new gt(t.resolve(e.from),t.resolve(e.to)));else n.push(new gt(t.resolve(o.from),t.resolve(o.to)));return n}(t.doc,n):void 0),__publicField(this,"parts"),__publicField(this,"visible",!1),this.parts=n}content(){const t=this.parts;if(!(null==t?void 0:t.length))return this.$from.doc.slice(this.from,this.to);const e=this.$from.doc,n=[];for(const o of t){if("block"===o.kind){const t=e.nodeAt(o.from);t&&n.push(t);continue}const t=e.nodeAt(o.from);if(!t)continue;const a=[];t.forEach((t,e)=>{const n=o.from+1+e;o.images.some(t=>n>=t.from&&n<t.to)&&a.push(t)}),a.length>=2?n.push(t.type.create(t.attrs,A.fromArray(a))):1===a.length&&n.push(a[0])}return new L(A.fromArray(n),0,0)}replace(t,e=L.empty){var n;if(!(null==(n=this.parts)?void 0:n.length)||e.size>0)return void super.replace(t,e);const o=[...this.parts].sort((t,e)=>e.from-t.from);let a=null;for(const e of o){if("block"===e.kind){t.delete(e.from,e.to),a=e.from;continue}const n=t.doc.nodeAt(e.from);if(!n)continue;const o=[];n.forEach((t,n)=>{const a=e.from+1+n;e.images.some(t=>a>=t.from&&a<t.to)||o.push(t)}),o.length>=2?t.replaceWith(e.from,e.to,n.type.create(n.attrs,A.fromArray(o))):1===o.length?t.replaceWith(e.from,e.to,o[0]):t.delete(e.from,e.to),a=e.from}if(null!==a){const e=Math.max(0,Math.min(a,t.doc.content.size));t.setSelection(ft.near(t.doc.resolve(e),1))}}eq(t){return"ywikiBlockRange"===t.toJSON().type&&t.from===this.from&&t.to===this.to&&JSON.stringify(t.parts??null)===JSON.stringify(this.parts??null)}map(t,e){return ft.near(t.resolve(e.map(this.from,1)))}toJSON(){return{type:"ywikiBlockRange",from:this.from,to:this.to,parts:this.parts}}static fromJSON(t,e){return new BlockRangeSelection(t.resolve(e.from),t.resolve(e.to),e.parts)}getBookmark(){return ft.near(this.$from).getBookmark()}}try{ft.jsonID("ywikiBlockRange",BlockRangeSelection)}catch(t){if(!(t instanceof RangeError)||"Duplicate use of selection JSON ID ywikiBlockRange"!==t.message)throw t}function blockAtY(t,e){const n=[];if(t.state.doc.forEach((e,o)=>{const a=t.nodeDOM(o);if(!(a instanceof HTMLElement))return;const r=a.getBoundingClientRect();n.push({pos:o,node:e,top:r.top,bottom:r.bottom})}),0===n.length)return null;for(const t of n)if(e>=t.top&&e<=t.bottom)return{pos:t.pos,node:t.node};let o=n[0],a=Number.POSITIVE_INFINITY;for(const t of n){const n=e<t.top?t.top-e:e-t.bottom;n<a&&(a=n,o=t)}return a>48?null:{pos:o.pos,node:o.node}}function coveredBlocks(t,e,n){const o=Math.min(e,n),a=Math.max(e,n),r=[];return t.forEach((t,e)=>{const n=e+t.nodeSize;n>o&&e<=a&&r.push({from:e,to:n})}),r}function rectsIntersect(t,e){return t.right>e.left&&t.left<e.right&&t.bottom>e.top&&t.top<e.bottom}function marqueeImageRanges(t,e,n,o){const a=[];let r=0;for(let l=0;l<e.length;l+=1){const i=t+1+r;r+=e[l];const s=n[l];s&&rectsIntersect(o,s)&&a.push({from:i,to:i+e[l]})}return a}function measureBlocksPadding(t,e){if(0===e.length)return[];if("function"!=typeof t.nodeDOM)return[];const n=[];for(const o of e){const e=t.nodeDOM(o.from);if(!(e instanceof HTMLElement))return[];const a=e.getBoundingClientRect();n.push({top:a.top,bottom:a.bottom})}return function selectionPadding(t){if(0===t.length)return[];let e=Number.POSITIVE_INFINITY;for(let n=1;n<t.length;n+=1){const o=t[n].top-t[n-1].bottom;o>0&&(e=Math.min(e,o))}const n=Number.isFinite(e)?Math.max(0,(e-6)/2):5,o=Math.max(0,Math.min(5,n));return t.map(()=>({top:o,bottom:o}))}(n)}function setBlockRangeSelection(t,e,n,o){const{doc:a}=t.state,r=o?function selectionPartsForRange(t,e,n,o,a){const r=[];for(const l of coveredBlocks(e,n,o)){const n=e.nodeAt(l.from);if("imageGallery"===(null==n?void 0:n.type.name)){const e="function"==typeof t.nodeDOM?t.nodeDOM(l.from):null;if(e instanceof HTMLElement){const o=e.getBoundingClientRect();if(rectsIntersect(a,{left:o.left,top:o.top,right:o.right,bottom:o.bottom})){const e=[];n.forEach(t=>e.push(t.nodeSize));const o=[];let i=0;n.forEach(e=>{const n=l.from+1+i;i+=e.nodeSize;const a="function"==typeof t.nodeDOM?t.nodeDOM(n):null;if(!(a instanceof HTMLElement))return void o.push(null);const r=a.getBoundingClientRect();o.push({left:r.left,top:r.top,right:r.right,bottom:r.bottom})});const s=marqueeImageRanges(l.from,e,o,a);if(0===s.length)continue;s.length===e.length?r.push({kind:"block",...l}):r.push({kind:"images",...l,images:s});continue}}}r.push({kind:"block",...l})}return r}(t,a,e,n,o):coveredBlocks(a,e,n).map(t=>({kind:"block",...t}));if(0===r.length)return function clearBlockRangeSelection(t){const e=t.state.tr.setMeta(ce,{blocks:[]});t.dispatch(e)}(t),!1;const l=r[0],i=r[r.length-1],s=new BlockRangeSelection(a.resolve(l.from),a.resolve(i.to),r),c=t.state.tr.setSelection(s),d=measureBlocksPadding(t,r.filter(t=>"block"===t.kind));let u=0;return c.setMeta(ce,{blocks:r.map(t=>{if("images"===t.kind)return{from:t.from,to:t.to,images:t.images};const e=d[u];return u+=1,{from:t.from,to:t.to,padding:e}})}),t.dispatch(c),!0}function setImageRangeSelection(t,e,n){const{doc:o}=t.state,a=o.nodeAt(e);if(!a||"imageGallery"!==a.type.name||0===n.length)return!1;const r=n.length===a.childCount?[{kind:"block",from:e,to:e+a.nodeSize}]:[{kind:"images",from:e,to:e+a.nodeSize,images:n}],l=r[0],i=r[r.length-1],s=new BlockRangeSelection(o.resolve(l.from),o.resolve(i.to),r),c=t.state.tr.setSelection(s),d=measureBlocksPadding(t,r.filter(t=>"block"===t.kind));return c.setMeta(ce,{blocks:r.map(t=>"images"===t.kind?{from:t.from,to:t.to,images:t.images}:{from:t.from,to:t.to,padding:d[0]})}),t.dispatch(c),!0}function getSelectedBlocks(t){var e;return(null==(e=ce.getState(t.state))?void 0:e.blocks)??[]}function hasPartialImageSelection(t){var e;const n=t.state.selection;return n instanceof BlockRangeSelection&&!!(null==(e=n.parts)?void 0:e.some(t=>"images"===t.kind))}function replacePartialWithText(t,e){if(!hasPartialImageSelection(t))return!1;const n=t.state.selection,o=t.state.tr;n.replace(o);const a=t.state.schema,r=o.selection.from;if(o.selection.$from.parent.inlineContent)e&&o.insertText(e,r),o.setSelection(ht.create(o.doc,r+e.length));else{if(!a.nodes.paragraph)return!1;o.insert(r,a.nodes.paragraph.create(null,e?a.text(e):void 0)),o.setSelection(ht.create(o.doc,r+1+e.length))}return o.setMeta(ce,{blocks:[]}),t.dispatch(o.scrollIntoView()),!0}const de=ut.create({name:"ywikiBlockSelection",priority:1e3,addKeyboardShortcuts(){const remove=()=>{var t;const e=this.editor.view,n=e.state.selection;if(!(n instanceof BlockRangeSelection&&(null==(t=n.parts)?void 0:t.length)))return!1;const o=e.state.tr;return n.replace(o),!!o.docChanged&&(o.setMeta(ce,{blocks:[]}),e.dispatch(o.scrollIntoView()),!0)};return{Backspace:remove,Delete:remove,"Mod-Backspace":remove,"Mod-Delete":remove,"Shift-Backspace":remove,"Ctrl-h":remove,"Ctrl-d":remove,"Alt-Backspace":remove,"Alt-Delete":remove,"Ctrl-Alt-Backspace":remove,"Alt-d":remove}},addProseMirrorPlugins:()=>[new mt({key:ce,state:{init:()=>({blocks:[]}),apply:(t,e)=>t.getMeta(ce)||(t.selectionSet||t.docChanged?{blocks:[]}:e)},props:{handleTextInput:(t,e,n,o)=>replacePartialWithText(t,o),handleDOMEvents:{beforeinput(t,e){const n=e;return"insertText"===n.inputType&&null!==n.data&&!!hasPartialImageSelection(t)&&(n.preventDefault(),replacePartialWithText(t,n.data),!0)},compositionstart:t=>!!hasPartialImageSelection(t)&&(replacePartialWithText(t,""),!1)},decorations(t){var e;const n=ce.getState(t);if(!n||0===n.blocks.length)return null;const o=[];for(const t of n.blocks)if(null==(e=t.images)?void 0:e.length){o.push(Mt.node(t.from,t.to,{class:"is-block-image-selected"}));for(const e of t.images)o.push(Mt.node(e.from,e.to,{class:"is-block-selected-image"}))}else o.push(Mt.node(t.from,t.to,{class:"is-block-selected",style:t.padding?`--block-select-pad-top:${t.padding.top}px;--block-select-pad-bottom:${t.padding.bottom}px`:""}));return xt.create(t.doc,o)}},view:t=>{let e=null;const applyBlockSelection=n=>{null!==e&&setBlockRangeSelection(t,e,n,marqueeRect(s,c))};let n=!1,o=0,a=0;const r=t.dom.closest(".editor-shell")??t.dom.parentElement;let l=null;const updateMarquee=(e,n)=>{if(!r)return;l||(l=document.createElement("div"),l.className="block-marquee",r.appendChild(l));const i=r.getBoundingClientRect(),s=blockSelectionBand(t),c=blockSelectionBandRect(t)??i,d=function clampMarqueeBand(t,e,n,o,a=Number.POSITIVE_INFINITY){const r=Math.max(t,n),l=Math.min(e,o,a);return l>r?{left:r,right:l}:{left:n,right:Math.max(n,Math.min(o,a))}}(s.left,s.right,c.left,c.right,"undefined"!=typeof document?document.documentElement.clientWidth:void 0),clampX=t=>Math.max(d.left,Math.min(t,d.right)),clampY=t=>Math.max(i.top,Math.min(t,i.bottom)),u=function marqueeBox(t,e,n,o,a,r){return{left:Math.min(t,n)-a,top:Math.min(e,o)-r,width:Math.abs(n-t),height:Math.abs(o-e)}}(clampX(o),clampY(a),clampX(e),clampY(n),i.left,i.top);l.style.left=`${u.left}px`,l.style.top=`${u.top}px`,l.style.width=`${u.width}px`,l.style.height=`${u.height}px`},clearMarquee=()=>{null==l||l.remove(),l=null},marqueeRect=(t,e)=>({left:Math.min(o,t),top:Math.min(a,e),right:Math.max(o,t),bottom:Math.max(a,e)});let i=0,s=0,c=0,d=null,u=0;const stopAutoScroll=()=>{i&&cancelAnimationFrame(i),i=0,d=null,u=0},tickAutoScroll=(o=performance.now())=>{if(i=0,null===e||!n)return;const a=d;if(!a)return;const r=u?Math.min(o-u,50):16.7;u=o;const l=a.getBoundingClientRect(),m=autoScrollDelta(c,l.top,l.bottom);if(0===m)return void(u=0);const p=Math.round(m*r/16.7),f=a.scrollTop;if(a.scrollTop=f+(0===p?Math.sign(m):p),a.scrollTop===f)return;const h=blockAtY(t,c);h&&applyBlockSelection(h.pos),updateMarquee(s,c),i=requestAnimationFrame(tickAutoScroll)},onMouseMove=r=>{if(null===e)return;if(!n&&!function isBlockSelectGesture(t,e){return Math.max(Math.abs(t),Math.abs(e))>=8}(r.clientX-o,r.clientY-a))return;s=r.clientX,c=r.clientY,n||(n=!0,applyBlockSelection(e)),d??(d=function scrollParentOf(t){let e=(null==t?void 0:t.parentElement)??null;for(;e;){const t="function"==typeof getComputedStyle?getComputedStyle(e):null;if(/(auto|scroll)/.test((null==t?void 0:t.overflowY)??""))return e;e=e.parentElement}return null}(t.dom)),updateMarquee(r.clientX,r.clientY);const l=blockAtY(t,r.clientY);if(l&&applyBlockSelection(l.pos),d){const t=d.getBoundingClientRect();0!==autoScrollDelta(r.clientY,t.top,t.bottom)&&(i||(i=requestAnimationFrame(tickAutoScroll)))}r.preventDefault()},finish=o=>{const a="mouseup"===(null==o?void 0:o.type)&&!n&&null!==e,r=e;if(e=null,n=!1,t.dom.classList.remove("is-block-marquee-active"),stopAutoScroll(),clearMarquee(),window.removeEventListener("mousemove",onMouseMove),window.removeEventListener("mouseup",finish,!0),window.removeEventListener("blur",finish),window.removeEventListener("pointercancel",finish),window.removeEventListener("keydown",onKeydown,!0),a&&null!==r){const e=function gutterClickCaretPos(t,e){if(!Number.isInteger(e)||e<0||e>=t.content.size)return null;const n=t.nodeAt(e);return n?n.isTextblock?Math.min(e+1,t.content.size):e:null}(t.state.doc,r);if(null!==e){const n=t.state.tr.setSelection(ht.near(t.state.doc.resolve(e),1));n.setMeta(ce,{blocks:[]}),t.dispatch(n),t.focus()}}},onKeydown=e=>{"Escape"!==e.key||e.isComposing||(e.preventDefault(),finish(),t.isDestroyed||t.dispatch(t.state.tr.setSelection(ft.near(t.state.doc.resolve(t.state.selection.from)))))},onMouseDown=l=>{var i,s;if(0!==l.button||!t.editable||t.composing)return;const c=l.target,d=t.dom.closest(".edit-workspace")??r;if(!c||!d||!d.contains(c)&&!c.contains(d))return;if(null==(i=null==c?void 0:c.closest)?void 0:i.call(c,'button, input, textarea, select, a, img, video, audio, [contenteditable="false"], .math-node, .code-lang-menu, .block-grip, .block-plus, .block-chip, .insert-picker, .tbl-handle, .sel-toolbar, .tbl-menu, .tbl-ctx, .block-anchor, .slash-anchor'))return;if(null==(s=null==c?void 0:c.closest)?void 0:s.call(c,"table"))return;if(c.closest(".is-block-selected")&&t.dom.contains(c))return;const u=function gutterAreaHit(t,e){const n=t.dom.getBoundingClientRect();return e.clientY<n.top||e.clientY>n.bottom?null:function bandSide(t,e,n,o){return t>=e&&t<=n?null:t<e?t>=o.left?"left":null:t<=o.right?"right":null}(e.clientX,n.left,n.right,blockSelectionBand(t))?blockAtY(t,e.clientY):null}(t,l);u&&(l.preventDefault(),l.stopPropagation(),t.focus(),e=u.pos,o=l.clientX,a=l.clientY,n=!1,t.dom.classList.add("is-block-marquee-active"),window.addEventListener("mousemove",onMouseMove),window.addEventListener("mouseup",finish,!0),window.addEventListener("blur",finish),window.addEventListener("pointercancel",finish),window.addEventListener("keydown",onKeydown,!0))};document.addEventListener("mousedown",onMouseDown,!0);const onGlobalKeydown=e=>{if("Escape"!==e.key||e.isComposing)return;if(!getSelectedBlocks(t).length)return;e.preventDefault(),e.stopPropagation();const{state:n}=t,o=n.tr.setSelection(ft.near(n.doc.resolve(n.selection.from)));o.setMeta(ce,{blocks:[]}),t.dispatch(o),t.focus()};window.addEventListener("keydown",onGlobalKeydown,!0);const syncNativeHighlight=t=>{const e=ce.getState(t.state);t.dom.classList.toggle("is-block-selecting",function shouldSuppressNativeHighlight(t,e){return((null==t?void 0:t.length)??0)>0||e instanceof vt&&"videoEmbed"===e.node.type.name}(null==e?void 0:e.blocks,t.state.selection))};return syncNativeHighlight(t),{update:(t,n)=>{null===e||t.state.doc.eq(n.doc)||finish(),syncNativeHighlight(t)},destroy:()=>{document.removeEventListener("mousedown",onMouseDown,!0),window.removeEventListener("keydown",onGlobalKeydown,!0),stopAutoScroll(),clearMarquee(),t.dom.classList.remove("is-block-selecting"),finish()}}}})]}),ue=new pt("ywikiBlockMenuHighlight"),me=ut.create({name:"ywikiBlockMenuHighlight",addProseMirrorPlugins:()=>[new mt({key:ue,state:{init:()=>null,apply(t,e){const n=t.getMeta(ue);if(void 0!==n)return n;if(null===e||!t.docChanged)return e;const o=t.mapping.mapResult(e);return o.deleted?null:o.pos}},props:{decorations(t){const e=ue.getState(t);if(null==e)return null;const n=t.doc.nodeAt(e);return n?xt.create(t.doc,[Mt.node(e,e+n.nodeSize,{class:"is-block-menu-target"})]):null}}})]});function highlightMenuBlock(t,e){t.isDestroyed||ue.getState(t.state)===e||t.dispatch(t.state.tr.setMeta(ue,e))}const pe=new pt("ywikiCodeHighlight");function decorate(t){const e=[];return t.descendants((t,n)=>{if("codeBlock"===t.type.name){for(const o of Et(t.textContent,t.attrs.language))e.push(Mt.inline(n+1+o.from,n+1+o.to,{class:o.classes}));return!1}}),xt.create(t,e)}const fe=ut.create({name:"ywikiCodeHighlight",addProseMirrorPlugins:()=>[new mt({key:pe,state:{init:(t,e)=>decorate(e.doc),apply:(t,e)=>t.docChanged||t.getMeta(pe)?decorate(t.doc):e},props:{decorations:t=>pe.getState(t)},view(t){let e=!1,n=!1;const load=()=>{if(n)return;let o=!1;t.state.doc.descendants(t=>{"codeBlock"===t.type.name&&(o=!0)}),o&&(n=!0,Ct().then(n=>{n&&!e&&t.dispatch(t.state.tr.setMeta(pe,!0).setMeta("addToHistory",!1))}))};return load(),{update:load,destroy:()=>{e=!0}}}})]}),he={a:["href","title"],img:["src","alt","title","width","height","data-width","data-align","data-attachment-id"],td:["colspan","rowspan","colwidth","data-align","data-cell-background"],th:["colspan","rowspan","colwidth","data-align","data-cell-background"],code:["class"],pre:["class","data-language"],ol:["start","data-type"],ul:["data-type"],li:["data-type","data-checked"],div:["data-video-embed","data-provider","data-video-id","data-page","data-start-seconds","data-auto-load","data-topic-meta","data-branch-style","data-mind-map","data-map-id","data-root-id","data-format-version","data-layout","data-theme","data-height","data-mind-topic","data-topic-id","data-parent-id","data-order","data-file-attachment","data-attachment-id","attachmentid","filename","mimetype","size","data-math-block","data-latex","data-columns","data-column","data-callout","data-tone","data-callout-content","data-callout-icon","data-callout-textcolor","data-callout-bordercolor","data-callout-backgroundcolor"],span:["data-mind-description","data-mind-note","data-mind-relation","data-id","data-source","data-target","data-kind","data-label","data-page-link","data-page-id","pageid","label","data-mention","data-user-id","userid","data-math-inline","data-latex","data-text-color","data-color"],mark:["data-highlight","data-color"],p:["data-indent","data-text-align"],h1:["data-indent","data-text-align"],h2:["data-indent","data-text-align"],h3:["data-indent","data-text-align"],h4:["data-indent","data-text-align"],h5:["data-indent","data-text-align"],h6:["data-indent","data-text-align"]},ge=/* @__PURE__ */new Set(["style","script","meta","link","iframe","object","embed","form","input","button"]);function sanitizeElement(t){for(const e of Array.from(t.children)){if(e.hasAttribute("data-callout-decoration")){e.remove();continue}if(ge.has(e.tagName.toLowerCase())){e.remove();continue}e.removeAttribute("style");const t=/(?:^|\s)(language-[\w+#-]+)/.exec(e.className);e.removeAttribute("class"),["code","pre"].includes(e.tagName.toLowerCase())&&t&&e.setAttribute("class",t[1]),e.removeAttribute("id");for(const t of Array.from(e.attributes)){const n=t.name.toLowerCase();if(n.startsWith("on")){e.removeAttribute(t.name);continue}const o=he[e.tagName.toLowerCase()];o&&o.includes(n)||e.removeAttribute(t.name)}if("a"===e.tagName.toLowerCase()){const t=(e.getAttribute("href")??"").trim().toLowerCase();(t.startsWith("javascript:")||t.startsWith("data:")||t.startsWith("vbscript:"))&&e.removeAttribute("href")}sanitizeElement(e)}}const ve=ut.create({name:"ywikiPasteSanitizer",addProseMirrorPlugins:()=>[new mt({props:{transformPastedHTML(t){const e=document.createElement("div");return e.innerHTML=t,sanitizeElement(e),e.innerHTML}}})]});function pastedImageFiles(t){var e;const n=null==(e=t.clipboardData)?void 0:e.items;if(!n)return[];const o=[];for(const t of Array.from(n))if("file"===t.kind&&t.type.startsWith("image/")){const e=t.getAsFile();e&&o.push(e)}return o}function pastedRemoteImageUrls(t){var e;const n=(null==(e=t.clipboardData)?void 0:e.getData("text/html"))??"";if(!n)return[];const o=document.createElement("div");o.innerHTML=n;const a=/* @__PURE__ */new Set;for(const t of Array.from(o.querySelectorAll("img"))){const e=(t.getAttribute("src")??"").trim();/^https?:\/\//i.test(e)&&a.add(e)}return[...a]}const be=new pt("ywikiInlineComments"),ye=ut.create({name:"ywikiInlineCommentHighlight",addProseMirrorPlugins(){const t=this.options;return[new mt({key:be,state:{init:()=>({comments:t.getComments()}),apply:(t,e)=>t.getMeta(be)??e},props:{decorations(e){var n;const o=be.getState(e);return o&&0!==o.comments.length?function buildDecorations(t,e,n){const{marks:o}=At(t.toJSON(),e);if(0===o.length)return xt.empty;const a=function textNodePositions(t){const e=[];return t.descendants((t,n)=>{var o;t.isText&&((null==(o=t.text)?void 0:o.length)??0)>0&&e.push(n)}),e}(t),r=[];for(const t of o){const e=a[t.textIndex];if(void 0===e)continue;const o=e+t.from,l=e+t.to;if(l<=o){r.push(Mt.widget(o,()=>{const e=document.createElement("span");return e.className="doc-inline-comment is-editor is-shifted",e.setAttribute("data-comment-id",t.commentId),e.setAttribute("data-comment-hint","此处有讨论(原文已改动)"),e}));continue}const i=["doc-inline-comment","is-editor"];t.hasReplies&&i.push("has-replies"),n===t.commentId&&i.push("is-active"),r.push(Mt.inline(o,l,{class:i.join(" "),"data-comment-id":t.commentId,"data-comment-hint":"点击查看该处讨论"}))}return xt.create(t,r)}(e.doc,o.comments,(null==(n=t.getActiveId)?void 0:n.call(t))??null):null},handleClick(e,n,o){var a;const r=o.target,l=null==r?void 0:r.closest("[data-comment-id]"),i=null==l?void 0:l.getAttribute("data-comment-id");return!!i&&(at(),null==(a=t.onMarkClick)||a.call(t,i),!0)},handleDOMEvents:{mouseover(t,e){const n=e.target,o=null==n?void 0:n.closest("[data-comment-hint]");if(!(o instanceof HTMLElement))return!1;const a=o.getAttribute("data-comment-hint");return a&&ot(o,a),!1},mouseout(t,e){const n=e,o=n.target,a=null==o?void 0:o.closest("[data-comment-hint]");if(!a)return!1;const r=n.relatedTarget;return r&&a.contains(r)||at(),!1}}}})]}});function refreshInlineComments(t,e){const n=t.state.tr.setMeta(be,{comments:e});t.view.dispatch(n)}new pt("ywiki-collab-cursor");const we=ut.create({name:"collabCursor",addOptions:()=>({awareness:null}),addProseMirrorPlugins(){return this.options.awareness?[_(this.options.awareness,{cursorBuilder:t=>function buildCursor(t){const e=t.color||"#2f6feb",n=t.name||"匿名",o=document.createElement("span");o.classList.add("ProseMirror-yjs-cursor"),o.style.setProperty("--yjs-cursor-color",e);const a=document.createElement("span");a.classList.add("ywiki-collab-caret"),a.style.backgroundColor=e;const r=document.createElement("span");return r.classList.add("ywiki-collab-caret-label"),r.style.backgroundColor=e,r.style.color=Lt(e),r.textContent=n,o.appendChild(a),o.appendChild(r),o}(t)})]:[]}}),ke=new pt("ywiki-slash");function dismissSlash(t){const{$from:e}=t.state.selection,n=e.parent.textBetween(0,e.parentOffset).lastIndexOf("/");t.dispatch(t.state.tr.setMeta(ke,{dismissedFrom:n>=0?e.start()+n:null}))}const Me=ut.create({name:"ywikiSlashCommand",addOptions:()=>({onOpen:()=>{},onUpdate:()=>{},onClose:()=>{}}),addProseMirrorPlugins(){const t=this.options;return[new mt({key:ke,state:{init:()=>({dismissedFrom:null}),apply:(t,e)=>{const n=t.getMeta(ke);if(n)return n;if(null===e.dismissedFrom)return e;const o=t.mapping.mapResult(e.dismissedFrom,1);return{dismissedFrom:o.deleted?null:o.pos}}},view:()=>{let e=null;return{update:(n,o)=>{var a;if(kt({isComposing:!1}))return;if(n.state.doc.eq(o.doc)&&n.state.selection.eq(o.selection)&&ke.getState(n.state)===ke.getState(o))return;const{$from:r,empty:l}=n.state.selection;if(!n.editable||n.composing||!l||r.parent.type.spec.code)return void(null!==e&&(e=null,t.onClose()));const i=r.parent.textBetween(0,r.parentOffset,void 0,""),s=i.lastIndexOf("/");if(s>=0&&(0===s||/\s/.test(i[s-1]))){const o=r.start()+s,l=i.slice(s+1);if((null==(a=ke.getState(n.state))?void 0:a.dismissedFrom)===o)return null!==e&&t.onClose(),void(e=null);if(/\s/.test(l))return void(null!==e&&(e=null,t.onClose()));e!==o?(e=o,t.onOpen({from:o,query:l})):t.onUpdate(l)}else null!==e&&(e=null,t.onClose())},destroy:()=>{null!==e&&(e=null,t.onClose())}}},props:{handleKeyDown:(t,e)=>(kt(e),!1)}})]}}),xe=new pt("ywiki-block-handle"),Ce=ut.create({name:"ywikiBlockHandle",addOptions:()=>({onHover:()=>{}}),addProseMirrorPlugins(){const t=this.options;return[new mt({key:xe,view:e=>{let n=null,o=Number.NaN;const a=e.dom.closest(".editor-shell")??e.dom.parentElement,report=e=>{e?(e.pos!==n||Math.abs(e.top-o)>.5)&&(n=e.pos,o=e.top,t.onHover(e)):null!==n&&(n=null,o=Number.NaN,t.onHover(null))},onMove=t=>{if(!e.editable)return void report(null);if(!a)return;const n=e.dom.getBoundingClientRect(),o=t.clientX>=n.left&&t.clientX<=n.right,r=t.clientX<n.left&&t.clientX>=n.left-64,l=t.clientY>=n.top-8&&t.clientY<=n.bottom+8;if(!o&&!r||!l)return void report(null);let i=null;try{i=function resolveTopLevelBlock(t,e,n){const o=t.dom;let a=null,r=null,l=null,i=e.target instanceof HTMLElement?e.target:null;for(;i&&i.parentElement&&i.parentElement!==o;)i=i.parentElement;if(i&&i.parentElement===o)try{const e=t.posAtDOM(i,0),n=t.state.doc.resolve(e),o=n.depth>0?n.before(1):e,s=t.state.doc.nodeAt(o);s&&(a=o,r=s,l=i)}catch{}if(null===a||!r){const n=t.posAtCoords({left:e.clientX,top:e.clientY});if(!n)return null;const o=n.pos;if("number"!=typeof o||o<0)return null;const l=Math.min(o,t.state.doc.content.size);if(t.state.doc.forEach((t,e)=>{null===a&&l>=e&&l<e+t.nodeSize&&(a=e,r=t)}),null===a&&t.state.doc.childCount>0){const e=t.state.doc.lastChild;a=t.state.doc.content.size-e.nodeSize,r=e}if(null===a||!r)return null}const s=n.getBoundingClientRect();let c=e.clientY,d=o.getBoundingClientRect().left-s.left;try{const e=l??t.nodeDOM(a);if(e instanceof HTMLElement){const t=e.getBoundingClientRect();let n=t.top,o=t.height;try{const t=document.createRange();t.selectNodeContents(e);const a=Array.from(t.getClientRects()).filter(t=>t.height>.5);a.length>0&&(n=a[0].top,o=a[0].height)}catch{}c=n+o/2-13-s.top}}catch{c=e.clientY-s.top}return{pos:a,type:r.type.name,top:c,contentLeft:d,isEmpty:(u=r.type.name,m=r.content.size,0===m&&("paragraph"===u||"heading"===u))};var u,m}(e,t,a)}catch{i=null}r&&!i||report(i)},onLeave=()=>{report(null)};return document.addEventListener("mousemove",onMove),document.addEventListener("mouseleave",onLeave),{destroy:()=>{document.removeEventListener("mousemove",onMove),document.removeEventListener("mouseleave",onLeave)}}}})]}});function insertUploadedBlock(t,e,n){const o=t.doc.resolve(e);if(n.isBlock&&o.depth>0&&"paragraph"===o.parent.type.name&&0===o.parent.content.size){const e=o.before(),a=o.after();return t.replaceWith(e,a,n),{replacedEmpty:!0,nextPos:e+n.nodeSize}}return t.insert(e,n),{replacedEmpty:!1,nextPos:t.mapping.map(e,1)}}const Ee=new pt("ywikiUploadPlaceholder");function anchorAt(t,e){const n=Math.max(0,Math.min(e,t.content.size));let o=-1,a=0;if(t.forEach((t,e,r)=>{o>=0||n>=e&&n<e+t.nodeSize&&(o=r,a=e)}),o<0&&t.childCount>0&&(o=t.childCount-1,a=t.content.size-t.child(t.childCount-1).nodeSize),o<0)return{pos:n,blockIndex:0,offset:0,blockText:"",blockCount:t.childCount,blockJSON:"",relative:0};const r=t.child(o);return{pos:n,blockIndex:o,offset:Math.max(0,n-(a+1)),blockText:r.textContent,blockCount:t.childCount,blockJSON:JSON.stringify(r.toJSON()),relative:n-a}}function resolveAnchor(t,e){if(0===t.childCount)return null;const n=[];if(t.forEach((t,o,a)=>{JSON.stringify(t.toJSON())===e.blockJSON&&n.push(a)}),1!==n.length)return null;const o=function blockStartAt(t,e){let n=0;for(let o=0;o<e&&o<t.childCount;o+=1)n+=t.child(o).nodeSize;return n}(t,n[0]),a=t.child(n[0]);return o+Math.max(0,Math.min(e.relative,a.nodeSize))}const Ae=/* @__PURE__ */new Set;function releasePreview(t){t&&Ae.delete(t)&&"function"==typeof URL.revokeObjectURL&&URL.revokeObjectURL(t)}const Le=ut.create({name:"ywikiUploadPlaceholder",addOptions:()=>({onLost:()=>{},onCancel:()=>{}}),addProseMirrorPlugins(){const t=this.options,e=this.editor;return[new mt({key:Ee,state:{init:()=>({items:[]}),apply:(e,n)=>{var o;const a=e.getMeta(Ee);if(null==a?void 0:a.clear){for(const t of n.items)releasePreview(t.previewUrl);return{items:[]}}const r=/* @__PURE__ */new Set([...(null==a?void 0:a.remove)?[a.remove]:[],...(null==a?void 0:a.removeMany)??[]]),l=0===r.size?n.items:n.items.filter(t=>!r.has(t.id));if(r.size>0)for(const t of n.items)r.has(t.id)&&releasePreview(t.previewUrl);const i=(null==a?void 0:a.reanchor)?l.filter(t=>t.anchor.pos===a.reanchor.from).map(t=>({...t,anchor:anchorAt(e.doc,a.reanchor.to)})):[],s=l.filter(t=>!(null==a?void 0:a.reanchor)||t.anchor.pos!==a.reanchor.from),c=e.docChanged?function advancePlaceholders(t,e,n,o=!1){const a=[],r=[];for(const l of e){const e=n.mapResult(l.anchor.pos,1);if(!e.deleted){a.push({...l,anchor:anchorAt(t,e.pos)});continue}const i=o?resolveAnchor(t,l.anchor):null;null!==i?a.push({...l,anchor:anchorAt(t,i)}):r.push(l.id)}return{items:a,lost:r}}(e.doc,s,e.mapping,!!e.getMeta("y-sync$")):{items:s,lost:[]};c.items.push(...i);for(const e of c.lost){const a=n.items.find(t=>t.id===e);releasePreview(null==a?void 0:a.previewUrl),null==(o=t.onLost)||o.call(t,e)}return a&&a.add?{items:[...c.items,a.add]}:{items:c.items}}},view:()=>({destroy:()=>function releaseAllPreviews(){for(const t of[...Ae])releasePreview(t)}()}),props:{decorations(n){const o=Ee.getState(n);return o&&0!==o.items.length?xt.create(n.doc,o.items.map(n=>{const o=y(e),a=Mt.widget(n.anchor.pos,()=>function placeholderDom(t,e,n){const o=document.createElement("span");o.className="ywiki-upload-placeholder",o.setAttribute("data-upload-id",t.id);const a=document.createElement("span");a.className="ywiki-upload-spinner",a.setAttribute("aria-hidden","true");const r=document.createElement("span");r.className="ywiki-upload-label",r.textContent=n.t("image"===t.kind?"upload.image":"upload.file",{0:t.label});const l=document.createElement("button");if(l.type="button",l.className="ywiki-upload-cancel",l.title=n.t("upload.cancel"),l.setAttribute("aria-label",n.t("upload.cancel")),l.textContent="×",l.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation()}),l.addEventListener("click",n=>{var o;n.preventDefault(),n.stopPropagation(),null==(o=e.onCancel)||o.call(e,t.id)}),t.previewUrl){o.classList.add("has-preview");const e=document.createElement("img");return e.className="ywiki-upload-preview",e.setAttribute("alt",""),e.setAttribute("aria-hidden","true"),e.setAttribute("draggable","false"),e.src=t.previewUrl,o.title=t.label,o.append(e,a,l),o}return o.append(a,r,l),o}(n,t,o),{key:`${n.id}:${o.version}`,side:1});return a})):null}}})]}});function addUploadPlaceholder(t,e){const n=anchorAt(t.state.doc,e.pos),o=function createPreview(t,e){if(t&&"image"===e&&"function"==typeof URL.createObjectURL)try{const e=URL.createObjectURL(t);return Ae.add(e),e}catch{return}}(e.file,e.kind);t.dispatch(t.state.tr.setMeta(Ee,{add:{id:e.id,label:e.label,kind:e.kind,anchor:n,...o?{previewUrl:o}:{}}}))}function removeUploadPlaceholder(t,e){const n=Ee.getState(t.state);(null==n?void 0:n.items.some(t=>t.id===e))&&t.dispatch(t.state.tr.setMeta(Ee,{remove:e}))}function replacePlaceholderWithNode(t,e,n){const o=currentPlaceholderPos(t,e);if(null===o||!t.editable||t.isDestroyed)return!1;const a=t.state.schema.nodes[n.type];if(!a)return!1;const r=a.create(n.attrs??null),l=t.state.tr;let i;try{const t=insertUploadedBlock(l,o,r);t.replacedEmpty&&(i={from:o,to:t.nextPos})}catch{return l.setMeta(Ee,{remove:e}),t.dispatch(l),!1}return l.setMeta(Ee,{remove:e,reanchor:i}),t.dispatch(l),!0}function currentPlaceholderPos(t,e){const n=Ee.getState(t.state),o=null==n?void 0:n.items.find(t=>t.id===e);return o?o.anchor.pos:null}function selectTableCell(t,e){var n,o;if(e<0||e>=t.state.doc.content.size||!["cell","header_cell"].includes((null==(n=t.state.doc.nodeAt(e))?void 0:n.type.spec.tableRole)??""))return;const a=t.state.selection;let r=!1;null==(o=a.forEachCell)||o.call(a,(t,n)=>{n===e&&(r=!0)}),r||t.dispatch(t.state.tr.setSelection(ft.near(t.state.doc.resolve(e+1))))}function cellPositionAtDOM(t,e){try{const n=t.state.doc.resolve(t.posAtDOM(e,0));for(let t=n.depth;t>0;t-=1)if(["cell","header_cell"].includes(n.node(t).type.spec.tableRole??""))return n.before(t)}catch{}return null}function selectTableAxis(t,e,n,o){if(!t.editable)return!1;try{const a=t.state.doc.resolve(e),r=a.node(-1);if("table"!==r.type.spec.tableRole)return!1;const l=a.start(-1),i=Nt.get(r),s=i.findCell(e-l);if(void 0!==o){const t="row"===n?i.height:i.width;if(!Number.isInteger(o)||o<0||o>=t)return!1;"row"===n&&(s.top=o,s.bottom=o+1),"column"===n&&(s.left=o,s.right=o+1)}const c="row"===n?s.top*i.width:"column"===n?s.left:0,d="row"===n?(s.bottom-1)*i.width+i.width-1:"column"===n?(i.height-1)*i.width+s.right-1:i.map.length-1,u=St.create(t.state.doc,l+i.map[c],l+i.map[d]);return t.dispatch(t.state.tr.setSelection(u)),t.focus(),!0}catch{return!1}}function tablePositionAtCell(t,e){try{const n=t.state.doc.resolve(e);return"table"===n.node(-1).type.spec.tableRole?n.before(-1):null}catch{return null}}function currentTableCellPosition(t){const e=t.state.selection;if(e instanceof St)return e.$anchorCell.pos;for(let t=e.$from.depth;t>0;t-=1)if(["cell","header_cell"].includes(e.$from.node(t).type.spec.tableRole??""))return e.$from.before(t);return null}function insertTableBoundary(t,e,n,o){if(!t.isEditable)return!1;const a=tablePositionAtCell(t.view,e);if(null===a)return!1;const r=t.state.doc.nodeAt(a),l=Nt.get(r),i="row"===n?l.height:l.width;if(!Number.isInteger(o)||o<0||o>i)return!1;const s={map:l,table:r,tableStart:a+1,left:0,top:0,right:l.width,bottom:l.height},c=t.state.tr.setSelection(ft.near(t.state.doc.resolve(e+1)));return"row"===n?Tt(c,s,o):Pt(c,s,o),t.view.dispatch(c),t.view.focus(),!0}function tableSelectionMarkActive(t,e){const n=t.state.schema.marks[e],o=t.state.selection;if(!(n&&o instanceof St))return!1;let a=!1,r=!0;return o.forEachCell(t=>t.descendants(t=>{t.isText&&(a=!0,n.isInSet(t.marks)||(r=!1))})),a&&r}function setTableSelectionMark(t,e,n){const o=t.state.schema.marks[e],a=t.state.selection;if(!(t.isEditable&&o&&a instanceof St))return!1;const r=t.state.tr;return a.forEachCell((t,e)=>{const a=e+1,l=e+t.nodeSize-1;null===n?r.removeMark(a,l,o):r.addMark(a,l,o.create(n))}),!!r.docChanged&&(t.view.dispatch(r),!0)}function findTable(t){const{$from:e}=t.state.selection;for(let t=e.depth;t>0;t-=1){const n=e.node(t);if("table"===n.type.spec.tableRole)return{node:n,pos:e.before(t)}}return null}function tableHeaderActive(t,e){const n=findTable(t);if(!n)return!1;const o=Nt.get(n.node),a=o.cellsInRect({left:0,top:0,right:"row"===e?o.width:1,bottom:"column"===e?o.height:1});return a.length>0&&a.every(t=>{var e;return"header_cell"===(null==(e=n.node.nodeAt(t))?void 0:e.type.spec.tableRole)})}function distributeTableColumns(t,e){const n=findTable(t);if(!t.isEditable||!n||!Number.isFinite(e)||e<=0)return!1;const o=Nt.get(n.node),a=Math.max(It,Math.min(2e3,Math.floor(e/o.width))),r=t.state.tr;for(const e of new Set(o.map)){const o=n.pos+1+e,l=t.state.doc.nodeAt(o);r.setNodeMarkup(o,void 0,{...l.attrs,colwidth:Array(Number(l.attrs.colspan)).fill(a)})}return t.view.dispatch(r),!0}function setTableHeaderBackground(t,e){const n=findTable(t),o=Object.values(t.state.schema.nodes).find(t=>"header_cell"===t.spec.tableRole);if(!t.isEditable||!n||!o||null!==e&&!Ht.some(t=>t.value===e))return!1;const a=Nt.get(n.node),r=t.state.tr;for(const l of new Set(a.map.slice(0,a.width))){const a=n.pos+1+l,i=t.state.doc.nodeAt(a);r.setNodeMarkup(a,o,{...i.attrs,backgroundColor:e})}return t.view.dispatch(r),!0}function currentCellRect(t){try{const e=Bt(t.state);return{row:e.top,col:e.left}}catch{return null}}function setColumnWidth(t,e,n){const o=findTable(t);if(!o)return!1;const a=Nt.get(o.node);if(e<0||e>=a.width)return!1;const{state:r,view:l}=t;if(!t.isEditable||!Number.isFinite(n)||n<40||n>2e3)return!1;const i=r.tr,s=/* @__PURE__ */new Set;let c=0;for(let t=0;t<a.height;t+=1){const l=a.map[t*a.width+e];if(s.has(l))continue;s.add(l);const d=o.pos+1+l,u=r.doc.nodeAt(d);if(!u)continue;const m=[...u.attrs.colwidth??Array(Number(u.attrs.colspan??1)).fill(0)];m[e-a.findCell(l).left]=n,i.setNodeMarkup(d,void 0,{...u.attrs,colwidth:m}),c+=1}return c>0&&l.dispatch(i),c>0}function autoFitColumn(t,e){var n;const o=findTable(t);if(!o)return!1;const a=Nt.get(o.node);if(e<0||e>=a.width)return!1;const{state:r,view:l}=t;if(!t.isEditable)return!1;const i=r.tr,s=/* @__PURE__ */new Set;let c=0;for(let t=0;t<a.height;t+=1){const l=a.map[t*a.width+e];if(s.has(l))continue;s.add(l);const d=o.pos+1+l,u=r.doc.nodeAt(d);if(!u)continue;if(null==(null==(n=u.attrs)?void 0:n.colwidth))continue;const m=[...u.attrs.colwidth];m[e-a.findCell(l).left]=0,i.setNodeMarkup(d,void 0,{...u.attrs,colwidth:m.some(t=>t>0)?m:null}),c+=1}return c>0&&l.dispatch(i),c>0}function readTableGeometry(t,e,n){var o,a,r;try{const l=t.state.doc.resolve(e),i=l.node(-1);if("table"!==i.type.spec.tableRole)return null;const s=l.start(-1),c=Nt.get(i),d=t.nodeDOM(e);if(!(d instanceof HTMLElement))return null;const u=d.closest("table"),m=t.dom.closest(".editor-shell");if(!u||!m)return null;const p=m.getBoundingClientRect(),f=u.getBoundingClientRect(),h=(u.closest(".tableWrapper")??u).getBoundingClientRect(),g=Math.max(f.left,h.left),v=Math.min(f.right,h.right);if(v<=g)return null;const b=Array.from(u.rows).map((t,e)=>{const n=t.getBoundingClientRect();return{index:e,cellPos:s+c.map[e*c.width],start:n.top-p.top,size:n.height}});let y=Array.from(u.querySelectorAll(":scope > colgroup > col")).map(t=>t.getBoundingClientRect());if(y.length!==c.width||y.some(t=>!Number.isFinite(t.width)||t.width<=0)){const e=[];for(const n of new Set(c.map)){const a=t.nodeDOM(s+n);if(!(a instanceof HTMLElement))continue;const r=a.getBoundingClientRect(),l=c.findCell(n),d=null==(o=i.nodeAt(n))?void 0:o.attrs.colwidth;e.push({from:l.left,to:l.right,left:r.left,right:r.right,widths:Array.isArray(d)?d:void 0})}const n=function columnBoundsFromCells(t,e){var n,o,a;const r=Array(e+1).fill(void 0),l=Array(e).fill(void 0);for(const i of t)i.from<0||i.to>e||i.from>=i.to||!Number.isFinite(i.left)||!Number.isFinite(i.right)||i.right<=i.left||(r[n=i.from]??(r[n]=i.left),r[o=i.to]??(r[o]=i.right),null==(a=i.widths)||a.forEach((t,e)=>{var n;i.from+e<i.to&&Number.isFinite(t)&&t>0&&(l[n=i.from+e]??(l[n]=t))}));if(null==r[0]||null==r[e])return null;let i=0;for(;i<e;){let t=i+1;for(;t<=e&&null==r[t];)t+=1;if(t>e||r[t]<=r[i])return null;const n=Array.from({length:t-i},(t,e)=>l[i+e]??1),o=n.reduce((t,e)=>t+e,0),a=r[i],s=r[t]-a;let c=0;for(let e=i+1;e<t;e++)c+=n[e-i-1],r[e]=a+s*c/o;i=t}return Array.from({length:e},(t,e)=>({left:r[e],width:r[e+1]-r[e]}))}(e,c.width);if(!n)return null;y=n}const w=y.map((t,e)=>({index:e,cellPos:s+c.map[e],start:t.left-p.left,size:t.width}));if(b.length!==c.height||w.length!==c.width)return null;const k=c.findCell(e-s),M=n?(null==(a=b.find(t=>n.y>=t.start+p.top&&n.y<t.start+p.top+t.size))?void 0:a.index)??k.top:k.top,x=n?(null==(r=w.find(t=>n.x>=t.start+p.left&&n.x<t.start+p.left+t.size))?void 0:r.index)??k.left:k.left;return{cellPos:e,rowIndex:M,colIndex:x,rowTop:b[M].start,rowHeight:b[M].size,colLeft:w[x].start,colWidth:w[x].size,tableWidth:v-g,tableHeight:f.height,tableTop:f.top-p.top,tableLeft:g-p.left,contentLeft:t.dom.getBoundingClientRect().left-p.left,rows:b,columns:w}}catch{return null}}function clippedTableSelection(t,e){if(!t.length)return null;const n=Math.max(e.left,Math.min(...t.map(t=>t.left))),o=Math.min(e.right,Math.max(...t.map(t=>t.right))),a=Math.min(...t.map(t=>t.top)),r=Math.max(...t.map(t=>t.bottom));return o>n&&r>a?{left:n,right:o,top:a,bottom:r}:null}const Se=new pt("ywiki-table-interaction"),Ne=ut.create({name:"ywikiTableInteraction",addOptions:()=>({onHover:()=>{}}),addProseMirrorPlugins(){const t=this.options;return[new mt({key:Se,view:e=>{const n=e.dom.closest(".editor-shell")??e.dom;let o,a=null,r="",l=0;const clear=()=>{a=null,o=void 0,r&&t.onHover(null),r=""},schedule=()=>{l||(l=requestAnimationFrame(()=>{l=0,(()=>{if(!(null==a?void 0:a.isConnected)||!e.editable)return void clear();const n=cellPositionAtDOM(e,a),l=null===n?null:readTableGeometry(e,n,o);if(!l)return void clear();const i=JSON.stringify(l);i!==r&&(r=i,t.onHover(l))})()}))},move=t=>{var n;const r=t,l=r.target instanceof Element?r.target:null;if(null==l?void 0:l.closest(".tbl-ui-host"))return;const i=null==l?void 0:l.closest("td,th");if(i&&e.dom.contains(i))return a=i,o={x:r.clientX,y:r.clientY},void schedule();const s=null==(n=null==a?void 0:a.closest("table"))?void 0:n.getBoundingClientRect();s&&r.clientX>=s.left-64&&r.clientX<=s.right+24&&r.clientY>=s.top-32&&r.clientY<=s.bottom+24||clear()};n.addEventListener("mousemove",move),n.addEventListener("mouseleave",clear),window.addEventListener("scroll",schedule,!0),window.addEventListener("resize",schedule);const i=new ResizeObserver(schedule);return i.observe(e.dom),{update:schedule,destroy:()=>{cancelAnimationFrame(l),i.disconnect(),n.removeEventListener("mousemove",move),n.removeEventListener("mouseleave",clear),window.removeEventListener("scroll",schedule,!0),window.removeEventListener("resize",schedule)}}}})]}}),Te="default";function coreExtensions(t={}){const E=[...t.i18n?[h(t.i18n)]:[],e.configure({heading:{levels:[1,2,3,4,5,6]},undoRedo:!t.collabDoc&&{},link:!1,codeBlock:!1,trailingNode:!1,dropcursor:!1}),ae.configure({canCopy:()=>{var e;return(null==(e=t.canCopyCode)?void 0:e.call(t))??!1},contentContext:t.contentContext}),fe,n.configure({openOnClick:!1,protocols:["http","https","mailto"],HTMLAttributes:{rel:"noopener noreferrer nofollow"}}),Yt.configure({inline:!1,allowBase64:!1}).extend({addNodeView:()=>createImageNodeView(t.attachmentFetcher,t.attachmentScope,t.attachmentPortal)}),Ut.extend({addNodeView:()=>((t=w,e)=>({node:n,editor:o})=>{var a,r,l;const i=y(o),s=i.text,c=document.createElement("div");c.className="doc-file-attachment",c.setAttribute("data-file-attachment","true"),c.setAttribute("data-block-chrome",""),c.setAttribute("contenteditable","false");let d,u=String((null==(a=n.attrs)?void 0:a.attachmentId)??""),m=String((null==(r=n.attrs)?void 0:r.mimeType)??""),p=String((null==(l=n.attrs)?void 0:l.filename)??s("附件")),f=null;const h=document.createElement("div");h.className="doc-file-head";const g=document.createElement("span");g.className="doc-file-icon";const v=document.createElement("span");v.className="doc-file-name";const b=document.createElement("span");b.className="doc-file-size";const w=document.createElement("button");w.type="button",w.className="doc-file-action",w.textContent=s("下载"),w.addEventListener("click",async e=>{if(e.preventDefault(),e.stopPropagation(),!u||w.disabled)return;const n=u;w.disabled=!0;try{await M(n,p,t),n===u&&(w.textContent=s("下载"))}catch{n===u&&(w.textContent=s("下载失败,重试"))}finally{n===u&&(w.disabled=!1)}}),h.append(g,v,b,w),c.append(h);let C=null;function render(){var o;c.setAttribute("data-attachment-id",u),g.textContent=m.startsWith("video/")?"▶":m.startsWith("image/")?"🖼":"📎",v.textContent=p,v.title=p;const a=Number((null==(o=n.attrs)?void 0:o.size)??0);if(b.textContent=a>0?x(a):"",w.disabled=!u,w.textContent=s("下载"),null==C||C.remove(),C=null,null==d||d(),null==f||f(),f=null,!u)return;if(m.startsWith("video/")){const t=document.createElement("video");t.className="doc-file-video",t.controls=!0,t.preload="metadata",C=t,c.append(t)}else{if(!m.startsWith("image/"))return;{const t=document.createElement("img");t.className="doc-file-image",t.alt=p,C=t,c.append(t)}}const r=u;f=S(c,()=>{null==d||d(),d=k(r,t=>{r===u&&C&&C.setAttribute("src",t)},t,void 0,e)})}render();const E=i.subscribe(()=>{w.textContent=s("下载")});return{dom:c,update:t=>{var e,o,a,r;if("fileAttachment"!==t.type.name)return!1;n=t;const l=Number((null==(e=t.attrs)?void 0:e.size)??0);b.textContent=l>0?x(l):"";const i=String((null==(o=t.attrs)?void 0:o.attachmentId)??""),c=String((null==(a=t.attrs)?void 0:a.mimeType)??""),d=String((null==(r=t.attrs)?void 0:r.filename)??s("附件"));return i===u&&c===m&&d===p||(u=i,m=c,p=d,render()),!0},destroy:()=>{E(),u="",C=null,null==d||d(),null==f||f(),f=null},stopEvent:t=>{var e,n;return!!(null==(n=null==(e=t.target)?void 0:e.closest)?void 0:n.call(e,"video, audio, button"))}}})(t.attachmentFetcher,t.attachmentScope)}),Xt,a.configure({resizable:!0,cellMinWidth:120,allowTableNodeSelection:!0}),r,Qt,Zt,l,i.configure({nested:!0}),Ft,Wt,Gt,Jt,jt.extend({addNodeView:()=>mathNodeView}),qt.extend({addNodeView:()=>mathNodeView}),g.configure({renderer:t.videoRenderer}),v.configure({renderer:t.mindMapRenderer}),b.configure({renderer:(A=t.contentContext,({node:t,editor:e,getPos:n})=>{const o=document.createElement("div"),a=document.createElement("div");a.className="callout-controls-host",a.contentEditable="false";const r=document.createElement("div");r.className="doc-callout-content",r.dataset.calloutContent="true",o.append(a,r);const l=function createPortalResolver(t,e){let n=null;return{resolve:()=>{var o;const a=null==e?void 0:e().portal;if(null==a?void 0:a.isConnected)return a;if(!t.isConnected)return null;if(null==n?void 0:n.isConnected)return n;const r=document.createElement("div");r.className="wendang-portal wendang",r.dataset.wendangPortal="";const l=null==(o=t.closest("[data-wendang-theme]"))?void 0:o.getAttribute("data-wendang-theme");return l&&(r.dataset.wendangTheme=l),document.body.append(r),n=r,r},destroy(){null==n||n.remove(),n=null}}}(o,A);let i=t,s=F(a),c=e.isEditable;const position=()=>{var t;const o=n();return"number"==typeof o&&"callout"===(null==(t=e.state.doc.nodeAt(o))?void 0:t.type.name)?o:null},paint=()=>{const t=W(i.attrs);o.classList.add("doc-callout");for(const t of Object.keys(o.dataset))(t.startsWith("callout")||"tone"===t||"iconHidden"===t)&&delete o.dataset[t];for(const[e,n]of Object.entries(t))o.setAttribute(e,n);const n=/* @__PURE__ */D(CalloutControls,{attrs:i.attrs,editable:e.isEditable,portal:l.resolve,onPatch:t=>{const n=position();null!==n&&function patchCallout(t,e,n){if(!t.isEditable||t.isDestroyed)return!1;const o=t.state.doc.nodeAt(e);"callout"!==(null==o?void 0:o.type.name)||!K({...o.attrs,...n})||dispatch(t,t.state.tr.setNodeMarkup(e,void 0,{...o.attrs,...n}))}(e,n,t)},onUnwrap:()=>{const t=position();null!==t&&unwrapCallout(e,t)}}),a=null==A?void 0:A();null==s||s.render(a?/* @__PURE__ */D(C,{value:a,children:n}):n)};paint();const syncEditable=({transaction:t})=>{(e.isEditable!==c||t.getMeta("content-context"))&&(c=e.isEditable,paint())};return e.on("transaction",syncEditable),{dom:o,contentDOM:r,update:t=>"callout"===t.type.name&&(i=t,paint(),!0),stopEvent:t=>a.contains(t.target),ignoreMutation:t=>"selection"!==t.type&&!r.contains(t.target),destroy(){l.destroy(),e.off("transaction",syncEditable);const t=s;s=null,queueMicrotask(()=>null==t?void 0:t.unmount())}}})}),c,d,u,m,p,f,se,de,me,le,ve];var A;return t.placeholder&&E.push(o.configure({placeholder:t.placeholder})),t.inlineComments&&E.push(ye.configure(t.inlineComments)),t.slash&&E.push(Me.configure(t.slash)),t.blockHandle&&E.push(Ce.configure(t.blockHandle)),t.tableInteraction&&E.push(Ne.configure(t.tableInteraction)),t.uploadPlaceholder&&E.push(Le.configure(t.uploadPlaceholder)),t.collabDoc&&E.push(s.configure({document:t.collabDoc,field:t.collabField??Te})),t.collabDoc&&t.collabAwareness&&E.push(we.configure({awareness:t.collabAwareness})),E}export{coreExtensions as A,BlockRangeSelection as B,Te as C,refreshInlineComments as D,addUploadPlaceholder as E,currentPlaceholderPos as F,insertUploadedBlock as G,removeUploadPlaceholder as H,replacePlaceholderWithNode as I,ie as T,tablePositionAtCell as a,buildColumnsJson as b,currentTableCellPosition as c,dismissSlash as d,Vt as e,cellPositionAtDOM as f,selectTableCell as g,highlightMenuBlock as h,insertTableBoundary as i,clippedTableSelection as j,tableSelectionMarkActive as k,setTableSelectionMark as l,setTableHeaderBackground as m,currentCellRect as n,setColumnWidth as o,autoFitColumn as p,distributeTableColumns as q,readTableGeometry as r,selectTableAxis as s,tableHeaderActive as t,unwrapCallout as u,getSelectedBlocks as v,setBlockRangeSelection as w,setImageRangeSelection as x,pastedImageFiles as y,pastedRemoteImageUrls as z};
|