dsh-builtin-browser 1.0.3 → 1.1.0

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 (305) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/README.en.md +89 -0
  3. package/browser-extension/constants.mjs +20 -0
  4. package/browser-extension/controller.mjs +293 -0
  5. package/browser-extension/locales.mjs +15 -0
  6. package/browser-extension/manifest.json +12 -0
  7. package/browser-extension/options.html +14 -0
  8. package/browser-extension/options.mjs +9 -0
  9. package/browser-extension/permission-guard.mjs +13 -0
  10. package/browser-extension/worker.mjs +74 -0
  11. package/desktop-bridge/desktop-identity.json +10 -2
  12. package/desktop-bridge/install.mjs +28 -2
  13. package/docs/issue-replies-2026-11-28.md +141 -0
  14. package/dsh-host-patch/apply.mjs +1 -1
  15. package/dsh-host-patch/rc3.json +4 -4
  16. package/dsh-host-patch/rc5.json +4 -4
  17. package/dsh-host-patch/v023-alpha2.json +2 -2
  18. package/lib/browser-electron/bridge-status.js +24 -1
  19. package/lib/browser-electron/desktop-identity.js +47 -8
  20. package/lib/client.js +2 -1
  21. package/native-host/install.mjs +5 -0
  22. package/package.json +20 -2
  23. package/scripts/build-client.mjs +305 -0
  24. package/scripts/build.mjs +69 -0
  25. package/scripts/bundle-host.mjs +28 -0
  26. package/scripts/fix-exports.mjs +40 -0
  27. package/scripts/install-electron.mjs +101 -0
  28. package/scripts/pack.mjs +99 -0
  29. package/scripts/publish-manifest.mjs +56 -0
  30. package/scripts/verify-exports.mjs +58 -0
  31. package/scripts/verify-preview-sdk.mjs +93 -0
  32. package/skills/dsh-builtin-browser/SKILL.md +98 -0
  33. package/skills/dsh-builtin-browser/references/batch.md +68 -0
  34. package/skills/dsh-builtin-browser/references/deliver.md +31 -0
  35. package/skills/dsh-builtin-browser/references/locate.md +11 -0
  36. package/skills/dsh-builtin-browser/references/recover.md +11 -0
  37. package/skills/dsh-builtin-browser/references/verify.md +13 -0
  38. package/skills/dsh-debug-host/SKILL.md +56 -0
  39. package/skills/dsh-debug-self/SKILL.md +50 -0
  40. package/src/bridge-compatibility.ts +39 -0
  41. package/src/browser/anti-bot.ts +251 -0
  42. package/src/browser/deep-dom.ts +40 -0
  43. package/src/browser/handles.ts +89 -0
  44. package/src/browser/runtime.ts +578 -0
  45. package/src/browser/takeover-target.ts +45 -0
  46. package/src/browser/types.ts +870 -0
  47. package/src/browser-electron/authenticated-route.ts +109 -0
  48. package/src/browser-electron/automatic-maintenance.ts +736 -0
  49. package/src/browser-electron/bridge-auto.ts +159 -0
  50. package/src/browser-electron/bridge-connection.ts +386 -0
  51. package/src/browser-electron/bridge-endpoint.ts +129 -0
  52. package/src/browser-electron/bridge-install.ts +290 -0
  53. package/src/browser-electron/bridge-maintenance.ts +189 -0
  54. package/src/browser-electron/bridge-status.ts +412 -0
  55. package/src/browser-electron/desktop-bridge-host.ts +253 -0
  56. package/src/browser-electron/desktop-identity.ts +400 -0
  57. package/src/browser-electron/desktop-shell.ts +100 -0
  58. package/src/browser-electron/document-readiness.ts +45 -0
  59. package/src/browser-electron/electron-provision.ts +347 -0
  60. package/src/browser-electron/entry.ts +1378 -0
  61. package/src/browser-electron/ephemeral-profile.ts +189 -0
  62. package/src/browser-electron/extension-browser.ts +230 -0
  63. package/src/browser-electron/extension-setup.ts +67 -0
  64. package/src/browser-electron/file-write.ts +31 -0
  65. package/src/browser-electron/foreground-watch.ts +142 -0
  66. package/src/browser-electron/guest-cookie-jar.ts +177 -0
  67. package/src/browser-electron/guest-cookie-store.ts +59 -0
  68. package/src/browser-electron/guest-css-runtime.ts +76 -0
  69. package/src/browser-electron/guest-css.ts +68 -0
  70. package/src/browser-electron/guest-route.ts +716 -0
  71. package/src/browser-electron/guest-runtime.ts +408 -0
  72. package/src/browser-electron/guest-storage-runtime.ts +54 -0
  73. package/src/browser-electron/guest-storage.ts +120 -0
  74. package/src/browser-electron/history-store.ts +224 -0
  75. package/src/browser-electron/host-main.ts +1385 -0
  76. package/src/browser-electron/host-patch-maintenance.ts +121 -0
  77. package/src/browser-electron/http-body.ts +65 -0
  78. package/src/browser-electron/json-reply.ts +47 -0
  79. package/src/browser-electron/maintenance-broker.ts +166 -0
  80. package/src/browser-electron/maintenance-lifecycle.ts +91 -0
  81. package/src/browser-electron/maintenance-route.ts +68 -0
  82. package/src/browser-electron/missing-system-browser.ts +114 -0
  83. package/src/browser-electron/open-slot.ts +49 -0
  84. package/src/browser-electron/paths.ts +25 -0
  85. package/src/browser-electron/preferred-browser.ts +130 -0
  86. package/src/browser-electron/preview-route.ts +215 -0
  87. package/src/browser-electron/process-ownership.ts +174 -0
  88. package/src/browser-electron/process.ts +23 -0
  89. package/src/browser-electron/profile-checkpoint.ts +187 -0
  90. package/src/browser-electron/profile-command.ts +47 -0
  91. package/src/browser-electron/profile-extension.ts +129 -0
  92. package/src/browser-electron/profile-lease.ts +211 -0
  93. package/src/browser-electron/profile-residue.ts +49 -0
  94. package/src/browser-electron/provider-core.ts +1107 -0
  95. package/src/browser-electron/provider-interaction.ts +1034 -0
  96. package/src/browser-electron/provider-media.ts +589 -0
  97. package/src/browser-electron/provider-navigation.ts +323 -0
  98. package/src/browser-electron/provider-observation.ts +664 -0
  99. package/src/browser-electron/provider-tabs.ts +372 -0
  100. package/src/browser-electron/provider.ts +666 -0
  101. package/src/browser-electron/reference-route.ts +598 -0
  102. package/src/browser-electron/remote-host.ts +1538 -0
  103. package/src/browser-electron/rpc-input.ts +13 -0
  104. package/src/browser-electron/rpc-ops.ts +41 -0
  105. package/src/browser-electron/runtime-diagnostics.ts +38 -0
  106. package/src/browser-electron/runtime-route.ts +105 -0
  107. package/src/browser-electron/runtime-status.ts +309 -0
  108. package/src/browser-electron/settings-route.ts +64 -0
  109. package/src/browser-electron/settings-store.ts +593 -0
  110. package/src/browser-electron/shortcuts-route.ts +112 -0
  111. package/src/browser-electron/sidebar-only-host.ts +300 -0
  112. package/src/browser-electron/startpage-shortcuts.ts +213 -0
  113. package/src/browser-electron/system-browser.ts +1850 -0
  114. package/src/browser-electron/tauri-host.ts +194 -0
  115. package/src/browser-electron/timing.ts +16 -0
  116. package/src/browser-electron/virtual-cursor.ts +162 -0
  117. package/src/browser-electron/windows-system.ts +24 -0
  118. package/src/browser-reference/delivery.ts +384 -0
  119. package/src/browser-reference/entry.ts +631 -0
  120. package/src/browser-reference/export.ts +339 -0
  121. package/src/browser-reference/import.ts +303 -0
  122. package/src/browser-reference/page-script.ts +1537 -0
  123. package/src/browser-reference/service.ts +1346 -0
  124. package/src/browser-reference/store.ts +172 -0
  125. package/src/browser-reference/text-quote.ts +219 -0
  126. package/src/browser-reference/types.ts +195 -0
  127. package/src/browser-reference/visible.ts +367 -0
  128. package/src/browser-reference/web-sources.ts +106 -0
  129. package/src/client/apply-guard.ts +22 -0
  130. package/src/client/browser/BrowserController.ts +693 -0
  131. package/src/client/browser/BrowserFrame.ts +78 -0
  132. package/src/client/browser/BrowserNavigation.ts +169 -0
  133. package/src/client/browser/BrowserPage.ts +23 -0
  134. package/src/client/browser/BrowserPersistence.ts +44 -0
  135. package/src/client/browser/IframeImpl.ts +182 -0
  136. package/src/client/browser/child-tabs.ts +14 -0
  137. package/src/client/browser/frame-history.ts +125 -0
  138. package/src/client/browser/frame-state.ts +27 -0
  139. package/src/client/browser/iframe-reference.ts +67 -0
  140. package/src/client/browser/initialization.ts +262 -0
  141. package/src/client/browser/omnibox.ts +243 -0
  142. package/src/client/browser/store.ts +38 -0
  143. package/src/client/browser/takeover-channel.ts +72 -0
  144. package/src/client/browser/url.ts +46 -0
  145. package/src/client/browser/web-reference-source.ts +56 -0
  146. package/src/client/css-modules.d.ts +4 -0
  147. package/src/client/definition.tsx +36 -0
  148. package/src/client/electron/ElectronWebViewImpl.ts +371 -0
  149. package/src/client/electron/ElectronWebviewPresentation.ts +140 -0
  150. package/src/client/electron/NativeChildPresentation.ts +53 -0
  151. package/src/client/electron/NativeViewPage.ts +265 -0
  152. package/src/client/electron/pages.ts +23 -0
  153. package/src/client/electron/reference-overlay.ts +53 -0
  154. package/src/client/electron/workspace.ts +33 -0
  155. package/src/client/index.ts +333 -0
  156. package/src/client/locales.ts +860 -0
  157. package/src/client/pages.ts +28 -0
  158. package/src/client/reference/client/BrowserRefLink.tsx +142 -0
  159. package/src/client/reference/client/draft-reference.ts +167 -0
  160. package/src/client/reference/client/index.ts +7 -0
  161. package/src/client/reference/client/ordered-submission.ts +108 -0
  162. package/src/client/reference/client/pending-delivery.ts +216 -0
  163. package/src/client/reference/client/plugin.ts +208 -0
  164. package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
  165. package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
  166. package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
  167. package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
  168. package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
  169. package/src/client/reference/client/production/ReferenceText.tsx +36 -0
  170. package/src/client/reference/client/production/assembly.ts +447 -0
  171. package/src/client/reference/client/production/asset-store.ts +144 -0
  172. package/src/client/reference/client/production/availability.ts +72 -0
  173. package/src/client/reference/client/production/bytes.ts +36 -0
  174. package/src/client/reference/client/production/composer-attachments.ts +44 -0
  175. package/src/client/reference/client/production/delivery-client.ts +211 -0
  176. package/src/client/reference/client/production/draft-adapter.ts +512 -0
  177. package/src/client/reference/client/production/http-transport.ts +212 -0
  178. package/src/client/reference/client/production/production-submission.ts +70 -0
  179. package/src/client/reference/client/production/protocol.ts +234 -0
  180. package/src/client/reference/client/production/reference-card.ts +240 -0
  181. package/src/client/reference/client/production/reference-labels.ts +29 -0
  182. package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
  183. package/src/client/reference/client/production/reveal.ts +215 -0
  184. package/src/client/reference/client/production/runtime.ts +1056 -0
  185. package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
  186. package/src/client/reference/client/production/source-marker.ts +99 -0
  187. package/src/client/reference/client/production/source-opener.ts +55 -0
  188. package/src/client/reference/client/production/styles.ts +104 -0
  189. package/src/client/reference/client/production/user-text-rule.ts +67 -0
  190. package/src/client/reference/client/reveal.ts +109 -0
  191. package/src/client/reference/client/scheme.ts +114 -0
  192. package/src/client/reference/client/session-schedule.ts +36 -0
  193. package/src/client/reference/client/types.ts +168 -0
  194. package/src/client/reference/css-modules.d.ts +4 -0
  195. package/src/client/reference/index.ts +11 -0
  196. package/src/client/reference-capture-owner.ts +162 -0
  197. package/src/client/reference-intents.ts +36 -0
  198. package/src/client/settings/index.ts +42 -0
  199. package/src/client/settings/mount-guard.ts +31 -0
  200. package/src/client/settings/panel.ts +2773 -0
  201. package/src/client/shortcut-open.ts +30 -0
  202. package/src/client/startpage/binding.ts +99 -0
  203. package/src/client/startpage/controller.ts +300 -0
  204. package/src/client/startpage/model.ts +279 -0
  205. package/src/client/view/Browser.module.css +751 -0
  206. package/src/client/view/BrowserBody.tsx +315 -0
  207. package/src/client/view/BrowserPresentation.ts +9 -0
  208. package/src/client/view/BrowserTitle.tsx +17 -0
  209. package/src/client/view/IframePresentation.ts +365 -0
  210. package/src/client/view/StartPage.tsx +598 -0
  211. package/src/client/view/TakeoverBanner.tsx +21 -0
  212. package/src/compat/host-features.ts +92 -0
  213. package/src/index.ts +110 -0
  214. package/src/reference-owner.ts +5 -0
  215. package/src/reference-page.ts +9 -0
  216. package/src/reference-source.ts +3 -0
  217. package/src/reference-text.ts +219 -0
  218. package/src/startpage-settings.ts +103 -0
  219. package/src/startpage.ts +71 -0
  220. package/src/takeover-protocol.ts +28 -0
  221. package/src/tool-browser/block-recovery.ts +85 -0
  222. package/src/tool-browser/code-tool.ts +555 -0
  223. package/src/tool-browser/code-worker.ts +725 -0
  224. package/src/tool-browser/element-fields.ts +167 -0
  225. package/src/tool-browser/errors.ts +40 -0
  226. package/src/tool-browser/index.ts +265 -0
  227. package/src/tool-browser/page-probe.ts +675 -0
  228. package/src/tool-browser/panel-page.ts +126 -0
  229. package/src/tool-browser/probe-client.ts +183 -0
  230. package/src/tool-browser/screenshot-annotations.ts +131 -0
  231. package/src/tool-browser/screenshot-image.ts +49 -0
  232. package/src/tool-browser/state.ts +375 -0
  233. package/src/tool-browser/takeover.ts +199 -0
  234. package/src/tool-browser/tools-debug.ts +806 -0
  235. package/src/tool-browser/tools-interaction.ts +956 -0
  236. package/src/tool-browser/tools-navigation.ts +786 -0
  237. package/src/tool-browser/tools-observation.ts +474 -0
  238. package/src/tool-browser/tools-reference.ts +294 -0
  239. package/src/types/electron-shim.d.ts +144 -0
  240. package/src/types.ts +85 -0
  241. package/src/web-guest.ts +35 -0
  242. package/tools/accept-desktop.mjs +148 -0
  243. package/dist/client.d.cts +0 -516
  244. package/dist/client.d.mts +0 -516
  245. package/dist/index.cjs +0 -92
  246. package/dist/index.d.mts +0 -2960
  247. package/dist/index.mjs +0 -24
  248. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  249. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  250. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  251. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  252. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  253. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  254. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  255. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  256. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  257. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  258. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  259. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  260. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  261. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  262. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  263. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  264. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  265. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  266. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  267. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  268. package/dsh-host-patch/sources/manifest.json +0 -218
  269. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  270. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  271. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  272. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  273. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  274. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  275. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  276. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  277. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  278. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  279. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  280. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  281. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  282. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  283. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  284. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  285. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  286. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  287. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  288. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  289. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  290. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  291. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  292. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  293. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  294. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  295. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  296. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  297. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  298. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  299. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  300. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  301. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  302. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  303. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  304. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  305. package/dsh-host-patch/sources/series.json +0 -260
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Client plugin entry: what the DSH client bundle actually loads.
3
+ *
4
+ * The bundle contract is `export const inject` + `export function apply(ctx,
5
+ * config)`; everything else here exists to supply the two things a YAML row
6
+ * cannot carry:
7
+ * - `createElement` / `useSyncExternalStore` ← React, a shared platform module.
8
+ * - `hostInputFor` and the active Session id ← the Session-scope props the
9
+ * `conversation.input.dock` registration receives on every render
10
+ * (`session`, `input`, `inputActions`).
11
+ *
12
+ * Both come from inside this package, so no separate `browserReferenceDeps`
13
+ * service has to be published by another package.
14
+ *
15
+ * @module dsh-browser-reference/plugin
16
+ */
17
+ import { createElement } from 'react'
18
+ import { referenceOwnerKey } from '../../../reference-owner.ts'
19
+ import type { BrowserInitializationReader } from '../../browser/initialization.ts'
20
+ import { openReferenceSource, type SourceSidebar } from './production/source-opener.ts'
21
+ import { createSessionScheduler } from './session-schedule.ts'
22
+ import {
23
+ apply as applyProduction,
24
+ type AssemblyConfig,
25
+ type HostContext,
26
+ type HostElementFactory,
27
+ } from './production/assembly.ts'
28
+ import type { HostInputFace } from './production/draft-adapter.ts'
29
+ import type { ComposerImage } from './production/production-submission.ts'
30
+ import { attachImages } from './production/composer-attachments.ts'
31
+ import type { ProductionRuntime } from './production/runtime.ts'
32
+ import type { ReferenceChipInsert } from './types.ts'
33
+
34
+ /** Slots render the dock, uiConversation parses source links, and locale supplies labels. */
35
+ export const inject = ['slots', 'uiConversation', 'locale']
36
+
37
+ /** The caret span the host editor hands out (`captureInsertion`). */
38
+ interface CaretSpan {
39
+ readonly start: number
40
+ readonly end: number
41
+ readonly draftRev: number
42
+ }
43
+
44
+ /** `SessionInput.actions`, as handed to a Session-scope slot registration. */
45
+ interface SlotInputActions {
46
+ captureInsertion(): CaretSpan
47
+ insertText(text: string, span: CaretSpan): boolean
48
+ persistDraft(): void
49
+ /**
50
+ * Insert a real reference chip into the editor — the same entry point the host's own built-in
51
+ * references use. Going through this instead of a decorator portal is what makes a web reference
52
+ * behave like a native one: the editor owns its content, its draft persistence, its caret guard and
53
+ * its send gating.
54
+ */
55
+ insertReference?(ref: ReferenceChipInsert, span: CaretSpan): boolean
56
+ insertQuote?(text: string, summary?: string): boolean
57
+ addAttachments?(ids: readonly string[]): boolean
58
+ }
59
+
60
+ /** Session-scope props the `conversation.input.dock` registration receives. */
61
+ interface DockProps {
62
+ readonly sessionId?: string
63
+ readonly session?: { readonly sessionId?: string }
64
+ readonly input?: { readonly draft?: string }
65
+ readonly inputActions?: SlotInputActions
66
+ }
67
+
68
+ /** Per-Session input face, so an async delivery never lands in another draft. */
69
+ interface InputBinding {
70
+ readonly sessionId: string
71
+ readonly face: HostInputFace
72
+ }
73
+
74
+ /** The slice of the shell's sidebar service this plugin drives. */
75
+ interface SidebarRightService {
76
+ /** Open — or re-aim — one session's `browser` tab at `url`. */
77
+ openTabIn(sessionId: string, kind: string, options?: { readonly params?: { readonly url?: string } }): void
78
+ }
79
+
80
+ interface SidebarScope {
81
+ readonly sidebarRight: SidebarRightService
82
+ }
83
+
84
+ const inertFace: HostInputFace = {
85
+ captureInsertion: () => ({ start: 0, end: 0, draftRev: 0 }),
86
+ insertText: () => false,
87
+ persistDraft: () => { throw new Error('browser reference input is not bound to its conversation') },
88
+ readText: () => '',
89
+ }
90
+
91
+ export function apply(ctx: HostContext, config: AssemblyConfig = {}): ProductionRuntime {
92
+ const bindings = new Map<string, InputBinding>()
93
+ const hostSessions = new Map<string, string>()
94
+
95
+ const bindingFor = (sessionId: string): HostInputFace =>
96
+ (sessionId === '' ? undefined : bindings.get(sessionId)?.face) ?? inertFace
97
+
98
+ // Two dock components can be mounted at once (one per kept-alive conversation), and each one's
99
+ // render reported its own Session here. Switching the runtime synchronously during render
100
+ // notified the other dock, which rendered and switched back — an unbounded render↔publish cycle
101
+ // that React reports as "Maximum update depth exceeded" (issue #127). The switch is deferred and
102
+ // only the last report of a tick survives (see session-schedule.ts).
103
+ const scheduleSession = createSessionScheduler(
104
+ sessionId => runtime.setSession(sessionId),
105
+ task => queueMicrotask(task),
106
+ )
107
+ const runtime: ProductionRuntime = applyProduction(ctx, {
108
+ ...config,
109
+ createElement: (config.createElement ?? createElement) as unknown as HostElementFactory,
110
+ hostInputFor: bindingFor,
111
+ onDockProps: (props) => {
112
+ config.onDockProps?.(props)
113
+ const dock = props as DockProps | undefined
114
+ const rawSession = dock?.sessionId ?? dock?.session?.sessionId
115
+ const sessionId = typeof rawSession === 'string' ? referenceOwnerKey(rawSession) : undefined
116
+ const actions = dock?.inputActions
117
+ if (typeof rawSession !== 'string' || typeof sessionId !== 'string' || sessionId === '') { scheduleSession(''); return }
118
+ hostSessions.set(sessionId, rawSession.trim())
119
+ // The visible Session becomes the active one: this is what makes the
120
+ // default entry poll a real conversation instead of the empty id, and it
121
+ // keeps an async delivery bound to the Session it belongs to.
122
+ scheduleSession(sessionId)
123
+ if (actions === undefined) return
124
+ const readDraft = (): string => {
125
+ const text = dock?.input?.draft
126
+ return typeof text === 'string' ? text : ''
127
+ }
128
+ const face: HostInputFace = {
129
+ captureInsertion: () => actions.captureInsertion(),
130
+ insertText: (span, text) => actions.insertText(text, span),
131
+ persistDraft: () => { actions.persistDraft() },
132
+ // Only used to prove the typed question was not disturbed; the
133
+ // authoritative guard remains the editor's `draftRev` compare-and-set.
134
+ readText: readDraft,
135
+ // 插入引文需要编辑器里有光标。确认按钮是在**侧栏 iframe 里**点的,那一刻焦点不在输入框,
136
+ // `insertQuote` 会静默失败(引文与标记都没进草稿)。插之前先把光标放回编辑器。
137
+ focusEditor: () => {
138
+ try {
139
+ const editor = document.querySelector('[contenteditable="true"]')
140
+ if (editor instanceof HTMLElement) editor.focus()
141
+ } catch {
142
+ // 文档里没有编辑器时无需处理:调用方按失败重试。
143
+ }
144
+ },
145
+ // rc.3 的门径:编辑器原生「原子引用」插入。插进去以后 `InputState.draft` 会展开成引文、
146
+ // `occurrences` 增加,上游发送闸门不再判空——「只有引用也能发」由此成立,且不改上游。
147
+ ...(typeof actions.insertQuote === 'function'
148
+ ? { insertQuote: (text: string, summary?: string) => actions.insertQuote?.(text, summary) === true }
149
+ : {}),
150
+ ...(typeof actions.addAttachments === 'function'
151
+ ? { attachImages: (images: readonly ComposerImage[]) => attachImages(ctx, rawSession.trim(), images, actions) }
152
+ : {}),
153
+ ...(typeof actions.removeAttachment === 'function'
154
+ ? { removeAttachments: (ids: readonly string[]) => { for (const id of ids) actions.removeAttachment?.(id) } }
155
+ : {}),
156
+ ...(typeof actions.insertReference === 'function'
157
+ ? { insertReference: (ref: ReferenceChipInsert, span: CaretSpan) => actions.insertReference?.(ref, span) === true }
158
+ : {}),
159
+ }
160
+ const binding: InputBinding = { sessionId, face }
161
+ bindings.set(sessionId, binding)
162
+ // 每次 dock 渲染把当前草稿交给运行时:草稿由非空变空即「消息已被接受」,需要退役本会话的引用,
163
+ // 否则发完消息输入框里还留着上一次的胶囊。
164
+ try { runtime.noteDraft(sessionId, readDraft()) } catch { /* 清理是尽力而为 */ }
165
+ },
166
+ })
167
+
168
+ // 侧栏页(同源 guest)需要知道「这条引用属于哪个会话」。旧实现把应答放在设置面板里,于是
169
+ // 只在设置页打开时才成立;现在由客户端半自己应答:页面加载时会 postMessage 询问,这里回当前的
170
+ // 会话 id,并把已知的同源 iframe 一并推一遍(会话切换后已加载的页面也能收到)。
171
+ if (typeof window !== 'undefined') {
172
+ // 页面可能在会话还没绑定好之前就发问(面板先挂载、dock props 后到)。早退会让它永远拿不到
173
+ // 会话 id,引用就落到空会话上——于是「卡片不出现、发送被禁用」。挂起的询问在这里等 id 到手
174
+ // 再回,而不是丢掉。
175
+ const pendingAsks = new Set<{ readonly source: Window; readonly origin: string }>()
176
+ const answer = (ask: { readonly source: Window; readonly origin: string }, sessionId: string): void => {
177
+ try {
178
+ ask.source.postMessage({ type: 'dsh.sidebar.session', sessionId }, ask.origin)
179
+ } catch {
180
+ // 跨源或已卸载的窗口:它不是我们的侧栏页,忽略。
181
+ }
182
+ }
183
+ const respond = (event: MessageEvent): void => {
184
+ const data = event.data as { readonly type?: string } | null
185
+ if (data === null || data.type !== 'dsh.sidebar.session.request') return
186
+ const source = event.source as Window | null
187
+ if (source === null) return
188
+ const ask = { source, origin: event.origin }
189
+ const sessionId = runtime.currentSessionId()
190
+ if (sessionId === '') { pendingAsks.add(ask); return }
191
+ answer(ask, sessionId)
192
+ }
193
+ window.addEventListener('message', respond)
194
+ runtime.onSessionChange((sessionId) => {
195
+ for (const ask of pendingAsks) answer(ask, sessionId)
196
+ pendingAsks.clear()
197
+ })
198
+ ctx.effect(() => () => { window.removeEventListener('message', respond) }, 'ui-browser-reference: guest session responder')
199
+ }
200
+
201
+ runtime.setSourceOpener(async (url, signal) => {
202
+ const sessionId = runtime.currentSessionId()
203
+ if (sessionId === '') throw new Error('reference source requires a conversation')
204
+ return openReferenceSource(ctx.get('sidebarRight') as SourceSidebar,
205
+ ctx.get('sidebarBrowserInitialization') as BrowserInitializationReader, hostSessions.get(sessionId) ?? sessionId, url, signal)
206
+ })
207
+ return runtime
208
+ }
@@ -0,0 +1,345 @@
1
+ /**
2
+ * Browser references inside the composer.
3
+ *
4
+ * COLLAPSED BY DEFAULT: every reference is one compact pill (`[1] 标题`) in a
5
+ * single wrapping row. A second selection is added BESIDE the first, so the row
6
+ * grows sideways instead of the composer growing taller, and the box keeps the
7
+ * height the user typed into.
8
+ *
9
+ * Hovering or focusing a pill opens a floating detail card ABOVE it: the
10
+ * captured content in its own shape (paragraphs keep their line breaks, images
11
+ * stay images, tables stay tables), the user's note, and the three actions —
12
+ * edit note, go to source, remove. The card is portalled with fixed positioning
13
+ * and bounded height, so opening it never pushes the input box or the
14
+ * conversation around; it also stays open while the pointer travels from the
15
+ * pill into the card, which is what makes “edit the note” reachable by mouse.
16
+ * Removal is final: the pill disappears and nothing offers to undo it.
17
+ */
18
+ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from 'react'
19
+ import { createPortal } from 'react-dom'
20
+ import { IconEditOutlineRegular, IconLinkOutlineRegular, IconTrashOutlineRegular, Tooltip } from '@deepseek-ai/dsh-client-ui-primitives'
21
+ import type { CardActions, CardPart, CardViewModel } from './reference-card.ts'
22
+ import type { ReferenceLabels } from './reference-labels.ts'
23
+ import css from './ReferenceDock.module.css'
24
+ import { ReferenceText } from './ReferenceText.tsx'
25
+ import { referenceTableRows } from '../../../../reference-text.ts'
26
+
27
+ export interface ReferenceCapsulesProps {
28
+ readonly sessionId: string
29
+ readonly cards: readonly CardViewModel[]
30
+ readonly actions: CardActions
31
+ readonly labels: ReferenceLabels
32
+ readonly notice?: string
33
+ readonly readOnly?: boolean
34
+ readonly anchor?: HTMLElement
35
+ }
36
+
37
+ /** Time the pointer may leave the pill and land on the card without a flicker. */
38
+ const CLOSE_DELAY_MS = 180
39
+ const PANEL_GAP_PX = 8
40
+ const VIEWPORT_PAD_PX = 8
41
+ const PANEL_MAX_WIDTH_PX = 460
42
+ const PANEL_MAX_HEIGHT_PX = 420
43
+
44
+
45
+ function Part({ part, labels }: { readonly part: CardPart; readonly labels: ReferenceLabels }): ReactNode {
46
+ if (part.kind === 'text') return part.value.content === undefined
47
+ ? <p className={css.quote} data-part-kind="text">{part.value.text}</p>
48
+ : <div className={css.quote} data-part-kind="text"><ReferenceText content={part.value.content} /></div>
49
+ if (part.kind === 'image') return part.value.bound
50
+ ? <figure data-part-kind="image"><img className={css.image} src={part.value.thumbnailSrc} alt={part.value.alt ?? labels.image} />
51
+ {part.value.caption !== undefined && <figcaption>{part.value.caption}</figcaption>}</figure>
52
+ : <p className={css.secondary} data-part-kind="image" role="status">{labels.loadingImage}</p>
53
+ const rows = referenceTableRows(part.value)
54
+ return <div className={css.tableScroll} data-part-kind="table" tabIndex={0} aria-label={part.value.caption ?? labels.table}>
55
+ <table className={css.table}>
56
+ {part.value.caption !== undefined && <caption>{part.value.caption}</caption>}
57
+ <tbody>{rows.map(({ row, cells }) => <tr key={row}>
58
+ {cells.map(({ column, columnSpan, rowSpan, value: cell }) => {
59
+ if (cell === undefined) return <td key={column} colSpan={columnSpan} />
60
+ const Cell = cell.role === 'header' ? 'th' : 'td'
61
+ return <Cell key={column} rowSpan={rowSpan} colSpan={columnSpan}>{cell.content === undefined ? cell.text : <ReferenceText content={cell.content} />}
62
+ {cell.inlineImages.map(image => image.thumbnailSrc === undefined
63
+ ? <span key={image.partId} className={css.secondary}>{labels.loadingImage}</span>
64
+ : <img key={image.partId} className={css.image} src={image.thumbnailSrc} alt={labels.image} />)}
65
+ </Cell>
66
+ })}
67
+ </tr>)}</tbody>
68
+ </table>
69
+ </div>
70
+ }
71
+
72
+ /** Presentation receives only data and callbacks; delivery and sending stay in the runtime. */
73
+ export function ReferenceCapsules({ sessionId, cards, actions, labels, notice, readOnly = true, anchor }: ReferenceCapsulesProps): ReactNode {
74
+ const [openId, setOpenId] = useState<string | undefined>(anchor === undefined ? undefined : cards[0]?.referenceId)
75
+ /** A click pins the card open so a touch user (and the note editor) keeps it. */
76
+ const [pinned, setPinned] = useState(false)
77
+ const [edit, setEdit] = useState<{ id: string; value: string }>()
78
+ const chips = useRef(new Map<string, HTMLButtonElement>())
79
+ const panel = useRef<HTMLDivElement | null>(null)
80
+ const closeTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
81
+ const id = useIdSafe()
82
+
83
+ const active = useMemo(() => cards.find(card => card.referenceId === openId), [cards, openId])
84
+
85
+ const clearTimer = useCallback(() => {
86
+ if (closeTimer.current !== undefined) { clearTimeout(closeTimer.current); closeTimer.current = undefined }
87
+ }, [])
88
+
89
+ const open = useCallback((referenceId: string) => {
90
+ clearTimer()
91
+ setOpenId(referenceId)
92
+ }, [clearTimer])
93
+
94
+ const scheduleClose = useCallback(() => {
95
+ if (pinned) return
96
+ clearTimer()
97
+ closeTimer.current = setTimeout(() => {
98
+ closeTimer.current = undefined
99
+ setOpenId(undefined)
100
+ setEdit(undefined)
101
+ }, CLOSE_DELAY_MS)
102
+ }, [clearTimer, pinned])
103
+
104
+ const close = useCallback(() => {
105
+ clearTimer()
106
+ setPinned(false)
107
+ setOpenId(undefined)
108
+ setEdit(undefined)
109
+ }, [clearTimer])
110
+
111
+ useEffect(() => () => { clearTimer() }, [clearTimer])
112
+
113
+ // The card floats over the composer instead of living in it. Placement is written STRAIGHT TO THE
114
+ // NODE: routing a measurement back through `setState` re-renders the card, and a render that can
115
+ // change measured geometry is exactly the measure→render→measure cycle that ends in
116
+ // "ResizeObserver loop completed with undelivered notifications". A `position: fixed` node cannot
117
+ // feed back into the layout it measured, so writing its style is final — no state, no second pass.
118
+ useLayoutEffect(() => {
119
+ const node = panel.current
120
+ if (openId === undefined || node === null) return
121
+ const measure = (): void => {
122
+ const chip = anchor ?? chips.current.get(openId)
123
+ if (chip === undefined) return
124
+ const rect = chip.getBoundingClientRect()
125
+ // A zero box means the pill is not laid out yet (or the host hides the composer). Fall back near
126
+ // the bottom-left corner so the card still renders rather than leaving the reference with no detail.
127
+ const laidOut = rect.width !== 0 || rect.height !== 0
128
+ const anchorTop = laidOut ? rect.top : window.innerHeight - 96
129
+ const anchorBottom = laidOut ? rect.bottom : anchorTop
130
+ const anchorLeft = laidOut ? rect.left : VIEWPORT_PAD_PX
131
+ const width = Math.max(240, Math.min(PANEL_MAX_WIDTH_PX, window.innerWidth - VIEWPORT_PAD_PX * 2))
132
+ const left = Math.min(Math.max(VIEWPORT_PAD_PX, anchorLeft), window.innerWidth - width - VIEWPORT_PAD_PX)
133
+ // Anchored by its BOTTOM edge so the card grows upward: the composer sits at the bottom of the
134
+ // window, a top-anchored card would open off-screen.
135
+ const bottom = Math.max(VIEWPORT_PAD_PX, window.innerHeight - anchorTop + PANEL_GAP_PX)
136
+ const below = readOnly && window.innerHeight - anchorBottom > anchorTop
137
+ const maxHeight = Math.min(PANEL_MAX_HEIGHT_PX, Math.max(140,
138
+ below ? window.innerHeight - anchorBottom - PANEL_GAP_PX - VIEWPORT_PAD_PX : anchorTop - VIEWPORT_PAD_PX * 2))
139
+ node.style.left = `${left}px`
140
+ node.style.bottom = below ? 'auto' : `${bottom}px`
141
+ node.style.top = below ? `${Math.max(VIEWPORT_PAD_PX, anchorBottom + PANEL_GAP_PX)}px` : 'auto'
142
+ node.style.width = `${width}px`
143
+ node.style.maxHeight = `${maxHeight}px`
144
+ }
145
+ measure()
146
+ window.addEventListener('resize', measure)
147
+ window.addEventListener('scroll', measure, true)
148
+ return () => {
149
+ window.removeEventListener('resize', measure)
150
+ window.removeEventListener('scroll', measure, true)
151
+ }
152
+ }, [openId, cards.length, anchor, readOnly])
153
+
154
+ useEffect(() => {
155
+ if (openId === undefined) return
156
+ const onKey = (event: KeyboardEvent): void => {
157
+ if (event.key !== 'Escape') return
158
+ if (edit !== undefined) { setEdit(undefined); return }
159
+ close()
160
+ }
161
+ const onPointerDown = (event: MouseEvent): void => {
162
+ const target = event.target as Node | null
163
+ if (target === null) return
164
+ if (panel.current?.contains(target) === true) return
165
+ if (anchor?.contains(target) === true) return
166
+ for (const chip of chips.current.values()) if (chip.contains(target)) return
167
+ close()
168
+ }
169
+ window.addEventListener('keydown', onKey)
170
+ window.addEventListener('mousedown', onPointerDown)
171
+ return () => {
172
+ window.removeEventListener('keydown', onKey)
173
+ window.removeEventListener('mousedown', onPointerDown)
174
+ }
175
+ }, [openId, edit, close, anchor])
176
+
177
+ useEffect(() => {
178
+ if (anchor === undefined) return
179
+ const enter = (): void => { if (cards[0] !== undefined) open(cards[0].referenceId) }
180
+ anchor.addEventListener('pointerenter', enter)
181
+ anchor.addEventListener('focus', enter)
182
+ anchor.addEventListener('pointerleave', scheduleClose)
183
+ anchor.addEventListener('blur', scheduleClose)
184
+ return () => {
185
+ anchor.removeEventListener('pointerenter', enter)
186
+ anchor.removeEventListener('focus', enter)
187
+ anchor.removeEventListener('pointerleave', scheduleClose)
188
+ anchor.removeEventListener('blur', scheduleClose)
189
+ }
190
+ }, [anchor, cards, open, scheduleClose])
191
+
192
+ const save = (): void => {
193
+ if (edit === undefined) return
194
+ actions.onEditComment?.(edit.id, edit.value)
195
+ setEdit(undefined)
196
+ }
197
+
198
+ // Nothing to draw: render NOTHING rather than an empty wrapper. The host seat
199
+ // is a flex row inside the composer card, and a zero-height child would still
200
+ // defeat the row's `:empty` collapse (and its -4px pull on the text surface).
201
+ // Never return null when empty: this component is the ONLY place the host's input face is handed to
202
+ // the runtime (`noteDockProps`), and the runtime needs that face to append a card. Returning null
203
+ // made it a chicken-and-egg loop — no cards, so no face, so no card could ever be appended, and the
204
+ // reference stayed a pending delivery forever. The empty host is invisible (the stylesheet hides an
205
+ // empty `.dock`), so nothing is drawn until a card exists.
206
+ if (cards.length === 0 && notice === undefined) {
207
+ return <div className={`dsh-browser-reference-dock ${css.dock}`} data-session={sessionId} data-cards={0} />
208
+ }
209
+
210
+ return <span className={readOnly ? 'dsh-browser-reference-capsules' : `dsh-browser-reference-dock ${css.dock}`} data-session={sessionId} data-cards={cards.length}>
211
+ {anchor === undefined && cards.length > 0 && <span className={readOnly ? css.sentRail : css.rail} role="group" aria-label={labels.count} data-count={cards.length}
212
+ data-pending={cards.some(card => card.state !== 'acknowledged') ? 'yes' : 'no'}>
213
+ {cards.map(card => <button
214
+ key={card.referenceId}
215
+ ref={(node) => {
216
+ if (node === null) chips.current.delete(card.referenceId)
217
+ else chips.current.set(card.referenceId, node)
218
+ }}
219
+ type="button"
220
+ className={css.chip}
221
+ data-reference-id={card.referenceId}
222
+ data-index={card.index}
223
+ data-has-note={card.comment !== undefined && card.comment !== '' ? 'yes' : 'no'}
224
+ aria-haspopup="dialog"
225
+ aria-expanded={openId === card.referenceId}
226
+ aria-controls={openId === card.referenceId ? `${id}-${card.index}` : undefined}
227
+ onMouseEnter={() => { open(card.referenceId) }}
228
+ onMouseLeave={scheduleClose}
229
+ onFocus={() => { open(card.referenceId) }}
230
+ onBlur={() => { if (!pinned) scheduleClose() }}
231
+ onClick={(event) => {
232
+ if (readOnly) {
233
+ if (!event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey) actions.onReveal?.(card.referenceId)
234
+ return
235
+ }
236
+ // Click pins the card (touch has no hover); a second click releases it.
237
+ if (openId === card.referenceId && pinned) { close(); return }
238
+ setPinned(true)
239
+ open(card.referenceId)
240
+ }}
241
+ >
242
+ <span className={css.badge} aria-hidden>{card.index}</span>
243
+ <span className={css.label}>{card.excerpt || card.source.title || card.source.host}</span>
244
+ {/* 这个位置原来是装饰性灰点:直接换成可点的删除键(交叉线由 CSS 画,避免字形缺失渲染成圆点)。 */}
245
+ {!readOnly && actions.onRemove !== undefined && <span
246
+ role="button"
247
+ tabIndex={0}
248
+ className={css.chipRemove}
249
+ aria-label={labels.removeDraft}
250
+ title={labels.removeDraft}
251
+ data-chip-remove={card.referenceId}
252
+ onClick={(event) => {
253
+ event.preventDefault()
254
+ event.stopPropagation()
255
+ actions.onRemove?.(card.referenceId)
256
+ }}
257
+ onKeyDown={(event) => {
258
+ if (event.key !== 'Enter' && event.key !== ' ') return
259
+ event.preventDefault()
260
+ event.stopPropagation()
261
+ actions.onRemove?.(card.referenceId)
262
+ }}
263
+ >
264
+ {/* 叉用内联 SVG 画:不依赖字体字形,也不依赖 CSS 伪元素(两者都曾导致它不可见)。 */}
265
+ <svg width="9" height="9" viewBox="0 0 9 9" aria-hidden="true" focusable="false">
266
+ <path d="M1 1 L8 8 M8 1 L1 8" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" fill="none" />
267
+ </svg>
268
+ </span>}
269
+
270
+ </button>)}
271
+ </span>}
272
+
273
+ {active !== undefined && typeof document !== 'undefined' && createPortal(
274
+ <div
275
+ id={`${id}-${active.index}`}
276
+ ref={node => { panel.current = node }}
277
+ className={css.panel}
278
+ role="dialog"
279
+ aria-label={`${active.index}. ${active.source.title || active.source.host}`}
280
+ // `position: fixed` is also in the stylesheet; inline keeps the card out of the
281
+ // composer's flow even if the stylesheet has not loaded yet. Left/bottom/width/maxHeight
282
+ // are written by the layout effect above, directly on this node.
283
+ style={{ position: 'fixed' }}
284
+ // The pointer may travel from the pill into the card: crossing the gap
285
+ // must not close it, or the note editor is unreachable by mouse.
286
+ onMouseEnter={() => { clearTimer() }}
287
+ onMouseLeave={scheduleClose}
288
+ onFocus={clearTimer}
289
+ onBlur={(event) => {
290
+ if (event.relatedTarget !== null && event.currentTarget.contains(event.relatedTarget)) return
291
+ scheduleClose()
292
+ }}
293
+ onKeyDown={(event) => { if (event.key === 'Escape') { event.stopPropagation(); close() } }}
294
+ >
295
+ <div className={css.head}>
296
+ <span className={css.badge} aria-hidden>{active.index}</span>
297
+ <div className={css.heading}>
298
+ <span className={css.title}>{active.source.title || active.source.host}</span>
299
+ <span className={css.host}>{active.source.host}</span>
300
+ </div>
301
+ {!readOnly && <div className={css.tools}>
302
+ <Tooltip label={labels.edit} portal><button type="button" aria-label={labels.edit} className={css.icon}
303
+ aria-pressed={edit?.id === active.referenceId}
304
+ onClick={() => {
305
+ setPinned(true)
306
+ setEdit(previous => previous?.id === active.referenceId
307
+ ? undefined
308
+ : { id: active.referenceId, value: active.comment ?? '' })
309
+ }}><IconEditOutlineRegular size={14} /></button></Tooltip>
310
+ {actions.onRemove !== undefined && <Tooltip label={labels.remove} portal><button type="button" aria-label={labels.remove} className={css.icon}
311
+ onClick={() => { close(); actions.onRemove?.(active.referenceId) }}><IconTrashOutlineRegular size={14} /></button></Tooltip>}
312
+ </div>}
313
+ </div>
314
+ <div className={css.parts}>{active.parts.map((part, index) => <Part key={`${part.kind}:${index}`} part={part} labels={labels} />)}</div>
315
+ {active.failures.length > 0 && <p className={css.notice} role="status">{labels.partial}</p>}
316
+ {edit?.id === active.referenceId ? <div className={css.editor}>
317
+ <label htmlFor={`${id}-${active.index}-note`}>{labels.comment}</label>
318
+ <textarea id={`${id}-${active.index}-note`} value={edit.value} rows={2} placeholder={labels.optional} autoFocus
319
+ onChange={(event) => { setEdit({ id: active.referenceId, value: event.currentTarget.value }) }}
320
+ onKeyDown={(event) => {
321
+ if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') { event.preventDefault(); save() }
322
+ // First Escape leaves the editor; the card stays open (a second one closes it).
323
+ if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); setEdit(undefined) }
324
+ }} />
325
+ <div className={css.editorActions}><button type="button" onClick={() => { setEdit(undefined) }}>{labels.cancel}</button><button type="button" onClick={save}>{labels.save}</button></div>
326
+ </div> : active.comment !== undefined && active.comment !== ''
327
+ ? <div className={css.comment}><span className={css.secondary}>{labels.comment}</span><p>{active.comment}</p></div>
328
+ : null}
329
+ <button type="button" className={css.source} title={active.source.pageUrl} onClick={() => { actions.onReveal?.(active.referenceId) }}>
330
+ <IconLinkOutlineRegular size={12} /><span>{labels.reveal}</span>
331
+ </button>
332
+ {(anchor !== undefined || readOnly) && notice !== undefined && <p className={css.status} role="status">{notice}</p>}
333
+ </div>,
334
+ document.body,
335
+ )}
336
+
337
+ {anchor === undefined && (!readOnly || active === undefined) && cards.length > 0 && notice !== undefined && <p className={css.status} role="status">{notice}</p>}
338
+ </span>
339
+ }
340
+
341
+ /** `useId` is React 18-only; the bundle also loads in hosts that pin 17. */
342
+ function useIdSafe(): string {
343
+ const [value] = useState(() => `dsh-ref-${Math.random().toString(36).slice(2, 9)}`)
344
+ return value
345
+ }