@fgbg/mdocs 1.3.29 → 1.3.30
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 +12 -0
- package/dist/server/agent/Agent/run-pi-agent.js +27 -0
- package/dist/server/agent/Agent/run-pi-agent.js.map +1 -1
- package/dist/server/agent/Agent/system-prompt.js +7 -5
- package/dist/server/agent/Agent/system-prompt.js.map +1 -1
- package/dist/server/agent/Agent/tool-call-ui.js +145 -0
- package/dist/server/agent/Agent/tool-call-ui.js.map +1 -0
- package/dist/server/agent/Agent/tool-call-ui.test.js +43 -0
- package/dist/server/agent/Agent/tool-call-ui.test.js.map +1 -0
- package/dist/server/agent/Agent/tool-ui-effects.js +3 -23
- package/dist/server/agent/Agent/tool-ui-effects.js.map +1 -1
- package/dist/server/agent/Agent/tools-registry.js +5 -3
- package/dist/server/agent/Agent/tools-registry.js.map +1 -1
- package/dist/server/agent/Agent/tools-registry.test.js +4 -0
- package/dist/server/agent/Agent/tools-registry.test.js.map +1 -1
- package/dist/server/agent/Agent/tools-template.js +5 -0
- package/dist/server/agent/Agent/tools-template.js.map +1 -1
- package/dist/server/agent/Agent/tools-time.js +42 -0
- package/dist/server/agent/Agent/tools-time.js.map +1 -0
- package/dist/server/agent/Agent/tools-time.test.js +20 -0
- package/dist/server/agent/Agent/tools-time.test.js.map +1 -0
- package/dist/web/assets/AgentChatPanel-e1h0rqbg.js +42 -0
- package/dist/web/assets/{AiWriteWorkbench-B0r87dOu.js → AiWriteWorkbench-Dq0aCk5c.js} +3 -3
- package/dist/web/assets/{DiagramEditor-NtNY3sZL-zENSuUSW.js → DiagramEditor-NtNY3sZL-DHC7qgkW.js} +1 -1
- package/dist/web/assets/{DocChrome-B-5PeA3Z.js → DocChrome-7KIXAHsE.js} +8 -3
- package/dist/web/assets/{DocumentEditor-CeH1smor.js → DocumentEditor-CmIk_VBn.js} +1 -1
- package/dist/web/assets/{HtmlEditor-DEwBOS1N.js → HtmlEditor-REIKOoam.js} +1 -1
- package/dist/web/assets/{MergeView-Bzk9R2GH.js → MergeView-DCgxAslc.js} +1 -1
- package/dist/web/assets/{PlaygroundPage-Bmq4l_R3.js → PlaygroundPage-Cz9TMo7h.js} +1 -1
- package/dist/web/assets/SettingsPage-DsLbUPt-.js +21 -0
- package/dist/web/assets/SheetEditor-Bkxxf3ly.js +26 -0
- package/dist/web/assets/SheetEditor-DbT_K_Ia.css +1 -0
- package/dist/web/assets/{Toolbar-SoiYp0SC.js → Toolbar-ClbpubYi.js} +1 -1
- package/dist/web/assets/VisitorPickerModal-D4xmZbNY.js +6 -0
- package/dist/web/assets/{check-CnsclxvV.js → check-CuLfkkz7.js} +1 -1
- package/dist/web/assets/{copy-CI3NmTJZ.js → copy-CjAdouag.js} +1 -1
- package/dist/web/assets/docPlainCharCount-DO5lb3Wt.js +1 -0
- package/dist/web/assets/index-C1Mc0Svw.css +1 -0
- package/dist/web/assets/index-DAhW-QRN.js +299 -0
- package/dist/web/assets/{italic-BljxX8Uj.js → italic-cqqPz-_Q.js} +1 -1
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-BuKVYpuY.js → meta2dEngine-BD2XbzaV-CNHknbe2.js} +1 -1
- package/dist/web/assets/{plus-BAqdJ6N2.js → plus-DkLh2brQ.js} +1 -1
- package/dist/web/assets/{react-C7YGEhUS.js → react-Dj2vqPq5.js} +3 -3
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/server/agent/Agent/tools-account.js +0 -25
- package/dist/server/agent/Agent/tools-account.js.map +0 -1
- package/dist/server/db/repositories/diagram.repo.js +0 -21
- package/dist/server/db/repositories/diagram.repo.js.map +0 -1
- package/dist/server/diagrams/diagram.service.js +0 -156
- package/dist/server/diagrams/diagram.service.js.map +0 -1
- package/dist/server/routes/diagrams.routes.js +0 -122
- package/dist/server/routes/diagrams.routes.js.map +0 -1
- package/dist/shared/types/diagram.js +0 -2
- package/dist/shared/types/diagram.js.map +0 -1
- package/dist/web/assets/AgentChatPanel-BD1oyUQ2.js +0 -42
- package/dist/web/assets/SettingsPage-B3-GANlD.js +0 -1
- package/dist/web/assets/SheetEditor-DYVKW2RD.js +0 -16
- package/dist/web/assets/SheetEditor-gXD-sRv2.css +0 -1
- package/dist/web/assets/VisitorPickerModal-BTmTrqrT.js +0 -1
- package/dist/web/assets/docPlainCharCount-C7aeeOM1.js +0 -11
- package/dist/web/assets/index-CSZ-Z1RJ.css +0 -1
- package/dist/web/assets/index-DNb6Q69l.js +0 -299
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as i,j as n}from"./react-vendor-BVS1XoFi.js";import{c as xe,f as ve,e as ge,a as ye,s as be,g as Ce,u as ke,h as je,S as Ie,l as we,r as De,i as Se,j as Ee,D as E,k as Ne,m as Pe,b as Z}from"./index-DNb6Q69l.js";import{D as Me}from"./DocChrome-B-5PeA3Z.js";import{V as Be}from"./VisitorPickerModal-BTmTrqrT.js";import{c as Re,U as Ae,S as Te}from"./docPlainCharCount-C7aeeOM1.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./file-type-policy-C6Nun42Q.js";function _e(e){const{t:a,lang:k}=xe(),r=e.meta.documentId,[h,N]=i.useState(e.initialContent),[x,P]=i.useState(e.initialDisplayName),[u,j]=i.useState(!0),[q,G]=i.useState(!1),[p,I]=i.useState(e.hasLocalDraft??!1),[f,M]=i.useState(!1),[B,K]=i.useState(!1),[v,R]=i.useState(!1),[y,A]=i.useState(!1),[ee,te]=i.useState([]),[ne,b]=i.useState(!1),[T,z]=i.useState(e.meta.permission),[O,Q]=i.useState(!1),[ie,L]=i.useState(!1),[w,ae]=i.useState(new Map),[Y,V]=i.useState(null),D=i.useRef(0),U=i.useRef(null),F=i.useRef(null),c=i.useRef(null),S=i.useRef(h),W=i.useRef(x);S.current=h,W.current=x;const se=e.canEdit&&!u;i.useEffect(()=>{N(e.initialContent),P(e.initialDisplayName),j(!0)},[r]),i.useEffect(()=>{e.contentRevision&&(N(e.initialContent),P(e.initialDisplayName))},[e.contentRevision]),i.useEffect(()=>{let t=!0;return ve().then(s=>{t&&te(s)}).catch(()=>{}),()=>{t=!1}},[]),i.useEffect(()=>{let t=!0;return ge(r).then(s=>{t&&M(s.bookmarked)}).catch(()=>{}),()=>{t=!1}},[r]),i.useEffect(()=>{let t=!1;const s=Z();return ye(r).then(o=>{var m;if(t||Z()!==s)return;const l=!!(o&&!o.published);I(l),(m=e.onDraftExistsChange)==null||m.call(e,l)}),()=>{t=!0}},[r,e.onDraftExistsChange]),i.useEffect(()=>be((t,s)=>{var o;t===r&&(I(s),(o=e.onDraftExistsChange)==null||o.call(e,s))}),[r,e.onDraftExistsChange]),i.useEffect(()=>{z(e.meta.permission)},[e.meta.permission,r]),i.useEffect(()=>{const t=s=>{U.current&&!U.current.contains(s.target)&&R(!1),F.current&&!F.current.contains(s.target)&&A(!1)};return(v||y)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[v,y]),i.useEffect(()=>{if(!v&&!y)return;const t=++D.current;V(null);const s=()=>{if(t===D.current)try{const m=Re("html",S.current||"");t===D.current&&V(m)}catch{t===D.current&&V(0)}},o=window;if(typeof o.requestIdleCallback=="function"){const m=o.requestIdleCallback(s);return()=>{var C;return(C=o.cancelIdleCallback)==null?void 0:C.call(o,m)}}const l=window.setTimeout(s,0);return()=>window.clearTimeout(l)},[v,y,h,r,e.contentRevision]);const H=i.useCallback(async()=>{var t;await Ce(r).execute(()=>ke({documentId:r,content:S.current,displayName:W.current,contentKind:"html",localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})),I(!0),(t=e.onDraftExistsChange)==null||t.call(e,!0)},[r,e]),J=i.useCallback(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{H()},1e3)},[H]);i.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);async function $(t){var s;if(e.canEdit){G(!0);try{c.current&&(clearTimeout(c.current),c.current=null),await H(),await e.onPublish(S.current,W.current.trim()||x,r,t),I(!1),(s=e.onDraftExistsChange)==null||s.call(e,!1)}finally{G(!1)}}}async function oe(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(x.trim()!==t)try{await $()}catch{}}async function _(){var t,s;if(!B){K(!0);try{f?(await De(r),M(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await Se(r),M(!0),(s=e.onShowToast)==null||s.call(e,a("bookmarkAdded")))}finally{K(!1)}}}function re(t){const s=ee.find(o=>o.visitorId===t);return(s==null?void 0:s.visitorName)??t.slice(0,8)}function le(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const d=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),ce=i.useMemo(()=>{const t=(d==null?void 0:d.permission)??"public";return je(t)},[d==null?void 0:d.permission]);function de(t){return t===E.PRIVATE?a("permissionPrivate"):t===E.DOMAIN_READ?a("permissionInvite"):t===E.DOMAIN_WRITE?a("permissionDomainWrite"):t===E.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function me(){if(O||T===e.meta.permission){b(!1);return}Q(!0);try{await $(T),b(!1)}finally{Q(!1)}}async function ue(t){const s=new Set(t.map(o=>o.visitorId));for(const[o]of w)s.has(o)||await Ne(r,o);for(const o of t)w.get(o.visitorId)!==o.permission&&await Pe(r,o.visitorId,o.permission);L(!1)}function g(){R(!1),A(!1)}function X(t,s){const o=(s==null?void 0:s.includeBookmark)??!0,l={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreator")}),n.jsx("span",{children:re(e.meta.ownerVisitorId)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreatedAt")}),n.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(k==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoSize")}),n.jsx("span",{children:le(new Blob([h]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCharCount")}),n.jsx("span",{children:Y===null?"…":Y.toLocaleString(k==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(k==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),o?n.jsxs("button",{type:"button",style:l,onClick:()=>{_(),t()},children:[n.jsx("span",{children:f?"⭐":"☆"}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),(async()=>{const m=await Ee(r);ae(new Map(m.map(C=>[C.visitorId,C.permission]))),L(!0)})()},children:[n.jsx(Ae,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),z(e.meta.permission),b(!0)},children:[n.jsx(Te,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})}const fe=i.useCallback(t=>{var o;const s=t.target.value;N(s),(o=e.onContentChange)==null||o.call(e,s),J()},[e,J]),he=`<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head><body>${h}</body></html>`;return n.jsxs("div",{className:"mdocs-editor"+(e.readerChrome?" mdocs-editor--reader":""),children:[n.jsx(Me,{fileType:"html",displayName:x,onDisplayNameChange:P,onDisplayNameBlur:()=>void oe(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:se,onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:q,draftExists:p,onPublish:()=>{$().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:f,bookmarkBusy:B,onToggleBookmark:()=>void _(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:X(g),docInfoOpen:v,onToggleDocInfo:()=>R(!v),docInfoMenuRef:U,readerChrome:e.readerChrome,readerActionsCollapsible:!0,readerHeaderDocked:e.readerChrome,onOpenMobileNav:e.onOpenMobileNav,readerMoreOpen:y,onToggleReaderMore:()=>A(t=>!t),readerMoreMenuRef:F,readerMoreMenu:n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:B,onClick:()=>{_(),g()},children:[n.jsx(Ie,{size:16,strokeWidth:1.5,style:{color:f?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:f?"#faad14":"none"}}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}),n.jsx("div",{className:"mdocs-reader-more-divider"}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:!u,onClick:()=>{j(!1),g()},children:a("edit")}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:u,onClick:()=>{j(!0),g()},children:a("preview")}),n.jsx("div",{className:"mdocs-reader-more-divider"}),e.canEdit?n.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:q,onClick:()=>{g(),e.onDelete()},children:n.jsx("span",{children:a("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),X(g,{includeBookmark:!1})]}),leadingExtra:e.canEdit&&!e.readerChrome?n.jsxs("label",{className:"mdocs-editor-mode-toggle","aria-label":a(u?"preview":"edit"),children:[n.jsx("input",{type:"checkbox",checked:u,onChange:()=>j(t=>!t)}),n.jsxs("span",{className:"mdocs-editor-mode-toggle-slider",children:[n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--left",children:a("edit")}),n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--right",children:a("preview")})]})]}):null}),n.jsxs("div",{className:"mdocs-html-editor-body",children:[!u&&e.canEdit?n.jsx("textarea",{className:"mdocs-html-editor-textarea",value:h,onChange:fe,spellCheck:!1,placeholder:"在此处编写 HTML 代码"}):null,n.jsx("div",{className:"mdocs-html-editor-preview",style:!u&&e.canEdit?{width:"50%"}:{width:"100%"},children:n.jsx("iframe",{className:"mdocs-html-editor-iframe",srcDoc:he,sandbox:"",title:x})})]}),ne&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&b(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:a("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[a("domainPermission"),":",d?we(d.domainName,k,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:ce.map(t=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n.jsx("input",{type:"radio",name:"html-doc-permission",value:t,checked:T===t,onChange:()=>z(t)}),n.jsx("span",{children:de(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>b(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:O,onClick:()=>void me(),children:a(O?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Be,{open:ie,title:a("docInfoInviteMember"),initialSelectedIds:[...w.keys()],initialPermissions:w,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>L(!1),onConfirm:t=>{ue(t)}})]})}export{_e as HtmlEditor};
|
|
1
|
+
import{r as i,j as n}from"./react-vendor-BVS1XoFi.js";import{c as xe,f as ve,e as ge,a as ye,s as be,g as Ce,u as ke,h as je,S as Ie,l as we,r as De,i as Se,j as Ee,D as E,k as Ne,m as Pe,b as Z}from"./index-DAhW-QRN.js";import{D as Me,S as Be}from"./DocChrome-7KIXAHsE.js";import{V as Re,U as Ae}from"./VisitorPickerModal-D4xmZbNY.js";import{c as Te}from"./docPlainCharCount-DO5lb3Wt.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./file-type-policy-C6Nun42Q.js";function _e(e){const{t:a,lang:k}=xe(),r=e.meta.documentId,[h,N]=i.useState(e.initialContent),[x,P]=i.useState(e.initialDisplayName),[u,j]=i.useState(!0),[q,G]=i.useState(!1),[p,I]=i.useState(e.hasLocalDraft??!1),[f,M]=i.useState(!1),[B,K]=i.useState(!1),[v,R]=i.useState(!1),[y,A]=i.useState(!1),[ee,te]=i.useState([]),[ne,b]=i.useState(!1),[T,z]=i.useState(e.meta.permission),[O,Q]=i.useState(!1),[ie,L]=i.useState(!1),[w,ae]=i.useState(new Map),[Y,V]=i.useState(null),D=i.useRef(0),U=i.useRef(null),F=i.useRef(null),c=i.useRef(null),S=i.useRef(h),W=i.useRef(x);S.current=h,W.current=x;const se=e.canEdit&&!u;i.useEffect(()=>{N(e.initialContent),P(e.initialDisplayName),j(!0)},[r]),i.useEffect(()=>{e.contentRevision&&(N(e.initialContent),P(e.initialDisplayName))},[e.contentRevision]),i.useEffect(()=>{let t=!0;return ve().then(s=>{t&&te(s)}).catch(()=>{}),()=>{t=!1}},[]),i.useEffect(()=>{let t=!0;return ge(r).then(s=>{t&&M(s.bookmarked)}).catch(()=>{}),()=>{t=!1}},[r]),i.useEffect(()=>{let t=!1;const s=Z();return ye(r).then(o=>{var m;if(t||Z()!==s)return;const l=!!(o&&!o.published);I(l),(m=e.onDraftExistsChange)==null||m.call(e,l)}),()=>{t=!0}},[r,e.onDraftExistsChange]),i.useEffect(()=>be((t,s)=>{var o;t===r&&(I(s),(o=e.onDraftExistsChange)==null||o.call(e,s))}),[r,e.onDraftExistsChange]),i.useEffect(()=>{z(e.meta.permission)},[e.meta.permission,r]),i.useEffect(()=>{const t=s=>{U.current&&!U.current.contains(s.target)&&R(!1),F.current&&!F.current.contains(s.target)&&A(!1)};return(v||y)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[v,y]),i.useEffect(()=>{if(!v&&!y)return;const t=++D.current;V(null);const s=()=>{if(t===D.current)try{const m=Te("html",S.current||"");t===D.current&&V(m)}catch{t===D.current&&V(0)}},o=window;if(typeof o.requestIdleCallback=="function"){const m=o.requestIdleCallback(s);return()=>{var C;return(C=o.cancelIdleCallback)==null?void 0:C.call(o,m)}}const l=window.setTimeout(s,0);return()=>window.clearTimeout(l)},[v,y,h,r,e.contentRevision]);const H=i.useCallback(async()=>{var t;await Ce(r).execute(()=>ke({documentId:r,content:S.current,displayName:W.current,contentKind:"html",localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})),I(!0),(t=e.onDraftExistsChange)==null||t.call(e,!0)},[r,e]),J=i.useCallback(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{H()},1e3)},[H]);i.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);async function $(t){var s;if(e.canEdit){G(!0);try{c.current&&(clearTimeout(c.current),c.current=null),await H(),await e.onPublish(S.current,W.current.trim()||x,r,t),I(!1),(s=e.onDraftExistsChange)==null||s.call(e,!1)}finally{G(!1)}}}async function oe(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(x.trim()!==t)try{await $()}catch{}}async function _(){var t,s;if(!B){K(!0);try{f?(await De(r),M(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await Se(r),M(!0),(s=e.onShowToast)==null||s.call(e,a("bookmarkAdded")))}finally{K(!1)}}}function re(t){const s=ee.find(o=>o.visitorId===t);return(s==null?void 0:s.visitorName)??t.slice(0,8)}function le(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const d=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),ce=i.useMemo(()=>{const t=(d==null?void 0:d.permission)??"public";return je(t)},[d==null?void 0:d.permission]);function de(t){return t===E.PRIVATE?a("permissionPrivate"):t===E.DOMAIN_READ?a("permissionInvite"):t===E.DOMAIN_WRITE?a("permissionDomainWrite"):t===E.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function me(){if(O||T===e.meta.permission){b(!1);return}Q(!0);try{await $(T),b(!1)}finally{Q(!1)}}async function ue(t){const s=new Set(t.map(o=>o.visitorId));for(const[o]of w)s.has(o)||await Ne(r,o);for(const o of t)w.get(o.visitorId)!==o.permission&&await Pe(r,o.visitorId,o.permission);L(!1)}function g(){R(!1),A(!1)}function X(t,s){const o=(s==null?void 0:s.includeBookmark)??!0,l={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreator")}),n.jsx("span",{children:re(e.meta.ownerVisitorId)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreatedAt")}),n.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(k==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoSize")}),n.jsx("span",{children:le(new Blob([h]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCharCount")}),n.jsx("span",{children:Y===null?"…":Y.toLocaleString(k==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(k==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),o?n.jsxs("button",{type:"button",style:l,onClick:()=>{_(),t()},children:[n.jsx("span",{children:f?"⭐":"☆"}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),(async()=>{const m=await Ee(r);ae(new Map(m.map(C=>[C.visitorId,C.permission]))),L(!0)})()},children:[n.jsx(Ae,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),z(e.meta.permission),b(!0)},children:[n.jsx(Be,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})}const fe=i.useCallback(t=>{var o;const s=t.target.value;N(s),(o=e.onContentChange)==null||o.call(e,s),J()},[e,J]),he=`<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head><body>${h}</body></html>`;return n.jsxs("div",{className:"mdocs-editor"+(e.readerChrome?" mdocs-editor--reader":""),children:[n.jsx(Me,{fileType:"html",displayName:x,onDisplayNameChange:P,onDisplayNameBlur:()=>void oe(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:se,onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:q,draftExists:p,onPublish:()=>{$().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:f,bookmarkBusy:B,onToggleBookmark:()=>void _(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:X(g),docInfoOpen:v,onToggleDocInfo:()=>R(!v),docInfoMenuRef:U,readerChrome:e.readerChrome,readerActionsCollapsible:!0,readerHeaderDocked:e.readerChrome,onOpenMobileNav:e.onOpenMobileNav,readerMoreOpen:y,onToggleReaderMore:()=>A(t=>!t),readerMoreMenuRef:F,readerMoreMenu:n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:B,onClick:()=>{_(),g()},children:[n.jsx(Ie,{size:16,strokeWidth:1.5,style:{color:f?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:f?"#faad14":"none"}}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}),n.jsx("div",{className:"mdocs-reader-more-divider"}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:!u,onClick:()=>{j(!1),g()},children:a("edit")}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:u,onClick:()=>{j(!0),g()},children:a("preview")}),n.jsx("div",{className:"mdocs-reader-more-divider"}),e.canEdit?n.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:q,onClick:()=>{g(),e.onDelete()},children:n.jsx("span",{children:a("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),X(g,{includeBookmark:!1})]}),leadingExtra:e.canEdit&&!e.readerChrome?n.jsxs("label",{className:"mdocs-editor-mode-toggle","aria-label":a(u?"preview":"edit"),children:[n.jsx("input",{type:"checkbox",checked:u,onChange:()=>j(t=>!t)}),n.jsxs("span",{className:"mdocs-editor-mode-toggle-slider",children:[n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--left",children:a("edit")}),n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--right",children:a("preview")})]})]}):null}),n.jsxs("div",{className:"mdocs-html-editor-body",children:[!u&&e.canEdit?n.jsx("textarea",{className:"mdocs-html-editor-textarea",value:h,onChange:fe,spellCheck:!1,placeholder:"在此处编写 HTML 代码"}):null,n.jsx("div",{className:"mdocs-html-editor-preview",style:!u&&e.canEdit?{width:"50%"}:{width:"100%"},children:n.jsx("iframe",{className:"mdocs-html-editor-iframe",srcDoc:he,sandbox:"",title:x})})]}),ne&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&b(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:a("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[a("domainPermission"),":",d?we(d.domainName,k,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:ce.map(t=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n.jsx("input",{type:"radio",name:"html-doc-permission",value:t,checked:T===t,onChange:()=>z(t)}),n.jsx("span",{children:de(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>b(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:O,onClick:()=>void me(),children:a(O?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Re,{open:ie,title:a("docInfoInviteMember"),initialSelectedIds:[...w.keys()],initialPermissions:w,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>L(!1),onConfirm:t=>{ue(t)}})]})}export{_e as HtmlEditor};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as x,j as i}from"./react-vendor-BVS1XoFi.js";import{c as K,
|
|
1
|
+
import{r as x,j as i}from"./react-vendor-BVS1XoFi.js";import{c as K,b8 as H,b9 as Y,ba as Z,bb as ee}from"./index-DAhW-QRN.js";import{E as te,B as ne}from"./react-Dj2vqPq5.js";import{g as le}from"./file-type-policy-C6Nun42Q.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./editor-DBWWidi3.js";import"./plus-DkLh2brQ.js";import"./copy-CjAdouag.js";import"./check-CuLfkkz7.js";function B({lexicalJson:e,onMarkdown:n,onError:c}){const[s,l]=x.useState(null),o=x.useRef(!1);return x.useEffect(()=>{o.current=!1},[e]),x.useEffect(()=>{if(!(!s||o.current))try{s.setDocument("json",e);const a=s.getDocument("markdown");typeof a=="string"&&(o.current=!0,n(a))}catch{c==null||c()}},[s,e,n,c]),i.jsx("div",{className:"mdocs-lexical-md-bridge","aria-hidden":!0,children:i.jsx(te,{content:e,type:"json",editable:!1,onInit:l,plugins:[ne]})})}function se(e){const{t:n}=K(),[c,s]=x.useState(0),l=e.segments.filter(t=>t.kind==="conflict"),o=e.unresolvedCount>0;x.useEffect(()=>{if(l.length===0){s(0);return}s(t=>Math.min(t,l.length-1))},[l.length]);function a(t){l.length!==0&&s(d=>{var m;const u=(d+t+l.length)%l.length;return(m=document.getElementById(`mdocs-merge-hunk-${u}`))==null||m.scrollIntoView({block:"center",behavior:"smooth"}),u})}let r=-1;return i.jsxs("div",{className:"mdocs-merge-inline-pane",children:[i.jsxs("div",{className:"mdocs-merge-inline-toolbar",children:[i.jsx("span",{className:"mdocs-merge-inline-hint",children:o?n("mergeReviewHint"):l.length===0?n("mergeNoConflicts"):n("mergeEditAfterResolve")}),l.length>0?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",onClick:e.onUseAllMine,children:n("mergeUseAllMine")}),i.jsx("button",{type:"button",onClick:e.onUseAllTheirs,children:n("mergeUseAllTheirs")})]}):null]}),o?i.jsxs("div",{className:"mdocs-merge-inline",role:"document",children:[e.segments.map((t,d)=>{if(t.kind==="unchanged")return i.jsx("pre",{className:"mdocs-merge-inline-same",children:t.lines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line ctx",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},C))},`u-${d}`);r+=1;const u=r,m=t.resolution!=="unresolved",f=u===c;return i.jsxs("div",{id:`mdocs-merge-hunk-${u}`,className:"mdocs-merge-inline-hunk"+(f?" is-active":"")+(m?" is-resolved":""),onClick:()=>s(u),children:[m?i.jsx("div",{className:"mdocs-merge-hunk-resolved-tag",children:t.resolution==="remote"?n("mergeReceive"):n("mergeReject")}):i.jsxs("div",{className:"mdocs-merge-hunk-actions",children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:g=>{g.stopPropagation(),e.onReject(t.id)},children:n("mergeReject")}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:g=>{g.stopPropagation(),e.onReceive(t.id)},children:n("mergeReceive")})]}),i.jsxs("pre",{className:"mdocs-ai-write-hunk-pre",children:[t.localLines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line del",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},`l${C}`)),t.remoteLines.map((g,C)=>i.jsxs("div",{className:"mdocs-ai-write-line add",children:[i.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),i.jsx("span",{className:"mdocs-ai-write-code",children:g||" "})]},`r${C}`))]})]},t.id)}),l.length>0?i.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"冲突导航",children:[i.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>a(-1),children:"↑"}),i.jsxs("span",{children:[c+1," / ",l.length]}),i.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>a(1),children:"↓"}),l[c]&&l[c].resolution==="unresolved"?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>e.onReject(l[c].id),children:n("mergeReject")}),i.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>e.onReceive(l[c].id),children:n("mergeReceive")})]}):null]}):null]}):i.jsx("textarea",{className:"mdocs-merge-inline-editor",value:e.editableMarkdown,onChange:t=>e.onEditableChange(t.target.value),spellCheck:!1})]})}function ie(e,n){let c={};for(let o=0;o<n.length;o++){const a=n[o];c[a]?c[a].push(o):c[a]=[o]}let l=[{buffer1index:-1,buffer2index:-1,chain:null}];for(let o=0;o<e.length;o++){const a=e[o],r=c[a]||[];let t=0,d=l[0];for(let u=0;u<r.length;u++){const m=r[u];let f;for(f=t;f<l.length&&!(l[f].buffer2index<m&&(f===l.length-1||l[f+1].buffer2index>m));f++);if(f<l.length){const g={buffer1index:o,buffer2index:m,chain:l[f]};if(t===l.length?l.push(d):l[t]=d,t=f+1,d=g,t===l.length)break}}l[t]=d}return l[l.length-1]}function O(e,n){const c=ie(e,n);let s=[],l=e.length,o=n.length;for(let a=c;a!==null;a=a.chain){const r=l-a.buffer1index-1,t=o-a.buffer2index-1;l=a.buffer1index,o=a.buffer2index,(r||t)&&s.push({buffer1:[l+1,r],buffer1Content:e.slice(l+1,l+1+r),buffer2:[o+1,t],buffer2Content:n.slice(o+1,o+1+t)})}return s.reverse(),s}function oe(e,n,c){let s=[];function l(t,d){s.push({ab:d,oStart:t.buffer1[0],oLength:t.buffer1[1],abStart:t.buffer2[0],abLength:t.buffer2[1]})}O(n,e).forEach(t=>l(t,"a")),O(n,c).forEach(t=>l(t,"b")),s.sort((t,d)=>t.oStart-d.oStart);let o=[],a=0;function r(t){t>a&&(o.push({stable:!0,buffer:"o",bufferStart:a,bufferLength:t-a,bufferContent:n.slice(a,t)}),a=t)}for(;s.length;){let t=s.shift(),d=t.oStart,u=t.oStart+t.oLength,m=[t];for(r(d);s.length;){const f=s[0],g=f.oStart;if(g>u)break;u=Math.max(u,g+f.oLength),m.push(s.shift())}if(m.length===1){if(t.abLength>0){const f=t.ab==="a"?e:c;o.push({stable:!0,buffer:t.ab,bufferStart:t.abStart,bufferLength:t.abLength,bufferContent:f.slice(t.abStart,t.abStart+t.abLength)})}}else{let f={a:[e.length,-1,n.length,-1],b:[c.length,-1,n.length,-1]};for(;m.length;){t=m.shift();const b=t.oStart,w=b+t.oLength,L=t.abStart,y=L+t.abLength;let v=f[t.ab];v[0]=Math.min(L,v[0]),v[1]=Math.max(y,v[1]),v[2]=Math.min(b,v[2]),v[3]=Math.max(w,v[3])}const g=f.a[0]+(d-f.a[2]),C=f.a[1]+(u-f.a[3]),k=f.b[0]+(d-f.b[2]),h=f.b[1]+(u-f.b[3]);let p={stable:!1,aStart:g,aLength:C-g,aContent:e.slice(g,C),oStart:d,oLength:u-d,oContent:n.slice(d,u),bStart:k,bLength:h-k,bContent:c.slice(k,h)};o.push(p)}a=u}return r(n.length),o}function ce(e,n,c,s){s=Object.assign({excludeFalseConflicts:!0,stringSeparator:/\s+/},s),typeof e=="string"&&(e=e.split(s.stringSeparator)),typeof n=="string"&&(n=n.split(s.stringSeparator)),typeof c=="string"&&(c=c.split(s.stringSeparator));let o=[];const a=oe(e,n,c);let r=[];function t(){r.length&&o.push({ok:r}),r=[]}function d(u,m){if(u.length!==m.length)return!1;for(let f=0;f<u.length;f++)if(u[f]!==m[f])return!1;return!0}return a.forEach(u=>{u.stable?r.push(...u.bufferContent):s.excludeFalseConflicts&&d(u.aContent,u.bContent)?r.push(...u.aContent):(t(),o.push({conflict:{a:u.aContent,aIndex:u.aStart,o:u.oContent,oIndex:u.oStart,b:u.bContent,bIndex:u.bStart}}))}),t(),o}const ae=/^<!--\s*mdocs-merge-conflict:([^\s]+)\s*-->$/;function re(e){return`<!-- mdocs-merge-conflict:${e} -->`}function ue(e){const n=e.trim().match(ae);return(n==null?void 0:n[1])??null}function E(e){return e===""?[]:e.split(`
|
|
2
2
|
`)}function V(e,n){return e.length===n.length&&e.every((c,s)=>c===n[s])}function de(e,n,c){const s=E(e),l=E(n),o=E(c);if(l.length===0&&n==="")return me(e,c);const a=ce(s,l,o),r=[];let t=0,d=0,u=0,m=0;const f=(C,k,h,p)=>{r.push({kind:"conflict",id:`conflict-${t}`,conflictKind:p,baseLines:C,localLines:k,remoteLines:h,resolution:"unresolved"}),t+=1},g=(C,k,h)=>{if(k.length===0&&C.length===0&&h.length===0)return;if(V(C,k)&&V(h,k)){k.length>0&&r.push({kind:"unchanged",lines:[...k]});return}if(C.length===k.length&&h.length===k.length){let b=[];const w=()=>{b.length>0&&(r.push({kind:"unchanged",lines:b}),b=[])};for(let L=0;L<k.length;L+=1){const y=k[L],v=C[L],I=h[L];v===y&&I===y?b.push(y):(w(),f([y],[v],[I],v!==y&&I!==y&&v!==I?"true_conflict":"change"))}w();return}const p=C.join(`
|
|
3
3
|
`)!==k.join(`
|
|
4
4
|
`)&&h.join(`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as n,j as o,ae as C}from"./react-vendor-BVS1XoFi.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as L,w as f,j as H,k as F,l as q,I as U,m as b,n as V,o as J,p as W,q as z,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-
|
|
1
|
+
import{r as n,j as o,ae as C}from"./react-vendor-BVS1XoFi.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as L,w as f,j as H,k as F,l as q,I as U,m as b,n as V,o as J,p as W,q as z,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-Dj2vqPq5.js";import{a7 as Q,a8 as X,a9 as ee,aa as te,ab as k,ac as oe}from"./ui-CEFkTVnG.js";import{H as re,a as ae,b as ne,M as le,T as ie,S as se,W as de,c as R,o as ce}from"./Toolbar-ClbpubYi.js";import{N as me}from"./index-DAhW-QRN.js";import"./editor-DBWWidi3.js";import"./diagram-BF8g9yg4.js";import"./plus-DkLh2brQ.js";import"./copy-CjAdouag.js";import"./check-CuLfkkz7.js";import"./motion-BAXVQJfN.js";import"./italic-cqqPz-_Q.js";const ue=({children:h,json:r,markdown:a,collapsible:m=!1,defaultActiveKey:y=["editor","text","json"],onJSONChange:p})=>{const[g,c]=n.useState(r),s=n.useRef(r);n.useEffect(()=>{r!==s.current&&(c(r),s.current=r)},[r]);const x=n.useCallback(d=>{s.current=d,c(d)},[]);return o.jsxs(o.Fragment,{children:[o.jsx(Q,{}),o.jsx(X,{collapsible:m,defaultActiveKey:y,items:[{children:h,key:"editor",label:"Playground"},{children:o.jsx(ee,{language:"markdown",style:{fontSize:12,padding:16},variant:"borderless",children:a}),key:"text",label:"Text Output"},{children:o.jsx(te,{language:"json",onBlur:()=>{if(r!==s.current)try{const d=JSON.parse(s.current||"");p==null||p(d)}catch(d){console.error("Invalid JSON:",d)}},onValueChange:x,value:g,variant:"borderless"}),key:"json",label:"JSON Output"}],padding:{body:0},style:{border:"none",borderRadius:0,width:"100%"},variant:"outlined"})]})},he={children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Welcome to the Lobe Editor Demo!",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",version:1,tag:"h1"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"In case you were wondering what the black box at the bottom is – it's the debug view, showing the current state of the editor. You can disable it by pressing on the settings control in the bottom-left of your screen and toggling the debug view setting.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"quote",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"The playground is a demo environment built with ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:"@lobehub/editor",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"codeInline",version:1},{detail:0,format:0,mode:"normal",style:"",text:"\uFEFF",type:"cursor",version:1},{detail:0,format:0,mode:"normal",style:"",text:". Try typing in ",type:"text",version:1},{detail:0,format:1,mode:"normal",style:"",text:"some text",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:" with ",type:"text",version:1},{detail:0,format:2,mode:"normal",style:"",text:"different formats",type:"text",version:1},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{children:[{detail:0,format:0,mode:"normal",style:"",text:"Visit the ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lobe Editor website",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://editor.lobehub.com"},{detail:0,format:0,mode:"normal",style:"",text:" for documentation and more information.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Check out the code on our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"GitHub repository",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://github.com/lobehub/lobe-editor",url:"https://github.com/lobehub/lobe-editor"},{detail:0,format:0,mode:"normal",style:"",text:".",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:2},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Playground code",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:"noreferrer",target:null,title:null,url:"https://github.com/lobehub/lobe-editor/blob/master/src/react/Editor/demos/index.tsx"},{detail:0,format:0,mode:"normal",style:"",text:" can be found here.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:3},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Join our ",type:"text",version:1},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Discover Server",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"link",version:1,rel:null,target:null,title:"https://discord.gg/AYFPHvv2jT",url:"https://discord.gg/AYFPHvv2jT"},{detail:0,format:0,mode:"normal",style:"",text:" and chat with the team.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"listitem",version:1,value:4}],direction:"ltr",format:"",indent:0,type:"list",version:1,listType:"bullet",start:1,tag:"ul"},{children:[{detail:0,format:0,mode:"normal",style:"",text:"Lastly, we're constantly adding cool new features to this playground. So make sure you check back here when you next get a chance 🙂.",type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""},{children:[{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"import",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"{",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:"Editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-error);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"}",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"from",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-text);",text:" ",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-success);",text:"@lobehub/editor",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:"'",type:"code-highlight",version:1},{detail:0,format:0,mode:"normal",style:"color: var(--ant-color-info);",text:";",type:"code-highlight",version:1}],direction:null,format:"",indent:0,type:"code",version:1,language:"typescript",theme:"lobe-theme"},{children:[],direction:null,format:"",indent:0,type:"paragraph",version:1,textFormat:0,textStyle:""}],direction:"ltr",format:"",indent:0,type:"root",version:1},ye={root:he};function S(h,r){let a;const m=(...y)=>{a!==void 0&&clearTimeout(a),a=setTimeout(()=>h(...y),r)};return m.cancel=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},m}window.__scrollIntoView=Z;const pe=h=>{const r=N(),a=n.useRef([]),[m,y]=n.useState(""),[p,g]=n.useState(""),c=n.useMemo(()=>S(t=>{const e=t.getDocument("markdown"),l=t.getDocument("json");g(e||""),y(JSON.stringify(l||{},null,2))},200),[]),s=n.useMemo(()=>S(t=>{r&&(console.info("handleJSONChange",t),r.setDocument("json",t))},200),[r]),x=t=>{window.editor=t,c(t)};n.useEffect(()=>()=>{for(const t of a.current)URL.revokeObjectURL(t);a.current=[],c.cancel(),s.cancel(),delete window.editor,delete window.__scrollIntoView},[c,s]);const d=n.useMemo(()=>[{icon:o.jsx(k,{avatar:"💻",size:24}),key:"bot1",label:"前端研发专家",metadata:{id:"bot1"}},{icon:o.jsx(k,{avatar:"🌍",size:24}),key:"bot2",label:"中英文互译助手",metadata:{id:"bot2"}},{icon:o.jsx(k,{avatar:"📖",size:24}),key:"bot3",label:"学术写作增强专家",metadata:{id:"bot3"}}],[]),w=n.useMemo(()=>[{icon:re,key:"h1",label:"Heading 1",onSelect:e=>{e.dispatchCommand(b,{tag:"h1"})}},{icon:ae,key:"h2",label:"Heading 2",onSelect:e=>{e.dispatchCommand(b,{tag:"h2"})}},{icon:ne,key:"h3",label:"Heading 3",onSelect:e=>{e.dispatchCommand(b,{tag:"h3"})}},{type:"divider"},{icon:le,key:"hr",label:"Hr",onSelect:e=>{e.dispatchCommand(V,{})}},{icon:ie,key:"table",label:"Table",onSelect:e=>{e.dispatchCommand(J,{columns:"3",rows:"3"})}},{icon:se,key:"tex",label:"Tex",onSelect:e=>{e.dispatchCommand(W,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>{e.focus()})}},{type:"divider"},{key:"file",label:"File",onSelect:e=>{ce(l=>{for(const u of l)e.dispatchCommand(z,{file:u})})}},{key:"set-text-content",label:"SetTextContent",onSelect:e=>{e.setDocument("text",`123
|
|
2
2
|
123`),queueMicrotask(()=>{e.focus()})}},{key:"insert-link",label:"InsertLink",onSelect:e=>{e.dispatchCommand(B,{url:"https://example.com"}),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeInline",label:"InsertCodeInline",onSelect:e=>{e.dispatchCommand($,void 0),queueMicrotask(()=>{e.focus()})}},{key:"insert-codeBlock",label:"InsertCodeBlock",onSelect:e=>{e.dispatchCommand(K,void 0),queueMicrotask(()=>{e.focus()})}},{icon:de,key:"meta2d",label:"Meta2d",onSelect:e=>{e.dispatchCommand(Y,void 0),queueMicrotask(()=>{e.focus()})}},{icon:me,key:"markmap",label:"Markmap",onSelect:e=>{e.dispatchCommand(G,void 0),queueMicrotask(()=>{e.focus()})}}].map(e=>e.type==="divider"?e:{...e,extra:o.jsx(oe,{code:!0,fontSize:12,type:"secondary",children:e.key})}),[]);return o.jsxs(ue,{json:m,markdown:p,onJSONChange:s,...h,children:[o.jsx(R,{editor:r}),o.jsx(T,{className:"mdocs-playground-editor",content:ye,editor:r,lineEmptyPlaceholder:"Start typing here...",mentionOption:{items:d,markdownWriter:t=>{var e;return`
|
|
3
3
|
<mention>${t.label}[${((e=t.metadata)==null?void 0:e.id)||t.label}]</mention>
|
|
4
4
|
`},onSelect:(t,e)=>{t.dispatchCommand(U,{label:String(e.label),metadata:{id:e.key}})},searchKeys:["label"]},onInit:x,onTextChange:c,pasteVSCodeAsCodeBlock:!0,placeholder:"Type something...",plugins:[I,E,M,j,O,P,A,_,D,L,f(H,{children:o.jsx(R,{editor:r,floating:!0})}),f(F,{delay:1e3,onAutoComplete:async({input:t,afterText:e,selectionType:l,abortSignal:u})=>{console.log("Auto-complete triggered:",{afterText:e,input:t,selectionType:l});try{const v=await fetch(`${location.origin}/nodeserver/completion`,{body:JSON.stringify({prompt:`Please complete the following text:
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import{r as t,j as e}from"./react-vendor-BVS1XoFi.js";import{o as De,c as ce,$ as Ks,a0 as Os,V as Us,l as re,a1 as $s,a2 as Vs,a3 as ee,a4 as Ue,a5 as _s,a6 as Ws,a7 as qs,a as Gs,d as Xe,a8 as us,a9 as hs,aa as Hs,ab as Js,ac as Zs,ad as Qs,ae as Ys,af as ps,ag as Be,ah as Xs,ai as et,aj as st,X as tt,ak as at,al as nt,f as gs,am as it,an as ct,ao as lt,ap as ot,aq as rt,ar as fs,as as dt,at as mt,au as ut,av as ht,aw as pt,ax as gt,ay as ft,az as xs,aA as xt,aB as yt,aC as bt,aD as jt,aE as Nt,S as vt,aF as kt,aG as St,aH as wt,aI as Ct,aJ as Dt,aK as It,aL as es,U as Tt,aM as At,aN as Mt,aO as Pt,r as Et,j as Rt,aP as Ft,k as zt,m as Lt}from"./index-DAhW-QRN.js";import{V as ys,a as Bt,M as ss,U as Kt}from"./VisitorPickerModal-D4xmZbNY.js";import{C as Ot}from"./check-CuLfkkz7.js";import{ai as Ke,aj as Ut,ak as $t,al as Vt,am as _t,an as Wt,ao as ts,ap as qt,aq as as}from"./ui-CEFkTVnG.js";import"./diagram-BF8g9yg4.js";import"./motion-BAXVQJfN.js";/**
|
|
2
|
+
* @license lucide-react v0.562.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const Gt=[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]],Ht=De("cloud-upload",Gt);/**
|
|
7
|
+
* @license lucide-react v0.562.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const Jt=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]],Zt=De("layout-grid",Jt);/**
|
|
12
|
+
* @license lucide-react v0.562.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const Qt=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"m16 16-1.9-1.9",key:"1dq9hf"}]],Yt=De("scan-search",Qt);/**
|
|
17
|
+
* @license lucide-react v0.562.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const Xt=[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]],ea=De("sparkles",Xt);function sa({draft:a,onClose:s,onSuccess:p}){const{t:u,lang:y}=ce(),[R,f]=t.useState([]),[S,N]=t.useState(a.domainId??""),[h,w]=t.useState([]),[A,I]=t.useState(""),[c,v]=t.useState(`${a.displayName||"untitled"}_recovered.md`),[g,x]=t.useState(!1),[D,L]=t.useState(null),b=t.useRef(null),B=t.useRef(!0);t.useEffect(()=>(B.current=!0,()=>{B.current=!1}),[]),t.useEffect(()=>{Ks().then(k=>{B.current&&f(k)})},[]),t.useEffect(()=>{S&&(w([]),I(""),Os(S).then(k=>{B.current&&w(k)}).catch(()=>{B.current&&w([])}))},[S]),t.useEffect(()=>{const k=window.setTimeout(()=>{var E;return(E=b.current)==null?void 0:E.focus()},0);return()=>window.clearTimeout(k)},[]),t.useEffect(()=>{const k=E=>{E.key==="Escape"&&s()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[s]);function K(k,E){for(const C of k){if(C.type==="folder"&&C.path===E)return C.documentId;if(C.type==="folder"){const F=K(C.children,E);if(F)return F}}return null}async function z(k){k.preventDefault(),x(!0),L(null);const E=c.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),C=E.endsWith(".md")?E:E+".md",F=C.replace(/\.md$/i,"");try{const m=A?`${A}/${C}`:C,d=A?K(h,A)??void 0:void 0;await Vs({fileName:C,displayName:F,content:a.content,domainId:S,parentId:d}),p()}catch(m){L(ee(u,m))}finally{x(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:k=>{k.target===k.currentTarget&&!g&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:u("recoverDraft")}),e.jsx("p",{className:"muted",children:u("recoverDraftDesc",{name:a.displayName||u("unknownTitle")})}),e.jsxs("form",{onSubmit:z,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[u("domainLabel"),R.length>0&&e.jsx(Us,{domains:R,value:S,onChange:N,onDomainsChange:f,ariaLabel:u("domainLabel"),localizeName:k=>re(k,y,u)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[u("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx($s,{nodes:h,activeDocumentId:null,selectedParentPath:A,onOpen:()=>{},onOpenFolder:k=>I(k),onContextMenu:()=>{},onDeselect:()=>I("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[u("fileNameLabel"),e.jsx("input",{ref:b,value:c,onChange:k=>v(k.target.value),placeholder:"recovered.md",maxLength:200,disabled:g})]}),D&&e.jsx("div",{className:"mdocs-dialog-error",children:D}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!g&&s(),disabled:g,children:u("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:g,children:u(g?"creating":"create")})]})]})]})})}function ta({onPublish:a,onClose:s,onCountChange:p,onRecover:u}){const{t:y}=ce(),[R,f]=t.useState([]),[S,N]=t.useState(new Set),[h,w]=t.useState(!1),[A,I]=t.useState(null),[c,v]=t.useState(null),[g,x]=t.useState(null),D=t.useRef(null),L=t.useRef(!0);t.useEffect(()=>(L.current=!0,Ue().then(d=>{if(!L.current)return;const j=d.filter(T=>!T.published);f(j),p==null||p(j.length)}),()=>{L.current=!1,D.current&&(clearTimeout(D.current),D.current=null)}),[]),t.useEffect(()=>{const d=j=>{j.key==="Escape"&&s()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[s]);const b=t.useCallback((d,j)=>{x({message:d,type:j}),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>x(null),3e3)},[]);async function B(d){await Ws(d),N(j=>new Set(j).add(d));try{await a(d),f(j=>{const T=j.filter($=>$.documentId!==d);return p==null||p(T.length),T}),b(y("published"),"success")}catch(j){j instanceof qs||b(y("publishFailed"),"error");const T=await Gs(d);T&&f($=>$.map(_=>_.documentId===d?T:_))}finally{N(j=>{const T=new Set(j);return T.delete(d),T})}}async function K(d){I(null),await Xe(d),f(j=>{const T=j.filter($=>$.documentId!==d);return p==null||p(T.length),T}),b(y("draftDeleted"),"success")}function z(d){const j=R.find(T=>T.documentId===d);j&&v(j)}function k(d){v(null),Xe(d),f(j=>{const T=j.filter($=>$.documentId!==d);return p==null||p(T.length),T}),u==null||u(R.find(j=>j.documentId===d)),b(y("published"),"success")}async function E(){w(!0);let d=0,j=0;for(const _ of R)try{await a(_.documentId),d++}catch{j++}const $=(await Ue()).filter(_=>!_.published);f($),p==null||p($.length),j===0?b(y("publishAll"),"success"):b(`${d} published, ${j} failed`,"error"),w(!1)}const C=d=>new Date(d).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),F=d=>_s(y,d,d.publishError??"UNKNOWN"),m=R;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:[y("unpublishedDrafts"),m.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:m.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:y("draftCount",{count:String(m.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":y("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:m.length===0?e.jsxs("div",{className:"mdocs-drawer-empty",children:[e.jsx("div",{className:"mdocs-drawer-empty-icon","aria-hidden":"true",children:"✓"}),e.jsx("p",{className:"mdocs-drawer-empty-text",children:y("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:m.map(d=>{const j=!!d.publishError;return e.jsxs("div",{className:j?"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:d.displayName||y("unknownTitle")}),j?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[C(d.publishErrorAt)," · ",F(d)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[C(d.updatedAt)," · ",y("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[j?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:h,onClick:()=>z(d.documentId),children:y("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:S.has(d.documentId)||h,onClick:()=>void B(d.documentId),children:S.has(d.documentId)?y("publishing"):y("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:h,onClick:()=>I(d.documentId),children:y("delete")})]})]},d.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:y("close")}),e.jsx("button",{type:"button",className:"primary",disabled:m.length===0||h,onClick:()=>void E(),children:h?y("publishing"):`${y("publishAll")} (${m.length})`})]}),g&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+g.type,role:"status",children:g.message})]}),A&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:d=>{d.target===d.currentTarget&&I(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:y("delete")}),e.jsx("p",{className:"muted",children:y("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>I(null),children:y("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void K(A),children:y("delete")})]})]})}),c&&e.jsx(sa,{draft:c,onClose:()=>v(null),onSuccess:()=>k(c.documentId)})]})}function aa(){const{t:a,lang:s}=ce(),p=us(),u=t.useRef(!1),[y,R]=t.useState([]),[f,S]=t.useState(!1),[N,h]=t.useState(""),[w,A]=t.useState("restricted"),[I,c]=t.useState(!1),[v,g]=t.useState(null),[x,D]=t.useState(null),[L,b]=t.useState(""),[B,K]=t.useState(""),[z,k]=t.useState("all"),[E,C]=t.useState(null);t.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]);const F=t.useCallback(async()=>{S(!0),g(null);try{const i=await hs();if(!u.current)return;R(i)}catch(i){if(!u.current)return;g(ee(a,i))}finally{u.current&&S(!1)}},[a]);t.useEffect(()=>{F()},[F]);async function m(i){if(i.preventDefault(),!N.trim()){g(a("domainNameRequired"));return}c(!0),g(null);try{if(await Ys({domainName:N.trim(),permission:w}),!u.current)return;h(""),A("restricted"),await F()}catch(r){if(!u.current)return;g(ee(a,r))}finally{u.current&&c(!1)}}async function d(i){if(L.trim()){g(null);try{if(await Qs(i,L.trim()),!u.current)return;D(null),C(null),await F()}catch(r){if(!u.current)return;g(ee(a,r))}}}function j(i){D(i.domainId),b(i.domainName),C(null)}function T(){D(null),C(null)}async function $(i,r){g(null);try{if(await Zs(i,r),!u.current)return;C(null),await F()}catch(O){if(!u.current)return;g(ee(a,O))}}async function _(i){if(window.confirm(a("deleteDomainConfirmDetail",{name:i.domainName,count:String(i.docCount)}))){g(null);try{if(await Js(i.domainId),!u.current)return;await F()}catch(r){if(!u.current)return;g(ee(a,r))}}}const Q=t.useCallback(i=>Hs(i,a),[a]),Z=t.useCallback(i=>re(i.domainName,s,a),[s,a]),Y=t.useMemo(()=>{const i=B.trim().toLowerCase();return y.filter(r=>z!=="all"&&r.permission!==z?!1:i?re(r.domainName,s,a).toLowerCase().includes(i)||r.domainName.toLowerCase().includes(i):!0)},[y,B,z,s,a]),G=t.useCallback((i,r)=>{const O=Q(i.permission);return r?`${O} ${a("domainTypeBuiltinSuffix")}`:O},[Q,a]);return{domains:y,loadingDomains:f,domainError:v,newDomainName:N,setNewDomainName:h,newDomainPermission:w,setNewDomainPermission:A,creating:I,handleCreateDomain:m,renamingId:x,setRenamingId:D,renameDraft:L,setRenameDraft:b,startRename:j,cancelRename:T,handleRename:d,changeTypeForId:E,setChangeTypeForId:C,handlePermissionChange:$,handleDelete:_,domainSearch:B,setDomainSearch:K,domainFilter:z,setDomainFilter:k,filteredDomains:Y,visitorId:p,plabel:Q,localizeDomain:Z,domainTypeLabel:G}}const ns={private:0,restricted:1,public:2};function is(a){return Object.prototype.hasOwnProperty.call(ns,a)?ns[a]:null}function cs(a,s){const p=is(a),u=is(s);return p===null||u===null?"invalid":u>p?"upgrade":u<p?"downgrade":"same"}function na(){const{t:a}=ce(),s=aa(),[p,u]=t.useState([]),[y,R]=t.useState(null),[f,S]=t.useState(""),N=t.useRef(null),[h,w]=t.useState(null),A=t.useCallback(async()=>{try{const c=await ps();u(c)}catch{u([])}},[]);t.useEffect(()=>{A()},[A]),t.useEffect(()=>{if(!s.changeTypeForId)return;const c=v=>{var g;(g=N.current)!=null&&g.contains(v.target)||s.setChangeTypeForId(null)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s.changeTypeForId,s.setChangeTypeForId]);async function I(c){R(null);try{const v=await nt(c.domainId);w({domainId:c.domainId,creatorVisitorId:c.creatorVisitorId,initialIds:v.map(g=>g.visitorId),memberRows:v})}catch(v){R({kind:"err",text:translateError(a,v)})}}return e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:a("domainManagement")})}),e.jsx("p",{className:"mdocs-domain-mgmt-restricted-hint",children:a("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:a("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:a("domainName")}),e.jsx("input",{value:s.newDomainName,onChange:c=>s.setNewDomainName(c.target.value),placeholder:a("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:a("domainPermission")}),e.jsx("div",{className:"mdocs-domain-mgmt-type-radios",children:Be.map(c=>e.jsxs("label",{className:"mdocs-domain-mgmt-radio",children:[e.jsx("input",{type:"radio",name:"newDomainPermission",checked:s.newDomainPermission===c,onChange:()=>s.setNewDomainPermission(c),disabled:s.creating}),e.jsx("span",{children:s.plabel(c)})]},c))})]}),e.jsx("button",{type:"submit",className:"primary mdocs-domain-mgmt-submit",disabled:s.creating,children:s.creating?a("creating"):a("create")})]})]}),y&&e.jsx("div",{className:"mdocs-settings-card",style:{color:y.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:y.text})}),s.domainError&&e.jsx("div",{className:"mdocs-settings-card mdocs-domain-error",children:e.jsx("span",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)"},children:s.domainError})}),e.jsxs("div",{className:"mdocs-settings-card mdocs-domain-mgmt-toolbar",children:[e.jsx("input",{type:"search",value:s.domainSearch,onChange:c=>s.setDomainSearch(c.target.value),placeholder:a("domainSearchPlaceholder"),className:"mdocs-domain-mgmt-search","aria-label":a("domainSearchPlaceholder")}),e.jsx("div",{className:"mdocs-domain-mgmt-filters",role:"group","aria-label":a("domainPermission"),children:["all",...Be].map(c=>e.jsx("button",{type:"button",className:"mdocs-domain-mgmt-filter"+(s.domainFilter===c?" active":""),"aria-pressed":s.domainFilter===c,onClick:()=>s.setDomainFilter(c),children:c==="all"?a("domainFilterAll"):s.plabel(c)},c))})]}),s.loadingDomains?e.jsx("div",{className:"mdocs-settings-card",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:a("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:a("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:a("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:a("domainColName")}),e.jsx("th",{scope:"col",children:a("domainColType")}),e.jsx("th",{scope:"col",className:"mdocs-domain-table-num",children:a("domainColDocCount")}),e.jsx("th",{scope:"col",children:a("domainColActions")})]})}),e.jsx("tbody",{children:s.filteredDomains.map(c=>{const v=Xs(c,s.visitorId),g=et(c.domainId),x=st(c),D=cs(c.permission,"public")==="upgrade",L=D?x?a("domainTooltipTypeLocked"):void 0:a("domainPermissionAlreadyTop");return e.jsxs("tr",{className:g?"mdocs-domain-table-row-builtin":void 0,children:[e.jsx("td",{children:s.renamingId===c.domainId?e.jsxs("div",{className:"mdocs-domain-table-rename",children:[e.jsx("input",{value:s.renameDraft,onChange:b=>s.setRenameDraft(b.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(c.domainId),children:a("save")}),e.jsx("button",{type:"button",onClick:s.cancelRename,children:a("cancel")})]}):e.jsxs("div",{className:"mdocs-domain-table-name-cell",children:[e.jsx("span",{className:"mdocs-domain-table-name",children:s.localizeDomain(c)}),g&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:a("domainBuiltIn")}),!v&&!g&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:a("shared")})]})}),e.jsx("td",{children:e.jsx("span",{className:"mdocs-domain-table-type",title:L,children:e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":c.permission,children:s.domainTypeLabel(c,g)})})}),e.jsx("td",{className:"mdocs-domain-table-num",children:c.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[g&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:a("domainNotModifiable")}),!g&&!v&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:a("domainNotCreator")}),!g&&v&&s.changeTypeForId===c.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",ref:N,children:[e.jsx("div",{className:"mdocs-domain-type-segment",role:"radiogroup","aria-label":a("domainChangeType"),children:Be.map(b=>{const K=cs(c.permission,b)==="downgrade";return e.jsx("span",{title:K?a("domainPermissionNoDowngrade"):void 0,children:e.jsx("button",{type:"button",role:"radio","aria-checked":f===b,className:f===b?"active":"",disabled:K,onClick:()=>S(b),children:s.plabel(b)})},b)})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon confirm","aria-label":a("save"),disabled:f===""||f===c.permission,onClick:()=>{f&&f!==c.permission&&s.handlePermissionChange(c.domainId,f)},children:e.jsx(Ot,{size:14,strokeWidth:2.5})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon cancel","aria-label":a("cancel"),onClick:()=>s.setChangeTypeForId(null),children:e.jsx(tt,{size:14,strokeWidth:2.5})})]}),!g&&v&&s.renamingId!==c.domainId&&s.changeTypeForId!==c.domainId&&e.jsxs("div",{className:"mdocs-domain-action-buttons",children:[c.permission==="restricted"&&e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--primary",onClick:()=>void I(c),children:a("domainMembersManageButton")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:x?a("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(c)},disabled:x,children:a("rename")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:L,onClick:()=>{s.setRenamingId(null),S(c.permission),s.setChangeTypeForId(c.domainId)},disabled:!D,children:a("domainChangeType")}),e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--danger",title:x?a("domainLocked"):void 0,onClick:()=>void s.handleDelete(c),disabled:x,children:a("deleteDomain")})]})]})]},c.domainId)})})]})})]}),e.jsx(ys,{open:h!==null,title:a("domainMembersPickerTitle"),initialSelectedIds:(h==null?void 0:h.initialIds)??[],lockedIds:h?[h.creatorVisitorId]:[],seedMembers:h==null?void 0:h.memberRows,templates:p,onClose:()=>w(null),onConfirm:async c=>{h&&(await at(h.domainId,c),R({kind:"ok",text:a("domainMembersSaved",{count:String(c.length)})}))}})]})}function ls(a){return a.length<=6?a:`${a.slice(0,6)}…`}function ia(){const{t:a}=ce(),s=t.useRef(!0),[p,u]=t.useState([]),[y,R]=t.useState(!0),[f,S]=t.useState(null),[N,h]=t.useState(1),[w,A]=t.useState(null),[I,c]=t.useState(""),[v,g]=t.useState([]),[x,D]=t.useState(!1),[L,b]=t.useState(null),[B,K]=t.useState(!1),z=us(),[k,E]=t.useState([]),[C,F]=t.useState("idle"),[m,d]=t.useState("");t.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),t.useEffect(()=>{F("loading"),gs().then(o=>{s.current&&(E(o),F("ok"))}).catch(()=>{s.current&&F("err")})},[]);const j=t.useMemo(()=>{const o=new Map;for(const P of k)o.set(P.visitorId,P.visitorName);return o},[k]),T=t.useCallback(async()=>{R(!0),b(null);try{const o=await ps();s.current&&u(o)}catch(o){s.current&&b(ee(a,o))}finally{s.current&&R(!1)}},[a]);t.useEffect(()=>{T()},[T]);const $=t.useMemo(()=>v.map(o=>{const P=k.find(W=>W.visitorId===o);return{visitorId:o,name:P?P.visitorName:a("visitorPickerUnknownVisitor"),muted:!P}}),[v,k,a]);function _(o){g(P=>P.includes(o)?P.filter(W=>W!==o):[...P,o])}const Q=N===1?I.trim().length>0:N===2?v.length>0:!0;function Z(){if(!(N>=3)){if(!Q){K(!0);return}K(!1),h(N+1),d("")}}function Y(){N<=1||(K(!1),h(N-1))}function G(){S(null),A(null),c(""),g(z?[z]:[]),b(null),h(1),d(""),K(!1)}function i(o){S(null),A(o.id),c(o.displayName);const P=z&&!o.visitorIds.includes(z)?[...o.visitorIds,z]:[...o.visitorIds];g(P),b(null),h(1),d(""),K(!1)}async function r(){if(!(!I.trim()||v.length===0)){D(!0),b(null);try{if(w===null?await it({displayName:I.trim(),visitorIds:v}):await ct(w,{displayName:I.trim(),visitorIds:v}),!s.current)return;G(),await T()}catch(o){if(!s.current)return;b(ee(a,o))}finally{s.current&&D(!1)}}}async function O(o){D(!0),b(null);try{if(await lt(o),!s.current)return;S(null),w===o&&G(),await T()}catch(P){if(!s.current)return;b(ee(a,P))}finally{s.current&&D(!1)}}const V=[{key:1,label:a("memberTemplateStepName")},{key:2,label:a("memberTemplateStepMembers")},{key:3,label:a("memberTemplateStepSave")}],U=`${(N-1)/2*100}%`;return e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:a(w!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),w!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:G,style:{fontSize:12},children:a("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:U}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:V.map(o=>{const P=N===o.key,W=N>o.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${P?" current":""}${W?" done":""}`,children:W?"✓":o.key}),e.jsx("span",{className:`mdocs-wizard-step-label${P?" current":""}${W?" done":""}`,children:o.label})]},o.key)})})]}),L&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:L}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[N===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:I,onChange:o=>c(o.target.value),placeholder:a("memberTemplateNamePlaceholder"),maxLength:200,disabled:x,autoFocus:!0,"aria-invalid":B&&!I.trim()}),B&&!I.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:a("domainNameRequired")})]}),N===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(Bt,{visitors:k,loadState:C,searchFilter:m,onSearchChange:d,selectedIds:new Set(v),onToggle:_,selectedRows:$,myVisitorId:z}),e.jsx("p",{className:`mdocs-wizard-hint${B&&v.length===0?" danger":""}`,children:"💡 "+a("memberTemplateStep2Hint")})]}),N===3&&e.jsx("div",{className:"mdocs-wizard-step-content",children:e.jsxs("div",{className:"mdocs-wizard-preview-card",children:[e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:a("memberTemplateNameLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:I})]}),e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:a("memberTemplateIdsLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:a("memberTemplateSelectedSummary",{count:String(v.length)})})]}),v.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[v.slice(0,15).map(o=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:ls(o)},o)),v.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",v.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:Y,children:["← ",a("memberTemplateWizardBack")]}),N<3?e.jsxs("button",{type:"button",className:"primary",onClick:Z,children:[a("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void r(),children:a(x?"saving":w===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:a("memberTemplateSavedList")}),y?e.jsx("span",{className:"mdocs-settings-item-desc",children:a("loading")}):p.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:a("memberTemplateEmpty")}),w===null&&e.jsx("button",{type:"button",className:"primary",onClick:G,children:a("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:p.map(o=>e.jsx("li",{className:"mdocs-member-template-row",children:f===o.id?e.jsxs("div",{className:"mdocs-member-template-confirm-row",children:[e.jsx("span",{className:"mdocs-member-template-confirm-text",children:a("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(o.id),children:a(x?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>S(null),children:a("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:a("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(P=>e.jsx("span",{className:"mdocs-member-template-tag",children:j.get(P)??ls(P)},P))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>i(o),children:a("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>S(o.id),children:a("memberTemplateDelete")})]})]})},o.id))})]})]})]})}const ca=[{value:"deepseek-flash",label:"deepseek-flash(V4.1 Flash)"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro(将路由至 Flash)"}],la=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function oa(a,s,p){return a==="deepseek"?"Deepseek":s||p}function os(a){return`${oa(a.kind,a.providerId,a.name)} · ${a.modelId} · ${a.name}`}function ra(){const{t:a}=ce(),s=t.useRef(!0),[p,u]=t.useState(""),[y,R]=t.useState([]),[f,S]=t.useState(null),[N,h]=t.useState(null),[w,A]=t.useState("deepseek"),[I,c]=t.useState(""),[v,g]=t.useState(""),[x,D]=t.useState(""),[L,b]=t.useState("openai-completions"),[B,K]=t.useState("deepseek-flash"),[z,k]=t.useState(1e6),[E,C]=t.useState(""),[F,m]=t.useState(!1),[d,j]=t.useState(null),[T,$]=t.useState(!1),[_,Q]=t.useState(!0),[Z,Y]=t.useState(!1),[G,i]=t.useState(null),[r,O]=t.useState(!1),[V,U]=t.useState(!1),[o,P]=t.useState(!1),[W,se]=t.useState(null),[ae,ne]=t.useState(null),te=t.useRef(!1);t.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]);const le=t.useCallback(async()=>{const l=await ot();if(s.current)return R(l),l},[]);function ie(){h(null),A("deepseek"),c(""),g(""),D(""),b("openai-completions"),K("deepseek-flash"),k(1e6),C(""),m(!1),j(null),$(!1),U(!1),P(!1),i(null),O(!1)}function ye(l){h(l.id),A(l.kind),c(l.name),g(l.providerId??""),D(l.baseUrl),b(l.apiType);const J=l.modelId.trim(),Ne=new Set(["deepseek-flash","deepseek-v4-flash","deepseek-v4-flash-vision-exp","deepseek-v4.1-flash","deepseek-v4.1-flash-expires-on-0910"]);K(l.kind==="deepseek"?J==="deepseek-v4-pro"?"deepseek-v4-pro":Ne.has(J)?"deepseek-flash":J||"deepseek-flash":J),k(l.contextWindow||1e6),m(l.hasApiKey),j(l.apiKeyMasked),C(""),$(l.isDefault)}t.useEffect(()=>{(async()=>{try{const l=await rt();if(!s.current)return;u(l.visitorName);const J=await le();if(!s.current||!J)return;J.length===0&&(ie(),S("create"))}catch(l){if(!s.current)return;i(l instanceof Error?l.message:String(l)),S("create")}finally{s.current&&Q(!1)}})()},[le]);function be(){ie(),S("create")}function Ie(l){ye(l),S("edit"),O(!1),i(null)}function ue(){ie(),S(null)}async function Te(l){if(!(l.isDefault||ae)){ne(l.id),i(null);try{await dt(l.id),await le()}catch(J){if(!s.current)return;i(J instanceof Error?J.message:String(J))}finally{s.current&&ne(null)}}}async function je(){if(W){Y(!0),i(null);try{await ut(W.id);const l=await le();if(!s.current)return;f==="edit"&&N===W.id&&ue(),((l==null?void 0:l.length)??0)===0&&(ie(),S("create"))}catch(l){if(!s.current)return;i(l instanceof Error?l.message:String(l))}finally{s.current&&(Y(!1),se(null))}}}async function de(){Y(!0),i(null),O(!1);try{const l=w==="custom"?{...f==="edit"&&N?{id:N}:{},...f==="create"&&T?{isDefault:!0}:{},kind:w,baseUrl:x,modelId:B,providerId:v.trim()||void 0,apiType:L,name:I,contextWindow:z,...E.trim()?{apiKey:E.trim()}:{}}:{...f==="edit"&&N?{id:N}:{},...f==="create"&&T?{isDefault:!0}:{},kind:w,modelId:B,name:I,contextWindow:z,...E.trim()?{apiKey:E.trim()}:{}};if(await mt(l),!s.current)return;await le(),O(!0),S(null),ie()}catch(l){if(!s.current)return;i(l instanceof Error?l.message:String(l))}finally{s.current&&Y(!1)}}const Ae=f!==null;return e.jsxs("div",{className:"mdocs-agent-config-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:a("agentConfig")}),_?null:e.jsx("button",{type:"button",className:"secondary",onClick:be,children:"添加配置"})]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[!_&&y.length>0?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:"选择默认配置后,智能助手与帮写将使用该模型。"}),e.jsx("ul",{className:"mdocs-agent-config-list",children:y.map(l=>e.jsxs("li",{className:"mdocs-agent-config-item",children:[e.jsxs("label",{className:"mdocs-agent-config-item-default",children:[e.jsx("input",{type:"radio",name:"agent-default-config",checked:l.isDefault,disabled:ae!==null,onChange:()=>void Te(l)}),e.jsx("span",{children:l.isDefault?"默认":"设为默认"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-main",children:[e.jsx("strong",{children:os(l)}),l.kind==="custom"?e.jsx("span",{className:"mdocs-agent-badge",children:"自定义"}):null,e.jsx("p",{className:"mdocs-agent-config-item-meta",children:l.hasApiKey?`Key ${l.apiKeyMasked??"已配置"}`:"未配置 Key"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>Ie(l),children:a("edit")}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>se(l),children:"删除"})]})]},l.id))}),r?e.jsx("p",{className:"mdocs-agent-config-ok",children:a("saved")}):null,G?e.jsx("p",{className:"mdocs-agent-config-error",children:G}):null]}):null,Ae?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsxs("p",{className:"mdocs-agent-config-lead",children:[f==="create"?"新建模型配置。":"编辑模型配置。","可以保存多套,勾选一条作为默认。智能助手和帮写使用默认那套。"]}),e.jsxs("div",{className:"mdocs-agent-form",children:[e.jsxs("div",{className:"mdocs-agent-kind-tabs",role:"tablist","aria-label":"配置方式",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":w==="deepseek",className:w==="deepseek"?"active":"",onClick:()=>A("deepseek"),children:"Deepseek"}),e.jsx("button",{type:"button",role:"tab","aria-selected":w==="custom",className:w==="custom"?"active":"",onClick:()=>A("custom"),children:"自定义"})]}),w==="deepseek"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigModel")}),e.jsx(ss,{options:[...ca],value:B,onChange:K})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:V?"text":"password",value:E,onChange:l=>C(l.target.value),placeholder:F?a("agentConfigApiKeyConfigured").replace("{{masked}}",d??"…"):a("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":a(V?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>U(l=>!l),children:V?"隐藏":"显示"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 地址"}),e.jsx("input",{type:"url",value:x,onChange:l=>{const J=l.target.value;if(D(J),te.current)return;J.toLowerCase().includes("anthropic")?b("anthropic-messages"):b("openai-completions")},placeholder:"https://api.example.com/v1",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Model ID"}),e.jsx("input",{type:"text",value:B,onChange:l=>K(l.target.value),placeholder:"模型名称,如 gpt-4o",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:V?"text":"password",value:E,onChange:l=>C(l.target.value),placeholder:F?a("agentConfigApiKeyConfigured").replace("{{masked}}",d??"…"):"粘贴 API Key",autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":a(V?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>U(l=>!l),children:V?"隐藏":"显示"})]})]})]}),e.jsxs("details",{className:"mdocs-agent-advanced",open:o,onToggle:l=>P(l.target.open),children:[e.jsx("summary",{children:"高级选项"}),w==="custom"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Provider ID(选填)"}),e.jsx("input",{type:"text",value:v,onChange:l=>g(l.target.value),placeholder:"不填则自动从 API 地址提取域名"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 协议"}),e.jsx(ss,{options:[...la],value:L,onChange:l=>{te.current=!0,b(l)}})]})]}):null,e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigName")}),e.jsx("input",{type:"text",value:I,onChange:l=>c(l.target.value),placeholder:a("agentConfigNameDefault").replace("{{name}}",p||"…")})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigContextWindow")}),e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:z,onChange:l=>k(Number(l.target.value)||1e6)}),e.jsx("p",{className:"mdocs-agent-field-hint",children:a("agentConfigContextWindowDesc")})]})]}),f==="create"&&y.length>0?e.jsxs("label",{className:"mdocs-agent-config-default-check",children:[e.jsx("input",{type:"checkbox",checked:T,onChange:l=>$(l.target.checked)}),e.jsx("span",{children:"保存后设为默认配置"})]}):null,G?e.jsx("p",{className:"mdocs-agent-config-error",children:G}):null,e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void de(),disabled:Z,children:a(Z?"saving":"save")}),y.length>0?e.jsx("button",{type:"button",className:"secondary",onClick:ue,disabled:Z,children:a("cancel")}):null]})]})]}):_?e.jsx("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:e.jsx("p",{className:"mdocs-agent-config-muted",children:a("loading")})}):null]}),W?e.jsx(fs,{title:"删除配置",message:`确定删除「${os(W)}」?${W.isDefault&&y.length>1?" 删除后将自动把另一条设为默认。":""}`,confirmLabel:"删除",cancelLabel:a("cancel"),onConfirm:()=>void je(),onCancel:()=>se(null)}):null]})}const da=/^[A-Za-z0-9_]+$/;function Oe(a){return da.test(a.trim())}function ma(){const a=t.useRef(!0),[s,p]=t.useState([]),[u,y]=t.useState(!0),[R,f]=t.useState(null),[S,N]=t.useState(null),[h,w]=t.useState(!1),[A,I]=t.useState(""),[c,v]=t.useState(""),[g,x]=t.useState(""),[D,L]=t.useState(!1);t.useEffect(()=>(a.current=!0,()=>{a.current=!1}),[]);async function b(){y(!0),f(null);try{const m=await ht();if(!a.current)return;p(m)}catch(m){if(!a.current)return;f(m instanceof Error?m.message:String(m))}finally{a.current&&y(!1)}}t.useEffect(()=>{b()},[]);function B(){w(!0),N(null),I(""),v(""),x(""),f(null)}function K(m){w(!1),N(m.id),I(m.name),v(m.description),x(m.body),f(null)}function z(){w(!1),N(null),I(""),v(""),x("")}async function k(){const m=A.trim();if(!Oe(m)){f("名称仅允许英文、数字、下划线");return}if(!g.trim()){f("正文不能为空");return}L(!0),f(null);try{if(h?await pt({name:m,description:c,body:g}):S&&await gt(S,{name:m,description:c,body:g}),!a.current)return;z(),await b()}catch(d){if(!a.current)return;f(d instanceof Error?d.message:String(d))}finally{a.current&&L(!1)}}async function E(m){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){f(null);try{if(await ft(m),!a.current)return;S===m&&z(),await b()}catch(d){if(!a.current)return;f(d instanceof Error?d.message:String(d))}}}const C=h||S!==null,F=!A.trim()||Oe(A);return e.jsxs("div",{className:"mdocs-agent-skills-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title",children:["Agent Skills",!u&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),C?null:e.jsx("button",{type:"button",className:"secondary",onClick:B,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:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),R?e.jsx("p",{className:"mdocs-agent-skills-error",children:R}):null,C?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:h?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:A,onChange:m=>I(m.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:F?void 0:"mdocs-agent-skills-input-invalid"}),F?e.jsx("span",{className:"mdocs-agent-skills-hint",children:"引用与索引键,保存后按此名称使用"}):e.jsx("span",{className:"mdocs-agent-skills-hint-bad",children:"仅允许 A–Z、a–z、0–9、_"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"简介(可选)"}),e.jsx("input",{type:"text",value:c,onChange:m=>v(m.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:g,onChange:m=>x(m.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void k(),disabled:D||!F||!A.trim()||!g.trim(),children:D?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:z,disabled:D,children:"取消"})]})]}):null,u?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!u&&s.length===0&&!C?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:B,children:"新建第一个"})]}):null,!u&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(m=>{const d=Oe(m.name),j=S===m.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(j?" mdocs-agent-skills-item-active":""),children:[e.jsxs("div",{className:"mdocs-agent-skills-item-main",children:[e.jsxs("div",{className:"mdocs-agent-skills-item-title-row",children:[e.jsx("code",{className:"mdocs-agent-skills-name",children:m.name}),d?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:m.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>K(m),disabled:C&&!j,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void E(m.id),disabled:C,children:"删除"})]})]},m.id)})}):null]})})]})}const ua={algorithm:$t.defaultAlgorithm,token:{colorPrimary:"#4CAF50",colorLink:"#4CAF50",colorInfo:"#4CAF50",colorSuccess:"#66BB6A",colorBgBase:"#ffffff",colorBgContainer:"#ffffff",colorText:"#212121",colorTextSecondary:"#616161",colorBorder:"#E0E0E0",colorFillSecondary:"#E8F5E9",borderRadius:8,fontFamily:"inherit"},components:{Table:{headerBg:"#F5F5F5",headerColor:"#212121",rowHoverBg:"#E8F5E9",borderColor:"#E0E0E0"},Button:{primaryShadow:"none"},Tag:{defaultBg:"#F5F5F5",defaultColor:"#616161"}}};function rs(a,s){if(!a)return"—";const p=new Date(a);return Number.isNaN(p.getTime())?"—":p.toLocaleString(s==="zh"?"zh-CN":"en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function ha(a){const{t:s,lang:p}=ce(),[u,y]=t.useState(!1),[R,f]=t.useState(!1),[S,N]=t.useState(!1),[h,w]=t.useState([]),[A,I]=t.useState([]),[c,v]=t.useState(null),[g,x]=t.useState(null),[D,L]=t.useState(""),[b,B]=t.useState("keyword"),[K,z]=t.useState(null),[k,E]=t.useState(!1),C=t.useRef(0),[F,m]=t.useState({current:1,pageSize:20}),[d,j]=t.useState(0);async function T(){y(!0),x(null);try{const i=await xt();N(i.modelReady),w(i.items),I([]),j(i.items.length),m(r=>({...r,current:1}))}catch(i){x(ee(s,i)||s("embeddingIndexLoadFailed"))}finally{y(!1)}}t.useEffect(()=>{T()},[]);const $=t.useMemo(()=>{const i=new Map;for(const r of h)i.has(r.domainId)||i.set(r.domainId,re(r.domainName,p,s));return Array.from(i.entries()).map(([r,O])=>({text:O,value:r}))},[h,p,s]),_=t.useMemo(()=>{const i=D.trim().toLowerCase();return i?h.filter(r=>(r.displayName||"").toLowerCase().includes(i)||(r.relativePath||"").toLowerCase().includes(i)||r.documentId.toLowerCase().includes(i)):h},[h,D]),Q=b==="semantic"&&!!D.trim();t.useEffect(()=>{if(b!=="semantic")return;const i=D.trim();if(!i){C.current+=1,z(null);return}const r=++C.current;E(!0);const O=window.setTimeout(()=>{(async()=>{try{const V=await xs({query:i,mode:"semantic",topN:50});if(r!==C.current)return;const U=new Map(h.map(o=>[o.documentId,o]));z(V.results.map(o=>{const P=U.get(o.documentId);return P?{...P,snippet:o.snippet}:{documentId:o.documentId,displayName:o.displayName,relativePath:o.relativePath,domainId:o.domainId,domainName:o.domainId,documentUpdatedAt:o.updatedAt,chunkCount:0,chunkUnknown:!0,embeddingUpdatedAt:null,snippet:o.snippet}}))}catch{r===C.current&&z([])}finally{r===C.current&&E(!1)}})()},300);return()=>window.clearTimeout(O)},[b,D,h]);const Z=Q?K??[]:_;t.useEffect(()=>{j(Z.length),m(i=>({...i,current:1}))},[Z.length,b]);const Y=t.useMemo(()=>[{title:s("myDocumentsColTitle"),dataIndex:"displayName",key:"displayName",ellipsis:!0,sorter:(i,r)=>(i.displayName||i.relativePath).localeCompare(r.displayName||r.relativePath,p==="zh"?"zh":"en"),render:(i,r)=>e.jsxs("div",{style:{minWidth:0},children:[e.jsx("button",{type:"button",className:"mdocs-linkish",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontWeight:500,color:"inherit",textAlign:"left"},onClick:()=>a.onOpenDocument(r.documentId),children:r.displayName||r.relativePath||"Untitled"}),r.snippet&&e.jsx("div",{className:"mdocs-embedding-index-snippet",title:r.snippet,children:r.snippet})]})},{title:s("myDocumentsColDomain"),dataIndex:"domainId",key:"domainId",width:160,ellipsis:!0,filters:$,onFilter:(i,r)=>r.domainId===i,sorter:(i,r)=>re(i.domainName,p,s).localeCompare(re(r.domainName,p,s),p==="zh"?"zh":"en"),render:(i,r)=>re(r.domainName,p,s)},{title:s("embeddingIndexColDocUpdated"),dataIndex:"documentUpdatedAt",key:"documentUpdatedAt",width:160,sorter:(i,r)=>new Date(i.documentUpdatedAt).getTime()-new Date(r.documentUpdatedAt).getTime(),defaultSortOrder:"descend",render:i=>rs(i,p)},{title:s("embeddingIndexColStatus"),dataIndex:"chunkCount",key:"buildStatus",width:140,filters:[{text:s("embeddingIndexFilterBuilt"),value:"built"},{text:s("embeddingIndexFilterMissing"),value:"missing"}],onFilter:(i,r)=>i==="built"?r.chunkCount>0:r.chunkCount===0,sorter:(i,r)=>i.chunkCount-r.chunkCount,render:(i,r)=>r.chunkUnknown?e.jsx(Ke,{color:"success",children:s("embeddingIndexStatusBuiltUnknown")}):i>0?e.jsx(Ke,{color:"success",children:s("embeddingIndexStatusReady",{chunks:String(i)})}):e.jsx(Ke,{children:s("embeddingIndexStatusMissing")})},{title:s("embeddingIndexColBuiltAt"),dataIndex:"embeddingUpdatedAt",key:"embeddingUpdatedAt",width:160,sorter:(i,r)=>{const O=i.embeddingUpdatedAt?new Date(i.embeddingUpdatedAt).getTime():0,V=r.embeddingUpdatedAt?new Date(r.embeddingUpdatedAt).getTime():0;return O-V},render:i=>rs(i,p)}],[$,p,a,s]);async function G(){const i=A.map(String);if(i.length!==0){f(!0),v(null),x(null);try{const r=await yt(i);N(r.modelReady),v(s("embeddingIndexRebuildResult",{ok:String(r.ok.length),skipped:String(r.skipped.length),failed:String(r.failed.length)})),await T()}catch(r){x(ee(s,r)||s("embeddingIndexRebuildFailed"))}finally{f(!1)}}}return e.jsx(Ut,{theme:ua,children:e.jsxs("div",{className:"mdocs-settings mdocs-embedding-index",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("embeddingIndex")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"muted",style:{marginTop:0},children:s("embeddingIndexDesc")}),e.jsxs("p",{style:{margin:"0 0 12px",fontSize:13},children:[s("embeddingIndexModel"),":"," ",e.jsx("strong",{children:s(S?"embeddingIndexModelReady":"embeddingIndexModelPending")})]}),e.jsxs(Vt,{wrap:!0,style:{marginBottom:12},children:[e.jsx(_t,{value:b,"aria-label":s("myDocumentsSearchMode"),onChange:i=>B(i),options:[{label:s("myDocumentsModeKeyword"),value:"keyword"},{label:s("myDocumentsModeSemantic"),value:"semantic"}]}),e.jsx(Wt.Search,{allowClear:!0,placeholder:s(b==="semantic"?"embeddingIndexSearchSemanticPlaceholder":"embeddingIndexSearchPlaceholder"),"aria-label":s(b==="semantic"?"embeddingIndexSearchSemanticPlaceholder":"embeddingIndexSearchPlaceholder"),value:D,onChange:i=>L(i.target.value),style:{width:240},disabled:u||R}),e.jsx(ts,{onClick:()=>void T(),disabled:u||R,children:s("embeddingIndexRefresh")}),e.jsx(ts,{type:"primary",onClick:()=>void G(),disabled:R||A.length===0,loading:R,children:s("embeddingIndexRebuildSelected",{count:String(A.length)})})]}),c&&e.jsx("p",{style:{fontSize:13,color:"var(--mdocs-text-muted)"},children:c}),g&&e.jsx("p",{className:"mdocs-doc-search-error",style:{marginBottom:8},children:g}),Q&&!S&&e.jsx("p",{className:"muted",style:{margin:"0 0 8px",fontSize:13},children:s("myDocumentsSemanticNotReady")}),(()=>{const i=Number(F.pageSize)||20,r=Number(F.current)||1,O=d,V=Math.max(1,Math.ceil(O/i)||1);return e.jsx(qt,{size:"small",rowKey:"documentId",loading:u||Q&&k,columns:Y,dataSource:Z,rowSelection:{selectedRowKeys:A,onChange:U=>I(U)},pagination:{current:r,pageSize:i,total:O,showSizeChanger:!1,showQuickJumper:!1,showTotal:(U,o)=>s("embeddingIndexPageTotal",{from:String(o[0]??0),to:String(o[1]??0),total:String(U)})},onChange:(U,o,P,W)=>{const se=U.pageSize??i,ae=W.currentDataSource.length,ne=Math.max(1,Math.ceil(ae/se)||1);let te=U.current??1;te>ne&&(te=ne),j(ae),m({current:te,pageSize:se})},locale:{emptyText:D.trim()?s("myDocumentsNoMatch"):s("embeddingIndexEmpty"),filterReset:s("embeddingIndexFilterReset"),filterConfirm:s("embeddingIndexFilterOk")},scroll:{x:900},footer:()=>e.jsxs("div",{className:"mdocs-embedding-index-pager",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"flex-end",gap:10},children:[e.jsx("span",{style:{fontSize:13},children:s("embeddingIndexPageSize")}),e.jsx(as,{size:"small",min:5,max:200,step:5,value:i,controls:!0,changeOnWheel:!0,disabled:u||R,"aria-label":s("embeddingIndexPageSize"),onChange:U=>{if(U==null||!Number.isFinite(Number(U)))return;const o=Math.min(200,Math.max(5,Math.floor(Number(U))));m({current:1,pageSize:o})}}),e.jsx("span",{style:{fontSize:13},children:s("embeddingIndexGoPage")}),e.jsx(as,{size:"small",min:1,max:V,step:1,value:Math.min(r,V),controls:!0,changeOnWheel:!0,disabled:u||R||O===0,"aria-label":s("embeddingIndexGoPage"),onChange:U=>{if(U==null||!Number.isFinite(Number(U)))return;const o=Math.min(V,Math.max(1,Math.floor(Number(U))));m(P=>({...P,current:o}))}}),e.jsxs("span",{style:{fontSize:13,color:"var(--mdocs-text-muted)"},children:["/ ",V]})]})})})()]})]})})}function ds(a,s){const p=localStorage.getItem(a);return p===null?s:p==="true"}function Ce(a){const s=new Date(a);if(Number.isNaN(s.getTime()))return"—";const p=String(s.getMonth()+1).padStart(2,"0"),u=String(s.getDate()).padStart(2,"0");return`${s.getFullYear()}-${p}-${u}`}const ms=[{id:"general",labelKey:"general",keywords:["设置","语言","settings","language"],Icon:Nt},{id:"bookmarks",labelKey:"bookmarkTitle",keywords:["收藏","bookmark","star"],Icon:vt},{id:"myDocuments",labelKey:"myDocuments",keywords:["文章","文档","documents","articles"],Icon:kt},{id:"embeddingIndex",labelKey:"embeddingIndex",keywords:["语义","索引","embedding","vector","检索"],Icon:Yt},{id:"domainManagement",labelKey:"domainManagement",keywords:["域","工作空间","workspace","domain"],Icon:Zt},{id:"memberTemplates",labelKey:"memberTemplates",keywords:["成员","模板","members","template","邀请"],Icon:Kt},{id:"agentConfig",labelKey:"agentConfig",keywords:["ai","助手","模型","agent","llm","deepseek"],Icon:ea},{id:"savePublish",labelKey:"saveAndPublish",keywords:["草稿","发布","同步","draft","publish","sync"],Icon:Ht}];function Na(a){const{t:s,lang:p,setLang:u}=ce(),{onBack:y,onPublishDraft:R}=a,f=bt(),[S,N]=t.useState(!1);jt(f,()=>N(!0),{open:S,onClose:()=>N(!1)});const h=t.useRef(!0);t.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]),t.useEffect(()=>{f||N(!1)},[f]);const[w,A]=t.useState(()=>ds("mdocs.autoPublish",!1)),[I,c]=t.useState(()=>ds("mdocs.autoEdit",!0)),[v,g]=t.useState(!1),[x,D]=t.useState("general"),[L,b]=t.useState("");function B(n){D(n),f&&N(!1)}const K=t.useMemo(()=>{const n=L.trim().toLowerCase();return n?ms.filter(M=>s(M.labelKey).toLowerCase().includes(n)?!0:M.keywords.some(q=>q.toLowerCase().includes(n))):ms},[L,s]),z=s(x==="general"?"general":x==="bookmarks"?"bookmarkTitle":x==="myDocuments"?"myDocuments":x==="embeddingIndex"?"embeddingIndex":x==="domainManagement"?"domainManagement":x==="memberTemplates"?"memberTemplates":x==="agentConfig"?"agentConfig":"saveAndPublish"),[k,E]=t.useState([]),[C,F]=t.useState(!0),[m,d]=t.useState(null),[j,T]=t.useState(!1),[$,_]=t.useState(!1),[Q,Z]=t.useState(!1),[Y,G]=t.useState(!1),[i,r]=t.useState(null),[O,V]=t.useState(!1),[U,o]=t.useState(!1),[P,W]=t.useState(!1),[se,ae]=t.useState(""),[ne,te]=t.useState(!1),[le,ie]=t.useState(!1),[ye,be]=t.useState(0),[Ie,ue]=t.useState([]),[Te,je]=t.useState(!1),[de,Ae]=t.useState(""),[l,J]=t.useState([]),[Ne,$e]=t.useState(!1),[ve,bs]=t.useState(""),[he,js]=t.useState("auto"),[ke,Me]=t.useState(null),[Ve,Pe]=t.useState(!0),[me,Ns]=t.useState(0),[_e,We]=t.useState("1"),[qe,vs]=t.useState(0),[pe,ks]=t.useState(""),[Ee,Ss]=t.useState(""),[Se,ws]=t.useState(""),[Cs,Ds]=t.useState(null),[Is,Ts]=t.useState([]),we=t.useRef(0),Re=20,ge=ke!==null,[Ge,As]=t.useState([]),[Ms,Fe]=t.useState(!1),[ze,He]=t.useState(null),[Le,Je]=t.useState(new Map);t.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(w))},[w]),t.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(I))},[I]),t.useEffect(()=>{x==="savePublish"&&Ue().then(n=>{h.current&&be(n.filter(M=>!M.published).length)})},[x]),t.useEffect(()=>{x==="bookmarks"&&Ps(),x==="myDocuments"&&(xe(),gs().then(n=>{h.current&&Ts(n)}).catch(()=>{}))},[x,pe,Ee,Se]),t.useEffect(()=>{if(x!=="myDocuments")return;const n=ve.trim();if(!n){we.current+=1,Me(null),Pe(!0);return}const M=++we.current,H=window.setTimeout(()=>{(async()=>{try{const q=await xs({query:n,mode:he,domainId:pe||void 0,topN:50});if(!h.current||M!==we.current)return;Me(q.results),Pe(q.modelReady)}catch{if(!h.current||M!==we.current)return;Me([]),Pe(!0)}})()},300);return()=>window.clearTimeout(H)},[x,ve,he,pe]),t.useEffect(()=>{Ze()},[]),t.useEffect(()=>{hs().then(n=>{h.current&&As(n)}).catch(()=>{})},[]);const fe=new Map(Ge.map(n=>[n.domainId,n.domainName]));async function Ze(){try{F(!0);const n=await St();if(!h.current)return;E(n)}catch{}finally{h.current&&F(!1)}}async function Ps(){try{je(!0);const n=await wt();if(!h.current)return;ue(n)}catch{}finally{h.current&&je(!1)}}async function xe(n=0){try{$e(!0);const M=await Ct({offset:n*Re,limit:Re,domainId:pe||void 0,creatorVisitorId:Ee||void 0,groupBy:Se||void 0});if(!h.current)return;J(M.items),Ds(M.groups??null),vs(M.total),Ns(n),We(String(n+1))}catch{}finally{h.current&&$e(!1)}}async function Es(n){try{await Et(n),ue(M=>M.filter(H=>H.documentId!==n))}catch{}}function Rs(){if(k.some(M=>!M.revoked)){_(!0);return}Qe()}async function Qe(){try{T(!0);const n=await Ft();d({token:n.token,name:n.name}),await Ze()}finally{T(!1)}}async function Fs(){try{W(!0);const n=await Mt();r(n.recoveryCode)}finally{W(!1)}}async function zs(n){n.preventDefault();const M=se.trim();if(!(M&&M.length<4))try{te(!0),await Pt(M),ae(""),ie(!0),setTimeout(()=>ie(!1),3e3)}finally{te(!1)}}async function Ls(n){He(n);try{const M=await Rt(n),H=new Map;M.forEach(q=>{H.set(q.visitorId,q.permission)}),Je(H)}catch{Je(new Map)}Fe(!0)}async function Bs(n){if(ze)try{const M=new Set(n.map(q=>q.visitorId)),H=new Set(Le.keys());for(const q of H)M.has(q)||await zt(ze,q);for(const q of n)await Lt(ze,q.visitorId,q.permission);await xe()}finally{Fe(!1),He(null)}}const Ye=Ie.filter(n=>{if(!de.trim())return!0;const M=de.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(M)||(n.ownerVisitorName||"").toLowerCase().includes(M)||(n.domainId||"").toLowerCase().includes(M)}),oe=Math.ceil(qe/Re);return e.jsxs("div",{className:"mdocs-layout"+(f?" mdocs-layout--reader mdocs-layout--settings":""),children:[f&&S?e.jsx("button",{type:"button",className:"mdocs-mobile-nav-scrim","aria-label":s("collapseSidebar"),onClick:()=>N(!1)}):null,e.jsxs("aside",{className:"mdocs-sidebar"+(f?S?" mdocs-sidebar--drawer-open":" mdocs-sidebar--drawer":""),children:[e.jsxs("header",{className:"mdocs-sidebar-header",children:[e.jsxs("div",{className:"mdocs-brand",children:[e.jsx("img",{src:Dt,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]}),f?e.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:()=>N(!1),"aria-label":s("collapseSidebar"),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(It,{size:18})}):null]}),e.jsx("div",{className:"mdocs-config-nav-search",children:e.jsxs("div",{className:"mdocs-config-nav-search-inner",children:[e.jsx(es,{size:14,strokeWidth:1.75,"aria-hidden":!0}),e.jsx("input",{type:"search",value:L,onChange:n=>b(n.target.value),placeholder:s("settingsNavSearch"),"aria-label":s("settingsNavSearch")})]})}),e.jsx("nav",{className:"mdocs-config-tree",children:K.length===0?e.jsx("div",{className:"mdocs-config-nav-empty",children:s("settingsNavNoMatch")}):K.map(n=>{const M=n.Icon,H=x===n.id;return e.jsxs("div",{className:"mdocs-config-item"+(H?" active":""),onClick:()=>B(n.id),children:[e.jsx(M,{size:16,strokeWidth:1.75,"aria-hidden":!0}),e.jsx("span",{children:s(n.labelKey)})]},n.id)})}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:y,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[f?e.jsxs("div",{className:"mdocs-settings-mobile-bar",children:[e.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>N(!0),"aria-label":s("expandSidebar"),children:e.jsx(Tt,{size:18,strokeWidth:1.75})}),e.jsx("span",{className:"mdocs-settings-mobile-bar-title",children:z})]}):null,At(),x==="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:p==="en"?"active":"",onClick:()=>u("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:p==="zh"?"active":"",onClick:()=>u("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"+(I?" active":""),role:"switch","aria-checked":I,onClick:()=>c(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliToken")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("cliTokenDesc")}),!C&&k.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:k.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:Rs,disabled:j||C,children:j?"…":k.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),m&&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:m.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(m.token),G(!1),Z(!0),window.setTimeout(()=>Z(!1),2e3)}catch{Z(!1),G(!0),window.setTimeout(()=>G(!1),3e3)}})()},children:s(Q?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>d(null),children:s("close")})]}),Q&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),Y&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--err",role:"status",children:s("cliTokenCopyFailed")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",children:"当 Token 丢失时,可用恢复码找回身份。生成后请立即保存,仅显示一次。"})]}),e.jsx("button",{type:"button",className:"secondary",onClick:Fs,disabled:P,children:P?"…":"生成恢复码"})]}),i&&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:i})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(i),o(!1),V(!0),window.setTimeout(()=>V(!1),2e3)}catch{V(!1),o(!0),window.setTimeout(()=>o(!1),3e3)}})()},children:O?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>r(null),children:s("close")})]}),O&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),U&&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:zs,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:se,onChange:n=>ae(n.target.value),minLength:0,style:{marginBottom:8}}),le&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:ne,children:ne?"设置中…":"保存密码"})]})]})]})]}):x==="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:de,onChange:n=>Ae(n.target.value)}),Te?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:Ye.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(de?"bookmarkNoMatch":"bookmarkEmpty")}):e.jsx("div",{className:"mdocs-settings-table-wrap",children:e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("bookmarkColTitle")}),e.jsx("th",{children:s("bookmarkColDomain")}),e.jsx("th",{children:s("bookmarkColAuthor")}),e.jsx("th",{children:s("bookmarkColTime")}),e.jsx("th",{style:{textAlign:"right"}})]})}),e.jsx("tbody",{children:Ye.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>a.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:n.isDeleted?e.jsx("span",{style:{opacity:.5,fontStyle:"italic"},children:"已删除"}):fe.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:()=>Es(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})})]})]}):x==="myDocuments"?e.jsxs("div",{className:"mdocs-settings mdocs-my-docs",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("myDocuments")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-my-docs-toolbar",children:[e.jsxs("div",{className:"mdocs-my-docs-search",children:[e.jsx(es,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("input",{type:"text",placeholder:"搜索文章…",value:ve,onChange:n=>bs(n.target.value)})]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:pe,"aria-label":s("myDocumentsFilterDomain"),onChange:n=>ks(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllDomains")}),Ge.map(n=>e.jsx("option",{value:n.domainId,children:fe.get(n.domainId)||n.domainName},n.domainId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:he,"aria-label":s("myDocumentsSearchMode"),onChange:n=>js(n.target.value),children:[e.jsx("option",{value:"auto",children:s("myDocumentsModeAuto")}),e.jsx("option",{value:"keyword",children:s("myDocumentsModeKeyword")}),e.jsx("option",{value:"semantic",children:s("myDocumentsModeSemantic")})]}),!ge&&e.jsxs("select",{className:"mdocs-my-docs-select",value:Ee,"aria-label":s("myDocumentsFilterCreator"),onChange:n=>Ss(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllCreators")}),Is.map(n=>e.jsx("option",{value:n.visitorId,children:n.visitorName},n.visitorId))]}),!ge&&e.jsxs("select",{className:"mdocs-my-docs-select",value:Se,"aria-label":s("myDocumentsGroupBy"),onChange:n=>ws(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsGroupNone")}),e.jsx("option",{value:"domain",children:s("myDocumentsGroupDomain")}),e.jsx("option",{value:"creator",children:s("myDocumentsGroupCreator")})]})]}),Ne&&!ge?e.jsx("div",{className:"mdocs-my-docs-empty",children:s("loading")}):ge?e.jsx(e.Fragment,{children:ke.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(he==="semantic"&&!Ve?"myDocumentsSemanticNotReady":"myDocumentsNoMatch")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-my-docs-search-meta",children:[s("myDocumentsResultCount",{count:String(ke.length)}),he==="semantic"&&!Ve?` · ${s("myDocumentsSemanticNotReadyShort")}`:""]}),e.jsx("div",{className:"mdocs-settings-table-wrap",children:e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("myDocumentsColTitle")}),e.jsx("th",{children:s("myDocumentsColDomain")}),e.jsx("th",{children:s("myDocumentsColCreator")}),e.jsx("th",{children:s("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{})]})}),e.jsx("tbody",{children:ke.map(n=>e.jsxs("tr",{children:[e.jsx("td",{className:"mdocs-my-docs-title",onClick:()=>a.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:fe.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:n.ownerVisitorName||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Ce(n.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:n.createdAt?Ce(n.createdAt):"—"}),e.jsx("td",{className:"mdocs-my-docs-actions",children:e.jsx("button",{type:"button",className:"primary small",onClick:()=>a.onOpenDocument(n.documentId),children:s("bookmarkOpen")})})]},n.documentId))})]})})]})}):e.jsxs(e.Fragment,{children:[l.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(ve?"myDocumentsNoMatch":"myDocumentsEmpty")}):e.jsx("div",{className:"mdocs-settings-table-wrap",children:e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("myDocumentsColTitle")}),e.jsx("th",{children:s("myDocumentsColDomain")}),e.jsx("th",{children:s("myDocumentsColCreator")}),e.jsx("th",{children:s("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{})]})}),e.jsx("tbody",{children:(Cs??[{key:"",items:l}]).flatMap(n=>{var q;const M=n.key?e.jsx("tr",{className:"mdocs-my-docs-group",children:e.jsx("td",{colSpan:6,children:Se==="domain"?fe.get(n.key)||n.key:((q=n.items[0])==null?void 0:q.creatorName)||n.key})},`group-${n.key}`):null,H=n.items.map(X=>e.jsxs("tr",{children:[e.jsx("td",{className:"mdocs-my-docs-title",onClick:()=>a.onOpenDocument(X.documentId),children:X.displayName||X.relativePath||"Untitled"}),e.jsx("td",{children:fe.get(X.domainId||"")||X.domainId||"—"}),e.jsx("td",{children:X.creatorName||X.creatorVisitorId||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Ce(X.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:Ce(X.createdAt)}),e.jsxs("td",{className:"mdocs-my-docs-actions",children:[e.jsx("button",{type:"button",className:"ghost small",onClick:()=>Ls(X.documentId),children:s("docInfoInviteMember")}),e.jsx("button",{type:"button",className:"primary small",onClick:()=>a.onOpenDocument(X.documentId),children:s("bookmarkOpen")})]})]},X.documentId));return M?[M,...H]:H})})]})}),!ge&&e.jsxs("div",{className:"mdocs-my-docs-footer",children:[e.jsx("span",{className:"mdocs-settings-page-info",children:s("myDocumentsPageInfo",{current:String(oe>0?me+1:0),total:String(oe),count:String(qe)})}),oe>1&&e.jsxs("form",{className:"mdocs-my-docs-jump",onSubmit:n=>{n.preventDefault();const M=Number.parseInt(_e,10);if(!Number.isFinite(M))return;const H=Math.min(Math.max(M,1),oe)-1;H!==me&&xe(H)},children:[e.jsx("span",{children:s("myDocumentsJumpTo")}),e.jsx("input",{type:"number",inputMode:"numeric",min:1,max:oe,"aria-label":s("myDocumentsJumpTo"),value:_e,onChange:n=>We(n.target.value)}),e.jsx("button",{type:"submit",className:"secondary small",children:s("myDocumentsJump")})]}),oe>1&&e.jsxs("div",{className:"mdocs-settings-pagination",children:[e.jsx("button",{type:"button",className:"secondary small",disabled:me<=0,onClick:()=>xe(me-1),children:s("myDocumentsPrev")}),e.jsx("button",{type:"button",className:"secondary small",disabled:me>=oe-1,onClick:()=>xe(me+1),children:s("myDocumentsNext")})]})]})]})]})]}):x==="embeddingIndex"?e.jsx(ha,{onOpenDocument:a.onOpenDocument}):x==="domainManagement"?e.jsx(na,{}):x==="memberTemplates"?e.jsx(ia,{}):x==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(ra,{}),e.jsx(ma,{})]}):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:y,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"+(w?" active":""),role:"switch","aria-checked":w,onClick:()=>A(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),ye>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>g(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",ye,")"]}),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")})})]})]}),v&&e.jsx(ta,{onPublish:R,onClose:()=>g(!1),onCountChange:be,onRecover:a.onRecoverDraft})]}),$&&e.jsx(fs,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:j,onConfirm:()=>{_(!1),Qe()},onCancel:()=>_(!1)}),e.jsx(ys,{open:Ms,title:s("docInfoInviteMember"),initialSelectedIds:[...Le.keys()],initialPermissions:Le,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>Fe(!1),onConfirm:n=>{Bs(n)}})]})}export{Na as SettingsPage};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import{r as l,j as n}from"./react-vendor-BVS1XoFi.js";import{o as p,c as tt,p as Ie,q as nt,t as De,a as st,s as it,e as ot,f as at,g as lt,u as dt,v as T,h as ct,w as ee,S as rt,x as ut,y as mt,z as Ee,A as ht,B as ft,E as xt,F as gt,G as It,H as Me,I as vt,J as bt,K as yt,X as wt,L as kt,M as jt,l as Ct,r as St,i as Nt,j as Dt,O as Et,P as Mt,Q as zt,R as Bt,D as te,k as Pt,m as Rt}from"./index-DAhW-QRN.js";import{D as At,S as Tt}from"./DocChrome-7KIXAHsE.js";import{V as Wt,U as $t}from"./VisitorPickerModal-D4xmZbNY.js";import{P as ve}from"./plus-DkLh2brQ.js";import{B as Lt,I as Vt}from"./italic-cqqPz-_Q.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./file-type-policy-C6Nun42Q.js";/**
|
|
2
|
+
* @license lucide-react v0.562.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const Ft=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]],_t=p("columns-3",Ft);/**
|
|
7
|
+
* @license lucide-react v0.562.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const pt=[["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}],["path",{d:"M12 2v10.3a4 4 0 0 1-1.172 2.872L4 22",key:"1hyw0i"}],["path",{d:"m20 22-5-5",key:"1m27yz"}]],Ot=p("merge",pt);/**
|
|
12
|
+
* @license lucide-react v0.562.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const Ut=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M21 9H3",key:"1338ky"}],["path",{d:"M21 15H3",key:"9uk58r"}]],qt=p("rows-3",Ut);/**
|
|
17
|
+
* @license lucide-react v0.562.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const Kt=[["path",{d:"M8 19H5c-1 0-2-1-2-2V7c0-1 1-2 2-2h3",key:"lubmu8"}],["path",{d:"M16 5h3c1 0 2 1 2 2v10c0 1-1 2-2 2h-3",key:"1ag34g"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]],Ht=p("square-split-horizontal",Kt);/**
|
|
22
|
+
* @license lucide-react v0.562.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const Qt=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],ze=p("trash-2",Qt);function w(t){return`${t.rowId}::${t.colId}`}function Gt(t){let o=t+1,u="";for(;o>0;){const c=(o-1)%26;u=String.fromCharCode(65+c)+u,o=Math.floor((o-1)/26)}return u}function Jt(t,o){const u=t.columns.findIndex(r=>r.id===o.colId),c=t.rows.findIndex(r=>r.id===o.rowId);return u<0||c<0?"":`${Gt(u)}${c+1}`}function Xt(t,o,u,c){return!o||!u||c.size===0?null:o.rowId===u.rowId&&t.columns.length>0&&t.columns.every(m=>c.has(w({rowId:o.rowId,colId:m.id})))?{rowId:o.rowId,colId:t.columns[0].id}:o.colId===u.colId&&t.rows.length>0&&t.rows.every(m=>c.has(w({rowId:m.id,colId:o.colId})))?{rowId:t.rows[0].id,colId:o.colId}:u}function Yt(t,o,u,c){if(!u.has(w(o)))return"mdocs-sheet-td";const r=t.rows.findIndex(y=>y.id===o.rowId),x=t.columns.findIndex(y=>y.id===o.colId),m=["mdocs-sheet-td","is-selected"];if(c&&c.rowId===o.rowId&&c.colId===o.colId&&m.push("is-active"),r<0||x<0)return m.join(" ");const C=r>0?w({rowId:t.rows[r-1].id,colId:o.colId}):null,E=r<t.rows.length-1?w({rowId:t.rows[r+1].id,colId:o.colId}):null,M=x>0?w({rowId:o.rowId,colId:t.columns[x-1].id}):null,A=x<t.columns.length-1?w({rowId:o.rowId,colId:t.columns[x+1].id}):null;return(!C||!u.has(C))&&m.push("sel-t"),(!E||!u.has(E))&&m.push("sel-b"),(!M||!u.has(M))&&m.push("sel-l"),(!A||!u.has(A))&&m.push("sel-r"),m.join(" ")}function Zt(t,o,u){const c=t.rows.findIndex(h=>h.id===o.rowId),r=t.rows.findIndex(h=>h.id===u.rowId),x=t.columns.findIndex(h=>h.id===o.colId),m=t.columns.findIndex(h=>h.id===u.colId);if(c<0||r<0||x<0||m<0)return[o];const C=Math.min(c,r),E=Math.max(c,r),M=Math.min(x,m),A=Math.max(x,m),y=[];for(let h=C;h<=E;h+=1)for(let z=M;z<=A;z+=1)y.push({rowId:t.rows[h].id,colId:t.columns[z].id});return y}function en(t){return t?{background:t.bg,color:t.color,fontWeight:t.bold?700:void 0,fontStyle:t.italic?"italic":void 0,fontSize:t.fontSize?`${t.fontSize}px`:void 0}:{}}function mn(t){var Ne;const{t:o,lang:u}=tt(),c=t.meta.documentId,[r,x]=l.useState(()=>Ie(t.initialContent)),[m,C]=l.useState(t.initialDisplayName),[E,M]=l.useState(!1),[A,y]=l.useState(t.hasLocalDraft??!1),[h,z]=l.useState(!1),[ne,be]=l.useState(!1),[O,se]=l.useState(!1),[ie,oe]=l.useState(!1),[Be,Pe]=l.useState([]),[Re,W]=l.useState(!1),[ae,le]=l.useState(t.meta.permission),[de,ye]=l.useState(!1),[Ae,ce]=l.useState(!1),[U,Te]=l.useState(new Map),[We,re]=l.useState(null),[we,q]=l.useState(null),[B,$]=l.useState(null),[v,j]=l.useState(null),[L,ue]=l.useState(""),S=l.useRef(null),K=l.useRef(!1),P=l.useRef(null),H=l.useRef(r),Q=l.useRef(m),me=l.useRef(null),he=l.useRef(null);H.current=r,Q.current=m,P.current=B,l.useEffect(()=>{const e=()=>{K.current=!1};return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]);const d=nt(r)??r.sheets[0],I=B&&v?Zt(d,B,v):[],V=new Set(I.map(w)),f=Xt(d,B,v,V),ke=f?Jt(d,f):"",G=f?De((Ne=d.rows.find(e=>e.id===f.rowId))==null?void 0:Ne.cells[f.colId]):"";l.useEffect(()=>{ue(G)},[G,f==null?void 0:f.rowId,f==null?void 0:f.colId]),l.useEffect(()=>{x(Ie(t.initialContent)),C(t.initialDisplayName),$(null),j(null),q(null)},[c,t.contentRevision,t.initialContent,t.initialDisplayName]),l.useEffect(()=>{let e=!1;return(async()=>{var s;const i=await st(c);e||!i||i.contentKind!=="sheet"||(x(Ie(i.content)),i.displayName&&C(i.displayName),y(!0),(s=t.onDraftExistsChange)==null||s.call(t,!0))})(),()=>{e=!0}},[c]),l.useEffect(()=>it((e,i)=>{var s;e===c&&(y(i),(s=t.onDraftExistsChange)==null||s.call(t,i))}),[c]),l.useEffect(()=>{let e=!1;return ot(c).then(i=>{e||z(!!(i!=null&&i.bookmarked))}),()=>{e=!0}},[c]),l.useEffect(()=>{let e=!0;return at().then(i=>{e&&Pe(i)}).catch(()=>{}),()=>{e=!1}},[]),l.useEffect(()=>{le(t.meta.permission)},[t.meta.permission,c]),l.useEffect(()=>{const e=i=>{me.current&&!me.current.contains(i.target)&&se(!1),he.current&&!he.current.contains(i.target)&&oe(!1)};return(O||ie)&&document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[O,ie]);const fe=l.useCallback(async()=>{var e;await lt(c).execute(()=>dt({documentId:c,content:T(H.current),displayName:Q.current,contentKind:"sheet",localBaseCommitIdAtEditStart:t.meta.headCommitId??null,snapshotMeta:{permission:t.meta.permission,ownerVisitorId:t.meta.ownerVisitorId,domainId:t.meta.domainId}})),y(!0),(e=t.onDraftExistsChange)==null||e.call(t,!0)},[c,t]),je=l.useCallback(()=>{S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{fe()},1e3)},[fe]);l.useEffect(()=>()=>{S.current&&clearTimeout(S.current)},[]);function J(e){var i;t.canEdit&&(x(e),(i=t.onContentChange)==null||i.call(t,T(e)),je())}function k(e){J(Et(r,e))}function $e(e,i,s){if(i&&P.current){s.preventDefault(),j(e);return}K.current=!0,$(e),j(e),P.current=e}function Le(e){K.current&&j(e)}function xe(e,i){$(e),j(i),P.current=e}function Ve(e,i,s){s.preventDefault();const a=d.rows;if(a.length===0)return;const D=a[0].id,b=a[a.length-1].id;if(i&&P.current){j({rowId:b,colId:e});return}xe({rowId:D,colId:e},{rowId:b,colId:e})}function Fe(e,i,s){s.preventDefault();const a=d.columns;if(a.length===0)return;const D=a[0].id,b=a[a.length-1].id;if(i&&P.current){j({rowId:e,colId:b});return}xe({rowId:e,colId:D},{rowId:e,colId:b})}function _e(e){e.preventDefault();const i=d.rows,s=d.columns;i.length===0||s.length===0||xe({rowId:i[0].id,colId:s[0].id},{rowId:i[i.length-1].id,colId:s[s.length-1].id})}function F(e){if(!t.canEdit||I.length===0)return;let i=d;for(const s of I)i=Mt(i,s.rowId,s.colId,e);k(i)}function pe(){var s;const e=I[0];if(!e)return;const i=ee((s=d.rows.find(a=>a.id===e.rowId))==null?void 0:s.cells[e.colId]);F({bold:!(i!=null&&i.bold)})}function Oe(){var s;const e=I[0];if(!e)return;const i=ee((s=d.rows.find(a=>a.id===e.rowId))==null?void 0:s.cells[e.colId]);F({italic:!(i!=null&&i.italic)})}function Ue(){if(!(!t.canEdit||!B||!v))try{k(zt(d,{startRowId:B.rowId,startColId:B.colId,endRowId:v.rowId,endColId:v.colId}))}catch{}}function qe(){if(!t.canEdit||!v)return;const{tab:e}=Bt(d,v.rowId,v.colId);k(e)}async function Ce(){var a;if(!t.canEdit)return;const e=document.querySelector(".mdocs-sheet-scroll"),i=(e==null?void 0:e.scrollTop)??null,s=(e==null?void 0:e.scrollLeft)??null;M(!0);try{S.current&&(clearTimeout(S.current),S.current=null),await fe(),await t.onPublish(T(H.current),Q.current.trim()||m,c),y(!1),(a=t.onDraftExistsChange)==null||a.call(t,!1)}finally{M(!1),e&&i!=null&&(e.scrollTop=i,s!=null&&(e.scrollLeft=s),requestAnimationFrame(()=>{e.scrollTop=i,s!=null&&(e.scrollLeft=s)}))}}async function Ke(){if(t.canEdit&&m.trim()!==t.initialDisplayName.trim())try{await Ce()}catch{}}async function ge(){var e,i;if(!ne){be(!0);try{h?(await St(c),z(!1),(e=t.onShowToast)==null||e.call(t,o("bookmarkRemoved"))):(await Nt(c),z(!0),(i=t.onShowToast)==null||i.call(t,o("bookmarkAdded")))}finally{be(!1)}}}function He(e){const i=Be.find(s=>s.visitorId===e);return(i==null?void 0:i.visitorName)??e.slice(0,8)}function Qe(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}const N=l.useMemo(()=>t.domains.find(e=>e.domainId===t.meta.domainId),[t.domains,t.meta.domainId]),Ge=l.useMemo(()=>{const e=(N==null?void 0:N.permission)??"public";return ct(e)},[N==null?void 0:N.permission]);function Je(e){return e===te.PRIVATE?o("permissionPrivate"):e===te.DOMAIN_READ?o("permissionInvite"):e===te.DOMAIN_WRITE?o("permissionDomainWrite"):e===te.PUBLIC_READ?o("permissionPublicRead"):o("permissionPublicEdit")}async function Xe(){if(de||ae===t.meta.permission){W(!1);return}ye(!0);try{await t.onPublish(T(H.current),Q.current.trim()||m,c,ae),W(!1)}finally{ye(!1)}}async function Ye(e){const i=new Set(e.map(s=>s.visitorId));for(const[s]of U)i.has(s)||await Pt(c,s);for(const s of e)U.get(s.visitorId)!==s.permission&&await Rt(c,s.visitorId,s.permission);ce(!1)}function X(){se(!1),oe(!1)}function Se(e,i){const s=(i==null?void 0:i.includeBookmark)??!0,a={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"},D=T(r);return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:o("docInfoCreator")}),n.jsx("span",{children:He(t.meta.ownerVisitorId)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:o("docInfoCreatedAt")}),n.jsx("span",{children:new Date(t.meta.createdAt).toLocaleString(u==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:o("docInfoSize")}),n.jsx("span",{children:Qe(new Blob([D]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:o("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(t.meta.updatedAt).toLocaleString(u==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),s?n.jsxs("button",{type:"button",style:a,onClick:()=>{ge(),e()},children:[n.jsx("span",{children:h?"⭐":"☆"}),n.jsx("span",{children:o(h?"bookmarkRemove":"bookmarkAdd")})]}):null,t.canManageInvites?n.jsxs("button",{type:"button",style:a,onClick:()=>{e(),(async()=>{const b=await Dt(c);Te(new Map(b.map(_=>[_.visitorId,_.permission]))),ce(!0)})()},children:[n.jsx($t,{size:14}),n.jsx("span",{children:o("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:a,onClick:()=>{e(),le(t.meta.permission),W(!0)},children:[n.jsx(Tt,{size:14}),n.jsx("span",{children:o("docInfoChangePermission")})]})]})}const g=(()=>{var i;const e=I[0];if(e)return ee((i=d.rows.find(s=>s.id===e.rowId))==null?void 0:i.cells[e.colId])})();function Ze(){!t.canEdit||!f||L!==G&&k(Me(d,f.rowId,f.colId,L))}return n.jsxs("div",{className:"mdocs-sheet-editor",children:[n.jsx(At,{fileType:"sheet",displayName:m,onDisplayNameChange:C,onDisplayNameBlur:()=>void Ke(),domains:t.domains,currentDomainId:t.currentDomainId,onDomainChange:t.onDomainChange,onDomainsChange:t.onDomainsChange,canEdit:t.canEdit,editing:!0,actionsAlwaysVisible:!0,syncBehind:t.syncBehind,onSyncClick:t.onSyncClick,busy:E,draftExists:A,onPublish:()=>void Ce(),onDelete:()=>void t.onDelete(),isBookmarked:h,bookmarkBusy:ne,onToggleBookmark:()=>void ge(),onToggleComments:t.onToggleComments,commentPanelOpen:t.commentPanelOpen,commentCount:t.commentCount,docInfoMenu:Se(X),docInfoOpen:O,onToggleDocInfo:()=>se(!O),docInfoMenuRef:me,readerChrome:t.readerChrome,onOpenMobileNav:t.onOpenMobileNav,readerMoreOpen:ie,onToggleReaderMore:()=>oe(e=>!e),readerMoreMenuRef:he,readerMoreMenu:n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:ne,onClick:()=>{ge(),X()},children:[n.jsx(rt,{size:16,strokeWidth:1.5,style:{color:h?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:h?"#faad14":"none"}}),n.jsx("span",{children:o(h?"bookmarkRemove":"bookmarkAdd")})]}),n.jsx("div",{className:"mdocs-reader-more-divider"}),t.canEdit?n.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:E,onClick:()=>{X(),t.onDelete()},children:n.jsx("span",{children:o("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),Se(X,{includeBookmark:!1})]})}),n.jsxs("div",{className:"mdocs-sheet-toolbar",children:[n.jsxs("div",{className:"mdocs-sheet-toolbar-left",children:[n.jsxs("button",{type:"button",className:"mdocs-sheet-btn mdocs-sheet-btn-add",disabled:!t.canEdit,onClick:()=>k(ut(d)),children:[n.jsxs("span",{className:"mdocs-sheet-btn-add-icon","aria-hidden":!0,children:[n.jsx(qt,{size:14,strokeWidth:2.4}),n.jsx(ve,{size:10,strokeWidth:3,className:"mdocs-sheet-btn-add-plus"})]}),n.jsx("span",{children:o("sheetAddRow")})]}),n.jsxs("button",{type:"button",className:"mdocs-sheet-btn mdocs-sheet-btn-add",disabled:!t.canEdit,onClick:()=>k(mt(d)),children:[n.jsxs("span",{className:"mdocs-sheet-btn-add-icon","aria-hidden":!0,children:[n.jsx(_t,{size:14,strokeWidth:2.4}),n.jsx(ve,{size:10,strokeWidth:3,className:"mdocs-sheet-btn-add-plus"})]}),n.jsx("span",{children:o("sheetAddColumn")})]}),n.jsx("span",{className:"mdocs-sheet-toolbar-sep","aria-hidden":!0}),n.jsx("button",{type:"button",className:`mdocs-sheet-btn mdocs-sheet-btn-icon${g!=null&&g.bold?" is-active":""}`,disabled:!t.canEdit||I.length===0,title:o("sheetBold"),onClick:pe,children:n.jsx(Lt,{size:13,strokeWidth:2.4})}),n.jsx("button",{type:"button",className:`mdocs-sheet-btn mdocs-sheet-btn-icon${g!=null&&g.italic?" is-active":""}`,disabled:!t.canEdit||I.length===0,title:o("sheetItalic"),onClick:Oe,children:n.jsx(Vt,{size:13,strokeWidth:2.4})}),n.jsx("label",{className:"mdocs-sheet-style-label",title:o("sheetFontSize"),children:n.jsxs("select",{className:"mdocs-sheet-font-size",disabled:!t.canEdit||I.length===0,value:(g==null?void 0:g.fontSize)??"",onChange:e=>{const i=e.target.value;F(i?{fontSize:Number(i)}:{fontSize:void 0})},children:[n.jsx("option",{value:"",children:"Aa"}),[12,13,14,16,18,20,24].map(e=>n.jsx("option",{value:e,children:e},e))]})}),n.jsx("label",{className:"mdocs-sheet-style-label",title:o("sheetTextColor"),children:n.jsx("input",{type:"color",className:"mdocs-sheet-color",disabled:!t.canEdit||I.length===0,value:(g==null?void 0:g.color)??"#212121",onChange:e=>F({color:e.target.value})})}),n.jsx("label",{className:"mdocs-sheet-style-label",title:o("sheetBgColor"),children:n.jsx("input",{type:"color",className:"mdocs-sheet-color",disabled:!t.canEdit||I.length===0,value:(g==null?void 0:g.bg)??"#ffffff",onChange:e=>F({bg:e.target.value})})}),n.jsx("span",{className:"mdocs-sheet-toolbar-sep","aria-hidden":!0}),n.jsxs("button",{type:"button",className:"mdocs-sheet-btn",disabled:!t.canEdit||I.length<2,title:`${o("sheetMerge")}(按住拖选,或 Shift+点第二格)`,onClick:Ue,children:[n.jsx(Ot,{size:13,strokeWidth:2.2}),n.jsx("span",{children:o("sheetMerge")})]}),n.jsxs("button",{type:"button",className:"mdocs-sheet-btn",disabled:!t.canEdit||!v||!Ee(d,v.rowId,v.colId),title:o("sheetUnmerge"),onClick:qe,children:[n.jsx(Ht,{size:13,strokeWidth:2.2}),n.jsx("span",{children:o("sheetUnmerge")})]})]}),n.jsx("div",{className:"mdocs-sheet-toolbar-right",children:n.jsxs("span",{className:"mdocs-sheet-stats-badge",children:[d.name," · ",d.rows.length," 行 × ",d.columns.length," 列"]})})]}),n.jsx("div",{className:"mdocs-sheet-formula-bar","aria-label":"单元格信息栏",children:n.jsxs("div",{className:"mdocs-sheet-formula-bar-inner",children:[n.jsx("input",{className:"mdocs-sheet-name-box",readOnly:!0,tabIndex:-1,value:ke,placeholder:"—",title:ke||"单元格地址","aria-label":"单元格地址"}),n.jsx("input",{className:"mdocs-sheet-formula-input",value:L,disabled:!t.canEdit||!f,placeholder:f?"":"点击单元格查看内容",title:L,"aria-label":"单元格内容",style:t.readerChrome?{width:`${Math.max(28,Math.min((L||" ").length+4,96))}ch`}:void 0,onChange:e=>ue(e.target.value),onBlur:()=>Ze(),onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),e.target.blur()),e.key==="Escape"&&(ue(G),e.target.blur())}})]})}),n.jsx("div",{className:"mdocs-sheet-scroll",children:n.jsxs("table",{className:"mdocs-sheet-table",children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{className:"mdocs-sheet-corner-cell",title:"全选",onMouseDown:_e,children:"#"}),d.columns.map(e=>{const i=I.length>0&&d.rows.every(s=>V.has(w({rowId:s.id,colId:e.id})));return n.jsx("th",{className:`mdocs-sheet-th${i?" is-selected":""}`,onMouseDown:s=>{we!==e.id&&(s.target.closest(".mdocs-sheet-col-del")||Ve(e.id,s.shiftKey,s))},children:n.jsxs("div",{className:"mdocs-sheet-header-cell",children:[we===e.id&&t.canEdit?n.jsx("input",{className:"mdocs-sheet-header-input",autoFocus:!0,defaultValue:e.name,title:"编辑列名",onClick:s=>s.stopPropagation(),onMouseDown:s=>s.stopPropagation(),onBlur:s=>{q(null);const a=s.target.value.trim();!a||a===e.name||k(ht(d,e.id,a))},onKeyDown:s=>{s.key==="Enter"&&s.target.blur(),s.key==="Escape"&&q(null)}}):n.jsx("button",{type:"button",className:"mdocs-sheet-header-label",title:"单击全选列;双击重命名",onDoubleClick:s=>{s.preventDefault(),s.stopPropagation(),t.canEdit&&q(e.id)},children:e.name}),t.canEdit&&d.columns.length>1&&n.jsx("button",{type:"button",className:"mdocs-sheet-col-del",title:o("sheetDeleteColumn"),onMouseDown:s=>s.stopPropagation(),onClick:()=>{try{const{tab:s}=ft(d,[e.id]);k(s)}catch{}},children:n.jsx(ze,{size:12,strokeWidth:1.8})})]})},e.id)}),n.jsx("th",{className:"mdocs-sheet-actions-header"})]})}),n.jsx("tbody",{children:d.rows.map((e,i)=>{const s=I.length>0&&d.columns.every(a=>V.has(w({rowId:e.id,colId:a.id})));return n.jsxs("tr",{className:`mdocs-sheet-tr${s?" is-row-selected":""}`,children:[n.jsx("td",{className:`mdocs-sheet-rownum${s?" is-selected":""}`,title:"单击全选行",onMouseDown:a=>Fe(e.id,a.shiftKey,a),children:i+1}),d.columns.map(a=>{if(xt(d,e.id,a.id))return null;const D=e.cells[a.id],b=ee(D),_=Ee(d,e.id,a.id),et=gt(d,e.id,a.id),Y=_&&et?It(d,_):{rowSpan:1,colSpan:1},R={rowId:e.id,colId:a.id};return V.has(w(R)),n.jsx("td",{className:Yt(d,R,V,v),rowSpan:Y.rowSpan>1?Y.rowSpan:void 0,colSpan:Y.colSpan>1?Y.colSpan:void 0,style:b!=null&&b.bg?{background:b.bg}:void 0,onMouseEnter:()=>Le(R),children:n.jsx("input",{className:"mdocs-sheet-cell-input",style:en(b),value:De(D),disabled:!t.canEdit,onMouseDown:Z=>$e(R,Z.shiftKey,Z),onFocus:()=>{K.current||($(R),j(R),P.current=R)},onChange:Z=>k(Me(d,e.id,a.id,Z.target.value))})},a.id)}),n.jsx("td",{className:"mdocs-sheet-actions-col",children:n.jsx("button",{type:"button",className:"mdocs-sheet-row-del",disabled:!t.canEdit,title:o("sheetDeleteRow"),onClick:()=>k(vt(d,e.id)),children:n.jsx(ze,{size:13,strokeWidth:1.8})})})]},e.id)})})]})}),n.jsxs("footer",{className:"mdocs-sheet-footer",children:[n.jsxs("div",{className:"mdocs-sheet-tabs",role:"tablist",children:[r.sheets.map(e=>{const i=e.id===d.id;return n.jsxs("div",{className:`mdocs-sheet-tab${i?" mdocs-sheet-tab--active":""}`,role:"tab","aria-selected":i,children:[We===e.id&&t.canEdit?n.jsx("input",{className:"mdocs-sheet-tab-rename",autoFocus:!0,defaultValue:e.name,onBlur:s=>{re(null);const a=s.target.value.trim();if(!(!a||a===e.name))try{J(bt(r,e.id,a))}catch{}},onKeyDown:s=>{s.key==="Enter"&&s.target.blur(),s.key==="Escape"&&re(null)}}):n.jsx("button",{type:"button",className:"mdocs-sheet-tab-btn",title:"双击可重命名工作表",onClick:()=>{var a;if(i)return;const s=yt(r,e.id);x(s),$(null),j(null),t.canEdit&&((a=t.onContentChange)==null||a.call(t,T(s)),je())},onDoubleClick:()=>{t.canEdit&&re(e.id)},children:e.name}),t.canEdit&&r.sheets.length>1?n.jsx("button",{type:"button",className:"mdocs-sheet-tab-close",title:o("sheetDeleteSheet"),onClick:s=>{s.stopPropagation();try{J(kt(r,e.id))}catch{}},children:n.jsx(wt,{size:11,strokeWidth:2.4})}):null]},e.id)}),n.jsx("button",{type:"button",className:"mdocs-sheet-tab-add",disabled:!t.canEdit,title:o("sheetAddSheet"),onClick:()=>{const{doc:e}=jt(r);J(e)},children:n.jsx(ve,{size:13,strokeWidth:2.2})})]}),n.jsx("div",{className:"mdocs-sheet-footer-info",children:n.jsxs("span",{children:["共 ",r.sheets.length," 个工作表"]})})]}),Re&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:e=>{e.target===e.currentTarget&&W(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:o("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[o("domainPermission"),":",N?Ct(N.domainName,u,o):t.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:Ge.map(e=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n.jsx("input",{type:"radio",name:"sheet-doc-permission",value:e,checked:ae===e,onChange:()=>le(e)}),n.jsx("span",{children:Je(e)})]},e))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>W(!1),children:o("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:de,onClick:()=>void Xe(),children:o(de?"publishing":"saveAndPublish")})]})]})}),t.canManageInvites?n.jsx(Wt,{open:Ae,title:o("docInfoInviteMember"),initialSelectedIds:[...U.keys()],initialPermissions:U,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:o("invitePermissionRead")},{value:"edit",label:o("invitePermissionEdit")}],onClose:()=>ce(!1),onConfirm:e=>{Ye(e)}}):null]})}export{mn as SheetEditor};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.mdocs-sheet-editor{display:flex;flex-direction:column;height:100%;min-height:0;background-color:var(--mdocs-bg, #f5f5f5);color:var(--mdocs-text, #212121);overflow:hidden;position:relative}.mdocs-sheet-toolbar{display:flex;align-items:center;justify-content:space-between;padding:0 16px;height:38px;min-height:38px;background:var(--mdocs-surface, #ffffff);border-bottom:1px solid var(--mdocs-border, #e0e0e0);gap:12px}.mdocs-sheet-toolbar-left{display:flex;align-items:center;gap:6px;flex-wrap:wrap}.mdocs-sheet-toolbar-sep{width:1px;height:18px;background:var(--mdocs-border, #e0e0e0);margin:0 4px}.mdocs-sheet-btn-icon{width:26px;padding:0;justify-content:center}.mdocs-sheet-btn.is-active{background:var(--mdocs-accent-soft, #e8f5e9);border-color:var(--mdocs-accent, #4caf50);color:var(--mdocs-accent-dark, #388e3c)}.mdocs-sheet-style-label{display:inline-flex;align-items:center;margin:0}.mdocs-sheet-font-size{height:26px;border:1px solid var(--mdocs-border, #e0e0e0);border-radius:var(--mdocs-radius-sm, 4px);background:var(--mdocs-surface, #fff);font-size:12px;color:var(--mdocs-text, #212121);padding:0 4px}.mdocs-sheet-color{width:26px;height:26px;padding:0;border:1px solid var(--mdocs-border, #e0e0e0);border-radius:4px;background:transparent;cursor:pointer}.mdocs-sheet-td.is-selected{--sel-t: 0;--sel-b: 0;--sel-l: 0;--sel-r: 0;outline:none;z-index:1;box-shadow:inset 0 calc(var(--sel-t) * 2px) 0 0 var(--mdocs-accent, #4caf50),inset 0 calc(var(--sel-b) * -2px) 0 0 var(--mdocs-accent, #4caf50),inset calc(var(--sel-l) * 2px) 0 0 0 var(--mdocs-accent, #4caf50),inset calc(var(--sel-r) * -2px) 0 0 0 var(--mdocs-accent, #4caf50)}.mdocs-sheet-td.is-selected.sel-t{--sel-t: 1}.mdocs-sheet-td.is-selected.sel-b{--sel-b: 1}.mdocs-sheet-td.is-selected.sel-l{--sel-l: 1}.mdocs-sheet-td.is-selected.sel-r{--sel-r: 1}.mdocs-sheet-td.is-selected:after{content:"";position:absolute;top:0;right:0;bottom:0;left:0;background:color-mix(in srgb,var(--mdocs-accent, #4caf50) 12%,transparent);pointer-events:none;z-index:0}.mdocs-sheet-td.is-selected.is-active{z-index:2;box-shadow:inset 0 0 0 2px var(--mdocs-accent, #4caf50)}.mdocs-sheet-td.is-selected.is-active:after{background:color-mix(in srgb,var(--mdocs-accent, #4caf50) 8%,transparent)}.mdocs-sheet-toolbar-right{display:flex;align-items:center}.mdocs-sheet-btn{display:inline-flex;align-items:center;gap:5px;height:26px;padding:0 10px;font-size:12px;font-weight:500;color:var(--mdocs-text, #212121);background:var(--mdocs-surface, #ffffff);border:1px solid var(--mdocs-border, #e0e0e0);border-radius:var(--mdocs-radius-sm, 4px);cursor:pointer;transition:all .15s ease;-webkit-user-select:none;user-select:none}.mdocs-sheet-btn:hover:not(:disabled){background:var(--mdocs-accent-soft, #e8f5e9);border-color:var(--mdocs-accent-secondary, #81c784);color:var(--mdocs-accent-dark, #388e3c)}.mdocs-sheet-btn:disabled{opacity:.45;cursor:not-allowed}.mdocs-sheet-btn-add{height:28px;padding:0 11px 0 8px;font-weight:600;color:var(--mdocs-accent-dark, #388e3c);background:var(--mdocs-surface, #fff);border:1.5px solid var(--mdocs-accent, #4caf50);box-shadow:none}.mdocs-sheet-btn-add:hover:not(:disabled){color:var(--mdocs-accent-dark, #2e7d32);background:var(--mdocs-surface, #fff);border-color:var(--mdocs-accent-dark, #388e3c);box-shadow:0 0 0 2px #4caf502e}.mdocs-sheet-btn-add:disabled{opacity:.4;box-shadow:none}.mdocs-sheet-btn-add-icon{position:relative;display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;flex-shrink:0;color:var(--mdocs-accent, #4caf50)}.mdocs-sheet-btn-add-plus{position:absolute;right:-3px;bottom:-2px;background:var(--mdocs-surface, #fff);color:var(--mdocs-accent-dark, #388e3c);border:1px solid var(--mdocs-accent, #4caf50);border-radius:50%;padding:0;box-sizing:content-box}.mdocs-sheet-stats-badge{font-size:11.5px;color:var(--mdocs-accent-dark, #388e3c);background:var(--mdocs-accent-soft, #e8f5e9);padding:3px 10px;border-radius:12px;font-variant-numeric:tabular-nums;border:1px solid var(--mdocs-accent-secondary, #81c784)}.mdocs-sheet-formula-bar{flex-shrink:0;background:var(--mdocs-bg, #f5f5f5);border-bottom:1px solid var(--mdocs-border, #e0e0e0);padding:6px 12px;min-width:0}.mdocs-sheet-formula-bar-inner{display:flex;align-items:center;gap:8px;min-width:0}.mdocs-sheet-name-box,.mdocs-sheet-formula-input{height:28px;box-sizing:border-box;border:1px solid var(--mdocs-border, #e0e0e0);border-radius:6px;background:var(--mdocs-surface, #fff);color:var(--mdocs-text, #212121);font-size:13px;line-height:1.2;padding:0 10px;outline:none;overflow-x:auto;white-space:nowrap}.mdocs-sheet-name-box:focus,.mdocs-sheet-formula-input:focus{border-color:var(--mdocs-accent, #4caf50);box-shadow:0 0 0 2px #4caf5026}.mdocs-sheet-name-box{width:72px;flex:0 0 72px;text-align:center;font-variant-numeric:tabular-nums;font-weight:500;color:var(--mdocs-text-secondary, #616161);cursor:default}.mdocs-sheet-formula-input{flex:1 1 auto;min-width:0;width:100%}.mdocs-sheet-formula-input:disabled{color:var(--mdocs-text-muted, #9e9e9e);background:#fafafa;cursor:default}@media (max-width: 768px){.mdocs-sheet-formula-bar{overflow-x:auto;-webkit-overflow-scrolling:touch;overscroll-behavior-x:contain;padding:6px 8px}.mdocs-sheet-formula-bar-inner{width:max-content;min-width:100%}.mdocs-sheet-name-box{width:64px;flex:0 0 64px}.mdocs-sheet-formula-input{flex:0 0 auto;width:auto;min-width:min(70vw,320px);max-width:none}}.mdocs-sheet-scroll{flex:1;min-height:0;overflow:auto;position:relative;background:var(--mdocs-surface, #ffffff)}.mdocs-sheet-table{border-collapse:separate;border-spacing:0;min-width:100%;table-layout:fixed;font-size:13px}.mdocs-sheet-corner-cell{position:sticky;top:0;left:0;z-index:10;width:44px;min-width:44px;max-width:44px;height:30px;background:#f8fafc;color:var(--mdocs-text-muted, #616161);font-size:11.5px;font-weight:600;text-align:center;border-right:1px solid var(--mdocs-border, #e0e0e0);border-bottom:1.5px solid var(--mdocs-border, #e0e0e0);-webkit-user-select:none;user-select:none;cursor:pointer}.mdocs-sheet-corner-cell:hover{background:var(--mdocs-accent-soft, #e8f5e9);color:var(--mdocs-accent-dark, #388e3c)}.mdocs-sheet-th{position:sticky;top:0;z-index:5;height:30px;min-width:140px;background:#f8fafc;border-right:1px solid var(--mdocs-border, #e0e0e0);border-bottom:1.5px solid var(--mdocs-border, #e0e0e0);padding:0;-webkit-user-select:none;user-select:none;cursor:pointer}.mdocs-sheet-header-cell{display:flex;align-items:center;justify-content:space-between;height:100%;padding:0 6px 0 10px;gap:4px}.mdocs-sheet-th.is-selected{background:var(--mdocs-accent-soft, #e8f5e9)!important;color:var(--mdocs-accent-dark, #388e3c);box-shadow:inset 0 -2px 0 0 var(--mdocs-accent, #4caf50)}.mdocs-sheet-rownum.is-selected{background:var(--mdocs-accent-soft, #e8f5e9)!important;color:var(--mdocs-accent-dark, #388e3c);box-shadow:inset -2px 0 0 0 var(--mdocs-accent, #4caf50)}.mdocs-sheet-header-label{flex:1;min-width:0;border:none;outline:none;background:transparent;font-size:12px;font-weight:600;color:inherit;padding:2px 4px;border-radius:3px;text-align:left;cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.mdocs-sheet-header-label:hover{background:var(--mdocs-accent-soft, #e8f5e9)}.mdocs-sheet-header-input{flex:1;min-width:0;border:none;outline:none;background:transparent;font-size:12px;font-weight:600;color:var(--mdocs-text, #212121);padding:2px 4px;border-radius:3px;transition:background-color .15s ease}.mdocs-sheet-header-input:hover:not(:disabled){background:var(--mdocs-accent-soft, #e8f5e9)}.mdocs-sheet-header-input:focus{background:var(--mdocs-surface, #ffffff);box-shadow:0 0 0 1.5px var(--mdocs-accent, #4caf50);color:var(--mdocs-text, #212121)}.mdocs-sheet-col-del{opacity:0;border:none;background:transparent;color:var(--mdocs-text-muted, #616161);cursor:pointer;padding:3px;border-radius:3px;display:flex;align-items:center;justify-content:center;transition:opacity .15s ease,background .15s ease,color .15s ease}.mdocs-sheet-th:hover .mdocs-sheet-col-del{opacity:1}.mdocs-sheet-col-del:hover{color:var(--mdocs-danger, #e53935);background:var(--mdocs-error-soft, #ffebee)}.mdocs-sheet-actions-header{position:sticky;top:0;z-index:5;width:36px;min-width:36px;max-width:36px;background:#f8fafc;border-bottom:1.5px solid var(--mdocs-border, #e0e0e0)}.mdocs-sheet-rownum{position:sticky;left:0;z-index:4;width:44px;min-width:44px;max-width:44px;height:28px;background:#f8fafc;color:var(--mdocs-text-muted, #616161);font-size:11px;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;text-align:center;border-right:1px solid var(--mdocs-border, #e0e0e0);border-bottom:1px solid var(--mdocs-border, #e0e0e0);-webkit-user-select:none;user-select:none;line-height:28px;cursor:pointer}.mdocs-sheet-tr:hover td{background-color:#f8fafc}.mdocs-sheet-tr:hover .mdocs-sheet-rownum{background-color:var(--mdocs-accent-soft, #e8f5e9);color:var(--mdocs-accent-dark, #388e3c)}.mdocs-sheet-td{height:28px;min-width:140px;padding:0;border-right:1px solid var(--mdocs-border, #e0e0e0);border-bottom:1px solid var(--mdocs-border, #e0e0e0);background:var(--mdocs-surface, #ffffff);position:relative;user-select:none;-webkit-user-select:none}.mdocs-sheet-td.is-selected .mdocs-sheet-cell-input{position:relative;z-index:1;background:transparent}.mdocs-sheet-cell-input:focus{user-select:text;-webkit-user-select:text}.mdocs-sheet-cell-input{width:100%;height:100%;min-height:28px;border:none;outline:none;background:transparent;padding:0 8px;font-size:12.5px;color:var(--mdocs-text, #212121);font-family:inherit;transition:box-shadow .1s ease}.mdocs-sheet-cell-input:focus{background:var(--mdocs-surface, #ffffff)!important;box-shadow:inset 0 0 0 2px var(--mdocs-accent, #4caf50);z-index:2;position:relative}.mdocs-sheet-actions-col{width:36px;min-width:36px;max-width:36px;border-bottom:1px solid var(--mdocs-border, #e0e0e0);text-align:center;vertical-align:middle;padding:0;background:var(--mdocs-surface, #ffffff)}.mdocs-sheet-row-del{opacity:0;border:none;background:transparent;color:var(--mdocs-text-muted, #616161);cursor:pointer;padding:4px;border-radius:4px;display:inline-flex;align-items:center;justify-content:center;transition:opacity .15s ease,background .15s ease,color .15s ease}.mdocs-sheet-tr:hover .mdocs-sheet-row-del{opacity:1}.mdocs-sheet-row-del:hover:not(:disabled){color:var(--mdocs-danger, #e53935);background:var(--mdocs-error-soft, #ffebee)}.mdocs-sheet-footer{height:36px;min-height:36px;display:flex;align-items:center;justify-content:space-between;border-top:1px solid var(--mdocs-border, #e0e0e0);background:var(--mdocs-bg, #f5f5f5);padding:0 12px;gap:16px;-webkit-user-select:none;user-select:none;z-index:10}.mdocs-sheet-tabs{display:flex;align-items:flex-end;height:100%;gap:2px;overflow-x:auto;overflow-y:hidden;scrollbar-width:none}.mdocs-sheet-tabs::-webkit-scrollbar{display:none}.mdocs-sheet-tab{display:flex;align-items:center;height:30px;padding:0 12px;border-radius:6px 6px 0 0;background:transparent;border:1px solid transparent;border-bottom:none;font-size:12px;color:var(--mdocs-text-muted, #616161);position:relative;transition:all .15s ease;white-space:nowrap}.mdocs-sheet-tab:hover:not(.mdocs-sheet-tab--active){background:var(--mdocs-border, #e0e0e0);color:var(--mdocs-text, #212121)}.mdocs-sheet-tab--active{background:var(--mdocs-surface, #ffffff);color:var(--mdocs-text, #212121);font-weight:600;border-color:var(--mdocs-border, #e0e0e0);border-bottom-color:var(--mdocs-surface, #ffffff);box-shadow:0 -1px 3px #0000000a}.mdocs-sheet-tab--active:after{content:"";position:absolute;bottom:-1px;left:0;right:0;height:2.5px;background:var(--mdocs-accent, #4caf50);border-radius:2px 2px 0 0}.mdocs-sheet-tab-btn{border:none;background:transparent;padding:0;font:inherit;color:inherit;cursor:pointer;white-space:nowrap;max-width:140px;overflow:hidden;text-overflow:ellipsis}.mdocs-sheet-tab-rename{border:1px solid var(--mdocs-accent, #4caf50);border-radius:3px;outline:none;font-size:12px;font-weight:500;padding:1px 4px;width:90px;background:var(--mdocs-surface, #ffffff);color:var(--mdocs-text, #212121)}.mdocs-sheet-tab-close{margin-left:6px;border:none;background:transparent;padding:2px;border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;color:var(--mdocs-text-muted, #616161);opacity:.6;transition:all .15s ease}.mdocs-sheet-tab-close:hover{opacity:1;background:var(--mdocs-error-soft, #ffebee);color:var(--mdocs-danger, #e53935)}.mdocs-sheet-tab-add{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;border:none;background:transparent;border-radius:4px;cursor:pointer;color:var(--mdocs-text-muted, #616161);margin-left:4px;margin-bottom:3px;transition:all .15s ease}.mdocs-sheet-tab-add:hover:not(:disabled){background:var(--mdocs-accent-soft, #e8f5e9);color:var(--mdocs-accent-dark, #388e3c)}.mdocs-sheet-tab-add:disabled{opacity:.4;cursor:not-allowed}.mdocs-sheet-footer-info{font-size:11px;color:var(--mdocs-text-muted, #616161);white-space:nowrap}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as t,C as _}from"./index-
|
|
1
|
+
import{o as t,C as _}from"./index-DAhW-QRN.js";import{r as u,j as y}from"./react-vendor-BVS1XoFi.js";import{F as x,G as v,L,H as c,J as l,K as N,M as z,q as j,N as H,P as w}from"./react-Dj2vqPq5.js";import{z as f,V as g}from"./editor-DBWWidi3.js";import{B as I,I as $}from"./italic-cqqPz-_Q.js";/**
|
|
2
2
|
* @license lucide-react v0.562.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{o as ee,c as z,a8 as se,f as ie,a3 as _}from"./index-DAhW-QRN.js";import{r,j as e}from"./react-vendor-BVS1XoFi.js";/**
|
|
2
|
+
* @license lucide-react v0.562.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const te=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],ae=ee("users",te);function re({options:v,value:a,onChange:b}){const[d,f]=r.useState(!1),y=r.useRef(null),x=r.useRef(null),p=v.find(o=>o.value===a);r.useEffect(()=>{if(!d)return;const o=u=>{var N,k;!((N=y.current)!=null&&N.contains(u.target))&&!((k=x.current)!=null&&k.contains(u.target))&&f(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[d]),r.useEffect(()=>{if(!d)return;const o=u=>{var N;u.key==="Escape"&&(f(!1),(N=y.current)==null||N.focus())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[d]);function j(o){b(o),f(!1)}return e.jsxs("div",{className:"mdocs-mini-select",style:{position:"relative"},children:[e.jsxs("button",{ref:y,type:"button",className:"mdocs-mini-select-trigger","aria-expanded":d,"aria-haspopup":"listbox",onClick:()=>f(o=>!o),children:[e.jsx("span",{children:p==null?void 0:p.label}),e.jsx("svg",{className:"mdocs-mini-select-chevron"+(d?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),d&&e.jsx("div",{ref:x,className:"mdocs-mini-select-menu card",role:"listbox",children:v.map(o=>e.jsx("button",{type:"button",className:"mdocs-mini-select-option"+(o.value===a?" active":""),role:"option","aria-selected":o.value===a,onClick:()=>j(o.value),children:o.label},o.value))})]})}function oe(v){return v.length<=6?v:`${v.slice(0,6)}…`}function ce(v){const{visitors:a,loadState:b,searchFilter:d,onSearchChange:f,selectedIds:y,onToggle:x,selectedRows:p,lockedIds:j=new Set,myVisitorId:o,showPermissionSelect:u=!1,permissionOptions:N=[],onPermissionChange:k}=v,{t:i}=z(),P=r.useMemo(()=>{const t=d.trim().toLowerCase();let g=t?a.filter(m=>m.visitorName.toLowerCase().includes(t)||m.visitorId.toLowerCase().includes(t)):a;return o&&(g=[...g].sort((m,R)=>m.visitorId===o?-1:R.visitorId===o?1:0)),g},[a,d,o]);return e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"search",className:"mdocs-visitor-picker-search",placeholder:i("visitorPickerSearchPlaceholder"),value:d,onChange:t=>f(t.target.value),disabled:b!=="ok"}),b==="loading"&&e.jsx("div",{className:"mdocs-visitor-picker-loading",children:i("loading")}),b==="err"&&e.jsx("div",{className:"mdocs-visitor-picker-error",children:i("visitorPickerLoadError")}),b==="ok"&&e.jsxs("div",{className:"mdocs-visitor-picker-columns",children:[e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnAll")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdShort")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col",children:i("visitorPickerColPick")})]})}),e.jsx("tbody",{children:P.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:3,className:"mdocs-visitor-picker-empty-cell",children:a.length===0?i("visitorPickerEmptyDirectory"):i("domainNoMatch")})}):P.map(t=>{const g=j.has(t.visitorId),m=y.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-short",children:oe(t.visitorId)})}),e.jsxs("td",{children:[t.visitorName,t.visitorId===o&&e.jsx("span",{className:"mdocs-visitor-picker-self-marker",children:i("visitorPickerSelfMarker")})]}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:e.jsx("input",{type:"checkbox",checked:m,disabled:g,onChange:()=>x(t.visitorId),"aria-label":t.visitorName})})]},t.visitorId)})})]})})]}),e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnSelected")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdFull")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),u&&e.jsx("th",{scope:"col",children:i("permissionLabel")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col"})]})}),e.jsx("tbody",{children:p.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:u?4:3,className:"mdocs-visitor-picker-empty-cell",children:i("visitorPickerNoSelection")})}):p.map(t=>{const g=j.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-full",children:t.visitorId})}),e.jsx("td",{className:t.muted?"mdocs-visitor-picker-name-muted":void 0,children:t.name}),u&&e.jsx("td",{children:e.jsx(re,{options:N,value:t.permission??"read",onChange:m=>k==null?void 0:k(t.visitorId,m)})}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:g?e.jsx("span",{className:"mdocs-visitor-picker-locked",title:i("visitorPickerLockedHint"),children:"—"}):e.jsx("button",{type:"button",className:"mdocs-visitor-picker-remove",onClick:()=>x(t.visitorId),"aria-label":i("visitorPickerRemove"),children:"×"})})]},t.visitorId)})})]})})]})]})]})}function de(v){var W;const{open:a,title:b,initialSelectedIds:d,lockedIds:f=[],seedMembers:y,excludeTemplateId:x,templates:p,onClose:j,onConfirm:o,showPermissionSelect:u=!1,permissionOptions:N=[],initialPermissions:k}=v,{t:i}=z(),P=r.useRef(i);P.current=i;const t=r.useMemo(()=>new Set(f),[f]),g=se(),[m,R]=r.useState([]),[E,T]=r.useState("idle"),[w,V]=r.useState(()=>new Set),[O,L]=r.useState(()=>new Map),[G,A]=r.useState(""),[I,B]=r.useState(""),[M,D]=r.useState(!1),U=r.useRef(null),[J,$]=r.useState(!1),[q,C]=r.useState(null),F=r.useMemo(()=>p.filter(s=>x==null||s.id!==x),[p,x]),H=r.useMemo(()=>new Map((y??[]).map(s=>[s.visitorId,s])),[y]);r.useEffect(()=>{a&&(V(new Set(d)),L(k?new Map(k):new Map),A(""),B(""),C(null))},[a,d,k]),r.useEffect(()=>{if(!a)return;let s=!1;return T("loading"),ie().then(n=>{s||(R(n),T("ok"))}).catch(n=>{s||(T("err"),C(_(P.current,n)))}),()=>{s=!0}},[a]),r.useEffect(()=>{if(!M)return;const s=n=>{var c;(c=U.current)!=null&&c.contains(n.target)||D(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[M]);const K=r.useMemo(()=>{const s=new Map(m.map(c=>[c.visitorId,c])),n=[];for(const c of w){const l=O.get(c),h=s.get(c);if(h){n.push({visitorId:c,name:h.visitorName,muted:!1,permission:l});continue}const S=H.get(c);if(S){S.missing?n.push({visitorId:c,name:i("visitorPickerMemberMissing"),muted:!0,permission:l}):S.disabled?n.push({visitorId:c,name:`${S.visitorName} · ${i("visitorPickerDisabledTag")}`,muted:!0,permission:l}):n.push({visitorId:c,name:S.visitorName,muted:!1,permission:l});continue}n.push({visitorId:c,name:i("visitorPickerUnknownVisitor"),muted:!0,permission:l})}return n.sort((c,l)=>c.name.localeCompare(l.name,void 0,{sensitivity:"base"})),n},[m,w,H,O,i]),Q=r.useCallback(s=>{t.has(s)||V(n=>{const c=new Set(n);return c.has(s)?(c.delete(s),L(l=>{const h=new Map(l);return h.delete(s),h})):(c.add(s),L(l=>{const h=new Map(l);return h.set(s,"read"),h})),c})},[t]),X=r.useCallback((s,n)=>{L(c=>{const l=new Map(c);return l.set(s,n),l})},[]),Y=r.useCallback(()=>{const s=Number(I);if(!Number.isInteger(s)||s<1)return;const n=p.find(l=>l.id===s);if(!n)return;const c=new Set(m.map(l=>l.visitorId));V(l=>{const h=new Set(l);for(const S of n.visitorIds)c.has(S)&&h.add(S);return h})},[I,p,m]);async function Z(){C(null),$(!0);try{if(u){const s=[...w].sort().map(n=>({visitorId:n,permission:O.get(n)??"read"}));await o(s)}else{const s=[...w].sort();await o(s)}j()}catch(s){C(_(i,s))}finally{$(!1)}}return a?e.jsx("div",{className:"mdocs-visitor-picker-overlay",role:"presentation",onMouseDown:s=>s.target===s.currentTarget&&j(),children:e.jsxs("div",{className:"mdocs-visitor-picker-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-visitor-picker-title",children:[e.jsxs("header",{className:"mdocs-visitor-picker-header",children:[e.jsx("h2",{id:"mdocs-visitor-picker-title",className:"mdocs-visitor-picker-title",children:b}),e.jsx("button",{type:"button",className:"mdocs-visitor-picker-close",onClick:j,"aria-label":i("close"),children:"×"})]}),F.length>0&&e.jsx("div",{className:"mdocs-visitor-picker-toolbar",children:e.jsxs("div",{className:"mdocs-visitor-picker-template-bar",children:[e.jsxs("div",{ref:U,className:"mdocs-template-picker",children:[e.jsxs("button",{type:"button",className:"mdocs-template-picker-trigger",onClick:()=>D(s=>!s),disabled:E!=="ok","aria-haspopup":"listbox","aria-expanded":M,children:[e.jsx("span",{className:"mdocs-template-picker-text",children:I?(W=F.find(s=>String(s.id)===I))==null?void 0:W.displayName:i("visitorPickerPickTemplate")}),e.jsx("svg",{className:"mdocs-template-picker-chevron"+(M?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),M&&e.jsx("div",{className:"mdocs-template-picker-menu card",role:"listbox",children:F.map(s=>e.jsx("button",{type:"button",className:"mdocs-template-picker-option"+(String(s.id)===I?" active":""),role:"option","aria-selected":String(s.id)===I,onClick:()=>{B(String(s.id)),D(!1)},children:s.displayName},s.id))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>{if(E!=="ok"){C(i("loading"));return}if(!I){C(i("visitorPickerPickTemplate"));return}Y()},children:i("visitorPickerApplyTemplate")})]})}),q&&e.jsx("div",{className:"mdocs-visitor-picker-error",role:"alert",children:q}),e.jsx("div",{style:{padding:"8px 18px 12px"},children:e.jsx(ce,{visitors:m,loadState:E,searchFilter:G,onSearchChange:A,selectedIds:w,onToggle:Q,selectedRows:K,lockedIds:t,myVisitorId:g,showPermissionSelect:u,permissionOptions:N,onPermissionChange:X})}),e.jsxs("footer",{className:"mdocs-visitor-picker-footer",children:[e.jsx("button",{type:"button",className:"secondary",onClick:j,children:i("cancel")}),e.jsx("button",{type:"button",className:"primary",onClick:()=>{if(E!=="ok"){C(i("loading"));return}Z()},children:i(J?"saving":"visitorPickerConfirm")})]})]})}):null}export{re as M,ae as U,de as V,ce as a};
|