dsh-timeback 0.7.1 → 0.7.3
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 +19 -6
- package/client.js +878 -47
- package/docs/MARKET.md +2 -2
- package/index.js +30 -0
- package/package.json +1 -1
- package/src/registry.js +59 -0
- package/src/service.js +111 -3
- package/src/snapshots.js +59 -21
package/client.js
CHANGED
|
@@ -23,7 +23,7 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
const REFRESH_MS = 3000
|
|
24
24
|
const MAX_ROWS = 240
|
|
25
25
|
/** Bump together with package.json so a stale browser bundle is obvious. */
|
|
26
|
-
const BUILD = '0.7.
|
|
26
|
+
const BUILD = '0.7.3+sticky'
|
|
27
27
|
/** Set by apply(): opens another Session in the main column. */
|
|
28
28
|
let openSessionBridge = null
|
|
29
29
|
/** Set by apply(): opens the Timeback tab in the right sidebar. */
|
|
@@ -98,6 +98,26 @@ window.__ModuleLoader__.load({
|
|
|
98
98
|
'note.removed': '卡片记录已删除',
|
|
99
99
|
'board.title': '记录板',
|
|
100
100
|
'board.subtitle': '全局 Markdown 记录板 · 回溯时一起恢复',
|
|
101
|
+
'md.bold': '加粗',
|
|
102
|
+
'md.italic': '斜体',
|
|
103
|
+
'md.strike': '删除线',
|
|
104
|
+
'md.inlineCode': '行内代码',
|
|
105
|
+
'md.codeBlock': '代码块',
|
|
106
|
+
'md.heading': '标题',
|
|
107
|
+
'md.bullet': '无序列表',
|
|
108
|
+
'md.numbered': '有序列表',
|
|
109
|
+
'md.task': '任务列表',
|
|
110
|
+
'md.quote': '引用',
|
|
111
|
+
'md.link': '链接',
|
|
112
|
+
'md.hr': '分隔线',
|
|
113
|
+
'md.rich': '富文本',
|
|
114
|
+
'md.source': '源码',
|
|
115
|
+
'md.preview': '预览',
|
|
116
|
+
'md.color': '文字颜色',
|
|
117
|
+
'md.customColor': '自定义',
|
|
118
|
+
'md.linkPrompt': '链接地址',
|
|
119
|
+
'md.empty': '空文档,直接输入即可',
|
|
120
|
+
'md.hint': '直接打字即可:选中文字后点工具栏按钮会立即格式化(例如选中“你好”按 B 立即加粗);也可切换源码/预览。',
|
|
101
121
|
'board.newSticky': '新建便签',
|
|
102
122
|
'board.stickyHint': '便签可拖动;画笔可在方格纸背景或便签上绘制,橡皮擦除笔画。',
|
|
103
123
|
'board.resizeNote': '拖动缩放便签',
|
|
@@ -106,6 +126,9 @@ window.__ModuleLoader__.load({
|
|
|
106
126
|
'board.drawOnStickyOff': '便签可画:关',
|
|
107
127
|
'board.drawOnStickyHint': '开启后画笔/图形可直接画在便签上;关闭则只画在方格纸背景。',
|
|
108
128
|
'board.center': '自动调整',
|
|
129
|
+
'board.zoomIn': '放大画布',
|
|
130
|
+
'board.zoomOut': '缩小画布',
|
|
131
|
+
'board.zoomReset': '重置为 100%',
|
|
109
132
|
'board.reader': '阅读 md',
|
|
110
133
|
'board.close': '关闭',
|
|
111
134
|
'board.toolSelect': '拖动',
|
|
@@ -179,6 +202,13 @@ window.__ModuleLoader__.load({
|
|
|
179
202
|
'panel.workspaceEnabled': '已开启此工作区的自动记录',
|
|
180
203
|
'panel.workspaceDisabled': '已关闭此工作区的自动记录',
|
|
181
204
|
'panel.workspaceStillOn': '操作已提交,但该目录仍被其它记录设置覆盖;请在上方已开启列表里取消对应路径。',
|
|
205
|
+
'panel.selectAllHint': '只记录勾选的文件夹和文件',
|
|
206
|
+
'panel.expandFolder': '展开文件夹',
|
|
207
|
+
'panel.collapseFolder': '收起文件夹',
|
|
208
|
+
'panel.selectedCount': '已选择 {selected} / {total} 项(文件夹包含其内部文件)',
|
|
209
|
+
'panel.selectNothing': '没有选择任何路径,不会创建文件快照',
|
|
210
|
+
'panel.pathsLoading': '正在读取工作区文件…',
|
|
211
|
+
'panel.pathsFailed': '读取工作区文件失败:{error}',
|
|
182
212
|
'panel.emptyNotRecording': '此工作区尚未开启记录。勾选上方的「记录此工作区并保存文件快照」后,之后的回合才会保存检查点。',
|
|
183
213
|
'view.tree': '树视图',
|
|
184
214
|
'view.list': '列表视图',
|
|
@@ -316,6 +346,26 @@ window.__ModuleLoader__.load({
|
|
|
316
346
|
'note.removed': 'Card note deleted',
|
|
317
347
|
'board.title': 'Notes board',
|
|
318
348
|
'board.subtitle': 'Global Markdown notes · rewinds restore them too',
|
|
349
|
+
'md.bold': 'Bold',
|
|
350
|
+
'md.italic': 'Italic',
|
|
351
|
+
'md.strike': 'Strikethrough',
|
|
352
|
+
'md.inlineCode': 'Inline code',
|
|
353
|
+
'md.codeBlock': 'Code block',
|
|
354
|
+
'md.heading': 'Heading',
|
|
355
|
+
'md.bullet': 'Bullet list',
|
|
356
|
+
'md.numbered': 'Numbered list',
|
|
357
|
+
'md.task': 'Task list',
|
|
358
|
+
'md.quote': 'Quote',
|
|
359
|
+
'md.link': 'Link',
|
|
360
|
+
'md.hr': 'Divider',
|
|
361
|
+
'md.rich': 'Rich',
|
|
362
|
+
'md.source': 'Source',
|
|
363
|
+
'md.preview': 'Preview',
|
|
364
|
+
'md.color': 'Text colour',
|
|
365
|
+
'md.customColor': 'Custom',
|
|
366
|
+
'md.linkPrompt': 'Link URL',
|
|
367
|
+
'md.empty': 'Empty document — just start typing',
|
|
368
|
+
'md.hint': 'Type directly: select text and press a toolbar button to format it immediately (e.g. select 你好 and press B). Source and preview tabs are still available.',
|
|
319
369
|
'board.newSticky': 'New sticky',
|
|
320
370
|
'board.stickyHint': 'Sticky notes are draggable; draw on the grid or on a note, erase strokes with the eraser.',
|
|
321
371
|
'board.resizeNote': 'Drag to resize the sticky',
|
|
@@ -324,6 +374,9 @@ window.__ModuleLoader__.load({
|
|
|
324
374
|
'board.drawOnStickyOff': 'Sticky drawing: off',
|
|
325
375
|
'board.drawOnStickyHint': 'When on, pen/shape tools draw directly on sticky notes; when off they only draw on the grid.',
|
|
326
376
|
'board.center': 'Auto fit',
|
|
377
|
+
'board.zoomIn': 'Zoom in',
|
|
378
|
+
'board.zoomOut': 'Zoom out',
|
|
379
|
+
'board.zoomReset': 'Reset to 100%',
|
|
327
380
|
'board.reader': 'Read md',
|
|
328
381
|
'board.close': 'Close',
|
|
329
382
|
'board.toolSelect': 'Move',
|
|
@@ -382,8 +435,8 @@ window.__ModuleLoader__.load({
|
|
|
382
435
|
'guide.boardTitle': 'Notes board',
|
|
383
436
|
'guide.boardDescription': 'Global Markdown notes: write manually or from the session; rewinds roll them back too.',
|
|
384
437
|
'panel.recording': 'Recording',
|
|
385
|
-
'panel.recordThis': '
|
|
386
|
-
'panel.recordThisHint': '
|
|
438
|
+
'panel.recordThis': 'Select all',
|
|
439
|
+
'panel.recordThisHint': 'Check Select all to record the whole workspace; uncheck folders/files below to record only the selected parts.',
|
|
387
440
|
'panel.recordOff': 'Not recording',
|
|
388
441
|
'panel.recordOn': 'Recording',
|
|
389
442
|
'panel.recordAll': 'Plugin config capture=all records every workspace automatically',
|
|
@@ -396,6 +449,20 @@ window.__ModuleLoader__.load({
|
|
|
396
449
|
'panel.disableThis': 'Turn off',
|
|
397
450
|
'panel.workspaceEnabled': 'Recording enabled for this workspace',
|
|
398
451
|
'panel.workspaceDisabled': 'Recording disabled for this workspace',
|
|
452
|
+
'panel.selectAllHint': '只记录勾选的文件夹和文件',
|
|
453
|
+
'panel.expandFolder': '展开文件夹',
|
|
454
|
+
'panel.collapseFolder': '收起文件夹',
|
|
455
|
+
'panel.selectedCount': '已选择 {selected} / {total} 项(文件夹包含其内部文件)',
|
|
456
|
+
'panel.selectNothing': '没有选择任何路径,不会创建文件快照',
|
|
457
|
+
'panel.pathsLoading': '正在读取工作区文件…',
|
|
458
|
+
'panel.pathsFailed': '读取工作区文件失败:{error}',
|
|
459
|
+
'panel.selectAllHint': 'Only selected folders/files are recorded',
|
|
460
|
+
'panel.expandFolder': 'Expand folder',
|
|
461
|
+
'panel.collapseFolder': 'Collapse folder',
|
|
462
|
+
'panel.selectedCount': '{selected} / {total} selected (a folder includes its contents)',
|
|
463
|
+
'panel.selectNothing': 'No paths selected; no file snapshots will be created',
|
|
464
|
+
'panel.pathsLoading': 'Reading workspace files…',
|
|
465
|
+
'panel.pathsFailed': 'Cannot read workspace files: {error}',
|
|
399
466
|
'panel.emptyNotRecording': 'Recording is off for this workspace. Check “Record this workspace and keep file snapshots” above to save checkpoints from later turns.',
|
|
400
467
|
'view.tree': 'Tree',
|
|
401
468
|
'view.list': 'List',
|
|
@@ -488,6 +555,20 @@ window.__ModuleLoader__.load({
|
|
|
488
555
|
.tb-btn.primary{border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff)}
|
|
489
556
|
.tb-btn.danger{border-color:var(--dsw-alias-state-warning-primary,rgba(240,178,62,.5));color:var(--dsw-alias-state-warning-primary,#f0b23e)}
|
|
490
557
|
.tb-body{flex:1;min-height:120px;overflow:auto;padding:10px 12px 28px;display:flex;flex-direction:column;gap:8px}
|
|
558
|
+
.tb-ws-select{display:flex;flex-direction:column;gap:5px;margin:3px 0 4px}
|
|
559
|
+
.tb-ws-master{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--dsw-alias-label-primary,#e6e6e6)}
|
|
560
|
+
.tb-ws-count{font-size:11px;color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
561
|
+
.tb-ws-tree{max-height:230px;overflow:auto;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));border-radius:6px;padding:3px;background:var(--dsw-alias-bg-base,#16181d)}
|
|
562
|
+
.tb-ws-node{display:flex;align-items:center;gap:5px;padding:2px 5px;border-radius:4px;font-size:11.5px;color:var(--dsw-alias-label-primary,#e6e6e6);cursor:pointer;white-space:nowrap;user-select:none}
|
|
563
|
+
.tb-ws-node:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.07))}
|
|
564
|
+
.tb-ws-node.disabled{opacity:.45;cursor:not-allowed}
|
|
565
|
+
.tb-ws-node .tb-ws-folder{opacity:.85}
|
|
566
|
+
.tb-ws-caret{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-secondary,#9aa0a6);width:14px;height:16px;padding:0;font-size:10px;line-height:1;cursor:pointer;flex:0 0 auto}
|
|
567
|
+
.tb-ws-caret:hover{color:var(--dsw-alias-label-primary,#e6e6e6)}
|
|
568
|
+
.tb-ws-caret-space{width:14px;flex:0 0 auto}
|
|
569
|
+
.tb-ws-name{cursor:default}
|
|
570
|
+
.tb-ws-node.dir .tb-ws-name{cursor:pointer}
|
|
571
|
+
.tb-ws{}
|
|
491
572
|
.tb-ws{border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));border-radius:9px;padding:8px 10px;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.03));display:flex;flex-direction:column;gap:6px}
|
|
492
573
|
.tb-ws-row{display:flex;align-items:flex-start;gap:8px;cursor:pointer}
|
|
493
574
|
.tb-ws-row.disabled{cursor:default;opacity:.65}
|
|
@@ -613,7 +694,7 @@ window.__ModuleLoader__.load({
|
|
|
613
694
|
.tb-board-canvas.draw .tb-sticky-resize{cursor:nwse-resize}
|
|
614
695
|
.tb-board-canvas.select:active{cursor:grabbing}
|
|
615
696
|
.tb-board-world{position:relative;flex:none}
|
|
616
|
-
.tb-board-stage{position:absolute;left:0;top:0;transform-origin:0 0;background-color:var(--dsw-alias-bg-base,#16181d);background-image:linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px);background-size:22px 22px,22px 22px,110px 110px,110px 110px}
|
|
697
|
+
.tb-board-stage{position:absolute;left:0;top:0;transform-origin:0 0;will-change:transform;background-color:var(--dsw-alias-bg-base,#16181d);background-image:linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px);background-size:22px 22px,22px 22px,110px 110px,110px 110px}
|
|
617
698
|
.tb-board-bgdraw{position:absolute;left:0;top:0;pointer-events:none;overflow:visible}
|
|
618
699
|
.tb-sticky{position:absolute;width:232px;height:176px;min-width:160px;min-height:120px;box-sizing:border-box;border-radius:5px;padding:8px 9px;display:flex;flex-direction:column;gap:5px;color:#2a2418;box-shadow:0 6px 16px rgba(0,0,0,.28);border:1px solid rgba(0,0,0,.18);overflow:hidden;cursor:grab;user-select:none}
|
|
619
700
|
.tb-sticky:active{cursor:grabbing}
|
|
@@ -642,6 +723,41 @@ window.__ModuleLoader__.load({
|
|
|
642
723
|
.tb-board-md-item-head{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
|
|
643
724
|
.tb-board-md-item-title{font-weight:600;font-size:12px}
|
|
644
725
|
.tb-board-md-empty{padding:10px;text-align:center;color:var(--dsw-alias-label-secondary,#9aa0a6);font-size:12px}
|
|
726
|
+
.tb-md-rich{flex:1;min-height:0;overflow:auto;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));border-radius:8px;padding:10px 12px;font-size:15px;line-height:1.65;color:var(--dsw-alias-label-primary,#e6e6e6);background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.04));outline:none;box-sizing:border-box}
|
|
727
|
+
.tb-md-rich:empty:before{content:attr(data-placeholder);color:var(--dsw-alias-label-tertiary,#8a919c)}
|
|
728
|
+
.tb-md-rich h1,.tb-md-rich h2,.tb-md-rich h3,.tb-md-rich h4,.tb-md-rich h5,.tb-md-rich h6{margin:10px 0 5px;line-height:1.35}
|
|
729
|
+
.tb-md-rich h1{font-size:23px}.tb-md-rich h2{font-size:20px}.tb-md-rich h3{font-size:18px}.tb-md-rich h4{font-size:16px}.tb-md-rich h5{font-size:15px}.tb-md-rich h6{font-size:14px}
|
|
730
|
+
.tb-md-rich p{margin:5px 0}
|
|
731
|
+
.tb-md-rich ul,.tb-md-rich ol{margin:5px 0;padding-left:22px}
|
|
732
|
+
.tb-md-rich blockquote{margin:6px 0;padding:2px 10px;border-left:3px solid var(--dsw-alias-border-l2,rgba(255,255,255,.3));color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
733
|
+
.tb-md-rich pre{margin:7px 0;padding:9px 11px;border-radius:7px;background:rgba(0,0,0,.35);font-size:13px;line-height:1.55;overflow:auto}
|
|
734
|
+
.tb-md-rich code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;background:rgba(255,255,255,.08);border-radius:4px;padding:0 3px;font-size:13.5px}
|
|
735
|
+
.tb-md-rich pre code{background:transparent;padding:0}
|
|
736
|
+
.tb-md-rich hr{border:0;border-top:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.2));margin:10px 0}
|
|
737
|
+
.tb-md-rich a{color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff)}
|
|
738
|
+
.tb-md-readonly{flex:1;min-height:0;overflow:auto;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));border-radius:8px;padding:12px 14px;background:var(--dsw-alias-bg-base,#16181d)}
|
|
739
|
+
.tb-md-color{width:21px;height:21px;padding:0;border-radius:4px;border:1px solid rgba(255,255,255,.32);cursor:pointer;flex:0 0 auto}
|
|
740
|
+
.tb-md-color:hover{transform:scale(1.12)}
|
|
741
|
+
.tb-md-color-custom{margin-left:auto;display:flex;align-items:center;gap:4px;flex:0 0 auto}
|
|
742
|
+
.tb-md-color-input{width:30px;height:24px;min-width:30px;box-sizing:border-box;padding:2px;border:1px solid rgba(255,255,255,.28);border-radius:5px;background:rgba(255,255,255,.04);cursor:pointer;flex:0 0 auto}
|
|
743
|
+
.tb-md-editor{display:flex;flex-direction:column;gap:6px;flex:1;min-height:0}
|
|
744
|
+
.tb-md-toolbar{display:flex;align-items:flex-start;gap:6px;flex-wrap:wrap;padding:5px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));border-radius:8px;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.03))}
|
|
745
|
+
.tb-md-tools{display:flex;align-items:center;gap:3px;flex-wrap:wrap;flex:1;min-width:0}
|
|
746
|
+
.tb-md-tool{appearance:none;border:1px solid transparent;background:transparent;color:var(--dsw-alias-label-secondary,#c3c9d2);border-radius:5px;min-width:30px;height:28px;padding:0 8px;font-size:13px;line-height:1;cursor:pointer;white-space:nowrap;flex:0 0 auto}
|
|
747
|
+
.tb-md-tool:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.1));color:var(--dsw-alias-label-primary,#e6e6e6)}
|
|
748
|
+
.tb-md-tool.on{color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff);border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
|
|
749
|
+
.tb-md-mode{margin-left:auto;display:flex;gap:2px;flex:0 0 auto}
|
|
750
|
+
.tb-md-colorbar{display:flex;align-items:center;gap:5px;flex-wrap:nowrap;overflow:hidden;padding:3px 5px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.10));border-radius:7px;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.02))}
|
|
751
|
+
.tb-md-color-label{font-size:12px;color:var(--dsw-alias-label-secondary,#9aa0a6);margin-right:1px}
|
|
752
|
+
.tb-md-body{display:flex;gap:8px;flex:1;min-height:0;overflow:hidden}
|
|
753
|
+
.tb-md-source{flex:1;min-width:0;resize:none;box-sizing:border-box;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.04));color:var(--dsw-alias-label-primary,#e6e6e6);border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));border-radius:8px;padding:10px 12px;font-size:14px;line-height:1.7;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
|
754
|
+
.tb-md-preview{flex:1;min-width:0;overflow:auto;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));border-radius:8px;padding:8px 10px;background:var(--dsw-alias-bg-base,#16181d)}
|
|
755
|
+
.tb-md-block{padding:3px 7px 5px;border-left:2px solid transparent;border-radius:5px;margin-bottom:5px;cursor:text}
|
|
756
|
+
.tb-md-block:hover{background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.04))}
|
|
757
|
+
.tb-md-block.active{border-left-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.06))}
|
|
758
|
+
.tb-md-line{display:block;font-size:10px;line-height:1.4;color:var(--dsw-alias-label-tertiary,#8a919c);margin-bottom:1px}
|
|
759
|
+
.tb-md-empty{padding:12px;text-align:center;color:var(--dsw-alias-label-secondary,#9aa0a6);font-size:13px}
|
|
760
|
+
@media (max-width: 760px){.tb-md-body{flex-direction:column}}
|
|
645
761
|
.tb-board-panel{display:flex;flex-direction:column;height:100%;min-height:100%;width:100%;font-size:12.5px;color:var(--dsw-alias-label-primary,#e6e6e6);background:var(--dsw-alias-bg-base,#16181d)}
|
|
646
762
|
.tb-board-head{display:flex;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.1));flex-wrap:wrap}
|
|
647
763
|
.tb-board-title{font-weight:600;font-size:13.5px}
|
|
@@ -654,17 +770,17 @@ window.__ModuleLoader__.load({
|
|
|
654
770
|
.tb-board-note-title{font-weight:600;font-size:12.5px;word-break:break-word}
|
|
655
771
|
.tb-board-meta{font-size:10.5px;color:var(--dsw-alias-label-tertiary,#8a919c);white-space:nowrap}
|
|
656
772
|
.tb-board-actions{margin-left:auto;display:flex;gap:4px;flex-wrap:wrap}
|
|
657
|
-
.tb-md{font-size:
|
|
773
|
+
.tb-md{font-size:14.5px;line-height:1.75;color:var(--dsw-alias-label-primary,#d7dbe2);word-break:break-word}
|
|
658
774
|
.tb-md>*:first-child{margin-top:0}
|
|
659
775
|
.tb-md>*:last-child{margin-bottom:0}
|
|
660
|
-
.tb-md h1,.tb-md h2,.tb-md h3,.tb-md h4,.tb-md h5,.tb-md h6{margin:
|
|
661
|
-
.tb-md h1{font-size:
|
|
662
|
-
.tb-md p{margin:
|
|
663
|
-
.tb-md ul,.tb-md ol{margin:
|
|
664
|
-
.tb-md li{margin:
|
|
776
|
+
.tb-md h1,.tb-md h2,.tb-md h3,.tb-md h4,.tb-md h5,.tb-md h6{margin:12px 0 6px;line-height:1.35;font-weight:700}
|
|
777
|
+
.tb-md h1{font-size:24px}.tb-md h2{font-size:21px}.tb-md h3{font-size:18.5px}.tb-md h4{font-size:16.5px}.tb-md h5{font-size:15px}.tb-md h6{font-size:14px;color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
778
|
+
.tb-md p{margin:7px 0}
|
|
779
|
+
.tb-md ul,.tb-md ol{margin:7px 0;padding-left:24px}
|
|
780
|
+
.tb-md li{margin:4px 0}
|
|
665
781
|
.tb-md blockquote{margin:6px 0;padding:2px 10px;border-left:3px solid var(--dsw-alias-border-l2,rgba(255,255,255,.24));color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
666
|
-
.tb-md code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:
|
|
667
|
-
.tb-md pre{margin:
|
|
782
|
+
.tb-md code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.08));border-radius:4px;padding:1px 4px}
|
|
783
|
+
.tb-md pre{margin:9px 0;padding:10px 12px;font-size:13px;line-height:1.6;border-radius:7px;background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.28));overflow:auto;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.1))}
|
|
668
784
|
.tb-md pre code{background:transparent;padding:0}
|
|
669
785
|
.tb-md a{color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff)}
|
|
670
786
|
.tb-md hr{border:0;border-top:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));margin:8px 0}
|
|
@@ -793,7 +909,7 @@ window.__ModuleLoader__.load({
|
|
|
793
909
|
/** Parse inline Markdown (bold/italic/code/link) into React children. */
|
|
794
910
|
function inlineMarkdown(text, keyPrefix) {
|
|
795
911
|
const nodes = []
|
|
796
|
-
const pattern = /(
|
|
912
|
+
const pattern = /(<span style="color:\s*#[0-9a-f]{3,8}\s*">[\s\S]*?<\/span>|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|\*[^*\n]+\*|_[^\n_]+_)/g
|
|
797
913
|
let last = 0
|
|
798
914
|
let match
|
|
799
915
|
let index = 0
|
|
@@ -801,7 +917,11 @@ window.__ModuleLoader__.load({
|
|
|
801
917
|
if (match.index > last) nodes.push(text.slice(last, match.index))
|
|
802
918
|
const token = match[0]
|
|
803
919
|
const key = `${keyPrefix}-i${index++}`
|
|
804
|
-
if (token.startsWith('
|
|
920
|
+
if (token.startsWith('<span')) {
|
|
921
|
+
const match = /^<span style="color:\s*(#[0-9a-f]{3,8})\s*">([\s\S]*?)<\/span>$/i.exec(token)
|
|
922
|
+
if (match) nodes.push(h('span', { key, style: { color: match[1] } }, ...inlineMarkdown(match[2], `${keyPrefix}-c${index}`)))
|
|
923
|
+
else nodes.push(token)
|
|
924
|
+
} else if (token.startsWith('`')) nodes.push(h('code', { key }, token.slice(1, -1)))
|
|
805
925
|
else if (token.startsWith('**') || token.startsWith('__')) nodes.push(h('strong', { key }, token.slice(2, -2)))
|
|
806
926
|
else if (token.startsWith('[')) {
|
|
807
927
|
const link = /^\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)$/.exec(token)
|
|
@@ -2324,7 +2444,7 @@ window.__ModuleLoader__.load({
|
|
|
2324
2444
|
),
|
|
2325
2445
|
)
|
|
2326
2446
|
: null,
|
|
2327
|
-
renderWorkspaceSection({ workspace: data?.workspace, gitOff, busy, t, toggleWorkspace }),
|
|
2447
|
+
renderWorkspaceSection({ workspace: data?.workspace, gitOff, busy, t, toggleWorkspace, sessionId, onWorkspaceChanged: () => setTick((value) => value + 1) }),
|
|
2328
2448
|
gitOff ? h('p', { className: 'tb-note' }, t('panel.noGit')) : h('p', { className: 'tb-note' }, t('panel.warning')),
|
|
2329
2449
|
state.error ? h('div', { className: 'tb-feedback err', role: 'alert' }, `${t('panel.error')}: ${state.error}`) : null,
|
|
2330
2450
|
state.loading && !data ? h('div', { className: 'tb-empty' }, t('panel.loading')) : null,
|
|
@@ -2431,11 +2551,12 @@ window.__ModuleLoader__.load({
|
|
|
2431
2551
|
h('button', { type: 'button', className: 'tb-btn', disabled: noteEditor.busy, onClick: () => setNoteEditor(null) }, t('note.cancel')),
|
|
2432
2552
|
),
|
|
2433
2553
|
h('div', { className: 'tb-ws-hint' }, t('note.hint')),
|
|
2434
|
-
h(
|
|
2554
|
+
h(MarkdownEditor, {
|
|
2435
2555
|
value: noteEditor.text,
|
|
2436
|
-
|
|
2556
|
+
onChange: (next) => setNoteEditor({ ...noteEditor, text: next }),
|
|
2557
|
+
t,
|
|
2437
2558
|
disabled: noteEditor.busy,
|
|
2438
|
-
|
|
2559
|
+
placeholder: t('note.placeholder'),
|
|
2439
2560
|
}),
|
|
2440
2561
|
noteEditor.error ? h('div', { className: 'tb-feedback err' }, noteEditor.error) : null,
|
|
2441
2562
|
h(
|
|
@@ -2452,8 +2573,202 @@ window.__ModuleLoader__.load({
|
|
|
2452
2573
|
)
|
|
2453
2574
|
}
|
|
2454
2575
|
|
|
2576
|
+
/** 全选 + folder/file checkbox selector for per-workspace snapshots. */
|
|
2577
|
+
function WorkspacePathSelector(props) {
|
|
2578
|
+
const t = typeof props?.t === 'function' ? props.t : (key) => key
|
|
2579
|
+
const sessionId = typeof props?.sessionId === 'string' ? props.sessionId : ''
|
|
2580
|
+
const workspace = props?.workspace || null
|
|
2581
|
+
const cwd = workspace?.cwd || ''
|
|
2582
|
+
const [state, setState] = React.useState({ loading: true, entries: [], excludePaths: [], error: '', saving: false })
|
|
2583
|
+
const [expanded, setExpanded] = React.useState({})
|
|
2584
|
+
const masterRef = React.useRef(null)
|
|
2585
|
+
const workspaceEnabled = workspace?.enabled === true
|
|
2586
|
+
const selectable = workspace?.mode === 'workspace' && workspace?.exists !== false && Boolean(cwd)
|
|
2587
|
+
|
|
2588
|
+
const load = async () => {
|
|
2589
|
+
if (!sessionId && !cwd) return
|
|
2590
|
+
setState((previous) => ({ ...previous, loading: true, error: '' }))
|
|
2591
|
+
try {
|
|
2592
|
+
const body = await request('action', {
|
|
2593
|
+
method: 'POST',
|
|
2594
|
+
body: { action: 'workspace-tree', ...(sessionId ? { sessionId } : {}), ...(cwd ? { cwd } : {}) },
|
|
2595
|
+
})
|
|
2596
|
+
setState({
|
|
2597
|
+
loading: false,
|
|
2598
|
+
entries: Array.isArray(body.entries) ? body.entries : [],
|
|
2599
|
+
excludePaths: Array.isArray(body.excludePaths) ? body.excludePaths : [],
|
|
2600
|
+
error: '',
|
|
2601
|
+
saving: false,
|
|
2602
|
+
})
|
|
2603
|
+
} catch (error) {
|
|
2604
|
+
setState((previous) => ({ ...previous, loading: false, error: error?.message || String(error) }))
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
React.useEffect(() => {
|
|
2609
|
+
load()
|
|
2610
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2611
|
+
}, [sessionId, cwd, workspaceEnabled])
|
|
2612
|
+
|
|
2613
|
+
React.useEffect(() => {
|
|
2614
|
+
if (!masterRef.current) return
|
|
2615
|
+
const excluded = (entry) => state.excludePaths.some((value) => entry.path === value || entry.path.startsWith(`${value}/`))
|
|
2616
|
+
const selected = state.entries.filter((entry) => !excluded(entry)).length
|
|
2617
|
+
masterRef.current.indeterminate = workspaceEnabled && state.excludePaths.length > 0 && selected > 0
|
|
2618
|
+
}, [state.excludePaths, state.entries, workspaceEnabled])
|
|
2619
|
+
|
|
2620
|
+
const savePaths = async (excludePaths) => {
|
|
2621
|
+
if (state.saving) return
|
|
2622
|
+
setState((previous) => ({ ...previous, saving: true, error: '' }))
|
|
2623
|
+
try {
|
|
2624
|
+
const body = await request('action', {
|
|
2625
|
+
method: 'POST',
|
|
2626
|
+
body: {
|
|
2627
|
+
action: 'set-workspace-paths',
|
|
2628
|
+
...(sessionId ? { sessionId } : {}),
|
|
2629
|
+
...(cwd ? { cwd } : {}),
|
|
2630
|
+
excludePaths,
|
|
2631
|
+
},
|
|
2632
|
+
})
|
|
2633
|
+
const nextExcludes = Array.isArray(body.workspace?.excludePaths) ? body.workspace.excludePaths : excludePaths
|
|
2634
|
+
setState((previous) => ({ ...previous, excludePaths: nextExcludes, saving: false }))
|
|
2635
|
+
if (typeof props?.onChanged === 'function') props.onChanged(body.workspace)
|
|
2636
|
+
} catch (error) {
|
|
2637
|
+
setState((previous) => ({ ...previous, saving: false, error: error?.message || String(error) }))
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
const setEnabled = async (enabled) => {
|
|
2642
|
+
if (state.saving) return
|
|
2643
|
+
setState((previous) => ({ ...previous, saving: true, error: '' }))
|
|
2644
|
+
try {
|
|
2645
|
+
await request('action', {
|
|
2646
|
+
method: 'POST',
|
|
2647
|
+
body: {
|
|
2648
|
+
action: 'set-workspace',
|
|
2649
|
+
...(sessionId ? { sessionId } : {}),
|
|
2650
|
+
...(cwd ? { cwd } : {}),
|
|
2651
|
+
enabled,
|
|
2652
|
+
},
|
|
2653
|
+
})
|
|
2654
|
+
if (enabled) {
|
|
2655
|
+
await savePaths([])
|
|
2656
|
+
} else {
|
|
2657
|
+
setState((previous) => ({ ...previous, saving: false }))
|
|
2658
|
+
if (typeof props?.onChanged === 'function') props.onChanged(null)
|
|
2659
|
+
}
|
|
2660
|
+
} catch (error) {
|
|
2661
|
+
setState((previous) => ({ ...previous, saving: false, error: error?.message || String(error) }))
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
|
|
2665
|
+
const toggleEntry = async (entry, checked) => {
|
|
2666
|
+
if (state.excludePaths.includes(entry.path)) {
|
|
2667
|
+
await savePaths(state.excludePaths.filter((value) => value !== entry.path))
|
|
2668
|
+
} else {
|
|
2669
|
+
const next = state.excludePaths
|
|
2670
|
+
.filter((value) => value !== entry.path && !value.startsWith(`${entry.path}/`))
|
|
2671
|
+
.concat(checked ? [] : [entry.path])
|
|
2672
|
+
await savePaths(next)
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2676
|
+
const toggleExpand = (folderPath) => {
|
|
2677
|
+
setExpanded((previous) => ({ ...previous, [folderPath]: !previous[folderPath] }))
|
|
2678
|
+
}
|
|
2679
|
+
const hiddenByCollapse = (entry) => {
|
|
2680
|
+
const segments = entry.path.split('/')
|
|
2681
|
+
for (let index = 1; index < segments.length; index += 1) {
|
|
2682
|
+
const ancestor = segments.slice(0, index).join('/')
|
|
2683
|
+
if (!expanded[ancestor]) return true
|
|
2684
|
+
}
|
|
2685
|
+
return false
|
|
2686
|
+
}
|
|
2687
|
+
const visibleEntries = state.entries.filter((entry) => !hiddenByCollapse(entry))
|
|
2688
|
+
const entries = state.entries
|
|
2689
|
+
const excludes = state.excludePaths
|
|
2690
|
+
const excludedByAncestor = (entry) => excludes.some((value) => entry.path.startsWith(`${value}/`))
|
|
2691
|
+
const selectedCount = entries.filter((entry) => !excludedByAncestor(entry) && !excludes.includes(entry.path)).length
|
|
2692
|
+
const masterDisabled = !selectable || state.loading || state.saving
|
|
2693
|
+
return h(
|
|
2694
|
+
'div',
|
|
2695
|
+
{ className: 'tb-ws-select' },
|
|
2696
|
+
h(
|
|
2697
|
+
'label',
|
|
2698
|
+
{ className: 'tb-ws-master' },
|
|
2699
|
+
h('input', {
|
|
2700
|
+
ref: masterRef,
|
|
2701
|
+
type: 'checkbox',
|
|
2702
|
+
checked: workspaceEnabled && excludes.length === 0,
|
|
2703
|
+
disabled: masterDisabled,
|
|
2704
|
+
'aria-label': t('panel.recordThis'),
|
|
2705
|
+
onChange: (event) => setEnabled(event.target.checked),
|
|
2706
|
+
}),
|
|
2707
|
+
h('span', null, t('panel.recordThis')),
|
|
2708
|
+
h('span', { className: 'tb-ws-count' }, t('panel.selectAllHint')),
|
|
2709
|
+
),
|
|
2710
|
+
state.loading
|
|
2711
|
+
? h('span', { className: 'tb-ws-hint' }, t('panel.pathsLoading'))
|
|
2712
|
+
: state.error
|
|
2713
|
+
? h('span', { className: 'tb-ws-hint err' }, format(t('panel.pathsFailed'), { error: state.error }))
|
|
2714
|
+
: [
|
|
2715
|
+
h(
|
|
2716
|
+
'span',
|
|
2717
|
+
{ className: 'tb-ws-count' },
|
|
2718
|
+
format(t('panel.selectedCount'), { selected: selectedCount, total: entries.length }),
|
|
2719
|
+
workspaceEnabled && selectedCount === 0 ? ` · ${t('panel.selectNothing')}` : '',
|
|
2720
|
+
),
|
|
2721
|
+
h(
|
|
2722
|
+
'div',
|
|
2723
|
+
{ className: 'tb-ws-tree' },
|
|
2724
|
+
...visibleEntries.map((entry) => {
|
|
2725
|
+
const inherited = excludedByAncestor(entry)
|
|
2726
|
+
const excluded = excludes.includes(entry.path)
|
|
2727
|
+
const checked = !inherited && !excluded
|
|
2728
|
+
const disabled = inherited || !workspaceEnabled || state.saving
|
|
2729
|
+
const depth = entry.path.split('/').length - 1
|
|
2730
|
+
const isDir = entry.type === 'dir'
|
|
2731
|
+
const open = expanded[entry.path] === true
|
|
2732
|
+
return h(
|
|
2733
|
+
'div',
|
|
2734
|
+
{ key: entry.path, className: `tb-ws-node${isDir ? ' dir' : ''}${disabled ? ' disabled' : ''}`, title: entry.path, style: { paddingLeft: 5 + depth * 14 } },
|
|
2735
|
+
isDir
|
|
2736
|
+
? h(
|
|
2737
|
+
'button',
|
|
2738
|
+
{
|
|
2739
|
+
type: 'button',
|
|
2740
|
+
className: 'tb-ws-caret',
|
|
2741
|
+
title: open ? t('panel.collapseFolder') : t('panel.expandFolder'),
|
|
2742
|
+
'aria-expanded': open,
|
|
2743
|
+
onClick: () => toggleExpand(entry.path),
|
|
2744
|
+
},
|
|
2745
|
+
open ? '▾' : '▸',
|
|
2746
|
+
)
|
|
2747
|
+
: h('span', { className: 'tb-ws-caret-space' }),
|
|
2748
|
+
h('input', {
|
|
2749
|
+
type: 'checkbox',
|
|
2750
|
+
checked,
|
|
2751
|
+
disabled,
|
|
2752
|
+
onChange: (event) => toggleEntry(entry, event.target.checked),
|
|
2753
|
+
}),
|
|
2754
|
+
h('span', { className: 'tb-ws-folder' }, isDir ? '📁' : '📄'),
|
|
2755
|
+
h(
|
|
2756
|
+
'span',
|
|
2757
|
+
{
|
|
2758
|
+
className: 'tb-ws-name',
|
|
2759
|
+
onClick: isDir ? () => toggleExpand(entry.path) : undefined,
|
|
2760
|
+
},
|
|
2761
|
+
entry.path,
|
|
2762
|
+
),
|
|
2763
|
+
)
|
|
2764
|
+
}),
|
|
2765
|
+
),
|
|
2766
|
+
],
|
|
2767
|
+
)
|
|
2768
|
+
}
|
|
2769
|
+
|
|
2455
2770
|
/** Draw the per-workspace recording switch and the enabled-workspace list. */
|
|
2456
|
-
function renderWorkspaceSection({ workspace, gitOff, busy, t, toggleWorkspace }) {
|
|
2771
|
+
function renderWorkspaceSection({ workspace, gitOff, busy, t, toggleWorkspace, sessionId, onWorkspaceChanged }) {
|
|
2457
2772
|
if (!workspace) return null
|
|
2458
2773
|
const cwd = workspace.cwd
|
|
2459
2774
|
const mode = workspace.mode
|
|
@@ -2472,17 +2787,8 @@ window.__ModuleLoader__.load({
|
|
|
2472
2787
|
'div',
|
|
2473
2788
|
{ className: 'tb-ws' },
|
|
2474
2789
|
h(
|
|
2475
|
-
'
|
|
2476
|
-
{ className:
|
|
2477
|
-
h('input', {
|
|
2478
|
-
type: 'checkbox',
|
|
2479
|
-
checked,
|
|
2480
|
-
disabled: !canToggle,
|
|
2481
|
-
'aria-label': t('panel.recordThis'),
|
|
2482
|
-
onChange: (event) => {
|
|
2483
|
-
if (canToggle) toggleWorkspace(event.target.checked)
|
|
2484
|
-
},
|
|
2485
|
-
}),
|
|
2790
|
+
'div',
|
|
2791
|
+
{ className: 'tb-ws-row', title: reason },
|
|
2486
2792
|
h(
|
|
2487
2793
|
'span',
|
|
2488
2794
|
{ className: 'tb-ws-text' },
|
|
@@ -2491,6 +2797,14 @@ window.__ModuleLoader__.load({
|
|
|
2491
2797
|
h('span', { className: 'tb-ws-hint' }, reason),
|
|
2492
2798
|
),
|
|
2493
2799
|
),
|
|
2800
|
+
mode === 'workspace' && cwd
|
|
2801
|
+
? h(WorkspacePathSelector, {
|
|
2802
|
+
sessionId,
|
|
2803
|
+
workspace,
|
|
2804
|
+
t,
|
|
2805
|
+
onChanged: typeof onWorkspaceChanged === 'function' ? onWorkspaceChanged : undefined,
|
|
2806
|
+
})
|
|
2807
|
+
: null,
|
|
2494
2808
|
mode === 'workspace' && workspace.enabledWorkspaces?.length > 0
|
|
2495
2809
|
? h(
|
|
2496
2810
|
'div',
|
|
@@ -3052,6 +3366,453 @@ window.__ModuleLoader__.load({
|
|
|
3052
3366
|
}
|
|
3053
3367
|
}
|
|
3054
3368
|
|
|
3369
|
+
function escapeHtmlText(text) {
|
|
3370
|
+
return String(text ?? '')
|
|
3371
|
+
.replace(/&/g, '&')
|
|
3372
|
+
.replace(/</g, '<')
|
|
3373
|
+
.replace(/>/g, '>')
|
|
3374
|
+
.replace(/"/g, '"')
|
|
3375
|
+
}
|
|
3376
|
+
|
|
3377
|
+
/** Inline Markdown -> HTML for the rich editor. */
|
|
3378
|
+
function inlineMarkdownToHtml(text) {
|
|
3379
|
+
const pattern = /(<span style="color:\s*#[0-9a-f]{3,8}\s*">[\s\S]*?<\/span>|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|~~[^~]+~~|\*[^*\n]+\*|_[^_\n]+_)/g
|
|
3380
|
+
let html = ''
|
|
3381
|
+
let last = 0
|
|
3382
|
+
let match
|
|
3383
|
+
while ((match = pattern.exec(text)) !== null) {
|
|
3384
|
+
html += escapeHtmlText(text.slice(last, match.index))
|
|
3385
|
+
const token = match[0]
|
|
3386
|
+
if (token.startsWith('<span')) {
|
|
3387
|
+
const span = /^<span style="color:\s*(#[0-9a-f]{3,8})\s*">([\s\S]*?)<\/span>$/i.exec(token)
|
|
3388
|
+
html += span
|
|
3389
|
+
? `<span style="color:${span[1].toLowerCase()}">${inlineMarkdownToHtml(span[2])}</span>`
|
|
3390
|
+
: escapeHtmlText(token)
|
|
3391
|
+
} else if (token.startsWith('**') || token.startsWith('__')) {
|
|
3392
|
+
html += `<strong>${inlineMarkdownToHtml(token.slice(2, -2))}</strong>`
|
|
3393
|
+
} else if (token.startsWith('~~')) {
|
|
3394
|
+
html += `<del>${inlineMarkdownToHtml(token.slice(2, -2))}</del>`
|
|
3395
|
+
} else if (token.startsWith('`')) {
|
|
3396
|
+
html += `<code>${escapeHtmlText(token.slice(1, -1))}</code>`
|
|
3397
|
+
} else if (token.startsWith('[')) {
|
|
3398
|
+
const link = /^\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)$/.exec(token)
|
|
3399
|
+
html += link ? `<a href="${escapeHtmlText(link[2])}">${inlineMarkdownToHtml(link[1])}</a>` : escapeHtmlText(token)
|
|
3400
|
+
} else {
|
|
3401
|
+
html += `<em>${inlineMarkdownToHtml(token.slice(1, -1))}</em>`
|
|
3402
|
+
}
|
|
3403
|
+
last = match.index + token.length
|
|
3404
|
+
}
|
|
3405
|
+
return html + escapeHtmlText(text.slice(last))
|
|
3406
|
+
}
|
|
3407
|
+
|
|
3408
|
+
/** Markdown document -> editable HTML for the WYSIWYG editor. */
|
|
3409
|
+
function markdownToEditorHtml(markdown) {
|
|
3410
|
+
const lines = String(markdown ?? '').replace(/\r\n?/g, '\n').split('\n')
|
|
3411
|
+
const out = []
|
|
3412
|
+
let index = 0
|
|
3413
|
+
while (index < lines.length) {
|
|
3414
|
+
const line = lines[index]
|
|
3415
|
+
if (/^\s*$/.test(line)) {
|
|
3416
|
+
index += 1
|
|
3417
|
+
continue
|
|
3418
|
+
}
|
|
3419
|
+
const fence = /^```(\w*)\s*$/.exec(line)
|
|
3420
|
+
if (fence) {
|
|
3421
|
+
const code = []
|
|
3422
|
+
index += 1
|
|
3423
|
+
while (index < lines.length && !/^```\s*$/.test(lines[index])) {
|
|
3424
|
+
code.push(lines[index])
|
|
3425
|
+
index += 1
|
|
3426
|
+
}
|
|
3427
|
+
index += 1
|
|
3428
|
+
out.push(`<pre><code>${escapeHtmlText(code.join('\n'))}</code></pre>`)
|
|
3429
|
+
continue
|
|
3430
|
+
}
|
|
3431
|
+
const heading = /^(#{1,6})\s+(.*)$/.exec(line)
|
|
3432
|
+
if (heading) {
|
|
3433
|
+
out.push(`<h${heading[1].length}>${inlineMarkdownToHtml(heading[2])}</h${heading[1].length}>`)
|
|
3434
|
+
index += 1
|
|
3435
|
+
continue
|
|
3436
|
+
}
|
|
3437
|
+
if (/^\s*([-*_])\s*\1\s*\1[\s\S]*$/.test(line)) {
|
|
3438
|
+
out.push('<hr>')
|
|
3439
|
+
index += 1
|
|
3440
|
+
continue
|
|
3441
|
+
}
|
|
3442
|
+
if (/^>\s?/.test(line)) {
|
|
3443
|
+
const quote = []
|
|
3444
|
+
while (index < lines.length && /^>\s?/.test(lines[index])) {
|
|
3445
|
+
quote.push(lines[index].replace(/^>\s?/, ''))
|
|
3446
|
+
index += 1
|
|
3447
|
+
}
|
|
3448
|
+
out.push(`<blockquote>${markdownToEditorHtml(quote.join('\n'))}</blockquote>`)
|
|
3449
|
+
continue
|
|
3450
|
+
}
|
|
3451
|
+
const bullet = /^\s*[-*+]\s+(.*)$/.exec(line)
|
|
3452
|
+
const numbered = /^\s*\d+[.)]\s+(.*)$/.exec(line)
|
|
3453
|
+
if (bullet || numbered) {
|
|
3454
|
+
const ordered = Boolean(numbered)
|
|
3455
|
+
const items = []
|
|
3456
|
+
while (index < lines.length) {
|
|
3457
|
+
const current = ordered ? /^\s*\d+[.)]\s+(.*)$/.exec(lines[index]) : /^\s*[-*+]\s+(.*)$/.exec(lines[index])
|
|
3458
|
+
if (!current) break
|
|
3459
|
+
items.push(`<li>${inlineMarkdownToHtml(current[1])}</li>`)
|
|
3460
|
+
index += 1
|
|
3461
|
+
}
|
|
3462
|
+
out.push(ordered ? `<ol>${items.join('')}</ol>` : `<ul>${items.join('')}</ul>`)
|
|
3463
|
+
continue
|
|
3464
|
+
}
|
|
3465
|
+
const paragraph = []
|
|
3466
|
+
while (index < lines.length) {
|
|
3467
|
+
const candidate = lines[index]
|
|
3468
|
+
if (/^\s*$/.test(candidate)) break
|
|
3469
|
+
if (/^```/.test(candidate) || /^(#{1,6})\s+/.test(candidate) || /^>\s?/.test(candidate) || /^\s*[-*+]\s+/.test(candidate) || /^\s*\d+[.)]\s+/.test(candidate) || /^\s*([-*_])\s*\1\s*\1[\s\S]*$/.test(candidate)) break
|
|
3470
|
+
paragraph.push(candidate)
|
|
3471
|
+
index += 1
|
|
3472
|
+
}
|
|
3473
|
+
out.push(`<p>${paragraph.map((item) => inlineMarkdownToHtml(item)).join('<br>')}</p>`)
|
|
3474
|
+
}
|
|
3475
|
+
return out.join('')
|
|
3476
|
+
}
|
|
3477
|
+
|
|
3478
|
+
/** DOM -> Markdown serializer used by the WYSIWYG editor. */
|
|
3479
|
+
function domToMarkdown(root) {
|
|
3480
|
+
const childrenOf = (node) => (node && node.childNodes ? Array.from(node.childNodes) : [])
|
|
3481
|
+
const tagOf = (node) => String(node?.tagName || node?.nodeName || '').toUpperCase()
|
|
3482
|
+
const colorOf = (node) => {
|
|
3483
|
+
if (!node) return ''
|
|
3484
|
+
const style = node.style
|
|
3485
|
+
if (style) {
|
|
3486
|
+
if (typeof style === 'string') {
|
|
3487
|
+
const match = /color:\s*(#[0-9a-f]{3,8})/i.exec(style)
|
|
3488
|
+
if (match) return match[1].toLowerCase()
|
|
3489
|
+
} else if (typeof style.color === 'string') {
|
|
3490
|
+
return /^#[0-9a-f]{3,8}$/i.test(style.color) ? style.color.toLowerCase() : ''
|
|
3491
|
+
}
|
|
3492
|
+
}
|
|
3493
|
+
const attr = node.getAttribute ? node.getAttribute('color') : ''
|
|
3494
|
+
return /^#[0-9a-f]{3,8}$/i.test(String(attr || '')) ? String(attr).toLowerCase() : ''
|
|
3495
|
+
}
|
|
3496
|
+
const inline = (node) => {
|
|
3497
|
+
if (!node) return ''
|
|
3498
|
+
if (node.nodeType === 3) return String(node.nodeValue ?? '')
|
|
3499
|
+
const tag = tagOf(node)
|
|
3500
|
+
const inner = () => childrenOf(node).map(inline).join('')
|
|
3501
|
+
if (tag === 'BR') return '\n'
|
|
3502
|
+
if (tag === 'STRONG' || tag === 'B') return `**${inner()}**`
|
|
3503
|
+
if (tag === 'EM' || tag === 'I') return `*${inner()}*`
|
|
3504
|
+
if (tag === 'DEL' || tag === 'S' || tag === 'STRIKE') return `~~${inner()}~~`
|
|
3505
|
+
if (tag === 'CODE') return `\`${inner()}\``
|
|
3506
|
+
if (tag === 'A') return `[${inner()}](${node.getAttribute ? node.getAttribute('href') || '' : ''})`
|
|
3507
|
+
if (tag === 'IMG') return ` || '' : ''})`
|
|
3508
|
+
const color = colorOf(node)
|
|
3509
|
+
if (color && (tag === 'SPAN' || tag === 'FONT')) return `<span style="color:${color}">${inner()}</span>`
|
|
3510
|
+
return inner()
|
|
3511
|
+
}
|
|
3512
|
+
const inlineOf = (node) => childrenOf(node).map(inline).join('')
|
|
3513
|
+
const block = (node) => {
|
|
3514
|
+
if (!node) return ''
|
|
3515
|
+
if (node.nodeType === 3) return String(node.nodeValue ?? '')
|
|
3516
|
+
const tag = tagOf(node)
|
|
3517
|
+
if (/^H[1-6]$/.test(tag)) return `${'#'.repeat(Number(tag[1]))} ${inlineOf(node)}\n\n`
|
|
3518
|
+
if (tag === 'HR') return '---\n\n'
|
|
3519
|
+
if (tag === 'PRE') {
|
|
3520
|
+
const text = childrenOf(node).map((child) => (child.nodeType === 3 ? String(child.nodeValue ?? '') : block(child))).join('')
|
|
3521
|
+
return `\`\`\`\n${text.replace(/\n+$/, '')}\n\`\`\`\n\n`
|
|
3522
|
+
}
|
|
3523
|
+
if (tag === 'BLOCKQUOTE') {
|
|
3524
|
+
const body = childrenOf(node).map(block).join('').trim()
|
|
3525
|
+
return `${body.split('\n').map((line) => `> ${line}`).join('\n')}\n\n`
|
|
3526
|
+
}
|
|
3527
|
+
if (tag === 'UL' || tag === 'OL') {
|
|
3528
|
+
const ordered = tag === 'OL'
|
|
3529
|
+
const items = childrenOf(node)
|
|
3530
|
+
.filter((child) => tagOf(child) === 'LI')
|
|
3531
|
+
.map((child, itemIndex) => `${ordered ? `${itemIndex + 1}. ` : '- '}${inlineOf(child).trim()}`)
|
|
3532
|
+
.join('\n')
|
|
3533
|
+
return `${items}\n\n`
|
|
3534
|
+
}
|
|
3535
|
+
if (tag === 'P' || tag === 'DIV' || tag === 'LI' || tag === 'SECTION' || tag === 'ARTICLE') {
|
|
3536
|
+
const body = inlineOf(node)
|
|
3537
|
+
return body === '' ? '\n' : `${body}\n\n`
|
|
3538
|
+
}
|
|
3539
|
+
const nested = childrenOf(node)
|
|
3540
|
+
.map((child) => (['UL', 'OL', 'PRE', 'BLOCKQUOTE', 'P', 'DIV', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'HR'].includes(tagOf(child)) ? block(child) : inline(child)))
|
|
3541
|
+
.join('')
|
|
3542
|
+
return `${inline(node) && !nested ? inline(node) : nested}\n\n`
|
|
3543
|
+
}
|
|
3544
|
+
return childrenOf(root)
|
|
3545
|
+
.map((child) => (['UL', 'OL', 'PRE', 'BLOCKQUOTE', 'P', 'DIV', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'HR'].includes(tagOf(child)) ? block(child) : inline(child)))
|
|
3546
|
+
.join('')
|
|
3547
|
+
.replace(/\r\n?/g, '\n')
|
|
3548
|
+
.replace(/[ \t]+\n/g, '\n')
|
|
3549
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
3550
|
+
.trim()
|
|
3551
|
+
}
|
|
3552
|
+
|
|
3553
|
+
/**
|
|
3554
|
+
* WYSIWYG Markdown editor: type directly in the formatted document, select
|
|
3555
|
+
* text and use the toolbar (e.g. B makes 你好 bold immediately). The document
|
|
3556
|
+
* is serialized back to Markdown on every edit. A raw source mode and a
|
|
3557
|
+
* continuous preview are still available as tabs.
|
|
3558
|
+
*/
|
|
3559
|
+
function MarkdownEditor(props) {
|
|
3560
|
+
const t = typeof props?.t === 'function' ? props.t : (key) => key
|
|
3561
|
+
const value = typeof props?.value === 'string' ? props.value : ''
|
|
3562
|
+
const onChange = typeof props?.onChange === 'function' ? props.onChange : () => {}
|
|
3563
|
+
const disabled = props?.disabled === true
|
|
3564
|
+
const [mode, setMode] = React.useState('rich')
|
|
3565
|
+
const sourceRef = React.useRef(null)
|
|
3566
|
+
const richRef = React.useRef(null)
|
|
3567
|
+
const lastMarkdownRef = React.useRef(null)
|
|
3568
|
+
const valueRef = React.useRef(value)
|
|
3569
|
+
valueRef.current = value
|
|
3570
|
+
const composingRef = React.useRef(false)
|
|
3571
|
+
// Stable callback ref: seed the editable document whenever the element is
|
|
3572
|
+
// (re)mounted (e.g. switching preview -> source -> rich). This is what keeps
|
|
3573
|
+
// the content from vanishing on mode switches.
|
|
3574
|
+
const setRichRef = React.useCallback((element) => {
|
|
3575
|
+
richRef.current = element
|
|
3576
|
+
if (!element) return
|
|
3577
|
+
element.innerHTML = markdownToEditorHtml(valueRef.current)
|
|
3578
|
+
lastMarkdownRef.current = valueRef.current
|
|
3579
|
+
}, [])
|
|
3580
|
+
|
|
3581
|
+
const syncRich = () => {
|
|
3582
|
+
if (composingRef.current) return
|
|
3583
|
+
const element = richRef.current
|
|
3584
|
+
if (!element) return
|
|
3585
|
+
const markdown = domToMarkdown(element)
|
|
3586
|
+
lastMarkdownRef.current = markdown
|
|
3587
|
+
if (markdown !== valueRef.current) onChange(markdown)
|
|
3588
|
+
}
|
|
3589
|
+
|
|
3590
|
+
const switchMode = (next) => {
|
|
3591
|
+
if (next === mode) return
|
|
3592
|
+
if (mode === 'rich') syncRich()
|
|
3593
|
+
setMode(next)
|
|
3594
|
+
}
|
|
3595
|
+
|
|
3596
|
+
const exec = (command, argument = null) => {
|
|
3597
|
+
const element = richRef.current
|
|
3598
|
+
if (!element) return
|
|
3599
|
+
try {
|
|
3600
|
+
element.focus()
|
|
3601
|
+
document.execCommand(command, false, argument)
|
|
3602
|
+
} catch {
|
|
3603
|
+
// execCommand can be unavailable; the source tab still works.
|
|
3604
|
+
}
|
|
3605
|
+
syncRich()
|
|
3606
|
+
}
|
|
3607
|
+
|
|
3608
|
+
const insertHtml = (html) => {
|
|
3609
|
+
const element = richRef.current
|
|
3610
|
+
if (!element) return
|
|
3611
|
+
let selected = ''
|
|
3612
|
+
try {
|
|
3613
|
+
selected = String(window.getSelection()?.toString() || '')
|
|
3614
|
+
} catch {
|
|
3615
|
+
selected = ''
|
|
3616
|
+
}
|
|
3617
|
+
exec('insertHTML', html.replace('{selection}', escapeHtmlText(selected)))
|
|
3618
|
+
}
|
|
3619
|
+
|
|
3620
|
+
const sourceSelection = () => {
|
|
3621
|
+
const area = sourceRef.current
|
|
3622
|
+
const start = area && Number.isFinite(area.selectionStart) ? area.selectionStart : value.length
|
|
3623
|
+
const end = area && Number.isFinite(area.selectionEnd) ? area.selectionEnd : start
|
|
3624
|
+
return { text: value, start, end, selected: value.slice(start, end) }
|
|
3625
|
+
}
|
|
3626
|
+
const sourceCommit = (next, selection) => {
|
|
3627
|
+
onChange(next)
|
|
3628
|
+
window.requestAnimationFrame(() => {
|
|
3629
|
+
const area = sourceRef.current
|
|
3630
|
+
if (!area) return
|
|
3631
|
+
area.focus()
|
|
3632
|
+
if (Array.isArray(selection)) area.setSelectionRange(selection[0], selection[1])
|
|
3633
|
+
})
|
|
3634
|
+
}
|
|
3635
|
+
const sourceSurround = (before, after = '') => {
|
|
3636
|
+
const { text, start, end, selected } = sourceSelection()
|
|
3637
|
+
sourceCommit(`${text.slice(0, start)}${before}${selected}${after}${text.slice(end)}`, [start + before.length, start + before.length + selected.length])
|
|
3638
|
+
}
|
|
3639
|
+
const sourceTransformLines = (mapper) => {
|
|
3640
|
+
const { text, start, end } = sourceSelection()
|
|
3641
|
+
const lineStart = text.lastIndexOf('\n', Math.max(0, start - 1)) + 1
|
|
3642
|
+
let lineEnd = text.indexOf('\n', end)
|
|
3643
|
+
if (lineEnd === -1) lineEnd = text.length
|
|
3644
|
+
const transformed = text
|
|
3645
|
+
.slice(lineStart, lineEnd)
|
|
3646
|
+
.split('\n')
|
|
3647
|
+
.map((line, lineIndex) => mapper(line, lineIndex))
|
|
3648
|
+
.join('\n')
|
|
3649
|
+
sourceCommit(`${text.slice(0, lineStart)}${transformed}${text.slice(lineEnd)}`, [lineStart + transformed.length, lineStart + transformed.length])
|
|
3650
|
+
}
|
|
3651
|
+
const sourceInsert = (snippet) => {
|
|
3652
|
+
const { text, start, end } = sourceSelection()
|
|
3653
|
+
const before = start > 0 && !text.slice(0, start).endsWith('\n') ? '\n' : ''
|
|
3654
|
+
const after = end < text.length && !text.slice(end).startsWith('\n') ? '\n' : ''
|
|
3655
|
+
const payload = `${before}${snippet}${after}`
|
|
3656
|
+
sourceCommit(`${text.slice(0, start)}${payload}${text.slice(end)}`, [start + payload.length, start + payload.length])
|
|
3657
|
+
}
|
|
3658
|
+
const applyColor = (color) => {
|
|
3659
|
+
if (mode === 'rich') exec('foreColor', color)
|
|
3660
|
+
else if (mode === 'source') sourceSurround(`<span style="color:${color}">`, '</span>')
|
|
3661
|
+
}
|
|
3662
|
+
|
|
3663
|
+
const richTools = [
|
|
3664
|
+
{ key: 'h1', label: 'H1', title: t('md.heading'), run: () => exec('formatBlock', '<h1>') },
|
|
3665
|
+
{ key: 'h2', label: 'H2', title: t('md.heading'), run: () => exec('formatBlock', '<h2>') },
|
|
3666
|
+
{ key: 'h3', label: 'H3', title: t('md.heading'), run: () => exec('formatBlock', '<h3>') },
|
|
3667
|
+
{ key: 'bold', label: 'B', title: t('md.bold'), run: () => exec('bold') },
|
|
3668
|
+
{ key: 'italic', label: 'I', title: t('md.italic'), run: () => exec('italic') },
|
|
3669
|
+
{ key: 'strike', label: 'S', title: t('md.strike'), run: () => exec('strikeThrough') },
|
|
3670
|
+
{ key: 'code', label: '`', title: t('md.inlineCode'), run: () => insertHtml('<code>{selection}</code>') },
|
|
3671
|
+
{ key: 'codeblock', label: '```', title: t('md.codeBlock'), run: () => exec('formatBlock', '<pre>') },
|
|
3672
|
+
{ key: 'bullet', label: '•', title: t('md.bullet'), run: () => exec('insertUnorderedList') },
|
|
3673
|
+
{ key: 'numbered', label: '1.', title: t('md.numbered'), run: () => exec('insertOrderedList') },
|
|
3674
|
+
{ key: 'task', label: '☐', title: t('md.task'), run: () => insertHtml('<div>- [ ] {selection}</div>') },
|
|
3675
|
+
{ key: 'quote', label: '❝', title: t('md.quote'), run: () => exec('formatBlock', '<blockquote>') },
|
|
3676
|
+
{ key: 'link', label: '🔗', title: t('md.link'), run: () => {
|
|
3677
|
+
let href = 'https://'
|
|
3678
|
+
try {
|
|
3679
|
+
href = window.prompt(t('md.linkPrompt'), 'https://') || ''
|
|
3680
|
+
} catch {
|
|
3681
|
+
href = ''
|
|
3682
|
+
}
|
|
3683
|
+
if (href) exec('createLink', href)
|
|
3684
|
+
} },
|
|
3685
|
+
{ key: 'hr', label: '—', title: t('md.hr'), run: () => exec('insertHorizontalRule') },
|
|
3686
|
+
]
|
|
3687
|
+
const sourceTools = [
|
|
3688
|
+
{ key: 'h1', label: 'H1', title: t('md.heading'), run: () => sourceTransformLines((line, lineIndex) => (lineIndex === 0 ? `# ${line.replace(/^#{1,6}\s+/, '')}` : line)) },
|
|
3689
|
+
{ key: 'h2', label: 'H2', title: t('md.heading'), run: () => sourceTransformLines((line, lineIndex) => (lineIndex === 0 ? `## ${line.replace(/^#{1,6}\s+/, '')}` : line)) },
|
|
3690
|
+
{ key: 'h3', label: 'H3', title: t('md.heading'), run: () => sourceTransformLines((line, lineIndex) => (lineIndex === 0 ? `### ${line.replace(/^#{1,6}\s+/, '')}` : line)) },
|
|
3691
|
+
{ key: 'bold', label: 'B', title: t('md.bold'), run: () => sourceSurround('**', '**') },
|
|
3692
|
+
{ key: 'italic', label: 'I', title: t('md.italic'), run: () => sourceSurround('*', '*') },
|
|
3693
|
+
{ key: 'strike', label: 'S', title: t('md.strike'), run: () => sourceSurround('~~', '~~') },
|
|
3694
|
+
{ key: 'code', label: '`', title: t('md.inlineCode'), run: () => sourceSurround('`', '`') },
|
|
3695
|
+
{ key: 'codeblock', label: '```', title: t('md.codeBlock'), run: () => sourceInsert('```\n\n```') },
|
|
3696
|
+
{ key: 'bullet', label: '•', title: t('md.bullet'), run: () => sourceTransformLines((line) => `- ${line.replace(/^[-*+]\s+/, '')}`) },
|
|
3697
|
+
{ key: 'numbered', label: '1.', title: t('md.numbered'), run: () => sourceTransformLines((line, lineIndex) => `${lineIndex + 1}. ${line.replace(/^\d+[.)]\s+/, '')}`) },
|
|
3698
|
+
{ key: 'task', label: '☐', title: t('md.task'), run: () => sourceTransformLines((line) => `- [ ] ${line.replace(/^[-*+]\s+(\[[ xX]\]\s+)?/, '')}`) },
|
|
3699
|
+
{ key: 'quote', label: '❝', title: t('md.quote'), run: () => sourceTransformLines((line) => `> ${line.replace(/^>\s?/, '')}`) },
|
|
3700
|
+
{ key: 'link', label: '🔗', title: t('md.link'), run: () => sourceSurround('[', '](https://)') },
|
|
3701
|
+
{ key: 'hr', label: '—', title: t('md.hr'), run: () => sourceInsert('---') },
|
|
3702
|
+
]
|
|
3703
|
+
const tools = mode === 'rich' ? richTools : sourceTools
|
|
3704
|
+
|
|
3705
|
+
return h(
|
|
3706
|
+
'div',
|
|
3707
|
+
{ className: 'tb-md-editor' },
|
|
3708
|
+
h(
|
|
3709
|
+
'div',
|
|
3710
|
+
{ className: 'tb-md-toolbar', role: 'toolbar' },
|
|
3711
|
+
h(
|
|
3712
|
+
'div',
|
|
3713
|
+
{ className: 'tb-md-tools' },
|
|
3714
|
+
...tools.map((tool) =>
|
|
3715
|
+
h('button', { key: tool.key, type: 'button', className: 'tb-md-tool', title: tool.title, disabled, onClick: tool.run }, tool.label),
|
|
3716
|
+
),
|
|
3717
|
+
),
|
|
3718
|
+
h(
|
|
3719
|
+
'div',
|
|
3720
|
+
{ className: 'tb-md-mode' },
|
|
3721
|
+
...['rich', 'source', 'preview'].map((value_) =>
|
|
3722
|
+
h(
|
|
3723
|
+
'button',
|
|
3724
|
+
{ key: value_, type: 'button', className: `tb-md-tool${mode === value_ ? ' on' : ''}`, onClick: () => switchMode(value_) },
|
|
3725
|
+
t(`md.${value_}`),
|
|
3726
|
+
),
|
|
3727
|
+
),
|
|
3728
|
+
),
|
|
3729
|
+
),
|
|
3730
|
+
h(
|
|
3731
|
+
'div',
|
|
3732
|
+
{ className: 'tb-md-colorbar' },
|
|
3733
|
+
h('span', { className: 'tb-md-color-label' }, t('md.color')),
|
|
3734
|
+
...BOARD_INKS.slice(0, 8).map((color) =>
|
|
3735
|
+
h('button', {
|
|
3736
|
+
key: `color-${color}`,
|
|
3737
|
+
type: 'button',
|
|
3738
|
+
className: 'tb-md-color',
|
|
3739
|
+
title: color,
|
|
3740
|
+
style: { background: color },
|
|
3741
|
+
disabled,
|
|
3742
|
+
onClick: () => applyColor(color),
|
|
3743
|
+
}),
|
|
3744
|
+
),
|
|
3745
|
+
h(
|
|
3746
|
+
'span',
|
|
3747
|
+
{ className: 'tb-md-color-custom' },
|
|
3748
|
+
h('span', { className: 'tb-md-color-label' }, t('md.customColor')),
|
|
3749
|
+
h('input', {
|
|
3750
|
+
type: 'color',
|
|
3751
|
+
className: 'tb-md-color-input',
|
|
3752
|
+
title: t('md.color'),
|
|
3753
|
+
disabled,
|
|
3754
|
+
style: { width: 30, height: 24, minWidth: 30, flex: '0 0 auto' },
|
|
3755
|
+
onChange: (event) => applyColor(event.target.value),
|
|
3756
|
+
}),
|
|
3757
|
+
),
|
|
3758
|
+
),
|
|
3759
|
+
h('div', { className: 'tb-ws-hint', style: { fontSize: '10.5px' } }, t('md.hint')),
|
|
3760
|
+
h(
|
|
3761
|
+
'div',
|
|
3762
|
+
{ className: 'tb-md-body' },
|
|
3763
|
+
mode === 'rich'
|
|
3764
|
+
? h('div', {
|
|
3765
|
+
ref: setRichRef,
|
|
3766
|
+
className: 'tb-md-rich',
|
|
3767
|
+
contentEditable: true,
|
|
3768
|
+
suppressContentEditableWarning: true,
|
|
3769
|
+
role: 'textbox',
|
|
3770
|
+
'aria-multiline': 'true',
|
|
3771
|
+
'data-placeholder': props?.placeholder || '',
|
|
3772
|
+
onInput: syncRich,
|
|
3773
|
+
onBlur: syncRich,
|
|
3774
|
+
onKeyUp: syncRich,
|
|
3775
|
+
onCompositionStart: () => {
|
|
3776
|
+
composingRef.current = true
|
|
3777
|
+
},
|
|
3778
|
+
onCompositionEnd: () => {
|
|
3779
|
+
composingRef.current = false
|
|
3780
|
+
syncRich()
|
|
3781
|
+
},
|
|
3782
|
+
onPaste: () => window.setTimeout(syncRich, 0),
|
|
3783
|
+
})
|
|
3784
|
+
: mode === 'source'
|
|
3785
|
+
? h('textarea', {
|
|
3786
|
+
ref: sourceRef,
|
|
3787
|
+
className: 'tb-md-source',
|
|
3788
|
+
value,
|
|
3789
|
+
disabled,
|
|
3790
|
+
placeholder: props?.placeholder || '',
|
|
3791
|
+
onChange: (event) => onChange(event.target.value),
|
|
3792
|
+
onKeyDown: (event) => {
|
|
3793
|
+
if ((event.ctrlKey || event.metaKey) && !event.altKey) {
|
|
3794
|
+
const key = event.key.toLowerCase()
|
|
3795
|
+
if (key === 'b') {
|
|
3796
|
+
event.preventDefault()
|
|
3797
|
+
sourceSurround('**', '**')
|
|
3798
|
+
} else if (key === 'i') {
|
|
3799
|
+
event.preventDefault()
|
|
3800
|
+
sourceSurround('*', '*')
|
|
3801
|
+
} else if (key === 's') {
|
|
3802
|
+
event.preventDefault()
|
|
3803
|
+
sourceSurround('~~', '~~')
|
|
3804
|
+
} else if (key === '`') {
|
|
3805
|
+
event.preventDefault()
|
|
3806
|
+
sourceSurround('`', '`')
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
},
|
|
3810
|
+
})
|
|
3811
|
+
: h('div', { className: 'tb-md tb-md-readonly' }, ...(value.trim() ? renderMarkdown(value, 'mde') : [h('div', { key: 'empty', className: 'tb-md-empty' }, t('md.empty'))])),
|
|
3812
|
+
),
|
|
3813
|
+
)
|
|
3814
|
+
}
|
|
3815
|
+
|
|
3055
3816
|
const BOARD_SHAPES = [
|
|
3056
3817
|
['rect', '▭', 'board.shapeRect'],
|
|
3057
3818
|
['ellipse', '◯', 'board.shapeEllipse'],
|
|
@@ -3125,6 +3886,8 @@ window.__ModuleLoader__.load({
|
|
|
3125
3886
|
const [zoom, setZoom] = React.useState(1)
|
|
3126
3887
|
const zoomRef = React.useRef(zoom)
|
|
3127
3888
|
zoomRef.current = zoom
|
|
3889
|
+
const zoomAnchorRef = React.useRef(null)
|
|
3890
|
+
const wheelRef = React.useRef({ frame: 0, target: null, pointer: null })
|
|
3128
3891
|
const [drawOnSticky, setDrawOnSticky] = React.useState(() => {
|
|
3129
3892
|
try {
|
|
3130
3893
|
return window.localStorage.getItem('dsh-timeback:board-draw-on-sticky') !== '0'
|
|
@@ -3168,6 +3931,76 @@ window.__ModuleLoader__.load({
|
|
|
3168
3931
|
if (saveTimerRef.current) clearTimeout(saveTimerRef.current)
|
|
3169
3932
|
}, [])
|
|
3170
3933
|
|
|
3934
|
+
/** Zoom around one viewport point while keeping that content anchored. */
|
|
3935
|
+
const applyZoom = (nextZoom, clientX, clientY) => {
|
|
3936
|
+
const viewport = viewportRef.current
|
|
3937
|
+
if (!viewport) return
|
|
3938
|
+
const clamped = Math.min(3, Math.max(0.2, nextZoom))
|
|
3939
|
+
if (Math.abs(clamped - zoomRef.current) < 0.0001) return
|
|
3940
|
+
const rect = viewport.getBoundingClientRect()
|
|
3941
|
+
const localX = Number.isFinite(clientX) ? clientX - rect.left : viewport.clientWidth / 2
|
|
3942
|
+
const localY = Number.isFinite(clientY) ? clientY - rect.top : viewport.clientHeight / 2
|
|
3943
|
+
const contentX = (viewport.scrollLeft + localX) / zoomRef.current
|
|
3944
|
+
const contentY = (viewport.scrollTop + localY) / zoomRef.current
|
|
3945
|
+
zoomAnchorRef.current = { contentX, contentY, localX, localY }
|
|
3946
|
+
setZoom(clamped)
|
|
3947
|
+
zoomRef.current = clamped
|
|
3948
|
+
}
|
|
3949
|
+
|
|
3950
|
+
// Scroll correction must happen before paint, otherwise the frame in which
|
|
3951
|
+
// the transform changes but the scroll does not yet shows a visible jump
|
|
3952
|
+
// (the "flicker" during wheel zoom).
|
|
3953
|
+
React.useLayoutEffect(() => {
|
|
3954
|
+
const pending = zoomAnchorRef.current
|
|
3955
|
+
if (!pending) return
|
|
3956
|
+
zoomAnchorRef.current = null
|
|
3957
|
+
const viewport = viewportRef.current
|
|
3958
|
+
if (!viewport) return
|
|
3959
|
+
const scale = zoomRef.current || 1
|
|
3960
|
+
viewport.scrollLeft = Math.max(0, pending.contentX * scale - pending.localX)
|
|
3961
|
+
viewport.scrollTop = Math.max(0, pending.contentY * scale - pending.localY)
|
|
3962
|
+
}, [zoom])
|
|
3963
|
+
|
|
3964
|
+
const zoomBy = (factor) => {
|
|
3965
|
+
const viewport = viewportRef.current
|
|
3966
|
+
if (!viewport) return
|
|
3967
|
+
const rect = viewport.getBoundingClientRect()
|
|
3968
|
+
applyZoom(zoomRef.current * factor, rect.left + viewport.clientWidth / 2, rect.top + viewport.clientHeight / 2)
|
|
3969
|
+
}
|
|
3970
|
+
|
|
3971
|
+
/** Delegate wheel/pinch zoom (Ctrl or ⌘ + wheel) to the viewport. */
|
|
3972
|
+
React.useEffect(() => {
|
|
3973
|
+
const viewport = viewportRef.current
|
|
3974
|
+
if (!viewport) return undefined
|
|
3975
|
+
const flushWheel = () => {
|
|
3976
|
+
const state = wheelRef.current
|
|
3977
|
+
state.frame = 0
|
|
3978
|
+
const target = state.target
|
|
3979
|
+
const pointer = state.pointer
|
|
3980
|
+
state.target = null
|
|
3981
|
+
if (target === null) return
|
|
3982
|
+
applyZoom(target, pointer?.x, pointer?.y)
|
|
3983
|
+
}
|
|
3984
|
+
const onWheel = (event) => {
|
|
3985
|
+
if (!(event.ctrlKey || event.metaKey)) return
|
|
3986
|
+
event.preventDefault()
|
|
3987
|
+
const state = wheelRef.current
|
|
3988
|
+
const factor = event.deltaY < 0 ? 1.12 : 1 / 1.12
|
|
3989
|
+
const base = state.target ?? zoomRef.current
|
|
3990
|
+
state.target = Math.min(3, Math.max(0.2, base * factor))
|
|
3991
|
+
state.pointer = { x: event.clientX, y: event.clientY }
|
|
3992
|
+
if (state.frame === 0) state.frame = window.requestAnimationFrame(flushWheel)
|
|
3993
|
+
}
|
|
3994
|
+
viewport.addEventListener('wheel', onWheel, { passive: false })
|
|
3995
|
+
return () => {
|
|
3996
|
+
viewport.removeEventListener('wheel', onWheel)
|
|
3997
|
+
if (wheelRef.current.frame !== 0) {
|
|
3998
|
+
window.cancelAnimationFrame(wheelRef.current.frame)
|
|
3999
|
+
wheelRef.current.frame = 0
|
|
4000
|
+
}
|
|
4001
|
+
}
|
|
4002
|
+
}, [state.board])
|
|
4003
|
+
|
|
3171
4004
|
/** Fit every note/stroke into view: pick a zoom and scroll offset. */
|
|
3172
4005
|
const autoFit = () => {
|
|
3173
4006
|
const viewport = viewportRef.current
|
|
@@ -3204,6 +4037,7 @@ window.__ModuleLoader__.load({
|
|
|
3204
4037
|
const spanX = Math.max(120, maxX - minX)
|
|
3205
4038
|
const spanY = Math.max(120, maxY - minY)
|
|
3206
4039
|
const nextZoom = Math.min(1.6, Math.max(0.2, Math.min((viewport.clientWidth - 40) / spanX, (viewport.clientHeight - 40) / spanY)))
|
|
4040
|
+
zoomAnchorRef.current = null
|
|
3207
4041
|
setZoom(nextZoom)
|
|
3208
4042
|
zoomRef.current = nextZoom
|
|
3209
4043
|
const centerX = (minX + maxX) / 2
|
|
@@ -4246,6 +5080,9 @@ window.__ModuleLoader__.load({
|
|
|
4246
5080
|
h('span', { style: { flex: 1 } }),
|
|
4247
5081
|
h('span', { className: 'tb-muted tb-small' }, format(t('board.count'), { count: entries.length, version: boardVersion })),
|
|
4248
5082
|
h('span', { className: 'tb-muted tb-small' }, format(t('board.canvasVersion'), { version: boardVersion })),
|
|
5083
|
+
h('button', { type: 'button', className: 'tb-tool', title: t('board.zoomOut'), onClick: () => zoomBy(1 / 1.2) }, '−'),
|
|
5084
|
+
h('button', { type: 'button', className: 'tb-tool', title: t('board.zoomReset'), onClick: () => zoomBy(1 / zoomRef.current) }, `${Math.round(zoom * 100)}%`),
|
|
5085
|
+
h('button', { type: 'button', className: 'tb-tool', title: t('board.zoomIn'), onClick: () => zoomBy(1.2) }, '+'),
|
|
4249
5086
|
h('button', { type: 'button', className: 'tb-btn', disabled: state.loading, onClick: refresh }, t('board.refresh')),
|
|
4250
5087
|
h('button', { type: 'button', className: 'tb-btn primary', onClick: startCreate }, `+ ${t('board.newSticky')}`),
|
|
4251
5088
|
),
|
|
@@ -4352,15 +5189,6 @@ window.__ModuleLoader__.load({
|
|
|
4352
5189
|
{ className: 'tb-detail-head' },
|
|
4353
5190
|
h('span', { className: 'tb-detail-title' }, draft.id ? t('board.edit') : t('board.newSticky')),
|
|
4354
5191
|
h('span', { style: { flex: 1 } }),
|
|
4355
|
-
h(
|
|
4356
|
-
'button',
|
|
4357
|
-
{
|
|
4358
|
-
type: 'button',
|
|
4359
|
-
className: `tb-viewtab${draft.preview ? ' on' : ''}`,
|
|
4360
|
-
onClick: () => setDraft({ ...draft, preview: !draft.preview }),
|
|
4361
|
-
},
|
|
4362
|
-
draft.preview ? t('board.editMode') : t('board.preview'),
|
|
4363
|
-
),
|
|
4364
5192
|
h('button', { type: 'button', className: 'tb-btn', title: t('board.resizeHint'), onClick: resetDialogSize }, t('board.resetSize')),
|
|
4365
5193
|
),
|
|
4366
5194
|
h('input', {
|
|
@@ -4369,14 +5197,13 @@ window.__ModuleLoader__.load({
|
|
|
4369
5197
|
disabled: draft.busy,
|
|
4370
5198
|
onChange: (event) => setDraft({ ...draft, title: event.target.value }),
|
|
4371
5199
|
}),
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
:
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
}),
|
|
5200
|
+
h(MarkdownEditor, {
|
|
5201
|
+
value: draft.body,
|
|
5202
|
+
onChange: (next) => setDraft({ ...draft, body: next }),
|
|
5203
|
+
t,
|
|
5204
|
+
disabled: draft.busy,
|
|
5205
|
+
placeholder: t('board.bodyPlaceholder'),
|
|
5206
|
+
}),
|
|
4380
5207
|
h('div', { className: 'tb-ws-hint' }, t('board.resizeHint')),
|
|
4381
5208
|
draft.error ? h('div', { className: 'tb-feedback err' }, format(t('board.error'), { error: draft.error })) : null,
|
|
4382
5209
|
h(
|
|
@@ -4399,6 +5226,10 @@ window.__ModuleLoader__.load({
|
|
|
4399
5226
|
window.__TIMEBACK_TEST__.renderMarkdown = renderMarkdown
|
|
4400
5227
|
window.__TIMEBACK_TEST__.stripMarkdown = stripMarkdown
|
|
4401
5228
|
window.__TIMEBACK_TEST__.boardEdgePath = boardEdgePath
|
|
5229
|
+
window.__TIMEBACK_TEST__.MarkdownEditor = MarkdownEditor
|
|
5230
|
+
window.__TIMEBACK_TEST__.WorkspacePathSelector = WorkspacePathSelector
|
|
5231
|
+
window.__TIMEBACK_TEST__.markdownToEditorHtml = markdownToEditorHtml
|
|
5232
|
+
window.__TIMEBACK_TEST__.domToMarkdown = domToMarkdown
|
|
4402
5233
|
}
|
|
4403
5234
|
|
|
4404
5235
|
return {
|