From 9c72a9e273bb4aac38715f6bbaac82a9680a5e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=82=A6?= Date: Tue, 28 Oct 2025 14:03:10 +0800 Subject: [PATCH] =?UTF-8?q?=20-=20=E5=9C=A8=20js/core/app-shell.js:72-89?= =?UTF-8?q?=20=E5=8A=A8=E6=80=81=E5=88=9B=E5=BB=BA=E2=80=9C=E5=9C=A8Mermai?= =?UTF-8?q?d=E4=B8=AD=E7=BC=96=E8=BE=91=E2=80=9D=E6=8C=89=E9=92=AE?= =?UTF-8?q?=EF=BC=8C=E6=8C=82=E8=BD=BD=E5=88=B0=E5=B7=A5=E5=85=B7=E6=A0=8F?= =?UTF-8?q?=E6=9C=AB=E5=B0=BE=E5=B9=B6=E9=BB=98=E8=AE=A4=E9=9A=90=E8=97=8F?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E5=9C=A8=E9=9D=9E=20=20=20=20=20Mer?= =?UTF-8?q?maid=20=E6=A8=A1=E5=9D=97=E5=8D=A0=E4=BD=8D=E3=80=82=20=20=20-?= =?UTF-8?q?=20=E5=9C=A8=20js/core/app-shell.js:201-204=20=E4=B8=BA?= =?UTF-8?q?=E6=96=B0=E6=8C=89=E9=92=AE=E7=BB=91=E5=AE=9A=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=EF=BC=8C=E8=A7=A6=E5=8F=91=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=85=A5=E5=8F=A3=E3=80=82=20=20=20-=20?= =?UTF-8?q?=E5=9C=A8=20js/core/app-shell.js:2232-2235=20=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E6=A8=A1=E5=9D=97=E4=B8=8E=E5=9B=BE=E5=BD=A2?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=8E=A7=E5=88=B6=E6=8C=89=E9=92=AE=E6=98=BE?= =?UTF-8?q?=E9=9A=90=E4=B8=8E=E5=8F=AF=E7=94=A8=E6=80=A7=EF=BC=8C=E4=BB=85?= =?UTF-8?q?=E5=9C=A8=20Mermaid=20=E4=B8=94=E5=B7=B2=E6=9C=89=E5=9B=BE=20?= =?UTF-8?q?=20=20=20=20=E5=BD=A2=E6=97=B6=E5=90=AF=E7=94=A8=E3=80=82=20=20?= =?UTF-8?q?=20-=20=E5=9C=A8=20js/core/app-shell.js:1560-1592=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20openMermaidLiveEditor=EF=BC=8C=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E7=8E=B0=E6=9C=89=20Pako=20=E7=BC=96=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=20https://=20=20=20=20=20mermaid.live/edit#pako:...?= =?UTF-8?q?=20=E9=93=BE=E6=8E=A5=E5=B9=B6=E9=80=9A=E8=BF=87=20window.open?= =?UTF-8?q?=20=E6=89=93=E5=BC=80=EF=BC=8C=E9=99=84=E5=B8=A6=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E4=B8=8E=E5=BC=B9=E7=AA=97=E6=8B=A6=E6=88=AA=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/core/app-shell.js | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/js/core/app-shell.js b/js/core/app-shell.js index 2091fc6..bf431ea 100644 --- a/js/core/app-shell.js +++ b/js/core/app-shell.js @@ -70,6 +70,24 @@ this.el.copyImageBtn = document.getElementById('copy-image-btn'); this.el.exportImageBtn = document.getElementById('export-image-btn'); this.el.viewCodeBtn = document.getElementById('view-code-btn'); + const toolbarContainer = this.el.viewCodeBtn?.parentElement; + if (toolbarContainer) { + let editBtn = toolbarContainer.querySelector('#edit-mermaid-btn'); + if (!editBtn) { + editBtn = document.createElement('button'); + editBtn.id = 'edit-mermaid-btn'; + editBtn.type = 'button'; + editBtn.className = + 'p-2 bg-purple-500 text-white border-2 border-black hover:bg-purple-600 transition-all flex items-center gap-1 hidden'; + editBtn.title = '在 Mermaid Live 中编辑当前图表'; + editBtn.innerHTML = + '在Mermaid中编辑'; + toolbarContainer.appendChild(editBtn); + } + this.el.editMermaidBtn = editBtn; + } else { + this.el.editMermaidBtn = null; + } // 配置模态框 this.el.settingsBtn = document.getElementById('settings-btn'); @@ -180,6 +198,11 @@ this.viewArtifactCode() ); } + if (this.el.editMermaidBtn) { + this.el.editMermaidBtn.addEventListener('click', () => + this.openMermaidLiveEditor() + ); + } if (this.el.settingsBtn) { this.el.settingsBtn.addEventListener('click', () => @@ -1534,6 +1557,41 @@ return `https://mermaid.ink/img/pako:${encoded}?${params.toString()}`; } + openMermaidLiveEditor() { + const manifest = this.getActiveManifest(); + if (!manifest || manifest.artifact?.type !== 'mermaid') { + console.warn('当前模块不支持 Mermaid 在线编辑'); + return; + } + const state = this.runtime.getState(manifest.id) || {}; + const artifactId = state.currentArtifactId; + if (!artifactId || !state.artifacts?.[artifactId]) { + alert('暂无可编辑的 Mermaid 图表,请先生成图表。'); + return; + } + const artifact = state.artifacts[artifactId]; + const code = this.getMermaidCode(artifact).trim(); + if (!code) { + alert('当前图表缺少 Mermaid 代码,无法打开在线编辑器。'); + return; + } + let encoded; + try { + encoded = this.encodeMermaidState(code); + } catch (error) { + console.error('构建 Mermaid 在线编辑链接失败:', error); + alert(error.message || '构建 Mermaid 编辑链接失败'); + return; + } + const url = `https://mermaid.live/edit#pako:${encoded}`; + const editorWindow = window.open(url, '_blank', 'noopener'); + if (!editorWindow) { + //alert('请允许浏览器弹出窗口以打开 Mermaid 编辑器。'); + return; + } + editorWindow.opener = null; + } + getMermaidExportScale() { return Math.max(6, this.imageExportScale); } @@ -2171,6 +2229,11 @@ this.el.viewCodeBtn.disabled = !hasArtifact || !manifest.exports?.allowCode; } + if (this.el.editMermaidBtn) { + const isMermaidManifest = manifest.artifact?.type === 'mermaid'; + this.el.editMermaidBtn.classList.toggle('hidden', !isMermaidManifest); + this.el.editMermaidBtn.disabled = !hasArtifact || !isMermaidManifest; + } } clearCurrentConversation() {