@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
package/src/structs/Skip.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AbstractStruct,
|
|
3
|
-
addStruct,
|
|
4
|
-
addToIdSet,
|
|
5
|
-
UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, // eslint-disable-line
|
|
6
|
-
createID
|
|
7
|
-
} from '../internals.js'
|
|
8
|
-
|
|
9
1
|
import * as encoding from 'lib0/encoding'
|
|
10
2
|
|
|
3
|
+
import { AbstractStruct } from './AbstractStruct.js'
|
|
4
|
+
import { createID } from '../utils/ID.js'
|
|
5
|
+
|
|
11
6
|
export const structSkipRefNumber = 10
|
|
12
7
|
|
|
13
8
|
/**
|
|
@@ -41,8 +36,9 @@ export class Skip extends AbstractStruct {
|
|
|
41
36
|
this.id.clock += offset
|
|
42
37
|
this.length -= offset
|
|
43
38
|
}
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
const store = transaction.doc.store
|
|
40
|
+
store.skips.add(this.id.client, this.id.clock, this.length)
|
|
41
|
+
store.add(this)
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
/**
|
|
@@ -55,15 +51,6 @@ export class Skip extends AbstractStruct {
|
|
|
55
51
|
encoding.writeVarUint(encoder.restEncoder, this.length - offset)
|
|
56
52
|
}
|
|
57
53
|
|
|
58
|
-
/**
|
|
59
|
-
* @param {Transaction} _transaction
|
|
60
|
-
* @param {StructStore} _store
|
|
61
|
-
* @return {null | number}
|
|
62
|
-
*/
|
|
63
|
-
getMissing (_transaction, _store) {
|
|
64
|
-
return null
|
|
65
|
-
}
|
|
66
|
-
|
|
67
54
|
/**
|
|
68
55
|
* @param {number} diff
|
|
69
56
|
*/
|
|
@@ -73,3 +60,13 @@ export class Skip extends AbstractStruct {
|
|
|
73
60
|
return other
|
|
74
61
|
}
|
|
75
62
|
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @type {10}
|
|
66
|
+
*/
|
|
67
|
+
Skip.prototype.ref = structSkipRefNumber
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @type {false}
|
|
71
|
+
*/
|
|
72
|
+
Skip.prototype.isItem = false
|
package/src/utils/BlockSet.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createID,
|
|
3
|
-
readItemContent,
|
|
4
|
-
findIndexCleanStart,
|
|
5
|
-
Skip,
|
|
6
|
-
createIdSet,
|
|
7
|
-
sliceStruct,
|
|
8
|
-
IdRange,
|
|
9
|
-
GC, Item, ID,
|
|
10
|
-
writeStructs
|
|
11
|
-
} from '../internals.js'
|
|
12
|
-
|
|
13
1
|
import * as decoding from 'lib0/decoding'
|
|
14
2
|
import * as binary from 'lib0/binary'
|
|
15
3
|
import * as map from 'lib0/map'
|
|
@@ -18,6 +6,16 @@ import * as math from 'lib0/math'
|
|
|
18
6
|
import * as encoding from 'lib0/encoding'
|
|
19
7
|
import * as number from 'lib0/number'
|
|
20
8
|
|
|
9
|
+
import { createID, ID } from './ID.js'
|
|
10
|
+
import { Item } from '../structs/Item.js'
|
|
11
|
+
import { readItemContent } from '../ytype.js'
|
|
12
|
+
import { findIndexCleanStart } from './transaction-helpers.js'
|
|
13
|
+
import { Skip } from '../structs/Skip.js'
|
|
14
|
+
import { createIdSet, IdRange } from './ids.js'
|
|
15
|
+
import { sliceStruct } from './updates.js'
|
|
16
|
+
import { GC } from '../structs/GC.js'
|
|
17
|
+
import { writeStructs } from './encoding-helpers.js'
|
|
18
|
+
|
|
21
19
|
/**
|
|
22
20
|
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder The decoder object to read data from.
|
|
23
21
|
* @return {BlockSet}
|
|
@@ -31,7 +29,7 @@ export const readBlockSet = (decoder) => {
|
|
|
31
29
|
for (let i = 0; i < numOfStateUpdates; i++) {
|
|
32
30
|
const numberOfBlocks = decoding.readVarUint(decoder.restDecoder)
|
|
33
31
|
/**
|
|
34
|
-
* @type {Array<GC|Item>}
|
|
32
|
+
* @type {Array<GC|Item|Skip>}
|
|
35
33
|
*/
|
|
36
34
|
const refs = new Array(numberOfBlocks)
|
|
37
35
|
const client = decoder.readClient()
|
|
@@ -99,12 +97,12 @@ export const writeBlockSet = (encoder, blocks) => {
|
|
|
99
97
|
|
|
100
98
|
class BlockRange {
|
|
101
99
|
/**
|
|
102
|
-
* @param {Array<Item|GC>} refs
|
|
100
|
+
* @param {Array<Item|GC|Skip>} refs
|
|
103
101
|
*/
|
|
104
102
|
constructor (refs) {
|
|
105
103
|
this.i = 0
|
|
106
104
|
/**
|
|
107
|
-
* @type {Array<Item | GC>}
|
|
105
|
+
* @type {Array<Item | GC | Skip>}
|
|
108
106
|
*/
|
|
109
107
|
this.refs = refs
|
|
110
108
|
}
|
|
@@ -196,17 +194,19 @@ export class BlockSet {
|
|
|
196
194
|
if (gapSize > 0) {
|
|
197
195
|
leftRanges.push(new Skip(new ID(clientid, lastBlockLeft.id.clock + lastBlockLeft.length), gapSize))
|
|
198
196
|
}
|
|
199
|
-
|
|
197
|
+
for (let i = 0; i < rightRanges.length; i++) {
|
|
198
|
+
leftRanges.push(rightRanges[i])
|
|
199
|
+
}
|
|
200
200
|
ranges.refs = leftRanges
|
|
201
201
|
} else {
|
|
202
202
|
// requires more computation because we need to filter duplicates
|
|
203
203
|
/**
|
|
204
|
-
* @type {Array<GC|Item>}
|
|
204
|
+
* @type {Array<GC|Item|Skip>}
|
|
205
205
|
*/
|
|
206
206
|
const result = []
|
|
207
207
|
let nextExpectedClock = leftRanges[0].id.clock
|
|
208
208
|
/**
|
|
209
|
-
* @param {Item|GC} block
|
|
209
|
+
* @param {Item|GC|Skip} block
|
|
210
210
|
*/
|
|
211
211
|
const addToResult = block => {
|
|
212
212
|
result.push(block)
|
|
@@ -215,11 +215,11 @@ export class BlockSet {
|
|
|
215
215
|
let li = 0
|
|
216
216
|
let ri = 0
|
|
217
217
|
/**
|
|
218
|
-
* @type {Item|GC|undefined}
|
|
218
|
+
* @type {Item|GC|Skip|undefined}
|
|
219
219
|
*/
|
|
220
220
|
let lblock = leftRanges[li]
|
|
221
221
|
/**
|
|
222
|
-
* @type {Item|GC|undefined}
|
|
222
|
+
* @type {Item|GC|Skip|undefined}
|
|
223
223
|
*/
|
|
224
224
|
let rblock = rightRanges[ri]
|
|
225
225
|
const applyLeft = () => {
|
package/src/utils/Doc.js
CHANGED
|
@@ -2,22 +2,16 @@
|
|
|
2
2
|
* @module Y
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
StructStore,
|
|
7
|
-
transact,
|
|
8
|
-
applyUpdate,
|
|
9
|
-
ContentDoc, Item, Transaction, // eslint-disable-line
|
|
10
|
-
encodeStateAsUpdate
|
|
11
|
-
} from '../internals.js'
|
|
12
|
-
|
|
13
|
-
import { YType } from '../ytype.js'
|
|
14
5
|
import { ObservableV2 } from 'lib0/observable'
|
|
15
6
|
import * as random from 'lib0/random'
|
|
16
7
|
import * as map from 'lib0/map'
|
|
17
8
|
import * as array from 'lib0/array'
|
|
18
9
|
import * as promise from 'lib0/promise'
|
|
19
10
|
|
|
20
|
-
|
|
11
|
+
import { StructStore } from './StructStore.js'
|
|
12
|
+
import { transact, generateNewClientId } from './Transaction.js'
|
|
13
|
+
import { YType } from '../ytype.js'
|
|
14
|
+
import { $ydoc } from './schemas.js'
|
|
21
15
|
|
|
22
16
|
/**
|
|
23
17
|
* @typedef {Object} DocOpts
|
|
@@ -179,12 +173,11 @@ export class Doc extends ObservableV2 {
|
|
|
179
173
|
* @template T
|
|
180
174
|
* @param {function(Transaction):T} f The function that should be executed as a transaction
|
|
181
175
|
* @param {any} [origin] Origin of who started the transaction. Will be stored on transaction.origin
|
|
176
|
+
* @param {boolean} [local]
|
|
182
177
|
* @return T
|
|
183
|
-
*
|
|
184
|
-
* @public
|
|
185
178
|
*/
|
|
186
|
-
transact (f, origin = null) {
|
|
187
|
-
return transact(this, f, origin)
|
|
179
|
+
transact (f, origin = null, local = true) {
|
|
180
|
+
return transact(this, f, origin, local)
|
|
188
181
|
}
|
|
189
182
|
|
|
190
183
|
/**
|
|
@@ -238,29 +231,22 @@ export class Doc extends ObservableV2 {
|
|
|
238
231
|
if (item !== null) {
|
|
239
232
|
this._item = null
|
|
240
233
|
const content = /** @type {ContentDoc} */ (item.content)
|
|
241
|
-
|
|
242
|
-
|
|
234
|
+
/**
|
|
235
|
+
* new content doc which replaces the new one
|
|
236
|
+
*/
|
|
237
|
+
const contentDoc = new Doc({ guid: this.guid, ...content.opts, shouldLoad: false })
|
|
238
|
+
content.doc = contentDoc
|
|
239
|
+
contentDoc._item = item
|
|
243
240
|
transact(/** @type {any} */ (item).parent.doc, transaction => {
|
|
244
|
-
const doc = content.doc
|
|
245
241
|
if (!item.deleted) {
|
|
246
|
-
transaction.subdocsAdded.add(
|
|
242
|
+
transaction.subdocsAdded.add(contentDoc)
|
|
247
243
|
}
|
|
248
244
|
transaction.subdocsRemoved.add(this)
|
|
249
245
|
}, null, true)
|
|
250
246
|
}
|
|
251
|
-
// @ts-ignore
|
|
252
|
-
this.emit('destroyed', [true]) // DEPRECATED!
|
|
253
247
|
this.emit('destroy', [this])
|
|
254
248
|
super.destroy()
|
|
255
249
|
}
|
|
256
250
|
}
|
|
257
251
|
|
|
258
|
-
|
|
259
|
-
* @param {Doc} ydoc
|
|
260
|
-
* @param {DocOpts} [opts]
|
|
261
|
-
*/
|
|
262
|
-
export const cloneDoc = (ydoc, opts) => {
|
|
263
|
-
const clone = new Doc(opts)
|
|
264
|
-
applyUpdate(clone, encodeStateAsUpdate(ydoc))
|
|
265
|
-
return clone
|
|
266
|
-
}
|
|
252
|
+
Doc.prototype.$type = $ydoc
|
package/src/utils/ID.js
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
writeID,
|
|
3
|
-
readID,
|
|
4
|
-
compareIDs,
|
|
5
|
-
getState,
|
|
6
|
-
findRootTypeKey,
|
|
7
|
-
Item,
|
|
8
|
-
createID,
|
|
9
|
-
ContentType,
|
|
10
|
-
followRedone,
|
|
11
|
-
getItem,
|
|
12
|
-
StructStore, ID, Doc, YType, noAttributionsManager, // eslint-disable-line
|
|
13
|
-
} from '../internals.js'
|
|
14
|
-
|
|
15
1
|
import * as encoding from 'lib0/encoding'
|
|
16
2
|
import * as decoding from 'lib0/decoding'
|
|
17
3
|
import * as error from 'lib0/error'
|
|
18
4
|
|
|
5
|
+
import { Item, followRedone, ContentType } from '../structs/Item.js'
|
|
6
|
+
import { writeID, readID, compareIDs, findRootTypeKey, createID } from './ID.js'
|
|
7
|
+
import { baseRenderer } from './renderer-helpers.js'
|
|
8
|
+
|
|
19
9
|
/**
|
|
20
10
|
* A relative position is based on the Yjs model and is not affected by document changes.
|
|
21
11
|
* E.g. If you place a relative position before a certain character, it will always point to this character.
|
|
@@ -156,12 +146,12 @@ export const createRelativePosition = (type, item, assoc) => {
|
|
|
156
146
|
* @param {YType} type The base type (e.g. YText or YArray).
|
|
157
147
|
* @param {number} index The absolute position.
|
|
158
148
|
* @param {number} [assoc]
|
|
159
|
-
* @param {import('../utils/
|
|
149
|
+
* @param {import('../utils/Renderer.js').AbstractRenderer} renderer
|
|
160
150
|
* @return {RelativePosition}
|
|
161
151
|
*
|
|
162
152
|
* @function
|
|
163
153
|
*/
|
|
164
|
-
export const createRelativePositionFromTypeIndex = (type, index, assoc = 0,
|
|
154
|
+
export const createRelativePositionFromTypeIndex = (type, index, assoc = 0, renderer = baseRenderer) => {
|
|
165
155
|
let t = type._start
|
|
166
156
|
if (assoc < 0) {
|
|
167
157
|
// associated to the left character or the beginning of a type, increment index if possible.
|
|
@@ -171,7 +161,7 @@ export const createRelativePositionFromTypeIndex = (type, index, assoc = 0, attr
|
|
|
171
161
|
index--
|
|
172
162
|
}
|
|
173
163
|
while (t !== null) {
|
|
174
|
-
const len =
|
|
164
|
+
const len = renderer.contentLength(t)
|
|
175
165
|
if (len > index) {
|
|
176
166
|
// case 1: found position somewhere in the linked list
|
|
177
167
|
return createRelativePosition(type, createID(t.id.client, t.id.clock + index), assoc)
|
|
@@ -261,7 +251,7 @@ export const decodeRelativePosition = uint8Array => readRelativePosition(decodin
|
|
|
261
251
|
* @param {ID} id
|
|
262
252
|
*/
|
|
263
253
|
const getItemWithOffset = (store, id) => {
|
|
264
|
-
const item = getItem(
|
|
254
|
+
const item = store.getItem(id)
|
|
265
255
|
const diff = id.clock - item.id.clock
|
|
266
256
|
return {
|
|
267
257
|
item, diff
|
|
@@ -282,12 +272,12 @@ const getItemWithOffset = (store, id) => {
|
|
|
282
272
|
* @param {RelativePosition} rpos
|
|
283
273
|
* @param {Doc} doc
|
|
284
274
|
* @param {boolean} followUndoneDeletions - whether to follow undone deletions - see https://github.com/yjs/yjs/issues/638
|
|
285
|
-
* @param {import('../utils/
|
|
275
|
+
* @param {import('../utils/Renderer.js').AbstractRenderer} renderer
|
|
286
276
|
* @return {AbsolutePosition|null}
|
|
287
277
|
*
|
|
288
278
|
* @function
|
|
289
279
|
*/
|
|
290
|
-
export const createAbsolutePositionFromRelativePosition = (rpos, doc, followUndoneDeletions = true,
|
|
280
|
+
export const createAbsolutePositionFromRelativePosition = (rpos, doc, followUndoneDeletions = true, renderer = baseRenderer) => {
|
|
291
281
|
const store = doc.store
|
|
292
282
|
const rightID = rpos.item
|
|
293
283
|
const typeID = rpos.type
|
|
@@ -296,7 +286,7 @@ export const createAbsolutePositionFromRelativePosition = (rpos, doc, followUndo
|
|
|
296
286
|
let type = null
|
|
297
287
|
let index = 0
|
|
298
288
|
if (rightID !== null) {
|
|
299
|
-
if (
|
|
289
|
+
if (store.getClock(rightID.client) <= rightID.clock) {
|
|
300
290
|
return null
|
|
301
291
|
}
|
|
302
292
|
const res = followUndoneDeletions ? followRedone(store, rightID) : getItemWithOffset(store, rightID)
|
|
@@ -306,10 +296,10 @@ export const createAbsolutePositionFromRelativePosition = (rpos, doc, followUndo
|
|
|
306
296
|
}
|
|
307
297
|
type = /** @type {YType<any>} */ (right.parent)
|
|
308
298
|
if (type._item === null || !type._item.deleted) {
|
|
309
|
-
index =
|
|
299
|
+
index = renderer.contentLength(right) === 0 ? 0 : (res.diff + (assoc >= 0 ? 0 : 1)) // adjust position based on left association if necessary
|
|
310
300
|
let n = right.left
|
|
311
301
|
while (n !== null) {
|
|
312
|
-
index +=
|
|
302
|
+
index += renderer.contentLength(n)
|
|
313
303
|
n = n.left
|
|
314
304
|
}
|
|
315
305
|
}
|
|
@@ -317,11 +307,11 @@ export const createAbsolutePositionFromRelativePosition = (rpos, doc, followUndo
|
|
|
317
307
|
if (tname !== null) {
|
|
318
308
|
type = doc.get(tname)
|
|
319
309
|
} else if (typeID !== null) {
|
|
320
|
-
if (
|
|
310
|
+
if (store.getClock(typeID.client) <= typeID.clock) {
|
|
321
311
|
// type does not exist yet
|
|
322
312
|
return null
|
|
323
313
|
}
|
|
324
|
-
const { item } = followUndoneDeletions ? followRedone(store, typeID) : { item: getItem(
|
|
314
|
+
const { item } = followUndoneDeletions ? followRedone(store, typeID) : { item: store.getItem(typeID) }
|
|
325
315
|
if (item instanceof Item && item.content instanceof ContentType) {
|
|
326
316
|
type = item.content.type
|
|
327
317
|
} else {
|