@agent-native/core 0.109.2 → 0.109.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (334) hide show
  1. package/corpus/README.md +2 -2
  2. package/corpus/core/CHANGELOG.md +16 -0
  3. package/corpus/core/docs/content/agent-native-toolkit.mdx +46 -13
  4. package/corpus/core/docs/content/locales/ar-SA/agent-native-toolkit.mdx +79 -55
  5. package/corpus/core/docs/content/locales/ar-SA/toolkit-capability-packages.mdx +21 -0
  6. package/corpus/core/docs/content/locales/ar-SA/toolkit-context-knowledge.mdx +12 -0
  7. package/corpus/core/docs/content/locales/ar-SA/toolkit-editors-canvases.mdx +17 -0
  8. package/corpus/core/docs/content/locales/de-DE/agent-native-toolkit.mdx +82 -54
  9. package/corpus/core/docs/content/locales/de-DE/toolkit-capability-packages.mdx +21 -0
  10. package/corpus/core/docs/content/locales/de-DE/toolkit-context-knowledge.mdx +12 -0
  11. package/corpus/core/docs/content/locales/de-DE/toolkit-editors-canvases.mdx +17 -0
  12. package/corpus/core/docs/content/locales/es-ES/agent-native-toolkit.mdx +81 -52
  13. package/corpus/core/docs/content/locales/es-ES/toolkit-capability-packages.mdx +21 -0
  14. package/corpus/core/docs/content/locales/es-ES/toolkit-context-knowledge.mdx +12 -0
  15. package/corpus/core/docs/content/locales/es-ES/toolkit-editors-canvases.mdx +21 -0
  16. package/corpus/core/docs/content/locales/fr-FR/agent-native-toolkit.mdx +84 -54
  17. package/corpus/core/docs/content/locales/fr-FR/toolkit-capability-packages.mdx +21 -0
  18. package/corpus/core/docs/content/locales/fr-FR/toolkit-context-knowledge.mdx +12 -0
  19. package/corpus/core/docs/content/locales/fr-FR/toolkit-editors-canvases.mdx +21 -0
  20. package/corpus/core/docs/content/locales/hi-IN/agent-native-toolkit.mdx +69 -62
  21. package/corpus/core/docs/content/locales/hi-IN/toolkit-capability-packages.mdx +21 -0
  22. package/corpus/core/docs/content/locales/hi-IN/toolkit-context-knowledge.mdx +12 -0
  23. package/corpus/core/docs/content/locales/hi-IN/toolkit-editors-canvases.mdx +17 -0
  24. package/corpus/core/docs/content/locales/ja-JP/agent-native-toolkit.mdx +69 -62
  25. package/corpus/core/docs/content/locales/ja-JP/toolkit-capability-packages.mdx +21 -0
  26. package/corpus/core/docs/content/locales/ja-JP/toolkit-context-knowledge.mdx +12 -0
  27. package/corpus/core/docs/content/locales/ja-JP/toolkit-editors-canvases.mdx +17 -0
  28. package/corpus/core/docs/content/locales/ko-KR/agent-native-toolkit.mdx +69 -62
  29. package/corpus/core/docs/content/locales/ko-KR/toolkit-capability-packages.mdx +21 -0
  30. package/corpus/core/docs/content/locales/ko-KR/toolkit-context-knowledge.mdx +12 -0
  31. package/corpus/core/docs/content/locales/ko-KR/toolkit-editors-canvases.mdx +17 -0
  32. package/corpus/core/docs/content/locales/pt-BR/agent-native-toolkit.mdx +82 -54
  33. package/corpus/core/docs/content/locales/pt-BR/toolkit-capability-packages.mdx +21 -0
  34. package/corpus/core/docs/content/locales/pt-BR/toolkit-context-knowledge.mdx +12 -0
  35. package/corpus/core/docs/content/locales/pt-BR/toolkit-editors-canvases.mdx +17 -0
  36. package/corpus/core/docs/content/locales/zh-CN/agent-native-toolkit.mdx +69 -62
  37. package/corpus/core/docs/content/locales/zh-CN/toolkit-capability-packages.mdx +21 -0
  38. package/corpus/core/docs/content/locales/zh-CN/toolkit-context-knowledge.mdx +12 -0
  39. package/corpus/core/docs/content/locales/zh-CN/toolkit-editors-canvases.mdx +17 -0
  40. package/corpus/core/docs/content/locales/zh-TW/agent-native-toolkit.mdx +69 -62
  41. package/corpus/core/docs/content/locales/zh-TW/toolkit-capability-packages.mdx +21 -0
  42. package/corpus/core/docs/content/locales/zh-TW/toolkit-context-knowledge.mdx +12 -0
  43. package/corpus/core/docs/content/locales/zh-TW/toolkit-editors-canvases.mdx +17 -0
  44. package/corpus/core/docs/content/toolkit-capability-packages.mdx +52 -0
  45. package/corpus/core/docs/content/toolkit-context-knowledge.mdx +46 -0
  46. package/corpus/core/docs/content/toolkit-editors-canvases.mdx +55 -0
  47. package/corpus/core/package.json +35 -34
  48. package/corpus/core/src/cli/create.ts +57 -15
  49. package/corpus/core/src/cli/package-lifecycle.ts +2 -0
  50. package/corpus/core/src/cli/skills-content/visual-plan-skill.ts +2 -0
  51. package/corpus/core/src/client/context-xray/ContextMeter.tsx +31 -111
  52. package/corpus/core/src/client/context-xray/ContextSegmentRow.tsx +8 -111
  53. package/corpus/core/src/client/context-xray/ContextTreemap.tsx +6 -111
  54. package/corpus/core/src/client/context-xray/ContextXRayPanel.tsx +31 -391
  55. package/corpus/core/src/client/context-xray/SegmentProvenancePopover.tsx +4 -52
  56. package/corpus/core/src/client/context-xray/format.ts +0 -33
  57. package/corpus/core/src/client/require-session.tsx +19 -3
  58. package/corpus/core/src/client/rich-markdown-editor/index.ts +42 -57
  59. package/corpus/core/src/client/rich-markdown-editor/uploadEditorImage.ts +2 -1
  60. package/corpus/core/src/client/use-action.ts +145 -2
  61. package/corpus/core/src/client/use-session.ts +79 -48
  62. package/corpus/core/src/client/visual-style-controls.tsx +1 -1088
  63. package/corpus/core/src/collab/agent-identity.ts +5 -22
  64. package/corpus/core/src/collab/client.ts +1 -53
  65. package/corpus/core/src/db/client.ts +13 -7
  66. package/corpus/core/src/db/create-get-db.ts +20 -13
  67. package/corpus/core/src/db/request-telemetry.ts +154 -0
  68. package/corpus/core/src/integrations/index.ts +1 -0
  69. package/corpus/core/src/integrations/plugin.ts +9 -3
  70. package/corpus/core/src/integrations/remote-push-delivery-job.ts +48 -0
  71. package/corpus/core/src/integrations/remote-push-delivery.ts +370 -0
  72. package/corpus/core/src/integrations/remote-push-store.ts +275 -26
  73. package/corpus/core/src/server/better-auth-instance.ts +11 -3
  74. package/corpus/core/src/server/core-routes-plugin.ts +36 -14
  75. package/corpus/core/src/server/framework-request-handler.ts +11 -1
  76. package/corpus/core/src/server/http-response-telemetry.ts +233 -31
  77. package/corpus/core/src/styles/rich-markdown-editor.css +1 -510
  78. package/corpus/core/src/templates/workspace-core/.agents/skills/tracking/SKILL.md +19 -0
  79. package/corpus/core/src/testing.ts +1 -1
  80. package/corpus/core/src/vite/client.ts +3 -0
  81. package/corpus/templates/clips/actions/finalize-recording.ts +3 -1
  82. package/corpus/templates/clips/actions/set-mobile-capture-state.ts +4 -1
  83. package/corpus/templates/clips/app/components/library/library-layout.tsx +1 -6
  84. package/corpus/templates/clips/changelog/2026-07-18-new-recording-is-now-emphasized-as-the-primary-action-in-the.md +6 -0
  85. package/corpus/templates/clips/changelog/2026-07-18-recordings-now-remain-safely-recoverable-until-the-stored-me.md +6 -0
  86. package/corpus/templates/content/app/components/editor/VisualEditor.tsx +5 -3
  87. package/corpus/templates/content/app/components/editor/extensions/DragHandle.tsx +4 -4
  88. package/corpus/templates/content/package.json +25 -25
  89. package/corpus/templates/design/app/components/design/TweaksPanel.tsx +2 -1
  90. package/corpus/templates/design/package.json +1 -1
  91. package/corpus/templates/mail/package.json +9 -9
  92. package/corpus/templates/plan/.agents/skills/visual-plan/SKILL.md +2 -0
  93. package/corpus/templates/plan/app/components/editor/PlanDocumentEditor.tsx +8 -8
  94. package/corpus/templates/plan/app/components/editor/planSlashCommands.ts +6 -6
  95. package/corpus/templates/plan/app/components/plan/PlanImageNode.tsx +4 -7
  96. package/corpus/templates/plan/app/components/plan/PlanMarkdownEditor.tsx +6 -4
  97. package/corpus/templates/plan/app/components/plan/PlanVisualSurface.tsx +1 -1
  98. package/corpus/templates/plan/changelog/2026-07-18-visual-plans-now-open-on-wireframes-by-default-when-a-protot.md +6 -0
  99. package/corpus/templates/plan/package.json +3 -3
  100. package/corpus/templates/slides/app/components/editor/SlideStyleInspector.tsx +2 -2
  101. package/corpus/templates/slides/app/components/editor/TweaksPanel.tsx +2 -2
  102. package/corpus/templates/slides/package.json +13 -13
  103. package/corpus/templates/tasks/AGENTS.md +3 -0
  104. package/corpus/templates/tasks/actions/render-task-list-inline.ts +202 -0
  105. package/corpus/templates/tasks/changelog/2026-07-18-task-lists-can-now-appear-as-interactive-widgets-inline-in-c.md +6 -0
  106. package/corpus/templates/tasks/docs/features/f8-chat.mdx +2 -0
  107. package/corpus/templates/tasks/server/plugins/agent-chat.ts +2 -0
  108. package/dist/catalog.json +39 -1
  109. package/dist/cli/create.d.ts +10 -1
  110. package/dist/cli/create.d.ts.map +1 -1
  111. package/dist/cli/create.js +49 -16
  112. package/dist/cli/create.js.map +1 -1
  113. package/dist/cli/package-lifecycle.d.ts.map +1 -1
  114. package/dist/cli/package-lifecycle.js +2 -0
  115. package/dist/cli/package-lifecycle.js.map +1 -1
  116. package/dist/cli/skills-content/visual-plan-skill.d.ts +1 -1
  117. package/dist/cli/skills-content/visual-plan-skill.d.ts.map +1 -1
  118. package/dist/cli/skills-content/visual-plan-skill.js +2 -0
  119. package/dist/cli/skills-content/visual-plan-skill.js.map +1 -1
  120. package/dist/client/context-xray/ContextMeter.d.ts.map +1 -1
  121. package/dist/client/context-xray/ContextMeter.js +8 -23
  122. package/dist/client/context-xray/ContextMeter.js.map +1 -1
  123. package/dist/client/context-xray/ContextSegmentRow.d.ts.map +1 -1
  124. package/dist/client/context-xray/ContextSegmentRow.js +3 -19
  125. package/dist/client/context-xray/ContextSegmentRow.js.map +1 -1
  126. package/dist/client/context-xray/ContextTreemap.d.ts.map +1 -1
  127. package/dist/client/context-xray/ContextTreemap.js +3 -54
  128. package/dist/client/context-xray/ContextTreemap.js.map +1 -1
  129. package/dist/client/context-xray/ContextXRayPanel.d.ts.map +1 -1
  130. package/dist/client/context-xray/ContextXRayPanel.js +21 -163
  131. package/dist/client/context-xray/ContextXRayPanel.js.map +1 -1
  132. package/dist/client/context-xray/SegmentProvenancePopover.d.ts.map +1 -1
  133. package/dist/client/context-xray/SegmentProvenancePopover.js +3 -4
  134. package/dist/client/context-xray/SegmentProvenancePopover.js.map +1 -1
  135. package/dist/client/context-xray/format.d.ts +0 -4
  136. package/dist/client/context-xray/format.d.ts.map +1 -1
  137. package/dist/client/context-xray/format.js +0 -49
  138. package/dist/client/context-xray/format.js.map +1 -1
  139. package/dist/client/require-session.d.ts.map +1 -1
  140. package/dist/client/require-session.js +6 -3
  141. package/dist/client/require-session.js.map +1 -1
  142. package/dist/client/rich-markdown-editor/index.d.ts +1 -12
  143. package/dist/client/rich-markdown-editor/index.d.ts.map +1 -1
  144. package/dist/client/rich-markdown-editor/index.js +1 -12
  145. package/dist/client/rich-markdown-editor/index.js.map +1 -1
  146. package/dist/client/rich-markdown-editor/uploadEditorImage.d.ts +1 -1
  147. package/dist/client/rich-markdown-editor/uploadEditorImage.d.ts.map +1 -1
  148. package/dist/client/rich-markdown-editor/uploadEditorImage.js.map +1 -1
  149. package/dist/client/use-action.d.ts.map +1 -1
  150. package/dist/client/use-action.js +117 -1
  151. package/dist/client/use-action.js.map +1 -1
  152. package/dist/client/use-session.d.ts.map +1 -1
  153. package/dist/client/use-session.js +72 -50
  154. package/dist/client/use-session.js.map +1 -1
  155. package/dist/client/visual-style-controls.d.ts +1 -89
  156. package/dist/client/visual-style-controls.d.ts.map +1 -1
  157. package/dist/client/visual-style-controls.js +1 -498
  158. package/dist/client/visual-style-controls.js.map +1 -1
  159. package/dist/collab/agent-identity.d.ts +1 -14
  160. package/dist/collab/agent-identity.d.ts.map +1 -1
  161. package/dist/collab/agent-identity.js +1 -13
  162. package/dist/collab/agent-identity.js.map +1 -1
  163. package/dist/collab/awareness.d.ts +2 -2
  164. package/dist/collab/awareness.d.ts.map +1 -1
  165. package/dist/collab/client.d.ts +1 -19
  166. package/dist/collab/client.d.ts.map +1 -1
  167. package/dist/collab/client.js +1 -53
  168. package/dist/collab/client.js.map +1 -1
  169. package/dist/collab/struct-routes.d.ts +1 -1
  170. package/dist/db/client.d.ts.map +1 -1
  171. package/dist/db/client.js +7 -1
  172. package/dist/db/client.js.map +1 -1
  173. package/dist/db/create-get-db.d.ts +3 -6
  174. package/dist/db/create-get-db.d.ts.map +1 -1
  175. package/dist/db/create-get-db.js +9 -2
  176. package/dist/db/create-get-db.js.map +1 -1
  177. package/dist/db/request-telemetry.d.ts +23 -0
  178. package/dist/db/request-telemetry.d.ts.map +1 -0
  179. package/dist/db/request-telemetry.js +95 -0
  180. package/dist/db/request-telemetry.js.map +1 -0
  181. package/dist/integrations/index.d.ts +1 -0
  182. package/dist/integrations/index.d.ts.map +1 -1
  183. package/dist/integrations/index.js +1 -0
  184. package/dist/integrations/index.js.map +1 -1
  185. package/dist/integrations/plugin.d.ts.map +1 -1
  186. package/dist/integrations/plugin.js +8 -3
  187. package/dist/integrations/plugin.js.map +1 -1
  188. package/dist/integrations/remote-push-delivery-job.d.ts +4 -0
  189. package/dist/integrations/remote-push-delivery-job.d.ts.map +1 -0
  190. package/dist/integrations/remote-push-delivery-job.js +44 -0
  191. package/dist/integrations/remote-push-delivery-job.js.map +1 -0
  192. package/dist/integrations/remote-push-delivery.d.ts +11 -0
  193. package/dist/integrations/remote-push-delivery.d.ts.map +1 -0
  194. package/dist/integrations/remote-push-delivery.js +265 -0
  195. package/dist/integrations/remote-push-delivery.js.map +1 -0
  196. package/dist/integrations/remote-push-store.d.ts +33 -0
  197. package/dist/integrations/remote-push-store.d.ts.map +1 -1
  198. package/dist/integrations/remote-push-store.js +195 -26
  199. package/dist/integrations/remote-push-store.js.map +1 -1
  200. package/dist/notifications/routes.d.ts +3 -3
  201. package/dist/progress/routes.d.ts +1 -1
  202. package/dist/provider-api/corpus-jobs.d.ts +2 -2
  203. package/dist/resources/handlers.d.ts +3 -3
  204. package/dist/secrets/routes.d.ts +9 -9
  205. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  206. package/dist/server/better-auth-instance.js +7 -3
  207. package/dist/server/better-auth-instance.js.map +1 -1
  208. package/dist/server/core-routes-plugin.d.ts +8 -0
  209. package/dist/server/core-routes-plugin.d.ts.map +1 -1
  210. package/dist/server/core-routes-plugin.js +23 -8
  211. package/dist/server/core-routes-plugin.js.map +1 -1
  212. package/dist/server/framework-request-handler.d.ts.map +1 -1
  213. package/dist/server/framework-request-handler.js +9 -1
  214. package/dist/server/framework-request-handler.js.map +1 -1
  215. package/dist/server/http-response-telemetry.d.ts +3 -2
  216. package/dist/server/http-response-telemetry.d.ts.map +1 -1
  217. package/dist/server/http-response-telemetry.js +160 -27
  218. package/dist/server/http-response-telemetry.js.map +1 -1
  219. package/dist/server/transcribe-voice.d.ts +1 -1
  220. package/dist/styles/rich-markdown-editor.css +1 -510
  221. package/dist/templates/workspace-core/.agents/skills/tracking/SKILL.md +19 -0
  222. package/dist/testing.d.ts +1 -1
  223. package/dist/testing.d.ts.map +1 -1
  224. package/dist/testing.js +1 -1
  225. package/dist/testing.js.map +1 -1
  226. package/dist/vite/client.d.ts.map +1 -1
  227. package/dist/vite/client.js +3 -0
  228. package/dist/vite/client.js.map +1 -1
  229. package/docs/content/agent-native-toolkit.mdx +46 -13
  230. package/docs/content/locales/ar-SA/agent-native-toolkit.mdx +79 -55
  231. package/docs/content/locales/ar-SA/toolkit-capability-packages.mdx +21 -0
  232. package/docs/content/locales/ar-SA/toolkit-context-knowledge.mdx +12 -0
  233. package/docs/content/locales/ar-SA/toolkit-editors-canvases.mdx +17 -0
  234. package/docs/content/locales/de-DE/agent-native-toolkit.mdx +82 -54
  235. package/docs/content/locales/de-DE/toolkit-capability-packages.mdx +21 -0
  236. package/docs/content/locales/de-DE/toolkit-context-knowledge.mdx +12 -0
  237. package/docs/content/locales/de-DE/toolkit-editors-canvases.mdx +17 -0
  238. package/docs/content/locales/es-ES/agent-native-toolkit.mdx +81 -52
  239. package/docs/content/locales/es-ES/toolkit-capability-packages.mdx +21 -0
  240. package/docs/content/locales/es-ES/toolkit-context-knowledge.mdx +12 -0
  241. package/docs/content/locales/es-ES/toolkit-editors-canvases.mdx +21 -0
  242. package/docs/content/locales/fr-FR/agent-native-toolkit.mdx +84 -54
  243. package/docs/content/locales/fr-FR/toolkit-capability-packages.mdx +21 -0
  244. package/docs/content/locales/fr-FR/toolkit-context-knowledge.mdx +12 -0
  245. package/docs/content/locales/fr-FR/toolkit-editors-canvases.mdx +21 -0
  246. package/docs/content/locales/hi-IN/agent-native-toolkit.mdx +69 -62
  247. package/docs/content/locales/hi-IN/toolkit-capability-packages.mdx +21 -0
  248. package/docs/content/locales/hi-IN/toolkit-context-knowledge.mdx +12 -0
  249. package/docs/content/locales/hi-IN/toolkit-editors-canvases.mdx +17 -0
  250. package/docs/content/locales/ja-JP/agent-native-toolkit.mdx +69 -62
  251. package/docs/content/locales/ja-JP/toolkit-capability-packages.mdx +21 -0
  252. package/docs/content/locales/ja-JP/toolkit-context-knowledge.mdx +12 -0
  253. package/docs/content/locales/ja-JP/toolkit-editors-canvases.mdx +17 -0
  254. package/docs/content/locales/ko-KR/agent-native-toolkit.mdx +69 -62
  255. package/docs/content/locales/ko-KR/toolkit-capability-packages.mdx +21 -0
  256. package/docs/content/locales/ko-KR/toolkit-context-knowledge.mdx +12 -0
  257. package/docs/content/locales/ko-KR/toolkit-editors-canvases.mdx +17 -0
  258. package/docs/content/locales/pt-BR/agent-native-toolkit.mdx +82 -54
  259. package/docs/content/locales/pt-BR/toolkit-capability-packages.mdx +21 -0
  260. package/docs/content/locales/pt-BR/toolkit-context-knowledge.mdx +12 -0
  261. package/docs/content/locales/pt-BR/toolkit-editors-canvases.mdx +17 -0
  262. package/docs/content/locales/zh-CN/agent-native-toolkit.mdx +69 -62
  263. package/docs/content/locales/zh-CN/toolkit-capability-packages.mdx +21 -0
  264. package/docs/content/locales/zh-CN/toolkit-context-knowledge.mdx +12 -0
  265. package/docs/content/locales/zh-CN/toolkit-editors-canvases.mdx +17 -0
  266. package/docs/content/locales/zh-TW/agent-native-toolkit.mdx +69 -62
  267. package/docs/content/locales/zh-TW/toolkit-capability-packages.mdx +21 -0
  268. package/docs/content/locales/zh-TW/toolkit-context-knowledge.mdx +12 -0
  269. package/docs/content/locales/zh-TW/toolkit-editors-canvases.mdx +17 -0
  270. package/docs/content/toolkit-capability-packages.mdx +52 -0
  271. package/docs/content/toolkit-context-knowledge.mdx +46 -0
  272. package/docs/content/toolkit-editors-canvases.mdx +55 -0
  273. package/package.json +27 -26
  274. package/src/templates/workspace-core/.agents/skills/tracking/SKILL.md +19 -0
  275. package/corpus/core/src/client/rich-markdown-editor/BubbleToolbar.tsx +0 -253
  276. package/corpus/core/src/client/rich-markdown-editor/CodeBlockNode.tsx +0 -258
  277. package/corpus/core/src/client/rich-markdown-editor/DragHandle.ts +0 -1437
  278. package/corpus/core/src/client/rich-markdown-editor/ImageExtension.ts +0 -306
  279. package/corpus/core/src/client/rich-markdown-editor/RichMarkdownEditor.tsx +0 -80
  280. package/corpus/core/src/client/rich-markdown-editor/RunId.ts +0 -61
  281. package/corpus/core/src/client/rich-markdown-editor/SharedRichEditor.tsx +0 -321
  282. package/corpus/core/src/client/rich-markdown-editor/SlashCommandMenu.tsx +0 -310
  283. package/corpus/core/src/client/rich-markdown-editor/extensions.ts +0 -402
  284. package/corpus/core/src/client/rich-markdown-editor/gfmDoc.ts +0 -92
  285. package/corpus/core/src/client/rich-markdown-editor/surgical-apply.ts +0 -192
  286. package/corpus/core/src/client/rich-markdown-editor/useCollabReconcile.ts +0 -590
  287. package/dist/client/rich-markdown-editor/BubbleToolbar.d.ts +0 -37
  288. package/dist/client/rich-markdown-editor/BubbleToolbar.d.ts.map +0 -1
  289. package/dist/client/rich-markdown-editor/BubbleToolbar.js +0 -171
  290. package/dist/client/rich-markdown-editor/BubbleToolbar.js.map +0 -1
  291. package/dist/client/rich-markdown-editor/CodeBlockNode.d.ts +0 -49
  292. package/dist/client/rich-markdown-editor/CodeBlockNode.d.ts.map +0 -1
  293. package/dist/client/rich-markdown-editor/CodeBlockNode.js +0 -127
  294. package/dist/client/rich-markdown-editor/CodeBlockNode.js.map +0 -1
  295. package/dist/client/rich-markdown-editor/DragHandle.d.ts +0 -97
  296. package/dist/client/rich-markdown-editor/DragHandle.d.ts.map +0 -1
  297. package/dist/client/rich-markdown-editor/DragHandle.js +0 -1066
  298. package/dist/client/rich-markdown-editor/DragHandle.js.map +0 -1
  299. package/dist/client/rich-markdown-editor/ImageExtension.d.ts +0 -63
  300. package/dist/client/rich-markdown-editor/ImageExtension.d.ts.map +0 -1
  301. package/dist/client/rich-markdown-editor/ImageExtension.js +0 -243
  302. package/dist/client/rich-markdown-editor/ImageExtension.js.map +0 -1
  303. package/dist/client/rich-markdown-editor/RichMarkdownEditor.d.ts +0 -51
  304. package/dist/client/rich-markdown-editor/RichMarkdownEditor.d.ts.map +0 -1
  305. package/dist/client/rich-markdown-editor/RichMarkdownEditor.js +0 -37
  306. package/dist/client/rich-markdown-editor/RichMarkdownEditor.js.map +0 -1
  307. package/dist/client/rich-markdown-editor/RunId.d.ts +0 -28
  308. package/dist/client/rich-markdown-editor/RunId.d.ts.map +0 -1
  309. package/dist/client/rich-markdown-editor/RunId.js +0 -60
  310. package/dist/client/rich-markdown-editor/RunId.js.map +0 -1
  311. package/dist/client/rich-markdown-editor/SharedRichEditor.d.ts +0 -110
  312. package/dist/client/rich-markdown-editor/SharedRichEditor.d.ts.map +0 -1
  313. package/dist/client/rich-markdown-editor/SharedRichEditor.js +0 -144
  314. package/dist/client/rich-markdown-editor/SharedRichEditor.js.map +0 -1
  315. package/dist/client/rich-markdown-editor/SlashCommandMenu.d.ts +0 -41
  316. package/dist/client/rich-markdown-editor/SlashCommandMenu.d.ts.map +0 -1
  317. package/dist/client/rich-markdown-editor/SlashCommandMenu.js +0 -221
  318. package/dist/client/rich-markdown-editor/SlashCommandMenu.js.map +0 -1
  319. package/dist/client/rich-markdown-editor/extensions.d.ts +0 -178
  320. package/dist/client/rich-markdown-editor/extensions.d.ts.map +0 -1
  321. package/dist/client/rich-markdown-editor/extensions.js +0 -224
  322. package/dist/client/rich-markdown-editor/extensions.js.map +0 -1
  323. package/dist/client/rich-markdown-editor/gfmDoc.d.ts +0 -24
  324. package/dist/client/rich-markdown-editor/gfmDoc.d.ts.map +0 -1
  325. package/dist/client/rich-markdown-editor/gfmDoc.js +0 -83
  326. package/dist/client/rich-markdown-editor/gfmDoc.js.map +0 -1
  327. package/dist/client/rich-markdown-editor/surgical-apply.d.ts +0 -66
  328. package/dist/client/rich-markdown-editor/surgical-apply.d.ts.map +0 -1
  329. package/dist/client/rich-markdown-editor/surgical-apply.js +0 -147
  330. package/dist/client/rich-markdown-editor/surgical-apply.js.map +0 -1
  331. package/dist/client/rich-markdown-editor/useCollabReconcile.d.ts +0 -110
  332. package/dist/client/rich-markdown-editor/useCollabReconcile.d.ts.map +0 -1
  333. package/dist/client/rich-markdown-editor/useCollabReconcile.js +0 -441
  334. package/dist/client/rich-markdown-editor/useCollabReconcile.js.map +0 -1
@@ -1,590 +0,0 @@
1
- import { isChangeOrigin } from "@tiptap/extension-collaboration";
2
- import type { Node as ProseMirrorNode } from "@tiptap/pm/model";
3
- import type { Transaction } from "@tiptap/pm/state";
4
- import type { Editor } from "@tiptap/react";
5
- import { useEffect, useRef, useState, type MutableRefObject } from "react";
6
- import type { Awareness } from "y-protocols/awareness";
7
- import type { Doc as YDoc } from "yjs";
8
-
9
- import { AGENT_CLIENT_ID } from "../../collab/agent-identity.js";
10
- import { isReconcileLeadClient } from "../../collab/client.js";
11
- import {
12
- RICH_MARKDOWN_PROGRAMMATIC_TRANSACTION,
13
- applyDocSurgically,
14
- defaultParseValue,
15
- } from "./surgical-apply.js";
16
-
17
- export { RICH_MARKDOWN_PROGRAMMATIC_TRANSACTION };
18
-
19
- /** Reads the current markdown out of the tiptap-markdown storage. */
20
- export function getEditorMarkdown(editor: Editor): string {
21
- const markdownStorage = editor.storage as unknown as {
22
- markdown?: { getMarkdown?: () => string };
23
- };
24
- return markdownStorage.markdown?.getMarkdown?.() ?? "";
25
- }
26
-
27
- /**
28
- * Push a value onto the bounded ring of recently-emitted markdown (most recent
29
- * last, deduped, capped). The reconcile uses this to recognize a stale-but-recent
30
- * echo of OUR OWN edits: a debounced autosave can persist a PARTIAL burst, and
31
- * the next poll re-supplies that partial value with a newer timestamp — applying
32
- * it would clobber the freshly-typed tail. An external change (agent/peer) never
33
- * byte-matches one of our own recent emissions, and if it somehow did the content
34
- * is identical, so skipping it is safe by construction.
35
- */
36
- const EMITTED_RING_MAX = 16;
37
- function pushEmittedRing(ring: string[], value: string): void {
38
- if (!value) return;
39
- if (ring[ring.length - 1] === value) return;
40
- const dupe = ring.indexOf(value);
41
- if (dupe !== -1) ring.splice(dupe, 1);
42
- ring.push(value);
43
- if (ring.length > EMITTED_RING_MAX) ring.shift();
44
- }
45
-
46
- export interface UseCollabReconcileOptions {
47
- /** The live editor, or null until it mounts. */
48
- editor: Editor | null;
49
- /** Shared Y.Doc when collaborating; null disables all collab paths. */
50
- ydoc?: YDoc | null;
51
- /** True after the collab provider has loaded the persisted initial Y.Doc state. */
52
- collabSynced?: boolean;
53
- /** Shared awareness; null keeps the sole-client lead path. */
54
- awareness?: Awareness | null;
55
- /** Authoritative markdown value (SQL source of truth). */
56
- value: string;
57
- /** Timestamp of the authoritative value; gates newer-than reconcile. */
58
- contentUpdatedAt?: string | null;
59
- /** Whether the editor accepts edits. Reconcile/seed only run for the live editor. */
60
- editable: boolean;
61
- /**
62
- * Reads the current markdown from the editor. Injected so a dialect could
63
- * swap serializers; defaults to the tiptap-markdown storage reader. For an app
64
- * with a custom serializer (e.g. Content's `docToNfm(editor.getJSON())`), pass
65
- * it here so the seed/reconcile equality checks compare like-for-like.
66
- */
67
- getMarkdown?: (editor: Editor) => string;
68
- /**
69
- * Applies the authoritative `value` into the editor. Defaults to passing the
70
- * raw markdown string to `editor.commands.setContent`. Apps whose serializer
71
- * is NOT tiptap-markdown (Content parses `nfmToDoc(value)` into a PM doc)
72
- * override this so seed + reconcile write the correct content shape. The
73
- * supplied `options` carry the history/whitespace flags the default path uses;
74
- * a custom implementation should forward them when relevant.
75
- */
76
- setContent?: (
77
- editor: Editor,
78
- value: string,
79
- options: { emitUpdate?: boolean; addToHistory?: boolean },
80
- ) => void;
81
- /**
82
- * Parses the authoritative `value` into a full ProseMirror document for the
83
- * SURGICAL reconcile path: instead of a whole-document `setContent` (which
84
- * under Collaboration rewrites the entire Y.XmlFragment and tears down every
85
- * block NodeView), the reconcile diffs the parsed doc against the live doc
86
- * and replaces only the changed top-level run. Return null to skip the
87
- * surgical path for a given value (falls back to `setContent`).
88
- *
89
- * Defaults to a best-effort tiptap-markdown parse; apps with their own
90
- * serializers (Content's NFM, Plan's blocks[] doc) should supply the exact
91
- * doc their `setContent` would write. Pass `false` to disable surgical
92
- * application entirely.
93
- */
94
- parseValue?:
95
- | ((editor: Editor, value: string) => ProseMirrorNode | null)
96
- | false;
97
- /**
98
- * Normalizes the authoritative `value` to the canonical markdown the editor
99
- * would emit, so the "already in sync / our own echo" equality checks match a
100
- * serializer that re-canonicalizes (Content's `canonicalizeNfm`). Defaults to
101
- * identity (GFM already round-trips byte-stably).
102
- */
103
- normalizeValue?: (value: string) => string;
104
- /**
105
- * Decides whether the empty-doc seed should run for the current shared
106
- * fragment. Defaults to "fragment has no nodes, or the editor holds no
107
- * semantic markdown". Apps with sentinel-empty content (Content's
108
- * `<empty-block/>` filler) override this. Receives the live fragment length
109
- * and the editor's current markdown.
110
- */
111
- shouldSeed?: (info: {
112
- value: string;
113
- currentMarkdown: string;
114
- fragmentLength: number;
115
- }) => boolean;
116
- /**
117
- * The initial "applied" watermark. Default mirrors `contentUpdatedAt`, so a
118
- * fresh mount whose Y.Doc already matches SQL doesn't re-apply. Pass `null`
119
- * to force the first reconcile pass to adopt authoritative SQL even at the
120
- * same timestamp — Content does this so a stale persisted Y.Doc (an agent that
121
- * edited the CLOSED doc) is corrected on open. The editor is keyed per
122
- * document upstream, so this only affects the first mount of each doc.
123
- */
124
- initialAppliedUpdatedAt?: string | null;
125
- }
126
-
127
- export interface UseCollabReconcileResult {
128
- /** True when a Y.Doc is bound (collaborative editing active). */
129
- collab: boolean;
130
- /**
131
- * Set true around any programmatic `setContent` so the editor's `onUpdate`
132
- * can ignore the resulting transaction (it isn't a user edit).
133
- */
134
- isSettingContentRef: MutableRefObject<boolean>;
135
- /**
136
- * Call from `onUpdate` BEFORE serializing. Returns true when the update must
137
- * be ignored: editor not editable, mid-programmatic-setContent, or (in collab
138
- * mode) a remote-origin transaction. Also records the local typing time.
139
- */
140
- shouldIgnoreUpdate: (transaction: Transaction) => boolean;
141
- /**
142
- * Call from `onUpdate` AFTER computing the markdown to emit. Returns false
143
- * when the value must NOT be persisted yet (an empty collab doc before the
144
- * seed has run); records it as the last-emitted value otherwise.
145
- */
146
- registerEmitted: (markdown: string) => boolean;
147
- }
148
-
149
- /**
150
- * The subtle seed / reconcile / lead-client logic for the shared markdown
151
- * editor, extracted once so it can never be duplicated across embedders.
152
- *
153
- * Responsibilities (reproducing the Plan editor's behavior exactly):
154
- * - Track whether THIS client is the reconcile lead (sole client always leads;
155
- * otherwise elected via {@link isReconcileLeadClient}) and how many other
156
- * visible human peers are present.
157
- * - Seed an empty shared Y.Doc once from `value` — lead client only — so two
158
- * clients opening a brand-new block don't both insert the content.
159
- * - Reconcile authoritative external markdown (agent edit, source patch, peer
160
- * edit mirrored to SQL) into the editor: in collab mode only the lead client
161
- * applies it through `setContent` and Yjs propagates; in non-collab mode this
162
- * is the original controlled-value reconcile.
163
- * - Provide the `onUpdate` guards (`shouldIgnoreUpdate`, `registerEmitted`) so
164
- * the component never persists remote-origin or pre-seed empty content.
165
- */
166
- /** Default seed predicate: seed only when the shared doc is genuinely empty. */
167
- function defaultShouldSeed({
168
- currentMarkdown,
169
- fragmentLength,
170
- }: {
171
- value: string;
172
- currentMarkdown: string;
173
- fragmentLength: number;
174
- }): boolean {
175
- return fragmentLength === 0 || !currentMarkdown.trim();
176
- }
177
-
178
- /**
179
- * Default content writer: hand the raw markdown string to `setContent`, which
180
- * tiptap-markdown overrides to parse the markdown into a ProseMirror doc.
181
- *
182
- * IMPORTANT: do NOT pass `parseOptions: { preserveWhitespace: "full" }` here.
183
- * In tiptap v3 the core `setContent` command routes `preserveWhitespace: "full"`
184
- * through `insertContentAt`, which tiptap-markdown ALSO overrides to re-run its
185
- * markdown parser. That double-parse stringifies the already-parsed PM doc and
186
- * re-parses it as HTML, so a clean heading/list/code block comes back as the
187
- * escaped, non-idempotent `&lt;h1&gt;…` — which then escalates every reconcile
188
- * cycle (`<p>` → `&lt;p&gt;` → `&amp;lt;p&amp;gt;` …). Letting the markdown
189
- * override parse the string directly (no `parseOptions`) round-trips byte-stably
190
- * for the GFM corpus, including code-block and empty-line whitespace. Content's
191
- * NFM path supplies its own `setContent` (it passes a pre-parsed PM doc) and is
192
- * unaffected by this default.
193
- */
194
- function defaultSetContent(
195
- editor: Editor,
196
- value: string,
197
- options: { emitUpdate?: boolean; addToHistory?: boolean },
198
- ): void {
199
- if (options.addToHistory === false) {
200
- editor
201
- .chain()
202
- .command(({ tr }) => {
203
- // addToHistory:false so cmd+z (or Yjs undo) doesn't erase
204
- // externally-loaded content.
205
- tr.setMeta("addToHistory", false);
206
- return true;
207
- })
208
- .setContent(value, { emitUpdate: options.emitUpdate })
209
- .run();
210
- return;
211
- }
212
- editor.commands.setContent(value);
213
- }
214
-
215
- export function useCollabReconcile({
216
- editor,
217
- ydoc = null,
218
- collabSynced = true,
219
- awareness = null,
220
- value,
221
- contentUpdatedAt,
222
- editable,
223
- getMarkdown = getEditorMarkdown,
224
- setContent = defaultSetContent,
225
- parseValue,
226
- normalizeValue = (v) => v,
227
- shouldSeed = defaultShouldSeed,
228
- initialAppliedUpdatedAt,
229
- }: UseCollabReconcileOptions): UseCollabReconcileResult {
230
- const collab = !!ydoc;
231
- const isSettingContentRef = useRef(false);
232
- const lastEmittedRef = useRef("");
233
- // Ring of recent local emissions (see pushEmittedRing). Lets the reconcile
234
- // recognize a stale-but-recent echo of our OWN (possibly partial, debounced)
235
- // save so a lagging poll never clobbers freshly-typed text.
236
- const recentEmittedRef = useRef<string[]>([]);
237
- const lastTypedAtRef = useRef(0);
238
- // The raw authoritative `value` string the reconcile last applied. When the
239
- // SAME raw string is re-fetched (a lagging poll, or a source-sync that keeps
240
- // re-supplying the same stored markdown), applying it again would only
241
- // reproduce the doc we already hold — and if `value` is NON-idempotent
242
- // (serialize(parse(value)) !== value) re-applying compounds the divergence
243
- // every cycle (`<p>` → `&lt;p&gt;` → `&amp;lt;p&amp;gt;` …). Tracked so the
244
- // identical re-fetch is recognized and skipped.
245
- const lastAppliedValueRef = useRef<string | null>(null);
246
- // The editor's SERIALIZED output captured right AFTER the last reconcile/seed
247
- // apply (`getMarkdown(editor)` once the content settled). For non-idempotent
248
- // input this is what autosave actually persists, so the NEXT poll hands it
249
- // back as the new `value`. Comparing the incoming value against this lets the
250
- // reconcile recognize its own echo even when the raw string changed once, so
251
- // it never re-parses content the editor already represents. This is the
252
- // doc-equivalence guard that breaks the escalation loop.
253
- const lastAppliedSerializedRef = useRef<string | null>(null);
254
- const lastAppliedUpdatedAtRef = useRef<string | null>(
255
- initialAppliedUpdatedAt !== undefined
256
- ? initialAppliedUpdatedAt
257
- : (contentUpdatedAt ?? null),
258
- );
259
-
260
- // Whether THIS client is the one that seeds the empty shared doc / applies an
261
- // authoritative external snapshot into it. Exactly one client does, so the
262
- // content isn't inserted once per open editor. A sole client always leads.
263
- const [isLeadClient, setIsLeadClient] = useState(true);
264
- // Count of OTHER visible human collaborators. When >0, a peer's edit also
265
- // arrives via Yjs, so external markdown reconcile must defer (avoid applying
266
- // the same change through both Yjs and setContent).
267
- const peerCountRef = useRef(0);
268
- useEffect(() => {
269
- if (!collab || !awareness || !ydoc) {
270
- setIsLeadClient(true);
271
- peerCountRef.current = 0;
272
- return;
273
- }
274
- const update = () => {
275
- setIsLeadClient(isReconcileLeadClient(awareness, ydoc.clientID));
276
- let peers = 0;
277
- awareness.getStates().forEach((state, clientId) => {
278
- if (clientId === ydoc.clientID) return; // self
279
- if (clientId === AGENT_CLIENT_ID) return; // agent isn't a Yjs editor
280
- const s = state as { user?: unknown; visible?: boolean };
281
- if (s && s.user && s.visible !== false) peers += 1;
282
- });
283
- peerCountRef.current = peers;
284
- };
285
- update();
286
- awareness.on("change", update);
287
- document.addEventListener("visibilitychange", update);
288
- return () => {
289
- awareness.off("change", update);
290
- document.removeEventListener("visibilitychange", update);
291
- };
292
- }, [collab, awareness, ydoc]);
293
-
294
- // Collab seed: populate an empty shared Y.Doc from the markdown `value` once.
295
- // The Collaboration extension does NOT auto-seed; only the lead client does,
296
- // so two clients opening a brand-new block at once don't both seed (which
297
- // would duplicate the content via concurrent inserts at the same position).
298
- const seededRef = useRef(false);
299
- useEffect(() => {
300
- if (!collab || !editor || editor.isDestroyed || !ydoc) return;
301
- if (seededRef.current) return;
302
- if (!collabSynced) return;
303
- if (!isLeadClient) return;
304
- if (!value.trim()) return;
305
- const fragment = ydoc.getXmlFragment("default");
306
- const currentMarkdown = getMarkdown(editor);
307
- // Seed only when the shared doc is genuinely empty — either the fragment has
308
- // no nodes yet, or it holds no semantic markdown (an empty paragraph, or an
309
- // app's sentinel-empty filler via a custom `shouldSeed`).
310
- if (
311
- !shouldSeed({ value, currentMarkdown, fragmentLength: fragment.length })
312
- ) {
313
- seededRef.current = true;
314
- return;
315
- }
316
-
317
- let cancelled = false;
318
- // Defer via a timer task (NOT a microtask — microtasks can still run
319
- // inside React's commit and trigger flushSync-from-lifecycle warnings).
320
- const seedTimer = setTimeout(() => {
321
- if (cancelled || editor.isDestroyed) return;
322
- isSettingContentRef.current = true;
323
- try {
324
- setContent(editor, value, {});
325
- } finally {
326
- isSettingContentRef.current = false;
327
- }
328
- const serialized = getMarkdown(editor);
329
- lastEmittedRef.current = serialized;
330
- pushEmittedRing(recentEmittedRef.current, serialized);
331
- lastAppliedValueRef.current = value;
332
- lastAppliedSerializedRef.current = serialized;
333
- if (contentUpdatedAt) lastAppliedUpdatedAtRef.current = contentUpdatedAt;
334
- seededRef.current = true;
335
- }, 0);
336
- return () => {
337
- cancelled = true;
338
- clearTimeout(seedTimer);
339
- };
340
- }, [
341
- collab,
342
- collabSynced,
343
- editor,
344
- ydoc,
345
- value,
346
- isLeadClient,
347
- contentUpdatedAt,
348
- getMarkdown,
349
- setContent,
350
- shouldSeed,
351
- ]);
352
-
353
- // Reconcile authoritative external markdown (agent edit, source patch, or a
354
- // peer edit mirrored to SQL) into the live editor. In collab mode only the
355
- // lead client applies it through setContent; Yjs propagates the result to
356
- // every other client. In non-collab mode this is the original controlled-value
357
- // reconcile, unchanged.
358
- useEffect(() => {
359
- if (!editor || editor.isDestroyed) return;
360
-
361
- let cancelled = false;
362
- let retry: ReturnType<typeof setTimeout> | null = null;
363
- // With peers present, a peer's edit also arrives via Yjs. Defer one poll
364
- // cycle (+margin) and re-check before applying via setContent so the same
365
- // change isn't inserted twice (Yjs + setContent → duplicated region).
366
- const PEER_SETTLE_MS = 2500;
367
-
368
- const apply = (deferred = false) => {
369
- if (cancelled || editor.isDestroyed) return;
370
- // In collab mode, defer all reconcile until the shared doc is seeded so we
371
- // never setContent over an unseeded fragment.
372
- if (collab && (!collabSynced || !seededRef.current)) {
373
- retry = setTimeout(() => apply(deferred), 300);
374
- return;
375
- }
376
- const currentMarkdown = getMarkdown(editor);
377
- // Compare against the canonical form the editor would emit so a serializer
378
- // that re-normalizes (Content's NFM) still recognizes "already in sync".
379
- const normalizedValue = normalizeValue(value);
380
- // Whether the editor still holds exactly what THIS hook last applied (the
381
- // user hasn't edited since). Only then are the round-trip echo guards
382
- // below safe: if the user has since edited away from the applied content,
383
- // an external snapshot equal to a previously-applied value is a real
384
- // revert and must NOT be swallowed as an echo.
385
- const editorUnchangedSinceApply =
386
- lastAppliedSerializedRef.current !== null &&
387
- currentMarkdown === lastAppliedSerializedRef.current;
388
- const typingRecently =
389
- editor.isFocused && Date.now() - lastTypedAtRef.current < 1500;
390
-
391
- // Doc-equivalence skip. Never re-apply content the editor already
392
- // represents — comparing by DOC EQUIVALENCE, not raw strings/timestamps:
393
- // 1. `currentMarkdown === normalizedValue` — the editor's CURRENT
394
- // serialized doc already equals the (normalized) incoming value.
395
- // 2. `value === lastEmittedRef.current` — the incoming value is our own
396
- // just-emitted markdown echoing back.
397
- // 3. `value === lastAppliedValueRef.current` — the SAME raw value we
398
- // already applied is being re-supplied (a lagging poll or a
399
- // source-sync re-handing the same stored markdown). Applying it again
400
- // would only reproduce the doc we hold; for NON-idempotent input it
401
- // would compound divergence. Guarded by `editorUnchangedSinceApply`
402
- // so a deliberate revert-to-previous after a local edit still lands.
403
- // 4. `normalizedValue === lastAppliedSerializedRef.current` — the
404
- // incoming value round-trips to the serialized output we last
405
- // produced (our own autosaved echo coming back from SQL). For
406
- // non-idempotent input the raw string differs from what we were
407
- // handed, but it is doc-equivalent to what the editor already shows,
408
- // so re-parsing it must be skipped. This is the guard that stops the
409
- // `<p>` → `&lt;p&gt;` → `&amp;lt;p&amp;gt;` escalation.
410
- if (
411
- currentMarkdown === normalizedValue ||
412
- (typingRecently &&
413
- // A stale echo of our own (possibly partial) save while the user is
414
- // actively typing would clobber the fresh tail. Outside active
415
- // typing, the same bytes can be a deliberate newer external revert
416
- // (history restore / provider conflict choice) and must be allowed
417
- // through even if mount-time normalization emitted them.
418
- (value === lastEmittedRef.current ||
419
- recentEmittedRef.current.includes(value) ||
420
- recentEmittedRef.current.includes(normalizedValue))) ||
421
- (editorUnchangedSinceApply &&
422
- (value === lastAppliedValueRef.current ||
423
- normalizedValue === lastAppliedSerializedRef.current))
424
- ) {
425
- if (contentUpdatedAt) {
426
- lastAppliedUpdatedAtRef.current = contentUpdatedAt;
427
- }
428
- return;
429
- }
430
-
431
- const externalNewer =
432
- !lastAppliedUpdatedAtRef.current ||
433
- !contentUpdatedAt ||
434
- contentUpdatedAt > lastAppliedUpdatedAtRef.current;
435
-
436
- // Only the lead client applies an authoritative snapshot into the shared
437
- // Y.Doc; peers receive it through Yjs sync.
438
- if (collab && !isLeadClient) {
439
- if (contentUpdatedAt && !externalNewer) {
440
- lastAppliedUpdatedAtRef.current = contentUpdatedAt;
441
- }
442
- return;
443
- }
444
-
445
- // Never clobber an in-progress edit. While the user is actively typing
446
- // (focused and a keystroke landed within the window) defer and re-check —
447
- // applying external content now would yank text out from under them and,
448
- // for non-idempotent input, fight every keystroke. Newer external content
449
- // retries so it still lands once they pause; older-or-equal content is a
450
- // stale poll and is dropped outright while focused.
451
- if (typingRecently) {
452
- if (externalNewer) {
453
- retry = setTimeout(() => apply(deferred), 700);
454
- }
455
- return;
456
- }
457
- // Older-or-equal content is a stale poll / lagging echo. Drop it while
458
- // focused (a peer/agent edit would be NEWER and retries above). In
459
- // NON-COLLAB mode there is no peer, so older-or-equal external content is
460
- // ALWAYS stale — dropping it regardless of focus stops a lagging
461
- // `get-visual-plan` poll from reverting a just-applied local structural
462
- // change (drag-to-columns) while the editor is blurred (the drag grips the
463
- // handle, not the prose, so `isFocused` is false at drop time). Gated on
464
- // `lastAppliedSerializedRef` so the very first seed (nothing applied yet,
465
- // also not-newer) still lands.
466
- const seeded = lastAppliedSerializedRef.current !== null;
467
- if (!externalNewer && (editor.isFocused || (!collab && seeded))) return;
468
-
469
- // Race guard: with peers present, let Yjs deliver a peer's edit first.
470
- // Defer once and re-check — a peer edit makes the equality check above
471
- // no-op next pass; an agent/source edit still differs and applies.
472
- if (collab && externalNewer && !deferred && peerCountRef.current > 0) {
473
- retry = setTimeout(() => apply(true), PEER_SETTLE_MS);
474
- return;
475
- }
476
-
477
- const applyTimer = setTimeout(() => {
478
- if (cancelled || editor.isDestroyed) return;
479
- // Re-check doc-equivalence at apply time. Between the decision above and
480
- // this task a peer/Yjs edit (or our own prior apply) may have made
481
- // the editor already represent this value — re-applying would be a
482
- // wasted setContent that, for non-idempotent input, re-triggers the
483
- // loop. Skip when the editor's current serialization already matches the
484
- // normalized value, or the value round-trips to what we last produced.
485
- const beforeMarkdown = getMarkdown(editor);
486
- const normalized = normalizeValue(value);
487
- const unchangedSinceApply =
488
- lastAppliedSerializedRef.current !== null &&
489
- beforeMarkdown === lastAppliedSerializedRef.current;
490
- if (
491
- beforeMarkdown === normalized ||
492
- (unchangedSinceApply &&
493
- normalized === lastAppliedSerializedRef.current)
494
- ) {
495
- lastAppliedValueRef.current = value;
496
- if (contentUpdatedAt) {
497
- lastAppliedUpdatedAtRef.current = contentUpdatedAt;
498
- }
499
- return;
500
- }
501
- isSettingContentRef.current = true;
502
- // Surgical path first: replace only the changed top-level run so
503
- // unchanged block NodeViews are never torn down and (under
504
- // Collaboration) Yjs sees a minimal edit instead of a full-fragment
505
- // rewrite. Falls back to the classic whole-document setContent when no
506
- // parser is available or the targeted transaction cannot be applied.
507
- let appliedSurgically = false;
508
- if (parseValue !== false) {
509
- const parse = parseValue ?? defaultParseValue;
510
- const parsedDoc = parse(editor, value);
511
- if (parsedDoc) {
512
- const result = applyDocSurgically(editor, parsedDoc);
513
- appliedSurgically = result === "applied" || result === "noop";
514
- }
515
- }
516
- if (!appliedSurgically) {
517
- setContent(editor, value, { emitUpdate: false, addToHistory: false });
518
- }
519
- isSettingContentRef.current = false;
520
- // Capture the SERIALIZED result, not the raw value. For non-idempotent
521
- // input these differ; recording the serialized output is what lets the
522
- // next poll (which returns this serialized form) be recognized as our
523
- // own echo and skipped — stabilizing the doc after exactly one apply.
524
- const serialized = getMarkdown(editor);
525
- lastEmittedRef.current = serialized;
526
- pushEmittedRing(recentEmittedRef.current, serialized);
527
- lastAppliedValueRef.current = value;
528
- lastAppliedSerializedRef.current = serialized;
529
- if (contentUpdatedAt) {
530
- lastAppliedUpdatedAtRef.current = contentUpdatedAt;
531
- }
532
- }, 0);
533
- retry = applyTimer;
534
- };
535
-
536
- apply();
537
- return () => {
538
- cancelled = true;
539
- if (retry) clearTimeout(retry);
540
- };
541
- }, [
542
- contentUpdatedAt,
543
- editor,
544
- value,
545
- collab,
546
- collabSynced,
547
- isLeadClient,
548
- getMarkdown,
549
- setContent,
550
- parseValue,
551
- normalizeValue,
552
- ]);
553
-
554
- const shouldIgnoreUpdate = (transaction: Transaction): boolean => {
555
- if (!editable || isSettingContentRef.current) return true;
556
- // Collaboration can emit schema/default-paragraph transactions while the
557
- // persisted Y.Doc is still loading and before the authoritative value has
558
- // seeded/reconciled. Never let those transient pre-seed updates reach an
559
- // app's local mirror or autosave path (Content serializes an empty paragraph
560
- // as `<empty-block/>`, which is non-empty text and bypasses the generic
561
- // registerEmitted empty-string guard).
562
- if (collab && !seededRef.current) return true;
563
- if (transaction.getMeta(RICH_MARKDOWN_PROGRAMMATIC_TRANSACTION)) {
564
- return true;
565
- }
566
- // In collab mode, never persist remote-originated changes (the initial Yjs
567
- // state load or a peer's edit arriving via sync). Each client saves only its
568
- // OWN local edits; a peer's edit is saved by that peer. Without this, a
569
- // lagging Y.Doc load would write stale markdown over newer SQL.
570
- if (collab && transaction && isChangeOrigin(transaction)) return true;
571
- lastTypedAtRef.current = Date.now();
572
- return false;
573
- };
574
-
575
- const registerEmitted = (markdown: string): boolean => {
576
- // Don't persist an empty doc before Collaboration has seeded — that would
577
- // clobber the saved block content with an empty string.
578
- if (collab && !markdown.trim()) return false;
579
- lastEmittedRef.current = markdown;
580
- pushEmittedRing(recentEmittedRef.current, markdown);
581
- return true;
582
- };
583
-
584
- return {
585
- collab,
586
- isSettingContentRef,
587
- shouldIgnoreUpdate,
588
- registerEmitted,
589
- };
590
- }
@@ -1,37 +0,0 @@
1
- import type { Editor } from "@tiptap/react";
2
- import { type CSSProperties } from "react";
3
- /** A bubble-toolbar button or a divider. */
4
- export type BubbleToolbarItem = {
5
- /** Short label/glyph shown on the button. */
6
- label: string;
7
- /** Accessible/title text. */
8
- title: string;
9
- action: () => void;
10
- isActive: () => boolean;
11
- style?: CSSProperties;
12
- } | {
13
- type: "divider";
14
- };
15
- /**
16
- * Builds the default selection-toolbar items (Plan's current set): bold,
17
- * italic, strike, code, headings 1-3, and a link toggle. `toggleLink` is
18
- * supplied by the toolbar so the link-editor input can be opened.
19
- */
20
- export declare function buildDefaultBubbleItems(editor: Editor, toggleLink: () => void): BubbleToolbarItem[];
21
- export interface BubbleToolbarProps {
22
- editor: Editor;
23
- /**
24
- * Custom item builder. Receives the editor and the `toggleLink` helper (so a
25
- * custom set can still open the built-in link editor). Defaults to
26
- * {@link buildDefaultBubbleItems}.
27
- */
28
- buildItems?: (editor: Editor, toggleLink: () => void) => BubbleToolbarItem[];
29
- }
30
- /**
31
- * The shared floating selection toolbar. Tracks the current text selection and
32
- * positions a fixed toolbar above it, with an inline link editor. Extracted
33
- * from the inline plan toolbar so embedders share one implementation; apps swap
34
- * the item set via `buildItems`.
35
- */
36
- export declare function BubbleToolbar({ editor, buildItems, }: BubbleToolbarProps): import("react").JSX.Element | null;
37
- //# sourceMappingURL=BubbleToolbar.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BubbleToolbar.d.ts","sourceRoot":"","sources":["../../../src/client/rich-markdown-editor/BubbleToolbar.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAIhE,4CAA4C;AAC5C,MAAM,MAAM,iBAAiB,GACzB;IACE,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,EAAE,MAAM,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,GACD;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAExB;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,IAAI,GACrB,iBAAiB,EAAE,CAyDrB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,IAAI,KAAK,iBAAiB,EAAE,CAAC;CAC9E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,UAAoC,GACrC,EAAE,kBAAkB,sCAmJpB"}