add internals file and use it to organize imports

This commit is contained in:
Kevin Jahns 2019-04-04 19:35:38 +02:00
parent 8dbd2c4696
commit 30bf3742c9
38 changed files with 378 additions and 260 deletions

@ -1,24 +1,30 @@
export { Y } from './utils/Y.js'
// export { UndoManager } from './utils/UndoManager.js'
export { Transaction } from './utils/Transaction.js'
export { ItemJSON } from './structs/ItemJSON.js'
export { ItemString } from './structs/ItemString.js'
export { ItemFormat } from './structs/ItemFormat.js'
export { ItemEmbed } from './structs/ItemEmbed.js'
export { ItemBinary } from './structs/ItemBinary.js'
export { GC } from './structs/GC.js'
export { YArray as Array } from './types/YArray.js'
export { YMap as Map } from './types/YMap.js'
export { YText as Text } from './types/YText.js'
export { YXmlText as XmlText } from './types/YXmlText.js'
export { YXmlHook as XmlHook } from './types/YXmlHook.js'
export { YXmlElement as XmlElement, YXmlFragment as XmlFragment } from './types/YXmlElement.js'
export { createRelativePosition, createRelativePositionByOffset, createAbsolutePosition, compareRelativePositions, writeRelativePosition, readRelativePosition, AbsolutePosition, RelativePosition } from './utils/relativePosition.js'
export { ID, createID, compareIDs } from './utils/ID.js'
export { isParentOf } from './utils/isParentOf.js'
export { writeStructs, writeStructsFromTransaction, readStructs } from './utils/structEncoding.js'
export { getState, getStates, readStatesAsMap, writeStates } from './utils/StructStore.js'
export {
Y,
Transaction,
YArray as Array,
YMap as Map,
YText as Text,
YXmlText as XmlText,
YXmlHook as XmlHook,
YXmlElement as XmlElement,
YXmlFragment as XmlFragment,
createRelativePosition,
createRelativePositionByOffset,
createAbsolutePosition,
compareRelativePositions,
writeRelativePosition,
readRelativePosition,
AbsolutePosition,
RelativePosition,
ID,
createID,
compareIDs,
writeStructs,
writeStructsFromTransaction,
readStructs,
getState,
getStates,
readStatesAsMap,
writeStates
} from './internals.js'

33
src/internals.js Normal file

@ -0,0 +1,33 @@
export * from './utils/DeleteSet.js'
export * from './utils/EventHandler.js'
export * from './utils/ID.js'
export * from './utils/isParentOf.js'
export * from './utils/relativePosition.js'
export * from './utils/Snapshot.js'
export * from './utils/StructStore.js'
export * from './utils/Transaction.js'
// export * from './utils/UndoManager.js'
export * from './utils/Y.js'
export * from './utils/YEvent.js'
export * from './types/AbstractType.js'
export * from './types/YArray.js'
export * from './types/YMap.js'
export * from './types/YText.js'
export * from './types/YXmlElement.js'
export * from './types/YXmlEvent.js'
export * from './types/YXmlHook.js'
export * from './types/YXmlText.js'
export * from './structs/AbstractStruct.js'
export * from './structs/AbstractItem.js'
export * from './structs/GC.js'
export * from './structs/ItemBinary.js'
export * from './structs/ItemDeleted.js'
export * from './structs/ItemEmbed.js'
export * from './structs/ItemFormat.js'
export * from './structs/ItemJSON.js'
export * from './structs/ItemString.js'
export * from './structs/ItemType.js'
export * from './utils/structEncoding.js'

@ -1,23 +1,25 @@
/**
* @module structs
*/
import { readID, createID, writeID, ID } from '../utils/ID.js' // eslint-disable-line
import { GC } from './GC.js'
import {
readID,
createID,
writeID,
GC,
nextID,
AbstractRef,
AbstractStruct,
replaceStruct,
addStruct,
addToDeleteSet,
ItemDeleted,
ID, AbstractType, Y, Transaction // eslint-disable-line
} from '../internals.js'
import * as error from 'lib0/error.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import { ItemType } from './ItemType.js' // eslint-disable-line
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
import { Y } from '../utils/Y.js' // eslint-disable-line
import { Transaction, nextID } from '../utils/Transaction.js' // eslint-disable-line
import * as maplib from 'lib0/map.js'
import * as set from 'lib0/set.js'
import * as binary from 'lib0/binary.js'
import { AbstractRef, AbstractStruct } from './AbstractStruct.js' // eslint-disable-line
import * as error from 'lib0/error.js'
import { replaceStruct, addStruct } from '../utils/StructStore.js'
import { addToDeleteSet } from '../utils/DeleteSet.js'
import { ItemDeleted } from './ItemDeleted.js'
/**
* Split leftItem into two items

@ -1,6 +1,8 @@
import { Y } from '../utils/Y.js' // eslint-disable-line
import { ID, createID } from '../utils/ID.js' // eslint-disable-line
import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
import {
Y, ID, Transaction // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js' // eslint-disable-line
import * as error from 'lib0/error.js'

@ -1,9 +1,14 @@
/**
* @module structs
*/
import { AbstractRef, AbstractStruct } from './AbstractStruct.js'
import { ID, readID, createID, writeID } from '../utils/ID.js' // eslint-disable-line
import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
import {
AbstractRef,
AbstractStruct,
createID,
writeID,
ID // eslint-disable-line
} from '../internals.js'
import * as decoding from 'lib0/decoding.js'
import * as encoding from 'lib0/encoding.js'

@ -4,14 +4,17 @@
// TODO: ItemBinary should be able to merge with right (similar to other items). Or the other items (ItemJSON) should not be able to merge - extra byte + consistency
import { AbstractItem, AbstractItemRef } from './AbstractItem.js'
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
import {
AbstractItem,
AbstractItemRef,
getItemCleanEnd,
getItemCleanStart,
getItemType,
Transaction, ID, AbstractType // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import { ID } from '../utils/ID.js' // eslint-disable-line
import { Y } from '../utils/Y.js' // eslint-disable-line
import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
import { getItemCleanEnd, getItemCleanStart, getItemType } from '../utils/StructStore.js'
export const structBinaryRefNumber = 1

@ -4,13 +4,17 @@
// TODO: ItemBinary should be able to merge with right (similar to other items). Or the other items (ItemJSON) should not be able to merge - extra byte + consistency
import { AbstractItem, AbstractItemRef } from './AbstractItem.js'
import {
AbstractItem,
AbstractItemRef,
getItemCleanEnd,
getItemCleanStart,
getItemType,
Transaction, ID, AbstractType // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import { ID } from '../utils/ID.js' // eslint-disable-line
import { getItemCleanEnd, getItemCleanStart, getItemType } from '../utils/StructStore.js'
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
export const structDeletedRefNumber = 2

@ -2,15 +2,17 @@
* @module structs
*/
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
import { AbstractItem, AbstractItemRef } from './AbstractItem.js'
import { ItemType } from './ItemType.js' // eslint-disable-line
import {
AbstractItem,
AbstractItemRef,
getItemCleanEnd,
getItemCleanStart,
getItemType,
Transaction, ID, AbstractType // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line
import { ID } from '../utils/ID.js' // eslint-disable-line
import { getItemCleanEnd, getItemCleanStart, getItemType } from '../utils/StructStore.js'
import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
export const structEmbedRefNumber = 3

@ -2,15 +2,17 @@
* @module structs
*/
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
import { AbstractItem, AbstractItemRef } from './AbstractItem.js'
import {
AbstractItem,
AbstractItemRef,
getItemCleanEnd,
getItemCleanStart,
getItemType,
Transaction, ID, AbstractType // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line
import { ID } from '../utils/ID.js' // eslint-disable-line
import { ItemType } from './ItemType.js' // eslint-disable-line
import { getItemCleanEnd, getItemCleanStart, getItemType } from '../utils/StructStore.js'
import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
export const structFormatRefNumber = 4

@ -2,15 +2,18 @@
* @module structs
*/
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
import { AbstractItem, AbstractItemRef, splitItem } from './AbstractItem.js'
import {
AbstractItem,
AbstractItemRef,
getItemCleanEnd,
getItemCleanStart,
getItemType,
splitItem,
Transaction, ID, AbstractType // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line
import { ID } from '../utils/ID.js' // eslint-disable-line
import { ItemType } from './ItemType.js' // eslint-disable-line
import { getItemCleanEnd, getItemCleanStart, getItemType } from '../utils/StructStore.js'
import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
export const structJSONRefNumber = 5

@ -1,15 +1,18 @@
/**
* @module structs
*/
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
import { AbstractItem, AbstractItemRef, splitItem } from './AbstractItem.js'
import {
AbstractItem,
AbstractItemRef,
getItemCleanEnd,
getItemCleanStart,
getItemType,
splitItem,
Transaction, ID, AbstractType // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line
import { ID } from '../utils/ID.js' // eslint-disable-line
import { ItemType } from './ItemType.js' // eslint-disable-line
import { getItemCleanEnd, getItemCleanStart, getItemType } from '../utils/StructStore.js'
import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
export const structStringRefNumber = 6

@ -4,22 +4,24 @@
// TODO: ItemBinary should be able to merge with right (similar to other items). Or the other items (ItemJSON) should not be able to merge - extra byte + consistency
import { ID } from '../utils/ID.js' // eslint-disable-line
import { Y } from '../utils/Y.js' // eslint-disable-line
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
import { AbstractItem, AbstractItemRef } from './AbstractItem.js'
import {
AbstractItem,
AbstractItemRef,
getItemCleanEnd,
getItemCleanStart,
getItemType,
readYArray,
readYMap,
readYText,
readYXmlElement,
readYXmlFragment,
readYXmlHook,
readYXmlText,
Y, GC, ItemDeleted, Transaction, ID, AbstractType // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js' // eslint-disable-line
import * as decoding from 'lib0/decoding.js'
import { readYArray } from '../types/YArray.js'
import { readYMap } from '../types/YMap.js'
import { readYText } from '../types/YText.js'
import { readYXmlElement, readYXmlFragment } from '../types/YXmlElement.js'
import { readYXmlHook } from '../types/YXmlHook.js'
import { readYXmlText } from '../types/YXmlText.js'
import { getItemCleanEnd, getItemCleanStart, getItemType } from '../utils/StructStore.js'
import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
import { GC } from './GC.js' // eslint-disable-line
import { ItemDeleted } from './ItemDeleted.js' // eslint-disable-line
/**
* @param {Y} y

@ -2,21 +2,26 @@
* @module structs
*/
import { Y } from '../utils/Y.js' // eslint-disable-line
import * as eventHandler from '../utils/EventHandler.js'
import { YEvent } from '../utils/YEvent.js' // eslint-disable-line
import { AbstractItem } from '../structs/AbstractItem.js' // eslint-disable-line
import { ItemType } from '../structs/ItemType.js' // eslint-disable-line
import { Encoder } from 'lib0/encoding.js' // eslint-disable-line
import { Transaction, nextID } from '../utils/Transaction.js' // eslint-disable-line
import {
removeEventHandlerListener,
callEventHandlerListeners,
addEventHandlerListener,
createEventHandler,
ItemType,
nextID,
isVisible,
ItemJSON,
ItemBinary,
createID,
getItemCleanStart,
getItemCleanEnd,
Y, Snapshot, Transaction, EventHandler, YEvent, AbstractItem, // eslint-disable-line
} from '../internals.js'
import * as map from 'lib0/map.js'
import { isVisible, Snapshot } from '../utils/Snapshot.js' // eslint-disable-line
import { ItemJSON } from '../structs/ItemJSON.js'
import { ItemBinary } from '../structs/ItemBinary.js'
import { ID, createID } from '../utils/ID.js' // eslint-disable-line
import { getItemCleanStart, getItemCleanEnd } from '../utils/StructStore.js'
import * as iterator from 'lib0/iterator.js'
import * as error from 'lib0/error.js'
import * as encoding from 'lib0/encoding.js' // eslint-disable-line
/**
* @template EventType
@ -46,14 +51,14 @@ export class AbstractType {
this._length = 0
/**
* Event handlers
* @type {eventHandler.EventHandler<EventType,Transaction>}
* @type {EventHandler<EventType,Transaction>}
*/
this._eH = eventHandler.create()
this._eH = createEventHandler()
/**
* Deep event handlers
* @type {eventHandler.EventHandler<Array<YEvent>,Transaction>}
* @type {EventHandler<Array<YEvent>,Transaction>}
*/
this._dEH = eventHandler.create()
this._dEH = createEventHandler()
}
/**
@ -80,7 +85,7 @@ export class AbstractType {
}
/**
* @param {Encoder} encoder
* @param {encoding.Encoder} encoder
*/
_write (encoder) {
throw new Error('unimplemented')
@ -119,7 +124,7 @@ export class AbstractType {
* @param {any} event
*/
_callEventHandler (transaction, event) {
eventHandler.callEventListeners(this._eH, [event, transaction])
callEventHandlerListeners(this._eH, [event, transaction])
const changedParentTypes = transaction.changedParentTypes
/**
* @type {AbstractType<EventType>}
@ -141,7 +146,7 @@ export class AbstractType {
* @param {function(EventType, Transaction):void} f Observer function
*/
observe (f) {
eventHandler.addEventListener(this._eH, f)
addEventHandlerListener(this._eH, f)
}
/**
@ -150,7 +155,7 @@ export class AbstractType {
* @param {function(Array<YEvent>,Transaction):void} f Observer function
*/
observeDeep (f) {
eventHandler.addEventListener(this._dEH, f)
addEventHandlerListener(this._dEH, f)
}
/**
@ -159,7 +164,7 @@ export class AbstractType {
* @param {function(EventType,Transaction):void} f Observer function
*/
unobserve (f) {
eventHandler.removeEventListener(this._eH, f)
removeEventHandlerListener(this._eH, f)
}
/**
@ -168,7 +173,7 @@ export class AbstractType {
* @param {function(Array<YEvent>,Transaction):void} f Observer function
*/
unobserveDeep (f) {
eventHandler.removeEventListener(this._dEH, f)
removeEventHandlerListener(this._dEH, f)
}
/**

@ -2,11 +2,19 @@
* @module types
*/
import { AbstractItem } from '../structs/AbstractItem.js' // eslint-disable-line
import { ItemType } from '../structs/ItemType.js' // eslint-disable-line
import { AbstractType, typeArrayGet, typeArrayToArray, typeArrayForEach, typeArrayCreateIterator, typeArrayInsertGenerics, typeArrayDelete, typeArrayMap } from './AbstractType.js'
import { YEvent } from '../utils/YEvent.js'
import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
import {
YEvent,
AbstractType,
typeArrayGet,
typeArrayToArray,
typeArrayForEach,
typeArrayCreateIterator,
typeArrayInsertGenerics,
typeArrayDelete,
typeArrayMap,
Transaction, ItemType, // eslint-disable-line
} from '../internals.js'
import * as decoding from 'lib0/decoding.js' // eslint-disable-line
/**

@ -2,11 +2,18 @@
* @module types
*/
import { AbstractType, typeMapDelete, typeMapSet, typeMapGet, typeMapHas, createMapIterator } from './AbstractType.js'
import { ItemType } from '../structs/ItemType.js' // eslint-disable-line
import { YEvent } from '../utils/YEvent.js'
import {
YEvent,
AbstractType,
typeMapDelete,
typeMapSet,
typeMapGet,
typeMapHas,
createMapIterator,
Transaction, ItemType, // eslint-disable-line
} from '../internals.js'
import * as decoding from 'lib0/decoding.js' // eslint-disable-line
import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
import * as iterator from 'lib0/iterator.js'
/**

@ -2,17 +2,19 @@
* @module types
*/
import { ItemEmbed } from '../structs/ItemEmbed.js'
import { ItemString } from '../structs/ItemString.js'
import { ItemFormat } from '../structs/ItemFormat.js'
import { YEvent } from '../utils/YEvent.js'
import { ItemType } from '../structs/ItemType.js' // eslint-disable-line
import { AbstractType } from './AbstractType.js'
import { AbstractItem } from '../structs/AbstractItem.js' // eslint-disable-line
import { isVisible, Snapshot } from '../utils/Snapshot.js' // eslint-disable-line
import { getItemCleanStart, StructStore } from '../utils/StructStore.js' // eslint-disable-line
import { Transaction, nextID } from '../utils/Transaction.js' // eslint-disable-line
import { createID } from '../utils/ID.js'
import {
YEvent,
ItemEmbed,
ItemString,
ItemFormat,
AbstractType,
nextID,
createID,
getItemCleanStart,
isVisible,
ItemType, AbstractItem, Snapshot, StructStore, Transaction // eslint-disable-line
} from '../internals.js'
import * as decoding from 'lib0/decoding.js' // eslint-disable-line
/**

@ -2,15 +2,22 @@
* @module types
*/
import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
import {
YXmlEvent,
AbstractType,
typeArrayMap,
typeArrayForEach,
typeMapGet,
typeMapGetAll,
typeArrayInsertGenerics,
typeArrayDelete,
typeMapSet,
typeMapDelete,
Transaction, ItemType, YXmlText, YXmlHook, Snapshot // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import { YXmlEvent } from './YXmlEvent.js'
import { ItemType } from '../structs/ItemType.js' // eslint-disable-line
import { YXmlText } from './YXmlText.js' // eslint-disable-line
import { YXmlHook } from './YXmlHook.js' // eslint-disable-line
import { AbstractType, typeArrayMap, typeArrayForEach, typeMapGet, typeMapGetAll, typeArrayInsertGenerics, typeArrayDelete, typeMapSet, typeMapDelete } from './AbstractType.js'
import { Snapshot } from '../utils/Snapshot.js' // eslint-disable-line
/**
* Define the elements to which a set of CSS queries apply.

@ -2,11 +2,10 @@
* @module types
*/
import { YEvent } from '../utils/YEvent.js'
import { AbstractType } from './AbstractType.js' // eslint-disable-line
import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
import { YXmlElement, YXmlFragment } from './YXmlElement.js' // eslint-disable-line
import {
YEvent,
YXmlElement, YXmlFragment, Transaction // eslint-disable-line
} from '../internals.js'
/**
* An Event that describes changes on a YXml Element or Yxml Fragment

@ -2,7 +2,7 @@
* @module types
*/
import { YMap } from './YMap.js'
import { YMap } from '../internals.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'

@ -2,7 +2,8 @@
* @module types
*/
import { YText } from './YText.js'
import { YText } from '../internals.js'
import * as decoding from 'lib0/decoding.js' // eslint-disable-line
/**

@ -1,10 +1,13 @@
import {
getItemRange,
StructStore, Transaction, ID // eslint-disable-line
} from '../internals.js'
import * as math from 'lib0/math.js'
import * as map from 'lib0/map.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import * as math from 'lib0/math.js'
import { StructStore, getItemRange } from './StructStore.js' // eslint-disable-line
import { Transaction } from './Transaction.js' // eslint-disable-line
import { ID } from './ID.js' // eslint-disable-line
class DeleteItem {
/**

@ -1,5 +1,3 @@
import { Transaction } from './Transaction.js' // eslint-disable-line
import { YEvent } from './YEvent.js' // eslint-disable-line
import * as f from 'lib0/function.js'
/**
@ -20,7 +18,7 @@ export class EventHandler {
* @template ARG0,ARG1
* @returns {EventHandler<ARG0,ARG1>}
*/
export const create = () => new EventHandler()
export const createEventHandler = () => new EventHandler()
/**
* Adds an event listener that is called when
@ -30,7 +28,7 @@ export const create = () => new EventHandler()
* @param {EventHandler<ARG0,ARG1>} eventHandler
* @param {function(ARG0,ARG1):void} f The event handler.
*/
export const addEventListener = (eventHandler, f) =>
export const addEventHandlerListener = (eventHandler, f) =>
eventHandler.l.push(f)
/**
@ -41,7 +39,7 @@ export const addEventListener = (eventHandler, f) =>
* @param {function(ARG0,ARG1):void} f The event handler that was added with
* {@link EventHandler#addEventListener}
*/
export const removeEventListener = (eventHandler, f) => {
export const removeEventHandlerListener = (eventHandler, f) => {
eventHandler.l = eventHandler.l.filter(g => f !== g)
}
@ -50,7 +48,7 @@ export const removeEventListener = (eventHandler, f) => {
* @template ARG0,ARG1
* @param {EventHandler<ARG0,ARG1>} eventHandler
*/
export const removeAllEventListeners = eventHandler => {
export const removeAllEventHandlerListeners = eventHandler => {
eventHandler.l.length = 0
}
@ -62,5 +60,5 @@ export const removeAllEventListeners = eventHandler => {
* @param {EventHandler<ARG0,ARG1>} eventHandler
* @param {[ARG0,ARG1]} args
*/
export const callEventListeners = (eventHandler, args) =>
export const callEventHandlerListeners = (eventHandler, args) =>
f.callAll(eventHandler.l, args)

@ -2,10 +2,11 @@
* @module utils
*/
import { AbstractType } from '../internals' // eslint-disable-line
import * as decoding from 'lib0/decoding.js'
import * as encoding from 'lib0/encoding.js'
import * as error from 'lib0/error.js'
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
export class ID {
/**

@ -1,5 +1,9 @@
import { DeleteSet, isDeleted } from './DeleteSet'
import { AbstractItem } from '../structs/AbstractItem.js' // eslint-disable-line
import {
DeleteSet,
isDeleted,
AbstractItem // eslint-disable-line
} from '../internals.js'
export class Snapshot {
/**

@ -1,8 +1,8 @@
import { AbstractStruct } from '../structs/AbstractStruct.js' // eslint-disable-line
import { AbstractItem } from '../structs/AbstractItem.js' // eslint-disable-line
import { ItemType } from '../structs/ItemType.js' // eslint-disable-line
import { ID } from './ID.js' // eslint-disable-line
import { Transaction } from './Transaction.js' // eslint-disable-line
import {
Transaction, ID, ItemType, AbstractItem, AbstractStruct // eslint-disable-line
} from '../internals.js'
import * as map from 'lib0/map.js'
import * as math from 'lib0/math.js'
import * as error from 'lib0/error.js'

@ -2,16 +2,17 @@
* @module utils
*/
import {
getState,
createID,
writeStructsFromTransaction,
writeDeleteSet,
DeleteSet,
sortAndMergeDeleteSet,
AbstractType, AbstractItem, YEvent, ItemType, Y // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js'
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
import { AbstractItem } from '../structs/AbstractItem.js' // eslint-disable-line
import { Y } from './Y.js' // eslint-disable-line
import { YEvent } from './YEvent.js' // eslint-disable-line
import { ItemType } from '../structs/ItemType.js' // eslint-disable-line
import { writeStructsFromTransaction } from './structEncoding.js'
import { createID } from './ID.js' // eslint-disable-line
import { writeDeleteSet, DeleteSet, sortAndMergeDeleteSet } from './DeleteSet.js'
import { getState } from './StructStore.js'
/**
* A transaction is created for every change on the Yjs model. It is possible

@ -1,15 +1,17 @@
// @ts-nocheck
import * as ID from './ID.js'
import { isParentOf } from './isParentOf.js'
import {
isParentOf,
createID
} from '../internals.js'
class ReverseOperation {
constructor (y, transaction, bindingInfos) {
this.created = new Date()
const beforeState = transaction.beforeState
if (beforeState.has(y.userID)) {
this.toState = ID.createID(y.userID, y.ss.getState(y.userID) - 1)
this.fromState = ID.createID(y.userID, beforeState.get(y.userID))
this.toState = createID(y.userID, y.ss.getState(y.userID) - 1)
this.fromState = createID(y.userID, beforeState.get(y.userID))
} else {
this.toState = null
this.fromState = null
@ -51,7 +53,7 @@ function applyReverseOperation (y, scope, reverseBuffer) {
const redoitems = new Set()
for (let del of undoOp.deletedStructs) {
const fromState = del.from
const toState = ID.createID(fromState.user, fromState.clock + del.len - 1)
const toState = createID(fromState.user, fromState.clock + del.len - 1)
y.os.getItemCleanStart(fromState)
y.os.getItemCleanEnd(toState)
y.os.iterate(fromState, toState, op => {

@ -1,21 +1,25 @@
import { StructStore, findIndexSS } from './StructStore.js'
import { } from './StructStore.js'
import {
callEventHandlerListeners,
sortAndMergeDeleteSet,
StructStore,
findIndexSS,
Transaction,
AbstractType,
AbstractItem,
YArray,
YText,
YMap,
YXmlFragment,
YEvent, ItemDeleted, GC, AbstractStruct // eslint-disable-line
} from '../internals.js'
import { Observable } from 'lib0/observable.js'
import * as error from 'lib0/error.js'
import * as random from 'lib0/random.js'
import * as map from 'lib0/map.js'
import { Observable } from 'lib0/observable.js'
import { Transaction } from './Transaction.js'
import { AbstractStruct, AbstractRef } from '../structs/AbstractStruct.js' // eslint-disable-line
import { AbstractType } from '../types/AbstractType.js'
import { AbstractItem } from '../structs/AbstractItem.js'
import { sortAndMergeDeleteSet } from './DeleteSet.js'
import * as math from 'lib0/math.js'
import { GC } from '../structs/GC.js' // eslint-disable-line
import { ItemDeleted } from '../structs/ItemDeleted.js' // eslint-disable-line
import { YArray } from '../types/YArray.js'
import { YText } from '../types/YText.js'
import { YMap } from '../types/YMap.js'
import { YXmlFragment } from '../types/YXmlElement.js'
import { YEvent } from './YEvent.js' // eslint-disable-line
import * as eventHandler from './EventHandler.js'
/**
* A Yjs instance handles the state of shared data.
@ -34,14 +38,6 @@ export class Y extends Observable {
*/
this.share = new Map()
this.store = new StructStore()
/**
* @type {Map<number, Map<number, AbstractRef>>}
*/
this._missingStructs = new Map()
/**
* @type {Array<AbstractStruct>}
*/
this._readyToIntegrate = []
/**
* @type {Transaction | null}
*/
@ -54,7 +50,7 @@ export class Y extends Observable {
get transaction () {
const t = this._transaction
if (t === null) {
throw new Error('All changes must happen inside a transaction')
throw error.create('All changes must happen inside a transaction')
}
return t
}
@ -98,7 +94,7 @@ export class Y extends Observable {
})
// we don't need to check for events.length
// because we know it has at least one element
eventHandler.callEventListeners(type._dEH, [events, transaction])
callEventHandlerListeners(type._dEH, [events, transaction])
})
// when all changes & events are processed, emit afterTransaction event
this.emit('afterTransaction', [this, transaction])

@ -1,8 +1,8 @@
import { AbstractItem } from '../structs/AbstractItem.js' // eslint-disable-line
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
import { Transaction } from './Transaction.js' // eslint-disable-line
import { AbstractStruct } from '../structs/AbstractStruct.js' // eslint-disable-line
import { isDeleted } from './DeleteSet.js'
import {
isDeleted,
AbstractItem, AbstractType, Transaction, AbstractStruct // eslint-disable-line
} from '../internals.js'
/**
* @module utils

@ -2,8 +2,7 @@
* @module utils
*/
import { Y } from '../utils/Y.js' // eslint-disable-line
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
import { AbstractType } from '../internals.js' // eslint-disable-line
/**
* Check if `parent` is a parent of `child`.

@ -1,15 +1,20 @@
/**
* @module utils
*/
import * as ID from './ID.js'
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
import { AbstractItem } from '../structs/AbstractItem.js' // eslint-disable-line
import {
find,
exists,
getItemType,
createID,
writeID,
readID,
compareIDs,
findRootTypeKey,
AbstractItem,
ID, StructStore, Y, AbstractType // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import * as error from 'lib0/error.js'
import { find, exists, getItemType, StructStore } from './StructStore.js' // eslint-disable-line
import { Y } from './Y.js' // eslint-disable-line
/**
* A relative position that is based on the Yjs model. In contrast to an
@ -38,13 +43,13 @@ import { Y } from './Y.js' // eslint-disable-line
*/
export class RelativePosition {
/**
* @param {ID.ID|null} type
* @param {ID|null} type
* @param {string|null} tname
* @param {ID.ID|null} item
* @param {ID|null} item
*/
constructor (type, tname, item) {
/**
* @type {ID.ID|null}
* @type {ID|null}
*/
this.type = type
/**
@ -52,7 +57,7 @@ export class RelativePosition {
*/
this.tname = tname
/**
* @type {ID.ID | null}
* @type {ID | null}
*/
this.item = item
}
@ -83,13 +88,13 @@ export const createAbsolutePosition = (type, offset) => new AbsolutePosition(typ
/**
* @param {AbstractType<any>} type
* @param {ID.ID|null} item
* @param {ID|null} item
*/
export const createRelativePosition = (type, item) => {
let typeid = null
let tname = null
if (type._item === null) {
tname = ID.findRootTypeKey(type)
tname = findRootTypeKey(type)
} else {
typeid = type._item.id
}
@ -109,7 +114,7 @@ export const createRelativePositionByOffset = (type, offset) => {
if (!t.deleted && t.countable) {
if (t.length > offset) {
// case 1: found position somewhere in the linked list
return createRelativePosition(type, ID.createID(t.id.client, t.id.clock + offset))
return createRelativePosition(type, createID(t.id.client, t.id.clock + offset))
}
offset -= t.length
}
@ -126,7 +131,7 @@ export const writeRelativePosition = (encoder, rpos) => {
const { type, tname, item } = rpos
if (item !== null) {
encoding.writeVarUint(encoder, 0)
ID.writeID(encoder, item)
writeID(encoder, item)
} else if (tname !== null) {
// case 2: found position at the end of the list and type is stored in y.share
encoding.writeUint8(encoder, 1)
@ -134,7 +139,7 @@ export const writeRelativePosition = (encoder, rpos) => {
} else if (type !== null) {
// case 3: found position at the end of the list and type is attached to an item
encoding.writeUint8(encoder, 2)
ID.writeID(encoder, type)
writeID(encoder, type)
} else {
throw error.unexpectedCase()
}
@ -154,7 +159,7 @@ export const readRelativePosition = (decoder, y, store) => {
switch (decoding.readVarUint(decoder)) {
case 0:
// case 1: found position somewhere in the linked list
itemID = ID.readID(decoder)
itemID = readID(decoder)
break
case 1:
// case 2: found position at the end of the list and type is stored in y.share
@ -162,7 +167,7 @@ export const readRelativePosition = (decoder, y, store) => {
break
case 2: {
// case 3: found position at the end of the list and type is attached to an item
type = ID.readID(decoder)
type = readID(decoder)
}
}
return new RelativePosition(type, tname, itemID)
@ -231,7 +236,7 @@ export const toRelativePosition = (apos, y) => {
while (n !== null) {
if (!n.deleted && n.countable) {
if (n.length > offset) {
return createRelativePosition(type, ID.createID(n.id.client, n.id.clock + offset))
return createRelativePosition(type, createID(n.id.client, n.id.clock + offset))
}
offset -= n.length
}
@ -247,8 +252,8 @@ export const toRelativePosition = (apos, y) => {
*/
export const compareRelativePositions = (a, b) => a === b || (
a !== null && b !== null && (
(a.item !== null && b.item !== null && ID.compareIDs(a.item, b.item)) ||
(a.item !== null && b.item !== null && compareIDs(a.item, b.item)) ||
(a.tname !== null && a.tname === b.tname) ||
(a.type !== null && b.type !== null && ID.compareIDs(a.type, b.type))
(a.type !== null && b.type !== null && compareIDs(a.type, b.type))
)
)

@ -1,20 +1,26 @@
import {
findIndexSS,
exists,
ItemBinaryRef,
GCRef,
ItemDeletedRef,
ItemEmbedRef,
ItemFormatRef,
ItemJSONRef,
ItemStringRef,
ItemTypeRef,
writeID,
createID,
readID,
Transaction, AbstractStruct, AbstractRef, StructStore, ID // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import * as map from 'lib0/map.js'
import { AbstractStruct, AbstractRef } from '../structs/AbstractStruct.js' // eslint-disable-line
import * as binary from 'lib0/binary.js'
import { Transaction } from './Transaction.js' // eslint-disable-line
import { findIndexSS, exists, StructStore } from './StructStore.js' // eslint-disable-line
import { writeID, createID, readID, ID } from './ID.js' // eslint-disable-line
import * as iterator from 'lib0/iterator.js'
import { ItemBinaryRef } from '../structs/ItemBinary.js'
import { GCRef } from '../structs/GC.js'
import { ItemDeletedRef } from '../structs/ItemDeleted.js'
import { ItemEmbedRef } from '../structs/ItemEmbed.js'
import { ItemFormatRef } from '../structs/ItemFormat.js'
import { ItemJSONRef } from '../structs/ItemJSON.js'
import { ItemStringRef } from '../structs/ItemString.js'
import { ItemTypeRef } from '../structs/ItemType.js'
/**
* @typedef {Map<number, number>} StateMap

@ -1,12 +1,13 @@
import { runTests } from 'lib0/testing.js'
import { isBrowser } from 'lib0/environment.js'
import * as log from 'lib0/logging.js'
import * as array from './y-array.tests.js'
import * as map from './y-map.tests.js'
import * as text from './y-text.tests.js'
import * as xml from './y-xml.tests.js'
import { runTests } from 'lib0/testing.js'
import { isBrowser } from 'lib0/environment.js'
import * as log from 'lib0/logging.js'
if (isBrowser) {
log.createVConsole(document.body)
}

@ -1,13 +1,18 @@
import * as Y from '../src/index.js'
import {
createDeleteSetFromStructStore,
getStates,
AbstractItem,
DeleteSet, StructStore // eslint-disable-line
} from '../src/internals.js'
import * as t from 'lib0/testing.js'
import * as prng from 'lib0/prng.js'
import { createMutex } from 'lib0/mutex.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import * as syncProtocol from 'y-protocols/sync.js'
import { createDeleteSetFromStructStore, DeleteSet } from '../src/utils/DeleteSet.js' // eslint-disable-line
import { getStates, StructStore } from '../src/utils/StructStore.js' // eslint-disable-line
import { AbstractItem } from '../src/structs/AbstractItem.js' // eslint-disable-line
/**
* @param {TestYInstance} y
@ -278,9 +283,6 @@ export const compare = users => {
compareDS(createDeleteSetFromStructStore(users[i].store), createDeleteSetFromStructStore(users[i + 1].store))
compareStructStores(users[i].store, users[i + 1].store)
}
users.forEach(user =>
t.assert(user._missingStructs.size === 0)
)
users.map(u => u.destroy())
}

@ -1,4 +1,5 @@
import { init, compare, applyRandomTests, TestYInstance } from './testHelper.js' // eslint-disable-line
import * as Y from '../src/index.js'
import * as t from 'lib0/testing.js'
import * as prng from 'lib0/prng.js'

@ -1,4 +1,5 @@
import { init, compare, applyRandomTests, TestYInstance } from './testHelper.js' // eslint-disable-line
import * as Y from '../src/index.js'
import * as t from 'lib0/testing.js'
import * as prng from 'lib0/prng.js'

@ -1,4 +1,5 @@
import { init, compare } from './testHelper.js'
import * as t from 'lib0/testing.js'
/**

@ -1,5 +1,6 @@
import { init, compare } from './testHelper.js'
import * as Y from '../src/index.js'
import * as t from 'lib0/testing.js'
/**