@flanksource/clicky-ui 0.3.65 → 0.3.67

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 (592) hide show
  1. package/NOTICE.md +4 -2
  2. package/dist/comments/CommentAuthor.cjs +6 -1
  3. package/dist/comments/CommentAuthor.cjs.map +1 -1
  4. package/dist/comments/CommentAuthor.d.ts.map +1 -1
  5. package/dist/comments/CommentAuthor.js +8 -3
  6. package/dist/comments/CommentAuthor.js.map +1 -1
  7. package/dist/comments/CommentComposer.cjs +4 -1
  8. package/dist/comments/CommentComposer.cjs.map +1 -1
  9. package/dist/comments/CommentComposer.d.ts.map +1 -1
  10. package/dist/comments/CommentComposer.js +4 -1
  11. package/dist/comments/CommentComposer.js.map +1 -1
  12. package/dist/comments/CommentEditor.cjs +3 -6
  13. package/dist/comments/CommentEditor.cjs.map +1 -1
  14. package/dist/comments/CommentEditor.d.ts.map +1 -1
  15. package/dist/comments/CommentEditor.js +3 -6
  16. package/dist/comments/CommentEditor.js.map +1 -1
  17. package/dist/comments/CommentProvider.cjs +3 -1
  18. package/dist/comments/CommentProvider.cjs.map +1 -1
  19. package/dist/comments/CommentProvider.d.ts +2 -0
  20. package/dist/comments/CommentProvider.d.ts.map +1 -1
  21. package/dist/comments/CommentProvider.js +3 -1
  22. package/dist/comments/CommentProvider.js.map +1 -1
  23. package/dist/comments/CommentRail.cjs +31 -18
  24. package/dist/comments/CommentRail.cjs.map +1 -1
  25. package/dist/comments/CommentRail.d.ts.map +1 -1
  26. package/dist/comments/CommentRail.js +31 -18
  27. package/dist/comments/CommentRail.js.map +1 -1
  28. package/dist/comments/agent-delivery.cjs +1 -2
  29. package/dist/comments/agent-delivery.cjs.map +1 -1
  30. package/dist/comments/agent-delivery.d.ts +1 -1
  31. package/dist/comments/agent-delivery.d.ts.map +1 -1
  32. package/dist/comments/agent-delivery.js +1 -2
  33. package/dist/comments/agent-delivery.js.map +1 -1
  34. package/dist/comments/annotation-types.d.ts +16 -0
  35. package/dist/comments/annotation-types.d.ts.map +1 -1
  36. package/dist/comments/comment-context.cjs.map +1 -1
  37. package/dist/comments/comment-context.d.ts +2 -1
  38. package/dist/comments/comment-context.d.ts.map +1 -1
  39. package/dist/comments/comment-context.js.map +1 -1
  40. package/dist/comments/comment-types.cjs.map +1 -1
  41. package/dist/comments/comment-types.d.ts +10 -1
  42. package/dist/comments/comment-types.d.ts.map +1 -1
  43. package/dist/comments/comment-types.js.map +1 -1
  44. package/dist/comments/gavel/CommentAgentSessions.cjs +55 -44
  45. package/dist/comments/gavel/CommentAgentSessions.cjs.map +1 -1
  46. package/dist/comments/gavel/CommentAgentSessions.d.ts +5 -2
  47. package/dist/comments/gavel/CommentAgentSessions.d.ts.map +1 -1
  48. package/dist/comments/gavel/CommentAgentSessions.js +55 -44
  49. package/dist/comments/gavel/CommentAgentSessions.js.map +1 -1
  50. package/dist/comments/gavel/client.cjs +3 -1
  51. package/dist/comments/gavel/client.cjs.map +1 -1
  52. package/dist/comments/gavel/client.d.ts.map +1 -1
  53. package/dist/comments/gavel/client.js +3 -1
  54. package/dist/comments/gavel/client.js.map +1 -1
  55. package/dist/comments/gavel/comment-agent-model.cjs +1 -1
  56. package/dist/comments/gavel/comment-agent-model.cjs.map +1 -1
  57. package/dist/comments/gavel/comment-agent-model.js +1 -1
  58. package/dist/comments/gavel/comment-agent-model.js.map +1 -1
  59. package/dist/comments/gavel/inbox-prompt.cjs +3 -1
  60. package/dist/comments/gavel/inbox-prompt.cjs.map +1 -1
  61. package/dist/comments/gavel/inbox-prompt.d.ts.map +1 -1
  62. package/dist/comments/gavel/inbox-prompt.js +3 -1
  63. package/dist/comments/gavel/inbox-prompt.js.map +1 -1
  64. package/dist/comments/gavel/index.d.ts +2 -1
  65. package/dist/comments/gavel/index.d.ts.map +1 -1
  66. package/dist/comments/gavel/useGavelComments.cjs +17 -9
  67. package/dist/comments/gavel/useGavelComments.cjs.map +1 -1
  68. package/dist/comments/gavel/useGavelComments.d.ts.map +1 -1
  69. package/dist/comments/gavel/useGavelComments.js +18 -10
  70. package/dist/comments/gavel/useGavelComments.js.map +1 -1
  71. package/dist/comments-gavel.cjs +4 -0
  72. package/dist/comments-gavel.js +3 -1
  73. package/dist/comments.d.ts +1 -1
  74. package/dist/comments.d.ts.map +1 -1
  75. package/dist/components/FilterBar.cjs +12 -5
  76. package/dist/components/FilterBar.cjs.map +1 -1
  77. package/dist/components/FilterBar.d.ts.map +1 -1
  78. package/dist/components/FilterBar.js +12 -5
  79. package/dist/components/FilterBar.js.map +1 -1
  80. package/dist/components/JsonSchemaForm.cjs +4 -1
  81. package/dist/components/JsonSchemaForm.cjs.map +1 -1
  82. package/dist/components/JsonSchemaForm.d.ts.map +1 -1
  83. package/dist/components/JsonSchemaForm.js +4 -1
  84. package/dist/components/JsonSchemaForm.js.map +1 -1
  85. package/dist/components/SecretFormField.cjs +3 -0
  86. package/dist/components/SecretFormField.cjs.map +1 -1
  87. package/dist/components/SecretFormField.d.ts.map +1 -1
  88. package/dist/components/SecretFormField.js +3 -0
  89. package/dist/components/SecretFormField.js.map +1 -1
  90. package/dist/components/SecretKeySelector.cjs +28 -2
  91. package/dist/components/SecretKeySelector.cjs.map +1 -1
  92. package/dist/components/SecretKeySelector.d.ts +7 -1
  93. package/dist/components/SecretKeySelector.d.ts.map +1 -1
  94. package/dist/components/SecretKeySelector.js +28 -2
  95. package/dist/components/SecretKeySelector.js.map +1 -1
  96. package/dist/components/SegmentedControl.cjs +4 -1
  97. package/dist/components/SegmentedControl.cjs.map +1 -1
  98. package/dist/components/SegmentedControl.d.ts +3 -3
  99. package/dist/components/SegmentedControl.d.ts.map +1 -1
  100. package/dist/components/SegmentedControl.js +5 -2
  101. package/dist/components/SegmentedControl.js.map +1 -1
  102. package/dist/components/WorkspaceAccessDialog.cjs +273 -99
  103. package/dist/components/WorkspaceAccessDialog.cjs.map +1 -1
  104. package/dist/components/WorkspaceAccessDialog.d.ts +4 -2
  105. package/dist/components/WorkspaceAccessDialog.d.ts.map +1 -1
  106. package/dist/components/WorkspaceAccessDialog.js +275 -101
  107. package/dist/components/WorkspaceAccessDialog.js.map +1 -1
  108. package/dist/components/json-schema-form-accordion-array.cjs +5 -3
  109. package/dist/components/json-schema-form-accordion-array.cjs.map +1 -1
  110. package/dist/components/json-schema-form-accordion-array.d.ts.map +1 -1
  111. package/dist/components/json-schema-form-accordion-array.js +7 -5
  112. package/dist/components/json-schema-form-accordion-array.js.map +1 -1
  113. package/dist/components/json-schema-form-cards-array.cjs +1 -0
  114. package/dist/components/json-schema-form-cards-array.cjs.map +1 -1
  115. package/dist/components/json-schema-form-cards-array.d.ts.map +1 -1
  116. package/dist/components/json-schema-form-cards-array.js +2 -1
  117. package/dist/components/json-schema-form-cards-array.js.map +1 -1
  118. package/dist/components/json-schema-form-conditionals.cjs +1 -4
  119. package/dist/components/json-schema-form-conditionals.cjs.map +1 -1
  120. package/dist/components/json-schema-form-conditionals.d.ts.map +1 -1
  121. package/dist/components/json-schema-form-conditionals.js +1 -4
  122. package/dist/components/json-schema-form-conditionals.js.map +1 -1
  123. package/dist/components/json-schema-form-enum-choice.cjs +4 -3
  124. package/dist/components/json-schema-form-enum-choice.cjs.map +1 -1
  125. package/dist/components/json-schema-form-enum-choice.d.ts.map +1 -1
  126. package/dist/components/json-schema-form-enum-choice.js +4 -3
  127. package/dist/components/json-schema-form-enum-choice.js.map +1 -1
  128. package/dist/components/json-schema-form-item-row.cjs +4 -0
  129. package/dist/components/json-schema-form-item-row.cjs.map +1 -1
  130. package/dist/components/json-schema-form-item-row.d.ts +3 -0
  131. package/dist/components/json-schema-form-item-row.d.ts.map +1 -1
  132. package/dist/components/json-schema-form-item-row.js +5 -2
  133. package/dist/components/json-schema-form-item-row.js.map +1 -1
  134. package/dist/components/json-schema-form-item-summary.cjs +10 -0
  135. package/dist/components/json-schema-form-item-summary.cjs.map +1 -1
  136. package/dist/components/json-schema-form-item-summary.d.ts +1 -0
  137. package/dist/components/json-schema-form-item-summary.d.ts.map +1 -1
  138. package/dist/components/json-schema-form-item-summary.js +10 -1
  139. package/dist/components/json-schema-form-item-summary.js.map +1 -1
  140. package/dist/components/json-schema-form-listeners.cjs +1 -5
  141. package/dist/components/json-schema-form-listeners.cjs.map +1 -1
  142. package/dist/components/json-schema-form-listeners.js +1 -5
  143. package/dist/components/json-schema-form-listeners.js.map +1 -1
  144. package/dist/components/json-schema-form-refs.cjs +29 -4
  145. package/dist/components/json-schema-form-refs.cjs.map +1 -1
  146. package/dist/components/json-schema-form-refs.js +29 -4
  147. package/dist/components/json-schema-form-refs.js.map +1 -1
  148. package/dist/components/json-schema-form-render.cjs +35 -13
  149. package/dist/components/json-schema-form-render.cjs.map +1 -1
  150. package/dist/components/json-schema-form-render.d.ts.map +1 -1
  151. package/dist/components/json-schema-form-render.js +36 -14
  152. package/dist/components/json-schema-form-render.js.map +1 -1
  153. package/dist/components/json-schema-form-resolve.cjs +3 -1
  154. package/dist/components/json-schema-form-resolve.cjs.map +1 -1
  155. package/dist/components/json-schema-form-resolve.d.ts.map +1 -1
  156. package/dist/components/json-schema-form-resolve.js +3 -1
  157. package/dist/components/json-schema-form-resolve.js.map +1 -1
  158. package/dist/components/json-schema-form-runtime-types.d.ts +8 -0
  159. package/dist/components/json-schema-form-runtime-types.d.ts.map +1 -1
  160. package/dist/components/json-schema-form-table-array.cjs +1 -1
  161. package/dist/components/json-schema-form-table-array.cjs.map +1 -1
  162. package/dist/components/json-schema-form-table-array.js +2 -2
  163. package/dist/components/json-schema-form-table-array.js.map +1 -1
  164. package/dist/components/json-schema-form-types.d.ts +6 -0
  165. package/dist/components/json-schema-form-types.d.ts.map +1 -1
  166. package/dist/components/json-schema-form-utils.cjs +12 -3
  167. package/dist/components/json-schema-form-utils.cjs.map +1 -1
  168. package/dist/components/json-schema-form-utils.d.ts +4 -1
  169. package/dist/components/json-schema-form-utils.d.ts.map +1 -1
  170. package/dist/components/json-schema-form-utils.js +12 -3
  171. package/dist/components/json-schema-form-utils.js.map +1 -1
  172. package/dist/components/secret-form-extension.cjs.map +1 -1
  173. package/dist/components/secret-form-extension.d.ts +2 -0
  174. package/dist/components/secret-form-extension.d.ts.map +1 -1
  175. package/dist/components/secret-form-extension.js.map +1 -1
  176. package/dist/components/useSingleRowTagCount.cjs +16 -13
  177. package/dist/components/useSingleRowTagCount.cjs.map +1 -1
  178. package/dist/components/useSingleRowTagCount.d.ts +0 -5
  179. package/dist/components/useSingleRowTagCount.d.ts.map +1 -1
  180. package/dist/components/useSingleRowTagCount.js +16 -13
  181. package/dist/components/useSingleRowTagCount.js.map +1 -1
  182. package/dist/components.cjs +4 -0
  183. package/dist/components.d.ts +2 -0
  184. package/dist/components.d.ts.map +1 -1
  185. package/dist/components.js +3 -1
  186. package/dist/connections/connectionSchemaFormExtensions.cjs +13 -2
  187. package/dist/connections/connectionSchemaFormExtensions.cjs.map +1 -1
  188. package/dist/connections/connectionSchemaFormExtensions.d.ts.map +1 -1
  189. package/dist/connections/connectionSchemaFormExtensions.js +13 -2
  190. package/dist/connections/connectionSchemaFormExtensions.js.map +1 -1
  191. package/dist/data/DataTable.cjs +128 -82
  192. package/dist/data/DataTable.cjs.map +1 -1
  193. package/dist/data/DataTable.d.ts +29 -0
  194. package/dist/data/DataTable.d.ts.map +1 -1
  195. package/dist/data/DataTable.js +129 -83
  196. package/dist/data/DataTable.js.map +1 -1
  197. package/dist/data/DataTableList.cjs +43 -0
  198. package/dist/data/DataTableList.cjs.map +1 -0
  199. package/dist/data/DataTableList.d.ts +13 -0
  200. package/dist/data/DataTableList.d.ts.map +1 -0
  201. package/dist/data/DataTableList.js +43 -0
  202. package/dist/data/DataTableList.js.map +1 -0
  203. package/dist/data/DataTableOverflowCue.cjs +18 -8
  204. package/dist/data/DataTableOverflowCue.cjs.map +1 -1
  205. package/dist/data/DataTableOverflowCue.d.ts.map +1 -1
  206. package/dist/data/DataTableOverflowCue.js +18 -8
  207. package/dist/data/DataTableOverflowCue.js.map +1 -1
  208. package/dist/data/Markdown.cjs +11 -1
  209. package/dist/data/Markdown.cjs.map +1 -1
  210. package/dist/data/Markdown.d.ts.map +1 -1
  211. package/dist/data/Markdown.js +11 -1
  212. package/dist/data/Markdown.js.map +1 -1
  213. package/dist/data/PromptBanner.cjs +13 -4
  214. package/dist/data/PromptBanner.cjs.map +1 -1
  215. package/dist/data/PromptBanner.d.ts.map +1 -1
  216. package/dist/data/PromptBanner.js +13 -4
  217. package/dist/data/PromptBanner.js.map +1 -1
  218. package/dist/data/SelectionActionBar.cjs +20 -5
  219. package/dist/data/SelectionActionBar.cjs.map +1 -1
  220. package/dist/data/SelectionActionBar.d.ts +6 -1
  221. package/dist/data/SelectionActionBar.d.ts.map +1 -1
  222. package/dist/data/SelectionActionBar.js +20 -5
  223. package/dist/data/SelectionActionBar.js.map +1 -1
  224. package/dist/data/StatStrip.cjs +12 -4
  225. package/dist/data/StatStrip.cjs.map +1 -1
  226. package/dist/data/StatStrip.d.ts +0 -8
  227. package/dist/data/StatStrip.d.ts.map +1 -1
  228. package/dist/data/StatStrip.js +12 -4
  229. package/dist/data/StatStrip.js.map +1 -1
  230. package/dist/data/TaskManager.cjs +173 -53
  231. package/dist/data/TaskManager.cjs.map +1 -1
  232. package/dist/data/TaskManager.d.ts +9 -1
  233. package/dist/data/TaskManager.d.ts.map +1 -1
  234. package/dist/data/TaskManager.js +175 -55
  235. package/dist/data/TaskManager.js.map +1 -1
  236. package/dist/data/TaskPoolUsage.cjs +65 -1
  237. package/dist/data/TaskPoolUsage.cjs.map +1 -1
  238. package/dist/data/TaskPoolUsage.d.ts +19 -1
  239. package/dist/data/TaskPoolUsage.d.ts.map +1 -1
  240. package/dist/data/TaskPoolUsage.js +65 -2
  241. package/dist/data/TaskPoolUsage.js.map +1 -1
  242. package/dist/data/ai/SessionInspector.cjs +24 -14
  243. package/dist/data/ai/SessionInspector.cjs.map +1 -1
  244. package/dist/data/ai/SessionInspector.collection.cjs +9 -7
  245. package/dist/data/ai/SessionInspector.collection.cjs.map +1 -1
  246. package/dist/data/ai/SessionInspector.collection.d.ts +1 -1
  247. package/dist/data/ai/SessionInspector.collection.d.ts.map +1 -1
  248. package/dist/data/ai/SessionInspector.collection.js +9 -7
  249. package/dist/data/ai/SessionInspector.collection.js.map +1 -1
  250. package/dist/data/ai/SessionInspector.d.ts +8 -3
  251. package/dist/data/ai/SessionInspector.d.ts.map +1 -1
  252. package/dist/data/ai/SessionInspector.hierarchy-state.cjs +5 -4
  253. package/dist/data/ai/SessionInspector.hierarchy-state.cjs.map +1 -1
  254. package/dist/data/ai/SessionInspector.hierarchy-state.js +6 -5
  255. package/dist/data/ai/SessionInspector.hierarchy-state.js.map +1 -1
  256. package/dist/data/ai/SessionInspector.host-tabs.cjs +28 -0
  257. package/dist/data/ai/SessionInspector.host-tabs.cjs.map +1 -0
  258. package/dist/data/ai/SessionInspector.host-tabs.d.ts +17 -0
  259. package/dist/data/ai/SessionInspector.host-tabs.d.ts.map +1 -0
  260. package/dist/data/ai/SessionInspector.host-tabs.js +28 -0
  261. package/dist/data/ai/SessionInspector.host-tabs.js.map +1 -0
  262. package/dist/data/ai/SessionInspector.js +24 -14
  263. package/dist/data/ai/SessionInspector.js.map +1 -1
  264. package/dist/data/ai/SessionInspector.legacy.cjs +13 -6
  265. package/dist/data/ai/SessionInspector.legacy.cjs.map +1 -1
  266. package/dist/data/ai/SessionInspector.legacy.d.ts +3 -1
  267. package/dist/data/ai/SessionInspector.legacy.d.ts.map +1 -1
  268. package/dist/data/ai/SessionInspector.legacy.js +13 -6
  269. package/dist/data/ai/SessionInspector.legacy.js.map +1 -1
  270. package/dist/data/ai/SessionInspector.remote.cjs +7 -3
  271. package/dist/data/ai/SessionInspector.remote.cjs.map +1 -1
  272. package/dist/data/ai/SessionInspector.remote.d.ts +1 -1
  273. package/dist/data/ai/SessionInspector.remote.d.ts.map +1 -1
  274. package/dist/data/ai/SessionInspector.remote.js +8 -4
  275. package/dist/data/ai/SessionInspector.remote.js.map +1 -1
  276. package/dist/data/ai/SessionViewer.input.cjs +78 -1
  277. package/dist/data/ai/SessionViewer.input.cjs.map +1 -1
  278. package/dist/data/ai/SessionViewer.input.d.ts +9 -0
  279. package/dist/data/ai/SessionViewer.input.d.ts.map +1 -1
  280. package/dist/data/ai/SessionViewer.input.js +77 -2
  281. package/dist/data/ai/SessionViewer.input.js.map +1 -1
  282. package/dist/data/ai/SessionViewer.tool-details.cjs +44 -13
  283. package/dist/data/ai/SessionViewer.tool-details.cjs.map +1 -1
  284. package/dist/data/ai/SessionViewer.tool-details.d.ts +7 -1
  285. package/dist/data/ai/SessionViewer.tool-details.d.ts.map +1 -1
  286. package/dist/data/ai/SessionViewer.tool-details.js +44 -13
  287. package/dist/data/ai/SessionViewer.tool-details.js.map +1 -1
  288. package/dist/data/ai/SessionViewer.tool-row.cjs +7 -3
  289. package/dist/data/ai/SessionViewer.tool-row.cjs.map +1 -1
  290. package/dist/data/ai/SessionViewer.tool-row.d.ts.map +1 -1
  291. package/dist/data/ai/SessionViewer.tool-row.js +8 -4
  292. package/dist/data/ai/SessionViewer.tool-row.js.map +1 -1
  293. package/dist/data/ai/index.d.ts +1 -1
  294. package/dist/data/ai/index.d.ts.map +1 -1
  295. package/dist/data/ai/runtime-preset-menu/use-runtime-preset-menu.cjs +5 -2
  296. package/dist/data/ai/runtime-preset-menu/use-runtime-preset-menu.cjs.map +1 -1
  297. package/dist/data/ai/runtime-preset-menu/use-runtime-preset-menu.d.ts.map +1 -1
  298. package/dist/data/ai/runtime-preset-menu/use-runtime-preset-menu.js +6 -3
  299. package/dist/data/ai/runtime-preset-menu/use-runtime-preset-menu.js.map +1 -1
  300. package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.cjs +2 -1
  301. package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.cjs.map +1 -1
  302. package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.d.ts.map +1 -1
  303. package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.js +2 -1
  304. package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.js.map +1 -1
  305. package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.cjs +2 -1
  306. package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.cjs.map +1 -1
  307. package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.d.ts.map +1 -1
  308. package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.js +2 -1
  309. package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.js.map +1 -1
  310. package/dist/data/ai/use-session-scroll.cjs +120 -41
  311. package/dist/data/ai/use-session-scroll.cjs.map +1 -1
  312. package/dist/data/ai/use-session-scroll.d.ts +3 -3
  313. package/dist/data/ai/use-session-scroll.d.ts.map +1 -1
  314. package/dist/data/ai/use-session-scroll.js +120 -41
  315. package/dist/data/ai/use-session-scroll.js.map +1 -1
  316. package/dist/data/cells/timestamp-format.cjs +57 -2
  317. package/dist/data/cells/timestamp-format.cjs.map +1 -1
  318. package/dist/data/cells/timestamp-format.d.ts +9 -1
  319. package/dist/data/cells/timestamp-format.d.ts.map +1 -1
  320. package/dist/data/cells/timestamp-format.js +56 -3
  321. package/dist/data/cells/timestamp-format.js.map +1 -1
  322. package/dist/data/chat/AgentIdentity.cjs +10 -3
  323. package/dist/data/chat/AgentIdentity.cjs.map +1 -1
  324. package/dist/data/chat/AgentIdentity.d.ts +2 -1
  325. package/dist/data/chat/AgentIdentity.d.ts.map +1 -1
  326. package/dist/data/chat/AgentIdentity.js +10 -3
  327. package/dist/data/chat/AgentIdentity.js.map +1 -1
  328. package/dist/data/chat/Conversation.cjs +14 -5
  329. package/dist/data/chat/Conversation.cjs.map +1 -1
  330. package/dist/data/chat/Conversation.d.ts.map +1 -1
  331. package/dist/data/chat/Conversation.js +14 -5
  332. package/dist/data/chat/Conversation.js.map +1 -1
  333. package/dist/data/data-table-list.cjs +24 -0
  334. package/dist/data/data-table-list.cjs.map +1 -0
  335. package/dist/data/data-table-list.d.ts +31 -0
  336. package/dist/data/data-table-list.d.ts.map +1 -0
  337. package/dist/data/data-table-list.js +24 -0
  338. package/dist/data/data-table-list.js.map +1 -0
  339. package/dist/data/delimited.cjs +48 -0
  340. package/dist/data/delimited.cjs.map +1 -0
  341. package/dist/data/delimited.d.ts +10 -0
  342. package/dist/data/delimited.d.ts.map +1 -0
  343. package/dist/data/delimited.js +47 -0
  344. package/dist/data/delimited.js.map +1 -0
  345. package/dist/data/git/index.d.ts +1 -0
  346. package/dist/data/git/index.d.ts.map +1 -1
  347. package/dist/data/git/pickers/GitPickers.cjs +2 -0
  348. package/dist/data/git/pickers/GitPickers.cjs.map +1 -1
  349. package/dist/data/git/pickers/GitPickers.d.ts.map +1 -1
  350. package/dist/data/git/pickers/GitPickers.js +2 -0
  351. package/dist/data/git/pickers/GitPickers.js.map +1 -1
  352. package/dist/data/git/pickers/GitSourcePicker.cjs +9 -2
  353. package/dist/data/git/pickers/GitSourcePicker.cjs.map +1 -1
  354. package/dist/data/git/pickers/GitSourcePicker.d.ts.map +1 -1
  355. package/dist/data/git/pickers/GitSourcePicker.js +9 -2
  356. package/dist/data/git/pickers/GitSourcePicker.js.map +1 -1
  357. package/dist/data/git/pickers/ReferencePicker.cjs +60 -6
  358. package/dist/data/git/pickers/ReferencePicker.cjs.map +1 -1
  359. package/dist/data/git/pickers/ReferencePicker.d.ts +9 -1
  360. package/dist/data/git/pickers/ReferencePicker.d.ts.map +1 -1
  361. package/dist/data/git/pickers/ReferencePicker.js +61 -7
  362. package/dist/data/git/pickers/ReferencePicker.js.map +1 -1
  363. package/dist/data/git/pickers/git-ref-group-limits.cjs +14 -0
  364. package/dist/data/git/pickers/git-ref-group-limits.cjs.map +1 -0
  365. package/dist/data/git/pickers/git-ref-group-limits.d.ts +11 -0
  366. package/dist/data/git/pickers/git-ref-group-limits.d.ts.map +1 -0
  367. package/dist/data/git/pickers/git-ref-group-limits.js +14 -0
  368. package/dist/data/git/pickers/git-ref-group-limits.js.map +1 -0
  369. package/dist/data/git/pickers/types.d.ts +2 -0
  370. package/dist/data/git/pickers/types.d.ts.map +1 -1
  371. package/dist/data/lint/LintList.cjs +154 -0
  372. package/dist/data/lint/LintList.cjs.map +1 -0
  373. package/dist/data/lint/LintList.d.ts +14 -0
  374. package/dist/data/lint/LintList.d.ts.map +1 -0
  375. package/dist/data/lint/LintList.js +154 -0
  376. package/dist/data/lint/LintList.js.map +1 -0
  377. package/dist/data/lint/LintResults.cjs +31 -10
  378. package/dist/data/lint/LintResults.cjs.map +1 -1
  379. package/dist/data/lint/LintResults.d.ts +5 -3
  380. package/dist/data/lint/LintResults.d.ts.map +1 -1
  381. package/dist/data/lint/LintResults.js +31 -10
  382. package/dist/data/lint/LintResults.js.map +1 -1
  383. package/dist/data/lint/actions.cjs +3 -1
  384. package/dist/data/lint/actions.cjs.map +1 -1
  385. package/dist/data/lint/actions.d.ts.map +1 -1
  386. package/dist/data/lint/actions.js +3 -1
  387. package/dist/data/lint/actions.js.map +1 -1
  388. package/dist/data/lint/index.d.ts +2 -0
  389. package/dist/data/lint/index.d.ts.map +1 -1
  390. package/dist/data/lint/list-grouping.cjs +39 -0
  391. package/dist/data/lint/list-grouping.cjs.map +1 -0
  392. package/dist/data/lint/list-grouping.d.ts +20 -0
  393. package/dist/data/lint/list-grouping.d.ts.map +1 -0
  394. package/dist/data/lint/list-grouping.js +39 -0
  395. package/dist/data/lint/list-grouping.js.map +1 -0
  396. package/dist/data/task-run-format.cjs +20 -0
  397. package/dist/data/task-run-format.cjs.map +1 -0
  398. package/dist/data/task-run-format.d.ts +6 -0
  399. package/dist/data/task-run-format.d.ts.map +1 -0
  400. package/dist/data/task-run-format.js +20 -0
  401. package/dist/data/task-run-format.js.map +1 -0
  402. package/dist/data/test-runner/TestDetailPanel.cjs +15 -4
  403. package/dist/data/test-runner/TestDetailPanel.cjs.map +1 -1
  404. package/dist/data/test-runner/TestDetailPanel.d.ts.map +1 -1
  405. package/dist/data/test-runner/TestDetailPanel.js +16 -5
  406. package/dist/data/test-runner/TestDetailPanel.js.map +1 -1
  407. package/dist/data/test-runner/TestList.cjs +87 -0
  408. package/dist/data/test-runner/TestList.cjs.map +1 -0
  409. package/dist/data/test-runner/TestList.d.ts +9 -0
  410. package/dist/data/test-runner/TestList.d.ts.map +1 -0
  411. package/dist/data/test-runner/TestList.js +87 -0
  412. package/dist/data/test-runner/TestList.js.map +1 -0
  413. package/dist/data/test-runner/TestRunner.cjs +21 -2
  414. package/dist/data/test-runner/TestRunner.cjs.map +1 -1
  415. package/dist/data/test-runner/TestRunner.d.ts +9 -1
  416. package/dist/data/test-runner/TestRunner.d.ts.map +1 -1
  417. package/dist/data/test-runner/TestRunner.js +21 -2
  418. package/dist/data/test-runner/TestRunner.js.map +1 -1
  419. package/dist/data/test-runner/TestTreeNode.cjs +1 -1
  420. package/dist/data/test-runner/TestTreeNode.cjs.map +1 -1
  421. package/dist/data/test-runner/TestTreeNode.js +1 -1
  422. package/dist/data/test-runner/TestTreeNode.js.map +1 -1
  423. package/dist/data/test-runner/TestViewToggle.cjs +32 -0
  424. package/dist/data/test-runner/TestViewToggle.cjs.map +1 -0
  425. package/dist/data/test-runner/TestViewToggle.d.ts +5 -0
  426. package/dist/data/test-runner/TestViewToggle.d.ts.map +1 -0
  427. package/dist/data/test-runner/TestViewToggle.js +32 -0
  428. package/dist/data/test-runner/TestViewToggle.js.map +1 -0
  429. package/dist/data/test-runner/adapter.cjs +14 -0
  430. package/dist/data/test-runner/adapter.cjs.map +1 -1
  431. package/dist/data/test-runner/adapter.d.ts +15 -0
  432. package/dist/data/test-runner/adapter.d.ts.map +1 -1
  433. package/dist/data/test-runner/adapter.js +14 -0
  434. package/dist/data/test-runner/adapter.js.map +1 -1
  435. package/dist/data/test-runner/context.cjs.map +1 -1
  436. package/dist/data/test-runner/context.d.ts +5 -0
  437. package/dist/data/test-runner/context.d.ts.map +1 -1
  438. package/dist/data/test-runner/context.js.map +1 -1
  439. package/dist/data/test-runner/index.d.ts +3 -0
  440. package/dist/data/test-runner/index.d.ts.map +1 -1
  441. package/dist/data/test-runner/status.cjs +5 -0
  442. package/dist/data/test-runner/status.cjs.map +1 -1
  443. package/dist/data/test-runner/status.d.ts +2 -0
  444. package/dist/data/test-runner/status.d.ts.map +1 -1
  445. package/dist/data/test-runner/status.js +5 -1
  446. package/dist/data/test-runner/status.js.map +1 -1
  447. package/dist/data/traces/index.d.ts +2 -1
  448. package/dist/data/traces/index.d.ts.map +1 -1
  449. package/dist/data/traces/otel/OtelTraceBrowser.cjs +173 -0
  450. package/dist/data/traces/otel/OtelTraceBrowser.cjs.map +1 -0
  451. package/dist/data/traces/otel/OtelTraceBrowser.d.ts +31 -0
  452. package/dist/data/traces/otel/OtelTraceBrowser.d.ts.map +1 -0
  453. package/dist/data/traces/otel/OtelTraceBrowser.js +173 -0
  454. package/dist/data/traces/otel/OtelTraceBrowser.js.map +1 -0
  455. package/dist/data/traces/otel/OtelTraceDetail.cjs +6 -4
  456. package/dist/data/traces/otel/OtelTraceDetail.cjs.map +1 -1
  457. package/dist/data/traces/otel/OtelTraceDetail.d.ts +5 -1
  458. package/dist/data/traces/otel/OtelTraceDetail.d.ts.map +1 -1
  459. package/dist/data/traces/otel/OtelTraceDetail.js +6 -4
  460. package/dist/data/traces/otel/OtelTraceDetail.js.map +1 -1
  461. package/dist/data/traces/otel/OtelTraceSearch.cjs +2 -1
  462. package/dist/data/traces/otel/OtelTraceSearch.cjs.map +1 -1
  463. package/dist/data/traces/otel/OtelTraceSearch.d.ts +3 -1
  464. package/dist/data/traces/otel/OtelTraceSearch.d.ts.map +1 -1
  465. package/dist/data/traces/otel/OtelTraceSearch.js +2 -1
  466. package/dist/data/traces/otel/OtelTraceSearch.js.map +1 -1
  467. package/dist/data/traces/otel/OtelTraceTable.cjs +62 -6
  468. package/dist/data/traces/otel/OtelTraceTable.cjs.map +1 -1
  469. package/dist/data/traces/otel/OtelTraceTable.d.ts +22 -1
  470. package/dist/data/traces/otel/OtelTraceTable.d.ts.map +1 -1
  471. package/dist/data/traces/otel/OtelTraceTable.js +62 -6
  472. package/dist/data/traces/otel/OtelTraceTable.js.map +1 -1
  473. package/dist/data/traces/otel/QueryBar.cjs +23 -10
  474. package/dist/data/traces/otel/QueryBar.cjs.map +1 -1
  475. package/dist/data/traces/otel/QueryBar.d.ts +3 -1
  476. package/dist/data/traces/otel/QueryBar.d.ts.map +1 -1
  477. package/dist/data/traces/otel/QueryBar.js +23 -10
  478. package/dist/data/traces/otel/QueryBar.js.map +1 -1
  479. package/dist/data/traces/otel/browser-state.cjs +86 -0
  480. package/dist/data/traces/otel/browser-state.cjs.map +1 -0
  481. package/dist/data/traces/otel/browser-state.d.ts +22 -0
  482. package/dist/data/traces/otel/browser-state.d.ts.map +1 -0
  483. package/dist/data/traces/otel/browser-state.js +83 -0
  484. package/dist/data/traces/otel/browser-state.js.map +1 -0
  485. package/dist/data/version-info.cjs +3 -3
  486. package/dist/data/version-info.js +3 -3
  487. package/dist/data.cjs +17 -0
  488. package/dist/data.d.ts +3 -3
  489. package/dist/data.d.ts.map +1 -1
  490. package/dist/data.js +10 -3
  491. package/dist/file-findings/file-review/FileReview.cjs +38 -11
  492. package/dist/file-findings/file-review/FileReview.cjs.map +1 -1
  493. package/dist/file-findings/file-review/FileReview.d.ts.map +1 -1
  494. package/dist/file-findings/file-review/FileReview.js +39 -12
  495. package/dist/file-findings/file-review/FileReview.js.map +1 -1
  496. package/dist/file-findings/file-review/geometry.cjs +20 -15
  497. package/dist/file-findings/file-review/geometry.cjs.map +1 -1
  498. package/dist/file-findings/file-review/geometry.d.ts +5 -3
  499. package/dist/file-findings/file-review/geometry.d.ts.map +1 -1
  500. package/dist/file-findings/file-review/geometry.js +21 -16
  501. package/dist/file-findings/file-review/geometry.js.map +1 -1
  502. package/dist/file-findings/file-review/patch-comments.cjs +23 -16
  503. package/dist/file-findings/file-review/patch-comments.cjs.map +1 -1
  504. package/dist/file-findings/file-review/patch-comments.d.ts +22 -12
  505. package/dist/file-findings/file-review/patch-comments.d.ts.map +1 -1
  506. package/dist/file-findings/file-review/patch-comments.js +23 -17
  507. package/dist/file-findings/file-review/patch-comments.js.map +1 -1
  508. package/dist/file-findings/file-review/quote-anchor.cjs +23 -9
  509. package/dist/file-findings/file-review/quote-anchor.cjs.map +1 -1
  510. package/dist/file-findings/file-review/quote-anchor.d.ts +12 -2
  511. package/dist/file-findings/file-review/quote-anchor.d.ts.map +1 -1
  512. package/dist/file-findings/file-review/quote-anchor.js +22 -9
  513. package/dist/file-findings/file-review/quote-anchor.js.map +1 -1
  514. package/dist/file-findings/file-review/selection-lines.cjs +17 -8
  515. package/dist/file-findings/file-review/selection-lines.cjs.map +1 -1
  516. package/dist/file-findings/file-review/selection-lines.d.ts +3 -2
  517. package/dist/file-findings/file-review/selection-lines.d.ts.map +1 -1
  518. package/dist/file-findings/file-review/selection-lines.js +17 -8
  519. package/dist/file-findings/file-review/selection-lines.js.map +1 -1
  520. package/dist/file-findings/file-review/table-cell.cjs +95 -0
  521. package/dist/file-findings/file-review/table-cell.cjs.map +1 -0
  522. package/dist/file-findings/file-review/table-cell.d.ts +31 -0
  523. package/dist/file-findings/file-review/table-cell.d.ts.map +1 -0
  524. package/dist/file-findings/file-review/table-cell.js +92 -0
  525. package/dist/file-findings/file-review/table-cell.js.map +1 -0
  526. package/dist/file-findings.cjs +2 -0
  527. package/dist/file-findings.d.ts +1 -0
  528. package/dist/file-findings.d.ts.map +1 -1
  529. package/dist/file-findings.js +2 -1
  530. package/dist/icons/components/UiFolderGit.cjs +8 -8
  531. package/dist/icons/components/UiFolderGit.cjs.map +1 -1
  532. package/dist/icons/components/UiFolderGit.js +8 -8
  533. package/dist/icons/components/UiFolderGit.js.map +1 -1
  534. package/dist/icons/components/UiUserSwitch.cjs +51 -0
  535. package/dist/icons/components/UiUserSwitch.cjs.map +1 -0
  536. package/dist/icons/components/UiUserSwitch.d.ts +15 -0
  537. package/dist/icons/components/UiUserSwitch.d.ts.map +1 -0
  538. package/dist/icons/components/UiUserSwitch.js +48 -0
  539. package/dist/icons/components/UiUserSwitch.js.map +1 -0
  540. package/dist/icons/index.d.ts +2 -0
  541. package/dist/icons/index.d.ts.map +1 -1
  542. package/dist/icons/registry.cjs +2 -0
  543. package/dist/icons/registry.cjs.map +1 -1
  544. package/dist/icons/registry.d.ts.map +1 -1
  545. package/dist/icons/registry.js +2 -0
  546. package/dist/icons/registry.js.map +1 -1
  547. package/dist/icons.cjs +3 -0
  548. package/dist/icons.js +2 -1
  549. package/dist/index.cjs +23 -0
  550. package/dist/index.js +13 -3
  551. package/dist/jvm/model/threads.cjs +1 -1
  552. package/dist/jvm/model/threads.cjs.map +1 -1
  553. package/dist/jvm/model/threads.js +1 -1
  554. package/dist/jvm/model/threads.js.map +1 -1
  555. package/dist/lib/random-uuid.cjs +12 -0
  556. package/dist/lib/random-uuid.cjs.map +1 -0
  557. package/dist/lib/random-uuid.d.ts +2 -0
  558. package/dist/lib/random-uuid.d.ts.map +1 -0
  559. package/dist/lib/random-uuid.js +12 -0
  560. package/dist/lib/random-uuid.js.map +1 -0
  561. package/dist/overlay/Modal.cjs +22 -11
  562. package/dist/overlay/Modal.cjs.map +1 -1
  563. package/dist/overlay/Modal.d.ts +5 -1
  564. package/dist/overlay/Modal.d.ts.map +1 -1
  565. package/dist/overlay/Modal.js +22 -11
  566. package/dist/overlay/Modal.js.map +1 -1
  567. package/dist/overlay/ModalProvider.cjs +238 -0
  568. package/dist/overlay/ModalProvider.cjs.map +1 -0
  569. package/dist/overlay/ModalProvider.d.ts +10 -0
  570. package/dist/overlay/ModalProvider.d.ts.map +1 -0
  571. package/dist/overlay/ModalProvider.js +238 -0
  572. package/dist/overlay/ModalProvider.js.map +1 -0
  573. package/dist/overlay/modal-context.cjs +12 -0
  574. package/dist/overlay/modal-context.cjs.map +1 -0
  575. package/dist/overlay/modal-context.d.ts +46 -0
  576. package/dist/overlay/modal-context.d.ts.map +1 -0
  577. package/dist/overlay/modal-context.js +11 -0
  578. package/dist/overlay/modal-context.js.map +1 -0
  579. package/dist/overlay/modal-draft-storage.cjs +51 -0
  580. package/dist/overlay/modal-draft-storage.cjs.map +1 -0
  581. package/dist/overlay/modal-draft-storage.d.ts +19 -0
  582. package/dist/overlay/modal-draft-storage.d.ts.map +1 -0
  583. package/dist/overlay/modal-draft-storage.js +47 -0
  584. package/dist/overlay/modal-draft-storage.js.map +1 -0
  585. package/dist/runtime/barrels.json +8696 -8652
  586. package/dist/runtime/importmap.json +2116 -2103
  587. package/dist/styles.css +1 -1
  588. package/dist/utils.cjs +2 -0
  589. package/dist/utils.d.ts +1 -0
  590. package/dist/utils.d.ts.map +1 -1
  591. package/dist/utils.js +2 -1
  592. package/package.json +2 -2
@@ -1,3 +1,4 @@
1
+ const require_table_cell = require("./table-cell.cjs");
1
2
  // src/file-findings/file-review/quote-anchor.ts
2
3
  var QUOTE_PREFIX = "q:";
3
4
  var SOURCE_BLOCK = "[data-source-start]";
@@ -166,17 +167,29 @@ var QUOTE_TIERS = [...TIERS, {
166
167
  suffix: false
167
168
  }];
168
169
  /**
169
- * Finds a patch's quote again, searching only the rendered blocks that cover
170
- * source lines `start`..`end` (where the patch matches now). The words with
170
+ * The rendered elements covering source lines `start`..`end`: each top-level
171
+ * block that overlaps them, or for a table only its rows on those lines.
172
+ */
173
+ function elementsInLines(root, lines) {
174
+ return sections(root).flatMap(({ block }) => {
175
+ const { sourceStart, sourceEnd } = block.dataset;
176
+ if (Number(sourceStart) > lines.end || Number(sourceEnd) < lines.start) return [];
177
+ const rows = require_table_cell.tableRows(block);
178
+ return rows.length > 0 ? rows.filter(({ line }) => line >= lines.start && line <= lines.end).map(({ row }) => row) : [block];
179
+ });
180
+ }
181
+ /**
182
+ * Finds a patch's quote again, searching only `within` (the rendered elements
183
+ * where the patch matches now, or the cell it was made in). The words with
171
184
  * their context first, then with the context edited away; null once they are
172
185
  * gone, or repeat so that nothing tells the occurrences apart, so the caller
173
186
  * falls back to highlighting the lines.
174
187
  */
175
- function resolveQuoteInLines(root, lines, quote) {
176
- const covering = sections(root).filter(({ block }) => {
177
- const { sourceStart, sourceEnd } = block.dataset;
178
- return Number(sourceStart) <= lines.end && Number(sourceEnd) >= lines.start;
179
- });
188
+ function resolveQuoteWithin(within, quote) {
189
+ const candidates = within.map((block) => ({
190
+ block,
191
+ path: []
192
+ }));
180
193
  const locator = {
181
194
  path: [],
182
195
  prefix: quote.prefix,
@@ -184,7 +197,7 @@ function resolveQuoteInLines(root, lines, quote) {
184
197
  suffix: quote.suffix
185
198
  };
186
199
  for (const tier of QUOTE_TIERS) {
187
- const found = matches(covering, locator, tier);
200
+ const found = matches(candidates, locator, tier);
188
201
  if (found.length === 1) return rangeIn(found[0].block, found[0].start, found[0].end);
189
202
  if (found.length > 1) return null;
190
203
  }
@@ -272,6 +285,7 @@ function describeQuote(locator) {
272
285
  exports.QUOTE_PREFIX = QUOTE_PREFIX;
273
286
  exports.captureTextQuote = captureTextQuote;
274
287
  exports.describeQuote = describeQuote;
288
+ exports.elementsInLines = elementsInLines;
275
289
  exports.locateSelection = locateSelection;
276
290
  exports.locateSourceSelection = locateSourceSelection;
277
291
  exports.markdownOutline = markdownOutline;
@@ -279,7 +293,7 @@ exports.parseQuoteAnchor = parseQuoteAnchor;
279
293
  exports.quoteAnchor = quoteAnchor;
280
294
  exports.quoteLiesInLines = quoteLiesInLines;
281
295
  exports.resolveQuote = resolveQuote;
282
- exports.resolveQuoteInLines = resolveQuoteInLines;
296
+ exports.resolveQuoteWithin = resolveQuoteWithin;
283
297
  exports.sourceSpans = sourceSpans;
284
298
 
285
299
  //# sourceMappingURL=quote-anchor.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"quote-anchor.cjs","names":[],"sources":["../../../src/file-findings/file-review/quote-anchor.ts"],"sourcesContent":["// Anchors on words inside rendered markdown, in the spirit of the W3C\n// TextQuoteSelector: a quote is found again through the heading outline (the\n// section it sits in) plus a few words on each side, so the same words\n// elsewhere — or edits to other sections — never move it.\nimport type { TextQuote } from \"../../comments/annotation-types\";\n\n/** A quote inside the section named by `path` (its heading trail), with the words around it. */\nexport type QuoteLocator = { path: string[]; prefix: string; quote: string; suffix: string };\n\nexport const QUOTE_PREFIX = \"q:\";\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\nconst HEADING = /^h([1-6])$/;\n/** Heading text kept in a path; longer headings are cut so stored anchors stay bounded. */\nexport const OUTLINE_HEADING_LIMIT = 200;\n/** Context words taken on each side to start with; grown until the anchor is unique. */\nconst MIN_CONTEXT_WORDS = 2;\n\nexport function quoteAnchor(locator: QuoteLocator): string {\n return `${QUOTE_PREFIX}${JSON.stringify([locator.path, locator.prefix, locator.quote, locator.suffix])}`;\n}\n\n/** The locator a `q:` anchor encodes; throws for a malformed one. */\nexport function parseQuoteAnchor(anchor: string): QuoteLocator {\n if (!anchor.startsWith(QUOTE_PREFIX)) throw new Error(`not a quote anchor: ${JSON.stringify(anchor)}`);\n const parsed: unknown = JSON.parse(anchor.slice(QUOTE_PREFIX.length));\n const [path, prefix, quote, suffix] = Array.isArray(parsed) ? parsed : [];\n if (\n !Array.isArray(path) ||\n !path.every((heading) => typeof heading === \"string\") ||\n typeof prefix !== \"string\" ||\n typeof quote !== \"string\" ||\n typeof suffix !== \"string\"\n ) {\n throw new Error(`malformed quote anchor ${JSON.stringify(anchor)}`);\n }\n return { path, prefix, quote, suffix };\n}\n\n/** A top-level rendered block, the heading trail it sits under, and its first source line. */\nexport type OutlineEntry = { block: Element; path: string[]; line: number };\n\n/**\n * Every top-level block of rendered markdown (`Markdown sourceBlocks`) in\n * document order, with the headings above it: its table-of-contents path.\n */\nexport function markdownOutline(root: Element): OutlineEntry[] {\n const stack: { level: number; text: string }[] = [];\n return [...root.querySelectorAll(SOURCE_BLOCK)]\n .filter((block) => !block.parentElement?.closest(SOURCE_BLOCK))\n .map((block) => {\n const level = HEADING.exec(block.tagName.toLowerCase())?.[1];\n if (level) {\n while (stack.length > 0 && (stack.at(-1)?.level ?? 0) >= Number(level)) stack.pop();\n const text = blockText(block).replace(/\\s+/g, \" \").trim().slice(0, OUTLINE_HEADING_LIMIT);\n stack.push({ level: Number(level), text });\n }\n return { block, path: stack.map((heading) => heading.text), line: Number((block as HTMLElement).dataset.sourceStart) };\n });\n}\n\ntype Section = Pick<OutlineEntry, \"block\" | \"path\">;\n\nconst sections = (root: Element): Section[] => markdownOutline(root);\n\nfunction textNodes(block: Element): Text[] {\n const walker = document.createTreeWalker(block, NodeFilter.SHOW_TEXT);\n const nodes: Text[] = [];\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n if (!node.parentElement?.closest(\"[data-comment-author]\")) nodes.push(node as Text);\n }\n return nodes;\n}\n\n/** A block's text exactly as its text nodes concatenate, so offsets map back onto them. */\nfunction blockText(block: Element): string {\n return textNodes(block)\n .map((node) => node.data)\n .join(\"\");\n}\n\nfunction rangeIn(block: Element, start: number, end: number): Range {\n const range = document.createRange();\n let offset = 0;\n let started = false;\n for (const node of textNodes(block)) {\n if (!started && start < offset + node.length) {\n range.setStart(node, start - offset);\n started = true;\n }\n if (started && end <= offset + node.length) {\n range.setEnd(node, end - offset);\n return range;\n }\n offset += node.length;\n }\n throw new Error(`quote-anchor: offsets ${start}-${end} lie outside the block`);\n}\n\n// Rendered cells and list items concatenate without whitespace (\"lead5 min\"),\n// so any run of whitespace in the locator matches zero or more in the text.\nfunction pattern(text: string): string {\n return text\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .map((word) => word.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"))\n .join(\"\\\\s*\");\n}\n\ntype Match = { block: Element; start: number; end: number };\n\nfunction matches(candidates: readonly Section[], locator: QuoteLocator, context: { prefix: boolean; suffix: boolean }): Match[] {\n const before = context.prefix && locator.prefix.trim() ? `(?<=${pattern(locator.prefix)}\\\\s*)` : \"\";\n const after = context.suffix && locator.suffix.trim() ? `(?=\\\\s*${pattern(locator.suffix)})` : \"\";\n const regex = new RegExp(`${before}${pattern(locator.quote)}${after}`, \"g\");\n return candidates.flatMap(({ block }) =>\n [...blockText(block).matchAll(regex)].map((m) => ({ block, start: m.index, end: m.index + m[0].length })),\n );\n}\n\nconst samePath = (a: readonly string[], b: readonly string[]) => a.length === b.length && a.every((h, i) => h === b[i]);\n\n// Strictest first. A looser tier is tried only when a stricter one finds\n// nothing, so edited context still resolves, but never guesses between two.\nconst TIERS = [\n { prefix: true, suffix: true },\n { prefix: true, suffix: false },\n { prefix: false, suffix: true },\n] as const;\n\n/**\n * Finds a quote again: in its section by quote plus context, then with one\n * side of the context edited away; failing that (a renamed heading), anywhere\n * by the full context. Null when it is gone or ambiguous.\n */\nexport function resolveQuote(root: Element, locator: QuoteLocator): Range | null {\n const all = sections(root);\n const section = all.filter((s) => samePath(s.path, locator.path));\n for (const tier of TIERS) {\n const found = matches(section, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n }\n const relocated = matches(all, locator, TIERS[0]);\n return relocated.length === 1 ? rangeIn(relocated[0]!.block, relocated[0]!.start, relocated[0]!.end) : null;\n}\n\n/**\n * The locator for a selection inside one block, with just enough context on\n * each side to make it unique in its section. Null when the selection spans\n * blocks, is blank, or repeats so exactly that no context tells it apart.\n */\nexport function locateSelection(root: Element, range: Range): QuoteLocator | null {\n const all = sections(root);\n const own = all.find(({ block }) => block.contains(range.startContainer) && block.contains(range.endContainer));\n if (!own) return null;\n const text = blockText(own.block);\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const raw = rangeText(range);\n const start = rangeText(lead).length + (raw.length - raw.trimStart().length);\n const end = rangeText(lead).length + raw.trimEnd().length;\n if (end <= start) return null;\n\n const before = text.slice(0, start).split(/\\s+/).filter(Boolean);\n const after = text.slice(end).split(/\\s+/).filter(Boolean);\n const section = all.filter((s) => samePath(s.path, own.path));\n for (let words = MIN_CONTEXT_WORDS; ; words++) {\n const locator = {\n path: own.path,\n prefix: before.slice(-words).join(\" \"),\n quote: text.slice(start, end),\n suffix: after.slice(0, words).join(\" \"),\n };\n const found = matches(section, locator, TIERS[0]);\n if (found.length === 1 && found[0]!.block === own.block && found[0]!.start === start) return locator;\n if (words >= before.length && words >= after.length) return null;\n }\n}\n\n/** A selection inside one rendered block as the words with the words around them; null when it spans blocks or is blank. */\nexport function captureTextQuote(root: Element, range: Range): TextQuote | null {\n const locator = locateSelection(root, range);\n return locator && { prefix: locator.prefix, exact: locator.quote, suffix: locator.suffix };\n}\n\n/** Context from the strictest tier to none at all: inside a patch's few lines the words alone may be enough. */\nconst QUOTE_TIERS = [...TIERS, { prefix: false, suffix: false }] as const;\n\n/**\n * Finds a patch's quote again, searching only the rendered blocks that cover\n * source lines `start`..`end` (where the patch matches now). The words with\n * their context first, then with the context edited away; null once they are\n * gone, or repeat so that nothing tells the occurrences apart, so the caller\n * falls back to highlighting the lines.\n */\nexport function resolveQuoteInLines(root: Element, lines: { start: number; end: number }, quote: TextQuote): Range | null {\n const covering = sections(root).filter(({ block }) => {\n const { sourceStart, sourceEnd } = (block as HTMLElement).dataset;\n return Number(sourceStart) <= lines.end && Number(sourceEnd) >= lines.start;\n });\n const locator = { path: [], prefix: quote.prefix, quote: quote.exact, suffix: quote.suffix };\n for (const tier of QUOTE_TIERS) {\n const found = matches(covering, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n if (found.length > 1) return null;\n }\n return null;\n}\n\n/**\n * Whether the quote's exact text appears verbatim in the markdown source `lines`:\n * the rule the server enforces on a selector's quote. Rendered text that\n * differs from its source (`**bold**`, links, escapes) therefore does not lie\n * in the lines, and the patch alone anchors the thread.\n */\nexport function quoteLiesInLines(quote: TextQuote, lines: readonly string[]): boolean {\n return quote.exact !== \"\" && lines.join(\"\\n\").includes(quote.exact);\n}\n\n/** A run of characters on one source line (1-based line, 0-based columns). */\nexport type SourceSpan = { line: number; start: number; end: number };\n\n// Markdown markup that renders as nothing (emphasis, code ticks, table pipes,\n// quote and heading markers, list bullets), so it may sit between source words.\nconst MARKUP = /[*_`|>#~]|(?:^|\\s)[-+](?=\\s)/g;\n\nfunction sourcePattern(quote: string): string {\n return pattern(quote.replace(MARKUP, \" \")).replaceAll(\"\\\\s*\", \"[\\\\s*_`|>#~]*\");\n}\n\nfunction sourceBlocks(root: Element, lines: readonly string[]) {\n return sections(root).map(({ block }) => {\n const first = Number((block as HTMLElement).dataset.sourceStart);\n const last = Number((block as HTMLElement).dataset.sourceEnd);\n return { block, first, last, text: lines.slice(first - 1, last).join(\"\\n\") };\n });\n}\n\nconst allMatches = (text: string, source: string) => [...text.matchAll(new RegExp(source, \"g\"))];\n\n/**\n * The quote locator for a selection in the raw markdown: the selection's words\n * are found in the rendered block built from that line, as the same occurrence\n * they are in the source, so a comment made in Source shows in Preview too.\n * Null when the selection is only markup or its block renders no such words.\n */\nexport function locateSourceSelection(root: Element, lines: readonly string[], span: SourceSpan): QuoteLocator | null {\n const selected = lines[span.line - 1]?.slice(span.start, span.end) ?? \"\";\n if (!selected.replace(MARKUP, \" \").trim()) return null;\n const own = sourceBlocks(root, lines).find((b) => span.line >= b.first && span.line <= b.last);\n if (!own) return null;\n const at = lines.slice(own.first - 1, span.line - 1).reduce((sum, l) => sum + l.length + 1, 0) + span.start;\n const k = allMatches(own.text, sourcePattern(selected)).findIndex((m) => m.index + m[0].length > at && m.index < at + selected.length);\n const hit = k < 0 ? undefined : allMatches(blockText(own.block), pattern(selected.replace(MARKUP, \" \")))[k];\n return hit ? locateSelection(root, rangeIn(own.block, hit.index, hit.index + hit[0].length)) : null;\n}\n\n/** Where a quote anchor's text sits in the raw markdown, one span per source line it covers. */\nexport function sourceSpans(root: Element, lines: readonly string[], locator: QuoteLocator): SourceSpan[] {\n const range = resolveQuote(root, locator);\n const own = range && sourceBlocks(root, lines).find(({ block }) => block.contains(range.startContainer));\n if (!range || !own) return [];\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const offset = rangeText(lead).length;\n const k = allMatches(blockText(own.block), pattern(locator.quote)).findIndex((m) => m.index === offset);\n const hit = k < 0 ? undefined : allMatches(own.text, sourcePattern(locator.quote))[k];\n if (!hit) return [];\n const spans: SourceSpan[] = [];\n let lineStart = 0;\n for (let line = own.first; line <= own.last; line++) {\n const text = lines[line - 1] ?? \"\";\n const start = Math.max(hit.index, lineStart) - lineStart;\n const end = Math.min(hit.index + hit[0].length, lineStart + text.length) - lineStart;\n if (end > start) spans.push({ line, start, end });\n lineStart += text.length + 1;\n }\n return spans;\n}\n\nfunction rangeText(range: Range): string {\n const content = range.cloneContents();\n for (const avatar of content.querySelectorAll(\"[data-comment-author]\")) avatar.remove();\n return content.textContent ?? \"\";\n}\n\n/** Reader-facing label: the section and the quoted words. */\nexport function describeQuote(locator: QuoteLocator): string {\n const section = locator.path.at(-1);\n return `${section ? `${section} › ` : \"\"}“${locator.quote}”`;\n}\n"],"mappings":";AASA,IAAa,eAAe;AAE5B,IAAM,eAAe;AACrB,IAAM,UAAU;;AAIhB,IAAM,oBAAoB;AAE1B,SAAgB,YAAY,SAA+B;CACzD,OAAO,KAAkB,KAAK,UAAU;EAAC,QAAQ;EAAM,QAAQ;EAAQ,QAAQ;EAAO,QAAQ;CAAM,CAAC;AACvG;;AAGA,SAAgB,iBAAiB,QAA8B;CAC7D,IAAI,CAAC,OAAO,WAAA,IAAuB,GAAG,MAAM,IAAI,MAAM,uBAAuB,KAAK,UAAU,MAAM,GAAG;CACrG,MAAM,SAAkB,KAAK,MAAM,OAAO,MAAM,CAAmB,CAAC;CACpE,MAAM,CAAC,MAAM,QAAQ,OAAO,UAAU,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC;CACxE,IACE,CAAC,MAAM,QAAQ,IAAI,KACnB,CAAC,KAAK,OAAO,YAAY,OAAO,YAAY,QAAQ,KACpD,OAAO,WAAW,YAClB,OAAO,UAAU,YACjB,OAAO,WAAW,UAElB,MAAM,IAAI,MAAM,0BAA0B,KAAK,UAAU,MAAM,GAAG;CAEpE,OAAO;EAAE;EAAM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K,IAAI,OAAO,IAAI,OAAO,QAAQ,IAAI,MAAM,QAAQ;EACnD,MAAM,OAAO,MAAM,OAAO,MAAM;EAChC,MAAM,QAAQ,KAAK,IAAI,IAAI,OAAO,SAAS,IAAI;EAC/C,MAAM,MAAM,KAAK,IAAI,IAAI,QAAQ,IAAI,EAAE,CAAC,QAAQ,YAAY,KAAK,MAAM,IAAI;EAC3E,IAAI,MAAM,OAAO,MAAM,KAAK;GAAE;GAAM;GAAO;EAAI,CAAC;EAChD,aAAa,KAAK,SAAS;CAC7B;CACA,OAAO;AACT;AAEA,SAAS,UAAU,OAAsB;CACvC,MAAM,UAAU,MAAM,cAAc;CACpC,KAAK,MAAM,UAAU,QAAQ,iBAAiB,uBAAuB,GAAG,OAAO,OAAO;CACtF,OAAO,QAAQ,eAAe;AAChC;;AAGA,SAAgB,cAAc,SAA+B;CAC3D,MAAM,UAAU,QAAQ,KAAK,GAAG,EAAE;CAClC,OAAO,GAAG,UAAU,GAAG,QAAQ,OAAO,GAAG,GAAG,QAAQ,MAAM;AAC5D"}
1
+ {"version":3,"file":"quote-anchor.cjs","names":["tableRows"],"sources":["../../../src/file-findings/file-review/quote-anchor.ts"],"sourcesContent":["// Anchors on words inside rendered markdown, in the spirit of the W3C\n// TextQuoteSelector: a quote is found again through the heading outline (the\n// section it sits in) plus a few words on each side, so the same words\n// elsewhere — or edits to other sections — never move it.\nimport type { TextQuote } from \"../../comments/annotation-types\";\nimport { tableRows } from \"./table-cell\";\n\n/** A quote inside the section named by `path` (its heading trail), with the words around it. */\nexport type QuoteLocator = { path: string[]; prefix: string; quote: string; suffix: string };\n\nexport const QUOTE_PREFIX = \"q:\";\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\nconst HEADING = /^h([1-6])$/;\n/** Heading text kept in a path; longer headings are cut so stored anchors stay bounded. */\nexport const OUTLINE_HEADING_LIMIT = 200;\n/** Context words taken on each side to start with; grown until the anchor is unique. */\nconst MIN_CONTEXT_WORDS = 2;\n\nexport function quoteAnchor(locator: QuoteLocator): string {\n return `${QUOTE_PREFIX}${JSON.stringify([locator.path, locator.prefix, locator.quote, locator.suffix])}`;\n}\n\n/** The locator a `q:` anchor encodes; throws for a malformed one. */\nexport function parseQuoteAnchor(anchor: string): QuoteLocator {\n if (!anchor.startsWith(QUOTE_PREFIX)) throw new Error(`not a quote anchor: ${JSON.stringify(anchor)}`);\n const parsed: unknown = JSON.parse(anchor.slice(QUOTE_PREFIX.length));\n const [path, prefix, quote, suffix] = Array.isArray(parsed) ? parsed : [];\n if (\n !Array.isArray(path) ||\n !path.every((heading) => typeof heading === \"string\") ||\n typeof prefix !== \"string\" ||\n typeof quote !== \"string\" ||\n typeof suffix !== \"string\"\n ) {\n throw new Error(`malformed quote anchor ${JSON.stringify(anchor)}`);\n }\n return { path, prefix, quote, suffix };\n}\n\n/** A top-level rendered block, the heading trail it sits under, and its first source line. */\nexport type OutlineEntry = { block: Element; path: string[]; line: number };\n\n/**\n * Every top-level block of rendered markdown (`Markdown sourceBlocks`) in\n * document order, with the headings above it: its table-of-contents path.\n */\nexport function markdownOutline(root: Element): OutlineEntry[] {\n const stack: { level: number; text: string }[] = [];\n return [...root.querySelectorAll(SOURCE_BLOCK)]\n .filter((block) => !block.parentElement?.closest(SOURCE_BLOCK))\n .map((block) => {\n const level = HEADING.exec(block.tagName.toLowerCase())?.[1];\n if (level) {\n while (stack.length > 0 && (stack.at(-1)?.level ?? 0) >= Number(level)) stack.pop();\n const text = blockText(block).replace(/\\s+/g, \" \").trim().slice(0, OUTLINE_HEADING_LIMIT);\n stack.push({ level: Number(level), text });\n }\n return { block, path: stack.map((heading) => heading.text), line: Number((block as HTMLElement).dataset.sourceStart) };\n });\n}\n\ntype Section = Pick<OutlineEntry, \"block\" | \"path\">;\n\nconst sections = (root: Element): Section[] => markdownOutline(root);\n\nfunction textNodes(block: Element): Text[] {\n const walker = document.createTreeWalker(block, NodeFilter.SHOW_TEXT);\n const nodes: Text[] = [];\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n if (!node.parentElement?.closest(\"[data-comment-author]\")) nodes.push(node as Text);\n }\n return nodes;\n}\n\n/** A block's text exactly as its text nodes concatenate, so offsets map back onto them. */\nfunction blockText(block: Element): string {\n return textNodes(block)\n .map((node) => node.data)\n .join(\"\");\n}\n\nfunction rangeIn(block: Element, start: number, end: number): Range {\n const range = document.createRange();\n let offset = 0;\n let started = false;\n for (const node of textNodes(block)) {\n if (!started && start < offset + node.length) {\n range.setStart(node, start - offset);\n started = true;\n }\n if (started && end <= offset + node.length) {\n range.setEnd(node, end - offset);\n return range;\n }\n offset += node.length;\n }\n throw new Error(`quote-anchor: offsets ${start}-${end} lie outside the block`);\n}\n\n// Rendered cells and list items concatenate without whitespace (\"lead5 min\"),\n// so any run of whitespace in the locator matches zero or more in the text.\nfunction pattern(text: string): string {\n return text\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .map((word) => word.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"))\n .join(\"\\\\s*\");\n}\n\ntype Match = { block: Element; start: number; end: number };\n\nfunction matches(candidates: readonly Section[], locator: QuoteLocator, context: { prefix: boolean; suffix: boolean }): Match[] {\n const before = context.prefix && locator.prefix.trim() ? `(?<=${pattern(locator.prefix)}\\\\s*)` : \"\";\n const after = context.suffix && locator.suffix.trim() ? `(?=\\\\s*${pattern(locator.suffix)})` : \"\";\n const regex = new RegExp(`${before}${pattern(locator.quote)}${after}`, \"g\");\n return candidates.flatMap(({ block }) =>\n [...blockText(block).matchAll(regex)].map((m) => ({ block, start: m.index, end: m.index + m[0].length })),\n );\n}\n\nconst samePath = (a: readonly string[], b: readonly string[]) => a.length === b.length && a.every((h, i) => h === b[i]);\n\n// Strictest first. A looser tier is tried only when a stricter one finds\n// nothing, so edited context still resolves, but never guesses between two.\nconst TIERS = [\n { prefix: true, suffix: true },\n { prefix: true, suffix: false },\n { prefix: false, suffix: true },\n] as const;\n\n/**\n * Finds a quote again: in its section by quote plus context, then with one\n * side of the context edited away; failing that (a renamed heading), anywhere\n * by the full context. Null when it is gone or ambiguous.\n */\nexport function resolveQuote(root: Element, locator: QuoteLocator): Range | null {\n const all = sections(root);\n const section = all.filter((s) => samePath(s.path, locator.path));\n for (const tier of TIERS) {\n const found = matches(section, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n }\n const relocated = matches(all, locator, TIERS[0]);\n return relocated.length === 1 ? rangeIn(relocated[0]!.block, relocated[0]!.start, relocated[0]!.end) : null;\n}\n\n/**\n * The locator for a selection inside one block, with just enough context on\n * each side to make it unique in its section. Null when the selection spans\n * blocks, is blank, or repeats so exactly that no context tells it apart.\n */\nexport function locateSelection(root: Element, range: Range): QuoteLocator | null {\n const all = sections(root);\n const own = all.find(({ block }) => block.contains(range.startContainer) && block.contains(range.endContainer));\n if (!own) return null;\n const text = blockText(own.block);\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const raw = rangeText(range);\n const start = rangeText(lead).length + (raw.length - raw.trimStart().length);\n const end = rangeText(lead).length + raw.trimEnd().length;\n if (end <= start) return null;\n\n const before = text.slice(0, start).split(/\\s+/).filter(Boolean);\n const after = text.slice(end).split(/\\s+/).filter(Boolean);\n const section = all.filter((s) => samePath(s.path, own.path));\n for (let words = MIN_CONTEXT_WORDS; ; words++) {\n const locator = {\n path: own.path,\n prefix: before.slice(-words).join(\" \"),\n quote: text.slice(start, end),\n suffix: after.slice(0, words).join(\" \"),\n };\n const found = matches(section, locator, TIERS[0]);\n if (found.length === 1 && found[0]!.block === own.block && found[0]!.start === start) return locator;\n if (words >= before.length && words >= after.length) return null;\n }\n}\n\n/** A selection inside one rendered block as the words with the words around them; null when it spans blocks or is blank. */\nexport function captureTextQuote(root: Element, range: Range): TextQuote | null {\n const locator = locateSelection(root, range);\n return locator && { prefix: locator.prefix, exact: locator.quote, suffix: locator.suffix };\n}\n\n/** Context from the strictest tier to none at all: inside a patch's few lines the words alone may be enough. */\nconst QUOTE_TIERS = [...TIERS, { prefix: false, suffix: false }] as const;\n\n/**\n * The rendered elements covering source lines `start`..`end`: each top-level\n * block that overlaps them, or for a table only its rows on those lines.\n */\nexport function elementsInLines(root: Element, lines: { start: number; end: number }): Element[] {\n return sections(root).flatMap(({ block }) => {\n const { sourceStart, sourceEnd } = (block as HTMLElement).dataset;\n if (Number(sourceStart) > lines.end || Number(sourceEnd) < lines.start) return [];\n const rows = tableRows(block);\n return rows.length > 0 ? rows.filter(({ line }) => line >= lines.start && line <= lines.end).map(({ row }) => row) : [block];\n });\n}\n\n/**\n * Finds a patch's quote again, searching only `within` (the rendered elements\n * where the patch matches now, or the cell it was made in). The words with\n * their context first, then with the context edited away; null once they are\n * gone, or repeat so that nothing tells the occurrences apart, so the caller\n * falls back to highlighting the lines.\n */\nexport function resolveQuoteWithin(within: readonly Element[], quote: TextQuote): Range | null {\n const candidates = within.map((block) => ({ block, path: [] }));\n const locator = { path: [], prefix: quote.prefix, quote: quote.exact, suffix: quote.suffix };\n for (const tier of QUOTE_TIERS) {\n const found = matches(candidates, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n if (found.length > 1) return null;\n }\n return null;\n}\n\n/** `resolveQuoteWithin` the elements covering source lines `start`..`end`. */\nexport function resolveQuoteInLines(root: Element, lines: { start: number; end: number }, quote: TextQuote): Range | null {\n return resolveQuoteWithin(elementsInLines(root, lines), quote);\n}\n\n/**\n * Whether the quote's exact text appears verbatim in the markdown source `lines`:\n * the rule the server enforces on a selector's quote. Rendered text that\n * differs from its source (`**bold**`, links, escapes) therefore does not lie\n * in the lines, and the patch alone anchors the thread.\n */\nexport function quoteLiesInLines(quote: TextQuote, lines: readonly string[]): boolean {\n return quote.exact !== \"\" && lines.join(\"\\n\").includes(quote.exact);\n}\n\n/** A run of characters on one source line (1-based line, 0-based columns). */\nexport type SourceSpan = { line: number; start: number; end: number };\n\n// Markdown markup that renders as nothing (emphasis, code ticks, table pipes,\n// quote and heading markers, list bullets), so it may sit between source words.\nconst MARKUP = /[*_`|>#~]|(?:^|\\s)[-+](?=\\s)/g;\n\nfunction sourcePattern(quote: string): string {\n return pattern(quote.replace(MARKUP, \" \")).replaceAll(\"\\\\s*\", \"[\\\\s*_`|>#~]*\");\n}\n\nfunction sourceBlocks(root: Element, lines: readonly string[]) {\n return sections(root).map(({ block }) => {\n const first = Number((block as HTMLElement).dataset.sourceStart);\n const last = Number((block as HTMLElement).dataset.sourceEnd);\n return { block, first, last, text: lines.slice(first - 1, last).join(\"\\n\") };\n });\n}\n\nconst allMatches = (text: string, source: string) => [...text.matchAll(new RegExp(source, \"g\"))];\n\n/**\n * The quote locator for a selection in the raw markdown: the selection's words\n * are found in the rendered block built from that line, as the same occurrence\n * they are in the source, so a comment made in Source shows in Preview too.\n * Null when the selection is only markup or its block renders no such words.\n */\nexport function locateSourceSelection(root: Element, lines: readonly string[], span: SourceSpan): QuoteLocator | null {\n const selected = lines[span.line - 1]?.slice(span.start, span.end) ?? \"\";\n if (!selected.replace(MARKUP, \" \").trim()) return null;\n const own = sourceBlocks(root, lines).find((b) => span.line >= b.first && span.line <= b.last);\n if (!own) return null;\n const at = lines.slice(own.first - 1, span.line - 1).reduce((sum, l) => sum + l.length + 1, 0) + span.start;\n const k = allMatches(own.text, sourcePattern(selected)).findIndex((m) => m.index + m[0].length > at && m.index < at + selected.length);\n const hit = k < 0 ? undefined : allMatches(blockText(own.block), pattern(selected.replace(MARKUP, \" \")))[k];\n return hit ? locateSelection(root, rangeIn(own.block, hit.index, hit.index + hit[0].length)) : null;\n}\n\n/** Where a quote anchor's text sits in the raw markdown, one span per source line it covers. */\nexport function sourceSpans(root: Element, lines: readonly string[], locator: QuoteLocator): SourceSpan[] {\n const range = resolveQuote(root, locator);\n const own = range && sourceBlocks(root, lines).find(({ block }) => block.contains(range.startContainer));\n if (!range || !own) return [];\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const offset = rangeText(lead).length;\n const k = allMatches(blockText(own.block), pattern(locator.quote)).findIndex((m) => m.index === offset);\n const hit = k < 0 ? undefined : allMatches(own.text, sourcePattern(locator.quote))[k];\n if (!hit) return [];\n const spans: SourceSpan[] = [];\n let lineStart = 0;\n for (let line = own.first; line <= own.last; line++) {\n const text = lines[line - 1] ?? \"\";\n const start = Math.max(hit.index, lineStart) - lineStart;\n const end = Math.min(hit.index + hit[0].length, lineStart + text.length) - lineStart;\n if (end > start) spans.push({ line, start, end });\n lineStart += text.length + 1;\n }\n return spans;\n}\n\nfunction rangeText(range: Range): string {\n const content = range.cloneContents();\n for (const avatar of content.querySelectorAll(\"[data-comment-author]\")) avatar.remove();\n return content.textContent ?? \"\";\n}\n\n/** Reader-facing label: the section and the quoted words. */\nexport function describeQuote(locator: QuoteLocator): string {\n const section = locator.path.at(-1);\n return `${section ? `${section} › ` : \"\"}“${locator.quote}”`;\n}\n"],"mappings":";;AAUA,IAAa,eAAe;AAE5B,IAAM,eAAe;AACrB,IAAM,UAAU;;AAIhB,IAAM,oBAAoB;AAE1B,SAAgB,YAAY,SAA+B;CACzD,OAAO,KAAkB,KAAK,UAAU;EAAC,QAAQ;EAAM,QAAQ;EAAQ,QAAQ;EAAO,QAAQ;CAAM,CAAC;AACvG;;AAGA,SAAgB,iBAAiB,QAA8B;CAC7D,IAAI,CAAC,OAAO,WAAA,IAAuB,GAAG,MAAM,IAAI,MAAM,uBAAuB,KAAK,UAAU,MAAM,GAAG;CACrG,MAAM,SAAkB,KAAK,MAAM,OAAO,MAAM,CAAmB,CAAC;CACpE,MAAM,CAAC,MAAM,QAAQ,OAAO,UAAU,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC;CACxE,IACE,CAAC,MAAM,QAAQ,IAAI,KACnB,CAAC,KAAK,OAAO,YAAY,OAAO,YAAY,QAAQ,KACpD,OAAO,WAAW,YAClB,OAAO,UAAU,YACjB,OAAO,WAAW,UAElB,MAAM,IAAI,MAAM,0B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M,gBAAgB,MAAM,WAAW;CACnD,MAAM,SAAS,UAAU,IAAI,CAAC,CAAC;CAC/B,MAAM,IAAI,WAAW,UAAU,IAAI,KAAK,GAAG,QAAQ,QAAQ,KAAK,CAAC,CAAC,CAAC,WAAW,MAAM,EAAE,UAAU,MAAM;CACtG,MAAM,MAAM,IAAI,IAAI,KAAA,IAAY,WAAW,IAAI,MAAM,cAAc,QAAQ,KAAK,CAAC,CAAC,CAAC;CACnF,IAAI,CAAC,KAAK,OAAO,CAAC;CAClB,MAAM,QAAsB,CAAC;CAC7B,IAAI,YAAY;CAChB,KAAK,IAAI,OAAO,IAAI,OAAO,QAAQ,IAAI,MAAM,QAAQ;EACnD,MAAM,OAAO,MAAM,OAAO,MAAM;EAChC,MAAM,QAAQ,KAAK,IAAI,IAAI,OAAO,SAAS,IAAI;EAC/C,MAAM,MAAM,KAAK,IAAI,IAAI,QAAQ,IAAI,EAAE,CAAC,QAAQ,YAAY,KAAK,MAAM,IAAI;EAC3E,IAAI,MAAM,OAAO,MAAM,KAAK;GAAE;GAAM;GAAO;EAAI,CAAC;EAChD,aAAa,KAAK,SAAS;CAC7B;CACA,OAAO;AACT;AAEA,SAAS,UAAU,OAAsB;CACvC,MAAM,UAAU,MAAM,cAAc;CACpC,KAAK,MAAM,UAAU,QAAQ,iBAAiB,uBAAuB,GAAG,OAAO,OAAO;CACtF,OAAO,QAAQ,eAAe;AAChC;;AAGA,SAAgB,cAAc,SAA+B;CAC3D,MAAM,UAAU,QAAQ,KAAK,GAAG,EAAE;CAClC,OAAO,GAAG,UAAU,GAAG,QAAQ,OAAO,GAAG,GAAG,QAAQ,MAAM;AAC5D"}
@@ -38,12 +38,22 @@ export declare function locateSelection(root: Element, range: Range): QuoteLocat
38
38
  /** A selection inside one rendered block as the words with the words around them; null when it spans blocks or is blank. */
39
39
  export declare function captureTextQuote(root: Element, range: Range): TextQuote | null;
40
40
  /**
41
- * Finds a patch's quote again, searching only the rendered blocks that cover
42
- * source lines `start`..`end` (where the patch matches now). The words with
41
+ * The rendered elements covering source lines `start`..`end`: each top-level
42
+ * block that overlaps them, or for a table only its rows on those lines.
43
+ */
44
+ export declare function elementsInLines(root: Element, lines: {
45
+ start: number;
46
+ end: number;
47
+ }): Element[];
48
+ /**
49
+ * Finds a patch's quote again, searching only `within` (the rendered elements
50
+ * where the patch matches now, or the cell it was made in). The words with
43
51
  * their context first, then with the context edited away; null once they are
44
52
  * gone, or repeat so that nothing tells the occurrences apart, so the caller
45
53
  * falls back to highlighting the lines.
46
54
  */
55
+ export declare function resolveQuoteWithin(within: readonly Element[], quote: TextQuote): Range | null;
56
+ /** `resolveQuoteWithin` the elements covering source lines `start`..`end`. */
47
57
  export declare function resolveQuoteInLines(root: Element, lines: {
48
58
  start: number;
49
59
  end: number;
@@ -1 +1 @@
1
- {"version":3,"file":"quote-anchor.d.ts","sourceRoot":"","sources":["../../../src/file-findings/file-review/quote-anchor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEjE,gGAAgG;AAChG,MAAM,MAAM,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7F,eAAO,MAAM,YAAY,OAAO,CAAC;AAIjC,2FAA2F;AAC3F,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAIzC,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAEzD;AAED,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAc7D;AAED,8FAA8F;AAC9F,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E;;;GA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
@@ -166,17 +167,29 @@ var QUOTE_TIERS = [...TIERS, {
166
167
  suffix: false
167
168
  }];
168
169
  /**
169
- * Finds a patch's quote again, searching only the rendered blocks that cover
170
- * source lines `start`..`end` (where the patch matches now). The words with
170
+ * The rendered elements covering source lines `start`..`end`: each top-level
171
+ * block that overlaps them, or for a table only its rows on those lines.
172
+ */
173
+ function elementsInLines(root, lines) {
174
+ return sections(root).flatMap(({ block }) => {
175
+ const { sourceStart, sourceEnd } = block.dataset;
176
+ if (Number(sourceStart) > lines.end || Number(sourceEnd) < lines.start) return [];
177
+ const rows = tableRows(block);
178
+ return rows.length > 0 ? rows.filter(({ line }) => line >= lines.start && line <= lines.end).map(({ row }) => row) : [block];
179
+ });
180
+ }
181
+ /**
182
+ * Finds a patch's quote again, searching only `within` (the rendered elements
183
+ * where the patch matches now, or the cell it was made in). The words with
171
184
  * their context first, then with the context edited away; null once they are
172
185
  * gone, or repeat so that nothing tells the occurrences apart, so the caller
173
186
  * falls back to highlighting the lines.
174
187
  */
175
- function resolveQuoteInLines(root, lines, quote) {
176
- const covering = sections(root).filter(({ block }) => {
177
- const { sourceStart, sourceEnd } = block.dataset;
178
- return Number(sourceStart) <= lines.end && Number(sourceEnd) >= lines.start;
179
- });
188
+ function resolveQuoteWithin(within, quote) {
189
+ const candidates = within.map((block) => ({
190
+ block,
191
+ path: []
192
+ }));
180
193
  const locator = {
181
194
  path: [],
182
195
  prefix: quote.prefix,
@@ -184,7 +197,7 @@ function resolveQuoteInLines(root, lines, quote) {
184
197
  suffix: quote.suffix
185
198
  };
186
199
  for (const tier of QUOTE_TIERS) {
187
- const found = matches(covering, locator, tier);
200
+ const found = matches(candidates, locator, tier);
188
201
  if (found.length === 1) return rangeIn(found[0].block, found[0].start, found[0].end);
189
202
  if (found.length > 1) return null;
190
203
  }
@@ -269,6 +282,6 @@ function describeQuote(locator) {
269
282
  const section = locator.path.at(-1);
270
283
  return `${section ? `${section} › ` : ""}“${locator.quote}”`;
271
284
  }
272
- export { QUOTE_PREFIX, captureTextQuote, describeQuote, locateSelection, locateSourceSelection, markdownOutline, parseQuoteAnchor, quoteAnchor, quoteLiesInLines, resolveQuote, resolveQuoteInLines, sourceSpans };
285
+ export { QUOTE_PREFIX, captureTextQuote, describeQuote, elementsInLines, locateSelection, locateSourceSelection, markdownOutline, parseQuoteAnchor, quoteAnchor, quoteLiesInLines, resolveQuote, resolveQuoteWithin, sourceSpans };
273
286
 
274
287
  //# sourceMappingURL=quote-anchor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"quote-anchor.js","names":[],"sources":["../../../src/file-findings/file-review/quote-anchor.ts"],"sourcesContent":["// Anchors on words inside rendered markdown, in the spirit of the W3C\n// TextQuoteSelector: a quote is found again through the heading outline (the\n// section it sits in) plus a few words on each side, so the same words\n// elsewhere — or edits to other sections — never move it.\nimport type { TextQuote } from \"../../comments/annotation-types\";\n\n/** A quote inside the section named by `path` (its heading trail), with the words around it. */\nexport type QuoteLocator = { path: string[]; prefix: string; quote: string; suffix: string };\n\nexport const QUOTE_PREFIX = \"q:\";\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\nconst HEADING = /^h([1-6])$/;\n/** Heading text kept in a path; longer headings are cut so stored anchors stay bounded. */\nexport const OUTLINE_HEADING_LIMIT = 200;\n/** Context words taken on each side to start with; grown until the anchor is unique. */\nconst MIN_CONTEXT_WORDS = 2;\n\nexport function quoteAnchor(locator: QuoteLocator): string {\n return `${QUOTE_PREFIX}${JSON.stringify([locator.path, locator.prefix, locator.quote, locator.suffix])}`;\n}\n\n/** The locator a `q:` anchor encodes; throws for a malformed one. */\nexport function parseQuoteAnchor(anchor: string): QuoteLocator {\n if (!anchor.startsWith(QUOTE_PREFIX)) throw new Error(`not a quote anchor: ${JSON.stringify(anchor)}`);\n const parsed: unknown = JSON.parse(anchor.slice(QUOTE_PREFIX.length));\n const [path, prefix, quote, suffix] = Array.isArray(parsed) ? parsed : [];\n if (\n !Array.isArray(path) ||\n !path.every((heading) => typeof heading === \"string\") ||\n typeof prefix !== \"string\" ||\n typeof quote !== \"string\" ||\n typeof suffix !== \"string\"\n ) {\n throw new Error(`malformed quote anchor ${JSON.stringify(anchor)}`);\n }\n return { path, prefix, quote, suffix };\n}\n\n/** A top-level rendered block, the heading trail it sits under, and its first source line. */\nexport type OutlineEntry = { block: Element; path: string[]; line: number };\n\n/**\n * Every top-level block of rendered markdown (`Markdown sourceBlocks`) in\n * document order, with the headings above it: its table-of-contents path.\n */\nexport function markdownOutline(root: Element): OutlineEntry[] {\n const stack: { level: number; text: string }[] = [];\n return [...root.querySelectorAll(SOURCE_BLOCK)]\n .filter((block) => !block.parentElement?.closest(SOURCE_BLOCK))\n .map((block) => {\n const level = HEADING.exec(block.tagName.toLowerCase())?.[1];\n if (level) {\n while (stack.length > 0 && (stack.at(-1)?.level ?? 0) >= Number(level)) stack.pop();\n const text = blockText(block).replace(/\\s+/g, \" \").trim().slice(0, OUTLINE_HEADING_LIMIT);\n stack.push({ level: Number(level), text });\n }\n return { block, path: stack.map((heading) => heading.text), line: Number((block as HTMLElement).dataset.sourceStart) };\n });\n}\n\ntype Section = Pick<OutlineEntry, \"block\" | \"path\">;\n\nconst sections = (root: Element): Section[] => markdownOutline(root);\n\nfunction textNodes(block: Element): Text[] {\n const walker = document.createTreeWalker(block, NodeFilter.SHOW_TEXT);\n const nodes: Text[] = [];\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n if (!node.parentElement?.closest(\"[data-comment-author]\")) nodes.push(node as Text);\n }\n return nodes;\n}\n\n/** A block's text exactly as its text nodes concatenate, so offsets map back onto them. */\nfunction blockText(block: Element): string {\n return textNodes(block)\n .map((node) => node.data)\n .join(\"\");\n}\n\nfunction rangeIn(block: Element, start: number, end: number): Range {\n const range = document.createRange();\n let offset = 0;\n let started = false;\n for (const node of textNodes(block)) {\n if (!started && start < offset + node.length) {\n range.setStart(node, start - offset);\n started = true;\n }\n if (started && end <= offset + node.length) {\n range.setEnd(node, end - offset);\n return range;\n }\n offset += node.length;\n }\n throw new Error(`quote-anchor: offsets ${start}-${end} lie outside the block`);\n}\n\n// Rendered cells and list items concatenate without whitespace (\"lead5 min\"),\n// so any run of whitespace in the locator matches zero or more in the text.\nfunction pattern(text: string): string {\n return text\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .map((word) => word.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"))\n .join(\"\\\\s*\");\n}\n\ntype Match = { block: Element; start: number; end: number };\n\nfunction matches(candidates: readonly Section[], locator: QuoteLocator, context: { prefix: boolean; suffix: boolean }): Match[] {\n const before = context.prefix && locator.prefix.trim() ? `(?<=${pattern(locator.prefix)}\\\\s*)` : \"\";\n const after = context.suffix && locator.suffix.trim() ? `(?=\\\\s*${pattern(locator.suffix)})` : \"\";\n const regex = new RegExp(`${before}${pattern(locator.quote)}${after}`, \"g\");\n return candidates.flatMap(({ block }) =>\n [...blockText(block).matchAll(regex)].map((m) => ({ block, start: m.index, end: m.index + m[0].length })),\n );\n}\n\nconst samePath = (a: readonly string[], b: readonly string[]) => a.length === b.length && a.every((h, i) => h === b[i]);\n\n// Strictest first. A looser tier is tried only when a stricter one finds\n// nothing, so edited context still resolves, but never guesses between two.\nconst TIERS = [\n { prefix: true, suffix: true },\n { prefix: true, suffix: false },\n { prefix: false, suffix: true },\n] as const;\n\n/**\n * Finds a quote again: in its section by quote plus context, then with one\n * side of the context edited away; failing that (a renamed heading), anywhere\n * by the full context. Null when it is gone or ambiguous.\n */\nexport function resolveQuote(root: Element, locator: QuoteLocator): Range | null {\n const all = sections(root);\n const section = all.filter((s) => samePath(s.path, locator.path));\n for (const tier of TIERS) {\n const found = matches(section, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n }\n const relocated = matches(all, locator, TIERS[0]);\n return relocated.length === 1 ? rangeIn(relocated[0]!.block, relocated[0]!.start, relocated[0]!.end) : null;\n}\n\n/**\n * The locator for a selection inside one block, with just enough context on\n * each side to make it unique in its section. Null when the selection spans\n * blocks, is blank, or repeats so exactly that no context tells it apart.\n */\nexport function locateSelection(root: Element, range: Range): QuoteLocator | null {\n const all = sections(root);\n const own = all.find(({ block }) => block.contains(range.startContainer) && block.contains(range.endContainer));\n if (!own) return null;\n const text = blockText(own.block);\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const raw = rangeText(range);\n const start = rangeText(lead).length + (raw.length - raw.trimStart().length);\n const end = rangeText(lead).length + raw.trimEnd().length;\n if (end <= start) return null;\n\n const before = text.slice(0, start).split(/\\s+/).filter(Boolean);\n const after = text.slice(end).split(/\\s+/).filter(Boolean);\n const section = all.filter((s) => samePath(s.path, own.path));\n for (let words = MIN_CONTEXT_WORDS; ; words++) {\n const locator = {\n path: own.path,\n prefix: before.slice(-words).join(\" \"),\n quote: text.slice(start, end),\n suffix: after.slice(0, words).join(\" \"),\n };\n const found = matches(section, locator, TIERS[0]);\n if (found.length === 1 && found[0]!.block === own.block && found[0]!.start === start) return locator;\n if (words >= before.length && words >= after.length) return null;\n }\n}\n\n/** A selection inside one rendered block as the words with the words around them; null when it spans blocks or is blank. */\nexport function captureTextQuote(root: Element, range: Range): TextQuote | null {\n const locator = locateSelection(root, range);\n return locator && { prefix: locator.prefix, exact: locator.quote, suffix: locator.suffix };\n}\n\n/** Context from the strictest tier to none at all: inside a patch's few lines the words alone may be enough. */\nconst QUOTE_TIERS = [...TIERS, { prefix: false, suffix: false }] as const;\n\n/**\n * Finds a patch's quote again, searching only the rendered blocks that cover\n * source lines `start`..`end` (where the patch matches now). The words with\n * their context first, then with the context edited away; null once they are\n * gone, or repeat so that nothing tells the occurrences apart, so the caller\n * falls back to highlighting the lines.\n */\nexport function resolveQuoteInLines(root: Element, lines: { start: number; end: number }, quote: TextQuote): Range | null {\n const covering = sections(root).filter(({ block }) => {\n const { sourceStart, sourceEnd } = (block as HTMLElement).dataset;\n return Number(sourceStart) <= lines.end && Number(sourceEnd) >= lines.start;\n });\n const locator = { path: [], prefix: quote.prefix, quote: quote.exact, suffix: quote.suffix };\n for (const tier of QUOTE_TIERS) {\n const found = matches(covering, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n if (found.length > 1) return null;\n }\n return null;\n}\n\n/**\n * Whether the quote's exact text appears verbatim in the markdown source `lines`:\n * the rule the server enforces on a selector's quote. Rendered text that\n * differs from its source (`**bold**`, links, escapes) therefore does not lie\n * in the lines, and the patch alone anchors the thread.\n */\nexport function quoteLiesInLines(quote: TextQuote, lines: readonly string[]): boolean {\n return quote.exact !== \"\" && lines.join(\"\\n\").includes(quote.exact);\n}\n\n/** A run of characters on one source line (1-based line, 0-based columns). */\nexport type SourceSpan = { line: number; start: number; end: number };\n\n// Markdown markup that renders as nothing (emphasis, code ticks, table pipes,\n// quote and heading markers, list bullets), so it may sit between source words.\nconst MARKUP = /[*_`|>#~]|(?:^|\\s)[-+](?=\\s)/g;\n\nfunction sourcePattern(quote: string): string {\n return pattern(quote.replace(MARKUP, \" \")).replaceAll(\"\\\\s*\", \"[\\\\s*_`|>#~]*\");\n}\n\nfunction sourceBlocks(root: Element, lines: readonly string[]) {\n return sections(root).map(({ block }) => {\n const first = Number((block as HTMLElement).dataset.sourceStart);\n const last = Number((block as HTMLElement).dataset.sourceEnd);\n return { block, first, last, text: lines.slice(first - 1, last).join(\"\\n\") };\n });\n}\n\nconst allMatches = (text: string, source: string) => [...text.matchAll(new RegExp(source, \"g\"))];\n\n/**\n * The quote locator for a selection in the raw markdown: the selection's words\n * are found in the rendered block built from that line, as the same occurrence\n * they are in the source, so a comment made in Source shows in Preview too.\n * Null when the selection is only markup or its block renders no such words.\n */\nexport function locateSourceSelection(root: Element, lines: readonly string[], span: SourceSpan): QuoteLocator | null {\n const selected = lines[span.line - 1]?.slice(span.start, span.end) ?? \"\";\n if (!selected.replace(MARKUP, \" \").trim()) return null;\n const own = sourceBlocks(root, lines).find((b) => span.line >= b.first && span.line <= b.last);\n if (!own) return null;\n const at = lines.slice(own.first - 1, span.line - 1).reduce((sum, l) => sum + l.length + 1, 0) + span.start;\n const k = allMatches(own.text, sourcePattern(selected)).findIndex((m) => m.index + m[0].length > at && m.index < at + selected.length);\n const hit = k < 0 ? undefined : allMatches(blockText(own.block), pattern(selected.replace(MARKUP, \" \")))[k];\n return hit ? locateSelection(root, rangeIn(own.block, hit.index, hit.index + hit[0].length)) : null;\n}\n\n/** Where a quote anchor's text sits in the raw markdown, one span per source line it covers. */\nexport function sourceSpans(root: Element, lines: readonly string[], locator: QuoteLocator): SourceSpan[] {\n const range = resolveQuote(root, locator);\n const own = range && sourceBlocks(root, lines).find(({ block }) => block.contains(range.startContainer));\n if (!range || !own) return [];\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const offset = rangeText(lead).length;\n const k = allMatches(blockText(own.block), pattern(locator.quote)).findIndex((m) => m.index === offset);\n const hit = k < 0 ? undefined : allMatches(own.text, sourcePattern(locator.quote))[k];\n if (!hit) return [];\n const spans: SourceSpan[] = [];\n let lineStart = 0;\n for (let line = own.first; line <= own.last; line++) {\n const text = lines[line - 1] ?? \"\";\n const start = Math.max(hit.index, lineStart) - lineStart;\n const end = Math.min(hit.index + hit[0].length, lineStart + text.length) - lineStart;\n if (end > start) spans.push({ line, start, end });\n lineStart += text.length + 1;\n }\n return spans;\n}\n\nfunction rangeText(range: Range): string {\n const content = range.cloneContents();\n for (const avatar of content.querySelectorAll(\"[data-comment-author]\")) avatar.remove();\n return content.textContent ?? \"\";\n}\n\n/** Reader-facing label: the section and the quoted words. */\nexport function describeQuote(locator: QuoteLocator): string {\n const section = locator.path.at(-1);\n return `${section ? `${section} › ` : \"\"}“${locator.quote}”`;\n}\n"],"mappings":";AASA,IAAa,eAAe;AAE5B,IAAM,eAAe;AACrB,IAAM,UAAU;;AAIhB,IAAM,oBAAoB;AAE1B,SAAgB,YAAY,SAA+B;CACzD,OAAO,KAAkB,KAAK,UA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ote-anchor.js","names":[],"sources":["../../../src/file-findings/file-review/quote-anchor.ts"],"sourcesContent":["// Anchors on words inside rendered markdown, in the spirit of the W3C\n// TextQuoteSelector: a quote is found again through the heading outline (the\n// section it sits in) plus a few words on each side, so the same words\n// elsewhere — or edits to other sections — never move it.\nimport type { TextQuote } from \"../../comments/annotation-types\";\nimport { tableRows } from \"./table-cell\";\n\n/** A quote inside the section named by `path` (its heading trail), with the words around it. */\nexport type QuoteLocator = { path: string[]; prefix: string; quote: string; suffix: string };\n\nexport const QUOTE_PREFIX = \"q:\";\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\nconst HEADING = /^h([1-6])$/;\n/** Heading text kept in a path; longer headings are cut so stored anchors stay bounded. */\nexport const OUTLINE_HEADING_LIMIT = 200;\n/** Context words taken on each side to start with; grown until the anchor is unique. */\nconst MIN_CONTEXT_WORDS = 2;\n\nexport function quoteAnchor(locator: QuoteLocator): string {\n return `${QUOTE_PREFIX}${JSON.stringify([locator.path, locator.prefix, locator.quote, locator.suffix])}`;\n}\n\n/** The locator a `q:` anchor encodes; throws for a malformed one. */\nexport function parseQuoteAnchor(anchor: string): QuoteLocator {\n if (!anchor.startsWith(QUOTE_PREFIX)) throw new Error(`not a quote anchor: ${JSON.stringify(anchor)}`);\n const parsed: unknown = JSON.parse(anchor.slice(QUOTE_PREFIX.length));\n const [path, prefix, quote, suffix] = Array.isArray(parsed) ? parsed : [];\n if (\n !Array.isArray(path) ||\n !path.every((heading) => typeof heading === \"string\") ||\n typeof prefix !== \"string\" ||\n typeof quote !== \"string\" ||\n typeof suffix !== \"string\"\n ) {\n throw new Error(`malformed quote anchor ${JSON.stringify(anchor)}`);\n }\n return { path, prefix, quote, suffix };\n}\n\n/** A top-level rendered block, the heading trail it sits under, and its first source line. */\nexport type OutlineEntry = { block: Element; path: string[]; line: number };\n\n/**\n * Every top-level block of rendered markdown (`Markdown sourceBlocks`) in\n * document order, with the headings above it: its table-of-contents path.\n */\nexport function markdownOutline(root: Element): OutlineEntry[] {\n const stack: { level: number; text: string }[] = [];\n return [...root.querySelectorAll(SOURCE_BLOCK)]\n .filter((block) => !block.parentElement?.closest(SOURCE_BLOCK))\n .map((block) => {\n const level = HEADING.exec(block.tagName.toLowerCase())?.[1];\n if (level) {\n while (stack.length > 0 && (stack.at(-1)?.level ?? 0) >= Number(level)) stack.pop();\n const text = blockText(block).replace(/\\s+/g, \" \").trim().slice(0, OUTLINE_HEADING_LIMIT);\n stack.push({ level: Number(level), text });\n }\n return { block, path: stack.map((heading) => heading.text), line: Number((block as HTMLElement).dataset.sourceStart) };\n });\n}\n\ntype Section = Pick<OutlineEntry, \"block\" | \"path\">;\n\nconst sections = (root: Element): Section[] => markdownOutline(root);\n\nfunction textNodes(block: Element): Text[] {\n const walker = document.createTreeWalker(block, NodeFilter.SHOW_TEXT);\n const nodes: Text[] = [];\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n if (!node.parentElement?.closest(\"[data-comment-author]\")) nodes.push(node as Text);\n }\n return nodes;\n}\n\n/** A block's text exactly as its text nodes concatenate, so offsets map back onto them. */\nfunction blockText(block: Element): string {\n return textNodes(block)\n .map((node) => node.data)\n .join(\"\");\n}\n\nfunction rangeIn(block: Element, start: number, end: number): Range {\n const range = document.createRange();\n let offset = 0;\n let started = false;\n for (const node of textNodes(block)) {\n if (!started && start < offset + node.length) {\n range.setStart(node, start - offset);\n started = true;\n }\n if (started && end <= offset + node.length) {\n range.setEnd(node, end - offset);\n return range;\n }\n offset += node.length;\n }\n throw new Error(`quote-anchor: offsets ${start}-${end} lie outside the block`);\n}\n\n// Rendered cells and list items concatenate without whitespace (\"lead5 min\"),\n// so any run of whitespace in the locator matches zero or more in the text.\nfunction pattern(text: string): string {\n return text\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .map((word) => word.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"))\n .join(\"\\\\s*\");\n}\n\ntype Match = { block: Element; start: number; end: number };\n\nfunction matches(candidates: readonly Section[], locator: QuoteLocator, context: { prefix: boolean; suffix: boolean }): Match[] {\n const before = context.prefix && locator.prefix.trim() ? `(?<=${pattern(locator.prefix)}\\\\s*)` : \"\";\n const after = context.suffix && locator.suffix.trim() ? `(?=\\\\s*${pattern(locator.suffix)})` : \"\";\n const regex = new RegExp(`${before}${pattern(locator.quote)}${after}`, \"g\");\n return candidates.flatMap(({ block }) =>\n [...blockText(block).matchAll(regex)].map((m) => ({ block, start: m.index, end: m.index + m[0].length })),\n );\n}\n\nconst samePath = (a: readonly string[], b: readonly string[]) => a.length === b.length && a.every((h, i) => h === b[i]);\n\n// Strictest first. A looser tier is tried only when a stricter one finds\n// nothing, so edited context still resolves, but never guesses between two.\nconst TIERS = [\n { prefix: true, suffix: true },\n { prefix: true, suffix: false },\n { prefix: false, suffix: true },\n] as const;\n\n/**\n * Finds a quote again: in its section by quote plus context, then with one\n * side of the context edited away; failing that (a renamed heading), anywhere\n * by the full context. Null when it is gone or ambiguous.\n */\nexport function resolveQuote(root: Element, locator: QuoteLocator): Range | null {\n const all = sections(root);\n const section = all.filter((s) => samePath(s.path, locator.path));\n for (const tier of TIERS) {\n const found = matches(section, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n }\n const relocated = matches(all, locator, TIERS[0]);\n return relocated.length === 1 ? rangeIn(relocated[0]!.block, relocated[0]!.start, relocated[0]!.end) : null;\n}\n\n/**\n * The locator for a selection inside one block, with just enough context on\n * each side to make it unique in its section. Null when the selection spans\n * blocks, is blank, or repeats so exactly that no context tells it apart.\n */\nexport function locateSelection(root: Element, range: Range): QuoteLocator | null {\n const all = sections(root);\n const own = all.find(({ block }) => block.contains(range.startContainer) && block.contains(range.endContainer));\n if (!own) return null;\n const text = blockText(own.block);\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const raw = rangeText(range);\n const start = rangeText(lead).length + (raw.length - raw.trimStart().length);\n const end = rangeText(lead).length + raw.trimEnd().length;\n if (end <= start) return null;\n\n const before = text.slice(0, start).split(/\\s+/).filter(Boolean);\n const after = text.slice(end).split(/\\s+/).filter(Boolean);\n const section = all.filter((s) => samePath(s.path, own.path));\n for (let words = MIN_CONTEXT_WORDS; ; words++) {\n const locator = {\n path: own.path,\n prefix: before.slice(-words).join(\" \"),\n quote: text.slice(start, end),\n suffix: after.slice(0, words).join(\" \"),\n };\n const found = matches(section, locator, TIERS[0]);\n if (found.length === 1 && found[0]!.block === own.block && found[0]!.start === start) return locator;\n if (words >= before.length && words >= after.length) return null;\n }\n}\n\n/** A selection inside one rendered block as the words with the words around them; null when it spans blocks or is blank. */\nexport function captureTextQuote(root: Element, range: Range): TextQuote | null {\n const locator = locateSelection(root, range);\n return locator && { prefix: locator.prefix, exact: locator.quote, suffix: locator.suffix };\n}\n\n/** Context from the strictest tier to none at all: inside a patch's few lines the words alone may be enough. */\nconst QUOTE_TIERS = [...TIERS, { prefix: false, suffix: false }] as const;\n\n/**\n * The rendered elements covering source lines `start`..`end`: each top-level\n * block that overlaps them, or for a table only its rows on those lines.\n */\nexport function elementsInLines(root: Element, lines: { start: number; end: number }): Element[] {\n return sections(root).flatMap(({ block }) => {\n const { sourceStart, sourceEnd } = (block as HTMLElement).dataset;\n if (Number(sourceStart) > lines.end || Number(sourceEnd) < lines.start) return [];\n const rows = tableRows(block);\n return rows.length > 0 ? rows.filter(({ line }) => line >= lines.start && line <= lines.end).map(({ row }) => row) : [block];\n });\n}\n\n/**\n * Finds a patch's quote again, searching only `within` (the rendered elements\n * where the patch matches now, or the cell it was made in). The words with\n * their context first, then with the context edited away; null once they are\n * gone, or repeat so that nothing tells the occurrences apart, so the caller\n * falls back to highlighting the lines.\n */\nexport function resolveQuoteWithin(within: readonly Element[], quote: TextQuote): Range | null {\n const candidates = within.map((block) => ({ block, path: [] }));\n const locator = { path: [], prefix: quote.prefix, quote: quote.exact, suffix: quote.suffix };\n for (const tier of QUOTE_TIERS) {\n const found = matches(candidates, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n if (found.length > 1) return null;\n }\n return null;\n}\n\n/** `resolveQuoteWithin` the elements covering source lines `start`..`end`. */\nexport function resolveQuoteInLines(root: Element, lines: { start: number; end: number }, quote: TextQuote): Range | null {\n return resolveQuoteWithin(elementsInLines(root, lines), quote);\n}\n\n/**\n * Whether the quote's exact text appears verbatim in the markdown source `lines`:\n * the rule the server enforces on a selector's quote. Rendered text that\n * differs from its source (`**bold**`, links, escapes) therefore does not lie\n * in the lines, and the patch alone anchors the thread.\n */\nexport function quoteLiesInLines(quote: TextQuote, lines: readonly string[]): boolean {\n return quote.exact !== \"\" && lines.join(\"\\n\").includes(quote.exact);\n}\n\n/** A run of characters on one source line (1-based line, 0-based columns). */\nexport type SourceSpan = { line: number; start: number; end: number };\n\n// Markdown markup that renders as nothing (emphasis, code ticks, table pipes,\n// quote and heading markers, list bullets), so it may sit between source words.\nconst MARKUP = /[*_`|>#~]|(?:^|\\s)[-+](?=\\s)/g;\n\nfunction sourcePattern(quote: string): string {\n return pattern(quote.replace(MARKUP, \" \")).replaceAll(\"\\\\s*\", \"[\\\\s*_`|>#~]*\");\n}\n\nfunction sourceBlocks(root: Element, lines: readonly string[]) {\n return sections(root).map(({ block }) => {\n const first = Number((block as HTMLElement).dataset.sourceStart);\n const last = Number((block as HTMLElement).dataset.sourceEnd);\n return { block, first, last, text: lines.slice(first - 1, last).join(\"\\n\") };\n });\n}\n\nconst allMatches = (text: string, source: string) => [...text.matchAll(new RegExp(source, \"g\"))];\n\n/**\n * The quote locator for a selection in the raw markdown: the selection's words\n * are found in the rendered block built from that line, as the same occurrence\n * they are in the source, so a comment made in Source shows in Preview too.\n * Null when the selection is only markup or its block renders no such words.\n */\nexport function locateSourceSelection(root: Element, lines: readonly string[], span: SourceSpan): QuoteLocator | null {\n const selected = lines[span.line - 1]?.slice(span.start, span.end) ?? \"\";\n if (!selected.replace(MARKUP, \" \").trim()) return null;\n const own = sourceBlocks(root, lines).find((b) => span.line >= b.first && span.line <= b.last);\n if (!own) return null;\n const at = lines.slice(own.first - 1, span.line - 1).reduce((sum, l) => sum + l.length + 1, 0) + span.start;\n const k = allMatches(own.text, sourcePattern(selected)).findIndex((m) => m.index + m[0].length > at && m.index < at + selected.length);\n const hit = k < 0 ? undefined : allMatches(blockText(own.block), pattern(selected.replace(MARKUP, \" \")))[k];\n return hit ? locateSelection(root, rangeIn(own.block, hit.index, hit.index + hit[0].length)) : null;\n}\n\n/** Where a quote anchor's text sits in the raw markdown, one span per source line it covers. */\nexport function sourceSpans(root: Element, lines: readonly string[], locator: QuoteLocator): SourceSpan[] {\n const range = resolveQuote(root, locator);\n const own = range && sourceBlocks(root, lines).find(({ block }) => block.contains(range.startContainer));\n if (!range || !own) return [];\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const offset = rangeText(lead).length;\n const k = allMatches(blockText(own.block), pattern(locator.quote)).findIndex((m) => m.index === offset);\n const hit = k < 0 ? undefined : allMatches(own.text, sourcePattern(locator.quote))[k];\n if (!hit) return [];\n const spans: SourceSpan[] = [];\n let lineStart = 0;\n for (let line = own.first; line <= own.last; line++) {\n const text = lines[line - 1] ?? \"\";\n const start = Math.max(hit.index, lineStart) - lineStart;\n const end = Math.min(hit.index + hit[0].length, lineStart + text.length) - lineStart;\n if (end > start) spans.push({ line, start, end });\n lineStart += text.length + 1;\n }\n return spans;\n}\n\nfunction rangeText(range: Range): string {\n const content = range.cloneContents();\n for (const avatar of content.querySelectorAll(\"[data-comment-author]\")) avatar.remove();\n return content.textContent ?? \"\";\n}\n\n/** Reader-facing label: the section and the quoted words. */\nexport function describeQuote(locator: QuoteLocator): string {\n const section = locator.path.at(-1);\n return `${section ? `${section} › ` : \"\"}“${locator.quote}”`;\n}\n"],"mappings":";;AAUA,IAAa,eAAe;AAE5B,IAAM,eAAe;AACrB,IAAM,UAAU;;AAIhB,IAAM,oBAAoB;AAE1B,SA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K,SAAS;CAC7B;CACA,OAAO;AACT;AAEA,SAAS,UAAU,OAAsB;CACvC,MAAM,UAAU,MAAM,cAAc;CACpC,KAAK,MAAM,UAAU,QAAQ,iBAAiB,uBAAuB,GAAG,OAAO,OAAO;CACtF,OAAO,QAAQ,eAAe;AAChC;;AAGA,SAAgB,cAAc,SAA+B;CAC3D,MAAM,UAAU,QAAQ,KAAK,GAAG,EAAE;CAClC,OAAO,GAAG,UAAU,GAAG,QAAQ,OAAO,GAAG,GAAG,QAAQ,MAAM;AAC5D"}
@@ -1,21 +1,30 @@
1
1
  const require_source_marks = require("./source-marks.cjs");
2
+ const require_table_cell = require("./table-cell.cjs");
2
3
  // src/file-findings/file-review/selection-lines.ts
3
4
  var SOURCE_BLOCK = "[data-source-start]";
5
+ /** Whether `range` covers some of `node`'s contents, not merely reaching its edge. */
6
+ function touches(range, node) {
7
+ const own = document.createRange();
8
+ own.selectNodeContents(node);
9
+ return range.compareBoundaryPoints(Range.END_TO_START, own) < 0 && range.compareBoundaryPoints(Range.START_TO_END, own) > 0;
10
+ }
4
11
  /**
5
12
  * The source lines of the rendered blocks (`Markdown sourceBlocks`) a
6
13
  * selection in Preview touches, from the first block's start to the last
7
- * block's end. A selection that merely reaches the edge of a block does not
8
- * cover it. Null when it touches no block.
14
+ * block's end; in a table, only the lines of the rows it touches. A selection
15
+ * that merely reaches the edge of a block does not cover it. Null when it
16
+ * touches no block.
9
17
  */
10
18
  function previewSelectionLines(range, markdown) {
11
19
  const covered = [];
12
20
  for (const block of markdown.querySelectorAll(SOURCE_BLOCK)) {
13
- if (block.parentElement?.closest(SOURCE_BLOCK)) continue;
14
- const blockRange = document.createRange();
15
- blockRange.selectNodeContents(block);
16
- const startsBeforeBlockEnds = range.compareBoundaryPoints(Range.END_TO_START, blockRange) < 0;
17
- const endsAfterBlockStarts = range.compareBoundaryPoints(Range.START_TO_END, blockRange) > 0;
18
- if (startsBeforeBlockEnds && endsAfterBlockStarts) covered.push({
21
+ if (block.parentElement?.closest(SOURCE_BLOCK) || !touches(range, block)) continue;
22
+ const rows = require_table_cell.tableRows(block).filter(({ row }) => touches(range, row));
23
+ if (rows.length > 0) covered.push(...rows.map(({ line }) => ({
24
+ startLine: line,
25
+ endLine: line
26
+ })));
27
+ else covered.push({
19
28
  startLine: Number(block.dataset.sourceStart),
20
29
  endLine: Number(block.dataset.sourceEnd)
21
30
  });
@@ -1 +1 @@
1
- {"version":3,"file":"selection-lines.cjs","names":["sourceRangeOf"],"sources":["../../../src/file-findings/file-review/selection-lines.ts"],"sourcesContent":["import { sourceRangeOf } from \"./source-marks\";\n\n/** An inclusive, 1-based range of source lines. */\nexport type LineRange = { startLine: number; endLine: number };\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\n\n/**\n * The source lines of the rendered blocks (`Markdown sourceBlocks`) a\n * selection in Preview touches, from the first block's start to the last\n * block's end. A selection that merely reaches the edge of a block does not\n * cover it. Null when it touches no block.\n */\nexport function previewSelectionLines(range: Range, markdown: Element): LineRange | null {\n const covered: LineRange[] = [];\n for (const block of markdown.querySelectorAll<HTMLElement>(SOURCE_BLOCK)) {\n if (block.parentElement?.closest(SOURCE_BLOCK)) continue;\n const blockRange = document.createRange();\n blockRange.selectNodeContents(block);\n const startsBeforeBlockEnds = range.compareBoundaryPoints(Range.END_TO_START, blockRange) < 0;\n const endsAfterBlockStarts = range.compareBoundaryPoints(Range.START_TO_END, blockRange) > 0;\n if (startsBeforeBlockEnds && endsAfterBlockStarts) {\n covered.push({ startLine: Number(block.dataset.sourceStart), endLine: Number(block.dataset.sourceEnd) });\n }\n }\n if (covered.length === 0) return null;\n return {\n startLine: Math.min(...covered.map((block) => block.startLine)),\n endLine: Math.max(...covered.map((block) => block.endLine)),\n };\n}\n\n/**\n * The source lines a selection in the Source listing covers. A selection that\n * ends at the very start of a later line does not include that line. Null when\n * either end is outside the lines' text.\n */\nexport function sourceSelectionLines(range: Range): LineRange | null {\n const covered = sourceRangeOf(range);\n if (!covered) return null;\n const { start, end } = covered;\n const endLine = end.column === 0 && end.line > start.line ? end.line - 1 : end.line;\n return { startLine: start.line, endLine };\n}\n"],"mappings":";;AAKA,IAAM,eAAe;;;;;;;AAQrB,SAAgB,sBAAsB,OAAc,UAAqC;CACvF,MAAM,UAAuB,CAAC;CAC9B,KAAK,MAAM,SAAS,SAAS,iBAA8B,YAAY,GAAG;EACxE,IAAI,MAAM,eAAe,QAAQ,YAAY,GAAG;EAChD,MAAM,aAAa,SAAS,YAAY;EACxC,WAAW,mBAAmB,KAAK;EACnC,MAAM,wBAAwB,MAAM,sBAAsB,MAAM,cAAc,UAAU,IAAI;EAC5F,MAAM,uBAAuB,MAAM,sBAAsB,MAAM,cAAc,UAAU,IAAI;EAC3F,IAAI,yBAAyB,sBAC3B,QAAQ,KAAK;GAAE,WAAW,OAAO,MAAM,QAAQ,WAAW;GAAG,SAAS,OAAO,MAAM,QAAQ,SAAS;EAAE,CAAC;CAE3G;CACA,IAAI,QAAQ,WAAW,GAAG,OAAO;CACjC,OAAO;EACL,WAAW,KAAK,IAAI,GAAG,QAAQ,KAAK,UAAU,MAAM,SAAS,CAAC;EAC9D,SAAS,KAAK,IAAI,GAAG,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC;CAC5D;AACF;;;;;;AAOA,SAAgB,qBAAqB,OAAgC;CACnE,MAAM,UAAUA,qBAAAA,cAAc,KAAK;CACnC,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,UAAU,IAAI,WAAW,KAAK,IAAI,OAAO,MAAM,OAAO,IAAI,OAAO,IAAI,IAAI;CAC/E,OAAO;EAAE,WAAW,MAAM;EAAM;CAAQ;AAC1C"}
1
+ {"version":3,"file":"selection-lines.cjs","names":["tableRows","sourceRangeOf"],"sources":["../../../src/file-findings/file-review/selection-lines.ts"],"sourcesContent":["import { sourceRangeOf } from \"./source-marks\";\nimport { tableRows } from \"./table-cell\";\n\n/** An inclusive, 1-based range of source lines. */\nexport type LineRange = { startLine: number; endLine: number };\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\n\n/** Whether `range` covers some of `node`'s contents, not merely reaching its edge. */\nfunction touches(range: Range, node: Node): boolean {\n const own = document.createRange();\n own.selectNodeContents(node);\n return range.compareBoundaryPoints(Range.END_TO_START, own) < 0 && range.compareBoundaryPoints(Range.START_TO_END, own) > 0;\n}\n\n/**\n * The source lines of the rendered blocks (`Markdown sourceBlocks`) a\n * selection in Preview touches, from the first block's start to the last\n * block's end; in a table, only the lines of the rows it touches. A selection\n * that merely reaches the edge of a block does not cover it. Null when it\n * touches no block.\n */\nexport function previewSelectionLines(range: Range, markdown: Element): LineRange | null {\n const covered: LineRange[] = [];\n for (const block of markdown.querySelectorAll<HTMLElement>(SOURCE_BLOCK)) {\n if (block.parentElement?.closest(SOURCE_BLOCK) || !touches(range, block)) continue;\n const rows = tableRows(block).filter(({ row }) => touches(range, row));\n if (rows.length > 0) covered.push(...rows.map(({ line }) => ({ startLine: line, endLine: line })));\n else covered.push({ startLine: Number(block.dataset.sourceStart), endLine: Number(block.dataset.sourceEnd) });\n }\n if (covered.length === 0) return null;\n return {\n startLine: Math.min(...covered.map((block) => block.startLine)),\n endLine: Math.max(...covered.map((block) => block.endLine)),\n };\n}\n\n/**\n * The source lines a selection in the Source listing covers. A selection that\n * ends at the very start of a later line does not include that line. Null when\n * either end is outside the lines' text.\n */\nexport function sourceSelectionLines(range: Range): LineRange | null {\n const covered = sourceRangeOf(range);\n if (!covered) return null;\n const { start, end } = covered;\n const endLine = end.column === 0 && end.line > start.line ? end.line - 1 : end.line;\n return { startLine: start.line, endLine };\n}\n"],"mappings":";;;AAMA,IAAM,eAAe;;AAGrB,SAAS,QAAQ,OAAc,MAAqB;CAClD,MAAM,MAAM,SAAS,YAAY;CACjC,IAAI,mBAAmB,IAAI;CAC3B,OAAO,MAAM,sBAAsB,MAAM,cAAc,GAAG,IAAI,KAAK,MAAM,sBAAsB,MAAM,cAAc,GAAG,IAAI;AAC5H;;;;;;;;AASA,SAAgB,sBAAsB,OAAc,UAAqC;CACvF,MAAM,UAAuB,CAAC;CAC9B,KAAK,MAAM,SAAS,SAAS,iBAA8B,YAAY,GAAG;EACxE,IAAI,MAAM,eAAe,QAAQ,YAAY,KAAK,CAAC,QAAQ,OAAO,KAAK,GAAG;EAC1E,MAAM,OAAOA,mBAAAA,UAAU,KAAK,CAAC,CAAC,QAAQ,EAAE,UAAU,QAAQ,OAAO,GAAG,CAAC;EACrE,IAAI,KAAK,SAAS,GAAG,QAAQ,KAAK,GAAG,KAAK,KAAK,EAAE,YAAY;GAAE,WAAW;GAAM,SAAS;EAAK,EAAE,CAAC;OAC5F,QAAQ,KAAK;GAAE,WAAW,OAAO,MAAM,QAAQ,WAAW;GAAG,SAAS,OAAO,MAAM,QAAQ,SAAS;EAAE,CAAC;CAC9G;CACA,IAAI,QAAQ,WAAW,GAAG,OAAO;CACjC,OAAO;EACL,WAAW,KAAK,IAAI,GAAG,QAAQ,KAAK,UAAU,MAAM,SAAS,CAAC;EAC9D,SAAS,KAAK,IAAI,GAAG,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC;CAC5D;AACF;;;;;;AAOA,SAAgB,qBAAqB,OAAgC;CACnE,MAAM,UAAUC,qBAAAA,cAAc,KAAK;CACnC,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,UAAU,IAAI,WAAW,KAAK,IAAI,OAAO,MAAM,OAAO,IAAI,OAAO,IAAI,IAAI;CAC/E,OAAO;EAAE,WAAW,MAAM;EAAM;CAAQ;AAC1C"}
@@ -6,8 +6,9 @@ export type LineRange = {
6
6
  /**
7
7
  * The source lines of the rendered blocks (`Markdown sourceBlocks`) a
8
8
  * selection in Preview touches, from the first block's start to the last
9
- * block's end. A selection that merely reaches the edge of a block does not
10
- * cover it. Null when it touches no block.
9
+ * block's end; in a table, only the lines of the rows it touches. A selection
10
+ * that merely reaches the edge of a block does not cover it. Null when it
11
+ * touches no block.
11
12
  */
12
13
  export declare function previewSelectionLines(range: Range, markdown: Element): LineRange | null;
13
14
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"selection-lines.d.ts","sourceRoot":"","sources":["../../../src/file-findings/file-review/selection-lines.ts"],"names":[],"mappings":"AAEA,mDAAmD;AACnD,MAAM,MAAM,SAAS,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAI/D;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAiBvF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CAMnE"}
1
+ {"version":3,"file":"selection-lines.d.ts","sourceRoot":"","sources":["../../../src/file-findings/file-review/selection-lines.ts"],"names":[],"mappings":"AAGA,mDAAmD;AACnD,MAAM,MAAM,SAAS,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAW/D;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAavF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CAMnE"}
@@ -1,21 +1,30 @@
1
1
  import { sourceRangeOf } from "./source-marks.js";
2
+ import { tableRows } from "./table-cell.js";
2
3
  // src/file-findings/file-review/selection-lines.ts
3
4
  var SOURCE_BLOCK = "[data-source-start]";
5
+ /** Whether `range` covers some of `node`'s contents, not merely reaching its edge. */
6
+ function touches(range, node) {
7
+ const own = document.createRange();
8
+ own.selectNodeContents(node);
9
+ return range.compareBoundaryPoints(Range.END_TO_START, own) < 0 && range.compareBoundaryPoints(Range.START_TO_END, own) > 0;
10
+ }
4
11
  /**
5
12
  * The source lines of the rendered blocks (`Markdown sourceBlocks`) a
6
13
  * selection in Preview touches, from the first block's start to the last
7
- * block's end. A selection that merely reaches the edge of a block does not
8
- * cover it. Null when it touches no block.
14
+ * block's end; in a table, only the lines of the rows it touches. A selection
15
+ * that merely reaches the edge of a block does not cover it. Null when it
16
+ * touches no block.
9
17
  */
10
18
  function previewSelectionLines(range, markdown) {
11
19
  const covered = [];
12
20
  for (const block of markdown.querySelectorAll(SOURCE_BLOCK)) {
13
- if (block.parentElement?.closest(SOURCE_BLOCK)) continue;
14
- const blockRange = document.createRange();
15
- blockRange.selectNodeContents(block);
16
- const startsBeforeBlockEnds = range.compareBoundaryPoints(Range.END_TO_START, blockRange) < 0;
17
- const endsAfterBlockStarts = range.compareBoundaryPoints(Range.START_TO_END, blockRange) > 0;
18
- if (startsBeforeBlockEnds && endsAfterBlockStarts) covered.push({
21
+ if (block.parentElement?.closest(SOURCE_BLOCK) || !touches(range, block)) continue;
22
+ const rows = tableRows(block).filter(({ row }) => touches(range, row));
23
+ if (rows.length > 0) covered.push(...rows.map(({ line }) => ({
24
+ startLine: line,
25
+ endLine: line
26
+ })));
27
+ else covered.push({
19
28
  startLine: Number(block.dataset.sourceStart),
20
29
  endLine: Number(block.dataset.sourceEnd)
21
30
  });
@@ -1 +1 @@
1
- {"version":3,"file":"selection-lines.js","names":[],"sources":["../../../src/file-findings/file-review/selection-lines.ts"],"sourcesContent":["import { sourceRangeOf } from \"./source-marks\";\n\n/** An inclusive, 1-based range of source lines. */\nexport type LineRange = { startLine: number; endLine: number };\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\n\n/**\n * The source lines of the rendered blocks (`Markdown sourceBlocks`) a\n * selection in Preview touches, from the first block's start to the last\n * block's end. A selection that merely reaches the edge of a block does not\n * cover it. Null when it touches no block.\n */\nexport function previewSelectionLines(range: Range, markdown: Element): LineRange | null {\n const covered: LineRange[] = [];\n for (const block of markdown.querySelectorAll<HTMLElement>(SOURCE_BLOCK)) {\n if (block.parentElement?.closest(SOURCE_BLOCK)) continue;\n const blockRange = document.createRange();\n blockRange.selectNodeContents(block);\n const startsBeforeBlockEnds = range.compareBoundaryPoints(Range.END_TO_START, blockRange) < 0;\n const endsAfterBlockStarts = range.compareBoundaryPoints(Range.START_TO_END, blockRange) > 0;\n if (startsBeforeBlockEnds && endsAfterBlockStarts) {\n covered.push({ startLine: Number(block.dataset.sourceStart), endLine: Number(block.dataset.sourceEnd) });\n }\n }\n if (covered.length === 0) return null;\n return {\n startLine: Math.min(...covered.map((block) => block.startLine)),\n endLine: Math.max(...covered.map((block) => block.endLine)),\n };\n}\n\n/**\n * The source lines a selection in the Source listing covers. A selection that\n * ends at the very start of a later line does not include that line. Null when\n * either end is outside the lines' text.\n */\nexport function sourceSelectionLines(range: Range): LineRange | null {\n const covered = sourceRangeOf(range);\n if (!covered) return null;\n const { start, end } = covered;\n const endLine = end.column === 0 && end.line > start.line ? end.line - 1 : end.line;\n return { startLine: start.line, endLine };\n}\n"],"mappings":";;AAKA,IAAM,eAAe;;;;;;;AAQrB,SAAgB,sBAAsB,OAAc,UAAqC;CACvF,MAAM,UAAuB,CAAC;CAC9B,KAAK,MAAM,SAAS,SAAS,iBAA8B,YAAY,GAAG;EACxE,IAAI,MAAM,eAAe,QAAQ,YAAY,GAAG;EAChD,MAAM,aAAa,SAAS,YAAY;EACxC,WAAW,mBAAmB,KAAK;EACnC,MAAM,wBAAwB,MAAM,sBAAsB,MAAM,cAAc,UAAU,IAAI;EAC5F,MAAM,uBAAuB,MAAM,sBAAsB,MAAM,cAAc,UAAU,IAAI;EAC3F,IAAI,yBAAyB,sBAC3B,QAAQ,KAAK;GAAE,WAAW,OAAO,MAAM,QAAQ,WAAW;GAAG,SAAS,OAAO,MAAM,QAAQ,SAAS;EAAE,CAAC;CAE3G;CACA,IAAI,QAAQ,WAAW,GAAG,OAAO;CACjC,OAAO;EACL,WAAW,KAAK,IAAI,GAAG,QAAQ,KAAK,UAAU,MAAM,SAAS,CAAC;EAC9D,SAAS,KAAK,IAAI,GAAG,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC;CAC5D;AACF;;;;;;AAOA,SAAgB,qBAAqB,OAAgC;CACnE,MAAM,UAAU,cAAc,KAAK;CACnC,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,UAAU,IAAI,WAAW,KAAK,IAAI,OAAO,MAAM,OAAO,IAAI,OAAO,IAAI,IAAI;CAC/E,OAAO;EAAE,WAAW,MAAM;EAAM;CAAQ;AAC1C"}
1
+ {"version":3,"file":"selection-lines.js","names":[],"sources":["../../../src/file-findings/file-review/selection-lines.ts"],"sourcesContent":["import { sourceRangeOf } from \"./source-marks\";\nimport { tableRows } from \"./table-cell\";\n\n/** An inclusive, 1-based range of source lines. */\nexport type LineRange = { startLine: number; endLine: number };\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\n\n/** Whether `range` covers some of `node`'s contents, not merely reaching its edge. */\nfunction touches(range: Range, node: Node): boolean {\n const own = document.createRange();\n own.selectNodeContents(node);\n return range.compareBoundaryPoints(Range.END_TO_START, own) < 0 && range.compareBoundaryPoints(Range.START_TO_END, own) > 0;\n}\n\n/**\n * The source lines of the rendered blocks (`Markdown sourceBlocks`) a\n * selection in Preview touches, from the first block's start to the last\n * block's end; in a table, only the lines of the rows it touches. A selection\n * that merely reaches the edge of a block does not cover it. Null when it\n * touches no block.\n */\nexport function previewSelectionLines(range: Range, markdown: Element): LineRange | null {\n const covered: LineRange[] = [];\n for (const block of markdown.querySelectorAll<HTMLElement>(SOURCE_BLOCK)) {\n if (block.parentElement?.closest(SOURCE_BLOCK) || !touches(range, block)) continue;\n const rows = tableRows(block).filter(({ row }) => touches(range, row));\n if (rows.length > 0) covered.push(...rows.map(({ line }) => ({ startLine: line, endLine: line })));\n else covered.push({ startLine: Number(block.dataset.sourceStart), endLine: Number(block.dataset.sourceEnd) });\n }\n if (covered.length === 0) return null;\n return {\n startLine: Math.min(...covered.map((block) => block.startLine)),\n endLine: Math.max(...covered.map((block) => block.endLine)),\n };\n}\n\n/**\n * The source lines a selection in the Source listing covers. A selection that\n * ends at the very start of a later line does not include that line. Null when\n * either end is outside the lines' text.\n */\nexport function sourceSelectionLines(range: Range): LineRange | null {\n const covered = sourceRangeOf(range);\n if (!covered) return null;\n const { start, end } = covered;\n const endLine = end.column === 0 && end.line > start.line ? end.line - 1 : end.line;\n return { startLine: start.line, endLine };\n}\n"],"mappings":";;;AAMA,IAAM,eAAe;;AAGrB,SAAS,QAAQ,OAAc,MAAqB;CAClD,MAAM,MAAM,SAAS,YAAY;CACjC,IAAI,mBAAmB,IAAI;CAC3B,OAAO,MAAM,sBAAsB,MAAM,cAAc,GAAG,IAAI,KAAK,MAAM,sBAAsB,MAAM,cAAc,GAAG,IAAI;AAC5H;;;;;;;;AASA,SAAgB,sBAAsB,OAAc,UAAqC;CACvF,MAAM,UAAuB,CAAC;CAC9B,KAAK,MAAM,SAAS,SAAS,iBAA8B,YAAY,GAAG;EACxE,IAAI,MAAM,eAAe,QAAQ,YAAY,KAAK,CAAC,QAAQ,OAAO,KAAK,GAAG;EAC1E,MAAM,OAAO,UAAU,KAAK,CAAC,CAAC,QAAQ,EAAE,UAAU,QAAQ,OAAO,GAAG,CAAC;EACrE,IAAI,KAAK,SAAS,GAAG,QAAQ,KAAK,GAAG,KAAK,KAAK,EAAE,YAAY;GAAE,WAAW;GAAM,SAAS;EAAK,EAAE,CAAC;OAC5F,QAAQ,KAAK;GAAE,WAAW,OAAO,MAAM,QAAQ,WAAW;GAAG,SAAS,OAAO,MAAM,QAAQ,SAAS;EAAE,CAAC;CAC9G;CACA,IAAI,QAAQ,WAAW,GAAG,OAAO;CACjC,OAAO;EACL,WAAW,KAAK,IAAI,GAAG,QAAQ,KAAK,UAAU,MAAM,SAAS,CAAC;EAC9D,SAAS,KAAK,IAAI,GAAG,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC;CAC5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