Skip to content

Commit

Permalink
bump lib0 and yjs dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Jahns committed Feb 19, 2020
2 parents c9b71d6 + 1553c5b commit dcdd7d1
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 53 deletions.
86 changes: 66 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "y-prosemirror",
"version": "0.2.4",
"version": "0.3.2",
"description": "Prosemirror bindings for Yjs",
"main": "./dist/y-prosemirror.cjs",
"module": "./src/y-prosemirror.js",
"types": "./dist/src/y-prosemirror.d.ts",
"sideEffects": false,
"scripts": {
"dist": "rm -rf dist && rollup -c",
"dist": "rm -rf dist && rollup -c && tsc",
"test": "rollup -c && node dist/test.cjs",
"lint": "standard",
"watch": "rollup -wc",
Expand Down Expand Up @@ -41,7 +42,7 @@
"lib0": "^0.2.15"
},
"peerDependencies": {
"yjs": ">=13.0.0-106",
"yjs": "^13.0.0",
"y-protocols": "^0.2.0",
"prosemirror-model": "^1.7.1",
"prosemirror-state": "^1.2.3",
Expand All @@ -50,17 +51,18 @@
"devDependencies": {
"@rollup/plugin-commonjs": "^11.0.1",
"@rollup/plugin-node-resolve": "^7.0.0",
"@types/prosemirror-state": "^1.2.3",
"concurrently": "^4.1.0",
"http-server": "^0.12.1",
"jsdom": "^15.1.1",
"prosemirror-model": "^1.7.1",
"prosemirror-model": "^1.9.1",
"prosemirror-schema-basic": "^1.0.1",
"prosemirror-state": "^1.2.3",
"prosemirror-view": "^1.9.10",
"rollup": "^1.29.0",
"prosemirror-view": "^1.13.8",
"rollup": "^1.29.1",
"standard": "^12.0.1",
"typescript": "^3.7.4",
"typescript": "^3.7.5",
"y-protocols": "^0.2.0",
"yjs": "13.0.0-106"
"yjs": "13.0.0"
}
}
1 change: 0 additions & 1 deletion src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ProsemirrorMapping } from './plugins/sync-plugin.js' // eslint-disable-

import * as Y from 'yjs'
import * as error from 'lib0/error.js'
import * as PModel from 'prosemirror-model' // eslint-disable-line

/**
* Transforms a Prosemirror based absolute position to a Yjs Cursor (relative position in the Yjs model).
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/cursor-plugin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import * as Y from 'yjs'
import { Decoration, DecorationSet } from 'prosemirror-view' // eslint-disable-line
import { Plugin, PluginKey, EditorState, TextSelection } from 'prosemirror-state' // eslint-disable-line
import { Plugin, PluginKey } from 'prosemirror-state' // eslint-disable-line
import { Awareness } from 'y-protocols/awareness.js' // eslint-disable-line
import { ySyncPluginKey } from './sync-plugin.js'
import { absolutePositionToRelativePosition, relativePositionToAbsolutePosition } from '../lib.js'
Expand All @@ -24,7 +24,7 @@ export const createDecorations = (state, awareness) => {
const ystate = ySyncPluginKey.getState(state)
const y = ystate.doc
const decorations = []
if (ystate.snapshot != null || ystate.binding === null) {
if (ystate.snapshot != null || ystate.prevSnapshot != null || ystate.binding === null) {
// do not render cursors while snapshot is active
return DecorationSet.create(state.doc, [])
}
Expand Down Expand Up @@ -96,6 +96,7 @@ export const yCursorPlugin = awareness => new Plugin({
view: view => {
const awarenessListener = () => {
setTimeout(() => {
// @ts-ignore
if (view.docView) {
view.dispatch(view.state.tr.setMeta(yCursorPluginKey, { awarenessUpdated: true }))
}
Expand Down
15 changes: 9 additions & 6 deletions src/plugins/sync-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import { createMutex } from 'lib0/mutex.js'
import * as PModel from 'prosemirror-model'
import { EditorView, Decoration, DecorationSet } from 'prosemirror-view' // eslint-disable-line
import { Plugin, PluginKey, EditorState, TextSelection } from 'prosemirror-state' // eslint-disable-line
import * as math from 'lib0/math.js'
import * as object from 'lib0/object.js'
Expand Down Expand Up @@ -226,6 +225,7 @@ export class ProsemirrorBinding {
this.mapping = new Map()
this.mux(() => {
const fragmentContent = this.type.toArray().map(t => createNodeFromYElement(/** @type {Y.XmlElement} */ (t), this.prosemirrorView.state.schema, this.mapping)).filter(n => n !== null)
// @ts-ignore
const tr = this.prosemirrorView.state.tr.replace(0, this.prosemirrorView.state.doc.content.size, new PModel.Slice(new PModel.Fragment(fragmentContent), 0, 0))
tr.setMeta(ySyncPluginKey, { snapshot: null, prevSnapshot: null })
this.prosemirrorView.dispatch(tr)
Expand All @@ -235,6 +235,7 @@ export class ProsemirrorBinding {
this.mapping = new Map()
this.mux(() => {
const fragmentContent = this.type.toArray().map(t => createNodeFromYElement(/** @type {Y.XmlElement} */ (t), this.prosemirrorView.state.schema, this.mapping)).filter(n => n !== null)
// @ts-ignore
const tr = this.prosemirrorView.state.tr.replace(0, this.prosemirrorView.state.doc.content.size, new PModel.Slice(new PModel.Fragment(fragmentContent), 0, 0))
this.prosemirrorView.dispatch(tr)
})
Expand Down Expand Up @@ -278,9 +279,10 @@ export class ProsemirrorBinding {
return null
}
}).filter(n => n !== null)
// @ts-ignore
const tr = this.prosemirrorView.state.tr.replace(0, this.prosemirrorView.state.doc.content.size, new PModel.Slice(new PModel.Fragment(fragmentContent), 0, 0))
this.prosemirrorView.dispatch(tr)
})
}, ySyncPluginKey)
})
}
/**
Expand All @@ -304,6 +306,7 @@ export class ProsemirrorBinding {
transaction.changed.forEach(delType)
transaction.changedParentTypes.forEach(delType)
const fragmentContent = this.type.toArray().map(t => createNodeIfNotExists(/** @type {Y.XmlElement | Y.XmlHook} */ (t), this.prosemirrorView.state.schema, this.mapping)).filter(n => n !== null)
// @ts-ignore
let tr = this.prosemirrorView.state.tr.replace(0, this.prosemirrorView.state.doc.content.size, new PModel.Slice(new PModel.Fragment(fragmentContent), 0, 0))
restoreRelativeSelection(tr, this.beforeTransactionSelection, this)
tr = tr.setMeta(ySyncPluginKey, { isChangeOrigin: true })
Expand All @@ -318,7 +321,7 @@ export class ProsemirrorBinding {
this.doc.transact(() => {
updateYFragment(this.doc, this.type, doc, this.mapping)
this.beforeTransactionSelection = getRelativeSelection(this, this.prosemirrorView.state)
})
}, ySyncPluginKey)
})
}
destroy () {
Expand Down Expand Up @@ -398,7 +401,7 @@ export const createNodeFromYElement = (el, schema, mapping, snapshot, prevSnapsh
// an error occured while creating the node. This is probably a result of a concurrent action.
/** @type {Y.Doc} */ (el.doc).transact(transaction => {
/** @type {Y.Item} */ (el._item).delete(transaction)
})
}, ySyncPluginKey)
mapping.delete(el)
return null
}
Expand Down Expand Up @@ -430,7 +433,7 @@ export const createTextNodesFromYText = (text, schema, mapping, snapshot, prevSn
// an error occured while creating the node. This is probably a result of a concurrent action.
/** @type {Y.Doc} */ (text.doc).transact(transaction => {
/** @type {Y.Item} */ (text._item).delete(transaction)
})
}, ySyncPluginKey)
return null
}
// @ts-ignore
Expand Down Expand Up @@ -756,7 +759,7 @@ const updateYFragment = (y, yDomFragment, pNode, mapping) => {
}
yDomFragment.insert(left, ins)
}
})
}, ySyncPluginKey)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/undo-plugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { Plugin, PluginKey, EditorState, TextSelection } from 'prosemirror-state' // eslint-disable-line
import { Plugin, PluginKey } from 'prosemirror-state' // eslint-disable-line

import { ySyncPluginKey, getRelativeSelection } from './sync-plugin.js'
import { UndoManager, Item, ContentType, XmlElement, Text } from 'yjs'
Expand Down Expand Up @@ -29,7 +29,7 @@ export const yUndoPlugin = ({ protectedNodes = new Set(['paragraph']), trackedOr
// TODO: check if plugin order matches and fix
const ystate = ySyncPluginKey.getState(state)
const undoManager = new UndoManager(ystate.type, {
trackedOrigins: new Set([null, ySyncPluginKey].concat(trackedOrigins)),
trackedOrigins: new Set([ySyncPluginKey].concat(trackedOrigins)),
deleteFilter: item => !(item instanceof Item) ||
!(item.content instanceof ContentType) ||
!(item.content.type instanceof Text ||
Expand Down
31 changes: 17 additions & 14 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@
"compilerOptions": {
/* Basic Options */
"target": "es2018",
"lib": ["es2018", "dom"], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
"checkJs": true, /* Report errors in .js files. */
"lib": [
"es2018",
"dom"
] /* Specify library files to be included in the compilation. */,
"allowJs": true /* Allow javascript files to be compiled. */,
"checkJs": true /* Report errors in .js files. */,
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
"declaration": true /* Generates corresponding '.d.ts' file. */,
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./build", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"outDir": "./dist" /* Redirect output structure to the directory. */,
"rootDir": "./" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true, /* Do not emit outputs. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": false, /* Enable all strict type-checking options. */
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
"strict": false /* Enable all strict type-checking options. */,
"noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */,
"emitDeclarationOnly": true,
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
Expand All @@ -35,8 +39,8 @@
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
"baseUrl": "./" /* Base directory to resolve non-absolute module names. */,
"paths": {
"yjs": ["node_modules/yjs/src/index.js"],
"lib0/*": ["node_modules/lib0/*"]
Expand All @@ -45,7 +49,7 @@
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

/* Source Map Options */
Expand All @@ -57,8 +61,7 @@
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"maxNodeModuleJsDepth": 5
},
"include": ["./src/**/*"],
"exclude": ["./node_modules"]
"exclude": ["../lib0/**/*", "node_modules/**/*", "dist", "dist/**/*.js"]
}

0 comments on commit dcdd7d1

Please sign in to comment.