@fgbg/mdocs 1.3.27 → 1.3.29
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 +18 -1
- package/agent-skills/getting-started-installation/SKILL.md +1 -1
- package/dist/server/agent/Agent/session-manager.js +116 -8
- package/dist/server/agent/Agent/session-manager.js.map +1 -1
- package/dist/server/agent/Agent/session-manager.pin-rename.test.js +75 -0
- package/dist/server/agent/Agent/session-manager.pin-rename.test.js.map +1 -0
- package/dist/server/app.js +41 -2
- package/dist/server/app.js.map +1 -1
- package/dist/server/cli/self-update.js +18 -7
- package/dist/server/cli/self-update.js.map +1 -1
- package/dist/server/routes/agent.routes.js +62 -2
- package/dist/server/routes/agent.routes.js.map +1 -1
- package/dist/web/assets/AgentChatPanel-BD1oyUQ2.js +42 -0
- package/dist/web/assets/AiWriteWorkbench-B0r87dOu.js +7 -0
- package/dist/web/assets/{DiagramEditor-NtNY3sZL-CyddeNUo.js → DiagramEditor-NtNY3sZL-zENSuUSW.js} +1 -1
- package/dist/web/assets/{DocChrome-C5syeHbQ.js → DocChrome-B-5PeA3Z.js} +1 -1
- package/dist/web/assets/{DocumentEditor-mG7hvAWj.js → DocumentEditor-CeH1smor.js} +1 -1
- package/dist/web/assets/{HtmlEditor-DABDor1R.js → HtmlEditor-DEwBOS1N.js} +1 -1
- package/dist/web/assets/{MergeView-BczHMfos.js → MergeView-Bzk9R2GH.js} +1 -1
- package/dist/web/assets/{PlaygroundPage-zg5tjWQs.js → PlaygroundPage-Bmq4l_R3.js} +1 -1
- package/dist/web/assets/{SettingsPage-BU0is_e7.js → SettingsPage-B3-GANlD.js} +1 -1
- package/dist/web/assets/{SheetEditor-4nXVP3NN.js → SheetEditor-DYVKW2RD.js} +1 -1
- package/dist/web/assets/{Toolbar-xB4u1mY1.js → Toolbar-SoiYp0SC.js} +1 -1
- package/dist/web/assets/{VisitorPickerModal-Djpm5bTf.js → VisitorPickerModal-BTmTrqrT.js} +1 -1
- package/dist/web/assets/{check--tqH9AMO.js → check-CnsclxvV.js} +1 -1
- package/dist/web/assets/copy-CI3NmTJZ.js +11 -0
- package/dist/web/assets/{docPlainCharCount-CTaZfi-M.js → docPlainCharCount-C7aeeOM1.js} +1 -1
- package/dist/web/assets/index-CSZ-Z1RJ.css +1 -0
- package/dist/web/assets/{index-CINfyH_g.js → index-DNb6Q69l.js} +14 -14
- package/dist/web/assets/{italic-phhei7W3.js → italic-BljxX8Uj.js} +1 -1
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-BDjANcdr.js → meta2dEngine-BD2XbzaV-BuKVYpuY.js} +1 -1
- package/dist/web/assets/{plus-BxZJ-Mya.js → plus-BAqdJ6N2.js} +1 -1
- package/dist/web/assets/{react-8gAAnUbI.js → react-C7YGEhUS.js} +129 -134
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/AgentChatPanel-TJVgAwlH.js +0 -22
- package/dist/web/assets/AgentSkillFormCard-3ZpgH1RY.js +0 -11
- package/dist/web/assets/AiWriteWorkbench-B9HrhEmd.js +0 -7
- package/dist/web/assets/copy-5mwMd6zK.js +0 -6
- package/dist/web/assets/index-DCgILSIv.css +0 -1
|
@@ -1 +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
|
+
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-DNb6Q69l.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-C7YGEhUS.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-SoiYp0SC.js";import{D as Ft}from"./DocChrome-B-5PeA3Z.js";import{V as Ht}from"./VisitorPickerModal-BTmTrqrT.js";import{c as Ut,U as qt,S as Vt}from"./docPlainCharCount-C7aeeOM1.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./editor-DBWWidi3.js";import"./plus-BAqdJ6N2.js";import"./copy-CI3NmTJZ.js";import"./check-CnsclxvV.js";import"./italic-BljxX8Uj.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-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
|
+
import{r as i,j as n}from"./react-vendor-BVS1XoFi.js";import{c as xe,f as ve,e as ge,a as ye,s as be,g as Ce,u as ke,h as je,S as Ie,l as we,r as De,i as Se,j as Ee,D as E,k as Ne,m as Pe,b as Z}from"./index-DNb6Q69l.js";import{D as Me}from"./DocChrome-B-5PeA3Z.js";import{V as Be}from"./VisitorPickerModal-BTmTrqrT.js";import{c as Re,U as Ae,S as Te}from"./docPlainCharCount-C7aeeOM1.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./file-type-policy-C6Nun42Q.js";function _e(e){const{t:a,lang:k}=xe(),r=e.meta.documentId,[h,N]=i.useState(e.initialContent),[x,P]=i.useState(e.initialDisplayName),[u,j]=i.useState(!0),[q,G]=i.useState(!1),[p,I]=i.useState(e.hasLocalDraft??!1),[f,M]=i.useState(!1),[B,K]=i.useState(!1),[v,R]=i.useState(!1),[y,A]=i.useState(!1),[ee,te]=i.useState([]),[ne,b]=i.useState(!1),[T,z]=i.useState(e.meta.permission),[O,Q]=i.useState(!1),[ie,L]=i.useState(!1),[w,ae]=i.useState(new Map),[Y,V]=i.useState(null),D=i.useRef(0),U=i.useRef(null),F=i.useRef(null),c=i.useRef(null),S=i.useRef(h),W=i.useRef(x);S.current=h,W.current=x;const se=e.canEdit&&!u;i.useEffect(()=>{N(e.initialContent),P(e.initialDisplayName),j(!0)},[r]),i.useEffect(()=>{e.contentRevision&&(N(e.initialContent),P(e.initialDisplayName))},[e.contentRevision]),i.useEffect(()=>{let t=!0;return ve().then(s=>{t&&te(s)}).catch(()=>{}),()=>{t=!1}},[]),i.useEffect(()=>{let t=!0;return ge(r).then(s=>{t&&M(s.bookmarked)}).catch(()=>{}),()=>{t=!1}},[r]),i.useEffect(()=>{let t=!1;const s=Z();return ye(r).then(o=>{var m;if(t||Z()!==s)return;const l=!!(o&&!o.published);I(l),(m=e.onDraftExistsChange)==null||m.call(e,l)}),()=>{t=!0}},[r,e.onDraftExistsChange]),i.useEffect(()=>be((t,s)=>{var o;t===r&&(I(s),(o=e.onDraftExistsChange)==null||o.call(e,s))}),[r,e.onDraftExistsChange]),i.useEffect(()=>{z(e.meta.permission)},[e.meta.permission,r]),i.useEffect(()=>{const t=s=>{U.current&&!U.current.contains(s.target)&&R(!1),F.current&&!F.current.contains(s.target)&&A(!1)};return(v||y)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[v,y]),i.useEffect(()=>{if(!v&&!y)return;const t=++D.current;V(null);const s=()=>{if(t===D.current)try{const m=Re("html",S.current||"");t===D.current&&V(m)}catch{t===D.current&&V(0)}},o=window;if(typeof o.requestIdleCallback=="function"){const m=o.requestIdleCallback(s);return()=>{var C;return(C=o.cancelIdleCallback)==null?void 0:C.call(o,m)}}const l=window.setTimeout(s,0);return()=>window.clearTimeout(l)},[v,y,h,r,e.contentRevision]);const H=i.useCallback(async()=>{var t;await Ce(r).execute(()=>ke({documentId:r,content:S.current,displayName:W.current,contentKind:"html",localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})),I(!0),(t=e.onDraftExistsChange)==null||t.call(e,!0)},[r,e]),J=i.useCallback(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{H()},1e3)},[H]);i.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);async function $(t){var s;if(e.canEdit){G(!0);try{c.current&&(clearTimeout(c.current),c.current=null),await H(),await e.onPublish(S.current,W.current.trim()||x,r,t),I(!1),(s=e.onDraftExistsChange)==null||s.call(e,!1)}finally{G(!1)}}}async function oe(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(x.trim()!==t)try{await $()}catch{}}async function _(){var t,s;if(!B){K(!0);try{f?(await De(r),M(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await Se(r),M(!0),(s=e.onShowToast)==null||s.call(e,a("bookmarkAdded")))}finally{K(!1)}}}function re(t){const s=ee.find(o=>o.visitorId===t);return(s==null?void 0:s.visitorName)??t.slice(0,8)}function le(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const d=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),ce=i.useMemo(()=>{const t=(d==null?void 0:d.permission)??"public";return je(t)},[d==null?void 0:d.permission]);function de(t){return t===E.PRIVATE?a("permissionPrivate"):t===E.DOMAIN_READ?a("permissionInvite"):t===E.DOMAIN_WRITE?a("permissionDomainWrite"):t===E.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function me(){if(O||T===e.meta.permission){b(!1);return}Q(!0);try{await $(T),b(!1)}finally{Q(!1)}}async function ue(t){const s=new Set(t.map(o=>o.visitorId));for(const[o]of w)s.has(o)||await Ne(r,o);for(const o of t)w.get(o.visitorId)!==o.permission&&await Pe(r,o.visitorId,o.permission);L(!1)}function g(){R(!1),A(!1)}function X(t,s){const o=(s==null?void 0:s.includeBookmark)??!0,l={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreator")}),n.jsx("span",{children:re(e.meta.ownerVisitorId)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreatedAt")}),n.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(k==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoSize")}),n.jsx("span",{children:le(new Blob([h]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCharCount")}),n.jsx("span",{children:Y===null?"…":Y.toLocaleString(k==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(k==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),o?n.jsxs("button",{type:"button",style:l,onClick:()=>{_(),t()},children:[n.jsx("span",{children:f?"⭐":"☆"}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),(async()=>{const m=await Ee(r);ae(new Map(m.map(C=>[C.visitorId,C.permission]))),L(!0)})()},children:[n.jsx(Ae,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),z(e.meta.permission),b(!0)},children:[n.jsx(Te,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})}const fe=i.useCallback(t=>{var o;const s=t.target.value;N(s),(o=e.onContentChange)==null||o.call(e,s),J()},[e,J]),he=`<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head><body>${h}</body></html>`;return n.jsxs("div",{className:"mdocs-editor"+(e.readerChrome?" mdocs-editor--reader":""),children:[n.jsx(Me,{fileType:"html",displayName:x,onDisplayNameChange:P,onDisplayNameBlur:()=>void oe(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:se,onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:q,draftExists:p,onPublish:()=>{$().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:f,bookmarkBusy:B,onToggleBookmark:()=>void _(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:X(g),docInfoOpen:v,onToggleDocInfo:()=>R(!v),docInfoMenuRef:U,readerChrome:e.readerChrome,readerActionsCollapsible:!0,readerHeaderDocked:e.readerChrome,onOpenMobileNav:e.onOpenMobileNav,readerMoreOpen:y,onToggleReaderMore:()=>A(t=>!t),readerMoreMenuRef:F,readerMoreMenu:n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:B,onClick:()=>{_(),g()},children:[n.jsx(Ie,{size:16,strokeWidth:1.5,style:{color:f?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:f?"#faad14":"none"}}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}),n.jsx("div",{className:"mdocs-reader-more-divider"}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:!u,onClick:()=>{j(!1),g()},children:a("edit")}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:u,onClick:()=>{j(!0),g()},children:a("preview")}),n.jsx("div",{className:"mdocs-reader-more-divider"}),e.canEdit?n.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:q,onClick:()=>{g(),e.onDelete()},children:n.jsx("span",{children:a("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),X(g,{includeBookmark:!1})]}),leadingExtra:e.canEdit&&!e.readerChrome?n.jsxs("label",{className:"mdocs-editor-mode-toggle","aria-label":a(u?"preview":"edit"),children:[n.jsx("input",{type:"checkbox",checked:u,onChange:()=>j(t=>!t)}),n.jsxs("span",{className:"mdocs-editor-mode-toggle-slider",children:[n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--left",children:a("edit")}),n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--right",children:a("preview")})]})]}):null}),n.jsxs("div",{className:"mdocs-html-editor-body",children:[!u&&e.canEdit?n.jsx("textarea",{className:"mdocs-html-editor-textarea",value:h,onChange:fe,spellCheck:!1,placeholder:"在此处编写 HTML 代码"}):null,n.jsx("div",{className:"mdocs-html-editor-preview",style:!u&&e.canEdit?{width:"50%"}:{width:"100%"},children:n.jsx("iframe",{className:"mdocs-html-editor-iframe",srcDoc:he,sandbox:"",title:x})})]}),ne&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&b(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:a("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[a("domainPermission"),":",d?we(d.domainName,k,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:ce.map(t=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n.jsx("input",{type:"radio",name:"html-doc-permission",value:t,checked:T===t,onChange:()=>z(t)}),n.jsx("span",{children:de(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>b(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:O,onClick:()=>void me(),children:a(O?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Be,{open:ie,title:a("docInfoInviteMember"),initialSelectedIds:[...w.keys()],initialPermissions:w,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>L(!1),onConfirm:t=>{ue(t)}})]})}export{_e as HtmlEditor};
|
|
@@ -1,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,b7 as H,b8 as Y,b9 as Z,ba as ee}from"./index-DNb6Q69l.js";import{E as te,B as ne}from"./react-C7YGEhUS.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-BAqdJ6N2.js";import"./copy-CI3NmTJZ.js";import"./check-CnsclxvV.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-C7YGEhUS.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-SoiYp0SC.js";import{N as me}from"./index-DNb6Q69l.js";import"./editor-DBWWidi3.js";import"./diagram-BF8g9yg4.js";import"./plus-BAqdJ6N2.js";import"./copy-CI3NmTJZ.js";import"./check-CnsclxvV.js";import"./motion-BAXVQJfN.js";import"./italic-BljxX8Uj.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:
|