dsh-timeback 0.7.4 → 0.7.6

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/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.4+sticky'
26
+ const BUILD = '0.7.6+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. */
@@ -119,6 +119,7 @@ window.__ModuleLoader__.load({
119
119
  'md.empty': '空文档,直接输入即可',
120
120
  'md.hint': '直接打字即可:选中文字后点工具栏按钮会立即格式化(例如选中“你好”按 B 立即加粗);也可切换源码/预览。',
121
121
  'board.newSticky': '新建便签',
122
+ 'board.stickyColor': '便签颜色',
122
123
  'board.stickyHint': '便签可拖动;画笔可在方格纸背景或便签上绘制,橡皮擦除笔画。',
123
124
  'board.resizeNote': '拖动缩放便签',
124
125
  'board.drawOnSticky': '便签可画',
@@ -181,6 +182,7 @@ window.__ModuleLoader__.load({
181
182
  'board.deleted': '记录已删除',
182
183
  'board.count': '{count} 条记录 · 版本 v{version}',
183
184
  'board.resetSize': '默认大小',
185
+ 'board.autosaveHint': '点击弹窗外会自动保存',
184
186
  'board.resizeHint': '可拖拽弹框右边缘、下边缘或右下角调整大小',
185
187
  'board.error': '记录板操作失败:{error}',
186
188
  'board.agentHint': '提示:让会话调用 timeback_note 工具即可把结论写进记录板;回溯时记录板会一起回退。',
@@ -345,7 +347,7 @@ window.__ModuleLoader__.load({
345
347
  'note.saved': 'Card note saved',
346
348
  'note.removed': 'Card note deleted',
347
349
  'board.title': 'Notes board',
348
- 'board.subtitle': 'Global Markdown notes · rewinds restore them too',
350
+ 'board.subtitle': 'This workspace’s Markdown notes · rewinds restore them too',
349
351
  'md.bold': 'Bold',
350
352
  'md.italic': 'Italic',
351
353
  'md.strike': 'Strikethrough',
@@ -367,7 +369,8 @@ window.__ModuleLoader__.load({
367
369
  'md.empty': 'Empty document — just start typing',
368
370
  '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.',
369
371
  'board.newSticky': 'New sticky',
370
- 'board.stickyHint': 'Sticky notes are draggable; draw on the grid or on a note, erase strokes with the eraser.',
372
+ 'board.stickyColor': 'Sticky colour',
373
+ '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.',
371
374
  'board.resizeNote': 'Drag to resize the sticky',
372
375
  'board.drawOnSticky': 'Draw on stickies',
373
376
  'board.drawOnStickyOn': 'Sticky drawing: on',
@@ -429,6 +432,7 @@ window.__ModuleLoader__.load({
429
432
  'board.deleted': 'Note deleted',
430
433
  'board.count': '{count} notes · version v{version}',
431
434
  'board.resetSize': 'Default size',
435
+ 'board.autosaveHint': 'Clicking outside the dialog saves automatically',
432
436
  'board.resizeHint': 'Drag the right edge, bottom edge or bottom-right corner to resize',
433
437
  'board.error': 'Notes board failed: {error}',
434
438
  'board.agentHint': 'Tip: ask the session to use the timeback_note tool; rewinds roll the board back with the conversation.',
@@ -581,7 +585,7 @@ window.__ModuleLoader__.load({
581
585
  .tb-ws-item{display:flex;align-items:center;gap:6px;font-size:11.5px}
582
586
  .tb-ws-item .tb-ws-path{flex:1}
583
587
  .tb-note{margin:0;padding:7px 9px;border-radius:7px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));color:var(--dsw-alias-label-secondary,#9aa0a6);font-size:11px;line-height:1.5}
584
- .tb-feedback{position:sticky;top:0;z-index:2;padding:7px 9px;border-radius:7px;font-size:11.5px;line-height:1.55;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));background:var(--dsw-alias-bg-layer-1,rgba(28,32,40,.96));display:flex;flex-direction:column;gap:6px}
588
+ .tb-feedback{position:relative;padding:7px 9px;border-radius:7px;font-size:11.5px;line-height:1.55;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));background:var(--dsw-alias-bg-layer-1,rgba(28,32,40,.96));display:flex;flex-direction:column;gap:6px}
585
589
  .tb-feedback.ok{color:var(--dsw-alias-state-success-primary,#3ecf8e);border-color:var(--dsw-alias-state-success-primary,rgba(62,207,142,.4))}
586
590
  .tb-feedback.warn{color:var(--dsw-alias-state-warning-primary,#f0b23e);border-color:var(--dsw-alias-state-warning-primary,rgba(240,178,62,.45))}
587
591
  .tb-feedback.err{color:var(--dsw-alias-state-error-primary,#ff7a59);border-color:var(--dsw-alias-state-error-primary,rgba(255,122,89,.45))}
@@ -607,6 +611,7 @@ window.__ModuleLoader__.load({
607
611
  .tb-canvas-toolbar{position:absolute;top:8px;right:8px;z-index:3;display:flex;gap:4px;align-items:center;background:var(--dsw-alias-bg-layer-2,rgba(24,28,36,.85));border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));border-radius:8px;padding:3px;backdrop-filter:blur(4px)}
608
612
  .tb-canvas-btn{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-secondary,#9aa0a6);border-radius:6px;min-width:22px;height:22px;padding:0 6px;font-size:11.5px;cursor:pointer;line-height:1}
609
613
  .tb-canvas-btn.off{opacity:.5}
614
+ .tb-canvas-hint{font-size:10.5px;line-height:20px;color:var(--dsw-alias-label-tertiary,#8a919c);margin-left:3px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:300px}
610
615
  .tb-canvas-btn.on{color:var(--dsw-alias-state-success-primary,#3ecf8e)}
611
616
  .tb-canvas-btn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.1));color:var(--dsw-alias-label-primary,#e6e6e6)}
612
617
  .tb-world{position:absolute;left:0;top:0;transform-origin:0 0}
@@ -616,31 +621,61 @@ window.__ModuleLoader__.load({
616
621
  .tb-link.current{stroke-width:2.6;opacity:1;filter:drop-shadow(0 0 3px currentColor)}
617
622
  .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}
618
623
  .tb-lane-label.current{opacity:1;font-weight:600}
619
- .tb-card{position:absolute;width:246px;height:116px;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}
624
+ .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}
620
625
  .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}
621
626
  .tb-card:hover{transform:translateY(-1px);box-shadow:0 6px 16px rgba(0,0,0,.26)}
627
+ .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}
628
+ .tb-folder-slot span{font-size:10.5px;color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff);background:var(--dsw-alias-bg-base,#16181d);border-radius:999px;padding:2px 8px;white-space:nowrap}
629
+ .tb-card.tb-drop-target{z-index:2;transform:scale(.9);opacity:.42;filter:blur(.8px);border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);box-shadow:0 0 0 2px color-mix(in srgb, var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6) 45%, transparent)}
630
+ .tb-card.tb-folding{z-index:3;transform:scale(.42);opacity:0;filter:blur(1.4px);transition:transform .22s cubic-bezier(.4,0,.6,1),opacity .22s ease,filter .22s ease}
631
+ .tb-card.folder{animation:tb-folder-pop .24s cubic-bezier(.2,.9,.25,1.25)}
632
+ .tb-card.folder .tb-folder-member{animation:tb-folder-member-in .22s ease-out both}
633
+ @keyframes tb-slot-in{from{opacity:0;transform:scale(.94)}to{opacity:1;transform:scale(1)}}
634
+ @keyframes tb-folder-pop{from{opacity:0;transform:scale(.72);filter:blur(1px)}to{opacity:1;transform:scale(1);filter:blur(0)}}
635
+ @keyframes tb-folder-member-in{from{opacity:0;transform:translateX(-4px)}to{opacity:1;transform:none}}
636
+ @media (prefers-reduced-motion: reduce){.tb-folder-slot,.tb-card.folder,.tb-card.folder .tb-folder-member{animation:none}.tb-card.tb-folding{transition:none}}
622
637
  .tb-card.onpath{border-color:color-mix(in srgb, var(--tb-color,#4d7cfe) 55%, transparent)}
623
638
  .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)}
624
639
  .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)}
625
640
  .tb-card-head{display:flex;align-items:center;gap:6px;min-height:18px}
626
- .tb-card-branch{font-size:10.5px;color:var(--dsw-alias-label-secondary,#9aa0a6);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:96px;line-height:16px}
627
- .tb-card-badge{font-size:10.5px;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
+ .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}
642
+ .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}
628
643
  .tb-card-spacer{flex:1}
629
644
  .tb-card-time{font-size:10px;color:var(--dsw-alias-label-tertiary,#8a919c);white-space:nowrap}
630
645
  .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)}
631
- .tb-card-prompt{font-size:11.5px;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}
646
+ .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}
632
647
  .tb-card-foot{display:flex;align-items:center;gap:5px;flex-wrap:wrap;font-size:10px;min-height:16px}
633
648
  .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)}
634
649
  .tb-card-chip.manual{border-style:dashed}
635
650
  .tb-card-chip.warn{color:var(--dsw-alias-state-warning-primary,#f0b23e);border-color:currentColor}
636
- .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:9.5px;cursor:pointer;white-space:nowrap}
651
+ .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}
637
652
  .tb-card-action:hover{background:color-mix(in srgb, var(--tb-color,#4d7cfe) 24%, transparent)}
653
+ .tb-card.folder{border-style:dashed;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.05))}
654
+ .tb-card.folder:not(.expanded){height:172px}
655
+ .tb-card.folder>.tb-card-head,.tb-card.folder>.tb-card-prompt,.tb-card.folder>.tb-card-foot{flex:0 0 auto}
656
+ .tb-card.folder:not(.expanded)>.tb-folder-members{flex:1;min-height:0}
657
+ .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))}
658
+ .tb-folder-expanded{display:flex;flex-direction:column;gap:3px;overflow:auto;min-height:0}
659
+ .tb-folder-hint{font-size:10px;line-height:1.4;color:var(--dsw-alias-label-tertiary,#8a919c);margin-bottom:1px}
660
+ .tb-folder-row{display:flex;gap:7px;align-items:flex-start;padding:3px 6px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));border-radius:5px;background:var(--dsw-alias-bg-base,rgba(0,0,0,.18));cursor:grab;touch-action:none}
661
+ .tb-folder-row:hover{border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
662
+ .tb-folder-row:active{cursor:grabbing}
663
+ .tb-folder-row-label{flex:0 0 auto;font-size:10.5px;font-weight:600;color:var(--dsw-alias-label-primary,#e6e6e6);line-height:1.45}
664
+ .tb-folder-row-prompt{flex:1;min-width:0;font-size:10.5px;line-height:1.45;color:var(--dsw-alias-label-secondary,#9aa0a6);white-space:normal;word-break:break-word}
665
+ .tb-folder-ghost{position:fixed;z-index:10000;pointer-events:none;max-width:320px;padding:5px 8px;border-radius:8px;border:1px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);background:var(--dsw-alias-bg-layer-2,rgba(28,32,40,.98));box-shadow:0 10px 26px rgba(0,0,0,.4);display:flex;gap:6px;font-size:11px}
666
+ .tb-folder-ghost-label{font-weight:700;color:var(--dsw-alias-label-primary,#e6e6e6);white-space:nowrap}
667
+ .tb-folder-ghost-prompt{color:var(--dsw-alias-label-secondary,#9aa0a6);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
668
+ .tb-folder-ghost.dropping{animation:tb-ghost-drop .2s ease-in forwards}
669
+ @keyframes tb-card-fade{from{opacity:0}to{opacity:1}}
670
+ @keyframes tb-ghost-drop{to{opacity:0;transform:scale(.18) translateY(2px);filter:blur(1px)}}
671
+ .tb-folder-members{display:flex;flex-direction:column;gap:2px;overflow:hidden;flex:1;min-height:0}
672
+ .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))}
638
673
  .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)}
639
674
  .tb-card-action.danger:hover{background:color-mix(in srgb, var(--dsw-alias-state-error-primary,#ff7a59) 22%, transparent)}
640
675
  .tb-card:active{cursor:grabbing}
641
- .tb-card-note{font-size:10.5px;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}
676
+ .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}
642
677
  .tb-card-prompt.withnote{-webkit-line-clamp:1;font-size:11px}
643
- .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:9.5px;cursor:pointer;white-space:nowrap}
678
+ .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}
644
679
  .tb-card-editnote:hover{color:var(--dsw-alias-label-primary,#e6e6e6)}
645
680
  .tb-card-editnote.has{color:var(--tb-color,#4d7cfe);border-color:color-mix(in srgb, var(--tb-color,#4d7cfe) 50%, transparent)}
646
681
  .tb-overlay{position:fixed;inset:0;z-index:60;background:rgba(0,0,0,.35);display:flex;justify-content:flex-end;align-items:stretch}
@@ -679,7 +714,7 @@ window.__ModuleLoader__.load({
679
714
  .tb-hex-row input[type=text]{flex:1;min-width:0;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.05));color:var(--dsw-alias-label-primary,#e6e6e6);border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));border-radius:5px;padding:3px 6px;font-size:11px;font-family:ui-monospace,monospace}
680
715
  .tb-swatch{width:18px;height:18px;border-radius:50%;border:2px solid transparent;cursor:pointer;padding:0}
681
716
  .tb-swatch.on{border-color:var(--dsw-alias-label-primary,#e6e6e6);box-shadow:0 0 0 2px rgba(0,0,0,.3)}
682
- .tb-board-canvas{position:relative;touch-action:none;flex:1;min-height:240px;overflow:auto;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));background:var(--dsw-alias-bg-base,#16181d);cursor:crosshair}
717
+ .tb-board-canvas{position:relative;touch-action:none;flex:1;min-height:240px;overflow:auto;scrollbar-gutter:stable;overscroll-behavior:contain;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));background:var(--dsw-alias-bg-base,#16181d);cursor:crosshair}
683
718
  .tb-board-canvas.select{cursor:grab}
684
719
  .tb-board-canvas.draw,.tb-board-canvas.draw .tb-sticky{cursor:crosshair}
685
720
  .tb-board-canvas.link,.tb-board-canvas.link .tb-sticky{cursor:crosshair}
@@ -693,8 +728,8 @@ window.__ModuleLoader__.load({
693
728
  .tb-board-edge-preview{fill:none;stroke-dasharray:6 5;stroke-width:2;opacity:.7}
694
729
  .tb-board-canvas.draw .tb-sticky-resize{cursor:nwse-resize}
695
730
  .tb-board-canvas.select:active{cursor:grabbing}
696
- .tb-board-world{position:relative;flex:none}
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}
731
+ .tb-board-world{position:relative;flex:none;contain:layout paint}
732
+ .tb-board-stage{position:absolute;left:0;top:0;transform-origin:0 0;will-change:transform;backface-visibility:hidden;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}
698
733
  .tb-board-bgdraw{position:absolute;left:0;top:0;pointer-events:none;overflow:visible}
699
734
  .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}
700
735
  .tb-sticky:active{cursor:grabbing}
@@ -705,13 +740,30 @@ window.__ModuleLoader__.load({
705
740
  .tb-sticky-actions{display:flex;gap:3px;opacity:.65}
706
741
  .tb-sticky-actions button{appearance:none;border:0;background:rgba(0,0,0,.08);border-radius:4px;font-size:10px;line-height:16px;padding:0 4px;cursor:pointer;color:#2a2418}
707
742
  .tb-sticky-actions button:hover{background:rgba(0,0,0,.16)}
708
- .tb-sticky-body{flex:1;min-height:0;overflow:hidden;font-size:11px;line-height:1.45;color:#3a3326;word-break:break-word;position:relative;z-index:2;pointer-events:none}
709
- .tb-sticky-body.md{display:-webkit-box;-webkit-line-clamp:5;-webkit-box-orient:vertical}
710
- .tb-sticky-linkline{display:flex;align-items:center;gap:6px;font-size:12px;font-weight:600;color:#1c4d8f;text-decoration:underline;cursor:pointer;background:rgba(255,255,255,.35);border-radius:5px;padding:6px 8px}
743
+ .tb-sticky-body{flex:1;min-height:0;overflow:hidden;font-size:11px;line-height:1.45;color:#3a3326;word-break:break-word;position:relative;z-index:2;pointer-events:none;display:flex;flex-direction:column;gap:4px}
744
+ .tb-sticky-md{flex:1;min-height:0;overflow:hidden;color:#2a2418;font-size:11.5px;line-height:1.42;word-break:break-word}
745
+ .tb-sticky-md>*:first-child{margin-top:0}
746
+ .tb-sticky-md>*:last-child{margin-bottom:0}
747
+ .tb-sticky-md h1,.tb-sticky-md h2,.tb-sticky-md h3,.tb-sticky-md h4,.tb-sticky-md h5,.tb-sticky-md h6{margin:3px 0 1px;line-height:1.25;font-weight:700}
748
+ .tb-sticky-md h1{font-size:16px}.tb-sticky-md h2{font-size:14px}.tb-sticky-md h3{font-size:12.5px}.tb-sticky-md h4,.tb-sticky-md h5,.tb-sticky-md h6{font-size:11.5px}
749
+ .tb-sticky-md p{margin:2px 0}
750
+ .tb-sticky-md ul,.tb-sticky-md ol{margin:2px 0;padding-left:16px}
751
+ .tb-sticky-md li{margin:1px 0}
752
+ .tb-sticky-md blockquote{margin:2px 0;padding-left:6px;border-left:2px solid rgba(0,0,0,.25);opacity:.8}
753
+ .tb-sticky-md code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;background:rgba(0,0,0,.08);border-radius:3px;padding:0 2px;font-size:10.5px}
754
+ .tb-sticky-md pre{margin:3px 0;padding:4px 6px;background:rgba(0,0,0,.1);border-radius:4px;font-size:10px;line-height:1.35;overflow:hidden;white-space:pre-wrap}
755
+ .tb-sticky-md a{color:#1c4d8f;text-decoration:underline}
756
+ .tb-sticky-md hr{border:0;border-top:1px solid rgba(0,0,0,.2);margin:4px 0}
757
+ .tb-sticky-linkline{display:flex;align-items:center;gap:6px;font-size:12px;font-weight:600;color:#1c4d8f;text-decoration:underline;cursor:pointer;background:rgba(255,255,255,.35);border-radius:5px;padding:6px 8px;pointer-events:auto;flex:0 0 auto}
711
758
  .tb-sticky-src{font-size:9.5px;font-weight:600;opacity:.6;white-space:nowrap}
712
759
  .tb-sticky-draw{position:absolute;inset:0;pointer-events:none;z-index:3}
713
760
  .tb-sticky-head{position:relative;z-index:4}
714
761
  .tb-sticky-resize{position:absolute;right:0;bottom:0;width:16px;height:16px;cursor:nwse-resize;z-index:6;opacity:.55}
762
+ .tb-sticky-color-row{display:flex;align-items:center;gap:6px;flex-wrap:nowrap;padding:4px 5px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));border-radius:7px;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.03))}
763
+ .tb-sticky-color-btn{width:26px;height:26px;min-width:26px;min-height:26px;padding:0;border-radius:5px;border:2px solid transparent;box-shadow:inset 0 0 0 1px rgba(0,0,0,.18);cursor:pointer;flex:0 0 auto;box-sizing:border-box}
764
+ .tb-sticky-color-btn.on{border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff);box-shadow:0 0 0 1px var(--dsw-alias-bg-base,#16181d),inset 0 0 0 1px rgba(0,0,0,.18)}
765
+ .tb-sticky-color-input{width:30px;height:26px;min-width:30px;min-height:26px;padding:2px;box-sizing:border-box;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.24));border-radius:5px;background:transparent;cursor:pointer;flex:0 0 auto}
766
+ .tb-sticky-color-preview{width:26px;height:26px;min-width:26px;border-radius:5px;border:1px solid rgba(0,0,0,.25);box-shadow:inset 0 0 0 1px rgba(255,255,255,.18)}
715
767
  .tb-sticky-resize:after{content:"";position:absolute;right:3px;bottom:3px;width:8px;height:8px;border-right:2px solid rgba(0,0,0,.45);border-bottom:2px solid rgba(0,0,0,.45)}
716
768
  .tb-sticky:hover .tb-sticky-resize{opacity:.9}
717
769
  .tb-sticky-linkline,.tb-sticky-actions{position:relative;z-index:4}
@@ -1063,11 +1115,20 @@ window.__ModuleLoader__.load({
1063
1115
  const order = { after: 3, before: 1, manual: 4, inherited: 0, safety: 5 }
1064
1116
  const rows = checkpoints.map((checkpoint) => ({ key: checkpoint.id, checkpoint }))
1065
1117
  rows.sort((left, right) => {
1066
- const turnDelta = (left.checkpoint.turn ?? -1) - (right.checkpoint.turn ?? -1)
1118
+ const leftCheckpoint = left.checkpoint
1119
+ const rightCheckpoint = right.checkpoint
1120
+ // A manual checkpoint created between turns has no turn number; order it
1121
+ // by creation time instead of forcing it below every turn.
1122
+ if (!Number.isInteger(leftCheckpoint.turn) || !Number.isInteger(rightCheckpoint.turn)) {
1123
+ const timeDelta = (rightCheckpoint.createdAt ?? 0) - (leftCheckpoint.createdAt ?? 0)
1124
+ if (timeDelta !== 0) return timeDelta
1125
+ return (rightCheckpoint.seq ?? 0) - (leftCheckpoint.seq ?? 0)
1126
+ }
1127
+ const turnDelta = leftCheckpoint.turn - rightCheckpoint.turn
1067
1128
  if (turnDelta !== 0) return -turnDelta
1068
- const phaseDelta = (order[left.checkpoint.phase] ?? 2) - (order[right.checkpoint.phase] ?? 2)
1129
+ const phaseDelta = (order[leftCheckpoint.phase] ?? 2) - (order[rightCheckpoint.phase] ?? 2)
1069
1130
  if (phaseDelta !== 0) return -phaseDelta
1070
- return (right.checkpoint.createdAt ?? 0) - (left.checkpoint.createdAt ?? 0)
1131
+ return (rightCheckpoint.createdAt ?? 0) - (leftCheckpoint.createdAt ?? 0)
1071
1132
  })
1072
1133
  return {
1073
1134
  rows: rows.slice(0, MAX_ROWS),
@@ -1086,6 +1147,8 @@ window.__ModuleLoader__.load({
1086
1147
  /** Card dimensions and spacing of the conversation canvas. */
1087
1148
  const CARD_WIDTH = 246
1088
1149
  const CARD_HEIGHT = 116
1150
+ /** Collapsed folder cards are taller so member rows and the footer never clip. */
1151
+ const FOLDER_CARD_HEIGHT = 172
1089
1152
  const CARD_GAP_X = 54
1090
1153
  const CARD_GAP_Y = 38
1091
1154
  const CANVAS_PAD = 46
@@ -1153,13 +1216,87 @@ window.__ModuleLoader__.load({
1153
1216
  return { x: leftDepth - rightDepth, y: topDepth - bottomDepth }
1154
1217
  }
1155
1218
 
1219
+ /** Remove one card from a folder; a folder with <2 members dissolves. */
1220
+ function removeFolderMember(folders, folderId, memberKey) {
1221
+ if (!Array.isArray(folders)) return folders
1222
+ let changed = false
1223
+ const next = []
1224
+ for (const folder of folders) {
1225
+ if (folder.id !== folderId) {
1226
+ next.push(folder)
1227
+ continue
1228
+ }
1229
+ const members = uniqueKeys(folder.members ?? []).filter((key) => key !== memberKey)
1230
+ changed = changed || members.length !== (folder.members?.length ?? 0)
1231
+ if (members.length >= 2) next.push({ ...folder, members })
1232
+ }
1233
+ return changed ? next : folders
1234
+ }
1235
+
1236
+ /** Unique keys in order. */
1237
+ function uniqueKeys(values) {
1238
+ const seen = new Set()
1239
+ return values.filter((value) => {
1240
+ if (typeof value !== 'string' || seen.has(value)) return false
1241
+ seen.add(value)
1242
+ return true
1243
+ })
1244
+ }
1245
+
1246
+ /**
1247
+ * Merge a dragged card/folder into a drop target underneath it.
1248
+ * Returns the same array reference when the drop is a no-op (different
1249
+ * sessions, same card, same folder), so callers can keep normal dragging.
1250
+ * @param {object[]} folders - saved folders for this branch family.
1251
+ * @param {object} source - dragged layout card.
1252
+ * @param {object} target - layout card/folder under the pointer.
1253
+ */
1254
+ function mergeCardFolder(folders, source, target) {
1255
+ if (!source || !target || source.key === target.key) return folders
1256
+ if (!source.sessionId || !target.sessionId || source.sessionId !== target.sessionId) return folders
1257
+ if (!Array.isArray(folders)) return folders
1258
+ const list = folders.map((folder) => ({ ...folder, members: uniqueKeys(folder.members ?? []) }))
1259
+ const sourceFolder = source.kind === 'folder' ? list.find((folder) => folder.id === source.folderId) : null
1260
+ const targetFolder = target.kind === 'folder' ? list.find((folder) => folder.id === target.folderId) : null
1261
+ if (sourceFolder && targetFolder && sourceFolder.id === targetFolder.id) return folders
1262
+ let host = null
1263
+ if (sourceFolder && targetFolder) {
1264
+ targetFolder.members = uniqueKeys([...targetFolder.members, ...sourceFolder.members])
1265
+ host = targetFolder
1266
+ const index = list.indexOf(sourceFolder)
1267
+ if (index !== -1) list.splice(index, 1)
1268
+ } else if (sourceFolder) {
1269
+ sourceFolder.members = uniqueKeys([...sourceFolder.members, target.key])
1270
+ host = sourceFolder
1271
+ } else if (targetFolder) {
1272
+ targetFolder.members = uniqueKeys([...targetFolder.members, source.key])
1273
+ host = targetFolder
1274
+ } else {
1275
+ host = {
1276
+ id: `fold-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
1277
+ members: uniqueKeys([target.key, source.key]),
1278
+ x: Number.isFinite(target.x) ? target.x : 0,
1279
+ y: Number.isFinite(target.y) ? target.y : 0,
1280
+ createdAt: Date.now(),
1281
+ }
1282
+ list.push(host)
1283
+ }
1284
+ // One card belongs to exactly one folder; drop duplicates from the others.
1285
+ for (const folder of list) {
1286
+ if (folder === host) continue
1287
+ folder.members = folder.members.filter((key) => !host.members.includes(key))
1288
+ }
1289
+ const next = list.filter((folder) => folder.members.length >= 2)
1290
+ return next.length === folders.length && next.every((folder, index) => folder === folders[index]) ? folders : next
1291
+ }
1292
+
1156
1293
  /**
1157
1294
  * Lay out branch cards left-to-right (turn chain) with one horizontal lane
1158
1295
  * per branch Session, fork edges from the parent turn card to the child's
1159
1296
  * first card, and the current root→Session path marked.
1160
1297
  * @returns {{width:number,height:number,cards:object[],links:object[],lanes:object[],byId:Map,currentKey:string|null,truncated:boolean}}
1161
1298
  */
1162
- function layoutTree(sessions, currentSessionId, overrides) {
1299
+ function layoutTree(sessions, currentSessionId, overrides, folders = []) {
1163
1300
  const byId = new Map(sessions.map((session) => [session.sessionId, session]))
1164
1301
  const laneOf = new Map()
1165
1302
  for (const session of sessions) {
@@ -1265,6 +1402,10 @@ window.__ModuleLoader__.load({
1265
1402
  })
1266
1403
  x += CARD_WIDTH + CARD_GAP_X
1267
1404
  }
1405
+ // Turn cards and turn-less manual cards are placed chronologically by
1406
+ // createdAt. A manual checkpoint created between two turns used to be
1407
+ // appended after every turn card, so the next turn appeared before it.
1408
+ const orderedCards = []
1268
1409
  for (const turn of shown) {
1269
1410
  const group = groups.get(turn)
1270
1411
  const list = []
@@ -1273,47 +1414,126 @@ window.__ModuleLoader__.load({
1273
1414
  if (group.after) list.push(group.after)
1274
1415
  for (const manual of group.manual ?? []) list.push(manual)
1275
1416
  const prompt = group.after?.prompt ?? group.before?.prompt ?? null
1276
- pushCard({
1417
+ const createdAt = group.after?.createdAt ?? group.before?.createdAt ?? 0
1418
+ orderedCards.push({
1277
1419
  key: `${session.sessionId}:turn:${turn}`,
1278
- kind: 'turn',
1279
- sessionId: session.sessionId,
1280
- sessionTitle: session.title || `${session.sessionId.slice(0, 8)}…`,
1281
- lane,
1282
- color,
1283
- x,
1284
- y,
1285
- turn,
1286
- label: `T${turn}`,
1287
- title: `${session.title || session.sessionId.slice(0, 8)} · 第 ${turn} 回合${prompt ? ` · ${prompt}` : ''}`,
1288
- prompt,
1289
- note: [...list].reverse().find((checkpoint) => checkpoint.note)?.note ?? null,
1290
- checkpoints: list,
1291
- manualCount: group.manual?.length ?? 0,
1292
- onPath,
1293
- createdAt: group.after?.createdAt ?? group.before?.createdAt ?? null,
1420
+ sortTime: createdAt,
1421
+ sortTurn: turn,
1422
+ card: {
1423
+ key: `${session.sessionId}:turn:${turn}`,
1424
+ kind: 'turn',
1425
+ sessionId: session.sessionId,
1426
+ sessionTitle: session.title || `${session.sessionId.slice(0, 8)}…`,
1427
+ lane,
1428
+ color,
1429
+ turn,
1430
+ label: `T${turn}`,
1431
+ title: `${session.title || session.sessionId.slice(0, 8)} · 第 ${turn} 回合${prompt ? ` · ${prompt}` : ''}`,
1432
+ prompt,
1433
+ note: [...list].reverse().find((checkpoint) => checkpoint.note)?.note ?? null,
1434
+ checkpoints: list,
1435
+ manualCount: group.manual?.length ?? 0,
1436
+ onPath,
1437
+ createdAt,
1438
+ },
1294
1439
  })
1295
- x += CARD_WIDTH + CARD_GAP_X
1296
1440
  }
1297
1441
  for (const manual of looseManuals) {
1298
- pushCard({
1442
+ orderedCards.push({
1299
1443
  key: `${session.sessionId}:manual:${manual.id}`,
1300
- kind: 'manual',
1301
- sessionId: session.sessionId,
1302
- sessionTitle: session.title || `${session.sessionId.slice(0, 8)}…`,
1303
- lane,
1304
- color,
1305
- x,
1306
- y,
1307
- label: '手动',
1308
- title: `${session.title || session.sessionId.slice(0, 8)} · 手动检查点`,
1309
- prompt: manual.prompt ?? null,
1310
- note: manual.note ?? null,
1311
- checkpoints: [manual],
1312
- onPath,
1313
- createdAt: manual.createdAt ?? null,
1444
+ sortTime: manual.createdAt ?? 0,
1445
+ sortTurn: Number.MAX_SAFE_INTEGER,
1446
+ card: {
1447
+ key: `${session.sessionId}:manual:${manual.id}`,
1448
+ kind: 'manual',
1449
+ sessionId: session.sessionId,
1450
+ sessionTitle: session.title || `${session.sessionId.slice(0, 8)}…`,
1451
+ lane,
1452
+ color,
1453
+ label: '手动',
1454
+ title: `${session.title || session.sessionId.slice(0, 8)} · 手动检查点`,
1455
+ prompt: manual.prompt ?? null,
1456
+ note: manual.note ?? null,
1457
+ checkpoints: [manual],
1458
+ onPath,
1459
+ createdAt: manual.createdAt ?? null,
1460
+ },
1314
1461
  })
1462
+ }
1463
+ orderedCards.sort((left, right) => {
1464
+ if (left.sortTime !== right.sortTime) return left.sortTime - right.sortTime
1465
+ if (left.sortTurn !== right.sortTurn) return left.sortTurn - right.sortTurn
1466
+ return left.key.localeCompare(right.key)
1467
+ })
1468
+ for (const ordered of orderedCards) {
1469
+ const card = ordered.card
1470
+ card.x = x
1471
+ card.y = y
1472
+ pushCard(card)
1315
1473
  x += CARD_WIDTH + CARD_GAP_X
1316
1474
  }
1475
+ // Folders collapse member cards into one compact card until unpacked.
1476
+ if (Array.isArray(folders) && folders.length > 0 && sessionCards.length > 0) {
1477
+ const consumed = new Set()
1478
+ const inserts = []
1479
+ for (const folder of folders) {
1480
+ if (!folder || !Array.isArray(folder.members) || folder.members.length < 2) continue
1481
+ const members = sessionCards.filter((card) => folder.members.includes(card.key))
1482
+ if (members.length < 2) continue
1483
+ if (members.some((card) => consumed.has(card.key))) continue
1484
+ const firstIndex = sessionCards.indexOf(members[0])
1485
+ for (const member of members) consumed.add(member.key)
1486
+ const key = `folder:${session.sessionId}:${folder.id}`
1487
+ const override = overrides?.[key]
1488
+ const firstMember = members[0]
1489
+ inserts.push({
1490
+ index: firstIndex,
1491
+ card: {
1492
+ key,
1493
+ kind: 'folder',
1494
+ folderId: folder.id,
1495
+ folderMembers: [...folder.members],
1496
+ members,
1497
+ sessionId: session.sessionId,
1498
+ sessionTitle: session.title || `${session.sessionId.slice(0, 8)}…`,
1499
+ lane,
1500
+ color: firstMember.color,
1501
+ x: override?.x ?? (Number.isFinite(folder.x) ? folder.x : firstMember.x),
1502
+ y: override?.y ?? (Number.isFinite(folder.y) ? folder.y : firstMember.y),
1503
+ label: '卡片夹',
1504
+ title: `${session.title || session.sessionId.slice(0, 8)} · 卡片夹(${members.length} 张)`,
1505
+ prompt: null,
1506
+ note: null,
1507
+ checkpoints: [],
1508
+ height: FOLDER_CARD_HEIGHT,
1509
+ onPath: members.some((member) => member.onPath),
1510
+ createdAt: members[0].createdAt ?? null,
1511
+ },
1512
+ })
1513
+ }
1514
+ if (inserts.length > 0) {
1515
+ const original = [...sessionCards]
1516
+ const remaining = original.filter((card) => !consumed.has(card.key))
1517
+ const positions = inserts
1518
+ .map((insert) => ({
1519
+ ...insert,
1520
+ position: original.slice(0, insert.index).filter((card) => !consumed.has(card.key)).length,
1521
+ }))
1522
+ .sort((left, right) => left.position - right.position)
1523
+ for (const insert of positions) remaining.splice(insert.position, 0, insert.card)
1524
+ sessionCards.length = 0
1525
+ sessionCards.push(...remaining)
1526
+ // `cards` is the global render list: replace the hidden member cards
1527
+ // with the folder card so the canvas actually collapses them.
1528
+ const visibleKeys = new Set(remaining.map((card) => card.key))
1529
+ for (let cardIndex = cards.length - 1; cardIndex >= 0; cardIndex -= 1) {
1530
+ if (cards[cardIndex].sessionId === session.sessionId && !visibleKeys.has(cards[cardIndex].key)) cards.splice(cardIndex, 1)
1531
+ }
1532
+ for (const card of remaining) {
1533
+ if (card.kind === 'folder' && !cards.some((existing) => existing.key === card.key)) cards.push(card)
1534
+ }
1535
+ }
1536
+ }
1317
1537
  cardsBySession.set(session.sessionId, sessionCards)
1318
1538
  for (let index = 1; index < sessionCards.length; index += 1) {
1319
1539
  const from = sessionCards[index - 1]
@@ -1361,8 +1581,9 @@ window.__ModuleLoader__.load({
1361
1581
  for (const card of cards) card.isCurrentPosition = card.key === currentKey
1362
1582
  const minX = cards.length === 0 ? 0 : Math.min(...cards.map((card) => card.x))
1363
1583
  const minY = cards.length === 0 ? 0 : Math.min(...cards.map((card) => card.y))
1584
+ const cardHeight = (card) => (card.kind === 'folder' && !card.expanded ? FOLDER_CARD_HEIGHT : CARD_HEIGHT)
1364
1585
  const maxX = cards.length === 0 ? 320 : Math.max(...cards.map((card) => card.x + CARD_WIDTH))
1365
- const maxY = cards.length === 0 ? 220 : Math.max(...cards.map((card) => card.y + CARD_HEIGHT))
1586
+ const maxY = cards.length === 0 ? 220 : Math.max(...cards.map((card) => card.y + cardHeight(card)))
1366
1587
  // Cards may carry negative coordinates after a drag. The world layer keeps
1367
1588
  // a fixed origin (no per-frame offset feedback) so dragging behaves the
1368
1589
  // same in every direction; the camera translate reveals negative space.
@@ -1378,7 +1599,7 @@ window.__ModuleLoader__.load({
1378
1599
  }
1379
1600
 
1380
1601
  /** One card of the conversation canvas. */
1381
- function CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef }) {
1602
+ function CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding }) {
1382
1603
  const files = (card.checkpoints ?? []).reduce(
1383
1604
  (total, checkpoint) => ({
1384
1605
  added: total.added + (checkpoint.files?.added ?? 0),
@@ -1408,7 +1629,9 @@ window.__ModuleLoader__.load({
1408
1629
  'article',
1409
1630
  {
1410
1631
  key: card.key,
1411
- className: `tb-card${card.onPath ? ' onpath' : ''}${card.isCurrentPosition ? ' current' : ''}${card.key === selectedKey ? ' selected' : ''}`,
1632
+ className: `tb-card${card.onPath ? ' onpath' : ''}${card.isCurrentPosition ? ' current' : ''}${card.key === selectedKey ? ' selected' : ''}${dropTargetKey === card.key ? ' tb-drop-target' : ''}${folding && (folding.sourceKey === card.key || folding.targetKey === card.key) ? ' tb-folding' : ''}`,
1633
+ 'data-card-key': card.key,
1634
+ 'data-card-kind': card.kind ?? 'turn',
1412
1635
  style: { left: card.x, top: card.y, '--tb-color': card.color },
1413
1636
  title: card.title,
1414
1637
  role: 'button',
@@ -1510,6 +1733,105 @@ window.__ModuleLoader__.load({
1510
1733
  )
1511
1734
  }
1512
1735
 
1736
+ /** One collapsed card folder: compact, with member labels and an unpack action. */
1737
+ function CanvasFolderCard({ card, t, onDragStart, onUnpackFolder, dropTargetKey, folding, expanded, onToggleFolder, onMemberDragStart, suppressClickRef }) {
1738
+ const members = card.members ?? []
1739
+ return h(
1740
+ 'article',
1741
+ {
1742
+ key: card.key,
1743
+ className: `tb-card folder${expanded ? ' expanded' : ''}${dropTargetKey === card.key ? ' tb-drop-target' : ''}${folding && (folding.sourceKey === card.key || folding.targetKey === card.key) ? ' tb-folding' : ''}`,
1744
+ style: { left: card.x, top: card.y, '--tb-color': card.color },
1745
+ title: card.title,
1746
+ 'data-card-key': card.key,
1747
+ 'data-card-kind': 'folder',
1748
+ onPointerDown: (event) => {
1749
+ if (typeof onDragStart === 'function') onDragStart(event, card)
1750
+ },
1751
+ onClick: (event) => {
1752
+ event.stopPropagation()
1753
+ if (suppressClickRef?.current) {
1754
+ suppressClickRef.current = false
1755
+ return
1756
+ }
1757
+ if (typeof onToggleFolder === 'function') onToggleFolder(card.folderId)
1758
+ },
1759
+ },
1760
+ h(
1761
+ 'div',
1762
+ { className: 'tb-card-head' },
1763
+ h('span', { className: 'tb-card-badge' }, '📁'),
1764
+ h('span', { className: 'tb-card-branch', title: card.sessionTitle, style: { color: card.color } }, card.sessionTitle),
1765
+ h('span', { className: 'tb-card-spacer' }),
1766
+ card.createdAt ? h('span', { className: 'tb-card-time' }, clock(card.createdAt)) : null,
1767
+ ),
1768
+ expanded
1769
+ ? h(
1770
+ 'div',
1771
+ { className: 'tb-folder-expanded' },
1772
+ h('div', { className: 'tb-folder-hint' }, t('tree.folderMemberDrag')),
1773
+ ...members.map((member) =>
1774
+ h(
1775
+ 'div',
1776
+ {
1777
+ key: member.key,
1778
+ className: 'tb-folder-row',
1779
+ title: member.prompt || member.title,
1780
+ 'data-member-key': member.key,
1781
+ onPointerDown: (event) => {
1782
+ if (typeof onMemberDragStart === 'function') onMemberDragStart(event, card, member)
1783
+ },
1784
+ },
1785
+ h('span', { className: 'tb-folder-row-label' }, member.label),
1786
+ h('span', { className: 'tb-folder-row-prompt' }, stripMarkdown(member.prompt || member.title || '')),
1787
+ ),
1788
+ ),
1789
+ )
1790
+ : h(
1791
+ 'div',
1792
+ { className: 'tb-folder-members' },
1793
+ ...members.slice(0, 4).map((member) =>
1794
+ h(
1795
+ 'div',
1796
+ { key: member.key, className: 'tb-folder-member', title: `${member.label}${member.prompt ? ` · ${stripMarkdown(member.prompt)}` : ''}` },
1797
+ `${member.label}${member.prompt ? ` · ${stripMarkdown(member.prompt).slice(0, 36)}` : ''}`,
1798
+ ),
1799
+ ),
1800
+ members.length > 4 ? h('div', { className: 'tb-folder-member more' }, `+${members.length - 4}`) : null,
1801
+ ),
1802
+ h(
1803
+ 'div',
1804
+ { className: 'tb-card-foot' },
1805
+ h(
1806
+ 'button',
1807
+ {
1808
+ type: 'button',
1809
+ className: 'tb-card-action',
1810
+ title: expanded ? t('tree.folderCollapse') : t('tree.folderExpand'),
1811
+ onClick: (event) => {
1812
+ event.stopPropagation()
1813
+ if (typeof onToggleFolder === 'function') onToggleFolder(card.folderId)
1814
+ },
1815
+ },
1816
+ expanded ? `▴ ${t('tree.folderCollapse')}` : `▾ ${t('tree.folderExpand')}`,
1817
+ ),
1818
+ h(
1819
+ 'button',
1820
+ {
1821
+ type: 'button',
1822
+ className: 'tb-card-action',
1823
+ title: t('tree.unpackHint'),
1824
+ onClick: (event) => {
1825
+ event.stopPropagation()
1826
+ if (typeof onUnpackFolder === 'function') onUnpackFolder(card.folderId)
1827
+ },
1828
+ },
1829
+ `↔ ${t('tree.unpack')}`,
1830
+ ),
1831
+ ),
1832
+ )
1833
+ }
1834
+
1513
1835
  /** Render the pannable/zoomable conversation canvas. */
1514
1836
  function TreeCanvas({
1515
1837
  layout,
@@ -1520,6 +1842,12 @@ window.__ModuleLoader__.load({
1520
1842
  onBranch,
1521
1843
  onNote,
1522
1844
  onDragStart,
1845
+ onUnpackFolder,
1846
+ dropTargetKey,
1847
+ folding,
1848
+ expandedFolderId,
1849
+ onToggleFolder,
1850
+ onMemberDragStart,
1523
1851
  onResetLayout,
1524
1852
  autoPan,
1525
1853
  panSpeed,
@@ -1573,6 +1901,7 @@ window.__ModuleLoader__.load({
1573
1901
  ),
1574
1902
  h('button', { type: 'button', className: 'tb-canvas-btn', title: t('tree.resetLayoutHint'), onClick: onResetLayout }, t('tree.resetLayout')),
1575
1903
  h('button', { type: 'button', className: 'tb-canvas-btn', title: t('tree.expandHint'), onClick: onToggleExpand }, expanded ? '⤡' : '⤢'),
1904
+ h('span', { className: 'tb-canvas-hint' }, t('tree.folderHint')),
1576
1905
  ),
1577
1906
  h(
1578
1907
  'div',
@@ -1593,8 +1922,39 @@ window.__ModuleLoader__.load({
1593
1922
  }),
1594
1923
  ),
1595
1924
  ),
1925
+ (() => {
1926
+ const targetCard = dropTargetKey ? layout.cards.find((card) => card.key === dropTargetKey) : null
1927
+ if (!targetCard) return null
1928
+ return h(
1929
+ 'div',
1930
+ {
1931
+ className: 'tb-folder-slot',
1932
+ style: {
1933
+ left: targetCard.x - 5,
1934
+ top: targetCard.y - 5,
1935
+ width: CARD_WIDTH + 10,
1936
+ height: (targetCard.kind === 'folder' ? FOLDER_CARD_HEIGHT : CARD_HEIGHT) + 10,
1937
+ },
1938
+ 'aria-hidden': true,
1939
+ },
1940
+ h('span', null, t('tree.folderDropHint')),
1941
+ )
1942
+ })(),
1596
1943
  ...layout.cards.map((card) =>
1597
- CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef }),
1944
+ card.kind === 'folder'
1945
+ ? CanvasFolderCard({
1946
+ card,
1947
+ t,
1948
+ onDragStart,
1949
+ onUnpackFolder,
1950
+ dropTargetKey,
1951
+ folding,
1952
+ expanded: expandedFolderId === card.folderId,
1953
+ onToggleFolder,
1954
+ onMemberDragStart,
1955
+ suppressClickRef,
1956
+ })
1957
+ : CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding }),
1598
1958
  ),
1599
1959
  ),
1600
1960
  )
@@ -1748,6 +2108,18 @@ window.__ModuleLoader__.load({
1748
2108
  const [tick, setTick] = React.useState(0)
1749
2109
  const [busy, setBusy] = React.useState('')
1750
2110
  const [feedback, setFeedback] = React.useState(null)
2111
+
2112
+ React.useEffect(() => {
2113
+ if (!feedback) return undefined
2114
+ if (feedback.tone === 'err' || feedback.tone === 'warn') return undefined
2115
+ // Actionable successes (open branch / undo restore) stay longer; plain
2116
+ // toasts such as "卡片记录已保存" disappear on their own.
2117
+ const actionable = Boolean(feedback.childSessionId || feedback.safetyCheckpointId || feedback.pruneCandidate)
2118
+ const timer = window.setTimeout(() => {
2119
+ setFeedback((current) => (current === feedback ? null : current))
2120
+ }, actionable ? 8000 : 3500)
2121
+ return () => window.clearTimeout(timer)
2122
+ }, [feedback])
1751
2123
  const [view, setView] = React.useState('tree')
1752
2124
  const [selectedKey, setSelectedKey] = React.useState(null)
1753
2125
  const [zoom, setZoom] = React.useState(1)
@@ -1781,6 +2153,14 @@ window.__ModuleLoader__.load({
1781
2153
  const applyCameraRef = React.useRef(() => {})
1782
2154
  const [positions, setPositions] = React.useState({})
1783
2155
  const positionsRef = React.useRef({})
2156
+ const [folders, setFolders] = React.useState([])
2157
+ const foldersRef = React.useRef([])
2158
+ const [dropTargetKey, setDropTargetKey] = React.useState(null)
2159
+ const dropTargetRef = React.useRef(null)
2160
+ const [folding, setFolding] = React.useState(null)
2161
+ const foldTimerRef = React.useRef(null)
2162
+ const [expandedFolderId, setExpandedFolderId] = React.useState(null)
2163
+ const [folderGhost, setFolderGhost] = React.useState(null)
1784
2164
  const suppressClickRef = React.useRef(false)
1785
2165
  const draggingRef = React.useRef(false)
1786
2166
  const busyRef = React.useRef('')
@@ -1991,7 +2371,12 @@ window.__ModuleLoader__.load({
1991
2371
  const world = worldRef.current
1992
2372
  if (world) {
1993
2373
  const camera = cameraRef.current
1994
- world.style.transform = `translate(${camera.x}px, ${camera.y}px) scale(${camera.scale})`
2374
+ // Snap the translation to real device pixels. A fractional CSS px
2375
+ // offset makes the browser rasterize every card's text on a half pixel,
2376
+ // which is what looks "糊" on desktop WebViews.
2377
+ const ratio = typeof window !== 'undefined' && Number.isFinite(window.devicePixelRatio) && window.devicePixelRatio > 0 ? window.devicePixelRatio : 1
2378
+ const snap = (value) => Math.round(value * ratio) / ratio
2379
+ world.style.transform = `translate(${snap(camera.x)}px, ${snap(camera.y)}px) scale(${camera.scale})`
1995
2380
  }
1996
2381
  if (announceZoom) setZoom(cameraRef.current.scale)
1997
2382
  }
@@ -2006,7 +2391,11 @@ window.__ModuleLoader__.load({
2006
2391
  const height = viewport.clientHeight || 320
2007
2392
  const spanX = Math.max(1, current.maxX - current.minX)
2008
2393
  const spanY = Math.max(1, current.maxY - current.minY)
2009
- const scale = Math.min(1.15, Math.max(0.35, Math.min((width - 28) / spanX, (height - 28) / spanY)))
2394
+ let scale = Math.min(1.15, Math.max(0.35, Math.min((width - 28) / spanX, (height - 28) / spanY)))
2395
+ // Prefer exactly 1x (crisp text) when the content almost fits; otherwise
2396
+ // quantize to 2 decimals so the world transform is not a repeating float.
2397
+ if (scale >= 0.92 && scale <= 1.15) scale = 1
2398
+ else scale = Math.round(scale * 100) / 100
2010
2399
  cameraRef.current = {
2011
2400
  scale,
2012
2401
  x: (width - spanX * scale) / 2 - current.minX * scale,
@@ -2087,7 +2476,7 @@ window.__ModuleLoader__.load({
2087
2476
  const sessions = data?.sessions ?? []
2088
2477
  const checkpointTotal = sessions.reduce((total, session) => total + (session.checkpointCount ?? session.checkpoints?.length ?? 0), 0)
2089
2478
  const gitOff = data?.git === false
2090
- const layout = data ? layoutTree(sessions, data.currentSessionId, positions) : null
2479
+ const layout = data ? layoutTree(sessions, data.currentSessionId, positions, folders) : null
2091
2480
  layoutRef.current = layout
2092
2481
  const clientVersion = BUILD.split('+')[0]
2093
2482
  const serverVersion = typeof data?.serverVersion === 'string' ? data.serverVersion : null
@@ -2097,34 +2486,45 @@ window.__ModuleLoader__.load({
2097
2486
  const selectedNode = (selectedKey ? layout?.cards.find((card) => card.key === selectedKey) : null) ?? fallbackNode
2098
2487
  const effectiveSelectedKey = selectedNode?.key ?? null
2099
2488
 
2100
- // Fit the canvas the first time a layout (or Session) appears.
2489
+ // Fit the canvas the first time a Session's layout appears. Later layout
2490
+ // size changes (folding/unfolding/dragging) must not re-center the camera,
2491
+ // otherwise a freshly formed folder appears to jump to the middle.
2492
+ const layoutReady = Boolean(layout && layout.cards.length > 0)
2101
2493
  React.useEffect(() => {
2102
- if (view !== 'tree' || !data || !layout || layout.cards.length === 0) return
2494
+ if (view !== 'tree' || !layoutReady) return
2103
2495
  if (draggingRef.current) return
2104
- const key = `${data.currentSessionId}:${layout.width}x${layout.height}`
2496
+ const key = String(data?.currentSessionId ?? '')
2105
2497
  if (fittedRef.current === key) return
2106
2498
  fittedRef.current = key
2107
2499
  window.requestAnimationFrame(() => fitCanvas())
2108
2500
  // fitCanvas only reads refs; it is intentionally excluded from deps.
2109
2501
  // eslint-disable-next-line react-hooks/exhaustive-deps
2110
- }, [view, data?.currentSessionId, layout?.width, layout?.height])
2502
+ }, [view, data?.currentSessionId, layoutReady])
2111
2503
 
2112
2504
  const positionsKey = data?.rootSessionId ? `dsh-timeback:card-positions:${data.rootSessionId}` : null
2505
+ const foldersKey = data?.rootSessionId ? `dsh-timeback:card-folders:${data.rootSessionId}` : null
2113
2506
 
2114
- // Restore dragged card positions for this branch family.
2507
+ // Restore dragged card positions and folders for this branch family.
2115
2508
  React.useEffect(() => {
2116
2509
  if (!positionsKey) return
2117
2510
  let saved = {}
2511
+ let savedFolders = []
2118
2512
  try {
2119
2513
  const raw = window.localStorage.getItem(positionsKey)
2120
2514
  if (raw) saved = JSON.parse(raw)
2515
+ const rawFolders = window.localStorage.getItem(foldersKey)
2516
+ if (rawFolders) savedFolders = JSON.parse(rawFolders)
2121
2517
  } catch {
2122
2518
  saved = {}
2519
+ savedFolders = []
2123
2520
  }
2124
2521
  if (saved === null || typeof saved !== 'object' || Array.isArray(saved)) saved = {}
2522
+ if (!Array.isArray(savedFolders)) savedFolders = []
2125
2523
  positionsRef.current = saved
2126
2524
  setPositions(saved)
2127
- }, [positionsKey])
2525
+ foldersRef.current = savedFolders
2526
+ setFolders(savedFolders)
2527
+ }, [positionsKey, foldersKey])
2128
2528
 
2129
2529
  // Wheel zoom must be non-passive, so it is bound directly to the viewport.
2130
2530
  React.useEffect(() => {
@@ -2155,6 +2555,91 @@ window.__ModuleLoader__.load({
2155
2555
  }
2156
2556
  }
2157
2557
 
2558
+ /** Persist card folders for this branch family. */
2559
+ const storeFolders = (next, persist) => {
2560
+ foldersRef.current = next
2561
+ setFolders(next)
2562
+ if (persist !== true) return
2563
+ try {
2564
+ if (foldersKey) window.localStorage.setItem(foldersKey, JSON.stringify(next))
2565
+ } catch {
2566
+ // Storage can be disabled; folding still works in memory.
2567
+ }
2568
+ }
2569
+
2570
+ /** Dissolve one folder and restore its member cards. */
2571
+ const unpackFolder = (folderId) => {
2572
+ const next = foldersRef.current.filter((folder) => folder.id !== folderId)
2573
+ storeFolders(next, true)
2574
+ }
2575
+
2576
+ /** Expand/collapse one folder's full member list. */
2577
+ const toggleFolder = (folderId) => {
2578
+ setExpandedFolderId((current) => (current === folderId ? null : folderId))
2579
+ }
2580
+
2581
+ /** Remove one card from a folder; a folder with <2 members dissolves. */
2582
+ const detachFolderMember = (folderId, memberKey, position) => {
2583
+ const next = removeFolderMember(foldersRef.current, folderId, memberKey)
2584
+ if (next === foldersRef.current) return
2585
+ storeFolders(next, true)
2586
+ if (next.every((folder) => folder.id !== folderId)) setExpandedFolderId(null)
2587
+ if (position && Number.isFinite(position.x) && Number.isFinite(position.y)) {
2588
+ storePositions({ ...positionsRef.current, [memberKey]: position }, true)
2589
+ }
2590
+ }
2591
+
2592
+ /**
2593
+ * Drag one row out of an expanded folder. Dropping it over the canvas
2594
+ * detaches the card and places it at the pointer; dropping back over the
2595
+ * folder cancels.
2596
+ */
2597
+ const startFolderMemberDrag = (event, folderCard, member) => {
2598
+ if (event.button !== 0) return
2599
+ event.preventDefault()
2600
+ event.stopPropagation()
2601
+ const startX = event.clientX
2602
+ const startY = event.clientY
2603
+ let moved = false
2604
+ const move = (next) => {
2605
+ if (!moved && Math.hypot(next.clientX - startX, next.clientY - startY) < 5) return
2606
+ moved = true
2607
+ setFolderGhost({ x: next.clientX, y: next.clientY, member, moved: true })
2608
+ }
2609
+ const finish = (next) => {
2610
+ window.removeEventListener('pointermove', move)
2611
+ window.removeEventListener('pointerup', finish)
2612
+ window.removeEventListener('pointercancel', finish)
2613
+ setFolderGhost(null)
2614
+ if (!moved) return
2615
+ const viewport = viewportRef.current
2616
+ if (!viewport) return
2617
+ const bounds = viewport.getBoundingClientRect()
2618
+ const insideCanvas =
2619
+ next.clientX >= bounds.left && next.clientX <= bounds.right && next.clientY >= bounds.top && next.clientY <= bounds.bottom
2620
+ if (!insideCanvas) return
2621
+ const camera = cameraRef.current
2622
+ const worldX = (next.clientX - bounds.left - camera.x) / camera.scale
2623
+ const worldY = (next.clientY - bounds.top - camera.y) / camera.scale
2624
+ // Dropping back on the expanded folder itself keeps the card filed.
2625
+ if (
2626
+ worldX >= folderCard.x && worldX <= folderCard.x + CARD_WIDTH &&
2627
+ worldY >= folderCard.y && worldY <= folderCard.y + FOLDER_CARD_HEIGHT
2628
+ ) return
2629
+ detachFolderMember(folderCard.folderId, member.key, {
2630
+ x: Math.round(worldX - CARD_WIDTH / 2),
2631
+ y: Math.round(worldY - CARD_HEIGHT / 2),
2632
+ })
2633
+ // Leave the ghost on screen for a short drop animation while the real
2634
+ // card pops in at the pointer.
2635
+ setFolderGhost({ x: next.clientX, y: next.clientY, member, moved: true, dropping: true })
2636
+ window.setTimeout(() => setFolderGhost((current) => (current?.dropping ? null : current)), 200)
2637
+ }
2638
+ window.addEventListener('pointermove', move)
2639
+ window.addEventListener('pointerup', finish)
2640
+ window.addEventListener('pointercancel', finish)
2641
+ }
2642
+
2158
2643
  /** Drag one card inside the world layer (screen delta ÷ zoom). */
2159
2644
  const onCardDragStart = (event, card) => {
2160
2645
  if (event.button !== 0) return
@@ -2229,6 +2714,27 @@ window.__ModuleLoader__.load({
2229
2714
  moved = true
2230
2715
  suppressClickRef.current = true
2231
2716
  scheduleApply()
2717
+ const target = dropTargetAt()
2718
+ const targetKey = target?.key ?? null
2719
+ if (dropTargetRef.current !== targetKey) {
2720
+ dropTargetRef.current = targetKey
2721
+ setDropTargetKey(targetKey)
2722
+ }
2723
+ }
2724
+ const dropTargetAt = () => {
2725
+ const cards = layoutRef.current?.cards ?? []
2726
+ const camera = cameraRef.current
2727
+ const worldX = (pointer.x - rect.left - camera.x) / camera.scale
2728
+ const worldY = (pointer.y - rect.top - camera.y) / camera.scale
2729
+ for (let index = cards.length - 1; index >= 0; index -= 1) {
2730
+ const candidate = cards[index]
2731
+ if (candidate.key === card.key) continue
2732
+ if (worldX < candidate.x || worldX > candidate.x + CARD_WIDTH) continue
2733
+ const candidateHeight = candidate.kind === 'folder' ? FOLDER_CARD_HEIGHT : CARD_HEIGHT
2734
+ if (worldY < candidate.y || worldY > candidate.y + candidateHeight) continue
2735
+ return candidate
2736
+ }
2737
+ return null
2232
2738
  }
2233
2739
  const finish = () => {
2234
2740
  window.removeEventListener('pointermove', move)
@@ -2244,7 +2750,28 @@ window.__ModuleLoader__.load({
2244
2750
  if (latest !== null) apply()
2245
2751
  }
2246
2752
  draggingRef.current = false
2753
+ dropTargetRef.current = null
2754
+ setDropTargetKey(null)
2247
2755
  if (moved) {
2756
+ const target = dropTargetAt()
2757
+ if (target) {
2758
+ const nextFolders = mergeCardFolder(foldersRef.current, card, target)
2759
+ if (nextFolders !== foldersRef.current) {
2760
+ // Let the hovered card dim/scale and the dragged card shrink into it
2761
+ // for a moment before the folder appears, like a phone home-screen
2762
+ // folder animation.
2763
+ setFolding({ sourceKey: card.key, targetKey: target.key })
2764
+ if (foldTimerRef.current) clearTimeout(foldTimerRef.current)
2765
+ foldTimerRef.current = window.setTimeout(() => {
2766
+ foldTimerRef.current = null
2767
+ storeFolders(nextFolders, true)
2768
+ setFolding(null)
2769
+ window.setTimeout(() => { suppressClickRef.current = false }, 80)
2770
+ }, 230)
2771
+ return
2772
+ }
2773
+ }
2774
+ setFolding(null)
2248
2775
  storePositions(positionsRef.current, true)
2249
2776
  window.setTimeout(() => { suppressClickRef.current = false }, 80)
2250
2777
  }
@@ -2310,6 +2837,17 @@ window.__ModuleLoader__.load({
2310
2837
  })
2311
2838
  }
2312
2839
 
2840
+ /** Saving close for the card-note sheet: outside clicks never discard text. */
2841
+ const dismissCardNoteSaving = async () => {
2842
+ const editor = noteEditor
2843
+ if (!editor || editor.busy) return
2844
+ if (editor.text.trim() === '' && !editor.card.note) {
2845
+ setNoteEditor(null)
2846
+ return
2847
+ }
2848
+ await saveCardNote(false)
2849
+ }
2850
+
2313
2851
  /** Save (or clear) the note on the card being edited. */
2314
2852
  const saveCardNote = async (clear) => {
2315
2853
  const editor = noteEditor
@@ -2342,6 +2880,13 @@ window.__ModuleLoader__.load({
2342
2880
  }
2343
2881
  positionsRef.current = {}
2344
2882
  setPositions({})
2883
+ try {
2884
+ if (foldersKey) window.localStorage.removeItem(foldersKey)
2885
+ } catch {
2886
+ // Storage can be disabled.
2887
+ }
2888
+ foldersRef.current = []
2889
+ setFolders([])
2345
2890
  }
2346
2891
  return h(
2347
2892
  'div',
@@ -2492,6 +3037,12 @@ window.__ModuleLoader__.load({
2492
3037
  expanded: canvasExpanded,
2493
3038
  onToggleExpand: () => setCanvasExpanded((value) => !value),
2494
3039
  onDragStart: onCardDragStart,
3040
+ onUnpackFolder: unpackFolder,
3041
+ dropTargetKey,
3042
+ folding,
3043
+ expandedFolderId,
3044
+ onToggleFolder: toggleFolder,
3045
+ onMemberDragStart: startFolderMemberDrag,
2495
3046
  onResetLayout: resetCardPositions,
2496
3047
  autoPan,
2497
3048
  panSpeed,
@@ -2539,7 +3090,7 @@ window.__ModuleLoader__.load({
2539
3090
  noteEditor
2540
3091
  ? h(
2541
3092
  'div',
2542
- { className: 'tb-overlay', onClick: () => { if (!noteEditor.busy) setNoteEditor(null) } },
3093
+ { className: 'tb-overlay', onClick: dismissCardNoteSaving },
2543
3094
  h(
2544
3095
  'div',
2545
3096
  { className: 'tb-note-dialog', role: 'dialog', 'aria-modal': true, onClick: (event) => event.stopPropagation() },
@@ -3362,7 +3913,7 @@ window.__ModuleLoader__.load({
3362
3913
  width: BOARD_NOTE_W,
3363
3914
  height: BOARD_NOTE_H,
3364
3915
  z: index,
3365
- color: BOARD_COLORS[index % BOARD_COLORS.length],
3916
+ color: '#ffffff',
3366
3917
  }
3367
3918
  }
3368
3919
 
@@ -3823,21 +4374,31 @@ window.__ModuleLoader__.load({
3823
4374
 
3824
4375
  function BoardPanel(props) {
3825
4376
  const t = typeof props?.t === 'function' ? props.t : (key) => key
4377
+ const boardSessionId = typeof props?.sessionId === 'string' ? props.sessionId : ''
4378
+ const boardScope = (body) => (boardSessionId ? { ...body, sessionId: boardSessionId } : body)
3826
4379
  const [state, setState] = React.useState({ loading: true, board: null, error: null })
3827
4380
  const [draft, setDraft] = React.useState(null)
3828
4381
  const [busy, setBusy] = React.useState('')
4382
+ const defaultDialogSize = () => {
4383
+ const viewportWidth = typeof window !== 'undefined' && Number.isFinite(window.innerWidth) ? window.innerWidth : 1280
4384
+ const viewportHeight = typeof window !== 'undefined' && Number.isFinite(window.innerHeight) ? window.innerHeight : 900
4385
+ return {
4386
+ width: Math.min(1100, Math.max(680, Math.round(viewportWidth * 0.8))),
4387
+ height: Math.min(820, Math.max(480, Math.round(viewportHeight * 0.82))),
4388
+ }
4389
+ }
3829
4390
  const [dialogSize, setDialogSize] = React.useState(() => {
3830
- const fallback = { width: 680, height: 520 }
3831
4391
  try {
3832
4392
  const raw = JSON.parse(window.localStorage.getItem('dsh-timeback:board-dialog-size') || 'null')
3833
4393
  if (raw && Number.isFinite(raw.width) && Number.isFinite(raw.height)) {
4394
+ // Migrate the old fixed 680x520 default to the new larger responsive one.
4395
+ if (raw.width === 680 && raw.height === 520) return defaultDialogSize()
3834
4396
  return { width: Math.min(1200, Math.max(340, raw.width)), height: Math.min(900, Math.max(260, raw.height)) }
3835
4397
  }
3836
4398
  } catch {
3837
4399
  // fall through to the default
3838
4400
  }
3839
- const height = typeof window !== 'undefined' && Number.isFinite(window.innerHeight) ? Math.round(window.innerHeight * 0.62) : fallback.height
3840
- return { width: fallback.width, height: Math.max(320, Math.min(640, height)) }
4401
+ return defaultDialogSize()
3841
4402
  })
3842
4403
  const dialogSizeRef = React.useRef(dialogSize)
3843
4404
  dialogSizeRef.current = dialogSize
@@ -3905,7 +4466,7 @@ window.__ModuleLoader__.load({
3905
4466
 
3906
4467
  const refresh = React.useCallback(async () => {
3907
4468
  try {
3908
- const body = await request('notes')
4469
+ const body = await request(`notes${boardSessionId ? `?session=${encodeURIComponent(boardSessionId)}` : ''}`)
3909
4470
  const board = body.board ?? null
3910
4471
  setState({ loading: false, board, error: null })
3911
4472
  if (board) {
@@ -3929,6 +4490,7 @@ window.__ModuleLoader__.load({
3929
4490
 
3930
4491
  React.useEffect(() => () => {
3931
4492
  if (saveTimerRef.current) clearTimeout(saveTimerRef.current)
4493
+ if (foldTimerRef.current) clearTimeout(foldTimerRef.current)
3932
4494
  }, [])
3933
4495
 
3934
4496
  /** Zoom around one viewport point while keeping that content anchored. */
@@ -4071,7 +4633,7 @@ window.__ModuleLoader__.load({
4071
4633
  saveTimerRef.current = setTimeout(async () => {
4072
4634
  saveTimerRef.current = null
4073
4635
  try {
4074
- const body = await request('action', { method: 'POST', body: { action: 'board-canvas', canvas: next } })
4636
+ const body = await request('action', { method: 'POST', body: boardScope({ action: 'board-canvas', canvas: next }) })
4075
4637
  setState((previous) => ({ ...previous, board: body.board ?? previous.board, error: null }))
4076
4638
  } catch (error) {
4077
4639
  setState((previous) => ({ ...previous, error: error?.message || String(error) }))
@@ -4079,6 +4641,19 @@ window.__ModuleLoader__.load({
4079
4641
  }, 420)
4080
4642
  }
4081
4643
 
4644
+ /** Persist a critical canvas layout change immediately (not debounced). */
4645
+ const saveCanvasNow = async (next) => {
4646
+ canvasRef.current = next
4647
+ setCanvas(next)
4648
+ if (saveTimerRef.current) {
4649
+ clearTimeout(saveTimerRef.current)
4650
+ saveTimerRef.current = null
4651
+ }
4652
+ const body = await request('action', { method: 'POST', body: boardScope({ action: 'board-canvas', canvas: next }) })
4653
+ setState((previous) => ({ ...previous, board: body.board ?? previous.board, error: null }))
4654
+ return body
4655
+ }
4656
+
4082
4657
  const persistDialogSize = (value) => {
4083
4658
  try {
4084
4659
  window.localStorage.setItem('dsh-timeback:board-dialog-size', JSON.stringify(value))
@@ -4087,7 +4662,7 @@ window.__ModuleLoader__.load({
4087
4662
  }
4088
4663
  }
4089
4664
  const resetDialogSize = () => {
4090
- const next = { width: 680, height: 520 }
4665
+ const next = defaultDialogSize()
4091
4666
  setDialogSize(next)
4092
4667
  persistDialogSize(next)
4093
4668
  }
@@ -4179,11 +4754,29 @@ window.__ModuleLoader__.load({
4179
4754
  const stage = stageRef.current
4180
4755
  return stage ? { layer: 'background', noteId: '', rect: stage.getBoundingClientRect() } : null
4181
4756
  }
4182
- const startCreate = () => setDraft({ id: '', title: '', body: '', preview: false, busy: false, error: null })
4183
- const startEdit = (entry) => setDraft({ id: entry.id, title: entry.title, body: entry.body, preview: false, busy: false, error: null })
4757
+ const startCreate = () => setDraft({ id: '', title: '', body: '', preview: false, busy: false, error: null, color: '#ffffff' })
4758
+ const startEdit = (entry) =>
4759
+ setDraft({
4760
+ id: entry.id,
4761
+ title: entry.title,
4762
+ body: entry.body,
4763
+ preview: false,
4764
+ busy: false,
4765
+ error: null,
4766
+ color: canvasRef.current.notes[entry.id]?.color || '#ffffff',
4767
+ })
4184
4768
  const closeDraft = () => {
4185
4769
  if (draft && !draft.busy) setDraft(null)
4186
4770
  }
4771
+ /** Clicking the dimmed area saves instead of silently discarding the note. */
4772
+ const dismissDraftSaving = async () => {
4773
+ if (!draft || draft.busy) return
4774
+ if (draft.title.trim() === '' && draft.body.trim() === '') {
4775
+ setDraft(null)
4776
+ return
4777
+ }
4778
+ await saveDraft()
4779
+ }
4187
4780
  const focusEntry = (id) => {
4188
4781
  setSelected(id)
4189
4782
  try {
@@ -4198,19 +4791,35 @@ window.__ModuleLoader__.load({
4198
4791
  try {
4199
4792
  const body = await request('action', {
4200
4793
  method: 'POST',
4201
- body: { action: 'note-save', ...(draft.id ? { id: draft.id } : {}), title: draft.title, body: draft.body },
4794
+ body: boardScope({ action: 'note-save', ...(draft.id ? { id: draft.id } : {}), title: draft.title, body: draft.body }),
4202
4795
  })
4203
- const board = body.board ?? state.board
4204
- setDraft(null)
4796
+ let board = body.board ?? state.board
4205
4797
  setState({ loading: false, board, error: null })
4206
- // Put a brand-new note where the sticky board expects one.
4798
+ // Put a brand-new note where the sticky board expects one, with the
4799
+ // colour chosen in the dialog; persist it before closing the dialog so
4800
+ // the visible sticky and the stored layout can never disagree.
4207
4801
  if (!draft.id && body.entry?.id && board && !canvasRef.current.notes[body.entry.id]) {
4208
4802
  const index = Math.max(0, (board.entries?.length ?? 1) - 1)
4209
- saveCanvasSoon({
4803
+ const layoutBody = await saveCanvasNow({
4804
+ ...canvasRef.current,
4805
+ notes: {
4806
+ ...canvasRef.current.notes,
4807
+ [body.entry.id]: { ...autoBoardLayout(index), color: draft.color || '#ffffff' },
4808
+ },
4809
+ })
4810
+ board = layoutBody?.board ?? board
4811
+ } else if (draft.id && canvasRef.current.notes[draft.id]) {
4812
+ const layoutBody = await saveCanvasNow({
4210
4813
  ...canvasRef.current,
4211
- notes: { ...canvasRef.current.notes, [body.entry.id]: autoBoardLayout(index) },
4814
+ notes: {
4815
+ ...canvasRef.current.notes,
4816
+ [draft.id]: { ...canvasRef.current.notes[draft.id], color: draft.color || '#ffffff' },
4817
+ },
4212
4818
  })
4819
+ board = layoutBody?.board ?? board
4213
4820
  }
4821
+ setDraft(null)
4822
+ setState({ loading: false, board, error: null })
4214
4823
  } catch (error) {
4215
4824
  setDraft({ ...draft, busy: false, error: error?.message || String(error) })
4216
4825
  }
@@ -4226,7 +4835,7 @@ window.__ModuleLoader__.load({
4226
4835
  if (!confirmed) return
4227
4836
  setBusy(id)
4228
4837
  try {
4229
- const body = await request('action', { method: 'POST', body: { action: 'note-delete', id } })
4838
+ const body = await request('action', { method: 'POST', body: boardScope({ action: 'note-delete', id }) })
4230
4839
  setState({ loading: false, board: body.board ?? state.board, error: null })
4231
4840
  const next = cloneBoardCanvas(canvasRef.current)
4232
4841
  delete next.notes[id]
@@ -4852,9 +5461,9 @@ window.__ModuleLoader__.load({
4852
5461
  },
4853
5462
  `🔗 ${t('board.openMd')}`,
4854
5463
  ),
4855
- h('div', { className: 'tb-board-meta' }, stripMarkdown(entry.body).slice(0, 90)),
5464
+ h('div', { className: 'tb-sticky-md' }, ...(entry.body.trim() ? renderMarkdown(entry.body, `sticky-${entry.id}`) : [h('span', { key: 'empty' }, t('board.empty'))])),
4856
5465
  )
4857
- : h('div', { className: 'tb-sticky-body md' }, stripMarkdown(entry.body) || t('board.empty')),
5466
+ : h('div', { className: 'tb-sticky-body' }, h('div', { className: 'tb-sticky-md' }, ...(entry.body.trim() ? renderMarkdown(entry.body, `sticky-${entry.id}`) : [h('span', { key: 'empty' }, t('board.empty'))]))),
4858
5467
  drawingLayer(canvas.drawings[entry.id] ?? [], `d-${entry.id}`),
4859
5468
  ...BOARD_ANCHORS.map((anchor) =>
4860
5469
  h('div', {
@@ -5174,7 +5783,7 @@ window.__ModuleLoader__.load({
5174
5783
  draft
5175
5784
  ? h(
5176
5785
  'div',
5177
- { className: 'tb-overlay center', onClick: closeDraft },
5786
+ { className: 'tb-overlay center', onClick: dismissDraftSaving },
5178
5787
  h(
5179
5788
  'div',
5180
5789
  {
@@ -5197,6 +5806,38 @@ window.__ModuleLoader__.load({
5197
5806
  disabled: draft.busy,
5198
5807
  onChange: (event) => setDraft({ ...draft, title: event.target.value }),
5199
5808
  }),
5809
+ h(
5810
+ 'div',
5811
+ { className: 'tb-sticky-color-row', style: { flexWrap: 'nowrap', overflow: 'hidden' } },
5812
+ h('span', { className: 'tb-color-label', style: { flex: '0 0 auto' } }, t('board.stickyColor')),
5813
+ h('span', {
5814
+ className: 'tb-sticky-color-preview',
5815
+ style: { background: draft.color || '#ffffff', flex: '0 0 auto' },
5816
+ title: draft.color || '#ffffff',
5817
+ }),
5818
+ ...BOARD_COLORS.map((value) =>
5819
+ h('button', {
5820
+ key: `sticky-${value}`,
5821
+ type: 'button',
5822
+ className: `tb-sticky-color-btn${(draft.color || '#ffffff').toLowerCase() === value ? ' on' : ''}`,
5823
+ style: { background: value, width: 26, height: 26, minWidth: 26, minHeight: 26, flex: '0 0 auto', padding: 0 },
5824
+ title: value,
5825
+ 'aria-label': `${t('board.stickyColor')} ${value}`,
5826
+ disabled: draft.busy,
5827
+ onClick: () => setDraft({ ...draft, color: value }),
5828
+ }),
5829
+ ),
5830
+ h('span', { className: 'tb-color-label', style: { marginLeft: 'auto', flex: '0 0 auto' } }, t('md.customColor')),
5831
+ h('input', {
5832
+ type: 'color',
5833
+ className: 'tb-sticky-color-input',
5834
+ value: draft.color || '#ffffff',
5835
+ title: t('board.stickyColor'),
5836
+ disabled: draft.busy,
5837
+ style: { width: 30, height: 26, minWidth: 30, flex: '0 0 auto' },
5838
+ onChange: (event) => setDraft({ ...draft, color: event.target.value }),
5839
+ }),
5840
+ ),
5200
5841
  h(MarkdownEditor, {
5201
5842
  value: draft.body,
5202
5843
  onChange: (next) => setDraft({ ...draft, body: next }),
@@ -5204,7 +5845,7 @@ window.__ModuleLoader__.load({
5204
5845
  disabled: draft.busy,
5205
5846
  placeholder: t('board.bodyPlaceholder'),
5206
5847
  }),
5207
- h('div', { className: 'tb-ws-hint' }, t('board.resizeHint')),
5848
+ h('div', { className: 'tb-ws-hint' }, `${t('board.resizeHint')} · ${t('board.autosaveHint')}`),
5208
5849
  draft.error ? h('div', { className: 'tb-feedback err' }, format(t('board.error'), { error: draft.error })) : null,
5209
5850
  h(
5210
5851
  'div',
@@ -5230,6 +5871,12 @@ window.__ModuleLoader__.load({
5230
5871
  window.__TIMEBACK_TEST__.WorkspacePathSelector = WorkspacePathSelector
5231
5872
  window.__TIMEBACK_TEST__.markdownToEditorHtml = markdownToEditorHtml
5232
5873
  window.__TIMEBACK_TEST__.domToMarkdown = domToMarkdown
5874
+ window.__TIMEBACK_TEST__.turnRows = turnRows
5875
+ window.__TIMEBACK_TEST__.mergeCardFolder = mergeCardFolder
5876
+ window.__TIMEBACK_TEST__.removeFolderMember = removeFolderMember
5877
+ window.__TIMEBACK_TEST__.layoutTree = layoutTree
5878
+ window.__TIMEBACK_TEST__.CanvasFolderCard = CanvasFolderCard
5879
+ window.__TIMEBACK_TEST__.TreeCanvas = TreeCanvas
5233
5880
  }
5234
5881
 
5235
5882
  return {