@tnotesjs/core 0.6.1 → 0.8.0

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.
Files changed (92) hide show
  1. package/commands/BaseCommand.ts +58 -0
  2. package/commands/build/BuildCommand.ts +25 -0
  3. package/commands/build/PreviewCommand.ts +29 -0
  4. package/commands/build/index.ts +8 -0
  5. package/commands/dev/DevCommand.ts +75 -0
  6. package/commands/dev/index.ts +7 -0
  7. package/commands/git/PullCommand.ts +25 -0
  8. package/commands/git/PushCommand.ts +64 -0
  9. package/commands/git/index.ts +8 -0
  10. package/commands/index.ts +11 -0
  11. package/commands/init-sub-repo/InitSubRepoCommand.ts +206 -0
  12. package/commands/init-sub-repo/index.ts +1 -0
  13. package/commands/misc/HelpCommand.ts +104 -0
  14. package/commands/misc/index.ts +7 -0
  15. package/commands/models.ts +87 -0
  16. package/commands/note/CreateNoteCommand.ts +160 -0
  17. package/commands/note/RenameNoteCommand.ts +147 -0
  18. package/commands/note/UpdateNoteConfigCommand.ts +78 -0
  19. package/commands/note/index.ts +9 -0
  20. package/commands/registry.ts +47 -0
  21. package/commands/update/UpdateCommand.ts +219 -0
  22. package/commands/update/index.ts +7 -0
  23. package/commands/update-completed-count/UpdateCompletedCountCommand.ts +208 -0
  24. package/commands/update-completed-count/index.ts +5 -0
  25. package/config/templates.ts +0 -5
  26. package/dist/{chunk-5F5RJ2HV.cjs → chunk-7FEANCT6.cjs} +16 -7
  27. package/dist/chunk-AGVER5MX.cjs +1746 -0
  28. package/dist/{chunk-TJ4527KA.cjs → chunk-BL22KD4V.cjs} +324 -950
  29. package/dist/{chunk-56PKXCOX.js → chunk-GWG75A5M.js} +13 -4
  30. package/dist/{chunk-DUTS75WQ.js → chunk-XNO3PCEH.js} +374 -1000
  31. package/dist/chunk-ZEQS64PE.js +1746 -0
  32. package/dist/cli/index.cjs +76 -155
  33. package/dist/cli/index.js +10 -89
  34. package/dist/markdown/index.cjs +8 -12
  35. package/dist/markdown/index.d.cts +1 -1
  36. package/dist/markdown/index.d.ts +1 -1
  37. package/dist/markdown/index.js +7 -11
  38. package/dist/{types-CwBWwNVv.d.ts → types-C_d0fFeD.d.ts} +8 -1
  39. package/dist/{types-CpsEy8lA.d.cts → types-MRBGgJTX.d.cts} +8 -1
  40. package/dist/vitepress/config/index.cjs +402 -178
  41. package/dist/vitepress/config/index.js +392 -168
  42. package/dist/workspace/index.cjs +4 -1202
  43. package/dist/workspace/index.d.cts +2 -2
  44. package/dist/workspace/index.d.ts +2 -2
  45. package/dist/workspace/index.js +4 -1202
  46. package/markdown/components.ts +86 -0
  47. package/markdown/index.ts +17 -0
  48. package/markdown/noteFormatter.test.ts +44 -0
  49. package/markdown/noteFormatter.ts +237 -0
  50. package/package.json +7 -3
  51. package/services/file-watcher/folderChangeHandler.ts +19 -15
  52. package/services/file-watcher/globalUpdateCoordinator.ts +21 -27
  53. package/services/file-watcher/service.ts +1 -6
  54. package/services/index.ts +0 -1
  55. package/services/note/service.ts +4 -6
  56. package/services/readme/service.ts +11 -18
  57. package/services/reconcileToc.ts +20 -0
  58. package/utils/index.ts +0 -9
  59. package/{services/toc → utils}/moveTocInside.test.ts +1 -1
  60. package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +9 -18
  61. package/vitepress/components/EnWordList/EnWordList.vue +16 -662
  62. package/vitepress/components/Footprints/Footprints.vue +15 -537
  63. package/vitepress/components/Mermaid/Mermaid.vue +13 -588
  64. package/vitepress/components/MindmapPreview/MindmapPreview.vue +12 -434
  65. package/vitepress/components/MindmapPreview/markdown.ts +1 -1
  66. package/vitepress/components/NotesTable/NotesTable.vue +11 -130
  67. package/vitepress/components/constants.ts +2 -2
  68. package/vitepress/components/sidebar.data.ts +8 -5
  69. package/vitepress/configs/markdown.config.ts +170 -26
  70. package/vitepress/plugins/sidebarStructurePlugin.ts +242 -145
  71. package/vitepress/theme/index.ts +9 -13
  72. package/vitepress/theme/styles/base.scss +15 -0
  73. package/workspace/atomic.ts +113 -0
  74. package/workspace/errors.ts +27 -0
  75. package/workspace/index.ts +40 -0
  76. package/workspace/mutationQueue.ts +28 -0
  77. package/workspace/paths.ts +64 -0
  78. package/workspace/reconcile.test.ts +300 -0
  79. package/workspace/reconcile.ts +95 -0
  80. package/workspace/scanner.ts +292 -0
  81. package/workspace/types.ts +224 -0
  82. package/workspace/workspace.test.ts +333 -0
  83. package/workspace/workspace.ts +1020 -0
  84. package/dist/chunk-3R7QSABB.cjs +0 -502
  85. package/dist/chunk-CZXRQPFJ.js +0 -11
  86. package/dist/chunk-HXED7KVT.cjs +0 -11
  87. package/dist/chunk-U6IBLREL.js +0 -502
  88. package/services/toc/index.ts +0 -5
  89. package/services/toc/service.ts +0 -759
  90. package/utils/migrateReadmeToToc.test.ts +0 -111
  91. package/utils/migrateReadmeToToc.ts +0 -135
  92. package/vitepress/components/EnWordList/RightClickMenu.vue +0 -93
@@ -1,541 +1,19 @@
1
- <!--
2
- vitepress/components/Footprints/Footprints.vue
3
- -->
4
-
5
- <script setup>
6
- import { onContentUpdated } from 'vitepress'
7
- import { ref, onMounted, onBeforeUnmount, computed, nextTick } from 'vue'
8
-
9
- // ----------------------------------------------------------
10
- // #region - 图片处理
11
- // ----------------------------------------------------------
12
- /**
13
- * 获取图片容器的 DOM 引用
14
- */
15
- const imageContainer = ref(null)
16
-
17
- /**
18
- * 图片数量,用于朋友圈式网格布局(1 / 2 / 4 / 3 列)
19
- */
20
- const imageCount = ref(0)
21
-
22
- const imageLayoutClass = computed(() => {
23
- const n = imageCount.value
24
- if (n === 1) return 'fp-layout-1'
25
- if (n === 2) return 'fp-layout-2'
26
- if (n === 4) return 'fp-layout-4'
27
- if (n >= 3) return 'fp-layout-grid'
28
- return ''
29
- })
30
-
31
- function initImageList() {
32
- if (!imageContainer.value) return
33
-
34
- const imgElements = imageContainer.value.querySelectorAll('img')
35
- imageCount.value = imgElements.length
36
- images.value = Array.from(imgElements).map((img) => img.src)
37
- }
38
-
39
- /**
40
- * 动态存储图片路径的列表
41
- */
42
- const images = ref([])
43
-
44
- /**
45
- * 控制 modal 显示
46
- */
47
- const isModalVisible = ref(false)
48
-
49
- /**
50
- * 当前预览的图片索引
51
- */
52
- const currentIndex = ref(0)
53
- const currentImage = computed(() => images.value[currentIndex.value])
54
-
55
- /**
56
- * 唯一标识符,用于区分不同的组件实例。
57
- * 解决被多次复用的时候,直接操作 DOM 的相关逻辑出现 bug。
58
- */
59
- const instanceId = Math.random().toString(36).substr(2, 9)
60
-
61
- /**
62
- * 打开模态框
63
- * @param index 需要展示的图片的索引
64
- */
65
- const openModal = (index) => {
66
- currentIndex.value = index
67
- isModalVisible.value = true
68
- }
69
- /**
70
- * 关闭模态框
71
- */
72
- const closeModal = () => (isModalVisible.value = false)
73
- /**
74
- * 键盘事件处理
75
- * @param event 事件对象
76
- */
77
- const handleKeyDown = (event) => {
78
- if (!isModalVisible.value) return
79
- switch (event.key) {
80
- case 'ArrowLeft':
81
- if (currentIndex.value > 0) currentIndex.value -= 1
82
- break
83
- case 'ArrowRight':
84
- if (currentIndex.value < images.value.length - 1) currentIndex.value += 1
85
- break
86
- case 'Escape':
87
- closeModal()
88
- break
89
- }
90
- }
91
- /**
92
- * 手指按下的初始 X 坐标
93
- */
94
- let touchStartX = 0
95
- /**
96
- * 手指抬起的最终 X 坐标
97
- */
98
- let touchEndX = 0
99
-
100
- /**
101
- * 处理触摸开始事件
102
- * @param event 事件对象
103
- */
104
- const handleTouchStart = (event) => {
105
- event.preventDefault() // 阻止默认行为
106
- touchStartX = event.touches[0].clientX // 记录手指按下的初始位置
107
- // console.log(`Touch start at: ${touchStartX}`);
108
- }
109
-
110
- /**
111
- * 处理触摸移动事件
112
- * @param event 事件对象
113
- */
114
- const handleTouchMove = (event) => {
115
- event.preventDefault() // 阻止默认行为
116
- const currentX = event.touches[0].clientX
117
- const moveDistance = currentX - touchStartX
118
-
119
- // 可选:添加视觉反馈(例如轻微移动图片的位置)
120
- // console.log(`Move distance: ${moveDistance}`);
121
- }
122
-
123
- /**
124
- * 处理触摸结束事件
125
- * - 向右滑动:切换到上一张图片
126
- * - 向左滑动:切换到下一张图片
127
- */
128
- const handleTouchEnd = () => {
129
- const swipeThreshold = 50 // 滑动阈值,单位为像素
130
- const swipeDistance = touchEndX - touchStartX // 计算滑动距离
131
- console.log(`Touch end at: ${touchEndX}, Distance: ${swipeDistance}`)
132
-
133
- if (swipeDistance > swipeThreshold && currentIndex.value > 0) {
134
- currentIndex.value--
135
- } else if (
136
- swipeDistance < -swipeThreshold &&
137
- currentIndex.value < images.value.length - 1
138
- ) {
139
- currentIndex.value++
140
- }
141
- }
142
- /**
143
- * 鼠标按下的初始 X 坐标
144
- */
145
- let mouseStartX = 0
146
- /**
147
- * 处理鼠标按下事件
148
- * @param event 事件对象
149
- */
150
- const handleMouseDown = (event) => {
151
- event.preventDefault()
152
- mouseStartX = event.clientX // 记录鼠标按下的初始位置
153
- window.addEventListener('mousemove', handleMouseMove)
154
- window.addEventListener('mouseup', handleMouseUp)
155
- }
156
- /**
157
- * 处理鼠标移动事件
158
- * @param event 事件对象
159
- */
160
- const handleMouseMove = (event) => {
161
- event.preventDefault()
162
- const currentX = event.clientX
163
- const moveDistance = currentX - mouseStartX
164
- // 可以在这里添加一些视觉反馈,比如轻微移动图片的位置
165
- // console.log(`Move distance: ${moveDistance}`);
166
- }
167
- /**
168
- * 处理鼠标松开事件
169
- */
170
- const handleMouseUp = () => {
171
- const swipeThreshold = 50 // 滑动阈值,单位为像素
172
- const modalContent = document.querySelector('.__dynamic__modal-content')
173
- if (!modalContent) return
174
-
175
- // 使用鼠标松开时的位置
176
- const currentX = event.clientX // 直接从事件对象中获取
177
- const moveDistance = currentX - mouseStartX
178
-
179
- if (moveDistance > swipeThreshold && currentIndex.value > 0) {
180
- currentIndex.value-- // 向右滑动,切换到上一张图片
181
- } else if (
182
- moveDistance < -swipeThreshold &&
183
- currentIndex.value < images.value.length - 1
184
- ) {
185
- currentIndex.value++ // 向左滑动,切换到下一张图片
186
- }
187
-
188
- // 清理变量和事件监听器
189
- mouseStartX = 0
190
- window.removeEventListener('mousemove', handleMouseMove)
191
- window.removeEventListener('mouseup', handleMouseUp)
192
- }
193
-
194
- onMounted(() => {
195
- nextTick(() => {
196
- initImageList()
197
- })
198
-
199
- // 添加键盘事件监听器
200
- window.addEventListener('keydown', handleKeyDown)
201
- })
202
-
203
- onContentUpdated(() => {
204
- nextTick(initImageList)
205
- })
206
-
207
- onBeforeUnmount(() => {
208
- window.removeEventListener('keydown', handleKeyDown)
209
-
210
- // 移除触摸事件监听器
211
- const modalContent = document.querySelector(
212
- `.__dynamic__modal-content-${instanceId}`
213
- )
214
- if (modalContent) {
215
- modalContent.removeEventListener('touchstart', handleTouchStart)
216
- modalContent.removeEventListener('touchmove', handleTouchMove) // 移除 touchmove 事件
217
- modalContent.removeEventListener('touchend', handleTouchEnd)
218
- modalContent.removeEventListener('mousedown', handleMouseDown)
219
- }
220
- })
221
- // ----------------------------------------------------------
222
- // #endregion - 图片处理
223
- // ----------------------------------------------------------
224
-
225
- // ----------------------------------------------------------
226
- // #region - 文案处理
227
- // ----------------------------------------------------------
228
-
229
- /**
230
- * 文本容器的 DOM 引用
231
- */
232
- const textContainer = ref(null)
233
-
234
- /**
235
- * 控制文本是否折叠
236
- */
237
- const isCollapsed = ref(true)
238
-
239
- /**
240
- * 是否需要显示“全文”按钮
241
- */
242
- const isExpandable = ref(false)
243
-
244
- /**
245
- * 计算一级子元素数量并判断是否需要折叠
246
- * 1. 获取所有一级子元素
247
- * 2. 如果一级子元素数量大于 2,则可以展开
248
- */
249
- const checkChildElementCount = () => {
250
- if (textContainer.value) {
251
- const childElements = textContainer.value.children
252
- isExpandable.value = childElements.length > 2
253
- }
254
- }
255
-
256
- /**
257
- * 切换折叠/展开状态
258
- */
259
- const toggleCollapse = () => {
260
- isCollapsed.value = !isCollapsed.value
261
- }
262
-
263
- /**
264
- * 在 DOM 渲染后再做计算
265
- */
266
- onMounted(() => {
267
- nextTick(checkChildElementCount)
268
- })
269
- // ----------------------------------------------------------
270
- // #endregion - 文案处理
271
- // ----------------------------------------------------------
272
-
273
- // ----------------------------------------------------------
274
- // #region - 时间信息处理
275
- // ----------------------------------------------------------
276
- const props = defineProps({
277
- times: {
278
- type: Array,
279
- default: () => [],
280
- validator: (value) => {
281
- // 验证数组长度和内容类型
282
- return (
283
- value.length >= 2 &&
284
- value.length <= 6 &&
285
- value.every((item, index) => {
286
- if (index === 0) return typeof item === 'number' && item >= 0 // 年
287
- if (index === 1)
288
- return typeof item === 'number' && item >= 1 && item <= 12 // 月
289
- if (index === 2)
290
- return typeof item === 'number' && item >= 1 && item <= 31 // 日
291
- if (index === 3)
292
- return typeof item === 'number' && item >= 0 && item <= 23 // 小时
293
- if (index === 4)
294
- return typeof item === 'number' && item >= 0 && item <= 59 // 分钟
295
- if (index === 5)
296
- return typeof item === 'number' && item >= 0 && item <= 59 // 秒
297
- return false
298
- })
299
- )
300
- },
301
- },
302
- })
303
-
304
- const formattedTime = computed(() => {
305
- if (props.times.length < 2) return ''
306
-
307
- const [year, month, day, hour, minute, second] = props.times
308
-
309
- // 格式化年月日
310
- const datePart = `${String(year).padStart(4, '0')}-${String(month).padStart(
311
- 2,
312
- '0'
313
- )}`
314
- const dayPart = day !== undefined ? `-${String(day).padStart(2, '0')}` : ''
315
-
316
- // 格式化时分秒
317
- let timePart = ''
318
- if (hour !== undefined && minute !== undefined && second !== undefined) {
319
- timePart = ` ${String(hour).padStart(2, '0')}:${String(minute).padStart(
320
- 2,
321
- '0'
322
- )}:${String(second).padStart(2, '0')}`
323
- } else if (hour !== undefined && minute !== undefined) {
324
- timePart = ` ${String(hour).padStart(2, '0')}:${String(minute).padStart(
325
- 2,
326
- '0'
327
- )}`
328
- }
329
-
330
- // 👣 天数
331
- let daysSinceBirthday = ''
332
- if (day !== undefined) {
333
- // 确保时间部分为 00:00:00,避免时区和时间部分的影响
334
- const birthday = new Date(Date.UTC(1999, 5, 29)) // 注意:月份从 0 开始计数
335
- const currentDate = new Date(Date.UTC(year, month - 1, day)) // 同样使用 UTC 时间
336
- const diffInMilliseconds = currentDate - birthday
337
- const diffInDays =
338
- Math.floor(diffInMilliseconds / (1000 * 60 * 60 * 24)) + 1
339
- daysSinceBirthday = `👣 ${diffInDays} | `
340
- }
341
-
342
- return daysSinceBirthday + datePart + dayPart + timePart
343
- })
344
- // ----------------------------------------------------------
345
- // #endregion - 时间信息处理
346
- // ----------------------------------------------------------
1
+ <script setup lang="ts">
2
+ import { Footprints as TnFootprints } from '@tnotesjs/ui'
3
+
4
+ defineProps<{
5
+ times?: number[]
6
+ paragraphs?: string[]
7
+ images?: string[]
8
+ otherInfo?: string
9
+ }>()
347
10
  </script>
348
11
 
349
12
  <template>
350
- <div class="textContainer">
351
- <div
352
- class="textContent"
353
- :class="{ collapsed: isCollapsed }"
354
- ref="textContainer"
355
- >
356
- <slot name="text-area"></slot>
357
- </div>
358
- <button
359
- v-if="isExpandable"
360
- class="toggleButton"
361
- @click="toggleCollapse"
362
- >
363
- {{ isCollapsed ? '全文' : '收起' }}
364
- </button>
365
- </div>
366
-
367
- <div
368
- class="imageContainer"
369
- :class="imageLayoutClass"
370
- ref="imageContainer"
371
- >
372
- <slot
373
- name="image-list"
374
- :openModal="openModal"
375
- :closeModal="closeModal"
376
- :currentImage="currentImage"
377
- :isModalVisible="isModalVisible"
378
- ></slot>
379
- </div>
380
- <div class="modal" v-show="isModalVisible" @click.self="closeModal">
381
- <span class="close" @click="closeModal">&times;</span>
382
- <img
383
- :class="['modalContent', `__dynamic__modal-content-${instanceId}`]"
384
- :src="currentImage"
385
- alt="Preview"
386
- @mousedown="handleMouseDown"
387
- />
388
- </div>
389
-
390
- <div class="timeContainer">
391
- <p>{{ formattedTime }}</p>
392
- </div>
393
- <div class="otherInfoContainer">
394
- <slot name="other-info"></slot>
395
- </div>
13
+ <TnFootprints
14
+ :times="times"
15
+ :paragraphs="paragraphs"
16
+ :images="images"
17
+ :other-info="otherInfo"
18
+ />
396
19
  </template>
397
-
398
- <style scoped lang="scss">
399
- // Footprints 组件样式
400
-
401
- // 其他信息容器和时间容器
402
- .otherInfoContainer,
403
- .timeContainer {
404
- font-size: 0.8rem;
405
- color: gray;
406
- }
407
-
408
- // 文本容器
409
- .textContainer {
410
- position: relative;
411
- margin-bottom: 1rem;
412
- }
413
-
414
- // 文本内容
415
- .textContent {
416
- overflow: hidden;
417
- transition: max-height 0.3s ease;
418
-
419
- // 折叠状态:隐藏从第三个开始的所有一级子元素
420
- &.collapsed > :nth-child(n + 3) {
421
- display: none;
422
- }
423
- }
424
-
425
- // 切换按钮
426
- .toggleButton {
427
- display: block;
428
- margin-top: 0.5rem;
429
- background-color: transparent;
430
- color: #007bff;
431
- border: none;
432
- cursor: pointer;
433
- text-align: left;
434
- font-size: 1rem;
435
-
436
- &:hover {
437
- text-decoration: underline;
438
- }
439
- }
440
-
441
- // 图片容器(朋友圈式网格:Markdown 图片常被包在 p/a 中,需 grid + :deep)
442
- .imageContainer {
443
- display: grid;
444
- gap: 4px;
445
- width: 100%;
446
-
447
- :deep(> *) {
448
- margin: 0;
449
- min-width: 0;
450
- }
451
-
452
- :deep(p) {
453
- margin: 0;
454
- line-height: 0;
455
- }
456
-
457
- :deep(a) {
458
- display: block;
459
- line-height: 0;
460
- }
461
-
462
- :deep(img) {
463
- width: 100%;
464
- aspect-ratio: 1;
465
- object-fit: cover;
466
- display: block;
467
- margin: 0;
468
- cursor: pointer;
469
- vertical-align: top;
470
- }
471
-
472
- /* 1 张:较大单图,不强制正方形 */
473
- &.fp-layout-1 {
474
- grid-template-columns: 1fr;
475
- max-width: 280px;
476
-
477
- :deep(img) {
478
- width: auto;
479
- max-width: 100%;
480
- max-height: 360px;
481
- aspect-ratio: auto;
482
- object-fit: cover;
483
- }
484
- }
485
-
486
- /* 2 张:一行两列 */
487
- &.fp-layout-2 {
488
- grid-template-columns: repeat(2, 1fr);
489
- max-width: 360px;
490
- }
491
-
492
- /* 4 张:2×2 */
493
- &.fp-layout-4 {
494
- grid-template-columns: repeat(2, 1fr);
495
- max-width: 360px;
496
- }
497
-
498
- /* 3 / 5–9 张:三列网格 */
499
- &.fp-layout-grid {
500
- grid-template-columns: repeat(3, 1fr);
501
- max-width: 480px;
502
- }
503
- }
504
-
505
- // 模态框
506
- .modal {
507
- display: flex;
508
- position: fixed;
509
- z-index: 1000;
510
- left: 0;
511
- top: 0;
512
- width: 100%;
513
- height: 100%;
514
- overflow: auto;
515
- background-color: rgba(0, 0, 0, 1);
516
- align-items: center;
517
- justify-content: center;
518
- }
519
-
520
- // 模态框内容(图片)
521
- .modalContent {
522
- position: absolute;
523
- top: 50%;
524
- left: 50%;
525
- transform: translate(-50%, -50%);
526
- max-width: 90%;
527
- max-height: 90%;
528
- cursor: grab;
529
- }
530
-
531
- // 关闭按钮
532
- .close {
533
- position: absolute;
534
- top: 20px;
535
- right: 30px;
536
- color: white;
537
- font-size: 30px;
538
- font-weight: bold;
539
- cursor: pointer;
540
- }
541
- </style>