@fgbg/mdocs 1.4.1 → 2.0.0

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.
Files changed (115) hide show
  1. package/README.md +1 -1
  2. package/agent-skills/changelog/SKILL.md +19 -0
  3. package/dist/server/agent/Agent/run-manager.js +1 -0
  4. package/dist/server/agent/Agent/run-manager.js.map +1 -1
  5. package/dist/server/agent/Agent/run-pi-agent.js +22 -7
  6. package/dist/server/agent/Agent/run-pi-agent.js.map +1 -1
  7. package/dist/server/agent/Agent/run.js +29 -4
  8. package/dist/server/agent/Agent/run.js.map +1 -1
  9. package/dist/server/agent/Agent/session-manager.js +45 -5
  10. package/dist/server/agent/Agent/session-manager.js.map +1 -1
  11. package/dist/server/agent/Agent/system-prompt.js +5 -3
  12. package/dist/server/agent/Agent/system-prompt.js.map +1 -1
  13. package/dist/server/agent/Agent/tools-documents.js +13 -4
  14. package/dist/server/agent/Agent/tools-documents.js.map +1 -1
  15. package/dist/server/agent/Agent/tools-registry.test.js +1 -1
  16. package/dist/server/agent/Agent/tools-registry.test.js.map +1 -1
  17. package/dist/server/agent/Agent/tools-template.js +2 -1
  18. package/dist/server/agent/Agent/tools-template.js.map +1 -1
  19. package/dist/server/agent/Config/config.test.js +21 -0
  20. package/dist/server/agent/Config/config.test.js.map +1 -1
  21. package/dist/server/agent/attachments/capabilities.js +52 -0
  22. package/dist/server/agent/attachments/capabilities.js.map +1 -0
  23. package/dist/server/agent/attachments/capabilities.test.js +33 -0
  24. package/dist/server/agent/attachments/capabilities.test.js.map +1 -0
  25. package/dist/server/agent/attachments/index.js +6 -0
  26. package/dist/server/agent/attachments/index.js.map +1 -0
  27. package/dist/server/agent/attachments/inject.js +67 -0
  28. package/dist/server/agent/attachments/inject.js.map +1 -0
  29. package/dist/server/agent/attachments/inject.test.js +41 -0
  30. package/dist/server/agent/attachments/inject.test.js.map +1 -0
  31. package/dist/server/agent/attachments/object-fs.js +44 -0
  32. package/dist/server/agent/attachments/object-fs.js.map +1 -0
  33. package/dist/server/agent/attachments/parse/image.js +22 -0
  34. package/dist/server/agent/attachments/parse/image.js.map +1 -0
  35. package/dist/server/agent/attachments/parse/pdf.js +19 -0
  36. package/dist/server/agent/attachments/parse/pdf.js.map +1 -0
  37. package/dist/server/agent/attachments/parse/plain-text.js +18 -0
  38. package/dist/server/agent/attachments/parse/plain-text.js.map +1 -0
  39. package/dist/server/agent/attachments/prepare-turn.js +32 -0
  40. package/dist/server/agent/attachments/prepare-turn.js.map +1 -0
  41. package/dist/server/agent/attachments/store.js +120 -0
  42. package/dist/server/agent/attachments/store.js.map +1 -0
  43. package/dist/server/agent/attachments/tools-read-attachment.js +95 -0
  44. package/dist/server/agent/attachments/tools-read-attachment.js.map +1 -0
  45. package/dist/server/agent/attachments/types.js +6 -0
  46. package/dist/server/agent/attachments/types.js.map +1 -0
  47. package/dist/server/agent/attachments/upload-filename.test.js +39 -0
  48. package/dist/server/agent/attachments/upload-filename.test.js.map +1 -0
  49. package/dist/server/agent/attachments/upload.js +11 -0
  50. package/dist/server/agent/attachments/upload.js.map +1 -0
  51. package/dist/server/app.js +9 -1
  52. package/dist/server/app.js.map +1 -1
  53. package/dist/server/config/index.js +1 -0
  54. package/dist/server/config/index.js.map +1 -1
  55. package/dist/server/db/repositories/agent-attachment.repo.js +51 -0
  56. package/dist/server/db/repositories/agent-attachment.repo.js.map +1 -0
  57. package/dist/server/db/repositories/document.repo.js +9 -9
  58. package/dist/server/db/repositories/document.repo.js.map +1 -1
  59. package/dist/server/db/schema.js +64 -3
  60. package/dist/server/db/schema.js.map +1 -1
  61. package/dist/server/documents/document.service.js +2 -3
  62. package/dist/server/documents/document.service.js.map +1 -1
  63. package/dist/server/documents/graph.integration.test.js +1 -0
  64. package/dist/server/documents/graph.integration.test.js.map +1 -1
  65. package/dist/server/documents/tree-and-folders.test.js +1 -0
  66. package/dist/server/documents/tree-and-folders.test.js.map +1 -1
  67. package/dist/server/domains/change-domain-permission.test.js +12 -0
  68. package/dist/server/domains/change-domain-permission.test.js.map +1 -1
  69. package/dist/server/routes/agent.routes.js +85 -2
  70. package/dist/server/routes/agent.routes.js.map +1 -1
  71. package/dist/server/routes/visitors.routes.js +2 -0
  72. package/dist/server/routes/visitors.routes.js.map +1 -1
  73. package/dist/server/search/document-index-manager.js +13 -4
  74. package/dist/server/search/document-index-manager.js.map +1 -1
  75. package/dist/server/search/document-index-manager.test.js +14 -3
  76. package/dist/server/search/document-index-manager.test.js.map +1 -1
  77. package/dist/server/search/embedding-store.js +9 -0
  78. package/dist/server/search/embedding-store.js.map +1 -1
  79. package/dist/server/search/embedding-store.test.js +27 -3
  80. package/dist/server/search/embedding-store.test.js.map +1 -1
  81. package/dist/shared/file-type-policy.js +1 -1
  82. package/dist/shared/file-type-policy.js.map +1 -1
  83. package/dist/shared/file-type-policy.test.js +2 -1
  84. package/dist/shared/file-type-policy.test.js.map +1 -1
  85. package/dist/web/assets/AgentChatPanel-Bhv57WUW.js +47 -0
  86. package/dist/web/assets/{AiWriteWorkbench-ob4AeDFt.js → AiWriteWorkbench-DOse9-oQ.js} +4 -4
  87. package/dist/web/assets/{DiagramEditor-NtNY3sZL-BuZCaqLT.js → DiagramEditor-NtNY3sZL-D7sapmVz.js} +1 -1
  88. package/dist/web/assets/{DocChrome-DwSYxHOP.js → DocChrome-Dj5rSAvl.js} +1 -1
  89. package/dist/web/assets/{DocumentEditor-C_TFaCan.js → DocumentEditor-BTxsH3UT.js} +1 -1
  90. package/dist/web/assets/{HtmlEditor-CYPTi1_L.js → HtmlEditor-OEfTnjjz.js} +1 -1
  91. package/dist/web/assets/MergeView-CGz2CWUZ.js +10 -0
  92. package/dist/web/assets/{PlaygroundPage-Bt53Sr06.js → PlaygroundPage-BsekHU2o.js} +1 -1
  93. package/dist/web/assets/{SettingsPage-C2SYz-8K.js → SettingsPage-cVFmyADe.js} +5 -5
  94. package/dist/web/assets/SheetEditor-1LMR2jA1.js +26 -0
  95. package/dist/web/assets/SheetEditor-DJOs2u-u.css +1 -0
  96. package/dist/web/assets/{Toolbar-LRioFemr.js → Toolbar-CPIpQgP1.js} +1 -1
  97. package/dist/web/assets/VisitorPickerModal-aRuuDomz.js +6 -0
  98. package/dist/web/assets/{check-65pb-o1o.js → check-NyVbPIj8.js} +1 -1
  99. package/dist/web/assets/{copy-BT35-MU9.js → copy-C_H9wgwB.js} +1 -1
  100. package/dist/web/assets/file-type-policy-5jFXMeIz.js +1 -0
  101. package/dist/web/assets/index-CervldVc.css +1 -0
  102. package/dist/web/assets/{index-92xZ1zjh.js → index-Kp5r4mc7.js} +48 -48
  103. package/dist/web/assets/{italic-BmGXEOKX.js → italic-BqrahN0G.js} +1 -1
  104. package/dist/web/assets/{meta2dEngine-BD2XbzaV-DeIPntMM.js → meta2dEngine-BD2XbzaV-CUKxedXW.js} +1 -1
  105. package/dist/web/assets/{plus-Ss1czARp.js → plus-D8tCpRfA.js} +1 -1
  106. package/dist/web/assets/{react-DHtvOuT-.js → react-DsdrF7vh.js} +3 -3
  107. package/dist/web/index.html +2 -2
  108. package/package.json +1 -1
  109. package/dist/web/assets/AgentChatPanel-BMOzVvwA.js +0 -42
  110. package/dist/web/assets/MergeView-FPF3k11v.js +0 -10
  111. package/dist/web/assets/SheetEditor-BOF-OgqU.js +0 -26
  112. package/dist/web/assets/SheetEditor-BPTMQ2s5.css +0 -1
  113. package/dist/web/assets/VisitorPickerModal-iK2QsYfY.js +0 -6
  114. package/dist/web/assets/file-type-policy-aRrzC4LZ.js +0 -1
  115. package/dist/web/assets/index-DE_nAopH.css +0 -1
@@ -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-92xZ1zjh.js";import{D as Me,S as Be}from"./DocChrome-DwSYxHOP.js";import{V as Re,U as Ae}from"./VisitorPickerModal-iK2QsYfY.js";import{c as Te}from"./docPlainCharCount-DO5lb3Wt.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./file-type-policy-aRrzC4LZ.js";function _e(e){const{t:a,lang:k}=xe(),r=e.meta.documentId,[h,N]=i.useState(e.initialContent),[x,P]=i.useState(e.initialDisplayName),[u,j]=i.useState(!0),[q,G]=i.useState(!1),[p,I]=i.useState(e.hasLocalDraft??!1),[f,M]=i.useState(!1),[B,K]=i.useState(!1),[v,R]=i.useState(!1),[y,A]=i.useState(!1),[ee,te]=i.useState([]),[ne,b]=i.useState(!1),[T,z]=i.useState(e.meta.permission),[O,Q]=i.useState(!1),[ie,L]=i.useState(!1),[w,ae]=i.useState(new Map),[Y,V]=i.useState(null),D=i.useRef(0),U=i.useRef(null),F=i.useRef(null),c=i.useRef(null),S=i.useRef(h),W=i.useRef(x);S.current=h,W.current=x;const se=e.canEdit&&!u;i.useEffect(()=>{N(e.initialContent),P(e.initialDisplayName),j(!0)},[r]),i.useEffect(()=>{e.contentRevision&&(N(e.initialContent),P(e.initialDisplayName))},[e.contentRevision]),i.useEffect(()=>{let t=!0;return ve().then(s=>{t&&te(s)}).catch(()=>{}),()=>{t=!1}},[]),i.useEffect(()=>{let t=!0;return ge(r).then(s=>{t&&M(s.bookmarked)}).catch(()=>{}),()=>{t=!1}},[r]),i.useEffect(()=>{let t=!1;const s=Z();return ye(r).then(o=>{var m;if(t||Z()!==s)return;const l=!!(o&&!o.published);I(l),(m=e.onDraftExistsChange)==null||m.call(e,l)}),()=>{t=!0}},[r,e.onDraftExistsChange]),i.useEffect(()=>be((t,s)=>{var o;t===r&&(I(s),(o=e.onDraftExistsChange)==null||o.call(e,s))}),[r,e.onDraftExistsChange]),i.useEffect(()=>{z(e.meta.permission)},[e.meta.permission,r]),i.useEffect(()=>{const t=s=>{U.current&&!U.current.contains(s.target)&&R(!1),F.current&&!F.current.contains(s.target)&&A(!1)};return(v||y)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[v,y]),i.useEffect(()=>{if(!v&&!y)return;const t=++D.current;V(null);const s=()=>{if(t===D.current)try{const m=Te("html",S.current||"");t===D.current&&V(m)}catch{t===D.current&&V(0)}},o=window;if(typeof o.requestIdleCallback=="function"){const m=o.requestIdleCallback(s);return()=>{var C;return(C=o.cancelIdleCallback)==null?void 0:C.call(o,m)}}const l=window.setTimeout(s,0);return()=>window.clearTimeout(l)},[v,y,h,r,e.contentRevision]);const H=i.useCallback(async()=>{var t;await Ce(r).execute(()=>ke({documentId:r,content:S.current,displayName:W.current,contentKind:"html",localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})),I(!0),(t=e.onDraftExistsChange)==null||t.call(e,!0)},[r,e]),J=i.useCallback(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{H()},1e3)},[H]);i.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);async function $(t){var s;if(e.canEdit){G(!0);try{c.current&&(clearTimeout(c.current),c.current=null),await H(),await e.onPublish(S.current,W.current.trim()||x,r,t),I(!1),(s=e.onDraftExistsChange)==null||s.call(e,!1)}finally{G(!1)}}}async function oe(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(x.trim()!==t)try{await $()}catch{}}async function _(){var t,s;if(!B){K(!0);try{f?(await De(r),M(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await Se(r),M(!0),(s=e.onShowToast)==null||s.call(e,a("bookmarkAdded")))}finally{K(!1)}}}function re(t){const s=ee.find(o=>o.visitorId===t);return(s==null?void 0:s.visitorName)??t.slice(0,8)}function le(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const d=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),ce=i.useMemo(()=>{const t=(d==null?void 0:d.permission)??"public";return je(t)},[d==null?void 0:d.permission]);function de(t){return t===E.PRIVATE?a("permissionPrivate"):t===E.DOMAIN_READ?a("permissionInvite"):t===E.DOMAIN_WRITE?a("permissionDomainWrite"):t===E.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function me(){if(O||T===e.meta.permission){b(!1);return}Q(!0);try{await $(T),b(!1)}finally{Q(!1)}}async function ue(t){const s=new Set(t.map(o=>o.visitorId));for(const[o]of w)s.has(o)||await Ne(r,o);for(const o of t)w.get(o.visitorId)!==o.permission&&await Pe(r,o.visitorId,o.permission);L(!1)}function g(){R(!1),A(!1)}function X(t,s){const o=(s==null?void 0:s.includeBookmark)??!0,l={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreator")}),n.jsx("span",{children:re(e.meta.ownerVisitorId)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreatedAt")}),n.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(k==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoSize")}),n.jsx("span",{children:le(new Blob([h]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCharCount")}),n.jsx("span",{children:Y===null?"…":Y.toLocaleString(k==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(k==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),o?n.jsxs("button",{type:"button",style:l,onClick:()=>{_(),t()},children:[n.jsx("span",{children:f?"⭐":"☆"}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),(async()=>{const m=await Ee(r);ae(new Map(m.map(C=>[C.visitorId,C.permission]))),L(!0)})()},children:[n.jsx(Ae,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),z(e.meta.permission),b(!0)},children:[n.jsx(Be,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})}const fe=i.useCallback(t=>{var o;const s=t.target.value;N(s),(o=e.onContentChange)==null||o.call(e,s),J()},[e,J]),he=`<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head><body>${h}</body></html>`;return n.jsxs("div",{className:"mdocs-editor"+(e.readerChrome?" mdocs-editor--reader":""),children:[n.jsx(Me,{fileType:"html",displayName:x,onDisplayNameChange:P,onDisplayNameBlur:()=>void oe(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:se,onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:q,draftExists:p,onPublish:()=>{$().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:f,bookmarkBusy:B,onToggleBookmark:()=>void _(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:X(g),docInfoOpen:v,onToggleDocInfo:()=>R(!v),docInfoMenuRef:U,readerChrome:e.readerChrome,readerActionsCollapsible:!0,readerHeaderDocked:e.readerChrome,onOpenMobileNav:e.onOpenMobileNav,readerMoreOpen:y,onToggleReaderMore:()=>A(t=>!t),readerMoreMenuRef:F,readerMoreMenu:n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:B,onClick:()=>{_(),g()},children:[n.jsx(Ie,{size:16,strokeWidth:1.5,style:{color:f?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:f?"#faad14":"none"}}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}),n.jsx("div",{className:"mdocs-reader-more-divider"}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:!u,onClick:()=>{j(!1),g()},children:a("edit")}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:u,onClick:()=>{j(!0),g()},children:a("preview")}),n.jsx("div",{className:"mdocs-reader-more-divider"}),e.canEdit?n.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:q,onClick:()=>{g(),e.onDelete()},children:n.jsx("span",{children:a("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),X(g,{includeBookmark:!1})]}),leadingExtra:e.canEdit&&!e.readerChrome?n.jsxs("label",{className:"mdocs-editor-mode-toggle","aria-label":a(u?"preview":"edit"),children:[n.jsx("input",{type:"checkbox",checked:u,onChange:()=>j(t=>!t)}),n.jsxs("span",{className:"mdocs-editor-mode-toggle-slider",children:[n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--left",children:a("edit")}),n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--right",children:a("preview")})]})]}):null}),n.jsxs("div",{className:"mdocs-html-editor-body",children:[!u&&e.canEdit?n.jsx("textarea",{className:"mdocs-html-editor-textarea",value:h,onChange:fe,spellCheck:!1,placeholder:"在此处编写 HTML 代码"}):null,n.jsx("div",{className:"mdocs-html-editor-preview",style:!u&&e.canEdit?{width:"50%"}:{width:"100%"},children:n.jsx("iframe",{className:"mdocs-html-editor-iframe",srcDoc:he,sandbox:"",title:x})})]}),ne&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&b(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:a("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[a("domainPermission"),":",d?we(d.domainName,k,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:ce.map(t=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n.jsx("input",{type:"radio",name:"html-doc-permission",value:t,checked:T===t,onChange:()=>z(t)}),n.jsx("span",{children:de(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>b(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:O,onClick:()=>void me(),children:a(O?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Re,{open:ie,title:a("docInfoInviteMember"),initialSelectedIds:[...w.keys()],initialPermissions:w,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>L(!1),onConfirm:t=>{ue(t)}})]})}export{_e as HtmlEditor};
1
+ 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-Kp5r4mc7.js";import{D as Me,S as Be}from"./DocChrome-Dj5rSAvl.js";import{V as Re,U as Ae}from"./VisitorPickerModal-aRuuDomz.js";import{c as Te}from"./docPlainCharCount-DO5lb3Wt.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./file-type-policy-5jFXMeIz.js";function _e(e){const{t:a,lang:k}=xe(),r=e.meta.documentId,[h,N]=i.useState(e.initialContent),[x,P]=i.useState(e.initialDisplayName),[u,j]=i.useState(!0),[q,G]=i.useState(!1),[p,I]=i.useState(e.hasLocalDraft??!1),[f,M]=i.useState(!1),[B,K]=i.useState(!1),[v,R]=i.useState(!1),[y,A]=i.useState(!1),[ee,te]=i.useState([]),[ne,b]=i.useState(!1),[T,z]=i.useState(e.meta.permission),[O,Q]=i.useState(!1),[ie,L]=i.useState(!1),[w,ae]=i.useState(new Map),[Y,V]=i.useState(null),D=i.useRef(0),U=i.useRef(null),F=i.useRef(null),c=i.useRef(null),S=i.useRef(h),W=i.useRef(x);S.current=h,W.current=x;const se=e.canEdit&&!u;i.useEffect(()=>{N(e.initialContent),P(e.initialDisplayName),j(!0)},[r]),i.useEffect(()=>{e.contentRevision&&(N(e.initialContent),P(e.initialDisplayName))},[e.contentRevision]),i.useEffect(()=>{let t=!0;return ve().then(s=>{t&&te(s)}).catch(()=>{}),()=>{t=!1}},[]),i.useEffect(()=>{let t=!0;return ge(r).then(s=>{t&&M(s.bookmarked)}).catch(()=>{}),()=>{t=!1}},[r]),i.useEffect(()=>{let t=!1;const s=Z();return ye(r).then(o=>{var m;if(t||Z()!==s)return;const l=!!(o&&!o.published);I(l),(m=e.onDraftExistsChange)==null||m.call(e,l)}),()=>{t=!0}},[r,e.onDraftExistsChange]),i.useEffect(()=>be((t,s)=>{var o;t===r&&(I(s),(o=e.onDraftExistsChange)==null||o.call(e,s))}),[r,e.onDraftExistsChange]),i.useEffect(()=>{z(e.meta.permission)},[e.meta.permission,r]),i.useEffect(()=>{const t=s=>{U.current&&!U.current.contains(s.target)&&R(!1),F.current&&!F.current.contains(s.target)&&A(!1)};return(v||y)&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[v,y]),i.useEffect(()=>{if(!v&&!y)return;const t=++D.current;V(null);const s=()=>{if(t===D.current)try{const m=Te("html",S.current||"");t===D.current&&V(m)}catch{t===D.current&&V(0)}},o=window;if(typeof o.requestIdleCallback=="function"){const m=o.requestIdleCallback(s);return()=>{var C;return(C=o.cancelIdleCallback)==null?void 0:C.call(o,m)}}const l=window.setTimeout(s,0);return()=>window.clearTimeout(l)},[v,y,h,r,e.contentRevision]);const H=i.useCallback(async()=>{var t;await Ce(r).execute(()=>ke({documentId:r,content:S.current,displayName:W.current,contentKind:"html",localBaseCommitIdAtEditStart:e.meta.headCommitId??null,snapshotMeta:{permission:e.meta.permission,ownerVisitorId:e.meta.ownerVisitorId,domainId:e.meta.domainId}})),I(!0),(t=e.onDraftExistsChange)==null||t.call(e,!0)},[r,e]),J=i.useCallback(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{H()},1e3)},[H]);i.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);async function $(t){var s;if(e.canEdit){G(!0);try{c.current&&(clearTimeout(c.current),c.current=null),await H(),await e.onPublish(S.current,W.current.trim()||x,r,t),I(!1),(s=e.onDraftExistsChange)==null||s.call(e,!1)}finally{G(!1)}}}async function oe(){if(!e.canEdit)return;const t=e.initialDisplayName.trim();if(x.trim()!==t)try{await $()}catch{}}async function _(){var t,s;if(!B){K(!0);try{f?(await De(r),M(!1),(t=e.onShowToast)==null||t.call(e,a("bookmarkRemoved"))):(await Se(r),M(!0),(s=e.onShowToast)==null||s.call(e,a("bookmarkAdded")))}finally{K(!1)}}}function re(t){const s=ee.find(o=>o.visitorId===t);return(s==null?void 0:s.visitorName)??t.slice(0,8)}function le(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}const d=i.useMemo(()=>e.domains.find(t=>t.domainId===e.meta.domainId),[e.domains,e.meta.domainId]),ce=i.useMemo(()=>{const t=(d==null?void 0:d.permission)??"public";return je(t)},[d==null?void 0:d.permission]);function de(t){return t===E.PRIVATE?a("permissionPrivate"):t===E.DOMAIN_READ?a("permissionInvite"):t===E.DOMAIN_WRITE?a("permissionDomainWrite"):t===E.PUBLIC_READ?a("permissionPublicRead"):a("permissionPublicEdit")}async function me(){if(O||T===e.meta.permission){b(!1);return}Q(!0);try{await $(T),b(!1)}finally{Q(!1)}}async function ue(t){const s=new Set(t.map(o=>o.visitorId));for(const[o]of w)s.has(o)||await Ne(r,o);for(const o of t)w.get(o.visitorId)!==o.permission&&await Pe(r,o.visitorId,o.permission);L(!1)}function g(){R(!1),A(!1)}function X(t,s){const o=(s==null?void 0:s.includeBookmark)??!0,l={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreator")}),n.jsx("span",{children:re(e.meta.ownerVisitorId)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCreatedAt")}),n.jsx("span",{children:new Date(e.meta.createdAt).toLocaleString(k==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoSize")}),n.jsx("span",{children:le(new Blob([h]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoCharCount")}),n.jsx("span",{children:Y===null?"…":Y.toLocaleString(k==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:a("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(e.meta.updatedAt).toLocaleString(k==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),o?n.jsxs("button",{type:"button",style:l,onClick:()=>{_(),t()},children:[n.jsx("span",{children:f?"⭐":"☆"}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}):null,e.canManageInvites?n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),(async()=>{const m=await Ee(r);ae(new Map(m.map(C=>[C.visitorId,C.permission]))),L(!0)})()},children:[n.jsx(Ae,{size:14}),n.jsx("span",{children:a("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:l,onClick:()=>{t(),z(e.meta.permission),b(!0)},children:[n.jsx(Be,{size:14}),n.jsx("span",{children:a("docInfoChangePermission")})]})]})}const fe=i.useCallback(t=>{var o;const s=t.target.value;N(s),(o=e.onContentChange)==null||o.call(e,s),J()},[e,J]),he=`<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head><body>${h}</body></html>`;return n.jsxs("div",{className:"mdocs-editor"+(e.readerChrome?" mdocs-editor--reader":""),children:[n.jsx(Me,{fileType:"html",displayName:x,onDisplayNameChange:P,onDisplayNameBlur:()=>void oe(),domains:e.domains,currentDomainId:e.currentDomainId,onDomainChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,canEdit:e.canEdit,editing:se,onAiWrite:e.onAiWrite,syncBehind:e.syncBehind,onSyncClick:e.onSyncClick,busy:q,draftExists:p,onPublish:()=>{$().catch(()=>{})},onDelete:()=>{e.onDelete()},isBookmarked:f,bookmarkBusy:B,onToggleBookmark:()=>void _(),onToggleComments:e.onToggleComments,commentPanelOpen:e.commentPanelOpen,commentCount:e.commentCount,docInfoMenu:X(g),docInfoOpen:v,onToggleDocInfo:()=>R(!v),docInfoMenuRef:U,readerChrome:e.readerChrome,readerActionsCollapsible:!0,readerHeaderDocked:e.readerChrome,onOpenMobileNav:e.onOpenMobileNav,readerMoreOpen:y,onToggleReaderMore:()=>A(t=>!t),readerMoreMenuRef:F,readerMoreMenu:n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:B,onClick:()=>{_(),g()},children:[n.jsx(Ie,{size:16,strokeWidth:1.5,style:{color:f?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:f?"#faad14":"none"}}),n.jsx("span",{children:a(f?"bookmarkRemove":"bookmarkAdd")})]}),n.jsx("div",{className:"mdocs-reader-more-divider"}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:!u,onClick:()=>{j(!1),g()},children:a("edit")}),n.jsx("button",{type:"button",className:"mdocs-reader-more-item",disabled:u,onClick:()=>{j(!0),g()},children:a("preview")}),n.jsx("div",{className:"mdocs-reader-more-divider"}),e.canEdit?n.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:q,onClick:()=>{g(),e.onDelete()},children:n.jsx("span",{children:a("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),X(g,{includeBookmark:!1})]}),leadingExtra:e.canEdit&&!e.readerChrome?n.jsxs("label",{className:"mdocs-editor-mode-toggle","aria-label":a(u?"preview":"edit"),children:[n.jsx("input",{type:"checkbox",checked:u,onChange:()=>j(t=>!t)}),n.jsxs("span",{className:"mdocs-editor-mode-toggle-slider",children:[n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--left",children:a("edit")}),n.jsx("span",{className:"mdocs-editor-mode-toggle-label mdocs-editor-mode-toggle-label--right",children:a("preview")})]})]}):null}),n.jsxs("div",{className:"mdocs-html-editor-body",children:[!u&&e.canEdit?n.jsx("textarea",{className:"mdocs-html-editor-textarea",value:h,onChange:fe,spellCheck:!1,placeholder:"在此处编写 HTML 代码"}):null,n.jsx("div",{className:"mdocs-html-editor-preview",style:!u&&e.canEdit?{width:"50%"}:{width:"100%"},children:n.jsx("iframe",{className:"mdocs-html-editor-iframe",srcDoc:he,sandbox:"",title:x})})]}),ne&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:t=>{t.target===t.currentTarget&&b(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:a("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[a("domainPermission"),":",d?we(d.domainName,k,a):e.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:ce.map(t=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n.jsx("input",{type:"radio",name:"html-doc-permission",value:t,checked:T===t,onChange:()=>z(t)}),n.jsx("span",{children:de(t)})]},t))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>b(!1),children:a("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:O,onClick:()=>void me(),children:a(O?"publishing":"saveAndPublish")})]})]})}),e.canManageInvites&&n.jsx(Re,{open:ie,title:a("docInfoInviteMember"),initialSelectedIds:[...w.keys()],initialPermissions:w,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:a("invitePermissionRead")},{value:"edit",label:a("invitePermissionEdit")}],onClose:()=>L(!1),onConfirm:t=>{ue(t)}})]})}export{_e as HtmlEditor};
@@ -0,0 +1,10 @@
1
+ import{r as g,j as l}from"./react-vendor-BVS1XoFi.js";import{c as p,p as Z,bf as U,bg as ee,bh as J,bi as te}from"./index-Kp5r4mc7.js";import{E as ne,B as se}from"./react-DsdrF7vh.js";import{g as le}from"./file-type-policy-5jFXMeIz.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./editor-DBWWidi3.js";import"./plus-D8tCpRfA.js";import"./copy-C_H9wgwB.js";import"./check-NyVbPIj8.js";function F({lexicalJson:e,onMarkdown:t,onError:o}){const[c,n]=g.useState(null),i=g.useRef(!1);return g.useEffect(()=>{i.current=!1},[e]),g.useEffect(()=>{if(!(!c||i.current))try{c.setDocument("json",e);const a=c.getDocument("markdown");typeof a=="string"&&(i.current=!0,t(a))}catch{o==null||o()}},[c,e,t,o]),l.jsx("div",{className:"mdocs-lexical-md-bridge","aria-hidden":!0,children:l.jsx(ne,{content:e,type:"json",editable:!1,onInit:n,plugins:[se]})})}function oe(e){const{t}=p(),[o,c]=g.useState(0),n=e.segments.filter(s=>s.kind==="conflict"),i=e.unresolvedCount>0;g.useEffect(()=>{if(n.length===0){c(0);return}c(s=>Math.min(s,n.length-1))},[n.length]);function a(s){n.length!==0&&c(m=>{var h;const r=(m+s+n.length)%n.length;return(h=document.getElementById(`mdocs-merge-hunk-${r}`))==null||h.scrollIntoView({block:"center",behavior:"smooth"}),r})}let d=-1;return l.jsxs("div",{className:"mdocs-merge-inline-pane",children:[l.jsxs("div",{className:"mdocs-merge-inline-toolbar",children:[l.jsx("span",{className:"mdocs-merge-inline-hint",children:i?t("mergeReviewHint"):n.length===0?t("mergeNoConflicts"):t("mergeEditAfterResolve")}),n.length>0?l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",onClick:e.onUseAllMine,children:t("mergeUseAllMine")}),l.jsx("button",{type:"button",onClick:e.onUseAllTheirs,children:t("mergeUseAllTheirs")})]}):null]}),i?l.jsxs("div",{className:"mdocs-merge-inline",role:"document",children:[e.segments.map((s,m)=>{if(s.kind==="unchanged")return l.jsx("pre",{className:"mdocs-merge-inline-same",children:s.lines.map((f,x)=>l.jsxs("div",{className:"mdocs-ai-write-line ctx",children:[l.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),l.jsx("span",{className:"mdocs-ai-write-code",children:f||" "})]},x))},`u-${m}`);d+=1;const r=d,h=s.resolution!=="unresolved",u=r===o;return l.jsxs("div",{id:`mdocs-merge-hunk-${r}`,className:"mdocs-merge-inline-hunk"+(u?" is-active":"")+(h?" is-resolved":""),onClick:()=>c(r),children:[h?l.jsx("div",{className:"mdocs-merge-hunk-resolved-tag",children:s.resolution==="remote"?t("mergeReceive"):t("mergeReject")}):l.jsxs("div",{className:"mdocs-merge-hunk-actions",children:[l.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:f=>{f.stopPropagation(),e.onReject(s.id)},children:t("mergeReject")}),l.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:f=>{f.stopPropagation(),e.onReceive(s.id)},children:t("mergeReceive")})]}),l.jsxs("pre",{className:"mdocs-ai-write-hunk-pre",children:[s.localLines.map((f,x)=>l.jsxs("div",{className:"mdocs-ai-write-line del",children:[l.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),l.jsx("span",{className:"mdocs-ai-write-code",children:f||" "})]},`l${x}`)),s.remoteLines.map((f,x)=>l.jsxs("div",{className:"mdocs-ai-write-line add",children:[l.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),l.jsx("span",{className:"mdocs-ai-write-code",children:f||" "})]},`r${x}`))]})]},s.id)}),n.length>0?l.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"冲突导航",children:[l.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>a(-1),children:"↑"}),l.jsxs("span",{children:[o+1," / ",n.length]}),l.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>a(1),children:"↓"}),n[o]&&n[o].resolution==="unresolved"?l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>e.onReject(n[o].id),children:t("mergeReject")}),l.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>e.onReceive(n[o].id),children:t("mergeReceive")})]}):null]}):null]}):l.jsx("textarea",{className:"mdocs-merge-inline-editor",value:e.editableMarkdown,onChange:s=>e.onEditableChange(s.target.value),spellCheck:!1})]})}function q(e){const t=e.trim();if(!t)return{ok:!1,reason:"empty"};try{JSON.parse(t)}catch{return{ok:!1,reason:"invalid"}}const o=Z(t);return{ok:!0,sheetCount:o.sheets.length,tabs:o.sheets.map(c=>{var n;return{name:c.name,rows:c.rows.length,cols:c.columns.length,merges:((n=c.merges)==null?void 0:n.length)??0}})}}function W(e){const{t}=p(),{title:o,side:c,summary:n}=e;return l.jsxs("div",{className:`mdocs-sheet-merge-card mdocs-sheet-merge-card--${c}`,children:[l.jsx("h3",{className:"mdocs-sheet-merge-card-title",children:o}),n.ok?l.jsxs(l.Fragment,{children:[l.jsx("p",{className:"mdocs-sheet-merge-card-meta",children:t("sheetMergeSheetCount",{count:String(n.sheetCount)})}),l.jsx("ul",{className:"mdocs-sheet-merge-tab-list",children:n.tabs.map(i=>l.jsxs("li",{children:[l.jsx("span",{className:"mdocs-sheet-merge-tab-name",children:i.name}),l.jsx("span",{className:"mdocs-sheet-merge-tab-stats",children:t("sheetMergeTabStats",{rows:String(i.rows),cols:String(i.cols),merges:String(i.merges)})})]},`${i.name}-${i.rows}-${i.cols}-${i.merges}`))})]}):l.jsx("p",{className:"mdocs-sheet-merge-card-muted",children:n.reason==="empty"?t("sheetMergePreviewEmpty"):t("sheetMergePreviewInvalid")})]})}function ie(e){const{t}=p(),o=q(e.localContent),c=q(e.remoteContent);return l.jsxs("div",{className:"mdocs-sheet-merge-pane",children:[l.jsx("p",{className:"mdocs-sheet-merge-hint",children:t("sheetMergeHint")}),l.jsxs("div",{className:"mdocs-sheet-merge-cards",children:[l.jsx(W,{title:t("mergeLocal"),side:"local",summary:o}),l.jsx(W,{title:t("mergeRemote"),side:"remote",summary:c})]}),l.jsxs("div",{className:"mdocs-sheet-merge-actions",children:[l.jsx("button",{type:"button",className:"primary mdocs-sheet-merge-btn-mine",disabled:e.busy||!e.localContent.trim(),onClick:e.onUseMine,children:e.busy?t("publishing"):t("sheetMergeUseMine")}),l.jsx("button",{type:"button",className:"secondary mdocs-sheet-merge-btn-theirs",disabled:e.busy||!e.remoteContent.trim(),onClick:e.onUseTheirs,children:e.busy?t("publishing"):t("sheetMergeUseTheirs")})]})]})}function ce(e,t){let o={};for(let i=0;i<t.length;i++){const a=t[i];o[a]?o[a].push(i):o[a]=[i]}let n=[{buffer1index:-1,buffer2index:-1,chain:null}];for(let i=0;i<e.length;i++){const a=e[i],d=o[a]||[];let s=0,m=n[0];for(let r=0;r<d.length;r++){const h=d[r];let u;for(u=s;u<n.length&&!(n[u].buffer2index<h&&(u===n.length-1||n[u+1].buffer2index>h));u++);if(u<n.length){const f={buffer1index:i,buffer2index:h,chain:n[u]};if(s===n.length?n.push(m):n[s]=m,s=u+1,m=f,s===n.length)break}}n[s]=m}return n[n.length-1]}function O(e,t){const o=ce(e,t);let c=[],n=e.length,i=t.length;for(let a=o;a!==null;a=a.chain){const d=n-a.buffer1index-1,s=i-a.buffer2index-1;n=a.buffer1index,i=a.buffer2index,(d||s)&&c.push({buffer1:[n+1,d],buffer1Content:e.slice(n+1,n+1+d),buffer2:[i+1,s],buffer2Content:t.slice(i+1,i+1+s)})}return c.reverse(),c}function ae(e,t,o){let c=[];function n(s,m){c.push({ab:m,oStart:s.buffer1[0],oLength:s.buffer1[1],abStart:s.buffer2[0],abLength:s.buffer2[1]})}O(t,e).forEach(s=>n(s,"a")),O(t,o).forEach(s=>n(s,"b")),c.sort((s,m)=>s.oStart-m.oStart);let i=[],a=0;function d(s){s>a&&(i.push({stable:!0,buffer:"o",bufferStart:a,bufferLength:s-a,bufferContent:t.slice(a,s)}),a=s)}for(;c.length;){let s=c.shift(),m=s.oStart,r=s.oStart+s.oLength,h=[s];for(d(m);c.length;){const u=c[0],f=u.oStart;if(f>r)break;r=Math.max(r,f+u.oLength),h.push(c.shift())}if(h.length===1){if(s.abLength>0){const u=s.ab==="a"?e:o;i.push({stable:!0,buffer:s.ab,bufferStart:s.abStart,bufferLength:s.abLength,bufferContent:u.slice(s.abStart,s.abStart+s.abLength)})}}else{let u={a:[e.length,-1,t.length,-1],b:[o.length,-1,t.length,-1]};for(;h.length;){s=h.shift();const k=s.oStart,M=k+s.oLength,v=s.abStart,w=v+s.abLength;let N=u[s.ab];N[0]=Math.min(v,N[0]),N[1]=Math.max(w,N[1]),N[2]=Math.min(k,N[2]),N[3]=Math.max(M,N[3])}const f=u.a[0]+(m-u.a[2]),x=u.a[1]+(r-u.a[3]),j=u.b[0]+(m-u.b[2]),b=u.b[1]+(r-u.b[3]);let S={stable:!1,aStart:f,aLength:x-f,aContent:e.slice(f,x),oStart:m,oLength:r-m,oContent:t.slice(m,r),bStart:j,bLength:b-j,bContent:o.slice(j,b)};i.push(S)}a=r}return d(t.length),i}function re(e,t,o,c){c=Object.assign({excludeFalseConflicts:!0,stringSeparator:/\s+/},c),typeof e=="string"&&(e=e.split(c.stringSeparator)),typeof t=="string"&&(t=t.split(c.stringSeparator)),typeof o=="string"&&(o=o.split(c.stringSeparator));let i=[];const a=ae(e,t,o);let d=[];function s(){d.length&&i.push({ok:d}),d=[]}function m(r,h){if(r.length!==h.length)return!1;for(let u=0;u<r.length;u++)if(r[u]!==h[u])return!1;return!0}return a.forEach(r=>{r.stable?d.push(...r.bufferContent):c.excludeFalseConflicts&&m(r.aContent,r.bContent)?d.push(...r.aContent):(s(),i.push({conflict:{a:r.aContent,aIndex:r.aStart,o:r.oContent,oIndex:r.oStart,b:r.bContent,bIndex:r.bStart}}))}),s(),i}const de=/^<!--\s*mdocs-merge-conflict:([^\s]+)\s*-->$/;function ue(e){return`<!-- mdocs-merge-conflict:${e} -->`}function me(e){const t=e.trim().match(de);return(t==null?void 0:t[1])??null}function R(e){return e===""?[]:e.split(`
2
+ `)}function V(e,t){return e.length===t.length&&e.every((o,c)=>o===t[c])}function he(e,t,o){const c=R(e),n=R(t),i=R(o);if(n.length===0&&t==="")return ge(e,o);const a=re(c,n,i),d=[];let s=0,m=0,r=0,h=0;const u=(x,j,b,S)=>{d.push({kind:"conflict",id:`conflict-${s}`,conflictKind:S,baseLines:x,localLines:j,remoteLines:b,resolution:"unresolved"}),s+=1},f=(x,j,b)=>{if(j.length===0&&x.length===0&&b.length===0)return;if(V(x,j)&&V(b,j)){j.length>0&&d.push({kind:"unchanged",lines:[...j]});return}if(x.length===j.length&&b.length===j.length){let k=[];const M=()=>{k.length>0&&(d.push({kind:"unchanged",lines:k}),k=[])};for(let v=0;v<j.length;v+=1){const w=j[v],N=x[v],I=b[v];N===w&&I===w?k.push(w):(M(),u([w],[N],[I],N!==w&&I!==w&&N!==I?"true_conflict":"change"))}M();return}const S=x.join(`
3
+ `)!==j.join(`
4
+ `)&&b.join(`
5
+ `)!==j.join(`
6
+ `)&&x.join(`
7
+ `)!==b.join(`
8
+ `)?"true_conflict":"change";u(j,x,b,S)};for(let x=0;x<a.length;x+=1){const j=a[x],b=j.conflict;if(b){f(c.slice(m,b.aIndex),n.slice(r,b.oIndex),i.slice(h,b.bIndex)),u(b.o,b.a,b.b,"true_conflict"),m=b.aIndex+b.a.length,r=b.oIndex+b.o.length,h=b.bIndex+b.b.length;continue}if(j.ok){const S=a[x+1],k=S==null?void 0:S.conflict;k?(f(c.slice(m,k.aIndex),n.slice(r,k.oIndex),i.slice(h,k.bIndex)),m=k.aIndex,r=k.oIndex,h=k.bIndex):(f(c.slice(m),n.slice(r),i.slice(h)),m=c.length,r=n.length,h=i.length)}}return d}function fe(e,t){const o=e.length,c=t.length,n=Array.from({length:o+1},()=>new Array(c+1).fill(0));for(let s=1;s<=o;s+=1)for(let m=1;m<=c;m+=1)e[s-1]===t[m-1]?n[s][m]=n[s-1][m-1]+1:n[s][m]=Math.max(n[s-1][m],n[s][m-1]);const i=[];let a=o,d=c;for(;a>0||d>0;)a>0&&d>0&&e[a-1]===t[d-1]?(i.push({type:"equal",line:e[a-1]}),a-=1,d-=1):d>0&&(a===0||n[a][d-1]>=n[a-1][d])?(i.push({type:"add",line:t[d-1]}),d-=1):(i.push({type:"del",line:e[a-1]}),a-=1);return i.reverse()}function ge(e,t){const o=R(e),c=R(t),n=fe(o,c),i=[];let a=0,d=0;for(;d<n.length;){if(n[d].type==="equal"){const h=[];for(;d<n.length&&n[d].type==="equal";)h.push(n[d].line),d+=1;i.push({kind:"unchanged",lines:h});continue}const m=[],r=[];for(;d<n.length&&n[d].type!=="equal";){const h=n[d];h.type==="del"&&m.push(h.line),h.type==="add"&&r.push(h.line),d+=1}i.push({kind:"conflict",id:`conflict-${a}`,conflictKind:"true_conflict",baseLines:[],localLines:m,remoteLines:r,resolution:"unresolved"}),a+=1}return i}function be(e){return e.filter(t=>t.kind==="conflict").length}function xe(e){return e.filter(t=>t.kind==="conflict"&&t.resolution==="unresolved").length}function je(e){switch(e.resolution){case"local":return e.localLines;case"remote":return e.remoteLines;case"both":return[...e.localLines,...e.remoteLines];case"manual":return e.manualLines??[];default:return[]}}function Ce(e){const t=[];for(const o of e)o.kind==="unchanged"?t.push(...o.lines):o.resolution==="unresolved"?t.push(ue(o.id)):t.push(...je(o));return t.join(`
9
+ `)}function z(e){return R(e).filter(t=>!me(t)).join(`
10
+ `)}function $(e,t,o,c){return e.map(n=>n.kind!=="conflict"||n.id!==t?n:{...n,resolution:o,manualLines:o==="manual"?n.manualLines??[]:void 0})}function Ue(e){var i;const{t}=p(),o=((i=le(e.fileType??"md"))==null?void 0:i.mergePipeline)??"lexical-md-bridge",c=o==="whole-document",n=o==="raw-text";return c?l.jsx(ye,{...e}):l.jsx(Se,{...e,isRawText:n})}function ye(e){const{t}=p(),[o,c]=g.useState(""),[n,i]=g.useState(!0),[a,d]=g.useState(!1),s=e.conflict.localSnapshotContent;g.useEffect(()=>{let h=!1;return i(!0),c(""),(async()=>{try{const u=await U(e.documentId);if(h)return;c(u.content)}catch{h||e.onError(t("mergeLoadRemoteFailed"))}finally{h||i(!1)}})(),()=>{h=!0}},[e.documentId,e.onError,t]);async function m(h){const u=h==="local"?s:o;if(!u.trim()){e.onError(t(h==="local"?"mergeLoadLocalFailed":"mergeLoadRemoteFailed"));return}d(!0);try{await J(e.documentId,{content:u,displayName:e.displayName,version:{localBaseCommitId:e.conflict.localBaseCommitId,merge:{remoteCommitId:e.conflict.remoteCommitId,localSnapshotContent:e.conflict.localSnapshotContent}}});const f=await U(e.documentId);e.onSuccess(f)}catch(f){e.onError(f instanceof Error?f.message:String(f))}finally{d(!1)}}const r=!n;return l.jsxs("div",{className:"mdocs-merge-overlay",children:[l.jsxs("header",{className:"mdocs-merge-toolbar",children:[l.jsxs("div",{className:"mdocs-merge-toolbar-title",children:[l.jsx("h2",{children:t("mergeTitle")}),l.jsx("span",{className:"mdocs-merge-conflict-pill pending",children:t("sheetMergeModeBadge")})]}),l.jsx("div",{className:"mdocs-merge-toolbar-actions",children:l.jsx("button",{type:"button",className:"secondary",disabled:a,onClick:e.onClose,children:t("cancel")})})]}),l.jsx("div",{className:"mdocs-merge-body mdocs-merge-body--sheet-whole",children:r?l.jsx(ie,{localContent:s,remoteContent:o,busy:a,onUseMine:()=>void m("local"),onUseTheirs:()=>void m("remote")}):l.jsx("p",{className:"mdocs-merge-loading",children:t("mergeLoadingRemote")})})]})}function Se(e){const{t}=p(),{isRawText:o}=e,[c,n]=g.useState(""),[i,a]=g.useState(""),[d,s]=g.useState(null),[m,r]=g.useState(!1),[h,u]=g.useState(!1),[f,x]=g.useState(null),[j,b]=g.useState(""),[S,k]=g.useState(null),[M,v]=g.useState(null),[w,N]=g.useState(!1),[I,E]=g.useState(!0);g.useEffect(()=>{let y=!1;return E(!0),x(null),b(""),k(null),v(null),(async()=>{try{const C=await U(e.documentId);if(y)return;o?(b(C.content),E(!1)):x(C.content)}catch{y||e.onError(t("mergeLoadRemoteFailed")),y||E(!1)}})(),()=>{y=!0}},[e.documentId,e.onError,t,o]),g.useEffect(()=>{let y=!1;return s(null),a(""),r(!1),u(!1),(async()=>{try{const C=await ee(e.documentId,e.conflict.localBaseCommitId,e.conflict.remoteCommitId);if(y)return;if(C.mode==="three_way"&&C.mergeBaseContent){o?(a(C.mergeBaseContent),u(!0)):s(C.mergeBaseContent);return}r(!0),u(!0)}catch{if(y)return;r(!0),u(!0)}})(),()=>{y=!0}},[e.documentId,e.conflict.localBaseCommitId,e.conflict.remoteCommitId,o]),g.useEffect(()=>{o&&n(e.conflict.localSnapshotContent)},[o,e.conflict.localSnapshotContent]);const K=g.useCallback(y=>{b(y),E(!1)},[]),G=g.useCallback(y=>{n(y)},[]),Q=g.useCallback(y=>{a(y),u(!0)},[]),X=g.useCallback(()=>{r(!0),a(""),u(!0)},[]);g.useEffect(()=>{!c||!j||I||!h||(k(he(c,i,j)),v(null))},[c,j,i,h,I,e.conflict.remoteCommitId]);const A=g.useMemo(()=>S?z(Ce(S)):"",[S]),B=S?be(S):0,L=S?xe(S):0,D=M??A;g.useEffect(()=>{L===0&&S&&M===null&&v(A)},[L,S,A,M]);function H(y){k(C=>{if(!C)return C;let T=C;for(const _ of C)_.kind==="conflict"&&(T=$(T,_.id,y));return T}),v(null)}async function Y(){if(L>0){e.onError(t("mergeConflictsUnresolved",{count:String(L)}));return}const y=z(D);N(!0);try{const C=o?y:(await te({content:y,from:"markdown",to:"lexical"})).content;await J(e.documentId,{content:C,displayName:e.displayName,version:{localBaseCommitId:e.conflict.localBaseCommitId,merge:{remoteCommitId:e.conflict.remoteCommitId,localSnapshotContent:e.conflict.localSnapshotContent}}});const T=await U(e.documentId);e.onSuccess(T)}catch(C){e.onError(C instanceof Error?C.message:String(C))}finally{N(!1)}}const P=!!(c&&j&&S&&!I&&h);return l.jsxs("div",{className:"mdocs-merge-overlay",children:[o?null:l.jsxs(l.Fragment,{children:[l.jsx(F,{lexicalJson:e.conflict.localSnapshotContent,onMarkdown:G,onError:()=>e.onError(t("mergeLoadLocalFailed"))}),d?l.jsx(F,{lexicalJson:d,onMarkdown:Q,onError:X}):null,f?l.jsx(F,{lexicalJson:f,onMarkdown:K,onError:()=>{E(!1),e.onError(t("mergeLoadRemoteFailed"))}}):null]}),l.jsxs("header",{className:"mdocs-merge-toolbar",children:[l.jsxs("div",{className:"mdocs-merge-toolbar-title",children:[l.jsx("h2",{children:t("mergeTitle")}),P&&B>0?l.jsx("span",{className:`mdocs-merge-conflict-pill ${L>0?"pending":"resolved"}`,children:L>0?t("mergeConflictsPending",{unresolved:String(L),total:String(B)}):t("mergeConflictsResolved",{total:String(B)})}):null,m?l.jsx("span",{className:"mdocs-merge-base-warning",children:t("mergeBaseMissing")}):null]}),l.jsxs("div",{className:"mdocs-merge-toolbar-actions",children:[l.jsx("button",{type:"button",className:"secondary",disabled:w,onClick:e.onClose,children:t("cancel")}),l.jsx("button",{type:"button",className:"primary",disabled:w||!P||L>0,onClick:()=>void Y(),children:t(w?"publishing":"mergeComplete")})]})]}),l.jsx("div",{className:"mdocs-merge-body mdocs-merge-body--inline",children:P?l.jsx(oe,{segments:S,unresolvedCount:L,onReceive:y=>{k(C=>C&&$(C,y,"remote")),v(null)},onReject:y=>{k(C=>C&&$(C,y,"local")),v(null)},onUseAllMine:()=>H("local"),onUseAllTheirs:()=>H("remote"),editableMarkdown:D,onEditableChange:v}):l.jsx("p",{className:"mdocs-merge-loading",children:t("mergeLoadingRemote")})})]})}export{Ue as MergeView};
@@ -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-DHtvOuT-.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-LRioFemr.js";import{N as me}from"./index-92xZ1zjh.js";import"./editor-DBWWidi3.js";import"./diagram-BF8g9yg4.js";import"./plus-Ss1czARp.js";import"./copy-BT35-MU9.js";import"./check-65pb-o1o.js";import"./motion-BAXVQJfN.js";import"./italic-BmGXEOKX.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
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-DsdrF7vh.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-CPIpQgP1.js";import{N as me}from"./index-Kp5r4mc7.js";import"./editor-DBWWidi3.js";import"./diagram-BF8g9yg4.js";import"./plus-D8tCpRfA.js";import"./copy-C_H9wgwB.js";import"./check-NyVbPIj8.js";import"./motion-BAXVQJfN.js";import"./italic-BqrahN0G.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: