@jaetask/toolkit 0.1.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (661) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/LICENSE +2 -0
  3. package/README.md +48 -76
  4. package/dist/app/review/InlineMarkdown.d.ts +20 -0
  5. package/dist/app/review/InlineMarkdown.d.ts.map +1 -0
  6. package/dist/app/review/InlineMarkdown.js +68 -0
  7. package/dist/app/review/InlineMarkdown.js.map +1 -0
  8. package/dist/app/review/index.d.ts +2 -0
  9. package/dist/app/review/index.d.ts.map +1 -0
  10. package/dist/app/review/index.js +3 -0
  11. package/dist/app/review/index.js.map +1 -0
  12. package/dist/collab-ui/AgentPresenceChip.d.ts +8 -0
  13. package/dist/collab-ui/AgentPresenceChip.d.ts.map +1 -0
  14. package/dist/collab-ui/AgentPresenceChip.js +42 -0
  15. package/dist/collab-ui/AgentPresenceChip.js.map +1 -0
  16. package/dist/collab-ui/LiveCursorOverlay.d.ts +17 -0
  17. package/dist/collab-ui/LiveCursorOverlay.d.ts.map +1 -0
  18. package/dist/collab-ui/LiveCursorOverlay.js +108 -0
  19. package/dist/collab-ui/LiveCursorOverlay.js.map +1 -0
  20. package/dist/collab-ui/PresenceBar.d.ts +17 -0
  21. package/dist/collab-ui/PresenceBar.d.ts.map +1 -0
  22. package/dist/collab-ui/PresenceBar.js +173 -0
  23. package/dist/collab-ui/PresenceBar.js.map +1 -0
  24. package/dist/collab-ui/RecentEditHighlights.d.ts +12 -0
  25. package/dist/collab-ui/RecentEditHighlights.d.ts.map +1 -0
  26. package/dist/collab-ui/RecentEditHighlights.js +128 -0
  27. package/dist/collab-ui/RecentEditHighlights.js.map +1 -0
  28. package/dist/collab-ui/RemoteSelectionRings.d.ts +15 -0
  29. package/dist/collab-ui/RemoteSelectionRings.d.ts.map +1 -0
  30. package/dist/collab-ui/RemoteSelectionRings.js +108 -0
  31. package/dist/collab-ui/RemoteSelectionRings.js.map +1 -0
  32. package/dist/collab-ui/agent-identity.d.ts +9 -0
  33. package/dist/collab-ui/agent-identity.d.ts.map +1 -0
  34. package/dist/collab-ui/agent-identity.js +8 -0
  35. package/dist/collab-ui/agent-identity.js.map +1 -0
  36. package/dist/collab-ui/index.d.ts +9 -0
  37. package/dist/collab-ui/index.d.ts.map +1 -0
  38. package/dist/collab-ui/index.js +9 -0
  39. package/dist/collab-ui/index.js.map +1 -0
  40. package/dist/collab-ui/lead-client.d.ts +3 -0
  41. package/dist/collab-ui/lead-client.d.ts.map +1 -0
  42. package/dist/collab-ui/lead-client.js +32 -0
  43. package/dist/collab-ui/lead-client.js.map +1 -0
  44. package/dist/collab-ui/types.d.ts +48 -0
  45. package/dist/collab-ui/types.d.ts.map +1 -0
  46. package/dist/collab-ui/types.js +52 -0
  47. package/dist/collab-ui/types.js.map +1 -0
  48. package/dist/design-system/components.d.ts +58 -0
  49. package/dist/design-system/components.d.ts.map +1 -0
  50. package/dist/design-system/components.js +79 -0
  51. package/dist/design-system/components.js.map +1 -0
  52. package/dist/design-system/context.d.ts +11 -0
  53. package/dist/design-system/context.d.ts.map +1 -0
  54. package/dist/design-system/context.js +17 -0
  55. package/dist/design-system/context.js.map +1 -0
  56. package/dist/design-system/default-adapter.d.ts +3 -0
  57. package/dist/design-system/default-adapter.d.ts.map +1 -0
  58. package/dist/design-system/default-adapter.js +229 -0
  59. package/dist/design-system/default-adapter.js.map +1 -0
  60. package/dist/design-system/definition.d.ts +9 -0
  61. package/dist/design-system/definition.d.ts.map +1 -0
  62. package/dist/design-system/definition.js +4 -0
  63. package/dist/design-system/definition.js.map +1 -0
  64. package/dist/design-system/error-boundary.d.ts +18 -0
  65. package/dist/design-system/error-boundary.d.ts.map +1 -0
  66. package/dist/design-system/error-boundary.js +16 -0
  67. package/dist/design-system/error-boundary.js.map +1 -0
  68. package/dist/design-system/index.d.ts +8 -0
  69. package/dist/design-system/index.d.ts.map +1 -0
  70. package/dist/design-system/index.js +8 -0
  71. package/dist/design-system/index.js.map +1 -0
  72. package/dist/design-system/theme.d.ts +29 -0
  73. package/dist/design-system/theme.d.ts.map +1 -0
  74. package/dist/design-system/theme.js +95 -0
  75. package/dist/design-system/theme.js.map +1 -0
  76. package/dist/design-system/types.d.ts +288 -0
  77. package/dist/design-system/types.d.ts.map +1 -0
  78. package/dist/design-system/types.js +2 -0
  79. package/dist/design-system/types.js.map +1 -0
  80. package/dist/editor/BubbleToolbar.d.ts +18 -0
  81. package/dist/editor/BubbleToolbar.d.ts.map +1 -0
  82. package/dist/editor/BubbleToolbar.js +160 -0
  83. package/dist/editor/BubbleToolbar.js.map +1 -0
  84. package/dist/editor/CodeBlockNode.d.ts +25 -0
  85. package/dist/editor/CodeBlockNode.d.ts.map +1 -0
  86. package/dist/editor/CodeBlockNode.js +112 -0
  87. package/dist/editor/CodeBlockNode.js.map +1 -0
  88. package/dist/editor/DragHandle.d.ts +40 -0
  89. package/dist/editor/DragHandle.d.ts.map +1 -0
  90. package/dist/editor/DragHandle.js +983 -0
  91. package/dist/editor/DragHandle.js.map +1 -0
  92. package/dist/editor/ImageExtension.d.ts +15 -0
  93. package/dist/editor/ImageExtension.d.ts.map +1 -0
  94. package/dist/editor/ImageExtension.js +182 -0
  95. package/dist/editor/ImageExtension.js.map +1 -0
  96. package/dist/editor/RegistryBlockContext.d.ts +72 -0
  97. package/dist/editor/RegistryBlockContext.d.ts.map +1 -0
  98. package/dist/editor/RegistryBlockContext.js +10 -0
  99. package/dist/editor/RegistryBlockContext.js.map +1 -0
  100. package/dist/editor/RegistryBlockNode.d.ts +36 -0
  101. package/dist/editor/RegistryBlockNode.d.ts.map +1 -0
  102. package/dist/editor/RegistryBlockNode.js +343 -0
  103. package/dist/editor/RegistryBlockNode.js.map +1 -0
  104. package/dist/editor/RichMarkdownEditor.d.ts +18 -0
  105. package/dist/editor/RichMarkdownEditor.d.ts.map +1 -0
  106. package/dist/editor/RichMarkdownEditor.js +11 -0
  107. package/dist/editor/RichMarkdownEditor.js.map +1 -0
  108. package/dist/editor/RunId.d.ts +4 -0
  109. package/dist/editor/RunId.d.ts.map +1 -0
  110. package/dist/editor/RunId.js +33 -0
  111. package/dist/editor/RunId.js.map +1 -0
  112. package/dist/editor/SharedRichEditor.d.ts +57 -0
  113. package/dist/editor/SharedRichEditor.d.ts.map +1 -0
  114. package/dist/editor/SharedRichEditor.js +155 -0
  115. package/dist/editor/SharedRichEditor.js.map +1 -0
  116. package/dist/editor/SlashCommandMenu.d.ts +25 -0
  117. package/dist/editor/SlashCommandMenu.d.ts.map +1 -0
  118. package/dist/editor/SlashCommandMenu.js +254 -0
  119. package/dist/editor/SlashCommandMenu.js.map +1 -0
  120. package/dist/editor/TaskListPaste.d.ts +4 -0
  121. package/dist/editor/TaskListPaste.d.ts.map +1 -0
  122. package/dist/editor/TaskListPaste.js +131 -0
  123. package/dist/editor/TaskListPaste.js.map +1 -0
  124. package/dist/editor/extensions.d.ts +42 -0
  125. package/dist/editor/extensions.d.ts.map +1 -0
  126. package/dist/editor/extensions.js +173 -0
  127. package/dist/editor/extensions.js.map +1 -0
  128. package/dist/editor/gfmDoc.d.ts +4 -0
  129. package/dist/editor/gfmDoc.d.ts.map +1 -0
  130. package/dist/editor/gfmDoc.js +37 -0
  131. package/dist/editor/gfmDoc.js.map +1 -0
  132. package/dist/editor/index.d.ts +17 -0
  133. package/dist/editor/index.d.ts.map +1 -0
  134. package/dist/editor/index.js +16 -0
  135. package/dist/editor/index.js.map +1 -0
  136. package/dist/editor/registrySlashCommands.d.ts +20 -0
  137. package/dist/editor/registrySlashCommands.d.ts.map +1 -0
  138. package/dist/editor/registrySlashCommands.js +40 -0
  139. package/dist/editor/registrySlashCommands.js.map +1 -0
  140. package/dist/editor/surgical-apply.d.ts +46 -0
  141. package/dist/editor/surgical-apply.d.ts.map +1 -0
  142. package/dist/editor/surgical-apply.js +286 -0
  143. package/dist/editor/surgical-apply.js.map +1 -0
  144. package/dist/editor/useCollabReconcile.d.ts +94 -0
  145. package/dist/editor/useCollabReconcile.d.ts.map +1 -0
  146. package/dist/editor/useCollabReconcile.js +879 -0
  147. package/dist/editor/useCollabReconcile.js.map +1 -0
  148. package/dist/editor.css +628 -0
  149. package/dist/fonts/OFL.txt +93 -0
  150. package/dist/fonts/inter-latin-ext-wght-normal.woff2 +0 -0
  151. package/dist/fonts/inter-latin-wght-normal.woff2 +0 -0
  152. package/dist/forms.d.ts +70 -0
  153. package/dist/forms.js +56 -0
  154. package/dist/forms.js.map +1 -0
  155. package/dist/guard.d.ts +2 -0
  156. package/dist/guard.d.ts.map +1 -0
  157. package/dist/guard.js +33 -6
  158. package/dist/guard.js.map +1 -1
  159. package/dist/hooks/index.d.ts +3 -0
  160. package/dist/hooks/index.d.ts.map +1 -0
  161. package/dist/hooks/index.js +3 -0
  162. package/dist/hooks/index.js.map +1 -0
  163. package/dist/hooks/use-mobile.d.ts +2 -0
  164. package/dist/hooks/use-mobile.d.ts.map +1 -0
  165. package/dist/hooks/use-mobile.js +16 -0
  166. package/dist/hooks/use-mobile.js.map +1 -0
  167. package/dist/hooks/use-toast.d.ts +45 -0
  168. package/dist/hooks/use-toast.d.ts.map +1 -0
  169. package/dist/hooks/use-toast.js +125 -0
  170. package/dist/hooks/use-toast.js.map +1 -0
  171. package/dist/icons/ResourceIcon.d.ts +14 -0
  172. package/dist/icons/ResourceIcon.d.ts.map +1 -0
  173. package/dist/icons/ResourceIcon.js +43 -0
  174. package/dist/icons/ResourceIcon.js.map +1 -0
  175. package/dist/icons/ResourceIconPicker.d.ts +57 -0
  176. package/dist/icons/ResourceIconPicker.d.ts.map +1 -0
  177. package/dist/icons/ResourceIconPicker.js +388 -0
  178. package/dist/icons/ResourceIconPicker.js.map +1 -0
  179. package/dist/icons/catalog.d.ts +17 -0
  180. package/dist/icons/catalog.d.ts.map +1 -0
  181. package/dist/icons/catalog.js +114 -0
  182. package/dist/icons/catalog.js.map +1 -0
  183. package/dist/icons/emoji-catalog.d.ts +12 -0
  184. package/dist/icons/emoji-catalog.d.ts.map +1 -0
  185. package/dist/icons/emoji-catalog.js +58 -0
  186. package/dist/icons/emoji-catalog.js.map +1 -0
  187. package/dist/icons/icon-colors.d.ts +3 -0
  188. package/dist/icons/icon-colors.d.ts.map +1 -0
  189. package/dist/icons/icon-colors.js +12 -0
  190. package/dist/icons/icon-colors.js.map +1 -0
  191. package/dist/icons/index.d.ts +5 -0
  192. package/dist/icons/index.d.ts.map +1 -0
  193. package/dist/icons/index.js +5 -0
  194. package/dist/icons/index.js.map +1 -0
  195. package/dist/icons/recents.d.ts +6 -0
  196. package/dist/icons/recents.d.ts.map +1 -0
  197. package/dist/icons/recents.js +23 -0
  198. package/dist/icons/recents.js.map +1 -0
  199. package/dist/icons/server.d.ts +7 -0
  200. package/dist/icons/server.d.ts.map +1 -0
  201. package/dist/icons/server.js +25 -0
  202. package/dist/icons/server.js.map +1 -0
  203. package/dist/icons/tabler-catalog-data.d.ts +31 -0
  204. package/dist/icons/tabler-catalog-data.d.ts.map +1 -0
  205. package/dist/icons/tabler-catalog-data.js +30121 -0
  206. package/dist/icons/tabler-catalog-data.js.map +1 -0
  207. package/dist/icons/tabler-chunk-loaders.d.ts +30 -0
  208. package/dist/icons/tabler-chunk-loaders.d.ts.map +1 -0
  209. package/dist/icons/tabler-chunk-loaders.js +29 -0
  210. package/dist/icons/tabler-chunk-loaders.js.map +1 -0
  211. package/dist/icons/tabler-chunks/a.d.ts +450 -0
  212. package/dist/icons/tabler-chunks/a.d.ts.map +1 -0
  213. package/dist/icons/tabler-chunks/a.js +450 -0
  214. package/dist/icons/tabler-chunks/a.js.map +1 -0
  215. package/dist/icons/tabler-chunks/b.d.ts +849 -0
  216. package/dist/icons/tabler-chunks/b.d.ts.map +1 -0
  217. package/dist/icons/tabler-chunks/b.js +849 -0
  218. package/dist/icons/tabler-chunks/b.js.map +1 -0
  219. package/dist/icons/tabler-chunks/c.d.ts +922 -0
  220. package/dist/icons/tabler-chunks/c.d.ts.map +1 -0
  221. package/dist/icons/tabler-chunks/c.js +922 -0
  222. package/dist/icons/tabler-chunks/c.js.map +1 -0
  223. package/dist/icons/tabler-chunks/d.d.ts +380 -0
  224. package/dist/icons/tabler-chunks/d.d.ts.map +1 -0
  225. package/dist/icons/tabler-chunks/d.js +380 -0
  226. package/dist/icons/tabler-chunks/d.js.map +1 -0
  227. package/dist/icons/tabler-chunks/e.d.ts +112 -0
  228. package/dist/icons/tabler-chunks/e.d.ts.map +1 -0
  229. package/dist/icons/tabler-chunks/e.js +112 -0
  230. package/dist/icons/tabler-chunks/e.js.map +1 -0
  231. package/dist/icons/tabler-chunks/f.d.ts +341 -0
  232. package/dist/icons/tabler-chunks/f.d.ts.map +1 -0
  233. package/dist/icons/tabler-chunks/f.js +341 -0
  234. package/dist/icons/tabler-chunks/f.js.map +1 -0
  235. package/dist/icons/tabler-chunks/g.d.ts +101 -0
  236. package/dist/icons/tabler-chunks/g.d.ts.map +1 -0
  237. package/dist/icons/tabler-chunks/g.js +101 -0
  238. package/dist/icons/tabler-chunks/g.js.map +1 -0
  239. package/dist/icons/tabler-chunks/h.d.ts +276 -0
  240. package/dist/icons/tabler-chunks/h.d.ts.map +1 -0
  241. package/dist/icons/tabler-chunks/h.js +276 -0
  242. package/dist/icons/tabler-chunks/h.js.map +1 -0
  243. package/dist/icons/tabler-chunks/i.d.ts +79 -0
  244. package/dist/icons/tabler-chunks/i.d.ts.map +1 -0
  245. package/dist/icons/tabler-chunks/i.js +79 -0
  246. package/dist/icons/tabler-chunks/i.js.map +1 -0
  247. package/dist/icons/tabler-chunks/j.d.ts +17 -0
  248. package/dist/icons/tabler-chunks/j.d.ts.map +1 -0
  249. package/dist/icons/tabler-chunks/j.js +17 -0
  250. package/dist/icons/tabler-chunks/j.js.map +1 -0
  251. package/dist/icons/tabler-chunks/k.d.ts +25 -0
  252. package/dist/icons/tabler-chunks/k.d.ts.map +1 -0
  253. package/dist/icons/tabler-chunks/k.js +25 -0
  254. package/dist/icons/tabler-chunks/k.js.map +1 -0
  255. package/dist/icons/tabler-chunks/l.d.ts +298 -0
  256. package/dist/icons/tabler-chunks/l.d.ts.map +1 -0
  257. package/dist/icons/tabler-chunks/l.js +298 -0
  258. package/dist/icons/tabler-chunks/l.js.map +1 -0
  259. package/dist/icons/tabler-chunks/m.d.ts +413 -0
  260. package/dist/icons/tabler-chunks/m.d.ts.map +1 -0
  261. package/dist/icons/tabler-chunks/m.js +413 -0
  262. package/dist/icons/tabler-chunks/m.js.map +1 -0
  263. package/dist/icons/tabler-chunks/n.d.ts +174 -0
  264. package/dist/icons/tabler-chunks/n.d.ts.map +1 -0
  265. package/dist/icons/tabler-chunks/n.js +174 -0
  266. package/dist/icons/tabler-chunks/n.js.map +1 -0
  267. package/dist/icons/tabler-chunks/o.d.ts +31 -0
  268. package/dist/icons/tabler-chunks/o.d.ts.map +1 -0
  269. package/dist/icons/tabler-chunks/o.js +31 -0
  270. package/dist/icons/tabler-chunks/o.js.map +1 -0
  271. package/dist/icons/tabler-chunks/p.d.ts +374 -0
  272. package/dist/icons/tabler-chunks/p.d.ts.map +1 -0
  273. package/dist/icons/tabler-chunks/p.js +374 -0
  274. package/dist/icons/tabler-chunks/p.js.map +1 -0
  275. package/dist/icons/tabler-chunks/q.d.ts +14 -0
  276. package/dist/icons/tabler-chunks/q.d.ts.map +1 -0
  277. package/dist/icons/tabler-chunks/q.js +14 -0
  278. package/dist/icons/tabler-chunks/q.js.map +1 -0
  279. package/dist/icons/tabler-chunks/r.d.ts +183 -0
  280. package/dist/icons/tabler-chunks/r.d.ts.map +1 -0
  281. package/dist/icons/tabler-chunks/r.js +183 -0
  282. package/dist/icons/tabler-chunks/r.js.map +1 -0
  283. package/dist/icons/tabler-chunks/s.d.ts +656 -0
  284. package/dist/icons/tabler-chunks/s.d.ts.map +1 -0
  285. package/dist/icons/tabler-chunks/s.js +656 -0
  286. package/dist/icons/tabler-chunks/s.js.map +1 -0
  287. package/dist/icons/tabler-chunks/t.d.ts +242 -0
  288. package/dist/icons/tabler-chunks/t.d.ts.map +1 -0
  289. package/dist/icons/tabler-chunks/t.js +242 -0
  290. package/dist/icons/tabler-chunks/t.js.map +1 -0
  291. package/dist/icons/tabler-chunks/u.d.ts +62 -0
  292. package/dist/icons/tabler-chunks/u.d.ts.map +1 -0
  293. package/dist/icons/tabler-chunks/u.js +62 -0
  294. package/dist/icons/tabler-chunks/u.js.map +1 -0
  295. package/dist/icons/tabler-chunks/v.d.ts +60 -0
  296. package/dist/icons/tabler-chunks/v.d.ts.map +1 -0
  297. package/dist/icons/tabler-chunks/v.js +60 -0
  298. package/dist/icons/tabler-chunks/v.js.map +1 -0
  299. package/dist/icons/tabler-chunks/w.d.ts +115 -0
  300. package/dist/icons/tabler-chunks/w.d.ts.map +1 -0
  301. package/dist/icons/tabler-chunks/w.js +115 -0
  302. package/dist/icons/tabler-chunks/w.js.map +1 -0
  303. package/dist/icons/tabler-chunks/x.d.ts +18 -0
  304. package/dist/icons/tabler-chunks/x.d.ts.map +1 -0
  305. package/dist/icons/tabler-chunks/x.js +18 -0
  306. package/dist/icons/tabler-chunks/x.js.map +1 -0
  307. package/dist/icons/tabler-chunks/y.d.ts +7 -0
  308. package/dist/icons/tabler-chunks/y.d.ts.map +1 -0
  309. package/dist/icons/tabler-chunks/y.js +3 -0
  310. package/dist/icons/tabler-chunks/y.js.map +1 -0
  311. package/dist/icons/tabler-chunks/z.d.ts +51 -0
  312. package/dist/icons/tabler-chunks/z.d.ts.map +1 -0
  313. package/dist/icons/tabler-chunks/z.js +51 -0
  314. package/dist/icons/tabler-chunks/z.js.map +1 -0
  315. package/dist/icons/tabler-groups.d.ts +30 -0
  316. package/dist/icons/tabler-groups.d.ts.map +1 -0
  317. package/dist/icons/tabler-groups.js +65 -0
  318. package/dist/icons/tabler-groups.js.map +1 -0
  319. package/dist/icons/types.d.ts +25 -0
  320. package/dist/icons/types.d.ts.map +1 -0
  321. package/dist/icons/types.js +2 -0
  322. package/dist/icons/types.js.map +1 -0
  323. package/dist/index.d.ts +6 -4
  324. package/dist/index.d.ts.map +1 -0
  325. package/dist/index.js +6 -4
  326. package/dist/index.js.map +1 -1
  327. package/dist/page.d.ts +19 -5
  328. package/dist/page.js +26 -8
  329. package/dist/page.js.map +1 -1
  330. package/dist/parts.d.ts +83 -0
  331. package/dist/parts.js +78 -0
  332. package/dist/parts.js.map +1 -0
  333. package/dist/provider.d.ts +15 -0
  334. package/dist/provider.d.ts.map +1 -0
  335. package/dist/provider.js +62 -0
  336. package/dist/provider.js.map +1 -0
  337. package/dist/shell.d.ts +25 -6
  338. package/dist/shell.js +96 -10
  339. package/dist/shell.js.map +1 -1
  340. package/dist/styles.css +344 -652
  341. package/dist/suite/controls.d.ts +8 -0
  342. package/dist/suite/controls.d.ts.map +1 -0
  343. package/dist/suite/controls.js +12 -0
  344. package/dist/suite/controls.js.map +1 -0
  345. package/dist/suite/due-picker.d.ts +24 -0
  346. package/dist/suite/due-picker.d.ts.map +1 -0
  347. package/dist/suite/due-picker.js +100 -0
  348. package/dist/suite/due-picker.js.map +1 -0
  349. package/dist/suite/due.d.ts +6 -0
  350. package/dist/suite/due.d.ts.map +1 -0
  351. package/dist/suite/due.js +58 -0
  352. package/dist/suite/due.js.map +1 -0
  353. package/dist/suite/emoji.d.ts +34 -0
  354. package/dist/suite/emoji.d.ts.map +1 -0
  355. package/dist/suite/emoji.js +643 -0
  356. package/dist/suite/emoji.js.map +1 -0
  357. package/dist/suite/files.d.ts +29 -0
  358. package/dist/suite/files.d.ts.map +1 -0
  359. package/dist/suite/files.js +46 -0
  360. package/dist/suite/files.js.map +1 -0
  361. package/dist/suite/forms.d.ts +32 -0
  362. package/dist/suite/forms.d.ts.map +1 -0
  363. package/dist/suite/forms.js +29 -0
  364. package/dist/suite/forms.js.map +1 -0
  365. package/dist/suite/index.d.ts +16 -0
  366. package/dist/suite/index.d.ts.map +1 -0
  367. package/dist/suite/index.js +18 -0
  368. package/dist/suite/index.js.map +1 -0
  369. package/dist/suite/link.d.ts +23 -0
  370. package/dist/suite/link.d.ts.map +1 -0
  371. package/dist/suite/link.js +45 -0
  372. package/dist/suite/link.js.map +1 -0
  373. package/dist/suite/links.d.ts +25 -0
  374. package/dist/suite/links.d.ts.map +1 -0
  375. package/dist/suite/links.js +69 -0
  376. package/dist/suite/links.js.map +1 -0
  377. package/dist/suite/markdown.d.ts +6 -0
  378. package/dist/suite/markdown.d.ts.map +1 -0
  379. package/dist/suite/markdown.js +64 -0
  380. package/dist/suite/markdown.js.map +1 -0
  381. package/dist/suite/page.d.ts +99 -0
  382. package/dist/suite/page.d.ts.map +1 -0
  383. package/dist/suite/page.js +92 -0
  384. package/dist/suite/page.js.map +1 -0
  385. package/dist/suite/parts.d.ts +67 -0
  386. package/dist/suite/parts.d.ts.map +1 -0
  387. package/dist/suite/parts.js +68 -0
  388. package/dist/suite/parts.js.map +1 -0
  389. package/dist/suite/pickers.d.ts +40 -0
  390. package/dist/suite/pickers.d.ts.map +1 -0
  391. package/dist/suite/pickers.js +87 -0
  392. package/dist/suite/pickers.js.map +1 -0
  393. package/dist/suite/project-appearance.d.ts +7 -0
  394. package/dist/suite/project-appearance.d.ts.map +1 -0
  395. package/dist/suite/project-appearance.js +45 -0
  396. package/dist/suite/project-appearance.js.map +1 -0
  397. package/dist/suite/project-icon.d.ts +26 -0
  398. package/dist/suite/project-icon.d.ts.map +1 -0
  399. package/dist/suite/project-icon.js +58 -0
  400. package/dist/suite/project-icon.js.map +1 -0
  401. package/dist/suite/shell.d.ts +89 -0
  402. package/dist/suite/shell.d.ts.map +1 -0
  403. package/dist/suite/shell.js +156 -0
  404. package/dist/suite/shell.js.map +1 -0
  405. package/dist/suite/suite.css +1146 -0
  406. package/dist/suite/views.d.ts +30 -0
  407. package/dist/suite/views.d.ts.map +1 -0
  408. package/dist/suite/views.js +20 -0
  409. package/dist/suite/views.js.map +1 -0
  410. package/dist/theme/resource-icons.css +23 -0
  411. package/dist/theme/suite-theme.css +97 -0
  412. package/dist/ui/accordion.d.ts +8 -0
  413. package/dist/ui/accordion.d.ts.map +1 -0
  414. package/dist/ui/accordion.js +14 -0
  415. package/dist/ui/accordion.js.map +1 -0
  416. package/dist/ui/alert-dialog.d.ts +24 -0
  417. package/dist/ui/alert-dialog.d.ts.map +1 -0
  418. package/dist/ui/alert-dialog.js +31 -0
  419. package/dist/ui/alert-dialog.js.map +1 -0
  420. package/dist/ui/alert.d.ts +9 -0
  421. package/dist/ui/alert.d.ts.map +1 -0
  422. package/dist/ui/alert.js +23 -0
  423. package/dist/ui/alert.js.map +1 -0
  424. package/dist/ui/aspect-ratio.d.ts +4 -0
  425. package/dist/ui/aspect-ratio.d.ts.map +1 -0
  426. package/dist/ui/aspect-ratio.js +4 -0
  427. package/dist/ui/aspect-ratio.js.map +1 -0
  428. package/dist/ui/avatar.d.ts +7 -0
  429. package/dist/ui/avatar.d.ts.map +1 -0
  430. package/dist/ui/avatar.js +12 -0
  431. package/dist/ui/avatar.js.map +1 -0
  432. package/dist/ui/badge.d.ts +10 -0
  433. package/dist/ui/badge.d.ts.map +1 -0
  434. package/dist/ui/badge.js +21 -0
  435. package/dist/ui/badge.js.map +1 -0
  436. package/dist/ui/breadcrumb.d.ts +20 -0
  437. package/dist/ui/breadcrumb.d.ts.map +1 -0
  438. package/dist/ui/breadcrumb.js +24 -0
  439. package/dist/ui/breadcrumb.js.map +1 -0
  440. package/dist/ui/button-group.d.ts +15 -0
  441. package/dist/ui/button-group.d.ts.map +1 -0
  442. package/dist/ui/button-group.js +30 -0
  443. package/dist/ui/button-group.js.map +1 -0
  444. package/dist/ui/button.d.ts +17 -0
  445. package/dist/ui/button.d.ts.map +1 -0
  446. package/dist/ui/button.js +89 -0
  447. package/dist/ui/button.js.map +1 -0
  448. package/dist/ui/calendar.d.ts +9 -0
  449. package/dist/ui/calendar.d.ts.map +1 -0
  450. package/dist/ui/calendar.js +74 -0
  451. package/dist/ui/calendar.js.map +1 -0
  452. package/dist/ui/card.d.ts +9 -0
  453. package/dist/ui/card.d.ts.map +1 -0
  454. package/dist/ui/card.js +17 -0
  455. package/dist/ui/card.js.map +1 -0
  456. package/dist/ui/carousel.d.ts +19 -0
  457. package/dist/ui/carousel.d.ts.map +1 -0
  458. package/dist/ui/carousel.js +99 -0
  459. package/dist/ui/carousel.js.map +1 -0
  460. package/dist/ui/chart.d.ts +80 -0
  461. package/dist/ui/chart.d.ts.map +1 -0
  462. package/dist/ui/chart.js +129 -0
  463. package/dist/ui/chart.js.map +1 -0
  464. package/dist/ui/checkbox.d.ts +5 -0
  465. package/dist/ui/checkbox.d.ts.map +1 -0
  466. package/dist/ui/checkbox.js +9 -0
  467. package/dist/ui/checkbox.js.map +1 -0
  468. package/dist/ui/collapsible.d.ts +6 -0
  469. package/dist/ui/collapsible.d.ts.map +1 -0
  470. package/dist/ui/collapsible.js +6 -0
  471. package/dist/ui/collapsible.js.map +1 -0
  472. package/dist/ui/command.d.ts +90 -0
  473. package/dist/ui/command.d.ts.map +1 -0
  474. package/dist/ui/command.js +35 -0
  475. package/dist/ui/command.js.map +1 -0
  476. package/dist/ui/context-menu.d.ts +28 -0
  477. package/dist/ui/context-menu.d.ts.map +1 -0
  478. package/dist/ui/context-menu.js +34 -0
  479. package/dist/ui/context-menu.js.map +1 -0
  480. package/dist/ui/cube-loader.d.ts +8 -0
  481. package/dist/ui/cube-loader.d.ts.map +1 -0
  482. package/dist/ui/cube-loader.js +45 -0
  483. package/dist/ui/cube-loader.js.map +1 -0
  484. package/dist/ui/date-picker.d.ts +9 -0
  485. package/dist/ui/date-picker.d.ts.map +1 -0
  486. package/dist/ui/date-picker.js +20 -0
  487. package/dist/ui/date-picker.js.map +1 -0
  488. package/dist/ui/dialog.d.ts +32 -0
  489. package/dist/ui/dialog.d.ts.map +1 -0
  490. package/dist/ui/dialog.js +26 -0
  491. package/dist/ui/dialog.js.map +1 -0
  492. package/dist/ui/drawer.d.ts +35 -0
  493. package/dist/ui/drawer.d.ts.map +1 -0
  494. package/dist/ui/drawer.js +25 -0
  495. package/dist/ui/drawer.js.map +1 -0
  496. package/dist/ui/dropdown-menu.d.ts +34 -0
  497. package/dist/ui/dropdown-menu.d.ts.map +1 -0
  498. package/dist/ui/dropdown-menu.js +42 -0
  499. package/dist/ui/dropdown-menu.js.map +1 -0
  500. package/dist/ui/empty.d.ts +13 -0
  501. package/dist/ui/empty.d.ts.map +1 -0
  502. package/dist/ui/empty.js +34 -0
  503. package/dist/ui/empty.js.map +1 -0
  504. package/dist/ui/filter-trigger.d.ts +9 -0
  505. package/dist/ui/filter-trigger.d.ts.map +1 -0
  506. package/dist/ui/filter-trigger.js +6 -0
  507. package/dist/ui/filter-trigger.js.map +1 -0
  508. package/dist/ui/form.d.ts +26 -0
  509. package/dist/ui/form.d.ts.map +1 -0
  510. package/dist/ui/form.js +63 -0
  511. package/dist/ui/form.js.map +1 -0
  512. package/dist/ui/hover-card.d.ts +7 -0
  513. package/dist/ui/hover-card.d.ts.map +1 -0
  514. package/dist/ui/hover-card.js +10 -0
  515. package/dist/ui/hover-card.js.map +1 -0
  516. package/dist/ui/index.d.ts +60 -0
  517. package/dist/ui/index.d.ts.map +1 -0
  518. package/dist/ui/index.js +60 -0
  519. package/dist/ui/index.js.map +1 -0
  520. package/dist/ui/input-group.d.ts +21 -0
  521. package/dist/ui/input-group.d.ts.map +1 -0
  522. package/dist/ui/input-group.js +59 -0
  523. package/dist/ui/input-group.js.map +1 -0
  524. package/dist/ui/input-otp.d.ts +37 -0
  525. package/dist/ui/input-otp.d.ts.map +1 -0
  526. package/dist/ui/input-otp.js +19 -0
  527. package/dist/ui/input-otp.js.map +1 -0
  528. package/dist/ui/input.d.ts +7 -0
  529. package/dist/ui/input.d.ts.map +1 -0
  530. package/dist/ui/input.js +9 -0
  531. package/dist/ui/input.js.map +1 -0
  532. package/dist/ui/item.d.ts +24 -0
  533. package/dist/ui/item.d.ts.map +1 -0
  534. package/dist/ui/item.js +67 -0
  535. package/dist/ui/item.js.map +1 -0
  536. package/dist/ui/kbd.d.ts +5 -0
  537. package/dist/ui/kbd.d.ts.map +1 -0
  538. package/dist/ui/kbd.js +10 -0
  539. package/dist/ui/kbd.js.map +1 -0
  540. package/dist/ui/label.d.ts +6 -0
  541. package/dist/ui/label.d.ts.map +1 -0
  542. package/dist/ui/label.js +10 -0
  543. package/dist/ui/label.js.map +1 -0
  544. package/dist/ui/logo.d.ts +7 -0
  545. package/dist/ui/logo.d.ts.map +1 -0
  546. package/dist/ui/logo.js +9 -0
  547. package/dist/ui/logo.js.map +1 -0
  548. package/dist/ui/menubar.d.ts +29 -0
  549. package/dist/ui/menubar.d.ts.map +1 -0
  550. package/dist/ui/menubar.js +36 -0
  551. package/dist/ui/menubar.js.map +1 -0
  552. package/dist/ui/navigation-menu.d.ts +13 -0
  553. package/dist/ui/navigation-menu.d.ts.map +1 -0
  554. package/dist/ui/navigation-menu.js +25 -0
  555. package/dist/ui/navigation-menu.js.map +1 -0
  556. package/dist/ui/pagination.d.ts +29 -0
  557. package/dist/ui/pagination.d.ts.map +1 -0
  558. package/dist/ui/pagination.js +24 -0
  559. package/dist/ui/pagination.js.map +1 -0
  560. package/dist/ui/pointer-lock.d.ts +2 -0
  561. package/dist/ui/pointer-lock.d.ts.map +1 -0
  562. package/dist/ui/pointer-lock.js +11 -0
  563. package/dist/ui/pointer-lock.js.map +1 -0
  564. package/dist/ui/popover.d.ts +11 -0
  565. package/dist/ui/popover.d.ts.map +1 -0
  566. package/dist/ui/popover.js +16 -0
  567. package/dist/ui/popover.js.map +1 -0
  568. package/dist/ui/progress.d.ts +5 -0
  569. package/dist/ui/progress.d.ts.map +1 -0
  570. package/dist/ui/progress.js +16 -0
  571. package/dist/ui/progress.js.map +1 -0
  572. package/dist/ui/radio-group.d.ts +6 -0
  573. package/dist/ui/radio-group.d.ts.map +1 -0
  574. package/dist/ui/radio-group.js +15 -0
  575. package/dist/ui/radio-group.js.map +1 -0
  576. package/dist/ui/resizable.d.ts +10 -0
  577. package/dist/ui/resizable.d.ts.map +1 -0
  578. package/dist/ui/resizable.js +9 -0
  579. package/dist/ui/resizable.js.map +1 -0
  580. package/dist/ui/scroll-area.d.ts +6 -0
  581. package/dist/ui/scroll-area.d.ts.map +1 -0
  582. package/dist/ui/scroll-area.js +12 -0
  583. package/dist/ui/scroll-area.js.map +1 -0
  584. package/dist/ui/select.d.ts +18 -0
  585. package/dist/ui/select.d.ts.map +1 -0
  586. package/dist/ui/select.js +27 -0
  587. package/dist/ui/select.js.map +1 -0
  588. package/dist/ui/separator.d.ts +5 -0
  589. package/dist/ui/separator.d.ts.map +1 -0
  590. package/dist/ui/separator.js +8 -0
  591. package/dist/ui/separator.js.map +1 -0
  592. package/dist/ui/sheet.d.ts +29 -0
  593. package/dist/ui/sheet.d.ts.map +1 -0
  594. package/dist/ui/sheet.js +37 -0
  595. package/dist/ui/sheet.js.map +1 -0
  596. package/dist/ui/sidebar.d.ts +73 -0
  597. package/dist/ui/sidebar.d.ts.map +1 -0
  598. package/dist/ui/sidebar.js +216 -0
  599. package/dist/ui/sidebar.js.map +1 -0
  600. package/dist/ui/skeleton.d.ts +3 -0
  601. package/dist/ui/skeleton.d.ts.map +1 -0
  602. package/dist/ui/skeleton.js +7 -0
  603. package/dist/ui/skeleton.js.map +1 -0
  604. package/dist/ui/slider.d.ts +5 -0
  605. package/dist/ui/slider.d.ts.map +1 -0
  606. package/dist/ui/slider.js +16 -0
  607. package/dist/ui/slider.js.map +1 -0
  608. package/dist/ui/sonner.d.ts +5 -0
  609. package/dist/ui/sonner.d.ts.map +1 -0
  610. package/dist/ui/sonner.js +25 -0
  611. package/dist/ui/sonner.js.map +1 -0
  612. package/dist/ui/spinner.d.ts +3 -0
  613. package/dist/ui/spinner.d.ts.map +1 -0
  614. package/dist/ui/spinner.js +6 -0
  615. package/dist/ui/spinner.js.map +1 -0
  616. package/dist/ui/switch.d.ts +7 -0
  617. package/dist/ui/switch.d.ts.map +1 -0
  618. package/dist/ui/switch.js +8 -0
  619. package/dist/ui/switch.js.map +1 -0
  620. package/dist/ui/table.d.ts +11 -0
  621. package/dist/ui/table.d.ts.map +1 -0
  622. package/dist/ui/table.js +21 -0
  623. package/dist/ui/table.js.map +1 -0
  624. package/dist/ui/tabs.d.ts +8 -0
  625. package/dist/ui/tabs.d.ts.map +1 -0
  626. package/dist/ui/tabs.js +13 -0
  627. package/dist/ui/tabs.js.map +1 -0
  628. package/dist/ui/textarea.d.ts +6 -0
  629. package/dist/ui/textarea.d.ts.map +1 -0
  630. package/dist/ui/textarea.js +9 -0
  631. package/dist/ui/textarea.js.map +1 -0
  632. package/dist/ui/toast.d.ts +16 -0
  633. package/dist/ui/toast.d.ts.map +1 -0
  634. package/dist/ui/toast.js +34 -0
  635. package/dist/ui/toast.js.map +1 -0
  636. package/dist/ui/toaster.d.ts +2 -0
  637. package/dist/ui/toaster.d.ts.map +1 -0
  638. package/dist/ui/toaster.js +10 -0
  639. package/dist/ui/toaster.js.map +1 -0
  640. package/dist/ui/toggle-group.d.ts +13 -0
  641. package/dist/ui/toggle-group.d.ts.map +1 -0
  642. package/dist/ui/toggle-group.js +21 -0
  643. package/dist/ui/toggle-group.js.map +1 -0
  644. package/dist/ui/toggle.d.ts +13 -0
  645. package/dist/ui/toggle.d.ts.map +1 -0
  646. package/dist/ui/toggle.js +26 -0
  647. package/dist/ui/toggle.js.map +1 -0
  648. package/dist/ui/tooltip.d.ts +11 -0
  649. package/dist/ui/tooltip.d.ts.map +1 -0
  650. package/dist/ui/tooltip.js +18 -0
  651. package/dist/ui/tooltip.js.map +1 -0
  652. package/dist/ui/use-toast.d.ts +3 -0
  653. package/dist/ui/use-toast.d.ts.map +1 -0
  654. package/dist/ui/use-toast.js +3 -0
  655. package/dist/ui/use-toast.js.map +1 -0
  656. package/dist/utils.d.ts +4 -0
  657. package/dist/utils.d.ts.map +1 -0
  658. package/dist/utils.js +7 -0
  659. package/dist/utils.js.map +1 -0
  660. package/package.json +186 -14
  661. package/skills/ux-flow/SKILL.md +6 -3
@@ -0,0 +1,879 @@
1
+ import { isChangeOrigin } from "@tiptap/extension-collaboration";
2
+ import { ySyncPluginKey } from "@tiptap/y-tiptap";
3
+ import { useEffect, useRef, useState } from "react";
4
+ import { applyUpdate } from "yjs";
5
+ import { AGENT_CLIENT_ID, isReconcileLeadClient } from "../collab-ui/index.js";
6
+ import { RICH_MARKDOWN_PROGRAMMATIC_TRANSACTION, applyDocSurgically, defaultParseValue, reconcileDocAgainstBase, } from "./surgical-apply.js";
7
+ export { RICH_MARKDOWN_PROGRAMMATIC_TRANSACTION };
8
+ export function isRemoteCollaborativeTransaction(transaction) {
9
+ return (isChangeOrigin(transaction) &&
10
+ !transaction.getMeta(ySyncPluginKey)?.isUndoRedoOperation);
11
+ }
12
+ export function applyAuthoritativeInitialSeed(ydoc, state, initialNodes) {
13
+ const fragment = ydoc.getXmlFragment("default");
14
+ ydoc.transact(() => {
15
+ for (const { node, serialized } of initialNodes) {
16
+ if (node.toString() !== serialized)
17
+ continue;
18
+ const index = fragment.toArray().indexOf(node);
19
+ if (index !== -1)
20
+ fragment.delete(index, 1);
21
+ }
22
+ applyUpdate(ydoc, state, "authoritative-initial-seed");
23
+ }, "authoritative-initial-seed");
24
+ }
25
+ export function getEditorMarkdown(editor) {
26
+ const markdownStorage = editor.storage;
27
+ return markdownStorage.markdown?.getMarkdown?.() ?? "";
28
+ }
29
+ const EMITTED_RING_MAX = 16;
30
+ const PEER_SETTLE_MS = 2500;
31
+ // A non-lead client leaves a newer snapshot to the lead; if the lead has not
32
+ // converged the doc by then (it never refetched), adopt it rather than keep a
33
+ // Yjs doc that disagrees with SQL until the next reload drops unsaved text.
34
+ const LEAD_FAILOVER_MS = PEER_SETTLE_MS * 2;
35
+ const CATCH_UP_ATTEMPTS = 3;
36
+ const CATCH_UP_RETRY_MS = 2000;
37
+ function pushEmittedRing(ring, value) {
38
+ if (!value)
39
+ return;
40
+ if (ring[ring.length - 1] === value)
41
+ return;
42
+ const dupe = ring.indexOf(value);
43
+ if (dupe !== -1)
44
+ ring.splice(dupe, 1);
45
+ ring.push(value);
46
+ if (ring.length > EMITTED_RING_MAX)
47
+ ring.shift();
48
+ }
49
+ function defaultShouldSeed({ currentMarkdown, fragmentLength, }) {
50
+ return fragmentLength === 0 || !currentMarkdown.trim();
51
+ }
52
+ function defaultSetContent(editor, value, options) {
53
+ if (options.addToHistory === false) {
54
+ editor
55
+ .chain()
56
+ .command(({ tr }) => {
57
+ tr.setMeta("addToHistory", false);
58
+ return true;
59
+ })
60
+ .setContent(value, { emitUpdate: options.emitUpdate })
61
+ .run();
62
+ return;
63
+ }
64
+ editor.commands.setContent(value);
65
+ }
66
+ function defaultIsEditorFocused(editor) {
67
+ return editor.isFocused;
68
+ }
69
+ export function useCollabReconcile({ editor, ydoc = null, collabSynced = true, awareness = null, value, contentUpdatedAt, contentRevision, compareContentRevisions, acknowledgedLocalSnapshot, collabContentRevision, requestCollabSync, onBaseAwareReconcile, onRemoteSnapshotChange, requestInitialSeed, quietSeedEditability = false, onInitialSeedError, overlapPolicy = "conflict", editable, isEditorFocused = defaultIsEditorFocused, getMarkdown = getEditorMarkdown, isEditorClean, setContent = defaultSetContent, parseValue, normalizeValue = (v) => v, shouldSeed = defaultShouldSeed, initialAppliedUpdatedAt, }) {
70
+ const collab = !!ydoc;
71
+ const collabBackedSnapshot = Boolean(collab && contentRevision && collabContentRevision === contentRevision);
72
+ const isSettingContentRef = useRef(false);
73
+ const lastEmittedRef = useRef("");
74
+ const lastRegisteredLocalEmissionRef = useRef(null);
75
+ const recentEmittedRef = useRef([]);
76
+ const lastTypedAtRef = useRef(0);
77
+ const lastAppliedValueRef = useRef(null);
78
+ const lastAppliedSerializedRef = useRef(null);
79
+ const lastAppliedUpdatedAtRef = useRef(initialAppliedUpdatedAt !== undefined
80
+ ? initialAppliedUpdatedAt
81
+ : (contentUpdatedAt ?? null));
82
+ const authoritativeBaseRef = useRef(contentRevision ? { value, revision: contentRevision } : null);
83
+ const reportedConflictRevisionRef = useRef(null);
84
+ const reconcileCallbacksRef = useRef({
85
+ getMarkdown,
86
+ setContent,
87
+ parseValue,
88
+ normalizeValue,
89
+ isEditorFocused,
90
+ isEditorClean,
91
+ onBaseAwareReconcile,
92
+ onRemoteSnapshotChange,
93
+ });
94
+ reconcileCallbacksRef.current = {
95
+ getMarkdown,
96
+ setContent,
97
+ parseValue,
98
+ normalizeValue,
99
+ isEditorFocused,
100
+ isEditorClean,
101
+ onBaseAwareReconcile,
102
+ onRemoteSnapshotChange,
103
+ };
104
+ const acknowledgedLocalSnapshotRef = useRef(null);
105
+ const latestObservedUpdatedAtRef = useRef(contentUpdatedAt ?? null);
106
+ const latestObservedRevisionRef = useRef(contentRevision ?? null);
107
+ const acknowledgementBaseRollbackRef = useRef(null);
108
+ const acknowledgedCollabRef = useRef(null);
109
+ const [pendingCollabSnapshot, setPendingCollabSnapshot] = useState(null);
110
+ useEffect(() => {
111
+ if (!collabBackedSnapshot || !ydoc || !contentRevision)
112
+ return;
113
+ if (acknowledgedCollabRef.current?.ydoc === ydoc &&
114
+ acknowledgedCollabRef.current.revision === contentRevision)
115
+ return;
116
+ setPendingCollabSnapshot((pending) => pending?.ydoc === ydoc && pending.revision === contentRevision
117
+ ? pending
118
+ : {
119
+ ydoc,
120
+ revision: contentRevision,
121
+ value,
122
+ updatedAt: contentUpdatedAt,
123
+ });
124
+ }, [collabBackedSnapshot, ydoc, contentRevision, value, contentUpdatedAt]);
125
+ useEffect(() => {
126
+ if (!pendingCollabSnapshot ||
127
+ !requestCollabSync ||
128
+ pendingCollabSnapshot.ydoc !== ydoc)
129
+ return;
130
+ let cancelled = false;
131
+ let retry;
132
+ const sync = async () => {
133
+ const result = await requestCollabSync().catch(() => ({
134
+ status: "failed",
135
+ }));
136
+ if (cancelled)
137
+ return;
138
+ if (result.status !== "synced") {
139
+ retry = setTimeout(() => void sync(), 2000);
140
+ return;
141
+ }
142
+ authoritativeBaseRef.current = {
143
+ value: pendingCollabSnapshot.value,
144
+ revision: pendingCollabSnapshot.revision,
145
+ };
146
+ reportedConflictRevisionRef.current = null;
147
+ if (pendingCollabSnapshot.updatedAt)
148
+ lastAppliedUpdatedAtRef.current = pendingCollabSnapshot.updatedAt;
149
+ acknowledgedCollabRef.current = pendingCollabSnapshot;
150
+ setPendingCollabSnapshot(null);
151
+ };
152
+ void sync();
153
+ return () => {
154
+ cancelled = true;
155
+ if (retry)
156
+ clearTimeout(retry);
157
+ };
158
+ }, [pendingCollabSnapshot, requestCollabSync, ydoc]);
159
+ const [isLeadClient, setIsLeadClient] = useState(true);
160
+ const seedLead = requestInitialSeed ? true : isLeadClient;
161
+ const peerCountRef = useRef(0);
162
+ const emptySnapshotDecisionPendingRef = useRef(false);
163
+ useEffect(() => {
164
+ if (!collab || !awareness || !ydoc) {
165
+ setIsLeadClient(true);
166
+ peerCountRef.current = 0;
167
+ return;
168
+ }
169
+ const update = () => {
170
+ setIsLeadClient(isReconcileLeadClient(awareness, ydoc.clientID));
171
+ let peers = 0;
172
+ awareness.getStates().forEach((state, clientId) => {
173
+ if (clientId === ydoc.clientID)
174
+ return;
175
+ if (clientId === AGENT_CLIENT_ID)
176
+ return;
177
+ const s = state;
178
+ if (s?.canFlushDocument === false)
179
+ return;
180
+ if (s && s.user && s.visible !== false)
181
+ peers += 1;
182
+ });
183
+ peerCountRef.current = peers;
184
+ };
185
+ update();
186
+ awareness.on("change", update);
187
+ document.addEventListener("visibilitychange", update);
188
+ return () => {
189
+ awareness.off("change", update);
190
+ document.removeEventListener("visibilitychange", update);
191
+ };
192
+ }, [collab, awareness, ydoc]);
193
+ const seededRef = useRef(false);
194
+ const [seeded, setSeeded] = useState(false);
195
+ const markSeeded = () => {
196
+ seededRef.current = true;
197
+ if (requestInitialSeed)
198
+ setSeeded(true);
199
+ };
200
+ const [initialSeedFailed, setInitialSeedFailed] = useState(false);
201
+ const [initialSeedRetry, setInitialSeedRetry] = useState(0);
202
+ useEffect(() => {
203
+ if (!collab || !editor || editor.isDestroyed || !ydoc)
204
+ return;
205
+ if (seededRef.current)
206
+ return;
207
+ if (!collabSynced)
208
+ return;
209
+ if (collabBackedSnapshot) {
210
+ markSeeded();
211
+ if (requestInitialSeed)
212
+ editor.setEditable(editable, !quietSeedEditability);
213
+ return;
214
+ }
215
+ if (contentRevision) {
216
+ authoritativeBaseRef.current = { value, revision: contentRevision };
217
+ reportedConflictRevisionRef.current = null;
218
+ }
219
+ if (!value.trim()) {
220
+ markSeeded();
221
+ const fragment = ydoc.getXmlFragment("default");
222
+ const currentMarkdown = getMarkdown(editor);
223
+ if (fragment.length === 0 && !currentMarkdown.trim())
224
+ return;
225
+ emptySnapshotDecisionPendingRef.current = true;
226
+ let cancelled = false;
227
+ const adoptTimer = setTimeout(() => {
228
+ if (cancelled || editor.isDestroyed)
229
+ return;
230
+ const projectedMarkdown = getMarkdown(editor);
231
+ const isOwnFreshEdit = projectedMarkdown.trim() &&
232
+ (projectedMarkdown === lastEmittedRef.current ||
233
+ recentEmittedRef.current.includes(projectedMarkdown));
234
+ if (projectedMarkdown.trim() &&
235
+ (peerCountRef.current > 0 || isOwnFreshEdit)) {
236
+ lastAppliedValueRef.current = value;
237
+ lastAppliedSerializedRef.current = projectedMarkdown;
238
+ if (contentUpdatedAt) {
239
+ lastAppliedUpdatedAtRef.current = contentUpdatedAt;
240
+ }
241
+ }
242
+ emptySnapshotDecisionPendingRef.current = false;
243
+ }, awareness ? PEER_SETTLE_MS : 0);
244
+ return () => {
245
+ cancelled = true;
246
+ clearTimeout(adoptTimer);
247
+ emptySnapshotDecisionPendingRef.current = false;
248
+ };
249
+ }
250
+ if (!seedLead) {
251
+ const releaseTimer = setTimeout(() => {
252
+ markSeeded();
253
+ }, 0);
254
+ return () => clearTimeout(releaseTimer);
255
+ }
256
+ let cancelled = false;
257
+ let retryTimer = null;
258
+ let retryDelayMs = 1000;
259
+ const seedTimer = setTimeout(() => {
260
+ if (cancelled || editor.isDestroyed)
261
+ return;
262
+ const fragment = ydoc.getXmlFragment("default");
263
+ const currentMarkdown = getMarkdown(editor);
264
+ if (!shouldSeed({
265
+ value,
266
+ currentMarkdown,
267
+ fragmentLength: fragment.length,
268
+ })) {
269
+ markSeeded();
270
+ if (requestInitialSeed)
271
+ editor.setEditable(editable, !quietSeedEditability);
272
+ return;
273
+ }
274
+ if (requestInitialSeed) {
275
+ editor.setEditable(false, !quietSeedEditability);
276
+ const initialNodes = fragment.toArray().map((node) => ({
277
+ node,
278
+ serialized: node.toString(),
279
+ }));
280
+ const claim = () => {
281
+ void requestInitialSeed(editor, value)
282
+ .then((state) => {
283
+ if (cancelled || editor.isDestroyed)
284
+ return;
285
+ isSettingContentRef.current = true;
286
+ try {
287
+ applyAuthoritativeInitialSeed(ydoc, state, initialNodes);
288
+ }
289
+ finally {
290
+ isSettingContentRef.current = false;
291
+ }
292
+ const serialized = getMarkdown(editor);
293
+ lastEmittedRef.current = serialized;
294
+ pushEmittedRing(recentEmittedRef.current, serialized);
295
+ lastAppliedValueRef.current = value;
296
+ lastAppliedSerializedRef.current = serialized;
297
+ if (contentUpdatedAt)
298
+ lastAppliedUpdatedAtRef.current = contentUpdatedAt;
299
+ markSeeded();
300
+ setInitialSeedFailed(false);
301
+ editor.setEditable(editable, !quietSeedEditability);
302
+ })
303
+ .catch((error) => {
304
+ if (cancelled || editor.isDestroyed)
305
+ return;
306
+ onInitialSeedError?.(error);
307
+ const status = error && typeof error === "object" && "status" in error
308
+ ? error.status
309
+ : undefined;
310
+ if (typeof status === "number" &&
311
+ status >= 400 &&
312
+ status < 500 &&
313
+ status !== 408 &&
314
+ status !== 429) {
315
+ setInitialSeedFailed(true);
316
+ return;
317
+ }
318
+ retryTimer = setTimeout(claim, retryDelayMs);
319
+ retryDelayMs = Math.min(retryDelayMs * 2, 8000);
320
+ });
321
+ };
322
+ claim();
323
+ return;
324
+ }
325
+ isSettingContentRef.current = true;
326
+ try {
327
+ setContent(editor, value, {});
328
+ }
329
+ finally {
330
+ isSettingContentRef.current = false;
331
+ }
332
+ const serialized = getMarkdown(editor);
333
+ lastEmittedRef.current = serialized;
334
+ pushEmittedRing(recentEmittedRef.current, serialized);
335
+ lastAppliedValueRef.current = value;
336
+ lastAppliedSerializedRef.current = serialized;
337
+ if (contentUpdatedAt)
338
+ lastAppliedUpdatedAtRef.current = contentUpdatedAt;
339
+ markSeeded();
340
+ }, 0);
341
+ return () => {
342
+ cancelled = true;
343
+ clearTimeout(seedTimer);
344
+ if (retryTimer)
345
+ clearTimeout(retryTimer);
346
+ if (requestInitialSeed && !editor.isDestroyed)
347
+ editor.setEditable(editable, !quietSeedEditability);
348
+ };
349
+ }, [
350
+ collab,
351
+ collabSynced,
352
+ editor,
353
+ ydoc,
354
+ value,
355
+ seedLead,
356
+ requestInitialSeed,
357
+ onInitialSeedError,
358
+ editable,
359
+ contentUpdatedAt,
360
+ contentRevision,
361
+ getMarkdown,
362
+ setContent,
363
+ shouldSeed,
364
+ collabBackedSnapshot,
365
+ initialSeedRetry,
366
+ ]);
367
+ const syncedBeforeAdoptRef = useRef(null);
368
+ const peerReconcileWaitRef = useRef(null);
369
+ useEffect(() => {
370
+ if (!editor || editor.isDestroyed) {
371
+ peerReconcileWaitRef.current = null;
372
+ return;
373
+ }
374
+ const previousWait = peerReconcileWaitRef.current;
375
+ if (!previousWait ||
376
+ previousWait.editor !== editor ||
377
+ previousWait.ydoc !== ydoc ||
378
+ previousWait.value !== value ||
379
+ previousWait.contentUpdatedAt !== contentUpdatedAt ||
380
+ previousWait.contentRevision !== contentRevision ||
381
+ previousWait.collabSynced !== collabSynced ||
382
+ previousWait.isLeadClient !== isLeadClient ||
383
+ previousWait.editable !== editable) {
384
+ peerReconcileWaitRef.current = {
385
+ editor,
386
+ ydoc,
387
+ value,
388
+ contentUpdatedAt,
389
+ contentRevision,
390
+ collabSynced,
391
+ isLeadClient,
392
+ editable,
393
+ deadline: null,
394
+ leadDeadline: null,
395
+ catchUpFailures: 0,
396
+ };
397
+ }
398
+ const peerWait = peerReconcileWaitRef.current;
399
+ let cancelled = false;
400
+ let retry = null;
401
+ const apply = (deferred = false) => {
402
+ if (cancelled || editor.isDestroyed)
403
+ return;
404
+ const callbacks = reconcileCallbacksRef.current;
405
+ if (contentUpdatedAt) {
406
+ const rollback = acknowledgementBaseRollbackRef.current;
407
+ const conflictsWithAcceptedAcknowledgement = contentRevision &&
408
+ rollback?.updatedAt === contentUpdatedAt &&
409
+ rollback.acknowledgementRevision !== contentRevision;
410
+ if (conflictsWithAcceptedAcknowledgement) {
411
+ const order = compareContentRevisions?.(contentRevision, rollback.acknowledgementRevision);
412
+ if (order !== undefined && order !== null && order <= 0) {
413
+ return;
414
+ }
415
+ if (authoritativeBaseRef.current?.revision ===
416
+ rollback.acknowledgementRevision) {
417
+ authoritativeBaseRef.current = rollback.base;
418
+ }
419
+ acknowledgementBaseRollbackRef.current = null;
420
+ latestObservedUpdatedAtRef.current = contentUpdatedAt;
421
+ latestObservedRevisionRef.current = contentRevision;
422
+ }
423
+ else if (!latestObservedUpdatedAtRef.current ||
424
+ contentUpdatedAt > latestObservedUpdatedAtRef.current) {
425
+ latestObservedUpdatedAtRef.current = contentUpdatedAt;
426
+ latestObservedRevisionRef.current = contentRevision ?? null;
427
+ acknowledgementBaseRollbackRef.current = null;
428
+ }
429
+ else if (contentUpdatedAt === latestObservedUpdatedAtRef.current &&
430
+ contentRevision &&
431
+ latestObservedRevisionRef.current !== contentRevision) {
432
+ const order = latestObservedRevisionRef.current
433
+ ? compareContentRevisions?.(contentRevision, latestObservedRevisionRef.current)
434
+ : null;
435
+ if (order !== undefined && order !== null && order <= 0) {
436
+ return;
437
+ }
438
+ latestObservedRevisionRef.current =
439
+ order !== undefined && order !== null ? contentRevision : null;
440
+ }
441
+ }
442
+ let rejectedMatchingAcknowledgement = false;
443
+ if (acknowledgedLocalSnapshot) {
444
+ const acceptedAcknowledgement = acknowledgedLocalSnapshotRef.current;
445
+ const acknowledgementIsNewestAccepted = !acceptedAcknowledgement ||
446
+ acknowledgedLocalSnapshot.sequence > acceptedAcknowledgement.sequence;
447
+ const acknowledgementRevisionOrder = acknowledgedLocalSnapshot.updatedAt ===
448
+ latestObservedUpdatedAtRef.current &&
449
+ latestObservedRevisionRef.current
450
+ ? compareContentRevisions?.(acknowledgedLocalSnapshot.revision, latestObservedRevisionRef.current)
451
+ : null;
452
+ const acknowledgementIsNotSuperseded = !latestObservedUpdatedAtRef.current ||
453
+ acknowledgedLocalSnapshot.updatedAt >
454
+ latestObservedUpdatedAtRef.current ||
455
+ (acknowledgedLocalSnapshot.updatedAt ===
456
+ latestObservedUpdatedAtRef.current &&
457
+ (latestObservedRevisionRef.current ===
458
+ acknowledgedLocalSnapshot.revision ||
459
+ acknowledgementRevisionOrder === undefined ||
460
+ acknowledgementRevisionOrder === null ||
461
+ acknowledgementRevisionOrder >= 0));
462
+ if (acknowledgementIsNewestAccepted && acknowledgementIsNotSuperseded) {
463
+ acknowledgedLocalSnapshotRef.current = acknowledgedLocalSnapshot;
464
+ const existingRollback = acknowledgementBaseRollbackRef.current;
465
+ if (existingRollback?.acknowledgementRevision !==
466
+ acknowledgedLocalSnapshot.revision ||
467
+ existingRollback.updatedAt !== acknowledgedLocalSnapshot.updatedAt) {
468
+ acknowledgementBaseRollbackRef.current = {
469
+ acknowledgementRevision: acknowledgedLocalSnapshot.revision,
470
+ updatedAt: acknowledgedLocalSnapshot.updatedAt,
471
+ base: authoritativeBaseRef.current,
472
+ };
473
+ }
474
+ authoritativeBaseRef.current = {
475
+ value: acknowledgedLocalSnapshot.value,
476
+ revision: acknowledgedLocalSnapshot.revision,
477
+ };
478
+ if (acknowledgedLocalSnapshot.updatedAt ===
479
+ latestObservedUpdatedAtRef.current &&
480
+ acknowledgementRevisionOrder !== undefined &&
481
+ acknowledgementRevisionOrder !== null &&
482
+ acknowledgementRevisionOrder > 0) {
483
+ latestObservedRevisionRef.current =
484
+ acknowledgedLocalSnapshot.revision;
485
+ }
486
+ if (!lastAppliedUpdatedAtRef.current ||
487
+ acknowledgedLocalSnapshot.updatedAt >
488
+ lastAppliedUpdatedAtRef.current) {
489
+ lastAppliedUpdatedAtRef.current =
490
+ acknowledgedLocalSnapshot.updatedAt;
491
+ }
492
+ }
493
+ else if (contentRevision === acknowledgedLocalSnapshot.revision &&
494
+ value === acknowledgedLocalSnapshot.value) {
495
+ rejectedMatchingAcknowledgement = true;
496
+ }
497
+ }
498
+ if (rejectedMatchingAcknowledgement)
499
+ return;
500
+ const acknowledged = acknowledgedLocalSnapshotRef.current;
501
+ if (acknowledged &&
502
+ contentRevision === acknowledged.revision &&
503
+ value === acknowledged.value) {
504
+ const acknowledgementWasSuperseded = latestObservedUpdatedAtRef.current !== null &&
505
+ (acknowledged.updatedAt < latestObservedUpdatedAtRef.current ||
506
+ (acknowledged.updatedAt === latestObservedUpdatedAtRef.current &&
507
+ latestObservedRevisionRef.current !== acknowledged.revision));
508
+ if (!acknowledgementWasSuperseded) {
509
+ authoritativeBaseRef.current = {
510
+ value: acknowledged.value,
511
+ revision: acknowledged.revision,
512
+ };
513
+ if (!lastAppliedUpdatedAtRef.current ||
514
+ acknowledged.updatedAt > lastAppliedUpdatedAtRef.current) {
515
+ lastAppliedUpdatedAtRef.current = acknowledged.updatedAt;
516
+ }
517
+ reportedConflictRevisionRef.current = null;
518
+ }
519
+ return;
520
+ }
521
+ if (acknowledged &&
522
+ contentUpdatedAt &&
523
+ contentUpdatedAt < acknowledged.updatedAt) {
524
+ return;
525
+ }
526
+ if (collab && !collabSynced) {
527
+ retry = setTimeout(() => apply(deferred), 300);
528
+ return;
529
+ }
530
+ if (collab && !seededRef.current) {
531
+ retry = setTimeout(() => apply(deferred), 25);
532
+ return;
533
+ }
534
+ if (collab && emptySnapshotDecisionPendingRef.current) {
535
+ retry = setTimeout(() => apply(deferred), 50);
536
+ return;
537
+ }
538
+ if (collabBackedSnapshot ||
539
+ (collab && pendingCollabSnapshot?.ydoc === ydoc)) {
540
+ peerWait.deadline = null;
541
+ return;
542
+ }
543
+ const currentMarkdown = callbacks.getMarkdown(editor);
544
+ const normalizedValue = callbacks.normalizeValue(value);
545
+ const editorUnchangedSinceApply = lastAppliedSerializedRef.current !== null &&
546
+ currentMarkdown === lastAppliedSerializedRef.current;
547
+ const editorFocused = callbacks.isEditorFocused(editor);
548
+ const typingRecently = editorFocused && Date.now() - lastTypedAtRef.current < 1500;
549
+ if (currentMarkdown === normalizedValue ||
550
+ (typingRecently &&
551
+ !contentRevision &&
552
+ (value === lastEmittedRef.current ||
553
+ recentEmittedRef.current.includes(value) ||
554
+ recentEmittedRef.current.includes(normalizedValue))) ||
555
+ (editorUnchangedSinceApply &&
556
+ (value === lastAppliedValueRef.current ||
557
+ normalizedValue === lastAppliedSerializedRef.current))) {
558
+ peerWait.deadline = null;
559
+ if (currentMarkdown === normalizedValue) {
560
+ lastAppliedValueRef.current = value;
561
+ lastAppliedSerializedRef.current = currentMarkdown;
562
+ }
563
+ if (contentRevision) {
564
+ authoritativeBaseRef.current = { value, revision: contentRevision };
565
+ reportedConflictRevisionRef.current = null;
566
+ }
567
+ if (contentUpdatedAt) {
568
+ lastAppliedUpdatedAtRef.current = contentUpdatedAt;
569
+ }
570
+ return;
571
+ }
572
+ const revisionChangedAtSameTimestamp = !!contentRevision &&
573
+ !!authoritativeBaseRef.current &&
574
+ contentRevision !== authoritativeBaseRef.current.revision &&
575
+ !!contentUpdatedAt &&
576
+ contentUpdatedAt === lastAppliedUpdatedAtRef.current;
577
+ // A parent that derives `value` and `contentUpdatedAt` separately can
578
+ // render the new timestamp next to the old value first. That render
579
+ // marks the timestamp applied, so the new value that follows it would
580
+ // never be adopted.
581
+ const valueChangedAtSameTimestamp = !contentRevision &&
582
+ !!contentUpdatedAt &&
583
+ contentUpdatedAt === lastAppliedUpdatedAtRef.current &&
584
+ lastAppliedValueRef.current !== null &&
585
+ value !== lastAppliedValueRef.current;
586
+ const externalNewer = revisionChangedAtSameTimestamp ||
587
+ valueChangedAtSameTimestamp ||
588
+ !lastAppliedUpdatedAtRef.current ||
589
+ !contentUpdatedAt ||
590
+ contentUpdatedAt > lastAppliedUpdatedAtRef.current;
591
+ if (collab && !isLeadClient) {
592
+ peerWait.deadline = null;
593
+ if (!externalNewer) {
594
+ peerWait.leadDeadline = null;
595
+ if (contentUpdatedAt) {
596
+ lastAppliedUpdatedAtRef.current = contentUpdatedAt;
597
+ }
598
+ return;
599
+ }
600
+ peerWait.leadDeadline ??= Date.now() + LEAD_FAILOVER_MS;
601
+ const leadRemaining = peerWait.leadDeadline - Date.now();
602
+ if (leadRemaining > 0) {
603
+ retry = setTimeout(() => apply(deferred), leadRemaining);
604
+ return;
605
+ }
606
+ // A live doc that moved on since the last snapshot holds typing the
607
+ // snapshot predates (a peer's save lags the Yjs state); adopting it
608
+ // would delete that text for every peer. SQL catches up on the next save.
609
+ if (!editorUnchangedSinceApply) {
610
+ peerWait.leadDeadline = null;
611
+ return;
612
+ }
613
+ }
614
+ if (typingRecently) {
615
+ if (externalNewer) {
616
+ retry = setTimeout(() => apply(deferred), 700);
617
+ }
618
+ else {
619
+ peerWait.deadline = null;
620
+ }
621
+ return;
622
+ }
623
+ const hasAppliedSnapshot = lastAppliedSerializedRef.current !== null;
624
+ const currentIsRegisteredLocalEmission = lastRegisteredLocalEmissionRef.current !== null &&
625
+ currentMarkdown === lastRegisteredLocalEmissionRef.current;
626
+ if (!externalNewer &&
627
+ (editorFocused ||
628
+ hasAppliedSnapshot ||
629
+ currentIsRegisteredLocalEmission)) {
630
+ peerWait.deadline = null;
631
+ return;
632
+ }
633
+ // A snapshot another writer saved can reach this tab before the Yjs
634
+ // updates that carry the same text (a collab poll lags the action poll,
635
+ // and a save's merged answer lags neither), and applying it first
636
+ // inserts that text a second time when they land. Only a collab-backed
637
+ // revision, returned above, is known to be in the Yjs doc already.
638
+ const snapshotKey = `${contentRevision ?? ""}@${contentUpdatedAt ?? ""}`;
639
+ if (collab &&
640
+ externalNewer &&
641
+ requestCollabSync &&
642
+ syncedBeforeAdoptRef.current !== snapshotKey) {
643
+ // The update a failed catch-up missed may only be late, so the
644
+ // catch-up retries first. Past that, adopting without it is the
645
+ // behavior before this step existed, so the sync degrades to it,
646
+ // loudly.
647
+ const caughtUp = (status, error) => {
648
+ if (status !== "synced") {
649
+ if (++peerWait.catchUpFailures < CATCH_UP_ATTEMPTS) {
650
+ if (!cancelled)
651
+ retry = setTimeout(() => apply(deferred), CATCH_UP_RETRY_MS);
652
+ return;
653
+ }
654
+ console.warn(`Adopting a saved snapshot without a live sync (${status})`, ...(error === undefined ? [] : [error]));
655
+ }
656
+ syncedBeforeAdoptRef.current = snapshotKey;
657
+ if (!cancelled)
658
+ apply(deferred);
659
+ };
660
+ void requestCollabSync().then((result) => caughtUp(result.status), (error) => caughtUp("failed", error));
661
+ return;
662
+ }
663
+ if (collab &&
664
+ externalNewer &&
665
+ !deferred &&
666
+ peerCountRef.current > 0 &&
667
+ !(authoritativeBaseRef.current !== null &&
668
+ callbacks.normalizeValue(authoritativeBaseRef.current.value) ===
669
+ currentMarkdown &&
670
+ callbacks.isEditorClean?.(currentMarkdown))) {
671
+ peerWait.deadline ??= Date.now() + PEER_SETTLE_MS;
672
+ const remaining = peerWait.deadline - Date.now();
673
+ if (remaining > 0) {
674
+ retry = setTimeout(() => apply(true), remaining);
675
+ return;
676
+ }
677
+ }
678
+ const applyTimer = setTimeout(() => {
679
+ if (cancelled || editor.isDestroyed)
680
+ return;
681
+ const scheduledCallbacks = reconcileCallbacksRef.current;
682
+ peerWait.deadline = null;
683
+ const beforeMarkdown = scheduledCallbacks.getMarkdown(editor);
684
+ const normalized = scheduledCallbacks.normalizeValue(value);
685
+ const unchangedSinceApply = lastAppliedSerializedRef.current !== null &&
686
+ beforeMarkdown === lastAppliedSerializedRef.current;
687
+ if (beforeMarkdown === normalized ||
688
+ (unchangedSinceApply &&
689
+ normalized === lastAppliedSerializedRef.current)) {
690
+ lastAppliedValueRef.current = value;
691
+ lastAppliedSerializedRef.current = beforeMarkdown;
692
+ if (contentRevision) {
693
+ authoritativeBaseRef.current = { value, revision: contentRevision };
694
+ reportedConflictRevisionRef.current = null;
695
+ }
696
+ if (contentUpdatedAt) {
697
+ lastAppliedUpdatedAtRef.current = contentUpdatedAt;
698
+ }
699
+ return;
700
+ }
701
+ isSettingContentRef.current = true;
702
+ const authoritativeBase = authoritativeBaseRef.current;
703
+ if (contentRevision &&
704
+ scheduledCallbacks.onBaseAwareReconcile &&
705
+ authoritativeBase &&
706
+ authoritativeBase.revision !== contentRevision) {
707
+ const parse = scheduledCallbacks.parseValue === false
708
+ ? null
709
+ : (scheduledCallbacks.parseValue ?? defaultParseValue);
710
+ const baseDoc = parse?.(editor, authoritativeBase.value) ?? null;
711
+ const serverDoc = parse?.(editor, value) ?? null;
712
+ if (!baseDoc || !serverDoc) {
713
+ isSettingContentRef.current = false;
714
+ if (reportedConflictRevisionRef.current !== contentRevision) {
715
+ reportedConflictRevisionRef.current = contentRevision;
716
+ scheduledCallbacks.onBaseAwareReconcile({
717
+ status: "failed",
718
+ content: beforeMarkdown,
719
+ serverContent: value,
720
+ baseRevision: authoritativeBase.revision,
721
+ serverRevision: contentRevision,
722
+ });
723
+ }
724
+ return;
725
+ }
726
+ const reconciled = reconcileDocAgainstBase(editor, baseDoc, serverDoc, { overlapPolicy });
727
+ if (reconciled.status === "conflict" ||
728
+ reconciled.status === "failed") {
729
+ isSettingContentRef.current = false;
730
+ if (reportedConflictRevisionRef.current !== contentRevision) {
731
+ reportedConflictRevisionRef.current = contentRevision;
732
+ scheduledCallbacks.onBaseAwareReconcile({
733
+ status: reconciled.status,
734
+ content: beforeMarkdown,
735
+ serverContent: value,
736
+ baseRevision: authoritativeBase.revision,
737
+ serverRevision: contentRevision,
738
+ });
739
+ }
740
+ return;
741
+ }
742
+ const merged = scheduledCallbacks.getMarkdown(editor);
743
+ isSettingContentRef.current = false;
744
+ authoritativeBaseRef.current = { value, revision: contentRevision };
745
+ reportedConflictRevisionRef.current = null;
746
+ lastEmittedRef.current = merged;
747
+ pushEmittedRing(recentEmittedRef.current, merged);
748
+ lastAppliedValueRef.current = value;
749
+ lastAppliedSerializedRef.current = merged;
750
+ if (contentUpdatedAt)
751
+ lastAppliedUpdatedAtRef.current = contentUpdatedAt;
752
+ if (merged !== beforeMarkdown)
753
+ scheduledCallbacks.onRemoteSnapshotChange?.(merged);
754
+ if (merged !== normalized) {
755
+ scheduledCallbacks.onBaseAwareReconcile({
756
+ status: "merged",
757
+ content: merged,
758
+ serverContent: value,
759
+ baseRevision: authoritativeBase.revision,
760
+ serverRevision: contentRevision,
761
+ });
762
+ }
763
+ return;
764
+ }
765
+ let appliedSurgically = false;
766
+ if (scheduledCallbacks.parseValue !== false) {
767
+ const parse = scheduledCallbacks.parseValue ?? defaultParseValue;
768
+ const parsedDoc = parse(editor, value);
769
+ if (parsedDoc) {
770
+ const result = applyDocSurgically(editor, parsedDoc);
771
+ appliedSurgically = result === "applied" || result === "noop";
772
+ }
773
+ }
774
+ if (!appliedSurgically) {
775
+ scheduledCallbacks.setContent(editor, value, {
776
+ emitUpdate: false,
777
+ addToHistory: false,
778
+ });
779
+ }
780
+ isSettingContentRef.current = false;
781
+ const serialized = scheduledCallbacks.getMarkdown(editor);
782
+ lastEmittedRef.current = serialized;
783
+ pushEmittedRing(recentEmittedRef.current, serialized);
784
+ lastAppliedValueRef.current = value;
785
+ lastAppliedSerializedRef.current = serialized;
786
+ if (contentRevision) {
787
+ authoritativeBaseRef.current = { value, revision: contentRevision };
788
+ reportedConflictRevisionRef.current = null;
789
+ }
790
+ if (contentUpdatedAt) {
791
+ lastAppliedUpdatedAtRef.current = contentUpdatedAt;
792
+ }
793
+ if (serialized !== beforeMarkdown) {
794
+ scheduledCallbacks.onRemoteSnapshotChange?.(serialized);
795
+ }
796
+ }, 0);
797
+ retry = applyTimer;
798
+ };
799
+ apply();
800
+ return () => {
801
+ cancelled = true;
802
+ if (retry)
803
+ clearTimeout(retry);
804
+ };
805
+ }, [
806
+ contentUpdatedAt,
807
+ contentRevision,
808
+ compareContentRevisions,
809
+ acknowledgedLocalSnapshot,
810
+ editor,
811
+ ydoc,
812
+ editable,
813
+ value,
814
+ collab,
815
+ collabSynced,
816
+ isLeadClient,
817
+ overlapPolicy,
818
+ collabBackedSnapshot,
819
+ pendingCollabSnapshot,
820
+ requestCollabSync,
821
+ ]);
822
+ const shouldIgnoreUpdate = (transaction) => {
823
+ if (!editable || isSettingContentRef.current)
824
+ return true;
825
+ if (collab && !seededRef.current) {
826
+ const firstSyncedEmptyUserEdit = collabSynced &&
827
+ !value.trim() &&
828
+ transaction.docChanged &&
829
+ Boolean(transaction.getMeta("uiEvent")) &&
830
+ !isChangeOrigin(transaction);
831
+ if (!firstSyncedEmptyUserEdit)
832
+ return true;
833
+ seededRef.current = true;
834
+ }
835
+ if (transaction.getMeta(RICH_MARKDOWN_PROGRAMMATIC_TRANSACTION)) {
836
+ return true;
837
+ }
838
+ if (collab && transaction && isRemoteCollaborativeTransaction(transaction))
839
+ return true;
840
+ lastTypedAtRef.current = Date.now();
841
+ return false;
842
+ };
843
+ const reportRemoteUpdate = (transaction) => {
844
+ if (!collab ||
845
+ !collabSynced ||
846
+ !seededRef.current ||
847
+ !editor ||
848
+ editor.isDestroyed ||
849
+ isSettingContentRef.current ||
850
+ !transaction.docChanged ||
851
+ !isChangeOrigin(transaction) ||
852
+ transaction.getMeta(ySyncPluginKey)?.isUndoRedoOperation) {
853
+ return;
854
+ }
855
+ onRemoteSnapshotChange?.(getMarkdown(editor));
856
+ };
857
+ const registerEmitted = (markdown) => {
858
+ if (collab && !markdown.trim())
859
+ return false;
860
+ lastEmittedRef.current = markdown;
861
+ pushEmittedRing(recentEmittedRef.current, markdown);
862
+ lastRegisteredLocalEmissionRef.current = markdown;
863
+ return true;
864
+ };
865
+ return {
866
+ collab,
867
+ initialSeedFailed,
868
+ initialSeedPending: Boolean(requestInitialSeed) && collab && !seeded,
869
+ retryInitialSeed: () => {
870
+ setInitialSeedFailed(false);
871
+ setInitialSeedRetry((retry) => retry + 1);
872
+ },
873
+ isSettingContentRef,
874
+ shouldIgnoreUpdate,
875
+ reportRemoteUpdate,
876
+ registerEmitted,
877
+ };
878
+ }
879
+ //# sourceMappingURL=useCollabReconcile.js.map