mirror of
https://github.com/yjs/yjs.git
synced 2025-12-16 19:57:45 +01:00
bump deps and use new delta format
This commit is contained in:
4030
package-lock.json
generated
4030
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
13
package.json
13
package.json
@@ -18,7 +18,6 @@
|
|||||||
"dist": "npm run clean && rollup -c && tsc --skipLibCheck",
|
"dist": "npm run clean && rollup -c && tsc --skipLibCheck",
|
||||||
"watch": "rollup -wc",
|
"watch": "rollup -wc",
|
||||||
"lint": "markdownlint README.md && standard && tsc",
|
"lint": "markdownlint README.md && standard && tsc",
|
||||||
"docs": "rm -rf docs; jsdoc --configure ./.jsdoc.json --verbose --readme ./README.md --package ./package.json || true",
|
|
||||||
"serve-docs": "npm run docs && 0serve ./docs/",
|
"serve-docs": "npm run docs && 0serve ./docs/",
|
||||||
"preversion": "PRODUCTION=1 npm run dist && npm run docs && test -e dist/src/index.d.ts && test -e dist/yjs.cjs && test -e dist/yjs.cjs",
|
"preversion": "PRODUCTION=1 npm run dist && npm run docs && test -e dist/src/index.d.ts && test -e dist/yjs.cjs && test -e dist/yjs.cjs",
|
||||||
"debug": "npm run gentesthtml && 0serve -o test.html",
|
"debug": "npm run gentesthtml && 0serve -o test.html",
|
||||||
@@ -85,17 +84,15 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://docs.yjs.dev",
|
"homepage": "https://docs.yjs.dev",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lib0": "^0.2.115-0"
|
"lib0": "^0.2.115-1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.14.1",
|
"@types/node": "^22.14.1",
|
||||||
"@y/protocols": "^1.0.6-1",
|
"@y/protocols": "^1.0.6-1",
|
||||||
"concurrently": "^3.6.1",
|
"concurrently": "^9.2.1",
|
||||||
"jsdoc": "^3.6.7",
|
"markdownlint-cli": "^0.45.0",
|
||||||
"markdownlint-cli": "^0.41.0",
|
"rollup": "^4.52.5",
|
||||||
"rollup": "^4.37.0",
|
"standard": "^17.1.2",
|
||||||
"standard": "^16.0.4",
|
|
||||||
"tui-jsdoc-template": "^1.2.2",
|
|
||||||
"typescript": "^5.9.3"
|
"typescript": "^5.9.3"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -468,7 +468,7 @@ export class AbstractType {
|
|||||||
getContent (am = noAttributionsManager, opts = {}) {
|
getContent (am = noAttributionsManager, opts = {}) {
|
||||||
const { itemsToRender = null, retainInserts = false, retainDeletes = false, renderAttrs = null, renderChildren = true, deletedItems = null, modified = null, deep = false } = opts
|
const { itemsToRender = null, retainInserts = false, retainDeletes = false, renderAttrs = null, renderChildren = true, deletedItems = null, modified = null, deep = false } = opts
|
||||||
/**
|
/**
|
||||||
* @type {EventDelta}
|
* @type {EventDelta extends delta.Delta<infer N,infer Attrs,infer Children,infer Text,any> ? delta.DeltaBuilder<N,Attrs,Children,Text,any> : never}
|
||||||
*/
|
*/
|
||||||
const d = /** @type {any} */ (delta.create(/** @type {any} */ (this).nodeName || null))
|
const d = /** @type {any} */ (delta.create(/** @type {any} */ (this).nodeName || null))
|
||||||
typeMapGetDelta(d, /** @type {any} */ (this), renderAttrs, am, deep, modified, deletedItems, itemsToRender)
|
typeMapGetDelta(d, /** @type {any} */ (this), renderAttrs, am, deep, modified, deletedItems, itemsToRender)
|
||||||
@@ -726,7 +726,7 @@ export class AbstractType {
|
|||||||
} else if (delta.$deleteOp.check(op)) {
|
} else if (delta.$deleteOp.check(op)) {
|
||||||
deleteText(transaction, currPos, op.delete)
|
deleteText(transaction, currPos, op.delete)
|
||||||
} else if (delta.$modifyOp.check(op)) {
|
} else if (delta.$modifyOp.check(op)) {
|
||||||
/** @type {ContentType} */ (currPos.right?.content).type.applyDelta(op.modify)
|
/** @type {ContentType} */ (currPos.right?.content).type.applyDelta(op.value)
|
||||||
currPos.formatText(transaction, /** @type {any} */ (this), 1, op.format || {})
|
currPos.formatText(transaction, /** @type {any} */ (this), 1, op.format || {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1277,7 +1277,7 @@ export const typeMapGetAll = (parent) => {
|
|||||||
* Note that deleted content that was not deleted in prevYdoc is rendered as an insertion with the
|
* Note that deleted content that was not deleted in prevYdoc is rendered as an insertion with the
|
||||||
* attribution `{ isDeleted: true, .. }`.
|
* attribution `{ isDeleted: true, .. }`.
|
||||||
*
|
*
|
||||||
* @template {delta.Delta<any,any,any,any>} TypeDelta
|
* @template {delta.DeltaBuilder<any,any,any,any>} TypeDelta
|
||||||
* @param {TypeDelta} d
|
* @param {TypeDelta} d
|
||||||
* @param {YType_} parent
|
* @param {YType_} parent
|
||||||
* @param {Set<string>?} attrsToRender
|
* @param {Set<string>?} attrsToRender
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import {
|
|||||||
* * An YXmlElement has attributes (key value pairs)
|
* * An YXmlElement has attributes (key value pairs)
|
||||||
* * An YXmlElement has childElements that must inherit from YXmlElement
|
* * An YXmlElement has childElements that must inherit from YXmlElement
|
||||||
*
|
*
|
||||||
* @template {{ [key: string]: ValueTypes }} [Attrs={ [key: string]: string }]
|
* @template {{ [key: string]: any }} [Attrs={ [key: string]: string }]
|
||||||
* @template {any} [Children=any]
|
* @template {any} [Children=any]
|
||||||
* @extends YXmlFragment<Children,Attrs>
|
* @extends YXmlFragment<Children,Attrs>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('../types/YArray.js').YArray<any>
|
* @typedef {import('../types/YArray.js').YArray<any>
|
||||||
* | import('../types/YMap.js').YMap<any>
|
* | import('../types/YMap.js').YMap<any>
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -460,7 +460,7 @@ export const compare = users => {
|
|||||||
users.push(.../** @type {any} */(mergedDocs))
|
users.push(.../** @type {any} */(mergedDocs))
|
||||||
const userArrayValues = users.map(u => u.getArray('array').toJSON())
|
const userArrayValues = users.map(u => u.getArray('array').toJSON())
|
||||||
const userMapValues = users.map(u => u.getMap('map').toJSON())
|
const userMapValues = users.map(u => u.getMap('map').toJSON())
|
||||||
const userXmlValues = users.map(u => u.get('xml', Y.XmlElement).toString())
|
const userXmlValues = users.map(u => /** @type {Y.XmlElement} */ (u.get('xml', Y.XmlElement)).toString())
|
||||||
const userTextValues = users.map(u => u.getText('text').getContentDeep())
|
const userTextValues = users.map(u => u.getText('text').getContentDeep())
|
||||||
for (const u of users) {
|
for (const u of users) {
|
||||||
t.assert(u.store.pendingDs === null)
|
t.assert(u.store.pendingDs === null)
|
||||||
@@ -486,7 +486,7 @@ export const compare = users => {
|
|||||||
t.compare(userArrayValues[i], userArrayValues[i + 1])
|
t.compare(userArrayValues[i], userArrayValues[i + 1])
|
||||||
t.compare(userMapValues[i], userMapValues[i + 1])
|
t.compare(userMapValues[i], userMapValues[i + 1])
|
||||||
t.compare(userXmlValues[i], userXmlValues[i + 1])
|
t.compare(userXmlValues[i], userXmlValues[i + 1])
|
||||||
t.compare(list.toArray(userTextValues[i].children).map(a => delta.$textOp.check(a) ? a.insert : ' ').join('').length, users[i].getText('text').length)
|
t.compare(list.toArray(userTextValues[i].children).map(a => (delta.$textOp.check(a) || delta.$insertOp.check(a)) ? a.insert.length : 0).reduce((a, b) => a + b, 0), users[i].getText('text').length)
|
||||||
t.compare(userTextValues[i], userTextValues[i + 1], '', (_constructor, a, b) => {
|
t.compare(userTextValues[i], userTextValues[i + 1], '', (_constructor, a, b) => {
|
||||||
if (a instanceof Y.AbstractType) {
|
if (a instanceof Y.AbstractType) {
|
||||||
t.compare(a.toJSON(), b.toJSON())
|
t.compare(a.toJSON(), b.toJSON())
|
||||||
|
|||||||
@@ -299,7 +299,9 @@ export const testUndoXml = tc => {
|
|||||||
// format textchild and revert that change
|
// format textchild and revert that change
|
||||||
undoManager.stopCapturing()
|
undoManager.stopCapturing()
|
||||||
textchild.format(3, 4, { bold: {} })
|
textchild.format(3, 4, { bold: {} })
|
||||||
|
t.compare(xml0.getContentDeep(), delta.create('UNDEFINED').insert([delta.text().insert('con').insert('tent', { bold: true }).done()]).done())
|
||||||
t.assert(xml0.toString() === '<undefined><p>con<bold>tent</bold></p></undefined>')
|
t.assert(xml0.toString() === '<undefined><p>con<bold>tent</bold></p></undefined>')
|
||||||
|
debugger
|
||||||
undoManager.undo()
|
undoManager.undo()
|
||||||
t.assert(xml0.toString() === '<undefined><p>content</p></undefined>')
|
t.assert(xml0.toString() === '<undefined><p>content</p></undefined>')
|
||||||
undoManager.redo()
|
undoManager.redo()
|
||||||
|
|||||||
@@ -127,7 +127,15 @@ export const testKeyEncoding = tc => {
|
|||||||
const update = Y.encodeStateAsUpdateV2(users[0])
|
const update = Y.encodeStateAsUpdateV2(users[0])
|
||||||
Y.applyUpdateV2(users[1], update)
|
Y.applyUpdateV2(users[1], update)
|
||||||
|
|
||||||
t.compare(text1.getContent().toJSON().children, [{ insert: 'c', format: { italic: true } }, { insert: 'b' }, { insert: 'a', format: { italic: true } }])
|
const c = text1.getContent()
|
||||||
|
t.compare(
|
||||||
|
c,
|
||||||
|
delta.create()
|
||||||
|
.insert('c', { italic: true })
|
||||||
|
.insert('b')
|
||||||
|
.insert('a', { italic: true })
|
||||||
|
.done()
|
||||||
|
)
|
||||||
|
|
||||||
compare(users)
|
compare(users)
|
||||||
}
|
}
|
||||||
@@ -335,7 +343,7 @@ export const testObfuscateUpdates = _tc => {
|
|||||||
t.assert(d[0].insert !== 'text' && d[0].insert.length === 4)
|
t.assert(d[0].insert !== 'text' && d[0].insert.length === 4)
|
||||||
t.assert(object.length(d[0].format) === 1)
|
t.assert(object.length(d[0].format) === 1)
|
||||||
t.assert(!object.hasProperty(d[0].format, 'bold'))
|
t.assert(!object.hasProperty(d[0].format, 'bold'))
|
||||||
t.assert(object.length(d[1]) === 1)
|
t.assert(object.length(d[1].insert) === 1)
|
||||||
t.assert(object.hasProperty(d[1], 'insert'))
|
t.assert(object.hasProperty(d[1], 'insert'))
|
||||||
// test ymap
|
// test ymap
|
||||||
t.assert(omap.size === 1)
|
t.assert(omap.size === 1)
|
||||||
|
|||||||
@@ -393,13 +393,13 @@ export const testChangeEvent = tc => {
|
|||||||
const newArr = new Y.Array()
|
const newArr = new Y.Array()
|
||||||
array0.insert(0, [newArr, 4, 'dtrn'])
|
array0.insert(0, [newArr, 4, 'dtrn'])
|
||||||
t.assert(d !== null && d.children.len === 1)
|
t.assert(d !== null && d.children.len === 1)
|
||||||
t.compare(d.toJSON().children, [{ insert: [newArr, 4, 'dtrn'] }])
|
t.compare(d, delta.create().insert([newArr, 4, 'dtrn']))
|
||||||
array0.delete(0, 2)
|
array0.delete(0, 2)
|
||||||
t.assert(d !== null && d.children.len === 1)
|
t.assert(d !== null && d.children.len === 1)
|
||||||
t.compare(d.toJSON().children, [{ delete: 2 }])
|
t.compare(d.toJSON().children, [{ delete: 2 }])
|
||||||
array0.insert(1, [0.1])
|
array0.insert(1, [0.1])
|
||||||
t.assert(d !== null && d.children.len === 2)
|
t.assert(d !== null && d.children.len === 2)
|
||||||
t.compare(d.toJSON().children, [{ retain: 1 }, { insert: [0.1] }])
|
t.compare(d, delta.create().retain(1).insert([0.1]).done())
|
||||||
compare(users)
|
compare(users)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import * as t from 'lib0/testing'
|
|||||||
import * as prng from 'lib0/prng'
|
import * as prng from 'lib0/prng'
|
||||||
import * as delta from 'lib0/delta'
|
import * as delta from 'lib0/delta'
|
||||||
import * as s from 'lib0/schema'
|
import * as s from 'lib0/schema'
|
||||||
|
import * as object from 'lib0/object'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {t.TestCase} _tc
|
* @param {t.TestCase} _tc
|
||||||
@@ -498,33 +499,33 @@ export const testChangeEvent = tc => {
|
|||||||
changes = e.delta
|
changes = e.delta
|
||||||
})
|
})
|
||||||
map0.set('a', 1)
|
map0.set('a', 1)
|
||||||
let keyChange = changes.attrs.get('a')
|
let keyChange = changes.attrs.a
|
||||||
t.assert(delta.$insertOpWith(s.$number).check(keyChange) && keyChange.prevValue === undefined)
|
t.assert(delta.$insertOpWith(s.$number).check(keyChange) && keyChange.prevValue === undefined)
|
||||||
map0.set('a', 2)
|
map0.set('a', 2)
|
||||||
keyChange = changes.attrs.get('a')
|
keyChange = changes.attrs.a
|
||||||
t.assert(delta.$insertOpWith(s.$number).check(keyChange) && keyChange.prevValue === 1)
|
t.assert(delta.$insertOpWith(s.$number).check(keyChange) && keyChange.prevValue === 1)
|
||||||
users[0].transact(() => {
|
users[0].transact(() => {
|
||||||
map0.set('a', 3)
|
map0.set('a', 3)
|
||||||
map0.set('a', 4)
|
map0.set('a', 4)
|
||||||
})
|
})
|
||||||
keyChange = changes.attrs.get('a')
|
keyChange = changes.attrs.a
|
||||||
t.assert(delta.$insertOpWith(s.$number).check(keyChange) && keyChange.prevValue === 2)
|
t.assert(delta.$insertOpWith(s.$number).check(keyChange) && keyChange.prevValue === 2)
|
||||||
users[0].transact(() => {
|
users[0].transact(() => {
|
||||||
map0.set('b', 1)
|
map0.set('b', 1)
|
||||||
map0.set('b', 2)
|
map0.set('b', 2)
|
||||||
})
|
})
|
||||||
keyChange = changes.attrs.get('b')
|
keyChange = changes.attrs.b
|
||||||
t.assert(delta.$insertOpWith(s.$number).check(keyChange) && keyChange.prevValue === undefined)
|
t.assert(delta.$insertOpWith(s.$number).check(keyChange) && keyChange.prevValue === undefined)
|
||||||
users[0].transact(() => {
|
users[0].transact(() => {
|
||||||
map0.set('c', 1)
|
map0.set('c', 1)
|
||||||
map0.delete('c')
|
map0.delete('c')
|
||||||
})
|
})
|
||||||
t.assert(changes !== null && changes.attrs.size === 0)
|
t.assert(changes !== null && object.isEmpty(changes.attrs))
|
||||||
users[0].transact(() => {
|
users[0].transact(() => {
|
||||||
map0.set('d', 1)
|
map0.set('d', 1)
|
||||||
map0.set('d', 2)
|
map0.set('d', 2)
|
||||||
})
|
})
|
||||||
keyChange = changes.attrs.get('d')
|
keyChange = changes.attrs.d
|
||||||
t.assert(delta.$insertOpWith(s.$number).check(keyChange) && keyChange.prevValue === undefined)
|
t.assert(delta.$insertOpWith(s.$number).check(keyChange) && keyChange.prevValue === undefined)
|
||||||
compare(users)
|
compare(users)
|
||||||
}
|
}
|
||||||
@@ -635,7 +636,7 @@ export const testAttributedContent = _tc => {
|
|||||||
})
|
})
|
||||||
t.group('overwrite value', () => {
|
t.group('overwrite value', () => {
|
||||||
ymap.set('test', 'fourtytwo')
|
ymap.set('test', 'fourtytwo')
|
||||||
const expectedContent = { test: delta.$deltaMapChangeJson.expect({ type: 'insert', prevValue: 42, value: 'fourtytwo', attribution: { insert: [] } }) }
|
const expectedContent = { test: delta.$deltaMapChangeJson.expect({ type: 'insert', value: 'fourtytwo', attribution: { insert: [] } }) }
|
||||||
const attributedContent = ymap.getContent(attributionManager)
|
const attributedContent = ymap.getContent(attributionManager)
|
||||||
console.log(attributedContent)
|
console.log(attributedContent)
|
||||||
t.compare(expectedContent, attributedContent.toJSON().attrs)
|
t.compare(expectedContent, attributedContent.toJSON().attrs)
|
||||||
|
|||||||
@@ -1216,6 +1216,7 @@ export const testDeltaBug2 = _tc => {
|
|||||||
ytext.applyDelta(changeEvent)
|
ytext.applyDelta(changeEvent)
|
||||||
const d = ytext.getContent()
|
const d = ytext.getContent()
|
||||||
t.compare(list.toArray(d.children)[40].toJSON(), {
|
t.compare(list.toArray(d.children)[40].toJSON(), {
|
||||||
|
type: 'insert',
|
||||||
insert: '\n',
|
insert: '\n',
|
||||||
format: {
|
format: {
|
||||||
'block-id': 'block-9d6566a1-be55-4e20-999a-b990bc15e143'
|
'block-id': 'block-9d6566a1-be55-4e20-999a-b990bc15e143'
|
||||||
@@ -1242,11 +1243,12 @@ export const testDeltaAfterConcurrentFormatting = tc => {
|
|||||||
const deltas = []
|
const deltas = []
|
||||||
text1.observe(event => {
|
text1.observe(event => {
|
||||||
if (event.delta.children.len > 0) {
|
if (event.delta.children.len > 0) {
|
||||||
deltas.push(event.delta.toJSON())
|
deltas.push(event.delta)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
testConnector.flushAllMessages()
|
testConnector.flushAllMessages()
|
||||||
t.compare(deltas, [[{ retain: 2, format: { bold: true } }, { retain: 1 }, { retain: 1, format: { bold: null } }]])
|
t.assert(deltas.length === 1)
|
||||||
|
t.compare(deltas[0], delta.create().retain(2, { bold: true }).retain(1).retain(1, { bold: null }).done())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1295,29 +1297,29 @@ export const testBasicFormat = tc => {
|
|||||||
})
|
})
|
||||||
text0.insert(0, 'abc', { bold: true })
|
text0.insert(0, 'abc', { bold: true })
|
||||||
t.assert(text0.toString() === 'abc', 'Basic insert with attributes works')
|
t.assert(text0.toString() === 'abc', 'Basic insert with attributes works')
|
||||||
t.compare(text0.getContent(), delta.create().insert('abc', { bold: true }))
|
t.compare(text0.getContent(), delta.create().insert('abc', { bold: true }).done())
|
||||||
t.compare(eventDelta, delta.create().insert('abc', { bold: true }))
|
t.compare(eventDelta, delta.create().insert('abc', { bold: true }))
|
||||||
text0.delete(0, 1)
|
text0.delete(0, 1)
|
||||||
t.assert(text0.toString() === 'bc', 'Basic delete on formatted works (position 0)')
|
t.assert(text0.toString() === 'bc', 'Basic delete on formatted works (position 0)')
|
||||||
t.compare(text0.getContent(), delta.create().insert('bc', { bold: true }))
|
t.compare(text0.getContent(), delta.create().insert('bc', { bold: true }).done())
|
||||||
t.compare(eventDelta, delta.create().delete(1))
|
t.compare(eventDelta, delta.create().delete(1))
|
||||||
text0.delete(1, 1)
|
text0.delete(1, 1)
|
||||||
t.assert(text0.toString() === 'b', 'Basic delete works (position 1)')
|
t.assert(text0.toString() === 'b', 'Basic delete works (position 1)')
|
||||||
t.compare(text0.getContent(), delta.create().insert('b', { bold: true }))
|
t.compare(text0.getContent(), delta.create().insert('b', { bold: true }).done())
|
||||||
t.compare(eventDelta, delta.create().retain(1).delete(1))
|
t.compare(eventDelta, delta.create().retain(1).delete(1))
|
||||||
text0.insert(0, 'z', { bold: true })
|
text0.insert(0, 'z', { bold: true })
|
||||||
t.assert(text0.toString() === 'zb')
|
t.assert(text0.toString() === 'zb')
|
||||||
t.compare(text0.getContent(), delta.create().insert('zb', { bold: true }))
|
t.compare(text0.getContent(), delta.create().insert('zb', { bold: true }).done())
|
||||||
t.compare(eventDelta, delta.create().insert('z', { bold: true }))
|
t.compare(eventDelta, delta.create().insert('z', { bold: true }))
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
t.assert(text0._start.right.right.right.content.str === 'b', 'Does not insert duplicate attribute marker')
|
t.assert(text0._start.right.right.right.content.str === 'b', 'Does not insert duplicate attribute marker')
|
||||||
text0.insert(0, 'y')
|
text0.insert(0, 'y')
|
||||||
t.assert(text0.toString() === 'yzb')
|
t.assert(text0.toString() === 'yzb')
|
||||||
t.compare(text0.getContent(), delta.create().insert('y').insert('zb', { bold: true }))
|
t.compare(text0.getContent(), delta.create().insert('y').insert('zb', { bold: true }).done())
|
||||||
t.compare(eventDelta, delta.create().insert('y'))
|
t.compare(eventDelta, delta.create().insert('y'))
|
||||||
text0.format(0, 2, { bold: null })
|
text0.format(0, 2, { bold: null })
|
||||||
t.assert(text0.toString() === 'yzb')
|
t.assert(text0.toString() === 'yzb')
|
||||||
t.compare(text0.getContent(), delta.create().insert('yz').insert('b', { bold: true }))
|
t.compare(text0.getContent(), delta.create().insert('yz').insert('b', { bold: true }).done())
|
||||||
t.compare(eventDelta, delta.create().retain(1).retain(1, { bold: null }))
|
t.compare(eventDelta, delta.create().retain(1).retain(1, { bold: null }))
|
||||||
compare(users)
|
compare(users)
|
||||||
}
|
}
|
||||||
@@ -1332,14 +1334,14 @@ export const testFalsyFormats = tc => {
|
|||||||
delta = event.delta.toJSON().children
|
delta = event.delta.toJSON().children
|
||||||
})
|
})
|
||||||
text0.insert(0, 'abcde', { falsy: false })
|
text0.insert(0, 'abcde', { falsy: false })
|
||||||
t.compare(text0.getContent().toJSON().children, [{ insert: 'abcde', format: { falsy: false } }])
|
t.compare(text0.getContent().toJSON().children, [{ type: 'insert', insert: 'abcde', format: { falsy: false } }])
|
||||||
t.compare(delta, [{ insert: 'abcde', format: { falsy: false } }])
|
t.compare(delta, [{ type: 'insert', insert: 'abcde', format: { falsy: false } }])
|
||||||
text0.format(1, 3, { falsy: true })
|
text0.format(1, 3, { falsy: true })
|
||||||
t.compare(text0.getContent().toJSON().children, [{ insert: 'a', format: { falsy: false } }, { insert: 'bcd', format: { falsy: true } }, { insert: 'e', format: { falsy: false } }])
|
t.compare(text0.getContent().toJSON().children, [{ type: 'insert', insert: 'a', format: { falsy: false } }, { type: 'insert', insert: 'bcd', format: { falsy: true } }, { type: 'insert', insert: 'e', format: { falsy: false } }])
|
||||||
t.compare(delta, [{ retain: 1 }, { retain: 3, format: { falsy: true } }])
|
t.compare(delta, [{ type: 'retain', retain: 1 }, { type: 'retain', retain: 3, format: { falsy: true } }])
|
||||||
text0.format(2, 1, { falsy: false })
|
text0.format(2, 1, { falsy: false })
|
||||||
t.compare(text0.getContent().toJSON().children, [{ insert: 'a', format: { falsy: false } }, { insert: 'b', format: { falsy: true } }, { insert: 'c', format: { falsy: false } }, { insert: 'd', format: { falsy: true } }, { insert: 'e', format: { falsy: false } }])
|
t.compare(text0.getContent().toJSON().children, [{ type: 'insert', insert: 'a', format: { falsy: false } }, { type: 'insert', insert: 'b', format: { falsy: true } }, { type: 'insert', insert: 'c', format: { falsy: false } }, { type: 'insert', insert: 'd', format: { falsy: true } }, { type: 'insert', insert: 'e', format: { falsy: false } }])
|
||||||
t.compare(delta, [{ retain: 2 }, { retain: 1, format: { falsy: false } }])
|
t.compare(delta, [{ type: 'retain', retain: 2 }, { type: 'retain', retain: 1, format: { falsy: false } }])
|
||||||
compare(users)
|
compare(users)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1357,13 +1359,16 @@ export const testMultilineFormat = _tc => {
|
|||||||
.retain(1) // newline character
|
.retain(1) // newline character
|
||||||
.retain(10, { bold: true })
|
.retain(10, { bold: true })
|
||||||
testText.applyDelta(tt)
|
testText.applyDelta(tt)
|
||||||
t.compare(testText.getContent().toJSON().children, [
|
t.compare(
|
||||||
{ insert: 'Test', format: { bold: true } },
|
testText.getContent(),
|
||||||
{ insert: '\n' },
|
delta.create()
|
||||||
{ insert: 'Multi-line', format: { bold: true } },
|
.insert('Test', { bold: true })
|
||||||
{ insert: '\n' },
|
.insert('\n')
|
||||||
{ insert: 'Formatting', format: { bold: true } }
|
.insert('Multi-line', { bold: true })
|
||||||
])
|
.insert('\n')
|
||||||
|
.insert('Formatting', { bold: true })
|
||||||
|
.done()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1378,12 +1383,15 @@ export const testNotMergeEmptyLinesFormat = _tc => {
|
|||||||
.insert('\nText')
|
.insert('\nText')
|
||||||
.insert('\n', { title: true })
|
.insert('\n', { title: true })
|
||||||
)
|
)
|
||||||
t.compare(testText.getContent().toJSON().children, [
|
t.compare(
|
||||||
{ insert: 'Text' },
|
testText.getContent(),
|
||||||
{ insert: '\n', format: { title: true } },
|
delta.create()
|
||||||
{ insert: '\nText' },
|
.insert('Text')
|
||||||
{ insert: '\n', format: { title: true } }
|
.insert('\n', { title: true })
|
||||||
])
|
.insert('\nText')
|
||||||
|
.insert('\n', { title: true })
|
||||||
|
.done()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1402,10 +1410,12 @@ export const testPreserveAttributesThroughDelete = _tc => {
|
|||||||
.delete(1)
|
.delete(1)
|
||||||
.retain(1, { title: true })
|
.retain(1, { title: true })
|
||||||
)
|
)
|
||||||
t.compare(testText.getContent().toJSON().children, [
|
t.compare(testText.getContent(),
|
||||||
{ insert: 'Text' },
|
delta.create()
|
||||||
{ insert: '\n', format: { title: true } }
|
.insert('Text')
|
||||||
])
|
.insert('\n', { title: true })
|
||||||
|
.done()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1414,9 +1424,11 @@ export const testPreserveAttributesThroughDelete = _tc => {
|
|||||||
export const testGetDeltaWithEmbeds = tc => {
|
export const testGetDeltaWithEmbeds = tc => {
|
||||||
const { text0 } = init(tc, { users: 1 })
|
const { text0 } = init(tc, { users: 1 })
|
||||||
text0.applyDelta(delta.create().insert([{ linebreak: 's' }]))
|
text0.applyDelta(delta.create().insert([{ linebreak: 's' }]))
|
||||||
t.compare(text0.getContent().toJSON().children, [{
|
t.compare(text0.getContent(),
|
||||||
insert: [{ linebreak: 's' }]
|
delta.create()
|
||||||
}])
|
.insert([{ linebreak: 's' }])
|
||||||
|
.done()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1427,18 +1439,18 @@ export const testTypesAsEmbed = tc => {
|
|||||||
text0.applyDelta(delta.create()
|
text0.applyDelta(delta.create()
|
||||||
.insert([new Y.Map([['key', 'val']])])
|
.insert([new Y.Map([['key', 'val']])])
|
||||||
)
|
)
|
||||||
t.compare(/** @type {any} */ (text0).getContentDeep().toJSON().children[0]?.insert, { key: 'val' })
|
t.compare(/** @type {any} */ (text0).getContentDeep().toJSON().children, [{ type: 'insert', insert: [{ attrs: { key: { type: 'insert', value: 'val' } }}] }])
|
||||||
let firedEvent = false
|
let firedEvent = false
|
||||||
text1.observe(event => {
|
text1.observe(event => {
|
||||||
const d = event.delta
|
const d = event.deltaDeep
|
||||||
t.assert(d.children.len === 1)
|
t.assert(d.children.len === 1)
|
||||||
t.compare(list.toArray(d.children).map(x => /** @type {any} */ (x).insert.toJSON()), [{ key: 'val' }])
|
t.compare(d.toJSON().children?.map(x => /** @type {any} */ (x).insert), [[{ key: { type: 'insert', value: 'val' } }]])
|
||||||
firedEvent = true
|
firedEvent = true
|
||||||
})
|
})
|
||||||
testConnector.flushAllMessages()
|
testConnector.flushAllMessages()
|
||||||
const dd = text1.getContent().toJSON().children
|
const dd = text1.getContent().toJSON().children
|
||||||
t.assert(dd?.length === 1)
|
t.assert(dd?.length === 1)
|
||||||
t.compare(/** @type {any} */ (dd?.[0]).insert.toJSON(), { key: 'val' })
|
t.compare(/** @type {any} */ (dd?.[0]).insert, { key: 'val' })
|
||||||
t.assert(firedEvent, 'fired the event observer containing a Type-Embed')
|
t.assert(firedEvent, 'fired the event observer containing a Type-Embed')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1463,12 +1475,19 @@ export const testSnapshot = tc => {
|
|||||||
.delete(1)
|
.delete(1)
|
||||||
)
|
)
|
||||||
const state1 = text0.getContent(createAttributionManagerFromSnapshots(snapshot1))
|
const state1 = text0.getContent(createAttributionManagerFromSnapshots(snapshot1))
|
||||||
t.compare(state1.toJSON().children, [{ insert: 'abcd' }])
|
t.compare(state1, delta.create().insert('abcd').done())
|
||||||
const state2 = text0.getContent(createAttributionManagerFromSnapshots(snapshot2))
|
const state2 = text0.getContent(createAttributionManagerFromSnapshots(snapshot2))
|
||||||
t.compare(state2.toJSON().children, [{ insert: 'axcd' }])
|
t.compare(state2, delta.create().insert('axcd').done())
|
||||||
const state2Diff = text0.getContent(createAttributionManagerFromSnapshots(snapshot1, snapshot2)).toJSON().children
|
const state2Diff = text0.getContent(createAttributionManagerFromSnapshots(snapshot1, snapshot2))
|
||||||
const expected = [{ insert: 'a' }, { insert: 'x', attribution: { insert: [] } }, { insert: 'b', attribution: { delete: [] } }, { insert: 'cd' }]
|
t.compare(
|
||||||
t.compare(state2Diff, expected)
|
state2Diff,
|
||||||
|
delta.create()
|
||||||
|
.insert('a')
|
||||||
|
.insert('x', null, { insert: [] })
|
||||||
|
.insert('b', null, { delete: [] })
|
||||||
|
.insert('cd')
|
||||||
|
.done()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1506,8 +1525,15 @@ export const testToDeltaEmbedAttributes = tc => {
|
|||||||
const { text0 } = init(tc, { users: 1 })
|
const { text0 } = init(tc, { users: 1 })
|
||||||
text0.insert(0, 'ab', { bold: true })
|
text0.insert(0, 'ab', { bold: true })
|
||||||
text0.insertEmbed(1, { image: 'imageSrc.png' }, { width: 100 })
|
text0.insertEmbed(1, { image: 'imageSrc.png' }, { width: 100 })
|
||||||
const delta0 = text0.getContent().toJSON().children
|
const delta0 = text0.getContent()
|
||||||
t.compare(delta0, [{ insert: 'a', format: { bold: true } }, { insert: [{ image: 'imageSrc.png' }], format: { width: 100 } }, { insert: 'b', format: { bold: true } }])
|
t.compare(
|
||||||
|
delta0,
|
||||||
|
delta.create()
|
||||||
|
.insert('a', { bold: true })
|
||||||
|
.insert([{ image: 'imageSrc.png' }], { width: 100 })
|
||||||
|
.insert('b', { bold: true })
|
||||||
|
.done()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1517,8 +1543,16 @@ export const testToDeltaEmbedNoAttributes = tc => {
|
|||||||
const { text0 } = init(tc, { users: 1 })
|
const { text0 } = init(tc, { users: 1 })
|
||||||
text0.insert(0, 'ab', { bold: true })
|
text0.insert(0, 'ab', { bold: true })
|
||||||
text0.insertEmbed(1, { image: 'imageSrc.png' })
|
text0.insertEmbed(1, { image: 'imageSrc.png' })
|
||||||
const delta0 = text0.getContent().toJSON().children
|
const delta0 = text0.getContent()
|
||||||
t.compare(delta0, [{ insert: 'a', format: { bold: true } }, { insert: [{ image: 'imageSrc.png' }] }, { insert: 'b', format: { bold: true } }], 'toDelta does not set attributes key when no attributes are present')
|
t.compare(
|
||||||
|
delta0,
|
||||||
|
delta.create()
|
||||||
|
.insert('a', { bold: true })
|
||||||
|
.insert([{ image: 'imageSrc.png' }])
|
||||||
|
.insert('b', { bold: true })
|
||||||
|
.done()
|
||||||
|
, 'toDelta does not set attributes key when no attributes are present'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1528,6 +1562,7 @@ export const testFormattingRemoved = tc => {
|
|||||||
const { text0 } = init(tc, { users: 1 })
|
const { text0 } = init(tc, { users: 1 })
|
||||||
text0.insert(0, 'ab', { bold: true })
|
text0.insert(0, 'ab', { bold: true })
|
||||||
text0.delete(0, 2)
|
text0.delete(0, 2)
|
||||||
|
// @ts-ignore
|
||||||
t.assert(Y.getTypeChildren(text0).length === 1)
|
t.assert(Y.getTypeChildren(text0).length === 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1571,9 +1606,7 @@ export const testFormattingDeltaUnnecessaryAttributeChange = tc => {
|
|||||||
testConnector.flushAllMessages()
|
testConnector.flushAllMessages()
|
||||||
const filteredDeltas = deltas.filter(d => d.children.len > 0)
|
const filteredDeltas = deltas.filter(d => d.children.len > 0)
|
||||||
t.assert(filteredDeltas.length === 2)
|
t.assert(filteredDeltas.length === 2)
|
||||||
t.compare(filteredDeltas[0].toJSON().children, [
|
t.compare(filteredDeltas[0], delta.create().retain(1, { LIST_STYLES: 'number' }).done())
|
||||||
{ retain: 1, format: { LIST_STYLES: 'number' } }
|
|
||||||
])
|
|
||||||
t.compare(filteredDeltas[0], filteredDeltas[1])
|
t.compare(filteredDeltas[0], filteredDeltas[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1820,12 +1853,12 @@ export const testFormattingBug = async _tc => {
|
|||||||
ydoc2.getText().format(1, 1, { url: 'http://docs.yjs.dev' })
|
ydoc2.getText().format(1, 1, { url: 'http://docs.yjs.dev' })
|
||||||
Y.applyUpdate(ydoc2, Y.encodeStateAsUpdate(ydoc1))
|
Y.applyUpdate(ydoc2, Y.encodeStateAsUpdate(ydoc1))
|
||||||
const text2 = ydoc2.getText()
|
const text2 = ydoc2.getText()
|
||||||
const expectedResult = [
|
const expectedResult = delta.create()
|
||||||
{ insert: '\n', format: { url: 'http://example.com' } },
|
.insert('\n', { url: 'http://example.com' })
|
||||||
{ insert: '\n', format: { url: 'http://docs.yjs.dev' } },
|
.insert('\n', { url: 'http://docs.yjs.dev' })
|
||||||
{ insert: '\n', format: { url: 'http://example.com' } }
|
.insert('\n', { url: 'http://example.com' })
|
||||||
]
|
.done()
|
||||||
t.compare(text1.getContent().toJSON().children, expectedResult)
|
t.compare(text1.getContent(), expectedResult)
|
||||||
t.compare(text1.getContent().toJSON(), text2.getContent().toJSON())
|
t.compare(text1.getContent().toJSON(), text2.getContent().toJSON())
|
||||||
console.log(text1.getContent().toJSON())
|
console.log(text1.getContent().toJSON())
|
||||||
}
|
}
|
||||||
@@ -1850,13 +1883,13 @@ export const testDeleteFormatting = _tc => {
|
|||||||
text.format(16, 4, { bold: null })
|
text.format(16, 4, { bold: null })
|
||||||
Y.applyUpdate(doc2, Y.encodeStateAsUpdate(doc))
|
Y.applyUpdate(doc2, Y.encodeStateAsUpdate(doc))
|
||||||
|
|
||||||
const expected = [
|
const expected = delta.create()
|
||||||
{ insert: 'Attack ships ' },
|
.insert('Attack ships ')
|
||||||
{ insert: 'on ', format: { bold: true } },
|
.insert('on ', { bold: true })
|
||||||
{ insert: 'fire off the shoulder of Orion.' }
|
.insert('fire off the shoulder of Orion.')
|
||||||
]
|
.done()
|
||||||
t.compare(text.getContent().toJSON().children, expected)
|
t.compare(text.getContent(), expected)
|
||||||
t.compare(text2.getContent().toJSON().children, expected)
|
t.compare(text2.getContent(), expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ export const testYtextAttributes = _tc => {
|
|||||||
const ydoc = new Y.Doc()
|
const ydoc = new Y.Doc()
|
||||||
const ytext = /** @type {Y.XmlText} */ (ydoc.get('', Y.XmlText))
|
const ytext = /** @type {Y.XmlText} */ (ydoc.get('', Y.XmlText))
|
||||||
ytext.observe(event => {
|
ytext.observe(event => {
|
||||||
t.assert(event.delta.attrs.get('test')?.type === 'insert')
|
t.assert(event.delta.attrs.test?.type === 'insert')
|
||||||
})
|
})
|
||||||
ytext.setAttribute('test', 42)
|
ytext.setAttribute('test', 42)
|
||||||
t.compare(ytext.getAttribute('test'), 42)
|
t.compare(ytext.getAttribute('test'), 42)
|
||||||
@@ -124,7 +124,7 @@ export const testSiblings = _tc => {
|
|||||||
yxml.insert(0, [first, second])
|
yxml.insert(0, [first, second])
|
||||||
t.assert(first.nextSibling === second)
|
t.assert(first.nextSibling === second)
|
||||||
t.assert(second.prevSibling === first)
|
t.assert(second.prevSibling === first)
|
||||||
t.assert(first.parent === yxml)
|
t.assert(first.parent === /** @type {Y.AbstractType<any>} */ (yxml))
|
||||||
t.assert(yxml.parent === null)
|
t.assert(yxml.parent === null)
|
||||||
t.assert(yxml.firstChild === first)
|
t.assert(yxml.firstChild === first)
|
||||||
}
|
}
|
||||||
@@ -272,7 +272,7 @@ export const testElementAttributedContent = _tc => {
|
|||||||
console.log('cs expec', JSON.stringify(expectedContent.toJSON(), null, 2))
|
console.log('cs expec', JSON.stringify(expectedContent.toJSON(), null, 2))
|
||||||
console.log('attributes', attributedContent.toJSON().attrs)
|
console.log('attributes', attributedContent.toJSON().attrs)
|
||||||
t.assert(attributedContent.equals(expectedContent))
|
t.assert(attributedContent.equals(expectedContent))
|
||||||
t.compare(attributedContent, /** @type {delta.MapDelta<any>} */ (delta.map()).set('key', '42', { insert: [] }))
|
t.compare(attributedContent, delta.map().set('key', '42', { insert: [] }))
|
||||||
t.compare(attributedContent.toJSON().attrs, { key: { type: 'insert', prevValue: undefined, value: '42', attribution: { insert: [] } } })
|
t.compare(attributedContent.toJSON().attrs, { key: { type: 'insert', prevValue: undefined, value: '42', attribution: { insert: [] } } })
|
||||||
t.assert(attributedContent.name === 'UNDEFINED')
|
t.assert(attributedContent.name === 'UNDEFINED')
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user