Compare commits
41 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
34b9343b2e | ||
|
d5b5e7a9a1 | ||
|
ad0d915794 | ||
|
2ef9ccd170 | ||
|
3ecfb4e898 | ||
|
35c030d834 | ||
|
e3739bce8e | ||
|
afa4c35866 | ||
|
09fbb62ba9 | ||
|
78e0527b46 | ||
|
69d4a5c821 | ||
|
cc9a857441 | ||
|
4b865764b8 | ||
|
40725e373b | ||
|
c05b815b4c | ||
|
e53c44e3a6 | ||
|
1bec008862 | ||
|
bb5410b6dd | ||
|
2d2e662d4d | ||
|
80e83a84c6 | ||
|
3c9c0f17d1 | ||
|
e67b1296a7 | ||
|
1a0d4aa797 | ||
|
f18eab2dfe | ||
|
89dddc2a95 | ||
|
f583d2a211 | ||
|
1b0f2e5463 | ||
|
4404d090e4 | ||
|
d4d4ae5f53 | ||
|
4ffd3709f8 | ||
|
0419b74315 | ||
|
c951f2b7ea | ||
|
4e2d3c8ac6 | ||
|
8dc1296a0b | ||
|
4329997350 | ||
|
2b7ea8a2af | ||
|
4f47355893 | ||
|
6074f80257 | ||
|
42bbb44bfc | ||
|
cc2d7320aa | ||
|
e804dd7573 |
@ -60,7 +60,7 @@ characters have either been deleted or all characters are not deleted. The item
|
|||||||
will be split if the run is interrupted for any reason (eg a character in the
|
will be split if the run is interrupted for any reason (eg a character in the
|
||||||
middle of the run is deleted).
|
middle of the run is deleted).
|
||||||
|
|
||||||
When an item is created, it stores a reference to the IDs of the preceeding and
|
When an item is created, it stores a reference to the IDs of the preceding and
|
||||||
succeeding item. These are stored in the item's `origin` and `originRight`
|
succeeding item. These are stored in the item's `origin` and `originRight`
|
||||||
fields, respectively. These are used when peers concurrently insert at the same
|
fields, respectively. These are used when peers concurrently insert at the same
|
||||||
location in a document. Though quite rare in practice, Yjs needs to make sure
|
location in a document. Though quite rare in practice, Yjs needs to make sure
|
||||||
|
40
README.md
40
README.md
@ -99,7 +99,6 @@ Showcase](https://yjs-diagram.synergy.codes/).
|
|||||||
* [AWS SageMaker](https://aws.amazon.com/sagemaker/) Tools for building Machine
|
* [AWS SageMaker](https://aws.amazon.com/sagemaker/) Tools for building Machine
|
||||||
Learning Models
|
Learning Models
|
||||||
* [linear](https://linear.app) Streamline issues, projects, and product roadmaps.
|
* [linear](https://linear.app) Streamline issues, projects, and product roadmaps.
|
||||||
* [btw](https://www.btw.so) - Personal website builder
|
|
||||||
* [AWS SageMaker](https://aws.amazon.com/sagemaker/) - Machine Learning Service
|
* [AWS SageMaker](https://aws.amazon.com/sagemaker/) - Machine Learning Service
|
||||||
* [Arkiter](https://www.arkiter.com/) - Live interview software
|
* [Arkiter](https://www.arkiter.com/) - Live interview software
|
||||||
* [Appflowy](https://www.appflowy.io/) - They use Yrs
|
* [Appflowy](https://www.appflowy.io/) - They use Yrs
|
||||||
@ -110,7 +109,7 @@ Showcase](https://yjs-diagram.synergy.codes/).
|
|||||||
* [Synthesia](https://www.synthesia.io) - Collaborative Video Editor
|
* [Synthesia](https://www.synthesia.io) - Collaborative Video Editor
|
||||||
* [thinkdeli](https://thinkdeli.com) - A fast and simple notes app powered by AI
|
* [thinkdeli](https://thinkdeli.com) - A fast and simple notes app powered by AI
|
||||||
* [ourboard](https://github.com/raimohanska/ourboard) - A collaborative whiteboard
|
* [ourboard](https://github.com/raimohanska/ourboard) - A collaborative whiteboard
|
||||||
applicaiton
|
application
|
||||||
* [Ellie.ai](https://ellie.ai) - Data Product Design and Collaboration
|
* [Ellie.ai](https://ellie.ai) - Data Product Design and Collaboration
|
||||||
* [GoPeer](https://gopeer.org/) - Collaborative tutoring
|
* [GoPeer](https://gopeer.org/) - Collaborative tutoring
|
||||||
* [screen.garden](https://screen.garden) - Collaborative backend for PKM apps.
|
* [screen.garden](https://screen.garden) - Collaborative backend for PKM apps.
|
||||||
@ -121,6 +120,9 @@ Showcase](https://yjs-diagram.synergy.codes/).
|
|||||||
* [Eclipse Theia](https://github.com/eclipse-theia/theia) - A cloud & desktop
|
* [Eclipse Theia](https://github.com/eclipse-theia/theia) - A cloud & desktop
|
||||||
IDE that runs in the browser.
|
IDE that runs in the browser.
|
||||||
* [ScienHub](https://scienhub.com) - Collaborative LaTeX editor in the browser.
|
* [ScienHub](https://scienhub.com) - Collaborative LaTeX editor in the browser.
|
||||||
|
* [Open Collaboration Tools](https://www.open-collab.tools/) - Collaborative
|
||||||
|
editing for your IDE or custom editor
|
||||||
|
* [Typst](https://typst.app/) - Compose, edit, and automate technical documents
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
@ -161,6 +163,8 @@ are implemented in separate modules.
|
|||||||
| React | | [react-yjs](https://github.com/nikgraf/react-yjs) | [demo](https://react-yjs-example.vercel.app/) |
|
| React | | [react-yjs](https://github.com/nikgraf/react-yjs) | [demo](https://react-yjs-example.vercel.app/) |
|
||||||
| React / Vue / Svelte / MobX | | [SyncedStore](https://syncedstore.org) | [demo](https://syncedstore.org/docs/react) |
|
| React / Vue / Svelte / MobX | | [SyncedStore](https://syncedstore.org) | [demo](https://syncedstore.org/docs/react) |
|
||||||
| [mobx-keystone](https://mobx-keystone.js.org/) | | [mobx-keystone-yjs](https://github.com/xaviergonz/mobx-keystone/tree/master/packages/mobx-keystone-yjs) | [demo](https://mobx-keystone.js.org/examples/yjs-binding) |
|
| [mobx-keystone](https://mobx-keystone.js.org/) | | [mobx-keystone-yjs](https://github.com/xaviergonz/mobx-keystone/tree/master/packages/mobx-keystone-yjs) | [demo](https://mobx-keystone.js.org/examples/yjs-binding) |
|
||||||
|
| [PSPDFKit](https://www.nutrient.io/) | | [yjs-pspdfkit](https://github.com/hoangqwe159/yjs-pspdfkit) | [demo](https://github.com/hoangqwe159/yjs-pspdfkit) |
|
||||||
|
| [Rows n'Columns](https://www.rowsncolumns.app/) | ✔ | [@rowsncolumns/y-spreadsheet](https://docs.rowsncolumns.app/collaboration/yjs-collaboration) | |
|
||||||
|
|
||||||
### Providers
|
### Providers
|
||||||
|
|
||||||
@ -186,12 +190,12 @@ backends to y-websocket.
|
|||||||
<dt><a href="https://github.com/yjs/y-webrtc">y-webrtc</a></dt>
|
<dt><a href="https://github.com/yjs/y-webrtc">y-webrtc</a></dt>
|
||||||
<dd>
|
<dd>
|
||||||
Propagates document updates peer-to-peer using WebRTC. The peers exchange
|
Propagates document updates peer-to-peer using WebRTC. The peers exchange
|
||||||
signaling data over signaling servers. Publically available signaling servers
|
signaling data over signaling servers. Publicly available signaling servers
|
||||||
are available. Communication over the signaling servers can be encrypted by
|
are available. Communication over the signaling servers can be encrypted by
|
||||||
providing a shared secret, keeping the connection information and the shared
|
providing a shared secret, keeping the connection information and the shared
|
||||||
document private.
|
document private.
|
||||||
</dd>
|
</dd>
|
||||||
<dt><a href="https://github.com/liveblocks/liveblocks">@liveblocks/yjs</a></dt>
|
<dt><a href="https://github.com/liveblocks/liveblocks">@liveblocks/yjs </a> 🌟</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<a href="https://liveblocks.io/document/yjs">Liveblocks Yjs</a> provides a fully
|
<a href="https://liveblocks.io/document/yjs">Liveblocks Yjs</a> provides a fully
|
||||||
hosted WebSocket infrastructure and persisted data store for Yjs
|
hosted WebSocket infrastructure and persisted data store for Yjs
|
||||||
@ -199,15 +203,23 @@ documents. No configuration or maintenance is required. It also features
|
|||||||
Yjs webhook events, REST API to read and update Yjs documents, and a
|
Yjs webhook events, REST API to read and update Yjs documents, and a
|
||||||
browser DevTools extension.
|
browser DevTools extension.
|
||||||
</dd>
|
</dd>
|
||||||
<dt><a href="https://github.com/drifting-in-space/y-sweet">y-sweet</a></dt>
|
<dt><a href="https://github.com/drifting-in-space/y-sweet">y-sweet</a> ⭐</dt>
|
||||||
<dd>
|
<dd>
|
||||||
A standalone yjs server with persistence to S3 or filesystem. They offer a
|
A standalone yjs server with persistence to S3 or filesystem. They offer a
|
||||||
<a href="https://y-sweet.cloud">cloud service</a> as well.
|
<a href="https://y-sweet.cloud">cloud service</a> as well.
|
||||||
</dd>
|
</dd>
|
||||||
<dt><a href="https://github.com/ueberdosis/hocuspocus">Hocuspocus</a></dt>
|
<dt><a href="https://github.com/ueberdosis/hocuspocus">Hocuspocus</a> ⭐</dt>
|
||||||
<dd>
|
<dd>
|
||||||
A standalone extensible yjs server with sqlite persistence, webhooks, auth and more.
|
A standalone extensible yjs server with sqlite persistence, webhooks, auth and more.
|
||||||
</dd>
|
</dd>
|
||||||
|
<dt><a href="https://docs.superviz.com/collaboration/integrations/YJS/overview">@superviz/yjs</a></dt>
|
||||||
|
<dd>
|
||||||
|
SuperViz Yjs Provider comes with a secure, scalable real-time infrastructure
|
||||||
|
for Yjs documents, fully compatible with a set of real-time
|
||||||
|
collaboration components offered by SuperViz. This solution ensures
|
||||||
|
synchronization, offline editing, and real-time updates, enabling
|
||||||
|
multiple users to collaborate effectively within shared workspaces.
|
||||||
|
</dd>
|
||||||
<dt><a href="https://docs.partykit.io/reference/y-partykit-api/">PartyKit</a></dt>
|
<dt><a href="https://docs.partykit.io/reference/y-partykit-api/">PartyKit</a></dt>
|
||||||
<dd>
|
<dd>
|
||||||
Cloud service for building multiplayer apps.
|
Cloud service for building multiplayer apps.
|
||||||
@ -272,11 +284,6 @@ network provider.
|
|||||||
<dd>
|
<dd>
|
||||||
Adds persistent storage to a server with MongoDB. Can be used with the
|
Adds persistent storage to a server with MongoDB. Can be used with the
|
||||||
y-websocket provider.
|
y-websocket provider.
|
||||||
</dd>
|
|
||||||
<dt><a href="https://github.com/toeverything/AFFiNE/tree/master/packages/y-indexeddb">
|
|
||||||
@toeverything/y-indexeddb</a></dt>
|
|
||||||
<dd>
|
|
||||||
Like y-indexeddb, but with sub-documents support and fully TypeScript.
|
|
||||||
</dd>
|
</dd>
|
||||||
<dt><a href="https://github.com/podraven/y-fire">y-fire</a></dt>
|
<dt><a href="https://github.com/podraven/y-fire">y-fire</a></dt>
|
||||||
<dd>
|
<dd>
|
||||||
@ -293,6 +300,10 @@ A database and connection provider for Yjs based on Firestore.
|
|||||||
Provides persistent storage for a web server using PostgreSQL and
|
Provides persistent storage for a web server using PostgreSQL and
|
||||||
is easily compatible with y-websocket.
|
is easily compatible with y-websocket.
|
||||||
</dd>
|
</dd>
|
||||||
|
<dt><a href="https://github.com/kapv89/k_yrs_go">k_yrs_go</a></dt>
|
||||||
|
<dd>
|
||||||
|
Golang database server for YJS CRDT using Postgres + Redis
|
||||||
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
### Tooling
|
### Tooling
|
||||||
@ -315,6 +326,7 @@ language bindings to other languages
|
|||||||
* [yswift](https://github.com/y-crdt/yswift) - Swift binding
|
* [yswift](https://github.com/y-crdt/yswift) - Swift binding
|
||||||
* [yffi](https://github.com/y-crdt/y-crdt/tree/main/yffi) - C-FFI
|
* [yffi](https://github.com/y-crdt/y-crdt/tree/main/yffi) - C-FFI
|
||||||
* [ywasm](https://github.com/y-crdt/y-crdt/tree/main/ywasm) - WASM binding
|
* [ywasm](https://github.com/y-crdt/y-crdt/tree/main/ywasm) - WASM binding
|
||||||
|
* [y_ex](https://github.com/satoren/y_ex) - Elixir bindings
|
||||||
* [ycs](https://github.com/yjs/ycs) - .Net compatible C# implementation.
|
* [ycs](https://github.com/yjs/ycs) - .Net compatible C# implementation.
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
@ -1090,7 +1102,7 @@ encoding format for document updates. If you prefer JSON encoding, you can
|
|||||||
simply JSON.stringify / JSON.parse the relative position instead.
|
simply JSON.stringify / JSON.parse the relative position instead.
|
||||||
</dd>
|
</dd>
|
||||||
<b><code>Y.decodeRelativePosition(Uint8Array):RelativePosition</code></b>
|
<b><code>Y.decodeRelativePosition(Uint8Array):RelativePosition</code></b>
|
||||||
<dd>Decode a binary-encoded relative position to a RelativePositon object.</dd>
|
<dd>Decode a binary-encoded relative position to a RelativePosition object.</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
### Y.UndoManager
|
### Y.UndoManager
|
||||||
@ -1270,11 +1282,11 @@ More information about the specific implementation is available in
|
|||||||
|
|
||||||
CRDTs that are suitable for shared text editing suffer from the fact that they
|
CRDTs that are suitable for shared text editing suffer from the fact that they
|
||||||
only grow in size. There are CRDTs that do not grow in size, but they do not
|
only grow in size. There are CRDTs that do not grow in size, but they do not
|
||||||
have the characteristics that are benificial for shared text editing (like
|
have the characteristics that are beneficial for shared text editing (like
|
||||||
intention preservation). Yjs implements many improvements to the original
|
intention preservation). Yjs implements many improvements to the original
|
||||||
algorithm that diminish the trade-off that the document only grows in size. We
|
algorithm that diminish the trade-off that the document only grows in size. We
|
||||||
can't garbage collect deleted structs (tombstones) while ensuring a unique
|
can't garbage collect deleted structs (tombstones) while ensuring a unique
|
||||||
order of the structs. But we can 1. merge preceeding structs into a single
|
order of the structs. But we can 1. merge preceding structs into a single
|
||||||
struct to reduce the amount of meta information, 2. we can delete content from
|
struct to reduce the amount of meta information, 2. we can delete content from
|
||||||
the struct if it is deleted, and 3. we can garbage collect tombstones if we
|
the struct if it is deleted, and 3. we can garbage collect tombstones if we
|
||||||
don't care about the order of the structs anymore (e.g. if the parent was
|
don't care about the order of the structs anymore (e.g. if the parent was
|
||||||
|
142
funding.json
Normal file
142
funding.json
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
{
|
||||||
|
"version": "v1.0.0",
|
||||||
|
"entity": {
|
||||||
|
"type": "group",
|
||||||
|
"role": "steward",
|
||||||
|
"name": "Kevin Jahns",
|
||||||
|
"email": "kevin.jahns@protonmail.com",
|
||||||
|
"phone": "",
|
||||||
|
"description": "OSS Developer",
|
||||||
|
"webpageUrl": {
|
||||||
|
"url": "https://github.com/yjs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"projects": [
|
||||||
|
{
|
||||||
|
"guid": "yjs",
|
||||||
|
"name": "Yjs",
|
||||||
|
"description": "A library for building collaborative applications. #p2p #local-first #CRDT Funding this project will also enable me to maintain the other Yjs-related technologies.",
|
||||||
|
"webpageUrl": {
|
||||||
|
"url": "https://github.com/yjs/yjs"
|
||||||
|
},
|
||||||
|
"repositoryUrl": {
|
||||||
|
"url": "https://github.com/yjs/yjs"
|
||||||
|
},
|
||||||
|
"licenses": [
|
||||||
|
"spdx:MIT"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"collaboration",
|
||||||
|
"p2p",
|
||||||
|
"CRDT",
|
||||||
|
"rich-text",
|
||||||
|
"real-time"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"guid": "Titanic",
|
||||||
|
"name": "Y/Titanic",
|
||||||
|
"description": "A provider for syncing millions of docs efficiently with other peers. This will become the foundation for building real local-first apps with Yjs.",
|
||||||
|
"webpageUrl": {
|
||||||
|
"url": "https://github.com/yjs/titanic",
|
||||||
|
"wellKnown": "https://github.com/yjs/titanic/blob/main/.well-known/funding-manifest-urls"
|
||||||
|
},
|
||||||
|
"repositoryUrl": {
|
||||||
|
"url": "https://github.com/yjs/titanic",
|
||||||
|
"wellKnown": "https://github.com/yjs/titanic/blob/main/.well-known/funding-manifest-urls"
|
||||||
|
},
|
||||||
|
"licenses": [
|
||||||
|
"spdx:MIT"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"privacy",
|
||||||
|
"collaboration",
|
||||||
|
"p2p",
|
||||||
|
"CRDT",
|
||||||
|
"rich-text",
|
||||||
|
"real-time",
|
||||||
|
"web-development"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"funding": {
|
||||||
|
"channels": [
|
||||||
|
{
|
||||||
|
"guid": "github-sponsors",
|
||||||
|
"type": "payment-provider",
|
||||||
|
"address": "",
|
||||||
|
"description": "For funding of the Yjs project"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"guid": "y-collective",
|
||||||
|
"type": "payment-provider",
|
||||||
|
"address": "https://opencollective.com/y-collective",
|
||||||
|
"description": "For funding the Y-CRDT - the Rust implementation of Yjs and other listed projects."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"plans": [
|
||||||
|
{
|
||||||
|
"guid": "supporter",
|
||||||
|
"status": "active",
|
||||||
|
"name": "Supporter",
|
||||||
|
"description": "",
|
||||||
|
"amount": 0,
|
||||||
|
"currency": "USD",
|
||||||
|
"frequency": "monthly",
|
||||||
|
"channels": [
|
||||||
|
"github-sponsors",
|
||||||
|
"y-collective"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"guid": "titanic-funding",
|
||||||
|
"status": "active",
|
||||||
|
"name": "Titanic Funding",
|
||||||
|
"description": "Fund the next generation of local-first providers.",
|
||||||
|
"amount": 30000,
|
||||||
|
"currency": "USD",
|
||||||
|
"frequency": "one-time",
|
||||||
|
"channels": [
|
||||||
|
"github-sponsors"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"guid": "bronze-sponsor",
|
||||||
|
"status": "active",
|
||||||
|
"name": "Bronze Sponsor",
|
||||||
|
"description": "This is the recommended plan for companies that use Yjs.",
|
||||||
|
"amount": 500,
|
||||||
|
"currency": "USD",
|
||||||
|
"frequency": "monthly",
|
||||||
|
"channels": [
|
||||||
|
"github-sponsors"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"guid": "silver-sponsor",
|
||||||
|
"status": "active",
|
||||||
|
"name": "Silver Sponsor",
|
||||||
|
"description": "This is the recommended plan for large/successfull companies that use Yjs.",
|
||||||
|
"amount": 1000,
|
||||||
|
"currency": "USD",
|
||||||
|
"frequency": "monthly",
|
||||||
|
"channels": [
|
||||||
|
"github-sponsors"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"guid": "gold-sponsor",
|
||||||
|
"status": "active",
|
||||||
|
"name": "Gold Sponsor",
|
||||||
|
"description": "This is the recommended plan for successful companies that build their entire product around Yjs-related technologies.",
|
||||||
|
"amount": 3000,
|
||||||
|
"currency": "USD",
|
||||||
|
"frequency": "monthly",
|
||||||
|
"channels": [
|
||||||
|
"github-sponsors"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"history": null
|
||||||
|
}
|
||||||
|
}
|
12
package-lock.json
generated
12
package-lock.json
generated
@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.6.20",
|
"version": "13.6.24",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.6.20",
|
"version": "13.6.24",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lib0": "^0.2.98"
|
"lib0": "^0.2.99"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^24.0.1",
|
"@rollup/plugin-commonjs": "^24.0.1",
|
||||||
@ -2785,9 +2785,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/lib0": {
|
"node_modules/lib0": {
|
||||||
"version": "0.2.98",
|
"version": "0.2.99",
|
||||||
"resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.98.tgz",
|
"resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.99.tgz",
|
||||||
"integrity": "sha512-XteTiNO0qEXqqweWx+b21p/fBnNHUA1NwAtJNJek1oPrewEZs2uiT4gWivHKr9GqCjDPAhchz0UQO8NwU3bBNA==",
|
"integrity": "sha512-vwztYuUf1uf/1zQxfzRfO5yzfNKhTtgOByCruuiQQxWQXnPb8Itaube5ylofcV0oM0aKal9Mv+S1s1Ky0UYP1w==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"isomorphic.js": "^0.2.4"
|
"isomorphic.js": "^0.2.4"
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.6.20",
|
"version": "13.6.24",
|
||||||
"description": "Shared Editing Library",
|
"description": "Shared Editing Library",
|
||||||
"main": "./dist/yjs.cjs",
|
"main": "./dist/yjs.cjs",
|
||||||
"module": "./dist/yjs.mjs",
|
"module": "./dist/yjs.mjs",
|
||||||
@ -76,7 +76,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://docs.yjs.dev",
|
"homepage": "https://docs.yjs.dev",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lib0": "^0.2.98"
|
"lib0": "^0.2.99"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^24.0.1",
|
"@rollup/plugin-commonjs": "^24.0.1",
|
||||||
|
@ -50,6 +50,8 @@ export {
|
|||||||
findRootTypeKey,
|
findRootTypeKey,
|
||||||
findIndexSS,
|
findIndexSS,
|
||||||
getItem,
|
getItem,
|
||||||
|
getItemCleanStart,
|
||||||
|
getItemCleanEnd,
|
||||||
typeListToArraySnapshot,
|
typeListToArraySnapshot,
|
||||||
typeMapGetSnapshot,
|
typeMapGetSnapshot,
|
||||||
typeMapGetAllSnapshot,
|
typeMapGetAllSnapshot,
|
||||||
|
@ -26,7 +26,7 @@ export class AbstractStruct {
|
|||||||
* This method is already assuming that `this.id.clock + this.length === this.id.clock`.
|
* This method is already assuming that `this.id.clock + this.length === this.id.clock`.
|
||||||
* Also this method does *not* remove right from StructStore!
|
* Also this method does *not* remove right from StructStore!
|
||||||
* @param {AbstractStruct} right
|
* @param {AbstractStruct} right
|
||||||
* @return {boolean} wether this merged with right
|
* @return {boolean} whether this merged with right
|
||||||
*/
|
*/
|
||||||
mergeWith (right) {
|
mergeWith (right) {
|
||||||
return false
|
return false
|
||||||
|
@ -393,8 +393,7 @@ export class Item extends AbstractStruct {
|
|||||||
if (this.left && this.left.constructor === Item) {
|
if (this.left && this.left.constructor === Item) {
|
||||||
this.parent = this.left.parent
|
this.parent = this.left.parent
|
||||||
this.parentSub = this.left.parentSub
|
this.parentSub = this.left.parentSub
|
||||||
}
|
} else if (this.right && this.right.constructor === Item) {
|
||||||
if (this.right && this.right.constructor === Item) {
|
|
||||||
this.parent = this.right.parent
|
this.parent = this.right.parent
|
||||||
this.parentSub = this.right.parentSub
|
this.parentSub = this.right.parentSub
|
||||||
}
|
}
|
||||||
|
@ -155,11 +155,11 @@ export const findMarker = (yarray, index) => {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// if (marker) {
|
// if (marker) {
|
||||||
// if (window.lengthes == null) {
|
// if (window.lengths == null) {
|
||||||
// window.lengthes = []
|
// window.lengths = []
|
||||||
// window.getLengthes = () => window.lengthes.sort((a, b) => a - b)
|
// window.getLengths = () => window.lengths.sort((a, b) => a - b)
|
||||||
// }
|
// }
|
||||||
// window.lengthes.push(marker.index - pindex)
|
// window.lengths.push(marker.index - pindex)
|
||||||
// console.log('distance', marker.index - pindex, 'len', p && p.parent.length)
|
// console.log('distance', marker.index - pindex, 'len', p && p.parent.length)
|
||||||
// }
|
// }
|
||||||
if (marker !== null && math.abs(marker.index - pindex) < /** @type {YText|YArray<any>} */ (p.parent).length / maxSearchMarker) {
|
if (marker !== null && math.abs(marker.index - pindex) < /** @type {YText|YArray<any>} */ (p.parent).length / maxSearchMarker) {
|
||||||
@ -751,7 +751,7 @@ export const typeListInsertGenerics = (transaction, parent, index, content) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Pushing content is special as we generally want to push after the last item. So we don't have to update
|
* Pushing content is special as we generally want to push after the last item. So we don't have to update
|
||||||
* the serach marker.
|
* the search marker.
|
||||||
*
|
*
|
||||||
* @param {Transaction} transaction
|
* @param {Transaction} transaction
|
||||||
* @param {AbstractType<any>} parent
|
* @param {AbstractType<any>} parent
|
||||||
|
@ -478,7 +478,7 @@ export const cleanupYTextFormatting = type => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This will be called by the transction once the event handlers are called to potentially cleanup
|
* This will be called by the transaction once the event handlers are called to potentially cleanup
|
||||||
* formatting attributes.
|
* formatting attributes.
|
||||||
*
|
*
|
||||||
* @param {Transaction} transaction
|
* @param {Transaction} transaction
|
||||||
@ -568,7 +568,7 @@ const deleteText = (transaction, currPos, length) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The Quill Delta format represents changes on a text document with
|
* The Quill Delta format represents changes on a text document with
|
||||||
* formatting information. For mor information visit {@link https://quilljs.com/docs/delta/|Quill Delta}
|
* formatting information. For more information visit {@link https://quilljs.com/docs/delta/|Quill Delta}
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* {
|
* {
|
||||||
@ -961,7 +961,7 @@ export class YText extends AbstractType {
|
|||||||
/**
|
/**
|
||||||
* Apply a {@link Delta} on this shared YText type.
|
* Apply a {@link Delta} on this shared YText type.
|
||||||
*
|
*
|
||||||
* @param {any} delta The changes to apply on this element.
|
* @param {Array<any>} delta The changes to apply on this element.
|
||||||
* @param {object} opts
|
* @param {object} opts
|
||||||
* @param {boolean} [opts.sanitize] Sanitize input delta. Removes ending newlines if set to true.
|
* @param {boolean} [opts.sanitize] Sanitize input delta. Removes ending newlines if set to true.
|
||||||
*
|
*
|
||||||
|
@ -12,7 +12,7 @@ export class YXmlEvent extends YEvent {
|
|||||||
* @param {YXmlElement|YXmlText|YXmlFragment} target The target on which the event is created.
|
* @param {YXmlElement|YXmlText|YXmlFragment} target The target on which the event is created.
|
||||||
* @param {Set<string|null>} subs The set of changed attributes. `null` is included if the
|
* @param {Set<string|null>} subs The set of changed attributes. `null` is included if the
|
||||||
* child list changed.
|
* child list changed.
|
||||||
* @param {Transaction} transaction The transaction instance with wich the
|
* @param {Transaction} transaction The transaction instance with which the
|
||||||
* change was created.
|
* change was created.
|
||||||
*/
|
*/
|
||||||
constructor (target, subs, transaction) {
|
constructor (target, subs, transaction) {
|
||||||
|
@ -96,8 +96,12 @@ export class YXmlTreeWalker {
|
|||||||
} else {
|
} else {
|
||||||
// walk right or up in the tree
|
// walk right or up in the tree
|
||||||
while (n !== null) {
|
while (n !== null) {
|
||||||
if (n.right !== null) {
|
/**
|
||||||
n = n.right
|
* @type {Item | null}
|
||||||
|
*/
|
||||||
|
const nxt = n.next
|
||||||
|
if (nxt !== null) {
|
||||||
|
n = nxt
|
||||||
break
|
break
|
||||||
} else if (n.parent === this._root) {
|
} else if (n.parent === this._root) {
|
||||||
n = null
|
n = null
|
||||||
|
@ -106,7 +106,7 @@ export class Doc extends ObservableV2 {
|
|||||||
this.isSynced = false
|
this.isSynced = false
|
||||||
this.isDestroyed = false
|
this.isDestroyed = false
|
||||||
/**
|
/**
|
||||||
* Promise that resolves once the document has been loaded from a presistence provider.
|
* Promise that resolves once the document has been loaded from a persistence provider.
|
||||||
*/
|
*/
|
||||||
this.whenLoaded = promise.create(resolve => {
|
this.whenLoaded = promise.create(resolve => {
|
||||||
this.on('load', () => {
|
this.on('load', () => {
|
||||||
|
@ -62,7 +62,7 @@ export class PermanentUserData {
|
|||||||
initUser(storeType.get(userDescription), userDescription)
|
initUser(storeType.get(userDescription), userDescription)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
// add intial data
|
// add initial data
|
||||||
storeType.forEach(initUser)
|
storeType.forEach(initUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import {
|
|||||||
ContentType,
|
ContentType,
|
||||||
followRedone,
|
followRedone,
|
||||||
getItem,
|
getItem,
|
||||||
ID, Doc, AbstractType // eslint-disable-line
|
StructStore, ID, Doc, AbstractType, // eslint-disable-line
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
|
||||||
import * as encoding from 'lib0/encoding'
|
import * as encoding from 'lib0/encoding'
|
||||||
@ -66,7 +66,7 @@ export class RelativePosition {
|
|||||||
* after the meant position.
|
* after the meant position.
|
||||||
* I.e. position 1 in 'ab' is associated to character 'b'.
|
* I.e. position 1 in 'ab' is associated to character 'b'.
|
||||||
*
|
*
|
||||||
* If assoc < 0, then the relative position is associated to the caharacter
|
* If assoc < 0, then the relative position is associated to the character
|
||||||
* before the meant position.
|
* before the meant position.
|
||||||
*
|
*
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@ -256,6 +256,18 @@ export const readRelativePosition = decoder => {
|
|||||||
*/
|
*/
|
||||||
export const decodeRelativePosition = uint8Array => readRelativePosition(decoding.createDecoder(uint8Array))
|
export const decodeRelativePosition = uint8Array => readRelativePosition(decoding.createDecoder(uint8Array))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StructStore} store
|
||||||
|
* @param {ID} id
|
||||||
|
*/
|
||||||
|
const getItemWithOffset = (store, id) => {
|
||||||
|
const item = getItem(store, id)
|
||||||
|
const diff = id.clock - item.id.clock
|
||||||
|
return {
|
||||||
|
item, diff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform a relative position to an absolute position.
|
* Transform a relative position to an absolute position.
|
||||||
*
|
*
|
||||||
@ -286,7 +298,7 @@ export const createAbsolutePositionFromRelativePosition = (rpos, doc, followUndo
|
|||||||
if (getState(store, rightID.client) <= rightID.clock) {
|
if (getState(store, rightID.client) <= rightID.clock) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const res = followUndoneDeletions ? followRedone(store, rightID) : { item: getItem(store, rightID), diff: 0 }
|
const res = followUndoneDeletions ? followRedone(store, rightID) : getItemWithOffset(store, rightID)
|
||||||
const right = res.item
|
const right = res.item
|
||||||
if (!(right instanceof Item)) {
|
if (!(right instanceof Item)) {
|
||||||
return null
|
return null
|
||||||
|
@ -66,13 +66,13 @@ export const getState = (store, client) => {
|
|||||||
* @private
|
* @private
|
||||||
* @function
|
* @function
|
||||||
*/
|
*/
|
||||||
export const integretyCheck = store => {
|
export const integrityCheck = store => {
|
||||||
store.clients.forEach(structs => {
|
store.clients.forEach(structs => {
|
||||||
for (let i = 1; i < structs.length; i++) {
|
for (let i = 1; i < structs.length; i++) {
|
||||||
const l = structs[i - 1]
|
const l = structs[i - 1]
|
||||||
const r = structs[i]
|
const r = structs[i]
|
||||||
if (l.id.clock + l.length !== r.id.clock) {
|
if (l.id.clock + l.length !== r.id.clock) {
|
||||||
throw new Error('StructStore failed integrety check')
|
throw new Error('StructStore failed integrity check')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -39,7 +39,7 @@ export class StackItem {
|
|||||||
*/
|
*/
|
||||||
const clearUndoManagerStackItem = (tr, um, stackItem) => {
|
const clearUndoManagerStackItem = (tr, um, stackItem) => {
|
||||||
iterateDeletedStructs(tr, stackItem.deletions, item => {
|
iterateDeletedStructs(tr, stackItem.deletions, item => {
|
||||||
if (item instanceof Item && um.scope.some(type => isParentOf(type, item))) {
|
if (item instanceof Item && um.scope.some(type => type === tr.doc || isParentOf(/** @type {AbstractType<any>} */ (type), item))) {
|
||||||
keepItem(item, false)
|
keepItem(item, false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -81,7 +81,7 @@ const popStackItem = (undoManager, stack, eventType) => {
|
|||||||
}
|
}
|
||||||
struct = item
|
struct = item
|
||||||
}
|
}
|
||||||
if (!struct.deleted && scope.some(type => isParentOf(type, /** @type {Item} */ (struct)))) {
|
if (!struct.deleted && scope.some(type => type === transaction.doc || isParentOf(/** @type {AbstractType<any>} */ (type), /** @type {Item} */ (struct)))) {
|
||||||
itemsToDelete.push(struct)
|
itemsToDelete.push(struct)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ const popStackItem = (undoManager, stack, eventType) => {
|
|||||||
iterateDeletedStructs(transaction, stackItem.deletions, struct => {
|
iterateDeletedStructs(transaction, stackItem.deletions, struct => {
|
||||||
if (
|
if (
|
||||||
struct instanceof Item &&
|
struct instanceof Item &&
|
||||||
scope.some(type => isParentOf(type, struct)) &&
|
scope.some(type => type === transaction.doc || isParentOf(/** @type {AbstractType<any>} */ (type), struct)) &&
|
||||||
// Never redo structs in stackItem.insertions because they were created and deleted in the same capture interval.
|
// Never redo structs in stackItem.insertions because they were created and deleted in the same capture interval.
|
||||||
!isDeleted(stackItem.insertions, struct.id)
|
!isDeleted(stackItem.insertions, struct.id)
|
||||||
) {
|
) {
|
||||||
@ -159,7 +159,7 @@ const popStackItem = (undoManager, stack, eventType) => {
|
|||||||
*/
|
*/
|
||||||
export class UndoManager extends ObservableV2 {
|
export class UndoManager extends ObservableV2 {
|
||||||
/**
|
/**
|
||||||
* @param {AbstractType<any>|Array<AbstractType<any>>} typeScope Accepts either a single type, or an array of types
|
* @param {Doc|AbstractType<any>|Array<AbstractType<any>>} typeScope Limits the scope of the UndoManager. If this is set to a ydoc instance, all changes on that ydoc will be undone. If set to a specific type, only changes on that type or its children will be undone. Also accepts an array of types.
|
||||||
* @param {UndoManagerOptions} options
|
* @param {UndoManagerOptions} options
|
||||||
*/
|
*/
|
||||||
constructor (typeScope, {
|
constructor (typeScope, {
|
||||||
@ -168,11 +168,11 @@ export class UndoManager extends ObservableV2 {
|
|||||||
deleteFilter = () => true,
|
deleteFilter = () => true,
|
||||||
trackedOrigins = new Set([null]),
|
trackedOrigins = new Set([null]),
|
||||||
ignoreRemoteMapChanges = false,
|
ignoreRemoteMapChanges = false,
|
||||||
doc = /** @type {Doc} */ (array.isArray(typeScope) ? typeScope[0].doc : typeScope.doc)
|
doc = /** @type {Doc} */ (array.isArray(typeScope) ? typeScope[0].doc : typeScope instanceof Doc ? typeScope : typeScope.doc)
|
||||||
} = {}) {
|
} = {}) {
|
||||||
super()
|
super()
|
||||||
/**
|
/**
|
||||||
* @type {Array<AbstractType<any>>}
|
* @type {Array<AbstractType<any> | Doc>}
|
||||||
*/
|
*/
|
||||||
this.scope = []
|
this.scope = []
|
||||||
this.doc = doc
|
this.doc = doc
|
||||||
@ -212,7 +212,7 @@ export class UndoManager extends ObservableV2 {
|
|||||||
// Only track certain transactions
|
// Only track certain transactions
|
||||||
if (
|
if (
|
||||||
!this.captureTransaction(transaction) ||
|
!this.captureTransaction(transaction) ||
|
||||||
!this.scope.some(type => transaction.changedParentTypes.has(type)) ||
|
!this.scope.some(type => transaction.changedParentTypes.has(/** @type {AbstractType<any>} */ (type)) || type === this.doc) ||
|
||||||
(!this.trackedOrigins.has(transaction.origin) && (!transaction.origin || !this.trackedOrigins.has(transaction.origin.constructor)))
|
(!this.trackedOrigins.has(transaction.origin) && (!transaction.origin || !this.trackedOrigins.has(transaction.origin.constructor)))
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
@ -251,7 +251,7 @@ export class UndoManager extends ObservableV2 {
|
|||||||
}
|
}
|
||||||
// make sure that deleted structs are not gc'd
|
// make sure that deleted structs are not gc'd
|
||||||
iterateDeletedStructs(transaction, transaction.deleteSet, /** @param {Item|GC} item */ item => {
|
iterateDeletedStructs(transaction, transaction.deleteSet, /** @param {Item|GC} item */ item => {
|
||||||
if (item instanceof Item && this.scope.some(type => isParentOf(type, item))) {
|
if (item instanceof Item && this.scope.some(type => type === transaction.doc || isParentOf(/** @type {AbstractType<any>} */ (type), item))) {
|
||||||
keepItem(item, true)
|
keepItem(item, true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -272,13 +272,17 @@ export class UndoManager extends ObservableV2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array<AbstractType<any>> | AbstractType<any>} ytypes
|
* Extend the scope.
|
||||||
|
*
|
||||||
|
* @param {Array<AbstractType<any> | Doc> | AbstractType<any> | Doc} ytypes
|
||||||
*/
|
*/
|
||||||
addToScope (ytypes) {
|
addToScope (ytypes) {
|
||||||
|
const tmpSet = new Set(this.scope)
|
||||||
ytypes = array.isArray(ytypes) ? ytypes : [ytypes]
|
ytypes = array.isArray(ytypes) ? ytypes : [ytypes]
|
||||||
ytypes.forEach(ytype => {
|
ytypes.forEach(ytype => {
|
||||||
if (this.scope.every(yt => yt !== ytype)) {
|
if (!tmpSet.has(ytype)) {
|
||||||
if (ytype.doc !== this.doc) logging.warn('[yjs#509] Not same Y.Doc') // use MultiDocUndoManager instead. also see https://github.com/yjs/yjs/issues/509
|
tmpSet.add(ytype)
|
||||||
|
if (ytype instanceof AbstractType ? ytype.doc !== this.doc : ytype !== this.doc) logging.warn('[yjs#509] Not same Y.Doc') // use MultiDocUndoManager instead. also see https://github.com/yjs/yjs/issues/509
|
||||||
this.scope.push(ytype)
|
this.scope.push(ytype)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -167,7 +167,7 @@ export class UpdateEncoderV2 extends DSEncoderV2 {
|
|||||||
*/
|
*/
|
||||||
this.keyMap = new Map()
|
this.keyMap = new Map()
|
||||||
/**
|
/**
|
||||||
* Refers to the next uniqe key-identifier to me used.
|
* Refers to the next unique key-identifier to me used.
|
||||||
* See writeKey method for more information.
|
* See writeKey method for more information.
|
||||||
*
|
*
|
||||||
* @type {number}
|
* @type {number}
|
||||||
|
@ -211,7 +211,7 @@ export const readClientsStructRefs = (decoder, doc) => {
|
|||||||
* then we start emptying the stack.
|
* then we start emptying the stack.
|
||||||
*
|
*
|
||||||
* It is not possible to have circles: i.e. struct1 (from client1) depends on struct2 (from client2)
|
* It is not possible to have circles: i.e. struct1 (from client1) depends on struct2 (from client2)
|
||||||
* depends on struct3 (from client1). Therefore the max stack size is eqaul to `structReaders.length`.
|
* depends on struct3 (from client1). Therefore the max stack size is equal to `structReaders.length`.
|
||||||
*
|
*
|
||||||
* This method is implemented in a way so that we can resume computation if this update
|
* This method is implemented in a way so that we can resume computation if this update
|
||||||
* causally depends on another update.
|
* causally depends on another update.
|
||||||
@ -279,14 +279,14 @@ const integrateStructs = (transaction, store, clientsStructRefs) => {
|
|||||||
const addStackToRestSS = () => {
|
const addStackToRestSS = () => {
|
||||||
for (const item of stack) {
|
for (const item of stack) {
|
||||||
const client = item.id.client
|
const client = item.id.client
|
||||||
const unapplicableItems = clientsStructRefs.get(client)
|
const inapplicableItems = clientsStructRefs.get(client)
|
||||||
if (unapplicableItems) {
|
if (inapplicableItems) {
|
||||||
// decrement because we weren't able to apply previous operation
|
// decrement because we weren't able to apply previous operation
|
||||||
unapplicableItems.i--
|
inapplicableItems.i--
|
||||||
restStructs.clients.set(client, unapplicableItems.refs.slice(unapplicableItems.i))
|
restStructs.clients.set(client, inapplicableItems.refs.slice(inapplicableItems.i))
|
||||||
clientsStructRefs.delete(client)
|
clientsStructRefs.delete(client)
|
||||||
unapplicableItems.i = 0
|
inapplicableItems.i = 0
|
||||||
unapplicableItems.refs = []
|
inapplicableItems.refs = []
|
||||||
} else {
|
} else {
|
||||||
// item was the last item on clientsStructRefs and the field was already cleared. Add item to restStructs and continue
|
// item was the last item on clientsStructRefs and the field was already cleared. Add item to restStructs and continue
|
||||||
restStructs.clients.set(client, [item])
|
restStructs.clients.set(client, [item])
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Testing if encoding/decoding compatibility and integration compatiblity is given.
|
* Testing if encoding/decoding compatibility and integration compatibility is given.
|
||||||
* We expect that the document always looks the same, even if we upgrade the integration algorithm, or add additional encoding approaches.
|
* We expect that the document always looks the same, even if we upgrade the integration algorithm, or add additional encoding approaches.
|
||||||
*
|
*
|
||||||
* The v1 documents were generated with Yjs v13.2.0 based on the randomisized tests.
|
* The v1 documents were generated with Yjs v13.2.0 based on the randomisized tests.
|
||||||
|
@ -15,15 +15,28 @@ import * as relativePositions from './relativePositions.tests.js'
|
|||||||
import { runTests } from 'lib0/testing'
|
import { runTests } from 'lib0/testing'
|
||||||
import { isBrowser, isNode } from 'lib0/environment'
|
import { isBrowser, isNode } from 'lib0/environment'
|
||||||
import * as log from 'lib0/logging'
|
import * as log from 'lib0/logging'
|
||||||
|
import { environment } from 'lib0'
|
||||||
|
|
||||||
if (isBrowser) {
|
if (isBrowser) {
|
||||||
log.createVConsole(document.body)
|
log.createVConsole(document.body)
|
||||||
}
|
}
|
||||||
runTests({
|
|
||||||
|
/**
|
||||||
|
* @type {any}
|
||||||
|
*/
|
||||||
|
const tests = {
|
||||||
doc, map, array, text, xml, encoding, undoredo, compatibility, snapshot, updates, relativePositions
|
doc, map, array, text, xml, encoding, undoredo, compatibility, snapshot, updates, relativePositions
|
||||||
}).then(success => {
|
}
|
||||||
|
|
||||||
|
const run = async () => {
|
||||||
|
if (environment.isNode) {
|
||||||
|
// tests.nodejs = await import('./node.tests.js')
|
||||||
|
}
|
||||||
|
|
||||||
|
const success = await runTests(tests)
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
if (isNode) {
|
if (isNode) {
|
||||||
process.exit(success ? 0 : 1)
|
process.exit(success ? 0 : 1)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
run()
|
||||||
|
@ -85,6 +85,26 @@ export const testRelativePositionCase6 = tc => {
|
|||||||
checkRelativePositions(ytext)
|
checkRelativePositions(ytext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing https://github.com/yjs/yjs/issues/657
|
||||||
|
*
|
||||||
|
* @param {t.TestCase} tc
|
||||||
|
*/
|
||||||
|
export const testRelativePositionCase7 = tc => {
|
||||||
|
const docA = new Y.Doc()
|
||||||
|
const textA = docA.getText('text')
|
||||||
|
textA.insert(0, 'abcde')
|
||||||
|
// Create a relative position at index 2 in 'textA'
|
||||||
|
const relativePosition = Y.createRelativePositionFromTypeIndex(textA, 2)
|
||||||
|
// Verify that the absolutes positions on 'docA' are the same
|
||||||
|
const absolutePositionWithFollow =
|
||||||
|
Y.createAbsolutePositionFromRelativePosition(relativePosition, docA, true)
|
||||||
|
const absolutePositionWithoutFollow =
|
||||||
|
Y.createAbsolutePositionFromRelativePosition(relativePosition, docA, false)
|
||||||
|
t.assert(absolutePositionWithFollow?.index === 2)
|
||||||
|
t.assert(absolutePositionWithoutFollow?.index === 2)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
|
@ -58,7 +58,7 @@ export const testEmptyRestoreSnapshot = _tc => {
|
|||||||
t.compare(docRestored.getArray().toArray(), [])
|
t.compare(docRestored.getArray().toArray(), [])
|
||||||
t.compare(doc.getArray().toArray(), ['world'])
|
t.compare(doc.getArray().toArray(), ['world'])
|
||||||
|
|
||||||
// now this snapshot reflects the latest state. It shoult still work.
|
// now this snapshot reflects the latest state. It should still work.
|
||||||
const snap2 = Y.snapshot(doc)
|
const snap2 = Y.snapshot(doc)
|
||||||
const docRestored2 = Y.createDocFromSnapshot(doc, snap2)
|
const docRestored2 = Y.createDocFromSnapshot(doc, snap2)
|
||||||
t.compare(docRestored2.getArray().toArray(), ['world'])
|
t.compare(docRestored2.getArray().toArray(), ['world'])
|
||||||
|
@ -116,6 +116,72 @@ export const testEmptyTypeScope = _tc => {
|
|||||||
t.assert(yarray.length === 0)
|
t.assert(yarray.length === 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {t.TestCase} _tc
|
||||||
|
*/
|
||||||
|
export const testRejectUpdateExample = _tc => {
|
||||||
|
const tmpydoc1 = new Y.Doc()
|
||||||
|
tmpydoc1.getArray('restricted').insert(0, [1])
|
||||||
|
tmpydoc1.getArray('public').insert(0, [1])
|
||||||
|
const update1 = Y.encodeStateAsUpdate(tmpydoc1)
|
||||||
|
const tmpydoc2 = new Y.Doc()
|
||||||
|
tmpydoc2.getArray('public').insert(0, [2])
|
||||||
|
const update2 = Y.encodeStateAsUpdate(tmpydoc2)
|
||||||
|
|
||||||
|
const ydoc = new Y.Doc()
|
||||||
|
const restrictedType = ydoc.getArray('restricted')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assume this function handles incoming updates via a communication channel like websockets.
|
||||||
|
* Changes to the `ydoc.getMap('restricted')` type should be rejected.
|
||||||
|
*
|
||||||
|
* - set up undo manager on the restricted types
|
||||||
|
* - cache pending* updates from the Ydoc to avoid certain attacks
|
||||||
|
* - apply received update and check whether the restricted type (or any of its children) has been changed.
|
||||||
|
* - catch errors that might try to circumvent the restrictions
|
||||||
|
* - undo changes on restricted types
|
||||||
|
* - reapply pending* updates
|
||||||
|
*
|
||||||
|
* @param {Uint8Array} update
|
||||||
|
*/
|
||||||
|
const updateHandler = (update) => {
|
||||||
|
// don't handle changes of the local undo manager, which is used to undo invalid changes
|
||||||
|
const um = new Y.UndoManager(restrictedType, { trackedOrigins: new Set(['remote change']) })
|
||||||
|
const beforePendingDs = ydoc.store.pendingDs
|
||||||
|
const beforePendingStructs = ydoc.store.pendingStructs?.update
|
||||||
|
try {
|
||||||
|
Y.applyUpdate(ydoc, update, 'remote change')
|
||||||
|
} finally {
|
||||||
|
while (um.undoStack.length) {
|
||||||
|
um.undo()
|
||||||
|
}
|
||||||
|
um.destroy()
|
||||||
|
ydoc.store.pendingDs = beforePendingDs
|
||||||
|
ydoc.store.pendingStructs = null
|
||||||
|
if (beforePendingStructs) {
|
||||||
|
Y.applyUpdateV2(ydoc, beforePendingStructs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateHandler(update1)
|
||||||
|
updateHandler(update2)
|
||||||
|
t.assert(restrictedType.length === 0)
|
||||||
|
t.assert(ydoc.getArray('public').length === 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test case to fix #241
|
||||||
|
* @param {t.TestCase} _tc
|
||||||
|
*/
|
||||||
|
export const testGlobalScope = _tc => {
|
||||||
|
const ydoc = new Y.Doc()
|
||||||
|
const um = new Y.UndoManager(ydoc)
|
||||||
|
const yarray = ydoc.getArray()
|
||||||
|
yarray.insert(0, [1])
|
||||||
|
um.undo()
|
||||||
|
t.assert(yarray.length === 0)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case to fix #241
|
* Test case to fix #241
|
||||||
* @param {t.TestCase} _tc
|
* @param {t.TestCase} _tc
|
||||||
|
@ -369,11 +369,11 @@ export const testObserversUsingObservedeep = tc => {
|
|||||||
/**
|
/**
|
||||||
* @type {Array<Array<string|number>>}
|
* @type {Array<Array<string|number>>}
|
||||||
*/
|
*/
|
||||||
const pathes = []
|
const paths = []
|
||||||
let calls = 0
|
let calls = 0
|
||||||
map0.observeDeep(events => {
|
map0.observeDeep(events => {
|
||||||
events.forEach(event => {
|
events.forEach(event => {
|
||||||
pathes.push(event.path)
|
paths.push(event.path)
|
||||||
})
|
})
|
||||||
calls++
|
calls++
|
||||||
})
|
})
|
||||||
@ -381,7 +381,7 @@ export const testObserversUsingObservedeep = tc => {
|
|||||||
map0.get('map').set('array', new Y.Array())
|
map0.get('map').set('array', new Y.Array())
|
||||||
map0.get('map').get('array').insert(0, ['content'])
|
map0.get('map').get('array').insert(0, ['content'])
|
||||||
t.assert(calls === 3)
|
t.assert(calls === 3)
|
||||||
t.compare(pathes, [[], ['map'], ['map', 'array']])
|
t.compare(paths, [[], ['map'], ['map', 'array']])
|
||||||
compare(users)
|
compare(users)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,14 +393,14 @@ export const testPathsOfSiblingEvents = tc => {
|
|||||||
/**
|
/**
|
||||||
* @type {Array<Array<string|number>>}
|
* @type {Array<Array<string|number>>}
|
||||||
*/
|
*/
|
||||||
const pathes = []
|
const paths = []
|
||||||
let calls = 0
|
let calls = 0
|
||||||
const doc = users[0]
|
const doc = users[0]
|
||||||
map0.set('map', new Y.Map())
|
map0.set('map', new Y.Map())
|
||||||
map0.get('map').set('text1', new Y.Text('initial'))
|
map0.get('map').set('text1', new Y.Text('initial'))
|
||||||
map0.observeDeep(events => {
|
map0.observeDeep(events => {
|
||||||
events.forEach(event => {
|
events.forEach(event => {
|
||||||
pathes.push(event.path)
|
paths.push(event.path)
|
||||||
})
|
})
|
||||||
calls++
|
calls++
|
||||||
})
|
})
|
||||||
@ -409,7 +409,7 @@ export const testPathsOfSiblingEvents = tc => {
|
|||||||
map0.get('map').set('text2', new Y.Text('new'))
|
map0.get('map').set('text2', new Y.Text('new'))
|
||||||
})
|
})
|
||||||
t.assert(calls === 1)
|
t.assert(calls === 1)
|
||||||
t.compare(pathes, [['map'], ['map', 'text1']])
|
t.compare(paths, [['map'], ['map', 'text1']])
|
||||||
compare(users)
|
compare(users)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@ export const testDeltaBug = _tc => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
insert: '\n',
|
insert: '\n',
|
||||||
// This attibutes has only list and no table-cell-line
|
// This attributes has only list and no table-cell-line
|
||||||
attributes: {
|
attributes: {
|
||||||
list: {
|
list: {
|
||||||
rowspan: '1',
|
rowspan: '1',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user