Skip to content

Commit 950d1ce

Browse files
committed
feat: 🎸 SelectionDecoration
1 parent db8159e commit 950d1ce

File tree

13 files changed

+578
-84
lines changed

13 files changed

+578
-84
lines changed

.vitepress/config/theme/sidebar.ts

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export function sidebarApi(locale :string) {
9191
{ text: 'Color Highlighter', link: extension('color-highlighter') },
9292
{ text: 'Image', link: extension('image') },
9393
{ text: 'Placeholder', link: extension('placeholder') },
94+
{ text: 'Selection Decoration', link: extension('selection-decoration') },
9495
{ text: 'Table', link: extension('table') },
9596
{ text: 'Trailing Node', link: extension('trailing-node') },
9697
{ text: 'Unique ID', link: extension('unique-id') },

.vitepress/data/demo/article.ts

+7-4
Large diffs are not rendered by default.

.vitepress/theme/components/YiitapDemo.vue

+114-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,54 @@
55
:editor="yiiEditor?.editor"
66
:menu="options.mainMenu"
77
:data-theme="isDark ? 'dark' : ''"
8-
/>
8+
>
9+
<template #left>
10+
<o-divider vertical />
11+
<o-popover
12+
ref="popover"
13+
tippy-class="o-ai-settings-popover"
14+
class="o-simple-command-btn"
15+
placement="bottom"
16+
trigger="click"
17+
arrow
18+
>
19+
<template #trigger>
20+
<o-command-btn
21+
icon="settings"
22+
tooltip="Settings"
23+
>
24+
</o-command-btn>
25+
</template>
26+
27+
<div>
28+
<o-btn-group>
29+
<div data-tippy-role="tooltip">
30+
<o-btn label="OpenAI"
31+
:class="{ 'active': aiOption.provider === 'openai' }"
32+
@click="aiOption.provider = 'openai'" />
33+
</div>
34+
<div data-tippy-role="tooltip">
35+
<o-btn label="DeepSeek"
36+
:class="{ 'active': aiOption.provider === 'deepseek' }"
37+
@click="aiOption.provider = 'deepseek'" />
38+
</div>
39+
</o-btn-group>
40+
</div>
41+
42+
<div>
43+
<o-input ref="input"
44+
v-model="aiOption.apiKey"
45+
type="text"
46+
placeholder="API Key"
47+
autofocus clearable>
48+
<template #prefix>
49+
<o-icon name="search" class="o-tips" />
50+
</template>
51+
</o-input>
52+
</div>
53+
</o-popover>
54+
</template>
55+
</o-main-menu>
956
</header>
1057

1158
<section class="layout-content">
@@ -23,9 +70,20 @@
2370
</template>
2471

2572
<script setup lang="ts">
26-
import { computed, ref, provide, onMounted, onUnmounted } from 'vue';
73+
import { computed, ref, provide, watch, onMounted, onUnmounted } from 'vue';
2774
import { useData } from 'vitepress';
28-
import { YiiEditor, ODocToc, OMainMenu } from '@yiitap/vue';
75+
import {
76+
YiiEditor,
77+
ODocToc,
78+
OMainMenu,
79+
OCommandBtn,
80+
ODivider,
81+
OIcon,
82+
OInput,
83+
OBtn,
84+
OBtnGroup,
85+
OPopover
86+
} from '@yiitap/vue';
2987
import '@yiitap/vue/dist/vue.css';
3088
import { BasicFeaturesArticle, BasicFeaturesArticleZh } from '../../data/demo/article';
3189
@@ -41,10 +99,14 @@ const { isDark } = useData();
4199
const localeAlt = ref('en')
42100
const yiiEditor = ref<InstanceType<typeof YiiEditor>>()
43101
const tocRef = ref<InstanceType<typeof ODocToc>>()
102+
const aiOption = ref<AiOption>({
103+
provider: 'deepseek',
104+
})
44105
provide('locale', localeAlt)
45106
46107
const options = computed(() => {
47108
return {
109+
aiOption: aiOption.value,
48110
// locale: locale.value,
49111
darkMode: isDark.value,
50112
// editable: editable.value,
@@ -79,8 +141,10 @@ const options = computed(() => {
79141
'table',
80142
'callout',
81143
'emoji',
144+
'aiBlock',
82145
],
83146
extensions: [
147+
'OAiBlock',
84148
'OBlockquote',
85149
'OCallout',
86150
'OCodeBlock',
@@ -98,12 +162,39 @@ const options = computed(() => {
98162
}
99163
})
100164
165+
const aiOptions = computed(() => {
166+
return [
167+
{ label: 'OpenAI', value: 'openai' },
168+
{ label: 'DeepSeek', value: 'deepseek' },
169+
]
170+
})
171+
172+
function init() {
173+
localeAlt.value = props.locale
174+
try {
175+
const aiOptionString = localStorage.getItem('yiitap.ai.option')
176+
if (aiOptionString) {
177+
aiOption.value = JSON.parse(aiOptionString)
178+
}
179+
} catch (e) {
180+
// ignore
181+
}
182+
}
183+
101184
const onScroll = (event: Event) => {
102185
tocRef.value?.onScroll(event);
103-
};
186+
}
187+
188+
watch(
189+
aiOption,
190+
(newValue) => {
191+
localStorage.setItem('yiitap.ai.option', JSON.stringify(aiOption.value))
192+
},
193+
{ deep: true }
194+
)
104195
105196
onMounted(() => {
106-
localeAlt.value = props.locale
197+
init()
107198
window.addEventListener("scroll", onScroll);
108199
});
109200
@@ -132,8 +223,25 @@ onUnmounted(() => {
132223
133224
.layout-toc {
134225
position: fixed;
135-
top: 64px ;
226+
top: 120px ;
136227
right: 10px;
137228
z-index: 101;
138229
}
230+
231+
.o-input {
232+
width: 400px;
233+
}
234+
235+
.o-btn-group {
236+
margin-bottom: 10px;
237+
238+
.o-btn.active {
239+
color: white;
240+
background: var(--vp-button-brand-bg);
241+
242+
&:hover {
243+
background: var(--vp-button-brand-hover-bg)!important;
244+
}
245+
}
246+
}
139247
</style>

.vitepress/theme/style/main.css

+13
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,17 @@
1010
display: unset;
1111
width: 100%;
1212
}
13+
}
14+
15+
.global-toast-container {
16+
position: fixed;
17+
top: 0;
18+
left: 0;
19+
right: 0;
20+
}
21+
22+
.o-ai-settings-popover {
23+
.popover-content {
24+
min-width: 480px;
25+
}
1326
}

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "yiitap-docs",
3-
"version": "1.0.0",
3+
"version": "1.3.1",
44
"description": "Documentation for Yiitap",
55
"keywords": [
66
"vitepress",
@@ -18,7 +18,10 @@
1818
"url": "https://github.com/yiitap/docs/issues"
1919
},
2020
"dependencies": {
21-
"@yiitap/vue": "^1.2.4",
21+
"@yiitap/vue": "^1.3.1",
22+
"@yiitap/util-emoji": "^1.3.1",
23+
"markdown-it": "^14.1.0",
24+
"openai": "^4.88.0",
2225
"vue": "^3.5.13"
2326
},
2427
"devDependencies": {

0 commit comments

Comments
 (0)