Merge branch 'main' of github.com:yjs/yjs into main
This commit is contained in:
		
						commit
						a1da486c8a
					
				
							
								
								
									
										2
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@ -1,6 +1,6 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "name": "yjs",
 | 
					  "name": "yjs",
 | 
				
			||||||
  "version": "13.4.0",
 | 
					  "version": "13.4.1",
 | 
				
			||||||
  "lockfileVersion": 1,
 | 
					  "lockfileVersion": 1,
 | 
				
			||||||
  "requires": true,
 | 
					  "requires": true,
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,6 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "name": "yjs",
 | 
					  "name": "yjs",
 | 
				
			||||||
  "version": "13.4.0",
 | 
					  "version": "13.4.1",
 | 
				
			||||||
  "description": "Shared Editing Library",
 | 
					  "description": "Shared Editing Library",
 | 
				
			||||||
  "main": "./dist/yjs.cjs",
 | 
					  "main": "./dist/yjs.cjs",
 | 
				
			||||||
  "module": "./dist/yjs.mjs",
 | 
					  "module": "./dist/yjs.mjs",
 | 
				
			||||||
 | 
				
			|||||||
@ -51,7 +51,7 @@ export class PermanentUserData {
 | 
				
			|||||||
          })
 | 
					          })
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
      this.dss.set(userDescription, mergeDeleteSets(ds.map(encodedDs => readDeleteSet(new DSDecoderV1(encodedDs)))))
 | 
					      this.dss.set(userDescription, mergeDeleteSets(ds.map(encodedDs => readDeleteSet(new DSDecoderV1(decoding.createDecoder(encodedDs))))))
 | 
				
			||||||
      ids.observe(/** @param {YArrayEvent<any>} event */ event =>
 | 
					      ids.observe(/** @param {YArrayEvent<any>} event */ event =>
 | 
				
			||||||
        event.changes.added.forEach(item => item.content.getContent().forEach(addClientId))
 | 
					        event.changes.added.forEach(item => item.content.getContent().forEach(addClientId))
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
import * as t from 'lib0/testing.js'
 | 
					import * as t from 'lib0/testing.js'
 | 
				
			||||||
 | 
					import * as promise from 'lib0/promise.js'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  contentRefs,
 | 
					  contentRefs,
 | 
				
			||||||
@ -10,7 +11,11 @@ import {
 | 
				
			|||||||
  readContentType,
 | 
					  readContentType,
 | 
				
			||||||
  readContentFormat,
 | 
					  readContentFormat,
 | 
				
			||||||
  readContentAny,
 | 
					  readContentAny,
 | 
				
			||||||
  readContentDoc
 | 
					  readContentDoc,
 | 
				
			||||||
 | 
					  Doc,
 | 
				
			||||||
 | 
					  PermanentUserData,
 | 
				
			||||||
 | 
					  encodeStateAsUpdate,
 | 
				
			||||||
 | 
					  applyUpdate
 | 
				
			||||||
} from '../src/internals.js'
 | 
					} from '../src/internals.js'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -28,3 +33,31 @@ export const testStructReferences = tc => {
 | 
				
			|||||||
  t.assert(contentRefs[8] === readContentAny)
 | 
					  t.assert(contentRefs[8] === readContentAny)
 | 
				
			||||||
  t.assert(contentRefs[9] === readContentDoc)
 | 
					  t.assert(contentRefs[9] === readContentDoc)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * There is some custom encoding/decoding happening in PermanentUserData.
 | 
				
			||||||
 | 
					 * This is why it landed here.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param {t.TestCase} tc
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export const testPermanentUserData = async tc => {
 | 
				
			||||||
 | 
					  const ydoc1 = new Doc()
 | 
				
			||||||
 | 
					  const ydoc2 = new Doc()
 | 
				
			||||||
 | 
					  const pd1 = new PermanentUserData(ydoc1)
 | 
				
			||||||
 | 
					  const pd2 = new PermanentUserData(ydoc2)
 | 
				
			||||||
 | 
					  pd1.setUserMapping(ydoc1, ydoc1.clientID, 'user a')
 | 
				
			||||||
 | 
					  pd2.setUserMapping(ydoc2, ydoc2.clientID, 'user b')
 | 
				
			||||||
 | 
					  ydoc1.getText().insert(0, 'xhi')
 | 
				
			||||||
 | 
					  ydoc1.getText().delete(0, 1)
 | 
				
			||||||
 | 
					  ydoc2.getText().insert(0, 'hxxi')
 | 
				
			||||||
 | 
					  ydoc2.getText().delete(1, 2)
 | 
				
			||||||
 | 
					  await promise.wait(10)
 | 
				
			||||||
 | 
					  applyUpdate(ydoc2, encodeStateAsUpdate(ydoc1))
 | 
				
			||||||
 | 
					  applyUpdate(ydoc1, encodeStateAsUpdate(ydoc2))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // now sync a third doc with same name as doc1 and then create PermanentUserData
 | 
				
			||||||
 | 
					  const ydoc3 = new Doc()
 | 
				
			||||||
 | 
					  applyUpdate(ydoc3, encodeStateAsUpdate(ydoc1))
 | 
				
			||||||
 | 
					  const pd3 = new PermanentUserData(ydoc3)
 | 
				
			||||||
 | 
					  pd3.setUserMapping(ydoc3, ydoc3.clientID, 'user a')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user