edytor 2.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/README.md +19 -4
  2. package/dist/block/block.svelte.js +2 -4
  3. package/dist/clipboard/htmlFlow.d.ts +20 -7
  4. package/dist/clipboard/htmlFlow.js +23 -15
  5. package/dist/clipboard/serializeClipboardFragment.d.ts +37 -4
  6. package/dist/clipboard/serializeClipboardFragment.js +6 -4
  7. package/dist/clipboard/textBlocks.d.ts +8 -0
  8. package/dist/clipboard/textBlocks.js +6 -2
  9. package/dist/cloudflare/DocumentRoom.d.ts +13 -9
  10. package/dist/cloudflare/DocumentRoom.js +10 -6
  11. package/dist/cloudflare/room/admission.js +3 -3
  12. package/dist/cloudflare/room/context.d.ts +28 -27
  13. package/dist/cloudflare/room/context.js +2 -2
  14. package/dist/cloudflare/room/purge.d.ts +6 -3
  15. package/dist/cloudflare/room/purge.js +44 -19
  16. package/dist/cloudflare/room/updates.d.ts +3 -4
  17. package/dist/cloudflare/room/updates.js +6 -8
  18. package/dist/cloudflare/routeDocumentSocket.d.ts +17 -0
  19. package/dist/cloudflare/routeDocumentSocket.js +53 -0
  20. package/dist/collaboration/comments/client.d.ts +1 -1
  21. package/dist/collaboration/comments/client.js +1 -1
  22. package/dist/collaboration/remoteSelection.js +3 -3
  23. package/dist/components/Edytor.svelte +2 -10
  24. package/dist/components/Edytor.svelte.d.ts +1 -3
  25. package/dist/crdt/admission.d.ts +5 -10
  26. package/dist/crdt/admission.js +5 -11
  27. package/dist/crdt/attribution/attribution.d.ts +31 -12
  28. package/dist/crdt/attribution/attribution.js +56 -18
  29. package/dist/crdt/attribution/block.d.ts +3 -3
  30. package/dist/crdt/attribution/block.js +7 -8
  31. package/dist/crdt/attribution/index.d.ts +1 -1
  32. package/dist/crdt/attribution/index.js +1 -1
  33. package/dist/crdt/data.d.ts +62 -31
  34. package/dist/crdt/data.js +211 -103
  35. package/dist/crdt/doc/delete.d.ts +1 -1
  36. package/dist/crdt/doc/delete.js +13 -30
  37. package/dist/crdt/doc/funnel.d.ts +7 -6
  38. package/dist/crdt/doc/funnel.js +39 -33
  39. package/dist/crdt/doc/gate.d.ts +3 -20
  40. package/dist/crdt/doc/gate.js +2 -41
  41. package/dist/crdt/doc/history.d.ts +25 -9
  42. package/dist/crdt/doc/history.js +152 -42
  43. package/dist/crdt/doc/layout.js +11 -22
  44. package/dist/crdt/doc/meta.js +12 -17
  45. package/dist/crdt/doc/moves.d.ts +1 -1
  46. package/dist/crdt/doc/moves.js +52 -32
  47. package/dist/crdt/doc/reads.js +2 -2
  48. package/dist/crdt/doc/seed.js +2 -2
  49. package/dist/crdt/doc/split-merge.js +12 -15
  50. package/dist/crdt/doc/steps.d.ts +25 -13
  51. package/dist/crdt/doc/steps.js +52 -122
  52. package/dist/crdt/doc/types.d.ts +21 -9
  53. package/dist/crdt/document.d.ts +21 -19
  54. package/dist/crdt/document.js +26 -23
  55. package/dist/crdt/edytor-doc.d.ts +66 -68
  56. package/dist/crdt/edytor-doc.js +21 -20
  57. package/dist/crdt/engine-api.d.ts +33 -1
  58. package/dist/crdt/engine.d.ts +0 -1
  59. package/dist/crdt/engine.js +1 -4
  60. package/dist/crdt/flow.d.ts +1 -1
  61. package/dist/crdt/flow.js +25 -27
  62. package/dist/crdt/index.d.ts +29 -28
  63. package/dist/crdt/index.js +3 -3
  64. package/dist/crdt/placement/display.d.ts +5 -30
  65. package/dist/crdt/placement/display.js +39 -144
  66. package/dist/crdt/placement/keys.d.ts +58 -0
  67. package/dist/crdt/placement/keys.js +90 -0
  68. package/dist/crdt/placement/model.d.ts +119 -118
  69. package/dist/crdt/placement/model.js +242 -142
  70. package/dist/crdt/placement/resolve.d.ts +123 -35
  71. package/dist/crdt/placement/resolve.js +187 -153
  72. package/dist/crdt/placement/slots.d.ts +134 -0
  73. package/dist/crdt/placement/slots.js +152 -0
  74. package/dist/crdt/protocol.d.ts +2 -2
  75. package/dist/crdt/protocol.js +2 -2
  76. package/dist/crdt/providers/index.d.ts +1 -1
  77. package/dist/crdt/providers/room.d.ts +26 -11
  78. package/dist/crdt/providers/room.js +77 -27
  79. package/dist/crdt/providers/websocket.d.ts +1 -1
  80. package/dist/crdt/providers/websocket.js +33 -32
  81. package/dist/crdt/purge.d.ts +17 -8
  82. package/dist/crdt/purge.js +236 -126
  83. package/dist/crdt/restore.d.ts +2 -2
  84. package/dist/crdt/restore.js +18 -34
  85. package/dist/crdt/schema.d.ts +22 -21
  86. package/dist/crdt/schema.js +29 -23
  87. package/dist/crdt/semantics.js +3 -1
  88. package/dist/crdt/storage.d.ts +1 -1
  89. package/dist/crdt/storage.js +1 -1
  90. package/dist/crdt/structs.d.ts +15 -15
  91. package/dist/crdt/structs.js +8 -22
  92. package/dist/crdt/text/index/cache.js +4 -0
  93. package/dist/crdt/text/index/claims.js +12 -0
  94. package/dist/crdt/text/index/fold.d.ts +2 -3
  95. package/dist/crdt/text/index/fold.js +194 -44
  96. package/dist/crdt/text/index/layout.js +5 -8
  97. package/dist/crdt/text/index/placement.d.ts +26 -18
  98. package/dist/crdt/text/index/placement.js +404 -138
  99. package/dist/crdt/text/index/records.d.ts +3 -3
  100. package/dist/crdt/text/index/records.js +24 -31
  101. package/dist/crdt/text/index/shared.d.ts +11 -3
  102. package/dist/crdt/text/index/shared.js +12 -3
  103. package/dist/crdt/text/index/state.d.ts +21 -17
  104. package/dist/crdt/text/index/state.js +15 -17
  105. package/dist/crdt/text/index/streams.d.ts +10 -5
  106. package/dist/crdt/text/index/streams.js +78 -27
  107. package/dist/crdt/text/items.d.ts +10 -3
  108. package/dist/crdt/text/items.js +7 -0
  109. package/dist/crdt/text/model.d.ts +77 -62
  110. package/dist/crdt/text/model.js +84 -169
  111. package/dist/crdt/text/ranges.d.ts +1 -1
  112. package/dist/crdt/text/ranges.js +3 -3
  113. package/dist/crdt/text/rows.d.ts +13 -7
  114. package/dist/crdt/text/rows.js +24 -7
  115. package/dist/crdt/text/runs.d.ts +17 -12
  116. package/dist/crdt/text/runs.js +24 -7
  117. package/dist/crdt/text/streams.d.ts +26 -13
  118. package/dist/crdt/text/streams.js +41 -14
  119. package/dist/crdt/vendor/yjs/UPSTREAM.md +568 -21
  120. package/dist/crdt/vendor/yjs/dts/global.d.ts +2 -0
  121. package/dist/crdt/vendor/yjs/dts/index.d.ts +1 -1
  122. package/dist/crdt/vendor/yjs/dts/structs/AbstractStruct.d.ts +7 -0
  123. package/dist/crdt/vendor/yjs/dts/structs/Item.d.ts +194 -10
  124. package/dist/crdt/vendor/yjs/dts/utils/Doc.d.ts +6 -3
  125. package/dist/crdt/vendor/yjs/dts/utils/StructStore.d.ts +5 -18
  126. package/dist/crdt/vendor/yjs/dts/utils/Transaction.d.ts +15 -1
  127. package/dist/crdt/vendor/yjs/dts/utils/UpdateDecoder.d.ts +14 -6
  128. package/dist/crdt/vendor/yjs/dts/utils/UpdateEncoder.d.ts +33 -6
  129. package/dist/crdt/vendor/yjs/dts/utils/ids.d.ts +1 -65
  130. package/dist/crdt/vendor/yjs/dts/utils/marks.d.ts +6 -1
  131. package/dist/crdt/vendor/yjs/dts/ynode.d.ts +43 -7
  132. package/dist/crdt/vendor/yjs/global.d.ts +2 -0
  133. package/dist/crdt/vendor/yjs/src/index.js +1 -1
  134. package/dist/crdt/vendor/yjs/src/structs/AbstractStruct.js +10 -0
  135. package/dist/crdt/vendor/yjs/src/structs/Item.js +610 -51
  136. package/dist/crdt/vendor/yjs/src/utils/BlockSet.js +18 -9
  137. package/dist/crdt/vendor/yjs/src/utils/Doc.js +5 -3
  138. package/dist/crdt/vendor/yjs/src/utils/StructStore.js +5 -0
  139. package/dist/crdt/vendor/yjs/src/utils/Transaction.js +36 -13
  140. package/dist/crdt/vendor/yjs/src/utils/UpdateDecoder.js +88 -18
  141. package/dist/crdt/vendor/yjs/src/utils/UpdateEncoder.js +119 -32
  142. package/dist/crdt/vendor/yjs/src/utils/encoding.js +13 -1
  143. package/dist/crdt/vendor/yjs/src/utils/ids.js +7 -7
  144. package/dist/crdt/vendor/yjs/src/utils/marks.js +193 -8
  145. package/dist/crdt/vendor/yjs/src/utils/redo.js +1 -1
  146. package/dist/crdt/vendor/yjs/src/utils/transaction-helpers.js +1 -1
  147. package/dist/crdt/vendor/yjs/src/utils/updates.js +3 -3
  148. package/dist/crdt/vendor/yjs/src/ynode.js +177 -12
  149. package/dist/dnd/autoScroll.d.ts +15 -7
  150. package/dist/dnd/autoScroll.js +10 -15
  151. package/dist/dnd/dropIndicator.js +2 -5
  152. package/dist/dnd/external.d.ts +6 -0
  153. package/dist/dnd/external.js +17 -0
  154. package/dist/dnd/geometry.d.ts +2 -0
  155. package/dist/dnd/geometry.js +3 -4
  156. package/dist/dnd/placement.d.ts +1 -1
  157. package/dist/dnd/pragmatic.d.ts +3 -1
  158. package/dist/dnd/pragmatic.js +12 -2
  159. package/dist/dnd/vendor/pragmatic/UPSTREAM.md +51 -18
  160. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/drop-target-for-external.d.ts +4 -0
  161. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/drop-target-for-external.js +6 -0
  162. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/element-adapter.d.ts +0 -2
  163. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/element-adapter.js +4 -22
  164. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/external-adapter-types.d.ts +26 -0
  165. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/external-adapter.d.ts +30 -0
  166. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/external-adapter.js +203 -0
  167. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/get-available-items.js +13 -0
  168. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/get-available-types.js +9 -0
  169. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/is-an-available-type.js +19 -0
  170. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/monitor-for-external.d.ts +4 -0
  171. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/monitor-for-external.js +6 -0
  172. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/honey-pot-fix/make-honey-pot-fix.js +4 -16
  173. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/internal-types.d.ts +1 -8
  174. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/make-adapter/make-drop-target.js +5 -6
  175. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/make-adapter/make-monitor.js +2 -3
  176. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/element/custom-native-drag-preview/set-custom-native-drag-preview.d.ts +1 -1
  177. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/element/custom-native-drag-preview/set-custom-native-drag-preview.js +6 -24
  178. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/external/contains-files.d.ts +2 -0
  179. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/external/contains-files.js +5 -0
  180. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/external/get-files.d.ts +3 -0
  181. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/external/get-files.js +12 -0
  182. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/external/native-types.d.ts +12 -0
  183. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/util/changing-window/is-entering-window-in-safari.js +10 -0
  184. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/util/changing-window/is-entering-window.js +55 -0
  185. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/entry-point/external.d.ts +4 -0
  186. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/entry-point/external.js +8 -0
  187. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/internal-types.d.ts +0 -4
  188. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/over-element/get-scroll-by.js +16 -72
  189. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/over-element/try-scroll.js +1 -9
  190. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/shared/configuration.js +4 -29
  191. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/shared/get-scroll-change.js +2 -3
  192. package/dist/edytor.svelte.d.ts +2 -5
  193. package/dist/edytor.svelte.js +21 -32
  194. package/dist/events/beforeInputCommands.js +2 -2
  195. package/dist/events/onBeforeInput.js +1 -1
  196. package/dist/events/onDrop.d.ts +0 -6
  197. package/dist/events/onDrop.js +10 -23
  198. package/dist/events/onInput.d.ts +0 -12
  199. package/dist/events/onInput.js +1 -67
  200. package/dist/events/onPageHide.d.ts +3 -0
  201. package/dist/events/onPageHide.js +16 -0
  202. package/dist/export/forms.d.ts +627 -0
  203. package/dist/export/forms.js +749 -0
  204. package/dist/export/index.d.ts +170 -0
  205. package/dist/export/index.js +161 -0
  206. package/dist/export/markdown.d.ts +41 -0
  207. package/dist/export/markdown.js +585 -0
  208. package/dist/export/markdownWriter.d.ts +9 -0
  209. package/dist/export/markdownWriter.js +133 -0
  210. package/dist/export/mdx.d.ts +15 -0
  211. package/dist/export/mdx.js +33 -0
  212. package/dist/index.d.ts +3 -3
  213. package/dist/index.js +1 -1
  214. package/dist/kinds.js +1 -1
  215. package/dist/plugins/anchored.svelte.d.ts +21 -25
  216. package/dist/plugins/anchored.svelte.js +23 -39
  217. package/dist/plugins/blockHandles/BlockHandleController.svelte.js +24 -32
  218. package/dist/plugins/blockHandles/dragPreview.d.ts +26 -7
  219. package/dist/plugins/blockHandles/dragPreview.js +33 -0
  220. package/dist/plugins/blockMenu/BlockMenuController.svelte.d.ts +5 -0
  221. package/dist/plugins/blockMenu/BlockMenuController.svelte.js +7 -2
  222. package/dist/plugins/blockMenu/blockMenuPlugin.js +5 -50
  223. package/dist/plugins/chrome.d.ts +27 -5
  224. package/dist/plugins/chrome.js +24 -9
  225. package/dist/plugins/code/CodePlugin.svelte +12 -9
  226. package/dist/plugins/code/header.svelte.js +7 -11
  227. package/dist/plugins/code/languageMenu.svelte.d.ts +5 -2
  228. package/dist/plugins/code/languageMenu.svelte.js +13 -20
  229. package/dist/plugins/columns/ColumnsPlugin.svelte +7 -20
  230. package/dist/plugins/columns/resize.svelte.d.ts +2 -3
  231. package/dist/plugins/columns/resize.svelte.js +2 -5
  232. package/dist/plugins/comments/CommentsController.svelte.d.ts +6 -0
  233. package/dist/plugins/comments/CommentsController.svelte.js +20 -0
  234. package/dist/plugins/equation/EquationPlugin.svelte +12 -22
  235. package/dist/plugins/equation/equation.svelte.d.ts +7 -15
  236. package/dist/plugins/equation/equation.svelte.js +13 -50
  237. package/dist/plugins/equation/tex.d.ts +17 -0
  238. package/dist/plugins/equation/tex.js +42 -0
  239. package/dist/plugins/fileDrop.d.ts +38 -23
  240. package/dist/plugins/fileDrop.js +82 -76
  241. package/dist/plugins/find/FindController.svelte.d.ts +5 -0
  242. package/dist/plugins/find/FindController.svelte.js +14 -14
  243. package/dist/plugins/find/findPlugin.js +1 -15
  244. package/dist/plugins/image/ImageChrome.svelte +8 -2
  245. package/dist/plugins/image/ImagePlugin.svelte +15 -52
  246. package/dist/plugins/image/controls.svelte.js +16 -2
  247. package/dist/plugins/image/toolbar.svelte.d.ts +5 -4
  248. package/dist/plugins/image/toolbar.svelte.js +21 -31
  249. package/dist/plugins/index.d.ts +1 -1
  250. package/dist/plugins/list.svelte.d.ts +9 -0
  251. package/dist/plugins/list.svelte.js +18 -0
  252. package/dist/plugins/marquee/marqueePlugin.js +0 -4
  253. package/dist/plugins/media/AudioPlugin.svelte +1 -1
  254. package/dist/plugins/media/BookmarkPlugin.svelte +6 -97
  255. package/dist/plugins/media/EmbedPlugin.svelte +5 -90
  256. package/dist/plugins/media/EmptySlot.svelte +36 -20
  257. package/dist/plugins/media/EmptySlot.svelte.d.ts +6 -15
  258. package/dist/plugins/media/FilePlugin.svelte +1 -19
  259. package/dist/plugins/media/MediaEmpty.svelte +2 -55
  260. package/dist/plugins/media/MediaEmpty.svelte.d.ts +18 -14
  261. package/dist/plugins/media/SourceBlock.svelte +142 -52
  262. package/dist/plugins/media/SourceBlock.svelte.d.ts +10 -4
  263. package/dist/plugins/media/VideoPlugin.svelte +1 -1
  264. package/dist/plugins/media/empty.svelte.js +2 -7
  265. package/dist/plugins/media/media.d.ts +2 -63
  266. package/dist/plugins/media/media.js +1 -194
  267. package/dist/plugins/media/sources.d.ts +60 -0
  268. package/dist/plugins/media/sources.js +165 -0
  269. package/dist/plugins/media/urlPaste.svelte.d.ts +2 -1
  270. package/dist/plugins/media/urlPaste.svelte.js +12 -21
  271. package/dist/plugins/mention/MentionPlugin.svelte +8 -35
  272. package/dist/plugins/page/PagePlugin.svelte +2 -9
  273. package/dist/plugins/page/page.js +1 -1
  274. package/dist/plugins/pageLink/PageLinkPlugin.svelte +6 -13
  275. package/dist/plugins/richtext/RichTextPlugin.svelte +85 -197
  276. package/dist/plugins/richtext/body.js +1 -1
  277. package/dist/plugins/richtext/calloutIcons.svelte.d.ts +2 -2
  278. package/dist/plugins/richtext/calloutIcons.svelte.js +5 -7
  279. package/dist/plugins/richtext/richTextOperations.d.ts +1 -19
  280. package/dist/plugins/richtext/richTextOperations.js +3 -49
  281. package/dist/plugins/slashMenu/SlashMenuController.svelte.d.ts +2 -0
  282. package/dist/plugins/slashMenu/SlashMenuController.svelte.js +7 -0
  283. package/dist/plugins/slashMenu/slashMenuPlugin.js +5 -14
  284. package/dist/plugins/table/TableChrome.svelte +2 -3
  285. package/dist/plugins/table/TablePlugin.svelte +20 -54
  286. package/dist/plugins/table/chrome.svelte.d.ts +5 -2
  287. package/dist/plugins/table/chrome.svelte.js +30 -54
  288. package/dist/plugins/table/table.js +3 -3
  289. package/dist/plugins/toc/TocPlugin.svelte +2 -4
  290. package/dist/plugins/toolbar/ToolbarController.svelte.d.ts +7 -0
  291. package/dist/plugins/toolbar/ToolbarController.svelte.js +20 -13
  292. package/dist/plugins/toolbar/toolbarPlugin.js +19 -53
  293. package/dist/plugins/triggers/TriggerController.svelte.d.ts +7 -2
  294. package/dist/plugins/triggers/TriggerController.svelte.js +11 -4
  295. package/dist/plugins/triggers/place.js +1 -2
  296. package/dist/plugins/triggers/triggers.d.ts +6 -1
  297. package/dist/plugins/triggers/triggers.js +12 -13
  298. package/dist/plugins/uploads.svelte.d.ts +5 -2
  299. package/dist/plugins/uploads.svelte.js +25 -15
  300. package/dist/plugins.d.ts +26 -0
  301. package/dist/plugins.js +0 -24
  302. package/dist/selection/replaceSelection.js +2 -2
  303. package/dist/selection/selection.svelte.d.ts +4 -10
  304. package/dist/selection/selection.svelte.js +7 -11
  305. package/dist/session/bindings.js +1 -1
  306. package/dist/session/commands.d.ts +7 -11
  307. package/dist/session/commands.js +13 -19
  308. package/dist/session/inputRules.js +1 -1
  309. package/dist/session/navigation.js +1 -1
  310. package/dist/session/suggestions.svelte.d.ts +0 -11
  311. package/dist/session/suggestions.svelte.js +15 -3
  312. package/dist/session/uploads.d.ts +8 -8
  313. package/dist/surface/lines.js +1 -3
  314. package/dist/surface/observer.svelte.d.ts +17 -1
  315. package/dist/surface/observer.svelte.js +74 -19
  316. package/dist/surface/overlay.d.ts +0 -14
  317. package/dist/surface/overlay.js +0 -25
  318. package/dist/surface/projector.svelte.d.ts +15 -3
  319. package/dist/surface/projector.svelte.js +60 -9
  320. package/dist/text/text.svelte.js +3 -13
  321. package/dist/utils/sanitize.d.ts +38 -0
  322. package/dist/utils/sanitize.js +82 -0
  323. package/dist/utils.d.ts +2 -0
  324. package/dist/utils.js +5 -0
  325. package/package.json +19 -2
  326. package/dist/crdt/placement/rank.d.ts +0 -87
  327. package/dist/crdt/placement/rank.js +0 -332
  328. package/dist/crdt/placement/source.d.ts +0 -43
  329. package/dist/crdt/placement/source.js +0 -66
  330. package/dist/crdt/text/delete-index.d.ts +0 -129
  331. package/dist/crdt/text/delete-index.js +0 -365
  332. package/dist/crdt/text/deletes.d.ts +0 -76
  333. package/dist/crdt/text/deletes.js +0 -362
  334. package/dist/crdt/text/index/anchored.d.ts +0 -17
  335. package/dist/crdt/text/index/anchored.js +0 -197
  336. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/util/max-z-index.js +0 -3
  337. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/util/supports-popover.js +0 -16
  338. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/shared/is-axis-allowed.js +0 -3
  339. package/dist/plugins/code/LanguageMenu.svelte +0 -25
  340. package/dist/plugins/code/LanguageMenu.svelte.d.ts +0 -9
  341. package/dist/plugins/equation/EquationEditor.svelte +0 -27
  342. package/dist/plugins/equation/EquationEditor.svelte.d.ts +0 -9
  343. package/dist/plugins/image/ImageToolbarHost.svelte +0 -37
  344. package/dist/plugins/image/ImageToolbarHost.svelte.d.ts +0 -9
  345. package/dist/plugins/richtext/CalloutIconPicker.svelte +0 -26
  346. package/dist/plugins/richtext/CalloutIconPicker.svelte.d.ts +0 -9
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Slots and move records — where a block or an array item stands (fork
3
+ * patch YP22).
4
+ *
5
+ * Every data owner keeps ONE order sequence, its node's list part (a block's
6
+ * node, an atom's node, the registry root for the top-level blocks, the
7
+ * `docdata` root for the document's data). The sequence holds one countable
8
+ * unit per thing it orders:
9
+ *
10
+ * - a block's **home slot** `{ b: id }`, written once at the block's creation
11
+ * in its parent's sequence, right after its left sibling's unit (YATA's
12
+ * origin rule: later inserts there stay together, `order.insert.run`);
13
+ * - an array item's **slot** `{ p: path, i: id }` (`crdt/data.ts`): the
14
+ * item exists while its slot does;
15
+ * - a **move record** (the engine's `ContentMove`): one unit at the
16
+ * destination naming the units it moves, in order. Each named unit shows
17
+ * at the record that wins its movers — the greatest `(priority, client,
18
+ * clock)` — and reads as deleted at home, so a sequence walk sees it gone
19
+ * from there. Deleting a record (an undo) hands its units to the next
20
+ * record, else home.
21
+ *
22
+ * A reader of a sequence (`entriesOf`) walks its live items: a slot at home,
23
+ * or a record expanded to the units it shows. A writer places a new slot or a
24
+ * record after a displayed entry (`placeAfter`): when that entry is a unit in
25
+ * the middle of a record's display, the new record also carries the record's
26
+ * later units, so the new thing shows between them.
27
+ *
28
+ * The engine is read through `engine.js` (structural types, `engine-api.ts`).
29
+ */
30
+ import type { EngineDoc, EngineNode } from '../engine-api.js';
31
+ import { type StoreStruct } from '../structs.js';
32
+ export type BlockId = string;
33
+ /**
34
+ * A block's home slot in its parent's sequence; `s`, when the block was made
35
+ * by a split (Enter, a paste of lines): the id (`client, clock`) of the
36
+ * split's boundary item in the text, the engine's sort key among the slots
37
+ * of one origin (the boundaries' order in the text, so two peers' splits of
38
+ * one block keep its text's order, `order.split.text`).
39
+ */
40
+ export type BlockSlot = {
41
+ b: BlockId;
42
+ s?: [client: number, clock: number];
43
+ };
44
+ /** An array item's slot: the array's path (`crdt/data.ts`) and the item's id. */
45
+ export type DataSlot = {
46
+ p: string;
47
+ i: string;
48
+ };
49
+ /** One unit of a sequence: its engine id. */
50
+ export type Unit = {
51
+ c: number;
52
+ k: number;
53
+ };
54
+ export declare const isBlockSlot: (v: unknown) => v is BlockSlot;
55
+ export declare const isDataSlot: (v: unknown) => v is DataSlot;
56
+ /** A sequence item as the slot reads walk it. */
57
+ export type SeqItem = StoreStruct & {
58
+ left: SeqItem | null;
59
+ right: SeqItem | null;
60
+ content: {
61
+ arr?: unknown[];
62
+ priority?: number;
63
+ side?: number;
64
+ part?: number;
65
+ at?: unknown;
66
+ ids?: number[];
67
+ };
68
+ /** The record that shows this unit (fork patch YP22), `null` at home. */
69
+ mover?: SeqItem | null;
70
+ movers?: SeqItem[] | null;
71
+ /** Removed or held: shown nowhere. */
72
+ gone?: boolean;
73
+ };
74
+ /** Whether `it` is a move record. */
75
+ export declare const isRecord: (it: SeqItem) => boolean;
76
+ /** A record's stamp, the order its wins follow: `(priority, client, clock)`. */
77
+ export type Stamp = readonly [priority: number, client: number, clock: number];
78
+ export declare const stampOf: (r: SeqItem) => Stamp;
79
+ export declare const cmpStamp: (a: Stamp, b: Stamp) => number;
80
+ /** One displayed entry of a sequence: its value, its unit, and the record it shows through (`null`: at home; `at`: its place among the units read with it). */
81
+ export type Entry = {
82
+ value: unknown;
83
+ unit: Unit;
84
+ via: SeqItem | null;
85
+ at: number;
86
+ };
87
+ /** Whether `a` and `b` are one unit. */
88
+ export declare const sameUnit: (a: Unit, b: Unit) => boolean;
89
+ /** The item holding unit `u`, or `null` when `doc` lacks it (no value read: the fold's hot path). */
90
+ export declare const itemAt: (doc: EngineDoc, u: Unit) => SeqItem | null;
91
+ /** The item holding unit `u` and the value at it, or `null` when `doc` lacks it (a GC struct, not arrived). */
92
+ export declare const unitOf: (doc: EngineDoc, u: Unit) => {
93
+ item: SeqItem;
94
+ value: unknown;
95
+ } | null;
96
+ /**
97
+ * The units item `it` can show, in order, those `keep` takes: a live
98
+ * record's named units (present, not gone; `via` the record), a slot item's
99
+ * units, moved away or not (none when it is gone; `via` `null`). THE walk
100
+ * every reader of a sequence's units takes: the engine's (`shownBy`), the
101
+ * index's places (`placement/resolve.ts`) and the writers' view of them
102
+ * (`placement/model.ts`).
103
+ */
104
+ export declare const unitsOf: (doc: EngineDoc, it: SeqItem, keep: (item: SeqItem, value: unknown, unit: Unit) => boolean) => Entry[];
105
+ /** The units the engine shows at item `it`, in order: a live record's, those it wins; a live slot item's, all. */
106
+ export declare const shownBy: (doc: EngineDoc, it: SeqItem) => Entry[];
107
+ /** The displayed entries of `node`'s sequence, in order. */
108
+ export declare const entriesOf: (doc: EngineDoc, node: EngineNode) => Entry[];
109
+ /**
110
+ * The entry unit `home` displays as: at home when no live record wins it,
111
+ * else at its mover (`via`, `at`); `null` when it shows nowhere (gone).
112
+ */
113
+ export declare const anchorOf: (doc: EngineDoc, home: Unit) => Entry | null;
114
+ /** The sequence node that holds `e`'s displaying item (its record's, or its slot's). */
115
+ export declare const nodeOf: (doc: EngineDoc, e: Entry) => EngineNode;
116
+ /** `units` as `client, clock, len` triples (one unit each). */
117
+ export declare const triples: (units: readonly Unit[]) => number[];
118
+ /**
119
+ * Write new slots (`payloads`) and/or a move of `moved` (unit triples) into
120
+ * `node`'s sequence right after the displayed entry `left` (at the start when
121
+ * `null`; `right` the entry that follows, if any). When `left` is a unit in
122
+ * the middle of a record's display, the record written here carries that
123
+ * record's later units too, so the new entries show between them. `side` is
124
+ * the record's class among the items of its origin (`0` after, `1` before);
125
+ * `chain` the units the record stands at for the engine's sort of two
126
+ * records at one origin, given its first unit — the home slots from the root
127
+ * sequence down to the unit it stands at (`null`: the first unit alone) — and
128
+ * `part` its order among the records standing there. `shown` reads the units
129
+ * a record shows, as the reader sees them (the index's: a unit a cycle sent
130
+ * back elsewhere is not carried).
131
+ */
132
+ export declare const placeAfter: (doc: EngineDoc, node: EngineNode, left: Entry | null, right: Entry | null, payloads: readonly unknown[] | null, moved?: readonly number[] | null, side?: number, part?: number, chain?: ((first: Unit) => readonly Unit[]) | null, shown?: (r: SeqItem) => Entry[]) => void;
133
+ /** Remove unit `u` from its sequence (the engine's delete: it shows nowhere any more). */
134
+ export declare const removeUnit: (doc: EngineDoc, u: Unit) => void;
@@ -0,0 +1,152 @@
1
+ import { Y } from '../engine.js';
2
+ import { asYDoc, clientsOf, engineOps, firstItem, storeOf, structAt } from '../structs.js';
3
+ export const isBlockSlot = (v) => v != null && typeof v === 'object' && typeof v.b === 'string';
4
+ export const isDataSlot = (v) => v != null &&
5
+ typeof v === 'object' &&
6
+ typeof v.p === 'string' &&
7
+ typeof v.i === 'string';
8
+ /** Whether `it` is a move record. */
9
+ export const isRecord = (it) => it.content.priority !== undefined && it.content.ids !== undefined;
10
+ export const stampOf = (r) => [r.content.priority, r.id.client, r.id.clock];
11
+ export const cmpStamp = (a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
12
+ /** Whether `a` and `b` are one unit. */
13
+ export const sameUnit = (a, b) => a.c === b.c && a.k === b.k;
14
+ const ops = engineOps(Y);
15
+ /** The item holding unit `u`, or `null` when `doc` lacks it (no value read: the fold's hot path). */
16
+ export const itemAt = (doc, u) => {
17
+ const structs = clientsOf(doc).get(u.c);
18
+ if (structs === undefined || u.k >= storeOf(doc).getClock(u.c))
19
+ return null;
20
+ const item = structAt(Y, structs, u.k);
21
+ return item === null || !ops.isItem(item) ? null : item;
22
+ };
23
+ /** The item holding unit `u` and the value at it, or `null` when `doc` lacks it (a GC struct, not arrived). */
24
+ export const unitOf = (doc, u) => {
25
+ const item = itemAt(doc, u);
26
+ return item === null ? null : { item, value: item.content.arr?.[u.k - item.id.clock] };
27
+ };
28
+ /**
29
+ * The units item `it` can show, in order, those `keep` takes: a live
30
+ * record's named units (present, not gone; `via` the record), a slot item's
31
+ * units, moved away or not (none when it is gone; `via` `null`). THE walk
32
+ * every reader of a sequence's units takes: the engine's (`shownBy`), the
33
+ * index's places (`placement/resolve.ts`) and the writers' view of them
34
+ * (`placement/model.ts`).
35
+ */
36
+ export const unitsOf = (doc, it, keep) => {
37
+ const out = [];
38
+ const add = (item, value, unit, via) => {
39
+ if (item.gone !== true && keep(item, value, unit))
40
+ out.push({ value, unit, via, at: out.length });
41
+ };
42
+ if (!isRecord(it))
43
+ it.content.arr?.forEach((value, j) => add(it, value, { c: it.id.client, k: it.id.clock + j }, null));
44
+ else if (!it.deleted) {
45
+ const ids = it.content.ids;
46
+ for (let i = 0; i < ids.length; i += 3)
47
+ for (let k = 0; k < ids[i + 2]; k++) {
48
+ const unit = { c: ids[i], k: ids[i + 1] + k };
49
+ const u = unitOf(doc, unit);
50
+ if (u !== null)
51
+ add(u.item, u.value, unit, it);
52
+ }
53
+ }
54
+ return out;
55
+ };
56
+ /** The units the engine shows at item `it`, in order: a live record's, those it wins; a live slot item's, all. */
57
+ export const shownBy = (doc, it) => {
58
+ const via = isRecord(it) ? it : null;
59
+ return it.deleted ? [] : unitsOf(doc, it, (item) => item.mover === via);
60
+ };
61
+ /** The displayed entries of `node`'s sequence, in order. */
62
+ export const entriesOf = (doc, node) => {
63
+ const out = [];
64
+ for (let it = firstItem(node); it !== null; it = it.right)
65
+ for (const e of shownBy(doc, it))
66
+ out.push(e);
67
+ return out;
68
+ };
69
+ /**
70
+ * The entry unit `home` displays as: at home when no live record wins it,
71
+ * else at its mover (`via`, `at`); `null` when it shows nowhere (gone).
72
+ */
73
+ export const anchorOf = (doc, home) => {
74
+ const u = unitOf(doc, home);
75
+ if (u === null || u.item.gone === true)
76
+ return null;
77
+ const r = u.item.mover ?? null;
78
+ if (r === null || r.deleted)
79
+ return { value: u.value, unit: home, via: null, at: 0 };
80
+ return shownBy(doc, r).find((e) => sameUnit(e.unit, home)) ?? null;
81
+ };
82
+ /** The sequence node that holds `e`'s displaying item (its record's, or its slot's). */
83
+ export const nodeOf = (doc, e) => (e.via !== null ? e.via.parent : unitOf(doc, e.unit).item.parent);
84
+ /** The live index of the item that displays `e` (its record, or its slot unit). */
85
+ const liveIndexOf = (doc, e) => {
86
+ const id = e.via === null ? Y.createID(e.unit.c, e.unit.k) : Y.createID(e.via.id.client, e.via.id.clock);
87
+ return Y.indexOfId(asYDoc(doc), id).index;
88
+ };
89
+ /** `units` as `client, clock, len` triples (one unit each). */
90
+ export const triples = (units) => units.flatMap((u) => [u.c, u.k, 1]);
91
+ /**
92
+ * Write new slots (`payloads`) and/or a move of `moved` (unit triples) into
93
+ * `node`'s sequence right after the displayed entry `left` (at the start when
94
+ * `null`; `right` the entry that follows, if any). When `left` is a unit in
95
+ * the middle of a record's display, the record written here carries that
96
+ * record's later units too, so the new entries show between them. `side` is
97
+ * the record's class among the items of its origin (`0` after, `1` before);
98
+ * `chain` the units the record stands at for the engine's sort of two
99
+ * records at one origin, given its first unit — the home slots from the root
100
+ * sequence down to the unit it stands at (`null`: the first unit alone) — and
101
+ * `part` its order among the records standing there. `shown` reads the units
102
+ * a record shows, as the reader sees them (the index's: a unit a cycle sent
103
+ * back elsewhere is not carried).
104
+ */
105
+ export const placeAfter = (doc, node, left, right, payloads, moved = null, side = 0, part = 0, chain = null, shown = (r) => shownBy(doc, r)) => {
106
+ let index;
107
+ let carry = [];
108
+ if (left === null)
109
+ index = right === null ? node.length : liveIndexOf(doc, right);
110
+ else {
111
+ if (left.via !== null)
112
+ carry = shown(left.via)
113
+ .slice(left.at + 1)
114
+ .map((e) => e.unit);
115
+ // A unit shown at home though its item moved away (a cycle sent it back)
116
+ // is no live unit: the gap after it starts at its live index.
117
+ const live = left.via !== null || unitOf(doc, left.unit)?.item.deleted !== true;
118
+ index = liveIndexOf(doc, left) + (live ? 1 : 0);
119
+ }
120
+ const units = moved === null ? [] : [...moved];
121
+ if (payloads !== null && payloads.length > 0) {
122
+ // The new slots' first unit is this writer's next clock.
123
+ if (carry.length > 0)
124
+ units.push(doc.clientID, storeOf(doc).getClock(doc.clientID), payloads.length);
125
+ node.insert(index, payloads);
126
+ }
127
+ // A carried unit that moves here anyway is named once.
128
+ const named = new Set();
129
+ for (let i = 0; i < units.length; i += 3)
130
+ for (let k = 0; k < units[i + 2]; k++)
131
+ named.add(`${units[i]}:${units[i + 1] + k}`);
132
+ for (const u of carry)
133
+ if (!named.has(`${u.c}:${u.k}`))
134
+ units.push(u.c, u.k, 1);
135
+ if (units.length > 0 && (moved !== null || carry.length > 0)) {
136
+ const first = { c: units[0], k: units[1] };
137
+ const at = chain === null ? null : chain(first);
138
+ // A chain of the first unit alone is the engine's default: not written.
139
+ const own = at !== null && at.length === 1 && sameUnit(at[0], first);
140
+ node.move(index, units, side, part, at === null || own ? null : at.map((u) => Y.createID(u.c, u.k)));
141
+ }
142
+ };
143
+ /** Remove unit `u` from its sequence (the engine's delete: it shows nowhere any more). */
144
+ export const removeUnit = (doc, u) => {
145
+ Y.transact(asYDoc(doc), (tr) => {
146
+ const it = Y.getItemCleanStart(tr, Y.createID(u.c, u.k));
147
+ if (it.length > 1)
148
+ Y.getItemCleanStart(tr, Y.createID(u.c, u.k + 1));
149
+ if (!it.removed)
150
+ ops.remove(tr, it);
151
+ });
152
+ };
@@ -27,14 +27,14 @@
27
27
  export { bindCrdt, type Crdt, type EngineApi, type EngineDoc, type EngineNode, type EngineTransaction, type EngineItemRef, type YNode, type YItem, type YDoc, type YUndoManager, type YTransaction } from './index.js';
28
28
  export { SCHEMA_VERSION, META_KEY } from './edytor-doc.js';
29
29
  export { GENERATION, generationWord, frame, PROTOCOL_VERSION, GENERATION_RECORD, GenerationMismatchError, readProtocolVersion, type GenerationRecord } from './protocols/envelope.js';
30
- export { messageSync, messageAwareness, messageAuth, messageQueryAwareness, messageSaved, messageChunk, messageComments, MAX_FRAME_BYTES, chunkFrame, createChunkReader, ChunkLimitError, type ChunkReader, CLOSE } from './providers/room.js';
30
+ export { messageSync, messageAwareness, messageAuth, messageQueryAwareness, messageSaved, messageChunk, messageComments, MAX_FRAME_BYTES, chunkFrame, createChunkReader, ChunkError, type ChunkReader, CLOSE } from './providers/room.js';
31
31
  export { messageYjsSyncStep1, messageYjsSyncStep2, messageYjsUpdate, type SyncProtocol } from './protocols/sync.js';
32
32
  export { messagePermissionDenied, messageReadOnly, writePermissionDenied, writeReadOnly } from './protocols/auth.js';
33
33
  export { commentsSubscribe, commentsSnapshot, commentsChange, writeCommentsSubscribe, writeCommentsSnapshot, writeCommentsChange, readCommentsMessage, type CommentChange, type CommentMessage, type CommentSnapshot, type CommentThread, type ThreadComment } from './protocols/comments.js';
34
34
  export { applyAwarenessUpdate, encodeAwarenessUpdate, readAwarenessEntries, writeAwarenessEntries, type AwarenessEntry } from './protocols/awareness.js';
35
35
  export { createDecoder, readVarUint, readVarUint8Array, type Decoder } from 'lib0-v14/decoding';
36
36
  export { writeVarUint8Array, type Encoder } from 'lib0-v14/encoding';
37
- export { assertAdmission, assertSchema, assertUsableDoc, checkSchema, inspectAdmission, isInitialized, registryEmpty, schemaVersion, SchemaMismatchError, UndecodableUpdateError, UnsupportedDocError, type AdmissionResult, type AdmissionVerdict, type SchemaProblem } from './admission.js';
37
+ export { assertAdmission, assertSchema, checkSchema, inspectAdmission, isInitialized, registryEmpty, schemaVersion, SchemaMismatchError, UndecodableUpdateError, type AdmissionResult, type AdmissionVerdict, type SchemaProblem } from './admission.js';
38
38
  import type { ProviderStack } from './providers/index.js';
39
39
  export declare const IndexeddbPersistence: ProviderStack['IndexeddbPersistence'];
40
40
  export declare const WebsocketProvider: ProviderStack['WebsocketProvider'];
@@ -30,7 +30,7 @@ export { bindCrdt } from './index.js';
30
30
  export { SCHEMA_VERSION, META_KEY } from './edytor-doc.js';
31
31
  export { GENERATION, generationWord, frame, PROTOCOL_VERSION, GENERATION_RECORD, GenerationMismatchError, readProtocolVersion } from './protocols/envelope.js';
32
32
  // ── Message types, acknowledgements and chunks ─────────────────────────
33
- export { messageSync, messageAwareness, messageAuth, messageQueryAwareness, messageSaved, messageChunk, messageComments, MAX_FRAME_BYTES, chunkFrame, createChunkReader, ChunkLimitError, CLOSE } from './providers/room.js';
33
+ export { messageSync, messageAwareness, messageAuth, messageQueryAwareness, messageSaved, messageChunk, messageComments, MAX_FRAME_BYTES, chunkFrame, createChunkReader, ChunkError, CLOSE } from './providers/room.js';
34
34
  export { messageYjsSyncStep1, messageYjsSyncStep2, messageYjsUpdate } from './protocols/sync.js';
35
35
  export { messagePermissionDenied, messageReadOnly, writePermissionDenied, writeReadOnly } from './protocols/auth.js';
36
36
  export { commentsSubscribe, commentsSnapshot, commentsChange, writeCommentsSubscribe, writeCommentsSnapshot, writeCommentsChange, readCommentsMessage } from './protocols/comments.js';
@@ -46,7 +46,7 @@ export { writeVarUint8Array } from 'lib0-v14/encoding';
46
46
  // the matrix and the refusal-preserves-data contract). The errors they
47
47
  // throw are also exported from `edytor` and `edytor/crdt/edytor`, where a
48
48
  // `loadDocument` caller catches them.
49
- export { assertAdmission, assertSchema, assertUsableDoc, checkSchema, inspectAdmission, isInitialized, registryEmpty, schemaVersion, SchemaMismatchError, UndecodableUpdateError, UnsupportedDocError } from './admission.js';
49
+ export { assertAdmission, assertSchema, checkSchema, inspectAdmission, isInitialized, registryEmpty, schemaVersion, SchemaMismatchError, UndecodableUpdateError } from './admission.js';
50
50
  // ── Raw providers ──────────────────────────────────────────────────────
51
51
  //
52
52
  // The classes `createIndexeddbSync`/`createWebsocketSync` construct, bound
@@ -280,7 +280,7 @@ export declare const bindProviders: (Y: EngineApi) => {
280
280
  off<NAME extends "refused" | "status" | "failed" | "schema-mismatch" | "message-error" | "protocol-mismatch" | "synced" | "connection-close" | "connection-error" | "saved" | "permission-denied" | "expired" | "unreachable">(name: NAME, f: WebsocketProviderEvents[NAME]): void;
281
281
  };
282
282
  };
283
- watchComments: (server: string, roomName: string, listener: (message: import("../protocol.js").CommentMessage) => void) => (() => void);
283
+ watchComments: (server: string | null, roomName: string, listener: (message: import("../protocol.js").CommentMessage) => void) => (() => void);
284
284
  storeState: (idbPersistence: {
285
285
  db: IDBDatabase | null;
286
286
  name: string;
@@ -69,14 +69,15 @@ export declare const MAX_FRAME_BYTES: number;
69
69
  * receiver applies the reassembled frame only once `end` arrives.
70
70
  */
71
71
  export declare const chunkFrame: (whole: Uint8Array, maxFrameBytes?: number) => Uint8Array[];
72
- /** A chunk sequence announces a frame larger than its reader takes ({@link createChunkReader}). */
73
- export declare class ChunkLimitError extends Error {
74
- readonly total: number;
75
- readonly limit: number;
76
- constructor(total: number, limit: number);
77
- }
78
- /** A chunk part or end with no sequence started (one lost, or never sent). */
79
- export declare class ChunkSequenceError extends Error {
72
+ /**
73
+ * A chunk sequence its reader refuses ({@link createChunkReader}): one
74
+ * announcing a frame larger than the reader takes (`total` over `limit`),
75
+ * or a part or end with no sequence started (one lost, or never sent).
76
+ */
77
+ export declare class ChunkError extends Error {
78
+ readonly total?: number | undefined;
79
+ readonly limit?: number | undefined;
80
+ constructor(total?: number | undefined, limit?: number | undefined);
80
81
  }
81
82
  /** A chunk reader ({@link createChunkReader}): feed it chunk bodies; `buffered` is what it holds. */
82
83
  export type ChunkReader = {
@@ -89,7 +90,7 @@ export type ChunkReader = {
89
90
  * each chunk frame's body (after the message type); it returns the whole
90
91
  * frame on `end`, `null` before. An out-of-order or oversized sequence
91
92
  * throws and resets; a sequence announcing more than `maxBytes` throws
92
- * {@link ChunkLimitError} at its start, before anything is buffered. A
93
+ * {@link ChunkError} at its start, before anything is buffered. A
93
94
  * sequence is assembled into ONE buffer of its announced size, allocated
94
95
  * at its start (`buffered`), never into parts copied at its end.
95
96
  * `admit(total)` is asked at each start, before that allocation: it may
@@ -138,13 +139,27 @@ export type LifecycleHost = {
138
139
  _leave: () => void;
139
140
  emit?(event: 'failed', args: [unknown, unknown]): void;
140
141
  };
142
+ /** When a subscriber of {@link onPageLeave} runs: a session's last writes, then the transports. */
143
+ export type PageLeavePhase = 'write' | 'transport';
144
+ /**
145
+ * Be told when the page leaves for good: a `pagehide` of a page the
146
+ * back/forward cache keeps nothing of (a kept page may come back as it was),
147
+ * or, in Node, the process's `exit`. One listener for the page; its
148
+ * subscribers run in two phases whatever order they subscribed in — a
149
+ * session's last writes (`write`: a history's release, `hist.release.end`)
150
+ * before the transports' teardown (`transport`: each provider), so those
151
+ * writes go out while the sockets and stores are still open (listener order
152
+ * on the window is registration order in Chromium, capturing or not).
153
+ * Returns the unsubscribe.
154
+ */
155
+ export declare const onPageLeave: (fn: () => void, phase: PageLeavePhase) => (() => void);
141
156
  /**
142
157
  * Install the lifecycle on a provider: `hasSynced`, `whenSynced`, and the
143
158
  * departure announcement. `beforeunload` only announces it (`depart`): an
144
159
  * app's unsaved-changes prompt fires it and the user may stay, so the
145
160
  * provider keeps running and its presence returns at the next renewal.
146
- * Leaving the page (`pagehide` of a page not kept in the back/forward
147
- * cache; Node: `exit`) destroys the provider, whose teardown announces it.
161
+ * Leaving the page for good ({@link onPageLeave}'s `transport` phase)
162
+ * destroys the provider, whose teardown announces it.
148
163
  */
149
164
  export declare const initLifecycle: (host: LifecycleHost, destroy: () => unknown, depart?: () => void) => void;
150
165
  /** The first sync — lifetime. Returns `true` only the first time. */
@@ -45,6 +45,7 @@ import * as encoding from 'lib0-v14/encoding';
45
45
  import * as decoding from 'lib0-v14/decoding';
46
46
  import * as promise from 'lib0-v14/promise';
47
47
  import { applyAwarenessUpdate, encodeAwarenessUpdate } from '../protocols/awareness.js';
48
+ import { callEach } from '../protocols/observable.js';
48
49
  import { BARE_REPLY_LENGTH, frame, GENERATION, writeProtocolVersion } from '../protocols/envelope.js';
49
50
  import { checkSchema, SchemaMismatchError } from '../admission.js';
50
51
  import { asEngineDoc } from '../structs.js';
@@ -92,26 +93,29 @@ export const chunkFrame = (whole, maxFrameBytes = MAX_FRAME_BYTES) => {
92
93
  frames.push(frame(messageChunk, (e) => encoding.writeVarUint(e, chunkEnd)));
93
94
  return frames;
94
95
  };
95
- /** A chunk sequence announces a frame larger than its reader takes ({@link createChunkReader}). */
96
- export class ChunkLimitError extends Error {
96
+ /**
97
+ * A chunk sequence its reader refuses ({@link createChunkReader}): one
98
+ * announcing a frame larger than the reader takes (`total` over `limit`),
99
+ * or a part or end with no sequence started (one lost, or never sent).
100
+ */
101
+ export class ChunkError extends Error {
97
102
  total;
98
103
  limit;
99
104
  constructor(total, limit) {
100
- super(`chunked frame of ${total} bytes exceeds ${limit}`);
105
+ super(limit === undefined
106
+ ? 'chunk without a start'
107
+ : `chunked frame of ${total} bytes exceeds ${limit}`);
101
108
  this.total = total;
102
109
  this.limit = limit;
103
- this.name = 'ChunkLimitError';
110
+ this.name = 'ChunkError';
104
111
  }
105
112
  }
106
- /** A chunk part or end with no sequence started (one lost, or never sent). */
107
- export class ChunkSequenceError extends Error {
108
- }
109
113
  /**
110
114
  * The receiving half of {@link chunkFrame}, one per connection: feed it
111
115
  * each chunk frame's body (after the message type); it returns the whole
112
116
  * frame on `end`, `null` before. An out-of-order or oversized sequence
113
117
  * throws and resets; a sequence announcing more than `maxBytes` throws
114
- * {@link ChunkLimitError} at its start, before anything is buffered. A
118
+ * {@link ChunkError} at its start, before anything is buffered. A
115
119
  * sequence is assembled into ONE buffer of its announced size, allocated
116
120
  * at its start (`buffered`), never into parts copied at its end.
117
121
  * `admit(total)` is asked at each start, before that allocation: it may
@@ -136,14 +140,14 @@ export const createChunkReader = (maxBytes = Infinity, admit = () => true) => {
136
140
  reset();
137
141
  const announced = decoding.readVarUint(decoder);
138
142
  if (announced > maxBytes)
139
- throw new ChunkLimitError(announced, maxBytes);
143
+ throw new ChunkError(announced, maxBytes);
140
144
  whole = admit(announced) ? new Uint8Array(announced) : null;
141
145
  total = announced;
142
146
  open = true;
143
147
  return null;
144
148
  }
145
149
  if (!open)
146
- throw new ChunkSequenceError(`chunk ${kind} without a start`);
150
+ throw new ChunkError();
147
151
  if (kind === chunkPart) {
148
152
  const bytes = decoding.readVarUint8Array(decoder);
149
153
  if (received + bytes.length > total)
@@ -202,13 +206,68 @@ export const tabs = {
202
206
  };
203
207
  /** The outbound quarantine: a read-only document does not spread. */
204
208
  export const quarantined = (doc) => checkSchema(asEngineDoc(doc)) !== null;
209
+ /**
210
+ * The departures installed, by the page's `addEventListener` (one per realm
211
+ * in a browser; a harness simulating several pages in one realm gives each
212
+ * its own) or, in Node, by the process.
213
+ */
214
+ const departures = new WeakMap();
215
+ /** The page (Node: the process) leaves for good: the writes first, then the transports, each isolated. */
216
+ const leave = (departure) => {
217
+ for (const phase of ['write', 'transport'])
218
+ callEach(`[edytor] page leave (${phase})`, [...departure.leaving[phase]]);
219
+ };
220
+ /**
221
+ * Be told when the page leaves for good: a `pagehide` of a page the
222
+ * back/forward cache keeps nothing of (a kept page may come back as it was),
223
+ * or, in Node, the process's `exit`. One listener for the page; its
224
+ * subscribers run in two phases whatever order they subscribed in — a
225
+ * session's last writes (`write`: a history's release, `hist.release.end`)
226
+ * before the transports' teardown (`transport`: each provider), so those
227
+ * writes go out while the sockets and stores are still open (listener order
228
+ * on the window is registration order in Chromium, capturing or not).
229
+ * Returns the unsubscribe.
230
+ */
231
+ export const onPageLeave = (fn, phase) => {
232
+ const page = globalThis;
233
+ const proc = globalThis.process ?? {};
234
+ const key = page.addEventListener ?? proc;
235
+ let departure = departures.get(key);
236
+ if (departure === undefined) {
237
+ const created = {
238
+ leaving: { write: new Set(), transport: new Set() },
239
+ uninstall: () => { }
240
+ };
241
+ if (page.addEventListener) {
242
+ const hide = (event) => void (event.persisted || leave(created));
243
+ const remove = page.removeEventListener;
244
+ page.addEventListener('pagehide', hide);
245
+ created.uninstall = () => remove?.call(page, 'pagehide', hide);
246
+ }
247
+ else {
248
+ const exit = () => leave(created);
249
+ proc.on?.('exit', exit);
250
+ created.uninstall = () => proc.off?.('exit', exit);
251
+ }
252
+ departures.set(key, (departure = created));
253
+ }
254
+ const own = departure;
255
+ own.leaving[phase].add(fn);
256
+ return () => {
257
+ own.leaving[phase].delete(fn);
258
+ if (own.leaving.write.size + own.leaving.transport.size === 0 && departures.get(key) === own) {
259
+ own.uninstall();
260
+ departures.delete(key);
261
+ }
262
+ };
263
+ };
205
264
  /**
206
265
  * Install the lifecycle on a provider: `hasSynced`, `whenSynced`, and the
207
266
  * departure announcement. `beforeunload` only announces it (`depart`): an
208
267
  * app's unsaved-changes prompt fires it and the user may stay, so the
209
268
  * provider keeps running and its presence returns at the next renewal.
210
- * Leaving the page (`pagehide` of a page not kept in the back/forward
211
- * cache; Node: `exit`) destroys the provider, whose teardown announces it.
269
+ * Leaving the page for good ({@link onPageLeave}'s `transport` phase)
270
+ * destroys the provider, whose teardown announces it.
212
271
  */
213
272
  export const initLifecycle = (host, destroy, depart = () => { }) => {
214
273
  host.hasSynced = false;
@@ -219,21 +278,12 @@ export const initLifecycle = (host, destroy, depart = () => { }) => {
219
278
  // A consumer that never attaches a catch must not crash the process.
220
279
  host.whenSynced.catch(() => { });
221
280
  const page = globalThis;
222
- if (page.addEventListener) {
223
- const leave = (event) => void (event.persisted || destroy());
224
- page.addEventListener('beforeunload', depart);
225
- page.addEventListener('pagehide', leave);
226
- host._leave = () => {
227
- page.removeEventListener?.('beforeunload', depart);
228
- page.removeEventListener?.('pagehide', leave);
229
- };
230
- }
231
- else {
232
- const leave = () => void destroy();
233
- const proc = globalThis.process ?? {};
234
- proc.on?.('exit', leave);
235
- host._leave = () => proc.off?.('exit', leave);
236
- }
281
+ page.addEventListener?.('beforeunload', depart);
282
+ const off = onPageLeave(() => void destroy(), 'transport');
283
+ host._leave = () => {
284
+ page.removeEventListener?.('beforeunload', depart);
285
+ off();
286
+ };
237
287
  };
238
288
  /** The first sync — lifetime. Returns `true` only the first time. */
239
289
  export const markSynced = (host) => {
@@ -228,5 +228,5 @@ export declare const bindWebsocketProvider: (Y: EngineApi) => {
228
228
  off<NAME extends "refused" | "status" | "failed" | "schema-mismatch" | "message-error" | "protocol-mismatch" | "synced" | "connection-close" | "connection-error" | "saved" | "permission-denied" | "expired" | "unreachable">(name: NAME, f: WebsocketProviderEvents[NAME]): void;
229
229
  };
230
230
  };
231
- watchComments: (server: string, roomName: string, listener: (message: CommentMessage) => void) => (() => void);
231
+ watchComments: (server: string | null, roomName: string, listener: (message: CommentMessage) => void) => (() => void);
232
232
  };