dsh-sidenote 0.8.2 → 0.8.4

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.
Files changed (48) hide show
  1. package/README.md +2 -2
  2. package/lib/client.js +657 -213
  3. package/lib/index.js +898 -1
  4. package/lib/types/client/annotate/SelectionToolbar.d.ts +10 -0
  5. package/lib/types/client/annotate/anchor.d.ts +2 -2
  6. package/lib/types/client/annotate/index.d.ts +2 -1
  7. package/lib/types/client/annotate/overlay.d.ts +2 -0
  8. package/lib/types/client/annotate/selection.d.ts +6 -14
  9. package/lib/types/client/annotations/format.d.ts +1 -1
  10. package/lib/types/client/annotations/model.d.ts +10 -6
  11. package/lib/types/client/annotations/source.d.ts +5 -0
  12. package/lib/types/client/host/contracts.d.ts +2 -1
  13. package/lib/types/client/host/dom.d.ts +5 -1
  14. package/lib/types/client/host/input.d.ts +2 -0
  15. package/lib/types/client/host/replyDefaults.d.ts +19 -0
  16. package/lib/types/client/host/selection.d.ts +4 -0
  17. package/lib/types/client/locales.d.ts +11 -0
  18. package/lib/types/client/preferences.d.ts +23 -0
  19. package/lib/types/client/settings.d.ts +3 -0
  20. package/lib/types/client/sidechat/context.d.ts +1 -0
  21. package/lib/types/index.d.ts +2 -1
  22. package/lib/types/settings.d.ts +9 -0
  23. package/package.json +7 -9
  24. package/src/client/annotate/SelectionToolbar.tsx +63 -0
  25. package/src/client/annotate/anchor.ts +32 -22
  26. package/src/client/annotate/annotate.module.css +25 -5
  27. package/src/client/annotate/index.tsx +6 -3
  28. package/src/client/annotate/overlay.tsx +52 -80
  29. package/src/client/annotate/selection.ts +26 -30
  30. package/src/client/annotations/format.ts +7 -3
  31. package/src/client/annotations/model.ts +50 -16
  32. package/src/client/annotations/send.ts +11 -2
  33. package/src/client/annotations/source.ts +56 -8
  34. package/src/client/host/contracts.ts +4 -0
  35. package/src/client/host/dom.ts +14 -1
  36. package/src/client/host/input.ts +6 -0
  37. package/src/client/host/replyDefaults.ts +38 -0
  38. package/src/client/host/selection.tsx +39 -0
  39. package/src/client/host/submission.ts +9 -2
  40. package/src/client/index.tsx +15 -2
  41. package/src/client/locales.ts +22 -0
  42. package/src/client/preferences.ts +52 -0
  43. package/src/client/settings.module.css +59 -0
  44. package/src/client/settings.tsx +43 -0
  45. package/src/client/sidechat/ContextProgress.tsx +1 -1
  46. package/src/client/sidechat/context.ts +3 -2
  47. package/src/index.ts +7 -0
  48. package/src/settings.ts +7 -0
package/lib/client.js CHANGED
@@ -53,6 +53,14 @@ window.__ModuleLoader__.load({
53
53
  function resolveInput(ctx, sessionId) {
54
54
  return probeInput(ctx, sessionId).input;
55
55
  }
56
+ /** The captured source session owns the quote, even if another pane has focus. */
57
+ function insertNativeQuote(ctx, sessionId, text) {
58
+ try {
59
+ return resolveInput(ctx, sessionId)?.insertQuote?.(text) ?? false;
60
+ } catch {
61
+ return false;
62
+ }
63
+ }
56
64
  /** Shape and real state read share the exact resolver used by both composers. */
57
65
  function probeInput(ctx, sessionId) {
58
66
  const path = "sessions.scope → conversation.input.for";
@@ -322,7 +330,18 @@ window.__ModuleLoader__.load({
322
330
  /** Internal conversation DOM seams, validated by the pinned host journeys.
323
331
  * Main message markers and composer seats have no public replacement API. */
324
332
  const MAIN_ASSISTANT = "[data-chat-flow-kind=\"assistant-step\"]";
325
- const NON_QUOTE = "button, [role=\"button\"], input, textarea, select, [contenteditable=\"true\"], [data-code-block-banner], [data-variant=\"think\"], [data-sidenote-no-quote]";
333
+ const NON_QUOTE = "button, [role=\"button\"], input, textarea, select, [contenteditable=\"true\"], [data-code-block-banner], [data-variant=\"think\"], [data-chat-group-part=\"reasoning\"], [data-sidenote-no-quote]";
334
+ const PROCESS_UI = "[data-variant=\"think\"], [data-chat-group-part=\"reasoning\"], [data-chat-flow-kind=\"tool-call\"], [data-chat-flow-kind=\"tool-result\"], [data-chat-flow-kind=\"turn-process\"], [data-context-kind=\"thinking\"], [data-context-kind=\"tool\"]";
335
+ /** Collapsed process rows can remain mounted, including during their animation. */
336
+ function quoteNodeVisible(node) {
337
+ for (let element = elementOf(node); element !== null; element = element.parentElement) {
338
+ if (element.matches("[hidden], [data-turn-process-hidden], [data-turn-process-inline]")) return false;
339
+ if (element instanceof HTMLDetailsElement && !element.open && !element.querySelector(":scope > summary")?.contains(node)) return false;
340
+ const style = getComputedStyle(element);
341
+ if (style.display === "none" || style.visibility === "hidden") return false;
342
+ }
343
+ return true;
344
+ }
326
345
  function nativeAssistantBodies(root = document) {
327
346
  return [...root.querySelectorAll(MAIN_ASSISTANT)];
328
347
  }
@@ -341,6 +360,7 @@ window.__ModuleLoader__.load({
341
360
  view: conversation ?? document.body,
342
361
  anchor,
343
362
  key: anchor.dataset.chatAnchorKey,
363
+ turn: body.closest("[data-chat-turn]")?.dataset.chatTurn,
344
364
  sessionId,
345
365
  surface: "main",
346
366
  streaming: body.hasAttribute("data-streaming") || body.querySelector("[data-streaming]") !== null
@@ -651,7 +671,8 @@ window.__ModuleLoader__.load({
651
671
  const inbox = inboxFaceOf(binding);
652
672
  const nodes = () => chat.getLegacy()?.nodes ?? [];
653
673
  const maxSeq = Math.max(-1, ...nodes().map((node) => node.seq ?? -1));
654
- const queueIds = new Set(queuedMessages(binding, inbox).map((message) => message.messageId ?? message.id));
674
+ const queuedBefore = queuedMessages(binding, inbox);
675
+ const queueIds = new Set(queuedBefore.map((message) => message.messageId ?? message.id));
655
676
  const previousError = binding.session.getSnapshot().promptError;
656
677
  const previousNoticeSeq = input.notices?.getSnapshot()?.seq ?? -1;
657
678
  const off = [];
@@ -687,7 +708,10 @@ window.__ModuleLoader__.load({
687
708
  };
688
709
  const check = () => {
689
710
  if (!submitted || settled) return;
690
- if (nodes().some((node) => (node.kind === "user" || node.kind === "steering") && (node.seq ?? -1) > maxSeq && matches(node)) || queuedMessages(binding, inbox).some((message) => {
711
+ if (nodes().some((node) => {
712
+ const id = node.messageId ?? node.id;
713
+ return (node.kind === "user" || node.kind === "steering") && (node.seq ?? -1) > maxSeq && matches(node) && (id === void 0 ? !queuedBefore.some(matches) : !queueIds.has(id));
714
+ }) || queuedMessages(binding, inbox).some((message) => {
691
715
  const id = message.messageId ?? message.id;
692
716
  return id !== void 0 && !queueIds.has(id) && matches(message);
693
717
  })) {
@@ -742,7 +766,7 @@ window.__ModuleLoader__.load({
742
766
  let dockRegistered = false;
743
767
  let report = {
744
768
  versions: {
745
- sidenote: "0.8.2",
769
+ sidenote: "0.8.4",
746
770
  dsh: "unknown",
747
771
  betterSidebar: null
748
772
  },
@@ -936,6 +960,17 @@ window.__ModuleLoader__.load({
936
960
  inputWaiting: "The input is not ready. Body, attachments and quotes have been retained. Please try again shortly.",
937
961
  draftRecoveryConflict: "The host has another draft. Your local body is retained; review this session in the main view before retrying.",
938
962
  quoteWorkflowWaiting: "Annotations are not ready yet. Please try again shortly.",
963
+ nativeQuote: "Quote",
964
+ nativeQuoteHint: "Insert the selected text as a quote in this conversation",
965
+ nativeQuoteFailed: "The quote could not be added. Wait for the input to be ready and try again.",
966
+ settingsDescription: "Choose the actions available when you select conversation text.",
967
+ hideNativeQuote: "Hide native quote",
968
+ hideNativeQuoteHint: "Hide the Quote action in main and side chats.",
969
+ settingsSaving: "Saving…",
970
+ settingsLoading: "Loading preferences…",
971
+ settingsUnavailable: "Preferences are unavailable. Reload the page to reconnect.",
972
+ settingsReadOnly: "Preferences are read-only in this host.",
973
+ settingsSaveFailed: "The preference could not be saved. Please try again.",
939
974
  menuTitle: "Side chat",
940
975
  tabBaseTitle: "Side",
941
976
  codeCopy: "Copy",
@@ -1100,6 +1135,17 @@ window.__ModuleLoader__.load({
1100
1135
  };
1101
1136
  /** 中文词典(与 en 同 key)。 */
1102
1137
  const zh = {
1138
+ nativeQuote: "引用",
1139
+ nativeQuoteHint: "将所选文字作为引用加入当前对话的输入框",
1140
+ nativeQuoteFailed: "暂时无法加入引用,请等待输入框就绪后重试。",
1141
+ settingsDescription: "调整划选对话文字时显示的操作。",
1142
+ hideNativeQuote: "隐藏原生引用",
1143
+ hideNativeQuoteHint: "在主对话和侧边聊天中隐藏“引用”按钮。",
1144
+ settingsSaving: "正在保存…",
1145
+ settingsLoading: "正在加载偏好设置…",
1146
+ settingsUnavailable: "暂时无法读取设置,请刷新页面重新连接。",
1147
+ settingsReadOnly: "当前宿主的偏好设置为只读。",
1148
+ settingsSaveFailed: "设置保存失败,请重试。",
1103
1149
  diagTitle: "兼容诊断",
1104
1150
  diagClose: "关闭兼容诊断",
1105
1151
  diagUnknownVersion: "版本未知",
@@ -1364,23 +1410,23 @@ window.__ModuleLoader__.load({
1364
1410
  }
1365
1411
  //#endregion
1366
1412
  //#region \0dsh-css:/home/runner/work/dsh-sidenote/dsh-sidenote/src/client/diagnostics/diagnostics.module.css.mjs
1367
- const css$3 = ".tGe0LW_trigger{color:var(--dsw-alias-label-secondary,#555);border:1px solid var(--dsw-alias-border-l1,#ddd);cursor:pointer;background:0 0;border-radius:8px;padding:4px 8px;font-size:12px}.tGe0LW_panel{z-index:100;box-sizing:border-box;background:var(--dsw-alias-bg-layer-1,#fff);width:min(400px,100vw - 32px);max-height:calc(100vh - 80px);color:var(--dsw-alias-label-primary,#222);border:1px solid var(--dsw-alias-border-l1,#ddd);border-radius:12px;padding:14px;font-size:13px;position:fixed;top:60px;right:16px;overflow:auto;box-shadow:0 12px 36px #0002}.tGe0LW_header,.tGe0LW_actions,.tGe0LW_list li>div{justify-content:space-between;align-items:center;gap:12px;display:flex}.tGe0LW_header button,.tGe0LW_actions button{color:inherit;border:1px solid var(--dsw-alias-border-l1,#ddd);cursor:pointer;background:0 0;border-radius:6px;padding:4px 8px}.tGe0LW_description,.tGe0LW_versions,.tGe0LW_list p{color:var(--dsw-alias-label-secondary,#666);font-size:12px;line-height:1.5}.tGe0LW_list{margin:12px 0;padding:0;list-style:none}.tGe0LW_list li{border-top:1px solid var(--dsw-alias-border-l1,#ddd);padding:10px 0}.tGe0LW_list li p{margin:4px 0}.tGe0LW_list strong{font-size:12px;font-weight:500}.tGe0LW_list [data-state=unavailable]{color:var(--dsw-alias-state-error-primary,#c33)}.tGe0LW_list details{color:var(--dsw-alias-label-tertiary,#888);font-size:11px}.tGe0LW_list summary{cursor:pointer}.tGe0LW_list code{overflow-wrap:anywhere}";
1368
- const tagId$3 = "dsh-sidenote/diagnostics.module.css";
1369
- if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$3) + "]") === null) {
1413
+ const css$4 = ".tGe0LW_trigger{color:var(--dsw-alias-label-secondary,#555);border:1px solid var(--dsw-alias-border-l1,#ddd);cursor:pointer;background:0 0;border-radius:8px;padding:4px 8px;font-size:12px}.tGe0LW_panel{z-index:100;box-sizing:border-box;background:var(--dsw-alias-bg-layer-1,#fff);width:min(400px,100vw - 32px);max-height:calc(100vh - 80px);color:var(--dsw-alias-label-primary,#222);border:1px solid var(--dsw-alias-border-l1,#ddd);border-radius:12px;padding:14px;font-size:13px;position:fixed;top:60px;right:16px;overflow:auto;box-shadow:0 12px 36px #0002}.tGe0LW_header,.tGe0LW_actions,.tGe0LW_list li>div{justify-content:space-between;align-items:center;gap:12px;display:flex}.tGe0LW_header button,.tGe0LW_actions button{color:inherit;border:1px solid var(--dsw-alias-border-l1,#ddd);cursor:pointer;background:0 0;border-radius:6px;padding:4px 8px}.tGe0LW_description,.tGe0LW_versions,.tGe0LW_list p{color:var(--dsw-alias-label-secondary,#666);font-size:12px;line-height:1.5}.tGe0LW_list{margin:12px 0;padding:0;list-style:none}.tGe0LW_list li{border-top:1px solid var(--dsw-alias-border-l1,#ddd);padding:10px 0}.tGe0LW_list li p{margin:4px 0}.tGe0LW_list strong{font-size:12px;font-weight:500}.tGe0LW_list [data-state=unavailable]{color:var(--dsw-alias-state-error-primary,#c33)}.tGe0LW_list details{color:var(--dsw-alias-label-tertiary,#888);font-size:11px}.tGe0LW_list summary{cursor:pointer}.tGe0LW_list code{overflow-wrap:anywhere}";
1414
+ const tagId$4 = "dsh-sidenote/diagnostics.module.css";
1415
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$4) + "]") === null) {
1370
1416
  const tag = document.createElement("style");
1371
1417
  tag.dataset.plugin = "dsh-sidenote";
1372
- tag.dataset.pluginCss = tagId$3;
1373
- tag.textContent = css$3;
1418
+ tag.dataset.pluginCss = tagId$4;
1419
+ tag.textContent = css$4;
1374
1420
  document.head.appendChild(tag);
1375
1421
  }
1376
1422
  var diagnostics_module_css_default = {
1377
- "panel": "tGe0LW_panel",
1378
- "actions": "tGe0LW_actions",
1379
- "description": "tGe0LW_description",
1380
1423
  "versions": "tGe0LW_versions",
1381
1424
  "header": "tGe0LW_header",
1425
+ "panel": "tGe0LW_panel",
1382
1426
  "trigger": "tGe0LW_trigger",
1383
- "list": "tGe0LW_list"
1427
+ "actions": "tGe0LW_actions",
1428
+ "list": "tGe0LW_list",
1429
+ "description": "tGe0LW_description"
1384
1430
  };
1385
1431
  //#endregion
1386
1432
  //#region src/client/diagnostics/index.tsx
@@ -1688,9 +1734,13 @@ window.__ModuleLoader__.load({
1688
1734
  if (typeof a.text !== "string" || typeof a.anchorText !== "string") return null;
1689
1735
  if (typeof a.occurrence !== "number") return null;
1690
1736
  if (a.state !== "active" && a.state !== "sent") return null;
1737
+ if (a.anchors !== void 0) {
1738
+ if (!Array.isArray(a.anchors) || a.anchors.length < 2) return null;
1739
+ for (const anchor of a.anchors) if (!anchor || typeof anchor.anchorKey !== "string" || !anchor.anchorKey || typeof anchor.anchorText !== "string" || !anchor.anchorText.trim() || !Number.isSafeInteger(anchor.occurrence) || anchor.occurrence < 0) return null;
1740
+ }
1691
1741
  return {
1692
1742
  id: a.id,
1693
- number: a.number,
1743
+ number: a.state === "sent" && typeof a.localNumber === "number" ? a.localNumber : a.number,
1694
1744
  sessionId: a.sessionId,
1695
1745
  sourceSessionId: typeof a.sourceSessionId === "string" && a.sourceSessionId !== "" ? a.sourceSessionId : void 0,
1696
1746
  sourceSurface: a.sourceSurface === "main" || a.sourceSurface === "side" ? a.sourceSurface : void 0,
@@ -1698,6 +1748,7 @@ window.__ModuleLoader__.load({
1698
1748
  text: a.text,
1699
1749
  anchorText: a.anchorText,
1700
1750
  occurrence: a.occurrence,
1751
+ ...a.anchors ? { anchors: a.anchors } : {},
1701
1752
  note: typeof a.note === "string" ? a.note : "",
1702
1753
  state: a.state,
1703
1754
  createdAt: typeof a.createdAt === "number" ? a.createdAt : 0
@@ -1707,11 +1758,24 @@ window.__ModuleLoader__.load({
1707
1758
  let annotations = [];
1708
1759
  let nextId = 1;
1709
1760
  let version = 0;
1710
- /** Per-session next display number. */
1711
- const counters = /* @__PURE__ */ new Map();
1712
1761
  const listeners = /* @__PURE__ */ new Set();
1713
1762
  const submissions = /* @__PURE__ */ new Map();
1714
1763
  const idleSubmission = { pending: false };
1764
+ const countActiveOf = (sessionId) => annotations.reduce((n, a) => n + (a.sessionId === sessionId && a.state === "active" ? 1 : 0), 0);
1765
+ /** 只重排目标会话的待发送编号,已发送编号保持冻结。 */
1766
+ const renumberActive = (sessionId) => {
1767
+ const numbers = /* @__PURE__ */ new Map();
1768
+ annotations.filter((a) => a.sessionId === sessionId && a.state === "active").sort((left, right) => left.id - right.id).forEach((annotation, index) => {
1769
+ numbers.set(annotation.id, index + 1);
1770
+ });
1771
+ annotations = annotations.map((a) => {
1772
+ const number = numbers.get(a.id);
1773
+ return number === void 0 || a.number === number ? a : {
1774
+ ...a,
1775
+ number
1776
+ };
1777
+ });
1778
+ };
1715
1779
  let store = storage ?? null;
1716
1780
  if (storage === void 0) try {
1717
1781
  store = globalThis.localStorage ?? null;
@@ -1742,7 +1806,6 @@ window.__ModuleLoader__.load({
1742
1806
  const revived = reviveStored(item);
1743
1807
  if (revived === null) continue;
1744
1808
  annotations.push(revived);
1745
- counters.set(revived.sessionId, Math.max(counters.get(revived.sessionId) ?? 0, revived.number));
1746
1809
  nextId = Math.max(nextId, revived.id + 1);
1747
1810
  }
1748
1811
  }
@@ -1775,6 +1838,7 @@ window.__ModuleLoader__.load({
1775
1838
  version += 1;
1776
1839
  for (const fn of [...listeners]) fn();
1777
1840
  };
1841
+ for (const sessionId of new Set(annotations.map((a) => a.sessionId))) renumberActive(sessionId);
1778
1842
  const replace = (id, patch) => {
1779
1843
  const target = annotations.find((a) => a.id === id);
1780
1844
  annotations = annotations.map((a) => a.id === id ? {
@@ -1799,8 +1863,7 @@ window.__ModuleLoader__.load({
1799
1863
  };
1800
1864
  },
1801
1865
  add(draft) {
1802
- const number = (counters.get(draft.sessionId) ?? 0) + 1;
1803
- counters.set(draft.sessionId, number);
1866
+ const number = countActiveOf(draft.sessionId) + 1;
1804
1867
  const annotation = {
1805
1868
  id: nextId,
1806
1869
  number,
@@ -1811,6 +1874,7 @@ window.__ModuleLoader__.load({
1811
1874
  text: draft.text,
1812
1875
  anchorText: draft.anchorText,
1813
1876
  occurrence: draft.occurrence,
1877
+ ...draft.anchors ? { anchors: draft.anchors } : {},
1814
1878
  note: draft.note,
1815
1879
  state: "active",
1816
1880
  createdAt: now()
@@ -1829,10 +1893,11 @@ window.__ModuleLoader__.load({
1829
1893
  const target = annotations.find((a) => a.id === id);
1830
1894
  if (target === void 0) return;
1831
1895
  annotations = annotations.filter((a) => a.id !== id);
1896
+ renumberActive(target.sessionId);
1832
1897
  persistTouched([target.sessionId]);
1833
1898
  notify();
1834
1899
  },
1835
- markSent(ids) {
1900
+ markSent(ids, frozenNumbers) {
1836
1901
  if (ids.length === 0) return;
1837
1902
  const idSet = new Set(ids);
1838
1903
  if (!annotations.some((a) => idSet.has(a.id) && a.state === "active")) return;
@@ -1842,9 +1907,11 @@ window.__ModuleLoader__.load({
1842
1907
  touched.add(a.sessionId);
1843
1908
  return {
1844
1909
  ...a,
1845
- state: "sent"
1910
+ state: "sent",
1911
+ number: frozenNumbers?.get(a.id) ?? a.number
1846
1912
  };
1847
1913
  });
1914
+ for (const sessionId of touched) renumberActive(sessionId);
1848
1915
  persistTouched([...touched]);
1849
1916
  notify();
1850
1917
  },
@@ -1858,7 +1925,7 @@ window.__ModuleLoader__.load({
1858
1925
  return annotations.filter((a) => a.sessionId === sessionId && a.state === "active");
1859
1926
  },
1860
1927
  countActive(sessionId) {
1861
- return annotations.reduce((n, a) => n + (a.sessionId === sessionId && a.state === "active" ? 1 : 0), 0);
1928
+ return countActiveOf(sessionId);
1862
1929
  },
1863
1930
  sessions() {
1864
1931
  return [...new Set(annotations.map((a) => a.sessionId))];
@@ -2208,7 +2275,7 @@ window.__ModuleLoader__.load({
2208
2275
  }
2209
2276
  /** 协议头识别(zh/en 都认):整行匹配。 */
2210
2277
  const PROTOCOL_HEADER_RE = /^(?:我批注了以下 (\d+) 处内容:|I annotated (\d+) passage\(s\) of the conversation above:)$/;
2211
- const ANNOTATION_RE = /<annotation id="(\d+)">\s*<quote>([\s\S]*?)<\/quote>\s*(?:<note>([\s\S]*?)<\/note>\s*)?<\/annotation>/y;
2278
+ const ANNOTATION_RE = /<annotation id="(\d+)"(?: local="(\d+)")?(?: scope="[^"]*")?>\s*<quote>([\s\S]*?)<\/quote>\s*(?:<note>([\s\S]*?)<\/note>\s*)?<\/annotation>/y;
2212
2279
  const REFLOW_RE = /<reflow\s+source="([^"]*)"(?:\s+reason="([^"]*)")?\s*>([\s\S]*?)<\/reflow>/y;
2213
2280
  /**
2214
2281
  * 气泡 tooltip / 面板留痕 chip 的展示拍平:剥掉 <问>/<答> 协议标签只留内容行
@@ -2246,14 +2313,16 @@ window.__ModuleLoader__.load({
2246
2313
  const headerMatch = /^([^\n]*)\n/.exec(rest);
2247
2314
  if (headerMatch !== null && PROTOCOL_HEADER_RE.test(headerMatch[1] ?? "")) {
2248
2315
  let cursor = pos + headerMatch[0].length;
2316
+ const legacyGuidance = /^Annotation ids stay stable within (?:their session scope|this conversation)\.[^\n]*\n/.exec(text.slice(cursor));
2317
+ if (legacyGuidance) cursor += legacyGuidance[0].length;
2249
2318
  for (;;) {
2250
2319
  ANNOTATION_RE.lastIndex = cursor;
2251
2320
  const m = ANNOTATION_RE.exec(text);
2252
2321
  if (m === null) break;
2253
2322
  annotations.push({
2254
- id: Number(m[1]),
2255
- quote: m[2] ?? "",
2256
- note: (m[3] ?? "").trim()
2323
+ id: Number(m[2] ?? m[1]),
2324
+ quote: m[3] ?? "",
2325
+ note: (m[4] ?? "").trim()
2257
2326
  });
2258
2327
  cursor = skipBlank(text, ANNOTATION_RE.lastIndex);
2259
2328
  }
@@ -2269,43 +2338,43 @@ window.__ModuleLoader__.load({
2269
2338
  }
2270
2339
  //#endregion
2271
2340
  //#region \0dsh-css:/home/runner/work/dsh-sidenote/dsh-sidenote/src/client/annotations/annotations.module.css.mjs
2272
- const css$2 = ".SVnebq_chipWrap{box-sizing:border-box;width:calc(100% - 2 * var(--dsh-composer-side-clearance,16px));max-width:var(--dsh-composer-card-max-width,780px);background:var(--dsw-alias-bg-base);flex-wrap:wrap;align-items:center;gap:6px;margin:0 auto;padding:2px 0;display:flex}.SVnebq_chip{--chip-surface:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);background:var(--chip-surface);color:var(--dsw-alias-label-secondary);border-radius:10px;align-items:center;transition:background .12s,color .12s;display:inline-flex;position:relative}.SVnebq_chip:hover,.SVnebq_chip:focus-within,.SVnebq_chip[data-open]{--chip-surface:var(--dsw-alias-interactive-bg-hover-solid);color:var(--dsw-alias-label-primary)}.SVnebq_chipMain{border-radius:inherit;min-height:28px;color:inherit;font:inherit;cursor:pointer;background:0 0;border:0;align-items:center;gap:5px;padding:3px 9px;font-size:12px;line-height:18px;display:inline-flex}.SVnebq_chipDismissShade{border-radius:inherit;background:linear-gradient(to right, transparent, var(--chip-surface) 45%);opacity:0;pointer-events:none;justify-content:flex-end;align-items:center;width:38px;transition:opacity .16s ease-out;display:flex;position:absolute;inset:0 3px 0 auto}.SVnebq_chipDismiss{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);width:24px;height:24px;color:var(--dsw-alias-label-secondary);cursor:pointer;border-radius:50%;flex:none;justify-content:center;align-items:center;padding:0;transition:transform .16s ease-out,background .12s,color .12s;display:inline-flex;transform:translate(2px)scale(.94)}.SVnebq_chip:hover .SVnebq_chipDismissShade,.SVnebq_chip:focus-within .SVnebq_chipDismissShade{opacity:1}.SVnebq_chip:hover .SVnebq_chipDismiss,.SVnebq_chip:focus-within .SVnebq_chipDismiss{pointer-events:auto;transform:none}.SVnebq_chipDismiss:hover{background:var(--dsw-alias-interactive-bg-hover-solid);color:var(--dsw-alias-label-primary)}.SVnebq_chipDismiss:disabled{opacity:.45;cursor:default}.SVnebq_contextPanel{box-sizing:border-box;z-index:1000;overscroll-behavior:contain;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);border-radius:14px;padding:4px;animation:.12s ease-out SVnebq_contextAppear;position:fixed;overflow:auto;box-shadow:0 8px 28px #0000001f}.SVnebq_contextList{margin:0;padding:0;list-style:none}.SVnebq_contextItem{border-radius:10px;align-items:flex-start;gap:10px;margin:0;padding:8px 10px;transition:background .12s;display:flex}.SVnebq_contextItem+.SVnebq_contextItem{border-top:1px solid var(--dsw-alias-border-l1)}.SVnebq_contextItem:hover,.SVnebq_contextItem:focus-within{background:var(--dsw-alias-interactive-bg-hover)}.SVnebq_contextNumber{min-width:16px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;flex:none;font-size:12px;line-height:21px}.SVnebq_contextContent{flex:1;min-width:0}.SVnebq_contextLabel{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}.SVnebq_contextLabel:not(:first-child){margin-top:6px}.SVnebq_contextSource{color:var(--dsw-alias-label-secondary);margin-bottom:8px;font-size:12px}.SVnebq_contextText{white-space:pre-wrap;overflow-wrap:anywhere;user-select:text;font-size:13px;line-height:1.6}.SVnebq_contextActions{flex:none;gap:2px;display:flex}.SVnebq_contextAction{width:26px;height:26px;color:var(--dsw-alias-label-tertiary);cursor:pointer;background:0 0;border:0;border-radius:8px;justify-content:center;align-items:center;padding:0;transition:color .12s,background .12s;display:inline-flex}.SVnebq_contextAction:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}.SVnebq_contextAction:disabled,.SVnebq_chipClearAll:disabled{opacity:.45;cursor:default}.SVnebq_contextEditor{box-sizing:border-box;resize:vertical;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-base);width:100%;min-height:64px;color:inherit;font:inherit;border-radius:6px;margin-top:4px;padding:6px 8px;font-size:13px;line-height:1.6;display:block}.SVnebq_contextFooter{padding:2px 10px 4px}.SVnebq_chipClearAll{color:var(--dsw-alias-label-tertiary);cursor:pointer;font:inherit;background:0 0;border:0;border-radius:6px;padding:4px 6px;font-size:12px}.SVnebq_chipClearAll:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-state-error-primary)}.SVnebq_chipMain:focus-visible,.SVnebq_chipDismiss:focus-visible,.SVnebq_contextAction:focus-visible,.SVnebq_chipClearAll:focus-visible,.SVnebq_contextEditor:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}.SVnebq_storageNotice{color:var(--dsw-alias-label-secondary);flex-basis:100%;font-size:12px}@keyframes SVnebq_contextAppear{0%{opacity:0;transform:translateY(3px)}to{opacity:1;transform:translateY(0)}}@media (hover:none){.SVnebq_chipMain{padding-right:32px}.SVnebq_chipDismissShade{opacity:1}.SVnebq_chipDismiss{pointer-events:auto;transform:none}}@media (prefers-reduced-motion:reduce){.SVnebq_contextPanel{animation:none}.SVnebq_chip,.SVnebq_chipDismissShade,.SVnebq_chipDismiss,.SVnebq_contextItem,.SVnebq_contextAction{transition:none}}.SVnebq_userContextHost{display:contents}[data-sidenote-context-replaced]{display:none!important}.SVnebq_sentChips{white-space:normal;display:inline}.SVnebq_sentChipGroup{display:inline}.SVnebq_sentChip{vertical-align:middle;background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary);font:inherit;border:0;border-radius:6px;align-items:center;gap:4px;margin:0 6px 2px 0;padding:2px 6px;font-size:12px;line-height:18px;transition:background .14s,color .14s;display:inline-flex}button.SVnebq_sentChip{cursor:pointer}button.SVnebq_sentChip:hover,button.SVnebq_sentChip[aria-expanded=true]{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover-solid)}button.SVnebq_sentChip:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}.SVnebq_sentChevron,.SVnebq_sentChevronOpen{opacity:.65;flex:none;transition:transform .14s}.SVnebq_sentChevronOpen{transform:rotate(180deg)}.SVnebq_sentPreview{text-align:left;white-space:normal}@media (prefers-reduced-motion:reduce){.SVnebq_sentChip,.SVnebq_sentChevron,.SVnebq_sentChevronOpen{transition:none}}";
2273
- const tagId$2 = "dsh-sidenote/annotations.module.css";
2274
- if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$2) + "]") === null) {
2341
+ const css$3 = ".SVnebq_chipWrap{box-sizing:border-box;width:calc(100% - 2 * var(--dsh-composer-side-clearance,16px));max-width:var(--dsh-composer-card-max-width,780px);background:var(--dsw-alias-bg-base);flex-wrap:wrap;align-items:center;gap:6px;margin:0 auto;padding:2px 0;display:flex}.SVnebq_chip{--chip-surface:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);background:var(--chip-surface);color:var(--dsw-alias-label-secondary);border-radius:10px;align-items:center;transition:background .12s,color .12s;display:inline-flex;position:relative}.SVnebq_chip:hover,.SVnebq_chip:focus-within,.SVnebq_chip[data-open]{--chip-surface:var(--dsw-alias-interactive-bg-hover-solid);color:var(--dsw-alias-label-primary)}.SVnebq_chipMain{border-radius:inherit;min-height:28px;color:inherit;font:inherit;cursor:pointer;background:0 0;border:0;align-items:center;gap:5px;padding:3px 9px;font-size:12px;line-height:18px;display:inline-flex}.SVnebq_chipDismissShade{border-radius:inherit;background:linear-gradient(to right, transparent, var(--chip-surface) 45%);opacity:0;pointer-events:none;justify-content:flex-end;align-items:center;width:38px;transition:opacity .16s ease-out;display:flex;position:absolute;inset:0 3px 0 auto}.SVnebq_chipDismiss{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);width:24px;height:24px;color:var(--dsw-alias-label-secondary);cursor:pointer;border-radius:50%;flex:none;justify-content:center;align-items:center;padding:0;transition:transform .16s ease-out,background .12s,color .12s;display:inline-flex;transform:translate(2px)scale(.94)}.SVnebq_chip:hover .SVnebq_chipDismissShade,.SVnebq_chip:focus-within .SVnebq_chipDismissShade{opacity:1}.SVnebq_chip:hover .SVnebq_chipDismiss,.SVnebq_chip:focus-within .SVnebq_chipDismiss{pointer-events:auto;transform:none}.SVnebq_chipDismiss:hover{background:var(--dsw-alias-interactive-bg-hover-solid);color:var(--dsw-alias-label-primary)}.SVnebq_chipDismiss:disabled{opacity:.45;cursor:default}.SVnebq_contextPanel{box-sizing:border-box;z-index:1000;overscroll-behavior:contain;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);border-radius:14px;padding:4px;animation:.12s ease-out SVnebq_contextAppear;position:fixed;overflow:auto;box-shadow:0 8px 28px #0000001f}.SVnebq_contextList{margin:0;padding:0;list-style:none}.SVnebq_contextItem{border-radius:10px;align-items:flex-start;gap:10px;margin:0;padding:8px 10px;transition:background .12s;display:flex}.SVnebq_contextItem+.SVnebq_contextItem{border-top:1px solid var(--dsw-alias-border-l1)}.SVnebq_contextItem:hover,.SVnebq_contextItem:focus-within{background:var(--dsw-alias-interactive-bg-hover)}.SVnebq_contextNumber{min-width:16px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;flex:none;font-size:12px;line-height:21px}.SVnebq_contextContent{flex:1;min-width:0}.SVnebq_contextLabel{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}.SVnebq_contextLabel:not(:first-child){margin-top:6px}.SVnebq_contextSource{color:var(--dsw-alias-label-secondary);margin-bottom:8px;font-size:12px}.SVnebq_contextText{white-space:pre-wrap;overflow-wrap:anywhere;user-select:text;font-size:13px;line-height:1.6}.SVnebq_contextActions{flex:none;gap:2px;display:flex}.SVnebq_contextAction{width:26px;height:26px;color:var(--dsw-alias-label-tertiary);cursor:pointer;background:0 0;border:0;border-radius:8px;justify-content:center;align-items:center;padding:0;transition:color .12s,background .12s;display:inline-flex}.SVnebq_contextAction:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}.SVnebq_contextAction:disabled,.SVnebq_chipClearAll:disabled{opacity:.45;cursor:default}.SVnebq_contextEditor{box-sizing:border-box;resize:vertical;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-base);width:100%;min-height:64px;color:inherit;font:inherit;border-radius:6px;margin-top:4px;padding:6px 8px;font-size:13px;line-height:1.6;display:block}.SVnebq_contextFooter{padding:2px 10px 4px}.SVnebq_chipClearAll{color:var(--dsw-alias-label-tertiary);cursor:pointer;font:inherit;background:0 0;border:0;border-radius:6px;padding:4px 6px;font-size:12px}.SVnebq_chipClearAll:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-state-error-primary)}.SVnebq_chipMain:focus-visible,.SVnebq_chipDismiss:focus-visible,.SVnebq_contextAction:focus-visible,.SVnebq_chipClearAll:focus-visible,.SVnebq_contextEditor:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}.SVnebq_storageNotice{color:var(--dsw-alias-label-secondary);flex-basis:100%;font-size:12px}@keyframes SVnebq_contextAppear{0%{opacity:0;transform:translateY(3px)}to{opacity:1;transform:translateY(0)}}@media (hover:none){.SVnebq_chipMain{padding-right:32px}.SVnebq_chipDismissShade{opacity:1}.SVnebq_chipDismiss{pointer-events:auto;transform:none}}@media (prefers-reduced-motion:reduce){.SVnebq_contextPanel{animation:none}.SVnebq_chip,.SVnebq_chipDismissShade,.SVnebq_chipDismiss,.SVnebq_contextItem,.SVnebq_contextAction{transition:none}}.SVnebq_userContextHost{display:contents}[data-sidenote-context-replaced]{display:none!important}.SVnebq_sentChips{white-space:normal;display:inline}.SVnebq_sentChipGroup{display:inline}.SVnebq_sentChip{vertical-align:middle;background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary);font:inherit;border:0;border-radius:6px;align-items:center;gap:4px;margin:0 6px 2px 0;padding:2px 6px;font-size:12px;line-height:18px;transition:background .14s,color .14s;display:inline-flex}button.SVnebq_sentChip{cursor:pointer}button.SVnebq_sentChip:hover,button.SVnebq_sentChip[aria-expanded=true]{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover-solid)}button.SVnebq_sentChip:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}.SVnebq_sentChevron,.SVnebq_sentChevronOpen{opacity:.65;flex:none;transition:transform .14s}.SVnebq_sentChevronOpen{transform:rotate(180deg)}.SVnebq_sentPreview{text-align:left;white-space:normal}@media (prefers-reduced-motion:reduce){.SVnebq_sentChip,.SVnebq_sentChevron,.SVnebq_sentChevronOpen{transition:none}}";
2342
+ const tagId$3 = "dsh-sidenote/annotations.module.css";
2343
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$3) + "]") === null) {
2275
2344
  const tag = document.createElement("style");
2276
2345
  tag.dataset.plugin = "dsh-sidenote";
2277
- tag.dataset.pluginCss = tagId$2;
2278
- tag.textContent = css$2;
2346
+ tag.dataset.pluginCss = tagId$3;
2347
+ tag.textContent = css$3;
2279
2348
  document.head.appendChild(tag);
2280
2349
  }
2281
2350
  var annotations_module_css_default = {
2282
- "chipDismiss": "SVnebq_chipDismiss",
2283
2351
  "contextNumber": "SVnebq_contextNumber",
2284
- "contextFooter": "SVnebq_contextFooter",
2352
+ "contextActions": "SVnebq_contextActions",
2285
2353
  "chipClearAll": "SVnebq_chipClearAll",
2286
2354
  "sentChips": "SVnebq_sentChips",
2287
- "sentChevronOpen": "SVnebq_sentChevronOpen",
2288
2355
  "contextText": "SVnebq_contextText",
2289
- "contextLabel": "SVnebq_contextLabel",
2356
+ "chipWrap": "SVnebq_chipWrap",
2357
+ "contextFooter": "SVnebq_contextFooter",
2358
+ "userContextHost": "SVnebq_userContextHost",
2290
2359
  "chip": "SVnebq_chip",
2291
- "contextPanel": "SVnebq_contextPanel",
2292
- "contextAction": "SVnebq_contextAction",
2293
- "chipMain": "SVnebq_chipMain",
2294
- "contextEditor": "SVnebq_contextEditor",
2360
+ "sentChipGroup": "SVnebq_sentChipGroup",
2361
+ "sentChevron": "SVnebq_sentChevron",
2295
2362
  "sentPreview": "SVnebq_sentPreview",
2296
- "userContextHost": "SVnebq_userContextHost",
2363
+ "contextList": "SVnebq_contextList",
2364
+ "chipDismissShade": "SVnebq_chipDismissShade",
2365
+ "chipDismiss": "SVnebq_chipDismiss",
2297
2366
  "sentChip": "SVnebq_sentChip",
2298
- "sentChipGroup": "SVnebq_sentChipGroup",
2299
2367
  "storageNotice": "SVnebq_storageNotice",
2300
- "contextSource": "SVnebq_contextSource",
2301
- "contextList": "SVnebq_contextList",
2302
- "sentChevron": "SVnebq_sentChevron",
2368
+ "contextLabel": "SVnebq_contextLabel",
2303
2369
  "contextAppear": "SVnebq_contextAppear",
2304
- "contextActions": "SVnebq_contextActions",
2305
- "chipWrap": "SVnebq_chipWrap",
2306
- "chipDismissShade": "SVnebq_chipDismissShade",
2307
- "contextItem": "SVnebq_contextItem",
2308
- "contextContent": "SVnebq_contextContent"
2370
+ "contextPanel": "SVnebq_contextPanel",
2371
+ "contextContent": "SVnebq_contextContent",
2372
+ "contextAction": "SVnebq_contextAction",
2373
+ "contextEditor": "SVnebq_contextEditor",
2374
+ "chipMain": "SVnebq_chipMain",
2375
+ "contextSource": "SVnebq_contextSource",
2376
+ "sentChevronOpen": "SVnebq_sentChevronOpen",
2377
+ "contextItem": "SVnebq_contextItem"
2309
2378
  };
2310
2379
  //#endregion
2311
2380
  //#region src/client/annotations/NativeUserContext.tsx
@@ -2769,47 +2838,47 @@ window.__ModuleLoader__.load({
2769
2838
  }
2770
2839
  //#endregion
2771
2840
  //#region \0dsh-css:/home/runner/work/dsh-sidenote/dsh-sidenote/src/client/sidechat/sidechat.module.css.mjs
2772
- const css$1 = "._5KEEsG_nativeHost,._5KEEsG_root,._5KEEsG_nativeConversation{flex-direction:column;min-height:0;display:flex}._5KEEsG_nativeHost,._5KEEsG_root{height:100%}._5KEEsG_root{color:var(--dsw-alias-label-primary)}._5KEEsG_nativeConversation{flex:1}._5KEEsG_chatView{flex-direction:column;flex:1 0 auto;min-width:0;display:flex}._5KEEsG_mainContext{box-sizing:border-box;width:100%;padding:12px calc(var(--dsh-composer-side-clearance,8px) + 16px) 4px;flex:none;min-width:0}._5KEEsG_contextColumn{width:100%;max-width:var(--dsh-chat-content-width,748px);min-width:0;margin-inline:auto}._5KEEsG_historyToggle{align-items:center;gap:6px;display:flex}._5KEEsG_contextHint{color:var(--dsw-alias-label-tertiary);font-size:12px}._5KEEsG_contextChevron{transform:rotate(-90deg)}._5KEEsG_contextChevron,._5KEEsG_contextChevronOpen{flex:none}._5KEEsG_progress{margin:12px 0;padding:4px 0;position:relative;container-type:inline-size}._5KEEsG_progressEntries{overscroll-behavior:contain;scrollbar-width:thin;overflow-anchor:none;max-height:min(240px,32vh);margin-inline-end:-16px;overflow:auto}._5KEEsG_progressContent{width:100cqw}._5KEEsG_progressEntries:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}._5KEEsG_progressDetail,._5KEEsG_contextBubble{white-space:pre-wrap}._5KEEsG_progressEntry,._5KEEsG_progressDetail{overflow-wrap:anywhere;font-size:14px;line-height:1.65}._5KEEsG_contextImage{border-radius:8px;max-width:100%;max-height:160px;margin:8px 0}._5KEEsG_progressEntry{margin:0 0 12px;display:flow-root}._5KEEsG_progressEntry:last-child{margin-bottom:0}._5KEEsG_progressProcess{color:var(--dsw-alias-label-tertiary);margin:8px 0;font-size:13px}._5KEEsG_progressProcess summary{cursor:pointer;border-radius:4px;align-items:center;gap:6px;min-height:24px;list-style:none;display:flex}._5KEEsG_progressProcess summary::-webkit-details-marker{display:none}._5KEEsG_progressProcess summary:hover{color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-interactive-bg-hover)}._5KEEsG_progressProcess summary>svg,._5KEEsG_progressProcess summary>span:not(._5KEEsG_progressPreview){flex:none}._5KEEsG_progressProcess summary>svg:last-child{margin-left:auto;transform:rotate(-90deg)}._5KEEsG_progressProcess[open] summary>svg:last-child{transform:none}._5KEEsG_progressPreview{white-space:nowrap;text-overflow:ellipsis;min-width:0;overflow:hidden}._5KEEsG_progressDetail{color:var(--dsw-alias-label-secondary);margin:6px 0 12px 20px}._5KEEsG_progressLatest{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-button-floating-fill);color:var(--dsw-alias-label-secondary);font:inherit;cursor:pointer;border-radius:16px;align-items:center;gap:4px;padding:5px 9px;font-size:12px;display:flex;position:absolute;bottom:4px;right:12px}._5KEEsG_progressLatest:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-button-floating-hover)}._5KEEsG_reflowAction{width:32px;height:32px;color:var(--dsw-alias-label-tertiary);cursor:pointer;background:0 0;border:0;border-radius:8px;flex:none;order:1;justify-content:center;align-items:center;margin-left:auto;padding:0;display:inline-flex}._5KEEsG_reflowAction:hover{color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-interactive-bg-hover)}._5KEEsG_reflowAction:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}._5KEEsG_reflowAction:disabled{cursor:default;color:var(--dsw-alias-state-business-primary);background:0 0}._5KEEsG_nativeToolbar{border-bottom:1px solid var(--dsw-alias-border-l1);justify-content:space-between;align-items:center;gap:8px;padding:8px 12px;display:flex}._5KEEsG_nativeToolbarActions{flex-wrap:wrap;align-items:center;gap:8px;display:flex}._5KEEsG_nativeAction,._5KEEsG_historyToggle{color:var(--dsw-alias-label-secondary);font:inherit;cursor:pointer;background:0 0;border:0;border-radius:6px;padding:4px 6px;font-size:13px}._5KEEsG_nativeAction:hover,._5KEEsG_nativeAction:focus-visible,._5KEEsG_historyToggle:hover,._5KEEsG_historyToggle:focus-visible{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}._5KEEsG_nativeAction:disabled{opacity:.5;cursor:default}._5KEEsG_historyToggle{margin:0;text-align:left;margin-inline-start:-6px}._5KEEsG_stateScreen{text-align:center;flex-direction:column;flex:1;justify-content:center;align-items:center;gap:8px;padding:24px 16px;display:flex}._5KEEsG_emptyIcon{color:var(--dsw-alias-label-tertiary)}._5KEEsG_emptyTitle{font-size:14px;font-weight:600}._5KEEsG_emptyText{color:var(--dsw-alias-label-secondary);max-width:280px;font-size:13px;line-height:1.6}._5KEEsG_stateDetail,._5KEEsG_errorRow{color:var(--dsw-alias-state-error-primary);overflow-wrap:anywhere;font-size:13px;line-height:1.6}._5KEEsG_errorRow{padding:8px 12px}._5KEEsG_headerSide{color:var(--dsw-alias-label-secondary);cursor:pointer;font:inherit;background:0 0;border:0;border-radius:6px;align-items:center;gap:4px;padding:4px 8px;display:inline-flex}._5KEEsG_headerSide:hover,._5KEEsG_headerSide:focus-visible{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}._5KEEsG_headerSide:disabled{opacity:.4;cursor:default}._5KEEsG_contextUserRow{flex-direction:column;align-items:flex-end;gap:8px;margin:16px 0 24px;display:flex}._5KEEsG_contextBubble{border-radius:var(--dsw-radius-xl);background:var(--dsw-specific-bubble);max-width:82%;color:var(--dsw-alias-label-primary);overflow-wrap:anywhere;padding:10px 16px;font-size:14px;line-height:1.65}";
2773
- const tagId$1 = "dsh-sidenote/sidechat.module.css";
2774
- if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
2841
+ const css$2 = "._5KEEsG_nativeHost,._5KEEsG_root,._5KEEsG_nativeConversation{flex-direction:column;min-height:0;display:flex}._5KEEsG_nativeHost,._5KEEsG_root{height:100%}._5KEEsG_root{color:var(--dsw-alias-label-primary)}._5KEEsG_nativeConversation{flex:1}._5KEEsG_chatView{flex-direction:column;flex:1 0 auto;min-width:0;display:flex}._5KEEsG_mainContext{box-sizing:border-box;width:100%;padding:12px calc(var(--dsh-composer-side-clearance,8px) + 16px) 4px;flex:none;min-width:0}._5KEEsG_contextColumn{width:100%;max-width:var(--dsh-chat-content-width,748px);min-width:0;margin-inline:auto}._5KEEsG_historyToggle{align-items:center;gap:6px;display:flex}._5KEEsG_contextHint{color:var(--dsw-alias-label-tertiary);font-size:12px}._5KEEsG_contextChevron{transform:rotate(-90deg)}._5KEEsG_contextChevron,._5KEEsG_contextChevronOpen{flex:none}._5KEEsG_progress{margin:12px 0;padding:4px 0;position:relative;container-type:inline-size}._5KEEsG_progressEntries{overscroll-behavior:contain;scrollbar-width:thin;overflow-anchor:none;max-height:min(240px,32vh);margin-inline-end:-16px;overflow:auto}._5KEEsG_progressContent{width:100cqw}._5KEEsG_progressEntries:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}._5KEEsG_progressDetail,._5KEEsG_contextBubble{white-space:pre-wrap}._5KEEsG_progressEntry,._5KEEsG_progressDetail{overflow-wrap:anywhere;font-size:14px;line-height:1.65}._5KEEsG_contextImage{border-radius:8px;max-width:100%;max-height:160px;margin:8px 0}._5KEEsG_progressEntry{margin:0 0 12px;display:flow-root}._5KEEsG_progressEntry:last-child{margin-bottom:0}._5KEEsG_progressProcess{color:var(--dsw-alias-label-tertiary);margin:8px 0;font-size:13px}._5KEEsG_progressProcess summary{cursor:pointer;border-radius:4px;align-items:center;gap:6px;min-height:24px;list-style:none;display:flex}._5KEEsG_progressProcess summary::-webkit-details-marker{display:none}._5KEEsG_progressProcess summary:hover{color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-interactive-bg-hover)}._5KEEsG_progressProcess summary>svg,._5KEEsG_progressProcess summary>span:not(._5KEEsG_progressPreview){flex:none}._5KEEsG_progressProcess summary>svg:last-child{margin-left:auto;transform:rotate(-90deg)}._5KEEsG_progressProcess[open] summary>svg:last-child{transform:none}._5KEEsG_progressPreview{white-space:nowrap;text-overflow:ellipsis;min-width:0;overflow:hidden}._5KEEsG_progressDetail{color:var(--dsw-alias-label-secondary);margin:6px 0 12px 20px}._5KEEsG_progressLatest{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-button-floating-fill);color:var(--dsw-alias-label-secondary);font:inherit;cursor:pointer;border-radius:16px;align-items:center;gap:4px;padding:5px 9px;font-size:12px;display:flex;position:absolute;bottom:4px;right:12px}._5KEEsG_progressLatest:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-button-floating-hover)}._5KEEsG_reflowAction{width:32px;height:32px;color:var(--dsw-alias-label-tertiary);cursor:pointer;background:0 0;border:0;border-radius:8px;flex:none;order:1;justify-content:center;align-items:center;margin-left:auto;padding:0;display:inline-flex}._5KEEsG_reflowAction:hover{color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-interactive-bg-hover)}._5KEEsG_reflowAction:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}._5KEEsG_reflowAction:disabled{cursor:default;color:var(--dsw-alias-state-business-primary);background:0 0}._5KEEsG_nativeToolbar{border-bottom:1px solid var(--dsw-alias-border-l1);justify-content:space-between;align-items:center;gap:8px;padding:8px 12px;display:flex}._5KEEsG_nativeToolbarActions{flex-wrap:wrap;align-items:center;gap:8px;display:flex}._5KEEsG_nativeAction,._5KEEsG_historyToggle{color:var(--dsw-alias-label-secondary);font:inherit;cursor:pointer;background:0 0;border:0;border-radius:6px;padding:4px 6px;font-size:13px}._5KEEsG_nativeAction:hover,._5KEEsG_nativeAction:focus-visible,._5KEEsG_historyToggle:hover,._5KEEsG_historyToggle:focus-visible{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}._5KEEsG_nativeAction:disabled{opacity:.5;cursor:default}._5KEEsG_historyToggle{margin:0;text-align:left;margin-inline-start:-6px}._5KEEsG_stateScreen{text-align:center;flex-direction:column;flex:1;justify-content:center;align-items:center;gap:8px;padding:24px 16px;display:flex}._5KEEsG_emptyIcon{color:var(--dsw-alias-label-tertiary)}._5KEEsG_emptyTitle{font-size:14px;font-weight:600}._5KEEsG_emptyText{color:var(--dsw-alias-label-secondary);max-width:280px;font-size:13px;line-height:1.6}._5KEEsG_stateDetail,._5KEEsG_errorRow{color:var(--dsw-alias-state-error-primary);overflow-wrap:anywhere;font-size:13px;line-height:1.6}._5KEEsG_errorRow{padding:8px 12px}._5KEEsG_headerSide{color:var(--dsw-alias-label-secondary);cursor:pointer;font:inherit;background:0 0;border:0;border-radius:6px;align-items:center;gap:4px;padding:4px 8px;display:inline-flex}._5KEEsG_headerSide:hover,._5KEEsG_headerSide:focus-visible{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}._5KEEsG_headerSide:disabled{opacity:.4;cursor:default}._5KEEsG_contextUserRow{flex-direction:column;align-items:flex-end;gap:8px;margin:16px 0 24px;display:flex}._5KEEsG_contextBubble{border-radius:var(--dsw-radius-xl);background:var(--dsw-specific-bubble);max-width:82%;color:var(--dsw-alias-label-primary);overflow-wrap:anywhere;padding:10px 16px;font-size:14px;line-height:1.65}";
2842
+ const tagId$2 = "dsh-sidenote/sidechat.module.css";
2843
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$2) + "]") === null) {
2775
2844
  const tag = document.createElement("style");
2776
2845
  tag.dataset.plugin = "dsh-sidenote";
2777
- tag.dataset.pluginCss = tagId$1;
2778
- tag.textContent = css$1;
2846
+ tag.dataset.pluginCss = tagId$2;
2847
+ tag.textContent = css$2;
2779
2848
  document.head.appendChild(tag);
2780
2849
  }
2781
2850
  var sidechat_module_css_default = {
2782
- "emptyTitle": "_5KEEsG_emptyTitle",
2783
- "contextChevron": "_5KEEsG_contextChevron",
2784
- "progressEntry": "_5KEEsG_progressEntry",
2785
- "stateDetail": "_5KEEsG_stateDetail",
2851
+ "contextColumn": "_5KEEsG_contextColumn",
2786
2852
  "progressDetail": "_5KEEsG_progressDetail",
2787
- "root": "_5KEEsG_root",
2788
- "emptyIcon": "_5KEEsG_emptyIcon",
2789
- "mainContext": "_5KEEsG_mainContext",
2790
- "contextHint": "_5KEEsG_contextHint",
2791
2853
  "progressPreview": "_5KEEsG_progressPreview",
2792
- "nativeToolbar": "_5KEEsG_nativeToolbar",
2854
+ "headerSide": "_5KEEsG_headerSide",
2855
+ "emptyTitle": "_5KEEsG_emptyTitle",
2793
2856
  "progressContent": "_5KEEsG_progressContent",
2857
+ "nativeToolbar": "_5KEEsG_nativeToolbar",
2858
+ "contextUserRow": "_5KEEsG_contextUserRow",
2859
+ "progress": "_5KEEsG_progress",
2794
2860
  "chatView": "_5KEEsG_chatView",
2795
- "contextImage": "_5KEEsG_contextImage",
2796
- "stateScreen": "_5KEEsG_stateScreen",
2797
- "headerSide": "_5KEEsG_headerSide",
2798
- "emptyText": "_5KEEsG_emptyText",
2799
- "nativeHost": "_5KEEsG_nativeHost",
2861
+ "contextChevron": "_5KEEsG_contextChevron",
2862
+ "nativeConversation": "_5KEEsG_nativeConversation",
2800
2863
  "contextBubble": "_5KEEsG_contextBubble",
2801
- "contextChevronOpen": "_5KEEsG_contextChevronOpen",
2802
- "nativeToolbarActions": "_5KEEsG_nativeToolbarActions",
2803
- "contextColumn": "_5KEEsG_contextColumn",
2864
+ "nativeHost": "_5KEEsG_nativeHost",
2804
2865
  "progressProcess": "_5KEEsG_progressProcess",
2866
+ "emptyIcon": "_5KEEsG_emptyIcon",
2867
+ "root": "_5KEEsG_root",
2868
+ "emptyText": "_5KEEsG_emptyText",
2869
+ "contextImage": "_5KEEsG_contextImage",
2870
+ "nativeToolbarActions": "_5KEEsG_nativeToolbarActions",
2871
+ "progressEntries": "_5KEEsG_progressEntries",
2872
+ "mainContext": "_5KEEsG_mainContext",
2873
+ "contextChevronOpen": "_5KEEsG_contextChevronOpen",
2874
+ "progressEntry": "_5KEEsG_progressEntry",
2875
+ "stateDetail": "_5KEEsG_stateDetail",
2805
2876
  "progressLatest": "_5KEEsG_progressLatest",
2806
2877
  "nativeAction": "_5KEEsG_nativeAction",
2807
- "historyToggle": "_5KEEsG_historyToggle",
2808
- "progress": "_5KEEsG_progress",
2809
2878
  "errorRow": "_5KEEsG_errorRow",
2810
- "contextUserRow": "_5KEEsG_contextUserRow",
2811
- "nativeConversation": "_5KEEsG_nativeConversation",
2812
- "progressEntries": "_5KEEsG_progressEntries",
2879
+ "contextHint": "_5KEEsG_contextHint",
2880
+ "historyToggle": "_5KEEsG_historyToggle",
2881
+ "stateScreen": "_5KEEsG_stateScreen",
2813
2882
  "reflowAction": "_5KEEsG_reflowAction"
2814
2883
  };
2815
2884
  //#endregion
@@ -2884,6 +2953,7 @@ window.__ModuleLoader__.load({
2884
2953
  "data-sidenote-quote-body": entry.messageKey ? "" : void 0,
2885
2954
  "data-sidenote-message-role": entry.messageKey ? "assistant" : void 0,
2886
2955
  "data-sidenote-message-key": entry.messageKey,
2956
+ "data-sidenote-turn": entry.turn === void 0 ? void 0 : `history:${entry.turn}`,
2887
2957
  "data-sidenote-streaming": live && unfinished ? "true" : "false",
2888
2958
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.MarkdownText, {
2889
2959
  text: entry.text,
@@ -3462,7 +3532,10 @@ ${body}
3462
3532
  return {
3463
3533
  ...entry,
3464
3534
  key,
3465
- ...node.kind === "assistant" && entry.kind === "reply" ? { messageKey: `a:${node.seq}` } : {},
3535
+ ...node.kind === "assistant" && entry.kind === "reply" ? {
3536
+ messageKey: `a:${node.seq}`,
3537
+ turn: node.turn
3538
+ } : {},
3466
3539
  ...node.kind !== "user" && node.kind !== "steering" && images.length && index === entries.length - 1 ? { images } : {}
3467
3540
  };
3468
3541
  });
@@ -6188,7 +6261,7 @@ ${body}
6188
6261
  /** Explicit side bodies are the sole exception to the legacy sidebar exclusion. */
6189
6262
  function quoteSourceOf(node, currentSessionId) {
6190
6263
  const element = elementOf(node);
6191
- if (element?.closest("button, [role=\"button\"], input, textarea, select, [contenteditable=\"true\"], [data-code-block-banner], [data-variant=\"think\"], [data-sidenote-no-quote]") !== null) return null;
6264
+ if (!element || element.closest(`button, [role="button"], input, textarea, select, [contenteditable="true"], [data-code-block-banner], [data-variant="think"], [data-chat-group-part="reasoning"], [data-sidenote-no-quote], [data-variant="think"], [data-chat-group-part="reasoning"], [data-chat-flow-kind="tool-call"], [data-chat-flow-kind="tool-result"], [data-chat-flow-kind="turn-process"], [data-context-kind="thinking"], [data-context-kind="tool"]`) !== null) return null;
6192
6265
  const body = element?.closest("[data-sidenote-quote-body]");
6193
6266
  if (body !== void 0 && body !== null) {
6194
6267
  const anchor = body.closest("[data-sidenote-message-key][data-sidenote-message-role=\"assistant\"]");
@@ -6202,6 +6275,7 @@ ${body}
6202
6275
  sessionId,
6203
6276
  surface: "side",
6204
6277
  key: anchor.dataset.sidenoteMessageKey,
6278
+ turn: body.dataset.sidenoteTurn ?? body.closest("[data-chat-turn]")?.dataset.chatTurn,
6205
6279
  streaming: body.dataset.sidenoteStreaming === "true"
6206
6280
  };
6207
6281
  }
@@ -6219,19 +6293,57 @@ ${body}
6219
6293
  return source.key;
6220
6294
  }
6221
6295
  function sourceBodies(sessionId, surface, anchorKey, currentSessionId) {
6222
- if (surface === "main") return mainAnchorBodies(sessionId, anchorKey, currentSessionId);
6223
- return [...document.querySelectorAll("[data-sidenote-quote-body]"), ...nativeAssistantBodies()].filter((body) => {
6296
+ return (surface === "main" ? mainAnchorBodies(sessionId, anchorKey, currentSessionId) : [...document.querySelectorAll("[data-sidenote-quote-body]"), ...nativeAssistantBodies().filter((body) => !body.querySelector("[data-sidenote-quote-body]"))]).filter((body) => {
6224
6297
  const source = quoteSourceOf(body, currentSessionId);
6225
- return source?.surface === "side" && source.sessionId === sessionId && sourceKey(source) === anchorKey;
6298
+ return source?.surface === surface && source.sessionId === sessionId && sourceKey(source) === anchorKey;
6226
6299
  });
6227
6300
  }
6301
+ /** Admit the complete visible selection, never silently drop process content. */
6302
+ function quoteSourcesOfRange(range, currentSessionId) {
6303
+ const root = range.commonAncestorContainer;
6304
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
6305
+ const sources = [];
6306
+ const seen = /* @__PURE__ */ new Set();
6307
+ for (let node = root.nodeType === Node.TEXT_NODE ? root : walker.nextNode(); node; node = walker.nextNode()) {
6308
+ if (!range.intersectsNode(node) || !quoteNodeVisible(node)) continue;
6309
+ const start = node === range.startContainer ? range.startOffset : 0;
6310
+ const end = node === range.endContainer ? range.endOffset : node.textContent.length;
6311
+ if (node.textContent.slice(start, end).trim() === "") continue;
6312
+ const element = elementOf(node);
6313
+ if (element.closest("[data-variant=\"think\"], [data-chat-group-part=\"reasoning\"], [data-chat-flow-kind=\"tool-call\"], [data-chat-flow-kind=\"tool-result\"], [data-chat-flow-kind=\"turn-process\"], [data-context-kind=\"thinking\"], [data-context-kind=\"tool\"]")) return null;
6314
+ if (element.closest("button, [role=\"button\"], input, textarea, select, [contenteditable=\"true\"], [data-code-block-banner], [data-variant=\"think\"], [data-chat-group-part=\"reasoning\"], [data-sidenote-no-quote]")) {
6315
+ const body = element.closest(`[data-sidenote-quote-body], ${MAIN_ASSISTANT}`);
6316
+ if (body && quoteSourceOf(body, currentSessionId)) continue;
6317
+ return null;
6318
+ }
6319
+ const source = quoteSourceOf(node, currentSessionId);
6320
+ if (!source || source.streaming) return null;
6321
+ const first = sources[0];
6322
+ if (first && (source.view !== first.view || source.sessionId !== first.sessionId || source.surface !== first.surface)) return null;
6323
+ if (seen.has(source.body)) continue;
6324
+ if (first && (!first.turn || source.turn !== first.turn || !first.key || !source.key)) return null;
6325
+ sources.push(source);
6326
+ seen.add(source.body);
6327
+ }
6328
+ return sources.length ? sources : null;
6329
+ }
6330
+ /** Trim each stored fragment to the actual selected text, excluding surrounding UI. */
6331
+ function quoteRangeOf(body, selection) {
6332
+ const nodes = quoteTextNodes(body).filter((node) => selection.intersectsNode(node) && (node !== selection.startContainer || selection.startOffset < node.length) && (node !== selection.endContainer || selection.endOffset > 0));
6333
+ const first = nodes[0], last = nodes.at(-1);
6334
+ if (!first || !last) return null;
6335
+ const range = document.createRange();
6336
+ range.setStart(first, first === selection.startContainer ? selection.startOffset : 0);
6337
+ range.setEnd(last, last === selection.endContainer ? selection.endOffset : last.length);
6338
+ return range;
6339
+ }
6228
6340
  /** The same text-node projection is used at capture and when rebuilding anchors.
6229
6341
  * Browser selections contain block newlines; anchor offsets deliberately do not. */
6230
6342
  function quoteTextNodes(body) {
6231
6343
  const walker = document.createTreeWalker(body, NodeFilter.SHOW_TEXT);
6232
6344
  const nodes = [];
6233
6345
  for (let node = walker.nextNode(); node; node = walker.nextNode()) {
6234
- if (node.parentElement?.closest("button, [role=\"button\"], input, textarea, select, [contenteditable=\"true\"], [data-code-block-banner], [data-variant=\"think\"], [data-sidenote-no-quote]") !== null) continue;
6346
+ if (node.parentElement?.closest(`button, [role="button"], input, textarea, select, [contenteditable="true"], [data-code-block-banner], [data-variant="think"], [data-chat-group-part="reasoning"], [data-sidenote-no-quote], [data-variant="think"], [data-chat-group-part="reasoning"], [data-chat-flow-kind="tool-call"], [data-chat-flow-kind="tool-result"], [data-chat-flow-kind="turn-process"], [data-context-kind="thinking"], [data-context-kind="tool"]`) !== null || !quoteNodeVisible(node)) continue;
6235
6347
  if (node.parentElement !== null && getComputedStyle(node.parentElement).userSelect === "none") continue;
6236
6348
  nodes.push(node);
6237
6349
  }
@@ -6248,7 +6360,7 @@ ${body}
6248
6360
  function selectedQuoteText(range, browserText, anchorText) {
6249
6361
  if (browserText.replace(/\s/g, "") === anchorText.replace(/\s/g, "")) return browserText;
6250
6362
  const fragment = range.cloneContents();
6251
- for (const element of fragment.querySelectorAll(NON_QUOTE)) element.remove();
6363
+ for (const element of fragment.querySelectorAll(`${NON_QUOTE}, ${PROCESS_UI}, [hidden], [data-turn-process-hidden], [data-turn-process-inline]`)) element.remove();
6252
6364
  const textOf = (node) => {
6253
6365
  if (node.nodeType === Node.TEXT_NODE) return node.textContent ?? "";
6254
6366
  if (node instanceof Element && node.tagName === "BR") return "\n";
@@ -6272,11 +6384,11 @@ ${body}
6272
6384
  * toolbar through a small external-store controller. Mirrors the
6273
6385
  * production-proven dsh-sidebar-qa contract, narrowed to assistant messages:
6274
6386
  *
6275
- * - both selection endpoints must sit in the SAME `[data-chat-flow-kind=
6276
- * "assistant-step"]` message node (跨消息划选不弹);
6387
+ * - completed reply bodies in one view and Turn may be selected together;
6388
+ * - selected visible process/tool UI invalidates the whole selection;
6277
6389
  * - `[data-streaming]` messages (still streaming) are excluded;
6278
6390
  * - explicit side assistant bodies are admitted; other sidebar/plugin UI is
6279
- * excluded; both endpoints belong to the same message and source view;
6391
+ * excluded; every selected reply belongs to the same source view;
6280
6392
  * - quote text is kept complete, while anchor offsets use one DOM projection.
6281
6393
  *
6282
6394
  * These are DSH-internal DOM attributes rather than a public contract — an
@@ -6308,24 +6420,38 @@ ${body}
6308
6420
  const sel = window.getSelection();
6309
6421
  if (sel === null || sel.isCollapsed || sel.rangeCount === 0) return null;
6310
6422
  const range = sel.getRangeAt(0);
6311
- const source = quoteSourceOf(range.startContainer, currentSessionId);
6312
- const end = quoteSourceOf(range.endContainer, currentSessionId);
6313
- if (source === null || end === null || source.body !== end.body || source.view !== end.view || source.streaming) return null;
6314
- const anchorText = projectedRangeText(source.body, range);
6423
+ const sources = quoteSourcesOfRange(range, currentSessionId);
6424
+ if (!sources) return null;
6425
+ const ranges = sources.map((source) => quoteRangeOf(source.body, range));
6426
+ if (ranges.some((fragment) => fragment === null)) return null;
6427
+ const fragments = ranges;
6428
+ const anchors = sources.map((source, index) => {
6429
+ const anchorText = projectedRangeText(source.body, fragments[index]);
6430
+ return {
6431
+ anchorKey: sourceKey(source),
6432
+ anchorText,
6433
+ occurrence: occurrenceOf(source.body, fragments[index], anchorText)
6434
+ };
6435
+ });
6436
+ const source = sources[0];
6437
+ const anchorText = anchors.map((anchor) => anchor.anchorText).join("");
6315
6438
  if (anchorText.trim() === "") return null;
6316
- const text = selectedQuoteText(range, sel.toString(), anchorText);
6439
+ const browserText = sel.toString();
6440
+ const text = browserText.replace(/\s/g, "") === anchorText.replace(/\s/g, "") ? browserText : fragments.map((fragment, index) => selectedQuoteText(fragment, fragment.toString(), anchors[index].anchorText)).join("\n\n");
6317
6441
  const rect = range.getBoundingClientRect();
6318
6442
  return {
6319
6443
  text,
6320
6444
  anchorText,
6321
6445
  anchorKey: sourceKey(source),
6322
- occurrence: occurrenceOf(source.body, range, anchorText),
6446
+ occurrence: anchors[0].occurrence,
6447
+ ...anchors.length > 1 ? { anchors } : {},
6323
6448
  rect: {
6324
6449
  left: rect.left,
6325
6450
  top: rect.top,
6326
6451
  width: rect.width
6327
6452
  },
6328
6453
  range: range.cloneRange(),
6454
+ ranges: fragments,
6329
6455
  sessionId: source.sessionId,
6330
6456
  source
6331
6457
  };
@@ -6349,7 +6475,7 @@ ${body}
6349
6475
  } catch {
6350
6476
  next = null;
6351
6477
  }
6352
- if (!(selection === null !== (next === null) || selection !== null && next !== null && (selection.anchorText !== next.anchorText || selection.anchorKey !== next.anchorKey || selection.sessionId !== next.sessionId || selection.source.view !== next.source.view || selection.source.surface !== next.source.surface || selection.rect.top !== next.rect.top || selection.rect.left !== next.rect.left || selection.rect.width !== next.rect.width))) return;
6478
+ if (!(selection === null !== (next === null) || selection !== null && next !== null && (selection.anchorText !== next.anchorText || selection.anchorKey !== next.anchorKey || selection.occurrence !== next.occurrence || JSON.stringify(selection.anchors) !== JSON.stringify(next.anchors) || selection.sessionId !== next.sessionId || selection.source.view !== next.source.view || selection.source.surface !== next.source.surface || selection.rect.top !== next.rect.top || selection.rect.left !== next.rect.left || selection.rect.width !== next.rect.width))) return;
6353
6479
  selection = next;
6354
6480
  notify();
6355
6481
  };
@@ -6428,31 +6554,41 @@ ${body}
6428
6554
  range.setEnd(endNode, endOffset);
6429
6555
  return range;
6430
6556
  }
6431
- function resolveRange(annotation, cache, currentSessionId = "") {
6557
+ function resolveRanges(annotation, cache, currentSessionId = "") {
6432
6558
  try {
6433
6559
  const sessionId = annotation.sourceSessionId ?? annotation.sessionId;
6434
6560
  const surface = annotation.sourceSurface ?? "main";
6435
- const valid = (range, view) => {
6561
+ const anchors = annotation.anchors ?? [annotation];
6562
+ const valid = (ranges, view) => ranges.length === anchors.length && ranges.every((range, index) => {
6436
6563
  if (!range.startContainer.isConnected || !range.endContainer.isConnected) return false;
6437
- const source = quoteSourceOf(range.startContainer, currentSessionId);
6438
- const end = quoteSourceOf(range.endContainer, currentSessionId);
6439
- return source !== null && end?.body === source.body && source.view === view && source.sessionId === sessionId && source.surface === surface && sourceKey(source) === annotation.anchorKey && !source.streaming && projectedRangeText(source.body, range) === annotation.anchorText;
6440
- };
6564
+ const sources = quoteSourcesOfRange(range, currentSessionId);
6565
+ const source = sources?.[0];
6566
+ const anchor = anchors[index];
6567
+ return sources?.length === 1 && source !== void 0 && source.view === view && source.sessionId === sessionId && source.surface === surface && sourceKey(source) === anchor.anchorKey && projectedRangeText(source.body, range) === anchor.anchorText;
6568
+ });
6441
6569
  const cached = cache.get(annotation.id);
6442
- if (cached !== void 0 && valid(cached.range, cached.view)) return cached.range;
6570
+ if (cached !== void 0 && valid(cached.ranges, cached.view)) return cached.ranges;
6443
6571
  cache.delete(annotation.id);
6444
- if (annotation.anchorKey === void 0 || annotation.anchorText === "") return null;
6445
- const bodies = sourceBodies(sessionId, surface, annotation.anchorKey, currentSessionId).filter((body) => body.getClientRects().length > 0);
6446
- if (bodies.length !== 1) return null;
6447
- const body = bodies[0];
6448
- const source = quoteSourceOf(body, currentSessionId);
6449
- if (source === null || source.streaming) return null;
6450
- const range = rangeOfOccurrence(body, annotation.anchorText, annotation.occurrence);
6451
- if (range !== null) cache.set(annotation.id, {
6452
- range,
6453
- view: source.view
6572
+ const ranges = [];
6573
+ let view;
6574
+ for (const anchor of anchors) {
6575
+ if (!anchor.anchorKey || !anchor.anchorText) return null;
6576
+ const bodies = sourceBodies(sessionId, surface, anchor.anchorKey, currentSessionId).filter((body) => body.getClientRects().length > 0);
6577
+ if (bodies.length !== 1) return null;
6578
+ const body = bodies[0];
6579
+ const source = quoteSourceOf(body, currentSessionId);
6580
+ if (!source || view && source.view !== view) return null;
6581
+ view = source.view;
6582
+ const range = rangeOfOccurrence(body, anchor.anchorText, anchor.occurrence);
6583
+ if (!range) return null;
6584
+ ranges.push(range);
6585
+ }
6586
+ if (!view || !valid(ranges, view)) return null;
6587
+ cache.set(annotation.id, {
6588
+ ranges,
6589
+ view
6454
6590
  });
6455
- return range;
6591
+ return ranges;
6456
6592
  } catch {
6457
6593
  return null;
6458
6594
  }
@@ -6538,44 +6674,45 @@ ${body}
6538
6674
  }
6539
6675
  //#endregion
6540
6676
  //#region \0dsh-css:/home/runner/work/dsh-sidenote/dsh-sidenote/src/client/annotate/annotate.module.css.mjs
6541
- const css = "._SVViG_toolbar{z-index:50;background:var(--dsw-alias-bg-layer-1,#fff);border:1px solid var(--dsw-alias-border-l1,#00000014);user-select:none;border-radius:10px;align-items:stretch;display:flex;position:fixed;overflow:hidden;transform:translate(-50%,-100%);box-shadow:0 4px 16px #0000001f}._SVViG_toolbarBelow{transform:translate(-50%)}._SVViG_toolbarButton{appearance:none;color:var(--dsw-alias-label-primary,#1f2329);cursor:pointer;white-space:nowrap;background:0 0;border:none;padding:7px 12px;font-size:13px;line-height:20px}._SVViG_toolbarButton+._SVViG_toolbarButton{border-left:1px solid var(--dsw-alias-border-l1,#00000014)}._SVViG_toolbarButton:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000d)}._SVViG_badge{z-index:50;color:#fff;text-align:center;cursor:pointer;user-select:none;background:#2f88ff;border:none;border-radius:999px;width:18px;height:18px;padding:0;font-size:11px;font-weight:600;line-height:18px;position:fixed;transform:translateY(-50%);box-shadow:0 1px 4px #2f88ff73}._SVViG_badge:hover{background:#1f78f0}._SVViG_highlight{z-index:49;pointer-events:none;background:#2f88ff38;border-radius:2px;position:fixed}._SVViG_editorNew{z-index:50;background:var(--dsw-alias-bg-layer-1,#fff);border:1px solid var(--dsw-alias-border-l1,#00000014);border-radius:999px;align-items:center;gap:8px;padding:6px 8px 6px 12px;display:flex;position:fixed;box-shadow:0 6px 24px #00000024}._SVViG_editorEdit{z-index:50;background:var(--dsw-alias-bg-layer-1,#fff);border:1px solid var(--dsw-alias-border-l1,#00000014);border-radius:14px;flex-direction:column;display:flex;position:fixed;overflow:hidden;box-shadow:0 8px 28px #00000029}._SVViG_editorInput{min-width:0;color:var(--dsw-alias-label-primary,#1f2329);background:0 0;border:none;outline:none;flex:auto;font-size:13px;line-height:22px}._SVViG_editorTextarea{resize:none;color:var(--dsw-alias-label-primary,#1f2329);background:0 0;border:none;outline:none;padding:10px 12px 4px;font-family:inherit;font-size:13px;line-height:20px}._SVViG_editorInput::placeholder,._SVViG_editorTextarea::placeholder{color:var(--dsw-alias-label-caption,#8f959e)}._SVViG_editorAsk{z-index:50;background:var(--dsw-alias-bg-layer-1,#fff);border:1px solid var(--dsw-alias-border-l1,#00000014);border-radius:14px;flex-direction:column;gap:2px;padding:6px 8px 6px 12px;display:flex;position:fixed;box-shadow:0 6px 24px #00000024}._SVViG_editorAskRow{align-items:center;gap:8px;display:flex}._SVViG_editorTarget{color:var(--dsw-alias-label-caption,#8f959e);user-select:none;padding:2px 2px 0;font-size:11px;line-height:16px}._SVViG_confirmButton{color:#fff;cursor:pointer;background:#1f2329;border:none;border-radius:999px;flex:none;place-items:center;width:26px;height:26px;padding:0;display:grid}._SVViG_confirmButton:hover{background:#000}._SVViG_editorFooter{align-items:center;gap:8px;padding:6px 10px 8px;display:flex}._SVViG_editorSpacer{flex:auto}._SVViG_deleteButton{width:26px;height:26px;color:var(--dsw-alias-label-tertiary,#8f959e);cursor:pointer;background:0 0;border:none;border-radius:999px;place-items:center;padding:0;display:grid}._SVViG_deleteButton:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000d);color:var(--dsw-alias-state-error-primary,#d53f3f)}._SVViG_cancelButton,._SVViG_saveButton{cursor:pointer;border:none;border-radius:999px;padding:4px 14px;font-size:13px;line-height:20px}._SVViG_cancelButton{background:var(--dsw-alias-interactive-bg-hover,#0000000d);color:var(--dsw-alias-label-primary,#1f2329)}._SVViG_saveButton{color:#fff;background:#1f2329}._SVViG_saveButton:hover{background:#000}._SVViG_editorError{color:#e5484d;white-space:nowrap;font-size:12px;position:absolute;top:calc(100% + 4px);left:12px}._SVViG_badgeSent{background:var(--dsw-alias-label-caption,#8f959e);box-shadow:none;opacity:.75}._SVViG_badgeSent:hover{background:var(--dsw-alias-label-tertiary,#6b7075)}._SVViG_sentChip{border:1px solid var(--dsw-alias-border-l1,#0000001a);background:var(--dsw-alias-interactive-bg-hover,#0000000d);color:var(--dsw-alias-label-secondary,#3f454d);cursor:default;user-select:none;border-radius:999px;align-items:center;gap:4px;margin:0 0 6px;padding:1px 10px;font-size:12px;line-height:18px;display:inline-flex}._SVViG_sentCardTitle{color:var(--dsw-alias-label-tertiary,#8f959e);padding:2px 12px 0;font-size:12px;font-weight:600}._SVViG_sentCardQuote{color:var(--dsw-alias-label-secondary,#3f454d);border-left:2px solid var(--dsw-alias-border-l1,#0000001f);word-break:break-word;margin:4px 12px 0;padding:4px 12px;font-size:13px;line-height:20px}._SVViG_sentCardNote{color:var(--dsw-alias-label-primary,#1f2329);word-break:break-word;padding:4px 12px 10px;font-size:13px;line-height:20px}._SVViG_hint{z-index:50;background:var(--dsw-alias-bg-layer-1,#fff);border:1px solid var(--dsw-alias-border-l1,#00000014);max-width:320px;color:var(--dsw-alias-label-secondary,#3f454d);border-radius:12px;align-items:center;gap:10px;padding:10px 12px;font-size:12px;line-height:18px;animation:.25s ease-out _SVViG_dshSidenoteHintIn;display:flex;position:fixed;bottom:160px;right:24px;box-shadow:0 8px 28px #00000024}._SVViG_hintClose{width:20px;height:20px;color:var(--dsw-alias-label-tertiary,#8f959e);cursor:pointer;background:0 0;border:none;border-radius:999px;flex:none;place-items:center;padding:0;font-size:14px;line-height:1;display:grid}._SVViG_hintClose:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000d);color:var(--dsw-alias-label-primary,#1f2329)}@keyframes _SVViG_dshSidenoteHintIn{0%{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}._SVViG_sentChipRow{align-items:center;gap:6px;margin:0 0 6px;display:inline-flex}._SVViG_badgeSent{background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-tertiary,#8f959e);border:1.5px solid var(--dsw-alias-label-caption,#b0b5bb);box-shadow:none;opacity:1;line-height:15px}._SVViG_badgeSent:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000a);color:var(--dsw-alias-label-secondary,#3f454d)}._SVViG_hint{background:color-mix(in srgb, var(--dsw-alias-bg-layer-1,#fff) 88%, transparent);backdrop-filter:blur(8px);bottom:130px}";
6542
- const tagId = "dsh-sidenote/annotate.module.css";
6543
- if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
6677
+ const css$1 = "._SVViG_toolbar{z-index:50;background:var(--dsw-alias-bg-layer-1,#fff);border:1px solid var(--dsw-alias-border-l1,#00000014);user-select:none;border-radius:10px;flex-wrap:wrap;align-items:stretch;width:max-content;display:flex;position:fixed;overflow:hidden;transform:translate(-50%,-100%);box-shadow:0 4px 16px #0000001f}._SVViG_toolbarBelow{transform:translate(-50%)}._SVViG_toolbarButton{appearance:none;color:var(--dsw-alias-label-primary,#1f2329);cursor:pointer;white-space:nowrap;background:0 0;border:none;padding:7px 12px;font-size:13px;line-height:20px}._SVViG_toolbarButton+._SVViG_toolbarButton{border-left:1px solid var(--dsw-alias-border-l1,#00000014)}._SVViG_toolbarButton:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000d)}._SVViG_toolbarButton:focus-visible{outline-offset:-3px;outline:2px solid #2f88ff}._SVViG_toolbarStatus{color:var(--dsw-alias-label-secondary,#646a73);flex-basis:100%;padding:6px 12px;font-size:12px;line-height:18px}._SVViG_badge{z-index:50;color:#fff;text-align:center;cursor:pointer;user-select:none;background:#2f88ff;border:none;border-radius:999px;width:18px;height:18px;padding:0;font-size:11px;font-weight:600;line-height:18px;position:fixed;transform:translateY(-50%);box-shadow:0 1px 4px #2f88ff73}._SVViG_badge:hover{background:#1f78f0}._SVViG_highlight{z-index:49;pointer-events:none;background:#2f88ff38;border-radius:2px;position:fixed}._SVViG_editorNew{z-index:50;background:var(--dsw-alias-bg-layer-1,#fff);border:1px solid var(--dsw-alias-border-l1,#00000014);border-radius:18px;align-items:center;gap:8px;padding:6px 8px 6px 12px;display:flex;position:fixed;box-shadow:0 6px 24px #00000024}._SVViG_editorEdit{z-index:50;background:var(--dsw-alias-bg-layer-1,#fff);border:1px solid var(--dsw-alias-border-l1,#00000014);border-radius:14px;flex-direction:column;display:flex;position:fixed;overflow:hidden;box-shadow:0 8px 28px #00000029}._SVViG_editorInput{resize:none;min-width:0;min-height:21px;max-height:110px;color:var(--dsw-alias-label-primary,#1f2329);background:0 0;border:none;outline:none;flex:auto;padding:0;font-family:inherit;font-size:13px;line-height:22px;overflow-y:auto}._SVViG_editorTextarea{resize:none;color:var(--dsw-alias-label-primary,#1f2329);background:0 0;border:none;outline:none;padding:10px 12px 4px;font-family:inherit;font-size:13px;line-height:20px}._SVViG_editorInput::placeholder,._SVViG_editorTextarea::placeholder{color:var(--dsw-alias-label-caption,#8f959e)}._SVViG_editorAsk{z-index:50;background:var(--dsw-alias-bg-layer-1,#fff);border:1px solid var(--dsw-alias-border-l1,#00000014);border-radius:14px;flex-direction:column;gap:2px;padding:6px 8px 6px 12px;display:flex;position:fixed;box-shadow:0 6px 24px #00000024}._SVViG_editorAskRow{align-items:center;gap:8px;display:flex}._SVViG_editorTarget{color:var(--dsw-alias-label-caption,#8f959e);user-select:none;padding:2px 2px 0;font-size:11px;line-height:16px}._SVViG_confirmButton{color:#fff;cursor:pointer;background:#1f2329;border:none;border-radius:999px;flex:none;place-items:center;width:26px;height:26px;padding:0;display:grid}._SVViG_confirmButton:hover{background:#000}._SVViG_editorFooter{align-items:center;gap:8px;padding:6px 10px 8px;display:flex}._SVViG_editorSpacer{flex:auto}._SVViG_deleteButton{width:26px;height:26px;color:var(--dsw-alias-label-tertiary,#8f959e);cursor:pointer;background:0 0;border:none;border-radius:999px;place-items:center;padding:0;display:grid}._SVViG_deleteButton:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000d);color:var(--dsw-alias-state-error-primary,#d53f3f)}._SVViG_cancelButton,._SVViG_saveButton{cursor:pointer;border:none;border-radius:999px;padding:4px 14px;font-size:13px;line-height:20px}._SVViG_cancelButton{background:var(--dsw-alias-interactive-bg-hover,#0000000d);color:var(--dsw-alias-label-primary,#1f2329)}._SVViG_saveButton{color:#fff;background:#1f2329}._SVViG_saveButton:hover{background:#000}._SVViG_editorError{color:#e5484d;white-space:normal;overflow-wrap:anywhere;padding:2px 2px 0;font-size:12px}._SVViG_badgeSent{background:var(--dsw-alias-label-caption,#8f959e);box-shadow:none;opacity:.75}._SVViG_badgeSent:hover{background:var(--dsw-alias-label-tertiary,#6b7075)}._SVViG_sentChip{border:1px solid var(--dsw-alias-border-l1,#0000001a);background:var(--dsw-alias-interactive-bg-hover,#0000000d);color:var(--dsw-alias-label-secondary,#3f454d);cursor:default;user-select:none;border-radius:999px;align-items:center;gap:4px;margin:0 0 6px;padding:1px 10px;font-size:12px;line-height:18px;display:inline-flex}._SVViG_sentCardTitle{color:var(--dsw-alias-label-tertiary,#8f959e);padding:2px 12px 0;font-size:12px;font-weight:600}._SVViG_sentCardQuote{color:var(--dsw-alias-label-secondary,#3f454d);border-left:2px solid var(--dsw-alias-border-l1,#0000001f);word-break:break-word;margin:4px 12px 0;padding:4px 12px;font-size:13px;line-height:20px}._SVViG_sentCardNote{color:var(--dsw-alias-label-primary,#1f2329);word-break:break-word;padding:4px 12px 10px;font-size:13px;line-height:20px}._SVViG_hint{z-index:50;background:var(--dsw-alias-bg-layer-1,#fff);border:1px solid var(--dsw-alias-border-l1,#00000014);max-width:320px;color:var(--dsw-alias-label-secondary,#3f454d);border-radius:12px;align-items:center;gap:10px;padding:10px 12px;font-size:12px;line-height:18px;animation:.25s ease-out _SVViG_dshSidenoteHintIn;display:flex;position:fixed;bottom:160px;right:24px;box-shadow:0 8px 28px #00000024}._SVViG_hintClose{width:20px;height:20px;color:var(--dsw-alias-label-tertiary,#8f959e);cursor:pointer;background:0 0;border:none;border-radius:999px;flex:none;place-items:center;padding:0;font-size:14px;line-height:1;display:grid}._SVViG_hintClose:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000d);color:var(--dsw-alias-label-primary,#1f2329)}@keyframes _SVViG_dshSidenoteHintIn{0%{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}._SVViG_sentChipRow{align-items:center;gap:6px;margin:0 0 6px;display:inline-flex}._SVViG_badgeSent{background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-tertiary,#8f959e);border:1.5px solid var(--dsw-alias-label-caption,#b0b5bb);box-shadow:none;opacity:1;line-height:15px}._SVViG_badgeSent:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000a);color:var(--dsw-alias-label-secondary,#3f454d)}._SVViG_hint{background:color-mix(in srgb, var(--dsw-alias-bg-layer-1,#fff) 88%, transparent);backdrop-filter:blur(8px);bottom:130px}";
6678
+ const tagId$1 = "dsh-sidenote/annotate.module.css";
6679
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
6544
6680
  const tag = document.createElement("style");
6545
6681
  tag.dataset.plugin = "dsh-sidenote";
6546
- tag.dataset.pluginCss = tagId;
6547
- tag.textContent = css;
6682
+ tag.dataset.pluginCss = tagId$1;
6683
+ tag.textContent = css$1;
6548
6684
  document.head.appendChild(tag);
6549
6685
  }
6550
6686
  var annotate_module_css_default = {
6551
- "hint": "_SVViG_hint",
6687
+ "saveButton": "_SVViG_saveButton",
6552
6688
  "hintClose": "_SVViG_hintClose",
6553
- "editorEdit": "_SVViG_editorEdit",
6554
6689
  "badgeSent": "_SVViG_badgeSent",
6555
- "sentCardTitle": "_SVViG_sentCardTitle",
6556
- "editorFooter": "_SVViG_editorFooter",
6557
- "toolbar": "_SVViG_toolbar",
6558
- "toolbarButton": "_SVViG_toolbarButton",
6559
- "toolbarBelow": "_SVViG_toolbarBelow",
6690
+ "deleteButton": "_SVViG_deleteButton",
6560
6691
  "highlight": "_SVViG_highlight",
6561
- "editorNew": "_SVViG_editorNew",
6562
- "editorAsk": "_SVViG_editorAsk",
6692
+ "confirmButton": "_SVViG_confirmButton",
6693
+ "editorFooter": "_SVViG_editorFooter",
6563
6694
  "editorAskRow": "_SVViG_editorAskRow",
6695
+ "sentCardNote": "_SVViG_sentCardNote",
6564
6696
  "cancelButton": "_SVViG_cancelButton",
6565
- "sentChip": "_SVViG_sentChip",
6697
+ "toolbarBelow": "_SVViG_toolbarBelow",
6698
+ "sentChipRow": "_SVViG_sentChipRow",
6566
6699
  "editorInput": "_SVViG_editorInput",
6700
+ "toolbar": "_SVViG_toolbar",
6701
+ "editorAsk": "_SVViG_editorAsk",
6702
+ "editorError": "_SVViG_editorError",
6703
+ "sentCardTitle": "_SVViG_sentCardTitle",
6704
+ "editorTextarea": "_SVViG_editorTextarea",
6705
+ "dshSidenoteHintIn": "_SVViG_dshSidenoteHintIn",
6567
6706
  "editorTarget": "_SVViG_editorTarget",
6568
- "confirmButton": "_SVViG_confirmButton",
6569
- "saveButton": "_SVViG_saveButton",
6570
- "deleteButton": "_SVViG_deleteButton",
6571
- "editorSpacer": "_SVViG_editorSpacer",
6707
+ "sentChip": "_SVViG_sentChip",
6572
6708
  "sentCardQuote": "_SVViG_sentCardQuote",
6573
- "dshSidenoteHintIn": "_SVViG_dshSidenoteHintIn",
6709
+ "editorEdit": "_SVViG_editorEdit",
6710
+ "editorSpacer": "_SVViG_editorSpacer",
6711
+ "hint": "_SVViG_hint",
6712
+ "toolbarStatus": "_SVViG_toolbarStatus",
6713
+ "editorNew": "_SVViG_editorNew",
6574
6714
  "badge": "_SVViG_badge",
6575
- "sentCardNote": "_SVViG_sentCardNote",
6576
- "editorError": "_SVViG_editorError",
6577
- "sentChipRow": "_SVViG_sentChipRow",
6578
- "editorTextarea": "_SVViG_editorTextarea"
6715
+ "toolbarButton": "_SVViG_toolbarButton"
6579
6716
  };
6580
6717
  //#endregion
6581
6718
  //#region src/client/annotate/hint.tsx
@@ -6654,6 +6791,97 @@ ${body}
6654
6791
  }
6655
6792
  };
6656
6793
  //#endregion
6794
+ //#region src/client/annotate/SelectionToolbar.tsx
6795
+ /** Preserve Sidenote's selection surface while admitting the host quote action. */
6796
+ function SelectionToolbar(props) {
6797
+ useLocaleTick();
6798
+ const root = (0, react.useRef)(null);
6799
+ const [failed, setFailed] = (0, react.useState)(false);
6800
+ (0, react.useLayoutEffect)(() => {
6801
+ const toolbar = root.current;
6802
+ if (toolbar === null) return;
6803
+ const place = () => {
6804
+ const rect = props.snapshot.range.getBoundingClientRect();
6805
+ const clip = sourceClip(props.snapshot.source);
6806
+ toolbar.style.maxWidth = `${Math.max(0, clip.right - clip.left - 16)}px`;
6807
+ const { width, height } = toolbar.getBoundingClientRect();
6808
+ const left = Math.max(clip.left + width / 2 + 8, Math.min(clip.right - width / 2 - 8, rect.left + rect.width / 2));
6809
+ const below = rect.top < clip.top + Math.max(64, height + 10);
6810
+ toolbar.style.left = `${left}px`;
6811
+ toolbar.style.top = `${below ? Math.max(clip.top + 4, Math.min(clip.bottom - height - 8, rect.bottom + 10)) : rect.top - 10}px`;
6812
+ toolbar.classList.toggle(annotate_module_css_default.toolbarBelow, below);
6813
+ toolbar.style.visibility = rect.bottom > clip.top && rect.top < clip.bottom ? "visible" : "hidden";
6814
+ };
6815
+ place();
6816
+ const observer = new ResizeObserver(place);
6817
+ observer.observe(toolbar);
6818
+ return () => {
6819
+ observer.disconnect();
6820
+ };
6821
+ });
6822
+ if (!props.snapshot.source.body.isConnected || props.snapshot.range.getClientRects().length === 0) return null;
6823
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6824
+ ref: root,
6825
+ className: annotate_module_css_default.toolbar,
6826
+ role: "toolbar",
6827
+ "aria-label": t("toolbarAria"),
6828
+ children: [
6829
+ props.onQuote && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
6830
+ type: "button",
6831
+ className: annotate_module_css_default.toolbarButton,
6832
+ title: t("nativeQuoteHint"),
6833
+ onMouseDown: (event) => {
6834
+ event.preventDefault();
6835
+ },
6836
+ onClick: (event) => {
6837
+ event.preventDefault();
6838
+ event.stopPropagation();
6839
+ setFailed(!props.onQuote());
6840
+ },
6841
+ children: t("nativeQuote")
6842
+ }),
6843
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
6844
+ type: "button",
6845
+ className: annotate_module_css_default.toolbarButton,
6846
+ disabled: !props.addAvailable,
6847
+ title: !props.addAvailable ? t("quoteWorkflowWaiting") : void 0,
6848
+ onMouseDown: (event) => {
6849
+ event.preventDefault();
6850
+ },
6851
+ onClick: (event) => {
6852
+ event.preventDefault();
6853
+ event.stopPropagation();
6854
+ props.onAdd();
6855
+ },
6856
+ children: t("addToConversation")
6857
+ }),
6858
+ props.sideChatAvailable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
6859
+ type: "button",
6860
+ className: annotate_module_css_default.toolbarButton,
6861
+ onMouseDown: (event) => {
6862
+ event.preventDefault();
6863
+ },
6864
+ onClick: (event) => {
6865
+ event.preventDefault();
6866
+ event.stopPropagation();
6867
+ props.onAsk();
6868
+ },
6869
+ children: t("askInSideChat")
6870
+ }),
6871
+ !props.addAvailable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6872
+ className: annotate_module_css_default.toolbarStatus,
6873
+ role: "status",
6874
+ children: t("quoteWorkflowWaiting")
6875
+ }),
6876
+ failed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6877
+ className: annotate_module_css_default.toolbarStatus,
6878
+ role: "alert",
6879
+ children: t("nativeQuoteFailed")
6880
+ })
6881
+ ]
6882
+ });
6883
+ }
6884
+ //#endregion
6657
6885
  //#region src/client/annotate/overlay.tsx
6658
6886
  /**
6659
6887
  * The annotation overlay (Workitem 02): an independent React root appended to
@@ -6669,6 +6897,17 @@ ${body}
6669
6897
  * so the selection survives until the click commits) and failure-safe (an
6670
6898
  * error boundary around the tree; layout math is wrapped in anchor.ts).
6671
6899
  */
6900
+ /** 两种新建注解入口共用紧凑的多行输入高度。 */
6901
+ function useAutoGrowingNote(note) {
6902
+ const input = (0, react.useRef)(null);
6903
+ (0, react.useLayoutEffect)(() => {
6904
+ const element = input.current;
6905
+ if (!element) return;
6906
+ element.style.height = "auto";
6907
+ element.style.height = `${Math.min(element.scrollHeight, 110)}px`;
6908
+ }, [note]);
6909
+ return input;
6910
+ }
6672
6911
  /** Badge anchor of a freshly captured selection (editor placement on create). */
6673
6912
  function selectionBadgePoint(snapshot) {
6674
6913
  const anchor = badgeAnchorOf(snapshot.range);
@@ -6687,8 +6926,9 @@ ${body}
6687
6926
  function AnnotateOverlay(props) {
6688
6927
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AnnotationBoundary, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AnnotateOverlayInner, { ...props }) });
6689
6928
  }
6690
- function AnnotateOverlayInner({ ctx, store, controller }) {
6929
+ function AnnotateOverlayInner({ ctx, store, controller, preferences }) {
6691
6930
  useLocaleTick();
6931
+ const preference = (0, react.useSyncExternalStore)(preferences.subscribe, preferences.getSnapshot);
6692
6932
  const diagnostics = hostDiagnostics(ctx);
6693
6933
  (0, react.useSyncExternalStore)(diagnostics.subscribe, diagnostics.getSnapshot);
6694
6934
  const selectionState = (0, react.useSyncExternalStore)((0, react.useCallback)((cb) => controller.subscribe(cb), [controller]), () => controller.getSnapshot());
@@ -6746,6 +6986,7 @@ ${body}
6746
6986
  };
6747
6987
  }, []);
6748
6988
  const selection = selectionState.selection;
6989
+ const nativeQuoteAvailable = selection !== null && !preference.hidden && typeof resolveInput(ctx, selection.sessionId)?.insertQuote === "function";
6749
6990
  const addToConversation = (snapshot) => {
6750
6991
  const anchor = selectionBadgePoint(snapshot);
6751
6992
  const annotation = store.add({
@@ -6756,11 +6997,11 @@ ${body}
6756
6997
  text: snapshot.text,
6757
6998
  anchorText: snapshot.anchorText,
6758
6999
  occurrence: snapshot.occurrence,
7000
+ anchors: snapshot.anchors,
6759
7001
  note: ""
6760
7002
  });
6761
- const cached = snapshot.range.cloneRange();
6762
7003
  rangeCache.current.set(annotation.id, {
6763
- range: cached,
7004
+ ranges: snapshot.ranges.map((range) => range.cloneRange()),
6764
7005
  view: snapshot.source.view
6765
7006
  });
6766
7007
  setEditor({
@@ -6804,10 +7045,11 @@ ${body}
6804
7045
  text: snapshot.text,
6805
7046
  anchorText: snapshot.anchorText,
6806
7047
  occurrence: snapshot.occurrence,
7048
+ anchors: snapshot.anchors,
6807
7049
  note
6808
7050
  });
6809
7051
  rangeCache.current.set(annotation.id, {
6810
- range: snapshot.range.cloneRange(),
7052
+ ranges: snapshot.ranges.map((range) => range.cloneRange()),
6811
7053
  view: snapshot.source.view
6812
7054
  });
6813
7055
  setSideDraft((current) => current === sideDraft ? null : current);
@@ -6839,6 +7081,12 @@ ${body}
6839
7081
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FirstUseHint, {}),
6840
7082
  selection !== null && editor === null && sideDraft === null && viewer === null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectionToolbar, {
6841
7083
  snapshot: selection,
7084
+ onQuote: nativeQuoteAvailable ? () => {
7085
+ if (!insertNativeQuote(ctx, selection.sessionId, selection.text)) return false;
7086
+ controller.clear();
7087
+ window.getSelection()?.removeAllRanges();
7088
+ return true;
7089
+ } : void 0,
6842
7090
  addAvailable: selection.source.surface === "side" || probeInput(ctx, selection.sessionId).state === "available" && hostDiagnostics(ctx).getSnapshot().capabilities.some((capability) => capability.id === "dock" && capability.state === "available"),
6843
7091
  sideChatAvailable: selection.source.surface === "main" && sideChatBridge.current !== null,
6844
7092
  onAdd: () => {
@@ -6847,7 +7095,7 @@ ${body}
6847
7095
  onAsk: () => {
6848
7096
  askInSideChat(selection);
6849
7097
  }
6850
- }),
7098
+ }, `${selection.sessionId}:${selection.anchorKey}:${selection.anchorText}:${selection.occurrence}`),
6851
7099
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BadgeLayer, {
6852
7100
  store,
6853
7101
  sessionId: currentSessionId,
@@ -6865,7 +7113,7 @@ ${body}
6865
7113
  onSave: (note) => {
6866
7114
  store.setNote(editingAnnotation.id, note);
6867
7115
  closeEditor();
6868
- const range = rangeCache.current.get(editingAnnotation.id)?.range;
7116
+ const range = rangeCache.current.get(editingAnnotation.id)?.ranges[0];
6869
7117
  const source = range === void 0 ? null : quoteSourceOf(range.startContainer, currentSessionId);
6870
7118
  if (source !== null) requestAnimationFrame(() => {
6871
7119
  if (document.activeElement === document.body) focusSourceComposer(source);
@@ -6984,6 +7232,7 @@ ${body}
6984
7232
  function SideChatNoteEditor(props) {
6985
7233
  useLocaleTick();
6986
7234
  const [note, setNote] = (0, react.useState)("");
7235
+ const noteInputRef = useAutoGrowingNote(note);
6987
7236
  const [failed, setFailed] = (0, react.useState)(false);
6988
7237
  const [pending, setPending] = (0, react.useState)(false);
6989
7238
  const rootRef = (0, react.useRef)(null);
@@ -7062,7 +7311,9 @@ ${body}
7062
7311
  style: {
7063
7312
  left,
7064
7313
  top,
7065
- width
7314
+ width,
7315
+ maxHeight: (props.bounds?.bottom ?? window.innerHeight) - top - 8,
7316
+ overflowY: "auto"
7066
7317
  },
7067
7318
  children: [
7068
7319
  props.targetTitle !== void 0 && props.targetTitle !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -7071,7 +7322,9 @@ ${body}
7071
7322
  }),
7072
7323
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
7073
7324
  className: annotate_module_css_default.editorAskRow,
7074
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
7325
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
7326
+ ref: noteInputRef,
7327
+ rows: 1,
7075
7328
  className: annotate_module_css_default.editorInput,
7076
7329
  value: note,
7077
7330
  placeholder: t("sideNotePlaceholder"),
@@ -7084,7 +7337,7 @@ ${body}
7084
7337
  setFailed(false);
7085
7338
  },
7086
7339
  onKeyDown: (event) => {
7087
- if (event.key !== "Enter") return;
7340
+ if (event.key !== "Enter" || event.shiftKey) return;
7088
7341
  if (event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) return;
7089
7342
  event.preventDefault();
7090
7343
  save();
@@ -7113,63 +7366,6 @@ ${body}
7113
7366
  ]
7114
7367
  });
7115
7368
  }
7116
- /** The floating two-button toolbar above a validated selection. */
7117
- function SelectionToolbar(props) {
7118
- useLocaleTick();
7119
- if (!props.snapshot.source.body.isConnected || props.snapshot.range.getClientRects().length === 0) return null;
7120
- const rect = props.snapshot.range.getBoundingClientRect();
7121
- const clip = sourceClip(props.snapshot.source);
7122
- const halfWidth = Math.min(props.sideChatAvailable ? 160 : 80, (clip.right - clip.left - 16) / 2);
7123
- const left = Math.max(clip.left + halfWidth + 8, Math.min(clip.right - halfWidth - 8, rect.left + rect.width / 2));
7124
- const flipBelow = rect.top < clip.top + 64;
7125
- const selectionBottom = props.snapshot.range.getBoundingClientRect().bottom;
7126
- const top = flipBelow ? Math.max(clip.top + 4, Math.min(clip.bottom - 48, selectionBottom + 10)) : Math.max(clip.top + 44, rect.top - 10);
7127
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
7128
- className: flipBelow ? `${annotate_module_css_default.toolbar} ${annotate_module_css_default.toolbarBelow}` : annotate_module_css_default.toolbar,
7129
- style: {
7130
- left,
7131
- top,
7132
- maxWidth: Math.max(0, clip.right - clip.left - 16)
7133
- },
7134
- role: "toolbar",
7135
- "aria-label": t("toolbarAria"),
7136
- children: [
7137
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
7138
- type: "button",
7139
- className: annotate_module_css_default.toolbarButton,
7140
- disabled: !props.addAvailable,
7141
- title: !props.addAvailable ? t("quoteWorkflowWaiting") : void 0,
7142
- onMouseDown: (event) => {
7143
- event.preventDefault();
7144
- },
7145
- onClick: (event) => {
7146
- event.preventDefault();
7147
- event.stopPropagation();
7148
- props.onAdd();
7149
- },
7150
- children: t("addToConversation")
7151
- }),
7152
- props.sideChatAvailable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
7153
- type: "button",
7154
- className: annotate_module_css_default.toolbarButton,
7155
- onMouseDown: (event) => {
7156
- event.preventDefault();
7157
- },
7158
- onClick: (event) => {
7159
- event.preventDefault();
7160
- event.stopPropagation();
7161
- props.onAsk();
7162
- },
7163
- children: t("askInSideChat")
7164
- }),
7165
- !props.addAvailable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
7166
- className: annotate_module_css_default.toolbarButton,
7167
- role: "status",
7168
- children: t("quoteWorkflowWaiting")
7169
- })
7170
- ]
7171
- });
7172
- }
7173
7369
  /** The badge layer (one numbered circle per annotation) + the active highlight. */
7174
7370
  function BadgeLayer(props) {
7175
7371
  const annotations = props.store.sessions().flatMap((id) => props.store.list(id));
@@ -7179,12 +7375,13 @@ ${body}
7179
7375
  const [hoveredId, setHoveredId] = (0, react.useState)(null);
7180
7376
  const highlightId = props.editingId ?? hoveredId;
7181
7377
  for (const annotation of annotations) {
7182
- const range = resolveRange(annotation, props.cache, props.sessionId);
7183
- if (range === null) continue;
7378
+ const ranges = resolveRanges(annotation, props.cache, props.sessionId);
7379
+ if (ranges === null) continue;
7380
+ const range = ranges[0];
7184
7381
  const source = quoteSourceOf(range.startContainer, props.sessionId);
7185
- if (source === null) continue;
7382
+ if (source === null || source.sessionId !== annotation.sessionId) continue;
7186
7383
  const clip = sourceClip(source);
7187
- if (annotation.id === highlightId) highlight = highlightRectsOf(range).map((rect) => {
7384
+ if (annotation.id === highlightId) highlight = ranges.flatMap(highlightRectsOf).map((rect) => {
7188
7385
  const left = Math.max(rect.left, clip.left), top = Math.max(rect.top, clip.top);
7189
7386
  return {
7190
7387
  left,
@@ -7252,6 +7449,7 @@ ${body}
7252
7449
  const rootRef = (0, react.useRef)(null);
7253
7450
  const noteRef = (0, react.useRef)(note);
7254
7451
  noteRef.current = note;
7452
+ const noteInputRef = useAutoGrowingNote(note);
7255
7453
  (0, react.useEffect)(() => {
7256
7454
  const onKeyDown = (event) => {
7257
7455
  if (event.key === "Escape") {
@@ -7286,7 +7484,9 @@ ${body}
7286
7484
  style: {
7287
7485
  left,
7288
7486
  top,
7289
- width
7487
+ width,
7488
+ maxHeight: (props.bounds?.bottom ?? window.innerHeight) - top - 8,
7489
+ overflowY: "auto"
7290
7490
  },
7291
7491
  children: [props.targetTitle !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
7292
7492
  className: annotate_module_css_default.editorTarget,
@@ -7294,16 +7494,18 @@ ${body}
7294
7494
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
7295
7495
  className: annotate_module_css_default.editorAskRow,
7296
7496
  style: { flex: 1 },
7297
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
7497
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
7498
+ ref: noteInputRef,
7298
7499
  className: annotate_module_css_default.editorInput,
7299
7500
  value: note,
7300
7501
  placeholder: t("notePlaceholder"),
7502
+ rows: 1,
7301
7503
  autoFocus: true,
7302
7504
  onChange: (event) => {
7303
7505
  setNote(event.target.value);
7304
7506
  },
7305
7507
  onKeyDown: (event) => {
7306
- if (event.key !== "Enter") return;
7508
+ if (event.key !== "Enter" || event.shiftKey) return;
7307
7509
  if (event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) return;
7308
7510
  event.preventDefault();
7309
7511
  save();
@@ -7737,6 +7939,7 @@ ${body}
7737
7939
  cancelInputRollback(input);
7738
7940
  const parts = [...options.leadingBlocks ?? []];
7739
7941
  if (annotations.length > 0) parts.push(buildProtocolBlock(annotations));
7942
+ const wireNumbers = new Map(annotations.map((annotation) => [annotation.id, annotation.number]));
7740
7943
  const block = parts.join("\n\n");
7741
7944
  if (block === "") return false;
7742
7945
  const draftBeforeWait = input.state.getSnapshot();
@@ -7758,7 +7961,10 @@ ${body}
7758
7961
  }
7759
7962
  receipt.submit(options.mode);
7760
7963
  await receipt.outcome;
7761
- store.markSent(annotations.filter((annotation) => store.get(annotation.id) === annotation).map((annotation) => annotation.id));
7964
+ store.markSent(annotations.filter((annotation) => {
7965
+ const current = store.get(annotation.id);
7966
+ return current !== void 0 && current.state === "active" && (current === annotation || current.note === annotation.note && current.text === annotation.text);
7967
+ }).map((annotation) => annotation.id), wireNumbers);
7762
7968
  return true;
7763
7969
  } catch (error) {
7764
7970
  rollbackInputPrefix(input, prefix, staged ? () => {
@@ -7973,6 +8179,38 @@ ${body}
7973
8179
  });
7974
8180
  }
7975
8181
  //#endregion
8182
+ //#region src/client/host/selection.tsx
8183
+ /** Coordinate the native surface with Sidenote's existing selection toolbar. */
8184
+ function registerNativeQuoteVisibility(ctx, preferences, ownsSelection) {
8185
+ const slots = ctx.slots;
8186
+ ctx.slots.inject("conversation.chat.text-interaction", () => {
8187
+ const patched = /* @__PURE__ */ new Map();
8188
+ const patch = () => {
8189
+ for (const entry of slots.entries("conversation.chat.text-interaction")) {
8190
+ if (entry.options.key !== "quote" || patched.has(entry)) continue;
8191
+ const Original = entry.component;
8192
+ const Wrapped = (props) => {
8193
+ const state = (0, react.useSyncExternalStore)(preferences.subscribe, preferences.getSnapshot);
8194
+ const sessionId = props.useSession((session) => session.sessionId);
8195
+ if (state.hidden || ownsSelection(sessionId)) return null;
8196
+ return (0, react.createElement)(Original, props);
8197
+ };
8198
+ entry.component = Wrapped;
8199
+ patched.set(entry, {
8200
+ original: Original,
8201
+ wrapped: Wrapped
8202
+ });
8203
+ }
8204
+ };
8205
+ patch();
8206
+ const unsubscribe = slots.subscribe("conversation.chat.text-interaction", patch);
8207
+ return () => {
8208
+ unsubscribe();
8209
+ for (const [entry, value] of patched) if (entry.component === value.wrapped) entry.component = value.original;
8210
+ };
8211
+ });
8212
+ }
8213
+ //#endregion
7976
8214
  //#region src/client/annotate/index.tsx
7977
8215
  /**
7978
8216
  * 划选注释(Delivery_02 重构后):selection listener + numbered badges +
@@ -7988,7 +8226,7 @@ ${body}
7988
8226
  * 否则重挂后双重挂载(两层工具条、双份监听、新旧 store 分裂)。slot 注册
7989
8227
  * 的 disposer 由 cordis 服务代理路由进调用方 fiber,无需手动回收。
7990
8228
  */
7991
- function registerAnnotations(ctx, reflow, store) {
8229
+ function registerAnnotations(ctx, reflow, store, preferences) {
7992
8230
  ctx.effect(() => {
7993
8231
  try {
7994
8232
  const controller = createSelectionController(() => currentSessionIdOf(ctx));
@@ -7999,8 +8237,10 @@ ${body}
7999
8237
  root.render(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(AnnotateOverlay, {
8000
8238
  ctx,
8001
8239
  store,
8002
- controller
8240
+ controller,
8241
+ preferences
8003
8242
  }));
8243
+ registerNativeQuoteVisibility(ctx, preferences, (sessionId) => captureSelection(currentSessionIdOf(ctx))?.sessionId === sessionId);
8004
8244
  registerNativeComposer(ctx, store, reflow);
8005
8245
  registerUserContext(ctx);
8006
8246
  ctx.slots.inject("conversation.input.dock", () => {
@@ -8098,13 +8338,209 @@ ${body}
8098
8338
  registerSessionListFilter(ctx, visibility);
8099
8339
  }
8100
8340
  //#endregion
8341
+ //#region src/client/preferences.ts
8342
+ /** Share one host-backed value between every main and side conversation. */
8343
+ function createSidenotePreferences(form) {
8344
+ const listeners = /* @__PURE__ */ new Set();
8345
+ let saving = false;
8346
+ let failed = false;
8347
+ const read = () => {
8348
+ const state = form.getSnapshot();
8349
+ return {
8350
+ hidden: state.value?.hideNativeQuote ?? true,
8351
+ status: state.status,
8352
+ writable: state.writable,
8353
+ saving,
8354
+ failed
8355
+ };
8356
+ };
8357
+ let snapshot = read();
8358
+ const publish = () => {
8359
+ snapshot = read();
8360
+ for (const listener of listeners) listener();
8361
+ };
8362
+ const unsubscribe = form.subscribe(publish);
8363
+ return {
8364
+ getSnapshot: () => snapshot,
8365
+ subscribe(listener) {
8366
+ listeners.add(listener);
8367
+ return () => {
8368
+ listeners.delete(listener);
8369
+ };
8370
+ },
8371
+ async setHidden(hidden) {
8372
+ if (saving || snapshot.status !== "ready" || !snapshot.writable) return;
8373
+ saving = true;
8374
+ failed = false;
8375
+ publish();
8376
+ try {
8377
+ failed = !await form.set("hideNativeQuote", hidden);
8378
+ } catch {
8379
+ failed = true;
8380
+ } finally {
8381
+ saving = false;
8382
+ publish();
8383
+ }
8384
+ },
8385
+ dispose() {
8386
+ unsubscribe();
8387
+ listeners.clear();
8388
+ }
8389
+ };
8390
+ }
8391
+ //#endregion
8392
+ //#region \0dsh-css:/home/runner/work/dsh-sidenote/dsh-sidenote/src/client/settings.module.css.mjs
8393
+ const css = "._2xJwMG_page{max-width:640px;color:var(--dsw-alias-label-primary,#1f2329);font-family:inherit}._2xJwMG_title{margin:0 0 8px;font-size:20px;font-weight:600;line-height:28px}._2xJwMG_description,._2xJwMG_hint,._2xJwMG_status{color:var(--dsw-alias-label-secondary,#646a73);font-size:13px;line-height:20px}._2xJwMG_description{margin:0 0 28px}._2xJwMG_row{border-top:1px solid var(--dsw-alias-border-l1,#00000014);border-bottom:1px solid var(--dsw-alias-border-l1,#00000014);align-items:center;gap:24px;padding:18px 0;display:flex}._2xJwMG_copy{flex:1;min-width:0}._2xJwMG_label{font-size:14px;font-weight:500;line-height:22px}._2xJwMG_hint{margin:4px 0 0}._2xJwMG_status,._2xJwMG_error{margin:12px 0 0}._2xJwMG_error{color:var(--dsw-alias-state-error-primary,#d53f3f);font-size:13px;line-height:20px}";
8394
+ const tagId = "dsh-sidenote/settings.module.css";
8395
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
8396
+ const tag = document.createElement("style");
8397
+ tag.dataset.plugin = "dsh-sidenote";
8398
+ tag.dataset.pluginCss = tagId;
8399
+ tag.textContent = css;
8400
+ document.head.appendChild(tag);
8401
+ }
8402
+ var settings_module_css_default = {
8403
+ "description": "_2xJwMG_description",
8404
+ "error": "_2xJwMG_error",
8405
+ "hint": "_2xJwMG_hint",
8406
+ "label": "_2xJwMG_label",
8407
+ "title": "_2xJwMG_title",
8408
+ "copy": "_2xJwMG_copy",
8409
+ "status": "_2xJwMG_status",
8410
+ "row": "_2xJwMG_row",
8411
+ "page": "_2xJwMG_page"
8412
+ };
8413
+ //#endregion
8414
+ //#region src/client/settings.tsx
8415
+ function SidenoteSettings({ preferences }) {
8416
+ useLocaleTick();
8417
+ const state = (0, react.useSyncExternalStore)(preferences.subscribe, preferences.getSnapshot);
8418
+ const id = (0, react.useId)();
8419
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
8420
+ className: settings_module_css_default.page,
8421
+ "aria-labelledby": `${id}-title`,
8422
+ children: [
8423
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
8424
+ id: `${id}-title`,
8425
+ className: settings_module_css_default.title,
8426
+ children: "Sidenote"
8427
+ }),
8428
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
8429
+ className: settings_module_css_default.description,
8430
+ children: t("settingsDescription")
8431
+ }),
8432
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
8433
+ className: settings_module_css_default.row,
8434
+ role: "group",
8435
+ "aria-labelledby": `${id}-label`,
8436
+ "aria-describedby": `${id}-description`,
8437
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
8438
+ className: settings_module_css_default.copy,
8439
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
8440
+ id: `${id}-label`,
8441
+ className: settings_module_css_default.label,
8442
+ children: t("hideNativeQuote")
8443
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
8444
+ id: `${id}-description`,
8445
+ className: settings_module_css_default.hint,
8446
+ children: t("hideNativeQuoteHint")
8447
+ })]
8448
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
8449
+ checked: state.hidden,
8450
+ label: t("hideNativeQuote"),
8451
+ title: t("hideNativeQuoteHint"),
8452
+ disabled: state.status !== "ready" || !state.writable || state.saving,
8453
+ onChange: (hidden) => {
8454
+ preferences.setHidden(hidden);
8455
+ }
8456
+ })]
8457
+ }),
8458
+ state.saving && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
8459
+ className: settings_module_css_default.status,
8460
+ role: "status",
8461
+ children: t("settingsSaving")
8462
+ }),
8463
+ state.status === "loading" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
8464
+ className: settings_module_css_default.status,
8465
+ role: "status",
8466
+ children: t("settingsLoading")
8467
+ }),
8468
+ state.status === "unavailable" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
8469
+ className: settings_module_css_default.error,
8470
+ role: "alert",
8471
+ children: t("settingsUnavailable")
8472
+ }),
8473
+ state.status === "ready" && !state.writable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
8474
+ className: settings_module_css_default.status,
8475
+ role: "status",
8476
+ children: t("settingsReadOnly")
8477
+ }),
8478
+ state.failed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
8479
+ className: settings_module_css_default.error,
8480
+ role: "alert",
8481
+ children: t("settingsSaveFailed")
8482
+ })
8483
+ ]
8484
+ });
8485
+ }
8486
+ function registerSidenoteSettings(ctx, preferences) {
8487
+ ctx.slots.inject("settings.section", () => ctx.slots.register({
8488
+ name: "settings.section",
8489
+ id: "dsh-sidenote",
8490
+ label: "Sidenote",
8491
+ order: 80,
8492
+ registrant: "dsh-sidenote"
8493
+ }, () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SidenoteSettings, { preferences })));
8494
+ ctx.slots.inject("settings.section.icon", () => ctx.slots.register({
8495
+ name: "settings.section.icon",
8496
+ id: "dsh-sidenote",
8497
+ registrant: "dsh-sidenote"
8498
+ }, ({ size }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconListPenOutline16, { size })));
8499
+ }
8500
+ //#endregion
8501
+ //#region src/client/host/replyDefaults.ts
8502
+ function initializeFinalReplies(sidenote, chat) {
8503
+ let stopped = false;
8504
+ let attempted = false;
8505
+ const initialize = () => {
8506
+ if (stopped || attempted) return;
8507
+ const own = sidenote.getSnapshot(), target = chat.getSnapshot();
8508
+ if (own.status !== "ready" || target.status !== "ready" || !own.writable || !target.writable || !own.value || !target.value || own.revision === void 0 || target.revision === void 0) return;
8509
+ if (own.value.finalRepliesDefaultAttempted) return;
8510
+ attempted = true;
8511
+ (async () => {
8512
+ if (!await sidenote.mutate([{
8513
+ op: "set",
8514
+ path: ["finalRepliesDefaultAttempted"],
8515
+ value: true
8516
+ }], own.revision) || stopped) return;
8517
+ if (target.value.foldedReplies !== "final") await chat.mutate([{
8518
+ op: "set",
8519
+ path: ["foldedReplies"],
8520
+ value: "final"
8521
+ }], target.revision);
8522
+ })().catch(() => {
8523
+ console.warn("[dsh-sidenote] 最终回答显示偏好初始化未完成,保留当前设置。");
8524
+ });
8525
+ };
8526
+ const unsubscribeOwn = sidenote.subscribe(initialize);
8527
+ const unsubscribeChat = chat.subscribe(initialize);
8528
+ initialize();
8529
+ return () => {
8530
+ stopped = true;
8531
+ unsubscribeOwn();
8532
+ unsubscribeChat();
8533
+ };
8534
+ }
8535
+ //#endregion
8101
8536
  //#region src/client/index.tsx
8102
8537
  const inject = [
8103
8538
  "sessions",
8104
8539
  "workspaces",
8105
8540
  "slots",
8106
8541
  "connection",
8107
- "locale"
8542
+ "locale",
8543
+ "configForms"
8108
8544
  ];
8109
8545
  function apply(ctx) {
8110
8546
  ctx.effect(() => {
@@ -8119,8 +8555,16 @@ ${body}
8119
8555
  sweepOrphanedSideChatMeta();
8120
8556
  const reflow = createReflowStore();
8121
8557
  const annotations = createAnnotationStore();
8558
+ const forms = ctx.get("configForms");
8559
+ const form = forms.get("side-chat");
8560
+ const preferences = createSidenotePreferences(form);
8561
+ ctx.effect(() => () => {
8562
+ preferences.dispose();
8563
+ }, "dsh-sidenote: preferences");
8564
+ ctx.effect(() => initializeFinalReplies(form, forms.get("ui-chat")), "dsh-sidenote: final replies default");
8565
+ registerSidenoteSettings(ctx, preferences);
8122
8566
  registerSideChat(ctx, reflow, annotations);
8123
- registerAnnotations(ctx, reflow, annotations);
8567
+ registerAnnotations(ctx, reflow, annotations, preferences);
8124
8568
  }
8125
8569
  //#endregion
8126
8570
  exports.apply = apply;