plitejs 54.0.0-beta.2 → 54.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (865) hide show
  1. package/dist/{internal/view/annotation-store-metrics.js → annotation-store-metrics-Ccjkef45.js} +1 -1
  2. package/dist/annotations/index.d.ts +1 -1
  3. package/dist/annotations/index.js +1 -1
  4. package/dist/authored/index.d.ts +596 -9
  5. package/dist/authored/index.js +18679 -4
  6. package/dist/{core/authored-veto.js → authored-veto-D_9wCJcK.js} +2 -2
  7. package/dist/{internal/browser-protocol.js → browser-protocol-pvt4HFF7.js} +1 -1
  8. package/dist/comparison-plan-DY_vuGPq.js +1338 -0
  9. package/dist/{diff/lib/comparison-types.d.ts → comparison-types-DdwE6mYq.d.ts} +11 -6
  10. package/dist/create-editor-CLQEkEZ1.js +1108 -0
  11. package/dist/diff/index.d.ts +31 -3
  12. package/dist/diff/index.js +1747 -1
  13. package/dist/dom/index.d.ts +2 -19
  14. package/dist/dom/index.js +2 -16
  15. package/dist/dom-CH2BXXj6.js +9220 -0
  16. package/dist/{core/same-result.js → editor-owner-C9rVbMTs.js} +77 -2
  17. package/dist/{core/editor-view-lifetime.js → editor-view-lifetime-GJKa_QGh.js} +1 -1
  18. package/dist/history/index.d.ts +169 -3
  19. package/dist/history/index.js +6717 -2
  20. package/dist/hyperscript/index.d.ts +1 -19
  21. package/dist/hyperscript/index.js +1 -8
  22. package/dist/{hyperscript/creators.js → hyperscript-CeT83ZLB.js} +134 -8
  23. package/dist/{annotations/store.d.ts → index-BWPcE4ac.d.ts} +27 -6
  24. package/dist/index-BXjLmx1n.d.ts +9827 -0
  25. package/dist/index-DVMNewDn.d.ts +1243 -0
  26. package/dist/index-Db-ktCTE.d.ts +1092 -0
  27. package/dist/index-Dq3Jlj8O.d.ts +119 -0
  28. package/dist/{yjs/core/plugin.d.ts → index-UrB4jAwl.d.ts} +88 -5
  29. package/dist/index.d.ts +2 -51
  30. package/dist/index.js +4 -34
  31. package/dist/internal/index.d.ts +2 -54
  32. package/dist/internal/index.js +156 -52
  33. package/dist/{internal/view/mapped-view-store.js → mapped-view-store-CbWqba_1.js} +2 -3
  34. package/dist/{core/native-grouping-input.js → native-grouping-input-DXNhlPHd.js} +2 -2
  35. package/dist/pagination/index.d.ts +1 -7
  36. package/dist/pagination/index.js +1 -693
  37. package/dist/pagination/react.d.ts +2 -4
  38. package/dist/pagination/react.js +436 -30
  39. package/dist/pagination-CBdYiOuR.js +1021 -0
  40. package/dist/plugin-SR3HTH0j.js +51505 -0
  41. package/dist/{react/range-geometry.js → range-geometry-CdltxcH6.js} +23 -18
  42. package/dist/{react/range-geometry.d.ts → range-geometry-Dwp2oyCc.d.ts} +2 -2
  43. package/dist/react/index.d.ts +5 -97
  44. package/dist/react/index.js +7 -72
  45. package/dist/react/virtualized.d.ts +2 -4
  46. package/dist/react/virtualized.js +146 -7
  47. package/dist/react-CN-iBh1z.js +1018 -0
  48. package/dist/{core/change/retraction.js → retraction-BmPJB9cE.js} +16 -4
  49. package/dist/src-B-zm0kz4.js +1511 -0
  50. package/dist/{internal/view/stable-id-mapped-source.js → store-51r4zpCR.js} +253 -3
  51. package/dist/testing/index.d.ts +182 -8
  52. package/dist/testing/index.js +95 -8
  53. package/dist/use-editor-dom-scope-uDJQ692F.js +28370 -0
  54. package/dist/yjs/index.d.ts +1 -4
  55. package/dist/yjs/index.js +1 -2
  56. package/dist/yjs/react/index.d.ts +25 -5
  57. package/dist/yjs/react/index.js +84 -3
  58. package/dist/yjs-IGE0Al3n.js +13416 -0
  59. package/package.json +1 -1
  60. package/dist/annotations/store.js +0 -244
  61. package/dist/authored/authored.d.ts +0 -116
  62. package/dist/authored/authored.js +0 -1271
  63. package/dist/authored/changes.js +0 -365
  64. package/dist/authored/comparison.d.ts +0 -41
  65. package/dist/authored/comparison.js +0 -270
  66. package/dist/authored/decision-window.js +0 -42
  67. package/dist/authored/decision.js +0 -306
  68. package/dist/authored/facts/admission.js +0 -388
  69. package/dist/authored/facts/compact.d.ts +0 -2
  70. package/dist/authored/facts/compact.js +0 -91
  71. package/dist/authored/facts/dependencies.d.ts +0 -5
  72. package/dist/authored/facts/dependencies.js +0 -66
  73. package/dist/authored/facts/editing.js +0 -12
  74. package/dist/authored/facts/facts.d.ts +0 -8
  75. package/dist/authored/facts/facts.js +0 -535
  76. package/dist/authored/facts/records.d.ts +0 -28
  77. package/dist/authored/facts/records.js +0 -226
  78. package/dist/authored/facts/settle.js +0 -529
  79. package/dist/authored/format.d.ts +0 -34
  80. package/dist/authored/format.js +0 -175
  81. package/dist/authored/ledger/book.js +0 -809
  82. package/dist/authored/ledger/cards.js +0 -223
  83. package/dist/authored/ledger/ledger.js +0 -830
  84. package/dist/authored/ledger/level.js +0 -1081
  85. package/dist/authored/ledger/links.js +0 -20
  86. package/dist/authored/ledger/pairs.js +0 -334
  87. package/dist/authored/ledger/places.js +0 -524
  88. package/dist/authored/ledger/preview-lens.js +0 -252
  89. package/dist/authored/ledger/projection.js +0 -163
  90. package/dist/authored/ledger/roots.js +0 -11
  91. package/dist/authored/ledger/runs.js +0 -480
  92. package/dist/authored/ledger/slots.js +0 -330
  93. package/dist/authored/ledger/work.js +0 -66
  94. package/dist/authored/refusal.d.ts +0 -33
  95. package/dist/authored/refusal.js +0 -188
  96. package/dist/authored/resolve-schema.js +0 -62
  97. package/dist/authored/tree/alignment.js +0 -456
  98. package/dist/authored/tree/carried.js +0 -205
  99. package/dist/authored/tree/command-values.js +0 -344
  100. package/dist/authored/tree/cuts.js +0 -320
  101. package/dist/authored/tree/grid.js +0 -49
  102. package/dist/authored/tree/halves.js +0 -120
  103. package/dist/authored/tree/holders.js +0 -345
  104. package/dist/authored/tree/holds.js +0 -135
  105. package/dist/authored/tree/layers.d.ts +0 -49
  106. package/dist/authored/tree/layers.js +0 -354
  107. package/dist/authored/tree/marks.d.ts +0 -136
  108. package/dist/authored/tree/marks.js +0 -263
  109. package/dist/authored/tree/proposed.js +0 -212
  110. package/dist/authored/tree/readiness.js +0 -545
  111. package/dist/authored/tree/record-completion.js +0 -423
  112. package/dist/authored/tree/record.js +0 -2908
  113. package/dist/authored/tree/reserves.js +0 -449
  114. package/dist/authored/tree/resolve.d.ts +0 -9
  115. package/dist/authored/tree/resolve.js +0 -1860
  116. package/dist/authored/tree/shown.js +0 -153
  117. package/dist/authored/tree/spare-lines.js +0 -119
  118. package/dist/authored/tree/spares.js +0 -61
  119. package/dist/authored/types.d.ts +0 -177
  120. package/dist/core/anchor-state.d.ts +0 -15
  121. package/dist/core/anchor-state.js +0 -792
  122. package/dist/core/anchor.d.ts +0 -34
  123. package/dist/core/anchor.js +0 -843
  124. package/dist/core/authored-document-capability.d.ts +0 -106
  125. package/dist/core/authored-document-capability.js +0 -6
  126. package/dist/core/authored-runtime.d.ts +0 -10
  127. package/dist/core/authored-runtime.js +0 -67
  128. package/dist/core/authored-veto.d.ts +0 -30
  129. package/dist/core/change/builder.d.ts +0 -546
  130. package/dist/core/change/builder.js +0 -1120
  131. package/dist/core/change/carried-projection.js +0 -1518
  132. package/dist/core/change/carried-run.d.ts +0 -26
  133. package/dist/core/change/carried-run.js +0 -251
  134. package/dist/core/change/carry-program.js +0 -537
  135. package/dist/core/change/classification.d.ts +0 -22
  136. package/dist/core/change/classification.js +0 -205
  137. package/dist/core/change/cross-rule.js +0 -238
  138. package/dist/core/change/cross.js +0 -577
  139. package/dist/core/change/document-change.d.ts +0 -137
  140. package/dist/core/change/document-change.js +0 -872
  141. package/dist/core/change/document-index.d.ts +0 -117
  142. package/dist/core/change/document-index.js +0 -542
  143. package/dist/core/change/draft-facts.js +0 -323
  144. package/dist/core/change/enclosure.d.ts +0 -12
  145. package/dist/core/change/enclosure.js +0 -272
  146. package/dist/core/change/join.js +0 -751
  147. package/dist/core/change/json.d.ts +0 -4
  148. package/dist/core/change/json.js +0 -26
  149. package/dist/core/change/lazy-root.d.ts +0 -1
  150. package/dist/core/change/lazy-root.js +0 -73
  151. package/dist/core/change/lineage.d.ts +0 -49
  152. package/dist/core/change/lineage.js +0 -390
  153. package/dist/core/change/mapping.d.ts +0 -31
  154. package/dist/core/change/mapping.js +0 -186
  155. package/dist/core/change/new-letters.d.ts +0 -14
  156. package/dist/core/change/new-letters.js +0 -139
  157. package/dist/core/change/range-association.js +0 -10
  158. package/dist/core/change/read-back.d.ts +0 -7
  159. package/dist/core/change/read-back.js +0 -7
  160. package/dist/core/change/record.d.ts +0 -59
  161. package/dist/core/change/record.js +0 -346
  162. package/dist/core/change/root-change.d.ts +0 -180
  163. package/dist/core/change/root-change.js +0 -3544
  164. package/dist/core/change/slice-facts.js +0 -89
  165. package/dist/core/change/text-splices.js +0 -98
  166. package/dist/core/change/tokens.d.ts +0 -97
  167. package/dist/core/change/tokens.js +0 -449
  168. package/dist/core/change/transform.d.ts +0 -36
  169. package/dist/core/change/transform.js +0 -97
  170. package/dist/core/change/wrap-fidelity.js +0 -295
  171. package/dist/core/change-events.js +0 -223
  172. package/dist/core/clone.js +0 -28
  173. package/dist/core/command-definition.d.ts +0 -25
  174. package/dist/core/command-definition.js +0 -48
  175. package/dist/core/command-document.d.ts +0 -4
  176. package/dist/core/command-document.js +0 -20
  177. package/dist/core/command-frame.js +0 -628
  178. package/dist/core/command-registry.d.ts +0 -36
  179. package/dist/core/command-registry.js +0 -283
  180. package/dist/core/commit-publication.js +0 -40
  181. package/dist/core/commit.d.ts +0 -26
  182. package/dist/core/commit.js +0 -686
  183. package/dist/core/composition-stamp.d.ts +0 -14
  184. package/dist/core/composition-stamp.js +0 -79
  185. package/dist/core/content-completion.d.ts +0 -4
  186. package/dist/core/content-completion.js +0 -343
  187. package/dist/core/content-landing.js +0 -124
  188. package/dist/core/content-slice-roots.js +0 -36
  189. package/dist/core/content-slice.d.ts +0 -38
  190. package/dist/core/content-slice.js +0 -253
  191. package/dist/core/content.js +0 -18
  192. package/dist/core/correction.js +0 -25
  193. package/dist/core/default-storage.js +0 -53
  194. package/dist/core/document-admission.d.ts +0 -4
  195. package/dist/core/document-admission.js +0 -64
  196. package/dist/core/document-change.d.ts +0 -3
  197. package/dist/core/document-recorder.d.ts +0 -6
  198. package/dist/core/document-recorder.js +0 -67
  199. package/dist/core/document-shape.d.ts +0 -68
  200. package/dist/core/document-shape.js +0 -173
  201. package/dist/core/document-view-read.d.ts +0 -16
  202. package/dist/core/document-view-read.js +0 -36
  203. package/dist/core/draft-track.d.ts +0 -3
  204. package/dist/core/draft-track.js +0 -90
  205. package/dist/core/editor-commands.d.ts +0 -99
  206. package/dist/core/editor-commands.js +0 -505
  207. package/dist/core/editor-lifecycle-api.d.ts +0 -8
  208. package/dist/core/editor-lifecycle-api.js +0 -219
  209. package/dist/core/editor-lifetime.js +0 -12
  210. package/dist/core/editor-owner.d.ts +0 -24
  211. package/dist/core/editor-owner.js +0 -78
  212. package/dist/core/editor-read-execution.d.ts +0 -6
  213. package/dist/core/editor-read-execution.js +0 -64
  214. package/dist/core/editor-read-runtime.js +0 -176
  215. package/dist/core/editor-reads.d.ts +0 -128
  216. package/dist/core/editor-reads.js +0 -63
  217. package/dist/core/editor-runtime.d.ts +0 -112
  218. package/dist/core/editor-runtime.js +0 -20
  219. package/dist/core/editor-schema.d.ts +0 -314
  220. package/dist/core/editor-schema.js +0 -2295
  221. package/dist/core/element-owned-root-index.d.ts +0 -4
  222. package/dist/core/element-owned-root-index.js +0 -353
  223. package/dist/core/get-content-slice.js +0 -118
  224. package/dist/core/get-fragment.js +0 -22
  225. package/dist/core/identity-owner.js +0 -697
  226. package/dist/core/import-content-slice.js +0 -26
  227. package/dist/core/initial-value.js +0 -87
  228. package/dist/core/insert-limit.js +0 -81
  229. package/dist/core/is-empty-element.js +0 -20
  230. package/dist/core/json-fingerprint.js +0 -16
  231. package/dist/core/landing.d.ts +0 -11
  232. package/dist/core/landing.js +0 -279
  233. package/dist/core/lifecycle-error.d.ts +0 -11
  234. package/dist/core/lifecycle-error.js +0 -68
  235. package/dist/core/listener-state.d.ts +0 -1
  236. package/dist/core/listener-state.js +0 -59
  237. package/dist/core/measured-sequence.d.ts +0 -43
  238. package/dist/core/measured-sequence.js +0 -404
  239. package/dist/core/missing-reference.js +0 -15
  240. package/dist/core/node-property-mutation.js +0 -10
  241. package/dist/core/node-selection.js +0 -85
  242. package/dist/core/node-write-veto.d.ts +0 -37
  243. package/dist/core/node-write-veto.js +0 -17
  244. package/dist/core/persisted-document.d.ts +0 -6
  245. package/dist/core/persisted-document.js +0 -39
  246. package/dist/core/persistent-map.js +0 -139
  247. package/dist/core/plain-text.d.ts +0 -32
  248. package/dist/core/plain-text.js +0 -92
  249. package/dist/core/plugin-dispatch.d.ts +0 -21
  250. package/dist/core/plugin-dispatch.js +0 -166
  251. package/dist/core/plugin-point.d.ts +0 -6
  252. package/dist/core/plugin-point.js +0 -21
  253. package/dist/core/plugin-registry.d.ts +0 -78
  254. package/dist/core/plugin-registry.js +0 -485
  255. package/dist/core/plugin-slot.d.ts +0 -23
  256. package/dist/core/plugin-slot.js +0 -30
  257. package/dist/core/plugin.d.ts +0 -125
  258. package/dist/core/plugin.js +0 -1485
  259. package/dist/core/prefix-occupant-join.js +0 -52
  260. package/dist/core/profiling.js +0 -18
  261. package/dist/core/property-validity.d.ts +0 -14
  262. package/dist/core/property-validity.js +0 -65
  263. package/dist/core/public-root.d.ts +0 -10
  264. package/dist/core/public-root.js +0 -50
  265. package/dist/core/public-state.d.ts +0 -191
  266. package/dist/core/public-state.js +0 -6772
  267. package/dist/core/read-definition.js +0 -22
  268. package/dist/core/read-registry.js +0 -127
  269. package/dist/core/record-store.d.ts +0 -12
  270. package/dist/core/record-store.js +0 -297
  271. package/dist/core/refusal.d.ts +0 -1
  272. package/dist/core/refusal.js +0 -40
  273. package/dist/core/representation.d.ts +0 -11
  274. package/dist/core/representation.js +0 -844
  275. package/dist/core/resolved-token-cursor.d.ts +0 -21
  276. package/dist/core/resolved-token-cursor.js +0 -294
  277. package/dist/core/root-entries.js +0 -121
  278. package/dist/core/root-ownership.d.ts +0 -19
  279. package/dist/core/root-ownership.js +0 -354
  280. package/dist/core/root-target.d.ts +0 -7
  281. package/dist/core/root-target.js +0 -281
  282. package/dist/core/same-result.d.ts +0 -18
  283. package/dist/core/schema-compiler.d.ts +0 -345
  284. package/dist/core/schema-compiler.js +0 -3166
  285. package/dist/core/schema-contribution-registry.d.ts +0 -12
  286. package/dist/core/schema-contribution-registry.js +0 -88
  287. package/dist/core/schema-definition.d.ts +0 -307
  288. package/dist/core/schema-definition.js +0 -628
  289. package/dist/core/schema-source.internal.d.ts +0 -49
  290. package/dist/core/schema-validation.d.ts +0 -11
  291. package/dist/core/schema-validation.js +0 -85
  292. package/dist/core/screen-reader-announcement.d.ts +0 -13
  293. package/dist/core/screen-reader-announcement.js +0 -17
  294. package/dist/core/selection-protocol.d.ts +0 -38
  295. package/dist/core/selection-protocol.js +0 -523
  296. package/dist/core/selection-state.js +0 -9
  297. package/dist/core/semantic-update-method.d.ts +0 -11
  298. package/dist/core/semantic-update-method.js +0 -26
  299. package/dist/core/set-root.d.ts +0 -3
  300. package/dist/core/set-root.js +0 -244
  301. package/dist/core/slice-end-matter.js +0 -77
  302. package/dist/core/slice-fit/compiled-slice-fitter.d.ts +0 -56
  303. package/dist/core/slice-fit/compiled-slice-fitter.js +0 -2087
  304. package/dist/core/slice-fit/fit-report.d.ts +0 -36
  305. package/dist/core/slice-fit/fit-report.js +0 -122
  306. package/dist/core/slice-fit/frontier.js +0 -98
  307. package/dist/core/slice-fit/origin.js +0 -57
  308. package/dist/core/slice-fit/provenance.d.ts +0 -30
  309. package/dist/core/slice-fit/provenance.js +0 -245
  310. package/dist/core/slice-identities.js +0 -21
  311. package/dist/core/slice-landing-types.d.ts +0 -61
  312. package/dist/core/slice-landing.js +0 -124
  313. package/dist/core/snapshot-index.d.ts +0 -13
  314. package/dist/core/snapshot-index.js +0 -860
  315. package/dist/core/state-field.d.ts +0 -12
  316. package/dist/core/state-field.js +0 -102
  317. package/dist/core/state-fields.js +0 -36
  318. package/dist/core/survival.js +0 -61
  319. package/dist/core/target-runtime.d.ts +0 -5
  320. package/dist/core/target-runtime.js +0 -42
  321. package/dist/core/transaction-values.d.ts +0 -47
  322. package/dist/core/transaction-values.js +0 -66
  323. package/dist/core/transfer-guard.js +0 -299
  324. package/dist/core/transfer-types.d.ts +0 -170
  325. package/dist/core/transfer.d.ts +0 -72
  326. package/dist/core/transfer.js +0 -655
  327. package/dist/core/tx-only.d.ts +0 -64
  328. package/dist/core/tx-only.js +0 -84
  329. package/dist/core/unique-values.js +0 -298
  330. package/dist/core/update-context.js +0 -28
  331. package/dist/core/update-policy.d.ts +0 -17
  332. package/dist/core/update-policy.js +0 -45
  333. package/dist/core/value-codec.d.ts +0 -35
  334. package/dist/core/value-codec.js +0 -240
  335. package/dist/core/view-carets.d.ts +0 -39
  336. package/dist/core/view-carets.js +0 -676
  337. package/dist/core/view-presentation.d.ts +0 -9
  338. package/dist/core/view-presentation.js +0 -70
  339. package/dist/core/work.d.ts +0 -192
  340. package/dist/core/work.js +0 -122
  341. package/dist/core/writable-text.js +0 -37
  342. package/dist/create-editor.d.ts +0 -187
  343. package/dist/create-editor.js +0 -281
  344. package/dist/diff/lib/compare.d.ts +0 -33
  345. package/dist/diff/lib/compare.js +0 -459
  346. package/dist/diff/lib/comparison-align.js +0 -324
  347. package/dist/diff/lib/comparison-index.js +0 -160
  348. package/dist/diff/lib/comparison-internal.js +0 -108
  349. package/dist/diff/lib/comparison-matcher.js +0 -1221
  350. package/dist/diff/lib/comparison-moves.js +0 -151
  351. package/dist/diff/lib/comparison-plan.js +0 -556
  352. package/dist/diff/lib/index.d.ts +0 -3
  353. package/dist/dom/dom-soft-line-end.d.ts +0 -3
  354. package/dist/dom/dom-soft-line-end.js +0 -295
  355. package/dist/dom/internal/index.d.ts +0 -15
  356. package/dist/dom/plugin/data-transfer-format.d.ts +0 -90
  357. package/dist/dom/plugin/data-transfer-format.js +0 -525
  358. package/dist/dom/plugin/dom-clipboard-runtime.d.ts +0 -50
  359. package/dist/dom/plugin/dom-clipboard-runtime.js +0 -482
  360. package/dist/dom/plugin/dom-coverage.d.ts +0 -140
  361. package/dist/dom/plugin/dom-coverage.js +0 -443
  362. package/dist/dom/plugin/dom-drag-scroll.js +0 -176
  363. package/dist/dom/plugin/dom-drag.d.ts +0 -54
  364. package/dist/dom/plugin/dom-drag.js +0 -507
  365. package/dist/dom/plugin/dom-editor.d.ts +0 -421
  366. package/dist/dom/plugin/dom-editor.js +0 -1316
  367. package/dist/dom/plugin/dom-event-range-targets.js +0 -39
  368. package/dist/dom/plugin/dom-geometry.d.ts +0 -11
  369. package/dist/dom/plugin/dom-geometry.js +0 -888
  370. package/dist/dom/plugin/dom-input-runtime.d.ts +0 -1
  371. package/dist/dom/plugin/dom-input-runtime.js +0 -571
  372. package/dist/dom/plugin/dom-integrity-observer.js +0 -436
  373. package/dist/dom/plugin/dom-node-path.js +0 -61
  374. package/dist/dom/plugin/dom-phase-scheduler.d.ts +0 -1
  375. package/dist/dom/plugin/dom-phase-scheduler.js +0 -284
  376. package/dist/dom/plugin/dom-root-runtime.d.ts +0 -10
  377. package/dist/dom/plugin/dom-root-runtime.js +0 -716
  378. package/dist/dom/plugin/dom-sync-mutation-ownership.d.ts +0 -1
  379. package/dist/dom/plugin/dom-sync-mutation-ownership.js +0 -120
  380. package/dist/dom/plugin/dom-text-flow-index.js +0 -396
  381. package/dist/dom/plugin/dom-text-freshness.js +0 -188
  382. package/dist/dom/plugin/dom-text-proofs.d.ts +0 -2
  383. package/dist/dom/plugin/dom-text-proofs.js +0 -350
  384. package/dist/dom/plugin/dom-view-caret.js +0 -28
  385. package/dist/dom/plugin/with-dom.d.ts +0 -53
  386. package/dist/dom/plugin/with-dom.js +0 -101
  387. package/dist/dom/utils/constants.d.ts +0 -5
  388. package/dist/dom/utils/constants.js +0 -5
  389. package/dist/dom/utils/diff-text.d.ts +0 -51
  390. package/dist/dom/utils/diff-text.js +0 -264
  391. package/dist/dom/utils/dom.d.ts +0 -104
  392. package/dist/dom/utils/dom.js +0 -257
  393. package/dist/dom/utils/drag-session.d.ts +0 -2
  394. package/dist/dom/utils/drag-session.js +0 -115
  395. package/dist/dom/utils/drop-indicator.d.ts +0 -18
  396. package/dist/dom/utils/drop-indicator.js +0 -36
  397. package/dist/dom/utils/environment.d.ts +0 -12
  398. package/dist/dom/utils/environment.js +0 -118
  399. package/dist/dom/utils/hotkey-match.d.ts +0 -36
  400. package/dist/dom/utils/hotkey-match.js +0 -208
  401. package/dist/dom/utils/hotkeys.d.ts +0 -32
  402. package/dist/dom/utils/hotkeys.js +0 -121
  403. package/dist/dom/utils/key.d.ts +0 -14
  404. package/dist/dom/utils/key.js +0 -18
  405. package/dist/dom/utils/plite-dom-markers.d.ts +0 -26
  406. package/dist/dom/utils/plite-dom-markers.js +0 -25
  407. package/dist/dom/utils/selection-writes.d.ts +0 -18
  408. package/dist/dom/utils/selection-writes.js +0 -63
  409. package/dist/dom/utils/weak-maps.d.ts +0 -2
  410. package/dist/dom/utils/weak-maps.js +0 -51
  411. package/dist/editor/above.js +0 -30
  412. package/dist/editor/add-mark.js +0 -79
  413. package/dist/editor/adjacent-character-point.js +0 -120
  414. package/dist/editor/after.js +0 -37
  415. package/dist/editor/before.js +0 -124
  416. package/dist/editor/block-void-break.js +0 -20
  417. package/dist/editor/correct-document.js +0 -225
  418. package/dist/editor/delete-backward.js +0 -64
  419. package/dist/editor/delete-forward.js +0 -11
  420. package/dist/editor/delete-fragment.js +0 -40
  421. package/dist/editor/edges.js +0 -5
  422. package/dist/editor/element-read-only.js +0 -35
  423. package/dist/editor/end.d.ts +0 -7
  424. package/dist/editor/end.js +0 -5
  425. package/dist/editor/exit-break.js +0 -51
  426. package/dist/editor/first.js +0 -8
  427. package/dist/editor/get-void.js +0 -9
  428. package/dist/editor/has-blocks.js +0 -6
  429. package/dist/editor/has-inlines.js +0 -6
  430. package/dist/editor/has-path.js +0 -5
  431. package/dist/editor/has-texts.js +0 -5
  432. package/dist/editor/insert-break.js +0 -77
  433. package/dist/editor/insert-default-child.js +0 -55
  434. package/dist/editor/insert-soft-break.js +0 -14
  435. package/dist/editor/insert-text.js +0 -83
  436. package/dist/editor/is-block.js +0 -5
  437. package/dist/editor/is-edge.js +0 -5
  438. package/dist/editor/is-editor.js +0 -13
  439. package/dist/editor/is-empty.js +0 -6
  440. package/dist/editor/is-end.js +0 -9
  441. package/dist/editor/is-start.js +0 -9
  442. package/dist/editor/last.js +0 -20
  443. package/dist/editor/leaf.js +0 -9
  444. package/dist/editor/levels.js +0 -21
  445. package/dist/editor/next.js +0 -46
  446. package/dist/editor/node.js +0 -9
  447. package/dist/editor/nodes.js +0 -106
  448. package/dist/editor/parent.js +0 -14
  449. package/dist/editor/path.js +0 -26
  450. package/dist/editor/point.js +0 -52
  451. package/dist/editor/positions.js +0 -322
  452. package/dist/editor/previous.js +0 -48
  453. package/dist/editor/project-range.js +0 -6
  454. package/dist/editor/range.js +0 -12
  455. package/dist/editor/remove-mark.js +0 -65
  456. package/dist/editor/should-merge-nodes-remove-prev-node.js +0 -11
  457. package/dist/editor/string.js +0 -35
  458. package/dist/editor/toggle-mark.js +0 -71
  459. package/dist/editor/unhang-range.js +0 -71
  460. package/dist/editor-runtime-view.d.ts +0 -33
  461. package/dist/editor-runtime-view.js +0 -788
  462. package/dist/history/history-carets.js +0 -127
  463. package/dist/history/history-character-map.js +0 -425
  464. package/dist/history/history-codec.js +0 -176
  465. package/dist/history/history-merge-policy.js +0 -164
  466. package/dist/history/history-plugin.d.ts +0 -71
  467. package/dist/history/history-plugin.js +0 -814
  468. package/dist/history/history-replay.js +0 -799
  469. package/dist/history/history-selection.js +0 -75
  470. package/dist/history/history-state.js +0 -1287
  471. package/dist/history/history.d.ts +0 -112
  472. package/dist/history/history.js +0 -29
  473. package/dist/hyperscript/creators.d.ts +0 -51
  474. package/dist/hyperscript/hyperscript.d.ts +0 -36
  475. package/dist/hyperscript/hyperscript.js +0 -66
  476. package/dist/hyperscript/tokens.d.ts +0 -31
  477. package/dist/hyperscript/tokens.js +0 -63
  478. package/dist/interfaces/decoration.d.ts +0 -35
  479. package/dist/interfaces/editor.d.ts +0 -2783
  480. package/dist/interfaces/editor.js +0 -348
  481. package/dist/interfaces/element.d.ts +0 -66
  482. package/dist/interfaces/element.js +0 -34
  483. package/dist/interfaces/index.d.ts +0 -13
  484. package/dist/interfaces/json.d.ts +0 -7
  485. package/dist/interfaces/location.d.ts +0 -50
  486. package/dist/interfaces/location.js +0 -26
  487. package/dist/interfaces/node.d.ts +0 -306
  488. package/dist/interfaces/node.js +0 -339
  489. package/dist/interfaces/path.d.ts +0 -118
  490. package/dist/interfaces/path.js +0 -116
  491. package/dist/interfaces/point.d.ts +0 -45
  492. package/dist/interfaces/point.js +0 -32
  493. package/dist/interfaces/range.d.ts +0 -80
  494. package/dist/interfaces/range.js +0 -85
  495. package/dist/interfaces/schema-validation.d.ts +0 -33
  496. package/dist/interfaces/schema.d.ts +0 -870
  497. package/dist/interfaces/selection.d.ts +0 -61
  498. package/dist/interfaces/selection.js +0 -106
  499. package/dist/interfaces/text.d.ts +0 -68
  500. package/dist/interfaces/text.js +0 -52
  501. package/dist/interfaces/transforms/node.d.ts +0 -222
  502. package/dist/interfaces/transforms/selection.d.ts +0 -48
  503. package/dist/interfaces/transforms/text.d.ts +0 -58
  504. package/dist/internal/browser-protocol.d.ts +0 -5
  505. package/dist/internal/document-range.d.ts +0 -9
  506. package/dist/internal/document-range.js +0 -31
  507. package/dist/internal/editor-options.d.ts +0 -37
  508. package/dist/internal/editor-options.js +0 -36
  509. package/dist/internal/fail-invariant.d.ts +0 -4
  510. package/dist/internal/fail-invariant.js +0 -6
  511. package/dist/internal/get-defined.js +0 -7
  512. package/dist/internal/law-check.js +0 -7
  513. package/dist/internal/range-text-marks.js +0 -31
  514. package/dist/internal/root-location.d.ts +0 -23
  515. package/dist/internal/root-location.js +0 -86
  516. package/dist/internal/text-run.d.ts +0 -13
  517. package/dist/internal/text-run.js +0 -44
  518. package/dist/internal/view/annotation-store-metrics.d.ts +0 -11
  519. package/dist/internal/view/view-source.d.ts +0 -20
  520. package/dist/pagination/page-composition.internal.js +0 -313
  521. package/dist/pagination/page-geometry.internal.js +0 -99
  522. package/dist/pagination/page-layout-engine-invalidation.internal.js +0 -20
  523. package/dist/pagination/page-mount-plan.js +0 -84
  524. package/dist/pagination/paged-view-lines.js +0 -163
  525. package/dist/range-projection.d.ts +0 -7
  526. package/dist/range-projection.js +0 -50
  527. package/dist/react/components/dom-coverage-boundary.d.ts +0 -14
  528. package/dist/react/components/dom-coverage-boundary.js +0 -143
  529. package/dist/react/components/editable-descendant-binding.js +0 -70
  530. package/dist/react/components/editable-dom-commit-fence.js +0 -107
  531. package/dist/react/components/editable-element-placement.d.ts +0 -2
  532. package/dist/react/components/editable-element-placement.js +0 -117
  533. package/dist/react/components/editable-external-text.js +0 -47
  534. package/dist/react/components/editable-node-equality.js +0 -25
  535. package/dist/react/components/editable-rendered-element.d.ts +0 -3
  536. package/dist/react/components/editable-rendered-element.js +0 -61
  537. package/dist/react/components/editable-text-blocks.d.ts +0 -192
  538. package/dist/react/components/editable-text-blocks.js +0 -896
  539. package/dist/react/components/editable-text-containers.d.ts +0 -3
  540. package/dist/react/components/editable-text-containers.js +0 -28
  541. package/dist/react/components/editable-text-flow.js +0 -1039
  542. package/dist/react/components/editable-text-pieces.d.ts +0 -7
  543. package/dist/react/components/editable-text-pieces.js +0 -193
  544. package/dist/react/components/editable-text.d.ts +0 -80
  545. package/dist/react/components/editable-text.js +0 -322
  546. package/dist/react/components/editable.d.ts +0 -35
  547. package/dist/react/components/editable.js +0 -406
  548. package/dist/react/components/editor-announcement-live-region.js +0 -113
  549. package/dist/react/components/plite-element.d.ts +0 -18
  550. package/dist/react/components/plite-element.js +0 -54
  551. package/dist/react/components/plite-leaf.d.ts +0 -18
  552. package/dist/react/components/plite-leaf.js +0 -21
  553. package/dist/react/components/plite-placeholder.d.ts +0 -19
  554. package/dist/react/components/plite-placeholder.js +0 -39
  555. package/dist/react/components/plite-spacer.js +0 -14
  556. package/dist/react/components/plite-text.d.ts +0 -23
  557. package/dist/react/components/plite-text.js +0 -32
  558. package/dist/react/components/plite-void-shell.js +0 -49
  559. package/dist/react/components/plite.d.ts +0 -45
  560. package/dist/react/components/plite.js +0 -297
  561. package/dist/react/components/text-string.js +0 -18
  562. package/dist/react/components/windowed-editable.internal.js +0 -51
  563. package/dist/react/components/zero-width-string.js +0 -26
  564. package/dist/react/context.js +0 -11
  565. package/dist/react/decoration-context.d.ts +0 -2
  566. package/dist/react/decoration-context.js +0 -22
  567. package/dist/react/decoration-source.d.ts +0 -11
  568. package/dist/react/decoration-source.js +0 -1030
  569. package/dist/react/dom-text-sync.d.ts +0 -24
  570. package/dist/react/dom-text-sync.js +0 -48
  571. package/dist/react/editable/android-composition.d.ts +0 -3
  572. package/dist/react/editable/android-composition.js +0 -496
  573. package/dist/react/editable/browser-handle.js +0 -515
  574. package/dist/react/editable/caret-engine.js +0 -681
  575. package/dist/react/editable/clipboard-input-strategy.js +0 -632
  576. package/dist/react/editable/composition-lease.d.ts +0 -3
  577. package/dist/react/editable/composition-lease.js +0 -350
  578. package/dist/react/editable/composition-state.js +0 -716
  579. package/dist/react/editable/content-root-boundaries.js +0 -79
  580. package/dist/react/editable/content-root-coordinate-navigation.js +0 -28
  581. package/dist/react/editable/content-root-navigation-actions.js +0 -190
  582. package/dist/react/editable/content-root-navigation.js +0 -819
  583. package/dist/react/editable/content-root-owner-target.js +0 -36
  584. package/dist/react/editable/content-root-owners.js +0 -191
  585. package/dist/react/editable/content-root-vertical-geometry.js +0 -60
  586. package/dist/react/editable/decoration-repair-bridge.js +0 -29
  587. package/dist/react/editable/dom-coverage-selection.js +0 -158
  588. package/dist/react/editable/dom-coverage-vertical-selection.js +0 -446
  589. package/dist/react/editable/dom-input-event.js +0 -14
  590. package/dist/react/editable/dom-repair-queue.d.ts +0 -7
  591. package/dist/react/editable/dom-repair-queue.js +0 -543
  592. package/dist/react/editable/dom-repair-text.js +0 -47
  593. package/dist/react/editable/editable-command-types.d.ts +0 -1
  594. package/dist/react/editable/editable-dom-runtime.d.ts +0 -66
  595. package/dist/react/editable/editable-dom-runtime.js +0 -1022
  596. package/dist/react/editable/editing-epoch-adapter.js +0 -46
  597. package/dist/react/editable/editing-kernel.d.ts +0 -7
  598. package/dist/react/editable/editing-kernel.js +0 -593
  599. package/dist/react/editable/external-text-binding.js +0 -43
  600. package/dist/react/editable/external-text-runtime.d.ts +0 -5
  601. package/dist/react/editable/external-text-runtime.js +0 -851
  602. package/dist/react/editable/history-focus.js +0 -71
  603. package/dist/react/editable/history-keyboard.d.ts +0 -4
  604. package/dist/react/editable/history-keyboard.js +0 -9
  605. package/dist/react/editable/input-controller.d.ts +0 -7
  606. package/dist/react/editable/input-controller.js +0 -175
  607. package/dist/react/editable/input-history.js +0 -21
  608. package/dist/react/editable/input-router.js +0 -742
  609. package/dist/react/editable/input-state.d.ts +0 -18
  610. package/dist/react/editable/input-state.js +0 -330
  611. package/dist/react/editable/input-target.js +0 -30
  612. package/dist/react/editable/install-browser-handle.d.ts +0 -12
  613. package/dist/react/editable/install-browser-handle.js +0 -18
  614. package/dist/react/editable/interaction-owner.js +0 -88
  615. package/dist/react/editable/keyboard-input-strategy.js +0 -730
  616. package/dist/react/editable/line-boundary.js +0 -37
  617. package/dist/react/editable/model-input-strategy.d.ts +0 -9
  618. package/dist/react/editable/model-input-strategy.js +0 -242
  619. package/dist/react/editable/model-selection-dom-preference.js +0 -11
  620. package/dist/react/editable/mutation-block-editing.js +0 -48
  621. package/dist/react/editable/mutation-controller.d.ts +0 -32
  622. package/dist/react/editable/mutation-controller.js +0 -632
  623. package/dist/react/editable/mutation-full-block-editing.d.ts +0 -2
  624. package/dist/react/editable/mutation-full-block-editing.js +0 -44
  625. package/dist/react/editable/mutation-history.d.ts +0 -3
  626. package/dist/react/editable/mutation-history.js +0 -146
  627. package/dist/react/editable/native-input-strategy.js +0 -86
  628. package/dist/react/editable/native-text-input-delta.js +0 -40
  629. package/dist/react/editable/placed-drag.js +0 -177
  630. package/dist/react/editable/plite-string-coordinate-placement.js +0 -46
  631. package/dist/react/editable/press-fence.d.ts +0 -2
  632. package/dist/react/editable/press-fence.js +0 -70
  633. package/dist/react/editable/projected-clipboard.js +0 -123
  634. package/dist/react/editable/projected-native-affordance.js +0 -30
  635. package/dist/react/editable/projected-selection-target.js +0 -13
  636. package/dist/react/editable/render-contract-monitor.d.ts +0 -3
  637. package/dist/react/editable/render-contract-monitor.js +0 -152
  638. package/dist/react/editable/root-interaction-controller.js +0 -1400
  639. package/dist/react/editable/root-interaction-dom-selection-replay.js +0 -40
  640. package/dist/react/editable/root-interaction-resolver.js +0 -116
  641. package/dist/react/editable/root-selector-sources.js +0 -90
  642. package/dist/react/editable/runtime-android-engine.js +0 -40
  643. package/dist/react/editable/runtime-before-input-events.js +0 -671
  644. package/dist/react/editable/runtime-browser-handle-events.js +0 -40
  645. package/dist/react/editable/runtime-clipboard-events.js +0 -169
  646. package/dist/react/editable/runtime-composition-events.js +0 -163
  647. package/dist/react/editable/runtime-drag-events.js +0 -136
  648. package/dist/react/editable/runtime-editor-api.d.ts +0 -20
  649. package/dist/react/editable/runtime-editor-api.js +0 -21
  650. package/dist/react/editable/runtime-event-engine.js +0 -213
  651. package/dist/react/editable/runtime-focus-mouse-events.js +0 -264
  652. package/dist/react/editable/runtime-input-events.js +0 -166
  653. package/dist/react/editable/runtime-kernel-trace.js +0 -185
  654. package/dist/react/editable/runtime-keyboard-events.js +0 -333
  655. package/dist/react/editable/runtime-live-state.js +0 -44
  656. package/dist/react/editable/runtime-mutation-state.js +0 -11
  657. package/dist/react/editable/runtime-repair-engine.js +0 -118
  658. package/dist/react/editable/runtime-root-engine.js +0 -244
  659. package/dist/react/editable/runtime-root-lifecycle.js +0 -118
  660. package/dist/react/editable/runtime-root-selection-export.js +0 -38
  661. package/dist/react/editable/runtime-root-selection-import.js +0 -54
  662. package/dist/react/editable/runtime-root-state.js +0 -62
  663. package/dist/react/editable/runtime-selection-engine.js +0 -260
  664. package/dist/react/editable/runtime-selection-state.js +0 -12
  665. package/dist/react/editable/runtime-target-bridge.js +0 -29
  666. package/dist/react/editable/schema-runtime-invalidation.js +0 -26
  667. package/dist/react/editable/selection-change-listener.js +0 -99
  668. package/dist/react/editable/selection-claim.d.ts +0 -3
  669. package/dist/react/editable/selection-claim.js +0 -398
  670. package/dist/react/editable/selection-controller.d.ts +0 -8
  671. package/dist/react/editable/selection-controller.js +0 -693
  672. package/dist/react/editable/selection-dom-range.js +0 -84
  673. package/dist/react/editable/selection-projected-dom.js +0 -156
  674. package/dist/react/editable/selection-reconciler.js +0 -630
  675. package/dist/react/editable/selection-runtime.js +0 -89
  676. package/dist/react/editable/selection-side-effect-policy.js +0 -20
  677. package/dist/react/editable/selection-triple-click.js +0 -48
  678. package/dist/react/editable/selection-void-target.js +0 -172
  679. package/dist/react/editable/set-root-endpoints.js +0 -75
  680. package/dist/react/editable/soft-line-end-delete.js +0 -106
  681. package/dist/react/editable/text-direction.js +0 -82
  682. package/dist/react/editable/typed-text.d.ts +0 -17
  683. package/dist/react/editable/typed-text.js +0 -89
  684. package/dist/react/editable/unread-press.d.ts +0 -2
  685. package/dist/react/editable/unread-press.js +0 -86
  686. package/dist/react/editable/view-caret-restore.js +0 -128
  687. package/dist/react/editable/view-lines.d.ts +0 -7
  688. package/dist/react/editable/view-lines.js +0 -166
  689. package/dist/react/external-text.d.ts +0 -131
  690. package/dist/react/history-step-views.d.ts +0 -4
  691. package/dist/react/history-step-views.js +0 -119
  692. package/dist/react/hooks/android-input-manager/android-input-manager.d.ts +0 -7
  693. package/dist/react/hooks/android-input-manager/android-input-manager.js +0 -716
  694. package/dist/react/hooks/android-input-manager/use-android-input-manager.js +0 -53
  695. package/dist/react/hooks/focus-plite-editable.js +0 -116
  696. package/dist/react/hooks/use-claim-editable-dom-commit.d.ts +0 -12
  697. package/dist/react/hooks/use-claim-editable-dom-commit.js +0 -31
  698. package/dist/react/hooks/use-drop-indicator.d.ts +0 -9
  699. package/dist/react/hooks/use-drop-indicator.js +0 -14
  700. package/dist/react/hooks/use-editable-clip.d.ts +0 -18
  701. package/dist/react/hooks/use-editable-clip.js +0 -31
  702. package/dist/react/hooks/use-editable-layout-pass.js +0 -53
  703. package/dist/react/hooks/use-editor-composing.d.ts +0 -7
  704. package/dist/react/hooks/use-editor-composing.js +0 -12
  705. package/dist/react/hooks/use-editor-context.d.ts +0 -10
  706. package/dist/react/hooks/use-editor-context.js +0 -18
  707. package/dist/react/hooks/use-editor-dom-scope.d.ts +0 -27
  708. package/dist/react/hooks/use-editor-dom-scope.js +0 -23
  709. package/dist/react/hooks/use-editor-focused.d.ts +0 -7
  710. package/dist/react/hooks/use-editor-focused.js +0 -12
  711. package/dist/react/hooks/use-editor-read-only.d.ts +0 -25
  712. package/dist/react/hooks/use-editor-read-only.js +0 -19
  713. package/dist/react/hooks/use-editor-runtime-state.d.ts +0 -18
  714. package/dist/react/hooks/use-editor-runtime-state.js +0 -38
  715. package/dist/react/hooks/use-editor-selection.d.ts +0 -10
  716. package/dist/react/hooks/use-editor-selection.js +0 -13
  717. package/dist/react/hooks/use-editor-selector.d.ts +0 -38
  718. package/dist/react/hooks/use-editor-selector.js +0 -265
  719. package/dist/react/hooks/use-editor-view-state.d.ts +0 -16
  720. package/dist/react/hooks/use-editor-view-state.js +0 -20
  721. package/dist/react/hooks/use-editor.d.ts +0 -26
  722. package/dist/react/hooks/use-editor.js +0 -27
  723. package/dist/react/hooks/use-element-path.d.ts +0 -7
  724. package/dist/react/hooks/use-element-path.js +0 -36
  725. package/dist/react/hooks/use-element-selected.d.ts +0 -26
  726. package/dist/react/hooks/use-element-selected.js +0 -91
  727. package/dist/react/hooks/use-element.d.ts +0 -13
  728. package/dist/react/hooks/use-element.js +0 -17
  729. package/dist/react/hooks/use-generic-selector.js +0 -91
  730. package/dist/react/hooks/use-hydrated.js +0 -12
  731. package/dist/react/hooks/use-isomorphic-layout-effect.js +0 -9
  732. package/dist/react/hooks/use-node-selector.d.ts +0 -40
  733. package/dist/react/hooks/use-node-selector.js +0 -102
  734. package/dist/react/hooks/use-plite-annotation-store.d.ts +0 -21
  735. package/dist/react/hooks/use-plite-annotation-store.js +0 -61
  736. package/dist/react/hooks/use-plite-annotations.d.ts +0 -9
  737. package/dist/react/hooks/use-plite-annotations.js +0 -16
  738. package/dist/react/hooks/use-plite-child-root.d.ts +0 -14
  739. package/dist/react/hooks/use-plite-child-root.js +0 -38
  740. package/dist/react/hooks/use-plite-content-root.d.ts +0 -21
  741. package/dist/react/hooks/use-plite-content-root.js +0 -26
  742. package/dist/react/hooks/use-plite-history.d.ts +0 -43
  743. package/dist/react/hooks/use-plite-history.js +0 -137
  744. package/dist/react/hooks/use-plite-node-ref.js +0 -513
  745. package/dist/react/hooks/use-plite-root-chrome.d.ts +0 -34
  746. package/dist/react/hooks/use-plite-root-chrome.js +0 -98
  747. package/dist/react/hooks/use-plite-runtime.d.ts +0 -86
  748. package/dist/react/hooks/use-plite-runtime.js +0 -433
  749. package/dist/react/hooks/use-runtime-focus-state.js +0 -37
  750. package/dist/react/hooks/use-selection-geometry.d.ts +0 -12
  751. package/dist/react/hooks/use-selection-geometry.js +0 -39
  752. package/dist/react/hooks/use-selection-view.d.ts +0 -14
  753. package/dist/react/hooks/use-selection-view.js +0 -14
  754. package/dist/react/hooks/use-state-field.d.ts +0 -26
  755. package/dist/react/hooks/use-state-field.js +0 -38
  756. package/dist/react/inactive-selection.js +0 -175
  757. package/dist/react/plugin/react-editor.d.ts +0 -20
  758. package/dist/react/plugin/react-editor.js +0 -6
  759. package/dist/react/plugin/with-react.d.ts +0 -108
  760. package/dist/react/plugin/with-react.js +0 -58
  761. package/dist/react/render-profiler.js +0 -20
  762. package/dist/react/root-key.js +0 -12
  763. package/dist/react/shell-runtime.js +0 -29
  764. package/dist/react/update-policy.d.ts +0 -10
  765. package/dist/react/update-policy.js +0 -15
  766. package/dist/react/utils/environment.js +0 -5
  767. package/dist/react/view-boundary-graph-core.d.ts +0 -1
  768. package/dist/react/view-boundary-graph-core.js +0 -208
  769. package/dist/react/view-boundary-graph.js +0 -105
  770. package/dist/react/view-selection-decoration.js +0 -97
  771. package/dist/react/view-selection.js +0 -184
  772. package/dist/react/viewport-boundary.js +0 -45
  773. package/dist/react/viewport-commands.d.ts +0 -1
  774. package/dist/react/viewport-commands.js +0 -17
  775. package/dist/react/viewport-plan.d.ts +0 -2
  776. package/dist/react/viewport-plan.js +0 -77
  777. package/dist/react/virtualized/use-virtualized-root-plan.js +0 -148
  778. package/dist/testing/createDataTransfer.d.ts +0 -4
  779. package/dist/testing/createDataTransfer.js +0 -13
  780. package/dist/testing/jsx.d.ts +0 -181
  781. package/dist/testing/jsx.js +0 -82
  782. package/dist/transforms-node/insert-nodes.js +0 -143
  783. package/dist/transforms-node/lift-nodes.js +0 -117
  784. package/dist/transforms-node/merge-nodes.js +0 -180
  785. package/dist/transforms-node/move-nodes.js +0 -58
  786. package/dist/transforms-node/remove-nodes.js +0 -86
  787. package/dist/transforms-node/replace-children.js +0 -117
  788. package/dist/transforms-node/set-nodes.js +0 -188
  789. package/dist/transforms-node/split-nodes.js +0 -258
  790. package/dist/transforms-node/unset-nodes.js +0 -10
  791. package/dist/transforms-node/unwrap-nodes.js +0 -182
  792. package/dist/transforms-node/wrap-nodes.js +0 -250
  793. package/dist/transforms-selection/collapse.js +0 -20
  794. package/dist/transforms-selection/deselect.js +0 -8
  795. package/dist/transforms-selection/move.js +0 -35
  796. package/dist/transforms-selection/select.js +0 -59
  797. package/dist/transforms-selection/set-point.js +0 -32
  798. package/dist/transforms-selection/set-selection.js +0 -52
  799. package/dist/transforms-text/delete-text-collapsed-path-targets.js +0 -102
  800. package/dist/transforms-text/delete-text-grid.js +0 -402
  801. package/dist/transforms-text/delete-text-inline-points.js +0 -82
  802. package/dist/transforms-text/delete-text-plan.js +0 -55
  803. package/dist/transforms-text/delete-text-removal.js +0 -153
  804. package/dist/transforms-text/delete-text-structural-cleanup.js +0 -130
  805. package/dist/transforms-text/delete-text-whole-blocks.js +0 -70
  806. package/dist/transforms-text/delete-text.js +0 -804
  807. package/dist/transforms-text/full-document-range.js +0 -12
  808. package/dist/transforms-text/insert-text.js +0 -314
  809. package/dist/types/types.d.ts +0 -13
  810. package/dist/utils/format-debug-value.d.ts +0 -8
  811. package/dist/utils/format-debug-value.js +0 -31
  812. package/dist/utils/get-default-insert-location.js +0 -19
  813. package/dist/utils/is-object.d.ts +0 -4
  814. package/dist/utils/is-object.js +0 -4
  815. package/dist/utils/match-path.js +0 -8
  816. package/dist/utils/node-keys.d.ts +0 -15
  817. package/dist/utils/node-keys.js +0 -179
  818. package/dist/utils/node-match.js +0 -9
  819. package/dist/utils/string.js +0 -283
  820. package/dist/yjs/core/addresses.js +0 -98
  821. package/dist/yjs/core/ancestor-properties.js +0 -56
  822. package/dist/yjs/core/attributes.js +0 -21
  823. package/dist/yjs/core/awareness-adapter.d.ts +0 -5
  824. package/dist/yjs/core/awareness-adapter.js +0 -399
  825. package/dist/yjs/core/awareness-relative-selection.js +0 -22
  826. package/dist/yjs/core/awareness.js +0 -25
  827. package/dist/yjs/core/binding.d.ts +0 -3
  828. package/dist/yjs/core/binding.js +0 -128
  829. package/dist/yjs/core/boundaries.js +0 -453
  830. package/dist/yjs/core/canonical-split.js +0 -130
  831. package/dist/yjs/core/change-bridge.js +0 -124
  832. package/dist/yjs/core/change-regions.js +0 -119
  833. package/dist/yjs/core/controller-registry.js +0 -70
  834. package/dist/yjs/core/controller.d.ts +0 -6
  835. package/dist/yjs/core/controller.js +0 -1282
  836. package/dist/yjs/core/document.js +0 -1499
  837. package/dist/yjs/core/editor-adapter.d.ts +0 -18
  838. package/dist/yjs/core/editor-adapter.js +0 -145
  839. package/dist/yjs/core/editor-only-roots.js +0 -53
  840. package/dist/yjs/core/editor-types.d.ts +0 -1
  841. package/dist/yjs/core/enclosures.js +0 -410
  842. package/dist/yjs/core/event-change-bridge.js +0 -3642
  843. package/dist/yjs/core/index.d.ts +0 -4
  844. package/dist/yjs/core/joined-lines.js +0 -81
  845. package/dist/yjs/core/joins.js +0 -587
  846. package/dist/yjs/core/json-equality.js +0 -31
  847. package/dist/yjs/core/keys.js +0 -29
  848. package/dist/yjs/core/letter-scripts.js +0 -449
  849. package/dist/yjs/core/new-letters.js +0 -300
  850. package/dist/yjs/core/path.js +0 -25
  851. package/dist/yjs/core/plugin.js +0 -206
  852. package/dist/yjs/core/record.js +0 -4
  853. package/dist/yjs/core/replacement.js +0 -165
  854. package/dist/yjs/core/retraction.js +0 -132
  855. package/dist/yjs/core/root-owners.js +0 -110
  856. package/dist/yjs/core/root-projection-index.js +0 -428
  857. package/dist/yjs/core/schema-metadata.js +0 -88
  858. package/dist/yjs/core/selection.js +0 -34
  859. package/dist/yjs/core/set-valued-attributes.js +0 -57
  860. package/dist/yjs/core/shared-effect-log.d.ts +0 -4
  861. package/dist/yjs/core/shared-effect-log.js +0 -674
  862. package/dist/yjs/core/text-runs.js +0 -1596
  863. package/dist/yjs/core/types.d.ts +0 -76
  864. package/dist/yjs/react/useYjs.d.ts +0 -25
  865. package/dist/yjs/react/useYjs.js +0 -85
@@ -1,2908 +0,0 @@
1
- import { getDefined } from "../../internal/get-defined.js";
2
- import { countCoreWork } from "../../core/work.js";
3
- import { jsonEqual } from "../../core/change/json.js";
4
- import { PreparedTokenSlice, closeToken, encodeNodes, openToken, textToken } from "../../core/change/tokens.js";
5
- import { normalizeSetValues } from "../../core/change/transform.js";
6
- import { DocumentIndex } from "../../core/change/document-index.js";
7
- import { RootChange, applyPropertyModifications, mapRootChangePositionBackward, semanticPropertyModifications } from "../../core/change/root-change.js";
8
- import { createInternalDocumentChange, getInternalDocumentChangeEntries, getInternalDocumentRootChange, valueRootIndex } from "../../core/change/document-change.js";
9
- import { countLedgerWork } from "../ledger/work.js";
10
- import { isEditingChange } from "../facts/editing.js";
11
- import { recordFormats } from "./layers.js";
12
- import { AUTHORED_MARKS_KEY, followsOf, joinedOf, readAuthoredMarks, readMembers, withMembers } from "./marks.js";
13
- import { incarnationOf, incarnationOfLink, linkOf } from "../facts/records.js";
14
- import { factsOf, isJoinAside } from "../facts/facts.js";
15
- import { isCut } from "./cuts.js";
16
- import { gaveBy, ownOf } from "./halves.js";
17
- import { isTextBlock } from "./resolve.js";
18
- import { unrepresentable, unrepresentableFor } from "../refusal.js";
19
- import { carriedJudge } from "./carried.js";
20
- import { refuseUnplacedGridWrite } from "./grid.js";
21
- //#region src/authored/tree/record.ts
22
- const NO_COPIES = /* @__PURE__ */ new Map();
23
- const closeIndexOf = (tokens, at) => {
24
- let depth = 0;
25
- for (let index = at; index < tokens.length; index += 1) {
26
- const { kind } = getDefined(tokens[index]);
27
- if (kind === "open") depth += 1;
28
- if (kind === "close") depth -= 1;
29
- if (depth === 0) return index;
30
- }
31
- return tokens.length;
32
- };
33
- const isKeyedJoin = (mark) => (mark.kind === "join" || mark.kind === "joined") && mark.key !== void 0;
34
- const isFollower = (mark) => (mark.kind === "insert" || mark.kind === "split") && mark.cut === void 0;
35
- const withoutLinkOutsideCopy = (mark, copied) => {
36
- if (!isFollower(mark) || mark.follows === void 0 || copied.has(mark.follows)) return mark;
37
- const { follows: _, ...rest } = mark;
38
- return rest;
39
- };
40
- const isEditingMoveCopy = (op, change) => op.moved === true && isEditingChange(change);
41
- const propsOf = (node) => {
42
- if (typeof node !== "object" || node === null) return {};
43
- const { children: _children, text: _text, ...props } = node;
44
- return props;
45
- };
46
- const withoutHeld = (props) => {
47
- const members = readMembers(props);
48
- return members.some((member) => member.kind === "held") ? withMembers(props, members.filter((member) => member.kind !== "held")) : props;
49
- };
50
- const withoutSpares = (props) => {
51
- const members = readMembers(props);
52
- return members.some((member) => member.kind === "reserve" || member.kind === "as") ? withMembers(props, members.filter((member) => member.kind !== "reserve" && member.kind !== "as")) : props;
53
- };
54
- const BOUNDARY_KINDS = /* @__PURE__ */ new Set([
55
- "join",
56
- "joined",
57
- "split",
58
- "unwrap",
59
- "wrap"
60
- ]);
61
- const reviewed = (token) => token.kind === "open" && readMembers(token.props).length > 0;
62
- /**
63
- * The insertion the content belongs to: the last one, since `marks` lists a
64
- * node's insertions outer to inner. A block's `follows` insertion is listed
65
- * outside that order.
66
- */
67
- const innermostInsert = (marks) => marks.findLast((mark) => mark.kind === "insert");
68
- const othersDelete = (member) => member.kind === "delete" && !isEditingChange(member.change);
69
- const struckWhole = (node) => {
70
- const members = readMembers(node);
71
- return members.length > 0 && members.every(othersDelete) && (node.children ?? []).every(struckWhole);
72
- };
73
- const bareContextAt = (index, position) => index.openContextAt(position).filter((entry) => entry.contentFrom <= position && position <= entry.contentTo).map((entry) => withMembers(propsOf(index.node(entry.path)), []));
74
- const identity = (position) => position;
75
- /**
76
- * The accepted position at the far side of an empty accepted leaf whose
77
- * stored letters the projection hid, with the stored edge of that leaf on the
78
- * side of `caret`, which sits at one end of those letters.
79
- */
80
- const farEdge = (toProjected, toStored, index, caret) => {
81
- const at = toProjected(caret);
82
- const from = toStored(at, -1);
83
- const to = toStored(at, 1);
84
- if (from === to || caret !== from && caret !== to) return null;
85
- const [open] = index.slice(from - 1, from).tokens;
86
- const [close] = index.slice(to, to + 1).tokens;
87
- if (open?.kind !== "open" || open.nodeKind !== "text" || close?.kind !== "close" || toStored(at - 1, 1) !== from - 1 || toStored(at + 1, -1) !== to + 1) return null;
88
- return caret === from ? {
89
- position: at + 1,
90
- stored: from - 1
91
- } : {
92
- position: at - 1,
93
- stored: to + 1
94
- };
95
- };
96
- const bothUnclaimed = (before, after) => !Object.hasOwn(before, "authored") && !Object.hasOwn(after, "authored");
97
- const changesOnlyProperties = (step) => step.sections.every((value, index) => index % 2 === 0 || value < 0);
98
- /**
99
- * The open tokens of the review texts that hold the letters of the plain text
100
- * opening at `open`. A letter maps by its end with backward association, so
101
- * the letter after a mid-text insertion lands in its own review text. The map
102
- * keeps the letters' order, so each review text costs one lookup and a binary
103
- * search for the first letter past it.
104
- */
105
- const reviewOpensOf = (map, review, open, length) => {
106
- const endOf = (letter) => {
107
- countLedgerWork("lettersMapped");
108
- return map(open + 2 + letter, -1, false);
109
- };
110
- const opens = [];
111
- let letter = 0;
112
- while (letter < length) {
113
- const at = review.openContextAt(endOf(letter)).at(-1);
114
- if (at?.kind !== "text") {
115
- letter += 1;
116
- continue;
117
- }
118
- if (opens.at(-1) !== at.from) opens.push(at.from);
119
- if (endOf(length - 1) <= at.contentTo) break;
120
- let low = letter + 1;
121
- let high = length - 1;
122
- while (low < high) {
123
- const middle = low + high >> 1;
124
- if (endOf(middle) > at.contentTo) high = middle;
125
- else low = middle + 1;
126
- }
127
- letter = low;
128
- }
129
- return opens;
130
- };
131
- /**
132
- * Rebase a step that changes only properties. It moves no content, so each
133
- * edited token maps on its own, in the review draft's order, wherever `plain`
134
- * shows it, and the step leaves every position where it was.
135
- */
136
- const rebaseProperties = (step, map, plain, review) => {
137
- const edits = [];
138
- const reviewTokens = (token) => {
139
- const entry = plain === review ? null : plain.nodeStartingAt(token);
140
- const text = entry && plain.node(entry.path).text;
141
- if (!entry || typeof text !== "string" || text === "") return [map(token, 1, false)];
142
- return reviewOpensOf(map, review, token, text.length);
143
- };
144
- let before = 0;
145
- for (let pair = 0; pair < step.sections.length / 2; pair += 1) {
146
- const length = getDefined(step.sections[pair * 2]);
147
- if (step.sections[pair * 2 + 1] === -2) {
148
- const data = step.data[pair];
149
- for (let offset = 0; offset < length; offset += 1) for (const at of reviewTokens(before + offset)) edits.push({
150
- at,
151
- data,
152
- plainAt: before + offset
153
- });
154
- }
155
- before += length;
156
- }
157
- edits.sort((left, right) => left.at - right.at);
158
- const groups = [];
159
- let at = 0;
160
- for (const [index, edit] of edits.entries()) {
161
- if (edit.at < at) {
162
- if (jsonEqual(edit.data, edits[index - 1]?.data)) continue;
163
- throw new Error("Two edits map to one review token.");
164
- }
165
- if (edit.at > at) groups.push({
166
- after: at,
167
- before: at,
168
- data: null,
169
- kind: "kept",
170
- length: edit.at - at
171
- });
172
- groups.push({
173
- after: edit.at,
174
- before: edit.at,
175
- data: edit.data,
176
- kind: "kept",
177
- length: 1,
178
- plainAt: edit.plainAt
179
- });
180
- at = edit.at + 1;
181
- }
182
- if (review.length > at) groups.push({
183
- after: at,
184
- before: at,
185
- data: null,
186
- kind: "kept",
187
- length: review.length - at
188
- });
189
- return {
190
- afterMap: map,
191
- groups
192
- };
193
- };
194
- /**
195
- * Rebase a plain step into review coordinates through `map`, from the plain
196
- * draft before the step to the review draft, and map the step's output
197
- * positions into review coordinates with the step's inserted tokens kept.
198
- */
199
- const rebase = (step, map, reviewLength) => {
200
- const groups = [];
201
- let plainBefore = 0;
202
- let plainAfter = 0;
203
- let reviewBefore = 0;
204
- let reviewAfter = 0;
205
- const outputs = [];
206
- for (let pair = 0; pair < step.sections.length / 2; pair += 1) {
207
- const length = step.sections[pair * 2];
208
- const inserted = step.sections[pair * 2 + 1];
209
- const replacesNext = inserted < 0 && pair + 1 < step.sections.length / 2;
210
- const mappedEnd = inserted === 0 && length > 0 ? map(plainBefore + length, -1, false) : map(plainBefore + length, replacesNext ? 1 : -1, replacesNext && step.sections[pair * 2 + 2] > 0 ? false : void 0);
211
- if (inserted === 0 && length > 0 && mappedEnd < reviewBefore) throw unrepresentableFor("crosses");
212
- const reviewEnd = Math.max(reviewBefore, mappedEnd);
213
- const removed = reviewEnd - reviewBefore;
214
- if (inserted < 0) {
215
- outputs.push({
216
- inserted: false,
217
- plainAfter,
218
- plainAfterTo: plainAfter + length,
219
- plainBefore,
220
- reviewAfter,
221
- reviewBefore,
222
- reviewTo: reviewEnd
223
- });
224
- if (inserted === -2) {
225
- const data = step.data[pair];
226
- let at = reviewBefore;
227
- for (let offset = 0; offset < length; offset += 1) {
228
- const token = map(plainBefore + offset, 1);
229
- if (token > at) groups.push({
230
- after: reviewAfter + at - reviewBefore,
231
- before: at,
232
- data: null,
233
- kind: "kept",
234
- length: token - at
235
- });
236
- groups.push({
237
- after: reviewAfter + token - reviewBefore,
238
- before: token,
239
- data,
240
- kind: "kept",
241
- length: 1,
242
- plainAt: plainBefore + offset
243
- });
244
- at = token + 1;
245
- }
246
- if (reviewEnd > at) groups.push({
247
- after: reviewAfter + at - reviewBefore,
248
- before: at,
249
- data: null,
250
- kind: "kept",
251
- length: reviewEnd - at
252
- });
253
- } else if (removed > 0) groups.push({
254
- after: reviewAfter,
255
- before: reviewBefore,
256
- data: null,
257
- kind: "kept",
258
- length: removed
259
- });
260
- plainAfter += length;
261
- reviewAfter += removed;
262
- } else {
263
- const slice = step.data[pair] ?? PreparedTokenSlice.empty;
264
- outputs.push({
265
- inserted: true,
266
- plainAfter,
267
- plainAfterTo: plainAfter + slice.length,
268
- plainBefore,
269
- reviewAfter,
270
- reviewBefore,
271
- reviewTo: reviewEnd
272
- });
273
- groups.push({
274
- after: reviewAfter,
275
- before: reviewBefore,
276
- kind: "replace",
277
- plainFrom: plainBefore,
278
- plainRemoved: length,
279
- removed,
280
- slice
281
- });
282
- plainAfter += slice.length;
283
- reviewAfter += slice.length;
284
- }
285
- plainBefore += length;
286
- reviewBefore = reviewEnd;
287
- }
288
- if (reviewBefore < reviewLength) {
289
- outputs.push({
290
- inserted: false,
291
- plainAfter,
292
- plainAfterTo: plainAfter,
293
- plainBefore,
294
- reviewAfter,
295
- reviewBefore,
296
- reviewTo: reviewLength
297
- });
298
- groups.push({
299
- after: reviewAfter,
300
- before: reviewBefore,
301
- data: null,
302
- kind: "kept",
303
- length: reviewLength - reviewBefore
304
- });
305
- reviewAfter += reviewLength - reviewBefore;
306
- }
307
- const covers = (output, position) => output !== void 0 && output.plainAfter <= position && position <= output.plainAfterTo;
308
- const removes = (output) => output?.inserted === true && output.plainAfter === output.plainAfterTo;
309
- const afterMap = (position, assoc, caret) => {
310
- let at = outputs.findIndex((output) => covers(output, position));
311
- const removal = removes(outputs[at]) ? at : at + 1;
312
- if (assoc > 0 && removes(outputs[removal]) && covers(outputs[removal + 1], position)) at = removal + 1;
313
- const output = outputs[at];
314
- if (!output) return reviewAfter;
315
- if (output.inserted) return output.reviewAfter + position - output.plainAfter;
316
- const review = map(output.plainBefore + position - output.plainAfter, assoc, caret);
317
- const holds = (other) => other.reviewBefore <= review && review <= other.reviewTo;
318
- const owner = (review < output.reviewBefore || review > output.reviewTo ? outputs.find((other) => !other.inserted && holds(other)) ?? outputs.find(holds) : void 0) ?? output;
319
- return owner.inserted ? owner.reviewAfter : owner.reviewAfter + review - owner.reviewBefore;
320
- };
321
- return {
322
- afterMap,
323
- groups
324
- };
325
- };
326
- /**
327
- * Each plain token goes to the review token the fold maps it to; review
328
- * content with no plain counterpart reads as inserted, and a plain token with
329
- * no single counterpart as replaced.
330
- */
331
- const correspondence = (plain, review, map) => {
332
- const sections = [];
333
- const data = [];
334
- let reviewAt = 0;
335
- let kept = 0;
336
- const replace = (removed, to) => {
337
- if (kept > 0) {
338
- sections.push(kept, -1);
339
- data.push(null);
340
- kept = 0;
341
- }
342
- const slice = review.slice(reviewAt, to);
343
- sections.push(removed, slice.length);
344
- data.push(slice);
345
- reviewAt = to;
346
- };
347
- for (let position = 0; position < plain.length; position += 1) {
348
- const from = map(position, 1, false);
349
- const to = map(position + 1, -1);
350
- if (to - from === 1 && from >= reviewAt) {
351
- if (from > reviewAt) replace(0, from);
352
- kept += 1;
353
- reviewAt = from + 1;
354
- } else replace(1, Math.max(reviewAt, to));
355
- }
356
- if (reviewAt < review.length) replace(0, review.length);
357
- if (kept > 0) {
358
- sections.push(kept, -1);
359
- data.push(null);
360
- }
361
- return RootChange.fromSections(sections, data);
362
- };
363
- const groupsChange = (groups) => {
364
- const sections = [];
365
- const data = [];
366
- for (const group of groups) if (group.kind === "kept") {
367
- sections.push(group.length, group.data ? -2 : -1);
368
- data.push(group.data);
369
- } else {
370
- sections.push(group.removed, group.slice.length);
371
- data.push(group.slice);
372
- }
373
- return RootChange.fromSections(sections, data);
374
- };
375
- const keepsTokens = (added) => added === -1 || added === -2;
376
- const insertsEmptyLeaves = (change) => {
377
- let inserted = false;
378
- for (let pair = 0; pair < change.data.length; pair += 1) {
379
- const length = change.sections[pair * 2];
380
- const added = change.sections[pair * 2 + 1];
381
- if (keepsTokens(added)) continue;
382
- const data = change.data[pair];
383
- if (length !== 0 || !(data instanceof PreparedTokenSlice)) return false;
384
- if (data.tokens.length % 2 !== 0) return false;
385
- for (let at = 0; at < data.tokens.length; at += 2) {
386
- const open = data.tokens[at];
387
- const close = data.tokens[at + 1];
388
- if (open.kind !== "open" || open.nodeKind !== "text" || close.kind !== "close" || close.nodeKind !== "text") return false;
389
- }
390
- inserted ||= data.length > 0;
391
- }
392
- return inserted;
393
- };
394
- /**
395
- * For a canonical step that only inserts empty text leaves, each inserted
396
- * leaf on a line the stored document holds childless, with its frame span
397
- * and the stored position it lands at. Enter at a line's end moves the
398
- * frame's empty leaf to the new line and the step refills the old one, while
399
- * the stored split keeps the stored leaf on the old line, so the first leaf
400
- * after each refilled line is checked too.
401
- */
402
- const emptyLeavesOf = (change, frame, stored, toStored) => {
403
- if (!insertsEmptyLeaves(change)) return [];
404
- const leaves = [];
405
- const lineOf = (position) => getDefined(frame.openContextAt(position).findLast((entry) => entry.kind === "element"));
406
- const record = (position) => {
407
- const leaf = frame.textAt(position);
408
- if (!leaf || leaf.contentFrom !== leaf.contentTo) return;
409
- const target = stored.nodeStartingAt(toStored(lineOf(leaf.from).from, 1, false));
410
- if (target?.kind === "element" && target.contentFrom === target.contentTo && !leaves.some((entry) => entry.stored === target.contentFrom)) leaves.push({
411
- from: leaf.from,
412
- slice: frame.nodeSlice(leaf.path),
413
- stored: target.contentFrom,
414
- to: leaf.to
415
- });
416
- };
417
- let position = 0;
418
- for (let index = 0; index < change.sections.length; index += 2) {
419
- const length = change.sections[index];
420
- const added = change.sections[index + 1];
421
- if (keepsTokens(added)) {
422
- position += length;
423
- continue;
424
- }
425
- for (let at = position; at < position + added; at += 2) {
426
- record(at + 1);
427
- const next = frame.pointAt(lineOf(at).to, 1);
428
- if (next) record(frame.positionAt(next));
429
- }
430
- position += added;
431
- }
432
- return leaves;
433
- };
434
- const advanceBreaks = (breaks, frame, stored) => breaks.map(({ after, at, before }) => ({
435
- after: getDefined(stored.mapPos(after, 1)),
436
- at: getDefined(frame.mapPos(at, 1)),
437
- before: getDefined(stored.mapPos(before, -1))
438
- })).filter(({ after, before }) => after !== before);
439
- /**
440
- * The stretch of a root's frame, in its coordinates before the steps, that the
441
- * steps change. A step crosses only a break inside it.
442
- */
443
- const changedStretch = (changes) => {
444
- let from = Infinity;
445
- let to = -Infinity;
446
- let earlier = null;
447
- for (const change of changes) {
448
- const back = (position, assoc) => earlier ? getDefined(mapRootChangePositionBackward(earlier, position, assoc)) : position;
449
- let position = 0;
450
- for (let pair = 0; pair < change.sections.length; pair += 2) {
451
- const length = change.sections[pair];
452
- if (change.sections[pair + 1] !== -1) {
453
- from = Math.min(from, back(position, -1));
454
- to = Math.max(to, back(position + length, 1));
455
- }
456
- position += length;
457
- }
458
- earlier = earlier ? earlier.compose(change) : change;
459
- }
460
- return from <= to ? {
461
- from,
462
- to
463
- } : null;
464
- };
465
- const isLine = (index, entry, isInline) => {
466
- if (entry.kind !== "element") return false;
467
- const node = index.node(entry.path);
468
- return isTextBlock(node) && !isInline(node);
469
- };
470
- const lineAround = (index, at, assoc, isInline) => {
471
- const point = index.pointAt(at, assoc);
472
- return point && index.openContextAt(index.positionAt(point)).findLast((entry) => isLine(index, entry, isInline));
473
- };
474
- const enclosingAt = (index, position) => index.openContextAt(position).filter((entry) => entry.from < position && position < entry.to);
475
- const lineHolding = (index, position, isInline) => enclosingAt(index, position).findLast((entry) => isLine(index, entry, isInline));
476
- const writtenAddedLine = (change, frame, earlier, added, isInline) => {
477
- const stretch = changedStretch([change]);
478
- const line = stretch && lineHolding(frame, stretch.from, isInline);
479
- if (!line || stretch.from <= line.from || stretch.to >= line.to) return change;
480
- const back = (position, assoc) => earlier ? getDefined(mapRootChangePositionBackward(earlier, position, assoc)) : position;
481
- const span = added(back(line.from + 1, 1));
482
- if (!span || span.from > back(line.from, -1) || back(line.to, 1) > span.to) return change;
483
- const after = change.apply(frame);
484
- return RootChange.create(frame, {
485
- from: line.from,
486
- insert: after.slice(line.from, line.to + after.length - frame.length),
487
- to: line.to
488
- });
489
- };
490
- const lineClosedAt = (index, position, slice, isInline) => {
491
- const open = enclosingAt(index, position);
492
- let depth = 0;
493
- for (const token of slice.tokens) {
494
- if (token.kind === "open") depth += 1;
495
- if (token.kind !== "close") continue;
496
- if (depth > 0) {
497
- depth -= 1;
498
- continue;
499
- }
500
- const closed = open.pop();
501
- if (closed && isLine(index, closed, isInline)) return closed;
502
- }
503
- };
504
- const joinsLines = (tokens) => {
505
- const opensElement = [];
506
- let closesOuter = false;
507
- for (const token of tokens) if (token.kind === "open") opensElement.push(token.nodeKind === "element");
508
- else if (token.kind === "close") if (opensElement.length > 0) opensElement.pop();
509
- else closesOuter ||= token.nodeKind === "element";
510
- return closesOuter && opensElement.includes(true);
511
- };
512
- const judgeStruckGridWrite = (step, frame, stored, toStored, holdsGridParts, changeId, moves) => {
513
- const strikingChanges = (range) => range.kind === "element" ? readMembers(stored.node(range.path)).flatMap((member) => member.kind === "delete" && !isEditingChange(member.change) ? [member.change] : []) : [];
514
- const struckByOtherChange = (range) => strikingChanges(range).some((change) => change !== changeId);
515
- const struckByThisChange = (range) => strikingChanges(range).includes(changeId);
516
- const struckPart = (range) => struckByOtherChange(range) && holdsGridParts(stored.node(range.path));
517
- const struckAround = (from, to) => stored.openContextAt(from).some((range) => range.from < from && to < range.to && struckPart(range));
518
- const removesOnlyStruckParts = (from, to) => {
519
- let at = from;
520
- while (at < to) {
521
- const removed = stored.nodeStartingAt(at);
522
- if (!removed || removed.to > to || !struckPart(removed)) return false;
523
- at = removed.to;
524
- }
525
- return at > from;
526
- };
527
- let position = 0;
528
- let takesStruckParts = false;
529
- let writesOther = false;
530
- for (let pair = 0; pair < step.data.length; pair += 1) {
531
- const length = step.sections[pair * 2];
532
- const inserted = step.sections[pair * 2 + 1];
533
- if (inserted < 0 || length === 0 && inserted === 0) {
534
- position += length;
535
- continue;
536
- }
537
- const start = toStored(position, 1);
538
- const end = toStored(position + length, -1);
539
- const from = Math.min(start, end);
540
- const to = Math.max(start, end);
541
- if (length === 0 ? struckAround(from, to) : struckAround(from, from) || struckAround(to, to)) throw unrepresentableFor("grid");
542
- if (length > 0 && joinsLines(frame.slice(position, position + length).tokens)) {
543
- const taken = [];
544
- for (const range of stored.nodeRangesTouching(from, to)) {
545
- if (range.from < from || range.to > to) continue;
546
- if (struckByThisChange(range)) taken.push(range);
547
- if (struckPart(range) && !taken.some((around) => around.from <= range.from && range.to <= around.to)) throw unrepresentableFor("grid");
548
- }
549
- } else if (length > 0 && !(moves && isEditingChange(changeId)) && removesOnlyStruckParts(from, to)) {
550
- if (moves) throw unrepresentableFor("grid");
551
- takesStruckParts = true;
552
- position += length;
553
- continue;
554
- }
555
- writesOther = true;
556
- position += length;
557
- }
558
- if (writesOther) return "other";
559
- return takesStruckParts ? "struck-parts" : "nothing";
560
- };
561
- /**
562
- * Splits a frame step that crosses a break into sub-steps that each map in
563
- * stored order, or returns null when it crosses none. It keeps a text
564
- * insertion at a break whole, cuts a text removal or property change inside
565
- * one line at each break, and lowers a merge of two lines to removals around
566
- * a move of the right line's children to the left line's end. It throws on
567
- * any other crossing, on a merge whose right line holds a break after the
568
- * merge point, and on a step that breaks a line after a break inside that
569
- * line even when the step crosses no break.
570
- */
571
- const lowerAcrossBreaks = (step, breaks, frame, isInline) => {
572
- if (breaks.length === 0) return null;
573
- const crossing = (from, to) => (edge) => from === to ? edge.at === from : from < edge.at && edge.at < to;
574
- const sections = [];
575
- let position = 0;
576
- let crosses = false;
577
- for (let pair = 0; pair < step.data.length; pair += 1) {
578
- const length = step.sections[pair * 2];
579
- const added = step.sections[pair * 2 + 1];
580
- const data = step.data[pair];
581
- if (added !== -1) {
582
- sections.push({
583
- from: position,
584
- to: position + length,
585
- added,
586
- data
587
- });
588
- crosses ||= breaks.some(crossing(position, position + length));
589
- const line = data instanceof PreparedTokenSlice && lineClosedAt(frame, position, data, isInline);
590
- if (line && breaks.some(({ at }) => line.contentFrom <= at && at < position)) throw unrepresentableFor("reordered");
591
- }
592
- position += length;
593
- }
594
- if (!crosses) return null;
595
- const result = [];
596
- let index = frame;
597
- let edges = breaks;
598
- const emit = (from, to, added, data, role = null, movedChildren) => {
599
- const change = RootChange.fromSections([
600
- from,
601
- -1,
602
- to - from,
603
- added,
604
- index.length - to,
605
- -1
606
- ], [
607
- null,
608
- data,
609
- null
610
- ]);
611
- result.push(movedChildren ? {
612
- change,
613
- movedChildren,
614
- role
615
- } : {
616
- change,
617
- role
618
- });
619
- index = change.apply(index);
620
- edges = edges.map((edge) => ({
621
- ...edge,
622
- at: getDefined(change.mapPos(edge.at, 1))
623
- }));
624
- return change;
625
- };
626
- const remove = (from, to, role = null) => {
627
- const cuts = [
628
- from,
629
- ...edges.filter(({ at }) => from < at && at < to).map(({ at }) => at),
630
- to
631
- ];
632
- for (let at = cuts.length - 2; at >= 0; at -= 1) if (cuts[at] < cuts[at + 1]) emit(cuts[at], cuts[at + 1], 0, PreparedTokenSlice.empty, role);
633
- };
634
- const lineAt = (at, assoc) => lineAround(index, at, assoc, isInline);
635
- for (const { from, to, added, data } of sections.reverse()) {
636
- const hits = edges.filter(crossing(from, to));
637
- const inserted = data instanceof PreparedTokenSlice ? data : PreparedTokenSlice.empty;
638
- if (hits.length === 0 || from === to && inserted.tokens.every((token) => token.kind === "text")) {
639
- emit(from, to, added, data);
640
- continue;
641
- }
642
- const removed = index.slice(from, to).tokens;
643
- const line = lineAt(from, 1);
644
- const onlyText = removed.every((token) => token.kind === "text" || token.nodeKind === "text");
645
- if (from < to && (added === 0 || added === -2) && onlyText && line && line.from === lineAt(to, -1)?.from) {
646
- const cuts = [
647
- from,
648
- ...hits.map(({ at }) => at),
649
- to
650
- ];
651
- for (let at = cuts.length - 2; at >= 0; at -= 1) emit(cuts[at], cuts[at + 1], added, data);
652
- continue;
653
- }
654
- const left = lineAt(from, -1);
655
- const right = lineAt(to, 1);
656
- if (added !== 0 || !left || !right || left.from >= right.from || from < left.contentFrom || from > left.contentTo || to < right.contentFrom || to > right.contentTo) throw unrepresentableFor("crosses");
657
- if (edges.some(({ at }) => to < at && at <= right.contentTo)) throw unrepresentableFor("crosses");
658
- remove(right.contentFrom, to);
659
- remove(left.to, right.from);
660
- const rightAt = lineAt(left.to, 1);
661
- if (!rightAt) throw unrepresentableFor("crosses");
662
- const children = index.slice(rightAt.contentFrom, rightAt.contentTo);
663
- const landing = emit(left.contentTo, left.contentTo, children.length, children, "landing", children);
664
- remove(getDefined(landing.mapPos(rightAt.from, 1)), getDefined(landing.mapPos(rightAt.to, 1)), "source");
665
- remove(from, left.contentTo);
666
- }
667
- return result;
668
- };
669
- /**
670
- * Where a composition commit's claimed write lands in the review draft: at
671
- * the commit's stored place, in the props of the leaf the command wrote, when
672
- * the command wrote into the element that holds that place. Hidden struck
673
- * text gives the frame's write position several stored places, and only the
674
- * stored one keeps the word where the person saw it.
675
- */
676
- const compositionLanding = (input, fold, root, change, written) => {
677
- const { composition, projection } = input;
678
- if (composition?.root !== root || !projection || !written) return null;
679
- const element = projection.map.nodePath(root, composition.element);
680
- const stretch = changedStretch([change]);
681
- if (!element || !stretch) return null;
682
- const at = fold.frameChange ? getDefined(mapRootChangePositionBackward(fold.frameChange, stretch.from, -1)) : stretch.from;
683
- const holder = getDefined(projection.indexes.get(root)).openContextAt(at).findLast((entry) => entry.kind === "element" && entry.contentFrom <= at && at <= entry.contentTo);
684
- if (!holder || !jsonEqual(holder.path, element)) return null;
685
- const point = written.pointAt(getDefined(change.mapPos(stretch.from, -1)), 1);
686
- const { [AUTHORED_MARKS_KEY]: _marks, ...leaf } = point ? propsOf(written.node(point.path)) : {};
687
- return {
688
- at: stretch.from,
689
- leaf: point ? leaf : null,
690
- place: fold.composed ? getDefined(fold.composed.mapPos(composition.position, 1)) : composition.position
691
- };
692
- };
693
- const applyReusingStep = (step, root, index, change) => {
694
- const written = getInternalDocumentRootChange(step.change, root);
695
- return index === step.indexedBefore.get(root) && written && change.sameAs(written) ? getDefined(step.indexedAfter.get(root)) : change.apply(index);
696
- };
697
- /**
698
- * Record a transaction's steps as the review tree's change. Each step folds
699
- * through a review draft: it is rebased from the plain draft into the review
700
- * draft, recorded there and applied, so each step reads the review state the
701
- * earlier ones left. Recording keys only on token kind, existing marks, the
702
- * step's origin and move link, intent and writer, so it imports no plugin or
703
- * command module.
704
- */
705
- const recordAuthoredSteps = (input) => {
706
- const facts = factsOf(input.before);
707
- const changeId = input.forcedChangeId ?? input.changeId;
708
- const inc = input.inc ?? void 0;
709
- const own = incarnationOf({
710
- at: input.now,
711
- change: changeId,
712
- inc
713
- });
714
- const isOwn = (mark) => input.forcedChangeId ? incarnationOf(mark) === own : mark.author === input.writer;
715
- const ownInsertion = (node) => {
716
- const inserted = innermostInsert(input.dependencies.marks(node));
717
- return inserted !== void 0 && isOwn(inserted);
718
- };
719
- const base = {
720
- at: input.now,
721
- author: input.writer,
722
- change: changeId,
723
- ...inc === void 0 ? {} : { inc }
724
- };
725
- const markOf = (kind) => kind === "split" ? {
726
- ...base,
727
- kind
728
- } : {
729
- ...base,
730
- kind
731
- };
732
- const folds = /* @__PURE__ */ new Map();
733
- let writtenPlain = true;
734
- const ownedRootsOf = (props) => input.ownedRoots?.(props) ?? [];
735
- const doubled = /* @__PURE__ */ new Map();
736
- const keepsMergedSource = !isEditingChange(changeId);
737
- const doubledIn = (root) => {
738
- let roots = doubled.get(root);
739
- if (!roots) {
740
- roots = /* @__PURE__ */ new Set();
741
- doubled.set(root, roots);
742
- }
743
- return roots;
744
- };
745
- const holdsWithdrawal = (props) => ownedRootsOf(props).some(({ root }) => {
746
- if (!input.deleteRoots.has(root) && !input.followed.has(root)) return false;
747
- const index = folds.get(root)?.index ?? (input.before.roots?.[root] ? valueRootIndex(input.before, root) : null);
748
- const holds = (nodes) => nodes.some((node) => !ownInsertion(node) || node.children !== void 0 && (holdsWithdrawal(propsOf(node)) || holds(node.children)));
749
- return index !== null && holds(index.value);
750
- });
751
- const foldOf = (root) => {
752
- let fold = folds.get(root);
753
- if (!fold) {
754
- const created = input.createRoots.has(root);
755
- fold = {
756
- breaks: [],
757
- composed: null,
758
- frameChange: null,
759
- frameIndex: null,
760
- index: created ? DocumentIndex.fromValue([]) : valueRootIndex(input.before, root),
761
- leftward: true,
762
- map: identity,
763
- created,
764
- touched: false
765
- };
766
- folds.set(root, fold);
767
- }
768
- return fold;
769
- };
770
- const storedIndexes = /* @__PURE__ */ new Map();
771
- const carried = input.schema && carriedJudge({
772
- before: (root) => {
773
- if (!storedIndexes.has(root)) storedIndexes.set(root, input.createRoots.has(root) ? null : valueRootIndex(input.before, root));
774
- return storedIndexes.get(root) ?? null;
775
- },
776
- dependencies: input.dependencies,
777
- editing: isEditingChange(changeId),
778
- isOwn,
779
- projection: input.projection,
780
- schema: input.schema,
781
- standing: input.standing,
782
- writer: {
783
- ...base,
784
- commitWriteId: input.commitWriteId,
785
- isOwn
786
- }
787
- });
788
- const composeFrame = (fold, change) => fold.frameChange ? fold.frameChange.compose(change) : change;
789
- const foldIn = (fold, change, reusing) => {
790
- if (!change) return;
791
- fold.index = reusing ? applyReusingStep(reusing.step, reusing.root, fold.index, change) : change.apply(fold.index);
792
- fold.composed = fold.composed ? fold.composed.compose(change) : change;
793
- };
794
- const replaces = (from, to) => !isEditingChange(changeId) && typeof from.type === "string" && typeof to.type === "string" && from.type !== to.type && input.crossesUnique(from.type, to.type) || input.followed.size > 0 && ownedRootsOf(from).some(({ root }) => input.followed.has(root) && !ownedRootsOf(to).some((kept) => kept.root === root));
795
- const loweredRoots = /* @__PURE__ */ new Set();
796
- const stepChanges = input.steps.map((step) => ({
797
- changes: [...getInternalDocumentChangeEntries(step.change)].flatMap(([root, written]) => {
798
- if (input.followed.has(root)) return [];
799
- const plain = getDefined(step.indexedBefore.get(root));
800
- const aligned = step.origin === "slice" ? written.alignOpens(plain, bothUnclaimed) : written;
801
- const starts = /* @__PURE__ */ new Set();
802
- return [[
803
- root,
804
- replaceRetyped(aligned, plain, replaces, ownedRootsOf, () => doubledIn(root), (start) => {
805
- loweredRoots.add(root);
806
- starts.add(start);
807
- }),
808
- starts
809
- ]];
810
- }),
811
- step
812
- }));
813
- if (input.projection) {
814
- const { indexes, map } = input.projection;
815
- for (const root of map.roots) {
816
- const fold = foldOf(root);
817
- const toStored = (position, assoc) => getDefined(map.toStored(root, position, assoc));
818
- const caretAt = input.selectionBefore?.root === root ? input.selectionBefore.position : null;
819
- const far = caretAt === null ? null : farEdge((position) => getDefined(map.toProjected(root, position, "forward")), toStored, fold.index, caretAt);
820
- const stretch = changedStretch(stepChanges.flatMap(({ changes }) => changes.flatMap(([changed, change]) => changed === root ? [change] : [])));
821
- const frame = getDefined(indexes.get(root));
822
- fold.frameIndex = frame;
823
- fold.breaks = stretch ? map.breaks(root, lineHolding(frame, stretch.from, input.isInline)?.contentFrom ?? stretch.from, lineHolding(frame, stretch.to, input.isInline)?.contentTo ?? stretch.to) : [];
824
- fold.map = (position, assoc, caret) => {
825
- if (far && caret !== false && position === far.position) return far.stored;
826
- const before = toStored(position, assoc);
827
- if (caret === false) return before;
828
- const other = toStored(position, assoc < 0 ? 1 : -1);
829
- if (map.added(root, position)) return other;
830
- return caretAt !== null && before !== caretAt && other === caretAt ? caretAt : before;
831
- };
832
- }
833
- }
834
- let removesStruckParts = false;
835
- let writesOther = false;
836
- for (const { changes, step } of stepChanges) for (const [root, rootChange, retypedStarts] of changes) {
837
- const fold = foldOf(root);
838
- if (step.origin === "canonical") {
839
- const previous = fold.map;
840
- if (carried && step.drops) foldIn(fold, carried.drops(root, fold.index, getDefined(step.indexedBefore.get(root)), step.drops, (position, assoc) => previous(position, assoc, false)));
841
- const back = (position, assoc, caret) => previous(getDefined(mapRootChangePositionBackward(rootChange, position, assoc)), assoc, caret);
842
- const frame = fold.frameIndex && rootChange.apply(fold.frameIndex);
843
- const leaves = frame ? emptyLeavesOf(rootChange, frame, fold.index, back) : [];
844
- const recorded = RootChange.create(fold.index, leaves.map(({ slice, stored }) => ({
845
- from: stored,
846
- insert: slice
847
- })));
848
- fold.frameIndex = frame;
849
- if (frame) fold.frameChange = composeFrame(fold, rootChange);
850
- fold.breaks = advanceBreaks(fold.breaks, rootChange, recorded);
851
- if (recorded.empty) {
852
- fold.map = back;
853
- continue;
854
- }
855
- foldIn(fold, recorded);
856
- fold.map = (position, assoc, caret) => {
857
- const leaf = leaves.find(({ from, to }) => from <= position && position <= to);
858
- return leaf ? getDefined(recorded.mapPos(leaf.stored, -1)) + position - leaf.from : getDefined(recorded.mapPos(back(position, assoc, caret), assoc));
859
- };
860
- continue;
861
- }
862
- const properties = changesOnlyProperties(rootChange);
863
- const { projection } = input;
864
- const written = fold.frameIndex && projection && !properties ? writtenAddedLine(rootChange, fold.frameIndex, fold.frameChange, (position) => projection.map.added(root, position), input.isInline) : rootChange;
865
- if (fold.created) writesOther = true;
866
- if (!fold.created && step.origin !== "migration") {
867
- const toStored = fold.map;
868
- const frame = fold.frameIndex ?? getDefined(step.indexedBefore.get(root));
869
- const map = (position, assoc) => toStored(position, assoc, false);
870
- const moves = step.origin === "move" || step.move?.role === "source";
871
- const writes = properties ? "other" : judgeStruckGridWrite(written, frame, fold.index, map, input.gridRoles.holdsParts, changeId, moves);
872
- removesStruckParts ||= writes === "struck-parts";
873
- writesOther ||= writes === "other";
874
- if (!isEditingChange(changeId)) refuseUnplacedGridWrite({
875
- claims: input.dependencies.marks,
876
- frame,
877
- frameAfter: applyReusingStep(step, root, frame, written),
878
- gridRoles: input.gridRoles,
879
- moves,
880
- ownInsertion,
881
- stored: fold.index,
882
- toStored: map,
883
- written
884
- });
885
- }
886
- const subSteps = (fold.frameIndex && !properties ? lowerAcrossBreaks(written, fold.breaks, fold.frameIndex, input.isInline) : null) ?? [{
887
- change: written,
888
- role: step.move?.role ?? null
889
- }];
890
- for (const sub of subSteps) {
891
- if (sub.movedChildren && keepsMergedSource) for (const node of DocumentIndex.fromTokens(sub.movedChildren).value) exclusiveRootsIn(node, ownedRootsOf, doubledIn(root));
892
- const frameAfter = fold.frameIndex && applyReusingStep(step, root, fold.frameIndex, sub.change);
893
- const landing = step.composition ? compositionLanding(input, fold, root, sub.change, frameAfter) : null;
894
- const mapped = fold.map;
895
- const plainToReview = landing ? (position, assoc, caret) => position === landing.at ? landing.place : mapped(position, assoc, caret) : mapped;
896
- const { afterMap, groups } = properties ? rebaseProperties(sub.change, plainToReview, fold.frameIndex ?? getDefined(step.indexedBefore.get(root)), fold.index) : rebase(sub.change, plainToReview, fold.index.length);
897
- let recorded;
898
- let mapRecorded = identity;
899
- let copies = [];
900
- if (fold.created || step.origin === "migration") recorded = groupsChange(groups);
901
- else {
902
- const result = new RootRecorder(fold.index, {
903
- joinAside: (mark) => isJoinAside(facts, mark),
904
- dependencies: input.dependencies,
905
- plainToReview,
906
- changeId,
907
- composedLeaf: landing?.leaf ?? null,
908
- createTagId: input.createTagId,
909
- emptyTextKeeps: (key, value, parents) => input.emptyTextKeeps(key, value, parents, root),
910
- framed: input.projection !== void 0,
911
- fill: (site) => input.fill(site, root),
912
- frameIndex: fold.frameIndex,
913
- holdsGridParts: input.gridRoles.holdsParts,
914
- holdsWithdrawal,
915
- isInline: input.isInline,
916
- isOwn,
917
- keepsOnSplit: (split) => input.keepsOnSplit(split, root),
918
- slotted: (type) => input.slotted(type, root),
919
- declaredIn: (element, ancestors) => input.declaredIn(element, ancestors, root),
920
- splitKeepsIn: (source, continuation, place) => input.splitKeepsIn(source, continuation, place, root),
921
- joinCompares: input.joinCompares,
922
- leftward: fold.leftward,
923
- markOf,
924
- moveRole: sub.role,
925
- oneText: input.oneText ?? (() => false),
926
- origin: step.origin,
927
- standing: input.standing,
928
- commitWriteId: input.commitWriteId,
929
- selectionBefore: !fold.touched && input.selectionBefore?.root === root ? input.selectionBefore.position : null,
930
- source: step.source,
931
- holdsUnique: input.holdsUnique,
932
- unique: input.unique
933
- }).record(groups);
934
- recorded = result.change;
935
- mapRecorded = result.mapPosition;
936
- ({copies} = result);
937
- fold.leftward = result.leftward;
938
- writtenPlain &&= result.writtenPlain;
939
- }
940
- fold.touched = true;
941
- if (frameAfter) {
942
- fold.frameIndex = frameAfter;
943
- fold.frameChange = composeFrame(fold, sub.change);
944
- }
945
- const composedBefore = fold.composed;
946
- foldIn(fold, recorded.empty ? null : recorded, {
947
- root,
948
- step
949
- });
950
- if (carried && copies.length > 0) foldIn(fold, carried.copied(root, fold.index, composedBefore, copies));
951
- fold.breaks = advanceBreaks(fold.breaks, sub.change, recorded);
952
- fold.map = (position, assoc, caret) => mapRecorded(afterMap(position, assoc, caret), assoc, caret);
953
- }
954
- if (retypedStarts.size > 0) {
955
- const mapped = fold.map;
956
- fold.map = (position, assoc, caret) => mapped(position, assoc, caret !== true && assoc === 1 && retypedStarts.has(position) ? false : caret);
957
- }
958
- }
959
- if (removesStruckParts && !writesOther) throw unrepresentableFor("grid");
960
- if (carried) {
961
- for (const [root, fold] of folds) if (!fold.created && fold.composed && !fold.composed.empty) foldIn(fold, carried.settle(root, fold.index, fold.composed));
962
- }
963
- for (const [root, roots] of doubled) {
964
- const owners = /* @__PURE__ */ new Map();
965
- const count = (nodes) => {
966
- for (const node of nodes) {
967
- if (node.children === void 0) continue;
968
- for (const owned of ownedRootsOf(propsOf(node))) {
969
- if (!roots.has(owned.root)) continue;
970
- const seen = (owners.get(owned.root) ?? 0) + 1;
971
- if (seen > 1) throw unrepresentable("Suggesting cannot keep two forms of content that both own one content root.");
972
- owners.set(owned.root, seen);
973
- }
974
- count(node.children);
975
- }
976
- };
977
- count(getDefined(folds.get(root)).index.value);
978
- }
979
- if (!isEditingChange(changeId)) {
980
- const inline = (node) => node?.children !== void 0 && input.isInline(propsOf(node));
981
- for (const root of loweredRoots) {
982
- const fits = (type, nodes) => {
983
- const max = input.maxChildren(type, root);
984
- const missingTexts = nodes.filter((node, index) => inline(node) && (index === 0 || inline(nodes[index - 1]))).length + (inline(nodes.at(-1)) ? 1 : 0);
985
- if (max !== null && nodes.length + missingTexts > max) throw unrepresentable("Suggesting cannot keep an element beside the element that replaces it where their content admits no more children.");
986
- for (const node of nodes) if (node.children !== void 0 && typeof node.type === "string") fits(node.type, node.children);
987
- };
988
- fits(null, getDefined(folds.get(root)).index.value);
989
- }
990
- }
991
- const changes = /* @__PURE__ */ new Map();
992
- const indexedAfter = /* @__PURE__ */ new Map();
993
- for (const [root, fold] of folds) {
994
- if (fold.composed && !fold.composed.empty) changes.set(root, fold.composed);
995
- if (!input.deleteRoots.has(root)) indexedAfter.set(root, fold.index);
996
- }
997
- return {
998
- anchorChange: (plainAfter) => createInternalDocumentChange(new Map([...folds].filter(([root]) => !input.deleteRoots.has(root) && !input.followed.has(root)).map(([root, fold]) => [root, correspondence(plainAfter(root), fold.index, fold.map)]))),
999
- change: createInternalDocumentChange(changes, {
1000
- createRoots: input.createRoots,
1001
- deleteRoots: input.deleteRoots
1002
- }),
1003
- indexedAfter,
1004
- mapPosition: (root, position, assoc, caret = true) => folds.get(root)?.map(position, assoc, caret) ?? position,
1005
- writtenPlain
1006
- };
1007
- };
1008
- const restoredBy = (tag) => [tag.before, ...[tag.base, ...(tag.over ?? []).flat().map(({ write }) => write)].flatMap((write) => write?.kind === "set" ? [write.value] : [])];
1009
- const exclusiveRootsIn = (node, ownedRoots, roots = /* @__PURE__ */ new Set()) => {
1010
- if (node.children === void 0) return roots;
1011
- for (const { exclusive, root } of ownedRoots(propsOf(node))) if (exclusive) roots.add(root);
1012
- for (const child of node.children) exclusiveRootsIn(child, ownedRoots, roots);
1013
- return roots;
1014
- };
1015
- /**
1016
- * A retype the review marks cannot hold as a format change, lowered to a
1017
- * replacement of the node: one whose old and new properties `replaces`, such
1018
- * as a retype that drops a followed root the node owned or one that crosses a
1019
- * unique target. Each step lowers against the plain draft it wrote on, so a
1020
- * later retype of the node replaces the replacement an earlier one inserted.
1021
- */
1022
- const replaceRetyped = (change, before, replaces, ownedRoots, doubled, lowered) => {
1023
- let after = null;
1024
- const replaced = [];
1025
- let at = 0;
1026
- let covered = 0;
1027
- for (let pair = 0; pair < change.sections.length / 2; pair += 1) {
1028
- const length = change.sections[pair * 2];
1029
- if (change.sections[pair * 2 + 1] !== -2) {
1030
- at += length;
1031
- continue;
1032
- }
1033
- const modifications = change.data[pair];
1034
- for (let offset = 0; offset < length; offset += 1) {
1035
- const from = before.nodeStartingAt(at + offset);
1036
- if (!from) continue;
1037
- const node = before.node(from.path);
1038
- const props = propsOf(node);
1039
- if (!replaces(props, applyPropertyModifications(props, modifications))) continue;
1040
- if (!after) {
1041
- countCoreWork("retypeLoweringApplies");
1042
- after = change.apply(before);
1043
- }
1044
- const mapped = change.mapPos(at + offset, 1);
1045
- const to = mapped === null ? null : after.nodeStartingAt(mapped);
1046
- if (!to) continue;
1047
- const range = after.nodeRange(to.path);
1048
- if (range.from < covered) continue;
1049
- const struck = exclusiveRootsIn(node, ownedRoots);
1050
- for (const root of exclusiveRootsIn(after.node(to.path), ownedRoots)) if (struck.has(root)) doubled().add(root);
1051
- countCoreWork("retypeLowerings");
1052
- lowered(range.from);
1053
- replaced.push({
1054
- from: range.from,
1055
- insert: after.slice(range.from, range.to),
1056
- to: range.to
1057
- });
1058
- covered = range.to;
1059
- }
1060
- at += length;
1061
- }
1062
- return after === null || replaced.length === 0 ? change : change.compose(RootChange.create(after, replaced));
1063
- };
1064
- var RootRecorder = class {
1065
- copies = [];
1066
- ops = [];
1067
- propsWrittenAtStart = /* @__PURE__ */ new Map();
1068
- pieces = [];
1069
- freshened = /* @__PURE__ */ new WeakSet();
1070
- splitHalves = /* @__PURE__ */ new WeakSet();
1071
- joinIndex = null;
1072
- framedStrikes = [];
1073
- index;
1074
- options;
1075
- withdrawsWrap = false;
1076
- constructor(index, options) {
1077
- this.index = index;
1078
- this.options = options;
1079
- }
1080
- marks(props) {
1081
- return this.options.dependencies.marks(props);
1082
- }
1083
- isLiveJoin = (mark) => mark.kind === "join" && !this.options.joinAside(mark);
1084
- droppedOnSplit(continued, continuation, marks) {
1085
- const formats = marks.filter((mark) => mark.kind === "format");
1086
- if (formats.length === 0) return null;
1087
- const keeps = this.options.keepsOnSplit({
1088
- continuation,
1089
- path: continued.path,
1090
- reviewDraft: this.index.value,
1091
- source: continued.props
1092
- });
1093
- return new Set(formats.flatMap((mark) => [continued.props[mark.key], ...restoredBy(mark)].every((value) => keeps(mark.key, value)) ? [] : [mark.key]));
1094
- }
1095
- withMarks(props, marks, fresh = false) {
1096
- return this.options.dependencies.props(props, marks, fresh);
1097
- }
1098
- withoutCuts(props) {
1099
- return this.marks(props).filter((mark) => !isCut(mark));
1100
- }
1101
- hasMarkKind(props, kind) {
1102
- return this.marks(props).some((mark) => mark.kind === kind);
1103
- }
1104
- /** Whether two leaves read the same to review, however each stores it. */
1105
- sameReview(left, right) {
1106
- const read = (props) => ({
1107
- held: readMembers(props).filter((member) => member.kind === "held"),
1108
- marks: normalizeSetValues(this.marks(props)),
1109
- props: withMembers(props, [])
1110
- });
1111
- return jsonEqual(read(left), read(right));
1112
- }
1113
- record(groups) {
1114
- const plain = new Map(groups.flatMap((group) => {
1115
- const removals = group.kind === "replace" ? this.plainRemovals(group) : null;
1116
- return removals ? [[group, removals]] : [];
1117
- }));
1118
- if (this.options.origin !== "move" || !this.recordNodeMove(groups)) for (const group of groups) {
1119
- if (group.kind === "replace") {
1120
- const start = this.ops.length;
1121
- const removals = plain.get(group);
1122
- if (removals) this.writePlain(group, removals);
1123
- else this.recordGroup(group);
1124
- this.followJoin(group, start);
1125
- continue;
1126
- }
1127
- if (group.data) this.recordProperties(group.before, group.data, group.plainAt);
1128
- this.pieces.push({
1129
- afterFrom: group.after,
1130
- afterTo: group.after + group.length,
1131
- beforeFrom: group.before,
1132
- kind: "kept"
1133
- });
1134
- }
1135
- this.strikeEmptiedWrappers();
1136
- this.freshCopyKeys();
1137
- const recorded = RootChange.create(this.index, this.sections());
1138
- return {
1139
- change: recorded,
1140
- copies: this.copies.map(({ at, from, offset, to }) => ({
1141
- at: getDefined(recorded.mapPos(at, -1)) + offset,
1142
- from,
1143
- to
1144
- })),
1145
- leftward: this.pieces.findLast((piece) => piece.kind === "removed")?.leftward ?? this.options.leftward,
1146
- mapPosition: (position, assoc, caret) => this.mapPosition(recorded, position, assoc, caret === true, caret === false),
1147
- writtenPlain: groups.every((group) => group.kind === "replace" ? plain.has(group) : !group.data)
1148
- };
1149
- }
1150
- /**
1151
- * The ranges an Editing write removes outright when accepting the claims it
1152
- * would record for this group gives, under every outcome of the pending
1153
- * changes, the plain group or the plain group with the blocks other changes
1154
- * strike left in place. Null when it gives neither.
1155
- */
1156
- plainRemovals(group) {
1157
- if (this.settlesPlain(group)) return group.removed > 0 ? [[group.before, group.before + group.removed]] : [];
1158
- return this.removalKeepingStruck(group);
1159
- }
1160
- /**
1161
- * A removal of whole siblings whose every sibling either goes in every
1162
- * outcome or is struck by other changes, which still decide it. A table or
1163
- * row goes with every pending change inside it. A pending join goes only
1164
- * with the whole root, so no follower outside the removal loses its join.
1165
- */
1166
- removalKeepingStruck({ before, plainFrom, plainRemoved, removed, slice }) {
1167
- const { changeId, frameIndex, holdsGridParts, moveRole, origin } = this.options;
1168
- const to = before + removed;
1169
- const parentOf = (index, from, end) => {
1170
- const first = index.childBoundaryAt(from);
1171
- const last = index.childBoundaryAt(end);
1172
- return first && last && jsonEqual(first.parentPath, last.parentPath) ? {
1173
- first: first.index,
1174
- last: last.index,
1175
- path: first.parentPath
1176
- } : null;
1177
- };
1178
- const siblings = parentOf(this.index, before, to);
1179
- if (!isEditingChange(changeId) || moveRole !== null || origin === "move" || origin === "wrap" || origin === "unwrap" || removed === 0 || !siblings || frameIndex && parentOf(frameIndex, plainFrom, plainFrom + plainRemoved)?.path.length !== siblings.path.length || slice.tokens.some(reviewed)) return null;
1180
- const whole = before === 0 && to === this.index.length;
1181
- const goes = (node) => holdsGridParts(node) ? !readMembers(node).some(othersDelete) : readMembers(node).every((member) => member.kind === "insert" || member.kind === "in" || member.kind === "as" || whole && member.kind === "join") && (node.children ?? []).every(goes);
1182
- const onlyGridPartsGo = siblings.path.length > 0;
1183
- const removals = [];
1184
- for (let rank = siblings.first; rank < siblings.last; rank += 1) {
1185
- const path = [...siblings.path, rank];
1186
- const node = this.index.node(path);
1187
- const { from, to: end } = this.index.nodeRange(path);
1188
- if (holdsGridParts(node)) {
1189
- if (readMembers(node).some(othersDelete)) continue;
1190
- } else if (onlyGridPartsGo) return null;
1191
- else if (struckWhole(node)) continue;
1192
- else if (!goes(node)) return null;
1193
- const previous = removals.at(-1);
1194
- if (previous?.[1] === from) removals[removals.length - 1] = [previous[0], end];
1195
- else removals.push([from, end]);
1196
- }
1197
- return removals;
1198
- }
1199
- /**
1200
- * Whether accepting the claims an Editing write would record for this group
1201
- * gives the plain group under every outcome of the pending changes.
1202
- */
1203
- settlesPlain({ before, plainFrom, plainRemoved, removed, slice }) {
1204
- const { changeId, frameIndex, moveRole, origin } = this.options;
1205
- if (!isEditingChange(changeId) || moveRole !== null || origin === "move" || origin === "wrap" || origin === "unwrap" || removed !== plainRemoved || removed === 0 && this.followedAt(before, plainFrom) !== null) return false;
1206
- const to = before + removed;
1207
- if (frameIndex && !(jsonEqual(bareContextAt(this.index, before), bareContextAt(frameIndex, plainFrom)) && jsonEqual(bareContextAt(this.index, to), bareContextAt(frameIndex, plainFrom + plainRemoved)))) return false;
1208
- if (slice.tokens.some(reviewed) || this.index.slice(before, to).tokens.some(reviewed)) return false;
1209
- let depth = 0;
1210
- let closes = 0;
1211
- for (const token of slice.tokens) {
1212
- if (token.kind === "text" || token.nodeKind !== "element") continue;
1213
- if (token.kind === "open") depth += 1;
1214
- else if (depth > 0) depth -= 1;
1215
- else closes += 1;
1216
- }
1217
- const atBefore = this.contextAt(before);
1218
- const elements = atBefore.filter((context) => context.kind === "element");
1219
- const split = new Set(closes > 0 ? elements.slice(-closes) : []);
1220
- return (to === before ? atBefore : [...atBefore, ...this.contextAt(to)]).every((context) => {
1221
- const members = readMembers(context.props);
1222
- if (context.kind === "text") return members.length === 0;
1223
- if (split.has(context) || context.contentFrom > before || context.contentTo < to) return members.length === 0 && !this.index.slice(context.contentFrom, context.contentTo).tokens.some(reviewed);
1224
- return members.every((member) => BOUNDARY_KINDS.has(member.kind));
1225
- });
1226
- }
1227
- writePlain({ after, before, removed, slice }, removals) {
1228
- const to = before + removed;
1229
- const last = removals.at(-1);
1230
- const at = last?.[1] === to ? last[0] : to;
1231
- for (const [from, end] of removals) this.ops.push({
1232
- from,
1233
- kind: "remove",
1234
- to: end
1235
- });
1236
- if (slice.length > 0) {
1237
- this.ops.push({
1238
- at,
1239
- kind: "insert",
1240
- tokens: slice.tokens
1241
- });
1242
- this.pieces.push({
1243
- afterFrom: after,
1244
- afterTo: after + slice.length,
1245
- at,
1246
- kind: "inserted",
1247
- offsets: Array.from({ length: slice.length + 1 }, (_, offset) => offset)
1248
- });
1249
- }
1250
- if (removed > 0) this.pushRemoved(after, before, to);
1251
- }
1252
- recordGroup(group) {
1253
- const { after, before, removed, slice } = group;
1254
- const edge = this.enclosureEdgeOf(group);
1255
- if (edge) {
1256
- this.recordEnclosureEdge(group, edge);
1257
- return;
1258
- }
1259
- const enclosure = this.enclosureOf(group);
1260
- if (enclosure) {
1261
- this.recordEnclosure(group, enclosure);
1262
- return;
1263
- }
1264
- if (slice.length === 0 && group.plainRemoved === 2 && this.recordBoundaryRemoval(group)) return;
1265
- if (this.options.origin === "split" && removed === 0 && slice.length === 2 && this.recordContainerSplit(group)) return;
1266
- this.recordReplacement(before, before + removed, slice, after);
1267
- }
1268
- enclosureEdgeOf(group) {
1269
- const { origin } = this.options;
1270
- const { before, removed, slice } = group;
1271
- if (origin !== "wrap" && origin !== "unwrap") return null;
1272
- const wraps = origin === "wrap";
1273
- const tokens = wraps ? group.plainRemoved === 0 ? slice.tokens : [] : slice.length === 0 ? this.index.slice(before, before + removed).tokens : [];
1274
- const all = (kind) => tokens.length > 0 && tokens.every((token) => token.kind === kind && token.nodeKind === "element");
1275
- if (all("open")) return {
1276
- lead: true,
1277
- wraps
1278
- };
1279
- if (all("close")) return {
1280
- lead: false,
1281
- wraps
1282
- };
1283
- return null;
1284
- }
1285
- recordEnclosureEdge(group, { lead, wraps }) {
1286
- const { after, before, removed, slice } = group;
1287
- if (wraps) {
1288
- const at = lead ? before : before + removed;
1289
- this.recordReplacement(at, at, slice, after, lead ? {} : { closesWrap: true });
1290
- return;
1291
- }
1292
- if (lead) {
1293
- const { isOwn } = this.options;
1294
- this.withdrawsWrap = this.index.slice(before, before + removed).tokens.every((token) => {
1295
- const marks = token.kind === "open" ? this.marks(token.props) : [];
1296
- return marks.length > 0 && marks.every((mark) => mark.kind === "wrap" && isOwn(mark));
1297
- });
1298
- }
1299
- if (this.withdrawsWrap) {
1300
- this.ops.push({
1301
- from: before,
1302
- kind: "remove",
1303
- to: before + removed
1304
- });
1305
- this.pushRemoved(after, before, before + removed);
1306
- return;
1307
- }
1308
- this.recordReplacement(before, before + removed, PreparedTokenSlice.empty, after);
1309
- }
1310
- enclosureOf(group) {
1311
- const { removed, slice } = group;
1312
- if (removed === 0 || slice.length === 0) return null;
1313
- return enclosureOf(this.index.slice(group.before, group.before + removed), slice);
1314
- }
1315
- recordEnclosure(group, { depth, wraps }) {
1316
- const { after, before, removed, slice } = group;
1317
- if (wraps) {
1318
- const lead = slice.slice(0, depth);
1319
- const trail = slice.slice(slice.length - depth);
1320
- const inner = slice.length - 2 * depth;
1321
- this.recordReplacement(before, before, lead, after);
1322
- this.pieces.push({
1323
- afterFrom: after + depth,
1324
- afterTo: after + depth + inner,
1325
- kind: "shifted",
1326
- plainFrom: group.plainFrom
1327
- });
1328
- this.recordReplacement(before + removed, before + removed, trail, after + depth + inner, { closesWrap: true });
1329
- return;
1330
- }
1331
- const { isOwn } = this.options;
1332
- if (this.index.slice(before, before + depth).tokens.every((token) => {
1333
- const marks = token.kind === "open" ? this.marks(token.props) : [];
1334
- return marks.length > 0 && marks.every((mark) => mark.kind === "wrap" && isOwn(mark));
1335
- })) {
1336
- const close = before + removed - depth;
1337
- this.ops.push({
1338
- from: before,
1339
- kind: "remove",
1340
- to: before + depth
1341
- });
1342
- this.pushRemoved(after, before, before + depth);
1343
- this.pieces.push({
1344
- afterFrom: after,
1345
- afterTo: after + slice.length,
1346
- kind: "shifted",
1347
- plainFrom: group.plainFrom + depth
1348
- });
1349
- this.ops.push({
1350
- from: close,
1351
- kind: "remove",
1352
- to: before + removed
1353
- });
1354
- this.pushRemoved(after + slice.length, close, before + removed);
1355
- return;
1356
- }
1357
- this.recordReplacement(before, before + depth, PreparedTokenSlice.empty, after);
1358
- this.pieces.push({
1359
- afterFrom: after,
1360
- afterTo: after + slice.length,
1361
- kind: "shifted",
1362
- plainFrom: group.plainFrom + depth
1363
- });
1364
- this.recordReplacement(before + removed - depth, before + removed, PreparedTokenSlice.empty, after + slice.length);
1365
- }
1366
- /**
1367
- * A step that removes one boundary: a leaf merge, which keeps the review
1368
- * leaves apart when their properties differ and is dropped when the review
1369
- * draft holds other content between them; or, in Suggesting, a container
1370
- * merge or a merge into a struck line, which records as a move of the right
1371
- * block's children.
1372
- */
1373
- recordBoundaryRemoval(group) {
1374
- const { after, before, removed } = group;
1375
- const [first] = this.index.slice(before, before + 1).tokens;
1376
- const [last] = this.index.slice(before + removed - 1, before + removed).tokens;
1377
- if (first?.kind !== "close" || last?.kind !== "open") return false;
1378
- if (first.nodeKind === "text" && last.nodeKind === "text") {
1379
- if (removed === 2) {
1380
- const left = this.index.openContextAt(before).find((entry) => entry.kind === "text" && entry.contentTo === before);
1381
- const leftProps = left ? propsOf(this.index.node(left.path)) : {};
1382
- const rightProps = this.propsStartingAt(before + 1);
1383
- const merged = this.formattedProps(rightProps, withMembers(leftProps, readMembers(rightProps))) ?? rightProps;
1384
- if (this.sameReview(merged, leftProps)) {
1385
- this.ops.push({
1386
- from: before,
1387
- kind: "remove",
1388
- to: before + 2
1389
- });
1390
- return true;
1391
- }
1392
- if (merged !== rightProps) this.ops.push({
1393
- at: before + 1,
1394
- kind: "props",
1395
- props: merged
1396
- });
1397
- } else if (this.options.origin !== "merge") return false;
1398
- this.pushRemoved(after, before, before + removed);
1399
- return true;
1400
- }
1401
- if (first.nodeKind !== "element") return false;
1402
- const right = this.index.nodeStartingAt(before + removed - 1);
1403
- if (!right || isTextBlock(this.index.node(right.path)) && !this.mergesIntoStruckLine(group)) return false;
1404
- const children = this.index.slice(right.contentFrom, right.contentTo);
1405
- this.ops.push({
1406
- at: before,
1407
- kind: "insert",
1408
- moved: true,
1409
- tokens: this.recordCopy(right.contentFrom, right.contentTo, before)
1410
- });
1411
- this.strike(right.from, right.to, this.contextAt(right.from), "move");
1412
- this.pieces.push({
1413
- afterFrom: after,
1414
- afterTo: after + children.length,
1415
- at: before,
1416
- kind: "inserted",
1417
- offsets: Array.from({ length: children.length + 1 }, (_, i) => i)
1418
- });
1419
- this.pushRemoved(after, before, right.contentFrom);
1420
- return true;
1421
- }
1422
- /**
1423
- * Whether a block merge starts inside a line a pending deletion strikes,
1424
- * where the write removed text at the line's end that the review draft keeps
1425
- * struck. The merged line then stands where the struck one does, after the
1426
- * line break before it, as Editing's merge leaves it. A join mark cannot say
1427
- * so: a decision lands it on the nearest block it keeps, and accepting the
1428
- * deletion takes the struck line away. A merge that removes only the
1429
- * boundary, such as Backspace at the start of the right block, joins the
1430
- * line before it.
1431
- */
1432
- mergesIntoStruckLine(group) {
1433
- const { before, plainFrom } = group;
1434
- const left = this.index.openContextAt(before).find((entry) => entry.kind === "element" && entry.contentTo === before);
1435
- if (!left || !this.hasMarkKind(propsOf(this.index.node(left.path)), "delete")) return false;
1436
- const textEnd = this.options.plainToReview(plainFrom - 1, -1);
1437
- return this.index.slice(textEnd, before).tokens.some((token) => token.kind === "text");
1438
- }
1439
- /**
1440
- * A container split in Suggesting records as a new container holding a
1441
- * moved copy of the children after the split point.
1442
- */
1443
- recordContainerSplit(group) {
1444
- const { after, before, slice } = group;
1445
- const [close, open] = slice.tokens;
1446
- if (close?.kind !== "close" || close.nodeKind !== "element" || open?.kind !== "open" || open.nodeKind !== "element") return false;
1447
- const container = this.contextAt(before).at(-1);
1448
- if (container?.kind !== "element" || open.props.type !== container.props.type) return false;
1449
- const entry = this.index.nodeRange(container.path);
1450
- if (isTextBlock(this.index.node(container.path))) return false;
1451
- const children = this.index.slice(before, container.contentTo);
1452
- this.strike(before, container.contentTo, this.contextAt(before), "move");
1453
- this.ops.push({
1454
- at: entry.to,
1455
- kind: "insert",
1456
- moved: true,
1457
- tokens: [
1458
- openToken("element", this.withMarks(open.props, [...this.marks(open.props), this.options.markOf("insert")])),
1459
- ...this.recordCopy(before, container.contentTo, entry.to, 1),
1460
- closeToken("element")
1461
- ]
1462
- });
1463
- this.pieces.push({
1464
- afterFrom: after + 1,
1465
- afterTo: after + 3 + children.length,
1466
- at: entry.to,
1467
- kind: "inserted",
1468
- offsets: Array.from({ length: children.length + 3 }, (_, i) => i)
1469
- });
1470
- this.pieces.push({
1471
- afterFrom: after,
1472
- afterTo: after,
1473
- beforeFrom: before,
1474
- kind: "kept"
1475
- });
1476
- return true;
1477
- }
1478
- /**
1479
- * A builder move: the source keeps its place under the mover's deletion in
1480
- * Suggesting, and the landing gets the source as the review draft holds it,
1481
- * with its marks, under the mover's insertion.
1482
- */
1483
- recordNodeMove(groups) {
1484
- const replacements = groups.filter((group) => group.kind === "replace");
1485
- const source = replacements.find((group) => group.removed > 0 && group.slice.length === 0);
1486
- const landing = replacements.find((group) => group.removed === 0 && group.slice.length > 0);
1487
- if (replacements.length !== 2 || !source || !landing) return false;
1488
- const { plainToReview } = this.options;
1489
- const [copyFrom, copyTo] = this.withoutStruckEdges(source.before, source.before + source.removed);
1490
- for (const group of groups) if (group.kind === "kept") this.pieces.push({
1491
- afterFrom: group.after,
1492
- afterTo: group.after + group.length,
1493
- beforeFrom: group.before,
1494
- kind: "kept"
1495
- });
1496
- else if (group === source) {
1497
- this.strike(copyFrom, copyTo, this.contextAt(copyFrom), "move");
1498
- this.pushRemoved(source.after, copyFrom, copyTo);
1499
- } else {
1500
- this.ops.push({
1501
- at: landing.before,
1502
- kind: "insert",
1503
- moved: true,
1504
- tokens: this.recordCopy(copyFrom, copyTo, landing.before)
1505
- });
1506
- this.followJoin(landing, this.ops.length - 1);
1507
- this.pieces.push({
1508
- afterFrom: landing.after,
1509
- afterTo: landing.after + landing.slice.length,
1510
- at: landing.before,
1511
- kind: "inserted",
1512
- offsets: Array.from({ length: landing.slice.length + 1 }, (_, offset) => offset === 0 ? 0 : plainToReview(source.plainFrom + offset, -1, false) - copyFrom)
1513
- });
1514
- }
1515
- return true;
1516
- }
1517
- /**
1518
- * The pending join a block written at `at`, which is `frameAt` in the
1519
- * frame, goes with: the one the block before it carries or goes with, when
1520
- * the frame's block before it ends there too or, outside a frame, when the
1521
- * block after it goes with a join of that suggestion too; or else the one
1522
- * the line after it carries, past only the ends of elements, which would
1523
- * otherwise merge into it. `previous` is the block an insert wrote just
1524
- * before this one, which then stands before it.
1525
- */
1526
- followedAt(at, frameAt, previous) {
1527
- const boundary = this.index.childBoundaryAt(at);
1528
- if (!boundary) return null;
1529
- let { index, parentPath } = boundary;
1530
- const before = previous ?? (index > 0 ? propsOf(getDefined(this.childAt(parentPath, index - 1))) : void 0);
1531
- const carried = before && this.followedBy(before);
1532
- const after = this.childAt(parentPath, index);
1533
- if (carried && (this.options.frameIndex ? previous !== void 0 || frameAt > 0 && this.options.plainToReview(frameAt - 1, -1, false) === at - 1 : after !== void 0 && this.marks(propsOf(after)).some((mark) => {
1534
- const link = followsOf(mark);
1535
- return link !== void 0 && incarnationOfLink(link) === incarnationOfLink(carried);
1536
- }))) return carried;
1537
- while (index === this.childCountAt(parentPath) && parentPath.length > 0) {
1538
- index = getDefined(parentPath.at(-1)) + 1;
1539
- parentPath = parentPath.slice(0, -1);
1540
- }
1541
- const next = this.childAt(parentPath, index);
1542
- const join = next && isTextBlock(next) ? this.marks(propsOf(next)).find(this.isLiveJoin) : void 0;
1543
- return join ? linkOf(join) : null;
1544
- }
1545
- childCountAt(path) {
1546
- return path.length === 0 ? this.index.size : this.index.node(path).children?.length ?? 0;
1547
- }
1548
- childAt(path, index) {
1549
- return path.length === 0 ? this.index.child(index) : this.index.node(path).children?.[index];
1550
- }
1551
- /**
1552
- * Has the blocks a group inserts go with the pending join they are written
1553
- * after or before, so the join lands where the frame shows them. Each block
1554
- * is linked as if it were inserted alone, after the blocks before it, whose
1555
- * copied joins already hold fresh keys. A block and its children cannot be
1556
- * inserted apart, so a link to a join the insert copies inside the block
1557
- * moves to the first such copy, which the original's removal cannot strand.
1558
- */
1559
- followJoin(group, start) {
1560
- if (group.removed > 0) return;
1561
- const mark = this.options.markOf("insert");
1562
- const own = incarnationOf(mark);
1563
- let previous;
1564
- for (let index = start; index < this.ops.length; index += 1) {
1565
- const op = getDefined(this.ops[index]);
1566
- if (op.kind !== "insert" || op.at !== group.before) continue;
1567
- let depth = 0;
1568
- const copied = isEditingMoveCopy(op, mark.change) ? {
1569
- links: NO_COPIES,
1570
- tokens: op.tokens
1571
- } : this.withCopyMarks(op.tokens);
1572
- const tokens = copied.tokens.map((token, at) => {
1573
- if (token.kind === "text") return token;
1574
- if (token.kind === "close") {
1575
- depth -= 1;
1576
- return token;
1577
- }
1578
- depth += 1;
1579
- if (depth !== 1 || token.nodeKind !== "element") return token;
1580
- const linkedTo = (link) => link === null ? token.props : this.withMarks(token.props, this.marks(token.props).map((each) => each.kind === "insert" && incarnationOf(each) === own ? {
1581
- ...each,
1582
- follows: link
1583
- } : each));
1584
- const alone = this.followedAt(group.before, group.plainFrom, previous);
1585
- const end = closeIndexOf(copied.tokens, at);
1586
- const moved = alone === null ? void 0 : copied.links.get(alone)?.find((copy) => copy.at > at && copy.at < end)?.link;
1587
- const props = linkedTo(moved ?? alone);
1588
- previous = moved === void 0 ? props : linkedTo(alone);
1589
- return props === token.props ? token : openToken("element", props);
1590
- });
1591
- const linked = {
1592
- ...op,
1593
- tokens
1594
- };
1595
- this.ops[index] = linked;
1596
- this.freshened.add(linked);
1597
- }
1598
- }
1599
- withoutStruckEdges(from, to) {
1600
- const { offsets, tokens } = this.index.slice(from, to);
1601
- const hidden = ([open, end]) => {
1602
- const first = tokens[open];
1603
- let live = false;
1604
- if (first.kind !== "open" || !this.hasMarkKind(first.props, "delete")) return false;
1605
- for (let index = open; index < end; index += 1) {
1606
- const token = tokens[index];
1607
- if (token.kind === "open" && token.nodeKind === "text") live = !this.hasMarkKind(token.props, "delete");
1608
- else if (token.kind === "text" && live) return false;
1609
- }
1610
- return true;
1611
- };
1612
- const opens = [];
1613
- const nodes = [];
1614
- tokens.forEach((token, index) => {
1615
- if (token.kind === "open") opens.push(index);
1616
- else if (token.kind === "close") {
1617
- const open = opens.pop();
1618
- if (open !== void 0 && opens.length === 0) nodes.push([open, index + 1]);
1619
- }
1620
- });
1621
- let start = 0;
1622
- let end = tokens.length;
1623
- let first = 0;
1624
- let last = nodes.length;
1625
- while (first < last && nodes[first][0] === start && hidden(nodes[first])) {
1626
- start = nodes[first][1];
1627
- first += 1;
1628
- }
1629
- while (last > first && nodes[last - 1][1] === end && hidden(nodes[last - 1])) {
1630
- end = nodes[last - 1][0];
1631
- last -= 1;
1632
- }
1633
- const at = (index) => index < tokens.length ? from + offsets[index] : to;
1634
- return start < end ? [at(start), at(end)] : [from, to];
1635
- }
1636
- /**
1637
- * The content at `[from, to)` under the writer's insertion, recorded as a
1638
- * moved copy that an insert at `at` lands `offset` tokens into.
1639
- */
1640
- recordCopy(from, to, at, offset = 0) {
1641
- const mark = this.options.markOf("insert");
1642
- const { tokens } = this.index.slice(from, to);
1643
- const copied = new Set(tokens.flatMap((token) => token.kind === "open" ? this.marks(token.props).flatMap((each) => each.kind === "join" || each.kind === "joined" ? [linkOf(each)] : []) : []));
1644
- this.copies.push({
1645
- at,
1646
- from,
1647
- offset,
1648
- to
1649
- });
1650
- const editingCopyKeepsLinks = isEditingChange(mark.change);
1651
- return tokens.map((token) => token.kind === "open" ? openToken(token.nodeKind, this.withMarks(withoutSpares(token.props), [...this.withoutCuts(token.props).map((each) => editingCopyKeepsLinks ? each : withoutLinkOutsideCopy(each, copied)), mark])) : token);
1652
- }
1653
- pushRemoved(after, from, to) {
1654
- this.pieces.push({
1655
- after,
1656
- beforeFrom: from,
1657
- beforeTo: to,
1658
- kind: "removed",
1659
- leftward: this.options.selectionBefore === null ? this.options.leftward : this.options.selectionBefore > from
1660
- });
1661
- }
1662
- contextAt(position) {
1663
- return this.index.openContextAt(position).filter((entry) => entry.contentFrom <= position && position <= entry.contentTo).map((entry) => ({
1664
- contentFrom: entry.contentFrom,
1665
- contentTo: entry.contentTo,
1666
- kind: entry.kind,
1667
- path: entry.path,
1668
- props: propsOf(this.index.node(entry.path))
1669
- }));
1670
- }
1671
- frameJoins() {
1672
- if (this.joinIndex) return this.joinIndex;
1673
- const followed = /* @__PURE__ */ new Set();
1674
- const holders = /* @__PURE__ */ new Map();
1675
- const visit = (node) => {
1676
- if (typeof node.text === "string") return;
1677
- for (const mark of readAuthoredMarks(node)) {
1678
- const link = followsOf(mark);
1679
- if (link !== void 0) followed.add(link);
1680
- if (isKeyedJoin(mark)) holders.set(mark.key, (holders.get(mark.key) ?? 0) + 1);
1681
- }
1682
- if (!isTextBlock(node)) node.children?.forEach(visit);
1683
- };
1684
- this.index.nodes.forEach(visit);
1685
- this.joinIndex = {
1686
- followed,
1687
- holders
1688
- };
1689
- return this.joinIndex;
1690
- }
1691
- propsStartingAt(position) {
1692
- const entry = this.index.nodeStartingAt(position);
1693
- return entry ? propsOf(this.index.node(entry.path)) : {};
1694
- }
1695
- recordProperties(at, modifications, frameAt = null) {
1696
- const previous = this.propsStartingAt(at);
1697
- let next = applyPropertyModifications(previous, modifications.filter((modification) => modification.key !== AUTHORED_MARKS_KEY));
1698
- const entry = this.index.nodeStartingAt(at);
1699
- if (entry && this.index.node(entry.path).text === "") {
1700
- const parents = entry.path.slice(1).map((_, depth) => propsOf(this.index.node(entry.path.slice(0, depth + 1)))).reverse();
1701
- const dropped = Object.keys({
1702
- ...previous,
1703
- ...next
1704
- }).filter((key) => !jsonEqual(previous[key], next[key]) && !this.options.emptyTextKeeps(key, next[key] ?? previous[key], parents));
1705
- next = Object.fromEntries([...Object.entries(next).filter(([key]) => !dropped.includes(key)), ...dropped.filter((key) => Object.hasOwn(previous, key)).map((key) => [key, previous[key]])]);
1706
- }
1707
- const props = this.formattedProps(previous, next);
1708
- this.propsWrittenAtStart.set(at, next);
1709
- if (props) this.ops.push({
1710
- at,
1711
- kind: "props",
1712
- props
1713
- });
1714
- const frameText = frameAt === null ? void 0 : this.options.frameIndex?.nodeStartingAt(frameAt);
1715
- if (frameText?.kind === "text" && entry?.kind === "text") this.spreadProperties(entry, previous, modifications, this.options.plainToReview(frameText.to, -1));
1716
- }
1717
- /**
1718
- * The frame's document merges a text piece with the later pieces that only
1719
- * crossed-out content separates from it when their properties match, so a
1720
- * property change on the merged text reaches each of them.
1721
- */
1722
- spreadProperties(entry, previous, modifications, end) {
1723
- const ordinary = (props) => withMembers(props, []);
1724
- const parent = entry.path.slice(0, -1);
1725
- for (let next = this.index.nodeStartingAt(entry.to); next?.kind === "text" && next.from < end && next.path.length === entry.path.length && jsonEqual(next.path.slice(0, -1), parent); next = this.index.nodeStartingAt(next.to)) {
1726
- const props = propsOf(this.index.node(next.path));
1727
- if (this.hasMarkKind(props, "delete")) continue;
1728
- if (!jsonEqual(ordinary(props), ordinary(previous))) return;
1729
- this.recordProperties(next.from, modifications);
1730
- }
1731
- }
1732
- /**
1733
- * The properties a node takes when an edit changes keys other than the
1734
- * review marks from `previous` to `next`, or `null` to keep `previous`.
1735
- */
1736
- formattedProps(previous, next) {
1737
- const keys = [.../* @__PURE__ */ new Set([...Object.keys(previous), ...Object.keys(next)])].filter((key) => key !== "authored" && !jsonEqual(previous[key], next[key]));
1738
- if (keys.length === 0) return null;
1739
- const { unique } = this.options;
1740
- const formatted = unique ? keys.filter((key) => !unique.has(key)) : keys;
1741
- const marks = this.marks(previous);
1742
- if (formatted.length === 0 || marks.some((mark) => mark.kind === "delete")) {
1743
- if (formatted.length === keys.length) return null;
1744
- const inPlace = { ...previous };
1745
- const retyped = previous.type !== next.type;
1746
- const typeHolds = (props, key) => typeof props.type === "string" && this.options.holdsUnique(props.type, key);
1747
- for (const key of keys) {
1748
- if (!unique?.has(key)) continue;
1749
- if (Object.hasOwn(next, key)) {
1750
- if (!retyped || typeHolds(previous, key)) inPlace[key] = next[key];
1751
- } else if (!retyped || typeHolds(next, key)) delete inPlace[key];
1752
- }
1753
- return this.withMarks(inPlace, marks);
1754
- }
1755
- const { isOwn, markOf, source, standing, commitWriteId } = this.options;
1756
- const { at, author, change, inc } = markOf("insert");
1757
- const innermost = innermostInsert(marks);
1758
- const tags = recordFormats({
1759
- keys: formatted,
1760
- next,
1761
- ownInsertion: innermost !== void 0 && isOwn(innermost),
1762
- previous,
1763
- source,
1764
- standing,
1765
- tags: marks.filter((mark) => mark.kind === "format"),
1766
- writer: {
1767
- at,
1768
- author,
1769
- change,
1770
- ...inc === void 0 ? {} : { inc },
1771
- isOwn,
1772
- commitWriteId
1773
- }
1774
- });
1775
- return this.withMarks(next, [...marks.filter((mark) => mark.kind !== "format"), ...tags]);
1776
- }
1777
- recordReplacement(from, to, inserted, after, { closesWrap = false } = {}) {
1778
- const startContext = this.contextAt(from);
1779
- const landing = this.options.moveRole === "landing";
1780
- const reinserted = new Set(inserted.tokens.flatMap((token) => token.kind === "open" ? this.marks(token.props).filter((mark) => mark.kind === "delete").map(incarnationOf) : []));
1781
- const struck = this.strike(from, to, startContext, this.options.moveRole === "source" ? "move" : "delete", reinserted);
1782
- if (this.options.framed && inserted.length === 0) this.keepEmptiedLine(from, to, startContext);
1783
- this.recordInsertion({
1784
- after,
1785
- at: to,
1786
- closesWrap,
1787
- contexts: struck.contexts,
1788
- inserted,
1789
- landing,
1790
- openLeaf: struck.openLeaf,
1791
- reopen: struck.reopen,
1792
- removedFrom: from,
1793
- startContexts: startContext
1794
- });
1795
- }
1796
- /**
1797
- * A line another author's pending deletion strikes stands in the frame only
1798
- * through its live content. When a removal inside it takes the last of that
1799
- * content, the frame still holds the emptied line, so an empty line with its
1800
- * properties follows it. A suggested one stood only while the line's
1801
- * deletions and the removed content's insertions did, so it rests on both.
1802
- */
1803
- keepEmptiedLine(from, to, contexts) {
1804
- const line = contexts.findLast((context) => context.kind === "element");
1805
- if (!line || to > line.contentTo || !isTextBlock(this.index.node(line.path)) || !this.hasMarkKind(line.props, "delete") || !this.holdsLiveContent(line, [{
1806
- from,
1807
- to: from
1808
- }]) || this.holdsLiveContent(line, [{
1809
- from,
1810
- to
1811
- }])) return;
1812
- const { isOwn, markOf } = this.options;
1813
- const lineMarks = this.marks(line.props);
1814
- const resting = [...lineMarks.flatMap((mark) => mark.kind === "delete" ? [asInsertion(mark)] : mark.kind === "insert" ? [mark] : []), ...this.removedLiveContent(line, from, to).flatMap((props) => this.marks(props).filter((mark) => mark.kind === "insert"))].filter((mark) => !isOwn(mark));
1815
- const node = this.options.dependencies.throughout({
1816
- ...this.withMarks(line.props, lineMarks.filter((mark) => mark.kind === "format"), true),
1817
- children: [{
1818
- ...this.withMarks(leafOf(contexts) ?? {}, [], true),
1819
- text: ""
1820
- }]
1821
- }, [...resting, markOf("insert")]);
1822
- this.ops.push({
1823
- at: line.contentTo + 1,
1824
- kind: "insert",
1825
- tokens: encodeNodes([node]).slice.tokens
1826
- });
1827
- }
1828
- /**
1829
- * A wrapper a pending unwrap dissolves never stands in the frame. When the
1830
- * frame's removals take the last of its live content and the step lands no
1831
- * live node inside it, the frame holds nothing in its place, so the wrapper
1832
- * takes the writer's strike too and goes once nothing inside it survives.
1833
- */
1834
- strikeEmptiedWrappers() {
1835
- const wrappers = /* @__PURE__ */ new Map();
1836
- for (const { contexts } of this.framedStrikes) for (const context of contexts) if (context.kind === "element" && this.hasMarkKind(context.props, "unwrap") && !this.marks(context.props).some((mark) => mark.kind === "delete" && mark.change === this.options.changeId)) wrappers.set(context.contentFrom, context);
1837
- if (wrappers.size === 0) return;
1838
- const removed = [...this.framedStrikes];
1839
- const liveLandings = this.ops.flatMap((op) => op.kind === "insert" && op.tokens.some((token) => token.kind === "open" && !this.hasMarkKind(token.props, "delete")) ? [op.at] : []);
1840
- for (const wrapper of [...wrappers.values()].sort((left, right) => right.path.length - left.path.length)) {
1841
- if (liveLandings.some((at) => at >= wrapper.contentFrom && at <= wrapper.contentTo) || this.holdsLiveContent(wrapper, removed)) continue;
1842
- this.ops.push({
1843
- at: wrapper.contentFrom - 1,
1844
- kind: "props",
1845
- props: this.withMarks(wrapper.props, [...this.marks(wrapper.props), this.options.markOf("delete")])
1846
- });
1847
- removed.push({
1848
- from: wrapper.contentFrom - 1,
1849
- to: wrapper.contentTo + 1
1850
- });
1851
- }
1852
- }
1853
- holdsLiveContent(element, removed) {
1854
- const gone = (from, to) => removed.some((span) => span.from <= from && to <= span.to);
1855
- if (!isTextBlock(this.index.node(element.path))) {
1856
- for (let from = element.contentFrom; from < element.contentTo;) {
1857
- const child = getDefined(this.index.nodeStartingAt(from));
1858
- from = child.to;
1859
- if (gone(child.from, child.to)) continue;
1860
- const live = !this.hasMarkKind(propsOf(this.index.node(child.path)), "delete");
1861
- const keepsAnEdge = !gone(child.from, child.from + 1) || !gone(child.to - 1, child.to);
1862
- if (live && keepsAnEdge) return true;
1863
- if (this.holdsLiveContent(child, removed)) return true;
1864
- }
1865
- return false;
1866
- }
1867
- const { offsets, tokens } = this.index.slice(element.contentFrom, element.contentTo);
1868
- let liveLeaf = false;
1869
- return tokens.some((token, index) => {
1870
- const at = element.contentFrom + offsets[index];
1871
- if (token.kind === "text") return liveLeaf && !gone(at, at + token.text.length);
1872
- if (token.kind !== "open") return false;
1873
- const live = !this.hasMarkKind(token.props, "delete");
1874
- if (token.nodeKind === "text") {
1875
- liveLeaf = live;
1876
- return false;
1877
- }
1878
- return live && !gone(at, at + 1);
1879
- });
1880
- }
1881
- removedLiveContent(line, from, to) {
1882
- const { offsets, tokens } = this.index.slice(line.contentFrom, line.contentTo);
1883
- const removed = [];
1884
- let leaf = null;
1885
- tokens.forEach((token, index) => {
1886
- const at = line.contentFrom + offsets[index];
1887
- if (token.kind === "open") {
1888
- const live = !this.hasMarkKind(token.props, "delete");
1889
- if (token.nodeKind === "text") leaf = live ? token.props : null;
1890
- else if (live && at >= from && at < to) removed.push(token.props);
1891
- } else if (token.kind === "text" && leaf && at < to && at + token.text.length > from && !removed.includes(leaf)) removed.push(leaf);
1892
- });
1893
- return removed;
1894
- }
1895
- /**
1896
- * Keep removed content in place under a delete mark. Each node decides by
1897
- * its own marks: one's own pending insertion is removed for real, and
1898
- * struck content stays as is. A move strikes everything it removes, over
1899
- * other deletions and one's own insertion, which a move never withdraws.
1900
- */
1901
- strike(from, to, startContext, mode, reinserted = /* @__PURE__ */ new Set()) {
1902
- const stack = [...startContext];
1903
- const opened = /* @__PURE__ */ new Set();
1904
- const removedTokens = this.index.slice(from, to);
1905
- const local = removedTokens.tokens;
1906
- const localOffsets = removedTokens.offsets;
1907
- const closeOf = matchTokens(local);
1908
- const { changeId, isOwn, markOf } = this.options;
1909
- const struck = (marks) => marks.some((mark) => mark.kind === "delete" && (mode === "delete" || mark.change === changeId) && !reinserted.has(incarnationOf(mark)));
1910
- const withdrawn = (marks) => {
1911
- const innermost = innermostInsert(marks);
1912
- return mode === "delete" && innermost !== void 0 && isOwn(innermost);
1913
- };
1914
- const withdrawnThroughout = (open, close) => {
1915
- for (let inner = open; inner < close; inner += 1) {
1916
- const token = local[inner];
1917
- if (token.kind !== "open") continue;
1918
- const marks = this.marks(this.propsStartingAt(from + localOffsets[inner]));
1919
- const spacer = inner > open && token.nodeKind === "text" && local[inner + 1]?.kind === "close" && marks.length === 0;
1920
- const ownBoundary = mode === "delete" && token.nodeKind === "element" && marks.length > 0 && marks.every((mark) => (mark.kind === "split" || mark.kind === "wrap") && isOwn(mark));
1921
- if (!spacer && !ownBoundary && !withdrawn(marks)) return false;
1922
- if (token.nodeKind === "element" && this.options.holdsWithdrawal(this.propsStartingAt(from + localOffsets[inner]))) return false;
1923
- }
1924
- return true;
1925
- };
1926
- const strikeMark = (leaf, position) => mode === "move" ? markOf("delete") : this.ownDeleteNear(leaf, position, to) ?? markOf("delete");
1927
- let openLeaf = leafOf(startContext);
1928
- let reopen = null;
1929
- let firstSplitLeaf = null;
1930
- const removedOpenByClose = /* @__PURE__ */ new Map();
1931
- const wholeElementByClose = /* @__PURE__ */ new Map();
1932
- const keptElementChildren = /* @__PURE__ */ new Map();
1933
- const deletedWhole = /* @__PURE__ */ new Set();
1934
- const ownsStruck = !isEditingChange(changeId);
1935
- const emptiedKeptElementAt = /* @__PURE__ */ new Map();
1936
- const unwrappedOpens = /* @__PURE__ */ new Set();
1937
- const survivingIndexBefore = (index) => {
1938
- let back = index - 1;
1939
- for (;;) {
1940
- const open = removedOpenByClose.get(back);
1941
- if (open !== void 0) back = open - 1;
1942
- else if (unwrappedOpens.has(back)) back -= 1;
1943
- else return back;
1944
- }
1945
- };
1946
- const boundaryMark = (previous) => {
1947
- if (this.options.origin === "unwrap" || previous?.kind !== "close" || previous.nodeKind !== "element") return markOf("unwrap");
1948
- const { at, author, change, inc } = markOf("join");
1949
- return {
1950
- at,
1951
- author,
1952
- change,
1953
- ...inc === void 0 ? {} : { inc },
1954
- key: this.options.createTagId(),
1955
- kind: "join"
1956
- };
1957
- };
1958
- for (let index = 0; index < local.length; index += 1) {
1959
- const token = local[index];
1960
- const position = from + localOffsets[index];
1961
- if (token.kind === "text") {
1962
- const leaf = stack.at(-1);
1963
- if (!leaf || leaf.kind !== "text") throw new Error("Text tokens must sit inside a text node.");
1964
- const marks = this.marks(leaf.props);
1965
- if (struck(marks)) continue;
1966
- if (withdrawn(marks)) {
1967
- this.ops.push({
1968
- from: position,
1969
- kind: "remove",
1970
- to: position + token.text.length
1971
- });
1972
- continue;
1973
- }
1974
- if (!opened.has(leaf.contentFrom) && firstSplitLeaf !== leaf) {
1975
- const struckProps = this.withMarks(leaf.props, [...marks, strikeMark(leaf, position)]);
1976
- this.ops.push({
1977
- at: position,
1978
- kind: "insert",
1979
- tokens: [closeToken("text"), openToken("text", struckProps)]
1980
- });
1981
- firstSplitLeaf = leaf;
1982
- openLeaf = struckProps;
1983
- if (leaf.contentTo > to) reopen = leaf.props;
1984
- }
1985
- continue;
1986
- }
1987
- if (token.kind === "open") {
1988
- const close = closeOf.get(index);
1989
- const props = this.propsStartingAt(position);
1990
- const entry = this.index.nodeStartingAt(position);
1991
- const context = {
1992
- contentFrom: position + 1,
1993
- contentTo: entry ? entry.contentTo : position + 1,
1994
- kind: token.nodeKind,
1995
- path: entry?.path ?? [],
1996
- props
1997
- };
1998
- const marks = this.marks(props);
1999
- const removedOutright = close !== void 0 && withdrawnThroughout(index, close);
2000
- const parent = stack.at(-1);
2001
- const parentChildren = parent && keptElementChildren.get(parent);
2002
- if (parentChildren && !removedOutright) parentChildren.survived = true;
2003
- else if (parentChildren) parentChildren.removed = true;
2004
- if (close !== void 0) {
2005
- if (removedOutright) {
2006
- this.ops.push({
2007
- from: position,
2008
- kind: "remove",
2009
- to: from + localOffsets[close] + 1
2010
- });
2011
- removedOpenByClose.set(close, index);
2012
- index = close;
2013
- continue;
2014
- }
2015
- const insideDeletedWhole = ownsStruck && mode === "delete" && stack.some((above) => deletedWhole.has(above)) && !marks.some((mark) => mark.kind === "delete" && mark.change === changeId);
2016
- const strikeOpIndex = struck(marks) && !insideDeletedWhole ? null : this.ops.length;
2017
- if (token.nodeKind === "element") wholeElementByClose.set(close, {
2018
- open: index,
2019
- props,
2020
- strikeOpIndex
2021
- });
2022
- if (strikeOpIndex !== null) this.ops.push({
2023
- at: position,
2024
- kind: "props",
2025
- props: this.withMarks(props, [...marks, markOf("delete")])
2026
- });
2027
- if (token.nodeKind === "text") index = close;
2028
- else {
2029
- stack.push(context);
2030
- if (strikeOpIndex !== null) deletedWhole.add(context);
2031
- keptElementChildren.set(context, {
2032
- removed: false,
2033
- survived: false
2034
- });
2035
- }
2036
- continue;
2037
- }
2038
- stack.push(context);
2039
- opened.add(context.contentFrom);
2040
- if (token.nodeKind === "text") {
2041
- openLeaf = props;
2042
- if (struck(marks) || withdrawn(marks)) continue;
2043
- const struckProps = this.withMarks(props, [...marks, strikeMark(context, context.contentFrom)]);
2044
- this.ops.push({
2045
- at: position,
2046
- kind: "props",
2047
- props: struckProps
2048
- });
2049
- openLeaf = struckProps;
2050
- reopen = props;
2051
- continue;
2052
- }
2053
- if (this.options.framed && marks.some((mark) => mark.kind === "unwrap")) {
2054
- unwrappedOpens.add(index);
2055
- openLeaf = null;
2056
- continue;
2057
- }
2058
- const previousIndex = survivingIndexBefore(index);
2059
- const previous = local[previousIndex];
2060
- const mergeTarget = wholeElementByClose.get(previousIndex);
2061
- if (mode === "delete" && previous?.kind === "close" && (!mergeTarget || mergeTarget.strikeOpIndex !== null || this.marks(mergeTarget.props).some((mark) => mark.kind === "delete" && mark.change === changeId)) && marks.some((mark) => (mark.kind === "split" || mark.kind === "wrap") && isOwn(mark))) {
2062
- const previousAt = from + localOffsets[previousIndex];
2063
- this.ops.push({
2064
- from: previousAt,
2065
- kind: "remove",
2066
- to: previousAt + 1
2067
- });
2068
- this.ops.push({
2069
- from: position,
2070
- kind: "remove",
2071
- to: position + 1
2072
- });
2073
- emptiedKeptElementAt.delete(previousIndex);
2074
- if (mergeTarget) {
2075
- const targetMarks = this.marks(mergeTarget.props);
2076
- const withoutOwnDelete = targetMarks.filter((mark) => !(mark.kind === "delete" && mark.change === changeId));
2077
- const boundaryInsteadOfStrike = {
2078
- at: from + localOffsets[mergeTarget.open],
2079
- kind: "props",
2080
- props: this.withMarks(mergeTarget.props, [...withoutOwnDelete, boundaryMark(local[survivingIndexBefore(mergeTarget.open)])])
2081
- };
2082
- if (mergeTarget.strikeOpIndex !== null) this.ops[mergeTarget.strikeOpIndex] = boundaryInsteadOfStrike;
2083
- else if (withoutOwnDelete.length < targetMarks.length) this.ops.push(boundaryInsteadOfStrike);
2084
- }
2085
- continue;
2086
- }
2087
- const boundary = boundaryMark(previous);
2088
- const joins = boundary.kind === "join" ? marks.filter(this.isLiveJoin) : [];
2089
- if (joins.length === 0 || this.editingMergesAcross(changeId, joins)) this.ops.push({
2090
- at: position,
2091
- kind: "props",
2092
- props: this.withMarks(props, [...marks.map((mark) => joins.includes(mark) ? joinedOf(mark) : mark), boundary])
2093
- });
2094
- openLeaf = null;
2095
- continue;
2096
- }
2097
- const closed = stack.pop();
2098
- const children = closed && keptElementChildren.get(closed);
2099
- if (closed && children?.removed && !children.survived) {
2100
- const whole = wholeElementByClose.get(index);
2101
- emptiedKeptElementAt.set(index, {
2102
- at: position,
2103
- marks: [...this.marks(closed.props).filter((mark) => mark.kind === "insert" || mark.kind === "delete"), ...whole && whole.strikeOpIndex !== null ? [markOf("delete")] : []],
2104
- site: [closed.props, ...stack.map((context) => context.props).reverse()]
2105
- });
2106
- }
2107
- if (token.nodeKind === "text") {
2108
- openLeaf = null;
2109
- reopen = null;
2110
- if (closed && firstSplitLeaf === closed) firstSplitLeaf = null;
2111
- }
2112
- }
2113
- for (const { at, marks, site } of emptiedKeptElementAt.values()) {
2114
- const children = this.options.fill(site);
2115
- if (children.length === 0) continue;
2116
- this.ops.push({
2117
- at,
2118
- kind: "insert",
2119
- tokens: encodeNodes(children.map((child) => this.options.dependencies.throughout(child, marks))).slice.tokens
2120
- });
2121
- }
2122
- if (this.options.framed && from < to) this.framedStrikes.push({
2123
- contexts: [...startContext, ...stack],
2124
- from,
2125
- to
2126
- });
2127
- return {
2128
- contexts: stack,
2129
- openLeaf,
2130
- reopen: reopen && openLeaf ? reopen : null
2131
- };
2132
- }
2133
- /**
2134
- * Insert a step's new tokens after any struck run, marking inserted content
2135
- * and restoring the leaf the document continues in. A move's landing keeps
2136
- * the moved content's marks and adds the mover's insertion to each node.
2137
- */
2138
- recordInsertion(input) {
2139
- const { at, inserted, landing } = input;
2140
- const output = [];
2141
- const outputTextOffsets = [];
2142
- const local = inserted.tokens;
2143
- const closeOf = matchTokens(local);
2144
- const stack = [...input.contexts];
2145
- const baseLeaf = input.reopen ?? leafOf(input.contexts);
2146
- let outLeaf = input.openLeaf;
2147
- let outLength = 0;
2148
- const emit = (token) => {
2149
- output.push(token);
2150
- outLength += token.kind === "text" ? token.text.length : 1;
2151
- };
2152
- const closeLeaf = () => {
2153
- if (outLeaf === null) return;
2154
- emit(closeToken("text"));
2155
- outLeaf = null;
2156
- };
2157
- const ensureLeaf = (props) => {
2158
- if (outLeaf !== null && jsonEqual(outLeaf, props)) return;
2159
- closeLeaf();
2160
- emit(openToken("text", props));
2161
- outLeaf = props;
2162
- };
2163
- const ownElement = () => {
2164
- for (const context of [...stack].reverse()) {
2165
- if (context.kind !== "element") continue;
2166
- const insertion = innermostInsert(this.marks(context.props).filter((mark) => !isEditingChange(mark.change)));
2167
- if (!insertion) continue;
2168
- if (!this.options.isOwn(insertion)) return null;
2169
- const { type } = context.props;
2170
- return {
2171
- mark: {
2172
- at: insertion.at,
2173
- author: insertion.author,
2174
- change: insertion.change,
2175
- ...insertion.inc === void 0 ? {} : { inc: insertion.inc },
2176
- kind: "insert"
2177
- },
2178
- oneText: typeof type === "string" && this.options.oneText(type)
2179
- };
2180
- }
2181
- return null;
2182
- };
2183
- const insertedMarks = () => {
2184
- const own = ownElement();
2185
- return own ? [own.mark] : [...this.containedInsertMarks(stack, at), this.continuedOwnInsert(stack, at) ?? this.options.markOf("insert")];
2186
- };
2187
- const withInserted = (props, added) => this.withMarks(withoutSpares(props), [...this.marks(props), ...added]);
2188
- const insertedLeaves = /* @__PURE__ */ new Set();
2189
- const landed = (props) => {
2190
- const marks = this.withoutCuts(props);
2191
- return this.withMarks(withoutSpares(props), [...marks, this.options.markOf("insert")]);
2192
- };
2193
- let trailingLeafProps = input.reopen ?? leafOf(stack);
2194
- let closedElement = false;
2195
- const elementsOf = (contexts) => contexts.filter((context) => context.kind === "element");
2196
- const keyOf = (context) => context?.path.join(",");
2197
- const written = elementsOf(input.startContexts ?? input.contexts);
2198
- const lands = elementsOf(input.contexts);
2199
- const landKeys = new Set(lands.map(keyOf));
2200
- const shared = new Set(written.map(keyOf).filter((key) => landKeys.has(key)));
2201
- let closedByStrike = written.length - lands.length;
2202
- let realigned = false;
2203
- let misplaced = false;
2204
- let reopened = false;
2205
- const misplacedReplacement = () => unrepresentable("Suggesting cannot place this replacement after the content it replaces.");
2206
- const closeLanding = () => {
2207
- for (; closedByStrike < 0; closedByStrike += 1) {
2208
- const inner = lands.at(-1);
2209
- if (misplaced || !inner || !this.options.isInline(inner.props)) throw misplacedReplacement();
2210
- closeLeaf();
2211
- if (stack.at(-1)?.kind === "text") stack.pop();
2212
- emit(closeToken("element"));
2213
- const closed = stack.pop();
2214
- if (closed) splitFrom.push(closed);
2215
- lands.pop();
2216
- closedElement = true;
2217
- realigned = true;
2218
- }
2219
- };
2220
- const place = (inline) => {
2221
- if (reopened) return;
2222
- closeLanding();
2223
- const into = written.at(-1);
2224
- const onto = lands.at(-1);
2225
- const joined = inline && into !== void 0 && onto !== void 0 && !shared.has(keyOf(into)) && !shared.has(keyOf(onto)) && into.props.type === onto.props.type && input.removedFrom > into.contentFrom + 1;
2226
- if (keyOf(into) !== keyOf(onto) && !joined) misplaced = true;
2227
- if (misplaced && realigned) throw misplacedReplacement();
2228
- };
2229
- const splitFrom = [];
2230
- let filled = 0;
2231
- const fills = /* @__PURE__ */ new Set();
2232
- const fillAt = (leaf = false, root = false) => {
2233
- const top = stack.at(-1);
2234
- if (!this.options.framed || (top ? top.kind !== "element" : !root) || outLeaf !== null) return;
2235
- const [first] = this.options.fill(stack.map((context) => context.props).reverse());
2236
- if (!first || typeof first.text === "string" || !first.children) return;
2237
- const { children, ...props } = first;
2238
- const withInsertMark = (marked) => this.withMarks(marked, [...this.marks(marked), this.options.markOf("insert")]);
2239
- const fillProps = withInsertMark(props);
2240
- const fill = {
2241
- contentFrom: at,
2242
- contentTo: at,
2243
- kind: "element",
2244
- path: [],
2245
- props: fillProps
2246
- };
2247
- emit(openToken("element", fillProps));
2248
- stack.push(fill);
2249
- fills.add(fill);
2250
- filled += 1;
2251
- const [text] = children;
2252
- if (leaf && text && typeof text.text === "string") {
2253
- const { text: _text, ...leafProps } = text;
2254
- ensureLeaf(withInsertMark(leafProps));
2255
- stack.push({
2256
- ...fill,
2257
- kind: "text",
2258
- props: outLeaf ?? leafProps
2259
- });
2260
- }
2261
- };
2262
- const [first] = local;
2263
- const splitsFill = first?.kind === "close" && !input.closesWrap;
2264
- if (splitsFill) fillAt(first.nodeKind === "text", true);
2265
- const unfill = () => {
2266
- if (filled === 0) return;
2267
- closeLeaf();
2268
- for (; filled > 0; filled -= 1) {
2269
- emit(closeToken("element"));
2270
- stack.pop();
2271
- }
2272
- };
2273
- for (let index = 0; index < local.length; index += 1) {
2274
- const token = local[index];
2275
- if (token.kind !== "text" && !splitsFill) unfill();
2276
- if (token.kind === "text") {
2277
- place(true);
2278
- fillAt(false, true);
2279
- const leaf = stack.at(-1);
2280
- const leafProps = leaf && leaf.kind === "text" ? leaf.props : {};
2281
- ensureLeaf(landing ? landed(leafProps) : leaf && insertedLeaves.has(leaf) ? leaf.props : this.suggestedTextProps(this.options.composedLeaf && leaf?.kind === "text" ? {
2282
- ...leaf,
2283
- props: this.withMarks(this.options.composedLeaf, this.marks(leaf.props))
2284
- } : leaf, at, ownElement()));
2285
- for (let offset = 0; offset < token.text.length; offset += 1) outputTextOffsets.push(outLength + offset);
2286
- emit(textToken(token.text));
2287
- continue;
2288
- }
2289
- const close = token.kind === "open" ? closeOf.get(index) : void 0;
2290
- if (token.kind === "open" && close !== void 0) {
2291
- place(token.nodeKind === "text" || this.options.isInline(token.props));
2292
- closeLeaf();
2293
- const subtree = local.slice(index, close + 1);
2294
- const added = landing ? null : insertedMarks();
2295
- for (const item of subtree) {
2296
- if (item.kind === "text") for (let offset = 0; offset < item.text.length; offset += 1) outputTextOffsets.push(outLength + offset);
2297
- else outputTextOffsets.push(outLength);
2298
- emit(item.kind !== "open" ? item : openToken(item.nodeKind, added === null ? landed(item.props) : withInserted(item.props, added)));
2299
- }
2300
- index = close;
2301
- continue;
2302
- }
2303
- if (token.kind === "open") {
2304
- closeLanding();
2305
- reopened = true;
2306
- closeLeaf();
2307
- outputTextOffsets.push(outLength);
2308
- const insertedLeaf = token.nodeKind === "text" && !landing && this.options.origin === "slice";
2309
- const continuing = {
2310
- contentFrom: at,
2311
- contentTo: at,
2312
- kind: token.nodeKind,
2313
- path: [],
2314
- props: insertedLeaf ? withInserted(token.props, insertedMarks()) : token.props
2315
- };
2316
- stack.push(continuing);
2317
- if (insertedLeaf) insertedLeaves.add(continuing);
2318
- if (token.nodeKind === "text") {
2319
- trailingLeafProps = this.continuedLeafProps(baseLeaf, token.props);
2320
- continue;
2321
- }
2322
- const continued = closedElement ? splitFrom.pop() : void 0;
2323
- const marks = continued ? this.marks(continued.props) : [];
2324
- const dropped = continued ? this.droppedOnSplit(continued, token.props, marks) : null;
2325
- const inherited = marks.filter((mark) => mark.kind === "insert" || mark.kind === "delete" || mark.kind === "format" && !dropped?.has(mark.key));
2326
- const own = ownElement();
2327
- const suggested = !own || continued !== void 0 && continued.path.length > 0 && !this.rejectingEmpties(this.index.node(continued.path), own.mark);
2328
- const claim = this.continuedOwnInsert(input.contexts, at) ?? this.options.markOf("split");
2329
- const rightCuts = this.splitInline(continued, token.props, suggested, claim);
2330
- const splitTags = continued && rightCuts?.some((mark) => isCut(mark) && mark.side === "start") ? this.splitHistoryTags(continued, token.props, marks, dropped, claim) : [];
2331
- const splitKeys = new Set(splitTags.map((tag) => tag.key));
2332
- if (continued && fills.has(continued)) {
2333
- fills.add(getDefined(stack.at(-1)));
2334
- filled += 1;
2335
- }
2336
- const writesType = continued !== void 0 && closedElement && suggested && !rightCuts && this.options.slotted(this.containerType(continued.path));
2337
- const isTypeTag = (mark) => mark.kind === "format" && mark.key === "type";
2338
- const carried = writesType ? [...inherited.filter((mark) => !isTypeTag(mark)), ...this.splitTypeTags(continued, token.props, inherited.filter((mark) => isTypeTag(mark)), claim)] : inherited;
2339
- const half = openToken("element", this.withMarks(token.props, [
2340
- ...this.marks(token.props),
2341
- ...carried.filter((mark) => mark.kind !== "format" || !splitKeys.has(mark.key)),
2342
- ...splitTags,
2343
- ...rightCuts ?? [],
2344
- ...suggested && !rightCuts ? [closedElement ? this.splitOf(continued, claim, token.props, dropped, stack.slice(0, -1).filter((context) => context.kind === "element")) : this.options.markOf("wrap")] : []
2345
- ]));
2346
- this.splitHalves.add(half);
2347
- emit(half);
2348
- continue;
2349
- }
2350
- if (token.nodeKind === "text") {
2351
- outputTextOffsets.push(outLength);
2352
- closeLeaf();
2353
- stack.pop();
2354
- trailingLeafProps = null;
2355
- continue;
2356
- }
2357
- closeLanding();
2358
- written.pop();
2359
- if (closedByStrike > 0) {
2360
- if (misplaced) throw misplacedReplacement();
2361
- closedByStrike -= 1;
2362
- realigned = true;
2363
- closeLeaf();
2364
- outputTextOffsets.push(outLength);
2365
- continue;
2366
- }
2367
- lands.pop();
2368
- closeLeaf();
2369
- outputTextOffsets.push(outLength);
2370
- emit(token);
2371
- const closed = stack.pop();
2372
- if (closed) splitFrom.push(closed);
2373
- if (closed && fills.has(closed)) filled -= 1;
2374
- closedElement = true;
2375
- }
2376
- if (trailingLeafProps !== null && local.at(-1)?.kind === "open") ensureLeaf(trailingLeafProps);
2377
- outputTextOffsets.push(outLength);
2378
- if (filled > 0) {
2379
- trailingLeafProps = null;
2380
- unfill();
2381
- }
2382
- if (trailingLeafProps === null) closeLeaf();
2383
- else ensureLeaf(trailingLeafProps);
2384
- if (output.length > 0) this.ops.push({
2385
- at,
2386
- kind: "insert",
2387
- tokens: output
2388
- });
2389
- if (inserted.length > 0) this.pieces.push({
2390
- afterFrom: input.after,
2391
- afterTo: input.after + inserted.length,
2392
- at,
2393
- kind: "inserted",
2394
- offsets: outputTextOffsets
2395
- });
2396
- if (at > input.removedFrom) this.pushRemoved(input.after, input.removedFrom, at);
2397
- }
2398
- /**
2399
- * A split of an inline element: the left fragment's `end` cuts move to the
2400
- * new right fragment, and a suggested split adds a cut, its `end` on the
2401
- * left fragment and its `start` on the right. Returns the right fragment's
2402
- * cut tags, or `null` when it gets none.
2403
- */
2404
- splitInline(continued, rightProps, suggested, claim) {
2405
- if (!continued || continued.path.length === 0 || !this.options.isInline(continued.props)) return null;
2406
- const marks = this.marks(continued.props);
2407
- const moved = marks.filter((mark) => isCut(mark) && mark.side === "end");
2408
- if (!suggested && moved.length === 0) return null;
2409
- const { at, author, change, inc } = claim;
2410
- const cut = suggested ? {
2411
- at,
2412
- author,
2413
- change,
2414
- ...inc === void 0 ? {} : { inc },
2415
- cut: this.options.createTagId(),
2416
- kind: "split"
2417
- } : null;
2418
- this.ops.push({
2419
- at: continued.contentFrom - 1,
2420
- kind: "props",
2421
- props: this.withMarks(continued.props, [...marks.filter((mark) => !moved.includes(mark)), ...cut ? [{
2422
- ...cut,
2423
- side: "end"
2424
- }] : []])
2425
- });
2426
- return [...moved, ...cut ? [{
2427
- ...cut,
2428
- side: "start"
2429
- }] : []];
2430
- }
2431
- splitHistoryTags(source, output, marks, dropped, claim) {
2432
- const keys = /* @__PURE__ */ new Set([...Object.keys(source.props).filter((key) => key !== "authored" && !Object.hasOwn(output, key)), ...dropped ?? []]);
2433
- if (keys.size === 0) return [];
2434
- const { source: origin, standing, commitWriteId } = this.options;
2435
- const { at, author, change, inc } = claim;
2436
- const copies = marks.filter((mark) => mark.kind === "format" && keys.has(mark.key));
2437
- return recordFormats({
2438
- keys,
2439
- next: output,
2440
- ownInsertion: false,
2441
- previous: source.props,
2442
- source: origin,
2443
- standing,
2444
- tags: copies,
2445
- writer: {
2446
- at,
2447
- author,
2448
- change,
2449
- ...inc === void 0 ? {} : { inc },
2450
- isOwn: () => false,
2451
- commitWriteId
2452
- }
2453
- }).map((tag) => copies.includes(tag) ? tag : {
2454
- ...tag,
2455
- split: change
2456
- });
2457
- }
2458
- /**
2459
- * The leaf a split or an insertion continues the document in: the review
2460
- * leaf's marks with the other properties the edit changed, which Suggesting
2461
- * records as that text's format change.
2462
- */
2463
- continuedLeafProps(base, next) {
2464
- if (!base) return next;
2465
- return this.formattedProps(base, this.withMarks(next, this.marks(base))) ?? base;
2466
- }
2467
- suggestedTextProps(leaf, at, ownElement) {
2468
- if (!leaf || leaf.kind !== "text") return this.withMarks({}, [ownElement?.mark ?? this.options.markOf("insert")]);
2469
- const marks = this.marks(leaf.props);
2470
- const innermost = innermostInsert(marks);
2471
- const foreign = innermost !== void 0 && !this.options.isOwn(innermost);
2472
- const struck = marks.some((mark) => mark.kind === "delete");
2473
- if (innermost && !foreign && !struck) return withoutHeld(leaf.props);
2474
- if (ownElement && (ownElement.oneText || !foreign)) {
2475
- const live = marks.filter((mark) => mark.kind !== "delete" && mark.kind !== "format");
2476
- return this.withMarks(leaf.props, ownElement.oneText ? live : [...live, ownElement.mark], true);
2477
- }
2478
- const kept = leaf.contentFrom < at && at < leaf.contentTo ? marks.filter((mark) => mark.kind === "insert") : this.sharedNeighborInserts(leaf, at);
2479
- return this.withMarks(leaf.props, [...kept, this.continuedOwnInsert([leaf], at) ?? this.options.markOf("insert")], true);
2480
- }
2481
- /**
2482
- * Insert marks an edge insertion keeps: only those on both sides of it, in
2483
- * the left side's order.
2484
- */
2485
- sharedNeighborInserts(leaf, at) {
2486
- const leftEdge = at === leaf.contentFrom;
2487
- const neighbor = this.neighborLeaf(leaf, leftEdge ? -1 : 1);
2488
- if (!neighbor) return [];
2489
- const inserts = (props) => this.marks(props).filter((mark) => mark.kind === "insert");
2490
- const [left, right] = leftEdge ? [inserts(neighbor), inserts(leaf.props)] : [inserts(leaf.props), inserts(neighbor)];
2491
- const keys = new Set(right.map(incarnationOf));
2492
- return left.filter((mark) => keys.has(incarnationOf(mark)));
2493
- }
2494
- editingMergesAcross(change, joins) {
2495
- return isEditingChange(change) && joins.every((join) => !isEditingChange(join.change) && !this.frameJoins().followed.has(linkOf(join)) && join.kind === "join" && join.key !== void 0 && this.frameJoins().holders.get(join.key) === 1);
2496
- }
2497
- /** The pending join a block with these marks carries or goes with. */
2498
- followedBy(props) {
2499
- const marks = this.marks(props);
2500
- const join = marks.find(this.isLiveJoin);
2501
- return join ? linkOf(join) : marks.map(followsOf).find(Boolean);
2502
- }
2503
- splitOf(source, claim, tail, dropped, openElements) {
2504
- const { at, author, change, inc } = claim;
2505
- const follows = source ? this.followedBy(source.props) : void 0;
2506
- const place = source && source.path.length > 0 && !isEditingChange(change) ? this.splitPlace(source.path, openElements) : null;
2507
- return {
2508
- at,
2509
- author,
2510
- change,
2511
- ...inc === void 0 ? {} : { inc },
2512
- ...follows === void 0 ? {} : { follows },
2513
- ...source && place ? { gave: this.gaveOf(source.props, tail, dropped, place) } : {},
2514
- kind: "split"
2515
- };
2516
- }
2517
- splitPlace(path, openElements) {
2518
- const parent = openElements.at(-1);
2519
- return {
2520
- continuationAncestors: openElements.map((context) => context.path.length === 0 ? context.props : this.propsWrittenAtStart.get(context.contentFrom - 1) ?? context.props).reverse(),
2521
- continuationIndex: parent?.path.length === 0 ? 0 : getDefined(path[parent?.path.length ?? 0]) + 1,
2522
- sourceAncestors: path.slice(1).map((_, depth) => propsOf(this.index.node(path.slice(0, depth + 1)))).reverse()
2523
- };
2524
- }
2525
- gaveOf(source, tail, dropped, place) {
2526
- const keeps = this.options.splitKeepsIn(source, tail, place);
2527
- const split = this.marks(source).find((mark) => mark.kind === "split" && mark.cut === void 0);
2528
- return gaveBy(source, split?.gave && {
2529
- gave: split.gave,
2530
- incarnation: incarnationOf(split)
2531
- }, tail, this.options.joinCompares, (key) => keeps(key, ownOf(source, key)), dropped ?? /* @__PURE__ */ new Set(), this.declaredAtEitherPlace(source, tail, place));
2532
- }
2533
- declaredAtEitherPlace(source, tail, place) {
2534
- return new Map([...[...this.options.declaredIn(source, place.sourceAncestors).keys()].map((key) => [key, void 0]), ...this.options.declaredIn(tail, place.continuationAncestors)]);
2535
- }
2536
- containerType(path) {
2537
- if (path.length < 2) return null;
2538
- const { type } = this.index.node(path.slice(0, -1));
2539
- return typeof type === "string" ? type : null;
2540
- }
2541
- /** The type tags of a split's tail, with the split's write over `tags`. */
2542
- splitTypeTags(source, tail, tags, claim) {
2543
- const { isOwn, source: origin, standing, commitWriteId } = this.options;
2544
- const { at, author, change, inc } = claim;
2545
- return recordFormats({
2546
- keys: ["type"],
2547
- next: tail,
2548
- ownInsertion: false,
2549
- previous: source.props,
2550
- source: origin,
2551
- standing,
2552
- tags,
2553
- writer: {
2554
- at,
2555
- author,
2556
- change,
2557
- ...inc === void 0 ? {} : { inc },
2558
- isOwn,
2559
- commitWriteId
2560
- }
2561
- });
2562
- }
2563
- rejectingEmpties(node, own) {
2564
- const { children, text } = node;
2565
- if (typeof text === "string") return text === "" || this.marks(propsOf(node)).some((mark) => mark.kind === "insert" && incarnationOf(mark) === incarnationOf(own));
2566
- return (children ?? []).every((child) => this.rejectingEmpties(child, own));
2567
- }
2568
- continuedOwnInsert(stack, at) {
2569
- const leaf = stack.at(-1);
2570
- const candidates = [];
2571
- if (leaf?.kind === "text") {
2572
- candidates.push(leaf.props);
2573
- if (at === leaf.contentFrom || at === leaf.contentTo) {
2574
- const neighbor = this.neighborLeaf(leaf, at === leaf.contentFrom ? -1 : 1);
2575
- if (neighbor) candidates.push(neighbor);
2576
- }
2577
- } else {
2578
- const ownSplitOfEmptyBlock = leaf && at === leaf.contentFrom && at === leaf.contentTo ? this.marks(leaf.props).find((mark) => mark.kind === "split" && !isCut(mark) && this.options.isOwn(mark)) : void 0;
2579
- if (ownSplitOfEmptyBlock) {
2580
- const { at: time, author, change, inc } = ownSplitOfEmptyBlock;
2581
- return {
2582
- at: time,
2583
- author,
2584
- change,
2585
- ...inc === void 0 ? {} : { inc },
2586
- kind: "insert"
2587
- };
2588
- }
2589
- for (const direction of [-1, 1]) {
2590
- const point = this.index.pointAt(at, direction);
2591
- if (point && (!leaf || leaf.path.every((index, depth) => point.path[depth] === index))) candidates.push(...this.textsBeside(point.path, direction));
2592
- }
2593
- }
2594
- for (const props of candidates) {
2595
- const marks = this.marks(props);
2596
- if (marks.some((mark) => mark.kind === "delete")) continue;
2597
- const innermost = innermostInsert(marks);
2598
- if (innermost && this.options.isOwn(innermost)) return innermost;
2599
- }
2600
- return null;
2601
- }
2602
- containedInsertMarks(stack, at) {
2603
- const leaf = stack.at(-1);
2604
- if (!leaf || leaf.kind !== "text") return [];
2605
- if (!(leaf.contentFrom < at && at < leaf.contentTo)) return [];
2606
- return this.marks(leaf.props).filter((mark) => mark.kind === "insert" && !this.options.isOwn(mark));
2607
- }
2608
- /**
2609
- * One's own pending deletion right beside a struck run takes it in, so
2610
- * repeated Backspace or Delete grows one deletion instead of many.
2611
- */
2612
- ownDeleteNear(leaf, from, to) {
2613
- const neighbors = [from === leaf.contentFrom ? this.neighborLeaf(leaf, -1) : null, to >= leaf.contentTo ? this.neighborLeaf(leaf, 1) : null];
2614
- for (const props of neighbors) {
2615
- const own = props ? this.marks(props).find((mark) => mark.kind === "delete" && this.options.isOwn(mark)) : void 0;
2616
- if (own) return own;
2617
- }
2618
- return null;
2619
- }
2620
- /** A split at a text's end leaves an empty leaf for a write to look past. */
2621
- textsBeside(path, direction) {
2622
- const parentPath = path.slice(0, -1);
2623
- const siblings = parentPath.length === 0 ? this.index.value : this.index.node(parentPath).children;
2624
- const texts = [];
2625
- for (let index = path.at(-1) ?? 0; typeof siblings[index]?.text === "string"; index += direction) {
2626
- texts.push(propsOf(siblings[index]));
2627
- if (siblings[index].text !== "") break;
2628
- }
2629
- return texts;
2630
- }
2631
- neighborLeaf(leaf, direction) {
2632
- const parentPath = leaf.path.slice(0, -1);
2633
- const index = leaf.path.at(-1) ?? 0;
2634
- const sibling = (parentPath.length === 0 ? this.index.value : this.index.node(parentPath).children)?.[index + direction];
2635
- return sibling && typeof sibling.text === "string" ? propsOf(sibling) : null;
2636
- }
2637
- composedProps() {
2638
- const propsAt = /* @__PURE__ */ new Map();
2639
- for (const op of this.ops) {
2640
- if (op.kind !== "props") continue;
2641
- const original = this.propsStartingAt(op.at);
2642
- propsAt.set(op.at, applyPropertyModifications(propsAt.get(op.at) ?? original, semanticPropertyModifications(original, op.props, isMarksKey)));
2643
- }
2644
- return propsAt;
2645
- }
2646
- freshCopyKeys() {
2647
- const { change } = this.options.markOf("insert");
2648
- this.ops.forEach((op, index) => {
2649
- if (op.kind !== "insert" || this.freshened.has(op) || isEditingMoveCopy(op, change)) return;
2650
- const { tokens } = this.withCopyMarks(op.tokens);
2651
- if (tokens !== op.tokens) this.ops[index] = {
2652
- ...op,
2653
- tokens
2654
- };
2655
- });
2656
- }
2657
- /**
2658
- * Gives each keyed join and `joined` claim in a copy a fresh key, and points
2659
- * each follower in it at the nearest copied join of its link before it, or
2660
- * else the first one after it. A half a split writes keeps its links, and a
2661
- * join set aside becomes a plain break. Also returns where each join's
2662
- * copies sit.
2663
- */
2664
- withCopyMarks(tokens) {
2665
- const joins = /* @__PURE__ */ new Map();
2666
- const links = /* @__PURE__ */ new Map();
2667
- let dropsAside = false;
2668
- for (const [at, token] of tokens.entries()) {
2669
- if (token.kind !== "open") continue;
2670
- for (const mark of this.marks(token.props)) {
2671
- if (!isKeyedJoin(mark)) continue;
2672
- if (this.options.joinAside(mark)) {
2673
- dropsAside = true;
2674
- continue;
2675
- }
2676
- const copy = {
2677
- ...mark,
2678
- key: this.options.createTagId()
2679
- };
2680
- const copied = joins.get(at) ?? /* @__PURE__ */ new Map();
2681
- const original = linkOf(mark);
2682
- copied.set(mark, copy);
2683
- joins.set(at, copied);
2684
- links.set(original, [...links.get(original) ?? [], {
2685
- at,
2686
- link: linkOf(copy)
2687
- }]);
2688
- }
2689
- }
2690
- if (joins.size === 0 && !dropsAside) return {
2691
- links,
2692
- tokens
2693
- };
2694
- return {
2695
- links,
2696
- tokens: tokens.map((token, at) => {
2697
- if (token.kind !== "open") return token;
2698
- const marks = this.marks(token.props);
2699
- const half = this.splitHalves.has(token);
2700
- if (!marks.some((mark) => this.options.joinAside(mark) || joins.get(at)?.has(mark) || !half && isFollower(mark) && mark.follows !== void 0 && links.has(mark.follows))) return token;
2701
- return openToken(token.nodeKind, this.withMarks(token.props, marks.flatMap((mark) => {
2702
- if (this.options.joinAside(mark)) return [];
2703
- const join = joins.get(at)?.get(mark);
2704
- if (join) return [join];
2705
- if (!half && isFollower(mark) && mark.follows !== void 0) {
2706
- const candidates = links.get(mark.follows);
2707
- const follows = (candidates?.findLast((copy) => copy.at < at) ?? candidates?.[0])?.link;
2708
- if (follows) return [{
2709
- ...mark,
2710
- follows
2711
- }];
2712
- }
2713
- return [mark];
2714
- })));
2715
- })
2716
- };
2717
- }
2718
- sections() {
2719
- const propsAt = this.composedProps();
2720
- const ordered = [...this.ops].sort((left, right) => startOf(left) - startOf(right) || rank(left) - rank(right));
2721
- const sections = [];
2722
- for (const op of ordered) {
2723
- const previous = sections.at(-1);
2724
- if (op.kind === "insert") {
2725
- if (previous && previous.insert && (previous.to ?? previous.from) === op.at) {
2726
- sections[sections.length - 1] = {
2727
- ...previous,
2728
- insert: previous.insert.concat(PreparedTokenSlice.fromTokens(op.tokens))
2729
- };
2730
- continue;
2731
- }
2732
- sections.push({
2733
- from: op.at,
2734
- insert: PreparedTokenSlice.fromTokens(op.tokens),
2735
- to: op.at
2736
- });
2737
- continue;
2738
- }
2739
- if (op.kind === "remove") {
2740
- if (previous && previous.insert && previous.from === op.from && previous.to === op.from) {
2741
- sections[sections.length - 1] = {
2742
- ...previous,
2743
- to: op.to
2744
- };
2745
- continue;
2746
- }
2747
- if (previous && !previous.properties && (previous.to ?? previous.from) === op.from && previous.to !== previous.from) {
2748
- sections[sections.length - 1] = {
2749
- ...previous,
2750
- to: op.to
2751
- };
2752
- continue;
2753
- }
2754
- sections.push({
2755
- from: op.from,
2756
- to: op.to
2757
- });
2758
- continue;
2759
- }
2760
- const props = propsAt.get(op.at);
2761
- if (!props) continue;
2762
- propsAt.delete(op.at);
2763
- const modifications = semanticPropertyModifications(this.propsStartingAt(op.at), props, isMarksKey);
2764
- if (modifications.length === 0) continue;
2765
- sections.push({
2766
- from: op.at,
2767
- properties: deltaOf(modifications),
2768
- to: op.at + 1
2769
- });
2770
- }
2771
- return sections;
2772
- }
2773
- insertionStartingAt(position) {
2774
- return this.pieces.find((piece) => piece.kind === "inserted" && piece.afterFrom === position && piece.afterTo > position);
2775
- }
2776
- mapPosition(recorded, position, assoc, caret, atContent) {
2777
- let removed = null;
2778
- const startsInserted = atContent && assoc === 1 && this.pieces.some((piece) => piece.kind === "inserted" && piece.afterFrom === position && piece.afterTo > position);
2779
- for (const piece of this.pieces) if (!startsInserted && piece.kind === "removed" && (piece.after === position || caret && this.besideRemoval(piece, position))) removed = piece;
2780
- const replacing = removed && !caret && assoc === 1 ? this.insertionStartingAt(position) : void 0;
2781
- if (replacing) return (recorded.mapPos(replacing.at, -1) ?? position) + (replacing.offsets[0] ?? 0);
2782
- for (const piece of this.pieces) {
2783
- if (piece.kind === "removed") continue;
2784
- if (position < piece.afterFrom || position > piece.afterTo) continue;
2785
- if (piece.kind === "shifted") return recorded.mapPos(this.options.plainToReview(piece.plainFrom + position - piece.afterFrom, assoc, caret), assoc) ?? position;
2786
- if (piece.kind === "kept") {
2787
- if (removed) break;
2788
- if (position === piece.afterTo && assoc === 1 && piece.afterTo > piece.afterFrom) continue;
2789
- return recorded.mapPos(piece.beforeFrom + position - piece.afterFrom, assoc) ?? position;
2790
- }
2791
- return (recorded.mapPos(piece.at, -1) ?? position) + (piece.offsets[position - piece.afterFrom] ?? 0);
2792
- }
2793
- if (removed) {
2794
- const right = caret ? !removed.leftward : assoc === 1;
2795
- const edge = right ? removed.beforeTo : removed.beforeFrom;
2796
- if (!caret) return recorded.mapPos(edge, right ? 1 : -1) ?? position;
2797
- return recorded.mapPos(...this.caretLanding(removed, right)) ?? position;
2798
- }
2799
- return position;
2800
- }
2801
- caretLanding(removed, right) {
2802
- const past = this.intoLeaf(right ? removed.beforeTo : removed.beforeFrom, right);
2803
- const near = this.intoLeaf(right ? removed.beforeFrom : removed.beforeTo, !right);
2804
- return !this.inLeaf(past) && this.inLeaf(near) ? [near, right ? -1 : 1] : [past, right ? 1 : -1];
2805
- }
2806
- inLeaf(position) {
2807
- const [before, after] = [position - 1, position].map((at) => at >= 0 && at < this.index.length ? this.index.slice(at, at + 1).tokens[0] : void 0);
2808
- return before?.kind === "text" || before?.kind === "open" && before.nodeKind === "text" || after?.kind === "text" || after?.kind === "close" && after.nodeKind === "text";
2809
- }
2810
- /**
2811
- * Whether a caret sits at a removal with only text-leaf boundaries between,
2812
- * which an edit leaves when it puts the caret in the next or previous leaf.
2813
- */
2814
- besideRemoval(removed, position) {
2815
- for (const piece of this.pieces) {
2816
- if (piece.kind !== "kept") continue;
2817
- if (position < piece.afterFrom || position > piece.afterTo) continue;
2818
- const at = piece.beforeFrom + position - piece.afterFrom;
2819
- if (piece.afterTo === removed.after) return this.onlyLeafBoundaries(at, removed.beforeFrom);
2820
- if (piece.afterFrom === removed.after) return this.onlyLeafBoundaries(removed.beforeTo, at);
2821
- }
2822
- return false;
2823
- }
2824
- onlyLeafBoundaries(from, to) {
2825
- if (from > to) return false;
2826
- for (let at = from; at < to; at += 1) for (const token of this.index.slice(at, at + 1).tokens) if (token.kind === "text" || token.nodeKind !== "text") return false;
2827
- return true;
2828
- }
2829
- intoLeaf(position, right) {
2830
- const boundary = (from, kind) => {
2831
- const token = this.index.slice(from, from + 1).tokens[0];
2832
- return token?.kind === kind && token.nodeKind === "text";
2833
- };
2834
- let at = position;
2835
- if (right) while (at < this.index.length && boundary(at, "open")) at += 1;
2836
- else while (at > 0 && boundary(at - 1, "close")) at -= 1;
2837
- return at;
2838
- }
2839
- };
2840
- const isMarksKey = (key) => key === AUTHORED_MARKS_KEY;
2841
- const sameToken = (left, right) => {
2842
- if (left.kind === "text") return right.kind === "text" && left.text === right.text;
2843
- if (right.kind !== left.kind || right.nodeKind !== left.nodeKind) return false;
2844
- return left.kind === "open" && right.kind === "open" ? jsonEqual(left.props, right.props) : true;
2845
- };
2846
- const hasEnclosingEdges = (tokens, depth) => {
2847
- const closeOf = matchTokens(tokens);
2848
- for (let level = 0; level < depth; level += 1) {
2849
- const open = tokens[level];
2850
- if (open?.kind !== "open" || open.nodeKind !== "element" || closeOf.get(level) !== tokens.length - 1 - level) return false;
2851
- }
2852
- return true;
2853
- };
2854
- const enclosureOf = (removed, inserted) => {
2855
- const wraps = removed.tokens.length < inserted.tokens.length;
2856
- const inner = wraps ? removed.tokens : inserted.tokens;
2857
- const outer = wraps ? inserted.tokens : removed.tokens;
2858
- const depth = (outer.length - inner.length) / 2;
2859
- if (inner.length === 0 || depth < 1 || !Number.isInteger(depth)) return null;
2860
- if (!hasEnclosingEdges(outer, depth) || !inner.every((token, index) => sameToken(token, outer[depth + index]))) return null;
2861
- return {
2862
- depth,
2863
- wraps
2864
- };
2865
- };
2866
- const asInsertion = ({ at, author, change, inc }) => ({
2867
- at,
2868
- author,
2869
- change,
2870
- ...inc === void 0 ? {} : { inc },
2871
- kind: "insert"
2872
- });
2873
- const leafOf = (contexts) => {
2874
- const leaf = contexts.at(-1);
2875
- return leaf?.kind === "text" ? leaf.props : null;
2876
- };
2877
- const matchTokens = (tokens) => {
2878
- const closeOf = /* @__PURE__ */ new Map();
2879
- const open = [];
2880
- tokens.forEach((token, index) => {
2881
- if (token.kind === "open") open.push(index);
2882
- else if (token.kind === "close") {
2883
- const opened = open.pop();
2884
- if (opened !== void 0) closeOf.set(opened, index);
2885
- }
2886
- });
2887
- return closeOf;
2888
- };
2889
- const startOf = (op) => op.kind === "remove" ? op.from : op.at;
2890
- const rank = (op) => op.kind === "insert" ? 0 : op.kind === "remove" ? 1 : 2;
2891
- const deltaOf = (modifications) => {
2892
- const set = {};
2893
- const unset = [];
2894
- const add = {};
2895
- const remove = {};
2896
- for (const modification of modifications) if (modification.type === "set") set[modification.key] = modification.value;
2897
- else if (modification.type === "unset") unset.push(modification.key);
2898
- else if (modification.type === "add") add[modification.key] = [...modification.values];
2899
- else remove[modification.key] = [...modification.values];
2900
- return {
2901
- ...Object.keys(add).length > 0 ? { add } : {},
2902
- ...Object.keys(remove).length > 0 ? { remove } : {},
2903
- ...Object.keys(set).length > 0 ? { set } : {},
2904
- ...unset.length > 0 ? { unset } : {}
2905
- };
2906
- };
2907
- //#endregion
2908
- export { recordAuthoredSteps };