@fgbg/mdocs 1.1.0 → 1.1.2
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/agent-skills/changelog/SKILL.md +18 -0
- package/dist/server/routes/assets.routes.js +9 -4
- package/dist/server/routes/assets.routes.js.map +1 -1
- package/dist/server/routes/assets.routes.upload.test.js +1 -0
- package/dist/server/routes/assets.routes.upload.test.js.map +1 -1
- package/dist/web/assets/{AgentChatPanel-C8TMWDuE.js → AgentChatPanel-Bt38gm3b.js} +2 -2
- package/dist/web/assets/{AgentSkillFormCard-yk7PWF0W.js → AgentSkillFormCard-CtfWIf7Y.js} +1 -1
- package/dist/web/assets/AiWriteWorkbench-Boie5E_-.js +7 -0
- package/dist/web/assets/{DiagramEditor-NtNY3sZL-Bw4wHaBD.js → DiagramEditor-NtNY3sZL-CZy-tmEe.js} +1 -1
- package/dist/web/assets/DocumentEditor-1A6lpvV-.js +26 -0
- package/dist/web/assets/{MergeView-royv5YkB.js → MergeView-Dip0aW7s.js} +1 -1
- package/dist/web/assets/PlaygroundPage-C4X6Lj-Q.js +8 -0
- package/dist/web/assets/{SettingsPage-D8HfepZ8.js → SettingsPage-nlnmzNZK.js} +1 -1
- package/dist/web/assets/{Toolbar-BDJ6WABq.js → Toolbar-BHLX-ug4.js} +2 -2
- package/dist/web/assets/{VisitorPickerModal-DPKIoySi.js → VisitorPickerModal-BPyEWlQo.js} +1 -1
- package/dist/web/assets/{copy-UwfRYkpI.js → copy-BE64wQqi.js} +1 -1
- package/dist/web/assets/diagram-CT58wBdU.js +5772 -0
- package/dist/web/assets/{editor-ONzd_YnO.js → editor-CL03se2B.js} +1 -1
- package/dist/web/assets/{index-4TuRcE3b.js → index-BkKvQv2F.js} +24 -24
- package/dist/web/assets/index-DKshvHIN.css +1 -0
- package/dist/web/assets/{meta2d-D3b5RRN8.js → meta2d-1-g23JOU.js} +1 -1
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-D1J2-XNv.js → meta2dEngine-BD2XbzaV-z-eR7E_V.js} +1 -1
- package/dist/web/assets/{motion-DddvD-ez.js → motion-DX3HNq_4.js} +2 -2
- package/dist/web/assets/{plus-CiGwts52.js → plus-ECzYbQfA.js} +1 -1
- package/dist/web/assets/react-GP8hKHRA.js +2122 -0
- package/dist/web/assets/react-vendor-BuABiQkA.js +242 -0
- package/dist/web/assets/ui-BQStT3dY.js +3116 -0
- package/dist/web/index.html +6 -6
- package/package.json +2 -2
- package/dist/web/assets/AiWriteWorkbench-ChCJt24m.js +0 -7
- package/dist/web/assets/DocumentEditor-B3Dsq02C.js +0 -26
- package/dist/web/assets/PlaygroundPage-B-_1l4Ix.js +0 -8
- package/dist/web/assets/diagram--gCCJK__.js +0 -6257
- package/dist/web/assets/index-C4ESYs7f.css +0 -1
- package/dist/web/assets/react-B99eF5mm.js +0 -2377
- package/dist/web/assets/react-vendor-BJFXgntS.js +0 -242
- package/dist/web/assets/ui-BHvBMRFE.js +0 -3126
package/dist/web/index.html
CHANGED
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
opacity: 0.65;
|
|
28
28
|
}
|
|
29
29
|
</style>
|
|
30
|
-
<script type="module" crossorigin src="/assets/index-
|
|
31
|
-
<link rel="modulepreload" crossorigin href="/assets/react-vendor-
|
|
32
|
-
<link rel="modulepreload" crossorigin href="/assets/motion-
|
|
33
|
-
<link rel="modulepreload" crossorigin href="/assets/ui-
|
|
34
|
-
<link rel="modulepreload" crossorigin href="/assets/diagram
|
|
35
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
30
|
+
<script type="module" crossorigin src="/assets/index-BkKvQv2F.js"></script>
|
|
31
|
+
<link rel="modulepreload" crossorigin href="/assets/react-vendor-BuABiQkA.js">
|
|
32
|
+
<link rel="modulepreload" crossorigin href="/assets/motion-DX3HNq_4.js">
|
|
33
|
+
<link rel="modulepreload" crossorigin href="/assets/ui-BQStT3dY.js">
|
|
34
|
+
<link rel="modulepreload" crossorigin href="/assets/diagram-CT58wBdU.js">
|
|
35
|
+
<link rel="stylesheet" crossorigin href="/assets/index-DKshvHIN.css">
|
|
36
36
|
</head>
|
|
37
37
|
<body>
|
|
38
38
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgbg/mdocs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A Markdown knowledge base for small teams",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@earendil-works/pi-agent-core": "^0.82.1",
|
|
43
43
|
"@earendil-works/pi-ai": "^0.82.1",
|
|
44
44
|
"@lexical/rich-text": "0.42.0",
|
|
45
|
-
"@lobehub/editor": "npm:@fgbg/lobe-editor@1.0.0-fork.
|
|
45
|
+
"@lobehub/editor": "npm:@fgbg/lobe-editor@1.0.0-fork.21",
|
|
46
46
|
"@lobehub/ui": "^5.0.0",
|
|
47
47
|
"@node-rs/jieba": "^2.0.1",
|
|
48
48
|
"@shikijs/langs": "4.0.2",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{r as u,j as n}from"./react-vendor-BJFXgntS.js";import{ag as Z,ah as de,i as ue,ak as me,as as he,al as fe,am as ge,an as xe}from"./index-4TuRcE3b.js";import{H as ke,A as ee,S as ye,a as we}from"./AgentSkillFormCard-yk7PWF0W.js";import{P as je}from"./plus-CiGwts52.js";import{D as pe,E as Ne}from"./ui-BHvBMRFE.js";import"./diagram--gCCJK__.js";import"./motion-DddvD-ez.js";function U(e){return e===""?[]:e.split(`
|
|
2
|
-
`)}function ae(e){return e.join(`
|
|
3
|
-
`)}function z(e,i){const s=U(e),a=U(i),m=s.length,k=a.length,y=Array.from({length:m+1},()=>Array.from({length:k+1},()=>0));for(let C=m-1;C>=0;C--)for(let I=k-1;I>=0;I--)s[C]===a[I]?y[C][I]=y[C+1][I+1]+1:y[C][I]=Math.max(y[C+1][I],y[C][I+1]);const S=[];let g=0,w=0;for(;g<m||w<k;)if(g<m&&w<k&&s[g]===a[w])S.push({kind:"eq",oi:g,ni:w}),g++,w++;else if(w<k&&(g===m||y[g][w+1]>=y[g+1][w]))S.push({kind:"ins",oi:g,ni:w}),w++;else if(g<m)S.push({kind:"del",oi:g,ni:w}),g++;else break;const E=[];let c=0,_=0;for(;c<S.length;){if(S[c].kind==="eq"){c++;continue}const C=S[c].oi,I=S[c].ni,T=[],L=[];let v=C,H=I;for(;c<S.length&&S[c].kind!=="eq";){const A=S[c];A.kind==="del"?(T.push(s[A.oi]),v=A.oi+1):(L.push(a[A.ni]),H=A.ni+1),c++}E.push({id:`h${_++}`,oldStart:C,oldEnd:v,newStart:I,newEnd:H,oldLines:T,newLines:L})}return E}function be(e,i){const s=U(e);return ae([...s.slice(0,i.oldStart),...i.newLines,...s.slice(i.oldEnd)])}function Ce(e,i){const s=U(e);return ae([...s.slice(0,i.newStart),...i.oldLines,...s.slice(i.newEnd)])}function J(e){return e===""?[]:e.split(`
|
|
4
|
-
`)}function V(e){return e.join(`
|
|
5
|
-
`)}function Se(e,i){const s=J(e),a=[];let m=0;return i.forEach((k,y)=>{k.oldStart>m&&a.push({kind:"same",lines:s.slice(m,k.oldStart),key:`s-${m}-${k.oldStart}`}),a.push({kind:"hunk",hunk:k,hunkIndex:y,key:`h-${k.id}-${y}`}),m=k.oldEnd}),m<s.length?a.push({kind:"same",lines:s.slice(m),key:`s-${m}-end`}):i.length===0&&s.length===0&&a.push({kind:"same",lines:[],key:"s-empty"}),a}function Ie(e){const i=[],s=[];for(const a of e)a.kind==="same"?i.push(V(a.lines)):s.push(V(a.hunk.newLines));return{sameTexts:i,newTexts:s}}function Me(e,i){const s=[];let a=0,m=0;for(const k of e)if(k.kind==="same"){const y=i.sameTexts[a++]??"";s.push(...J(y))}else{const y=i.newTexts[m++]??"";s.push(...J(y))}return V(s)}function ve(e){return e.oldLines.length===0?"add":e.newLines.length===0?"del":"mod"}function ne(e){const i=Math.max(1,J(e.value).length);return n.jsxs("div",{className:`mdocs-ai-write-line ${e.className}`,children:[n.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),n.jsx("textarea",{className:"mdocs-ai-write-inline-edit",value:e.value,rows:i,spellCheck:!1,"aria-label":e["aria-label"],onChange:s=>e.onChange(s.target.value),onBlur:()=>e.onBlurFlush()})]})}function Ae(e){const i=!!e.sending,[s,a]=u.useState(0),[m,k]=u.useState(null),[y,S]=u.useState({sameTexts:[],newTexts:[]}),g=u.useRef(!1),w=u.useRef([]),E=u.useRef(y);E.current=y;const c=u.useMemo(()=>e.proposedMd==null||e.proposedMd===e.currentMd?[]:z(e.currentMd,e.proposedMd),[e.currentMd,e.proposedMd]),_=u.useMemo(()=>Se(e.currentMd,c),[e.currentMd,c]);w.current=_;const C=!i&&c.length>0;u.useEffect(()=>{if(c.length===0){a(0);return}a(l=>Math.min(l,c.length-1))},[c.length]),u.useEffect(()=>{if(!C){g.current=!1;return}g.current||S(Ie(_))},[C,e.proposedMd,e.currentMd,_]);const I=m??s;function T(){return Me(w.current,E.current)}function L(){if(!C)return e.proposedMd;const l=T();return g.current=!1,l===e.currentMd?(e.onProposedChange(null),null):(l!==e.proposedMd&&e.onProposedChange(l),l)}function v(l){const h=c.indexOf(l),x=T();if(g.current=!1,x===e.currentMd){e.onProposedChange(null);return}const N=z(e.currentMd,x),b=N[h]??N.find(q=>q.id===l.id);if(!b){e.onProposedChange(x);return}const p=be(e.currentMd,b);e.onCurrentChange(p),z(p,x).length===0?e.onProposedChange(null):e.onProposedChange(x)}function H(l){const h=c.indexOf(l),x=T();if(g.current=!1,x===e.currentMd){e.onProposedChange(null);return}const N=z(e.currentMd,x),b=N[h]??N.find(D=>D.id===l.id);if(!b){e.onProposedChange(x);return}const p=Ce(x,b);p===e.currentMd?e.onProposedChange(null):e.onProposedChange(p)}function A(){const l=T();g.current=!1,e.onCurrentChange(l),e.onProposedChange(null)}function F(){g.current=!1,e.onProposedChange(null)}function K(l){c.length!==0&&a(h=>{const x=(h+l+c.length)%c.length,N=document.getElementById(`mdocs-ai-hunk-${x}`);return N==null||N.scrollIntoView({block:"center",behavior:"smooth"}),x})}function M(l,h){g.current=!0,S(x=>{const N=x.sameTexts.slice();return N[l]=h,{...x,sameTexts:N}})}function O(l,h){g.current=!0,S(x=>{const N=x.newTexts.slice();return N[l]=h,{...x,newTexts:N}})}const j=c[I]??null;let B=0;return n.jsxs("div",{className:"mdocs-ai-write-md-pane",children:[n.jsxs("div",{className:"mdocs-ai-write-diff-toolbar",children:[n.jsx("span",{className:"mdocs-ai-write-diff-count",children:i?"接收中·编辑我的稿":c.length===0?e.proposedMd?"与提案一致(可编辑)":"Markdown 源码(可编辑)":`${c.length} 处变更(可改提案)`}),!i&&c.length>0?n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",onClick:A,children:"全部接受"}),n.jsx("button",{type:"button",onClick:F,children:"全部拒绝"})]}):null]}),C?n.jsxs("div",{className:"mdocs-ai-write-inline",role:"document",children:[_.map(l=>{if(l.kind==="same"){const p=B++,D=y.sameTexts[p]??V(l.lines);return n.jsx("div",{className:"mdocs-ai-write-inline-same",children:n.jsx(ne,{className:"ctx",value:D,"aria-label":"提案相同行",onChange:q=>M(p,q),onBlurFlush:()=>L()})},l.key)}const h=l.hunk,x=ve(h),N=l.hunkIndex===I,b=y.newTexts[l.hunkIndex]??V(h.newLines);return n.jsxs("div",{id:`mdocs-ai-hunk-${l.hunkIndex}`,className:`mdocs-ai-write-inline-hunk mdocs-ai-write-inline-hunk-${x}`+(N?" is-active":""),onMouseEnter:()=>k(l.hunkIndex),onMouseLeave:()=>k(null),onClick:()=>a(l.hunkIndex),children:[n.jsxs("div",{className:"mdocs-ai-write-hunk-hover",hidden:m!==l.hunkIndex,children:[n.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:p=>{p.stopPropagation(),H(h)},children:"拒绝"}),n.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:p=>{p.stopPropagation(),v(h)},children:"接受"})]}),n.jsx("pre",{className:"mdocs-ai-write-hunk-pre",children:h.oldLines.map((p,D)=>n.jsxs("div",{className:"mdocs-ai-write-line del mdocs-ai-write-line-readonly",children:[n.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),n.jsx("span",{className:"mdocs-ai-write-code",children:p||" "})]},`o${D}`))}),h.newLines.length>0||b!==""||x!=="del"?n.jsx(ne,{className:"add",value:b,"aria-label":"提案新增行",onChange:p=>O(l.hunkIndex,p),onBlurFlush:()=>L()}):null]},l.key)}),j?n.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"变更导航",children:[n.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>K(-1),children:"↑"}),n.jsxs("span",{children:[I+1," / ",c.length]}),n.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>K(1),children:"↓"}),n.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>H(j),children:"拒绝"}),n.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>v(j),children:"接受"})]}):null]}):n.jsx("textarea",{className:"mdocs-ai-write-editor",value:e.currentMd,onChange:l=>e.onCurrentChange(l.target.value),spellCheck:!1,placeholder:`# 标题
|
|
6
|
-
|
|
7
|
-
在此编辑 Markdown 源码…`})]})}let te=0;function se(e){return te+=1,`${e}-${Date.now()}-${te}`}function $e(e,i){const s=e.slice(),a=s[s.length-1];return(a==null?void 0:a.type)==="text"?s[s.length-1]={type:"text",text:a.text+i}:s.push({type:"text",text:i}),s}function Ee(e,i){const s=e.slice(),a=s[s.length-1];return(a==null?void 0:a.type)==="thinking"?s[s.length-1]={type:"thinking",text:a.text+i}:s.push({type:"thinking",text:i}),s}function G(e,i){const s=i.trim();return s?[...e,{type:"tool",text:s}]:e}function Pe(e){return e.some(i=>i.type==="text"||i.type==="thinking"?i.text.length>0:!0)}function Te(e){const i=new Date(e);if(Number.isNaN(i.getTime()))return"";const s=new Date;return i.getFullYear()===s.getFullYear()&&i.getMonth()===s.getMonth()&&i.getDate()===s.getDate()?i.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):i.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function ie(e,i){return i.map((s,a)=>{const m=`h-${e}-${a}-${s.role}`;if(s.role==="user"){const k=s.skillNames&&s.skillNames.length>0?s.skillNames:s.skillIds&&s.skillIds.length>0?s.skillIds:void 0;return{id:m,role:"user",content:s.content,skillNames:k}}return{id:m,role:"assistant",blocks:s.content?[{type:"text",text:s.content}]:[]}})}function qe(e){const[i,s]=u.useState(e.initialMarkdown),[a,m]=u.useState(null),[k]=u.useState(e.initialMarkdown),[y,S]=u.useState(e.displayName||"未命名"),[g,w]=u.useState([]),[E,c]=u.useState(null),[_,C]=u.useState([]),[I,T]=u.useState(!1),[L,v]=u.useState(!1),[H,A]=u.useState(""),[F,K]=u.useState([]),[M,O]=u.useState(!1),[j,B]=u.useState(null),[l,h]=u.useState(null),[x,N]=u.useState(!1),b=u.useRef(null);async function p(){T(!0);try{const t=await me("coding",e.documentId);C(t.sessions),E||c(t.lastOpenedSessionId)}catch{}finally{T(!1)}}async function D(){try{const t=await Z();B(t)}catch{B({enabled:!1,skillsReady:!1,model:null})}}if(u.useEffect(()=>{var d;if(!e.open){v(!1),(d=b.current)==null||d.abort();return}s(e.initialMarkdown),m(null),S(e.displayName||"未命名"),A(""),h(null),v(!1);let t=!1;return(async()=>{try{const r=await Z();t||B(r)}catch{t||B({enabled:!1,skillsReady:!1,model:null})}try{const r=await de("coding",e.documentId);if(t)return;c(r.sessionId),w(ie(r.sessionId,r.messages))}catch{t||(c(null),w([]))}p()})(),()=>{t=!0}},[e.open,e.initialMarkdown,e.displayName,e.documentId]),u.useEffect(()=>()=>{var t;return(t=b.current)==null?void 0:t.abort()},[]),u.useEffect(()=>{e.open&&L&&p()},[L,e.open,e.documentId]),!e.open)return null;const q=(j==null?void 0:j.reason)==="missing_api_key",Q=a!=null&&a!==i?z(i,a):[];async function le(){var t;if(!M){(t=b.current)==null||t.abort(),h(null),v(!1),O(!1);try{const d=await fe("coding",e.documentId);c(d.sessionId),w([]),A(""),p()}catch(d){h(d instanceof Error?d.message:String(d))}}}async function oe(t){var d;if(!M){if(t===E){v(!1);return}(d=b.current)==null||d.abort(),h(null);try{const r=await ge(t,"coding",e.documentId);c(r.sessionId),w(ie(r.sessionId,r.messages)),A(""),v(!1)}catch(r){h(r instanceof Error?r.message:String(r))}}}async function X(){var Y;const t=H.trim();if(!t||M)return;if(!(j!=null&&j.enabled)){h("请先配置 API Key");return}(Y=b.current)==null||Y.abort();const d=new AbortController;b.current=d;const r=se("u"),R=se("a");w($=>[...$,{id:r,role:"user",content:t,skillNames:F.length>0?[...F]:void 0},{id:R,role:"assistant",blocks:[]}]),A(""),O(!0),h(null);const P=$=>{w(o=>o.map(f=>f.id===R&&f.role==="assistant"?{...f,blocks:$(f.blocks)}:f))};try{let $=!1;await xe(t,{mode:"coding",skillNames:F.length>0?F:void 0,documentId:e.documentId,workingMarkdown:i,baseMarkdown:k,signal:d.signal,onEvent:o=>{o.type==="text_delta"?P(f=>$e(f,o.text)):o.type==="thinking_delta"?P(f=>Ee(f,o.text)):o.type==="markdown_set"?m(o.markdown):o.type==="tool_notice"?P(f=>G(f,o.text)):o.type==="document_table"?P(f=>G(f,o.title)):o.type==="document_card"?P(f=>G(f,`读取文档「${o.title}」`)):o.type==="sources"?o.items.length>0&&P(f=>G(f,`已阅读 ${o.items.length} 个手册页面`)):o.type==="skill_form_card"?P(f=>[...f,{type:"skill_form_card",requestId:o.requestId,mode:o.mode,title:o.title,currentName:o.currentName,initialName:o.initialName,initialDescription:o.initialDescription,initialBody:o.initialBody,expiresAt:o.expiresAt,status:"open"}]):o.type==="skill_form_expired"?P(f=>f.map(W=>W.type==="skill_form_card"&&W.requestId===o.requestId&&W.status==="open"?{...W,status:"expired"}:W)):o.type==="error"&&($=!0,h(o.message))}}),!d.signal.aborted&&!$&&K([]),p()}catch($){d.signal.aborted||h($ instanceof Error?$.message:String($))}finally{b.current===d&&(b.current=null),O(!1)}}async function re(){let t=i;if(Q.length>0){if(!window.confirm(`还有 ${Q.length} 段未审阅,将全部接受后写回。继续?`))return;t=a??i,s(t),m(null)}N(!0);const d=!e.documentId;try{const r=await e.onComplete({markdown:t,documentId:e.documentId,displayName:y.trim()||"未命名"}),R=r&&typeof r=="object"&&typeof r.documentId=="string"?r.documentId.trim():"";if(d&&R&&E)try{await he(E,R)}catch{}e.onClose()}catch(r){if(r!=null&&r.silent||r instanceof Error&&r.message==="cancelled")return;h(r instanceof Error?r.message:String(r))}finally{N(!1)}}function ce(){var t;(i!==k||a!=null)&&!window.confirm("取消帮写?未写回的修改将丢失。")||((t=b.current)==null||t.abort(),e.onClose())}return n.jsxs("div",{className:"mdocs-ai-write-overlay",role:"dialog","aria-modal":"true","aria-label":"帮写",children:[n.jsxs("header",{className:"mdocs-ai-write-header",children:[n.jsxs("div",{className:"mdocs-ai-write-header-left",children:[n.jsx("img",{src:ue,alt:"",className:"mdocs-ai-write-title-logo"}),n.jsx("strong",{children:"帮写"}),n.jsx("input",{className:"mdocs-ai-write-title",value:y,onChange:t=>S(t.target.value),"aria-label":"文档标题"})]}),n.jsxs("div",{className:"mdocs-ai-write-header-actions",children:[n.jsx("button",{type:"button",onClick:ce,disabled:x,children:"取消"}),n.jsx("button",{type:"button",className:"mdocs-ai-write-primary",onClick:()=>void re(),disabled:x,children:x?"写回中…":"完成并写回"})]})]}),n.jsxs("div",{className:"mdocs-ai-write-body",children:[n.jsxs("section",{className:"mdocs-ai-write-chat",children:[n.jsxs("div",{className:"mdocs-ai-write-chat-toolbar",children:[n.jsx("span",{className:"mdocs-ai-write-chat-toolbar-label",children:"对话"}),n.jsxs("div",{className:"mdocs-ai-write-chat-toolbar-actions",children:[n.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:M,onClick:()=>void le(),children:n.jsx(je,{size:16,strokeWidth:1.8})}),n.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(L?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>v(t=>!t),children:n.jsx(ke,{size:16,strokeWidth:1.8})})]})]}),L?n.jsxs("div",{className:"mdocs-ai-write-history mdocs-agent-panel-history",children:[n.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[n.jsx("span",{children:"历史会话"}),n.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>v(!1),children:"返回对话"})]}),I?n.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):_.length===0?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),n.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):n.jsx("ul",{className:"mdocs-agent-panel-history-list",children:_.map(t=>n.jsx("li",{children:n.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(t.id===E?" active":""),disabled:M,onClick:()=>void oe(t.id),children:[n.jsx("span",{className:"mdocs-agent-panel-history-title",children:t.title}),n.jsx("span",{className:"mdocs-agent-panel-history-time",children:Te(t.updatedAt)})]})},t.id))})]}):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"mdocs-ai-write-chat-messages",children:g.length===0?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"mdocs-ai-write-hint",children:"描述你想写或改的内容。助手可读取右侧当前稿与进场快照,再更新提案;请按段接受或拒绝后完成写回。"}),q?n.jsx(ee,{onConfigured:D}):null]}):g.map(t=>n.jsx("div",{className:"mdocs-ai-write-msg"+(t.role==="user"?" mdocs-ai-write-msg-user":""),children:t.role==="user"?n.jsxs(n.Fragment,{children:[t.skillNames&&t.skillNames.length>0?n.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",t.skillNames.length]}):null,t.content]}):Pe(t.blocks)?n.jsx("div",{className:"mdocs-ai-write-timeline",children:t.blocks.map((d,r)=>d.type==="thinking"?d.text?n.jsxs("details",{className:"mdocs-ai-write-thinking",open:M,children:[n.jsx("summary",{children:"思考中"}),n.jsx("pre",{className:"mdocs-ai-write-thinking-body",children:d.text})]},`${t.id}-think-${r}`):null:d.type==="tool"?n.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:d.text},`${t.id}-tool-${r}`):d.type==="skill_form_card"?n.jsx(ye,{block:d,onResolved:(R,P,Y)=>{w($=>$.map(o=>o.id!==t.id||o.role!=="assistant"?o:{...o,blocks:o.blocks.map(f=>f.type==="skill_form_card"&&f.requestId===R?{...f,status:P,submittedName:P==="submitted"?Y:f.submittedName}:f)}))}},`${t.id}-sf-${r}`):d.text?n.jsx("div",{className:"mdocs-agent-panel-md",children:n.jsx(pe,{remarkPlugins:[Ne],children:d.text})},`${t.id}-text-${r}`):null)}):M?n.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[n.jsx("span",{}),n.jsx("span",{}),n.jsx("span",{})]}):null},t.id))}),l?n.jsx("p",{className:"mdocs-ai-write-error",children:l}):null,q&&g.length>0?n.jsx(ee,{onConfigured:D}):null,n.jsxs("div",{className:"mdocs-ai-write-input-row",children:[n.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:6},children:[n.jsx(we,{selectedNames:F,onChange:K,disabled:M||!(j!=null&&j.enabled)}),n.jsx("textarea",{rows:2,value:H,disabled:M||!(j!=null&&j.enabled),placeholder:j!=null&&j.enabled?"说说要写什么…":"请先配置 API Key",onChange:t=>A(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),X())}})]}),n.jsx("button",{type:"button",className:M?"mdocs-ai-write-stop":void 0,disabled:M?!1:!(j!=null&&j.enabled),onClick:()=>{var t;if(M){(t=b.current)==null||t.abort();return}X()},children:M?"停止":"发送"})]})]})]}),n.jsx(Ae,{currentMd:i,proposedMd:a,sending:M,onCurrentChange:s,onProposedChange:m})]})]})}export{qe as AiWriteWorkbench};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import{r as i,j as n}from"./react-vendor-BJFXgntS.js";import{B as ke}from"./ui-BHvBMRFE.js";import{c as Y,g as Re,u as Ae,a as Ie,d as $e,b as Ye,f as Je,e as Ge,h as Ke,N as Xe,P as Qe,D as je,F as Ce,l as le,S as Se,i as Ze,M as pe,r as et,j as tt,k as nt,m as X,n as at,o as it,p as we}from"./index-4TuRcE3b.js";import{z as ot,A as st,m as de,n as rt,o as ct,p as lt,r as dt,s as ut,t as mt,v as ft,x as ht,B as yt,R as gt,a as xt,b as Me,c as vt,d as bt,e as kt,f as It,g as jt,h as Ct,i as St,w as ue,j as wt,O as Mt,E as Et,q as Nt,l as Dt,C as Rt,D as At}from"./react-B99eF5mm.js";import{H as Pt,a as Tt,b as Bt,M as Lt,T as _t,S as Ot,W as zt,o as Ht,c as Ee}from"./Toolbar-BDJ6WABq.js";import{V as Ft}from"./VisitorPickerModal-DPKIoySi.js";import"./motion-DddvD-ez.js";import"./diagram--gCCJK__.js";import"./editor-ONzd_YnO.js";import"./plus-CiGwts52.js";import"./copy-UwfRYkpI.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 Ut=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]],Wt=Y("ellipsis-vertical",Ut);/**
|
|
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 qt=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],Vt=Y("refresh-cw",qt);/**
|
|
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 $t=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M6.376 18.91a6 6 0 0 1 11.249.003",key:"hnjrf2"}],["circle",{cx:"12",cy:"11",r:"4",key:"1gt34v"}]],Yt=Y("shield-user",$t);/**
|
|
17
|
-
* @license lucide-react v0.562.0 - ISC
|
|
18
|
-
*
|
|
19
|
-
* This source code is licensed under the ISC license.
|
|
20
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const Jt=[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],Gt=Y("text-align-justify",Jt);/**
|
|
22
|
-
* @license lucide-react v0.562.0 - ISC
|
|
23
|
-
*
|
|
24
|
-
* This source code is licensed under the ISC license.
|
|
25
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const Kt=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],Xt=Y("users",Kt),Qt=48;function Q(e){try{const a=e.getDocument("markdown");return typeof a=="string"?a:""}catch{return null}}function Zt(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}function pt({editor:e,documentId:a,displayName:c,debounceMs:v=1e3,enabled:y=!0,localBaseCommitIdAtEditStart:S,snapshotMeta:w}){const[H,M]=i.useState(!1),[Z,P]=i.useState(!1),[p,b]=i.useState(null),u=i.useRef(null),f=i.useRef(null),k=i.useRef(!1),x=i.useRef(""),I=i.useRef(!1),E=i.useRef(a),ee=i.useRef(c),F=i.useRef(S),T=i.useRef(w);E.current=a,ee.current=c,F.current=S,T.current=w;const j=i.useCallback(async()=>{if(!e)return;if(!x.current){console.log("[useAutoSave] performSave blocked: lastContentRef is empty");return}const s=Zt(e);s!=null&&(console.log("[useAutoSave] performSave saving draft, documentId:",E.current,"content preview:",s.slice(0,80)),await Re(E.current).execute(()=>Ae({documentId:E.current,content:s,displayName:ee.current,localBaseCommitIdAtEditStart:F.current,snapshotMeta:T.current})),x.current=Q(e)??x.current,P(!0),M(!1),b(Date.now()),k.current=!0,I.current=!1)},[e]);i.useEffect(()=>{let s=!1;return Ie(a).then(m=>{s||(m?(P(!0),b(m.updatedAt),k.current=!0):(P(!1),b(null),k.current=!1,I.current=!1))}),()=>{s=!0}},[a]),i.useEffect(()=>{var O,B;if(!y){(O=f.current)==null||O.call(f),f.current=null;return}if(!e)return;const s=e.getLexicalEditor();if(!s)return;(B=f.current)==null||B.call(f);let m=!1,h=0,U=0;const g=()=>{if(m)return;const N=Q(e);if(N===null){if(U+=1,U>Qt)return;h=requestAnimationFrame(g);return}x.current=N;const ae=s.registerUpdateListener(()=>{const L=Q(e);L!==null&&L!==x.current&&(console.log("[useAutoSave] updateListener dirty, documentId:",a,"oldLen:",x.current.length,"newLen:",L.length),x.current=L,M(!0),I.current=!0,k.current=!1,u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{u.current=null,j()},v))});f.current=()=>{ae(),u.current&&(clearTimeout(u.current),u.current=null)}};return queueMicrotask(()=>{m||(h=requestAnimationFrame(g))}),()=>{var N;m=!0,cancelAnimationFrame(h),(N=f.current)==null||N.call(f)}},[y,e,a,c,v,S,w,j]),i.useEffect(()=>{var h;if(!y||!e)return;const s=(h=e.getLexicalEditor())==null?void 0:h.getRootElement();if(!s)return;const m=()=>{u.current&&(clearTimeout(u.current),u.current=null),I.current&&j()};return s.addEventListener("blur",m),()=>s.removeEventListener("blur",m)},[y,e,j]),i.useEffect(()=>{if(!y)return;const s=()=>{document.visibilityState==="hidden"&&(u.current&&(clearTimeout(u.current),u.current=null),I.current&&j())},m=()=>{I.current&&(u.current&&(clearTimeout(u.current),u.current=null),j())};return document.addEventListener("visibilitychange",s),window.addEventListener("beforeunload",m),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("beforeunload",m)}},[y,j]);async function te(){await $e(a),P(!1),M(!1),I.current=!1,k.current=!1,x.current=""}async function J(){const s=await Ie(a);return s?s.content:null}function ne(){P(!0),M(!1),I.current=!1,b(Date.now()),k.current=!0,e&&(x.current=Q(e)??"")}return{isDirty:H,draftExists:Z,lastSavedAt:p,clearDraft:te,loadDraftContent:J,markDraftSaved:ne}}function en({isDirty:e,draftExists:a}){const c=e&&!a;i.useEffect(()=>{if(!c)return;const v=y=>{y.preventDefault()};return window.addEventListener("beforeunload",v),()=>window.removeEventListener("beforeunload",v)},[c])}function me(e){try{return JSON.stringify(e.getDocument("json"))}catch{return null}}const Ne='{"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 De(e){const c=(e instanceof Error?e.message:String(e)).trim();return/^File too large$/i.test(c)?"文件过大(单文件上限 55MB)":/^unsupported file type$/i.test(c)?"不支持的文件类型":/^not an image$/i.test(c)?"不是有效的图片文件":c||"上传失败"}function tn(e,a){if(!e)return a==="json"?Ne:e;if(a!=="json")return e;try{const c=JSON.parse(e);if(c!=null&&c.root&&Array.isArray(c.root.children)&&c.root.children.length===0)return Ne}catch{}return e}function nn({editor:e}){const{visible:a}=Rt();return n.jsx("div",{className:"mdocs-outline-siderail",style:{flexShrink:0,overflow:"hidden",transition:"width 0.2s ease",width:a?200:0},children:n.jsx("div",{style:{width:200},children:n.jsx(At,{editor:e})})})}function yn(e){const{t:a,lang:c}=Ye(),[v,y]=i.useState(!1),[S,w]=i.useState(!1),H=i.useRef(null),M=i.useRef(null),[Z,P]=i.useState([]),[p,b]=i.useState(!1),[u,f]=i.useState(e.meta.permission),[k,x]=i.useState(!1),[I,E]=i.useState(!1),[ee,F]=i.useState(!1),[T,j]=i.useState(new Map),[te,J]=i.useState(!1);i.useEffect(()=>{const t=o=>{H.current&&!H.current.contains(o.target)&&y(!1),M.current&&!M.current.contains(o.target)&&w(!1)};return(v||S)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[v,S]),i.useEffect(()=>{let t=!0;return Je().then(o=>{t&&P(o)}).catch(()=>{}),()=>{t=!1}},[]);function ne(t){const o=Z.find(l=>l.visitorId===t);return(o==null?void 0:o.visitorName)??t.slice(0,8)}const[s,m]=i.useState(e.initialDisplayName),[h,U]=i.useState(!1),[g,O]=i.useState(!1),[B,N]=i.useState(!1),[ae,L]=i.useState(()=>localStorage.getItem("mdocs.autoEdit")!=="false"),D=e.canEdit&&ae,[d,fe]=i.useState(null),[Pe,he]=i.useState(!1),ie=i.useRef(null);i.useLayoutEffect(()=>{he(!1),fe(null),ie.current=null},[e.meta.documentId]),i.useEffect(()=>{const t=requestAnimationFrame(()=>he(!0));return()=>cancelAnimationFrame(t)},[e.meta.documentId]);const R=i.useMemo(()=>{var t;if(!e.initialContent)return"json";try{const o=JSON.parse(e.initialContent);return Array.isArray((t=o==null?void 0:o.root)==null?void 0:t.children)?"json":"markdown"}catch{return"markdown"}},[e.initialContent,e.contentRevision]),W=i.useMemo(()=>tn(e.initialContent||"",R),[e.initialContent,R,e.contentRevision]),{isDirty:ye,draftExists:q,markDraftSaved:Te}=pt({editor:d,documentId:e.meta.documentId,displayName:s,enabled:e.canEdit,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}});i.useEffect(()=>{var t;(t=e.onDraftExistsChange)==null||t.call(e,q)},[q,e.onDraftExistsChange]),en({isDirty:ye,draftExists:q}),i.useEffect(()=>{if(d)try{d.setDocument(R,W)}catch{}},[d,e.meta.documentId,e.contentRevision,W,R]),i.useEffect(()=>{d==null||d.setLocale(c==="zh"?ot:st)},[d,c]),i.useEffect(()=>{m(e.initialDisplayName)},[e.initialDisplayName,e.meta.documentId,e.contentRevision]),i.useEffect(()=>{f(e.meta.permission)},[e.meta.permission,e.meta.documentId]),i.useEffect(()=>{let t=!0;return(async()=>{try{const o=await Ge(e.meta.documentId);t&&O(o.bookmarked)}catch{}})(),()=>{t=!1}},[e.meta.documentId]);async function oe(){var t,o;if(!B){N(!0);try{g?(await et(e.meta.documentId),O(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await tt(e.meta.documentId),O(!0),(o=e.onShowToast)==null||o.call(e,a("bookmarkAdded")))}finally{N(!1)}}}i.useEffect(()=>(e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=Fe),()=>{e.saveBeforeNavRef&&(e.saveBeforeNavRef.current=void 0)})),i.useEffect(()=>{if(e.exportMarkdownRef)return e.exportMarkdownRef.current=()=>{const t=ie.current;if(!t)return"";try{const o=t.getDocument("markdown");return typeof o=="string"?o:String(o??"")}catch{return""}},()=>{e.exportMarkdownRef&&(e.exportMarkdownRef.current=void 0)}});function Be(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const Le=i.useCallback(t=>{ie.current=t,fe(t);const o=W;if(!o)return;const l=()=>{try{t.setDocument(R,o)}catch{requestAnimationFrame(()=>{try{t.setDocument(R,o)}catch{}})}};queueMicrotask(()=>{queueMicrotask(l)})},[R,W]);async function se(){if(!(!d||!e.canEdit)){U(!0);try{const t=me(d);if(!t)return;await e.onPublish(t,s,e.meta.documentId)}catch(t){throw t}finally{U(!1)}}}async function ge(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(s.trim()!==t)try{await se()}catch{}}const A=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),_e=i.useMemo(()=>{const t=(A==null?void 0:A.permission)??"public";return Ke(t)},[A==null?void 0:A.permission]);function Oe(t){return t===X.PRIVATE?a("permissionPrivate"):t===X.DOMAIN_READ?a("permissionInvite"):t===X.DOMAIN_WRITE?a("permissionDomainWrite"):t===X.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function ze(){var t;if(k||u===e.meta.permission){b(!1);return}x(!0);try{const l=(d?me(d):null)??e.initialContent;await e.onPublish(l,s,e.meta.documentId,u),b(!1),(t=e.onShowToast)==null||t.call(e,a("docInfoPermissionUpdated"))}finally{x(!1)}}async function He(t){var o;if(!te){J(!0);try{const l=new Set(t.map(r=>r.visitorId)),_=new Map(t.map(r=>[r.visitorId,r.permission]));for(const[r]of T)l.has(r)||await at(e.meta.documentId,r);for(const{visitorId:r,permission:V}of t){const $=T.get(r);(!$||$!==V)&&await it(e.meta.documentId,r,V)}E(!1),(o=e.onShowToast)==null||o.call(e,a("docInfoInviteSuccess",{count:t.length}))}finally{J(!1)}}}async function Fe(){if(!d||!e.canEdit)return;if(!ye){console.log("[DocumentEditor.saveDraft] skipped: not dirty, documentId:",e.meta.documentId);return}const t=me(d);t&&(console.log("[DocumentEditor.saveDraft] saving draft, documentId:",e.meta.documentId,"content preview:",t.slice(0,80)),Te(),await Re(e.meta.documentId).execute(()=>Ae({documentId:e.meta.documentId,content:t,displayName:s,localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})))}const Ue=i.useMemo(()=>[{icon:Pt,key:"h1",label:"Heading 1",onSelect:t=>{t.dispatchCommand(de,{tag:"h1"})}},{icon:Tt,key:"h2",label:"Heading 2",onSelect:t=>{t.dispatchCommand(de,{tag:"h2"})}},{icon:Bt,key:"h3",label:"Heading 3",onSelect:t=>{t.dispatchCommand(de,{tag:"h3"})}},{type:"divider"},{icon:Lt,key:"hr",label:"Hr",onSelect:t=>{t.dispatchCommand(rt,{})}},{icon:_t,key:"table",label:"Table",onSelect:t=>{t.dispatchCommand(ct,{columns:"3",rows:"3"})}},{icon:Ot,key:"tex",label:"TeX",onSelect:t=>{t.dispatchCommand(lt,{code:"x^2 + y^2 = z^2"}),queueMicrotask(()=>t.focus())}},{type:"divider"},{key:"file",label:"File",onSelect:t=>{Ht(o=>{for(const l of o)t.dispatchCommand(Nt,{file:l})})}},{key:"insert-link",label:"Insert Link",onSelect:t=>{t.dispatchCommand(dt,{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(mt,void 0),queueMicrotask(()=>t.focus())}},{icon:zt,key:"meta2d",label:"Meta2d",onSelect:t=>{t.dispatchCommand(ft,void 0),queueMicrotask(()=>t.focus())}},{icon:Xe,key:"markmap",label:"Markmap",onSelect:t=>{t.dispatchCommand(ht,void 0),queueMicrotask(()=>t.focus())}}].map(t=>"type"in t&&t.type==="divider"?t:{...t,extra:n.jsx("span",{style:{color:"var(--mdocs-text-muted)",fontFamily:"monospace",fontSize:12},children:t.key})}),[]),We=i.useMemo(()=>[yt,gt,xt,Me,vt,bt,kt,It,jt,Ct,St,ue(wt,{children:d?n.jsx(Ee,{editor:d,floating:!0,outlineCollapseTitle:a("outlineHide"),outlineExpandTitle:a("outlineShow"),outlineToggle:!0}):null}),ue(Dt,{handleUpload:async t=>{var o;try{return{url:await we(t,e.meta.documentId)}}catch(l){throw(o=e.onShowError)==null||o.call(e,De(l)),l}}}),ue(Me,{defaultBlockImage:!0,needRehost:t=>t.startsWith("blob:"),handleRehost:async t=>{var o;try{const _=await(await fetch(t)).blob(),r=new File([_],"image.png",{type:_.type});return{url:await we(r,e.meta.documentId)}}catch(l){throw(o=e.onShowError)==null||o.call(e,De(l)),l}}})],[d,a,e.meta.documentId,e.onShowError]),C=!!e.readerChrome,[z,re]=i.useState(!1),G=i.useRef(null),[xe,ce]=i.useState(0);i.useEffect(()=>{if(!C){re(!1),ce(0);return}if(z)return;const t=window.setTimeout(()=>re(!0),2800);return()=>window.clearTimeout(t)},[C,z,e.meta.documentId]),i.useEffect(()=>{w(!1),y(!1)},[e.meta.documentId]);function qe(t){!C||z||t.target.closest("button, a, input, textarea, select")||(G.current={startY:t.clientY,dragging:!0},t.currentTarget.setPointerCapture(t.pointerId))}function Ve(t){const o=G.current;if(!(o!=null&&o.dragging))return;const l=t.clientY-o.startY;ce(Math.max(-72,Math.min(0,l)))}function ve(t){const o=G.current;if(!(o!=null&&o.dragging))return;G.current=null;const l=t.clientY-o.startY;ce(0),l<-36&&re(!0);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}function K(){y(!1),w(!1)}function be(t,o){const l=(o==null?void 0:o.includeBookmark)??!0,_={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:ne(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(c==="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:Be(new Blob([e.initialContent]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(c==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),l?n.jsxs("button",{type:"button",style:_,onMouseEnter:r=>{r.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:r=>{r.currentTarget.style.background="none"},onClick:()=>{oe(),t()},children:[n.jsx("span",{children:g?"⭐":"☆"}),n.jsx("span",{children:a(g?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:_,onMouseEnter:r=>{r.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:r=>{r.currentTarget.style.background="none"},onClick:()=>{t(),(async()=>{F(!0);try{const r=await nt(e.meta.documentId),V=new Map(r.map($=>[$.visitorId,$.permission]));j(V),E(!0)}finally{F(!1)}})()},children:[n.jsx(Xt,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:_,onMouseEnter:r=>{r.currentTarget.style.background="var(--mdocs-hover-bg, #f5f5f5)"},onMouseLeave:r=>{r.currentTarget.style.background="none"},onClick:()=>{t(),f(e.meta.permission),b(!0)},children:[n.jsx(Yt,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})}return n.jsxs("div",{className:"mdocs-editor"+(C?" mdocs-editor--reader":"")+(C&&z?" mdocs-editor--reader-docked":""),children:[n.jsx("div",{className:"mdocs-editor-toolbar"+(C?z?" mdocs-editor-toolbar--docked":" mdocs-editor-toolbar--float":""),style:C&&!z&&xe!==0?{transform:`translateY(${xe}px)`}:void 0,children:C?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mdocs-editor-toolbar-leading",onPointerDown:qe,onPointerMove:Ve,onPointerUp:ve,onPointerCancel:ve,children:[n.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>{var t;return(t=e.onOpenMobileNav)==null?void 0:t.call(e)},"aria-label":a("expandSidebar"),children:n.jsx(Qe,{size:18,strokeWidth:1.75})}),n.jsx("input",{className:"mdocs-editor-title-input",value:s,onChange:t=>m(t.target.value),onBlur:()=>void ge(),placeholder:a("displayNamePlaceholder"),disabled:!D,readOnly:!D})]}),n.jsx(je,{domains:e.domains.length?e.domains:[Ce],value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:a("currentDomainAria"),localizeName:t=>le(t,c,a)}),e.canEdit?n.jsx("button",{type:"button",className:"primary mdocs-reader-action-btn",disabled:h,onClick:()=>{D||L(!0),se().catch(()=>{})},children:a(h?"publishing":"publish")}):null,n.jsxs("div",{ref:M,className:"mdocs-reader-more-menu",children:[n.jsx("button",{type:"button",className:"mdocs-reader-more-btn","aria-label":"更多","aria-expanded":S,onClick:()=>w(t=>!t),children:n.jsx(Wt,{size:18,strokeWidth:1.75})}),S?n.jsxs("div",{className:"mdocs-reader-more-dropdown card",children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:B,onClick:()=>{oe(),K()},children:[n.jsx(Se,{size:16,strokeWidth:1.5,style:{color:g?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:g?"#faad14":"none"}}),n.jsx("span",{children:a(g?"bookmarkRemove":"bookmarkAdd")})]}),e.canEdit?n.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:h,onClick:()=>{K(),e.onDelete()},children:n.jsx("span",{children:a("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),be(K,{includeBookmark:!1})]}):null]})]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mdocs-editor-toolbar-leading",children:[n.jsx("input",{className:"mdocs-editor-title-input",value:s,onChange:t=>m(t.target.value),onBlur:()=>void ge(),placeholder:a("displayNamePlaceholder"),disabled:!D}),n.jsx(je,{domains:e.domains.length?e.domains:[Ce],value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:a("currentDomainAria"),localizeName:t=>le(t,c,a)}),e.onAiWrite?n.jsxs("button",{type:"button",className:"secondary",onClick:()=>{var t;return(t=e.onAiWrite)==null?void 0:t.call(e)},style:{padding:"4px 10px",whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",gap:6},children:[n.jsx("img",{src:Ze,alt:"",width:16,height:16,style:{display:"block"}}),"帮写"]}):null]}),n.jsx("span",{className:"mdocs-editor-toolbar-spacer","aria-hidden":!0}),n.jsxs("div",{className:"mdocs-editor-toolbar-trailing",children:[n.jsxs("button",{type:"button",className:"secondary mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>void oe(),disabled:B,"data-tooltip":g?"取消收藏":"收藏",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,opacity:B?.5:1},children:[n.jsx(Se,{size:18,strokeWidth:1.5,style:{color:g?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:g?"#faad14":"none"}}),g?n.jsx("span",{children:"已收藏"}):null]}),n.jsxs("div",{className:"mdocs-editor-toolbar-actions",children:[e.onSyncClick?n.jsxs("button",{type:"button",className:"mdocs-sync-btn mdocs-tooltip mdocs-tooltip-bottom"+(e.syncBehind?" behind":""),"data-tooltip":e.syncBehind?a("syncBehindHint"):a("syncPull"),onClick:()=>{var t;return void((t=e.onSyncClick)==null?void 0:t.call(e))},style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx(Vt,{size:16,strokeWidth:1.5}),n.jsx("span",{children:a("syncPull")})]}):null,D?n.jsxs(n.Fragment,{children:[localStorage.getItem("mdocs.autoPublish")!=="true"&&n.jsxs("span",{className:"mdocs-save-indicator",children:[n.jsx("span",{className:"mdocs-save-dot "+(h?"saving":q?"unsaved":"saved")}),n.jsx("span",{children:a(h?"publishing":q?"unsaved":"published")})]}),n.jsx("button",{type:"button",className:"primary",disabled:h,onClick:()=>{se().catch(()=>{})},children:a(h?"publishing":"publish")}),n.jsx("button",{type:"button",className:"danger",disabled:h,onClick:e.onDelete,children:a("delete")})]}):null,!D&&e.canEdit?n.jsx("button",{type:"button",className:"primary",onClick:()=>L(!0),children:a("edit")}):null,n.jsxs("button",{type:"button",className:"secondary mdocs-tooltip mdocs-tooltip-bottom",onClick:e.onToggleComments,"data-tooltip":"评论",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:e.commentPanelOpen?"var(--mdocs-hover-bg, #f0f0f0)":void 0},children:[n.jsx(pe,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}}),e.commentCount>0?n.jsx("span",{style:{fontSize:"0.85rem"},children:e.commentCount}):null]}),n.jsxs("div",{ref:H,className:"mdocs-tooltip mdocs-tooltip-bottom","data-tooltip":a("docInfo"),style:{position:"relative"},children:[n.jsx("button",{type:"button",className:"secondary",onClick:()=>y(!v),style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:n.jsx(Gt,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}})}),v?n.jsx("div",{className:"mdocs-doc-info-dropdown",children:be(K)}):null]})]})]})]})}),p&&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"),":",A?le(A.domainName,c,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:_e.map(t=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n.jsx("input",{type:"radio",name:"doc-permission",value:t,checked:u===t,onChange:()=>f(t)}),n.jsx("span",{children:Oe(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:k,onClick:()=>void ze(),children:a(k?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Ft,{open:I,title:a("docInfoInviteMember"),initialSelectedIds:[...T.keys()],initialPermissions:T,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>E(!1),onConfirm:t=>{He(t)}}),n.jsx(Mt,{children:n.jsx(ke,{flex:1,style:{minHeight:0},children:n.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[D&&d&&!C?n.jsx(Ee,{editor:d,outlineCollapseTitle:a("outlineHide"),outlineExpandTitle:a("outlineShow"),outlineToggle:!0}):null,n.jsx("div",{className:"mdocs-editor-content-area",style:{flex:1,display:"flex",minHeight:0},children:n.jsxs(ke,{variant:"outlined",horizontal:!0,style:{background:"var(--mdocs-surface)",flex:1,minHeight:0,minWidth:0,borderRadius:0,outline:"none"},children:[n.jsx("div",{className:"mdocs-editor-scroll-host",children:Pe?n.jsx(Et,{content:W,type:R,confirmPasteMarkdown:!0,editable:D,onInit:Le,plugins:We,lineEmptyPlaceholder:a("displayNamePlaceholder"),placeholder:a("displayNamePlaceholder"),slashOption:{items:Ue},className:"mdocs-document-editor-root"},e.meta.documentId):null}),d&&n.jsx(nn,{editor:d})]})})]})})})]})}export{yn as DocumentEditor};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import{r as n,j as o,ae as C}from"./react-vendor-BJFXgntS.js";import{u as N,E as T,R as I,a as E,b as M,c as j,d as O,e as P,f as A,g as _,h as D,i as H,w as f,j as L,k as F,l as q,I as U,m as b,n as V,o as z,p as J,q as W,r as B,s as $,t as K,v as Y,x as G,y as Z}from"./react-B99eF5mm.js";import{v as Q,x as X,H as ee,y as te,A as k,z as oe}from"./ui-BHvBMRFE.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-BDJ6WABq.js";import{N as me}from"./index-4TuRcE3b.js";import"./editor-ONzd_YnO.js";import"./diagram--gCCJK__.js";import"./plus-CiGwts52.js";import"./copy-UwfRYkpI.js";import"./motion-DddvD-ez.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(z,{columns:"3",rows:"3"})}},{icon:se,key:"tex",label:"Tex",onSelect:e=>{e.dispatchCommand(J,{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(W,{file:u})})}},{key:"set-text-content",label:"SetTextContent",onSelect:e=>{e.setDocument("text",`123
|
|
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
|
-
<mention>${t.label}[${((e=t.metadata)==null?void 0:e.id)||t.label}]</mention>
|
|
4
|
-
`},onSelect:(t,e)=>{t.dispatchCommand(U,{label:String(e.label),metadata:{id:e.key}})},searchKeys:["label"]},onInit:x,onTextChange:c,pasteVSCodeAsCodeBlock:!0,placeholder:"Type something...",plugins:[I,E,M,j,O,P,A,_,D,H,f(L,{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:
|
|
5
|
-
|
|
6
|
-
${t}`}),headers:{"Content-Type":"application/json"},method:"POST",signal:u});if(u.aborted)return console.log("Auto-complete aborted"),null;const i=await v.json();if(i)return typeof i.content=="string"&&i.content.startsWith(t)?i.content.replace(t,""):i.content}catch{}return null}}),f(M,{defaultBlockImage:!0,handleRehost:async t=>{const l=await(await fetch(t)).blob();return await new Promise((u,v)=>{const i=new FileReader;i.onloadend=()=>u({url:i.result}),i.onerror=v,i.readAsDataURL(l)})},needRehost:t=>(console.debug("needRehost",t),t.startsWith("blob:"))}),f(q,{handleUpload:async t=>(console.debug("Files uploaded:",t),new Promise(e=>{setTimeout(()=>{const l=URL.createObjectURL(t);a.current.push(l),e({url:l})},1e3)})),markdownWriter:t=>`
|
|
7
|
-
<file>${t.fileUrl}</file>
|
|
8
|
-
`})],slashOption:{items:w}})]})};function Ce(){return o.jsxs("div",{className:"mdocs-playground-page",children:[o.jsx("header",{className:"mdocs-playground-header",children:o.jsx(C,{className:"mdocs-playground-back",to:"/",children:"← mdocs"})}),o.jsx(pe,{})]})}export{Ce as PlaygroundPage};
|