@fgbg/mdocs 0.8.20 → 0.8.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/agent-skills/changelog/SKILL.md +7 -1
- package/agent-skills/index.json +1 -1
- package/dist/server/agent/Agent/choice-pending.js +10 -1
- package/dist/server/agent/Agent/choice-pending.js.map +1 -1
- package/dist/server/agent/Agent/run-pi-agent.js +10 -4
- package/dist/server/agent/Agent/run-pi-agent.js.map +1 -1
- package/dist/server/agent/Agent/run.js +3 -1
- package/dist/server/agent/Agent/run.js.map +1 -1
- package/dist/server/agent/Agent/skill-form-pending.js +9 -0
- package/dist/server/agent/Agent/skill-form-pending.js.map +1 -1
- package/dist/server/routes/agent.routes.js +25 -9
- package/dist/server/routes/agent.routes.js.map +1 -1
- package/dist/web/assets/AgentChatPanel-D95hI02c.js +1 -0
- package/dist/web/assets/AgentSkillFormCard-BtJ0QjLG.js +6 -0
- package/dist/web/assets/AiWriteWorkbench-Qam8cfY6.js +6 -0
- package/dist/web/assets/{DiagramEditor-BTRe45TX-C1YVSFMK.js → DiagramEditor-BTRe45TX-Did98cnP.js} +1 -1
- package/dist/web/assets/{DocumentEditor-B6IMAcRI.js → DocumentEditor-DtSzkl6A.js} +1 -1
- package/dist/web/assets/{MergeView-DoUvoUF6.js → MergeView-DgFQHD5_.js} +1 -1
- package/dist/web/assets/{PlaygroundPage-XyDSnDG_.js → PlaygroundPage-Dg57Xxpl.js} +1 -1
- package/dist/web/assets/{SettingsPage-DOeySRr-.js → SettingsPage-CkYpe5v7.js} +1 -1
- package/dist/web/assets/{Toolbar-C6GIlNMW.js → Toolbar-0Y2wmGwe.js} +1 -1
- package/dist/web/assets/{VisitorPickerModal-Db9Mh63R.js → VisitorPickerModal-COxtOvc4.js} +1 -1
- package/dist/web/assets/{copy-D8ORBt1-.js → copy-nOl0d3Th.js} +1 -1
- package/dist/web/assets/{index-czw0A2GN.js → index-B-XJ-ScV.js} +22 -22
- package/dist/web/assets/index-CGvsjO9f.css +1 -0
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-D1CzYV6l.js → meta2dEngine-BD2XbzaV-e28q005B.js} +1 -1
- package/dist/web/assets/{plus-9njZDkAU.js → plus-DvBbg6jL.js} +1 -1
- package/dist/web/assets/{react-BCo8JH1D.js → react-BsVOIHR8.js} +3 -3
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/AgentChatPanel-Cva-1CWE.js +0 -1
- package/dist/web/assets/AgentSkillFormCard-DcKxyiAV.js +0 -6
- package/dist/web/assets/AiWriteWorkbench-DkZ4JQuS.js +0 -6
- package/dist/web/assets/index-BQ1RXV0n.css +0 -1
package/dist/web/assets/{DiagramEditor-BTRe45TX-C1YVSFMK.js → DiagramEditor-BTRe45TX-Did98cnP.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Q as M,S as F,T as A,U as W,V}from"./react-
|
|
1
|
+
import{Q as M,S as F,T as A,U as W,V}from"./react-BsVOIHR8.js";import{r as c,j as e}from"./react-vendor-BNpqFP9B.js";import{ensureMeta2dShapes as N,generateSvgFromMeta2d as q,generateSvgFromDiagram as I}from"./meta2dEngine-BD2XbzaV-e28q005B.js";import{M as G}from"./meta2d-C8Z4cn-d.js";import"./editor-ONzd_YnO.js";import"./ui-C3xtW1w8.js";import"./motion-D-I76zAi.js";import"./diagram-BJFhx-27.js";import"./index-B-XJ-ScV.js";import"./plus-DvBbg6jL.js";import"./copy-nOl0d3Th.js";let T=0;const D=new Set;function O(n){return D.add(n),()=>{D.delete(n)}}function P(){return T}function Q(){T++,D.forEach(n=>n())}function E(n){let t=null;try{const[a]=M();t=a}catch{}const l=t;if(!l)throw new Error("[useEditorLocale] No editor found. Pass an editor instance or use this hook inside an <Editor> tree.");return c.useSyncExternalStore(O,P,P),{setLocale:c.useCallback(a=>{l.setLocale(a),Q()},[l]),t:c.useCallback((a,p)=>l.t(a,p),[l])}}const X={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 L(n){return`meta2d.palette.${n}`}const s={background:"#fff",color:"#1f1f1f",height:60,lineWidth:1,textColor:"#1f1f1f",width:120};function Y(){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 z(n){return V(structuredClone(n))}function $(n){const t=new Map;for(const l of n){const a=t.get(l.group)??[];a.push(l),t.set(l.group,a)}return Array.from(t.entries())}function J({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 K({disabled:n,engineRef:t,item:l,t:a}){const p=()=>{const r=t.current;if(!(!r||n))try{r.canvas.addCaches=[z(l.pen)]}catch{}};return e.jsxs("div",{draggable:!n,onClick:r=>{r.stopPropagation(),p()},onDragStart:r=>{if(n){r.preventDefault();return}const g=JSON.stringify(z(l.pen));r.dataTransfer.setData("Meta2d",g),r.dataTransfer.setData("Text",g),r.dataTransfer.effectAllowed="copy"},onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),p())},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:`${a(L(l.key))||l.label} — drag or click to add`,children:[e.jsx(J,{name:String(l.pen.name??"rectangle")}),e.jsx("span",{style:{fontSize:11},children:a(L(l.key))||l.label})]})}function U({disabled:n,engineRef:t}){const{t:l}=E(),a=c.useMemo(()=>$(Y()),[]);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:l("meta2d.palette.title")}),e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:12},children:l("meta2d.palette.hint")}),a.map(([p,r])=>e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:6},children:l(X[p]||p)}),e.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"repeat(2, minmax(0, 1fr))"},children:r.map(g=>e.jsx(K,{disabled:n,engineRef:t,item:g,t:l},g.key))})]},p))]})}const H={borderLeft:"1px solid #f0f0f0",flexShrink:0,maxHeight:"100%",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",touchAction:"pan-y",width:220},j={color:"#8c8c8c",fontSize:12,marginBottom:4},k={borderBottom:"1px solid #f0f0f0",padding:"10px 12px"},f={alignItems:"center",display:"flex",gap:6,marginBottom:6},m={background:"#fafafa",border:"1px solid #e5e5e5",borderRadius:4,fontSize:12,height:28,outline:"none",padding:"0 6px"},y={color:"#8c8c8c",fontSize:11,minWidth:22},C={background:"#fff",border:"1px solid #d9d9d9",borderRadius:4,cursor:"pointer",fontSize:11,minWidth:48,padding:"4px 8px"};function _({engine:n}){const{t}=E(),[l,a]=c.useState(null),[p,r]=c.useState(null),g=c.useRef({}),b=c.useCallback(o=>{if(!o||o.length!==1){a(null),r(null);return}const d=o[0];if((d.globalAlpha===null||d.globalAlpha===void 0)&&(d.globalAlpha=1),a(d),n)try{r(n.getPenRect(d))}catch{r(null)}},[n]),v=c.useCallback(()=>{a(null),r(null)},[]);if(c.useEffect(()=>{if(n)return n.on("active",b),n.on("inactive",v),()=>{n.off("active",b),n.off("inactive",v)}},[n,b,v]),!l||!n)return e.jsx("aside",{style:H,children:e.jsx("div",{style:{color:"#bbb",fontSize:12,padding:16,textAlign:"center"},children:t("meta2d.props.empty")})});const h=(o,d)=>{g.current[o]=d;const i={id:l.id};i[o]=d,o==="dash"&&(i.lineDash=[void 0,[5,5]][d]),n.setValue(i,{render:!0})},B=(o,d)=>{if(!p)return;const i={id:l.id};i[o]=d,n.setValue(i,{render:!0}),r(u=>u?{...u,[o]:d}:null)},w=o=>{o(n),n.render(!0)};return e.jsxs("aside",{style:H,children:[e.jsxs("div",{style:k,children:[e.jsx("div",{style:j,children:t("meta2d.props.text")}),e.jsx("div",{style:f,children:e.jsx("input",{onChange:o=>h("text",o.target.value),style:m,type:"text",value:l.text??""})})]}),e.jsxs("div",{style:k,children:[e.jsx("div",{style:{...j,marginBottom:6},children:t("meta2d.props.appearance")}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.color")}),e.jsx("input",{onChange:o=>h("color",o.target.value),style:{...m,flex:1},type:"color",value:l.color||"#1f1f1f"})]}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.bg")}),e.jsx("input",{onChange:o=>h("background",o.target.value),style:{...m,flex:1},type:"color",value:l.background||"#ffffff"})]}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.dash")}),e.jsxs("select",{onChange:o=>h("dash",Number(o.target.value)),style:{...m,flex:1},value:String(l.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:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.radius")}),e.jsx("input",{max:1,min:0,onChange:o=>h("borderRadius",Number(o.target.value)),step:.01,style:{...m,flex:1},type:"range",value:String(l.borderRadius??0)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:l.borderRadius??0})]}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.alpha")}),e.jsx("input",{max:1,min:0,onChange:o=>h("globalAlpha",Number(o.target.value)),step:.01,style:{...m,flex:1},type:"range",value:String(l.globalAlpha??1)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:(l.globalAlpha??1).toFixed(2)})]})]}),e.jsxs("div",{style:k,children:[e.jsx("div",{style:{...j,marginBottom:6},children:t("meta2d.props.position")}),[["X","x"],["Y","y"],["W","width"],["H","height"]].map(([o,d])=>e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:o}),e.jsx("input",{onChange:i=>B(d,Number(i.target.value)),style:{...m,flex:1},type:"number",value:p?p[d]:0})]},d))]}),e.jsxs("div",{style:k,children:[e.jsx("div",{style:{...j,marginBottom:6},children:t("meta2d.props.textAlign")}),e.jsxs("div",{style:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.h")}),e.jsxs("select",{onChange:o=>h("textAlign",o.target.value),style:{...m,flex:1},value:l.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:f,children:[e.jsx("span",{style:y,children:t("meta2d.props.v")}),e.jsxs("select",{onChange:o=>h("textBaseline",o.target.value),style:{...m,flex:1},value:l.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:k,children:[e.jsx("div",{style:{...j,marginBottom:6},children:t("meta2d.props.layer")}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:[e.jsx("button",{onClick:()=>w(o=>o.top()),style:C,type:"button",children:t("meta2d.props.top")}),e.jsx("button",{onClick:()=>w(o=>o.up()),style:C,type:"button",children:t("meta2d.props.up")}),e.jsx("button",{onClick:()=>w(o=>o.down()),style:C,type:"button",children:t("meta2d.props.down")}),e.jsx("button",{onClick:()=>w(o=>o.bottom()),style:C,type:"button",children:t("meta2d.props.bottom")})]})]})]})}const R={background:"#fff",border:"1px solid #d9d9d9",borderRadius:6,cursor:"pointer",minWidth:68,padding:"6px 12px"},S={...R,fontSize:12,minWidth:52,padding:"4px 10px"};function Z(n){c.useEffect(()=>{const t=document.documentElement,l=document.body,a=t.style.overflow,p=l.style.overflow;return t.style.overflow="hidden",l.style.overflow="hidden",()=>{t.style.overflow=a,l.style.overflow=p}},[n])}function pe({diagram:n,onClose:t,onSave:l}){const{t:a}=E(),p=c.useRef(null),r=c.useRef(null),g=c.useRef(n),b=c.useRef(t),[v,h]=c.useState(null),[B,w]=c.useState(!1);Z(!0),c.useLayoutEffect(()=>{b.current=t}),c.useEffect(()=>{if(!p.current)return;N();const i=new G(p.current,{grid:!0,rule:!1});r.current=i,h(i);try{const x=g.current;x!=null&&x.trim()?i.open(JSON.parse(x)):i.open(F()),A(i.data()),i.render(!0)}catch{i.open(F()),A(i.data()),i.render(!0)}const u=x=>{x.key==="Escape"&&b.current()};return window.addEventListener("keydown",u),()=>{window.removeEventListener("keydown",u);try{i.destroy()}catch{}r.current=null}},[]);const o=async()=>{const i=r.current;if(i){w(!0);try{A(i.data()),i.render(!0);const u=W(i.data()),x=JSON.stringify(u);l(x,await q(i)||await I(x)||'<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{w(!1)}}},d=i=>{const u=r.current;u&&i(u)};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:i=>i.stopPropagation(),onWheel:i=>i.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:a("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:()=>d(i=>i.undo()),style:S,title:`${a("meta2d.editor.undo")} (Ctrl+Z)`,type:"button",children:a("meta2d.editor.undo")}),e.jsx("button",{onClick:()=>d(i=>i.redo()),style:S,title:`${a("meta2d.editor.redo")} (Ctrl+Y)`,type:"button",children:a("meta2d.editor.redo")}),e.jsx("button",{onClick:()=>d(i=>i.delete()),style:S,title:a("meta2d.editor.delete"),type:"button",children:a("meta2d.editor.delete")}),e.jsx("button",{onClick:()=>d(i=>i.fitView(!0)),style:S,title:a("meta2d.editor.fit"),type:"button",children:a("meta2d.editor.fit")}),e.jsx("button",{onClick:()=>d(i=>{i.scale(1),i.centerView()}),style:S,title:a("meta2d.editor.zoom100"),type:"button",children:a("meta2d.editor.zoom100")})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:t,style:R,type:"button",children:a("meta2d.editor.close")}),e.jsx("button",{disabled:B,onClick:()=>void o(),style:{...R,background:"#1677ff",border:"none",color:"#fff"},type:"button",children:a(B?"meta2d.editor.saving":"meta2d.editor.save")})]})]})]}),e.jsxs("div",{style:{display:"flex",flex:1,minHeight:0,overflow:"hidden"},children:[e.jsx(U,{engineRef:r}),e.jsx("div",{ref:p,style:{flex:1,minHeight:0,minWidth:0}}),e.jsx(_,{engine:v})]})]})})}export{pe as DiagramEditor};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as i,j as n}from"./react-vendor-BNpqFP9B.js";import{B as oe}from"./ui-C3xtW1w8.js";import{c as J,g as he,u as ye,a as re,d as Ne,b as Re,f as De,e as Ae,h as Pe,D as Te,F as Le,l as ce,i as Be,S as _e,M as Oe,j as ze,r as pe,k as Fe,m as V,n as He,o as Ue,p as le}from"./index-
|
|
1
|
+
import{r as i,j as n}from"./react-vendor-BNpqFP9B.js";import{B as oe}from"./ui-C3xtW1w8.js";import{c as J,g as he,u as ye,a as re,d as Ne,b as Re,f as De,e as Ae,h as Pe,D as Te,F as Le,l as ce,i as Be,S as _e,M as Oe,j as ze,r as pe,k as Fe,m as V,n as He,o as Ue,p as le}from"./index-B-XJ-ScV.js";import{z as We,A as qe,m as Q,n as Ve,o as $e,p as Je,r as Ge,s as Ke,t as Xe,v as Ye,x as Qe,B as Ze,R as et,a as tt,b as de,c as nt,d as at,e as it,f as st,g as ot,h as rt,i as ct,w as Z,j as lt,O as dt,E as ut,q as mt,l as ft,C as ht,D as yt}from"./react-BsVOIHR8.js";import{H as gt,a as xt,b as vt,M as bt,T as kt,S as It,W as St,N as Ct,o as wt,c as ue}from"./Toolbar-0Y2wmGwe.js";import{V as jt}from"./VisitorPickerModal-COxtOvc4.js";import"./motion-D-I76zAi.js";import"./editor-ONzd_YnO.js";import"./diagram-BJFhx-27.js";import"./plus-DvBbg6jL.js";import"./copy-nOl0d3Th.js";/**
|
|
2
2
|
* @license lucide-react v0.562.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as E,j as W}from"./react-vendor-BNpqFP9B.js";import{b as io,
|
|
1
|
+
import{r as E,j as W}from"./react-vendor-BNpqFP9B.js";import{b as io,ap as js,aq as sa,ar as ra,as as oa}from"./index-B-XJ-ScV.js";import{E as la,B as aa}from"./react-BsVOIHR8.js";import"./ui-C3xtW1w8.js";import"./motion-D-I76zAi.js";import"./editor-ONzd_YnO.js";import"./diagram-BJFhx-27.js";import"./plus-DvBbg6jL.js";import"./copy-nOl0d3Th.js";function hn({lexicalJson:s,onMarkdown:e,onError:t}){const[i,n]=E.useState(null),r=E.useRef(!1);return E.useEffect(()=>{r.current=!1},[s]),E.useEffect(()=>{if(!(!i||r.current))try{i.setDocument("json",s);const o=i.getDocument("markdown");typeof o=="string"&&(r.current=!0,e(o))}catch{t==null||t()}},[i,s,e,t]),W.jsx("div",{className:"mdocs-lexical-md-bridge","aria-hidden":!0,children:W.jsx(la,{content:s,type:"json",editable:!1,onInit:n,plugins:[aa]})})}let Ln=[],no=[];(()=>{let s="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<s.length;e++)(e%2?no:Ln).push(t=t+s[e])})();function ha(s){if(s<768)return!1;for(let e=0,t=Ln.length;;){let i=e+t>>1;if(s<Ln[i])t=i;else if(s>=no[i])e=i+1;else return!0;if(e==t)return!1}}function Ks(s){return s>=127462&&s<=127487}const qs=8205;function ca(s,e,t=!0,i=!0){return(t?so:fa)(s,e,i)}function so(s,e,t){if(e==s.length)return e;e&&ro(s.charCodeAt(e))&&oo(s.charCodeAt(e-1))&&e--;let i=cn(s,e);for(e+=$s(i);e<s.length;){let n=cn(s,e);if(i==qs||n==qs||t&&ha(n))e+=$s(n),i=n;else if(Ks(n)){let r=0,o=e-2;for(;o>=0&&Ks(cn(s,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function fa(s,e,t){for(;e>0;){let i=so(s,e-2,t);if(i<e)return i;e--}return 0}function cn(s,e){let t=s.charCodeAt(e);if(!oo(t)||e+1==s.length)return t;let i=s.charCodeAt(e+1);return ro(i)?(t-55296<<10)+(i-56320)+65536:t}function ro(s){return s>=56320&&s<57344}function oo(s){return s>=55296&&s<56320}function $s(s){return s<65536?1:2}class I{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){[e,t]=Bt(this,e,t);let n=[];return this.decompose(0,e,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(t,this.length,n,1),Pe.from(n,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=Bt(this,e,t);let i=[];return this.decompose(e,t,i,0),Pe.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),n=new qt(this),r=new qt(e);for(let o=t,l=t;;){if(n.next(o),r.next(o),o=0,n.lineBreak!=r.lineBreak||n.done!=r.done||n.value!=r.value)return!1;if(l+=n.value.length,n.done||l>=i)return!0}}iter(e=1){return new qt(this,e)}iterRange(e,t=this.length){return new lo(this,e,t)}iterLines(e,t){let i;if(e==null)i=this.iter();else{t==null&&(t=this.lines+1);let n=this.line(e).from;i=this.iterRange(n,Math.max(n,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new ao(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?I.empty:e.length<=32?new _(e):Pe.from(_.split(e,[]))}}class _ extends I{constructor(e,t=ua(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,n){for(let r=0;;r++){let o=this.text[r],l=n+o.length;if((t?i:l)>=e)return new da(n,l,i,o);n=l+1,i++}}decompose(e,t,i,n){let r=e<=0&&t>=this.length?this:new _(Us(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(n&1){let o=i.pop(),l=Mi(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new _(l,o.length+r.length));else{let a=l.length>>1;i.push(new _(l.slice(0,a)),new _(l.slice(a)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof _))return super.replace(e,t,i);[e,t]=Bt(this,e,t);let n=Mi(this.text,Mi(i.text,Us(this.text,0,e)),t),r=this.length+i.length-(t-e);return n.length<=32?new _(n,r):Pe.from(_.split(n,[]),r)}sliceString(e,t=this.length,i=`
|
|
2
2
|
`){[e,t]=Bt(this,e,t);let n="";for(let r=0,o=0;r<=t&&o<this.text.length;o++){let l=this.text[o],a=r+l.length;r>e&&o&&(n+=i),e<a&&t>r&&(n+=l.slice(Math.max(0,e-r),t-r)),r=a+1}return n}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],n=-1;for(let r of e)i.push(r),n+=r.length+1,i.length==32&&(t.push(new _(i,n)),i=[],n=-1);return n>-1&&t.push(new _(i,n)),t}}class Pe extends I{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,n){for(let r=0;;r++){let o=this.children[r],l=n+o.length,a=i+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,i,n);n=l+1,i=a+1}}decompose(e,t,i,n){for(let r=0,o=0;o<=t&&r<this.children.length;r++){let l=this.children[r],a=o+l.length;if(e<=a&&t>=o){let h=n&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!h?i.push(l):l.decompose(e-o,t-o,i,h)}o=a+1}}replace(e,t,i){if([e,t]=Bt(this,e,t),i.lines<this.lines)for(let n=0,r=0;n<this.children.length;n++){let o=this.children[n],l=r+o.length;if(e>=r&&t<=l){let a=o.replace(e-r,t-r,i),h=this.lines-o.lines+a.lines;if(a.lines<h>>4&&a.lines>h>>6){let c=this.children.slice();return c[n]=a,new Pe(c,this.length-(t-e)+i.length)}return super.replace(r,l,a)}r=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=`
|
|
3
3
|
`){[e,t]=Bt(this,e,t);let n="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],a=o+l.length;o>e&&r&&(n+=i),e<a&&t>o&&(n+=l.sliceString(e-o,t-o,i)),o=a+1}return n}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof Pe))return 0;let i=0,[n,r,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;n+=t,r+=t){if(n==o||r==l)return i;let a=this.children[n],h=e.children[r];if(a!=h)return i+a.scanIdentical(h,t);i+=a.length+1}}static from(e,t=e.reduce((i,n)=>i+n.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let d=[];for(let g of e)g.flatten(d);return new _(d,t)}let n=Math.max(32,i>>5),r=n<<1,o=n>>1,l=[],a=0,h=-1,c=[];function f(d){let g;if(d.lines>r&&d instanceof Pe)for(let p of d.children)f(p);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof _&&a&&(g=c[c.length-1])instanceof _&&d.lines+g.lines<=32?(a+=d.lines,h+=d.length+1,c[c.length-1]=new _(g.text.concat(d.text),g.length+1+d.length)):(a+d.lines>n&&u(),a+=d.lines,h+=d.length+1,c.push(d))}function u(){a!=0&&(l.push(c.length==1?c[0]:Pe.from(c,h)),h=-1,a=c.length=0)}for(let d of e)f(d);return u(),l.length==1?l[0]:new Pe(l,t)}}I.empty=new _([""],0);function ua(s){let e=-1;for(let t of s)e+=t.length+1;return e}function Mi(s,e,t=0,i=1e9){for(let n=0,r=0,o=!0;r<s.length&&n<=i;r++){let l=s[r],a=n+l.length;a>=t&&(a>i&&(l=l.slice(0,i-n)),n<t&&(l=l.slice(t-n)),o?(e[e.length-1]+=l,o=!1):e.push(l)),n=a+1}return e}function Us(s,e,t){return Mi(s,[""],e,t)}class qt{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof _?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],r=this.offsets[i],o=r>>1,l=n instanceof _?n.text.length:n.children.length;if(o==(t>0?l:0)){if(i==0)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(t>0?0:1)){if(this.offsets[i]+=t,e==0)return this.lineBreak=!0,this.value=`
|
|
4
4
|
`,this;e--}else if(n instanceof _){let a=n.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=n.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof _?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class lo{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new qt(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:n}=this.cursor.next(e);return this.pos+=(n.length+e)*t,this.value=n.length<=i?n:t<0?n.slice(n.length-i):n.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class ao{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:n}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(I.prototype[Symbol.iterator]=function(){return this.iter()},qt.prototype[Symbol.iterator]=lo.prototype[Symbol.iterator]=ao.prototype[Symbol.iterator]=function(){return this});class da{constructor(e,t,i,n){this.from=e,this.to=t,this.number=i,this.text=n}get length(){return this.to-this.from}}function Bt(s,e,t){return e=Math.max(0,Math.min(s.length,e)),[e,Math.max(e,Math.min(s.length,t))]}function le(s,e,t=!0,i=!0){return ca(s,e,t,i)}function ga(s){return s>=56320&&s<57344}function pa(s){return s>=55296&&s<56320}function ma(s,e){let t=s.charCodeAt(e);if(!pa(t)||e+1==s.length)return t;let i=s.charCodeAt(e+1);return ga(i)?(t-55296<<10)+(i-56320)+65536:t}function ya(s){return s<65536?1:2}const En=/\r\n?|\n/;var me=function(s){return s[s.Simple=0]="Simple",s[s.TrackDel=1]="TrackDel",s[s.TrackBefore=2]="TrackBefore",s[s.TrackAfter=3]="TrackAfter",s}(me||(me={}));class Ve{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,n=0;t<this.sections.length;){let r=this.sections[t++],o=this.sections[t++];o<0?(e(i,n,r),n+=r):n+=o,i+=r}}iterChangedRanges(e,t=!1){Rn(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];n<0?e.push(i,n):e.push(n,i)}return new Ve(e)}composeDesc(e){return this.empty?e:e.empty?this:ho(this,e)}mapDesc(e,t=!1){return e.empty?this:In(this,e,t)}mapPos(e,t=-1,i=me.Simple){let n=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],h=n+l;if(a<0){if(h>e)return r+(e-n);r+=l}else{if(i!=me.Simple&&h>=e&&(i==me.TrackDel&&n<e&&h>e||i==me.TrackBefore&&n<e||i==me.TrackAfter&&h>e))return null;if(h>e||h==e&&t<0&&!l)return e==n||t<0?r:r+a;r+=a}n=h}if(e>n)throw new RangeError(`Position ${e} is out of range for changeset of length ${n}`);return r}touchesRange(e,t=e){for(let i=0,n=0;i<this.sections.length&&n<=t;){let r=this.sections[i++],o=this.sections[i++],l=n+r;if(o>=0&&n<=t&&l>=e)return n<e&&l>t?"cover":!0;n=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];e+=(e?" ":"")+i+(n>=0?":"+n:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Ve(e)}static create(e){return new Ve(e)}}class Q extends Ve{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Rn(this,(t,i,n,r,o)=>e=e.replace(n,n+(i-t),o),!1),e}mapDesc(e,t=!1){return In(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let n=0,r=0;n<t.length;n+=2){let o=t[n],l=t[n+1];if(l>=0){t[n]=l,t[n+1]=o;let a=n>>1;for(;i.length<a;)i.push(I.empty);i.push(o?e.slice(r,r+o):I.empty)}r+=o}return new Q(t,i)}compose(e){return this.empty?e:e.empty?this:ho(this,e,!0)}map(e,t=!1){return e.empty?this:In(this,e,t,!0)}iterChanges(e,t=!1){Rn(this,e,t)}get desc(){return Ve.create(this.sections)}filter(e){let t=[],i=[],n=[],r=new Yt(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break e;let c=Math.min(r.len,a-l);oe(n,c,-1);let f=r.ins==-1?-1:r.off==0?r.ins:0;oe(t,c,f),f>0&&Xe(i,t,r.text),r.forward(c),l+=c}let h=e[o++];for(;l<h;){if(r.done)break e;let c=Math.min(r.len,h-l);oe(t,c,-1),oe(n,c,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(c),l+=c}}return{changes:new Q(t,i),filtered:Ve.create(n)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],n=this.sections[t+1];n<0?e.push(i):n==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let n=[],r=[],o=0,l=null;function a(c=!1){if(!c&&!n.length)return;o<t&&oe(n,t-o,-1);let f=new Q(n,r);l=l?l.compose(f.map(l)):f,n=[],r=[],o=0}function h(c){if(Array.isArray(c))for(let f of c)h(f);else if(c instanceof Q){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);a(),l=l?l.compose(c.map(l)):c}else{let{from:f,to:u=f,insert:d}=c;if(f>u||f<0||u>t)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`);let g=d?typeof d=="string"?I.of(d.split(i||En)):d:I.empty,p=g.length;if(f==u&&p==0)return;f<o&&a(),f>o&&oe(n,f-o,-1),oe(n,u-f,p),Xe(r,n,g),o=u}}return h(e),a(!l),l}static empty(e){return new Q(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let n=0;n<e.length;n++){let r=e[n];if(typeof r=="number")t.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;i.length<n;)i.push(I.empty);i[n]=I.of(r.slice(1)),t.push(r[0],i[n].length)}}}return new Q(t,i)}static createSet(e,t){return new Q(e,t)}}function oe(s,e,t,i=!1){if(e==0&&t<=0)return;let n=s.length-2;n>=0&&t<=0&&t==s[n+1]?s[n]+=e:n>=0&&e==0&&s[n]==0?s[n+1]+=t:i?(s[n]+=e,s[n+1]+=t):s.push(e,t)}function Xe(s,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i<s.length)s[s.length-1]=s[s.length-1].append(t);else{for(;s.length<i;)s.push(I.empty);s.push(t)}}function Rn(s,e,t){let i=s.inserted;for(let n=0,r=0,o=0;o<s.sections.length;){let l=s.sections[o++],a=s.sections[o++];if(a<0)n+=l,r+=l;else{let h=n,c=r,f=I.empty;for(;h+=l,c+=a,a&&i&&(f=f.append(i[o-2>>1])),!(t||o==s.sections.length||s.sections[o+1]<0);)l=s.sections[o++],a=s.sections[o++];e(n,h,r,c,f),n=h,r=c}}}function In(s,e,t,i=!1){let n=[],r=i?[]:null,o=new Yt(s),l=new Yt(e);for(let a=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&l.ins==-1){let h=Math.min(o.len,l.len);oe(n,h,-1),o.forward(h),l.forward(h)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let h=l.len;for(oe(n,l.ins,-1);h;){let c=Math.min(o.len,h);o.ins>=0&&a<o.i&&o.len<=c&&(oe(n,0,o.ins),r&&Xe(r,n,o.text),a=o.i),o.forward(c),h-=c}l.next()}else if(o.ins>=0){let h=0,c=o.len;for(;c;)if(l.ins==-1){let f=Math.min(c,l.len);h+=f,c-=f,l.forward(f)}else if(l.ins==0&&l.len<c)c-=l.len,l.next();else break;oe(n,h,a<o.i?o.ins:0),r&&a<o.i&&Xe(r,n,o.text),a=o.i,o.forward(o.len-c)}else{if(o.done&&l.done)return r?Q.createSet(n,r):Ve.create(n);throw new Error("Mismatched change set lengths")}}}function ho(s,e,t=!1){let i=[],n=t?[]:null,r=new Yt(s),o=new Yt(e);for(let l=!1;;){if(r.done&&o.done)return n?Q.createSet(i,n):Ve.create(i);if(r.ins==0)oe(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)oe(i,0,o.ins,l),n&&Xe(n,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(r.len2,o.len),h=i.length;if(r.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;oe(i,a,c,l),n&&c&&Xe(n,i,o.text)}else o.ins==-1?(oe(i,r.off?0:r.len,a,l),n&&Xe(n,i,r.textBit(a))):(oe(i,r.off?0:r.len,o.off?0:o.ins,l),n&&!o.off&&Xe(n,i,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>h),r.forward2(a),o.forward(a)}}}}class Yt{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?I.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?I.empty:t[i].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class ct{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let i,n;return this.empty?i=n=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),n=e.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new ct(i,n,this.flags)}extend(e,t=e,i=0){if(e<=this.anchor&&t>=this.anchor)return b.range(e,t,void 0,void 0,i);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return b.range(this.anchor,n,void 0,void 0,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return b.range(e.anchor,e.head)}static create(e,t,i){return new ct(e,t,i)}}class b{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:b.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new b([this.main],0)}addRange(e,t=!0){return b.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,b.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new b(e.ranges.map(t=>ct.fromJSON(t)),e.main)}static single(e,t=e){return new b([b.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;n<e.length;n++){let r=e[n];if(r.empty?r.from<=i:r.from<i)return b.normalized(e.slice(),t);i=r.to}return new b(e,t)}static cursor(e,t=0,i,n){return ct.create(e,e,(t==0?0:t<0?8:16)|(i==null?7:Math.min(6,i))|(n??16777215)<<6)}static range(e,t,i,n,r){let o=(i??16777215)<<6|(n==null?7:Math.min(6,n));return!r&&e!=t&&(r=t<e?1:-1),t<e?ct.create(t,e,48|o):ct.create(e,t,(r?r<0?8:16:0)|o)}static normalized(e,t=0){let i=e[t];e.sort((n,r)=>n.from-r.from),t=e.indexOf(i);for(let n=1;n<e.length;n++){let r=e[n],o=e[n-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,a=Math.max(r.to,o.to);n<=t&&t--,e.splice(--n,2,r.anchor>r.head?b.range(a,l):b.range(l,a))}}return new b(e,t)}}function co(s,e){for(let t of s.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let bs=0;class M{constructor(e,t,i,n,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=n,this.id=bs++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new M(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:xs),!!e.static,e.enables)}of(e){return new Di([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Di(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Di(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function xs(s,e){return s==e||s.length==e.length&&s.every((t,i)=>t===e[i])}class Di{constructor(e,t,i,n){this.dependencies=e,this.facet=t,this.type=i,this.value=n,this.id=bs++}dynamicSlot(e){var t;let i=this.value,n=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,a=!1,h=!1,c=[];for(let f of this.dependencies)f=="doc"?a=!0:f=="selection"?h=!0:((t=e[f.id])!==null&&t!==void 0?t:1)&1||c.push(e[f.id]);return{create(f){return f.values[o]=i(f),1},update(f,u){if(a&&u.docChanged||h&&(u.docChanged||u.selection)||Pn(f,c)){let d=i(f);if(l?!Gs(d,f.values[o],n):!n(d,f.values[o]))return f.values[o]=d,1}return 0},reconfigure:(f,u)=>{let d,g=u.config.address[r];if(g!=null){let p=Ri(u,g);if(this.dependencies.every(m=>m instanceof M?u.facet(m)===f.facet(m):m instanceof ze?u.field(m,!1)==f.field(m,!1):!0)||(l?Gs(d=i(f),p,n):n(d=i(f),p)))return f.values[o]=p,0}else d=i(f);return f.values[o]=d,1}}}}function Gs(s,e,t){if(s.length!=e.length)return!1;for(let i=0;i<s.length;i++)if(!t(s[i],e[i]))return!1;return!0}function Pn(s,e){let t=!1;for(let i of e)$t(s,i)&1&&(t=!0);return t}function ba(s,e,t){let i=t.map(a=>s[a.id]),n=t.map(a=>a.type),r=i.filter(a=>!(a&1)),o=s[e.id]>>1;function l(a){let h=[];for(let c=0;c<i.length;c++){let f=Ri(a,i[c]);if(n[c]==2)for(let u of f)h.push(u);else h.push(f)}return e.combine(h)}return{create(a){for(let h of i)$t(a,h);return a.values[o]=l(a),1},update(a,h){if(!Pn(a,r))return 0;let c=l(a);return e.compare(c,a.values[o])?0:(a.values[o]=c,1)},reconfigure(a,h){let c=Pn(a,i),f=h.config.facets[e.id],u=h.facet(e);if(f&&!c&&xs(t,f))return a.values[o]=u,0;let d=l(a);return e.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const hi=M.define({static:!0});class ze{constructor(e,t,i,n,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=n,this.spec=r,this.provides=void 0}static define(e){let t=new ze(bs++,e.create,e.update,e.compare||((i,n)=>i===n),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(hi).find(i=>i.field==this);return((t==null?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,n)=>{let r=i.values[t],o=this.updateF(r,n);return this.compareF(r,o)?0:(i.values[t]=o,1)},reconfigure:(i,n)=>{let r=i.facet(hi),o=n.facet(hi),l;return(l=r.find(a=>a.field==this))&&l!=o.find(a=>a.field==this)?(i.values[t]=l.create(i),1):n.config.address[this.id]!=null?(i.values[t]=n.field(this),0):(i.values[t]=this.create(i),1)}}}init(e){return[this,hi.of({field:this,create:e})]}get extension(){return this}}const ht={lowest:4,low:3,default:2,high:1,highest:0};function Wt(s){return e=>new uo(e,s)}const fo={highest:Wt(ht.highest),high:Wt(ht.high),default:Wt(ht.default),low:Wt(ht.low),lowest:Wt(ht.lowest)};class uo{constructor(e,t){this.inner=e,this.prec=t}}class Yi{of(e){return new Nn(this,e)}reconfigure(e){return Yi.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class Nn{constructor(e,t){this.compartment=e,this.inner=t}}class Ei{constructor(e,t,i,n,r,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=n,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let n=[],r=Object.create(null),o=new Map;for(let u of xa(e,t,o))u instanceof ze?n.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],h=[];for(let u of n)l[u.id]=h.length<<1,h.push(d=>u.slot(d));let c=i==null?void 0:i.config.facets;for(let u in r){let d=r[u],g=d[0].facet,p=c&&c[u]||[];if(d.every(m=>m.type==0))if(l[g.id]=a.length<<1|1,xs(p,d))a.push(i.facet(g));else{let m=g.combine(d.map(y=>y.value));a.push(i&&g.compare(m,i.facet(g))?i.facet(g):m)}else{for(let m of d)m.type==0?(l[m.id]=a.length<<1|1,a.push(m.value)):(l[m.id]=h.length<<1,h.push(y=>m.dynamicSlot(y)));l[g.id]=h.length<<1,h.push(m=>ba(m,g,d))}}let f=h.map(u=>u(l));return new Ei(e,o,f,l,a,r)}}function xa(s,e,t){let i=[[],[],[],[],[]],n=new Map;function r(o,l){let a=n.get(o);if(a!=null){if(a<=l)return;let h=i[a].indexOf(o);h>-1&&i[a].splice(h,1),o instanceof Nn&&t.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let h of o)r(h,l);else if(o instanceof Nn){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),r(h,l)}else if(o instanceof uo)r(o.inner,o.prec);else if(o instanceof ze)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof Di)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,ht.default);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(h,l)}}return r(s,ht.default),i.reduce((o,l)=>o.concat(l))}function $t(s,e){if(e&1)return 2;let t=e>>1,i=s.status[t];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;s.status[t]=4;let n=s.computeSlot(s,s.config.dynamicSlots[t]);return s.status[t]=2|n}function Ri(s,e){return e&1?s.config.staticValues[e>>1]:s.values[e>>1]}const go=M.define(),Wn=M.define({combine:s=>s.some(e=>e),static:!0}),po=M.define({combine:s=>s.length?s[0]:void 0,static:!0}),mo=M.define(),yo=M.define(),bo=M.define(),xo=M.define({combine:s=>s.length?s[0]:!1});class nt{constructor(e,t){this.type=e,this.value=t}static define(){return new wa}}class wa{of(e){return new nt(this,e)}}class ka{constructor(e){this.map=e}of(e){return new G(this,e)}}class G{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new G(this.type,t)}is(e){return this.type==e}static define(e={}){return new ka(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let n of e){let r=n.map(t);r&&i.push(r)}return i}}G.reconfigure=G.define();G.appendConfig=G.define();class Z{constructor(e,t,i,n,r,o){this.startState=e,this.changes=t,this.selection=i,this.effects=n,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&co(i,t.newLength),r.some(l=>l.type==Z.time)||(this.annotations=r.concat(Z.time.of(Date.now())))}static create(e,t,i,n,r,o){return new Z(e,t,i,n,r,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(Z.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}Z.time=nt.define();Z.userEvent=nt.define();Z.addToHistory=nt.define();Z.remote=nt.define();function Sa(s,e){let t=[];for(let i=0,n=0;;){let r,o;if(i<s.length&&(n==e.length||e[n]>=s[i]))r=s[i++],o=s[i++];else if(n<e.length)r=e[n++],o=e[n++];else return t;!t.length||t[t.length-1]<r?t.push(r,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function wo(s,e,t){var i;let n,r,o;return t?(n=e.changes,r=Q.empty(e.changes.length),o=s.changes.compose(e.changes)):(n=e.changes.map(s.changes),r=s.changes.mapDesc(e.changes,!0),o=s.changes.compose(n)),{changes:o,selection:e.selection?e.selection.map(r):(i=s.selection)===null||i===void 0?void 0:i.map(n),effects:G.mapEffects(s.effects,n).concat(G.mapEffects(e.effects,r)),annotations:s.annotations.length?s.annotations.concat(e.annotations):e.annotations,scrollIntoView:s.scrollIntoView||e.scrollIntoView}}function Hn(s,e,t){let i=e.selection,n=Ct(e.annotations);return e.userEvent&&(n=n.concat(Z.userEvent.of(e.userEvent))),{changes:e.changes instanceof Q?e.changes:Q.of(e.changes||[],t,s.facet(po)),selection:i&&(i instanceof b?i:b.single(i.anchor,i.head)),effects:Ct(e.effects),annotations:n,scrollIntoView:!!e.scrollIntoView}}function ko(s,e,t){let i=Hn(s,e.length?e[0]:{},s.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let r=1;r<e.length;r++){e[r].filter===!1&&(t=!1);let o=!!e[r].sequential;i=wo(i,Hn(s,e[r],o?i.changes.newLength:s.doc.length),o)}let n=Z.create(s,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return Ca(t?va(n):n)}function va(s){let e=s.startState,t=!0;for(let n of e.facet(mo)){let r=n(s);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:Sa(t,r))}if(t!==!0){let n,r;if(t===!1)r=s.changes.invertedDesc,n=Q.empty(e.doc.length);else{let o=s.changes.filter(t);n=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}s=Z.create(e,n,s.selection&&s.selection.map(r),G.mapEffects(s.effects,r),s.annotations,s.scrollIntoView)}let i=e.facet(yo);for(let n=i.length-1;n>=0;n--){let r=i[n](s);r instanceof Z?s=r:Array.isArray(r)&&r.length==1&&r[0]instanceof Z?s=r[0]:s=ko(e,Ct(r),!1)}return s}function Ca(s){let e=s.startState,t=e.facet(bo),i=s;for(let n=t.length-1;n>=0;n--){let r=t[n](s);r&&Object.keys(r).length&&(i=wo(i,Hn(e,r,s.changes.newLength),!0))}return i==s?s:Z.create(e,s.changes,s.selection,i.effects,i.annotations,i.scrollIntoView)}const Aa=[];function Ct(s){return s==null?Aa:Array.isArray(s)?s:[s]}var Ke=function(s){return s[s.Word=0]="Word",s[s.Space=1]="Space",s[s.Other=2]="Other",s}(Ke||(Ke={}));const Ma=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Fn;try{Fn=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function Da(s){if(Fn)return Fn.test(s);for(let e=0;e<s.length;e++){let t=s[e];if(/\w/.test(t)||t>""&&(t.toUpperCase()!=t.toLowerCase()||Ma.test(t)))return!0}return!1}function Ta(s){return e=>{if(!/\S/.test(e))return Ke.Space;if(Da(e))return Ke.Word;for(let t=0;t<s.length;t++)if(e.indexOf(s[t])>-1)return Ke.Word;return Ke.Other}}class N{constructor(e,t,i,n,r,o){this.config=e,this.doc=t,this.selection=i,this.values=n,this.status=e.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)$t(this,l<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(i==null){if(t)throw new RangeError("Field is not present in this state");return}return $t(this,i),Ri(this,i)}update(...e){return ko(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:n}=t;for(let l of e.effects)l.is(Yi.reconfigure)?(t&&(n=new Map,t.compartments.forEach((a,h)=>n.set(h,a)),t=null),n.set(l.value.compartment,l.value.extension)):l.is(G.reconfigure)?(t=null,i=l.value):l.is(G.appendConfig)&&(t=null,i=Ct(i).concat(l.value));let r;t?r=e.startState.values.slice():(t=Ei.resolve(i,n,this),r=new N(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,h)=>h.reconfigure(a,this),null).values);let o=e.startState.facet(Wn)?e.newSelection:e.newSelection.asSingle();new N(t,e.newDoc,o,r,(l,a)=>a.update(l,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:b.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),n=this.changes(i.changes),r=[i.range],o=Ct(i.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),h=this.changes(a.changes),c=h.map(n);for(let u=0;u<l;u++)r[u]=r[u].map(c);let f=n.mapDesc(h,!0);r.push(a.range.map(f)),n=n.compose(c),o=G.mapEffects(o,c).concat(G.mapEffects(Ct(a.effects),f))}return{changes:n,selection:b.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof Q?e:Q.of(e,this.doc.length,this.facet(N.lineSeparator))}toText(e){return I.of(e.split(this.facet(N.lineSeparator)||En))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:($t(this,t),Ri(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let n=e[i];n instanceof ze&&this.config.address[n.id]!=null&&(t[i]=n.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let n=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let o=i[r],l=e[r];n.push(o.init(a=>o.spec.fromJSON(l,a)))}}return N.create({doc:e.doc,selection:b.fromJSON(e.selection),extensions:t.extensions?n.concat([t.extensions]):n})}static create(e={}){let t=Ei.resolve(e.extensions||[],new Map),i=e.doc instanceof I?e.doc:I.of((e.doc||"").split(t.staticFacet(N.lineSeparator)||En)),n=e.selection?e.selection instanceof b?e.selection:b.single(e.selection.anchor,e.selection.head):b.single(0);return co(n,i.length),t.staticFacet(Wn)||(n=n.asSingle()),new N(t,i,n,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(N.tabSize)}get lineBreak(){return this.facet(N.lineSeparator)||`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as n,j as o,ae as C}from"./react-vendor-BNpqFP9B.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 H,w as g,j as L,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-
|
|
1
|
+
import{r as n,j as o,ae as C}from"./react-vendor-BNpqFP9B.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 H,w as g,j as L,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-BsVOIHR8.js";import{m as Q,n as X,H as ee,o as te,A as k,p as oe}from"./ui-C3xtW1w8.js";import{H as re,a as ae,b as ne,M as le,T as ie,S as se,W as de,N as ce,c as R,o as me}from"./Toolbar-0Y2wmGwe.js";import"./editor-ONzd_YnO.js";import"./diagram-BJFhx-27.js";import"./index-B-XJ-ScV.js";import"./motion-D-I76zAi.js";import"./plus-DvBbg6jL.js";import"./copy-nOl0d3Th.js";const ue=({children:h,json:r,markdown:a,collapsible:m=!1,defaultActiveKey:y=["editor","text","json"],onJSONChange:p})=>{const[f,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:f,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,f]=n.useState(""),c=n.useMemo(()=>S(t=>{const e=t.getDocument("markdown"),l=t.getDocument("json");f(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=>{me(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:ce,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,H,g(L,{children:o.jsx(R,{editor:r,floating:!0})}),g(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:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as a,j as e}from"./react-vendor-BNpqFP9B.js";import{b as Z,q as We,s as Ue,D as _e,l as ce,t as He,v as qe,w as _,x as le,y as Ge,z as Ze,A as Je,a as Qe,d as Ne,B as ve,C as ke,E as Xe,G as Ye,H as es,I as ss,J as ts,K as we,L as ne,N as as,O as ns,P as is,Q as cs,R as ls,f as rs,T as os,U as ds,V as ms,W as us,X as hs,i as gs,Y as ps,Z as fs,_ as xs,$ as js,a0 as Ns,a1 as ys,a2 as bs,a3 as vs,a4 as ks,a5 as ws,a6 as Ss,a7 as Cs,a8 as Ds,r as Is,j as Ts,a9 as As,n as Es,o as Ps}from"./index-czw0A2GN.js";import{V as Se,a as Ms,M as Ls}from"./VisitorPickerModal-Db9Mh63R.js";import"./ui-C3xtW1w8.js";import"./motion-D-I76zAi.js";function Rs({draft:t,onClose:s,onSuccess:k}){const{t:h,lang:g}=Z(),[M,r]=a.useState([]),[y,b]=a.useState(t.domainId??""),[C,i]=a.useState([]),[N,f]=a.useState(""),[d,j]=a.useState(`${t.displayName||"untitled"}_recovered.md`),[u,z]=a.useState(!1),[T,R]=a.useState(null),I=a.useRef(null),A=a.useRef(!0);a.useEffect(()=>(A.current=!0,()=>{A.current=!1}),[]),a.useEffect(()=>{We().then(x=>{A.current&&r(x)})},[]),a.useEffect(()=>{y&&(i([]),f(""),Ue(y).then(x=>{A.current&&i(x)}).catch(()=>{A.current&&i([])}))},[y]),a.useEffect(()=>{const x=window.setTimeout(()=>{var P;return(P=I.current)==null?void 0:P.focus()},0);return()=>window.clearTimeout(x)},[]),a.useEffect(()=>{const x=P=>{P.key==="Escape"&&s()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[s]);function B(x,P){for(const v of x){if(v.type==="folder"&&v.path===P)return v.documentId;if(v.type==="folder"){const S=B(v.children,P);if(S)return S}}return null}async function E(x){x.preventDefault(),z(!0),R(null);const P=d.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),v=P.endsWith(".md")?P:P+".md",S=v.replace(/\.md$/i,"");try{const l=N?`${N}/${v}`:v,c=N?B(C,N)??void 0:void 0;await qe({fileName:v,displayName:S,content:t.content,domainId:y,parentId:c}),k()}catch(l){R(_(h,l))}finally{z(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:x=>{x.target===x.currentTarget&&!u&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:h("recoverDraft")}),e.jsx("p",{className:"muted",children:h("recoverDraftDesc",{name:t.displayName||h("unknownTitle")})}),e.jsxs("form",{onSubmit:E,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[h("domainLabel"),M.length>0&&e.jsx(_e,{domains:M,value:y,onChange:b,onDomainsChange:r,ariaLabel:h("domainLabel"),localizeName:x=>ce(x,g,h)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[h("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(He,{nodes:C,activeDocumentId:null,selectedParentPath:N,onOpen:()=>{},onOpenFolder:x=>f(x),onContextMenu:()=>{},onDeselect:()=>f("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[h("fileNameLabel"),e.jsx("input",{ref:I,value:d,onChange:x=>j(x.target.value),placeholder:"recovered.md",maxLength:200,disabled:u})]}),T&&e.jsx("div",{className:"mdocs-dialog-error",children:T}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!u&&s(),disabled:u,children:h("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:u,children:h(u?"creating":"create")})]})]})]})})}function zs({onPublish:t,onClose:s,onCountChange:k,onRecover:h}){const{t:g}=Z(),[M,r]=a.useState([]),[y,b]=a.useState(new Set),[C,i]=a.useState(!1),[N,f]=a.useState(null),[d,j]=a.useState(null),[u,z]=a.useState(null),T=a.useRef(null),R=a.useRef(!0);a.useEffect(()=>(R.current=!0,le().then(c=>{if(!R.current)return;const m=c.filter(w=>!w.published);r(m),k==null||k(m.length)}),()=>{R.current=!1,T.current&&(clearTimeout(T.current),T.current=null)}),[]),a.useEffect(()=>{const c=m=>{m.key==="Escape"&&s()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[s]);const I=a.useCallback((c,m)=>{z({message:c,type:m}),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>z(null),3e3)},[]);async function A(c){await Ze(c),b(m=>new Set(m).add(c));try{await t(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),I(g("published"),"success")}catch(m){m instanceof Je||I(g("publishFailed"),"error");const w=await Qe(c);w&&r(F=>F.map(K=>K.documentId===c?w:K))}finally{b(m=>{const w=new Set(m);return w.delete(c),w})}}async function B(c){f(null),await Ne(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),I(g("draftDeleted"),"success")}function E(c){const m=M.find(w=>w.documentId===c);m&&j(m)}function x(c){j(null),Ne(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),h==null||h(M.find(m=>m.documentId===c)),I(g("published"),"success")}async function P(){i(!0);let c=0,m=0;for(const K of M)try{await t(K.documentId),c++}catch{m++}const F=(await le()).filter(K=>!K.published);r(F),k==null||k(F.length),m===0?I(g("publishAll"),"success"):I(`${c} published, ${m} failed`,"error"),i(!1)}const v=c=>new Date(c).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),S=c=>Ge(g,c,c.publishError??"UNKNOWN"),l=M;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:[g("unpublishedDrafts"),l.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:l.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:g("draftCount",{count:String(l.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":g("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:l.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:g("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:l.map(c=>{const m=!!c.publishError;return e.jsxs("div",{className:m?"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:c.displayName||g("unknownTitle")}),m?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[v(c.publishErrorAt)," · ",S(c)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[v(c.updatedAt)," · ",g("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[m?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:C,onClick:()=>E(c.documentId),children:g("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:y.has(c.documentId)||C,onClick:()=>void A(c.documentId),children:y.has(c.documentId)?g("publishing"):g("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:C,onClick:()=>f(c.documentId),children:g("delete")})]})]},c.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:g("close")}),e.jsx("button",{type:"button",className:"primary",disabled:l.length===0||C,onClick:()=>void P(),children:C?g("publishing"):`${g("publishAll")} (${l.length})`})]}),u&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+u.type,role:"status",children:u.message})]}),N&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:c=>{c.target===c.currentTarget&&f(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:g("delete")}),e.jsx("p",{className:"muted",children:g("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>f(null),children:g("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void B(N),children:g("delete")})]})]})}),d&&e.jsx(Rs,{draft:d,onClose:()=>j(null),onSuccess:()=>x(d.documentId)})]})}function Bs(){const{t,lang:s}=Z(),k=ve(),h=a.useRef(!1),[g,M]=a.useState([]),[r,y]=a.useState(!1),[b,C]=a.useState(""),[i,N]=a.useState("restricted"),[f,d]=a.useState(!1),[j,u]=a.useState(null),[z,T]=a.useState(null),[R,I]=a.useState(""),[A,B]=a.useState(""),[E,x]=a.useState("all"),[P,v]=a.useState(null);a.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]);const S=a.useCallback(async()=>{y(!0),u(null);try{const p=await ke();if(!h.current)return;M(p)}catch(p){if(!h.current)return;u(_(t,p))}finally{h.current&&y(!1)}},[t]);a.useEffect(()=>{S()},[S]);async function l(p){if(p.preventDefault(),!b.trim()){u(t("domainNameRequired"));return}d(!0),u(null);try{if(await ts({domainName:b.trim(),permission:i}),!h.current)return;C(""),N("restricted"),await S()}catch(V){if(!h.current)return;u(_(t,V))}finally{h.current&&d(!1)}}async function c(p){if(R.trim()){u(null);try{if(await ss(p,R.trim()),!h.current)return;T(null),v(null),await S()}catch(V){if(!h.current)return;u(_(t,V))}}}function m(p){T(p.domainId),I(p.domainName),v(null)}function w(){T(null),v(null)}async function F(p,V){u(null);try{if(await es(p,V),!h.current)return;v(null),await S()}catch($){if(!h.current)return;u(_(t,$))}}async function K(p){if(window.confirm(t("deleteDomainConfirmDetail",{name:p.domainName,count:String(p.docCount)}))){u(null);try{if(await Ye(p.domainId),!h.current)return;await S()}catch(V){if(!h.current)return;u(_(t,V))}}}const H=a.useCallback(p=>Xe(p,t),[t]),q=a.useCallback(p=>ce(p.domainName,s,t),[s,t]),G=a.useMemo(()=>{const p=A.trim().toLowerCase();return g.filter(V=>E!=="all"&&V.permission!==E?!1:p?ce(V.domainName,s,t).toLowerCase().includes(p)||V.domainName.toLowerCase().includes(p):!0)},[g,A,E,s,t]),D=a.useCallback((p,V)=>{const $=H(p.permission);return V?`${$} ${t("domainTypeBuiltinSuffix")}`:$},[H,t]);return{domains:g,loadingDomains:r,domainError:j,newDomainName:b,setNewDomainName:C,newDomainPermission:i,setNewDomainPermission:N,creating:f,handleCreateDomain:l,renamingId:z,setRenamingId:T,renameDraft:R,setRenameDraft:I,startRename:m,cancelRename:w,handleRename:c,changeTypeForId:P,setChangeTypeForId:v,handlePermissionChange:F,handleDelete:K,domainSearch:A,setDomainSearch:B,domainFilter:E,setDomainFilter:x,filteredDomains:G,visitorId:k,plabel:H,localizeDomain:q,domainTypeLabel:D}}function Fs(){const{t}=Z(),s=Bs(),[k,h]=a.useState([]),[g,M]=a.useState(null),[r,y]=a.useState(null),b=a.useCallback(async()=>{try{const i=await we();h(i)}catch{h([])}},[]);a.useEffect(()=>{b()},[b]);async function C(i){M(null);try{const N=await ls(i.domainId);y({domainId:i.domainId,creatorVisitorId:i.creatorVisitorId,initialIds:N.map(f=>f.visitorId),memberRows:N})}catch(N){M({kind:"err",text:_(t,N)})}}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:i=>s.setNewDomainName(i.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:ne.map(i=>e.jsxs("label",{className:"mdocs-domain-mgmt-radio",children:[e.jsx("input",{type:"radio",name:"newDomainPermission",checked:s.newDomainPermission===i,onChange:()=>s.setNewDomainPermission(i),disabled:s.creating}),e.jsx("span",{children:s.plabel(i)})]},i))})]}),e.jsx("button",{type:"submit",className:"primary mdocs-domain-mgmt-submit",disabled:s.creating,children:s.creating?t("creating"):t("create")})]})]}),g&&e.jsx("div",{className:"mdocs-settings-card",style:{color:g.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:g.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:i=>s.setDomainSearch(i.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",...ne].map(i=>e.jsx("button",{type:"button",className:"mdocs-domain-mgmt-filter"+(s.domainFilter===i?" active":""),"aria-pressed":s.domainFilter===i,onClick:()=>s.setDomainFilter(i),children:i==="all"?t("domainFilterAll"):s.plabel(i)},i))})]}),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(i=>{const N=as(i,s.visitorId),f=ns(i.domainId),d=is(i),j=d?t("domainTooltipTypeLocked",{count:String(i.docCount)}):void 0;return e.jsxs("tr",{className:f?"mdocs-domain-table-row-builtin":void 0,children:[e.jsx("td",{children:s.renamingId===i.domainId?e.jsxs("div",{className:"mdocs-domain-table-rename",children:[e.jsx("input",{value:s.renameDraft,onChange:u=>s.setRenameDraft(u.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(i.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(i)}),f&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:t("domainBuiltIn")}),!N&&!f&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:t("shared")})]})}),e.jsx("td",{children:e.jsxs("span",{className:"mdocs-domain-table-type",title:j,children:[e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":i.permission,children:s.domainTypeLabel(i,f)}),d&&!f&&e.jsx("span",{className:"mdocs-domain-type-lock","aria-hidden":"true",children:"🔒"})]})}),e.jsx("td",{className:"mdocs-domain-table-num",children:i.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[f&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:t("domainNotModifiable")}),!f&&!N&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:t("domainNotCreator")}),!f&&N&&s.changeTypeForId===i.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",children:[e.jsx("div",{className:"mdocs-domain-permission-select",children:ne.map(u=>e.jsx("button",{type:"button",className:i.permission===u?"active":"",onClick:()=>void s.handlePermissionChange(i.domainId,u),children:s.plabel(u)},u))}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>s.setChangeTypeForId(null),children:t("cancel")})]}),!f&&N&&s.renamingId!==i.domainId&&s.changeTypeForId!==i.domainId&&e.jsxs("div",{className:"mdocs-domain-action-buttons",children:[e.jsx("button",{type:"button",className:"secondary",title:d?t("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(i)},disabled:d,children:t("rename")}),e.jsx("button",{type:"button",className:"secondary",title:d?j:void 0,onClick:()=>{s.setRenamingId(null),s.setChangeTypeForId(i.domainId)},disabled:d,children:t("domainChangeType")}),e.jsx("button",{type:"button",className:"secondary",title:d?t("domainLocked"):void 0,onClick:()=>void s.handleDelete(i),disabled:d,children:t("deleteDomain")}),i.permission==="restricted"&&!f&&e.jsx("button",{type:"button",className:"secondary",onClick:()=>void C(i),children:t("domainMembersManageButton")})]})]})]},i.domainId)})})]})})]}),e.jsx(Se,{open:r!==null,title:t("domainMembersPickerTitle"),initialSelectedIds:(r==null?void 0:r.initialIds)??[],lockedIds:r?[r.creatorVisitorId]:[],seedMembers:r==null?void 0:r.memberRows,templates:k,onClose:()=>y(null),onConfirm:async i=>{r&&(await cs(r.domainId,i),M({kind:"ok",text:t("domainMembersSaved",{count:String(i.length)})}))}})]})}function ye(t){return t.length<=6?t:`${t.slice(0,6)}…`}function Os(){const{t}=Z(),s=a.useRef(!0),[k,h]=a.useState([]),[g,M]=a.useState(!0),[r,y]=a.useState(null),[b,C]=a.useState(1),[i,N]=a.useState(null),[f,d]=a.useState(""),[j,u]=a.useState([]),[z,T]=a.useState(!1),[R,I]=a.useState(null),[A,B]=a.useState(!1),E=ve(),[x,P]=a.useState([]),[v,S]=a.useState("idle"),[l,c]=a.useState("");a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{S("loading"),rs().then(o=>{s.current&&(P(o),S("ok"))}).catch(()=>{s.current&&S("err")})},[]);const m=a.useMemo(()=>{const o=new Map;for(const L of x)o.set(L.visitorId,L.visitorName);return o},[x]),w=a.useCallback(async()=>{M(!0),I(null);try{const o=await we();s.current&&h(o)}catch(o){s.current&&I(_(t,o))}finally{s.current&&M(!1)}},[t]);a.useEffect(()=>{w()},[w]);const F=a.useMemo(()=>j.map(o=>{const L=x.find(W=>W.visitorId===o);return{visitorId:o,name:L?L.visitorName:t("visitorPickerUnknownVisitor"),muted:!L}}),[j,x,t]);function K(o){u(L=>L.includes(o)?L.filter(W=>W!==o):[...L,o])}const H=b===1?f.trim().length>0:b===2?j.length>0:!0;function q(){if(!(b>=3)){if(!H){B(!0);return}B(!1),C(b+1),c("")}}function G(){b<=1||(B(!1),C(b-1))}function D(){y(null),N(null),d(""),u(E?[E]:[]),I(null),C(1),c(""),B(!1)}function p(o){y(null),N(o.id),d(o.displayName);const L=E&&!o.visitorIds.includes(E)?[...o.visitorIds,E]:[...o.visitorIds];u(L),I(null),C(1),c(""),B(!1)}async function V(){if(!(!f.trim()||j.length===0)){T(!0),I(null);try{if(i===null?await os({displayName:f.trim(),visitorIds:j}):await ds(i,{displayName:f.trim(),visitorIds:j}),!s.current)return;D(),await w()}catch(o){if(!s.current)return;I(_(t,o))}finally{s.current&&T(!1)}}}async function $(o){T(!0),I(null);try{if(await ms(o),!s.current)return;y(null),i===o&&D(),await w()}catch(L){if(!s.current)return;I(_(t,L))}finally{s.current&&T(!1)}}const Q=[{key:1,label:t("memberTemplateStepName")},{key:2,label:t("memberTemplateStepMembers")},{key:3,label:t("memberTemplateStepSave")}],ee=`${(b-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(i!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),i!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:D,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:Q.map(o=>{const L=b===o.key,W=b>o.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${L?" current":""}${W?" done":""}`,children:W?"✓":o.key}),e.jsx("span",{className:`mdocs-wizard-step-label${L?" current":""}${W?" done":""}`,children:o.label})]},o.key)})})]}),R&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:R}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[b===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:f,onChange:o=>d(o.target.value),placeholder:t("memberTemplateNamePlaceholder"),maxLength:200,disabled:z,autoFocus:!0,"aria-invalid":A&&!f.trim()}),A&&!f.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:t("domainNameRequired")})]}),b===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(Ms,{visitors:x,loadState:v,searchFilter:l,onSearchChange:c,selectedIds:new Set(j),onToggle:K,selectedRows:F,myVisitorId:E}),e.jsx("p",{className:`mdocs-wizard-hint${A&&j.length===0?" danger":""}`,children:"💡 "+t("memberTemplateStep2Hint")})]}),b===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:f})]}),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(j.length)})})]}),j.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[j.slice(0,15).map(o=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:ye(o)},o)),j.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",j.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:G,children:["← ",t("memberTemplateWizardBack")]}),b<3?e.jsxs("button",{type:"button",className:"primary",onClick:q,children:[t("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void V(),children:t(z?"saving":i===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("memberTemplateSavedList")}),g?e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")}):k.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateEmpty")}),i===null&&e.jsx("button",{type:"button",className:"primary",onClick:D,children:t("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:k.map(o=>e.jsx("li",{className:"mdocs-member-template-row",children:r===o.id?e.jsxs("div",{className:"mdocs-member-template-confirm-row",children:[e.jsx("span",{className:"mdocs-member-template-confirm-text",children:t("memberTemplateConfirmDeleteDesc",{name:o.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 $(o.id),children:t(z?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>y(null),children:t("memberTemplateConfirmDeleteCancel")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-member-template-row-head",children:[e.jsx("strong",{children:o.displayName}),e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateCount",{count:String(o.visitorIds.length)})}),o.visitorIds.length>0&&e.jsx("div",{className:"mdocs-member-template-tags mdocs-member-template-tags-scroll",children:o.visitorIds.map(L=>e.jsx("span",{className:"mdocs-member-template-tag",children:m.get(L)??ye(L)},L))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>p(o),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>y(o.id),children:t("memberTemplateDelete")})]})]})},o.id))})]})]})]})}const Vs=[{value:"deepseek-v4-flash",label:"deepseek-v4-flash"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro"}];function Ks(){const{t}=Z(),s=a.useRef(!0),[k,h]=a.useState(""),[g,M]=a.useState(null),[r,y]=a.useState(""),[b,C]=a.useState("deepseek-v4-flash"),[i,N]=a.useState(128e3),[f,d]=a.useState(""),[j,u]=a.useState(!1),[z,T]=a.useState(null),[R,I]=a.useState(!0),[A,B]=a.useState(!1),[E,x]=a.useState(null),[P,v]=a.useState(!1),[S,l]=a.useState(!1),[c,m]=a.useState(!1),[w,F]=a.useState(null);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{(async()=>{try{const[D,p]=await Promise.all([us(),hs()]);if(!s.current)return;h(D.visitorName),p?(M(p.id),y(p.name),C(p.modelId),N(p.contextWindow||128e3),u(p.hasApiKey),T(p.apiKeyMasked),l(!1)):l(!0)}catch(D){if(!s.current)return;x(D instanceof Error?D.message:String(D)),l(!0)}finally{s.current&&I(!1)}})()},[]);function K(){F({name:r,modelId:b,contextWindow:i}),d(""),m(!1),v(!1),x(null),l(!0)}function H(){w&&(y(w.name),C(w.modelId),N(w.contextWindow)),d(""),m(!1),x(null),v(!1),l(!1),F(null)}async function q(){B(!0),x(null),v(!1);try{const D={modelId:b,name:r,contextWindow:i};f.trim()&&(D.apiKey=f.trim());const p=await ps(D);if(!s.current)return;M(p.id),y(p.name),C(p.modelId),N(p.contextWindow||128e3),u(p.hasApiKey),T(p.apiKeyMasked),d(""),m(!1),v(!0),l(!1),F(null)}catch(D){if(!s.current)return;x(D instanceof Error?D.message:String(D))}finally{s.current&&B(!1)}}const G=t("agentConfigNameDefault").replace("{{name}}",k||"…");return e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title mdocs-agent-config-title",children:[e.jsx("img",{src:gs,alt:"DeepSeek",className:"mdocs-agent-config-logo"}),t("agentConfig")]}),!R&&g&&!S?e.jsx("button",{type:"button",className:"secondary",onClick:K,children:t("edit")}):null]}),e.jsx("div",{className:"mdocs-settings-cards",children:e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:t("agentConfigDesc")}),R?e.jsx("p",{children:t("loading")}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-settings-item",style:{display:"block",marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigName")}),e.jsx("input",{type:"text",value:r,onChange:D=>y(D.target.value),placeholder:G,disabled:!S,style:{width:"100%",marginTop:6}})]}),e.jsxs("div",{className:"mdocs-settings-item mdocs-agent-config-field",style:{marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigModel")}),S?e.jsx("div",{className:"mdocs-agent-config-select",children:e.jsx(Ls,{options:Vs,value:b,onChange:D=>C(D)})}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:b})]}),e.jsxs("label",{className:"mdocs-settings-item",style:{display:"block",marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigContextWindow")}),e.jsx("p",{className:"mdocs-settings-item-desc",style:{margin:"4px 0 6px"},children:t("agentConfigContextWindowDesc")}),S?e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:i,onChange:D=>N(Number(D.target.value)||128e3),style:{width:"100%"}}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:i})]}),e.jsxs("div",{className:"mdocs-settings-item mdocs-agent-config-field",style:{marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigApiKey")}),S?e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:c?"text":"password",value:f,onChange:D=>d(D.target.value),placeholder:j?t("agentConfigApiKeyConfigured").replace("{{masked}}",z??"…"):t("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(c?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>m(D=>!D),children:c?e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[e.jsx("path",{d:"M3 3l18 18"}),e.jsx("path",{d:"M10.6 10.6a2 2 0 002.8 2.8"}),e.jsx("path",{d:"M9.9 5.1A10.5 10.5 0 0121 12c-.6 1.1-1.4 2.1-2.4 2.9"}),e.jsx("path",{d:"M6.1 6.1C4.5 7.4 3.2 9.1 2.5 12c1.5 3.5 5 7 9.5 7 1.4 0 2.7-.3 3.9-.8"})]}):e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[e.jsx("path",{d:"M2.5 12C4 8.5 7.5 5 12 5s8 3.5 9.5 7c-1.5 3.5-5 7-9.5 7s-8-3.5-9.5-7z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:j?z??"…":t("agentConfigApiKeyPlaceholder")})]}),g?e.jsxs("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:[t("agentConfigId"),": ",g]}):null,E?e.jsx("p",{style:{color:"var(--mdocs-danger, #c00)",marginBottom:12},children:E}):null,P&&!S?e.jsx("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:t("saved")}):null,S?e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void q(),disabled:A,children:t(A?"saving":"save")}),g?e.jsx("button",{type:"button",className:"secondary",onClick:H,disabled:A,children:t("cancel")}):null]}):null]})]})})]})}const $s=/^[A-Za-z0-9_]+$/;function ie(t){return $s.test(t.trim())}function Ws(){const t=a.useRef(!0),[s,k]=a.useState([]),[h,g]=a.useState(!0),[M,r]=a.useState(null),[y,b]=a.useState(null),[C,i]=a.useState(!1),[N,f]=a.useState(""),[d,j]=a.useState(""),[u,z]=a.useState(""),[T,R]=a.useState(!1);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]);async function I(){g(!0),r(null);try{const l=await fs();if(!t.current)return;k(l)}catch(l){if(!t.current)return;r(l instanceof Error?l.message:String(l))}finally{t.current&&g(!1)}}a.useEffect(()=>{I()},[]);function A(){i(!0),b(null),f(""),j(""),z(""),r(null)}function B(l){i(!1),b(l.id),f(l.name),j(l.description),z(l.body),r(null)}function E(){i(!1),b(null),f(""),j(""),z("")}async function x(){const l=N.trim();if(!ie(l)){r("名称仅允许英文、数字、下划线");return}if(!u.trim()){r("正文不能为空");return}R(!0),r(null);try{if(C?await xs({name:l,description:d,body:u}):y&&await js(y,{name:l,description:d,body:u}),!t.current)return;E(),await I()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}finally{t.current&&R(!1)}}async function P(l){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){r(null);try{if(await Ns(l),!t.current)return;y===l&&E(),await I()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}}}const v=C||y!==null,S=!N.trim()||ie(N);return e.jsxs("div",{className:"mdocs-settings mdocs-agent-skills-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title",children:["Agent Skills",!h&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),v?null:e.jsx("button",{type:"button",className:"secondary",onClick:A,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:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),M?e.jsx("p",{className:"mdocs-agent-skills-error",children:M}):null,v?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:C?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:N,onChange:l=>f(l.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:S?void 0:"mdocs-agent-skills-input-invalid"}),S?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:d,onChange:l=>j(l.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:u,onChange:l=>z(l.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void x(),disabled:T||!S||!N.trim()||!u.trim(),children:T?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:E,disabled:T,children:"取消"})]})]}):null,h?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!h&&s.length===0&&!v?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:A,children:"新建第一个"})]}):null,!h&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(l=>{const c=ie(l.name),m=y===l.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(m?" 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:l.name}),c?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:l.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>B(l),disabled:v&&!m,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void P(l.id),disabled:v,children:"删除"})]})]},l.id)})}):null]})})]})}function be(t,s){const k=localStorage.getItem(t);return k===null?s:k==="true"}function Zs(t){const{t:s,lang:k,setLang:h}=Z(),{onBack:g,onPublishDraft:M}=t,r=a.useRef(!0);a.useEffect(()=>(r.current=!0,()=>{r.current=!1}),[]);const[y,b]=a.useState(()=>be("mdocs.autoPublish",!1)),[C,i]=a.useState(()=>be("mdocs.autoEdit",!0)),[N,f]=a.useState(!1),[d,j]=a.useState("general"),[u,z]=a.useState([]),[T,R]=a.useState(!0),[I,A]=a.useState(null),[B,E]=a.useState(!1),[x,P]=a.useState(!1),[v,S]=a.useState(!1),[l,c]=a.useState(!1),[m,w]=a.useState(null),[F,K]=a.useState(!1),[H,q]=a.useState(!1),[G,D]=a.useState(!1),[p,V]=a.useState(""),[$,Q]=a.useState(!1),[ee,o]=a.useState(!1),[L,W]=a.useState(0),[Ce,re]=a.useState([]),[De,oe]=a.useState(!1),[X,Ie]=a.useState(""),[Te,Ae]=a.useState([]),[Ee,de]=a.useState(!1),[Y,Pe]=a.useState(""),[Me,Le]=a.useState([]),[Re,se]=a.useState(!1),[te,me]=a.useState(null),[ae,ue]=a.useState(new Map);a.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(y))},[y]),a.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(C))},[C]),a.useEffect(()=>{d==="savePublish"&&le().then(n=>{r.current&&W(n.filter(O=>!O.published).length)})},[d]),a.useEffect(()=>{d==="bookmarks"&&ze(),d==="myDocuments"&&pe()},[d]),a.useEffect(()=>{ge()},[]),a.useEffect(()=>{ke().then(n=>{r.current&&Le(n)}).catch(()=>{})},[]);const he=new Map(Me.map(n=>[n.domainId,n.domainName]));async function ge(){try{R(!0);const n=await ys();if(!r.current)return;z(n)}catch{}finally{r.current&&R(!1)}}async function ze(){try{oe(!0);const n=await bs();if(!r.current)return;re(n)}catch{}finally{r.current&&oe(!1)}}async function pe(){try{de(!0);const n=await vs();if(!r.current)return;Ae(n)}catch{}finally{r.current&&de(!1)}}async function Be(n){try{await Is(n),re(O=>O.filter(J=>J.documentId!==n))}catch{}}function Fe(){if(u.some(O=>!O.revoked)){P(!0);return}fe()}async function fe(){try{E(!0);const n=await As();A({token:n.token,name:n.name}),await ge()}finally{E(!1)}}async function Oe(){try{D(!0);const n=await Cs();w(n.recoveryCode)}finally{D(!1)}}async function Ve(n){n.preventDefault();const O=p.trim();if(!(O&&O.length<4))try{Q(!0),await Ds(O),V(""),o(!0),setTimeout(()=>o(!1),3e3)}finally{Q(!1)}}async function Ke(n){me(n);try{const O=await Ts(n),J=new Map;O.forEach(U=>{J.set(U.visitorId,U.permission)}),ue(J)}catch{ue(new Map)}se(!0)}async function $e(n){if(te)try{const O=new Set(n.map(U=>U.visitorId)),J=new Set(ae.keys());for(const U of J)O.has(U)||await Es(te,U);for(const U of n)await Ps(te,U.visitorId,U.permission);await pe()}finally{se(!1),me(null)}}const xe=Ce.filter(n=>{if(!X.trim())return!0;const O=X.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(O)||(n.ownerVisitorName||"").toLowerCase().includes(O)||(n.domainId||"").toLowerCase().includes(O)}),je=Te.filter(n=>{if(!Y.trim())return!0;const O=Y.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(O)||(n.domainId||"").toLowerCase().includes(O)});return e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"mdocs-sidebar",children:[e.jsx("header",{className:"mdocs-sidebar-header",children:e.jsxs("div",{className:"mdocs-brand",children:[e.jsx("img",{src:ks,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]})}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(d==="general"?" active":""),onClick:()=>j("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(d==="bookmarks"?" active":""),onClick:()=>j("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(d==="myDocuments"?" active":""),onClick:()=>j("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(d==="domainManagement"?" active":""),onClick:()=>j("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(d==="memberTemplates"?" active":""),onClick:()=>j("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(d==="agentConfig"?" active":""),onClick:()=>j("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(d==="savePublish"?" active":""),onClick:()=>j("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:g,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[ws(),d==="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:k==="en"?"active":"",onClick:()=>h("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:k==="zh"?"active":"",onClick:()=>h("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"+(C?" active":""),role:"switch","aria-checked":C,onClick:()=>i(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")}),!T&&u.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:u.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:Fe,disabled:B||T,children:B?"…":u.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),I&&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:I.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(I.token),c(!1),S(!0),window.setTimeout(()=>S(!1),2e3)}catch{S(!1),c(!0),window.setTimeout(()=>c(!1),3e3)}})()},children:s(v?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>A(null),children:s("close")})]}),v&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),l&&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:Oe,disabled:G,children:G?"…":"生成恢复码"})]}),m&&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:m})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(m),q(!1),K(!0),window.setTimeout(()=>K(!1),2e3)}catch{K(!1),q(!0),window.setTimeout(()=>q(!1),3e3)}})()},children:F?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>w(null),children:s("close")})]}),F&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),H&&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:Ve,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:p,onChange:n=>V(n.target.value),minLength:0,style:{marginBottom:8}}),ee&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:$,children:$?"设置中…":"保存密码"})]})]})]})]}):d==="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:X,onChange:n=>Ie(n.target.value)}),De?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:xe.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(X?"bookmarkNoMatch":"bookmarkEmpty")}):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:xe.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:"已删除"}):he.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:()=>Be(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})]})]}):d==="myDocuments"?e.jsxs("div",{className:"mdocs-settings",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.jsx("input",{type:"text",className:"mdocs-settings-search",placeholder:"搜索文章…",value:Y,onChange:n=>Pe(n.target.value)}),Ee?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:je.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(Y?"myDocumentsNoMatch":"myDocumentsEmpty")}):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("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{colSpan:2})]})}),e.jsx("tbody",{children:je.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:he.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:new Date(n.updatedAt).toLocaleDateString()}),e.jsx("td",{children:new Date(n.createdAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>Ke(n.documentId),children:s("docInfoInviteMember")})}),e.jsx("td",{style:{textAlign:"right",paddingLeft:0},children:e.jsx("button",{type:"button",className:"primary small",onClick:()=>t.onOpenDocument(n.documentId),children:s("bookmarkOpen")})})]},n.documentId))})]})})]})]}):d==="domainManagement"?e.jsx(Fs,{}):d==="memberTemplates"?e.jsx(Os,{}):d==="agentConfig"?e.jsxs(e.Fragment,{children:[e.jsx(Ks,{}),e.jsx(Ws,{})]}):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:g,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"+(y?" active":""),role:"switch","aria-checked":y,onClick:()=>b(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),L>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>f(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",L,")"]}),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")})})]})]}),N&&e.jsx(zs,{onPublish:M,onClose:()=>f(!1),onCountChange:W,onRecover:t.onRecoverDraft})]}),x&&e.jsx(Ss,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:B,onConfirm:()=>{P(!1),fe()},onCancel:()=>P(!1)}),e.jsx(Se,{open:Re,title:s("docInfoInviteMember"),initialSelectedIds:[...ae.keys()],initialPermissions:ae,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>se(!1),onConfirm:n=>{$e(n)}})]})}export{Zs as SettingsPage};
|
|
1
|
+
import{r as a,j as e}from"./react-vendor-BNpqFP9B.js";import{b as Z,q as We,s as Ue,D as _e,l as ce,t as He,v as qe,w as _,x as le,y as Ge,z as Ze,A as Je,a as Qe,d as Ne,B as ve,C as ke,E as Xe,G as Ye,H as es,I as ss,J as ts,K as we,L as ne,N as as,O as ns,P as is,Q as cs,R as ls,f as rs,T as os,U as ds,V as ms,W as us,X as hs,i as gs,Y as ps,Z as fs,_ as xs,$ as js,a0 as Ns,a1 as ys,a2 as bs,a3 as vs,a4 as ks,a5 as ws,a6 as Ss,a7 as Cs,a8 as Ds,r as Is,j as Ts,a9 as As,n as Es,o as Ps}from"./index-B-XJ-ScV.js";import{V as Se,a as Ms,M as Ls}from"./VisitorPickerModal-COxtOvc4.js";import"./ui-C3xtW1w8.js";import"./motion-D-I76zAi.js";function Rs({draft:t,onClose:s,onSuccess:k}){const{t:h,lang:g}=Z(),[M,r]=a.useState([]),[y,b]=a.useState(t.domainId??""),[C,i]=a.useState([]),[N,f]=a.useState(""),[d,j]=a.useState(`${t.displayName||"untitled"}_recovered.md`),[u,z]=a.useState(!1),[T,R]=a.useState(null),I=a.useRef(null),A=a.useRef(!0);a.useEffect(()=>(A.current=!0,()=>{A.current=!1}),[]),a.useEffect(()=>{We().then(x=>{A.current&&r(x)})},[]),a.useEffect(()=>{y&&(i([]),f(""),Ue(y).then(x=>{A.current&&i(x)}).catch(()=>{A.current&&i([])}))},[y]),a.useEffect(()=>{const x=window.setTimeout(()=>{var P;return(P=I.current)==null?void 0:P.focus()},0);return()=>window.clearTimeout(x)},[]),a.useEffect(()=>{const x=P=>{P.key==="Escape"&&s()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[s]);function B(x,P){for(const v of x){if(v.type==="folder"&&v.path===P)return v.documentId;if(v.type==="folder"){const S=B(v.children,P);if(S)return S}}return null}async function E(x){x.preventDefault(),z(!0),R(null);const P=d.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),v=P.endsWith(".md")?P:P+".md",S=v.replace(/\.md$/i,"");try{const l=N?`${N}/${v}`:v,c=N?B(C,N)??void 0:void 0;await qe({fileName:v,displayName:S,content:t.content,domainId:y,parentId:c}),k()}catch(l){R(_(h,l))}finally{z(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:x=>{x.target===x.currentTarget&&!u&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:h("recoverDraft")}),e.jsx("p",{className:"muted",children:h("recoverDraftDesc",{name:t.displayName||h("unknownTitle")})}),e.jsxs("form",{onSubmit:E,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[h("domainLabel"),M.length>0&&e.jsx(_e,{domains:M,value:y,onChange:b,onDomainsChange:r,ariaLabel:h("domainLabel"),localizeName:x=>ce(x,g,h)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[h("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(He,{nodes:C,activeDocumentId:null,selectedParentPath:N,onOpen:()=>{},onOpenFolder:x=>f(x),onContextMenu:()=>{},onDeselect:()=>f("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[h("fileNameLabel"),e.jsx("input",{ref:I,value:d,onChange:x=>j(x.target.value),placeholder:"recovered.md",maxLength:200,disabled:u})]}),T&&e.jsx("div",{className:"mdocs-dialog-error",children:T}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!u&&s(),disabled:u,children:h("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:u,children:h(u?"creating":"create")})]})]})]})})}function zs({onPublish:t,onClose:s,onCountChange:k,onRecover:h}){const{t:g}=Z(),[M,r]=a.useState([]),[y,b]=a.useState(new Set),[C,i]=a.useState(!1),[N,f]=a.useState(null),[d,j]=a.useState(null),[u,z]=a.useState(null),T=a.useRef(null),R=a.useRef(!0);a.useEffect(()=>(R.current=!0,le().then(c=>{if(!R.current)return;const m=c.filter(w=>!w.published);r(m),k==null||k(m.length)}),()=>{R.current=!1,T.current&&(clearTimeout(T.current),T.current=null)}),[]),a.useEffect(()=>{const c=m=>{m.key==="Escape"&&s()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[s]);const I=a.useCallback((c,m)=>{z({message:c,type:m}),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>z(null),3e3)},[]);async function A(c){await Ze(c),b(m=>new Set(m).add(c));try{await t(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),I(g("published"),"success")}catch(m){m instanceof Je||I(g("publishFailed"),"error");const w=await Qe(c);w&&r(F=>F.map(K=>K.documentId===c?w:K))}finally{b(m=>{const w=new Set(m);return w.delete(c),w})}}async function B(c){f(null),await Ne(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),I(g("draftDeleted"),"success")}function E(c){const m=M.find(w=>w.documentId===c);m&&j(m)}function x(c){j(null),Ne(c),r(m=>{const w=m.filter(F=>F.documentId!==c);return k==null||k(w.length),w}),h==null||h(M.find(m=>m.documentId===c)),I(g("published"),"success")}async function P(){i(!0);let c=0,m=0;for(const K of M)try{await t(K.documentId),c++}catch{m++}const F=(await le()).filter(K=>!K.published);r(F),k==null||k(F.length),m===0?I(g("publishAll"),"success"):I(`${c} published, ${m} failed`,"error"),i(!1)}const v=c=>new Date(c).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),S=c=>Ge(g,c,c.publishError??"UNKNOWN"),l=M;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:[g("unpublishedDrafts"),l.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:l.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:g("draftCount",{count:String(l.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":g("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:l.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:g("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:l.map(c=>{const m=!!c.publishError;return e.jsxs("div",{className:m?"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:c.displayName||g("unknownTitle")}),m?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[v(c.publishErrorAt)," · ",S(c)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[v(c.updatedAt)," · ",g("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[m?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:C,onClick:()=>E(c.documentId),children:g("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:y.has(c.documentId)||C,onClick:()=>void A(c.documentId),children:y.has(c.documentId)?g("publishing"):g("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:C,onClick:()=>f(c.documentId),children:g("delete")})]})]},c.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:g("close")}),e.jsx("button",{type:"button",className:"primary",disabled:l.length===0||C,onClick:()=>void P(),children:C?g("publishing"):`${g("publishAll")} (${l.length})`})]}),u&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+u.type,role:"status",children:u.message})]}),N&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:c=>{c.target===c.currentTarget&&f(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:g("delete")}),e.jsx("p",{className:"muted",children:g("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>f(null),children:g("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void B(N),children:g("delete")})]})]})}),d&&e.jsx(Rs,{draft:d,onClose:()=>j(null),onSuccess:()=>x(d.documentId)})]})}function Bs(){const{t,lang:s}=Z(),k=ve(),h=a.useRef(!1),[g,M]=a.useState([]),[r,y]=a.useState(!1),[b,C]=a.useState(""),[i,N]=a.useState("restricted"),[f,d]=a.useState(!1),[j,u]=a.useState(null),[z,T]=a.useState(null),[R,I]=a.useState(""),[A,B]=a.useState(""),[E,x]=a.useState("all"),[P,v]=a.useState(null);a.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]);const S=a.useCallback(async()=>{y(!0),u(null);try{const p=await ke();if(!h.current)return;M(p)}catch(p){if(!h.current)return;u(_(t,p))}finally{h.current&&y(!1)}},[t]);a.useEffect(()=>{S()},[S]);async function l(p){if(p.preventDefault(),!b.trim()){u(t("domainNameRequired"));return}d(!0),u(null);try{if(await ts({domainName:b.trim(),permission:i}),!h.current)return;C(""),N("restricted"),await S()}catch(V){if(!h.current)return;u(_(t,V))}finally{h.current&&d(!1)}}async function c(p){if(R.trim()){u(null);try{if(await ss(p,R.trim()),!h.current)return;T(null),v(null),await S()}catch(V){if(!h.current)return;u(_(t,V))}}}function m(p){T(p.domainId),I(p.domainName),v(null)}function w(){T(null),v(null)}async function F(p,V){u(null);try{if(await es(p,V),!h.current)return;v(null),await S()}catch($){if(!h.current)return;u(_(t,$))}}async function K(p){if(window.confirm(t("deleteDomainConfirmDetail",{name:p.domainName,count:String(p.docCount)}))){u(null);try{if(await Ye(p.domainId),!h.current)return;await S()}catch(V){if(!h.current)return;u(_(t,V))}}}const H=a.useCallback(p=>Xe(p,t),[t]),q=a.useCallback(p=>ce(p.domainName,s,t),[s,t]),G=a.useMemo(()=>{const p=A.trim().toLowerCase();return g.filter(V=>E!=="all"&&V.permission!==E?!1:p?ce(V.domainName,s,t).toLowerCase().includes(p)||V.domainName.toLowerCase().includes(p):!0)},[g,A,E,s,t]),D=a.useCallback((p,V)=>{const $=H(p.permission);return V?`${$} ${t("domainTypeBuiltinSuffix")}`:$},[H,t]);return{domains:g,loadingDomains:r,domainError:j,newDomainName:b,setNewDomainName:C,newDomainPermission:i,setNewDomainPermission:N,creating:f,handleCreateDomain:l,renamingId:z,setRenamingId:T,renameDraft:R,setRenameDraft:I,startRename:m,cancelRename:w,handleRename:c,changeTypeForId:P,setChangeTypeForId:v,handlePermissionChange:F,handleDelete:K,domainSearch:A,setDomainSearch:B,domainFilter:E,setDomainFilter:x,filteredDomains:G,visitorId:k,plabel:H,localizeDomain:q,domainTypeLabel:D}}function Fs(){const{t}=Z(),s=Bs(),[k,h]=a.useState([]),[g,M]=a.useState(null),[r,y]=a.useState(null),b=a.useCallback(async()=>{try{const i=await we();h(i)}catch{h([])}},[]);a.useEffect(()=>{b()},[b]);async function C(i){M(null);try{const N=await ls(i.domainId);y({domainId:i.domainId,creatorVisitorId:i.creatorVisitorId,initialIds:N.map(f=>f.visitorId),memberRows:N})}catch(N){M({kind:"err",text:_(t,N)})}}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:i=>s.setNewDomainName(i.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:ne.map(i=>e.jsxs("label",{className:"mdocs-domain-mgmt-radio",children:[e.jsx("input",{type:"radio",name:"newDomainPermission",checked:s.newDomainPermission===i,onChange:()=>s.setNewDomainPermission(i),disabled:s.creating}),e.jsx("span",{children:s.plabel(i)})]},i))})]}),e.jsx("button",{type:"submit",className:"primary mdocs-domain-mgmt-submit",disabled:s.creating,children:s.creating?t("creating"):t("create")})]})]}),g&&e.jsx("div",{className:"mdocs-settings-card",style:{color:g.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:g.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:i=>s.setDomainSearch(i.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",...ne].map(i=>e.jsx("button",{type:"button",className:"mdocs-domain-mgmt-filter"+(s.domainFilter===i?" active":""),"aria-pressed":s.domainFilter===i,onClick:()=>s.setDomainFilter(i),children:i==="all"?t("domainFilterAll"):s.plabel(i)},i))})]}),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(i=>{const N=as(i,s.visitorId),f=ns(i.domainId),d=is(i),j=d?t("domainTooltipTypeLocked",{count:String(i.docCount)}):void 0;return e.jsxs("tr",{className:f?"mdocs-domain-table-row-builtin":void 0,children:[e.jsx("td",{children:s.renamingId===i.domainId?e.jsxs("div",{className:"mdocs-domain-table-rename",children:[e.jsx("input",{value:s.renameDraft,onChange:u=>s.setRenameDraft(u.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(i.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(i)}),f&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:t("domainBuiltIn")}),!N&&!f&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:t("shared")})]})}),e.jsx("td",{children:e.jsxs("span",{className:"mdocs-domain-table-type",title:j,children:[e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":i.permission,children:s.domainTypeLabel(i,f)}),d&&!f&&e.jsx("span",{className:"mdocs-domain-type-lock","aria-hidden":"true",children:"🔒"})]})}),e.jsx("td",{className:"mdocs-domain-table-num",children:i.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[f&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:t("domainNotModifiable")}),!f&&!N&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:t("domainNotCreator")}),!f&&N&&s.changeTypeForId===i.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",children:[e.jsx("div",{className:"mdocs-domain-permission-select",children:ne.map(u=>e.jsx("button",{type:"button",className:i.permission===u?"active":"",onClick:()=>void s.handlePermissionChange(i.domainId,u),children:s.plabel(u)},u))}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>s.setChangeTypeForId(null),children:t("cancel")})]}),!f&&N&&s.renamingId!==i.domainId&&s.changeTypeForId!==i.domainId&&e.jsxs("div",{className:"mdocs-domain-action-buttons",children:[e.jsx("button",{type:"button",className:"secondary",title:d?t("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(i)},disabled:d,children:t("rename")}),e.jsx("button",{type:"button",className:"secondary",title:d?j:void 0,onClick:()=>{s.setRenamingId(null),s.setChangeTypeForId(i.domainId)},disabled:d,children:t("domainChangeType")}),e.jsx("button",{type:"button",className:"secondary",title:d?t("domainLocked"):void 0,onClick:()=>void s.handleDelete(i),disabled:d,children:t("deleteDomain")}),i.permission==="restricted"&&!f&&e.jsx("button",{type:"button",className:"secondary",onClick:()=>void C(i),children:t("domainMembersManageButton")})]})]})]},i.domainId)})})]})})]}),e.jsx(Se,{open:r!==null,title:t("domainMembersPickerTitle"),initialSelectedIds:(r==null?void 0:r.initialIds)??[],lockedIds:r?[r.creatorVisitorId]:[],seedMembers:r==null?void 0:r.memberRows,templates:k,onClose:()=>y(null),onConfirm:async i=>{r&&(await cs(r.domainId,i),M({kind:"ok",text:t("domainMembersSaved",{count:String(i.length)})}))}})]})}function ye(t){return t.length<=6?t:`${t.slice(0,6)}…`}function Os(){const{t}=Z(),s=a.useRef(!0),[k,h]=a.useState([]),[g,M]=a.useState(!0),[r,y]=a.useState(null),[b,C]=a.useState(1),[i,N]=a.useState(null),[f,d]=a.useState(""),[j,u]=a.useState([]),[z,T]=a.useState(!1),[R,I]=a.useState(null),[A,B]=a.useState(!1),E=ve(),[x,P]=a.useState([]),[v,S]=a.useState("idle"),[l,c]=a.useState("");a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{S("loading"),rs().then(o=>{s.current&&(P(o),S("ok"))}).catch(()=>{s.current&&S("err")})},[]);const m=a.useMemo(()=>{const o=new Map;for(const L of x)o.set(L.visitorId,L.visitorName);return o},[x]),w=a.useCallback(async()=>{M(!0),I(null);try{const o=await we();s.current&&h(o)}catch(o){s.current&&I(_(t,o))}finally{s.current&&M(!1)}},[t]);a.useEffect(()=>{w()},[w]);const F=a.useMemo(()=>j.map(o=>{const L=x.find(W=>W.visitorId===o);return{visitorId:o,name:L?L.visitorName:t("visitorPickerUnknownVisitor"),muted:!L}}),[j,x,t]);function K(o){u(L=>L.includes(o)?L.filter(W=>W!==o):[...L,o])}const H=b===1?f.trim().length>0:b===2?j.length>0:!0;function q(){if(!(b>=3)){if(!H){B(!0);return}B(!1),C(b+1),c("")}}function G(){b<=1||(B(!1),C(b-1))}function D(){y(null),N(null),d(""),u(E?[E]:[]),I(null),C(1),c(""),B(!1)}function p(o){y(null),N(o.id),d(o.displayName);const L=E&&!o.visitorIds.includes(E)?[...o.visitorIds,E]:[...o.visitorIds];u(L),I(null),C(1),c(""),B(!1)}async function V(){if(!(!f.trim()||j.length===0)){T(!0),I(null);try{if(i===null?await os({displayName:f.trim(),visitorIds:j}):await ds(i,{displayName:f.trim(),visitorIds:j}),!s.current)return;D(),await w()}catch(o){if(!s.current)return;I(_(t,o))}finally{s.current&&T(!1)}}}async function $(o){T(!0),I(null);try{if(await ms(o),!s.current)return;y(null),i===o&&D(),await w()}catch(L){if(!s.current)return;I(_(t,L))}finally{s.current&&T(!1)}}const Q=[{key:1,label:t("memberTemplateStepName")},{key:2,label:t("memberTemplateStepMembers")},{key:3,label:t("memberTemplateStepSave")}],ee=`${(b-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(i!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),i!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:D,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:Q.map(o=>{const L=b===o.key,W=b>o.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${L?" current":""}${W?" done":""}`,children:W?"✓":o.key}),e.jsx("span",{className:`mdocs-wizard-step-label${L?" current":""}${W?" done":""}`,children:o.label})]},o.key)})})]}),R&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:R}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[b===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:f,onChange:o=>d(o.target.value),placeholder:t("memberTemplateNamePlaceholder"),maxLength:200,disabled:z,autoFocus:!0,"aria-invalid":A&&!f.trim()}),A&&!f.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:t("domainNameRequired")})]}),b===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(Ms,{visitors:x,loadState:v,searchFilter:l,onSearchChange:c,selectedIds:new Set(j),onToggle:K,selectedRows:F,myVisitorId:E}),e.jsx("p",{className:`mdocs-wizard-hint${A&&j.length===0?" danger":""}`,children:"💡 "+t("memberTemplateStep2Hint")})]}),b===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:f})]}),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(j.length)})})]}),j.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[j.slice(0,15).map(o=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:ye(o)},o)),j.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",j.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:G,children:["← ",t("memberTemplateWizardBack")]}),b<3?e.jsxs("button",{type:"button",className:"primary",onClick:q,children:[t("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void V(),children:t(z?"saving":i===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("memberTemplateSavedList")}),g?e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")}):k.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateEmpty")}),i===null&&e.jsx("button",{type:"button",className:"primary",onClick:D,children:t("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:k.map(o=>e.jsx("li",{className:"mdocs-member-template-row",children:r===o.id?e.jsxs("div",{className:"mdocs-member-template-confirm-row",children:[e.jsx("span",{className:"mdocs-member-template-confirm-text",children:t("memberTemplateConfirmDeleteDesc",{name:o.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 $(o.id),children:t(z?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>y(null),children:t("memberTemplateConfirmDeleteCancel")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-member-template-row-head",children:[e.jsx("strong",{children:o.displayName}),e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateCount",{count:String(o.visitorIds.length)})}),o.visitorIds.length>0&&e.jsx("div",{className:"mdocs-member-template-tags mdocs-member-template-tags-scroll",children:o.visitorIds.map(L=>e.jsx("span",{className:"mdocs-member-template-tag",children:m.get(L)??ye(L)},L))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>p(o),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>y(o.id),children:t("memberTemplateDelete")})]})]})},o.id))})]})]})]})}const Vs=[{value:"deepseek-v4-flash",label:"deepseek-v4-flash"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro"}];function Ks(){const{t}=Z(),s=a.useRef(!0),[k,h]=a.useState(""),[g,M]=a.useState(null),[r,y]=a.useState(""),[b,C]=a.useState("deepseek-v4-flash"),[i,N]=a.useState(128e3),[f,d]=a.useState(""),[j,u]=a.useState(!1),[z,T]=a.useState(null),[R,I]=a.useState(!0),[A,B]=a.useState(!1),[E,x]=a.useState(null),[P,v]=a.useState(!1),[S,l]=a.useState(!1),[c,m]=a.useState(!1),[w,F]=a.useState(null);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{(async()=>{try{const[D,p]=await Promise.all([us(),hs()]);if(!s.current)return;h(D.visitorName),p?(M(p.id),y(p.name),C(p.modelId),N(p.contextWindow||128e3),u(p.hasApiKey),T(p.apiKeyMasked),l(!1)):l(!0)}catch(D){if(!s.current)return;x(D instanceof Error?D.message:String(D)),l(!0)}finally{s.current&&I(!1)}})()},[]);function K(){F({name:r,modelId:b,contextWindow:i}),d(""),m(!1),v(!1),x(null),l(!0)}function H(){w&&(y(w.name),C(w.modelId),N(w.contextWindow)),d(""),m(!1),x(null),v(!1),l(!1),F(null)}async function q(){B(!0),x(null),v(!1);try{const D={modelId:b,name:r,contextWindow:i};f.trim()&&(D.apiKey=f.trim());const p=await ps(D);if(!s.current)return;M(p.id),y(p.name),C(p.modelId),N(p.contextWindow||128e3),u(p.hasApiKey),T(p.apiKeyMasked),d(""),m(!1),v(!0),l(!1),F(null)}catch(D){if(!s.current)return;x(D instanceof Error?D.message:String(D))}finally{s.current&&B(!1)}}const G=t("agentConfigNameDefault").replace("{{name}}",k||"…");return e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title mdocs-agent-config-title",children:[e.jsx("img",{src:gs,alt:"DeepSeek",className:"mdocs-agent-config-logo"}),t("agentConfig")]}),!R&&g&&!S?e.jsx("button",{type:"button",className:"secondary",onClick:K,children:t("edit")}):null]}),e.jsx("div",{className:"mdocs-settings-cards",children:e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:t("agentConfigDesc")}),R?e.jsx("p",{children:t("loading")}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-settings-item",style:{display:"block",marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigName")}),e.jsx("input",{type:"text",value:r,onChange:D=>y(D.target.value),placeholder:G,disabled:!S,style:{width:"100%",marginTop:6}})]}),e.jsxs("div",{className:"mdocs-settings-item mdocs-agent-config-field",style:{marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigModel")}),S?e.jsx("div",{className:"mdocs-agent-config-select",children:e.jsx(Ls,{options:Vs,value:b,onChange:D=>C(D)})}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:b})]}),e.jsxs("label",{className:"mdocs-settings-item",style:{display:"block",marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigContextWindow")}),e.jsx("p",{className:"mdocs-settings-item-desc",style:{margin:"4px 0 6px"},children:t("agentConfigContextWindowDesc")}),S?e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:i,onChange:D=>N(Number(D.target.value)||128e3),style:{width:"100%"}}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:i})]}),e.jsxs("div",{className:"mdocs-settings-item mdocs-agent-config-field",style:{marginBottom:12},children:[e.jsx("span",{className:"mdocs-settings-card-title",children:t("agentConfigApiKey")}),S?e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:c?"text":"password",value:f,onChange:D=>d(D.target.value),placeholder:j?t("agentConfigApiKeyConfigured").replace("{{masked}}",z??"…"):t("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(c?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>m(D=>!D),children:c?e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[e.jsx("path",{d:"M3 3l18 18"}),e.jsx("path",{d:"M10.6 10.6a2 2 0 002.8 2.8"}),e.jsx("path",{d:"M9.9 5.1A10.5 10.5 0 0121 12c-.6 1.1-1.4 2.1-2.4 2.9"}),e.jsx("path",{d:"M6.1 6.1C4.5 7.4 3.2 9.1 2.5 12c1.5 3.5 5 7 9.5 7 1.4 0 2.7-.3 3.9-.8"})]}):e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[e.jsx("path",{d:"M2.5 12C4 8.5 7.5 5 12 5s8 3.5 9.5 7c-1.5 3.5-5 7-9.5 7s-8-3.5-9.5-7z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]}):e.jsx("p",{className:"mdocs-agent-config-readonly",children:j?z??"…":t("agentConfigApiKeyPlaceholder")})]}),g?e.jsxs("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:[t("agentConfigId"),": ",g]}):null,E?e.jsx("p",{style:{color:"var(--mdocs-danger, #c00)",marginBottom:12},children:E}):null,P&&!S?e.jsx("p",{className:"mdocs-settings-item-desc",style:{marginBottom:12},children:t("saved")}):null,S?e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void q(),disabled:A,children:t(A?"saving":"save")}),g?e.jsx("button",{type:"button",className:"secondary",onClick:H,disabled:A,children:t("cancel")}):null]}):null]})]})})]})}const $s=/^[A-Za-z0-9_]+$/;function ie(t){return $s.test(t.trim())}function Ws(){const t=a.useRef(!0),[s,k]=a.useState([]),[h,g]=a.useState(!0),[M,r]=a.useState(null),[y,b]=a.useState(null),[C,i]=a.useState(!1),[N,f]=a.useState(""),[d,j]=a.useState(""),[u,z]=a.useState(""),[T,R]=a.useState(!1);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]);async function I(){g(!0),r(null);try{const l=await fs();if(!t.current)return;k(l)}catch(l){if(!t.current)return;r(l instanceof Error?l.message:String(l))}finally{t.current&&g(!1)}}a.useEffect(()=>{I()},[]);function A(){i(!0),b(null),f(""),j(""),z(""),r(null)}function B(l){i(!1),b(l.id),f(l.name),j(l.description),z(l.body),r(null)}function E(){i(!1),b(null),f(""),j(""),z("")}async function x(){const l=N.trim();if(!ie(l)){r("名称仅允许英文、数字、下划线");return}if(!u.trim()){r("正文不能为空");return}R(!0),r(null);try{if(C?await xs({name:l,description:d,body:u}):y&&await js(y,{name:l,description:d,body:u}),!t.current)return;E(),await I()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}finally{t.current&&R(!1)}}async function P(l){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){r(null);try{if(await Ns(l),!t.current)return;y===l&&E(),await I()}catch(c){if(!t.current)return;r(c instanceof Error?c.message:String(c))}}}const v=C||y!==null,S=!N.trim()||ie(N);return e.jsxs("div",{className:"mdocs-settings mdocs-agent-skills-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title",children:["Agent Skills",!h&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),v?null:e.jsx("button",{type:"button",className:"secondary",onClick:A,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:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),M?e.jsx("p",{className:"mdocs-agent-skills-error",children:M}):null,v?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:C?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:N,onChange:l=>f(l.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:S?void 0:"mdocs-agent-skills-input-invalid"}),S?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:d,onChange:l=>j(l.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:u,onChange:l=>z(l.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void x(),disabled:T||!S||!N.trim()||!u.trim(),children:T?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:E,disabled:T,children:"取消"})]})]}):null,h?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!h&&s.length===0&&!v?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:A,children:"新建第一个"})]}):null,!h&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(l=>{const c=ie(l.name),m=y===l.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(m?" 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:l.name}),c?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:l.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>B(l),disabled:v&&!m,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void P(l.id),disabled:v,children:"删除"})]})]},l.id)})}):null]})})]})}function be(t,s){const k=localStorage.getItem(t);return k===null?s:k==="true"}function Zs(t){const{t:s,lang:k,setLang:h}=Z(),{onBack:g,onPublishDraft:M}=t,r=a.useRef(!0);a.useEffect(()=>(r.current=!0,()=>{r.current=!1}),[]);const[y,b]=a.useState(()=>be("mdocs.autoPublish",!1)),[C,i]=a.useState(()=>be("mdocs.autoEdit",!0)),[N,f]=a.useState(!1),[d,j]=a.useState("general"),[u,z]=a.useState([]),[T,R]=a.useState(!0),[I,A]=a.useState(null),[B,E]=a.useState(!1),[x,P]=a.useState(!1),[v,S]=a.useState(!1),[l,c]=a.useState(!1),[m,w]=a.useState(null),[F,K]=a.useState(!1),[H,q]=a.useState(!1),[G,D]=a.useState(!1),[p,V]=a.useState(""),[$,Q]=a.useState(!1),[ee,o]=a.useState(!1),[L,W]=a.useState(0),[Ce,re]=a.useState([]),[De,oe]=a.useState(!1),[X,Ie]=a.useState(""),[Te,Ae]=a.useState([]),[Ee,de]=a.useState(!1),[Y,Pe]=a.useState(""),[Me,Le]=a.useState([]),[Re,se]=a.useState(!1),[te,me]=a.useState(null),[ae,ue]=a.useState(new Map);a.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(y))},[y]),a.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(C))},[C]),a.useEffect(()=>{d==="savePublish"&&le().then(n=>{r.current&&W(n.filter(O=>!O.published).length)})},[d]),a.useEffect(()=>{d==="bookmarks"&&ze(),d==="myDocuments"&&pe()},[d]),a.useEffect(()=>{ge()},[]),a.useEffect(()=>{ke().then(n=>{r.current&&Le(n)}).catch(()=>{})},[]);const he=new Map(Me.map(n=>[n.domainId,n.domainName]));async function ge(){try{R(!0);const n=await ys();if(!r.current)return;z(n)}catch{}finally{r.current&&R(!1)}}async function ze(){try{oe(!0);const n=await bs();if(!r.current)return;re(n)}catch{}finally{r.current&&oe(!1)}}async function pe(){try{de(!0);const n=await vs();if(!r.current)return;Ae(n)}catch{}finally{r.current&&de(!1)}}async function Be(n){try{await Is(n),re(O=>O.filter(J=>J.documentId!==n))}catch{}}function Fe(){if(u.some(O=>!O.revoked)){P(!0);return}fe()}async function fe(){try{E(!0);const n=await As();A({token:n.token,name:n.name}),await ge()}finally{E(!1)}}async function Oe(){try{D(!0);const n=await Cs();w(n.recoveryCode)}finally{D(!1)}}async function Ve(n){n.preventDefault();const O=p.trim();if(!(O&&O.length<4))try{Q(!0),await Ds(O),V(""),o(!0),setTimeout(()=>o(!1),3e3)}finally{Q(!1)}}async function Ke(n){me(n);try{const O=await Ts(n),J=new Map;O.forEach(U=>{J.set(U.visitorId,U.permission)}),ue(J)}catch{ue(new Map)}se(!0)}async function $e(n){if(te)try{const O=new Set(n.map(U=>U.visitorId)),J=new Set(ae.keys());for(const U of J)O.has(U)||await Es(te,U);for(const U of n)await Ps(te,U.visitorId,U.permission);await pe()}finally{se(!1),me(null)}}const xe=Ce.filter(n=>{if(!X.trim())return!0;const O=X.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(O)||(n.ownerVisitorName||"").toLowerCase().includes(O)||(n.domainId||"").toLowerCase().includes(O)}),je=Te.filter(n=>{if(!Y.trim())return!0;const O=Y.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(O)||(n.domainId||"").toLowerCase().includes(O)});return e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"mdocs-sidebar",children:[e.jsx("header",{className:"mdocs-sidebar-header",children:e.jsxs("div",{className:"mdocs-brand",children:[e.jsx("img",{src:ks,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]})}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(d==="general"?" active":""),onClick:()=>j("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(d==="bookmarks"?" active":""),onClick:()=>j("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(d==="myDocuments"?" active":""),onClick:()=>j("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(d==="domainManagement"?" active":""),onClick:()=>j("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(d==="memberTemplates"?" active":""),onClick:()=>j("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(d==="agentConfig"?" active":""),onClick:()=>j("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(d==="savePublish"?" active":""),onClick:()=>j("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:g,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[ws(),d==="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:k==="en"?"active":"",onClick:()=>h("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:k==="zh"?"active":"",onClick:()=>h("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"+(C?" active":""),role:"switch","aria-checked":C,onClick:()=>i(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")}),!T&&u.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:u.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:Fe,disabled:B||T,children:B?"…":u.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),I&&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:I.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(I.token),c(!1),S(!0),window.setTimeout(()=>S(!1),2e3)}catch{S(!1),c(!0),window.setTimeout(()=>c(!1),3e3)}})()},children:s(v?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>A(null),children:s("close")})]}),v&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),l&&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:Oe,disabled:G,children:G?"…":"生成恢复码"})]}),m&&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:m})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(m),q(!1),K(!0),window.setTimeout(()=>K(!1),2e3)}catch{K(!1),q(!0),window.setTimeout(()=>q(!1),3e3)}})()},children:F?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>w(null),children:s("close")})]}),F&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),H&&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:Ve,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:p,onChange:n=>V(n.target.value),minLength:0,style:{marginBottom:8}}),ee&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:$,children:$?"设置中…":"保存密码"})]})]})]})]}):d==="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:X,onChange:n=>Ie(n.target.value)}),De?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:xe.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(X?"bookmarkNoMatch":"bookmarkEmpty")}):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:xe.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:"已删除"}):he.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:()=>Be(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})]})]}):d==="myDocuments"?e.jsxs("div",{className:"mdocs-settings",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.jsx("input",{type:"text",className:"mdocs-settings-search",placeholder:"搜索文章…",value:Y,onChange:n=>Pe(n.target.value)}),Ee?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:je.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(Y?"myDocumentsNoMatch":"myDocumentsEmpty")}):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("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{colSpan:2})]})}),e.jsx("tbody",{children:je.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:he.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:new Date(n.updatedAt).toLocaleDateString()}),e.jsx("td",{children:new Date(n.createdAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>Ke(n.documentId),children:s("docInfoInviteMember")})}),e.jsx("td",{style:{textAlign:"right",paddingLeft:0},children:e.jsx("button",{type:"button",className:"primary small",onClick:()=>t.onOpenDocument(n.documentId),children:s("bookmarkOpen")})})]},n.documentId))})]})})]})]}):d==="domainManagement"?e.jsx(Fs,{}):d==="memberTemplates"?e.jsx(Os,{}):d==="agentConfig"?e.jsxs(e.Fragment,{children:[e.jsx(Ks,{}),e.jsx(Ws,{})]}):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:g,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"+(y?" active":""),role:"switch","aria-checked":y,onClick:()=>b(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),L>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>f(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",L,")"]}),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")})})]})]}),N&&e.jsx(zs,{onPublish:M,onClose:()=>f(!1),onCountChange:W,onRecover:t.onRecoverDraft})]}),x&&e.jsx(Ss,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:B,onConfirm:()=>{P(!1),fe()},onCancel:()=>P(!1)}),e.jsx(Se,{open:Re,title:s("docInfoInviteMember"),initialSelectedIds:[...ae.keys()],initialPermissions:ae,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>se(!1),onConfirm:n=>{$e(n)}})]})}export{Zs as SettingsPage};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as o}from"./index-
|
|
1
|
+
import{c as o}from"./index-B-XJ-ScV.js";import{r as u,j as r}from"./react-vendor-BNpqFP9B.js";import{F as _,G as C,L as v,H as c,J as l,K as N,M as L,q as j,N as z,P as w}from"./react-BsVOIHR8.js";import{z as g,V as b}from"./editor-ONzd_YnO.js";/**
|
|
2
2
|
* @license lucide-react v0.562.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|