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

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