@tnotesjs/core 0.1.21 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -87
- package/dist/{chunk-4MO7F7Q4.js → chunk-BSTQOJVE.js} +1 -1
- package/dist/{chunk-SQVHJR2Z.js → chunk-O4DCXHOV.js} +0 -3
- package/dist/cli/index.js +2 -2
- package/dist/index.js +1 -1
- package/dist/vitepress/config/index.js +2 -2
- package/package.json +3 -4
- package/types/config.ts +60 -61
- package/types/index.ts +11 -11
- package/types/note.ts +33 -33
- package/vitepress/assets/icons/icon__check.svg +3 -3
- package/vitepress/assets/icons/icon__clipboard.svg +7 -7
- package/vitepress/assets/icons/icon__close.svg +1 -1
- package/vitepress/assets/icons/icon__collapse.svg +1 -1
- package/vitepress/assets/icons/icon__confirm.svg +1 -1
- package/vitepress/assets/icons/icon__copy.svg +4 -4
- package/vitepress/assets/icons/icon__focus.svg +1 -1
- package/vitepress/assets/icons/icon__fold.svg +3 -3
- package/vitepress/assets/icons/icon__folder.svg +1 -1
- package/vitepress/assets/icons/icon__fullscreen.svg +1 -1
- package/vitepress/assets/icons/icon__fullscreen_exit.svg +1 -1
- package/vitepress/assets/icons/icon__github.svg +3 -3
- package/vitepress/assets/icons/icon__mindmap.svg +1 -1
- package/vitepress/assets/icons/icon__next.svg +1 -1
- package/vitepress/assets/icons/icon__number_gray.svg +1 -1
- package/vitepress/assets/icons/icon__number_purple.svg +1 -1
- package/vitepress/assets/icons/icon__prev.svg +1 -1
- package/vitepress/assets/icons/icon__restore.svg +1 -1
- package/vitepress/assets/icons/icon__rotate.svg +4 -4
- package/vitepress/assets/icons/icon__search.svg +1 -1
- package/vitepress/assets/icons/icon__sidebar_collapsed.svg +1 -1
- package/vitepress/assets/icons/icon__sidebar_opened.svg +1 -1
- package/vitepress/assets/icons/icon__totop.svg +5 -5
- package/vitepress/assets/icons/icon__vscode.svg +5 -5
- package/vitepress/assets/icons/icon__zoom_fit.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_in.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_out.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_reset.svg +1 -1
- package/vitepress/assets/icons/index.ts +39 -39
- package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -20
- package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +369 -369
- package/vitepress/components/CodeBlockFullscreen/index.ts +209 -213
- package/vitepress/components/CodeBlockFullscreen/styles.css +126 -126
- package/vitepress/components/Discussions/Discussions.vue +244 -211
- package/vitepress/components/EnWordList/EnWordList.vue +663 -543
- package/vitepress/components/EnWordList/RightClickMenu.vue +89 -66
- package/vitepress/components/Footprints/Footprints.vue +472 -377
- package/vitepress/components/Layout/AboutModal.vue +331 -105
- package/vitepress/components/Layout/AboutPanel.vue +484 -270
- package/vitepress/components/Layout/ContentCollapse.vue +590 -603
- package/vitepress/components/Layout/CustomSidebar.vue +817 -817
- package/vitepress/components/Layout/DocBeforeControls.vue +351 -149
- package/vitepress/components/Layout/DocFooter.vue +233 -233
- package/vitepress/components/Layout/ImagePreview.vue +484 -281
- package/vitepress/components/Layout/Layout.vue +744 -621
- package/vitepress/components/Layout/NavBarSettingsTrigger.vue +0 -2
- package/vitepress/components/Layout/NoteStatus.vue +140 -140
- package/vitepress/components/Layout/SidebarItems.vue +1083 -1083
- package/vitepress/components/Layout/SidebarNavBefore.vue +170 -171
- package/vitepress/components/Layout/SidebarResizeHandle.vue +311 -319
- package/vitepress/components/Layout/Swiper.vue +167 -167
- package/vitepress/components/Layout/ToggleFullContent.vue +47 -35
- package/vitepress/components/Layout/ToggleSidebar.vue +37 -26
- package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -88
- package/vitepress/components/Layout/composables/useNoteConfig.ts +119 -119
- package/vitepress/components/Layout/composables/useNoteSave.ts +178 -178
- package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -85
- package/vitepress/components/Layout/composables/useRedirect.ts +113 -113
- package/vitepress/components/Layout/composables/useSidebarLayout.ts +122 -122
- package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +85 -85
- package/vitepress/components/Layout/homeReadme.data.ts +124 -124
- package/vitepress/components/LoadingPage/LoadingPage.vue +1 -6
- package/vitepress/components/MarkMap/MarkMap.vue +564 -405
- package/vitepress/components/Mermaid/Mermaid.vue +643 -365
- package/vitepress/components/NotesTable/NotesTable.vue +174 -98
- package/vitepress/components/NotesTable/README.md +67 -67
- package/vitepress/components/Settings/Settings.vue +711 -334
- package/vitepress/components/Settings/SettingsDialog.vue +1 -11
- package/vitepress/components/SidebarCard/MindMapView.vue +484 -484
- package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -108
- package/vitepress/components/SidebarCard/SidebarCard.vue +945 -946
- package/vitepress/components/Tooltip/Tooltip.vue +70 -70
- package/vitepress/components/constants.ts +109 -109
- package/vitepress/components/notesConfig.data.ts +73 -73
- package/vitepress/components/sidebar.data.ts +59 -59
- package/vitepress/components/tnotes-config.data.ts +21 -21
- package/vitepress/components/utils.ts +26 -26
- package/vitepress/config/index.ts +169 -169
- package/vitepress/configs/constants.ts +26 -26
- package/vitepress/configs/head.config.ts +25 -25
- package/vitepress/configs/index.ts +9 -9
- package/vitepress/configs/markdown-it.d.ts +23 -23
- package/vitepress/configs/markdown.config.ts +368 -367
- package/vitepress/configs/theme.config.ts +108 -108
- package/vitepress/plugins/buildProgressPlugin.ts +434 -434
- package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -107
- package/vitepress/plugins/renameNotePlugin.ts +68 -68
- package/vitepress/plugins/sidebarStructurePlugin.ts +260 -260
- package/vitepress/plugins/updateConfigPlugin.ts +63 -63
- package/vitepress/theme/index.ts +137 -137
- package/vitepress/theme/styles/base.scss +66 -64
- package/vitepress/theme/styles/components/404.scss +31 -31
- package/vitepress/theme/styles/components/collapse.scss +172 -172
- package/vitepress/theme/styles/components/markmap.scss +101 -101
- package/vitepress/theme/styles/components/swiper.scss +255 -255
- package/vitepress/theme/styles/index.scss +25 -25
- package/vitepress/theme/styles/layout.scss +78 -78
- package/vitepress/theme/styles/utilities.scss +39 -39
- package/vitepress/theme/styles/vitepress-override.scss +25 -25
- package/vitepress/components/Discussions/Discussions.module.scss +0 -32
- package/vitepress/components/EnWordList/EnWordList.module.scss +0 -124
- package/vitepress/components/EnWordList/RightClickMenu.module.scss +0 -22
- package/vitepress/components/Footprints/Footprints.module.scss +0 -93
- package/vitepress/components/Layout/AboutModal.module.scss +0 -233
- package/vitepress/components/Layout/ImagePreview.module.scss +0 -201
- package/vitepress/components/Layout/Layout.module.scss +0 -661
- package/vitepress/components/Layout/ToggleFullContent.module.scss +0 -11
- package/vitepress/components/Layout/ToggleSidebar.module.scss +0 -11
- package/vitepress/components/MarkMap/MarkMap.module.scss +0 -159
- package/vitepress/components/Mermaid/Mermaid.module.scss +0 -275
- package/vitepress/components/NotesTable/NotesTable.module.scss +0 -77
- package/vitepress/components/Settings/Settings.module.scss +0 -375
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
import { ref, computed, watch } from 'vue'
|
|
2
|
-
|
|
3
|
-
import type { NoteConfig } from '../../../../types'
|
|
4
|
-
import type { Ref } from 'vue'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 管理笔记配置状态
|
|
8
|
-
* 包括可编辑字段、原始值、变更检测等
|
|
9
|
-
*/
|
|
10
|
-
export function useNoteConfig(
|
|
11
|
-
currentNoteId: Ref<string>,
|
|
12
|
-
currentNoteConfig: Ref<NoteConfig | null>,
|
|
13
|
-
currentNoteTitle: Ref<string>,
|
|
14
|
-
timeModalOpen: Ref<boolean>
|
|
15
|
-
) {
|
|
16
|
-
// 可编辑的配置项
|
|
17
|
-
const editableNoteStatus = ref(false)
|
|
18
|
-
const editableDiscussionsEnabled = ref(false)
|
|
19
|
-
const editableNoteTitle = ref('')
|
|
20
|
-
const editableDescription = ref('')
|
|
21
|
-
|
|
22
|
-
// 原始配置(用于检测是否有变更)
|
|
23
|
-
const originalNoteStatus = ref(false)
|
|
24
|
-
const originalDiscussionsEnabled = ref(false)
|
|
25
|
-
const originalNoteTitle = ref('')
|
|
26
|
-
const originalDescription = ref('')
|
|
27
|
-
|
|
28
|
-
// 标题验证错误信息
|
|
29
|
-
const titleError = ref('')
|
|
30
|
-
|
|
31
|
-
// 检测是否有配置变更
|
|
32
|
-
const hasConfigChanges = computed(() => {
|
|
33
|
-
return (
|
|
34
|
-
editableNoteStatus.value !== originalNoteStatus.value ||
|
|
35
|
-
editableDiscussionsEnabled.value !== originalDiscussionsEnabled.value ||
|
|
36
|
-
editableDescription.value.trim() !== originalDescription.value ||
|
|
37
|
-
(editableNoteTitle.value.trim() !== originalNoteTitle.value &&
|
|
38
|
-
!titleError.value)
|
|
39
|
-
)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
// 初始化可编辑字段
|
|
43
|
-
function initEditableFields() {
|
|
44
|
-
if (!currentNoteConfig.value) return
|
|
45
|
-
|
|
46
|
-
editableNoteStatus.value = currentNoteConfig.value.done || false
|
|
47
|
-
editableDiscussionsEnabled.value =
|
|
48
|
-
currentNoteConfig.value.enableDiscussions || false
|
|
49
|
-
editableNoteTitle.value = currentNoteTitle.value || ''
|
|
50
|
-
editableDescription.value = currentNoteConfig.value.description || ''
|
|
51
|
-
|
|
52
|
-
// 保存原始值
|
|
53
|
-
originalNoteStatus.value = editableNoteStatus.value
|
|
54
|
-
originalDiscussionsEnabled.value = editableDiscussionsEnabled.value
|
|
55
|
-
originalNoteTitle.value = editableNoteTitle.value
|
|
56
|
-
originalDescription.value = editableDescription.value
|
|
57
|
-
|
|
58
|
-
// 清除错误信息
|
|
59
|
-
titleError.value = ''
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// 重置笔记配置
|
|
63
|
-
function resetNoteConfig() {
|
|
64
|
-
editableNoteStatus.value = originalNoteStatus.value
|
|
65
|
-
editableDiscussionsEnabled.value = originalDiscussionsEnabled.value
|
|
66
|
-
editableNoteTitle.value = originalNoteTitle.value
|
|
67
|
-
editableDescription.value = originalDescription.value
|
|
68
|
-
titleError.value = ''
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 更新原始值(保存成功后调用)
|
|
72
|
-
function updateOriginalValues() {
|
|
73
|
-
originalNoteStatus.value = editableNoteStatus.value
|
|
74
|
-
originalDiscussionsEnabled.value = editableDiscussionsEnabled.value
|
|
75
|
-
originalNoteTitle.value = editableNoteTitle.value.trim()
|
|
76
|
-
originalDescription.value = editableDescription.value.trim()
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// 监听笔记配置变化,重新初始化字段
|
|
80
|
-
watch(
|
|
81
|
-
() => currentNoteConfig.value,
|
|
82
|
-
() => {
|
|
83
|
-
initEditableFields()
|
|
84
|
-
},
|
|
85
|
-
{ immediate: true }
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
// modal 打开时重新初始化(确保数据最新)
|
|
89
|
-
watch(timeModalOpen, (isOpen) => {
|
|
90
|
-
if (isOpen) {
|
|
91
|
-
initEditableFields()
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
// 可编辑字段
|
|
97
|
-
editableNoteStatus,
|
|
98
|
-
editableDiscussionsEnabled,
|
|
99
|
-
editableNoteTitle,
|
|
100
|
-
editableDescription,
|
|
101
|
-
|
|
102
|
-
// 原始值
|
|
103
|
-
originalNoteStatus,
|
|
104
|
-
originalDiscussionsEnabled,
|
|
105
|
-
originalNoteTitle,
|
|
106
|
-
originalDescription,
|
|
107
|
-
|
|
108
|
-
// 验证
|
|
109
|
-
titleError,
|
|
110
|
-
|
|
111
|
-
// 计算属性
|
|
112
|
-
hasConfigChanges,
|
|
113
|
-
|
|
114
|
-
// 方法
|
|
115
|
-
initEditableFields,
|
|
116
|
-
resetNoteConfig,
|
|
117
|
-
updateOriginalValues,
|
|
118
|
-
}
|
|
119
|
-
}
|
|
1
|
+
import { ref, computed, watch } from 'vue'
|
|
2
|
+
|
|
3
|
+
import type { NoteConfig } from '../../../../types'
|
|
4
|
+
import type { Ref } from 'vue'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 管理笔记配置状态
|
|
8
|
+
* 包括可编辑字段、原始值、变更检测等
|
|
9
|
+
*/
|
|
10
|
+
export function useNoteConfig(
|
|
11
|
+
currentNoteId: Ref<string>,
|
|
12
|
+
currentNoteConfig: Ref<NoteConfig | null>,
|
|
13
|
+
currentNoteTitle: Ref<string>,
|
|
14
|
+
timeModalOpen: Ref<boolean>
|
|
15
|
+
) {
|
|
16
|
+
// 可编辑的配置项
|
|
17
|
+
const editableNoteStatus = ref(false)
|
|
18
|
+
const editableDiscussionsEnabled = ref(false)
|
|
19
|
+
const editableNoteTitle = ref('')
|
|
20
|
+
const editableDescription = ref('')
|
|
21
|
+
|
|
22
|
+
// 原始配置(用于检测是否有变更)
|
|
23
|
+
const originalNoteStatus = ref(false)
|
|
24
|
+
const originalDiscussionsEnabled = ref(false)
|
|
25
|
+
const originalNoteTitle = ref('')
|
|
26
|
+
const originalDescription = ref('')
|
|
27
|
+
|
|
28
|
+
// 标题验证错误信息
|
|
29
|
+
const titleError = ref('')
|
|
30
|
+
|
|
31
|
+
// 检测是否有配置变更
|
|
32
|
+
const hasConfigChanges = computed(() => {
|
|
33
|
+
return (
|
|
34
|
+
editableNoteStatus.value !== originalNoteStatus.value ||
|
|
35
|
+
editableDiscussionsEnabled.value !== originalDiscussionsEnabled.value ||
|
|
36
|
+
editableDescription.value.trim() !== originalDescription.value ||
|
|
37
|
+
(editableNoteTitle.value.trim() !== originalNoteTitle.value &&
|
|
38
|
+
!titleError.value)
|
|
39
|
+
)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// 初始化可编辑字段
|
|
43
|
+
function initEditableFields() {
|
|
44
|
+
if (!currentNoteConfig.value) return
|
|
45
|
+
|
|
46
|
+
editableNoteStatus.value = currentNoteConfig.value.done || false
|
|
47
|
+
editableDiscussionsEnabled.value =
|
|
48
|
+
currentNoteConfig.value.enableDiscussions || false
|
|
49
|
+
editableNoteTitle.value = currentNoteTitle.value || ''
|
|
50
|
+
editableDescription.value = currentNoteConfig.value.description || ''
|
|
51
|
+
|
|
52
|
+
// 保存原始值
|
|
53
|
+
originalNoteStatus.value = editableNoteStatus.value
|
|
54
|
+
originalDiscussionsEnabled.value = editableDiscussionsEnabled.value
|
|
55
|
+
originalNoteTitle.value = editableNoteTitle.value
|
|
56
|
+
originalDescription.value = editableDescription.value
|
|
57
|
+
|
|
58
|
+
// 清除错误信息
|
|
59
|
+
titleError.value = ''
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 重置笔记配置
|
|
63
|
+
function resetNoteConfig() {
|
|
64
|
+
editableNoteStatus.value = originalNoteStatus.value
|
|
65
|
+
editableDiscussionsEnabled.value = originalDiscussionsEnabled.value
|
|
66
|
+
editableNoteTitle.value = originalNoteTitle.value
|
|
67
|
+
editableDescription.value = originalDescription.value
|
|
68
|
+
titleError.value = ''
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 更新原始值(保存成功后调用)
|
|
72
|
+
function updateOriginalValues() {
|
|
73
|
+
originalNoteStatus.value = editableNoteStatus.value
|
|
74
|
+
originalDiscussionsEnabled.value = editableDiscussionsEnabled.value
|
|
75
|
+
originalNoteTitle.value = editableNoteTitle.value.trim()
|
|
76
|
+
originalDescription.value = editableDescription.value.trim()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 监听笔记配置变化,重新初始化字段
|
|
80
|
+
watch(
|
|
81
|
+
() => currentNoteConfig.value,
|
|
82
|
+
() => {
|
|
83
|
+
initEditableFields()
|
|
84
|
+
},
|
|
85
|
+
{ immediate: true }
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
// modal 打开时重新初始化(确保数据最新)
|
|
89
|
+
watch(timeModalOpen, (isOpen) => {
|
|
90
|
+
if (isOpen) {
|
|
91
|
+
initEditableFields()
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
// 可编辑字段
|
|
97
|
+
editableNoteStatus,
|
|
98
|
+
editableDiscussionsEnabled,
|
|
99
|
+
editableNoteTitle,
|
|
100
|
+
editableDescription,
|
|
101
|
+
|
|
102
|
+
// 原始值
|
|
103
|
+
originalNoteStatus,
|
|
104
|
+
originalDiscussionsEnabled,
|
|
105
|
+
originalNoteTitle,
|
|
106
|
+
originalDescription,
|
|
107
|
+
|
|
108
|
+
// 验证
|
|
109
|
+
titleError,
|
|
110
|
+
|
|
111
|
+
// 计算属性
|
|
112
|
+
hasConfigChanges,
|
|
113
|
+
|
|
114
|
+
// 方法
|
|
115
|
+
initEditableFields,
|
|
116
|
+
resetNoteConfig,
|
|
117
|
+
updateOriginalValues,
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -1,178 +1,178 @@
|
|
|
1
|
-
import { useData } from 'vitepress'
|
|
2
|
-
import { ref, computed } from 'vue'
|
|
3
|
-
|
|
4
|
-
import { redirectAfterRename } from './useRenameRedirect'
|
|
5
|
-
|
|
6
|
-
import type { NoteConfig } from '../../../../types'
|
|
7
|
-
import type { Ref, ComputedRef } from 'vue'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 处理笔记配置的保存和重置逻辑
|
|
11
|
-
*/
|
|
12
|
-
export function useNoteSave(
|
|
13
|
-
currentNoteId: Ref<string>,
|
|
14
|
-
isDev: Ref<boolean> | ComputedRef<boolean>,
|
|
15
|
-
hasConfigChanges: ComputedRef<boolean>,
|
|
16
|
-
titleError: Ref<string>,
|
|
17
|
-
editableNoteTitle: Ref<string>,
|
|
18
|
-
originalNoteTitle: Ref<string>,
|
|
19
|
-
editableNoteStatus: Ref<boolean>,
|
|
20
|
-
originalNoteStatus: Ref<boolean>,
|
|
21
|
-
editableDiscussionsEnabled: Ref<boolean>,
|
|
22
|
-
originalDiscussionsEnabled: Ref<boolean>,
|
|
23
|
-
editableDescription: Ref<string>,
|
|
24
|
-
originalDescription: Ref<string>,
|
|
25
|
-
allNotesConfig: Record<string, NoteConfig & { redirect?: string }>,
|
|
26
|
-
updateOriginalValues: () => void
|
|
27
|
-
) {
|
|
28
|
-
const vpData = useData()
|
|
29
|
-
|
|
30
|
-
// 保存状态
|
|
31
|
-
const isSaving = ref(false)
|
|
32
|
-
const showSuccessToast = ref(false)
|
|
33
|
-
const savingMessage = ref('') // 保存进度提示
|
|
34
|
-
|
|
35
|
-
// 保存按钮文本
|
|
36
|
-
const saveButtonText = computed(() => {
|
|
37
|
-
if (isSaving.value) return '保存中...'
|
|
38
|
-
if (!hasConfigChanges.value) return '无更改'
|
|
39
|
-
return '保存配置'
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
// 保存笔记配置
|
|
43
|
-
async function saveNoteConfig() {
|
|
44
|
-
if (!currentNoteId.value || !isDev.value || !hasConfigChanges.value) return
|
|
45
|
-
|
|
46
|
-
// 验证标题
|
|
47
|
-
if (titleError.value) {
|
|
48
|
-
alert('❌ 请修正标题错误后再保存')
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const titleChanged =
|
|
53
|
-
editableNoteTitle.value.trim() !== originalNoteTitle.value &&
|
|
54
|
-
editableNoteTitle.value.trim()
|
|
55
|
-
|
|
56
|
-
isSaving.value = true
|
|
57
|
-
savingMessage.value = '正在保存配置...'
|
|
58
|
-
|
|
59
|
-
let renameNewUrl: string | null = null
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
// 如果标题有变化,先重命名文件夹
|
|
63
|
-
if (titleChanged) {
|
|
64
|
-
savingMessage.value = '正在重命名文件夹...'
|
|
65
|
-
|
|
66
|
-
const renameResponse = await fetch('/__tnotes_rename_note', {
|
|
67
|
-
method: 'POST',
|
|
68
|
-
headers: {
|
|
69
|
-
'Content-Type': 'application/json',
|
|
70
|
-
},
|
|
71
|
-
body: JSON.stringify({
|
|
72
|
-
noteIndex: currentNoteId.value,
|
|
73
|
-
newTitle: editableNoteTitle.value.trim(),
|
|
74
|
-
}),
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
if (!renameResponse.ok) {
|
|
78
|
-
const error = await renameResponse.text()
|
|
79
|
-
throw new Error(`重命名失败: ${error}`)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// 后端已经完成所有更新(含文件系统、根 README、sidebar)
|
|
83
|
-
const result = (await renameResponse.json()) as {
|
|
84
|
-
success: boolean
|
|
85
|
-
newUrl?: string
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!result?.newUrl) {
|
|
89
|
-
throw new Error('重命名响应缺少 newUrl 字段')
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
renameNewUrl = result.newUrl
|
|
93
|
-
savingMessage.value = '文件已同步,准备跳转...'
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 检查是否需要更新配置(无论标题是否改变)
|
|
97
|
-
const needConfigUpdate =
|
|
98
|
-
editableNoteStatus.value !== originalNoteStatus.value ||
|
|
99
|
-
editableDiscussionsEnabled.value !== originalDiscussionsEnabled.value ||
|
|
100
|
-
editableDescription.value.trim() !== originalDescription.value
|
|
101
|
-
|
|
102
|
-
if (needConfigUpdate) {
|
|
103
|
-
savingMessage.value = '正在更新笔记配置...'
|
|
104
|
-
|
|
105
|
-
const response = await fetch('/__tnotes_update_config', {
|
|
106
|
-
method: 'POST',
|
|
107
|
-
headers: {
|
|
108
|
-
'Content-Type': 'application/json',
|
|
109
|
-
},
|
|
110
|
-
body: JSON.stringify({
|
|
111
|
-
noteIndex: currentNoteId.value,
|
|
112
|
-
config: {
|
|
113
|
-
done: editableNoteStatus.value,
|
|
114
|
-
enableDiscussions: editableDiscussionsEnabled.value,
|
|
115
|
-
description: editableDescription.value.trim(),
|
|
116
|
-
},
|
|
117
|
-
}),
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
if (!response.ok) {
|
|
121
|
-
const error = await response.text()
|
|
122
|
-
throw new Error(error || '保存失败')
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// 更新原始值
|
|
127
|
-
updateOriginalValues()
|
|
128
|
-
|
|
129
|
-
// 更新本地配置(立即反映在页面上)
|
|
130
|
-
if (allNotesConfig[currentNoteId.value]) {
|
|
131
|
-
allNotesConfig[currentNoteId.value].done = editableNoteStatus.value
|
|
132
|
-
allNotesConfig[currentNoteId.value].enableDiscussions =
|
|
133
|
-
editableDiscussionsEnabled.value
|
|
134
|
-
allNotesConfig[currentNoteId.value].description =
|
|
135
|
-
editableDescription.value.trim()
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
savingMessage.value = '保存成功!'
|
|
139
|
-
|
|
140
|
-
// 显示成功提示
|
|
141
|
-
showSuccessToast.value = true
|
|
142
|
-
setTimeout(() => {
|
|
143
|
-
showSuccessToast.value = false
|
|
144
|
-
}, 3000)
|
|
145
|
-
|
|
146
|
-
// 如果标题改变了, 显示遮罩并整页跳到新 URL
|
|
147
|
-
if (titleChanged && renameNewUrl) {
|
|
148
|
-
// 提前结束「保存中」状态,避免遮罩退出后按钮文案残留
|
|
149
|
-
isSaving.value = false
|
|
150
|
-
savingMessage.value = ''
|
|
151
|
-
|
|
152
|
-
const base = vpData.site.value.base || '/'
|
|
153
|
-
await redirectAfterRename(renameNewUrl, { base })
|
|
154
|
-
}
|
|
155
|
-
} catch (error) {
|
|
156
|
-
console.error('保存配置失败:', error)
|
|
157
|
-
savingMessage.value = ''
|
|
158
|
-
|
|
159
|
-
alert(
|
|
160
|
-
'❌ 保存失败: ' +
|
|
161
|
-
(error instanceof Error ? error.message : String(error))
|
|
162
|
-
)
|
|
163
|
-
} finally {
|
|
164
|
-
if (!titleChanged) {
|
|
165
|
-
isSaving.value = false
|
|
166
|
-
savingMessage.value = ''
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return {
|
|
172
|
-
isSaving,
|
|
173
|
-
showSuccessToast,
|
|
174
|
-
savingMessage,
|
|
175
|
-
saveButtonText,
|
|
176
|
-
saveNoteConfig,
|
|
177
|
-
}
|
|
178
|
-
}
|
|
1
|
+
import { useData } from 'vitepress'
|
|
2
|
+
import { ref, computed } from 'vue'
|
|
3
|
+
|
|
4
|
+
import { redirectAfterRename } from './useRenameRedirect'
|
|
5
|
+
|
|
6
|
+
import type { NoteConfig } from '../../../../types'
|
|
7
|
+
import type { Ref, ComputedRef } from 'vue'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 处理笔记配置的保存和重置逻辑
|
|
11
|
+
*/
|
|
12
|
+
export function useNoteSave(
|
|
13
|
+
currentNoteId: Ref<string>,
|
|
14
|
+
isDev: Ref<boolean> | ComputedRef<boolean>,
|
|
15
|
+
hasConfigChanges: ComputedRef<boolean>,
|
|
16
|
+
titleError: Ref<string>,
|
|
17
|
+
editableNoteTitle: Ref<string>,
|
|
18
|
+
originalNoteTitle: Ref<string>,
|
|
19
|
+
editableNoteStatus: Ref<boolean>,
|
|
20
|
+
originalNoteStatus: Ref<boolean>,
|
|
21
|
+
editableDiscussionsEnabled: Ref<boolean>,
|
|
22
|
+
originalDiscussionsEnabled: Ref<boolean>,
|
|
23
|
+
editableDescription: Ref<string>,
|
|
24
|
+
originalDescription: Ref<string>,
|
|
25
|
+
allNotesConfig: Record<string, NoteConfig & { redirect?: string }>,
|
|
26
|
+
updateOriginalValues: () => void
|
|
27
|
+
) {
|
|
28
|
+
const vpData = useData()
|
|
29
|
+
|
|
30
|
+
// 保存状态
|
|
31
|
+
const isSaving = ref(false)
|
|
32
|
+
const showSuccessToast = ref(false)
|
|
33
|
+
const savingMessage = ref('') // 保存进度提示
|
|
34
|
+
|
|
35
|
+
// 保存按钮文本
|
|
36
|
+
const saveButtonText = computed(() => {
|
|
37
|
+
if (isSaving.value) return '保存中...'
|
|
38
|
+
if (!hasConfigChanges.value) return '无更改'
|
|
39
|
+
return '保存配置'
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// 保存笔记配置
|
|
43
|
+
async function saveNoteConfig() {
|
|
44
|
+
if (!currentNoteId.value || !isDev.value || !hasConfigChanges.value) return
|
|
45
|
+
|
|
46
|
+
// 验证标题
|
|
47
|
+
if (titleError.value) {
|
|
48
|
+
alert('❌ 请修正标题错误后再保存')
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const titleChanged =
|
|
53
|
+
editableNoteTitle.value.trim() !== originalNoteTitle.value &&
|
|
54
|
+
editableNoteTitle.value.trim()
|
|
55
|
+
|
|
56
|
+
isSaving.value = true
|
|
57
|
+
savingMessage.value = '正在保存配置...'
|
|
58
|
+
|
|
59
|
+
let renameNewUrl: string | null = null
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
// 如果标题有变化,先重命名文件夹
|
|
63
|
+
if (titleChanged) {
|
|
64
|
+
savingMessage.value = '正在重命名文件夹...'
|
|
65
|
+
|
|
66
|
+
const renameResponse = await fetch('/__tnotes_rename_note', {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
headers: {
|
|
69
|
+
'Content-Type': 'application/json',
|
|
70
|
+
},
|
|
71
|
+
body: JSON.stringify({
|
|
72
|
+
noteIndex: currentNoteId.value,
|
|
73
|
+
newTitle: editableNoteTitle.value.trim(),
|
|
74
|
+
}),
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
if (!renameResponse.ok) {
|
|
78
|
+
const error = await renameResponse.text()
|
|
79
|
+
throw new Error(`重命名失败: ${error}`)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 后端已经完成所有更新(含文件系统、根 README、sidebar)
|
|
83
|
+
const result = (await renameResponse.json()) as {
|
|
84
|
+
success: boolean
|
|
85
|
+
newUrl?: string
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!result?.newUrl) {
|
|
89
|
+
throw new Error('重命名响应缺少 newUrl 字段')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
renameNewUrl = result.newUrl
|
|
93
|
+
savingMessage.value = '文件已同步,准备跳转...'
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 检查是否需要更新配置(无论标题是否改变)
|
|
97
|
+
const needConfigUpdate =
|
|
98
|
+
editableNoteStatus.value !== originalNoteStatus.value ||
|
|
99
|
+
editableDiscussionsEnabled.value !== originalDiscussionsEnabled.value ||
|
|
100
|
+
editableDescription.value.trim() !== originalDescription.value
|
|
101
|
+
|
|
102
|
+
if (needConfigUpdate) {
|
|
103
|
+
savingMessage.value = '正在更新笔记配置...'
|
|
104
|
+
|
|
105
|
+
const response = await fetch('/__tnotes_update_config', {
|
|
106
|
+
method: 'POST',
|
|
107
|
+
headers: {
|
|
108
|
+
'Content-Type': 'application/json',
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify({
|
|
111
|
+
noteIndex: currentNoteId.value,
|
|
112
|
+
config: {
|
|
113
|
+
done: editableNoteStatus.value,
|
|
114
|
+
enableDiscussions: editableDiscussionsEnabled.value,
|
|
115
|
+
description: editableDescription.value.trim(),
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
if (!response.ok) {
|
|
121
|
+
const error = await response.text()
|
|
122
|
+
throw new Error(error || '保存失败')
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 更新原始值
|
|
127
|
+
updateOriginalValues()
|
|
128
|
+
|
|
129
|
+
// 更新本地配置(立即反映在页面上)
|
|
130
|
+
if (allNotesConfig[currentNoteId.value]) {
|
|
131
|
+
allNotesConfig[currentNoteId.value].done = editableNoteStatus.value
|
|
132
|
+
allNotesConfig[currentNoteId.value].enableDiscussions =
|
|
133
|
+
editableDiscussionsEnabled.value
|
|
134
|
+
allNotesConfig[currentNoteId.value].description =
|
|
135
|
+
editableDescription.value.trim()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
savingMessage.value = '保存成功!'
|
|
139
|
+
|
|
140
|
+
// 显示成功提示
|
|
141
|
+
showSuccessToast.value = true
|
|
142
|
+
setTimeout(() => {
|
|
143
|
+
showSuccessToast.value = false
|
|
144
|
+
}, 3000)
|
|
145
|
+
|
|
146
|
+
// 如果标题改变了, 显示遮罩并整页跳到新 URL
|
|
147
|
+
if (titleChanged && renameNewUrl) {
|
|
148
|
+
// 提前结束「保存中」状态,避免遮罩退出后按钮文案残留
|
|
149
|
+
isSaving.value = false
|
|
150
|
+
savingMessage.value = ''
|
|
151
|
+
|
|
152
|
+
const base = vpData.site.value.base || '/'
|
|
153
|
+
await redirectAfterRename(renameNewUrl, { base })
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error('保存配置失败:', error)
|
|
157
|
+
savingMessage.value = ''
|
|
158
|
+
|
|
159
|
+
alert(
|
|
160
|
+
'❌ 保存失败: ' +
|
|
161
|
+
(error instanceof Error ? error.message : String(error))
|
|
162
|
+
)
|
|
163
|
+
} finally {
|
|
164
|
+
if (!titleChanged) {
|
|
165
|
+
isSaving.value = false
|
|
166
|
+
savingMessage.value = ''
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
isSaving,
|
|
173
|
+
showSuccessToast,
|
|
174
|
+
savingMessage,
|
|
175
|
+
saveButtonText,
|
|
176
|
+
saveNoteConfig,
|
|
177
|
+
}
|
|
178
|
+
}
|