@vite-hub/ui 0.1.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/README.md +247 -21
  2. package/dist/attachments-BzTwqRTU.js +90 -0
  3. package/dist/{avatar-stack-DXmCQhxd.d.ts → avatar-stack-DPRFuezh.d.ts} +1 -1
  4. package/dist/choices-input-ByXJvDn1.d.ts +94 -0
  5. package/dist/{code-view-J4OsgEdh.js → code-view-DsU-xzic.js} +20 -4
  6. package/dist/colors-BghReA9C-CjF9gnmy.js +28 -0
  7. package/dist/comment-attachments-C4yNbcx5.js +20 -0
  8. package/dist/comment-composer-fINL5bxo.d.ts +243 -0
  9. package/dist/comment-composer-jYv2ULNP.js +591 -0
  10. package/dist/comment-layer-C_sbPIR5.d.ts +176 -0
  11. package/dist/comment-list-BcSaLngS.d.ts +62 -0
  12. package/dist/comment-marks.css +234 -0
  13. package/dist/comment-panel-CfvdRUMX.d.ts +208 -0
  14. package/dist/comment-person-CLPlW_SS.js +40 -0
  15. package/dist/comment-pin-DHOdRvUw.d.ts +68 -0
  16. package/dist/comment-row-Bn3nr8l5.js +39 -0
  17. package/dist/comment-selection-bar-CyVBNYl9.d.ts +42 -0
  18. package/dist/comment-thread-DKJjmWN0.d.ts +385 -0
  19. package/dist/comment-visibility-DsVuVndP.d.ts +40 -0
  20. package/dist/{comments-C08J3z4e.js → comments-D0d26ghV.js} +210 -59
  21. package/dist/comments-D8hulVPy.d.ts +198 -0
  22. package/dist/comments-context-C2lOZyQ5.js +38 -0
  23. package/dist/config-DgxBW013.d.ts +80 -0
  24. package/dist/config-Dk67emQt.js +63 -0
  25. package/dist/copy-button-CRN3kmSD.js +253 -0
  26. package/dist/draw-DzSmD7uo-Dwz8zoH2.js +72976 -0
  27. package/dist/editor-C_wt4RRV.js +582 -0
  28. package/dist/error-diagnostics-SXtnk6bz.js +38 -0
  29. package/dist/{file-tree-C1pv4_AI.js → file-tree-C4OYgbV-.js} +292 -145
  30. package/dist/{file-tree-Ctb8hZ_g.d.ts → file-tree-DlT9RGhu.d.ts} +51 -15
  31. package/dist/format-orwcdZL_.js +39 -0
  32. package/dist/handlers-DMl-Na3x.js +182 -0
  33. package/dist/headless.d.ts +5 -176
  34. package/dist/headless.js +5 -3
  35. package/dist/icon-swap.css +69 -0
  36. package/dist/{image-preview-VfknBEFu.js → image-preview-C9tdkmEj.js} +8 -5
  37. package/dist/{index-DcH0QSI5.d.ts → index-BYRFQfCd.d.ts} +14 -0
  38. package/dist/{code-view-vDM-hph-.d.ts → index-CNY1uNTh.d.ts} +14 -228
  39. package/dist/index.d.ts +55 -57
  40. package/dist/index.js +678 -25
  41. package/dist/markdown-editor-CMbNZOdN.js +2394 -0
  42. package/dist/markdown-editor-wQF0yD5o.d.ts +195 -0
  43. package/dist/markdown-editor.d.ts +108 -0
  44. package/dist/markdown-editor.js +3 -0
  45. package/dist/message-scroller-jrYN9dG9.d.ts +175 -0
  46. package/dist/nuxt-ui-DSQFzq3s.js +38 -0
  47. package/dist/nuxt.d.ts +84 -2
  48. package/dist/nuxt.js +243 -35
  49. package/dist/parts/components/agent-session.d.ts +254 -0
  50. package/dist/parts/components/agent-session.js +640 -0
  51. package/dist/{attachment-BBndG9_P.d.ts → parts/components/attachment.d.ts} +14 -15
  52. package/dist/{attachment-B3dXC7jM.js → parts/components/attachment.js} +6 -4
  53. package/dist/{avatar-stack.d.ts → parts/components/avatar-stack.d.ts} +1 -1
  54. package/dist/{avatar-stack-DM6HRnc0.js → parts/components/avatar-stack.js} +2 -5
  55. package/dist/{bubble-BJH2rfii.d.ts → parts/components/bubble.d.ts} +7 -8
  56. package/dist/{bubble-BPyFQlW7.js → parts/components/bubble.js} +2 -2
  57. package/dist/{chat-message-mpDmZbIC.d.ts → parts/components/chat-message.d.ts} +2 -3
  58. package/dist/{chat-message-BNK9G7xF.js → parts/components/chat-message.js} +4 -4
  59. package/dist/{chat-session-D6C7VJBR.d.ts → parts/components/chat-session.d.ts} +3 -4
  60. package/dist/{chat-session-DYEHB1HC.js → parts/components/chat-session.js} +2 -2
  61. package/dist/{chat-B9HlZWA2.d.ts → parts/components/chat.d.ts} +8 -4
  62. package/dist/{chat-BoFHlu9V.js → parts/components/chat.js} +42 -9
  63. package/dist/{highlighted-code-Dzf6o54i.d.ts → parts/components/code-block.d.ts} +15 -23
  64. package/dist/{code-block-Br-02hn-.js → parts/components/code-block.js} +9 -38
  65. package/dist/parts/components/code-view.d.ts +270 -0
  66. package/dist/parts/components/code-view.js +2 -0
  67. package/dist/parts/components/comment-composer.d.ts +2 -0
  68. package/dist/parts/components/comment-composer.js +2 -0
  69. package/dist/parts/components/comment-layer.d.ts +2 -0
  70. package/dist/parts/components/comment-layer.js +631 -0
  71. package/dist/parts/components/comment-list.d.ts +2 -0
  72. package/dist/parts/components/comment-list.js +168 -0
  73. package/dist/parts/components/comment-panel.d.ts +2 -0
  74. package/dist/parts/components/comment-panel.js +311 -0
  75. package/dist/parts/components/comment-pin.d.ts +2 -0
  76. package/dist/parts/components/comment-pin.js +75 -0
  77. package/dist/parts/components/comment-selection-bar.d.ts +2 -0
  78. package/dist/parts/components/comment-selection-bar.js +116 -0
  79. package/dist/parts/components/comment-thread.d.ts +2 -0
  80. package/dist/parts/components/comment-thread.js +598 -0
  81. package/dist/parts/components/comments.d.ts +8 -0
  82. package/dist/parts/components/comments.js +9 -0
  83. package/dist/{connection-status-DjGBw6xX.d.ts → parts/components/connection-status.d.ts} +6 -7
  84. package/dist/{connection-status-CzuWBENf.js → parts/components/connection-status.js} +1 -1
  85. package/dist/parts/components/copy-button.d.ts +118 -0
  86. package/dist/parts/components/copy-button.js +2 -0
  87. package/dist/parts/components/device-frame.d.ts +130 -0
  88. package/dist/parts/components/device-frame.js +471 -0
  89. package/dist/parts/components/file-tree.d.ts +2 -0
  90. package/dist/parts/components/file-tree.js +2 -0
  91. package/dist/parts/components/filter-search.d.ts +47 -0
  92. package/dist/parts/components/filter-search.js +58 -0
  93. package/dist/parts/components/markdown-editor.d.ts +2 -0
  94. package/dist/parts/components/markdown-editor.js +2 -0
  95. package/dist/parts/components/markdown-renderer.d.ts +52 -0
  96. package/dist/parts/components/markdown-renderer.js +23077 -0
  97. package/dist/{markdown-Dse5ldJe.d.ts → parts/components/markdown.d.ts} +7 -7
  98. package/dist/parts/components/markdown.js +47 -0
  99. package/dist/{marker-ea-tvx-J.d.ts → parts/components/marker.d.ts} +6 -7
  100. package/dist/{marker-Di2ZG_k1.js → parts/components/marker.js} +2 -2
  101. package/dist/{message-parts-BBFUkluC.d.ts → parts/components/message-parts.d.ts} +2 -3
  102. package/dist/{message-parts-DQnfioAH.js → parts/components/message-parts.js} +6 -6
  103. package/dist/{message-CW_paC1k.d.ts → parts/components/message.d.ts} +8 -9
  104. package/dist/{message-DiyBthIq.js → parts/components/message.js} +2 -2
  105. package/dist/parts/components/patch-parsers.d.ts +2 -0
  106. package/dist/parts/components/patch-parsers.js +2 -0
  107. package/dist/{prompt-input-Cy_Ue6B5.d.ts → parts/components/prompt-input.d.ts} +53 -10
  108. package/dist/{prompt-input-BbnCb80O.js → parts/components/prompt-input.js} +66 -111
  109. package/dist/parts/components/relative-time.d.ts +73 -0
  110. package/dist/parts/components/relative-time.js +2 -0
  111. package/dist/parts/components/status.d.ts +60 -0
  112. package/dist/parts/components/status.js +48 -0
  113. package/dist/{sync-status-refELOZn.d.ts → parts/components/sync-status.d.ts} +5 -6
  114. package/dist/{sync-status-BpxYdZIJ.js → parts/components/sync-status.js} +1 -1
  115. package/dist/{tool-list-E7CA52rz.d.ts → parts/components/tool-list.d.ts} +3 -4
  116. package/dist/{tool-list-BdSr5CT4.js → parts/components/tool-list.js} +7 -38
  117. package/dist/{trace-run-COeXn46Z.d.ts → parts/components/trace-run.d.ts} +3 -4
  118. package/dist/{trace-run-BIQ17CED.js → parts/components/trace-run.js} +15 -23
  119. package/dist/{trace-V7rM3Pyd.d.ts → parts/components/trace.d.ts} +11 -12
  120. package/dist/{trace-llBCDiSW.js → parts/components/trace.js} +20 -13
  121. package/dist/parts/composables/attachments.d.ts +32 -0
  122. package/dist/parts/composables/attachments.js +2 -0
  123. package/dist/parts/composables/highlighted-code.d.ts +9 -0
  124. package/dist/{highlighted-code-Ck4zexJX.js → parts/composables/highlighted-code.js} +5 -2
  125. package/dist/parts/headless/choices-input.d.ts +2 -0
  126. package/dist/parts/headless/choices-input.js +162 -0
  127. package/dist/parts/headless/comment-visibility.d.ts +2 -0
  128. package/dist/parts/headless/comment-visibility.js +128 -0
  129. package/dist/parts/headless/comments.d.ts +2 -0
  130. package/dist/parts/headless/comments.js +2 -0
  131. package/dist/parts/headless/message-scroller.d.ts +2 -0
  132. package/dist/{message-scroller-CX6NJTdm.js → parts/headless/message-scroller.js} +2 -2
  133. package/dist/parts/playground/highlight.d.ts +5 -0
  134. package/dist/parts/playground/highlight.js +23 -0
  135. package/dist/parts/playground/paths.d.ts +4 -0
  136. package/dist/parts/playground/paths.js +7 -0
  137. package/dist/parts/playground/playground-render.d.ts +126 -0
  138. package/dist/parts/playground/playground-render.js +356 -0
  139. package/dist/parts/playground/share.d.ts +2 -0
  140. package/dist/parts/playground/share.js +92 -0
  141. package/dist/parts/playground/zip.d.ts +6 -0
  142. package/dist/parts/playground/zip.js +76 -0
  143. package/dist/parts/workspace/browser-support-notice.d.ts +76 -0
  144. package/dist/parts/workspace/browser-support-notice.js +105 -0
  145. package/dist/parts/workspace/codemirror.d.ts +16 -0
  146. package/dist/parts/workspace/codemirror.js +243 -0
  147. package/dist/parts/workspace/connect-panel.d.ts +129 -0
  148. package/dist/parts/workspace/connect-panel.js +285 -0
  149. package/dist/parts/workspace/connect-store.d.ts +26 -0
  150. package/dist/parts/workspace/connect-store.js +59 -0
  151. package/dist/parts/workspace/icons.d.ts +34 -0
  152. package/dist/parts/workspace/icons.js +46 -0
  153. package/dist/parts/workspace/playground-container.d.ts +192 -0
  154. package/dist/parts/workspace/playground-container.js +603 -0
  155. package/dist/parts/workspace/workspace-boot-status.d.ts +75 -0
  156. package/dist/parts/workspace/workspace-boot-status.js +207 -0
  157. package/dist/parts/workspace/workspace-editor.d.ts +43 -0
  158. package/dist/parts/workspace/workspace-editor.js +54 -0
  159. package/dist/parts/workspace/workspace-file-tree.d.ts +53 -0
  160. package/dist/parts/workspace/workspace-file-tree.js +68 -0
  161. package/dist/parts/workspace/workspace-preview.d.ts +72 -0
  162. package/dist/parts/workspace/workspace-preview.js +307 -0
  163. package/dist/parts/workspace/workspace-shell.d.ts +88 -0
  164. package/dist/parts/workspace/workspace-shell.js +291 -0
  165. package/dist/parts/workspace/workspace-terminal.d.ts +39 -0
  166. package/dist/parts/workspace/workspace-terminal.js +130 -0
  167. package/dist/payload-text-sjkYAwvw.js +32 -0
  168. package/dist/{pierre-code-view-T7V67hwT.js → pierre-code-view-NE35tkmR.js} +245 -102
  169. package/dist/{pierre-dark-DDWDl8g6.js → pierre-dark-CzUmjETS.js} +3 -1
  170. package/dist/{pierre-light-CWhW4NrH.js → pierre-light-Dn6E0sWv.js} +3 -1
  171. package/dist/playground.d.ts +4 -0
  172. package/dist/playground.js +4 -0
  173. package/dist/relative-time-BVmjOsYG.js +309 -0
  174. package/dist/rolldown-runtime-C9mWXvCC.js +29 -0
  175. package/dist/runtime/nuxt-plugin.js +23 -4
  176. package/dist/sankey-CAYwt82B-D4uDQoMR.js +2887 -0
  177. package/dist/share-DM4eNy4q.d.ts +37 -0
  178. package/dist/{slot-part-C7Ocxn3b.js → slot-part-Doic71uh.js} +7 -1
  179. package/dist/styles.css +2609 -620
  180. package/dist/temml-BilSAAws.js +12362 -0
  181. package/dist/theme-focus-ring.css +42 -0
  182. package/dist/theme.css +376 -0
  183. package/dist/theme.d.ts +355 -0
  184. package/dist/theme.js +265 -0
  185. package/dist/{types-CqDwuJAm.d.ts → types-Dj7vp0lZ.d.ts} +1 -1
  186. package/dist/vue-BDmSCtay.js +30779 -0
  187. package/dist/vue-DGstVdGn.js +2492 -0
  188. package/dist/workspace.d.ts +15 -0
  189. package/dist/workspace.js +12 -0
  190. package/package.json +135 -149
  191. package/dist/andromeeda-BASpqCeJ.js +0 -4
  192. package/dist/attachment.d.ts +0 -2
  193. package/dist/attachment.js +0 -2
  194. package/dist/aurora-x-DugsLcii.js +0 -4
  195. package/dist/avatar-stack.js +0 -2
  196. package/dist/ayu-dark-BT3qdi3o.js +0 -4
  197. package/dist/ayu-light-BVZyHoh9.js +0 -4
  198. package/dist/ayu-mirage-XFwUVZQZ.js +0 -4
  199. package/dist/bubble.d.ts +0 -2
  200. package/dist/bubble.js +0 -2
  201. package/dist/catppuccin-frappe-D20KODDN.js +0 -4
  202. package/dist/catppuccin-latte-eGLVHIUJ.js +0 -4
  203. package/dist/catppuccin-macchiato-bQGch4PY.js +0 -4
  204. package/dist/catppuccin-mocha-Bes8-0Mr.js +0 -4
  205. package/dist/chat-message.d.ts +0 -2
  206. package/dist/chat-message.js +0 -2
  207. package/dist/chat-session.d.ts +0 -2
  208. package/dist/chat-session.js +0 -2
  209. package/dist/chat.d.ts +0 -2
  210. package/dist/chat.js +0 -2
  211. package/dist/code-block.d.ts +0 -2
  212. package/dist/code-block.js +0 -3
  213. package/dist/code-view.d.ts +0 -2
  214. package/dist/code-view.js +0 -2
  215. package/dist/comment-layer-CBlxJ8eK.js +0 -1113
  216. package/dist/comments-ChNJkV1d.d.ts +0 -108
  217. package/dist/comments-Cq5eewsu.d.ts +0 -537
  218. package/dist/comments.d.ts +0 -2
  219. package/dist/comments.js +0 -2
  220. package/dist/config-Bux_AJzm.d.ts +0 -29
  221. package/dist/config-bHqE4JOs.js +0 -38
  222. package/dist/connection-status.d.ts +0 -2
  223. package/dist/connection-status.js +0 -2
  224. package/dist/dark-plus-BGuiqa1B.js +0 -4
  225. package/dist/dracula-0CVA2XY5.js +0 -4
  226. package/dist/dracula-soft-Dk9bpbVU.js +0 -4
  227. package/dist/error-diagnostics-B4hMpJRL.js +0 -13
  228. package/dist/everforest-dark-CRjTbhh5.js +0 -4
  229. package/dist/everforest-light-CEeYFLn8.js +0 -4
  230. package/dist/file-diff.d.ts +0 -2
  231. package/dist/file-diff.js +0 -2
  232. package/dist/file-tree.d.ts +0 -2
  233. package/dist/file-tree.js +0 -2
  234. package/dist/file-view.d.ts +0 -2
  235. package/dist/file-view.js +0 -2
  236. package/dist/github-dark-BXgKmOw_.js +0 -4
  237. package/dist/github-dark-default-DzJQXksd.js +0 -4
  238. package/dist/github-dark-dimmed-B1pEmGtS.js +0 -4
  239. package/dist/github-dark-high-contrast-BkHIa6jc.js +0 -4
  240. package/dist/github-light-BKRlUbaB.js +0 -4
  241. package/dist/github-light-default-BU3eYkzs.js +0 -4
  242. package/dist/github-light-high-contrast-B3MumDcI.js +0 -4
  243. package/dist/gruvbox-dark-hard-B0ecF443.js +0 -4
  244. package/dist/gruvbox-dark-medium-BQnpC39k.js +0 -4
  245. package/dist/gruvbox-dark-soft-DFZUgESr.js +0 -4
  246. package/dist/gruvbox-light-hard-CuB_LOJr.js +0 -4
  247. package/dist/gruvbox-light-medium-idDHgxjs.js +0 -4
  248. package/dist/gruvbox-light-soft-CfWH49MY.js +0 -4
  249. package/dist/horizon-bright-Ba6M8QSV.js +0 -4
  250. package/dist/horizon-h92C5OlZ.js +0 -4
  251. package/dist/houston-EQnPegWq.js +0 -4
  252. package/dist/kanagawa-dragon-DgDvwi3B.js +0 -4
  253. package/dist/kanagawa-lotus-BgoQro20.js +0 -4
  254. package/dist/kanagawa-wave-DgXEowHs.js +0 -4
  255. package/dist/laserwave-IxBH_3yW.js +0 -4
  256. package/dist/light-plus-S8JBx6is.js +0 -4
  257. package/dist/markdown-BoLBN0qH.js +0 -197
  258. package/dist/markdown.d.ts +0 -2
  259. package/dist/markdown.js +0 -2
  260. package/dist/marker.d.ts +0 -2
  261. package/dist/marker.js +0 -2
  262. package/dist/material-theme-D1f3HBq-.js +0 -4
  263. package/dist/material-theme-darker-ExzYhT0j.js +0 -4
  264. package/dist/material-theme-lighter-D6gH9nnA.js +0 -4
  265. package/dist/material-theme-ocean-D1w5BPAa.js +0 -4
  266. package/dist/material-theme-palenight-CkqWmVpF.js +0 -4
  267. package/dist/message-parts.d.ts +0 -2
  268. package/dist/message-parts.js +0 -2
  269. package/dist/message.d.ts +0 -2
  270. package/dist/message.js +0 -2
  271. package/dist/min-dark-npsJH98j.js +0 -4
  272. package/dist/min-light-DUk1XsVt.js +0 -4
  273. package/dist/monokai-CfFRWUNl.js +0 -4
  274. package/dist/multi-file-diff.d.ts +0 -2
  275. package/dist/multi-file-diff.js +0 -2
  276. package/dist/night-owl-BS7V-av_.js +0 -4
  277. package/dist/night-owl-light-CZtRawYE.js +0 -4
  278. package/dist/nord-BFh54Nqz.js +0 -4
  279. package/dist/one-dark-pro-zDovGosB.js +0 -4
  280. package/dist/one-light-gmHK3iK6.js +0 -4
  281. package/dist/patch-diff.d.ts +0 -2
  282. package/dist/patch-diff.js +0 -2
  283. package/dist/plastic-DtdaCjub.js +0 -4
  284. package/dist/poimandres-Hdda6aHK.js +0 -4
  285. package/dist/primitive-rail.d.ts +0 -222
  286. package/dist/primitive-rail.js +0 -348
  287. package/dist/prompt-input.d.ts +0 -2
  288. package/dist/prompt-input.js +0 -2
  289. package/dist/red-VqZFRByZ.js +0 -4
  290. package/dist/rose-pine-DiTkEueR.js +0 -4
  291. package/dist/rose-pine-dawn-tfo5y2X0.js +0 -4
  292. package/dist/rose-pine-moon-C0gON9XN.js +0 -4
  293. package/dist/runtime-type-DlCscMfw.js +0 -59
  294. package/dist/slack-dark-v8P_eXr6.js +0 -4
  295. package/dist/slack-ochin-D8SyEdKz.js +0 -4
  296. package/dist/snazzy-light-BtkQkvXb.js +0 -4
  297. package/dist/solarized-dark-B8nAdMfM.js +0 -4
  298. package/dist/solarized-light-B-3F1INj.js +0 -4
  299. package/dist/sync-status.d.ts +0 -2
  300. package/dist/sync-status.js +0 -2
  301. package/dist/synthwave-84-DcsXCF_c.js +0 -4
  302. package/dist/tokyo-night-Bvpqduda.js +0 -4
  303. package/dist/tool-list.d.ts +0 -2
  304. package/dist/tool-list.js +0 -2
  305. package/dist/trace-run.d.ts +0 -2
  306. package/dist/trace-run.js +0 -2
  307. package/dist/trace.d.ts +0 -2
  308. package/dist/trace.js +0 -2
  309. package/dist/unresolved-file.d.ts +0 -2
  310. package/dist/unresolved-file.js +0 -2
  311. package/dist/vesper-CfxmMOy3.js +0 -4
  312. package/dist/vitesse-black-D9-_1mjV.js +0 -4
  313. package/dist/vitesse-dark-DlSMLlr9.js +0 -4
  314. package/dist/vitesse-light-KRWWWztf.js +0 -4
@@ -1,39 +1,68 @@
1
- import { t as uiErrorDiagnostics } from "./error-diagnostics-B4hMpJRL.js";
2
- import { computed, getCurrentInstance, inject, onBeforeUnmount, onMounted, provide, reactive, ref, shallowRef, toRaw, toValue, watch } from "vue";
1
+ import { t as uiErrorDiagnostics } from "./error-diagnostics-SXtnk6bz.js";
2
+ import { i as hasDirtyComposer, n as injectComments, o as shakeDirtyComposers, t as commentsKey } from "./comments-context-C2lOZyQ5.js";
3
+ import { createCommentVisibility } from "./parts/headless/comment-visibility.js";
4
+ import { computed, getCurrentInstance, isRef, onBeforeUnmount, onMounted, provide, reactive, ref, shallowRef, toRaw, toValue, watch } from "vue";
3
5
  import { createAnchor, resolveAnchor } from "@vite-hub/comments/client";
4
- //#region src/internal/comment-outside.ts
5
- const consumedPointerEvents = /* @__PURE__ */ new WeakSet();
6
- function swallowNextClick() {
7
- const stop = (event) => {
8
- event.stopPropagation();
9
- event.preventDefault();
10
- cleanup();
11
- };
12
- const cleanup = () => {
13
- document.removeEventListener("click", stop, true);
14
- document.removeEventListener("pointerdown", cleanup, true);
15
- };
16
- document.addEventListener("click", stop, true);
17
- document.addEventListener("pointerdown", cleanup, true);
6
+ //#region src/internal/comment-selection.ts
7
+ function commentThreadKey(thread) {
8
+ return thread.requestId === void 0 ? thread.id : JSON.stringify([
9
+ thread.subject.kind,
10
+ thread.subject.id,
11
+ thread.author.id,
12
+ thread.requestId
13
+ ]);
18
14
  }
19
- function useDocumentPointerDown(handler) {
20
- onMounted(() => document.addEventListener("pointerdown", handler, true));
21
- onBeforeUnmount(() => document.removeEventListener("pointerdown", handler, true));
15
+ function useSelectedComment(threads, id) {
16
+ const selection = computed((previous) => {
17
+ const selectedId = id.value;
18
+ const items = threads.value;
19
+ const direct = items.find((thread) => thread.id === selectedId);
20
+ const last = previous?.id === selectedId ? previous.thread : void 0;
21
+ const key = last?.requestId === void 0 ? void 0 : commentThreadKey(last);
22
+ return {
23
+ id: selectedId,
24
+ thread: direct ?? (key === void 0 ? void 0 : items.find((thread) => commentThreadKey(thread) === key))
25
+ };
26
+ });
27
+ return computed(() => selection.value.thread);
22
28
  }
23
- const shakeEventName = "comments:shake";
24
- const dirtySelector = "[data-slot='comment-composer'][data-dirty='true']";
25
- function hasDirtyComposer(root = document) {
26
- return root.querySelector(dirtySelector) !== null;
29
+ //#endregion
30
+ //#region src/internal/comment-status.ts
31
+ /** The messages written after the thread was resolved. Empty for an open thread. */
32
+ function messagesSinceResolved(thread) {
33
+ const { resolvedAt } = thread;
34
+ if (thread.status !== "resolved" || resolvedAt === void 0) return [];
35
+ return thread.messages.filter((message) => message.createdAt > resolvedAt);
36
+ }
37
+ /**
38
+ * Whether someone replied after the thread was resolved, such as an agent that says what it changed. The thread stays
39
+ * resolved, and lists show it with the open threads until someone resolves it again.
40
+ */
41
+ const repliedSinceResolved = (thread) => messagesSinceResolved(thread).length > 0;
42
+ /** "Comment 3". A comment that waits in the outbox has no number yet. */
43
+ function commentTitle(thread) {
44
+ return thread.n ? `Comment ${thread.n}` : "Comment";
27
45
  }
28
- function shakeDirtyComposers(root = document) {
29
- const dirty = [...root.querySelectorAll(dirtySelector)];
30
- for (const composer of dirty) composer.dispatchEvent(new CustomEvent(shakeEventName));
31
- return dirty.length > 0;
46
+ /** `data-pending` or `data-failed` for a thread, message, or row that the outbox holds. */
47
+ function deliveryAttributes(delivery) {
48
+ return {
49
+ "data-failed": delivery?.status === "failed" ? "true" : void 0,
50
+ "data-pending": delivery?.status === "pending" ? "true" : void 0
51
+ };
32
52
  }
33
- const pathOf = (event) => event.composedPath().filter((node) => node instanceof Element);
34
53
  //#endregion
35
54
  //#region src/headless/comments.ts
36
- const commentsKey = Symbol("ViteHubComments");
55
+ /**
56
+ * The permissions that the parts assume without a `can` option: a signed-in user may reply to and resolve any thread,
57
+ * and edit and delete their own messages. Nobody may do anything without a user.
58
+ */
59
+ function defaultCommentCan(user) {
60
+ return (action, { message }) => {
61
+ if (!user) return false;
62
+ if (action === "edit" || action === "delete") return message?.author.id === user.id;
63
+ return true;
64
+ };
65
+ }
37
66
  const draftPositionKey = "draft";
38
67
  const uiSelector = "[data-comments-ui]";
39
68
  function defaultIgnore(element) {
@@ -83,14 +112,27 @@ function useComments(options) {
83
112
  });
84
113
  const status = ref(client.status);
85
114
  const threads = shallowRef(client.threads);
115
+ const outboxEntries = shallowRef(client.outbox?.entries ?? []);
86
116
  const positions = shallowRef(/* @__PURE__ */ new Map());
87
117
  const draft = ref(null);
88
118
  const openId = ref(null);
119
+ const retained = shallowRef(/* @__PURE__ */ new Map());
120
+ const retainedIds = computed(() => new Set(retained.value.values()));
121
+ const retainMark = (id) => {
122
+ const key = Symbol();
123
+ retained.value = new Map(retained.value).set(key, id);
124
+ return () => {
125
+ const next = new Map(retained.value);
126
+ next.delete(key);
127
+ retained.value = next;
128
+ };
129
+ };
89
130
  const hoverId = ref(null);
90
131
  const listOpen = ref(false);
91
132
  const blocked = ref(0);
133
+ const isOpen = (thread) => thread.status === "open" || repliedSinceResolved(thread);
92
134
  const passes = (thread) => {
93
- if (thread.status === "open" ? !filters.open : !filters.resolved) return false;
135
+ if (!(filters.open && isOpen(thread) || filters.resolved && thread.status === "resolved")) return false;
94
136
  return !filters.mine || thread.author.id === user.value?.id;
95
137
  };
96
138
  const onPage = (thread) => sameSubject(thread.subject, subject.value);
@@ -99,26 +141,56 @@ function useComments(options) {
99
141
  const counts = computed(() => {
100
142
  const scoped = threads.value.filter((thread) => scope.value === "site" || onPage(thread));
101
143
  return {
102
- open: scoped.filter((thread) => thread.status === "open").length,
144
+ open: scoped.filter(isOpen).length,
103
145
  resolved: scoped.filter((thread) => thread.status === "resolved").length
104
146
  };
105
147
  });
106
- const opened = computed(() => threads.value.find((thread) => thread.id === openId.value));
148
+ const opened = useSelectedComment(threads, openId);
149
+ watch(opened, (thread) => {
150
+ if (thread && thread.id !== openId.value) openId.value = thread.id;
151
+ }, { flush: "sync" });
152
+ const visibility = isRef(options.visibility) ? options.visibility : ref(options.visibility ?? "all");
153
+ const seen = createCommentVisibility({
154
+ visibility: visibility.value,
155
+ flashMs: options.flashMs
156
+ });
157
+ const seenChanges = ref(0);
158
+ seen.subscribe(() => seenChanges.value++);
159
+ watch(visibility, (value) => seen.set(value), { flush: "sync" });
160
+ watch(openId, (id) => seen.open(id), { flush: "sync" });
161
+ watch(hoverId, (id) => seen.hover(id), { flush: "sync" });
162
+ const marked = computed(() => {
163
+ seenChanges.value;
164
+ const ids = new Set(pageThreads.value.map((thread) => thread.id));
165
+ if (opened.value && onPage(opened.value)) ids.add(opened.value.id);
166
+ for (const thread of threads.value) {
167
+ const temporary = visibility.value === "hidden" && (seen.isShown(thread.id) || seen.leaving.includes(thread.id));
168
+ if (onPage(thread) && (retainedIds.value.has(thread.id) || temporary)) ids.add(thread.id);
169
+ }
170
+ return ids;
171
+ });
172
+ const shown = computed(() => {
173
+ seenChanges.value;
174
+ return new Set([...marked.value].filter((id) => seen.isShown(id) || retainedIds.value.has(id)));
175
+ });
176
+ const leaving = computed(() => {
177
+ seenChanges.value;
178
+ return new Set(seen.leaving.filter((id) => marked.value.has(id) && !retainedIds.value.has(id)));
179
+ });
180
+ const flash = (id) => seen.flash(id);
107
181
  const root = () => toValue(options.root) ?? document;
108
182
  const uiRoot = () => toValue(options.uiRoot) ?? document;
109
183
  function measure() {
110
184
  const next = /* @__PURE__ */ new Map();
111
- for (const thread of pageThreads.value) next.set(thread.id, resolveAnchor(thread.anchor, root()));
112
- const current = opened.value;
113
- if (current && onPage(current) && !next.has(current.id)) next.set(current.id, resolveAnchor(current.anchor, root()));
185
+ for (const thread of threads.value.filter((thread) => marked.value.has(thread.id))) next.set(thread.id, resolveAnchor(thread.anchor, root()));
114
186
  if (draft.value) next.set(draftPositionKey, resolveAnchor(draft.value.anchor, root()));
115
187
  const previous = positions.value;
116
188
  if (!(next.size === previous.size && [...next].every(([key, position]) => samePosition(position, previous.get(key))))) positions.value = next;
117
189
  }
118
190
  const hasText = () => (draft.value?.body.trim().length ?? 0) > 0 || hasDirtyComposer(uiRoot());
119
- const block = () => {
191
+ const block = (escape = false) => {
120
192
  blocked.value++;
121
- shakeDirtyComposers(uiRoot());
193
+ shakeDirtyComposers(uiRoot(), escape);
122
194
  };
123
195
  function enter() {
124
196
  active.value = true;
@@ -126,13 +198,15 @@ function useComments(options) {
126
198
  if (selection && !selection.isCollapsed && selection.rangeCount > 0) {
127
199
  const container = selection.getRangeAt(0).commonAncestorContainer;
128
200
  const element = container instanceof Element ? container : container.parentElement;
129
- if (element && !ignore(element)) {
201
+ if (element?.isConnected && !ignore(element)) {
130
202
  const rect = selection.getRangeAt(0).getBoundingClientRect();
131
- startDraft(selection, { point: {
132
- x: rect.left,
133
- y: rect.top
134
- } });
135
- selection.removeAllRanges();
203
+ try {
204
+ startDraft(selection, { point: {
205
+ x: rect.left,
206
+ y: rect.top
207
+ } });
208
+ selection.removeAllRanges();
209
+ } catch {}
136
210
  }
137
211
  }
138
212
  }
@@ -148,8 +222,8 @@ function useComments(options) {
148
222
  hoverId.value = null;
149
223
  return true;
150
224
  }
151
- function exit() {
152
- if (hasText()) return block();
225
+ function exit(escape = false) {
226
+ if (hasText()) return block(escape);
153
227
  cancelDraft();
154
228
  close();
155
229
  active.value = false;
@@ -158,7 +232,7 @@ function useComments(options) {
158
232
  if (active.value) exit();
159
233
  else enter();
160
234
  }
161
- function startDraft(target, anchorOptions = {}) {
235
+ function startDraft(target, { files, ...anchorOptions } = {}) {
162
236
  if (hasText()) return block();
163
237
  close();
164
238
  const anchor = createAnchor(target, {
@@ -186,17 +260,21 @@ function useComments(options) {
186
260
  point,
187
261
  body: "",
188
262
  mentions: [],
263
+ attachments: [],
264
+ ...files?.length ? { files } : {},
189
265
  busy: false,
190
266
  error: void 0
191
267
  };
192
268
  measure();
193
269
  }
194
- async function send() {
270
+ async function send(sendOptions = {}) {
195
271
  const current = draft.value;
196
272
  const body = current?.body.trim() ?? "";
197
- if (!current || current.busy || !body) return void 0;
273
+ const files = sendOptions.files ?? [];
274
+ if (!current || current.busy || !body && current.attachments.length === 0 && files.length === 0) return void 0;
198
275
  const submittedBody = current.body;
199
276
  const mentions = [...current.mentions];
277
+ const attachments = [...current.attachments];
200
278
  current.busy = true;
201
279
  current.error = void 0;
202
280
  try {
@@ -204,9 +282,12 @@ function useComments(options) {
204
282
  subject: subject.value,
205
283
  anchor: toRaw(current.anchor),
206
284
  body,
207
- mentions
285
+ mentions,
286
+ ...attachments.length > 0 ? { attachments } : {},
287
+ ...files.length > 0 ? { files } : {}
208
288
  });
209
289
  current.busy = false;
290
+ flash(thread.id);
210
291
  if (draft.value === current && current.body === submittedBody && current.mentions.length === mentions.length && current.mentions.every((id, index) => id === mentions[index])) draft.value = null;
211
292
  return thread;
212
293
  } catch (error) {
@@ -267,7 +348,7 @@ function useComments(options) {
267
348
  const origin = path[0];
268
349
  if (event.key === "Escape") {
269
350
  if (path.some((element) => element.matches("[data-slot='comment-composer']"))) return;
270
- if (active.value || draft.value || openId.value) exit();
351
+ if (active.value || draft.value || openId.value) exit(true);
271
352
  return;
272
353
  }
273
354
  if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey || isEditable(path)) return;
@@ -288,6 +369,7 @@ function useComments(options) {
288
369
  stops.push(client.onChange(() => {
289
370
  status.value = client.status;
290
371
  threads.value = client.threads;
372
+ outboxEntries.value = client.outbox?.entries ?? [];
291
373
  }));
292
374
  status.value = client.status;
293
375
  threads.value = client.threads;
@@ -314,6 +396,7 @@ function useComments(options) {
314
396
  applyDeepLink();
315
397
  };
316
398
  window.addEventListener("popstate", onPopstate);
399
+ stops.push(watch(() => options.location?.().search, onPopstate));
317
400
  const observer = new MutationObserver((records) => {
318
401
  if (records.every((record) => record.target instanceof Element && defaultIgnore(record.target))) return;
319
402
  schedule();
@@ -357,10 +440,11 @@ function useComments(options) {
357
440
  resizes?.disconnect();
358
441
  clearTimeout(revealTimer);
359
442
  if (frame) cancelAnimationFrame(frame);
443
+ seen.stop();
360
444
  });
361
445
  stops.push(watch(positions, follow, { flush: "post" }));
362
446
  stops.push(watch([
363
- pageThreads,
447
+ marked,
364
448
  () => draft.value?.anchor,
365
449
  openId
366
450
  ], () => measure(), { flush: "post" }));
@@ -377,15 +461,58 @@ function useComments(options) {
377
461
  for (const stop of stops.splice(0)) stop();
378
462
  };
379
463
  }
464
+ const found = shallowRef(/* @__PURE__ */ new Map());
465
+ const people = computed(() => {
466
+ const known = /* @__PURE__ */ new Map();
467
+ const add = (person) => {
468
+ if (person && (!known.has(person.id) || person.name)) known.set(person.id, person);
469
+ };
470
+ for (const person of found.value.values()) add(person);
471
+ for (const person of toValue(options.people) ?? []) add(person);
472
+ for (const thread of threads.value) {
473
+ add(thread.author);
474
+ add(thread.resolvedBy);
475
+ for (const message of thread.messages) add(message.author);
476
+ }
477
+ add(user.value);
478
+ return [...known.values()];
479
+ });
480
+ async function users(query, threadId) {
481
+ const result = await client.users({
482
+ query,
483
+ ...threadId ? { threadId } : { subject: subject.value }
484
+ });
485
+ if (result.some((person) => found.value.get(person.id) !== person)) {
486
+ const next = new Map(found.value);
487
+ for (const person of result) next.set(person.id, person);
488
+ found.value = next;
489
+ }
490
+ return result;
491
+ }
492
+ const can = (action, target) => user.value !== void 0 && (options.can ?? defaultCommentCan(user.value))(action, target);
380
493
  const state = {
381
494
  client,
382
495
  subject,
383
496
  user,
497
+ can,
498
+ people,
384
499
  active,
385
500
  scope,
386
501
  filters,
387
502
  status,
388
503
  threads,
504
+ outbox: {
505
+ enabled: client.outbox !== void 0,
506
+ queued: computed(() => outboxEntries.value.filter((entry) => entry.status !== "failed")),
507
+ failures: computed(() => outboxEntries.value.filter((entry) => entry.status === "failed")),
508
+ delivery(threadId, messageId) {
509
+ const thread = threads.value.find((item) => item.id === threadId);
510
+ return messageId === void 0 ? thread?.delivery : thread?.messages.find((item) => item.id === messageId)?.delivery;
511
+ },
512
+ retry: async (id) => client.outbox?.retry(id),
513
+ dismiss: async (id) => await client.outbox?.dismiss(id) ?? false,
514
+ edit: async (id, body, mentions) => await client.outbox?.edit(id, body, mentions) ?? false
515
+ },
389
516
  pageThreads,
390
517
  listed,
391
518
  counts,
@@ -396,6 +523,12 @@ function useComments(options) {
396
523
  opened,
397
524
  listOpen,
398
525
  blocked,
526
+ visibility,
527
+ shown,
528
+ leaving,
529
+ retainMark,
530
+ isShown: (id) => shown.value.has(id),
531
+ flash,
399
532
  enter,
400
533
  exit,
401
534
  toggle,
@@ -404,11 +537,29 @@ function useComments(options) {
404
537
  send,
405
538
  open,
406
539
  close,
407
- reply: (threadId, body, mentions) => client.reply({
408
- threadId,
409
- body,
410
- mentions
411
- }),
540
+ create: async ({ anchor = { kind: "page" }, attachments, body, files, mentions }) => {
541
+ const thread = await client.create({
542
+ subject: subject.value,
543
+ anchor,
544
+ body,
545
+ mentions,
546
+ ...attachments?.length ? { attachments } : {},
547
+ ...files?.length ? { files } : {}
548
+ });
549
+ flash(thread.id);
550
+ return thread;
551
+ },
552
+ reply: async (threadId, body, mentions, attachments, files) => {
553
+ const thread = await client.reply({
554
+ threadId,
555
+ body,
556
+ mentions,
557
+ ...attachments?.length ? { attachments } : {},
558
+ ...files?.length ? { files } : {}
559
+ });
560
+ flash(threadId);
561
+ return thread;
562
+ },
412
563
  edit: (threadId, messageId, body, mentions) => client.edit({
413
564
  threadId,
414
565
  messageId,
@@ -428,7 +579,7 @@ function useComments(options) {
428
579
  },
429
580
  resolve: (threadId) => client.resolve({ threadId }),
430
581
  reopen: (threadId) => client.reopen({ threadId }),
431
- users: (query) => client.users({ query }),
582
+ users,
432
583
  link,
433
584
  measure,
434
585
  start
@@ -448,9 +599,9 @@ function provideComments(state) {
448
599
  }
449
600
  /** The state that a comment part uses: the one you pass, else the one of the nearest `CommentLayer` or `provideComments()`. Call it in `setup()`. */
450
601
  function useCommentsContext(state) {
451
- const found = state ?? inject(commentsKey, null);
602
+ const found = state ?? injectComments();
452
603
  if (!found) throw uiErrorDiagnostics.UI_R0002({ message: "Comment parts need a comments state. Put them inside CommentLayer, or pass the result of useComments() as the `comments` prop." });
453
604
  return found;
454
605
  }
455
606
  //#endregion
456
- export { consumedPointerEvents as a, shakeEventName as c, useCommentsContext as i, swallowNextClick as l, provideComments as n, pathOf as o, useComments as r, shakeDirtyComposers as s, draftPositionKey as t, useDocumentPointerDown as u };
607
+ export { useCommentsContext as a, messagesSinceResolved as c, useSelectedComment as d, useComments as i, repliedSinceResolved as l, draftPositionKey as n, commentTitle as o, provideComments as r, deliveryAttributes as s, defaultCommentCan as t, commentThreadKey as u };
@@ -0,0 +1,198 @@
1
+ import { t as CommentVisibility } from "./comment-visibility-DsVuVndP.js";
2
+ import { ComputedRef, MaybeRefOrGetter, Ref, ShallowRef } from "vue";
3
+ import { AnchorPoint, AnchorPosition, AnchorTarget, CommentAnchor, CommentDelivery, CommentMessage, CommentSubject, CommentThread, CommentUser, CommentsClient, CommentsClientStatus, CommentsOutboxEntry, CreateAnchorOptions } from "@vite-hub/comments/client";
4
+ //#region src/headless/comments.d.ts
5
+ /**
6
+ * Each switch shows one kind of thread. Resolved threads stay hidden until `resolved` is on. A resolved thread with a
7
+ * reply since it was resolved also counts as open, so the reply is seen.
8
+ */
9
+ interface CommentFilterState {
10
+ open: boolean;
11
+ resolved: boolean;
12
+ /** Only threads that the signed-in user started. */
13
+ mine: boolean;
14
+ }
15
+ /** `page` lists the threads of this page. `site` lists the threads of every page. */
16
+ type CommentScope = "page" | "site";
17
+ /** A comment that is being written. It becomes a thread when it is sent. */
18
+ interface CommentDraft {
19
+ anchor: CommentAnchor;
20
+ /** Where the click landed in client coordinates. The pin sits here until its element is measured. */
21
+ point: AnchorPoint;
22
+ body: string;
23
+ mentions: string[];
24
+ /** Attachment keys, such as Blob keys, that the comment sends. */
25
+ attachments: string[];
26
+ /** Files that the composer starts with, such as a screenshot. They upload with the comment, as picked files do. */
27
+ files?: File[];
28
+ busy: boolean;
29
+ error: string | undefined;
30
+ }
31
+ /** What the signed-in user may do to a thread. `edit` and `delete` name a message; deleting the first one deletes the thread. */
32
+ type CommentThreadAction = "reply" | "resolve" | "edit" | "delete";
33
+ /** Whether the signed-in user may do `action`. The parts show only the controls that it allows. The server still decides. */
34
+ type CommentCan = (action: CommentThreadAction, target: {
35
+ thread: CommentThread;
36
+ message?: CommentMessage;
37
+ }) => boolean;
38
+ /**
39
+ * The permissions that the parts assume without a `can` option: a signed-in user may reply to and resolve any thread,
40
+ * and edit and delete their own messages. Nobody may do anything without a user.
41
+ */
42
+ declare function defaultCommentCan(user: CommentUser | undefined): CommentCan;
43
+ interface UseCommentsOptions {
44
+ client: CommentsClient;
45
+ /** What the threads of this page are about. For a page, `{ kind: "page", id: location.pathname }`. */
46
+ subject: MaybeRefOrGetter<CommentSubject>;
47
+ /** The signed-in user. Defaults to `client.user`. */
48
+ user?: MaybeRefOrGetter<CommentUser | undefined>;
49
+ /** People that the app already knows, such as the ones that a server answer named. Their mentions show as chips. */
50
+ people?: MaybeRefOrGetter<readonly CommentUser[]>;
51
+ /** Where anchors are looked up. Defaults to the document. */
52
+ root?: MaybeRefOrGetter<ParentNode | undefined>;
53
+ /** The query parameter that deep-links a thread. Default `"comment"`. */
54
+ param?: string;
55
+ /** The key that toggles comment mode. Default `"c"`. `false` turns the key off. */
56
+ hotkey?: string | false;
57
+ /** Elements that anchors skip. Defaults to the comment UI. */
58
+ ignore?: (element: Element) => boolean;
59
+ /** Where the comment UI lives: the document, or the shadow root of the overlay. Composers are looked up there. Defaults to the document. */
60
+ uiRoot?: MaybeRefOrGetter<ParentNode | undefined>;
61
+ /** The URL of the page that a subject lives on, for a link to a thread. Page subjects use their id as the path. Other subjects need this, or their link is the current page. */
62
+ subjectUrl?: (subject: CommentSubject) => string | undefined;
63
+ /** Where the deep link is read. Defaults to `window.location`. */
64
+ location?: () => Pick<Location, "href" | "origin" | "search">;
65
+ /** Load the threads and listen for keys when the component mounts. Default `true`. Call `start()` yourself when `false`. */
66
+ autoStart?: boolean;
67
+ /** What the signed-in user may do, such as your app's sharing rules. Defaults to `defaultCommentCan()`. */
68
+ can?: CommentCan;
69
+ /**
70
+ * Which comments show on the page. Default `"all"`. Pass a ref to keep the reader's choice, such as one saved in
71
+ * `localStorage`: the state reads and writes it.
72
+ */
73
+ visibility?: CommentVisibility | Ref<CommentVisibility>;
74
+ /** How long a comment or reply that was just sent shows while comments are hidden. Default `2500`. */
75
+ flashMs?: number;
76
+ }
77
+ /**
78
+ * The comments and replies that the client's outbox saved and did not send yet. Without the `outbox` option of
79
+ * `createCommentsClient()`, it is empty and its actions do nothing.
80
+ */
81
+ interface CommentsOutboxState {
82
+ /** `true` when the client has an outbox. */
83
+ readonly enabled: boolean;
84
+ /** The entries that wait or go out now, in order. */
85
+ readonly queued: ComputedRef<readonly CommentsOutboxEntry[]>;
86
+ /** The entries that the server refused. */
87
+ readonly failures: ComputedRef<readonly CommentsOutboxEntry[]>;
88
+ /** Whether the thread, or one of its messages, is waiting or refused. `undefined` when the server has it. */
89
+ delivery: (threadId: string, messageId?: string) => CommentDelivery | undefined;
90
+ /** Sends the waiting comment or reply `id` now. Without `id`, the whole queue tries again, such as after a sign-in. */
91
+ retry: (id?: string) => Promise<void>;
92
+ /** Removes the waiting comment or reply. `false` while it is on its way. */
93
+ dismiss: (id: string) => Promise<boolean>;
94
+ /** Changes the text of the waiting comment or reply. A refused one goes back in the queue. `false` while it is on its way. */
95
+ edit: (id: string, body: string, mentions?: string[]) => Promise<boolean>;
96
+ }
97
+ interface CommentsState {
98
+ readonly client: CommentsClient;
99
+ readonly subject: ComputedRef<CommentSubject>;
100
+ readonly user: ComputedRef<CommentUser | undefined>;
101
+ /** Whether the signed-in user may reply, resolve, edit, or delete. Always false without a user. */
102
+ readonly can: CommentCan;
103
+ /** Every person the state knows: the user, the authors of threads, the people that `users()` found, and `people`. Mentions get their names here. */
104
+ readonly people: ComputedRef<CommentUser[]>;
105
+ /** Comment mode: a click drops a pin. */
106
+ readonly active: Ref<boolean>;
107
+ readonly scope: Ref<CommentScope>;
108
+ readonly filters: CommentFilterState;
109
+ readonly status: Ref<CommentsClientStatus>;
110
+ /** Every thread that the client holds, with the ones that wait in the outbox. */
111
+ readonly threads: ShallowRef<readonly CommentThread[]>;
112
+ readonly outbox: CommentsOutboxState;
113
+ /** The threads of this page that pass the filters. They get pins. */
114
+ readonly pageThreads: ComputedRef<CommentThread[]>;
115
+ /** The threads that pass the filters, for the page or the whole site as `scope` says. The list shows them. */
116
+ readonly listed: ComputedRef<CommentThread[]>;
117
+ readonly counts: ComputedRef<{
118
+ open: number;
119
+ resolved: number;
120
+ }>;
121
+ /** Pin positions by thread id, and `"draft"` for the comment being written. */
122
+ readonly positions: ShallowRef<ReadonlyMap<string, AnchorPosition>>;
123
+ readonly draft: Ref<CommentDraft | null>;
124
+ readonly openId: Ref<string | null>;
125
+ readonly hoverId: Ref<string | null>;
126
+ readonly opened: ComputedRef<CommentThread | undefined>;
127
+ readonly listOpen: Ref<boolean>;
128
+ /** Goes up when a composer with text stopped a click or a key. The composer shakes by itself. */
129
+ readonly blocked: Ref<number>;
130
+ /** Which comments show. Writing or opening a comment never changes it. */
131
+ readonly visibility: Ref<CommentVisibility>;
132
+ /**
133
+ * The ids of the threads of this page that get a pin or a mark: all of them, or while comments are hidden, the open
134
+ * thread and each one that was just sent or replied to. The draft always shows.
135
+ */
136
+ readonly shown: ComputedRef<ReadonlySet<string>>;
137
+ /** The ids of threads that stopped showing while comments are hidden, for 180 ms. Their marks play the pop-out. */
138
+ readonly leaving: ComputedRef<ReadonlySet<string>>;
139
+ /** Keeps page marks visible without opening a popover. Call the returned release function when the panel closes. */
140
+ retainMark: (id: string) => () => void;
141
+ isShown: (id: string) => boolean;
142
+ /** Shows the thread for `flashMs` while comments are hidden. `send()`, `create()`, and `reply()` call it. */
143
+ flash: (id: string) => void;
144
+ enter: () => void;
145
+ exit: () => void;
146
+ toggle: () => void;
147
+ /**
148
+ * Starts a draft on a point, an element, a selection, or `"page"`. Ends an empty draft first, and keeps one with text.
149
+ * A pin has no number until the server assigns one. `files` start in its composer, such as a screenshot of the area.
150
+ */
151
+ startDraft: (target: AnchorTarget, options?: CreateAnchorOptions & {
152
+ files?: File[];
153
+ }) => void;
154
+ cancelDraft: () => void;
155
+ /**
156
+ * Sends the draft. Resolves with the new thread, or `undefined` when there is nothing to send or the send failed. With
157
+ * an outbox it resolves, and the draft closes, once the comment is saved, before the server answers. `files` go with
158
+ * the comment, for a client with an outbox.
159
+ */
160
+ send: (options?: {
161
+ files?: Blob[];
162
+ }) => Promise<CommentThread | undefined>;
163
+ open: (thread: CommentThread | string, options?: {
164
+ scroll?: boolean;
165
+ }) => void;
166
+ /** Closes the thread, returning false when unsent text prevents closing or navigation. */
167
+ close: () => boolean;
168
+ /** Starts a thread on the subject. The anchor defaults to the whole page. */
169
+ create: (input: {
170
+ body: string;
171
+ mentions?: string[];
172
+ attachments?: string[];
173
+ files?: Blob[];
174
+ anchor?: CommentAnchor;
175
+ }) => Promise<CommentThread>;
176
+ reply: (threadId: string, body: string, mentions?: string[], attachments?: string[], files?: Blob[]) => Promise<CommentThread>;
177
+ edit: (threadId: string, messageId: string, body: string, mentions?: string[]) => Promise<CommentThread>;
178
+ remove: (threadId: string, messageId?: string) => Promise<CommentThread | null>;
179
+ resolve: (threadId: string) => Promise<CommentThread>;
180
+ reopen: (threadId: string) => Promise<CommentThread>;
181
+ /** Finds people for a reply or edit in `threadId`, or for a new thread on the current subject. */
182
+ users: (query: string, threadId?: string) => Promise<CommentUser[]>;
183
+ /** The URL that opens the thread: its page with `?comment=<n>`. */
184
+ link: (thread: CommentThread) => string;
185
+ /** Measures every pin again. The state does it on scroll, resize, and DOM changes. */
186
+ measure: () => void;
187
+ /** Loads the threads and starts the key, layout, and deep-link handling. Returns a function that stops them. */
188
+ start: () => () => void;
189
+ }
190
+ declare const draftPositionKey = "draft";
191
+ /** The comment state of one page. The styled parts, `CommentLayer` and the others, are built on it. */
192
+ declare function useComments(options: UseCommentsOptions): CommentsState;
193
+ /** Makes `state` the one that `CommentToolbar`, `CommentList`, and `CommentFilters` use inside this component tree. */
194
+ declare function provideComments(state: CommentsState): void;
195
+ /** The state that a comment part uses: the one you pass, else the one of the nearest `CommentLayer` or `provideComments()`. Call it in `setup()`. */
196
+ declare function useCommentsContext(state?: CommentsState): CommentsState;
197
+ //#endregion
198
+ export { CommentThreadAction as a, UseCommentsOptions as c, provideComments as d, useComments as f, CommentScope as i, defaultCommentCan as l, CommentDraft as n, CommentsOutboxState as o, useCommentsContext as p, CommentFilterState as r, CommentsState as s, CommentCan as t, draftPositionKey as u };
@@ -0,0 +1,38 @@
1
+ import { inject, onBeforeUnmount, onMounted } from "vue";
2
+ //#region src/internal/comment-outside.ts
3
+ const consumedPointerEvents = /* @__PURE__ */ new WeakSet();
4
+ function swallowNextClick() {
5
+ const stop = (event) => {
6
+ event.stopPropagation();
7
+ event.preventDefault();
8
+ cleanup();
9
+ };
10
+ const cleanup = () => {
11
+ document.removeEventListener("click", stop, true);
12
+ document.removeEventListener("pointerdown", cleanup, true);
13
+ };
14
+ document.addEventListener("click", stop, true);
15
+ document.addEventListener("pointerdown", cleanup, true);
16
+ }
17
+ function useDocumentPointerDown(handler) {
18
+ onMounted(() => document.addEventListener("pointerdown", handler, true));
19
+ onBeforeUnmount(() => document.removeEventListener("pointerdown", handler, true));
20
+ }
21
+ const shakeEventName = "comments:shake";
22
+ const dirtySelector = "[data-slot='comment-composer'][data-dirty='true']";
23
+ function hasDirtyComposer(root = document) {
24
+ return root.querySelector(dirtySelector) !== null;
25
+ }
26
+ function shakeDirtyComposers(root = document, escape = false) {
27
+ const dirty = [...root.querySelectorAll(dirtySelector)];
28
+ for (const composer of dirty) composer.dispatchEvent(new CustomEvent(shakeEventName, { detail: { escape } }));
29
+ return dirty.length > 0;
30
+ }
31
+ const pathOf = (event) => event.composedPath().filter((node) => node instanceof Element);
32
+ //#endregion
33
+ //#region src/internal/comments-context.ts
34
+ const commentsKey = Symbol("ViteHubComments");
35
+ /** The state of the nearest `CommentLayer`, `CommentPanel`, or `provideComments()`, if there is one. Call it in `setup()`. */
36
+ const injectComments = () => inject(commentsKey, null) ?? void 0;
37
+ //#endregion
38
+ export { pathOf as a, swallowNextClick as c, hasDirtyComposer as i, useDocumentPointerDown as l, injectComments as n, shakeDirtyComposers as o, consumedPointerEvents as r, shakeEventName as s, commentsKey as t };