dsh-timeback 0.6.1 → 0.7.1
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 +49 -18
- package/client.js +1494 -35
- package/docs/MARKET.md +2 -2
- package/docs/PUBLISHING.md +11 -8
- package/index.js +6 -1
- package/package.json +1 -1
- package/src/notes.js +120 -1
- package/src/service.js +7 -0
package/client.js
CHANGED
|
@@ -23,7 +23,7 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
const REFRESH_MS = 3000
|
|
24
24
|
const MAX_ROWS = 240
|
|
25
25
|
/** Bump together with package.json so a stale browser bundle is obvious. */
|
|
26
|
-
const BUILD = '0.
|
|
26
|
+
const BUILD = '0.7.1+sticky'
|
|
27
27
|
/** Set by apply(): opens another Session in the main column. */
|
|
28
28
|
let openSessionBridge = null
|
|
29
29
|
/** Set by apply(): opens the Timeback tab in the right sidebar. */
|
|
@@ -98,6 +98,48 @@ window.__ModuleLoader__.load({
|
|
|
98
98
|
'note.removed': '卡片记录已删除',
|
|
99
99
|
'board.title': '记录板',
|
|
100
100
|
'board.subtitle': '全局 Markdown 记录板 · 回溯时一起恢复',
|
|
101
|
+
'board.newSticky': '新建便签',
|
|
102
|
+
'board.stickyHint': '便签可拖动;画笔可在方格纸背景或便签上绘制,橡皮擦除笔画。',
|
|
103
|
+
'board.resizeNote': '拖动缩放便签',
|
|
104
|
+
'board.drawOnSticky': '便签可画',
|
|
105
|
+
'board.drawOnStickyOn': '便签可画:开',
|
|
106
|
+
'board.drawOnStickyOff': '便签可画:关',
|
|
107
|
+
'board.drawOnStickyHint': '开启后画笔/图形可直接画在便签上;关闭则只画在方格纸背景。',
|
|
108
|
+
'board.center': '自动调整',
|
|
109
|
+
'board.reader': '阅读 md',
|
|
110
|
+
'board.close': '关闭',
|
|
111
|
+
'board.toolSelect': '拖动',
|
|
112
|
+
'board.shapeRect': '矩形',
|
|
113
|
+
'board.shapeEllipse': '圆形',
|
|
114
|
+
'board.shapeLine': '直线',
|
|
115
|
+
'board.shapeArrow': '箭头',
|
|
116
|
+
'board.shapeTriangle': '三角形',
|
|
117
|
+
'board.toolLink': '路径',
|
|
118
|
+
'board.commonShapes': '常用图形',
|
|
119
|
+
'board.brushSize': '粗细',
|
|
120
|
+
'board.anchorsHint': '路径工具:从便签四角的吸附点拖到另一张便签,形成图结构;点路径可删除。',
|
|
121
|
+
'board.clearEdges': '清路径',
|
|
122
|
+
'board.edgeDeleteConfirm': '删除这条路径?',
|
|
123
|
+
'board.panHint': '拖动工具下按住空白方格纸可平移画布',
|
|
124
|
+
'board.toolPen': '画笔',
|
|
125
|
+
'board.toolEraser': '橡皮',
|
|
126
|
+
'board.clearBg': '清背景笔迹',
|
|
127
|
+
'board.clearNote': '清便签笔迹',
|
|
128
|
+
'board.linkSticky': '超链接便签',
|
|
129
|
+
'board.openMd': '打开 md',
|
|
130
|
+
'board.mdBelow': '记录板内容(Markdown)',
|
|
131
|
+
'board.canvasVersion': '便签板 v{version}',
|
|
132
|
+
'board.color': '颜色',
|
|
133
|
+
'board.colorTitle': '选择颜色',
|
|
134
|
+
'board.commonColors': '常用颜色',
|
|
135
|
+
'board.recentColors': '近期使用',
|
|
136
|
+
'board.customColor': '自定义颜色',
|
|
137
|
+
'board.rgb': 'RGB',
|
|
138
|
+
'board.eyedropper': '屏幕取色',
|
|
139
|
+
'board.eyedropperHint': '从屏幕任意位置吸取颜色(需要 Chrome/Edge 等支持 EyeDropper 的浏览器)',
|
|
140
|
+
'board.eyedropperUnsupported': '当前浏览器不支持屏幕取色,请使用「自定义颜色」里的系统取色器或手动输入 HEX。',
|
|
141
|
+
'board.eyedropperInsecure': '屏幕取色需要 https 或 localhost 环境;当前页面不是安全上下文。',
|
|
142
|
+
'board.eyedropperFailed': '取色被取消或失败:{error}',
|
|
101
143
|
'board.new': '新建记录',
|
|
102
144
|
'board.edit': '编辑',
|
|
103
145
|
'board.delete': '删除',
|
|
@@ -274,6 +316,48 @@ window.__ModuleLoader__.load({
|
|
|
274
316
|
'note.removed': 'Card note deleted',
|
|
275
317
|
'board.title': 'Notes board',
|
|
276
318
|
'board.subtitle': 'Global Markdown notes · rewinds restore them too',
|
|
319
|
+
'board.newSticky': 'New sticky',
|
|
320
|
+
'board.stickyHint': 'Sticky notes are draggable; draw on the grid or on a note, erase strokes with the eraser.',
|
|
321
|
+
'board.resizeNote': 'Drag to resize the sticky',
|
|
322
|
+
'board.drawOnSticky': 'Draw on stickies',
|
|
323
|
+
'board.drawOnStickyOn': 'Sticky drawing: on',
|
|
324
|
+
'board.drawOnStickyOff': 'Sticky drawing: off',
|
|
325
|
+
'board.drawOnStickyHint': 'When on, pen/shape tools draw directly on sticky notes; when off they only draw on the grid.',
|
|
326
|
+
'board.center': 'Auto fit',
|
|
327
|
+
'board.reader': 'Read md',
|
|
328
|
+
'board.close': 'Close',
|
|
329
|
+
'board.toolSelect': 'Move',
|
|
330
|
+
'board.shapeRect': 'Rectangle',
|
|
331
|
+
'board.shapeEllipse': 'Ellipse',
|
|
332
|
+
'board.shapeLine': 'Line',
|
|
333
|
+
'board.shapeArrow': 'Arrow',
|
|
334
|
+
'board.shapeTriangle': 'Triangle',
|
|
335
|
+
'board.toolLink': 'Link',
|
|
336
|
+
'board.commonShapes': 'Shapes',
|
|
337
|
+
'board.brushSize': 'Size',
|
|
338
|
+
'board.anchorsHint': 'Link tool: drag from a sticky anchor to another sticky to build a graph; click a link to delete it.',
|
|
339
|
+
'board.clearEdges': 'Clear links',
|
|
340
|
+
'board.edgeDeleteConfirm': 'Delete this link?',
|
|
341
|
+
'board.panHint': 'With the Move tool, drag on empty grid to pan the canvas',
|
|
342
|
+
'board.toolPen': 'Pen',
|
|
343
|
+
'board.toolEraser': 'Eraser',
|
|
344
|
+
'board.clearBg': 'Clear drawings',
|
|
345
|
+
'board.clearNote': 'Clear note drawing',
|
|
346
|
+
'board.linkSticky': 'Link sticky',
|
|
347
|
+
'board.openMd': 'Open md',
|
|
348
|
+
'board.mdBelow': 'Board contents (Markdown)',
|
|
349
|
+
'board.canvasVersion': 'Board v{version}',
|
|
350
|
+
'board.color': 'Colour',
|
|
351
|
+
'board.colorTitle': 'Pick a colour',
|
|
352
|
+
'board.commonColors': 'Common colours',
|
|
353
|
+
'board.recentColors': 'Recent',
|
|
354
|
+
'board.customColor': 'Custom colour',
|
|
355
|
+
'board.rgb': 'RGB',
|
|
356
|
+
'board.eyedropper': 'Pick from screen',
|
|
357
|
+
'board.eyedropperHint': 'Sample any colour from the screen (Chrome/Edge and other EyeDropper-capable browsers)',
|
|
358
|
+
'board.eyedropperUnsupported': 'This browser does not support screen sampling; use the system picker under Custom colour or type a HEX value.',
|
|
359
|
+
'board.eyedropperInsecure': 'Screen sampling needs https or localhost; this page is not a secure context.',
|
|
360
|
+
'board.eyedropperFailed': 'Colour picking was cancelled or failed: {error}',
|
|
277
361
|
'board.new': 'New note',
|
|
278
362
|
'board.edit': 'Edit',
|
|
279
363
|
'board.delete': 'Delete',
|
|
@@ -493,6 +577,71 @@ window.__ModuleLoader__.load({
|
|
|
493
577
|
.tb-resize-handle.se{right:0;bottom:0;width:18px;height:18px;cursor:nwse-resize}
|
|
494
578
|
.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}
|
|
495
579
|
.tb-board-testid{display:none}
|
|
580
|
+
.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))}
|
|
581
|
+
.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}
|
|
582
|
+
.tb-shape-wrap{position:relative;display:inline-flex}
|
|
583
|
+
.tb-shape-menu{position:absolute;top:calc(100% + 4px);left:0;z-index:40;display:flex;flex-direction:column;gap:2px;min-width:148px;padding:4px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:var(--dsw-alias-bg-layer-2,rgba(24,28,36,.98));box-shadow:0 10px 24px rgba(0,0,0,.35)}
|
|
584
|
+
.tb-shape-menu button{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-primary,#e6e6e6);text-align:left;padding:5px 8px;border-radius:5px;font-size:11.5px;cursor:pointer;white-space:nowrap}
|
|
585
|
+
.tb-shape-menu button:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.1))}
|
|
586
|
+
.tb-size-range{width:82px;accent-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
|
|
587
|
+
.tb-tool.on{color:var(--dsw-alias-label-primary,#e6e6e6);border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.08))}
|
|
588
|
+
.tb-color-wrap{position:relative;display:inline-flex}
|
|
589
|
+
.tb-color-btn{width:26px;height:22px;border-radius:6px;border:2px solid var(--dsw-alias-border-l2,rgba(255,255,255,.3));cursor:pointer;padding:0;box-shadow:inset 0 0 0 1px rgba(0,0,0,.25)}
|
|
590
|
+
.tb-color-panel{position:absolute;top:calc(100% + 4px);left:0;z-index:45;width:248px;padding:8px;border-radius:9px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:var(--dsw-alias-bg-layer-2,rgba(24,28,36,.99));box-shadow:0 12px 30px rgba(0,0,0,.4);display:flex;flex-direction:column;gap:7px}
|
|
591
|
+
.tb-color-row{display:flex;align-items:center;gap:5px;flex-wrap:wrap}
|
|
592
|
+
.tb-color-label{font-size:10.5px;color:var(--dsw-alias-label-secondary,#9aa0a6);min-width:56px}
|
|
593
|
+
.tb-color-grid{display:grid;grid-template-columns:repeat(8,1fr);gap:4px}
|
|
594
|
+
.tb-color-grid button{width:100%;aspect-ratio:1;border-radius:4px;border:1px solid rgba(255,255,255,.22);cursor:pointer;padding:0}
|
|
595
|
+
.tb-rgb-row{display:flex;align-items:center;gap:4px;font-size:10.5px;color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
596
|
+
.tb-rgb-row input[type=range]{flex:1;min-width:40px;accent-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
|
|
597
|
+
.tb-hex-row{display:flex;align-items:center;gap:5px}
|
|
598
|
+
.tb-hex-row input[type=text]{flex:1;min-width:0;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.05));color:var(--dsw-alias-label-primary,#e6e6e6);border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));border-radius:5px;padding:3px 6px;font-size:11px;font-family:ui-monospace,monospace}
|
|
599
|
+
.tb-swatch{width:18px;height:18px;border-radius:50%;border:2px solid transparent;cursor:pointer;padding:0}
|
|
600
|
+
.tb-swatch.on{border-color:var(--dsw-alias-label-primary,#e6e6e6);box-shadow:0 0 0 2px rgba(0,0,0,.3)}
|
|
601
|
+
.tb-board-canvas{position:relative;touch-action:none;flex:1;min-height:240px;overflow:auto;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));background:var(--dsw-alias-bg-base,#16181d);cursor:crosshair}
|
|
602
|
+
.tb-board-canvas.select{cursor:grab}
|
|
603
|
+
.tb-board-canvas.draw,.tb-board-canvas.draw .tb-sticky{cursor:crosshair}
|
|
604
|
+
.tb-board-canvas.link,.tb-board-canvas.link .tb-sticky{cursor:crosshair}
|
|
605
|
+
.tb-anchor{position:absolute;width:9px;height:9px;border-radius:50%;background:var(--dsw-alias-bg-base,#16181d);border:2px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);z-index:7;display:none;box-sizing:border-box;transform:translate(-50%,-50%)}
|
|
606
|
+
.tb-board-stage.show-anchors .tb-anchor{display:block}
|
|
607
|
+
.tb-anchor:hover{background:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
|
|
608
|
+
.tb-board-edges{position:absolute;left:0;top:0;pointer-events:none;overflow:visible;z-index:1}
|
|
609
|
+
.tb-board-edge-path{fill:none;stroke-width:2;opacity:.7;pointer-events:stroke}
|
|
610
|
+
.tb-board-edge-path:hover{opacity:1;stroke-width:3}
|
|
611
|
+
.tb-board-edge-dot{fill:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);stroke:none}
|
|
612
|
+
.tb-board-edge-preview{fill:none;stroke-dasharray:6 5;stroke-width:2;opacity:.7}
|
|
613
|
+
.tb-board-canvas.draw .tb-sticky-resize{cursor:nwse-resize}
|
|
614
|
+
.tb-board-canvas.select:active{cursor:grabbing}
|
|
615
|
+
.tb-board-world{position:relative;flex:none}
|
|
616
|
+
.tb-board-stage{position:absolute;left:0;top:0;transform-origin:0 0;background-color:var(--dsw-alias-bg-base,#16181d);background-image:linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px);background-size:22px 22px,22px 22px,110px 110px,110px 110px}
|
|
617
|
+
.tb-board-bgdraw{position:absolute;left:0;top:0;pointer-events:none;overflow:visible}
|
|
618
|
+
.tb-sticky{position:absolute;width:232px;height:176px;min-width:160px;min-height:120px;box-sizing:border-box;border-radius:5px;padding:8px 9px;display:flex;flex-direction:column;gap:5px;color:#2a2418;box-shadow:0 6px 16px rgba(0,0,0,.28);border:1px solid rgba(0,0,0,.18);overflow:hidden;cursor:grab;user-select:none}
|
|
619
|
+
.tb-sticky:active{cursor:grabbing}
|
|
620
|
+
.tb-sticky.selected{outline:2px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);outline-offset:1px}
|
|
621
|
+
.tb-sticky.link{border-style:dashed;cursor:pointer}
|
|
622
|
+
.tb-sticky-head{display:flex;align-items:center;gap:5px;font-size:12px;font-weight:700;line-height:1.3}
|
|
623
|
+
.tb-sticky-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
624
|
+
.tb-sticky-actions{display:flex;gap:3px;opacity:.65}
|
|
625
|
+
.tb-sticky-actions button{appearance:none;border:0;background:rgba(0,0,0,.08);border-radius:4px;font-size:10px;line-height:16px;padding:0 4px;cursor:pointer;color:#2a2418}
|
|
626
|
+
.tb-sticky-actions button:hover{background:rgba(0,0,0,.16)}
|
|
627
|
+
.tb-sticky-body{flex:1;min-height:0;overflow:hidden;font-size:11px;line-height:1.45;color:#3a3326;word-break:break-word;position:relative;z-index:2;pointer-events:none}
|
|
628
|
+
.tb-sticky-body.md{display:-webkit-box;-webkit-line-clamp:5;-webkit-box-orient:vertical}
|
|
629
|
+
.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}
|
|
630
|
+
.tb-sticky-src{font-size:9.5px;font-weight:600;opacity:.6;white-space:nowrap}
|
|
631
|
+
.tb-sticky-draw{position:absolute;inset:0;pointer-events:none;z-index:3}
|
|
632
|
+
.tb-sticky-head{position:relative;z-index:4}
|
|
633
|
+
.tb-sticky-resize{position:absolute;right:0;bottom:0;width:16px;height:16px;cursor:nwse-resize;z-index:6;opacity:.55}
|
|
634
|
+
.tb-sticky-resize:after{content:"";position:absolute;right:3px;bottom:3px;width:8px;height:8px;border-right:2px solid rgba(0,0,0,.45);border-bottom:2px solid rgba(0,0,0,.45)}
|
|
635
|
+
.tb-sticky:hover .tb-sticky-resize{opacity:.9}
|
|
636
|
+
.tb-sticky-linkline,.tb-sticky-actions{position:relative;z-index:4}
|
|
637
|
+
.tb-board-bgdraw rect,.tb-board-bgdraw ellipse,.tb-board-bgdraw polygon,.tb-board-bgdraw line,.tb-sticky-draw rect,.tb-sticky-draw ellipse,.tb-sticky-draw polygon,.tb-sticky-draw line,.tb-board-bgdraw polyline,.tb-sticky-draw polyline{vector-effect:non-scaling-stroke}
|
|
638
|
+
.tb-board-md-pane{flex:0 0 36%;min-height:140px;overflow:auto;padding:8px 12px 20px;display:flex;flex-direction:column;gap:8px;background:var(--dsw-alias-bg-base,#16181d)}
|
|
639
|
+
.tb-board-md-head{font-size:11px;color:var(--dsw-alias-label-secondary,#9aa0a6);position:sticky;top:0;background:var(--dsw-alias-bg-base,#16181d);padding:2px 0;z-index:1}
|
|
640
|
+
.tb-board-md-item{border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));border-radius:8px;padding:8px 10px;display:flex;flex-direction:column;gap:5px;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.03))}
|
|
641
|
+
.tb-board-md-item.selected{border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
|
|
642
|
+
.tb-board-md-item-head{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
|
|
643
|
+
.tb-board-md-item-title{font-weight:600;font-size:12px}
|
|
644
|
+
.tb-board-md-empty{padding:10px;text-align:center;color:var(--dsw-alias-label-secondary,#9aa0a6);font-size:12px}
|
|
496
645
|
.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)}
|
|
497
646
|
.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}
|
|
498
647
|
.tb-board-title{font-weight:600;font-size:13.5px}
|
|
@@ -2700,6 +2849,217 @@ window.__ModuleLoader__.load({
|
|
|
2700
2849
|
/* global notes board page */
|
|
2701
2850
|
/* ---------------------------------------------------------------- */
|
|
2702
2851
|
|
|
2852
|
+
const BOARD_NOTE_W = 232
|
|
2853
|
+
const BOARD_NOTE_H = 176
|
|
2854
|
+
const BOARD_STAGE_W = 4000
|
|
2855
|
+
const BOARD_STAGE_H = 3000
|
|
2856
|
+
const BOARD_COLORS = ['#e6b84c', '#ff8f7a', '#7ad3ff', '#8be28b', '#d9a8ff', '#ffffff']
|
|
2857
|
+
const BOARD_INKS = [
|
|
2858
|
+
'#e6b84c', '#ff7a7a', '#7ad3ff', '#8be28b', '#d9a8ff', '#ffffff',
|
|
2859
|
+
'#ff9f43', '#ff6b81', '#54a0ff', '#00d2d3', '#10ac84', '#f368e0',
|
|
2860
|
+
'#576574', '#222f3e', '#feca57', '#48dbfb',
|
|
2861
|
+
]
|
|
2862
|
+
|
|
2863
|
+
/** #rrggbb -> [r,g,b]. */
|
|
2864
|
+
function hexToRgb(value) {
|
|
2865
|
+
const match = /^#?([0-9a-f]{6})$/i.exec(String(value || '').trim())
|
|
2866
|
+
if (!match) return [255, 255, 255]
|
|
2867
|
+
const number = parseInt(match[1], 16)
|
|
2868
|
+
return [(number >> 16) & 255, (number >> 8) & 255, number & 255]
|
|
2869
|
+
}
|
|
2870
|
+
|
|
2871
|
+
/** [r,g,b] -> #rrggbb. */
|
|
2872
|
+
function rgbToHex(rgb) {
|
|
2873
|
+
return `#${rgb.map((value) => Math.min(255, Math.max(0, Math.round(Number(value) || 0))).toString(16).padStart(2, '0')).join('')}`
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
const BOARD_ANCHORS = ['top', 'right', 'bottom', 'left']
|
|
2877
|
+
|
|
2878
|
+
function emptyBoardCanvas() {
|
|
2879
|
+
return { notes: {}, background: [], drawings: {}, edges: [] }
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2882
|
+
/** Deep-copy the sticky canvas so React sees new references. */
|
|
2883
|
+
function cloneBoardCanvas(value) {
|
|
2884
|
+
const canvas = value && typeof value === 'object' ? value : {}
|
|
2885
|
+
const copyStrokes = (strokes) =>
|
|
2886
|
+
(Array.isArray(strokes) ? strokes : []).map((stroke) => ({
|
|
2887
|
+
...stroke,
|
|
2888
|
+
points: (Array.isArray(stroke.points) ? stroke.points : []).map((point) => [...point]),
|
|
2889
|
+
}))
|
|
2890
|
+
return {
|
|
2891
|
+
notes: Object.fromEntries(
|
|
2892
|
+
Object.entries(canvas.notes && typeof canvas.notes === 'object' ? canvas.notes : {}).map(([id, layout]) => [id, { ...layout }]),
|
|
2893
|
+
),
|
|
2894
|
+
background: copyStrokes(canvas.background),
|
|
2895
|
+
drawings: Object.fromEntries(
|
|
2896
|
+
Object.entries(canvas.drawings && typeof canvas.drawings === 'object' ? canvas.drawings : {}).map(([id, strokes]) => [id, copyStrokes(strokes)]),
|
|
2897
|
+
),
|
|
2898
|
+
edges: (Array.isArray(canvas.edges) ? canvas.edges : []).map((edge) => ({
|
|
2899
|
+
...edge,
|
|
2900
|
+
from: { ...(edge.from ?? {}) },
|
|
2901
|
+
to: { ...(edge.to ?? {}) },
|
|
2902
|
+
})),
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
|
|
2906
|
+
/** World coordinates of one sticky anchor point. */
|
|
2907
|
+
function boardAnchorPoint(layout, anchor) {
|
|
2908
|
+
const x = Number(layout?.x) || 0
|
|
2909
|
+
const y = Number(layout?.y) || 0
|
|
2910
|
+
const width = Math.min(640, Math.max(160, Number(layout?.width) || BOARD_NOTE_W))
|
|
2911
|
+
const height = Math.min(560, Math.max(120, Number(layout?.height) || BOARD_NOTE_H))
|
|
2912
|
+
if (anchor === 'top') return [x + width / 2, y]
|
|
2913
|
+
if (anchor === 'right') return [x + width, y + height / 2]
|
|
2914
|
+
if (anchor === 'bottom') return [x + width / 2, y + height]
|
|
2915
|
+
return [x, y + height / 2]
|
|
2916
|
+
}
|
|
2917
|
+
|
|
2918
|
+
/** Nearest anchor id to a world point. */
|
|
2919
|
+
function nearestBoardAnchor(layout, point) {
|
|
2920
|
+
let best = BOARD_ANCHORS[0]
|
|
2921
|
+
let bestDistance = Infinity
|
|
2922
|
+
for (const anchor of BOARD_ANCHORS) {
|
|
2923
|
+
const [x, y] = boardAnchorPoint(layout, anchor)
|
|
2924
|
+
const distance = Math.hypot(x - point[0], y - point[1])
|
|
2925
|
+
if (distance < bestDistance) {
|
|
2926
|
+
bestDistance = distance
|
|
2927
|
+
best = anchor
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
return best
|
|
2931
|
+
}
|
|
2932
|
+
|
|
2933
|
+
/** Cubic path between two anchor points (same path in both directions). */
|
|
2934
|
+
function boardEdgePath(from, to) {
|
|
2935
|
+
let [x1, y1] = from
|
|
2936
|
+
let [x2, y2] = to
|
|
2937
|
+
if (x1 > x2 || (x1 === x2 && y1 > y2)) {
|
|
2938
|
+
;[x1, x2] = [x2, x1]
|
|
2939
|
+
;[y1, y2] = [y2, y1]
|
|
2940
|
+
}
|
|
2941
|
+
const dx = Math.max(24, Math.abs(x2 - x1) * 0.4)
|
|
2942
|
+
const dy = Math.max(20, Math.abs(y2 - y1) * 0.25)
|
|
2943
|
+
return `M ${x1} ${y1} C ${x1 + dx} ${y1 + (y2 >= y1 ? dy : -dy)}, ${x2 - dx} ${y2 + (y1 >= y2 ? dy : -dy)}, ${x2} ${y2}`
|
|
2944
|
+
}
|
|
2945
|
+
|
|
2946
|
+
/** Arrowhead polygon points for one arrow stroke. */
|
|
2947
|
+
function boardArrowHead(first, last, size) {
|
|
2948
|
+
const dx = last[0] - first[0]
|
|
2949
|
+
const dy = last[1] - first[1]
|
|
2950
|
+
const length = Math.hypot(dx, dy)
|
|
2951
|
+
if (length < 1) return ''
|
|
2952
|
+
const ux = dx / length
|
|
2953
|
+
const uy = dy / length
|
|
2954
|
+
const px = -uy
|
|
2955
|
+
const py = ux
|
|
2956
|
+
const head = Math.min(18, Math.max(8, size * 4))
|
|
2957
|
+
const width = head * 0.55
|
|
2958
|
+
const p1 = `${last[0] - ux * head + px * width},${last[1] - uy * head + py * width}`
|
|
2959
|
+
const p2 = `${last[0] - ux * head - px * width},${last[1] - uy * head - py * width}`
|
|
2960
|
+
return `${last[0]},${last[1]} ${p1} ${p2}`
|
|
2961
|
+
}
|
|
2962
|
+
|
|
2963
|
+
/** Render pen strokes and common shapes for one stroke layer. */
|
|
2964
|
+
function boardStrokeElements(strokes, keyPrefix) {
|
|
2965
|
+
return (strokes ?? []).map((stroke, index) => {
|
|
2966
|
+
const key = `${keyPrefix}-${index}`
|
|
2967
|
+
const points = stroke.points ?? []
|
|
2968
|
+
const kind = stroke.kind || 'pen'
|
|
2969
|
+
const color = stroke.color
|
|
2970
|
+
const width = stroke.width
|
|
2971
|
+
if (kind === 'pen' || points.length < 2) {
|
|
2972
|
+
return h('polyline', {
|
|
2973
|
+
key,
|
|
2974
|
+
points: points.map((point) => `${point[0]},${point[1]}`).join(' '),
|
|
2975
|
+
fill: 'none',
|
|
2976
|
+
stroke: color,
|
|
2977
|
+
strokeWidth: width,
|
|
2978
|
+
strokeLinecap: 'round',
|
|
2979
|
+
strokeLinejoin: 'round',
|
|
2980
|
+
})
|
|
2981
|
+
}
|
|
2982
|
+
const a = points[0]
|
|
2983
|
+
const b = points[1]
|
|
2984
|
+
const x = Math.min(a[0], b[0])
|
|
2985
|
+
const y = Math.min(a[1], b[1])
|
|
2986
|
+
const w = Math.abs(b[0] - a[0])
|
|
2987
|
+
const hgt = Math.abs(b[1] - a[1])
|
|
2988
|
+
if (kind === 'rect') {
|
|
2989
|
+
return h('rect', { key, x, y, width: w, height: hgt, rx: 2, fill: 'none', stroke: color, strokeWidth: width })
|
|
2990
|
+
}
|
|
2991
|
+
if (kind === 'ellipse') {
|
|
2992
|
+
return h('ellipse', { key, cx: x + w / 2, cy: y + hgt / 2, rx: w / 2, ry: hgt / 2, fill: 'none', stroke: color, strokeWidth: width })
|
|
2993
|
+
}
|
|
2994
|
+
if (kind === 'line') {
|
|
2995
|
+
return h('line', { key, x1: a[0], y1: a[1], x2: b[0], y2: b[1], stroke: color, strokeWidth: width, strokeLinecap: 'round' })
|
|
2996
|
+
}
|
|
2997
|
+
if (kind === 'triangle') {
|
|
2998
|
+
return h('polygon', {
|
|
2999
|
+
key,
|
|
3000
|
+
points: `${(a[0] + b[0]) / 2},${y} ${x},${y + hgt} ${x + w},${y + hgt}`,
|
|
3001
|
+
fill: 'none',
|
|
3002
|
+
stroke: color,
|
|
3003
|
+
strokeWidth: width,
|
|
3004
|
+
strokeLinejoin: 'round',
|
|
3005
|
+
})
|
|
3006
|
+
}
|
|
3007
|
+
if (kind === 'arrow') {
|
|
3008
|
+
return h(
|
|
3009
|
+
'g',
|
|
3010
|
+
{ key },
|
|
3011
|
+
h('line', { x1: a[0], y1: a[1], x2: b[0], y2: b[1], stroke: color, strokeWidth: width, strokeLinecap: 'round' }),
|
|
3012
|
+
h('polygon', { points: boardArrowHead(a, b, width), fill: color, stroke: 'none' }),
|
|
3013
|
+
)
|
|
3014
|
+
}
|
|
3015
|
+
return h('polyline', {
|
|
3016
|
+
key,
|
|
3017
|
+
points: points.map((point) => `${point[0]},${point[1]}`).join(' '),
|
|
3018
|
+
fill: 'none',
|
|
3019
|
+
stroke: color,
|
|
3020
|
+
strokeWidth: width,
|
|
3021
|
+
strokeLinecap: 'round',
|
|
3022
|
+
})
|
|
3023
|
+
})
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
/** Whether an eraser click hits one stroke. */
|
|
3027
|
+
function boardStrokeHit(stroke, point) {
|
|
3028
|
+
const points = stroke.points ?? []
|
|
3029
|
+
if ((stroke.kind || 'pen') === 'pen') {
|
|
3030
|
+
return points.some(([x, y]) => Math.hypot(x - point[0], y - point[1]) < 12)
|
|
3031
|
+
}
|
|
3032
|
+
if (points.length < 2) return false
|
|
3033
|
+
const [a, b] = points
|
|
3034
|
+
return (
|
|
3035
|
+
point[0] >= Math.min(a[0], b[0]) - 10 &&
|
|
3036
|
+
point[0] <= Math.max(a[0], b[0]) + 10 &&
|
|
3037
|
+
point[1] >= Math.min(a[1], b[1]) - 10 &&
|
|
3038
|
+
point[1] <= Math.max(a[1], b[1]) + 10
|
|
3039
|
+
)
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
/** Default position/colour for a note without a saved layout. */
|
|
3043
|
+
function autoBoardLayout(index) {
|
|
3044
|
+
const columns = 5
|
|
3045
|
+
return {
|
|
3046
|
+
x: 24 + (index % columns) * (BOARD_NOTE_W + 20),
|
|
3047
|
+
y: 24 + Math.floor(index / columns) * (BOARD_NOTE_H + 20),
|
|
3048
|
+
width: BOARD_NOTE_W,
|
|
3049
|
+
height: BOARD_NOTE_H,
|
|
3050
|
+
z: index,
|
|
3051
|
+
color: BOARD_COLORS[index % BOARD_COLORS.length],
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
|
|
3055
|
+
const BOARD_SHAPES = [
|
|
3056
|
+
['rect', '▭', 'board.shapeRect'],
|
|
3057
|
+
['ellipse', '◯', 'board.shapeEllipse'],
|
|
3058
|
+
['line', '╱', 'board.shapeLine'],
|
|
3059
|
+
['arrow', '→', 'board.shapeArrow'],
|
|
3060
|
+
['triangle', '△', 'board.shapeTriangle'],
|
|
3061
|
+
]
|
|
3062
|
+
|
|
2703
3063
|
function BoardPanel(props) {
|
|
2704
3064
|
const t = typeof props?.t === 'function' ? props.t : (key) => key
|
|
2705
3065
|
const [state, setState] = React.useState({ loading: true, board: null, error: null })
|
|
@@ -2720,11 +3080,76 @@ window.__ModuleLoader__.load({
|
|
|
2720
3080
|
})
|
|
2721
3081
|
const dialogSizeRef = React.useRef(dialogSize)
|
|
2722
3082
|
dialogSizeRef.current = dialogSize
|
|
3083
|
+
const [canvas, setCanvas] = React.useState(emptyBoardCanvas)
|
|
3084
|
+
const canvasRef = React.useRef(canvas)
|
|
3085
|
+
canvasRef.current = canvas
|
|
3086
|
+
const [tool, setTool] = React.useState('select')
|
|
3087
|
+
const toolRef = React.useRef(tool)
|
|
3088
|
+
toolRef.current = tool
|
|
3089
|
+
const [ink, setInk] = React.useState(() => {
|
|
3090
|
+
try {
|
|
3091
|
+
const stored = window.localStorage.getItem('dsh-timeback:board-ink-color') || ''
|
|
3092
|
+
return /^#[0-9a-f]{6}$/i.test(stored) ? stored.toLowerCase() : BOARD_INKS[0]
|
|
3093
|
+
} catch {
|
|
3094
|
+
return BOARD_INKS[0]
|
|
3095
|
+
}
|
|
3096
|
+
})
|
|
3097
|
+
const inkRef = React.useRef(ink)
|
|
3098
|
+
inkRef.current = ink
|
|
3099
|
+
const [inkWidth, setInkWidth] = React.useState(() => {
|
|
3100
|
+
try {
|
|
3101
|
+
const raw = Number(window.localStorage.getItem('dsh-timeback:board-ink-width'))
|
|
3102
|
+
return Number.isFinite(raw) && raw >= 1 && raw <= 8 ? Math.round(raw) : 2
|
|
3103
|
+
} catch {
|
|
3104
|
+
return 2
|
|
3105
|
+
}
|
|
3106
|
+
})
|
|
3107
|
+
const inkWidthRef = React.useRef(inkWidth)
|
|
3108
|
+
inkWidthRef.current = inkWidth
|
|
3109
|
+
const [shapeMenu, setShapeMenu] = React.useState(false)
|
|
3110
|
+
const [colorOpen, setColorOpen] = React.useState(false)
|
|
3111
|
+
const [colorHint, setColorHint] = React.useState('')
|
|
3112
|
+
const [recentColors, setRecentColors] = React.useState(() => {
|
|
3113
|
+
try {
|
|
3114
|
+
const raw = JSON.parse(window.localStorage.getItem('dsh-timeback:board-recent-colors') || '[]')
|
|
3115
|
+
return Array.isArray(raw) ? raw.filter((value) => /^#[0-9a-f]{6}$/i.test(String(value))).slice(0, 8) : []
|
|
3116
|
+
} catch {
|
|
3117
|
+
return []
|
|
3118
|
+
}
|
|
3119
|
+
})
|
|
3120
|
+
const [selected, setSelected] = React.useState('')
|
|
3121
|
+
const selectedRef = React.useRef(selected)
|
|
3122
|
+
selectedRef.current = selected
|
|
3123
|
+
const [readerId, setReaderId] = React.useState('')
|
|
3124
|
+
const [linkPreview, setLinkPreview] = React.useState(null)
|
|
3125
|
+
const [zoom, setZoom] = React.useState(1)
|
|
3126
|
+
const zoomRef = React.useRef(zoom)
|
|
3127
|
+
zoomRef.current = zoom
|
|
3128
|
+
const [drawOnSticky, setDrawOnSticky] = React.useState(() => {
|
|
3129
|
+
try {
|
|
3130
|
+
return window.localStorage.getItem('dsh-timeback:board-draw-on-sticky') !== '0'
|
|
3131
|
+
} catch {
|
|
3132
|
+
return true
|
|
3133
|
+
}
|
|
3134
|
+
})
|
|
3135
|
+
const drawOnStickyRef = React.useRef(drawOnSticky)
|
|
3136
|
+
drawOnStickyRef.current = drawOnSticky
|
|
3137
|
+
const centeredRef = React.useRef(false)
|
|
3138
|
+
const stageRef = React.useRef(null)
|
|
3139
|
+
const viewportRef = React.useRef(null)
|
|
3140
|
+
const saveTimerRef = React.useRef(null)
|
|
3141
|
+
const gestureRef = React.useRef(null)
|
|
2723
3142
|
|
|
2724
3143
|
const refresh = React.useCallback(async () => {
|
|
2725
3144
|
try {
|
|
2726
3145
|
const body = await request('notes')
|
|
2727
|
-
|
|
3146
|
+
const board = body.board ?? null
|
|
3147
|
+
setState({ loading: false, board, error: null })
|
|
3148
|
+
if (board) {
|
|
3149
|
+
const next = cloneBoardCanvas(board.canvas)
|
|
3150
|
+
canvasRef.current = next
|
|
3151
|
+
setCanvas(next)
|
|
3152
|
+
}
|
|
2728
3153
|
} catch (error) {
|
|
2729
3154
|
setState((previous) => ({ ...previous, loading: false, error: error?.message || String(error) }))
|
|
2730
3155
|
}
|
|
@@ -2739,6 +3164,87 @@ window.__ModuleLoader__.load({
|
|
|
2739
3164
|
return () => window.removeEventListener('dsh-timeback:board-changed', handler)
|
|
2740
3165
|
}, [refresh])
|
|
2741
3166
|
|
|
3167
|
+
React.useEffect(() => () => {
|
|
3168
|
+
if (saveTimerRef.current) clearTimeout(saveTimerRef.current)
|
|
3169
|
+
}, [])
|
|
3170
|
+
|
|
3171
|
+
/** Fit every note/stroke into view: pick a zoom and scroll offset. */
|
|
3172
|
+
const autoFit = () => {
|
|
3173
|
+
const viewport = viewportRef.current
|
|
3174
|
+
if (!viewport) return
|
|
3175
|
+
const notes = (state.board?.entries ?? []).map((entry, index) => layoutFor(entry, index))
|
|
3176
|
+
let minX = Infinity
|
|
3177
|
+
let minY = Infinity
|
|
3178
|
+
let maxX = -Infinity
|
|
3179
|
+
let maxY = -Infinity
|
|
3180
|
+
const include = (x, y) => {
|
|
3181
|
+
if (Number.isFinite(x) && Number.isFinite(y)) {
|
|
3182
|
+
minX = Math.min(minX, x)
|
|
3183
|
+
minY = Math.min(minY, y)
|
|
3184
|
+
maxX = Math.max(maxX, x)
|
|
3185
|
+
maxY = Math.max(maxY, y)
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
for (const layout of notes) {
|
|
3189
|
+
const size = noteSize(layout)
|
|
3190
|
+
include(Number(layout.x) || 0, Number(layout.y) || 0)
|
|
3191
|
+
include((Number(layout.x) || 0) + size.width, (Number(layout.y) || 0) + size.height)
|
|
3192
|
+
}
|
|
3193
|
+
const addStrokes = (strokes) => {
|
|
3194
|
+
for (const stroke of strokes ?? []) for (const point of stroke.points ?? []) include(point[0], point[1])
|
|
3195
|
+
}
|
|
3196
|
+
addStrokes(canvasRef.current.background)
|
|
3197
|
+
for (const strokes of Object.values(canvasRef.current.drawings ?? {})) addStrokes(strokes)
|
|
3198
|
+
if (!Number.isFinite(minX)) {
|
|
3199
|
+
minX = BOARD_STAGE_W / 2 - 300
|
|
3200
|
+
maxX = BOARD_STAGE_W / 2 + 300
|
|
3201
|
+
minY = BOARD_STAGE_H / 2 - 200
|
|
3202
|
+
maxY = BOARD_STAGE_H / 2 + 200
|
|
3203
|
+
}
|
|
3204
|
+
const spanX = Math.max(120, maxX - minX)
|
|
3205
|
+
const spanY = Math.max(120, maxY - minY)
|
|
3206
|
+
const nextZoom = Math.min(1.6, Math.max(0.2, Math.min((viewport.clientWidth - 40) / spanX, (viewport.clientHeight - 40) / spanY)))
|
|
3207
|
+
setZoom(nextZoom)
|
|
3208
|
+
zoomRef.current = nextZoom
|
|
3209
|
+
const centerX = (minX + maxX) / 2
|
|
3210
|
+
const centerY = (minY + maxY) / 2
|
|
3211
|
+
window.requestAnimationFrame(() => {
|
|
3212
|
+
const currentViewport = viewportRef.current
|
|
3213
|
+
if (!currentViewport) return
|
|
3214
|
+
currentViewport.scrollLeft = Math.max(0, centerX * nextZoom - currentViewport.clientWidth / 2)
|
|
3215
|
+
currentViewport.scrollTop = Math.max(0, centerY * nextZoom - currentViewport.clientHeight / 2)
|
|
3216
|
+
})
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3219
|
+
React.useEffect(() => {
|
|
3220
|
+
if (!state.board || centeredRef.current) return
|
|
3221
|
+
centeredRef.current = true
|
|
3222
|
+
const frame = window.requestAnimationFrame(() => autoFit())
|
|
3223
|
+
return () => window.cancelAnimationFrame(frame)
|
|
3224
|
+
}, [state.board])
|
|
3225
|
+
|
|
3226
|
+
/** Read one Markdown note in a large overlay. */
|
|
3227
|
+
const openReader = (id) => {
|
|
3228
|
+
setSelected(id)
|
|
3229
|
+
setReaderId(id)
|
|
3230
|
+
}
|
|
3231
|
+
|
|
3232
|
+
/** Persist the canvas shortly after the last change (drag/draw). */
|
|
3233
|
+
const saveCanvasSoon = (next) => {
|
|
3234
|
+
canvasRef.current = next
|
|
3235
|
+
setCanvas(next)
|
|
3236
|
+
if (saveTimerRef.current) clearTimeout(saveTimerRef.current)
|
|
3237
|
+
saveTimerRef.current = setTimeout(async () => {
|
|
3238
|
+
saveTimerRef.current = null
|
|
3239
|
+
try {
|
|
3240
|
+
const body = await request('action', { method: 'POST', body: { action: 'board-canvas', canvas: next } })
|
|
3241
|
+
setState((previous) => ({ ...previous, board: body.board ?? previous.board, error: null }))
|
|
3242
|
+
} catch (error) {
|
|
3243
|
+
setState((previous) => ({ ...previous, error: error?.message || String(error) }))
|
|
3244
|
+
}
|
|
3245
|
+
}, 420)
|
|
3246
|
+
}
|
|
3247
|
+
|
|
2742
3248
|
const persistDialogSize = (value) => {
|
|
2743
3249
|
try {
|
|
2744
3250
|
window.localStorage.setItem('dsh-timeback:board-dialog-size', JSON.stringify(value))
|
|
@@ -2784,13 +3290,74 @@ window.__ModuleLoader__.load({
|
|
|
2784
3290
|
window.addEventListener('pointercancel', finish)
|
|
2785
3291
|
}
|
|
2786
3292
|
|
|
2787
|
-
const entries =
|
|
3293
|
+
const entries = state.board?.entries ?? []
|
|
3294
|
+
const sortedEntries = [...entries].sort((left, right) => (right.updatedAt ?? 0) - (left.updatedAt ?? 0))
|
|
2788
3295
|
const boardVersion = state.board?.version ?? 0
|
|
3296
|
+
const layoutFor = (entry, index) => canvas.notes[entry.id] ?? autoBoardLayout(index)
|
|
3297
|
+
const noteSize = (layout) => ({
|
|
3298
|
+
width: Math.min(640, Math.max(160, Number(layout?.width) || BOARD_NOTE_W)),
|
|
3299
|
+
height: Math.min(560, Math.max(120, Number(layout?.height) || BOARD_NOTE_H)),
|
|
3300
|
+
})
|
|
3301
|
+
/** Viewport client point -> unscaled stage coordinates. */
|
|
3302
|
+
const stagePoint = (event) => {
|
|
3303
|
+
const stage = stageRef.current
|
|
3304
|
+
if (!stage) return [event.clientX, event.clientY]
|
|
3305
|
+
const rect = stage.getBoundingClientRect()
|
|
3306
|
+
const scale = zoomRef.current || 1
|
|
3307
|
+
return [(event.clientX - rect.left) / scale, (event.clientY - rect.top) / scale]
|
|
3308
|
+
}
|
|
3309
|
+
/** Viewport rect of a sticky, as unscaled stage-relative offsets. */
|
|
3310
|
+
const noteOffsets = (element) => {
|
|
3311
|
+
const stage = stageRef.current
|
|
3312
|
+
if (!stage) return { left: 0, top: 0 }
|
|
3313
|
+
const stageRect = stage.getBoundingClientRect()
|
|
3314
|
+
const rect = element.getBoundingClientRect()
|
|
3315
|
+
const scale = zoomRef.current || 1
|
|
3316
|
+
return { left: (rect.left - stageRect.left) / scale, top: (rect.top - stageRect.top) / scale }
|
|
3317
|
+
}
|
|
3318
|
+
const offsetsFromRect = (rect) => {
|
|
3319
|
+
const stage = stageRef.current
|
|
3320
|
+
if (!stage) return { left: 0, top: 0 }
|
|
3321
|
+
const stageRect = stage.getBoundingClientRect()
|
|
3322
|
+
const scale = zoomRef.current || 1
|
|
3323
|
+
return { left: (rect.left - stageRect.left) / scale, top: (rect.top - stageRect.top) / scale }
|
|
3324
|
+
}
|
|
3325
|
+
const zoomScale = () => zoomRef.current || 1
|
|
3326
|
+
|
|
3327
|
+
/** Which layer (background or one sticky) is under the pointer. */
|
|
3328
|
+
const layerAt = (event) => {
|
|
3329
|
+
let element = event.target
|
|
3330
|
+
try {
|
|
3331
|
+
if (typeof document !== 'undefined' && typeof document.elementFromPoint === 'function') {
|
|
3332
|
+
element = document.elementFromPoint(event.clientX, event.clientY) || element
|
|
3333
|
+
}
|
|
3334
|
+
} catch {
|
|
3335
|
+
// elementFromPoint is a convenience; event.target is the fallback.
|
|
3336
|
+
}
|
|
3337
|
+
const noteElement = element?.closest?.('.tb-sticky')
|
|
3338
|
+
if (noteElement) {
|
|
3339
|
+
return {
|
|
3340
|
+
layer: 'note',
|
|
3341
|
+
noteId: noteElement.getAttribute('data-note-id') || '',
|
|
3342
|
+
rect: noteElement.getBoundingClientRect(),
|
|
3343
|
+
}
|
|
3344
|
+
}
|
|
3345
|
+
const stage = stageRef.current
|
|
3346
|
+
return stage ? { layer: 'background', noteId: '', rect: stage.getBoundingClientRect() } : null
|
|
3347
|
+
}
|
|
2789
3348
|
const startCreate = () => setDraft({ id: '', title: '', body: '', preview: false, busy: false, error: null })
|
|
2790
3349
|
const startEdit = (entry) => setDraft({ id: entry.id, title: entry.title, body: entry.body, preview: false, busy: false, error: null })
|
|
2791
3350
|
const closeDraft = () => {
|
|
2792
3351
|
if (draft && !draft.busy) setDraft(null)
|
|
2793
3352
|
}
|
|
3353
|
+
const focusEntry = (id) => {
|
|
3354
|
+
setSelected(id)
|
|
3355
|
+
try {
|
|
3356
|
+
if (typeof document !== 'undefined') document.getElementById(`tb-md-${id}`)?.scrollIntoView({ block: 'nearest' })
|
|
3357
|
+
} catch {
|
|
3358
|
+
// Scrolling is a convenience.
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
2794
3361
|
const saveDraft = async () => {
|
|
2795
3362
|
if (!draft || draft.busy) return
|
|
2796
3363
|
setDraft({ ...draft, busy: true, error: null })
|
|
@@ -2799,8 +3366,17 @@ window.__ModuleLoader__.load({
|
|
|
2799
3366
|
method: 'POST',
|
|
2800
3367
|
body: { action: 'note-save', ...(draft.id ? { id: draft.id } : {}), title: draft.title, body: draft.body },
|
|
2801
3368
|
})
|
|
3369
|
+
const board = body.board ?? state.board
|
|
2802
3370
|
setDraft(null)
|
|
2803
|
-
setState({ loading: false, board
|
|
3371
|
+
setState({ loading: false, board, error: null })
|
|
3372
|
+
// Put a brand-new note where the sticky board expects one.
|
|
3373
|
+
if (!draft.id && body.entry?.id && board && !canvasRef.current.notes[body.entry.id]) {
|
|
3374
|
+
const index = Math.max(0, (board.entries?.length ?? 1) - 1)
|
|
3375
|
+
saveCanvasSoon({
|
|
3376
|
+
...canvasRef.current,
|
|
3377
|
+
notes: { ...canvasRef.current.notes, [body.entry.id]: autoBoardLayout(index) },
|
|
3378
|
+
})
|
|
3379
|
+
}
|
|
2804
3380
|
} catch (error) {
|
|
2805
3381
|
setDraft({ ...draft, busy: false, error: error?.message || String(error) })
|
|
2806
3382
|
}
|
|
@@ -2818,6 +3394,10 @@ window.__ModuleLoader__.load({
|
|
|
2818
3394
|
try {
|
|
2819
3395
|
const body = await request('action', { method: 'POST', body: { action: 'note-delete', id } })
|
|
2820
3396
|
setState({ loading: false, board: body.board ?? state.board, error: null })
|
|
3397
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3398
|
+
delete next.notes[id]
|
|
3399
|
+
delete next.drawings[id]
|
|
3400
|
+
saveCanvasSoon(next)
|
|
2821
3401
|
} catch (error) {
|
|
2822
3402
|
setState((previous) => ({ ...previous, error: error?.message || String(error) }))
|
|
2823
3403
|
} finally {
|
|
@@ -2825,6 +3405,836 @@ window.__ModuleLoader__.load({
|
|
|
2825
3405
|
}
|
|
2826
3406
|
}
|
|
2827
3407
|
|
|
3408
|
+
/* -------------------------------------------------------------- */
|
|
3409
|
+
/* sticky canvas: drag notes and draw strokes */
|
|
3410
|
+
/* -------------------------------------------------------------- */
|
|
3411
|
+
|
|
3412
|
+
/** Ctrl/Shift snapping: shapes stay square/circular, lines/arrows snap to 45°. */
|
|
3413
|
+
const snapShapeEnd = (gesture, world) => {
|
|
3414
|
+
const [sx, sy] = gesture.startWorld
|
|
3415
|
+
const dx = world[0] - sx
|
|
3416
|
+
const dy = world[1] - sy
|
|
3417
|
+
const ctrl = gesture.ctrl
|
|
3418
|
+
if (!ctrl) return world
|
|
3419
|
+
if (gesture.kind === 'line' || gesture.kind === 'arrow') {
|
|
3420
|
+
const length = Math.hypot(dx, dy)
|
|
3421
|
+
if (length < 1) return world
|
|
3422
|
+
const step = Math.PI / 4
|
|
3423
|
+
const angle = Math.round(Math.atan2(dy, dx) / step) * step
|
|
3424
|
+
return [Math.round(sx + Math.cos(angle) * length), Math.round(sy + Math.sin(angle) * length)]
|
|
3425
|
+
}
|
|
3426
|
+
const size = Math.max(Math.abs(dx), Math.abs(dy))
|
|
3427
|
+
return [sx + (dx < 0 ? -size : size), sy + (dy < 0 ? -size : size)]
|
|
3428
|
+
}
|
|
3429
|
+
|
|
3430
|
+
/**
|
|
3431
|
+
* Build the shape preview on BOTH layers: the background copy always, plus
|
|
3432
|
+
* one copy on every sticky the shape touched (so the sticky shows the
|
|
3433
|
+
* clipped part even when the pointer ends outside it).
|
|
3434
|
+
*/
|
|
3435
|
+
const buildShapeCanvas = (gesture) => {
|
|
3436
|
+
const next = cloneBoardCanvas(gesture.baseCanvas)
|
|
3437
|
+
const start = gesture.startWorld
|
|
3438
|
+
const end = snapShapeEnd(gesture, gesture.endWorld)
|
|
3439
|
+
next.background.push({
|
|
3440
|
+
kind: gesture.kind,
|
|
3441
|
+
color: gesture.color,
|
|
3442
|
+
width: gesture.width,
|
|
3443
|
+
points: [start, end],
|
|
3444
|
+
})
|
|
3445
|
+
for (const [noteId, offset] of gesture.targets) {
|
|
3446
|
+
const local = [
|
|
3447
|
+
[start[0] - offset.left, start[1] - offset.top],
|
|
3448
|
+
[end[0] - offset.left, end[1] - offset.top],
|
|
3449
|
+
]
|
|
3450
|
+
const list = [...(next.drawings[noteId] ?? [])]
|
|
3451
|
+
list.push({ kind: gesture.kind, color: gesture.color, width: gesture.width, points: local })
|
|
3452
|
+
next.drawings[noteId] = list
|
|
3453
|
+
}
|
|
3454
|
+
return next
|
|
3455
|
+
}
|
|
3456
|
+
|
|
3457
|
+
const setGesture = (gesture) => {
|
|
3458
|
+
gestureRef.current = gesture
|
|
3459
|
+
const move = (event) => {
|
|
3460
|
+
const current = gestureRef.current
|
|
3461
|
+
if (!current) return
|
|
3462
|
+
if (current.type === 'link') {
|
|
3463
|
+
const localPoint = stagePoint(event)
|
|
3464
|
+
const under = layerAt(event)
|
|
3465
|
+
let targetNoteId = ''
|
|
3466
|
+
let targetAnchor = ''
|
|
3467
|
+
if (under?.layer === 'note' && under.noteId && under.noteId !== current.fromNoteId) {
|
|
3468
|
+
const layout = canvasRef.current.notes[under.noteId] ?? autoBoardLayout(0)
|
|
3469
|
+
targetNoteId = under.noteId
|
|
3470
|
+
targetAnchor = nearestBoardAnchor(layout, localPoint)
|
|
3471
|
+
}
|
|
3472
|
+
setLinkPreview((previous) =>
|
|
3473
|
+
previous
|
|
3474
|
+
? { ...previous, pointer: localPoint, targetNoteId, targetAnchor }
|
|
3475
|
+
: previous,
|
|
3476
|
+
)
|
|
3477
|
+
return
|
|
3478
|
+
}
|
|
3479
|
+
if (current.type === 'shape') {
|
|
3480
|
+
const under = layerAt(event)
|
|
3481
|
+
if (under?.layer === 'note' && drawOnStickyRef.current && under.noteId && !current.targets.has(under.noteId)) {
|
|
3482
|
+
current.targets.set(under.noteId, offsetsFromRect(under.rect))
|
|
3483
|
+
}
|
|
3484
|
+
current.endWorld = stagePoint(event)
|
|
3485
|
+
current.ctrl = event.ctrlKey || event.metaKey || event.shiftKey
|
|
3486
|
+
const next = buildShapeCanvas(current)
|
|
3487
|
+
canvasRef.current = next
|
|
3488
|
+
setCanvas(next)
|
|
3489
|
+
return
|
|
3490
|
+
}
|
|
3491
|
+
if (current.type === 'pan') {
|
|
3492
|
+
const viewport = viewportRef.current
|
|
3493
|
+
if (viewport) {
|
|
3494
|
+
viewport.scrollLeft = current.scrollLeft - (event.clientX - current.startX)
|
|
3495
|
+
viewport.scrollTop = current.scrollTop - (event.clientY - current.startY)
|
|
3496
|
+
}
|
|
3497
|
+
return
|
|
3498
|
+
}
|
|
3499
|
+
if (current.type === 'resize') {
|
|
3500
|
+
const scale = zoomScale()
|
|
3501
|
+
const width = Math.min(640, Math.max(160, Math.round(current.startW + (event.clientX - current.startX) / scale)))
|
|
3502
|
+
const height = Math.min(560, Math.max(120, Math.round(current.startH + (event.clientY - current.startY) / scale)))
|
|
3503
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3504
|
+
const layout = next.notes[current.noteId] ?? autoBoardLayout(0)
|
|
3505
|
+
layout.width = width
|
|
3506
|
+
layout.height = height
|
|
3507
|
+
next.notes[current.noteId] = layout
|
|
3508
|
+
canvasRef.current = next
|
|
3509
|
+
setCanvas(next)
|
|
3510
|
+
return
|
|
3511
|
+
}
|
|
3512
|
+
if (current.type === 'drag') {
|
|
3513
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3514
|
+
const layout = { ...(next.notes[current.noteId] ?? autoBoardLayout(0)) }
|
|
3515
|
+
const size = noteSize(layout)
|
|
3516
|
+
const scale = zoomScale()
|
|
3517
|
+
layout.x = Math.max(0, Math.min(BOARD_STAGE_W - size.width, current.originX + (event.clientX - current.startX) / scale))
|
|
3518
|
+
layout.y = Math.max(0, Math.min(BOARD_STAGE_H - size.height, current.originY + (event.clientY - current.startY) / scale))
|
|
3519
|
+
next.notes[current.noteId] = layout
|
|
3520
|
+
canvasRef.current = next
|
|
3521
|
+
setCanvas(next)
|
|
3522
|
+
return
|
|
3523
|
+
}
|
|
3524
|
+
const scale = zoomScale()
|
|
3525
|
+
const point = [Math.round((event.clientX - current.rect.left) / scale), Math.round((event.clientY - current.rect.top) / scale)]
|
|
3526
|
+
if (current.type === 'draw') {
|
|
3527
|
+
const stroke = current.stroke
|
|
3528
|
+
if (!current.shape) {
|
|
3529
|
+
const under = layerAt(event)
|
|
3530
|
+
const changed =
|
|
3531
|
+
under &&
|
|
3532
|
+
(under.layer !== current.layer || (under.layer === 'note' && under.noteId !== current.noteId)) &&
|
|
3533
|
+
!(under.layer === 'note' && !drawOnStickyRef.current)
|
|
3534
|
+
if (changed) {
|
|
3535
|
+
const previous = current.lastWorld ?? [event.clientX, event.clientY]
|
|
3536
|
+
const crossScale = zoomScale()
|
|
3537
|
+
const local = [
|
|
3538
|
+
Math.round((previous[0] - under.rect.left) / crossScale),
|
|
3539
|
+
Math.round((previous[1] - under.rect.top) / crossScale),
|
|
3540
|
+
]
|
|
3541
|
+
const localCurrent = [
|
|
3542
|
+
Math.round((event.clientX - under.rect.left) / crossScale),
|
|
3543
|
+
Math.round((event.clientY - under.rect.top) / crossScale),
|
|
3544
|
+
]
|
|
3545
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3546
|
+
// Extend the old stroke to the crossing point so the sticky edge
|
|
3547
|
+
// is not left with a gap (the sticky's own SVG clips it).
|
|
3548
|
+
const oldLocal = [
|
|
3549
|
+
Math.round((event.clientX - current.rect.left) / crossScale),
|
|
3550
|
+
Math.round((event.clientY - current.rect.top) / crossScale),
|
|
3551
|
+
]
|
|
3552
|
+
const oldLast = stroke.points[stroke.points.length - 1]
|
|
3553
|
+
if (!oldLast || oldLast[0] !== oldLocal[0] || oldLast[1] !== oldLocal[1]) stroke.points.push(oldLocal)
|
|
3554
|
+
if (current.layer === 'background') {
|
|
3555
|
+
next.background = [...next.background]
|
|
3556
|
+
next.background[current.strokeIndex] = { ...stroke, points: stroke.points.map((item) => [...item]) }
|
|
3557
|
+
} else {
|
|
3558
|
+
const list = [...(next.drawings[current.noteId] ?? [])]
|
|
3559
|
+
list[current.strokeIndex] = { ...stroke, points: stroke.points.map((item) => [...item]) }
|
|
3560
|
+
next.drawings[current.noteId] = list
|
|
3561
|
+
}
|
|
3562
|
+
const nextStroke = {
|
|
3563
|
+
kind: 'pen',
|
|
3564
|
+
color: stroke.color,
|
|
3565
|
+
width: stroke.width,
|
|
3566
|
+
points: local[0] === localCurrent[0] && local[1] === localCurrent[1] ? [local] : [local, localCurrent],
|
|
3567
|
+
}
|
|
3568
|
+
let nextIndex
|
|
3569
|
+
if (under.layer === 'background') {
|
|
3570
|
+
nextIndex = next.background.length
|
|
3571
|
+
next.background.push(nextStroke)
|
|
3572
|
+
} else {
|
|
3573
|
+
const list = [...(next.drawings[under.noteId] ?? [])]
|
|
3574
|
+
nextIndex = list.length
|
|
3575
|
+
list.push(nextStroke)
|
|
3576
|
+
next.drawings[under.noteId] = list
|
|
3577
|
+
}
|
|
3578
|
+
current.layer = under.layer
|
|
3579
|
+
current.noteId = under.noteId
|
|
3580
|
+
current.rect = under.rect
|
|
3581
|
+
current.stroke = nextStroke
|
|
3582
|
+
current.strokeIndex = nextIndex
|
|
3583
|
+
current.lastWorld = [event.clientX, event.clientY]
|
|
3584
|
+
canvasRef.current = next
|
|
3585
|
+
setCanvas(next)
|
|
3586
|
+
return
|
|
3587
|
+
}
|
|
3588
|
+
}
|
|
3589
|
+
if (current.shape) {
|
|
3590
|
+
const underShape = layerAt(event)
|
|
3591
|
+
const shapeChanged =
|
|
3592
|
+
underShape &&
|
|
3593
|
+
(underShape.layer !== current.layer || (underShape.layer === 'note' && underShape.noteId !== current.noteId)) &&
|
|
3594
|
+
!(underShape.layer === 'note' && !drawOnStickyRef.current)
|
|
3595
|
+
if (shapeChanged) {
|
|
3596
|
+
const startWorld = current.startWorld ?? [event.clientX, event.clientY]
|
|
3597
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3598
|
+
if (current.layer === 'background') {
|
|
3599
|
+
next.background = next.background.filter((_, index) => index !== current.strokeIndex)
|
|
3600
|
+
} else {
|
|
3601
|
+
const list = (next.drawings[current.noteId] ?? []).filter((_, index) => index !== current.strokeIndex)
|
|
3602
|
+
if (list.length > 0) next.drawings[current.noteId] = list
|
|
3603
|
+
else delete next.drawings[current.noteId]
|
|
3604
|
+
}
|
|
3605
|
+
current.layer = underShape.layer
|
|
3606
|
+
current.noteId = underShape.noteId
|
|
3607
|
+
current.rect = underShape.rect
|
|
3608
|
+
stroke.points = [
|
|
3609
|
+
[startWorld[0] - underShape.rect.left, startWorld[1] - underShape.rect.top],
|
|
3610
|
+
[event.clientX - underShape.rect.left, event.clientY - underShape.rect.top],
|
|
3611
|
+
]
|
|
3612
|
+
let nextIndex
|
|
3613
|
+
if (underShape.layer === 'background') {
|
|
3614
|
+
nextIndex = next.background.length
|
|
3615
|
+
next.background.push(stroke)
|
|
3616
|
+
} else {
|
|
3617
|
+
const list = [...(next.drawings[underShape.noteId] ?? [])]
|
|
3618
|
+
nextIndex = list.length
|
|
3619
|
+
list.push(stroke)
|
|
3620
|
+
next.drawings[underShape.noteId] = list
|
|
3621
|
+
}
|
|
3622
|
+
current.strokeIndex = nextIndex
|
|
3623
|
+
canvasRef.current = next
|
|
3624
|
+
setCanvas(next)
|
|
3625
|
+
return
|
|
3626
|
+
}
|
|
3627
|
+
const startPoint = stroke.points[0]
|
|
3628
|
+
const ctrl = event.ctrlKey || event.metaKey || event.shiftKey
|
|
3629
|
+
const dx = point[0] - startPoint[0]
|
|
3630
|
+
const dy = point[1] - startPoint[1]
|
|
3631
|
+
if (ctrl && (current.stroke.kind === 'line' || current.stroke.kind === 'arrow')) {
|
|
3632
|
+
// Ctrl/Shift snaps lines and arrows to the nearest cardinal direction.
|
|
3633
|
+
stroke.points[1] = Math.abs(dx) >= Math.abs(dy)
|
|
3634
|
+
? [point[0], startPoint[1]]
|
|
3635
|
+
: [startPoint[0], point[1]]
|
|
3636
|
+
} else if (ctrl) {
|
|
3637
|
+
const size = Math.max(Math.abs(dx), Math.abs(dy))
|
|
3638
|
+
stroke.points[1] = [startPoint[0] + (dx < 0 ? -size : size), startPoint[1] + (dy < 0 ? -size : size)]
|
|
3639
|
+
} else {
|
|
3640
|
+
stroke.points[1] = point
|
|
3641
|
+
}
|
|
3642
|
+
} else {
|
|
3643
|
+
const last = stroke.points[stroke.points.length - 1]
|
|
3644
|
+
if (last && Math.abs(last[0] - point[0]) + Math.abs(last[1] - point[1]) < 2) return
|
|
3645
|
+
if (stroke.points.length >= 800) return
|
|
3646
|
+
stroke.points.push(point)
|
|
3647
|
+
current.lastWorld = [event.clientX, event.clientY]
|
|
3648
|
+
}
|
|
3649
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3650
|
+
if (current.layer === 'background') {
|
|
3651
|
+
next.background = [...next.background]
|
|
3652
|
+
next.background[current.strokeIndex] = { ...stroke, points: stroke.points.map((item) => [...item]) }
|
|
3653
|
+
} else {
|
|
3654
|
+
const list = [...(next.drawings[current.noteId] ?? [])]
|
|
3655
|
+
list[current.strokeIndex] = { ...stroke, points: stroke.points.map((item) => [...item]) }
|
|
3656
|
+
next.drawings[current.noteId] = list
|
|
3657
|
+
}
|
|
3658
|
+
canvasRef.current = next
|
|
3659
|
+
setCanvas(next)
|
|
3660
|
+
} else if (current.type === 'erase') {
|
|
3661
|
+
eraseAt(current, point)
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
const finish = (event) => {
|
|
3665
|
+
window.removeEventListener('pointermove', move)
|
|
3666
|
+
window.removeEventListener('pointerup', finish)
|
|
3667
|
+
window.removeEventListener('pointercancel', finish)
|
|
3668
|
+
const current = gestureRef.current
|
|
3669
|
+
gestureRef.current = null
|
|
3670
|
+
if (current && current.type === 'link') {
|
|
3671
|
+
setLinkPreview(null)
|
|
3672
|
+
const under = event ? layerAt(event) : null
|
|
3673
|
+
if (!under || under.layer !== 'note' || !under.noteId || under.noteId === current.fromNoteId) return
|
|
3674
|
+
const localPoint = stagePoint(event)
|
|
3675
|
+
const layout = canvasRef.current.notes[under.noteId] ?? autoBoardLayout(0)
|
|
3676
|
+
const anchor = nearestBoardAnchor(layout, localPoint)
|
|
3677
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3678
|
+
next.edges.push({
|
|
3679
|
+
id: `eg-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
|
|
3680
|
+
from: { noteId: current.fromNoteId, anchor: current.fromAnchor },
|
|
3681
|
+
to: { noteId: under.noteId, anchor },
|
|
3682
|
+
color: inkRef.current,
|
|
3683
|
+
})
|
|
3684
|
+
saveCanvasSoon(next)
|
|
3685
|
+
return
|
|
3686
|
+
}
|
|
3687
|
+
if (current && current.type !== 'pan') saveCanvasSoon(cloneBoardCanvas(canvasRef.current))
|
|
3688
|
+
}
|
|
3689
|
+
window.addEventListener('pointermove', move)
|
|
3690
|
+
window.addEventListener('pointerup', finish)
|
|
3691
|
+
window.addEventListener('pointercancel', finish)
|
|
3692
|
+
}
|
|
3693
|
+
|
|
3694
|
+
const eraseAt = (gesture, point) => {
|
|
3695
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3696
|
+
const list = gesture.layer === 'background' ? [...next.background] : [...(next.drawings[gesture.noteId] ?? [])]
|
|
3697
|
+
const kept = list.filter((stroke) => !boardStrokeHit(stroke, point))
|
|
3698
|
+
if (kept.length === list.length) return
|
|
3699
|
+
if (gesture.layer === 'background') next.background = kept
|
|
3700
|
+
else if (kept.length > 0) next.drawings[gesture.noteId] = kept
|
|
3701
|
+
else delete next.drawings[gesture.noteId]
|
|
3702
|
+
canvasRef.current = next
|
|
3703
|
+
setCanvas(next)
|
|
3704
|
+
}
|
|
3705
|
+
|
|
3706
|
+
const beginPointer = (event) => {
|
|
3707
|
+
if (event.button !== 0) return
|
|
3708
|
+
if (event.target?.closest?.('button') || event.target?.closest?.('.tb-sticky-linkline') || event.target?.closest?.('.tb-sticky-actions')) return
|
|
3709
|
+
const stage = stageRef.current
|
|
3710
|
+
if (!stage) return
|
|
3711
|
+
const noteElement = event.target?.closest?.('.tb-sticky')
|
|
3712
|
+
const noteId = noteElement?.getAttribute?.('data-note-id') || ''
|
|
3713
|
+
if (toolRef.current === 'link') {
|
|
3714
|
+
event.preventDefault()
|
|
3715
|
+
if (!noteId) return
|
|
3716
|
+
const localPoint = stagePoint(event)
|
|
3717
|
+
const layout = canvasRef.current.notes[noteId] ?? autoBoardLayout(0)
|
|
3718
|
+
const anchorElement = event.target?.closest?.('.tb-anchor')
|
|
3719
|
+
const anchor = anchorElement?.getAttribute?.('data-anchor') || nearestBoardAnchor(layout, localPoint)
|
|
3720
|
+
setLinkPreview({ fromNoteId: noteId, fromAnchor: anchor, pointer: localPoint, targetNoteId: '', targetAnchor: '' })
|
|
3721
|
+
setGesture({ type: 'link', fromNoteId: noteId, fromAnchor: anchor })
|
|
3722
|
+
return
|
|
3723
|
+
}
|
|
3724
|
+
if (noteId && event.target?.closest?.('.tb-sticky-resize')) {
|
|
3725
|
+
event.preventDefault()
|
|
3726
|
+
event.stopPropagation()
|
|
3727
|
+
setSelected(noteId)
|
|
3728
|
+
const layout = canvasRef.current.notes[noteId] ?? autoBoardLayout(0)
|
|
3729
|
+
const size = noteSize(layout)
|
|
3730
|
+
setGesture({
|
|
3731
|
+
type: 'resize',
|
|
3732
|
+
noteId,
|
|
3733
|
+
startX: event.clientX,
|
|
3734
|
+
startY: event.clientY,
|
|
3735
|
+
startW: size.width,
|
|
3736
|
+
startH: size.height,
|
|
3737
|
+
})
|
|
3738
|
+
return
|
|
3739
|
+
}
|
|
3740
|
+
if (toolRef.current === 'select') {
|
|
3741
|
+
if (!noteId) {
|
|
3742
|
+
event.preventDefault()
|
|
3743
|
+
setSelected('')
|
|
3744
|
+
const viewport = viewportRef.current
|
|
3745
|
+
setGesture({
|
|
3746
|
+
type: 'pan',
|
|
3747
|
+
startX: event.clientX,
|
|
3748
|
+
startY: event.clientY,
|
|
3749
|
+
scrollLeft: viewport?.scrollLeft ?? 0,
|
|
3750
|
+
scrollTop: viewport?.scrollTop ?? 0,
|
|
3751
|
+
})
|
|
3752
|
+
return
|
|
3753
|
+
}
|
|
3754
|
+
event.preventDefault()
|
|
3755
|
+
setSelected(noteId)
|
|
3756
|
+
const layout = canvasRef.current.notes[noteId] ?? autoBoardLayout(0)
|
|
3757
|
+
setGesture({
|
|
3758
|
+
type: 'drag',
|
|
3759
|
+
noteId,
|
|
3760
|
+
startX: event.clientX,
|
|
3761
|
+
startY: event.clientY,
|
|
3762
|
+
originX: Number(layout.x) || 0,
|
|
3763
|
+
originY: Number(layout.y) || 0,
|
|
3764
|
+
})
|
|
3765
|
+
return
|
|
3766
|
+
}
|
|
3767
|
+
if (noteId && !drawOnStickyRef.current) {
|
|
3768
|
+
// Drawing on sticky notes is switched off: keep the note selected but
|
|
3769
|
+
// do not start a stroke there.
|
|
3770
|
+
event.preventDefault()
|
|
3771
|
+
setSelected(noteId)
|
|
3772
|
+
return
|
|
3773
|
+
}
|
|
3774
|
+
event.preventDefault()
|
|
3775
|
+
const rect = (noteElement ?? stage).getBoundingClientRect()
|
|
3776
|
+
const scale = zoomScale()
|
|
3777
|
+
const point = [Math.round((event.clientX - rect.left) / scale), Math.round((event.clientY - rect.top) / scale)]
|
|
3778
|
+
const layer = noteId ? 'note' : 'background'
|
|
3779
|
+
if (toolRef.current === 'eraser') {
|
|
3780
|
+
const gesture = { type: 'erase', layer, noteId, rect }
|
|
3781
|
+
eraseAt(gesture, point)
|
|
3782
|
+
setGesture(gesture)
|
|
3783
|
+
return
|
|
3784
|
+
}
|
|
3785
|
+
const shape = ['rect', 'ellipse', 'line', 'arrow', 'triangle'].includes(toolRef.current)
|
|
3786
|
+
if (shape) {
|
|
3787
|
+
const baseCanvas = cloneBoardCanvas(canvasRef.current)
|
|
3788
|
+
const targets = new Map()
|
|
3789
|
+
if (noteId && noteElement) targets.set(noteId, noteOffsets(noteElement))
|
|
3790
|
+
const startWorld = stagePoint(event)
|
|
3791
|
+
const gesture = {
|
|
3792
|
+
type: 'shape',
|
|
3793
|
+
kind: toolRef.current,
|
|
3794
|
+
color: inkRef.current,
|
|
3795
|
+
width: inkWidthRef.current,
|
|
3796
|
+
baseCanvas,
|
|
3797
|
+
startWorld,
|
|
3798
|
+
endWorld: [...startWorld],
|
|
3799
|
+
targets,
|
|
3800
|
+
ctrl: event.ctrlKey || event.metaKey || event.shiftKey,
|
|
3801
|
+
}
|
|
3802
|
+
const preview = buildShapeCanvas(gesture)
|
|
3803
|
+
canvasRef.current = preview
|
|
3804
|
+
setCanvas(preview)
|
|
3805
|
+
setGesture(gesture)
|
|
3806
|
+
return
|
|
3807
|
+
}
|
|
3808
|
+
const stroke = { kind: 'pen', color: inkRef.current, width: inkWidthRef.current, points: [point] }
|
|
3809
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3810
|
+
let strokeIndex
|
|
3811
|
+
if (layer === 'background') {
|
|
3812
|
+
strokeIndex = next.background.length
|
|
3813
|
+
next.background.push(stroke)
|
|
3814
|
+
} else {
|
|
3815
|
+
const list = [...(next.drawings[noteId] ?? [])]
|
|
3816
|
+
strokeIndex = list.length
|
|
3817
|
+
list.push(stroke)
|
|
3818
|
+
next.drawings[noteId] = list
|
|
3819
|
+
}
|
|
3820
|
+
canvasRef.current = next
|
|
3821
|
+
setCanvas(next)
|
|
3822
|
+
setGesture({
|
|
3823
|
+
type: 'draw',
|
|
3824
|
+
shape,
|
|
3825
|
+
layer,
|
|
3826
|
+
noteId,
|
|
3827
|
+
rect,
|
|
3828
|
+
stroke,
|
|
3829
|
+
strokeIndex,
|
|
3830
|
+
startWorld: [event.clientX, event.clientY],
|
|
3831
|
+
lastWorld: [event.clientX, event.clientY],
|
|
3832
|
+
})
|
|
3833
|
+
}
|
|
3834
|
+
|
|
3835
|
+
const toggleDrawOnSticky = () => {
|
|
3836
|
+
setDrawOnSticky((value) => {
|
|
3837
|
+
const next = !value
|
|
3838
|
+
try {
|
|
3839
|
+
window.localStorage.setItem('dsh-timeback:board-draw-on-sticky', next ? '1' : '0')
|
|
3840
|
+
} catch {
|
|
3841
|
+
// Storage can be disabled.
|
|
3842
|
+
}
|
|
3843
|
+
return next
|
|
3844
|
+
})
|
|
3845
|
+
}
|
|
3846
|
+
|
|
3847
|
+
/** Change the drawing colour (recent colours are recorded only once used). */
|
|
3848
|
+
const applyInk = (value, options = {}) => {
|
|
3849
|
+
const normalized = /^#[0-9a-f]{6}$/i.test(String(value || '')) ? String(value).toLowerCase() : '#e6b84c'
|
|
3850
|
+
setInk(normalized)
|
|
3851
|
+
inkRef.current = normalized
|
|
3852
|
+
try {
|
|
3853
|
+
window.localStorage.setItem('dsh-timeback:board-ink-color', normalized)
|
|
3854
|
+
} catch {
|
|
3855
|
+
// Storage can be disabled.
|
|
3856
|
+
}
|
|
3857
|
+
if (options.close === true) setColorOpen(false)
|
|
3858
|
+
}
|
|
3859
|
+
|
|
3860
|
+
/** Remember a colour in the recent list after a real stroke used it. */
|
|
3861
|
+
const rememberInk = (value) => {
|
|
3862
|
+
const normalized = /^#[0-9a-f]{6}$/i.test(String(value || '')) ? String(value).toLowerCase() : ''
|
|
3863
|
+
if (normalized === '') return
|
|
3864
|
+
setRecentColors((previous) => {
|
|
3865
|
+
const next = [normalized, ...previous.filter((item) => item !== normalized)].slice(0, 8)
|
|
3866
|
+
try {
|
|
3867
|
+
window.localStorage.setItem('dsh-timeback:board-recent-colors', JSON.stringify(next))
|
|
3868
|
+
} catch {
|
|
3869
|
+
// Storage can be disabled.
|
|
3870
|
+
}
|
|
3871
|
+
return next
|
|
3872
|
+
})
|
|
3873
|
+
}
|
|
3874
|
+
|
|
3875
|
+
const pickScreenColor = async () => {
|
|
3876
|
+
setColorHint('')
|
|
3877
|
+
if (typeof window === 'undefined' || typeof window.EyeDropper !== 'function') {
|
|
3878
|
+
setColorHint(t('board.eyedropperUnsupported'))
|
|
3879
|
+
return
|
|
3880
|
+
}
|
|
3881
|
+
if (window.isSecureContext === false) {
|
|
3882
|
+
setColorHint(t('board.eyedropperInsecure'))
|
|
3883
|
+
return
|
|
3884
|
+
}
|
|
3885
|
+
try {
|
|
3886
|
+
const result = await new window.EyeDropper().open()
|
|
3887
|
+
if (result?.sRGBHex) applyInk(result.sRGBHex, { close: true })
|
|
3888
|
+
} catch (error) {
|
|
3889
|
+
setColorHint(format(t('board.eyedropperFailed'), { error: error?.message || 'cancelled' }))
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3892
|
+
|
|
3893
|
+
const clearBackground = () => {
|
|
3894
|
+
if (canvasRef.current.background.length === 0) return
|
|
3895
|
+
saveCanvasSoon({ ...cloneBoardCanvas(canvasRef.current), background: [] })
|
|
3896
|
+
}
|
|
3897
|
+
const clearSelectedDrawing = () => {
|
|
3898
|
+
const id = selectedRef.current
|
|
3899
|
+
if (!id || !canvasRef.current.drawings[id]?.length) return
|
|
3900
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3901
|
+
delete next.drawings[id]
|
|
3902
|
+
saveCanvasSoon(next)
|
|
3903
|
+
}
|
|
3904
|
+
|
|
3905
|
+
/* -------------------------------------------------------------- */
|
|
3906
|
+
/* render */
|
|
3907
|
+
/* -------------------------------------------------------------- */
|
|
3908
|
+
|
|
3909
|
+
const drawingLayer = (strokes, prefix) =>
|
|
3910
|
+
h('svg', { className: prefix === 'bg' ? 'tb-board-bgdraw' : 'tb-sticky-draw', width: prefix === 'bg' ? BOARD_STAGE_W : '100%', height: prefix === 'bg' ? BOARD_STAGE_H : '100%' }, ...boardStrokeElements(strokes, prefix))
|
|
3911
|
+
|
|
3912
|
+
const layoutById = new Map()
|
|
3913
|
+
entries.forEach((entry, index) => layoutById.set(entry.id, layoutFor(entry, index)))
|
|
3914
|
+
|
|
3915
|
+
const edgeLayer = () => {
|
|
3916
|
+
const nodes = []
|
|
3917
|
+
for (const edge of canvas.edges ?? []) {
|
|
3918
|
+
const fromLayout = layoutById.get(edge.from?.noteId)
|
|
3919
|
+
const toLayout = layoutById.get(edge.to?.noteId)
|
|
3920
|
+
if (!fromLayout || !toLayout) continue
|
|
3921
|
+
const from = boardAnchorPoint(fromLayout, edge.from.anchor)
|
|
3922
|
+
const to = boardAnchorPoint(toLayout, edge.to.anchor)
|
|
3923
|
+
nodes.push(
|
|
3924
|
+
h(
|
|
3925
|
+
'g',
|
|
3926
|
+
{
|
|
3927
|
+
key: edge.id,
|
|
3928
|
+
className: 'tb-board-edge',
|
|
3929
|
+
onPointerDown: (event) => {
|
|
3930
|
+
if (toolRef.current !== 'link') return
|
|
3931
|
+
event.stopPropagation()
|
|
3932
|
+
event.preventDefault()
|
|
3933
|
+
let confirmed = true
|
|
3934
|
+
try {
|
|
3935
|
+
confirmed = typeof window.confirm === 'function' ? window.confirm(t('board.edgeDeleteConfirm')) : true
|
|
3936
|
+
} catch {
|
|
3937
|
+
confirmed = true
|
|
3938
|
+
}
|
|
3939
|
+
if (!confirmed) return
|
|
3940
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
3941
|
+
next.edges = next.edges.filter((candidate) => candidate.id !== edge.id)
|
|
3942
|
+
saveCanvasSoon(next)
|
|
3943
|
+
},
|
|
3944
|
+
},
|
|
3945
|
+
h('path', { className: 'tb-board-edge-path', d: boardEdgePath(from, to), stroke: edge.color || '#7aa2ff' }),
|
|
3946
|
+
h('circle', { className: 'tb-board-edge-dot', cx: from[0], cy: from[1], r: 3 }),
|
|
3947
|
+
h('circle', { className: 'tb-board-edge-dot', cx: to[0], cy: to[1], r: 3 }),
|
|
3948
|
+
),
|
|
3949
|
+
)
|
|
3950
|
+
}
|
|
3951
|
+
if (linkPreview) {
|
|
3952
|
+
const fromLayout = layoutById.get(linkPreview.fromNoteId)
|
|
3953
|
+
if (fromLayout) {
|
|
3954
|
+
const from = boardAnchorPoint(fromLayout, linkPreview.fromAnchor)
|
|
3955
|
+
let to = linkPreview.pointer
|
|
3956
|
+
if (linkPreview.targetNoteId) {
|
|
3957
|
+
const targetLayout = layoutById.get(linkPreview.targetNoteId)
|
|
3958
|
+
if (targetLayout) to = boardAnchorPoint(targetLayout, linkPreview.targetAnchor)
|
|
3959
|
+
}
|
|
3960
|
+
nodes.push(
|
|
3961
|
+
h('g', { key: 'link-preview', className: 'tb-board-edge-preview-group' },
|
|
3962
|
+
h('path', { className: 'tb-board-edge-preview', d: boardEdgePath(from, to), stroke: ink })),
|
|
3963
|
+
)
|
|
3964
|
+
}
|
|
3965
|
+
}
|
|
3966
|
+
return h('svg', { className: 'tb-board-edges', width: BOARD_STAGE_W, height: BOARD_STAGE_H }, ...nodes)
|
|
3967
|
+
}
|
|
3968
|
+
|
|
3969
|
+
const stickyFor = (entry, index) => {
|
|
3970
|
+
const layout = layoutFor(entry, index)
|
|
3971
|
+
const size = noteSize(layout)
|
|
3972
|
+
const agent = entry.source === 'agent'
|
|
3973
|
+
return h(
|
|
3974
|
+
'article',
|
|
3975
|
+
{
|
|
3976
|
+
key: entry.id,
|
|
3977
|
+
className: `tb-sticky${agent ? ' link' : ''}${selected === entry.id ? ' selected' : ''}`,
|
|
3978
|
+
'data-note-id': entry.id,
|
|
3979
|
+
style: {
|
|
3980
|
+
left: Number(layout.x) || 0,
|
|
3981
|
+
top: Number(layout.y) || 0,
|
|
3982
|
+
width: size.width,
|
|
3983
|
+
height: size.height,
|
|
3984
|
+
zIndex: 100 + (Number(layout.z) || 0),
|
|
3985
|
+
background: layout.color || BOARD_COLORS[index % BOARD_COLORS.length],
|
|
3986
|
+
},
|
|
3987
|
+
onDoubleClick: (event) => {
|
|
3988
|
+
event.stopPropagation()
|
|
3989
|
+
startEdit(entry)
|
|
3990
|
+
},
|
|
3991
|
+
},
|
|
3992
|
+
h(
|
|
3993
|
+
'div',
|
|
3994
|
+
{ className: 'tb-sticky-head' },
|
|
3995
|
+
h('span', { className: 'tb-sticky-src' }, agent ? '🔗' : t('board.sourceUser')),
|
|
3996
|
+
h('span', { className: 'tb-sticky-title', title: entry.title }, entry.title || '未命名便签'),
|
|
3997
|
+
h(
|
|
3998
|
+
'div',
|
|
3999
|
+
{ className: 'tb-sticky-actions' },
|
|
4000
|
+
h('button', { type: 'button', title: t('board.edit'), onClick: (event) => { event.stopPropagation(); startEdit(entry) } }, '✎'),
|
|
4001
|
+
h('button', { type: 'button', title: t('board.delete'), disabled: busy !== '', onClick: (event) => { event.stopPropagation(); removeEntry(entry.id) } }, '✕'),
|
|
4002
|
+
),
|
|
4003
|
+
),
|
|
4004
|
+
agent
|
|
4005
|
+
? h(
|
|
4006
|
+
'div',
|
|
4007
|
+
{ className: 'tb-sticky-body' },
|
|
4008
|
+
h(
|
|
4009
|
+
'span',
|
|
4010
|
+
{
|
|
4011
|
+
className: 'tb-sticky-linkline',
|
|
4012
|
+
role: 'link',
|
|
4013
|
+
tabIndex: 0,
|
|
4014
|
+
onClick: (event) => {
|
|
4015
|
+
event.stopPropagation()
|
|
4016
|
+
openReader(entry.id)
|
|
4017
|
+
},
|
|
4018
|
+
},
|
|
4019
|
+
`🔗 ${t('board.openMd')}`,
|
|
4020
|
+
),
|
|
4021
|
+
h('div', { className: 'tb-board-meta' }, stripMarkdown(entry.body).slice(0, 90)),
|
|
4022
|
+
)
|
|
4023
|
+
: h('div', { className: 'tb-sticky-body md' }, stripMarkdown(entry.body) || t('board.empty')),
|
|
4024
|
+
drawingLayer(canvas.drawings[entry.id] ?? [], `d-${entry.id}`),
|
|
4025
|
+
...BOARD_ANCHORS.map((anchor) =>
|
|
4026
|
+
h('div', {
|
|
4027
|
+
key: anchor,
|
|
4028
|
+
className: `tb-anchor tb-anchor-${anchor}`,
|
|
4029
|
+
'data-note-id': entry.id,
|
|
4030
|
+
'data-anchor': anchor,
|
|
4031
|
+
style:
|
|
4032
|
+
anchor === 'top'
|
|
4033
|
+
? { left: '50%', top: 0 }
|
|
4034
|
+
: anchor === 'right'
|
|
4035
|
+
? { left: '100%', top: '50%' }
|
|
4036
|
+
: anchor === 'bottom'
|
|
4037
|
+
? { left: '50%', top: '100%' }
|
|
4038
|
+
: { left: 0, top: '50%' },
|
|
4039
|
+
}),
|
|
4040
|
+
),
|
|
4041
|
+
h('div', { className: 'tb-sticky-resize', title: t('board.resizeNote'), role: 'separator' }),
|
|
4042
|
+
)
|
|
4043
|
+
}
|
|
4044
|
+
|
|
4045
|
+
const toolbar = h(
|
|
4046
|
+
'div',
|
|
4047
|
+
{ className: 'tb-board-toolbar' },
|
|
4048
|
+
h('button', { type: 'button', className: `tb-tool${tool === 'select' ? ' on' : ''}`, onClick: () => setTool('select') }, t('board.toolSelect')),
|
|
4049
|
+
h('button', { type: 'button', className: `tb-tool${tool === 'pen' ? ' on' : ''}`, onClick: () => setTool('pen') }, `✏️ ${t('board.toolPen')}`),
|
|
4050
|
+
h('button', { type: 'button', className: `tb-tool${tool === 'eraser' ? ' on' : ''}`, onClick: () => setTool('eraser') }, `🧽 ${t('board.toolEraser')}`),
|
|
4051
|
+
h('button', { type: 'button', className: `tb-tool${tool === 'link' ? ' on' : ''}`, title: t('board.anchorsHint'), onClick: () => setTool('link') }, `🔗 ${t('board.toolLink')}`),
|
|
4052
|
+
h(
|
|
4053
|
+
'div',
|
|
4054
|
+
{ className: 'tb-shape-wrap' },
|
|
4055
|
+
h(
|
|
4056
|
+
'button',
|
|
4057
|
+
{
|
|
4058
|
+
type: 'button',
|
|
4059
|
+
className: `tb-tool${BOARD_SHAPES.some(([value]) => value === tool) ? ' on' : ''}`,
|
|
4060
|
+
title: t('board.commonShapes'),
|
|
4061
|
+
onClick: () => setShapeMenu((value) => !value),
|
|
4062
|
+
},
|
|
4063
|
+
`${t('board.commonShapes')} ${BOARD_SHAPES.find(([value]) => value === tool)?.[1] ?? '▭'}`,
|
|
4064
|
+
),
|
|
4065
|
+
shapeMenu
|
|
4066
|
+
? h(
|
|
4067
|
+
'div',
|
|
4068
|
+
{ className: 'tb-shape-menu', role: 'menu' },
|
|
4069
|
+
...BOARD_SHAPES.map(([value, glyph, key]) =>
|
|
4070
|
+
h(
|
|
4071
|
+
'button',
|
|
4072
|
+
{
|
|
4073
|
+
key: value,
|
|
4074
|
+
type: 'button',
|
|
4075
|
+
role: 'menuitem',
|
|
4076
|
+
onClick: () => {
|
|
4077
|
+
setTool(value)
|
|
4078
|
+
setShapeMenu(false)
|
|
4079
|
+
},
|
|
4080
|
+
},
|
|
4081
|
+
`${glyph} ${t(key)}`,
|
|
4082
|
+
),
|
|
4083
|
+
),
|
|
4084
|
+
)
|
|
4085
|
+
: null,
|
|
4086
|
+
),
|
|
4087
|
+
h('span', { className: 'tb-board-meta' }, t('board.brushSize')),
|
|
4088
|
+
h('input', {
|
|
4089
|
+
type: 'range',
|
|
4090
|
+
className: 'tb-size-range',
|
|
4091
|
+
min: 1,
|
|
4092
|
+
max: 8,
|
|
4093
|
+
step: 1,
|
|
4094
|
+
value: inkWidth,
|
|
4095
|
+
'aria-label': t('board.brushSize'),
|
|
4096
|
+
onChange: (event) => {
|
|
4097
|
+
const next = Math.min(8, Math.max(1, Number(event.target.value) || 2))
|
|
4098
|
+
setInkWidth(next)
|
|
4099
|
+
try {
|
|
4100
|
+
window.localStorage.setItem('dsh-timeback:board-ink-width', String(next))
|
|
4101
|
+
} catch {
|
|
4102
|
+
// Storage can be disabled.
|
|
4103
|
+
}
|
|
4104
|
+
},
|
|
4105
|
+
}),
|
|
4106
|
+
h('span', { className: 'tb-board-meta' }, String(inkWidth)),
|
|
4107
|
+
h(
|
|
4108
|
+
'div',
|
|
4109
|
+
{ className: 'tb-color-wrap' },
|
|
4110
|
+
h('button', {
|
|
4111
|
+
type: 'button',
|
|
4112
|
+
className: 'tb-color-btn',
|
|
4113
|
+
style: { background: ink },
|
|
4114
|
+
title: `${t('board.color')} ${ink}`,
|
|
4115
|
+
'aria-label': t('board.colorTitle'),
|
|
4116
|
+
onClick: () => setColorOpen((value) => !value),
|
|
4117
|
+
}),
|
|
4118
|
+
colorOpen
|
|
4119
|
+
? (() => {
|
|
4120
|
+
const rgb = hexToRgb(ink)
|
|
4121
|
+
return h(
|
|
4122
|
+
'div',
|
|
4123
|
+
{ className: 'tb-color-panel', role: 'dialog' },
|
|
4124
|
+
h('div', { className: 'tb-board-meta' }, t('board.colorTitle')),
|
|
4125
|
+
h(
|
|
4126
|
+
'div',
|
|
4127
|
+
{ className: 'tb-color-row' },
|
|
4128
|
+
h('span', { className: 'tb-color-label' }, t('board.customColor')),
|
|
4129
|
+
h('input', {
|
|
4130
|
+
type: 'color',
|
|
4131
|
+
value: ink,
|
|
4132
|
+
'aria-label': t('board.customColor'),
|
|
4133
|
+
onChange: (event) => applyInk(event.target.value),
|
|
4134
|
+
}),
|
|
4135
|
+
h(
|
|
4136
|
+
'button',
|
|
4137
|
+
{
|
|
4138
|
+
type: 'button',
|
|
4139
|
+
className: 'tb-tool',
|
|
4140
|
+
title: t('board.eyedropperHint'),
|
|
4141
|
+
onClick: pickScreenColor,
|
|
4142
|
+
},
|
|
4143
|
+
`🎯 ${t('board.eyedropper')}`,
|
|
4144
|
+
),
|
|
4145
|
+
),
|
|
4146
|
+
colorHint ? h('div', { className: 'tb-feedback warn', style: { padding: '5px 7px', fontSize: '10.5px' } }, colorHint) : null,
|
|
4147
|
+
h(
|
|
4148
|
+
'div',
|
|
4149
|
+
{ className: 'tb-hex-row' },
|
|
4150
|
+
h('span', { className: 'tb-color-label' }, 'HEX'),
|
|
4151
|
+
h('input', {
|
|
4152
|
+
type: 'text',
|
|
4153
|
+
value: ink,
|
|
4154
|
+
spellCheck: false,
|
|
4155
|
+
onChange: (event) => {
|
|
4156
|
+
const value = event.target.value.trim()
|
|
4157
|
+
if (/^#[0-9a-f]{6}$/i.test(value)) applyInk(value)
|
|
4158
|
+
},
|
|
4159
|
+
}),
|
|
4160
|
+
),
|
|
4161
|
+
h('div', { className: 'tb-color-label' }, t('board.rgb')),
|
|
4162
|
+
...['R', 'G', 'B'].map((channel, index) =>
|
|
4163
|
+
h(
|
|
4164
|
+
'div',
|
|
4165
|
+
{ key: channel, className: 'tb-rgb-row' },
|
|
4166
|
+
h('span', { className: 'tb-color-label' }, channel),
|
|
4167
|
+
h('input', {
|
|
4168
|
+
type: 'range',
|
|
4169
|
+
min: 0,
|
|
4170
|
+
max: 255,
|
|
4171
|
+
step: 1,
|
|
4172
|
+
value: rgb[index],
|
|
4173
|
+
'aria-label': `${t('board.rgb')} ${channel}`,
|
|
4174
|
+
onChange: (event) => {
|
|
4175
|
+
const next = [...rgb]
|
|
4176
|
+
next[index] = Number(event.target.value)
|
|
4177
|
+
applyInk(rgbToHex(next))
|
|
4178
|
+
},
|
|
4179
|
+
}),
|
|
4180
|
+
h('span', null, String(rgb[index])),
|
|
4181
|
+
),
|
|
4182
|
+
),
|
|
4183
|
+
h('div', { className: 'tb-color-label' }, t('board.commonColors')),
|
|
4184
|
+
h(
|
|
4185
|
+
'div',
|
|
4186
|
+
{ className: 'tb-color-grid' },
|
|
4187
|
+
...BOARD_INKS.map((value) =>
|
|
4188
|
+
h('button', {
|
|
4189
|
+
key: value,
|
|
4190
|
+
type: 'button',
|
|
4191
|
+
title: value,
|
|
4192
|
+
style: { background: value },
|
|
4193
|
+
onClick: () => applyInk(value, { close: true }),
|
|
4194
|
+
}),
|
|
4195
|
+
),
|
|
4196
|
+
),
|
|
4197
|
+
recentColors.length > 0
|
|
4198
|
+
? h(
|
|
4199
|
+
'div',
|
|
4200
|
+
null,
|
|
4201
|
+
h('div', { className: 'tb-color-label' }, t('board.recentColors')),
|
|
4202
|
+
h(
|
|
4203
|
+
'div',
|
|
4204
|
+
{ className: 'tb-color-grid' },
|
|
4205
|
+
...recentColors.map((value) =>
|
|
4206
|
+
h('button', {
|
|
4207
|
+
key: `recent-${value}`,
|
|
4208
|
+
type: 'button',
|
|
4209
|
+
title: value,
|
|
4210
|
+
style: { background: value },
|
|
4211
|
+
onClick: () => applyInk(value, { close: true }),
|
|
4212
|
+
}),
|
|
4213
|
+
),
|
|
4214
|
+
),
|
|
4215
|
+
)
|
|
4216
|
+
: null,
|
|
4217
|
+
)
|
|
4218
|
+
})()
|
|
4219
|
+
: null,
|
|
4220
|
+
),
|
|
4221
|
+
h(
|
|
4222
|
+
'button',
|
|
4223
|
+
{
|
|
4224
|
+
type: 'button',
|
|
4225
|
+
className: `tb-tool${drawOnSticky ? ' on' : ''}`,
|
|
4226
|
+
title: t('board.drawOnStickyHint'),
|
|
4227
|
+
onClick: toggleDrawOnSticky,
|
|
4228
|
+
},
|
|
4229
|
+
drawOnSticky ? t('board.drawOnStickyOn') : t('board.drawOnStickyOff'),
|
|
4230
|
+
),
|
|
4231
|
+
h('span', { style: { flex: 1 } }),
|
|
4232
|
+
h('button', { type: 'button', className: 'tb-btn', onClick: autoFit }, t('board.center')),
|
|
4233
|
+
h('button', { type: 'button', className: 'tb-btn', disabled: canvas.background.length === 0, onClick: clearBackground }, t('board.clearBg')),
|
|
4234
|
+
h('button', { type: 'button', className: 'tb-btn', disabled: (canvas.edges ?? []).length === 0, onClick: () => { const next = cloneBoardCanvas(canvasRef.current); next.edges = []; saveCanvasSoon(next) } }, t('board.clearEdges')),
|
|
4235
|
+
h('button', { type: 'button', className: 'tb-btn', disabled: !selected || !(canvas.drawings[selected]?.length > 0), onClick: clearSelectedDrawing }, t('board.clearNote')),
|
|
4236
|
+
)
|
|
4237
|
+
|
|
2828
4238
|
return h(
|
|
2829
4239
|
'div',
|
|
2830
4240
|
{ className: 'tb-board-panel' },
|
|
@@ -2835,47 +4245,95 @@ window.__ModuleLoader__.load({
|
|
|
2835
4245
|
h('span', { className: 'tb-board-sub' }, t('board.subtitle')),
|
|
2836
4246
|
h('span', { style: { flex: 1 } }),
|
|
2837
4247
|
h('span', { className: 'tb-muted tb-small' }, format(t('board.count'), { count: entries.length, version: boardVersion })),
|
|
4248
|
+
h('span', { className: 'tb-muted tb-small' }, format(t('board.canvasVersion'), { version: boardVersion })),
|
|
2838
4249
|
h('button', { type: 'button', className: 'tb-btn', disabled: state.loading, onClick: refresh }, t('board.refresh')),
|
|
2839
|
-
h('button', { type: 'button', className: 'tb-btn primary', onClick: startCreate }, `+ ${t('board.
|
|
4250
|
+
h('button', { type: 'button', className: 'tb-btn primary', onClick: startCreate }, `+ ${t('board.newSticky')}`),
|
|
2840
4251
|
),
|
|
4252
|
+
toolbar,
|
|
4253
|
+
h('div', { className: 'tb-board-hint-wrap' }, h('span', { className: 'tb-ws-hint' }, `${t('board.stickyHint')} · ${t('board.panHint')}`)),
|
|
4254
|
+
state.error ? h('div', { className: 'tb-feedback err' }, format(t('board.error'), { error: state.error })) : null,
|
|
2841
4255
|
h(
|
|
2842
4256
|
'div',
|
|
2843
|
-
{ className:
|
|
2844
|
-
h(
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
!state.loading && entries.length === 0
|
|
2848
|
-
? h('p', { className: 'tb-board-empty' }, t('board.empty'))
|
|
2849
|
-
: null,
|
|
2850
|
-
...entries.map((entry) =>
|
|
4257
|
+
{ className: `tb-board-canvas${tool === 'select' ? ' select' : tool === 'link' ? ' link' : ' draw'}`, ref: viewportRef, onPointerDown: beginPointer },
|
|
4258
|
+
h(
|
|
4259
|
+
'div',
|
|
4260
|
+
{ className: 'tb-board-world', style: { width: BOARD_STAGE_W * zoom, height: BOARD_STAGE_H * zoom } },
|
|
2851
4261
|
h(
|
|
2852
|
-
'
|
|
2853
|
-
{
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
{
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
4262
|
+
'div',
|
|
4263
|
+
{
|
|
4264
|
+
className: `tb-board-stage${tool === 'link' || linkPreview ? ' show-anchors' : ''}`,
|
|
4265
|
+
ref: stageRef,
|
|
4266
|
+
style: { width: BOARD_STAGE_W, height: BOARD_STAGE_H, transform: `scale(${zoom})` },
|
|
4267
|
+
},
|
|
4268
|
+
drawingLayer(canvas.background, 'bg'),
|
|
4269
|
+
edgeLayer(),
|
|
4270
|
+
...entries.map((entry, index) => stickyFor(entry, index)),
|
|
4271
|
+
),
|
|
4272
|
+
),
|
|
4273
|
+
state.loading && !state.board ? h('p', { className: 'tb-board-md-empty' }, t('panel.loading')) : null,
|
|
4274
|
+
!state.loading && entries.length === 0 ? h('p', { className: 'tb-board-md-empty' }, t('board.empty')) : null,
|
|
4275
|
+
),
|
|
4276
|
+
h(
|
|
4277
|
+
'div',
|
|
4278
|
+
{ className: 'tb-board-md-pane' },
|
|
4279
|
+
h('div', { className: 'tb-board-md-head' }, t('board.mdBelow')),
|
|
4280
|
+
sortedEntries.length === 0
|
|
4281
|
+
? h('p', { className: 'tb-board-md-empty' }, t('board.empty'))
|
|
4282
|
+
: sortedEntries.map((entry) =>
|
|
2864
4283
|
h(
|
|
2865
|
-
'
|
|
2866
|
-
{ className:
|
|
2867
|
-
h('button', { type: 'button', className: 'tb-btn', onClick: () => startEdit(entry) }, t('board.edit')),
|
|
4284
|
+
'section',
|
|
4285
|
+
{ key: entry.id, id: `tb-md-${entry.id}`, className: `tb-board-md-item${selected === entry.id ? ' selected' : ''}` },
|
|
2868
4286
|
h(
|
|
2869
|
-
'
|
|
2870
|
-
{
|
|
2871
|
-
|
|
4287
|
+
'div',
|
|
4288
|
+
{ className: 'tb-board-md-item-head' },
|
|
4289
|
+
h('span', { className: 'tb-board-md-item-title' }, entry.title || '未命名便签'),
|
|
4290
|
+
h('span', { className: `tb-chip ${entry.source === 'agent' ? 'ok' : ''}` }, entry.source === 'agent' ? t('board.sourceAgent') : t('board.sourceUser')),
|
|
4291
|
+
h('span', { className: 'tb-board-meta' }, clock(entry.updatedAt)),
|
|
4292
|
+
h(
|
|
4293
|
+
'div',
|
|
4294
|
+
{ className: 'tb-board-actions' },
|
|
4295
|
+
h('button', { type: 'button', className: 'tb-btn', onClick: () => openReader(entry.id) }, t('board.reader')),
|
|
4296
|
+
h('button', { type: 'button', className: 'tb-btn', onClick: () => startEdit(entry) }, t('board.edit')),
|
|
4297
|
+
h('button', { type: 'button', className: 'tb-btn danger', disabled: busy !== '', onClick: () => removeEntry(entry.id) }, busy === entry.id ? '…' : t('board.delete')),
|
|
4298
|
+
),
|
|
2872
4299
|
),
|
|
4300
|
+
entry.body ? h('div', { className: 'tb-md' }, ...renderMarkdown(entry.body, `md-${entry.id}`)) : null,
|
|
2873
4301
|
),
|
|
2874
4302
|
),
|
|
2875
|
-
entry.body ? h('div', { className: 'tb-md' }, ...renderMarkdown(entry.body, `board-${entry.id}`)) : null,
|
|
2876
|
-
),
|
|
2877
|
-
),
|
|
2878
4303
|
),
|
|
4304
|
+
(() => {
|
|
4305
|
+
const readerEntry = entries.find((entry) => entry.id === readerId)
|
|
4306
|
+
if (!readerEntry) return null
|
|
4307
|
+
return h(
|
|
4308
|
+
'div',
|
|
4309
|
+
{ className: 'tb-overlay center', onClick: () => setReaderId('') },
|
|
4310
|
+
h(
|
|
4311
|
+
'div',
|
|
4312
|
+
{
|
|
4313
|
+
className: 'tb-board-dialog',
|
|
4314
|
+
role: 'dialog',
|
|
4315
|
+
'aria-modal': true,
|
|
4316
|
+
style: { width: 'min(780px, 94vw)', height: '72vh' },
|
|
4317
|
+
onClick: (event) => event.stopPropagation(),
|
|
4318
|
+
},
|
|
4319
|
+
h(
|
|
4320
|
+
'div',
|
|
4321
|
+
{ className: 'tb-detail-head' },
|
|
4322
|
+
h('span', { className: 'tb-detail-title' }, `📄 ${readerEntry.title || '未命名便签'}`),
|
|
4323
|
+
h('span', { className: 'tb-chip' }, readerEntry.source === 'agent' ? t('board.sourceAgent') : t('board.sourceUser')),
|
|
4324
|
+
h('span', { style: { flex: 1 } }),
|
|
4325
|
+
h('button', { type: 'button', className: 'tb-btn', onClick: () => { setReaderId(''); startEdit(readerEntry) } }, t('board.edit')),
|
|
4326
|
+
h(
|
|
4327
|
+
'button',
|
|
4328
|
+
{ type: 'button', className: 'tb-btn danger', disabled: busy !== '', onClick: () => { setReaderId(''); removeEntry(readerEntry.id) } },
|
|
4329
|
+
t('board.delete'),
|
|
4330
|
+
),
|
|
4331
|
+
h('button', { type: 'button', className: 'tb-btn primary', onClick: () => setReaderId('') }, t('board.close')),
|
|
4332
|
+
),
|
|
4333
|
+
h('div', { className: 'tb-md', style: { flex: 1, overflow: 'auto' } }, ...renderMarkdown(readerEntry.body || '', `reader-${readerEntry.id}`)),
|
|
4334
|
+
),
|
|
4335
|
+
)
|
|
4336
|
+
})(),
|
|
2879
4337
|
draft
|
|
2880
4338
|
? h(
|
|
2881
4339
|
'div',
|
|
@@ -2892,7 +4350,7 @@ window.__ModuleLoader__.load({
|
|
|
2892
4350
|
h(
|
|
2893
4351
|
'div',
|
|
2894
4352
|
{ className: 'tb-detail-head' },
|
|
2895
|
-
h('span', { className: 'tb-detail-title' }, draft.id ? t('board.edit') : t('board.
|
|
4353
|
+
h('span', { className: 'tb-detail-title' }, draft.id ? t('board.edit') : t('board.newSticky')),
|
|
2896
4354
|
h('span', { style: { flex: 1 } }),
|
|
2897
4355
|
h(
|
|
2898
4356
|
'button',
|
|
@@ -2940,6 +4398,7 @@ window.__ModuleLoader__.load({
|
|
|
2940
4398
|
window.__TIMEBACK_TEST__.edgePanVector = edgePanVector
|
|
2941
4399
|
window.__TIMEBACK_TEST__.renderMarkdown = renderMarkdown
|
|
2942
4400
|
window.__TIMEBACK_TEST__.stripMarkdown = stripMarkdown
|
|
4401
|
+
window.__TIMEBACK_TEST__.boardEdgePath = boardEdgePath
|
|
2943
4402
|
}
|
|
2944
4403
|
|
|
2945
4404
|
return {
|