dsh-timeback 0.7.0 → 0.7.2
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 +43 -6
- package/client.js +1747 -82
- package/docs/MARKET.md +2 -2
- package/package.json +1 -1
- package/src/notes.js +36 -3
package/client.js
CHANGED
|
@@ -23,7 +23,7 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
const REFRESH_MS = 3000
|
|
24
24
|
const MAX_ROWS = 240
|
|
25
25
|
/** Bump together with package.json so a stale browser bundle is obvious. */
|
|
26
|
-
const BUILD = '0.7.
|
|
26
|
+
const BUILD = '0.7.2+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,9 +98,52 @@ window.__ModuleLoader__.load({
|
|
|
98
98
|
'note.removed': '卡片记录已删除',
|
|
99
99
|
'board.title': '记录板',
|
|
100
100
|
'board.subtitle': '全局 Markdown 记录板 · 回溯时一起恢复',
|
|
101
|
+
'md.bold': '加粗',
|
|
102
|
+
'md.italic': '斜体',
|
|
103
|
+
'md.strike': '删除线',
|
|
104
|
+
'md.inlineCode': '行内代码',
|
|
105
|
+
'md.codeBlock': '代码块',
|
|
106
|
+
'md.heading': '标题',
|
|
107
|
+
'md.bullet': '无序列表',
|
|
108
|
+
'md.numbered': '有序列表',
|
|
109
|
+
'md.task': '任务列表',
|
|
110
|
+
'md.quote': '引用',
|
|
111
|
+
'md.link': '链接',
|
|
112
|
+
'md.hr': '分隔线',
|
|
113
|
+
'md.rich': '富文本',
|
|
114
|
+
'md.source': '源码',
|
|
115
|
+
'md.preview': '预览',
|
|
116
|
+
'md.color': '文字颜色',
|
|
117
|
+
'md.customColor': '自定义',
|
|
118
|
+
'md.linkPrompt': '链接地址',
|
|
119
|
+
'md.empty': '空文档,直接输入即可',
|
|
120
|
+
'md.hint': '直接打字即可:选中文字后点工具栏按钮会立即格式化(例如选中“你好”按 B 立即加粗);也可切换源码/预览。',
|
|
101
121
|
'board.newSticky': '新建便签',
|
|
102
122
|
'board.stickyHint': '便签可拖动;画笔可在方格纸背景或便签上绘制,橡皮擦除笔画。',
|
|
123
|
+
'board.resizeNote': '拖动缩放便签',
|
|
124
|
+
'board.drawOnSticky': '便签可画',
|
|
125
|
+
'board.drawOnStickyOn': '便签可画:开',
|
|
126
|
+
'board.drawOnStickyOff': '便签可画:关',
|
|
127
|
+
'board.drawOnStickyHint': '开启后画笔/图形可直接画在便签上;关闭则只画在方格纸背景。',
|
|
128
|
+
'board.center': '自动调整',
|
|
129
|
+
'board.zoomIn': '放大画布',
|
|
130
|
+
'board.zoomOut': '缩小画布',
|
|
131
|
+
'board.zoomReset': '重置为 100%',
|
|
132
|
+
'board.reader': '阅读 md',
|
|
133
|
+
'board.close': '关闭',
|
|
103
134
|
'board.toolSelect': '拖动',
|
|
135
|
+
'board.shapeRect': '矩形',
|
|
136
|
+
'board.shapeEllipse': '圆形',
|
|
137
|
+
'board.shapeLine': '直线',
|
|
138
|
+
'board.shapeArrow': '箭头',
|
|
139
|
+
'board.shapeTriangle': '三角形',
|
|
140
|
+
'board.toolLink': '路径',
|
|
141
|
+
'board.commonShapes': '常用图形',
|
|
142
|
+
'board.brushSize': '粗细',
|
|
143
|
+
'board.anchorsHint': '路径工具:从便签四角的吸附点拖到另一张便签,形成图结构;点路径可删除。',
|
|
144
|
+
'board.clearEdges': '清路径',
|
|
145
|
+
'board.edgeDeleteConfirm': '删除这条路径?',
|
|
146
|
+
'board.panHint': '拖动工具下按住空白方格纸可平移画布',
|
|
104
147
|
'board.toolPen': '画笔',
|
|
105
148
|
'board.toolEraser': '橡皮',
|
|
106
149
|
'board.clearBg': '清背景笔迹',
|
|
@@ -110,6 +153,16 @@ window.__ModuleLoader__.load({
|
|
|
110
153
|
'board.mdBelow': '记录板内容(Markdown)',
|
|
111
154
|
'board.canvasVersion': '便签板 v{version}',
|
|
112
155
|
'board.color': '颜色',
|
|
156
|
+
'board.colorTitle': '选择颜色',
|
|
157
|
+
'board.commonColors': '常用颜色',
|
|
158
|
+
'board.recentColors': '近期使用',
|
|
159
|
+
'board.customColor': '自定义颜色',
|
|
160
|
+
'board.rgb': 'RGB',
|
|
161
|
+
'board.eyedropper': '屏幕取色',
|
|
162
|
+
'board.eyedropperHint': '从屏幕任意位置吸取颜色(需要 Chrome/Edge 等支持 EyeDropper 的浏览器)',
|
|
163
|
+
'board.eyedropperUnsupported': '当前浏览器不支持屏幕取色,请使用「自定义颜色」里的系统取色器或手动输入 HEX。',
|
|
164
|
+
'board.eyedropperInsecure': '屏幕取色需要 https 或 localhost 环境;当前页面不是安全上下文。',
|
|
165
|
+
'board.eyedropperFailed': '取色被取消或失败:{error}',
|
|
113
166
|
'board.new': '新建记录',
|
|
114
167
|
'board.edit': '编辑',
|
|
115
168
|
'board.delete': '删除',
|
|
@@ -286,9 +339,52 @@ window.__ModuleLoader__.load({
|
|
|
286
339
|
'note.removed': 'Card note deleted',
|
|
287
340
|
'board.title': 'Notes board',
|
|
288
341
|
'board.subtitle': 'Global Markdown notes · rewinds restore them too',
|
|
342
|
+
'md.bold': 'Bold',
|
|
343
|
+
'md.italic': 'Italic',
|
|
344
|
+
'md.strike': 'Strikethrough',
|
|
345
|
+
'md.inlineCode': 'Inline code',
|
|
346
|
+
'md.codeBlock': 'Code block',
|
|
347
|
+
'md.heading': 'Heading',
|
|
348
|
+
'md.bullet': 'Bullet list',
|
|
349
|
+
'md.numbered': 'Numbered list',
|
|
350
|
+
'md.task': 'Task list',
|
|
351
|
+
'md.quote': 'Quote',
|
|
352
|
+
'md.link': 'Link',
|
|
353
|
+
'md.hr': 'Divider',
|
|
354
|
+
'md.rich': 'Rich',
|
|
355
|
+
'md.source': 'Source',
|
|
356
|
+
'md.preview': 'Preview',
|
|
357
|
+
'md.color': 'Text colour',
|
|
358
|
+
'md.customColor': 'Custom',
|
|
359
|
+
'md.linkPrompt': 'Link URL',
|
|
360
|
+
'md.empty': 'Empty document — just start typing',
|
|
361
|
+
'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.',
|
|
289
362
|
'board.newSticky': 'New sticky',
|
|
290
363
|
'board.stickyHint': 'Sticky notes are draggable; draw on the grid or on a note, erase strokes with the eraser.',
|
|
364
|
+
'board.resizeNote': 'Drag to resize the sticky',
|
|
365
|
+
'board.drawOnSticky': 'Draw on stickies',
|
|
366
|
+
'board.drawOnStickyOn': 'Sticky drawing: on',
|
|
367
|
+
'board.drawOnStickyOff': 'Sticky drawing: off',
|
|
368
|
+
'board.drawOnStickyHint': 'When on, pen/shape tools draw directly on sticky notes; when off they only draw on the grid.',
|
|
369
|
+
'board.center': 'Auto fit',
|
|
370
|
+
'board.zoomIn': 'Zoom in',
|
|
371
|
+
'board.zoomOut': 'Zoom out',
|
|
372
|
+
'board.zoomReset': 'Reset to 100%',
|
|
373
|
+
'board.reader': 'Read md',
|
|
374
|
+
'board.close': 'Close',
|
|
291
375
|
'board.toolSelect': 'Move',
|
|
376
|
+
'board.shapeRect': 'Rectangle',
|
|
377
|
+
'board.shapeEllipse': 'Ellipse',
|
|
378
|
+
'board.shapeLine': 'Line',
|
|
379
|
+
'board.shapeArrow': 'Arrow',
|
|
380
|
+
'board.shapeTriangle': 'Triangle',
|
|
381
|
+
'board.toolLink': 'Link',
|
|
382
|
+
'board.commonShapes': 'Shapes',
|
|
383
|
+
'board.brushSize': 'Size',
|
|
384
|
+
'board.anchorsHint': 'Link tool: drag from a sticky anchor to another sticky to build a graph; click a link to delete it.',
|
|
385
|
+
'board.clearEdges': 'Clear links',
|
|
386
|
+
'board.edgeDeleteConfirm': 'Delete this link?',
|
|
387
|
+
'board.panHint': 'With the Move tool, drag on empty grid to pan the canvas',
|
|
292
388
|
'board.toolPen': 'Pen',
|
|
293
389
|
'board.toolEraser': 'Eraser',
|
|
294
390
|
'board.clearBg': 'Clear drawings',
|
|
@@ -298,6 +394,16 @@ window.__ModuleLoader__.load({
|
|
|
298
394
|
'board.mdBelow': 'Board contents (Markdown)',
|
|
299
395
|
'board.canvasVersion': 'Board v{version}',
|
|
300
396
|
'board.color': 'Colour',
|
|
397
|
+
'board.colorTitle': 'Pick a colour',
|
|
398
|
+
'board.commonColors': 'Common colours',
|
|
399
|
+
'board.recentColors': 'Recent',
|
|
400
|
+
'board.customColor': 'Custom colour',
|
|
401
|
+
'board.rgb': 'RGB',
|
|
402
|
+
'board.eyedropper': 'Pick from screen',
|
|
403
|
+
'board.eyedropperHint': 'Sample any colour from the screen (Chrome/Edge and other EyeDropper-capable browsers)',
|
|
404
|
+
'board.eyedropperUnsupported': 'This browser does not support screen sampling; use the system picker under Custom colour or type a HEX value.',
|
|
405
|
+
'board.eyedropperInsecure': 'Screen sampling needs https or localhost; this page is not a secure context.',
|
|
406
|
+
'board.eyedropperFailed': 'Colour picking was cancelled or failed: {error}',
|
|
301
407
|
'board.new': 'New note',
|
|
302
408
|
'board.edit': 'Edit',
|
|
303
409
|
'board.delete': 'Delete',
|
|
@@ -519,14 +625,43 @@ window.__ModuleLoader__.load({
|
|
|
519
625
|
.tb-board-testid{display:none}
|
|
520
626
|
.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))}
|
|
521
627
|
.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}
|
|
628
|
+
.tb-shape-wrap{position:relative;display:inline-flex}
|
|
629
|
+
.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)}
|
|
630
|
+
.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}
|
|
631
|
+
.tb-shape-menu button:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.1))}
|
|
632
|
+
.tb-size-range{width:82px;accent-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
|
|
522
633
|
.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))}
|
|
634
|
+
.tb-color-wrap{position:relative;display:inline-flex}
|
|
635
|
+
.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)}
|
|
636
|
+
.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}
|
|
637
|
+
.tb-color-row{display:flex;align-items:center;gap:5px;flex-wrap:wrap}
|
|
638
|
+
.tb-color-label{font-size:10.5px;color:var(--dsw-alias-label-secondary,#9aa0a6);min-width:56px}
|
|
639
|
+
.tb-color-grid{display:grid;grid-template-columns:repeat(8,1fr);gap:4px}
|
|
640
|
+
.tb-color-grid button{width:100%;aspect-ratio:1;border-radius:4px;border:1px solid rgba(255,255,255,.22);cursor:pointer;padding:0}
|
|
641
|
+
.tb-rgb-row{display:flex;align-items:center;gap:4px;font-size:10.5px;color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
642
|
+
.tb-rgb-row input[type=range]{flex:1;min-width:40px;accent-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
|
|
643
|
+
.tb-hex-row{display:flex;align-items:center;gap:5px}
|
|
644
|
+
.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}
|
|
523
645
|
.tb-swatch{width:18px;height:18px;border-radius:50%;border:2px solid transparent;cursor:pointer;padding:0}
|
|
524
646
|
.tb-swatch.on{border-color:var(--dsw-alias-label-primary,#e6e6e6);box-shadow:0 0 0 2px rgba(0,0,0,.3)}
|
|
525
|
-
.tb-board-canvas{position:relative;flex:1;min-height:240px;overflow:auto;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));background
|
|
526
|
-
.tb-board-canvas.select{cursor:
|
|
527
|
-
.tb-board-
|
|
647
|
+
.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}
|
|
648
|
+
.tb-board-canvas.select{cursor:grab}
|
|
649
|
+
.tb-board-canvas.draw,.tb-board-canvas.draw .tb-sticky{cursor:crosshair}
|
|
650
|
+
.tb-board-canvas.link,.tb-board-canvas.link .tb-sticky{cursor:crosshair}
|
|
651
|
+
.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%)}
|
|
652
|
+
.tb-board-stage.show-anchors .tb-anchor{display:block}
|
|
653
|
+
.tb-anchor:hover{background:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
|
|
654
|
+
.tb-board-edges{position:absolute;left:0;top:0;pointer-events:none;overflow:visible;z-index:1}
|
|
655
|
+
.tb-board-edge-path{fill:none;stroke-width:2;opacity:.7;pointer-events:stroke}
|
|
656
|
+
.tb-board-edge-path:hover{opacity:1;stroke-width:3}
|
|
657
|
+
.tb-board-edge-dot{fill:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);stroke:none}
|
|
658
|
+
.tb-board-edge-preview{fill:none;stroke-dasharray:6 5;stroke-width:2;opacity:.7}
|
|
659
|
+
.tb-board-canvas.draw .tb-sticky-resize{cursor:nwse-resize}
|
|
660
|
+
.tb-board-canvas.select:active{cursor:grabbing}
|
|
661
|
+
.tb-board-world{position:relative;flex:none}
|
|
662
|
+
.tb-board-stage{position:absolute;left:0;top:0;transform-origin:0 0;will-change:transform;background-color:var(--dsw-alias-bg-base,#16181d);background-image:linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px);background-size:22px 22px,22px 22px,110px 110px,110px 110px}
|
|
528
663
|
.tb-board-bgdraw{position:absolute;left:0;top:0;pointer-events:none;overflow:visible}
|
|
529
|
-
.tb-sticky{position:absolute;width:232px;height:176px;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}
|
|
664
|
+
.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}
|
|
530
665
|
.tb-sticky:active{cursor:grabbing}
|
|
531
666
|
.tb-sticky.selected{outline:2px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);outline-offset:1px}
|
|
532
667
|
.tb-sticky.link{border-style:dashed;cursor:pointer}
|
|
@@ -535,11 +670,17 @@ window.__ModuleLoader__.load({
|
|
|
535
670
|
.tb-sticky-actions{display:flex;gap:3px;opacity:.65}
|
|
536
671
|
.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}
|
|
537
672
|
.tb-sticky-actions button:hover{background:rgba(0,0,0,.16)}
|
|
538
|
-
.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}
|
|
673
|
+
.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}
|
|
539
674
|
.tb-sticky-body.md{display:-webkit-box;-webkit-line-clamp:5;-webkit-box-orient:vertical}
|
|
540
675
|
.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}
|
|
541
676
|
.tb-sticky-src{font-size:9.5px;font-weight:600;opacity:.6;white-space:nowrap}
|
|
542
|
-
.tb-sticky-draw{position:absolute;inset:0;pointer-events:none;z-index:
|
|
677
|
+
.tb-sticky-draw{position:absolute;inset:0;pointer-events:none;z-index:3}
|
|
678
|
+
.tb-sticky-head{position:relative;z-index:4}
|
|
679
|
+
.tb-sticky-resize{position:absolute;right:0;bottom:0;width:16px;height:16px;cursor:nwse-resize;z-index:6;opacity:.55}
|
|
680
|
+
.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)}
|
|
681
|
+
.tb-sticky:hover .tb-sticky-resize{opacity:.9}
|
|
682
|
+
.tb-sticky-linkline,.tb-sticky-actions{position:relative;z-index:4}
|
|
683
|
+
.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}
|
|
543
684
|
.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)}
|
|
544
685
|
.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}
|
|
545
686
|
.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))}
|
|
@@ -547,6 +688,41 @@ window.__ModuleLoader__.load({
|
|
|
547
688
|
.tb-board-md-item-head{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
|
|
548
689
|
.tb-board-md-item-title{font-weight:600;font-size:12px}
|
|
549
690
|
.tb-board-md-empty{padding:10px;text-align:center;color:var(--dsw-alias-label-secondary,#9aa0a6);font-size:12px}
|
|
691
|
+
.tb-md-rich{flex:1;min-height:0;overflow:auto;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));border-radius:8px;padding:10px 12px;font-size:15px;line-height:1.65;color:var(--dsw-alias-label-primary,#e6e6e6);background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.04));outline:none;box-sizing:border-box}
|
|
692
|
+
.tb-md-rich:empty:before{content:attr(data-placeholder);color:var(--dsw-alias-label-tertiary,#8a919c)}
|
|
693
|
+
.tb-md-rich h1,.tb-md-rich h2,.tb-md-rich h3,.tb-md-rich h4,.tb-md-rich h5,.tb-md-rich h6{margin:10px 0 5px;line-height:1.35}
|
|
694
|
+
.tb-md-rich h1{font-size:23px}.tb-md-rich h2{font-size:20px}.tb-md-rich h3{font-size:18px}.tb-md-rich h4{font-size:16px}.tb-md-rich h5{font-size:15px}.tb-md-rich h6{font-size:14px}
|
|
695
|
+
.tb-md-rich p{margin:5px 0}
|
|
696
|
+
.tb-md-rich ul,.tb-md-rich ol{margin:5px 0;padding-left:22px}
|
|
697
|
+
.tb-md-rich blockquote{margin:6px 0;padding:2px 10px;border-left:3px solid var(--dsw-alias-border-l2,rgba(255,255,255,.3));color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
698
|
+
.tb-md-rich pre{margin:7px 0;padding:9px 11px;border-radius:7px;background:rgba(0,0,0,.35);font-size:13px;line-height:1.55;overflow:auto}
|
|
699
|
+
.tb-md-rich code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;background:rgba(255,255,255,.08);border-radius:4px;padding:0 3px;font-size:13.5px}
|
|
700
|
+
.tb-md-rich pre code{background:transparent;padding:0}
|
|
701
|
+
.tb-md-rich hr{border:0;border-top:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.2));margin:10px 0}
|
|
702
|
+
.tb-md-rich a{color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff)}
|
|
703
|
+
.tb-md-readonly{flex:1;min-height:0;overflow:auto;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));border-radius:8px;padding:12px 14px;background:var(--dsw-alias-bg-base,#16181d)}
|
|
704
|
+
.tb-md-color{width:21px;height:21px;padding:0;border-radius:4px;border:1px solid rgba(255,255,255,.32);cursor:pointer;flex:0 0 auto}
|
|
705
|
+
.tb-md-color:hover{transform:scale(1.12)}
|
|
706
|
+
.tb-md-color-custom{margin-left:auto;display:flex;align-items:center;gap:4px;flex:0 0 auto}
|
|
707
|
+
.tb-md-color-input{width:30px;height:24px;min-width:30px;box-sizing:border-box;padding:2px;border:1px solid rgba(255,255,255,.28);border-radius:5px;background:rgba(255,255,255,.04);cursor:pointer;flex:0 0 auto}
|
|
708
|
+
.tb-md-editor{display:flex;flex-direction:column;gap:6px;flex:1;min-height:0}
|
|
709
|
+
.tb-md-toolbar{display:flex;align-items:flex-start;gap:6px;flex-wrap:wrap;padding:5px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));border-radius:8px;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.03))}
|
|
710
|
+
.tb-md-tools{display:flex;align-items:center;gap:3px;flex-wrap:wrap;flex:1;min-width:0}
|
|
711
|
+
.tb-md-tool{appearance:none;border:1px solid transparent;background:transparent;color:var(--dsw-alias-label-secondary,#c3c9d2);border-radius:5px;min-width:30px;height:28px;padding:0 8px;font-size:13px;line-height:1;cursor:pointer;white-space:nowrap;flex:0 0 auto}
|
|
712
|
+
.tb-md-tool:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.1));color:var(--dsw-alias-label-primary,#e6e6e6)}
|
|
713
|
+
.tb-md-tool.on{color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff);border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
|
|
714
|
+
.tb-md-mode{margin-left:auto;display:flex;gap:2px;flex:0 0 auto}
|
|
715
|
+
.tb-md-colorbar{display:flex;align-items:center;gap:5px;flex-wrap:nowrap;overflow:hidden;padding:3px 5px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.10));border-radius:7px;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.02))}
|
|
716
|
+
.tb-md-color-label{font-size:12px;color:var(--dsw-alias-label-secondary,#9aa0a6);margin-right:1px}
|
|
717
|
+
.tb-md-body{display:flex;gap:8px;flex:1;min-height:0;overflow:hidden}
|
|
718
|
+
.tb-md-source{flex:1;min-width:0;resize:none;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:8px;padding:10px 12px;font-size:14px;line-height:1.7;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
|
719
|
+
.tb-md-preview{flex:1;min-width:0;overflow:auto;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));border-radius:8px;padding:8px 10px;background:var(--dsw-alias-bg-base,#16181d)}
|
|
720
|
+
.tb-md-block{padding:3px 7px 5px;border-left:2px solid transparent;border-radius:5px;margin-bottom:5px;cursor:text}
|
|
721
|
+
.tb-md-block:hover{background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.04))}
|
|
722
|
+
.tb-md-block.active{border-left-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.06))}
|
|
723
|
+
.tb-md-line{display:block;font-size:10px;line-height:1.4;color:var(--dsw-alias-label-tertiary,#8a919c);margin-bottom:1px}
|
|
724
|
+
.tb-md-empty{padding:12px;text-align:center;color:var(--dsw-alias-label-secondary,#9aa0a6);font-size:13px}
|
|
725
|
+
@media (max-width: 760px){.tb-md-body{flex-direction:column}}
|
|
550
726
|
.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)}
|
|
551
727
|
.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}
|
|
552
728
|
.tb-board-title{font-weight:600;font-size:13.5px}
|
|
@@ -559,17 +735,17 @@ window.__ModuleLoader__.load({
|
|
|
559
735
|
.tb-board-note-title{font-weight:600;font-size:12.5px;word-break:break-word}
|
|
560
736
|
.tb-board-meta{font-size:10.5px;color:var(--dsw-alias-label-tertiary,#8a919c);white-space:nowrap}
|
|
561
737
|
.tb-board-actions{margin-left:auto;display:flex;gap:4px;flex-wrap:wrap}
|
|
562
|
-
.tb-md{font-size:
|
|
738
|
+
.tb-md{font-size:14.5px;line-height:1.75;color:var(--dsw-alias-label-primary,#d7dbe2);word-break:break-word}
|
|
563
739
|
.tb-md>*:first-child{margin-top:0}
|
|
564
740
|
.tb-md>*:last-child{margin-bottom:0}
|
|
565
|
-
.tb-md h1,.tb-md h2,.tb-md h3,.tb-md h4,.tb-md h5,.tb-md h6{margin:
|
|
566
|
-
.tb-md h1{font-size:
|
|
567
|
-
.tb-md p{margin:
|
|
568
|
-
.tb-md ul,.tb-md ol{margin:
|
|
569
|
-
.tb-md li{margin:
|
|
741
|
+
.tb-md h1,.tb-md h2,.tb-md h3,.tb-md h4,.tb-md h5,.tb-md h6{margin:12px 0 6px;line-height:1.35;font-weight:700}
|
|
742
|
+
.tb-md h1{font-size:24px}.tb-md h2{font-size:21px}.tb-md h3{font-size:18.5px}.tb-md h4{font-size:16.5px}.tb-md h5{font-size:15px}.tb-md h6{font-size:14px;color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
743
|
+
.tb-md p{margin:7px 0}
|
|
744
|
+
.tb-md ul,.tb-md ol{margin:7px 0;padding-left:24px}
|
|
745
|
+
.tb-md li{margin:4px 0}
|
|
570
746
|
.tb-md blockquote{margin:6px 0;padding:2px 10px;border-left:3px solid var(--dsw-alias-border-l2,rgba(255,255,255,.24));color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
571
|
-
.tb-md code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:
|
|
572
|
-
.tb-md pre{margin:
|
|
747
|
+
.tb-md code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.08));border-radius:4px;padding:1px 4px}
|
|
748
|
+
.tb-md pre{margin:9px 0;padding:10px 12px;font-size:13px;line-height:1.6;border-radius:7px;background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.28));overflow:auto;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.1))}
|
|
573
749
|
.tb-md pre code{background:transparent;padding:0}
|
|
574
750
|
.tb-md a{color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff)}
|
|
575
751
|
.tb-md hr{border:0;border-top:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));margin:8px 0}
|
|
@@ -698,7 +874,7 @@ window.__ModuleLoader__.load({
|
|
|
698
874
|
/** Parse inline Markdown (bold/italic/code/link) into React children. */
|
|
699
875
|
function inlineMarkdown(text, keyPrefix) {
|
|
700
876
|
const nodes = []
|
|
701
|
-
const pattern = /(
|
|
877
|
+
const pattern = /(<span style="color:\s*#[0-9a-f]{3,8}\s*">[\s\S]*?<\/span>|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|\*[^*\n]+\*|_[^\n_]+_)/g
|
|
702
878
|
let last = 0
|
|
703
879
|
let match
|
|
704
880
|
let index = 0
|
|
@@ -706,7 +882,11 @@ window.__ModuleLoader__.load({
|
|
|
706
882
|
if (match.index > last) nodes.push(text.slice(last, match.index))
|
|
707
883
|
const token = match[0]
|
|
708
884
|
const key = `${keyPrefix}-i${index++}`
|
|
709
|
-
if (token.startsWith('
|
|
885
|
+
if (token.startsWith('<span')) {
|
|
886
|
+
const match = /^<span style="color:\s*(#[0-9a-f]{3,8})\s*">([\s\S]*?)<\/span>$/i.exec(token)
|
|
887
|
+
if (match) nodes.push(h('span', { key, style: { color: match[1] } }, ...inlineMarkdown(match[2], `${keyPrefix}-c${index}`)))
|
|
888
|
+
else nodes.push(token)
|
|
889
|
+
} else if (token.startsWith('`')) nodes.push(h('code', { key }, token.slice(1, -1)))
|
|
710
890
|
else if (token.startsWith('**') || token.startsWith('__')) nodes.push(h('strong', { key }, token.slice(2, -2)))
|
|
711
891
|
else if (token.startsWith('[')) {
|
|
712
892
|
const link = /^\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)$/.exec(token)
|
|
@@ -2336,11 +2516,12 @@ window.__ModuleLoader__.load({
|
|
|
2336
2516
|
h('button', { type: 'button', className: 'tb-btn', disabled: noteEditor.busy, onClick: () => setNoteEditor(null) }, t('note.cancel')),
|
|
2337
2517
|
),
|
|
2338
2518
|
h('div', { className: 'tb-ws-hint' }, t('note.hint')),
|
|
2339
|
-
h(
|
|
2519
|
+
h(MarkdownEditor, {
|
|
2340
2520
|
value: noteEditor.text,
|
|
2341
|
-
|
|
2521
|
+
onChange: (next) => setNoteEditor({ ...noteEditor, text: next }),
|
|
2522
|
+
t,
|
|
2342
2523
|
disabled: noteEditor.busy,
|
|
2343
|
-
|
|
2524
|
+
placeholder: t('note.placeholder'),
|
|
2344
2525
|
}),
|
|
2345
2526
|
noteEditor.error ? h('div', { className: 'tb-feedback err' }, noteEditor.error) : null,
|
|
2346
2527
|
h(
|
|
@@ -2756,13 +2937,32 @@ window.__ModuleLoader__.load({
|
|
|
2756
2937
|
|
|
2757
2938
|
const BOARD_NOTE_W = 232
|
|
2758
2939
|
const BOARD_NOTE_H = 176
|
|
2759
|
-
const BOARD_STAGE_W =
|
|
2760
|
-
const BOARD_STAGE_H =
|
|
2940
|
+
const BOARD_STAGE_W = 4000
|
|
2941
|
+
const BOARD_STAGE_H = 3000
|
|
2761
2942
|
const BOARD_COLORS = ['#e6b84c', '#ff8f7a', '#7ad3ff', '#8be28b', '#d9a8ff', '#ffffff']
|
|
2762
|
-
const BOARD_INKS = [
|
|
2943
|
+
const BOARD_INKS = [
|
|
2944
|
+
'#e6b84c', '#ff7a7a', '#7ad3ff', '#8be28b', '#d9a8ff', '#ffffff',
|
|
2945
|
+
'#ff9f43', '#ff6b81', '#54a0ff', '#00d2d3', '#10ac84', '#f368e0',
|
|
2946
|
+
'#576574', '#222f3e', '#feca57', '#48dbfb',
|
|
2947
|
+
]
|
|
2948
|
+
|
|
2949
|
+
/** #rrggbb -> [r,g,b]. */
|
|
2950
|
+
function hexToRgb(value) {
|
|
2951
|
+
const match = /^#?([0-9a-f]{6})$/i.exec(String(value || '').trim())
|
|
2952
|
+
if (!match) return [255, 255, 255]
|
|
2953
|
+
const number = parseInt(match[1], 16)
|
|
2954
|
+
return [(number >> 16) & 255, (number >> 8) & 255, number & 255]
|
|
2955
|
+
}
|
|
2956
|
+
|
|
2957
|
+
/** [r,g,b] -> #rrggbb. */
|
|
2958
|
+
function rgbToHex(rgb) {
|
|
2959
|
+
return `#${rgb.map((value) => Math.min(255, Math.max(0, Math.round(Number(value) || 0))).toString(16).padStart(2, '0')).join('')}`
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2962
|
+
const BOARD_ANCHORS = ['top', 'right', 'bottom', 'left']
|
|
2763
2963
|
|
|
2764
2964
|
function emptyBoardCanvas() {
|
|
2765
|
-
return { notes: {}, background: [], drawings: {} }
|
|
2965
|
+
return { notes: {}, background: [], drawings: {}, edges: [] }
|
|
2766
2966
|
}
|
|
2767
2967
|
|
|
2768
2968
|
/** Deep-copy the sticky canvas so React sees new references. */
|
|
@@ -2781,21 +2981,147 @@ window.__ModuleLoader__.load({
|
|
|
2781
2981
|
drawings: Object.fromEntries(
|
|
2782
2982
|
Object.entries(canvas.drawings && typeof canvas.drawings === 'object' ? canvas.drawings : {}).map(([id, strokes]) => [id, copyStrokes(strokes)]),
|
|
2783
2983
|
),
|
|
2984
|
+
edges: (Array.isArray(canvas.edges) ? canvas.edges : []).map((edge) => ({
|
|
2985
|
+
...edge,
|
|
2986
|
+
from: { ...(edge.from ?? {}) },
|
|
2987
|
+
to: { ...(edge.to ?? {}) },
|
|
2988
|
+
})),
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
|
|
2992
|
+
/** World coordinates of one sticky anchor point. */
|
|
2993
|
+
function boardAnchorPoint(layout, anchor) {
|
|
2994
|
+
const x = Number(layout?.x) || 0
|
|
2995
|
+
const y = Number(layout?.y) || 0
|
|
2996
|
+
const width = Math.min(640, Math.max(160, Number(layout?.width) || BOARD_NOTE_W))
|
|
2997
|
+
const height = Math.min(560, Math.max(120, Number(layout?.height) || BOARD_NOTE_H))
|
|
2998
|
+
if (anchor === 'top') return [x + width / 2, y]
|
|
2999
|
+
if (anchor === 'right') return [x + width, y + height / 2]
|
|
3000
|
+
if (anchor === 'bottom') return [x + width / 2, y + height]
|
|
3001
|
+
return [x, y + height / 2]
|
|
3002
|
+
}
|
|
3003
|
+
|
|
3004
|
+
/** Nearest anchor id to a world point. */
|
|
3005
|
+
function nearestBoardAnchor(layout, point) {
|
|
3006
|
+
let best = BOARD_ANCHORS[0]
|
|
3007
|
+
let bestDistance = Infinity
|
|
3008
|
+
for (const anchor of BOARD_ANCHORS) {
|
|
3009
|
+
const [x, y] = boardAnchorPoint(layout, anchor)
|
|
3010
|
+
const distance = Math.hypot(x - point[0], y - point[1])
|
|
3011
|
+
if (distance < bestDistance) {
|
|
3012
|
+
bestDistance = distance
|
|
3013
|
+
best = anchor
|
|
3014
|
+
}
|
|
2784
3015
|
}
|
|
3016
|
+
return best
|
|
2785
3017
|
}
|
|
2786
3018
|
|
|
2787
|
-
/**
|
|
2788
|
-
function
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
3019
|
+
/** Cubic path between two anchor points (same path in both directions). */
|
|
3020
|
+
function boardEdgePath(from, to) {
|
|
3021
|
+
let [x1, y1] = from
|
|
3022
|
+
let [x2, y2] = to
|
|
3023
|
+
if (x1 > x2 || (x1 === x2 && y1 > y2)) {
|
|
3024
|
+
;[x1, x2] = [x2, x1]
|
|
3025
|
+
;[y1, y2] = [y2, y1]
|
|
3026
|
+
}
|
|
3027
|
+
const dx = Math.max(24, Math.abs(x2 - x1) * 0.4)
|
|
3028
|
+
const dy = Math.max(20, Math.abs(y2 - y1) * 0.25)
|
|
3029
|
+
return `M ${x1} ${y1} C ${x1 + dx} ${y1 + (y2 >= y1 ? dy : -dy)}, ${x2 - dx} ${y2 + (y1 >= y2 ? dy : -dy)}, ${x2} ${y2}`
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
/** Arrowhead polygon points for one arrow stroke. */
|
|
3033
|
+
function boardArrowHead(first, last, size) {
|
|
3034
|
+
const dx = last[0] - first[0]
|
|
3035
|
+
const dy = last[1] - first[1]
|
|
3036
|
+
const length = Math.hypot(dx, dy)
|
|
3037
|
+
if (length < 1) return ''
|
|
3038
|
+
const ux = dx / length
|
|
3039
|
+
const uy = dy / length
|
|
3040
|
+
const px = -uy
|
|
3041
|
+
const py = ux
|
|
3042
|
+
const head = Math.min(18, Math.max(8, size * 4))
|
|
3043
|
+
const width = head * 0.55
|
|
3044
|
+
const p1 = `${last[0] - ux * head + px * width},${last[1] - uy * head + py * width}`
|
|
3045
|
+
const p2 = `${last[0] - ux * head - px * width},${last[1] - uy * head - py * width}`
|
|
3046
|
+
return `${last[0]},${last[1]} ${p1} ${p2}`
|
|
3047
|
+
}
|
|
3048
|
+
|
|
3049
|
+
/** Render pen strokes and common shapes for one stroke layer. */
|
|
3050
|
+
function boardStrokeElements(strokes, keyPrefix) {
|
|
3051
|
+
return (strokes ?? []).map((stroke, index) => {
|
|
3052
|
+
const key = `${keyPrefix}-${index}`
|
|
3053
|
+
const points = stroke.points ?? []
|
|
3054
|
+
const kind = stroke.kind || 'pen'
|
|
3055
|
+
const color = stroke.color
|
|
3056
|
+
const width = stroke.width
|
|
3057
|
+
if (kind === 'pen' || points.length < 2) {
|
|
3058
|
+
return h('polyline', {
|
|
3059
|
+
key,
|
|
3060
|
+
points: points.map((point) => `${point[0]},${point[1]}`).join(' '),
|
|
3061
|
+
fill: 'none',
|
|
3062
|
+
stroke: color,
|
|
3063
|
+
strokeWidth: width,
|
|
3064
|
+
strokeLinecap: 'round',
|
|
3065
|
+
strokeLinejoin: 'round',
|
|
3066
|
+
})
|
|
3067
|
+
}
|
|
3068
|
+
const a = points[0]
|
|
3069
|
+
const b = points[1]
|
|
3070
|
+
const x = Math.min(a[0], b[0])
|
|
3071
|
+
const y = Math.min(a[1], b[1])
|
|
3072
|
+
const w = Math.abs(b[0] - a[0])
|
|
3073
|
+
const hgt = Math.abs(b[1] - a[1])
|
|
3074
|
+
if (kind === 'rect') {
|
|
3075
|
+
return h('rect', { key, x, y, width: w, height: hgt, rx: 2, fill: 'none', stroke: color, strokeWidth: width })
|
|
3076
|
+
}
|
|
3077
|
+
if (kind === 'ellipse') {
|
|
3078
|
+
return h('ellipse', { key, cx: x + w / 2, cy: y + hgt / 2, rx: w / 2, ry: hgt / 2, fill: 'none', stroke: color, strokeWidth: width })
|
|
3079
|
+
}
|
|
3080
|
+
if (kind === 'line') {
|
|
3081
|
+
return h('line', { key, x1: a[0], y1: a[1], x2: b[0], y2: b[1], stroke: color, strokeWidth: width, strokeLinecap: 'round' })
|
|
3082
|
+
}
|
|
3083
|
+
if (kind === 'triangle') {
|
|
3084
|
+
return h('polygon', {
|
|
3085
|
+
key,
|
|
3086
|
+
points: `${(a[0] + b[0]) / 2},${y} ${x},${y + hgt} ${x + w},${y + hgt}`,
|
|
3087
|
+
fill: 'none',
|
|
3088
|
+
stroke: color,
|
|
3089
|
+
strokeWidth: width,
|
|
3090
|
+
strokeLinejoin: 'round',
|
|
3091
|
+
})
|
|
3092
|
+
}
|
|
3093
|
+
if (kind === 'arrow') {
|
|
3094
|
+
return h(
|
|
3095
|
+
'g',
|
|
3096
|
+
{ key },
|
|
3097
|
+
h('line', { x1: a[0], y1: a[1], x2: b[0], y2: b[1], stroke: color, strokeWidth: width, strokeLinecap: 'round' }),
|
|
3098
|
+
h('polygon', { points: boardArrowHead(a, b, width), fill: color, stroke: 'none' }),
|
|
3099
|
+
)
|
|
3100
|
+
}
|
|
3101
|
+
return h('polyline', {
|
|
3102
|
+
key,
|
|
3103
|
+
points: points.map((point) => `${point[0]},${point[1]}`).join(' '),
|
|
2793
3104
|
fill: 'none',
|
|
2794
|
-
stroke:
|
|
2795
|
-
strokeWidth:
|
|
3105
|
+
stroke: color,
|
|
3106
|
+
strokeWidth: width,
|
|
2796
3107
|
strokeLinecap: 'round',
|
|
2797
|
-
|
|
2798
|
-
|
|
3108
|
+
})
|
|
3109
|
+
})
|
|
3110
|
+
}
|
|
3111
|
+
|
|
3112
|
+
/** Whether an eraser click hits one stroke. */
|
|
3113
|
+
function boardStrokeHit(stroke, point) {
|
|
3114
|
+
const points = stroke.points ?? []
|
|
3115
|
+
if ((stroke.kind || 'pen') === 'pen') {
|
|
3116
|
+
return points.some(([x, y]) => Math.hypot(x - point[0], y - point[1]) < 12)
|
|
3117
|
+
}
|
|
3118
|
+
if (points.length < 2) return false
|
|
3119
|
+
const [a, b] = points
|
|
3120
|
+
return (
|
|
3121
|
+
point[0] >= Math.min(a[0], b[0]) - 10 &&
|
|
3122
|
+
point[0] <= Math.max(a[0], b[0]) + 10 &&
|
|
3123
|
+
point[1] >= Math.min(a[1], b[1]) - 10 &&
|
|
3124
|
+
point[1] <= Math.max(a[1], b[1]) + 10
|
|
2799
3125
|
)
|
|
2800
3126
|
}
|
|
2801
3127
|
|
|
@@ -2805,11 +3131,468 @@ window.__ModuleLoader__.load({
|
|
|
2805
3131
|
return {
|
|
2806
3132
|
x: 24 + (index % columns) * (BOARD_NOTE_W + 20),
|
|
2807
3133
|
y: 24 + Math.floor(index / columns) * (BOARD_NOTE_H + 20),
|
|
3134
|
+
width: BOARD_NOTE_W,
|
|
3135
|
+
height: BOARD_NOTE_H,
|
|
2808
3136
|
z: index,
|
|
2809
3137
|
color: BOARD_COLORS[index % BOARD_COLORS.length],
|
|
2810
3138
|
}
|
|
2811
3139
|
}
|
|
2812
3140
|
|
|
3141
|
+
function escapeHtmlText(text) {
|
|
3142
|
+
return String(text ?? '')
|
|
3143
|
+
.replace(/&/g, '&')
|
|
3144
|
+
.replace(/</g, '<')
|
|
3145
|
+
.replace(/>/g, '>')
|
|
3146
|
+
.replace(/"/g, '"')
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
/** Inline Markdown -> HTML for the rich editor. */
|
|
3150
|
+
function inlineMarkdownToHtml(text) {
|
|
3151
|
+
const pattern = /(<span style="color:\s*#[0-9a-f]{3,8}\s*">[\s\S]*?<\/span>|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|~~[^~]+~~|\*[^*\n]+\*|_[^_\n]+_)/g
|
|
3152
|
+
let html = ''
|
|
3153
|
+
let last = 0
|
|
3154
|
+
let match
|
|
3155
|
+
while ((match = pattern.exec(text)) !== null) {
|
|
3156
|
+
html += escapeHtmlText(text.slice(last, match.index))
|
|
3157
|
+
const token = match[0]
|
|
3158
|
+
if (token.startsWith('<span')) {
|
|
3159
|
+
const span = /^<span style="color:\s*(#[0-9a-f]{3,8})\s*">([\s\S]*?)<\/span>$/i.exec(token)
|
|
3160
|
+
html += span
|
|
3161
|
+
? `<span style="color:${span[1].toLowerCase()}">${inlineMarkdownToHtml(span[2])}</span>`
|
|
3162
|
+
: escapeHtmlText(token)
|
|
3163
|
+
} else if (token.startsWith('**') || token.startsWith('__')) {
|
|
3164
|
+
html += `<strong>${inlineMarkdownToHtml(token.slice(2, -2))}</strong>`
|
|
3165
|
+
} else if (token.startsWith('~~')) {
|
|
3166
|
+
html += `<del>${inlineMarkdownToHtml(token.slice(2, -2))}</del>`
|
|
3167
|
+
} else if (token.startsWith('`')) {
|
|
3168
|
+
html += `<code>${escapeHtmlText(token.slice(1, -1))}</code>`
|
|
3169
|
+
} else if (token.startsWith('[')) {
|
|
3170
|
+
const link = /^\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)$/.exec(token)
|
|
3171
|
+
html += link ? `<a href="${escapeHtmlText(link[2])}">${inlineMarkdownToHtml(link[1])}</a>` : escapeHtmlText(token)
|
|
3172
|
+
} else {
|
|
3173
|
+
html += `<em>${inlineMarkdownToHtml(token.slice(1, -1))}</em>`
|
|
3174
|
+
}
|
|
3175
|
+
last = match.index + token.length
|
|
3176
|
+
}
|
|
3177
|
+
return html + escapeHtmlText(text.slice(last))
|
|
3178
|
+
}
|
|
3179
|
+
|
|
3180
|
+
/** Markdown document -> editable HTML for the WYSIWYG editor. */
|
|
3181
|
+
function markdownToEditorHtml(markdown) {
|
|
3182
|
+
const lines = String(markdown ?? '').replace(/\r\n?/g, '\n').split('\n')
|
|
3183
|
+
const out = []
|
|
3184
|
+
let index = 0
|
|
3185
|
+
while (index < lines.length) {
|
|
3186
|
+
const line = lines[index]
|
|
3187
|
+
if (/^\s*$/.test(line)) {
|
|
3188
|
+
index += 1
|
|
3189
|
+
continue
|
|
3190
|
+
}
|
|
3191
|
+
const fence = /^```(\w*)\s*$/.exec(line)
|
|
3192
|
+
if (fence) {
|
|
3193
|
+
const code = []
|
|
3194
|
+
index += 1
|
|
3195
|
+
while (index < lines.length && !/^```\s*$/.test(lines[index])) {
|
|
3196
|
+
code.push(lines[index])
|
|
3197
|
+
index += 1
|
|
3198
|
+
}
|
|
3199
|
+
index += 1
|
|
3200
|
+
out.push(`<pre><code>${escapeHtmlText(code.join('\n'))}</code></pre>`)
|
|
3201
|
+
continue
|
|
3202
|
+
}
|
|
3203
|
+
const heading = /^(#{1,6})\s+(.*)$/.exec(line)
|
|
3204
|
+
if (heading) {
|
|
3205
|
+
out.push(`<h${heading[1].length}>${inlineMarkdownToHtml(heading[2])}</h${heading[1].length}>`)
|
|
3206
|
+
index += 1
|
|
3207
|
+
continue
|
|
3208
|
+
}
|
|
3209
|
+
if (/^\s*([-*_])\s*\1\s*\1[\s\S]*$/.test(line)) {
|
|
3210
|
+
out.push('<hr>')
|
|
3211
|
+
index += 1
|
|
3212
|
+
continue
|
|
3213
|
+
}
|
|
3214
|
+
if (/^>\s?/.test(line)) {
|
|
3215
|
+
const quote = []
|
|
3216
|
+
while (index < lines.length && /^>\s?/.test(lines[index])) {
|
|
3217
|
+
quote.push(lines[index].replace(/^>\s?/, ''))
|
|
3218
|
+
index += 1
|
|
3219
|
+
}
|
|
3220
|
+
out.push(`<blockquote>${markdownToEditorHtml(quote.join('\n'))}</blockquote>`)
|
|
3221
|
+
continue
|
|
3222
|
+
}
|
|
3223
|
+
const bullet = /^\s*[-*+]\s+(.*)$/.exec(line)
|
|
3224
|
+
const numbered = /^\s*\d+[.)]\s+(.*)$/.exec(line)
|
|
3225
|
+
if (bullet || numbered) {
|
|
3226
|
+
const ordered = Boolean(numbered)
|
|
3227
|
+
const items = []
|
|
3228
|
+
while (index < lines.length) {
|
|
3229
|
+
const current = ordered ? /^\s*\d+[.)]\s+(.*)$/.exec(lines[index]) : /^\s*[-*+]\s+(.*)$/.exec(lines[index])
|
|
3230
|
+
if (!current) break
|
|
3231
|
+
items.push(`<li>${inlineMarkdownToHtml(current[1])}</li>`)
|
|
3232
|
+
index += 1
|
|
3233
|
+
}
|
|
3234
|
+
out.push(ordered ? `<ol>${items.join('')}</ol>` : `<ul>${items.join('')}</ul>`)
|
|
3235
|
+
continue
|
|
3236
|
+
}
|
|
3237
|
+
const paragraph = []
|
|
3238
|
+
while (index < lines.length) {
|
|
3239
|
+
const candidate = lines[index]
|
|
3240
|
+
if (/^\s*$/.test(candidate)) break
|
|
3241
|
+
if (/^```/.test(candidate) || /^(#{1,6})\s+/.test(candidate) || /^>\s?/.test(candidate) || /^\s*[-*+]\s+/.test(candidate) || /^\s*\d+[.)]\s+/.test(candidate) || /^\s*([-*_])\s*\1\s*\1[\s\S]*$/.test(candidate)) break
|
|
3242
|
+
paragraph.push(candidate)
|
|
3243
|
+
index += 1
|
|
3244
|
+
}
|
|
3245
|
+
out.push(`<p>${paragraph.map((item) => inlineMarkdownToHtml(item)).join('<br>')}</p>`)
|
|
3246
|
+
}
|
|
3247
|
+
return out.join('')
|
|
3248
|
+
}
|
|
3249
|
+
|
|
3250
|
+
/** DOM -> Markdown serializer used by the WYSIWYG editor. */
|
|
3251
|
+
function domToMarkdown(root) {
|
|
3252
|
+
const childrenOf = (node) => (node && node.childNodes ? Array.from(node.childNodes) : [])
|
|
3253
|
+
const tagOf = (node) => String(node?.tagName || node?.nodeName || '').toUpperCase()
|
|
3254
|
+
const colorOf = (node) => {
|
|
3255
|
+
if (!node) return ''
|
|
3256
|
+
const style = node.style
|
|
3257
|
+
if (style) {
|
|
3258
|
+
if (typeof style === 'string') {
|
|
3259
|
+
const match = /color:\s*(#[0-9a-f]{3,8})/i.exec(style)
|
|
3260
|
+
if (match) return match[1].toLowerCase()
|
|
3261
|
+
} else if (typeof style.color === 'string') {
|
|
3262
|
+
return /^#[0-9a-f]{3,8}$/i.test(style.color) ? style.color.toLowerCase() : ''
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
const attr = node.getAttribute ? node.getAttribute('color') : ''
|
|
3266
|
+
return /^#[0-9a-f]{3,8}$/i.test(String(attr || '')) ? String(attr).toLowerCase() : ''
|
|
3267
|
+
}
|
|
3268
|
+
const inline = (node) => {
|
|
3269
|
+
if (!node) return ''
|
|
3270
|
+
if (node.nodeType === 3) return String(node.nodeValue ?? '')
|
|
3271
|
+
const tag = tagOf(node)
|
|
3272
|
+
const inner = () => childrenOf(node).map(inline).join('')
|
|
3273
|
+
if (tag === 'BR') return '\n'
|
|
3274
|
+
if (tag === 'STRONG' || tag === 'B') return `**${inner()}**`
|
|
3275
|
+
if (tag === 'EM' || tag === 'I') return `*${inner()}*`
|
|
3276
|
+
if (tag === 'DEL' || tag === 'S' || tag === 'STRIKE') return `~~${inner()}~~`
|
|
3277
|
+
if (tag === 'CODE') return `\`${inner()}\``
|
|
3278
|
+
if (tag === 'A') return `[${inner()}](${node.getAttribute ? node.getAttribute('href') || '' : ''})`
|
|
3279
|
+
if (tag === 'IMG') return ` || '' : ''})`
|
|
3280
|
+
const color = colorOf(node)
|
|
3281
|
+
if (color && (tag === 'SPAN' || tag === 'FONT')) return `<span style="color:${color}">${inner()}</span>`
|
|
3282
|
+
return inner()
|
|
3283
|
+
}
|
|
3284
|
+
const inlineOf = (node) => childrenOf(node).map(inline).join('')
|
|
3285
|
+
const block = (node) => {
|
|
3286
|
+
if (!node) return ''
|
|
3287
|
+
if (node.nodeType === 3) return String(node.nodeValue ?? '')
|
|
3288
|
+
const tag = tagOf(node)
|
|
3289
|
+
if (/^H[1-6]$/.test(tag)) return `${'#'.repeat(Number(tag[1]))} ${inlineOf(node)}\n\n`
|
|
3290
|
+
if (tag === 'HR') return '---\n\n'
|
|
3291
|
+
if (tag === 'PRE') {
|
|
3292
|
+
const text = childrenOf(node).map((child) => (child.nodeType === 3 ? String(child.nodeValue ?? '') : block(child))).join('')
|
|
3293
|
+
return `\`\`\`\n${text.replace(/\n+$/, '')}\n\`\`\`\n\n`
|
|
3294
|
+
}
|
|
3295
|
+
if (tag === 'BLOCKQUOTE') {
|
|
3296
|
+
const body = childrenOf(node).map(block).join('').trim()
|
|
3297
|
+
return `${body.split('\n').map((line) => `> ${line}`).join('\n')}\n\n`
|
|
3298
|
+
}
|
|
3299
|
+
if (tag === 'UL' || tag === 'OL') {
|
|
3300
|
+
const ordered = tag === 'OL'
|
|
3301
|
+
const items = childrenOf(node)
|
|
3302
|
+
.filter((child) => tagOf(child) === 'LI')
|
|
3303
|
+
.map((child, itemIndex) => `${ordered ? `${itemIndex + 1}. ` : '- '}${inlineOf(child).trim()}`)
|
|
3304
|
+
.join('\n')
|
|
3305
|
+
return `${items}\n\n`
|
|
3306
|
+
}
|
|
3307
|
+
if (tag === 'P' || tag === 'DIV' || tag === 'LI' || tag === 'SECTION' || tag === 'ARTICLE') {
|
|
3308
|
+
const body = inlineOf(node)
|
|
3309
|
+
return body === '' ? '\n' : `${body}\n\n`
|
|
3310
|
+
}
|
|
3311
|
+
const nested = childrenOf(node)
|
|
3312
|
+
.map((child) => (['UL', 'OL', 'PRE', 'BLOCKQUOTE', 'P', 'DIV', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'HR'].includes(tagOf(child)) ? block(child) : inline(child)))
|
|
3313
|
+
.join('')
|
|
3314
|
+
return `${inline(node) && !nested ? inline(node) : nested}\n\n`
|
|
3315
|
+
}
|
|
3316
|
+
return childrenOf(root)
|
|
3317
|
+
.map((child) => (['UL', 'OL', 'PRE', 'BLOCKQUOTE', 'P', 'DIV', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'HR'].includes(tagOf(child)) ? block(child) : inline(child)))
|
|
3318
|
+
.join('')
|
|
3319
|
+
.replace(/\r\n?/g, '\n')
|
|
3320
|
+
.replace(/[ \t]+\n/g, '\n')
|
|
3321
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
3322
|
+
.trim()
|
|
3323
|
+
}
|
|
3324
|
+
|
|
3325
|
+
/**
|
|
3326
|
+
* WYSIWYG Markdown editor: type directly in the formatted document, select
|
|
3327
|
+
* text and use the toolbar (e.g. B makes 你好 bold immediately). The document
|
|
3328
|
+
* is serialized back to Markdown on every edit. A raw source mode and a
|
|
3329
|
+
* continuous preview are still available as tabs.
|
|
3330
|
+
*/
|
|
3331
|
+
function MarkdownEditor(props) {
|
|
3332
|
+
const t = typeof props?.t === 'function' ? props.t : (key) => key
|
|
3333
|
+
const value = typeof props?.value === 'string' ? props.value : ''
|
|
3334
|
+
const onChange = typeof props?.onChange === 'function' ? props.onChange : () => {}
|
|
3335
|
+
const disabled = props?.disabled === true
|
|
3336
|
+
const [mode, setMode] = React.useState('rich')
|
|
3337
|
+
const sourceRef = React.useRef(null)
|
|
3338
|
+
const richRef = React.useRef(null)
|
|
3339
|
+
const lastMarkdownRef = React.useRef(null)
|
|
3340
|
+
const valueRef = React.useRef(value)
|
|
3341
|
+
valueRef.current = value
|
|
3342
|
+
const composingRef = React.useRef(false)
|
|
3343
|
+
// Stable callback ref: seed the editable document whenever the element is
|
|
3344
|
+
// (re)mounted (e.g. switching preview -> source -> rich). This is what keeps
|
|
3345
|
+
// the content from vanishing on mode switches.
|
|
3346
|
+
const setRichRef = React.useCallback((element) => {
|
|
3347
|
+
richRef.current = element
|
|
3348
|
+
if (!element) return
|
|
3349
|
+
element.innerHTML = markdownToEditorHtml(valueRef.current)
|
|
3350
|
+
lastMarkdownRef.current = valueRef.current
|
|
3351
|
+
}, [])
|
|
3352
|
+
|
|
3353
|
+
const syncRich = () => {
|
|
3354
|
+
if (composingRef.current) return
|
|
3355
|
+
const element = richRef.current
|
|
3356
|
+
if (!element) return
|
|
3357
|
+
const markdown = domToMarkdown(element)
|
|
3358
|
+
lastMarkdownRef.current = markdown
|
|
3359
|
+
if (markdown !== valueRef.current) onChange(markdown)
|
|
3360
|
+
}
|
|
3361
|
+
|
|
3362
|
+
const switchMode = (next) => {
|
|
3363
|
+
if (next === mode) return
|
|
3364
|
+
if (mode === 'rich') syncRich()
|
|
3365
|
+
setMode(next)
|
|
3366
|
+
}
|
|
3367
|
+
|
|
3368
|
+
const exec = (command, argument = null) => {
|
|
3369
|
+
const element = richRef.current
|
|
3370
|
+
if (!element) return
|
|
3371
|
+
try {
|
|
3372
|
+
element.focus()
|
|
3373
|
+
document.execCommand(command, false, argument)
|
|
3374
|
+
} catch {
|
|
3375
|
+
// execCommand can be unavailable; the source tab still works.
|
|
3376
|
+
}
|
|
3377
|
+
syncRich()
|
|
3378
|
+
}
|
|
3379
|
+
|
|
3380
|
+
const insertHtml = (html) => {
|
|
3381
|
+
const element = richRef.current
|
|
3382
|
+
if (!element) return
|
|
3383
|
+
let selected = ''
|
|
3384
|
+
try {
|
|
3385
|
+
selected = String(window.getSelection()?.toString() || '')
|
|
3386
|
+
} catch {
|
|
3387
|
+
selected = ''
|
|
3388
|
+
}
|
|
3389
|
+
exec('insertHTML', html.replace('{selection}', escapeHtmlText(selected)))
|
|
3390
|
+
}
|
|
3391
|
+
|
|
3392
|
+
const sourceSelection = () => {
|
|
3393
|
+
const area = sourceRef.current
|
|
3394
|
+
const start = area && Number.isFinite(area.selectionStart) ? area.selectionStart : value.length
|
|
3395
|
+
const end = area && Number.isFinite(area.selectionEnd) ? area.selectionEnd : start
|
|
3396
|
+
return { text: value, start, end, selected: value.slice(start, end) }
|
|
3397
|
+
}
|
|
3398
|
+
const sourceCommit = (next, selection) => {
|
|
3399
|
+
onChange(next)
|
|
3400
|
+
window.requestAnimationFrame(() => {
|
|
3401
|
+
const area = sourceRef.current
|
|
3402
|
+
if (!area) return
|
|
3403
|
+
area.focus()
|
|
3404
|
+
if (Array.isArray(selection)) area.setSelectionRange(selection[0], selection[1])
|
|
3405
|
+
})
|
|
3406
|
+
}
|
|
3407
|
+
const sourceSurround = (before, after = '') => {
|
|
3408
|
+
const { text, start, end, selected } = sourceSelection()
|
|
3409
|
+
sourceCommit(`${text.slice(0, start)}${before}${selected}${after}${text.slice(end)}`, [start + before.length, start + before.length + selected.length])
|
|
3410
|
+
}
|
|
3411
|
+
const sourceTransformLines = (mapper) => {
|
|
3412
|
+
const { text, start, end } = sourceSelection()
|
|
3413
|
+
const lineStart = text.lastIndexOf('\n', Math.max(0, start - 1)) + 1
|
|
3414
|
+
let lineEnd = text.indexOf('\n', end)
|
|
3415
|
+
if (lineEnd === -1) lineEnd = text.length
|
|
3416
|
+
const transformed = text
|
|
3417
|
+
.slice(lineStart, lineEnd)
|
|
3418
|
+
.split('\n')
|
|
3419
|
+
.map((line, lineIndex) => mapper(line, lineIndex))
|
|
3420
|
+
.join('\n')
|
|
3421
|
+
sourceCommit(`${text.slice(0, lineStart)}${transformed}${text.slice(lineEnd)}`, [lineStart + transformed.length, lineStart + transformed.length])
|
|
3422
|
+
}
|
|
3423
|
+
const sourceInsert = (snippet) => {
|
|
3424
|
+
const { text, start, end } = sourceSelection()
|
|
3425
|
+
const before = start > 0 && !text.slice(0, start).endsWith('\n') ? '\n' : ''
|
|
3426
|
+
const after = end < text.length && !text.slice(end).startsWith('\n') ? '\n' : ''
|
|
3427
|
+
const payload = `${before}${snippet}${after}`
|
|
3428
|
+
sourceCommit(`${text.slice(0, start)}${payload}${text.slice(end)}`, [start + payload.length, start + payload.length])
|
|
3429
|
+
}
|
|
3430
|
+
const applyColor = (color) => {
|
|
3431
|
+
if (mode === 'rich') exec('foreColor', color)
|
|
3432
|
+
else if (mode === 'source') sourceSurround(`<span style="color:${color}">`, '</span>')
|
|
3433
|
+
}
|
|
3434
|
+
|
|
3435
|
+
const richTools = [
|
|
3436
|
+
{ key: 'h1', label: 'H1', title: t('md.heading'), run: () => exec('formatBlock', '<h1>') },
|
|
3437
|
+
{ key: 'h2', label: 'H2', title: t('md.heading'), run: () => exec('formatBlock', '<h2>') },
|
|
3438
|
+
{ key: 'h3', label: 'H3', title: t('md.heading'), run: () => exec('formatBlock', '<h3>') },
|
|
3439
|
+
{ key: 'bold', label: 'B', title: t('md.bold'), run: () => exec('bold') },
|
|
3440
|
+
{ key: 'italic', label: 'I', title: t('md.italic'), run: () => exec('italic') },
|
|
3441
|
+
{ key: 'strike', label: 'S', title: t('md.strike'), run: () => exec('strikeThrough') },
|
|
3442
|
+
{ key: 'code', label: '`', title: t('md.inlineCode'), run: () => insertHtml('<code>{selection}</code>') },
|
|
3443
|
+
{ key: 'codeblock', label: '```', title: t('md.codeBlock'), run: () => exec('formatBlock', '<pre>') },
|
|
3444
|
+
{ key: 'bullet', label: '•', title: t('md.bullet'), run: () => exec('insertUnorderedList') },
|
|
3445
|
+
{ key: 'numbered', label: '1.', title: t('md.numbered'), run: () => exec('insertOrderedList') },
|
|
3446
|
+
{ key: 'task', label: '☐', title: t('md.task'), run: () => insertHtml('<div>- [ ] {selection}</div>') },
|
|
3447
|
+
{ key: 'quote', label: '❝', title: t('md.quote'), run: () => exec('formatBlock', '<blockquote>') },
|
|
3448
|
+
{ key: 'link', label: '🔗', title: t('md.link'), run: () => {
|
|
3449
|
+
let href = 'https://'
|
|
3450
|
+
try {
|
|
3451
|
+
href = window.prompt(t('md.linkPrompt'), 'https://') || ''
|
|
3452
|
+
} catch {
|
|
3453
|
+
href = ''
|
|
3454
|
+
}
|
|
3455
|
+
if (href) exec('createLink', href)
|
|
3456
|
+
} },
|
|
3457
|
+
{ key: 'hr', label: '—', title: t('md.hr'), run: () => exec('insertHorizontalRule') },
|
|
3458
|
+
]
|
|
3459
|
+
const sourceTools = [
|
|
3460
|
+
{ key: 'h1', label: 'H1', title: t('md.heading'), run: () => sourceTransformLines((line, lineIndex) => (lineIndex === 0 ? `# ${line.replace(/^#{1,6}\s+/, '')}` : line)) },
|
|
3461
|
+
{ key: 'h2', label: 'H2', title: t('md.heading'), run: () => sourceTransformLines((line, lineIndex) => (lineIndex === 0 ? `## ${line.replace(/^#{1,6}\s+/, '')}` : line)) },
|
|
3462
|
+
{ key: 'h3', label: 'H3', title: t('md.heading'), run: () => sourceTransformLines((line, lineIndex) => (lineIndex === 0 ? `### ${line.replace(/^#{1,6}\s+/, '')}` : line)) },
|
|
3463
|
+
{ key: 'bold', label: 'B', title: t('md.bold'), run: () => sourceSurround('**', '**') },
|
|
3464
|
+
{ key: 'italic', label: 'I', title: t('md.italic'), run: () => sourceSurround('*', '*') },
|
|
3465
|
+
{ key: 'strike', label: 'S', title: t('md.strike'), run: () => sourceSurround('~~', '~~') },
|
|
3466
|
+
{ key: 'code', label: '`', title: t('md.inlineCode'), run: () => sourceSurround('`', '`') },
|
|
3467
|
+
{ key: 'codeblock', label: '```', title: t('md.codeBlock'), run: () => sourceInsert('```\n\n```') },
|
|
3468
|
+
{ key: 'bullet', label: '•', title: t('md.bullet'), run: () => sourceTransformLines((line) => `- ${line.replace(/^[-*+]\s+/, '')}`) },
|
|
3469
|
+
{ key: 'numbered', label: '1.', title: t('md.numbered'), run: () => sourceTransformLines((line, lineIndex) => `${lineIndex + 1}. ${line.replace(/^\d+[.)]\s+/, '')}`) },
|
|
3470
|
+
{ key: 'task', label: '☐', title: t('md.task'), run: () => sourceTransformLines((line) => `- [ ] ${line.replace(/^[-*+]\s+(\[[ xX]\]\s+)?/, '')}`) },
|
|
3471
|
+
{ key: 'quote', label: '❝', title: t('md.quote'), run: () => sourceTransformLines((line) => `> ${line.replace(/^>\s?/, '')}`) },
|
|
3472
|
+
{ key: 'link', label: '🔗', title: t('md.link'), run: () => sourceSurround('[', '](https://)') },
|
|
3473
|
+
{ key: 'hr', label: '—', title: t('md.hr'), run: () => sourceInsert('---') },
|
|
3474
|
+
]
|
|
3475
|
+
const tools = mode === 'rich' ? richTools : sourceTools
|
|
3476
|
+
|
|
3477
|
+
return h(
|
|
3478
|
+
'div',
|
|
3479
|
+
{ className: 'tb-md-editor' },
|
|
3480
|
+
h(
|
|
3481
|
+
'div',
|
|
3482
|
+
{ className: 'tb-md-toolbar', role: 'toolbar' },
|
|
3483
|
+
h(
|
|
3484
|
+
'div',
|
|
3485
|
+
{ className: 'tb-md-tools' },
|
|
3486
|
+
...tools.map((tool) =>
|
|
3487
|
+
h('button', { key: tool.key, type: 'button', className: 'tb-md-tool', title: tool.title, disabled, onClick: tool.run }, tool.label),
|
|
3488
|
+
),
|
|
3489
|
+
),
|
|
3490
|
+
h(
|
|
3491
|
+
'div',
|
|
3492
|
+
{ className: 'tb-md-mode' },
|
|
3493
|
+
...['rich', 'source', 'preview'].map((value_) =>
|
|
3494
|
+
h(
|
|
3495
|
+
'button',
|
|
3496
|
+
{ key: value_, type: 'button', className: `tb-md-tool${mode === value_ ? ' on' : ''}`, onClick: () => switchMode(value_) },
|
|
3497
|
+
t(`md.${value_}`),
|
|
3498
|
+
),
|
|
3499
|
+
),
|
|
3500
|
+
),
|
|
3501
|
+
),
|
|
3502
|
+
h(
|
|
3503
|
+
'div',
|
|
3504
|
+
{ className: 'tb-md-colorbar' },
|
|
3505
|
+
h('span', { className: 'tb-md-color-label' }, t('md.color')),
|
|
3506
|
+
...BOARD_INKS.slice(0, 8).map((color) =>
|
|
3507
|
+
h('button', {
|
|
3508
|
+
key: `color-${color}`,
|
|
3509
|
+
type: 'button',
|
|
3510
|
+
className: 'tb-md-color',
|
|
3511
|
+
title: color,
|
|
3512
|
+
style: { background: color },
|
|
3513
|
+
disabled,
|
|
3514
|
+
onClick: () => applyColor(color),
|
|
3515
|
+
}),
|
|
3516
|
+
),
|
|
3517
|
+
h(
|
|
3518
|
+
'span',
|
|
3519
|
+
{ className: 'tb-md-color-custom' },
|
|
3520
|
+
h('span', { className: 'tb-md-color-label' }, t('md.customColor')),
|
|
3521
|
+
h('input', {
|
|
3522
|
+
type: 'color',
|
|
3523
|
+
className: 'tb-md-color-input',
|
|
3524
|
+
title: t('md.color'),
|
|
3525
|
+
disabled,
|
|
3526
|
+
style: { width: 30, height: 24, minWidth: 30, flex: '0 0 auto' },
|
|
3527
|
+
onChange: (event) => applyColor(event.target.value),
|
|
3528
|
+
}),
|
|
3529
|
+
),
|
|
3530
|
+
),
|
|
3531
|
+
h('div', { className: 'tb-ws-hint', style: { fontSize: '10.5px' } }, t('md.hint')),
|
|
3532
|
+
h(
|
|
3533
|
+
'div',
|
|
3534
|
+
{ className: 'tb-md-body' },
|
|
3535
|
+
mode === 'rich'
|
|
3536
|
+
? h('div', {
|
|
3537
|
+
ref: setRichRef,
|
|
3538
|
+
className: 'tb-md-rich',
|
|
3539
|
+
contentEditable: true,
|
|
3540
|
+
suppressContentEditableWarning: true,
|
|
3541
|
+
role: 'textbox',
|
|
3542
|
+
'aria-multiline': 'true',
|
|
3543
|
+
'data-placeholder': props?.placeholder || '',
|
|
3544
|
+
onInput: syncRich,
|
|
3545
|
+
onBlur: syncRich,
|
|
3546
|
+
onKeyUp: syncRich,
|
|
3547
|
+
onCompositionStart: () => {
|
|
3548
|
+
composingRef.current = true
|
|
3549
|
+
},
|
|
3550
|
+
onCompositionEnd: () => {
|
|
3551
|
+
composingRef.current = false
|
|
3552
|
+
syncRich()
|
|
3553
|
+
},
|
|
3554
|
+
onPaste: () => window.setTimeout(syncRich, 0),
|
|
3555
|
+
})
|
|
3556
|
+
: mode === 'source'
|
|
3557
|
+
? h('textarea', {
|
|
3558
|
+
ref: sourceRef,
|
|
3559
|
+
className: 'tb-md-source',
|
|
3560
|
+
value,
|
|
3561
|
+
disabled,
|
|
3562
|
+
placeholder: props?.placeholder || '',
|
|
3563
|
+
onChange: (event) => onChange(event.target.value),
|
|
3564
|
+
onKeyDown: (event) => {
|
|
3565
|
+
if ((event.ctrlKey || event.metaKey) && !event.altKey) {
|
|
3566
|
+
const key = event.key.toLowerCase()
|
|
3567
|
+
if (key === 'b') {
|
|
3568
|
+
event.preventDefault()
|
|
3569
|
+
sourceSurround('**', '**')
|
|
3570
|
+
} else if (key === 'i') {
|
|
3571
|
+
event.preventDefault()
|
|
3572
|
+
sourceSurround('*', '*')
|
|
3573
|
+
} else if (key === 's') {
|
|
3574
|
+
event.preventDefault()
|
|
3575
|
+
sourceSurround('~~', '~~')
|
|
3576
|
+
} else if (key === '`') {
|
|
3577
|
+
event.preventDefault()
|
|
3578
|
+
sourceSurround('`', '`')
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
},
|
|
3582
|
+
})
|
|
3583
|
+
: h('div', { className: 'tb-md tb-md-readonly' }, ...(value.trim() ? renderMarkdown(value, 'mde') : [h('div', { key: 'empty', className: 'tb-md-empty' }, t('md.empty'))])),
|
|
3584
|
+
),
|
|
3585
|
+
)
|
|
3586
|
+
}
|
|
3587
|
+
|
|
3588
|
+
const BOARD_SHAPES = [
|
|
3589
|
+
['rect', '▭', 'board.shapeRect'],
|
|
3590
|
+
['ellipse', '◯', 'board.shapeEllipse'],
|
|
3591
|
+
['line', '╱', 'board.shapeLine'],
|
|
3592
|
+
['arrow', '→', 'board.shapeArrow'],
|
|
3593
|
+
['triangle', '△', 'board.shapeTriangle'],
|
|
3594
|
+
]
|
|
3595
|
+
|
|
2813
3596
|
function BoardPanel(props) {
|
|
2814
3597
|
const t = typeof props?.t === 'function' ? props.t : (key) => key
|
|
2815
3598
|
const [state, setState] = React.useState({ loading: true, board: null, error: null })
|
|
@@ -2836,13 +3619,59 @@ window.__ModuleLoader__.load({
|
|
|
2836
3619
|
const [tool, setTool] = React.useState('select')
|
|
2837
3620
|
const toolRef = React.useRef(tool)
|
|
2838
3621
|
toolRef.current = tool
|
|
2839
|
-
const [ink, setInk] = React.useState(
|
|
3622
|
+
const [ink, setInk] = React.useState(() => {
|
|
3623
|
+
try {
|
|
3624
|
+
const stored = window.localStorage.getItem('dsh-timeback:board-ink-color') || ''
|
|
3625
|
+
return /^#[0-9a-f]{6}$/i.test(stored) ? stored.toLowerCase() : BOARD_INKS[0]
|
|
3626
|
+
} catch {
|
|
3627
|
+
return BOARD_INKS[0]
|
|
3628
|
+
}
|
|
3629
|
+
})
|
|
2840
3630
|
const inkRef = React.useRef(ink)
|
|
2841
3631
|
inkRef.current = ink
|
|
3632
|
+
const [inkWidth, setInkWidth] = React.useState(() => {
|
|
3633
|
+
try {
|
|
3634
|
+
const raw = Number(window.localStorage.getItem('dsh-timeback:board-ink-width'))
|
|
3635
|
+
return Number.isFinite(raw) && raw >= 1 && raw <= 8 ? Math.round(raw) : 2
|
|
3636
|
+
} catch {
|
|
3637
|
+
return 2
|
|
3638
|
+
}
|
|
3639
|
+
})
|
|
3640
|
+
const inkWidthRef = React.useRef(inkWidth)
|
|
3641
|
+
inkWidthRef.current = inkWidth
|
|
3642
|
+
const [shapeMenu, setShapeMenu] = React.useState(false)
|
|
3643
|
+
const [colorOpen, setColorOpen] = React.useState(false)
|
|
3644
|
+
const [colorHint, setColorHint] = React.useState('')
|
|
3645
|
+
const [recentColors, setRecentColors] = React.useState(() => {
|
|
3646
|
+
try {
|
|
3647
|
+
const raw = JSON.parse(window.localStorage.getItem('dsh-timeback:board-recent-colors') || '[]')
|
|
3648
|
+
return Array.isArray(raw) ? raw.filter((value) => /^#[0-9a-f]{6}$/i.test(String(value))).slice(0, 8) : []
|
|
3649
|
+
} catch {
|
|
3650
|
+
return []
|
|
3651
|
+
}
|
|
3652
|
+
})
|
|
2842
3653
|
const [selected, setSelected] = React.useState('')
|
|
2843
3654
|
const selectedRef = React.useRef(selected)
|
|
2844
3655
|
selectedRef.current = selected
|
|
3656
|
+
const [readerId, setReaderId] = React.useState('')
|
|
3657
|
+
const [linkPreview, setLinkPreview] = React.useState(null)
|
|
3658
|
+
const [zoom, setZoom] = React.useState(1)
|
|
3659
|
+
const zoomRef = React.useRef(zoom)
|
|
3660
|
+
zoomRef.current = zoom
|
|
3661
|
+
const zoomAnchorRef = React.useRef(null)
|
|
3662
|
+
const wheelRef = React.useRef({ frame: 0, target: null, pointer: null })
|
|
3663
|
+
const [drawOnSticky, setDrawOnSticky] = React.useState(() => {
|
|
3664
|
+
try {
|
|
3665
|
+
return window.localStorage.getItem('dsh-timeback:board-draw-on-sticky') !== '0'
|
|
3666
|
+
} catch {
|
|
3667
|
+
return true
|
|
3668
|
+
}
|
|
3669
|
+
})
|
|
3670
|
+
const drawOnStickyRef = React.useRef(drawOnSticky)
|
|
3671
|
+
drawOnStickyRef.current = drawOnSticky
|
|
3672
|
+
const centeredRef = React.useRef(false)
|
|
2845
3673
|
const stageRef = React.useRef(null)
|
|
3674
|
+
const viewportRef = React.useRef(null)
|
|
2846
3675
|
const saveTimerRef = React.useRef(null)
|
|
2847
3676
|
const gestureRef = React.useRef(null)
|
|
2848
3677
|
|
|
@@ -2874,6 +3703,138 @@ window.__ModuleLoader__.load({
|
|
|
2874
3703
|
if (saveTimerRef.current) clearTimeout(saveTimerRef.current)
|
|
2875
3704
|
}, [])
|
|
2876
3705
|
|
|
3706
|
+
/** Zoom around one viewport point while keeping that content anchored. */
|
|
3707
|
+
const applyZoom = (nextZoom, clientX, clientY) => {
|
|
3708
|
+
const viewport = viewportRef.current
|
|
3709
|
+
if (!viewport) return
|
|
3710
|
+
const clamped = Math.min(3, Math.max(0.2, nextZoom))
|
|
3711
|
+
if (Math.abs(clamped - zoomRef.current) < 0.0001) return
|
|
3712
|
+
const rect = viewport.getBoundingClientRect()
|
|
3713
|
+
const localX = Number.isFinite(clientX) ? clientX - rect.left : viewport.clientWidth / 2
|
|
3714
|
+
const localY = Number.isFinite(clientY) ? clientY - rect.top : viewport.clientHeight / 2
|
|
3715
|
+
const contentX = (viewport.scrollLeft + localX) / zoomRef.current
|
|
3716
|
+
const contentY = (viewport.scrollTop + localY) / zoomRef.current
|
|
3717
|
+
zoomAnchorRef.current = { contentX, contentY, localX, localY }
|
|
3718
|
+
setZoom(clamped)
|
|
3719
|
+
zoomRef.current = clamped
|
|
3720
|
+
}
|
|
3721
|
+
|
|
3722
|
+
// Scroll correction must happen before paint, otherwise the frame in which
|
|
3723
|
+
// the transform changes but the scroll does not yet shows a visible jump
|
|
3724
|
+
// (the "flicker" during wheel zoom).
|
|
3725
|
+
React.useLayoutEffect(() => {
|
|
3726
|
+
const pending = zoomAnchorRef.current
|
|
3727
|
+
if (!pending) return
|
|
3728
|
+
zoomAnchorRef.current = null
|
|
3729
|
+
const viewport = viewportRef.current
|
|
3730
|
+
if (!viewport) return
|
|
3731
|
+
const scale = zoomRef.current || 1
|
|
3732
|
+
viewport.scrollLeft = Math.max(0, pending.contentX * scale - pending.localX)
|
|
3733
|
+
viewport.scrollTop = Math.max(0, pending.contentY * scale - pending.localY)
|
|
3734
|
+
}, [zoom])
|
|
3735
|
+
|
|
3736
|
+
const zoomBy = (factor) => {
|
|
3737
|
+
const viewport = viewportRef.current
|
|
3738
|
+
if (!viewport) return
|
|
3739
|
+
const rect = viewport.getBoundingClientRect()
|
|
3740
|
+
applyZoom(zoomRef.current * factor, rect.left + viewport.clientWidth / 2, rect.top + viewport.clientHeight / 2)
|
|
3741
|
+
}
|
|
3742
|
+
|
|
3743
|
+
/** Delegate wheel/pinch zoom (Ctrl or ⌘ + wheel) to the viewport. */
|
|
3744
|
+
React.useEffect(() => {
|
|
3745
|
+
const viewport = viewportRef.current
|
|
3746
|
+
if (!viewport) return undefined
|
|
3747
|
+
const flushWheel = () => {
|
|
3748
|
+
const state = wheelRef.current
|
|
3749
|
+
state.frame = 0
|
|
3750
|
+
const target = state.target
|
|
3751
|
+
const pointer = state.pointer
|
|
3752
|
+
state.target = null
|
|
3753
|
+
if (target === null) return
|
|
3754
|
+
applyZoom(target, pointer?.x, pointer?.y)
|
|
3755
|
+
}
|
|
3756
|
+
const onWheel = (event) => {
|
|
3757
|
+
if (!(event.ctrlKey || event.metaKey)) return
|
|
3758
|
+
event.preventDefault()
|
|
3759
|
+
const state = wheelRef.current
|
|
3760
|
+
const factor = event.deltaY < 0 ? 1.12 : 1 / 1.12
|
|
3761
|
+
const base = state.target ?? zoomRef.current
|
|
3762
|
+
state.target = Math.min(3, Math.max(0.2, base * factor))
|
|
3763
|
+
state.pointer = { x: event.clientX, y: event.clientY }
|
|
3764
|
+
if (state.frame === 0) state.frame = window.requestAnimationFrame(flushWheel)
|
|
3765
|
+
}
|
|
3766
|
+
viewport.addEventListener('wheel', onWheel, { passive: false })
|
|
3767
|
+
return () => {
|
|
3768
|
+
viewport.removeEventListener('wheel', onWheel)
|
|
3769
|
+
if (wheelRef.current.frame !== 0) {
|
|
3770
|
+
window.cancelAnimationFrame(wheelRef.current.frame)
|
|
3771
|
+
wheelRef.current.frame = 0
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
}, [state.board])
|
|
3775
|
+
|
|
3776
|
+
/** Fit every note/stroke into view: pick a zoom and scroll offset. */
|
|
3777
|
+
const autoFit = () => {
|
|
3778
|
+
const viewport = viewportRef.current
|
|
3779
|
+
if (!viewport) return
|
|
3780
|
+
const notes = (state.board?.entries ?? []).map((entry, index) => layoutFor(entry, index))
|
|
3781
|
+
let minX = Infinity
|
|
3782
|
+
let minY = Infinity
|
|
3783
|
+
let maxX = -Infinity
|
|
3784
|
+
let maxY = -Infinity
|
|
3785
|
+
const include = (x, y) => {
|
|
3786
|
+
if (Number.isFinite(x) && Number.isFinite(y)) {
|
|
3787
|
+
minX = Math.min(minX, x)
|
|
3788
|
+
minY = Math.min(minY, y)
|
|
3789
|
+
maxX = Math.max(maxX, x)
|
|
3790
|
+
maxY = Math.max(maxY, y)
|
|
3791
|
+
}
|
|
3792
|
+
}
|
|
3793
|
+
for (const layout of notes) {
|
|
3794
|
+
const size = noteSize(layout)
|
|
3795
|
+
include(Number(layout.x) || 0, Number(layout.y) || 0)
|
|
3796
|
+
include((Number(layout.x) || 0) + size.width, (Number(layout.y) || 0) + size.height)
|
|
3797
|
+
}
|
|
3798
|
+
const addStrokes = (strokes) => {
|
|
3799
|
+
for (const stroke of strokes ?? []) for (const point of stroke.points ?? []) include(point[0], point[1])
|
|
3800
|
+
}
|
|
3801
|
+
addStrokes(canvasRef.current.background)
|
|
3802
|
+
for (const strokes of Object.values(canvasRef.current.drawings ?? {})) addStrokes(strokes)
|
|
3803
|
+
if (!Number.isFinite(minX)) {
|
|
3804
|
+
minX = BOARD_STAGE_W / 2 - 300
|
|
3805
|
+
maxX = BOARD_STAGE_W / 2 + 300
|
|
3806
|
+
minY = BOARD_STAGE_H / 2 - 200
|
|
3807
|
+
maxY = BOARD_STAGE_H / 2 + 200
|
|
3808
|
+
}
|
|
3809
|
+
const spanX = Math.max(120, maxX - minX)
|
|
3810
|
+
const spanY = Math.max(120, maxY - minY)
|
|
3811
|
+
const nextZoom = Math.min(1.6, Math.max(0.2, Math.min((viewport.clientWidth - 40) / spanX, (viewport.clientHeight - 40) / spanY)))
|
|
3812
|
+
zoomAnchorRef.current = null
|
|
3813
|
+
setZoom(nextZoom)
|
|
3814
|
+
zoomRef.current = nextZoom
|
|
3815
|
+
const centerX = (minX + maxX) / 2
|
|
3816
|
+
const centerY = (minY + maxY) / 2
|
|
3817
|
+
window.requestAnimationFrame(() => {
|
|
3818
|
+
const currentViewport = viewportRef.current
|
|
3819
|
+
if (!currentViewport) return
|
|
3820
|
+
currentViewport.scrollLeft = Math.max(0, centerX * nextZoom - currentViewport.clientWidth / 2)
|
|
3821
|
+
currentViewport.scrollTop = Math.max(0, centerY * nextZoom - currentViewport.clientHeight / 2)
|
|
3822
|
+
})
|
|
3823
|
+
}
|
|
3824
|
+
|
|
3825
|
+
React.useEffect(() => {
|
|
3826
|
+
if (!state.board || centeredRef.current) return
|
|
3827
|
+
centeredRef.current = true
|
|
3828
|
+
const frame = window.requestAnimationFrame(() => autoFit())
|
|
3829
|
+
return () => window.cancelAnimationFrame(frame)
|
|
3830
|
+
}, [state.board])
|
|
3831
|
+
|
|
3832
|
+
/** Read one Markdown note in a large overlay. */
|
|
3833
|
+
const openReader = (id) => {
|
|
3834
|
+
setSelected(id)
|
|
3835
|
+
setReaderId(id)
|
|
3836
|
+
}
|
|
3837
|
+
|
|
2877
3838
|
/** Persist the canvas shortly after the last change (drag/draw). */
|
|
2878
3839
|
const saveCanvasSoon = (next) => {
|
|
2879
3840
|
canvasRef.current = next
|
|
@@ -2939,6 +3900,57 @@ window.__ModuleLoader__.load({
|
|
|
2939
3900
|
const sortedEntries = [...entries].sort((left, right) => (right.updatedAt ?? 0) - (left.updatedAt ?? 0))
|
|
2940
3901
|
const boardVersion = state.board?.version ?? 0
|
|
2941
3902
|
const layoutFor = (entry, index) => canvas.notes[entry.id] ?? autoBoardLayout(index)
|
|
3903
|
+
const noteSize = (layout) => ({
|
|
3904
|
+
width: Math.min(640, Math.max(160, Number(layout?.width) || BOARD_NOTE_W)),
|
|
3905
|
+
height: Math.min(560, Math.max(120, Number(layout?.height) || BOARD_NOTE_H)),
|
|
3906
|
+
})
|
|
3907
|
+
/** Viewport client point -> unscaled stage coordinates. */
|
|
3908
|
+
const stagePoint = (event) => {
|
|
3909
|
+
const stage = stageRef.current
|
|
3910
|
+
if (!stage) return [event.clientX, event.clientY]
|
|
3911
|
+
const rect = stage.getBoundingClientRect()
|
|
3912
|
+
const scale = zoomRef.current || 1
|
|
3913
|
+
return [(event.clientX - rect.left) / scale, (event.clientY - rect.top) / scale]
|
|
3914
|
+
}
|
|
3915
|
+
/** Viewport rect of a sticky, as unscaled stage-relative offsets. */
|
|
3916
|
+
const noteOffsets = (element) => {
|
|
3917
|
+
const stage = stageRef.current
|
|
3918
|
+
if (!stage) return { left: 0, top: 0 }
|
|
3919
|
+
const stageRect = stage.getBoundingClientRect()
|
|
3920
|
+
const rect = element.getBoundingClientRect()
|
|
3921
|
+
const scale = zoomRef.current || 1
|
|
3922
|
+
return { left: (rect.left - stageRect.left) / scale, top: (rect.top - stageRect.top) / scale }
|
|
3923
|
+
}
|
|
3924
|
+
const offsetsFromRect = (rect) => {
|
|
3925
|
+
const stage = stageRef.current
|
|
3926
|
+
if (!stage) return { left: 0, top: 0 }
|
|
3927
|
+
const stageRect = stage.getBoundingClientRect()
|
|
3928
|
+
const scale = zoomRef.current || 1
|
|
3929
|
+
return { left: (rect.left - stageRect.left) / scale, top: (rect.top - stageRect.top) / scale }
|
|
3930
|
+
}
|
|
3931
|
+
const zoomScale = () => zoomRef.current || 1
|
|
3932
|
+
|
|
3933
|
+
/** Which layer (background or one sticky) is under the pointer. */
|
|
3934
|
+
const layerAt = (event) => {
|
|
3935
|
+
let element = event.target
|
|
3936
|
+
try {
|
|
3937
|
+
if (typeof document !== 'undefined' && typeof document.elementFromPoint === 'function') {
|
|
3938
|
+
element = document.elementFromPoint(event.clientX, event.clientY) || element
|
|
3939
|
+
}
|
|
3940
|
+
} catch {
|
|
3941
|
+
// elementFromPoint is a convenience; event.target is the fallback.
|
|
3942
|
+
}
|
|
3943
|
+
const noteElement = element?.closest?.('.tb-sticky')
|
|
3944
|
+
if (noteElement) {
|
|
3945
|
+
return {
|
|
3946
|
+
layer: 'note',
|
|
3947
|
+
noteId: noteElement.getAttribute('data-note-id') || '',
|
|
3948
|
+
rect: noteElement.getBoundingClientRect(),
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3951
|
+
const stage = stageRef.current
|
|
3952
|
+
return stage ? { layer: 'background', noteId: '', rect: stage.getBoundingClientRect() } : null
|
|
3953
|
+
}
|
|
2942
3954
|
const startCreate = () => setDraft({ id: '', title: '', body: '', preview: false, busy: false, error: null })
|
|
2943
3955
|
const startEdit = (entry) => setDraft({ id: entry.id, title: entry.title, body: entry.body, preview: false, busy: false, error: null })
|
|
2944
3956
|
const closeDraft = () => {
|
|
@@ -3003,28 +4015,243 @@ window.__ModuleLoader__.load({
|
|
|
3003
4015
|
/* sticky canvas: drag notes and draw strokes */
|
|
3004
4016
|
/* -------------------------------------------------------------- */
|
|
3005
4017
|
|
|
4018
|
+
/** Ctrl/Shift snapping: shapes stay square/circular, lines/arrows snap to 45°. */
|
|
4019
|
+
const snapShapeEnd = (gesture, world) => {
|
|
4020
|
+
const [sx, sy] = gesture.startWorld
|
|
4021
|
+
const dx = world[0] - sx
|
|
4022
|
+
const dy = world[1] - sy
|
|
4023
|
+
const ctrl = gesture.ctrl
|
|
4024
|
+
if (!ctrl) return world
|
|
4025
|
+
if (gesture.kind === 'line' || gesture.kind === 'arrow') {
|
|
4026
|
+
const length = Math.hypot(dx, dy)
|
|
4027
|
+
if (length < 1) return world
|
|
4028
|
+
const step = Math.PI / 4
|
|
4029
|
+
const angle = Math.round(Math.atan2(dy, dx) / step) * step
|
|
4030
|
+
return [Math.round(sx + Math.cos(angle) * length), Math.round(sy + Math.sin(angle) * length)]
|
|
4031
|
+
}
|
|
4032
|
+
const size = Math.max(Math.abs(dx), Math.abs(dy))
|
|
4033
|
+
return [sx + (dx < 0 ? -size : size), sy + (dy < 0 ? -size : size)]
|
|
4034
|
+
}
|
|
4035
|
+
|
|
4036
|
+
/**
|
|
4037
|
+
* Build the shape preview on BOTH layers: the background copy always, plus
|
|
4038
|
+
* one copy on every sticky the shape touched (so the sticky shows the
|
|
4039
|
+
* clipped part even when the pointer ends outside it).
|
|
4040
|
+
*/
|
|
4041
|
+
const buildShapeCanvas = (gesture) => {
|
|
4042
|
+
const next = cloneBoardCanvas(gesture.baseCanvas)
|
|
4043
|
+
const start = gesture.startWorld
|
|
4044
|
+
const end = snapShapeEnd(gesture, gesture.endWorld)
|
|
4045
|
+
next.background.push({
|
|
4046
|
+
kind: gesture.kind,
|
|
4047
|
+
color: gesture.color,
|
|
4048
|
+
width: gesture.width,
|
|
4049
|
+
points: [start, end],
|
|
4050
|
+
})
|
|
4051
|
+
for (const [noteId, offset] of gesture.targets) {
|
|
4052
|
+
const local = [
|
|
4053
|
+
[start[0] - offset.left, start[1] - offset.top],
|
|
4054
|
+
[end[0] - offset.left, end[1] - offset.top],
|
|
4055
|
+
]
|
|
4056
|
+
const list = [...(next.drawings[noteId] ?? [])]
|
|
4057
|
+
list.push({ kind: gesture.kind, color: gesture.color, width: gesture.width, points: local })
|
|
4058
|
+
next.drawings[noteId] = list
|
|
4059
|
+
}
|
|
4060
|
+
return next
|
|
4061
|
+
}
|
|
4062
|
+
|
|
3006
4063
|
const setGesture = (gesture) => {
|
|
3007
4064
|
gestureRef.current = gesture
|
|
3008
4065
|
const move = (event) => {
|
|
3009
4066
|
const current = gestureRef.current
|
|
3010
4067
|
if (!current) return
|
|
4068
|
+
if (current.type === 'link') {
|
|
4069
|
+
const localPoint = stagePoint(event)
|
|
4070
|
+
const under = layerAt(event)
|
|
4071
|
+
let targetNoteId = ''
|
|
4072
|
+
let targetAnchor = ''
|
|
4073
|
+
if (under?.layer === 'note' && under.noteId && under.noteId !== current.fromNoteId) {
|
|
4074
|
+
const layout = canvasRef.current.notes[under.noteId] ?? autoBoardLayout(0)
|
|
4075
|
+
targetNoteId = under.noteId
|
|
4076
|
+
targetAnchor = nearestBoardAnchor(layout, localPoint)
|
|
4077
|
+
}
|
|
4078
|
+
setLinkPreview((previous) =>
|
|
4079
|
+
previous
|
|
4080
|
+
? { ...previous, pointer: localPoint, targetNoteId, targetAnchor }
|
|
4081
|
+
: previous,
|
|
4082
|
+
)
|
|
4083
|
+
return
|
|
4084
|
+
}
|
|
4085
|
+
if (current.type === 'shape') {
|
|
4086
|
+
const under = layerAt(event)
|
|
4087
|
+
if (under?.layer === 'note' && drawOnStickyRef.current && under.noteId && !current.targets.has(under.noteId)) {
|
|
4088
|
+
current.targets.set(under.noteId, offsetsFromRect(under.rect))
|
|
4089
|
+
}
|
|
4090
|
+
current.endWorld = stagePoint(event)
|
|
4091
|
+
current.ctrl = event.ctrlKey || event.metaKey || event.shiftKey
|
|
4092
|
+
const next = buildShapeCanvas(current)
|
|
4093
|
+
canvasRef.current = next
|
|
4094
|
+
setCanvas(next)
|
|
4095
|
+
return
|
|
4096
|
+
}
|
|
4097
|
+
if (current.type === 'pan') {
|
|
4098
|
+
const viewport = viewportRef.current
|
|
4099
|
+
if (viewport) {
|
|
4100
|
+
viewport.scrollLeft = current.scrollLeft - (event.clientX - current.startX)
|
|
4101
|
+
viewport.scrollTop = current.scrollTop - (event.clientY - current.startY)
|
|
4102
|
+
}
|
|
4103
|
+
return
|
|
4104
|
+
}
|
|
4105
|
+
if (current.type === 'resize') {
|
|
4106
|
+
const scale = zoomScale()
|
|
4107
|
+
const width = Math.min(640, Math.max(160, Math.round(current.startW + (event.clientX - current.startX) / scale)))
|
|
4108
|
+
const height = Math.min(560, Math.max(120, Math.round(current.startH + (event.clientY - current.startY) / scale)))
|
|
4109
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
4110
|
+
const layout = next.notes[current.noteId] ?? autoBoardLayout(0)
|
|
4111
|
+
layout.width = width
|
|
4112
|
+
layout.height = height
|
|
4113
|
+
next.notes[current.noteId] = layout
|
|
4114
|
+
canvasRef.current = next
|
|
4115
|
+
setCanvas(next)
|
|
4116
|
+
return
|
|
4117
|
+
}
|
|
3011
4118
|
if (current.type === 'drag') {
|
|
3012
4119
|
const next = cloneBoardCanvas(canvasRef.current)
|
|
3013
4120
|
const layout = { ...(next.notes[current.noteId] ?? autoBoardLayout(0)) }
|
|
3014
|
-
|
|
3015
|
-
|
|
4121
|
+
const size = noteSize(layout)
|
|
4122
|
+
const scale = zoomScale()
|
|
4123
|
+
layout.x = Math.max(0, Math.min(BOARD_STAGE_W - size.width, current.originX + (event.clientX - current.startX) / scale))
|
|
4124
|
+
layout.y = Math.max(0, Math.min(BOARD_STAGE_H - size.height, current.originY + (event.clientY - current.startY) / scale))
|
|
3016
4125
|
next.notes[current.noteId] = layout
|
|
3017
4126
|
canvasRef.current = next
|
|
3018
4127
|
setCanvas(next)
|
|
3019
4128
|
return
|
|
3020
4129
|
}
|
|
3021
|
-
const
|
|
4130
|
+
const scale = zoomScale()
|
|
4131
|
+
const point = [Math.round((event.clientX - current.rect.left) / scale), Math.round((event.clientY - current.rect.top) / scale)]
|
|
3022
4132
|
if (current.type === 'draw') {
|
|
3023
4133
|
const stroke = current.stroke
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
4134
|
+
if (!current.shape) {
|
|
4135
|
+
const under = layerAt(event)
|
|
4136
|
+
const changed =
|
|
4137
|
+
under &&
|
|
4138
|
+
(under.layer !== current.layer || (under.layer === 'note' && under.noteId !== current.noteId)) &&
|
|
4139
|
+
!(under.layer === 'note' && !drawOnStickyRef.current)
|
|
4140
|
+
if (changed) {
|
|
4141
|
+
const previous = current.lastWorld ?? [event.clientX, event.clientY]
|
|
4142
|
+
const crossScale = zoomScale()
|
|
4143
|
+
const local = [
|
|
4144
|
+
Math.round((previous[0] - under.rect.left) / crossScale),
|
|
4145
|
+
Math.round((previous[1] - under.rect.top) / crossScale),
|
|
4146
|
+
]
|
|
4147
|
+
const localCurrent = [
|
|
4148
|
+
Math.round((event.clientX - under.rect.left) / crossScale),
|
|
4149
|
+
Math.round((event.clientY - under.rect.top) / crossScale),
|
|
4150
|
+
]
|
|
4151
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
4152
|
+
// Extend the old stroke to the crossing point so the sticky edge
|
|
4153
|
+
// is not left with a gap (the sticky's own SVG clips it).
|
|
4154
|
+
const oldLocal = [
|
|
4155
|
+
Math.round((event.clientX - current.rect.left) / crossScale),
|
|
4156
|
+
Math.round((event.clientY - current.rect.top) / crossScale),
|
|
4157
|
+
]
|
|
4158
|
+
const oldLast = stroke.points[stroke.points.length - 1]
|
|
4159
|
+
if (!oldLast || oldLast[0] !== oldLocal[0] || oldLast[1] !== oldLocal[1]) stroke.points.push(oldLocal)
|
|
4160
|
+
if (current.layer === 'background') {
|
|
4161
|
+
next.background = [...next.background]
|
|
4162
|
+
next.background[current.strokeIndex] = { ...stroke, points: stroke.points.map((item) => [...item]) }
|
|
4163
|
+
} else {
|
|
4164
|
+
const list = [...(next.drawings[current.noteId] ?? [])]
|
|
4165
|
+
list[current.strokeIndex] = { ...stroke, points: stroke.points.map((item) => [...item]) }
|
|
4166
|
+
next.drawings[current.noteId] = list
|
|
4167
|
+
}
|
|
4168
|
+
const nextStroke = {
|
|
4169
|
+
kind: 'pen',
|
|
4170
|
+
color: stroke.color,
|
|
4171
|
+
width: stroke.width,
|
|
4172
|
+
points: local[0] === localCurrent[0] && local[1] === localCurrent[1] ? [local] : [local, localCurrent],
|
|
4173
|
+
}
|
|
4174
|
+
let nextIndex
|
|
4175
|
+
if (under.layer === 'background') {
|
|
4176
|
+
nextIndex = next.background.length
|
|
4177
|
+
next.background.push(nextStroke)
|
|
4178
|
+
} else {
|
|
4179
|
+
const list = [...(next.drawings[under.noteId] ?? [])]
|
|
4180
|
+
nextIndex = list.length
|
|
4181
|
+
list.push(nextStroke)
|
|
4182
|
+
next.drawings[under.noteId] = list
|
|
4183
|
+
}
|
|
4184
|
+
current.layer = under.layer
|
|
4185
|
+
current.noteId = under.noteId
|
|
4186
|
+
current.rect = under.rect
|
|
4187
|
+
current.stroke = nextStroke
|
|
4188
|
+
current.strokeIndex = nextIndex
|
|
4189
|
+
current.lastWorld = [event.clientX, event.clientY]
|
|
4190
|
+
canvasRef.current = next
|
|
4191
|
+
setCanvas(next)
|
|
4192
|
+
return
|
|
4193
|
+
}
|
|
4194
|
+
}
|
|
4195
|
+
if (current.shape) {
|
|
4196
|
+
const underShape = layerAt(event)
|
|
4197
|
+
const shapeChanged =
|
|
4198
|
+
underShape &&
|
|
4199
|
+
(underShape.layer !== current.layer || (underShape.layer === 'note' && underShape.noteId !== current.noteId)) &&
|
|
4200
|
+
!(underShape.layer === 'note' && !drawOnStickyRef.current)
|
|
4201
|
+
if (shapeChanged) {
|
|
4202
|
+
const startWorld = current.startWorld ?? [event.clientX, event.clientY]
|
|
4203
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
4204
|
+
if (current.layer === 'background') {
|
|
4205
|
+
next.background = next.background.filter((_, index) => index !== current.strokeIndex)
|
|
4206
|
+
} else {
|
|
4207
|
+
const list = (next.drawings[current.noteId] ?? []).filter((_, index) => index !== current.strokeIndex)
|
|
4208
|
+
if (list.length > 0) next.drawings[current.noteId] = list
|
|
4209
|
+
else delete next.drawings[current.noteId]
|
|
4210
|
+
}
|
|
4211
|
+
current.layer = underShape.layer
|
|
4212
|
+
current.noteId = underShape.noteId
|
|
4213
|
+
current.rect = underShape.rect
|
|
4214
|
+
stroke.points = [
|
|
4215
|
+
[startWorld[0] - underShape.rect.left, startWorld[1] - underShape.rect.top],
|
|
4216
|
+
[event.clientX - underShape.rect.left, event.clientY - underShape.rect.top],
|
|
4217
|
+
]
|
|
4218
|
+
let nextIndex
|
|
4219
|
+
if (underShape.layer === 'background') {
|
|
4220
|
+
nextIndex = next.background.length
|
|
4221
|
+
next.background.push(stroke)
|
|
4222
|
+
} else {
|
|
4223
|
+
const list = [...(next.drawings[underShape.noteId] ?? [])]
|
|
4224
|
+
nextIndex = list.length
|
|
4225
|
+
list.push(stroke)
|
|
4226
|
+
next.drawings[underShape.noteId] = list
|
|
4227
|
+
}
|
|
4228
|
+
current.strokeIndex = nextIndex
|
|
4229
|
+
canvasRef.current = next
|
|
4230
|
+
setCanvas(next)
|
|
4231
|
+
return
|
|
4232
|
+
}
|
|
4233
|
+
const startPoint = stroke.points[0]
|
|
4234
|
+
const ctrl = event.ctrlKey || event.metaKey || event.shiftKey
|
|
4235
|
+
const dx = point[0] - startPoint[0]
|
|
4236
|
+
const dy = point[1] - startPoint[1]
|
|
4237
|
+
if (ctrl && (current.stroke.kind === 'line' || current.stroke.kind === 'arrow')) {
|
|
4238
|
+
// Ctrl/Shift snaps lines and arrows to the nearest cardinal direction.
|
|
4239
|
+
stroke.points[1] = Math.abs(dx) >= Math.abs(dy)
|
|
4240
|
+
? [point[0], startPoint[1]]
|
|
4241
|
+
: [startPoint[0], point[1]]
|
|
4242
|
+
} else if (ctrl) {
|
|
4243
|
+
const size = Math.max(Math.abs(dx), Math.abs(dy))
|
|
4244
|
+
stroke.points[1] = [startPoint[0] + (dx < 0 ? -size : size), startPoint[1] + (dy < 0 ? -size : size)]
|
|
4245
|
+
} else {
|
|
4246
|
+
stroke.points[1] = point
|
|
4247
|
+
}
|
|
4248
|
+
} else {
|
|
4249
|
+
const last = stroke.points[stroke.points.length - 1]
|
|
4250
|
+
if (last && Math.abs(last[0] - point[0]) + Math.abs(last[1] - point[1]) < 2) return
|
|
4251
|
+
if (stroke.points.length >= 800) return
|
|
4252
|
+
stroke.points.push(point)
|
|
4253
|
+
current.lastWorld = [event.clientX, event.clientY]
|
|
4254
|
+
}
|
|
3028
4255
|
const next = cloneBoardCanvas(canvasRef.current)
|
|
3029
4256
|
if (current.layer === 'background') {
|
|
3030
4257
|
next.background = [...next.background]
|
|
@@ -3040,14 +4267,30 @@ window.__ModuleLoader__.load({
|
|
|
3040
4267
|
eraseAt(current, point)
|
|
3041
4268
|
}
|
|
3042
4269
|
}
|
|
3043
|
-
const finish = () => {
|
|
4270
|
+
const finish = (event) => {
|
|
3044
4271
|
window.removeEventListener('pointermove', move)
|
|
3045
4272
|
window.removeEventListener('pointerup', finish)
|
|
3046
4273
|
window.removeEventListener('pointercancel', finish)
|
|
3047
4274
|
const current = gestureRef.current
|
|
3048
4275
|
gestureRef.current = null
|
|
3049
|
-
if (current && current.type
|
|
3050
|
-
|
|
4276
|
+
if (current && current.type === 'link') {
|
|
4277
|
+
setLinkPreview(null)
|
|
4278
|
+
const under = event ? layerAt(event) : null
|
|
4279
|
+
if (!under || under.layer !== 'note' || !under.noteId || under.noteId === current.fromNoteId) return
|
|
4280
|
+
const localPoint = stagePoint(event)
|
|
4281
|
+
const layout = canvasRef.current.notes[under.noteId] ?? autoBoardLayout(0)
|
|
4282
|
+
const anchor = nearestBoardAnchor(layout, localPoint)
|
|
4283
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
4284
|
+
next.edges.push({
|
|
4285
|
+
id: `eg-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
|
|
4286
|
+
from: { noteId: current.fromNoteId, anchor: current.fromAnchor },
|
|
4287
|
+
to: { noteId: under.noteId, anchor },
|
|
4288
|
+
color: inkRef.current,
|
|
4289
|
+
})
|
|
4290
|
+
saveCanvasSoon(next)
|
|
4291
|
+
return
|
|
4292
|
+
}
|
|
4293
|
+
if (current && current.type !== 'pan') saveCanvasSoon(cloneBoardCanvas(canvasRef.current))
|
|
3051
4294
|
}
|
|
3052
4295
|
window.addEventListener('pointermove', move)
|
|
3053
4296
|
window.addEventListener('pointerup', finish)
|
|
@@ -3057,7 +4300,7 @@ window.__ModuleLoader__.load({
|
|
|
3057
4300
|
const eraseAt = (gesture, point) => {
|
|
3058
4301
|
const next = cloneBoardCanvas(canvasRef.current)
|
|
3059
4302
|
const list = gesture.layer === 'background' ? [...next.background] : [...(next.drawings[gesture.noteId] ?? [])]
|
|
3060
|
-
const kept = list.filter((stroke) => !stroke
|
|
4303
|
+
const kept = list.filter((stroke) => !boardStrokeHit(stroke, point))
|
|
3061
4304
|
if (kept.length === list.length) return
|
|
3062
4305
|
if (gesture.layer === 'background') next.background = kept
|
|
3063
4306
|
else if (kept.length > 0) next.drawings[gesture.noteId] = kept
|
|
@@ -3068,14 +4311,50 @@ window.__ModuleLoader__.load({
|
|
|
3068
4311
|
|
|
3069
4312
|
const beginPointer = (event) => {
|
|
3070
4313
|
if (event.button !== 0) return
|
|
3071
|
-
if (event.target?.closest?.('button')) return
|
|
4314
|
+
if (event.target?.closest?.('button') || event.target?.closest?.('.tb-sticky-linkline') || event.target?.closest?.('.tb-sticky-actions')) return
|
|
3072
4315
|
const stage = stageRef.current
|
|
3073
4316
|
if (!stage) return
|
|
3074
4317
|
const noteElement = event.target?.closest?.('.tb-sticky')
|
|
3075
4318
|
const noteId = noteElement?.getAttribute?.('data-note-id') || ''
|
|
4319
|
+
if (toolRef.current === 'link') {
|
|
4320
|
+
event.preventDefault()
|
|
4321
|
+
if (!noteId) return
|
|
4322
|
+
const localPoint = stagePoint(event)
|
|
4323
|
+
const layout = canvasRef.current.notes[noteId] ?? autoBoardLayout(0)
|
|
4324
|
+
const anchorElement = event.target?.closest?.('.tb-anchor')
|
|
4325
|
+
const anchor = anchorElement?.getAttribute?.('data-anchor') || nearestBoardAnchor(layout, localPoint)
|
|
4326
|
+
setLinkPreview({ fromNoteId: noteId, fromAnchor: anchor, pointer: localPoint, targetNoteId: '', targetAnchor: '' })
|
|
4327
|
+
setGesture({ type: 'link', fromNoteId: noteId, fromAnchor: anchor })
|
|
4328
|
+
return
|
|
4329
|
+
}
|
|
4330
|
+
if (noteId && event.target?.closest?.('.tb-sticky-resize')) {
|
|
4331
|
+
event.preventDefault()
|
|
4332
|
+
event.stopPropagation()
|
|
4333
|
+
setSelected(noteId)
|
|
4334
|
+
const layout = canvasRef.current.notes[noteId] ?? autoBoardLayout(0)
|
|
4335
|
+
const size = noteSize(layout)
|
|
4336
|
+
setGesture({
|
|
4337
|
+
type: 'resize',
|
|
4338
|
+
noteId,
|
|
4339
|
+
startX: event.clientX,
|
|
4340
|
+
startY: event.clientY,
|
|
4341
|
+
startW: size.width,
|
|
4342
|
+
startH: size.height,
|
|
4343
|
+
})
|
|
4344
|
+
return
|
|
4345
|
+
}
|
|
3076
4346
|
if (toolRef.current === 'select') {
|
|
3077
4347
|
if (!noteId) {
|
|
4348
|
+
event.preventDefault()
|
|
3078
4349
|
setSelected('')
|
|
4350
|
+
const viewport = viewportRef.current
|
|
4351
|
+
setGesture({
|
|
4352
|
+
type: 'pan',
|
|
4353
|
+
startX: event.clientX,
|
|
4354
|
+
startY: event.clientY,
|
|
4355
|
+
scrollLeft: viewport?.scrollLeft ?? 0,
|
|
4356
|
+
scrollTop: viewport?.scrollTop ?? 0,
|
|
4357
|
+
})
|
|
3079
4358
|
return
|
|
3080
4359
|
}
|
|
3081
4360
|
event.preventDefault()
|
|
@@ -3091,9 +4370,17 @@ window.__ModuleLoader__.load({
|
|
|
3091
4370
|
})
|
|
3092
4371
|
return
|
|
3093
4372
|
}
|
|
4373
|
+
if (noteId && !drawOnStickyRef.current) {
|
|
4374
|
+
// Drawing on sticky notes is switched off: keep the note selected but
|
|
4375
|
+
// do not start a stroke there.
|
|
4376
|
+
event.preventDefault()
|
|
4377
|
+
setSelected(noteId)
|
|
4378
|
+
return
|
|
4379
|
+
}
|
|
3094
4380
|
event.preventDefault()
|
|
3095
4381
|
const rect = (noteElement ?? stage).getBoundingClientRect()
|
|
3096
|
-
const
|
|
4382
|
+
const scale = zoomScale()
|
|
4383
|
+
const point = [Math.round((event.clientX - rect.left) / scale), Math.round((event.clientY - rect.top) / scale)]
|
|
3097
4384
|
const layer = noteId ? 'note' : 'background'
|
|
3098
4385
|
if (toolRef.current === 'eraser') {
|
|
3099
4386
|
const gesture = { type: 'erase', layer, noteId, rect }
|
|
@@ -3101,7 +4388,30 @@ window.__ModuleLoader__.load({
|
|
|
3101
4388
|
setGesture(gesture)
|
|
3102
4389
|
return
|
|
3103
4390
|
}
|
|
3104
|
-
const
|
|
4391
|
+
const shape = ['rect', 'ellipse', 'line', 'arrow', 'triangle'].includes(toolRef.current)
|
|
4392
|
+
if (shape) {
|
|
4393
|
+
const baseCanvas = cloneBoardCanvas(canvasRef.current)
|
|
4394
|
+
const targets = new Map()
|
|
4395
|
+
if (noteId && noteElement) targets.set(noteId, noteOffsets(noteElement))
|
|
4396
|
+
const startWorld = stagePoint(event)
|
|
4397
|
+
const gesture = {
|
|
4398
|
+
type: 'shape',
|
|
4399
|
+
kind: toolRef.current,
|
|
4400
|
+
color: inkRef.current,
|
|
4401
|
+
width: inkWidthRef.current,
|
|
4402
|
+
baseCanvas,
|
|
4403
|
+
startWorld,
|
|
4404
|
+
endWorld: [...startWorld],
|
|
4405
|
+
targets,
|
|
4406
|
+
ctrl: event.ctrlKey || event.metaKey || event.shiftKey,
|
|
4407
|
+
}
|
|
4408
|
+
const preview = buildShapeCanvas(gesture)
|
|
4409
|
+
canvasRef.current = preview
|
|
4410
|
+
setCanvas(preview)
|
|
4411
|
+
setGesture(gesture)
|
|
4412
|
+
return
|
|
4413
|
+
}
|
|
4414
|
+
const stroke = { kind: 'pen', color: inkRef.current, width: inkWidthRef.current, points: [point] }
|
|
3105
4415
|
const next = cloneBoardCanvas(canvasRef.current)
|
|
3106
4416
|
let strokeIndex
|
|
3107
4417
|
if (layer === 'background') {
|
|
@@ -3115,7 +4425,75 @@ window.__ModuleLoader__.load({
|
|
|
3115
4425
|
}
|
|
3116
4426
|
canvasRef.current = next
|
|
3117
4427
|
setCanvas(next)
|
|
3118
|
-
setGesture({
|
|
4428
|
+
setGesture({
|
|
4429
|
+
type: 'draw',
|
|
4430
|
+
shape,
|
|
4431
|
+
layer,
|
|
4432
|
+
noteId,
|
|
4433
|
+
rect,
|
|
4434
|
+
stroke,
|
|
4435
|
+
strokeIndex,
|
|
4436
|
+
startWorld: [event.clientX, event.clientY],
|
|
4437
|
+
lastWorld: [event.clientX, event.clientY],
|
|
4438
|
+
})
|
|
4439
|
+
}
|
|
4440
|
+
|
|
4441
|
+
const toggleDrawOnSticky = () => {
|
|
4442
|
+
setDrawOnSticky((value) => {
|
|
4443
|
+
const next = !value
|
|
4444
|
+
try {
|
|
4445
|
+
window.localStorage.setItem('dsh-timeback:board-draw-on-sticky', next ? '1' : '0')
|
|
4446
|
+
} catch {
|
|
4447
|
+
// Storage can be disabled.
|
|
4448
|
+
}
|
|
4449
|
+
return next
|
|
4450
|
+
})
|
|
4451
|
+
}
|
|
4452
|
+
|
|
4453
|
+
/** Change the drawing colour (recent colours are recorded only once used). */
|
|
4454
|
+
const applyInk = (value, options = {}) => {
|
|
4455
|
+
const normalized = /^#[0-9a-f]{6}$/i.test(String(value || '')) ? String(value).toLowerCase() : '#e6b84c'
|
|
4456
|
+
setInk(normalized)
|
|
4457
|
+
inkRef.current = normalized
|
|
4458
|
+
try {
|
|
4459
|
+
window.localStorage.setItem('dsh-timeback:board-ink-color', normalized)
|
|
4460
|
+
} catch {
|
|
4461
|
+
// Storage can be disabled.
|
|
4462
|
+
}
|
|
4463
|
+
if (options.close === true) setColorOpen(false)
|
|
4464
|
+
}
|
|
4465
|
+
|
|
4466
|
+
/** Remember a colour in the recent list after a real stroke used it. */
|
|
4467
|
+
const rememberInk = (value) => {
|
|
4468
|
+
const normalized = /^#[0-9a-f]{6}$/i.test(String(value || '')) ? String(value).toLowerCase() : ''
|
|
4469
|
+
if (normalized === '') return
|
|
4470
|
+
setRecentColors((previous) => {
|
|
4471
|
+
const next = [normalized, ...previous.filter((item) => item !== normalized)].slice(0, 8)
|
|
4472
|
+
try {
|
|
4473
|
+
window.localStorage.setItem('dsh-timeback:board-recent-colors', JSON.stringify(next))
|
|
4474
|
+
} catch {
|
|
4475
|
+
// Storage can be disabled.
|
|
4476
|
+
}
|
|
4477
|
+
return next
|
|
4478
|
+
})
|
|
4479
|
+
}
|
|
4480
|
+
|
|
4481
|
+
const pickScreenColor = async () => {
|
|
4482
|
+
setColorHint('')
|
|
4483
|
+
if (typeof window === 'undefined' || typeof window.EyeDropper !== 'function') {
|
|
4484
|
+
setColorHint(t('board.eyedropperUnsupported'))
|
|
4485
|
+
return
|
|
4486
|
+
}
|
|
4487
|
+
if (window.isSecureContext === false) {
|
|
4488
|
+
setColorHint(t('board.eyedropperInsecure'))
|
|
4489
|
+
return
|
|
4490
|
+
}
|
|
4491
|
+
try {
|
|
4492
|
+
const result = await new window.EyeDropper().open()
|
|
4493
|
+
if (result?.sRGBHex) applyInk(result.sRGBHex, { close: true })
|
|
4494
|
+
} catch (error) {
|
|
4495
|
+
setColorHint(format(t('board.eyedropperFailed'), { error: error?.message || 'cancelled' }))
|
|
4496
|
+
}
|
|
3119
4497
|
}
|
|
3120
4498
|
|
|
3121
4499
|
const clearBackground = () => {
|
|
@@ -3135,10 +4513,68 @@ window.__ModuleLoader__.load({
|
|
|
3135
4513
|
/* -------------------------------------------------------------- */
|
|
3136
4514
|
|
|
3137
4515
|
const drawingLayer = (strokes, prefix) =>
|
|
3138
|
-
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%' }, ...
|
|
4516
|
+
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))
|
|
4517
|
+
|
|
4518
|
+
const layoutById = new Map()
|
|
4519
|
+
entries.forEach((entry, index) => layoutById.set(entry.id, layoutFor(entry, index)))
|
|
4520
|
+
|
|
4521
|
+
const edgeLayer = () => {
|
|
4522
|
+
const nodes = []
|
|
4523
|
+
for (const edge of canvas.edges ?? []) {
|
|
4524
|
+
const fromLayout = layoutById.get(edge.from?.noteId)
|
|
4525
|
+
const toLayout = layoutById.get(edge.to?.noteId)
|
|
4526
|
+
if (!fromLayout || !toLayout) continue
|
|
4527
|
+
const from = boardAnchorPoint(fromLayout, edge.from.anchor)
|
|
4528
|
+
const to = boardAnchorPoint(toLayout, edge.to.anchor)
|
|
4529
|
+
nodes.push(
|
|
4530
|
+
h(
|
|
4531
|
+
'g',
|
|
4532
|
+
{
|
|
4533
|
+
key: edge.id,
|
|
4534
|
+
className: 'tb-board-edge',
|
|
4535
|
+
onPointerDown: (event) => {
|
|
4536
|
+
if (toolRef.current !== 'link') return
|
|
4537
|
+
event.stopPropagation()
|
|
4538
|
+
event.preventDefault()
|
|
4539
|
+
let confirmed = true
|
|
4540
|
+
try {
|
|
4541
|
+
confirmed = typeof window.confirm === 'function' ? window.confirm(t('board.edgeDeleteConfirm')) : true
|
|
4542
|
+
} catch {
|
|
4543
|
+
confirmed = true
|
|
4544
|
+
}
|
|
4545
|
+
if (!confirmed) return
|
|
4546
|
+
const next = cloneBoardCanvas(canvasRef.current)
|
|
4547
|
+
next.edges = next.edges.filter((candidate) => candidate.id !== edge.id)
|
|
4548
|
+
saveCanvasSoon(next)
|
|
4549
|
+
},
|
|
4550
|
+
},
|
|
4551
|
+
h('path', { className: 'tb-board-edge-path', d: boardEdgePath(from, to), stroke: edge.color || '#7aa2ff' }),
|
|
4552
|
+
h('circle', { className: 'tb-board-edge-dot', cx: from[0], cy: from[1], r: 3 }),
|
|
4553
|
+
h('circle', { className: 'tb-board-edge-dot', cx: to[0], cy: to[1], r: 3 }),
|
|
4554
|
+
),
|
|
4555
|
+
)
|
|
4556
|
+
}
|
|
4557
|
+
if (linkPreview) {
|
|
4558
|
+
const fromLayout = layoutById.get(linkPreview.fromNoteId)
|
|
4559
|
+
if (fromLayout) {
|
|
4560
|
+
const from = boardAnchorPoint(fromLayout, linkPreview.fromAnchor)
|
|
4561
|
+
let to = linkPreview.pointer
|
|
4562
|
+
if (linkPreview.targetNoteId) {
|
|
4563
|
+
const targetLayout = layoutById.get(linkPreview.targetNoteId)
|
|
4564
|
+
if (targetLayout) to = boardAnchorPoint(targetLayout, linkPreview.targetAnchor)
|
|
4565
|
+
}
|
|
4566
|
+
nodes.push(
|
|
4567
|
+
h('g', { key: 'link-preview', className: 'tb-board-edge-preview-group' },
|
|
4568
|
+
h('path', { className: 'tb-board-edge-preview', d: boardEdgePath(from, to), stroke: ink })),
|
|
4569
|
+
)
|
|
4570
|
+
}
|
|
4571
|
+
}
|
|
4572
|
+
return h('svg', { className: 'tb-board-edges', width: BOARD_STAGE_W, height: BOARD_STAGE_H }, ...nodes)
|
|
4573
|
+
}
|
|
3139
4574
|
|
|
3140
4575
|
const stickyFor = (entry, index) => {
|
|
3141
4576
|
const layout = layoutFor(entry, index)
|
|
4577
|
+
const size = noteSize(layout)
|
|
3142
4578
|
const agent = entry.source === 'agent'
|
|
3143
4579
|
return h(
|
|
3144
4580
|
'article',
|
|
@@ -3149,6 +4585,8 @@ window.__ModuleLoader__.load({
|
|
|
3149
4585
|
style: {
|
|
3150
4586
|
left: Number(layout.x) || 0,
|
|
3151
4587
|
top: Number(layout.y) || 0,
|
|
4588
|
+
width: size.width,
|
|
4589
|
+
height: size.height,
|
|
3152
4590
|
zIndex: 100 + (Number(layout.z) || 0),
|
|
3153
4591
|
background: layout.color || BOARD_COLORS[index % BOARD_COLORS.length],
|
|
3154
4592
|
},
|
|
@@ -3181,7 +4619,7 @@ window.__ModuleLoader__.load({
|
|
|
3181
4619
|
tabIndex: 0,
|
|
3182
4620
|
onClick: (event) => {
|
|
3183
4621
|
event.stopPropagation()
|
|
3184
|
-
|
|
4622
|
+
openReader(entry.id)
|
|
3185
4623
|
},
|
|
3186
4624
|
},
|
|
3187
4625
|
`🔗 ${t('board.openMd')}`,
|
|
@@ -3190,6 +4628,23 @@ window.__ModuleLoader__.load({
|
|
|
3190
4628
|
)
|
|
3191
4629
|
: h('div', { className: 'tb-sticky-body md' }, stripMarkdown(entry.body) || t('board.empty')),
|
|
3192
4630
|
drawingLayer(canvas.drawings[entry.id] ?? [], `d-${entry.id}`),
|
|
4631
|
+
...BOARD_ANCHORS.map((anchor) =>
|
|
4632
|
+
h('div', {
|
|
4633
|
+
key: anchor,
|
|
4634
|
+
className: `tb-anchor tb-anchor-${anchor}`,
|
|
4635
|
+
'data-note-id': entry.id,
|
|
4636
|
+
'data-anchor': anchor,
|
|
4637
|
+
style:
|
|
4638
|
+
anchor === 'top'
|
|
4639
|
+
? { left: '50%', top: 0 }
|
|
4640
|
+
: anchor === 'right'
|
|
4641
|
+
? { left: '100%', top: '50%' }
|
|
4642
|
+
: anchor === 'bottom'
|
|
4643
|
+
? { left: '50%', top: '100%' }
|
|
4644
|
+
: { left: 0, top: '50%' },
|
|
4645
|
+
}),
|
|
4646
|
+
),
|
|
4647
|
+
h('div', { className: 'tb-sticky-resize', title: t('board.resizeNote'), role: 'separator' }),
|
|
3193
4648
|
)
|
|
3194
4649
|
}
|
|
3195
4650
|
|
|
@@ -3199,19 +4654,190 @@ window.__ModuleLoader__.load({
|
|
|
3199
4654
|
h('button', { type: 'button', className: `tb-tool${tool === 'select' ? ' on' : ''}`, onClick: () => setTool('select') }, t('board.toolSelect')),
|
|
3200
4655
|
h('button', { type: 'button', className: `tb-tool${tool === 'pen' ? ' on' : ''}`, onClick: () => setTool('pen') }, `✏️ ${t('board.toolPen')}`),
|
|
3201
4656
|
h('button', { type: 'button', className: `tb-tool${tool === 'eraser' ? ' on' : ''}`, onClick: () => setTool('eraser') }, `🧽 ${t('board.toolEraser')}`),
|
|
3202
|
-
h('
|
|
3203
|
-
|
|
4657
|
+
h('button', { type: 'button', className: `tb-tool${tool === 'link' ? ' on' : ''}`, title: t('board.anchorsHint'), onClick: () => setTool('link') }, `🔗 ${t('board.toolLink')}`),
|
|
4658
|
+
h(
|
|
4659
|
+
'div',
|
|
4660
|
+
{ className: 'tb-shape-wrap' },
|
|
4661
|
+
h(
|
|
4662
|
+
'button',
|
|
4663
|
+
{
|
|
4664
|
+
type: 'button',
|
|
4665
|
+
className: `tb-tool${BOARD_SHAPES.some(([value]) => value === tool) ? ' on' : ''}`,
|
|
4666
|
+
title: t('board.commonShapes'),
|
|
4667
|
+
onClick: () => setShapeMenu((value) => !value),
|
|
4668
|
+
},
|
|
4669
|
+
`${t('board.commonShapes')} ${BOARD_SHAPES.find(([value]) => value === tool)?.[1] ?? '▭'}`,
|
|
4670
|
+
),
|
|
4671
|
+
shapeMenu
|
|
4672
|
+
? h(
|
|
4673
|
+
'div',
|
|
4674
|
+
{ className: 'tb-shape-menu', role: 'menu' },
|
|
4675
|
+
...BOARD_SHAPES.map(([value, glyph, key]) =>
|
|
4676
|
+
h(
|
|
4677
|
+
'button',
|
|
4678
|
+
{
|
|
4679
|
+
key: value,
|
|
4680
|
+
type: 'button',
|
|
4681
|
+
role: 'menuitem',
|
|
4682
|
+
onClick: () => {
|
|
4683
|
+
setTool(value)
|
|
4684
|
+
setShapeMenu(false)
|
|
4685
|
+
},
|
|
4686
|
+
},
|
|
4687
|
+
`${glyph} ${t(key)}`,
|
|
4688
|
+
),
|
|
4689
|
+
),
|
|
4690
|
+
)
|
|
4691
|
+
: null,
|
|
4692
|
+
),
|
|
4693
|
+
h('span', { className: 'tb-board-meta' }, t('board.brushSize')),
|
|
4694
|
+
h('input', {
|
|
4695
|
+
type: 'range',
|
|
4696
|
+
className: 'tb-size-range',
|
|
4697
|
+
min: 1,
|
|
4698
|
+
max: 8,
|
|
4699
|
+
step: 1,
|
|
4700
|
+
value: inkWidth,
|
|
4701
|
+
'aria-label': t('board.brushSize'),
|
|
4702
|
+
onChange: (event) => {
|
|
4703
|
+
const next = Math.min(8, Math.max(1, Number(event.target.value) || 2))
|
|
4704
|
+
setInkWidth(next)
|
|
4705
|
+
try {
|
|
4706
|
+
window.localStorage.setItem('dsh-timeback:board-ink-width', String(next))
|
|
4707
|
+
} catch {
|
|
4708
|
+
// Storage can be disabled.
|
|
4709
|
+
}
|
|
4710
|
+
},
|
|
4711
|
+
}),
|
|
4712
|
+
h('span', { className: 'tb-board-meta' }, String(inkWidth)),
|
|
4713
|
+
h(
|
|
4714
|
+
'div',
|
|
4715
|
+
{ className: 'tb-color-wrap' },
|
|
3204
4716
|
h('button', {
|
|
3205
|
-
key: value,
|
|
3206
4717
|
type: 'button',
|
|
3207
|
-
className:
|
|
3208
|
-
style: { background:
|
|
3209
|
-
title:
|
|
3210
|
-
|
|
4718
|
+
className: 'tb-color-btn',
|
|
4719
|
+
style: { background: ink },
|
|
4720
|
+
title: `${t('board.color')} ${ink}`,
|
|
4721
|
+
'aria-label': t('board.colorTitle'),
|
|
4722
|
+
onClick: () => setColorOpen((value) => !value),
|
|
3211
4723
|
}),
|
|
4724
|
+
colorOpen
|
|
4725
|
+
? (() => {
|
|
4726
|
+
const rgb = hexToRgb(ink)
|
|
4727
|
+
return h(
|
|
4728
|
+
'div',
|
|
4729
|
+
{ className: 'tb-color-panel', role: 'dialog' },
|
|
4730
|
+
h('div', { className: 'tb-board-meta' }, t('board.colorTitle')),
|
|
4731
|
+
h(
|
|
4732
|
+
'div',
|
|
4733
|
+
{ className: 'tb-color-row' },
|
|
4734
|
+
h('span', { className: 'tb-color-label' }, t('board.customColor')),
|
|
4735
|
+
h('input', {
|
|
4736
|
+
type: 'color',
|
|
4737
|
+
value: ink,
|
|
4738
|
+
'aria-label': t('board.customColor'),
|
|
4739
|
+
onChange: (event) => applyInk(event.target.value),
|
|
4740
|
+
}),
|
|
4741
|
+
h(
|
|
4742
|
+
'button',
|
|
4743
|
+
{
|
|
4744
|
+
type: 'button',
|
|
4745
|
+
className: 'tb-tool',
|
|
4746
|
+
title: t('board.eyedropperHint'),
|
|
4747
|
+
onClick: pickScreenColor,
|
|
4748
|
+
},
|
|
4749
|
+
`🎯 ${t('board.eyedropper')}`,
|
|
4750
|
+
),
|
|
4751
|
+
),
|
|
4752
|
+
colorHint ? h('div', { className: 'tb-feedback warn', style: { padding: '5px 7px', fontSize: '10.5px' } }, colorHint) : null,
|
|
4753
|
+
h(
|
|
4754
|
+
'div',
|
|
4755
|
+
{ className: 'tb-hex-row' },
|
|
4756
|
+
h('span', { className: 'tb-color-label' }, 'HEX'),
|
|
4757
|
+
h('input', {
|
|
4758
|
+
type: 'text',
|
|
4759
|
+
value: ink,
|
|
4760
|
+
spellCheck: false,
|
|
4761
|
+
onChange: (event) => {
|
|
4762
|
+
const value = event.target.value.trim()
|
|
4763
|
+
if (/^#[0-9a-f]{6}$/i.test(value)) applyInk(value)
|
|
4764
|
+
},
|
|
4765
|
+
}),
|
|
4766
|
+
),
|
|
4767
|
+
h('div', { className: 'tb-color-label' }, t('board.rgb')),
|
|
4768
|
+
...['R', 'G', 'B'].map((channel, index) =>
|
|
4769
|
+
h(
|
|
4770
|
+
'div',
|
|
4771
|
+
{ key: channel, className: 'tb-rgb-row' },
|
|
4772
|
+
h('span', { className: 'tb-color-label' }, channel),
|
|
4773
|
+
h('input', {
|
|
4774
|
+
type: 'range',
|
|
4775
|
+
min: 0,
|
|
4776
|
+
max: 255,
|
|
4777
|
+
step: 1,
|
|
4778
|
+
value: rgb[index],
|
|
4779
|
+
'aria-label': `${t('board.rgb')} ${channel}`,
|
|
4780
|
+
onChange: (event) => {
|
|
4781
|
+
const next = [...rgb]
|
|
4782
|
+
next[index] = Number(event.target.value)
|
|
4783
|
+
applyInk(rgbToHex(next))
|
|
4784
|
+
},
|
|
4785
|
+
}),
|
|
4786
|
+
h('span', null, String(rgb[index])),
|
|
4787
|
+
),
|
|
4788
|
+
),
|
|
4789
|
+
h('div', { className: 'tb-color-label' }, t('board.commonColors')),
|
|
4790
|
+
h(
|
|
4791
|
+
'div',
|
|
4792
|
+
{ className: 'tb-color-grid' },
|
|
4793
|
+
...BOARD_INKS.map((value) =>
|
|
4794
|
+
h('button', {
|
|
4795
|
+
key: value,
|
|
4796
|
+
type: 'button',
|
|
4797
|
+
title: value,
|
|
4798
|
+
style: { background: value },
|
|
4799
|
+
onClick: () => applyInk(value, { close: true }),
|
|
4800
|
+
}),
|
|
4801
|
+
),
|
|
4802
|
+
),
|
|
4803
|
+
recentColors.length > 0
|
|
4804
|
+
? h(
|
|
4805
|
+
'div',
|
|
4806
|
+
null,
|
|
4807
|
+
h('div', { className: 'tb-color-label' }, t('board.recentColors')),
|
|
4808
|
+
h(
|
|
4809
|
+
'div',
|
|
4810
|
+
{ className: 'tb-color-grid' },
|
|
4811
|
+
...recentColors.map((value) =>
|
|
4812
|
+
h('button', {
|
|
4813
|
+
key: `recent-${value}`,
|
|
4814
|
+
type: 'button',
|
|
4815
|
+
title: value,
|
|
4816
|
+
style: { background: value },
|
|
4817
|
+
onClick: () => applyInk(value, { close: true }),
|
|
4818
|
+
}),
|
|
4819
|
+
),
|
|
4820
|
+
),
|
|
4821
|
+
)
|
|
4822
|
+
: null,
|
|
4823
|
+
)
|
|
4824
|
+
})()
|
|
4825
|
+
: null,
|
|
4826
|
+
),
|
|
4827
|
+
h(
|
|
4828
|
+
'button',
|
|
4829
|
+
{
|
|
4830
|
+
type: 'button',
|
|
4831
|
+
className: `tb-tool${drawOnSticky ? ' on' : ''}`,
|
|
4832
|
+
title: t('board.drawOnStickyHint'),
|
|
4833
|
+
onClick: toggleDrawOnSticky,
|
|
4834
|
+
},
|
|
4835
|
+
drawOnSticky ? t('board.drawOnStickyOn') : t('board.drawOnStickyOff'),
|
|
3212
4836
|
),
|
|
3213
4837
|
h('span', { style: { flex: 1 } }),
|
|
4838
|
+
h('button', { type: 'button', className: 'tb-btn', onClick: autoFit }, t('board.center')),
|
|
3214
4839
|
h('button', { type: 'button', className: 'tb-btn', disabled: canvas.background.length === 0, onClick: clearBackground }, t('board.clearBg')),
|
|
4840
|
+
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')),
|
|
3215
4841
|
h('button', { type: 'button', className: 'tb-btn', disabled: !selected || !(canvas.drawings[selected]?.length > 0), onClick: clearSelectedDrawing }, t('board.clearNote')),
|
|
3216
4842
|
)
|
|
3217
4843
|
|
|
@@ -3226,20 +4852,32 @@ window.__ModuleLoader__.load({
|
|
|
3226
4852
|
h('span', { style: { flex: 1 } }),
|
|
3227
4853
|
h('span', { className: 'tb-muted tb-small' }, format(t('board.count'), { count: entries.length, version: boardVersion })),
|
|
3228
4854
|
h('span', { className: 'tb-muted tb-small' }, format(t('board.canvasVersion'), { version: boardVersion })),
|
|
4855
|
+
h('button', { type: 'button', className: 'tb-tool', title: t('board.zoomOut'), onClick: () => zoomBy(1 / 1.2) }, '−'),
|
|
4856
|
+
h('button', { type: 'button', className: 'tb-tool', title: t('board.zoomReset'), onClick: () => zoomBy(1 / zoomRef.current) }, `${Math.round(zoom * 100)}%`),
|
|
4857
|
+
h('button', { type: 'button', className: 'tb-tool', title: t('board.zoomIn'), onClick: () => zoomBy(1.2) }, '+'),
|
|
3229
4858
|
h('button', { type: 'button', className: 'tb-btn', disabled: state.loading, onClick: refresh }, t('board.refresh')),
|
|
3230
4859
|
h('button', { type: 'button', className: 'tb-btn primary', onClick: startCreate }, `+ ${t('board.newSticky')}`),
|
|
3231
4860
|
),
|
|
3232
4861
|
toolbar,
|
|
3233
|
-
h('div', { className: 'tb-board-hint-wrap' }, h('span', { className: 'tb-ws-hint' }, t('board.stickyHint'))),
|
|
4862
|
+
h('div', { className: 'tb-board-hint-wrap' }, h('span', { className: 'tb-ws-hint' }, `${t('board.stickyHint')} · ${t('board.panHint')}`)),
|
|
3234
4863
|
state.error ? h('div', { className: 'tb-feedback err' }, format(t('board.error'), { error: state.error })) : null,
|
|
3235
4864
|
h(
|
|
3236
4865
|
'div',
|
|
3237
|
-
{ className: `tb-board-canvas${tool === 'select' ? ' select' : ''}`, onPointerDown: beginPointer },
|
|
4866
|
+
{ className: `tb-board-canvas${tool === 'select' ? ' select' : tool === 'link' ? ' link' : ' draw'}`, ref: viewportRef, onPointerDown: beginPointer },
|
|
3238
4867
|
h(
|
|
3239
4868
|
'div',
|
|
3240
|
-
{ className: 'tb-board-
|
|
3241
|
-
|
|
3242
|
-
|
|
4869
|
+
{ className: 'tb-board-world', style: { width: BOARD_STAGE_W * zoom, height: BOARD_STAGE_H * zoom } },
|
|
4870
|
+
h(
|
|
4871
|
+
'div',
|
|
4872
|
+
{
|
|
4873
|
+
className: `tb-board-stage${tool === 'link' || linkPreview ? ' show-anchors' : ''}`,
|
|
4874
|
+
ref: stageRef,
|
|
4875
|
+
style: { width: BOARD_STAGE_W, height: BOARD_STAGE_H, transform: `scale(${zoom})` },
|
|
4876
|
+
},
|
|
4877
|
+
drawingLayer(canvas.background, 'bg'),
|
|
4878
|
+
edgeLayer(),
|
|
4879
|
+
...entries.map((entry, index) => stickyFor(entry, index)),
|
|
4880
|
+
),
|
|
3243
4881
|
),
|
|
3244
4882
|
state.loading && !state.board ? h('p', { className: 'tb-board-md-empty' }, t('panel.loading')) : null,
|
|
3245
4883
|
!state.loading && entries.length === 0 ? h('p', { className: 'tb-board-md-empty' }, t('board.empty')) : null,
|
|
@@ -3263,7 +4901,7 @@ window.__ModuleLoader__.load({
|
|
|
3263
4901
|
h(
|
|
3264
4902
|
'div',
|
|
3265
4903
|
{ className: 'tb-board-actions' },
|
|
3266
|
-
h('button', { type: 'button', className: 'tb-btn', onClick: () =>
|
|
4904
|
+
h('button', { type: 'button', className: 'tb-btn', onClick: () => openReader(entry.id) }, t('board.reader')),
|
|
3267
4905
|
h('button', { type: 'button', className: 'tb-btn', onClick: () => startEdit(entry) }, t('board.edit')),
|
|
3268
4906
|
h('button', { type: 'button', className: 'tb-btn danger', disabled: busy !== '', onClick: () => removeEntry(entry.id) }, busy === entry.id ? '…' : t('board.delete')),
|
|
3269
4907
|
),
|
|
@@ -3272,6 +4910,39 @@ window.__ModuleLoader__.load({
|
|
|
3272
4910
|
),
|
|
3273
4911
|
),
|
|
3274
4912
|
),
|
|
4913
|
+
(() => {
|
|
4914
|
+
const readerEntry = entries.find((entry) => entry.id === readerId)
|
|
4915
|
+
if (!readerEntry) return null
|
|
4916
|
+
return h(
|
|
4917
|
+
'div',
|
|
4918
|
+
{ className: 'tb-overlay center', onClick: () => setReaderId('') },
|
|
4919
|
+
h(
|
|
4920
|
+
'div',
|
|
4921
|
+
{
|
|
4922
|
+
className: 'tb-board-dialog',
|
|
4923
|
+
role: 'dialog',
|
|
4924
|
+
'aria-modal': true,
|
|
4925
|
+
style: { width: 'min(780px, 94vw)', height: '72vh' },
|
|
4926
|
+
onClick: (event) => event.stopPropagation(),
|
|
4927
|
+
},
|
|
4928
|
+
h(
|
|
4929
|
+
'div',
|
|
4930
|
+
{ className: 'tb-detail-head' },
|
|
4931
|
+
h('span', { className: 'tb-detail-title' }, `📄 ${readerEntry.title || '未命名便签'}`),
|
|
4932
|
+
h('span', { className: 'tb-chip' }, readerEntry.source === 'agent' ? t('board.sourceAgent') : t('board.sourceUser')),
|
|
4933
|
+
h('span', { style: { flex: 1 } }),
|
|
4934
|
+
h('button', { type: 'button', className: 'tb-btn', onClick: () => { setReaderId(''); startEdit(readerEntry) } }, t('board.edit')),
|
|
4935
|
+
h(
|
|
4936
|
+
'button',
|
|
4937
|
+
{ type: 'button', className: 'tb-btn danger', disabled: busy !== '', onClick: () => { setReaderId(''); removeEntry(readerEntry.id) } },
|
|
4938
|
+
t('board.delete'),
|
|
4939
|
+
),
|
|
4940
|
+
h('button', { type: 'button', className: 'tb-btn primary', onClick: () => setReaderId('') }, t('board.close')),
|
|
4941
|
+
),
|
|
4942
|
+
h('div', { className: 'tb-md', style: { flex: 1, overflow: 'auto' } }, ...renderMarkdown(readerEntry.body || '', `reader-${readerEntry.id}`)),
|
|
4943
|
+
),
|
|
4944
|
+
)
|
|
4945
|
+
})(),
|
|
3275
4946
|
draft
|
|
3276
4947
|
? h(
|
|
3277
4948
|
'div',
|
|
@@ -3290,15 +4961,6 @@ window.__ModuleLoader__.load({
|
|
|
3290
4961
|
{ className: 'tb-detail-head' },
|
|
3291
4962
|
h('span', { className: 'tb-detail-title' }, draft.id ? t('board.edit') : t('board.newSticky')),
|
|
3292
4963
|
h('span', { style: { flex: 1 } }),
|
|
3293
|
-
h(
|
|
3294
|
-
'button',
|
|
3295
|
-
{
|
|
3296
|
-
type: 'button',
|
|
3297
|
-
className: `tb-viewtab${draft.preview ? ' on' : ''}`,
|
|
3298
|
-
onClick: () => setDraft({ ...draft, preview: !draft.preview }),
|
|
3299
|
-
},
|
|
3300
|
-
draft.preview ? t('board.editMode') : t('board.preview'),
|
|
3301
|
-
),
|
|
3302
4964
|
h('button', { type: 'button', className: 'tb-btn', title: t('board.resizeHint'), onClick: resetDialogSize }, t('board.resetSize')),
|
|
3303
4965
|
),
|
|
3304
4966
|
h('input', {
|
|
@@ -3307,14 +4969,13 @@ window.__ModuleLoader__.load({
|
|
|
3307
4969
|
disabled: draft.busy,
|
|
3308
4970
|
onChange: (event) => setDraft({ ...draft, title: event.target.value }),
|
|
3309
4971
|
}),
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
:
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
}),
|
|
4972
|
+
h(MarkdownEditor, {
|
|
4973
|
+
value: draft.body,
|
|
4974
|
+
onChange: (next) => setDraft({ ...draft, body: next }),
|
|
4975
|
+
t,
|
|
4976
|
+
disabled: draft.busy,
|
|
4977
|
+
placeholder: t('board.bodyPlaceholder'),
|
|
4978
|
+
}),
|
|
3318
4979
|
h('div', { className: 'tb-ws-hint' }, t('board.resizeHint')),
|
|
3319
4980
|
draft.error ? h('div', { className: 'tb-feedback err' }, format(t('board.error'), { error: draft.error })) : null,
|
|
3320
4981
|
h(
|
|
@@ -3336,6 +4997,10 @@ window.__ModuleLoader__.load({
|
|
|
3336
4997
|
window.__TIMEBACK_TEST__.edgePanVector = edgePanVector
|
|
3337
4998
|
window.__TIMEBACK_TEST__.renderMarkdown = renderMarkdown
|
|
3338
4999
|
window.__TIMEBACK_TEST__.stripMarkdown = stripMarkdown
|
|
5000
|
+
window.__TIMEBACK_TEST__.boardEdgePath = boardEdgePath
|
|
5001
|
+
window.__TIMEBACK_TEST__.MarkdownEditor = MarkdownEditor
|
|
5002
|
+
window.__TIMEBACK_TEST__.markdownToEditorHtml = markdownToEditorHtml
|
|
5003
|
+
window.__TIMEBACK_TEST__.domToMarkdown = domToMarkdown
|
|
3339
5004
|
}
|
|
3340
5005
|
|
|
3341
5006
|
return {
|