@fluidframework/tree 2.83.0 → 2.90.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 (412) hide show
  1. package/.vscode/settings.json +6 -5
  2. package/CHANGELOG.md +95 -0
  3. package/README.md +1 -1
  4. package/api-report/tree.alpha.api.md +63 -24
  5. package/api-report/tree.beta.api.md +30 -0
  6. package/api-report/tree.legacy.beta.api.md +30 -0
  7. package/dist/alpha.d.ts +10 -6
  8. package/dist/beta.d.ts +4 -1
  9. package/dist/codec/codec.d.ts +2 -0
  10. package/dist/codec/codec.d.ts.map +1 -1
  11. package/dist/codec/codec.js +4 -3
  12. package/dist/codec/codec.js.map +1 -1
  13. package/dist/codec/index.d.ts +1 -1
  14. package/dist/codec/index.d.ts.map +1 -1
  15. package/dist/codec/index.js +2 -1
  16. package/dist/codec/index.js.map +1 -1
  17. package/dist/codec/versioned/codec.d.ts +13 -1
  18. package/dist/codec/versioned/codec.d.ts.map +1 -1
  19. package/dist/codec/versioned/codec.js +18 -3
  20. package/dist/codec/versioned/codec.js.map +1 -1
  21. package/dist/codec/versioned/format.d.ts +22 -1
  22. package/dist/codec/versioned/format.d.ts.map +1 -1
  23. package/dist/codec/versioned/format.js +16 -3
  24. package/dist/codec/versioned/format.js.map +1 -1
  25. package/dist/codec/versioned/index.d.ts +1 -1
  26. package/dist/codec/versioned/index.d.ts.map +1 -1
  27. package/dist/codec/versioned/index.js +2 -1
  28. package/dist/codec/versioned/index.js.map +1 -1
  29. package/dist/core/index.d.ts +1 -2
  30. package/dist/core/index.d.ts.map +1 -1
  31. package/dist/core/index.js +1 -3
  32. package/dist/core/index.js.map +1 -1
  33. package/dist/core/rebase/index.d.ts +1 -1
  34. package/dist/core/rebase/index.d.ts.map +1 -1
  35. package/dist/core/rebase/index.js.map +1 -1
  36. package/dist/core/rebase/types.d.ts +78 -0
  37. package/dist/core/rebase/types.d.ts.map +1 -1
  38. package/dist/core/rebase/types.js.map +1 -1
  39. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +8 -7
  40. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  41. package/dist/feature-libraries/chunked-forest/codec/codecs.js +22 -44
  42. package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  43. package/dist/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
  44. package/dist/feature-libraries/chunked-forest/codec/format.js +11 -0
  45. package/dist/feature-libraries/chunked-forest/codec/format.js.map +1 -1
  46. package/dist/feature-libraries/chunked-forest/codec/index.d.ts +3 -2
  47. package/dist/feature-libraries/chunked-forest/codec/index.d.ts.map +1 -1
  48. package/dist/feature-libraries/chunked-forest/codec/index.js +2 -4
  49. package/dist/feature-libraries/chunked-forest/codec/index.js.map +1 -1
  50. package/dist/feature-libraries/chunked-forest/index.d.ts +1 -1
  51. package/dist/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  52. package/dist/feature-libraries/chunked-forest/index.js +2 -4
  53. package/dist/feature-libraries/chunked-forest/index.js.map +1 -1
  54. package/dist/feature-libraries/flex-tree/observer.d.ts +17 -0
  55. package/dist/feature-libraries/flex-tree/observer.d.ts.map +1 -1
  56. package/dist/feature-libraries/flex-tree/observer.js.map +1 -1
  57. package/dist/feature-libraries/forest-summary/codec.d.ts +5 -12
  58. package/dist/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  59. package/dist/feature-libraries/forest-summary/codec.js +33 -33
  60. package/dist/feature-libraries/forest-summary/codec.js.map +1 -1
  61. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +2 -2
  62. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  63. package/dist/feature-libraries/forest-summary/forestSummarizer.js +6 -7
  64. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  65. package/dist/feature-libraries/forest-summary/formatCommon.d.ts +6 -4
  66. package/dist/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -1
  67. package/dist/feature-libraries/forest-summary/formatCommon.js +13 -11
  68. package/dist/feature-libraries/forest-summary/formatCommon.js.map +1 -1
  69. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +19 -14
  70. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  71. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js +31 -48
  72. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  73. package/dist/feature-libraries/forest-summary/index.d.ts +1 -1
  74. package/dist/feature-libraries/forest-summary/index.d.ts.map +1 -1
  75. package/dist/feature-libraries/forest-summary/index.js +2 -2
  76. package/dist/feature-libraries/forest-summary/index.js.map +1 -1
  77. package/dist/feature-libraries/index.d.ts +3 -3
  78. package/dist/feature-libraries/index.d.ts.map +1 -1
  79. package/dist/feature-libraries/index.js +4 -5
  80. package/dist/feature-libraries/index.js.map +1 -1
  81. package/dist/feature-libraries/indexing/anchorTreeIndex.d.ts +3 -3
  82. package/dist/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -1
  83. package/dist/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  84. package/dist/feature-libraries/indexing/index.d.ts +1 -1
  85. package/dist/feature-libraries/indexing/index.d.ts.map +1 -1
  86. package/dist/feature-libraries/indexing/index.js.map +1 -1
  87. package/dist/feature-libraries/indexing/types.d.ts +15 -13
  88. package/dist/feature-libraries/indexing/types.d.ts.map +1 -1
  89. package/dist/feature-libraries/indexing/types.js.map +1 -1
  90. package/dist/index.d.ts +3 -3
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +2 -2
  93. package/dist/index.js.map +1 -1
  94. package/dist/legacy.d.ts +4 -1
  95. package/dist/packageVersion.d.ts +1 -1
  96. package/dist/packageVersion.js +1 -1
  97. package/dist/packageVersion.js.map +1 -1
  98. package/dist/shared-tree/independentView.js +2 -2
  99. package/dist/shared-tree/independentView.js.map +1 -1
  100. package/dist/shared-tree/schematizingTreeView.d.ts +5 -0
  101. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  102. package/dist/shared-tree/schematizingTreeView.js +35 -7
  103. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  104. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  105. package/dist/shared-tree/sharedTree.js +7 -7
  106. package/dist/shared-tree/sharedTree.js.map +1 -1
  107. package/dist/shared-tree/tree.js +1 -1
  108. package/dist/shared-tree/tree.js.map +1 -1
  109. package/dist/shared-tree/treeAlpha.d.ts +8 -1
  110. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  111. package/dist/shared-tree/treeAlpha.js +48 -8
  112. package/dist/shared-tree/treeAlpha.js.map +1 -1
  113. package/dist/shared-tree/treeCheckout.d.ts +35 -3
  114. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  115. package/dist/shared-tree/treeCheckout.js +123 -17
  116. package/dist/shared-tree/treeCheckout.js.map +1 -1
  117. package/dist/shared-tree/unhydratedTreeContext.d.ts +20 -0
  118. package/dist/shared-tree/unhydratedTreeContext.d.ts.map +1 -0
  119. package/dist/shared-tree/unhydratedTreeContext.js +56 -0
  120. package/dist/shared-tree/unhydratedTreeContext.js.map +1 -0
  121. package/dist/shared-tree-core/transaction.d.ts +15 -27
  122. package/dist/shared-tree-core/transaction.d.ts.map +1 -1
  123. package/dist/shared-tree-core/transaction.js +7 -11
  124. package/dist/shared-tree-core/transaction.js.map +1 -1
  125. package/dist/simple-tree/api/configuration.d.ts +4 -0
  126. package/dist/simple-tree/api/configuration.d.ts.map +1 -1
  127. package/dist/simple-tree/api/configuration.js.map +1 -1
  128. package/dist/simple-tree/api/identifierIndex.d.ts +2 -2
  129. package/dist/simple-tree/api/identifierIndex.d.ts.map +1 -1
  130. package/dist/simple-tree/api/identifierIndex.js +1 -1
  131. package/dist/simple-tree/api/identifierIndex.js.map +1 -1
  132. package/dist/simple-tree/api/index.d.ts +3 -3
  133. package/dist/simple-tree/api/index.d.ts.map +1 -1
  134. package/dist/simple-tree/api/index.js +2 -2
  135. package/dist/simple-tree/api/index.js.map +1 -1
  136. package/dist/simple-tree/api/schemaFactory.d.ts +3 -2
  137. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  138. package/dist/simple-tree/api/schemaFactory.js +3 -2
  139. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  140. package/dist/simple-tree/api/simpleTreeIndex.d.ts +15 -13
  141. package/dist/simple-tree/api/simpleTreeIndex.d.ts.map +1 -1
  142. package/dist/simple-tree/api/simpleTreeIndex.js +4 -4
  143. package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -1
  144. package/dist/simple-tree/api/snapshotCompatibilityChecker.d.ts +4 -4
  145. package/dist/simple-tree/api/snapshotCompatibilityChecker.js +2 -2
  146. package/dist/simple-tree/api/snapshotCompatibilityChecker.js.map +1 -1
  147. package/dist/simple-tree/api/transactionTypes.d.ts +22 -25
  148. package/dist/simple-tree/api/transactionTypes.d.ts.map +1 -1
  149. package/dist/simple-tree/api/transactionTypes.js.map +1 -1
  150. package/dist/simple-tree/api/tree.d.ts +69 -132
  151. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  152. package/dist/simple-tree/api/tree.js.map +1 -1
  153. package/dist/simple-tree/index.d.ts +1 -1
  154. package/dist/simple-tree/index.d.ts.map +1 -1
  155. package/dist/simple-tree/index.js +2 -2
  156. package/dist/simple-tree/index.js.map +1 -1
  157. package/dist/text/textDomain.d.ts +27 -9
  158. package/dist/text/textDomain.d.ts.map +1 -1
  159. package/dist/text/textDomain.js +43 -7
  160. package/dist/text/textDomain.js.map +1 -1
  161. package/dist/text/textDomainFormatted.d.ts +14 -8
  162. package/dist/text/textDomainFormatted.d.ts.map +1 -1
  163. package/dist/text/textDomainFormatted.js +97 -25
  164. package/dist/text/textDomainFormatted.js.map +1 -1
  165. package/dist/util/rangeMap.d.ts +1 -0
  166. package/dist/util/rangeMap.d.ts.map +1 -1
  167. package/dist/util/rangeMap.js +5 -6
  168. package/dist/util/rangeMap.js.map +1 -1
  169. package/lib/alpha.d.ts +10 -6
  170. package/lib/beta.d.ts +4 -1
  171. package/lib/codec/codec.d.ts +2 -0
  172. package/lib/codec/codec.d.ts.map +1 -1
  173. package/lib/codec/codec.js +4 -3
  174. package/lib/codec/codec.js.map +1 -1
  175. package/lib/codec/index.d.ts +1 -1
  176. package/lib/codec/index.d.ts.map +1 -1
  177. package/lib/codec/index.js +1 -1
  178. package/lib/codec/index.js.map +1 -1
  179. package/lib/codec/versioned/codec.d.ts +13 -1
  180. package/lib/codec/versioned/codec.d.ts.map +1 -1
  181. package/lib/codec/versioned/codec.js +18 -3
  182. package/lib/codec/versioned/codec.js.map +1 -1
  183. package/lib/codec/versioned/format.d.ts +22 -1
  184. package/lib/codec/versioned/format.d.ts.map +1 -1
  185. package/lib/codec/versioned/format.js +15 -2
  186. package/lib/codec/versioned/format.js.map +1 -1
  187. package/lib/codec/versioned/index.d.ts +1 -1
  188. package/lib/codec/versioned/index.d.ts.map +1 -1
  189. package/lib/codec/versioned/index.js +1 -1
  190. package/lib/codec/versioned/index.js.map +1 -1
  191. package/lib/core/index.d.ts +1 -2
  192. package/lib/core/index.d.ts.map +1 -1
  193. package/lib/core/index.js +0 -1
  194. package/lib/core/index.js.map +1 -1
  195. package/lib/core/rebase/index.d.ts +1 -1
  196. package/lib/core/rebase/index.d.ts.map +1 -1
  197. package/lib/core/rebase/index.js.map +1 -1
  198. package/lib/core/rebase/types.d.ts +78 -0
  199. package/lib/core/rebase/types.d.ts.map +1 -1
  200. package/lib/core/rebase/types.js.map +1 -1
  201. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +8 -7
  202. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  203. package/lib/feature-libraries/chunked-forest/codec/codecs.js +25 -45
  204. package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  205. package/lib/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
  206. package/lib/feature-libraries/chunked-forest/codec/format.js +11 -0
  207. package/lib/feature-libraries/chunked-forest/codec/format.js.map +1 -1
  208. package/lib/feature-libraries/chunked-forest/codec/index.d.ts +3 -2
  209. package/lib/feature-libraries/chunked-forest/codec/index.d.ts.map +1 -1
  210. package/lib/feature-libraries/chunked-forest/codec/index.js +2 -2
  211. package/lib/feature-libraries/chunked-forest/codec/index.js.map +1 -1
  212. package/lib/feature-libraries/chunked-forest/index.d.ts +1 -1
  213. package/lib/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  214. package/lib/feature-libraries/chunked-forest/index.js +1 -1
  215. package/lib/feature-libraries/chunked-forest/index.js.map +1 -1
  216. package/lib/feature-libraries/flex-tree/observer.d.ts +17 -0
  217. package/lib/feature-libraries/flex-tree/observer.d.ts.map +1 -1
  218. package/lib/feature-libraries/flex-tree/observer.js.map +1 -1
  219. package/lib/feature-libraries/forest-summary/codec.d.ts +5 -12
  220. package/lib/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  221. package/lib/feature-libraries/forest-summary/codec.js +35 -32
  222. package/lib/feature-libraries/forest-summary/codec.js.map +1 -1
  223. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +2 -2
  224. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  225. package/lib/feature-libraries/forest-summary/forestSummarizer.js +7 -8
  226. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  227. package/lib/feature-libraries/forest-summary/formatCommon.d.ts +6 -4
  228. package/lib/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -1
  229. package/lib/feature-libraries/forest-summary/formatCommon.js +7 -4
  230. package/lib/feature-libraries/forest-summary/formatCommon.js.map +1 -1
  231. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +19 -14
  232. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  233. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js +30 -47
  234. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  235. package/lib/feature-libraries/forest-summary/index.d.ts +1 -1
  236. package/lib/feature-libraries/forest-summary/index.d.ts.map +1 -1
  237. package/lib/feature-libraries/forest-summary/index.js +1 -1
  238. package/lib/feature-libraries/forest-summary/index.js.map +1 -1
  239. package/lib/feature-libraries/index.d.ts +3 -3
  240. package/lib/feature-libraries/index.d.ts.map +1 -1
  241. package/lib/feature-libraries/index.js +2 -2
  242. package/lib/feature-libraries/index.js.map +1 -1
  243. package/lib/feature-libraries/indexing/anchorTreeIndex.d.ts +3 -3
  244. package/lib/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -1
  245. package/lib/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  246. package/lib/feature-libraries/indexing/index.d.ts +1 -1
  247. package/lib/feature-libraries/indexing/index.d.ts.map +1 -1
  248. package/lib/feature-libraries/indexing/index.js.map +1 -1
  249. package/lib/feature-libraries/indexing/types.d.ts +15 -13
  250. package/lib/feature-libraries/indexing/types.d.ts.map +1 -1
  251. package/lib/feature-libraries/indexing/types.js.map +1 -1
  252. package/lib/index.d.ts +3 -3
  253. package/lib/index.d.ts.map +1 -1
  254. package/lib/index.js +1 -1
  255. package/lib/index.js.map +1 -1
  256. package/lib/legacy.d.ts +4 -1
  257. package/lib/packageVersion.d.ts +1 -1
  258. package/lib/packageVersion.js +1 -1
  259. package/lib/packageVersion.js.map +1 -1
  260. package/lib/shared-tree/independentView.js +3 -3
  261. package/lib/shared-tree/independentView.js.map +1 -1
  262. package/lib/shared-tree/schematizingTreeView.d.ts +5 -0
  263. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  264. package/lib/shared-tree/schematizingTreeView.js +33 -6
  265. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  266. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  267. package/lib/shared-tree/sharedTree.js +8 -8
  268. package/lib/shared-tree/sharedTree.js.map +1 -1
  269. package/lib/shared-tree/tree.js +1 -1
  270. package/lib/shared-tree/tree.js.map +1 -1
  271. package/lib/shared-tree/treeAlpha.d.ts +8 -1
  272. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  273. package/lib/shared-tree/treeAlpha.js +49 -9
  274. package/lib/shared-tree/treeAlpha.js.map +1 -1
  275. package/lib/shared-tree/treeCheckout.d.ts +35 -3
  276. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  277. package/lib/shared-tree/treeCheckout.js +124 -18
  278. package/lib/shared-tree/treeCheckout.js.map +1 -1
  279. package/lib/shared-tree/unhydratedTreeContext.d.ts +20 -0
  280. package/lib/shared-tree/unhydratedTreeContext.d.ts.map +1 -0
  281. package/lib/shared-tree/unhydratedTreeContext.js +52 -0
  282. package/lib/shared-tree/unhydratedTreeContext.js.map +1 -0
  283. package/lib/shared-tree-core/transaction.d.ts +15 -27
  284. package/lib/shared-tree-core/transaction.d.ts.map +1 -1
  285. package/lib/shared-tree-core/transaction.js +7 -11
  286. package/lib/shared-tree-core/transaction.js.map +1 -1
  287. package/lib/simple-tree/api/configuration.d.ts +4 -0
  288. package/lib/simple-tree/api/configuration.d.ts.map +1 -1
  289. package/lib/simple-tree/api/configuration.js.map +1 -1
  290. package/lib/simple-tree/api/identifierIndex.d.ts +2 -2
  291. package/lib/simple-tree/api/identifierIndex.d.ts.map +1 -1
  292. package/lib/simple-tree/api/identifierIndex.js +2 -2
  293. package/lib/simple-tree/api/identifierIndex.js.map +1 -1
  294. package/lib/simple-tree/api/index.d.ts +3 -3
  295. package/lib/simple-tree/api/index.d.ts.map +1 -1
  296. package/lib/simple-tree/api/index.js +1 -1
  297. package/lib/simple-tree/api/index.js.map +1 -1
  298. package/lib/simple-tree/api/schemaFactory.d.ts +3 -2
  299. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  300. package/lib/simple-tree/api/schemaFactory.js +3 -2
  301. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  302. package/lib/simple-tree/api/simpleTreeIndex.d.ts +15 -13
  303. package/lib/simple-tree/api/simpleTreeIndex.d.ts.map +1 -1
  304. package/lib/simple-tree/api/simpleTreeIndex.js +2 -2
  305. package/lib/simple-tree/api/simpleTreeIndex.js.map +1 -1
  306. package/lib/simple-tree/api/snapshotCompatibilityChecker.d.ts +4 -4
  307. package/lib/simple-tree/api/snapshotCompatibilityChecker.js +2 -2
  308. package/lib/simple-tree/api/snapshotCompatibilityChecker.js.map +1 -1
  309. package/lib/simple-tree/api/transactionTypes.d.ts +22 -25
  310. package/lib/simple-tree/api/transactionTypes.d.ts.map +1 -1
  311. package/lib/simple-tree/api/transactionTypes.js.map +1 -1
  312. package/lib/simple-tree/api/tree.d.ts +69 -132
  313. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  314. package/lib/simple-tree/api/tree.js.map +1 -1
  315. package/lib/simple-tree/index.d.ts +1 -1
  316. package/lib/simple-tree/index.d.ts.map +1 -1
  317. package/lib/simple-tree/index.js +1 -1
  318. package/lib/simple-tree/index.js.map +1 -1
  319. package/lib/text/textDomain.d.ts +27 -9
  320. package/lib/text/textDomain.d.ts.map +1 -1
  321. package/lib/text/textDomain.js +45 -9
  322. package/lib/text/textDomain.js.map +1 -1
  323. package/lib/text/textDomainFormatted.d.ts +14 -8
  324. package/lib/text/textDomainFormatted.d.ts.map +1 -1
  325. package/lib/text/textDomainFormatted.js +80 -8
  326. package/lib/text/textDomainFormatted.js.map +1 -1
  327. package/lib/util/rangeMap.d.ts +1 -0
  328. package/lib/util/rangeMap.d.ts.map +1 -1
  329. package/lib/util/rangeMap.js +5 -6
  330. package/lib/util/rangeMap.js.map +1 -1
  331. package/package.json +24 -24
  332. package/src/codec/codec.ts +5 -4
  333. package/src/codec/index.ts +1 -0
  334. package/src/codec/versioned/codec.ts +32 -6
  335. package/src/codec/versioned/format.ts +17 -2
  336. package/src/codec/versioned/index.ts +1 -1
  337. package/src/core/index.ts +2 -6
  338. package/src/core/rebase/index.ts +2 -0
  339. package/src/core/rebase/types.ts +80 -0
  340. package/src/feature-libraries/chunked-forest/codec/codecs.ts +59 -78
  341. package/src/feature-libraries/chunked-forest/codec/format.ts +11 -0
  342. package/src/feature-libraries/chunked-forest/codec/index.ts +3 -3
  343. package/src/feature-libraries/chunked-forest/index.ts +2 -3
  344. package/src/feature-libraries/flex-tree/observer.ts +17 -0
  345. package/src/feature-libraries/forest-summary/codec.ts +46 -56
  346. package/src/feature-libraries/forest-summary/forestSummarizer.ts +5 -14
  347. package/src/feature-libraries/forest-summary/formatCommon.ts +14 -19
  348. package/src/feature-libraries/forest-summary/incrementalSummaryBuilder.ts +44 -74
  349. package/src/feature-libraries/forest-summary/index.ts +1 -1
  350. package/src/feature-libraries/index.ts +2 -4
  351. package/src/feature-libraries/indexing/anchorTreeIndex.ts +3 -5
  352. package/src/feature-libraries/indexing/index.ts +1 -1
  353. package/src/feature-libraries/indexing/types.ts +15 -17
  354. package/src/index.ts +6 -3
  355. package/src/packageVersion.ts +1 -1
  356. package/src/shared-tree/independentView.ts +3 -3
  357. package/src/shared-tree/schematizingTreeView.ts +43 -10
  358. package/src/shared-tree/sharedTree.ts +8 -10
  359. package/src/shared-tree/tree.ts +1 -1
  360. package/src/shared-tree/treeAlpha.ts +64 -11
  361. package/src/shared-tree/treeCheckout.ts +142 -21
  362. package/src/shared-tree/unhydratedTreeContext.ts +87 -0
  363. package/src/shared-tree-core/transaction.ts +19 -39
  364. package/src/simple-tree/api/configuration.ts +4 -0
  365. package/src/simple-tree/api/identifierIndex.ts +4 -4
  366. package/src/simple-tree/api/index.ts +3 -1
  367. package/src/simple-tree/api/schemaFactory.ts +3 -2
  368. package/src/simple-tree/api/simpleTreeIndex.ts +26 -20
  369. package/src/simple-tree/api/snapshotCompatibilityChecker.ts +4 -4
  370. package/src/simple-tree/api/transactionTypes.ts +24 -26
  371. package/src/simple-tree/api/tree.ts +92 -131
  372. package/src/simple-tree/index.ts +4 -2
  373. package/src/text/textDomain.ts +91 -12
  374. package/src/text/textDomainFormatted.ts +127 -15
  375. package/src/util/rangeMap.ts +5 -11
  376. package/dist/core/schema-view/index.d.ts +0 -6
  377. package/dist/core/schema-view/index.d.ts.map +0 -1
  378. package/dist/core/schema-view/index.js +0 -10
  379. package/dist/core/schema-view/index.js.map +0 -1
  380. package/dist/core/schema-view/view.d.ts +0 -31
  381. package/dist/core/schema-view/view.d.ts.map +0 -1
  382. package/dist/core/schema-view/view.js +0 -18
  383. package/dist/core/schema-view/view.js.map +0 -1
  384. package/dist/feature-libraries/forest-summary/formatV1.d.ts +0 -12
  385. package/dist/feature-libraries/forest-summary/formatV1.d.ts.map +0 -1
  386. package/dist/feature-libraries/forest-summary/formatV1.js +0 -10
  387. package/dist/feature-libraries/forest-summary/formatV1.js.map +0 -1
  388. package/dist/feature-libraries/forest-summary/formatV2.d.ts +0 -12
  389. package/dist/feature-libraries/forest-summary/formatV2.d.ts.map +0 -1
  390. package/dist/feature-libraries/forest-summary/formatV2.js +0 -10
  391. package/dist/feature-libraries/forest-summary/formatV2.js.map +0 -1
  392. package/lib/core/schema-view/index.d.ts +0 -6
  393. package/lib/core/schema-view/index.d.ts.map +0 -1
  394. package/lib/core/schema-view/index.js +0 -6
  395. package/lib/core/schema-view/index.js.map +0 -1
  396. package/lib/core/schema-view/view.d.ts +0 -31
  397. package/lib/core/schema-view/view.d.ts.map +0 -1
  398. package/lib/core/schema-view/view.js +0 -14
  399. package/lib/core/schema-view/view.js.map +0 -1
  400. package/lib/feature-libraries/forest-summary/formatV1.d.ts +0 -12
  401. package/lib/feature-libraries/forest-summary/formatV1.d.ts.map +0 -1
  402. package/lib/feature-libraries/forest-summary/formatV1.js +0 -7
  403. package/lib/feature-libraries/forest-summary/formatV1.js.map +0 -1
  404. package/lib/feature-libraries/forest-summary/formatV2.d.ts +0 -12
  405. package/lib/feature-libraries/forest-summary/formatV2.d.ts.map +0 -1
  406. package/lib/feature-libraries/forest-summary/formatV2.js +0 -7
  407. package/lib/feature-libraries/forest-summary/formatV2.js.map +0 -1
  408. package/src/core/schema-view/README.md +0 -9
  409. package/src/core/schema-view/index.ts +0 -10
  410. package/src/core/schema-view/view.ts +0 -38
  411. package/src/feature-libraries/forest-summary/formatV1.ts +0 -11
  412. package/src/feature-libraries/forest-summary/formatV2.ts +0 -11
@@ -3,6 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import type { TreeNode, WithType } from "../simple-tree/index.js";
6
+ import type { NodeKind, TreeNodeSchema } from "../simple-tree/index.js";
6
7
  /**
7
8
  * Interpret a string as an iterable of characters.
8
9
  * @remarks
@@ -71,12 +72,12 @@ export declare function charactersFromString(value: string): Iterable<string>;
71
72
  *
72
73
  * Part of that work will be establishing and documenting those patterns so other components with complex encodings can follow them,
73
74
  * in addition to implementing them for text.
74
- * @internal
75
+ * @alpha
75
76
  */
76
77
  export declare namespace TextAsTree {
77
78
  /**
78
79
  * Statics for text nodes.
79
- * @internal
80
+ * @alpha
80
81
  */
81
82
  interface Statics {
82
83
  /**
@@ -100,7 +101,7 @@ export declare namespace TextAsTree {
100
101
  *
101
102
  * @see {@link TextAsTree.Statics.fromString} for construction.
102
103
  * @see {@link TextAsTree.(Tree:type)} for schema.
103
- * @internal
104
+ * @alpha
104
105
  */
105
106
  interface Members {
106
107
  /**
@@ -109,6 +110,18 @@ export declare namespace TextAsTree {
109
110
  * This iterator matches the behavior of {@link (TreeArrayNode:interface)} with respect to edits during iteration.
110
111
  */
111
112
  characters(): Iterable<string>;
113
+ /**
114
+ * Optimized way to get a copy of the {@link TextAsTree.Members.characters} in an array.
115
+ */
116
+ charactersCopy(): string[];
117
+ /**
118
+ * Gets the number of characters currently in the text.
119
+ * @remarks
120
+ * The length of {@link TextAsTree.Members.characters}.
121
+ * This is not the length of the string returned by {@link TextAsTree.Members.fullString},
122
+ * as that string may contain characters which are made up of multiple UTF-16 code units.
123
+ */
124
+ characterCount(): number;
112
125
  /**
113
126
  * Copy the content of this node into a string.
114
127
  */
@@ -131,16 +144,21 @@ export declare namespace TextAsTree {
131
144
  * Remove a range from a string based on character index.
132
145
  * See {@link (TreeArrayNode:interface).removeRange} for more details on the behavior.
133
146
  */
134
- removeRange(index: number, length: number): void;
147
+ removeRange(startIndex: number | undefined, endIndex: number | undefined): void;
135
148
  }
136
149
  /**
137
- * Schema for a text node.
150
+ * Schema for a {@link TextAsTree.(Tree:variable)} node.
151
+ * @remarks
152
+ * See {@link TextAsTree.Statics} for static APIs on this schema, including construction.
153
+ * @alpha
154
+ */
155
+ const Tree: Statics & TreeNodeSchema<"com.fluidframework.text.Text", NodeKind, Members & TreeNode & WithType<"com.fluidframework.text.Text", NodeKind, unknown>, never, false>;
156
+ /**
157
+ * Node for the {@link TextAsTree.(Tree:type)} schema exposing the {@link TextAsTree.Members} API.
138
158
  * @remarks
139
- * See {@link TextAsTree.Members} for the API.
140
- * See {@link TextAsTree.Statics} for static APIs on this Schema, including construction.
141
- * @internal
159
+ * Create using {@link TextAsTree.Statics.fromString}.
160
+ * @alpha
142
161
  */
143
- const Tree: Statics & import("../simple-tree/index.js").TreeNodeSchema<"com.fluidframework.text.Text", import("../simple-tree/index.js").NodeKind, Members & TreeNode & WithType<"com.fluidframework.text.Text", import("../simple-tree/index.js").NodeKind, unknown>, never, false>;
144
162
  type Tree = Members & TreeNode & WithType<"com.fluidframework.text.Text">;
145
163
  }
146
164
  //# sourceMappingURL=textDomain.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"textDomain.d.ts","sourceRoot":"","sources":["../../src/text/textDomain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAkClE;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAKpE;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,yBAAiB,UAAU,CAAC;IAC3B;;;OAGG;IACH,UAA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AAM,CAAC,CAAC;QAE/B;;WAEG;QACH,cAAc,IAAI,MAAM,EAAE,CAAC;QAE3B;;;;;;WAMG;QACH,cAAc,IAAI,MAAM,CAAC;QAEzB;;WAEG;QACH,UAAU,IAAI,MAAM,CAAC;QAErB;;;;;;;;;;;;WAYG;QACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;QAE5D;;;WAGG;QACH,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;KAChF;IAED;;;;;OAKG;IACI,MAAM,IAAI,oKAAmD,CAAC;IAErE;;;;;OAKG;IACH,KAAY,IAAI,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC,8BAA8B,CAAC,CAAC;CACjF"}
@@ -2,8 +2,9 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { EmptyKey } from "../core/index.js";
6
- import { eraseSchemaDetails, SchemaFactory, SchemaFactoryAlpha, TreeArrayNode, } from "../simple-tree/index.js";
5
+ import { compareArrays, debugAssert } from "@fluidframework/core-utils/internal";
6
+ import { EmptyKey, mapCursorField } from "../core/index.js";
7
+ import { eraseSchemaDetails, getInnerNode, SchemaFactory, SchemaFactoryAlpha, TreeArrayNode, } from "../simple-tree/index.js";
7
8
  const sf = new SchemaFactoryAlpha("com.fluidframework.text");
8
9
  class TextNode extends sf.object("Text", {
9
10
  content: SchemaFactory.required([() => StringArray], { key: EmptyKey }),
@@ -11,15 +12,38 @@ class TextNode extends sf.object("Text", {
11
12
  insertAt(index, additionalCharacters) {
12
13
  this.content.insertAt(index, TreeArrayNode.spread(charactersFromString(additionalCharacters)));
13
14
  }
14
- removeRange(index, length) {
15
- this.content.removeRange(index, length);
15
+ removeRange(index, end) {
16
+ this.content.removeRange(index, end);
16
17
  }
17
18
  characters() {
18
19
  return this.content[Symbol.iterator]();
19
20
  }
21
+ characterCount() {
22
+ return this.content.length;
23
+ }
24
+ charactersCopy() {
25
+ const result = this.content.charactersCopy();
26
+ debugAssert(() => compareArrays(result, this.charactersCopy_reference()) ||
27
+ "invalid charactersCopy optimizations");
28
+ return result;
29
+ }
20
30
  fullString() {
31
+ const result = this.content.fullString();
32
+ debugAssert(() => result === this.fullString_reference() || "invalid fullString optimizations");
33
+ return result;
34
+ }
35
+ /**
36
+ * Unoptimized trivially correct implementation of fullString.
37
+ */
38
+ fullString_reference() {
21
39
  return this.content.join("");
22
40
  }
41
+ /**
42
+ * Unoptimized trivially correct implementation of charactersCopy.
43
+ */
44
+ charactersCopy_reference() {
45
+ return [...this.content];
46
+ }
23
47
  static fromString(value) {
24
48
  // Constructing an ArrayNode from an iterator is supported, so creating an array from the iterable of characters seems like its not necessary here,
25
49
  // 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.
@@ -41,6 +65,19 @@ export function charactersFromString(value) {
41
65
  return value;
42
66
  }
43
67
  class StringArray extends sf.array("StringArray", SchemaFactory.string) {
68
+ withBorrowedSequenceCursor(f) {
69
+ const cursor = getInnerNode(this).borrowCursor();
70
+ cursor.enterField(EmptyKey);
71
+ const result = f(cursor);
72
+ cursor.exitField();
73
+ return result;
74
+ }
75
+ charactersCopy() {
76
+ return this.withBorrowedSequenceCursor((cursor) => mapCursorField(cursor, () => cursor.value));
77
+ }
78
+ fullString() {
79
+ return this.charactersCopy().join("");
80
+ }
44
81
  }
45
82
  /**
46
83
  * A collection of text related types, schema and utilities for working with text beyond the basic {@link SchemaStatics.string}.
@@ -102,16 +139,15 @@ class StringArray extends sf.array("StringArray", SchemaFactory.string) {
102
139
  *
103
140
  * Part of that work will be establishing and documenting those patterns so other components with complex encodings can follow them,
104
141
  * in addition to implementing them for text.
105
- * @internal
142
+ * @alpha
106
143
  */
107
144
  export var TextAsTree;
108
145
  (function (TextAsTree) {
109
146
  /**
110
- * Schema for a text node.
147
+ * Schema for a {@link TextAsTree.(Tree:variable)} node.
111
148
  * @remarks
112
- * See {@link TextAsTree.Members} for the API.
113
- * See {@link TextAsTree.Statics} for static APIs on this Schema, including construction.
114
- * @internal
149
+ * See {@link TextAsTree.Statics} for static APIs on this schema, including construction.
150
+ * @alpha
115
151
  */
116
152
  TextAsTree.Tree = eraseSchemaDetails()(TextNode);
117
153
  })(TextAsTree || (TextAsTree = {}));
@@ -1 +1 @@
1
- {"version":3,"file":"textDomain.js","sourceRoot":"","sources":["../../src/text/textDomain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EACN,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,aAAa,GACb,MAAM,yBAAyB,CAAC;AAGjC,MAAM,EAAE,GAAG,IAAI,kBAAkB,CAAC,yBAAyB,CAAC,CAAC;AAE7D,MAAM,QACL,SAAQ,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE;IACzB,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;CACvE,CAAC;IAGK,QAAQ,CAAC,KAAa,EAAE,oBAA4B;QAC1D,IAAI,CAAC,OAAO,CAAC,QAAQ,CACpB,KAAK,EACL,aAAa,CAAC,MAAM,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,CAAC,CAChE,CAAC;IACH,CAAC;IACM,WAAW,CAAC,KAAa,EAAE,MAAc;QAC/C,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACzC,CAAC;IACM,UAAU;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IACxC,CAAC;IACM,UAAU;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;IAEM,MAAM,CAAC,UAAU,CAAC,KAAa;QACrC,mJAAmJ;QACnJ,qKAAqK;QACrK,0EAA0E;QAC1E,OAAO,IAAI,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;IACpE,CAAC;CACD;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa;IACjD,0GAA0G;IAC1G,iKAAiK;IACjK,0CAA0C;IAC1C,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,WAAY,SAAQ,EAAE,CAAC,KAAK,CAAC,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC;CAAG;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAM,KAAW,UAAU,CA0E1B;AA1ED,WAAiB,UAAU;IAiE1B;;;;;;OAMG;IACU,eAAI,GAAG,kBAAkB,EAAoB,CAAC,QAAQ,CAAC,CAAC;AAEtE,CAAC,EA1EgB,UAAU,KAAV,UAAU,QA0E1B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EmptyKey } from \"../core/index.js\";\nimport {\n\teraseSchemaDetails,\n\tSchemaFactory,\n\tSchemaFactoryAlpha,\n\tTreeArrayNode,\n} from \"../simple-tree/index.js\";\nimport type { TreeNode, WithType } from \"../simple-tree/index.js\";\n\nconst sf = new SchemaFactoryAlpha(\"com.fluidframework.text\");\n\nclass TextNode\n\textends sf.object(\"Text\", {\n\t\tcontent: SchemaFactory.required([() => StringArray], { key: EmptyKey }),\n\t})\n\timplements TextAsTree.Members\n{\n\tpublic insertAt(index: number, additionalCharacters: string): void {\n\t\tthis.content.insertAt(\n\t\t\tindex,\n\t\t\tTreeArrayNode.spread(charactersFromString(additionalCharacters)),\n\t\t);\n\t}\n\tpublic removeRange(index: number, length: number): void {\n\t\tthis.content.removeRange(index, length);\n\t}\n\tpublic characters(): Iterable<string> {\n\t\treturn this.content[Symbol.iterator]();\n\t}\n\tpublic fullString(): string {\n\t\treturn this.content.join(\"\");\n\t}\n\n\tpublic static fromString(value: string): TextNode {\n\t\t// Constructing an ArrayNode from an iterator is supported, so creating an array from the iterable of characters seems like its not necessary here,\n\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// Thus the array construction here is necessary to avoid a runtime error.\n\t\treturn new TextNode({ content: [...charactersFromString(value)] });\n\t}\n}\n\n/**\n * Interpret a string as an iterable of characters.\n * @remarks\n * This mostly exists to clearly document where the code is interpreting a string as characters,\n * and provide a centralized place where validation could be added in the future if desired.\n * Additionally using this function consistently will make any refactors to support alternative character boundaries easier.\n */\nexport function charactersFromString(value: string): Iterable<string> {\n\t// Uses the string as an iterable of characters, so utf-16 surrogate pairs get grouped together correctly.\n\t// Might be nice to call isWellFormed or toWellFormed here (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toWellFormed)\n\t// But those are not widely supported yet.\n\treturn value;\n}\n\nclass StringArray extends sf.array(\"StringArray\", SchemaFactory.string) {}\n\n/**\n * A collection of text related types, schema and utilities for working with text beyond the basic {@link SchemaStatics.string}.\n * @privateRemarks\n * Currently this API only supports a really minimal feature set, and has no support for more advanced features like:\n * - Alternative character boundaries (e.g. grapheme clusters, paragraphs, tokens, etc.).\n * We may want to provide either ways to create strings with application controlled character boundaries since there is not a clear single answer on how to break a string into atomic units.\n * - Character attributes (e.g. bold, italic, etc):\n * Properties that can be set on any character independently with optimizations for runs of characters with the same attributes.\n * - Inline objects (e.g. images, embedded components, etc):\n * These would be logically part of the text, generalizing characters to allow inline objects in character ranges.\n * How character attributes apply to inline objects is an open question\n * (there could be a kind of object which gets them, and one that doesn't for example).\n * - Annotations (e.g. comments, suggestions, etc).\n * Objects which can be associated with a range of characters but are not logically part of the text.\n * These would need to have the logical range they apply to updated by edits.\n * How edits which overlap annotation boundaries are handled may require hints from the application for optimal behavior (mainly inserts at the boundaries).\n * These get a lifetime tied to the text node, not any of the characters the annotation covers,\n * however it might be desirable to have a way for a range edit to (optionally) also remove any annotations which are fully covered by the edit.\n * Annotations over an empty range should also be supported and behave well (for example not end up with characters inside the range after edits unless specifically structured so that makes sense).\n * - Anchors (e.g. positions in the text which survive edits).\n * These would be useful for ephemeral state like cursor positions, but should match the behaviors with respect to edits exhibited by the ends of Annotations.\n *\n * How these features will be represented in the schema and API should be determined before any of this is stabilized so the simple more limited version can neatly fit into the larger design.\n *\n * There are various optimizations that should be implemented to make this performant for large texts and common usage patterns.\n * These include:\n * - Optimized persisted format.\n * - Optimized in memory representation (via chunked forest).\n * - Optimized edit persisted format (e.g. combining adjacent inserts/removes into single operations as well as support for efficient attribute editing of ranges).\n * - Optimized edit application (e.g. applying the above noted optimizable edit cases efficiently).\n * This applies to the revision manager, the forest, and any flex or simple-tree nodes and user events.\n *\n * There are also additional features required for ensuring the invariants of collaborative text editing are maintained through concurrent edits.\n * The main challenges here are related to annotations, but some policies for what to do in the case of corrupt/invalid text should also be included.\n * There are quite a few ways invariants could break, including:\n * - concurrent edits without proper constraints.\n * - collaboration with clients using compatible schema with different constraints.\n * - opening documents which contain invalid content (e.g. from older versions of the software, manual edits to the persisted format, or simply an existing corrupt case which was saved).\n * - a user inserting/constructing/importing invalid content.\n *\n * These cases could break constraints causing issues like invalided characters (empty, a utf-16 surrogate pair alone, etc) or\n * annotations which reference out of bounds character ranges.\n * Addressing these issues mainly falls into these categories:\n * - Handling of invalid content on import/construction of unhydrated nodes and/or insertion into the document (hydration).\n * - Handling of invalid content which is already part of the document (live). This should ideally include both detection and repair.\n * - Constraints on edits to prevent invalid content from being created by merges.\n * - Optimization of the constraints to reduce cases in which edits are rejected due to conflicts.\n *\n * Note that these cases of invariant violations are the same cases any component should handle, so ideally there would be a general framework or pattern for documenting and enforcing such constraints.\n *\n * Another area for future work is improved APIs for import, export and non-schema-aware use. This includes a variety of cases, including but not limited to:\n * - Insertable content format (taken by the constructor and import APIs).\n * - Customizable export formats (like a way to make exportVerbose and exportConcise flatten the text nodes to strings automatically).\n * - Customizable toJson behavior (e.g. flattening to strings, possibly via tools or patterns for custom tree stringifier).\n * - Ensure JS object APIs (like iteration, own vs inherited properties, etc) provide a good and consistent experience with respect to other nodes.\n * - Support in generateSchemaFromSimpleSchema for recognizing text nodes and generating the appropriate schema.\n * - Ensure above features work well enough to support important scenarios like AI assisted editing and document indexing for search.\n *\n * Part of that work will be establishing and documenting those patterns so other components with complex encodings can follow them,\n * in addition to implementing them for text.\n * @internal\n */\nexport namespace TextAsTree {\n\t/**\n\t * Statics for text nodes.\n\t * @internal\n\t */\n\texport interface Statics {\n\t\t/**\n\t\t * Construct a {@link TextAsTree.(Tree:type)} from a string, where each character (as defined by iterating over the string) becomes a single character in the text node.\n\t\t * This combines pairs of utf-16 surrogate code units into single characters as appropriate.\n\t\t */\n\t\tfromString(value: string): Tree;\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 TextAsTree.Statics.fromString} for construction.\n\t * @see {@link TextAsTree.(Tree:type)} for schema.\n\t * @internal\n\t */\n\texport interface Members {\n\t\t/**\n\t\t * Gets an iterable over 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\tcharacters(): Iterable<string>;\n\n\t\t/**\n\t\t * Copy the content of this node into a string.\n\t\t */\n\t\tfullString(): string;\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 TextAsTree.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\tinsertAt(index: number, additionalCharacters: string): void;\n\n\t\t/**\n\t\t * Remove a range from a string based on character index.\n\t\t * See {@link (TreeArrayNode:interface).removeRange} for more details on the behavior.\n\t\t */\n\t\tremoveRange(index: number, length: number): void;\n\t}\n\n\t/**\n\t * Schema for a text node.\n\t * @remarks\n\t * See {@link TextAsTree.Members} for the API.\n\t * See {@link TextAsTree.Statics} for static APIs on this Schema, including construction.\n\t * @internal\n\t */\n\texport const Tree = eraseSchemaDetails<Members, Statics>()(TextNode);\n\texport type Tree = Members & TreeNode & WithType<\"com.fluidframework.text.Text\">;\n}\n"]}
1
+ {"version":3,"file":"textDomain.js","sourceRoot":"","sources":["../../src/text/textDomain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAEjF,OAAO,EAAE,QAAQ,EAAE,cAAc,EAA+B,MAAM,kBAAkB,CAAC;AACzF,OAAO,EACN,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,aAAa,GACb,MAAM,yBAAyB,CAAC;AAQjC,MAAM,EAAE,GAAG,IAAI,kBAAkB,CAAC,yBAAyB,CAAC,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kBAAkB,EAAoB,CAAC,QAAQ,CAAC,CAAC;AAStE,CAAC,EA9FgB,UAAU,KAAV,UAAU,QA8F1B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { compareArrays, debugAssert } from \"@fluidframework/core-utils/internal\";\n\nimport { EmptyKey, mapCursorField, type ITreeCursorSynchronous } from \"../core/index.js\";\nimport {\n\teraseSchemaDetails,\n\tgetInnerNode,\n\tSchemaFactory,\n\tSchemaFactoryAlpha,\n\tTreeArrayNode,\n} from \"../simple-tree/index.js\";\n// eslint-disable-next-line import-x/no-duplicates\nimport type { TreeNode, WithType } from \"../simple-tree/index.js\";\n// Add some unused imports which show up in the generated d.ts file.\n// This prevents them from getting inline imports generated, cleaning up the d.ts file and API reports.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-imports, import-x/no-duplicates\nimport type { NodeKind, TreeNodeSchema } from \"../simple-tree/index.js\";\n\nconst sf = new SchemaFactoryAlpha(\"com.fluidframework.text\");\n\nclass TextNode\n\textends sf.object(\"Text\", {\n\t\tcontent: SchemaFactory.required([() => StringArray], { key: EmptyKey }),\n\t})\n\timplements TextAsTree.Members\n{\n\tpublic insertAt(index: number, additionalCharacters: string): void {\n\t\tthis.content.insertAt(\n\t\t\tindex,\n\t\t\tTreeArrayNode.spread(charactersFromString(additionalCharacters)),\n\t\t);\n\t}\n\tpublic removeRange(index: number | undefined, end: number | undefined): void {\n\t\tthis.content.removeRange(index, end);\n\t}\n\tpublic characters(): Iterable<string> {\n\t\treturn this.content[Symbol.iterator]();\n\t}\n\n\tpublic characterCount(): number {\n\t\treturn this.content.length;\n\t}\n\n\tpublic charactersCopy(): string[] {\n\t\tconst result = this.content.charactersCopy();\n\t\tdebugAssert(\n\t\t\t() =>\n\t\t\t\tcompareArrays(result, this.charactersCopy_reference()) ||\n\t\t\t\t\"invalid charactersCopy optimizations\",\n\t\t);\n\t\treturn result;\n\t}\n\n\tpublic fullString(): string {\n\t\tconst result = this.content.fullString();\n\t\tdebugAssert(\n\t\t\t() => result === this.fullString_reference() || \"invalid fullString optimizations\",\n\t\t);\n\t\treturn result;\n\t}\n\n\t/**\n\t * Unoptimized trivially correct implementation of fullString.\n\t */\n\tpublic fullString_reference(): string {\n\t\treturn this.content.join(\"\");\n\t}\n\n\t/**\n\t * Unoptimized trivially correct implementation of charactersCopy.\n\t */\n\tpublic charactersCopy_reference(): string[] {\n\t\treturn [...this.content];\n\t}\n\n\tpublic static fromString(value: string): TextNode {\n\t\t// Constructing an ArrayNode from an iterator is supported, so creating an array from the iterable of characters seems like its not necessary here,\n\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// Thus the array construction here is necessary to avoid a runtime error.\n\t\treturn new TextNode({ content: [...charactersFromString(value)] });\n\t}\n}\n\n/**\n * Interpret a string as an iterable of characters.\n * @remarks\n * This mostly exists to clearly document where the code is interpreting a string as characters,\n * and provide a centralized place where validation could be added in the future if desired.\n * Additionally using this function consistently will make any refactors to support alternative character boundaries easier.\n */\nexport function charactersFromString(value: string): Iterable<string> {\n\t// Uses the string as an iterable of characters, so utf-16 surrogate pairs get grouped together correctly.\n\t// Might be nice to call isWellFormed or toWellFormed here (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toWellFormed)\n\t// But those are not widely supported yet.\n\treturn value;\n}\n\nclass StringArray extends sf.array(\"StringArray\", SchemaFactory.string) {\n\tpublic withBorrowedSequenceCursor<T>(f: (cursor: ITreeCursorSynchronous) => T): T {\n\t\tconst cursor = getInnerNode(this).borrowCursor();\n\t\tcursor.enterField(EmptyKey);\n\t\tconst result = f(cursor);\n\t\tcursor.exitField();\n\t\treturn result;\n\t}\n\n\tpublic charactersCopy(): string[] {\n\t\treturn this.withBorrowedSequenceCursor((cursor) =>\n\t\t\tmapCursorField(cursor, () => cursor.value as string),\n\t\t);\n\t}\n\n\tpublic fullString(): string {\n\t\treturn this.charactersCopy().join(\"\");\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 * @privateRemarks\n * Currently this API only supports a really minimal feature set, and has no support for more advanced features like:\n * - Alternative character boundaries (e.g. grapheme clusters, paragraphs, tokens, etc.).\n * We may want to provide either ways to create strings with application controlled character boundaries since there is not a clear single answer on how to break a string into atomic units.\n * - Character attributes (e.g. bold, italic, etc):\n * Properties that can be set on any character independently with optimizations for runs of characters with the same attributes.\n * - Inline objects (e.g. images, embedded components, etc):\n * These would be logically part of the text, generalizing characters to allow inline objects in character ranges.\n * How character attributes apply to inline objects is an open question\n * (there could be a kind of object which gets them, and one that doesn't for example).\n * - Annotations (e.g. comments, suggestions, etc).\n * Objects which can be associated with a range of characters but are not logically part of the text.\n * These would need to have the logical range they apply to updated by edits.\n * How edits which overlap annotation boundaries are handled may require hints from the application for optimal behavior (mainly inserts at the boundaries).\n * These get a lifetime tied to the text node, not any of the characters the annotation covers,\n * however it might be desirable to have a way for a range edit to (optionally) also remove any annotations which are fully covered by the edit.\n * Annotations over an empty range should also be supported and behave well (for example not end up with characters inside the range after edits unless specifically structured so that makes sense).\n * - Anchors (e.g. positions in the text which survive edits).\n * These would be useful for ephemeral state like cursor positions, but should match the behaviors with respect to edits exhibited by the ends of Annotations.\n *\n * How these features will be represented in the schema and API should be determined before any of this is stabilized so the simple more limited version can neatly fit into the larger design.\n *\n * There are various optimizations that should be implemented to make this performant for large texts and common usage patterns.\n * These include:\n * - Optimized persisted format.\n * - Optimized in memory representation (via chunked forest).\n * - Optimized edit persisted format (e.g. combining adjacent inserts/removes into single operations as well as support for efficient attribute editing of ranges).\n * - Optimized edit application (e.g. applying the above noted optimizable edit cases efficiently).\n * This applies to the revision manager, the forest, and any flex or simple-tree nodes and user events.\n *\n * There are also additional features required for ensuring the invariants of collaborative text editing are maintained through concurrent edits.\n * The main challenges here are related to annotations, but some policies for what to do in the case of corrupt/invalid text should also be included.\n * There are quite a few ways invariants could break, including:\n * - concurrent edits without proper constraints.\n * - collaboration with clients using compatible schema with different constraints.\n * - opening documents which contain invalid content (e.g. from older versions of the software, manual edits to the persisted format, or simply an existing corrupt case which was saved).\n * - a user inserting/constructing/importing invalid content.\n *\n * These cases could break constraints causing issues like invalided characters (empty, a utf-16 surrogate pair alone, etc) or\n * annotations which reference out of bounds character ranges.\n * Addressing these issues mainly falls into these categories:\n * - Handling of invalid content on import/construction of unhydrated nodes and/or insertion into the document (hydration).\n * - Handling of invalid content which is already part of the document (live). This should ideally include both detection and repair.\n * - Constraints on edits to prevent invalid content from being created by merges.\n * - Optimization of the constraints to reduce cases in which edits are rejected due to conflicts.\n *\n * Note that these cases of invariant violations are the same cases any component should handle, so ideally there would be a general framework or pattern for documenting and enforcing such constraints.\n *\n * Another area for future work is improved APIs for import, export and non-schema-aware use. This includes a variety of cases, including but not limited to:\n * - Insertable content format (taken by the constructor and import APIs).\n * - Customizable export formats (like a way to make exportVerbose and exportConcise flatten the text nodes to strings automatically).\n * - Customizable toJson behavior (e.g. flattening to strings, possibly via tools or patterns for custom tree stringifier).\n * - Ensure JS object APIs (like iteration, own vs inherited properties, etc) provide a good and consistent experience with respect to other nodes.\n * - Support in generateSchemaFromSimpleSchema for recognizing text nodes and generating the appropriate schema.\n * - Ensure above features work well enough to support important scenarios like AI assisted editing and document indexing for search.\n *\n * Part of that work will be establishing and documenting those patterns so other components with complex encodings can follow them,\n * in addition to implementing them for text.\n * @alpha\n */\nexport namespace TextAsTree {\n\t/**\n\t * Statics for text nodes.\n\t * @alpha\n\t */\n\texport interface Statics {\n\t\t/**\n\t\t * Construct a {@link TextAsTree.(Tree:type)} from a string, where each character (as defined by iterating over the string) becomes a single character in the text node.\n\t\t * This combines pairs of utf-16 surrogate code units into single characters as appropriate.\n\t\t */\n\t\tfromString(value: string): Tree;\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 TextAsTree.Statics.fromString} for construction.\n\t * @see {@link TextAsTree.(Tree:type)} for schema.\n\t * @alpha\n\t */\n\texport interface Members {\n\t\t/**\n\t\t * Gets an iterable over 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\tcharacters(): Iterable<string>;\n\n\t\t/**\n\t\t * Optimized way to get a copy of the {@link TextAsTree.Members.characters} in an array.\n\t\t */\n\t\tcharactersCopy(): string[];\n\n\t\t/**\n\t\t * Gets the number of characters currently in the text.\n\t\t * @remarks\n\t\t * The length of {@link TextAsTree.Members.characters}.\n\t\t * This is not the length of the string returned by {@link TextAsTree.Members.fullString},\n\t\t * as that string may contain characters which are made up of multiple UTF-16 code units.\n\t\t */\n\t\tcharacterCount(): number;\n\n\t\t/**\n\t\t * Copy the content of this node into a string.\n\t\t */\n\t\tfullString(): string;\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 TextAsTree.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\tinsertAt(index: number, additionalCharacters: string): void;\n\n\t\t/**\n\t\t * Remove a range from a string based on character index.\n\t\t * See {@link (TreeArrayNode:interface).removeRange} for more details on the behavior.\n\t\t */\n\t\tremoveRange(startIndex: number | undefined, endIndex: number | undefined): void;\n\t}\n\n\t/**\n\t * Schema for a {@link TextAsTree.(Tree:variable)} node.\n\t * @remarks\n\t * See {@link TextAsTree.Statics} for static APIs on this schema, including construction.\n\t * @alpha\n\t */\n\texport const Tree = eraseSchemaDetails<Members, Statics>()(TextNode);\n\n\t/**\n\t * Node for the {@link TextAsTree.(Tree:type)} schema exposing the {@link TextAsTree.Members} API.\n\t * @remarks\n\t * Create using {@link TextAsTree.Statics.fromString}.\n\t * @alpha\n\t */\n\texport type Tree = Members & TreeNode & WithType<\"com.fluidframework.text.Text\">;\n}\n"]}
@@ -83,12 +83,12 @@ export declare namespace FormattedTextAsTree {
83
83
  h4: import("../simple-tree/index.js").TreeNodeSchemaClass<"com.fluidframework.text.formatted.lineTag.h4" | "com.h4", import("../simple-tree/index.js").NodeKind.Object, TreeNode & {
84
84
  readonly value: "h4";
85
85
  }, Record<string, never>, true, Record<string, never>, undefined>;
86
- h5: import("../simple-tree/index.js").TreeNodeSchemaClass<"com.fluidframework.text.formatted.lineTag.h5" | "com.h5", import("../simple-tree/index.js").NodeKind.Object, TreeNode & {
87
- readonly value: "h5";
88
- }, Record<string, never>, true, Record<string, never>, undefined>;
89
86
  li: import("../simple-tree/index.js").TreeNodeSchemaClass<"com.fluidframework.text.formatted.lineTag.li" | "com.li", import("../simple-tree/index.js").NodeKind.Object, TreeNode & {
90
87
  readonly value: "li";
91
88
  }, Record<string, never>, true, Record<string, never>, undefined>;
89
+ h5: import("../simple-tree/index.js").TreeNodeSchemaClass<"com.fluidframework.text.formatted.lineTag.h5" | "com.h5", import("../simple-tree/index.js").NodeKind.Object, TreeNode & {
90
+ readonly value: "h5";
91
+ }, Record<string, never>, true, Record<string, never>, undefined>;
92
92
  } & {
93
93
  readonly schema: [import("../simple-tree/index.js").TreeNodeSchemaClass<"com.fluidframework.text.formatted.lineTag.li" | "com.li", import("../simple-tree/index.js").NodeKind.Object, TreeNode & {
94
94
  readonly value: "li";
@@ -531,11 +531,15 @@ export declare namespace FormattedTextAsTree {
531
531
  */
532
532
  defaultFormat: CharacterFormat;
533
533
  /**
534
- * Gets an iterable over the characters currently in the text.
534
+ * Gets an array type view of the characters currently in the text.
535
535
  * @remarks
536
536
  * This iterator matches the behavior of {@link (TreeArrayNode:interface)} with respect to edits during iteration.
537
+ * @privateRemarks
538
+ * Currently this is implemented by a node and changes with the text over time.
539
+ * We might not want to leak a node like this in the API.
540
+ * Providing a way to index and iterate separately might be better.
537
541
  */
538
- charactersWithFormatting(): Iterable<StringAtom>;
542
+ charactersWithFormatting(): readonly StringAtom[];
539
543
  /**
540
544
  * Insert a range of characters into the string based on character index.
541
545
  * @remarks
@@ -552,11 +556,13 @@ export declare namespace FormattedTextAsTree {
552
556
  insertWithFormattingAt(index: number, additionalCharacters: Iterable<InsertableTypedNode<typeof StringAtom>>): void;
553
557
  /**
554
558
  * Apply formatting to a range of characters based on character index.
555
- * @param startIndex - The starting index of the range to format.
556
- * @param length - The number of characters to format.
559
+ * @param startIndex - The starting index (inclusive) of the range to format.
560
+ * @param endIndex - The ending index (exclusive) of the range to format.
557
561
  * @param format - The formatting to apply to the specified range.
562
+ * @remarks
563
+ * The start and end behave the same as in {@link (TreeArrayNode:interface).removeRange}.
558
564
  */
559
- formatRange(startIndex: number, length: number, format: Partial<CharacterFormat>): void;
565
+ formatRange(startIndex: number | undefined, endIndex: number | undefined, format: Partial<CharacterFormat>): void;
560
566
  }
561
567
  /**
562
568
  * Schema for a text node.
@@ -1 +1 @@
1
- {"version":3,"file":"textDomainFormatted.d.ts","sourceRoot":"","sources":["../../src/text/textDomainFormatted.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,OAAO,KAAK,EACX,mBAAmB,EACnB,QAAQ,EAC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,IAAI,SAAS,UAAU,EAAE,CAAC;QAElD;;;;;;;;;;;;WAYG;QACH,sBAAsB,CACrB,KAAK,EAAE,MAAM,EACb,oBAAoB,EAAE,QAAQ,CAAC,mBAAmB,CAAC,OAAO,UAAU,CAAC,CAAC,GACpE,IAAI,CAAC;QAER;;;;;;;WAOG;QACH,WAAW,CACV,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAC9B,IAAI,CAAC;KACR;IAED;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,IAAI,8RAAmD,CAAC;IACrE,MAAM,MAAM,IAAI,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC,wCAAwC,CAAC,CAAC;;CAC3F"}
@@ -2,12 +2,13 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { assert } from "@fluidframework/core-utils/internal";
5
+ import { assert, compareArrays, debugAssert, fail } from "@fluidframework/core-utils/internal";
6
6
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
7
- import { EmptyKey } from "../core/index.js";
7
+ import { EmptyKey, mapCursorField } from "../core/index.js";
8
+ import { currentObserver } from "../feature-libraries/index.js";
8
9
  import { TreeAlpha } from "../shared-tree/index.js";
9
- import { enumFromStrings, eraseSchemaDetails, SchemaFactory, SchemaFactoryAlpha, TreeArrayNode, TreeBeta, } from "../simple-tree/index.js";
10
- import { mapIterable } from "../util/index.js";
10
+ import { enumFromStrings, eraseSchemaDetails, getInnerNode, SchemaFactory, SchemaFactoryAlpha, TreeArrayNode, TreeBeta, } from "../simple-tree/index.js";
11
+ import { mapIterable, validateIndex, validateIndexRange } from "../util/index.js";
11
12
  import { charactersFromString } from "./textDomain.js";
12
13
  const sf = new SchemaFactoryAlpha("com.fluidframework.text.formatted");
13
14
  class TextNode extends sf.object("Text", {
@@ -20,15 +21,38 @@ class TextNode extends sf.object("Text", {
20
21
  insertAt(index, additionalCharacters) {
21
22
  this.content.insertAt(index, TreeArrayNode.spread(textAtomsFromString(additionalCharacters, this.defaultFormat)));
22
23
  }
23
- removeRange(index, length) {
24
- this.content.removeRange(index, length);
24
+ removeRange(index, end) {
25
+ this.content.removeRange(index, end);
25
26
  }
26
27
  characters() {
27
28
  return mapIterable(this.content, (atom) => atom.content.content);
28
29
  }
30
+ charactersCopy() {
31
+ const result = this.content.charactersCopy();
32
+ debugAssert(() => compareArrays(result, this.charactersCopy_reference()) ||
33
+ "invalid charactersCopy optimizations");
34
+ return result;
35
+ }
36
+ characterCount() {
37
+ return this.content.length;
38
+ }
29
39
  fullString() {
40
+ const result = this.content.fullString();
41
+ debugAssert(() => result === this.fullString_reference() || "invalid fullString optimizations");
42
+ return result;
43
+ }
44
+ /**
45
+ * A non-optimized reference implementation of fullString.
46
+ */
47
+ fullString_reference() {
30
48
  return [...this.characters()].join("");
31
49
  }
50
+ /**
51
+ * Unoptimized trivially correct implementation of charactersCopy.
52
+ */
53
+ charactersCopy_reference() {
54
+ return [...this.characters()];
55
+ }
32
56
  static fromString(value, format) {
33
57
  // Constructing an ArrayNode from an iterator is supported, so creating an array from the iterable of characters seems like it's not necessary here,
34
58
  // 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.
@@ -45,10 +69,14 @@ class TextNode extends sf.object("Text", {
45
69
  insertWithFormattingAt(index, additionalCharacters) {
46
70
  this.content.insertAt(index, TreeArrayNode.spread(additionalCharacters));
47
71
  }
48
- formatRange(startIndex, length, format) {
72
+ formatRange(start, end, format) {
73
+ const formatStart = start ?? 0;
74
+ validateIndex(formatStart, this.content, "FormattedTextAsTree.formatRange", true);
75
+ const formatEnd = Math.min(this.content.length, end ?? this.content.length);
76
+ validateIndexRange(formatStart, formatEnd, this.content, "FormattedTextAsTree.formatRange");
49
77
  const branch = TreeAlpha.branch(this);
50
78
  const applyFormatting = () => {
51
- for (let i = startIndex; i < startIndex + length; i++) {
79
+ for (let i = formatStart; i < formatEnd; i++) {
52
80
  const atom = this.content[i];
53
81
  if (atom === undefined) {
54
82
  throw new UsageError("Index out of bounds while formatting text range.");
@@ -95,6 +123,50 @@ function textAtomsFromString(value, format) {
95
123
  return result;
96
124
  }
97
125
  class StringArray extends sf.array("StringArray", [() => FormattedTextAsTree.StringAtom]) {
126
+ withBorrowedSequenceCursor(f) {
127
+ const innerNode = getInnerNode(this);
128
+ // Since the cursor will be used to read content from the tree and won't track observations,
129
+ // treat it as if it observed the whole subtree.
130
+ currentObserver?.observeNodeDeep(innerNode);
131
+ const cursor = innerNode.borrowCursor();
132
+ cursor.enterField(EmptyKey);
133
+ const result = f(cursor);
134
+ cursor.exitField();
135
+ return result;
136
+ }
137
+ charactersCopy() {
138
+ return this.withBorrowedSequenceCursor((cursor) => mapCursorField(cursor, () => {
139
+ debugAssert(() => cursor.type === FormattedTextAsTree.StringAtom.identifier ||
140
+ "invalid fullString type optimizations");
141
+ cursor.enterField(EmptyKey);
142
+ cursor.enterNode(0);
143
+ let content;
144
+ switch (cursor.type) {
145
+ case FormattedTextAsTree.StringTextAtom.identifier: {
146
+ cursor.enterField(EmptyKey);
147
+ cursor.enterNode(0);
148
+ content = cursor.value;
149
+ debugAssert(() => typeof content === "string" || "invalid fullString type optimizations");
150
+ cursor.exitNode();
151
+ cursor.exitField();
152
+ break;
153
+ }
154
+ case FormattedTextAsTree.StringLineAtom.identifier: {
155
+ content = "\n";
156
+ break;
157
+ }
158
+ default: {
159
+ fail(0xcde /* Unsupported node type in text array */, () => `${cursor.type}`);
160
+ }
161
+ }
162
+ cursor.exitNode();
163
+ cursor.exitField();
164
+ return content;
165
+ }));
166
+ }
167
+ fullString() {
168
+ return this.charactersCopy().join("");
169
+ }
98
170
  }
99
171
  /**
100
172
  * A collection of text related types, schema and utilities for working with text beyond the basic {@link SchemaStatics.string}.
@@ -1 +1 @@
1
- {"version":3,"file":"textDomainFormatted.js","sourceR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ACU,qCAAiB,GAAG,CAAC,cAAc,EAAE,cAAc,CAAU,CAAC;IAO3E;;;OAGG;IACH,MAAa,UAAW,SAAQ,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE;QACvD,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,oBAAA,iBAAiB,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;QACrE,MAAM,EAAE,eAAe;KACvB,CAAC;KAAG;IAHQ,8BAAU,aAGlB,CAAA;IA2EL;;;;;;OAMG;IACU,wBAAI,GAAG,kBAAkB,EAAoB,CAAC,QAAQ,CAAC,CAAC;AAEtE,CAAC,EAtKgB,mBAAmB,KAAnB,mBAAmB,QAsKnC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { EmptyKey } from \"../core/index.js\";\nimport { TreeAlpha } from \"../shared-tree/index.js\";\nimport {\n\tenumFromStrings,\n\teraseSchemaDetails,\n\tSchemaFactory,\n\tSchemaFactoryAlpha,\n\tTreeArrayNode,\n\tTreeBeta,\n} from \"../simple-tree/index.js\";\nimport type {\n\tInsertableTypedNode,\n\tTreeNode,\n\tTreeNodeFromImplicitAllowedTypes,\n\tWithType,\n} from \"../simple-tree/index.js\";\nimport { mapIterable } from \"../util/index.js\";\n\nimport { charactersFromString, type TextAsTree } from \"./textDomain.js\";\n\nconst sf = new SchemaFactoryAlpha(\"com.fluidframework.text.formatted\");\n\nclass TextNode\n\textends sf.object(\"Text\", {\n\t\tcontent: SchemaFactory.required([() => StringArray], { key: EmptyKey }),\n\t})\n\timplements FormattedTextAsTree.Members\n{\n\tpublic defaultFormat: FormattedTextAsTree.CharacterFormat =\n\t\tnew FormattedTextAsTree.CharacterFormat(defaultFormat);\n\n\tpublic insertAt(index: number, additionalCharacters: string): void {\n\t\tthis.content.insertAt(\n\t\t\tindex,\n\t\t\tTreeArrayNode.spread(textAtomsFromString(additionalCharacters, this.defaultFormat)),\n\t\t);\n\t}\n\tpublic removeRange(index: number, length: number): void {\n\t\tthis.content.removeRange(index, length);\n\t}\n\tpublic characters(): Iterable<string> {\n\t\treturn mapIterable(this.content, (atom) => atom.content.content);\n\t}\n\tpublic fullString(): string {\n\t\treturn [...this.characters()].join(\"\");\n\t}\n\n\tpublic static fromString(\n\t\tvalue: string,\n\t\tformat?: FormattedTextAsTree.CharacterFormat,\n\t): TextNode {\n\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// 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// Thus the array construction here is necessary to avoid a runtime error.\n\t\treturn new TextNode({\n\t\t\tcontent: [\n\t\t\t\t...textAtomsFromString(\n\t\t\t\t\tvalue,\n\t\t\t\t\tformat ?? new FormattedTextAsTree.CharacterFormat(defaultFormat),\n\t\t\t\t),\n\t\t\t],\n\t\t});\n\t}\n\n\tpublic charactersWithFormatting(): Iterable<FormattedTextAsTree.StringAtom> {\n\t\treturn this.content;\n\t}\n\tpublic insertWithFormattingAt(\n\t\tindex: number,\n\t\tadditionalCharacters: Iterable<InsertableTypedNode<typeof FormattedTextAsTree.StringAtom>>,\n\t): void {\n\t\tthis.content.insertAt(index, TreeArrayNode.spread(additionalCharacters));\n\t}\n\tpublic formatRange(\n\t\tstartIndex: number,\n\t\tlength: number,\n\t\tformat: Partial<FormattedTextAsTree.CharacterFormat>,\n\t): void {\n\t\tconst branch = TreeAlpha.branch(this);\n\n\t\tconst applyFormatting = (): void => {\n\t\t\tfor (let i = startIndex; i < startIndex + length; i++) {\n\t\t\t\tconst atom = this.content[i];\n\t\t\t\tif (atom === undefined) {\n\t\t\t\t\tthrow new UsageError(\"Index out of bounds while formatting text range.\");\n\t\t\t\t}\n\t\t\t\tfor (const [key, value] of Object.entries(format) as [\n\t\t\t\t\tkeyof FormattedTextAsTree.CharacterFormat,\n\t\t\t\t\tunknown,\n\t\t\t\t][]) {\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\tconst f = FormattedTextAsTree.CharacterFormat.fields.get(key);\n\t\t\t\t\tif (f === undefined) {\n\t\t\t\t\t\tthrow new UsageError(`Unknown format key: ${key}`);\n\t\t\t\t\t}\n\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\tatom.format[key] = TreeBeta.clone(TreeBeta.create(f, value as never)) as never;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tif (branch === undefined) {\n\t\t\t// If this node does not have a corresponding branch, then it is unhydrated.\n\t\t\t// I.e., it is not part of a collaborative session yet.\n\t\t\t// Therefore, we don't need to run the edits as a transaction.\n\t\t\tapplyFormatting();\n\t\t} else {\n\t\t\t// Wrap all formatting operations in a single transaction for atomicity.\n\t\t\tbranch.runTransaction(() => {\n\t\t\t\tapplyFormatting();\n\t\t\t});\n\t\t}\n\t}\n}\n\nconst defaultFormat = {\n\tbold: false,\n\titalic: false,\n\tunderline: false,\n\tsize: 12,\n\tfont: \"Arial\",\n} as const;\n\nfunction textAtomsFromString(\n\tvalue: string,\n\tformat: FormattedTextAsTree.CharacterFormat,\n): Iterable<FormattedTextAsTree.StringAtom> {\n\tconst result = mapIterable(\n\t\tcharactersFromString(value),\n\t\t(char) =>\n\t\t\tnew FormattedTextAsTree.StringAtom({\n\t\t\t\tcontent: { content: char },\n\t\t\t\tformat: TreeBeta.clone<typeof FormattedTextAsTree.CharacterFormat>(format),\n\t\t\t}),\n\t);\n\treturn result;\n}\n\nclass StringArray extends sf.array(\"StringArray\", [() => FormattedTextAsTree.StringAtom]) {}\n\n/**\n * A collection of text related types, schema and utilities for working with text beyond the basic {@link SchemaStatics.string}.\n * @privateRemarks\n * This has hard-coded assumptions about what kind of embedded content and what kind of formatting is supported.\n * We will want to generalize this with a more generic schema factory function like with table.\n * Then either that and/or the output from it can be package exported.\n * This version is just an initial prototype.\n * @internal\n */\nexport namespace FormattedTextAsTree {\n\t/**\n\t * Formatting options for characters.\n\t * @internal\n\t */\n\texport class CharacterFormat extends sf.objectAlpha(\"CharacterFormat\", {\n\t\tbold: SchemaFactory.boolean,\n\t\titalic: SchemaFactory.boolean,\n\t\tunderline: SchemaFactory.boolean,\n\t\tsize: SchemaFactory.number,\n\t\tfont: SchemaFactory.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 extends sf.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 codepoint, and thus may contain multiple utf-16 surrogate pair code units.\n\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 * 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\n\t/**\n\t * Tag with which a line in text can be formatted from HTML.\n\t * @internal\n\t */\n\texport const LineTag = enumFromStrings(sf.scopedFactory(\"lineTag\"), [\n\t\t\"h1\",\n\t\t\"h2\",\n\t\t\"h3\",\n\t\t\"h4\",\n\t\t\"h5\",\n\t\t\"li\",\n\t]);\n\t/**\n\t * {@inheritdoc FormattedTextAsTree.(LineTag:variable)}\n\t * @internal\n\t */\n\texport type LineTag = TreeNodeFromImplicitAllowedTypes<typeof LineTag.schema>;\n\n\t/**\n\t * Unit in the string representing a new line character with line formatting.\n\t * @remarks\n\t * This aligns with how Quill represents line formatting.\n\t * Note that not all new lines will use this,\n\t * but only ones using this can have line specific formatting.\n\t * @internal\n\t */\n\texport class StringLineAtom extends sf.object(\"StringLineAtom\", {\n\t\ttag: LineTag.schema,\n\t}) {\n\t\tpublic readonly content = \"\\n\";\n\t}\n\n\t/**\n\t * Types of \"atoms\" that make up the text.\n\t * @internal\n\t */\n\texport const StringAtomContent = [StringTextAtom, StringLineAtom] as const;\n\t/**\n\t * {@inheritdoc FormattedTextAsTree.(StringAtomContent:variable)}\n\t * @internal\n\t */\n\texport type StringAtomContent = TreeNodeFromImplicitAllowedTypes<typeof StringAtomContent>;\n\n\t/**\n\t * A unit of the text, with formatting.\n\t * @internal\n\t */\n\texport class StringAtom extends sf.object(\"StringAtom\", {\n\t\tcontent: SchemaFactory.required(StringAtomContent, { key: EmptyKey }),\n\t\tformat: CharacterFormat,\n\t}) {}\n\n\t/**\n\t * Statics for text nodes.\n\t * @internal\n\t */\n\texport interface Statics {\n\t\t/**\n\t\t * Construct a {@link FormattedTextAsTree.(Tree:type)} 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): Tree;\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.(Tree:type)} for schema.\n\t * @internal\n\t */\n\texport interface Members extends 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: CharacterFormat;\n\n\t\t/**\n\t\t * Gets an iterable over 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\tcharactersWithFormatting(): Iterable<StringAtom>;\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<InsertableTypedNode<typeof StringAtom>>,\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 of the range to format.\n\t\t * @param length - The number of characters to format.\n\t\t * @param format - The formatting to apply to the specified range.\n\t\t */\n\t\tformatRange(startIndex: number, length: number, format: Partial<CharacterFormat>): void;\n\t}\n\n\t/**\n\t * Schema for a text node.\n\t * @remarks\n\t * See {@link FormattedTextAsTree.Members} for the API.\n\t * See {@link FormattedTextAsTree.Statics} for static APIs on this Schema, including construction.\n\t * @internal\n\t */\n\texport const Tree = eraseSchemaDetails<Members, Statics>()(TextNode);\n\texport type Tree = Members & TreeNode & WithType<\"com.fluidframework.text.formatted.Text\">;\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,EAAE,QAAQ,EAAE,cAAc,EAA+B,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EACN,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,QAAQ,GACR,MAAM,yBAAyB,CAAC;AAOjC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAElF,OAAO,EAAE,oBAAoB,EAAmB,MAAM,iBAAiB,CAAC;AAExE,MAAM,EAAE,GAAG,IAAI,kBAAkB,CAAC,mCAAmC,CAAC,CAAC;AAEvE,MAAM,QACL,SAAQ,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE;IACzB,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;CACvE,CAAC;IAHH;;QAMQ,kBAAa,GACnB,IAAI,mBAAmB,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;IAuIzD,CAAC;IArIO,QAAQ,CAAC,KAAa,EAAE,oBAA4B;QAC1D,IAAI,CAAC,OAAO,CAAC,QAAQ,CACpB,KAA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Aa,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;KAC1E,CAAC;KAAG;IAbQ,kCAAc,iBAatB,CAAA;IAEL;;;OAGG;IACU,2BAAO,GAAG,eAAe,CAAC,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE;QACnE,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI;KACJ,CAAC,CAAC;IAOH;;;;;;;OAOG;IACH,MAAa,cAAe,SAAQ,EAAE,CAAC,MAAM,CAAC,gBAAgB,EAAE;QAC/D,GAAG,EAAE,oBAAA,OAAO,CAAC,MAAM;KACnB,CAAC;QAFF;;YAGiB,YAAO,GAAG,IAAI,CAAC;QAChC,CAAC;KAAA;IAJY,kCAAc,iBAI1B,CAAA;IAED;;;OAGG;IACU,qCAAiB,GAAG,CAAC,cAAc,EAAE,cAAc,CAAU,CAAC;IAO3E;;;OAGG;IACH,MAAa,UAAW,SAAQ,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE;QACvD,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,oBAAA,iBAAiB,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;QACrE,MAAM,EAAE,eAAe;KACvB,CAAC;KAAG;IAHQ,8BAAU,aAGlB,CAAA;IAqFL;;;;;;OAMG;IACU,wBAAI,GAAG,kBAAkB,EAAoB,CAAC,QAAQ,CAAC,CAAC;AAEtE,CAAC,EAhLgB,mBAAmB,KAAnB,mBAAmB,QAgLnC","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 { EmptyKey, mapCursorField, type ITreeCursorSynchronous } from \"../core/index.js\";\nimport { currentObserver } from \"../feature-libraries/index.js\";\nimport { TreeAlpha } from \"../shared-tree/index.js\";\nimport {\n\tenumFromStrings,\n\teraseSchemaDetails,\n\tgetInnerNode,\n\tSchemaFactory,\n\tSchemaFactoryAlpha,\n\tTreeArrayNode,\n\tTreeBeta,\n} from \"../simple-tree/index.js\";\nimport type {\n\tInsertableTypedNode,\n\tTreeNode,\n\tTreeNodeFromImplicitAllowedTypes,\n\tWithType,\n} from \"../simple-tree/index.js\";\nimport { mapIterable, validateIndex, validateIndexRange } from \"../util/index.js\";\n\nimport { charactersFromString, type TextAsTree } from \"./textDomain.js\";\n\nconst sf = new SchemaFactoryAlpha(\"com.fluidframework.text.formatted\");\n\nclass TextNode\n\textends sf.object(\"Text\", {\n\t\tcontent: SchemaFactory.required([() => StringArray], { key: EmptyKey }),\n\t})\n\timplements FormattedTextAsTree.Members\n{\n\tpublic defaultFormat: FormattedTextAsTree.CharacterFormat =\n\t\tnew FormattedTextAsTree.CharacterFormat(defaultFormat);\n\n\tpublic insertAt(index: number, additionalCharacters: string): void {\n\t\tthis.content.insertAt(\n\t\t\tindex,\n\t\t\tTreeArrayNode.spread(textAtomsFromString(additionalCharacters, this.defaultFormat)),\n\t\t);\n\t}\n\n\tpublic removeRange(index: number | undefined, end: number | undefined): void {\n\t\tthis.content.removeRange(index, end);\n\t}\n\n\tpublic characters(): Iterable<string> {\n\t\treturn mapIterable(this.content, (atom) => atom.content.content);\n\t}\n\n\tpublic charactersCopy(): string[] {\n\t\tconst result = this.content.charactersCopy();\n\t\tdebugAssert(\n\t\t\t() =>\n\t\t\t\tcompareArrays(result, this.charactersCopy_reference()) ||\n\t\t\t\t\"invalid charactersCopy optimizations\",\n\t\t);\n\t\treturn result;\n\t}\n\n\tpublic characterCount(): number {\n\t\treturn this.content.length;\n\t}\n\n\tpublic fullString(): string {\n\t\tconst result = this.content.fullString();\n\t\tdebugAssert(\n\t\t\t() => result === this.fullString_reference() || \"invalid fullString optimizations\",\n\t\t);\n\t\treturn result;\n\t}\n\n\t/**\n\t * A non-optimized reference implementation of fullString.\n\t */\n\tpublic fullString_reference(): string {\n\t\treturn [...this.characters()].join(\"\");\n\t}\n\n\t/**\n\t * Unoptimized trivially correct implementation of charactersCopy.\n\t */\n\tpublic charactersCopy_reference(): string[] {\n\t\treturn [...this.characters()];\n\t}\n\n\tpublic static fromString(\n\t\tvalue: string,\n\t\tformat?: FormattedTextAsTree.CharacterFormat,\n\t): TextNode {\n\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// 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// Thus the array construction here is necessary to avoid a runtime error.\n\t\treturn new TextNode({\n\t\t\tcontent: [\n\t\t\t\t...textAtomsFromString(\n\t\t\t\t\tvalue,\n\t\t\t\t\tformat ?? new FormattedTextAsTree.CharacterFormat(defaultFormat),\n\t\t\t\t),\n\t\t\t],\n\t\t});\n\t}\n\n\tpublic charactersWithFormatting(): readonly FormattedTextAsTree.StringAtom[] {\n\t\treturn this.content;\n\t}\n\tpublic insertWithFormattingAt(\n\t\tindex: number,\n\t\tadditionalCharacters: Iterable<InsertableTypedNode<typeof FormattedTextAsTree.StringAtom>>,\n\t): void {\n\t\tthis.content.insertAt(index, TreeArrayNode.spread(additionalCharacters));\n\t}\n\tpublic formatRange(\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\tformat: Partial<FormattedTextAsTree.CharacterFormat>,\n\t): void {\n\t\tconst formatStart = start ?? 0;\n\t\tvalidateIndex(formatStart, this.content, \"FormattedTextAsTree.formatRange\", true);\n\n\t\tconst formatEnd = Math.min(this.content.length, end ?? this.content.length);\n\t\tvalidateIndexRange(\n\t\t\tformatStart,\n\t\t\tformatEnd,\n\t\t\tthis.content,\n\t\t\t\"FormattedTextAsTree.formatRange\",\n\t\t);\n\n\t\tconst branch = TreeAlpha.branch(this);\n\n\t\tconst applyFormatting = (): void => {\n\t\t\tfor (let i = formatStart; i < formatEnd; i++) {\n\t\t\t\tconst atom = this.content[i];\n\t\t\t\tif (atom === undefined) {\n\t\t\t\t\tthrow new UsageError(\"Index out of bounds while formatting text range.\");\n\t\t\t\t}\n\t\t\t\tfor (const [key, value] of Object.entries(format) as [\n\t\t\t\t\tkeyof FormattedTextAsTree.CharacterFormat,\n\t\t\t\t\tunknown,\n\t\t\t\t][]) {\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\tconst f = FormattedTextAsTree.CharacterFormat.fields.get(key);\n\t\t\t\t\tif (f === undefined) {\n\t\t\t\t\t\tthrow new UsageError(`Unknown format key: ${key}`);\n\t\t\t\t\t}\n\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\tatom.format[key] = TreeBeta.clone(TreeBeta.create(f, value as never)) as never;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tif (branch === undefined) {\n\t\t\t// If this node does not have a corresponding branch, then it is unhydrated.\n\t\t\t// I.e., it is not part of a collaborative session yet.\n\t\t\t// Therefore, we don't need to run the edits as a transaction.\n\t\t\tapplyFormatting();\n\t\t} else {\n\t\t\t// Wrap all formatting operations in a single transaction for atomicity.\n\t\t\tbranch.runTransaction(() => {\n\t\t\t\tapplyFormatting();\n\t\t\t});\n\t\t}\n\t}\n}\n\nconst defaultFormat = {\n\tbold: false,\n\titalic: false,\n\tunderline: false,\n\tsize: 12,\n\tfont: \"Arial\",\n} as const;\n\nfunction textAtomsFromString(\n\tvalue: string,\n\tformat: FormattedTextAsTree.CharacterFormat,\n): Iterable<FormattedTextAsTree.StringAtom> {\n\tconst result = mapIterable(\n\t\tcharactersFromString(value),\n\t\t(char) =>\n\t\t\tnew FormattedTextAsTree.StringAtom({\n\t\t\t\tcontent: { content: char },\n\t\t\t\tformat: TreeBeta.clone<typeof FormattedTextAsTree.CharacterFormat>(format),\n\t\t\t}),\n\t);\n\treturn result;\n}\n\nclass StringArray extends sf.array(\"StringArray\", [() => FormattedTextAsTree.StringAtom]) {\n\tpublic withBorrowedSequenceCursor<T>(f: (cursor: ITreeCursorSynchronous) => T): T {\n\t\tconst innerNode = getInnerNode(this);\n\t\t// Since the cursor will be used to read content from the tree and won't track observations,\n\t\t// treat it as if it observed the whole subtree.\n\t\tcurrentObserver?.observeNodeDeep(innerNode);\n\t\tconst cursor = innerNode.borrowCursor();\n\t\tcursor.enterField(EmptyKey);\n\t\tconst result = f(cursor);\n\t\tcursor.exitField();\n\t\treturn result;\n\t}\n\n\tpublic charactersCopy(): string[] {\n\t\treturn this.withBorrowedSequenceCursor((cursor) =>\n\t\t\tmapCursorField(cursor, () => {\n\t\t\t\tdebugAssert(\n\t\t\t\t\t() =>\n\t\t\t\t\t\tcursor.type === FormattedTextAsTree.StringAtom.identifier ||\n\t\t\t\t\t\t\"invalid fullString type optimizations\",\n\t\t\t\t);\n\t\t\t\tcursor.enterField(EmptyKey);\n\t\t\t\tcursor.enterNode(0);\n\t\t\t\tlet content: string;\n\t\t\t\tswitch (cursor.type) {\n\t\t\t\t\tcase FormattedTextAsTree.StringTextAtom.identifier: {\n\t\t\t\t\t\tcursor.enterField(EmptyKey);\n\t\t\t\t\t\tcursor.enterNode(0);\n\t\t\t\t\t\tcontent = cursor.value as string;\n\t\t\t\t\t\tdebugAssert(\n\t\t\t\t\t\t\t() => typeof content === \"string\" || \"invalid fullString type optimizations\",\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\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase FormattedTextAsTree.StringLineAtom.identifier: {\n\t\t\t\t\t\tcontent = \"\\n\";\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tfail(0xcde /* Unsupported node type in text array */, () => `${cursor.type}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcursor.exitNode();\n\t\t\t\tcursor.exitField();\n\t\t\t\treturn content;\n\t\t\t}),\n\t\t);\n\t}\n\n\tpublic fullString(): string {\n\t\treturn this.charactersCopy().join(\"\");\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 * @privateRemarks\n * This has hard-coded assumptions about what kind of embedded content and what kind of formatting is supported.\n * We will want to generalize this with a more generic schema factory function like with table.\n * Then either that and/or the output from it can be package exported.\n * This version is just an initial prototype.\n * @internal\n */\nexport namespace FormattedTextAsTree {\n\t/**\n\t * Formatting options for characters.\n\t * @internal\n\t */\n\texport class CharacterFormat extends sf.objectAlpha(\"CharacterFormat\", {\n\t\tbold: SchemaFactory.boolean,\n\t\titalic: SchemaFactory.boolean,\n\t\tunderline: SchemaFactory.boolean,\n\t\tsize: SchemaFactory.number,\n\t\tfont: SchemaFactory.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 extends sf.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 codepoint, and thus may contain multiple utf-16 surrogate pair code units.\n\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 * 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\n\t/**\n\t * Tag with which a line in text can be formatted from HTML.\n\t * @internal\n\t */\n\texport const LineTag = enumFromStrings(sf.scopedFactory(\"lineTag\"), [\n\t\t\"h1\",\n\t\t\"h2\",\n\t\t\"h3\",\n\t\t\"h4\",\n\t\t\"h5\",\n\t\t\"li\",\n\t]);\n\t/**\n\t * {@inheritdoc FormattedTextAsTree.(LineTag:variable)}\n\t * @internal\n\t */\n\texport type LineTag = TreeNodeFromImplicitAllowedTypes<typeof LineTag.schema>;\n\n\t/**\n\t * Unit in the string representing a new line character with line formatting.\n\t * @remarks\n\t * This aligns with how Quill represents line formatting.\n\t * Note that not all new lines will use this,\n\t * but only ones using this can have line specific formatting.\n\t * @internal\n\t */\n\texport class StringLineAtom extends sf.object(\"StringLineAtom\", {\n\t\ttag: LineTag.schema,\n\t}) {\n\t\tpublic readonly content = \"\\n\";\n\t}\n\n\t/**\n\t * Types of \"atoms\" that make up the text.\n\t * @internal\n\t */\n\texport const StringAtomContent = [StringTextAtom, StringLineAtom] as const;\n\t/**\n\t * {@inheritdoc FormattedTextAsTree.(StringAtomContent:variable)}\n\t * @internal\n\t */\n\texport type StringAtomContent = TreeNodeFromImplicitAllowedTypes<typeof StringAtomContent>;\n\n\t/**\n\t * A unit of the text, with formatting.\n\t * @internal\n\t */\n\texport class StringAtom extends sf.object(\"StringAtom\", {\n\t\tcontent: SchemaFactory.required(StringAtomContent, { key: EmptyKey }),\n\t\tformat: CharacterFormat,\n\t}) {}\n\n\t/**\n\t * Statics for text nodes.\n\t * @internal\n\t */\n\texport interface Statics {\n\t\t/**\n\t\t * Construct a {@link FormattedTextAsTree.(Tree:type)} 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): Tree;\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.(Tree:type)} for schema.\n\t * @internal\n\t */\n\texport interface Members extends 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: CharacterFormat;\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 StringAtom[];\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<InsertableTypedNode<typeof StringAtom>>,\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: Partial<CharacterFormat>,\n\t\t): void;\n\t}\n\n\t/**\n\t * Schema for a text node.\n\t * @remarks\n\t * See {@link FormattedTextAsTree.Members} for the API.\n\t * See {@link FormattedTextAsTree.Statics} for static APIs on this Schema, including construction.\n\t * @internal\n\t */\n\texport const Tree = eraseSchemaDetails<Members, Statics>()(TextNode);\n\texport type Tree = Members & TreeNode & WithType<\"com.fluidframework.text.formatted.Text\">;\n}\n"]}
@@ -88,6 +88,7 @@ export declare class RangeMap<K, V> {
88
88
  clone(): RangeMap<K, V>;
89
89
  /**
90
90
  * Returns a new map which contains the entries from both input maps.
91
+ * Whenever both maps contain entires for the same keys, the value from map `b` is used in the returned map.
91
92
  */
92
93
  static union<K, V>(a: RangeMap<K, V>, b: RangeMap<K, V>): RangeMap<K, V>;
93
94
  private getIntersectingEntries;
@@ -1 +1 @@
1
- {"version":3,"file":"rangeMap.d.ts","sourceRoot":"","sources":["../../src/util/rangeMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH;;;;;;GAMG;AACH,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC;IAqBxB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY;aACb,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;IAtB7D,OAAO,CAAC,IAAI,CAA0B;IAEtC;;;;;;;;;;;;;;;;OAgBG;gBAEe,SAAS,EA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K,EAAE,CAAC,CAAC;CAClB;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,KAAK,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAEjF"}
@@ -4,8 +4,6 @@
4
4
  */
5
5
  import { assert, oob } from "@fluidframework/core-utils/internal";
6
6
  import { BTree } from "@tylerbu/sorted-btree-es6";
7
- // eslint-disable-next-line import-x/no-internal-modules
8
- import { union } from "@tylerbu/sorted-btree-es6/extended/union";
9
7
  /**
10
8
  * RangeMap represents a mapping from keys of type K to values of type V or undefined.
11
9
  * The set of all possible keys is assumed to be fully ordered,
@@ -190,15 +188,16 @@ export class RangeMap {
190
188
  }
191
189
  /**
192
190
  * Returns a new map which contains the entries from both input maps.
191
+ * Whenever both maps contain entires for the same keys, the value from map `b` is used in the returned map.
193
192
  */
194
193
  static union(a, b) {
195
194
  assert(a.offsetKey === b.offsetKey &&
196
195
  a.subtractKeys === b.subtractKeys &&
197
196
  a.offsetValue === b.offsetValue, 0xaae /* Maps should have the same behavior */);
198
- const merged = new RangeMap(a.offsetKey, a.subtractKeys, a.offsetValue);
199
- merged.tree = union(a.tree, b.tree, (_key, _val1, val2) => {
200
- return val2;
201
- });
197
+ const merged = a.clone();
198
+ for (const entry of b.entries()) {
199
+ merged.set(entry.start, entry.length, entry.value);
200
+ }
202
201
  return merged;
203
202
  }
204
203
  getIntersectingEntries(start, length) {