@fluidframework/tree 2.81.1 → 2.82.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (579) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/api-report/tree.alpha.api.md +54 -22
  3. package/api-report/tree.beta.api.md +150 -1
  4. package/api-report/tree.legacy.beta.api.md +150 -1
  5. package/api-report/tree.legacy.public.api.md +1 -0
  6. package/api-report/tree.public.api.md +1 -0
  7. package/dist/alpha.d.ts +8 -2
  8. package/dist/beta.d.ts +3 -0
  9. package/dist/codec/codec.d.ts +17 -8
  10. package/dist/codec/codec.d.ts.map +1 -1
  11. package/dist/codec/codec.js +8 -1
  12. package/dist/codec/codec.js.map +1 -1
  13. package/dist/codec/index.d.ts +1 -1
  14. package/dist/codec/index.d.ts.map +1 -1
  15. package/dist/codec/index.js +2 -1
  16. package/dist/codec/index.js.map +1 -1
  17. package/dist/codec/versioned/codec.d.ts +1 -1
  18. package/dist/codec/versioned/codec.d.ts.map +1 -1
  19. package/dist/codec/versioned/codec.js.map +1 -1
  20. package/dist/core/index.d.ts +1 -1
  21. package/dist/core/index.d.ts.map +1 -1
  22. package/dist/core/index.js +4 -2
  23. package/dist/core/index.js.map +1 -1
  24. package/dist/core/rebase/changeRebaser.d.ts +3 -2
  25. package/dist/core/rebase/changeRebaser.d.ts.map +1 -1
  26. package/dist/core/rebase/changeRebaser.js.map +1 -1
  27. package/dist/core/rebase/index.d.ts +1 -1
  28. package/dist/core/rebase/index.d.ts.map +1 -1
  29. package/dist/core/rebase/index.js +4 -2
  30. package/dist/core/rebase/index.js.map +1 -1
  31. package/dist/core/rebase/types.d.ts +23 -3
  32. package/dist/core/rebase/types.d.ts.map +1 -1
  33. package/dist/core/rebase/types.js +30 -16
  34. package/dist/core/rebase/types.js.map +1 -1
  35. package/dist/core/schema-stored/formatV1.d.ts +2 -2
  36. package/dist/core/schema-stored/formatV1.d.ts.map +1 -1
  37. package/dist/core/schema-stored/formatV1.js +0 -5
  38. package/dist/core/schema-stored/formatV1.js.map +1 -1
  39. package/dist/core/schema-stored/formatV2.d.ts +11 -10
  40. package/dist/core/schema-stored/formatV2.d.ts.map +1 -1
  41. package/dist/core/schema-stored/formatV2.js +1 -6
  42. package/dist/core/schema-stored/formatV2.js.map +1 -1
  43. package/dist/core/schema-stored/index.d.ts.map +1 -1
  44. package/dist/core/schema-stored/index.js.map +1 -1
  45. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  46. package/dist/core/schema-stored/schema.js.map +1 -1
  47. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  48. package/dist/core/tree/anchorSet.js.map +1 -1
  49. package/dist/core/tree/delta.d.ts +9 -7
  50. package/dist/core/tree/delta.d.ts.map +1 -1
  51. package/dist/core/tree/delta.js.map +1 -1
  52. package/dist/core/tree/deltaUtil.js +1 -1
  53. package/dist/core/tree/deltaUtil.js.map +1 -1
  54. package/dist/core/tree/visitDelta.js +2 -2
  55. package/dist/core/tree/visitDelta.js.map +1 -1
  56. package/dist/extensibleSchemaUnion.d.ts +72 -0
  57. package/dist/extensibleSchemaUnion.d.ts.map +1 -0
  58. package/dist/extensibleSchemaUnion.js +79 -0
  59. package/dist/extensibleSchemaUnion.js.map +1 -0
  60. package/dist/feature-libraries/changeAtomIdBTree.d.ts +4 -2
  61. package/dist/feature-libraries/changeAtomIdBTree.d.ts.map +1 -1
  62. package/dist/feature-libraries/changeAtomIdBTree.js +9 -1
  63. package/dist/feature-libraries/changeAtomIdBTree.js.map +1 -1
  64. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts +1 -3
  65. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  66. package/dist/feature-libraries/default-schema/defaultFieldKinds.js +20 -21
  67. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  68. package/dist/feature-libraries/default-schema/index.d.ts +1 -1
  69. package/dist/feature-libraries/default-schema/index.d.ts.map +1 -1
  70. package/dist/feature-libraries/default-schema/index.js.map +1 -1
  71. package/dist/feature-libraries/forest-summary/codec.d.ts +2 -1
  72. package/dist/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  73. package/dist/feature-libraries/forest-summary/codec.js.map +1 -1
  74. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  75. package/dist/feature-libraries/forest-summary/forestSummarizer.js +5 -2
  76. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  77. package/dist/feature-libraries/forest-summary/formatCommon.d.ts +1 -39
  78. package/dist/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -1
  79. package/dist/feature-libraries/forest-summary/formatCommon.js +1 -2
  80. package/dist/feature-libraries/forest-summary/formatCommon.js.map +1 -1
  81. package/dist/feature-libraries/forest-summary/formatV1.d.ts +1 -39
  82. package/dist/feature-libraries/forest-summary/formatV1.d.ts.map +1 -1
  83. package/dist/feature-libraries/forest-summary/formatV2.d.ts +1 -39
  84. package/dist/feature-libraries/forest-summary/formatV2.d.ts.map +1 -1
  85. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +1 -1
  86. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  87. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js +1 -1
  88. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  89. package/dist/feature-libraries/index.d.ts +3 -3
  90. package/dist/feature-libraries/index.d.ts.map +1 -1
  91. package/dist/feature-libraries/index.js +4 -3
  92. package/dist/feature-libraries/index.js.map +1 -1
  93. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts +2 -2
  94. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts.map +1 -1
  95. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.js +42 -22
  96. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.js.map +1 -1
  97. package/dist/feature-libraries/modular-schema/genericFieldKind.js +1 -1
  98. package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  99. package/dist/feature-libraries/modular-schema/index.d.ts +1 -1
  100. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  101. package/dist/feature-libraries/modular-schema/index.js +2 -1
  102. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  103. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +1 -1
  104. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
  105. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js +9 -5
  106. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
  107. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts +11 -1
  108. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  109. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +30 -7
  110. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  111. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  112. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +38 -27
  113. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  114. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.d.ts +10 -127
  115. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.d.ts.map +1 -1
  116. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.js +2 -4
  117. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.js.map +1 -1
  118. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.d.ts +3 -79
  119. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.d.ts.map +1 -1
  120. package/dist/feature-libraries/optional-field/optionalField.js +1 -1
  121. package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
  122. package/dist/feature-libraries/optional-field/requiredField.d.ts.map +1 -1
  123. package/dist/feature-libraries/optional-field/requiredField.js.map +1 -1
  124. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -2
  125. package/dist/feature-libraries/schema-index/codec.js.map +1 -1
  126. package/dist/feature-libraries/schema-index/formatV2.d.ts +4 -4
  127. package/dist/feature-libraries/schema-index/schemaSummarizer.js +1 -1
  128. package/dist/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  129. package/dist/feature-libraries/sequence-field/invert.js +2 -2
  130. package/dist/feature-libraries/sequence-field/invert.js.map +1 -1
  131. package/dist/feature-libraries/sequence-field/replaceRevisions.js +16 -16
  132. package/dist/feature-libraries/sequence-field/replaceRevisions.js.map +1 -1
  133. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js +1 -1
  134. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  135. package/dist/index.d.ts +5 -5
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/index.js +4 -1
  138. package/dist/index.js.map +1 -1
  139. package/dist/legacy.d.ts +3 -0
  140. package/dist/packageVersion.d.ts +1 -1
  141. package/dist/packageVersion.js +1 -1
  142. package/dist/packageVersion.js.map +1 -1
  143. package/dist/shared-tree/independentView.d.ts +36 -13
  144. package/dist/shared-tree/independentView.d.ts.map +1 -1
  145. package/dist/shared-tree/independentView.js +1 -0
  146. package/dist/shared-tree/independentView.js.map +1 -1
  147. package/dist/shared-tree/index.d.ts +1 -1
  148. package/dist/shared-tree/index.d.ts.map +1 -1
  149. package/dist/shared-tree/index.js.map +1 -1
  150. package/dist/shared-tree/schematizingTreeView.d.ts +10 -0
  151. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  152. package/dist/shared-tree/schematizingTreeView.js +25 -9
  153. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  154. package/dist/shared-tree/sharedTree.d.ts +3 -3
  155. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  156. package/dist/shared-tree/sharedTree.js +8 -32
  157. package/dist/shared-tree/sharedTree.js.map +1 -1
  158. package/dist/shared-tree/sharedTreeChangeCodecs.d.ts +11 -3
  159. package/dist/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
  160. package/dist/shared-tree/sharedTreeChangeCodecs.js +38 -4
  161. package/dist/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  162. package/dist/shared-tree/sharedTreeChangeFormat.d.ts +4 -4
  163. package/dist/shared-tree/tree.js +1 -1
  164. package/dist/shared-tree/tree.js.map +1 -1
  165. package/dist/shared-tree/treeCheckout.d.ts +20 -0
  166. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  167. package/dist/shared-tree/treeCheckout.js +39 -3
  168. package/dist/shared-tree/treeCheckout.js.map +1 -1
  169. package/dist/shared-tree-core/editManagerSummarizer.js +1 -1
  170. package/dist/shared-tree-core/editManagerSummarizer.js.map +1 -1
  171. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  172. package/dist/shared-tree-core/messageCodecV1ToV4.js +2 -2
  173. package/dist/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  174. package/dist/shared-tree-core/transaction.d.ts +14 -3
  175. package/dist/shared-tree-core/transaction.d.ts.map +1 -1
  176. package/dist/shared-tree-core/transaction.js +59 -16
  177. package/dist/shared-tree-core/transaction.js.map +1 -1
  178. package/dist/shared-tree-core/versionedSummarizer.d.ts.map +1 -1
  179. package/dist/shared-tree-core/versionedSummarizer.js +1 -1
  180. package/dist/shared-tree-core/versionedSummarizer.js.map +1 -1
  181. package/dist/simple-tree/api/index.d.ts +1 -1
  182. package/dist/simple-tree/api/index.d.ts.map +1 -1
  183. package/dist/simple-tree/api/index.js +3 -2
  184. package/dist/simple-tree/api/index.js.map +1 -1
  185. package/dist/simple-tree/api/schemaCreationUtilities.d.ts +9 -0
  186. package/dist/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  187. package/dist/simple-tree/api/schemaCreationUtilities.js +16 -1
  188. package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  189. package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -1
  190. package/dist/simple-tree/api/transactionTypes.d.ts +10 -0
  191. package/dist/simple-tree/api/transactionTypes.d.ts.map +1 -1
  192. package/dist/simple-tree/api/transactionTypes.js.map +1 -1
  193. package/dist/simple-tree/api/tree.d.ts +81 -6
  194. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  195. package/dist/simple-tree/api/tree.js.map +1 -1
  196. package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  197. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  198. package/dist/simple-tree/index.d.ts +2 -2
  199. package/dist/simple-tree/index.d.ts.map +1 -1
  200. package/dist/simple-tree/index.js +4 -2
  201. package/dist/simple-tree/index.js.map +1 -1
  202. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  203. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  204. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts +63 -0
  205. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  206. package/dist/simple-tree/node-kinds/array/arrayNode.js +43 -1
  207. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  208. package/dist/simple-tree/node-kinds/array/index.d.ts +1 -1
  209. package/dist/simple-tree/node-kinds/array/index.d.ts.map +1 -1
  210. package/dist/simple-tree/node-kinds/array/index.js +2 -1
  211. package/dist/simple-tree/node-kinds/array/index.js.map +1 -1
  212. package/dist/simple-tree/node-kinds/index.d.ts +1 -1
  213. package/dist/simple-tree/node-kinds/index.d.ts.map +1 -1
  214. package/dist/simple-tree/node-kinds/index.js +2 -1
  215. package/dist/simple-tree/node-kinds/index.js.map +1 -1
  216. package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  217. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  218. package/dist/tableSchema.d.ts +71 -48
  219. package/dist/tableSchema.d.ts.map +1 -1
  220. package/dist/tableSchema.js +200 -98
  221. package/dist/tableSchema.js.map +1 -1
  222. package/dist/text/textDomainFormatted.js +1 -1
  223. package/dist/text/textDomainFormatted.js.map +1 -1
  224. package/dist/util/bTreeUtils.d.ts +30 -4
  225. package/dist/util/bTreeUtils.d.ts.map +1 -1
  226. package/dist/util/bTreeUtils.js +29 -17
  227. package/dist/util/bTreeUtils.js.map +1 -1
  228. package/dist/util/brand.d.ts.map +1 -1
  229. package/dist/util/brand.js.map +1 -1
  230. package/dist/util/brandedMap.d.ts.map +1 -1
  231. package/dist/util/brandedMap.js.map +1 -1
  232. package/dist/util/breakable.d.ts.map +1 -1
  233. package/dist/util/breakable.js +2 -1
  234. package/dist/util/breakable.js.map +1 -1
  235. package/dist/util/index.d.ts +2 -2
  236. package/dist/util/index.d.ts.map +1 -1
  237. package/dist/util/index.js +6 -3
  238. package/dist/util/index.js.map +1 -1
  239. package/dist/util/opaque.d.ts.map +1 -1
  240. package/dist/util/opaque.js.map +1 -1
  241. package/dist/util/rangeMap.d.ts +3 -2
  242. package/dist/util/rangeMap.d.ts.map +1 -1
  243. package/dist/util/rangeMap.js +7 -1
  244. package/dist/util/rangeMap.js.map +1 -1
  245. package/dist/util/readSnapshotBlob.d.ts +1 -1
  246. package/dist/util/readSnapshotBlob.d.ts.map +1 -1
  247. package/dist/util/readSnapshotBlob.js.map +1 -1
  248. package/dist/util/typeCheck.d.ts.map +1 -1
  249. package/dist/util/typeCheck.js.map +1 -1
  250. package/dist/util/utils.d.ts +20 -16
  251. package/dist/util/utils.d.ts.map +1 -1
  252. package/dist/util/utils.js +49 -17
  253. package/dist/util/utils.js.map +1 -1
  254. package/eslint.config.mts +0 -9
  255. package/lib/alpha.d.ts +8 -2
  256. package/lib/beta.d.ts +3 -0
  257. package/lib/codec/codec.d.ts +17 -8
  258. package/lib/codec/codec.d.ts.map +1 -1
  259. package/lib/codec/codec.js +6 -0
  260. package/lib/codec/codec.js.map +1 -1
  261. package/lib/codec/index.d.ts +1 -1
  262. package/lib/codec/index.d.ts.map +1 -1
  263. package/lib/codec/index.js +1 -1
  264. package/lib/codec/index.js.map +1 -1
  265. package/lib/codec/versioned/codec.d.ts +1 -1
  266. package/lib/codec/versioned/codec.d.ts.map +1 -1
  267. package/lib/codec/versioned/codec.js.map +1 -1
  268. package/lib/core/index.d.ts +1 -1
  269. package/lib/core/index.d.ts.map +1 -1
  270. package/lib/core/index.js +1 -1
  271. package/lib/core/index.js.map +1 -1
  272. package/lib/core/rebase/changeRebaser.d.ts +3 -2
  273. package/lib/core/rebase/changeRebaser.d.ts.map +1 -1
  274. package/lib/core/rebase/changeRebaser.js.map +1 -1
  275. package/lib/core/rebase/index.d.ts +1 -1
  276. package/lib/core/rebase/index.d.ts.map +1 -1
  277. package/lib/core/rebase/index.js +1 -1
  278. package/lib/core/rebase/index.js.map +1 -1
  279. package/lib/core/rebase/types.d.ts +23 -3
  280. package/lib/core/rebase/types.d.ts.map +1 -1
  281. package/lib/core/rebase/types.js +27 -15
  282. package/lib/core/rebase/types.js.map +1 -1
  283. package/lib/core/schema-stored/formatV1.d.ts +2 -2
  284. package/lib/core/schema-stored/formatV1.d.ts.map +1 -1
  285. package/lib/core/schema-stored/formatV1.js +0 -5
  286. package/lib/core/schema-stored/formatV1.js.map +1 -1
  287. package/lib/core/schema-stored/formatV2.d.ts +11 -10
  288. package/lib/core/schema-stored/formatV2.d.ts.map +1 -1
  289. package/lib/core/schema-stored/formatV2.js +1 -6
  290. package/lib/core/schema-stored/formatV2.js.map +1 -1
  291. package/lib/core/schema-stored/index.d.ts.map +1 -1
  292. package/lib/core/schema-stored/index.js +2 -0
  293. package/lib/core/schema-stored/index.js.map +1 -1
  294. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  295. package/lib/core/schema-stored/schema.js.map +1 -1
  296. package/lib/core/tree/anchorSet.d.ts.map +1 -1
  297. package/lib/core/tree/anchorSet.js.map +1 -1
  298. package/lib/core/tree/delta.d.ts +9 -7
  299. package/lib/core/tree/delta.d.ts.map +1 -1
  300. package/lib/core/tree/delta.js.map +1 -1
  301. package/lib/core/tree/deltaUtil.js +1 -1
  302. package/lib/core/tree/deltaUtil.js.map +1 -1
  303. package/lib/core/tree/visitDelta.js +2 -2
  304. package/lib/core/tree/visitDelta.js.map +1 -1
  305. package/lib/extensibleSchemaUnion.d.ts +72 -0
  306. package/lib/extensibleSchemaUnion.d.ts.map +1 -0
  307. package/lib/extensibleSchemaUnion.js +76 -0
  308. package/lib/extensibleSchemaUnion.js.map +1 -0
  309. package/lib/feature-libraries/changeAtomIdBTree.d.ts +4 -2
  310. package/lib/feature-libraries/changeAtomIdBTree.d.ts.map +1 -1
  311. package/lib/feature-libraries/changeAtomIdBTree.js +7 -0
  312. package/lib/feature-libraries/changeAtomIdBTree.js.map +1 -1
  313. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts +1 -3
  314. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  315. package/lib/feature-libraries/default-schema/defaultFieldKinds.js +4 -5
  316. package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  317. package/lib/feature-libraries/default-schema/index.d.ts +1 -1
  318. package/lib/feature-libraries/default-schema/index.d.ts.map +1 -1
  319. package/lib/feature-libraries/default-schema/index.js.map +1 -1
  320. package/lib/feature-libraries/forest-summary/codec.d.ts +2 -1
  321. package/lib/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  322. package/lib/feature-libraries/forest-summary/codec.js.map +1 -1
  323. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  324. package/lib/feature-libraries/forest-summary/forestSummarizer.js +6 -3
  325. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  326. package/lib/feature-libraries/forest-summary/formatCommon.d.ts +1 -39
  327. package/lib/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -1
  328. package/lib/feature-libraries/forest-summary/formatCommon.js +2 -3
  329. package/lib/feature-libraries/forest-summary/formatCommon.js.map +1 -1
  330. package/lib/feature-libraries/forest-summary/formatV1.d.ts +1 -39
  331. package/lib/feature-libraries/forest-summary/formatV1.d.ts.map +1 -1
  332. package/lib/feature-libraries/forest-summary/formatV2.d.ts +1 -39
  333. package/lib/feature-libraries/forest-summary/formatV2.d.ts.map +1 -1
  334. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +1 -1
  335. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  336. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js +1 -1
  337. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  338. package/lib/feature-libraries/index.d.ts +3 -3
  339. package/lib/feature-libraries/index.d.ts.map +1 -1
  340. package/lib/feature-libraries/index.js +3 -3
  341. package/lib/feature-libraries/index.js.map +1 -1
  342. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts +2 -2
  343. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts.map +1 -1
  344. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.js +41 -21
  345. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.js.map +1 -1
  346. package/lib/feature-libraries/modular-schema/genericFieldKind.js +1 -1
  347. package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  348. package/lib/feature-libraries/modular-schema/index.d.ts +1 -1
  349. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  350. package/lib/feature-libraries/modular-schema/index.js +1 -1
  351. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  352. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +1 -1
  353. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
  354. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js +10 -6
  355. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
  356. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts +11 -1
  357. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  358. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +29 -6
  359. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  360. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  361. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +41 -30
  362. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  363. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.d.ts +10 -127
  364. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.d.ts.map +1 -1
  365. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.js +2 -4
  366. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.js.map +1 -1
  367. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.d.ts +3 -79
  368. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.d.ts.map +1 -1
  369. package/lib/feature-libraries/optional-field/optionalField.js +1 -1
  370. package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
  371. package/lib/feature-libraries/optional-field/requiredField.d.ts.map +1 -1
  372. package/lib/feature-libraries/optional-field/requiredField.js.map +1 -1
  373. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -2
  374. package/lib/feature-libraries/schema-index/codec.js.map +1 -1
  375. package/lib/feature-libraries/schema-index/formatV2.d.ts +4 -4
  376. package/lib/feature-libraries/schema-index/schemaSummarizer.js +1 -1
  377. package/lib/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  378. package/lib/feature-libraries/sequence-field/invert.js +2 -2
  379. package/lib/feature-libraries/sequence-field/invert.js.map +1 -1
  380. package/lib/feature-libraries/sequence-field/replaceRevisions.js +16 -16
  381. package/lib/feature-libraries/sequence-field/replaceRevisions.js.map +1 -1
  382. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js +1 -1
  383. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  384. package/lib/index.d.ts +5 -5
  385. package/lib/index.d.ts.map +1 -1
  386. package/lib/index.js +4 -3
  387. package/lib/index.js.map +1 -1
  388. package/lib/legacy.d.ts +3 -0
  389. package/lib/packageVersion.d.ts +1 -1
  390. package/lib/packageVersion.js +1 -1
  391. package/lib/packageVersion.js.map +1 -1
  392. package/lib/shared-tree/independentView.d.ts +36 -13
  393. package/lib/shared-tree/independentView.d.ts.map +1 -1
  394. package/lib/shared-tree/independentView.js +1 -0
  395. package/lib/shared-tree/independentView.js.map +1 -1
  396. package/lib/shared-tree/index.d.ts +1 -1
  397. package/lib/shared-tree/index.d.ts.map +1 -1
  398. package/lib/shared-tree/index.js.map +1 -1
  399. package/lib/shared-tree/schematizingTreeView.d.ts +10 -0
  400. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  401. package/lib/shared-tree/schematizingTreeView.js +25 -9
  402. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  403. package/lib/shared-tree/sharedTree.d.ts +3 -3
  404. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  405. package/lib/shared-tree/sharedTree.js +10 -34
  406. package/lib/shared-tree/sharedTree.js.map +1 -1
  407. package/lib/shared-tree/sharedTreeChangeCodecs.d.ts +11 -3
  408. package/lib/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
  409. package/lib/shared-tree/sharedTreeChangeCodecs.js +39 -5
  410. package/lib/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  411. package/lib/shared-tree/sharedTreeChangeFormat.d.ts +4 -4
  412. package/lib/shared-tree/tree.js +1 -1
  413. package/lib/shared-tree/tree.js.map +1 -1
  414. package/lib/shared-tree/treeCheckout.d.ts +20 -0
  415. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  416. package/lib/shared-tree/treeCheckout.js +39 -3
  417. package/lib/shared-tree/treeCheckout.js.map +1 -1
  418. package/lib/shared-tree-core/editManagerSummarizer.js +1 -1
  419. package/lib/shared-tree-core/editManagerSummarizer.js.map +1 -1
  420. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  421. package/lib/shared-tree-core/messageCodecV1ToV4.js +2 -2
  422. package/lib/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  423. package/lib/shared-tree-core/transaction.d.ts +14 -3
  424. package/lib/shared-tree-core/transaction.d.ts.map +1 -1
  425. package/lib/shared-tree-core/transaction.js +61 -18
  426. package/lib/shared-tree-core/transaction.js.map +1 -1
  427. package/lib/shared-tree-core/versionedSummarizer.d.ts.map +1 -1
  428. package/lib/shared-tree-core/versionedSummarizer.js +1 -1
  429. package/lib/shared-tree-core/versionedSummarizer.js.map +1 -1
  430. package/lib/simple-tree/api/index.d.ts +1 -1
  431. package/lib/simple-tree/api/index.d.ts.map +1 -1
  432. package/lib/simple-tree/api/index.js +1 -1
  433. package/lib/simple-tree/api/index.js.map +1 -1
  434. package/lib/simple-tree/api/schemaCreationUtilities.d.ts +9 -0
  435. package/lib/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  436. package/lib/simple-tree/api/schemaCreationUtilities.js +14 -0
  437. package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  438. package/lib/simple-tree/api/simpleTreeIndex.js.map +1 -1
  439. package/lib/simple-tree/api/transactionTypes.d.ts +10 -0
  440. package/lib/simple-tree/api/transactionTypes.d.ts.map +1 -1
  441. package/lib/simple-tree/api/transactionTypes.js.map +1 -1
  442. package/lib/simple-tree/api/tree.d.ts +81 -6
  443. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  444. package/lib/simple-tree/api/tree.js.map +1 -1
  445. package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  446. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  447. package/lib/simple-tree/index.d.ts +2 -2
  448. package/lib/simple-tree/index.d.ts.map +1 -1
  449. package/lib/simple-tree/index.js +2 -2
  450. package/lib/simple-tree/index.js.map +1 -1
  451. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  452. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  453. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts +63 -0
  454. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  455. package/lib/simple-tree/node-kinds/array/arrayNode.js +41 -0
  456. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  457. package/lib/simple-tree/node-kinds/array/index.d.ts +1 -1
  458. package/lib/simple-tree/node-kinds/array/index.d.ts.map +1 -1
  459. package/lib/simple-tree/node-kinds/array/index.js +1 -1
  460. package/lib/simple-tree/node-kinds/array/index.js.map +1 -1
  461. package/lib/simple-tree/node-kinds/index.d.ts +1 -1
  462. package/lib/simple-tree/node-kinds/index.d.ts.map +1 -1
  463. package/lib/simple-tree/node-kinds/index.js +1 -1
  464. package/lib/simple-tree/node-kinds/index.js.map +1 -1
  465. package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  466. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  467. package/lib/tableSchema.d.ts +71 -48
  468. package/lib/tableSchema.d.ts.map +1 -1
  469. package/lib/tableSchema.js +201 -99
  470. package/lib/tableSchema.js.map +1 -1
  471. package/lib/text/textDomainFormatted.js +1 -1
  472. package/lib/text/textDomainFormatted.js.map +1 -1
  473. package/lib/util/bTreeUtils.d.ts +30 -4
  474. package/lib/util/bTreeUtils.d.ts.map +1 -1
  475. package/lib/util/bTreeUtils.js +27 -16
  476. package/lib/util/bTreeUtils.js.map +1 -1
  477. package/lib/util/brand.d.ts.map +1 -1
  478. package/lib/util/brand.js.map +1 -1
  479. package/lib/util/brandedMap.d.ts.map +1 -1
  480. package/lib/util/brandedMap.js.map +1 -1
  481. package/lib/util/breakable.d.ts.map +1 -1
  482. package/lib/util/breakable.js +2 -1
  483. package/lib/util/breakable.js.map +1 -1
  484. package/lib/util/index.d.ts +2 -2
  485. package/lib/util/index.d.ts.map +1 -1
  486. package/lib/util/index.js +2 -2
  487. package/lib/util/index.js.map +1 -1
  488. package/lib/util/opaque.d.ts.map +1 -1
  489. package/lib/util/opaque.js.map +1 -1
  490. package/lib/util/rangeMap.d.ts +3 -2
  491. package/lib/util/rangeMap.d.ts.map +1 -1
  492. package/lib/util/rangeMap.js +7 -1
  493. package/lib/util/rangeMap.js.map +1 -1
  494. package/lib/util/readSnapshotBlob.d.ts +1 -1
  495. package/lib/util/readSnapshotBlob.d.ts.map +1 -1
  496. package/lib/util/readSnapshotBlob.js.map +1 -1
  497. package/lib/util/typeCheck.d.ts.map +1 -1
  498. package/lib/util/typeCheck.js.map +1 -1
  499. package/lib/util/utils.d.ts +20 -16
  500. package/lib/util/utils.d.ts.map +1 -1
  501. package/lib/util/utils.js +44 -15
  502. package/lib/util/utils.js.map +1 -1
  503. package/package.json +22 -22
  504. package/src/codec/codec.ts +30 -11
  505. package/src/codec/index.ts +2 -0
  506. package/src/codec/versioned/codec.ts +9 -13
  507. package/src/core/index.ts +3 -1
  508. package/src/core/rebase/changeRebaser.ts +3 -2
  509. package/src/core/rebase/index.ts +3 -1
  510. package/src/core/rebase/types.ts +51 -13
  511. package/src/core/schema-stored/formatV1.ts +2 -4
  512. package/src/core/schema-stored/formatV2.ts +9 -7
  513. package/src/core/schema-stored/index.ts +2 -0
  514. package/src/core/schema-stored/schema.ts +4 -1
  515. package/src/core/tree/anchorSet.ts +1 -3
  516. package/src/core/tree/delta.ts +9 -7
  517. package/src/core/tree/deltaUtil.ts +1 -1
  518. package/src/core/tree/visitDelta.ts +2 -2
  519. package/src/extensibleSchemaUnion.ts +135 -0
  520. package/src/feature-libraries/changeAtomIdBTree.ts +17 -2
  521. package/src/feature-libraries/default-schema/defaultFieldKinds.ts +5 -6
  522. package/src/feature-libraries/default-schema/index.ts +0 -1
  523. package/src/feature-libraries/forest-summary/codec.ts +7 -2
  524. package/src/feature-libraries/forest-summary/forestSummarizer.ts +15 -3
  525. package/src/feature-libraries/forest-summary/formatCommon.ts +2 -3
  526. package/src/feature-libraries/forest-summary/incrementalSummaryBuilder.ts +4 -5
  527. package/src/feature-libraries/index.ts +3 -2
  528. package/src/feature-libraries/modular-schema/defaultRevisionReplacer.ts +57 -31
  529. package/src/feature-libraries/modular-schema/genericFieldKind.ts +1 -1
  530. package/src/feature-libraries/modular-schema/index.ts +4 -1
  531. package/src/feature-libraries/modular-schema/modularChangeCodecV1.ts +7 -6
  532. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +32 -7
  533. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +54 -33
  534. package/src/feature-libraries/modular-schema/modularChangeFormatV1.ts +2 -4
  535. package/src/feature-libraries/optional-field/optionalField.ts +1 -1
  536. package/src/feature-libraries/optional-field/requiredField.ts +2 -4
  537. package/src/feature-libraries/schema-index/codec.ts +1 -1
  538. package/src/feature-libraries/schema-index/schemaSummarizer.ts +1 -1
  539. package/src/feature-libraries/sequence-field/invert.ts +2 -2
  540. package/src/feature-libraries/sequence-field/replaceRevisions.ts +17 -10
  541. package/src/feature-libraries/sequence-field/sequenceFieldToDelta.ts +1 -1
  542. package/src/index.ts +12 -7
  543. package/src/packageVersion.ts +1 -1
  544. package/src/shared-tree/independentView.ts +42 -6
  545. package/src/shared-tree/index.ts +2 -0
  546. package/src/shared-tree/schematizingTreeView.ts +63 -18
  547. package/src/shared-tree/sharedTree.ts +19 -37
  548. package/src/shared-tree/sharedTreeChangeCodecs.ts +43 -9
  549. package/src/shared-tree/tree.ts +1 -1
  550. package/src/shared-tree/treeCheckout.ts +50 -3
  551. package/src/shared-tree-core/editManagerSummarizer.ts +1 -1
  552. package/src/shared-tree-core/messageCodecV1ToV4.ts +4 -3
  553. package/src/shared-tree-core/transaction.ts +125 -23
  554. package/src/shared-tree-core/versionedSummarizer.ts +3 -2
  555. package/src/simple-tree/api/index.ts +1 -0
  556. package/src/simple-tree/api/schemaCreationUtilities.ts +35 -5
  557. package/src/simple-tree/api/simpleTreeIndex.ts +1 -1
  558. package/src/simple-tree/api/transactionTypes.ts +10 -0
  559. package/src/simple-tree/api/tree.ts +88 -6
  560. package/src/simple-tree/core/treeNodeSchema.ts +5 -8
  561. package/src/simple-tree/index.ts +3 -0
  562. package/src/simple-tree/leafNodeSchema.ts +3 -2
  563. package/src/simple-tree/node-kinds/array/arrayNode.ts +86 -0
  564. package/src/simple-tree/node-kinds/array/index.ts +2 -0
  565. package/src/simple-tree/node-kinds/index.ts +2 -0
  566. package/src/simple-tree/node-kinds/object/objectNode.ts +19 -18
  567. package/src/tableSchema.ts +280 -140
  568. package/src/text/textDomainFormatted.ts +1 -1
  569. package/src/util/bTreeUtils.ts +45 -26
  570. package/src/util/brand.ts +4 -12
  571. package/src/util/brandedMap.ts +2 -6
  572. package/src/util/breakable.ts +3 -2
  573. package/src/util/index.ts +9 -3
  574. package/src/util/opaque.ts +2 -6
  575. package/src/util/rangeMap.ts +11 -5
  576. package/src/util/readSnapshotBlob.ts +3 -3
  577. package/src/util/typeCheck.ts +11 -9
  578. package/src/util/utils.ts +57 -28
  579. package/biome.jsonc +0 -4
@@ -1 +1 @@
1
- {"version":3,"file":"anchorSet.js","sourceRoot":"","sources":["../../../src/core/tree/anchorSet.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;AAEH,6DAA6D;AAE7D,+DAA6D;AAE7D,kEAAmE;AAEnE,kDAU6B;AAK7B,iDAAgD;AAChD,+CAOuB;AACvB,yCAAsC;AAStC;;GAEG;AACH,MAAM,WAAW,GAAW,IAAA,gBAAK,EAAC,CAAC,CAAC,CAAC;AA+MrC;;;;;;;;;;;;;;GAcG;AACH,SAAgB,UAAU;IACzB,OAAO,IAAA,sBAAW,GAAwB,CAAC;AAC5C,CAAC;AAFD,gCAEC;AAED;;;;;;;;;;GAUG;AACH,MAAa,SAAS;IAoCrB;QAnCS,4BAAU,IAAA,4BAAa,GAAuB,EAAC;QACxC,WAAM,GAAoC,uBAAA,IAAI,yBAAQ,CAAC;QAEvE;;;WAGG;QACK,kBAAa,GAAG,CAAC,CAAC;QAE1B;;;;WAIG;QACI,qBAAgB,GAAG,CAAC,CAAC;QAE5B;;;;;;;;;;WAUG;QACc,SAAI,GAAG,IAAI,QAAQ,CAAC,I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,GAAG,GAAG,CAAC,CAAC,CAAC,gCAAgC;QAChD,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC,CAAC,qEAAqE;AACxF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { HasListeners, Listenable } from \"@fluidframework/core-interfaces/internal\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\ttype Brand,\n\ttype BrandedKey,\n\ttype BrandedMapSubset,\n\ttype Opaque,\n\tReferenceCountedBase,\n\tbrand,\n\tbrandedSlot,\n\tgetOrAddEmptyToMap,\n\tgetOrCreate,\n} from \"../../util/index.js\";\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport type { ITreeCursorSynchronous } from \"./cursor.js\";\nimport type * as Delta from \"./delta.js\";\nimport { offsetDetachId } from \"./deltaUtil.js\";\nimport {\n\tisDetachedUpPathRoot,\n\ttype INormalizedUpPath,\n\ttype NormalizedUpPath,\n\ttype PlaceIndex,\n\ttype Range,\n\ttype UpPath,\n} from \"./pathTree.js\";\nimport { EmptyKey } from \"./types.js\";\nimport type { DeltaVisitor } from \"./visitDelta.js\";\n\n/**\n * A way to refer to a particular tree location within an {@link AnchorSet}.\n * Associated with a ref count on the underlying {@link AnchorNode}.\n */\nexport type Anchor = Brand<number, \"rebaser.Anchor\">;\n\n/**\n * A singleton which represents a permanently invalid location (i.e. there is never a node there)\n */\nconst NeverAnchor: Anchor = brand(0);\n\n/**\n * Maps anchors (which must be ones this locator knows about) to paths.\n */\nexport interface AnchorLocator {\n\t/**\n\t * Get the current location of an Anchor.\n\t * The returned value should not be used after an edit has occurred.\n\t *\n\t * TODO: support extra/custom return types for specific/custom anchor types:\n\t * for now caller must rely on data in anchor + returned node location\n\t * (not ideal for anchors for places or ranges instead of nodes).\n\t */\n\tlocate(anchor: Anchor): AnchorNode | undefined;\n}\n\n/**\n * Stores arbitrary, user-defined data on an {@link Anchor}.\n * This data is preserved over the course of that anchor's lifetime.\n * @see {@link anchorSlot} for creation and an example use case.\n */\nexport type AnchorSlot<TContent> = BrandedKey<Opaque<Brand<number, \"AnchorSlot\">>, TContent>;\n\n/**\n * Events for {@link AnchorNode}.\n * These events are triggered while the internal data structures are being updated.\n * Thus these events must not trigger reading of the anchorSet or forest.\n *\n * TODO:\n * - Include sub-deltas in events.\n * - Add more events.\n */\nexport interface AnchorEvents {\n\t/**\n\t * When the anchor node will never get reused by its AnchorSet.\n\t * This means that the content it corresponds to has been permanently destroyed.\n\t *\n\t * @remarks\n\t * When this happens depends entirely on how the anchorSet is used.\n\t * It's possible nodes removed from the tree will be kept indefinitely, and thus never trigger this event, or they may be discarded immediately.\n\t *\n\t * @privateRemarks\n\t * The specifics of the delta visit algorithm can impact the behavior of these events.\n\t * Refer to the privateRemarks of specific events and/or the documentation of the delta visit algorithm (as of\n\t * 2024-04-02, src/core/tree/visitDelta.ts) for more information.\n\t */\n\tafterDestroy(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if one or more of this node's\n\t * direct children are about to change due to updates from the batch.\n\t *\n\t * @remarks\n\t * Does not include edits of child subtrees: instead only includes changes to nodes which are direct children in this\n\t * node's fields.\n\t */\n\tchildrenChanging(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if one or more of this node's\n\t * direct children just changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * Does not include edits of child subtrees: instead only includes changes to nodes which are direct children in this\n\t * node's fields.\n\t *\n\t * Compare to {@link AnchorEvents.childrenChangedAfterBatch} which is emitted after the whole batch has been applied.\n\t */\n\tchildrenChanged(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted after a batch of changes has been applied (i.e. when a delta visit completes), if one or more of this node's\n\t * direct children changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * Does not include edits of child subtrees: instead only includes changes to nodes which are direct children in this\n\t * node's fields.\n\t *\n\t * This event is guaranteed to be emitted on a given node only once per batch.\n\t *\n\t * Compare to {@link AnchorEvents.childrenChanged} which is emitted in the middle of the batch/delta-visit.\n\t */\n\tchildrenChangedAfterBatch(arg: {\n\t\tchangedFields: ReadonlySet<FieldKey>;\n\t}): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if something in the subtree\n\t * rooted at `anchor` _may_ be about to change due to updates from the batch.\n\t *\n\t * @remarks\n\t * Called on every parent (transitively) when a change is occurring.\n\t */\n\tsubtreeChanging(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if something in the subtree\n\t * rooted at `anchor` _may_ have just changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * While this event is always emitted in the presence of changes to the subtree,\n\t * it may also be emitted even though no changes have been made to the subtree.\n\t * It may be emitted multiple times within the application of a single edit or transaction.\n\t *\n\t * If this event is emitted by a node, it will later be emitted by all its ancestors up to the root as well, at\n\t * least once on each ancestor.\n\t *\n\t * Compare to {@link AnchorEvents.subtreeChangedAfterBatch} which is emitted after the whole batch has been applied.\n\t *\n\t * @privateRemarks\n\t * The delta visit algorithm is complicated and it may fire this event multiple times for the same change to a node.\n\t * The change to the tree may not be visible until the event fires for the last time.\n\t * Refer to the documentation of the delta visit algorithm for more details.\n\t */\n\tsubtreeChanged(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted after a batch of changes has been applied (i.e. when a delta visit completes), if something in the subtree\n\t * rooted at `anchor` changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * If this event is emitted by a node, it will later be emitted by all its ancestors up to the root as well, from bottom to top.\n\t *\n\t * This event is guaranteed to be emitted on a given node only once per batch.\n\t *\n\t * Compare to {@link AnchorEvents.subtreeChanged} which is emitted in the middle of the batch/delta-visit.\n\t *\n\t * @privateRemarks\n\t * Note that because this is fired after the full batch of changes is applied, it guarantees that something in the\n\t * subtree changed, compared to {@link AnchorEvents.subtreeChanged} or {@link AnchorEvents.subtreeChanging} which\n\t * fire when something _may_ have changed or _may_ be about to change.\n\t */\n\tsubtreeChangedAfterBatch(): void;\n}\n\n/**\n * Events for {@link AnchorSet}.\n * These events are triggered while the internal data structures are being updated.\n * Thus these events must not trigger reading of the anchorSet or forest.\n *\n * TODO:\n * - Design how events should be ordered.\n * - Include sub-deltas in events.\n * - Add more events.\n */\nexport interface AnchorSetRootEvents {\n\t/**\n\t * What children are at the root is changing.\n\t */\n\tchildrenChanging(anchors: AnchorSet): void;\n\n\t/**\n\t * Something in the tree is changing.\n\t */\n\ttreeChanging(anchors: AnchorSet): void;\n}\n\n/**\n * Node in a tree of anchors.\n */\nexport interface AnchorNode extends INormalizedUpPath<AnchorNode> {\n\t/**\n\t * Events for this anchor node.\n\t */\n\treadonly events: Listenable<AnchorEvents> & HasListeners<AnchorEvents>;\n\n\t/**\n\t * Allows access to data stored on the Anchor in \"slots\".\n\t * Use {@link anchorSlot} to create slots.\n\t */\n\t// See note on BrandedKey\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\treadonly slots: BrandedMapSubset<AnchorSlot<any>>;\n\n\t/**\n\t * The set this anchor node is part of.\n\t */\n\treadonly anchorSet: AnchorSet;\n\n\t/**\n\t * Gets a child of this node.\n\t *\n\t * @remarks\n\t * This does not return an AnchorNode since there might not be one, and lazily creating one here would have messy lifetime management (See {@link AnchorNode#getOrCreateChildRef})\n\t * If an AnchorNode is required, use the AnchorSet to track then locate the returned path.\n\t * TODO:\n\t * Revisit this API.\n\t * Perhaps if we use weak down pointers and remove ref counting, we can make this return a AnchorNode.\n\t *\n\t */\n\tchild(key: FieldKey, index: number): UpPath<AnchorNode>;\n\n\t/**\n\t * Gets the child AnchorNode if already exists.\n\t *\n\t * Does NOT add a ref, so the returned AnchorNode must be used with care.\n\t */\n\tchildIfAnchored(key: FieldKey, index: number): AnchorNode | undefined;\n\n\t/**\n\t * Gets a child AnchorNode (creating it if needed), and an Anchor owning a ref to it.\n\t * Caller is responsible for freeing the returned Anchor, and must not use the AnchorNode after that.\n\t */\n\tgetOrCreateChildRef(key: FieldKey, index: number): [Anchor, AnchorNode];\n}\n\n/**\n * Define a strongly typed slot on anchors in which data can be stored.\n *\n * @remarks\n * This is mainly useful for caching data associated with a location in the tree.\n *\n * Example usage:\n * ```typescript\n * const counterSlot = anchorSlot<number>();\n *\n * function useSlot(anchor: AnchorNode): void {\n * \tanchor.slots.set(counterSlot, 1 + anchor.slots.get(counterSlot) ?? 0);\n * }\n * ```\n */\nexport function anchorSlot<TContent>(): AnchorSlot<TContent> {\n\treturn brandedSlot<AnchorSlot<TContent>>();\n}\n\n/**\n * Collection of Anchors at a specific revision.\n *\n * See `Rebaser` for how to update across revisions.\n *\n * TODO: this should not be package exported.\n * If it's needed outside the package an Interface should be used instead which can reduce its\n * API surface to a small subset.\n *\n * @sealed\n */\nexport class AnchorSet implements AnchorLocator {\n\treadonly #events = createEmitter<AnchorSetRootEvents>();\n\tpublic readonly events: Listenable<AnchorSetRootEvents> = this.#events;\n\n\t/**\n\t * Incrementing counter to give each anchor in this set a unique index for its identifier.\n\t * \"0\" is reserved for the `NeverAnchor`.\n\t */\n\tprivate anchorCounter = 1;\n\n\t/**\n\t * Incrementing number that is bumped each time that the {@link AnchorSet} is changed.\n\t * This allows consumers to cache state associated with a particular generation number and later determine if that state may have been invalidated using a comparison with the current generation number.\n\t * For example, anchor slots can be used to cache the removal status of a node to memoize repeated walks up the tree.\n\t */\n\tpublic generationNumber = 0;\n\n\t/**\n\t * Special root node under which all anchors in this anchor set are transitively parented.\n\t * This does not appear in the UpPaths (instead they use undefined for the root).\n\t * Immediate children of this root are in detached fields (which have their identifiers used as the field keys).\n\t *\n\t * This is allocated with refCount one, which is never freed so it is never cleaned up\n\t * (as long as this AnchorSet is not garbage collected).\n\t *\n\t * There should never be any children other than the special root detached field under this between transactions:\n\t * TODO: check for and enforce this.\n\t */\n\tprivate readonly root = new PathNode(this, EmptyKey, 0, undefined);\n\n\t// TODO: anchor system could be optimized a bit to avoid the maps (Anchor is ref to Path, path has ref count).\n\t// For now use this more encapsulated approach with maps.\n\tprivate readonly anchorToPath: Map<Anchor, PathNode> = new Map();\n\n\tprivate activeVisitor?: DeltaVisitor;\n\n\tpublic constructor() {\n\t\tthis.events.on(\"treeChanging\", () => {\n\t\t\tthis.generationNumber += 1;\n\t\t});\n\t}\n\n\t/**\n\t * Allows access to data stored on the AnchorSet in \"slots\".\n\t * Use {@link anchorSlot} to create slots.\n\t *\n\t * @privateRemarks\n\t * This forwards to the slots of the special above root anchor which locate can't access.\n\t */\n\t// See note on BrandedKey.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic get slots(): BrandedMapSubset<AnchorSlot<any>> {\n\t\treturn this.root.slots;\n\t}\n\n\tpublic *[Symbol.iterator](): IterableIterator<AnchorNode> {\n\t\tconst stack: PathNode[] = [];\n\t\tlet node: PathNode | undefined = this.root;\n\t\twhile (node !== undefined) {\n\t\t\tyield node;\n\t\t\tfor (const [_, children] of node.children) {\n\t\t\t\tfor (const child of children) {\n\t\t\t\t\tstack.push(child);\n\t\t\t\t}\n\t\t\t}\n\t\t\tnode = stack.pop();\n\t\t}\n\t}\n\n\t/**\n\t * Check if there are currently no anchors tracked.\n\t * Mainly for testing anchor cleanup.\n\t */\n\tpublic isEmpty(): boolean {\n\t\treturn this.root.children.size === 0;\n\t}\n\n\tpublic locate(anchor: Anchor): AnchorNode | undefined {\n\t\tif (anchor === NeverAnchor) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst path = this.anchorToPath.get(anchor);\n\t\tassert(\n\t\t\tpath !== undefined,\n\t\t\t0x3a6 /* Cannot locate anchor which is not in this AnchorSet */,\n\t\t);\n\t\treturn path.status === Status.Alive ? path : undefined;\n\t}\n\n\tpublic forget(anchor: Anchor): void {\n\t\tif (anchor !== NeverAnchor) {\n\t\t\tconst path = this.anchorToPath.get(anchor);\n\t\t\tassert(path !== undefined, 0x351 /* cannot forget unknown Anchor */);\n\t\t\tpath.removeRef();\n\t\t\tthis.anchorToPath.delete(anchor);\n\t\t}\n\t}\n\n\t/**\n\t * TODO: Add APIs need to allow callers of this function to reduce copying here.\n\t * Ex: maybe return something extending UpPath here.\n\t * @param path - the path to the node to be tracked. If null, returns an anchor\n\t * which is permanently invalid.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic track(path: UpPath | null): Anchor {\n\t\tif (path === null) {\n\t\t\treturn NeverAnchor;\n\t\t}\n\n\t\tconst foundPath = this.trackInner(path);\n\t\tconst anchor: Anchor = brand(this.anchorCounter++);\n\t\tthis.anchorToPath.set(anchor, foundPath);\n\t\treturn anchor;\n\t}\n\n\t/**\n\t * Finds a path node, creating if needed, and adds a ref count to it.\n\t */\n\tprivate trackInner(path: UpPath): PathNode {\n\t\tif (path instanceof PathNode && path.anchorSet === this) {\n\t\t\tpath.addRef();\n\t\t\treturn path;\n\t\t}\n\t\tconst parent = path.parent ?? this.root;\n\t\tconst parentPath = this.trackInner(parent);\n\n\t\tconst child = parentPath.getOrCreateChild(path.parentField, path.parentIndex);\n\n\t\t// Now that child is added (if needed), remove the extra ref that we added in the recursive call.\n\t\tparentPath.removeRef();\n\n\t\treturn child;\n\t}\n\n\t/**\n\t * Finds a path node if it already exists.\n\t *\n\t * Does not add a ref!\n\t */\n\tpublic find(path: UpPath): PathNode | undefined {\n\t\tif (path instanceof PathNode && path.anchorSet === this) {\n\t\t\treturn path;\n\t\t}\n\t\tconst parent = path.parent ?? this.root;\n\t\tconst parentPath = this.find(parent);\n\t\treturn parentPath?.childIfAnchored(path.parentField, path.parentIndex);\n\t}\n\n\t/**\n\t * Returns an equivalent path making as much of it with PathNodes as possible.\n\t * This allows future operations (like find, track, locate) on this path (and derived ones) to be faster.\n\t * Note that the returned path may use AnchorNodes from this AnchorSet,\n\t * but does not have a tracked reference to them, so this should not be held onto across anything that might free an AnchorNode.\n\t *\n\t * @remarks\n\t * Also ensures that any PathNode in the path is from this AnchorSet.\n\t */\n\tpublic internalizePath(originalPath: UpPath): UpPath {\n\t\tlet path: UpPath | undefined = originalPath;\n\t\tconst stack: UpPath[] = [];\n\t\twhile (path !== undefined) {\n\t\t\tif (path instanceof PathNode && path.anchorSet === this) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tstack.push(path);\n\t\t\tpath = path.parent;\n\t\t}\n\n\t\t// Now `path` contains an internalized path.\n\t\t// It just needs the paths from stackOut to wrap it.\n\n\t\tlet wrapWith: UpPath | undefined;\n\t\twhile ((wrapWith = stack.pop()) !== undefined) {\n\t\t\tif (path === undefined || path instanceof PathNode) {\n\t\t\t\t// If path already has an anchor, get an anchor for it's child if there is one:\n\t\t\t\tconst child = (path ?? this.root).childIfAnchored(\n\t\t\t\t\twrapWith.parentField,\n\t\t\t\t\twrapWith.parentIndex,\n\t\t\t\t);\n\t\t\t\tif (child !== undefined) {\n\t\t\t\t\tpath = child;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Replacing this if with a ternary makes the documentation harder to include and hurts readability.\n\t\t\t// eslint-disable-next-line unicorn/prefer-ternary\n\t\t\tif (path === wrapWith.parent && !(wrapWith instanceof PathNode)) {\n\t\t\t\t// path is safe to reuse from input path, so use it to avoid allocating another object.\n\t\t\t\tpath = wrapWith;\n\t\t\t} else {\n\t\t\t\tpath = {\n\t\t\t\t\tparent: path,\n\t\t\t\t\tparentField: wrapWith.parentField,\n\t\t\t\t\tparentIndex: wrapWith.parentIndex,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn path ?? fail(0xaea /* internalize path must be a path */);\n\t}\n\n\t/**\n\t * Recursively marks the given `nodes` and their descendants as disposed and pointing to a deleted node.\n\t * Note that this does NOT detach the nodes.\n\t */\n\tprivate deepDelete(nodes: readonly PathNode[]): void {\n\t\tconst stack = [...nodes];\n\t\twhile (stack.length > 0) {\n\t\t\tconst node = stack.pop()!;\n\t\t\tassert(node.status === Status.Alive, 0x408 /* PathNode must be alive */);\n\t\t\tnode.status = Status.Dangling;\n\t\t\tnode.events.emit(\"afterDestroy\", node);\n\t\t\tfor (const children of node.children.values()) {\n\t\t\t\tstack.push(...children);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Decouple nodes from their parent.\n\t * This removes the reference from the parent to the decoupled children, and updates the indexes of the remaining children accordingly.\n\t * This does NOT update the decoupled children: both their index and parent are left at their existing values.\n\t * To decouple and fixup the children, see `removeChildren` and `moveChildren`.\n\t * @param startPath - The path to the first node that is being decoupled.\n\t * @param count - number of siblings that are decoupled from the original tree.\n\t *\n\t * TODO: tests\n\t */\n\tprivate decoupleNodes(startPath: UpPath, count: number): PathNode[] {\n\t\tassert(count > 0, 0x681 /* count must be positive */);\n\n\t\tconst sourceParent = this.find(startPath.parent ?? this.root);\n\t\tconst sourceChildren = sourceParent?.children?.get(startPath.parentField);\n\t\tlet nodes: PathNode[] = [];\n\n\t\tif (sourceChildren !== undefined) {\n\t\t\tlet numberBeforeDecouple = 0;\n\t\t\tlet numberToDecouple = 0;\n\t\t\tlet index = 0;\n\t\t\twhile (\n\t\t\t\tindex < sourceChildren.length &&\n\t\t\t\tsourceChildren[index]!.parentIndex < startPath.parentIndex\n\t\t\t) {\n\t\t\t\tnumberBeforeDecouple++;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\twhile (\n\t\t\t\tindex < sourceChildren.length &&\n\t\t\t\tsourceChildren[index]!.parentIndex < startPath.parentIndex + count\n\t\t\t) {\n\t\t\t\tnumberToDecouple++;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\twhile (index < sourceChildren.length) {\n\t\t\t\t// Fix indexes in source after moved items (subtract count).\n\t\t\t\tsourceChildren[index]!.parentIndex -= count;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\t// Sever the parent -> child connections\n\t\t\tnodes = sourceChildren.splice(numberBeforeDecouple, numberToDecouple);\n\t\t\tif (sourceChildren.length === 0) {\n\t\t\t\tsourceParent!.afterEmptyField(startPath.parentField);\n\t\t\t}\n\t\t}\n\n\t\treturn nodes;\n\t}\n\n\t/**\n\t * Couple nodes to a parent.\n\t * @param destination - where the siblings are coupled to.\n\t * @param count - number of siblings that are coupled in the original tree.\n\t * @param coupleInfo - this object contains the nodes to couple and the parent index of the first node that is coupled in the original tree.\n\t *\n\t * TODO: tests\n\t */\n\tprivate coupleNodes(\n\t\tdestination: UpPath,\n\t\tcount: number,\n\t\tcoupleInfo: { startParentIndex: number; nodes: PathNode[] },\n\t): void {\n\t\tassert(coupleInfo.nodes.length > 0, 0x682 /* coupleInfo must have nodes to couple */);\n\n\t\t// The destination needs to be created if it does not exist yet.\n\t\tconst destinationPath = this.trackInner(destination.parent ?? this.root);\n\n\t\t// Update nodes for new parent.\n\t\tfor (const node of coupleInfo.nodes) {\n\t\t\tnode.parentIndex += destination.parentIndex - coupleInfo.startParentIndex;\n\t\t\tnode.parentPath = destinationPath;\n\t\t\tnode.parentField = destination.parentField;\n\t\t\t// If the destination is a detached root, propagate its detachedNodeId, otherwise remove any existing one\n\t\t\tnode.detachedNodeId = isDetachedUpPathRoot(destination)\n\t\t\t\t? offsetDetachId(\n\t\t\t\t\t\tdestination.detachedNodeId,\n\t\t\t\t\t\tnode.parentIndex - destination.parentIndex,\n\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\t}\n\n\t\t// Update new parent to add children\n\t\tconst field = destinationPath.children.get(destination.parentField);\n\t\tif (field === undefined) {\n\t\t\tdestinationPath.children.set(destination.parentField, coupleInfo.nodes);\n\t\t} else {\n\t\t\t// Update existing field contents\n\t\t\tconst numberBeforeCouple = this.increaseParentIndexes(\n\t\t\t\tfield,\n\t\t\t\tdestination.parentIndex,\n\t\t\t\tcount,\n\t\t\t);\n\n\t\t\t// TODO: this will fail for very large numbers of anchors due to argument limits.\n\t\t\tfield.splice(numberBeforeCouple, 0, ...coupleInfo.nodes);\n\t\t}\n\n\t\tdestinationPath.removeRef();\n\t}\n\n\t/**\n\t * Updates the parent indexes within `field` to account for `count` children being inserted at `fromParentIndex`. Note that\n\t * `fromParentIndex` is the logical position within the field, not the index with the sparse PathNode array.\n\t *\n\t * @param field - the field to update.\n\t * @param fromParentIndex - the logical index within the field to start updating from.\n\t * @param count - the number to increase parent indexes.\n\t * @returns the number of items in the field that are not increased.\n\t *\n\t * TODO: tests\n\t */\n\tprivate increaseParentIndexes(\n\t\tfield: PathNode[],\n\t\tfromParentIndex: number,\n\t\tcount: number,\n\t): number {\n\t\tlet index = 0;\n\t\twhile (index < field.length && field[index]!.parentIndex < fromParentIndex) {\n\t\t\tindex++;\n\t\t}\n\t\tconst numberBeforeIncrease = index;\n\t\twhile (index < field.length) {\n\t\t\tfield[index]!.parentIndex += count;\n\t\t\tindex++;\n\t\t}\n\n\t\treturn numberBeforeIncrease;\n\t}\n\n\t/**\n\t * Updates paths for a range move (including re-parenting path items and updating indexes).\n\t * @param sourceStart - where the siblings are removed from.\n\t * @param destination - where the siblings are moved to.\n\t * @param count - number of siblings to move.\n\t *\n\t * TODO:\n\t * How should anchors that become invalid, then valid again (ex: into content that was deleted, then undone) work?\n\t * Add an API to resurrect them? Store them in special detached fields? Store them in special non-detached fields?\n\t *\n\t * TODO:\n\t * How should custom anchors work (ex: ones not just tied to a specific Node)?\n\t * This design assumes they can be expressed in terms of a Node anchor + some extra stuff,\n\t * but we don't have an API for the extra stuff yet.\n\t *\n\t * TODO: tests\n\t */\n\tprivate moveChildren(sourceStart: UpPath, destination: UpPath, count: number): void {\n\t\tconst nodes = this.decoupleNodes(sourceStart, count);\n\t\tif (nodes.length > 0) {\n\t\t\tthis.coupleNodes(destination, count, {\n\t\t\t\tstartParentIndex: sourceStart.parentIndex,\n\t\t\t\tnodes,\n\t\t\t});\n\t\t} else {\n\t\t\t// If there are no nodes to move, we still need to update the parent indexes of the nodes\n\t\t\t// affected in the move in.\n\t\t\tthis.offsetChildren(destination, count);\n\t\t}\n\t}\n\n\tprivate removeChildren(path: UpPath, count: number): void {\n\t\tconst nodes = this.decoupleNodes(path, count);\n\t\tthis.deepDelete(nodes);\n\t}\n\n\t/**\n\t * Updates the parent indexes of all the nodes located at right side of the given path by the given offset.\n\t * @param firstSiblingToOffset - the path to offset children of.\n\t * @param offset - the offset to apply to the children.\n\t *\n\t */\n\tprivate offsetChildren(firstSiblingToOffset: UpPath, offset: number): void {\n\t\tconst nodePath = this.find(firstSiblingToOffset.parent ?? this.root);\n\t\tconst field = nodePath?.children.get(firstSiblingToOffset.parentField);\n\t\tif (field !== undefined) {\n\t\t\tthis.increaseParentIndexes(field, firstSiblingToOffset.parentIndex, offset);\n\t\t}\n\t}\n\n\t/**\n\t * Provides a visitor that can be used to mutate this {@link AnchorSet}.\n\t *\n\t * @returns A visitor that can be used to mutate this {@link AnchorSet}.\n\t *\n\t * @remarks\n\t * Mutating the {@link AnchorSet} does NOT update the forest.\n\t * The visitor must be released after use by calling {@link DeltaVisitor.free} on it.\n\t * It is invalid to acquire a visitor without releasing the previous one,\n\t * and this method will throw an error if this is attempted.\n\t */\n\tpublic acquireVisitor(): DeltaVisitor {\n\t\tassert(\n\t\t\tthis.activeVisitor === undefined,\n\t\t\t0x767 /* Must release existing visitor before acquiring another */,\n\t\t);\n\n\t\tconst referencedPathNodes: PathNode[] = [];\n\t\tconst visitor = {\n\t\t\tanchorSet: this,\n\t\t\t// Run `withNode` on anchorNode for parent if there is such an anchorNode.\n\t\t\t// If at root, run `withRoot` instead.\n\t\t\tmaybeWithNode(withNode: (anchorNode: PathNode) => void, withRoot?: () => void) {\n\t\t\t\tif (this.parent === undefined && withRoot !== undefined) {\n\t\t\t\t\twithRoot();\n\t\t\t\t} else {\n\t\t\t\t\tassert(this.parent !== undefined, 0x5b0 /* parent must exist */);\n\t\t\t\t\t// TODO:Perf:\n\t\t\t\t\t// When traversing to a depth D when there are not anchors in that subtree, this goes O(D^2).\n\t\t\t\t\t// Delta traversal should early out in this case because no work is needed (and all move outs are known to not contain anchors).\n\t\t\t\t\tthis.parent = this.anchorSet.internalizePath(this.parent);\n\t\t\t\t\tif (this.parent instanceof PathNode) {\n\t\t\t\t\t\tthis.parent.addRef();\n\t\t\t\t\t\treferencedPathNodes.push(this.parent);\n\t\t\t\t\t\twithNode(this.parent);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tparentField: undefined as FieldKey | undefined,\n\t\t\tparent: undefined as UpPath | undefined,\n\n\t\t\t/**\n\t\t\t * Events collected during the visit which get sent as a batch during \"free\".\n\t\t\t */\n\t\t\tbufferedEvents: [] as BufferedEvent[],\n\n\t\t\t/**\n\t\t\t * 'currentDepth' and 'depthThresholdForSubtreeChanged' serve to keep track of when do we need to emit\n\t\t\t * subtreeChangedAfterBatch events.\n\t\t\t * The algorithm works as follows:\n\t\t\t *\n\t\t\t * - Initialize both to 0.\n\t\t\t * - As we walk the tree from the root towards the leaves, when we enter a node increment currentDepth by 1.\n\t\t\t * - When we edit a node, set depthThresholdForSubtreeChanged = currentDepth.\n\t\t\t * Intuitively, depthThresholdForSubtreeChanged means \"as you walk the tree towards the root, when you exit a\n\t\t\t * node at this depth you should emit a subtreeChangedAfterBatch event\".\n\t\t\t * - When we exit a node, if d === currentDepth then emit a subtreeChangedAfterBatch and decrement d by 1.\n\t\t\t * Then decrement currentDepth unconditionally.\n\t\t\t *\n\t\t\t * Note that the event will be emitted when exiting a node that was edited (depthThresholdForSubtreeChanged will\n\t\t\t * have been set to the current depth when the edit happened), it will be emitted when exiting a node that is the\n\t\t\t * parent of a node that already emitted the event (because both depthThresholdForSubtreeChanged and currentDepth\n\t\t\t * get decremented when exiting a node so they stay in sync), and if we're already emitting the event but start\n\t\t\t * walking the tree back towards the leaves in a path where no edits happen, currentDepth will be increased again\n\t\t\t * as we walk that path, depthThresholdForSubtreeChanged will not, and thus no event will be emitted when walking\n\t\t\t * back up that path, until we get back to the depth where we were already emitting the event, and will continue\n\t\t\t * emitting it on the way to the root.\n\t\t\t */\n\t\t\tcurrentDepth: 0,\n\t\t\t/**\n\t\t\t * See {@link visitor.currentDepth}.\n\t\t\t */\n\t\t\tdepthThresholdForSubtreeChanged: 0,\n\n\t\t\tfree() {\n\t\t\t\tassert(\n\t\t\t\t\tthis.anchorSet.activeVisitor !== undefined,\n\t\t\t\t\t0x768 /* Multiple free calls for same visitor */,\n\t\t\t\t);\n\t\t\t\tfor (const node of referencedPathNodes) {\n\t\t\t\t\tnode.removeRef();\n\t\t\t\t}\n\t\t\t\tthis.anchorSet.activeVisitor = undefined;\n\n\t\t\t\t// Aggregate changedFields by node.\n\t\t\t\tconst eventsByNode: Map<PathNode, Set<FieldKey>> = new Map();\n\t\t\t\tfor (const { node, event, changedField } of this.bufferedEvents) {\n\t\t\t\t\tif (event === \"childrenChangedAfterBatch\") {\n\t\t\t\t\t\tconst keys = getOrCreate(eventsByNode, node, () => new Set());\n\t\t\t\t\t\tkeys.add(\n\t\t\t\t\t\t\tchangedField ??\n\t\t\t\t\t\t\t\tfail(0xb57 /* childrenChangedAfterBatch events should have a changedField */),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst alreadyEmitted = new Map<PathNode, (keyof AnchorEvents)[]>();\n\t\t\t\tfor (const { node, event } of this.bufferedEvents) {\n\t\t\t\t\tconst emittedEvents = getOrAddEmptyToMap(alreadyEmitted, node);\n\t\t\t\t\tif (emittedEvents.includes(event)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\temittedEvents.push(event);\n\t\t\t\t\tif (event === \"childrenChangedAfterBatch\") {\n\t\t\t\t\t\tconst changedFields =\n\t\t\t\t\t\t\teventsByNode.get(node) ??\n\t\t\t\t\t\t\tfail(0xaeb /* childrenChangedAfterBatch events should have changedFields */);\n\t\t\t\t\t\tnode.events.emit(event, { changedFields });\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnode.events.emit(event);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tnotifyChildrenChanging(): void {\n\t\t\t\tthis.maybeWithNode(\n\t\t\t\t\t(p) => p.events.emit(\"childrenChanging\", p),\n\t\t\t\t\t() => this.anchorSet.#events.emit(\"childrenChanging\", this.anchorSet),\n\t\t\t\t);\n\t\t\t},\n\t\t\tnotifyChildrenChanged(): void {\n\t\t\t\tthis.maybeWithNode(\n\t\t\t\t\t(p) => {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tthis.parentField !== undefined,\n\t\t\t\t\t\t\t0xa24 /* Must be in a field to modify its contents */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tp.events.emit(\"childrenChanged\", p);\n\t\t\t\t\t\tthis.bufferedEvents.push({\n\t\t\t\t\t\t\tnode: p,\n\t\t\t\t\t\t\tevent: \"childrenChangedAfterBatch\",\n\t\t\t\t\t\t\tchangedField: this.parentField,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\t() => {},\n\t\t\t\t);\n\t\t\t},\n\t\t\tattach(source: FieldKey, count: number, destination: PlaceIndex): void {\n\t\t\t\tthis.notifyChildrenChanging();\n\t\t\t\tthis.attachEdit(source, count, destination);\n\t\t\t\tthis.notifyChildrenChanged();\n\t\t\t},\n\t\t\tattachEdit(source: FieldKey, count: number, destination: PlaceIndex): void {\n\t\t\t\tassert(\n\t\t\t\t\tthis.parentField !== undefined,\n\t\t\t\t\t0x7a2 /* Must be in a field in order to attach */,\n\t\t\t\t);\n\t\t\t\tconst sourcePath = {\n\t\t\t\t\tparent: this.anchorSet.root,\n\t\t\t\t\tparentField: source,\n\t\t\t\t\tparentIndex: 0,\n\t\t\t\t};\n\t\t\t\tconst destinationPath = {\n\t\t\t\t\tparent: this.parent,\n\t\t\t\t\tparentField: this.parentField,\n\t\t\t\t\tparentIndex: destination,\n\t\t\t\t};\n\t\t\t\tthis.anchorSet.moveChildren(sourcePath, destinationPath, count);\n\t\t\t\tthis.depthThresholdForSubtreeChanged = this.currentDepth;\n\t\t\t},\n\t\t\tdetach(\n\t\t\t\tsource: Range,\n\t\t\t\tdestination: FieldKey,\n\t\t\t\tdetachedNodeId: Delta.DetachedNodeId,\n\t\t\t): void {\n\t\t\t\tthis.notifyChildrenChanging();\n\t\t\t\tthis.detachEdit(source, destination, detachedNodeId);\n\t\t\t\tthis.notifyChildrenChanged();\n\t\t\t},\n\t\t\tdetachEdit(\n\t\t\t\tsource: Range,\n\t\t\t\tdestination: FieldKey,\n\t\t\t\tdetachedNodeId: Delta.DetachedNodeId,\n\t\t\t): void {\n\t\t\t\tassert(\n\t\t\t\t\tthis.parentField !== undefined,\n\t\t\t\t\t0x7a5 /* Must be in a field in order to detach */,\n\t\t\t\t);\n\t\t\t\tconst sourcePath: UpPath = {\n\t\t\t\t\tparent: this.parent,\n\t\t\t\t\tparentField: this.parentField,\n\t\t\t\t\tparentIndex: source.start,\n\t\t\t\t};\n\t\t\t\tconst destinationPath: NormalizedUpPath = {\n\t\t\t\t\tparent: this.anchorSet.root,\n\t\t\t\t\tparentField: destination,\n\t\t\t\t\tparentIndex: 0,\n\t\t\t\t\tdetachedNodeId,\n\t\t\t\t};\n\t\t\t\tthis.anchorSet.moveChildren(sourcePath, destinationPath, source.end - source.start);\n\t\t\t\tthis.depthThresholdForSubtreeChanged = this.currentDepth;\n\t\t\t},\n\t\t\treplace(\n\t\t\t\tnewContentSource: FieldKey,\n\t\t\t\trange: Range,\n\t\t\t\toldContentDestination: FieldKey,\n\t\t\t\tdestinationDetachedNodeId: Delta.DetachedNodeId,\n\t\t\t): void {\n\t\t\t\tthis.notifyChildrenChanging();\n\t\t\t\tthis.detachEdit(range, oldContentDestination, destinationDetachedNodeId);\n\t\t\t\tthis.attachEdit(newContentSource, range.end - range.start, range.start);\n\t\t\t\tthis.notifyChildrenChanged();\n\t\t\t},\n\t\t\tdestroy(detachedField: FieldKey, count: number): void {\n\t\t\t\tthis.anchorSet.removeChildren(\n\t\t\t\t\t{\n\t\t\t\t\t\tparent: undefined,\n\t\t\t\t\t\tparentField: detachedField,\n\t\t\t\t\t\tparentIndex: 0,\n\t\t\t\t\t},\n\t\t\t\t\tcount,\n\t\t\t\t);\n\t\t\t},\n\t\t\tcreate(content: ITreeCursorSynchronous[], destination: FieldKey): void {\n\t\t\t\t// Nothing to do since content can only be created in a new detached field,\n\t\t\t\t// which cannot contain any anchors.\n\t\t\t},\n\t\t\tenterNode(index: number): void {\n\t\t\t\tassert(this.parentField !== undefined, 0x3ab /* Must be in a field to enter node */);\n\n\t\t\t\tthis.parent = {\n\t\t\t\t\tparent: this.parent,\n\t\t\t\t\tparentField: this.parentField,\n\t\t\t\t\tparentIndex: index,\n\t\t\t\t};\n\t\t\t\tthis.parentField = undefined;\n\t\t\t\tthis.maybeWithNode((p) => {\n\t\t\t\t\tp.events.emit(\"subtreeChanging\", p);\n\t\t\t\t});\n\t\t\t\tthis.currentDepth++;\n\t\t\t},\n\t\t\texitNode(index: number): void {\n\t\t\t\tassert(this.parent !== undefined, 0x3ac /* Must have parent node */);\n\t\t\t\tif (this.depthThresholdForSubtreeChanged === this.currentDepth) {\n\t\t\t\t\tthis.maybeWithNode((p) => {\n\t\t\t\t\t\tp.events.emit(\"subtreeChanged\", p);\n\n\t\t\t\t\t\tthis.bufferedEvents.push({\n\t\t\t\t\t\t\tnode: p,\n\t\t\t\t\t\t\tevent: \"subtreeChangedAfterBatch\",\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t\tthis.depthThresholdForSubtreeChanged--;\n\t\t\t\t}\n\t\t\t\tconst parent = this.parent;\n\t\t\t\tthis.parentField = parent.parentField;\n\t\t\t\tthis.parent = parent.parent;\n\t\t\t\tthis.currentDepth--;\n\t\t\t},\n\t\t\tenterField(key: FieldKey): void {\n\t\t\t\tthis.parentField = key;\n\t\t\t},\n\t\t\texitField(key: FieldKey): void {\n\t\t\t\tthis.parentField = undefined;\n\t\t\t},\n\t\t};\n\t\tthis.#events.emit(\"treeChanging\", this);\n\t\tthis.activeVisitor = visitor;\n\t\treturn visitor;\n\t}\n}\n\n/**\n * Indicates the status of a `NodePath`.\n */\nenum Status {\n\t/**\n\t * Indicates the `NodePath` is being maintained and corresponds to a valid\n\t * (i.e., not removed) node in the document.\n\t */\n\tAlive,\n\t/**\n\t * Indicates the `NodePath` is not being maintained by the `AnchorSet`.\n\t * The `NodePath` may or may not correspond to a valid node in the document.\n\t *\n\t * Accessing such a node is invalid.\n\t * Nodes in this state are retained to detect use-after-free bugs.\n\t */\n\tDisposed,\n\t/**\n\t * Indicates the `NodePath` corresponds to a removed node in the document.\n\t * Such `NodePath`s are not maintained by the `AnchorSet` (other than updating\n\t * their status to `Disposed` when appropriate).\n\t *\n\t * Accessing such a node is invalid.\n\t * Nodes in this state are retained to detect use-after-free bugs.\n\t */\n\tDangling,\n}\n\n/**\n * Tree of anchors.\n *\n * Contains both child and parent pointers, which are kept in sync.\n *\n * Each anchor is equivalent to a path through the tree.\n * This tree structure stores a collection of these paths, but deduplicating the common prefixes of the tree\n * prefix-tree style.\n *\n * These anchors are used instead of just holding onto the node objects in forests for several reasons:\n *\n * - Update policy might be more complex than just tracking a node object in the forest.\n *\n * - Not all forests will have node objects: some may use compressed binary formats with no objects to reference.\n *\n * - Anchors are needed even when not using forests, and for nodes that are outside the currently loaded part of the\n * forest.\n *\n * - Forest in general do not need to support up pointers, but they are needed for anchors.\n *\n * Thus this can be thought of as a sparse copy of the subset of trees which are used as anchors,\n * plus the parent paths for them.\n *\n * ReferenceCountedBase tracks the number of references to this from external sources (`Anchors` via `AnchorSet`.).\n * Kept alive as if any of the follow are true:\n * 1. there are children.\n * 2. refcount is non-zero.\n * 3. events are registered.\n */\nclass PathNode extends ReferenceCountedBase implements AnchorNode {\n\tpublic status: Status = Status.Alive;\n\t/**\n\t * Event emitter for this anchor.\n\t */\n\tpublic readonly events = createEmitter<AnchorEvents>(this.considerDispose.bind(this));\n\n\t/**\n\t * PathNode arrays are kept sorted the PathNode's parentIndex for efficient search.\n\t * Users of this field must take care to maintain invariants (correct parent pointers, not empty child arrays etc.)\n\t *\n\t * Performance Note:\n\t * Large child lists could be updated more efficiently here using a data-structure optimized\n\t * for efficient prefix sum updates, such as a Fenwick tree or Finger tree.\n\t * This would be complicated by the need for parent pointers (including indexes),\n\t * but is possible to do.\n\t */\n\tpublic readonly children: Map<FieldKey, PathNode[]> = new Map();\n\n\t// See note on BrandedKey.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic readonly slots: BrandedMapSubset<AnchorSlot<any>> = new Map();\n\n\t/**\n\t * {@inheritdoc UpPath.detachedNodeId}\n\t */\n\tpublic detachedNodeId: Delta.DetachedNodeId | undefined;\n\n\t/**\n\t * Construct a PathNode with refcount 1.\n\t * @param anchorSet - used to determine if this PathNode is already part of a specific anchorSet\n\t * to early out UpPath walking.\n\t */\n\tpublic constructor(\n\t\tpublic readonly anchorSet: AnchorSet,\n\t\tpublic parentField: FieldKey,\n\t\tpublic parentIndex: number,\n\t\t/**\n\t\t * The parent of this `PathNode` (an up pointer in the `PathNode` tree).\n\t\t * If the status of this node is `Alive`, then there must be a corresponding down pointer from the\n\t\t * `parentPath` node to this node.\n\t\t * When undefined, this node is the {@link AnchorSet.root} for `this.anchorSet` and thus has no parent.\n\t\t *\n\t\t * When updating the tree, `AnchorSet` may transiently leave the up and down pointers inconsistent\n\t\t * (updating down pointers first), but must ensure they are consistent before the editing operation returns\n\t\t * to non-`AnchorSet` code.\n\t\t * This consistency guarantee only applies to nodes that are `Alive`.\n\t\t */\n\t\tpublic parentPath: PathNode | undefined,\n\t) {\n\t\tsuper(1);\n\t}\n\n\tpublic child(key: FieldKey, index: number): UpPath<AnchorNode> {\n\t\t// Fast path: if child exists, return it.\n\t\treturn (\n\t\t\tthis.childIfAnchored(key, index) ?? {\n\t\t\t\tparent: this,\n\t\t\t\tparentField: key,\n\t\t\t\tparentIndex: index,\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic getOrCreateChildRef(key: FieldKey, index: number): [Anchor, AnchorNode] {\n\t\tconst anchor = this.anchorSet.track(this.child(key, index));\n\t\tconst node =\n\t\t\tthis.anchorSet.locate(anchor) ??\n\t\t\tfail(0xaec /* cannot reference child that does not exist */);\n\t\treturn [anchor, node];\n\t}\n\n\t/**\n\t * Whether or not this `PathNode` is the special root node that sits above all the detached fields.\n\t * @remarks\n\t * In this case, the fields are detached sequences.\n\t * Note that the special root node should never appear in an UpPath\n\t * since UpPaths represent this root as `undefined`.\n\t */\n\tprivate isRoot(): boolean {\n\t\treturn this.parentPath === undefined;\n\t}\n\n\tpublic get parent(): PathNode | undefined {\n\t\tassert(this.status !== Status.Disposed, 0x409 /* PathNode must not be disposed */);\n\t\tassert(\n\t\t\tthis.parentPath !== undefined,\n\t\t\t0x355 /* PathNode.parent is an UpPath API and thus should never be called on the root PathNode. */,\n\t\t);\n\t\t// Root PathNode corresponds to the undefined root for UpPath API.\n\t\tif (this.parentPath.isRoot()) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.parentPath;\n\t}\n\n\tpublic addRef(count = 1): void {\n\t\tassert(this.status === Status.Alive, 0x40a /* PathNode must be alive */);\n\t\tthis.referenceAdded(count);\n\t}\n\n\tpublic removeRef(count = 1): void {\n\t\tassert(this.status !== Status.Disposed, 0x40b /* PathNode must not be disposed */);\n\t\tthis.referenceRemoved(count);\n\t}\n\n\t// Called when refcount is set to 0.\n\t// Node may be kept alive by children or events after this point.\n\tprotected onUnreferenced(): void {\n\t\tthis.considerDispose();\n\t}\n\n\t/**\n\t * Gets a child, adding a ref to it.\n\t * Creates child (with 1 ref) if needed.\n\t */\n\tpublic getOrCreateChild(key: FieldKey, index: number): PathNode {\n\t\tassert(this.status === Status.Alive, 0x40c /* PathNode must be alive */);\n\t\tlet field = this.children.get(key);\n\t\tif (field === undefined) {\n\t\t\tfield = [];\n\t\t\tthis.children.set(key, field);\n\t\t}\n\t\tlet child = binaryFind(field, index);\n\t\tif (child === undefined) {\n\t\t\tchild = new PathNode(this.anchorSet, key, index, this);\n\t\t\tfield.push(child);\n\t\t\t// Keep list sorted by index.\n\t\t\tfield.sort((a, b) => a.parentIndex - b.parentIndex);\n\t\t} else {\n\t\t\tchild.addRef();\n\t\t}\n\t\treturn child;\n\t}\n\n\tpublic childIfAnchored(key: FieldKey, index: number): PathNode | undefined {\n\t\tassert(this.status === Status.Alive, 0x40d /* PathNode must be alive */);\n\t\tconst field = this.children.get(key);\n\n\t\treturn field === undefined ? undefined : binaryFind(field, index);\n\t}\n\n\t/**\n\t * Removes reference from this to `child`.\n\t * Since PathNodes are doubly linked,\n\t * the caller must ensure that the reference from child to parent is also removed (or the child is no longer used).\n\t */\n\tpublic removeChild(child: PathNode): void {\n\t\tassert(this.status === Status.Alive, 0x40e /* PathNode must be alive */);\n\t\tconst key = child.parentField;\n\t\tconst field = this.children.get(key);\n\t\t// TODO: should do more optimized search (ex: binary search or better) using child.parentIndex()\n\t\t// Note that this is the index in the list of child paths, not the index within the field\n\t\tconst childIndex = field?.indexOf(child) ?? -1;\n\t\tassert(childIndex !== -1, 0x35c /* child must be parented to be removed */);\n\t\tfield?.splice(childIndex, 1);\n\t\tif (field?.length === 0) {\n\t\t\tthis.afterEmptyField(key);\n\t\t}\n\t}\n\n\t/**\n\t * Call this after directly editing the child array for a field to be empty.\n\t * Handles cleaning up unneeded data\n\t * (like the field in the map, and possibly this entire PathNode and its parents if they are no longer needed.)\n\t */\n\tpublic afterEmptyField(key: FieldKey): void {\n\t\tassert(this.status === Status.Alive, 0x40f /* PathNode must be alive */);\n\t\tthis.children.delete(key);\n\t\tthis.considerDispose();\n\t}\n\n\t/**\n\t * If node is no longer needed (has no references, no children and no events):\n\t * removes this from parent if alive, and sets this to disposed.\n\t * Must only be called when .\n\t *\n\t * Allowed when dangling (but not when disposed).\n\t */\n\tprivate considerDispose(): void {\n\t\tassert(this.status !== Status.Disposed, 0x41d /* PathNode must not be disposed */);\n\t\tif (this.isUnreferenced() && this.children.size === 0 && !this.events.hasListeners()) {\n\t\t\tif (this.status === Status.Alive) {\n\t\t\t\t// eslint-disable-next-line unicorn/prefer-dom-node-remove -- Custom tree structure, not DOM\n\t\t\t\tthis.parentPath?.removeChild(this);\n\t\t\t}\n\t\t\tthis.status = Status.Disposed;\n\t\t}\n\t}\n}\n\n/**\n * Find a child PathNode by index using a binary search.\n * @param sorted - array of PathNode's sorted by parentIndex.\n * @param index - index being looked for.\n * @returns child with the requested parentIndex, or undefined.\n * @privateRemarks\n * This function is very commonly used with small arrays (length 0 or one for all non sequence fields),\n * and is currently a hot path due to how flex tree leaves to excessive cursor to anchor and anchor to cursor translations,\n * both of which walk paths down the AnchorSet.\n * Additionally current usages tends to fully populate the anchor tree leading the correct array index to be the requested parent index.\n * This makes the performance of this performance both important in small cases and easy to overly tune to the current usage patterns.\n * This lead to not implementing a general purpose reusable binary search.\n * Once this function is not so heavily overused due to inefficient patterns in flex-tree,\n * replacing it with a standard binary search is likely fine.\n * Until then, care and benchmarking should be used when messing with this function.\n */\nfunction binaryFind(sorted: readonly PathNode[], index: number): PathNode | undefined {\n\t// Try guessing the list is not sparse as a starter:\n\tconst guess = sorted[index];\n\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- using ?. could change behavior\n\tif (guess !== undefined && guess.parentIndex === index) {\n\t\treturn guess;\n\t}\n\n\t// inclusive\n\tlet min = 0;\n\t// exclusive\n\tlet max = sorted.length;\n\n\twhile (min !== max) {\n\t\tconst mid = Math.floor((min + max) / 2);\n\t\tconst item = sorted[mid]!;\n\t\tconst found = item.parentIndex;\n\t\tif (found === index) {\n\t\t\treturn item; // Found the target, return it.\n\t\t} else if (found > index) {\n\t\t\tmax = mid; // Continue search on lower half.\n\t\t} else {\n\t\t\tmin = mid + 1; // Continue search on left half.\n\t\t}\n\t}\n\treturn undefined; // If we reach here, target is not in array (or array was not sorted)\n}\n\ninterface BufferedEvent {\n\tnode: PathNode;\n\tevent: keyof AnchorEvents;\n\t/**\n\t * The key for the impacted field, if the event is associated with a key.\n\t * Some events, such as afterDestroy, do not involve a key, and thus leave this undefined.\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,CAAC,CAAC;IAC5B,sGAAsG;IACtG,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,WAAW,KAAK,KAAK,EAAE,CAAC;QACxD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,YAAY;IACZ,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,YAAY;IACZ,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;IAExB,OAAO,GAAG,KAAK,GAAG,EAAE,CAAC;QACpB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACxC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC;QAC/B,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,CAAC,+BAA+B;QAC7C,CAAC;aAAM,IAAI,KAAK,GAAG,KAAK,EAAE,CAAC;YAC1B,GAAG,GAAG,GAAG,CAAC,CAAC,iCAAiC;QAC7C,CAAC;aAAM,CAAC;YACP,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,gCAAgC;QAChD,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC,CAAC,qEAAqE;AACxF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { HasListeners, Listenable } from \"@fluidframework/core-interfaces/internal\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\ttype Brand,\n\ttype BrandedKey,\n\ttype BrandedMapSubset,\n\ttype Opaque,\n\tReferenceCountedBase,\n\tbrand,\n\tbrandedSlot,\n\tgetOrAddEmptyToMap,\n\tgetOrCreate,\n} from \"../../util/index.js\";\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport type { ITreeCursorSynchronous } from \"./cursor.js\";\nimport type * as Delta from \"./delta.js\";\nimport { offsetDetachId } from \"./deltaUtil.js\";\nimport {\n\tisDetachedUpPathRoot,\n\ttype INormalizedUpPath,\n\ttype NormalizedUpPath,\n\ttype PlaceIndex,\n\ttype Range,\n\ttype UpPath,\n} from \"./pathTree.js\";\nimport { EmptyKey } from \"./types.js\";\nimport type { DeltaVisitor } from \"./visitDelta.js\";\n\n/**\n * A way to refer to a particular tree location within an {@link AnchorSet}.\n * Associated with a ref count on the underlying {@link AnchorNode}.\n */\nexport type Anchor = Brand<number, \"rebaser.Anchor\">;\n\n/**\n * A singleton which represents a permanently invalid location (i.e. there is never a node there)\n */\nconst NeverAnchor: Anchor = brand(0);\n\n/**\n * Maps anchors (which must be ones this locator knows about) to paths.\n */\nexport interface AnchorLocator {\n\t/**\n\t * Get the current location of an Anchor.\n\t * The returned value should not be used after an edit has occurred.\n\t *\n\t * TODO: support extra/custom return types for specific/custom anchor types:\n\t * for now caller must rely on data in anchor + returned node location\n\t * (not ideal for anchors for places or ranges instead of nodes).\n\t */\n\tlocate(anchor: Anchor): AnchorNode | undefined;\n}\n\n/**\n * Stores arbitrary, user-defined data on an {@link Anchor}.\n * This data is preserved over the course of that anchor's lifetime.\n * @see {@link anchorSlot} for creation and an example use case.\n */\nexport type AnchorSlot<TContent> = BrandedKey<Opaque<Brand<number, \"AnchorSlot\">>, TContent>;\n\n/**\n * Events for {@link AnchorNode}.\n * These events are triggered while the internal data structures are being updated.\n * Thus these events must not trigger reading of the anchorSet or forest.\n *\n * TODO:\n * - Include sub-deltas in events.\n * - Add more events.\n */\nexport interface AnchorEvents {\n\t/**\n\t * When the anchor node will never get reused by its AnchorSet.\n\t * This means that the content it corresponds to has been permanently destroyed.\n\t *\n\t * @remarks\n\t * When this happens depends entirely on how the anchorSet is used.\n\t * It's possible nodes removed from the tree will be kept indefinitely, and thus never trigger this event, or they may be discarded immediately.\n\t *\n\t * @privateRemarks\n\t * The specifics of the delta visit algorithm can impact the behavior of these events.\n\t * Refer to the privateRemarks of specific events and/or the documentation of the delta visit algorithm (as of\n\t * 2024-04-02, src/core/tree/visitDelta.ts) for more information.\n\t */\n\tafterDestroy(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if one or more of this node's\n\t * direct children are about to change due to updates from the batch.\n\t *\n\t * @remarks\n\t * Does not include edits of child subtrees: instead only includes changes to nodes which are direct children in this\n\t * node's fields.\n\t */\n\tchildrenChanging(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if one or more of this node's\n\t * direct children just changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * Does not include edits of child subtrees: instead only includes changes to nodes which are direct children in this\n\t * node's fields.\n\t *\n\t * Compare to {@link AnchorEvents.childrenChangedAfterBatch} which is emitted after the whole batch has been applied.\n\t */\n\tchildrenChanged(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted after a batch of changes has been applied (i.e. when a delta visit completes), if one or more of this node's\n\t * direct children changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * Does not include edits of child subtrees: instead only includes changes to nodes which are direct children in this\n\t * node's fields.\n\t *\n\t * This event is guaranteed to be emitted on a given node only once per batch.\n\t *\n\t * Compare to {@link AnchorEvents.childrenChanged} which is emitted in the middle of the batch/delta-visit.\n\t */\n\tchildrenChangedAfterBatch(arg: { changedFields: ReadonlySet<FieldKey> }): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if something in the subtree\n\t * rooted at `anchor` _may_ be about to change due to updates from the batch.\n\t *\n\t * @remarks\n\t * Called on every parent (transitively) when a change is occurring.\n\t */\n\tsubtreeChanging(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if something in the subtree\n\t * rooted at `anchor` _may_ have just changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * While this event is always emitted in the presence of changes to the subtree,\n\t * it may also be emitted even though no changes have been made to the subtree.\n\t * It may be emitted multiple times within the application of a single edit or transaction.\n\t *\n\t * If this event is emitted by a node, it will later be emitted by all its ancestors up to the root as well, at\n\t * least once on each ancestor.\n\t *\n\t * Compare to {@link AnchorEvents.subtreeChangedAfterBatch} which is emitted after the whole batch has been applied.\n\t *\n\t * @privateRemarks\n\t * The delta visit algorithm is complicated and it may fire this event multiple times for the same change to a node.\n\t * The change to the tree may not be visible until the event fires for the last time.\n\t * Refer to the documentation of the delta visit algorithm for more details.\n\t */\n\tsubtreeChanged(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted after a batch of changes has been applied (i.e. when a delta visit completes), if something in the subtree\n\t * rooted at `anchor` changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * If this event is emitted by a node, it will later be emitted by all its ancestors up to the root as well, from bottom to top.\n\t *\n\t * This event is guaranteed to be emitted on a given node only once per batch.\n\t *\n\t * Compare to {@link AnchorEvents.subtreeChanged} which is emitted in the middle of the batch/delta-visit.\n\t *\n\t * @privateRemarks\n\t * Note that because this is fired after the full batch of changes is applied, it guarantees that something in the\n\t * subtree changed, compared to {@link AnchorEvents.subtreeChanged} or {@link AnchorEvents.subtreeChanging} which\n\t * fire when something _may_ have changed or _may_ be about to change.\n\t */\n\tsubtreeChangedAfterBatch(): void;\n}\n\n/**\n * Events for {@link AnchorSet}.\n * These events are triggered while the internal data structures are being updated.\n * Thus these events must not trigger reading of the anchorSet or forest.\n *\n * TODO:\n * - Design how events should be ordered.\n * - Include sub-deltas in events.\n * - Add more events.\n */\nexport interface AnchorSetRootEvents {\n\t/**\n\t * What children are at the root is changing.\n\t */\n\tchildrenChanging(anchors: AnchorSet): void;\n\n\t/**\n\t * Something in the tree is changing.\n\t */\n\ttreeChanging(anchors: AnchorSet): void;\n}\n\n/**\n * Node in a tree of anchors.\n */\nexport interface AnchorNode extends INormalizedUpPath<AnchorNode> {\n\t/**\n\t * Events for this anchor node.\n\t */\n\treadonly events: Listenable<AnchorEvents> & HasListeners<AnchorEvents>;\n\n\t/**\n\t * Allows access to data stored on the Anchor in \"slots\".\n\t * Use {@link anchorSlot} to create slots.\n\t */\n\t// See note on BrandedKey\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\treadonly slots: BrandedMapSubset<AnchorSlot<any>>;\n\n\t/**\n\t * The set this anchor node is part of.\n\t */\n\treadonly anchorSet: AnchorSet;\n\n\t/**\n\t * Gets a child of this node.\n\t *\n\t * @remarks\n\t * This does not return an AnchorNode since there might not be one, and lazily creating one here would have messy lifetime management (See {@link AnchorNode#getOrCreateChildRef})\n\t * If an AnchorNode is required, use the AnchorSet to track then locate the returned path.\n\t * TODO:\n\t * Revisit this API.\n\t * Perhaps if we use weak down pointers and remove ref counting, we can make this return a AnchorNode.\n\t *\n\t */\n\tchild(key: FieldKey, index: number): UpPath<AnchorNode>;\n\n\t/**\n\t * Gets the child AnchorNode if already exists.\n\t *\n\t * Does NOT add a ref, so the returned AnchorNode must be used with care.\n\t */\n\tchildIfAnchored(key: FieldKey, index: number): AnchorNode | undefined;\n\n\t/**\n\t * Gets a child AnchorNode (creating it if needed), and an Anchor owning a ref to it.\n\t * Caller is responsible for freeing the returned Anchor, and must not use the AnchorNode after that.\n\t */\n\tgetOrCreateChildRef(key: FieldKey, index: number): [Anchor, AnchorNode];\n}\n\n/**\n * Define a strongly typed slot on anchors in which data can be stored.\n *\n * @remarks\n * This is mainly useful for caching data associated with a location in the tree.\n *\n * Example usage:\n * ```typescript\n * const counterSlot = anchorSlot<number>();\n *\n * function useSlot(anchor: AnchorNode): void {\n * \tanchor.slots.set(counterSlot, 1 + anchor.slots.get(counterSlot) ?? 0);\n * }\n * ```\n */\nexport function anchorSlot<TContent>(): AnchorSlot<TContent> {\n\treturn brandedSlot<AnchorSlot<TContent>>();\n}\n\n/**\n * Collection of Anchors at a specific revision.\n *\n * See `Rebaser` for how to update across revisions.\n *\n * TODO: this should not be package exported.\n * If it's needed outside the package an Interface should be used instead which can reduce its\n * API surface to a small subset.\n *\n * @sealed\n */\nexport class AnchorSet implements AnchorLocator {\n\treadonly #events = createEmitter<AnchorSetRootEvents>();\n\tpublic readonly events: Listenable<AnchorSetRootEvents> = this.#events;\n\n\t/**\n\t * Incrementing counter to give each anchor in this set a unique index for its identifier.\n\t * \"0\" is reserved for the `NeverAnchor`.\n\t */\n\tprivate anchorCounter = 1;\n\n\t/**\n\t * Incrementing number that is bumped each time that the {@link AnchorSet} is changed.\n\t * This allows consumers to cache state associated with a particular generation number and later determine if that state may have been invalidated using a comparison with the current generation number.\n\t * For example, anchor slots can be used to cache the removal status of a node to memoize repeated walks up the tree.\n\t */\n\tpublic generationNumber = 0;\n\n\t/**\n\t * Special root node under which all anchors in this anchor set are transitively parented.\n\t * This does not appear in the UpPaths (instead they use undefined for the root).\n\t * Immediate children of this root are in detached fields (which have their identifiers used as the field keys).\n\t *\n\t * This is allocated with refCount one, which is never freed so it is never cleaned up\n\t * (as long as this AnchorSet is not garbage collected).\n\t *\n\t * There should never be any children other than the special root detached field under this between transactions:\n\t * TODO: check for and enforce this.\n\t */\n\tprivate readonly root = new PathNode(this, EmptyKey, 0, undefined);\n\n\t// TODO: anchor system could be optimized a bit to avoid the maps (Anchor is ref to Path, path has ref count).\n\t// For now use this more encapsulated approach with maps.\n\tprivate readonly anchorToPath: Map<Anchor, PathNode> = new Map();\n\n\tprivate activeVisitor?: DeltaVisitor;\n\n\tpublic constructor() {\n\t\tthis.events.on(\"treeChanging\", () => {\n\t\t\tthis.generationNumber += 1;\n\t\t});\n\t}\n\n\t/**\n\t * Allows access to data stored on the AnchorSet in \"slots\".\n\t * Use {@link anchorSlot} to create slots.\n\t *\n\t * @privateRemarks\n\t * This forwards to the slots of the special above root anchor which locate can't access.\n\t */\n\t// See note on BrandedKey.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic get slots(): BrandedMapSubset<AnchorSlot<any>> {\n\t\treturn this.root.slots;\n\t}\n\n\tpublic *[Symbol.iterator](): IterableIterator<AnchorNode> {\n\t\tconst stack: PathNode[] = [];\n\t\tlet node: PathNode | undefined = this.root;\n\t\twhile (node !== undefined) {\n\t\t\tyield node;\n\t\t\tfor (const [_, children] of node.children) {\n\t\t\t\tfor (const child of children) {\n\t\t\t\t\tstack.push(child);\n\t\t\t\t}\n\t\t\t}\n\t\t\tnode = stack.pop();\n\t\t}\n\t}\n\n\t/**\n\t * Check if there are currently no anchors tracked.\n\t * Mainly for testing anchor cleanup.\n\t */\n\tpublic isEmpty(): boolean {\n\t\treturn this.root.children.size === 0;\n\t}\n\n\tpublic locate(anchor: Anchor): AnchorNode | undefined {\n\t\tif (anchor === NeverAnchor) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst path = this.anchorToPath.get(anchor);\n\t\tassert(\n\t\t\tpath !== undefined,\n\t\t\t0x3a6 /* Cannot locate anchor which is not in this AnchorSet */,\n\t\t);\n\t\treturn path.status === Status.Alive ? path : undefined;\n\t}\n\n\tpublic forget(anchor: Anchor): void {\n\t\tif (anchor !== NeverAnchor) {\n\t\t\tconst path = this.anchorToPath.get(anchor);\n\t\t\tassert(path !== undefined, 0x351 /* cannot forget unknown Anchor */);\n\t\t\tpath.removeRef();\n\t\t\tthis.anchorToPath.delete(anchor);\n\t\t}\n\t}\n\n\t/**\n\t * TODO: Add APIs need to allow callers of this function to reduce copying here.\n\t * Ex: maybe return something extending UpPath here.\n\t * @param path - the path to the node to be tracked. If null, returns an anchor\n\t * which is permanently invalid.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic track(path: UpPath | null): Anchor {\n\t\tif (path === null) {\n\t\t\treturn NeverAnchor;\n\t\t}\n\n\t\tconst foundPath = this.trackInner(path);\n\t\tconst anchor: Anchor = brand(this.anchorCounter++);\n\t\tthis.anchorToPath.set(anchor, foundPath);\n\t\treturn anchor;\n\t}\n\n\t/**\n\t * Finds a path node, creating if needed, and adds a ref count to it.\n\t */\n\tprivate trackInner(path: UpPath): PathNode {\n\t\tif (path instanceof PathNode && path.anchorSet === this) {\n\t\t\tpath.addRef();\n\t\t\treturn path;\n\t\t}\n\t\tconst parent = path.parent ?? this.root;\n\t\tconst parentPath = this.trackInner(parent);\n\n\t\tconst child = parentPath.getOrCreateChild(path.parentField, path.parentIndex);\n\n\t\t// Now that child is added (if needed), remove the extra ref that we added in the recursive call.\n\t\tparentPath.removeRef();\n\n\t\treturn child;\n\t}\n\n\t/**\n\t * Finds a path node if it already exists.\n\t *\n\t * Does not add a ref!\n\t */\n\tpublic find(path: UpPath): PathNode | undefined {\n\t\tif (path instanceof PathNode && path.anchorSet === this) {\n\t\t\treturn path;\n\t\t}\n\t\tconst parent = path.parent ?? this.root;\n\t\tconst parentPath = this.find(parent);\n\t\treturn parentPath?.childIfAnchored(path.parentField, path.parentIndex);\n\t}\n\n\t/**\n\t * Returns an equivalent path making as much of it with PathNodes as possible.\n\t * This allows future operations (like find, track, locate) on this path (and derived ones) to be faster.\n\t * Note that the returned path may use AnchorNodes from this AnchorSet,\n\t * but does not have a tracked reference to them, so this should not be held onto across anything that might free an AnchorNode.\n\t *\n\t * @remarks\n\t * Also ensures that any PathNode in the path is from this AnchorSet.\n\t */\n\tpublic internalizePath(originalPath: UpPath): UpPath {\n\t\tlet path: UpPath | undefined = originalPath;\n\t\tconst stack: UpPath[] = [];\n\t\twhile (path !== undefined) {\n\t\t\tif (path instanceof PathNode && path.anchorSet === this) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tstack.push(path);\n\t\t\tpath = path.parent;\n\t\t}\n\n\t\t// Now `path` contains an internalized path.\n\t\t// It just needs the paths from stackOut to wrap it.\n\n\t\tlet wrapWith: UpPath | undefined;\n\t\twhile ((wrapWith = stack.pop()) !== undefined) {\n\t\t\tif (path === undefined || path instanceof PathNode) {\n\t\t\t\t// If path already has an anchor, get an anchor for it's child if there is one:\n\t\t\t\tconst child = (path ?? this.root).childIfAnchored(\n\t\t\t\t\twrapWith.parentField,\n\t\t\t\t\twrapWith.parentIndex,\n\t\t\t\t);\n\t\t\t\tif (child !== undefined) {\n\t\t\t\t\tpath = child;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Replacing this if with a ternary makes the documentation harder to include and hurts readability.\n\t\t\t// eslint-disable-next-line unicorn/prefer-ternary\n\t\t\tif (path === wrapWith.parent && !(wrapWith instanceof PathNode)) {\n\t\t\t\t// path is safe to reuse from input path, so use it to avoid allocating another object.\n\t\t\t\tpath = wrapWith;\n\t\t\t} else {\n\t\t\t\tpath = {\n\t\t\t\t\tparent: path,\n\t\t\t\t\tparentField: wrapWith.parentField,\n\t\t\t\t\tparentIndex: wrapWith.parentIndex,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn path ?? fail(0xaea /* internalize path must be a path */);\n\t}\n\n\t/**\n\t * Recursively marks the given `nodes` and their descendants as disposed and pointing to a deleted node.\n\t * Note that this does NOT detach the nodes.\n\t */\n\tprivate deepDelete(nodes: readonly PathNode[]): void {\n\t\tconst stack = [...nodes];\n\t\twhile (stack.length > 0) {\n\t\t\tconst node = stack.pop()!;\n\t\t\tassert(node.status === Status.Alive, 0x408 /* PathNode must be alive */);\n\t\t\tnode.status = Status.Dangling;\n\t\t\tnode.events.emit(\"afterDestroy\", node);\n\t\t\tfor (const children of node.children.values()) {\n\t\t\t\tstack.push(...children);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Decouple nodes from their parent.\n\t * This removes the reference from the parent to the decoupled children, and updates the indexes of the remaining children accordingly.\n\t * This does NOT update the decoupled children: both their index and parent are left at their existing values.\n\t * To decouple and fixup the children, see `removeChildren` and `moveChildren`.\n\t * @param startPath - The path to the first node that is being decoupled.\n\t * @param count - number of siblings that are decoupled from the original tree.\n\t *\n\t * TODO: tests\n\t */\n\tprivate decoupleNodes(startPath: UpPath, count: number): PathNode[] {\n\t\tassert(count > 0, 0x681 /* count must be positive */);\n\n\t\tconst sourceParent = this.find(startPath.parent ?? this.root);\n\t\tconst sourceChildren = sourceParent?.children?.get(startPath.parentField);\n\t\tlet nodes: PathNode[] = [];\n\n\t\tif (sourceChildren !== undefined) {\n\t\t\tlet numberBeforeDecouple = 0;\n\t\t\tlet numberToDecouple = 0;\n\t\t\tlet index = 0;\n\t\t\twhile (\n\t\t\t\tindex < sourceChildren.length &&\n\t\t\t\tsourceChildren[index]!.parentIndex < startPath.parentIndex\n\t\t\t) {\n\t\t\t\tnumberBeforeDecouple++;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\twhile (\n\t\t\t\tindex < sourceChildren.length &&\n\t\t\t\tsourceChildren[index]!.parentIndex < startPath.parentIndex + count\n\t\t\t) {\n\t\t\t\tnumberToDecouple++;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\twhile (index < sourceChildren.length) {\n\t\t\t\t// Fix indexes in source after moved items (subtract count).\n\t\t\t\tsourceChildren[index]!.parentIndex -= count;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\t// Sever the parent -> child connections\n\t\t\tnodes = sourceChildren.splice(numberBeforeDecouple, numberToDecouple);\n\t\t\tif (sourceChildren.length === 0) {\n\t\t\t\tsourceParent!.afterEmptyField(startPath.parentField);\n\t\t\t}\n\t\t}\n\n\t\treturn nodes;\n\t}\n\n\t/**\n\t * Couple nodes to a parent.\n\t * @param destination - where the siblings are coupled to.\n\t * @param count - number of siblings that are coupled in the original tree.\n\t * @param coupleInfo - this object contains the nodes to couple and the parent index of the first node that is coupled in the original tree.\n\t *\n\t * TODO: tests\n\t */\n\tprivate coupleNodes(\n\t\tdestination: UpPath,\n\t\tcount: number,\n\t\tcoupleInfo: { startParentIndex: number; nodes: PathNode[] },\n\t): void {\n\t\tassert(coupleInfo.nodes.length > 0, 0x682 /* coupleInfo must have nodes to couple */);\n\n\t\t// The destination needs to be created if it does not exist yet.\n\t\tconst destinationPath = this.trackInner(destination.parent ?? this.root);\n\n\t\t// Update nodes for new parent.\n\t\tfor (const node of coupleInfo.nodes) {\n\t\t\tnode.parentIndex += destination.parentIndex - coupleInfo.startParentIndex;\n\t\t\tnode.parentPath = destinationPath;\n\t\t\tnode.parentField = destination.parentField;\n\t\t\t// If the destination is a detached root, propagate its detachedNodeId, otherwise remove any existing one\n\t\t\tnode.detachedNodeId = isDetachedUpPathRoot(destination)\n\t\t\t\t? offsetDetachId(\n\t\t\t\t\t\tdestination.detachedNodeId,\n\t\t\t\t\t\tnode.parentIndex - destination.parentIndex,\n\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\t}\n\n\t\t// Update new parent to add children\n\t\tconst field = destinationPath.children.get(destination.parentField);\n\t\tif (field === undefined) {\n\t\t\tdestinationPath.children.set(destination.parentField, coupleInfo.nodes);\n\t\t} else {\n\t\t\t// Update existing field contents\n\t\t\tconst numberBeforeCouple = this.increaseParentIndexes(\n\t\t\t\tfield,\n\t\t\t\tdestination.parentIndex,\n\t\t\t\tcount,\n\t\t\t);\n\n\t\t\t// TODO: this will fail for very large numbers of anchors due to argument limits.\n\t\t\tfield.splice(numberBeforeCouple, 0, ...coupleInfo.nodes);\n\t\t}\n\n\t\tdestinationPath.removeRef();\n\t}\n\n\t/**\n\t * Updates the parent indexes within `field` to account for `count` children being inserted at `fromParentIndex`. Note that\n\t * `fromParentIndex` is the logical position within the field, not the index with the sparse PathNode array.\n\t *\n\t * @param field - the field to update.\n\t * @param fromParentIndex - the logical index within the field to start updating from.\n\t * @param count - the number to increase parent indexes.\n\t * @returns the number of items in the field that are not increased.\n\t *\n\t * TODO: tests\n\t */\n\tprivate increaseParentIndexes(\n\t\tfield: PathNode[],\n\t\tfromParentIndex: number,\n\t\tcount: number,\n\t): number {\n\t\tlet index = 0;\n\t\twhile (index < field.length && field[index]!.parentIndex < fromParentIndex) {\n\t\t\tindex++;\n\t\t}\n\t\tconst numberBeforeIncrease = index;\n\t\twhile (index < field.length) {\n\t\t\tfield[index]!.parentIndex += count;\n\t\t\tindex++;\n\t\t}\n\n\t\treturn numberBeforeIncrease;\n\t}\n\n\t/**\n\t * Updates paths for a range move (including re-parenting path items and updating indexes).\n\t * @param sourceStart - where the siblings are removed from.\n\t * @param destination - where the siblings are moved to.\n\t * @param count - number of siblings to move.\n\t *\n\t * TODO:\n\t * How should anchors that become invalid, then valid again (ex: into content that was deleted, then undone) work?\n\t * Add an API to resurrect them? Store them in special detached fields? Store them in special non-detached fields?\n\t *\n\t * TODO:\n\t * How should custom anchors work (ex: ones not just tied to a specific Node)?\n\t * This design assumes they can be expressed in terms of a Node anchor + some extra stuff,\n\t * but we don't have an API for the extra stuff yet.\n\t *\n\t * TODO: tests\n\t */\n\tprivate moveChildren(sourceStart: UpPath, destination: UpPath, count: number): void {\n\t\tconst nodes = this.decoupleNodes(sourceStart, count);\n\t\tif (nodes.length > 0) {\n\t\t\tthis.coupleNodes(destination, count, {\n\t\t\t\tstartParentIndex: sourceStart.parentIndex,\n\t\t\t\tnodes,\n\t\t\t});\n\t\t} else {\n\t\t\t// If there are no nodes to move, we still need to update the parent indexes of the nodes\n\t\t\t// affected in the move in.\n\t\t\tthis.offsetChildren(destination, count);\n\t\t}\n\t}\n\n\tprivate removeChildren(path: UpPath, count: number): void {\n\t\tconst nodes = this.decoupleNodes(path, count);\n\t\tthis.deepDelete(nodes);\n\t}\n\n\t/**\n\t * Updates the parent indexes of all the nodes located at right side of the given path by the given offset.\n\t * @param firstSiblingToOffset - the path to offset children of.\n\t * @param offset - the offset to apply to the children.\n\t *\n\t */\n\tprivate offsetChildren(firstSiblingToOffset: UpPath, offset: number): void {\n\t\tconst nodePath = this.find(firstSiblingToOffset.parent ?? this.root);\n\t\tconst field = nodePath?.children.get(firstSiblingToOffset.parentField);\n\t\tif (field !== undefined) {\n\t\t\tthis.increaseParentIndexes(field, firstSiblingToOffset.parentIndex, offset);\n\t\t}\n\t}\n\n\t/**\n\t * Provides a visitor that can be used to mutate this {@link AnchorSet}.\n\t *\n\t * @returns A visitor that can be used to mutate this {@link AnchorSet}.\n\t *\n\t * @remarks\n\t * Mutating the {@link AnchorSet} does NOT update the forest.\n\t * The visitor must be released after use by calling {@link DeltaVisitor.free} on it.\n\t * It is invalid to acquire a visitor without releasing the previous one,\n\t * and this method will throw an error if this is attempted.\n\t */\n\tpublic acquireVisitor(): DeltaVisitor {\n\t\tassert(\n\t\t\tthis.activeVisitor === undefined,\n\t\t\t0x767 /* Must release existing visitor before acquiring another */,\n\t\t);\n\n\t\tconst referencedPathNodes: PathNode[] = [];\n\t\tconst visitor = {\n\t\t\tanchorSet: this,\n\t\t\t// Run `withNode` on anchorNode for parent if there is such an anchorNode.\n\t\t\t// If at root, run `withRoot` instead.\n\t\t\tmaybeWithNode(withNode: (anchorNode: PathNode) => void, withRoot?: () => void) {\n\t\t\t\tif (this.parent === undefined && withRoot !== undefined) {\n\t\t\t\t\twithRoot();\n\t\t\t\t} else {\n\t\t\t\t\tassert(this.parent !== undefined, 0x5b0 /* parent must exist */);\n\t\t\t\t\t// TODO:Perf:\n\t\t\t\t\t// When traversing to a depth D when there are not anchors in that subtree, this goes O(D^2).\n\t\t\t\t\t// Delta traversal should early out in this case because no work is needed (and all move outs are known to not contain anchors).\n\t\t\t\t\tthis.parent = this.anchorSet.internalizePath(this.parent);\n\t\t\t\t\tif (this.parent instanceof PathNode) {\n\t\t\t\t\t\tthis.parent.addRef();\n\t\t\t\t\t\treferencedPathNodes.push(this.parent);\n\t\t\t\t\t\twithNode(this.parent);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tparentField: undefined as FieldKey | undefined,\n\t\t\tparent: undefined as UpPath | undefined,\n\n\t\t\t/**\n\t\t\t * Events collected during the visit which get sent as a batch during \"free\".\n\t\t\t */\n\t\t\tbufferedEvents: [] as BufferedEvent[],\n\n\t\t\t/**\n\t\t\t * 'currentDepth' and 'depthThresholdForSubtreeChanged' serve to keep track of when do we need to emit\n\t\t\t * subtreeChangedAfterBatch events.\n\t\t\t * The algorithm works as follows:\n\t\t\t *\n\t\t\t * - Initialize both to 0.\n\t\t\t * - As we walk the tree from the root towards the leaves, when we enter a node increment currentDepth by 1.\n\t\t\t * - When we edit a node, set depthThresholdForSubtreeChanged = currentDepth.\n\t\t\t * Intuitively, depthThresholdForSubtreeChanged means \"as you walk the tree towards the root, when you exit a\n\t\t\t * node at this depth you should emit a subtreeChangedAfterBatch event\".\n\t\t\t * - When we exit a node, if d === currentDepth then emit a subtreeChangedAfterBatch and decrement d by 1.\n\t\t\t * Then decrement currentDepth unconditionally.\n\t\t\t *\n\t\t\t * Note that the event will be emitted when exiting a node that was edited (depthThresholdForSubtreeChanged will\n\t\t\t * have been set to the current depth when the edit happened), it will be emitted when exiting a node that is the\n\t\t\t * parent of a node that already emitted the event (because both depthThresholdForSubtreeChanged and currentDepth\n\t\t\t * get decremented when exiting a node so they stay in sync), and if we're already emitting the event but start\n\t\t\t * walking the tree back towards the leaves in a path where no edits happen, currentDepth will be increased again\n\t\t\t * as we walk that path, depthThresholdForSubtreeChanged will not, and thus no event will be emitted when walking\n\t\t\t * back up that path, until we get back to the depth where we were already emitting the event, and will continue\n\t\t\t * emitting it on the way to the root.\n\t\t\t */\n\t\t\tcurrentDepth: 0,\n\t\t\t/**\n\t\t\t * See {@link visitor.currentDepth}.\n\t\t\t */\n\t\t\tdepthThresholdForSubtreeChanged: 0,\n\n\t\t\tfree() {\n\t\t\t\tassert(\n\t\t\t\t\tthis.anchorSet.activeVisitor !== undefined,\n\t\t\t\t\t0x768 /* Multiple free calls for same visitor */,\n\t\t\t\t);\n\t\t\t\tfor (const node of referencedPathNodes) {\n\t\t\t\t\tnode.removeRef();\n\t\t\t\t}\n\t\t\t\tthis.anchorSet.activeVisitor = undefined;\n\n\t\t\t\t// Aggregate changedFields by node.\n\t\t\t\tconst eventsByNode: Map<PathNode, Set<FieldKey>> = new Map();\n\t\t\t\tfor (const { node, event, changedField } of this.bufferedEvents) {\n\t\t\t\t\tif (event === \"childrenChangedAfterBatch\") {\n\t\t\t\t\t\tconst keys = getOrCreate(eventsByNode, node, () => new Set());\n\t\t\t\t\t\tkeys.add(\n\t\t\t\t\t\t\tchangedField ??\n\t\t\t\t\t\t\t\tfail(0xb57 /* childrenChangedAfterBatch events should have a changedField */),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst alreadyEmitted = new Map<PathNode, (keyof AnchorEvents)[]>();\n\t\t\t\tfor (const { node, event } of this.bufferedEvents) {\n\t\t\t\t\tconst emittedEvents = getOrAddEmptyToMap(alreadyEmitted, node);\n\t\t\t\t\tif (emittedEvents.includes(event)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\temittedEvents.push(event);\n\t\t\t\t\tif (event === \"childrenChangedAfterBatch\") {\n\t\t\t\t\t\tconst changedFields =\n\t\t\t\t\t\t\teventsByNode.get(node) ??\n\t\t\t\t\t\t\tfail(0xaeb /* childrenChangedAfterBatch events should have changedFields */);\n\t\t\t\t\t\tnode.events.emit(event, { changedFields });\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnode.events.emit(event);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tnotifyChildrenChanging(): void {\n\t\t\t\tthis.maybeWithNode(\n\t\t\t\t\t(p) => p.events.emit(\"childrenChanging\", p),\n\t\t\t\t\t() => this.anchorSet.#events.emit(\"childrenChanging\", this.anchorSet),\n\t\t\t\t);\n\t\t\t},\n\t\t\tnotifyChildrenChanged(): void {\n\t\t\t\tthis.maybeWithNode(\n\t\t\t\t\t(p) => {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tthis.parentField !== undefined,\n\t\t\t\t\t\t\t0xa24 /* Must be in a field to modify its contents */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tp.events.emit(\"childrenChanged\", p);\n\t\t\t\t\t\tthis.bufferedEvents.push({\n\t\t\t\t\t\t\tnode: p,\n\t\t\t\t\t\t\tevent: \"childrenChangedAfterBatch\",\n\t\t\t\t\t\t\tchangedField: this.parentField,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\t() => {},\n\t\t\t\t);\n\t\t\t},\n\t\t\tattach(source: FieldKey, count: number, destination: PlaceIndex): void {\n\t\t\t\tthis.notifyChildrenChanging();\n\t\t\t\tthis.attachEdit(source, count, destination);\n\t\t\t\tthis.notifyChildrenChanged();\n\t\t\t},\n\t\t\tattachEdit(source: FieldKey, count: number, destination: PlaceIndex): void {\n\t\t\t\tassert(\n\t\t\t\t\tthis.parentField !== undefined,\n\t\t\t\t\t0x7a2 /* Must be in a field in order to attach */,\n\t\t\t\t);\n\t\t\t\tconst sourcePath = {\n\t\t\t\t\tparent: this.anchorSet.root,\n\t\t\t\t\tparentField: source,\n\t\t\t\t\tparentIndex: 0,\n\t\t\t\t};\n\t\t\t\tconst destinationPath = {\n\t\t\t\t\tparent: this.parent,\n\t\t\t\t\tparentField: this.parentField,\n\t\t\t\t\tparentIndex: destination,\n\t\t\t\t};\n\t\t\t\tthis.anchorSet.moveChildren(sourcePath, destinationPath, count);\n\t\t\t\tthis.depthThresholdForSubtreeChanged = this.currentDepth;\n\t\t\t},\n\t\t\tdetach(\n\t\t\t\tsource: Range,\n\t\t\t\tdestination: FieldKey,\n\t\t\t\tdetachedNodeId: Delta.DetachedNodeId,\n\t\t\t): void {\n\t\t\t\tthis.notifyChildrenChanging();\n\t\t\t\tthis.detachEdit(source, destination, detachedNodeId);\n\t\t\t\tthis.notifyChildrenChanged();\n\t\t\t},\n\t\t\tdetachEdit(\n\t\t\t\tsource: Range,\n\t\t\t\tdestination: FieldKey,\n\t\t\t\tdetachedNodeId: Delta.DetachedNodeId,\n\t\t\t): void {\n\t\t\t\tassert(\n\t\t\t\t\tthis.parentField !== undefined,\n\t\t\t\t\t0x7a5 /* Must be in a field in order to detach */,\n\t\t\t\t);\n\t\t\t\tconst sourcePath: UpPath = {\n\t\t\t\t\tparent: this.parent,\n\t\t\t\t\tparentField: this.parentField,\n\t\t\t\t\tparentIndex: source.start,\n\t\t\t\t};\n\t\t\t\tconst destinationPath: NormalizedUpPath = {\n\t\t\t\t\tparent: this.anchorSet.root,\n\t\t\t\t\tparentField: destination,\n\t\t\t\t\tparentIndex: 0,\n\t\t\t\t\tdetachedNodeId,\n\t\t\t\t};\n\t\t\t\tthis.anchorSet.moveChildren(sourcePath, destinationPath, source.end - source.start);\n\t\t\t\tthis.depthThresholdForSubtreeChanged = this.currentDepth;\n\t\t\t},\n\t\t\treplace(\n\t\t\t\tnewContentSource: FieldKey,\n\t\t\t\trange: Range,\n\t\t\t\toldContentDestination: FieldKey,\n\t\t\t\tdestinationDetachedNodeId: Delta.DetachedNodeId,\n\t\t\t): void {\n\t\t\t\tthis.notifyChildrenChanging();\n\t\t\t\tthis.detachEdit(range, oldContentDestination, destinationDetachedNodeId);\n\t\t\t\tthis.attachEdit(newContentSource, range.end - range.start, range.start);\n\t\t\t\tthis.notifyChildrenChanged();\n\t\t\t},\n\t\t\tdestroy(detachedField: FieldKey, count: number): void {\n\t\t\t\tthis.anchorSet.removeChildren(\n\t\t\t\t\t{\n\t\t\t\t\t\tparent: undefined,\n\t\t\t\t\t\tparentField: detachedField,\n\t\t\t\t\t\tparentIndex: 0,\n\t\t\t\t\t},\n\t\t\t\t\tcount,\n\t\t\t\t);\n\t\t\t},\n\t\t\tcreate(content: ITreeCursorSynchronous[], destination: FieldKey): void {\n\t\t\t\t// Nothing to do since content can only be created in a new detached field,\n\t\t\t\t// which cannot contain any anchors.\n\t\t\t},\n\t\t\tenterNode(index: number): void {\n\t\t\t\tassert(this.parentField !== undefined, 0x3ab /* Must be in a field to enter node */);\n\n\t\t\t\tthis.parent = {\n\t\t\t\t\tparent: this.parent,\n\t\t\t\t\tparentField: this.parentField,\n\t\t\t\t\tparentIndex: index,\n\t\t\t\t};\n\t\t\t\tthis.parentField = undefined;\n\t\t\t\tthis.maybeWithNode((p) => {\n\t\t\t\t\tp.events.emit(\"subtreeChanging\", p);\n\t\t\t\t});\n\t\t\t\tthis.currentDepth++;\n\t\t\t},\n\t\t\texitNode(index: number): void {\n\t\t\t\tassert(this.parent !== undefined, 0x3ac /* Must have parent node */);\n\t\t\t\tif (this.depthThresholdForSubtreeChanged === this.currentDepth) {\n\t\t\t\t\tthis.maybeWithNode((p) => {\n\t\t\t\t\t\tp.events.emit(\"subtreeChanged\", p);\n\n\t\t\t\t\t\tthis.bufferedEvents.push({\n\t\t\t\t\t\t\tnode: p,\n\t\t\t\t\t\t\tevent: \"subtreeChangedAfterBatch\",\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t\tthis.depthThresholdForSubtreeChanged--;\n\t\t\t\t}\n\t\t\t\tconst parent = this.parent;\n\t\t\t\tthis.parentField = parent.parentField;\n\t\t\t\tthis.parent = parent.parent;\n\t\t\t\tthis.currentDepth--;\n\t\t\t},\n\t\t\tenterField(key: FieldKey): void {\n\t\t\t\tthis.parentField = key;\n\t\t\t},\n\t\t\texitField(key: FieldKey): void {\n\t\t\t\tthis.parentField = undefined;\n\t\t\t},\n\t\t};\n\t\tthis.#events.emit(\"treeChanging\", this);\n\t\tthis.activeVisitor = visitor;\n\t\treturn visitor;\n\t}\n}\n\n/**\n * Indicates the status of a `NodePath`.\n */\nenum Status {\n\t/**\n\t * Indicates the `NodePath` is being maintained and corresponds to a valid\n\t * (i.e., not removed) node in the document.\n\t */\n\tAlive,\n\t/**\n\t * Indicates the `NodePath` is not being maintained by the `AnchorSet`.\n\t * The `NodePath` may or may not correspond to a valid node in the document.\n\t *\n\t * Accessing such a node is invalid.\n\t * Nodes in this state are retained to detect use-after-free bugs.\n\t */\n\tDisposed,\n\t/**\n\t * Indicates the `NodePath` corresponds to a removed node in the document.\n\t * Such `NodePath`s are not maintained by the `AnchorSet` (other than updating\n\t * their status to `Disposed` when appropriate).\n\t *\n\t * Accessing such a node is invalid.\n\t * Nodes in this state are retained to detect use-after-free bugs.\n\t */\n\tDangling,\n}\n\n/**\n * Tree of anchors.\n *\n * Contains both child and parent pointers, which are kept in sync.\n *\n * Each anchor is equivalent to a path through the tree.\n * This tree structure stores a collection of these paths, but deduplicating the common prefixes of the tree\n * prefix-tree style.\n *\n * These anchors are used instead of just holding onto the node objects in forests for several reasons:\n *\n * - Update policy might be more complex than just tracking a node object in the forest.\n *\n * - Not all forests will have node objects: some may use compressed binary formats with no objects to reference.\n *\n * - Anchors are needed even when not using forests, and for nodes that are outside the currently loaded part of the\n * forest.\n *\n * - Forest in general do not need to support up pointers, but they are needed for anchors.\n *\n * Thus this can be thought of as a sparse copy of the subset of trees which are used as anchors,\n * plus the parent paths for them.\n *\n * ReferenceCountedBase tracks the number of references to this from external sources (`Anchors` via `AnchorSet`.).\n * Kept alive as if any of the follow are true:\n * 1. there are children.\n * 2. refcount is non-zero.\n * 3. events are registered.\n */\nclass PathNode extends ReferenceCountedBase implements AnchorNode {\n\tpublic status: Status = Status.Alive;\n\t/**\n\t * Event emitter for this anchor.\n\t */\n\tpublic readonly events = createEmitter<AnchorEvents>(this.considerDispose.bind(this));\n\n\t/**\n\t * PathNode arrays are kept sorted the PathNode's parentIndex for efficient search.\n\t * Users of this field must take care to maintain invariants (correct parent pointers, not empty child arrays etc.)\n\t *\n\t * Performance Note:\n\t * Large child lists could be updated more efficiently here using a data-structure optimized\n\t * for efficient prefix sum updates, such as a Fenwick tree or Finger tree.\n\t * This would be complicated by the need for parent pointers (including indexes),\n\t * but is possible to do.\n\t */\n\tpublic readonly children: Map<FieldKey, PathNode[]> = new Map();\n\n\t// See note on BrandedKey.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic readonly slots: BrandedMapSubset<AnchorSlot<any>> = new Map();\n\n\t/**\n\t * {@inheritdoc UpPath.detachedNodeId}\n\t */\n\tpublic detachedNodeId: Delta.DetachedNodeId | undefined;\n\n\t/**\n\t * Construct a PathNode with refcount 1.\n\t * @param anchorSet - used to determine if this PathNode is already part of a specific anchorSet\n\t * to early out UpPath walking.\n\t */\n\tpublic constructor(\n\t\tpublic readonly anchorSet: AnchorSet,\n\t\tpublic parentField: FieldKey,\n\t\tpublic parentIndex: number,\n\t\t/**\n\t\t * The parent of this `PathNode` (an up pointer in the `PathNode` tree).\n\t\t * If the status of this node is `Alive`, then there must be a corresponding down pointer from the\n\t\t * `parentPath` node to this node.\n\t\t * When undefined, this node is the {@link AnchorSet.root} for `this.anchorSet` and thus has no parent.\n\t\t *\n\t\t * When updating the tree, `AnchorSet` may transiently leave the up and down pointers inconsistent\n\t\t * (updating down pointers first), but must ensure they are consistent before the editing operation returns\n\t\t * to non-`AnchorSet` code.\n\t\t * This consistency guarantee only applies to nodes that are `Alive`.\n\t\t */\n\t\tpublic parentPath: PathNode | undefined,\n\t) {\n\t\tsuper(1);\n\t}\n\n\tpublic child(key: FieldKey, index: number): UpPath<AnchorNode> {\n\t\t// Fast path: if child exists, return it.\n\t\treturn (\n\t\t\tthis.childIfAnchored(key, index) ?? {\n\t\t\t\tparent: this,\n\t\t\t\tparentField: key,\n\t\t\t\tparentIndex: index,\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic getOrCreateChildRef(key: FieldKey, index: number): [Anchor, AnchorNode] {\n\t\tconst anchor = this.anchorSet.track(this.child(key, index));\n\t\tconst node =\n\t\t\tthis.anchorSet.locate(anchor) ??\n\t\t\tfail(0xaec /* cannot reference child that does not exist */);\n\t\treturn [anchor, node];\n\t}\n\n\t/**\n\t * Whether or not this `PathNode` is the special root node that sits above all the detached fields.\n\t * @remarks\n\t * In this case, the fields are detached sequences.\n\t * Note that the special root node should never appear in an UpPath\n\t * since UpPaths represent this root as `undefined`.\n\t */\n\tprivate isRoot(): boolean {\n\t\treturn this.parentPath === undefined;\n\t}\n\n\tpublic get parent(): PathNode | undefined {\n\t\tassert(this.status !== Status.Disposed, 0x409 /* PathNode must not be disposed */);\n\t\tassert(\n\t\t\tthis.parentPath !== undefined,\n\t\t\t0x355 /* PathNode.parent is an UpPath API and thus should never be called on the root PathNode. */,\n\t\t);\n\t\t// Root PathNode corresponds to the undefined root for UpPath API.\n\t\tif (this.parentPath.isRoot()) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.parentPath;\n\t}\n\n\tpublic addRef(count = 1): void {\n\t\tassert(this.status === Status.Alive, 0x40a /* PathNode must be alive */);\n\t\tthis.referenceAdded(count);\n\t}\n\n\tpublic removeRef(count = 1): void {\n\t\tassert(this.status !== Status.Disposed, 0x40b /* PathNode must not be disposed */);\n\t\tthis.referenceRemoved(count);\n\t}\n\n\t// Called when refcount is set to 0.\n\t// Node may be kept alive by children or events after this point.\n\tprotected onUnreferenced(): void {\n\t\tthis.considerDispose();\n\t}\n\n\t/**\n\t * Gets a child, adding a ref to it.\n\t * Creates child (with 1 ref) if needed.\n\t */\n\tpublic getOrCreateChild(key: FieldKey, index: number): PathNode {\n\t\tassert(this.status === Status.Alive, 0x40c /* PathNode must be alive */);\n\t\tlet field = this.children.get(key);\n\t\tif (field === undefined) {\n\t\t\tfield = [];\n\t\t\tthis.children.set(key, field);\n\t\t}\n\t\tlet child = binaryFind(field, index);\n\t\tif (child === undefined) {\n\t\t\tchild = new PathNode(this.anchorSet, key, index, this);\n\t\t\tfield.push(child);\n\t\t\t// Keep list sorted by index.\n\t\t\tfield.sort((a, b) => a.parentIndex - b.parentIndex);\n\t\t} else {\n\t\t\tchild.addRef();\n\t\t}\n\t\treturn child;\n\t}\n\n\tpublic childIfAnchored(key: FieldKey, index: number): PathNode | undefined {\n\t\tassert(this.status === Status.Alive, 0x40d /* PathNode must be alive */);\n\t\tconst field = this.children.get(key);\n\n\t\treturn field === undefined ? undefined : binaryFind(field, index);\n\t}\n\n\t/**\n\t * Removes reference from this to `child`.\n\t * Since PathNodes are doubly linked,\n\t * the caller must ensure that the reference from child to parent is also removed (or the child is no longer used).\n\t */\n\tpublic removeChild(child: PathNode): void {\n\t\tassert(this.status === Status.Alive, 0x40e /* PathNode must be alive */);\n\t\tconst key = child.parentField;\n\t\tconst field = this.children.get(key);\n\t\t// TODO: should do more optimized search (ex: binary search or better) using child.parentIndex()\n\t\t// Note that this is the index in the list of child paths, not the index within the field\n\t\tconst childIndex = field?.indexOf(child) ?? -1;\n\t\tassert(childIndex !== -1, 0x35c /* child must be parented to be removed */);\n\t\tfield?.splice(childIndex, 1);\n\t\tif (field?.length === 0) {\n\t\t\tthis.afterEmptyField(key);\n\t\t}\n\t}\n\n\t/**\n\t * Call this after directly editing the child array for a field to be empty.\n\t * Handles cleaning up unneeded data\n\t * (like the field in the map, and possibly this entire PathNode and its parents if they are no longer needed.)\n\t */\n\tpublic afterEmptyField(key: FieldKey): void {\n\t\tassert(this.status === Status.Alive, 0x40f /* PathNode must be alive */);\n\t\tthis.children.delete(key);\n\t\tthis.considerDispose();\n\t}\n\n\t/**\n\t * If node is no longer needed (has no references, no children and no events):\n\t * removes this from parent if alive, and sets this to disposed.\n\t * Must only be called when .\n\t *\n\t * Allowed when dangling (but not when disposed).\n\t */\n\tprivate considerDispose(): void {\n\t\tassert(this.status !== Status.Disposed, 0x41d /* PathNode must not be disposed */);\n\t\tif (this.isUnreferenced() && this.children.size === 0 && !this.events.hasListeners()) {\n\t\t\tif (this.status === Status.Alive) {\n\t\t\t\t// eslint-disable-next-line unicorn/prefer-dom-node-remove -- Custom tree structure, not DOM\n\t\t\t\tthis.parentPath?.removeChild(this);\n\t\t\t}\n\t\t\tthis.status = Status.Disposed;\n\t\t}\n\t}\n}\n\n/**\n * Find a child PathNode by index using a binary search.\n * @param sorted - array of PathNode's sorted by parentIndex.\n * @param index - index being looked for.\n * @returns child with the requested parentIndex, or undefined.\n * @privateRemarks\n * This function is very commonly used with small arrays (length 0 or one for all non sequence fields),\n * and is currently a hot path due to how flex tree leaves to excessive cursor to anchor and anchor to cursor translations,\n * both of which walk paths down the AnchorSet.\n * Additionally current usages tends to fully populate the anchor tree leading the correct array index to be the requested parent index.\n * This makes the performance of this performance both important in small cases and easy to overly tune to the current usage patterns.\n * This lead to not implementing a general purpose reusable binary search.\n * Once this function is not so heavily overused due to inefficient patterns in flex-tree,\n * replacing it with a standard binary search is likely fine.\n * Until then, care and benchmarking should be used when messing with this function.\n */\nfunction binaryFind(sorted: readonly PathNode[], index: number): PathNode | undefined {\n\t// Try guessing the list is not sparse as a starter:\n\tconst guess = sorted[index];\n\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- using ?. could change behavior\n\tif (guess !== undefined && guess.parentIndex === index) {\n\t\treturn guess;\n\t}\n\n\t// inclusive\n\tlet min = 0;\n\t// exclusive\n\tlet max = sorted.length;\n\n\twhile (min !== max) {\n\t\tconst mid = Math.floor((min + max) / 2);\n\t\tconst item = sorted[mid]!;\n\t\tconst found = item.parentIndex;\n\t\tif (found === index) {\n\t\t\treturn item; // Found the target, return it.\n\t\t} else if (found > index) {\n\t\t\tmax = mid; // Continue search on lower half.\n\t\t} else {\n\t\t\tmin = mid + 1; // Continue search on left half.\n\t\t}\n\t}\n\treturn undefined; // If we reach here, target is not in array (or array was not sorted)\n}\n\ninterface BufferedEvent {\n\tnode: PathNode;\n\tevent: keyof AnchorEvents;\n\t/**\n\t * The key for the impacted field, if the event is associated with a key.\n\t * Some events, such as afterDestroy, do not involve a key, and thus leave this undefined.\n\t */\n\tchangedField?: FieldKey;\n}\n"]}
@@ -180,11 +180,13 @@ export interface DetachedNodeRename {
180
180
  readonly oldId: DetachedNodeId;
181
181
  readonly newId: DetachedNodeId;
182
182
  }
183
- /**
184
- * Represents a list of changes to the nodes in the field.
185
- * The index of each mark within the range of nodes, before
186
- * applying any of the changes, is not represented explicitly.
187
- * It corresponds to the sum of `mark.count` values for all previous marks for which `isAttachMark(mark)` is false.
188
- */
189
- export type FieldChanges = readonly Mark[];
183
+ export interface FieldChanges {
184
+ /**
185
+ * Represents a list of changes to the nodes in the field.
186
+ * The index of each mark within the range of nodes, before
187
+ * applying any of the changes, is not represented explicitly.
188
+ * It corresponds to the sum of `mark.count` values for all previous marks for which `isAttachMark(mark)` is false.
189
+ */
190
+ readonly marks: readonly Mark[];
191
+ }
190
192
  //# sourceMappingURL=delta.d.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Ac,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;CAC1B;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB,CAAC,MAAM,GAAG,UAAU;IACrD,QAAQ,CAAC,EAAE,EAAE,cAAc,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,EAAE,EAAE,cAAc,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;CAC/B;AAED,MAAM,WAAW,YAAY;IAC5B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;CAChC"}
@@ -1 +1 @@
1
- {"version":3,"file":"delta.js","sourceRoot":"","sources":["../../../src/core/tree/delta.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { RevisionTag } from \"../rebase/index.js\";\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport type { TreeChunk } from \"./chunk.js\";\n\n/**\n * This format describes changes that must be applied to a forest in order to update it.\n * Instances of this format are generated based on incoming changesets and consumed by a view layer (e.g., Forest) to\n * update itself.\n *\n * Because this format is only meant for updating document state, it does not fully represent user intentions.\n * For example, if some concurrent edits A and B insert content at the same location, then a Delta that represents\n * represents the state update for edit A would not include information that allows B's insertion to be ordered\n * relative to A's insertion. This format is therefore not fit to be rebased in the face of concurrent changes.\n * Instead this format is used to describe the end product of rebasing user intentions over concurrent edits.\n *\n * This format is self-contained in the following ways:\n *\n * 1. It uses integer indices (offsets, technically) to describe the locations of necessary changes.\n * As such, it does not rely on document nodes being accessible/locatable by ID.\n *\n * 2. This format does not require historical information in order to apply the changes it describes.\n * For example, if a user undoes the deletion of a subtree, then the Delta generated for the undo edit will contain all\n * information necessary to restore that subtree.\n *\n * This format can be generated from any Changeset without having access to the current document state.\n *\n * This format is meant to serve as the lowest common denominator to represent state changes resulting from any kind\n * of operation on any kind of field.\n * This means all such operations must be expressible in terms of this format.\n *\n * Within the above design constrains, this format is designed with the following goals in mind:\n *\n * 1. Make it easy to walk both a document tree and the delta tree to apply the changes described in the delta\n * with a minimum amount of backtracking over the contents of the tree.\n * This a boon for both code simplicity and performance.\n *\n * 2. Make the format terse.\n *\n * 3. Make the format uniform.\n *\n * These goals are reflected in the following design choices (this is very much optional reading for users of this\n * format):\n *\n * 1. All marks that apply to field elements are represented in a single linear structure where marks that affect later\n * elements of the document field appear after marks that affect earlier elements of the document field.\n *\n * If the marks were not ordered in this fashion then a consumer would need to backtrack within the document field.\n *\n * If the marks were represented in multiple such linear structures then it would be necessary to either:\n * - backtrack when iterating over one structure fully, then the next\n * - maintain a pointer within each such linear structure and advance them in lock-step (like in a k-way merge-sort but\n * more fiddly because of the offsets).\n *\n * 2. Nested changes are not inlined within `ProtoNode`s.\n *\n * Inlining them would force the consuming code to detect such changes within the `ProtoNode` and handle them\n * within the context of the content creation.\n * This would be cumbersome because either the code that is responsible for consuming the `ProtoNode` would need to\n * be aware of and have the context to handle such changes, or some caller of that code would need to find and extract such\n * change information ahead to calling that code.\n */\n\n/**\n * Represents the change made to a document.\n * Immutable, therefore safe to retain for async processing.\n */\nexport interface Root<TTrees = ProtoNodes> {\n\t/**\n\t * Changes to apply to the root fields.\n\t */\n\treadonly fields?: FieldMap;\n\t/**\n\t * New detached nodes to be constructed.\n\t * The ordering has no significance.\n\t *\n\t * Build instructions for a root that is undergoing a rename should be listed under the starting name.\n\t * For example, if one wishes to build a tree which is being renamed from ID A to ID B,\n\t * then the build should be listed under ID A.\n\t */\n\treadonly build?: readonly DetachedNodeBuild<TTrees>[];\n\t/**\n\t * New detached nodes to be destroyed.\n\t * The ordering has no significance.\n\t *\n\t * Destruction instructions for a root that is undergoing a rename should be listed under the final name.\n\t * For example, if one wishes to destroy a tree which is being renamed from ID A to ID B,\n\t * then the destruction should be listed under ID B.\n\t */\n\treadonly destroy?: readonly DetachedNodeDestruction[];\n\t/**\n\t * Refreshers for detached nodes that may need to be recreated.\n\t * The ordering has no significance.\n\t */\n\treadonly refreshers?: readonly DetachedNodeBuild<TTrees>[];\n\t/**\n\t * Changes to apply to detached nodes.\n\t * The ordering has no significance.\n\t *\n\t * Nested changes for a root that is undergoing a rename should be listed under the starting name.\n\t * For example, if one wishes to change a tree which is being renamed from ID A to ID B,\n\t * then the changes should be listed under ID A.\n\t */\n\treadonly global?: readonly DetachedNodeChanges[];\n\t/**\n\t * Detached roots whose associated ID needs to be updated.\n\t * The ordering has no significance.\n\t * Note that the renames may need to be performed in a specific order to avoid collisions.\n\t * This ordering problem is left to the consumer of this format.\n\t */\n\treadonly rename?: readonly DetachedNodeRename[];\n}\n\n/**\n * The default representation for a chunk (sub-sequence) of inserted content.\n */\nexport type ProtoNodes = TreeChunk;\n\n/**\n * Represents a change being made to a part of the document tree.\n */\nexport interface Mark {\n\t/**\n\t * The number of nodes affected.\n\t * When `isAttachMark(mark)` is true, this is the number of new nodes being attached.\n\t * When `isAttachMark(mark)` is false, this the number of existing nodes affected.\n\t * Must be 1 when `fields` is populated.\n\t */\n\treadonly count: number;\n\n\t/**\n\t * Modifications to the pre-existing content.\n\t * Must be undefined when `attach` is set but `detach` is not.\n\t */\n\treadonly fields?: FieldMap;\n\n\t/**\n\t * When set, indicates that some pre-existing content is being detached and sent to the given detached field.\n\t */\n\treadonly detach?: DetachedNodeId;\n\n\t/**\n\t * When set, indicates that some content is being attached from the given detached field.\n\t */\n\treadonly attach?: DetachedNodeId;\n}\n\n/**\n * A globally unique ID for a node in a detached field.\n */\nexport interface DetachedNodeId {\n\treadonly major?: RevisionTag;\n\treadonly minor: number;\n}\n\nexport type FieldMap = ReadonlyMap<FieldKey, FieldChanges>;\n\n/**\n * Represents changes made to a detached node\n */\nexport interface DetachedNodeChanges {\n\treadonly id: DetachedNodeId;\n\treadonly fields: FieldMap;\n}\n\n/**\n * Represents the creation of detached nodes.\n *\n * Tree creation is idempotent: if a tree with the same ID already exists,\n * then this build is ignored in favor of the existing tree.\n */\nexport interface DetachedNodeBuild<TTrees = ProtoNodes> {\n\treadonly id: DetachedNodeId;\n\treadonly trees: TTrees;\n}\n\n/**\n * Represents the destruction of detached nodes\n */\nexport interface DetachedNodeDestruction {\n\treadonly id: DetachedNodeId;\n\treadonly count: number;\n}\n\n/**\n * Represents a detached node being assigned a new `DetachedNodeId`.\n */\nexport interface DetachedNodeRename {\n\treadonly count: number;\n\treadonly oldId: DetachedNodeId;\n\treadonly newId: DetachedNodeId;\n}\n\n/**\n * Represents a list of changes to the nodes in the field.\n * The index of each mark within the range of nodes, before\n * applying any of the changes, is not represented explicitly.\n * It corresponds to the sum of `mark.count` values for all previous marks for which `isAttachMark(mark)` is false.\n */\nexport type FieldChanges = readonly Mark[];\n"]}
1
+ {"version":3,"file":"delta.js","sourceRoot":"","sources":["../../../src/core/tree/delta.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { RevisionTag } from \"../rebase/index.js\";\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport type { TreeChunk } from \"./chunk.js\";\n\n/**\n * This format describes changes that must be applied to a forest in order to update it.\n * Instances of this format are generated based on incoming changesets and consumed by a view layer (e.g., Forest) to\n * update itself.\n *\n * Because this format is only meant for updating document state, it does not fully represent user intentions.\n * For example, if some concurrent edits A and B insert content at the same location, then a Delta that represents\n * represents the state update for edit A would not include information that allows B's insertion to be ordered\n * relative to A's insertion. This format is therefore not fit to be rebased in the face of concurrent changes.\n * Instead this format is used to describe the end product of rebasing user intentions over concurrent edits.\n *\n * This format is self-contained in the following ways:\n *\n * 1. It uses integer indices (offsets, technically) to describe the locations of necessary changes.\n * As such, it does not rely on document nodes being accessible/locatable by ID.\n *\n * 2. This format does not require historical information in order to apply the changes it describes.\n * For example, if a user undoes the deletion of a subtree, then the Delta generated for the undo edit will contain all\n * information necessary to restore that subtree.\n *\n * This format can be generated from any Changeset without having access to the current document state.\n *\n * This format is meant to serve as the lowest common denominator to represent state changes resulting from any kind\n * of operation on any kind of field.\n * This means all such operations must be expressible in terms of this format.\n *\n * Within the above design constrains, this format is designed with the following goals in mind:\n *\n * 1. Make it easy to walk both a document tree and the delta tree to apply the changes described in the delta\n * with a minimum amount of backtracking over the contents of the tree.\n * This a boon for both code simplicity and performance.\n *\n * 2. Make the format terse.\n *\n * 3. Make the format uniform.\n *\n * These goals are reflected in the following design choices (this is very much optional reading for users of this\n * format):\n *\n * 1. All marks that apply to field elements are represented in a single linear structure where marks that affect later\n * elements of the document field appear after marks that affect earlier elements of the document field.\n *\n * If the marks were not ordered in this fashion then a consumer would need to backtrack within the document field.\n *\n * If the marks were represented in multiple such linear structures then it would be necessary to either:\n * - backtrack when iterating over one structure fully, then the next\n * - maintain a pointer within each such linear structure and advance them in lock-step (like in a k-way merge-sort but\n * more fiddly because of the offsets).\n *\n * 2. Nested changes are not inlined within `ProtoNode`s.\n *\n * Inlining them would force the consuming code to detect such changes within the `ProtoNode` and handle them\n * within the context of the content creation.\n * This would be cumbersome because either the code that is responsible for consuming the `ProtoNode` would need to\n * be aware of and have the context to handle such changes, or some caller of that code would need to find and extract such\n * change information ahead to calling that code.\n */\n\n/**\n * Represents the change made to a document.\n * Immutable, therefore safe to retain for async processing.\n */\nexport interface Root<TTrees = ProtoNodes> {\n\t/**\n\t * Changes to apply to the root fields.\n\t */\n\treadonly fields?: FieldMap;\n\t/**\n\t * New detached nodes to be constructed.\n\t * The ordering has no significance.\n\t *\n\t * Build instructions for a root that is undergoing a rename should be listed under the starting name.\n\t * For example, if one wishes to build a tree which is being renamed from ID A to ID B,\n\t * then the build should be listed under ID A.\n\t */\n\treadonly build?: readonly DetachedNodeBuild<TTrees>[];\n\t/**\n\t * New detached nodes to be destroyed.\n\t * The ordering has no significance.\n\t *\n\t * Destruction instructions for a root that is undergoing a rename should be listed under the final name.\n\t * For example, if one wishes to destroy a tree which is being renamed from ID A to ID B,\n\t * then the destruction should be listed under ID B.\n\t */\n\treadonly destroy?: readonly DetachedNodeDestruction[];\n\t/**\n\t * Refreshers for detached nodes that may need to be recreated.\n\t * The ordering has no significance.\n\t */\n\treadonly refreshers?: readonly DetachedNodeBuild<TTrees>[];\n\t/**\n\t * Changes to apply to detached nodes.\n\t * The ordering has no significance.\n\t *\n\t * Nested changes for a root that is undergoing a rename should be listed under the starting name.\n\t * For example, if one wishes to change a tree which is being renamed from ID A to ID B,\n\t * then the changes should be listed under ID A.\n\t */\n\treadonly global?: readonly DetachedNodeChanges[];\n\t/**\n\t * Detached roots whose associated ID needs to be updated.\n\t * The ordering has no significance.\n\t * Note that the renames may need to be performed in a specific order to avoid collisions.\n\t * This ordering problem is left to the consumer of this format.\n\t */\n\treadonly rename?: readonly DetachedNodeRename[];\n}\n\n/**\n * The default representation for a chunk (sub-sequence) of inserted content.\n */\nexport type ProtoNodes = TreeChunk;\n\n/**\n * Represents a change being made to a part of the document tree.\n */\nexport interface Mark {\n\t/**\n\t * The number of nodes affected.\n\t * When `isAttachMark(mark)` is true, this is the number of new nodes being attached.\n\t * When `isAttachMark(mark)` is false, this the number of existing nodes affected.\n\t * Must be 1 when `fields` is populated.\n\t */\n\treadonly count: number;\n\n\t/**\n\t * Modifications to the pre-existing content.\n\t * Must be undefined when `attach` is set but `detach` is not.\n\t */\n\treadonly fields?: FieldMap;\n\n\t/**\n\t * When set, indicates that some pre-existing content is being detached and sent to the given detached field.\n\t */\n\treadonly detach?: DetachedNodeId;\n\n\t/**\n\t * When set, indicates that some content is being attached from the given detached field.\n\t */\n\treadonly attach?: DetachedNodeId;\n}\n\n/**\n * A globally unique ID for a node in a detached field.\n */\nexport interface DetachedNodeId {\n\treadonly major?: RevisionTag;\n\treadonly minor: number;\n}\n\nexport type FieldMap = ReadonlyMap<FieldKey, FieldChanges>;\n\n/**\n * Represents changes made to a detached node\n */\nexport interface DetachedNodeChanges {\n\treadonly id: DetachedNodeId;\n\treadonly fields: FieldMap;\n}\n\n/**\n * Represents the creation of detached nodes.\n *\n * Tree creation is idempotent: if a tree with the same ID already exists,\n * then this build is ignored in favor of the existing tree.\n */\nexport interface DetachedNodeBuild<TTrees = ProtoNodes> {\n\treadonly id: DetachedNodeId;\n\treadonly trees: TTrees;\n}\n\n/**\n * Represents the destruction of detached nodes\n */\nexport interface DetachedNodeDestruction {\n\treadonly id: DetachedNodeId;\n\treadonly count: number;\n}\n\n/**\n * Represents a detached node being assigned a new `DetachedNodeId`.\n */\nexport interface DetachedNodeRename {\n\treadonly count: number;\n\treadonly oldId: DetachedNodeId;\n\treadonly newId: DetachedNodeId;\n}\n\nexport interface FieldChanges {\n\t/**\n\t * Represents a list of changes to the nodes in the field.\n\t * The index of each mark within the range of nodes, before\n\t * applying any of the changes, is not represented explicitly.\n\t * It corresponds to the sum of `mark.count` values for all previous marks for which `isAttachMark(mark)` is false.\n\t */\n\treadonly marks: readonly Mark[];\n}\n"]}
@@ -15,7 +15,7 @@ function deltaForRootInitialization(content) {
15
15
  const delta = {
16
16
  build: [{ id: buildId, trees: content }],
17
17
  fields: new Map([
18
- [types_js_1.rootFieldKey, [{ count: content.topLevelLength, attach: buildId }]],
18
+ [types_js_1.rootFieldKey, { marks: [{ count: content.topLevelLength, attach: buildId }] }],
19
19
  ]),
20
20
  };
21
21
  return delta;
@@ -1 +1 @@
1
- {"version":3,"file":"deltaUtil.js","sourceRoot":"","sources":["../../../src/core/tree/deltaUtil.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,yCAA0C;AAE7B,QAAA,UAAU,GAAS,EAAE,CAAC;AAE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IT License.\n */\n\nimport type { Mutable } from \"../../util/index.js\";\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport type { TreeChunk } from \"./chunk.js\";\nimport type { DetachedNodeId, FieldChanges, Root } from \"./delta.js\";\nimport { rootFieldKey } from \"./types.js\";\n\nexport const emptyDelta: Root = {};\n\nexport function deltaForRootInitialization(content: TreeChunk): Root {\n\tif (content.topLevelLength === 0) {\n\t\treturn emptyDelta;\n\t}\n\tconst buildId = { minor: 0 };\n\tconst delta: Root = {\n\t\tbuild: [{ id: buildId, trees: content }],\n\t\tfields: new Map<FieldKey, FieldChanges>([\n\t\t\t[rootFieldKey, [{ count: content.topLevelLength, attach: buildId }]],\n\t\t]),\n\t};\n\treturn delta;\n}\n\nexport function makeDetachedNodeId(\n\tmajor: DetachedNodeId[\"major\"],\n\tminor: DetachedNodeId[\"minor\"],\n): DetachedNodeId {\n\tconst out: Mutable<DetachedNodeId> = { minor };\n\tif (major !== undefined) {\n\t\tout.major = major;\n\t}\n\treturn out;\n}\n\nexport function offsetDetachId(id: DetachedNodeId, offset: number): DetachedNodeId;\nexport function offsetDetachId(\n\tid: DetachedNodeId | undefined,\n\toffset: number,\n): DetachedNodeId | undefined;\nexport function offsetDetachId(\n\tid: DetachedNodeId | undefined,\n\toffset: number,\n): DetachedNodeId | undefined {\n\tif (id === undefined) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\t...id,\n\t\tminor: id.minor + offset,\n\t};\n}\n\nexport function areDetachedNodeIdsEqual(a: DetachedNodeId, b: DetachedNodeId): boolean {\n\treturn a.major === b.major && a.minor === b.minor;\n}\n"]}
1
+ {"version":3,"file":"deltaUtil.js","sourceRoot":"","sources":["../../../src/core/tree/deltaUtil.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,yCAA0C;AAE7B,QAAA,UAAU,GAAS,EAAE,CAAC;AAEnC,SAAgB,0BAA0B,CAAC,OAAkB;IAC5D,IAAI,OAAO,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,kBAAU,CAAC;IACnB,CAAC;IACD,MAAM,OAAO,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAS;QACnB,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QACxC,MAAM,EAAE,IAAI,GAAG,CAAyB;YACvC,CAAC,uBAAY,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;SAC/E,CAAC;KACF,CAAC;IACF,OAAO,KAAK,CAAC;AACd,CAAC;AAZD,gEAYC;AAED,SAAgB,kBAAkB,CACjC,KAA8B,EAC9B,KAA8B;IAE9B,MAAM,GAAG,GAA4B,EAAE,KAAK,EAAE,CAAC;IAC/C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AATD,gDASC;AAOD,SAAgB,cAAc,CAC7B,EAA8B,EAC9B,MAAc;IAEd,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,OAAO;QACN,GAAG,EAAE;QACL,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,MAAM;KACxB,CAAC;AACH,CAAC;AAXD,wCAWC;AAED,SAAgB,uBAAuB,CAAC,CAAiB,EAAE,CAAiB;IAC3E,OAAO,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,CAAC;AACnD,CAAC;AAFD,0DAEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { Mutable } from \"../../util/index.js\";\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport type { TreeChunk } from \"./chunk.js\";\nimport type { DetachedNodeId, FieldChanges, Root } from \"./delta.js\";\nimport { rootFieldKey } from \"./types.js\";\n\nexport const emptyDelta: Root = {};\n\nexport function deltaForRootInitialization(content: TreeChunk): Root {\n\tif (content.topLevelLength === 0) {\n\t\treturn emptyDelta;\n\t}\n\tconst buildId = { minor: 0 };\n\tconst delta: Root = {\n\t\tbuild: [{ id: buildId, trees: content }],\n\t\tfields: new Map<FieldKey, FieldChanges>([\n\t\t\t[rootFieldKey, { marks: [{ count: content.topLevelLength, attach: buildId }] }],\n\t\t]),\n\t};\n\treturn delta;\n}\n\nexport function makeDetachedNodeId(\n\tmajor: DetachedNodeId[\"major\"],\n\tminor: DetachedNodeId[\"minor\"],\n): DetachedNodeId {\n\tconst out: Mutable<DetachedNodeId> = { minor };\n\tif (major !== undefined) {\n\t\tout.major = major;\n\t}\n\treturn out;\n}\n\nexport function offsetDetachId(id: DetachedNodeId, offset: number): DetachedNodeId;\nexport function offsetDetachId(\n\tid: DetachedNodeId | undefined,\n\toffset: number,\n): DetachedNodeId | undefined;\nexport function offsetDetachId(\n\tid: DetachedNodeId | undefined,\n\toffset: number,\n): DetachedNodeId | undefined {\n\tif (id === undefined) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\t...id,\n\t\tminor: id.minor + offset,\n\t};\n}\n\nexport function areDetachedNodeIdsEqual(a: DetachedNodeId, b: DetachedNodeId): boolean {\n\treturn a.major === b.major && a.minor === b.minor;\n}\n"]}
@@ -210,7 +210,7 @@ function visitNode(index, fields, visitor, config) {
210
210
  */
211
211
  function detachPass(fieldChanges, visitor, config) {
212
212
  let index = 0;
213
- for (const mark of fieldChanges) {
213
+ for (const mark of fieldChanges.marks) {
214
214
  if (mark.fields !== undefined) {
215
215
  (0, internal_1.assert)(mark.attach === undefined || mark.detach !== undefined, 0x7d0 /* Invalid nested changes on an additive mark */);
216
216
  visitNode(index, mark.fields, visitor, config);
@@ -281,7 +281,7 @@ function collectDestroys(destroys, config) {
281
281
  */
282
282
  function attachPass(fieldChanges, visitor, config) {
283
283
  let index = 0;
284
- for (const mark of fieldChanges) {
284
+ for (const mark of fieldChanges.marks) {
285
285
  if (mark.attach !== undefined) {
286
286
  for (let i = 0; i < mark.count; i += 1) {
287
287
  const offsetAttachId = (0, deltaUtil_js_1.offsetDetachId)(mark.attach, i);