@fgbg/mdocs 1.3.22 → 1.3.23

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.
Files changed (50) hide show
  1. package/README.md +1 -1
  2. package/agent-skills/changelog/SKILL.md +13 -0
  3. package/agent-skills/getting-started-installation/SKILL.md +8 -2
  4. package/dist/server/agent/Agent/session-manager.js +354 -144
  5. package/dist/server/agent/Agent/session-manager.js.map +1 -1
  6. package/dist/server/agent/Agent/session-manager.queue.test.js +65 -0
  7. package/dist/server/agent/Agent/session-manager.queue.test.js.map +1 -0
  8. package/dist/server/agent/Agent/session-meta-lock.js +73 -0
  9. package/dist/server/agent/Agent/session-meta-lock.js.map +1 -0
  10. package/dist/server/agent/Agent/session-meta-lock.test.js +44 -0
  11. package/dist/server/agent/Agent/session-meta-lock.test.js.map +1 -0
  12. package/dist/server/agent/Agent/session-repair.test.js +40 -0
  13. package/dist/server/agent/Agent/session-repair.test.js.map +1 -0
  14. package/dist/server/cli/main.js +73 -0
  15. package/dist/server/cli/main.js.map +1 -1
  16. package/dist/server/config/index.js +2 -1
  17. package/dist/server/config/index.js.map +1 -1
  18. package/dist/server/main.js +6 -0
  19. package/dist/server/main.js.map +1 -1
  20. package/dist/server/search/embedding-model.js +33 -11
  21. package/dist/server/search/embedding-model.js.map +1 -1
  22. package/dist/web/assets/{AgentChatPanel-BZlAgyrV.js → AgentChatPanel-CXCoVr71.js} +3 -3
  23. package/dist/web/assets/{AgentSkillFormCard-CzJG8FK4.js → AgentSkillFormCard-BokYfssA.js} +1 -1
  24. package/dist/web/assets/{AiWriteWorkbench-DiSDDAee.js → AiWriteWorkbench-BLYRPfhm.js} +1 -1
  25. package/dist/web/assets/{DiagramEditor-NtNY3sZL-DfkpQX3P.js → DiagramEditor-NtNY3sZL-uAUfkpbp.js} +1 -1
  26. package/dist/web/assets/DocumentEditor-C7eEw_Gh.js +1 -0
  27. package/dist/web/assets/HtmlEditor-B8hAvriH.js +1 -0
  28. package/dist/web/assets/{MergeView-CbFSN3Bi.js → MergeView-3RaowcU-.js} +1 -1
  29. package/dist/web/assets/{PlaygroundPage-DuMH_V-7.js → PlaygroundPage-Bc54r4cU.js} +1 -1
  30. package/dist/web/assets/{SettingsPage-C_RMO-5M.js → SettingsPage-hnisLfn5.js} +1 -1
  31. package/dist/web/assets/{Toolbar-D9FcRwg3.js → Toolbar-D0IqMu2I.js} +1 -1
  32. package/dist/web/assets/{VisitorPickerModal-CM13Y6jQ.js → VisitorPickerModal-C31LXFbB.js} +1 -1
  33. package/dist/web/assets/{check-Bf8YbzH7.js → check-CmDfmXpb.js} +1 -1
  34. package/dist/web/assets/{copy-SBghRY2T.js → copy-CeksexKY.js} +1 -1
  35. package/dist/web/assets/{diagram-CgEd0hrk.js → diagram-BF8g9yg4.js} +3 -3
  36. package/dist/web/assets/docPlainCharCount-D3z2Ee8P.js +21 -0
  37. package/dist/web/assets/{editor-CL03se2B.js → editor-DBWWidi3.js} +1 -1
  38. package/dist/web/assets/{index-Cwy87sZC.js → index-3-Dt0Ns3.js} +5 -5
  39. package/dist/web/assets/{meta2d-1-g23JOU.js → meta2d-DP4Vt_ZE.js} +1 -1
  40. package/dist/web/assets/{meta2dEngine-BD2XbzaV-ulfRZEvk.js → meta2dEngine-BD2XbzaV-CFDBvzS1.js} +1 -1
  41. package/dist/web/assets/{motion-Dyy8pB0Q.js → motion-BAXVQJfN.js} +1 -1
  42. package/dist/web/assets/{plus-CEapsZwl.js → plus-Vt2TO_HW.js} +1 -1
  43. package/dist/web/assets/{react-vendor-BuABiQkA.js → react-vendor-BVS1XoFi.js} +1 -1
  44. package/dist/web/assets/{react-BkX5Koku.js → react-zRau5ppr.js} +171 -168
  45. package/dist/web/assets/{ui-ZPt_BNBg.js → ui-CEFkTVnG.js} +200 -181
  46. package/dist/web/index.html +5 -5
  47. package/package.json +2 -2
  48. package/dist/web/assets/DocChrome-QTGER_Af.js +0 -21
  49. package/dist/web/assets/DocumentEditor-DYSRZnJa.js +0 -1
  50. package/dist/web/assets/HtmlEditor-oDPrhq3o.js +0 -1
@@ -27,11 +27,11 @@
27
27
  opacity: 0.65;
28
28
  }
29
29
  </style>
30
- <script type="module" crossorigin src="/assets/index-Cwy87sZC.js"></script>
31
- <link rel="modulepreload" crossorigin href="/assets/react-vendor-BuABiQkA.js">
32
- <link rel="modulepreload" crossorigin href="/assets/motion-Dyy8pB0Q.js">
33
- <link rel="modulepreload" crossorigin href="/assets/ui-ZPt_BNBg.js">
34
- <link rel="modulepreload" crossorigin href="/assets/diagram-CgEd0hrk.js">
30
+ <script type="module" crossorigin src="/assets/index-3-Dt0Ns3.js"></script>
31
+ <link rel="modulepreload" crossorigin href="/assets/react-vendor-BVS1XoFi.js">
32
+ <link rel="modulepreload" crossorigin href="/assets/motion-BAXVQJfN.js">
33
+ <link rel="modulepreload" crossorigin href="/assets/ui-CEFkTVnG.js">
34
+ <link rel="modulepreload" crossorigin href="/assets/diagram-BF8g9yg4.js">
35
35
  <link rel="stylesheet" crossorigin href="/assets/index-CIgmAX2Q.css">
36
36
  </head>
37
37
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgbg/mdocs",
3
- "version": "1.3.22",
3
+ "version": "1.3.23",
4
4
  "description": "A Markdown knowledge base for small teams",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  "@earendil-works/pi-agent-core": "^0.82.1",
24
24
  "@earendil-works/pi-ai": "^0.82.1",
25
25
  "@lexical/rich-text": "0.42.0",
26
- "@lobehub/editor": "npm:@fgbg/lobe-editor@1.0.0-fork.21",
26
+ "@lobehub/editor": "npm:@fgbg/lobe-editor@1.0.0-fork.22",
27
27
  "@lobehub/ui": "^5.0.0",
28
28
  "@node-rs/jieba": "^2.0.1",
29
29
  "@shikijs/langs": "4.0.2",
@@ -1,21 +0,0 @@
1
- import{o as d,c as v,F as D,P as M,p as x,l as k,R as j,E as B,q as P,S as E,M as S}from"./index-Cwy87sZC.js";import{r as I,j as n}from"./react-vendor-BuABiQkA.js";import{g as W}from"./file-type-policy-GUk904tm.js";/**
2
- * @license lucide-react v0.562.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const w=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],z=d("chevron-up",w);/**
7
- * @license lucide-react v0.562.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const A=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M6.376 18.91a6 6 0 0 1 11.249.003",key:"hnjrf2"}],["circle",{cx:"12",cy:"11",r:"4",key:"1gt34v"}]],L=d("shield-user",A);/**
12
- * @license lucide-react v0.562.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const O=[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],R=d("text-align-justify",O);/**
17
- * @license lucide-react v0.562.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const _=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],$=d("users",_);function q(e){const{t,lang:m}=v(),l=W(e.fileType||"md"),f=!!(l!=null&&l.aiWrite&&e.onAiWrite),C=!!(l!=null&&l.comments&&e.onToggleComments);e.canEdit&&(e.editing||e.actionsAlwaysVisible);const[o,N]=I.useState(!1),r=e.domains.length?e.domains:[D],c="mdocs-editor-toolbar"+(e.readerChrome?e.readerHeaderDocked?" mdocs-editor-toolbar--docked":" mdocs-editor-toolbar--float":""),s=e.readerChrome&&!e.readerHeaderDocked&&e.readerDragOffset?{transform:`translateY(${e.readerDragOffset}px)`}:void 0;if(e.readerChrome){const a=n.jsxs("div",{className:"mdocs-editor-toolbar-leading",onPointerDown:e.onReaderHeaderPointerDown,onPointerMove:e.onReaderHeaderPointerMove,onPointerUp:e.onReaderHeaderPointerUp,onPointerCancel:e.onReaderHeaderPointerUp,children:[n.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>{var i;return(i=e.onOpenMobileNav)==null?void 0:i.call(e)},"aria-label":t("expandSidebar"),children:n.jsx(M,{size:18,strokeWidth:1.75})}),n.jsx("input",{className:"mdocs-editor-title-input",value:e.displayName,onChange:i=>e.onDisplayNameChange(i.target.value),onBlur:e.onDisplayNameBlur,placeholder:t("displayNamePlaceholder"),disabled:!e.editing,readOnly:!e.editing})]}),u=n.jsx(x,{domains:r,value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:t("currentDomainAria"),localizeName:i=>k(i,m,t)}),h=e.canEdit&&e.onPublish?n.jsx("button",{type:"button",className:"primary mdocs-reader-action-btn",disabled:e.busy,onClick:()=>{var i,g;e.editing||(i=e.onEnterEdit)==null||i.call(e),(g=e.onPublish)==null||g.call(e)},children:e.busy?t("publishing"):t("publish")}):null,y=e.onSyncClick?n.jsx("button",{type:"button",className:"mdocs-sync-btn mdocs-reader-sync-btn"+(e.syncBehind?" behind":""),"aria-label":e.syncBehind?t("syncBehindHint"):t("syncPull"),onClick:()=>{var i;return void((i=e.onSyncClick)==null?void 0:i.call(e))},children:n.jsx(j,{size:16,strokeWidth:1.75})}):null,b=e.readerMoreMenu!=null?n.jsxs("div",{ref:e.readerMoreMenuRef,className:"mdocs-reader-more-menu",children:[n.jsx("button",{type:"button",className:"mdocs-reader-more-btn","aria-label":"更多","aria-expanded":e.readerMoreOpen,onClick:()=>{var i;return(i=e.onToggleReaderMore)==null?void 0:i.call(e)},children:n.jsx(B,{size:18,strokeWidth:1.75})}),e.readerMoreOpen?n.jsx("div",{className:"mdocs-reader-more-dropdown card",children:e.readerMoreMenu}):null]}):null;return e.readerActionsCollapsible?n.jsxs("div",{className:c+" mdocs-editor-toolbar--stacked",style:s,children:[n.jsxs("div",{className:"mdocs-reader-top-row",children:[a,y,n.jsx("button",{type:"button",className:"mdocs-reader-expand-btn",onClick:()=>N(i=>!i),"aria-label":o?"收起操作栏":"展开操作栏",children:n.jsx(z,{size:16,strokeWidth:2,style:{transform:o?"rotate(0deg)":"rotate(180deg)",transition:"transform 0.2s"}})}),b]}),o&&n.jsxs("div",{className:"mdocs-reader-actions-row",children:[u,e.leadingExtra,h,e.trailingExtra]})]}):n.jsxs("div",{className:c,style:s,children:[a,u,e.leadingExtra,y,h,b,e.trailingExtra]})}return n.jsxs("div",{className:c,style:s,children:[n.jsxs("div",{className:"mdocs-editor-toolbar-leading",children:[n.jsx("input",{className:"mdocs-editor-title-input",value:e.displayName,onChange:a=>e.onDisplayNameChange(a.target.value),onBlur:e.onDisplayNameBlur,placeholder:t("displayNamePlaceholder"),disabled:!e.editing}),n.jsx(x,{domains:r,value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:t("currentDomainAria"),localizeName:a=>k(a,m,t)}),f?n.jsxs("button",{type:"button",className:"secondary",onClick:()=>{var a;return(a=e.onAiWrite)==null?void 0:a.call(e)},style:{padding:"4px 10px",whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",gap:6},children:[n.jsx("img",{src:P,alt:"",width:16,height:16,style:{display:"block"}}),"帮写"]}):null,e.leadingExtra]}),n.jsx("span",{className:"mdocs-editor-toolbar-spacer","aria-hidden":!0}),n.jsxs("div",{className:"mdocs-editor-toolbar-trailing",children:[e.onToggleBookmark?n.jsxs("button",{type:"button",className:"ghost mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>{var a;return(a=e.onToggleBookmark)==null?void 0:a.call(e)},disabled:e.bookmarkBusy,"data-tooltip":e.isBookmarked?"取消收藏":"收藏",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,opacity:e.bookmarkBusy?.5:1},children:[n.jsx(E,{size:18,strokeWidth:1.5,style:{color:e.isBookmarked?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:e.isBookmarked?"#faad14":"none"}}),e.isBookmarked?n.jsx("span",{children:"已收藏"}):null]}):null,n.jsxs("div",{className:"mdocs-editor-toolbar-actions",children:[e.onSyncClick?n.jsxs("button",{type:"button",className:"mdocs-sync-btn mdocs-tooltip mdocs-tooltip-bottom"+(e.syncBehind?" behind":""),"data-tooltip":e.syncBehind?t("syncBehindHint"):t("syncPull"),onClick:()=>{var a;return void((a=e.onSyncClick)==null?void 0:a.call(e))},style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx(j,{size:16,strokeWidth:1.5}),n.jsx("span",{children:t("syncPull")})]}):null,e.editing?n.jsxs(n.Fragment,{children:[localStorage.getItem("mdocs.autoPublish")!=="true"&&n.jsxs("span",{className:"mdocs-save-indicator",children:[n.jsx("span",{className:"mdocs-save-dot "+(e.busy?"saving":e.draftExists?"unsaved":"saved")}),n.jsx("span",{children:e.busy?t("publishing"):e.draftExists?t("unsaved"):t("published")})]}),e.onPublish?n.jsx("button",{type:"button",className:"primary",disabled:e.busy,onClick:()=>{var a;return(a=e.onPublish)==null?void 0:a.call(e)},children:e.busy?t("publishing"):t("publish")}):null,e.onDelete?n.jsx("button",{type:"button",className:"danger",disabled:e.busy,onClick:()=>{var a;return(a=e.onDelete)==null?void 0:a.call(e)},children:t("delete")}):null]}):null,!e.editing&&e.canEdit&&e.onEnterEdit?n.jsx("button",{type:"button",className:"primary",onClick:()=>{var a;return(a=e.onEnterEdit)==null?void 0:a.call(e)},children:t("edit")}):null,e.trailingExtra,C?n.jsxs("button",{type:"button",className:"ghost mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>{var a;return(a=e.onToggleComments)==null?void 0:a.call(e)},"data-tooltip":"评论",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:e.commentPanelOpen?"var(--mdocs-hover-bg, #f0f0f0)":void 0},children:[n.jsx(S,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}}),e.commentCount&&e.commentCount>0?n.jsx("span",{style:{fontSize:"0.85rem"},children:e.commentCount}):null]}):null,e.onToggleDocInfo?n.jsxs("div",{ref:e.docInfoMenuRef,className:"mdocs-tooltip mdocs-tooltip-bottom","data-tooltip":t("docInfo"),style:{position:"relative"},children:[n.jsx("button",{type:"button",className:"secondary",onClick:()=>{var a;return(a=e.onToggleDocInfo)==null?void 0:a.call(e)},style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:n.jsx(R,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}})}),e.docInfoOpen?n.jsx("div",{className:"mdocs-doc-info-dropdown",children:e.docInfoMenu}):null]}):null]})]})]})}export{q as D,L as S,$ as U};
@@ -1 +0,0 @@
1
- import{r as n,j as a}from"./react-vendor-BuABiQkA.js";import{ad as ge}from"./ui-ZPt_BNBg.js";import{g as be,u as we,a as ye,s as Ue,d as qe,b as ve,c as Ve,f as We,e as Ye,h as Ge,N as Je,S as $e,l as Ke,r as Xe,i as Qe,j as Ze,D as Z,k as pe,m as et,n as xe}from"./index-Cwy87sZC.js";import{z as tt,A as nt,m as se,n as at,o as it,p as rt,r as ot,s as st,t as ct,v as lt,x as ut,B as dt,R as mt,a as ft,b as Ie,c as ht,d as gt,e as yt,f as vt,g as xt,h as It,i as kt,w as ce,j as St,O as Et,E as bt,q as wt,l as Mt,C as Ct,D as Dt}from"./react-BkX5Koku.js";import{H as Rt,a as jt,b as At,M as Nt,T as Pt,S as Tt,W as Bt,o as Lt,c as ke}from"./Toolbar-D9FcRwg3.js";import{D as Ot,U as _t,S as Ht}from"./DocChrome-QTGER_Af.js";import{V as zt}from"./VisitorPickerModal-CM13Y6jQ.js";import"./motion-Dyy8pB0Q.js";import"./diagram-CgEd0hrk.js";import"./editor-CL03se2B.js";import"./plus-CEapsZwl.js";import"./check-Bf8YbzH7.js";import"./copy-SBghRY2T.js";import"./file-type-policy-GUk904tm.js";const Ft=48;function p(e){try{const i=e.getDocument("markdown");return typeof i=="string"?i:""}catch{return null}}function Ut(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function qt({editor:e,documentId:i,displayName:c,debounceMs:I=1e3,enabled:g=!0,localBaseCommitIdAtEditStart:R,snapshotMeta:b,seedDraftExists:z=!1}){const[F,L]=n.useState(!1),[ee,j]=n.useState(z),[A,S]=n.useState(null),d=n.useRef(null),f=n.useRef(null),k=n.useRef(!1),x=n.useRef(""),v=n.useRef(!1),O=n.useRef(i),U=n.useRef(c),N=n.useRef(R),J=n.useRef(b);O.current=i,U.current=c,N.current=R,J.current=b;const E=n.useCallback(async()=>{if(!e)return;if(!x.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const s=Ut(e);s!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",O.current,"content preview:",s.slice(0,80)),await be(O.current).execute(()=>we({documentId:O.current,content:s,displayName:U.current,localBaseCommitIdAtEditStart:N.current,snapshotMeta:J.current})),x.current=p(e)??x.current,j(!0),L(!1),S(Date.now()),k.current=!0,v.current=!1)},[e]);n.useEffect(()=>{let s=!1;const m=ve();return ye(i).then(h=>{if(s||ve()!==m)return;const y=!!(h&&!h.published);j(y),y&&h?(S(h.updatedAt),k.current=!0):(S(null),k.current=!1,v.current=!1)}),()=>{s=!0}},[i]),n.useEffect(()=>Ue((s,m)=>{s===O.current&&(j(m),m||(S(null),k.current=!1))}),[]),n.useEffect(()=>{var H,q;if(!g){(H=f.current)==null||H.call(f),f.current=null;return}if(!e)return;const s=e.getLexicalEditor();if(!s)return;(q=f.current)==null||q.call(f);let m=!1,h=0,y=0;const _=()=>{if(m)return;const P=p(e);if(P===null){if(y+=1,y>Ft)return;h=requestAnimationFrame(_);return}x.current=P;const ne=s.registerUpdateListener(()=>{const M=p(e);M!==null&&M!==x.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",i,"oldLen:",x.current.length,"newLen:",M.length),x.current=M,L(!0),v.current=!0,k.current=!1,d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{d.current=null,E()},I))});f.current=()=>{ne(),d.current&&(clearTimeout(d.current),d.current=null)}};return queueMicrotask(()=>{m||(h=requestAnimationFrame(_))}),()=>{var P;m=!0,cancelAnimationFrame(h),(P=f.current)==null||P.call(f)}},[g,e,i,c,I,R,b,E]),n.useEffect(()=>{var h;if(!g||!e)return;const s=(h=e.getLexicalEditor())==null?void 0:h.getRootElement();if(!s)return;const m=()=>{d.current&&(clearTimeout(d.current),d.current=null),v.current&&E()};return s.addEventListener("blur",m),()=>s.removeEventListener("blur",m)},[g,e,E]),n.useEffect(()=>{if(!g)return;const s=()=>{document.visibilityState==="hidden"&&(d.current&&(clearTimeout(d.current),d.current=null),v.current&&E())},m=()=>{v.current&&(d.current&&(clearTimeout(d.current),d.current=null),E())};return document.addEventListener("visibilitychange",s),window.addEventListener("beforeunload",m),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("beforeunload",m)}},[g,E]);async function $(){await qe(i),j(!1),L(!1),v.current=!1,k.current=!1,x.current=""}async function te(){const s=await ye(i);return s?s.content:null}function w(){j(!0),L(!1),v.current=!1,S(Date.now()),k.current=!0,e&&(x.current=p(e)??"")}return{isDirty:F,draftExists:ee,lastSavedAt:A,clearDraft:$,loadDraftContent:te,markDraftSaved:w}}function Vt({isDirty:e,draftExists:i}){const c=e&&!i;n.useEffect(()=>{if(!c)return;const I=g=>{g.preventDefault()};return window.addEventListener("beforeunload",I),()=>window.removeEventListener("beforeunload",I)},[c])}function le(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const Se='{"root":{"direction":"ltr","format":"","indent":0,"version":1,"type":"root","children":[{"direction":"ltr","format":"","indent":0,"version":1,"textFormat":0,"textStyle":"","children":[],"type":"paragraph"}]}}';function Ee(e){const c=(e instanceof Error?e.message:String(e)).trim();return/^File too large$/i.test(c)?"文件过大(单文件上限 55MB)":/^unsupported file type$/i.test(c)?"不支持的文件类型":/^not an image$/i.test(c)?"不是有效的图片文件":c||"上传失败"}function Wt(e,i){if(!e)return i==="json"?Se:e;if(i!=="json")return e;try{const c=JSON.parse(e);if(c!=null&&c.root&&Array.isArray(c.root.children)&&c.root.children.length===0)return Se}catch{}return e}function Yt({editor:e}){const{visible:i}=Ct();return a.jsx("div",{className:"mdocs-outline-siderail",style:{flexShrink:0,overflow:"hidden",transition:"width 0.2s ease",width:i?200:0},children:a.jsx("div",{style:{width:200},children:a.jsx(Dt,{editor:e})})})}function sn(e){const{t:i,lang:c}=Ve(),[I,g]=n.useState(!1),[R,b]=n.useState(!1),z=n.useRef(null),F=n.useRef(null),[L,ee]=n.useState([]),[j,A]=n.useState(!1),[S,d]=n.useState(e.meta.permission),[f,k]=n.useState(!1),[x,v]=n.useState(!1),[O,U]=n.useState(!1),[N,J]=n.useState(new Map),[E,$]=n.useState(!1);n.useEffect(()=>{const t=r=>{z.current&&!z.current.contains(r.target)&&g(!1),F.current&&!F.current.contains(r.target)&&b(!1)};return(I||R)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[I,R]),n.useEffect(()=>{let t=!0;return We().then(r=>{t&&ee(r)}).catch(()=>{}),()=>{t=!1}},[]);function te(t){const r=L.find(l=>l.visitorId===t);return(r==null?void 0:r.visitorName)??t.slice(0,8)}const[w,s]=n.useState(e.initialDisplayName),[m,h]=n.useState(!1),[y,_]=n.useState(!1),[H,q]=n.useState(!1),[P,ne]=n.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),M=e.canEdit&&P,[u,ue]=n.useState(null),[Me,de]=n.useState(!1),ae=n.useRef(null);n.useLayoutEffect(()=>{de(!1),ue(null),ae.current=null},[e.meta.documentId]),n.useEffect(()=>{const t=requestAnimationFrame(()=>de(!0));return()=>cancelAnimationFrame(t)},[e.meta.documentId]);const C=n.useMemo(()=>{var t;if(!e.initialContent)return"json";try{const r=JSON.parse(e.initialContent);return Array.isArray((t=r==null?void 0:r.root)==null?void 0:t.children)?"json":"markdown"}catch{return"markdown"}},[e.initialContent,e.contentRevision]),V=n.useMemo(()=>Wt(e.initialContent||"",C),[e.initialContent,C,e.contentRevision]),{isDirty:me,draftExists:K,markDraftSaved:Ce}=qt({editor:u,documentId:e.meta.documentId,displayName:w,enabled:e.canEdit,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId},seedDraftExists:e.hasLocalDraft});n.useEffect(()=>{var t;(t=e.onDraftExistsChange)==null||t.call(e,K)},[K,e.onDraftExistsChange]),Vt({isDirty:me,draftExists:K}),n.useEffect(()=>{if(u)try{u.setDocument(C,V)}catch{}},[u,e.meta.documentId,e.contentRevision,V,C]),n.useEffect(()=>{u==null||u.setLocale(c==="zh"?tt:nt)},[u,c]),n.useEffect(()=>{s(e.initialDisplayName)},[e.initialDisplayName,e.meta.documentId,e.contentRevision]),n.useEffect(()=>{d(e.meta.permission)},[e.meta.permission,e.meta.documentId]),n.useEffect(()=>{let t=!0;return(async()=>{try{const r=await Ye(e.meta.documentId);t&&_(r.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function ie(){var t,r;if(!H){q(!0);try{y?(await Xe(e.meta.documentId),_(!1),(t=e.onShowToast)==null||t.call(e,i("bookmarkRemoved"))):(await Qe(e.meta.documentId),_(!0),(r=e.onShowToast)==null||r.call(e,i("bookmarkAdded")))}finally{q(!1)}}}n.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=Be),()=>{e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=void 0)})),n.useEffect(()=>{if(e.exportMarkdownRef)return e.exportMarkdownRef.current=()=>{const t=ae.current;if(!t)return"";try{const r=t.getDocument("markdown");return typeof r=="string"?r:String(r??"")}catch{return""}},()=>{e.exportMarkdownRef&&(e.exportMarkdownRef.current=void 0)}});function De(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const Re=n.useCallback(t=>{ae.current=t,ue(t);const r=V;if(!r)return;const l=()=>{try{t.setDocument(C,r)}catch{requestAnimationFrame(()=>{try{t.setDocument(C,r)}catch{}})}};queueMicrotask(()=>{queueMicrotask(l)})},[C,V]);async function fe(){if(!(!u||!e.canEdit)){h(!0);try{const t=le(u);if(!t)return;await e.onPublish(t,w,e.meta.documentId)}catch(t){throw t}finally{h(!1)}}}async function je(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(w.trim()!==t)try{await fe()}catch{}}const D=n.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),Ae=n.useMemo(()=>{const t=(D==null?void 0:D.permission)??"public";return Ge(t)},[D==null?void 0:D.permission]);function Ne(t){return t===Z.PRIVATE?i("permissionPrivate"):t===Z.DOMAIN_READ?i("permissionInvite"):t===Z.DOMAIN_WRITE?i("permissionDomainWrite"):t===Z.PUBLIC_READ?i("permissionPublicRead"):i("permissionPublicEdit")}async function Pe(){var t;if(f||S===e.meta.permission){A(!1);return}k(!0);try{const l=(u?le(u):null)??e.initialContent;await e.onPublish(l,w,e.meta.documentId,S),A(!1),(t=e.onShowToast)==null||t.call(e,i("docInfoPermissionUpdated"))}finally{k(!1)}}async function Te(t){var r;if(!E){$(!0);try{const l=new Set(t.map(o=>o.visitorId)),B=new Map(t.map(o=>[o.visitorId,o.permission]));for(const[o]of N)l.has(o)||await pe(e.meta.documentId,o);for(const{visitorId:o,permission:Y}of t){const G=N.get(o);(!G||G!==Y)&&await et(e.meta.documentId,o,Y)}v(!1),(r=e.onShowToast)==null||r.call(e,i("docInfoInviteSuccess",{count:t.length}))}finally{$(!1)}}}async function Be(){if(!u||!e.canEdit)return;if(!me){console.log("[DocumentEditor.saveDraft] skipped: not dirty, documentId:",e.meta.documentId);return}const t=le(u);t&&(console.log("[DocumentEditor.saveDraft] saving draft, documentId:",e.meta.documentId,"content preview:",t.slice(0,80)),Ce(),await be(e.meta.documentId).execute(()=>we({documentId:e.meta.documentId,content:t,displayName:w,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const Le=n.useMemo(()=>[{icon:Rt,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(se,{tag:"h1"})}},{icon:jt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(se,{tag:"h2"})}},{icon:At,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(se,{tag:"h3"})}},{type:"divider"},{icon:Nt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(at,{})}},{icon:Pt,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand(it,{columns:"3",rows:"3"})}},{icon:Tt,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(rt,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{Lt(r=>{for(const l of r)t.dispatchCommand(wt,{file:l})},".pdf,.zip,.txt,.md,.csv,.html,.htm,audio/*,*/*")}},{key:"insert-link",label:"Insert Link",onSelect:t=>{t.dispatchCommand(ot,{url:"https://example.com"}),queueMicrotask(()=>t.focus())}},{key:"insert-codeInline",label:"Inline Code",onSelect:t=>{t.dispatchCommand(st,void 0),queueMicrotask(()=>t.focus())}},{key:"insert-codeBlock",label:"Code Block",onSelect:t=>{t.dispatchCommand(ct,void 0),queueMicrotask(()=>t.focus())}},{icon:Bt,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(lt,void 0),queueMicrotask(()=>t.focus())}},{icon:Je,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(ut,void 0),queueMicrotask(()=>t.focus())}}].map(t=>"type"in t&&t.type==="divider"?t:{...t,extra:a.jsx("span",{style:{color:"var(--mdocs-text-muted)",fontFamily:"monospace",fontSize:12},children:t.key})}),[]),Oe=n.useMemo(()=>[dt,mt,ft,Ie,ht,gt,yt,vt,xt,It,kt,ce(St,{children:u?a.jsx(ke,{editor:u,floating:!0,outlineCollapseTitle:i("outlineHide"),outlineExpandTitle:i("outlineShow"),outlineToggle:!0}):null}),ce(Mt,{handleUpload:async t=>{var r;try{return{url:await xe(t,e.meta.documentId)}}catch(l){throw(r=e.onShowError)==null||r.call(e,Ee(l)),l}}}),ce(Ie,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var r;try{const B=await(await fetch(t)).blob(),o=new File([B],"image.png",{type:B.type});return{url:await xe(o,e.meta.documentId)}}catch(l){throw(r=e.onShowError)==null||r.call(e,Ee(l)),l}}})],[u,i,e.meta.documentId,e.onShowError]),T=!!e.readerChrome,[W,re]=n.useState(!1),X=n.useRef(null),[_e,oe]=n.useState(0);n.useEffect(()=>{if(!T){re(!1),oe(0);return}if(W)return;const t=window.setTimeout(()=>re(!0),2800);return()=>window.clearTimeout(t)},[T,W,e.meta.documentId]),n.useEffect(()=>{b(!1),g(!1)},[e.meta.documentId]);function He(t){!T||W||t.target.closest("button, a, input, textarea, select")||(X.current={startY:t.clientY,dragging:!0},t.currentTarget.setPointerCapture(t.pointerId))}function ze(t){const r=X.current;if(!(r!=null&&r.dragging))return;const l=t.clientY-r.startY;oe(Math.max(-72,Math.min(0,l)))}function Fe(t){const r=X.current;if(!(r!=null&&r.dragging))return;X.current=null;const l=t.clientY-r.startY;oe(0),l<-36&&re(!0);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}function Q(){g(!1),b(!1)}function he(t,r){const l=(r==null?void 0:r.includeBookmark)??!0,B={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return a.jsxs(a.Fragment,{children:[a.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoCreator")}),a.jsx("span",{children:te(e.meta.ownerVisitorId)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoCreatedAt")}),a.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(c==="zh"?"zh-CN":"en-US")})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoSize")}),a.jsx("span",{children:De(new Blob([e.initialContent]).size)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoUpdatedAt")}),a.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(c==="zh"?"zh-CN":"en-US")})]})]}),a.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),l?a.jsxs("button",{type:"button",style:B,onMouseEnter:o=>{o.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:o=>{o.currentTarget.style.background="none"},onClick:()=>{ie(),t()},children:[a.jsx("span",{children:y?"⭐":"☆"}),a.jsx("span",{children:i(y?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?a.jsxs("button",{type:"button",style:B,onMouseEnter:o=>{o.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:o=>{o.currentTarget.style.background="none"},onClick:()=>{t(),(async()=>{U(!0);try{const o=await Ze(e.meta.documentId),Y=new Map(o.map(G=>[G.visitorId,G.permission]));J(Y),v(!0)}finally{U(!1)}})()},children:[a.jsx(_t,{size:14}),a.jsx("span",{children:i("docInfoInviteMember")})]}):null,a.jsxs("button",{type:"button",style:B,onMouseEnter:o=>{o.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:o=>{o.currentTarget.style.background="none"},onClick:()=>{t(),d(e.meta.permission),A(!0)},children:[a.jsx(Ht,{size:14}),a.jsx("span",{children:i("docInfoChangePermission")})]})]})}return a.jsxs("div",{className:"mdocs-editor"+(T?" mdocs-editor--reader":"")+(T&&W?" mdocs-editor--reader-docked":""),children:[a.jsx(Ot,{fileType:e.meta.fileType||"md",displayName:w,onDisplayNameChange:s,onDisplayNameBlur:()=>void je(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:M,onEnterEdit:()=>ne(!0),onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:m,draftExists:K,onPublish:()=>{fe().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:y,bookmarkBusy:H,onToggleBookmark:()=>void ie(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:he(Q),docInfoOpen:I,onToggleDocInfo:()=>g(!I),docInfoMenuRef:z,readerChrome:T,onOpenMobileNav:e.onOpenMobileNav,readerHeaderDocked:W,readerDragOffset:_e,onReaderHeaderPointerDown:He,onReaderHeaderPointerMove:ze,onReaderHeaderPointerUp:Fe,readerMoreOpen:R,onToggleReaderMore:()=>b(t=>!t),readerMoreMenuRef:F,readerMoreMenu:a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:H,onClick:()=>{ie(),Q()},children:[a.jsx($e,{size:16,strokeWidth:1.5,style:{color:y?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:y?"#faad14":"none"}}),a.jsx("span",{children:i(y?"bookmarkRemove":"bookmarkAdd")})]}),e.canEdit?a.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:m,onClick:()=>{Q(),e.onDelete()},children:a.jsx("span",{children:i("delete")})}):null,a.jsx("div",{className:"mdocs-reader-more-divider"}),he(Q,{includeBookmark:!1})]})}),j&&a.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&A(!1)},children:a.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[a.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:i("docInfoChangePermission")}),a.jsxs("div",{className:"muted",style:{marginBottom:12},children:[i("domainPermission"),":",D?Ke(D.domainName,c,i):e.meta.domainId]}),a.jsx("div",{style:{display:"grid",gap:8},children:Ae.map(t=>a.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[a.jsx("input",{type:"radio",name:"doc-permission",value:t,checked:S===t,onChange:()=>d(t)}),a.jsx("span",{children:Ne(t)})]},t))}),a.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[a.jsx("button",{type:"button",onClick:()=>A(!1),children:i("cancel")}),a.jsx("button",{type:"button",className:"primary",disabled:f,onClick:()=>void Pe(),children:i(f?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&a.jsx(zt,{open:x,title:i("docInfoInviteMember"),initialSelectedIds:[...N.keys()],initialPermissions:N,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:i("invitePermissionRead")},{value:"edit",label:i("invitePermissionEdit")}],onClose:()=>v(!1),onConfirm:t=>{Te(t)}}),a.jsx(Et,{children:a.jsx(ge,{flex:1,style:{minHeight:0},children:a.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[M&&u&&!T?a.jsx(ke,{editor:u,outlineCollapseTitle:i("outlineHide"),outlineExpandTitle:i("outlineShow"),outlineToggle:!0}):null,a.jsx("div",{className:"mdocs-editor-content-area",style:{flex:1,display:"flex",minHeight:0},children:a.jsxs(ge,{variant:"outlined",horizontal:!0,style:{background:"var(--mdocs-surface)",flex:1,minHeight:0,minWidth:0,borderRadius:0,outline:"none"},children:[a.jsx("div",{className:"mdocs-editor-scroll-host",children:Me?a.jsx(bt,{content:V,type:C,confirmPasteMarkdown:!0,editable:M,onInit:Re,plugins:Oe,lineEmptyPlaceholder:i("displayNamePlaceholder"),placeholder:i("displayNamePlaceholder"),slashOption:{items:Le},className:"mdocs-document-editor-root"},e.meta.documentId):null}),u&&a.jsx(Yt,{editor:u})]})})]})})})]})}export{sn as DocumentEditor};
@@ -1 +0,0 @@
1
- import{r as i,j as n}from"./react-vendor-BuABiQkA.js";import{c as ue,f as fe,e as he,a as xe,s as ve,g as ge,u as ye,h as be,S as ke,l as je,r as Ce,i as Ie,j as De,D as C,k as we,m as Se,b as q}from"./index-Cwy87sZC.js";import{D as Ee,U as Ne,S as Me}from"./DocChrome-QTGER_Af.js";import{V as Pe}from"./VisitorPickerModal-CM13Y6jQ.js";import"./ui-ZPt_BNBg.js";import"./motion-Dyy8pB0Q.js";import"./diagram-CgEd0hrk.js";import"./file-type-policy-GUk904tm.js";function Ue(e){const{t:a,lang:I}=ue(),r=e.meta.documentId,[x,D]=i.useState(e.initialContent),[f,w]=i.useState(e.initialDisplayName),[c,g]=i.useState(!0),[H,$]=i.useState(!1),[J,y]=i.useState(e.hasLocalDraft??!1),[m,S]=i.useState(!1),[E,_]=i.useState(!1),[b,N]=i.useState(!1),[M,P]=i.useState(!1),[X,Z]=i.useState([]),[p,v]=i.useState(!1),[B,A]=i.useState(e.meta.permission),[R,K]=i.useState(!1),[ee,T]=i.useState(!1),[k,te]=i.useState(new Map),z=i.useRef(null),O=i.useRef(null),d=i.useRef(null),V=i.useRef(x),L=i.useRef(f);V.current=x,L.current=f;const ne=e.canEdit&&!c;i.useEffect(()=>{D(e.initialContent),w(e.initialDisplayName),g(!0)},[r]),i.useEffect(()=>{e.contentRevision&&(D(e.initialContent),w(e.initialDisplayName))},[e.contentRevision]),i.useEffect(()=>{let t=!0;return fe().then(s=>{t&&Z(s)}).catch(()=>{}),()=>{t=!1}},[]),i.useEffect(()=>{let t=!0;return he(r).then(s=>{t&&S(s.bookmarked)}).catch(()=>{}),()=>{t=!1}},[r]),i.useEffect(()=>{let t=!1;const s=q();return xe(r).then(o=>{var j;if(t||q()!==s)return;const u=!!(o&&!o.published);y(u),(j=e.onDraftExistsChange)==null||j.call(e,u)}),()=>{t=!0}},[r,e.onDraftExistsChange]),i.useEffect(()=>ve((t,s)=>{var o;t===r&&(y(s),(o=e.onDraftExistsChange)==null||o.call(e,s))}),[r,e.onDraftExistsChange]),i.useEffect(()=>{A(e.meta.permission)},[e.meta.permission,r]),i.useEffect(()=>{const t=s=>{z.current&&!z.current.contains(s.target)&&N(!1),O.current&&!O.current.contains(s.target)&&P(!1)};return(b||M)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[b,M]);const U=i.useCallback(async()=>{var t;await ge(r).execute(()=>ye({documentId:r,content:V.current,displayName:L.current,contentKind:"html",localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})),y(!0),(t=e.onDraftExistsChange)==null||t.call(e,!0)},[r,e]),G=i.useCallback(()=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{U()},1e3)},[U]);i.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]);async function F(t){var s;if(e.canEdit){$(!0);try{d.current&&(clearTimeout(d.current),d.current=null),await U(),await e.onPublish(V.current,L.current.trim()||f,r,t),y(!1),(s=e.onDraftExistsChange)==null||s.call(e,!1)}finally{$(!1)}}}async function ie(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(f.trim()!==t)try{await F()}catch{}}async function W(){var t,s;if(!E){_(!0);try{m?(await Ce(r),S(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await Ie(r),S(!0),(s=e.onShowToast)==null||s.call(e,a("bookmarkAdded")))}finally{_(!1)}}}function ae(t){const s=X.find(o=>o.visitorId===t);return(s==null?void 0:s.visitorName)??t.slice(0,8)}function se(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const l=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),oe=i.useMemo(()=>{const t=(l==null?void 0:l.permission)??"public";return be(t)},[l==null?void 0:l.permission]);function re(t){return t===C.PRIVATE?a("permissionPrivate"):t===C.DOMAIN_READ?a("permissionInvite"):t===C.DOMAIN_WRITE?a("permissionDomainWrite"):t===C.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function de(){if(R||B===e.meta.permission){v(!1);return}K(!0);try{await F(B),v(!1)}finally{K(!1)}}async function le(t){const s=new Set(t.map(o=>o.visitorId));for(const[o]of k)s.has(o)||await we(r,o);for(const o of t)k.get(o.visitorId)!==o.permission&&await Se(r,o.visitorId,o.permission);T(!1)}function h(){N(!1),P(!1)}function Q(t,s){const o=(s==null?void 0:s.includeBookmark)??!0,u={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreator")}),n.jsx("span",{children:ae(e.meta.ownerVisitorId)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreatedAt")}),n.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(I==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoSize")}),n.jsx("span",{children:se(new Blob([x]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(I==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),o?n.jsxs("button",{type:"button",style:u,onClick:()=>{W(),t()},children:[n.jsx("span",{children:m?"⭐":"☆"}),n.jsx("span",{children:a(m?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:u,onClick:()=>{t(),(async()=>{const j=await De(r);te(new Map(j.map(Y=>[Y.visitorId,Y.permission]))),T(!0)})()},children:[n.jsx(Ne,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:u,onClick:()=>{t(),A(e.meta.permission),v(!0)},children:[n.jsx(Me,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})}const ce=i.useCallback(t=>{var o;const s=t.target.value;D(s),(o=e.onContentChange)==null||o.call(e,s),G()},[e,G]),me=`<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head><body>${x}</body></html>`;return n.jsxs("div",{className:"mdocs-editor"+(e.readerChrome?" mdocs-editor--reader":""),children:[n.jsx(Ee,{fileType:"html",displayName:f,onDisplayNameChange:w,onDisplayNameBlur:()=>void ie(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:ne,onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:H,draftExists:J,onPublish:()=>{F().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:m,bookmarkBusy:E,onToggleBookmark:()=>void W(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:Q(h),docInfoOpen:b,onToggleDocInfo:()=>N(!b),docInfoMenuRef:z,readerChrome:e.readerChrome,readerActionsCollapsible:!0,readerHeaderDocked:e.readerChrome,onOpenMobileNav:e.onOpenMobileNav,readerMoreOpen:M,onToggleReaderMore:()=>P(t=>!t),readerMoreMenuRef:O,readerMoreMenu:n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:E,onClick:()=>{W(),h()},children:[n.jsx(ke,{size:16,strokeWidth:1.5,style:{color:m?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:m?"#faad14":"none"}}),n.jsx("span",{children:a(m?"bookmarkRemove":"bookmarkAdd")})]}),n.jsx("div",{className:"mdocs-reader-more-divider"}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:!c,onClick:()=>{g(!1),h()},children:a("edit")}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:c,onClick:()=>{g(!0),h()},children:a("preview")}),n.jsx("div",{className:"mdocs-reader-more-divider"}),e.canEdit?n.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:H,onClick:()=>{h(),e.onDelete()},children:n.jsx("span",{children:a("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),Q(h,{includeBookmark:!1})]}),leadingExtra:e.canEdit&&!e.readerChrome?n.jsxs("label",{className:"mdocs-editor-mode-toggle","aria-label":a(c?"preview":"edit"),children:[n.jsx("input",{type:"checkbox",checked:c,onChange:()=>g(t=>!t)}),n.jsxs("span",{className:"mdocs-editor-mode-toggle-slider",children:[n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--left",children:a("edit")}),n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--right",children:a("preview")})]})]}):null}),n.jsxs("div",{className:"mdocs-html-editor-body",children:[!c&&e.canEdit?n.jsx("textarea",{className:"mdocs-html-editor-textarea",value:x,onChange:ce,spellCheck:!1,placeholder:"在此处编写 HTML 代码"}):null,n.jsx("div",{className:"mdocs-html-editor-preview",style:!c&&e.canEdit?{width:"50%"}:{width:"100%"},children:n.jsx("iframe",{className:"mdocs-html-editor-iframe",srcDoc:me,sandbox:"",title:f})})]}),p&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&v(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:a("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[a("domainPermission"),":",l?je(l.domainName,I,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:oe.map(t=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n.jsx("input",{type:"radio",name:"html-doc-permission",value:t,checked:B===t,onChange:()=>A(t)}),n.jsx("span",{children:re(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>v(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:R,onClick:()=>void de(),children:a(R?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Pe,{open:ee,title:a("docInfoInviteMember"),initialSelectedIds:[...k.keys()],initialPermissions:k,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>T(!1),onConfirm:t=>{le(t)}})]})}export{Ue as HtmlEditor};