wendang-react 0.6.5 → 0.6.7
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/dist/bindings/yjs.js +1 -1
- package/dist/chunks/{MindMapCanvas-C46Q5JBU.js → MindMapCanvas-BA3FYy8p.js} +29 -29
- package/dist/chunks/{MindMapViewer-C9zxZIW8.js → MindMapViewer-B1_uaMHB.js} +1 -1
- package/dist/chunks/extensions-CreWnubi.js +16 -0
- package/dist/chunks/mind-map-defaults-B9SSENmK.js +1 -0
- package/dist/chunks/{mind-topic-text-BHXkxexr.js → mind-topic-text-C7pIS6L9.js} +11 -11
- package/dist/chunks/worksheet-engine-Dz6P8Kiq.js +1 -0
- package/dist/document/viewer.js +6 -6
- package/dist/document.js +68 -75
- package/dist/mindmap/viewer.js +1 -1
- package/dist/mindmap.js +3 -3
- package/dist/spreadsheet.js +1 -1
- 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/table-geometry.d.ts +12 -0
- package/dist/types/engine/shared/color-preview.d.ts +1 -0
- package/dist/types/engine/shared/mind-map-defaults.d.ts +3 -0
- package/integrity.json +51 -41
- package/package.json +3 -3
- package/dist/chunks/extensions-BefQ1tDm.js +0 -14
- package/dist/chunks/mind-map-controller-Ce76mETT.js +0 -1
- package/dist/chunks/worksheet-engine-c84sdD4N.js +0 -1
- /package/third-party-notices/{wendang-export@0.6.4-LICENSE.txt → wendang-export@0.6.5-LICENSE.txt} +0 -0
- /package/third-party-notices/{wendang-export@0.6.4-NOTICE.md.txt → wendang-export@0.6.5-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.5 | 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/dist/bindings/yjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{C as e}from"../chunks/extensions-
|
|
1
|
+
"use client";import{C as e}from"../chunks/extensions-CreWnubi.js";export{e as COLLAB_FIELD};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use client";import{jsxs as e,jsx as t,Fragment as n}from"react/jsx-runtime";import{c as i,b as l,a as o}from"./i18n-B0kCsIjc.js";import{useState as a,useRef as r,useEffect as d,useMemo as c}from"react";import{textDifference as s,mindMapTree as u,layoutMindMap as m,MIND_MAP_PALETTE as h,mindMapDescendants as p,projectMindSideMove as v,mindMapBranchSides as f,mindMapOutline as g,mindRelationPaths as b,mindMapMarkdown as y,mindMapSvg as w,mindMapToJson as x,MIND_MAP_MAX_TOPICS as k}from"wendang/mindmap";import{TEXT_COLORS as C,HIGHLIGHT_COLORS as N,mindTopicLineHeight as I,MIND_TOPIC_FONT as S,readableTextColor as M}from"wendang/shared";import{MIND_ICONS as D,MIND_COLORS as z,MIND_BACKGROUNDS as L,branchModel as P,searchMindMap as E,parseMindMapImport as T,importBranch as A,mindMapTemplate as _,parseMindBranch as $,ancestorIds as K}from"wendang/internal/mind-map-phase2";import{normalizeMindFolds as j,firstLevelMindFolds as B}from"wendang/internal/mind-map-folding";import{p as R}from"./mind-map-delete-CVsxdXfs.js";import{mindMapDescendants as W}from"wendang/internal/mind-map";import{m as U,s as F}from"./mind-map-input-CEWRz_t6.js";import{createPortal as
|
|
1
|
+
"use client";import{jsxs as e,jsx as t,Fragment as n}from"react/jsx-runtime";import{c as i,b as l,a as o}from"./i18n-B0kCsIjc.js";import{useState as a,useRef as r,useEffect as d,useMemo as c}from"react";import{textDifference as s,mindMapTree as u,layoutMindMap as m,MIND_MAP_PALETTE as h,mindMapDescendants as p,projectMindSideMove as v,mindMapBranchSides as f,mindMapOutline as g,mindRelationPaths as b,mindMapMarkdown as y,mindMapSvg as w,mindMapToJson as x,MIND_MAP_MAX_TOPICS as k}from"wendang/mindmap";import{TEXT_COLORS as C,HIGHLIGHT_COLORS as N,mindTopicLineHeight as I,MIND_TOPIC_FONT as S,readableTextColor as M}from"wendang/shared";import{MIND_ICONS as D,MIND_COLORS as z,MIND_BACKGROUNDS as L,branchModel as P,searchMindMap as E,parseMindMapImport as T,importBranch as A,mindMapTemplate as _,parseMindBranch as $,ancestorIds as K}from"wendang/internal/mind-map-phase2";import{normalizeMindFolds as j,firstLevelMindFolds as B}from"wendang/internal/mind-map-folding";import{p as R}from"./mind-map-delete-CVsxdXfs.js";import{mindMapDescendants as W}from"wendang/internal/mind-map";import{m as U,s as F}from"./mind-map-input-CEWRz_t6.js";import{createPortal as G}from"react-dom";import{u as H}from"./hooks-C53Dp0pr.js";import{a as Y,c as O,W as X,d as q}from"./index-COeA2QcQ.js";import{T as J,A as V}from"./mind-topic-text-C7pIS6L9.js";import{W as Q}from"./Dropdown-D98tXfe0.js";import{A as Z}from"./AnchoredPanel-C7jMoPze.js";function topicsInMarquee(e,t,n=[]){const i=new Set(e.map(e=>e.id)),l=new Set([...n].filter(e=>i.has(e)));if(t.width<=0||t.height<=0)return l;for(const n of e)n.x<t.x+t.width&&n.x+n.width>t.x&&n.y<t.y+t.height&&n.y+n.height>t.y&&l.add(n.id);return l}function MindMapComments({pageId:n,blockId:o,topicId:c,topicLabel:s,canComment:u,onClose:m,onChanged:h}){const p=i(),v=p.text,f=l(),[g,b]=a([]),[y,w]=a(""),[x,k]=a(""),[C,N]=a(!1),[I,S]=a(!0),[M,D]=a(null),[z,L]=a(null),[P,E]=a(0),T=r(!0),A=r(!1);async function perform(e){if(!A.current){A.current=!0,N(!0),k("");try{await e(),null==h||h(),T.current&&(w(""),D(null),E(e=>e+1))}catch(e){T.current&&k(String(e))}finally{A.current=!1,T.current&&N(!1)}}}d(()=>(T.current=!0,()=>{T.current=!1}),[]),d(()=>{let e=!0;if(w(""),D(null),L(null),k(""),S(!0),f.comments)return f.comments.list(n).then(t=>{e&&b(t.items.filter(e=>{var t,n;return(null==(t=e.anchor)?void 0:t.prefix)===`mind:${o}`&&(null==(n=e.anchor)?void 0:n.suffix)===c}))}).catch(t=>{e&&k(String(t))}).finally(()=>{e&&S(!1)}),()=>{e=!1};S(!1)},[f.comments,n,o,c,P]);const _=s.trim()?`「${s.trim()}」`:v("当前主题"),time=e=>{const t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString(p.locale)};function compose(i){if(!M||M.id!==i.id)return null;const l="edit"===M.kind;/* @__PURE__ */
|
|
2
2
|
return e("form",{className:"mind-comment__compose",onSubmit:e=>{e.preventDefault(),M.text.trim()&&(l||u)&&perform(()=>l?f.comments.update(M.id,M.text.trim()):f.comments.create(n,M.text.trim(),M.id))},children:[
|
|
3
3
|
/* @__PURE__ */t("label",{className:"mind-comment__label",children:l?v("正在编辑评论"):v("回复 {0}",{0:i.authorName})}),
|
|
4
4
|
/* @__PURE__ */t("textarea",{"aria-label":v(l?"编辑主题讨论":"回复主题讨论"),rows:l?3:2,maxLength:5e3,value:M.text,onChange:e=>D({...M,text:e.target.value})}),
|
|
@@ -20,7 +20,7 @@ return e("aside",{className:"mind-comments","aria-label":v("主题讨论"),child
|
|
|
20
20
|
/* @__PURE__ */e("div",{className:"mind-comments__list",children:[I&&/* @__PURE__ */t("p",{role:"status",children:v("正在加载讨论…")}),!I&&!x&&!g.length&&/* @__PURE__ */e("p",{className:"mind-comments__empty",children:[v("这个主题还没有讨论。"),u?v("在下方写下第一条即可。"):""]}),g.map(e=>comment(e))]}),u?/* @__PURE__ */e("form",{className:"mind-comments__compose",onSubmit:e=>{e.preventDefault(),y.trim()&&perform(()=>f.comments.create(n,y.trim(),void 0,{blockId:o,topicId:c}))},children:[
|
|
21
21
|
/* @__PURE__ */t("label",{className:"mind-comment__label",children:p.t("mind.discussTitle",{title:_})}),
|
|
22
22
|
/* @__PURE__ */t("textarea",{"aria-label":v("主题评论内容"),rows:3,maxLength:5e3,placeholder:v("写下你的想法…"),value:y,onChange:e=>w(e.target.value)}),
|
|
23
|
-
/* @__PURE__ */t("div",{className:"mind-comment__actions",children:/* @__PURE__ */t(Y,{variant:"primary",loading:C,disabled:!y.trim(),htmlType:"submit",children:v("发表讨论")})})]}):/* @__PURE__ */t("p",{className:"mind-comments__empty",children:v("你没有在这个空间发表讨论的权限。")}),z&&/* @__PURE__ */e(
|
|
23
|
+
/* @__PURE__ */t("div",{className:"mind-comment__actions",children:/* @__PURE__ */t(Y,{variant:"primary",loading:C,disabled:!y.trim(),htmlType:"submit",children:v("发表讨论")})})]}):/* @__PURE__ */t("p",{className:"mind-comments__empty",children:v("你没有在这个空间发表讨论的权限。")}),z&&/* @__PURE__ */e(O,{title:v("删除评论"),onClose:()=>L(null),children:[
|
|
24
24
|
/* @__PURE__ */t("p",{children:v("确定删除这条评论?")}),
|
|
25
25
|
/* @__PURE__ */e("div",{className:"wr-toolbar",children:[
|
|
26
26
|
/* @__PURE__ */t(Y,{onClick:()=>L(null),children:v("取消")}),
|
|
@@ -47,17 +47,17 @@ return e("aside",{className:"mind-details","aria-label":h("主题属性"),childr
|
|
|
47
47
|
/* @__PURE__ */e("fieldset",{children:[
|
|
48
48
|
/* @__PURE__ */t("legend",{children:h("外观")}),
|
|
49
49
|
/* @__PURE__ */e("label",{children:[h("形状"),
|
|
50
|
-
/* @__PURE__ */t(
|
|
50
|
+
/* @__PURE__ */t(X,{label:h("主题形状"),ariaLabel:h("主题形状"),value:p.shape??"round",onChange:e=>patch("shape",e),options:[{value:"round",label:h("圆角矩形")},{value:"pill",label:h("胶囊")},{value:"text",label:h("文本")}]})]}),
|
|
51
51
|
/* @__PURE__ */e("label",{children:[h("字号"),
|
|
52
|
-
/* @__PURE__ */t(
|
|
52
|
+
/* @__PURE__ */t(X,{label:h("主题字号"),ariaLabel:h("主题字号"),value:p.fontSize??14,onChange:e=>patch("fontSize",Number(e)),options:[12,14,16,18,20].map(e=>({value:e,label:String(e)}))})]}),
|
|
53
53
|
/* @__PURE__ */e("label",{children:[h("对齐"),
|
|
54
|
-
/* @__PURE__ */t(
|
|
54
|
+
/* @__PURE__ */t(X,{label:h("主题对齐"),ariaLabel:h("主题对齐"),value:p.align??"center",onChange:e=>patch("align",e),options:[{value:"left",label:h("左对齐")},{value:"center",label:h("居中")},{value:"right",label:h("右对齐")}]})]}),
|
|
55
55
|
/* @__PURE__ */t("span",{children:h("节点文字色")}),
|
|
56
56
|
/* @__PURE__ */t("div",{className:"mind-color-grid",onMouseDown:e=>e.preventDefault(),children:ee.map(e=>/* @__PURE__ */t(Y,{size:"small",variant:"outline",narrow:!0,"aria-label":h("节点字体:{0}",{0:e.label}),title:h(e.label),onClick:()=>patch("color",e.value),children:/* @__PURE__ */t("span",{style:e.value?{color:e.value}:void 0,children:"A"})},e.label))}),
|
|
57
57
|
/* @__PURE__ */t("span",{children:h("节点背景")}),
|
|
58
58
|
/* @__PURE__ */t("div",{className:"mind-color-grid",onMouseDown:e=>e.preventDefault(),children:te.map(e=>/* @__PURE__ */t(Y,{size:"small",variant:"outline",narrow:!0,"aria-label":h("节点背景:{0}",{0:e.label}),title:h(e.label),style:e.value?{background:e.value}:void 0,onClick:()=>patch("background",e.value),children:e.value?"":"/"},e.label))}),
|
|
59
59
|
/* @__PURE__ */e("label",{children:[h("图标"),
|
|
60
|
-
/* @__PURE__ */t(
|
|
60
|
+
/* @__PURE__ */t(X,{label:h("主题图标"),ariaLabel:h("主题图标"),value:p.icon??"",onChange:e=>patch("icon",e),options:D.map(e=>({value:e,label:e||h("无图标")}))})]}),
|
|
61
61
|
/* @__PURE__ */t(Y,{size:"small",onClick:()=>null==d?void 0:d.patch(o,{done:!p.done}),children:p.done?h("取消完成"):h("标记完成")})]})]}),
|
|
62
62
|
/* @__PURE__ */e("fieldset",{children:[
|
|
63
63
|
/* @__PURE__ */t("legend",{children:h("描述")}),
|
|
@@ -72,49 +72,49 @@ return e("aside",{className:"mind-details","aria-label":h("主题属性"),childr
|
|
|
72
72
|
/* @__PURE__ */t("legend",{children:h("主题关系")}),E.map(n=>{var i;/* @__PURE__ */
|
|
73
73
|
return e("div",{className:"mind-relation-item",children:[
|
|
74
74
|
/* @__PURE__ */e("span",{children:[n.label||{related:h("相关"),depends:h("依赖"),reference:h("参考")}[n.kind]," → ",(null==(i=l.topics.find(e=>e.id===(n.source===o?n.target:n.source)))?void 0:i.text)||h("已移除主题")]}),v&&n.source===o&&/* @__PURE__ */t(Y,{variant:"text",size:"small",onClick:()=>{L(n.id),x(n.target),M(n.kind),I(n.label)},children:h("编辑")}),v&&/* @__PURE__ */t(Y,{variant:"text",size:"small",onClick:()=>null==d?void 0:d.deleteRelation(n.id),children:h("删除")})]},n.id)}),v&&/* @__PURE__ */e(n,{children:[
|
|
75
|
-
/* @__PURE__ */t(
|
|
76
|
-
/* @__PURE__ */t(
|
|
75
|
+
/* @__PURE__ */t(X,{label:h("关系目标主题"),ariaLabel:h("关系目标主题"),value:w,onChange:x,options:l.topics.filter(e=>e.id!==o).map(e=>({value:e.id,label:e.text||h("未命名主题")})),searchable:!0}),
|
|
76
|
+
/* @__PURE__ */t(X,{label:h("主题关系类型"),ariaLabel:h("主题关系类型"),value:S,onChange:e=>M(e),options:[{value:"related",label:h("相关")},{value:"depends",label:h("依赖")},{value:"reference",label:h("参考")}]}),
|
|
77
77
|
/* @__PURE__ */t("input",{"aria-label":h("关系说明"),placeholder:h("关系说明(可选)"),maxLength:200,value:k,onChange:e=>I(e.target.value)}),
|
|
78
|
-
/* @__PURE__ */t(Y,{size:"small",disabled:!w,onClick:function addRelation(){(null==d?void 0:d.relation({id:z,source:o,target:w,kind:S,label:k}))?(I(""),L(void 0),null==u||u(h("已保存主题关系"))):null==u||u(h("请选择不同的目标主题"))},children:h(z?"保存关系":"添加关系")})]})]})]})}function WTooltip({children:n,content:l}){var o;i().text;const[c,s]=a(!1),u=r(null),m=r(void 0);function close(){clearTimeout(m.current),s(!1)}function show(){clearTimeout(m.current),m.current=setTimeout(()=>s(!0),200)}return d(()=>()=>clearTimeout(m.current),[]),d(()=>{if(c)return window.addEventListener("scroll",close,!0),()=>window.removeEventListener("scroll",close,!0)},[c]),/* @__PURE__ */e("span",{ref:u,style:{display:"contents"},onMouseEnter:show,onMouseLeave:close,onFocus:show,onBlur:close,children:[n,c&&/* @__PURE__ */t(Z,{anchor:(null==(o=u.current)?void 0:o.firstElementChild)??null,align:"center",prefer:"above",gap:8,role:"tooltip",onClose:close,className:"code-tooltip-popup",children:/* @__PURE__ */t("div",{className:"w-tooltip",children:l})})]})}function MindMapCanvas(l){var C,N,D,z,L,ee,te;const ne=i(),ie=ne.text,{host:le,portal:oe}=o(),ae=l.controller,[,re]=a(0);d(()=>{const e=null==ae?void 0:ae.subscribe(()=>re(e=>e+1));return()=>{null==e||e()}},[ae]);const de=(null==ae?void 0:ae.snapshot())??l.model,ce=(null==ae?void 0:ae.editable())??!1,se=r(null==(C=null==ae?void 0:ae.context.viewState)?void 0:C.maps[de.id]).current,[ue,me]=a(()=>new Set((null==se?void 0:se.selectedIds)??[(null==se?void 0:se.selectedId)??de.rootId])),[he,pe]=a((null==se?void 0:se.selectedId)??de.rootId),[ve,fe]=a(null),[ge,be]=a(""),ye=r(!1),[we,xe]=a(()=>j(de,(null==se?void 0:se.collapsed)??[])),[ke,Ce]=a((null==(N=null==se?void 0:se.viewport)?void 0:N.zoom)??1),[Ne,Ie]=a({x:(null==(D=null==se?void 0:se.viewport)?void 0:D.x)??0,y:(null==(z=null==se?void 0:se.viewport)?void 0:z.y)??0}),[Se,Me]=a((null==se?void 0:se.panMode)??!1),De=r(!1),[ze,Le]=a(!1),[Pe,Ee]=a((null==se?void 0:se.showGrid)??!0),[Te,Ae]=a(!1),[_e,$e]=a((null==se?void 0:se.showQuickControls)??!0),[Ke,je]=a(!1),Be=r(null),[Re,We]=a(!1),Ue=r(!1),[Fe,He]=a(!1),[Ge,Ye]=a(""),[Xe,Oe]=a(""),[qe,Je]=a(0),[Ve,Qe]=a(null),[Ze,et]=a(!1),[tt,nt]=a(!!l.openComments),[it,lt]=a({from:0,to:0}),[ot,at]=a(""),[rt,dt]=a(null),[ct,st]=a(null),ut=r([]),mt=r(he),[ht,pt]=a(!1),[vt,ft]=a(""),[gt,bt]=a(""),[yt,wt]=a(!1),[xt,kt]=a(!1),[Ct,Nt]=a(2),[It,St]=a(null),[Mt,Dt]=a(null),[zt,Lt]=a(null),Pt=r(null),[Et,Tt]=a(null),[At,_t]=a(!1),$t=r(!1),Kt=r(!0),jt=r(null),Bt=r(null),Rt=r(null),Wt=r(null),Ut=r([]),[Ft,Ht]=a({width:0,height:0}),Gt=u(de),Yt=Gt.find(e=>e.id===he)??Gt[0],Xt=rt&&Gt.some(e=>e.id===rt)?P(de,rt):de,Ot=m(Xt,j(Xt,we)),qt=h[de.theme],Jt=G({model:de,editable:ce,c:ae,active:he}),Vt=Et?p(de,Et.id):/* @__PURE__ */new Set,Qt="side"===(null==Mt?void 0:Mt.kind)&&Et?v(de,Et.id,Mt.side,Mt.beforeId):null,Zt=Qt?m(Qt,we):null,en=Ge?E(de,Ge):[],tn=c(()=>{try{return vt.trim()?T(vt):null}catch{return null}},[vt]),nn=l.saveStatus??(null==ae?void 0:ae.status())??"",ln=l.pageId??(null==ae?void 0:ae.context.pageId),on=ae?ae.canExport():!0===l.allowExport,an=(null==(L=de.topics.find(e=>e.id===de.rootId))?void 0:L.text)||ie("思维导图");d(()=>{const e=Bt.current;if(!e)return;const t=new ResizeObserver(()=>Ht({width:e.clientWidth,height:e.clientHeight})),wheel=e=>e.preventDefault();return e.addEventListener("wheel",wheel,{passive:!1}),t.observe(e),()=>{t.disconnect(),e.removeEventListener("wheel",wheel)}},[]),d(()=>{const keyup=e=>{"Space"===e.code&&(De.current=!1,Ae(!1))},blur=()=>{cancelGesture(),De.current=!1,Ae(!1),Lt(null)};return window.addEventListener("keyup",keyup),window.addEventListener("blur",blur),()=>{window.removeEventListener("keyup",keyup),window.removeEventListener("blur",blur)}},[]),d(()=>(Kt.current=!0,()=>{Kt.current=!1,null==ae||ae.composition(!1)}),[ae]),d(()=>{const close=e=>{var t;(null==(t=Pt.current)?void 0:t.contains(e.target))||Lt(null)},key=e=>{var t;e.isComposing||"Escape"!==e.key||(Wt.current||zt)&&(e.preventDefault(),e.stopImmediatePropagation(),cancelGesture(),Lt(null),null==(t=Bt.current)||t.focus())};return document.addEventListener("pointerdown",close,!0),window.addEventListener("keydown",key,!0),()=>{document.removeEventListener("pointerdown",close,!0),window.removeEventListener("keydown",key,!0)}},[zt]),d(()=>{const e=Pt.current;if(!e||!zt)return;const t=e.getBoundingClientRect();e.style.left=`${Math.max(8,Math.min(zt.x,innerWidth-t.width-8))}px`,e.style.top=`${Math.max(8,Math.min(zt.y,innerHeight-t.height-8))}px`,e.focus()},[zt,oe]),d(()=>{const e=Wt.current;e&&(e.doc!==JSON.stringify(de)||!ce&&"node"===e.kind)&&cancelGesture()},[de,ce]),d(()=>{var e,t;ve&&(null==(e=Rt.current)||e.focus(),null==(t=Rt.current)||t.select())},[ve]),d(()=>{if(!ve)return;const e=de.topics.find(e=>e.id===ve),t=Rt.current;if(!e||!ce)return null==ae||ae.endText(ve),void fe(null);if(ye.current||e.text===ge)return;const n=(null==t?void 0:t.selectionStart)??0,i=(null==t?void 0:t.selectionEnd)??n,l=s(ge,e.text),o=l.text.length-l.to+l.from,map=e=>e<=l.from?e:e>=l.to?e+o:l.from+l.text.length;be(e.text),queueMicrotask(()=>{t===document.activeElement&&(null==t||t.setSelectionRange(map(n),map(i)))})},[de,ce,ve]),d(()=>{const e=Rt.current;ve&&e&&(e.style.height="0px",e.style.height=`${Math.max(I(Yt.fontSize||14),e.scrollHeight)}px`)},[ve,ge,Yt.fontSize]),d(()=>{const e=new Set(Ot.nodes.map(e=>e.id));me(t=>{const n=new Set([...t].filter(t=>e.has(t)));return n.size===t.size?t:n}),e.has(he)||pe(de.rootId)},[de,he,rt,we]);const rn=r({zoom:ke,pan:Ne,grid:Pe,quickControls:_e,moving:Se,folds:we,active:he,selected:ue});rn.current={zoom:ke,pan:Ne,grid:Pe,quickControls:_e,moving:Se,folds:we,active:he,selected:ue},d(()=>()=>{const e=null==ae?void 0:ae.context.viewState;if(!e)return;const t=rn.current;e.maps[de.id]={selectedId:t.active,selectedIds:[...t.selected],showGrid:t.grid,showQuickControls:t.quickControls,panMode:t.moving,collapsed:[...t.folds],viewport:{x:t.pan.x,y:t.pan.y,zoom:t.zoom}}},[ae,de.id]);const dn=null==ae?void 0:ae.context.awareness,[cn,sn]=a(0);d(()=>{if(!dn)return;const change=()=>sn(e=>e+1);return dn.on("change",change),()=>{dn.off("change",change)}},[dn]),d(()=>{var e;const t=null==(e=null==dn?void 0:dn.getLocalState())?void 0:e.mindMap;!dn||(null==t?void 0:t.blockId)!==de.id&&t||dn.setLocalStateField("mindMap",{blockId:de.id,topicId:he,editing:!!ve,viewport:{...Ne,zoom:ke}})},[dn,de.id,he,ve,Ne.x,Ne.y,ke]),d(()=>()=>{var e,t;(null==(t=null==(e=null==dn?void 0:dn.getLocalState())?void 0:e.mindMap)?void 0:t.blockId)===de.id&&dn.setLocalStateField("mindMap",null)},[dn,de.id]),d(()=>{var e;if(!dn||null===Ve)return;const t=null==(e=dn.getStates().get(Ve))?void 0:e.mindMap;if((null==t?void 0:t.blockId)!==de.id||!t.viewport||![t.viewport.x,t.viewport.y,t.viewport.zoom].every(Number.isFinite))return;const n=Math.min(2.5,Math.max(.005,t.viewport.zoom));Ie({x:t.viewport.x,y:t.viewport.y}),Ce(n)},[dn,Ve,de.id,cn]);const un=c(()=>Array.from((null==dn?void 0:dn.getStates().entries())??[]).flatMap(([e,t])=>{var n,i;const l=t.mindMap;return e===(null==dn?void 0:dn.clientID)||(null==l?void 0:l.blockId)!==de.id?[]:[{client:e,name:String((null==(n=t.user)?void 0:n.name)||(null==(i=t.user)?void 0:i.displayName)||ie("协作者")),topicId:String(l.topicId||""),editing:!!l.editing}]}),[dn,de.id,cn]);function fit(e=Xt){var t,n;const i=m(e,j(e,we)).bounds,l=(null==(t=Bt.current)?void 0:t.clientWidth)??Ft.width,o=(null==(n=Bt.current)?void 0:n.clientHeight)??Ft.height,a=Math.min(1.15,Math.max(.005,Math.min((l-110)/i.width,(o-150)/i.height)));Ce(a),Ie({x:l/2-(i.x+i.width/2)*a,y:o/2-(i.y+i.height/2)*a})}const mn=r(!1),hn=r(de.layout),pn=r({details:Ze,comments:tt,outline:ze});d(()=>{const e=pn.current;!mn.current||hn.current===de.layout&&e.details===Ze&&e.comments===tt&&e.outline===ze||null!==Ve||fit(),hn.current=de.layout,pn.current={details:Ze,comments:tt,outline:ze}},[de.layout,Ze,tt,ze,Ft.width,Ft.height]),d(()=>{mn.current||Ft.width&&Ft.height&&Bt.current&&(mn.current=!0,(null==se?void 0:se.viewport)?Ie({x:se.viewport.x,y:se.viewport.y}):fit())},[Ft.width,Ft.height]);const point=(e,t)=>{const n=Bt.current.getBoundingClientRect();return{x:(e-n.left-Ne.x)/ke,y:(t-n.top-Ne.y)/ke}};function select(e,t=!1){var n;const i=F(ue,e,t);Qe(null),me(i),pe(i.has(e)?e:[...i].at(-1)??de.rootId),null==(n=Bt.current)||n.focus()}function locateHit(e){locate(e.id),"title"!==e.field&&(et(!0),nt(!1))}function locate(e){const t=(null==ae?void 0:ae.snapshot())??de;if(!t.topics.some(t=>t.id===e))return;const n=new Set(we);for(const i of K(t,e))n.delete(i);const i=m(t,n).nodes.find(t=>t.id===e);xe(n),dt(null),select(e),i&&Ie({x:Ft.width/2-(i.x+i.width/2)*ke,y:Ft.height/2-(i.y+i.height/2)*ke})}function jumpHit(e){if(!en.length)return;const t=(qe+e+en.length)%en.length;Je(t),locateHit(en[t])}function edit(e){if(e&&ce){const t=de.topics.find(t=>t.id===e);if(!t)return;pe(e),me(/* @__PURE__ */new Set([e])),null==ae||ae.beginText(e),be(t.text),fe(e)}else ve&&(null==ae||ae.endText(ve)),fe(null),queueMicrotask(()=>{var e;return null==(e=Bt.current)?void 0:e.focus()})}function add(e,t,n=he){if(!ae||!ce)return;if(de.topics.length>=k)return void at(ie("单张导图最多支持 500 个主题。"));const i="parent"===e?ae.addParent(n):void 0!==t&&n===de.rootId?ae.addRootChild(t):"sibling"===e?ae.addSibling(n,"after"):ae.add(n);i&&(xe(e=>{const t=new Set(e);return t.delete(n),t}),me(/* @__PURE__ */new Set([i])),pe(i),ae.beginText(i),be(ie("新主题")),fe(i))}function addSiblingAt(e,t){if(!ae||!ce)return;if(de.topics.length>=k)return void at(ie("单张导图最多支持 500 个主题。"));const n=ae.addSibling(e,t);n&&(xe(t=>{const n=new Set(t);return n.delete(e),n}),me(/* @__PURE__ */new Set([n])),pe(n),ae.beginText(n),be(ie("新主题")),fe(n))}function remove(e=he,t=ue){if(!ae||!ce)return;const n=R(de,t,e);n&&(ut.current=[...t],mt.current=e,n.ids.size>n.roots.length?st(n):performDelete(n,e))}function performDelete(e,t=mt.current){const n=R((null==ae?void 0:ae.snapshot())??de,ut.current,t);n&&n.ids.size===e.ids.size&&![...n.ids].some(t=>!e.ids.has(t))&&(null==ae?void 0:ae.removeMany(ut.current))?(me(/* @__PURE__ */new Set([n.nextId])),pe(n.nextId),fe(null),st(null),at(ie("已删除 {0} 个主题,可撤销。",{0:e.ids.size})),queueMicrotask(()=>{var e;return null==(e=Bt.current)?void 0:e.focus()})):at(ie("主题或权限已变化,请重新选择"))}function fold(e){p(de,e).size&&e!==de.rootId&&xe(t=>{const n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function copy(e=he){var t;ae&&(Ut.current=ae.copyBranch(e),at(ie("分支已复制,选择目标主题后粘贴。")),on&&(null==(t=navigator.clipboard)||t.writeText(`YWIKI_MINDMAP_BRANCH_V1\n${JSON.stringify(Ut.current)}`).catch(()=>{})))}async function paste(e=he){if(ce&&ae&&!$t.current){$t.current=!0,_t(!0);try{let t=Ut.current;if(on)try{const e=await Promise.race([navigator.clipboard.readText(),new Promise((e,t)=>setTimeout(()=>t(new Error(ie("剪贴板读取超时"))),1500))]);e.length<2e6&&e.startsWith("YWIKI_MINDMAP_BRANCH_V1\n")&&(t=$(e))}catch{}await insertBranch(t,e)}catch(e){Kt.current&&at(e instanceof Error?e.message:ie("图片复制失败"))}finally{$t.current=!1,Kt.current&&_t(!1)}}}async function insertBranch(e,t){var n;if(e.filter(e=>"mindMapTopic"===e.type).length+de.topics.length>k)throw new Error(ie("粘贴后主题超过 500 个,本次未修改"));const i=await async function materializeImages(e){var t,n;const i=structuredClone(e),o=new Set(de.topics.flatMap(e=>e.attachmentId?[e.attachmentId]:[])),a=/* @__PURE__ */new Map;for(const e of i){const i=null==(t=e.attrs)?void 0:t.attachmentId;if("string"==typeof i&&i&&!o.has(i)){if(!(null==ae?void 0:ae.context.uploadImage))throw new Error(ie("当前文档不支持图片复制,请移除图片后导入"));if(!a.has(i)){const e=ae.context.fetchAttachment??l.fetchAttachment??(null==(n=le.attachments)?void 0:n.fetch);if(!e)throw new Error(ie("当前文档未配置图片读取服务"));const t=await e(i),o=await ae.context.uploadImage(new File([t],"导图主题图片.png",{type:t.type||"image/png"}));a.set(i,o.id)}e.attrs.attachmentId=a.get(i)}}return i}(e),o=Jt.current;if(!Kt.current||o.c!==ae||!o.editable||o.model.id!==de.id)return;if(!(null==(n=null==ae?void 0:ae.snapshot())?void 0:n.topics.some(e=>e.id===t)))throw new Error(ie("目标主题已移除,请重新选择"));const a=ae.pasteBranch(t,i);if(!a)throw new Error(ie("没有可粘贴的分支,或主题容量超过上限"));at(ie("已粘贴分支。")),xe(e=>{const n=new Set(e);return n.delete(t),n}),locate(a)}function moveSide(e,t=he){var n;(null==ae?void 0:ae.moveToSide(t,e))&&(at(ie("已移到{0}侧",{0:ie(-1===e?"左":"右")})),null==(n=Bt.current)||n.focus())}function openContextMenu(e,t){t.preventDefault(),t.stopPropagation(),e&&select(e),Lt({id:e,x:t.clientX,y:t.clientY})}function contextAction(e){const t=(null==zt?void 0:zt.id)??he;Lt(null),t&&(pe(t),"child"===e||"sibling"===e||"parent"===e?add(e,void 0,t):"rename"===e?edit(t):"properties"===e?(et(!0),nt(!1)):"fold"===e?fold(t):"focus"===e?(dt(t),fit(P(de,t))):"left"===e?moveSide(-1,t):"right"===e?moveSide(1,t):"copy"===e?copy(t):"paste"===e?paste((null==zt?void 0:zt.id)?t:1===ue.size?he:Xt.rootId):"delete"===e?remove(t,/* @__PURE__ */new Set([t])):paneCommand(e))}function paneCommand(e){var t;Qe(null),"quick"===e?$e(e=>!e):"grid"===e?Ee(e=>!e):"comments"===e?(nt(e=>!e),et(!1)):"zoom-in"===e?zoomTo(1.2*ke):"zoom-out"===e?zoomTo(ke/1.2):"reset-zoom"===e?zoomTo(1):"fit"===e&&fit(),null==(t=Bt.current)||t.focus()}function followPeer(e){cancelGesture(),edit(null),Qe(e)}function zoomTo(e,t={x:Ft.width/2,y:Ft.height/2}){const n=Math.max(.005,Math.min(2.5,e)),i=n/ke,l=t.x-(t.x-Ne.x)*i,o=t.y-(t.y-Ne.y)*i;Ce(n),Ie({x:l,y:o})}function cancelGesture(e=!0){const t=Wt.current;e&&"box"===(null==t?void 0:t.kind)&&(me(t.selected),pe(t.active)),Wt.current=null,St(null),Dt(null),Tt(null)}function pointerDown(e,t){var n,i;if(!(null==(n=Bt.current)?void 0:n.contains(e.target)))return;if(e.target.closest("button,input,textarea,a"))return;Qe(null),Lt(null);const l={x:e.clientX,y:e.clientY,lastX:e.clientX,lastY:e.clientY,doc:JSON.stringify(de),count:ue.size,selected:new Set(ue),active:he};if(!t||0!==e.button||Se||De.current)if(1===e.button||0===e.button&&(Se||De.current))Wt.current={...l,kind:"pan"};else{if(t||0!==e.button)return;Wt.current={...l,kind:"box",additive:e.shiftKey||e.metaKey||e.ctrlKey},Wt.current.additive||me(/* @__PURE__ */new Set)}else{const n=e.shiftKey||e.metaKey||e.ctrlKey,i=ue.has(t)&&ue.size>1&&!n?ue:F(ue,t,n);me(i),pe(i.has(t)?t:[...i].at(-1)??de.rootId),Wt.current={...l,kind:"node",id:t,count:i.size,additive:n}}e.currentTarget.setPointerCapture(e.pointerId),null==(i=Bt.current)||i.focus(),e.preventDefault()}async function exportAs(e){var t,n;if(!on||Ue.current)return;if(le.exports&&"copy"!==e&&"copy-image"!==e){Ue.current=!0,We(!0);try{await le.exports.request({kind:"mindmap",format:"md"===e?"markdown":"print"===e?"pdf":e,resourceId:l.pageId??(null==ae?void 0:ae.context.pageId),blockId:de.id})}catch(e){at(e instanceof Error?e.message:ie("导出失败"))}finally{Ue.current=!1,We(!1)}return}Ue.current=!0,We(!0);const i=yt?P(de,he):de,o="print"===e?window.open("","_blank"):null;try{if("copy"===e)return void await navigator.clipboard.writeText(y(i));const a={};for(const e of i.topics)if(e.attachmentId){const n=l.fetchAttachment??(null==ae?void 0:ae.context.fetchAttachment)??(null==(t=le.attachments)?void 0:t.fetch);if(!n)throw new Error(ie("未配置主题图片读取服务"));const i=await n(e.attachmentId);a[e.attachmentId]=await new Promise((e,t)=>{const n=new FileReader;n.onload=()=>e(String(n.result)),n.onerror=t,n.readAsDataURL(i)})}const r=w(i,{transparent:xt,images:a}),download=(e,t)=>{const n=URL.createObjectURL(e),i=document.createElement("a");i.href=n,i.download=`思维导图.${t}`,i.click(),setTimeout(()=>URL.revokeObjectURL(n),1e3)};if("svg"===e)download(new Blob([r],{type:"image/svg+xml"}),"svg");else if("md"===e)download(new Blob([y(i)],{type:"text/markdown"}),"md");else if("json"===e)download(new Blob([JSON.stringify(x(i),null,2)],{type:"application/json"}),"json");else if("png"===e||"copy-image"===e||"print"===e){const t=new Image,i=URL.createObjectURL(new Blob([r],{type:"image/svg+xml"}));try{await new Promise((e,n)=>{t.onload=()=>e(),t.onerror=n,t.src=i});const l=document.createElement("canvas");l.width=t.width*Ct,l.height=t.height*Ct,null==(n=l.getContext("2d"))||n.drawImage(t,0,0,l.width,l.height);const a=await new Promise((e,t)=>l.toBlob(n=>n?e(n):t(new Error(ie("图片生成失败")))));if("copy-image"===e)await navigator.clipboard.write([new ClipboardItem({"image/png":a})]);else if("print"===e){if(!o)throw new Error(ie("打印窗口被浏览器拦截"));const e=o.document.createElement("img");e.src=l.toDataURL(),e.style.maxWidth="100%",o.document.body.append(e),e.onload=()=>o.print()}else download(a,"png")}finally{URL.revokeObjectURL(i)}}}catch(e){null==o||o.close(),at(String(e))}finally{Ue.current=!1,Kt.current&&We(!1)}}d(()=>{lt({from:0,to:0})},[he]),d(()=>{if(!le.location)return;const linked=()=>{const e=new URLSearchParams(le.location.current().replace(/^#/,"")),t=e.get("topic");e.get("mind")===de.id&&t&&locate(t)};return linked(),le.location.subscribe(linked)},[le.location,de.id]);const vn=f(de),fn=Yt.parentId===de.rootId,gn=Gt.find(e=>e.id===(null==zt?void 0:zt.id)),bn="undefined"!=typeof navigator&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",yn=(null==zt?void 0:zt.id)?[{items:[...ce?[{value:"child",label:ie("添加子主题")},{value:"sibling",label:ie("添加同级主题")},...zt.id!==de.rootId?[{value:"parent",label:ie("插入父主题")}]:[],{value:"rename",label:ie("修改文字")}]:[],{value:"properties",label:ie("主题属性")},...zt.id!==de.rootId&&p(de,zt.id).size>1?[{value:"fold",label:we.has(zt.id)?ie("展开分支"):ie("收起分支")}]:[],...ce&&(null==gn?void 0:gn.parentId)===de.rootId&&"down"!==de.layout?[{value:"left",label:ie("移到左侧"),disabled:-1===vn.get(zt.id)},{value:"right",label:ie("移到右侧"),disabled:1===vn.get(zt.id)}]:[],{value:"focus",label:ie("聚焦分支")},...ce?[{value:"copy",label:ie("复制分支")},{value:"paste",label:ie("粘贴分支"),disabled:At},...zt.id!==de.rootId?[{value:"delete",label:ie("删除分支")}]:[]]:[]]}]:[...ce?[{items:[{value:"paste",label:ie("粘贴"),disabled:At,shortcut:"⌘ / Ctrl+V"}]}]:[],{items:[...ln?[{value:"comments",label:ie(tt?"隐藏评论":"显示评论"),shortcut:"Shift+C"}]:[],...ce?[{value:"quick",label:ie(_e?"隐藏快捷创建":"显示快捷创建"),shortcut:"Shift+Q"}]:[],{value:"grid",label:ie(Pe?"隐藏网格":"显示网格"),shortcut:"Shift+G"}]},{items:[{value:"zoom-in",label:ie("放大"),shortcut:`${bn} + +`},{value:"zoom-out",label:ie("缩小"),shortcut:`${bn} + −`},{value:"reset-zoom",label:ie("缩放至 100%"),shortcut:`${bn} + 0`},{value:"fit",label:ie("画布全览"),shortcut:"Shift+1"}]}],wn=/* @__PURE__ */e("div",{className:"mind-map-workspace",ref:jt,onKeyDown:function keydown(e){var t,n,i,o;if(!(null==(t=jt.current)?void 0:t.contains(e.target))||e.defaultPrevented||e.nativeEvent.isComposing||229===e.keyCode||e.target.closest("input,textarea,[contenteditable=true]"))return;const a=e.ctrlKey||e.metaKey,r=U(e);if(!e.target.closest("button,select,[role=combobox]")||r||a){if("Space"===e.code)return e.preventDefault(),De.current=!0,void Ae(!0);if("Escape"===e.key){if(!(l.inline||Ze||tt||Fe))return;return e.preventDefault(),e.stopPropagation(),cancelGesture(),Lt(null),me(/* @__PURE__ */new Set),et(!1),nt(!1),void He(!1)}if(a&&"z"===e.key.toLowerCase()&&ce)return e.preventDefault(),void(e.shiftKey?null==ae||ae.redo():null==ae||ae.undo());if(a&&"y"===e.key.toLowerCase()&&ce)return e.preventDefault(),void(null==ae||ae.redo());if(a&&"f"===e.key.toLowerCase())return e.preventDefault(),void He(!0);if(a&&"c"===e.key.toLowerCase()&&ce&&1===ue.size)return e.preventDefault(),void copy();if(a&&"v"===e.key.toLowerCase()&&ce)return e.preventDefault(),void paste();if((a||e.altKey)&&"."===e.key)return e.preventDefault(),void fold(he);if(r)return e.preventDefault(),void paneCommand(r);if(("Delete"===e.key||"Backspace"===e.key)&&ce&&!a&&!e.altKey&&ue.size)return e.preventDefault(),void(e.repeat||remove());if(ce&&1===ue.size)if("Tab"===e.key)e.preventDefault(),add(e.shiftKey?"parent":"child");else if("Enter"===e.key)e.preventDefault(),add("sibling");else if("F2"===e.key)e.preventDefault(),edit(he);else if(e.altKey&&["ArrowUp","ArrowDown"].includes(e.key)){const t=Gt.filter(e=>e.parentId===Yt.parentId),n=t.findIndex(e=>e.id===he),i=t[n+("ArrowUp"===e.key?-1:1)];i&&(null==ae||ae.move(he,i.id,"ArrowUp"===e.key?"before":"after")),e.preventDefault()}else if(e.key.startsWith("Arrow")){e.preventDefault();const t=(null==(n=Ot.nodes.find(e=>e.id===he))?void 0:n.side)??1,l="down"===de.layout?"ArrowUp":1===t?"ArrowLeft":"ArrowRight",a="down"===de.layout?"ArrowDown":1===t?"ArrowRight":"ArrowLeft",r=Ot.nodes.filter(e=>e.parentId===Yt.parentId),d=r.findIndex(e=>e.id===he),c=e.key===l?Yt.parentId:e.key===a?null==(i=Ot.nodes.find(e=>e.parentId===he))?void 0:i.id:null==(o=r[d+("ArrowUp"===e.key||"ArrowLeft"===e.key?-1:1)])?void 0:o.id;c&&select(c)}}},onPaste:async function nativePaste(e){var t;if(!ce||e.target.closest('input,textarea,[contenteditable="true"]'))return;const n=(null==(t=e.clipboardData)?void 0:t.getData("text/plain"))??"";if(n.startsWith("YWIKI_MINDMAP_BRANCH_V1\n")){e.preventDefault(),e.stopPropagation();try{if($t.current)return;$t.current=!0,_t(!0),await insertBranch($(n),he)}catch(e){at(e instanceof Error?e.message:ie("分支格式无效"))}finally{$t.current=!1,Kt.current&&_t(!1)}}},style:{"--mind-color":qt},children:[ce&&!nn&&!1!==l.showSaveHint&&/* @__PURE__ */t(q,{closable:!0,closeLabel:ie("关闭保存提示"),className:"mind-save-hint",children:ie("编辑完成后,请确认已保存再离开。")}),
|
|
78
|
+
/* @__PURE__ */t(Y,{size:"small",disabled:!w,onClick:function addRelation(){(null==d?void 0:d.relation({id:z,source:o,target:w,kind:S,label:k}))?(I(""),L(void 0),null==u||u(h("已保存主题关系"))):null==u||u(h("请选择不同的目标主题"))},children:h(z?"保存关系":"添加关系")})]})]})]})}function WTooltip({children:n,content:l}){var o;i().text;const[c,s]=a(!1),u=r(null),m=r(void 0);function close(){clearTimeout(m.current),s(!1)}function show(){clearTimeout(m.current),m.current=setTimeout(()=>s(!0),200)}return d(()=>()=>clearTimeout(m.current),[]),d(()=>{if(c)return window.addEventListener("scroll",close,!0),()=>window.removeEventListener("scroll",close,!0)},[c]),/* @__PURE__ */e("span",{ref:u,style:{display:"contents"},onMouseEnter:show,onMouseLeave:close,onFocus:show,onBlur:close,children:[n,c&&/* @__PURE__ */t(Z,{anchor:(null==(o=u.current)?void 0:o.firstElementChild)??null,align:"center",prefer:"above",gap:8,role:"tooltip",onClose:close,className:"code-tooltip-popup",children:/* @__PURE__ */t("div",{className:"w-tooltip",children:l})})]})}function MindMapCanvas(l){var C,N,D,z,L,ee,te;const ne=i(),ie=ne.text,{host:le,portal:oe}=o(),ae=l.controller,[,re]=a(0);d(()=>{const e=null==ae?void 0:ae.subscribe(()=>re(e=>e+1));return()=>{null==e||e()}},[ae]);const de=(null==ae?void 0:ae.snapshot())??l.model,ce=(null==ae?void 0:ae.editable())??!1,se=r(null==(C=null==ae?void 0:ae.context.viewState)?void 0:C.maps[de.id]).current,[ue,me]=a(()=>new Set((null==se?void 0:se.selectedIds)??[(null==se?void 0:se.selectedId)??de.rootId])),[he,pe]=a((null==se?void 0:se.selectedId)??de.rootId),[ve,fe]=a(null),[ge,be]=a(""),ye=r(!1),[we,xe]=a(()=>j(de,(null==se?void 0:se.collapsed)??[])),[ke,Ce]=a((null==(N=null==se?void 0:se.viewport)?void 0:N.zoom)??1),[Ne,Ie]=a({x:(null==(D=null==se?void 0:se.viewport)?void 0:D.x)??0,y:(null==(z=null==se?void 0:se.viewport)?void 0:z.y)??0}),[Se,Me]=a((null==se?void 0:se.panMode)??!1),De=r(!1),[ze,Le]=a(!1),[Pe,Ee]=a((null==se?void 0:se.showGrid)??!0),[Te,Ae]=a(!1),[_e,$e]=a((null==se?void 0:se.showQuickControls)??!0),[Ke,je]=a(!1),Be=r(null),[Re,We]=a(!1),Ue=r(!1),[Fe,Ge]=a(!1),[He,Ye]=a(""),[Oe,Xe]=a(""),[qe,Je]=a(0),[Ve,Qe]=a(null),[Ze,et]=a(!1),[tt,nt]=a(!!l.openComments),[it,lt]=a({from:0,to:0}),[ot,at]=a(""),[rt,dt]=a(null),[ct,st]=a(null),ut=r([]),mt=r(he),[ht,pt]=a(!1),[vt,ft]=a(""),[gt,bt]=a(""),[yt,wt]=a(!1),[xt,kt]=a(!1),[Ct,Nt]=a(2),[It,St]=a(null),[Mt,Dt]=a(null),[zt,Lt]=a(null),Pt=r(null),[Et,Tt]=a(null),[At,_t]=a(!1),$t=r(!1),Kt=r(!0),jt=r(null),Bt=r(null),Rt=r(null),Wt=r(null),Ut=r([]),[Ft,Gt]=a({width:0,height:0}),Ht=u(de),Yt=Ht.find(e=>e.id===he)??Ht[0],Ot=rt&&Ht.some(e=>e.id===rt)?P(de,rt):de,Xt=m(Ot,j(Ot,we)),qt=h[de.theme],Jt=H({model:de,editable:ce,c:ae,active:he}),Vt=Et?p(de,Et.id):/* @__PURE__ */new Set,Qt="side"===(null==Mt?void 0:Mt.kind)&&Et?v(de,Et.id,Mt.side,Mt.beforeId):null,Zt=Qt?m(Qt,we):null,en=He?E(de,He):[],tn=c(()=>{try{return vt.trim()?T(vt):null}catch{return null}},[vt]),nn=l.saveStatus??(null==ae?void 0:ae.status())??"",ln=l.pageId??(null==ae?void 0:ae.context.pageId),on=ae?ae.canExport():!0===l.allowExport,an=(null==(L=de.topics.find(e=>e.id===de.rootId))?void 0:L.text)||ie("思维导图");d(()=>{const e=Bt.current;if(!e)return;const t=new ResizeObserver(()=>Gt({width:e.clientWidth,height:e.clientHeight})),wheel=e=>e.preventDefault();return e.addEventListener("wheel",wheel,{passive:!1}),t.observe(e),()=>{t.disconnect(),e.removeEventListener("wheel",wheel)}},[]),d(()=>{const keyup=e=>{"Space"===e.code&&(De.current=!1,Ae(!1))},blur=()=>{cancelGesture(),De.current=!1,Ae(!1),Lt(null)};return window.addEventListener("keyup",keyup),window.addEventListener("blur",blur),()=>{window.removeEventListener("keyup",keyup),window.removeEventListener("blur",blur)}},[]),d(()=>(Kt.current=!0,()=>{Kt.current=!1,null==ae||ae.composition(!1)}),[ae]),d(()=>{const close=e=>{var t;(null==(t=Pt.current)?void 0:t.contains(e.target))||Lt(null)},key=e=>{var t;e.isComposing||"Escape"!==e.key||(Wt.current||zt)&&(e.preventDefault(),e.stopImmediatePropagation(),cancelGesture(),Lt(null),null==(t=Bt.current)||t.focus())};return document.addEventListener("pointerdown",close,!0),window.addEventListener("keydown",key,!0),()=>{document.removeEventListener("pointerdown",close,!0),window.removeEventListener("keydown",key,!0)}},[zt]),d(()=>{const e=Pt.current;if(!e||!zt)return;const t=e.getBoundingClientRect();e.style.left=`${Math.max(8,Math.min(zt.x,innerWidth-t.width-8))}px`,e.style.top=`${Math.max(8,Math.min(zt.y,innerHeight-t.height-8))}px`,e.focus()},[zt,oe]),d(()=>{const e=Wt.current;e&&(e.doc!==JSON.stringify(de)||!ce&&"node"===e.kind)&&cancelGesture()},[de,ce]),d(()=>{var e,t;ve&&(null==(e=Rt.current)||e.focus(),null==(t=Rt.current)||t.select())},[ve]),d(()=>{if(!ve)return;const e=de.topics.find(e=>e.id===ve),t=Rt.current;if(!e||!ce)return null==ae||ae.endText(ve),void fe(null);if(ye.current||e.text===ge)return;const n=(null==t?void 0:t.selectionStart)??0,i=(null==t?void 0:t.selectionEnd)??n,l=s(ge,e.text),o=l.text.length-l.to+l.from,map=e=>e<=l.from?e:e>=l.to?e+o:l.from+l.text.length;be(e.text),queueMicrotask(()=>{t===document.activeElement&&(null==t||t.setSelectionRange(map(n),map(i)))})},[de,ce,ve]),d(()=>{const e=Rt.current;ve&&e&&(e.style.height="0px",e.style.height=`${Math.max(I(Yt.fontSize||14),e.scrollHeight)}px`)},[ve,ge,Yt.fontSize]),d(()=>{const e=new Set(Xt.nodes.map(e=>e.id));me(t=>{const n=new Set([...t].filter(t=>e.has(t)));return n.size===t.size?t:n}),e.has(he)||pe(de.rootId)},[de,he,rt,we]);const rn=r({zoom:ke,pan:Ne,grid:Pe,quickControls:_e,moving:Se,folds:we,active:he,selected:ue});rn.current={zoom:ke,pan:Ne,grid:Pe,quickControls:_e,moving:Se,folds:we,active:he,selected:ue},d(()=>()=>{const e=null==ae?void 0:ae.context.viewState;if(!e)return;const t=rn.current;e.maps[de.id]={selectedId:t.active,selectedIds:[...t.selected],showGrid:t.grid,showQuickControls:t.quickControls,panMode:t.moving,collapsed:[...t.folds],viewport:{x:t.pan.x,y:t.pan.y,zoom:t.zoom}}},[ae,de.id]);const dn=null==ae?void 0:ae.context.awareness,[cn,sn]=a(0);d(()=>{if(!dn)return;const change=()=>sn(e=>e+1);return dn.on("change",change),()=>{dn.off("change",change)}},[dn]),d(()=>{var e;const t=null==(e=null==dn?void 0:dn.getLocalState())?void 0:e.mindMap;!dn||(null==t?void 0:t.blockId)!==de.id&&t||dn.setLocalStateField("mindMap",{blockId:de.id,topicId:he,editing:!!ve,viewport:{...Ne,zoom:ke}})},[dn,de.id,he,ve,Ne.x,Ne.y,ke]),d(()=>()=>{var e,t;(null==(t=null==(e=null==dn?void 0:dn.getLocalState())?void 0:e.mindMap)?void 0:t.blockId)===de.id&&dn.setLocalStateField("mindMap",null)},[dn,de.id]),d(()=>{var e;if(!dn||null===Ve)return;const t=null==(e=dn.getStates().get(Ve))?void 0:e.mindMap;if((null==t?void 0:t.blockId)!==de.id||!t.viewport||![t.viewport.x,t.viewport.y,t.viewport.zoom].every(Number.isFinite))return;const n=Math.min(2.5,Math.max(.005,t.viewport.zoom));Ie({x:t.viewport.x,y:t.viewport.y}),Ce(n)},[dn,Ve,de.id,cn]);const un=c(()=>Array.from((null==dn?void 0:dn.getStates().entries())??[]).flatMap(([e,t])=>{var n,i;const l=t.mindMap;return e===(null==dn?void 0:dn.clientID)||(null==l?void 0:l.blockId)!==de.id?[]:[{client:e,name:String((null==(n=t.user)?void 0:n.name)||(null==(i=t.user)?void 0:i.displayName)||ie("协作者")),topicId:String(l.topicId||""),editing:!!l.editing}]}),[dn,de.id,cn]);function fit(e=Ot){var t,n;const i=m(e,j(e,we)).bounds,l=(null==(t=Bt.current)?void 0:t.clientWidth)??Ft.width,o=(null==(n=Bt.current)?void 0:n.clientHeight)??Ft.height,a=Math.min(1.15,Math.max(.005,Math.min((l-110)/i.width,(o-150)/i.height)));Ce(a),Ie({x:l/2-(i.x+i.width/2)*a,y:o/2-(i.y+i.height/2)*a})}const mn=r(!1),hn=r(de.layout),pn=r({details:Ze,comments:tt,outline:ze});d(()=>{const e=pn.current;!mn.current||hn.current===de.layout&&e.details===Ze&&e.comments===tt&&e.outline===ze||null!==Ve||fit(),hn.current=de.layout,pn.current={details:Ze,comments:tt,outline:ze}},[de.layout,Ze,tt,ze,Ft.width,Ft.height]),d(()=>{mn.current||Ft.width&&Ft.height&&Bt.current&&(mn.current=!0,(null==se?void 0:se.viewport)?Ie({x:se.viewport.x,y:se.viewport.y}):fit())},[Ft.width,Ft.height]);const point=(e,t)=>{const n=Bt.current.getBoundingClientRect();return{x:(e-n.left-Ne.x)/ke,y:(t-n.top-Ne.y)/ke}};function select(e,t=!1){var n;const i=F(ue,e,t);Qe(null),me(i),pe(i.has(e)?e:[...i].at(-1)??de.rootId),null==(n=Bt.current)||n.focus()}function locateHit(e){locate(e.id),"title"!==e.field&&(et(!0),nt(!1))}function locate(e){const t=(null==ae?void 0:ae.snapshot())??de;if(!t.topics.some(t=>t.id===e))return;const n=new Set(we);for(const i of K(t,e))n.delete(i);const i=m(t,n).nodes.find(t=>t.id===e);xe(n),dt(null),select(e),i&&Ie({x:Ft.width/2-(i.x+i.width/2)*ke,y:Ft.height/2-(i.y+i.height/2)*ke})}function jumpHit(e){if(!en.length)return;const t=(qe+e+en.length)%en.length;Je(t),locateHit(en[t])}function edit(e){if(e&&ce){const t=de.topics.find(t=>t.id===e);if(!t)return;pe(e),me(/* @__PURE__ */new Set([e])),null==ae||ae.beginText(e),be(t.text),fe(e)}else ve&&(null==ae||ae.endText(ve)),fe(null),queueMicrotask(()=>{var e;return null==(e=Bt.current)?void 0:e.focus()})}function add(e,t,n=he){if(!ae||!ce)return;if(de.topics.length>=k)return void at(ie("单张导图最多支持 500 个主题。"));const i="parent"===e?ae.addParent(n):void 0!==t&&n===de.rootId?ae.addRootChild(t):"sibling"===e?ae.addSibling(n,"after"):ae.add(n);i&&(xe(e=>{const t=new Set(e);return t.delete(n),t}),me(/* @__PURE__ */new Set([i])),pe(i),ae.beginText(i),be(ie("新主题")),fe(i))}function addSiblingAt(e,t){if(!ae||!ce)return;if(de.topics.length>=k)return void at(ie("单张导图最多支持 500 个主题。"));const n=ae.addSibling(e,t);n&&(xe(t=>{const n=new Set(t);return n.delete(e),n}),me(/* @__PURE__ */new Set([n])),pe(n),ae.beginText(n),be(ie("新主题")),fe(n))}function remove(e=he,t=ue){if(!ae||!ce)return;const n=R(de,t,e);n&&(ut.current=[...t],mt.current=e,n.ids.size>n.roots.length?st(n):performDelete(n,e))}function performDelete(e,t=mt.current){const n=R((null==ae?void 0:ae.snapshot())??de,ut.current,t);n&&n.ids.size===e.ids.size&&![...n.ids].some(t=>!e.ids.has(t))&&(null==ae?void 0:ae.removeMany(ut.current))?(me(/* @__PURE__ */new Set([n.nextId])),pe(n.nextId),fe(null),st(null),at(ie("已删除 {0} 个主题,可撤销。",{0:e.ids.size})),queueMicrotask(()=>{var e;return null==(e=Bt.current)?void 0:e.focus()})):at(ie("主题或权限已变化,请重新选择"))}function fold(e){p(de,e).size&&e!==de.rootId&&xe(t=>{const n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function copy(e=he){var t;ae&&(Ut.current=ae.copyBranch(e),at(ie("分支已复制,选择目标主题后粘贴。")),on&&(null==(t=navigator.clipboard)||t.writeText(`YWIKI_MINDMAP_BRANCH_V1\n${JSON.stringify(Ut.current)}`).catch(()=>{})))}async function paste(e=he){if(ce&&ae&&!$t.current){$t.current=!0,_t(!0);try{let t=Ut.current;if(on)try{const e=await Promise.race([navigator.clipboard.readText(),new Promise((e,t)=>setTimeout(()=>t(new Error(ie("剪贴板读取超时"))),1500))]);e.length<2e6&&e.startsWith("YWIKI_MINDMAP_BRANCH_V1\n")&&(t=$(e))}catch{}await insertBranch(t,e)}catch(e){Kt.current&&at(e instanceof Error?e.message:ie("图片复制失败"))}finally{$t.current=!1,Kt.current&&_t(!1)}}}async function insertBranch(e,t){var n;if(e.filter(e=>"mindMapTopic"===e.type).length+de.topics.length>k)throw new Error(ie("粘贴后主题超过 500 个,本次未修改"));const i=await async function materializeImages(e){var t,n;const i=structuredClone(e),o=new Set(de.topics.flatMap(e=>e.attachmentId?[e.attachmentId]:[])),a=/* @__PURE__ */new Map;for(const e of i){const i=null==(t=e.attrs)?void 0:t.attachmentId;if("string"==typeof i&&i&&!o.has(i)){if(!(null==ae?void 0:ae.context.uploadImage))throw new Error(ie("当前文档不支持图片复制,请移除图片后导入"));if(!a.has(i)){const e=ae.context.fetchAttachment??l.fetchAttachment??(null==(n=le.attachments)?void 0:n.fetch);if(!e)throw new Error(ie("当前文档未配置图片读取服务"));const t=await e(i),o=await ae.context.uploadImage(new File([t],"导图主题图片.png",{type:t.type||"image/png"}));a.set(i,o.id)}e.attrs.attachmentId=a.get(i)}}return i}(e),o=Jt.current;if(!Kt.current||o.c!==ae||!o.editable||o.model.id!==de.id)return;if(!(null==(n=null==ae?void 0:ae.snapshot())?void 0:n.topics.some(e=>e.id===t)))throw new Error(ie("目标主题已移除,请重新选择"));const a=ae.pasteBranch(t,i);if(!a)throw new Error(ie("没有可粘贴的分支,或主题容量超过上限"));at(ie("已粘贴分支。")),xe(e=>{const n=new Set(e);return n.delete(t),n}),locate(a)}function moveSide(e,t=he){var n;(null==ae?void 0:ae.moveToSide(t,e))&&(at(ie("已移到{0}侧",{0:ie(-1===e?"左":"右")})),null==(n=Bt.current)||n.focus())}function openContextMenu(e,t){t.preventDefault(),t.stopPropagation(),e&&select(e),Lt({id:e,x:t.clientX,y:t.clientY})}function contextAction(e){const t=(null==zt?void 0:zt.id)??he;Lt(null),t&&(pe(t),"child"===e||"sibling"===e||"parent"===e?add(e,void 0,t):"rename"===e?edit(t):"properties"===e?(et(!0),nt(!1)):"fold"===e?fold(t):"focus"===e?(dt(t),fit(P(de,t))):"left"===e?moveSide(-1,t):"right"===e?moveSide(1,t):"copy"===e?copy(t):"paste"===e?paste((null==zt?void 0:zt.id)?t:1===ue.size?he:Ot.rootId):"delete"===e?remove(t,/* @__PURE__ */new Set([t])):paneCommand(e))}function paneCommand(e){var t;Qe(null),"quick"===e?$e(e=>!e):"grid"===e?Ee(e=>!e):"comments"===e?(nt(e=>!e),et(!1)):"zoom-in"===e?zoomTo(1.2*ke):"zoom-out"===e?zoomTo(ke/1.2):"reset-zoom"===e?zoomTo(1):"fit"===e&&fit(),null==(t=Bt.current)||t.focus()}function followPeer(e){cancelGesture(),edit(null),Qe(e)}function zoomTo(e,t={x:Ft.width/2,y:Ft.height/2}){const n=Math.max(.005,Math.min(2.5,e)),i=n/ke,l=t.x-(t.x-Ne.x)*i,o=t.y-(t.y-Ne.y)*i;Ce(n),Ie({x:l,y:o})}function cancelGesture(e=!0){const t=Wt.current;e&&"box"===(null==t?void 0:t.kind)&&(me(t.selected),pe(t.active)),Wt.current=null,St(null),Dt(null),Tt(null)}function pointerDown(e,t){var n,i;if(!(null==(n=Bt.current)?void 0:n.contains(e.target)))return;if(e.target.closest("button,input,textarea,a"))return;Qe(null),Lt(null);const l={x:e.clientX,y:e.clientY,lastX:e.clientX,lastY:e.clientY,doc:JSON.stringify(de),count:ue.size,selected:new Set(ue),active:he};if(!t||0!==e.button||Se||De.current)if(1===e.button||0===e.button&&(Se||De.current))Wt.current={...l,kind:"pan"};else{if(t||0!==e.button)return;Wt.current={...l,kind:"box",additive:e.shiftKey||e.metaKey||e.ctrlKey},Wt.current.additive||me(/* @__PURE__ */new Set)}else{const n=e.shiftKey||e.metaKey||e.ctrlKey,i=ue.has(t)&&ue.size>1&&!n?ue:F(ue,t,n);me(i),pe(i.has(t)?t:[...i].at(-1)??de.rootId),Wt.current={...l,kind:"node",id:t,count:i.size,additive:n}}e.currentTarget.setPointerCapture(e.pointerId),null==(i=Bt.current)||i.focus(),e.preventDefault()}async function exportAs(e){var t,n;if(!on||Ue.current)return;if(le.exports&&"copy"!==e&&"copy-image"!==e){Ue.current=!0,We(!0);try{await le.exports.request({kind:"mindmap",format:"md"===e?"markdown":"print"===e?"pdf":e,resourceId:l.pageId??(null==ae?void 0:ae.context.pageId),blockId:de.id})}catch(e){at(e instanceof Error?e.message:ie("导出失败"))}finally{Ue.current=!1,We(!1)}return}Ue.current=!0,We(!0);const i=yt?P(de,he):de,o="print"===e?window.open("","_blank"):null;try{if("copy"===e)return void await navigator.clipboard.writeText(y(i));const a={};for(const e of i.topics)if(e.attachmentId){const n=l.fetchAttachment??(null==ae?void 0:ae.context.fetchAttachment)??(null==(t=le.attachments)?void 0:t.fetch);if(!n)throw new Error(ie("未配置主题图片读取服务"));const i=await n(e.attachmentId);a[e.attachmentId]=await new Promise((e,t)=>{const n=new FileReader;n.onload=()=>e(String(n.result)),n.onerror=t,n.readAsDataURL(i)})}const r=w(i,{transparent:xt,images:a}),download=(e,t)=>{const n=URL.createObjectURL(e),i=document.createElement("a");i.href=n,i.download=`思维导图.${t}`,i.click(),setTimeout(()=>URL.revokeObjectURL(n),1e3)};if("svg"===e)download(new Blob([r],{type:"image/svg+xml"}),"svg");else if("md"===e)download(new Blob([y(i)],{type:"text/markdown"}),"md");else if("json"===e)download(new Blob([JSON.stringify(x(i),null,2)],{type:"application/json"}),"json");else if("png"===e||"copy-image"===e||"print"===e){const t=new Image,i=URL.createObjectURL(new Blob([r],{type:"image/svg+xml"}));try{await new Promise((e,n)=>{t.onload=()=>e(),t.onerror=n,t.src=i});const l=document.createElement("canvas");l.width=t.width*Ct,l.height=t.height*Ct,null==(n=l.getContext("2d"))||n.drawImage(t,0,0,l.width,l.height);const a=await new Promise((e,t)=>l.toBlob(n=>n?e(n):t(new Error(ie("图片生成失败")))));if("copy-image"===e)await navigator.clipboard.write([new ClipboardItem({"image/png":a})]);else if("print"===e){if(!o)throw new Error(ie("打印窗口被浏览器拦截"));const e=o.document.createElement("img");e.src=l.toDataURL(),e.style.maxWidth="100%",o.document.body.append(e),e.onload=()=>o.print()}else download(a,"png")}finally{URL.revokeObjectURL(i)}}}catch(e){null==o||o.close(),at(String(e))}finally{Ue.current=!1,Kt.current&&We(!1)}}d(()=>{lt({from:0,to:0})},[he]),d(()=>{if(!le.location)return;const linked=()=>{const e=new URLSearchParams(le.location.current().replace(/^#/,"")),t=e.get("topic");e.get("mind")===de.id&&t&&locate(t)};return linked(),le.location.subscribe(linked)},[le.location,de.id]);const vn=f(de),fn=Yt.parentId===de.rootId,gn=Ht.find(e=>e.id===(null==zt?void 0:zt.id)),bn="undefined"!=typeof navigator&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",yn=(null==zt?void 0:zt.id)?[{items:[...ce?[{value:"child",label:ie("添加子主题")},{value:"sibling",label:ie("添加同级主题")},...zt.id!==de.rootId?[{value:"parent",label:ie("插入父主题")}]:[],{value:"rename",label:ie("修改文字")}]:[],{value:"properties",label:ie("主题属性")},...zt.id!==de.rootId&&p(de,zt.id).size>1?[{value:"fold",label:we.has(zt.id)?ie("展开分支"):ie("收起分支")}]:[],...ce&&(null==gn?void 0:gn.parentId)===de.rootId&&"down"!==de.layout?[{value:"left",label:ie("移到左侧"),disabled:-1===vn.get(zt.id)},{value:"right",label:ie("移到右侧"),disabled:1===vn.get(zt.id)}]:[],{value:"focus",label:ie("聚焦分支")},...ce?[{value:"copy",label:ie("复制分支")},{value:"paste",label:ie("粘贴分支"),disabled:At},...zt.id!==de.rootId?[{value:"delete",label:ie("删除分支")}]:[]]:[]]}]:[...ce?[{items:[{value:"paste",label:ie("粘贴"),disabled:At,shortcut:"⌘ / Ctrl+V"}]}]:[],{items:[...ln?[{value:"comments",label:ie(tt?"隐藏评论":"显示评论"),shortcut:"Shift+C"}]:[],...ce?[{value:"quick",label:ie(_e?"隐藏快捷创建":"显示快捷创建"),shortcut:"Shift+Q"}]:[],{value:"grid",label:ie(Pe?"隐藏网格":"显示网格"),shortcut:"Shift+G"}]},{items:[{value:"zoom-in",label:ie("放大"),shortcut:`${bn} + +`},{value:"zoom-out",label:ie("缩小"),shortcut:`${bn} + −`},{value:"reset-zoom",label:ie("缩放至 100%"),shortcut:`${bn} + 0`},{value:"fit",label:ie("画布全览"),shortcut:"Shift+1"}]}],wn=/* @__PURE__ */e("div",{className:"mind-map-workspace",ref:jt,onKeyDown:function keydown(e){var t,n,i,o;if(!(null==(t=jt.current)?void 0:t.contains(e.target))||e.defaultPrevented||e.nativeEvent.isComposing||229===e.keyCode||e.target.closest("input,textarea,[contenteditable=true]"))return;const a=e.ctrlKey||e.metaKey,r=U(e);if(!e.target.closest("button,select,[role=combobox]")||r||a){if("Space"===e.code)return e.preventDefault(),De.current=!0,void Ae(!0);if("Escape"===e.key){if(!(l.inline||Ze||tt||Fe))return;return e.preventDefault(),e.stopPropagation(),cancelGesture(),Lt(null),me(/* @__PURE__ */new Set),et(!1),nt(!1),void Ge(!1)}if(a&&"z"===e.key.toLowerCase()&&ce)return e.preventDefault(),void(e.shiftKey?null==ae||ae.redo():null==ae||ae.undo());if(a&&"y"===e.key.toLowerCase()&&ce)return e.preventDefault(),void(null==ae||ae.redo());if(a&&"f"===e.key.toLowerCase())return e.preventDefault(),void Ge(!0);if(a&&"c"===e.key.toLowerCase()&&ce&&1===ue.size)return e.preventDefault(),void copy();if(a&&"v"===e.key.toLowerCase()&&ce)return e.preventDefault(),void paste();if((a||e.altKey)&&"."===e.key)return e.preventDefault(),void fold(he);if(r)return e.preventDefault(),void paneCommand(r);if(("Delete"===e.key||"Backspace"===e.key)&&ce&&!a&&!e.altKey&&ue.size)return e.preventDefault(),void(e.repeat||remove());if(ce&&1===ue.size)if("Tab"===e.key)e.preventDefault(),add(e.shiftKey?"parent":"child");else if("Enter"===e.key)e.preventDefault(),add("sibling");else if("F2"===e.key)e.preventDefault(),edit(he);else if(e.altKey&&["ArrowUp","ArrowDown"].includes(e.key)){const t=Ht.filter(e=>e.parentId===Yt.parentId),n=t.findIndex(e=>e.id===he),i=t[n+("ArrowUp"===e.key?-1:1)];i&&(null==ae||ae.move(he,i.id,"ArrowUp"===e.key?"before":"after")),e.preventDefault()}else if(e.key.startsWith("Arrow")){e.preventDefault();const t=(null==(n=Xt.nodes.find(e=>e.id===he))?void 0:n.side)??1,l="down"===de.layout?"ArrowUp":1===t?"ArrowLeft":"ArrowRight",a="down"===de.layout?"ArrowDown":1===t?"ArrowRight":"ArrowLeft",r=Xt.nodes.filter(e=>e.parentId===Yt.parentId),d=r.findIndex(e=>e.id===he),c=e.key===l?Yt.parentId:e.key===a?null==(i=Xt.nodes.find(e=>e.parentId===he))?void 0:i.id:null==(o=r[d+("ArrowUp"===e.key||"ArrowLeft"===e.key?-1:1)])?void 0:o.id;c&&select(c)}}},onPaste:async function nativePaste(e){var t;if(!ce||e.target.closest('input,textarea,[contenteditable="true"]'))return;const n=(null==(t=e.clipboardData)?void 0:t.getData("text/plain"))??"";if(n.startsWith("YWIKI_MINDMAP_BRANCH_V1\n")){e.preventDefault(),e.stopPropagation();try{if($t.current)return;$t.current=!0,_t(!0),await insertBranch($(n),he)}catch(e){at(e instanceof Error?e.message:ie("分支格式无效"))}finally{$t.current=!1,Kt.current&&_t(!1)}}},style:{"--mind-color":qt},children:[ce&&!nn&&!1!==l.showSaveHint&&/* @__PURE__ */t(q,{closable:!0,closeLabel:ie("关闭保存提示"),className:"mind-save-hint",children:ie("编辑完成后,请确认已保存再离开。")}),
|
|
79
79
|
/* @__PURE__ */e("header",{className:"mind-canvas-toolbar",children:[
|
|
80
80
|
/* @__PURE__ */e("div",{className:"mind-canvas-tools",children:[!l.inline&&l.onClose&&/* @__PURE__ */t(Y,{onClick:l.onClose,children:ie("返回文档")}),
|
|
81
|
-
/* @__PURE__ */t(Q,{label:ie("展开与收起"),groups:[{items:[{value:"expand",label:ie("全部展开")},{value:"first-level",label:ie("收起至一级")}]}],onSelect:e=>xe("expand"===e?/* @__PURE__ */new Set:B(
|
|
81
|
+
/* @__PURE__ */t(Q,{label:ie("展开与收起"),groups:[{items:[{value:"expand",label:ie("全部展开")},{value:"first-level",label:ie("收起至一级")}]}],onSelect:e=>xe("expand"===e?/* @__PURE__ */new Set:B(Ot))}),
|
|
82
82
|
/* @__PURE__ */t(Y,{ref:Be,"aria-expanded":Ke,onClick:()=>je(!Ke),children:ie("视图与导出设置")}),Ke&&/* @__PURE__ */t(Z,{anchor:Be.current,onClose:()=>je(!1),align:"center",gap:6,label:ie("视图与导出设置"),className:"mind-dropdown-popup",children:/* @__PURE__ */e("div",{className:"mind-settings-menu",children:[un.map(n=>{var i,l;/* @__PURE__ */
|
|
83
83
|
return e("span",{className:"mind-peer",children:[
|
|
84
84
|
/* @__PURE__ */e("span",{children:[n.name,n.editing?" 正在编辑":" 正在查看"," ",null==(l=null==(i=de.topics.find(e=>e.id===n.topicId))?void 0:i.text)?void 0:l.slice(0,12)]}),
|
|
85
85
|
/* @__PURE__ */t(Y,{variant:"text",onClick:()=>followPeer(n.client),children:ie("跟随")})]},n.client)}),null!==Ve&&/* @__PURE__ */t(Y,{onClick:()=>followPeer(null),children:ie("停止跟随")}),
|
|
86
86
|
/* @__PURE__ */t(Y,{variant:"text",onClick:()=>{const e=rt?null:he;dt(e),fit(e?P(de,e):de)},children:ie(rt?"返回全图":"聚焦分支")}),
|
|
87
|
-
/* @__PURE__ */t(Y,{variant:"text",onClick:()=>{!async function copyTopicLink(){var e,t;const n=null==(t=null==(e=le.location)?void 0:e.createLink)?void 0:t.call(e,{blockId:de.id,topicId:he});if(n)try{await navigator.clipboard.writeText(n),at(ie("已复制主题定位链接"))}catch{at(n)}else at(ie("宿主未提供主题定位链接"))}()},children:ie("复制主题链接")}),ce&&/* @__PURE__ */t(
|
|
87
|
+
/* @__PURE__ */t(Y,{variant:"text",onClick:()=>{!async function copyTopicLink(){var e,t;const n=null==(t=null==(e=le.location)?void 0:e.createLink)?void 0:t.call(e,{blockId:de.id,topicId:he});if(n)try{await navigator.clipboard.writeText(n),at(ie("已复制主题定位链接"))}catch{at(n)}else at(ie("宿主未提供主题定位链接"))}()},children:ie("复制主题链接")}),ce&&/* @__PURE__ */t(X,{label:ie("分支线型"),ariaLabel:ie("分支线型"),width:95,value:de.branchStyle??"curve",onChange:e=>null==ae?void 0:ae.settings({branchStyle:e}),options:["curve","straight","step"].map((e,t)=>({value:e,label:[ie("曲线"),ie("直线"),ie("折线")][t]}))}),on&&/* @__PURE__ */e(n,{children:[
|
|
88
88
|
/* @__PURE__ */e("label",{children:[
|
|
89
89
|
/* @__PURE__ */t("input",{type:"checkbox",checked:yt,onChange:e=>wt(e.target.checked)}),ie("仅导出选中分支")]}),
|
|
90
90
|
/* @__PURE__ */e("label",{children:[
|
|
91
91
|
/* @__PURE__ */t("input",{type:"checkbox",checked:xt,onChange:e=>kt(e.target.checked)}),ie("透明背景")]}),
|
|
92
|
-
/* @__PURE__ */t(
|
|
92
|
+
/* @__PURE__ */t(X,{label:ie("图片分辨率"),ariaLabel:ie("图片分辨率"),width:90,value:Ct,onChange:e=>Nt(Number(e)),options:[1,2,3].map(e=>({value:e,label:ie("{0} 倍图片",{0:e})}))})]}),on&&/* @__PURE__ */e(n,{children:[
|
|
93
93
|
/* @__PURE__ */t(Y,{variant:"text",onClick:()=>{exportAs("copy-image")},children:ie("复制图片")}),
|
|
94
94
|
/* @__PURE__ */t(Y,{variant:"text",onClick:()=>{exportAs("print")},children:le.exports?ie("导出 PDF"):ie("打印 / PDF")})]})]})}),un.length>0&&/* @__PURE__ */t(Q,{label:ie("协作({0})",{0:un.length}),buttonProps:{variant:"text"},groups:[{items:un.map(e=>({value:String(e.client),label:`${e.name}${e.editing?" 正在编辑":" 正在查看"} · 跟随`}))}],onSelect:e=>followPeer(Number(e))})]}),
|
|
95
95
|
/* @__PURE__ */e("div",{className:"mind-canvas-tools mind-canvas-options",children:[nn||!ce?/* @__PURE__ */t("span",{className:"mind-canvas-status",role:"status","aria-label":ie("保存状态"),children:nn||ie("只读")}):null,ce&&/* @__PURE__ */e(n,{children:[
|
|
96
|
-
/* @__PURE__ */t(
|
|
97
|
-
/* @__PURE__ */t(
|
|
98
|
-
/* @__PURE__ */t(
|
|
99
|
-
/* @__PURE__ */t(Y,{onClick:()=>
|
|
100
|
-
/* @__PURE__ */t(Q,{label:ie("更多"),groups:[{items:[{value:"outline",label:ie(ze?"隐藏文字大纲":"显示文字大纲")},{value:"details",label:ie("主题属性")},...le.comments&&ln?[{value:"comments",label:ie(tt?"隐藏主题讨论":"主题讨论")}]:[],...ce?[{value:"import",label:ie("导入")}]:[]]}],onSelect:e=>{"outline"===e?Le(!ze):"details"===e?(et(!Ze),nt(!1)):"comments"===e?(nt(!tt),et(!1)):"import"===e&&pt(!0)}}),on&&/* @__PURE__ */t(
|
|
101
|
-
/* @__PURE__ */t("input",{"aria-label":ie("查找导图文字"),placeholder:ie("查找主题、描述和备注"),value:
|
|
96
|
+
/* @__PURE__ */t(X,{label:ie("导图布局"),ariaLabel:ie("导图布局"),width:94,value:de.layout,onChange:e=>null==ae?void 0:ae.settings({layout:e}),options:["right","left","both","down"].map((e,t)=>({value:e,label:[ie("向右"),ie("向左"),ie("双侧"),ie("向下")][t]}))}),
|
|
97
|
+
/* @__PURE__ */t(X,{label:ie("导图主题"),ariaLabel:ie("导图主题"),width:94,value:de.theme,onChange:e=>null==ae?void 0:ae.settings({theme:e}),options:["blue","teal","violet","amber"].map((e,t)=>({value:e,label:[ie("靛蓝"),ie("青绿"),ie("紫藤"),ie("琥珀")][t]}))}),
|
|
98
|
+
/* @__PURE__ */t(X,{label:ie("正文预览高度"),ariaLabel:ie("正文预览高度"),width:114,value:de.height,onChange:e=>null==ae?void 0:ae.settings({height:Number(e)}),options:[280,380,520].map((e,t)=>({value:e,label:[ie("预览 · 紧凑"),ie("预览 · 标准"),ie("预览 · 宽松")][t]}))})]}),
|
|
99
|
+
/* @__PURE__ */t(Y,{onClick:()=>Ge(!Fe),children:ie("查找替换")}),!ce&&le.comments&&ln&&/* @__PURE__ */t(Y,{variant:tt?"primary":"default","aria-pressed":tt,onClick:()=>{nt(!tt),et(!1)},children:tt?"收起讨论":ie("查看讨论")}),
|
|
100
|
+
/* @__PURE__ */t(Q,{label:ie("更多"),groups:[{items:[{value:"outline",label:ie(ze?"隐藏文字大纲":"显示文字大纲")},{value:"details",label:ie("主题属性")},...le.comments&&ln?[{value:"comments",label:ie(tt?"隐藏主题讨论":"主题讨论")}]:[],...ce?[{value:"import",label:ie("导入")}]:[]]}],onSelect:e=>{"outline"===e?Le(!ze):"details"===e?(et(!Ze),nt(!1)):"comments"===e?(nt(!tt),et(!1)):"import"===e&&pt(!0)}}),on&&/* @__PURE__ */t(X,{label:ie("导出"),ariaLabel:ie("导出思维导图"),width:105,value:"",disabled:Re,onChange:e=>{exportAs(e)},options:[{value:"png",label:ie("PNG 图片")},{value:"svg",label:ie("SVG 图片")},{value:"md",label:ie("文字大纲")},{value:"json",label:ie("结构 JSON")}]})]})]}),Fe&&/* @__PURE__ */e("div",{className:"mind-search","aria-label":ie("图内查找替换"),children:[
|
|
101
|
+
/* @__PURE__ */t("input",{"aria-label":ie("查找导图文字"),placeholder:ie("查找主题、描述和备注"),value:He,onChange:e=>{Ye(e.target.value),Je(0)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),jumpHit(1))}}),
|
|
102
102
|
/* @__PURE__ */t("span",{children:ne.t("mind.matches",{count:en.length>5e3?"5000+":en.length})}),
|
|
103
103
|
/* @__PURE__ */t(Y,{disabled:!en.length,onClick:()=>jumpHit(-1),children:ie("上一处")}),
|
|
104
|
-
/* @__PURE__ */t(Y,{disabled:!en.length,onClick:()=>jumpHit(1),children:ie("下一处")}),en.length>0&&/* @__PURE__ */t(
|
|
105
|
-
/* @__PURE__ */t("input",{"aria-label":ie("替换为"),placeholder:ie("替换为"),value:
|
|
106
|
-
/* @__PURE__ */t(Y,{disabled:!en.length,onClick:()=>{const e=null==ae?void 0:ae.replace(
|
|
107
|
-
/* @__PURE__ */t(Y,{disabled:!en.length,onClick:()=>{const e=null==ae?void 0:ae.replace(
|
|
108
|
-
/* @__PURE__ */t(Y,{variant:"text",onClick:()=>
|
|
104
|
+
/* @__PURE__ */t(Y,{disabled:!en.length,onClick:()=>jumpHit(1),children:ie("下一处")}),en.length>0&&/* @__PURE__ */t(X,{label:ie("导图搜索结果"),ariaLabel:ie("导图搜索结果"),width:180,value:qe,options:en.slice(0,500).map((e,t)=>{var n,i;return{value:t,label:`${t+1}. ${(null==(i=null==(n=Ht.find(t=>t.id===e.id))?void 0:n.text)?void 0:i.slice(0,24))??""} · ${"title"===e.field?ie("标题"):"note"===e.field?ie("备注"):ie("描述")}`}}),onChange:e=>{const t=Number(e),n=en[t];n&&(Je(t),locateHit(n))}}),ce&&/* @__PURE__ */e(n,{children:[
|
|
105
|
+
/* @__PURE__ */t("input",{"aria-label":ie("替换为"),placeholder:ie("替换为"),value:Oe,onChange:e=>Xe(e.target.value)}),
|
|
106
|
+
/* @__PURE__ */t(Y,{disabled:!en.length,onClick:()=>{const e=null==ae?void 0:ae.replace(He,Oe,en[qe]);at(-1===e?ie("匹配超过 5000 处,请缩小查找范围"):-2===e?ie("替换后文字超过上限,本次未修改"):ie("已替换 {0} 处",{0:e??0}))},children:ie("替换当前")}),
|
|
107
|
+
/* @__PURE__ */t(Y,{disabled:!en.length,onClick:()=>{const e=null==ae?void 0:ae.replace(He,Oe);at(-1===e?ie("匹配超过 5000 处,请缩小查找范围"):-2===e?ie("替换后文字超过上限,本次未修改"):ie("已替换 {0} 处",{0:e??0}))},children:ie("全部替换")})]}),
|
|
108
|
+
/* @__PURE__ */t(Y,{variant:"text",onClick:()=>Ge(!1),children:ie("关闭")})]}),
|
|
109
109
|
/* @__PURE__ */e("div",{className:"mind-canvas-body",children:[ze&&/* @__PURE__ */t("aside",{className:"mind-canvas-outline","aria-label":ie("导图文字大纲"),children:g(de).map(n=>/* @__PURE__ */e("div",{className:"mind-outline-row"+(n.id===he?" current":""),style:{paddingLeft:8+14*Math.min(12,n.depth)},children:[ce?/* @__PURE__ */t(MindMapField,{id:n.id,field:"title",value:n.text,controller:ae,label:ie("大纲主题 {0}",{0:n.text||ie("未命名")}),onFocus:()=>{pe(n.id),me(/* @__PURE__ */new Set([n.id]))},onCommand:e=>{"Tab"===e.key?(e.preventDefault(),null==ae||ae.indent(n.id,e.shiftKey)):"Enter"!==e.key||e.shiftKey||(e.preventDefault(),add("sibling",void 0,n.id))}}):/* @__PURE__ */t("button",{type:"button",onClick:()=>locate(n.id),children:n.text}),
|
|
110
110
|
/* @__PURE__ */t("button",{type:"button",title:ie("定位主题"),"aria-label":ie("定位大纲主题:{0}",{0:n.text}),onClick:()=>locate(n.id),children:"⌖"})]},n.id))}),
|
|
111
|
-
/* @__PURE__ */e("div",{ref:Bt,tabIndex:0,"aria-label":ie("思维导图画布"),className:`mind-canvas-stage${Pe?"":" mind-grid-hidden"}${Se||Te?" mind-space-pan":""}`,onPointerDown:e=>pointerDown(e),onPointerMove:function pointerMove(e){const t=Wt.current;if(t)if(t.doc===JSON.stringify(Jt.current.model)){if("pan"===t.kind){const n=e.clientX-t.lastX,i=e.clientY-t.lastY;Ie(e=>({x:e.x+n,y:e.y+i}))}else if("box"===t.kind){const n=point(t.x,t.y),i=point(e.clientX,e.clientY);t.box={x:Math.min(n.x,i.x),y:Math.min(n.y,i.y),w:Math.abs(i.x-n.x),h:Math.abs(i.y-n.y)},St(t.box),me(topicsInMarquee(
|
|
111
|
+
/* @__PURE__ */e("div",{ref:Bt,tabIndex:0,"aria-label":ie("思维导图画布"),className:`mind-canvas-stage${Pe?"":" mind-grid-hidden"}${Se||Te?" mind-space-pan":""}`,onPointerDown:e=>pointerDown(e),onPointerMove:function pointerMove(e){const t=Wt.current;if(t)if(t.doc===JSON.stringify(Jt.current.model)){if("pan"===t.kind){const n=e.clientX-t.lastX,i=e.clientY-t.lastY;Ie(e=>({x:e.x+n,y:e.y+i}))}else if("box"===t.kind){const n=point(t.x,t.y),i=point(e.clientX,e.clientY);t.box={x:Math.min(n.x,i.x),y:Math.min(n.y,i.y),w:Math.abs(i.x-n.x),h:Math.abs(i.y-n.y)},St(t.box),me(topicsInMarquee(Xt.nodes,{x:t.box.x,y:t.box.y,width:t.box.w,height:t.box.h},t.additive?t.selected:[]))}else ce&&t.id&&t.id!==de.rootId&&1===t.count&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>8&&(t.drop=function mindMapDrop(e,t,n,i,l=!0){const o=t.nodes.find(e=>e.id===n),a=t.nodes.find(t=>t.id===e.rootId);if(!o||!a||n===e.rootId)return null;const r=W(e,n),{x:d,y:c}=i,s=t.nodes.filter(e=>!r.has(e.id)).map(e=>({t:e,distance:Math.hypot(d-e.x-e.width/2,c-e.y-e.height/2)})).sort((e,t)=>e.distance-t.distance)[0],u=d<a.x+a.width/2-24?-1:d>a.x+a.width/2+24?1:null,m=l&&"down"!==e.layout&&null!==u&&u!==o.side;if(s&&s.t.id!==a.id&&d>=s.t.x-18&&d<=s.t.x+s.t.width+18&&c>=s.t.y-18&&c<=s.t.y+s.t.height+18||!m&&s&&s.distance<Math.max(s.t.width,130))return{kind:"node",id:s.t.id,mode:s.t.id===a.id?"child":c<s.t.y+10?"before":c>s.t.y+s.t.height-10?"after":"child"};if(l&&"down"!==e.layout&&null!==u&&(m||o.parentId===a.id&&"both"===e.layout)){const e=t.nodes.filter(e=>e.parentId===a.id&&e.id!==n&&e.side===u).find(e=>c<e.y+e.height/2);return{kind:"side",id:a.id,mode:"side",side:u,...e?{beforeId:e.id}:{}}}return null}(Ot,Xt,t.id,point(e.clientX,e.clientY),!rt),Dt(t.drop),Tt({id:t.id,dx:(e.clientX-t.x)/ke,dy:(e.clientY-t.y)/ke}));t.lastX=e.clientX,t.lastY=e.clientY}else cancelGesture()},onPointerUp:function pointerUp(){const e=Wt.current;if(!e)return;if(cancelGesture(!1),e.doc!==JSON.stringify(Jt.current.model))return;const t=e.box;if("box"===e.kind&&t){const n=topicsInMarquee(Xt.nodes,{x:t.x,y:t.y,width:t.w,height:t.h},e.additive?e.selected:[]);me(n),n.size&&pe([...n].at(-1))}else"node"===e.kind&&e.id&&e.drop&&ce?"side"===e.drop.kind?null==ae||ae.moveToSide(e.id,e.drop.side,e.drop.beforeId):null==ae||ae.move(e.id,e.drop.id,e.drop.mode):"node"===e.kind&&e.id&&e.count>1&&!e.additive&&Math.hypot(e.lastX-e.x,e.lastY-e.y)<8&&(me(/* @__PURE__ */new Set([e.id])),pe(e.id))},onPointerCancel:()=>cancelGesture(),onLostPointerCapture:()=>cancelGesture(),onContextMenu:e=>{var t;openContextMenu((null==(t=e.target.closest("[data-topic-id]"))?void 0:t.dataset.topicId)??null,e)},onWheel:e=>{if(Qe(null),e.ctrlKey||e.metaKey){const t=Bt.current.getBoundingClientRect();zoomTo(ke*Math.exp(.002*-e.deltaY),{x:e.clientX-t.left,y:e.clientY-t.top})}else Ie(t=>({x:t.x-e.deltaX,y:t.y-e.deltaY}))},children:[
|
|
112
112
|
/* @__PURE__ */t("div",{className:"mind-canvas-surface",children:/* @__PURE__ */e("div",{className:"mind-canvas-layers",style:{transform:`translate(${Ne.x}px,${Ne.y}px) scale(${ke})`},children:[
|
|
113
|
-
/* @__PURE__ */e("svg",{className:"mind-canvas-edges",children:[
|
|
113
|
+
/* @__PURE__ */e("svg",{className:"mind-canvas-edges",children:[Xt.edges.map(e=>/* @__PURE__ */t("path",{d:e.path,className:Vt.has(e.target)?"mind-drag-branch-edge":void 0,stroke:qt,strokeWidth:2,fill:"none"},e.id)),b(de,Xt).map(n=>/* @__PURE__ */e("g",{children:[
|
|
114
114
|
/* @__PURE__ */t("path",{d:n.path,stroke:"#9a68d4",strokeWidth:2,strokeDasharray:"6 4",fill:"none"}),
|
|
115
115
|
/* @__PURE__ */t("text",{x:n.x,y:n.y,fill:"var(--color-text)",fontSize:12,children:n.label||{related:ie("相关"),depends:ie("依赖"),reference:ie("参考")}[n.kind]})]},n.id)),Zt&&/* @__PURE__ */e("g",{className:"mind-side-projection",children:[Zt.edges.filter(e=>Vt.has(e.source)||Vt.has(e.target)).map(e=>/* @__PURE__ */t("path",{d:e.path,stroke:qt,fill:"none",strokeWidth:2,strokeDasharray:"5 4"},e.id)),Zt.nodes.filter(e=>Vt.has(e.id)).map(n=>/* @__PURE__ */e("g",{children:[
|
|
116
116
|
/* @__PURE__ */t("rect",{x:n.x,y:n.y,width:n.width,height:n.height,rx:8,fill:"var(--color-accent-soft)",stroke:qt,strokeDasharray:"5 4"}),
|
|
117
|
-
/* @__PURE__ */t("text",{x:n.x+n.width/2,y:n.y+n.height/2+5,textAnchor:"middle",fontSize:14,fill:"var(--color-text)",children:n.text.slice(0,24)})]},n.id))]})]}),
|
|
117
|
+
/* @__PURE__ */t("text",{x:n.x+n.width/2,y:n.y+n.height/2+5,textAnchor:"middle",fontSize:14,fill:"var(--color-text)",children:n.text.slice(0,24)})]},n.id))]})]}),Xt.nodes.map(i=>{const o=Ht.some(e=>e.parentId===i.id),a=_e&&!Se&&!Te&&!Et&&!It&&ce&&ue.has(i.id)&&1===ue.size&&ve!==i.id,r=i.side??1,d="down"===de.layout?"grows-down":-1===r?"grows-left":"";/* @__PURE__ */
|
|
118
118
|
return e("div",{"data-topic-id":i.id,className:`mind-topic-shell${i.id===de.rootId?" root":""}${ue.has(i.id)?" is-selected":""}${o?" has-children":""}${d?` ${d}`:""}${we.has(i.id)?" is-collapsed":""}`,style:{position:"absolute",left:i.x,top:i.y,width:i.width,height:i.height,transform:Et&&Vt.has(i.id)?`translate(${Et.dx}px,${Et.dy}px)`:void 0,opacity:Et&&Vt.has(i.id)?.35:void 0},children:[
|
|
119
119
|
/* @__PURE__ */e("div",{className:`mind-topic${i.id===de.rootId?" root":""}${ue.has(i.id)?" active":""}${ve===i.id?" editing":""}${d?` ${d}`:""}${(null==Mt?void 0:Mt.id)===i.id?` drop mind-drop-${Mt.mode}`:""}`,style:{width:"100%",minHeight:i.height,fontFamily:S,"--mind-topic-line-height":`${I(i.fontSize||14)}px`,color:i.color||("text"===i.shape?"var(--color-text)":i.background?M(i.background):void 0),background:"text"===i.shape?"transparent":i.background||void 0,borderRadius:"pill"===i.shape?28:void 0,border:"text"===i.shape?0:void 0,fontSize:i.fontSize||14,textAlign:i.align||"center"},onPointerDown:e=>{e.stopPropagation(),pointerDown(e,i.id)},onDoubleClick:()=>edit(i.id),onContextMenu:e=>openContextMenu(i.id,e),children:[(i.icon||i.done)&&/* @__PURE__ */e("span",{className:"mind-topic-icon",children:[i.done?"☑ ":"",i.icon]}),ve===i.id?/* @__PURE__ */t("textarea",{ref:Rt,className:"mind-topic-input","aria-label":ie("主题文字"),rows:Math.max(1,i.lines.length),maxLength:2e3,value:ge,onChange:e=>{(null==ae?void 0:ae.text(i.id,e.target.value))&&be(e.target.value)},onSelect:e=>{const t=e.currentTarget;lt({from:t.selectionStart??0,to:t.selectionEnd??0})},onKeyUp:e=>{const t=e.currentTarget;lt({from:t.selectionStart??0,to:t.selectionEnd??0})},onCompositionStart:()=>{ye.current=!0,null==ae||ae.composition(!0)},onCompositionEnd:e=>{null==ae||ae.text(i.id,e.currentTarget.value),ye.current=!1,null==ae||ae.composition(!1),null==ae||ae.beginText(i.id)},onKeyDown:e=>{if(e.stopPropagation(),!e.nativeEvent.isComposing&&!ye.current&&229!==e.keyCode)return(e.metaKey||e.ctrlKey)&&["z","y"].includes(e.key.toLowerCase())?(e.preventDefault(),void(e.shiftKey||"y"===e.key.toLowerCase()?null==ae||ae.redo():null==ae||ae.undo())):void("Escape"===e.key||"Enter"===e.key&&!e.shiftKey?(e.preventDefault(),edit(null)):"Tab"===e.key&&(e.preventDefault(),null==ae||ae.endText(i.id),add("child",void 0,i.id)))},onBlur:()=>{null==ae||ae.composition(!1),null==ae||ae.endText(i.id),fe(null)}}):/* @__PURE__ */t("div",{className:"mind-topic-label",style:{textAlign:i.align||"center",minHeight:i.lines.length*I(i.fontSize||14)},children:/* @__PURE__ */t(J,{topic:i})}),i.description&&/* @__PURE__ */t("div",{className:"mind-topic-description",style:"text"===i.shape?{color:"var(--color-text-muted)"}:i.background?{color:M(i.background)}:void 0,children:i.description}),i.note&&/* @__PURE__ */t("div",{className:"mind-topic-note",title:ie("此主题有备注"),onClick:e=>{e.stopPropagation(),select(i.id),et(!0)},children:ie("▤ 备注")}),i.attachmentId&&/* @__PURE__ */t("div",{className:"mind-topic-image",children:/* @__PURE__ */t(V,{id:i.attachmentId,alt:ie("主题图片"),fetcher:l.fetchAttachment})}),un.filter(e=>e.topicId===i.id).map(e=>/* @__PURE__ */t("span",{className:"mind-peer-badge",title:`${e.name}${e.editing?" 正在编辑":""}`,"aria-label":`${e.name}${e.editing?" 正在编辑此主题":" 正在查看此主题"}`,children:e.name.slice(0,2)},e.client))]}),a&&i.id!==de.rootId&&/* @__PURE__ */t("button",{type:"button",className:"mind-topic-sibling before","aria-label":"down"===de.layout?ie("在左侧添加同级主题"):ie("在上方添加同级主题"),title:"down"===de.layout?ie("在左侧添加同级主题"):ie("在上方添加同级主题"),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),addSiblingAt(i.id,"before")},children:/* @__PURE__ */t("span",{"aria-hidden":"true",children:"+"})}),a&&i.id===de.rootId&&"down"!==de.layout&&/* @__PURE__ */e(n,{children:[
|
|
120
120
|
/* @__PURE__ */t("button",{type:"button",className:"mind-topic-add root-left","aria-label":ie("在中心主题左侧添加子主题"),title:ie("在左侧添加子主题"),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),add("child",-1)},children:"+"}),
|
|
@@ -149,15 +149,15 @@ return e("div",{"data-topic-id":i.id,className:`mind-topic-shell${i.id===de.root
|
|
|
149
149
|
/* @__PURE__ */e("kbd",{children:[bn,ie("+鼠标滚轮")]}),
|
|
150
150
|
/* @__PURE__ */t("kbd",{children:ie("捏合手势")})]}),children:/* @__PURE__ */t(Y,{"aria-label":ie("放大导图"),onClick:()=>paneCommand("zoom-in"),children:"+"})}),
|
|
151
151
|
/* @__PURE__ */t(WTooltip,{content:/* @__PURE__ */e("span",{className:"mind-viewport-tip",children:[ie("画布全览")," ",
|
|
152
|
-
/* @__PURE__ */t("kbd",{children:"Shift+1"})]}),children:/* @__PURE__ */t(Y,{onClick:()=>paneCommand("fit"),children:ie("适应画布")})})]})]}),(ot||Mt)&&/* @__PURE__ */t("p",{className:"mind-canvas-notice",role:"status",children:Mt?"side"===Mt.kind?`松开后移到中心主题${-1===Mt.side?ie("左"):ie("右")}侧,保留整条子分支`:ie("松开后{0}",{0:"child"===Mt.mode?"移入目标主题":"before"===Mt.mode?"放到目标上方":"放到目标下方"}):ot})]}),tt&&ln&&le.comments&&/* @__PURE__ */t(MindMapComments,{pageId:ln,blockId:de.id,topicId:he,topicLabel:Yt.text,canComment:l.canComment??(null==(te=null==ae?void 0:(ee=ae.context).canComment)?void 0:te.call(ee)),onClose:()=>nt(!1),onChanged:l.onCommentsChanged},`${ln}:${de.id}:${he}`),Ze&&/* @__PURE__ */t(MindMapDetails,{model:de,id:he,controller:ae,range:it,onClose:()=>et(!1),onNotice:at},he)]}),zt&&oe&&
|
|
152
|
+
/* @__PURE__ */t("kbd",{children:"Shift+1"})]}),children:/* @__PURE__ */t(Y,{onClick:()=>paneCommand("fit"),children:ie("适应画布")})})]})]}),(ot||Mt)&&/* @__PURE__ */t("p",{className:"mind-canvas-notice",role:"status",children:Mt?"side"===Mt.kind?`松开后移到中心主题${-1===Mt.side?ie("左"):ie("右")}侧,保留整条子分支`:ie("松开后{0}",{0:"child"===Mt.mode?"移入目标主题":"before"===Mt.mode?"放到目标上方":"放到目标下方"}):ot})]}),tt&&ln&&le.comments&&/* @__PURE__ */t(MindMapComments,{pageId:ln,blockId:de.id,topicId:he,topicLabel:Yt.text,canComment:l.canComment??(null==(te=null==ae?void 0:(ee=ae.context).canComment)?void 0:te.call(ee)),onClose:()=>nt(!1),onChanged:l.onCommentsChanged},`${ln}:${de.id}:${he}`),Ze&&/* @__PURE__ */t(MindMapDetails,{model:de,id:he,controller:ae,range:it,onClose:()=>et(!1),onNotice:at},he)]}),zt&&oe&&G(/* @__PURE__ */t("div",{ref:Pt,className:"mind-context-menu",role:"menu",tabIndex:-1,"aria-label":zt.id?ie("主题操作菜单"):ie("画布操作菜单"),onKeyDown:function menuKeydown(e){var t,n;const i=Array.from((null==(t=Pt.current)?void 0:t.querySelectorAll('[role="menuitem"]:not([aria-disabled="true"])'))??[]);if(!i.length||!["ArrowDown","ArrowUp","Home","End"].includes(e.key))return;e.preventDefault(),e.stopPropagation();const l=i.indexOf(document.activeElement);null==(n=i["Home"===e.key?0:"End"===e.key?i.length-1:l<0?"ArrowUp"===e.key?i.length-1:0:(l+("ArrowUp"===e.key?-1:1)+i.length)%i.length])||n.focus()},style:{left:zt.x,top:zt.y},children:/* @__PURE__ */t("div",{className:"w-dropdown",children:yn.map((n,i)=>/* @__PURE__ */e("div",{className:"w-dropdown-group",role:"group","aria-label":n.title,children:[n.title&&/* @__PURE__ */t("div",{className:"w-dropdown-group__title",children:n.title}),n.items.map(n=>/* @__PURE__ */e("div",{role:"menuitem",tabIndex:n.disabled?void 0:-1,"aria-disabled":n.disabled||void 0,className:"w-dropdown-option"+(n.disabled?" is-disabled":""),onClick:()=>{n.disabled||contextAction(n.value)},onKeyDown:e=>{n.disabled||"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),contextAction(n.value))},children:["string"==typeof n.label?ie(n.label):n.label,n.shortcut&&/* @__PURE__ */t("span",{className:"mind-menu-key",children:n.shortcut})]},n.value))]},i))})}),oe),ct&&/* @__PURE__ */e(O,{title:ie("删除分支"),onClose:()=>{var e;st(null),null==(e=Bt.current)||e.focus()},children:[
|
|
153
153
|
/* @__PURE__ */t("p",{children:ne.t("mind.deleteConfirm",{count:ct.ids.size})}),
|
|
154
154
|
/* @__PURE__ */e("div",{className:"wr-toolbar",children:[
|
|
155
155
|
/* @__PURE__ */t(Y,{onClick:()=>{var e;st(null),null==(e=Bt.current)||e.focus()},children:ie("取消")}),
|
|
156
|
-
/* @__PURE__ */t(Y,{variant:"primary",onClick:()=>performDelete(ct),children:ie("删除分支")})]})]}),ht&&/* @__PURE__ */e(
|
|
156
|
+
/* @__PURE__ */t(Y,{variant:"primary",onClick:()=>performDelete(ct),children:ie("删除分支")})]})]}),ht&&/* @__PURE__ */e(O,{title:ie("导入导图或列表"),onClose:()=>pt(!1),footer:/* @__PURE__ */e(n,{children:[
|
|
157
157
|
/* @__PURE__ */t(Y,{onClick:()=>pt(!1),children:ie("取消")}),
|
|
158
158
|
/* @__PURE__ */t(Y,{variant:"primary",loading:At,disabled:!tn,onClick:()=>{!$t.current&&tn&&($t.current=!0,_t(!0),bt(""),(async()=>{try{await insertBranch(A(tn),he),Kt.current&&pt(!1)}catch(e){Kt.current&&bt(e instanceof Error?e.message:ie("导入失败"))}finally{$t.current=!1,Kt.current&&_t(!1)}})())},children:ie("导入分支")})]}),children:[
|
|
159
159
|
/* @__PURE__ */t("p",{className:"mind-import-hint",children:ie("导入为当前主题的子分支;支持 JSON 和缩进列表。不会替换现有导图。")}),
|
|
160
160
|
/* @__PURE__ */t("input",{"aria-label":ie("选择导图文件"),type:"file",accept:".json,.md,.txt",onChange:e=>{var t;const n=null==(t=e.target.files)?void 0:t[0];n&&(n.size>2e6?bt(ie("文件超过 2 MB")):n.text().then(e=>{Kt.current&&(ft(e),bt(""))}).catch(()=>{Kt.current&&bt(ie("文件读取失败"))}))}}),
|
|
161
161
|
/* @__PURE__ */t("textarea",{"aria-label":ie("导入内容"),rows:10,placeholder:ie("粘贴缩进列表或导图 JSON"),style:{marginTop:12},value:vt,onChange:e=>{ft(e.target.value),bt("")}}),tn&&/* @__PURE__ */t("p",{children:ne.t("mind.detected",{count:tn.topics.length})}),gt&&/* @__PURE__ */t("p",{role:"alert",children:gt}),
|
|
162
|
-
/* @__PURE__ */t("div",{className:"wr-toolbar",children:["project","meeting","knowledge"].map((e,n)=>/* @__PURE__ */t(Y,{onClick:()=>{const t=null==ae?void 0:ae.pasteBranch(he,A(_(e)));t&&(select(t),pt(!1))},children:[ie("项目模板"),ie("会议模板"),ie("知识模板")][n]},e))})]})]});return l.inline?/* @__PURE__ */t("section",{className:"mind-canvas-shell mind-inline",children:wn}):/* @__PURE__ */t(
|
|
162
|
+
/* @__PURE__ */t("div",{className:"wr-toolbar",children:["project","meeting","knowledge"].map((e,n)=>/* @__PURE__ */t(Y,{onClick:()=>{const t=null==ae?void 0:ae.pasteBranch(he,A(_(e)));t&&(select(t),pt(!1))},children:[ie("项目模板"),ie("会议模板"),ie("知识模板")][n]},e))})]})]});return l.inline?/* @__PURE__ */t("section",{className:"mind-canvas-shell mind-inline",children:wn}):/* @__PURE__ */t(O,{workspace:!0,fullscreen:!0,hideFooter:!0,className:"mind-canvas-shell mind-canvas-fullscreen",ariaLabel:ie("思维导图"),title:/* @__PURE__ */e("span",{className:"mind-canvas-title",children:[ie("思维导图")," ",
|
|
163
163
|
/* @__PURE__ */t("span",{children:an})]}),escToClose:!(ve||zt||Ke||ht||ct),onClose:()=>{var e;return null==(e=l.onClose)?void 0:e.call(l)},children:wn})}export{MindMapCanvas};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use client";import{jsx as e,jsxs as t}from"react/jsx-runtime";import{c as n,b as i}from"./i18n-B0kCsIjc.js";import{useState as o,useEffect as a,Suspense as d,useRef as l,lazy as r}from"react";import{readMindMap as s,mindMapOutline as c,MIND_MAP_PALETTE as h,layoutMindMap as m,mindRelationPaths as p}from"wendang/mindmap";import{MIND_TOPIC_FONT as u,mindTopicLineHeight as v,readableTextColor as w}from"wendang/shared";import{a as f}from"./index-COeA2QcQ.js";import{T as g,A as b}from"./mind-topic-text-
|
|
1
|
+
"use client";import{jsx as e,jsxs as t}from"react/jsx-runtime";import{c as n,b as i}from"./i18n-B0kCsIjc.js";import{useState as o,useEffect as a,Suspense as d,useRef as l,lazy as r}from"react";import{readMindMap as s,mindMapOutline as c,MIND_MAP_PALETTE as h,layoutMindMap as m,mindRelationPaths as p}from"wendang/mindmap";import{MIND_TOPIC_FONT as u,mindTopicLineHeight as v,readableTextColor as w}from"wendang/shared";import{a as f}from"./index-COeA2QcQ.js";import{T as g,A as b}from"./mind-topic-text-C7pIS6L9.js";const x=r(()=>import("./MindMapCanvas-BA3FYy8p.js").then(e=>({default:e.MindMapCanvas})));function MindMapViewer({value:i,modelValue:d,height:r,fetchAttachment:s}){var c;const f=n().text,x=i??d,k=l(null),[C,M]=o(900);if(a(()=>{const e=k.current;if(!e||"undefined"==typeof ResizeObserver)return;M(e.clientWidth||900);const t=new ResizeObserver(e=>{var t;return M((null==(t=e[0])?void 0:t.contentRect.width)||900)});return t.observe(e),()=>t.disconnect()},[]),!x)/* @__PURE__ */return e("p",{role:"alert",children:f("思维导图格式无效")});const y=m(x),N=p(x,y),I=h[x.theme],S=r??x.height,A=Math.min(1,(S-30)/y.bounds.height,Math.max(100,C-24)/y.bounds.width);/* @__PURE__ */
|
|
2
2
|
return e("div",{ref:k,className:"mind-preview-wrap",style:{height:S},role:"group","aria-label":(null==(c=x.topics.find(e=>e.id===x.rootId))?void 0:c.text)||f("思维导图"),children:/* @__PURE__ */e("div",{className:"mind-preview-sized",style:{width:y.bounds.width*A,height:y.bounds.height*A},children:/* @__PURE__ */t("div",{className:"mind-preview-scene",style:{width:y.bounds.width,height:y.bounds.height,transform:`scale(${A})`},children:[
|
|
3
3
|
/* @__PURE__ */t("svg",{className:"mind-preview-lines",width:y.bounds.width,height:y.bounds.height,viewBox:`${y.bounds.x} ${y.bounds.y} ${y.bounds.width} ${y.bounds.height}`,children:[y.edges.map(t=>/* @__PURE__ */e("path",{d:t.path,fill:"none",stroke:I,strokeWidth:2},t.id)),N.map(n=>/* @__PURE__ */t("g",{children:[
|
|
4
4
|
/* @__PURE__ */e("path",{d:n.path,fill:"none",stroke:"#9a68d4",strokeWidth:2,strokeDasharray:"6 4"}),
|