Skip to content

Commit df74d3e

Browse files
authored
feat: add option to pin Floating TOC (#1122)
1 parent 8d580da commit df74d3e

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

apps/web/src/components/editor/FloatingToc.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<script setup lang='ts'>
22
import { List } from 'lucide-vue-next'
33
import { useRenderStore } from '@/stores/render'
4+
import { useUIStore } from '@/stores/ui'
45
56
const renderStore = useRenderStore()
7+
const uiStore = useUIStore()
8+
const { isPinFloatingToc } = storeToRefs(uiStore)
69
710
const isOpenHeadingSlider = ref(false)
811
</script>
@@ -17,8 +20,8 @@ const isOpenHeadingSlider = ref(false)
1720
<ul
1821
class="overflow-auto transition-all"
1922
:class="{
20-
'max-h-0 w-0': !isOpenHeadingSlider,
21-
'max-h-100 w-60 mt-2': isOpenHeadingSlider,
23+
'max-h-0 w-0': !isOpenHeadingSlider && !isPinFloatingToc,
24+
'max-h-100 w-60 mt-2': isOpenHeadingSlider || isPinFloatingToc,
2225
}"
2326
>
2427
<li

apps/web/src/components/editor/ThemeCustomizer.vue

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,27 @@ function customStyle() {
100100
</Button>
101101
</div>
102102
</div>
103+
<div class="space-y-2">
104+
<h2 class="text-sm font-medium">
105+
浮动目录
106+
</h2>
107+
<div class="grid grid-cols-2 justify-items-center gap-2">
108+
<Button
109+
class="w-full" variant="outline" :class="{
110+
'border-black dark:border-white border-2': uiStore.isPinFloatingToc,
111+
}" @click="!uiStore.isPinFloatingToc && uiStore.togglePinFloatingToc()"
112+
>
113+
常驻显示
114+
</Button>
115+
<Button
116+
class="w-full" variant="outline" :class="{
117+
'border-black dark:border-white border-2': !uiStore.isPinFloatingToc,
118+
}" @click="uiStore.isPinFloatingToc && uiStore.togglePinFloatingToc()"
119+
>
120+
移入触发
121+
</Button>
122+
</div>
123+
</div>
103124
<div class="space-y-2">
104125
<h2 class="text-sm font-medium">
105126
模式

apps/web/src/stores/ui.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export const useUIStore = defineStore(`ui`, () => {
3030
// 是否为移动端
3131
const isMobile = store.reactive(`isMobile`, false)
3232

33+
// 是否固定显示浮动目录
34+
const isPinFloatingToc = store.reactive(addPrefix(`isPinFloatingToc`), false)
35+
const togglePinFloatingToc = useToggle(isPinFloatingToc)
36+
3337
// ==================== 对话框状态 ====================
3438
// 是否展示 CSS 编辑器
3539
const isShowCssEditor = store.reactive(`isShowCssEditor`, false)
@@ -86,6 +90,7 @@ export const useUIStore = defineStore(`ui`, () => {
8690
isOpenRightSlider,
8791
isOpenPostSlider,
8892
isMobile,
93+
isPinFloatingToc,
8994

9095
// ==================== 对话框状态 ====================
9196
isShowCssEditor,
@@ -106,5 +111,6 @@ export const useUIStore = defineStore(`ui`, () => {
106111
toggleDark,
107112
toggleEditOnLeft,
108113
toggleAIToolbox,
114+
togglePinFloatingToc,
109115
}
110116
})

0 commit comments

Comments
 (0)