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

View File

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

33
src/internals.js Normal file
View 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'

View File

@ -1,23 +1,25 @@
/**
* @module structs
*/
import { readID, createID, writeID, ID } from '../utils/ID.js' // eslint-disable-line import {
import { GC } from './GC.js' 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 encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.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 maplib from 'lib0/map.js'
import * as set from 'lib0/set.js' import * as set from 'lib0/set.js'
import * as binary from 'lib0/binary.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 * Split leftItem into two items

View File

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

View File

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

View File

@ -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 // 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 {
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line AbstractItem,
AbstractItemRef,
getItemCleanEnd,
getItemCleanStart,
getItemType,
Transaction, ID, AbstractType // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.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 export const structBinaryRefNumber = 1

View File

@ -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 // 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 encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.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 export const structDeletedRefNumber = 2

View File

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

View File

@ -2,15 +2,17 @@
* @module structs * @module structs
*/ */
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line import {
import { AbstractItem, AbstractItemRef } from './AbstractItem.js' AbstractItem,
AbstractItemRef,
getItemCleanEnd,
getItemCleanStart,
getItemType,
Transaction, ID, AbstractType // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.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 export const structFormatRefNumber = 4

View File

@ -2,15 +2,18 @@
* @module structs * @module structs
*/ */
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line import {
import { AbstractItem, AbstractItemRef, splitItem } from './AbstractItem.js' AbstractItem,
AbstractItemRef,
getItemCleanEnd,
getItemCleanStart,
getItemType,
splitItem,
Transaction, ID, AbstractType // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.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 export const structJSONRefNumber = 5

View File

@ -1,15 +1,18 @@
/** /**
* @module structs * @module structs
*/ */
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line import {
import { AbstractItem, AbstractItemRef, splitItem } from './AbstractItem.js' AbstractItem,
AbstractItemRef,
getItemCleanEnd,
getItemCleanStart,
getItemType,
splitItem,
Transaction, ID, AbstractType // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.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 export const structStringRefNumber = 6

View File

@ -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 // 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 {
import { Y } from '../utils/Y.js' // eslint-disable-line AbstractItem,
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line AbstractItemRef,
import { AbstractItem, AbstractItemRef } from './AbstractItem.js' 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 encoding from 'lib0/encoding.js' // eslint-disable-line
import * as decoding from 'lib0/decoding.js' 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 * @param {Y} y

View File

@ -2,21 +2,26 @@
* @module structs * @module structs
*/ */
import { Y } from '../utils/Y.js' // eslint-disable-line import {
import * as eventHandler from '../utils/EventHandler.js' removeEventHandlerListener,
import { YEvent } from '../utils/YEvent.js' // eslint-disable-line callEventHandlerListeners,
import { AbstractItem } from '../structs/AbstractItem.js' // eslint-disable-line addEventHandlerListener,
import { ItemType } from '../structs/ItemType.js' // eslint-disable-line createEventHandler,
import { Encoder } from 'lib0/encoding.js' // eslint-disable-line ItemType,
import { Transaction, nextID } from '../utils/Transaction.js' // eslint-disable-line 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 * 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 iterator from 'lib0/iterator.js'
import * as error from 'lib0/error.js' import * as error from 'lib0/error.js'
import * as encoding from 'lib0/encoding.js' // eslint-disable-line
/** /**
* @template EventType * @template EventType
@ -46,14 +51,14 @@ export class AbstractType {
this._length = 0 this._length = 0
/** /**
* Event handlers * Event handlers
* @type {eventHandler.EventHandler<EventType,Transaction>} * @type {EventHandler<EventType,Transaction>}
*/ */
this._eH = eventHandler.create() this._eH = createEventHandler()
/** /**
* Deep event handlers * 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) { _write (encoder) {
throw new Error('unimplemented') throw new Error('unimplemented')
@ -119,7 +124,7 @@ export class AbstractType {
* @param {any} event * @param {any} event
*/ */
_callEventHandler (transaction, event) { _callEventHandler (transaction, event) {
eventHandler.callEventListeners(this._eH, [event, transaction]) callEventHandlerListeners(this._eH, [event, transaction])
const changedParentTypes = transaction.changedParentTypes const changedParentTypes = transaction.changedParentTypes
/** /**
* @type {AbstractType<EventType>} * @type {AbstractType<EventType>}
@ -141,7 +146,7 @@ export class AbstractType {
* @param {function(EventType, Transaction):void} f Observer function * @param {function(EventType, Transaction):void} f Observer function
*/ */
observe (f) { 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 * @param {function(Array<YEvent>,Transaction):void} f Observer function
*/ */
observeDeep (f) { 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 * @param {function(EventType,Transaction):void} f Observer function
*/ */
unobserve (f) { 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 * @param {function(Array<YEvent>,Transaction):void} f Observer function
*/ */
unobserveDeep (f) { unobserveDeep (f) {
eventHandler.removeEventListener(this._dEH, f) removeEventHandlerListener(this._dEH, f)
} }
/** /**

View File

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

View File

@ -2,11 +2,18 @@
* @module types * @module types
*/ */
import { AbstractType, typeMapDelete, typeMapSet, typeMapGet, typeMapHas, createMapIterator } from './AbstractType.js' import {
import { ItemType } from '../structs/ItemType.js' // eslint-disable-line YEvent,
import { YEvent } from '../utils/YEvent.js' 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 * 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' import * as iterator from 'lib0/iterator.js'
/** /**

View File

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

View File

@ -2,15 +2,22 @@
* @module types * @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 encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.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. * Define the elements to which a set of CSS queries apply.

View File

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

View File

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

View File

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

View File

@ -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 map from 'lib0/map.js'
import * as encoding from 'lib0/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.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 { class DeleteItem {
/** /**

View File

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

View File

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

View File

@ -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 { export class Snapshot {
/** /**

View File

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

View File

@ -2,16 +2,17 @@
* @module utils * @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 * 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 * A transaction is created for every change on the Yjs model. It is possible

View File

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

View File

@ -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 random from 'lib0/random.js'
import * as map from 'lib0/map.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 * 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. * A Yjs instance handles the state of shared data.
@ -34,14 +38,6 @@ export class Y extends Observable {
*/ */
this.share = new Map() this.share = new Map()
this.store = new StructStore() this.store = new StructStore()
/**
* @type {Map<number, Map<number, AbstractRef>>}
*/
this._missingStructs = new Map()
/**
* @type {Array<AbstractStruct>}
*/
this._readyToIntegrate = []
/** /**
* @type {Transaction | null} * @type {Transaction | null}
*/ */
@ -54,7 +50,7 @@ export class Y extends Observable {
get transaction () { get transaction () {
const t = this._transaction const t = this._transaction
if (t === null) { 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 return t
} }
@ -98,7 +94,7 @@ export class Y extends Observable {
}) })
// we don't need to check for events.length // we don't need to check for events.length
// because we know it has at least one element // 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 // when all changes & events are processed, emit afterTransaction event
this.emit('afterTransaction', [this, transaction]) this.emit('afterTransaction', [this, transaction])

View File

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

View File

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

View File

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

View File

@ -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 encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js' import * as decoding from 'lib0/decoding.js'
import * as map from 'lib0/map.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 * 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 * 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 * @typedef {Map<number, number>} StateMap

View File

@ -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 array from './y-array.tests.js'
import * as map from './y-map.tests.js' import * as map from './y-map.tests.js'
import * as text from './y-text.tests.js' import * as text from './y-text.tests.js'
import * as xml from './y-xml.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) { if (isBrowser) {
log.createVConsole(document.body) log.createVConsole(document.body)
} }

View File

@ -1,13 +1,18 @@
import * as Y from '../src/index.js' 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 t from 'lib0/testing.js'
import * as prng from 'lib0/prng.js' import * as prng from 'lib0/prng.js'
import { createMutex } from 'lib0/mutex.js' import { createMutex } from 'lib0/mutex.js'
import * as encoding from 'lib0/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js' import * as decoding from 'lib0/decoding.js'
import * as syncProtocol from 'y-protocols/sync.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 * @param {TestYInstance} y
@ -278,9 +283,6 @@ export const compare = users => {
compareDS(createDeleteSetFromStructStore(users[i].store), createDeleteSetFromStructStore(users[i + 1].store)) compareDS(createDeleteSetFromStructStore(users[i].store), createDeleteSetFromStructStore(users[i + 1].store))
compareStructStores(users[i].store, 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()) users.map(u => u.destroy())
} }

View File

@ -1,4 +1,5 @@
import { init, compare, applyRandomTests, TestYInstance } from './testHelper.js' // eslint-disable-line import { init, compare, applyRandomTests, TestYInstance } 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.js' import * as t from 'lib0/testing.js'
import * as prng from 'lib0/prng.js' import * as prng from 'lib0/prng.js'

View File

@ -1,4 +1,5 @@
import { init, compare, applyRandomTests, TestYInstance } from './testHelper.js' // eslint-disable-line import { init, compare, applyRandomTests, TestYInstance } 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.js' import * as t from 'lib0/testing.js'
import * as prng from 'lib0/prng.js' import * as prng from 'lib0/prng.js'

View File

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

View File

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