Skip to content

Commit 457d2f8

Browse files
committed
bump to latest yjs and fix tests
1 parent 5ca430e commit 457d2f8

File tree

7 files changed

+79
-39
lines changed

7 files changed

+79
-39
lines changed

demo/codemirror.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,8 @@ providerYdoc.awareness.setLocalStateField('user', {
111111
let currentView = null
112112
const initEditorBinding = () => {
113113
const withSuggestions = elemToggleShowSuggestions.checked
114-
/**
115-
* @type {Y.Text<never>}
116-
*/
117-
const ytext = /** @type {any} */ ((withSuggestions ? suggestionDoc : ydoc).getText('quill'))
118-
const docContent = ytext.getContent(attributionManager).children.map(s.match().if(delta.TextOp, op => op.insert).else(() => '').done()).join('')
114+
const ytext = (withSuggestions ? suggestionDoc : ydoc).get('quill')
115+
const docContent = ytext.toDelta(attributionManager).children.map(s.match().if(delta.TextOp, op => op.insert).else(() => '').done()).join('')
119116
const state = EditorState.create({
120117
doc: docContent,
121118
extensions: [

package-lock.json

Lines changed: 61 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
"@codemirror/state": "^6.5.2",
5454
"@codemirror/view": "^6.38.6",
5555
"@y/protocols": "^1.0.6-3",
56-
"@y/y": "^14.0.0-16"
56+
"@y/y": "^14.0.0-21"
5757
},
5858
"dependencies": {
59-
"lib0": "^0.2.115"
59+
"lib0": "^1.0.0-0"
6060
},
6161
"devDependencies": {
6262
"@codemirror/lang-javascript": "^6.2.4",
@@ -75,6 +75,6 @@
7575
"rollup": "^4.53.3",
7676
"standard": "^17.1.2",
7777
"typescript": "^5.9.3",
78-
"@y/y": "^14.0.0-16"
78+
"@y/y": "^14.0.0-21"
7979
}
8080
}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { yUndoManager, yUndoManagerFacet, YUndoManagerConfig, undo, redo, yUndoM
1010
export { YRange, yRemoteSelections, yRemoteSelectionsTheme, ySync, ySyncFacet, YSyncConfig, ySyncAnnotation, yUndoManagerKeymap }
1111

1212
/**
13-
* @param {Y.Text<never>} ytext
13+
* @param {Y.Type<{text: true}>} ytext
1414
* @param {any} awareness
1515
* @param {Object} [opts]
1616
* @param {Y.UndoManager | false} [opts.undoManager] Set undoManager to false to disable the undo-redo plugin

src/y-sync.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const yAttributionDecorations = cmState.StateField.define({
1010
create (state) {
1111
const conf = state.facet(ySyncFacet)
1212
const ytext = conf.ytext
13-
const delta = ytext.getContent(conf.am, { retainInserts: true, retainDeletes: true })
13+
const delta = ytext.toDelta(conf.am, { retainInserts: true, retainDeletes: true })
1414
const { decorations } = ydeltaToCmChanges(delta, false)
1515
return cmView.Decoration.set(decorations)
1616
},
@@ -78,13 +78,13 @@ const createAttributionDecoration = (type, username) => {
7878

7979
export class YSyncConfig {
8080
/**
81-
* @param {Y.Text<never>} ytext
81+
* @param {Y.Type<{ text: true }>} ytext
8282
* @param {import('@y/protocols/awareness').Awareness} awareness
8383
* @param {Y.AbstractAttributionManager} am
8484
*/
8585
constructor (ytext, awareness, am) {
8686
/**
87-
* @type {Y.Text<never>}
87+
* @type {Y.Type<{ text: true }>}
8888
*/
8989
this.ytext = ytext
9090
this.awareness = awareness
@@ -235,12 +235,12 @@ class YSyncPluginValue {
235235
this._ytext = this.conf.ytext
236236
this._observer = this._ytext.observe((event, tr) => {
237237
/**
238-
* @type {delta.DeltaAny?}
238+
* @type {delta.Delta<{text: true}>?}
239239
*/
240240
let delta = null
241241
if (tr.origin === this.conf && this.conf.am !== Y.noAttributionsManager) {
242242
const changes = Y.mergeIdSets([tr.insertSet, tr.deleteSet])
243-
delta = this._ytext.getContent(this.conf.am, { itemsToRender: changes, retainInserts: true })
243+
delta = this._ytext.toDelta(this.conf.am, { itemsToRender: changes, retainInserts: true })
244244
} else if (tr.origin !== this.conf) {
245245
delta = event.getDelta(this.conf.am)
246246
}
@@ -252,7 +252,7 @@ class YSyncPluginValue {
252252
}
253253
})
254254
this._onAttrChange = this.conf.am.on('change', (changes) => {
255-
const delta = this._ytext.getContent(this.conf.am, { itemsToRender: changes, retainInserts: true, retainDeletes: true })
255+
const delta = this._ytext.toDelta(this.conf.am, { itemsToRender: changes, retainInserts: true, retainDeletes: true })
256256
if (!delta.isEmpty()) {
257257
const { changes, decorations } = ydeltaToCmChanges(delta, false)
258258
if (changes.length > 0 && decorations.length > 0) {
@@ -276,7 +276,7 @@ class YSyncPluginValue {
276276
* This variable adjusts the fromA position to the current position in the Y.Text type.
277277
*/
278278
let adj = 0
279-
const d = delta.text()
279+
const d = delta.create(delta.$delta({ text: true }))
280280
update.changes.iterChanges((fromA, toA, fromB, toB, insert) => {
281281
const insertText = insert.sliceString(0, insert.length, '\n')
282282
if (fromA !== toA) {
@@ -290,7 +290,7 @@ class YSyncPluginValue {
290290
ytext.applyDelta(d, this.conf.am)
291291
const attributedDeletes = tr.meta.get('attributedDeletes')
292292
if (attributedDeletes != null) {
293-
const updateFix = this._ytext.getContent(this.conf.am, { itemsToRender: attributedDeletes })
293+
const updateFix = this._ytext.toDelta(this.conf.am, { itemsToRender: attributedDeletes })
294294
const { changes, decorations } = ydeltaToCmChanges(updateFix, false)
295295
const dispatch = () => this.view.dispatch({ changes, annotations: [ySyncAnnotation.of(this.conf), yAttributionAnnotation.of(decorations)] })
296296
setTimeout(dispatch, 0)

test/test.node.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ document.getSelection = () => ({ })
2323
global.requestAnimationFrame = f => setTimeout(f, 0)
2424
window.Element.prototype.scrollTo = () => {}
2525
global.scrollTo = () => {}
26+
window.requestAnimationFrame = setTimeout
2627

2728
document.createRange = () => ({
2829
setStart () {},

test/y-codemirror.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import { applyRandomTests } from '@y/y/testHelper'
1010
import { yCollab } from '@y/codemirror'
1111

1212
/**
13-
* @param {any} ydoc
13+
* @param {Y.Doc} ydoc
1414
* @return {EditorView}
1515
*/
1616
const createNewCodemirror = ydoc => {
1717
const state = EditorState.create({
18-
doc: ydoc.getText().toString(),
18+
doc: ydoc.get().toString(),
1919
extensions: [
2020
basicSetup,
21-
yCollab(ydoc.getText(), null, { undoManager: false })
21+
yCollab(ydoc.get(), null, { undoManager: false })
2222
]
2323
})
2424
return new EditorView({ state })

0 commit comments

Comments
 (0)