dsh-timeback 0.7.5 → 0.7.7
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 +11 -5
- package/client.js +246 -103
- package/docs/MARKET.md +2 -2
- package/docs/PUBLISHING.md +7 -1
- package/index.js +39 -11
- package/package.json +1 -1
- package/src/registry.js +40 -0
- package/src/service.js +125 -23
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.7+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. */
|
|
@@ -182,14 +182,15 @@ window.__ModuleLoader__.load({
|
|
|
182
182
|
'board.deleted': '记录已删除',
|
|
183
183
|
'board.count': '{count} 条记录 · 版本 v{version}',
|
|
184
184
|
'board.resetSize': '默认大小',
|
|
185
|
+
'board.autosaveHint': '点击弹窗外会自动保存',
|
|
185
186
|
'board.resizeHint': '可拖拽弹框右边缘、下边缘或右下角调整大小',
|
|
186
187
|
'board.error': '记录板操作失败:{error}',
|
|
187
188
|
'board.agentHint': '提示:让会话调用 timeback_note 工具即可把结论写进记录板;回溯时记录板会一起回退。',
|
|
188
189
|
'guide.boardTitle': '记录板',
|
|
189
190
|
'guide.boardDescription': '全局 Markdown 记录板:手动添加或让会话记录,回溯时一起回退。',
|
|
190
191
|
'panel.recording': '记录设置',
|
|
191
|
-
'panel.recordThis': '
|
|
192
|
-
'panel.recordThisHint': '
|
|
192
|
+
'panel.recordThis': '全选',
|
|
193
|
+
'panel.recordThisHint': '勾选“全选”记录整个工作区;取消下面文件夹/文件即可只记录选中的部分。',
|
|
193
194
|
'panel.recordOff': '未开启记录',
|
|
194
195
|
'panel.recordOn': '记录中',
|
|
195
196
|
'panel.recordAll': '插件配置 capture=all:所有工作区自动记录',
|
|
@@ -204,6 +205,9 @@ window.__ModuleLoader__.load({
|
|
|
204
205
|
'panel.workspaceDisabled': '已关闭此工作区的自动记录',
|
|
205
206
|
'panel.workspaceStillOn': '操作已提交,但该目录仍被其它记录设置覆盖;请在上方已开启列表里取消对应路径。',
|
|
206
207
|
'panel.selectAllHint': '只记录勾选的文件夹和文件',
|
|
208
|
+
'panel.workspaceSectionTitle': '工作区文件快照',
|
|
209
|
+
'panel.expandWorkspaceSection': '展开工作区记录设置',
|
|
210
|
+
'panel.collapseWorkspaceSection': '收起工作区记录设置',
|
|
207
211
|
'panel.expandFolder': '展开文件夹',
|
|
208
212
|
'panel.collapseFolder': '收起文件夹',
|
|
209
213
|
'panel.selectedCount': '已选择 {selected} / {total} 项(文件夹包含其内部文件)',
|
|
@@ -346,7 +350,7 @@ window.__ModuleLoader__.load({
|
|
|
346
350
|
'note.saved': 'Card note saved',
|
|
347
351
|
'note.removed': 'Card note deleted',
|
|
348
352
|
'board.title': 'Notes board',
|
|
349
|
-
'board.subtitle': '
|
|
353
|
+
'board.subtitle': 'This workspace’s Markdown notes · rewinds restore them too',
|
|
350
354
|
'md.bold': 'Bold',
|
|
351
355
|
'md.italic': 'Italic',
|
|
352
356
|
'md.strike': 'Strikethrough',
|
|
@@ -369,7 +373,7 @@ window.__ModuleLoader__.load({
|
|
|
369
373
|
'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.',
|
|
370
374
|
'board.newSticky': 'New sticky',
|
|
371
375
|
'board.stickyColor': 'Sticky colour',
|
|
372
|
-
'board.stickyHint': 'Sticky notes are draggable; draw on the grid or on a note, erase strokes with the eraser.',
|
|
376
|
+
'board.stickyHint': 'Sticky notes are draggable; draw on the grid or on a note, erase strokes with the eraser. Clicking outside the editor auto-saves.',
|
|
373
377
|
'board.resizeNote': 'Drag to resize the sticky',
|
|
374
378
|
'board.drawOnSticky': 'Draw on stickies',
|
|
375
379
|
'board.drawOnStickyOn': 'Sticky drawing: on',
|
|
@@ -431,6 +435,7 @@ window.__ModuleLoader__.load({
|
|
|
431
435
|
'board.deleted': 'Note deleted',
|
|
432
436
|
'board.count': '{count} notes · version v{version}',
|
|
433
437
|
'board.resetSize': 'Default size',
|
|
438
|
+
'board.autosaveHint': 'Clicking outside the dialog saves automatically',
|
|
434
439
|
'board.resizeHint': 'Drag the right edge, bottom edge or bottom-right corner to resize',
|
|
435
440
|
'board.error': 'Notes board failed: {error}',
|
|
436
441
|
'board.agentHint': 'Tip: ask the session to use the timeback_note tool; rewinds roll the board back with the conversation.',
|
|
@@ -452,6 +457,9 @@ window.__ModuleLoader__.load({
|
|
|
452
457
|
'panel.workspaceEnabled': 'Recording enabled for this workspace',
|
|
453
458
|
'panel.workspaceDisabled': 'Recording disabled for this workspace',
|
|
454
459
|
'panel.selectAllHint': '只记录勾选的文件夹和文件',
|
|
460
|
+
'panel.workspaceSectionTitle': '工作区文件快照',
|
|
461
|
+
'panel.expandWorkspaceSection': '展开工作区记录设置',
|
|
462
|
+
'panel.collapseWorkspaceSection': '收起工作区记录设置',
|
|
455
463
|
'panel.expandFolder': '展开文件夹',
|
|
456
464
|
'panel.collapseFolder': '收起文件夹',
|
|
457
465
|
'panel.selectedCount': '已选择 {selected} / {total} 项(文件夹包含其内部文件)',
|
|
@@ -459,6 +467,9 @@ window.__ModuleLoader__.load({
|
|
|
459
467
|
'panel.pathsLoading': '正在读取工作区文件…',
|
|
460
468
|
'panel.pathsFailed': '读取工作区文件失败:{error}',
|
|
461
469
|
'panel.selectAllHint': 'Only selected folders/files are recorded',
|
|
470
|
+
'panel.workspaceSectionTitle': 'Workspace file snapshots',
|
|
471
|
+
'panel.expandWorkspaceSection': 'Expand workspace recording settings',
|
|
472
|
+
'panel.collapseWorkspaceSection': 'Collapse workspace recording settings',
|
|
462
473
|
'panel.expandFolder': 'Expand folder',
|
|
463
474
|
'panel.collapseFolder': 'Collapse folder',
|
|
464
475
|
'panel.selectedCount': '{selected} / {total} selected (a folder includes its contents)',
|
|
@@ -619,7 +630,7 @@ window.__ModuleLoader__.load({
|
|
|
619
630
|
.tb-link.current{stroke-width:2.6;opacity:1;filter:drop-shadow(0 0 3px currentColor)}
|
|
620
631
|
.tb-lane-label{position:absolute;transform:translateY(-50%);max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:10.5px;line-height:16px;border:1px solid;border-radius:999px;padding:0 8px;background:var(--dsw-alias-bg-base,#16181d);color:var(--dsw-alias-label-secondary,#9aa0a6);opacity:.85}
|
|
621
632
|
.tb-lane-label.current{opacity:1;font-weight:600}
|
|
622
|
-
.tb-card{position:absolute;width:246px;height:116px;animation:tb-card-
|
|
633
|
+
.tb-card{position:absolute;width:246px;height:116px;animation:tb-card-fade .15s ease-out;box-sizing:border-box;border-radius:12px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));background:var(--dsw-alias-bg-layer-2,rgba(28,32,40,.96));box-shadow:0 2px 8px rgba(0,0,0,.18);padding:8px 10px;display:flex;flex-direction:column;gap:5px;cursor:pointer;overflow:hidden;transition:box-shadow .12s, border-color .12s, transform .12s;-webkit-font-smoothing:antialiased;text-rendering:optimizeLegibility}
|
|
623
634
|
.tb-card:before{content:"";position:absolute;left:0;top:0;bottom:0;width:3px;background:var(--tb-color,#4d7cfe);opacity:.55;border-radius:12px 0 0 12px}
|
|
624
635
|
.tb-card:hover{transform:translateY(-1px);box-shadow:0 6px 16px rgba(0,0,0,.26)}
|
|
625
636
|
.tb-folder-slot{position:absolute;z-index:0;border:2px dashed var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);border-radius:14px;background:color-mix(in srgb, var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6) 10%, transparent);display:flex;align-items:center;justify-content:center;pointer-events:none;animation:tb-slot-in .16s ease-out}
|
|
@@ -636,19 +647,22 @@ window.__ModuleLoader__.load({
|
|
|
636
647
|
.tb-card.current{border-color:var(--tb-color,#4d7cfe);box-shadow:0 0 0 2px color-mix(in srgb, var(--tb-color,#4d7cfe) 32%, transparent), 0 6px 16px rgba(0,0,0,.24)}
|
|
637
648
|
.tb-card.selected{border-color:var(--tb-color,#4d7cfe);box-shadow:0 0 0 3px color-mix(in srgb, var(--tb-color,#4d7cfe) 42%, transparent), 0 8px 20px rgba(0,0,0,.3)}
|
|
638
649
|
.tb-card-head{display:flex;align-items:center;gap:6px;min-height:18px}
|
|
639
|
-
.tb-card-branch{font-size:
|
|
640
|
-
.tb-card-badge{font-size:
|
|
650
|
+
.tb-card-branch{font-size:11px;color:var(--dsw-alias-label-secondary,#9aa0a6);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:96px;line-height:16px}
|
|
651
|
+
.tb-card-badge{font-size:11px;font-weight:700;line-height:16px;border-radius:999px;padding:0 7px;color:var(--tb-color,#4d7cfe);border:1px solid color-mix(in srgb, var(--tb-color,#4d7cfe) 55%, transparent);background:color-mix(in srgb, var(--tb-color,#4d7cfe) 12%, transparent);white-space:nowrap}
|
|
641
652
|
.tb-card-spacer{flex:1}
|
|
642
653
|
.tb-card-time{font-size:10px;color:var(--dsw-alias-label-tertiary,#8a919c);white-space:nowrap}
|
|
643
654
|
.tb-card-dot{width:7px;height:7px;border-radius:50%;background:var(--tb-color,#4d7cfe);box-shadow:0 0 0 3px color-mix(in srgb, var(--tb-color,#4d7cfe) 25%, transparent)}
|
|
644
|
-
.tb-card-prompt{font-size:
|
|
655
|
+
.tb-card-prompt{font-size:12px;line-height:1.45;color:var(--dsw-alias-label-secondary,#9aa0a6);overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;flex:1;word-break:break-word}
|
|
645
656
|
.tb-card-foot{display:flex;align-items:center;gap:5px;flex-wrap:wrap;font-size:10px;min-height:16px}
|
|
646
657
|
.tb-card-chip{border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));border-radius:4px;padding:0 4px;line-height:14px;color:var(--dsw-alias-label-tertiary,#8a919c)}
|
|
647
658
|
.tb-card-chip.manual{border-style:dashed}
|
|
648
659
|
.tb-card-chip.warn{color:var(--dsw-alias-state-warning-primary,#f0b23e);border-color:currentColor}
|
|
649
|
-
.tb-card-action{margin-left:auto;appearance:none;border:1px solid color-mix(in srgb, var(--tb-color,#4d7cfe) 45%, transparent);background:color-mix(in srgb, var(--tb-color,#4d7cfe) 12%, transparent);color:var(--tb-color,#4d7cfe);border-radius:4px;padding:0 5px;line-height:15px;font-size:
|
|
660
|
+
.tb-card-action{margin-left:auto;appearance:none;border:1px solid color-mix(in srgb, var(--tb-color,#4d7cfe) 45%, transparent);background:color-mix(in srgb, var(--tb-color,#4d7cfe) 12%, transparent);color:var(--tb-color,#4d7cfe);border-radius:4px;padding:0 5px;line-height:15px;font-size:10px;cursor:pointer;white-space:nowrap}
|
|
650
661
|
.tb-card-action:hover{background:color-mix(in srgb, var(--tb-color,#4d7cfe) 24%, transparent)}
|
|
651
662
|
.tb-card.folder{border-style:dashed;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.05))}
|
|
663
|
+
.tb-card.folder:not(.expanded){height:172px}
|
|
664
|
+
.tb-card.folder>.tb-card-head,.tb-card.folder>.tb-card-prompt,.tb-card.folder>.tb-card-foot{flex:0 0 auto}
|
|
665
|
+
.tb-card.folder:not(.expanded)>.tb-folder-members{flex:1;min-height:0}
|
|
652
666
|
.tb-card.folder.expanded{width:370px;height:auto;min-height:116px;max-height:460px;z-index:6;overflow:auto;cursor:grab;background:var(--dsw-alias-bg-layer-2,rgba(28,32,40,.98))}
|
|
653
667
|
.tb-folder-expanded{display:flex;flex-direction:column;gap:3px;overflow:auto;min-height:0}
|
|
654
668
|
.tb-folder-hint{font-size:10px;line-height:1.4;color:var(--dsw-alias-label-tertiary,#8a919c);margin-bottom:1px}
|
|
@@ -661,16 +675,17 @@ window.__ModuleLoader__.load({
|
|
|
661
675
|
.tb-folder-ghost-label{font-weight:700;color:var(--dsw-alias-label-primary,#e6e6e6);white-space:nowrap}
|
|
662
676
|
.tb-folder-ghost-prompt{color:var(--dsw-alias-label-secondary,#9aa0a6);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
663
677
|
.tb-folder-ghost.dropping{animation:tb-ghost-drop .2s ease-in forwards}
|
|
664
|
-
@keyframes tb-card-
|
|
678
|
+
@keyframes tb-card-fade{from{opacity:0}to{opacity:1}}
|
|
665
679
|
@keyframes tb-ghost-drop{to{opacity:0;transform:scale(.18) translateY(2px);filter:blur(1px)}}
|
|
666
680
|
.tb-folder-members{display:flex;flex-direction:column;gap:2px;overflow:hidden;flex:1;min-height:0}
|
|
667
681
|
.tb-folder-member{font-size:10.5px;line-height:1.35;color:var(--dsw-alias-label-secondary,#9aa0a6);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.1));border-radius:4px;padding:1px 4px;background:var(--dsw-alias-bg-base,rgba(0,0,0,.18))}
|
|
668
682
|
.tb-card-action.danger{border-color:color-mix(in srgb, var(--dsw-alias-state-error-primary,#ff7a59) 55%, transparent);background:color-mix(in srgb, var(--dsw-alias-state-error-primary,#ff7a59) 10%, transparent);color:var(--dsw-alias-state-error-primary,#ff7a59)}
|
|
669
683
|
.tb-card-action.danger:hover{background:color-mix(in srgb, var(--dsw-alias-state-error-primary,#ff7a59) 22%, transparent)}
|
|
670
684
|
.tb-card:active{cursor:grabbing}
|
|
671
|
-
.tb-card-note{font-size:
|
|
685
|
+
.tb-card-note{font-size:11px;line-height:1.35;color:var(--dsw-alias-label-primary,#d7dbe2);overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;word-break:break-word;border-left:2px solid color-mix(in srgb, var(--tb-color,#4d7cfe) 65%, transparent);padding-left:6px}
|
|
672
686
|
.tb-card-prompt.withnote{-webkit-line-clamp:1;font-size:11px}
|
|
673
|
-
.tb-card-
|
|
687
|
+
.tb-card-rewind{margin-left:auto;appearance:none;border:1px solid color-mix(in srgb, var(--tb-color,#4d7cfe) 55%, transparent);background:color-mix(in srgb, var(--tb-color,#4d7cfe) 14%, transparent);color:var(--tb-color,#4d7cfe);border-radius:4px;padding:0 5px;line-height:15px;font-size:10px;cursor:pointer;white-space:nowrap}
|
|
688
|
+
.tb-card-editnote{margin-left:auto;appearance:none;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.05));color:var(--dsw-alias-label-secondary,#9aa0a6);border-radius:4px;padding:0 5px;line-height:15px;font-size:10px;cursor:pointer;white-space:nowrap}
|
|
674
689
|
.tb-card-editnote:hover{color:var(--dsw-alias-label-primary,#e6e6e6)}
|
|
675
690
|
.tb-card-editnote.has{color:var(--tb-color,#4d7cfe);border-color:color-mix(in srgb, var(--tb-color,#4d7cfe) 50%, transparent)}
|
|
676
691
|
.tb-overlay{position:fixed;inset:0;z-index:60;background:rgba(0,0,0,.35);display:flex;justify-content:flex-end;align-items:stretch}
|
|
@@ -956,7 +971,7 @@ window.__ModuleLoader__.load({
|
|
|
956
971
|
/** Parse inline Markdown (bold/italic/code/link) into React children. */
|
|
957
972
|
function inlineMarkdown(text, keyPrefix) {
|
|
958
973
|
const nodes = []
|
|
959
|
-
const pattern = /(<span style="color:\s
|
|
974
|
+
const pattern = /(<span style="[^"]*color:\s*(?:#[0-9a-f]{3,8}|rgba?\([^)]*\))[^"]*">[\s\S]*?<\/span>|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|\*[^*\n]+\*|_[^\n_]+_)/gi
|
|
960
975
|
let last = 0
|
|
961
976
|
let match
|
|
962
977
|
let index = 0
|
|
@@ -965,8 +980,9 @@ window.__ModuleLoader__.load({
|
|
|
965
980
|
const token = match[0]
|
|
966
981
|
const key = `${keyPrefix}-i${index++}`
|
|
967
982
|
if (token.startsWith('<span')) {
|
|
968
|
-
const match = /^<span style="color:\s*(
|
|
969
|
-
|
|
983
|
+
const match = /^<span style="[^"]*color:\s*([^";]+)[^"]*">([\s\S]*?)<\/span>$/i.exec(token)
|
|
984
|
+
const color = match ? normalizeCssColor(match[1]) : ''
|
|
985
|
+
if (color) nodes.push(h('span', { key, style: { color } }, ...inlineMarkdown(match[2], `${keyPrefix}-c${index}`)))
|
|
970
986
|
else nodes.push(token)
|
|
971
987
|
} else if (token.startsWith('`')) nodes.push(h('code', { key }, token.slice(1, -1)))
|
|
972
988
|
else if (token.startsWith('**') || token.startsWith('__')) nodes.push(h('strong', { key }, token.slice(2, -2)))
|
|
@@ -1142,6 +1158,8 @@ window.__ModuleLoader__.load({
|
|
|
1142
1158
|
/** Card dimensions and spacing of the conversation canvas. */
|
|
1143
1159
|
const CARD_WIDTH = 246
|
|
1144
1160
|
const CARD_HEIGHT = 116
|
|
1161
|
+
/** Collapsed folder cards are taller so member rows and the footer never clip. */
|
|
1162
|
+
const FOLDER_CARD_HEIGHT = 172
|
|
1145
1163
|
const CARD_GAP_X = 54
|
|
1146
1164
|
const CARD_GAP_Y = 38
|
|
1147
1165
|
const CANVAS_PAD = 46
|
|
@@ -1283,6 +1301,14 @@ window.__ModuleLoader__.load({
|
|
|
1283
1301
|
return next.length === folders.length && next.every((folder, index) => folder === folders[index]) ? folders : next
|
|
1284
1302
|
}
|
|
1285
1303
|
|
|
1304
|
+
/** A stable lane colour for one Session (order-independent). */
|
|
1305
|
+
function stableSessionColor(sessionId) {
|
|
1306
|
+
const value = String(sessionId ?? '')
|
|
1307
|
+
let hash = 0
|
|
1308
|
+
for (let index = 0; index < value.length; index += 1) hash = (hash * 31 + value.charCodeAt(index)) >>> 0
|
|
1309
|
+
return LANE_COLORS[hash % LANE_COLORS.length]
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1286
1312
|
/**
|
|
1287
1313
|
* Lay out branch cards left-to-right (turn chain) with one horizontal lane
|
|
1288
1314
|
* per branch Session, fork edges from the parent turn card to the child's
|
|
@@ -1322,7 +1348,7 @@ window.__ModuleLoader__.load({
|
|
|
1322
1348
|
}
|
|
1323
1349
|
for (const session of sessions) {
|
|
1324
1350
|
const lane = laneOf.get(session.sessionId) ?? 0
|
|
1325
|
-
const color =
|
|
1351
|
+
const color = stableSessionColor(session.sessionId)
|
|
1326
1352
|
const y = CANVAS_PAD + lane * (CARD_HEIGHT + CARD_GAP_Y)
|
|
1327
1353
|
const onPath = currentPath.has(session.sessionId)
|
|
1328
1354
|
const parent = session.parentSessionId ? byId.get(session.parentSessionId) : null
|
|
@@ -1460,10 +1486,13 @@ window.__ModuleLoader__.load({
|
|
|
1460
1486
|
})
|
|
1461
1487
|
for (const ordered of orderedCards) {
|
|
1462
1488
|
const card = ordered.card
|
|
1463
|
-
|
|
1489
|
+
const naturalX = x
|
|
1490
|
+
card.x = naturalX
|
|
1464
1491
|
card.y = y
|
|
1465
1492
|
pushCard(card)
|
|
1466
|
-
|
|
1493
|
+
// If the user dragged the previous card, keep the next new card after
|
|
1494
|
+
// where it actually is instead of the old automatic slot.
|
|
1495
|
+
x = Math.max(naturalX + CARD_WIDTH + CARD_GAP_X, card.x + CARD_WIDTH + CARD_GAP_X)
|
|
1467
1496
|
}
|
|
1468
1497
|
// Folders collapse member cards into one compact card until unpacked.
|
|
1469
1498
|
if (Array.isArray(folders) && folders.length > 0 && sessionCards.length > 0) {
|
|
@@ -1498,6 +1527,7 @@ window.__ModuleLoader__.load({
|
|
|
1498
1527
|
prompt: null,
|
|
1499
1528
|
note: null,
|
|
1500
1529
|
checkpoints: [],
|
|
1530
|
+
height: FOLDER_CARD_HEIGHT,
|
|
1501
1531
|
onPath: members.some((member) => member.onPath),
|
|
1502
1532
|
createdAt: members[0].createdAt ?? null,
|
|
1503
1533
|
},
|
|
@@ -1573,8 +1603,9 @@ window.__ModuleLoader__.load({
|
|
|
1573
1603
|
for (const card of cards) card.isCurrentPosition = card.key === currentKey
|
|
1574
1604
|
const minX = cards.length === 0 ? 0 : Math.min(...cards.map((card) => card.x))
|
|
1575
1605
|
const minY = cards.length === 0 ? 0 : Math.min(...cards.map((card) => card.y))
|
|
1606
|
+
const cardHeight = (card) => (card.kind === 'folder' && !card.expanded ? FOLDER_CARD_HEIGHT : CARD_HEIGHT)
|
|
1576
1607
|
const maxX = cards.length === 0 ? 320 : Math.max(...cards.map((card) => card.x + CARD_WIDTH))
|
|
1577
|
-
const maxY = cards.length === 0 ? 220 : Math.max(...cards.map((card) => card.y +
|
|
1608
|
+
const maxY = cards.length === 0 ? 220 : Math.max(...cards.map((card) => card.y + cardHeight(card)))
|
|
1578
1609
|
// Cards may carry negative coordinates after a drag. The world layer keeps
|
|
1579
1610
|
// a fixed origin (no per-frame offset feedback) so dragging behaves the
|
|
1580
1611
|
// same in every direction; the camera translate reveals negative space.
|
|
@@ -1590,7 +1621,7 @@ window.__ModuleLoader__.load({
|
|
|
1590
1621
|
}
|
|
1591
1622
|
|
|
1592
1623
|
/** One card of the conversation canvas. */
|
|
1593
|
-
function CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding }) {
|
|
1624
|
+
function CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding, onRewind }) {
|
|
1594
1625
|
const files = (card.checkpoints ?? []).reduce(
|
|
1595
1626
|
(total, checkpoint) => ({
|
|
1596
1627
|
added: total.added + (checkpoint.files?.added ?? 0),
|
|
@@ -1670,6 +1701,22 @@ window.__ModuleLoader__.load({
|
|
|
1670
1701
|
'📝',
|
|
1671
1702
|
)
|
|
1672
1703
|
: null,
|
|
1704
|
+
branchTarget && branchTarget.hasSnapshot === true && typeof onRewind === 'function'
|
|
1705
|
+
? h(
|
|
1706
|
+
'button',
|
|
1707
|
+
{
|
|
1708
|
+
type: 'button',
|
|
1709
|
+
className: 'tb-card-rewind',
|
|
1710
|
+
title: t('panel.rewind'),
|
|
1711
|
+
'aria-label': t('panel.rewind'),
|
|
1712
|
+
onClick: (event) => {
|
|
1713
|
+
event.stopPropagation()
|
|
1714
|
+
onRewind(card, branchTarget)
|
|
1715
|
+
},
|
|
1716
|
+
},
|
|
1717
|
+
'⏪',
|
|
1718
|
+
)
|
|
1719
|
+
: null,
|
|
1673
1720
|
card.createdAt ? h('span', { className: 'tb-card-time' }, clock(card.createdAt)) : null,
|
|
1674
1721
|
card.isCurrentPosition ? h('span', { className: 'tb-card-dot', title: t('panel.current') }) : null,
|
|
1675
1722
|
),
|
|
@@ -1836,6 +1883,7 @@ window.__ModuleLoader__.load({
|
|
|
1836
1883
|
onUnpackFolder,
|
|
1837
1884
|
dropTargetKey,
|
|
1838
1885
|
folding,
|
|
1886
|
+
onRewind,
|
|
1839
1887
|
expandedFolderId,
|
|
1840
1888
|
onToggleFolder,
|
|
1841
1889
|
onMemberDragStart,
|
|
@@ -1924,7 +1972,7 @@ window.__ModuleLoader__.load({
|
|
|
1924
1972
|
left: targetCard.x - 5,
|
|
1925
1973
|
top: targetCard.y - 5,
|
|
1926
1974
|
width: CARD_WIDTH + 10,
|
|
1927
|
-
height: CARD_HEIGHT + 10,
|
|
1975
|
+
height: (targetCard.kind === 'folder' ? FOLDER_CARD_HEIGHT : CARD_HEIGHT) + 10,
|
|
1928
1976
|
},
|
|
1929
1977
|
'aria-hidden': true,
|
|
1930
1978
|
},
|
|
@@ -1945,7 +1993,7 @@ window.__ModuleLoader__.load({
|
|
|
1945
1993
|
onMemberDragStart,
|
|
1946
1994
|
suppressClickRef,
|
|
1947
1995
|
})
|
|
1948
|
-
: CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding }),
|
|
1996
|
+
: CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding, onRewind }),
|
|
1949
1997
|
),
|
|
1950
1998
|
),
|
|
1951
1999
|
)
|
|
@@ -2112,6 +2160,7 @@ window.__ModuleLoader__.load({
|
|
|
2112
2160
|
return () => window.clearTimeout(timer)
|
|
2113
2161
|
}, [feedback])
|
|
2114
2162
|
const [view, setView] = React.useState('tree')
|
|
2163
|
+
const [workspaceOpen, setWorkspaceOpen] = React.useState(false)
|
|
2115
2164
|
const [selectedKey, setSelectedKey] = React.useState(null)
|
|
2116
2165
|
const [zoom, setZoom] = React.useState(1)
|
|
2117
2166
|
const [canvasExpanded, setCanvasExpanded] = React.useState(false)
|
|
@@ -2299,7 +2348,7 @@ window.__ModuleLoader__.load({
|
|
|
2299
2348
|
pruneCandidate,
|
|
2300
2349
|
})
|
|
2301
2350
|
if (action === 'prune' && result.childSessionId) openChild(result.childSessionId)
|
|
2302
|
-
if (action === 'rewind') {
|
|
2351
|
+
if (action === 'rewind' || action === 'prune') {
|
|
2303
2352
|
try {
|
|
2304
2353
|
window.dispatchEvent(new CustomEvent('dsh-timeback:board-changed'))
|
|
2305
2354
|
} catch {
|
|
@@ -2362,7 +2411,12 @@ window.__ModuleLoader__.load({
|
|
|
2362
2411
|
const world = worldRef.current
|
|
2363
2412
|
if (world) {
|
|
2364
2413
|
const camera = cameraRef.current
|
|
2365
|
-
|
|
2414
|
+
// Snap the translation to real device pixels. A fractional CSS px
|
|
2415
|
+
// offset makes the browser rasterize every card's text on a half pixel,
|
|
2416
|
+
// which is what looks "糊" on desktop WebViews.
|
|
2417
|
+
const ratio = typeof window !== 'undefined' && Number.isFinite(window.devicePixelRatio) && window.devicePixelRatio > 0 ? window.devicePixelRatio : 1
|
|
2418
|
+
const snap = (value) => Math.round(value * ratio) / ratio
|
|
2419
|
+
world.style.transform = `translate(${snap(camera.x)}px, ${snap(camera.y)}px) scale(${camera.scale})`
|
|
2366
2420
|
}
|
|
2367
2421
|
if (announceZoom) setZoom(cameraRef.current.scale)
|
|
2368
2422
|
}
|
|
@@ -2377,7 +2431,11 @@ window.__ModuleLoader__.load({
|
|
|
2377
2431
|
const height = viewport.clientHeight || 320
|
|
2378
2432
|
const spanX = Math.max(1, current.maxX - current.minX)
|
|
2379
2433
|
const spanY = Math.max(1, current.maxY - current.minY)
|
|
2380
|
-
|
|
2434
|
+
let scale = Math.min(1.15, Math.max(0.35, Math.min((width - 28) / spanX, (height - 28) / spanY)))
|
|
2435
|
+
// Prefer exactly 1x (crisp text) when the content almost fits; otherwise
|
|
2436
|
+
// quantize to 2 decimals so the world transform is not a repeating float.
|
|
2437
|
+
if (scale >= 0.92 && scale <= 1.15) scale = 1
|
|
2438
|
+
else scale = Math.round(scale * 100) / 100
|
|
2381
2439
|
cameraRef.current = {
|
|
2382
2440
|
scale,
|
|
2383
2441
|
x: (width - spanX * scale) / 2 - current.minX * scale,
|
|
@@ -2463,8 +2521,13 @@ window.__ModuleLoader__.load({
|
|
|
2463
2521
|
const clientVersion = BUILD.split('+')[0]
|
|
2464
2522
|
const serverVersion = typeof data?.serverVersion === 'string' ? data.serverVersion : null
|
|
2465
2523
|
const staleBundle = Boolean(serverVersion && clientVersion !== serverVersion)
|
|
2466
|
-
const
|
|
2467
|
-
layout?.cards.filter((card) => card.sessionId === data?.currentSessionId)
|
|
2524
|
+
const fallbackCard = (() => {
|
|
2525
|
+
const candidates = layout?.cards.filter((card) => card.sessionId === data?.currentSessionId) ?? []
|
|
2526
|
+
const latest = candidates[candidates.length - 1]
|
|
2527
|
+
if (latest?.kind === 'folder') return latest.members?.[latest.members.length - 1] ?? candidates.filter((card) => card.kind !== 'folder').slice(-1)[0] ?? latest
|
|
2528
|
+
return latest ?? candidates[candidates.length - 1] ?? layout?.cards.slice(-1)[0] ?? null
|
|
2529
|
+
})()
|
|
2530
|
+
const fallbackNode = fallbackCard && fallbackCard.kind !== 'folder' ? fallbackCard : null
|
|
2468
2531
|
const selectedNode = (selectedKey ? layout?.cards.find((card) => card.key === selectedKey) : null) ?? fallbackNode
|
|
2469
2532
|
const effectiveSelectedKey = selectedNode?.key ?? null
|
|
2470
2533
|
|
|
@@ -2606,7 +2669,7 @@ window.__ModuleLoader__.load({
|
|
|
2606
2669
|
// Dropping back on the expanded folder itself keeps the card filed.
|
|
2607
2670
|
if (
|
|
2608
2671
|
worldX >= folderCard.x && worldX <= folderCard.x + CARD_WIDTH &&
|
|
2609
|
-
worldY >= folderCard.y && worldY <= folderCard.y +
|
|
2672
|
+
worldY >= folderCard.y && worldY <= folderCard.y + FOLDER_CARD_HEIGHT
|
|
2610
2673
|
) return
|
|
2611
2674
|
detachFolderMember(folderCard.folderId, member.key, {
|
|
2612
2675
|
x: Math.round(worldX - CARD_WIDTH / 2),
|
|
@@ -2712,7 +2775,8 @@ window.__ModuleLoader__.load({
|
|
|
2712
2775
|
const candidate = cards[index]
|
|
2713
2776
|
if (candidate.key === card.key) continue
|
|
2714
2777
|
if (worldX < candidate.x || worldX > candidate.x + CARD_WIDTH) continue
|
|
2715
|
-
|
|
2778
|
+
const candidateHeight = candidate.kind === 'folder' ? FOLDER_CARD_HEIGHT : CARD_HEIGHT
|
|
2779
|
+
if (worldY < candidate.y || worldY > candidate.y + candidateHeight) continue
|
|
2716
2780
|
return candidate
|
|
2717
2781
|
}
|
|
2718
2782
|
return null
|
|
@@ -2818,6 +2882,17 @@ window.__ModuleLoader__.load({
|
|
|
2818
2882
|
})
|
|
2819
2883
|
}
|
|
2820
2884
|
|
|
2885
|
+
/** Saving close for the card-note sheet: outside clicks never discard text. */
|
|
2886
|
+
const dismissCardNoteSaving = async () => {
|
|
2887
|
+
const editor = noteEditor
|
|
2888
|
+
if (!editor || editor.busy) return
|
|
2889
|
+
if (editor.text.trim() === '' && !editor.card.note) {
|
|
2890
|
+
setNoteEditor(null)
|
|
2891
|
+
return
|
|
2892
|
+
}
|
|
2893
|
+
await saveCardNote(false)
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2821
2896
|
/** Save (or clear) the note on the card being edited. */
|
|
2822
2897
|
const saveCardNote = async (clear) => {
|
|
2823
2898
|
const editor = noteEditor
|
|
@@ -2959,7 +3034,17 @@ window.__ModuleLoader__.load({
|
|
|
2959
3034
|
),
|
|
2960
3035
|
)
|
|
2961
3036
|
: null,
|
|
2962
|
-
renderWorkspaceSection({
|
|
3037
|
+
renderWorkspaceSection({
|
|
3038
|
+
workspace: data?.workspace,
|
|
3039
|
+
gitOff,
|
|
3040
|
+
busy,
|
|
3041
|
+
t,
|
|
3042
|
+
toggleWorkspace,
|
|
3043
|
+
sessionId,
|
|
3044
|
+
onWorkspaceChanged: () => setTick((value) => value + 1),
|
|
3045
|
+
open: workspaceOpen,
|
|
3046
|
+
onToggle: () => setWorkspaceOpen((value) => !value),
|
|
3047
|
+
}),
|
|
2963
3048
|
gitOff ? h('p', { className: 'tb-note' }, t('panel.noGit')) : h('p', { className: 'tb-note' }, t('panel.warning')),
|
|
2964
3049
|
state.error ? h('div', { className: 'tb-feedback err', role: 'alert' }, `${t('panel.error')}: ${state.error}`) : null,
|
|
2965
3050
|
state.loading && !data ? h('div', { className: 'tb-empty' }, t('panel.loading')) : null,
|
|
@@ -2995,6 +3080,7 @@ window.__ModuleLoader__.load({
|
|
|
2995
3080
|
? h(
|
|
2996
3081
|
'div',
|
|
2997
3082
|
{ className: 'tb-tree-section' },
|
|
3083
|
+
renderCheckpointDetail({ node: selectedNode, layout, t, act, busy, gitOff, currentSessionId: data.currentSessionId, onNote: openCardNote }),
|
|
2998
3084
|
TreeCanvas({
|
|
2999
3085
|
layout,
|
|
3000
3086
|
t,
|
|
@@ -3003,6 +3089,7 @@ window.__ModuleLoader__.load({
|
|
|
3003
3089
|
onOpen: openSessionByCard,
|
|
3004
3090
|
onBranch: branchFromCard,
|
|
3005
3091
|
onPrune: pruneFromCard,
|
|
3092
|
+
onRewind: (card, checkpoint) => act('rewind', checkpoint, null, card.sessionId),
|
|
3006
3093
|
onNote: openCardNote,
|
|
3007
3094
|
expanded: canvasExpanded,
|
|
3008
3095
|
onToggleExpand: () => setCanvasExpanded((value) => !value),
|
|
@@ -3030,7 +3117,6 @@ window.__ModuleLoader__.load({
|
|
|
3030
3117
|
h('div', { className: 'tb-canvas-hint' }, t('tree.panHint')),
|
|
3031
3118
|
h('div', { className: 'tb-canvas-hint' }, t('tree.dragHint')),
|
|
3032
3119
|
layout.truncated ? h('div', { className: 'tb-ws-hint' }, format(t('tree.truncated'), { count: MAX_TREE_TURNS })) : null,
|
|
3033
|
-
renderCheckpointDetail({ node: selectedNode, layout, t, act, busy, gitOff, currentSessionId: data.currentSessionId, onNote: openCardNote }),
|
|
3034
3120
|
)
|
|
3035
3121
|
: h(
|
|
3036
3122
|
'div',
|
|
@@ -3060,7 +3146,7 @@ window.__ModuleLoader__.load({
|
|
|
3060
3146
|
noteEditor
|
|
3061
3147
|
? h(
|
|
3062
3148
|
'div',
|
|
3063
|
-
{ className: 'tb-overlay', onClick:
|
|
3149
|
+
{ className: 'tb-overlay', onClick: dismissCardNoteSaving },
|
|
3064
3150
|
h(
|
|
3065
3151
|
'div',
|
|
3066
3152
|
{ className: 'tb-note-dialog', role: 'dialog', 'aria-modal': true, onClick: (event) => event.stopPropagation() },
|
|
@@ -3289,11 +3375,10 @@ window.__ModuleLoader__.load({
|
|
|
3289
3375
|
}
|
|
3290
3376
|
|
|
3291
3377
|
/** Draw the per-workspace recording switch and the enabled-workspace list. */
|
|
3292
|
-
function renderWorkspaceSection({ workspace, gitOff, busy, t, toggleWorkspace, sessionId, onWorkspaceChanged }) {
|
|
3378
|
+
function renderWorkspaceSection({ workspace, gitOff, busy, t, toggleWorkspace, sessionId, onWorkspaceChanged, open, onToggle }) {
|
|
3293
3379
|
if (!workspace) return null
|
|
3294
3380
|
const cwd = workspace.cwd
|
|
3295
3381
|
const mode = workspace.mode
|
|
3296
|
-
const canToggle = mode === 'workspace' && !gitOff && Boolean(cwd) && workspace.exists !== false && busy === ''
|
|
3297
3382
|
const checked = mode === 'all' || workspace.enabled === true
|
|
3298
3383
|
const reason = gitOff
|
|
3299
3384
|
? t('panel.recordDisabledNoGit')
|
|
@@ -3304,37 +3389,16 @@ window.__ModuleLoader__.load({
|
|
|
3304
3389
|
: mode === 'off'
|
|
3305
3390
|
? t('panel.recordFixedOff')
|
|
3306
3391
|
: t('panel.recordThisHint')
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
{ className: 'tb-ws' },
|
|
3310
|
-
h(
|
|
3311
|
-
'div',
|
|
3312
|
-
{ className: 'tb-ws-row', title: reason },
|
|
3313
|
-
h(
|
|
3314
|
-
'span',
|
|
3315
|
-
{ className: 'tb-ws-text' },
|
|
3316
|
-
h('span', { className: 'tb-ws-title' }, t('panel.recordThis')),
|
|
3317
|
-
cwd ? h('span', { className: 'tb-ws-path', title: cwd }, cwd) : null,
|
|
3318
|
-
h('span', { className: 'tb-ws-hint' }, reason),
|
|
3319
|
-
),
|
|
3320
|
-
),
|
|
3321
|
-
mode === 'workspace' && cwd
|
|
3322
|
-
? h(WorkspacePathSelector, {
|
|
3323
|
-
sessionId,
|
|
3324
|
-
workspace,
|
|
3325
|
-
t,
|
|
3326
|
-
onChanged: typeof onWorkspaceChanged === 'function' ? onWorkspaceChanged : undefined,
|
|
3327
|
-
})
|
|
3328
|
-
: null,
|
|
3329
|
-
mode === 'workspace' && workspace.enabledWorkspaces?.length > 0
|
|
3392
|
+
const list = (items, kind) =>
|
|
3393
|
+
Array.isArray(items) && items.length > 0
|
|
3330
3394
|
? h(
|
|
3331
3395
|
'div',
|
|
3332
3396
|
{ className: 'tb-ws-list' },
|
|
3333
|
-
h('span', { className: 'tb-ws-hint' }, t('panel.enabledWorkspaces')),
|
|
3334
|
-
...
|
|
3397
|
+
h('span', { className: 'tb-ws-hint' }, kind === 'enabled' ? t('panel.enabledWorkspaces') : t('panel.excludedWorkspaces')),
|
|
3398
|
+
...items.map((entry) =>
|
|
3335
3399
|
h(
|
|
3336
3400
|
'div',
|
|
3337
|
-
{ key: entry.path, className: 'tb-ws-item' },
|
|
3401
|
+
{ key: kind + entry.path, className: 'tb-ws-item' },
|
|
3338
3402
|
h('span', { className: 'tb-ws-path', title: entry.path }, entry.path),
|
|
3339
3403
|
h(
|
|
3340
3404
|
'button',
|
|
@@ -3342,36 +3406,46 @@ window.__ModuleLoader__.load({
|
|
|
3342
3406
|
type: 'button',
|
|
3343
3407
|
className: 'tb-btn',
|
|
3344
3408
|
disabled: busy !== '',
|
|
3345
|
-
onClick: () => toggleWorkspace(
|
|
3409
|
+
onClick: () => toggleWorkspace(kind === 'excluded', entry.path),
|
|
3346
3410
|
},
|
|
3347
|
-
t('panel.disableThis'),
|
|
3411
|
+
kind === 'enabled' ? t('panel.disableThis') : t('panel.restoreThis'),
|
|
3348
3412
|
),
|
|
3349
3413
|
),
|
|
3350
3414
|
),
|
|
3351
3415
|
)
|
|
3352
|
-
: null
|
|
3353
|
-
|
|
3416
|
+
: null
|
|
3417
|
+
return h(
|
|
3418
|
+
'div',
|
|
3419
|
+
{ className: 'tb-ws' },
|
|
3420
|
+
h(
|
|
3421
|
+
'button',
|
|
3422
|
+
{
|
|
3423
|
+
type: 'button',
|
|
3424
|
+
className: 'tb-ws-summary',
|
|
3425
|
+
title: `${t('panel.workspaceSectionTitle')} · ${reason}`,
|
|
3426
|
+
'aria-expanded': open === true,
|
|
3427
|
+
onClick: typeof onToggle === 'function' ? onToggle : undefined,
|
|
3428
|
+
},
|
|
3429
|
+
h('span', { className: 'tb-ws-caret' }, open ? '▾' : '▸'),
|
|
3430
|
+
h('span', { className: 'tb-ws-title' }, t('panel.workspaceSectionTitle')),
|
|
3431
|
+
cwd ? h('span', { className: 'tb-ws-path', title: cwd }, cwd) : null,
|
|
3432
|
+
h('span', { className: `tb-chip ${checked ? 'ok' : 'warn'}` }, checked ? t('panel.recordOn') : t('panel.recordOff')),
|
|
3433
|
+
),
|
|
3434
|
+
open
|
|
3354
3435
|
? h(
|
|
3355
3436
|
'div',
|
|
3356
|
-
{ className: 'tb-ws-
|
|
3357
|
-
h('span', { className: 'tb-ws-
|
|
3358
|
-
|
|
3359
|
-
h(
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
disabled: busy !== '',
|
|
3369
|
-
onClick: () => toggleWorkspace(true, entry.path),
|
|
3370
|
-
},
|
|
3371
|
-
t('panel.restoreThis'),
|
|
3372
|
-
),
|
|
3373
|
-
),
|
|
3374
|
-
),
|
|
3437
|
+
{ className: 'tb-ws-body' },
|
|
3438
|
+
h('div', { className: 'tb-ws-row' }, h('span', { className: 'tb-ws-text' }, h('span', { className: 'tb-ws-hint' }, reason))),
|
|
3439
|
+
mode === 'workspace' && cwd
|
|
3440
|
+
? h(WorkspacePathSelector, {
|
|
3441
|
+
sessionId,
|
|
3442
|
+
workspace,
|
|
3443
|
+
t,
|
|
3444
|
+
onChanged: typeof onWorkspaceChanged === 'function' ? onWorkspaceChanged : undefined,
|
|
3445
|
+
})
|
|
3446
|
+
: null,
|
|
3447
|
+
list(workspace.enabledWorkspaces, 'enabled'),
|
|
3448
|
+
list(workspace.excludedWorkspaces, 'excluded'),
|
|
3375
3449
|
)
|
|
3376
3450
|
: null,
|
|
3377
3451
|
)
|
|
@@ -3708,6 +3782,22 @@ window.__ModuleLoader__.load({
|
|
|
3708
3782
|
return `#${rgb.map((value) => Math.min(255, Math.max(0, Math.round(Number(value) || 0))).toString(16).padStart(2, '0')).join('')}`
|
|
3709
3783
|
}
|
|
3710
3784
|
|
|
3785
|
+
/** Normalize any CSS color string (#rgb, #rrggbbaa, rgb()/rgba()) to #rrggbb. */
|
|
3786
|
+
function normalizeCssColor(value) {
|
|
3787
|
+
const raw = String(value || '').trim().toLowerCase()
|
|
3788
|
+
if (raw === '') return ''
|
|
3789
|
+
const short = /^#([0-9a-f]{3})$/.exec(raw)
|
|
3790
|
+
if (short) return `#${[...short[1]].map((char) => char + char).join('')}`
|
|
3791
|
+
const hex = /^#([0-9a-f]{6})(?:[0-9a-f]{2})?$/.exec(raw)
|
|
3792
|
+
if (hex) return `#${hex[1]}`
|
|
3793
|
+
const rgb = /^rgba?\(\s*([0-9.]+%?)[\s,]+([0-9.]+%?)[\s,]+([0-9.]+%?)/.exec(raw)
|
|
3794
|
+
if (rgb) {
|
|
3795
|
+
const channel = (part) => (part.endsWith('%') ? Math.round((parseFloat(part) * 255) / 100) : Math.round(parseFloat(part)))
|
|
3796
|
+
return rgbToHex([channel(rgb[1]), channel(rgb[2]), channel(rgb[3])])
|
|
3797
|
+
}
|
|
3798
|
+
return ''
|
|
3799
|
+
}
|
|
3800
|
+
|
|
3711
3801
|
const BOARD_ANCHORS = ['top', 'right', 'bottom', 'left']
|
|
3712
3802
|
|
|
3713
3803
|
function emptyBoardCanvas() {
|
|
@@ -3897,7 +3987,7 @@ window.__ModuleLoader__.load({
|
|
|
3897
3987
|
|
|
3898
3988
|
/** Inline Markdown -> HTML for the rich editor. */
|
|
3899
3989
|
function inlineMarkdownToHtml(text) {
|
|
3900
|
-
const pattern = /(<span style="color:\s
|
|
3990
|
+
const pattern = /(<span style="[^"]*color:\s*(?:#[0-9a-f]{3,8}|rgba?\([^)]*\))[^"]*">[\s\S]*?<\/span>|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|~~[^~]+~~|\*[^*\n]+\*|_[^_\n]+_)/gi
|
|
3901
3991
|
let html = ''
|
|
3902
3992
|
let last = 0
|
|
3903
3993
|
let match
|
|
@@ -3905,9 +3995,10 @@ window.__ModuleLoader__.load({
|
|
|
3905
3995
|
html += escapeHtmlText(text.slice(last, match.index))
|
|
3906
3996
|
const token = match[0]
|
|
3907
3997
|
if (token.startsWith('<span')) {
|
|
3908
|
-
const span = /^<span style="color:\s*(
|
|
3909
|
-
|
|
3910
|
-
|
|
3998
|
+
const span = /^<span style="[^"]*color:\s*([^";]+)[^"]*">([\s\S]*?)<\/span>$/i.exec(token)
|
|
3999
|
+
const color = span ? normalizeCssColor(span[1]) : ''
|
|
4000
|
+
html += color
|
|
4001
|
+
? `<span style="color:${color}">${inlineMarkdownToHtml(span[2])}</span>`
|
|
3911
4002
|
: escapeHtmlText(token)
|
|
3912
4003
|
} else if (token.startsWith('**') || token.startsWith('__')) {
|
|
3913
4004
|
html += `<strong>${inlineMarkdownToHtml(token.slice(2, -2))}</strong>`
|
|
@@ -4005,14 +4096,15 @@ window.__ModuleLoader__.load({
|
|
|
4005
4096
|
const style = node.style
|
|
4006
4097
|
if (style) {
|
|
4007
4098
|
if (typeof style === 'string') {
|
|
4008
|
-
const match = /color:\s*(
|
|
4009
|
-
if (match) return match[1]
|
|
4099
|
+
const match = /color:\s*([^;]+)/i.exec(style)
|
|
4100
|
+
if (match && normalizeCssColor(match[1])) return normalizeCssColor(match[1])
|
|
4010
4101
|
} else if (typeof style.color === 'string') {
|
|
4011
|
-
|
|
4102
|
+
const normalized = normalizeCssColor(style.color)
|
|
4103
|
+
if (normalized) return normalized
|
|
4012
4104
|
}
|
|
4013
4105
|
}
|
|
4014
4106
|
const attr = node.getAttribute ? node.getAttribute('color') : ''
|
|
4015
|
-
return
|
|
4107
|
+
return normalizeCssColor(attr)
|
|
4016
4108
|
}
|
|
4017
4109
|
const inline = (node) => {
|
|
4018
4110
|
if (!node) return ''
|
|
@@ -4085,6 +4177,7 @@ window.__ModuleLoader__.load({
|
|
|
4085
4177
|
const [mode, setMode] = React.useState('rich')
|
|
4086
4178
|
const sourceRef = React.useRef(null)
|
|
4087
4179
|
const richRef = React.useRef(null)
|
|
4180
|
+
const richRangeRef = React.useRef(null)
|
|
4088
4181
|
const lastMarkdownRef = React.useRef(null)
|
|
4089
4182
|
const valueRef = React.useRef(value)
|
|
4090
4183
|
valueRef.current = value
|
|
@@ -4099,7 +4192,21 @@ window.__ModuleLoader__.load({
|
|
|
4099
4192
|
lastMarkdownRef.current = valueRef.current
|
|
4100
4193
|
}, [])
|
|
4101
4194
|
|
|
4195
|
+
const rememberRichSelection = () => {
|
|
4196
|
+
const element = richRef.current
|
|
4197
|
+
if (!element) return
|
|
4198
|
+
try {
|
|
4199
|
+
const selection = window.getSelection()
|
|
4200
|
+
if (!selection || selection.rangeCount === 0) return
|
|
4201
|
+
const range = selection.getRangeAt(0)
|
|
4202
|
+
if (element.contains(range.commonAncestorContainer)) richRangeRef.current = range.cloneRange()
|
|
4203
|
+
} catch {
|
|
4204
|
+
// Selection APIs can be unavailable in tests.
|
|
4205
|
+
}
|
|
4206
|
+
}
|
|
4207
|
+
|
|
4102
4208
|
const syncRich = () => {
|
|
4209
|
+
rememberRichSelection()
|
|
4103
4210
|
if (composingRef.current) return
|
|
4104
4211
|
const element = richRef.current
|
|
4105
4212
|
if (!element) return
|
|
@@ -4118,11 +4225,18 @@ window.__ModuleLoader__.load({
|
|
|
4118
4225
|
const element = richRef.current
|
|
4119
4226
|
if (!element) return
|
|
4120
4227
|
try {
|
|
4121
|
-
element.focus()
|
|
4228
|
+
element.focus({ preventScroll: true })
|
|
4229
|
+
const range = richRangeRef.current
|
|
4230
|
+
if (range) {
|
|
4231
|
+
const selection = window.getSelection()
|
|
4232
|
+
selection.removeAllRanges()
|
|
4233
|
+
selection.addRange(range)
|
|
4234
|
+
}
|
|
4122
4235
|
document.execCommand(command, false, argument)
|
|
4123
4236
|
} catch {
|
|
4124
4237
|
// execCommand can be unavailable; the source tab still works.
|
|
4125
4238
|
}
|
|
4239
|
+
rememberRichSelection()
|
|
4126
4240
|
syncRich()
|
|
4127
4241
|
}
|
|
4128
4242
|
|
|
@@ -4233,7 +4347,19 @@ window.__ModuleLoader__.load({
|
|
|
4233
4347
|
'div',
|
|
4234
4348
|
{ className: 'tb-md-tools' },
|
|
4235
4349
|
...tools.map((tool) =>
|
|
4236
|
-
h(
|
|
4350
|
+
h(
|
|
4351
|
+
'button',
|
|
4352
|
+
{
|
|
4353
|
+
key: tool.key,
|
|
4354
|
+
type: 'button',
|
|
4355
|
+
className: 'tb-md-tool',
|
|
4356
|
+
title: tool.title,
|
|
4357
|
+
disabled,
|
|
4358
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
4359
|
+
onClick: tool.run,
|
|
4360
|
+
},
|
|
4361
|
+
tool.label,
|
|
4362
|
+
),
|
|
4237
4363
|
),
|
|
4238
4364
|
),
|
|
4239
4365
|
h(
|
|
@@ -4260,6 +4386,7 @@ window.__ModuleLoader__.load({
|
|
|
4260
4386
|
title: color,
|
|
4261
4387
|
style: { background: color },
|
|
4262
4388
|
disabled,
|
|
4389
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
4263
4390
|
onClick: () => applyColor(color),
|
|
4264
4391
|
}),
|
|
4265
4392
|
),
|
|
@@ -4291,8 +4418,12 @@ window.__ModuleLoader__.load({
|
|
|
4291
4418
|
'aria-multiline': 'true',
|
|
4292
4419
|
'data-placeholder': props?.placeholder || '',
|
|
4293
4420
|
onInput: syncRich,
|
|
4421
|
+
onMouseUp: rememberRichSelection,
|
|
4294
4422
|
onBlur: syncRich,
|
|
4295
|
-
onKeyUp:
|
|
4423
|
+
onKeyUp: () => {
|
|
4424
|
+
rememberRichSelection()
|
|
4425
|
+
syncRich()
|
|
4426
|
+
},
|
|
4296
4427
|
onCompositionStart: () => {
|
|
4297
4428
|
composingRef.current = true
|
|
4298
4429
|
},
|
|
@@ -4344,6 +4475,8 @@ window.__ModuleLoader__.load({
|
|
|
4344
4475
|
|
|
4345
4476
|
function BoardPanel(props) {
|
|
4346
4477
|
const t = typeof props?.t === 'function' ? props.t : (key) => key
|
|
4478
|
+
const boardSessionId = typeof props?.sessionId === 'string' ? props.sessionId : ''
|
|
4479
|
+
const boardScope = (body) => (boardSessionId ? { ...body, sessionId: boardSessionId } : body)
|
|
4347
4480
|
const [state, setState] = React.useState({ loading: true, board: null, error: null })
|
|
4348
4481
|
const [draft, setDraft] = React.useState(null)
|
|
4349
4482
|
const [busy, setBusy] = React.useState('')
|
|
@@ -4434,7 +4567,7 @@ window.__ModuleLoader__.load({
|
|
|
4434
4567
|
|
|
4435
4568
|
const refresh = React.useCallback(async () => {
|
|
4436
4569
|
try {
|
|
4437
|
-
const body = await request(
|
|
4570
|
+
const body = await request(`notes${boardSessionId ? `?session=${encodeURIComponent(boardSessionId)}` : ''}`)
|
|
4438
4571
|
const board = body.board ?? null
|
|
4439
4572
|
setState({ loading: false, board, error: null })
|
|
4440
4573
|
if (board) {
|
|
@@ -4445,7 +4578,7 @@ window.__ModuleLoader__.load({
|
|
|
4445
4578
|
} catch (error) {
|
|
4446
4579
|
setState((previous) => ({ ...previous, loading: false, error: error?.message || String(error) }))
|
|
4447
4580
|
}
|
|
4448
|
-
}, [])
|
|
4581
|
+
}, [boardSessionId])
|
|
4449
4582
|
|
|
4450
4583
|
React.useEffect(() => {
|
|
4451
4584
|
refresh()
|
|
@@ -4601,7 +4734,7 @@ window.__ModuleLoader__.load({
|
|
|
4601
4734
|
saveTimerRef.current = setTimeout(async () => {
|
|
4602
4735
|
saveTimerRef.current = null
|
|
4603
4736
|
try {
|
|
4604
|
-
const body = await request('action', { method: 'POST', body: { action: 'board-canvas', canvas: next } })
|
|
4737
|
+
const body = await request('action', { method: 'POST', body: boardScope({ action: 'board-canvas', canvas: next }) })
|
|
4605
4738
|
setState((previous) => ({ ...previous, board: body.board ?? previous.board, error: null }))
|
|
4606
4739
|
} catch (error) {
|
|
4607
4740
|
setState((previous) => ({ ...previous, error: error?.message || String(error) }))
|
|
@@ -4617,7 +4750,7 @@ window.__ModuleLoader__.load({
|
|
|
4617
4750
|
clearTimeout(saveTimerRef.current)
|
|
4618
4751
|
saveTimerRef.current = null
|
|
4619
4752
|
}
|
|
4620
|
-
const body = await request('action', { method: 'POST', body: { action: 'board-canvas', canvas: next } })
|
|
4753
|
+
const body = await request('action', { method: 'POST', body: boardScope({ action: 'board-canvas', canvas: next }) })
|
|
4621
4754
|
setState((previous) => ({ ...previous, board: body.board ?? previous.board, error: null }))
|
|
4622
4755
|
return body
|
|
4623
4756
|
}
|
|
@@ -4736,6 +4869,15 @@ window.__ModuleLoader__.load({
|
|
|
4736
4869
|
const closeDraft = () => {
|
|
4737
4870
|
if (draft && !draft.busy) setDraft(null)
|
|
4738
4871
|
}
|
|
4872
|
+
/** Clicking the dimmed area saves instead of silently discarding the note. */
|
|
4873
|
+
const dismissDraftSaving = async () => {
|
|
4874
|
+
if (!draft || draft.busy) return
|
|
4875
|
+
if (draft.title.trim() === '' && draft.body.trim() === '') {
|
|
4876
|
+
setDraft(null)
|
|
4877
|
+
return
|
|
4878
|
+
}
|
|
4879
|
+
await saveDraft()
|
|
4880
|
+
}
|
|
4739
4881
|
const focusEntry = (id) => {
|
|
4740
4882
|
setSelected(id)
|
|
4741
4883
|
try {
|
|
@@ -4750,7 +4892,7 @@ window.__ModuleLoader__.load({
|
|
|
4750
4892
|
try {
|
|
4751
4893
|
const body = await request('action', {
|
|
4752
4894
|
method: 'POST',
|
|
4753
|
-
body: { action: 'note-save', ...(draft.id ? { id: draft.id } : {}), title: draft.title, body: draft.body },
|
|
4895
|
+
body: boardScope({ action: 'note-save', ...(draft.id ? { id: draft.id } : {}), title: draft.title, body: draft.body }),
|
|
4754
4896
|
})
|
|
4755
4897
|
let board = body.board ?? state.board
|
|
4756
4898
|
setState({ loading: false, board, error: null })
|
|
@@ -4794,7 +4936,7 @@ window.__ModuleLoader__.load({
|
|
|
4794
4936
|
if (!confirmed) return
|
|
4795
4937
|
setBusy(id)
|
|
4796
4938
|
try {
|
|
4797
|
-
const body = await request('action', { method: 'POST', body: { action: 'note-delete', id } })
|
|
4939
|
+
const body = await request('action', { method: 'POST', body: boardScope({ action: 'note-delete', id }) })
|
|
4798
4940
|
setState({ loading: false, board: body.board ?? state.board, error: null })
|
|
4799
4941
|
const next = cloneBoardCanvas(canvasRef.current)
|
|
4800
4942
|
delete next.notes[id]
|
|
@@ -5742,7 +5884,7 @@ window.__ModuleLoader__.load({
|
|
|
5742
5884
|
draft
|
|
5743
5885
|
? h(
|
|
5744
5886
|
'div',
|
|
5745
|
-
{ className: 'tb-overlay center', onClick:
|
|
5887
|
+
{ className: 'tb-overlay center', onClick: dismissDraftSaving },
|
|
5746
5888
|
h(
|
|
5747
5889
|
'div',
|
|
5748
5890
|
{
|
|
@@ -5804,7 +5946,7 @@ window.__ModuleLoader__.load({
|
|
|
5804
5946
|
disabled: draft.busy,
|
|
5805
5947
|
placeholder: t('board.bodyPlaceholder'),
|
|
5806
5948
|
}),
|
|
5807
|
-
h('div', { className: 'tb-ws-hint' }, t('board.resizeHint')),
|
|
5949
|
+
h('div', { className: 'tb-ws-hint' }, `${t('board.resizeHint')} · ${t('board.autosaveHint')}`),
|
|
5808
5950
|
draft.error ? h('div', { className: 'tb-feedback err' }, format(t('board.error'), { error: draft.error })) : null,
|
|
5809
5951
|
h(
|
|
5810
5952
|
'div',
|
|
@@ -5832,6 +5974,7 @@ window.__ModuleLoader__.load({
|
|
|
5832
5974
|
window.__TIMEBACK_TEST__.domToMarkdown = domToMarkdown
|
|
5833
5975
|
window.__TIMEBACK_TEST__.turnRows = turnRows
|
|
5834
5976
|
window.__TIMEBACK_TEST__.mergeCardFolder = mergeCardFolder
|
|
5977
|
+
window.__TIMEBACK_TEST__.stableSessionColor = stableSessionColor
|
|
5835
5978
|
window.__TIMEBACK_TEST__.removeFolderMember = removeFolderMember
|
|
5836
5979
|
window.__TIMEBACK_TEST__.layoutTree = layoutTree
|
|
5837
5980
|
window.__TIMEBACK_TEST__.CanvasFolderCard = CanvasFolderCard
|