@fgbg/mdocs 1.3.24 → 1.3.26
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 +16 -0
- package/dist/web/assets/{AgentChatPanel-NcsMAhWM.js → AgentChatPanel-TJVgAwlH.js} +3 -3
- package/dist/web/assets/{AgentSkillFormCard-B99CncJO.js → AgentSkillFormCard-3ZpgH1RY.js} +2 -2
- package/dist/web/assets/{AiWriteWorkbench-DomEbwzU.js → AiWriteWorkbench-B9HrhEmd.js} +4 -4
- package/dist/web/assets/{DiagramEditor-NtNY3sZL-BhsjOCtK.js → DiagramEditor-NtNY3sZL-CyddeNUo.js} +1 -1
- package/dist/web/assets/DocChrome-C5syeHbQ.js +11 -0
- package/dist/web/assets/DocumentEditor-mG7hvAWj.js +1 -0
- package/dist/web/assets/{HtmlEditor-g2NNYmv2.js → HtmlEditor-DABDor1R.js} +1 -1
- package/dist/web/assets/{MergeView-GL7xdFM4.js → MergeView-BczHMfos.js} +1 -1
- package/dist/web/assets/{PlaygroundPage-Bb4X1bvp.js → PlaygroundPage-zg5tjWQs.js} +1 -1
- package/dist/web/assets/SettingsPage-BU0is_e7.js +1 -0
- package/dist/web/assets/SheetEditor-4nXVP3NN.js +16 -0
- package/dist/web/assets/{Toolbar-Bk3LKZfg.js → Toolbar-xB4u1mY1.js} +1 -1
- package/dist/web/assets/{VisitorPickerModal-zafJ6beK.js → VisitorPickerModal-Djpm5bTf.js} +1 -1
- package/dist/web/assets/{check-BMeXlsHC.js → check--tqH9AMO.js} +1 -1
- package/dist/web/assets/{copy-CCsiKd_j.js → copy-5mwMd6zK.js} +1 -1
- package/dist/web/assets/{docPlainCharCount-BjBZaoHy.js → docPlainCharCount-CTaZfi-M.js} +1 -1
- package/dist/web/assets/{index-3B7_9QOQ.js → index-CINfyH_g.js} +17 -17
- package/dist/web/assets/index-DCgILSIv.css +1 -0
- package/dist/web/assets/{italic-B6bGjo1_.js → italic-phhei7W3.js} +1 -1
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-9HAADQ7Y.js → meta2dEngine-BD2XbzaV-BDjANcdr.js} +1 -1
- package/dist/web/assets/{plus-BD44y7Zf.js → plus-BxZJ-Mya.js} +1 -1
- package/dist/web/assets/{react-2y9P8xJn.js → react-8gAAnUbI.js} +5 -5
- package/dist/web/index.html +2 -2
- package/package.json +2 -2
- package/dist/web/assets/DocChrome-wfHrPEB7.js +0 -11
- package/dist/web/assets/DocumentEditor-CCuqHlmF.js +0 -1
- package/dist/web/assets/SettingsPage-B4INgMK-.js +0 -1
- package/dist/web/assets/SheetEditor-Cka57s62.js +0 -16
- package/dist/web/assets/index-BF754bDB.css +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as n,j as a}from"./react-vendor-BVS1XoFi.js";import{ad as ge}from"./ui-CEFkTVnG.js";import{g as be,u as Ee,a as ve,s as We,d as Ge,b as xe,c as Ye,f as Je,e as $e,h as Ke,N as Xe,S as Qe,l as Ze,r as pe,i as et,j as tt,D as ee,k as nt,m as at,n as Ie}from"./index-CINfyH_g.js";import{z as it,A as rt,m as ce,n as ot,o as st,p as ct,r as lt,s as ut,t as dt,v as mt,x as ft,B as ht,R as yt,a as gt,b as ke,c as vt,d as xt,e as It,f as kt,g as St,h as Ct,i as wt,w as le,j as bt,O as Et,E as Mt,q as Dt,l as Rt,C as jt,D as At}from"./react-8gAAnUbI.js";import{H as Nt,a as Tt,b as Pt,M as Bt,T as Lt,S as Ot,W as _t,o as zt,c as Se}from"./Toolbar-xB4u1mY1.js";import{D as Ft}from"./DocChrome-C5syeHbQ.js";import{V as Ht}from"./VisitorPickerModal-Djpm5bTf.js";import{c as Ut,U as qt,S as Vt}from"./docPlainCharCount-CTaZfi-M.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./editor-DBWWidi3.js";import"./plus-BxZJ-Mya.js";import"./check--tqH9AMO.js";import"./copy-5mwMd6zK.js";import"./italic-phhei7W3.js";import"./file-type-policy-C6Nun42Q.js";const Wt=48;function te(e){try{const r=e.getDocument("markdown");return typeof r=="string"?r:""}catch{return null}}function Gt(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function Yt({editor:e,documentId:r,displayName:l,debounceMs:g=1e3,enabled:y=!0,localBaseCommitIdAtEditStart:C,snapshotMeta:D,seedDraftExists:F=!1}){const[H,_]=n.useState(!1),[ne,T]=n.useState(F),[P,w]=n.useState(null),d=n.useRef(null),h=n.useRef(null),I=n.useRef(!1),x=n.useRef(""),v=n.useRef(!1),z=n.useRef(r),U=n.useRef(l),B=n.useRef(C),J=n.useRef(D);z.current=r,U.current=l,B.current=C,J.current=D;const b=n.useCallback(async()=>{if(!e)return;if(!x.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const c=Gt(e);c!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",z.current,"content preview:",c.slice(0,80)),await be(z.current).execute(()=>Ee({documentId:z.current,content:c,displayName:U.current,localBaseCommitIdAtEditStart:B.current,snapshotMeta:J.current})),x.current=te(e)??x.current,T(!0),_(!1),w(Date.now()),I.current=!0,v.current=!1)},[e]);n.useEffect(()=>{let c=!1;const f=xe();return ve(r).then(m=>{if(c||xe()!==f)return;const R=!!(m&&!m.published);T(R),R&&m?(w(m.updatedAt),I.current=!0):(w(null),I.current=!1,v.current=!1)}),()=>{c=!0}},[r]),n.useEffect(()=>We((c,f)=>{c===z.current&&(T(f),f||(w(null),I.current=!1))}),[]),n.useEffect(()=>{var W,k;if(!y){(W=h.current)==null||W.call(h),h.current=null;return}if(!e)return;const c=e.getLexicalEditor();if(!c)return;(k=h.current)==null||k.call(h);let f=!1,m=0,R=0;const V=()=>{if(f)return;const E=te(e);if(E===null){if(R+=1,R>Wt)return;m=requestAnimationFrame(V);return}x.current=E;const G=c.registerUpdateListener(()=>{const L=te(e);L!==null&&L!==x.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",r,"oldLen:",x.current.length,"newLen:",L.length),x.current=L,_(!0),v.current=!0,I.current=!1,d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{d.current=null,b()},g))});h.current=()=>{G(),d.current&&(clearTimeout(d.current),d.current=null)}};return queueMicrotask(()=>{f||(m=requestAnimationFrame(V))}),()=>{var E;f=!0,cancelAnimationFrame(m),(E=h.current)==null||E.call(h)}},[y,e,r,l,g,C,D,b]),n.useEffect(()=>{var m;if(!y||!e)return;const c=(m=e.getLexicalEditor())==null?void 0:m.getRootElement();if(!c)return;const f=()=>{d.current&&(clearTimeout(d.current),d.current=null),v.current&&b()};return c.addEventListener("blur",f),()=>c.removeEventListener("blur",f)},[y,e,b]),n.useEffect(()=>{if(!y)return;const c=()=>{document.visibilityState==="hidden"&&(d.current&&(clearTimeout(d.current),d.current=null),v.current&&b())},f=()=>{v.current&&(d.current&&(clearTimeout(d.current),d.current=null),b())};return document.addEventListener("visibilitychange",c),window.addEventListener("beforeunload",f),()=>{document.removeEventListener("visibilitychange",c),window.removeEventListener("beforeunload",f)}},[y,b]);async function $(){await Ge(r),T(!1),_(!1),v.current=!1,I.current=!1,x.current=""}async function K(){const c=await ve(r);return c?c.content:null}function q(){T(!0),_(!1),v.current=!1,w(Date.now()),I.current=!0,e&&(x.current=te(e)??"")}return{isDirty:H,draftExists:ne,lastSavedAt:P,clearDraft:$,loadDraftContent:K,markDraftSaved:q}}function Jt({isDirty:e,draftExists:r}){const l=e&&!r;n.useEffect(()=>{if(!l)return;const g=y=>{y.preventDefault()};return window.addEventListener("beforeunload",g),()=>window.removeEventListener("beforeunload",g)},[l])}function ue(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const Ce='{"root":{"direction":"ltr","format":"","indent":0,"version":1,"type":"root","children":[{"direction":"ltr","format":"","indent":0,"version":1,"textFormat":0,"textStyle":"","children":[],"type":"paragraph"}]}}';function we(e){const l=(e instanceof Error?e.message:String(e)).trim();return/^File too large$/i.test(l)?"文件过大(单文件上限 55MB)":/^unsupported file type$/i.test(l)?"不支持的文件类型":/^not an image$/i.test(l)?"不是有效的图片文件":l||"上传失败"}function $t(e,r){if(!e)return r==="json"?Ce:e;if(r!=="json")return e;try{const l=JSON.parse(e);if(l!=null&&l.root&&Array.isArray(l.root.children)&&l.root.children.length===0)return Ce}catch{}return e}function Kt({editor:e}){const{visible:r}=jt();return a.jsx("div",{className:"mdocs-outline-siderail",style:{flexShrink:0,overflow:"hidden",transition:"width 0.2s ease",width:r?200:0},children:a.jsx("div",{style:{width:200},children:a.jsx(At,{editor:e})})})}function fn(e){const{t:r,lang:l}=Ye(),[g,y]=n.useState(!1),[C,D]=n.useState(!1),F=n.useRef(null),H=n.useRef(null),[_,ne]=n.useState([]),[T,P]=n.useState(!1),[w,d]=n.useState(e.meta.permission),[h,I]=n.useState(!1),[x,v]=n.useState(!1),[z,U]=n.useState(!1),[B,J]=n.useState(new Map),[b,$]=n.useState(!1),[K,q]=n.useState(null),c=n.useRef(0);n.useEffect(()=>{const t=i=>{F.current&&!F.current.contains(i.target)&&y(!1),H.current&&!H.current.contains(i.target)&&D(!1)};return(g||C)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[g,C]),n.useEffect(()=>{let t=!0;return Je().then(i=>{t&&ne(i)}).catch(()=>{}),()=>{t=!1}},[]);function f(t){const i=_.find(o=>o.visitorId===t);return(i==null?void 0:i.visitorName)??t.slice(0,8)}const[m,R]=n.useState(e.initialDisplayName),[V,W]=n.useState(!1),[k,E]=n.useState(!1),[G,L]=n.useState(!1),[Me,De]=n.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),ae=e.canEdit&&Me,[u,de]=n.useState(null),[Re,me]=n.useState(!1),ie=n.useRef(null);n.useLayoutEffect(()=>{me(!1),de(null),ie.current=null},[e.meta.documentId]),n.useEffect(()=>{const t=requestAnimationFrame(()=>me(!0));return()=>cancelAnimationFrame(t)},[e.meta.documentId]),n.useEffect(()=>{if(!g&&!C)return;const t=++c.current;q(null);const i=()=>{if(t===c.current)try{let s=e.initialContent||"";if(u)try{const N=u.getDocument("markdown");typeof N=="string"&&(s=N)}catch{}const S=Ut("md",s);t===c.current&&q(S)}catch{t===c.current&&q(0)}},o=window;if(typeof o.requestIdleCallback=="function"){const s=o.requestIdleCallback(i);return()=>{var S;return(S=o.cancelIdleCallback)==null?void 0:S.call(o,s)}}const M=window.setTimeout(i,0);return()=>window.clearTimeout(M)},[g,C,u,e.initialContent,e.meta.documentId,e.contentRevision]);const j=n.useMemo(()=>{var t;if(!e.initialContent)return"json";try{const i=JSON.parse(e.initialContent);return Array.isArray((t=i==null?void 0:i.root)==null?void 0:t.children)?"json":"markdown"}catch{return"markdown"}},[e.initialContent,e.contentRevision]),X=n.useMemo(()=>$t(e.initialContent||"",j),[e.initialContent,j,e.contentRevision]),{isDirty:fe,draftExists:Q,markDraftSaved:je}=Yt({editor:u,documentId:e.meta.documentId,displayName:m,enabled:e.canEdit,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId},seedDraftExists:e.hasLocalDraft});n.useEffect(()=>{var t;(t=e.onDraftExistsChange)==null||t.call(e,Q)},[Q,e.onDraftExistsChange]),Jt({isDirty:fe,draftExists:Q}),n.useEffect(()=>{if(u)try{u.setDocument(j,X)}catch{}},[u,e.meta.documentId,e.contentRevision,j]),n.useEffect(()=>{u==null||u.setLocale(l==="zh"?it:rt)},[u,l]),n.useEffect(()=>{R(e.initialDisplayName)},[e.initialDisplayName,e.meta.documentId,e.contentRevision]),n.useEffect(()=>{d(e.meta.permission)},[e.meta.permission,e.meta.documentId]),n.useEffect(()=>{let t=!0;return(async()=>{try{const i=await $e(e.meta.documentId);t&&E(i.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function re(){var t,i;if(!G){L(!0);try{k?(await pe(e.meta.documentId),E(!1),(t=e.onShowToast)==null||t.call(e,r("bookmarkRemoved"))):(await et(e.meta.documentId),E(!0),(i=e.onShowToast)==null||i.call(e,r("bookmarkAdded")))}finally{L(!1)}}}n.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=_e),()=>{e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=void 0)})),n.useEffect(()=>{if(e.exportMarkdownRef)return e.exportMarkdownRef.current=()=>{const t=ie.current;if(!t)return"";try{const i=t.getDocument("markdown");return typeof i=="string"?i:String(i??"")}catch{return""}},()=>{e.exportMarkdownRef&&(e.exportMarkdownRef.current=void 0)}});function Ae(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const Ne=n.useCallback(t=>{ie.current=t,de(t);const i=X;if(!i)return;const o=()=>{try{t.setDocument(j,i)}catch{requestAnimationFrame(()=>{try{t.setDocument(j,i)}catch{}})}};queueMicrotask(()=>{queueMicrotask(o)})},[j,X]);async function he(){if(!u||!e.canEdit)return;const t=document.querySelector(".mdocs-editor-scroll-host"),i=(t==null?void 0:t.scrollTop)??null;W(!0);try{const o=ue(u);if(!o)return;await e.onPublish(o,m,e.meta.documentId)}catch(o){throw o}finally{W(!1),t&&i!=null&&(t.scrollTop=i,requestAnimationFrame(()=>{t.scrollTop=i}))}}async function Te(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(m.trim()!==t)try{await he()}catch{}}const A=n.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),Pe=n.useMemo(()=>{const t=(A==null?void 0:A.permission)??"public";return Ke(t)},[A==null?void 0:A.permission]);function Be(t){return t===ee.PRIVATE?r("permissionPrivate"):t===ee.DOMAIN_READ?r("permissionInvite"):t===ee.DOMAIN_WRITE?r("permissionDomainWrite"):t===ee.PUBLIC_READ?r("permissionPublicRead"):r("permissionPublicEdit")}async function Le(){var t;if(h||w===e.meta.permission){P(!1);return}I(!0);try{const o=(u?ue(u):null)??e.initialContent;await e.onPublish(o,m,e.meta.documentId,w),P(!1),(t=e.onShowToast)==null||t.call(e,r("docInfoPermissionUpdated"))}finally{I(!1)}}async function Oe(t){var i;if(!b){$(!0);try{const o=new Set(t.map(s=>s.visitorId)),M=new Map(t.map(s=>[s.visitorId,s.permission]));for(const[s]of B)o.has(s)||await nt(e.meta.documentId,s);for(const{visitorId:s,permission:S}of t){const N=B.get(s);(!N||N!==S)&&await at(e.meta.documentId,s,S)}v(!1),(i=e.onShowToast)==null||i.call(e,r("docInfoInviteSuccess",{count:t.length}))}finally{$(!1)}}}async function _e(){if(!u||!e.canEdit)return;if(!fe){console.log("[DocumentEditor.saveDraft] skipped: not dirty, documentId:",e.meta.documentId);return}const t=ue(u);t&&(console.log("[DocumentEditor.saveDraft] saving draft, documentId:",e.meta.documentId,"content preview:",t.slice(0,80)),je(),await be(e.meta.documentId).execute(()=>Ee({documentId:e.meta.documentId,content:t,displayName:m,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const ze=n.useMemo(()=>[{icon:Nt,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(ce,{tag:"h1"})}},{icon:Tt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(ce,{tag:"h2"})}},{icon:Pt,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(ce,{tag:"h3"})}},{type:"divider"},{icon:Bt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(ot,{})}},{icon:Lt,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand(st,{columns:"3",rows:"3"})}},{icon:Ot,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(ct,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{zt(i=>{for(const o of i)t.dispatchCommand(Dt,{file:o})},".pdf,.zip,.txt,.md,.csv,.html,.htm,audio/*,*/*")}},{key:"insert-link",label:"Insert Link",onSelect:t=>{t.dispatchCommand(lt,{url:"https://example.com"}),queueMicrotask(()=>t.focus())}},{key:"insert-codeInline",label:"Inline Code",onSelect:t=>{t.dispatchCommand(ut,void 0),queueMicrotask(()=>t.focus())}},{key:"insert-codeBlock",label:"Code Block",onSelect:t=>{t.dispatchCommand(dt,void 0),queueMicrotask(()=>t.focus())}},{icon:_t,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(mt,void 0),queueMicrotask(()=>t.focus())}},{icon:Xe,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(ft,void 0),queueMicrotask(()=>t.focus())}}].map(t=>"type"in t&&t.type==="divider"?t:{...t,extra:a.jsx("span",{style:{color:"var(--mdocs-text-muted)",fontFamily:"monospace",fontSize:12},children:t.key})}),[]),Fe=n.useMemo(()=>[ht,yt,gt,ke,vt,xt,It,kt,St,Ct,wt,le(bt,{children:u?a.jsx(Se,{editor:u,floating:!0,outlineCollapseTitle:r("outlineHide"),outlineExpandTitle:r("outlineShow"),outlineToggle:!0}):null}),le(Rt,{handleUpload:async t=>{var i;try{return{url:await Ie(t,e.meta.documentId)}}catch(o){throw(i=e.onShowError)==null||i.call(e,we(o)),o}}}),le(ke,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var i;try{const M=await(await fetch(t)).blob(),s=new File([M],"image.png",{type:M.type});return{url:await Ie(s,e.meta.documentId)}}catch(o){throw(i=e.onShowError)==null||i.call(e,we(o)),o}}})],[u,r,e.meta.documentId,e.onShowError]),O=!!e.readerChrome,[Y,oe]=n.useState(!1),Z=n.useRef(null),[He,se]=n.useState(0);n.useEffect(()=>{if(!O){oe(!1),se(0);return}if(Y)return;const t=window.setTimeout(()=>oe(!0),2800);return()=>window.clearTimeout(t)},[O,Y,e.meta.documentId]),n.useEffect(()=>{D(!1),y(!1)},[e.meta.documentId]);function Ue(t){!O||Y||t.target.closest("button, a, input, textarea, select")||(Z.current={startY:t.clientY,dragging:!0},t.currentTarget.setPointerCapture(t.pointerId))}function qe(t){const i=Z.current;if(!(i!=null&&i.dragging))return;const o=t.clientY-i.startY;se(Math.max(-72,Math.min(0,o)))}function Ve(t){const i=Z.current;if(!(i!=null&&i.dragging))return;Z.current=null;const o=t.clientY-i.startY;se(0),o<-36&&oe(!0);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}function p(){y(!1),D(!1)}function ye(t,i){const o=(i==null?void 0:i.includeBookmark)??!0,M={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return a.jsxs(a.Fragment,{children:[a.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoCreator")}),a.jsx("span",{children:f(e.meta.ownerVisitorId)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoCreatedAt")}),a.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(l==="zh"?"zh-CN":"en-US")})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoSize")}),a.jsx("span",{children:Ae(new Blob([e.initialContent]).size)})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoCharCount")}),a.jsx("span",{children:K===null?"…":K.toLocaleString(l==="zh"?"zh-CN":"en-US")})]}),a.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[a.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:r("docInfoUpdatedAt")}),a.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(l==="zh"?"zh-CN":"en-US")})]})]}),a.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),o?a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{re(),t()},children:[a.jsx("span",{children:k?"⭐":"☆"}),a.jsx("span",{children:r(k?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{t(),(async()=>{U(!0);try{const s=await tt(e.meta.documentId),S=new Map(s.map(N=>[N.visitorId,N.permission]));J(S),v(!0)}finally{U(!1)}})()},children:[a.jsx(qt,{size:14}),a.jsx("span",{children:r("docInfoInviteMember")})]}):null,a.jsxs("button",{type:"button",style:M,onMouseEnter:s=>{s.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:s=>{s.currentTarget.style.background="none"},onClick:()=>{t(),d(e.meta.permission),P(!0)},children:[a.jsx(Vt,{size:14}),a.jsx("span",{children:r("docInfoChangePermission")})]})]})}return a.jsxs("div",{className:"mdocs-editor"+(O?" mdocs-editor--reader":"")+(O&&Y?" mdocs-editor--reader-docked":""),children:[a.jsx(Ft,{fileType:e.meta.fileType||"md",displayName:m,onDisplayNameChange:R,onDisplayNameBlur:()=>void Te(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:ae,onEnterEdit:()=>De(!0),onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:V,draftExists:Q,onPublish:()=>{he().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:k,bookmarkBusy:G,onToggleBookmark:()=>void re(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:ye(p),docInfoOpen:g,onToggleDocInfo:()=>y(!g),docInfoMenuRef:F,readerChrome:O,onOpenMobileNav:e.onOpenMobileNav,readerHeaderDocked:Y,readerDragOffset:He,onReaderHeaderPointerDown:Ue,onReaderHeaderPointerMove:qe,onReaderHeaderPointerUp:Ve,readerMoreOpen:C,onToggleReaderMore:()=>D(t=>!t),readerMoreMenuRef:H,readerMoreMenu:a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:G,onClick:()=>{re(),p()},children:[a.jsx(Qe,{size:16,strokeWidth:1.5,style:{color:k?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:k?"#faad14":"none"}}),a.jsx("span",{children:r(k?"bookmarkRemove":"bookmarkAdd")})]}),e.canEdit?a.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:V,onClick:()=>{p(),e.onDelete()},children:a.jsx("span",{children:r("delete")})}):null,a.jsx("div",{className:"mdocs-reader-more-divider"}),ye(p,{includeBookmark:!1})]})}),T&&a.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&P(!1)},children:a.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[a.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:r("docInfoChangePermission")}),a.jsxs("div",{className:"muted",style:{marginBottom:12},children:[r("domainPermission"),":",A?Ze(A.domainName,l,r):e.meta.domainId]}),a.jsx("div",{style:{display:"grid",gap:8},children:Pe.map(t=>a.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[a.jsx("input",{type:"radio",name:"doc-permission",value:t,checked:w===t,onChange:()=>d(t)}),a.jsx("span",{children:Be(t)})]},t))}),a.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[a.jsx("button",{type:"button",onClick:()=>P(!1),children:r("cancel")}),a.jsx("button",{type:"button",className:"primary",disabled:h,onClick:()=>void Le(),children:r(h?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&a.jsx(Ht,{open:x,title:r("docInfoInviteMember"),initialSelectedIds:[...B.keys()],initialPermissions:B,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:r("invitePermissionRead")},{value:"edit",label:r("invitePermissionEdit")}],onClose:()=>v(!1),onConfirm:t=>{Oe(t)}}),a.jsx(Et,{children:a.jsx(ge,{flex:1,style:{minHeight:0},children:a.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[ae&&u&&!O?a.jsx(Se,{editor:u,outlineCollapseTitle:r("outlineHide"),outlineExpandTitle:r("outlineShow"),outlineToggle:!0}):null,a.jsx("div",{className:"mdocs-editor-content-area",style:{flex:1,display:"flex",minHeight:0},children:a.jsxs(ge,{variant:"outlined",horizontal:!0,style:{background:"var(--mdocs-surface)",flex:1,minHeight:0,minWidth:0,borderRadius:0,outline:"none"},children:[a.jsx("div",{className:"mdocs-editor-scroll-host",children:Re?a.jsx(Mt,{content:X,type:j,confirmPasteMarkdown:!0,editable:ae,onInit:Ne,plugins:Fe,lineEmptyPlaceholder:r("displayNamePlaceholder"),placeholder:r("displayNamePlaceholder"),slashOption:{items:ze},className:"mdocs-document-editor-root"},e.meta.documentId):null}),u&&a.jsx(Kt,{editor:u})]})})]})})})]})}export{fn as DocumentEditor};
|
|
@@ -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-3B7_9QOQ.js";import{D as Me}from"./DocChrome-wfHrPEB7.js";import{V as Be}from"./VisitorPickerModal-zafJ6beK.js";import{c as Re,U as Ae,S as Te}from"./docPlainCharCount-BjBZaoHy.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-CINfyH_g.js";import{D as Me}from"./DocChrome-C5syeHbQ.js";import{V as Be}from"./VisitorPickerModal-Djpm5bTf.js";import{c as Re,U as Ae,S as Te}from"./docPlainCharCount-CTaZfi-M.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,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,b3 as H,b4 as Y,b5 as Z,b6 as ee}from"./index-CINfyH_g.js";import{E as te,B as ne}from"./react-8gAAnUbI.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-BxZJ-Mya.js";import"./check--tqH9AMO.js";import"./copy-5mwMd6zK.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-8gAAnUbI.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-xB4u1mY1.js";import{N as me}from"./index-CINfyH_g.js";import"./editor-DBWWidi3.js";import"./diagram-BF8g9yg4.js";import"./plus-BxZJ-Mya.js";import"./check--tqH9AMO.js";import"./copy-5mwMd6zK.js";import"./motion-BAXVQJfN.js";import"./italic-phhei7W3.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 @@
|
|
|
1
|
+
import{r as t,j as e}from"./react-vendor-BVS1XoFi.js";import{c as ie,$ as Es,a0 as Rs,V as Fs,l as de,a1 as zs,a2 as Ls,a3 as ee,a4 as Oe,a5 as Bs,a6 as Os,a7 as Us,a as Ks,d as Ze,a8 as ls,a9 as os,aa as $s,ab as Vs,ac as Ws,ad as _s,ae as Gs,af as rs,ag as ze,ah as qs,ai as Hs,aj as Js,X as Zs,ak as Ys,al as Qs,f as ds,am as Xs,an as et,ao as st,ap as tt,aq as at,ar as ms,as as nt,at as it,au as ct,av as lt,aw as ot,ax as rt,ay as dt,az as us,aA as mt,aB as ut,aC as ht,aD as pt,aE as gt,aF as ft,aG as xt,aH as yt,aI as bt,U as jt,aJ as Nt,aK as vt,aL as kt,aM as St,r as wt,j as Ct,aN as Dt,k as It,m as Tt}from"./index-CINfyH_g.js";import{V as hs,a as At,M as Ye}from"./VisitorPickerModal-Djpm5bTf.js";import{C as Mt}from"./check--tqH9AMO.js";import{ai as Le,aj as Pt,ak as Et,al as Rt,am as Ft,an as zt,ao as Qe,ap as Lt,aq as Xe}from"./ui-CEFkTVnG.js";import"./diagram-BF8g9yg4.js";import"./motion-BAXVQJfN.js";function Bt({draft:a,onClose:s,onSuccess:g}){const{t:u,lang:y}=ie(),[z,x]=t.useState([]),[S,v]=t.useState(a.domainId??""),[p,w]=t.useState([]),[A,I]=t.useState(""),[c,N]=t.useState(`${a.displayName||"untitled"}_recovered.md`),[f,m]=t.useState(!1),[D,M]=t.useState(null),b=t.useRef(null),R=t.useRef(!0);t.useEffect(()=>(R.current=!0,()=>{R.current=!1}),[]),t.useEffect(()=>{Es().then(k=>{R.current&&x(k)})},[]),t.useEffect(()=>{S&&(w([]),I(""),Rs(S).then(k=>{R.current&&w(k)}).catch(()=>{R.current&&w([])}))},[S]),t.useEffect(()=>{const k=window.setTimeout(()=>{var P;return(P=b.current)==null?void 0:P.focus()},0);return()=>window.clearTimeout(k)},[]),t.useEffect(()=>{const k=P=>{P.key==="Escape"&&s()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[s]);function O(k,P){for(const C of k){if(C.type==="folder"&&C.path===P)return C.documentId;if(C.type==="folder"){const F=O(C.children,P);if(F)return F}}return null}async function L(k){k.preventDefault(),m(!0),M(null);const P=c.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),C=P.endsWith(".md")?P:P+".md",F=C.replace(/\.md$/i,"");try{const h=A?`${A}/${C}`:C,d=A?O(p,A)??void 0:void 0;await Ls({fileName:C,displayName:F,content:a.content,domainId:S,parentId:d}),g()}catch(h){M(ee(u,h))}finally{m(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:k=>{k.target===k.currentTarget&&!f&&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:L,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[u("domainLabel"),z.length>0&&e.jsx(Fs,{domains:z,value:S,onChange:v,onDomainsChange:x,ariaLabel:u("domainLabel"),localizeName:k=>de(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(zs,{nodes:p,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=>N(k.target.value),placeholder:"recovered.md",maxLength:200,disabled:f})]}),D&&e.jsx("div",{className:"mdocs-dialog-error",children:D}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!f&&s(),disabled:f,children:u("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:f,children:u(f?"creating":"create")})]})]})]})})}function Ot({onPublish:a,onClose:s,onCountChange:g,onRecover:u}){const{t:y}=ie(),[z,x]=t.useState([]),[S,v]=t.useState(new Set),[p,w]=t.useState(!1),[A,I]=t.useState(null),[c,N]=t.useState(null),[f,m]=t.useState(null),D=t.useRef(null),M=t.useRef(!0);t.useEffect(()=>(M.current=!0,Oe().then(d=>{if(!M.current)return;const j=d.filter(T=>!T.published);x(j),g==null||g(j.length)}),()=>{M.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)=>{m({message:d,type:j}),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>m(null),3e3)},[]);async function R(d){await Os(d),v(j=>new Set(j).add(d));try{await a(d),x(j=>{const T=j.filter(K=>K.documentId!==d);return g==null||g(T.length),T}),b(y("published"),"success")}catch(j){j instanceof Us||b(y("publishFailed"),"error");const T=await Ks(d);T&&x(K=>K.map(G=>G.documentId===d?T:G))}finally{v(j=>{const T=new Set(j);return T.delete(d),T})}}async function O(d){I(null),await Ze(d),x(j=>{const T=j.filter(K=>K.documentId!==d);return g==null||g(T.length),T}),b(y("draftDeleted"),"success")}function L(d){const j=z.find(T=>T.documentId===d);j&&N(j)}function k(d){N(null),Ze(d),x(j=>{const T=j.filter(K=>K.documentId!==d);return g==null||g(T.length),T}),u==null||u(z.find(j=>j.documentId===d)),b(y("published"),"success")}async function P(){w(!0);let d=0,j=0;for(const G of z)try{await a(G.documentId),d++}catch{j++}const K=(await Oe()).filter(G=>!G.published);x(K),g==null||g(K.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=>Bs(y,d,d.publishError??"UNKNOWN"),h=z;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"),h.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:h.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:y("draftCount",{count:String(h.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:h.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:h.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:p,onClick:()=>L(d.documentId),children:y("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:S.has(d.documentId)||p,onClick:()=>void R(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:p,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:h.length===0||p,onClick:()=>void P(),children:p?y("publishing"):`${y("publishAll")} (${h.length})`})]}),f&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+f.type,role:"status",children:f.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 O(A),children:y("delete")})]})]})}),c&&e.jsx(Bt,{draft:c,onClose:()=>N(null),onSuccess:()=>k(c.documentId)})]})}function Ut(){const{t:a,lang:s}=ie(),g=ls(),u=t.useRef(!1),[y,z]=t.useState([]),[x,S]=t.useState(!1),[v,p]=t.useState(""),[w,A]=t.useState("restricted"),[I,c]=t.useState(!1),[N,f]=t.useState(null),[m,D]=t.useState(null),[M,b]=t.useState(""),[R,O]=t.useState(""),[L,k]=t.useState("all"),[P,C]=t.useState(null);t.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]);const F=t.useCallback(async()=>{S(!0),f(null);try{const i=await os();if(!u.current)return;z(i)}catch(i){if(!u.current)return;f(ee(a,i))}finally{u.current&&S(!1)}},[a]);t.useEffect(()=>{F()},[F]);async function h(i){if(i.preventDefault(),!v.trim()){f(a("domainNameRequired"));return}c(!0),f(null);try{if(await Gs({domainName:v.trim(),permission:w}),!u.current)return;p(""),A("restricted"),await F()}catch(r){if(!u.current)return;f(ee(a,r))}finally{u.current&&c(!1)}}async function d(i){if(M.trim()){f(null);try{if(await _s(i,M.trim()),!u.current)return;D(null),C(null),await F()}catch(r){if(!u.current)return;f(ee(a,r))}}}function j(i){D(i.domainId),b(i.domainName),C(null)}function T(){D(null),C(null)}async function K(i,r){f(null);try{if(await Ws(i,r),!u.current)return;C(null),await F()}catch(U){if(!u.current)return;f(ee(a,U))}}async function G(i){if(window.confirm(a("deleteDomainConfirmDetail",{name:i.domainName,count:String(i.docCount)}))){f(null);try{if(await Vs(i.domainId),!u.current)return;await F()}catch(r){if(!u.current)return;f(ee(a,r))}}}const J=t.useCallback(i=>$s(i,a),[a]),Z=t.useCallback(i=>de(i.domainName,s,a),[s,a]),Q=t.useMemo(()=>{const i=R.trim().toLowerCase();return y.filter(r=>L!=="all"&&r.permission!==L?!1:i?de(r.domainName,s,a).toLowerCase().includes(i)||r.domainName.toLowerCase().includes(i):!0)},[y,R,L,s,a]),q=t.useCallback((i,r)=>{const U=J(i.permission);return r?`${U} ${a("domainTypeBuiltinSuffix")}`:U},[J,a]);return{domains:y,loadingDomains:x,domainError:N,newDomainName:v,setNewDomainName:p,newDomainPermission:w,setNewDomainPermission:A,creating:I,handleCreateDomain:h,renamingId:m,setRenamingId:D,renameDraft:M,setRenameDraft:b,startRename:j,cancelRename:T,handleRename:d,changeTypeForId:P,setChangeTypeForId:C,handlePermissionChange:K,handleDelete:G,domainSearch:R,setDomainSearch:O,domainFilter:L,setDomainFilter:k,filteredDomains:Q,visitorId:g,plabel:J,localizeDomain:Z,domainTypeLabel:q}}const es={private:0,restricted:1,public:2};function ss(a){return Object.prototype.hasOwnProperty.call(es,a)?es[a]:null}function ts(a,s){const g=ss(a),u=ss(s);return g===null||u===null?"invalid":u>g?"upgrade":u<g?"downgrade":"same"}function Kt(){const{t:a}=ie(),s=Ut(),[g,u]=t.useState([]),[y,z]=t.useState(null),[x,S]=t.useState(""),v=t.useRef(null),[p,w]=t.useState(null),A=t.useCallback(async()=>{try{const c=await rs();u(c)}catch{u([])}},[]);t.useEffect(()=>{A()},[A]),t.useEffect(()=>{if(!s.changeTypeForId)return;const c=N=>{var f;(f=v.current)!=null&&f.contains(N.target)||s.setChangeTypeForId(null)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s.changeTypeForId,s.setChangeTypeForId]);async function I(c){z(null);try{const N=await Qs(c.domainId);w({domainId:c.domainId,creatorVisitorId:c.creatorVisitorId,initialIds:N.map(f=>f.visitorId),memberRows:N})}catch(N){z({kind:"err",text:translateError(a,N)})}}return e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children: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:ze.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",...ze].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 N=qs(c,s.visitorId),f=Hs(c.domainId),m=Js(c),D=ts(c.permission,"public")==="upgrade",M=D?m?a("domainTooltipTypeLocked"):void 0:a("domainPermissionAlreadyTop");return e.jsxs("tr",{className:f?"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)}),f&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:a("domainBuiltIn")}),!N&&!f&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:a("shared")})]})}),e.jsx("td",{children:e.jsx("span",{className:"mdocs-domain-table-type",title:M,children:e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":c.permission,children:s.domainTypeLabel(c,f)})})}),e.jsx("td",{className:"mdocs-domain-table-num",children:c.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[f&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:a("domainNotModifiable")}),!f&&!N&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:a("domainNotCreator")}),!f&&N&&s.changeTypeForId===c.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",ref:v,children:[e.jsx("div",{className:"mdocs-domain-type-segment",role:"radiogroup","aria-label":a("domainChangeType"),children:ze.map(b=>{const O=ts(c.permission,b)==="downgrade";return e.jsx("span",{title:O?a("domainPermissionNoDowngrade"):void 0,children:e.jsx("button",{type:"button",role:"radio","aria-checked":x===b,className:x===b?"active":"",disabled:O,onClick:()=>S(b),children:s.plabel(b)})},b)})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon confirm","aria-label":a("save"),disabled:x===""||x===c.permission,onClick:()=>{x&&x!==c.permission&&s.handlePermissionChange(c.domainId,x)},children:e.jsx(Mt,{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(Zs,{size:14,strokeWidth:2.5})})]}),!f&&N&&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:m?a("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(c)},disabled:m,children:a("rename")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:M,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:m?a("domainLocked"):void 0,onClick:()=>void s.handleDelete(c),disabled:m,children:a("deleteDomain")})]})]})]},c.domainId)})})]})})]}),e.jsx(hs,{open:p!==null,title:a("domainMembersPickerTitle"),initialSelectedIds:(p==null?void 0:p.initialIds)??[],lockedIds:p?[p.creatorVisitorId]:[],seedMembers:p==null?void 0:p.memberRows,templates:g,onClose:()=>w(null),onConfirm:async c=>{p&&(await Ys(p.domainId,c),z({kind:"ok",text:a("domainMembersSaved",{count:String(c.length)})}))}})]})}function as(a){return a.length<=6?a:`${a.slice(0,6)}…`}function $t(){const{t:a}=ie(),s=t.useRef(!0),[g,u]=t.useState([]),[y,z]=t.useState(!0),[x,S]=t.useState(null),[v,p]=t.useState(1),[w,A]=t.useState(null),[I,c]=t.useState(""),[N,f]=t.useState([]),[m,D]=t.useState(!1),[M,b]=t.useState(null),[R,O]=t.useState(!1),L=ls(),[k,P]=t.useState([]),[C,F]=t.useState("idle"),[h,d]=t.useState("");t.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),t.useEffect(()=>{F("loading"),ds().then(o=>{s.current&&(P(o),F("ok"))}).catch(()=>{s.current&&F("err")})},[]);const j=t.useMemo(()=>{const o=new Map;for(const E of k)o.set(E.visitorId,E.visitorName);return o},[k]),T=t.useCallback(async()=>{z(!0),b(null);try{const o=await rs();s.current&&u(o)}catch(o){s.current&&b(ee(a,o))}finally{s.current&&z(!1)}},[a]);t.useEffect(()=>{T()},[T]);const K=t.useMemo(()=>N.map(o=>{const E=k.find(W=>W.visitorId===o);return{visitorId:o,name:E?E.visitorName:a("visitorPickerUnknownVisitor"),muted:!E}}),[N,k,a]);function G(o){f(E=>E.includes(o)?E.filter(W=>W!==o):[...E,o])}const J=v===1?I.trim().length>0:v===2?N.length>0:!0;function Z(){if(!(v>=3)){if(!J){O(!0);return}O(!1),p(v+1),d("")}}function Q(){v<=1||(O(!1),p(v-1))}function q(){S(null),A(null),c(""),f(L?[L]:[]),b(null),p(1),d(""),O(!1)}function i(o){S(null),A(o.id),c(o.displayName);const E=L&&!o.visitorIds.includes(L)?[...o.visitorIds,L]:[...o.visitorIds];f(E),b(null),p(1),d(""),O(!1)}async function r(){if(!(!I.trim()||N.length===0)){D(!0),b(null);try{if(w===null?await Xs({displayName:I.trim(),visitorIds:N}):await et(w,{displayName:I.trim(),visitorIds:N}),!s.current)return;q(),await T()}catch(o){if(!s.current)return;b(ee(a,o))}finally{s.current&&D(!1)}}}async function U(o){D(!0),b(null);try{if(await st(o),!s.current)return;S(null),w===o&&q(),await T()}catch(E){if(!s.current)return;b(ee(a,E))}finally{s.current&&D(!1)}}const V=[{key:1,label:a("memberTemplateStepName")},{key:2,label:a("memberTemplateStepMembers")},{key:3,label:a("memberTemplateStepSave")}],$=`${(v-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:q,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:$}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:V.map(o=>{const E=v===o.key,W=v>o.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${E?" current":""}${W?" done":""}`,children:W?"✓":o.key}),e.jsx("span",{className:`mdocs-wizard-step-label${E?" current":""}${W?" done":""}`,children:o.label})]},o.key)})})]}),M&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:M}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[v===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:m,autoFocus:!0,"aria-invalid":R&&!I.trim()}),R&&!I.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:a("domainNameRequired")})]}),v===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(At,{visitors:k,loadState:C,searchFilter:h,onSearchChange:d,selectedIds:new Set(N),onToggle:G,selectedRows:K,myVisitorId:L}),e.jsx("p",{className:`mdocs-wizard-hint${R&&N.length===0?" danger":""}`,children:"💡 "+a("memberTemplateStep2Hint")})]}),v===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(N.length)})})]}),N.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[N.slice(0,15).map(o=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:as(o)},o)),N.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",N.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:Q,children:["← ",a("memberTemplateWizardBack")]}),v<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(m?"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")}):g.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:q,children:a("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:g.map(o=>e.jsx("li",{className:"mdocs-member-template-row",children:x===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 U(o.id),children:a(m?"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(E=>e.jsx("span",{className:"mdocs-member-template-tag",children:j.get(E)??as(E)},E))})]}),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 Vt=[{value:"deepseek-flash",label:"deepseek-flash(V4.1 Flash)"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro(将路由至 Flash)"}],Wt=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function _t(a,s,g){return a==="deepseek"?"Deepseek":s||g}function ns(a){return`${_t(a.kind,a.providerId,a.name)} · ${a.modelId} · ${a.name}`}function Gt(){const{t:a}=ie(),s=t.useRef(!0),[g,u]=t.useState(""),[y,z]=t.useState([]),[x,S]=t.useState(null),[v,p]=t.useState(null),[w,A]=t.useState("deepseek"),[I,c]=t.useState(""),[N,f]=t.useState(""),[m,D]=t.useState(""),[M,b]=t.useState("openai-completions"),[R,O]=t.useState("deepseek-flash"),[L,k]=t.useState(1e6),[P,C]=t.useState(""),[F,h]=t.useState(!1),[d,j]=t.useState(null),[T,K]=t.useState(!1),[G,J]=t.useState(!0),[Z,Q]=t.useState(!1),[q,i]=t.useState(null),[r,U]=t.useState(!1),[V,$]=t.useState(!1),[o,E]=t.useState(!1),[W,se]=t.useState(null),[ce,ae]=t.useState(null),te=t.useRef(!1);t.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]);const ne=t.useCallback(async()=>{const l=await tt();if(s.current)return z(l),l},[]);function le(){p(null),A("deepseek"),c(""),f(""),D(""),b("openai-completions"),O("deepseek-flash"),k(1e6),C(""),h(!1),j(null),K(!1),$(!1),E(!1),i(null),U(!1)}function xe(l){p(l.id),A(l.kind),c(l.name),f(l.providerId??""),D(l.baseUrl),b(l.apiType);const _=l.modelId.trim(),je=new Set(["deepseek-flash","deepseek-v4-flash","deepseek-v4-flash-vision-exp","deepseek-v4.1-flash","deepseek-v4.1-flash-expires-on-0910"]);O(l.kind==="deepseek"?_==="deepseek-v4-pro"?"deepseek-v4-pro":je.has(_)?"deepseek-flash":_||"deepseek-flash":_),k(l.contextWindow||1e6),h(l.hasApiKey),j(l.apiKeyMasked),C(""),K(l.isDefault)}t.useEffect(()=>{(async()=>{try{const l=await at();if(!s.current)return;u(l.visitorName);const _=await ne();if(!s.current||!_)return;_.length===0&&(le(),S("create"))}catch(l){if(!s.current)return;i(l instanceof Error?l.message:String(l)),S("create")}finally{s.current&&J(!1)}})()},[ne]);function we(){le(),S("create")}function ye(l){xe(l),S("edit"),U(!1),i(null)}function oe(){le(),S(null)}async function Ce(l){if(!(l.isDefault||ce)){ae(l.id),i(null);try{await nt(l.id),await ne()}catch(_){if(!s.current)return;i(_ instanceof Error?_.message:String(_))}finally{s.current&&ae(null)}}}async function be(){if(W){Q(!0),i(null);try{await ct(W.id);const l=await ne();if(!s.current)return;x==="edit"&&v===W.id&&oe(),((l==null?void 0:l.length)??0)===0&&(le(),S("create"))}catch(l){if(!s.current)return;i(l instanceof Error?l.message:String(l))}finally{s.current&&(Q(!1),se(null))}}}async function De(){Q(!0),i(null),U(!1);try{const l=w==="custom"?{...x==="edit"&&v?{id:v}:{},...x==="create"&&T?{isDefault:!0}:{},kind:w,baseUrl:m,modelId:R,providerId:N.trim()||void 0,apiType:M,name:I,contextWindow:L,...P.trim()?{apiKey:P.trim()}:{}}:{...x==="edit"&&v?{id:v}:{},...x==="create"&&T?{isDefault:!0}:{},kind:w,modelId:R,name:I,contextWindow:L,...P.trim()?{apiKey:P.trim()}:{}};if(await it(l),!s.current)return;await ne(),U(!0),S(null),le()}catch(l){if(!s.current)return;i(l instanceof Error?l.message:String(l))}finally{s.current&&Q(!1)}}const Ie=x!==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")}),G?null:e.jsx("button",{type:"button",className:"secondary",onClick:we,children:"添加配置"})]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[!G&&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:ce!==null,onChange:()=>void Ce(l)}),e.jsx("span",{children:l.isDefault?"默认":"设为默认"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-main",children:[e.jsx("strong",{children:ns(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:()=>ye(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,q?e.jsx("p",{className:"mdocs-agent-config-error",children:q}):null]}):null,Ie?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsxs("p",{className:"mdocs-agent-config-lead",children:[x==="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(Ye,{options:[...Vt],value:R,onChange:O})]}),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:P,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:()=>$(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:m,onChange:l=>{const _=l.target.value;if(D(_),te.current)return;_.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:R,onChange:l=>O(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:P,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:()=>$(l=>!l),children:V?"隐藏":"显示"})]})]})]}),e.jsxs("details",{className:"mdocs-agent-advanced",open:o,onToggle:l=>E(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:N,onChange:l=>f(l.target.value),placeholder:"不填则自动从 API 地址提取域名"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 协议"}),e.jsx(Ye,{options:[...Wt],value:M,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}}",g||"…")})]}),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:L,onChange:l=>k(Number(l.target.value)||1e6)}),e.jsx("p",{className:"mdocs-agent-field-hint",children:a("agentConfigContextWindowDesc")})]})]}),x==="create"&&y.length>0?e.jsxs("label",{className:"mdocs-agent-config-default-check",children:[e.jsx("input",{type:"checkbox",checked:T,onChange:l=>K(l.target.checked)}),e.jsx("span",{children:"保存后设为默认配置"})]}):null,q?e.jsx("p",{className:"mdocs-agent-config-error",children:q}):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:oe,disabled:Z,children:a("cancel")}):null]})]})]}):G?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(ms,{title:"删除配置",message:`确定删除「${ns(W)}」?${W.isDefault&&y.length>1?" 删除后将自动把另一条设为默认。":""}`,confirmLabel:"删除",cancelLabel:a("cancel"),onConfirm:()=>void be(),onCancel:()=>se(null)}):null]})}const qt=/^[A-Za-z0-9_]+$/;function Be(a){return qt.test(a.trim())}function Ht(){const a=t.useRef(!0),[s,g]=t.useState([]),[u,y]=t.useState(!0),[z,x]=t.useState(null),[S,v]=t.useState(null),[p,w]=t.useState(!1),[A,I]=t.useState(""),[c,N]=t.useState(""),[f,m]=t.useState(""),[D,M]=t.useState(!1);t.useEffect(()=>(a.current=!0,()=>{a.current=!1}),[]);async function b(){y(!0),x(null);try{const h=await lt();if(!a.current)return;g(h)}catch(h){if(!a.current)return;x(h instanceof Error?h.message:String(h))}finally{a.current&&y(!1)}}t.useEffect(()=>{b()},[]);function R(){w(!0),v(null),I(""),N(""),m(""),x(null)}function O(h){w(!1),v(h.id),I(h.name),N(h.description),m(h.body),x(null)}function L(){w(!1),v(null),I(""),N(""),m("")}async function k(){const h=A.trim();if(!Be(h)){x("名称仅允许英文、数字、下划线");return}if(!f.trim()){x("正文不能为空");return}M(!0),x(null);try{if(p?await ot({name:h,description:c,body:f}):S&&await rt(S,{name:h,description:c,body:f}),!a.current)return;L(),await b()}catch(d){if(!a.current)return;x(d instanceof Error?d.message:String(d))}finally{a.current&&M(!1)}}async function P(h){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){x(null);try{if(await dt(h),!a.current)return;S===h&&L(),await b()}catch(d){if(!a.current)return;x(d instanceof Error?d.message:String(d))}}}const C=p||S!==null,F=!A.trim()||Be(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:R,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:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),z?e.jsx("p",{className:"mdocs-agent-skills-error",children:z}):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:p?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:A,onChange:h=>I(h.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:h=>N(h.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:f,onChange:h=>m(h.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()||!f.trim(),children:D?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:L,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:R,children:"新建第一个"})]}):null,!u&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(h=>{const d=Be(h.name),j=S===h.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:h.name}),d?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:h.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>O(h),disabled:C&&!j,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void P(h.id),disabled:C,children:"删除"})]})]},h.id)})}):null]})})]})}const Jt={algorithm:Et.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 is(a,s){if(!a)return"—";const g=new Date(a);return Number.isNaN(g.getTime())?"—":g.toLocaleString(s==="zh"?"zh-CN":"en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function Zt(a){const{t:s,lang:g}=ie(),[u,y]=t.useState(!1),[z,x]=t.useState(!1),[S,v]=t.useState(!1),[p,w]=t.useState([]),[A,I]=t.useState([]),[c,N]=t.useState(null),[f,m]=t.useState(null),[D,M]=t.useState(""),[b,R]=t.useState("keyword"),[O,L]=t.useState(null),[k,P]=t.useState(!1),C=t.useRef(0),[F,h]=t.useState({current:1,pageSize:20}),[d,j]=t.useState(0);async function T(){y(!0),m(null);try{const i=await mt();v(i.modelReady),w(i.items),I([]),j(i.items.length),h(r=>({...r,current:1}))}catch(i){m(ee(s,i)||s("embeddingIndexLoadFailed"))}finally{y(!1)}}t.useEffect(()=>{T()},[]);const K=t.useMemo(()=>{const i=new Map;for(const r of p)i.has(r.domainId)||i.set(r.domainId,de(r.domainName,g,s));return Array.from(i.entries()).map(([r,U])=>({text:U,value:r}))},[p,g,s]),G=t.useMemo(()=>{const i=D.trim().toLowerCase();return i?p.filter(r=>(r.displayName||"").toLowerCase().includes(i)||(r.relativePath||"").toLowerCase().includes(i)||r.documentId.toLowerCase().includes(i)):p},[p,D]),J=b==="semantic"&&!!D.trim();t.useEffect(()=>{if(b!=="semantic")return;const i=D.trim();if(!i){C.current+=1,L(null);return}const r=++C.current;P(!0);const U=window.setTimeout(()=>{(async()=>{try{const V=await us({query:i,mode:"semantic",topN:50});if(r!==C.current)return;const $=new Map(p.map(o=>[o.documentId,o]));L(V.results.map(o=>{const E=$.get(o.documentId);return E?{...E,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&&L([])}finally{r===C.current&&P(!1)}})()},300);return()=>window.clearTimeout(U)},[b,D,p]);const Z=J?O??[]:G;t.useEffect(()=>{j(Z.length),h(i=>({...i,current:1}))},[Z.length,b]);const Q=t.useMemo(()=>[{title:s("myDocumentsColTitle"),dataIndex:"displayName",key:"displayName",ellipsis:!0,sorter:(i,r)=>(i.displayName||i.relativePath).localeCompare(r.displayName||r.relativePath,g==="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:K,onFilter:(i,r)=>r.domainId===i,sorter:(i,r)=>de(i.domainName,g,s).localeCompare(de(r.domainName,g,s),g==="zh"?"zh":"en"),render:(i,r)=>de(r.domainName,g,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=>is(i,g)},{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(Le,{color:"success",children:s("embeddingIndexStatusBuiltUnknown")}):i>0?e.jsx(Le,{color:"success",children:s("embeddingIndexStatusReady",{chunks:String(i)})}):e.jsx(Le,{children:s("embeddingIndexStatusMissing")})},{title:s("embeddingIndexColBuiltAt"),dataIndex:"embeddingUpdatedAt",key:"embeddingUpdatedAt",width:160,sorter:(i,r)=>{const U=i.embeddingUpdatedAt?new Date(i.embeddingUpdatedAt).getTime():0,V=r.embeddingUpdatedAt?new Date(r.embeddingUpdatedAt).getTime():0;return U-V},render:i=>is(i,g)}],[K,g,a,s]);async function q(){const i=A.map(String);if(i.length!==0){x(!0),N(null),m(null);try{const r=await ut(i);v(r.modelReady),N(s("embeddingIndexRebuildResult",{ok:String(r.ok.length),skipped:String(r.skipped.length),failed:String(r.failed.length)})),await T()}catch(r){m(ee(s,r)||s("embeddingIndexRebuildFailed"))}finally{x(!1)}}}return e.jsx(Pt,{theme:Jt,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(Rt,{wrap:!0,style:{marginBottom:12},children:[e.jsx(Ft,{value:b,"aria-label":s("myDocumentsSearchMode"),onChange:i=>R(i),options:[{label:s("myDocumentsModeKeyword"),value:"keyword"},{label:s("myDocumentsModeSemantic"),value:"semantic"}]}),e.jsx(zt.Search,{allowClear:!0,placeholder:s(b==="semantic"?"embeddingIndexSearchSemanticPlaceholder":"embeddingIndexSearchPlaceholder"),"aria-label":s(b==="semantic"?"embeddingIndexSearchSemanticPlaceholder":"embeddingIndexSearchPlaceholder"),value:D,onChange:i=>M(i.target.value),style:{width:240},disabled:u||z}),e.jsx(Qe,{onClick:()=>void T(),disabled:u||z,children:s("embeddingIndexRefresh")}),e.jsx(Qe,{type:"primary",onClick:()=>void q(),disabled:z||A.length===0,loading:z,children:s("embeddingIndexRebuildSelected",{count:String(A.length)})})]}),c&&e.jsx("p",{style:{fontSize:13,color:"var(--mdocs-text-muted)"},children:c}),f&&e.jsx("p",{className:"mdocs-doc-search-error",style:{marginBottom:8},children:f}),J&&!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,U=d,V=Math.max(1,Math.ceil(U/i)||1);return e.jsx(Lt,{size:"small",rowKey:"documentId",loading:u||J&&k,columns:Q,dataSource:Z,rowSelection:{selectedRowKeys:A,onChange:$=>I($)},pagination:{current:r,pageSize:i,total:U,showSizeChanger:!1,showQuickJumper:!1,showTotal:($,o)=>s("embeddingIndexPageTotal",{from:String(o[0]??0),to:String(o[1]??0),total:String($)})},onChange:($,o,E,W)=>{const se=$.pageSize??i,ce=W.currentDataSource.length,ae=Math.max(1,Math.ceil(ce/se)||1);let te=$.current??1;te>ae&&(te=ae),j(ce),h({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(Xe,{size:"small",min:5,max:200,step:5,value:i,controls:!0,changeOnWheel:!0,disabled:u||z,"aria-label":s("embeddingIndexPageSize"),onChange:$=>{if($==null||!Number.isFinite(Number($)))return;const o=Math.min(200,Math.max(5,Math.floor(Number($))));h({current:1,pageSize:o})}}),e.jsx("span",{style:{fontSize:13},children:s("embeddingIndexGoPage")}),e.jsx(Xe,{size:"small",min:1,max:V,step:1,value:Math.min(r,V),controls:!0,changeOnWheel:!0,disabled:u||z||U===0,"aria-label":s("embeddingIndexGoPage"),onChange:$=>{if($==null||!Number.isFinite(Number($)))return;const o=Math.min(V,Math.max(1,Math.floor(Number($))));h(E=>({...E,current:o}))}}),e.jsxs("span",{style:{fontSize:13,color:"var(--mdocs-text-muted)"},children:["/ ",V]})]})})})()]})]})})}function cs(a,s){const g=localStorage.getItem(a);return g===null?s:g==="true"}function Se(a){const s=new Date(a);if(Number.isNaN(s.getTime()))return"—";const g=String(s.getMonth()+1).padStart(2,"0"),u=String(s.getDate()).padStart(2,"0");return`${s.getFullYear()}-${g}-${u}`}function na(a){const{t:s,lang:g,setLang:u}=ie(),{onBack:y,onPublishDraft:z}=a,x=ht(),[S,v]=t.useState(!1);pt(x&&!S,()=>v(!0));const p=t.useRef(!0);t.useEffect(()=>(p.current=!0,()=>{p.current=!1}),[]),t.useEffect(()=>{x||v(!1)},[x]);const[w,A]=t.useState(()=>cs("mdocs.autoPublish",!1)),[I,c]=t.useState(()=>cs("mdocs.autoEdit",!0)),[N,f]=t.useState(!1),[m,D]=t.useState("general");function M(n){D(n),x&&v(!1)}const b=s(m==="general"?"general":m==="bookmarks"?"bookmarkTitle":m==="myDocuments"?"myDocuments":m==="embeddingIndex"?"embeddingIndex":m==="domainManagement"?"domainManagement":m==="memberTemplates"?"memberTemplates":m==="agentConfig"?"agentConfig":"saveAndPublish"),[R,O]=t.useState([]),[L,k]=t.useState(!0),[P,C]=t.useState(null),[F,h]=t.useState(!1),[d,j]=t.useState(!1),[T,K]=t.useState(!1),[G,J]=t.useState(!1),[Z,Q]=t.useState(null),[q,i]=t.useState(!1),[r,U]=t.useState(!1),[V,$]=t.useState(!1),[o,E]=t.useState(""),[W,se]=t.useState(!1),[ce,ae]=t.useState(!1),[te,ne]=t.useState(0),[le,xe]=t.useState([]),[we,ye]=t.useState(!1),[oe,Ce]=t.useState(""),[be,De]=t.useState([]),[Ie,l]=t.useState(!1),[_,je]=t.useState(""),[ue,ps]=t.useState("auto"),[Ne,Te]=t.useState(null),[Ue,Ae]=t.useState(!0),[me,gs]=t.useState(0),[Ke,$e]=t.useState("1"),[Ve,fs]=t.useState(0),[he,xs]=t.useState(""),[Me,ys]=t.useState(""),[ve,bs]=t.useState(""),[js,Ns]=t.useState(null),[vs,ks]=t.useState([]),ke=t.useRef(0),Pe=20,pe=Ne!==null,[We,Ss]=t.useState([]),[ws,Ee]=t.useState(!1),[Re,_e]=t.useState(null),[Fe,Ge]=t.useState(new Map);t.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(w))},[w]),t.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(I))},[I]),t.useEffect(()=>{m==="savePublish"&&Oe().then(n=>{p.current&&ne(n.filter(B=>!B.published).length)})},[m]),t.useEffect(()=>{m==="bookmarks"&&Cs(),m==="myDocuments"&&(fe(),ds().then(n=>{p.current&&ks(n)}).catch(()=>{}))},[m,he,Me,ve]),t.useEffect(()=>{if(m!=="myDocuments")return;const n=_.trim();if(!n){ke.current+=1,Te(null),Ae(!0);return}const B=++ke.current,Y=window.setTimeout(()=>{(async()=>{try{const H=await us({query:n,mode:ue,domainId:he||void 0,topN:50});if(!p.current||B!==ke.current)return;Te(H.results),Ae(H.modelReady)}catch{if(!p.current||B!==ke.current)return;Te([]),Ae(!0)}})()},300);return()=>window.clearTimeout(Y)},[m,_,ue,he]),t.useEffect(()=>{qe()},[]),t.useEffect(()=>{os().then(n=>{p.current&&Ss(n)}).catch(()=>{})},[]);const ge=new Map(We.map(n=>[n.domainId,n.domainName]));async function qe(){try{k(!0);const n=await gt();if(!p.current)return;O(n)}catch{}finally{p.current&&k(!1)}}async function Cs(){try{ye(!0);const n=await ft();if(!p.current)return;xe(n)}catch{}finally{p.current&&ye(!1)}}async function fe(n=0){try{l(!0);const B=await xt({offset:n*Pe,limit:Pe,domainId:he||void 0,creatorVisitorId:Me||void 0,groupBy:ve||void 0});if(!p.current)return;De(B.items),Ns(B.groups??null),fs(B.total),gs(n),$e(String(n+1))}catch{}finally{p.current&&l(!1)}}async function Ds(n){try{await wt(n),xe(B=>B.filter(Y=>Y.documentId!==n))}catch{}}function Is(){if(R.some(B=>!B.revoked)){j(!0);return}He()}async function He(){try{h(!0);const n=await Dt();C({token:n.token,name:n.name}),await qe()}finally{h(!1)}}async function Ts(){try{$(!0);const n=await kt();Q(n.recoveryCode)}finally{$(!1)}}async function As(n){n.preventDefault();const B=o.trim();if(!(B&&B.length<4))try{se(!0),await St(B),E(""),ae(!0),setTimeout(()=>ae(!1),3e3)}finally{se(!1)}}async function Ms(n){_e(n);try{const B=await Ct(n),Y=new Map;B.forEach(H=>{Y.set(H.visitorId,H.permission)}),Ge(Y)}catch{Ge(new Map)}Ee(!0)}async function Ps(n){if(Re)try{const B=new Set(n.map(H=>H.visitorId)),Y=new Set(Fe.keys());for(const H of Y)B.has(H)||await It(Re,H);for(const H of n)await Tt(Re,H.visitorId,H.permission);await fe()}finally{Ee(!1),_e(null)}}const Je=le.filter(n=>{if(!oe.trim())return!0;const B=oe.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(B)||(n.ownerVisitorName||"").toLowerCase().includes(B)||(n.domainId||"").toLowerCase().includes(B)}),re=Math.ceil(Ve/Pe);return e.jsxs("div",{className:"mdocs-layout"+(x?" mdocs-layout--reader mdocs-layout--settings":""),children:[x&&S?e.jsx("button",{type:"button",className:"mdocs-mobile-nav-scrim","aria-label":s("collapseSidebar"),onClick:()=>v(!1)}):null,e.jsxs("aside",{className:"mdocs-sidebar"+(x?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:yt,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]}),x?e.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:()=>v(!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(bt,{size:18})}):null]}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(m==="general"?" active":""),onClick:()=>M("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(m==="bookmarks"?" active":""),onClick:()=>M("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(m==="myDocuments"?" active":""),onClick:()=>M("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(m==="embeddingIndex"?" active":""),onClick:()=>M("embeddingIndex"),children:s("embeddingIndex")}),e.jsx("div",{className:"mdocs-config-item"+(m==="domainManagement"?" active":""),onClick:()=>M("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(m==="memberTemplates"?" active":""),onClick:()=>M("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(m==="agentConfig"?" active":""),onClick:()=>M("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(m==="savePublish"?" active":""),onClick:()=>M("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:y,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[x?e.jsxs("div",{className:"mdocs-settings-mobile-bar",children:[e.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>v(!0),"aria-label":s("expandSidebar"),children:e.jsx(jt,{size:18,strokeWidth:1.75})}),e.jsx("span",{className:"mdocs-settings-mobile-bar-title",children:b})]}):null,Nt(),m==="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:g==="en"?"active":"",onClick:()=>u("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:g==="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")}),!L&&R.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:R.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:Is,disabled:F||L,children:F?"…":R.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),P&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--ok",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliTokenGenerated")}),e.jsx("span",{className:"mdocs-settings-secret-value",children:P.token})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(P.token),J(!1),K(!0),window.setTimeout(()=>K(!1),2e3)}catch{K(!1),J(!0),window.setTimeout(()=>J(!1),3e3)}})()},children:s(T?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>C(null),children:s("close")})]}),T&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),G&&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:Ts,disabled:V,children:V?"…":"生成恢复码"})]}),Z&&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:Z})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(Z),U(!1),i(!0),window.setTimeout(()=>i(!1),2e3)}catch{i(!1),U(!0),window.setTimeout(()=>U(!1),3e3)}})()},children:q?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>Q(null),children:s("close")})]}),q&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),r&&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:As,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:o,onChange:n=>E(n.target.value),minLength:0,style:{marginBottom:8}}),ce&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:W,children:W?"设置中…":"保存密码"})]})]})]})]}):m==="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:oe,onChange:n=>Ce(n.target.value)}),we?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:Je.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(oe?"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:Je.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:"已删除"}):ge.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:()=>Ds(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})})]})]}):m==="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(vt,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("input",{type:"text",placeholder:"搜索文章…",value:_,onChange:n=>je(n.target.value)})]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:he,"aria-label":s("myDocumentsFilterDomain"),onChange:n=>xs(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllDomains")}),We.map(n=>e.jsx("option",{value:n.domainId,children:ge.get(n.domainId)||n.domainName},n.domainId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ue,"aria-label":s("myDocumentsSearchMode"),onChange:n=>ps(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")})]}),!pe&&e.jsxs("select",{className:"mdocs-my-docs-select",value:Me,"aria-label":s("myDocumentsFilterCreator"),onChange:n=>ys(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllCreators")}),vs.map(n=>e.jsx("option",{value:n.visitorId,children:n.visitorName},n.visitorId))]}),!pe&&e.jsxs("select",{className:"mdocs-my-docs-select",value:ve,"aria-label":s("myDocumentsGroupBy"),onChange:n=>bs(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")})]})]}),Ie&&!pe?e.jsx("div",{className:"mdocs-my-docs-empty",children:s("loading")}):pe?e.jsx(e.Fragment,{children:Ne.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(ue==="semantic"&&!Ue?"myDocumentsSemanticNotReady":"myDocumentsNoMatch")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-my-docs-search-meta",children:[s("myDocumentsResultCount",{count:String(Ne.length)}),ue==="semantic"&&!Ue?` · ${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:Ne.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:ge.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:n.ownerVisitorName||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Se(n.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:n.createdAt?Se(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:[be.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(_?"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:(js??[{key:"",items:be}]).flatMap(n=>{var H;const B=n.key?e.jsx("tr",{className:"mdocs-my-docs-group",children:e.jsx("td",{colSpan:6,children:ve==="domain"?ge.get(n.key)||n.key:((H=n.items[0])==null?void 0:H.creatorName)||n.key})},`group-${n.key}`):null,Y=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:ge.get(X.domainId||"")||X.domainId||"—"}),e.jsx("td",{children:X.creatorName||X.creatorVisitorId||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Se(X.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:Se(X.createdAt)}),e.jsxs("td",{className:"mdocs-my-docs-actions",children:[e.jsx("button",{type:"button",className:"ghost small",onClick:()=>Ms(X.documentId),children:s("docInfoInviteMember")}),e.jsx("button",{type:"button",className:"primary small",onClick:()=>a.onOpenDocument(X.documentId),children:s("bookmarkOpen")})]})]},X.documentId));return B?[B,...Y]:Y})})]})}),!pe&&e.jsxs("div",{className:"mdocs-my-docs-footer",children:[e.jsx("span",{className:"mdocs-settings-page-info",children:s("myDocumentsPageInfo",{current:String(re>0?me+1:0),total:String(re),count:String(Ve)})}),re>1&&e.jsxs("form",{className:"mdocs-my-docs-jump",onSubmit:n=>{n.preventDefault();const B=Number.parseInt(Ke,10);if(!Number.isFinite(B))return;const Y=Math.min(Math.max(B,1),re)-1;Y!==me&&fe(Y)},children:[e.jsx("span",{children:s("myDocumentsJumpTo")}),e.jsx("input",{type:"number",inputMode:"numeric",min:1,max:re,"aria-label":s("myDocumentsJumpTo"),value:Ke,onChange:n=>$e(n.target.value)}),e.jsx("button",{type:"submit",className:"secondary small",children:s("myDocumentsJump")})]}),re>1&&e.jsxs("div",{className:"mdocs-settings-pagination",children:[e.jsx("button",{type:"button",className:"secondary small",disabled:me<=0,onClick:()=>fe(me-1),children:s("myDocumentsPrev")}),e.jsx("button",{type:"button",className:"secondary small",disabled:me>=re-1,onClick:()=>fe(me+1),children:s("myDocumentsNext")})]})]})]})]})]}):m==="embeddingIndex"?e.jsx(Zt,{onOpenDocument:a.onOpenDocument}):m==="domainManagement"?e.jsx(Kt,{}):m==="memberTemplates"?e.jsx($t,{}):m==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(Gt,{}),e.jsx(Ht,{})]}):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"})})]})}),te>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>f(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",te,")"]}),e.jsx("span",{className:"mdocs-settings-draft-arrow","aria-hidden":"true",children:"›"})]}):e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:s("noDrafts")})})]})]}),N&&e.jsx(Ot,{onPublish:z,onClose:()=>f(!1),onCountChange:ne,onRecover:a.onRecoverDraft})]}),d&&e.jsx(ms,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:F,onConfirm:()=>{j(!1),He()},onCancel:()=>j(!1)}),e.jsx(hs,{open:ws,title:s("docInfoInviteMember"),initialSelectedIds:[...Fe.keys()],initialPermissions:Fe,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>Ee(!1),onConfirm:n=>{Ps(n)}})]})}export{na as SettingsPage};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import{r as c,j as s}from"./react-vendor-BVS1XoFi.js";import{o as X,c as ke,p as H,q as ye,a as ve,s as Ce,e as Ie,g as je,u as we,t as $,v as K,w as Ne,x as Se,y as ne,z as Ee,A as De,B as Me,E as Be,F as Re,G as ze,H as Te,I as Ae,J as We,K as Pe,X as $e,L as Ke,M as Le,r as Ve,i as Fe,O as _e,P as qe,Q as Oe,R as Ue}from"./index-CINfyH_g.js";import{D as Qe}from"./DocChrome-C5syeHbQ.js";import{P as J}from"./plus-BxZJ-Mya.js";import{B as Ge,I as He}from"./italic-phhei7W3.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 Je=[["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"}]],Xe=X("merge",Je);/**
|
|
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 Ye=[["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"}]],Ze=X("square-split-horizontal",Ye);/**
|
|
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 pe=[["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"}]],se=X("trash-2",pe);function L(t){return`${t.rowId}::${t.colId}`}function et(t,l,d){const r=t.rows.findIndex(u=>u.id===l.rowId),y=t.rows.findIndex(u=>u.id===d.rowId),b=t.columns.findIndex(u=>u.id===l.colId),C=t.columns.findIndex(u=>u.id===d.colId);if(r<0||y<0||b<0||C<0)return[l];const V=Math.min(r,y),R=Math.max(r,y),F=Math.min(b,C),j=Math.max(b,C),D=[];for(let u=V;u<=R;u+=1)for(let w=F;w<=j;w+=1)D.push({rowId:t.rows[u].id,colId:t.columns[w].id});return D}function tt(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 ut(t){const{t:l}=ke(),d=t.meta.documentId,[r,y]=c.useState(()=>H(t.initialContent)),[b,C]=c.useState(t.initialDisplayName),[V,R]=c.useState(!1),[F,j]=c.useState(t.hasLocalDraft??!1),[D,u]=c.useState(!1),[w,Y]=c.useState(!1),[oe,_]=c.useState(null),[Z,z]=c.useState(null),[N,M]=c.useState(null),[f,x]=c.useState(null),v=c.useRef(null),T=c.useRef(!1),I=c.useRef(null),q=c.useRef(r),O=c.useRef(b);q.current=r,O.current=b,I.current=N,c.useEffect(()=>{const e=()=>{T.current=!1};return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]);const i=ye(r)??r.sheets[0],m=N&&f?et(i,N,f):[],U=new Set(m.map(L));c.useEffect(()=>{y(H(t.initialContent)),C(t.initialDisplayName),M(null),x(null),z(null)},[d,t.contentRevision,t.initialContent,t.initialDisplayName]),c.useEffect(()=>{let e=!1;return(async()=>{var n;const o=await ve(d);e||!o||o.contentKind!=="sheet"||(y(H(o.content)),o.displayName&&C(o.displayName),j(!0),(n=t.onDraftExistsChange)==null||n.call(t,!0))})(),()=>{e=!0}},[d]),c.useEffect(()=>Ce((e,o)=>{var n;e===d&&(j(o),(n=t.onDraftExistsChange)==null||n.call(t,o))}),[d]),c.useEffect(()=>{let e=!1;return Ie(d).then(o=>{e||u(!!(o!=null&&o.bookmarked))}),()=>{e=!0}},[d]);const Q=c.useCallback(async()=>{var e;await je(d).execute(()=>we({documentId:d,content:$(q.current),displayName:O.current,contentKind:"sheet",localBaseCommitIdAtEditStart:t.meta.headCommitId??null,snapshotMeta:{permission:t.meta.permission,ownerVisitorId:t.meta.ownerVisitorId,domainId:t.meta.domainId}})),j(!0),(e=t.onDraftExistsChange)==null||e.call(t,!0)},[d,t]),p=c.useCallback(()=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{Q()},1e3)},[Q]);c.useEffect(()=>()=>{v.current&&clearTimeout(v.current)},[]);function A(e){var o;t.canEdit&&(y(e),(o=t.onContentChange)==null||o.call(t,$(e)),p())}function k(e){A(_e(r,e))}function ae(e,o,n){if(o&&I.current){n.preventDefault(),x(e);return}T.current=!0,M(e),x(e),I.current=e}function ie(e){T.current&&x(e)}function G(e,o){M(e),x(o),I.current=e}function ce(e,o,n){n.preventDefault();const a=i.rows;if(a.length===0)return;const S=a[0].id,g=a[a.length-1].id;if(o&&I.current){x({rowId:g,colId:e});return}G({rowId:S,colId:e},{rowId:g,colId:e})}function le(e,o,n){n.preventDefault();const a=i.columns;if(a.length===0)return;const S=a[0].id,g=a[a.length-1].id;if(o&&I.current){x({rowId:e,colId:g});return}G({rowId:e,colId:S},{rowId:e,colId:g})}function de(e){e.preventDefault();const o=i.rows,n=i.columns;o.length===0||n.length===0||G({rowId:o[0].id,colId:n[0].id},{rowId:o[o.length-1].id,colId:n[n.length-1].id})}function B(e){if(!t.canEdit||m.length===0)return;let o=i;for(const n of m)o=qe(o,n.rowId,n.colId,e);k(o)}function re(){var n;const e=m[0];if(!e)return;const o=K((n=i.rows.find(a=>a.id===e.rowId))==null?void 0:n.cells[e.colId]);B({bold:!(o!=null&&o.bold)})}function ue(){var n;const e=m[0];if(!e)return;const o=K((n=i.rows.find(a=>a.id===e.rowId))==null?void 0:n.cells[e.colId]);B({italic:!(o!=null&&o.italic)})}function he(){if(!(!t.canEdit||!N||!f))try{k(Oe(i,{startRowId:N.rowId,startColId:N.colId,endRowId:f.rowId,endColId:f.colId}))}catch{}}function me(){if(!t.canEdit||!f)return;const{tab:e}=Ue(i,f.rowId,f.colId);k(e)}async function ee(){var a;if(!t.canEdit)return;const e=document.querySelector(".mdocs-sheet-scroll"),o=(e==null?void 0:e.scrollTop)??null,n=(e==null?void 0:e.scrollLeft)??null;R(!0);try{v.current&&(clearTimeout(v.current),v.current=null),await Q(),await t.onPublish($(q.current),O.current.trim()||b,d),j(!1),(a=t.onDraftExistsChange)==null||a.call(t,!1)}finally{R(!1),e&&o!=null&&(e.scrollTop=o,n!=null&&(e.scrollLeft=n),requestAnimationFrame(()=>{e.scrollTop=o,n!=null&&(e.scrollLeft=n)}))}}async function fe(){if(t.canEdit&&b.trim()!==t.initialDisplayName.trim())try{await ee()}catch{}}async function ge(){var e,o;if(!w){Y(!0);try{D?(await Ve(d),u(!1),(e=t.onShowToast)==null||e.call(t,l("bookmarkRemoved"))):(await Fe(d),u(!0),(o=t.onShowToast)==null||o.call(t,l("bookmarkAdded")))}finally{Y(!1)}}}const h=(()=>{var o;const e=m[0];if(e)return K((o=i.rows.find(n=>n.id===e.rowId))==null?void 0:o.cells[e.colId])})();return s.jsxs("div",{className:"mdocs-sheet-editor",children:[s.jsx(Qe,{fileType:"sheet",displayName:b,onDisplayNameChange:C,onDisplayNameBlur:()=>void fe(),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:V,draftExists:F,onPublish:()=>void ee(),onDelete:()=>void t.onDelete(),isBookmarked:D,bookmarkBusy:w,onToggleBookmark:()=>void ge(),onToggleComments:t.onToggleComments,commentPanelOpen:t.commentPanelOpen,commentCount:t.commentCount,readerChrome:t.readerChrome,onOpenMobileNav:t.onOpenMobileNav}),s.jsxs("div",{className:"mdocs-sheet-toolbar",children:[s.jsxs("div",{className:"mdocs-sheet-toolbar-left",children:[s.jsxs("button",{type:"button",className:"mdocs-sheet-btn",disabled:!t.canEdit,onClick:()=>k(Ne(i)),children:[s.jsx(J,{size:13,strokeWidth:2.2}),s.jsx("span",{children:l("sheetAddRow")})]}),s.jsxs("button",{type:"button",className:"mdocs-sheet-btn",disabled:!t.canEdit,onClick:()=>k(Se(i)),children:[s.jsx(J,{size:13,strokeWidth:2.2}),s.jsx("span",{children:l("sheetAddColumn")})]}),s.jsx("span",{className:"mdocs-sheet-toolbar-sep","aria-hidden":!0}),s.jsx("button",{type:"button",className:`mdocs-sheet-btn mdocs-sheet-btn-icon${h!=null&&h.bold?" is-active":""}`,disabled:!t.canEdit||m.length===0,title:l("sheetBold"),onClick:re,children:s.jsx(Ge,{size:13,strokeWidth:2.4})}),s.jsx("button",{type:"button",className:`mdocs-sheet-btn mdocs-sheet-btn-icon${h!=null&&h.italic?" is-active":""}`,disabled:!t.canEdit||m.length===0,title:l("sheetItalic"),onClick:ue,children:s.jsx(He,{size:13,strokeWidth:2.4})}),s.jsx("label",{className:"mdocs-sheet-style-label",title:l("sheetFontSize"),children:s.jsxs("select",{className:"mdocs-sheet-font-size",disabled:!t.canEdit||m.length===0,value:(h==null?void 0:h.fontSize)??"",onChange:e=>{const o=e.target.value;B(o?{fontSize:Number(o)}:{fontSize:void 0})},children:[s.jsx("option",{value:"",children:"Aa"}),[12,13,14,16,18,20,24].map(e=>s.jsx("option",{value:e,children:e},e))]})}),s.jsx("label",{className:"mdocs-sheet-style-label",title:l("sheetTextColor"),children:s.jsx("input",{type:"color",className:"mdocs-sheet-color",disabled:!t.canEdit||m.length===0,value:(h==null?void 0:h.color)??"#212121",onChange:e=>B({color:e.target.value})})}),s.jsx("label",{className:"mdocs-sheet-style-label",title:l("sheetBgColor"),children:s.jsx("input",{type:"color",className:"mdocs-sheet-color",disabled:!t.canEdit||m.length===0,value:(h==null?void 0:h.bg)??"#ffffff",onChange:e=>B({bg:e.target.value})})}),s.jsx("span",{className:"mdocs-sheet-toolbar-sep","aria-hidden":!0}),s.jsxs("button",{type:"button",className:"mdocs-sheet-btn",disabled:!t.canEdit||m.length<2,title:`${l("sheetMerge")}(按住拖选,或 Shift+点第二格)`,onClick:he,children:[s.jsx(Xe,{size:13,strokeWidth:2.2}),s.jsx("span",{children:l("sheetMerge")})]}),s.jsxs("button",{type:"button",className:"mdocs-sheet-btn",disabled:!t.canEdit||!f||!ne(i,f.rowId,f.colId),title:l("sheetUnmerge"),onClick:me,children:[s.jsx(Ze,{size:13,strokeWidth:2.2}),s.jsx("span",{children:l("sheetUnmerge")})]})]}),s.jsx("div",{className:"mdocs-sheet-toolbar-right",children:s.jsxs("span",{className:"mdocs-sheet-stats-badge",children:[i.name," · ",i.rows.length," 行 × ",i.columns.length," 列"]})})]}),s.jsx("div",{className:"mdocs-sheet-scroll",children:s.jsxs("table",{className:"mdocs-sheet-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{className:"mdocs-sheet-corner-cell",title:"全选",onMouseDown:de,children:"#"}),i.columns.map(e=>{const o=m.length>0&&i.rows.every(n=>U.has(L({rowId:n.id,colId:e.id})));return s.jsx("th",{className:`mdocs-sheet-th${o?" is-selected":""}`,onMouseDown:n=>{Z!==e.id&&(n.target.closest(".mdocs-sheet-col-del")||ce(e.id,n.shiftKey,n))},children:s.jsxs("div",{className:"mdocs-sheet-header-cell",children:[Z===e.id&&t.canEdit?s.jsx("input",{className:"mdocs-sheet-header-input",autoFocus:!0,defaultValue:e.name,title:"编辑列名",onClick:n=>n.stopPropagation(),onMouseDown:n=>n.stopPropagation(),onBlur:n=>{z(null);const a=n.target.value.trim();!a||a===e.name||k(Ee(i,e.id,a))},onKeyDown:n=>{n.key==="Enter"&&n.target.blur(),n.key==="Escape"&&z(null)}}):s.jsx("button",{type:"button",className:"mdocs-sheet-header-label",title:"单击全选列;双击重命名",onDoubleClick:n=>{n.preventDefault(),n.stopPropagation(),t.canEdit&&z(e.id)},children:e.name}),t.canEdit&&i.columns.length>1&&s.jsx("button",{type:"button",className:"mdocs-sheet-col-del",title:l("sheetDeleteColumn"),onMouseDown:n=>n.stopPropagation(),onClick:()=>{try{const{tab:n}=De(i,[e.id]);k(n)}catch{}},children:s.jsx(se,{size:12,strokeWidth:1.8})})]})},e.id)}),s.jsx("th",{className:"mdocs-sheet-actions-header"})]})}),s.jsx("tbody",{children:i.rows.map((e,o)=>{const n=m.length>0&&i.columns.every(a=>U.has(L({rowId:e.id,colId:a.id})));return s.jsxs("tr",{className:`mdocs-sheet-tr${n?" is-row-selected":""}`,children:[s.jsx("td",{className:`mdocs-sheet-rownum${n?" is-selected":""}`,title:"单击全选行",onMouseDown:a=>le(e.id,a.shiftKey,a),children:o+1}),i.columns.map(a=>{if(Me(i,e.id,a.id))return null;const S=e.cells[a.id],g=K(S),te=ne(i,e.id,a.id),be=Be(i,e.id,a.id),W=te&&be?Re(i,te):{rowSpan:1,colSpan:1},E={rowId:e.id,colId:a.id},xe=U.has(L(E));return s.jsx("td",{className:`mdocs-sheet-td${xe?" is-selected":""}`,rowSpan:W.rowSpan>1?W.rowSpan:void 0,colSpan:W.colSpan>1?W.colSpan:void 0,style:g!=null&&g.bg?{background:g.bg}:void 0,onMouseEnter:()=>ie(E),children:s.jsx("input",{className:"mdocs-sheet-cell-input",style:tt(g),value:Te(S),disabled:!t.canEdit,onMouseDown:P=>ae(E,P.shiftKey,P),onFocus:()=>{T.current||(M(E),x(E),I.current=E)},onChange:P=>k(ze(i,e.id,a.id,P.target.value))})},a.id)}),s.jsx("td",{className:"mdocs-sheet-actions-col",children:s.jsx("button",{type:"button",className:"mdocs-sheet-row-del",disabled:!t.canEdit,title:l("sheetDeleteRow"),onClick:()=>k(Ae(i,e.id)),children:s.jsx(se,{size:13,strokeWidth:1.8})})})]},e.id)})})]})}),s.jsxs("footer",{className:"mdocs-sheet-footer",children:[s.jsxs("div",{className:"mdocs-sheet-tabs",role:"tablist",children:[r.sheets.map(e=>{const o=e.id===i.id;return s.jsxs("div",{className:`mdocs-sheet-tab${o?" mdocs-sheet-tab--active":""}`,role:"tab","aria-selected":o,children:[oe===e.id&&t.canEdit?s.jsx("input",{className:"mdocs-sheet-tab-rename",autoFocus:!0,defaultValue:e.name,onBlur:n=>{_(null);const a=n.target.value.trim();if(!(!a||a===e.name))try{A(We(r,e.id,a))}catch{}},onKeyDown:n=>{n.key==="Enter"&&n.target.blur(),n.key==="Escape"&&_(null)}}):s.jsx("button",{type:"button",className:"mdocs-sheet-tab-btn",title:"双击可重命名工作表",onClick:()=>{var a;if(o)return;const n=Pe(r,e.id);y(n),M(null),x(null),t.canEdit&&((a=t.onContentChange)==null||a.call(t,$(n)),p())},onDoubleClick:()=>{t.canEdit&&_(e.id)},children:e.name}),t.canEdit&&r.sheets.length>1?s.jsx("button",{type:"button",className:"mdocs-sheet-tab-close",title:l("sheetDeleteSheet"),onClick:n=>{n.stopPropagation();try{A(Ke(r,e.id))}catch{}},children:s.jsx($e,{size:11,strokeWidth:2.4})}):null]},e.id)}),s.jsx("button",{type:"button",className:"mdocs-sheet-tab-add",disabled:!t.canEdit,title:l("sheetAddSheet"),onClick:()=>{const{doc:e}=Le(r);A(e)},children:s.jsx(J,{size:13,strokeWidth:2.2})})]}),s.jsx("div",{className:"mdocs-sheet-footer-info",children:s.jsxs("span",{children:["共 ",r.sheets.length," 个工作表"]})})]})]})}export{ut as SheetEditor};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as t,C as _}from"./index-
|
|
1
|
+
import{o as t,C as _}from"./index-CINfyH_g.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-8gAAnUbI.js";import{z as f,V as g}from"./editor-DBWWidi3.js";import{B as I,I as $}from"./italic-phhei7W3.js";/**
|
|
2
2
|
* @license lucide-react v0.562.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r,j as e}from"./react-vendor-BVS1XoFi.js";import{c as G,a8 as ee,f as se,a3 as z}from"./index-3B7_9QOQ.js";function ie({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 te(v){return v.length<=6?v:`${v.slice(0,6)}…`}function re(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}=G(),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:te(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(ie,{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 ne(v){var U;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}=G(),P=r.useRef(i);P.current=i;const t=r.useMemo(()=>new Set(f),[f]),g=ee(),[m,R]=r.useState([]),[E,T]=r.useState("idle"),[w,V]=r.useState(()=>new Set),[O,L]=r.useState(()=>new Map),[J,A]=r.useState(""),[C,B]=r.useState(""),[M,D]=r.useState(!1),$=r.useRef(null),[K,W]=r.useState(!1),[q,I]=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(""),I(null))},[a,d,k]),r.useEffect(()=>{if(!a)return;let s=!1;return T("loading"),se().then(n=>{s||(R(n),T("ok"))}).catch(n=>{s||(T("err"),I(z(P.current,n)))}),()=>{s=!0}},[a]),r.useEffect(()=>{if(!M)return;const s=n=>{var c;(c=$.current)!=null&&c.contains(n.target)||D(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[M]);const Q=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]),X=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]),Y=r.useCallback((s,n)=>{L(c=>{const l=new Map(c);return l.set(s,n),l})},[]),Z=r.useCallback(()=>{const s=Number(C);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})},[C,p,m]);async function _(){I(null),W(!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){I(z(i,s))}finally{W(!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:$,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:C?(U=F.find(s=>String(s.id)===C))==null?void 0:U.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)===C?" active":""),role:"option","aria-selected":String(s.id)===C,onClick:()=>{B(String(s.id)),D(!1)},children:s.displayName},s.id))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}if(!C){I(i("visitorPickerPickTemplate"));return}Z()},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(re,{visitors:m,loadState:E,searchFilter:J,onSearchChange:A,selectedIds:w,onToggle:X,selectedRows:Q,lockedIds:t,myVisitorId:g,showPermissionSelect:u,permissionOptions:N,onPermissionChange:Y})}),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"){I(i("loading"));return}_()},children:i(K?"saving":"visitorPickerConfirm")})]})]})}):null}export{ie as M,ne as V,re as a};
|
|
1
|
+
import{r,j as e}from"./react-vendor-BVS1XoFi.js";import{c as G,a8 as ee,f as se,a3 as z}from"./index-CINfyH_g.js";function ie({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 te(v){return v.length<=6?v:`${v.slice(0,6)}…`}function re(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}=G(),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:te(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(ie,{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 ne(v){var U;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}=G(),P=r.useRef(i);P.current=i;const t=r.useMemo(()=>new Set(f),[f]),g=ee(),[m,R]=r.useState([]),[E,T]=r.useState("idle"),[w,V]=r.useState(()=>new Set),[O,L]=r.useState(()=>new Map),[J,A]=r.useState(""),[C,B]=r.useState(""),[M,D]=r.useState(!1),$=r.useRef(null),[K,W]=r.useState(!1),[q,I]=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(""),I(null))},[a,d,k]),r.useEffect(()=>{if(!a)return;let s=!1;return T("loading"),se().then(n=>{s||(R(n),T("ok"))}).catch(n=>{s||(T("err"),I(z(P.current,n)))}),()=>{s=!0}},[a]),r.useEffect(()=>{if(!M)return;const s=n=>{var c;(c=$.current)!=null&&c.contains(n.target)||D(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[M]);const Q=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]),X=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]),Y=r.useCallback((s,n)=>{L(c=>{const l=new Map(c);return l.set(s,n),l})},[]),Z=r.useCallback(()=>{const s=Number(C);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})},[C,p,m]);async function _(){I(null),W(!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){I(z(i,s))}finally{W(!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:$,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:C?(U=F.find(s=>String(s.id)===C))==null?void 0:U.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)===C?" active":""),role:"option","aria-selected":String(s.id)===C,onClick:()=>{B(String(s.id)),D(!1)},children:s.displayName},s.id))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}if(!C){I(i("visitorPickerPickTemplate"));return}Z()},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(re,{visitors:m,loadState:E,searchFilter:J,onSearchChange:A,selectedIds:w,onToggle:X,selectedRows:Q,lockedIds:t,myVisitorId:g,showPermissionSelect:u,permissionOptions:N,onPermissionChange:Y})}),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"){I(i("loading"));return}_()},children:i(K?"saving":"visitorPickerConfirm")})]})]})}):null}export{ie as M,ne as V,re as a};
|