@fluidframework/sequence 1.4.0-121020 → 2.0.0-dev-rc.1.0.0.224419

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 (349) hide show
  1. package/.eslintrc.js +9 -11
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +449 -0
  4. package/README.md +364 -183
  5. package/api-extractor-lint.json +4 -0
  6. package/api-extractor.json +2 -2
  7. package/api-report/sequence.api.md +741 -0
  8. package/dist/{defaultMap.js → defaultMap.cjs} +29 -22
  9. package/dist/defaultMap.cjs.map +1 -0
  10. package/dist/defaultMap.d.ts +7 -6
  11. package/dist/defaultMap.d.ts.map +1 -1
  12. package/dist/defaultMapInterfaces.cjs +7 -0
  13. package/dist/defaultMapInterfaces.cjs.map +1 -0
  14. package/dist/defaultMapInterfaces.d.ts +44 -12
  15. package/dist/defaultMapInterfaces.d.ts.map +1 -1
  16. package/dist/index.cjs +60 -0
  17. package/dist/index.cjs.map +1 -0
  18. package/dist/index.d.ts +14 -12
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/intervalCollection.cjs +1159 -0
  21. package/dist/intervalCollection.cjs.map +1 -0
  22. package/dist/intervalCollection.d.ts +461 -162
  23. package/dist/intervalCollection.d.ts.map +1 -1
  24. package/dist/intervalIndex/endpointInRangeIndex.cjs +66 -0
  25. package/dist/intervalIndex/endpointInRangeIndex.cjs.map +1 -0
  26. package/dist/intervalIndex/endpointInRangeIndex.d.ts +34 -0
  27. package/dist/intervalIndex/endpointInRangeIndex.d.ts.map +1 -0
  28. package/dist/intervalIndex/endpointIndex.cjs +47 -0
  29. package/dist/intervalIndex/endpointIndex.cjs.map +1 -0
  30. package/dist/intervalIndex/endpointIndex.d.ts +38 -0
  31. package/dist/intervalIndex/endpointIndex.d.ts.map +1 -0
  32. package/dist/intervalIndex/idIntervalIndex.cjs +44 -0
  33. package/dist/intervalIndex/idIntervalIndex.cjs.map +1 -0
  34. package/dist/intervalIndex/idIntervalIndex.d.ts +18 -0
  35. package/dist/intervalIndex/idIntervalIndex.d.ts.map +1 -0
  36. package/dist/intervalIndex/index.cjs +24 -0
  37. package/dist/intervalIndex/index.cjs.map +1 -0
  38. package/dist/intervalIndex/index.d.ts +13 -0
  39. package/dist/intervalIndex/index.d.ts.map +1 -0
  40. package/dist/{defaultMapInterfaces.js → intervalIndex/intervalIndex.cjs} +1 -1
  41. package/dist/intervalIndex/intervalIndex.cjs.map +1 -0
  42. package/dist/intervalIndex/intervalIndex.d.ts +30 -0
  43. package/dist/intervalIndex/intervalIndex.d.ts.map +1 -0
  44. package/dist/intervalIndex/intervalIndexUtils.cjs +22 -0
  45. package/dist/intervalIndex/intervalIndexUtils.cjs.map +1 -0
  46. package/dist/intervalIndex/intervalIndexUtils.d.ts +17 -0
  47. package/dist/intervalIndex/intervalIndexUtils.d.ts.map +1 -0
  48. package/dist/intervalIndex/overlappingIntervalsIndex.cjs +116 -0
  49. package/dist/intervalIndex/overlappingIntervalsIndex.cjs.map +1 -0
  50. package/dist/intervalIndex/overlappingIntervalsIndex.d.ts +44 -0
  51. package/dist/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -0
  52. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.cjs +41 -0
  53. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.cjs.map +1 -0
  54. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts +11 -0
  55. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +1 -0
  56. package/dist/intervalIndex/sequenceIntervalIndexes.cjs +7 -0
  57. package/dist/intervalIndex/sequenceIntervalIndexes.cjs.map +1 -0
  58. package/dist/intervalIndex/sequenceIntervalIndexes.d.ts +35 -0
  59. package/dist/intervalIndex/sequenceIntervalIndexes.d.ts.map +1 -0
  60. package/dist/intervalIndex/startpointInRangeIndex.cjs +66 -0
  61. package/dist/intervalIndex/startpointInRangeIndex.cjs.map +1 -0
  62. package/dist/intervalIndex/startpointInRangeIndex.d.ts +34 -0
  63. package/dist/intervalIndex/startpointInRangeIndex.d.ts.map +1 -0
  64. package/dist/intervalTree.cjs +80 -0
  65. package/dist/intervalTree.cjs.map +1 -0
  66. package/dist/intervalTree.d.ts +24 -0
  67. package/dist/intervalTree.d.ts.map +1 -0
  68. package/dist/intervals/index.cjs +23 -0
  69. package/dist/intervals/index.cjs.map +1 -0
  70. package/dist/intervals/index.d.ts +8 -0
  71. package/dist/intervals/index.d.ts.map +1 -0
  72. package/dist/intervals/interval.cjs +181 -0
  73. package/dist/intervals/interval.cjs.map +1 -0
  74. package/dist/intervals/interval.d.ts +84 -0
  75. package/dist/intervals/interval.d.ts.map +1 -0
  76. package/dist/intervals/intervalUtils.cjs +83 -0
  77. package/dist/intervals/intervalUtils.cjs.map +1 -0
  78. package/dist/intervals/intervalUtils.d.ts +230 -0
  79. package/dist/intervals/intervalUtils.d.ts.map +1 -0
  80. package/dist/intervals/sequenceInterval.cjs +378 -0
  81. package/dist/intervals/sequenceInterval.cjs.map +1 -0
  82. package/dist/intervals/sequenceInterval.d.ts +137 -0
  83. package/dist/intervals/sequenceInterval.d.ts.map +1 -0
  84. package/dist/{localValues.js → localValues.cjs} +1 -1
  85. package/dist/localValues.cjs.map +1 -0
  86. package/dist/localValues.d.ts +2 -1
  87. package/dist/localValues.d.ts.map +1 -1
  88. package/dist/{packageVersion.js → packageVersion.cjs} +2 -2
  89. package/dist/packageVersion.cjs.map +1 -0
  90. package/dist/packageVersion.d.ts +1 -1
  91. package/dist/packageVersion.d.ts.map +1 -1
  92. package/dist/revertibles.cjs +425 -0
  93. package/dist/revertibles.cjs.map +1 -0
  94. package/dist/revertibles.d.ts +86 -0
  95. package/dist/revertibles.d.ts.map +1 -0
  96. package/dist/sequence-alpha.d.ts +1315 -0
  97. package/dist/sequence-beta.d.ts +244 -0
  98. package/dist/sequence-public.d.ts +244 -0
  99. package/dist/sequence-untrimmed.d.ts +1803 -0
  100. package/dist/{sequence.js → sequence.cjs} +226 -156
  101. package/dist/sequence.cjs.map +1 -0
  102. package/dist/sequence.d.ts +125 -48
  103. package/dist/sequence.d.ts.map +1 -1
  104. package/dist/{sequenceDeltaEvent.js → sequenceDeltaEvent.cjs} +18 -8
  105. package/dist/sequenceDeltaEvent.cjs.map +1 -0
  106. package/dist/sequenceDeltaEvent.d.ts +24 -7
  107. package/dist/sequenceDeltaEvent.d.ts.map +1 -1
  108. package/dist/sequenceFactory.cjs +55 -0
  109. package/dist/sequenceFactory.cjs.map +1 -0
  110. package/dist/sequenceFactory.d.ts +3 -89
  111. package/dist/sequenceFactory.d.ts.map +1 -1
  112. package/dist/{sharedIntervalCollection.js → sharedIntervalCollection.cjs} +17 -22
  113. package/dist/sharedIntervalCollection.cjs.map +1 -0
  114. package/dist/sharedIntervalCollection.d.ts +12 -12
  115. package/dist/sharedIntervalCollection.d.ts.map +1 -1
  116. package/dist/{sharedSequence.js → sharedSequence.cjs} +29 -22
  117. package/dist/sharedSequence.cjs.map +1 -0
  118. package/dist/sharedSequence.d.ts +14 -2
  119. package/dist/sharedSequence.d.ts.map +1 -1
  120. package/dist/sharedString.cjs +286 -0
  121. package/dist/sharedString.cjs.map +1 -0
  122. package/dist/sharedString.d.ts +58 -22
  123. package/dist/sharedString.d.ts.map +1 -1
  124. package/dist/tsdoc-metadata.json +11 -0
  125. package/lib/{defaultMap.d.ts → defaultMap.d.mts} +7 -6
  126. package/lib/defaultMap.d.mts.map +1 -0
  127. package/lib/{defaultMap.js → defaultMap.mjs} +28 -21
  128. package/lib/defaultMap.mjs.map +1 -0
  129. package/lib/{defaultMapInterfaces.d.ts → defaultMapInterfaces.d.mts} +44 -12
  130. package/lib/defaultMapInterfaces.d.mts.map +1 -0
  131. package/lib/defaultMapInterfaces.mjs +6 -0
  132. package/lib/defaultMapInterfaces.mjs.map +1 -0
  133. package/lib/index.d.mts +17 -0
  134. package/lib/index.d.mts.map +1 -0
  135. package/lib/index.mjs +16 -0
  136. package/lib/index.mjs.map +1 -0
  137. package/lib/intervalCollection.d.mts +569 -0
  138. package/lib/intervalCollection.d.mts.map +1 -0
  139. package/lib/intervalCollection.mjs +1144 -0
  140. package/lib/intervalCollection.mjs.map +1 -0
  141. package/lib/intervalIndex/endpointInRangeIndex.d.mts +34 -0
  142. package/lib/intervalIndex/endpointInRangeIndex.d.mts.map +1 -0
  143. package/lib/intervalIndex/endpointInRangeIndex.mjs +61 -0
  144. package/lib/intervalIndex/endpointInRangeIndex.mjs.map +1 -0
  145. package/lib/intervalIndex/endpointIndex.d.mts +38 -0
  146. package/lib/intervalIndex/endpointIndex.d.mts.map +1 -0
  147. package/lib/intervalIndex/endpointIndex.mjs +42 -0
  148. package/lib/intervalIndex/endpointIndex.mjs.map +1 -0
  149. package/lib/intervalIndex/idIntervalIndex.d.mts +18 -0
  150. package/lib/intervalIndex/idIntervalIndex.d.mts.map +1 -0
  151. package/lib/intervalIndex/idIntervalIndex.mjs +40 -0
  152. package/lib/intervalIndex/idIntervalIndex.mjs.map +1 -0
  153. package/lib/intervalIndex/index.d.mts +13 -0
  154. package/lib/intervalIndex/index.d.mts.map +1 -0
  155. package/lib/intervalIndex/index.mjs +11 -0
  156. package/lib/intervalIndex/index.mjs.map +1 -0
  157. package/lib/intervalIndex/intervalIndex.d.mts +30 -0
  158. package/lib/intervalIndex/intervalIndex.d.mts.map +1 -0
  159. package/lib/{defaultMapInterfaces.js → intervalIndex/intervalIndex.mjs} +1 -1
  160. package/lib/intervalIndex/intervalIndex.mjs.map +1 -0
  161. package/lib/intervalIndex/intervalIndexUtils.d.mts +17 -0
  162. package/lib/intervalIndex/intervalIndexUtils.d.mts.map +1 -0
  163. package/lib/intervalIndex/intervalIndexUtils.mjs +18 -0
  164. package/lib/intervalIndex/intervalIndexUtils.mjs.map +1 -0
  165. package/lib/intervalIndex/overlappingIntervalsIndex.d.mts +44 -0
  166. package/lib/intervalIndex/overlappingIntervalsIndex.d.mts.map +1 -0
  167. package/lib/intervalIndex/overlappingIntervalsIndex.mjs +111 -0
  168. package/lib/intervalIndex/overlappingIntervalsIndex.mjs.map +1 -0
  169. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.mts +11 -0
  170. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.mts.map +1 -0
  171. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.mjs +37 -0
  172. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.mjs.map +1 -0
  173. package/lib/intervalIndex/sequenceIntervalIndexes.d.mts +35 -0
  174. package/lib/intervalIndex/sequenceIntervalIndexes.d.mts.map +1 -0
  175. package/lib/intervalIndex/sequenceIntervalIndexes.mjs +6 -0
  176. package/lib/intervalIndex/sequenceIntervalIndexes.mjs.map +1 -0
  177. package/lib/intervalIndex/startpointInRangeIndex.d.mts +34 -0
  178. package/lib/intervalIndex/startpointInRangeIndex.d.mts.map +1 -0
  179. package/lib/intervalIndex/startpointInRangeIndex.mjs +61 -0
  180. package/lib/intervalIndex/startpointInRangeIndex.mjs.map +1 -0
  181. package/lib/intervalTree.d.mts +24 -0
  182. package/lib/intervalTree.d.mts.map +1 -0
  183. package/lib/intervalTree.mjs +76 -0
  184. package/lib/intervalTree.mjs.map +1 -0
  185. package/lib/intervals/index.d.mts +8 -0
  186. package/lib/intervals/index.d.mts.map +1 -0
  187. package/lib/intervals/index.mjs +8 -0
  188. package/lib/intervals/index.mjs.map +1 -0
  189. package/lib/intervals/interval.d.mts +84 -0
  190. package/lib/intervals/interval.d.mts.map +1 -0
  191. package/lib/intervals/interval.mjs +176 -0
  192. package/lib/intervals/interval.mjs.map +1 -0
  193. package/lib/intervals/intervalUtils.d.mts +230 -0
  194. package/lib/intervals/intervalUtils.d.mts.map +1 -0
  195. package/lib/intervals/intervalUtils.mjs +77 -0
  196. package/lib/intervals/intervalUtils.mjs.map +1 -0
  197. package/lib/intervals/sequenceInterval.d.mts +137 -0
  198. package/lib/intervals/sequenceInterval.d.mts.map +1 -0
  199. package/lib/intervals/sequenceInterval.mjs +370 -0
  200. package/lib/intervals/sequenceInterval.mjs.map +1 -0
  201. package/lib/{localValues.d.ts → localValues.d.mts} +3 -2
  202. package/lib/localValues.d.mts.map +1 -0
  203. package/lib/{localValues.js → localValues.mjs} +2 -2
  204. package/lib/localValues.mjs.map +1 -0
  205. package/lib/{packageVersion.d.ts → packageVersion.d.mts} +1 -1
  206. package/lib/{packageVersion.d.ts.map → packageVersion.d.mts.map} +1 -1
  207. package/lib/{packageVersion.js → packageVersion.mjs} +2 -2
  208. package/lib/packageVersion.mjs.map +1 -0
  209. package/lib/revertibles.d.mts +86 -0
  210. package/lib/revertibles.d.mts.map +1 -0
  211. package/lib/revertibles.mjs +416 -0
  212. package/lib/revertibles.mjs.map +1 -0
  213. package/lib/sequence-alpha.d.mts +1315 -0
  214. package/lib/sequence-beta.d.mts +244 -0
  215. package/lib/sequence-public.d.mts +244 -0
  216. package/lib/sequence-untrimmed.d.mts +1803 -0
  217. package/lib/{sequence.d.ts → sequence.d.mts} +127 -50
  218. package/lib/sequence.d.mts.map +1 -0
  219. package/lib/{sequence.js → sequence.mjs} +225 -152
  220. package/lib/sequence.mjs.map +1 -0
  221. package/lib/{sequenceDeltaEvent.d.ts → sequenceDeltaEvent.d.mts} +24 -7
  222. package/lib/sequenceDeltaEvent.d.mts.map +1 -0
  223. package/lib/{sequenceDeltaEvent.js → sequenceDeltaEvent.mjs} +20 -8
  224. package/lib/sequenceDeltaEvent.mjs.map +1 -0
  225. package/lib/sequenceFactory.d.mts +22 -0
  226. package/lib/sequenceFactory.d.mts.map +1 -0
  227. package/lib/sequenceFactory.mjs +51 -0
  228. package/lib/sequenceFactory.mjs.map +1 -0
  229. package/lib/{sharedIntervalCollection.d.ts → sharedIntervalCollection.d.mts} +12 -12
  230. package/lib/sharedIntervalCollection.d.mts.map +1 -0
  231. package/lib/{sharedIntervalCollection.js → sharedIntervalCollection.mjs} +16 -21
  232. package/lib/sharedIntervalCollection.mjs.map +1 -0
  233. package/lib/{sharedSequence.d.ts → sharedSequence.d.mts} +15 -3
  234. package/lib/sharedSequence.d.mts.map +1 -0
  235. package/lib/{sharedSequence.js → sharedSequence.mjs} +30 -23
  236. package/lib/sharedSequence.mjs.map +1 -0
  237. package/lib/{sharedString.d.ts → sharedString.d.mts} +60 -24
  238. package/lib/sharedString.d.mts.map +1 -0
  239. package/lib/sharedString.mjs +281 -0
  240. package/lib/sharedString.mjs.map +1 -0
  241. package/package.json +146 -75
  242. package/prettier.config.cjs +8 -0
  243. package/sequence.test-files.tar +0 -0
  244. package/src/defaultMap.ts +417 -403
  245. package/src/defaultMapInterfaces.ts +157 -117
  246. package/src/index.ts +86 -26
  247. package/src/intervalCollection.ts +2043 -1563
  248. package/src/intervalIndex/endpointInRangeIndex.ts +116 -0
  249. package/src/intervalIndex/endpointIndex.ts +91 -0
  250. package/src/intervalIndex/idIntervalIndex.ts +64 -0
  251. package/src/intervalIndex/index.ts +25 -0
  252. package/src/intervalIndex/intervalIndex.ts +32 -0
  253. package/src/intervalIndex/intervalIndexUtils.ts +27 -0
  254. package/src/intervalIndex/overlappingIntervalsIndex.ts +187 -0
  255. package/src/intervalIndex/overlappingSequenceIntervalsIndex.ts +80 -0
  256. package/src/intervalIndex/sequenceIntervalIndexes.ts +34 -0
  257. package/src/intervalIndex/startpointInRangeIndex.ts +114 -0
  258. package/src/intervalTree.ts +98 -0
  259. package/src/intervals/index.ts +25 -0
  260. package/src/intervals/interval.ts +238 -0
  261. package/src/intervals/intervalUtils.ts +288 -0
  262. package/src/intervals/sequenceInterval.ts +616 -0
  263. package/src/localValues.ts +68 -73
  264. package/src/packageVersion.ts +1 -1
  265. package/src/revertibles.ts +693 -0
  266. package/src/sequence.ts +845 -690
  267. package/src/sequenceDeltaEvent.ts +164 -131
  268. package/src/sequenceFactory.ts +58 -214
  269. package/src/sharedIntervalCollection.ts +161 -152
  270. package/src/sharedSequence.ts +181 -167
  271. package/src/sharedString.ts +390 -234
  272. package/tsc-multi.test.json +10 -0
  273. package/tsconfig.json +11 -13
  274. package/.editorconfig +0 -7
  275. package/.vscode/launch.json +0 -15
  276. package/dist/defaultMap.js.map +0 -1
  277. package/dist/defaultMapInterfaces.js.map +0 -1
  278. package/dist/index.js +0 -44
  279. package/dist/index.js.map +0 -1
  280. package/dist/intervalCollection.js +0 -1250
  281. package/dist/intervalCollection.js.map +0 -1
  282. package/dist/localValues.js.map +0 -1
  283. package/dist/packageVersion.js.map +0 -1
  284. package/dist/sequence.js.map +0 -1
  285. package/dist/sequenceDeltaEvent.js.map +0 -1
  286. package/dist/sequenceFactory.js +0 -192
  287. package/dist/sequenceFactory.js.map +0 -1
  288. package/dist/sharedIntervalCollection.js.map +0 -1
  289. package/dist/sharedNumberSequence.d.ts +0 -50
  290. package/dist/sharedNumberSequence.d.ts.map +0 -1
  291. package/dist/sharedNumberSequence.js +0 -61
  292. package/dist/sharedNumberSequence.js.map +0 -1
  293. package/dist/sharedObjectSequence.d.ts +0 -50
  294. package/dist/sharedObjectSequence.d.ts.map +0 -1
  295. package/dist/sharedObjectSequence.js +0 -61
  296. package/dist/sharedObjectSequence.js.map +0 -1
  297. package/dist/sharedSequence.js.map +0 -1
  298. package/dist/sharedString.js +0 -187
  299. package/dist/sharedString.js.map +0 -1
  300. package/dist/sparsematrix.d.ts +0 -139
  301. package/dist/sparsematrix.d.ts.map +0 -1
  302. package/dist/sparsematrix.js +0 -332
  303. package/dist/sparsematrix.js.map +0 -1
  304. package/lib/defaultMap.d.ts.map +0 -1
  305. package/lib/defaultMap.js.map +0 -1
  306. package/lib/defaultMapInterfaces.d.ts.map +0 -1
  307. package/lib/defaultMapInterfaces.js.map +0 -1
  308. package/lib/index.d.ts +0 -27
  309. package/lib/index.d.ts.map +0 -1
  310. package/lib/index.js +0 -26
  311. package/lib/index.js.map +0 -1
  312. package/lib/intervalCollection.d.ts +0 -270
  313. package/lib/intervalCollection.d.ts.map +0 -1
  314. package/lib/intervalCollection.js +0 -1238
  315. package/lib/intervalCollection.js.map +0 -1
  316. package/lib/localValues.d.ts.map +0 -1
  317. package/lib/localValues.js.map +0 -1
  318. package/lib/packageVersion.js.map +0 -1
  319. package/lib/sequence.d.ts.map +0 -1
  320. package/lib/sequence.js.map +0 -1
  321. package/lib/sequenceDeltaEvent.d.ts.map +0 -1
  322. package/lib/sequenceDeltaEvent.js.map +0 -1
  323. package/lib/sequenceFactory.d.ts +0 -108
  324. package/lib/sequenceFactory.d.ts.map +0 -1
  325. package/lib/sequenceFactory.js +0 -186
  326. package/lib/sequenceFactory.js.map +0 -1
  327. package/lib/sharedIntervalCollection.d.ts.map +0 -1
  328. package/lib/sharedIntervalCollection.js.map +0 -1
  329. package/lib/sharedNumberSequence.d.ts +0 -50
  330. package/lib/sharedNumberSequence.d.ts.map +0 -1
  331. package/lib/sharedNumberSequence.js +0 -57
  332. package/lib/sharedNumberSequence.js.map +0 -1
  333. package/lib/sharedObjectSequence.d.ts +0 -50
  334. package/lib/sharedObjectSequence.d.ts.map +0 -1
  335. package/lib/sharedObjectSequence.js +0 -57
  336. package/lib/sharedObjectSequence.js.map +0 -1
  337. package/lib/sharedSequence.d.ts.map +0 -1
  338. package/lib/sharedSequence.js.map +0 -1
  339. package/lib/sharedString.d.ts.map +0 -1
  340. package/lib/sharedString.js +0 -183
  341. package/lib/sharedString.js.map +0 -1
  342. package/lib/sparsematrix.d.ts +0 -139
  343. package/lib/sparsematrix.d.ts.map +0 -1
  344. package/lib/sparsematrix.js +0 -323
  345. package/lib/sparsematrix.js.map +0 -1
  346. package/src/sharedNumberSequence.ts +0 -62
  347. package/src/sharedObjectSequence.ts +0 -62
  348. package/src/sparsematrix.ts +0 -421
  349. package/tsconfig.esnext.json +0 -7
@@ -4,17 +4,16 @@
4
4
  */
5
5
 
6
6
  import {
7
- ICombiningOp,
8
- IMergeTreeInsertMsg,
9
- IMergeTreeRemoveMsg,
10
- IRelativePosition,
11
- ISegment,
12
- Marker,
13
- MergeTreeTextHelper,
14
- PropertySet,
15
- ReferencePosition,
16
- ReferenceType,
17
- TextSegment,
7
+ IMergeTreeTextHelper,
8
+ IRelativePosition,
9
+ ISegment,
10
+ ISegmentAction,
11
+ Marker,
12
+ PropertySet,
13
+ ReferencePosition,
14
+ ReferenceType,
15
+ refHasTileLabel,
16
+ TextSegment,
18
17
  } from "@fluidframework/merge-tree";
19
18
  import { IFluidDataStoreRuntime, IChannelAttributes } from "@fluidframework/datastore-definitions";
20
19
  import { SharedSegmentSequence } from "./sequence";
@@ -22,30 +21,34 @@ import { SharedStringFactory } from "./sequenceFactory";
22
21
 
23
22
  /**
24
23
  * Fluid object interface describing access methods on a SharedString
24
+ * @alpha
25
25
  */
26
26
  export interface ISharedString extends SharedSegmentSequence<SharedStringSegment> {
27
- /**
28
- * Inserts the text at the position.
29
- * @param pos - The position to insert the text at
30
- * @param text - The text to insert
31
- * @param props - The properties of the text
32
- */
33
- insertText(pos: number, text: string, props?: PropertySet): void;
34
-
35
- /**
36
- * Inserts a marker at the position.
37
- * @param pos - The position to insert the marker at
38
- * @param refType - The reference type of the marker
39
- * @param props - The properties of the marker
40
- */
41
- insertMarker(pos: number, refType: ReferenceType, props?: PropertySet): IMergeTreeInsertMsg;
42
-
43
- /**
44
- * {@inheritDoc SharedSegmentSequence.posFromRelativePos}
45
- */
46
- posFromRelativePos(relativePos: IRelativePosition): number;
27
+ /**
28
+ * Inserts the text at the position.
29
+ * @param pos - The position to insert the text at
30
+ * @param text - The text to insert
31
+ * @param props - The properties of the text
32
+ */
33
+ insertText(pos: number, text: string, props?: PropertySet): void;
34
+
35
+ /**
36
+ * Inserts a marker at the position.
37
+ * @param pos - The position to insert the marker at
38
+ * @param refType - The reference type of the marker
39
+ * @param props - The properties of the marker
40
+ */
41
+ insertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void;
42
+
43
+ /**
44
+ * {@inheritDoc SharedSegmentSequence.posFromRelativePos}
45
+ */
46
+ posFromRelativePos(relativePos: IRelativePosition): number;
47
47
  }
48
48
 
49
+ /**
50
+ * @alpha
51
+ */
49
52
  export type SharedStringSegment = TextSegment | Marker;
50
53
 
51
54
  /**
@@ -56,208 +59,361 @@ export type SharedStringSegment = TextSegment | Marker;
56
59
  * In addition to text, a Shared String can also contain markers. Markers can be
57
60
  * used to store metadata at positions within the text, like the details of an
58
61
  * image or Fluid object that should be rendered with the text.
59
- *
62
+ * @alpha
60
63
  */
61
- export class SharedString extends SharedSegmentSequence<SharedStringSegment> implements ISharedString {
62
- /**
63
- * Create a new shared string.
64
- * @param runtime - data store runtime the new shared string belongs to
65
- * @param id - optional name of the shared string
66
- * @returns newly create shared string (but not attached yet)
67
- */
68
- public static create(runtime: IFluidDataStoreRuntime, id?: string) {
69
- return runtime.createChannel(id, SharedStringFactory.Type) as SharedString;
70
- }
71
-
72
- /**
73
- * Get a factory for SharedString to register with the data store.
74
- * @returns a factory that creates and load SharedString
75
- */
76
- public static getFactory() {
77
- return new SharedStringFactory();
78
- }
79
-
80
- public get ISharedString(): ISharedString {
81
- return this;
82
- }
83
-
84
- private readonly mergeTreeTextHelper: MergeTreeTextHelper;
85
-
86
- constructor(document: IFluidDataStoreRuntime, public id: string, attributes: IChannelAttributes) {
87
- super(document, id, attributes, SharedStringFactory.segmentFromSpec);
88
- this.mergeTreeTextHelper = this.client.createTextHelper();
89
- }
90
-
91
- /**
92
- * Inserts a marker at a relative position.
93
- * @param relativePos1 - The relative position to insert the marker at
94
- * @param refType - The reference type of the marker
95
- * @param props - The properties of the marker
96
- */
97
- public insertMarkerRelative(
98
- relativePos1: IRelativePosition,
99
- refType: ReferenceType,
100
- props?: PropertySet) {
101
- const segment = new Marker(refType);
102
- if (props) {
103
- segment.addProperties(props);
104
- }
105
-
106
- const pos = this.posFromRelativePos(relativePos1);
107
- const insertOp = this.client.insertSegmentLocal(pos, segment);
108
- if (insertOp) {
109
- this.submitSequenceMessage(insertOp);
110
- }
111
- }
112
-
113
- /**
114
- * {@inheritDoc ISharedString.insertMarker}
115
- */
116
- public insertMarker(
117
- pos: number,
118
- refType: ReferenceType,
119
- props?: PropertySet): IMergeTreeInsertMsg {
120
- const segment = new Marker(refType);
121
- if (props) {
122
- segment.addProperties(props);
123
- }
124
-
125
- const insertOp = this.client.insertSegmentLocal(pos, segment);
126
- if (insertOp) {
127
- this.submitSequenceMessage(insertOp);
128
- }
129
- return insertOp;
130
- }
131
-
132
- /**
133
- * Inserts the text at the position.
134
- * @param relativePos1 - The relative position to insert the text at
135
- * @param text - The text to insert
136
- * @param props - The properties of text
137
- */
138
- public insertTextRelative(relativePos1: IRelativePosition, text: string, props?: PropertySet) {
139
- const segment = new TextSegment(text);
140
- if (props) {
141
- segment.addProperties(props);
142
- }
143
-
144
- const pos = this.posFromRelativePos(relativePos1);
145
- const insertOp = this.client.insertSegmentLocal(pos, segment);
146
- if (insertOp) {
147
- this.submitSequenceMessage(insertOp);
148
- }
149
- }
150
-
151
- /**
152
- * {@inheritDoc ISharedString.insertText}
153
- */
154
- public insertText(pos: number, text: string, props?: PropertySet) {
155
- const segment = new TextSegment(text);
156
- if (props) {
157
- segment.addProperties(props);
158
- }
159
-
160
- const insertOp = this.client.insertSegmentLocal(pos, segment);
161
- if (insertOp) {
162
- this.submitSequenceMessage(insertOp);
163
- }
164
- }
165
-
166
- /**
167
- * Replaces a range with the provided text.
168
- * @param start - The inclusive start of the range to replace
169
- * @param end - The exclusive end of the range to replace
170
- * @param text - The text to replace the range with
171
- * @param props - Optional. The properties of the replacement text
172
- */
173
- public replaceText(start: number, end: number, text: string, props?: PropertySet) {
174
- this.replaceRange(start, end, TextSegment.make(text, props));
175
- }
176
-
177
- /**
178
- * Removes the text in the given range.
179
- * @param start - The inclusive start of the range to remove
180
- * @param end - The exclusive end of the range to replace
181
- * @returns the message sent.
182
- */
183
- public removeText(start: number, end: number): IMergeTreeRemoveMsg {
184
- return this.removeRange(start, end);
185
- }
186
-
187
- /**
188
- * Annotates the marker with the provided properties and calls the callback on consensus.
189
- * @param marker - The marker to annotate
190
- * @param props - The properties to annotate the marker with
191
- * @param consensusCallback - The callback called when consensus is reached
192
- */
193
- public annotateMarkerNotifyConsensus(
194
- marker: Marker,
195
- props: PropertySet,
196
- callback: (m: Marker) => void) {
197
- const annotateOp = this.client.annotateMarkerNotifyConsensus(marker, props, callback);
198
- if (annotateOp) {
199
- this.submitSequenceMessage(annotateOp);
200
- }
201
- }
202
-
203
- /**
204
- * Annotates the marker with the provided properties.
205
- * @param marker - The marker to annotate
206
- * @param props - The properties to annotate the marker with
207
- * @param combiningOp - Optional. Specifies how to combine values for the property, such as "incr" for increment.
208
- */
209
- public annotateMarker(
210
- marker: Marker,
211
- props: PropertySet,
212
- combiningOp?: ICombiningOp) {
213
- const annotateOp = this.client.annotateMarker(marker, props, combiningOp);
214
- if (annotateOp) {
215
- this.submitSequenceMessage(annotateOp);
216
- }
217
- }
218
-
219
- public findTile(startPos: number | undefined, tileLabel: string, preceding = true): {
220
- tile: ReferencePosition;
221
- pos: number;
222
- } {
223
- return this.client.findTile(startPos, tileLabel, preceding);
224
- }
225
-
226
- public getTextAndMarkers(label: string) {
227
- const segmentWindow = this.client.getCollabWindow();
228
- return this.mergeTreeTextHelper.getTextAndMarkers(segmentWindow.currentSeq, segmentWindow.clientId, label);
229
- }
230
-
231
- /**
232
- * Retrieve text from the SharedString in string format.
233
- * @param start - The starting index of the text to retrieve, or 0 if omitted.
234
- * @param end - The ending index of the text to retrieve, or the end of the string if omitted
235
- * @returns The requested text content as a string.
236
- */
237
- public getText(start?: number, end?: number) {
238
- const segmentWindow = this.client.getCollabWindow();
239
- return this.mergeTreeTextHelper.getText(segmentWindow.currentSeq, segmentWindow.clientId, "", start, end);
240
- }
241
-
242
- /**
243
- * Adds spaces for markers and handles, so that position calculations account for them.
244
- */
245
- public getTextWithPlaceholders() {
246
- const segmentWindow = this.client.getCollabWindow();
247
- return this.mergeTreeTextHelper.getText(segmentWindow.currentSeq, segmentWindow.clientId, " ");
248
- }
249
-
250
- public getTextRangeWithPlaceholders(start: number, end: number) {
251
- const segmentWindow = this.client.getCollabWindow();
252
- return this.mergeTreeTextHelper.getText(segmentWindow.currentSeq, segmentWindow.clientId, " ", start, end);
253
- }
254
-
255
- public getTextRangeWithMarkers(start: number, end: number) {
256
- const segmentWindow = this.client.getCollabWindow();
257
- return this.mergeTreeTextHelper.getText(segmentWindow.currentSeq, segmentWindow.clientId, "*", start, end);
258
- }
259
-
260
- public getMarkerFromId(id: string): ISegment {
261
- return this.client.getMarkerFromId(id);
262
- }
64
+ export class SharedString
65
+ extends SharedSegmentSequence<SharedStringSegment>
66
+ implements ISharedString
67
+ {
68
+ /**
69
+ * Create a new shared string.
70
+ * @param runtime - data store runtime the new shared string belongs to
71
+ * @param id - optional name of the shared string
72
+ * @returns newly create shared string (but not attached yet)
73
+ */
74
+ public static create(runtime: IFluidDataStoreRuntime, id?: string) {
75
+ return runtime.createChannel(id, SharedStringFactory.Type) as SharedString;
76
+ }
77
+
78
+ /**
79
+ * Get a factory for SharedString to register with the data store.
80
+ * @returns a factory that creates and load SharedString
81
+ */
82
+ public static getFactory() {
83
+ return new SharedStringFactory();
84
+ }
85
+
86
+ public get ISharedString(): ISharedString {
87
+ return this;
88
+ }
89
+
90
+ private readonly mergeTreeTextHelper: IMergeTreeTextHelper;
91
+
92
+ constructor(
93
+ document: IFluidDataStoreRuntime,
94
+ public id: string,
95
+ attributes: IChannelAttributes,
96
+ ) {
97
+ super(document, id, attributes, SharedStringFactory.segmentFromSpec as any);
98
+ this.mergeTreeTextHelper = this.client.createTextHelper();
99
+ }
100
+
101
+ /**
102
+ * Inserts a marker at a relative position.
103
+ * @param relativePos1 - The relative position to insert the marker at
104
+ * @param refType - The reference type of the marker
105
+ * @param props - The properties of the marker
106
+ */
107
+ public insertMarkerRelative(
108
+ relativePos1: IRelativePosition,
109
+ refType: ReferenceType,
110
+ props?: PropertySet,
111
+ ): void {
112
+ const segment = new Marker(refType);
113
+ if (props) {
114
+ segment.addProperties(props);
115
+ }
116
+
117
+ const pos = this.posFromRelativePos(relativePos1);
118
+ this.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));
119
+ }
120
+
121
+ /**
122
+ * {@inheritDoc ISharedString.insertMarker}
123
+ */
124
+ public insertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void {
125
+ const segment = new Marker(refType);
126
+ if (props) {
127
+ segment.addProperties(props);
128
+ }
129
+
130
+ this.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));
131
+ }
132
+
133
+ /**
134
+ * Inserts the text at the position.
135
+ * @param relativePos1 - The relative position to insert the text at
136
+ * @param text - The text to insert
137
+ * @param props - The properties of text
138
+ */
139
+ public insertTextRelative(
140
+ relativePos1: IRelativePosition,
141
+ text: string,
142
+ props?: PropertySet,
143
+ ): void {
144
+ const segment = new TextSegment(text);
145
+ if (props) {
146
+ segment.addProperties(props);
147
+ }
148
+
149
+ const pos = this.posFromRelativePos(relativePos1);
150
+ this.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));
151
+ }
152
+
153
+ /**
154
+ * {@inheritDoc ISharedString.insertText}
155
+ */
156
+ public insertText(pos: number, text: string, props?: PropertySet): void {
157
+ const segment = new TextSegment(text);
158
+ if (props) {
159
+ segment.addProperties(props);
160
+ }
161
+
162
+ this.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));
163
+ }
164
+
165
+ /**
166
+ * Replaces a range with the provided text.
167
+ * @param start - The inclusive start of the range to replace
168
+ * @param end - The exclusive end of the range to replace
169
+ * @param text - The text to replace the range with
170
+ * @param props - Optional. The properties of the replacement text
171
+ */
172
+ public replaceText(start: number, end: number, text: string, props?: PropertySet): void {
173
+ this.replaceRange(start, end, TextSegment.make(text, props));
174
+ }
175
+
176
+ /**
177
+ * Removes the text in the given range.
178
+ * @param start - The inclusive start of the range to remove
179
+ * @param end - The exclusive end of the range to replace
180
+ * @returns the message sent.
181
+ */
182
+ public removeText(start: number, end: number): void {
183
+ this.removeRange(start, end);
184
+ }
185
+
186
+ /**
187
+ * Annotates the marker with the provided properties.
188
+ * @param marker - The marker to annotate
189
+ * @param props - The properties to annotate the marker with
190
+ */
191
+ public annotateMarker(marker: Marker, props: PropertySet) {
192
+ this.guardReentrancy(() => this.client.annotateMarker(marker, props));
193
+ }
194
+
195
+ /**
196
+ * Finds the nearest reference with ReferenceType.Tile to `startPos` in the direction dictated by `tilePrecedesPos`.
197
+ * Note that Markers receive `ReferenceType.Tile` by default.
198
+ * @deprecated Use `searchForMarker` instead.
199
+ * @param startPos - Position at which to start the search
200
+ * @param clientId - clientId dictating the perspective to search from
201
+ * @param tileLabel - Label of the tile to search for
202
+ * @param preceding - Whether the desired tile comes before (true) or after (false) `startPos`
203
+ */
204
+ public findTile(
205
+ startPos: number | undefined,
206
+ tileLabel: string,
207
+ preceding = true,
208
+ ):
209
+ | {
210
+ tile: ReferencePosition;
211
+ pos: number;
212
+ }
213
+ | undefined {
214
+ return this.client.findTile(startPos ?? 0, tileLabel, preceding);
215
+ }
216
+
217
+ /**
218
+ * Searches a string for the nearest marker in either direction to a given start position.
219
+ * The search will include the start position, so markers at the start position are valid
220
+ * results of the search.
221
+ * @param startPos - Position at which to start the search
222
+ * @param markerLabel - Label of the marker to search for
223
+ * @param forwards - Whether the desired marker comes before (false) or after (true) `startPos`
224
+ */
225
+ public searchForMarker(
226
+ startPos: number,
227
+ markerLabel: string,
228
+ forwards = true,
229
+ ): Marker | undefined {
230
+ return this.client.searchForMarker(startPos, markerLabel, forwards);
231
+ }
232
+
233
+ /**
234
+ * Retrieve text from the SharedString in string format.
235
+ * @param start - The starting index of the text to retrieve, or 0 if omitted.
236
+ * @param end - The ending index of the text to retrieve, or the end of the string if omitted
237
+ * @returns The requested text content as a string.
238
+ */
239
+ public getText(start?: number, end?: number) {
240
+ const segmentWindow = this.client.getCollabWindow();
241
+ return this.mergeTreeTextHelper.getText(
242
+ segmentWindow.currentSeq,
243
+ segmentWindow.clientId,
244
+ "",
245
+ start,
246
+ end,
247
+ );
248
+ }
249
+
250
+ /**
251
+ * Adds spaces for markers and handles, so that position calculations account for them.
252
+ */
253
+ public getTextWithPlaceholders(start?: number, end?: number) {
254
+ const segmentWindow = this.client.getCollabWindow();
255
+ return this.mergeTreeTextHelper.getText(
256
+ segmentWindow.currentSeq,
257
+ segmentWindow.clientId,
258
+ " ",
259
+ start,
260
+ end,
261
+ );
262
+ }
263
+
264
+ public getTextRangeWithMarkers(start: number, end: number) {
265
+ const segmentWindow = this.client.getCollabWindow();
266
+ return this.mergeTreeTextHelper.getText(
267
+ segmentWindow.currentSeq,
268
+ segmentWindow.clientId,
269
+ "*",
270
+ start,
271
+ end,
272
+ );
273
+ }
274
+
275
+ /**
276
+ * Looks up and returns a `Marker` using its id. Returns `undefined` if there is no marker with the provided
277
+ * id in this `SharedString`.
278
+ */
279
+ public getMarkerFromId(id: string): ISegment | undefined {
280
+ return this.client.getMarkerFromId(id);
281
+ }
282
+
283
+ /**
284
+ * Revert an op
285
+ */
286
+ protected rollback(content: any, localOpMetadata: unknown): void {
287
+ if (this.client.rollback !== undefined) {
288
+ this.client.rollback(content, localOpMetadata);
289
+ } else {
290
+ super.rollback(content, localOpMetadata);
291
+ }
292
+ }
293
+ }
294
+
295
+ interface ITextAndMarkerAccumulator {
296
+ parallelText: string[];
297
+ parallelMarkers: Marker[];
298
+ parallelMarkerLabel: string;
299
+ placeholder?: string;
300
+ tagsInProgress: string[];
301
+ textSegment: TextSegment;
263
302
  }
303
+
304
+ /**
305
+ * Splits the text into regions ending with markers with the given `label`.
306
+ * @param sharedString - String to retrieve text and markers from
307
+ * @param label - label to split on
308
+ * @returns Two parallel lists of text and markers, split by markers with the provided `label`.
309
+ * For example:
310
+ * ```typescript
311
+ * // Say sharedstring has contents "hello<paragraph marker 1>world<paragraph marker 2>missing".
312
+ * const { parallelText, parallelMarkers } = getTextAndMarkers(sharedString, "paragraph");
313
+ * // parallelText === ["hello", "world"]
314
+ * // parallelMarkers === [<paragraph marker 1 object>, <paragraph marker 2 object>]
315
+ * // Note parallelText does not include "missing".
316
+ * ```
317
+ * @internal
318
+ */
319
+ export function getTextAndMarkers(
320
+ sharedString: SharedString,
321
+ label: string,
322
+ start?: number,
323
+ end?: number,
324
+ ): {
325
+ parallelText: string[];
326
+ parallelMarkers: Marker[];
327
+ } {
328
+ const accum: ITextAndMarkerAccumulator = {
329
+ parallelMarkerLabel: label,
330
+ parallelMarkers: [],
331
+ parallelText: [],
332
+ tagsInProgress: [],
333
+ textSegment: new TextSegment(""),
334
+ };
335
+
336
+ sharedString.walkSegments(gatherTextAndMarkers, start, end, accum);
337
+ return { parallelText: accum.parallelText, parallelMarkers: accum.parallelMarkers };
338
+ }
339
+
340
+ const gatherTextAndMarkers: ISegmentAction<ITextAndMarkerAccumulator> = (
341
+ segment: ISegment,
342
+ pos: number,
343
+ refSeq: number,
344
+ clientId: number,
345
+ start: number,
346
+ end: number,
347
+ accumText: ITextAndMarkerAccumulator,
348
+ ) => {
349
+ const { placeholder, tagsInProgress, textSegment } = accumText;
350
+ if (TextSegment.is(segment)) {
351
+ let beginTags = "";
352
+ let endTags = "";
353
+ // TODO: let clients pass in function to get tag
354
+ const tags = [] as string[];
355
+ const initTags = [] as string[];
356
+
357
+ if (segment.properties?.["font-weight"]) {
358
+ tags.push("b");
359
+ }
360
+ if (segment.properties?.["text-decoration"]) {
361
+ tags.push("u");
362
+ }
363
+ const remTags = [] as string[];
364
+ if (tags.length > 0) {
365
+ for (const tag of tags) {
366
+ if (!tagsInProgress.includes(tag)) {
367
+ beginTags += `<${tag}>`;
368
+ initTags.push(tag);
369
+ }
370
+ }
371
+ for (const accumTag of tagsInProgress) {
372
+ if (!tags.includes(accumTag)) {
373
+ endTags += `</${accumTag}>`;
374
+ remTags.push(accumTag);
375
+ }
376
+ }
377
+ for (const initTag of initTags.reverse()) {
378
+ tagsInProgress.push(initTag);
379
+ }
380
+ } else {
381
+ for (const accumTag of tagsInProgress) {
382
+ endTags += `</${accumTag}>`;
383
+ remTags.push(accumTag);
384
+ }
385
+ }
386
+ for (const remTag of remTags) {
387
+ const remdex = tagsInProgress.indexOf(remTag);
388
+ if (remdex >= 0) {
389
+ tagsInProgress.splice(remdex, 1);
390
+ }
391
+ }
392
+ textSegment.text += endTags;
393
+ textSegment.text += beginTags;
394
+ if (start <= 0 && end >= segment.text.length) {
395
+ textSegment.text += segment.text;
396
+ } else {
397
+ const seglen = segment.text.length;
398
+ const _start = start < 0 ? 0 : start;
399
+ const _end = end >= seglen ? undefined : end;
400
+ textSegment.text += segment.text.substring(_start, _end);
401
+ }
402
+ } else {
403
+ if (placeholder && placeholder.length > 0) {
404
+ const placeholderText =
405
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
406
+ placeholder === "*" ? `\n${segment}` : placeholder.repeat(segment.cachedLength);
407
+ textSegment.text += placeholderText;
408
+ } else {
409
+ const marker = segment as Marker;
410
+ if (refHasTileLabel(marker, accumText.parallelMarkerLabel)) {
411
+ accumText.parallelMarkers.push(marker);
412
+ accumText.parallelText.push(textSegment.text);
413
+ textSegment.text = "";
414
+ }
415
+ }
416
+ }
417
+
418
+ return true;
419
+ };
@@ -0,0 +1,10 @@
1
+ {
2
+ "targets": [
3
+ {
4
+ "extname": ".cjs",
5
+ "module": "Node16",
6
+ "moduleResolution": "Node16"
7
+ }
8
+ ],
9
+ "projects": ["./tsconfig.json", "./src/test/tsconfig.json"]
10
+ }