diff --git a/src/index.js b/src/index.js index 990aab25..2db9148a 100644 --- a/src/index.js +++ b/src/index.js @@ -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' diff --git a/src/internals.js b/src/internals.js new file mode 100644 index 00000000..dea4946c --- /dev/null +++ b/src/internals.js @@ -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' diff --git a/src/structs/AbstractItem.js b/src/structs/AbstractItem.js index 7b0ad76a..ac920482 100644 --- a/src/structs/AbstractItem.js +++ b/src/structs/AbstractItem.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 diff --git a/src/structs/AbstractStruct.js b/src/structs/AbstractStruct.js index c214d30a..860b92f7 100644 --- a/src/structs/AbstractStruct.js +++ b/src/structs/AbstractStruct.js @@ -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' diff --git a/src/structs/GC.js b/src/structs/GC.js index 25ce963b..06d42be5 100644 --- a/src/structs/GC.js +++ b/src/structs/GC.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' diff --git a/src/structs/ItemBinary.js b/src/structs/ItemBinary.js index b08c55b7..370b88f1 100644 --- a/src/structs/ItemBinary.js +++ b/src/structs/ItemBinary.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 diff --git a/src/structs/ItemDeleted.js b/src/structs/ItemDeleted.js index 0211aecb..0c4a93a2 100644 --- a/src/structs/ItemDeleted.js +++ b/src/structs/ItemDeleted.js @@ -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 diff --git a/src/structs/ItemEmbed.js b/src/structs/ItemEmbed.js index 559abee0..27c47dd2 100644 --- a/src/structs/ItemEmbed.js +++ b/src/structs/ItemEmbed.js @@ -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 diff --git a/src/structs/ItemFormat.js b/src/structs/ItemFormat.js index 943c27c5..8747146c 100644 --- a/src/structs/ItemFormat.js +++ b/src/structs/ItemFormat.js @@ -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 diff --git a/src/structs/ItemJSON.js b/src/structs/ItemJSON.js index 9271b966..21e041f3 100644 --- a/src/structs/ItemJSON.js +++ b/src/structs/ItemJSON.js @@ -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 diff --git a/src/structs/ItemString.js b/src/structs/ItemString.js index e0088efe..66785ac8 100644 --- a/src/structs/ItemString.js +++ b/src/structs/ItemString.js @@ -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 diff --git a/src/structs/ItemType.js b/src/structs/ItemType.js index c065c615..906dd3db 100644 --- a/src/structs/ItemType.js +++ b/src/structs/ItemType.js @@ -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 diff --git a/src/types/AbstractType.js b/src/types/AbstractType.js index 27924220..e57231ef 100644 --- a/src/types/AbstractType.js +++ b/src/types/AbstractType.js @@ -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} + * @type {EventHandler} */ - this._eH = eventHandler.create() + this._eH = createEventHandler() /** * Deep event handlers - * @type {eventHandler.EventHandler,Transaction>} + * @type {EventHandler,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} @@ -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,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,Transaction):void} f Observer function */ unobserveDeep (f) { - eventHandler.removeEventListener(this._dEH, f) + removeEventHandlerListener(this._dEH, f) } /** diff --git a/src/types/YArray.js b/src/types/YArray.js index 8b9ff161..f5a13941 100644 --- a/src/types/YArray.js +++ b/src/types/YArray.js @@ -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 /** diff --git a/src/types/YMap.js b/src/types/YMap.js index 290db548..25f4d58e 100644 --- a/src/types/YMap.js +++ b/src/types/YMap.js @@ -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' /** diff --git a/src/types/YText.js b/src/types/YText.js index a6057906..f949dae2 100644 --- a/src/types/YText.js +++ b/src/types/YText.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 /** diff --git a/src/types/YXmlElement.js b/src/types/YXmlElement.js index e03df0d5..69f1479e 100644 --- a/src/types/YXmlElement.js +++ b/src/types/YXmlElement.js @@ -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. diff --git a/src/types/YXmlEvent.js b/src/types/YXmlEvent.js index 19c8aa10..38f4b727 100644 --- a/src/types/YXmlEvent.js +++ b/src/types/YXmlEvent.js @@ -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 diff --git a/src/types/YXmlHook.js b/src/types/YXmlHook.js index 95a89f1d..a052ffad 100644 --- a/src/types/YXmlHook.js +++ b/src/types/YXmlHook.js @@ -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' diff --git a/src/types/YXmlText.js b/src/types/YXmlText.js index 69aeb10a..c410cb9c 100644 --- a/src/types/YXmlText.js +++ b/src/types/YXmlText.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 /** diff --git a/src/utils/DeleteSet.js b/src/utils/DeleteSet.js index 3b1f1137..dd3d8493 100644 --- a/src/utils/DeleteSet.js +++ b/src/utils/DeleteSet.js @@ -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 { /** diff --git a/src/utils/EventHandler.js b/src/utils/EventHandler.js index f6e89d85..f366338a 100644 --- a/src/utils/EventHandler.js +++ b/src/utils/EventHandler.js @@ -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} */ -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} 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} eventHandler */ -export const removeAllEventListeners = eventHandler => { +export const removeAllEventHandlerListeners = eventHandler => { eventHandler.l.length = 0 } @@ -62,5 +60,5 @@ export const removeAllEventListeners = eventHandler => { * @param {EventHandler} eventHandler * @param {[ARG0,ARG1]} args */ -export const callEventListeners = (eventHandler, args) => +export const callEventHandlerListeners = (eventHandler, args) => f.callAll(eventHandler.l, args) diff --git a/src/utils/ID.js b/src/utils/ID.js index 802e1bfc..114f7c47 100644 --- a/src/utils/ID.js +++ b/src/utils/ID.js @@ -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 { /** diff --git a/src/utils/Snapshot.js b/src/utils/Snapshot.js index bebf987d..941be3c6 100644 --- a/src/utils/Snapshot.js +++ b/src/utils/Snapshot.js @@ -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 { /** diff --git a/src/utils/StructStore.js b/src/utils/StructStore.js index 80fdcde9..27790373 100644 --- a/src/utils/StructStore.js +++ b/src/utils/StructStore.js @@ -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' diff --git a/src/utils/Transaction.js b/src/utils/Transaction.js index 4119df95..1e33d6c8 100644 --- a/src/utils/Transaction.js +++ b/src/utils/Transaction.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 diff --git a/src/utils/UndoManager.js b/src/utils/UndoManager.js index 1e1f8b8a..69a72894 100644 --- a/src/utils/UndoManager.js +++ b/src/utils/UndoManager.js @@ -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 => { diff --git a/src/utils/Y.js b/src/utils/Y.js index 615f4914..d385bac7 100644 --- a/src/utils/Y.js +++ b/src/utils/Y.js @@ -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>} - */ - this._missingStructs = new Map() - /** - * @type {Array} - */ - 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]) diff --git a/src/utils/YEvent.js b/src/utils/YEvent.js index c2bb85ce..c908390c 100644 --- a/src/utils/YEvent.js +++ b/src/utils/YEvent.js @@ -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 diff --git a/src/utils/isParentOf.js b/src/utils/isParentOf.js index 638bcc06..808212c7 100644 --- a/src/utils/isParentOf.js +++ b/src/utils/isParentOf.js @@ -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`. diff --git a/src/utils/relativePosition.js b/src/utils/relativePosition.js index 4c48d097..cf1c992a 100644 --- a/src/utils/relativePosition.js +++ b/src/utils/relativePosition.js @@ -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} 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)) ) ) diff --git a/src/utils/structEncoding.js b/src/utils/structEncoding.js index c85145fe..266ef4c2 100644 --- a/src/utils/structEncoding.js +++ b/src/utils/structEncoding.js @@ -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} StateMap diff --git a/tests/index.js b/tests/index.js index f4345138..6241d0dd 100644 --- a/tests/index.js +++ b/tests/index.js @@ -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) } diff --git a/tests/testHelper.js b/tests/testHelper.js index 47d024a2..da6240e8 100644 --- a/tests/testHelper.js +++ b/tests/testHelper.js @@ -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()) } diff --git a/tests/y-array.tests.js b/tests/y-array.tests.js index ab950806..bd94cd2c 100644 --- a/tests/y-array.tests.js +++ b/tests/y-array.tests.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' diff --git a/tests/y-map.tests.js b/tests/y-map.tests.js index eae65910..359743df 100644 --- a/tests/y-map.tests.js +++ b/tests/y-map.tests.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' diff --git a/tests/y-text.tests.js b/tests/y-text.tests.js index 1ef294d5..4e86b6d8 100644 --- a/tests/y-text.tests.js +++ b/tests/y-text.tests.js @@ -1,4 +1,5 @@ import { init, compare } from './testHelper.js' + import * as t from 'lib0/testing.js' /** diff --git a/tests/y-xml.tests.js b/tests/y-xml.tests.js index ad25d757..476e80e8 100644 --- a/tests/y-xml.tests.js +++ b/tests/y-xml.tests.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' /**