Skip to content

Commit c312920

Browse files
committed
feat: 增加AI模块
1 parent 1c51d8d commit c312920

11 files changed

Lines changed: 390 additions & 0 deletions

File tree

packages/docs/fluent-editor/.vitepress/sidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function sidebar() {
2525
{ text: '工具栏提示', link: '/docs/demo/toolbar-tip' },
2626
{ text: '只读模式', link: '/docs/demo/readonly' },
2727
{ text: '模拟语雀文档', link: 'https://opentiny.github.io/tiny-editor/projects' },
28+
{ text: 'AI', link: '/docs/demo/ai' },
2829
],
2930
},
3031
{
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<script setup lang="ts">
2+
import type FluentEditor from '@opentiny/fluent-editor'
3+
import { onMounted } from 'vue'
4+
5+
const TOOLBAR_CONFIG = [
6+
['ai', { header: [] }],
7+
['bold', 'italic', 'underline', 'link'],
8+
[{ list: 'ordered' }, { list: 'bullet' }],
9+
['clean'],
10+
]
11+
12+
onMounted(() => {
13+
// ssr compat, reference: https://vitepress.dev/guide/ssr-compat#importing-in-mounted-hook
14+
import('@opentiny/fluent-editor').then((module) => {
15+
const FluentEditor = module.default
16+
17+
editor = new FluentEditor('#editor-add-toolbar-item', {
18+
theme: 'snow',
19+
modules: {
20+
toolbar: {
21+
container: TOOLBAR_CONFIG,
22+
},
23+
ai: {
24+
host: 'http://localhost:11434',
25+
model: 'deepseek-r1:8b',
26+
apiKey: '',
27+
},
28+
},
29+
})
30+
})
31+
})
32+
</script>
33+
34+
<template>
35+
<div id="editor-add-toolbar-item">
36+
<h3>标题:</h3>
37+
<p>内容:</p>
38+
<p>署名:</p>
39+
</div>
40+
</template>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# AI
2+
3+
通过工具栏配置AI。
4+
5+
:::demo src=demos/ai.vue
6+
:::

packages/fluent-editor/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
},
3434
"dependencies": {
3535
"lodash-es": "^4.17.15",
36+
"ollama": "0.5.14",
3637
"quill": "^2.0.0",
3738
"quill-easy-color": "^0.0.9",
3839
"quill-shortcut-key": "^0.0.5"
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
.ql-ai-dialog {
2+
position: absolute;
3+
left: 15px;
4+
}
5+
6+
.ql-ai-wrapper {
7+
position: relative;
8+
width: 100%;
9+
z-index: 1000;
10+
}
11+
12+
.ql-ai-tip {
13+
flex-shrink: 0;
14+
}
15+
16+
.ql-ai-input {
17+
display: flex;
18+
align-items: center;
19+
padding: 10px;
20+
background: white;
21+
border: 1px solid #c2c2c2;
22+
border-radius: 4px;
23+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16);
24+
}
25+
26+
.ql-ai-icon {
27+
width: 18px;
28+
height: 18px;
29+
margin-right: 8px;
30+
display: flex;
31+
align-items: center;
32+
justify-content: center;
33+
}
34+
35+
.ql-ai-icon svg {
36+
width: 100%;
37+
height: 100%;
38+
fill: currentColor;
39+
}
40+
41+
.ql-ai-input input {
42+
flex: 1;
43+
padding: 8px;
44+
border: none !important;
45+
outline: none !important;
46+
box-shadow: none !important;
47+
}
48+
49+
.ql-ai-result {
50+
position: absolute;
51+
bottom: calc(100% + 10px);
52+
left: 0;
53+
right: 0;
54+
padding: 10px;
55+
background: white;
56+
border: 1px solid #c2c2c2;
57+
border-radius: 4px;
58+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16);
59+
max-height: 200px;
60+
overflow-y: auto;
61+
}
62+
63+
.ql-ai-dropdown-button {
64+
padding: 4px 8px;
65+
background: #f0f0f0;
66+
border: 1px solid #ddd;
67+
cursor: pointer;
68+
}
69+
70+
.ql-ai-actions {
71+
position: absolute;
72+
top: calc(100% + 10px);
73+
left: 0;
74+
background: white;
75+
border: 1px solid #c2c2c2;
76+
border-radius: 4px;
77+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16);
78+
z-index: 1001;
79+
min-width: 100px;
80+
}
81+
82+
.ql-ai-action-item {
83+
padding: 8px 12px;
84+
cursor: pointer;
85+
&:hover {
86+
background: #f5f5f5;
87+
}
88+
}
89+
90+
.ql-ai-send {
91+
margin-left: 8px;
92+
padding: 2px 8px;
93+
background: #1890ff;
94+
color: white;
95+
border: none;
96+
border-radius: 8px;
97+
cursor: pointer;
98+
&:hover {
99+
background: #40a9ff;
100+
}
101+
}

packages/fluent-editor/src/assets/style.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
@import './fullscreen';
2626
@import './screenshot';
2727
@import './mathlive';
28+
@import './ai.scss';
2829

2930
// 模块:字数统计 counter
3031
@include counter;

packages/fluent-editor/src/fluent-editor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { EN_US } from './config/i18n/en-us'
33
import { ZH_CN } from './config/i18n/zh-cn'
44
import FluentEditor from './core/fluent-editor'
55
import { SoftBreak, StrikeBlot, Video } from './formats'
6+
import { AI } from './modules/ai' // AI
67
import Counter from './modules/counter' // 字符统计
78
import { CustomClipboard } from './modules/custom-clipboard' // 粘贴板
89
import { BlotFormatter } from './modules/custom-image' // 图片
@@ -53,6 +54,7 @@ FluentEditor.register(
5354
'modules/i18n': I18N,
5455
'modules/image': BlotFormatter,
5556
'modules/mathlive': MathliveModule,
57+
'modules/ai': AI,
5658
'modules/mention': Mention,
5759
'modules/syntax': Syntax,
5860
'modules/toolbar': BetterToolbar,

0 commit comments

Comments
 (0)