Skip to content

Commit be0d5d7

Browse files
authored
☑️ feat: mermaid copy code (#52)
1 parent 0243cc3 commit be0d5d7

File tree

9 files changed

+59
-40
lines changed

9 files changed

+59
-40
lines changed

components.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable */
1+
22
// @ts-nocheck
33
// Generated by unplugin-vue-components
44
// Read more: https://github.com/vuejs/core/pull/3399

eslint.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ export default defineFlatConfig([
388388
}
389389
},
390390

391+
...pluginVue.configs['flat/base'],
392+
...pluginVue.configs['flat/essential'],
393+
...pluginVue.configs['flat/strongly-recommended'],
394+
...pluginVue.configs['flat/recommended'],
391395
{
392396
files: ['**/*.vue'],
393397
languageOptions: {
@@ -408,10 +412,6 @@ export default defineFlatConfig([
408412
},
409413
processor: pluginVue.processors['.vue'],
410414
rules: {
411-
...pluginVue.configs['flat/base'].rules,
412-
...pluginVue.configs['flat/essential'].rules,
413-
...pluginVue.configs['flat/strongly-recommended'].rules,
414-
...pluginVue.configs['flat/recommended'].rules,
415415
'vue/no-v-html': 'off',
416416
'vue/multi-word-component-names': 0,
417417
'vue/singleline-html-element-content-newline': 'off',

src/components/Layout/CenterPanel.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts" setup>
2-
import { systemTitle } from '@/base'
32
</script>
43

54
<template>

src/components/MarkdownPreview/index.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { CrossTransformFunction, TransformFunction } from './models'
55
import { defaultMockModelName } from './models'
66
77
interface Props {
8-
reader: ReadableStreamDefaultReader<Uint8Array> | null | undefined
8+
reader?: ReadableStreamDefaultReader<Uint8Array> | null | undefined
99
model: string | null| undefined
1010
transformStreamFn: TransformFunction | null | undefined
1111
}
@@ -235,24 +235,24 @@ const showText = () => {
235235
cancelAnimationFrame(typingAnimationFrame)
236236
typingAnimationFrame = null
237237
readerLoading.value = false
238-
renderMermaidProcess()
238+
renderMermaidProcess(scrollToBottom)
239239
return
240240
}
241241
242242
// 若 reader 还没结束,则保持打字行为
243243
if (!readIsOver.value) {
244244
runReadBuffer()
245-
renderMermaidProcess()
245+
renderMermaidProcess(scrollToBottom)
246246
typingAnimationFrame = requestAnimationFrame(showText)
247247
} else {
248248
// 读取剩余的 buffer
249249
runReadBuffer(
250250
() => {
251-
renderMermaidProcess()
251+
renderMermaidProcess(scrollToBottom)
252252
typingAnimationFrame = requestAnimationFrame(showText)
253253
},
254254
() => {
255-
renderMermaidProcess()
255+
renderMermaidProcess(scrollToBottom)
256256
257257
window.$ModalNotification.success({
258258
title: '生成完毕',

src/components/MarkdownPreview/plugins/markdown.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ export const renderMarkdownText = (content: string) => {
118118
return md.render(mermaidTransformed)
119119
}
120120

121-
const debounceRenderMermaid = _.debounce(() => {
122-
processMermaid.fn()
121+
const debounceRenderMermaid = _.debounce((callback = () => {}) => {
122+
processMermaid.fn(callback)
123123
}, 10)
124124

125125
// 触发 Mermaid 渲染
126-
export const renderMermaidProcess = () => {
127-
debounceRenderMermaid()
126+
export const renderMermaidProcess = (callback = () => {}) => {
127+
debounceRenderMermaid(callback)
128128
}

src/components/MarkdownPreview/plugins/mermaid.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import mermaid from 'mermaid'
22
import CryptoJs from 'crypto-js'
33

44
export const processMermaid = {
5-
fn: () => {}
5+
fn: (callback) => {}
66
}
77

88
const computeHash = (str) => {
@@ -43,7 +43,10 @@ export const mermaidPlugin = (md, options = {}) => {
4343

4444

4545
if (cache.has(hash)) {
46-
return `<div data-mermaid-hash="${ hash }">${ cache.get(hash) }</div>`
46+
return `
47+
${ defaultFence(tokens, idx, opts, env, self) }
48+
<div data-mermaid-hash="${ hash }">${ cache.get(hash) }</div>
49+
`
4750
}
4851

4952
return `
@@ -59,7 +62,7 @@ export const mermaidPlugin = (md, options = {}) => {
5962
}
6063

6164
// 后处理渲染 mermaid
62-
const renderMermaid = async (container) => {
65+
const renderMermaid = async (container, callback = () => {}) => {
6366
const encodedContent = container.dataset.mermaidContent
6467
const content = decodeURIComponent(encodedContent)
6568
const hash = container.dataset.mermaidHash
@@ -93,6 +96,8 @@ export const mermaidPlugin = (md, options = {}) => {
9396
fragment.appendChild(wrapper)
9497

9598
container.replaceWith(fragment)
99+
100+
callback()
96101
} catch (err) {
97102
console.error('Mermaid 渲染失败:', err)
98103
container.dataset.mermaidStatus = 'error'
@@ -101,7 +106,7 @@ export const mermaidPlugin = (md, options = {}) => {
101106
}
102107

103108
// 全局渲染控制器
104-
const processContainers = () => {
109+
const processContainers = (callback = () => {}) => {
105110
const containers = document.querySelectorAll(`
106111
div[data-mermaid-status="pending"]
107112
`) as NodeListOf<HTMLElement>
@@ -116,7 +121,7 @@ export const mermaidPlugin = (md, options = {}) => {
116121
container.dataset.mermaidStatus = 'pending'
117122
}
118123
nextTick(() => {
119-
renderMermaid(container)
124+
renderMermaid(container, callback)
120125
})
121126
})
122127
}
@@ -131,8 +136,8 @@ export const mermaidPlugin = (md, options = {}) => {
131136
})
132137

133138
// 触发 Mermaid 图表渲染 export
134-
processMermaid.fn = () => {
135-
processContainers()
139+
processMermaid.fn = (callback = () => {}) => {
140+
processContainers(callback)
136141
}
137142
}
138143

src/components/Navigation/NavBar.vue

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,38 @@ const handleToRepo = () => {
3737
<div
3838
class="header-left"
3939
>
40+
<div
41+
flex="~ items-center justify-center"
42+
class="text-20"
43+
select-none
44+
cursor-pointer
45+
@click="handleToRepo()"
46+
>
47+
<div class="size-24 i-streamline-emojis:cloud-1"></div>
48+
<div class="flex-1 pl-10 font-600 text-center">{{ systemTitle }}</div>
49+
</div>
4050
</div>
4151
<div class="flex-1">
4252
<div
4353
flex="~ col items-center justify-center"
4454
px-36px
4555
>
46-
<div
47-
flex="~ items-center justify-center"
48-
class="text-20"
49-
select-none
50-
cursor-pointer
51-
@click="handleToRepo()"
52-
>
53-
<div class="size-24 i-streamline-emojis:cloud-1"></div>
54-
<div class="flex-1 pl-10 font-600 text-center">{{ systemTitle }}</div>
55-
</div>
5656
<slot name="bottom"></slot>
5757
</div>
5858
</div>
5959

6060
<div class="header-right">
61+
<slot name="right"></slot>
6162
</div>
6263
</header>
6364
</template>
6465

6566
<style lang="scss" scoped>
6667
6768
.navigation-nav-header-container {
68-
--at-apply: w-full flex items-center justify-center py-10;
69+
--at-apply: w-full flex items-center justify-center;
70+
--at-apply: px-16 py-10;
71+
--at-apply: lt-lg:flex-col;
6972
7073
.header-left,
7174
.header-right {

src/views/chat.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,18 +252,18 @@ const promptTextList = ref([
252252
flex="~ justify-between items-center"
253253
>
254254
<NavigationNavBar>
255-
<template #bottom>
255+
<template #right>
256256
<div
257257
flex="~ justify-center items-center wrap"
258-
class="pt-10 text-16"
258+
class="text-16 line-height-16"
259259
>
260-
<span>当前模型:</span>
260+
<span class="lt-xs:hidden">当前模型:</span>
261261
<div
262262
flex="~ justify-center items-center"
263263
>
264264
<n-select
265265
v-model:value="businessStore.systemModelName"
266-
class="w-280 pr-10 font-italic font-bold"
266+
class="w-280 lt-xs:w-260 pr-10 font-italic font-bold"
267267
placeholder="请选择模型"
268268
:disabled="stylizingLoading"
269269
:options="modelListSelections"
@@ -283,7 +283,11 @@ const promptTextList = ref([
283283
>本仓库</a>到本地运行
284284
</div>
285285
<template #trigger>
286-
<span class="cursor-help font-bold c-primary text-17 i-radix-icons:question-mark-circled"></span>
286+
<span
287+
class="cursor-help font-bold c-primary text-17 i-ic:sharp-help"
288+
ml-10
289+
mr-24
290+
></span>
287291
</template>
288292
</CustomTooltip>
289293
</div>

uno.config.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
defineConfig,
33
presetAttributify,
44
presetIcons,
5-
presetUno,
5+
presetWind3,
66
toEscapedSelector,
77
transformerDirectives
88
} from 'unocss'
@@ -12,7 +12,7 @@ import presetRemToPx from '@unocss/preset-rem-to-px'
1212

1313
export default defineConfig({
1414
presets: [
15-
presetUno(),
15+
presetWind3(),
1616
presetAttributify(),
1717
presetIcons(),
1818
presetRemToPx({
@@ -23,6 +23,14 @@ export default defineConfig({
2323
transformerDirectives()
2424
],
2525
theme: {
26+
breakpoints: {
27+
'xs': '475px',
28+
'sm': '640px',
29+
'md': '1024px',
30+
'lg': '1200px',
31+
'xl': '1440px',
32+
'2xl': '1920px'
33+
},
2634
colors: {
2735
primary: '#692ee6',
2836
success: '#52c41a',

0 commit comments

Comments
 (0)