From 9aab5a983a52606f3819457c83283c8d0d352d38 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Mon, 3 Feb 2020 11:31:24 +0100 Subject: [PATCH] add type generation --- package-lock.json | 46 ++++++++++++++++++++++++++++++++++++ package.json | 4 +++- src/plugins/cursor-plugin.js | 1 + src/plugins/sync-plugin.js | 4 ++++ tsconfig.json | 30 +++++++++++++---------- 5 files changed, 71 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0edbea1..a9fbc79 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,6 +51,52 @@ "integrity": "sha512-Jg1F+bmxcpENHP23sVKkNuU3uaxPnsBMW0cLjleiikFKomJQbsn0Cqk2yDvQArqzZN6ABfBkZ0To7pQ8sLdWDg==", "dev": true }, + "@types/orderedmap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/orderedmap/-/orderedmap-1.0.0.tgz", + "integrity": "sha512-dxKo80TqYx3YtBipHwA/SdFmMMyLCnP+5mkEqN0eMjcTBzHkiiX0ES118DsjDBjvD+zeSsSU9jULTZ+frog+Gw==", + "dev": true + }, + "@types/prosemirror-model": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/@types/prosemirror-model/-/prosemirror-model-1.7.2.tgz", + "integrity": "sha512-2l+yXvidg3AUHN07mO4Jd8Q84fo6ksFsy7LHUurLYrZ74uTahBp2fzcO49AKZMzww2EulXJ40Kl/OFaQ/7A1fw==", + "dev": true, + "requires": { + "@types/orderedmap": "*" + } + }, + "@types/prosemirror-state": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@types/prosemirror-state/-/prosemirror-state-1.2.3.tgz", + "integrity": "sha512-6m433Hubix9bx+JgcLW7zzyiZuzwjq5mBdSMYY4Yi5c5ZpV2RiVmg7Cy6f9Thtts8vuztilw+PczJAgDm1Frfw==", + "dev": true, + "requires": { + "@types/prosemirror-model": "*", + "@types/prosemirror-transform": "*", + "@types/prosemirror-view": "*" + } + }, + "@types/prosemirror-transform": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@types/prosemirror-transform/-/prosemirror-transform-1.1.1.tgz", + "integrity": "sha512-yYCYSoiRH+Wcbl8GJc0PFCzeyMzNQ1vL2xrHHSXZuNcIlH75VoiKrZFeZ6BS9cl8mYXjZrlmdBe8YOxYvyKM6A==", + "dev": true, + "requires": { + "@types/prosemirror-model": "*" + } + }, + "@types/prosemirror-view": { + "version": "1.11.2", + "resolved": "https://registry.npmjs.org/@types/prosemirror-view/-/prosemirror-view-1.11.2.tgz", + "integrity": "sha512-EKcQmR4KdkFZU13wS5pWrkSojRCPGqz/l/uzpZFfW5cgdr7fQsftf2/ttvIjpk1a94ISifEY4UZwflVJ+uL4Rg==", + "dev": true, + "requires": { + "@types/prosemirror-model": "*", + "@types/prosemirror-state": "*", + "@types/prosemirror-transform": "*" + } + }, "@types/resolve": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-0.0.8.tgz", diff --git a/package.json b/package.json index 8dce0a8..12e33e2 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/plugins/cursor-plugin.js b/src/plugins/cursor-plugin.js index 98ebed7..021a2f7 100644 --- a/src/plugins/cursor-plugin.js +++ b/src/plugins/cursor-plugin.js @@ -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 })) } diff --git a/src/plugins/sync-plugin.js b/src/plugins/sync-plugin.js index b38f419..6a27a30 100644 --- a/src/plugins/sync-plugin.js +++ b/src/plugins/sync-plugin.js @@ -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) @@ -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) }) @@ -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) @@ -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 }) diff --git a/tsconfig.json b/tsconfig.json index 1ddaa22..832355c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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. */ @@ -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/*"] @@ -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 */ @@ -60,5 +64,5 @@ "maxNodeModuleJsDepth": 5 }, "include": ["./src/**/*"], - "exclude": ["./node_modules"] + "exclude": ["../lib0/**/*", "node_modules/**/*", "dist", "dist/**/*.js"] }