@y/y 14.0.0-19 → 14.0.0-20

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 (129) hide show
  1. package/README.md +7 -5
  2. package/dist/src/index.d.ts +2 -1
  3. package/dist/src/internals.d.ts +2 -9
  4. package/dist/src/structs/ContentType.d.ts +6 -12
  5. package/dist/src/structs/ContentType.d.ts.map +1 -1
  6. package/dist/src/structs/Item.d.ts +5 -6
  7. package/dist/src/structs/Item.d.ts.map +1 -1
  8. package/dist/src/utils/AttributionManager.d.ts +16 -14
  9. package/dist/src/utils/AttributionManager.d.ts.map +1 -1
  10. package/dist/src/utils/Doc.d.ts +7 -70
  11. package/dist/src/utils/Doc.d.ts.map +1 -1
  12. package/dist/src/utils/ID.d.ts +2 -2
  13. package/dist/src/utils/ID.d.ts.map +1 -1
  14. package/dist/src/utils/IdMap.d.ts +19 -16
  15. package/dist/src/utils/IdMap.d.ts.map +1 -1
  16. package/dist/src/utils/IdSet.d.ts +2 -2
  17. package/dist/src/utils/IdSet.d.ts.map +1 -1
  18. package/dist/src/utils/RelativePosition.d.ts +8 -8
  19. package/dist/src/utils/RelativePosition.d.ts.map +1 -1
  20. package/dist/src/utils/Transaction.d.ts +9 -5
  21. package/dist/src/utils/Transaction.d.ts.map +1 -1
  22. package/dist/src/utils/UndoManager.d.ts +14 -12
  23. package/dist/src/utils/UndoManager.d.ts.map +1 -1
  24. package/dist/src/utils/UpdateEncoder.d.ts +2 -0
  25. package/dist/src/utils/UpdateEncoder.d.ts.map +1 -1
  26. package/dist/src/utils/YEvent.d.ts +21 -42
  27. package/dist/src/utils/YEvent.d.ts.map +1 -1
  28. package/dist/src/utils/isParentOf.d.ts +1 -1
  29. package/dist/src/utils/isParentOf.d.ts.map +1 -1
  30. package/dist/src/utils/logging.d.ts +2 -2
  31. package/dist/src/utils/logging.d.ts.map +1 -1
  32. package/dist/src/utils/meta.d.ts +43 -0
  33. package/dist/src/utils/meta.d.ts.map +1 -0
  34. package/dist/src/utils/ts.d.ts +4 -0
  35. package/dist/src/utils/ts.d.ts.map +1 -0
  36. package/dist/src/utils/updates.d.ts +3 -9
  37. package/dist/src/utils/updates.d.ts.map +1 -1
  38. package/dist/src/ytype.d.ts +498 -0
  39. package/dist/src/ytype.d.ts.map +1 -0
  40. package/dist/tests/IdMap.tests.d.ts.map +1 -1
  41. package/dist/tests/attribution.tests.d.ts +1 -0
  42. package/dist/tests/attribution.tests.d.ts.map +1 -1
  43. package/dist/tests/compatibility.tests.d.ts.map +1 -1
  44. package/dist/tests/doc.tests.d.ts.map +1 -1
  45. package/dist/tests/relativePositions.tests.d.ts +9 -9
  46. package/dist/tests/relativePositions.tests.d.ts.map +1 -1
  47. package/dist/tests/snapshot.tests.d.ts.map +1 -1
  48. package/dist/tests/testHelper.d.ts +28 -27
  49. package/dist/tests/testHelper.d.ts.map +1 -1
  50. package/dist/tests/undo-redo.tests.d.ts.map +1 -1
  51. package/dist/tests/updates.tests.d.ts +1 -1
  52. package/dist/tests/updates.tests.d.ts.map +1 -1
  53. package/dist/tests/y-array.tests.d.ts +0 -2
  54. package/dist/tests/y-array.tests.d.ts.map +1 -1
  55. package/dist/tests/y-map.tests.d.ts +0 -3
  56. package/dist/tests/y-map.tests.d.ts.map +1 -1
  57. package/dist/tests/y-text.tests.d.ts +1 -1
  58. package/dist/tests/y-text.tests.d.ts.map +1 -1
  59. package/dist/tests/y-xml.tests.d.ts +0 -1
  60. package/dist/tests/y-xml.tests.d.ts.map +1 -1
  61. package/package.json +16 -16
  62. package/src/index.js +152 -0
  63. package/src/internals.js +35 -0
  64. package/src/structs/AbstractStruct.js +59 -0
  65. package/src/structs/ContentAny.js +115 -0
  66. package/src/structs/ContentBinary.js +93 -0
  67. package/src/structs/ContentDeleted.js +101 -0
  68. package/src/structs/ContentDoc.js +141 -0
  69. package/src/structs/ContentEmbed.js +98 -0
  70. package/src/structs/ContentFormat.js +105 -0
  71. package/src/structs/ContentJSON.js +119 -0
  72. package/src/structs/ContentString.js +113 -0
  73. package/src/structs/ContentType.js +152 -0
  74. package/src/structs/GC.js +80 -0
  75. package/src/structs/Item.js +841 -0
  76. package/src/structs/Skip.js +75 -0
  77. package/src/utils/AttributionManager.js +653 -0
  78. package/src/utils/Doc.js +266 -0
  79. package/src/utils/EventHandler.js +87 -0
  80. package/src/utils/ID.js +89 -0
  81. package/src/utils/IdMap.js +673 -0
  82. package/src/utils/IdSet.js +825 -0
  83. package/src/utils/RelativePosition.js +352 -0
  84. package/src/utils/Snapshot.js +220 -0
  85. package/src/utils/StructSet.js +137 -0
  86. package/src/utils/StructStore.js +289 -0
  87. package/src/utils/Transaction.js +671 -0
  88. package/src/utils/UndoManager.js +406 -0
  89. package/src/utils/UpdateDecoder.js +281 -0
  90. package/src/utils/UpdateEncoder.js +327 -0
  91. package/src/utils/YEvent.js +189 -0
  92. package/src/utils/delta-helpers.js +54 -0
  93. package/src/utils/encoding.js +623 -0
  94. package/src/utils/isParentOf.js +21 -0
  95. package/src/utils/logging.js +21 -0
  96. package/src/utils/meta.js +97 -0
  97. package/src/utils/ts.js +3 -0
  98. package/src/utils/updates.js +711 -0
  99. package/src/ytype.js +1962 -0
  100. package/dist/Skip-CE05BUF8.js +0 -11875
  101. package/dist/Skip-CE05BUF8.js.map +0 -1
  102. package/dist/index-C21sDQ5u.js +0 -163
  103. package/dist/index-C21sDQ5u.js.map +0 -1
  104. package/dist/internals.js +0 -25
  105. package/dist/internals.js.map +0 -1
  106. package/dist/src/types/AbstractType.d.ts +0 -239
  107. package/dist/src/types/AbstractType.d.ts.map +0 -1
  108. package/dist/src/types/YArray.d.ts +0 -128
  109. package/dist/src/types/YArray.d.ts.map +0 -1
  110. package/dist/src/types/YMap.d.ts +0 -112
  111. package/dist/src/types/YMap.d.ts.map +0 -1
  112. package/dist/src/types/YText.d.ts +0 -216
  113. package/dist/src/types/YText.d.ts.map +0 -1
  114. package/dist/src/types/YXmlElement.d.ts +0 -106
  115. package/dist/src/types/YXmlElement.d.ts.map +0 -1
  116. package/dist/src/types/YXmlFragment.d.ts +0 -143
  117. package/dist/src/types/YXmlFragment.d.ts.map +0 -1
  118. package/dist/src/types/YXmlHook.d.ts +0 -32
  119. package/dist/src/types/YXmlHook.d.ts.map +0 -1
  120. package/dist/src/types/YXmlText.d.ts +0 -34
  121. package/dist/src/types/YXmlText.d.ts.map +0 -1
  122. package/dist/src/utils/AbstractConnector.d.ts +0 -20
  123. package/dist/src/utils/AbstractConnector.d.ts.map +0 -1
  124. package/dist/src/utils/types.d.ts +0 -7
  125. package/dist/src/utils/types.d.ts.map +0 -1
  126. package/dist/testHelper.js +0 -617
  127. package/dist/testHelper.js.map +0 -1
  128. package/dist/yjs.js +0 -26
  129. package/dist/yjs.js.map +0 -1
@@ -0,0 +1,152 @@
1
+ import {
2
+ UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Transaction, Item // eslint-disable-line
3
+ } from '../internals.js'
4
+
5
+ import * as error from 'lib0/error'
6
+ import { readYType } from '../ytype.js'
7
+
8
+ export const YArrayRefID = 0
9
+ export const YMapRefID = 1
10
+ export const YTextRefID = 2
11
+ export const YXmlElementRefID = 3
12
+ export const YXmlFragmentRefID = 4
13
+ export const YXmlHookRefID = 5
14
+ export const YXmlTextRefID = 6
15
+
16
+ /**
17
+ * @private
18
+ */
19
+ export class ContentType {
20
+ /**
21
+ * @param {import('../ytype.js').YType} type
22
+ */
23
+ constructor (type) {
24
+ /**
25
+ * @type {import('../ytype.js').YType}
26
+ */
27
+ this.type = type
28
+ }
29
+
30
+ /**
31
+ * @return {number}
32
+ */
33
+ getLength () {
34
+ return 1
35
+ }
36
+
37
+ /**
38
+ * @return {Array<any>}
39
+ */
40
+ getContent () {
41
+ return [this.type]
42
+ }
43
+
44
+ /**
45
+ * @return {boolean}
46
+ */
47
+ isCountable () {
48
+ return true
49
+ }
50
+
51
+ /**
52
+ * @return {ContentType}
53
+ */
54
+ copy () {
55
+ return new ContentType(this.type._copy())
56
+ }
57
+
58
+ /**
59
+ * @param {number} _offset
60
+ * @return {ContentType}
61
+ */
62
+ splice (_offset) {
63
+ throw error.methodUnimplemented()
64
+ }
65
+
66
+ /**
67
+ * @param {ContentType} _right
68
+ * @return {boolean}
69
+ */
70
+ mergeWith (_right) {
71
+ return false
72
+ }
73
+
74
+ /**
75
+ * @param {Transaction} transaction
76
+ * @param {Item} item
77
+ */
78
+ integrate (transaction, item) {
79
+ this.type._integrate(transaction.doc, item)
80
+ }
81
+
82
+ /**
83
+ * @param {Transaction} transaction
84
+ */
85
+ delete (transaction) {
86
+ let item = this.type._start
87
+ while (item !== null) {
88
+ if (!item.deleted) {
89
+ item.delete(transaction)
90
+ } else if (!transaction.insertSet.hasId(item.id)) {
91
+ // This will be gc'd later and we want to merge it if possible
92
+ // We try to merge all deleted items after each transaction,
93
+ // but we have no knowledge about that this needs to be merged
94
+ // since it is not in transaction.ds. Hence we add it to transaction._mergeStructs
95
+ transaction._mergeStructs.push(item)
96
+ }
97
+ item = item.right
98
+ }
99
+ this.type._map.forEach(item => {
100
+ if (!item.deleted) {
101
+ item.delete(transaction)
102
+ } else if (!transaction.insertSet.hasId(item.id)) {
103
+ // same as above
104
+ transaction._mergeStructs.push(item)
105
+ }
106
+ })
107
+ transaction.changed.delete(this.type)
108
+ }
109
+
110
+ /**
111
+ * @param {Transaction} tr
112
+ */
113
+ gc (tr) {
114
+ let item = this.type._start
115
+ while (item !== null) {
116
+ item.gc(tr, true)
117
+ item = item.right
118
+ }
119
+ this.type._start = null
120
+ this.type._map.forEach(/** @param {Item | null} item */ (item) => {
121
+ while (item !== null) {
122
+ item.gc(tr, true)
123
+ item = item.left
124
+ }
125
+ })
126
+ this.type._map = new Map()
127
+ }
128
+
129
+ /**
130
+ * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
131
+ * @param {number} _offset
132
+ * @param {number} _offsetEnd
133
+ */
134
+ write (encoder, _offset, _offsetEnd) {
135
+ this.type._write(encoder)
136
+ }
137
+
138
+ /**
139
+ * @return {number}
140
+ */
141
+ getRef () {
142
+ return 7
143
+ }
144
+ }
145
+
146
+ /**
147
+ * @private
148
+ *
149
+ * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
150
+ * @return {ContentType}
151
+ */
152
+ export const readContentType = decoder => new ContentType(readYType(decoder))
@@ -0,0 +1,80 @@
1
+ import {
2
+ AbstractStruct,
3
+ addStruct,
4
+ addStructToIdSet,
5
+ addToIdSet,
6
+ createID,
7
+ UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction // eslint-disable-line
8
+ } from '../internals.js'
9
+
10
+ export const structGCRefNumber = 0
11
+
12
+ /**
13
+ * @private
14
+ */
15
+ export class GC extends AbstractStruct {
16
+ get deleted () {
17
+ return true
18
+ }
19
+
20
+ delete () {}
21
+
22
+ /**
23
+ * @param {GC} right
24
+ * @return {boolean}
25
+ */
26
+ mergeWith (right) {
27
+ if (this.constructor !== right.constructor) {
28
+ return false
29
+ }
30
+ this.length += right.length
31
+ return true
32
+ }
33
+
34
+ /**
35
+ * @param {Transaction} transaction
36
+ * @param {number} offset - @todo remove offset parameter
37
+ */
38
+ integrate (transaction, offset) {
39
+ if (offset > 0) {
40
+ this.id.clock += offset
41
+ this.length -= offset
42
+ }
43
+ addToIdSet(transaction.deleteSet, this.id.client, this.id.clock, this.length)
44
+ addStructToIdSet(transaction.insertSet, this)
45
+ addStruct(transaction.doc.store, this)
46
+ }
47
+
48
+ /**
49
+ * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
50
+ * @param {number} offset
51
+ * @param {number} offsetEnd
52
+ */
53
+ write (encoder, offset, offsetEnd) {
54
+ encoder.writeInfo(structGCRefNumber)
55
+ encoder.writeLen(this.length - offset - offsetEnd)
56
+ }
57
+
58
+ /**
59
+ * @param {Transaction} _transaction
60
+ * @param {StructStore} _store
61
+ * @return {null | number}
62
+ */
63
+ getMissing (_transaction, _store) {
64
+ return null
65
+ }
66
+
67
+ /**
68
+ * gc structs can't be spliced.
69
+ *
70
+ * If this feature is required in the future, then need to try to merge this struct after
71
+ * transaction.
72
+ *
73
+ * @param {number} diff
74
+ */
75
+ splice (diff) {
76
+ const other = new GC(createID(this.id.client, this.id.clock + diff), this.length - diff)
77
+ this.length = diff
78
+ return other
79
+ }
80
+ }