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
@@ -5,11 +5,15 @@ import { AbstractStruct, addStructToIdSet } from '../structs/AbstractStruct.js'
5
5
 
6
6
  import { ID, createID, compareIDs, findRootTypeKey } from '../utils/ID.js'
7
7
  import { GC } from '../structs/GC.js'
8
- import { sortsBefore, pairedRole } from '../utils/marks.js' // YP13
8
+ import { sortsBefore, pairedRole, markClass } from '../utils/marks.js' // YP13, YP21
9
+
10
+ import * as math from 'lib0-v14/math' // YP20
9
11
 
10
12
  import {
11
13
  replaceStruct,
12
14
  getItemCleanEnd,
15
+ getItemCleanStart, // YP20
16
+ findIndexSS, // YP20
13
17
  addChangedTypeToTransaction,
14
18
  isKeptReplaced // YP14
15
19
  } from '../utils/transaction-helpers.js'
@@ -107,6 +111,21 @@ export class Item extends AbstractStruct {
107
111
  * @type {number} byte
108
112
  */
109
113
  this.info = this.content.isCountable() ? binary.BIT2 : 0
114
+ /**
115
+ * YP20: how many live hold records (`ContentHold`) name this item. A
116
+ * held item reads as deleted; the count is local, never encoded (each
117
+ * replica counts the records it integrated).
118
+ * @type {number}
119
+ */
120
+ this.holds = 0
121
+ /**
122
+ * YP22: the live move records (`ContentMove`) naming this item, the
123
+ * strongest first — the greatest `(priority, client, clock)` — or `null`.
124
+ * The first is its mover: the item shows there, hidden at home. Local,
125
+ * never encoded.
126
+ * @type {Array<Item>|null}
127
+ */
128
+ this.movers = null
110
129
  }
111
130
 
112
131
  /**
@@ -142,10 +161,38 @@ export class Item extends AbstractStruct {
142
161
  }
143
162
 
144
163
  /**
145
- * Whether this item was deleted or not.
164
+ * Whether this item is hidden at home: removed, held by a live hold record
165
+ * (YP20), or moved by a live move record (YP22: it shows at its mover).
146
166
  * @type {Boolean}
147
167
  */
148
168
  get deleted () {
169
+ return (this.info & binary.BIT3) > 0 || this.holds > 0 || this.movers !== null
170
+ }
171
+
172
+ /**
173
+ * Whether this item shows nowhere: removed or held (YP22; a moved item
174
+ * shows at its mover).
175
+ * @type {Boolean}
176
+ */
177
+ get gone () {
178
+ return (this.info & binary.BIT3) > 0 || this.holds > 0
179
+ }
180
+
181
+ /**
182
+ * YP22: the live move record this item shows at (the strongest of
183
+ * `movers`), or `null` at home.
184
+ * @type {Item|null}
185
+ */
186
+ get mover () {
187
+ return this.movers === null ? null : this.movers[0]
188
+ }
189
+
190
+ /**
191
+ * Whether the engine deleted this item (the delete set's fact; YP20: a held
192
+ * item is hidden, not removed).
193
+ * @type {Boolean}
194
+ */
195
+ get removed () {
149
196
  return (this.info & binary.BIT3) > 0
150
197
  }
151
198
 
@@ -206,7 +253,7 @@ export class Item extends AbstractStruct {
206
253
  conflictingItems.add(o)
207
254
  if (compareIDs(this.origin, o.origin)) {
208
255
  // case 1
209
- if (sortsBefore(o, this)) { // YP13: paired marks sort by side, then by client id
256
+ if (sortsBefore(o, this, transaction)) { // YP13: paired marks sort by side, then by client id
210
257
  left = o
211
258
  conflictingItems.clear()
212
259
  } else if (compareIDs(this.rightOrigin, o.rightOrigin)) {
@@ -266,7 +313,7 @@ export class Item extends AbstractStruct {
266
313
  addChangedTypeToTransaction(transaction, /** @type {YNode} */ (this.parent), this.parentSub)
267
314
  const parentItem = /** @type {YNode} */ (this.parent)._item
268
315
  // YP14: a node a concurrent value replaced keeps its subtree: what lands in it stays
269
- if ((parentItem !== null && parentItem.deleted && !isKeptReplaced(parentItem)) || (this.parentSub !== null && this.right !== null)) {
316
+ if ((parentItem !== null && parentItem.removed && !isKeptReplaced(parentItem)) || (this.parentSub !== null && this.right !== null)) { // YP20: a held parent is alive
270
317
  // delete if parent is deleted or if this is not the current attribute value of parent
271
318
  this.delete(transaction)
272
319
  }
@@ -298,7 +345,9 @@ export class Item extends AbstractStruct {
298
345
  compareIDs(this.rightOrigin, right.rightOrigin) &&
299
346
  this.id.client === right.id.client &&
300
347
  this.id.clock + this.length === right.id.clock &&
301
- this.deleted === right.deleted &&
348
+ this.removed === right.removed &&
349
+ this.holds === right.holds && // YP20
350
+ this.movers === null && right.movers === null && // YP22: a moved unit stands alone
302
351
  this.redone === null &&
303
352
  right.redone === null &&
304
353
  this.content.constructor === right.content.constructor &&
@@ -339,10 +388,16 @@ export class Item extends AbstractStruct {
339
388
  * @param {Transaction} transaction
340
389
  */
341
390
  delete (transaction) {
342
- if (!this.deleted) {
391
+ if (!this.removed) {
343
392
  const parent = /** @type {YNode} */ (this.parent)
344
393
  // adjust the length of parent
345
- if (this.countable && this.parentSub === null) {
394
+ if (this.holds > 0) {
395
+ // YP20: already hidden — the delete set counts it again, the log gives it back
396
+ logHold(transaction, this, this.length)
397
+ } else if (this.movers !== null) {
398
+ // YP22: hidden at home already; its mover shows it no more (`gone`)
399
+ logMove(transaction, this, this.mover)
400
+ } else if (this.countable && this.parentSub === null) {
346
401
  parent._length -= this.length
347
402
  }
348
403
  // WU9 format-aware markers: tombstoning a format item changes the format
@@ -358,7 +413,7 @@ export class Item extends AbstractStruct {
358
413
  transaction.deleteSet.add(this.id.client, this.id.clock, this.length)
359
414
  addChangedTypeToTransaction(transaction, parent, this.parentSub)
360
415
  // YP14: a node a concurrent value replaced keeps its subtree (the document asked)
361
- if (!isKeptReplaced(this)) this.content.delete(transaction)
416
+ if (!isKeptReplaced(this)) this.content.delete(transaction, this) // YP22: a move record drops itself from its units' movers
362
417
  }
363
418
  }
364
419
 
@@ -367,16 +422,28 @@ export class Item extends AbstractStruct {
367
422
  * @param {boolean} parentGCd
368
423
  */
369
424
  gc (tr, parentGCd) {
370
- if (!this.deleted) {
425
+ if (!this.removed) { // YP20
371
426
  throw error.unexpectedCase()
372
427
  }
373
428
  this.content.gc(tr)
374
429
  if (parentGCd) {
375
430
  replaceStruct(tr, this, new GC(this.id, this.length))
376
- } else if (!(this.content.constructor === ContentFormat && pairedRole(/** @type {ContentFormat} */ (this.content)) >= 0)) {
377
- // YP13: a paired mark item keeps its content: its side orders
378
- // concurrent inserts (`markClass`) on every replica, collected or not.
379
- this.content = new ContentDeleted(this.length)
431
+ } else {
432
+ // YP13, YP21, YP22, YP29: an item of another class than content keeps
433
+ // what orders concurrent inserts at its origin (`markClass`) on every
434
+ // replica, collected or not: a paired mark item or a claim item its
435
+ // class, a move record its content (its sort reads its chain). A block
436
+ // slot a split made keeps its split key the same way (`splitKey`),
437
+ // trimmed to it.
438
+ const cls = markClass(this)
439
+ const arr = /** @type {any} */ (this.content).arr
440
+ if (cls === 1) {
441
+ const keys = arr?.map((/** @type {any} */ v) => (Array.isArray(v?.s) ? { s: v.s } : null))
442
+ this.content = keys?.some((/** @type {any} */ k) => k !== null) ? new ContentAny(keys) : new ContentDeleted(this.length)
443
+ } else if (cls < 3 || (cls === 3 && arr?.every((/** @type {any} */ v) => typeof v?.m === 'string'))) {
444
+ // every unit of the item has its class (a mark is one unit; merged claims all are claims)
445
+ this.content = new ContentDeleted(this.length, cls)
446
+ }
380
447
  }
381
448
  }
382
449
 
@@ -399,9 +466,11 @@ export class Item extends AbstractStruct {
399
466
  this.parentSub,
400
467
  this.content.splice(diff)
401
468
  )
402
- if (this.deleted) {
469
+ if (this.removed) { // YP20
403
470
  rightItem.markDeleted()
404
471
  }
472
+ rightItem.holds = this.holds // YP20
473
+ rightItem.movers = this.movers?.slice() ?? null // YP22
405
474
  if (this.keep) {
406
475
  rightItem.keep = true
407
476
  }
@@ -443,10 +512,15 @@ export class Item extends AbstractStruct {
443
512
  const origin = offset > 0 ? createID(this.id.client, this.id.clock + offset - 1) : this.origin
444
513
  const rightOrigin = this.rightOrigin
445
514
  const parentSub = this.parentSub
446
- const info = (this.content.getRef() & binary.BITS5) |
515
+ const parent = /** @type {any} */ (this.parent)
516
+ // YP27: an item written with its parent says in bit 5 whether the parent is
517
+ // a root (its name follows) or an item (its id follows): no parentInfo column
518
+ const named = origin === null && rightOrigin === null && (parent.constructor === String || parent._item === null)
519
+ const info = (this.content.getRef() & binary.BITS4) | // YP27: content refs fit four bits
447
520
  (origin === null ? 0 : binary.BIT8) | // origin is defined
448
521
  (rightOrigin === null ? 0 : binary.BIT7) | // right origin is defined
449
- (parentSub === null ? 0 : binary.BIT6) // parentSub is non-null
522
+ (parentSub === null ? 0 : binary.BIT6) | // parentSub is non-null
523
+ (named ? binary.BIT5 : 0) // YP27: the parent is a root, by name
450
524
  encoder.writeInfo(info)
451
525
  if (origin !== null) {
452
526
  encoder.writeLeftID(origin)
@@ -455,33 +529,21 @@ export class Item extends AbstractStruct {
455
529
  encoder.writeRightID(rightOrigin)
456
530
  }
457
531
  if (origin === null && rightOrigin === null) {
458
- const parent = /** @type {YNode} */ (this.parent)
459
- if (parent._item !== undefined) {
460
- const parentItem = parent._item
461
- if (parentItem === null) {
462
- // parent type on y._map
463
- // find the correct key
464
- const ykey = findRootTypeKey(parent)
465
- encoder.writeParentInfo(true) // write parentYKey
466
- encoder.writeString(ykey)
467
- } else {
468
- encoder.writeParentInfo(false) // write parent id
469
- encoder.writeLeftID(parentItem.id)
470
- }
471
- } else if (parent.constructor === String) { // this edge case was added by differential updates
472
- encoder.writeParentInfo(true) // write parentYKey
473
- encoder.writeString(parent)
532
+ if (named) {
533
+ // a root's name (a string parent: an edge case of differential updates)
534
+ encoder.writeKey(parent.constructor === String ? /** @type {string} */ (parent) : findRootTypeKey(parent)) // YP24
474
535
  } else if (parent.constructor === ID) {
475
- encoder.writeParentInfo(false) // write parent id
476
536
  encoder.writeLeftID(parent)
537
+ } else if (parent._item) {
538
+ encoder.writeLeftID(parent._item.id)
477
539
  } else {
478
540
  error.unexpectedCase()
479
541
  }
480
542
  if (parentSub !== null) {
481
- encoder.writeString(parentSub)
543
+ encoder.writeKey(parentSub) // YP24
482
544
  }
483
545
  }
484
- this.content.write(encoder, offset, offsetEnd)
546
+ this.content.write(encoder, offset, offsetEnd, this) // YP25: a format item reads its own id
485
547
  }
486
548
 
487
549
  get ref () {
@@ -558,8 +620,9 @@ export class AbstractContent {
558
620
 
559
621
  /**
560
622
  * @param {Transaction} _transaction
623
+ * @param {Item} [_item] the item deleted (YP22: a move record reads it)
561
624
  */
562
- delete (_transaction) {
625
+ delete (_transaction, _item) {
563
626
  throw error.methodUnimplemented()
564
627
  }
565
628
 
@@ -574,15 +637,16 @@ export class AbstractContent {
574
637
  * @param {UpdateEncoder} _encoder
575
638
  * @param {number} _offset
576
639
  * @param {number} _offsetEnd
640
+ * @param {Item} [_item] the item written (YP25: a format item reads its id)
577
641
  */
578
- write (_encoder, _offset, _offsetEnd) {
642
+ write (_encoder, _offset, _offsetEnd, _item) {
579
643
  throw error.methodUnimplemented()
580
644
  }
581
645
 
582
646
  /**
583
- * @return {1|2|3|4|5|6|7|8|9}
647
+ * @return {1|2|3|4|5|6|7|8|9|11|12|13}
584
648
  */
585
- getRef () {
649
+ getRef () { // YP20: 11, a hold record; YP22: 12, a move record; YP29: 13, a collected mark's class
586
650
  throw error.methodUnimplemented()
587
651
  }
588
652
  }
@@ -766,9 +830,19 @@ export class ContentBinary {
766
830
  export class ContentDeleted {
767
831
  /**
768
832
  * @param {number} len
833
+ * @param {number} [cls] YP29: a collected mark's or claim's sort class
769
834
  */
770
- constructor (len) {
835
+ constructor (len, cls) {
771
836
  this.len = len
837
+ /**
838
+ * YP29: what a collected paired mark item or claim item keeps, for each
839
+ * of its units: its sort class (`markClass`: `0` a left-side mark, `2` a
840
+ * right-side one, `3` a claim), which orders concurrent inserts at its
841
+ * origin on every replica (`undefined`: none, any other deleted content).
842
+ *
843
+ * @type {number|undefined}
844
+ */
845
+ this.cls = cls
772
846
  }
773
847
 
774
848
  /**
@@ -789,14 +863,14 @@ export class ContentDeleted {
789
863
  * @return {boolean}
790
864
  */
791
865
  isCountable () {
792
- return false
866
+ return this.cls === 3 // YP29: a claim is a unit of its text
793
867
  }
794
868
 
795
869
  /**
796
870
  * @return {ContentDeleted}
797
871
  */
798
872
  copy () {
799
- return new ContentDeleted(this.len)
873
+ return new ContentDeleted(this.len, this.cls)
800
874
  }
801
875
 
802
876
  /**
@@ -804,7 +878,7 @@ export class ContentDeleted {
804
878
  * @return {ContentDeleted}
805
879
  */
806
880
  splice (offset) {
807
- const right = new ContentDeleted(this.len - offset)
881
+ const right = new ContentDeleted(this.len - offset, this.cls)
808
882
  this.len = offset
809
883
  return right
810
884
  }
@@ -814,6 +888,7 @@ export class ContentDeleted {
814
888
  * @return {boolean}
815
889
  */
816
890
  mergeWith (right) {
891
+ if (right.cls !== this.cls) return false // YP29
817
892
  this.len += right.len
818
893
  return true
819
894
  }
@@ -841,20 +916,502 @@ export class ContentDeleted {
841
916
  * @param {number} offsetEnd
842
917
  */
843
918
  write (encoder, offset, offsetEnd) {
844
- encoder.writeLen(this.len - offset - offsetEnd)
919
+ const len = this.len - offset - offsetEnd
920
+ encoder.writeLen(this.cls === undefined ? len : len * 4 + this.cls) // YP29
845
921
  }
846
922
 
847
923
  /**
848
- * @return {1}
924
+ * @return {1|13}
849
925
  */
850
926
  getRef () {
927
+ return this.cls === undefined ? 1 : 13 // YP29: 13, a collected mark or claim
928
+ }
929
+ }
930
+
931
+ // YP20 begin (edytor fork: hold records — see UPSTREAM.md YP20)
932
+ /**
933
+ * Log that a hold changed `item`'s visibility (`len > 0`: shown, `< 0`:
934
+ * hidden) in `tr.holds`, in order, and its parent as changed.
935
+ *
936
+ * @param {Transaction} tr
937
+ * @param {Item} item
938
+ * @param {number} len
939
+ */
940
+ const logHold = (tr, item, len) => {
941
+ tr.holds.push(item.id.client, item.id.clock, len)
942
+ addChangedTypeToTransaction(tr, /** @type {YNode} */ (item.parent), item.parentSub)
943
+ }
944
+
945
+ /**
946
+ * Add `delta` (1, or -1: release) of a hold record (`record` null: `holds`)
947
+ * or of the move record `record` (its `movers`, YP22; a record never moves a
948
+ * record) to `item`. An item that is not removed and starts or stops being
949
+ * hidden moves its parent's length and drops its search markers; a hold that
950
+ * does is logged (`tr.holds`), and so is a unit whose mover changed
951
+ * (`tr.moves`).
952
+ *
953
+ * @param {Transaction} tr
954
+ * @param {Item} item
955
+ * @param {number} delta
956
+ * @param {Item|null} record
957
+ */
958
+ const holdItem = (tr, item, delta, record) => {
959
+ const was = item.deleted
960
+ const before = item.mover
961
+ if (record === null) item.holds += delta
962
+ else if (item.content.constructor === ContentMove) return
963
+ else if (delta > 0) {
964
+ const m = (item.movers ??= [])
965
+ const i = m.findIndex(r => stronger(record, r))
966
+ m.splice(i < 0 ? m.length : i, 0, record)
967
+ }
968
+ else if (item.movers !== null) {
969
+ const i = item.movers.indexOf(record)
970
+ if (i >= 0) item.movers.splice(i, 1)
971
+ if (item.movers.length === 0) item.movers = null
972
+ }
973
+ if (was !== item.deleted) {
974
+ const parent = /** @type {YNode} */ (item.parent)
975
+ const len = was ? item.length : -item.length
976
+ if (item.countable && item.parentSub === null) parent._length += len
977
+ // the indices the search markers counted moved (a held delete moves them itself)
978
+ if (parent._searchMarker) parent._searchMarker.length = 0
979
+ if (record === null) logHold(tr, item, len)
980
+ }
981
+ const after = item.mover
982
+ if (before !== after) {
983
+ logMove(tr, item, after)
984
+ if (before !== null) addChangedTypeToTransaction(tr, /** @type {YNode} */ (before.parent), null)
985
+ }
986
+ }
987
+
988
+ /**
989
+ * A hold this replica cannot apply yet (its items have not arrived): it waits
990
+ * in `store.pendingHolds` (`client → [clock, len, delta, …]`).
991
+ *
992
+ * @param {import('../utils/StructStore.js').StructStore} store
993
+ * @param {number} client
994
+ * @param {number} from
995
+ * @param {number} to
996
+ * @param {number} delta
997
+ */
998
+ const pendHold = (store, client, from, to, delta) => {
999
+ const pending = store.pendingHolds ?? (store.pendingHolds = new Map())
1000
+ const list = pending.get(client)
1001
+ if (list === undefined) pending.set(client, [from, to - from, delta])
1002
+ else list.push(from, to - from, delta)
1003
+ }
1004
+
1005
+ /**
1006
+ * Hold (`delta` 1) or release (-1) the ids `client:clock … clock+len-1`, or
1007
+ * add or drop the move record `record` on them (YP22): the items here take
1008
+ * it now, split at the edges; what this replica lacks (past its clock, or a
1009
+ * Skip) waits until it integrates (`applyPending`) — a hold's only: a move
1010
+ * record integrates once every unit it names has, and no Skip stands for
1011
+ * one (`getMissing`). A GC struct takes nothing (it is gone everywhere).
1012
+ *
1013
+ * @param {Transaction} tr
1014
+ * @param {number} client
1015
+ * @param {number} clock
1016
+ * @param {number} len
1017
+ * @param {number} delta
1018
+ * @param {Item|null} [record]
1019
+ */
1020
+ const holdRange = (tr, client, clock, len, delta, record = null) => {
1021
+ const store = tr.doc.store
1022
+ const structs = /** @type {Array<GC|Item>} */ (store.clients.get(client))
1023
+ const end = clock + len
1024
+ const state = store.getClock(client)
1025
+ if (end > state) pendHold(store, client, math.max(clock, state), end, delta)
1026
+ for (let k = clock; k < math.min(end, state);) {
1027
+ let struct = structs[findIndexSS(structs, k)]
1028
+ const to = math.min(struct.id.clock + struct.length, end)
1029
+ if (struct.isItem) {
1030
+ if (struct.id.clock < k) struct = getItemCleanStart(tr, createID(client, k))
1031
+ if (struct.id.clock + struct.length > to) getItemCleanStart(tr, createID(client, to))
1032
+ holdItem(tr, /** @type {Item} */ (struct), delta, record)
1033
+ } else if (!struct.deleted) {
1034
+ pendHold(store, client, k, to, delta) // a Skip
1035
+ }
1036
+ k = to
1037
+ }
1038
+ }
1039
+
1040
+ /**
1041
+ * Hold or release (`delta`) the items `ids` names (`client, clock, len`
1042
+ * triples), or add or drop the move record `record` on them.
1043
+ *
1044
+ * @param {Transaction} tr
1045
+ * @param {Array<number>} ids
1046
+ * @param {number} delta
1047
+ * @param {Item|null} [record]
1048
+ */
1049
+ const holdIds = (tr, ids, delta, record = null) => {
1050
+ for (let i = 0; i < ids.length; i += 3) holdRange(tr, ids[i], ids[i + 1], ids[i + 2], delta, record)
1051
+ }
1052
+
1053
+ /**
1054
+ * Write the id ranges `ids[from … to)` (`client, clock, len` triples): their
1055
+ * count, then each as a left id and a length (a hold record's and a move
1056
+ * record's ranges).
1057
+ *
1058
+ * @param {UpdateEncoder} encoder
1059
+ * @param {Array<number>} ids
1060
+ * @param {number} from
1061
+ * @param {number} to
1062
+ */
1063
+ const writeIds = (encoder, ids, from, to) => {
1064
+ encoder.writeLen((to - from) / 3)
1065
+ for (let i = from; i < to; i += 3) {
1066
+ encoder.writeLeftID(createID(ids[i], ids[i + 1]))
1067
+ encoder.writeLen(ids[i + 2])
1068
+ }
1069
+ }
1070
+
1071
+ /**
1072
+ * A hold record: one unit per held id range (`client, clock, len`). While the
1073
+ * record is live, the items it names read as deleted; deleting the record
1074
+ * shows them again (an undo), unless another live record holds them. A record
1075
+ * integrates at once; what it names that has not arrived takes its hold when
1076
+ * it does (`applyPending`).
1077
+ */
1078
+ export class ContentHold {
1079
+ /**
1080
+ * @param {Array<number>} ids
1081
+ */
1082
+ constructor (ids) {
1083
+ this.ids = ids
1084
+ }
1085
+
1086
+ /**
1087
+ * @return {number}
1088
+ */
1089
+ getLength () {
1090
+ return this.ids.length / 3
1091
+ }
1092
+
1093
+ /**
1094
+ * @return {Array<any>}
1095
+ */
1096
+ getContent () {
1097
+ const out = []
1098
+ for (let i = 0; i < this.ids.length; i += 3) out.push(this.ids.slice(i, i + 3))
1099
+ return out
1100
+ }
1101
+
1102
+ /**
1103
+ * @return {boolean}
1104
+ */
1105
+ isCountable () {
1106
+ return true
1107
+ }
1108
+
1109
+ /**
1110
+ * @return {ContentHold}
1111
+ */
1112
+ copy () {
1113
+ return new ContentHold(this.ids)
1114
+ }
1115
+
1116
+ /**
1117
+ * @param {number} offset
1118
+ * @return {ContentHold}
1119
+ */
1120
+ splice (offset) {
1121
+ const right = new ContentHold(this.ids.slice(offset * 3))
1122
+ this.ids = this.ids.slice(0, offset * 3)
1123
+ return right
1124
+ }
1125
+
1126
+ /**
1127
+ * @param {ContentHold} right
1128
+ * @return {boolean}
1129
+ */
1130
+ mergeWith (right) {
1131
+ this.ids = this.ids.concat(right.ids)
1132
+ return true
1133
+ }
1134
+
1135
+ /**
1136
+ * @param {Transaction} transaction
1137
+ * @param {Item} _item
1138
+ */
1139
+ integrate (transaction, _item) {
1140
+ holdIds(transaction, this.ids, 1)
1141
+ }
1142
+
1143
+ /**
1144
+ * @param {Transaction} transaction
1145
+ */
1146
+ delete (transaction) {
1147
+ holdIds(transaction, this.ids, -1)
1148
+ }
1149
+
1150
+ /**
1151
+ * @param {Transaction} _tr
1152
+ */
1153
+ gc (_tr) {}
1154
+
1155
+ /**
1156
+ * @param {UpdateEncoder} encoder
1157
+ * @param {number} offset
1158
+ * @param {number} offsetEnd
1159
+ */
1160
+ write (encoder, offset, offsetEnd) {
1161
+ writeIds(encoder, this.ids, offset * 3, this.ids.length - offsetEnd * 3)
1162
+ }
1163
+
1164
+ /**
1165
+ * @return {11}
1166
+ */
1167
+ getRef () {
1168
+ return 11
1169
+ }
1170
+ }
1171
+ // YP20 end
1172
+
1173
+ // YP22 begin (edytor fork: move records — see UPSTREAM.md YP22)
1174
+ /**
1175
+ * Whether move record `a` beats `b`: the greater `(priority, client, clock)`
1176
+ * (a unit's `movers` are kept in that order, the strongest first).
1177
+ *
1178
+ * @param {Item} a
1179
+ * @param {Item} b
1180
+ * @return {boolean}
1181
+ */
1182
+ const stronger = (a, b) =>
1183
+ (/** @type {ContentMove} */ (a.content).priority - /** @type {ContentMove} */ (b.content).priority || a.id.client - b.id.client || a.id.clock - b.id.clock) > 0
1184
+
1185
+ /**
1186
+ * Log that `item`'s mover changed (or it left its mover: removed) in
1187
+ * `tr.moves`, in order, and its home and its new mover's sequences as changed.
1188
+ *
1189
+ * @param {Transaction} tr
1190
+ * @param {Item} item
1191
+ * @param {Item|null} mover
1192
+ */
1193
+ const logMove = (tr, item, mover) => {
1194
+ tr.moves.push(item.id.client, item.id.clock, item.length)
1195
+ addChangedTypeToTransaction(tr, /** @type {YNode} */ (item.parent), item.parentSub)
1196
+ if (mover !== null) addChangedTypeToTransaction(tr, /** @type {YNode} */ (mover.parent), null)
1197
+ }
1198
+
1199
+ /**
1200
+ * Apply the holds (YP20) that waited for items of `clients` an update just
1201
+ * integrated (what is still missing waits on).
1202
+ *
1203
+ * @param {Transaction} tr
1204
+ * @param {Array<number>} clients
1205
+ */
1206
+ export const applyPending = (tr, clients) => {
1207
+ const store = tr.doc.store
1208
+ for (const client of clients) {
1209
+ const holds = store.pendingHolds?.get(client)
1210
+ if (holds !== undefined) {
1211
+ /** @type {Map<number, Array<number>>} */ (store.pendingHolds).delete(client)
1212
+ for (let i = 0; i < holds.length; i += 3) holdRange(tr, client, holds[i], holds[i + 1], holds[i + 2])
1213
+ }
1214
+ }
1215
+ if (store.pendingHolds?.size === 0) store.pendingHolds = null
1216
+ }
1217
+
1218
+ /**
1219
+ * A move record: one countable unit at its destination, naming the units
1220
+ * it moves (`client, clock, len` ranges, in the order they show) with a
1221
+ * Lamport `priority`, a `side` (`0`: it stands after what precedes it,
1222
+ * `1`: before what follows it — its sort class among the items of one
1223
+ * origin, `markClass`), and for the sort of two records at one origin
1224
+ * (`utils/marks.js` `sourceOrder`) the chain of units it stands at (`at`:
1225
+ * the home slots from the root sequence down to that unit, else the first
1226
+ * unit it names) and its `part` there. While the record is live, each named unit shows at
1227
+ * the record that wins its movers and is hidden at home; deleting the
1228
+ * record (an undo) hands the unit to the next record, else home. A record
1229
+ * waits for the units it names as an item waits for its origin
1230
+ * (`getMissing`), so two records at one origin sort by their units' home
1231
+ * order on every replica (`sourceOrder`). Immutable once written, so
1232
+ * replicas converge in any order. The record's item is the one integrating
1233
+ * or deleting it (it is what the units' `movers` hold).
1234
+ */
1235
+ export class ContentMove {
1236
+ /**
1237
+ * @param {number} priority
1238
+ * @param {number} side
1239
+ * @param {Array<number>} ids
1240
+ * @param {number} [part] the writer's order among the records standing at one unit (0–7)
1241
+ * @param {Array<ID>|null} [at] the chain the record stands at, outermost first (`null`: the first unit it names)
1242
+ */
1243
+ constructor (priority, side, ids, part = 0, at = null) {
1244
+ this.priority = priority
1245
+ this.side = side
1246
+ this.ids = ids
1247
+ this.part = part
1248
+ this.at = at
1249
+ }
1250
+
1251
+ /**
1252
+ * @return {number}
1253
+ */
1254
+ getLength () {
851
1255
  return 1
852
1256
  }
1257
+
1258
+ /**
1259
+ * @return {Array<any>}
1260
+ */
1261
+ getContent () {
1262
+ return [this]
1263
+ }
1264
+
1265
+ /**
1266
+ * @return {boolean}
1267
+ */
1268
+ isCountable () {
1269
+ return true
1270
+ }
1271
+
1272
+ /**
1273
+ * @return {ContentMove}
1274
+ */
1275
+ copy () {
1276
+ return new ContentMove(this.priority, this.side, this.ids, this.part, this.at)
1277
+ }
1278
+
1279
+ /**
1280
+ * @param {number} _offset
1281
+ * @return {ContentMove}
1282
+ */
1283
+ splice (_offset) {
1284
+ throw error.methodUnimplemented()
1285
+ }
1286
+
1287
+ /**
1288
+ * @param {ContentMove} _right
1289
+ * @return {boolean}
1290
+ */
1291
+ mergeWith (_right) {
1292
+ return false
1293
+ }
1294
+
1295
+ /**
1296
+ * @param {Transaction} transaction
1297
+ * @param {Item} item
1298
+ */
1299
+ integrate (transaction, item) {
1300
+ const doc = /** @type {any} */ (transaction.doc)
1301
+ // A peer's record raises the clock; this writer's own leave it, so its
1302
+ // next records stay level with these until it sees a peer's.
1303
+ if (!transaction.local && this.priority > doc._clock) doc._clock = this.priority
1304
+ holdIds(transaction, this.ids, 1, item)
1305
+ }
1306
+
1307
+ /**
1308
+ * @param {Transaction} transaction
1309
+ * @param {Item} item
1310
+ */
1311
+ delete (transaction, item) {
1312
+ holdIds(transaction, this.ids, -1, item)
1313
+ }
1314
+
1315
+ /**
1316
+ * @param {Transaction} _tr
1317
+ */
1318
+ gc (_tr) {}
1319
+
1320
+ /**
1321
+ * @param {UpdateEncoder} encoder
1322
+ * @param {number} _offset
1323
+ * @param {number} _offsetEnd
1324
+ */
1325
+ write (encoder, _offset, _offsetEnd) {
1326
+ // One varint: the priority, whether an anchor chain follows, the part, the side.
1327
+ encoder.writeLen(this.priority * 32 + (this.at === null ? 0 : 16) + this.part * 2 + this.side)
1328
+ if (this.at !== null) {
1329
+ encoder.writeLen(this.at.length)
1330
+ for (const id of this.at) encoder.writeLeftID(id)
1331
+ }
1332
+ writeIds(encoder, this.ids, 0, this.ids.length)
1333
+ }
1334
+
1335
+ /**
1336
+ * @return {12}
1337
+ */
1338
+ getRef () {
1339
+ return 12
1340
+ }
853
1341
  }
1342
+ // YP22 end
854
1343
 
855
1344
  /**
856
1345
  * @private
857
1346
  */
1347
+ // YP25 begin (edytor fork: paired marks written natively — see UPSTREAM.md YP25)
1348
+ /**
1349
+ * Whether `x` is a non-negative integer (a clock, a client id, a stamp).
1350
+ *
1351
+ * @param {any} x
1352
+ * @return {boolean}
1353
+ */
1354
+ const natural = x => Number.isInteger(x) && x >= 0
1355
+
1356
+ /**
1357
+ * Write a format item's value. A paired mark's (YP13) is written in parts: a
1358
+ * flags length — bit 0 its side; bit 1 a start's operation id is the item's
1359
+ * own, an end's start is the item's own client (its clock follows as a
1360
+ * distance); bit 2 a start's value is `true`, bit 3 `null` — then a start's
1361
+ * Lamport stamp, the operation id where the flags do not imply it, and a
1362
+ * start's value where it is neither `true` nor `null`. Any other value (a
1363
+ * plain format, a value of another shape) is flagged `16` and written whole.
1364
+ *
1365
+ * @param {UpdateEncoder} encoder
1366
+ * @param {ContentFormat} content
1367
+ * @param {Item} [item]
1368
+ */
1369
+ const writeFormatValue = (encoder, content, item) => {
1370
+ const v = /** @type {any} */ (content.value)
1371
+ const role = pairedRole(content)
1372
+ if (role === 0 && Array.isArray(v) && v.length === 5 && natural(v[1]) && natural(v[2]) && natural(v[3]) && (v[4] === 0 || v[4] === 1)) {
1373
+ const own = item !== undefined && v[2] === item.id.client && v[3] === item.id.clock
1374
+ const tail = v[0] === true ? 4 : v[0] === null ? 8 : 0
1375
+ encoder.writeLen(v[4] | (own ? 2 : 0) | tail)
1376
+ encoder.writeLen(v[1])
1377
+ if (!own) encoder.writeLeftID(createID(v[2], v[3]))
1378
+ if (tail === 0) encoder.writeJSON(v[0])
1379
+ } else if (role === 1 && Array.isArray(v) && v.length === 3 && natural(v[0]) && natural(v[1]) && (v[2] === 0 || v[2] === 1)) {
1380
+ const near = item !== undefined && v[0] === item.id.client && v[1] <= item.id.clock
1381
+ encoder.writeLen(v[2] | (near ? 2 : 0))
1382
+ if (near) encoder.writeLen(/** @type {Item} */ (item).id.clock - v[1])
1383
+ else encoder.writeLeftID(createID(v[0], v[1]))
1384
+ } else {
1385
+ encoder.writeLen(16)
1386
+ encoder.writeJSON(v)
1387
+ }
1388
+ }
1389
+
1390
+ /**
1391
+ * Read a format item's value (`writeFormatValue`): `id` is the item's.
1392
+ *
1393
+ * @param {UpdateDecoder} decoder
1394
+ * @param {string} key
1395
+ * @param {ID} id
1396
+ * @return {any}
1397
+ */
1398
+ export const readFormatValue = (decoder, key, id) => {
1399
+ const flags = decoder.readLen()
1400
+ if ((flags & 16) !== 0) return decoder.readJSON()
1401
+ const side = flags & 1
1402
+ const role = pairedRole({ key })
1403
+ if (role === 0) {
1404
+ const l = decoder.readLen()
1405
+ const at = (flags & 2) !== 0 ? id : decoder.readLeftID()
1406
+ const v = (flags & 4) !== 0 ? true : (flags & 8) !== 0 ? null : decoder.readJSON()
1407
+ return [v, l, at.client, at.clock, side]
1408
+ }
1409
+ if (role !== 1) error.unexpectedCase()
1410
+ const at = (flags & 2) !== 0 ? createID(id.client, id.clock - decoder.readLen()) : decoder.readLeftID()
1411
+ return [at.client, at.clock, side]
1412
+ }
1413
+ // YP25 end
1414
+
858
1415
  export class ContentFormat {
859
1416
  /**
860
1417
  * @param {string} key
@@ -916,11 +1473,12 @@ export class ContentFormat {
916
1473
  integrate (_transaction, item) {
917
1474
  // Format items are non-countable: no marker index shifts (YP4).
918
1475
  // YP13: a paired mark's start carries its Lamport timestamp; the document
919
- // keeps the greatest it saw, so the next mark it writes wins over it.
1476
+ // keeps the greatest it saw (YP22: one clock with the move records), so the
1477
+ // next mark or move it writes wins over it.
920
1478
  if (pairedRole(this) === 0) {
921
1479
  const doc = /** @type {any} */ (_transaction.doc)
922
1480
  const l = /** @type {Array<any>} */ (this.value)[1]
923
- if (l > doc._markClock) doc._markClock = l
1481
+ if (l > doc._clock) doc._clock = l
924
1482
  }
925
1483
  }
926
1484
 
@@ -936,10 +1494,11 @@ export class ContentFormat {
936
1494
  * @param {UpdateEncoder} encoder
937
1495
  * @param {number} _offset
938
1496
  * @param {number} _offsetEnd
1497
+ * @param {Item} [item] YP25: the item, whose id a mark's operation id usually is
939
1498
  */
940
- write (encoder, _offset, _offsetEnd) {
1499
+ write (encoder, _offset, _offsetEnd, item) {
941
1500
  encoder.writeKey(this.key)
942
- encoder.writeJSON(this.value)
1501
+ writeFormatValue(encoder, this, item) // YP25
943
1502
  }
944
1503
 
945
1504
  /**
@@ -1132,7 +1691,7 @@ export class ContentType {
1132
1691
  delete (transaction) {
1133
1692
  let item = this.type._start
1134
1693
  while (item !== null) {
1135
- if (!item.deleted) {
1694
+ if (!item.removed) { // YP20: a held child goes with its node
1136
1695
  item.delete(transaction)
1137
1696
  } else if (!transaction.insertSet.hasId(item.id)) {
1138
1697
  // This will be gc'd later and we want to merge it if possible
@@ -1144,7 +1703,7 @@ export class ContentType {
1144
1703
  item = item.right
1145
1704
  }
1146
1705
  this.type._map.forEach(item => {
1147
- if (!item.deleted) {
1706
+ if (!item.removed) { // YP20
1148
1707
  item.delete(transaction)
1149
1708
  } else if (!transaction.insertSet.hasId(item.id)) {
1150
1709
  // same as above