dsh-timeback 0.7.8 → 0.7.9

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 CHANGED
@@ -113,7 +113,7 @@ desktop app):
113
113
  ```bash
114
114
  # From npm (published: https://www.npmjs.com/package/dsh-timeback)
115
115
  dsh plugin --profile web add dsh-timeback
116
- dsh plugin --profile web add dsh-timeback@0.7.8 # pin a release
116
+ dsh plugin --profile web add dsh-timeback@0.7.9 # pin a release
117
117
 
118
118
  # Straight from GitHub (no npm release needed)
119
119
  dsh plugin --profile web add github:<owner>/dsh-timeback
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.8+sticky'
26
+ const BUILD = '0.7.9+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. */
@@ -62,6 +62,12 @@ window.__ModuleLoader__.load({
62
62
  'panel.confirmRewind': '将创建新分支并恢复工作区到:{who}\n\n{warning}\n\n确定继续?',
63
63
  'panel.confirmFiles': '将把工作区文件恢复为:{who}\n\n{warning}\n\n确定继续?',
64
64
  'panel.branchNamePrompt': '输入新分支会话的名称:',
65
+ 'panel.branchNameTitle': '新分支名称',
66
+ 'panel.confirm': '确定',
67
+ 'panel.cancel': '取消',
68
+ 'panel.close': '关闭',
69
+ 'panel.branchNameHint': '输入新分支会话的名称;留空则使用默认名称。',
70
+ 'panel.createBranch': '创建分支',
65
71
  'panel.confirmBranchOnly': '将在该检查点创建新分支,不修改工作区文件:{who}\n\n确定继续?',
66
72
  'panel.confirmCheckpoint': '将记录当前对话位置与工作区快照。确定继续?',
67
73
  'panel.deleteWarning': '快照之后新增的文件会被删除,之后修改的文件会被覆盖。回退前会自动保存安全快照,可用它撤销本次恢复。',
@@ -130,7 +136,9 @@ window.__ModuleLoader__.load({
130
136
  'board.fontSize': '字号',
131
137
  'board.deleteText': '删除文本',
132
138
  'board.insert': '插入',
139
+ 'board.clear': '清理',
133
140
  'board.insertHint': '添加表格、导入表格或导入图片窗口',
141
+ 'board.clearHint': '清理背景笔迹、路径或选中便签的笔迹',
134
142
  'board.table': '表格',
135
143
  'board.importTable': '导入表格',
136
144
  'board.importImage': '导入图片',
@@ -142,6 +150,11 @@ window.__ModuleLoader__.load({
142
150
  'board.chooseImage': '选择图片',
143
151
  'board.imageHint': '图片窗口可拖动,右下角可缩放;大小上限约 1.5MB。',
144
152
  'board.windowTitle': '窗口标题',
153
+ 'board.tableTooLarge': '表格文件过大(上限约 2MB)',
154
+ 'board.tableReadFailed': '表格读取失败',
155
+ 'board.imageType': '请选择图片文件',
156
+ 'board.imageTooLarge': '图片过大(上限约 1.5MB)',
157
+ 'board.imageReadFailed': '图片读取失败',
145
158
  'board.docHint': '完整 Markdown 文档页:默认展开预览,可拖动右下角调整大小。',
146
159
  'board.stickyColor': '便签颜色',
147
160
  'board.stickyHint': '便签可拖动;画笔可在方格纸背景或便签上绘制,橡皮擦除笔画。',
@@ -339,6 +352,12 @@ window.__ModuleLoader__.load({
339
352
  'panel.confirmRewind': 'Create a new branch and restore the workspace to: {who}\n\n{warning}\n\nContinue?',
340
353
  'panel.confirmFiles': 'Restore workspace files to: {who}\n\n{warning}\n\nContinue?',
341
354
  'panel.branchNamePrompt': 'Name for the new branch session:',
355
+ 'panel.branchNameTitle': 'New branch name',
356
+ 'panel.confirm': 'Confirm',
357
+ 'panel.cancel': 'Cancel',
358
+ 'panel.close': 'Close',
359
+ 'panel.branchNameHint': 'Name the new branch session; leave blank to use the default.',
360
+ 'panel.createBranch': 'Create branch',
342
361
  'panel.confirmBranchOnly': 'Create a new branch at this checkpoint without touching files: {who}\n\nContinue?',
343
362
  'panel.confirmCheckpoint': 'Record the current conversation position and a workspace snapshot?',
344
363
  'panel.deleteWarning': 'Files created after the snapshot are deleted and files changed later are overwritten. A safety snapshot is taken first; it can undo this restore.',
@@ -407,7 +426,9 @@ window.__ModuleLoader__.load({
407
426
  'board.fontSize': 'Font size',
408
427
  'board.deleteText': 'Delete text',
409
428
  'board.insert': 'Insert',
429
+ 'board.clear': 'Clear',
410
430
  'board.insertHint': 'Add a table, import a table, or import an image window',
431
+ 'board.clearHint': 'Clear background drawings, links, or the selected note drawing',
411
432
  'board.table': 'Table',
412
433
  'board.importTable': 'Import table',
413
434
  'board.importImage': 'Import image',
@@ -419,6 +440,11 @@ window.__ModuleLoader__.load({
419
440
  'board.chooseImage': 'Choose image',
420
441
  'board.imageHint': 'Image windows can be dragged and resized from the bottom-right; max about 1.5MB.',
421
442
  'board.windowTitle': 'Window title',
443
+ 'board.tableTooLarge': 'Table file is too large (max about 2MB)',
444
+ 'board.tableReadFailed': 'Could not read the table file',
445
+ 'board.imageType': 'Please choose an image file',
446
+ 'board.imageTooLarge': 'Image is too large (max about 1.5MB)',
447
+ 'board.imageReadFailed': 'Could not read the image file',
422
448
  'board.docHint': 'Full Markdown document page: expanded preview by default, resize from the bottom-right corner.',
423
449
  'board.stickyColor': 'Sticky colour',
424
450
  '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.',
@@ -615,6 +641,7 @@ window.__ModuleLoader__.load({
615
641
  .tb-btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.1))}
616
642
  .tb-btn:disabled{opacity:.5;cursor:default}
617
643
  .tb-btn.primary{border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff)}
644
+ .tb-btn.on{border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff)}
618
645
  .tb-btn.danger{border-color:var(--dsw-alias-state-warning-primary,rgba(240,178,62,.5));color:var(--dsw-alias-state-warning-primary,#f0b23e)}
619
646
  .tb-body{flex:1;min-height:120px;overflow:auto;padding:10px 12px 28px;display:flex;flex-direction:column;gap:8px}
620
647
  .tb-ws-select{display:flex;flex-direction:column;gap:5px;margin:3px 0 4px}
@@ -674,7 +701,7 @@ window.__ModuleLoader__.load({
674
701
  .tb-canvas-btn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.1));color:var(--dsw-alias-label-primary,#e6e6e6)}
675
702
  .tb-world{position:absolute;left:0;top:0;transform-origin:0 0}
676
703
  .tb-tree-doodles{position:absolute;left:0;top:0;overflow:visible;z-index:50}
677
- .tb-tree-doodles polyline{fill:none;stroke-linecap:round;stroke-linejoin:round}
704
+ .tb-tree-doodles polyline,.tb-tree-doodles path{fill:none;stroke-linecap:round;stroke-linejoin:round}
678
705
  .tb-world-links{position:absolute;left:0;top:0;pointer-events:none;overflow:visible}
679
706
  .tb-link{fill:none;stroke-width:1.6;opacity:.55}
680
707
  .tb-link.fork{stroke-width:2;opacity:.75}
@@ -745,7 +772,11 @@ window.__ModuleLoader__.load({
745
772
  .tb-card-editnote.has{color:var(--tb-color,#4d7cfe);border-color:color-mix(in srgb, var(--tb-color,#4d7cfe) 50%, transparent)}
746
773
  .tb-overlay{position:fixed;inset:0;z-index:60;background:rgba(0,0,0,.35);display:flex;justify-content:flex-end;align-items:stretch}
747
774
  .tb-overlay.center{justify-content:center;align-items:center;padding:16px}
748
- .tb-chat-dialog{width:min(640px,94vw);height:min(680px,88vh);display:flex;flex-direction:column;gap:8px}
775
+ .tb-board-dialog.tb-branch-dialog{width:min(470px,92vw);height:auto;min-height:0;display:flex;flex-direction:column;gap:8px}
776
+ .tb-board-dialog.tb-branch-dialog input{font-family:inherit;font-size:13px}
777
+ .tb-branch-message{white-space:pre-wrap;font-size:12px;line-height:1.6;color:var(--dsw-alias-label-primary,#e6e6e6);background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.05));border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));border-radius:7px;padding:7px 9px;max-height:180px;overflow:auto}
778
+ .tb-note-dialog.tb-chat-dialog{width:min(640px,94vw);height:100%;display:flex;flex-direction:column;gap:8px}
779
+ .tb-note-dialog.tb-chat-dialog .tb-chat-composer textarea{min-height:64px;max-height:180px;font-family:inherit}
749
780
  .tb-chat-messages{flex:1;min-height:0;overflow:auto;display:flex;flex-direction:column;gap:8px;padding:2px 2px 4px}
750
781
  .tb-chat-msg{border-radius:8px;padding:7px 9px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.1));background:var(--dsw-alias-bg-base,#1b1d22)}
751
782
  .tb-chat-msg.user{background:rgba(77,124,254,.13);border-color:rgba(77,124,254,.4)}
@@ -810,6 +841,8 @@ window.__ModuleLoader__.load({
810
841
  .tb-board-bgdraw{position:absolute;left:0;top:0;pointer-events:none;overflow:visible}
811
842
  .tb-window-insert{position:relative;display:inline-flex}
812
843
  .tb-insert-menu{left:0;top:calc(100% + 4px);min-width:180px}
844
+ .tb-clear-menu{left:0;top:calc(100% + 4px);min-width:160px}
845
+ .tb-clear-menu button:disabled{opacity:.4;cursor:default}
813
846
  .tb-board-window{position:absolute;display:flex;flex-direction:column;box-sizing:border-box;border-radius:8px;overflow:hidden;background:var(--dsw-alias-bg-elevated,#22252b);border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.18));box-shadow:0 8px 24px rgba(0,0,0,.3);color:var(--dsw-alias-label-primary,#e6e6e6)}
814
847
  .tb-board-window.selected{outline:2px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff);outline-offset:1px}
815
848
  .tb-board-window-head{display:flex;align-items:center;gap:6px;padding:4px 6px;background:rgba(255,255,255,.05);cursor:grab;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));flex:0 0 auto;user-select:none}
@@ -824,6 +857,7 @@ window.__ModuleLoader__.load({
824
857
  .tb-board-window-body img{display:block;width:100%;height:100%;object-fit:contain;background:rgba(0,0,0,.14)}
825
858
  .tb-board-window-resize{position:absolute;right:0;bottom:0;width:14px;height:14px;cursor:nwse-resize;z-index:5;opacity:.55;background:linear-gradient(135deg,transparent 45%,rgba(255,255,255,.55) 45%,rgba(255,255,255,.55) 55%,transparent 55%)}
826
859
  .tb-window-editor-dialog{width:min(760px,94vw);height:auto;max-height:92vh;display:flex;flex-direction:column;gap:8px}
860
+ .tb-window-editor-dialog .tb-text-input{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12.5px}
827
861
  .tb-window-editor-body{display:flex;flex-direction:column;gap:6px;min-height:0}
828
862
  .tb-table-editor-preview{max-height:150px;overflow:auto;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));border-radius:6px;background:rgba(255,255,255,.02)}
829
863
  .tb-table-editor-preview table{border-collapse:collapse;width:100%;font-size:12px}
@@ -840,6 +874,8 @@ window.__ModuleLoader__.load({
840
874
  .tb-board-text-actions button:hover{background:rgba(255,255,255,.12);color:#fff}
841
875
  .tb-text-dialog{width:min(700px,94vw);height:auto;max-height:90vh;display:flex;flex-direction:column;gap:8px}
842
876
  .tb-text-input{box-sizing:border-box;width:100%;min-height:110px;resize:vertical;background:var(--dsw-alias-bg-base,#16181d);color:var(--dsw-alias-label-primary,#e6e6e6);border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));border-radius:6px;padding:8px;font:inherit;font-size:14px;line-height:1.55;outline:none}
877
+ .tb-board-dialog .tb-text-input{font-family:inherit;font-size:13px;line-height:1.55}
878
+ .tb-board-dialog input{font-family:inherit;font-size:13px}
843
879
  .tb-text-input:focus{border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff)}
844
880
  .tb-text-row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
845
881
  .tb-text-swatches{display:flex;gap:4px;flex-wrap:wrap}
@@ -921,6 +957,8 @@ window.__ModuleLoader__.load({
921
957
  .tb-md-tool:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.1));color:var(--dsw-alias-label-primary,#e6e6e6)}
922
958
  .tb-md-tool.on{color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff);border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
923
959
  .tb-md-mode{margin-left:auto;display:flex;gap:2px;flex:0 0 auto}
960
+ .tb-md-linkbar{display:flex;align-items:center;gap:6px;padding:4px 5px;border:1px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);border-radius:7px;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.04))}
961
+ .tb-md-link-input{flex:1;min-width:120px;box-sizing:border-box;background:var(--dsw-alias-bg-base,#16181d);color:var(--dsw-alias-label-primary,#e6e6e6);border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));border-radius:5px;padding:4px 7px;font-size:12px;outline:none}
924
962
  .tb-md-colorbar{display:flex;align-items:center;gap:5px;flex-wrap:nowrap;overflow:hidden;padding:3px 5px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.10));border-radius:7px;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.02))}
925
963
  .tb-md-color-label{font-size:12px;color:var(--dsw-alias-label-secondary,#9aa0a6);margin-right:1px}
926
964
  .tb-md-body{display:flex;gap:8px;flex:1;min-height:0;overflow:hidden}
@@ -2198,11 +2236,14 @@ window.__ModuleLoader__.load({
2198
2236
  },
2199
2237
  },
2200
2238
  ...(doodles ?? []).map((stroke, index) =>
2201
- h('polyline', {
2239
+ h('path', {
2202
2240
  key: `doodle-${index}`,
2203
- points: (stroke.points ?? []).map((point) => `${point[0]},${point[1]}`).join(' '),
2241
+ d: smoothStrokePath(stroke.points),
2242
+ fill: 'none',
2204
2243
  stroke: stroke.color || '#ff5f56',
2205
2244
  strokeWidth: stroke.width || 3,
2245
+ strokeLinecap: 'round',
2246
+ strokeLinejoin: 'round',
2206
2247
  opacity: 0.9,
2207
2248
  }),
2208
2249
  ),
@@ -2489,6 +2530,7 @@ window.__ModuleLoader__.load({
2489
2530
  panSpeedRef.current = panSpeed
2490
2531
  const [noteEditor, setNoteEditor] = React.useState(null)
2491
2532
  const [chat, setChat] = React.useState(null)
2533
+ const [branchPrompt, setBranchPrompt] = React.useState(null)
2492
2534
  const viewportRef = React.useRef(null)
2493
2535
  const worldRef = React.useRef(null)
2494
2536
  const cameraRef = React.useRef({ x: 0, y: 0, scale: 1 })
@@ -2516,6 +2558,10 @@ window.__ModuleLoader__.load({
2516
2558
  setFeedback(null)
2517
2559
  setBusy('')
2518
2560
  setSelectedKey(null)
2561
+ setChat(null)
2562
+ setBranchPrompt(null)
2563
+ setInsertMenu(false)
2564
+ setClearMenu(false)
2519
2565
  busyRef.current = ''
2520
2566
  cameraRef.current = { x: 0, y: 0, scale: 1 }
2521
2567
  fittedRef.current = ''
@@ -2580,27 +2626,10 @@ window.__ModuleLoader__.load({
2580
2626
  return ''
2581
2627
  }
2582
2628
 
2583
- const act = async (action, checkpoint, mode, targetSessionId, existingChildSessionId) => {
2629
+ const runAct = async (action, checkpoint, mode, targetSessionId, existingChildSessionId, branchName = '') => {
2584
2630
  const data = state.data
2585
2631
  if (!data || data.currentSessionId !== sessionId) return
2586
2632
  const actionSessionId = targetSessionId || sessionId
2587
- const who = checkpoint ? checkpointName(checkpoint, t) : ''
2588
- let message
2589
- if (action === 'checkpoint') message = t('panel.confirmCheckpoint')
2590
- else if (action === 'prune') message = format(t('panel.confirmPrune'), { who })
2591
- else if (mode === 'branch-only') message = format(t('panel.confirmBranchOnly'), { who })
2592
- else if (action === 'restore-files') message = format(t('panel.confirmFiles'), { who, warning: t('panel.deleteWarning') })
2593
- else message = format(t('panel.confirmRewind'), { who, warning: t('panel.deleteWarning') })
2594
- if (!window.confirm(message)) return
2595
- let branchName = ''
2596
- if (action === 'rewind' && mode !== 'files-only') {
2597
- const source = (data.sessions ?? []).find((entry) => entry.sessionId === actionSessionId)
2598
- const suffix = Number.isInteger(checkpoint?.turn) ? ` · T${checkpoint.turn}` : ''
2599
- const fallbackName = `${source?.title || t('panel.branch')} · ${t('panel.branch')}${suffix}`
2600
- const entered = window.prompt(t('panel.branchNamePrompt'), fallbackName)
2601
- if (entered === null) return
2602
- branchName = (entered || '').trim() || fallbackName
2603
- }
2604
2633
  const busyKey = checkpoint ? checkpoint.id : action
2605
2634
  setBusy(busyKey)
2606
2635
  busyRef.current = busyKey
@@ -2679,6 +2708,47 @@ window.__ModuleLoader__.load({
2679
2708
  }
2680
2709
  }
2681
2710
 
2711
+ const act = async (action, checkpoint, mode, targetSessionId, existingChildSessionId) => {
2712
+ const data = state.data
2713
+ if (!data || data.currentSessionId !== sessionId) return
2714
+ const actionSessionId = targetSessionId || sessionId
2715
+ const who = checkpoint ? checkpointName(checkpoint, t) : ''
2716
+ let message
2717
+ if (action === 'checkpoint') message = t('panel.confirmCheckpoint')
2718
+ else if (action === 'prune') message = format(t('panel.confirmPrune'), { who })
2719
+ else if (mode === 'branch-only') message = format(t('panel.confirmBranchOnly'), { who })
2720
+ else if (action === 'restore-files') message = format(t('panel.confirmFiles'), { who, warning: t('panel.deleteWarning') })
2721
+ else message = format(t('panel.confirmRewind'), { who, warning: t('panel.deleteWarning') })
2722
+ if (action === 'rewind' && mode !== 'files-only') {
2723
+ // One dialog for both the warning and the branch name: desktop webviews
2724
+ // do not support window.prompt and a second modal is easy to miss.
2725
+ const source = (data.sessions ?? []).find((entry) => entry.sessionId === actionSessionId)
2726
+ const suffix = Number.isInteger(checkpoint?.turn) ? ` · T${checkpoint.turn}` : ''
2727
+ const fallbackName = `${source?.title || t('panel.branch')} · ${t('panel.branch')}${suffix}`
2728
+ setBranchPrompt({
2729
+ action,
2730
+ checkpoint,
2731
+ mode,
2732
+ targetSessionId,
2733
+ existingChildSessionId,
2734
+ defaultName: fallbackName,
2735
+ name: fallbackName,
2736
+ message,
2737
+ })
2738
+ return
2739
+ }
2740
+ if (!window.confirm(message)) return
2741
+ await runAct(action, checkpoint, mode, targetSessionId, existingChildSessionId, '')
2742
+ }
2743
+
2744
+ const confirmBranchPrompt = async () => {
2745
+ const prompt = branchPrompt
2746
+ if (!prompt) return
2747
+ setBranchPrompt(null)
2748
+ const name = String(prompt.name ?? '').trim() || prompt.defaultName
2749
+ await runAct(prompt.action, prompt.checkpoint, prompt.mode, prompt.targetSessionId, prompt.existingChildSessionId, name)
2750
+ }
2751
+
2682
2752
  const toggleWorkspace = async (enabled, explicitCwd) => {
2683
2753
  if (busyRef.current !== '') return
2684
2754
  const data = state.data
@@ -2860,9 +2930,24 @@ window.__ModuleLoader__.load({
2860
2930
  // eslint-disable-next-line react-hooks/exhaustive-deps
2861
2931
  }, [view, data?.currentSessionId, layoutReady])
2862
2932
 
2863
- const positionsKey = data?.rootSessionId ? `dsh-timeback:card-positions:${data.rootSessionId}` : null
2864
- const foldersKey = data?.rootSessionId ? `dsh-timeback:card-folders:${data.rootSessionId}` : null
2865
- const doodlesKey = data?.rootSessionId ? `dsh-timeback:tree-doodles:${data.rootSessionId}` : null
2933
+ // Canvas layout belongs to the workspace, not one branch-family root:
2934
+ // pruning a branch replaces rootSessionId and used to make positions,
2935
+ // folder names and doodles disappear. Keep old root-scoped keys as
2936
+ // one-time migration sources.
2937
+ const layoutScope = data?.workspace?.cwd
2938
+ ? `ws:${data.workspace.cwd}`
2939
+ : data?.rootSessionId
2940
+ ? `root:${data.rootSessionId}`
2941
+ : null
2942
+ const scopeKey = (kind) => (layoutScope ? `dsh-timeback:${kind}:${layoutScope}` : null)
2943
+ // Pre-0.7.9 layout keys were scoped by the bare root session id.
2944
+ const legacyScopeKey = (kind) => (data?.rootSessionId ? `dsh-timeback:${kind}:${data.rootSessionId}` : null)
2945
+ const positionsKey = scopeKey('card-positions')
2946
+ const foldersKey = scopeKey('card-folders')
2947
+ const doodlesKey = scopeKey('tree-doodles')
2948
+ const legacyPositionsKey = legacyScopeKey('card-positions')
2949
+ const legacyFoldersKey = legacyScopeKey('card-folders')
2950
+ const legacyDoodlesKey = legacyScopeKey('tree-doodles')
2866
2951
 
2867
2952
  // Restore dragged card positions and folders for this branch family.
2868
2953
  React.useEffect(() => {
@@ -2870,12 +2955,20 @@ window.__ModuleLoader__.load({
2870
2955
  let saved = {}
2871
2956
  let savedFolders = []
2872
2957
  let savedDoodles = []
2958
+ const readScope = (key, legacyKey) => {
2959
+ let raw = key ? window.localStorage.getItem(key) : null
2960
+ if (!raw && legacyKey && legacyKey !== key) {
2961
+ raw = window.localStorage.getItem(legacyKey)
2962
+ if (raw && key) window.localStorage.setItem(key, raw)
2963
+ }
2964
+ return raw
2965
+ }
2873
2966
  try {
2874
- const raw = window.localStorage.getItem(positionsKey)
2967
+ const raw = readScope(positionsKey, legacyPositionsKey)
2875
2968
  if (raw) saved = JSON.parse(raw)
2876
- const rawFolders = window.localStorage.getItem(foldersKey)
2969
+ const rawFolders = readScope(foldersKey, legacyFoldersKey)
2877
2970
  if (rawFolders) savedFolders = JSON.parse(rawFolders)
2878
- const rawDoodles = window.localStorage.getItem(doodlesKey)
2971
+ const rawDoodles = readScope(doodlesKey, legacyDoodlesKey)
2879
2972
  if (rawDoodles) savedDoodles = JSON.parse(rawDoodles)
2880
2973
  } catch {
2881
2974
  saved = {}
@@ -2900,7 +2993,7 @@ window.__ModuleLoader__.load({
2900
2993
  setFolders(savedFolders)
2901
2994
  doodlesRef.current = savedDoodles
2902
2995
  setDoodles(savedDoodles)
2903
- }, [positionsKey, foldersKey, doodlesKey])
2996
+ }, [positionsKey, foldersKey, doodlesKey, legacyPositionsKey, legacyFoldersKey, legacyDoodlesKey])
2904
2997
 
2905
2998
  // Wheel zoom must be non-passive, so it is bound directly to the viewport.
2906
2999
  React.useEffect(() => {
@@ -3006,21 +3099,32 @@ window.__ModuleLoader__.load({
3006
3099
  }
3007
3100
  const startPoint = toWorld(event)
3008
3101
  const stroke = { color: '#ff5f56', width: 3, points: [startPoint] }
3009
- let strokes = [...doodlesRef.current, stroke]
3010
- setDoodles(strokes)
3102
+ let frame = 0
3103
+ setDoodles([...doodlesRef.current, stroke])
3011
3104
  const move = (next) => {
3012
- const point = toWorld(next)
3013
- const last = stroke.points[stroke.points.length - 1]
3014
- if (last && Math.abs(last[0] - point[0]) + Math.abs(last[1] - point[1]) < 2) return
3015
- if (stroke.points.length >= 2000) return
3016
- stroke.points = [...stroke.points, point]
3017
- strokes = [...doodlesRef.current, stroke]
3018
- setDoodles(strokes)
3105
+ const samples = typeof next.getCoalescedEvents === 'function' ? next.getCoalescedEvents() : [next]
3106
+ for (const sample of samples.length > 0 ? samples : [next]) {
3107
+ if (stroke.points.length >= 2000) break
3108
+ const point = toWorld(sample)
3109
+ const last = stroke.points[stroke.points.length - 1]
3110
+ if (last && last[0] === point[0] && last[1] === point[1]) continue
3111
+ stroke.points.push(point)
3112
+ }
3113
+ if (!frame) {
3114
+ frame = window.requestAnimationFrame(() => {
3115
+ frame = 0
3116
+ setDoodles([...doodlesRef.current, stroke])
3117
+ })
3118
+ }
3019
3119
  }
3020
3120
  const finish = () => {
3021
3121
  window.removeEventListener('pointermove', move)
3022
3122
  window.removeEventListener('pointerup', finish)
3023
3123
  window.removeEventListener('pointercancel', finish)
3124
+ if (frame) {
3125
+ window.cancelAnimationFrame(frame)
3126
+ frame = 0
3127
+ }
3024
3128
  doodlesRef.current = [...doodlesRef.current.filter((item) => item !== stroke), stroke].slice(-200)
3025
3129
  storeDoodles(doodlesRef.current, true)
3026
3130
  }
@@ -3295,7 +3399,7 @@ window.__ModuleLoader__.load({
3295
3399
  /** Read the turn behind one card and open its conversation/composer. */
3296
3400
  const openCardConversation = async (card) => {
3297
3401
  if (!card || card.kind === 'folder') return
3298
- const base = { card, loading: true, messages: [], error: null, input: '', sending: false }
3402
+ const base = { card, loading: true, messages: [], error: null, input: '', sending: false, branchedTo: null }
3299
3403
  setChat(base)
3300
3404
  if (!sessionApi) {
3301
3405
  setChat({ ...base, loading: false, error: t('chat.unavailable') })
@@ -3349,9 +3453,9 @@ window.__ModuleLoader__.load({
3349
3453
  const data = state.data
3350
3454
  const layout = data ? layoutTree(data.sessions ?? [], data.currentSessionId, positionsRef.current, foldersRef.current) : null
3351
3455
  const tail = cardIsTail(current.card, layout, data)
3352
- let targetSessionId = current.card.sessionId
3353
- let branched = false
3354
- if (!tail) {
3456
+ let targetSessionId = current.branchedTo || current.card.sessionId
3457
+ let branched = Boolean(current.branchedTo)
3458
+ if (!tail && !current.branchedTo) {
3355
3459
  const checkpoints = current.card.checkpoints ?? []
3356
3460
  const checkpoint =
3357
3461
  [...checkpoints].reverse().find((entry) => Number.isInteger(entry.seq) && entry.phase !== 'before') ??
@@ -3364,15 +3468,17 @@ window.__ModuleLoader__.load({
3364
3468
  sessionId: current.card.sessionId,
3365
3469
  checkpointId: checkpoint.id,
3366
3470
  mode: 'branch-only',
3367
- name: text.slice(0, 120),
3471
+ name: text.replace(/\s+/g, ' ').trim().slice(0, 120),
3368
3472
  },
3369
3473
  })
3370
3474
  if (!result?.childSessionId) throw new Error(t('chat.noCheckpoint'))
3371
3475
  targetSessionId = result.childSessionId
3372
3476
  branched = true
3373
- // Open the replacement session before prompting so its Client
3374
- // session object is materialized and ready for the composer.
3375
- openChild(targetSessionId)
3477
+ // Keep the created branch on the draft so a failed prompt can be
3478
+ // retried without creating a second branch. Do not switch the UI
3479
+ // session yet: that would reset the chat drawer and hide a prompt
3480
+ // error; the catalog refresh below makes the new branch resolvable.
3481
+ setChat((previous) => (previous ? { ...previous, branchedTo: targetSessionId } : previous))
3376
3482
  }
3377
3483
  const promptOnce = () =>
3378
3484
  sessionApi.using(targetSessionId, { source: 'gateway' }, async (reference) => {
@@ -3389,6 +3495,7 @@ window.__ModuleLoader__.load({
3389
3495
  if (result && result.ok === false) {
3390
3496
  throw new Error(result.error?.message ? String(result.error.message) : JSON.stringify(result.error))
3391
3497
  }
3498
+ if (branched) openChild(targetSessionId)
3392
3499
  setChat(null)
3393
3500
  setFeedback({ tone: 'ok', text: branched ? t('chat.branched') : t('chat.sent') })
3394
3501
  setTick((value) => value + 1)
@@ -3438,17 +3545,14 @@ window.__ModuleLoader__.load({
3438
3545
  /** Clear dragged positions and return to the automatic layout. */
3439
3546
  const resetCardPositions = () => {
3440
3547
  try {
3441
- if (positionsKey) window.localStorage.removeItem(positionsKey)
3548
+ for (const key of [positionsKey, legacyPositionsKey, foldersKey, legacyFoldersKey]) {
3549
+ if (key) window.localStorage.removeItem(key)
3550
+ }
3442
3551
  } catch {
3443
3552
  // Storage can be disabled.
3444
3553
  }
3445
3554
  positionsRef.current = {}
3446
3555
  setPositions({})
3447
- try {
3448
- if (foldersKey) window.localStorage.removeItem(foldersKey)
3449
- } catch {
3450
- // Storage can be disabled.
3451
- }
3452
3556
  foldersRef.current = []
3453
3557
  setFolders([])
3454
3558
  }
@@ -3473,7 +3577,6 @@ window.__ModuleLoader__.load({
3473
3577
  { className: 'tb-muted tb-small', title: `timeback client ${BUILD}` },
3474
3578
  format(t('panel.branchCount'), { sessions: sessions.length, checkpoints: checkpointTotal }),
3475
3579
  ),
3476
- h('span', { className: 'tb-muted tb-small', title: 'timeback client build' }, BUILD),
3477
3580
  h('span', { style: { flex: 1 } }),
3478
3581
  h(
3479
3582
  'button',
@@ -3760,7 +3863,7 @@ window.__ModuleLoader__.load({
3760
3863
  : h('div', { className: 'tb-chat-text' }, message.text),
3761
3864
  ),
3762
3865
  )
3763
- : h('div', { className: 'tb-empty tb-small' }, chat.error || t('chat.empty')),
3866
+ : h('div', { className: 'tb-empty tb-small' }, t('chat.empty')),
3764
3867
  ),
3765
3868
  chat.error && !chat.loading
3766
3869
  ? h('div', { className: 'tb-feedback err' }, chat.error)
@@ -3774,6 +3877,7 @@ window.__ModuleLoader__.load({
3774
3877
  disabled: chat.sending,
3775
3878
  onChange: (event) => setChat((current) => (current ? { ...current, input: event.target.value } : current)),
3776
3879
  onKeyDown: (event) => {
3880
+ if (event.nativeEvent?.isComposing) return
3777
3881
  if (event.key === 'Enter' && !event.shiftKey) {
3778
3882
  event.preventDefault()
3779
3883
  sendChatMessage()
@@ -3788,7 +3892,7 @@ window.__ModuleLoader__.load({
3788
3892
  {
3789
3893
  type: 'button',
3790
3894
  className: 'tb-btn',
3791
- onClick: () => openSessionByCard(chat.card.sessionId),
3895
+ onClick: () => openSessionByCard(chat.branchedTo || chat.card.sessionId),
3792
3896
  },
3793
3897
  t('chat.openSession'),
3794
3898
  ),
@@ -3808,6 +3912,54 @@ window.__ModuleLoader__.load({
3808
3912
  ),
3809
3913
  )
3810
3914
  : null,
3915
+ branchPrompt
3916
+ ? h(
3917
+ 'div',
3918
+ { className: 'tb-overlay center', onClick: () => setBranchPrompt(null) },
3919
+ h(
3920
+ 'div',
3921
+ {
3922
+ className: 'tb-board-dialog tb-branch-dialog',
3923
+ role: 'dialog',
3924
+ 'aria-modal': true,
3925
+ onClick: (event) => event.stopPropagation(),
3926
+ },
3927
+ h(
3928
+ 'div',
3929
+ { className: 'tb-detail-head' },
3930
+ h('span', { className: 'tb-detail-title' }, t('panel.branchNameTitle')),
3931
+ h('span', { style: { flex: 1 } }),
3932
+ ),
3933
+ branchPrompt.message ? h('div', { className: 'tb-branch-message' }, branchPrompt.message) : null,
3934
+ h('div', { className: 'tb-ws-hint' }, t('panel.branchNameHint')),
3935
+ h('input', {
3936
+ value: branchPrompt.name ?? '',
3937
+ autoFocus: true,
3938
+ placeholder: branchPrompt.defaultName,
3939
+ onFocus: (event) => event.target.select(),
3940
+ onChange: (event) =>
3941
+ setBranchPrompt((current) => (current ? { ...current, name: event.target.value } : current)),
3942
+ onKeyDown: (event) => {
3943
+ event.stopPropagation()
3944
+ if (event.nativeEvent?.isComposing) return
3945
+ if (event.key === 'Enter') {
3946
+ event.preventDefault()
3947
+ confirmBranchPrompt()
3948
+ } else if (event.key === 'Escape') {
3949
+ event.preventDefault()
3950
+ setBranchPrompt(null)
3951
+ }
3952
+ },
3953
+ }),
3954
+ h(
3955
+ 'div',
3956
+ { className: 'tb-note-actions' },
3957
+ h('button', { type: 'button', className: 'tb-btn', onClick: () => setBranchPrompt(null) }, t('panel.cancel')),
3958
+ h('button', { type: 'button', className: 'tb-btn primary', onClick: confirmBranchPrompt }, t('panel.createBranch')),
3959
+ ),
3960
+ ),
3961
+ )
3962
+ : null,
3811
3963
  )
3812
3964
  }
3813
3965
 
@@ -4581,6 +4733,27 @@ window.__ModuleLoader__.load({
4581
4733
  }
4582
4734
 
4583
4735
  /** Render pen strokes and common shapes for one stroke layer. */
4736
+ /** Smooth a freehand point list with Catmull-Rom -> cubic Bezier. */
4737
+ function smoothStrokePath(points) {
4738
+ const list = Array.isArray(points) ? points : []
4739
+ if (list.length === 0) return ''
4740
+ if (list.length === 1) return `M ${list[0][0]} ${list[0][1]} L ${list[0][0] + 0.1} ${list[0][1] + 0.1}`
4741
+ if (list.length === 2) return `M ${list[0][0]} ${list[0][1]} L ${list[1][0]} ${list[1][1]}`
4742
+ let d = `M ${list[0][0]} ${list[0][1]}`
4743
+ for (let index = 0; index < list.length - 1; index += 1) {
4744
+ const p0 = list[index - 1] ?? list[index]
4745
+ const p1 = list[index]
4746
+ const p2 = list[index + 1]
4747
+ const p3 = list[index + 2] ?? p2
4748
+ const cp1x = p1[0] + (p2[0] - p0[0]) / 6
4749
+ const cp1y = p1[1] + (p2[1] - p0[1]) / 6
4750
+ const cp2x = p2[0] - (p3[0] - p1[0]) / 6
4751
+ const cp2y = p2[1] - (p3[1] - p1[1]) / 6
4752
+ d += ` C ${cp1x.toFixed(2)} ${cp1y.toFixed(2)} ${cp2x.toFixed(2)} ${cp2y.toFixed(2)} ${p2[0]} ${p2[1]}`
4753
+ }
4754
+ return d
4755
+ }
4756
+
4584
4757
  function boardStrokeElements(strokes, keyPrefix) {
4585
4758
  return (strokes ?? []).map((stroke, index) => {
4586
4759
  const key = `${keyPrefix}-${index}`
@@ -4589,9 +4762,9 @@ window.__ModuleLoader__.load({
4589
4762
  const color = stroke.color
4590
4763
  const width = stroke.width
4591
4764
  if (kind === 'pen' || points.length < 2) {
4592
- return h('polyline', {
4765
+ return h('path', {
4593
4766
  key,
4594
- points: points.map((point) => `${point[0]},${point[1]}`).join(' '),
4767
+ d: smoothStrokePath(points),
4595
4768
  fill: 'none',
4596
4769
  stroke: color,
4597
4770
  strokeWidth: width,
@@ -4632,13 +4805,14 @@ window.__ModuleLoader__.load({
4632
4805
  h('polygon', { points: boardArrowHead(a, b, width), fill: color, stroke: 'none' }),
4633
4806
  )
4634
4807
  }
4635
- return h('polyline', {
4808
+ return h('path', {
4636
4809
  key,
4637
- points: points.map((point) => `${point[0]},${point[1]}`).join(' '),
4810
+ d: smoothStrokePath(points),
4638
4811
  fill: 'none',
4639
4812
  stroke: color,
4640
4813
  strokeWidth: width,
4641
4814
  strokeLinecap: 'round',
4815
+ strokeLinejoin: 'round',
4642
4816
  })
4643
4817
  })
4644
4818
  }
@@ -4871,6 +5045,7 @@ window.__ModuleLoader__.load({
4871
5045
  const onChange = typeof props?.onChange === 'function' ? props.onChange : () => {}
4872
5046
  const disabled = props?.disabled === true
4873
5047
  const [mode, setMode] = React.useState('rich')
5048
+ const [linkEditor, setLinkEditor] = React.useState(null)
4874
5049
  const sourceRef = React.useRef(null)
4875
5050
  const richRef = React.useRef(null)
4876
5051
  const richRangeRef = React.useRef(null)
@@ -4920,6 +5095,7 @@ window.__ModuleLoader__.load({
4920
5095
  const exec = (command, argument = null) => {
4921
5096
  const element = richRef.current
4922
5097
  if (!element) return
5098
+ let applied = false
4923
5099
  try {
4924
5100
  element.focus({ preventScroll: true })
4925
5101
  const range = richRangeRef.current
@@ -4928,10 +5104,26 @@ window.__ModuleLoader__.load({
4928
5104
  selection.removeAllRanges()
4929
5105
  selection.addRange(range)
4930
5106
  }
4931
- document.execCommand(command, false, argument)
5107
+ applied = document.execCommand(command, false, argument)
4932
5108
  } catch {
4933
5109
  // execCommand can be unavailable; the source tab still works.
4934
5110
  }
5111
+ // Some desktop WebViews disable execCommand but still expose the DOM
5112
+ // Range API; keep the text-colour button working there.
5113
+ if (!applied && command === 'foreColor' && typeof document !== 'undefined') {
5114
+ try {
5115
+ const selection = window.getSelection()
5116
+ const range = selection && selection.rangeCount > 0 ? selection.getRangeAt(0) : null
5117
+ if (range && !range.collapsed) {
5118
+ const span = document.createElement('span')
5119
+ span.style.color = argument
5120
+ span.appendChild(range.extractContents())
5121
+ range.insertNode(span)
5122
+ }
5123
+ } catch {
5124
+ // Leave the document unchanged if the selection cannot be wrapped.
5125
+ }
5126
+ }
4935
5127
  rememberRichSelection()
4936
5128
  syncRich()
4937
5129
  }
@@ -4991,6 +5183,14 @@ window.__ModuleLoader__.load({
4991
5183
  else if (mode === 'source') sourceSurround(`<span style="color:${color}">`, '</span>')
4992
5184
  }
4993
5185
 
5186
+ const submitLink = () => {
5187
+ const href = String(linkEditor?.href ?? '').trim()
5188
+ setLinkEditor(null)
5189
+ if (href === '') return
5190
+ if (mode === 'rich') exec('createLink', href)
5191
+ else sourceSurround('[', `](${href})`)
5192
+ }
5193
+
4994
5194
  const richTools = [
4995
5195
  { key: 'h1', label: 'H1', title: t('md.heading'), run: () => exec('formatBlock', '<h1>') },
4996
5196
  { key: 'h2', label: 'H2', title: t('md.heading'), run: () => exec('formatBlock', '<h2>') },
@@ -5004,15 +5204,7 @@ window.__ModuleLoader__.load({
5004
5204
  { key: 'numbered', label: '1.', title: t('md.numbered'), run: () => exec('insertOrderedList') },
5005
5205
  { key: 'task', label: '☐', title: t('md.task'), run: () => insertHtml('<div>- [ ] {selection}</div>') },
5006
5206
  { key: 'quote', label: '❝', title: t('md.quote'), run: () => exec('formatBlock', '<blockquote>') },
5007
- { key: 'link', label: '🔗', title: t('md.link'), run: () => {
5008
- let href = 'https://'
5009
- try {
5010
- href = window.prompt(t('md.linkPrompt'), 'https://') || ''
5011
- } catch {
5012
- href = ''
5013
- }
5014
- if (href) exec('createLink', href)
5015
- } },
5207
+ { key: 'link', label: '🔗', title: t('md.link'), run: () => setLinkEditor({ href: 'https://' }) },
5016
5208
  { key: 'hr', label: '—', title: t('md.hr'), run: () => exec('insertHorizontalRule') },
5017
5209
  ]
5018
5210
  const sourceTools = [
@@ -5100,6 +5292,32 @@ window.__ModuleLoader__.load({
5100
5292
  }),
5101
5293
  ),
5102
5294
  ),
5295
+ linkEditor
5296
+ ? h(
5297
+ 'div',
5298
+ { className: 'tb-md-linkbar' },
5299
+ h('span', { className: 'tb-md-color-label' }, t('md.linkPrompt')),
5300
+ h('input', {
5301
+ className: 'tb-md-link-input',
5302
+ value: linkEditor.href ?? '',
5303
+ autoFocus: true,
5304
+ placeholder: 'https://',
5305
+ onChange: (event) => setLinkEditor({ href: event.target.value }),
5306
+ onKeyDown: (event) => {
5307
+ if (event.nativeEvent?.isComposing) return
5308
+ if (event.key === 'Enter') {
5309
+ event.preventDefault()
5310
+ submitLink()
5311
+ } else if (event.key === 'Escape') {
5312
+ event.preventDefault()
5313
+ setLinkEditor(null)
5314
+ }
5315
+ },
5316
+ }),
5317
+ h('button', { type: 'button', className: 'tb-btn', onClick: () => setLinkEditor(null) }, t('panel.cancel')),
5318
+ h('button', { type: 'button', className: 'tb-btn primary', onClick: submitLink }, t('panel.confirm')),
5319
+ )
5320
+ : null,
5103
5321
  h('div', { className: 'tb-ws-hint', style: { fontSize: '10.5px' } }, t('md.hint')),
5104
5322
  h(
5105
5323
  'div',
@@ -5243,6 +5461,7 @@ window.__ModuleLoader__.load({
5243
5461
  const [textEditor, setTextEditor] = React.useState(null)
5244
5462
  const [windowEditor, setWindowEditor] = React.useState(null)
5245
5463
  const [insertMenu, setInsertMenu] = React.useState(false)
5464
+ const [clearMenu, setClearMenu] = React.useState(false)
5246
5465
  const [notice, setNotice] = React.useState(null)
5247
5466
  const [linkPreview, setLinkPreview] = React.useState(null)
5248
5467
  const [zoom, setZoom] = React.useState(1)
@@ -5514,7 +5733,21 @@ window.__ModuleLoader__.load({
5514
5733
  const entries = state.board?.entries ?? []
5515
5734
  const sortedEntries = [...entries].sort((left, right) => (right.updatedAt ?? 0) - (left.updatedAt ?? 0))
5516
5735
  const boardVersion = state.board?.version ?? 0
5517
- const layoutFor = (entry, index) => canvas.notes[entry.id] ?? autoBoardLayout(index)
5736
+ const withDocLayout = (entry, base) => {
5737
+ if (entry?.kind !== 'doc' || base?.kind === 'doc') return base
5738
+ return {
5739
+ ...base,
5740
+ kind: 'doc',
5741
+ width: Math.max(560, Number(base.width) || 0),
5742
+ height: Math.max(420, Number(base.height) || 0),
5743
+ }
5744
+ }
5745
+ const layoutFor = (entry, index) => withDocLayout(entry, canvas.notes[entry.id] ?? autoBoardLayout(index))
5746
+ const layoutForNote = (noteId) => {
5747
+ const entry = entries.find((candidate) => candidate.id === noteId)
5748
+ const index = Math.max(0, entries.findIndex((candidate) => candidate.id === noteId))
5749
+ return withDocLayout(entry, canvasRef.current.notes[noteId] ?? autoBoardLayout(index))
5750
+ }
5518
5751
  const noteSize = (layout) => {
5519
5752
  const doc = layout?.kind === 'doc'
5520
5753
  return {
@@ -5666,17 +5899,18 @@ window.__ModuleLoader__.load({
5666
5899
 
5667
5900
  const startAddText = () => {
5668
5901
  const [cx, cy] = viewportStageCenter()
5669
- setTextEditor({ id: '', text: '', color: '#e6e6e6', fontSize: 18, x: Math.max(0, cx - 160), y: Math.max(0, cy - 24), width: 320 })
5902
+ setTextEditor({ id: '', text: '', color: '#e6e6e6', fontSize: 18, x: Math.max(0, cx - 160), y: Math.max(0, cy - 24), width: 320, busy: false, error: null })
5670
5903
  }
5671
5904
 
5672
5905
  const startEditText = (item) => {
5673
5906
  if (!item) return
5674
- setTextEditor({ ...item })
5907
+ setTextEditor({ ...item, busy: false, error: null })
5675
5908
  }
5676
5909
 
5677
5910
  const saveText = async () => {
5678
5911
  const editor = textEditor
5679
- if (!editor) return
5912
+ if (!editor || editor.busy) return
5913
+ setTextEditor((current) => (current ? { ...current, busy: true, error: null } : current))
5680
5914
  const text = String(editor.text ?? '').trim()
5681
5915
  if (text === '') {
5682
5916
  if (editor.id) await deleteText(editor.id)
@@ -5699,13 +5933,24 @@ window.__ModuleLoader__.load({
5699
5933
  try {
5700
5934
  await saveCanvasNow(next)
5701
5935
  } catch (error) {
5702
- setTextEditor({ ...editor, error: error?.message || String(error) })
5936
+ setTextEditor({ ...editor, busy: false, error: error?.message || String(error) })
5703
5937
  return
5704
5938
  }
5705
5939
  setSelected(id)
5706
5940
  setTextEditor(null)
5707
5941
  }
5708
5942
 
5943
+ /** Outside-click close for the text editor: save non-empty text like stickies. */
5944
+ const dismissTextSaving = () => {
5945
+ const editor = textEditor
5946
+ if (!editor || editor.busy) return
5947
+ if (String(editor.text ?? '').trim() === '') {
5948
+ setTextEditor(null)
5949
+ return
5950
+ }
5951
+ saveText()
5952
+ }
5953
+
5709
5954
  const deleteText = async (id) => {
5710
5955
  if (!id) return
5711
5956
  const next = cloneBoardCanvas(canvasRef.current)
@@ -5745,12 +5990,25 @@ window.__ModuleLoader__.load({
5745
5990
  const input = document.createElement('input')
5746
5991
  input.type = 'file'
5747
5992
  input.accept = accept
5748
- input.style.display = 'none'
5993
+ input.style.position = 'fixed'
5994
+ input.style.left = '-10000px'
5995
+ input.style.top = '0'
5996
+ input.style.opacity = '0'
5997
+ input.style.pointerEvents = 'none'
5998
+ // Some desktop WebViews only open the picker for an input attached to
5999
+ // the document, unlike Chromium's detached-input path.
6000
+ document.body.appendChild(input)
6001
+ const cleanup = () => input.remove()
5749
6002
  input.addEventListener('change', () => {
5750
6003
  const file = input.files?.[0]
5751
6004
  if (file) onFile(file)
6005
+ cleanup()
5752
6006
  })
6007
+ input.addEventListener('cancel', cleanup)
5753
6008
  input.click()
6009
+ window.setTimeout(() => {
6010
+ if (input.isConnected) cleanup()
6011
+ }, 60_000)
5754
6012
  } catch (error) {
5755
6013
  setState((previous) => ({ ...previous, error: error?.message || String(error) }))
5756
6014
  }
@@ -5760,7 +6018,7 @@ window.__ModuleLoader__.load({
5760
6018
  setInsertMenu(false)
5761
6019
  pickFile('.csv,.tsv,.txt,.md,text/csv,text/tab-separated-values,text/plain,text/markdown', (file) => {
5762
6020
  if (file.size > 2_000_000) {
5763
- setState((previous) => ({ ...previous, error: '表格文件过大' }))
6021
+ setState((previous) => ({ ...previous, error: t('board.tableTooLarge') }))
5764
6022
  return
5765
6023
  }
5766
6024
  const reader = new FileReader()
@@ -5780,7 +6038,7 @@ window.__ModuleLoader__.load({
5780
6038
  error: null,
5781
6039
  })
5782
6040
  }
5783
- reader.onerror = () => setState((previous) => ({ ...previous, error: '表格读取失败' }))
6041
+ reader.onerror = () => setState((previous) => ({ ...previous, error: t('board.tableReadFailed') }))
5784
6042
  reader.readAsText(file)
5785
6043
  })
5786
6044
  }
@@ -5788,12 +6046,12 @@ window.__ModuleLoader__.load({
5788
6046
  const startImportImage = () => {
5789
6047
  setInsertMenu(false)
5790
6048
  pickFile('image/*', (file) => {
5791
- if (!/^image\//i.test(file.type)) {
5792
- setState((previous) => ({ ...previous, error: '请选择图片文件' }))
6049
+ if (!/^image\//i.test(file.type) && !/\.(png|jpe?g|gif|webp|bmp|svg|avif)$/i.test(file.name)) {
6050
+ setState((previous) => ({ ...previous, error: t('board.imageType') }))
5793
6051
  return
5794
6052
  }
5795
6053
  if (file.size > 1_500_000) {
5796
- setState((previous) => ({ ...previous, error: '图片过大(上限约 1.5MB)' }))
6054
+ setState((previous) => ({ ...previous, error: t('board.imageTooLarge') }))
5797
6055
  return
5798
6056
  }
5799
6057
  const reader = new FileReader()
@@ -5813,7 +6071,7 @@ window.__ModuleLoader__.load({
5813
6071
  error: null,
5814
6072
  })
5815
6073
  }
5816
- reader.onerror = () => setState((previous) => ({ ...previous, error: '图片读取失败' }))
6074
+ reader.onerror = () => setState((previous) => ({ ...previous, error: t('board.imageReadFailed') }))
5817
6075
  reader.readAsDataURL(file)
5818
6076
  })
5819
6077
  }
@@ -5830,10 +6088,11 @@ window.__ModuleLoader__.load({
5830
6088
 
5831
6089
  const saveWindow = async () => {
5832
6090
  const editor = windowEditor
5833
- if (!editor) return
6091
+ if (!editor || editor.busy) return
6092
+ setWindowEditor((current) => (current ? { ...current, busy: true, error: null } : current))
5834
6093
  const title = String(editor.title ?? '').trim() || (editor.kind === 'table' ? '表格' : '图片')
5835
6094
  if (editor.kind === 'image' && !editor.src) {
5836
- setWindowEditor({ ...editor, error: '请先选择图片' })
6095
+ setWindowEditor({ ...editor, busy: false, error: '请先选择图片' })
5837
6096
  return
5838
6097
  }
5839
6098
  let rows = editor.rows
@@ -5866,6 +6125,17 @@ window.__ModuleLoader__.load({
5866
6125
  setWindowEditor(null)
5867
6126
  }
5868
6127
 
6128
+ /** Outside-click close for the window editor: save valid content. */
6129
+ const dismissWindowSaving = () => {
6130
+ const editor = windowEditor
6131
+ if (!editor || editor.busy) return
6132
+ if (editor.kind === 'image' && !editor.src) {
6133
+ setWindowEditor(null)
6134
+ return
6135
+ }
6136
+ saveWindow()
6137
+ }
6138
+
5869
6139
  const deleteWindow = async (id) => {
5870
6140
  if (!id) return
5871
6141
  const next = cloneBoardCanvas(canvasRef.current)
@@ -6035,14 +6305,12 @@ window.__ModuleLoader__.load({
6035
6305
  }
6036
6306
  if (current.type === 'resize') {
6037
6307
  const scale = zoomScale()
6038
- const currentLayout = canvasRef.current.notes[current.noteId] ?? autoBoardLayout(0)
6308
+ const currentLayout = layoutForNote(current.noteId)
6039
6309
  const doc = currentLayout.kind === 'doc'
6040
6310
  const width = Math.min(doc ? 1200 : 640, Math.max(doc ? 320 : 160, Math.round(current.startW + (event.clientX - current.startX) / scale)))
6041
6311
  const height = Math.min(doc ? 900 : 560, Math.max(doc ? 200 : 120, Math.round(current.startH + (event.clientY - current.startY) / scale)))
6042
6312
  const next = cloneBoardCanvas(canvasRef.current)
6043
- const layout = next.notes[current.noteId] ?? autoBoardLayout(0)
6044
- layout.width = width
6045
- layout.height = height
6313
+ const layout = { ...currentLayout, width, height }
6046
6314
  next.notes[current.noteId] = layout
6047
6315
  canvasRef.current = next
6048
6316
  setCanvas(next)
@@ -6177,11 +6445,30 @@ window.__ModuleLoader__.load({
6177
6445
  stroke.points[1] = point
6178
6446
  }
6179
6447
  } else {
6180
- const last = stroke.points[stroke.points.length - 1]
6181
- if (last && Math.abs(last[0] - point[0]) + Math.abs(last[1] - point[1]) < 2) return
6182
- if (stroke.points.length >= 800) return
6183
- stroke.points.push(point)
6448
+ // Use every coalesced pointer sample and render at most once per
6449
+ // animation frame. Cloning the whole board on every pointermove
6450
+ // made fast strokes visibly chunky.
6451
+ const scale = zoomScale()
6452
+ const samples =
6453
+ typeof event.getCoalescedEvents === 'function' ? event.getCoalescedEvents() : [event]
6454
+ for (const sample of samples.length > 0 ? samples : [event]) {
6455
+ if (stroke.points.length >= 800) break
6456
+ const samplePoint = [
6457
+ Math.round((sample.clientX - current.rect.left) / scale),
6458
+ Math.round((sample.clientY - current.rect.top) / scale),
6459
+ ]
6460
+ const last = stroke.points[stroke.points.length - 1]
6461
+ if (last && last[0] === samplePoint[0] && last[1] === samplePoint[1]) continue
6462
+ stroke.points.push(samplePoint)
6463
+ }
6184
6464
  current.lastWorld = [event.clientX, event.clientY]
6465
+ if (!current.renderFrame) {
6466
+ current.renderFrame = window.requestAnimationFrame(() => {
6467
+ current.renderFrame = 0
6468
+ setCanvas({ ...canvasRef.current })
6469
+ })
6470
+ }
6471
+ return
6185
6472
  }
6186
6473
  const next = cloneBoardCanvas(canvasRef.current)
6187
6474
  if (current.layer === 'background') {
@@ -6204,6 +6491,10 @@ window.__ModuleLoader__.load({
6204
6491
  window.removeEventListener('pointercancel', finish)
6205
6492
  const current = gestureRef.current
6206
6493
  gestureRef.current = null
6494
+ if (current && current.renderFrame) {
6495
+ window.cancelAnimationFrame(current.renderFrame)
6496
+ current.renderFrame = 0
6497
+ }
6207
6498
  if (current && current.type === 'link') {
6208
6499
  setLinkPreview(null)
6209
6500
  const under = event ? layerAt(event) : null
@@ -6242,6 +6533,9 @@ window.__ModuleLoader__.load({
6242
6533
 
6243
6534
  const beginPointer = (event) => {
6244
6535
  if (event.button !== 0) return
6536
+ if (insertMenu) setInsertMenu(false)
6537
+ if (clearMenu) setClearMenu(false)
6538
+ if (shapeMenu) setShapeMenu(false)
6245
6539
  if (event.target?.closest?.('button') || event.target?.closest?.('.tb-sticky-linkline') || event.target?.closest?.('.tb-sticky-actions')) return
6246
6540
  const stage = stageRef.current
6247
6541
  if (!stage) return
@@ -6304,7 +6598,7 @@ window.__ModuleLoader__.load({
6304
6598
  event.preventDefault()
6305
6599
  if (!noteId) return
6306
6600
  const localPoint = stagePoint(event)
6307
- const layout = canvasRef.current.notes[noteId] ?? autoBoardLayout(0)
6601
+ const layout = layoutForNote(noteId)
6308
6602
  const anchorElement = event.target?.closest?.('.tb-anchor')
6309
6603
  const anchor = anchorElement?.getAttribute?.('data-anchor') || nearestBoardAnchor(layout, localPoint)
6310
6604
  setLinkPreview({ fromNoteId: noteId, fromAnchor: anchor, pointer: localPoint, targetNoteId: '', targetAnchor: '' })
@@ -6315,7 +6609,7 @@ window.__ModuleLoader__.load({
6315
6609
  event.preventDefault()
6316
6610
  event.stopPropagation()
6317
6611
  setSelected(noteId)
6318
- const layout = canvasRef.current.notes[noteId] ?? autoBoardLayout(0)
6612
+ const layout = layoutForNote(noteId)
6319
6613
  const size = noteSize(layout)
6320
6614
  setGesture({
6321
6615
  type: 'resize',
@@ -6343,7 +6637,7 @@ window.__ModuleLoader__.load({
6343
6637
  }
6344
6638
  event.preventDefault()
6345
6639
  setSelected(noteId)
6346
- const layout = canvasRef.current.notes[noteId] ?? autoBoardLayout(0)
6640
+ const layout = layoutForNote(noteId)
6347
6641
  setGesture({
6348
6642
  type: 'drag',
6349
6643
  noteId,
@@ -6701,7 +6995,10 @@ window.__ModuleLoader__.load({
6701
6995
  type: 'button',
6702
6996
  className: `tb-tool${insertMenu ? ' on' : ''}`,
6703
6997
  title: t('board.insertHint'),
6704
- onClick: () => setInsertMenu((value) => !value),
6998
+ onClick: () => {
6999
+ setClearMenu(false)
7000
+ setInsertMenu((value) => !value)
7001
+ },
6705
7002
  },
6706
7003
  `+ ${t('board.insert')}`,
6707
7004
  ),
@@ -6861,9 +7158,59 @@ window.__ModuleLoader__.load({
6861
7158
  ),
6862
7159
  h('span', { style: { flex: 1 } }),
6863
7160
  h('button', { type: 'button', className: 'tb-btn', onClick: autoFit }, t('board.center')),
6864
- h('button', { type: 'button', className: 'tb-btn', disabled: canvas.background.length === 0, onClick: clearBackground }, t('board.clearBg')),
6865
- h('button', { type: 'button', className: 'tb-btn', disabled: (canvas.edges ?? []).length === 0, onClick: () => { const next = cloneBoardCanvas(canvasRef.current); next.edges = []; saveCanvasSoon(next) } }, t('board.clearEdges')),
6866
- h('button', { type: 'button', className: 'tb-btn', disabled: !selected || !(canvas.drawings[selected]?.length > 0), onClick: clearSelectedDrawing }, t('board.clearNote')),
7161
+ h(
7162
+ 'div',
7163
+ { className: 'tb-window-insert' },
7164
+ h(
7165
+ 'button',
7166
+ {
7167
+ type: 'button',
7168
+ className: `tb-btn${clearMenu ? ' on' : ''}`,
7169
+ title: t('board.clearHint'),
7170
+ onClick: () => {
7171
+ setInsertMenu(false)
7172
+ setClearMenu((value) => !value)
7173
+ },
7174
+ },
7175
+ `🧹 ${t('board.clear')}`,
7176
+ ),
7177
+ clearMenu
7178
+ ? h(
7179
+ 'div',
7180
+ { className: 'tb-shape-menu tb-clear-menu', role: 'menu' },
7181
+ h(
7182
+ 'button',
7183
+ { type: 'button', role: 'menuitem', disabled: canvas.background.length === 0, onClick: () => { setClearMenu(false); clearBackground() } },
7184
+ t('board.clearBg'),
7185
+ ),
7186
+ h(
7187
+ 'button',
7188
+ {
7189
+ type: 'button',
7190
+ role: 'menuitem',
7191
+ disabled: (canvas.edges ?? []).length === 0,
7192
+ onClick: () => {
7193
+ setClearMenu(false)
7194
+ const next = cloneBoardCanvas(canvasRef.current)
7195
+ next.edges = []
7196
+ saveCanvasSoon(next)
7197
+ },
7198
+ },
7199
+ t('board.clearEdges'),
7200
+ ),
7201
+ h(
7202
+ 'button',
7203
+ {
7204
+ type: 'button',
7205
+ role: 'menuitem',
7206
+ disabled: !selected || !(canvas.drawings[selected]?.length > 0),
7207
+ onClick: () => { setClearMenu(false); clearSelectedDrawing() },
7208
+ },
7209
+ t('board.clearNote'),
7210
+ ),
7211
+ )
7212
+ : null,
7213
+ ),
6867
7214
  )
6868
7215
 
6869
7216
  return h(
@@ -6876,7 +7223,6 @@ window.__ModuleLoader__.load({
6876
7223
  h('span', { className: 'tb-board-sub' }, t('board.subtitle')),
6877
7224
  h('span', { style: { flex: 1 } }),
6878
7225
  h('span', { className: 'tb-muted tb-small' }, format(t('board.count'), { count: entries.length, version: boardVersion })),
6879
- h('span', { className: 'tb-muted tb-small' }, format(t('board.canvasVersion'), { version: boardVersion })),
6880
7226
  h('button', { type: 'button', className: 'tb-tool', title: t('board.zoomOut'), onClick: () => zoomBy(1 / 1.2) }, '−'),
6881
7227
  h('button', { type: 'button', className: 'tb-tool', title: t('board.zoomReset'), onClick: () => zoomBy(1 / zoomRef.current) }, `${Math.round(zoom * 100)}%`),
6882
7228
  h('button', { type: 'button', className: 'tb-tool', title: t('board.zoomIn'), onClick: () => zoomBy(1.2) }, '+'),
@@ -7202,7 +7548,7 @@ window.__ModuleLoader__.load({
7202
7548
  textEditor
7203
7549
  ? h(
7204
7550
  'div',
7205
- { className: 'tb-overlay center', onClick: () => setTextEditor(null) },
7551
+ { className: 'tb-overlay center', onClick: dismissTextSaving },
7206
7552
  h(
7207
7553
  'div',
7208
7554
  {
@@ -7285,8 +7631,8 @@ window.__ModuleLoader__.load({
7285
7631
  h(
7286
7632
  'div',
7287
7633
  { className: 'tb-note-actions' },
7288
- h('button', { type: 'button', className: 'tb-btn', onClick: () => setTextEditor(null) }, t('board.cancel')),
7289
- h('button', { type: 'button', className: 'tb-btn primary', onClick: saveText }, t('board.save')),
7634
+ h('button', { type: 'button', className: 'tb-btn', disabled: textEditor.busy === true, onClick: () => setTextEditor(null) }, t('board.cancel')),
7635
+ h('button', { type: 'button', className: 'tb-btn primary', disabled: textEditor.busy === true, onClick: saveText }, t('board.save')),
7290
7636
  ),
7291
7637
  ),
7292
7638
  )
@@ -7294,7 +7640,7 @@ window.__ModuleLoader__.load({
7294
7640
  windowEditor
7295
7641
  ? h(
7296
7642
  'div',
7297
- { className: 'tb-overlay center', onClick: () => setWindowEditor(null) },
7643
+ { className: 'tb-overlay center', onClick: dismissWindowSaving },
7298
7644
  h(
7299
7645
  'div',
7300
7646
  {
@@ -7376,12 +7722,12 @@ window.__ModuleLoader__.load({
7376
7722
  }
7377
7723
  pickFile('.csv,.tsv,.txt,.md,text/csv,text/tab-separated-values,text/plain,text/markdown', (file) => {
7378
7724
  if (file.size > 2_000_000) {
7379
- setWindowEditor((current) => (current ? { ...current, error: '表格文件过大' } : current))
7725
+ setWindowEditor((current) => (current ? { ...current, error: t('board.tableTooLarge') } : current))
7380
7726
  return
7381
7727
  }
7382
7728
  const reader = new FileReader()
7383
7729
  reader.onload = () => applyRows(String(reader.result ?? ''), file.name)
7384
- reader.onerror = () => setWindowEditor((current) => (current ? { ...current, error: '表格读取失败' } : current))
7730
+ reader.onerror = () => setWindowEditor((current) => (current ? { ...current, error: t('board.tableReadFailed') } : current))
7385
7731
  reader.readAsText(file)
7386
7732
  })
7387
7733
  },
@@ -7426,8 +7772,11 @@ window.__ModuleLoader__.load({
7426
7772
  className: 'tb-btn',
7427
7773
  onClick: () => {
7428
7774
  pickFile('image/*', (file) => {
7429
- if (!/^image\//i.test(file.type) || file.size > 1_500_000) {
7430
- setWindowEditor((current) => (current ? { ...current, error: '请选择 1.5MB 以内的图片' } : current))
7775
+ const imageType = /^image\//i.test(file.type) || /\.(png|jpe?g|gif|webp|bmp|svg|avif)$/i.test(file.name)
7776
+ if (!imageType || file.size > 1_500_000) {
7777
+ setWindowEditor((current) =>
7778
+ current ? { ...current, error: imageType ? t('board.imageTooLarge') : t('board.imageType') } : current,
7779
+ )
7431
7780
  return
7432
7781
  }
7433
7782
  const reader = new FileReader()
@@ -7435,7 +7784,7 @@ window.__ModuleLoader__.load({
7435
7784
  setWindowEditor((current) =>
7436
7785
  current ? { ...current, src: String(reader.result ?? ''), alt: file.name } : current,
7437
7786
  )
7438
- reader.onerror = () => setWindowEditor((current) => (current ? { ...current, error: '图片读取失败' } : current))
7787
+ reader.onerror = () => setWindowEditor((current) => (current ? { ...current, error: t('board.imageReadFailed') } : current))
7439
7788
  reader.readAsDataURL(file)
7440
7789
  })
7441
7790
  },
@@ -7448,8 +7797,8 @@ window.__ModuleLoader__.load({
7448
7797
  h(
7449
7798
  'div',
7450
7799
  { className: 'tb-note-actions' },
7451
- h('button', { type: 'button', className: 'tb-btn', onClick: () => setWindowEditor(null) }, t('board.cancel')),
7452
- h('button', { type: 'button', className: 'tb-btn primary', onClick: saveWindow }, t('board.save')),
7800
+ h('button', { type: 'button', className: 'tb-btn', disabled: windowEditor.busy === true, onClick: () => setWindowEditor(null) }, t('board.cancel')),
7801
+ h('button', { type: 'button', className: 'tb-btn primary', disabled: windowEditor.busy === true, onClick: saveWindow }, t('board.save')),
7453
7802
  ),
7454
7803
  ),
7455
7804
  )
@@ -7464,6 +7813,7 @@ window.__ModuleLoader__.load({
7464
7813
  window.__TIMEBACK_TEST__.renderMarkdown = renderMarkdown
7465
7814
  window.__TIMEBACK_TEST__.stripMarkdown = stripMarkdown
7466
7815
  window.__TIMEBACK_TEST__.boardEdgePath = boardEdgePath
7816
+ window.__TIMEBACK_TEST__.smoothStrokePath = smoothStrokePath
7467
7817
  window.__TIMEBACK_TEST__.MarkdownEditor = MarkdownEditor
7468
7818
  window.__TIMEBACK_TEST__.WorkspacePathSelector = WorkspacePathSelector
7469
7819
  window.__TIMEBACK_TEST__.markdownToEditorHtml = markdownToEditorHtml
package/docs/MARKET.md CHANGED
@@ -78,12 +78,12 @@ dshmarket;要让所有人的 dshmarket 搜到,必须走下一节的公共目
78
78
 
79
79
  ## 4. npm(已发布 0.6.0)
80
80
 
81
- `dsh-timeback@0.7.8` 已发布到官方 npm(<https://www.npmjs.com/package/dsh-timeback>),
81
+ `dsh-timeback@0.7.9` 已发布到官方 npm(<https://www.npmjs.com/package/dsh-timeback>),
82
82
  用户可以直接安装/固定版本:
83
83
 
84
84
  ```bash
85
85
  dsh plugin --profile web add dsh-timeback
86
- dsh plugin --profile web add dsh-timeback@0.7.8
86
+ dsh plugin --profile web add dsh-timeback@0.7.9
87
87
  ```
88
88
 
89
89
  awesome 目录 CI 会从 npm 自动补充映射,之后市场安装和更新会走 registry。发布流程参考:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-timeback",
3
- "version": "0.7.8",
3
+ "version": "0.7.9",
4
4
  "description": "Conversation tree with per-turn workspace snapshots for DeepSeek Harness: branch at any checkpoint and restore the files that turn had.",
5
5
  "type": "module",
6
6
  "license": "MIT",