Compare commits

...

8 Commits

Author SHA1 Message Date
Kevin Jahns
0fb55981ba 13.0.0 2020-01-23 21:53:02 +01:00
Kevin Jahns
89378e29ae publish stable Yjs release 🎆 2020-01-23 21:51:26 +01:00
Kevin Jahns
cce35270ec typescript typingis!!! fixes #180 2020-01-23 21:45:56 +01:00
Kevin Jahns
d78180bf97 make opts optional in PermanentUserData 2020-01-23 18:05:12 +01:00
Kevin Jahns
0ab415de3e 13.0.0-108 2020-01-23 05:01:05 +01:00
Kevin Jahns
ff3969caeb dedupe npm 2020-01-23 05:00:11 +01:00
Kevin Jahns
c82cc9f8d6 lint 2020-01-23 04:59:17 +01:00
Kevin Jahns
ef5c71bd8b PermanentUserData fixes 2020-01-23 04:58:02 +01:00
5 changed files with 43 additions and 78 deletions

View File

@@ -20,9 +20,6 @@ suited for even large documents.
* Podcast [**"Yjs Deep Dive into real time collaborative editing solutions":**](https://www.tag1consulting.com/blog/deep-dive-real-time-collaborative-editing-solutions-tagteamtalk-001-0) * Podcast [**"Yjs Deep Dive into real time collaborative editing solutions":**](https://www.tag1consulting.com/blog/deep-dive-real-time-collaborative-editing-solutions-tagteamtalk-001-0)
* Podcast [**"Google Docs-style editing in Gutenberg with the YJS framework":**](https://publishpress.com/blog/yjs/) * Podcast [**"Google Docs-style editing in Gutenberg with the YJS framework":**](https://publishpress.com/blog/yjs/)
:warning: This is the documentation for v13 (still in alpha). For the stable v12
release checkout the [v12 docs](./README.v12.md) :warning:
:construction_worker_woman: If you are looking for professional support to build :construction_worker_woman: If you are looking for professional support to build
collaborative or distributed applications ping us at <yjs@tag1consulting.com>. collaborative or distributed applications ping us at <yjs@tag1consulting.com>.
@@ -103,7 +100,7 @@ hypercores and y-dat listens to changes and applies them to the Yjs document.
Install Yjs and a provider with your favorite package manager: Install Yjs and a provider with your favorite package manager:
```sh ```sh
npm i yjs@13.0.0-103 y-websocket@1.0.0-6 npm i yjs y-websocket
``` ```
Start the y-websocket server: Start the y-websocket server:
@@ -677,7 +674,7 @@ undo- or the redo-stack.
<code> <code>
on('stack-item-popped', { stackItem: { meta: Map&lt;any,any&gt; }, type: 'undo' on('stack-item-popped', { stackItem: { meta: Map&lt;any,any&gt; }, type: 'undo'
| 'redo' }) | 'redo' })
</code> </code>
</b> </b>
<dd> <dd>
Register an event that is called when a <code>StackItem</code> is popped from Register an event that is called when a <code>StackItem</code> is popped from

77
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "yjs", "name": "yjs",
"version": "13.0.0-107", "version": "13.0.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@@ -1017,12 +1017,6 @@
"requires": { "requires": {
"ms": "^2.1.1" "ms": "^2.1.1"
} }
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
"dev": true
} }
} }
}, },
@@ -1136,19 +1130,6 @@
"entities": "^1.1.1", "entities": "^1.1.1",
"inherits": "^2.0.1", "inherits": "^2.0.1",
"readable-stream": "^3.1.1" "readable-stream": "^3.1.1"
},
"dependencies": {
"readable-stream": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.4.0.tgz",
"integrity": "sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==",
"dev": true,
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
}
} }
}, },
"http-proxy": { "http-proxy": {
@@ -1351,10 +1332,9 @@
"dev": true "dev": true
}, },
"isomorphic.js": { "isomorphic.js": {
"version": "0.1.0", "version": "0.1.1",
"resolved": "https://registry.npmjs.org/isomorphic.js/-/isomorphic.js-0.1.0.tgz", "resolved": "https://registry.npmjs.org/isomorphic.js/-/isomorphic.js-0.1.1.tgz",
"integrity": "sha512-qoOHpuSbJ56TlPR+vi0xRxdhNBbh/xFbgjB2d+ysekcM5iSh9jzxHURnACQxy0Sb9SnZhxxo9EyN+XbGcQhkAg==", "integrity": "sha512-Q85LNm6e50saL4EPWa0mWEYNUuV51n623gzPVNC1QiLGLmjONEtfFT3pa04OoUIYB7rzGJBpzO2iNPhV1Ib4hg=="
"dev": true
}, },
"js-tokens": { "js-tokens": {
"version": "4.0.0", "version": "4.0.0",
@@ -1464,13 +1444,6 @@
"integrity": "sha512-25ojhgEondpayWt2mgVTKels6R8viO27AetFgvdOk+WWGVah+q2pXouQ6dGj/gtxNwCDD2ih2B0LbDovNEtCrg==", "integrity": "sha512-25ojhgEondpayWt2mgVTKels6R8viO27AetFgvdOk+WWGVah+q2pXouQ6dGj/gtxNwCDD2ih2B0LbDovNEtCrg==",
"requires": { "requires": {
"isomorphic.js": "^0.1.1" "isomorphic.js": "^0.1.1"
},
"dependencies": {
"isomorphic.js": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/isomorphic.js/-/isomorphic.js-0.1.1.tgz",
"integrity": "sha512-Q85LNm6e50saL4EPWa0mWEYNUuV51n623gzPVNC1QiLGLmjONEtfFT3pa04OoUIYB7rzGJBpzO2iNPhV1Ib4hg=="
}
} }
}, },
"linkify-it": { "linkify-it": {
@@ -1888,14 +1861,6 @@
"requires": { "requires": {
"minimist": "~0.0.1", "minimist": "~0.0.1",
"wordwrap": "~0.0.2" "wordwrap": "~0.0.2"
},
"dependencies": {
"wordwrap": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz",
"integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=",
"dev": true
}
} }
}, },
"optionator": { "optionator": {
@@ -2113,12 +2078,6 @@
"requires": { "requires": {
"ms": "^2.1.1" "ms": "^2.1.1"
} }
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
"dev": true
} }
} }
}, },
@@ -2265,6 +2224,17 @@
} }
} }
}, },
"readable-stream": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.4.0.tgz",
"integrity": "sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==",
"dev": true,
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
},
"regexpp": { "regexpp": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz",
@@ -2779,6 +2749,12 @@
"integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==",
"dev": true "dev": true
}, },
"wordwrap": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz",
"integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=",
"dev": true
},
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
@@ -2813,17 +2789,6 @@
"dev": true, "dev": true,
"requires": { "requires": {
"lib0": "^0.2.3" "lib0": "^0.2.3"
},
"dependencies": {
"lib0": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.3.tgz",
"integrity": "sha512-J1Gw9PT78tO3QODgvzk9NVTXTXTsru9LKq+iPOdWw5s1/QiapUKmCJMCWBrNSGkJ0f3WQkZJtGzn3azJwMDdeg==",
"dev": true,
"requires": {
"isomorphic.js": "^0.1.0"
}
}
} }
} }
} }

View File

@@ -1,14 +1,15 @@
{ {
"name": "yjs", "name": "yjs",
"version": "13.0.0-107", "version": "13.0.0",
"description": "Shared Editing Library", "description": "Shared Editing Library",
"main": "./dist/yjs.cjs", "main": "./dist/yjs.cjs",
"module": "./src/index.js", "module": "./src/index.js",
"types": "./dist/src/index.d.ts",
"sideEffects": false, "sideEffects": false,
"scripts": { "scripts": {
"test": "npm run dist && node ./dist/tests.cjs --repitition-time 50", "test": "npm run dist && node ./dist/tests.cjs --repitition-time 50",
"test-exhaustive": "npm run lint && npm run dist && node ./dist/tests.cjs --production --repitition-time 10000", "test-exhaustive": "npm run lint && npm run dist && node ./dist/tests.cjs --production --repitition-time 10000",
"dist": "rm -rf dist && rollup -c", "dist": "rm -rf dist && rollup -c && tsc",
"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", "docs": "rm -rf docs; jsdoc --configure ./.jsdoc.json --verbose --readme ./README.md --package ./package.json || true",

View File

@@ -15,15 +15,14 @@ import { mergeDeleteSets, isDeleted } from './DeleteSet.js'
export class PermanentUserData { export class PermanentUserData {
/** /**
* @param {Doc} doc * @param {Doc} doc
* @param {string} key * @param {YMap<any>} [storeType]
*/ */
constructor (doc, key = 'users') { constructor (doc, storeType = doc.getMap('users')) {
const users = doc.getMap(key)
/** /**
* @type {Map<string,DeleteSet>} * @type {Map<string,DeleteSet>}
*/ */
const dss = new Map() const dss = new Map()
this.yusers = users this.yusers = storeType
this.doc = doc this.doc = doc
/** /**
* Maps from clientid to userDescription * Maps from clientid to userDescription
@@ -59,21 +58,23 @@ export class PermanentUserData {
ids.forEach(addClientId) ids.forEach(addClientId)
} }
// observe users // observe users
users.observe(event => { storeType.observe(event => {
event.keysChanged.forEach(userDescription => event.keysChanged.forEach(userDescription =>
initUser(users.get(userDescription), userDescription) initUser(storeType.get(userDescription), userDescription)
) )
}) })
// add intial data // add intial data
users.forEach(initUser) storeType.forEach(initUser)
} }
/** /**
* @param {Doc} doc * @param {Doc} doc
* @param {number} clientid * @param {number} clientid
* @param {string} userDescription * @param {string} userDescription
* @param {Object} [conf]
* @param {function(Transaction, DeleteSet):boolean} [conf.filter]
*/ */
setUserMapping (doc, clientid, userDescription) { setUserMapping (doc, clientid, userDescription, { filter = () => true } = {}) {
const users = this.yusers const users = this.yusers
let user = users.get(userDescription) let user = users.get(userDescription)
if (!user) { if (!user) {
@@ -109,7 +110,7 @@ export class PermanentUserData {
setTimeout(() => { setTimeout(() => {
const yds = user.get('ds') const yds = user.get('ds')
const ds = transaction.deleteSet const ds = transaction.deleteSet
if (transaction.local && ds.clients.size > 0) { if (transaction.local && ds.clients.size > 0 && filter(transaction, ds)) {
const encoder = encoding.createEncoder() const encoder = encoding.createEncoder()
writeDeleteSet(encoder, ds) writeDeleteSet(encoder, ds)
yds.push([encoding.toUint8Array(encoder)]) yds.push([encoding.toUint8Array(encoder)])

View File

@@ -6,15 +6,15 @@
"allowJs": true, /* Allow javascript files to be compiled. */ "allowJs": true, /* Allow javascript files to be compiled. */
"checkJs": true, /* Report errors in .js files. */ "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "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. */ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */ // "outFile": "./dist/yjs.js", /* Concatenate and emit output to single file. */
// "outDir": "./build", /* Redirect output structure to the directory. */ "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. */ "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */ // "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */ // "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'. */ // "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'. */ // "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'). */ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
@@ -22,6 +22,7 @@
/* Strict Type-Checking Options */ /* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */ "strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"emitDeclarationOnly": true,
// "strictNullChecks": true, /* Enable strict null checks. */ // "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
@@ -62,6 +63,6 @@
"maxNodeModuleJsDepth": 5, "maxNodeModuleJsDepth": 5,
// "types": ["./src/utils/typedefs.js"] // "types": ["./src/utils/typedefs.js"]
}, },
"include": ["./src/**/*", "./tests/**/*"], "include": ["./src/**/*.js", "./tests/**/*.js"],
"exclude": ["../lib0/**/*", "node_modules/**/*", "dist", "dist/**/*.js"] "exclude": ["../lib0/**/*", "node_modules/**/*", "dist", "dist/**/*.js"]
} }