Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
710ac31af3 | ||
|
|
49f435284f | ||
|
|
ba96f2fe74 | ||
|
|
99bab4a1d8 | ||
|
|
1674d3986d | ||
|
|
dc3e99e6a1 | ||
|
|
fb6664a2bc | ||
|
|
0d7e865531 | ||
|
|
e73eb0bf92 | ||
|
|
d815855450 | ||
|
|
61ba6cdde1 | ||
|
|
cb70d7bad3 | ||
|
|
2001bec8eb | ||
|
|
2e2710ded9 | ||
|
|
227018f5c7 | ||
|
|
da8bacfc78 | ||
|
|
92bad63145 |
8
.github/workflows/node.js.yml
vendored
8
.github/workflows/node.js.yml
vendored
@@ -16,7 +16,7 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [10.x, 12.x, 14.x]
|
node-version: [16.x, 18.x]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
@@ -25,5 +25,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run build --if-present
|
- run: npm run lint
|
||||||
- run: npm test
|
- run: npm run test-extensive
|
||||||
|
env:
|
||||||
|
CI: true
|
||||||
|
|||||||
31
.github/workflows/nodejs.yml
vendored
31
.github/workflows/nodejs.yml
vendored
@@ -1,31 +0,0 @@
|
|||||||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
|
||||||
|
|
||||||
name: Node.js CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ master ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [10.x, 12.x, 13.x]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- run: npm ci
|
|
||||||
- run: npm run lint
|
|
||||||
- run: npm run test-extensive
|
|
||||||
env:
|
|
||||||
CI: true
|
|
||||||
3504
package-lock.json
generated
3504
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.5.49",
|
"version": "13.5.52",
|
||||||
"description": "Shared Editing Library",
|
"description": "Shared Editing Library",
|
||||||
"main": "./dist/yjs.cjs",
|
"main": "./dist/yjs.cjs",
|
||||||
"module": "./dist/yjs.mjs",
|
"module": "./dist/yjs.mjs",
|
||||||
@@ -75,19 +75,24 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://docs.yjs.dev",
|
"homepage": "https://docs.yjs.dev",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lib0": "^0.2.49"
|
"lib0": "^0.2.72"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^17.0.0",
|
"@rollup/plugin-commonjs": "^24.0.1",
|
||||||
"@rollup/plugin-node-resolve": "^11.2.1",
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
||||||
|
"@types/node": "^18.15.5",
|
||||||
"concurrently": "^3.6.1",
|
"concurrently": "^3.6.1",
|
||||||
"typescript": "^4.9.5",
|
|
||||||
"http-server": "^0.12.3",
|
"http-server": "^0.12.3",
|
||||||
"jsdoc": "^3.6.7",
|
"jsdoc": "^3.6.7",
|
||||||
"markdownlint-cli": "^0.23.2",
|
"markdownlint-cli": "^0.23.2",
|
||||||
"rollup": "^2.60.0",
|
"rollup": "^3.20.0",
|
||||||
"standard": "^16.0.4",
|
"standard": "^16.0.4",
|
||||||
"tui-jsdoc-template": "^1.2.2",
|
"tui-jsdoc-template": "^1.2.2",
|
||||||
|
"typescript": "^4.9.5",
|
||||||
"y-protocols": "^1.0.5"
|
"y-protocols": "^1.0.5"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"npm": ">=8.0.0",
|
||||||
|
"node": ">=16.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,13 +42,7 @@ export default [{
|
|||||||
name: 'Y',
|
name: 'Y',
|
||||||
file: 'dist/yjs.cjs',
|
file: 'dist/yjs.cjs',
|
||||||
format: 'cjs',
|
format: 'cjs',
|
||||||
sourcemap: true,
|
sourcemap: true
|
||||||
paths: path => {
|
|
||||||
if (/^lib0\//.test(path)) {
|
|
||||||
return `lib0/dist/${path.slice(5)}.cjs`
|
|
||||||
}
|
|
||||||
return path
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
external: id => /^lib0\//.test(id)
|
external: id => /^lib0\//.test(id)
|
||||||
}, {
|
}, {
|
||||||
@@ -88,7 +82,7 @@ export default [{
|
|||||||
plugins: [
|
plugins: [
|
||||||
debugResolve,
|
debugResolve,
|
||||||
nodeResolve({
|
nodeResolve({
|
||||||
mainFields: ['module', 'browser', 'main']
|
mainFields: ['browser', 'module', 'main']
|
||||||
}),
|
}),
|
||||||
commonjs()
|
commonjs()
|
||||||
]
|
]
|
||||||
@@ -103,9 +97,10 @@ export default [{
|
|||||||
plugins: [
|
plugins: [
|
||||||
debugResolve,
|
debugResolve,
|
||||||
nodeResolve({
|
nodeResolve({
|
||||||
mainFields: ['module', 'main']
|
mainFields: ['node', 'module', 'main'],
|
||||||
|
exportConditions: ['node', 'module', 'import', 'default']
|
||||||
}),
|
}),
|
||||||
commonjs()
|
commonjs()
|
||||||
],
|
],
|
||||||
external: ['isomorphic.js']
|
external: id => /^lib0\//.test(id)
|
||||||
}]
|
}]
|
||||||
|
|||||||
@@ -23,11 +23,12 @@ import {
|
|||||||
readContentType,
|
readContentType,
|
||||||
addChangedTypeToTransaction,
|
addChangedTypeToTransaction,
|
||||||
isDeleted,
|
isDeleted,
|
||||||
DeleteSet, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ContentType, ContentDeleted, StructStore, ID, AbstractType, Transaction // eslint-disable-line
|
StackItem, DeleteSet, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ContentType, ContentDeleted, StructStore, ID, AbstractType, Transaction // eslint-disable-line
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
|
||||||
import * as error from 'lib0/error'
|
import * as error from 'lib0/error'
|
||||||
import * as binary from 'lib0/binary'
|
import * as binary from 'lib0/binary'
|
||||||
|
import * as array from 'lib0/array'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo This should return several items
|
* @todo This should return several items
|
||||||
@@ -120,6 +121,12 @@ export const splitItem = (transaction, leftItem, diff) => {
|
|||||||
return rightItem
|
return rightItem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Array<StackItem>} stack
|
||||||
|
* @param {ID} id
|
||||||
|
*/
|
||||||
|
const isDeletedByUndoStack = (stack, id) => array.some(stack, /** @param {StackItem} s */ s => isDeleted(s.deletions, id))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redoes the effect of this operation.
|
* Redoes the effect of this operation.
|
||||||
*
|
*
|
||||||
@@ -128,12 +135,13 @@ export const splitItem = (transaction, leftItem, diff) => {
|
|||||||
* @param {Set<Item>} redoitems
|
* @param {Set<Item>} redoitems
|
||||||
* @param {DeleteSet} itemsToDelete
|
* @param {DeleteSet} itemsToDelete
|
||||||
* @param {boolean} ignoreRemoteMapChanges
|
* @param {boolean} ignoreRemoteMapChanges
|
||||||
|
* @param {import('../utils/UndoManager.js').UndoManager} um
|
||||||
*
|
*
|
||||||
* @return {Item|null}
|
* @return {Item|null}
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
export const redoItem = (transaction, item, redoitems, itemsToDelete, ignoreRemoteMapChanges) => {
|
export const redoItem = (transaction, item, redoitems, itemsToDelete, ignoreRemoteMapChanges, um) => {
|
||||||
const doc = transaction.doc
|
const doc = transaction.doc
|
||||||
const store = doc.store
|
const store = doc.store
|
||||||
const ownClientID = doc.clientID
|
const ownClientID = doc.clientID
|
||||||
@@ -153,7 +161,7 @@ export const redoItem = (transaction, item, redoitems, itemsToDelete, ignoreRemo
|
|||||||
// make sure that parent is redone
|
// make sure that parent is redone
|
||||||
if (parentItem !== null && parentItem.deleted === true) {
|
if (parentItem !== null && parentItem.deleted === true) {
|
||||||
// try to undo parent if it will be undone anyway
|
// try to undo parent if it will be undone anyway
|
||||||
if (parentItem.redone === null && (!redoitems.has(parentItem) || redoItem(transaction, parentItem, redoitems, itemsToDelete, ignoreRemoteMapChanges) === null)) {
|
if (parentItem.redone === null && (!redoitems.has(parentItem) || redoItem(transaction, parentItem, redoitems, itemsToDelete, ignoreRemoteMapChanges, um) === null)) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
while (parentItem.redone !== null) {
|
while (parentItem.redone !== null) {
|
||||||
@@ -203,13 +211,10 @@ export const redoItem = (transaction, item, redoitems, itemsToDelete, ignoreRemo
|
|||||||
left = item
|
left = item
|
||||||
// Iterate right while right is in itemsToDelete
|
// Iterate right while right is in itemsToDelete
|
||||||
// If it is intended to delete right while item is redone, we can expect that item should replace right.
|
// If it is intended to delete right while item is redone, we can expect that item should replace right.
|
||||||
while (left !== null && left.right !== null && isDeleted(itemsToDelete, left.right.id)) {
|
while (left !== null && left.right !== null && (left.right.redone || isDeleted(itemsToDelete, left.right.id) || isDeletedByUndoStack(um.undoStack, left.right.id) || isDeletedByUndoStack(um.redoStack, left.right.id))) {
|
||||||
left = left.right
|
left = left.right
|
||||||
}
|
// follow redone
|
||||||
// follow redone
|
while (left.redone) left = getItemCleanStart(transaction, left.redone)
|
||||||
// trace redone until parent matches
|
|
||||||
while (left !== null && left.redone !== null) {
|
|
||||||
left = getItemCleanStart(transaction, left.redone)
|
|
||||||
}
|
}
|
||||||
if (left && left.right !== null) {
|
if (left && left.right !== null) {
|
||||||
// It is not possible to redo this item because it conflicts with a
|
// It is not possible to redo this item because it conflicts with a
|
||||||
@@ -756,48 +761,48 @@ export class AbstractContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} offset
|
* @param {number} _offset
|
||||||
* @return {AbstractContent}
|
* @return {AbstractContent}
|
||||||
*/
|
*/
|
||||||
splice (offset) {
|
splice (_offset) {
|
||||||
throw error.methodUnimplemented()
|
throw error.methodUnimplemented()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {AbstractContent} right
|
* @param {AbstractContent} _right
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
mergeWith (right) {
|
mergeWith (_right) {
|
||||||
throw error.methodUnimplemented()
|
throw error.methodUnimplemented()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Transaction} transaction
|
* @param {Transaction} _transaction
|
||||||
* @param {Item} item
|
* @param {Item} _item
|
||||||
*/
|
*/
|
||||||
integrate (transaction, item) {
|
integrate (_transaction, _item) {
|
||||||
throw error.methodUnimplemented()
|
throw error.methodUnimplemented()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Transaction} transaction
|
* @param {Transaction} _transaction
|
||||||
*/
|
*/
|
||||||
delete (transaction) {
|
delete (_transaction) {
|
||||||
throw error.methodUnimplemented()
|
throw error.methodUnimplemented()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {StructStore} store
|
* @param {StructStore} _store
|
||||||
*/
|
*/
|
||||||
gc (store) {
|
gc (_store) {
|
||||||
throw error.methodUnimplemented()
|
throw error.methodUnimplemented()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
* @param {UpdateEncoderV1 | UpdateEncoderV2} _encoder
|
||||||
* @param {number} offset
|
* @param {number} _offset
|
||||||
*/
|
*/
|
||||||
write (encoder, offset) {
|
write (_encoder, _offset) {
|
||||||
throw error.methodUnimplemented()
|
throw error.methodUnimplemented()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ export class YArray extends AbstractType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a provided function on once on overy element of this YArray.
|
* Executes a provided function once on overy element of this YArray.
|
||||||
*
|
*
|
||||||
* @param {function(T,number,YArray<T>):void} f A function to execute on every element of this YArray.
|
* @param {function(T,number,YArray<T>):void} f A function to execute on every element of this YArray.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1018,15 +1018,7 @@ export class YText extends AbstractType {
|
|||||||
str = ''
|
str = ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// snapshots are merged again after the transaction, so we need to keep the
|
const computeDelta = () => {
|
||||||
// transalive until we are done
|
|
||||||
transact(doc, transaction => {
|
|
||||||
if (snapshot) {
|
|
||||||
splitSnapshotAffectedStructs(transaction, snapshot)
|
|
||||||
}
|
|
||||||
if (prevSnapshot) {
|
|
||||||
splitSnapshotAffectedStructs(transaction, prevSnapshot)
|
|
||||||
}
|
|
||||||
while (n !== null) {
|
while (n !== null) {
|
||||||
if (isVisible(n, snapshot) || (prevSnapshot !== undefined && isVisible(n, prevSnapshot))) {
|
if (isVisible(n, snapshot) || (prevSnapshot !== undefined && isVisible(n, prevSnapshot))) {
|
||||||
switch (n.content.constructor) {
|
switch (n.content.constructor) {
|
||||||
@@ -1079,7 +1071,22 @@ export class YText extends AbstractType {
|
|||||||
n = n.right
|
n = n.right
|
||||||
}
|
}
|
||||||
packStr()
|
packStr()
|
||||||
}, 'cleanup')
|
}
|
||||||
|
if (snapshot || prevSnapshot) {
|
||||||
|
// snapshots are merged again after the transaction, so we need to keep the
|
||||||
|
// transaction alive until we are done
|
||||||
|
transact(doc, transaction => {
|
||||||
|
if (snapshot) {
|
||||||
|
splitSnapshotAffectedStructs(transaction, snapshot)
|
||||||
|
}
|
||||||
|
if (prevSnapshot) {
|
||||||
|
splitSnapshotAffectedStructs(transaction, prevSnapshot)
|
||||||
|
}
|
||||||
|
computeDelta()
|
||||||
|
}, 'cleanup')
|
||||||
|
} else {
|
||||||
|
computeDelta()
|
||||||
|
}
|
||||||
return ops
|
return ops
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -257,8 +257,7 @@ export class YXmlFragment extends AbstractType {
|
|||||||
* @return {string} The string representation of all children.
|
* @return {string} The string representation of all children.
|
||||||
*/
|
*/
|
||||||
toString () {
|
toString () {
|
||||||
// toString can result in many cleanup transactions. We wrap all cleanup transactions here to reduce the work
|
return typeListMap(this, xml => xml.toString()).join('')
|
||||||
return transact(/** @type {Doc} */ (this.doc), () => typeListMap(this, xml => xml.toString()).join(''))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ export const mergeDeleteSets = dss => {
|
|||||||
* @function
|
* @function
|
||||||
*/
|
*/
|
||||||
export const addToDeleteSet = (ds, client, clock, length) => {
|
export const addToDeleteSet = (ds, client, clock, length) => {
|
||||||
map.setIfUndefined(ds.clients, client, () => []).push(new DeleteItem(clock, length))
|
map.setIfUndefined(ds.clients, client, () => /** @type {Array<DeleteItem>} */ ([])).push(new DeleteItem(clock, length))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createDeleteSet = () => new DeleteSet()
|
export const createDeleteSet = () => new DeleteSet()
|
||||||
@@ -251,7 +251,7 @@ export const readDeleteSet = decoder => {
|
|||||||
const client = decoding.readVarUint(decoder.restDecoder)
|
const client = decoding.readVarUint(decoder.restDecoder)
|
||||||
const numberOfDeletes = decoding.readVarUint(decoder.restDecoder)
|
const numberOfDeletes = decoding.readVarUint(decoder.restDecoder)
|
||||||
if (numberOfDeletes > 0) {
|
if (numberOfDeletes > 0) {
|
||||||
const dsField = map.setIfUndefined(ds.clients, client, () => [])
|
const dsField = map.setIfUndefined(ds.clients, client, () => /** @type {Array<DeleteItem>} */ ([]))
|
||||||
for (let i = 0; i < numberOfDeletes; i++) {
|
for (let i = 0; i < numberOfDeletes; i++) {
|
||||||
dsField.push(new DeleteItem(decoder.readDsClock(), decoder.readDsLen()))
|
dsField.push(new DeleteItem(decoder.readDsClock(), decoder.readDsLen()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,13 +156,15 @@ export class Doc extends Observable {
|
|||||||
* that happened inside of the transaction are sent as one message to the
|
* that happened inside of the transaction are sent as one message to the
|
||||||
* other peers.
|
* other peers.
|
||||||
*
|
*
|
||||||
* @param {function(Transaction):void} f The function that should be executed as a transaction
|
* @template T
|
||||||
|
* @param {function(Transaction):T} f The function that should be executed as a transaction
|
||||||
* @param {any} [origin] Origin of who started the transaction. Will be stored on transaction.origin
|
* @param {any} [origin] Origin of who started the transaction. Will be stored on transaction.origin
|
||||||
|
* @return T
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
transact (f, origin = null) {
|
transact (f, origin = null) {
|
||||||
transact(this, f, origin)
|
return transact(this, f, origin)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ import {
|
|||||||
getItemCleanStart,
|
getItemCleanStart,
|
||||||
isDeleted,
|
isDeleted,
|
||||||
addToDeleteSet,
|
addToDeleteSet,
|
||||||
Transaction, Doc, Item, GC, DeleteSet, AbstractType, YEvent // eslint-disable-line
|
Transaction, Doc, Item, GC, DeleteSet, AbstractType // eslint-disable-line
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
|
||||||
import * as time from 'lib0/time'
|
import * as time from 'lib0/time'
|
||||||
import * as array from 'lib0/array'
|
import * as array from 'lib0/array'
|
||||||
import { Observable } from 'lib0/observable'
|
import { Observable } from 'lib0/observable'
|
||||||
|
|
||||||
class StackItem {
|
export class StackItem {
|
||||||
/**
|
/**
|
||||||
* @param {DeleteSet} deletions
|
* @param {DeleteSet} deletions
|
||||||
* @param {DeleteSet} insertions
|
* @param {DeleteSet} insertions
|
||||||
@@ -101,7 +101,7 @@ const popStackItem = (undoManager, stack, eventType) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
itemsToRedo.forEach(struct => {
|
itemsToRedo.forEach(struct => {
|
||||||
performedChange = redoItem(transaction, struct, itemsToRedo, stackItem.insertions, undoManager.ignoreRemoteMapChanges) !== null || performedChange
|
performedChange = redoItem(transaction, struct, itemsToRedo, stackItem.insertions, undoManager.ignoreRemoteMapChanges, undoManager) !== null || performedChange
|
||||||
})
|
})
|
||||||
// We want to delete in reverse order so that children are deleted before
|
// We want to delete in reverse order so that children are deleted before
|
||||||
// parents, so we have more information available when items are filtered.
|
// parents, so we have more information available when items are filtered.
|
||||||
@@ -158,7 +158,7 @@ export class UndoManager extends Observable {
|
|||||||
*/
|
*/
|
||||||
constructor (typeScope, {
|
constructor (typeScope, {
|
||||||
captureTimeout = 500,
|
captureTimeout = 500,
|
||||||
captureTransaction = tr => true,
|
captureTransaction = _tr => true,
|
||||||
deleteFilter = () => true,
|
deleteFilter = () => true,
|
||||||
trackedOrigins = new Set([null]),
|
trackedOrigins = new Set([null]),
|
||||||
ignoreRemoteMapChanges = false,
|
ignoreRemoteMapChanges = false,
|
||||||
|
|||||||
@@ -130,6 +130,11 @@ export class YEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This is a computed property. Note that this can only be safely computed during the
|
||||||
|
* event call. Computing this property after other changes happened might result in
|
||||||
|
* unexpected behavior (incorrect computation of deltas). A safe way to collect changes
|
||||||
|
* is to store the `changes` or the `delta` object. Avoid storing the `transaction` object.
|
||||||
|
*
|
||||||
* @type {Array<{insert?: string | Array<any> | object | AbstractType<any>, retain?: number, delete?: number, attributes?: Object<string, any>}>}
|
* @type {Array<{insert?: string | Array<any> | object | AbstractType<any>, retain?: number, delete?: number, attributes?: Object<string, any>}>}
|
||||||
*/
|
*/
|
||||||
get delta () {
|
get delta () {
|
||||||
@@ -149,6 +154,11 @@ export class YEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This is a computed property. Note that this can only be safely computed during the
|
||||||
|
* event call. Computing this property after other changes happened might result in
|
||||||
|
* unexpected behavior (incorrect computation of deltas). A safe way to collect changes
|
||||||
|
* is to store the `changes` or the `delta` object. Avoid storing the `transaction` object.
|
||||||
|
*
|
||||||
* @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert?:Array<any>|string, delete?:number, retain?:number}>}}
|
* @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert?:Array<any>|string, delete?:number, retain?:number}>}}
|
||||||
*/
|
*/
|
||||||
get changes () {
|
get changes () {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export const testOriginInTransaction = _tc => {
|
|||||||
doc.on('afterTransaction', (tr) => {
|
doc.on('afterTransaction', (tr) => {
|
||||||
origins.push(tr.origin)
|
origins.push(tr.origin)
|
||||||
if (origins.length <= 1) {
|
if (origins.length <= 1) {
|
||||||
ytext.toDelta()
|
ytext.toDelta(Y.snapshot(doc)) // adding a snapshot forces toDelta to create a cleanup transaction
|
||||||
doc.transact(() => {
|
doc.transact(() => {
|
||||||
ytext.insert(0, 'a')
|
ytext.insert(0, 'a')
|
||||||
}, 'nested')
|
}, 'nested')
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-env node */
|
||||||
|
|
||||||
import * as map from './y-map.tests.js'
|
import * as map from './y-map.tests.js'
|
||||||
import * as array from './y-array.tests.js'
|
import * as array from './y-array.tests.js'
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ export class TestYInstance extends Y.Doc {
|
|||||||
* @param {TestYInstance} remoteClient
|
* @param {TestYInstance} remoteClient
|
||||||
*/
|
*/
|
||||||
_receive (message, remoteClient) {
|
_receive (message, remoteClient) {
|
||||||
map.setIfUndefined(this.receiving, remoteClient, () => []).push(message)
|
map.setIfUndefined(this.receiving, remoteClient, () => /** @type {Array<Uint8Array>} */ ([])).push(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,7 +347,7 @@ export const compare = users => {
|
|||||||
t.compare(userMapValues[i], userMapValues[i + 1])
|
t.compare(userMapValues[i], userMapValues[i + 1])
|
||||||
t.compare(userXmlValues[i], userXmlValues[i + 1])
|
t.compare(userXmlValues[i], userXmlValues[i + 1])
|
||||||
t.compare(userTextValues[i].map(/** @param {any} a */ a => typeof a.insert === 'string' ? a.insert : ' ').join('').length, users[i].getText('text').length)
|
t.compare(userTextValues[i].map(/** @param {any} a */ a => typeof a.insert === 'string' ? a.insert : ' ').join('').length, users[i].getText('text').length)
|
||||||
t.compare(userTextValues[i], userTextValues[i + 1], '', (constructor, a, b) => {
|
t.compare(userTextValues[i], userTextValues[i + 1], '', (_constructor, a, b) => {
|
||||||
if (a instanceof Y.AbstractType) {
|
if (a instanceof Y.AbstractType) {
|
||||||
t.compare(a.toJSON(), b.toJSON())
|
t.compare(a.toJSON(), b.toJSON())
|
||||||
} else if (a !== b) {
|
} else if (a !== b) {
|
||||||
@@ -370,8 +370,8 @@ export const compare = users => {
|
|||||||
export const compareItemIDs = (a, b) => a === b || (a !== null && b != null && Y.compareIDs(a.id, b.id))
|
export const compareItemIDs = (a, b) => a === b || (a !== null && b != null && Y.compareIDs(a.id, b.id))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import('../src/internals').StructStore} ss1
|
* @param {import('../src/internals.js').StructStore} ss1
|
||||||
* @param {import('../src/internals').StructStore} ss2
|
* @param {import('../src/internals.js').StructStore} ss2
|
||||||
*/
|
*/
|
||||||
export const compareStructStores = (ss1, ss2) => {
|
export const compareStructStores = (ss1, ss2) => {
|
||||||
t.assert(ss1.clients.size === ss2.clients.size)
|
t.assert(ss1.clients.size === ss2.clients.size)
|
||||||
@@ -413,13 +413,13 @@ export const compareStructStores = (ss1, ss2) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import('../src/internals').DeleteSet} ds1
|
* @param {import('../src/internals.js').DeleteSet} ds1
|
||||||
* @param {import('../src/internals').DeleteSet} ds2
|
* @param {import('../src/internals.js').DeleteSet} ds2
|
||||||
*/
|
*/
|
||||||
export const compareDS = (ds1, ds2) => {
|
export const compareDS = (ds1, ds2) => {
|
||||||
t.assert(ds1.clients.size === ds2.clients.size)
|
t.assert(ds1.clients.size === ds2.clients.size)
|
||||||
ds1.clients.forEach((deleteItems1, client) => {
|
ds1.clients.forEach((deleteItems1, client) => {
|
||||||
const deleteItems2 = /** @type {Array<import('../src/internals').DeleteItem>} */ (ds2.clients.get(client))
|
const deleteItems2 = /** @type {Array<import('../src/internals.js').DeleteItem>} */ (ds2.clients.get(client))
|
||||||
t.assert(deleteItems2 !== undefined && deleteItems1.length === deleteItems2.length)
|
t.assert(deleteItems2 !== undefined && deleteItems1.length === deleteItems2.length)
|
||||||
for (let i = 0; i < deleteItems1.length; i++) {
|
for (let i = 0; i < deleteItems1.length; i++) {
|
||||||
const di1 = deleteItems1[i]
|
const di1 = deleteItems1[i]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { init, compare, applyRandomTests, Doc } from './testHelper.js' // eslint-disable-line
|
import { init } from './testHelper.js' // eslint-disable-line
|
||||||
|
|
||||||
import * as Y from '../src/index.js'
|
import * as Y from '../src/index.js'
|
||||||
import * as t from 'lib0/testing'
|
import * as t from 'lib0/testing'
|
||||||
@@ -64,9 +64,9 @@ export const testUndoText = tc => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case to fix #241
|
* Test case to fix #241
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testEmptyTypeScope = tc => {
|
export const testEmptyTypeScope = _tc => {
|
||||||
const ydoc = new Y.Doc()
|
const ydoc = new Y.Doc()
|
||||||
const um = new Y.UndoManager([], { doc: ydoc })
|
const um = new Y.UndoManager([], { doc: ydoc })
|
||||||
const yarray = ydoc.getArray()
|
const yarray = ydoc.getArray()
|
||||||
@@ -78,9 +78,9 @@ export const testEmptyTypeScope = tc => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case to fix #241
|
* Test case to fix #241
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testDoubleUndo = tc => {
|
export const testDoubleUndo = _tc => {
|
||||||
const doc = new Y.Doc()
|
const doc = new Y.Doc()
|
||||||
const text = doc.getText()
|
const text = doc.getText()
|
||||||
text.insert(0, '1221')
|
text.insert(0, '1221')
|
||||||
@@ -316,9 +316,9 @@ export const testUndoDeleteFilter = tc => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This issue has been reported in https://discuss.yjs.dev/t/undomanager-with-external-updates/454/6
|
* This issue has been reported in https://discuss.yjs.dev/t/undomanager-with-external-updates/454/6
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testUndoUntilChangePerformed = tc => {
|
export const testUndoUntilChangePerformed = _tc => {
|
||||||
const doc = new Y.Doc()
|
const doc = new Y.Doc()
|
||||||
const doc2 = new Y.Doc()
|
const doc2 = new Y.Doc()
|
||||||
doc.on('update', update => Y.applyUpdate(doc2, update))
|
doc.on('update', update => Y.applyUpdate(doc2, update))
|
||||||
@@ -347,9 +347,9 @@ export const testUndoUntilChangePerformed = tc => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This issue has been reported in https://github.com/yjs/yjs/issues/317
|
* This issue has been reported in https://github.com/yjs/yjs/issues/317
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testUndoNestedUndoIssue = tc => {
|
export const testUndoNestedUndoIssue = _tc => {
|
||||||
const doc = new Y.Doc({ gc: false })
|
const doc = new Y.Doc({ gc: false })
|
||||||
const design = doc.getMap()
|
const design = doc.getMap()
|
||||||
const undoManager = new Y.UndoManager(design, { captureTimeout: 0 })
|
const undoManager = new Y.UndoManager(design, { captureTimeout: 0 })
|
||||||
@@ -403,9 +403,9 @@ export const testUndoNestedUndoIssue = tc => {
|
|||||||
/**
|
/**
|
||||||
* This issue has been reported in https://github.com/yjs/yjs/issues/355
|
* This issue has been reported in https://github.com/yjs/yjs/issues/355
|
||||||
*
|
*
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testConsecutiveRedoBug = tc => {
|
export const testConsecutiveRedoBug = _tc => {
|
||||||
const doc = new Y.Doc()
|
const doc = new Y.Doc()
|
||||||
const yRoot = doc.getMap()
|
const yRoot = doc.getMap()
|
||||||
const undoMgr = new Y.UndoManager(yRoot)
|
const undoMgr = new Y.UndoManager(yRoot)
|
||||||
@@ -454,9 +454,9 @@ export const testConsecutiveRedoBug = tc => {
|
|||||||
/**
|
/**
|
||||||
* This issue has been reported in https://github.com/yjs/yjs/issues/304
|
* This issue has been reported in https://github.com/yjs/yjs/issues/304
|
||||||
*
|
*
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testUndoXmlBug = tc => {
|
export const testUndoXmlBug = _tc => {
|
||||||
const origin = 'origin'
|
const origin = 'origin'
|
||||||
const doc = new Y.Doc()
|
const doc = new Y.Doc()
|
||||||
const fragment = doc.getXmlFragment('t')
|
const fragment = doc.getXmlFragment('t')
|
||||||
@@ -499,9 +499,9 @@ export const testUndoXmlBug = tc => {
|
|||||||
/**
|
/**
|
||||||
* This issue has been reported in https://github.com/yjs/yjs/issues/343
|
* This issue has been reported in https://github.com/yjs/yjs/issues/343
|
||||||
*
|
*
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testUndoBlockBug = tc => {
|
export const testUndoBlockBug = _tc => {
|
||||||
const doc = new Y.Doc({ gc: false })
|
const doc = new Y.Doc({ gc: false })
|
||||||
const design = doc.getMap()
|
const design = doc.getMap()
|
||||||
|
|
||||||
@@ -559,9 +559,9 @@ export const testUndoBlockBug = tc => {
|
|||||||
* Undo text formatting delete should not corrupt peer state.
|
* Undo text formatting delete should not corrupt peer state.
|
||||||
*
|
*
|
||||||
* @see https://github.com/yjs/yjs/issues/392
|
* @see https://github.com/yjs/yjs/issues/392
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testUndoDeleteTextFormat = tc => {
|
export const testUndoDeleteTextFormat = _tc => {
|
||||||
const doc = new Y.Doc()
|
const doc = new Y.Doc()
|
||||||
const text = doc.getText()
|
const text = doc.getText()
|
||||||
text.insert(0, 'Attack ships on fire off the shoulder of Orion.')
|
text.insert(0, 'Attack ships on fire off the shoulder of Orion.')
|
||||||
@@ -597,9 +597,9 @@ export const testUndoDeleteTextFormat = tc => {
|
|||||||
* Undo text formatting delete should not corrupt peer state.
|
* Undo text formatting delete should not corrupt peer state.
|
||||||
*
|
*
|
||||||
* @see https://github.com/yjs/yjs/issues/392
|
* @see https://github.com/yjs/yjs/issues/392
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testBehaviorOfIgnoreremotemapchangesProperty = tc => {
|
export const testBehaviorOfIgnoreremotemapchangesProperty = _tc => {
|
||||||
const doc = new Y.Doc()
|
const doc = new Y.Doc()
|
||||||
const doc2 = new Y.Doc()
|
const doc2 = new Y.Doc()
|
||||||
doc.on('update', update => Y.applyUpdate(doc2, update, doc))
|
doc.on('update', update => Y.applyUpdate(doc2, update, doc))
|
||||||
@@ -620,9 +620,9 @@ export const testBehaviorOfIgnoreremotemapchangesProperty = tc => {
|
|||||||
* Special deletion case.
|
* Special deletion case.
|
||||||
*
|
*
|
||||||
* @see https://github.com/yjs/yjs/issues/447
|
* @see https://github.com/yjs/yjs/issues/447
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testSpecialDeletionCase = tc => {
|
export const testSpecialDeletionCase = _tc => {
|
||||||
const origin = 'undoable'
|
const origin = 'undoable'
|
||||||
const doc = new Y.Doc()
|
const doc = new Y.Doc()
|
||||||
const fragment = doc.getXmlFragment()
|
const fragment = doc.getXmlFragment()
|
||||||
@@ -644,3 +644,34 @@ export const testSpecialDeletionCase = tc => {
|
|||||||
undoManager.undo()
|
undoManager.undo()
|
||||||
t.compareStrings(fragment.toString(), '<test a="1" b="2"></test>')
|
t.compareStrings(fragment.toString(), '<test a="1" b="2"></test>')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deleted entries in a map should be restored on undo.
|
||||||
|
*
|
||||||
|
* @see https://github.com/yjs/yjs/issues/500
|
||||||
|
* @param {t.TestCase} tc
|
||||||
|
*/
|
||||||
|
export const testUndoDeleteInMap = (tc) => {
|
||||||
|
const { map0 } = init(tc, { users: 3 })
|
||||||
|
const undoManager = new Y.UndoManager(map0, { captureTimeout: 0 })
|
||||||
|
map0.set('a', 'a')
|
||||||
|
map0.delete('a')
|
||||||
|
map0.set('a', 'b')
|
||||||
|
map0.delete('a')
|
||||||
|
map0.set('a', 'c')
|
||||||
|
map0.delete('a')
|
||||||
|
map0.set('a', 'd')
|
||||||
|
t.compare(map0.toJSON(), { a: 'd' })
|
||||||
|
undoManager.undo()
|
||||||
|
t.compare(map0.toJSON(), {})
|
||||||
|
undoManager.undo()
|
||||||
|
t.compare(map0.toJSON(), { a: 'c' })
|
||||||
|
undoManager.undo()
|
||||||
|
t.compare(map0.toJSON(), {})
|
||||||
|
undoManager.undo()
|
||||||
|
t.compare(map0.toJSON(), { a: 'b' })
|
||||||
|
undoManager.undo()
|
||||||
|
t.compare(map0.toJSON(), {})
|
||||||
|
undoManager.undo()
|
||||||
|
t.compare(map0.toJSON(), { a: 'a' })
|
||||||
|
}
|
||||||
|
|||||||
@@ -1747,9 +1747,9 @@ export const testBasicFormat = tc => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testMultilineFormat = tc => {
|
export const testMultilineFormat = _tc => {
|
||||||
const ydoc = new Y.Doc()
|
const ydoc = new Y.Doc()
|
||||||
const testText = ydoc.getText('test')
|
const testText = ydoc.getText('test')
|
||||||
testText.insert(0, 'Test\nMulti-line\nFormatting')
|
testText.insert(0, 'Test\nMulti-line\nFormatting')
|
||||||
@@ -1770,9 +1770,9 @@ export const testMultilineFormat = tc => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testNotMergeEmptyLinesFormat = tc => {
|
export const testNotMergeEmptyLinesFormat = _tc => {
|
||||||
const ydoc = new Y.Doc()
|
const ydoc = new Y.Doc()
|
||||||
const testText = ydoc.getText('test')
|
const testText = ydoc.getText('test')
|
||||||
testText.applyDelta([
|
testText.applyDelta([
|
||||||
@@ -1790,9 +1790,9 @@ export const testNotMergeEmptyLinesFormat = tc => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testPreserveAttributesThroughDelete = tc => {
|
export const testPreserveAttributesThroughDelete = _tc => {
|
||||||
const ydoc = new Y.Doc()
|
const ydoc = new Y.Doc()
|
||||||
const testText = ydoc.getText('test')
|
const testText = ydoc.getText('test')
|
||||||
testText.applyDelta([
|
testText.applyDelta([
|
||||||
@@ -2046,9 +2046,9 @@ const id = Y.createID(0, 0)
|
|||||||
const c = new Y.ContentString('a')
|
const c = new Y.ContentString('a')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testBestCase = tc => {
|
export const testBestCase = _tc => {
|
||||||
const N = largeDocumentSize
|
const N = largeDocumentSize
|
||||||
const items = new Array(N)
|
const items = new Array(N)
|
||||||
t.measureTime('time to create two million items in the best case', () => {
|
t.measureTime('time to create two million items in the best case', () => {
|
||||||
@@ -2085,9 +2085,9 @@ const tryGc = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testLargeFragmentedDocument = tc => {
|
export const testLargeFragmentedDocument = _tc => {
|
||||||
const itemsToInsert = largeDocumentSize
|
const itemsToInsert = largeDocumentSize
|
||||||
let update = /** @type {any} */ (null)
|
let update = /** @type {any} */ (null)
|
||||||
;(() => {
|
;(() => {
|
||||||
@@ -2117,9 +2117,9 @@ export const testLargeFragmentedDocument = tc => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testIncrementalUpdatesPerformanceOnLargeFragmentedDocument = tc => {
|
export const testIncrementalUpdatesPerformanceOnLargeFragmentedDocument = _tc => {
|
||||||
const itemsToInsert = largeDocumentSize
|
const itemsToInsert = largeDocumentSize
|
||||||
const updates = /** @type {Array<Uint8Array>} */ ([])
|
const updates = /** @type {Array<Uint8Array>} */ ([])
|
||||||
;(() => {
|
;(() => {
|
||||||
@@ -2227,9 +2227,9 @@ export const testSearchMarkerBug1 = tc => {
|
|||||||
/**
|
/**
|
||||||
* Reported in https://github.com/yjs/yjs/pull/32
|
* Reported in https://github.com/yjs/yjs/pull/32
|
||||||
*
|
*
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testFormattingBug = async tc => {
|
export const testFormattingBug = async _tc => {
|
||||||
const ydoc1 = new Y.Doc()
|
const ydoc1 = new Y.Doc()
|
||||||
const ydoc2 = new Y.Doc()
|
const ydoc2 = new Y.Doc()
|
||||||
const text1 = ydoc1.getText()
|
const text1 = ydoc1.getText()
|
||||||
@@ -2252,9 +2252,9 @@ export const testFormattingBug = async tc => {
|
|||||||
/**
|
/**
|
||||||
* Delete formatting should not leave redundant formatting items.
|
* Delete formatting should not leave redundant formatting items.
|
||||||
*
|
*
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} _tc
|
||||||
*/
|
*/
|
||||||
export const testDeleteFormatting = tc => {
|
export const testDeleteFormatting = _tc => {
|
||||||
const doc = new Y.Doc()
|
const doc = new Y.Doc()
|
||||||
const text = doc.getText()
|
const text = doc.getText()
|
||||||
text.insert(0, 'Attack ships on fire off the shoulder of Orion.')
|
text.insert(0, 'Attack ships on fire off the shoulder of Orion.')
|
||||||
@@ -2456,6 +2456,41 @@ const qChanges = [
|
|||||||
}
|
}
|
||||||
ops.push({ insert: text }, { insert: '\n', format: { 'code-block': true } })
|
ops.push({ insert: text }, { insert: '\n', format: { 'code-block': true } })
|
||||||
ytext.applyDelta(ops)
|
ytext.applyDelta(ops)
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* @param {Y.Doc} y
|
||||||
|
* @param {prng.PRNG} gen
|
||||||
|
*/
|
||||||
|
(y, gen) => { // complex delta op
|
||||||
|
const ytext = y.getText('text')
|
||||||
|
const contentLen = ytext.toString().length
|
||||||
|
let currentPos = math.max(0, prng.int32(gen, 0, contentLen - 1))
|
||||||
|
/**
|
||||||
|
* @type {Array<any>}
|
||||||
|
*/
|
||||||
|
const ops = currentPos > 0 ? [{ retain: currentPos }] : []
|
||||||
|
// create max 3 ops
|
||||||
|
for (let i = 0; i < 7 && currentPos < contentLen; i++) {
|
||||||
|
prng.oneOf(gen, [
|
||||||
|
() => { // format
|
||||||
|
const retain = math.min(prng.int32(gen, 0, contentLen - currentPos), 5)
|
||||||
|
const format = prng.oneOf(gen, marks)
|
||||||
|
ops.push({ retain, attributes: format })
|
||||||
|
currentPos += retain
|
||||||
|
},
|
||||||
|
() => { // insert
|
||||||
|
const attrs = prng.oneOf(gen, marksChoices)
|
||||||
|
const text = prng.word(gen, 1, 3)
|
||||||
|
ops.push({ insert: text, attributes: attrs })
|
||||||
|
},
|
||||||
|
() => { // delete
|
||||||
|
const delLen = math.min(prng.int32(gen, 0, contentLen - currentPos), 10)
|
||||||
|
ops.push({ delete: delLen })
|
||||||
|
currentPos += delLen
|
||||||
|
}
|
||||||
|
])()
|
||||||
|
}
|
||||||
|
ytext.applyDelta(ops)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -1,64 +1,21 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
/* Basic Options */
|
"target": "ES2021",
|
||||||
"target": "es2018",
|
"lib": ["ES2021", "dom"],
|
||||||
"lib": ["es2018", "dom"], /* Specify library files to be included in the compilation. */
|
"module": "node16",
|
||||||
"allowJs": true, /* Allow javascript files to be compiled. */
|
"allowJs": true,
|
||||||
"checkJs": true, /* Report errors in .js files. */
|
"checkJs": true,
|
||||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
"declaration": true,
|
||||||
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
"declarationMap": true,
|
||||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
"outDir": "./dist",
|
||||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
"baseUrl": "./",
|
||||||
// "outFile": "./dist/yjs.js", /* Concatenate and emit output to single file. */
|
|
||||||
"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. */
|
|
||||||
// "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": true, /* Enable all strict type-checking options. */
|
|
||||||
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
||||||
"emitDeclarationOnly": true,
|
"emitDeclarationOnly": true,
|
||||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
"strict": true,
|
||||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
"noImplicitAny": true,
|
||||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
"moduleResolution": "nodenext",
|
||||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
||||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
||||||
|
|
||||||
/* Additional Checks */
|
|
||||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
||||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
||||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
||||||
// "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. */
|
|
||||||
"paths": {
|
"paths": {
|
||||||
"yjs": ["./src/index.js"]
|
"yjs": ["./src/index.js"]
|
||||||
}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
}
|
||||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
||||||
// "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'. */
|
|
||||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
||||||
|
|
||||||
/* Source Map Options */
|
|
||||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
||||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
||||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
||||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
||||||
|
|
||||||
/* Experimental Options */
|
|
||||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
||||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
||||||
// "maxNodeModuleJsDepth": 0,
|
|
||||||
// "types": ["./src/utils/typedefs.js"]
|
|
||||||
},
|
},
|
||||||
"include": ["./src/**/*.js", "./tests/**/*.js"]
|
"include": ["./src/**/*.js", "./tests/**/*.js"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user