@y/y 14.0.0-rc.2 → 14.0.0-rc.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.
- package/README.md +36 -12
- package/dist/src/index.d.ts +24 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/structs/AbstractStruct.d.ts +14 -17
- package/dist/src/structs/AbstractStruct.d.ts.map +1 -1
- package/dist/src/structs/GC.d.ts +9 -14
- package/dist/src/structs/GC.d.ts.map +1 -1
- package/dist/src/structs/Item.d.ts +569 -31
- package/dist/src/structs/Item.d.ts.map +1 -1
- package/dist/src/structs/Skip.d.ts +9 -11
- package/dist/src/structs/Skip.d.ts.map +1 -1
- package/dist/src/utils/BlockSet.d.ts +8 -7
- package/dist/src/utils/BlockSet.d.ts.map +1 -1
- package/dist/src/utils/Doc.d.ts +4 -9
- package/dist/src/utils/Doc.d.ts.map +1 -1
- package/dist/src/utils/ID.d.ts +0 -1
- package/dist/src/utils/ID.d.ts.map +1 -1
- package/dist/src/utils/RelativePosition.d.ts +2 -5
- package/dist/src/utils/RelativePosition.d.ts.map +1 -1
- package/dist/src/utils/Renderer.d.ts +144 -0
- package/dist/src/utils/Renderer.d.ts.map +1 -0
- package/dist/src/utils/Snapshot.d.ts +7 -11
- package/dist/src/utils/Snapshot.d.ts.map +1 -1
- package/dist/src/utils/StructStore.d.ts +45 -23
- package/dist/src/utils/StructStore.d.ts.map +1 -1
- package/dist/src/utils/Transaction.d.ts +11 -21
- package/dist/src/utils/Transaction.d.ts.map +1 -1
- package/dist/src/utils/UndoManager.d.ts +13 -14
- package/dist/src/utils/UndoManager.d.ts.map +1 -1
- package/dist/src/utils/UpdateDecoder.d.ts +1 -1
- package/dist/src/utils/UpdateDecoder.d.ts.map +1 -1
- package/dist/src/utils/UpdateEncoder.d.ts +0 -1
- package/dist/src/utils/UpdateEncoder.d.ts.map +1 -1
- package/dist/src/utils/YEvent.d.ts +22 -26
- package/dist/src/utils/YEvent.d.ts.map +1 -1
- package/dist/src/utils/content-helper.d.ts +2 -0
- package/dist/src/utils/content-helper.d.ts.map +1 -0
- package/dist/src/utils/delta-helpers.d.ts +2 -3
- package/dist/src/utils/delta-helpers.d.ts.map +1 -1
- package/dist/src/utils/encoding-helpers.d.ts +6 -0
- package/dist/src/utils/encoding-helpers.d.ts.map +1 -0
- package/dist/src/utils/encoding.d.ts +16 -18
- package/dist/src/utils/encoding.d.ts.map +1 -1
- package/dist/src/utils/ids.d.ts +331 -0
- package/dist/src/utils/ids.d.ts.map +1 -0
- package/dist/src/utils/isParentOf.d.ts +1 -2
- package/dist/src/utils/isParentOf.d.ts.map +1 -1
- package/dist/src/utils/logging.d.ts +0 -1
- package/dist/src/utils/logging.d.ts.map +1 -1
- package/dist/src/utils/meta.d.ts +15 -64
- package/dist/src/utils/meta.d.ts.map +1 -1
- package/dist/src/utils/renderer-helpers.d.ts +99 -0
- package/dist/src/utils/renderer-helpers.d.ts.map +1 -0
- package/dist/src/utils/schemas.d.ts +3 -0
- package/dist/src/utils/schemas.d.ts.map +1 -0
- package/dist/src/utils/transaction-helpers.d.ts +18 -0
- package/dist/src/utils/transaction-helpers.d.ts.map +1 -0
- package/dist/src/utils/updates.d.ts +19 -25
- package/dist/src/utils/updates.d.ts.map +1 -1
- package/dist/src/ytype.d.ts +55 -24
- package/dist/src/ytype.d.ts.map +1 -1
- package/global.d.ts +53 -0
- package/package.json +12 -16
- package/src/index.js +32 -124
- package/src/structs/AbstractStruct.js +21 -16
- package/src/structs/GC.js +15 -20
- package/src/structs/Item.js +992 -318
- package/src/structs/Skip.js +16 -19
- package/src/utils/BlockSet.js +20 -20
- package/src/utils/Doc.js +15 -29
- package/src/utils/ID.js +0 -2
- package/src/utils/RelativePosition.js +15 -25
- package/src/utils/{AttributionManager.js → Renderer.js} +42 -197
- package/src/utils/Snapshot.js +15 -37
- package/src/utils/StructStore.js +89 -227
- package/src/utils/Transaction.js +63 -307
- package/src/utils/UndoManager.js +157 -19
- package/src/utils/UpdateDecoder.js +2 -3
- package/src/utils/UpdateEncoder.js +0 -4
- package/src/utils/YEvent.js +20 -26
- package/src/utils/content-helper.js +0 -0
- package/src/utils/delta-helpers.js +21 -42
- package/src/utils/encoding-helpers.js +110 -0
- package/src/utils/encoding.js +197 -122
- package/src/utils/ids.js +1527 -0
- package/src/utils/isParentOf.js +2 -4
- package/src/utils/logging.js +0 -4
- package/src/utils/meta.js +57 -46
- package/src/utils/renderer-helpers.js +110 -0
- package/src/utils/schemas.js +3 -0
- package/src/utils/transaction-helpers.js +413 -0
- package/src/utils/updates.js +24 -146
- package/src/ytype.js +325 -117
- package/tests/testHelper.js +10 -12
- package/dist/src/internals.d.ts +0 -36
- package/dist/src/internals.d.ts.map +0 -1
- package/dist/src/structs/ContentAny.d.ts +0 -67
- package/dist/src/structs/ContentAny.d.ts.map +0 -1
- package/dist/src/structs/ContentBinary.d.ts +0 -64
- package/dist/src/structs/ContentBinary.d.ts.map +0 -1
- package/dist/src/structs/ContentDeleted.d.ts +0 -64
- package/dist/src/structs/ContentDeleted.d.ts.map +0 -1
- package/dist/src/structs/ContentDoc.d.ts +0 -72
- package/dist/src/structs/ContentDoc.d.ts.map +0 -1
- package/dist/src/structs/ContentEmbed.d.ts +0 -67
- package/dist/src/structs/ContentEmbed.d.ts.map +0 -1
- package/dist/src/structs/ContentFormat.d.ts +0 -69
- package/dist/src/structs/ContentFormat.d.ts.map +0 -1
- package/dist/src/structs/ContentJSON.d.ts +0 -70
- package/dist/src/structs/ContentJSON.d.ts.map +0 -1
- package/dist/src/structs/ContentString.d.ts +0 -70
- package/dist/src/structs/ContentString.d.ts.map +0 -1
- package/dist/src/structs/ContentType.d.ts +0 -77
- package/dist/src/structs/ContentType.d.ts.map +0 -1
- package/dist/src/utils/AttributionManager.d.ts +0 -238
- package/dist/src/utils/AttributionManager.d.ts.map +0 -1
- package/dist/src/utils/IdMap.d.ts +0 -164
- package/dist/src/utils/IdMap.d.ts.map +0 -1
- package/dist/src/utils/IdSet.d.ts +0 -163
- package/dist/src/utils/IdSet.d.ts.map +0 -1
- package/dist/tests/IdMap.tests.d.ts +0 -9
- package/dist/tests/IdMap.tests.d.ts.map +0 -1
- package/dist/tests/IdSet.tests.d.ts +0 -9
- package/dist/tests/IdSet.tests.d.ts.map +0 -1
- package/dist/tests/attribution.tests.d.ts +0 -9
- package/dist/tests/attribution.tests.d.ts.map +0 -1
- package/dist/tests/compatibility.tests.d.ts +0 -5
- package/dist/tests/compatibility.tests.d.ts.map +0 -1
- package/dist/tests/delta.tests.d.ts +0 -7
- package/dist/tests/delta.tests.d.ts.map +0 -1
- package/dist/tests/doc.tests.d.ts +0 -13
- package/dist/tests/doc.tests.d.ts.map +0 -1
- package/dist/tests/encoding.tests.d.ts +0 -5
- package/dist/tests/encoding.tests.d.ts.map +0 -1
- package/dist/tests/index.d.ts +0 -2
- package/dist/tests/index.d.ts.map +0 -1
- package/dist/tests/relativePositions.tests.d.ts +0 -11
- package/dist/tests/relativePositions.tests.d.ts.map +0 -1
- package/dist/tests/snapshot.tests.d.ts +0 -14
- package/dist/tests/snapshot.tests.d.ts.map +0 -1
- package/dist/tests/testHelper.d.ts +0 -171
- package/dist/tests/testHelper.d.ts.map +0 -1
- package/dist/tests/undo-redo.tests.d.ts +0 -27
- package/dist/tests/undo-redo.tests.d.ts.map +0 -1
- package/dist/tests/updates.tests.d.ts +0 -26
- package/dist/tests/updates.tests.d.ts.map +0 -1
- package/dist/tests/y-array.tests.d.ts +0 -43
- package/dist/tests/y-array.tests.d.ts.map +0 -1
- package/dist/tests/y-map.tests.d.ts +0 -42
- package/dist/tests/y-map.tests.d.ts.map +0 -1
- package/dist/tests/y-text.tests.d.ts +0 -49
- package/dist/tests/y-text.tests.d.ts.map +0 -1
- package/dist/tests/y-xml.tests.d.ts +0 -14
- package/dist/tests/y-xml.tests.d.ts.map +0 -1
- package/src/internals.js +0 -35
- package/src/structs/ContentAny.js +0 -115
- package/src/structs/ContentBinary.js +0 -93
- package/src/structs/ContentDeleted.js +0 -101
- package/src/structs/ContentDoc.js +0 -141
- package/src/structs/ContentEmbed.js +0 -98
- package/src/structs/ContentFormat.js +0 -105
- package/src/structs/ContentJSON.js +0 -119
- package/src/structs/ContentString.js +0 -113
- package/src/structs/ContentType.js +0 -152
- package/src/utils/IdMap.js +0 -673
- package/src/utils/IdSet.js +0 -825
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Item, Transaction // eslint-disable-line
|
|
3
|
-
} from '../internals.js'
|
|
4
|
-
|
|
5
|
-
import * as error from 'lib0/error'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @private
|
|
9
|
-
*/
|
|
10
|
-
export class ContentEmbed {
|
|
11
|
-
/**
|
|
12
|
-
* @param {Object} embed
|
|
13
|
-
*/
|
|
14
|
-
constructor (embed) {
|
|
15
|
-
this.embed = embed
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @return {number}
|
|
20
|
-
*/
|
|
21
|
-
getLength () {
|
|
22
|
-
return 1
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @return {Array<any>}
|
|
27
|
-
*/
|
|
28
|
-
getContent () {
|
|
29
|
-
return [this.embed]
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @return {boolean}
|
|
34
|
-
*/
|
|
35
|
-
isCountable () {
|
|
36
|
-
return true
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @return {ContentEmbed}
|
|
41
|
-
*/
|
|
42
|
-
copy () {
|
|
43
|
-
return new ContentEmbed(this.embed)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @param {number} offset
|
|
48
|
-
* @return {ContentEmbed}
|
|
49
|
-
*/
|
|
50
|
-
splice (offset) {
|
|
51
|
-
throw error.methodUnimplemented()
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @param {ContentEmbed} right
|
|
56
|
-
* @return {boolean}
|
|
57
|
-
*/
|
|
58
|
-
mergeWith (right) {
|
|
59
|
-
return false
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @param {Transaction} transaction
|
|
64
|
-
* @param {Item} item
|
|
65
|
-
*/
|
|
66
|
-
integrate (transaction, item) {}
|
|
67
|
-
/**
|
|
68
|
-
* @param {Transaction} transaction
|
|
69
|
-
*/
|
|
70
|
-
delete (transaction) {}
|
|
71
|
-
/**
|
|
72
|
-
* @param {Transaction} _tr
|
|
73
|
-
*/
|
|
74
|
-
gc (_tr) {}
|
|
75
|
-
/**
|
|
76
|
-
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
77
|
-
* @param {number} _offset
|
|
78
|
-
* @param {number} _offsetEnd
|
|
79
|
-
*/
|
|
80
|
-
write (encoder, _offset, _offsetEnd) {
|
|
81
|
-
encoder.writeJSON(this.embed)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* @return {number}
|
|
86
|
-
*/
|
|
87
|
-
getRef () {
|
|
88
|
-
return 5
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @private
|
|
94
|
-
*
|
|
95
|
-
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
|
|
96
|
-
* @return {ContentEmbed}
|
|
97
|
-
*/
|
|
98
|
-
export const readContentEmbed = decoder => new ContentEmbed(decoder.readJSON())
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Item, Transaction // eslint-disable-line
|
|
3
|
-
} from '../internals.js'
|
|
4
|
-
|
|
5
|
-
import * as error from 'lib0/error'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @private
|
|
9
|
-
*/
|
|
10
|
-
export class ContentFormat {
|
|
11
|
-
/**
|
|
12
|
-
* @param {string} key
|
|
13
|
-
* @param {Object} value
|
|
14
|
-
*/
|
|
15
|
-
constructor (key, value) {
|
|
16
|
-
this.key = key
|
|
17
|
-
this.value = value
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @return {number}
|
|
22
|
-
*/
|
|
23
|
-
getLength () {
|
|
24
|
-
return 1
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @return {Array<any>}
|
|
29
|
-
*/
|
|
30
|
-
getContent () {
|
|
31
|
-
return []
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @return {boolean}
|
|
36
|
-
*/
|
|
37
|
-
isCountable () {
|
|
38
|
-
return false
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @return {ContentFormat}
|
|
43
|
-
*/
|
|
44
|
-
copy () {
|
|
45
|
-
return new ContentFormat(this.key, this.value)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @param {number} _offset
|
|
50
|
-
* @return {ContentFormat}
|
|
51
|
-
*/
|
|
52
|
-
splice (_offset) {
|
|
53
|
-
throw error.methodUnimplemented()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @param {ContentFormat} _right
|
|
58
|
-
* @return {boolean}
|
|
59
|
-
*/
|
|
60
|
-
mergeWith (_right) {
|
|
61
|
-
return false
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @param {Transaction} _transaction
|
|
66
|
-
* @param {Item} item
|
|
67
|
-
*/
|
|
68
|
-
integrate (_transaction, item) {
|
|
69
|
-
// @todo searchmarker are currently unsupported for rich text documents
|
|
70
|
-
const p = /** @type {import('../ytype.js').YType<any>} */ (item.parent)
|
|
71
|
-
p._searchMarker = null
|
|
72
|
-
p._hasFormatting = true
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @param {Transaction} _transaction
|
|
77
|
-
*/
|
|
78
|
-
delete (_transaction) {}
|
|
79
|
-
/**
|
|
80
|
-
* @param {Transaction} _tr
|
|
81
|
-
*/
|
|
82
|
-
gc (_tr) {}
|
|
83
|
-
/**
|
|
84
|
-
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
85
|
-
* @param {number} _offset
|
|
86
|
-
* @param {number} _offsetEnd
|
|
87
|
-
*/
|
|
88
|
-
write (encoder, _offset, _offsetEnd) {
|
|
89
|
-
encoder.writeKey(this.key)
|
|
90
|
-
encoder.writeJSON(this.value)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @return {number}
|
|
95
|
-
*/
|
|
96
|
-
getRef () {
|
|
97
|
-
return 6
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
|
|
103
|
-
* @return {ContentFormat}
|
|
104
|
-
*/
|
|
105
|
-
export const readContentFormat = decoder => new ContentFormat(decoder.readKey(), decoder.readJSON())
|
|
@@ -1,119 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
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())
|
|
@@ -1,152 +0,0 @@
|
|
|
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))
|