@y/y 14.0.0-16
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.
- package/LICENSE +23 -0
- package/README.md +1406 -0
- package/dist/Skip-j0kX7pdq.js +12173 -0
- package/dist/Skip-j0kX7pdq.js.map +1 -0
- package/dist/Skip-wRT7BKFP.js +11877 -0
- package/dist/Skip-wRT7BKFP.js.map +1 -0
- package/dist/index-DyTeTfmj.js +163 -0
- package/dist/index-DyTeTfmj.js.map +1 -0
- package/dist/index-R7GxO-36.js +165 -0
- package/dist/index-R7GxO-36.js.map +1 -0
- package/dist/internals.cjs +286 -0
- package/dist/internals.cjs.map +1 -0
- package/dist/internals.mjs +25 -0
- package/dist/internals.mjs.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/internals.d.ts +43 -0
- package/dist/src/internals.d.ts.map +1 -0
- package/dist/src/structs/AbstractStruct.d.ts +42 -0
- package/dist/src/structs/AbstractStruct.d.ts.map +1 -0
- package/dist/src/structs/ContentAny.d.ts +67 -0
- package/dist/src/structs/ContentAny.d.ts.map +1 -0
- package/dist/src/structs/ContentBinary.d.ts +64 -0
- package/dist/src/structs/ContentBinary.d.ts.map +1 -0
- package/dist/src/structs/ContentDeleted.d.ts +64 -0
- package/dist/src/structs/ContentDeleted.d.ts.map +1 -0
- package/dist/src/structs/ContentDoc.d.ts +72 -0
- package/dist/src/structs/ContentDoc.d.ts.map +1 -0
- package/dist/src/structs/ContentEmbed.d.ts +67 -0
- package/dist/src/structs/ContentEmbed.d.ts.map +1 -0
- package/dist/src/structs/ContentFormat.d.ts +69 -0
- package/dist/src/structs/ContentFormat.d.ts.map +1 -0
- package/dist/src/structs/ContentJSON.d.ts +70 -0
- package/dist/src/structs/ContentJSON.d.ts.map +1 -0
- package/dist/src/structs/ContentString.d.ts +70 -0
- package/dist/src/structs/ContentString.d.ts.map +1 -0
- package/dist/src/structs/ContentType.d.ts +83 -0
- package/dist/src/structs/ContentType.d.ts.map +1 -0
- package/dist/src/structs/GC.d.ts +31 -0
- package/dist/src/structs/GC.d.ts.map +1 -0
- package/dist/src/structs/Item.d.ts +212 -0
- package/dist/src/structs/Item.d.ts.map +1 -0
- package/dist/src/structs/Skip.d.ts +33 -0
- package/dist/src/structs/Skip.d.ts.map +1 -0
- package/dist/src/types/AbstractType.d.ts +239 -0
- package/dist/src/types/AbstractType.d.ts.map +1 -0
- package/dist/src/types/YArray.d.ts +128 -0
- package/dist/src/types/YArray.d.ts.map +1 -0
- package/dist/src/types/YMap.d.ts +112 -0
- package/dist/src/types/YMap.d.ts.map +1 -0
- package/dist/src/types/YText.d.ts +216 -0
- package/dist/src/types/YText.d.ts.map +1 -0
- package/dist/src/types/YXmlElement.d.ts +106 -0
- package/dist/src/types/YXmlElement.d.ts.map +1 -0
- package/dist/src/types/YXmlFragment.d.ts +143 -0
- package/dist/src/types/YXmlFragment.d.ts.map +1 -0
- package/dist/src/types/YXmlHook.d.ts +32 -0
- package/dist/src/types/YXmlHook.d.ts.map +1 -0
- package/dist/src/types/YXmlText.d.ts +34 -0
- package/dist/src/types/YXmlText.d.ts.map +1 -0
- package/dist/src/utils/AbstractConnector.d.ts +20 -0
- package/dist/src/utils/AbstractConnector.d.ts.map +1 -0
- package/dist/src/utils/AttributionManager.d.ts +224 -0
- package/dist/src/utils/AttributionManager.d.ts.map +1 -0
- package/dist/src/utils/Doc.d.ts +267 -0
- package/dist/src/utils/Doc.d.ts.map +1 -0
- package/dist/src/utils/EventHandler.d.ts +19 -0
- package/dist/src/utils/EventHandler.d.ts.map +1 -0
- package/dist/src/utils/ID.d.ts +26 -0
- package/dist/src/utils/ID.d.ts.map +1 -0
- package/dist/src/utils/IdMap.d.ts +161 -0
- package/dist/src/utils/IdMap.d.ts.map +1 -0
- package/dist/src/utils/IdSet.d.ts +163 -0
- package/dist/src/utils/IdSet.d.ts.map +1 -0
- package/dist/src/utils/RelativePosition.d.ts +91 -0
- package/dist/src/utils/RelativePosition.d.ts.map +1 -0
- package/dist/src/utils/Snapshot.d.ts +40 -0
- package/dist/src/utils/Snapshot.d.ts.map +1 -0
- package/dist/src/utils/StructSet.d.ts +27 -0
- package/dist/src/utils/StructSet.d.ts.map +1 -0
- package/dist/src/utils/StructStore.d.ts +41 -0
- package/dist/src/utils/StructStore.d.ts.map +1 -0
- package/dist/src/utils/Transaction.d.ts +136 -0
- package/dist/src/utils/Transaction.d.ts.map +1 -0
- package/dist/src/utils/UndoManager.d.ts +188 -0
- package/dist/src/utils/UndoManager.d.ts.map +1 -0
- package/dist/src/utils/UpdateDecoder.d.ts +167 -0
- package/dist/src/utils/UpdateDecoder.d.ts.map +1 -0
- package/dist/src/utils/UpdateEncoder.d.ts +164 -0
- package/dist/src/utils/UpdateEncoder.d.ts.map +1 -0
- package/dist/src/utils/YEvent.d.ts +120 -0
- package/dist/src/utils/YEvent.d.ts.map +1 -0
- package/dist/src/utils/delta-helpers.d.ts +6 -0
- package/dist/src/utils/delta-helpers.d.ts.map +1 -0
- package/dist/src/utils/encoding.d.ts +30 -0
- package/dist/src/utils/encoding.d.ts.map +1 -0
- package/dist/src/utils/isParentOf.d.ts +3 -0
- package/dist/src/utils/isParentOf.d.ts.map +1 -0
- package/dist/src/utils/logging.d.ts +3 -0
- package/dist/src/utils/logging.d.ts.map +1 -0
- package/dist/src/utils/types.d.ts +7 -0
- package/dist/src/utils/types.d.ts.map +1 -0
- package/dist/src/utils/updates.d.ts +89 -0
- package/dist/src/utils/updates.d.ts.map +1 -0
- package/dist/testHelper.cjs +780 -0
- package/dist/testHelper.cjs.map +1 -0
- package/dist/testHelper.mjs +617 -0
- package/dist/testHelper.mjs.map +1 -0
- package/dist/tests/IdMap.tests.d.ts +9 -0
- package/dist/tests/IdMap.tests.d.ts.map +1 -0
- package/dist/tests/IdSet.tests.d.ts +9 -0
- package/dist/tests/IdSet.tests.d.ts.map +1 -0
- package/dist/tests/attribution.tests.d.ts +8 -0
- package/dist/tests/attribution.tests.d.ts.map +1 -0
- package/dist/tests/compatibility.tests.d.ts +5 -0
- package/dist/tests/compatibility.tests.d.ts.map +1 -0
- package/dist/tests/delta.tests.d.ts +7 -0
- package/dist/tests/delta.tests.d.ts.map +1 -0
- package/dist/tests/doc.tests.d.ts +13 -0
- package/dist/tests/doc.tests.d.ts.map +1 -0
- package/dist/tests/encoding.tests.d.ts +5 -0
- package/dist/tests/encoding.tests.d.ts.map +1 -0
- package/dist/tests/index.d.ts +2 -0
- package/dist/tests/index.d.ts.map +1 -0
- package/dist/tests/relativePositions.tests.d.ts +11 -0
- package/dist/tests/relativePositions.tests.d.ts.map +1 -0
- package/dist/tests/snapshot.tests.d.ts +13 -0
- package/dist/tests/snapshot.tests.d.ts.map +1 -0
- package/dist/tests/testHelper.d.ts +167 -0
- package/dist/tests/testHelper.d.ts.map +1 -0
- package/dist/tests/undo-redo.tests.d.ts +27 -0
- package/dist/tests/undo-redo.tests.d.ts.map +1 -0
- package/dist/tests/updates.tests.d.ts +24 -0
- package/dist/tests/updates.tests.d.ts.map +1 -0
- package/dist/tests/y-array.tests.d.ts +45 -0
- package/dist/tests/y-array.tests.d.ts.map +1 -0
- package/dist/tests/y-map.tests.d.ts +45 -0
- package/dist/tests/y-map.tests.d.ts.map +1 -0
- package/dist/tests/y-text.tests.d.ts +49 -0
- package/dist/tests/y-text.tests.d.ts.map +1 -0
- package/dist/tests/y-xml.tests.d.ts +15 -0
- package/dist/tests/y-xml.tests.d.ts.map +1 -0
- package/dist/yjs.cjs +151 -0
- package/dist/yjs.cjs.map +1 -0
- package/dist/yjs.mjs +26 -0
- package/dist/yjs.mjs.map +1 -0
- package/package.json +101 -0
- package/src/index.js +153 -0
- package/src/internals.js +44 -0
- package/src/structs/AbstractStruct.js +59 -0
- package/src/structs/ContentAny.js +115 -0
- package/src/structs/ContentBinary.js +93 -0
- package/src/structs/ContentDeleted.js +101 -0
- package/src/structs/ContentDoc.js +141 -0
- package/src/structs/ContentEmbed.js +98 -0
- package/src/structs/ContentFormat.js +105 -0
- package/src/structs/ContentJSON.js +119 -0
- package/src/structs/ContentString.js +113 -0
- package/src/structs/ContentType.js +176 -0
- package/src/structs/GC.js +80 -0
- package/src/structs/Item.js +845 -0
- package/src/structs/Skip.js +75 -0
- package/src/types/AbstractType.js +1434 -0
- package/src/types/YArray.js +270 -0
- package/src/types/YMap.js +244 -0
- package/src/types/YText.js +934 -0
- package/src/types/YXmlElement.js +227 -0
- package/src/types/YXmlFragment.js +266 -0
- package/src/types/YXmlHook.js +68 -0
- package/src/types/YXmlText.js +66 -0
- package/src/utils/AbstractConnector.js +25 -0
- package/src/utils/AttributionManager.js +619 -0
- package/src/utils/Doc.js +372 -0
- package/src/utils/EventHandler.js +87 -0
- package/src/utils/ID.js +89 -0
- package/src/utils/IdMap.js +629 -0
- package/src/utils/IdSet.js +823 -0
- package/src/utils/RelativePosition.js +352 -0
- package/src/utils/Snapshot.js +220 -0
- package/src/utils/StructSet.js +137 -0
- package/src/utils/StructStore.js +289 -0
- package/src/utils/Transaction.js +489 -0
- package/src/utils/UndoManager.js +391 -0
- package/src/utils/UpdateDecoder.js +281 -0
- package/src/utils/UpdateEncoder.js +320 -0
- package/src/utils/YEvent.js +216 -0
- package/src/utils/delta-helpers.js +54 -0
- package/src/utils/encoding.js +623 -0
- package/src/utils/isParentOf.js +21 -0
- package/src/utils/logging.js +21 -0
- package/src/utils/types.js +28 -0
- package/src/utils/updates.js +715 -0
- package/tests/testHelper.js +600 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Transaction, Item, StructStore // eslint-disable-line
|
|
3
|
+
} from '../internals.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
export class ContentJSON {
|
|
9
|
+
/**
|
|
10
|
+
* @param {Array<any>} arr
|
|
11
|
+
*/
|
|
12
|
+
constructor (arr) {
|
|
13
|
+
/**
|
|
14
|
+
* @type {Array<any>}
|
|
15
|
+
*/
|
|
16
|
+
this.arr = arr
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @return {number}
|
|
21
|
+
*/
|
|
22
|
+
getLength () {
|
|
23
|
+
return this.arr.length
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @return {Array<any>}
|
|
28
|
+
*/
|
|
29
|
+
getContent () {
|
|
30
|
+
return this.arr
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @return {boolean}
|
|
35
|
+
*/
|
|
36
|
+
isCountable () {
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @return {ContentJSON}
|
|
42
|
+
*/
|
|
43
|
+
copy () {
|
|
44
|
+
return new ContentJSON(this.arr)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {number} offset
|
|
49
|
+
* @return {ContentJSON}
|
|
50
|
+
*/
|
|
51
|
+
splice (offset) {
|
|
52
|
+
const right = new ContentJSON(this.arr.slice(offset))
|
|
53
|
+
this.arr = this.arr.slice(0, offset)
|
|
54
|
+
return right
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {ContentJSON} right
|
|
59
|
+
* @return {boolean}
|
|
60
|
+
*/
|
|
61
|
+
mergeWith (right) {
|
|
62
|
+
this.arr = this.arr.concat(right.arr)
|
|
63
|
+
return true
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param {Transaction} transaction
|
|
68
|
+
* @param {Item} item
|
|
69
|
+
*/
|
|
70
|
+
integrate (transaction, item) {}
|
|
71
|
+
/**
|
|
72
|
+
* @param {Transaction} transaction
|
|
73
|
+
*/
|
|
74
|
+
delete (transaction) {}
|
|
75
|
+
/**
|
|
76
|
+
* @param {Transaction} _tr
|
|
77
|
+
*/
|
|
78
|
+
gc (_tr) {}
|
|
79
|
+
/**
|
|
80
|
+
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
81
|
+
* @param {number} offset
|
|
82
|
+
* @param {number} offsetEnd
|
|
83
|
+
*/
|
|
84
|
+
write (encoder, offset, offsetEnd) {
|
|
85
|
+
const end = this.arr.length - offsetEnd
|
|
86
|
+
encoder.writeLen(end - offset)
|
|
87
|
+
for (let i = offset; i < end; i++) {
|
|
88
|
+
const c = this.arr[i]
|
|
89
|
+
encoder.writeString(c === undefined ? 'undefined' : JSON.stringify(c))
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @return {number}
|
|
95
|
+
*/
|
|
96
|
+
getRef () {
|
|
97
|
+
return 2
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @private
|
|
103
|
+
*
|
|
104
|
+
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
|
|
105
|
+
* @return {ContentJSON}
|
|
106
|
+
*/
|
|
107
|
+
export const readContentJSON = decoder => {
|
|
108
|
+
const len = decoder.readLen()
|
|
109
|
+
const cs = []
|
|
110
|
+
for (let i = 0; i < len; i++) {
|
|
111
|
+
const c = decoder.readString()
|
|
112
|
+
if (c === 'undefined') {
|
|
113
|
+
cs.push(undefined)
|
|
114
|
+
} else {
|
|
115
|
+
cs.push(JSON.parse(c))
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return new ContentJSON(cs)
|
|
119
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Transaction, Item, StructStore // eslint-disable-line
|
|
3
|
+
} from '../internals.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
export class ContentString {
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} str
|
|
11
|
+
*/
|
|
12
|
+
constructor (str) {
|
|
13
|
+
/**
|
|
14
|
+
* @type {string}
|
|
15
|
+
*/
|
|
16
|
+
this.str = str
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @return {number}
|
|
21
|
+
*/
|
|
22
|
+
getLength () {
|
|
23
|
+
return this.str.length
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @return {Array<any>}
|
|
28
|
+
*/
|
|
29
|
+
getContent () {
|
|
30
|
+
return this.str.split('')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @return {boolean}
|
|
35
|
+
*/
|
|
36
|
+
isCountable () {
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @return {ContentString}
|
|
42
|
+
*/
|
|
43
|
+
copy () {
|
|
44
|
+
return new ContentString(this.str)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {number} offset
|
|
49
|
+
* @return {ContentString}
|
|
50
|
+
*/
|
|
51
|
+
splice (offset) {
|
|
52
|
+
const right = new ContentString(this.str.slice(offset))
|
|
53
|
+
this.str = this.str.slice(0, offset)
|
|
54
|
+
|
|
55
|
+
// Prevent encoding invalid documents because of splitting of surrogate pairs: https://github.com/yjs/yjs/issues/248
|
|
56
|
+
const firstCharCode = this.str.charCodeAt(offset - 1)
|
|
57
|
+
if (firstCharCode >= 0xD800 && firstCharCode <= 0xDBFF) {
|
|
58
|
+
// Last character of the left split is the start of a surrogate utf16/ucs2 pair.
|
|
59
|
+
// We don't support splitting of surrogate pairs because this may lead to invalid documents.
|
|
60
|
+
// Replace the invalid character with a unicode replacement character (� / U+FFFD)
|
|
61
|
+
this.str = this.str.slice(0, offset - 1) + '�'
|
|
62
|
+
// replace right as well
|
|
63
|
+
right.str = '�' + right.str.slice(1)
|
|
64
|
+
}
|
|
65
|
+
return right
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {ContentString} right
|
|
70
|
+
* @return {boolean}
|
|
71
|
+
*/
|
|
72
|
+
mergeWith (right) {
|
|
73
|
+
this.str += right.str
|
|
74
|
+
return true
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param {Transaction} transaction
|
|
79
|
+
* @param {Item} item
|
|
80
|
+
*/
|
|
81
|
+
integrate (transaction, item) {}
|
|
82
|
+
/**
|
|
83
|
+
* @param {Transaction} transaction
|
|
84
|
+
*/
|
|
85
|
+
delete (transaction) {}
|
|
86
|
+
/**
|
|
87
|
+
* @param {Transaction} _tr
|
|
88
|
+
*/
|
|
89
|
+
gc (_tr) {}
|
|
90
|
+
/**
|
|
91
|
+
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
92
|
+
* @param {number} offset
|
|
93
|
+
* @param {number} offsetEnd
|
|
94
|
+
*/
|
|
95
|
+
write (encoder, offset, offsetEnd) {
|
|
96
|
+
encoder.writeString((offset === 0 && offsetEnd === 0) ? this.str : this.str.slice(offset, this.str.length - offsetEnd))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @return {number}
|
|
101
|
+
*/
|
|
102
|
+
getRef () {
|
|
103
|
+
return 4
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @private
|
|
109
|
+
*
|
|
110
|
+
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
|
|
111
|
+
* @return {ContentString}
|
|
112
|
+
*/
|
|
113
|
+
export const readContentString = decoder => new ContentString(decoder.readString())
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readYArray,
|
|
3
|
+
readYMap,
|
|
4
|
+
readYText,
|
|
5
|
+
readYXmlElement,
|
|
6
|
+
readYXmlFragment,
|
|
7
|
+
readYXmlHook,
|
|
8
|
+
readYXmlText,
|
|
9
|
+
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Transaction, Item // eslint-disable-line
|
|
10
|
+
} from '../internals.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {import('../utils/types.js').YType} YType_CT
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import * as error from 'lib0/error'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @type {Array<(decoder: UpdateDecoderV1 | UpdateDecoderV2)=>(import('../utils/types.js').YType)>}
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
export const typeRefs = [
|
|
23
|
+
readYArray,
|
|
24
|
+
readYMap,
|
|
25
|
+
readYText,
|
|
26
|
+
readYXmlElement,
|
|
27
|
+
readYXmlFragment,
|
|
28
|
+
readYXmlHook,
|
|
29
|
+
readYXmlText
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
export const YArrayRefID = 0
|
|
33
|
+
export const YMapRefID = 1
|
|
34
|
+
export const YTextRefID = 2
|
|
35
|
+
export const YXmlElementRefID = 3
|
|
36
|
+
export const YXmlFragmentRefID = 4
|
|
37
|
+
export const YXmlHookRefID = 5
|
|
38
|
+
export const YXmlTextRefID = 6
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
export class ContentType {
|
|
44
|
+
/**
|
|
45
|
+
* @param {YType_CT} type
|
|
46
|
+
*/
|
|
47
|
+
constructor (type) {
|
|
48
|
+
/**
|
|
49
|
+
* @type {YType_CT}
|
|
50
|
+
*/
|
|
51
|
+
this.type = type
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @return {number}
|
|
56
|
+
*/
|
|
57
|
+
getLength () {
|
|
58
|
+
return 1
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @return {Array<any>}
|
|
63
|
+
*/
|
|
64
|
+
getContent () {
|
|
65
|
+
return [this.type]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @return {boolean}
|
|
70
|
+
*/
|
|
71
|
+
isCountable () {
|
|
72
|
+
return true
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @return {ContentType}
|
|
77
|
+
*/
|
|
78
|
+
copy () {
|
|
79
|
+
return new ContentType(this.type._copy())
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {number} _offset
|
|
84
|
+
* @return {ContentType}
|
|
85
|
+
*/
|
|
86
|
+
splice (_offset) {
|
|
87
|
+
throw error.methodUnimplemented()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {ContentType} _right
|
|
92
|
+
* @return {boolean}
|
|
93
|
+
*/
|
|
94
|
+
mergeWith (_right) {
|
|
95
|
+
return false
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {Transaction} transaction
|
|
100
|
+
* @param {Item} item
|
|
101
|
+
*/
|
|
102
|
+
integrate (transaction, item) {
|
|
103
|
+
this.type._integrate(transaction.doc, item)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {Transaction} transaction
|
|
108
|
+
*/
|
|
109
|
+
delete (transaction) {
|
|
110
|
+
let item = this.type._start
|
|
111
|
+
while (item !== null) {
|
|
112
|
+
if (!item.deleted) {
|
|
113
|
+
item.delete(transaction)
|
|
114
|
+
} else if (!transaction.insertSet.hasId(item.id)) {
|
|
115
|
+
// This will be gc'd later and we want to merge it if possible
|
|
116
|
+
// We try to merge all deleted items after each transaction,
|
|
117
|
+
// but we have no knowledge about that this needs to be merged
|
|
118
|
+
// since it is not in transaction.ds. Hence we add it to transaction._mergeStructs
|
|
119
|
+
transaction._mergeStructs.push(item)
|
|
120
|
+
}
|
|
121
|
+
item = item.right
|
|
122
|
+
}
|
|
123
|
+
this.type._map.forEach(item => {
|
|
124
|
+
if (!item.deleted) {
|
|
125
|
+
item.delete(transaction)
|
|
126
|
+
} else if (!transaction.insertSet.hasId(item.id)) {
|
|
127
|
+
// same as above
|
|
128
|
+
transaction._mergeStructs.push(item)
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
transaction.changed.delete(this.type)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @param {Transaction} tr
|
|
136
|
+
*/
|
|
137
|
+
gc (tr) {
|
|
138
|
+
let item = this.type._start
|
|
139
|
+
while (item !== null) {
|
|
140
|
+
item.gc(tr, true)
|
|
141
|
+
item = item.right
|
|
142
|
+
}
|
|
143
|
+
this.type._start = null
|
|
144
|
+
this.type._map.forEach(/** @param {Item | null} item */ (item) => {
|
|
145
|
+
while (item !== null) {
|
|
146
|
+
item.gc(tr, true)
|
|
147
|
+
item = item.left
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
this.type._map = new Map()
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
155
|
+
* @param {number} _offset
|
|
156
|
+
* @param {number} _offsetEnd
|
|
157
|
+
*/
|
|
158
|
+
write (encoder, _offset, _offsetEnd) {
|
|
159
|
+
this.type._write(encoder)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @return {number}
|
|
164
|
+
*/
|
|
165
|
+
getRef () {
|
|
166
|
+
return 7
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @private
|
|
172
|
+
*
|
|
173
|
+
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
|
|
174
|
+
* @return {ContentType}
|
|
175
|
+
*/
|
|
176
|
+
export const readContentType = decoder => new ContentType(typeRefs[decoder.readTypeRef()](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
|
+
}
|