@fluidframework/tree 2.113.0-411909 → 2.114.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 (534) hide show
  1. package/CHANGELOG.md +272 -0
  2. package/api-report/tree.alpha.api.md +19 -0
  3. package/dist/core/change-family/changeFamily.d.ts +15 -4
  4. package/dist/core/change-family/changeFamily.d.ts.map +1 -1
  5. package/dist/core/change-family/changeFamily.js.map +1 -1
  6. package/dist/core/change-family/editBuilder.d.ts +2 -3
  7. package/dist/core/change-family/editBuilder.d.ts.map +1 -1
  8. package/dist/core/change-family/editBuilder.js +1 -2
  9. package/dist/core/change-family/editBuilder.js.map +1 -1
  10. package/dist/core/change-family/index.d.ts +1 -1
  11. package/dist/core/change-family/index.d.ts.map +1 -1
  12. package/dist/core/change-family/index.js.map +1 -1
  13. package/dist/core/index.d.ts +3 -2
  14. package/dist/core/index.d.ts.map +1 -1
  15. package/dist/core/index.js.map +1 -1
  16. package/dist/core/tree/delta.d.ts +62 -16
  17. package/dist/core/tree/delta.d.ts.map +1 -1
  18. package/dist/core/tree/delta.js.map +1 -1
  19. package/dist/core/tree/detachedFieldIndex.d.ts +7 -13
  20. package/dist/core/tree/detachedFieldIndex.d.ts.map +1 -1
  21. package/dist/core/tree/detachedFieldIndex.js +32 -46
  22. package/dist/core/tree/detachedFieldIndex.js.map +1 -1
  23. package/dist/core/tree/index.d.ts +1 -0
  24. package/dist/core/tree/index.d.ts.map +1 -1
  25. package/dist/core/tree/index.js.map +1 -1
  26. package/dist/core/tree/visitorUtils.d.ts +2 -4
  27. package/dist/core/tree/visitorUtils.d.ts.map +1 -1
  28. package/dist/core/tree/visitorUtils.js +2 -2
  29. package/dist/core/tree/visitorUtils.js.map +1 -1
  30. package/dist/entrypoints/alpha.d.ts +1 -1
  31. package/dist/entrypoints/alpha.d.ts.map +1 -1
  32. package/dist/entrypoints/alpha.js +5 -2
  33. package/dist/entrypoints/alpha.js.map +1 -1
  34. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  35. package/dist/feature-libraries/chunked-forest/uniformChunk.js +10 -2
  36. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  37. package/dist/feature-libraries/comparison-forest/comparisonForest.d.ts +51 -0
  38. package/dist/feature-libraries/comparison-forest/comparisonForest.d.ts.map +1 -0
  39. package/dist/feature-libraries/comparison-forest/comparisonForest.js +98 -0
  40. package/dist/feature-libraries/comparison-forest/comparisonForest.js.map +1 -0
  41. package/dist/feature-libraries/comparison-forest/index.d.ts +6 -0
  42. package/dist/feature-libraries/comparison-forest/index.d.ts.map +1 -0
  43. package/dist/feature-libraries/comparison-forest/index.js +10 -0
  44. package/dist/feature-libraries/comparison-forest/index.js.map +1 -0
  45. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +8 -6
  46. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  47. package/dist/feature-libraries/default-schema/defaultEditBuilder.js +6 -3
  48. package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  49. package/dist/feature-libraries/default-schema/index.d.ts +1 -1
  50. package/dist/feature-libraries/default-schema/index.d.ts.map +1 -1
  51. package/dist/feature-libraries/default-schema/index.js.map +1 -1
  52. package/dist/feature-libraries/default-schema/noChangeCodecs.d.ts +2 -2
  53. package/dist/feature-libraries/default-schema/noChangeCodecs.d.ts.map +1 -1
  54. package/dist/feature-libraries/default-schema/noChangeCodecs.js +3 -1
  55. package/dist/feature-libraries/default-schema/noChangeCodecs.js.map +1 -1
  56. package/dist/feature-libraries/detachedFieldIndexSummarizer.d.ts +6 -3
  57. package/dist/feature-libraries/detachedFieldIndexSummarizer.d.ts.map +1 -1
  58. package/dist/feature-libraries/detachedFieldIndexSummarizer.js +18 -6
  59. package/dist/feature-libraries/detachedFieldIndexSummarizer.js.map +1 -1
  60. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +2 -3
  61. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  62. package/dist/feature-libraries/forest-summary/forestSummarizer.js +2 -3
  63. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  64. package/dist/feature-libraries/index.d.ts +4 -3
  65. package/dist/feature-libraries/index.d.ts.map +1 -1
  66. package/dist/feature-libraries/index.js +77 -72
  67. package/dist/feature-libraries/index.js.map +1 -1
  68. package/dist/feature-libraries/mitigatedChangeFamily.d.ts +1 -1
  69. package/dist/feature-libraries/mitigatedChangeFamily.d.ts.map +1 -1
  70. package/dist/feature-libraries/mitigatedChangeFamily.js +12 -0
  71. package/dist/feature-libraries/mitigatedChangeFamily.js.map +1 -1
  72. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +9 -1
  73. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  74. package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  75. package/dist/feature-libraries/modular-schema/genericFieldKindCodecs.d.ts +2 -2
  76. package/dist/feature-libraries/modular-schema/genericFieldKindCodecs.d.ts.map +1 -1
  77. package/dist/feature-libraries/modular-schema/genericFieldKindCodecs.js.map +1 -1
  78. package/dist/feature-libraries/modular-schema/index.d.ts +1 -1
  79. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  80. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  81. package/dist/feature-libraries/modular-schema/invert.d.ts +15 -0
  82. package/dist/feature-libraries/modular-schema/invert.d.ts.map +1 -0
  83. package/dist/feature-libraries/modular-schema/invert.js +159 -0
  84. package/dist/feature-libraries/modular-schema/invert.js.map +1 -0
  85. package/dist/feature-libraries/modular-schema/minimizeModularChange.d.ts +3 -4
  86. package/dist/feature-libraries/modular-schema/minimizeModularChange.d.ts.map +1 -1
  87. package/dist/feature-libraries/modular-schema/minimizeModularChange.js +2 -2
  88. package/dist/feature-libraries/modular-schema/minimizeModularChange.js.map +1 -1
  89. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +9 -9
  90. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
  91. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js +0 -2
  92. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
  93. package/dist/feature-libraries/modular-schema/modularChangeCodecV2.d.ts +2 -2
  94. package/dist/feature-libraries/modular-schema/modularChangeCodecV2.d.ts.map +1 -1
  95. package/dist/feature-libraries/modular-schema/modularChangeCodecV2.js.map +1 -1
  96. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts +2 -2
  97. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  98. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  99. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +8 -22
  100. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  101. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +53 -406
  102. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  103. package/dist/feature-libraries/modular-schema/modularChangeUtils.d.ts +61 -0
  104. package/dist/feature-libraries/modular-schema/modularChangeUtils.d.ts.map +1 -0
  105. package/dist/feature-libraries/modular-schema/modularChangeUtils.js +205 -0
  106. package/dist/feature-libraries/modular-schema/modularChangeUtils.js.map +1 -0
  107. package/dist/feature-libraries/modular-schema/prune.d.ts +10 -0
  108. package/dist/feature-libraries/modular-schema/prune.d.ts.map +1 -0
  109. package/dist/feature-libraries/modular-schema/prune.js +49 -0
  110. package/dist/feature-libraries/modular-schema/prune.js.map +1 -0
  111. package/dist/feature-libraries/optional-field/optionalField.js +1 -1
  112. package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
  113. package/dist/feature-libraries/optional-field/optionalFieldCodecV2.d.ts +2 -2
  114. package/dist/feature-libraries/optional-field/optionalFieldCodecV2.d.ts.map +1 -1
  115. package/dist/feature-libraries/optional-field/optionalFieldCodecV2.js.map +1 -1
  116. package/dist/feature-libraries/optional-field/optionalFieldCodecs.d.ts +2 -2
  117. package/dist/feature-libraries/optional-field/optionalFieldCodecs.d.ts.map +1 -1
  118. package/dist/feature-libraries/optional-field/optionalFieldCodecs.js.map +1 -1
  119. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts +2 -2
  120. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts.map +1 -1
  121. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  122. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts +2 -2
  123. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts.map +1 -1
  124. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.js.map +1 -1
  125. package/dist/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts +2 -2
  126. package/dist/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts.map +1 -1
  127. package/dist/feature-libraries/sequence-field/sequenceFieldCodecs.js.map +1 -1
  128. package/dist/feature-libraries/treeTextCursor.d.ts +15 -0
  129. package/dist/feature-libraries/treeTextCursor.d.ts.map +1 -1
  130. package/dist/feature-libraries/treeTextCursor.js +64 -1
  131. package/dist/feature-libraries/treeTextCursor.js.map +1 -1
  132. package/dist/index.d.ts +3 -1
  133. package/dist/index.d.ts.map +1 -1
  134. package/dist/index.js +5 -1
  135. package/dist/index.js.map +1 -1
  136. package/dist/packageVersion.d.ts +1 -1
  137. package/dist/packageVersion.d.ts.map +1 -1
  138. package/dist/packageVersion.js +1 -1
  139. package/dist/packageVersion.js.map +1 -1
  140. package/dist/shared-tree/serializedChange.d.ts +2 -2
  141. package/dist/shared-tree/serializedChange.d.ts.map +1 -1
  142. package/dist/shared-tree/serializedChange.js.map +1 -1
  143. package/dist/shared-tree/sharedTree.d.ts +6 -3
  144. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  145. package/dist/shared-tree/sharedTree.js +8 -6
  146. package/dist/shared-tree/sharedTree.js.map +1 -1
  147. package/dist/shared-tree/sharedTreeChangeCodecs.d.ts +2 -2
  148. package/dist/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
  149. package/dist/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  150. package/dist/shared-tree/sharedTreeChangeFamily.d.ts +41 -4
  151. package/dist/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  152. package/dist/shared-tree/sharedTreeChangeFamily.js +57 -1
  153. package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  154. package/dist/shared-tree/transactionMinimize.d.ts.map +1 -1
  155. package/dist/shared-tree/transactionMinimize.js +2 -2
  156. package/dist/shared-tree/transactionMinimize.js.map +1 -1
  157. package/dist/shared-tree/transactionPostProcessor.d.ts +2 -1
  158. package/dist/shared-tree/transactionPostProcessor.d.ts.map +1 -1
  159. package/dist/shared-tree/transactionPostProcessor.js.map +1 -1
  160. package/dist/shared-tree/treeCheckout.d.ts +8 -7
  161. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  162. package/dist/shared-tree/treeCheckout.js +1 -1
  163. package/dist/shared-tree/treeCheckout.js.map +1 -1
  164. package/dist/shared-tree-core/branch.d.ts +23 -9
  165. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  166. package/dist/shared-tree-core/branch.js +7 -0
  167. package/dist/shared-tree-core/branch.js.map +1 -1
  168. package/dist/shared-tree-core/editManager.d.ts +4 -4
  169. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  170. package/dist/shared-tree-core/editManager.js +2 -0
  171. package/dist/shared-tree-core/editManager.js.map +1 -1
  172. package/dist/shared-tree-core/editManagerCodecs.d.ts +3 -14
  173. package/dist/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  174. package/dist/shared-tree-core/editManagerCodecs.js.map +1 -1
  175. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts +11 -1
  176. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
  177. package/dist/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
  178. package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts +4 -11
  179. package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -1
  180. package/dist/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
  181. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.d.ts +4 -11
  182. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.d.ts.map +1 -1
  183. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
  184. package/dist/shared-tree-core/editManagerSummarizer.d.ts +4 -4
  185. package/dist/shared-tree-core/editManagerSummarizer.d.ts.map +1 -1
  186. package/dist/shared-tree-core/editManagerSummarizer.js +0 -1
  187. package/dist/shared-tree-core/editManagerSummarizer.js.map +1 -1
  188. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts +2 -2
  189. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  190. package/dist/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  191. package/dist/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  192. package/dist/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  193. package/dist/shared-tree-core/messageCodecs.d.ts +8 -1
  194. package/dist/shared-tree-core/messageCodecs.d.ts.map +1 -1
  195. package/dist/shared-tree-core/messageCodecs.js.map +1 -1
  196. package/dist/shared-tree-core/sharedTreeCore.d.ts +5 -5
  197. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  198. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  199. package/dist/shared-tree-core/transaction.d.ts +10 -10
  200. package/dist/shared-tree-core/transaction.d.ts.map +1 -1
  201. package/dist/shared-tree-core/transaction.js +6 -3
  202. package/dist/shared-tree-core/transaction.js.map +1 -1
  203. package/dist/simple-tree/api/eraseSchemaDetails.d.ts +15 -0
  204. package/dist/simple-tree/api/eraseSchemaDetails.d.ts.map +1 -1
  205. package/dist/simple-tree/api/eraseSchemaDetails.js +15 -0
  206. package/dist/simple-tree/api/eraseSchemaDetails.js.map +1 -1
  207. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts +21 -2
  208. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  209. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  210. package/dist/simple-tree/node-kinds/map/mapNode.d.ts +13 -0
  211. package/dist/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  212. package/dist/simple-tree/node-kinds/map/mapNode.js +9 -0
  213. package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  214. package/dist/text/textDomain.d.ts +12 -0
  215. package/dist/text/textDomain.d.ts.map +1 -1
  216. package/dist/text/textDomain.js +37 -16
  217. package/dist/text/textDomain.js.map +1 -1
  218. package/dist/text/textDomainFormatted.d.ts +155 -61
  219. package/dist/text/textDomainFormatted.d.ts.map +1 -1
  220. package/dist/text/textDomainFormatted.js +147 -71
  221. package/dist/text/textDomainFormatted.js.map +1 -1
  222. package/dist/text/textDomainFormattedDefault.d.ts +37 -14
  223. package/dist/text/textDomainFormattedDefault.d.ts.map +1 -1
  224. package/dist/text/textDomainFormattedDefault.js +13 -5
  225. package/dist/text/textDomainFormattedDefault.js.map +1 -1
  226. package/dist/treeDataStore.d.ts +49 -0
  227. package/dist/treeDataStore.d.ts.map +1 -0
  228. package/dist/treeDataStore.js +57 -0
  229. package/dist/treeDataStore.js.map +1 -0
  230. package/dist/treeFactory.d.ts +8 -3
  231. package/dist/treeFactory.d.ts.map +1 -1
  232. package/dist/treeFactory.js +6 -1
  233. package/dist/treeFactory.js.map +1 -1
  234. package/lib/core/change-family/changeFamily.d.ts +15 -4
  235. package/lib/core/change-family/changeFamily.d.ts.map +1 -1
  236. package/lib/core/change-family/changeFamily.js.map +1 -1
  237. package/lib/core/change-family/editBuilder.d.ts +2 -3
  238. package/lib/core/change-family/editBuilder.d.ts.map +1 -1
  239. package/lib/core/change-family/editBuilder.js +1 -2
  240. package/lib/core/change-family/editBuilder.js.map +1 -1
  241. package/lib/core/change-family/index.d.ts +1 -1
  242. package/lib/core/change-family/index.d.ts.map +1 -1
  243. package/lib/core/change-family/index.js.map +1 -1
  244. package/lib/core/index.d.ts +3 -2
  245. package/lib/core/index.d.ts.map +1 -1
  246. package/lib/core/index.js +1 -1
  247. package/lib/core/index.js.map +1 -1
  248. package/lib/core/tree/delta.d.ts +62 -16
  249. package/lib/core/tree/delta.d.ts.map +1 -1
  250. package/lib/core/tree/delta.js.map +1 -1
  251. package/lib/core/tree/detachedFieldIndex.d.ts +7 -13
  252. package/lib/core/tree/detachedFieldIndex.d.ts.map +1 -1
  253. package/lib/core/tree/detachedFieldIndex.js +7 -21
  254. package/lib/core/tree/detachedFieldIndex.js.map +1 -1
  255. package/lib/core/tree/index.d.ts +1 -0
  256. package/lib/core/tree/index.d.ts.map +1 -1
  257. package/lib/core/tree/index.js.map +1 -1
  258. package/lib/core/tree/visitorUtils.d.ts +2 -4
  259. package/lib/core/tree/visitorUtils.d.ts.map +1 -1
  260. package/lib/core/tree/visitorUtils.js +2 -2
  261. package/lib/core/tree/visitorUtils.js.map +1 -1
  262. package/lib/entrypoints/alpha.d.ts +1 -1
  263. package/lib/entrypoints/alpha.d.ts.map +1 -1
  264. package/lib/entrypoints/alpha.js +1 -1
  265. package/lib/entrypoints/alpha.js.map +1 -1
  266. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  267. package/lib/feature-libraries/chunked-forest/uniformChunk.js +10 -2
  268. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  269. package/lib/feature-libraries/comparison-forest/comparisonForest.d.ts +51 -0
  270. package/lib/feature-libraries/comparison-forest/comparisonForest.d.ts.map +1 -0
  271. package/lib/feature-libraries/comparison-forest/comparisonForest.js +94 -0
  272. package/lib/feature-libraries/comparison-forest/comparisonForest.js.map +1 -0
  273. package/lib/feature-libraries/comparison-forest/index.d.ts +6 -0
  274. package/lib/feature-libraries/comparison-forest/index.d.ts.map +1 -0
  275. package/lib/feature-libraries/comparison-forest/index.js +6 -0
  276. package/lib/feature-libraries/comparison-forest/index.js.map +1 -0
  277. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +8 -6
  278. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  279. package/lib/feature-libraries/default-schema/defaultEditBuilder.js +6 -3
  280. package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  281. package/lib/feature-libraries/default-schema/index.d.ts +1 -1
  282. package/lib/feature-libraries/default-schema/index.d.ts.map +1 -1
  283. package/lib/feature-libraries/default-schema/index.js.map +1 -1
  284. package/lib/feature-libraries/default-schema/noChangeCodecs.d.ts +2 -2
  285. package/lib/feature-libraries/default-schema/noChangeCodecs.d.ts.map +1 -1
  286. package/lib/feature-libraries/default-schema/noChangeCodecs.js +3 -1
  287. package/lib/feature-libraries/default-schema/noChangeCodecs.js.map +1 -1
  288. package/lib/feature-libraries/detachedFieldIndexSummarizer.d.ts +6 -3
  289. package/lib/feature-libraries/detachedFieldIndexSummarizer.d.ts.map +1 -1
  290. package/lib/feature-libraries/detachedFieldIndexSummarizer.js +16 -4
  291. package/lib/feature-libraries/detachedFieldIndexSummarizer.js.map +1 -1
  292. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +2 -3
  293. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  294. package/lib/feature-libraries/forest-summary/forestSummarizer.js +2 -3
  295. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  296. package/lib/feature-libraries/index.d.ts +4 -3
  297. package/lib/feature-libraries/index.d.ts.map +1 -1
  298. package/lib/feature-libraries/index.js +2 -1
  299. package/lib/feature-libraries/index.js.map +1 -1
  300. package/lib/feature-libraries/mitigatedChangeFamily.d.ts +1 -1
  301. package/lib/feature-libraries/mitigatedChangeFamily.d.ts.map +1 -1
  302. package/lib/feature-libraries/mitigatedChangeFamily.js +12 -0
  303. package/lib/feature-libraries/mitigatedChangeFamily.js.map +1 -1
  304. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +9 -1
  305. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  306. package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  307. package/lib/feature-libraries/modular-schema/genericFieldKindCodecs.d.ts +2 -2
  308. package/lib/feature-libraries/modular-schema/genericFieldKindCodecs.d.ts.map +1 -1
  309. package/lib/feature-libraries/modular-schema/genericFieldKindCodecs.js.map +1 -1
  310. package/lib/feature-libraries/modular-schema/index.d.ts +1 -1
  311. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  312. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  313. package/lib/feature-libraries/modular-schema/invert.d.ts +15 -0
  314. package/lib/feature-libraries/modular-schema/invert.d.ts.map +1 -0
  315. package/lib/feature-libraries/modular-schema/invert.js +155 -0
  316. package/lib/feature-libraries/modular-schema/invert.js.map +1 -0
  317. package/lib/feature-libraries/modular-schema/minimizeModularChange.d.ts +3 -4
  318. package/lib/feature-libraries/modular-schema/minimizeModularChange.d.ts.map +1 -1
  319. package/lib/feature-libraries/modular-schema/minimizeModularChange.js +2 -2
  320. package/lib/feature-libraries/modular-schema/minimizeModularChange.js.map +1 -1
  321. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +9 -9
  322. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
  323. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js +0 -2
  324. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
  325. package/lib/feature-libraries/modular-schema/modularChangeCodecV2.d.ts +2 -2
  326. package/lib/feature-libraries/modular-schema/modularChangeCodecV2.d.ts.map +1 -1
  327. package/lib/feature-libraries/modular-schema/modularChangeCodecV2.js.map +1 -1
  328. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts +2 -2
  329. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  330. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  331. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +8 -22
  332. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  333. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +16 -367
  334. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  335. package/lib/feature-libraries/modular-schema/modularChangeUtils.d.ts +61 -0
  336. package/lib/feature-libraries/modular-schema/modularChangeUtils.d.ts.map +1 -0
  337. package/lib/feature-libraries/modular-schema/modularChangeUtils.js +192 -0
  338. package/lib/feature-libraries/modular-schema/modularChangeUtils.js.map +1 -0
  339. package/lib/feature-libraries/modular-schema/prune.d.ts +10 -0
  340. package/lib/feature-libraries/modular-schema/prune.d.ts.map +1 -0
  341. package/lib/feature-libraries/modular-schema/prune.js +45 -0
  342. package/lib/feature-libraries/modular-schema/prune.js.map +1 -0
  343. package/lib/feature-libraries/optional-field/optionalField.js +1 -1
  344. package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
  345. package/lib/feature-libraries/optional-field/optionalFieldCodecV2.d.ts +2 -2
  346. package/lib/feature-libraries/optional-field/optionalFieldCodecV2.d.ts.map +1 -1
  347. package/lib/feature-libraries/optional-field/optionalFieldCodecV2.js.map +1 -1
  348. package/lib/feature-libraries/optional-field/optionalFieldCodecs.d.ts +2 -2
  349. package/lib/feature-libraries/optional-field/optionalFieldCodecs.d.ts.map +1 -1
  350. package/lib/feature-libraries/optional-field/optionalFieldCodecs.js.map +1 -1
  351. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts +2 -2
  352. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts.map +1 -1
  353. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  354. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts +2 -2
  355. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts.map +1 -1
  356. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.js.map +1 -1
  357. package/lib/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts +2 -2
  358. package/lib/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts.map +1 -1
  359. package/lib/feature-libraries/sequence-field/sequenceFieldCodecs.js.map +1 -1
  360. package/lib/feature-libraries/treeTextCursor.d.ts +15 -0
  361. package/lib/feature-libraries/treeTextCursor.d.ts.map +1 -1
  362. package/lib/feature-libraries/treeTextCursor.js +62 -1
  363. package/lib/feature-libraries/treeTextCursor.js.map +1 -1
  364. package/lib/index.d.ts +3 -1
  365. package/lib/index.d.ts.map +1 -1
  366. package/lib/index.js +2 -1
  367. package/lib/index.js.map +1 -1
  368. package/lib/packageVersion.d.ts +1 -1
  369. package/lib/packageVersion.d.ts.map +1 -1
  370. package/lib/packageVersion.js +1 -1
  371. package/lib/packageVersion.js.map +1 -1
  372. package/lib/shared-tree/serializedChange.d.ts +2 -2
  373. package/lib/shared-tree/serializedChange.d.ts.map +1 -1
  374. package/lib/shared-tree/serializedChange.js.map +1 -1
  375. package/lib/shared-tree/sharedTree.d.ts +6 -3
  376. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  377. package/lib/shared-tree/sharedTree.js +9 -7
  378. package/lib/shared-tree/sharedTree.js.map +1 -1
  379. package/lib/shared-tree/sharedTreeChangeCodecs.d.ts +2 -2
  380. package/lib/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
  381. package/lib/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  382. package/lib/shared-tree/sharedTreeChangeFamily.d.ts +41 -4
  383. package/lib/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  384. package/lib/shared-tree/sharedTreeChangeFamily.js +55 -0
  385. package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  386. package/lib/shared-tree/transactionMinimize.d.ts.map +1 -1
  387. package/lib/shared-tree/transactionMinimize.js +3 -3
  388. package/lib/shared-tree/transactionMinimize.js.map +1 -1
  389. package/lib/shared-tree/transactionPostProcessor.d.ts +2 -1
  390. package/lib/shared-tree/transactionPostProcessor.d.ts.map +1 -1
  391. package/lib/shared-tree/transactionPostProcessor.js.map +1 -1
  392. package/lib/shared-tree/treeCheckout.d.ts +8 -7
  393. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  394. package/lib/shared-tree/treeCheckout.js +1 -1
  395. package/lib/shared-tree/treeCheckout.js.map +1 -1
  396. package/lib/shared-tree-core/branch.d.ts +23 -9
  397. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  398. package/lib/shared-tree-core/branch.js +7 -0
  399. package/lib/shared-tree-core/branch.js.map +1 -1
  400. package/lib/shared-tree-core/editManager.d.ts +4 -4
  401. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  402. package/lib/shared-tree-core/editManager.js +2 -0
  403. package/lib/shared-tree-core/editManager.js.map +1 -1
  404. package/lib/shared-tree-core/editManagerCodecs.d.ts +3 -14
  405. package/lib/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  406. package/lib/shared-tree-core/editManagerCodecs.js.map +1 -1
  407. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts +11 -1
  408. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
  409. package/lib/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
  410. package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts +4 -11
  411. package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -1
  412. package/lib/shared-tree-core/editManagerCodecsV1toV4.js +1 -1
  413. package/lib/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
  414. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.d.ts +4 -11
  415. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.d.ts.map +1 -1
  416. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js +1 -1
  417. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
  418. package/lib/shared-tree-core/editManagerSummarizer.d.ts +4 -4
  419. package/lib/shared-tree-core/editManagerSummarizer.d.ts.map +1 -1
  420. package/lib/shared-tree-core/editManagerSummarizer.js +0 -1
  421. package/lib/shared-tree-core/editManagerSummarizer.js.map +1 -1
  422. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts +2 -2
  423. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  424. package/lib/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  425. package/lib/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  426. package/lib/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  427. package/lib/shared-tree-core/messageCodecs.d.ts +8 -1
  428. package/lib/shared-tree-core/messageCodecs.d.ts.map +1 -1
  429. package/lib/shared-tree-core/messageCodecs.js.map +1 -1
  430. package/lib/shared-tree-core/sharedTreeCore.d.ts +5 -5
  431. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  432. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  433. package/lib/shared-tree-core/transaction.d.ts +10 -10
  434. package/lib/shared-tree-core/transaction.d.ts.map +1 -1
  435. package/lib/shared-tree-core/transaction.js +6 -3
  436. package/lib/shared-tree-core/transaction.js.map +1 -1
  437. package/lib/simple-tree/api/eraseSchemaDetails.d.ts +15 -0
  438. package/lib/simple-tree/api/eraseSchemaDetails.d.ts.map +1 -1
  439. package/lib/simple-tree/api/eraseSchemaDetails.js +15 -0
  440. package/lib/simple-tree/api/eraseSchemaDetails.js.map +1 -1
  441. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts +21 -2
  442. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  443. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  444. package/lib/simple-tree/node-kinds/map/mapNode.d.ts +13 -0
  445. package/lib/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  446. package/lib/simple-tree/node-kinds/map/mapNode.js +9 -0
  447. package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  448. package/lib/text/textDomain.d.ts +12 -0
  449. package/lib/text/textDomain.d.ts.map +1 -1
  450. package/lib/text/textDomain.js +34 -15
  451. package/lib/text/textDomain.js.map +1 -1
  452. package/lib/text/textDomainFormatted.d.ts +155 -61
  453. package/lib/text/textDomainFormatted.d.ts.map +1 -1
  454. package/lib/text/textDomainFormatted.js +148 -73
  455. package/lib/text/textDomainFormatted.js.map +1 -1
  456. package/lib/text/textDomainFormattedDefault.d.ts +37 -14
  457. package/lib/text/textDomainFormattedDefault.d.ts.map +1 -1
  458. package/lib/text/textDomainFormattedDefault.js +14 -6
  459. package/lib/text/textDomainFormattedDefault.js.map +1 -1
  460. package/lib/treeDataStore.d.ts +49 -0
  461. package/lib/treeDataStore.d.ts.map +1 -0
  462. package/lib/treeDataStore.js +52 -0
  463. package/lib/treeDataStore.js.map +1 -0
  464. package/lib/treeFactory.d.ts +8 -3
  465. package/lib/treeFactory.d.ts.map +1 -1
  466. package/lib/treeFactory.js +5 -0
  467. package/lib/treeFactory.js.map +1 -1
  468. package/package.json +25 -24
  469. package/src/core/change-family/changeFamily.ts +32 -4
  470. package/src/core/change-family/editBuilder.ts +1 -2
  471. package/src/core/change-family/index.ts +2 -0
  472. package/src/core/index.ts +9 -6
  473. package/src/core/tree/delta.ts +62 -16
  474. package/src/core/tree/detachedFieldIndex.ts +7 -38
  475. package/src/core/tree/index.ts +2 -0
  476. package/src/core/tree/visitorUtils.ts +3 -17
  477. package/src/entrypoints/alpha.ts +7 -3
  478. package/src/feature-libraries/chunked-forest/uniformChunk.ts +11 -1
  479. package/src/feature-libraries/comparison-forest/comparisonForest.ts +140 -0
  480. package/src/feature-libraries/comparison-forest/index.ts +6 -0
  481. package/src/feature-libraries/default-schema/defaultEditBuilder.ts +20 -6
  482. package/src/feature-libraries/default-schema/index.ts +1 -0
  483. package/src/feature-libraries/default-schema/noChangeCodecs.ts +11 -3
  484. package/src/feature-libraries/detachedFieldIndexSummarizer.ts +33 -5
  485. package/src/feature-libraries/forest-summary/forestSummarizer.ts +1 -3
  486. package/src/feature-libraries/index.ts +5 -0
  487. package/src/feature-libraries/mitigatedChangeFamily.ts +21 -3
  488. package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +10 -1
  489. package/src/feature-libraries/modular-schema/genericFieldKindCodecs.ts +9 -4
  490. package/src/feature-libraries/modular-schema/index.ts +1 -0
  491. package/src/feature-libraries/modular-schema/invert.ts +338 -0
  492. package/src/feature-libraries/modular-schema/minimizeModularChange.ts +3 -5
  493. package/src/feature-libraries/modular-schema/modularChangeCodecV1.ts +16 -13
  494. package/src/feature-libraries/modular-schema/modularChangeCodecV2.ts +3 -1
  495. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +2 -1
  496. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +45 -644
  497. package/src/feature-libraries/modular-schema/modularChangeUtils.ts +340 -0
  498. package/src/feature-libraries/modular-schema/prune.ts +69 -0
  499. package/src/feature-libraries/optional-field/optionalField.ts +1 -1
  500. package/src/feature-libraries/optional-field/optionalFieldCodecV2.ts +4 -2
  501. package/src/feature-libraries/optional-field/optionalFieldCodecs.ts +5 -2
  502. package/src/feature-libraries/sequence-field/sequenceFieldCodecV2.ts +4 -2
  503. package/src/feature-libraries/sequence-field/sequenceFieldCodecV3.ts +4 -2
  504. package/src/feature-libraries/sequence-field/sequenceFieldCodecs.ts +6 -3
  505. package/src/feature-libraries/treeTextCursor.ts +66 -1
  506. package/src/index.ts +4 -0
  507. package/src/packageVersion.ts +1 -1
  508. package/src/shared-tree/serializedChange.ts +2 -2
  509. package/src/shared-tree/sharedTree.ts +34 -14
  510. package/src/shared-tree/sharedTreeChangeCodecs.ts +11 -3
  511. package/src/shared-tree/sharedTreeChangeFamily.ts +77 -2
  512. package/src/shared-tree/transactionMinimize.ts +7 -3
  513. package/src/shared-tree/transactionPostProcessor.ts +5 -1
  514. package/src/shared-tree/treeCheckout.ts +55 -16
  515. package/src/shared-tree-core/branch.ts +40 -12
  516. package/src/shared-tree-core/editManager.ts +46 -25
  517. package/src/shared-tree-core/editManagerCodecs.ts +9 -21
  518. package/src/shared-tree-core/editManagerCodecsCommons.ts +14 -2
  519. package/src/shared-tree-core/editManagerCodecsV1toV4.ts +18 -21
  520. package/src/shared-tree-core/editManagerCodecsVSharedBranches.ts +18 -20
  521. package/src/shared-tree-core/editManagerSummarizer.ts +9 -6
  522. package/src/shared-tree-core/messageCodecV1ToV4.ts +3 -3
  523. package/src/shared-tree-core/messageCodecVSharedBranches.ts +2 -2
  524. package/src/shared-tree-core/messageCodecs.ts +12 -2
  525. package/src/shared-tree-core/sharedTreeCore.ts +15 -6
  526. package/src/shared-tree-core/transaction.ts +47 -25
  527. package/src/simple-tree/api/eraseSchemaDetails.ts +15 -0
  528. package/src/simple-tree/node-kinds/array/arrayNode.ts +21 -2
  529. package/src/simple-tree/node-kinds/map/mapNode.ts +24 -2
  530. package/src/text/textDomain.ts +29 -6
  531. package/src/text/textDomainFormatted.ts +351 -134
  532. package/src/text/textDomainFormattedDefault.ts +25 -16
  533. package/src/treeDataStore.ts +125 -0
  534. package/src/treeFactory.ts +11 -3
@@ -2,14 +2,15 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import { __classPrivateFieldGet } from "tslib";
5
6
  import { assert, compareArrays, debugAssert, fail } from "@fluidframework/core-utils/internal";
6
7
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
7
8
  import { EmptyKey, forEachNodeSubsequence, } from "../core/index.js";
8
9
  import { currentObserver, buildNodeComparator } from "../feature-libraries/index.js";
9
10
  import { TreeAlpha, Tree as TreeStatic } from "../shared-tree/index.js";
10
- import { getInnerNode, SchemaFactory, SchemaFactoryAlpha, TreeArrayNode, TreeBeta, createCustomizedFluidFrameworkScopedFactory, isObjectNodeSchema, eraseSchemaDetailsSubclassable, } from "../simple-tree/index.js";
11
- import { brand, mapIterable, validateIndex, validateIndexRange } from "../util/index.js";
12
- import { charactersFromString, processCharactersChangedDelta, } from "./textDomain.js";
11
+ import { getInnerNode, SchemaFactory, SchemaFactoryAlpha, TreeArrayNode, TreeBeta, createCustomizedFluidFrameworkScopedFactory, eraseSchemaDetails, isObjectNodeSchema, eraseSchemaDetailsSubclassable, } from "../simple-tree/index.js";
12
+ import { brand, mapIterable, oneFromIterable, validateIndex, validateIndexRange, } from "../util/index.js";
13
+ import { charactersFromString, expensiveInternalValidationAssert, processCharactersChangedDelta, } from "./textDomain.js";
13
14
  /**
14
15
  * Sets up scope for formatted text schema built-in types.
15
16
  * @remarks User-provided factory scoping will be applied as `com.fluidframework.text.formatted<user-scope>`.
@@ -23,6 +24,36 @@ function createFormattedScopedFactory(inputSchemaFactory) {
23
24
  */
24
25
  const sfStatic = new SchemaFactoryAlpha("com.fluidframework.text.formatted");
25
26
  const formatKey = brand("format");
27
+ /**
28
+ * Atom in the string containing a single character.
29
+ * @privateRemarks
30
+ * This is outside the namespace so it can be exported for testing, but not package exported.
31
+ */
32
+ export class StringTextAtomNode extends sfStatic.object("StringTextAtom", {
33
+ /**
34
+ * The underlying text content of this atom.
35
+ * @remarks
36
+ * This is typically a single Unicode code point, and thus may contain multiple UTF-16 surrogate pair code units.
37
+ * Longer strings are still valid. For example, users might store whole grapheme clusters here, or even longer sections of text.
38
+ * Anything combined into a single atom will be treated atomically, and can not be partially selected or formatted.
39
+ * Using larger atoms and splitting them as needed is NOT a recommended approach, since this will result in poor merge behavior for concurrent edits.
40
+ * Instead, atoms should always be the smallest unit of text which will be independently selected, moved or formatted.
41
+ * @privateRemarks
42
+ * This content logically represents the whole atom's content, so using {@link EmptyKey} makes sense to help indicate that.
43
+ */
44
+ content: SchemaFactory.required([SchemaFactory.string], { key: EmptyKey }),
45
+ }) {
46
+ static fromCharacter(value) {
47
+ const character = oneFromIterable(charactersFromString(value));
48
+ if (character === undefined) {
49
+ throw new UsageError("value must contain exactly one Unicode character.");
50
+ }
51
+ return new StringTextAtomNode({ content: character });
52
+ }
53
+ static fromString(value) {
54
+ return Array.from(charactersFromString(value), (character) => new StringTextAtomNode({ content: character }));
55
+ }
56
+ }
26
57
  /**
27
58
  * A collection of text related types, schema and utilities for working with text beyond the basic {@link SchemaStatics.string}.
28
59
  * @remarks
@@ -37,20 +68,57 @@ const formatKey = brand("format");
37
68
  export var FormattedTextAsTree;
38
69
  (function (FormattedTextAsTree) {
39
70
  /**
40
- * Factory for formatted text schema as a function of the formatting and the embedded object (atom) types.
71
+ * Creates a schema for a formatted text node, parameterized by the formatting and the embedded object (atom) types.
72
+ *
73
+ * @param inputSchemaFactory - The {@link SchemaFactoryBeta} used to scope the generated schema.
74
+ * The generated types are scoped under `com.fluidframework.text.formatted<TUserScope>`, where `TUserScope` is the scope of this factory.
75
+ * This scope is used to distinguish different usages of `createSchema` from each-other, and must be kept the same between versions for nodes to remain compatible.
76
+ * It must be different to distinguish different formatted text schema within the same document.
77
+ * @param formatSchema - Schema describing the formatting associated with each atom of text.
78
+ * Use an {@link NodeKind.Object|Object node} to support {@link FormattedTextAsTree.Members.formatRange}.
79
+ * @param extraAtoms - Additional atom schema to allow as text content beyond the built-in {@link FormattedTextAsTree.(StringTextAtom:variable)}.
80
+ * Use this to embed richer content (for example line breaks or inline objects) alongside plain characters.
81
+ * @param defaultFormatInsertable - The formatting applied to text inserted via non-formatted APIs
82
+ * (for example {@link FormattedTextAsTree.Members.insertAt} and {@link FormattedTextAsTree.Statics.fromString} when no explicit format is provided).
83
+ * @returns The schema for the formatted text node, whose nodes implement {@link FormattedTextAsTree.Members} and whose statics implement {@link FormattedTextAsTree.Statics}.
84
+ * @remarks
85
+ * See {@link FormattedTextAsTreeDefault} for a default parameterization of this factory.
86
+ * @privateRemarks
87
+ * TODO: The choice to always include the built-in {@link FormattedTextAsTree.(StringTextAtom:variable)} is a design decision that should be re-evaluated before stabilizing.
41
88
  */
42
89
  function createSchema(inputSchemaFactory, formatSchema, extraAtoms, defaultFormatInsertable) {
43
- const atoms = [StringTextAtom, ...extraAtoms];
90
+ var _TextNode_instances, _TextNode_fullString_reference, _TextNode_charactersCopy_reference, _TextNode_editRange;
91
+ const atoms = [FormattedTextAsTree.StringTextAtom, ...extraAtoms];
44
92
  const sf = createFormattedScopedFactory(inputSchemaFactory);
93
+ const defaultFormat = TreeBeta.create(formatSchema, defaultFormatInsertable);
94
+ /**
95
+ * Gets a format node, which must be cloned before being inserted.
96
+ */
97
+ function getFormatNode(format) {
98
+ // Note we cannot use the `format ?? defaultFormat` syntax as format is allowed to be `null`.
99
+ return format === undefined
100
+ ? defaultFormat
101
+ : TreeBeta.create(formatSchema, format);
102
+ }
103
+ function cloneFormat(format) {
104
+ const clone = TreeBeta.clone(format);
105
+ // TypeScript fails to prove that cloning a node gives a node, and not possible undefined (like cloning a empty field could).
106
+ // This cast helps users of this function get the types they need.
107
+ return clone;
108
+ }
45
109
  class TextNode extends sf.object("Text", {
46
110
  content: SchemaFactory.required([() => StringArray], { key: EmptyKey }),
47
111
  }) {
48
112
  constructor() {
49
113
  super(...arguments);
50
- this.defaultFormat = TreeBeta.create(formatSchema, defaultFormatInsertable);
114
+ _TextNode_instances.add(this);
51
115
  }
52
- insertAt(index, additionalCharacters) {
53
- this.content.insertAt(index, TreeArrayNode.spread(textAtomsFromString(additionalCharacters, this.defaultFormat)));
116
+ insertAt(index, additionalCharacters, format) {
117
+ const newAtoms = typeof additionalCharacters === "string"
118
+ ? stringTextAtomsFromString(additionalCharacters)
119
+ : additionalCharacters;
120
+ const formatNode = getFormatNode(format);
121
+ this.content.insertAt(index, TreeArrayNode.spread(stringAtomsFromTextAtoms(newAtoms, formatNode)));
54
122
  }
55
123
  removeRange(index, end) {
56
124
  this.content.removeRange(index, end);
@@ -60,7 +128,7 @@ export var FormattedTextAsTree;
60
128
  }
61
129
  charactersCopy() {
62
130
  const result = this.content.charactersCopy();
63
- debugAssert(() => compareArrays(result, this.charactersCopy_reference()) ||
131
+ expensiveInternalValidationAssert(() => compareArrays(result, __classPrivateFieldGet(this, _TextNode_instances, "m", _TextNode_charactersCopy_reference).call(this)) ||
64
132
  "invalid charactersCopy optimizations");
65
133
  return result;
66
134
  }
@@ -69,29 +137,18 @@ export var FormattedTextAsTree;
69
137
  }
70
138
  fullString() {
71
139
  const result = this.content.fullString();
72
- debugAssert(() => result === this.fullString_reference() || "invalid fullString optimizations");
140
+ expensiveInternalValidationAssert(() => result === __classPrivateFieldGet(this, _TextNode_instances, "m", _TextNode_fullString_reference).call(this) || "invalid fullString optimizations");
73
141
  return result;
74
142
  }
75
- /**
76
- * A non-optimized reference implementation of fullString.
77
- */
78
- fullString_reference() {
79
- return [...this.characters()].join("");
80
- }
81
- /**
82
- * Unoptimized trivially correct implementation of charactersCopy.
83
- */
84
- charactersCopy_reference() {
85
- return [...this.characters()];
86
- }
87
143
  static fromString(value, format) {
144
+ const formatNode = getFormatNode(format);
88
145
  // Use `this` rather than `TextNode` so the more derived schema class is constructed when using this as a static on a subclass.
89
146
  return new this({
90
147
  content: [
91
148
  // Constructing an ArrayNode from an iterator is supported, so creating an array from the iterable of characters seems like it's not necessary here,
92
149
  // but to reduce the risk of incorrect data interpretation, we actually ban this in the special case where the iterable is a string directly, which is the case here.
93
150
  // Thus the array construction here is necessary to avoid a runtime error.
94
- ...textAtomsFromString(value, format ?? TreeBeta.create(formatSchema, defaultFormatInsertable)),
151
+ ...textAtomsFromString(value, formatNode),
95
152
  ],
96
153
  });
97
154
  }
@@ -102,37 +159,37 @@ export var FormattedTextAsTree;
102
159
  this.content.insertAt(index, TreeArrayNode.spread(additionalCharacters));
103
160
  }
104
161
  formatRange(start, end, format) {
105
- const formatStart = start ?? 0;
106
- validateIndex(formatStart, this.content, "FormattedTextAsTree.formatRange", true);
107
- const formatEnd = Math.min(this.content.length, end ?? this.content.length);
108
- validateIndexRange(formatStart, formatEnd, this.content, "FormattedTextAsTree.formatRange");
109
- const fieldFormats = Object.entries(format);
110
- TreeAlpha.context(this).runTransaction(() => {
111
- for (let i = formatStart; i < formatEnd; i++) {
112
- const atom = this.content[i];
113
- // Range validated above, so this should never fail.
114
- assert(atom !== undefined, 0xd08 /* Index out of bounds while formatting text range. */);
115
- const formatNode = atom.format;
116
- const atomFormatSchema = TreeStatic.schema(formatNode);
117
- if (!isObjectNodeSchema(atomFormatSchema)) {
118
- // TODO: redesign this API to work with all allowed FormatSchema types.
119
- throw new UsageError("formatRange currently only supports object nodes for the format.");
120
- }
121
- for (const [key, value] of fieldFormats) {
122
- // Object.entries should only return string keyed enumerable own properties.
123
- // The TypeScript typing does not account for this, and thus this assertion is necessary for this code to compile.
124
- assert(typeof key === "string", 0xcc8 /* Object.entries returned a non-string key. */);
125
- const field = atomFormatSchema.fields.get(key);
126
- if (field === undefined) {
127
- throw new UsageError(`Unknown format key: ${key}`);
128
- }
129
- // Ensures that if the input is a node, it is cloned before being inserted into the tree.
130
- const clonedValue = TreeBeta.clone(TreeBeta.create(field, value));
131
- formatNode[key] = clonedValue;
162
+ const fieldFormatsRaw = Object.entries(format);
163
+ const fieldFormats = fieldFormatsRaw.map(([key, value]) => {
164
+ // Object.entries should only return string keyed enumerable own properties.
165
+ // The TypeScript typing does not account for this, and thus this assertion is necessary for this code to compile.
166
+ assert(typeof key === "string", 0xcc8 /* Object.entries returned a non-string key. */);
167
+ return [key, value];
168
+ });
169
+ __classPrivateFieldGet(this, _TextNode_instances, "m", _TextNode_editRange).call(this, start, end, "FormattedTextAsTree.formatRange", (atom) => {
170
+ const formatNode = atom.format;
171
+ const atomFormatSchema = TreeStatic.schema(formatNode);
172
+ if (!isObjectNodeSchema(atomFormatSchema)) {
173
+ throw new UsageError("formatRange currently only supports object nodes for the format.");
174
+ }
175
+ for (const [key, value] of fieldFormats) {
176
+ const field = atomFormatSchema.fields.get(key);
177
+ if (field === undefined) {
178
+ throw new UsageError(`Unknown format key: ${key}`);
132
179
  }
180
+ // Ensures that if the input is a node, it is cloned before being inserted into the tree.
181
+ // Note that since this uses field schema, `undefined` can pass through this if allowed by the schema.
182
+ const clonedValue = TreeBeta.clone(TreeBeta.create(field, value));
183
+ formatNode[key] = clonedValue;
133
184
  }
134
185
  });
135
186
  }
187
+ reformat(start, end, format) {
188
+ const node = getFormatNode(format);
189
+ __classPrivateFieldGet(this, _TextNode_instances, "m", _TextNode_editRange).call(this, start, end, "FormattedTextAsTree.reformat", (atom) => {
190
+ atom.format = cloneFormat(node);
191
+ });
192
+ }
136
193
  /**
137
194
  * Returns the {@link FormattedTextAsTree.TextAtom.content} at the given atom index, or `undefined` if out of bounds.
138
195
  */
@@ -155,17 +212,43 @@ export var FormattedTextAsTree;
155
212
  return this.content.getString(startIndex, endIndex);
156
213
  }
157
214
  }
158
- function textAtomsFromString(value, format) {
159
- const result = mapIterable(charactersFromString(value), (char) => {
160
- const textAtom = new StringTextAtom({ content: char });
215
+ _TextNode_instances = new WeakSet(), _TextNode_fullString_reference = function _TextNode_fullString_reference() {
216
+ return [...this.characters()].join("");
217
+ }, _TextNode_charactersCopy_reference = function _TextNode_charactersCopy_reference() {
218
+ return [...this.characters()];
219
+ }, _TextNode_editRange = function _TextNode_editRange(start, end, method, edit) {
220
+ const formatStart = start ?? 0;
221
+ validateIndex(formatStart, this.content, method, true);
222
+ const formatEnd = Math.min(this.content.length, end ?? this.content.length);
223
+ validateIndexRange(formatStart, formatEnd, this.content, method);
224
+ TreeAlpha.context(this).runTransaction(() => {
225
+ for (let i = formatStart; i < formatEnd; i++) {
226
+ const atom = this.content[i];
227
+ // Range validated above, so this should never fail.
228
+ assert(atom !== undefined, 0xd08 /* Index out of bounds while formatting text range. */);
229
+ edit(atom);
230
+ }
231
+ });
232
+ };
233
+ function stringTextAtomsFromString(value) {
234
+ // TypeScript can't prove in this Generic context that StringTextAtom is assignable to TextAtomNode, so we have to cast.
235
+ // Since TextAtomSchemas unconditionally includes StringTextAtom, this cast is safe.
236
+ return FormattedTextAsTree.StringTextAtom.fromString(value);
237
+ }
238
+ function stringAtomsFromTextAtoms(value, format) {
239
+ const result = mapIterable(value, (content) => {
161
240
  const data = {
162
- content: textAtom,
163
- format: TreeBeta.clone(format),
241
+ content,
242
+ format: cloneFormat(format),
164
243
  };
165
244
  return new StringAtom(data); // Generic break type safety here. TODO: try and make safer.
166
245
  });
167
246
  return result;
168
247
  }
248
+ function textAtomsFromString(value, format) {
249
+ const textAtoms = stringTextAtomsFromString(value);
250
+ return stringAtomsFromTextAtoms(textAtoms, format);
251
+ }
169
252
  class StringArray extends sf.array("StringArray", [() => StringAtom]) {
170
253
  withBorrowedSequenceCursor(f) {
171
254
  const innerNode = getInnerNode(this);
@@ -189,7 +272,7 @@ export var FormattedTextAsTree;
189
272
  cursor.enterNode(0);
190
273
  let content;
191
274
  switch (cursor.type) {
192
- case StringTextAtom.identifier: {
275
+ case FormattedTextAsTree.StringTextAtom.identifier: {
193
276
  cursor.enterField(EmptyKey);
194
277
  cursor.enterNode(0);
195
278
  content = cursor.value;
@@ -295,30 +378,22 @@ export var FormattedTextAsTree;
295
378
  * @remarks
296
379
  * See {@link FormattedTextAsTree.Members} for the API.
297
380
  * See {@link FormattedTextAsTree.Statics} for static APIs on this Schema, including construction.
381
+ * @privateRemarks
382
+ * eraseSchemaDetailsSubclassable risks user's defining subclass members which collide with internals.
383
+ * Ideally we would generate private members for non-public properties, but TypeScript does not support this.
384
+ * It is up to the user of eraseSchemaDetailsSubclassable to manage this risk.
385
+ *
386
+ * TODO: there is at least one collision prone member to worry about here: `content`.
298
387
  */
299
388
  const Tree = eraseSchemaDetailsSubclassable()(TextNode);
300
389
  return Tree;
301
390
  }
302
391
  FormattedTextAsTree.createSchema = createSchema;
303
392
  /**
304
- * Unit in the string representing a single character.
393
+ * Schema for a {@link FormattedTextAsTree.(StringTextAtom:variable)} node.
394
+ * @sealed
305
395
  * @internal
306
396
  */
307
- class StringTextAtom extends sfStatic.object("StringTextAtom", {
308
- /**
309
- * The underlying text content of this atom.
310
- * @remarks
311
- * This is typically a single Unicode code point, and thus may contain multiple UTF-16 surrogate pair code units.
312
- * Using longer strings is still valid. For example, so users might store whole grapheme clusters here, or even longer sections of text.
313
- * Anything combined into a single atom will be treated atomically, and can not be partially selected or formatted.
314
- * Using larger atoms and splitting them as needed is NOT a recommended approach, since this will result in poor merge behavior for concurrent edits.
315
- * Instead atoms should always be the smallest unit of text which will be independently selected, moved or formatted.
316
- * @privateRemarks
317
- * This content logically represents the whole atom's content, so using {@link EmptyKey} makes sense to help indicate that.
318
- */
319
- content: SchemaFactory.required([SchemaFactory.string], { key: EmptyKey }),
320
- }) {
321
- }
322
- FormattedTextAsTree.StringTextAtom = StringTextAtom;
397
+ FormattedTextAsTree.StringTextAtom = eraseSchemaDetails()(StringTextAtomNode);
323
398
  })(FormattedTextAsTree || (FormattedTextAsTree = {}));
324
399
  //# sourceMappingURL=textDomainFormatted.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"textDomainFormatted.js","sourceRoot":"","sources":["../../src/text/textDomainFormatted.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAC/F,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EACN,QAAQ,EACR,sBAAsB,GAItB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EACN,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,QAAQ,EACR,2CAA2C,EAC3C,kBAAkB,EAClB,8BAA8B,GAC9B,MAAM,yBAAyB,CAAC;AAiBjC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB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eJ,CAAA;AAqMxB,CAAC,EA9nBgB,mBAAmB,KAAnB,mBAAmB,QA8nBnC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, compareArrays, debugAssert, fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tEmptyKey,\n\tforEachNodeSubsequence,\n\ttype FieldKey,\n\ttype ITreeCursorSynchronous,\n\ttype TreeValue,\n} from \"../core/index.js\";\nimport { currentObserver, buildNodeComparator } from \"../feature-libraries/index.js\";\nimport { TreeAlpha, Tree as TreeStatic } from \"../shared-tree/index.js\";\nimport {\n\tgetInnerNode,\n\tSchemaFactory,\n\tSchemaFactoryAlpha,\n\tTreeArrayNode,\n\tTreeBeta,\n\tcreateCustomizedFluidFrameworkScopedFactory,\n\tisObjectNodeSchema,\n\teraseSchemaDetailsSubclassable,\n} from \"../simple-tree/index.js\";\nimport type {\n\tTreeNodeSchema,\n\tLazyItem,\n\tImplicitAllowedTypes,\n\tTreeFieldFromImplicitField,\n\tInsertableTypedNode,\n\tTreeNodeFromImplicitAllowedTypes,\n\tInsertableTreeNodeFromImplicitAllowedTypes,\n\tInsertableTreeFieldFromImplicitField,\n\tNodeKind,\n\tTreeNode,\n\tScopedSchemaName,\n\tErasedSchemaSubclassable,\n\tErasedNode,\n\tSchemaFactoryBeta,\n} from \"../simple-tree/index.js\";\nimport { brand, mapIterable, validateIndex, validateIndexRange } from \"../util/index.js\";\n\nimport {\n\tcharactersFromString,\n\tprocessCharactersChangedDelta,\n\ttype TextAsTree,\n} from \"./textDomain.js\";\n\n/**\n * Sets up scope for formatted text schema built-in types.\n * @remarks User-provided factory scoping will be applied as `com.fluidframework.text.formatted<user-scope>`.\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -- Inferring is the most practical option here\nfunction createFormattedScopedFactory<TUserScope extends string>(\n\tinputSchemaFactory: SchemaFactoryBeta<TUserScope>,\n) {\n\treturn createCustomizedFluidFrameworkScopedFactory(inputSchemaFactory, \"text.formatted\");\n}\n\n/**\n * Schema factory for formatted text types which are not generic.\n */\nconst sfStatic = new SchemaFactoryAlpha(\"com.fluidframework.text.formatted\");\n\nconst formatKey: FieldKey = brand(\"format\");\n\n/**\n * A collection of text related types, schema and utilities for working with text beyond the basic {@link SchemaStatics.string}.\n * @remarks\n * This is generic over formatting an embedded object/atom types.\n * See {@link FormattedTextAsTreeDefault} for a default parameterization.\n * @privateRemarks\n * TODO:\n * - Add more comprehensive tests for generic parameterizations other than default.\n * - Sort out API around overwriting subsets of formatting information.\n * @internal\n */\nexport namespace FormattedTextAsTree {\n\t/**\n\t * Factory for formatted text schema as a function of the formatting and the embedded object (atom) types.\n\t */\n\texport function createSchema<\n\t\tconst TUserScope extends string,\n\t\tconst FormatSchema extends ImplicitAllowedTypes,\n\t\tconst ExtraAtomsSchema extends readonly LazyItem<\n\t\t\tTreeNodeSchema<string, NodeKind, TextAtom & TreeNode>\n\t\t>[],\n\t>(\n\t\tinputSchemaFactory: SchemaFactoryBeta<TUserScope>,\n\t\tformatSchema: FormatSchema,\n\t\textraAtoms: ExtraAtomsSchema,\n\t\tdefaultFormatInsertable: InsertableTreeFieldFromImplicitField<FormatSchema>,\n\t): FormattedTextSchema<TUserScope, FormatSchema, ExtraAtomsSchema> {\n\t\tconst atoms = [StringTextAtom, ...extraAtoms] as const;\n\n\t\tconst sf = createFormattedScopedFactory(inputSchemaFactory);\n\t\tclass TextNode\n\t\t\textends sf.object(\"Text\", {\n\t\t\t\tcontent: SchemaFactory.required([() => StringArray], { key: EmptyKey }),\n\t\t\t})\n\t\t\timplements FormattedTextMembers<FormatSchema, ExtraAtomsSchema>\n\t\t{\n\t\t\tpublic defaultFormat: TreeFieldFromImplicitField<FormatSchema> =\n\t\t\t\tTreeBeta.create<FormatSchema>(formatSchema, defaultFormatInsertable);\n\n\t\t\tpublic insertAt(index: number, additionalCharacters: string): void {\n\t\t\t\tthis.content.insertAt(\n\t\t\t\t\tindex,\n\t\t\t\t\tTreeArrayNode.spread(textAtomsFromString(additionalCharacters, this.defaultFormat)),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tpublic removeRange(index: number | undefined, end: number | undefined): void {\n\t\t\t\tthis.content.removeRange(index, end);\n\t\t\t}\n\n\t\t\tpublic characters(): Iterable<string> {\n\t\t\t\treturn mapIterable(this.content, (atom) => atom.content.content);\n\t\t\t}\n\n\t\t\tpublic charactersCopy(): string[] {\n\t\t\t\tconst result = this.content.charactersCopy();\n\t\t\t\tdebugAssert(\n\t\t\t\t\t() =>\n\t\t\t\t\t\tcompareArrays(result, this.charactersCopy_reference()) ||\n\t\t\t\t\t\t\"invalid charactersCopy optimizations\",\n\t\t\t\t);\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tpublic characterCount(): number {\n\t\t\t\treturn this.content.length;\n\t\t\t}\n\n\t\t\tpublic fullString(): string {\n\t\t\t\tconst result = this.content.fullString();\n\t\t\t\tdebugAssert(\n\t\t\t\t\t() => result === this.fullString_reference() || \"invalid fullString optimizations\",\n\t\t\t\t);\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * A non-optimized reference implementation of fullString.\n\t\t\t */\n\t\t\tpublic fullString_reference(): string {\n\t\t\t\treturn [...this.characters()].join(\"\");\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Unoptimized trivially correct implementation of charactersCopy.\n\t\t\t */\n\t\t\tpublic charactersCopy_reference(): string[] {\n\t\t\t\treturn [...this.characters()];\n\t\t\t}\n\n\t\t\tpublic static fromString(\n\t\t\t\tvalue: string,\n\t\t\t\tformat?: TreeFieldFromImplicitField<FormatSchema>,\n\t\t\t): TextNode {\n\t\t\t\t// Use `this` rather than `TextNode` so the more derived schema class is constructed when using this as a static on a subclass.\n\t\t\t\treturn new this({\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t// Constructing an ArrayNode from an iterator is supported, so creating an array from the iterable of characters seems like it's not necessary here,\n\t\t\t\t\t\t// but to reduce the risk of incorrect data interpretation, we actually ban this in the special case where the iterable is a string directly, which is the case here.\n\t\t\t\t\t\t// Thus the array construction here is necessary to avoid a runtime error.\n\t\t\t\t\t\t...textAtomsFromString(\n\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\tformat ?? TreeBeta.create<FormatSchema>(formatSchema, defaultFormatInsertable),\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tpublic charactersWithFormatting(): readonly StringAtom[] {\n\t\t\t\treturn this.content;\n\t\t\t}\n\t\t\tpublic insertWithFormattingAt(\n\t\t\t\tindex: number,\n\t\t\t\tadditionalCharacters: Iterable<InsertableTypedNode<typeof StringAtom>>,\n\t\t\t): void {\n\t\t\t\tthis.content.insertAt(index, TreeArrayNode.spread(additionalCharacters));\n\t\t\t}\n\n\t\t\tpublic formatRange(\n\t\t\t\tstart: number | undefined,\n\t\t\t\tend: number | undefined,\n\t\t\t\tformat: Partial<TreeNodeFromImplicitAllowedTypes<FormatSchema>>,\n\t\t\t): void {\n\t\t\t\tconst formatStart = start ?? 0;\n\t\t\t\tvalidateIndex(formatStart, this.content, \"FormattedTextAsTree.formatRange\", true);\n\n\t\t\t\tconst formatEnd = Math.min(this.content.length, end ?? this.content.length);\n\t\t\t\tvalidateIndexRange(\n\t\t\t\t\tformatStart,\n\t\t\t\t\tformatEnd,\n\t\t\t\t\tthis.content,\n\t\t\t\t\t\"FormattedTextAsTree.formatRange\",\n\t\t\t\t);\n\n\t\t\t\tconst fieldFormats = Object.entries(format) as [\n\t\t\t\t\tkeyof TreeNodeFromImplicitAllowedTypes<FormatSchema>,\n\t\t\t\t\tunknown,\n\t\t\t\t][];\n\n\t\t\t\tTreeAlpha.context(this).runTransaction(() => {\n\t\t\t\t\tfor (let i = formatStart; i < formatEnd; i++) {\n\t\t\t\t\t\tconst atom = this.content[i];\n\t\t\t\t\t\t// Range validated above, so this should never fail.\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tatom !== undefined,\n\t\t\t\t\t\t\t0xd08 /* Index out of bounds while formatting text range. */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst formatNode: TreeNode | TreeValue = atom.format;\n\t\t\t\t\t\tconst atomFormatSchema = TreeStatic.schema(formatNode);\n\t\t\t\t\t\tif (!isObjectNodeSchema(atomFormatSchema)) {\n\t\t\t\t\t\t\t// TODO: redesign this API to work with all allowed FormatSchema types.\n\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t\"formatRange currently only supports object nodes for the format.\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (const [key, value] of fieldFormats) {\n\t\t\t\t\t\t\t// Object.entries should only return string keyed enumerable own properties.\n\t\t\t\t\t\t\t// The TypeScript typing does not account for this, and thus this assertion is necessary for this code to compile.\n\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\ttypeof key === \"string\",\n\t\t\t\t\t\t\t\t0xcc8 /* Object.entries returned a non-string key. */,\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tconst field = atomFormatSchema.fields.get(key);\n\t\t\t\t\t\t\tif (field === undefined) {\n\t\t\t\t\t\t\t\tthrow new UsageError(`Unknown format key: ${key}`);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Ensures that if the input is a node, it is cloned before being inserted into the tree.\n\t\t\t\t\t\t\tconst clonedValue = TreeBeta.clone(TreeBeta.create(field, value as never)) as\n\t\t\t\t\t\t\t\t| TreeNode\n\t\t\t\t\t\t\t\t| TreeValue;\n\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tformatNode as unknown as Record<\n\t\t\t\t\t\t\t\t\tkeyof TreeNodeFromImplicitAllowedTypes<FormatSchema>,\n\t\t\t\t\t\t\t\t\tTreeNode | TreeValue\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t)[key] = clonedValue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Returns the {@link FormattedTextAsTree.TextAtom.content} at the given atom index, or `undefined` if out of bounds.\n\t\t\t */\n\t\t\tprivate getAtomCharacterAt(index: number): string | undefined {\n\t\t\t\tconst atom = this.content[index];\n\t\t\t\tif (atom === undefined) return undefined;\n\t\t\t\treturn atom.content.content;\n\t\t\t}\n\n\t\t\tpublic onCharactersChanged(\n\t\t\t\tcallback: (ops: readonly TextAsTree.TextOp[] | undefined) => void,\n\t\t\t): () => void {\n\t\t\t\treturn TreeAlpha.on(this.content, \"nodeChanged\", ({ delta }) =>\n\t\t\t\t\tprocessCharactersChangedDelta(\n\t\t\t\t\t\tdelta,\n\t\t\t\t\t\t(index) => this.getAtomCharacterAt(index),\n\t\t\t\t\t\tcallback,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tpublic onContentChanged(\n\t\t\t\tcallback: (ops: readonly TextAsTree.TextOp[] | undefined) => void,\n\t\t\t): () => void {\n\t\t\t\treturn TreeAlpha.on(this.content, \"treeChanged\", ({ delta }) =>\n\t\t\t\t\tprocessCharactersChangedDelta(\n\t\t\t\t\t\tdelta,\n\t\t\t\t\t\t(index) => this.getAtomCharacterAt(index),\n\t\t\t\t\t\tcallback,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tpublic getUniformRun(startIndex: number, endIndex?: number): number {\n\t\t\t\treturn this.content.getUniformRun(startIndex, endIndex);\n\t\t\t}\n\n\t\t\tpublic getString(startIndex: number, endIndex?: number): string {\n\t\t\t\treturn this.content.getString(startIndex, endIndex);\n\t\t\t}\n\t\t}\n\n\t\tfunction textAtomsFromString(\n\t\t\tvalue: string,\n\t\t\tformat: TreeFieldFromImplicitField<FormatSchema>,\n\t\t): Iterable<StringAtom> {\n\t\t\tconst result = mapIterable(charactersFromString(value), (char) => {\n\t\t\t\tconst textAtom = new StringTextAtom({ content: char });\n\t\t\t\tconst data = {\n\t\t\t\t\tcontent: textAtom,\n\t\t\t\t\tformat: TreeBeta.clone<FormatSchema>(format),\n\t\t\t\t};\n\t\t\t\treturn new StringAtom(data as never); // Generic break type safety here. TODO: try and make safer.\n\t\t\t});\n\t\t\treturn result;\n\t\t}\n\n\t\tclass StringArray extends sf.array(\"StringArray\", [() => StringAtom]) {\n\t\t\tpublic withBorrowedSequenceCursor<T>(f: (cursor: ITreeCursorSynchronous) => T): T {\n\t\t\t\tconst innerNode = getInnerNode(this);\n\t\t\t\t// Since the cursor will be used to read content from the tree and won't track observations,\n\t\t\t\t// treat it as if it observed the whole subtree.\n\t\t\t\tcurrentObserver?.observeNodeDeep(innerNode);\n\t\t\t\tconst cursor = innerNode.borrowCursor();\n\t\t\t\tcursor.enterField(EmptyKey);\n\t\t\t\tconst result = f(cursor);\n\t\t\t\tcursor.exitField();\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tprivate getCharactersSubarray(startIndex: number, endIndex: number): string[] {\n\t\t\t\tconst slowPathIndexes: number[] = [];\n\t\t\t\tconst result: string[] = [];\n\t\t\t\tthis.withBorrowedSequenceCursor((cursor) => {\n\t\t\t\t\tforEachNodeSubsequence(cursor, startIndex, endIndex, () => {\n\t\t\t\t\t\tdebugAssert(\n\t\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\t\t(cursor.type as string) === StringAtom.identifier ||\n\t\t\t\t\t\t\t\t\"invalid fullString type optimizations\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcursor.enterField(EmptyKey);\n\t\t\t\t\t\tcursor.enterNode(0);\n\t\t\t\t\t\tlet content: string;\n\t\t\t\t\t\tswitch (cursor.type) {\n\t\t\t\t\t\t\tcase StringTextAtom.identifier: {\n\t\t\t\t\t\t\t\tcursor.enterField(EmptyKey);\n\t\t\t\t\t\t\t\tcursor.enterNode(0);\n\t\t\t\t\t\t\t\tcontent = cursor.value as string;\n\t\t\t\t\t\t\t\tdebugAssert(\n\t\t\t\t\t\t\t\t\t() => typeof content === \"string\" || \"invalid fullString type optimizations\",\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\t\t\t\tcursor.exitField();\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// TODO: we could optimize this for constant cases via an optional symbol on the atom schema holding the constant.\n\t\t\t\t\t\t\t// A less general optimization could just include cases for build in types with constant values\n\t\t\t\t\t\t\t// (like below commented code: currently this would cause a cyclical dependency but could be refactored).\n\t\t\t\t\t\t\t// case FormattedTextAsTree.StringLineAtom.identifier: {\n\t\t\t\t\t\t\t// \tcontent = \"\\n\";\n\t\t\t\t\t\t\t// \tbreak;\n\t\t\t\t\t\t\t// }\n\t\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\t\tslowPathIndexes.push(result.length);\n\t\t\t\t\t\t\t\tcontent = \"\"; // Placeholder for slow path content\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\t\tcursor.exitField();\n\t\t\t\t\t\tresult.push(content);\n\t\t\t\t\t});\n\t\t\t\t});\n\n\t\t\t\t// Fill in slow path cases not optimized above.\n\t\t\t\tfor (const index of slowPathIndexes) {\n\t\t\t\t\tconst node =\n\t\t\t\t\t\tthis[index + startIndex] ??\n\t\t\t\t\t\tfail(\n\t\t\t\t\t\t\t0xd09 /* getCharactersSubarray failed to find index after index range was checked */,\n\t\t\t\t\t\t);\n\t\t\t\t\tresult[index] = node.content.content;\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tpublic charactersCopy(): string[] {\n\t\t\t\treturn this.getCharactersSubarray(0, this.length);\n\t\t\t}\n\n\t\t\tpublic fullString(): string {\n\t\t\t\treturn this.charactersCopy().join(\"\");\n\t\t\t}\n\n\t\t\tpublic getString(startIndex: number, endIndex: number = this.length): string {\n\t\t\t\tvalidateIndexRange(startIndex, endIndex, this, \"FormattedTextAsTree.getString\");\n\t\t\t\treturn this.getCharactersSubarray(startIndex, endIndex).join(\"\");\n\t\t\t}\n\n\t\t\tpublic getUniformRun(startIndex: number, endIndex: number = this.length): number {\n\t\t\t\tvalidateIndexRange(startIndex, endIndex, this, \"FormattedTextAsTree.getUniformRun\");\n\t\t\t\tif (endIndex === startIndex) {\n\t\t\t\t\tthrow new UsageError(\"endIndex must be greater than startIndex for getUniformRun.\");\n\t\t\t\t}\n\t\t\t\tconst arrayLength = this.length;\n\t\t\t\treturn this.withBorrowedSequenceCursor((cursor) => {\n\t\t\t\t\tcursor.enterNode(startIndex);\n\n\t\t\t\t\t// Capture the content type of the first atom\n\t\t\t\t\tcursor.enterField(EmptyKey);\n\t\t\t\t\tcursor.enterNode(0);\n\t\t\t\t\tconst contentType = cursor.type;\n\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\tcursor.exitField();\n\n\t\t\t\t\t// Build a comparator from the format subtree of the first atom\n\t\t\t\t\t// This compares by field key\n\t\t\t\t\tcursor.enterField(formatKey);\n\t\t\t\t\tcursor.enterNode(0);\n\t\t\t\t\tconst formatComparator = buildNodeComparator(cursor);\n\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\tcursor.exitField();\n\n\t\t\t\t\tlet runLength = 1;\n\t\t\t\t\tconst limit = Math.min(endIndex, arrayLength) - startIndex;\n\n\t\t\t\t\twhile (runLength < limit && cursor.nextNode()) {\n\t\t\t\t\t\t// Compare atom type\n\t\t\t\t\t\tcursor.enterField(EmptyKey);\n\t\t\t\t\t\tcursor.enterNode(0);\n\t\t\t\t\t\tconst typeMatches = cursor.type === contentType;\n\t\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\t\tcursor.exitField();\n\t\t\t\t\t\tif (!typeMatches) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Compare format subtree using the compiled comparator\n\t\t\t\t\t\tcursor.enterField(formatKey);\n\t\t\t\t\t\tcursor.enterNode(0);\n\t\t\t\t\t\tconst formatMatches = formatComparator(cursor);\n\t\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\t\tcursor.exitField();\n\n\t\t\t\t\t\tif (formatMatches !== true) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\trunLength++;\n\t\t\t\t\t}\n\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\treturn runLength;\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * A unit of the text, with formatting.\n\t\t */\n\t\tclass StringAtom\n\t\t\textends sf.object(\"StringAtom\", {\n\t\t\t\tcontent: SchemaFactory.required(atoms, { key: EmptyKey }),\n\t\t\t\tformat: SchemaFactory.required(formatSchema),\n\t\t\t})\n\t\t\timplements\n\t\t\t\tFormattedAtom<\n\t\t\t\t\tTreeNodeFromImplicitAllowedTypes<FormatSchema>,\n\t\t\t\t\tTreeNodeFromImplicitAllowedTypes<typeof atoms>\n\t\t\t\t> {}\n\n\t\t/**\n\t\t * Schema for a text node.\n\t\t * @remarks\n\t\t * See {@link FormattedTextAsTree.Members} for the API.\n\t\t * See {@link FormattedTextAsTree.Statics} for static APIs on this Schema, including construction.\n\t\t */\n\t\tconst Tree = eraseSchemaDetailsSubclassable<\n\t\t\tFormattedTextMembers<FormatSchema, ExtraAtomsSchema>,\n\t\t\tStatics<Tree>\n\t\t>()(TextNode);\n\t\ttype Tree = ErasedNode<\n\t\t\tFormattedTextMembers<FormatSchema, ExtraAtomsSchema>,\n\t\t\tFormattedTextSchemaIdentifier<TUserScope>\n\t\t>;\n\n\t\treturn Tree;\n\t}\n\n\t/**\n\t * Portion of a string with formatting.\n\t * @sealed\n\t * @internal\n\t */\n\texport interface FormattedAtom<TFormat, TText> {\n\t\treadonly content: TText;\n\t\tformat: TFormat;\n\t}\n\n\t/**\n\t * Portion of a string.\n\t * @internal\n\t */\n\texport interface TextAtom {\n\t\t/**\n\t\t * The content of the text atom, viewed as a string.\n\t\t */\n\t\treadonly content: string;\n\t}\n\n\t/**\n\t * Unit in the string representing a single character.\n\t * @internal\n\t */\n\texport class StringTextAtom\n\t\textends sfStatic.object(\"StringTextAtom\", {\n\t\t\t/**\n\t\t\t * The underlying text content of this atom.\n\t\t\t * @remarks\n\t\t\t * This is typically a single Unicode code point, and thus may contain multiple UTF-16 surrogate pair code units.\n\t\t\t * Using longer strings is still valid. For example, so users might store whole grapheme clusters here, or even longer sections of text.\n\t\t\t * Anything combined into a single atom will be treated atomically, and can not be partially selected or formatted.\n\t\t\t * Using larger atoms and splitting them as needed is NOT a recommended approach, since this will result in poor merge behavior for concurrent edits.\n\t\t\t * Instead atoms should always be the smallest unit of text which will be independently selected, moved or formatted.\n\t\t\t * @privateRemarks\n\t\t\t * This content logically represents the whole atom's content, so using {@link EmptyKey} makes sense to help indicate that.\n\t\t\t */\n\t\t\tcontent: SchemaFactory.required([SchemaFactory.string], { key: EmptyKey }),\n\t\t})\n\t\timplements TextAtom {}\n\n\t/**\n\t * Statics for text nodes.\n\t * @internal\n\t */\n\texport interface Statics<TTree> {\n\t\t/**\n\t\t * Construct a node of `this` schema from a string, where each character (as defined by iterating over the string) becomes a single character in the text node.\n\t\t * @remarks This combines pairs of utf-16 surrogate code units into single characters as appropriate.\n\t\t */\n\t\tfromString(value: string): TTree;\n\t}\n\n\t/**\n\t * Interface for a text node.\n\t * @remarks\n\t * The string is broken up into substrings which are referred to as 'characters'.\n\t * Unlike with JavaScript strings, all indexes are by character, not UTF-16 code unit.\n\t * This avoids the problem JavaScript where it can split UTF-16 surrogate pairs producing invalid strings,\n\t * and avoids the issue where indexing a string and iterating it segment the string differently.\n\t * This does NOT mean the characters correspond to user perceived characters (like grapheme clusters try to do):\n\t * applications will likely want to include higher level segmentation logic\n\t * which might differ between operations like delete\n\t * (which often operates on something in between unicode code points and grapheme clusters)\n\t * and navigation/selection (which typically uses grapheme clusters).\n\t *\n\t * @see {@link FormattedTextAsTree.Statics.fromString} for construction.\n\t * @see {@link FormattedTextAsTree.createSchema} for creating schemas whose nodes implement this.\n\t * @internal\n\t */\n\texport interface Members<TFormatTree, TPartialFormat, TFormattedAtom, TFormattedInsert>\n\t\textends TextAsTree.Members {\n\t\t/**\n\t\t * Format to use by default for text inserted with non-formatted APIs.\n\t\t * @remarks\n\t\t * This is not persisted in the tree, and observation of it is not tracked by the tree observation tracking.\n\t\t * @privateRemarks\n\t\t * Opt this into observation tracking.\n\t\t */\n\t\tdefaultFormat: TFormatTree;\n\n\t\t/**\n\t\t * Gets an array type view of the characters currently in the text.\n\t\t * @remarks\n\t\t * This iterator matches the behavior of {@link (TreeArrayNode:interface)} with respect to edits during iteration.\n\t\t * @privateRemarks\n\t\t * Currently this is implemented by a node and changes with the text over time.\n\t\t * We might not want to leak a node like this in the API.\n\t\t * Providing a way to index and iterate separately might be better.\n\t\t */\n\t\tcharactersWithFormatting(): readonly TFormattedAtom[];\n\n\t\t/**\n\t\t * Insert a range of characters into the string based on character index.\n\t\t * @remarks\n\t\t * See {@link (TreeArrayNode:interface).insertAt} for more details on the behavior.\n\t\t * See {@link FormattedTextAsTree.Statics.fromString} for how the `additionalCharacters` string is broken into characters.\n\t\t * @privateRemarks\n\t\t * If we provide ways to customize character boundaries, that could be handled here by taking in an Iterable<string> instead of a string.\n\t\t * Doing this currently would enable insertion of text with different character boundaries than the existing text,\n\t\t * which would violate the currently documented character boundary invariants.\n\t\t *\n\t\t * Another option would be to take an approach like Table,\n\t\t * where the user of the API uses a factory function to generate the schema, and can inject custom logic, like a string character iterator.\n\t\t */\n\t\tinsertWithFormattingAt(\n\t\t\tindex: number,\n\t\t\tadditionalCharacters: Iterable<TFormattedInsert>,\n\t\t): void;\n\n\t\t/**\n\t\t * Apply formatting to a range of characters based on character index.\n\t\t * @param startIndex - The starting index (inclusive) of the range to format.\n\t\t * @param endIndex - The ending index (exclusive) of the range to format.\n\t\t * @param format - The formatting to apply to the specified range.\n\t\t * @remarks\n\t\t * The start and end behave the same as in {@link (TreeArrayNode:interface).removeRange}.\n\t\t */\n\t\tformatRange(\n\t\t\tstartIndex: number | undefined,\n\t\t\tendIndex: number | undefined,\n\t\t\tformat: TPartialFormat,\n\t\t): void;\n\n\t\t/**\n\t\t * Returns the length of the run of characters starting at `startIndex` which have the same formatting and atom type, up to `endIndex`.\n\t\t * @param startIndex - The starting index of the run.\n\t\t * @param endIndex - The ending index (exclusive) of the run. Defaults to the end of the text.\n\t\t */\n\t\tgetUniformRun(startIndex: number, endIndex?: number): number;\n\t\t/**\n\t\t * Returns a substring of the text from `startIndex` to `endIndex`\n\t\t * @param startIndex - starting index (inclusive)\n\t\t * @param endIndex - Optional ending index (exclusive). Defaults to the end of the text.\n\t\t */\n\t\tgetString(startIndex: number, endIndex?: number): string;\n\n\t\t/**\n\t\t * Subscribe to all content changes on this text node, including both shallow\n\t\t * changes (inserts/removes) and deep changes (formatting updates on existing characters).\n\t\t * @param callback - Called after each change with a sequence of {@link TextAsTree.TextOp}s describing what changed,\n\t\t * or `undefined` when a delta could not be computed (e.g. during a schema upgrade).\n\t\t * @returns A cleanup function that unsubscribes the callback when called.\n\t\t * @remarks\n\t\t * Unlike {@link TextAsTree.Members.onCharactersChanged} which only fires on\n\t\t * shallow changes (inserts and removes), this method also fires on deep changes —\n\t\t * formatting property updates on existing characters.\n\t\t * The {@link TextAsTree.TextRetainOp.formattingChanged} flag on retain ops\n\t\t * indicates which character ranges had formatting updates.\n\t\t *\n\t\t * All counts in the delivered ops are in Unicode code points, not UTF-16 code units.\n\t\t * For characters outside the Basic Multilingual Plane (e.g. emoji), one code point\n\t\t * corresponds to two UTF-16 code units — convert before using the counts as string indices.\n\t\t */\n\t\tonContentChanged(\n\t\t\tcallback: (ops: readonly TextAsTree.TextOp[] | undefined) => void,\n\t\t): () => void;\n\t}\n\n\t/**\n\t * Insertable shape for a formatted text atom used by {@link FormattedTextAsTree.Members.insertWithFormattingAt}.\n\t * @internal\n\t */\n\texport interface FormattedAtomInsertable<TFormat, TContent> {\n\t\treadonly content: TContent;\n\t\treadonly format: TFormat;\n\t}\n\n\t/**\n\t * Schema identifier for the a generic formatted text schema.\n\t * @privateRemarks\n\t * Eventually this should probably be given a better name and/or made a system type in a system namespace.\n\t * @internal\n\t */\n\texport type FormattedTextSchemaIdentifier<TUserScope extends string> = ScopedSchemaName<\n\t\t`com.fluidframework.text.formatted<${TUserScope}>`,\n\t\t\"Text\"\n\t>;\n\n\t/**\n\t * Helper for expressing the full set of formatted text atoms for a given schema.\n\t * @privateRemarks\n\t * Eventually this should probably be given a better name and/or made a system type in a system namespace.\n\t * @internal\n\t */\n\texport type FormattedTextAtoms<\n\t\tExtraAtomsSchema extends readonly LazyItem<\n\t\t\tTreeNodeSchema<string, NodeKind, TextAtom & TreeNode>\n\t\t>[],\n\t> = readonly [typeof StringTextAtom, ...ExtraAtomsSchema];\n\n\t/**\n\t * Helper for configuring {@link FormattedTextAsTree.Members}.\n\t * @privateRemarks\n\t * Eventually this should probably be inlined into `FormattedTextAsTree.Members` or made a system type in a system namespace.\n\t * The approach should be evaluated after settling on a redesign of the `formatRange` API as that will impact what the type parameters are.\n\t * @internal\n\t */\n\texport type FormattedTextMembers<\n\t\tFormatSchema extends ImplicitAllowedTypes,\n\t\tExtraAtomsSchema extends readonly LazyItem<\n\t\t\tTreeNodeSchema<string, NodeKind, TextAtom & TreeNode>\n\t\t>[],\n\t> = Members<\n\t\tTreeFieldFromImplicitField<FormatSchema>,\n\t\tPartial<TreeNodeFromImplicitAllowedTypes<FormatSchema>>,\n\t\tFormattedAtom<\n\t\t\tTreeNodeFromImplicitAllowedTypes<FormatSchema>,\n\t\t\tTreeNodeFromImplicitAllowedTypes<FormattedTextAtoms<ExtraAtomsSchema>>\n\t\t>,\n\t\tFormattedAtomInsertable<\n\t\t\tInsertableTreeNodeFromImplicitAllowedTypes<FormatSchema>,\n\t\t\tInsertableTreeNodeFromImplicitAllowedTypes<FormattedTextAtoms<ExtraAtomsSchema>>\n\t\t>\n\t>;\n\n\t/**\n\t * A generic type for a formatted text schema.\n\t * @internal\n\t */\n\texport type FormattedTextSchema<\n\t\tTUserScope extends string,\n\t\tFormatSchema extends ImplicitAllowedTypes,\n\t\tExtraAtomsSchema extends readonly LazyItem<\n\t\t\tTreeNodeSchema<string, NodeKind, TextAtom & TreeNode>\n\t\t>[],\n\t> = Statics<\n\t\tErasedNode<\n\t\t\tFormattedTextMembers<FormatSchema, ExtraAtomsSchema>,\n\t\t\tFormattedTextSchemaIdentifier<TUserScope>\n\t\t>\n\t> &\n\t\tErasedSchemaSubclassable<\n\t\t\tFormattedTextMembers<FormatSchema, ExtraAtomsSchema>,\n\t\t\tFormattedTextSchemaIdentifier<TUserScope>\n\t\t>;\n}\n"]}
1
+ {"version":3,"file":"textDomainFormatted.js","sourceRoot":"","sources":["../../src/text/textDomainFormatted.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAEH,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAC/F,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EACN,QAAQ,EACR,sBAAsB,GAItB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EACN,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,QAAQ,EACR,2CAA2C,EAC3C,kBAAkB,EAClB,kBAAkB,EAClB,8BAA8B,GAC9B,MAAM,yBAAyB,CAAC;AAiBjC,OAAO,EACN,KAAK,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,kBAAkB,GAClB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,oBAAoB,EACpB,iCAAiC,EACjC,6BAA6B,GAE7B,MAAM,iBAAiB,CAAC;AAEzB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C,MAAM,CAAC,QAAQ,EAAE,CAAC;wBAClB,MAAM,CAAC,SAAS,EAAE,CAAC;wBAEnB,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;4BAC5B,MAAM;wBACP,CAAC;wBAED,SAAS,EAAE,CAAC;oBACb,CAAC;oBACD,MAAM,CAAC,QAAQ,EAAE,CAAC;oBAClB,OAAO,SAAS,CAAC;gBAClB,CAAC,CAAC,CAAC;YACJ,CAAC;SACD;QAED;;WAEG;QACH,MAAM,UACL,SAAQ,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE;YAC/B,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;YACzD,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,YAAY,CAAC;SAC5C,CAAC;SAKG;QAEN;;;;;;;;;;;WAWG;QACH,MAAM,IAAI,GAAG,8BAA8B,EAGxC,CAAC,QAAQ,CAAC,CAAC;QAMd,OAAO,IAAI,CAAC;IACb,CAAC;IA7de,gCAAY,eA6d3B,CAAA;IA4DD;;;;OAIG;IACU,kCAAc,GAAG,kBAAkB,EAAmC,CAClF,kBAAkB,CAClB,CAAC;AAqPH,CAAC,EAzyBgB,mBAAmB,KAAnB,mBAAmB,QAyyBnC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, compareArrays, debugAssert, fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tEmptyKey,\n\tforEachNodeSubsequence,\n\ttype FieldKey,\n\ttype ITreeCursorSynchronous,\n\ttype TreeValue,\n} from \"../core/index.js\";\nimport { currentObserver, buildNodeComparator } from \"../feature-libraries/index.js\";\nimport { TreeAlpha, Tree as TreeStatic } from \"../shared-tree/index.js\";\nimport {\n\tgetInnerNode,\n\tSchemaFactory,\n\tSchemaFactoryAlpha,\n\tTreeArrayNode,\n\tTreeBeta,\n\tcreateCustomizedFluidFrameworkScopedFactory,\n\teraseSchemaDetails,\n\tisObjectNodeSchema,\n\teraseSchemaDetailsSubclassable,\n} from \"../simple-tree/index.js\";\nimport type {\n\tTreeNodeSchema,\n\tLazyItem,\n\tImplicitAllowedTypes,\n\tTreeFieldFromImplicitField,\n\tInsertableTypedNode,\n\tTreeNodeFromImplicitAllowedTypes,\n\tInsertableTreeNodeFromImplicitAllowedTypes,\n\tInsertableTreeFieldFromImplicitField,\n\tNodeKind,\n\tTreeNode,\n\tScopedSchemaName,\n\tErasedSchemaSubclassable,\n\tErasedNode,\n\tSchemaFactoryBeta,\n} from \"../simple-tree/index.js\";\nimport {\n\tbrand,\n\tmapIterable,\n\toneFromIterable,\n\tvalidateIndex,\n\tvalidateIndexRange,\n} from \"../util/index.js\";\n\nimport {\n\tcharactersFromString,\n\texpensiveInternalValidationAssert,\n\tprocessCharactersChangedDelta,\n\ttype TextAsTree,\n} from \"./textDomain.js\";\n\n/**\n * Sets up scope for formatted text schema built-in types.\n * @remarks User-provided factory scoping will be applied as `com.fluidframework.text.formatted<user-scope>`.\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -- Inferring is the most practical option here\nfunction createFormattedScopedFactory<TUserScope extends string>(\n\tinputSchemaFactory: SchemaFactoryBeta<TUserScope>,\n) {\n\treturn createCustomizedFluidFrameworkScopedFactory(inputSchemaFactory, \"text.formatted\");\n}\n\n/**\n * Schema factory for formatted text types which are not generic.\n */\nconst sfStatic = new SchemaFactoryAlpha(\"com.fluidframework.text.formatted\");\n\nconst formatKey: FieldKey = brand(\"format\");\n\n/**\n * Atom in the string containing a single character.\n * @privateRemarks\n * This is outside the namespace so it can be exported for testing, but not package exported.\n */\nexport class StringTextAtomNode\n\textends sfStatic.object(\"StringTextAtom\", {\n\t\t/**\n\t\t * The underlying text content of this atom.\n\t\t * @remarks\n\t\t * This is typically a single Unicode code point, and thus may contain multiple UTF-16 surrogate pair code units.\n\t\t * Longer strings are still valid. For example, users might store whole grapheme clusters here, or even longer sections of text.\n\t\t * Anything combined into a single atom will be treated atomically, and can not be partially selected or formatted.\n\t\t * Using larger atoms and splitting them as needed is NOT a recommended approach, since this will result in poor merge behavior for concurrent edits.\n\t\t * Instead, atoms should always be the smallest unit of text which will be independently selected, moved or formatted.\n\t\t * @privateRemarks\n\t\t * This content logically represents the whole atom's content, so using {@link EmptyKey} makes sense to help indicate that.\n\t\t */\n\t\tcontent: SchemaFactory.required([SchemaFactory.string], { key: EmptyKey }),\n\t})\n\timplements FormattedTextAsTree.TextAtom\n{\n\tpublic static fromCharacter(value: string): StringTextAtomNode {\n\t\tconst character = oneFromIterable(charactersFromString(value));\n\t\tif (character === undefined) {\n\t\t\tthrow new UsageError(\"value must contain exactly one Unicode character.\");\n\t\t}\n\t\treturn new StringTextAtomNode({ content: character });\n\t}\n\n\tpublic static fromString(value: string): StringTextAtomNode[] {\n\t\treturn Array.from(\n\t\t\tcharactersFromString(value),\n\t\t\t(character) => new StringTextAtomNode({ content: character }),\n\t\t);\n\t}\n}\n\n/**\n * A collection of text related types, schema and utilities for working with text beyond the basic {@link SchemaStatics.string}.\n * @remarks\n * This is generic over formatting an embedded object/atom types.\n * See {@link FormattedTextAsTreeDefault} for a default parameterization.\n * @privateRemarks\n * TODO:\n * - Add more comprehensive tests for generic parameterizations other than default.\n * - Sort out API around overwriting subsets of formatting information.\n * @internal\n */\nexport namespace FormattedTextAsTree {\n\t/**\n\t * Creates a schema for a formatted text node, parameterized by the formatting and the embedded object (atom) types.\n\t *\n\t * @param inputSchemaFactory - The {@link SchemaFactoryBeta} used to scope the generated schema.\n\t * The generated types are scoped under `com.fluidframework.text.formatted<TUserScope>`, where `TUserScope` is the scope of this factory.\n\t * This scope is used to distinguish different usages of `createSchema` from each-other, and must be kept the same between versions for nodes to remain compatible.\n\t * It must be different to distinguish different formatted text schema within the same document.\n\t * @param formatSchema - Schema describing the formatting associated with each atom of text.\n\t * Use an {@link NodeKind.Object|Object node} to support {@link FormattedTextAsTree.Members.formatRange}.\n\t * @param extraAtoms - Additional atom schema to allow as text content beyond the built-in {@link FormattedTextAsTree.(StringTextAtom:variable)}.\n\t * Use this to embed richer content (for example line breaks or inline objects) alongside plain characters.\n\t * @param defaultFormatInsertable - The formatting applied to text inserted via non-formatted APIs\n\t * (for example {@link FormattedTextAsTree.Members.insertAt} and {@link FormattedTextAsTree.Statics.fromString} when no explicit format is provided).\n\t * @returns The schema for the formatted text node, whose nodes implement {@link FormattedTextAsTree.Members} and whose statics implement {@link FormattedTextAsTree.Statics}.\n\t * @remarks\n\t * See {@link FormattedTextAsTreeDefault} for a default parameterization of this factory.\n\t * @privateRemarks\n\t * TODO: The choice to always include the built-in {@link FormattedTextAsTree.(StringTextAtom:variable)} is a design decision that should be re-evaluated before stabilizing.\n\t */\n\texport function createSchema<\n\t\tconst TUserScope extends string,\n\t\tconst FormatSchema extends ImplicitAllowedTypes,\n\t\tconst ExtraAtomsSchema extends readonly LazyItem<\n\t\t\tTreeNodeSchema<string, NodeKind, TextAtom & TreeNode>\n\t\t>[],\n\t>(\n\t\tinputSchemaFactory: SchemaFactoryBeta<TUserScope>,\n\t\tformatSchema: FormatSchema,\n\t\textraAtoms: ExtraAtomsSchema,\n\t\tdefaultFormatInsertable: InsertableTreeFieldFromImplicitField<FormatSchema>,\n\t): FormattedTextSchema<TUserScope, FormatSchema, ExtraAtomsSchema> {\n\t\tconst atoms = [StringTextAtom, ...extraAtoms] as const;\n\t\t/**\n\t\t * The type of a text atom node, which goes in a StringAtom.\n\t\t */\n\t\ttype TextAtomNode = TreeNodeFromImplicitAllowedTypes<TextAtomSchemas<ExtraAtomsSchema>>;\n\n\t\tconst sf = createFormattedScopedFactory(inputSchemaFactory);\n\n\t\tconst defaultFormat: TreeFieldFromImplicitField<FormatSchema> =\n\t\t\tTreeBeta.create<FormatSchema>(formatSchema, defaultFormatInsertable);\n\n\t\t/**\n\t\t * Gets a format node, which must be cloned before being inserted.\n\t\t */\n\t\tfunction getFormatNode(\n\t\t\tformat?: InsertableTreeFieldFromImplicitField<FormatSchema>,\n\t\t): TreeFieldFromImplicitField<FormatSchema> {\n\t\t\t// Note we cannot use the `format ?? defaultFormat` syntax as format is allowed to be `null`.\n\t\t\treturn format === undefined\n\t\t\t\t? defaultFormat\n\t\t\t\t: TreeBeta.create<FormatSchema>(formatSchema, format);\n\t\t}\n\n\t\tfunction cloneFormat(\n\t\t\tformat: TreeFieldFromImplicitField<FormatSchema>,\n\t\t): TreeFieldFromImplicitField<FormatSchema> &\n\t\t\tTreeNodeFromImplicitAllowedTypes<FormatSchema> {\n\t\t\tconst clone: TreeFieldFromImplicitField<FormatSchema> =\n\t\t\t\tTreeBeta.clone<FormatSchema>(format);\n\t\t\t// TypeScript fails to prove that cloning a node gives a node, and not possible undefined (like cloning a empty field could).\n\t\t\t// This cast helps users of this function get the types they need.\n\t\t\treturn clone as typeof clone & TreeNodeFromImplicitAllowedTypes<FormatSchema>;\n\t\t}\n\n\t\tclass TextNode\n\t\t\textends sf.object(\"Text\", {\n\t\t\t\tcontent: SchemaFactory.required([() => StringArray], { key: EmptyKey }),\n\t\t\t})\n\t\t\timplements Members<FormatSchema, ExtraAtomsSchema>\n\t\t{\n\t\t\tpublic insertAt(\n\t\t\t\tindex: number,\n\t\t\t\tadditionalCharacters:\n\t\t\t\t\t| string\n\t\t\t\t\t| Iterable<TreeNodeFromImplicitAllowedTypes<TextAtomSchemas<ExtraAtomsSchema>>>,\n\t\t\t\tformat?: InsertableTreeFieldFromImplicitField<FormatSchema>,\n\t\t\t): void {\n\t\t\t\tconst newAtoms: Iterable<TextAtomNode> =\n\t\t\t\t\ttypeof additionalCharacters === \"string\"\n\t\t\t\t\t\t? stringTextAtomsFromString(additionalCharacters)\n\t\t\t\t\t\t: additionalCharacters;\n\t\t\t\tconst formatNode = getFormatNode(format);\n\t\t\t\tthis.content.insertAt(\n\t\t\t\t\tindex,\n\t\t\t\t\tTreeArrayNode.spread(stringAtomsFromTextAtoms(newAtoms, formatNode)),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tpublic removeRange(index: number | undefined, end: number | undefined): void {\n\t\t\t\tthis.content.removeRange(index, end);\n\t\t\t}\n\n\t\t\tpublic characters(): Iterable<string> {\n\t\t\t\treturn mapIterable(this.content, (atom) => atom.content.content);\n\t\t\t}\n\n\t\t\tpublic charactersCopy(): string[] {\n\t\t\t\tconst result = this.content.charactersCopy();\n\t\t\t\texpensiveInternalValidationAssert(\n\t\t\t\t\t() =>\n\t\t\t\t\t\tcompareArrays(result, this.#charactersCopy_reference()) ||\n\t\t\t\t\t\t\"invalid charactersCopy optimizations\",\n\t\t\t\t);\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tpublic characterCount(): number {\n\t\t\t\treturn this.content.length;\n\t\t\t}\n\n\t\t\tpublic fullString(): string {\n\t\t\t\tconst result = this.content.fullString();\n\t\t\t\texpensiveInternalValidationAssert(\n\t\t\t\t\t() => result === this.#fullString_reference() || \"invalid fullString optimizations\",\n\t\t\t\t);\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * A non-optimized reference implementation of fullString.\n\t\t\t */\n\t\t\t#fullString_reference(): string {\n\t\t\t\treturn [...this.characters()].join(\"\");\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Unoptimized trivially correct implementation of charactersCopy.\n\t\t\t */\n\t\t\t#charactersCopy_reference(): string[] {\n\t\t\t\treturn [...this.characters()];\n\t\t\t}\n\n\t\t\tpublic static fromString(\n\t\t\t\tvalue: string,\n\t\t\t\tformat?: InsertableTreeFieldFromImplicitField<FormatSchema>,\n\t\t\t): TextNode {\n\t\t\t\tconst formatNode = getFormatNode(format);\n\t\t\t\t// Use `this` rather than `TextNode` so the more derived schema class is constructed when using this as a static on a subclass.\n\t\t\t\treturn new this({\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t// Constructing an ArrayNode from an iterator is supported, so creating an array from the iterable of characters seems like it's not necessary here,\n\t\t\t\t\t\t// but to reduce the risk of incorrect data interpretation, we actually ban this in the special case where the iterable is a string directly, which is the case here.\n\t\t\t\t\t\t// Thus the array construction here is necessary to avoid a runtime error.\n\t\t\t\t\t\t...textAtomsFromString(value, formatNode),\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tpublic charactersWithFormatting(): readonly StringAtom[] {\n\t\t\t\treturn this.content;\n\t\t\t}\n\t\t\tpublic insertWithFormattingAt(\n\t\t\t\tindex: number,\n\t\t\t\tadditionalCharacters: Iterable<InsertableTypedNode<typeof StringAtom>>,\n\t\t\t): void {\n\t\t\t\tthis.content.insertAt(index, TreeArrayNode.spread(additionalCharacters));\n\t\t\t}\n\n\t\t\tpublic formatRange(\n\t\t\t\tstart: number | undefined,\n\t\t\t\tend: number | undefined,\n\t\t\t\tformat: Partial<TreeNodeFromImplicitAllowedTypes<FormatSchema>>,\n\t\t\t): void {\n\t\t\t\tconst fieldFormatsRaw = Object.entries(format) as [\n\t\t\t\t\tkeyof TreeNodeFromImplicitAllowedTypes<FormatSchema>,\n\t\t\t\t\tunknown,\n\t\t\t\t][];\n\t\t\t\tconst fieldFormats = fieldFormatsRaw.map(([key, value]) => {\n\t\t\t\t\t// Object.entries should only return string keyed enumerable own properties.\n\t\t\t\t\t// The TypeScript typing does not account for this, and thus this assertion is necessary for this code to compile.\n\t\t\t\t\tassert(\n\t\t\t\t\t\ttypeof key === \"string\",\n\t\t\t\t\t\t0xcc8 /* Object.entries returned a non-string key. */,\n\t\t\t\t\t);\n\t\t\t\t\treturn [key, value] as const;\n\t\t\t\t});\n\t\t\t\tthis.#editRange(start, end, \"FormattedTextAsTree.formatRange\", (atom) => {\n\t\t\t\t\tconst formatNode: TreeNode | TreeValue = atom.format;\n\t\t\t\t\tconst atomFormatSchema = TreeStatic.schema(formatNode);\n\t\t\t\t\tif (!isObjectNodeSchema(atomFormatSchema)) {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\"formatRange currently only supports object nodes for the format.\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tfor (const [key, value] of fieldFormats) {\n\t\t\t\t\t\tconst field = atomFormatSchema.fields.get(key);\n\t\t\t\t\t\tif (field === undefined) {\n\t\t\t\t\t\t\tthrow new UsageError(`Unknown format key: ${key}`);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Ensures that if the input is a node, it is cloned before being inserted into the tree.\n\t\t\t\t\t\t// Note that since this uses field schema, `undefined` can pass through this if allowed by the schema.\n\t\t\t\t\t\tconst clonedValue = TreeBeta.clone(TreeBeta.create(field, value as never)) as\n\t\t\t\t\t\t\t| TreeNode\n\t\t\t\t\t\t\t| TreeValue;\n\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tformatNode as unknown as Record<\n\t\t\t\t\t\t\t\tkeyof TreeNodeFromImplicitAllowedTypes<FormatSchema>,\n\t\t\t\t\t\t\t\tTreeNode | TreeValue\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t)[key] = clonedValue;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tpublic reformat(\n\t\t\t\tstart: number | undefined,\n\t\t\t\tend: number | undefined,\n\t\t\t\tformat?: InsertableTreeFieldFromImplicitField<FormatSchema>,\n\t\t\t): void {\n\t\t\t\tconst node = getFormatNode(format);\n\t\t\t\tthis.#editRange(start, end, \"FormattedTextAsTree.reformat\", (atom) => {\n\t\t\t\t\tatom.format = cloneFormat(node);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Map an edit over a range of atoms, validating the range and running the edits in a transaction.\n\t\t\t * @remarks\n\t\t\t * This is not exposed in the API since this approach will have to be replaced when formatting is optimized,\n\t\t\t * so we don't want users to directly depend on this un-optimizable layer.\n\t\t\t */\n\t\t\t#editRange(\n\t\t\t\tstart: number | undefined,\n\t\t\t\tend: number | undefined,\n\t\t\t\tmethod: string,\n\t\t\t\tedit: (atom: StringAtom) => void,\n\t\t\t): void {\n\t\t\t\tconst formatStart = start ?? 0;\n\t\t\t\tvalidateIndex(formatStart, this.content, method, true);\n\n\t\t\t\tconst formatEnd = Math.min(this.content.length, end ?? this.content.length);\n\t\t\t\tvalidateIndexRange(formatStart, formatEnd, this.content, method);\n\n\t\t\t\tTreeAlpha.context(this).runTransaction(() => {\n\t\t\t\t\tfor (let i = formatStart; i < formatEnd; i++) {\n\t\t\t\t\t\tconst atom = this.content[i];\n\t\t\t\t\t\t// Range validated above, so this should never fail.\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tatom !== undefined,\n\t\t\t\t\t\t\t0xd08 /* Index out of bounds while formatting text range. */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tedit(atom);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Returns the {@link FormattedTextAsTree.TextAtom.content} at the given atom index, or `undefined` if out of bounds.\n\t\t\t */\n\t\t\tprivate getAtomCharacterAt(index: number): string | undefined {\n\t\t\t\tconst atom = this.content[index];\n\t\t\t\tif (atom === undefined) return undefined;\n\t\t\t\treturn atom.content.content;\n\t\t\t}\n\n\t\t\tpublic onCharactersChanged(\n\t\t\t\tcallback: (ops: readonly TextAsTree.TextOp[] | undefined) => void,\n\t\t\t): () => void {\n\t\t\t\treturn TreeAlpha.on(this.content, \"nodeChanged\", ({ delta }) =>\n\t\t\t\t\tprocessCharactersChangedDelta(\n\t\t\t\t\t\tdelta,\n\t\t\t\t\t\t(index) => this.getAtomCharacterAt(index),\n\t\t\t\t\t\tcallback,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tpublic onContentChanged(\n\t\t\t\tcallback: (ops: readonly TextAsTree.TextOp[] | undefined) => void,\n\t\t\t): () => void {\n\t\t\t\treturn TreeAlpha.on(this.content, \"treeChanged\", ({ delta }) =>\n\t\t\t\t\tprocessCharactersChangedDelta(\n\t\t\t\t\t\tdelta,\n\t\t\t\t\t\t(index) => this.getAtomCharacterAt(index),\n\t\t\t\t\t\tcallback,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tpublic getUniformRun(startIndex: number, endIndex?: number): number {\n\t\t\t\treturn this.content.getUniformRun(startIndex, endIndex);\n\t\t\t}\n\n\t\t\tpublic getString(startIndex: number, endIndex?: number): string {\n\t\t\t\treturn this.content.getString(startIndex, endIndex);\n\t\t\t}\n\t\t}\n\n\t\tfunction stringTextAtomsFromString(\n\t\t\tvalue: string,\n\t\t): Iterable<StringTextAtom & TextAtomNode> {\n\t\t\t// TypeScript can't prove in this Generic context that StringTextAtom is assignable to TextAtomNode, so we have to cast.\n\t\t\t// Since TextAtomSchemas unconditionally includes StringTextAtom, this cast is safe.\n\t\t\treturn StringTextAtom.fromString(value) as (StringTextAtom & TextAtomNode)[];\n\t\t}\n\n\t\tfunction stringAtomsFromTextAtoms(\n\t\t\tvalue: Iterable<TreeNodeFromImplicitAllowedTypes<TextAtomSchemas<ExtraAtomsSchema>>>,\n\t\t\tformat: TreeFieldFromImplicitField<FormatSchema>,\n\t\t): Iterable<StringAtom> {\n\t\t\tconst result = mapIterable(value, (content) => {\n\t\t\t\tconst data = {\n\t\t\t\t\tcontent,\n\t\t\t\t\tformat: cloneFormat(format),\n\t\t\t\t};\n\t\t\t\treturn new StringAtom(data as never); // Generic break type safety here. TODO: try and make safer.\n\t\t\t});\n\t\t\treturn result;\n\t\t}\n\n\t\tfunction textAtomsFromString(\n\t\t\tvalue: string,\n\t\t\tformat: TreeFieldFromImplicitField<FormatSchema>,\n\t\t): Iterable<StringAtom> {\n\t\t\tconst textAtoms = stringTextAtomsFromString(value);\n\t\t\treturn stringAtomsFromTextAtoms(textAtoms, format);\n\t\t}\n\n\t\tclass StringArray extends sf.array(\"StringArray\", [() => StringAtom]) {\n\t\t\tpublic withBorrowedSequenceCursor<T>(f: (cursor: ITreeCursorSynchronous) => T): T {\n\t\t\t\tconst innerNode = getInnerNode(this);\n\t\t\t\t// Since the cursor will be used to read content from the tree and won't track observations,\n\t\t\t\t// treat it as if it observed the whole subtree.\n\t\t\t\tcurrentObserver?.observeNodeDeep(innerNode);\n\t\t\t\tconst cursor = innerNode.borrowCursor();\n\t\t\t\tcursor.enterField(EmptyKey);\n\t\t\t\tconst result = f(cursor);\n\t\t\t\tcursor.exitField();\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tprivate getCharactersSubarray(startIndex: number, endIndex: number): string[] {\n\t\t\t\tconst slowPathIndexes: number[] = [];\n\t\t\t\tconst result: string[] = [];\n\t\t\t\tthis.withBorrowedSequenceCursor((cursor) => {\n\t\t\t\t\tforEachNodeSubsequence(cursor, startIndex, endIndex, () => {\n\t\t\t\t\t\tdebugAssert(\n\t\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\t\t(cursor.type as string) === StringAtom.identifier ||\n\t\t\t\t\t\t\t\t\"invalid fullString type optimizations\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcursor.enterField(EmptyKey);\n\t\t\t\t\t\tcursor.enterNode(0);\n\t\t\t\t\t\tlet content: string;\n\t\t\t\t\t\tswitch (cursor.type) {\n\t\t\t\t\t\t\tcase StringTextAtom.identifier: {\n\t\t\t\t\t\t\t\tcursor.enterField(EmptyKey);\n\t\t\t\t\t\t\t\tcursor.enterNode(0);\n\t\t\t\t\t\t\t\tcontent = cursor.value as string;\n\t\t\t\t\t\t\t\tdebugAssert(\n\t\t\t\t\t\t\t\t\t() => typeof content === \"string\" || \"invalid fullString type optimizations\",\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\t\t\t\tcursor.exitField();\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// TODO: we could optimize this for constant cases via an optional symbol on the atom schema holding the constant.\n\t\t\t\t\t\t\t// A less general optimization could just include cases for build in types with constant values\n\t\t\t\t\t\t\t// (like below commented code: currently this would cause a cyclical dependency but could be refactored).\n\t\t\t\t\t\t\t// case FormattedTextAsTree.StringLineAtom.identifier: {\n\t\t\t\t\t\t\t// \tcontent = \"\\n\";\n\t\t\t\t\t\t\t// \tbreak;\n\t\t\t\t\t\t\t// }\n\t\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\t\tslowPathIndexes.push(result.length);\n\t\t\t\t\t\t\t\tcontent = \"\"; // Placeholder for slow path content\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\t\tcursor.exitField();\n\t\t\t\t\t\tresult.push(content);\n\t\t\t\t\t});\n\t\t\t\t});\n\n\t\t\t\t// Fill in slow path cases not optimized above.\n\t\t\t\tfor (const index of slowPathIndexes) {\n\t\t\t\t\tconst node =\n\t\t\t\t\t\tthis[index + startIndex] ??\n\t\t\t\t\t\tfail(\n\t\t\t\t\t\t\t0xd09 /* getCharactersSubarray failed to find index after index range was checked */,\n\t\t\t\t\t\t);\n\t\t\t\t\tresult[index] = node.content.content;\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tpublic charactersCopy(): string[] {\n\t\t\t\treturn this.getCharactersSubarray(0, this.length);\n\t\t\t}\n\n\t\t\tpublic fullString(): string {\n\t\t\t\treturn this.charactersCopy().join(\"\");\n\t\t\t}\n\n\t\t\tpublic getString(startIndex: number, endIndex: number = this.length): string {\n\t\t\t\tvalidateIndexRange(startIndex, endIndex, this, \"FormattedTextAsTree.getString\");\n\t\t\t\treturn this.getCharactersSubarray(startIndex, endIndex).join(\"\");\n\t\t\t}\n\n\t\t\tpublic getUniformRun(startIndex: number, endIndex: number = this.length): number {\n\t\t\t\tvalidateIndexRange(startIndex, endIndex, this, \"FormattedTextAsTree.getUniformRun\");\n\t\t\t\tif (endIndex === startIndex) {\n\t\t\t\t\tthrow new UsageError(\"endIndex must be greater than startIndex for getUniformRun.\");\n\t\t\t\t}\n\t\t\t\tconst arrayLength = this.length;\n\t\t\t\treturn this.withBorrowedSequenceCursor((cursor) => {\n\t\t\t\t\tcursor.enterNode(startIndex);\n\n\t\t\t\t\t// Capture the content type of the first atom\n\t\t\t\t\tcursor.enterField(EmptyKey);\n\t\t\t\t\tcursor.enterNode(0);\n\t\t\t\t\tconst contentType = cursor.type;\n\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\tcursor.exitField();\n\n\t\t\t\t\t// Build a comparator from the format subtree of the first atom\n\t\t\t\t\t// This compares by field key\n\t\t\t\t\tcursor.enterField(formatKey);\n\t\t\t\t\tcursor.enterNode(0);\n\t\t\t\t\tconst formatComparator = buildNodeComparator(cursor);\n\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\tcursor.exitField();\n\n\t\t\t\t\tlet runLength = 1;\n\t\t\t\t\tconst limit = Math.min(endIndex, arrayLength) - startIndex;\n\n\t\t\t\t\twhile (runLength < limit && cursor.nextNode()) {\n\t\t\t\t\t\t// Compare atom type\n\t\t\t\t\t\tcursor.enterField(EmptyKey);\n\t\t\t\t\t\tcursor.enterNode(0);\n\t\t\t\t\t\tconst typeMatches = cursor.type === contentType;\n\t\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\t\tcursor.exitField();\n\t\t\t\t\t\tif (!typeMatches) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Compare format subtree using the compiled comparator\n\t\t\t\t\t\tcursor.enterField(formatKey);\n\t\t\t\t\t\tcursor.enterNode(0);\n\t\t\t\t\t\tconst formatMatches = formatComparator(cursor);\n\t\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\t\tcursor.exitField();\n\n\t\t\t\t\t\tif (formatMatches !== true) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\trunLength++;\n\t\t\t\t\t}\n\t\t\t\t\tcursor.exitNode();\n\t\t\t\t\treturn runLength;\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * A unit of the text, with formatting.\n\t\t */\n\t\tclass StringAtom\n\t\t\textends sf.object(\"StringAtom\", {\n\t\t\t\tcontent: SchemaFactory.required(atoms, { key: EmptyKey }),\n\t\t\t\tformat: SchemaFactory.required(formatSchema),\n\t\t\t})\n\t\t\timplements\n\t\t\t\tFormattedAtom<\n\t\t\t\t\tTreeNodeFromImplicitAllowedTypes<FormatSchema>,\n\t\t\t\t\tTreeNodeFromImplicitAllowedTypes<typeof atoms>\n\t\t\t\t> {}\n\n\t\t/**\n\t\t * Schema for a text node.\n\t\t * @remarks\n\t\t * See {@link FormattedTextAsTree.Members} for the API.\n\t\t * See {@link FormattedTextAsTree.Statics} for static APIs on this Schema, including construction.\n\t\t * @privateRemarks\n\t\t * eraseSchemaDetailsSubclassable risks user's defining subclass members which collide with internals.\n\t\t * Ideally we would generate private members for non-public properties, but TypeScript does not support this.\n\t\t * It is up to the user of eraseSchemaDetailsSubclassable to manage this risk.\n\t\t *\n\t\t * TODO: there is at least one collision prone member to worry about here: `content`.\n\t\t */\n\t\tconst Tree = eraseSchemaDetailsSubclassable<\n\t\t\tMembers<FormatSchema, ExtraAtomsSchema>,\n\t\t\tStatics<Tree, FormatSchema>\n\t\t>()(TextNode);\n\t\ttype Tree = ErasedNode<\n\t\t\tMembers<FormatSchema, ExtraAtomsSchema>,\n\t\t\tFormattedTextSchemaIdentifier<TUserScope>\n\t\t>;\n\n\t\treturn Tree;\n\t}\n\n\t/**\n\t * Portion of a string with formatting.\n\t * @privateRemarks\n\t * This is implemented {@link StringAtom}, but we avoid leaking the fact this is a TreeNode in the API surface to\n\t * preserve more future flexibility.\n\t * @sealed\n\t * @internal\n\t */\n\texport interface FormattedAtom<TFormat, TText> {\n\t\t/**\n\t\t * Content which is formatted.\n\t\t */\n\t\treadonly content: TText;\n\t\t/**\n\t\t * Formatting which is applied to the content.\n\t\t * @remarks\n\t\t * Can be reassigned or deeply mutated to edit the formatting of the content.\n\t\t */\n\t\tformat: TFormat;\n\t}\n\n\t/**\n\t * Portion of a string.\n\t * @remarks\n\t * Additional kinds of text atoms (also known as embedded objects) which can occur inside a string can implement this.\n\t * The schema for them can then be provided to {@link FormattedTextAsTree.createSchema}.\n\t * @internal\n\t */\n\texport interface TextAtom {\n\t\t/**\n\t\t * The content of the text atom, viewed as a string.\n\t\t */\n\t\treadonly content: string;\n\t}\n\n\t/**\n\t * Static factory functions for {@link FormattedTextAsTree.(StringTextAtom:variable)}.\n\t * @privateRemarks\n\t * We type-erase `StringTextAtom` and only provide these static factories for construction\n\t * to reduce the chance of someone accidentally creating a text atom for a string other than a single unicode code point.\n\t * Other strings should work, but our intention is to provide no type-safe API which can produce them, so an application can take their lack of existence as an invariant if they want.\n\t * It is still however possible to produce them, like export/import round trips with editing in the middle of the process, or collaboration with an equivalent schema which doesn't enforce this invariant.\n\t * @sealed\n\t * @internal\n\t */\n\texport interface StringTextAtomStatics {\n\t\t/**\n\t\t * Creates an atom from exactly one Unicode code point.\n\t\t * @throws A {@link @fluidframework/telemetry-utils#UsageError} if `value` does not contain exactly one Unicode code character.\n\t\t */\n\t\tfromCharacter(value: string): StringTextAtom;\n\n\t\t/**\n\t\t * Creates one atom for each Unicode code point in `value`.\n\t\t */\n\t\tfromString(value: string): StringTextAtom[];\n\t}\n\n\t/**\n\t * Schema for a {@link FormattedTextAsTree.(StringTextAtom:variable)} node.\n\t * @sealed\n\t * @internal\n\t */\n\texport const StringTextAtom = eraseSchemaDetails<TextAtom, StringTextAtomStatics>()(\n\t\tStringTextAtomNode,\n\t);\n\n\t/**\n\t * Node for the {@link FormattedTextAsTree.(StringTextAtom:variable)} schema.\n\t * @sealed\n\t * @internal\n\t */\n\texport type StringTextAtom = ErasedNode<\n\t\tTextAtom,\n\t\t\"com.fluidframework.text.formatted.StringTextAtom\"\n\t>;\n\n\t/**\n\t * Statics for formatted text nodes.\n\t * @sealed\n\t * @internal\n\t */\n\texport interface Statics<TTree, FormatSchema extends ImplicitAllowedTypes> {\n\t\t/**\n\t\t * Construct a node of `this` schema from a string, where each character (as defined by iterating over the string) becomes a single character in the text node.\n\t\t * @remarks This combines pairs of utf-16 surrogate code units into single characters as appropriate.\n\t\t */\n\t\tfromString(\n\t\t\tvalue: string,\n\t\t\tformat?: InsertableTreeFieldFromImplicitField<FormatSchema>,\n\t\t): TTree;\n\t}\n\n\t/**\n\t * Interface for a text node.\n\t * @remarks\n\t * The string is broken up into substrings which are referred to as 'characters'.\n\t * Unlike with JavaScript strings, all indexes are by character, not UTF-16 code unit.\n\t * This avoids the problem JavaScript where it can split UTF-16 surrogate pairs producing invalid strings,\n\t * and avoids the issue where indexing a string and iterating it segment the string differently.\n\t * This does NOT mean the characters correspond to user perceived characters (like grapheme clusters try to do):\n\t * applications will likely want to include higher level segmentation logic\n\t * which might differ between operations like delete\n\t * (which often operates on something in between unicode code points and grapheme clusters)\n\t * and navigation/selection (which typically uses grapheme clusters).\n\t *\n\t * @see {@link FormattedTextAsTree.Statics.fromString} for construction.\n\t * @see {@link FormattedTextAsTree.createSchema} for creating schemas whose nodes implement this.\n\t * @sealed\n\t * @internal\n\t */\n\texport interface Members<\n\t\tFormatSchema extends ImplicitAllowedTypes,\n\t\tExtraAtomsSchema extends readonly LazyItem<\n\t\t\tTreeNodeSchema<string, NodeKind, TextAtom & TreeNode>\n\t\t>[],\n\t> extends TextAsTree.Members {\n\t\t/**\n\t\t * {@link TextAsTree.Members.insertAt} with optional formatting to apply to all additional characters,\n\t\t * and allowing an array of atoms instead of a string.\n\t\t * @param format - Optional formatting to apply to all additional characters. If not specified, the default formatting (from {@link FormattedTextAsTree.createSchema}) will be used.\n\t\t * @remarks\n\t\t * Use {@link FormattedTextAsTree.Members.insertWithFormattingAt} if you need to specify formatting for atom independently.\n\t\t * @override\n\t\t */\n\t\tinsertAt(\n\t\t\tindex: number,\n\t\t\tadditionalCharacters:\n\t\t\t\t| string\n\t\t\t\t| Iterable<TreeNodeFromImplicitAllowedTypes<TextAtomSchemas<ExtraAtomsSchema>>>,\n\t\t\tformat?: InsertableTreeFieldFromImplicitField<FormatSchema>,\n\t\t): void;\n\n\t\t/**\n\t\t * Gets an array type view of the characters currently in the text.\n\t\t * @remarks\n\t\t * This iterator matches the behavior of {@link (TreeArrayNode:interface)} with respect to edits during iteration.\n\t\t *\n\t\t * For more efficient access, use {@link FormattedTextAsTree.Members.getUniformRun} and {@link FormattedTextAsTree.Members.getString} to access ranges of characters\n\t\t * to avoid having to inspect the formatting on every atom.\n\t\t * @privateRemarks\n\t\t * Currently this is implemented by a node and changes with the text over time.\n\t\t * We might not want to leak a node like this in the API.\n\t\t * Providing a way to index and iterate separately might be better.\n\t\t */\n\t\tcharactersWithFormatting(): readonly FormattedAtom<\n\t\t\tTreeNodeFromImplicitAllowedTypes<FormatSchema>,\n\t\t\tTreeNodeFromImplicitAllowedTypes<TextAtomSchemas<ExtraAtomsSchema>>\n\t\t>[];\n\n\t\t/**\n\t\t * Insert a range of characters into the string based on character index.\n\t\t * @remarks\n\t\t * See {@link (TreeArrayNode:interface).insertAt} for more details on the behavior.\n\t\t * See {@link FormattedTextAsTree.Statics.fromString} for how the `additionalCharacters` string is broken into characters.\n\t\t * @privateRemarks\n\t\t * If we provide ways to customize character boundaries, that could be handled here by taking in an Iterable<string> instead of a string.\n\t\t * Doing this currently would enable insertion of text with different character boundaries than the existing text,\n\t\t * which would violate the currently documented character boundary invariants.\n\t\t *\n\t\t * Another option would be to take an approach like Table,\n\t\t * where the user of the API uses a factory function to generate the schema, and can inject custom logic, like a string character iterator.\n\t\t */\n\t\tinsertWithFormattingAt(\n\t\t\tindex: number,\n\t\t\tadditionalCharacters: Iterable<\n\t\t\t\tFormattedAtomInsertable<\n\t\t\t\t\tInsertableTreeNodeFromImplicitAllowedTypes<FormatSchema>,\n\t\t\t\t\tInsertableTreeNodeFromImplicitAllowedTypes<TextAtomSchemas<ExtraAtomsSchema>>\n\t\t\t\t>\n\t\t\t>,\n\t\t): void;\n\n\t\t/**\n\t\t * Apply formatting to a range of characters based on character index.\n\t\t * @param startIndex - The starting index (inclusive) of the range to format.\n\t\t * @param endIndex - The ending index (exclusive) of the range to format.\n\t\t * @param format - The formatting to apply to the specified range.\n\t\t * For each atom, every property of `format` will be cloned and assigned to the atom's format's corresponding subtree, overwriting any existing values for those properties.\n\t\t * All enumerable own properties of `format` will be applied, including those with `undefined` values.\n\t\t * @remarks\n\t\t * The start and end behave the same as in {@link (TreeArrayNode:interface).removeRange}.\n\t\t * This edits existing formatting subtrees on each atom, and only works when those atoms are object nodes.\n\t\t *\n\t\t * This is typically used to set some formatting property, like `bold` on a range of text without impacting other formatting properties.\n\t\t * @privateRemarks\n\t\t * This API is designed such that it can be optimized and improved in the future in a few different ways:\n\t\t * 1. TODO: It can be optimized to use lower level APIs directly, bypassing the overhead of the public API surface.\n\t\t * 2. TODO: A lower level editing API could be introduced and used to more efficiently express the edit (for example a bulk edit based on path, or a way to reuse the inserted content in multiple places instead of having to clone it before making the edit).\n\t\t * 3. TODO: Optimize the encoding of such edits, either with a dedicated format for range edits like this and/or encoding optimizations that can compress such edits over ranges to O(1) space.\n\t\t * 4. TODO: Preserve the range editing semantics through the whole stack to allow for better merge behavior, and make optimizations easier.\n\t\t */\n\t\tformatRange(\n\t\t\tstartIndex: number | undefined,\n\t\t\tendIndex: number | undefined,\n\t\t\tformat: Partial<TreeNodeFromImplicitAllowedTypes<FormatSchema>>,\n\t\t): void;\n\n\t\t/**\n\t\t * Replace formatting of a range of characters based on character index.\n\t\t * @param startIndex - The starting index (inclusive) of the range to format.\n\t\t * @param endIndex - The ending index (exclusive) of the range to format.\n\t\t * @param format - The formatting to replace the formatting of the indicated range with.\n\t\t * For each atom, `format` will be cloned and assigned to the atom's format, overwriting any existing formatting.\n\t\t * If not specified the `defaultFormat` from {@link FormattedTextAsTree.createSchema} will be used.\n\t\t * @remarks\n\t\t * The start and end behave the same as in {@link (TreeArrayNode:interface).removeRange}.\n\t\t *\n\t\t * This is typically used to normalize formatting, like resetting the formatting of a range to default settings.\n\t\t * @privateRemarks\n\t\t * See notes on {@link FormattedTextAsTree.Members.formatRange} for future optimization opportunities.\n\t\t */\n\t\treformat(\n\t\t\tstartIndex?: number | undefined,\n\t\t\tendIndex?: number | undefined,\n\t\t\tformat?: InsertableTreeFieldFromImplicitField<FormatSchema>,\n\t\t): void;\n\n\t\t/**\n\t\t * Returns the length of the run of characters starting at `startIndex` which have the same formatting and atom type, up to `endIndex`.\n\t\t * @param startIndex - The starting index of the run.\n\t\t * @param endIndex - The ending index (exclusive) of the run. Defaults to the end of the text.\n\t\t */\n\t\tgetUniformRun(startIndex: number, endIndex?: number): number;\n\t\t/**\n\t\t * Returns a substring of the text from `startIndex` to `endIndex`\n\t\t * @param startIndex - starting index (inclusive)\n\t\t * @param endIndex - Optional ending index (exclusive). Defaults to the end of the text.\n\t\t */\n\t\tgetString(startIndex: number, endIndex?: number): string;\n\n\t\t/**\n\t\t * Subscribe to all content changes on this text node, including both shallow\n\t\t * changes (inserts/removes) and deep changes (formatting updates on existing characters).\n\t\t * @param callback - Called after each change with a sequence of {@link TextAsTree.TextOp}s describing what changed,\n\t\t * or `undefined` when a delta could not be computed (e.g. during a schema upgrade).\n\t\t * @returns A cleanup function that unsubscribes the callback when called.\n\t\t * @remarks\n\t\t * Unlike {@link TextAsTree.Members.onCharactersChanged} which only fires on\n\t\t * shallow changes (inserts and removes), this method also fires on deep changes —\n\t\t * formatting property updates on existing characters.\n\t\t * The {@link TextAsTree.TextRetainOp.formattingChanged} flag on retain ops\n\t\t * indicates which character ranges had formatting updates.\n\t\t *\n\t\t * All counts in the delivered ops are in Unicode code points, not UTF-16 code units.\n\t\t * For characters outside the Basic Multilingual Plane (e.g. emoji), one code point\n\t\t * corresponds to two UTF-16 code units — convert before using the counts as string indices.\n\t\t */\n\t\tonContentChanged(\n\t\t\tcallback: (ops: readonly TextAsTree.TextOp[] | undefined) => void,\n\t\t): () => void;\n\t}\n\n\t/**\n\t * Insertable shape for a formatted text atom used by {@link FormattedTextAsTree.Members.insertWithFormattingAt}.\n\t * @input\n\t * @internal\n\t */\n\texport interface FormattedAtomInsertable<TFormat, TContent> {\n\t\treadonly content: TContent;\n\t\treadonly format: TFormat;\n\t}\n\n\t/**\n\t * Schema identifier for the a generic formatted text schema.\n\t * @privateRemarks\n\t * Eventually this should probably be given a better name and/or made a system type in a system namespace.\n\t * @internal\n\t */\n\texport type FormattedTextSchemaIdentifier<TUserScope extends string> = ScopedSchemaName<\n\t\t`com.fluidframework.text.formatted<${TUserScope}>`,\n\t\t\"Text\"\n\t>;\n\n\t/**\n\t * Helper for expressing the full set of text atoms for a given schema.\n\t * @remarks\n\t * This is just schema for the text atom {@link AllowedTypes},\n\t * and does not include the actual formatting (which is higher up in the tree).\n\t * @sealed\n\t * @internal\n\t */\n\texport type TextAtomSchemas<\n\t\tExtraAtomsSchema extends readonly LazyItem<\n\t\t\tTreeNodeSchema<string, NodeKind, TextAtom & TreeNode>\n\t\t>[],\n\t> = readonly [typeof StringTextAtom, ...ExtraAtomsSchema];\n\n\t/**\n\t * A generic type for a formatted text schema.\n\t * @sealed\n\t * @internal\n\t */\n\texport type FormattedTextSchema<\n\t\tTUserScope extends string,\n\t\tFormatSchema extends ImplicitAllowedTypes,\n\t\tExtraAtomsSchema extends readonly LazyItem<\n\t\t\tTreeNodeSchema<string, NodeKind, TextAtom & TreeNode>\n\t\t>[],\n\t> = Statics<\n\t\tErasedNode<\n\t\t\tMembers<FormatSchema, ExtraAtomsSchema>,\n\t\t\tFormattedTextSchemaIdentifier<TUserScope>\n\t\t>,\n\t\tFormatSchema\n\t> &\n\t\tErasedSchemaSubclassable<\n\t\t\tMembers<FormatSchema, ExtraAtomsSchema>,\n\t\t\tFormattedTextSchemaIdentifier<TUserScope>\n\t\t>;\n}\n"]}