Skip to content

Commit

Permalink
Merge pull request #11 from yjs/add-type-generation
Browse files Browse the repository at this point in the history
add type generation
  • Loading branch information
dmonad authored Feb 3, 2020
2 parents ec2b5bf + 9aab5a9 commit a8f742f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 14 deletions.
46 changes: 46 additions & 0 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"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 @@ -50,6 +51,7 @@
"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",
Expand Down
1 change: 1 addition & 0 deletions src/plugins/cursor-plugin.js
Original file line number Diff line number Diff line change
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
4 changes: 4 additions & 0 deletions src/plugins/sync-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,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 +236,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,6 +280,7 @@ 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 +307,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 Down
30 changes: 17 additions & 13 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 @@ -60,5 +64,5 @@
"maxNodeModuleJsDepth": 5
},
"include": ["./src/**/*"],
"exclude": ["./node_modules"]
"exclude": ["../lib0/**/*", "node_modules/**/*", "dist", "dist/**/*.js"]
}

0 comments on commit a8f742f

Please sign in to comment.