dsh-timeback 0.7.6 → 0.7.8
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 +22 -2
- package/client.js +1724 -122
- package/docs/MARKET.md +2 -2
- package/index.js +16 -2
- package/package.json +1 -1
- package/src/notes.js +59 -4
- package/src/registry.js +40 -0
- package/src/service.js +35 -4
package/client.js
CHANGED
|
@@ -23,12 +23,13 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
const REFRESH_MS = 3000
|
|
24
24
|
const MAX_ROWS = 240
|
|
25
25
|
/** Bump together with package.json so a stale browser bundle is obvious. */
|
|
26
|
-
const BUILD = '0.7.
|
|
26
|
+
const BUILD = '0.7.8+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. */
|
|
30
30
|
let openPanelBridge = null
|
|
31
31
|
let openBoardBridge = null
|
|
32
|
+
let sessionApi = null
|
|
32
33
|
|
|
33
34
|
const DICT = {
|
|
34
35
|
zh: {
|
|
@@ -60,6 +61,7 @@ window.__ModuleLoader__.load({
|
|
|
60
61
|
'panel.warning': '回退会按快照覆盖工作区文件,并删除快照之后新增的文件;回退前会自动保存安全快照。',
|
|
61
62
|
'panel.confirmRewind': '将创建新分支并恢复工作区到:{who}\n\n{warning}\n\n确定继续?',
|
|
62
63
|
'panel.confirmFiles': '将把工作区文件恢复为:{who}\n\n{warning}\n\n确定继续?',
|
|
64
|
+
'panel.branchNamePrompt': '输入新分支会话的名称:',
|
|
63
65
|
'panel.confirmBranchOnly': '将在该检查点创建新分支,不修改工作区文件:{who}\n\n确定继续?',
|
|
64
66
|
'panel.confirmCheckpoint': '将记录当前对话位置与工作区快照。确定继续?',
|
|
65
67
|
'panel.deleteWarning': '快照之后新增的文件会被删除,之后修改的文件会被覆盖。回退前会自动保存安全快照,可用它撤销本次恢复。',
|
|
@@ -119,6 +121,28 @@ window.__ModuleLoader__.load({
|
|
|
119
121
|
'md.empty': '空文档,直接输入即可',
|
|
120
122
|
'md.hint': '直接打字即可:选中文字后点工具栏按钮会立即格式化(例如选中“你好”按 B 立即加粗);也可切换源码/预览。',
|
|
121
123
|
'board.newSticky': '新建便签',
|
|
124
|
+
'board.newDoc': '新建完整 md',
|
|
125
|
+
'board.addText': '文本',
|
|
126
|
+
'board.newText': '添加文本',
|
|
127
|
+
'board.editText': '编辑文本',
|
|
128
|
+
'board.textPlaceholder': '输入文本…',
|
|
129
|
+
'board.fontColor': '字体颜色',
|
|
130
|
+
'board.fontSize': '字号',
|
|
131
|
+
'board.deleteText': '删除文本',
|
|
132
|
+
'board.insert': '插入',
|
|
133
|
+
'board.insertHint': '添加表格、导入表格或导入图片窗口',
|
|
134
|
+
'board.table': '表格',
|
|
135
|
+
'board.importTable': '导入表格',
|
|
136
|
+
'board.importImage': '导入图片',
|
|
137
|
+
'board.tableHint': '窗口可拖动;右下角可缩放。表格内容每行一行、单元格用 Tab 分隔,也支持 CSV 和 Markdown 表格。',
|
|
138
|
+
'board.addRow': '加行',
|
|
139
|
+
'board.addCol': '加列',
|
|
140
|
+
'board.tableTitle': '表格标题',
|
|
141
|
+
'board.fromFile': '从文件导入',
|
|
142
|
+
'board.chooseImage': '选择图片',
|
|
143
|
+
'board.imageHint': '图片窗口可拖动,右下角可缩放;大小上限约 1.5MB。',
|
|
144
|
+
'board.windowTitle': '窗口标题',
|
|
145
|
+
'board.docHint': '完整 Markdown 文档页:默认展开预览,可拖动右下角调整大小。',
|
|
122
146
|
'board.stickyColor': '便签颜色',
|
|
123
147
|
'board.stickyHint': '便签可拖动;画笔可在方格纸背景或便签上绘制,橡皮擦除笔画。',
|
|
124
148
|
'board.resizeNote': '拖动缩放便签',
|
|
@@ -126,6 +150,7 @@ window.__ModuleLoader__.load({
|
|
|
126
150
|
'board.drawOnStickyOn': '便签可画:开',
|
|
127
151
|
'board.drawOnStickyOff': '便签可画:关',
|
|
128
152
|
'board.drawOnStickyHint': '开启后画笔/图形可直接画在便签上;关闭则只画在方格纸背景。',
|
|
153
|
+
'board.drawOnStickyNotice': '便签可画当前为关:先在工具栏打开「便签可画:开」才能在便签上绘制。',
|
|
129
154
|
'board.center': '自动调整',
|
|
130
155
|
'board.zoomIn': '放大画布',
|
|
131
156
|
'board.zoomOut': '缩小画布',
|
|
@@ -189,8 +214,8 @@ window.__ModuleLoader__.load({
|
|
|
189
214
|
'guide.boardTitle': '记录板',
|
|
190
215
|
'guide.boardDescription': '全局 Markdown 记录板:手动添加或让会话记录,回溯时一起回退。',
|
|
191
216
|
'panel.recording': '记录设置',
|
|
192
|
-
'panel.recordThis': '
|
|
193
|
-
'panel.recordThisHint': '
|
|
217
|
+
'panel.recordThis': '全选',
|
|
218
|
+
'panel.recordThisHint': '勾选“全选”记录整个工作区;取消下面文件夹/文件即可只记录选中的部分。',
|
|
194
219
|
'panel.recordOff': '未开启记录',
|
|
195
220
|
'panel.recordOn': '记录中',
|
|
196
221
|
'panel.recordAll': '插件配置 capture=all:所有工作区自动记录',
|
|
@@ -205,6 +230,9 @@ window.__ModuleLoader__.load({
|
|
|
205
230
|
'panel.workspaceDisabled': '已关闭此工作区的自动记录',
|
|
206
231
|
'panel.workspaceStillOn': '操作已提交,但该目录仍被其它记录设置覆盖;请在上方已开启列表里取消对应路径。',
|
|
207
232
|
'panel.selectAllHint': '只记录勾选的文件夹和文件',
|
|
233
|
+
'panel.workspaceSectionTitle': '工作区文件快照',
|
|
234
|
+
'panel.expandWorkspaceSection': '展开工作区记录设置',
|
|
235
|
+
'panel.collapseWorkspaceSection': '收起工作区记录设置',
|
|
208
236
|
'panel.expandFolder': '展开文件夹',
|
|
209
237
|
'panel.collapseFolder': '收起文件夹',
|
|
210
238
|
'panel.selectedCount': '已选择 {selected} / {total} 项(文件夹包含其内部文件)',
|
|
@@ -310,6 +338,7 @@ window.__ModuleLoader__.load({
|
|
|
310
338
|
'panel.warning': 'Rewinding overwrites workspace files from the snapshot and deletes files created after it. A safety snapshot is taken first.',
|
|
311
339
|
'panel.confirmRewind': 'Create a new branch and restore the workspace to: {who}\n\n{warning}\n\nContinue?',
|
|
312
340
|
'panel.confirmFiles': 'Restore workspace files to: {who}\n\n{warning}\n\nContinue?',
|
|
341
|
+
'panel.branchNamePrompt': 'Name for the new branch session:',
|
|
313
342
|
'panel.confirmBranchOnly': 'Create a new branch at this checkpoint without touching files: {who}\n\nContinue?',
|
|
314
343
|
'panel.confirmCheckpoint': 'Record the current conversation position and a workspace snapshot?',
|
|
315
344
|
'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.',
|
|
@@ -369,6 +398,28 @@ window.__ModuleLoader__.load({
|
|
|
369
398
|
'md.empty': 'Empty document — just start typing',
|
|
370
399
|
'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.',
|
|
371
400
|
'board.newSticky': 'New sticky',
|
|
401
|
+
'board.newDoc': 'New full MD',
|
|
402
|
+
'board.addText': 'Text',
|
|
403
|
+
'board.newText': 'Add text',
|
|
404
|
+
'board.editText': 'Edit text',
|
|
405
|
+
'board.textPlaceholder': 'Type text…',
|
|
406
|
+
'board.fontColor': 'Font colour',
|
|
407
|
+
'board.fontSize': 'Font size',
|
|
408
|
+
'board.deleteText': 'Delete text',
|
|
409
|
+
'board.insert': 'Insert',
|
|
410
|
+
'board.insertHint': 'Add a table, import a table, or import an image window',
|
|
411
|
+
'board.table': 'Table',
|
|
412
|
+
'board.importTable': 'Import table',
|
|
413
|
+
'board.importImage': 'Import image',
|
|
414
|
+
'board.tableHint': 'Windows can be dragged and resized from the bottom-right. Each table line is a row; separate cells with Tab. CSV and Markdown tables are accepted.',
|
|
415
|
+
'board.addRow': 'Add row',
|
|
416
|
+
'board.addCol': 'Add column',
|
|
417
|
+
'board.tableTitle': 'Table title',
|
|
418
|
+
'board.fromFile': 'Import from file',
|
|
419
|
+
'board.chooseImage': 'Choose image',
|
|
420
|
+
'board.imageHint': 'Image windows can be dragged and resized from the bottom-right; max about 1.5MB.',
|
|
421
|
+
'board.windowTitle': 'Window title',
|
|
422
|
+
'board.docHint': 'Full Markdown document page: expanded preview by default, resize from the bottom-right corner.',
|
|
372
423
|
'board.stickyColor': 'Sticky colour',
|
|
373
424
|
'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.',
|
|
374
425
|
'board.resizeNote': 'Drag to resize the sticky',
|
|
@@ -376,6 +427,7 @@ window.__ModuleLoader__.load({
|
|
|
376
427
|
'board.drawOnStickyOn': 'Sticky drawing: on',
|
|
377
428
|
'board.drawOnStickyOff': 'Sticky drawing: off',
|
|
378
429
|
'board.drawOnStickyHint': 'When on, pen/shape tools draw directly on sticky notes; when off they only draw on the grid.',
|
|
430
|
+
'board.drawOnStickyNotice': 'Sticky drawing is off: turn on “Sticky drawing: on” in the toolbar before drawing on a sticky.',
|
|
379
431
|
'board.center': 'Auto fit',
|
|
380
432
|
'board.zoomIn': 'Zoom in',
|
|
381
433
|
'board.zoomOut': 'Zoom out',
|
|
@@ -454,6 +506,9 @@ window.__ModuleLoader__.load({
|
|
|
454
506
|
'panel.workspaceEnabled': 'Recording enabled for this workspace',
|
|
455
507
|
'panel.workspaceDisabled': 'Recording disabled for this workspace',
|
|
456
508
|
'panel.selectAllHint': '只记录勾选的文件夹和文件',
|
|
509
|
+
'panel.workspaceSectionTitle': '工作区文件快照',
|
|
510
|
+
'panel.expandWorkspaceSection': '展开工作区记录设置',
|
|
511
|
+
'panel.collapseWorkspaceSection': '收起工作区记录设置',
|
|
457
512
|
'panel.expandFolder': '展开文件夹',
|
|
458
513
|
'panel.collapseFolder': '收起文件夹',
|
|
459
514
|
'panel.selectedCount': '已选择 {selected} / {total} 项(文件夹包含其内部文件)',
|
|
@@ -461,6 +516,9 @@ window.__ModuleLoader__.load({
|
|
|
461
516
|
'panel.pathsLoading': '正在读取工作区文件…',
|
|
462
517
|
'panel.pathsFailed': '读取工作区文件失败:{error}',
|
|
463
518
|
'panel.selectAllHint': 'Only selected folders/files are recorded',
|
|
519
|
+
'panel.workspaceSectionTitle': 'Workspace file snapshots',
|
|
520
|
+
'panel.expandWorkspaceSection': 'Expand workspace recording settings',
|
|
521
|
+
'panel.collapseWorkspaceSection': 'Collapse workspace recording settings',
|
|
464
522
|
'panel.expandFolder': 'Expand folder',
|
|
465
523
|
'panel.collapseFolder': 'Collapse folder',
|
|
466
524
|
'panel.selectedCount': '{selected} / {total} selected (a folder includes its contents)',
|
|
@@ -615,6 +673,8 @@ window.__ModuleLoader__.load({
|
|
|
615
673
|
.tb-canvas-btn.on{color:var(--dsw-alias-state-success-primary,#3ecf8e)}
|
|
616
674
|
.tb-canvas-btn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.1));color:var(--dsw-alias-label-primary,#e6e6e6)}
|
|
617
675
|
.tb-world{position:absolute;left:0;top:0;transform-origin:0 0}
|
|
676
|
+
.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}
|
|
618
678
|
.tb-world-links{position:absolute;left:0;top:0;pointer-events:none;overflow:visible}
|
|
619
679
|
.tb-link{fill:none;stroke-width:1.6;opacity:.55}
|
|
620
680
|
.tb-link.fork{stroke-width:2;opacity:.75}
|
|
@@ -662,6 +722,10 @@ window.__ModuleLoader__.load({
|
|
|
662
722
|
.tb-folder-row:active{cursor:grabbing}
|
|
663
723
|
.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
724
|
.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}
|
|
725
|
+
.tb-folder-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:700}
|
|
726
|
+
.tb-folder-name-input{flex:1;min-width:0;box-sizing:border-box;background:var(--dsw-alias-bg-base,#16181d);color:var(--dsw-alias-label-primary,#e6e6e6);border:1px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);border-radius:4px;padding:1px 5px;font:inherit;outline:none}
|
|
727
|
+
.tb-folder-rename{appearance:none;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:transparent;color:var(--dsw-alias-label-secondary,#9aa0a6);border-radius:4px;padding:0 5px;line-height:15px;font-size:10px;cursor:pointer;flex:0 0 auto}
|
|
728
|
+
.tb-folder-rename:hover{color:var(--dsw-alias-label-primary,#e6e6e6);border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
|
|
665
729
|
.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
730
|
.tb-folder-ghost-label{font-weight:700;color:var(--dsw-alias-label-primary,#e6e6e6);white-space:nowrap}
|
|
667
731
|
.tb-folder-ghost-prompt{color:var(--dsw-alias-label-secondary,#9aa0a6);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
@@ -675,11 +739,23 @@ window.__ModuleLoader__.load({
|
|
|
675
739
|
.tb-card:active{cursor:grabbing}
|
|
676
740
|
.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}
|
|
677
741
|
.tb-card-prompt.withnote{-webkit-line-clamp:1;font-size:11px}
|
|
742
|
+
.tb-card-rewind{margin-left:auto;appearance:none;border:1px solid color-mix(in srgb, var(--tb-color,#4d7cfe) 55%, transparent);background:color-mix(in srgb, var(--tb-color,#4d7cfe) 14%, transparent);color:var(--tb-color,#4d7cfe);border-radius:4px;padding:0 5px;line-height:15px;font-size:10px;cursor:pointer;white-space:nowrap}
|
|
678
743
|
.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}
|
|
679
744
|
.tb-card-editnote:hover{color:var(--dsw-alias-label-primary,#e6e6e6)}
|
|
680
745
|
.tb-card-editnote.has{color:var(--tb-color,#4d7cfe);border-color:color-mix(in srgb, var(--tb-color,#4d7cfe) 50%, transparent)}
|
|
681
746
|
.tb-overlay{position:fixed;inset:0;z-index:60;background:rgba(0,0,0,.35);display:flex;justify-content:flex-end;align-items:stretch}
|
|
682
747
|
.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}
|
|
749
|
+
.tb-chat-messages{flex:1;min-height:0;overflow:auto;display:flex;flex-direction:column;gap:8px;padding:2px 2px 4px}
|
|
750
|
+
.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
|
+
.tb-chat-msg.user{background:rgba(77,124,254,.13);border-color:rgba(77,124,254,.4)}
|
|
752
|
+
.tb-chat-msg.assistant{background:rgba(62,207,142,.1);border-color:rgba(62,207,142,.3)}
|
|
753
|
+
.tb-chat-role{font-size:10px;font-weight:700;opacity:.65;margin-bottom:4px}
|
|
754
|
+
.tb-chat-text{white-space:pre-wrap;word-break:break-word;font-size:13px;line-height:1.55}
|
|
755
|
+
.tb-chat-composer{display:flex;flex-direction:column;gap:6px;border-top:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.1));padding-top:8px}
|
|
756
|
+
.tb-chat-composer textarea{box-sizing:border-box;width:100%;min-height:64px;max-height:180px;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:7px 8px;font:inherit;font-size:13px;line-height:1.5;outline:none}
|
|
757
|
+
.tb-chat-composer textarea:focus{border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff)}
|
|
758
|
+
.tb-chat-actions{display:flex;align-items:center;gap:8px}
|
|
683
759
|
.tb-note-dialog{width:min(520px,92vw);height:100%;background:var(--dsw-alias-bg-base,#16181d);border-left:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));padding:12px;display:flex;flex-direction:column;gap:8px;overflow:auto;box-shadow:-8px 0 24px rgba(0,0,0,.28)}
|
|
684
760
|
.tb-note-dialog textarea,.tb-board-dialog textarea,.tb-board-dialog input{width:100%;box-sizing:border-box;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.04));color:var(--dsw-alias-label-primary,#e6e6e6);border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));border-radius:7px;padding:7px 9px;font-size:12px;line-height:1.5;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;resize:vertical}
|
|
685
761
|
.tb-note-dialog textarea{min-height:180px}
|
|
@@ -693,6 +769,7 @@ window.__ModuleLoader__.load({
|
|
|
693
769
|
.tb-resize-handle.se{right:0;bottom:0;width:18px;height:18px;cursor:nwse-resize}
|
|
694
770
|
.tb-resize-handle.se:after{content:"";position:absolute;right:3px;bottom:3px;width:8px;height:8px;border-right:2px solid var(--dsw-alias-label-secondary,#9aa0a6);border-bottom:2px solid var(--dsw-alias-label-secondary,#9aa0a6);opacity:.55}
|
|
695
771
|
.tb-board-testid{display:none}
|
|
772
|
+
.tb-board-toast{position:absolute;top:88px;left:50%;transform:translateX(-50%);z-index:60;max-width:min(520px,86vw);padding:8px 14px;border-radius:999px;background:#f7f3e8;color:#3a3326;border:1px solid rgba(0,0,0,.12);box-shadow:0 8px 22px rgba(0,0,0,.28);font-size:12px;line-height:1.45;text-align:center;pointer-events:none}
|
|
696
773
|
.tb-board-toolbar{display:flex;align-items:center;gap:6px;flex-wrap:wrap;padding:6px 12px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.08))}
|
|
697
774
|
.tb-tool{appearance:none;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:transparent;color:var(--dsw-alias-label-secondary,#9aa0a6);border-radius:6px;padding:3px 8px;font-size:11.5px;cursor:pointer;line-height:1.4}
|
|
698
775
|
.tb-shape-wrap{position:relative;display:inline-flex}
|
|
@@ -731,6 +808,44 @@ window.__ModuleLoader__.load({
|
|
|
731
808
|
.tb-board-world{position:relative;flex:none;contain:layout paint}
|
|
732
809
|
.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}
|
|
733
810
|
.tb-board-bgdraw{position:absolute;left:0;top:0;pointer-events:none;overflow:visible}
|
|
811
|
+
.tb-window-insert{position:relative;display:inline-flex}
|
|
812
|
+
.tb-insert-menu{left:0;top:calc(100% + 4px);min-width:180px}
|
|
813
|
+
.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
|
+
.tb-board-window.selected{outline:2px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff);outline-offset:1px}
|
|
815
|
+
.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}
|
|
816
|
+
.tb-board-window-title{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px;font-weight:600}
|
|
817
|
+
.tb-board-window-actions{display:flex;gap:2px}
|
|
818
|
+
.tb-board-window-actions button{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-secondary,#c9ced6);border-radius:3px;font-size:10px;line-height:15px;padding:0 4px;cursor:pointer}
|
|
819
|
+
.tb-board-window-actions button:hover{background:rgba(255,255,255,.12);color:#fff}
|
|
820
|
+
.tb-board-window-body{flex:1;min-height:0;overflow:auto;position:relative}
|
|
821
|
+
.tb-board-window-body table{border-collapse:collapse;width:100%;background:rgba(255,255,255,.02);font-size:12px;color:var(--dsw-alias-label-primary,#e6e6e6)}
|
|
822
|
+
.tb-board-window-body th,.tb-board-window-body td{border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));padding:4px 6px;text-align:left;vertical-align:top;white-space:pre-wrap;word-break:break-word;min-width:48px}
|
|
823
|
+
.tb-board-window-body th{background:rgba(255,255,255,.07);font-weight:600;position:sticky;top:0;z-index:1}
|
|
824
|
+
.tb-board-window-body img{display:block;width:100%;height:100%;object-fit:contain;background:rgba(0,0,0,.14)}
|
|
825
|
+
.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
|
+
.tb-window-editor-dialog{width:min(760px,94vw);height:auto;max-height:92vh;display:flex;flex-direction:column;gap:8px}
|
|
827
|
+
.tb-window-editor-body{display:flex;flex-direction:column;gap:6px;min-height:0}
|
|
828
|
+
.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
|
+
.tb-table-editor-preview table{border-collapse:collapse;width:100%;font-size:12px}
|
|
830
|
+
.tb-table-editor-preview td{border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));padding:3px 5px;white-space:pre-wrap}
|
|
831
|
+
.tb-table-editor-preview img{display:block;max-width:100%;max-height:140px;object-fit:contain;margin:auto}
|
|
832
|
+
.tb-board-text{position:absolute;box-sizing:border-box;padding:5px 7px;border-radius:6px;line-height:1.45;white-space:pre-wrap;word-break:break-word;cursor:grab;user-select:none;border:1px solid transparent;text-shadow:0 1px 0 rgba(0,0,0,.12)}
|
|
833
|
+
.tb-board-text:hover{border-color:rgba(122,162,255,.5)}
|
|
834
|
+
.tb-board-text.selected{outline:2px dashed var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff);outline-offset:2px}
|
|
835
|
+
.tb-board-text:active{cursor:grabbing}
|
|
836
|
+
.tb-board-text-content{white-space:pre-wrap;word-break:break-word;pointer-events:none}
|
|
837
|
+
.tb-board-text-actions{position:absolute;right:-1px;top:-24px;display:none;gap:2px;padding:1px;border-radius:5px;background:var(--dsw-alias-bg-elevated,#2a2d34);border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));z-index:4}
|
|
838
|
+
.tb-board-text:hover .tb-board-text-actions,.tb-board-text.selected .tb-board-text-actions{display:flex}
|
|
839
|
+
.tb-board-text-actions button{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-secondary,#c9ced6);border-radius:3px;font-size:11px;line-height:16px;padding:0 4px;cursor:pointer}
|
|
840
|
+
.tb-board-text-actions button:hover{background:rgba(255,255,255,.12);color:#fff}
|
|
841
|
+
.tb-text-dialog{width:min(700px,94vw);height:auto;max-height:90vh;display:flex;flex-direction:column;gap:8px}
|
|
842
|
+
.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}
|
|
843
|
+
.tb-text-input:focus{border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff)}
|
|
844
|
+
.tb-text-row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
|
|
845
|
+
.tb-text-swatches{display:flex;gap:4px;flex-wrap:wrap}
|
|
846
|
+
.tb-text-swatch{width:24px;height:24px;border-radius:5px;border:2px solid transparent;box-shadow:inset 0 0 0 1px rgba(0,0,0,.2);cursor:pointer;padding:0}
|
|
847
|
+
.tb-text-swatch.on{border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff)}
|
|
848
|
+
.tb-text-preview{flex:1;min-height:64px;max-height:140px;overflow:auto;padding:8px;border:1px dashed var(--dsw-alias-border-l2,rgba(255,255,255,.2));border-radius:6px;background:var(--dsw-alias-bg-base,#16181d);white-space:pre-wrap;word-break:break-word}
|
|
734
849
|
.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}
|
|
735
850
|
.tb-sticky:active{cursor:grabbing}
|
|
736
851
|
.tb-sticky.selected{outline:2px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);outline-offset:1px}
|
|
@@ -754,6 +869,13 @@ window.__ModuleLoader__.load({
|
|
|
754
869
|
.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
870
|
.tb-sticky-md a{color:#1c4d8f;text-decoration:underline}
|
|
756
871
|
.tb-sticky-md hr{border:0;border-top:1px solid rgba(0,0,0,.2);margin:4px 0}
|
|
872
|
+
.tb-sticky.tb-doc{background:#ffffff;color:#2a2418;box-shadow:0 8px 24px rgba(0,0,0,.32);border-color:rgba(0,0,0,.22)}
|
|
873
|
+
.tb-sticky.tb-doc .tb-sticky-head{flex:0 0 auto;cursor:grab}
|
|
874
|
+
.tb-doc-body{flex:1;min-height:0;overflow:auto;pointer-events:auto;user-select:text;cursor:text;color:#2a2418;background:#ffffff;border-radius:0 0 4px 4px;padding:2px 2px 4px}
|
|
875
|
+
.tb-doc-body .tb-md{font-size:13px;line-height:1.6;color:#2a2418}
|
|
876
|
+
.tb-doc-body .tb-md h1{font-size:21px}.tb-doc-body .tb-md h2{font-size:18px}.tb-doc-body .tb-md h3{font-size:16px}.tb-doc-body .tb-md h4{font-size:14px}
|
|
877
|
+
.tb-doc-body .tb-md pre{background:rgba(0,0,0,.07);color:#2a2418}
|
|
878
|
+
.tb-doc-body .tb-md code{background:rgba(0,0,0,.08)}
|
|
757
879
|
.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}
|
|
758
880
|
.tb-sticky-src{font-size:9.5px;font-weight:600;opacity:.6;white-space:nowrap}
|
|
759
881
|
.tb-sticky-draw{position:absolute;inset:0;pointer-events:none;z-index:3}
|
|
@@ -810,7 +932,7 @@ window.__ModuleLoader__.load({
|
|
|
810
932
|
.tb-md-line{display:block;font-size:10px;line-height:1.4;color:var(--dsw-alias-label-tertiary,#8a919c);margin-bottom:1px}
|
|
811
933
|
.tb-md-empty{padding:12px;text-align:center;color:var(--dsw-alias-label-secondary,#9aa0a6);font-size:13px}
|
|
812
934
|
@media (max-width: 760px){.tb-md-body{flex-direction:column}}
|
|
813
|
-
.tb-board-panel{display:flex;flex-direction:column;height:100%;min-height:100%;width:100%;font-size:12.5px;color:var(--dsw-alias-label-primary,#e6e6e6);background:var(--dsw-alias-bg-base,#16181d)}
|
|
935
|
+
.tb-board-panel{position:relative;display:flex;flex-direction:column;height:100%;min-height:100%;width:100%;font-size:12.5px;color:var(--dsw-alias-label-primary,#e6e6e6);background:var(--dsw-alias-bg-base,#16181d)}
|
|
814
936
|
.tb-board-head{display:flex;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.1));flex-wrap:wrap}
|
|
815
937
|
.tb-board-title{font-weight:600;font-size:13.5px}
|
|
816
938
|
.tb-board-sub{font-size:11px;color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
@@ -961,7 +1083,7 @@ window.__ModuleLoader__.load({
|
|
|
961
1083
|
/** Parse inline Markdown (bold/italic/code/link) into React children. */
|
|
962
1084
|
function inlineMarkdown(text, keyPrefix) {
|
|
963
1085
|
const nodes = []
|
|
964
|
-
const pattern = /(<span style="color:\s
|
|
1086
|
+
const pattern = /(<span style="[^"]*color:\s*(?:#[0-9a-f]{3,8}|rgba?\([^)]*\))[^"]*">[\s\S]*?<\/span>|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|\*[^*\n]+\*|_[^\n_]+_)/gi
|
|
965
1087
|
let last = 0
|
|
966
1088
|
let match
|
|
967
1089
|
let index = 0
|
|
@@ -970,8 +1092,9 @@ window.__ModuleLoader__.load({
|
|
|
970
1092
|
const token = match[0]
|
|
971
1093
|
const key = `${keyPrefix}-i${index++}`
|
|
972
1094
|
if (token.startsWith('<span')) {
|
|
973
|
-
const match = /^<span style="color:\s*(
|
|
974
|
-
|
|
1095
|
+
const match = /^<span style="[^"]*color:\s*([^";]+)[^"]*">([\s\S]*?)<\/span>$/i.exec(token)
|
|
1096
|
+
const color = match ? normalizeCssColor(match[1]) : ''
|
|
1097
|
+
if (color) nodes.push(h('span', { key, style: { color } }, ...inlineMarkdown(match[2], `${keyPrefix}-c${index}`)))
|
|
975
1098
|
else nodes.push(token)
|
|
976
1099
|
} else if (token.startsWith('`')) nodes.push(h('code', { key }, token.slice(1, -1)))
|
|
977
1100
|
else if (token.startsWith('**') || token.startsWith('__')) nodes.push(h('strong', { key }, token.slice(2, -2)))
|
|
@@ -1233,6 +1356,19 @@ window.__ModuleLoader__.load({
|
|
|
1233
1356
|
return changed ? next : folders
|
|
1234
1357
|
}
|
|
1235
1358
|
|
|
1359
|
+
/** Rename one folder; empty names fall back to the default label. */
|
|
1360
|
+
function renameCardFolder(folders, folderId, name) {
|
|
1361
|
+
if (!Array.isArray(folders)) return folders
|
|
1362
|
+
const nextName = String(name ?? '').trim().slice(0, 40) || '卡片夹'
|
|
1363
|
+
let changed = false
|
|
1364
|
+
const next = folders.map((folder) => {
|
|
1365
|
+
if (folder.id !== folderId || folder.name === nextName) return folder
|
|
1366
|
+
changed = true
|
|
1367
|
+
return { ...folder, name: nextName }
|
|
1368
|
+
})
|
|
1369
|
+
return changed ? next : folders
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1236
1372
|
/** Unique keys in order. */
|
|
1237
1373
|
function uniqueKeys(values) {
|
|
1238
1374
|
const seen = new Set()
|
|
@@ -1262,6 +1398,7 @@ window.__ModuleLoader__.load({
|
|
|
1262
1398
|
let host = null
|
|
1263
1399
|
if (sourceFolder && targetFolder) {
|
|
1264
1400
|
targetFolder.members = uniqueKeys([...targetFolder.members, ...sourceFolder.members])
|
|
1401
|
+
if (!targetFolder.name || targetFolder.name === '卡片夹') targetFolder.name = sourceFolder.name || targetFolder.name
|
|
1265
1402
|
host = targetFolder
|
|
1266
1403
|
const index = list.indexOf(sourceFolder)
|
|
1267
1404
|
if (index !== -1) list.splice(index, 1)
|
|
@@ -1274,6 +1411,7 @@ window.__ModuleLoader__.load({
|
|
|
1274
1411
|
} else {
|
|
1275
1412
|
host = {
|
|
1276
1413
|
id: `fold-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
|
|
1414
|
+
name: '卡片夹',
|
|
1277
1415
|
members: uniqueKeys([target.key, source.key]),
|
|
1278
1416
|
x: Number.isFinite(target.x) ? target.x : 0,
|
|
1279
1417
|
y: Number.isFinite(target.y) ? target.y : 0,
|
|
@@ -1290,6 +1428,14 @@ window.__ModuleLoader__.load({
|
|
|
1290
1428
|
return next.length === folders.length && next.every((folder, index) => folder === folders[index]) ? folders : next
|
|
1291
1429
|
}
|
|
1292
1430
|
|
|
1431
|
+
/** A stable lane colour for one Session (order-independent). */
|
|
1432
|
+
function stableSessionColor(sessionId) {
|
|
1433
|
+
const value = String(sessionId ?? '')
|
|
1434
|
+
let hash = 0
|
|
1435
|
+
for (let index = 0; index < value.length; index += 1) hash = (hash * 31 + value.charCodeAt(index)) >>> 0
|
|
1436
|
+
return LANE_COLORS[hash % LANE_COLORS.length]
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1293
1439
|
/**
|
|
1294
1440
|
* Lay out branch cards left-to-right (turn chain) with one horizontal lane
|
|
1295
1441
|
* per branch Session, fork edges from the parent turn card to the child's
|
|
@@ -1329,7 +1475,7 @@ window.__ModuleLoader__.load({
|
|
|
1329
1475
|
}
|
|
1330
1476
|
for (const session of sessions) {
|
|
1331
1477
|
const lane = laneOf.get(session.sessionId) ?? 0
|
|
1332
|
-
const color =
|
|
1478
|
+
const color = stableSessionColor(session.sessionId)
|
|
1333
1479
|
const y = CANVAS_PAD + lane * (CARD_HEIGHT + CARD_GAP_Y)
|
|
1334
1480
|
const onPath = currentPath.has(session.sessionId)
|
|
1335
1481
|
const parent = session.parentSessionId ? byId.get(session.parentSessionId) : null
|
|
@@ -1467,10 +1613,13 @@ window.__ModuleLoader__.load({
|
|
|
1467
1613
|
})
|
|
1468
1614
|
for (const ordered of orderedCards) {
|
|
1469
1615
|
const card = ordered.card
|
|
1470
|
-
|
|
1616
|
+
const naturalX = x
|
|
1617
|
+
card.x = naturalX
|
|
1471
1618
|
card.y = y
|
|
1472
1619
|
pushCard(card)
|
|
1473
|
-
|
|
1620
|
+
// If the user dragged the previous card, keep the next new card after
|
|
1621
|
+
// where it actually is instead of the old automatic slot.
|
|
1622
|
+
x = Math.max(naturalX + CARD_WIDTH + CARD_GAP_X, card.x + CARD_WIDTH + CARD_GAP_X)
|
|
1474
1623
|
}
|
|
1475
1624
|
// Folders collapse member cards into one compact card until unpacked.
|
|
1476
1625
|
if (Array.isArray(folders) && folders.length > 0 && sessionCards.length > 0) {
|
|
@@ -1500,8 +1649,9 @@ window.__ModuleLoader__.load({
|
|
|
1500
1649
|
color: firstMember.color,
|
|
1501
1650
|
x: override?.x ?? (Number.isFinite(folder.x) ? folder.x : firstMember.x),
|
|
1502
1651
|
y: override?.y ?? (Number.isFinite(folder.y) ? folder.y : firstMember.y),
|
|
1503
|
-
label: '卡片夹',
|
|
1504
|
-
|
|
1652
|
+
label: folder.name || '卡片夹',
|
|
1653
|
+
folderName: folder.name || '卡片夹',
|
|
1654
|
+
title: `${session.title || session.sessionId.slice(0, 8)} · ${folder.name || '卡片夹'}(${members.length} 张)`,
|
|
1505
1655
|
prompt: null,
|
|
1506
1656
|
note: null,
|
|
1507
1657
|
checkpoints: [],
|
|
@@ -1599,7 +1749,7 @@ window.__ModuleLoader__.load({
|
|
|
1599
1749
|
}
|
|
1600
1750
|
|
|
1601
1751
|
/** One card of the conversation canvas. */
|
|
1602
|
-
function CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding }) {
|
|
1752
|
+
function CanvasCard({ card, t, selectedKey, onSelect, onChat, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding, onRewind }) {
|
|
1603
1753
|
const files = (card.checkpoints ?? []).reduce(
|
|
1604
1754
|
(total, checkpoint) => ({
|
|
1605
1755
|
added: total.added + (checkpoint.files?.added ?? 0),
|
|
@@ -1641,6 +1791,7 @@ window.__ModuleLoader__.load({
|
|
|
1641
1791
|
event.stopPropagation()
|
|
1642
1792
|
if (consumeClick()) return
|
|
1643
1793
|
onSelect(card.key)
|
|
1794
|
+
if (typeof onChat === 'function') onChat(card)
|
|
1644
1795
|
},
|
|
1645
1796
|
onDoubleClick: (event) => {
|
|
1646
1797
|
event.stopPropagation()
|
|
@@ -1654,6 +1805,7 @@ window.__ModuleLoader__.load({
|
|
|
1654
1805
|
if (event.key === 'Enter' || event.key === ' ') {
|
|
1655
1806
|
event.preventDefault()
|
|
1656
1807
|
onSelect(card.key)
|
|
1808
|
+
if (typeof onChat === 'function') onChat(card)
|
|
1657
1809
|
}
|
|
1658
1810
|
},
|
|
1659
1811
|
},
|
|
@@ -1679,6 +1831,22 @@ window.__ModuleLoader__.load({
|
|
|
1679
1831
|
'📝',
|
|
1680
1832
|
)
|
|
1681
1833
|
: null,
|
|
1834
|
+
branchTarget && branchTarget.hasSnapshot === true && typeof onRewind === 'function'
|
|
1835
|
+
? h(
|
|
1836
|
+
'button',
|
|
1837
|
+
{
|
|
1838
|
+
type: 'button',
|
|
1839
|
+
className: 'tb-card-rewind',
|
|
1840
|
+
title: t('panel.rewind'),
|
|
1841
|
+
'aria-label': t('panel.rewind'),
|
|
1842
|
+
onClick: (event) => {
|
|
1843
|
+
event.stopPropagation()
|
|
1844
|
+
onRewind(card, branchTarget)
|
|
1845
|
+
},
|
|
1846
|
+
},
|
|
1847
|
+
'⏪',
|
|
1848
|
+
)
|
|
1849
|
+
: null,
|
|
1682
1850
|
card.createdAt ? h('span', { className: 'tb-card-time' }, clock(card.createdAt)) : null,
|
|
1683
1851
|
card.isCurrentPosition ? h('span', { className: 'tb-card-dot', title: t('panel.current') }) : null,
|
|
1684
1852
|
),
|
|
@@ -1734,7 +1902,24 @@ window.__ModuleLoader__.load({
|
|
|
1734
1902
|
}
|
|
1735
1903
|
|
|
1736
1904
|
/** One collapsed card folder: compact, with member labels and an unpack action. */
|
|
1737
|
-
function CanvasFolderCard({
|
|
1905
|
+
function CanvasFolderCard({
|
|
1906
|
+
card,
|
|
1907
|
+
t,
|
|
1908
|
+
onDragStart,
|
|
1909
|
+
onUnpackFolder,
|
|
1910
|
+
dropTargetKey,
|
|
1911
|
+
folding,
|
|
1912
|
+
expanded,
|
|
1913
|
+
onToggleFolder,
|
|
1914
|
+
onMemberDragStart,
|
|
1915
|
+
suppressClickRef,
|
|
1916
|
+
renaming,
|
|
1917
|
+
renameDraft,
|
|
1918
|
+
onRenameStart,
|
|
1919
|
+
onRenameChange,
|
|
1920
|
+
onRenameCommit,
|
|
1921
|
+
onRenameCancel,
|
|
1922
|
+
}) {
|
|
1738
1923
|
const members = card.members ?? []
|
|
1739
1924
|
return h(
|
|
1740
1925
|
'article',
|
|
@@ -1761,8 +1946,40 @@ window.__ModuleLoader__.load({
|
|
|
1761
1946
|
'div',
|
|
1762
1947
|
{ className: 'tb-card-head' },
|
|
1763
1948
|
h('span', { className: 'tb-card-badge' }, '📁'),
|
|
1764
|
-
|
|
1949
|
+
renaming
|
|
1950
|
+
? h('input', {
|
|
1951
|
+
className: 'tb-folder-name-input',
|
|
1952
|
+
value: renameDraft ?? '',
|
|
1953
|
+
placeholder: t('tree.folderNamePlaceholder'),
|
|
1954
|
+
autoFocus: true,
|
|
1955
|
+
'aria-label': t('tree.folderRename'),
|
|
1956
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
1957
|
+
onChange: (event) => onRenameChange?.(event.target.value),
|
|
1958
|
+
onKeyDown: (event) => {
|
|
1959
|
+
event.stopPropagation()
|
|
1960
|
+
if (event.key === 'Enter') onRenameCommit?.()
|
|
1961
|
+
else if (event.key === 'Escape') onRenameCancel?.()
|
|
1962
|
+
},
|
|
1963
|
+
onBlur: () => onRenameCommit?.(),
|
|
1964
|
+
})
|
|
1965
|
+
: h('span', { className: 'tb-folder-name', title: card.folderName || '卡片夹' }, card.folderName || '卡片夹'),
|
|
1765
1966
|
h('span', { className: 'tb-card-spacer' }),
|
|
1967
|
+
!renaming && typeof onRenameStart === 'function'
|
|
1968
|
+
? h(
|
|
1969
|
+
'button',
|
|
1970
|
+
{
|
|
1971
|
+
type: 'button',
|
|
1972
|
+
className: 'tb-folder-rename',
|
|
1973
|
+
title: t('tree.folderRename'),
|
|
1974
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
1975
|
+
onClick: (event) => {
|
|
1976
|
+
event.stopPropagation()
|
|
1977
|
+
onRenameStart(card.folderId)
|
|
1978
|
+
},
|
|
1979
|
+
},
|
|
1980
|
+
'✎',
|
|
1981
|
+
)
|
|
1982
|
+
: null,
|
|
1766
1983
|
card.createdAt ? h('span', { className: 'tb-card-time' }, clock(card.createdAt)) : null,
|
|
1767
1984
|
),
|
|
1768
1985
|
expanded
|
|
@@ -1838,6 +2055,7 @@ window.__ModuleLoader__.load({
|
|
|
1838
2055
|
t,
|
|
1839
2056
|
selectedKey,
|
|
1840
2057
|
onSelect,
|
|
2058
|
+
onChat,
|
|
1841
2059
|
onOpen,
|
|
1842
2060
|
onBranch,
|
|
1843
2061
|
onNote,
|
|
@@ -1845,9 +2063,21 @@ window.__ModuleLoader__.load({
|
|
|
1845
2063
|
onUnpackFolder,
|
|
1846
2064
|
dropTargetKey,
|
|
1847
2065
|
folding,
|
|
2066
|
+
onRewind,
|
|
1848
2067
|
expandedFolderId,
|
|
1849
2068
|
onToggleFolder,
|
|
1850
2069
|
onMemberDragStart,
|
|
2070
|
+
renamingFolderId,
|
|
2071
|
+
folderNameDraft,
|
|
2072
|
+
doodleMode,
|
|
2073
|
+
doodles,
|
|
2074
|
+
onToggleDoodle,
|
|
2075
|
+
onClearDoodles,
|
|
2076
|
+
onDoodlePointerDown,
|
|
2077
|
+
onRenameStart,
|
|
2078
|
+
onRenameChange,
|
|
2079
|
+
onRenameCommit,
|
|
2080
|
+
onRenameCancel,
|
|
1851
2081
|
onResetLayout,
|
|
1852
2082
|
autoPan,
|
|
1853
2083
|
panSpeed,
|
|
@@ -1899,6 +2129,20 @@ window.__ModuleLoader__.load({
|
|
|
1899
2129
|
},
|
|
1900
2130
|
panSpeed === 'slow' ? t('tree.panSpeedSlow') : panSpeed === 'fast' ? t('tree.panSpeedFast') : t('tree.panSpeedNormal'),
|
|
1901
2131
|
),
|
|
2132
|
+
h(
|
|
2133
|
+
'button',
|
|
2134
|
+
{
|
|
2135
|
+
type: 'button',
|
|
2136
|
+
className: `tb-canvas-btn${doodleMode ? ' on' : ''}`,
|
|
2137
|
+
title: t('tree.doodleHint'),
|
|
2138
|
+
'aria-pressed': doodleMode === true,
|
|
2139
|
+
onClick: onToggleDoodle,
|
|
2140
|
+
},
|
|
2141
|
+
doodleMode ? `✏️ ${t('tree.doodleOn')}` : `✏️ ${t('tree.doodleOff')}`,
|
|
2142
|
+
),
|
|
2143
|
+
doodleMode
|
|
2144
|
+
? h('button', { type: 'button', className: 'tb-canvas-btn', title: t('tree.doodleClear'), onClick: onClearDoodles }, `🧽 ${t('tree.doodleClear')}`)
|
|
2145
|
+
: null,
|
|
1902
2146
|
h('button', { type: 'button', className: 'tb-canvas-btn', title: t('tree.resetLayoutHint'), onClick: onResetLayout }, t('tree.resetLayout')),
|
|
1903
2147
|
h('button', { type: 'button', className: 'tb-canvas-btn', title: t('tree.expandHint'), onClick: onToggleExpand }, expanded ? '⤡' : '⤢'),
|
|
1904
2148
|
h('span', { className: 'tb-canvas-hint' }, t('tree.folderHint')),
|
|
@@ -1940,6 +2184,30 @@ window.__ModuleLoader__.load({
|
|
|
1940
2184
|
h('span', null, t('tree.folderDropHint')),
|
|
1941
2185
|
)
|
|
1942
2186
|
})(),
|
|
2187
|
+
h(
|
|
2188
|
+
'svg',
|
|
2189
|
+
{
|
|
2190
|
+
className: `tb-tree-doodles${doodleMode ? ' active' : ''}`,
|
|
2191
|
+
width: layout.width,
|
|
2192
|
+
height: layout.height,
|
|
2193
|
+
style: { pointerEvents: doodleMode ? 'auto' : 'none', cursor: doodleMode ? 'crosshair' : 'default' },
|
|
2194
|
+
onPointerDown: (event) => {
|
|
2195
|
+
if (!doodleMode) return
|
|
2196
|
+
event.stopPropagation()
|
|
2197
|
+
onDoodlePointerDown?.(event)
|
|
2198
|
+
},
|
|
2199
|
+
},
|
|
2200
|
+
...(doodles ?? []).map((stroke, index) =>
|
|
2201
|
+
h('polyline', {
|
|
2202
|
+
key: `doodle-${index}`,
|
|
2203
|
+
points: (stroke.points ?? []).map((point) => `${point[0]},${point[1]}`).join(' '),
|
|
2204
|
+
stroke: stroke.color || '#ff5f56',
|
|
2205
|
+
strokeWidth: stroke.width || 3,
|
|
2206
|
+
opacity: 0.9,
|
|
2207
|
+
}),
|
|
2208
|
+
),
|
|
2209
|
+
doodleMode ? h('rect', { x: 0, y: 0, width: layout.width, height: layout.height, fill: 'transparent' }) : null,
|
|
2210
|
+
),
|
|
1943
2211
|
...layout.cards.map((card) =>
|
|
1944
2212
|
card.kind === 'folder'
|
|
1945
2213
|
? CanvasFolderCard({
|
|
@@ -1953,8 +2221,14 @@ window.__ModuleLoader__.load({
|
|
|
1953
2221
|
onToggleFolder,
|
|
1954
2222
|
onMemberDragStart,
|
|
1955
2223
|
suppressClickRef,
|
|
2224
|
+
renaming: renamingFolderId === card.folderId,
|
|
2225
|
+
renameDraft: folderNameDraft,
|
|
2226
|
+
onRenameStart,
|
|
2227
|
+
onRenameChange,
|
|
2228
|
+
onRenameCommit,
|
|
2229
|
+
onRenameCancel,
|
|
1956
2230
|
})
|
|
1957
|
-
: CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding }),
|
|
2231
|
+
: CanvasCard({ card, t, selectedKey, onSelect, onChat, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding, onRewind }),
|
|
1958
2232
|
),
|
|
1959
2233
|
),
|
|
1960
2234
|
)
|
|
@@ -2097,6 +2371,69 @@ window.__ModuleLoader__.load({
|
|
|
2097
2371
|
)
|
|
2098
2372
|
}
|
|
2099
2373
|
|
|
2374
|
+
/** Extract text from one model/user message's content blocks. */
|
|
2375
|
+
function messageTextOf(message) {
|
|
2376
|
+
const blocks = Array.isArray(message?.content) ? message.content : []
|
|
2377
|
+
const parts = []
|
|
2378
|
+
for (const block of blocks) {
|
|
2379
|
+
if (!block || typeof block !== 'object') continue
|
|
2380
|
+
if (block.type === 'text' && typeof block.text === 'string') parts.push(block.text)
|
|
2381
|
+
else if (block.type === 'image') parts.push('[image]')
|
|
2382
|
+
else if (block.type === 'file') parts.push('[file]')
|
|
2383
|
+
}
|
|
2384
|
+
return parts.join('\n\n').trim()
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
/** Durable Session events from an event-window snapshot. */
|
|
2388
|
+
function durableSessionEvents(entries) {
|
|
2389
|
+
return (Array.isArray(entries) ? entries : [])
|
|
2390
|
+
.map((entry) => (entry?.type === 'event' ? entry.event : null))
|
|
2391
|
+
.filter(Boolean)
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2394
|
+
/** Messages belonging to one turn number, in conversation order. */
|
|
2395
|
+
function turnConversation(events, turn) {
|
|
2396
|
+
if (!Number.isInteger(turn)) return []
|
|
2397
|
+
const start = events.find((event) => event.type === 'turn/start' && event.data?.turn === turn)
|
|
2398
|
+
if (!start) return []
|
|
2399
|
+
const later = events.find((event) => event.type === 'turn/start' && event.seq > start.seq)
|
|
2400
|
+
const endSeq = later?.seq ?? Infinity
|
|
2401
|
+
const messages = []
|
|
2402
|
+
for (const event of events) {
|
|
2403
|
+
if (!Number.isInteger(event.seq) || event.seq < start.seq || event.seq >= endSeq) continue
|
|
2404
|
+
if (event.type === 'user/message' && event.data?.source?.kind === 'user') {
|
|
2405
|
+
const text = messageTextOf(event.data)
|
|
2406
|
+
if (text !== '') messages.push({ role: 'user', text, seq: event.seq })
|
|
2407
|
+
} else if (event.type === 'assistant/message') {
|
|
2408
|
+
const text = messageTextOf(event.data?.message)
|
|
2409
|
+
if (text !== '') messages.push({ role: 'assistant', text, seq: event.seq })
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
return messages
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
/** Best turn number for a card without an explicit turn (manual/start cards). */
|
|
2416
|
+
function turnForCheckpoint(events, checkpoint) {
|
|
2417
|
+
if (!checkpoint) return null
|
|
2418
|
+
const seq = Number.isInteger(checkpoint.seq) ? checkpoint.seq : Infinity
|
|
2419
|
+
let best = null
|
|
2420
|
+
for (const event of events) {
|
|
2421
|
+
if (event.type !== 'turn/start' || !Number.isInteger(event.data?.turn)) continue
|
|
2422
|
+
if (event.seq <= seq) best = event.data.turn
|
|
2423
|
+
else break
|
|
2424
|
+
}
|
|
2425
|
+
return best
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
/** Whether a card is the last card of the current session's branch. */
|
|
2429
|
+
function cardIsTail(card, layout, data) {
|
|
2430
|
+
if (!card || card.kind === 'folder' || !layout || !data) return false
|
|
2431
|
+
if (String(card.sessionId) !== String(data.currentSessionId)) return false
|
|
2432
|
+
const cards = (layout.cards ?? []).filter((entry) => entry.kind !== 'folder' && String(entry.sessionId) === String(card.sessionId))
|
|
2433
|
+
const last = cards[cards.length - 1]
|
|
2434
|
+
return Boolean(last && last.key === card.key)
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2100
2437
|
/* ---------------------------------------------------------------- */
|
|
2101
2438
|
/* panel */
|
|
2102
2439
|
/* ---------------------------------------------------------------- */
|
|
@@ -2121,6 +2458,12 @@ window.__ModuleLoader__.load({
|
|
|
2121
2458
|
return () => window.clearTimeout(timer)
|
|
2122
2459
|
}, [feedback])
|
|
2123
2460
|
const [view, setView] = React.useState('tree')
|
|
2461
|
+
const [workspaceOpen, setWorkspaceOpen] = React.useState(false)
|
|
2462
|
+
const [renamingFolderId, setRenamingFolderId] = React.useState(null)
|
|
2463
|
+
const [folderNameDraft, setFolderNameDraft] = React.useState('')
|
|
2464
|
+
const [doodleMode, setDoodleMode] = React.useState(false)
|
|
2465
|
+
const [doodles, setDoodles] = React.useState([])
|
|
2466
|
+
const doodlesRef = React.useRef([])
|
|
2124
2467
|
const [selectedKey, setSelectedKey] = React.useState(null)
|
|
2125
2468
|
const [zoom, setZoom] = React.useState(1)
|
|
2126
2469
|
const [canvasExpanded, setCanvasExpanded] = React.useState(false)
|
|
@@ -2145,6 +2488,7 @@ window.__ModuleLoader__.load({
|
|
|
2145
2488
|
const panSpeedRef = React.useRef(panSpeed)
|
|
2146
2489
|
panSpeedRef.current = panSpeed
|
|
2147
2490
|
const [noteEditor, setNoteEditor] = React.useState(null)
|
|
2491
|
+
const [chat, setChat] = React.useState(null)
|
|
2148
2492
|
const viewportRef = React.useRef(null)
|
|
2149
2493
|
const worldRef = React.useRef(null)
|
|
2150
2494
|
const cameraRef = React.useRef({ x: 0, y: 0, scale: 1 })
|
|
@@ -2248,6 +2592,15 @@ window.__ModuleLoader__.load({
|
|
|
2248
2592
|
else if (action === 'restore-files') message = format(t('panel.confirmFiles'), { who, warning: t('panel.deleteWarning') })
|
|
2249
2593
|
else message = format(t('panel.confirmRewind'), { who, warning: t('panel.deleteWarning') })
|
|
2250
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
|
+
}
|
|
2251
2604
|
const busyKey = checkpoint ? checkpoint.id : action
|
|
2252
2605
|
setBusy(busyKey)
|
|
2253
2606
|
busyRef.current = busyKey
|
|
@@ -2270,6 +2623,7 @@ window.__ModuleLoader__.load({
|
|
|
2270
2623
|
const isFileAction = action === 'restore-files' || mode === 'files-only'
|
|
2271
2624
|
body = { action: isFileAction ? 'restore-files' : 'rewind', sessionId: actionSessionId, checkpointId: checkpoint.id }
|
|
2272
2625
|
if (mode) body.mode = mode
|
|
2626
|
+
if (branchName) body.name = branchName
|
|
2273
2627
|
}
|
|
2274
2628
|
const result = await request('action', { method: 'POST', body })
|
|
2275
2629
|
let tone = 'ok'
|
|
@@ -2308,7 +2662,7 @@ window.__ModuleLoader__.load({
|
|
|
2308
2662
|
pruneCandidate,
|
|
2309
2663
|
})
|
|
2310
2664
|
if (action === 'prune' && result.childSessionId) openChild(result.childSessionId)
|
|
2311
|
-
if (action === 'rewind') {
|
|
2665
|
+
if (action === 'rewind' || action === 'prune') {
|
|
2312
2666
|
try {
|
|
2313
2667
|
window.dispatchEvent(new CustomEvent('dsh-timeback:board-changed'))
|
|
2314
2668
|
} catch {
|
|
@@ -2481,8 +2835,13 @@ window.__ModuleLoader__.load({
|
|
|
2481
2835
|
const clientVersion = BUILD.split('+')[0]
|
|
2482
2836
|
const serverVersion = typeof data?.serverVersion === 'string' ? data.serverVersion : null
|
|
2483
2837
|
const staleBundle = Boolean(serverVersion && clientVersion !== serverVersion)
|
|
2484
|
-
const
|
|
2485
|
-
layout?.cards.filter((card) => card.sessionId === data?.currentSessionId)
|
|
2838
|
+
const fallbackCard = (() => {
|
|
2839
|
+
const candidates = layout?.cards.filter((card) => card.sessionId === data?.currentSessionId) ?? []
|
|
2840
|
+
const latest = candidates[candidates.length - 1]
|
|
2841
|
+
if (latest?.kind === 'folder') return latest.members?.[latest.members.length - 1] ?? candidates.filter((card) => card.kind !== 'folder').slice(-1)[0] ?? latest
|
|
2842
|
+
return latest ?? candidates[candidates.length - 1] ?? layout?.cards.slice(-1)[0] ?? null
|
|
2843
|
+
})()
|
|
2844
|
+
const fallbackNode = fallbackCard && fallbackCard.kind !== 'folder' ? fallbackCard : null
|
|
2486
2845
|
const selectedNode = (selectedKey ? layout?.cards.find((card) => card.key === selectedKey) : null) ?? fallbackNode
|
|
2487
2846
|
const effectiveSelectedKey = selectedNode?.key ?? null
|
|
2488
2847
|
|
|
@@ -2503,28 +2862,45 @@ window.__ModuleLoader__.load({
|
|
|
2503
2862
|
|
|
2504
2863
|
const positionsKey = data?.rootSessionId ? `dsh-timeback:card-positions:${data.rootSessionId}` : null
|
|
2505
2864
|
const foldersKey = data?.rootSessionId ? `dsh-timeback:card-folders:${data.rootSessionId}` : null
|
|
2865
|
+
const doodlesKey = data?.rootSessionId ? `dsh-timeback:tree-doodles:${data.rootSessionId}` : null
|
|
2506
2866
|
|
|
2507
2867
|
// Restore dragged card positions and folders for this branch family.
|
|
2508
2868
|
React.useEffect(() => {
|
|
2509
2869
|
if (!positionsKey) return
|
|
2510
2870
|
let saved = {}
|
|
2511
2871
|
let savedFolders = []
|
|
2872
|
+
let savedDoodles = []
|
|
2512
2873
|
try {
|
|
2513
2874
|
const raw = window.localStorage.getItem(positionsKey)
|
|
2514
2875
|
if (raw) saved = JSON.parse(raw)
|
|
2515
2876
|
const rawFolders = window.localStorage.getItem(foldersKey)
|
|
2516
2877
|
if (rawFolders) savedFolders = JSON.parse(rawFolders)
|
|
2878
|
+
const rawDoodles = window.localStorage.getItem(doodlesKey)
|
|
2879
|
+
if (rawDoodles) savedDoodles = JSON.parse(rawDoodles)
|
|
2517
2880
|
} catch {
|
|
2518
2881
|
saved = {}
|
|
2519
2882
|
savedFolders = []
|
|
2883
|
+
savedDoodles = []
|
|
2520
2884
|
}
|
|
2521
2885
|
if (saved === null || typeof saved !== 'object' || Array.isArray(saved)) saved = {}
|
|
2522
2886
|
if (!Array.isArray(savedFolders)) savedFolders = []
|
|
2887
|
+
if (!Array.isArray(savedDoodles)) savedDoodles = []
|
|
2888
|
+
savedDoodles = savedDoodles
|
|
2889
|
+
.filter((stroke) => stroke && Array.isArray(stroke.points) && stroke.points.length > 1)
|
|
2890
|
+
.slice(-200)
|
|
2891
|
+
.map((stroke) => ({
|
|
2892
|
+
color: /^#[0-9a-f]{6}$/i.test(String(stroke.color || '')) ? String(stroke.color) : '#ff5f56',
|
|
2893
|
+
width: Math.min(12, Math.max(1, Number(stroke.width) || 3)),
|
|
2894
|
+
points: stroke.points.filter((point) => Array.isArray(point) && point.length >= 2 && Number.isFinite(point[0]) && Number.isFinite(point[1])).slice(0, 2000),
|
|
2895
|
+
}))
|
|
2896
|
+
.filter((stroke) => stroke.points.length > 1)
|
|
2523
2897
|
positionsRef.current = saved
|
|
2524
2898
|
setPositions(saved)
|
|
2525
2899
|
foldersRef.current = savedFolders
|
|
2526
2900
|
setFolders(savedFolders)
|
|
2527
|
-
|
|
2901
|
+
doodlesRef.current = savedDoodles
|
|
2902
|
+
setDoodles(savedDoodles)
|
|
2903
|
+
}, [positionsKey, foldersKey, doodlesKey])
|
|
2528
2904
|
|
|
2529
2905
|
// Wheel zoom must be non-passive, so it is bound directly to the viewport.
|
|
2530
2906
|
React.useEffect(() => {
|
|
@@ -2571,6 +2947,10 @@ window.__ModuleLoader__.load({
|
|
|
2571
2947
|
const unpackFolder = (folderId) => {
|
|
2572
2948
|
const next = foldersRef.current.filter((folder) => folder.id !== folderId)
|
|
2573
2949
|
storeFolders(next, true)
|
|
2950
|
+
if (renamingFolderId === folderId) {
|
|
2951
|
+
setRenamingFolderId(null)
|
|
2952
|
+
setFolderNameDraft('')
|
|
2953
|
+
}
|
|
2574
2954
|
}
|
|
2575
2955
|
|
|
2576
2956
|
/** Expand/collapse one folder's full member list. */
|
|
@@ -2578,6 +2958,81 @@ window.__ModuleLoader__.load({
|
|
|
2578
2958
|
setExpandedFolderId((current) => (current === folderId ? null : folderId))
|
|
2579
2959
|
}
|
|
2580
2960
|
|
|
2961
|
+
/** Start inline renaming for one folder card. */
|
|
2962
|
+
const startFolderRename = (folderId) => {
|
|
2963
|
+
const folder = foldersRef.current.find((entry) => entry.id === folderId)
|
|
2964
|
+
if (!folder) return
|
|
2965
|
+
setRenamingFolderId(folderId)
|
|
2966
|
+
setFolderNameDraft(folder.name || '卡片夹')
|
|
2967
|
+
}
|
|
2968
|
+
|
|
2969
|
+
const commitFolderRename = () => {
|
|
2970
|
+
if (!renamingFolderId) return
|
|
2971
|
+
const next = renameCardFolder(foldersRef.current, renamingFolderId, folderNameDraft)
|
|
2972
|
+
storeFolders(next, true)
|
|
2973
|
+
setRenamingFolderId(null)
|
|
2974
|
+
setFolderNameDraft('')
|
|
2975
|
+
}
|
|
2976
|
+
|
|
2977
|
+
const cancelFolderRename = () => {
|
|
2978
|
+
setRenamingFolderId(null)
|
|
2979
|
+
setFolderNameDraft('')
|
|
2980
|
+
}
|
|
2981
|
+
|
|
2982
|
+
/** Persist freehand doodles over the conversation canvas. */
|
|
2983
|
+
const storeDoodles = (next, persist) => {
|
|
2984
|
+
doodlesRef.current = next
|
|
2985
|
+
setDoodles(next)
|
|
2986
|
+
if (persist !== true) return
|
|
2987
|
+
try {
|
|
2988
|
+
if (doodlesKey) window.localStorage.setItem(doodlesKey, JSON.stringify(next))
|
|
2989
|
+
} catch {
|
|
2990
|
+
// Storage can be disabled; doodles still work in memory.
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
|
|
2994
|
+
const beginDoodle = (event) => {
|
|
2995
|
+
if (event.button !== 0) return
|
|
2996
|
+
const viewport = viewportRef.current
|
|
2997
|
+
if (!viewport) return
|
|
2998
|
+
event.preventDefault()
|
|
2999
|
+
const rect = viewport.getBoundingClientRect()
|
|
3000
|
+
const toWorld = (next) => {
|
|
3001
|
+
const camera = cameraRef.current
|
|
3002
|
+
return [
|
|
3003
|
+
Math.round((next.clientX - rect.left - camera.x) / camera.scale),
|
|
3004
|
+
Math.round((next.clientY - rect.top - camera.y) / camera.scale),
|
|
3005
|
+
]
|
|
3006
|
+
}
|
|
3007
|
+
const startPoint = toWorld(event)
|
|
3008
|
+
const stroke = { color: '#ff5f56', width: 3, points: [startPoint] }
|
|
3009
|
+
let strokes = [...doodlesRef.current, stroke]
|
|
3010
|
+
setDoodles(strokes)
|
|
3011
|
+
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)
|
|
3019
|
+
}
|
|
3020
|
+
const finish = () => {
|
|
3021
|
+
window.removeEventListener('pointermove', move)
|
|
3022
|
+
window.removeEventListener('pointerup', finish)
|
|
3023
|
+
window.removeEventListener('pointercancel', finish)
|
|
3024
|
+
doodlesRef.current = [...doodlesRef.current.filter((item) => item !== stroke), stroke].slice(-200)
|
|
3025
|
+
storeDoodles(doodlesRef.current, true)
|
|
3026
|
+
}
|
|
3027
|
+
window.addEventListener('pointermove', move)
|
|
3028
|
+
window.addEventListener('pointerup', finish)
|
|
3029
|
+
window.addEventListener('pointercancel', finish)
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
const clearDoodles = () => {
|
|
3033
|
+
storeDoodles([], true)
|
|
3034
|
+
}
|
|
3035
|
+
|
|
2581
3036
|
/** Remove one card from a folder; a folder with <2 members dissolves. */
|
|
2582
3037
|
const detachFolderMember = (folderId, memberKey, position) => {
|
|
2583
3038
|
const next = removeFolderMember(foldersRef.current, folderId, memberKey)
|
|
@@ -2837,6 +3292,115 @@ window.__ModuleLoader__.load({
|
|
|
2837
3292
|
})
|
|
2838
3293
|
}
|
|
2839
3294
|
|
|
3295
|
+
/** Read the turn behind one card and open its conversation/composer. */
|
|
3296
|
+
const openCardConversation = async (card) => {
|
|
3297
|
+
if (!card || card.kind === 'folder') return
|
|
3298
|
+
const base = { card, loading: true, messages: [], error: null, input: '', sending: false }
|
|
3299
|
+
setChat(base)
|
|
3300
|
+
if (!sessionApi) {
|
|
3301
|
+
setChat({ ...base, loading: false, error: t('chat.unavailable') })
|
|
3302
|
+
return
|
|
3303
|
+
}
|
|
3304
|
+
try {
|
|
3305
|
+
const checkpoint = [...(card.checkpoints ?? [])].reverse().find((entry) => Number.isInteger(entry.seq))
|
|
3306
|
+
const entries = await sessionApi.using(card.sessionId, { source: 'gateway' }, async (reference) => {
|
|
3307
|
+
const binding = await reference.ready
|
|
3308
|
+
if (checkpoint) {
|
|
3309
|
+
try {
|
|
3310
|
+
await binding.session.loadThrough(checkpoint.seq)
|
|
3311
|
+
} catch {
|
|
3312
|
+
// The visible window may already cover the turn.
|
|
3313
|
+
}
|
|
3314
|
+
}
|
|
3315
|
+
const source = binding.eventSource
|
|
3316
|
+
const window = typeof source?.getSnapshot === 'function' ? source.getSnapshot() : source?.snapshot
|
|
3317
|
+
return window?.entries ?? []
|
|
3318
|
+
})
|
|
3319
|
+
const events = durableSessionEvents(entries)
|
|
3320
|
+
const turn = Number.isInteger(card.turn) ? card.turn : turnForCheckpoint(events, checkpoint)
|
|
3321
|
+
let messages = turnConversation(events, turn)
|
|
3322
|
+
if (messages.length === 0 && card.prompt) messages = [{ role: 'user', text: card.prompt }]
|
|
3323
|
+
setChat((current) =>
|
|
3324
|
+
current && current.card.key === card.key
|
|
3325
|
+
? { ...current, loading: false, messages, error: null }
|
|
3326
|
+
: current,
|
|
3327
|
+
)
|
|
3328
|
+
} catch (error) {
|
|
3329
|
+
setChat((current) =>
|
|
3330
|
+
current && current.card.key === card.key
|
|
3331
|
+
? { ...current, loading: false, error: error?.message || String(error) }
|
|
3332
|
+
: current,
|
|
3333
|
+
)
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
|
|
3337
|
+
/** Send the composer text: continue the tail session or branch then send. */
|
|
3338
|
+
const sendChatMessage = async () => {
|
|
3339
|
+
const current = chat
|
|
3340
|
+
if (!current || current.sending) return
|
|
3341
|
+
const text = String(current.input ?? '').trim()
|
|
3342
|
+
if (text === '') return
|
|
3343
|
+
if (!sessionApi) {
|
|
3344
|
+
setChat({ ...current, error: t('chat.unavailable') })
|
|
3345
|
+
return
|
|
3346
|
+
}
|
|
3347
|
+
setChat({ ...current, sending: true, error: null })
|
|
3348
|
+
try {
|
|
3349
|
+
const data = state.data
|
|
3350
|
+
const layout = data ? layoutTree(data.sessions ?? [], data.currentSessionId, positionsRef.current, foldersRef.current) : null
|
|
3351
|
+
const tail = cardIsTail(current.card, layout, data)
|
|
3352
|
+
let targetSessionId = current.card.sessionId
|
|
3353
|
+
let branched = false
|
|
3354
|
+
if (!tail) {
|
|
3355
|
+
const checkpoints = current.card.checkpoints ?? []
|
|
3356
|
+
const checkpoint =
|
|
3357
|
+
[...checkpoints].reverse().find((entry) => Number.isInteger(entry.seq) && entry.phase !== 'before') ??
|
|
3358
|
+
[...checkpoints].reverse().find((entry) => Number.isInteger(entry.seq))
|
|
3359
|
+
if (!checkpoint) throw new Error(t('chat.noCheckpoint'))
|
|
3360
|
+
const result = await request('action', {
|
|
3361
|
+
method: 'POST',
|
|
3362
|
+
body: {
|
|
3363
|
+
action: 'rewind',
|
|
3364
|
+
sessionId: current.card.sessionId,
|
|
3365
|
+
checkpointId: checkpoint.id,
|
|
3366
|
+
mode: 'branch-only',
|
|
3367
|
+
name: text.slice(0, 120),
|
|
3368
|
+
},
|
|
3369
|
+
})
|
|
3370
|
+
if (!result?.childSessionId) throw new Error(t('chat.noCheckpoint'))
|
|
3371
|
+
targetSessionId = result.childSessionId
|
|
3372
|
+
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)
|
|
3376
|
+
}
|
|
3377
|
+
const promptOnce = () =>
|
|
3378
|
+
sessionApi.using(targetSessionId, { source: 'gateway' }, async (reference) => {
|
|
3379
|
+
const binding = await reference.ready
|
|
3380
|
+
return binding.session.prompt([{ type: 'text', text }], 'queue')
|
|
3381
|
+
})
|
|
3382
|
+
let result
|
|
3383
|
+
try {
|
|
3384
|
+
result = await promptOnce()
|
|
3385
|
+
} catch (error) {
|
|
3386
|
+
await sessionApi.refresh().catch(() => {})
|
|
3387
|
+
result = await promptOnce()
|
|
3388
|
+
}
|
|
3389
|
+
if (result && result.ok === false) {
|
|
3390
|
+
throw new Error(result.error?.message ? String(result.error.message) : JSON.stringify(result.error))
|
|
3391
|
+
}
|
|
3392
|
+
setChat(null)
|
|
3393
|
+
setFeedback({ tone: 'ok', text: branched ? t('chat.branched') : t('chat.sent') })
|
|
3394
|
+
setTick((value) => value + 1)
|
|
3395
|
+
} catch (error) {
|
|
3396
|
+
setChat((previous) =>
|
|
3397
|
+
previous
|
|
3398
|
+
? { ...previous, sending: false, error: format(t('chat.failed'), { error: error?.message || String(error) }) }
|
|
3399
|
+
: previous,
|
|
3400
|
+
)
|
|
3401
|
+
}
|
|
3402
|
+
}
|
|
3403
|
+
|
|
2840
3404
|
/** Saving close for the card-note sheet: outside clicks never discard text. */
|
|
2841
3405
|
const dismissCardNoteSaving = async () => {
|
|
2842
3406
|
const editor = noteEditor
|
|
@@ -2989,7 +3553,17 @@ window.__ModuleLoader__.load({
|
|
|
2989
3553
|
),
|
|
2990
3554
|
)
|
|
2991
3555
|
: null,
|
|
2992
|
-
renderWorkspaceSection({
|
|
3556
|
+
renderWorkspaceSection({
|
|
3557
|
+
workspace: data?.workspace,
|
|
3558
|
+
gitOff,
|
|
3559
|
+
busy,
|
|
3560
|
+
t,
|
|
3561
|
+
toggleWorkspace,
|
|
3562
|
+
sessionId,
|
|
3563
|
+
onWorkspaceChanged: () => setTick((value) => value + 1),
|
|
3564
|
+
open: workspaceOpen,
|
|
3565
|
+
onToggle: () => setWorkspaceOpen((value) => !value),
|
|
3566
|
+
}),
|
|
2993
3567
|
gitOff ? h('p', { className: 'tb-note' }, t('panel.noGit')) : h('p', { className: 'tb-note' }, t('panel.warning')),
|
|
2994
3568
|
state.error ? h('div', { className: 'tb-feedback err', role: 'alert' }, `${t('panel.error')}: ${state.error}`) : null,
|
|
2995
3569
|
state.loading && !data ? h('div', { className: 'tb-empty' }, t('panel.loading')) : null,
|
|
@@ -3025,14 +3599,17 @@ window.__ModuleLoader__.load({
|
|
|
3025
3599
|
? h(
|
|
3026
3600
|
'div',
|
|
3027
3601
|
{ className: 'tb-tree-section' },
|
|
3602
|
+
renderCheckpointDetail({ node: selectedNode, layout, t, act, busy, gitOff, currentSessionId: data.currentSessionId, onNote: openCardNote }),
|
|
3028
3603
|
TreeCanvas({
|
|
3029
3604
|
layout,
|
|
3030
3605
|
t,
|
|
3031
3606
|
selectedKey: effectiveSelectedKey,
|
|
3032
3607
|
onSelect: setSelectedKey,
|
|
3608
|
+
onChat: openCardConversation,
|
|
3033
3609
|
onOpen: openSessionByCard,
|
|
3034
3610
|
onBranch: branchFromCard,
|
|
3035
3611
|
onPrune: pruneFromCard,
|
|
3612
|
+
onRewind: (card, checkpoint) => act('rewind', checkpoint, null, card.sessionId),
|
|
3036
3613
|
onNote: openCardNote,
|
|
3037
3614
|
expanded: canvasExpanded,
|
|
3038
3615
|
onToggleExpand: () => setCanvasExpanded((value) => !value),
|
|
@@ -3043,6 +3620,17 @@ window.__ModuleLoader__.load({
|
|
|
3043
3620
|
expandedFolderId,
|
|
3044
3621
|
onToggleFolder: toggleFolder,
|
|
3045
3622
|
onMemberDragStart: startFolderMemberDrag,
|
|
3623
|
+
renamingFolderId,
|
|
3624
|
+
folderNameDraft,
|
|
3625
|
+
onRenameStart: startFolderRename,
|
|
3626
|
+
onRenameChange: setFolderNameDraft,
|
|
3627
|
+
onRenameCommit: commitFolderRename,
|
|
3628
|
+
onRenameCancel: cancelFolderRename,
|
|
3629
|
+
doodleMode,
|
|
3630
|
+
doodles,
|
|
3631
|
+
onToggleDoodle: () => setDoodleMode((value) => !value),
|
|
3632
|
+
onClearDoodles: clearDoodles,
|
|
3633
|
+
onDoodlePointerDown: beginDoodle,
|
|
3046
3634
|
onResetLayout: resetCardPositions,
|
|
3047
3635
|
autoPan,
|
|
3048
3636
|
panSpeed,
|
|
@@ -3060,7 +3648,6 @@ window.__ModuleLoader__.load({
|
|
|
3060
3648
|
h('div', { className: 'tb-canvas-hint' }, t('tree.panHint')),
|
|
3061
3649
|
h('div', { className: 'tb-canvas-hint' }, t('tree.dragHint')),
|
|
3062
3650
|
layout.truncated ? h('div', { className: 'tb-ws-hint' }, format(t('tree.truncated'), { count: MAX_TREE_TURNS })) : null,
|
|
3063
|
-
renderCheckpointDetail({ node: selectedNode, layout, t, act, busy, gitOff, currentSessionId: data.currentSessionId, onNote: openCardNote }),
|
|
3064
3651
|
)
|
|
3065
3652
|
: h(
|
|
3066
3653
|
'div',
|
|
@@ -3121,6 +3708,106 @@ window.__ModuleLoader__.load({
|
|
|
3121
3708
|
),
|
|
3122
3709
|
)
|
|
3123
3710
|
: null,
|
|
3711
|
+
chat
|
|
3712
|
+
? h(
|
|
3713
|
+
'div',
|
|
3714
|
+
{ className: 'tb-overlay', onClick: () => { if (!chat.sending) setChat(null) } },
|
|
3715
|
+
h(
|
|
3716
|
+
'div',
|
|
3717
|
+
{
|
|
3718
|
+
className: 'tb-note-dialog tb-chat-dialog',
|
|
3719
|
+
role: 'dialog',
|
|
3720
|
+
'aria-modal': true,
|
|
3721
|
+
onClick: (event) => event.stopPropagation(),
|
|
3722
|
+
},
|
|
3723
|
+
h(
|
|
3724
|
+
'div',
|
|
3725
|
+
{ className: 'tb-detail-head' },
|
|
3726
|
+
h(
|
|
3727
|
+
'span',
|
|
3728
|
+
{ className: 'tb-detail-title' },
|
|
3729
|
+
`${t('chat.title')} · ${chat.card.label}${chat.card.sessionTitle ? ` · ${chat.card.sessionTitle}` : ''}`,
|
|
3730
|
+
),
|
|
3731
|
+
h('span', { style: { flex: 1 } }),
|
|
3732
|
+
h(
|
|
3733
|
+
'button',
|
|
3734
|
+
{
|
|
3735
|
+
type: 'button',
|
|
3736
|
+
className: 'tb-btn',
|
|
3737
|
+
onClick: () => setChat(null),
|
|
3738
|
+
},
|
|
3739
|
+
t('chat.close'),
|
|
3740
|
+
),
|
|
3741
|
+
),
|
|
3742
|
+
h(
|
|
3743
|
+
'div',
|
|
3744
|
+
{ className: 'tb-ws-hint' },
|
|
3745
|
+
cardIsTail(chat.card, layout, state.data) ? t('chat.tailHint') : t('chat.branchHint'),
|
|
3746
|
+
),
|
|
3747
|
+
h(
|
|
3748
|
+
'div',
|
|
3749
|
+
{ className: 'tb-chat-messages' },
|
|
3750
|
+
chat.loading
|
|
3751
|
+
? h('div', { className: 'tb-empty tb-small' }, t('chat.loading'))
|
|
3752
|
+
: chat.messages.length > 0
|
|
3753
|
+
? chat.messages.map((message, index) =>
|
|
3754
|
+
h(
|
|
3755
|
+
'div',
|
|
3756
|
+
{ key: `msg-${index}`, className: `tb-chat-msg ${message.role}` },
|
|
3757
|
+
h('div', { className: 'tb-chat-role' }, message.role === 'user' ? t('chat.user') : t('chat.assistant')),
|
|
3758
|
+
message.role === 'assistant'
|
|
3759
|
+
? h('div', { className: 'tb-md' }, ...renderMarkdown(message.text, `chat-${index}`))
|
|
3760
|
+
: h('div', { className: 'tb-chat-text' }, message.text),
|
|
3761
|
+
),
|
|
3762
|
+
)
|
|
3763
|
+
: h('div', { className: 'tb-empty tb-small' }, chat.error || t('chat.empty')),
|
|
3764
|
+
),
|
|
3765
|
+
chat.error && !chat.loading
|
|
3766
|
+
? h('div', { className: 'tb-feedback err' }, chat.error)
|
|
3767
|
+
: null,
|
|
3768
|
+
h(
|
|
3769
|
+
'div',
|
|
3770
|
+
{ className: 'tb-chat-composer' },
|
|
3771
|
+
h('textarea', {
|
|
3772
|
+
value: chat.input,
|
|
3773
|
+
placeholder: t('chat.placeholder'),
|
|
3774
|
+
disabled: chat.sending,
|
|
3775
|
+
onChange: (event) => setChat((current) => (current ? { ...current, input: event.target.value } : current)),
|
|
3776
|
+
onKeyDown: (event) => {
|
|
3777
|
+
if (event.key === 'Enter' && !event.shiftKey) {
|
|
3778
|
+
event.preventDefault()
|
|
3779
|
+
sendChatMessage()
|
|
3780
|
+
}
|
|
3781
|
+
},
|
|
3782
|
+
}),
|
|
3783
|
+
h(
|
|
3784
|
+
'div',
|
|
3785
|
+
{ className: 'tb-chat-actions' },
|
|
3786
|
+
h(
|
|
3787
|
+
'button',
|
|
3788
|
+
{
|
|
3789
|
+
type: 'button',
|
|
3790
|
+
className: 'tb-btn',
|
|
3791
|
+
onClick: () => openSessionByCard(chat.card.sessionId),
|
|
3792
|
+
},
|
|
3793
|
+
t('chat.openSession'),
|
|
3794
|
+
),
|
|
3795
|
+
h('span', { style: { flex: 1 } }),
|
|
3796
|
+
h(
|
|
3797
|
+
'button',
|
|
3798
|
+
{
|
|
3799
|
+
type: 'button',
|
|
3800
|
+
className: 'tb-btn primary',
|
|
3801
|
+
disabled: chat.sending || String(chat.input ?? '').trim() === '',
|
|
3802
|
+
onClick: sendChatMessage,
|
|
3803
|
+
},
|
|
3804
|
+
chat.sending ? t('panel.acting') : t('chat.send'),
|
|
3805
|
+
),
|
|
3806
|
+
),
|
|
3807
|
+
),
|
|
3808
|
+
),
|
|
3809
|
+
)
|
|
3810
|
+
: null,
|
|
3124
3811
|
)
|
|
3125
3812
|
}
|
|
3126
3813
|
|
|
@@ -3319,11 +4006,10 @@ window.__ModuleLoader__.load({
|
|
|
3319
4006
|
}
|
|
3320
4007
|
|
|
3321
4008
|
/** Draw the per-workspace recording switch and the enabled-workspace list. */
|
|
3322
|
-
function renderWorkspaceSection({ workspace, gitOff, busy, t, toggleWorkspace, sessionId, onWorkspaceChanged }) {
|
|
4009
|
+
function renderWorkspaceSection({ workspace, gitOff, busy, t, toggleWorkspace, sessionId, onWorkspaceChanged, open, onToggle }) {
|
|
3323
4010
|
if (!workspace) return null
|
|
3324
4011
|
const cwd = workspace.cwd
|
|
3325
4012
|
const mode = workspace.mode
|
|
3326
|
-
const canToggle = mode === 'workspace' && !gitOff && Boolean(cwd) && workspace.exists !== false && busy === ''
|
|
3327
4013
|
const checked = mode === 'all' || workspace.enabled === true
|
|
3328
4014
|
const reason = gitOff
|
|
3329
4015
|
? t('panel.recordDisabledNoGit')
|
|
@@ -3334,37 +4020,16 @@ window.__ModuleLoader__.load({
|
|
|
3334
4020
|
: mode === 'off'
|
|
3335
4021
|
? t('panel.recordFixedOff')
|
|
3336
4022
|
: t('panel.recordThisHint')
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
{ className: 'tb-ws' },
|
|
3340
|
-
h(
|
|
3341
|
-
'div',
|
|
3342
|
-
{ className: 'tb-ws-row', title: reason },
|
|
3343
|
-
h(
|
|
3344
|
-
'span',
|
|
3345
|
-
{ className: 'tb-ws-text' },
|
|
3346
|
-
h('span', { className: 'tb-ws-title' }, t('panel.recordThis')),
|
|
3347
|
-
cwd ? h('span', { className: 'tb-ws-path', title: cwd }, cwd) : null,
|
|
3348
|
-
h('span', { className: 'tb-ws-hint' }, reason),
|
|
3349
|
-
),
|
|
3350
|
-
),
|
|
3351
|
-
mode === 'workspace' && cwd
|
|
3352
|
-
? h(WorkspacePathSelector, {
|
|
3353
|
-
sessionId,
|
|
3354
|
-
workspace,
|
|
3355
|
-
t,
|
|
3356
|
-
onChanged: typeof onWorkspaceChanged === 'function' ? onWorkspaceChanged : undefined,
|
|
3357
|
-
})
|
|
3358
|
-
: null,
|
|
3359
|
-
mode === 'workspace' && workspace.enabledWorkspaces?.length > 0
|
|
4023
|
+
const list = (items, kind) =>
|
|
4024
|
+
Array.isArray(items) && items.length > 0
|
|
3360
4025
|
? h(
|
|
3361
4026
|
'div',
|
|
3362
4027
|
{ className: 'tb-ws-list' },
|
|
3363
|
-
h('span', { className: 'tb-ws-hint' }, t('panel.enabledWorkspaces')),
|
|
3364
|
-
...
|
|
4028
|
+
h('span', { className: 'tb-ws-hint' }, kind === 'enabled' ? t('panel.enabledWorkspaces') : t('panel.excludedWorkspaces')),
|
|
4029
|
+
...items.map((entry) =>
|
|
3365
4030
|
h(
|
|
3366
4031
|
'div',
|
|
3367
|
-
{ key: entry.path, className: 'tb-ws-item' },
|
|
4032
|
+
{ key: kind + entry.path, className: 'tb-ws-item' },
|
|
3368
4033
|
h('span', { className: 'tb-ws-path', title: entry.path }, entry.path),
|
|
3369
4034
|
h(
|
|
3370
4035
|
'button',
|
|
@@ -3372,36 +4037,46 @@ window.__ModuleLoader__.load({
|
|
|
3372
4037
|
type: 'button',
|
|
3373
4038
|
className: 'tb-btn',
|
|
3374
4039
|
disabled: busy !== '',
|
|
3375
|
-
onClick: () => toggleWorkspace(
|
|
4040
|
+
onClick: () => toggleWorkspace(kind === 'excluded', entry.path),
|
|
3376
4041
|
},
|
|
3377
|
-
t('panel.disableThis'),
|
|
4042
|
+
kind === 'enabled' ? t('panel.disableThis') : t('panel.restoreThis'),
|
|
3378
4043
|
),
|
|
3379
4044
|
),
|
|
3380
4045
|
),
|
|
3381
4046
|
)
|
|
3382
|
-
: null
|
|
3383
|
-
|
|
4047
|
+
: null
|
|
4048
|
+
return h(
|
|
4049
|
+
'div',
|
|
4050
|
+
{ className: 'tb-ws' },
|
|
4051
|
+
h(
|
|
4052
|
+
'button',
|
|
4053
|
+
{
|
|
4054
|
+
type: 'button',
|
|
4055
|
+
className: 'tb-ws-summary',
|
|
4056
|
+
title: `${t('panel.workspaceSectionTitle')} · ${reason}`,
|
|
4057
|
+
'aria-expanded': open === true,
|
|
4058
|
+
onClick: typeof onToggle === 'function' ? onToggle : undefined,
|
|
4059
|
+
},
|
|
4060
|
+
h('span', { className: 'tb-ws-caret' }, open ? '▾' : '▸'),
|
|
4061
|
+
h('span', { className: 'tb-ws-title' }, t('panel.workspaceSectionTitle')),
|
|
4062
|
+
cwd ? h('span', { className: 'tb-ws-path', title: cwd }, cwd) : null,
|
|
4063
|
+
h('span', { className: `tb-chip ${checked ? 'ok' : 'warn'}` }, checked ? t('panel.recordOn') : t('panel.recordOff')),
|
|
4064
|
+
),
|
|
4065
|
+
open
|
|
3384
4066
|
? h(
|
|
3385
4067
|
'div',
|
|
3386
|
-
{ className: 'tb-ws-
|
|
3387
|
-
h('span', { className: 'tb-ws-
|
|
3388
|
-
|
|
3389
|
-
h(
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
disabled: busy !== '',
|
|
3399
|
-
onClick: () => toggleWorkspace(true, entry.path),
|
|
3400
|
-
},
|
|
3401
|
-
t('panel.restoreThis'),
|
|
3402
|
-
),
|
|
3403
|
-
),
|
|
3404
|
-
),
|
|
4068
|
+
{ className: 'tb-ws-body' },
|
|
4069
|
+
h('div', { className: 'tb-ws-row' }, h('span', { className: 'tb-ws-text' }, h('span', { className: 'tb-ws-hint' }, reason))),
|
|
4070
|
+
mode === 'workspace' && cwd
|
|
4071
|
+
? h(WorkspacePathSelector, {
|
|
4072
|
+
sessionId,
|
|
4073
|
+
workspace,
|
|
4074
|
+
t,
|
|
4075
|
+
onChanged: typeof onWorkspaceChanged === 'function' ? onWorkspaceChanged : undefined,
|
|
4076
|
+
})
|
|
4077
|
+
: null,
|
|
4078
|
+
list(workspace.enabledWorkspaces, 'enabled'),
|
|
4079
|
+
list(workspace.excludedWorkspaces, 'excluded'),
|
|
3405
4080
|
)
|
|
3406
4081
|
: null,
|
|
3407
4082
|
)
|
|
@@ -3738,28 +4413,108 @@ window.__ModuleLoader__.load({
|
|
|
3738
4413
|
return `#${rgb.map((value) => Math.min(255, Math.max(0, Math.round(Number(value) || 0))).toString(16).padStart(2, '0')).join('')}`
|
|
3739
4414
|
}
|
|
3740
4415
|
|
|
4416
|
+
/** Normalize any CSS color string (#rgb, #rrggbbaa, rgb()/rgba()) to #rrggbb. */
|
|
4417
|
+
function normalizeCssColor(value) {
|
|
4418
|
+
const raw = String(value || '').trim().toLowerCase()
|
|
4419
|
+
if (raw === '') return ''
|
|
4420
|
+
const short = /^#([0-9a-f]{3})$/.exec(raw)
|
|
4421
|
+
if (short) return `#${[...short[1]].map((char) => char + char).join('')}`
|
|
4422
|
+
const hex = /^#([0-9a-f]{6})(?:[0-9a-f]{2})?$/.exec(raw)
|
|
4423
|
+
if (hex) return `#${hex[1]}`
|
|
4424
|
+
const rgb = /^rgba?\(\s*([0-9.]+%?)[\s,]+([0-9.]+%?)[\s,]+([0-9.]+%?)/.exec(raw)
|
|
4425
|
+
if (rgb) {
|
|
4426
|
+
const channel = (part) => (part.endsWith('%') ? Math.round((parseFloat(part) * 255) / 100) : Math.round(parseFloat(part)))
|
|
4427
|
+
return rgbToHex([channel(rgb[1]), channel(rgb[2]), channel(rgb[3])])
|
|
4428
|
+
}
|
|
4429
|
+
return ''
|
|
4430
|
+
}
|
|
4431
|
+
|
|
3741
4432
|
const BOARD_ANCHORS = ['top', 'right', 'bottom', 'left']
|
|
3742
4433
|
|
|
3743
4434
|
function emptyBoardCanvas() {
|
|
3744
|
-
return { notes: {}, background: [], drawings: {}, edges: [] }
|
|
4435
|
+
return { notes: {}, background: [], drawings: {}, edges: [], texts: [], windows: [] }
|
|
3745
4436
|
}
|
|
3746
4437
|
|
|
3747
|
-
/**
|
|
3748
|
-
function
|
|
3749
|
-
const
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
4438
|
+
/** Parse CSV/TSV/Markdown-table text into a rectangular cell grid. */
|
|
4439
|
+
function parseTableText(text) {
|
|
4440
|
+
const lines = String(text ?? '')
|
|
4441
|
+
.replace(/\r\n?/g, '\n')
|
|
4442
|
+
.split('\n')
|
|
4443
|
+
while (lines.length > 0 && lines[lines.length - 1] === '') lines.pop()
|
|
4444
|
+
if (lines.length === 0) return [['']]
|
|
4445
|
+
if (lines.filter((line) => line.includes('|')).length >= 2) {
|
|
4446
|
+
const rows = []
|
|
4447
|
+
for (const line of lines) {
|
|
4448
|
+
const trimmed = line.trim()
|
|
4449
|
+
if (!trimmed.includes('|')) continue
|
|
4450
|
+
if (/^\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?$/.test(trimmed)) continue
|
|
4451
|
+
let cells = trimmed.split('|').map((cell) => cell.trim())
|
|
4452
|
+
if (cells.length > 0 && cells[0] === '') cells = cells.slice(1)
|
|
4453
|
+
if (cells.length > 0 && cells[cells.length - 1] === '') cells = cells.slice(0, -1)
|
|
4454
|
+
rows.push(cells)
|
|
4455
|
+
}
|
|
4456
|
+
if (rows.length > 0) return rows.slice(0, 50).map((row) => row.slice(0, 20))
|
|
4457
|
+
}
|
|
4458
|
+
const delimiter = lines.some((line) => line.includes('\t')) ? '\t' : ','
|
|
4459
|
+
const rows = []
|
|
4460
|
+
let row = []
|
|
4461
|
+
let cell = ''
|
|
4462
|
+
let quoted = false
|
|
4463
|
+
const pushCell = () => {
|
|
4464
|
+
row.push(cell)
|
|
4465
|
+
cell = ''
|
|
4466
|
+
}
|
|
4467
|
+
const pushRow = () => {
|
|
4468
|
+
pushCell()
|
|
4469
|
+
rows.push(row)
|
|
4470
|
+
row = []
|
|
4471
|
+
}
|
|
4472
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
4473
|
+
const char = text[index]
|
|
4474
|
+
if (quoted) {
|
|
4475
|
+
if (char === '"' && text[index + 1] === '"') {
|
|
4476
|
+
cell += '"'
|
|
4477
|
+
index += 1
|
|
4478
|
+
} else if (char === '"') quoted = false
|
|
4479
|
+
else cell += char
|
|
4480
|
+
continue
|
|
4481
|
+
}
|
|
4482
|
+
if (char === '"') quoted = true
|
|
4483
|
+
else if (char === delimiter) pushCell()
|
|
4484
|
+
else if (char === '\n') pushRow()
|
|
4485
|
+
else if (char !== '\r') cell += char
|
|
4486
|
+
}
|
|
4487
|
+
if (cell !== '' || row.length > 0) pushRow()
|
|
4488
|
+
if (rows.length === 0) return [['']]
|
|
4489
|
+
return rows.slice(0, 50).map((entry) => entry.slice(0, 20).map((value) => value.slice(0, 500)))
|
|
4490
|
+
}
|
|
4491
|
+
|
|
4492
|
+
/** Serialize a table grid back to editable TSV text. */
|
|
4493
|
+
function tableRowsToText(rows) {
|
|
4494
|
+
return (Array.isArray(rows) ? rows : []).map((row) => (Array.isArray(row) ? row : []).join('\t')).join('\n')
|
|
4495
|
+
}
|
|
4496
|
+
|
|
4497
|
+
/** Deep-copy the sticky canvas so React sees new references. */
|
|
4498
|
+
function cloneBoardCanvas(value) {
|
|
4499
|
+
const canvas = value && typeof value === 'object' ? value : {}
|
|
4500
|
+
const copyStrokes = (strokes) =>
|
|
4501
|
+
(Array.isArray(strokes) ? strokes : []).map((stroke) => ({
|
|
4502
|
+
...stroke,
|
|
4503
|
+
points: (Array.isArray(stroke.points) ? stroke.points : []).map((point) => [...point]),
|
|
4504
|
+
}))
|
|
4505
|
+
return {
|
|
4506
|
+
notes: Object.fromEntries(
|
|
4507
|
+
Object.entries(canvas.notes && typeof canvas.notes === 'object' ? canvas.notes : {}).map(([id, layout]) => [id, { ...layout }]),
|
|
3758
4508
|
),
|
|
3759
4509
|
background: copyStrokes(canvas.background),
|
|
3760
4510
|
drawings: Object.fromEntries(
|
|
3761
4511
|
Object.entries(canvas.drawings && typeof canvas.drawings === 'object' ? canvas.drawings : {}).map(([id, strokes]) => [id, copyStrokes(strokes)]),
|
|
3762
4512
|
),
|
|
4513
|
+
texts: (Array.isArray(canvas.texts) ? canvas.texts : []).map((text) => ({ ...text })),
|
|
4514
|
+
windows: (Array.isArray(canvas.windows) ? canvas.windows : []).map((window) => ({
|
|
4515
|
+
...window,
|
|
4516
|
+
...(Array.isArray(window.rows) ? { rows: window.rows.map((row) => [...row]) } : {}),
|
|
4517
|
+
})),
|
|
3763
4518
|
edges: (Array.isArray(canvas.edges) ? canvas.edges : []).map((edge) => ({
|
|
3764
4519
|
...edge,
|
|
3765
4520
|
from: { ...(edge.from ?? {}) },
|
|
@@ -3913,6 +4668,7 @@ window.__ModuleLoader__.load({
|
|
|
3913
4668
|
width: BOARD_NOTE_W,
|
|
3914
4669
|
height: BOARD_NOTE_H,
|
|
3915
4670
|
z: index,
|
|
4671
|
+
kind: 'sticky',
|
|
3916
4672
|
color: '#ffffff',
|
|
3917
4673
|
}
|
|
3918
4674
|
}
|
|
@@ -3927,7 +4683,7 @@ window.__ModuleLoader__.load({
|
|
|
3927
4683
|
|
|
3928
4684
|
/** Inline Markdown -> HTML for the rich editor. */
|
|
3929
4685
|
function inlineMarkdownToHtml(text) {
|
|
3930
|
-
const pattern = /(<span style="color:\s
|
|
4686
|
+
const pattern = /(<span style="[^"]*color:\s*(?:#[0-9a-f]{3,8}|rgba?\([^)]*\))[^"]*">[\s\S]*?<\/span>|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|~~[^~]+~~|\*[^*\n]+\*|_[^_\n]+_)/gi
|
|
3931
4687
|
let html = ''
|
|
3932
4688
|
let last = 0
|
|
3933
4689
|
let match
|
|
@@ -3935,9 +4691,10 @@ window.__ModuleLoader__.load({
|
|
|
3935
4691
|
html += escapeHtmlText(text.slice(last, match.index))
|
|
3936
4692
|
const token = match[0]
|
|
3937
4693
|
if (token.startsWith('<span')) {
|
|
3938
|
-
const span = /^<span style="color:\s*(
|
|
3939
|
-
|
|
3940
|
-
|
|
4694
|
+
const span = /^<span style="[^"]*color:\s*([^";]+)[^"]*">([\s\S]*?)<\/span>$/i.exec(token)
|
|
4695
|
+
const color = span ? normalizeCssColor(span[1]) : ''
|
|
4696
|
+
html += color
|
|
4697
|
+
? `<span style="color:${color}">${inlineMarkdownToHtml(span[2])}</span>`
|
|
3941
4698
|
: escapeHtmlText(token)
|
|
3942
4699
|
} else if (token.startsWith('**') || token.startsWith('__')) {
|
|
3943
4700
|
html += `<strong>${inlineMarkdownToHtml(token.slice(2, -2))}</strong>`
|
|
@@ -4035,14 +4792,15 @@ window.__ModuleLoader__.load({
|
|
|
4035
4792
|
const style = node.style
|
|
4036
4793
|
if (style) {
|
|
4037
4794
|
if (typeof style === 'string') {
|
|
4038
|
-
const match = /color:\s*(
|
|
4039
|
-
if (match) return match[1]
|
|
4795
|
+
const match = /color:\s*([^;]+)/i.exec(style)
|
|
4796
|
+
if (match && normalizeCssColor(match[1])) return normalizeCssColor(match[1])
|
|
4040
4797
|
} else if (typeof style.color === 'string') {
|
|
4041
|
-
|
|
4798
|
+
const normalized = normalizeCssColor(style.color)
|
|
4799
|
+
if (normalized) return normalized
|
|
4042
4800
|
}
|
|
4043
4801
|
}
|
|
4044
4802
|
const attr = node.getAttribute ? node.getAttribute('color') : ''
|
|
4045
|
-
return
|
|
4803
|
+
return normalizeCssColor(attr)
|
|
4046
4804
|
}
|
|
4047
4805
|
const inline = (node) => {
|
|
4048
4806
|
if (!node) return ''
|
|
@@ -4115,6 +4873,7 @@ window.__ModuleLoader__.load({
|
|
|
4115
4873
|
const [mode, setMode] = React.useState('rich')
|
|
4116
4874
|
const sourceRef = React.useRef(null)
|
|
4117
4875
|
const richRef = React.useRef(null)
|
|
4876
|
+
const richRangeRef = React.useRef(null)
|
|
4118
4877
|
const lastMarkdownRef = React.useRef(null)
|
|
4119
4878
|
const valueRef = React.useRef(value)
|
|
4120
4879
|
valueRef.current = value
|
|
@@ -4129,7 +4888,21 @@ window.__ModuleLoader__.load({
|
|
|
4129
4888
|
lastMarkdownRef.current = valueRef.current
|
|
4130
4889
|
}, [])
|
|
4131
4890
|
|
|
4891
|
+
const rememberRichSelection = () => {
|
|
4892
|
+
const element = richRef.current
|
|
4893
|
+
if (!element) return
|
|
4894
|
+
try {
|
|
4895
|
+
const selection = window.getSelection()
|
|
4896
|
+
if (!selection || selection.rangeCount === 0) return
|
|
4897
|
+
const range = selection.getRangeAt(0)
|
|
4898
|
+
if (element.contains(range.commonAncestorContainer)) richRangeRef.current = range.cloneRange()
|
|
4899
|
+
} catch {
|
|
4900
|
+
// Selection APIs can be unavailable in tests.
|
|
4901
|
+
}
|
|
4902
|
+
}
|
|
4903
|
+
|
|
4132
4904
|
const syncRich = () => {
|
|
4905
|
+
rememberRichSelection()
|
|
4133
4906
|
if (composingRef.current) return
|
|
4134
4907
|
const element = richRef.current
|
|
4135
4908
|
if (!element) return
|
|
@@ -4148,11 +4921,18 @@ window.__ModuleLoader__.load({
|
|
|
4148
4921
|
const element = richRef.current
|
|
4149
4922
|
if (!element) return
|
|
4150
4923
|
try {
|
|
4151
|
-
element.focus()
|
|
4924
|
+
element.focus({ preventScroll: true })
|
|
4925
|
+
const range = richRangeRef.current
|
|
4926
|
+
if (range) {
|
|
4927
|
+
const selection = window.getSelection()
|
|
4928
|
+
selection.removeAllRanges()
|
|
4929
|
+
selection.addRange(range)
|
|
4930
|
+
}
|
|
4152
4931
|
document.execCommand(command, false, argument)
|
|
4153
4932
|
} catch {
|
|
4154
4933
|
// execCommand can be unavailable; the source tab still works.
|
|
4155
4934
|
}
|
|
4935
|
+
rememberRichSelection()
|
|
4156
4936
|
syncRich()
|
|
4157
4937
|
}
|
|
4158
4938
|
|
|
@@ -4263,7 +5043,19 @@ window.__ModuleLoader__.load({
|
|
|
4263
5043
|
'div',
|
|
4264
5044
|
{ className: 'tb-md-tools' },
|
|
4265
5045
|
...tools.map((tool) =>
|
|
4266
|
-
h(
|
|
5046
|
+
h(
|
|
5047
|
+
'button',
|
|
5048
|
+
{
|
|
5049
|
+
key: tool.key,
|
|
5050
|
+
type: 'button',
|
|
5051
|
+
className: 'tb-md-tool',
|
|
5052
|
+
title: tool.title,
|
|
5053
|
+
disabled,
|
|
5054
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
5055
|
+
onClick: tool.run,
|
|
5056
|
+
},
|
|
5057
|
+
tool.label,
|
|
5058
|
+
),
|
|
4267
5059
|
),
|
|
4268
5060
|
),
|
|
4269
5061
|
h(
|
|
@@ -4290,6 +5082,7 @@ window.__ModuleLoader__.load({
|
|
|
4290
5082
|
title: color,
|
|
4291
5083
|
style: { background: color },
|
|
4292
5084
|
disabled,
|
|
5085
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
4293
5086
|
onClick: () => applyColor(color),
|
|
4294
5087
|
}),
|
|
4295
5088
|
),
|
|
@@ -4321,8 +5114,12 @@ window.__ModuleLoader__.load({
|
|
|
4321
5114
|
'aria-multiline': 'true',
|
|
4322
5115
|
'data-placeholder': props?.placeholder || '',
|
|
4323
5116
|
onInput: syncRich,
|
|
5117
|
+
onMouseUp: rememberRichSelection,
|
|
4324
5118
|
onBlur: syncRich,
|
|
4325
|
-
onKeyUp:
|
|
5119
|
+
onKeyUp: () => {
|
|
5120
|
+
rememberRichSelection()
|
|
5121
|
+
syncRich()
|
|
5122
|
+
},
|
|
4326
5123
|
onCompositionStart: () => {
|
|
4327
5124
|
composingRef.current = true
|
|
4328
5125
|
},
|
|
@@ -4443,6 +5240,10 @@ window.__ModuleLoader__.load({
|
|
|
4443
5240
|
const selectedRef = React.useRef(selected)
|
|
4444
5241
|
selectedRef.current = selected
|
|
4445
5242
|
const [readerId, setReaderId] = React.useState('')
|
|
5243
|
+
const [textEditor, setTextEditor] = React.useState(null)
|
|
5244
|
+
const [windowEditor, setWindowEditor] = React.useState(null)
|
|
5245
|
+
const [insertMenu, setInsertMenu] = React.useState(false)
|
|
5246
|
+
const [notice, setNotice] = React.useState(null)
|
|
4446
5247
|
const [linkPreview, setLinkPreview] = React.useState(null)
|
|
4447
5248
|
const [zoom, setZoom] = React.useState(1)
|
|
4448
5249
|
const zoomRef = React.useRef(zoom)
|
|
@@ -4477,7 +5278,7 @@ window.__ModuleLoader__.load({
|
|
|
4477
5278
|
} catch (error) {
|
|
4478
5279
|
setState((previous) => ({ ...previous, loading: false, error: error?.message || String(error) }))
|
|
4479
5280
|
}
|
|
4480
|
-
}, [])
|
|
5281
|
+
}, [boardSessionId])
|
|
4481
5282
|
|
|
4482
5283
|
React.useEffect(() => {
|
|
4483
5284
|
refresh()
|
|
@@ -4590,6 +5391,17 @@ window.__ModuleLoader__.load({
|
|
|
4590
5391
|
}
|
|
4591
5392
|
addStrokes(canvasRef.current.background)
|
|
4592
5393
|
for (const strokes of Object.values(canvasRef.current.drawings ?? {})) addStrokes(strokes)
|
|
5394
|
+
for (const item of canvasRef.current.windows ?? []) {
|
|
5395
|
+
include(Number(item.x) || 0, Number(item.y) || 0)
|
|
5396
|
+
include((Number(item.x) || 0) + (Number(item.width) || 480), (Number(item.y) || 0) + (Number(item.height) || 260))
|
|
5397
|
+
}
|
|
5398
|
+
for (const item of canvasRef.current.texts ?? []) {
|
|
5399
|
+
const width = Math.min(1200, Math.max(80, Number(item.width) || 320))
|
|
5400
|
+
const lines = String(item.text || '').split(String.fromCharCode(10)).length
|
|
5401
|
+
const height = Math.max(24, lines * (Number(item.fontSize) || 18) * 1.45)
|
|
5402
|
+
include(Number(item.x) || 0, Number(item.y) || 0)
|
|
5403
|
+
include((Number(item.x) || 0) + width, (Number(item.y) || 0) + height)
|
|
5404
|
+
}
|
|
4593
5405
|
if (!Number.isFinite(minX)) {
|
|
4594
5406
|
minX = BOARD_STAGE_W / 2 - 300
|
|
4595
5407
|
maxX = BOARD_STAGE_W / 2 + 300
|
|
@@ -4703,10 +5515,17 @@ window.__ModuleLoader__.load({
|
|
|
4703
5515
|
const sortedEntries = [...entries].sort((left, right) => (right.updatedAt ?? 0) - (left.updatedAt ?? 0))
|
|
4704
5516
|
const boardVersion = state.board?.version ?? 0
|
|
4705
5517
|
const layoutFor = (entry, index) => canvas.notes[entry.id] ?? autoBoardLayout(index)
|
|
4706
|
-
const noteSize = (layout) =>
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
5518
|
+
const noteSize = (layout) => {
|
|
5519
|
+
const doc = layout?.kind === 'doc'
|
|
5520
|
+
return {
|
|
5521
|
+
width: doc
|
|
5522
|
+
? Math.min(1200, Math.max(320, Number(layout?.width) || 560))
|
|
5523
|
+
: Math.min(640, Math.max(160, Number(layout?.width) || BOARD_NOTE_W)),
|
|
5524
|
+
height: doc
|
|
5525
|
+
? Math.min(900, Math.max(200, Number(layout?.height) || 420))
|
|
5526
|
+
: Math.min(560, Math.max(120, Number(layout?.height) || BOARD_NOTE_H)),
|
|
5527
|
+
}
|
|
5528
|
+
}
|
|
4710
5529
|
/** Viewport client point -> unscaled stage coordinates. */
|
|
4711
5530
|
const stagePoint = (event) => {
|
|
4712
5531
|
const stage = stageRef.current
|
|
@@ -4754,7 +5573,7 @@ window.__ModuleLoader__.load({
|
|
|
4754
5573
|
const stage = stageRef.current
|
|
4755
5574
|
return stage ? { layer: 'background', noteId: '', rect: stage.getBoundingClientRect() } : null
|
|
4756
5575
|
}
|
|
4757
|
-
const startCreate = () => setDraft({ id: '', title: '', body: '', preview: false, busy: false, error: null, color: '#ffffff' })
|
|
5576
|
+
const startCreate = (kind = 'sticky') => setDraft({ id: '', title: '', body: '', preview: false, busy: false, error: null, color: '#ffffff', kind })
|
|
4758
5577
|
const startEdit = (entry) =>
|
|
4759
5578
|
setDraft({
|
|
4760
5579
|
id: entry.id,
|
|
@@ -4764,6 +5583,7 @@ window.__ModuleLoader__.load({
|
|
|
4764
5583
|
busy: false,
|
|
4765
5584
|
error: null,
|
|
4766
5585
|
color: canvasRef.current.notes[entry.id]?.color || '#ffffff',
|
|
5586
|
+
kind: entry.kind === 'doc' ? 'doc' : 'sticky',
|
|
4767
5587
|
})
|
|
4768
5588
|
const closeDraft = () => {
|
|
4769
5589
|
if (draft && !draft.busy) setDraft(null)
|
|
@@ -4791,7 +5611,7 @@ window.__ModuleLoader__.load({
|
|
|
4791
5611
|
try {
|
|
4792
5612
|
const body = await request('action', {
|
|
4793
5613
|
method: 'POST',
|
|
4794
|
-
body: boardScope({ action: 'note-save', ...(draft.id ? { id: draft.id } : {}), title: draft.title, body: draft.body }),
|
|
5614
|
+
body: boardScope({ action: 'note-save', ...(draft.id ? { id: draft.id } : {}), title: draft.title, body: draft.body, kind: draft.kind === 'doc' ? 'doc' : 'sticky' }),
|
|
4795
5615
|
})
|
|
4796
5616
|
let board = body.board ?? state.board
|
|
4797
5617
|
setState({ loading: false, board, error: null })
|
|
@@ -4800,11 +5620,15 @@ window.__ModuleLoader__.load({
|
|
|
4800
5620
|
// the visible sticky and the stored layout can never disagree.
|
|
4801
5621
|
if (!draft.id && body.entry?.id && board && !canvasRef.current.notes[body.entry.id]) {
|
|
4802
5622
|
const index = Math.max(0, (board.entries?.length ?? 1) - 1)
|
|
5623
|
+
const isDoc = draft.kind === 'doc' || body.entry?.kind === 'doc'
|
|
5624
|
+
const base = autoBoardLayout(index)
|
|
4803
5625
|
const layoutBody = await saveCanvasNow({
|
|
4804
5626
|
...canvasRef.current,
|
|
4805
5627
|
notes: {
|
|
4806
5628
|
...canvasRef.current.notes,
|
|
4807
|
-
[body.entry.id]:
|
|
5629
|
+
[body.entry.id]: isDoc
|
|
5630
|
+
? { ...base, kind: 'doc', width: 560, height: 420, color: draft.color || '#ffffff' }
|
|
5631
|
+
: { ...base, kind: 'sticky', color: draft.color || '#ffffff' },
|
|
4808
5632
|
},
|
|
4809
5633
|
})
|
|
4810
5634
|
board = layoutBody?.board ?? board
|
|
@@ -4813,7 +5637,11 @@ window.__ModuleLoader__.load({
|
|
|
4813
5637
|
...canvasRef.current,
|
|
4814
5638
|
notes: {
|
|
4815
5639
|
...canvasRef.current.notes,
|
|
4816
|
-
[draft.id]: {
|
|
5640
|
+
[draft.id]: {
|
|
5641
|
+
...canvasRef.current.notes[draft.id],
|
|
5642
|
+
kind: draft.kind === 'doc' ? 'doc' : 'sticky',
|
|
5643
|
+
color: draft.color || '#ffffff',
|
|
5644
|
+
},
|
|
4817
5645
|
},
|
|
4818
5646
|
})
|
|
4819
5647
|
board = layoutBody?.board ?? board
|
|
@@ -4824,6 +5652,233 @@ window.__ModuleLoader__.load({
|
|
|
4824
5652
|
setDraft({ ...draft, busy: false, error: error?.message || String(error) })
|
|
4825
5653
|
}
|
|
4826
5654
|
}
|
|
5655
|
+
/** Stage point at the centre of the current viewport (used for new text). */
|
|
5656
|
+
const viewportStageCenter = () => {
|
|
5657
|
+
const viewport = viewportRef.current
|
|
5658
|
+
const stage = stageRef.current
|
|
5659
|
+
if (!viewport || !stage) return [180, 160]
|
|
5660
|
+
const rect = stage.getBoundingClientRect()
|
|
5661
|
+
return [
|
|
5662
|
+
Math.round((viewport.scrollLeft + viewport.clientWidth / 2 - rect.left) / zoomScale()),
|
|
5663
|
+
Math.round((viewport.scrollTop + viewport.clientHeight / 2 - rect.top) / zoomScale()),
|
|
5664
|
+
]
|
|
5665
|
+
}
|
|
5666
|
+
|
|
5667
|
+
const startAddText = () => {
|
|
5668
|
+
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 })
|
|
5670
|
+
}
|
|
5671
|
+
|
|
5672
|
+
const startEditText = (item) => {
|
|
5673
|
+
if (!item) return
|
|
5674
|
+
setTextEditor({ ...item })
|
|
5675
|
+
}
|
|
5676
|
+
|
|
5677
|
+
const saveText = async () => {
|
|
5678
|
+
const editor = textEditor
|
|
5679
|
+
if (!editor) return
|
|
5680
|
+
const text = String(editor.text ?? '').trim()
|
|
5681
|
+
if (text === '') {
|
|
5682
|
+
if (editor.id) await deleteText(editor.id)
|
|
5683
|
+
else setTextEditor(null)
|
|
5684
|
+
return
|
|
5685
|
+
}
|
|
5686
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
5687
|
+
let id = editor.id
|
|
5688
|
+
if (!id) id = `tx-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`
|
|
5689
|
+
const item = {
|
|
5690
|
+
id,
|
|
5691
|
+
text,
|
|
5692
|
+
x: Math.max(0, Number(editor.x) || 0),
|
|
5693
|
+
y: Math.max(0, Number(editor.y) || 0),
|
|
5694
|
+
width: Math.min(1200, Math.max(80, Number(editor.width) || 320)),
|
|
5695
|
+
color: /^#[0-9a-f]{6}$/i.test(String(editor.color || '')) ? String(editor.color).toLowerCase() : '#e6e6e6',
|
|
5696
|
+
fontSize: Math.min(96, Math.max(8, Number(editor.fontSize) || 18)),
|
|
5697
|
+
}
|
|
5698
|
+
next.texts = [...(next.texts ?? []).filter((entry) => entry.id !== id), item]
|
|
5699
|
+
try {
|
|
5700
|
+
await saveCanvasNow(next)
|
|
5701
|
+
} catch (error) {
|
|
5702
|
+
setTextEditor({ ...editor, error: error?.message || String(error) })
|
|
5703
|
+
return
|
|
5704
|
+
}
|
|
5705
|
+
setSelected(id)
|
|
5706
|
+
setTextEditor(null)
|
|
5707
|
+
}
|
|
5708
|
+
|
|
5709
|
+
const deleteText = async (id) => {
|
|
5710
|
+
if (!id) return
|
|
5711
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
5712
|
+
next.texts = (next.texts ?? []).filter((entry) => entry.id !== id)
|
|
5713
|
+
try {
|
|
5714
|
+
await saveCanvasNow(next)
|
|
5715
|
+
} catch {
|
|
5716
|
+
// The text stays visible if the save fails.
|
|
5717
|
+
return
|
|
5718
|
+
}
|
|
5719
|
+
if (selectedRef.current === id) setSelected('')
|
|
5720
|
+
setTextEditor(null)
|
|
5721
|
+
}
|
|
5722
|
+
|
|
5723
|
+
const emptyTableRows = (rows = 3, cols = 3) =>
|
|
5724
|
+
Array.from({ length: Math.max(1, rows) }, () => Array.from({ length: Math.max(1, cols) }, () => ''))
|
|
5725
|
+
|
|
5726
|
+
const startAddTable = (rows = 3, cols = 3) => {
|
|
5727
|
+
const [cx, cy] = viewportStageCenter()
|
|
5728
|
+
setInsertMenu(false)
|
|
5729
|
+
setWindowEditor({
|
|
5730
|
+
id: '',
|
|
5731
|
+
kind: 'table',
|
|
5732
|
+
title: '表格',
|
|
5733
|
+
rows: emptyTableRows(rows, cols),
|
|
5734
|
+
width: 500,
|
|
5735
|
+
height: 300,
|
|
5736
|
+
x: Math.max(0, cx - 250),
|
|
5737
|
+
y: Math.max(0, cy - 150),
|
|
5738
|
+
busy: false,
|
|
5739
|
+
error: null,
|
|
5740
|
+
})
|
|
5741
|
+
}
|
|
5742
|
+
|
|
5743
|
+
const pickFile = (accept, onFile) => {
|
|
5744
|
+
try {
|
|
5745
|
+
const input = document.createElement('input')
|
|
5746
|
+
input.type = 'file'
|
|
5747
|
+
input.accept = accept
|
|
5748
|
+
input.style.display = 'none'
|
|
5749
|
+
input.addEventListener('change', () => {
|
|
5750
|
+
const file = input.files?.[0]
|
|
5751
|
+
if (file) onFile(file)
|
|
5752
|
+
})
|
|
5753
|
+
input.click()
|
|
5754
|
+
} catch (error) {
|
|
5755
|
+
setState((previous) => ({ ...previous, error: error?.message || String(error) }))
|
|
5756
|
+
}
|
|
5757
|
+
}
|
|
5758
|
+
|
|
5759
|
+
const startImportTable = () => {
|
|
5760
|
+
setInsertMenu(false)
|
|
5761
|
+
pickFile('.csv,.tsv,.txt,.md,text/csv,text/tab-separated-values,text/plain,text/markdown', (file) => {
|
|
5762
|
+
if (file.size > 2_000_000) {
|
|
5763
|
+
setState((previous) => ({ ...previous, error: '表格文件过大' }))
|
|
5764
|
+
return
|
|
5765
|
+
}
|
|
5766
|
+
const reader = new FileReader()
|
|
5767
|
+
reader.onload = () => {
|
|
5768
|
+
const rows = parseTableText(String(reader.result ?? ''))
|
|
5769
|
+
const [cx, cy] = viewportStageCenter()
|
|
5770
|
+
setWindowEditor({
|
|
5771
|
+
id: '',
|
|
5772
|
+
kind: 'table',
|
|
5773
|
+
title: file.name.replace(/\.[^.]+$/, '') || '导入表格',
|
|
5774
|
+
rows,
|
|
5775
|
+
width: Math.min(900, Math.max(420, (rows[0]?.length ?? 3) * 120)),
|
|
5776
|
+
height: Math.min(700, Math.max(220, rows.length * 34 + 44)),
|
|
5777
|
+
x: Math.max(0, cx - 250),
|
|
5778
|
+
y: Math.max(0, cy - 150),
|
|
5779
|
+
busy: false,
|
|
5780
|
+
error: null,
|
|
5781
|
+
})
|
|
5782
|
+
}
|
|
5783
|
+
reader.onerror = () => setState((previous) => ({ ...previous, error: '表格读取失败' }))
|
|
5784
|
+
reader.readAsText(file)
|
|
5785
|
+
})
|
|
5786
|
+
}
|
|
5787
|
+
|
|
5788
|
+
const startImportImage = () => {
|
|
5789
|
+
setInsertMenu(false)
|
|
5790
|
+
pickFile('image/*', (file) => {
|
|
5791
|
+
if (!/^image\//i.test(file.type)) {
|
|
5792
|
+
setState((previous) => ({ ...previous, error: '请选择图片文件' }))
|
|
5793
|
+
return
|
|
5794
|
+
}
|
|
5795
|
+
if (file.size > 1_500_000) {
|
|
5796
|
+
setState((previous) => ({ ...previous, error: '图片过大(上限约 1.5MB)' }))
|
|
5797
|
+
return
|
|
5798
|
+
}
|
|
5799
|
+
const reader = new FileReader()
|
|
5800
|
+
reader.onload = () => {
|
|
5801
|
+
const [cx, cy] = viewportStageCenter()
|
|
5802
|
+
setWindowEditor({
|
|
5803
|
+
id: '',
|
|
5804
|
+
kind: 'image',
|
|
5805
|
+
title: file.name.replace(/\.[^.]+$/, '') || '图片',
|
|
5806
|
+
src: String(reader.result ?? ''),
|
|
5807
|
+
alt: file.name,
|
|
5808
|
+
width: 380,
|
|
5809
|
+
height: 280,
|
|
5810
|
+
x: Math.max(0, cx - 190),
|
|
5811
|
+
y: Math.max(0, cy - 140),
|
|
5812
|
+
busy: false,
|
|
5813
|
+
error: null,
|
|
5814
|
+
})
|
|
5815
|
+
}
|
|
5816
|
+
reader.onerror = () => setState((previous) => ({ ...previous, error: '图片读取失败' }))
|
|
5817
|
+
reader.readAsDataURL(file)
|
|
5818
|
+
})
|
|
5819
|
+
}
|
|
5820
|
+
|
|
5821
|
+
const startEditWindow = (item) => {
|
|
5822
|
+
if (!item) return
|
|
5823
|
+
setWindowEditor({
|
|
5824
|
+
...item,
|
|
5825
|
+
rows: Array.isArray(item.rows) ? item.rows.map((row) => [...row]) : item.rows,
|
|
5826
|
+
busy: false,
|
|
5827
|
+
error: null,
|
|
5828
|
+
})
|
|
5829
|
+
}
|
|
5830
|
+
|
|
5831
|
+
const saveWindow = async () => {
|
|
5832
|
+
const editor = windowEditor
|
|
5833
|
+
if (!editor) return
|
|
5834
|
+
const title = String(editor.title ?? '').trim() || (editor.kind === 'table' ? '表格' : '图片')
|
|
5835
|
+
if (editor.kind === 'image' && !editor.src) {
|
|
5836
|
+
setWindowEditor({ ...editor, error: '请先选择图片' })
|
|
5837
|
+
return
|
|
5838
|
+
}
|
|
5839
|
+
let rows = editor.rows
|
|
5840
|
+
if (editor.kind === 'table') {
|
|
5841
|
+
rows = (Array.isArray(editor.rows) ? editor.rows : [[]]).slice(0, 50).map((row) =>
|
|
5842
|
+
(Array.isArray(row) ? row : []).slice(0, 20).map((cell) => String(cell ?? '').slice(0, 500)),
|
|
5843
|
+
)
|
|
5844
|
+
if (rows.length === 0) rows = [['']]
|
|
5845
|
+
}
|
|
5846
|
+
const id = editor.id || `win-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`
|
|
5847
|
+
const item = {
|
|
5848
|
+
id,
|
|
5849
|
+
kind: editor.kind,
|
|
5850
|
+
title,
|
|
5851
|
+
x: Math.max(0, Number(editor.x) || 0),
|
|
5852
|
+
y: Math.max(0, Number(editor.y) || 0),
|
|
5853
|
+
width: Math.min(1600, Math.max(160, Number(editor.width) || (editor.kind === 'image' ? 380 : 500))),
|
|
5854
|
+
height: Math.min(1200, Math.max(120, Number(editor.height) || 280)),
|
|
5855
|
+
...(editor.kind === 'table' ? { rows } : { src: editor.src, alt: editor.alt || title }),
|
|
5856
|
+
}
|
|
5857
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
5858
|
+
next.windows = [...(next.windows ?? []).filter((entry) => entry.id !== id), item]
|
|
5859
|
+
try {
|
|
5860
|
+
await saveCanvasNow(next)
|
|
5861
|
+
} catch (error) {
|
|
5862
|
+
setWindowEditor({ ...editor, busy: false, error: error?.message || String(error) })
|
|
5863
|
+
return
|
|
5864
|
+
}
|
|
5865
|
+
setSelected(id)
|
|
5866
|
+
setWindowEditor(null)
|
|
5867
|
+
}
|
|
5868
|
+
|
|
5869
|
+
const deleteWindow = async (id) => {
|
|
5870
|
+
if (!id) return
|
|
5871
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
5872
|
+
next.windows = (next.windows ?? []).filter((entry) => entry.id !== id)
|
|
5873
|
+
try {
|
|
5874
|
+
await saveCanvasNow(next)
|
|
5875
|
+
} catch {
|
|
5876
|
+
return
|
|
5877
|
+
}
|
|
5878
|
+
if (selectedRef.current === id) setSelected('')
|
|
5879
|
+
setWindowEditor(null)
|
|
5880
|
+
}
|
|
5881
|
+
|
|
4827
5882
|
const removeEntry = async (id) => {
|
|
4828
5883
|
if (!id || busy !== '') return
|
|
4829
5884
|
let confirmed = true
|
|
@@ -4939,10 +5994,51 @@ window.__ModuleLoader__.load({
|
|
|
4939
5994
|
}
|
|
4940
5995
|
return
|
|
4941
5996
|
}
|
|
5997
|
+
if (current.type === 'window-drag') {
|
|
5998
|
+
const scale = zoomScale()
|
|
5999
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
6000
|
+
const item = (next.windows ?? []).find((entry) => entry.id === current.windowId)
|
|
6001
|
+
if (item) {
|
|
6002
|
+
item.x = Math.max(0, Math.min(BOARD_STAGE_W - (Number(item.width) || 480), current.originX + (event.clientX - current.startX) / scale))
|
|
6003
|
+
item.y = Math.max(0, Math.min(BOARD_STAGE_H - 80, current.originY + (event.clientY - current.startY) / scale))
|
|
6004
|
+
next.windows = (next.windows ?? []).map((entry) => (entry.id === item.id ? item : entry))
|
|
6005
|
+
canvasRef.current = next
|
|
6006
|
+
setCanvas(next)
|
|
6007
|
+
}
|
|
6008
|
+
return
|
|
6009
|
+
}
|
|
6010
|
+
if (current.type === 'window-resize') {
|
|
6011
|
+
const scale = zoomScale()
|
|
6012
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
6013
|
+
const item = (next.windows ?? []).find((entry) => entry.id === current.windowId)
|
|
6014
|
+
if (item) {
|
|
6015
|
+
item.width = Math.min(1600, Math.max(160, Math.round(current.startW + (event.clientX - current.startX) / scale)))
|
|
6016
|
+
item.height = Math.min(1200, Math.max(120, Math.round(current.startH + (event.clientY - current.startY) / scale)))
|
|
6017
|
+
next.windows = (next.windows ?? []).map((entry) => (entry.id === item.id ? item : entry))
|
|
6018
|
+
canvasRef.current = next
|
|
6019
|
+
setCanvas(next)
|
|
6020
|
+
}
|
|
6021
|
+
return
|
|
6022
|
+
}
|
|
6023
|
+
if (current.type === 'text-drag') {
|
|
6024
|
+
const scale = zoomScale()
|
|
6025
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
6026
|
+
const item = (next.texts ?? []).find((entry) => entry.id === current.textId)
|
|
6027
|
+
if (item) {
|
|
6028
|
+
item.x = Math.max(0, Math.min(BOARD_STAGE_W - (Number(item.width) || 320), current.originX + (event.clientX - current.startX) / scale))
|
|
6029
|
+
item.y = Math.max(0, Math.min(BOARD_STAGE_H - 40, current.originY + (event.clientY - current.startY) / scale))
|
|
6030
|
+
next.texts = (next.texts ?? []).map((entry) => (entry.id === item.id ? item : entry))
|
|
6031
|
+
canvasRef.current = next
|
|
6032
|
+
setCanvas(next)
|
|
6033
|
+
}
|
|
6034
|
+
return
|
|
6035
|
+
}
|
|
4942
6036
|
if (current.type === 'resize') {
|
|
4943
6037
|
const scale = zoomScale()
|
|
4944
|
-
const
|
|
4945
|
-
const
|
|
6038
|
+
const currentLayout = canvasRef.current.notes[current.noteId] ?? autoBoardLayout(0)
|
|
6039
|
+
const doc = currentLayout.kind === 'doc'
|
|
6040
|
+
const width = Math.min(doc ? 1200 : 640, Math.max(doc ? 320 : 160, Math.round(current.startW + (event.clientX - current.startX) / scale)))
|
|
6041
|
+
const height = Math.min(doc ? 900 : 560, Math.max(doc ? 200 : 120, Math.round(current.startH + (event.clientY - current.startY) / scale)))
|
|
4946
6042
|
const next = cloneBoardCanvas(canvasRef.current)
|
|
4947
6043
|
const layout = next.notes[current.noteId] ?? autoBoardLayout(0)
|
|
4948
6044
|
layout.width = width
|
|
@@ -4972,8 +6068,7 @@ window.__ModuleLoader__.load({
|
|
|
4972
6068
|
const under = layerAt(event)
|
|
4973
6069
|
const changed =
|
|
4974
6070
|
under &&
|
|
4975
|
-
(under.layer !== current.layer || (under.layer === 'note' && under.noteId !== current.noteId))
|
|
4976
|
-
!(under.layer === 'note' && !drawOnStickyRef.current)
|
|
6071
|
+
(under.layer !== current.layer || (under.layer === 'note' && under.noteId !== current.noteId))
|
|
4977
6072
|
if (changed) {
|
|
4978
6073
|
const previous = current.lastWorld ?? [event.clientX, event.clientY]
|
|
4979
6074
|
const crossScale = zoomScale()
|
|
@@ -5033,8 +6128,7 @@ window.__ModuleLoader__.load({
|
|
|
5033
6128
|
const underShape = layerAt(event)
|
|
5034
6129
|
const shapeChanged =
|
|
5035
6130
|
underShape &&
|
|
5036
|
-
(underShape.layer !== current.layer || (underShape.layer === 'note' && underShape.noteId !== current.noteId))
|
|
5037
|
-
!(underShape.layer === 'note' && !drawOnStickyRef.current)
|
|
6131
|
+
(underShape.layer !== current.layer || (underShape.layer === 'note' && underShape.noteId !== current.noteId))
|
|
5038
6132
|
if (shapeChanged) {
|
|
5039
6133
|
const startWorld = current.startWorld ?? [event.clientX, event.clientY]
|
|
5040
6134
|
const next = cloneBoardCanvas(canvasRef.current)
|
|
@@ -5151,6 +6245,59 @@ window.__ModuleLoader__.load({
|
|
|
5151
6245
|
if (event.target?.closest?.('button') || event.target?.closest?.('.tb-sticky-linkline') || event.target?.closest?.('.tb-sticky-actions')) return
|
|
5152
6246
|
const stage = stageRef.current
|
|
5153
6247
|
if (!stage) return
|
|
6248
|
+
const windowElement = event.target?.closest?.('.tb-board-window')
|
|
6249
|
+
const windowId = windowElement?.getAttribute?.('data-window-id') || ''
|
|
6250
|
+
if (windowId) {
|
|
6251
|
+
if (toolRef.current !== 'select') return
|
|
6252
|
+
if (event.target?.closest?.('.tb-board-window-body')) {
|
|
6253
|
+
setSelected(windowId)
|
|
6254
|
+
return
|
|
6255
|
+
}
|
|
6256
|
+
event.preventDefault()
|
|
6257
|
+
setSelected(windowId)
|
|
6258
|
+
const item = (canvasRef.current.windows ?? []).find((entry) => entry.id === windowId)
|
|
6259
|
+
if (item) {
|
|
6260
|
+
if (event.target?.closest?.('.tb-board-window-resize')) {
|
|
6261
|
+
setGesture({
|
|
6262
|
+
type: 'window-resize',
|
|
6263
|
+
windowId,
|
|
6264
|
+
startX: event.clientX,
|
|
6265
|
+
startY: event.clientY,
|
|
6266
|
+
startW: Number(item.width) || 480,
|
|
6267
|
+
startH: Number(item.height) || 260,
|
|
6268
|
+
})
|
|
6269
|
+
} else {
|
|
6270
|
+
setGesture({
|
|
6271
|
+
type: 'window-drag',
|
|
6272
|
+
windowId,
|
|
6273
|
+
startX: event.clientX,
|
|
6274
|
+
startY: event.clientY,
|
|
6275
|
+
originX: Number(item.x) || 0,
|
|
6276
|
+
originY: Number(item.y) || 0,
|
|
6277
|
+
})
|
|
6278
|
+
}
|
|
6279
|
+
}
|
|
6280
|
+
return
|
|
6281
|
+
}
|
|
6282
|
+
const textElement = event.target?.closest?.('.tb-board-text')
|
|
6283
|
+
const textId = textElement?.getAttribute?.('data-text-id') || ''
|
|
6284
|
+
if (textId && toolRef.current === 'select') {
|
|
6285
|
+
event.preventDefault()
|
|
6286
|
+
setSelected(textId)
|
|
6287
|
+
const item = (canvasRef.current.texts ?? []).find((entry) => entry.id === textId)
|
|
6288
|
+
if (item) {
|
|
6289
|
+
setGesture({
|
|
6290
|
+
type: 'text-drag',
|
|
6291
|
+
textId,
|
|
6292
|
+
startX: event.clientX,
|
|
6293
|
+
startY: event.clientY,
|
|
6294
|
+
originX: Number(item.x) || 0,
|
|
6295
|
+
originY: Number(item.y) || 0,
|
|
6296
|
+
})
|
|
6297
|
+
}
|
|
6298
|
+
return
|
|
6299
|
+
}
|
|
6300
|
+
if (event.target?.closest?.('.tb-doc-body') && toolRef.current === 'select') return
|
|
5154
6301
|
const noteElement = event.target?.closest?.('.tb-sticky')
|
|
5155
6302
|
const noteId = noteElement?.getAttribute?.('data-note-id') || ''
|
|
5156
6303
|
if (toolRef.current === 'link') {
|
|
@@ -5208,10 +6355,13 @@ window.__ModuleLoader__.load({
|
|
|
5208
6355
|
return
|
|
5209
6356
|
}
|
|
5210
6357
|
if (noteId && !drawOnStickyRef.current) {
|
|
5211
|
-
//
|
|
5212
|
-
//
|
|
6358
|
+
// Keep the user's "draw on stickies" choice off; explain why the
|
|
6359
|
+
// stroke did not start with a small light toast instead.
|
|
5213
6360
|
event.preventDefault()
|
|
5214
6361
|
setSelected(noteId)
|
|
6362
|
+
const message = t('board.drawOnStickyNotice')
|
|
6363
|
+
setNotice(message)
|
|
6364
|
+
window.setTimeout(() => setNotice((current) => (current === message ? null : current)), 3600)
|
|
5215
6365
|
return
|
|
5216
6366
|
}
|
|
5217
6367
|
event.preventDefault()
|
|
@@ -5413,11 +6563,12 @@ window.__ModuleLoader__.load({
|
|
|
5413
6563
|
const layout = layoutFor(entry, index)
|
|
5414
6564
|
const size = noteSize(layout)
|
|
5415
6565
|
const agent = entry.source === 'agent'
|
|
6566
|
+
const isDoc = entry.kind === 'doc' || layout.kind === 'doc'
|
|
5416
6567
|
return h(
|
|
5417
6568
|
'article',
|
|
5418
6569
|
{
|
|
5419
6570
|
key: entry.id,
|
|
5420
|
-
className: `tb-sticky${agent ? ' link' : ''}${selected === entry.id ? ' selected' : ''}`,
|
|
6571
|
+
className: `tb-sticky${isDoc ? ' tb-doc' : ''}${agent && !isDoc ? ' link' : ''}${selected === entry.id ? ' selected' : ''}`,
|
|
5421
6572
|
'data-note-id': entry.id,
|
|
5422
6573
|
style: {
|
|
5423
6574
|
left: Number(layout.x) || 0,
|
|
@@ -5435,16 +6586,25 @@ window.__ModuleLoader__.load({
|
|
|
5435
6586
|
h(
|
|
5436
6587
|
'div',
|
|
5437
6588
|
{ className: 'tb-sticky-head' },
|
|
5438
|
-
h('span', { className: 'tb-sticky-src' }, agent ? '🔗' : t('board.sourceUser')),
|
|
5439
|
-
h('span', { className: 'tb-sticky-title', title: entry.title }, entry.title || '未命名便签'),
|
|
6589
|
+
h('span', { className: 'tb-sticky-src' }, isDoc ? '📄' : agent ? '🔗' : t('board.sourceUser')),
|
|
6590
|
+
h('span', { className: 'tb-sticky-title', title: entry.title }, entry.title || (isDoc ? '未命名文档' : '未命名便签')),
|
|
5440
6591
|
h(
|
|
5441
6592
|
'div',
|
|
5442
6593
|
{ className: 'tb-sticky-actions' },
|
|
6594
|
+
h('button', { type: 'button', title: t('board.openMd'), onClick: (event) => { event.stopPropagation(); openReader(entry.id) } }, '📖'),
|
|
5443
6595
|
h('button', { type: 'button', title: t('board.edit'), onClick: (event) => { event.stopPropagation(); startEdit(entry) } }, '✎'),
|
|
5444
6596
|
h('button', { type: 'button', title: t('board.delete'), disabled: busy !== '', onClick: (event) => { event.stopPropagation(); removeEntry(entry.id) } }, '✕'),
|
|
5445
6597
|
),
|
|
5446
6598
|
),
|
|
5447
|
-
|
|
6599
|
+
isDoc
|
|
6600
|
+
? h(
|
|
6601
|
+
'div',
|
|
6602
|
+
{ className: 'tb-doc-body' },
|
|
6603
|
+
...(entry.body.trim()
|
|
6604
|
+
? [h('div', { key: 'md', className: 'tb-md' }, ...renderMarkdown(entry.body, `doc-${entry.id}`))]
|
|
6605
|
+
: [h('span', { key: 'empty' }, t('board.empty'))]),
|
|
6606
|
+
)
|
|
6607
|
+
: agent
|
|
5448
6608
|
? h(
|
|
5449
6609
|
'div',
|
|
5450
6610
|
{ className: 'tb-sticky-body' },
|
|
@@ -5527,6 +6687,34 @@ window.__ModuleLoader__.load({
|
|
|
5527
6687
|
)
|
|
5528
6688
|
: null,
|
|
5529
6689
|
),
|
|
6690
|
+
h(
|
|
6691
|
+
'button',
|
|
6692
|
+
{ type: 'button', className: 'tb-tool', title: t('board.newText'), onClick: startAddText },
|
|
6693
|
+
`T ${t('board.addText')}`,
|
|
6694
|
+
),
|
|
6695
|
+
h(
|
|
6696
|
+
'div',
|
|
6697
|
+
{ className: 'tb-window-insert' },
|
|
6698
|
+
h(
|
|
6699
|
+
'button',
|
|
6700
|
+
{
|
|
6701
|
+
type: 'button',
|
|
6702
|
+
className: `tb-tool${insertMenu ? ' on' : ''}`,
|
|
6703
|
+
title: t('board.insertHint'),
|
|
6704
|
+
onClick: () => setInsertMenu((value) => !value),
|
|
6705
|
+
},
|
|
6706
|
+
`+ ${t('board.insert')}`,
|
|
6707
|
+
),
|
|
6708
|
+
insertMenu
|
|
6709
|
+
? h(
|
|
6710
|
+
'div',
|
|
6711
|
+
{ className: 'tb-shape-menu tb-insert-menu', role: 'menu' },
|
|
6712
|
+
h('button', { type: 'button', role: 'menuitem', onClick: () => startAddTable(3, 3) }, `▦ ${t('board.table')}`),
|
|
6713
|
+
h('button', { type: 'button', role: 'menuitem', onClick: startImportTable }, `⇥ ${t('board.importTable')}`),
|
|
6714
|
+
h('button', { type: 'button', role: 'menuitem', onClick: startImportImage }, `🖼 ${t('board.importImage')}`),
|
|
6715
|
+
)
|
|
6716
|
+
: null,
|
|
6717
|
+
),
|
|
5530
6718
|
h('span', { className: 'tb-board-meta' }, t('board.brushSize')),
|
|
5531
6719
|
h('input', {
|
|
5532
6720
|
type: 'range',
|
|
@@ -5693,9 +6881,11 @@ window.__ModuleLoader__.load({
|
|
|
5693
6881
|
h('button', { type: 'button', className: 'tb-tool', title: t('board.zoomReset'), onClick: () => zoomBy(1 / zoomRef.current) }, `${Math.round(zoom * 100)}%`),
|
|
5694
6882
|
h('button', { type: 'button', className: 'tb-tool', title: t('board.zoomIn'), onClick: () => zoomBy(1.2) }, '+'),
|
|
5695
6883
|
h('button', { type: 'button', className: 'tb-btn', disabled: state.loading, onClick: refresh }, t('board.refresh')),
|
|
5696
|
-
h('button', { type: 'button', className: 'tb-btn primary', onClick: startCreate }, `+ ${t('board.newSticky')}`),
|
|
6884
|
+
h('button', { type: 'button', className: 'tb-btn primary', onClick: () => startCreate('sticky') }, `+ ${t('board.newSticky')}`),
|
|
6885
|
+
h('button', { type: 'button', className: 'tb-btn', onClick: () => startCreate('doc') }, `+ ${t('board.newDoc')}`),
|
|
5697
6886
|
),
|
|
5698
6887
|
toolbar,
|
|
6888
|
+
notice ? h('div', { className: 'tb-board-toast', role: 'status' }, notice) : null,
|
|
5699
6889
|
h('div', { className: 'tb-board-hint-wrap' }, h('span', { className: 'tb-ws-hint' }, `${t('board.stickyHint')} · ${t('board.panHint')}`)),
|
|
5700
6890
|
state.error ? h('div', { className: 'tb-feedback err' }, format(t('board.error'), { error: state.error })) : null,
|
|
5701
6891
|
h(
|
|
@@ -5714,10 +6904,160 @@ window.__ModuleLoader__.load({
|
|
|
5714
6904
|
drawingLayer(canvas.background, 'bg'),
|
|
5715
6905
|
edgeLayer(),
|
|
5716
6906
|
...entries.map((entry, index) => stickyFor(entry, index)),
|
|
6907
|
+
...(canvas.texts ?? []).map((item) =>
|
|
6908
|
+
h(
|
|
6909
|
+
'div',
|
|
6910
|
+
{
|
|
6911
|
+
key: item.id,
|
|
6912
|
+
className: `tb-board-text${selected === item.id ? ' selected' : ''}`,
|
|
6913
|
+
'data-text-id': item.id,
|
|
6914
|
+
style: {
|
|
6915
|
+
left: Number(item.x) || 0,
|
|
6916
|
+
top: Number(item.y) || 0,
|
|
6917
|
+
width: Math.min(1200, Math.max(80, Number(item.width) || 320)),
|
|
6918
|
+
color: item.color || '#e6e6e6',
|
|
6919
|
+
fontSize: Math.min(96, Math.max(8, Number(item.fontSize) || 18)),
|
|
6920
|
+
zIndex: 260,
|
|
6921
|
+
},
|
|
6922
|
+
onDoubleClick: (event) => {
|
|
6923
|
+
event.stopPropagation()
|
|
6924
|
+
startEditText(item)
|
|
6925
|
+
},
|
|
6926
|
+
},
|
|
6927
|
+
h('div', { className: 'tb-board-text-content' }, item.text || ''),
|
|
6928
|
+
h(
|
|
6929
|
+
'div',
|
|
6930
|
+
{ className: 'tb-board-text-actions' },
|
|
6931
|
+
h(
|
|
6932
|
+
'button',
|
|
6933
|
+
{
|
|
6934
|
+
type: 'button',
|
|
6935
|
+
title: t('board.editText'),
|
|
6936
|
+
onClick: (event) => {
|
|
6937
|
+
event.stopPropagation()
|
|
6938
|
+
startEditText(item)
|
|
6939
|
+
},
|
|
6940
|
+
},
|
|
6941
|
+
'✎',
|
|
6942
|
+
),
|
|
6943
|
+
h(
|
|
6944
|
+
'button',
|
|
6945
|
+
{
|
|
6946
|
+
type: 'button',
|
|
6947
|
+
title: t('board.deleteText'),
|
|
6948
|
+
onClick: (event) => {
|
|
6949
|
+
event.stopPropagation()
|
|
6950
|
+
deleteText(item.id)
|
|
6951
|
+
},
|
|
6952
|
+
},
|
|
6953
|
+
'✕',
|
|
6954
|
+
),
|
|
6955
|
+
),
|
|
6956
|
+
),
|
|
6957
|
+
),
|
|
6958
|
+
...(canvas.windows ?? []).map((item) =>
|
|
6959
|
+
h(
|
|
6960
|
+
'div',
|
|
6961
|
+
{
|
|
6962
|
+
key: item.id,
|
|
6963
|
+
className: `tb-board-window${selected === item.id ? ' selected' : ''}`,
|
|
6964
|
+
'data-window-id': item.id,
|
|
6965
|
+
style: {
|
|
6966
|
+
left: Number(item.x) || 0,
|
|
6967
|
+
top: Number(item.y) || 0,
|
|
6968
|
+
width: Math.min(1600, Math.max(160, Number(item.width) || 480)),
|
|
6969
|
+
height: Math.min(1200, Math.max(120, Number(item.height) || 260)),
|
|
6970
|
+
zIndex: 280,
|
|
6971
|
+
},
|
|
6972
|
+
onDoubleClick: (event) => {
|
|
6973
|
+
if (event.target?.closest?.('.tb-board-window-body')) return
|
|
6974
|
+
event.stopPropagation()
|
|
6975
|
+
startEditWindow(item)
|
|
6976
|
+
},
|
|
6977
|
+
},
|
|
6978
|
+
h(
|
|
6979
|
+
'div',
|
|
6980
|
+
{ className: 'tb-board-window-head' },
|
|
6981
|
+
h('span', { className: 'tb-board-window-title', title: item.title }, item.title || (item.kind === 'table' ? t('board.table') : t('board.importImage'))),
|
|
6982
|
+
h(
|
|
6983
|
+
'div',
|
|
6984
|
+
{ className: 'tb-board-window-actions' },
|
|
6985
|
+
h(
|
|
6986
|
+
'button',
|
|
6987
|
+
{
|
|
6988
|
+
type: 'button',
|
|
6989
|
+
title: t('board.edit'),
|
|
6990
|
+
onClick: (event) => {
|
|
6991
|
+
event.stopPropagation()
|
|
6992
|
+
startEditWindow(item)
|
|
6993
|
+
},
|
|
6994
|
+
},
|
|
6995
|
+
'✎',
|
|
6996
|
+
),
|
|
6997
|
+
h(
|
|
6998
|
+
'button',
|
|
6999
|
+
{
|
|
7000
|
+
type: 'button',
|
|
7001
|
+
title: t('board.delete'),
|
|
7002
|
+
onClick: (event) => {
|
|
7003
|
+
event.stopPropagation()
|
|
7004
|
+
deleteWindow(item.id)
|
|
7005
|
+
},
|
|
7006
|
+
},
|
|
7007
|
+
'✕',
|
|
7008
|
+
),
|
|
7009
|
+
),
|
|
7010
|
+
),
|
|
7011
|
+
h(
|
|
7012
|
+
'div',
|
|
7013
|
+
{ className: 'tb-board-window-body' },
|
|
7014
|
+
item.kind === 'table'
|
|
7015
|
+
? h(
|
|
7016
|
+
'table',
|
|
7017
|
+
null,
|
|
7018
|
+
...(item.rows ?? [['']]).map((row, rowIndex) =>
|
|
7019
|
+
h(
|
|
7020
|
+
'tr',
|
|
7021
|
+
{ key: `row-${rowIndex}` },
|
|
7022
|
+
...(row ?? []).map((cell, cellIndex) =>
|
|
7023
|
+
h(
|
|
7024
|
+
'td',
|
|
7025
|
+
{
|
|
7026
|
+
key: `cell-${rowIndex}-${cellIndex}`,
|
|
7027
|
+
contentEditable: true,
|
|
7028
|
+
suppressContentEditableWarning: true,
|
|
7029
|
+
onBlur: (event) => {
|
|
7030
|
+
const text = String(event.currentTarget?.textContent ?? '').replace(/\u00a0/g, '')
|
|
7031
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
7032
|
+
const target = (next.windows ?? []).find((entry) => entry.id === item.id)
|
|
7033
|
+
if (!target || !Array.isArray(target.rows)) return
|
|
7034
|
+
target.rows[rowIndex] = [...(target.rows[rowIndex] ?? [])]
|
|
7035
|
+
target.rows[rowIndex][cellIndex] = text
|
|
7036
|
+
next.windows = (next.windows ?? []).map((entry) => (entry.id === item.id ? target : entry))
|
|
7037
|
+
saveCanvasSoon(next)
|
|
7038
|
+
},
|
|
7039
|
+
},
|
|
7040
|
+
String(cell ?? '') === '' ? '\u00a0' : String(cell),
|
|
7041
|
+
),
|
|
7042
|
+
),
|
|
7043
|
+
),
|
|
7044
|
+
),
|
|
7045
|
+
)
|
|
7046
|
+
: h('img', { src: item.src, alt: item.alt || item.title || '', draggable: false }),
|
|
7047
|
+
),
|
|
7048
|
+
h('div', { className: 'tb-board-window-resize', title: t('board.resizeNote') }),
|
|
7049
|
+
),
|
|
7050
|
+
),
|
|
5717
7051
|
),
|
|
5718
7052
|
),
|
|
5719
7053
|
state.loading && !state.board ? h('p', { className: 'tb-board-md-empty' }, t('panel.loading')) : null,
|
|
5720
|
-
!state.loading &&
|
|
7054
|
+
!state.loading &&
|
|
7055
|
+
entries.length === 0 &&
|
|
7056
|
+
(canvas.texts ?? []).length === 0 &&
|
|
7057
|
+
(canvas.windows ?? []).length === 0 &&
|
|
7058
|
+
(canvas.background ?? []).length === 0
|
|
7059
|
+
? h('p', { className: 'tb-board-md-empty' }, t('board.empty'))
|
|
7060
|
+
: null,
|
|
5721
7061
|
),
|
|
5722
7062
|
h(
|
|
5723
7063
|
'div',
|
|
@@ -5796,7 +7136,7 @@ window.__ModuleLoader__.load({
|
|
|
5796
7136
|
h(
|
|
5797
7137
|
'div',
|
|
5798
7138
|
{ className: 'tb-detail-head' },
|
|
5799
|
-
h('span', { className: 'tb-detail-title' }, draft.id ? t('board.edit') : t('board.newSticky')),
|
|
7139
|
+
h('span', { className: 'tb-detail-title' }, draft.id ? t('board.edit') : draft.kind === 'doc' ? t('board.newDoc') : t('board.newSticky')),
|
|
5800
7140
|
h('span', { style: { flex: 1 } }),
|
|
5801
7141
|
h('button', { type: 'button', className: 'tb-btn', title: t('board.resizeHint'), onClick: resetDialogSize }, t('board.resetSize')),
|
|
5802
7142
|
),
|
|
@@ -5845,7 +7185,7 @@ window.__ModuleLoader__.load({
|
|
|
5845
7185
|
disabled: draft.busy,
|
|
5846
7186
|
placeholder: t('board.bodyPlaceholder'),
|
|
5847
7187
|
}),
|
|
5848
|
-
h('div', { className: 'tb-ws-hint' }, `${t('board.resizeHint')} · ${t('board.autosaveHint')}`),
|
|
7188
|
+
h('div', { className: 'tb-ws-hint' }, `${t('board.resizeHint')} · ${t('board.autosaveHint')}${draft.kind === 'doc' ? ` · ${t('board.docHint')}` : ''}`),
|
|
5849
7189
|
draft.error ? h('div', { className: 'tb-feedback err' }, format(t('board.error'), { error: draft.error })) : null,
|
|
5850
7190
|
h(
|
|
5851
7191
|
'div',
|
|
@@ -5859,10 +7199,267 @@ window.__ModuleLoader__.load({
|
|
|
5859
7199
|
),
|
|
5860
7200
|
)
|
|
5861
7201
|
: null,
|
|
7202
|
+
textEditor
|
|
7203
|
+
? h(
|
|
7204
|
+
'div',
|
|
7205
|
+
{ className: 'tb-overlay center', onClick: () => setTextEditor(null) },
|
|
7206
|
+
h(
|
|
7207
|
+
'div',
|
|
7208
|
+
{
|
|
7209
|
+
className: 'tb-board-dialog tb-text-dialog',
|
|
7210
|
+
role: 'dialog',
|
|
7211
|
+
'aria-modal': true,
|
|
7212
|
+
onClick: (event) => event.stopPropagation(),
|
|
7213
|
+
},
|
|
7214
|
+
h(
|
|
7215
|
+
'div',
|
|
7216
|
+
{ className: 'tb-detail-head' },
|
|
7217
|
+
h('span', { className: 'tb-detail-title' }, textEditor.id ? t('board.editText') : t('board.newText')),
|
|
7218
|
+
h('span', { style: { flex: 1 } }),
|
|
7219
|
+
textEditor.id
|
|
7220
|
+
? h(
|
|
7221
|
+
'button',
|
|
7222
|
+
{
|
|
7223
|
+
type: 'button',
|
|
7224
|
+
className: 'tb-btn danger',
|
|
7225
|
+
onClick: () => deleteText(textEditor.id),
|
|
7226
|
+
},
|
|
7227
|
+
t('board.deleteText'),
|
|
7228
|
+
)
|
|
7229
|
+
: null,
|
|
7230
|
+
),
|
|
7231
|
+
h('textarea', {
|
|
7232
|
+
className: 'tb-text-input',
|
|
7233
|
+
value: textEditor.text ?? '',
|
|
7234
|
+
placeholder: t('board.textPlaceholder'),
|
|
7235
|
+
autoFocus: true,
|
|
7236
|
+
onChange: (event) => setTextEditor((current) => (current ? { ...current, text: event.target.value } : current)),
|
|
7237
|
+
}),
|
|
7238
|
+
h(
|
|
7239
|
+
'div',
|
|
7240
|
+
{ className: 'tb-text-row' },
|
|
7241
|
+
h('span', { className: 'tb-color-label' }, t('board.fontColor')),
|
|
7242
|
+
...['#e6e6e6', '#2a2418', '#ffffff', '#ff5f56', '#f0b23e', '#3ecf8e', '#38bdf8', '#c084fc', '#f472b6', '#1c4d8f'].map((value) =>
|
|
7243
|
+
h('button', {
|
|
7244
|
+
key: `text-${value}`,
|
|
7245
|
+
type: 'button',
|
|
7246
|
+
className: `tb-text-swatch${String(textEditor.color || '').toLowerCase() === value ? ' on' : ''}`,
|
|
7247
|
+
style: { background: value },
|
|
7248
|
+
title: value,
|
|
7249
|
+
'aria-label': value,
|
|
7250
|
+
onClick: () => setTextEditor((current) => (current ? { ...current, color: value } : current)),
|
|
7251
|
+
}),
|
|
7252
|
+
),
|
|
7253
|
+
h('input', {
|
|
7254
|
+
type: 'color',
|
|
7255
|
+
value: textEditor.color || '#e6e6e6',
|
|
7256
|
+
title: t('md.customColor'),
|
|
7257
|
+
style: { width: 30, height: 24, padding: 0, border: 0, background: 'transparent' },
|
|
7258
|
+
onChange: (event) => setTextEditor((current) => (current ? { ...current, color: event.target.value } : current)),
|
|
7259
|
+
}),
|
|
7260
|
+
),
|
|
7261
|
+
h(
|
|
7262
|
+
'div',
|
|
7263
|
+
{ className: 'tb-text-row' },
|
|
7264
|
+
h('span', { className: 'tb-color-label' }, t('board.fontSize')),
|
|
7265
|
+
h('input', {
|
|
7266
|
+
type: 'range',
|
|
7267
|
+
min: 8,
|
|
7268
|
+
max: 72,
|
|
7269
|
+
step: 1,
|
|
7270
|
+
value: Number(textEditor.fontSize) || 18,
|
|
7271
|
+
style: { width: 220 },
|
|
7272
|
+
onChange: (event) => setTextEditor((current) => (current ? { ...current, fontSize: Number(event.target.value) || 18 } : current)),
|
|
7273
|
+
}),
|
|
7274
|
+
h('span', { className: 'tb-board-meta' }, `${Number(textEditor.fontSize) || 18}px`),
|
|
7275
|
+
),
|
|
7276
|
+
h(
|
|
7277
|
+
'div',
|
|
7278
|
+
{
|
|
7279
|
+
className: 'tb-text-preview',
|
|
7280
|
+
style: { color: textEditor.color || '#e6e6e6', fontSize: Number(textEditor.fontSize) || 18 },
|
|
7281
|
+
},
|
|
7282
|
+
textEditor.text || t('board.textPlaceholder'),
|
|
7283
|
+
),
|
|
7284
|
+
textEditor.error ? h('div', { className: 'tb-feedback err' }, textEditor.error) : null,
|
|
7285
|
+
h(
|
|
7286
|
+
'div',
|
|
7287
|
+
{ 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')),
|
|
7290
|
+
),
|
|
7291
|
+
),
|
|
7292
|
+
)
|
|
7293
|
+
: null,
|
|
7294
|
+
windowEditor
|
|
7295
|
+
? h(
|
|
7296
|
+
'div',
|
|
7297
|
+
{ className: 'tb-overlay center', onClick: () => setWindowEditor(null) },
|
|
7298
|
+
h(
|
|
7299
|
+
'div',
|
|
7300
|
+
{
|
|
7301
|
+
className: 'tb-board-dialog tb-window-editor-dialog',
|
|
7302
|
+
role: 'dialog',
|
|
7303
|
+
'aria-modal': true,
|
|
7304
|
+
onClick: (event) => event.stopPropagation(),
|
|
7305
|
+
},
|
|
7306
|
+
h(
|
|
7307
|
+
'div',
|
|
7308
|
+
{ className: 'tb-detail-head' },
|
|
7309
|
+
h(
|
|
7310
|
+
'span',
|
|
7311
|
+
{ className: 'tb-detail-title' },
|
|
7312
|
+
`${windowEditor.kind === 'table' ? '▦' : '🖼'} ${
|
|
7313
|
+
windowEditor.id ? t('board.edit') : windowEditor.kind === 'table' ? t('board.table') : t('board.importImage')
|
|
7314
|
+
}`,
|
|
7315
|
+
),
|
|
7316
|
+
h('span', { style: { flex: 1 } }),
|
|
7317
|
+
windowEditor.id
|
|
7318
|
+
? h(
|
|
7319
|
+
'button',
|
|
7320
|
+
{ type: 'button', className: 'tb-btn danger', onClick: () => deleteWindow(windowEditor.id) },
|
|
7321
|
+
t('board.delete'),
|
|
7322
|
+
)
|
|
7323
|
+
: null,
|
|
7324
|
+
),
|
|
7325
|
+
h('input', {
|
|
7326
|
+
value: windowEditor.title ?? '',
|
|
7327
|
+
placeholder: t('board.windowTitle'),
|
|
7328
|
+
onChange: (event) => setWindowEditor((current) => (current ? { ...current, title: event.target.value } : current)),
|
|
7329
|
+
}),
|
|
7330
|
+
windowEditor.kind === 'table'
|
|
7331
|
+
? h(
|
|
7332
|
+
'div',
|
|
7333
|
+
{ className: 'tb-window-editor-body' },
|
|
7334
|
+
h(
|
|
7335
|
+
'div',
|
|
7336
|
+
{ className: 'tb-text-row' },
|
|
7337
|
+
h('button', {
|
|
7338
|
+
type: 'button',
|
|
7339
|
+
className: 'tb-btn',
|
|
7340
|
+
onClick: () =>
|
|
7341
|
+
setWindowEditor((current) => {
|
|
7342
|
+
if (!current) return current
|
|
7343
|
+
const rows = (current.rows ?? [[]]).map((row) => [...row])
|
|
7344
|
+
const cols = Math.max(1, ...rows.map((row) => row.length))
|
|
7345
|
+
rows.push(Array.from({ length: cols }, () => ''))
|
|
7346
|
+
return { ...current, rows }
|
|
7347
|
+
}),
|
|
7348
|
+
}, `+ ${t('board.addRow')}`),
|
|
7349
|
+
h('button', {
|
|
7350
|
+
type: 'button',
|
|
7351
|
+
className: 'tb-btn',
|
|
7352
|
+
onClick: () =>
|
|
7353
|
+
setWindowEditor((current) => {
|
|
7354
|
+
if (!current) return current
|
|
7355
|
+
const rows = (current.rows ?? [[]]).map((row) => [...row, ''])
|
|
7356
|
+
return { ...current, rows }
|
|
7357
|
+
}),
|
|
7358
|
+
}, `+ ${t('board.addCol')}`),
|
|
7359
|
+
h('button', {
|
|
7360
|
+
type: 'button',
|
|
7361
|
+
className: 'tb-btn',
|
|
7362
|
+
onClick: () => {
|
|
7363
|
+
const applyRows = (text, name) => {
|
|
7364
|
+
const rows = parseTableText(text)
|
|
7365
|
+
setWindowEditor((current) =>
|
|
7366
|
+
current
|
|
7367
|
+
? {
|
|
7368
|
+
...current,
|
|
7369
|
+
rows,
|
|
7370
|
+
...(name ? { title: name.replace(/\.[^.]+$/, '') || current.title } : {}),
|
|
7371
|
+
width: Math.min(900, Math.max(420, (rows[0]?.length ?? 3) * 120)),
|
|
7372
|
+
height: Math.min(700, Math.max(220, rows.length * 34 + 44)),
|
|
7373
|
+
}
|
|
7374
|
+
: current,
|
|
7375
|
+
)
|
|
7376
|
+
}
|
|
7377
|
+
pickFile('.csv,.tsv,.txt,.md,text/csv,text/tab-separated-values,text/plain,text/markdown', (file) => {
|
|
7378
|
+
if (file.size > 2_000_000) {
|
|
7379
|
+
setWindowEditor((current) => (current ? { ...current, error: '表格文件过大' } : current))
|
|
7380
|
+
return
|
|
7381
|
+
}
|
|
7382
|
+
const reader = new FileReader()
|
|
7383
|
+
reader.onload = () => applyRows(String(reader.result ?? ''), file.name)
|
|
7384
|
+
reader.onerror = () => setWindowEditor((current) => (current ? { ...current, error: '表格读取失败' } : current))
|
|
7385
|
+
reader.readAsText(file)
|
|
7386
|
+
})
|
|
7387
|
+
},
|
|
7388
|
+
}, `⇥ ${t('board.fromFile')}`),
|
|
7389
|
+
),
|
|
7390
|
+
h('textarea', {
|
|
7391
|
+
className: 'tb-text-input',
|
|
7392
|
+
value: tableRowsToText(windowEditor.rows),
|
|
7393
|
+
placeholder: t('board.tableHint'),
|
|
7394
|
+
onChange: (event) => {
|
|
7395
|
+
const rows = parseTableText(event.target.value)
|
|
7396
|
+
setWindowEditor((current) => (current ? { ...current, rows } : current))
|
|
7397
|
+
},
|
|
7398
|
+
}),
|
|
7399
|
+
h(
|
|
7400
|
+
'div',
|
|
7401
|
+
{ className: 'tb-table-editor-preview' },
|
|
7402
|
+
h(
|
|
7403
|
+
'table',
|
|
7404
|
+
null,
|
|
7405
|
+
...(windowEditor.rows ?? [['']]).slice(0, 10).map((row, rowIndex) =>
|
|
7406
|
+
h(
|
|
7407
|
+
'tr',
|
|
7408
|
+
{ key: `preview-row-${rowIndex}` },
|
|
7409
|
+
...(row ?? []).slice(0, 8).map((cell, cellIndex) =>
|
|
7410
|
+
h('td', { key: `preview-cell-${rowIndex}-${cellIndex}` }, String(cell ?? '') === '' ? '\u00a0' : String(cell)),
|
|
7411
|
+
),
|
|
7412
|
+
),
|
|
7413
|
+
),
|
|
7414
|
+
),
|
|
7415
|
+
),
|
|
7416
|
+
)
|
|
7417
|
+
: h(
|
|
7418
|
+
'div',
|
|
7419
|
+
{ className: 'tb-window-editor-body' },
|
|
7420
|
+
h('div', { className: 'tb-table-editor-preview' }, h('img', { src: windowEditor.src, alt: windowEditor.alt || '' })),
|
|
7421
|
+
h(
|
|
7422
|
+
'div',
|
|
7423
|
+
{ className: 'tb-text-row' },
|
|
7424
|
+
h('button', {
|
|
7425
|
+
type: 'button',
|
|
7426
|
+
className: 'tb-btn',
|
|
7427
|
+
onClick: () => {
|
|
7428
|
+
pickFile('image/*', (file) => {
|
|
7429
|
+
if (!/^image\//i.test(file.type) || file.size > 1_500_000) {
|
|
7430
|
+
setWindowEditor((current) => (current ? { ...current, error: '请选择 1.5MB 以内的图片' } : current))
|
|
7431
|
+
return
|
|
7432
|
+
}
|
|
7433
|
+
const reader = new FileReader()
|
|
7434
|
+
reader.onload = () =>
|
|
7435
|
+
setWindowEditor((current) =>
|
|
7436
|
+
current ? { ...current, src: String(reader.result ?? ''), alt: file.name } : current,
|
|
7437
|
+
)
|
|
7438
|
+
reader.onerror = () => setWindowEditor((current) => (current ? { ...current, error: '图片读取失败' } : current))
|
|
7439
|
+
reader.readAsDataURL(file)
|
|
7440
|
+
})
|
|
7441
|
+
},
|
|
7442
|
+
}, `🖼 ${t('board.chooseImage')}`),
|
|
7443
|
+
),
|
|
7444
|
+
h('div', { className: 'tb-ws-hint' }, t('board.imageHint')),
|
|
7445
|
+
),
|
|
7446
|
+
h('div', { className: 'tb-ws-hint' }, windowEditor.kind === 'table' ? t('board.tableHint') : t('board.imageHint')),
|
|
7447
|
+
windowEditor.error ? h('div', { className: 'tb-feedback err' }, windowEditor.error) : null,
|
|
7448
|
+
h(
|
|
7449
|
+
'div',
|
|
7450
|
+
{ 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')),
|
|
7453
|
+
),
|
|
7454
|
+
),
|
|
7455
|
+
)
|
|
7456
|
+
: null,
|
|
5862
7457
|
)
|
|
5863
7458
|
}
|
|
5864
7459
|
|
|
5865
7460
|
if (typeof window !== 'undefined' && window.__TIMEBACK_TEST__) {
|
|
7461
|
+
window.__TIMEBACK_TEST__.parseTableText = parseTableText
|
|
7462
|
+
window.__TIMEBACK_TEST__.tableRowsToText = tableRowsToText
|
|
5866
7463
|
window.__TIMEBACK_TEST__.edgePanVector = edgePanVector
|
|
5867
7464
|
window.__TIMEBACK_TEST__.renderMarkdown = renderMarkdown
|
|
5868
7465
|
window.__TIMEBACK_TEST__.stripMarkdown = stripMarkdown
|
|
@@ -5873,16 +7470,21 @@ window.__ModuleLoader__.load({
|
|
|
5873
7470
|
window.__TIMEBACK_TEST__.domToMarkdown = domToMarkdown
|
|
5874
7471
|
window.__TIMEBACK_TEST__.turnRows = turnRows
|
|
5875
7472
|
window.__TIMEBACK_TEST__.mergeCardFolder = mergeCardFolder
|
|
7473
|
+
window.__TIMEBACK_TEST__.stableSessionColor = stableSessionColor
|
|
5876
7474
|
window.__TIMEBACK_TEST__.removeFolderMember = removeFolderMember
|
|
7475
|
+
window.__TIMEBACK_TEST__.renameCardFolder = renameCardFolder
|
|
5877
7476
|
window.__TIMEBACK_TEST__.layoutTree = layoutTree
|
|
7477
|
+
window.__TIMEBACK_TEST__.turnConversation = turnConversation
|
|
7478
|
+
window.__TIMEBACK_TEST__.messageTextOf = messageTextOf
|
|
5878
7479
|
window.__TIMEBACK_TEST__.CanvasFolderCard = CanvasFolderCard
|
|
5879
7480
|
window.__TIMEBACK_TEST__.TreeCanvas = TreeCanvas
|
|
5880
7481
|
}
|
|
5881
7482
|
|
|
5882
7483
|
return {
|
|
5883
|
-
inject: ['slots', 'locale', 'sidebarRight', 'sidebarRightTabs', 'uiWorkspace', 'uiSession', 'contextMenus'],
|
|
7484
|
+
inject: ['slots', 'locale', 'sidebarRight', 'sidebarRightTabs', 'uiWorkspace', 'uiSession', 'sessions', 'contextMenus'],
|
|
5884
7485
|
apply(ctx) {
|
|
5885
7486
|
const t = ctx.locale.bind(NS)
|
|
7487
|
+
sessionApi = ctx.sessions ?? null
|
|
5886
7488
|
console.log(`[timeback] client ${BUILD} loaded`)
|
|
5887
7489
|
openSessionBridge = (sessionId) => {
|
|
5888
7490
|
try {
|