@fgbg/mdocs 1.3.16 → 1.3.17

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 (39) hide show
  1. package/README.md +1 -1
  2. package/agent-skills/changelog/SKILL.md +16 -0
  3. package/dist/server/access/access-control.js +23 -0
  4. package/dist/server/access/access-control.js.map +1 -1
  5. package/dist/server/access/access-control.test.js +44 -0
  6. package/dist/server/access/access-control.test.js.map +1 -1
  7. package/dist/server/access/domain-access.js +8 -0
  8. package/dist/server/access/domain-access.js.map +1 -1
  9. package/dist/server/documents/graph/folder-progress.test.js +40 -0
  10. package/dist/server/documents/graph/folder-progress.test.js.map +1 -0
  11. package/dist/server/documents/graph/index.js +2 -1
  12. package/dist/server/documents/graph/index.js.map +1 -1
  13. package/dist/server/documents/graph.service.js +3 -4
  14. package/dist/server/documents/graph.service.js.map +1 -1
  15. package/dist/server/routes/graph.routes.js +36 -0
  16. package/dist/server/routes/graph.routes.js.map +1 -1
  17. package/dist/web/assets/{AgentChatPanel-Bsx3DwQ7.js → AgentChatPanel-C3c14Bo_.js} +1 -1
  18. package/dist/web/assets/{AgentSkillFormCard-TFpdC5LM.js → AgentSkillFormCard-BYUjSFe1.js} +1 -1
  19. package/dist/web/assets/{AiWriteWorkbench-Jl0I9eM9.js → AiWriteWorkbench-ze827qk7.js} +1 -1
  20. package/dist/web/assets/{DiagramEditor-NtNY3sZL-CAEe_iNQ.js → DiagramEditor-NtNY3sZL-Cie6NhLx.js} +1 -1
  21. package/dist/web/assets/{DocChrome-BWMgRxlr.js → DocChrome-ixaNyUG9.js} +1 -1
  22. package/dist/web/assets/{DocumentEditor-DALklXO2.js → DocumentEditor-ByqPHijF.js} +1 -1
  23. package/dist/web/assets/{HtmlEditor-CX0e0ifD.js → HtmlEditor-CpqCAPAr.js} +1 -1
  24. package/dist/web/assets/{MergeView-DNu_ac5f.js → MergeView-D93ZHlTG.js} +1 -1
  25. package/dist/web/assets/{PlaygroundPage-mv9P6czE.js → PlaygroundPage-CodSaeWS.js} +1 -1
  26. package/dist/web/assets/SettingsPage-C8doYEbb.js +6 -0
  27. package/dist/web/assets/{Toolbar-Hsam79hu.js → Toolbar-CSKpV4ua.js} +1 -1
  28. package/dist/web/assets/{VisitorPickerModal-CqHzml8s.js → VisitorPickerModal-CqDA1S9F.js} +1 -1
  29. package/dist/web/assets/{check-soiTDN2u.js → check-CN9m0reb.js} +1 -1
  30. package/dist/web/assets/{copy-B4fvX0p8.js → copy-DFs3qk19.js} +1 -1
  31. package/dist/web/assets/index-C0ujN3sT.css +1 -0
  32. package/dist/web/assets/{index-OmOf_og0.js → index-CUdIA5aE.js} +49 -44
  33. package/dist/web/assets/{meta2dEngine-BD2XbzaV-Bq3HuUfD.js → meta2dEngine-BD2XbzaV-SYn2XtSh.js} +1 -1
  34. package/dist/web/assets/{plus-DKKQ-AoS.js → plus-QDhBbIRF.js} +1 -1
  35. package/dist/web/assets/{react-CI5PDFXT.js → react-Bf45libg.js} +3 -3
  36. package/dist/web/index.html +2 -2
  37. package/package.json +1 -1
  38. package/dist/web/assets/SettingsPage-nT9hvcPA.js +0 -6
  39. package/dist/web/assets/index-CuXb3X2-.css +0 -1
@@ -1,2 +1,2 @@
1
- import{Q as I,S as H,T as F,U as O,V as G}from"./react-CI5PDFXT.js";import{r as c,j as e}from"./react-vendor-BuABiQkA.js";import{ensureMeta2dShapes as X,generateSvgFromMeta2d as Q,generateSvgFromDiagram as Y}from"./meta2dEngine-BD2XbzaV-Bq3HuUfD.js";import{M as _}from"./meta2d-1-g23JOU.js";import"./editor-CL03se2B.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./index-OmOf_og0.js";import"./plus-DKKQ-AoS.js";import"./check-soiTDN2u.js";import"./copy-B4fvX0p8.js";let q=0;const P=new Set;function $(n){return P.add(n),()=>{P.delete(n)}}function M(){return q}function J(){q++,P.forEach(n=>n())}function z(n){let t=null;try{const[r]=I();t=r}catch{}const i=t;if(!i)throw new Error("[useEditorLocale] No editor found. Pass an editor instance or use this hook inside an <Editor> tree.");return c.useSyncExternalStore($,M,M),{setLocale:c.useCallback(r=>{i.setLocale(r),J()},[i]),t:c.useCallback((r,u)=>i.t(r,u),[i])}}const K={Activity:"meta2d.palette.groups.activity",Basic:"meta2d.palette.groups.basic","Fault tree":"meta2d.palette.groups.faultTree",Flow:"meta2d.palette.groups.flow","Sequence & class":"meta2d.palette.groups.sequenceClass"};function W(n){return`meta2d.palette.${n}`}const s={background:"#fff",color:"#1f1f1f",height:60,lineWidth:1,textColor:"#1f1f1f",width:120};function U(){return[{group:"Basic",key:"square",label:"Square",pen:{...s,height:100,name:"square",text:"",width:100}},{group:"Basic",key:"rect",label:"Rectangle",pen:{...s,name:"rectangle",text:"Rectangle"}},{group:"Basic",key:"roundRect",label:"Rounded",pen:{...s,borderRadius:.2,name:"rectangle",text:"Rounded"}},{group:"Basic",key:"circle",label:"Circle",pen:{...s,height:80,name:"circle",text:"Circle",width:80}},{group:"Basic",key:"triangle",label:"Triangle",pen:{...s,height:90,name:"triangle",text:"Triangle",width:100}},{group:"Basic",key:"diamond",label:"Diamond",pen:{...s,height:100,name:"diamond",text:"Decision",width:100}},{group:"Basic",key:"pentagon",label:"Pentagon",pen:{...s,height:100,name:"pentagon",text:"Pentagon",width:100}},{group:"Basic",key:"hexagon",label:"Hexagon",pen:{...s,height:100,name:"hexagon",text:"Hexagon",width:100}},{group:"Basic",key:"pentagram",label:"Star",pen:{...s,height:100,name:"pentagram",text:"",width:100}},{group:"Basic",key:"leftArrow",label:"Left arrow",pen:{height:60,name:"leftArrow",width:120}},{group:"Basic",key:"rightArrow",label:"Right arrow",pen:{height:60,name:"rightArrow",width:120}},{group:"Basic",key:"twowayArrow",label:"Two-way",pen:{height:60,name:"twowayArrow",width:150}},{group:"Basic",key:"cloud",label:"Cloud",pen:{height:100,name:"cloud",width:100}},{group:"Basic",key:"message",label:"Message",pen:{height:100,name:"message",textTop:-.1,width:100}},{group:"Basic",key:"file",label:"File",pen:{height:100,name:"file",width:80}},{group:"Basic",key:"cube",label:"Cube",pen:{height:100,name:"cube",width:60,z:.25}},{group:"Basic",key:"people",label:"Actor",pen:{height:100,name:"people",width:70}},{group:"Basic",key:"text",label:"Text",pen:{...s,background:"transparent",color:"transparent",height:32,name:"text",text:"text",width:120}},{group:"Basic",key:"line",label:"Line",pen:{color:"#1f1f1f",height:1,lineWidth:1,name:"line",width:160}},{group:"Flow",key:"flowTerminal",label:"Terminal",pen:{...s,borderRadius:.5,height:40,name:"rectangle",text:"Start / End",width:120}},{group:"Flow",key:"flowProcess",label:"Process",pen:{...s,height:40,name:"rectangle",text:"Process",width:120}},{group:"Flow",key:"flowDecision",label:"Decision",pen:{...s,height:60,name:"diamond",text:"Decision",width:120}},{group:"Flow",key:"flowData",label:"Data",pen:{...s,name:"flowData",offsetX:.14,text:"Data"}},{group:"Flow",key:"flowPrepare",label:"Prepare",pen:{...s,height:50,name:"hexagon",text:"Prepare",width:120}},{group:"Flow",key:"flowSubprocess",label:"Subprocess",pen:{...s,height:50,name:"flowSubprocess",text:"Subprocess",width:120}},{group:"Flow",key:"flowDb",label:"Database",pen:{...s,height:100,name:"flowDb",text:"DB",width:80}},{group:"Flow",key:"flowDocument",label:"Document",pen:{...s,height:100,name:"flowDocument",text:"Document",width:120}},{group:"Flow",key:"flowInternalStorage",label:"Int. storage",pen:{...s,height:80,name:"flowInternalStorage",text:"Internal",width:120}},{group:"Flow",key:"flowExternStorage",label:"Ext. storage",pen:{...s,height:80,name:"flowExternStorage",text:"External",width:120}},{group:"Flow",key:"flowQueue",label:"Queue",pen:{...s,height:100,name:"flowQueue",text:"Queue",width:100}},{group:"Flow",key:"flowManually",label:"Manual input",pen:{...s,height:80,name:"flowManually",text:"Manual",width:120}},{group:"Flow",key:"flowDisplay",label:"Display",pen:{...s,height:80,name:"flowDisplay",text:"Display",width:120}},{group:"Flow",key:"flowParallel",label:"Parallel",pen:{...s,height:50,name:"flowParallel",text:"Parallel",width:120}},{group:"Flow",key:"flowComment",label:"Comment",pen:{...s,height:100,name:"flowComment",text:"Note",width:100}},{group:"Activity",key:"actStart",label:"Start",pen:{background:"#555",height:30,lineWidth:0,name:"circle",text:"",width:30}},{group:"Activity",key:"actFinal",label:"Final",pen:{height:30,name:"activityFinal",width:30}},{group:"Activity",key:"actStep",label:"Action",pen:{...s,borderRadius:.25,height:50,name:"rectangle",text:"Action",width:120}},{group:"Activity",key:"actMerge",label:"Merge",pen:{...s,height:50,name:"diamond",text:"Merge",width:120}},{group:"Activity",key:"swimlaneV",label:"Swimlane V",pen:{height:500,lineTop:.08,name:"swimlaneV",text:"Swimlane",textBaseline:"top",textTop:20,width:200}},{group:"Activity",key:"swimlaneH",label:"Swimlane H",pen:{height:200,lineLeft:.08,name:"swimlaneH",text:"Swimlane",textAlign:"left",textLeft:.04,textWidth:.01,width:500}},{group:"Activity",key:"forkV",label:"Fork V",pen:{fillStyle:"#555",height:150,name:"forkV",strokeStyle:"transparent",text:"",width:10}},{group:"Activity",key:"forkH",label:"Fork H",pen:{fillStyle:"#555",height:10,name:"forkH",strokeStyle:"transparent",text:"",width:150}},{group:"Sequence & class",key:"lifeline",label:"Lifeline",pen:{height:400,name:"lifeline",text:"Object",textHeight:50,width:150}},{group:"Sequence & class",key:"sequenceFocus",label:"Activation",pen:{height:200,name:"sequenceFocus",text:"",width:12}},{group:"Sequence & class",key:"simpleClass",label:"Simple class",pen:{height:200,list:[{text:`- name: string
1
+ import{Q as I,S as H,T as F,U as O,V as G}from"./react-Bf45libg.js";import{r as c,j as e}from"./react-vendor-BuABiQkA.js";import{ensureMeta2dShapes as X,generateSvgFromMeta2d as Q,generateSvgFromDiagram as Y}from"./meta2dEngine-BD2XbzaV-SYn2XtSh.js";import{M as _}from"./meta2d-1-g23JOU.js";import"./editor-CL03se2B.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./index-CUdIA5aE.js";import"./plus-QDhBbIRF.js";import"./check-CN9m0reb.js";import"./copy-DFs3qk19.js";let q=0;const P=new Set;function $(n){return P.add(n),()=>{P.delete(n)}}function M(){return q}function J(){q++,P.forEach(n=>n())}function z(n){let t=null;try{const[r]=I();t=r}catch{}const i=t;if(!i)throw new Error("[useEditorLocale] No editor found. Pass an editor instance or use this hook inside an <Editor> tree.");return c.useSyncExternalStore($,M,M),{setLocale:c.useCallback(r=>{i.setLocale(r),J()},[i]),t:c.useCallback((r,u)=>i.t(r,u),[i])}}const K={Activity:"meta2d.palette.groups.activity",Basic:"meta2d.palette.groups.basic","Fault tree":"meta2d.palette.groups.faultTree",Flow:"meta2d.palette.groups.flow","Sequence & class":"meta2d.palette.groups.sequenceClass"};function W(n){return`meta2d.palette.${n}`}const s={background:"#fff",color:"#1f1f1f",height:60,lineWidth:1,textColor:"#1f1f1f",width:120};function U(){return[{group:"Basic",key:"square",label:"Square",pen:{...s,height:100,name:"square",text:"",width:100}},{group:"Basic",key:"rect",label:"Rectangle",pen:{...s,name:"rectangle",text:"Rectangle"}},{group:"Basic",key:"roundRect",label:"Rounded",pen:{...s,borderRadius:.2,name:"rectangle",text:"Rounded"}},{group:"Basic",key:"circle",label:"Circle",pen:{...s,height:80,name:"circle",text:"Circle",width:80}},{group:"Basic",key:"triangle",label:"Triangle",pen:{...s,height:90,name:"triangle",text:"Triangle",width:100}},{group:"Basic",key:"diamond",label:"Diamond",pen:{...s,height:100,name:"diamond",text:"Decision",width:100}},{group:"Basic",key:"pentagon",label:"Pentagon",pen:{...s,height:100,name:"pentagon",text:"Pentagon",width:100}},{group:"Basic",key:"hexagon",label:"Hexagon",pen:{...s,height:100,name:"hexagon",text:"Hexagon",width:100}},{group:"Basic",key:"pentagram",label:"Star",pen:{...s,height:100,name:"pentagram",text:"",width:100}},{group:"Basic",key:"leftArrow",label:"Left arrow",pen:{height:60,name:"leftArrow",width:120}},{group:"Basic",key:"rightArrow",label:"Right arrow",pen:{height:60,name:"rightArrow",width:120}},{group:"Basic",key:"twowayArrow",label:"Two-way",pen:{height:60,name:"twowayArrow",width:150}},{group:"Basic",key:"cloud",label:"Cloud",pen:{height:100,name:"cloud",width:100}},{group:"Basic",key:"message",label:"Message",pen:{height:100,name:"message",textTop:-.1,width:100}},{group:"Basic",key:"file",label:"File",pen:{height:100,name:"file",width:80}},{group:"Basic",key:"cube",label:"Cube",pen:{height:100,name:"cube",width:60,z:.25}},{group:"Basic",key:"people",label:"Actor",pen:{height:100,name:"people",width:70}},{group:"Basic",key:"text",label:"Text",pen:{...s,background:"transparent",color:"transparent",height:32,name:"text",text:"text",width:120}},{group:"Basic",key:"line",label:"Line",pen:{color:"#1f1f1f",height:1,lineWidth:1,name:"line",width:160}},{group:"Flow",key:"flowTerminal",label:"Terminal",pen:{...s,borderRadius:.5,height:40,name:"rectangle",text:"Start / End",width:120}},{group:"Flow",key:"flowProcess",label:"Process",pen:{...s,height:40,name:"rectangle",text:"Process",width:120}},{group:"Flow",key:"flowDecision",label:"Decision",pen:{...s,height:60,name:"diamond",text:"Decision",width:120}},{group:"Flow",key:"flowData",label:"Data",pen:{...s,name:"flowData",offsetX:.14,text:"Data"}},{group:"Flow",key:"flowPrepare",label:"Prepare",pen:{...s,height:50,name:"hexagon",text:"Prepare",width:120}},{group:"Flow",key:"flowSubprocess",label:"Subprocess",pen:{...s,height:50,name:"flowSubprocess",text:"Subprocess",width:120}},{group:"Flow",key:"flowDb",label:"Database",pen:{...s,height:100,name:"flowDb",text:"DB",width:80}},{group:"Flow",key:"flowDocument",label:"Document",pen:{...s,height:100,name:"flowDocument",text:"Document",width:120}},{group:"Flow",key:"flowInternalStorage",label:"Int. storage",pen:{...s,height:80,name:"flowInternalStorage",text:"Internal",width:120}},{group:"Flow",key:"flowExternStorage",label:"Ext. storage",pen:{...s,height:80,name:"flowExternStorage",text:"External",width:120}},{group:"Flow",key:"flowQueue",label:"Queue",pen:{...s,height:100,name:"flowQueue",text:"Queue",width:100}},{group:"Flow",key:"flowManually",label:"Manual input",pen:{...s,height:80,name:"flowManually",text:"Manual",width:120}},{group:"Flow",key:"flowDisplay",label:"Display",pen:{...s,height:80,name:"flowDisplay",text:"Display",width:120}},{group:"Flow",key:"flowParallel",label:"Parallel",pen:{...s,height:50,name:"flowParallel",text:"Parallel",width:120}},{group:"Flow",key:"flowComment",label:"Comment",pen:{...s,height:100,name:"flowComment",text:"Note",width:100}},{group:"Activity",key:"actStart",label:"Start",pen:{background:"#555",height:30,lineWidth:0,name:"circle",text:"",width:30}},{group:"Activity",key:"actFinal",label:"Final",pen:{height:30,name:"activityFinal",width:30}},{group:"Activity",key:"actStep",label:"Action",pen:{...s,borderRadius:.25,height:50,name:"rectangle",text:"Action",width:120}},{group:"Activity",key:"actMerge",label:"Merge",pen:{...s,height:50,name:"diamond",text:"Merge",width:120}},{group:"Activity",key:"swimlaneV",label:"Swimlane V",pen:{height:500,lineTop:.08,name:"swimlaneV",text:"Swimlane",textBaseline:"top",textTop:20,width:200}},{group:"Activity",key:"swimlaneH",label:"Swimlane H",pen:{height:200,lineLeft:.08,name:"swimlaneH",text:"Swimlane",textAlign:"left",textLeft:.04,textWidth:.01,width:500}},{group:"Activity",key:"forkV",label:"Fork V",pen:{fillStyle:"#555",height:150,name:"forkV",strokeStyle:"transparent",text:"",width:10}},{group:"Activity",key:"forkH",label:"Fork H",pen:{fillStyle:"#555",height:10,name:"forkH",strokeStyle:"transparent",text:"",width:150}},{group:"Sequence & class",key:"lifeline",label:"Lifeline",pen:{height:400,name:"lifeline",text:"Object",textHeight:50,width:150}},{group:"Sequence & class",key:"sequenceFocus",label:"Activation",pen:{height:200,name:"sequenceFocus",text:"",width:12}},{group:"Sequence & class",key:"simpleClass",label:"Simple class",pen:{height:200,list:[{text:`- name: string
2
2
  + setName(name: string): void`}],name:"simpleClass",text:"ClassName",textAlign:"center",textBaseline:"top",textHeight:200,textTop:10,width:270}},{group:"Sequence & class",key:"interfaceClass",label:"Class",pen:{height:200,list:[{text:"- name: string"},{text:"+ setName(name: string): void"}],name:"interfaceClass",text:"ClassName",textAlign:"center",textBaseline:"top",textHeight:200,textTop:10,width:270}},{group:"Fault tree",key:"andGate",label:"AND gate",pen:{height:150,name:"andGate",width:100}},{group:"Fault tree",key:"orGate",label:"OR gate",pen:{height:150,name:"orGate",width:100}},{group:"Fault tree",key:"basicEvent",label:"Basic event",pen:{height:150,name:"basicEvent",width:100}},{group:"Fault tree",key:"xorGate",label:"XOR gate",pen:{height:150,name:"xorGate",width:100}},{group:"Fault tree",key:"votingGate",label:"Voting gate",pen:{height:150,name:"votingGate",width:100}}]}function V(n){return G(structuredClone(n))}function Z(n){const t=new Map;for(const i of n){const r=t.get(i.group)??[];r.push(i),t.set(i.group,r)}return Array.from(t.entries())}function ee({name:n}){const t={fill:"#fff",stroke:"#1f1f1f",strokeWidth:1.2};return n==="circle"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("circle",{cx:"14",cy:"14",r:"10",...t})}):n==="diamond"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 25,14 14,25 3,14",...t})}):n==="triangle"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,4 25,24 3,24",...t})}):n==="pentagon"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 25,12 21,25 7,25 3,12",...t})}):n==="hexagon"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"8,4 20,4 25,14 20,24 8,24 3,14",...t})}):n==="pentagram"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 17,11 26,11 18,16 21,25 14,20 7,25 10,16 2,11 11,11",...t})}):n==="line"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("line",{x1:"4",x2:"24",y1:"14",y2:"14",...t})}):n==="text"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("text",{dominantBaseline:"middle",fill:"#1f1f1f",fontSize:"14",textAnchor:"middle",x:"14",y:"15",children:"T"})}):e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("rect",{height:"14",rx:"2",width:"20",x:"4",y:"7",...t})})}function te({disabled:n,engineRef:t,item:i,t:r}){const u=()=>{const a=t.current;if(!(!a||n))try{a.canvas.addCaches=[V(i.pen)]}catch{}};return e.jsxs("div",{draggable:!n,onClick:a=>{a.stopPropagation(),u()},onDragStart:a=>{if(n){a.preventDefault();return}const f=JSON.stringify(V(i.pen));a.dataTransfer.setData("Meta2d",f),a.dataTransfer.setData("Text",f),a.dataTransfer.effectAllowed="copy"},onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),u())},role:"button",style:{alignItems:"center",border:"1px solid #efefef",borderRadius:6,cursor:n?"not-allowed":"grab",display:"flex",flexDirection:"column",gap:4,justifyContent:"center",minHeight:56,opacity:n?.5:1,outline:"none",padding:6},tabIndex:n?-1:0,title:`${r(W(i.key))||i.label} — drag or click to add`,children:[e.jsx(ee,{name:String(i.pen.name??"rectangle")}),e.jsx("span",{style:{fontSize:11},children:r(W(i.key))||i.label})]})}function ne({disabled:n,engineRef:t}){const{t:i}=z(),r=c.useMemo(()=>Z(U()),[]);return e.jsxs("aside",{style:{borderRight:"1px solid #f0f0f0",flexShrink:0,maxHeight:"100%",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",padding:12,touchAction:"pan-y",width:240},children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,marginBottom:4},children:i("meta2d.palette.title")}),e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:12},children:i("meta2d.palette.hint")}),r.map(([u,a])=>e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:6},children:i(K[u]||u)}),e.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"repeat(2, minmax(0, 1fr))"},children:a.map(f=>e.jsx(te,{disabled:n,engineRef:t,item:f,t:i},f.key))})]},u))]})}const N={borderLeft:"1px solid #f0f0f0",flexShrink:0,maxHeight:"100%",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",touchAction:"pan-y",width:220},A={color:"#8c8c8c",fontSize:12,marginBottom:4},D={borderBottom:"1px solid #f0f0f0",padding:"10px 12px"},y={alignItems:"center",display:"flex",gap:6,marginBottom:6},w={background:"#fafafa",border:"1px solid #e5e5e5",borderRadius:4,fontSize:12,height:28,outline:"none",padding:"0 6px"},b={color:"#8c8c8c",fontSize:11,minWidth:22},T={background:"#fff",border:"1px solid #d9d9d9",borderRadius:4,cursor:"pointer",fontSize:11,minWidth:48,padding:"4px 8px"},le=120;function ie({engine:n}){const{t}=z(),[i,r]=c.useState(null),[u,a]=c.useState(null),[f,v]=c.useState(""),p=c.useRef(null),j=c.useRef(null),B=c.useCallback((l,d)=>{!n||l===null||l===void 0||n.setValue({id:l,text:d},{render:!0})},[n]),k=c.useCallback(l=>{if(!l||l.length!==1){p.current&&(clearTimeout(p.current),p.current=null),r(null),a(null),v(""),j.current=null;return}const d=l[0];if((d.globalAlpha===null||d.globalAlpha===void 0)&&(d.globalAlpha=1),d.id!==j.current&&(p.current&&(clearTimeout(p.current),p.current=null),j.current=d.id,v(d.text??"")),r(d),n)try{a(n.getPenRect(d))}catch{a(null)}},[n]),C=c.useCallback(()=>{p.current&&(clearTimeout(p.current),p.current=null),r(null),a(null),v(""),j.current=null},[]);if(c.useEffect(()=>{if(n)return n.on("active",k),n.on("inactive",C),()=>{n.off("active",k),n.off("inactive",C),p.current&&(clearTimeout(p.current),p.current=null)}},[n,k,C]),!i||!n)return e.jsx("aside",{style:N,children:e.jsx("div",{style:{color:"#bbb",fontSize:12,padding:16,textAlign:"center"},children:t("meta2d.props.empty")})});const h=(l,d)=>{const m={id:i.id};m[l]=d,l==="dash"&&(m.lineDash=[void 0,[5,5]][d]),l!=="text"&&r(S=>S&&{...S,...m}),n.setValue(m,{render:!0})},o=l=>{v(l);const d=i.id;p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{p.current=null,B(d,l)},le)},x=()=>{p.current&&(clearTimeout(p.current),p.current=null),B(i.id,f)},g=(l,d)=>{if(!u)return;const m={id:i.id};m[l]=d,n.setValue(m,{render:!0}),a(S=>S?{...S,[l]:d}:null)},R=l=>{l(n),n.render(!0)};return e.jsxs("aside",{style:N,children:[e.jsxs("div",{style:D,children:[e.jsx("div",{style:A,children:t("meta2d.props.text")}),e.jsx("div",{style:y,children:e.jsx("input",{onBlur:x,onChange:l=>o(l.target.value),onKeyDown:l=>{l.stopPropagation(),l.key==="Enter"&&(l.preventDefault(),l.target.blur())},style:{...w,flex:1,width:"100%"},type:"text",value:f})})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.appearance")}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.color")}),e.jsx("input",{onChange:l=>h("color",l.target.value),style:{...w,flex:1},type:"color",value:i.color||"#1f1f1f"})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.bg")}),e.jsx("input",{onChange:l=>h("background",l.target.value),style:{...w,flex:1},type:"color",value:i.background||"#ffffff"})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.dash")}),e.jsxs("select",{onChange:l=>h("dash",Number(l.target.value)),style:{...w,flex:1},value:String(i.dash??0),children:[e.jsx("option",{value:"0",children:t("meta2d.props.solid")}),e.jsx("option",{value:"1",children:t("meta2d.props.dashLine")})]})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.radius")}),e.jsx("input",{max:1,min:0,onChange:l=>h("borderRadius",Number(l.target.value)),step:.01,style:{...w,flex:1},type:"range",value:String(i.borderRadius??0)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:i.borderRadius??0})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.alpha")}),e.jsx("input",{max:1,min:0,onChange:l=>h("globalAlpha",Number(l.target.value)),step:.01,style:{...w,flex:1},type:"range",value:String(i.globalAlpha??1)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:(i.globalAlpha??1).toFixed(2)})]})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.position")}),[["X","x"],["Y","y"],["W","width"],["H","height"]].map(([l,d])=>e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:l}),e.jsx("input",{onChange:m=>g(d,Number(m.target.value)),style:{...w,flex:1},type:"number",value:u?u[d]:0})]},d))]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.textAlign")}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.h")}),e.jsxs("select",{onChange:l=>h("textAlign",l.target.value),style:{...w,flex:1},value:i.textAlign||"center",children:[e.jsx("option",{value:"left",children:t("meta2d.props.left")}),e.jsx("option",{value:"center",children:t("meta2d.props.center")}),e.jsx("option",{value:"right",children:t("meta2d.props.right")})]})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.v")}),e.jsxs("select",{onChange:l=>h("textBaseline",l.target.value),style:{...w,flex:1},value:i.textBaseline||"middle",children:[e.jsx("option",{value:"top",children:t("meta2d.props.topAlign")}),e.jsx("option",{value:"middle",children:t("meta2d.props.middle")}),e.jsx("option",{value:"bottom",children:t("meta2d.props.bottomAlign")})]})]})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.layer")}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:[e.jsx("button",{onClick:()=>R(l=>l.top()),style:T,type:"button",children:t("meta2d.props.top")}),e.jsx("button",{onClick:()=>R(l=>l.up()),style:T,type:"button",children:t("meta2d.props.up")}),e.jsx("button",{onClick:()=>R(l=>l.down()),style:T,type:"button",children:t("meta2d.props.down")}),e.jsx("button",{onClick:()=>R(l=>l.bottom()),style:T,type:"button",children:t("meta2d.props.bottom")})]})]})]})}const L={background:"#fff",border:"1px solid #d9d9d9",borderRadius:6,cursor:"pointer",minWidth:68,padding:"6px 12px"},E={...L,fontSize:12,minWidth:52,padding:"4px 10px"};function re(n){c.useEffect(()=>{const t=document.documentElement,i=document.body,r=t.style.overflow,u=i.style.overflow;return t.style.overflow="hidden",i.style.overflow="hidden",()=>{t.style.overflow=r,i.style.overflow=u}},[n])}function ye({diagram:n,onClose:t,onSave:i}){const{t:r}=z(),u=c.useRef(null),a=c.useRef(null),f=c.useRef(n),v=c.useRef(t),[p,j]=c.useState(null),[B,k]=c.useState(!1);re(!0),c.useLayoutEffect(()=>{v.current=t}),c.useEffect(()=>{if(!u.current)return;X();const o=new _(u.current,{grid:!0,rule:!1});a.current=o,j(o);try{const g=f.current;g!=null&&g.trim()?o.open(JSON.parse(g)):o.open(H()),F(o.data()),o.render(!0)}catch{o.open(H()),F(o.data()),o.render(!0)}const x=g=>{g.key==="Escape"&&v.current()};return window.addEventListener("keydown",x),()=>{window.removeEventListener("keydown",x);try{o.destroy()}catch{}a.current=null}},[]);const C=async()=>{const o=a.current;if(o){k(!0);try{F(o.data()),o.render(!0);const x=O(o.data()),g=JSON.stringify(x);i(g,await Q(o)||await Y(g)||'<svg xmlns="http://www.w3.org/2000/svg" width="320" height="180" viewBox="0 0 320 180"><rect width="100%" height="100%" fill="#fafafa" stroke="#eee"/></svg>')}finally{k(!1)}}},h=o=>{const x=a.current;x&&o(x)};return e.jsx("div",{onClick:t,style:{alignItems:"center",background:"rgb(0 0 0 / 35%)",display:"flex",inset:0,justifyContent:"center",overflow:"hidden",position:"fixed",zIndex:1e3},children:e.jsxs("div",{onClick:o=>o.stopPropagation(),onWheel:o=>o.stopPropagation(),style:{background:"#fff",borderRadius:10,boxShadow:"0 12px 30px rgb(0 0 0 / 20%)",display:"flex",flexDirection:"column",height:"86vh",maxHeight:"100%",maxWidth:"1200px",overflow:"hidden",width:"92vw"},children:[e.jsxs("div",{style:{alignItems:"center",borderBottom:"1px solid #f0f0f0",display:"flex",flexWrap:"wrap",gap:8,justifyContent:"space-between",padding:"10px 14px"},children:[e.jsx("span",{style:{fontWeight:600},children:r("meta2d.editor.title")}),e.jsxs("div",{style:{alignItems:"center",display:"flex",flexWrap:"wrap",gap:8},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:[e.jsx("button",{onClick:()=>h(o=>o.undo()),style:E,title:`${r("meta2d.editor.undo")} (Ctrl+Z)`,type:"button",children:r("meta2d.editor.undo")}),e.jsx("button",{onClick:()=>h(o=>o.redo()),style:E,title:`${r("meta2d.editor.redo")} (Ctrl+Y)`,type:"button",children:r("meta2d.editor.redo")}),e.jsx("button",{onClick:()=>h(o=>o.delete()),style:E,title:r("meta2d.editor.delete"),type:"button",children:r("meta2d.editor.delete")}),e.jsx("button",{onClick:()=>h(o=>o.fitView(!0)),style:E,title:r("meta2d.editor.fit"),type:"button",children:r("meta2d.editor.fit")}),e.jsx("button",{onClick:()=>h(o=>{o.scale(1),o.centerView()}),style:E,title:r("meta2d.editor.zoom100"),type:"button",children:r("meta2d.editor.zoom100")})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:t,style:L,type:"button",children:r("meta2d.editor.close")}),e.jsx("button",{disabled:B,onClick:()=>void C(),style:{...L,background:"#1677ff",border:"none",color:"#fff"},type:"button",children:r(B?"meta2d.editor.saving":"meta2d.editor.save")})]})]})]}),e.jsxs("div",{style:{display:"flex",flex:1,minHeight:0,overflow:"hidden"},children:[e.jsx(ne,{engineRef:a}),e.jsx("div",{ref:u,style:{flex:1,minHeight:0,minWidth:0}}),e.jsx(ie,{engine:p})]})]})})}export{ye as DiagramEditor};
@@ -1,4 +1,4 @@
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-OmOf_og0.js";import{r as I,j as n}from"./react-vendor-BuABiQkA.js";import{g as W}from"./file-type-policy-GUk904tm.js";/**
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-CUdIA5aE.js";import{r as I,j as n}from"./react-vendor-BuABiQkA.js";import{g as W}from"./file-type-policy-GUk904tm.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1 +1 @@
1
- import{r as n,j as a}from"./react-vendor-BuABiQkA.js";import{ad as ge}from"./ui-CvA4pq3d.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-OmOf_og0.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-CI5PDFXT.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-Hsam79hu.js";import{D as Ot,U as _t,S as Ht}from"./DocChrome-BWMgRxlr.js";import{V as zt}from"./VisitorPickerModal-CqHzml8s.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./editor-CL03se2B.js";import"./plus-DKKQ-AoS.js";import"./check-soiTDN2u.js";import"./copy-B4fvX0p8.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
+ import{r as n,j as a}from"./react-vendor-BuABiQkA.js";import{ad as ge}from"./ui-CvA4pq3d.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-CUdIA5aE.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-Bf45libg.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-CSKpV4ua.js";import{D as Ot,U as _t,S as Ht}from"./DocChrome-ixaNyUG9.js";import{V as zt}from"./VisitorPickerModal-CqDA1S9F.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./editor-CL03se2B.js";import"./plus-QDhBbIRF.js";import"./check-CN9m0reb.js";import"./copy-DFs3qk19.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 +1 @@
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-OmOf_og0.js";import{D as Ee,U as Ne,S as Me}from"./DocChrome-BWMgRxlr.js";import{V as Pe}from"./VisitorPickerModal-CqHzml8s.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.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};
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-CUdIA5aE.js";import{D as Ee,U as Ne,S as Me}from"./DocChrome-ixaNyUG9.js";import{V as Pe}from"./VisitorPickerModal-CqDA1S9F.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.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};
@@ -1,4 +1,4 @@
1
- import{r as x,j as i}from"./react-vendor-BuABiQkA.js";import{c as G,aD as H,aE as Y,aF as Z,aG as ee}from"./index-OmOf_og0.js";import{E as te,B as ne}from"./react-CI5PDFXT.js";import{g as le}from"./file-type-policy-GUk904tm.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./editor-CL03se2B.js";import"./plus-DKKQ-AoS.js";import"./check-soiTDN2u.js";import"./copy-B4fvX0p8.js";function U({lexicalJson:e,onMarkdown:n,onError:c}){const[s,l]=x.useState(null),o=x.useRef(!1);return x.useEffect(()=>{o.current=!1},[e]),x.useEffect(()=>{if(!(!s||o.current))try{s.setDocument("json",e);const a=s.getDocument("markdown");typeof a=="string"&&(o.current=!0,n(a))}catch{c==null||c()}},[s,e,n,c]),i.jsx("div",{className:"mdocs-lexical-md-bridge","aria-hidden":!0,children:i.jsx(te,{content:e,type:"json",editable:!1,onInit:l,plugins:[ne]})})}function se(e){const{t:n}=G(),[c,s]=x.useState(0),l=e.segments.filter(t=>t.kind==="conflict"),o=e.unresolvedCount>0;x.useEffect(()=>{if(l.length===0){s(0);return}s(t=>Math.min(t,l.length-1))},[l.length]);function a(t){l.length!==0&&s(d=>{var m;const u=(d+t+l.length)%l.length;return(m=document.getElementById(`mdocs-merge-hunk-${u}`))==null||m.scrollIntoView({block:"center",behavior:"smooth"}),u})}let r=-1;return i.jsxs("div",{className:"mdocs-merge-inline-pane",children:[i.jsxs("div",{className:"mdocs-merge-inline-toolbar",children:[i.jsx("span",{className:"mdocs-merge-inline-hint",children:o?n("mergeReviewHint"):l.length===0?n("mergeNoConflicts"):n("mergeEditAfterResolve")}),l.length>0?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",onClick:e.onUseAllMine,children:n("mergeUseAllMine")}),i.jsx("button",{type:"button",onClick:e.onUseAllTheirs,children:n("mergeUseAllTheirs")})]}):null]}),o?i.jsxs("div",{className:"mdocs-merge-inline",role:"document",children:[e.segments.map((t,d)=>{if(t.kind==="unchanged")return i.jsx("pre",{className:"mdocs-merge-inline-same",children:t.lines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line ctx",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},C))},`u-${d}`);r+=1;const u=r,m=t.resolution!=="unresolved",f=u===c;return i.jsxs("div",{id:`mdocs-merge-hunk-${u}`,className:"mdocs-merge-inline-hunk"+(f?" is-active":"")+(m?" is-resolved":""),onClick:()=>s(u),children:[m?i.jsx("div",{className:"mdocs-merge-hunk-resolved-tag",children:t.resolution==="remote"?n("mergeReceive"):n("mergeReject")}):i.jsxs("div",{className:"mdocs-merge-hunk-actions",children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:g=>{g.stopPropagation(),e.onReject(t.id)},children:n("mergeReject")}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:g=>{g.stopPropagation(),e.onReceive(t.id)},children:n("mergeReceive")})]}),i.jsxs("pre",{className:"mdocs-ai-write-hunk-pre",children:[t.localLines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line del",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},`l${C}`)),t.remoteLines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line add",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},`r${C}`))]})]},t.id)}),l.length>0?i.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"冲突导航",children:[i.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>a(-1),children:"↑"}),i.jsxs("span",{children:[c+1," / ",l.length]}),i.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>a(1),children:"↓"}),l[c]&&l[c].resolution==="unresolved"?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>e.onReject(l[c].id),children:n("mergeReject")}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>e.onReceive(l[c].id),children:n("mergeReceive")})]}):null]}):null]}):i.jsx("textarea",{className:"mdocs-merge-inline-editor",value:e.editableMarkdown,onChange:t=>e.onEditableChange(t.target.value),spellCheck:!1})]})}function ie(e,n){let c={};for(let o=0;o<n.length;o++){const a=n[o];c[a]?c[a].push(o):c[a]=[o]}let l=[{buffer1index:-1,buffer2index:-1,chain:null}];for(let o=0;o<e.length;o++){const a=e[o],r=c[a]||[];let t=0,d=l[0];for(let u=0;u<r.length;u++){const m=r[u];let f;for(f=t;f<l.length&&!(l[f].buffer2index<m&&(f===l.length-1||l[f+1].buffer2index>m));f++);if(f<l.length){const g={buffer1index:o,buffer2index:m,chain:l[f]};if(t===l.length?l.push(d):l[t]=d,t=f+1,d=g,t===l.length)break}}l[t]=d}return l[l.length-1]}function O(e,n){const c=ie(e,n);let s=[],l=e.length,o=n.length;for(let a=c;a!==null;a=a.chain){const r=l-a.buffer1index-1,t=o-a.buffer2index-1;l=a.buffer1index,o=a.buffer2index,(r||t)&&s.push({buffer1:[l+1,r],buffer1Content:e.slice(l+1,l+1+r),buffer2:[o+1,t],buffer2Content:n.slice(o+1,o+1+t)})}return s.reverse(),s}function oe(e,n,c){let s=[];function l(t,d){s.push({ab:d,oStart:t.buffer1[0],oLength:t.buffer1[1],abStart:t.buffer2[0],abLength:t.buffer2[1]})}O(n,e).forEach(t=>l(t,"a")),O(n,c).forEach(t=>l(t,"b")),s.sort((t,d)=>t.oStart-d.oStart);let o=[],a=0;function r(t){t>a&&(o.push({stable:!0,buffer:"o",bufferStart:a,bufferLength:t-a,bufferContent:n.slice(a,t)}),a=t)}for(;s.length;){let t=s.shift(),d=t.oStart,u=t.oStart+t.oLength,m=[t];for(r(d);s.length;){const f=s[0],g=f.oStart;if(g>u)break;u=Math.max(u,g+f.oLength),m.push(s.shift())}if(m.length===1){if(t.abLength>0){const f=t.ab==="a"?e:c;o.push({stable:!0,buffer:t.ab,bufferStart:t.abStart,bufferLength:t.abLength,bufferContent:f.slice(t.abStart,t.abStart+t.abLength)})}}else{let f={a:[e.length,-1,n.length,-1],b:[c.length,-1,n.length,-1]};for(;m.length;){t=m.shift();const b=t.oStart,w=b+t.oLength,L=t.abStart,y=L+t.abLength;let v=f[t.ab];v[0]=Math.min(L,v[0]),v[1]=Math.max(y,v[1]),v[2]=Math.min(b,v[2]),v[3]=Math.max(w,v[3])}const g=f.a[0]+(d-f.a[2]),C=f.a[1]+(u-f.a[3]),k=f.b[0]+(d-f.b[2]),h=f.b[1]+(u-f.b[3]);let p={stable:!1,aStart:g,aLength:C-g,aContent:e.slice(g,C),oStart:d,oLength:u-d,oContent:n.slice(d,u),bStart:k,bLength:h-k,bContent:c.slice(k,h)};o.push(p)}a=u}return r(n.length),o}function ce(e,n,c,s){s=Object.assign({excludeFalseConflicts:!0,stringSeparator:/\s+/},s),typeof e=="string"&&(e=e.split(s.stringSeparator)),typeof n=="string"&&(n=n.split(s.stringSeparator)),typeof c=="string"&&(c=c.split(s.stringSeparator));let o=[];const a=oe(e,n,c);let r=[];function t(){r.length&&o.push({ok:r}),r=[]}function d(u,m){if(u.length!==m.length)return!1;for(let f=0;f<u.length;f++)if(u[f]!==m[f])return!1;return!0}return a.forEach(u=>{u.stable?r.push(...u.bufferContent):s.excludeFalseConflicts&&d(u.aContent,u.bContent)?r.push(...u.aContent):(t(),o.push({conflict:{a:u.aContent,aIndex:u.aStart,o:u.oContent,oIndex:u.oStart,b:u.bContent,bIndex:u.bStart}}))}),t(),o}const ae=/^<!--\s*mdocs-merge-conflict:([^\s]+)\s*-->$/;function re(e){return`<!-- mdocs-merge-conflict:${e} -->`}function ue(e){const n=e.trim().match(ae);return(n==null?void 0:n[1])??null}function E(e){return e===""?[]:e.split(`
1
+ import{r as x,j as i}from"./react-vendor-BuABiQkA.js";import{c as G,aD as H,aE as Y,aF as Z,aG as ee}from"./index-CUdIA5aE.js";import{E as te,B as ne}from"./react-Bf45libg.js";import{g as le}from"./file-type-policy-GUk904tm.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./editor-CL03se2B.js";import"./plus-QDhBbIRF.js";import"./check-CN9m0reb.js";import"./copy-DFs3qk19.js";function U({lexicalJson:e,onMarkdown:n,onError:c}){const[s,l]=x.useState(null),o=x.useRef(!1);return x.useEffect(()=>{o.current=!1},[e]),x.useEffect(()=>{if(!(!s||o.current))try{s.setDocument("json",e);const a=s.getDocument("markdown");typeof a=="string"&&(o.current=!0,n(a))}catch{c==null||c()}},[s,e,n,c]),i.jsx("div",{className:"mdocs-lexical-md-bridge","aria-hidden":!0,children:i.jsx(te,{content:e,type:"json",editable:!1,onInit:l,plugins:[ne]})})}function se(e){const{t:n}=G(),[c,s]=x.useState(0),l=e.segments.filter(t=>t.kind==="conflict"),o=e.unresolvedCount>0;x.useEffect(()=>{if(l.length===0){s(0);return}s(t=>Math.min(t,l.length-1))},[l.length]);function a(t){l.length!==0&&s(d=>{var m;const u=(d+t+l.length)%l.length;return(m=document.getElementById(`mdocs-merge-hunk-${u}`))==null||m.scrollIntoView({block:"center",behavior:"smooth"}),u})}let r=-1;return i.jsxs("div",{className:"mdocs-merge-inline-pane",children:[i.jsxs("div",{className:"mdocs-merge-inline-toolbar",children:[i.jsx("span",{className:"mdocs-merge-inline-hint",children:o?n("mergeReviewHint"):l.length===0?n("mergeNoConflicts"):n("mergeEditAfterResolve")}),l.length>0?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",onClick:e.onUseAllMine,children:n("mergeUseAllMine")}),i.jsx("button",{type:"button",onClick:e.onUseAllTheirs,children:n("mergeUseAllTheirs")})]}):null]}),o?i.jsxs("div",{className:"mdocs-merge-inline",role:"document",children:[e.segments.map((t,d)=>{if(t.kind==="unchanged")return i.jsx("pre",{className:"mdocs-merge-inline-same",children:t.lines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line ctx",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},C))},`u-${d}`);r+=1;const u=r,m=t.resolution!=="unresolved",f=u===c;return i.jsxs("div",{id:`mdocs-merge-hunk-${u}`,className:"mdocs-merge-inline-hunk"+(f?" is-active":"")+(m?" is-resolved":""),onClick:()=>s(u),children:[m?i.jsx("div",{className:"mdocs-merge-hunk-resolved-tag",children:t.resolution==="remote"?n("mergeReceive"):n("mergeReject")}):i.jsxs("div",{className:"mdocs-merge-hunk-actions",children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:g=>{g.stopPropagation(),e.onReject(t.id)},children:n("mergeReject")}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:g=>{g.stopPropagation(),e.onReceive(t.id)},children:n("mergeReceive")})]}),i.jsxs("pre",{className:"mdocs-ai-write-hunk-pre",children:[t.localLines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line del",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},`l${C}`)),t.remoteLines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line add",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},`r${C}`))]})]},t.id)}),l.length>0?i.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"冲突导航",children:[i.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>a(-1),children:"↑"}),i.jsxs("span",{children:[c+1," / ",l.length]}),i.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>a(1),children:"↓"}),l[c]&&l[c].resolution==="unresolved"?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>e.onReject(l[c].id),children:n("mergeReject")}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>e.onReceive(l[c].id),children:n("mergeReceive")})]}):null]}):null]}):i.jsx("textarea",{className:"mdocs-merge-inline-editor",value:e.editableMarkdown,onChange:t=>e.onEditableChange(t.target.value),spellCheck:!1})]})}function ie(e,n){let c={};for(let o=0;o<n.length;o++){const a=n[o];c[a]?c[a].push(o):c[a]=[o]}let l=[{buffer1index:-1,buffer2index:-1,chain:null}];for(let o=0;o<e.length;o++){const a=e[o],r=c[a]||[];let t=0,d=l[0];for(let u=0;u<r.length;u++){const m=r[u];let f;for(f=t;f<l.length&&!(l[f].buffer2index<m&&(f===l.length-1||l[f+1].buffer2index>m));f++);if(f<l.length){const g={buffer1index:o,buffer2index:m,chain:l[f]};if(t===l.length?l.push(d):l[t]=d,t=f+1,d=g,t===l.length)break}}l[t]=d}return l[l.length-1]}function O(e,n){const c=ie(e,n);let s=[],l=e.length,o=n.length;for(let a=c;a!==null;a=a.chain){const r=l-a.buffer1index-1,t=o-a.buffer2index-1;l=a.buffer1index,o=a.buffer2index,(r||t)&&s.push({buffer1:[l+1,r],buffer1Content:e.slice(l+1,l+1+r),buffer2:[o+1,t],buffer2Content:n.slice(o+1,o+1+t)})}return s.reverse(),s}function oe(e,n,c){let s=[];function l(t,d){s.push({ab:d,oStart:t.buffer1[0],oLength:t.buffer1[1],abStart:t.buffer2[0],abLength:t.buffer2[1]})}O(n,e).forEach(t=>l(t,"a")),O(n,c).forEach(t=>l(t,"b")),s.sort((t,d)=>t.oStart-d.oStart);let o=[],a=0;function r(t){t>a&&(o.push({stable:!0,buffer:"o",bufferStart:a,bufferLength:t-a,bufferContent:n.slice(a,t)}),a=t)}for(;s.length;){let t=s.shift(),d=t.oStart,u=t.oStart+t.oLength,m=[t];for(r(d);s.length;){const f=s[0],g=f.oStart;if(g>u)break;u=Math.max(u,g+f.oLength),m.push(s.shift())}if(m.length===1){if(t.abLength>0){const f=t.ab==="a"?e:c;o.push({stable:!0,buffer:t.ab,bufferStart:t.abStart,bufferLength:t.abLength,bufferContent:f.slice(t.abStart,t.abStart+t.abLength)})}}else{let f={a:[e.length,-1,n.length,-1],b:[c.length,-1,n.length,-1]};for(;m.length;){t=m.shift();const b=t.oStart,w=b+t.oLength,L=t.abStart,y=L+t.abLength;let v=f[t.ab];v[0]=Math.min(L,v[0]),v[1]=Math.max(y,v[1]),v[2]=Math.min(b,v[2]),v[3]=Math.max(w,v[3])}const g=f.a[0]+(d-f.a[2]),C=f.a[1]+(u-f.a[3]),k=f.b[0]+(d-f.b[2]),h=f.b[1]+(u-f.b[3]);let p={stable:!1,aStart:g,aLength:C-g,aContent:e.slice(g,C),oStart:d,oLength:u-d,oContent:n.slice(d,u),bStart:k,bLength:h-k,bContent:c.slice(k,h)};o.push(p)}a=u}return r(n.length),o}function ce(e,n,c,s){s=Object.assign({excludeFalseConflicts:!0,stringSeparator:/\s+/},s),typeof e=="string"&&(e=e.split(s.stringSeparator)),typeof n=="string"&&(n=n.split(s.stringSeparator)),typeof c=="string"&&(c=c.split(s.stringSeparator));let o=[];const a=oe(e,n,c);let r=[];function t(){r.length&&o.push({ok:r}),r=[]}function d(u,m){if(u.length!==m.length)return!1;for(let f=0;f<u.length;f++)if(u[f]!==m[f])return!1;return!0}return a.forEach(u=>{u.stable?r.push(...u.bufferContent):s.excludeFalseConflicts&&d(u.aContent,u.bContent)?r.push(...u.aContent):(t(),o.push({conflict:{a:u.aContent,aIndex:u.aStart,o:u.oContent,oIndex:u.oStart,b:u.bContent,bIndex:u.bStart}}))}),t(),o}const ae=/^<!--\s*mdocs-merge-conflict:([^\s]+)\s*-->$/;function re(e){return`<!-- mdocs-merge-conflict:${e} -->`}function ue(e){const n=e.trim().match(ae);return(n==null?void 0:n[1])??null}function E(e){return e===""?[]:e.split(`
2
2
  `)}function V(e,n){return e.length===n.length&&e.every((c,s)=>c===n[s])}function de(e,n,c){const s=E(e),l=E(n),o=E(c);if(l.length===0&&n==="")return me(e,c);const a=ce(s,l,o),r=[];let t=0,d=0,u=0,m=0;const f=(C,k,h,p)=>{r.push({kind:"conflict",id:`conflict-${t}`,conflictKind:p,baseLines:C,localLines:k,remoteLines:h,resolution:"unresolved"}),t+=1},g=(C,k,h)=>{if(k.length===0&&C.length===0&&h.length===0)return;if(V(C,k)&&V(h,k)){k.length>0&&r.push({kind:"unchanged",lines:[...k]});return}if(C.length===k.length&&h.length===k.length){let b=[];const w=()=>{b.length>0&&(r.push({kind:"unchanged",lines:b}),b=[])};for(let L=0;L<k.length;L+=1){const y=k[L],v=C[L],I=h[L];v===y&&I===y?b.push(y):(w(),f([y],[v],[I],v!==y&&I!==y&&v!==I?"true_conflict":"change"))}w();return}const p=C.join(`
3
3
  `)!==k.join(`
4
4
  `)&&h.join(`
@@ -1,4 +1,4 @@
1
- import{r as n,j as o,ad as C}from"./react-vendor-BuABiQkA.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as L,w as f,j as H,k as F,l as q,I as U,m as b,n as V,o as J,p as W,q as z,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-CI5PDFXT.js";import{a7 as Q,a8 as X,a9 as ee,aa as te,ab as k,ac as oe}from"./ui-CvA4pq3d.js";import{H as re,a as ae,b as ne,M as le,T as ie,S as se,W as de,c as R,o as ce}from"./Toolbar-Hsam79hu.js";import{N as me}from"./index-OmOf_og0.js";import"./editor-CL03se2B.js";import"./diagram-Bk84WZto.js";import"./plus-DKKQ-AoS.js";import"./check-soiTDN2u.js";import"./copy-B4fvX0p8.js";import"./motion-DFABYlwt.js";const ue=({children:h,json:r,markdown:a,collapsible:m=!1,defaultActiveKey:y=["editor","text","json"],onJSONChange:p})=>{const[g,c]=n.useState(r),s=n.useRef(r);n.useEffect(()=>{r!==s.current&&(c(r),s.current=r)},[r]);const x=n.useCallback(d=>{s.current=d,c(d)},[]);return o.jsxs(o.Fragment,{children:[o.jsx(Q,{}),o.jsx(X,{collapsible:m,defaultActiveKey:y,items:[{children:h,key:"editor",label:"Playground"},{children:o.jsx(ee,{language:"markdown",style:{fontSize:12,padding:16},variant:"borderless",children:a}),key:"text",label:"Text Output"},{children:o.jsx(te,{language:"json",onBlur:()=>{if(r!==s.current)try{const d=JSON.parse(s.current||"");p==null||p(d)}catch(d){console.error("Invalid JSON:",d)}},onValueChange:x,value:g,variant:"borderless"}),key:"json",label:"JSON Output"}],padding:{body:0},style:{border:"none",borderRadius:0,width:"100%"},variant:"outlined"})]})},he={children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Welcome to the Lobe Editor Demo!",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",version:1,tag:"h1"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"In case you were wondering what the black box at the bottom is – it's the debug view, showing the current state of the editor. You can disable it by pressing on the settings control in the bottom-left of your screen and toggling the debug view setting.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"quote",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"The playground is a demo environment built with ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"@lobehub/editor",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"codeInline",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:". Try typing in ",type:"text",version:1},{detail:0,format:1,mode:"normal",style:"",text:"some text",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:" with ",type:"text",version:1},{detail:0,format:2,mode:"normal",style:"",text:"different formats",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Visit the ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lobe Editor website",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://editor.lobehub.com"},{detail:0,format:0,mode:"normal",style:"",text:" for documentation and more information.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Check out the code on our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"GitHub repository",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://github.com/lobehub/lobe-editor",url:"https://github.com/lobehub/lobe-editor"},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:2},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://github.com/lobehub/lobe-editor/blob/master/src/react/Editor/demos/index.tsx"},{detail:0,format:0,mode:"normal",style:"",text:" can be found here.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:3},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Join our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Discover Server",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://discord.gg/AYFPHvv2jT",url:"https://discord.gg/AYFPHvv2jT"},{detail:0,format:0,mode:"normal",style:"",text:" and chat with the team.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:4}],direction:"ltr",format:"",indent:0,type:"list",version:1,listType:"bullet",start:1,tag:"ul"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lastly, we're constantly adding cool new features to this playground. So make sure you check back here when you next get a chance 🙂.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"import",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"{",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:"Editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"}",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"from",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-success);",text:"@lobehub/editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:";",type:"code-highlight",version:1}],direction:null,format:"",indent:0,type:"code",version:1,language:"typescript",theme:"lobe-theme"},{children:[],direction:null,format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""}],direction:"ltr",format:"",indent:0,type:"root",version:1},ye={root:he};function S(h,r){let a;const m=(...y)=>{a!==void 0&&clearTimeout(a),a=setTimeout(()=>h(...y),r)};return m.cancel=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},m}window.__scrollIntoView=Z;const pe=h=>{const r=N(),a=n.useRef([]),[m,y]=n.useState(""),[p,g]=n.useState(""),c=n.useMemo(()=>S(t=>{const e=t.getDocument("markdown"),l=t.getDocument("json");g(e||""),y(JSON.stringify(l||{},null,2))},200),[]),s=n.useMemo(()=>S(t=>{r&&(console.info("handleJSONChange",t),r.setDocument("json",t))},200),[r]),x=t=>{window.editor=t,c(t)};n.useEffect(()=>()=>{for(const t of a.current)URL.revokeObjectURL(t);a.current=[],c.cancel(),s.cancel(),delete window.editor,delete window.__scrollIntoView},[c,s]);const d=n.useMemo(()=>[{icon:o.jsx(k,{avatar:"💻",size:24}),key:"bot1",label:"前端研发专家",metadata:{id:"bot1"}},{icon:o.jsx(k,{avatar:"🌍",size:24}),key:"bot2",label:"中英文互译助手",metadata:{id:"bot2"}},{icon:o.jsx(k,{avatar:"📖",size:24}),key:"bot3",label:"学术写作增强专家",metadata:{id:"bot3"}}],[]),w=n.useMemo(()=>[{icon:re,key:"h1",label:"Heading 1",onSelect:e=>{e.dispatchCommand(b,{tag:"h1"})}},{icon:ae,key:"h2",label:"Heading 2",onSelect:e=>{e.dispatchCommand(b,{tag:"h2"})}},{icon:ne,key:"h3",label:"Heading 3",onSelect:e=>{e.dispatchCommand(b,{tag:"h3"})}},{type:"divider"},{icon:le,key:"hr",label:"Hr",onSelect:e=>{e.dispatchCommand(V,{})}},{icon:ie,key:"table",label:"Table",onSelect:e=>{e.dispatchCommand(J,{columns:"3",rows:"3"})}},{icon:se,key:"tex",label:"Tex",onSelect:e=>{e.dispatchCommand(W,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>{e.focus()})}},{type:"divider"},{key:"file",label:"File",onSelect:e=>{ce(l=>{for(const u of l)e.dispatchCommand(z,{file:u})})}},{key:"set-text-content",label:"SetTextContent",onSelect:e=>{e.setDocument("text",`123
1
+ import{r as n,j as o,ad as C}from"./react-vendor-BuABiQkA.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as L,w as f,j as H,k as F,l as q,I as U,m as b,n as V,o as J,p as W,q as z,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-Bf45libg.js";import{a7 as Q,a8 as X,a9 as ee,aa as te,ab as k,ac as oe}from"./ui-CvA4pq3d.js";import{H as re,a as ae,b as ne,M as le,T as ie,S as se,W as de,c as R,o as ce}from"./Toolbar-CSKpV4ua.js";import{N as me}from"./index-CUdIA5aE.js";import"./editor-CL03se2B.js";import"./diagram-Bk84WZto.js";import"./plus-QDhBbIRF.js";import"./check-CN9m0reb.js";import"./copy-DFs3qk19.js";import"./motion-DFABYlwt.js";const ue=({children:h,json:r,markdown:a,collapsible:m=!1,defaultActiveKey:y=["editor","text","json"],onJSONChange:p})=>{const[g,c]=n.useState(r),s=n.useRef(r);n.useEffect(()=>{r!==s.current&&(c(r),s.current=r)},[r]);const x=n.useCallback(d=>{s.current=d,c(d)},[]);return o.jsxs(o.Fragment,{children:[o.jsx(Q,{}),o.jsx(X,{collapsible:m,defaultActiveKey:y,items:[{children:h,key:"editor",label:"Playground"},{children:o.jsx(ee,{language:"markdown",style:{fontSize:12,padding:16},variant:"borderless",children:a}),key:"text",label:"Text Output"},{children:o.jsx(te,{language:"json",onBlur:()=>{if(r!==s.current)try{const d=JSON.parse(s.current||"");p==null||p(d)}catch(d){console.error("Invalid JSON:",d)}},onValueChange:x,value:g,variant:"borderless"}),key:"json",label:"JSON Output"}],padding:{body:0},style:{border:"none",borderRadius:0,width:"100%"},variant:"outlined"})]})},he={children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Welcome to the Lobe Editor Demo!",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",version:1,tag:"h1"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"In case you were wondering what the black box at the bottom is – it's the debug view, showing the current state of the editor. You can disable it by pressing on the settings control in the bottom-left of your screen and toggling the debug view setting.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"quote",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"The playground is a demo environment built with ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"@lobehub/editor",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"codeInline",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:". Try typing in ",type:"text",version:1},{detail:0,format:1,mode:"normal",style:"",text:"some text",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:" with ",type:"text",version:1},{detail:0,format:2,mode:"normal",style:"",text:"different formats",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Visit the ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lobe Editor website",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://editor.lobehub.com"},{detail:0,format:0,mode:"normal",style:"",text:" for documentation and more information.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Check out the code on our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"GitHub repository",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://github.com/lobehub/lobe-editor",url:"https://github.com/lobehub/lobe-editor"},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:2},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://github.com/lobehub/lobe-editor/blob/master/src/react/Editor/demos/index.tsx"},{detail:0,format:0,mode:"normal",style:"",text:" can be found here.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:3},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Join our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Discover Server",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://discord.gg/AYFPHvv2jT",url:"https://discord.gg/AYFPHvv2jT"},{detail:0,format:0,mode:"normal",style:"",text:" and chat with the team.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:4}],direction:"ltr",format:"",indent:0,type:"list",version:1,listType:"bullet",start:1,tag:"ul"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lastly, we're constantly adding cool new features to this playground. So make sure you check back here when you next get a chance 🙂.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"import",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"{",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:"Editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"}",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"from",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-success);",text:"@lobehub/editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:";",type:"code-highlight",version:1}],direction:null,format:"",indent:0,type:"code",version:1,language:"typescript",theme:"lobe-theme"},{children:[],direction:null,format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""}],direction:"ltr",format:"",indent:0,type:"root",version:1},ye={root:he};function S(h,r){let a;const m=(...y)=>{a!==void 0&&clearTimeout(a),a=setTimeout(()=>h(...y),r)};return m.cancel=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},m}window.__scrollIntoView=Z;const pe=h=>{const r=N(),a=n.useRef([]),[m,y]=n.useState(""),[p,g]=n.useState(""),c=n.useMemo(()=>S(t=>{const e=t.getDocument("markdown"),l=t.getDocument("json");g(e||""),y(JSON.stringify(l||{},null,2))},200),[]),s=n.useMemo(()=>S(t=>{r&&(console.info("handleJSONChange",t),r.setDocument("json",t))},200),[r]),x=t=>{window.editor=t,c(t)};n.useEffect(()=>()=>{for(const t of a.current)URL.revokeObjectURL(t);a.current=[],c.cancel(),s.cancel(),delete window.editor,delete window.__scrollIntoView},[c,s]);const d=n.useMemo(()=>[{icon:o.jsx(k,{avatar:"💻",size:24}),key:"bot1",label:"前端研发专家",metadata:{id:"bot1"}},{icon:o.jsx(k,{avatar:"🌍",size:24}),key:"bot2",label:"中英文互译助手",metadata:{id:"bot2"}},{icon:o.jsx(k,{avatar:"📖",size:24}),key:"bot3",label:"学术写作增强专家",metadata:{id:"bot3"}}],[]),w=n.useMemo(()=>[{icon:re,key:"h1",label:"Heading 1",onSelect:e=>{e.dispatchCommand(b,{tag:"h1"})}},{icon:ae,key:"h2",label:"Heading 2",onSelect:e=>{e.dispatchCommand(b,{tag:"h2"})}},{icon:ne,key:"h3",label:"Heading 3",onSelect:e=>{e.dispatchCommand(b,{tag:"h3"})}},{type:"divider"},{icon:le,key:"hr",label:"Hr",onSelect:e=>{e.dispatchCommand(V,{})}},{icon:ie,key:"table",label:"Table",onSelect:e=>{e.dispatchCommand(J,{columns:"3",rows:"3"})}},{icon:se,key:"tex",label:"Tex",onSelect:e=>{e.dispatchCommand(W,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>{e.focus()})}},{type:"divider"},{key:"file",label:"File",onSelect:e=>{ce(l=>{for(const u of l)e.dispatchCommand(z,{file:u})})}},{key:"set-text-content",label:"SetTextContent",onSelect:e=>{e.setDocument("text",`123
2
2
  123`),queueMicrotask(()=>{e.focus()})}},{key:"insert-link",label:"InsertLink",onSelect:e=>{e.dispatchCommand(B,{url:"https://example.com"}),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeInline",label:"InsertCodeInline",onSelect:e=>{e.dispatchCommand($,void 0),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeBlock",label:"InsertCodeBlock",onSelect:e=>{e.dispatchCommand(K,void 0),queueMicrotask(()=>{e.focus()})}},{icon:de,key:"meta2d",label:"Meta2d",onSelect:e=>{e.dispatchCommand(Y,void 0),queueMicrotask(()=>{e.focus()})}},{icon:me,key:"markmap",label:"Markmap",onSelect:e=>{e.dispatchCommand(G,void 0),queueMicrotask(()=>{e.focus()})}}].map(e=>e.type==="divider"?e:{...e,extra:o.jsx(oe,{code:!0,fontSize:12,type:"secondary",children:e.key})}),[]);return o.jsxs(ue,{json:m,markdown:p,onJSONChange:s,...h,children:[o.jsx(R,{editor:r}),o.jsx(T,{className:"mdocs-playground-editor",content:ye,editor:r,lineEmptyPlaceholder:"Start typing here...",mentionOption:{items:d,markdownWriter:t=>{var e;return`
3
3
  <mention>${t.label}[${((e=t.metadata)==null?void 0:e.id)||t.label}]</mention>
4
4
  `},onSelect:(t,e)=>{t.dispatchCommand(U,{label:String(e.label),metadata:{id:e.key}})},searchKeys:["label"]},onInit:x,onTextChange:c,pasteVSCodeAsCodeBlock:!0,placeholder:"Type something...",plugins:[I,E,M,j,O,P,A,_,D,L,f(H,{children:o.jsx(R,{editor:r,floating:!0})}),f(F,{delay:1e3,onAutoComplete:async({input:t,afterText:e,selectionType:l,abortSignal:u})=>{console.log("Auto-complete triggered:",{afterText:e,input:t,selectionType:l});try{const v=await fetch(`${location.origin}/nodeserver/completion`,{body:JSON.stringify({prompt:`Please complete the following text:
@@ -0,0 +1,6 @@
1
+ import{r as a,j as e}from"./react-vendor-BuABiQkA.js";import{o as bs,c as ie,t as Ns,v as vs,p as ks,l as Ae,w as ws,x as Ss,y as Q,z as Pe,A as Cs,B as Ds,G as Is,a as Ts,d as Oe,H as Ye,I as qe,J as As,K as Ps,L as Ms,O as Es,Q as Rs,T as Xe,U as Ie,V as Ls,W as Fs,X as zs,Y as Bs,Z as $s,_ as Ks,f as Qe,$ as Os,a0 as Vs,a1 as Us,a2 as Ws,a3 as _s,a4 as es,a5 as Gs,a6 as Hs,a7 as Js,a8 as Zs,a9 as Ys,aa as qs,ab as Xs,ac as Qs,ad as et,ae as st,af as tt,ag as at,ah as nt,P as it,ai as ct,aj as lt,ak as ot,r as rt,j as dt,al as mt,k as ut,m as ht}from"./index-CUdIA5aE.js";import{V as ss,a as pt,M as Ve}from"./VisitorPickerModal-CqDA1S9F.js";import{C as gt}from"./check-CN9m0reb.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.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 ft=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],xt=bs("search",ft);function jt({draft:t,onClose:s,onSuccess:j}){const{t:d,lang:p}=ie(),[B,u]=a.useState([]),[w,N]=a.useState(t.domainId??""),[g,k]=a.useState([]),[T,S]=a.useState(""),[c,x]=a.useState(`${t.displayName||"untitled"}_recovered.md`),[o,h]=a.useState(!1),[I,A]=a.useState(null),y=a.useRef(null),M=a.useRef(!0);a.useEffect(()=>(M.current=!0,()=>{M.current=!1}),[]),a.useEffect(()=>{Ns().then(v=>{M.current&&u(v)})},[]),a.useEffect(()=>{w&&(k([]),S(""),vs(w).then(v=>{M.current&&k(v)}).catch(()=>{M.current&&k([])}))},[w]),a.useEffect(()=>{const v=window.setTimeout(()=>{var P;return(P=y.current)==null?void 0:P.focus()},0);return()=>window.clearTimeout(v)},[]),a.useEffect(()=>{const v=P=>{P.key==="Escape"&&s()};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[s]);function z(v,P){for(const C of v){if(C.type==="folder"&&C.path===P)return C.documentId;if(C.type==="folder"){const E=z(C.children,P);if(E)return E}}return null}async function F(v){v.preventDefault(),h(!0),A(null);const P=c.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),C=P.endsWith(".md")?P:P+".md",E=C.replace(/\.md$/i,"");try{const m=T?`${T}/${C}`:C,l=T?z(g,T)??void 0:void 0;await Ss({fileName:C,displayName:E,content:t.content,domainId:w,parentId:l}),j()}catch(m){A(Q(d,m))}finally{h(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:v=>{v.target===v.currentTarget&&!o&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:d("recoverDraft")}),e.jsx("p",{className:"muted",children:d("recoverDraftDesc",{name:t.displayName||d("unknownTitle")})}),e.jsxs("form",{onSubmit:F,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[d("domainLabel"),B.length>0&&e.jsx(ks,{domains:B,value:w,onChange:N,onDomainsChange:u,ariaLabel:d("domainLabel"),localizeName:v=>Ae(v,p,d)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[d("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(ws,{nodes:g,activeDocumentId:null,selectedParentPath:T,onOpen:()=>{},onOpenFolder:v=>S(v),onContextMenu:()=>{},onDeselect:()=>S("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[d("fileNameLabel"),e.jsx("input",{ref:y,value:c,onChange:v=>x(v.target.value),placeholder:"recovered.md",maxLength:200,disabled:o})]}),I&&e.jsx("div",{className:"mdocs-dialog-error",children:I}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!o&&s(),disabled:o,children:d("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:o,children:d(o?"creating":"create")})]})]})]})})}function yt({onPublish:t,onClose:s,onCountChange:j,onRecover:d}){const{t:p}=ie(),[B,u]=a.useState([]),[w,N]=a.useState(new Set),[g,k]=a.useState(!1),[T,S]=a.useState(null),[c,x]=a.useState(null),[o,h]=a.useState(null),I=a.useRef(null),A=a.useRef(!0);a.useEffect(()=>(A.current=!0,Pe().then(l=>{if(!A.current)return;const f=l.filter(D=>!D.published);u(f),j==null||j(f.length)}),()=>{A.current=!1,I.current&&(clearTimeout(I.current),I.current=null)}),[]),a.useEffect(()=>{const l=f=>{f.key==="Escape"&&s()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[s]);const y=a.useCallback((l,f)=>{h({message:l,type:f}),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>h(null),3e3)},[]);async function M(l){await Ds(l),N(f=>new Set(f).add(l));try{await t(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),y(p("published"),"success")}catch(f){f instanceof Is||y(p("publishFailed"),"error");const D=await Ts(l);D&&u($=>$.map(U=>U.documentId===l?D:U))}finally{N(f=>{const D=new Set(f);return D.delete(l),D})}}async function z(l){S(null),await Oe(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),y(p("draftDeleted"),"success")}function F(l){const f=B.find(D=>D.documentId===l);f&&x(f)}function v(l){x(null),Oe(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),d==null||d(B.find(f=>f.documentId===l)),y(p("published"),"success")}async function P(){k(!0);let l=0,f=0;for(const U of B)try{await t(U.documentId),l++}catch{f++}const $=(await Pe()).filter(U=>!U.published);u($),j==null||j($.length),f===0?y(p("publishAll"),"success"):y(`${l} published, ${f} failed`,"error"),k(!1)}const C=l=>new Date(l).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),E=l=>Cs(p,l,l.publishError??"UNKNOWN"),m=B;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-drawer-overlay",onClick:s}),e.jsxs("div",{className:"mdocs-drawer",role:"dialog","aria-modal":"true",children:[e.jsxs("header",{className:"mdocs-drawer-header",children:[e.jsxs("div",{className:"mdocs-drawer-header-text",children:[e.jsxs("h2",{className:"mdocs-drawer-title",children:[p("unpublishedDrafts"),m.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:m.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:p("draftCount",{count:String(m.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":p("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:m.length===0?e.jsxs("div",{className:"mdocs-drawer-empty",children:[e.jsx("div",{className:"mdocs-drawer-empty-icon","aria-hidden":"true",children:"✓"}),e.jsx("p",{className:"mdocs-drawer-empty-text",children:p("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:m.map(l=>{const f=!!l.publishError;return e.jsxs("div",{className:f?"mdocs-drawer-item mdocs-drawer-item-failed":"mdocs-drawer-item",children:[e.jsx("div",{className:"mdocs-drawer-item-icon","aria-hidden":"true",children:"📄"}),e.jsxs("div",{className:"mdocs-drawer-item-info",children:[e.jsx("span",{className:"mdocs-drawer-item-name",children:l.displayName||p("unknownTitle")}),f?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[C(l.publishErrorAt)," · ",E(l)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[C(l.updatedAt)," · ",p("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[f?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:g,onClick:()=>F(l.documentId),children:p("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:w.has(l.documentId)||g,onClick:()=>void M(l.documentId),children:w.has(l.documentId)?p("publishing"):p("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:g,onClick:()=>S(l.documentId),children:p("delete")})]})]},l.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:p("close")}),e.jsx("button",{type:"button",className:"primary",disabled:m.length===0||g,onClick:()=>void P(),children:g?p("publishing"):`${p("publishAll")} (${m.length})`})]}),o&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+o.type,role:"status",children:o.message})]}),T&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:l=>{l.target===l.currentTarget&&S(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:p("delete")}),e.jsx("p",{className:"muted",children:p("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>S(null),children:p("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void z(T),children:p("delete")})]})]})}),c&&e.jsx(jt,{draft:c,onClose:()=>x(null),onSuccess:()=>v(c.documentId)})]})}function bt(){const{t,lang:s}=ie(),j=Ye(),d=a.useRef(!1),[p,B]=a.useState([]),[u,w]=a.useState(!1),[N,g]=a.useState(""),[k,T]=a.useState("restricted"),[S,c]=a.useState(!1),[x,o]=a.useState(null),[h,I]=a.useState(null),[A,y]=a.useState(""),[M,z]=a.useState(""),[F,v]=a.useState("all"),[P,C]=a.useState(null);a.useEffect(()=>(d.current=!0,()=>{d.current=!1}),[]);const E=a.useCallback(async()=>{w(!0),o(null);try{const b=await qe();if(!d.current)return;B(b)}catch(b){if(!d.current)return;o(Q(t,b))}finally{d.current&&w(!1)}},[t]);a.useEffect(()=>{E()},[E]);async function m(b){if(b.preventDefault(),!N.trim()){o(t("domainNameRequired"));return}c(!0),o(null);try{if(await Rs({domainName:N.trim(),permission:k}),!d.current)return;g(""),T("restricted"),await E()}catch(K){if(!d.current)return;o(Q(t,K))}finally{d.current&&c(!1)}}async function l(b){if(A.trim()){o(null);try{if(await Es(b,A.trim()),!d.current)return;I(null),C(null),await E()}catch(K){if(!d.current)return;o(Q(t,K))}}}function f(b){I(b.domainId),y(b.domainName),C(null)}function D(){I(null),C(null)}async function $(b,K){o(null);try{if(await Ms(b,K),!d.current)return;C(null),await E()}catch(W){if(!d.current)return;o(Q(t,W))}}async function U(b){if(window.confirm(t("deleteDomainConfirmDetail",{name:b.domainName,count:String(b.docCount)}))){o(null);try{if(await Ps(b.domainId),!d.current)return;await E()}catch(K){if(!d.current)return;o(Q(t,K))}}}const Z=a.useCallback(b=>As(b,t),[t]),Y=a.useCallback(b=>Ae(b.domainName,s,t),[s,t]),q=a.useMemo(()=>{const b=M.trim().toLowerCase();return p.filter(K=>F!=="all"&&K.permission!==F?!1:b?Ae(K.domainName,s,t).toLowerCase().includes(b)||K.domainName.toLowerCase().includes(b):!0)},[p,M,F,s,t]),_=a.useCallback((b,K)=>{const W=Z(b.permission);return K?`${W} ${t("domainTypeBuiltinSuffix")}`:W},[Z,t]);return{domains:p,loadingDomains:u,domainError:x,newDomainName:N,setNewDomainName:g,newDomainPermission:k,setNewDomainPermission:T,creating:S,handleCreateDomain:m,renamingId:h,setRenamingId:I,renameDraft:A,setRenameDraft:y,startRename:f,cancelRename:D,handleRename:l,changeTypeForId:P,setChangeTypeForId:C,handlePermissionChange:$,handleDelete:U,domainSearch:M,setDomainSearch:z,domainFilter:F,setDomainFilter:v,filteredDomains:q,visitorId:j,plabel:Z,localizeDomain:Y,domainTypeLabel:_}}const Ue={private:0,restricted:1,public:2};function We(t){return Object.prototype.hasOwnProperty.call(Ue,t)?Ue[t]:null}function _e(t,s){const j=We(t),d=We(s);return j===null||d===null?"invalid":d>j?"upgrade":d<j?"downgrade":"same"}function Nt(){const{t}=ie(),s=bt(),[j,d]=a.useState([]),[p,B]=a.useState(null),[u,w]=a.useState(""),N=a.useRef(null),[g,k]=a.useState(null),T=a.useCallback(async()=>{try{const c=await Xe();d(c)}catch{d([])}},[]);a.useEffect(()=>{T()},[T]),a.useEffect(()=>{if(!s.changeTypeForId)return;const c=x=>{var o;(o=N.current)!=null&&o.contains(x.target)||s.setChangeTypeForId(null)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s.changeTypeForId,s.setChangeTypeForId]);async function S(c){B(null);try{const x=await Ks(c.domainId);k({domainId:c.domainId,creatorVisitorId:c.creatorVisitorId,initialIds:x.map(o=>o.visitorId),memberRows:x})}catch(x){B({kind:"err",text:translateError(t,x)})}}return e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:t("domainManagement")})}),e.jsx("p",{className:"mdocs-domain-mgmt-restricted-hint",children:t("domainMgmtRestrictedMemberHint")}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-domain-mgmt-create",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("createDomain")}),e.jsxs("form",{onSubmit:s.handleCreateDomain,className:"mdocs-domain-mgmt-create-form",children:[e.jsxs("label",{className:"mdocs-domain-mgmt-field",children:[e.jsx("span",{className:"mdocs-domain-mgmt-label",children:t("domainName")}),e.jsx("input",{value:s.newDomainName,onChange:c=>s.setNewDomainName(c.target.value),placeholder:t("domainName"),maxLength:100,disabled:s.creating,className:"mdocs-domain-name-input"})]}),e.jsxs("fieldset",{className:"mdocs-domain-mgmt-fieldset",children:[e.jsx("legend",{className:"mdocs-domain-mgmt-label",children:t("domainPermission")}),e.jsx("div",{className:"mdocs-domain-mgmt-type-radios",children:Ie.map(c=>e.jsxs("label",{className:"mdocs-domain-mgmt-radio",children:[e.jsx("input",{type:"radio",name:"newDomainPermission",checked:s.newDomainPermission===c,onChange:()=>s.setNewDomainPermission(c),disabled:s.creating}),e.jsx("span",{children:s.plabel(c)})]},c))})]}),e.jsx("button",{type:"submit",className:"primary mdocs-domain-mgmt-submit",disabled:s.creating,children:s.creating?t("creating"):t("create")})]})]}),p&&e.jsx("div",{className:"mdocs-settings-card",style:{color:p.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:p.text})}),s.domainError&&e.jsx("div",{className:"mdocs-settings-card mdocs-domain-error",children:e.jsx("span",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)"},children:s.domainError})}),e.jsxs("div",{className:"mdocs-settings-card mdocs-domain-mgmt-toolbar",children:[e.jsx("input",{type:"search",value:s.domainSearch,onChange:c=>s.setDomainSearch(c.target.value),placeholder:t("domainSearchPlaceholder"),className:"mdocs-domain-mgmt-search","aria-label":t("domainSearchPlaceholder")}),e.jsx("div",{className:"mdocs-domain-mgmt-filters",role:"group","aria-label":t("domainPermission"),children:["all",...Ie].map(c=>e.jsx("button",{type:"button",className:"mdocs-domain-mgmt-filter"+(s.domainFilter===c?" active":""),"aria-pressed":s.domainFilter===c,onClick:()=>s.setDomainFilter(c),children:c==="all"?t("domainFilterAll"):s.plabel(c)},c))})]}),s.loadingDomains?e.jsx("div",{className:"mdocs-settings-card",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")})}):s.domains.length===0?e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("noDomains")})}):s.filteredDomains.length===0?e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("domainNoMatch")})}):e.jsx("div",{className:"mdocs-settings-card mdocs-domain-table-wrap",children:e.jsxs("table",{className:"mdocs-domain-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:t("domainColName")}),e.jsx("th",{scope:"col",children:t("domainColType")}),e.jsx("th",{scope:"col",className:"mdocs-domain-table-num",children:t("domainColDocCount")}),e.jsx("th",{scope:"col",children:t("domainColActions")})]})}),e.jsx("tbody",{children:s.filteredDomains.map(c=>{const x=Ls(c,s.visitorId),o=Fs(c.domainId),h=zs(c),I=_e(c.permission,"public")==="upgrade",A=I?h?t("domainTooltipTypeLocked"):void 0:t("domainPermissionAlreadyTop");return e.jsxs("tr",{className:o?"mdocs-domain-table-row-builtin":void 0,children:[e.jsx("td",{children:s.renamingId===c.domainId?e.jsxs("div",{className:"mdocs-domain-table-rename",children:[e.jsx("input",{value:s.renameDraft,onChange:y=>s.setRenameDraft(y.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(c.domainId),children:t("save")}),e.jsx("button",{type:"button",onClick:s.cancelRename,children:t("cancel")})]}):e.jsxs("div",{className:"mdocs-domain-table-name-cell",children:[e.jsx("span",{className:"mdocs-domain-table-name",children:s.localizeDomain(c)}),o&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:t("domainBuiltIn")}),!x&&!o&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:t("shared")})]})}),e.jsx("td",{children:e.jsx("span",{className:"mdocs-domain-table-type",title:A,children:e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":c.permission,children:s.domainTypeLabel(c,o)})})}),e.jsx("td",{className:"mdocs-domain-table-num",children:c.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[o&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:t("domainNotModifiable")}),!o&&!x&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:t("domainNotCreator")}),!o&&x&&s.changeTypeForId===c.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",ref:N,children:[e.jsx("div",{className:"mdocs-domain-type-segment",role:"radiogroup","aria-label":t("domainChangeType"),children:Ie.map(y=>{const z=_e(c.permission,y)==="downgrade";return e.jsx("span",{title:z?t("domainPermissionNoDowngrade"):void 0,children:e.jsx("button",{type:"button",role:"radio","aria-checked":u===y,className:u===y?"active":"",disabled:z,onClick:()=>w(y),children:s.plabel(y)})},y)})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon confirm","aria-label":t("save"),disabled:u===""||u===c.permission,onClick:()=>{u&&u!==c.permission&&s.handlePermissionChange(c.domainId,u)},children:e.jsx(gt,{size:14,strokeWidth:2.5})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon cancel","aria-label":t("cancel"),onClick:()=>s.setChangeTypeForId(null),children:e.jsx(Bs,{size:14,strokeWidth:2.5})})]}),!o&&x&&s.renamingId!==c.domainId&&s.changeTypeForId!==c.domainId&&e.jsxs("div",{className:"mdocs-domain-action-buttons",children:[c.permission==="restricted"&&e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--primary",onClick:()=>void S(c),children:t("domainMembersManageButton")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:h?t("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(c)},disabled:h,children:t("rename")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:A,onClick:()=>{s.setRenamingId(null),w(c.permission),s.setChangeTypeForId(c.domainId)},disabled:!I,children:t("domainChangeType")}),e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--danger",title:h?t("domainLocked"):void 0,onClick:()=>void s.handleDelete(c),disabled:h,children:t("deleteDomain")})]})]})]},c.domainId)})})]})})]}),e.jsx(ss,{open:g!==null,title:t("domainMembersPickerTitle"),initialSelectedIds:(g==null?void 0:g.initialIds)??[],lockedIds:g?[g.creatorVisitorId]:[],seedMembers:g==null?void 0:g.memberRows,templates:j,onClose:()=>k(null),onConfirm:async c=>{g&&(await $s(g.domainId,c),B({kind:"ok",text:t("domainMembersSaved",{count:String(c.length)})}))}})]})}function Ge(t){return t.length<=6?t:`${t.slice(0,6)}…`}function vt(){const{t}=ie(),s=a.useRef(!0),[j,d]=a.useState([]),[p,B]=a.useState(!0),[u,w]=a.useState(null),[N,g]=a.useState(1),[k,T]=a.useState(null),[S,c]=a.useState(""),[x,o]=a.useState([]),[h,I]=a.useState(!1),[A,y]=a.useState(null),[M,z]=a.useState(!1),F=Ye(),[v,P]=a.useState([]),[C,E]=a.useState("idle"),[m,l]=a.useState("");a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{E("loading"),Qe().then(r=>{s.current&&(P(r),E("ok"))}).catch(()=>{s.current&&E("err")})},[]);const f=a.useMemo(()=>{const r=new Map;for(const R of v)r.set(R.visitorId,R.visitorName);return r},[v]),D=a.useCallback(async()=>{B(!0),y(null);try{const r=await Xe();s.current&&d(r)}catch(r){s.current&&y(Q(t,r))}finally{s.current&&B(!1)}},[t]);a.useEffect(()=>{D()},[D]);const $=a.useMemo(()=>x.map(r=>{const R=v.find(O=>O.visitorId===r);return{visitorId:r,name:R?R.visitorName:t("visitorPickerUnknownVisitor"),muted:!R}}),[x,v,t]);function U(r){o(R=>R.includes(r)?R.filter(O=>O!==r):[...R,r])}const Z=N===1?S.trim().length>0:N===2?x.length>0:!0;function Y(){if(!(N>=3)){if(!Z){z(!0);return}z(!1),g(N+1),l("")}}function q(){N<=1||(z(!1),g(N-1))}function _(){w(null),T(null),c(""),o(F?[F]:[]),y(null),g(1),l(""),z(!1)}function b(r){w(null),T(r.id),c(r.displayName);const R=F&&!r.visitorIds.includes(F)?[...r.visitorIds,F]:[...r.visitorIds];o(R),y(null),g(1),l(""),z(!1)}async function K(){if(!(!S.trim()||x.length===0)){I(!0),y(null);try{if(k===null?await Os({displayName:S.trim(),visitorIds:x}):await Vs(k,{displayName:S.trim(),visitorIds:x}),!s.current)return;_(),await D()}catch(r){if(!s.current)return;y(Q(t,r))}finally{s.current&&I(!1)}}}async function W(r){I(!0),y(null);try{if(await Us(r),!s.current)return;w(null),k===r&&_(),await D()}catch(R){if(!s.current)return;y(Q(t,R))}finally{s.current&&I(!1)}}const X=[{key:1,label:t("memberTemplateStepName")},{key:2,label:t("memberTemplateStepMembers")},{key:3,label:t("memberTemplateStepSave")}],ee=`${(N-1)/2*100}%`;return e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:t(k!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),k!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:_,style:{fontSize:12},children:t("memberTemplateCancelEdit")})]}),e.jsxs("div",{className:"mdocs-wizard-progress",children:[e.jsx("div",{className:"mdocs-wizard-progress-track",children:e.jsx("div",{className:"mdocs-wizard-progress-fill",style:{width:ee}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:X.map(r=>{const R=N===r.key,O=N>r.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${R?" current":""}${O?" done":""}`,children:O?"✓":r.key}),e.jsx("span",{className:`mdocs-wizard-step-label${R?" current":""}${O?" done":""}`,children:r.label})]},r.key)})})]}),A&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:A}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[N===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:S,onChange:r=>c(r.target.value),placeholder:t("memberTemplateNamePlaceholder"),maxLength:200,disabled:h,autoFocus:!0,"aria-invalid":M&&!S.trim()}),M&&!S.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:t("domainNameRequired")})]}),N===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(pt,{visitors:v,loadState:C,searchFilter:m,onSearchChange:l,selectedIds:new Set(x),onToggle:U,selectedRows:$,myVisitorId:F}),e.jsx("p",{className:`mdocs-wizard-hint${M&&x.length===0?" danger":""}`,children:"💡 "+t("memberTemplateStep2Hint")})]}),N===3&&e.jsx("div",{className:"mdocs-wizard-step-content",children:e.jsxs("div",{className:"mdocs-wizard-preview-card",children:[e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:t("memberTemplateNameLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:S})]}),e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:t("memberTemplateIdsLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:t("memberTemplateSelectedSummary",{count:String(x.length)})})]}),x.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[x.slice(0,15).map(r=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:Ge(r)},r)),x.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",x.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:q,children:["← ",t("memberTemplateWizardBack")]}),N<3?e.jsxs("button",{type:"button",className:"primary",onClick:Y,children:[t("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void K(),children:t(h?"saving":k===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("memberTemplateSavedList")}),p?e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")}):j.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateEmpty")}),k===null&&e.jsx("button",{type:"button",className:"primary",onClick:_,children:t("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:j.map(r=>e.jsx("li",{className:"mdocs-member-template-row",children:u===r.id?e.jsxs("div",{className:"mdocs-member-template-confirm-row",children:[e.jsx("span",{className:"mdocs-member-template-confirm-text",children:t("memberTemplateConfirmDeleteDesc",{name:r.displayName})}),e.jsxs("div",{className:"mdocs-member-template-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",style:{color:"var(--mdocs-danger)"},onClick:()=>void W(r.id),children:t(h?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(null),children:t("memberTemplateConfirmDeleteCancel")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-member-template-row-head",children:[e.jsx("strong",{children:r.displayName}),e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateCount",{count:String(r.visitorIds.length)})}),r.visitorIds.length>0&&e.jsx("div",{className:"mdocs-member-template-tags mdocs-member-template-tags-scroll",children:r.visitorIds.map(R=>e.jsx("span",{className:"mdocs-member-template-tag",children:f.get(R)??Ge(R)},R))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>b(r),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(r.id),children:t("memberTemplateDelete")})]})]})},r.id))})]})]})]})}const kt=[{value:"deepseek-flash",label:"deepseek-flash(V4.1 Flash)"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro(将路由至 Flash)"}],wt=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function St(t,s,j){return t==="deepseek"?"Deepseek":s||j}function He(t){return`${St(t.kind,t.providerId,t.name)} · ${t.modelId} · ${t.name}`}function Ct(){const{t}=ie(),s=a.useRef(!0),[j,d]=a.useState(""),[p,B]=a.useState([]),[u,w]=a.useState(null),[N,g]=a.useState(null),[k,T]=a.useState("deepseek"),[S,c]=a.useState(""),[x,o]=a.useState(""),[h,I]=a.useState(""),[A,y]=a.useState("openai-completions"),[M,z]=a.useState("deepseek-flash"),[F,v]=a.useState(1e6),[P,C]=a.useState(""),[E,m]=a.useState(!1),[l,f]=a.useState(null),[D,$]=a.useState(!1),[U,Z]=a.useState(!0),[Y,q]=a.useState(!1),[_,b]=a.useState(null),[K,W]=a.useState(!1),[X,ee]=a.useState(!1),[r,R]=a.useState(!1),[O,ce]=a.useState(null),[me,oe]=a.useState(null),re=a.useRef(!1);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]);const se=a.useCallback(async()=>{const i=await Ws();if(s.current)return B(i),i},[]);function te(){g(null),T("deepseek"),c(""),o(""),I(""),y("openai-completions"),z("deepseek-flash"),v(1e6),C(""),m(!1),f(null),$(!1),ee(!1),R(!1),b(null),W(!1)}function ue(i){g(i.id),T(i.kind),c(i.name),o(i.providerId??""),I(i.baseUrl),y(i.apiType);const V=i.modelId.trim(),ge=new Set(["deepseek-flash","deepseek-v4-flash","deepseek-v4-flash-vision-exp","deepseek-v4.1-flash","deepseek-v4.1-flash-expires-on-0910"]);z(i.kind==="deepseek"?V==="deepseek-v4-pro"?"deepseek-v4-pro":ge.has(V)?"deepseek-flash":V||"deepseek-flash":V),v(i.contextWindow||1e6),m(i.hasApiKey),f(i.apiKeyMasked),C(""),$(i.isDefault)}a.useEffect(()=>{(async()=>{try{const i=await _s();if(!s.current)return;d(i.visitorName);const V=await se();if(!s.current||!V)return;V.length===0&&(te(),w("create"))}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i)),w("create")}finally{s.current&&Z(!1)}})()},[se]);function je(){te(),w("create")}function he(i){ue(i),w("edit"),W(!1),b(null)}function ae(){te(),w(null)}async function ye(i){if(!(i.isDefault||me)){oe(i.id),b(null);try{await Gs(i.id),await se()}catch(V){if(!s.current)return;b(V instanceof Error?V.message:String(V))}finally{s.current&&oe(null)}}}async function pe(){if(O){q(!0),b(null);try{await Js(O.id);const i=await se();if(!s.current)return;u==="edit"&&N===O.id&&ae(),((i==null?void 0:i.length)??0)===0&&(te(),w("create"))}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i))}finally{s.current&&(q(!1),ce(null))}}}async function be(){q(!0),b(null),W(!1);try{const i=k==="custom"?{...u==="edit"&&N?{id:N}:{},...u==="create"&&D?{isDefault:!0}:{},kind:k,baseUrl:h,modelId:M,providerId:x.trim()||void 0,apiType:A,name:S,contextWindow:F,...P.trim()?{apiKey:P.trim()}:{}}:{...u==="edit"&&N?{id:N}:{},...u==="create"&&D?{isDefault:!0}:{},kind:k,modelId:M,name:S,contextWindow:F,...P.trim()?{apiKey:P.trim()}:{}};if(await Hs(i),!s.current)return;await se(),W(!0),w(null),te()}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i))}finally{s.current&&q(!1)}}const Ne=u!==null;return e.jsxs("div",{className:"mdocs-agent-config-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:t("agentConfig")}),U?null:e.jsx("button",{type:"button",className:"secondary",onClick:je,children:"添加配置"})]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[!U&&p.length>0?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:"选择默认配置后,智能助手与帮写将使用该模型。"}),e.jsx("ul",{className:"mdocs-agent-config-list",children:p.map(i=>e.jsxs("li",{className:"mdocs-agent-config-item",children:[e.jsxs("label",{className:"mdocs-agent-config-item-default",children:[e.jsx("input",{type:"radio",name:"agent-default-config",checked:i.isDefault,disabled:me!==null,onChange:()=>void ye(i)}),e.jsx("span",{children:i.isDefault?"默认":"设为默认"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-main",children:[e.jsx("strong",{children:He(i)}),i.kind==="custom"?e.jsx("span",{className:"mdocs-agent-badge",children:"自定义"}):null,e.jsx("p",{className:"mdocs-agent-config-item-meta",children:i.hasApiKey?`Key ${i.apiKeyMasked??"已配置"}`:"未配置 Key"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>he(i),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>ce(i),children:"删除"})]})]},i.id))}),K?e.jsx("p",{className:"mdocs-agent-config-ok",children:t("saved")}):null,_?e.jsx("p",{className:"mdocs-agent-config-error",children:_}):null]}):null,Ne?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsxs("p",{className:"mdocs-agent-config-lead",children:[u==="create"?"新建模型配置。":"编辑模型配置。","可以保存多套,勾选一条作为默认。智能助手和帮写使用默认那套。"]}),e.jsxs("div",{className:"mdocs-agent-form",children:[e.jsxs("div",{className:"mdocs-agent-kind-tabs",role:"tablist","aria-label":"配置方式",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":k==="deepseek",className:k==="deepseek"?"active":"",onClick:()=>T("deepseek"),children:"Deepseek"}),e.jsx("button",{type:"button",role:"tab","aria-selected":k==="custom",className:k==="custom"?"active":"",onClick:()=>T("custom"),children:"自定义"})]}),k==="deepseek"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigModel")}),e.jsx(Ve,{options:[...kt],value:M,onChange:z})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:X?"text":"password",value:P,onChange:i=>C(i.target.value),placeholder:E?t("agentConfigApiKeyConfigured").replace("{{masked}}",l??"…"):t("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(X?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>ee(i=>!i),children:X?"隐藏":"显示"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 地址"}),e.jsx("input",{type:"url",value:h,onChange:i=>{const V=i.target.value;if(I(V),re.current)return;V.toLowerCase().includes("anthropic")?y("anthropic-messages"):y("openai-completions")},placeholder:"https://api.example.com/v1",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Model ID"}),e.jsx("input",{type:"text",value:M,onChange:i=>z(i.target.value),placeholder:"模型名称,如 gpt-4o",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:X?"text":"password",value:P,onChange:i=>C(i.target.value),placeholder:E?t("agentConfigApiKeyConfigured").replace("{{masked}}",l??"…"):"粘贴 API Key",autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(X?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>ee(i=>!i),children:X?"隐藏":"显示"})]})]})]}),e.jsxs("details",{className:"mdocs-agent-advanced",open:r,onToggle:i=>R(i.target.open),children:[e.jsx("summary",{children:"高级选项"}),k==="custom"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Provider ID(选填)"}),e.jsx("input",{type:"text",value:x,onChange:i=>o(i.target.value),placeholder:"不填则自动从 API 地址提取域名"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 协议"}),e.jsx(Ve,{options:[...wt],value:A,onChange:i=>{re.current=!0,y(i)}})]})]}):null,e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigName")}),e.jsx("input",{type:"text",value:S,onChange:i=>c(i.target.value),placeholder:t("agentConfigNameDefault").replace("{{name}}",j||"…")})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigContextWindow")}),e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:F,onChange:i=>v(Number(i.target.value)||1e6)}),e.jsx("p",{className:"mdocs-agent-field-hint",children:t("agentConfigContextWindowDesc")})]})]}),u==="create"&&p.length>0?e.jsxs("label",{className:"mdocs-agent-config-default-check",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:i=>$(i.target.checked)}),e.jsx("span",{children:"保存后设为默认配置"})]}):null,_?e.jsx("p",{className:"mdocs-agent-config-error",children:_}):null,e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void be(),disabled:Y,children:t(Y?"saving":"save")}),p.length>0?e.jsx("button",{type:"button",className:"secondary",onClick:ae,disabled:Y,children:t("cancel")}):null]})]})]}):U?e.jsx("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:e.jsx("p",{className:"mdocs-agent-config-muted",children:t("loading")})}):null]}),O?e.jsx(es,{title:"删除配置",message:`确定删除「${He(O)}」?${O.isDefault&&p.length>1?" 删除后将自动把另一条设为默认。":""}`,confirmLabel:"删除",cancelLabel:t("cancel"),onConfirm:()=>void pe(),onCancel:()=>ce(null)}):null]})}const Dt=/^[A-Za-z0-9_]+$/;function Te(t){return Dt.test(t.trim())}function It(){const t=a.useRef(!0),[s,j]=a.useState([]),[d,p]=a.useState(!0),[B,u]=a.useState(null),[w,N]=a.useState(null),[g,k]=a.useState(!1),[T,S]=a.useState(""),[c,x]=a.useState(""),[o,h]=a.useState(""),[I,A]=a.useState(!1);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]);async function y(){p(!0),u(null);try{const m=await Zs();if(!t.current)return;j(m)}catch(m){if(!t.current)return;u(m instanceof Error?m.message:String(m))}finally{t.current&&p(!1)}}a.useEffect(()=>{y()},[]);function M(){k(!0),N(null),S(""),x(""),h(""),u(null)}function z(m){k(!1),N(m.id),S(m.name),x(m.description),h(m.body),u(null)}function F(){k(!1),N(null),S(""),x(""),h("")}async function v(){const m=T.trim();if(!Te(m)){u("名称仅允许英文、数字、下划线");return}if(!o.trim()){u("正文不能为空");return}A(!0),u(null);try{if(g?await Ys({name:m,description:c,body:o}):w&&await qs(w,{name:m,description:c,body:o}),!t.current)return;F(),await y()}catch(l){if(!t.current)return;u(l instanceof Error?l.message:String(l))}finally{t.current&&A(!1)}}async function P(m){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){u(null);try{if(await Xs(m),!t.current)return;w===m&&F(),await y()}catch(l){if(!t.current)return;u(l instanceof Error?l.message:String(l))}}}const C=g||w!==null,E=!T.trim()||Te(T);return e.jsxs("div",{className:"mdocs-agent-skills-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title",children:["Agent Skills",!d&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),C?null:e.jsx("button",{type:"button",className:"secondary",onClick:M,children:"新建"})]}),e.jsx("div",{className:"mdocs-settings-cards",children:e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"mdocs-settings-item-desc mdocs-agent-skills-lead",children:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),B?e.jsx("p",{className:"mdocs-agent-skills-error",children:B}):null,C?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:g?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:T,onChange:m=>S(m.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:E?void 0:"mdocs-agent-skills-input-invalid"}),E?e.jsx("span",{className:"mdocs-agent-skills-hint",children:"引用与索引键,保存后按此名称使用"}):e.jsx("span",{className:"mdocs-agent-skills-hint-bad",children:"仅允许 A–Z、a–z、0–9、_"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"简介(可选)"}),e.jsx("input",{type:"text",value:c,onChange:m=>x(m.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:o,onChange:m=>h(m.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void v(),disabled:I||!E||!T.trim()||!o.trim(),children:I?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:F,disabled:I,children:"取消"})]})]}):null,d?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!d&&s.length===0&&!C?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:M,children:"新建第一个"})]}):null,!d&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(m=>{const l=Te(m.name),f=w===m.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(f?" mdocs-agent-skills-item-active":""),children:[e.jsxs("div",{className:"mdocs-agent-skills-item-main",children:[e.jsxs("div",{className:"mdocs-agent-skills-item-title-row",children:[e.jsx("code",{className:"mdocs-agent-skills-name",children:m.name}),l?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:m.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>z(m),disabled:C&&!f,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void P(m.id),disabled:C,children:"删除"})]})]},m.id)})}):null]})})]})}function Je(t,s){const j=localStorage.getItem(t);return j===null?s:j==="true"}function Ze(t){const s=new Date(t);if(Number.isNaN(s.getTime()))return"—";const j=String(s.getMonth()+1).padStart(2,"0"),d=String(s.getDate()).padStart(2,"0");return`${s.getFullYear()}-${j}-${d}`}function Ft(t){const{t:s,lang:j,setLang:d}=ie(),{onBack:p,onPublishDraft:B}=t,u=Qs(),[w,N]=a.useState(!1),g=a.useRef(!0);a.useEffect(()=>(g.current=!0,()=>{g.current=!1}),[]),a.useEffect(()=>{u||N(!1)},[u]);const[k,T]=a.useState(()=>Je("mdocs.autoPublish",!1)),[S,c]=a.useState(()=>Je("mdocs.autoEdit",!0)),[x,o]=a.useState(!1),[h,I]=a.useState("general");function A(n){I(n),u&&N(!1)}const y=s(h==="general"?"general":h==="bookmarks"?"bookmarkTitle":h==="myDocuments"?"myDocuments":h==="domainManagement"?"domainManagement":h==="memberTemplates"?"memberTemplates":h==="agentConfig"?"agentConfig":"saveAndPublish"),[M,z]=a.useState([]),[F,v]=a.useState(!0),[P,C]=a.useState(null),[E,m]=a.useState(!1),[l,f]=a.useState(!1),[D,$]=a.useState(!1),[U,Z]=a.useState(!1),[Y,q]=a.useState(null),[_,b]=a.useState(!1),[K,W]=a.useState(!1),[X,ee]=a.useState(!1),[r,R]=a.useState(""),[O,ce]=a.useState(!1),[me,oe]=a.useState(!1),[re,se]=a.useState(0),[te,ue]=a.useState([]),[je,he]=a.useState(!1),[ae,ye]=a.useState(""),[pe,be]=a.useState([]),[Ne,i]=a.useState(!1),[V,ge]=a.useState(""),[le,ts]=a.useState(0),[Me,Ee]=a.useState("1"),[Re,as]=a.useState(0),[ve,ns]=a.useState(""),[ke,is]=a.useState(""),[fe,cs]=a.useState(""),[ls,os]=a.useState(null),[rs,ds]=a.useState([]),we=20,[Le,ms]=a.useState([]),[us,Se]=a.useState(!1),[Ce,Fe]=a.useState(null),[De,ze]=a.useState(new Map);a.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(k))},[k]),a.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(S))},[S]),a.useEffect(()=>{h==="savePublish"&&Pe().then(n=>{g.current&&se(n.filter(L=>!L.published).length)})},[h]),a.useEffect(()=>{h==="bookmarks"&&hs(),h==="myDocuments"&&(de(),Qe().then(n=>{g.current&&ds(n)}).catch(()=>{}))},[h,ve,ke,fe]),a.useEffect(()=>{Be()},[]),a.useEffect(()=>{qe().then(n=>{g.current&&ms(n)}).catch(()=>{})},[]);const xe=new Map(Le.map(n=>[n.domainId,n.domainName]));async function Be(){try{v(!0);const n=await et();if(!g.current)return;z(n)}catch{}finally{g.current&&v(!1)}}async function hs(){try{he(!0);const n=await st();if(!g.current)return;ue(n)}catch{}finally{g.current&&he(!1)}}async function de(n=0){try{i(!0);const L=await tt({offset:n*we,limit:we,domainId:ve||void 0,creatorVisitorId:ke||void 0,groupBy:fe||void 0});if(!g.current)return;be(L.items),os(L.groups??null),as(L.total),ts(n),Ee(String(n+1))}catch{}finally{g.current&&i(!1)}}async function ps(n){try{await rt(n),ue(L=>L.filter(H=>H.documentId!==n))}catch{}}function gs(){if(M.some(L=>!L.revoked)){f(!0);return}$e()}async function $e(){try{m(!0);const n=await mt();C({token:n.token,name:n.name}),await Be()}finally{m(!1)}}async function fs(){try{ee(!0);const n=await lt();q(n.recoveryCode)}finally{ee(!1)}}async function xs(n){n.preventDefault();const L=r.trim();if(!(L&&L.length<4))try{ce(!0),await ot(L),R(""),oe(!0),setTimeout(()=>oe(!1),3e3)}finally{ce(!1)}}async function js(n){Fe(n);try{const L=await dt(n),H=new Map;L.forEach(G=>{H.set(G.visitorId,G.permission)}),ze(H)}catch{ze(new Map)}Se(!0)}async function ys(n){if(Ce)try{const L=new Set(n.map(G=>G.visitorId)),H=new Set(De.keys());for(const G of H)L.has(G)||await ut(Ce,G);for(const G of n)await ht(Ce,G.visitorId,G.permission);await de()}finally{Se(!1),Fe(null)}}const Ke=te.filter(n=>{if(!ae.trim())return!0;const L=ae.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(L)||(n.ownerVisitorName||"").toLowerCase().includes(L)||(n.domainId||"").toLowerCase().includes(L)}),ne=Math.ceil(Re/we);return e.jsxs("div",{className:"mdocs-layout"+(u?" mdocs-layout--reader mdocs-layout--settings":""),children:[u&&w?e.jsx("button",{type:"button",className:"mdocs-mobile-nav-scrim","aria-label":s("collapseSidebar"),onClick:()=>N(!1)}):null,e.jsxs("aside",{className:"mdocs-sidebar"+(u?w?" mdocs-sidebar--drawer-open":" mdocs-sidebar--drawer":""),children:[e.jsxs("header",{className:"mdocs-sidebar-header",children:[e.jsxs("div",{className:"mdocs-brand",children:[e.jsx("img",{src:at,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]}),u?e.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:()=>N(!1),"aria-label":s("collapseSidebar"),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(nt,{size:18})}):null]}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(h==="general"?" active":""),onClick:()=>A("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(h==="bookmarks"?" active":""),onClick:()=>A("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(h==="myDocuments"?" active":""),onClick:()=>A("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(h==="domainManagement"?" active":""),onClick:()=>A("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(h==="memberTemplates"?" active":""),onClick:()=>A("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(h==="agentConfig"?" active":""),onClick:()=>A("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(h==="savePublish"?" active":""),onClick:()=>A("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:p,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[u?e.jsxs("div",{className:"mdocs-settings-mobile-bar",children:[e.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>N(!0),"aria-label":s("expandSidebar"),children:e.jsx(it,{size:18,strokeWidth:1.75})}),e.jsx("span",{className:"mdocs-settings-mobile-bar-title",children:y})]}):null,ct(),h==="general"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("general")})}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsx("span",{className:"mdocs-settings-item-info",children:e.jsx("span",{className:"mdocs-settings-card-title",children:s("language")})}),e.jsxs("span",{className:"mdocs-settings-lang",children:[e.jsx("button",{type:"button",className:j==="en"?"active":"",onClick:()=>d("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:j==="zh"?"active":"",onClick:()=>d("zh"),children:"中"})]})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoEdit")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoEditDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(S?" active":""),role:"switch","aria-checked":S,onClick:()=>c(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliToken")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("cliTokenDesc")}),!F&&M.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:M.map(n=>e.jsxs("span",{style:{display:"block"},children:[n.name," — ",new Date(n.createdAt).toLocaleString()," ",n.revoked?`(${s("cliTokenRevoked")})`:`(${s("cliTokenActive")})`]},n.tokenId))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:gs,disabled:E||F,children:E?"…":M.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),P&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--ok",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliTokenGenerated")}),e.jsx("span",{className:"mdocs-settings-secret-value",children:P.token})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(P.token),Z(!1),$(!0),window.setTimeout(()=>$(!1),2e3)}catch{$(!1),Z(!0),window.setTimeout(()=>Z(!1),3e3)}})()},children:s(D?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>C(null),children:s("close")})]}),D&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),U&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--err",role:"status",children:s("cliTokenCopyFailed")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",children:"当 Token 丢失时,可用恢复码找回身份。生成后请立即保存,仅显示一次。"})]}),e.jsx("button",{type:"button",className:"secondary",onClick:fs,disabled:X,children:X?"…":"生成恢复码"})]}),Y&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--warn",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 你的恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8},children:"请立即复制保存,关闭后不可再查看。"}),e.jsx("div",{className:"mdocs-settings-secret-code",children:Y})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(Y),W(!1),b(!0),window.setTimeout(()=>b(!1),2e3)}catch{b(!1),W(!0),window.setTimeout(()=>W(!1),3e3)}})()},children:_?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>q(null),children:s("close")})]}),_&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),K&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--err",role:"status",children:"复制失败,请手动选中上方内容复制"})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-item",children:e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔐 登录密码"}),e.jsx("span",{className:"mdocs-settings-item-desc",children:"设置密码后,可在其他浏览器或设备用「用户名+密码」登录。"})]})}),e.jsxs("form",{onSubmit:xs,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:r,onChange:n=>R(n.target.value),minLength:0,style:{marginBottom:8}}),me&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:O,children:O?"设置中…":"保存密码"})]})]})]})]}):h==="bookmarks"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("bookmarkTitle")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("input",{type:"text",className:"mdocs-settings-search",placeholder:s("bookmarkSearch"),value:ae,onChange:n=>ye(n.target.value)}),je?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:Ke.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(ae?"bookmarkNoMatch":"bookmarkEmpty")}):e.jsx("div",{className:"mdocs-settings-table-wrap",children:e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("bookmarkColTitle")}),e.jsx("th",{children:s("bookmarkColDomain")}),e.jsx("th",{children:s("bookmarkColAuthor")}),e.jsx("th",{children:s("bookmarkColTime")}),e.jsx("th",{style:{textAlign:"right"}})]})}),e.jsx("tbody",{children:Ke.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>t.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:n.isDeleted?e.jsx("span",{style:{opacity:.5,fontStyle:"italic"},children:"已删除"}):xe.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:n.ownerVisitorName||"—"}),e.jsx("td",{children:new Date(n.bookmarkedAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>ps(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})})]})]}):h==="myDocuments"?e.jsxs("div",{className:"mdocs-settings mdocs-my-docs",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("myDocuments")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-my-docs-toolbar",children:[e.jsxs("div",{className:"mdocs-my-docs-search",children:[e.jsx(xt,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("input",{type:"text",placeholder:"搜索文章…",value:V,onChange:n=>ge(n.target.value)})]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ve,"aria-label":s("myDocumentsFilterDomain"),onChange:n=>ns(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllDomains")}),Le.map(n=>e.jsx("option",{value:n.domainId,children:xe.get(n.domainId)||n.domainName},n.domainId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ke,"aria-label":s("myDocumentsFilterCreator"),onChange:n=>is(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllCreators")}),rs.map(n=>e.jsx("option",{value:n.visitorId,children:n.visitorName},n.visitorId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:fe,"aria-label":s("myDocumentsGroupBy"),onChange:n=>cs(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsGroupNone")}),e.jsx("option",{value:"domain",children:s("myDocumentsGroupDomain")}),e.jsx("option",{value:"creator",children:s("myDocumentsGroupCreator")})]})]}),Ne?e.jsx("div",{className:"mdocs-my-docs-empty",children:s("loading")}):e.jsxs(e.Fragment,{children:[pe.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(V?"myDocumentsNoMatch":"myDocumentsEmpty")}):e.jsx("div",{className:"mdocs-settings-table-wrap",children:e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("myDocumentsColTitle")}),e.jsx("th",{children:s("myDocumentsColDomain")}),e.jsx("th",{children:s("myDocumentsColCreator")}),e.jsx("th",{children:s("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{})]})}),e.jsx("tbody",{children:(ls??[{key:"",items:pe}]).flatMap(n=>{var G;const L=n.key?e.jsx("tr",{className:"mdocs-my-docs-group",children:e.jsx("td",{colSpan:6,children:fe==="domain"?xe.get(n.key)||n.key:((G=n.items[0])==null?void 0:G.creatorName)||n.key})},`group-${n.key}`):null,H=n.items.map(J=>e.jsxs("tr",{children:[e.jsx("td",{className:"mdocs-my-docs-title",onClick:()=>t.onOpenDocument(J.documentId),children:J.displayName||J.relativePath||"Untitled"}),e.jsx("td",{children:xe.get(J.domainId||"")||J.domainId||"—"}),e.jsx("td",{children:J.creatorName||J.creatorVisitorId||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Ze(J.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:Ze(J.createdAt)}),e.jsxs("td",{className:"mdocs-my-docs-actions",children:[e.jsx("button",{type:"button",className:"ghost small",onClick:()=>js(J.documentId),children:s("docInfoInviteMember")}),e.jsx("button",{type:"button",className:"primary small",onClick:()=>t.onOpenDocument(J.documentId),children:s("bookmarkOpen")})]})]},J.documentId));return L?[L,...H]:H})})]})}),e.jsxs("div",{className:"mdocs-my-docs-footer",children:[e.jsx("span",{className:"mdocs-settings-page-info",children:s("myDocumentsPageInfo",{current:String(ne>0?le+1:0),total:String(ne),count:String(Re)})}),ne>1&&e.jsxs("form",{className:"mdocs-my-docs-jump",onSubmit:n=>{n.preventDefault();const L=Number.parseInt(Me,10);if(!Number.isFinite(L))return;const H=Math.min(Math.max(L,1),ne)-1;H!==le&&de(H)},children:[e.jsx("span",{children:s("myDocumentsJumpTo")}),e.jsx("input",{type:"number",inputMode:"numeric",min:1,max:ne,"aria-label":s("myDocumentsJumpTo"),value:Me,onChange:n=>Ee(n.target.value)}),e.jsx("button",{type:"submit",className:"secondary small",children:s("myDocumentsJump")})]}),ne>1&&e.jsxs("div",{className:"mdocs-settings-pagination",children:[e.jsx("button",{type:"button",className:"secondary small",disabled:le<=0,onClick:()=>de(le-1),children:s("myDocumentsPrev")}),e.jsx("button",{type:"button",className:"secondary small",disabled:le>=ne-1,onClick:()=>de(le+1),children:s("myDocumentsNext")})]})]})]})]})]}):h==="domainManagement"?e.jsx(Nt,{}):h==="memberTemplates"?e.jsx(vt,{}):h==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(Ct,{}),e.jsx(It,{})]}):e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:s("saveAndPublish")}),e.jsx("button",{type:"button",className:"secondary",onClick:p,children:s("backToDocs")})]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoSave")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoSaveAlwaysOnDesc")})]}),e.jsx("span",{className:"mdocs-toggle active",role:"switch","aria-checked":"true","aria-disabled":"true",style:{opacity:.6,cursor:"not-allowed"},children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoPublish")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoPublishDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(k?" active":""),role:"switch","aria-checked":k,onClick:()=>T(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),re>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>o(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",re,")"]}),e.jsx("span",{className:"mdocs-settings-draft-arrow","aria-hidden":"true",children:"›"})]}):e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:s("noDrafts")})})]})]}),x&&e.jsx(yt,{onPublish:B,onClose:()=>o(!1),onCountChange:se,onRecover:t.onRecoverDraft})]}),l&&e.jsx(es,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:E,onConfirm:()=>{f(!1),$e()},onCancel:()=>f(!1)}),e.jsx(ss,{open:us,title:s("docInfoInviteMember"),initialSelectedIds:[...De.keys()],initialPermissions:De,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>Se(!1),onConfirm:n=>{ys(n)}})]})}export{Ft as SettingsPage};
@@ -1,4 +1,4 @@
1
- import{o as t,C as _}from"./index-OmOf_og0.js";import{r as u,j as r}from"./react-vendor-BuABiQkA.js";import{F as C,G as v,L as N,H as c,J as l,K as L,M as j,q as z,N as H,P as $}from"./react-CI5PDFXT.js";import{z as f,V as g}from"./editor-CL03se2B.js";/**
1
+ import{o as t,C as _}from"./index-CUdIA5aE.js";import{r as u,j as r}from"./react-vendor-BuABiQkA.js";import{F as C,G as v,L as N,H as c,J as l,K as L,M as j,q as z,N as H,P as $}from"./react-Bf45libg.js";import{z as f,V as g}from"./editor-CL03se2B.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.