dsh-timeback 0.7.1 → 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 CHANGED
@@ -103,7 +103,7 @@ desktop app):
103
103
  ```bash
104
104
  # From npm (published: https://www.npmjs.com/package/dsh-timeback)
105
105
  dsh plugin --profile web add dsh-timeback
106
- dsh plugin --profile web add dsh-timeback@0.7.1 # pin a release
106
+ dsh plugin --profile web add dsh-timeback@0.7.2 # pin a release
107
107
 
108
108
  # Straight from GitHub (no npm release needed)
109
109
  dsh plugin --profile web add github:<owner>/dsh-timeback
@@ -192,8 +192,10 @@ The board is a **sticky-note canvas** with a graph-paper background:
192
192
  crossed (each layer clips its own copy).
193
193
  With the Move tool, dragging empty grid pans the canvas; on open the view
194
194
  **auto-fits** every note and stroke (zoom + scroll) and the **自动调整** button
195
- recomputes that fit whenever the board grows); stickies drag under the cursor
196
- and have a bottom-right **resize handle** (sizes are saved with the board). The canvas is a
195
+ recomputes that fit whenever the board grows. Manual zoom is available with the
196
+ toolbar **− / % / +** buttons (the percentage resets to 100%) or **Ctrl/⌘ +
197
+ mouse wheel / trackpad pinch**, anchored at the pointer. Stickies drag under the
198
+ cursor and have a bottom-right **resize handle** (sizes are saved with the board). The canvas is a
197
199
  4000×3000 grid that scrolls with the content. **打开 md**
198
200
  opens a large Markdown reader overlay.
199
201
  - **New sticky** — the “新建便签” button opens the centred Markdown editor
@@ -208,8 +210,18 @@ The board is a **sticky-note canvas** with a graph-paper background:
208
210
  as board edges, roll back with rewinds, and can be deleted by clicking them (or
209
211
  with **清路径**).
210
212
  - **Markdown below the canvas** — the bottom pane always shows the current board
211
- contents fully rendered (`#`/lists/code/bold/links…), with edit/delete/open
212
- actions, so the Markdown documents stay readable even when the canvas is full.
213
+ contents fully rendered with **larger typography** (H1 24px, H2 21px, body
214
+ 14.5px, code 13px…), with edit/delete/open actions, so the Markdown documents
215
+ stay readable even when the canvas is full.
216
+ - **WYSIWYG Markdown editor (SiYuan-inspired)** — creating/editing a sticky opens
217
+ a rich editing area where you **type directly into the formatted document**.
218
+ Select 你好, press **B**, and it becomes **bold** immediately; the document is
219
+ serialized back to Markdown as you type. Toolbar: H1–H3, bold/italic/strike,
220
+ inline code, code block, bullet/numbered/task lists, quote, link, divider and
221
+ **text colour** (common palette + custom picker, stored as safe
222
+ `<span style="color:#rrggbb">…</span>` Markdown). Tabs switch between
223
+ **富文本 / 源码 / 预览**; the preview is one continuous document with no block
224
+ separators or line labels. Card notes (📝) use the same editor.
213
225
 
214
226
  Every board change (notes, layout, drawings) is a numbered board revision and is
215
227
  captured by checkpoints: rewinding restores the sticky layout and drawings at that
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.1+sticky'
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,6 +98,26 @@ 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': '便签可拖动;画笔可在方格纸背景或便签上绘制,橡皮擦除笔画。',
103
123
  'board.resizeNote': '拖动缩放便签',
@@ -106,6 +126,9 @@ window.__ModuleLoader__.load({
106
126
  'board.drawOnStickyOff': '便签可画:关',
107
127
  'board.drawOnStickyHint': '开启后画笔/图形可直接画在便签上;关闭则只画在方格纸背景。',
108
128
  'board.center': '自动调整',
129
+ 'board.zoomIn': '放大画布',
130
+ 'board.zoomOut': '缩小画布',
131
+ 'board.zoomReset': '重置为 100%',
109
132
  'board.reader': '阅读 md',
110
133
  'board.close': '关闭',
111
134
  'board.toolSelect': '拖动',
@@ -316,6 +339,26 @@ window.__ModuleLoader__.load({
316
339
  'note.removed': 'Card note deleted',
317
340
  'board.title': 'Notes board',
318
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.',
319
362
  'board.newSticky': 'New sticky',
320
363
  'board.stickyHint': 'Sticky notes are draggable; draw on the grid or on a note, erase strokes with the eraser.',
321
364
  'board.resizeNote': 'Drag to resize the sticky',
@@ -324,6 +367,9 @@ window.__ModuleLoader__.load({
324
367
  'board.drawOnStickyOff': 'Sticky drawing: off',
325
368
  'board.drawOnStickyHint': 'When on, pen/shape tools draw directly on sticky notes; when off they only draw on the grid.',
326
369
  'board.center': 'Auto fit',
370
+ 'board.zoomIn': 'Zoom in',
371
+ 'board.zoomOut': 'Zoom out',
372
+ 'board.zoomReset': 'Reset to 100%',
327
373
  'board.reader': 'Read md',
328
374
  'board.close': 'Close',
329
375
  'board.toolSelect': 'Move',
@@ -613,7 +659,7 @@ window.__ModuleLoader__.load({
613
659
  .tb-board-canvas.draw .tb-sticky-resize{cursor:nwse-resize}
614
660
  .tb-board-canvas.select:active{cursor:grabbing}
615
661
  .tb-board-world{position:relative;flex:none}
616
- .tb-board-stage{position:absolute;left:0;top:0;transform-origin:0 0;background-color:var(--dsw-alias-bg-base,#16181d);background-image:linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px);background-size:22px 22px,22px 22px,110px 110px,110px 110px}
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}
617
663
  .tb-board-bgdraw{position:absolute;left:0;top:0;pointer-events:none;overflow:visible}
618
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}
619
665
  .tb-sticky:active{cursor:grabbing}
@@ -642,6 +688,41 @@ window.__ModuleLoader__.load({
642
688
  .tb-board-md-item-head{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
643
689
  .tb-board-md-item-title{font-weight:600;font-size:12px}
644
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}}
645
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)}
646
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}
647
728
  .tb-board-title{font-weight:600;font-size:13.5px}
@@ -654,17 +735,17 @@ window.__ModuleLoader__.load({
654
735
  .tb-board-note-title{font-weight:600;font-size:12.5px;word-break:break-word}
655
736
  .tb-board-meta{font-size:10.5px;color:var(--dsw-alias-label-tertiary,#8a919c);white-space:nowrap}
656
737
  .tb-board-actions{margin-left:auto;display:flex;gap:4px;flex-wrap:wrap}
657
- .tb-md{font-size:12px;line-height:1.6;color:var(--dsw-alias-label-primary,#d7dbe2);word-break:break-word}
738
+ .tb-md{font-size:14.5px;line-height:1.75;color:var(--dsw-alias-label-primary,#d7dbe2);word-break:break-word}
658
739
  .tb-md>*:first-child{margin-top:0}
659
740
  .tb-md>*:last-child{margin-bottom:0}
660
- .tb-md h1,.tb-md h2,.tb-md h3,.tb-md h4,.tb-md h5,.tb-md h6{margin:8px 0 4px;font-size:13px;line-height:1.4}
661
- .tb-md h1{font-size:15px}.tb-md h2{font-size:14px}
662
- .tb-md p{margin:4px 0}
663
- .tb-md ul,.tb-md ol{margin:4px 0;padding-left:20px}
664
- .tb-md li{margin:2px 0}
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}
665
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)}
666
- .tb-md code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:11px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.08));border-radius:4px;padding:1px 4px}
667
- .tb-md pre{margin:6px 0;padding:8px 10px;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))}
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))}
668
749
  .tb-md pre code{background:transparent;padding:0}
669
750
  .tb-md a{color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#7aa2ff)}
670
751
  .tb-md hr{border:0;border-top:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));margin:8px 0}
@@ -793,7 +874,7 @@ window.__ModuleLoader__.load({
793
874
  /** Parse inline Markdown (bold/italic/code/link) into React children. */
794
875
  function inlineMarkdown(text, keyPrefix) {
795
876
  const nodes = []
796
- const pattern = /(\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|\*[^*\n]+\*|_[^_\n]+_)/g
877
+ const pattern = /(<span style="color:\s*#[0-9a-f]{3,8}\s*">[\s\S]*?<\/span>|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|\*[^*\n]+\*|_[^\n_]+_)/g
797
878
  let last = 0
798
879
  let match
799
880
  let index = 0
@@ -801,7 +882,11 @@ window.__ModuleLoader__.load({
801
882
  if (match.index > last) nodes.push(text.slice(last, match.index))
802
883
  const token = match[0]
803
884
  const key = `${keyPrefix}-i${index++}`
804
- if (token.startsWith('`')) nodes.push(h('code', { key }, token.slice(1, -1)))
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)))
805
890
  else if (token.startsWith('**') || token.startsWith('__')) nodes.push(h('strong', { key }, token.slice(2, -2)))
806
891
  else if (token.startsWith('[')) {
807
892
  const link = /^\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)$/.exec(token)
@@ -2431,11 +2516,12 @@ window.__ModuleLoader__.load({
2431
2516
  h('button', { type: 'button', className: 'tb-btn', disabled: noteEditor.busy, onClick: () => setNoteEditor(null) }, t('note.cancel')),
2432
2517
  ),
2433
2518
  h('div', { className: 'tb-ws-hint' }, t('note.hint')),
2434
- h('textarea', {
2519
+ h(MarkdownEditor, {
2435
2520
  value: noteEditor.text,
2436
- placeholder: t('note.placeholder'),
2521
+ onChange: (next) => setNoteEditor({ ...noteEditor, text: next }),
2522
+ t,
2437
2523
  disabled: noteEditor.busy,
2438
- onChange: (event) => setNoteEditor({ ...noteEditor, text: event.target.value }),
2524
+ placeholder: t('note.placeholder'),
2439
2525
  }),
2440
2526
  noteEditor.error ? h('div', { className: 'tb-feedback err' }, noteEditor.error) : null,
2441
2527
  h(
@@ -3052,6 +3138,453 @@ window.__ModuleLoader__.load({
3052
3138
  }
3053
3139
  }
3054
3140
 
3141
+ function escapeHtmlText(text) {
3142
+ return String(text ?? '')
3143
+ .replace(/&/g, '&amp;')
3144
+ .replace(/</g, '&lt;')
3145
+ .replace(/>/g, '&gt;')
3146
+ .replace(/"/g, '&quot;')
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 `![${node.getAttribute ? node.getAttribute('alt') || '' : ''}](${node.getAttribute ? node.getAttribute('src') || '' : ''})`
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
+
3055
3588
  const BOARD_SHAPES = [
3056
3589
  ['rect', '▭', 'board.shapeRect'],
3057
3590
  ['ellipse', '◯', 'board.shapeEllipse'],
@@ -3125,6 +3658,8 @@ window.__ModuleLoader__.load({
3125
3658
  const [zoom, setZoom] = React.useState(1)
3126
3659
  const zoomRef = React.useRef(zoom)
3127
3660
  zoomRef.current = zoom
3661
+ const zoomAnchorRef = React.useRef(null)
3662
+ const wheelRef = React.useRef({ frame: 0, target: null, pointer: null })
3128
3663
  const [drawOnSticky, setDrawOnSticky] = React.useState(() => {
3129
3664
  try {
3130
3665
  return window.localStorage.getItem('dsh-timeback:board-draw-on-sticky') !== '0'
@@ -3168,6 +3703,76 @@ window.__ModuleLoader__.load({
3168
3703
  if (saveTimerRef.current) clearTimeout(saveTimerRef.current)
3169
3704
  }, [])
3170
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
+
3171
3776
  /** Fit every note/stroke into view: pick a zoom and scroll offset. */
3172
3777
  const autoFit = () => {
3173
3778
  const viewport = viewportRef.current
@@ -3204,6 +3809,7 @@ window.__ModuleLoader__.load({
3204
3809
  const spanX = Math.max(120, maxX - minX)
3205
3810
  const spanY = Math.max(120, maxY - minY)
3206
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
3207
3813
  setZoom(nextZoom)
3208
3814
  zoomRef.current = nextZoom
3209
3815
  const centerX = (minX + maxX) / 2
@@ -4246,6 +4852,9 @@ window.__ModuleLoader__.load({
4246
4852
  h('span', { style: { flex: 1 } }),
4247
4853
  h('span', { className: 'tb-muted tb-small' }, format(t('board.count'), { count: entries.length, version: boardVersion })),
4248
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) }, '+'),
4249
4858
  h('button', { type: 'button', className: 'tb-btn', disabled: state.loading, onClick: refresh }, t('board.refresh')),
4250
4859
  h('button', { type: 'button', className: 'tb-btn primary', onClick: startCreate }, `+ ${t('board.newSticky')}`),
4251
4860
  ),
@@ -4352,15 +4961,6 @@ window.__ModuleLoader__.load({
4352
4961
  { className: 'tb-detail-head' },
4353
4962
  h('span', { className: 'tb-detail-title' }, draft.id ? t('board.edit') : t('board.newSticky')),
4354
4963
  h('span', { style: { flex: 1 } }),
4355
- h(
4356
- 'button',
4357
- {
4358
- type: 'button',
4359
- className: `tb-viewtab${draft.preview ? ' on' : ''}`,
4360
- onClick: () => setDraft({ ...draft, preview: !draft.preview }),
4361
- },
4362
- draft.preview ? t('board.editMode') : t('board.preview'),
4363
- ),
4364
4964
  h('button', { type: 'button', className: 'tb-btn', title: t('board.resizeHint'), onClick: resetDialogSize }, t('board.resetSize')),
4365
4965
  ),
4366
4966
  h('input', {
@@ -4369,14 +4969,13 @@ window.__ModuleLoader__.load({
4369
4969
  disabled: draft.busy,
4370
4970
  onChange: (event) => setDraft({ ...draft, title: event.target.value }),
4371
4971
  }),
4372
- draft.preview
4373
- ? h('div', { className: 'tb-md' }, ...renderMarkdown(draft.body, 'board-draft'))
4374
- : h('textarea', {
4375
- value: draft.body,
4376
- placeholder: t('board.bodyPlaceholder'),
4377
- disabled: draft.busy,
4378
- onChange: (event) => setDraft({ ...draft, body: event.target.value }),
4379
- }),
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
+ }),
4380
4979
  h('div', { className: 'tb-ws-hint' }, t('board.resizeHint')),
4381
4980
  draft.error ? h('div', { className: 'tb-feedback err' }, format(t('board.error'), { error: draft.error })) : null,
4382
4981
  h(
@@ -4399,6 +4998,9 @@ window.__ModuleLoader__.load({
4399
4998
  window.__TIMEBACK_TEST__.renderMarkdown = renderMarkdown
4400
4999
  window.__TIMEBACK_TEST__.stripMarkdown = stripMarkdown
4401
5000
  window.__TIMEBACK_TEST__.boardEdgePath = boardEdgePath
5001
+ window.__TIMEBACK_TEST__.MarkdownEditor = MarkdownEditor
5002
+ window.__TIMEBACK_TEST__.markdownToEditorHtml = markdownToEditorHtml
5003
+ window.__TIMEBACK_TEST__.domToMarkdown = domToMarkdown
4402
5004
  }
4403
5005
 
4404
5006
  return {
package/docs/MARKET.md CHANGED
@@ -78,12 +78,12 @@ dshmarket;要让所有人的 dshmarket 搜到,必须走下一节的公共目
78
78
 
79
79
  ## 4. npm(已发布 0.6.0)
80
80
 
81
- `dsh-timeback@0.7.1` 已发布到官方 npm(<https://www.npmjs.com/package/dsh-timeback>),
81
+ `dsh-timeback@0.7.2` 已发布到官方 npm(<https://www.npmjs.com/package/dsh-timeback>),
82
82
  用户可以直接安装/固定版本:
83
83
 
84
84
  ```bash
85
85
  dsh plugin --profile web add dsh-timeback
86
- dsh plugin --profile web add dsh-timeback@0.7.1
86
+ dsh plugin --profile web add dsh-timeback@0.7.2
87
87
  ```
88
88
 
89
89
  awesome 目录 CI 会从 npm 自动补充映射,之后市场安装和更新会走 registry。发布流程参考:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-timeback",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "Conversation tree with per-turn workspace snapshots for DeepSeek Harness: branch at any checkpoint and restore the files that turn had.",
5
5
  "type": "module",
6
6
  "license": "MIT",