From 3ddff186c2cb0e2afdf2fbb7696d056475bbd3ee Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Tue, 27 Nov 2018 14:59:12 +0100 Subject: [PATCH] back to .js extension --- .jsdoc.json | 2 +- bindings/dom.js | 1 + bindings/dom.mjs | 1 - .../dom/{DomBinding.mjs => DomBinding.js} | 16 +- .../dom/{domObserver.mjs => domObserver.js} | 11 +- bindings/dom/{domToType.mjs => domToType.js} | 13 +- bindings/dom/{filter.mjs => filter.js} | 18 +- bindings/dom/{selection.mjs => selection.js} | 12 +- .../dom/{typeObserver.mjs => typeObserver.js} | 6 +- bindings/dom/{util.mjs => util.js} | 10 +- bindings/{prosemirror.mjs => prosemirror.js} | 8 +- bindings/{quill.mjs => quill.js} | 3 +- bindings/{textarea.mjs => textarea.js} | 6 +- examples/dom.html | 6 +- examples/{dom.mjs => dom.js} | 6 +- examples/prosemirror.html | 2 +- examples/{prosemirror.mjs => prosemirror.js} | 4 +- examples/quill.html | 4 +- examples/{quill.mjs => quill.js} | 6 +- examples/textarea.html | 4 +- examples/{textarea.mjs => textarea.js} | 6 +- examples_all/ace/index.html | 2 +- examples_all/chat/index.html | 2 +- examples_all/codemirror/index.html | 2 +- examples_all/drawing/index.html | 2 +- .../html-editor-drawing-hook/index.html | 2 +- examples_all/html-editor/index.js | 16 +- examples_all/indexeddb/index.html | 2 +- examples_all/jigsaw/index.html | 2 +- examples_all/monaco/index.html | 2 +- examples_all/notes/index.js | 8 +- index.js | 50 ++ index.mjs | 50 -- ...dEventHandler.mjs => NamedEventHandler.js} | 0 lib/{Tree.mjs => Tree.js} | 0 lib/{binary.mjs => binary.js} | 0 lib/{decoding.mjs => decoding.js} | 2 +- lib/{diff.mjs => diff.js} | 0 lib/{encoding.mjs => encoding.js} | 2 +- lib/{encoding.test.mjs => encoding.test.js} | 2 +- lib/{globals.mjs => globals.js} | 0 lib/{idb.mjs => idb.js} | 4 +- lib/{idb.test.mjs => idb.test.js} | 6 +- lib/{logging.mjs => logging.js} | 2 +- lib/{math.mjs => math.js} | 0 lib/{mutex.mjs => mutex.js} | 0 lib/{number.mjs => number.js} | 0 lib/prng/PRNG/{Mt19937.mjs => Mt19937.js} | 0 .../PRNG/{PRNG.tests.mjs => PRNG.tests.js} | 8 +- ...roshiro128plus.mjs => Xoroshiro128plus.js} | 2 +- .../PRNG/{Xorshift32.mjs => Xorshift32.js} | 0 lib/prng/prng.js | 10 +- lib/prng/prng.mjs | 134 ----- lib/prng/{prng.test.mjs => prng.test.js} | 16 +- lib/{random.mjs => random.js} | 0 lib/{string.mjs => string.js} | 0 lib/{testing.mjs => testing.js} | 4 +- lib/{time.mjs => time.js} | 0 package-lock.json | 28 +- package.json | 5 +- ...FilePersistence.mjs => FilePersistence.js} | 8 +- persistences/IndexedDBPersistence.js | 553 ++++++++++++++++++ persistences/IndexedDBPersistence.mjs | 288 --------- ...decodePersisted.mjs => decodePersisted.js} | 6 +- persistences/indexeddb.js | 1 + ...enessProtocol.mjs => awarenessProtocol.js} | 6 +- .../{syncProtocol.mjs => syncProtocol.js} | 18 +- provider/websocket.js | 5 + provider/websocket.mjs | 5 - ...ocketProvider.mjs => WebSocketProvider.js} | 4 +- provider/websocket/{server.mjs => server.js} | 8 +- ...dEventHandler.mjs => NamedEventHandler.js} | 2 +- provider/ydb/{YdbClient.mjs => YdbClient.js} | 24 +- .../{YdbClient.test.mjs => YdbClient.test.js} | 10 +- ...oadcastchannel.mjs => broadcastchannel.js} | 8 +- .../ydb/{idbactions.mjs => idbactions.js} | 10 +- ...idbactions.test.mjs => idbactions.test.js} | 6 +- provider/ydb/{index.mjs => index.js} | 2 +- provider/ydb/{message.mjs => message.js} | 10 +- rollup.config.js | 14 +- structs/{Delete.mjs => Delete.js} | 18 +- structs/{GC.mjs => GC.js} | 12 +- structs/{Item.mjs => Item.js} | 18 +- structs/{ItemEmbed.mjs => ItemEmbed.js} | 10 +- structs/{ItemFormat.mjs => ItemFormat.js} | 10 +- structs/{ItemJSON.mjs => ItemJSON.js} | 10 +- structs/{ItemString.mjs => ItemString.js} | 10 +- structs/{Type.mjs => Type.js} | 10 +- ...teStore.tests.mjs => DeleteStore.tests.js} | 6 +- tests/{diff.tests.mjs => diff.tests.js} | 4 +- ...ecode.tests.mjs => encode-decode.tests.js} | 8 +- tests/{helper.mjs => helper.js} | 26 +- tests/index.js | 9 + tests/index.mjs | 9 - ...osemirror.test.mjs => prosemirror.test.js} | 6 +- .../{red-black-tree.mjs => red-black-tree.js} | 6 +- tests/{y-array.tests.mjs => y-array.tests.js} | 6 +- tests/{y-map.tests.mjs => y-map.tests.js} | 6 +- tests/{y-text.tests.mjs => y-text.tests.js} | 2 +- tests/{y-xml.tests.mjs => y-xml.tests.js} | 6 +- types/{YArray.mjs => YArray.js} | 14 +- types/{YMap.mjs => YMap.js} | 10 +- types/{YText.mjs => YText.js} | 10 +- types/{YXmlElement.mjs => YXmlElement.js} | 20 +- types/{YXmlEvent.mjs => YXmlEvent.js} | 6 +- types/{YXmlHook.mjs => YXmlHook.js} | 12 +- types/{YXmlText.mjs => YXmlText.js} | 8 +- .../{YXmlTreeWalker.mjs => YXmlTreeWalker.js} | 2 +- utils/{BindMapping.mjs => BindMapping.js} | 0 utils/{DeleteStore.mjs => DeleteStore.js} | 4 +- utils/{EventHandler.mjs => EventHandler.js} | 0 utils/{ID.mjs => ID.js} | 6 +- .../{OperationStore.mjs => OperationStore.js} | 10 +- utils/{StateStore.mjs => StateStore.js} | 2 +- utils/{Transaction.mjs => Transaction.js} | 10 +- utils/{UndoManager.mjs => UndoManager.js} | 4 +- utils/{Y.mjs => Y.js} | 24 +- utils/{YEvent.mjs => YEvent.js} | 2 +- ...emContent.mjs => defragmentItemContent.js} | 6 +- ...ndomUint32.mjs => generateRandomUint32.js} | 0 ...eStructs.mjs => integrateRemoteStructs.js} | 10 +- utils/{isParentOf.mjs => isParentOf.js} | 4 +- ...lativePosition.mjs => relativePosition.js} | 4 +- ...Manipulation.mjs => structManipulation.js} | 2 +- ...ructReferences.mjs => structReferences.js} | 0 125 files changed, 1015 insertions(+), 845 deletions(-) create mode 100644 bindings/dom.js delete mode 100644 bindings/dom.mjs rename bindings/dom/{DomBinding.mjs => DomBinding.js} (94%) rename bindings/dom/{domObserver.mjs => domObserver.js} (95%) rename bindings/dom/{domToType.mjs => domToType.js} (84%) rename bindings/dom/{filter.mjs => filter.js} (85%) rename bindings/dom/{selection.mjs => selection.js} (94%) rename bindings/dom/{typeObserver.mjs => typeObserver.js} (95%) rename bindings/dom/{util.mjs => util.js} (95%) rename bindings/{prosemirror.mjs => prosemirror.js} (97%) rename bindings/{quill.mjs => quill.js} (97%) rename bindings/{textarea.mjs => textarea.js} (94%) rename examples/{dom.mjs => dom.js} (69%) rename examples/{prosemirror.mjs => prosemirror.js} (89%) rename examples/{quill.mjs => quill.js} (82%) rename examples/{textarea.mjs => textarea.js} (68%) create mode 100644 index.js delete mode 100644 index.mjs rename lib/{NamedEventHandler.mjs => NamedEventHandler.js} (100%) rename lib/{Tree.mjs => Tree.js} (100%) rename lib/{binary.mjs => binary.js} (100%) rename lib/{decoding.mjs => decoding.js} (99%) rename lib/{diff.mjs => diff.js} (100%) rename lib/{encoding.mjs => encoding.js} (99%) rename lib/{encoding.test.mjs => encoding.test.js} (97%) rename lib/{globals.mjs => globals.js} (100%) rename lib/{idb.mjs => idb.js} (98%) rename lib/{idb.test.mjs => idb.test.js} (90%) rename lib/{logging.mjs => logging.js} (93%) rename lib/{math.mjs => math.js} (100%) rename lib/{mutex.mjs => mutex.js} (100%) rename lib/{number.mjs => number.js} (100%) rename lib/prng/PRNG/{Mt19937.mjs => Mt19937.js} (100%) rename lib/prng/PRNG/{PRNG.tests.mjs => PRNG.tests.js} (87%) rename lib/prng/PRNG/{Xoroshiro128plus.mjs => Xoroshiro128plus.js} (98%) rename lib/prng/PRNG/{Xorshift32.mjs => Xorshift32.js} (100%) delete mode 100644 lib/prng/prng.mjs rename lib/prng/{prng.test.mjs => prng.test.js} (88%) rename lib/{random.mjs => random.js} (100%) rename lib/{string.mjs => string.js} (100%) rename lib/{testing.mjs => testing.js} (92%) rename lib/{time.mjs => time.js} (100%) rename persistences/{FilePersistence.mjs => FilePersistence.js} (92%) create mode 100644 persistences/IndexedDBPersistence.js delete mode 100644 persistences/IndexedDBPersistence.mjs rename persistences/{decodePersisted.mjs => decodePersisted.js} (93%) create mode 100644 persistences/indexeddb.js rename protocols/{awarenessProtocol.mjs => awarenessProtocol.js} (94%) rename protocols/{syncProtocol.mjs => syncProtocol.js} (97%) create mode 100644 provider/websocket.js delete mode 100644 provider/websocket.mjs rename provider/websocket/{WebSocketProvider.mjs => WebSocketProvider.js} (97%) rename provider/websocket/{server.mjs => server.js} (96%) rename provider/ydb/{NamedEventHandler.mjs => NamedEventHandler.js} (91%) rename provider/ydb/{YdbClient.mjs => YdbClient.js} (92%) rename provider/ydb/{YdbClient.test.mjs => YdbClient.test.js} (92%) rename provider/ydb/{broadcastchannel.mjs => broadcastchannel.js} (97%) rename provider/ydb/{idbactions.mjs => idbactions.js} (98%) rename provider/ydb/{idbactions.test.mjs => idbactions.test.js} (86%) rename provider/ydb/{index.mjs => index.js} (78%) rename provider/ydb/{message.mjs => message.js} (94%) rename structs/{Delete.mjs => Delete.js} (83%) rename structs/{GC.mjs => GC.js} (88%) rename structs/{Item.mjs => Item.js} (97%) rename structs/{ItemEmbed.mjs => ItemEmbed.js} (79%) rename structs/{ItemFormat.mjs => ItemFormat.js} (82%) rename structs/{ItemJSON.mjs => ItemJSON.js} (87%) rename structs/{ItemString.mjs => ItemString.js} (82%) rename structs/{Type.mjs => Type.js} (96%) rename tests/{DeleteStore.tests.mjs => DeleteStore.tests.js} (94%) rename tests/{diff.tests.mjs => diff.tests.js} (92%) rename tests/{encode-decode.tests.mjs => encode-decode.tests.js} (94%) rename tests/{helper.mjs => helper.js} (95%) create mode 100644 tests/index.js delete mode 100644 tests/index.mjs rename tests/{prosemirror.test.mjs => prosemirror.test.js} (88%) rename tests/{red-black-tree.mjs => red-black-tree.js} (97%) rename tests/{y-array.tests.mjs => y-array.tests.js} (99%) rename tests/{y-map.tests.mjs => y-map.tests.js} (99%) rename tests/{y-text.tests.mjs => y-text.tests.js} (98%) rename tests/{y-xml.tests.mjs => y-xml.tests.js} (99%) rename types/{YArray.mjs => YArray.js} (96%) rename types/{YMap.mjs => YMap.js} (94%) rename types/{YText.mjs => YText.js} (98%) rename types/{YXmlElement.mjs => YXmlElement.js} (94%) rename types/{YXmlEvent.mjs => YXmlEvent.js} (87%) rename types/{YXmlHook.mjs => YXmlHook.js} (89%) rename types/{YXmlText.mjs => YXmlText.js} (87%) rename types/{YXmlTreeWalker.mjs => YXmlTreeWalker.js} (95%) rename utils/{BindMapping.mjs => BindMapping.js} (100%) rename utils/{DeleteStore.mjs => DeleteStore.js} (97%) rename utils/{EventHandler.mjs => EventHandler.js} (100%) rename utils/{ID.mjs => ID.js} (93%) rename utils/{OperationStore.mjs => OperationStore.js} (93%) rename utils/{StateStore.mjs => StateStore.js} (96%) rename utils/{Transaction.mjs => Transaction.js} (89%) rename utils/{UndoManager.mjs => UndoManager.js} (98%) rename utils/{Y.mjs => Y.js} (90%) rename utils/{YEvent.mjs => YEvent.js} (92%) rename utils/{defragmentItemContent.mjs => defragmentItemContent.js} (91%) rename utils/{generateRandomUint32.mjs => generateRandomUint32.js} (100%) rename utils/{integrateRemoteStructs.mjs => integrateRemoteStructs.js} (93%) rename utils/{isParentOf.mjs => isParentOf.js} (76%) rename utils/{relativePosition.mjs => relativePosition.js} (97%) rename utils/{structManipulation.mjs => structManipulation.js} (96%) rename utils/{structReferences.mjs => structReferences.js} (100%) diff --git a/.jsdoc.json b/.jsdoc.json index c987d659..c8ea1af5 100644 --- a/.jsdoc.json +++ b/.jsdoc.json @@ -5,7 +5,7 @@ "dictionaries": ["jsdoc"] }, "source": { - "include": ["./types", "./utils/UndoManager.mjs", "./utils/Y.mjs", "./provider", "./bindings"], + "include": ["./types", "./utils/UndoManager.js", "./utils/Y.js", "./provider", "./bindings"], "includePattern": ".js$" }, "plugins": [ diff --git a/bindings/dom.js b/bindings/dom.js new file mode 100644 index 00000000..4eb4d91f --- /dev/null +++ b/bindings/dom.js @@ -0,0 +1 @@ +export * from './dom/DomBinding.js' diff --git a/bindings/dom.mjs b/bindings/dom.mjs deleted file mode 100644 index d957a7ad..00000000 --- a/bindings/dom.mjs +++ /dev/null @@ -1 +0,0 @@ -export * from './dom/DomBinding.mjs' diff --git a/bindings/dom/DomBinding.mjs b/bindings/dom/DomBinding.js similarity index 94% rename from bindings/dom/DomBinding.mjs rename to bindings/dom/DomBinding.js index 6490595b..4c12cead 100644 --- a/bindings/dom/DomBinding.mjs +++ b/bindings/dom/DomBinding.js @@ -4,14 +4,14 @@ /* global MutationObserver, getSelection */ -import { fromRelativePosition } from '../../utils/relativePosition.mjs' -import { createMutex } from '../../lib/mutex.mjs' -import { createAssociation, removeAssociation } from './util.mjs' -import { beforeTransactionSelectionFixer, afterTransactionSelectionFixer, getCurrentRelativeSelection } from './selection.mjs' -import { defaultFilter, applyFilterOnType } from './filter.mjs' -import { typeObserver } from './typeObserver.mjs' -import { domObserver } from './domObserver.mjs' -import { YXmlFragment } from '../../types/YXmlElement.mjs' // eslint-disable-line +import { fromRelativePosition } from '../../utils/relativePosition.js' +import { createMutex } from '../../lib/mutex.js' +import { createAssociation, removeAssociation } from './util.js' +import { beforeTransactionSelectionFixer, afterTransactionSelectionFixer, getCurrentRelativeSelection } from './selection.js' +import { defaultFilter, applyFilterOnType } from './filter.js' +import { typeObserver } from './typeObserver.js' +import { domObserver } from './domObserver.js' +import { YXmlFragment } from '../../types/YXmlElement.js' // eslint-disable-line /** * @callback DomFilter diff --git a/bindings/dom/domObserver.mjs b/bindings/dom/domObserver.js similarity index 95% rename from bindings/dom/domObserver.mjs rename to bindings/dom/domObserver.js index ba3b3eb0..f0531256 100644 --- a/bindings/dom/domObserver.mjs +++ b/bindings/dom/domObserver.js @@ -2,13 +2,13 @@ * @module bindings/dom */ -import { YXmlHook } from '../../types/YXmlHook.mjs' +import { YXmlHook } from '../../types/YXmlHook.js' import { iterateUntilUndeleted, removeAssociation, - insertNodeHelper } from './util.mjs' -import { simpleDiff } from '../../lib/diff.mjs' -import { YXmlFragment } from '../../types/YXmlElement.mjs' + insertNodeHelper } from './util.js' +import { simpleDiff } from '../../lib/diff.js' +import { YXmlFragment } from '../../types/YXmlElement.js' /** * 1. Check if any of the nodes was deleted @@ -20,6 +20,8 @@ import { YXmlFragment } from '../../types/YXmlElement.mjs' * recreate a new yxml element that is bound to that node. * You can detect that a node was moved because expectedId * !== actualId in the list + * + * @function * @private */ const applyChangesFromDom = (binding, dom, yxml, _document) => { @@ -85,6 +87,7 @@ const applyChangesFromDom = (binding, dom, yxml, _document) => { /** * @private + * @function */ export function domObserver (mutations, _document) { this._mutualExclude(() => { diff --git a/bindings/dom/domToType.mjs b/bindings/dom/domToType.js similarity index 84% rename from bindings/dom/domToType.mjs rename to bindings/dom/domToType.js index 79955c9f..dbd03941 100644 --- a/bindings/dom/domToType.mjs +++ b/bindings/dom/domToType.js @@ -3,12 +3,12 @@ */ /* eslint-env browser */ -import { YXmlText } from '../../types/YXmlText.mjs' -import { YXmlHook } from '../../types/YXmlHook.mjs' -import { YXmlElement } from '../../types/YXmlElement.mjs' -import { createAssociation, domsToTypes } from './util.mjs' -import { filterDomAttributes, defaultFilter } from './filter.mjs' -import { DomBinding } from './DomBinding.mjs' // eslint-disable-line +import { YXmlText } from '../../types/YXmlText.js' +import { YXmlHook } from '../../types/YXmlHook.js' +import { YXmlElement } from '../../types/YXmlElement.js' +import { createAssociation, domsToTypes } from './util.js' +import { filterDomAttributes, defaultFilter } from './filter.js' +import { DomBinding } from './DomBinding.js' // eslint-disable-line /** * @callback DomFilter @@ -20,6 +20,7 @@ import { DomBinding } from './DomBinding.mjs' // eslint-disable-line /** * Creates a Yjs type (YXml) based on the contents of a DOM Element. * + * @function * @param {Element|Text} element The DOM Element * @param {?Document} _document Optional. Provide the global document object * @param {Object} [hooks = {}] Optional. Set of Yjs Hooks diff --git a/bindings/dom/filter.mjs b/bindings/dom/filter.js similarity index 85% rename from bindings/dom/filter.mjs rename to bindings/dom/filter.js index 124f2dbd..bd4c41ef 100644 --- a/bindings/dom/filter.mjs +++ b/bindings/dom/filter.js @@ -2,14 +2,15 @@ * @module bindings/dom */ -import { Y } from '../../utils/Y.mjs' // eslint-disable-line -import { YXmlElement, YXmlFragment } from '../../types/YXmlElement.mjs' // eslint-disable-line -import { isParentOf } from '../../utils/isParentOf.mjs' -import { DomBinding } from './DomBinding.mjs' // eslint-disable-line +import { Y } from '../../utils/Y.js' // eslint-disable-line +import { YXmlElement, YXmlFragment } from '../../types/YXmlElement.js' // eslint-disable-line +import { isParentOf } from '../../utils/isParentOf.js' +import { DomBinding } from './DomBinding.js' // eslint-disable-line /** * Default filter method (does nothing). * + * @function * @param {String} nodeName The nodeName of the element * @param {Map} attrs Map of key-value pairs that are attributes of the node. * @return {Map | null} The allowed attributes or null, if the element should be @@ -21,7 +22,10 @@ export const defaultFilter = (nodeName, attrs) => { } /** - * + * @private + * @function + * @param {Element} dom + * @param {Function} filter */ export const filterDomAttributes = (dom, filter) => { const attrs = new Map() @@ -35,11 +39,11 @@ export const filterDomAttributes = (dom, filter) => { /** * Applies a filter on a type. * + * @private + * @function * @param {Y} y The Yjs instance. * @param {DomBinding} binding The DOM binding instance that has the dom filter. * @param {YXmlElement | YXmlFragment } type The type to apply the filter to. - * - * @private */ export const applyFilterOnType = (y, binding, type) => { if (isParentOf(binding.type, type) && type instanceof YXmlElement) { diff --git a/bindings/dom/selection.mjs b/bindings/dom/selection.js similarity index 94% rename from bindings/dom/selection.mjs rename to bindings/dom/selection.js index c8ce7fcd..d541b205 100644 --- a/bindings/dom/selection.mjs +++ b/bindings/dom/selection.js @@ -4,10 +4,13 @@ /* globals getSelection */ -import { getRelativePosition } from '../../utils/relativePosition.mjs' +import { getRelativePosition } from '../../utils/relativePosition.js' let relativeSelection = null +/** + * @private + */ const _getCurrentRelativeSelection = domBinding => { const { baseNode, baseOffset, extentNode, extentOffset } = getSelection() const baseNodeType = domBinding.domToType.get(baseNode) @@ -21,8 +24,14 @@ const _getCurrentRelativeSelection = domBinding => { return null } +/** + * @private + */ export const getCurrentRelativeSelection = typeof getSelection !== 'undefined' ? _getCurrentRelativeSelection : domBinding => null +/** + * @private + */ export const beforeTransactionSelectionFixer = domBinding => { relativeSelection = getCurrentRelativeSelection(domBinding) } @@ -30,6 +39,7 @@ export const beforeTransactionSelectionFixer = domBinding => { /** * Reset the browser range after every transaction. * This prevents any collapsing issues with the local selection. + * * @private */ export const afterTransactionSelectionFixer = domBinding => { diff --git a/bindings/dom/typeObserver.mjs b/bindings/dom/typeObserver.js similarity index 95% rename from bindings/dom/typeObserver.mjs rename to bindings/dom/typeObserver.js index 6ce5e21e..5767a932 100644 --- a/bindings/dom/typeObserver.mjs +++ b/bindings/dom/typeObserver.js @@ -5,9 +5,9 @@ /* eslint-env browser */ /* global getSelection */ -import { YXmlText } from '../../types/YXmlText.mjs' -import { YXmlHook } from '../../types/YXmlHook.mjs' -import { removeDomChildrenUntilElementFound } from './util.mjs' +import { YXmlText } from '../../types/YXmlText.js' +import { YXmlHook } from '../../types/YXmlHook.js' +import { removeDomChildrenUntilElementFound } from './util.js' const findScrollReference = scrollingElement => { if (scrollingElement !== null) { diff --git a/bindings/dom/util.mjs b/bindings/dom/util.js similarity index 95% rename from bindings/dom/util.mjs rename to bindings/dom/util.js index 32f0d94d..04459a97 100644 --- a/bindings/dom/util.mjs +++ b/bindings/dom/util.js @@ -2,8 +2,8 @@ * @module bindings/dom */ -import { domToType } from './domToType.mjs' -import { DomBinding } from './DomBinding.mjs' // eslint-disable-line +import { domToType } from './domToType.js' +import { DomBinding } from './DomBinding.js' // eslint-disable-line /** * Iterates items until an undeleted item is found. @@ -22,6 +22,7 @@ export const iterateUntilUndeleted = item => { * type). * * @private + * @function * @param {DomBinding} domBinding The binding object * @param {Element} dom The dom that is to be associated with type * @param {YXmlElement|YXmlHook} type The type that is to be associated with dom @@ -37,6 +38,7 @@ export const removeAssociation = (domBinding, dom, type) => { * type). * * @private + * @function * @param {DomBinding} domBinding The binding object * @param {DocumentFragment|Element|Text} dom The dom that is to be associated with type * @param {YXmlFragment|YXmlElement|YXmlHook|YXmlText} type The type that is to be associated with dom @@ -54,6 +56,7 @@ export const createAssociation = (domBinding, dom, type) => { * forget about oldDom. If oldDom is not associated with any type, nothing happens. * * @private + * @function * @param {DomBinding} domBinding The binding object * @param {Element} oldDom The existing dom * @param {Element} newDom The new dom object @@ -74,6 +77,7 @@ export const switchAssociation = (domBinding, oldDom, newDom) => { * specified position. * * @private + * @function * @param {YXmlElement} type The type in which to insert DOM elements. * @param {YXmlElement|null} prev The reference node. New YxmlElements are * inserted after this node. Set null to insert at @@ -101,6 +105,7 @@ export const domsToTypes = (doms, _document, hooks, filter, binding) => { /** * @private + * @function */ export const insertNodeHelper = (yxml, prevExpectedNode, child, _document, binding) => { let insertedNodes = insertDomElementsAfter(yxml, prevExpectedNode, [child], _document, binding) @@ -115,6 +120,7 @@ export const insertNodeHelper = (yxml, prevExpectedNode, child, _document, bindi * Remove children until `elem` is found. * * @private + * @function * @param {Element} parent The parent of `elem` and `currentChild`. * @param {Node} currentChild Start removing elements with `currentChild`. If * `currentChild` is `elem` it won't be removed. diff --git a/bindings/prosemirror.mjs b/bindings/prosemirror.js similarity index 97% rename from bindings/prosemirror.mjs rename to bindings/prosemirror.js index c6bca5fa..4aa08725 100644 --- a/bindings/prosemirror.mjs +++ b/bindings/prosemirror.js @@ -2,10 +2,10 @@ * @module bindings/prosemirror */ -import { BindMapping } from '../utils/BindMapping.mjs' -import { YText } from '../types/YText.mjs' // eslint-disable-line -import { YXmlElement, YXmlFragment } from '../types/YXmlElement.mjs' // eslint-disable-line -import { createMutex } from '../lib/mutex.mjs' +import { BindMapping } from '../utils/BindMapping.js' +import { YText } from '../types/YText.js' // eslint-disable-line +import { YXmlElement, YXmlFragment } from '../types/YXmlElement.js' // eslint-disable-line +import { createMutex } from '../lib/mutex.js' import * as PModel from 'prosemirror-model' import { EditorView, Decoration, DecorationSet } from 'prosemirror-view' // eslint-disable-line import { Plugin, PluginKey, EditorState } from 'prosemirror-state' // eslint-disable-line diff --git a/bindings/quill.mjs b/bindings/quill.js similarity index 97% rename from bindings/quill.mjs rename to bindings/quill.js index 47410172..369adcf5 100644 --- a/bindings/quill.mjs +++ b/bindings/quill.js @@ -2,7 +2,7 @@ * @module bindings/quill */ -import { createMutex } from '../lib/mutex.mjs' +import { createMutex } from '../lib/mutex.js' const typeObserver = function (event) { const quill = this.target @@ -53,7 +53,6 @@ export class QuillBinding { * @private */ this._mutualExclude = createMutex() - // Set initial value. quill.setContents(textType.toDelta(), 'yjs') // Observers are handled by this class. diff --git a/bindings/textarea.mjs b/bindings/textarea.js similarity index 94% rename from bindings/textarea.mjs rename to bindings/textarea.js index c0fc50fe..73c4c087 100644 --- a/bindings/textarea.mjs +++ b/bindings/textarea.js @@ -2,9 +2,9 @@ * @module bindings/textarea */ -import { simpleDiff } from '../lib/diff.mjs' -import { getRelativePosition, fromRelativePosition } from '../utils/relativePosition.mjs' -import { createMutex } from '../lib/mutex.mjs' +import { simpleDiff } from '../lib/diff.js' +import { getRelativePosition, fromRelativePosition } from '../utils/relativePosition.js' +import { createMutex } from '../lib/mutex.js' function typeObserver () { this._mutualExclude(() => { diff --git a/examples/dom.html b/examples/dom.html index 370d38b4..570cbfcb 100644 --- a/examples/dom.html +++ b/examples/dom.html @@ -18,9 +18,9 @@
- + diff --git a/examples_all/chat/index.html b/examples_all/chat/index.html index df79fd54..228c7e75 100644 --- a/examples_all/chat/index.html +++ b/examples_all/chat/index.html @@ -13,7 +13,7 @@ - + diff --git a/examples_all/codemirror/index.html b/examples_all/codemirror/index.html index 0a172f13..2233240e 100644 --- a/examples_all/codemirror/index.html +++ b/examples_all/codemirror/index.html @@ -6,7 +6,7 @@
- + diff --git a/examples_all/drawing/index.html b/examples_all/drawing/index.html index 837da40a..a9dda2c8 100644 --- a/examples_all/drawing/index.html +++ b/examples_all/drawing/index.html @@ -13,7 +13,7 @@ - + diff --git a/examples_all/html-editor-drawing-hook/index.html b/examples_all/html-editor-drawing-hook/index.html index 291f6243..50166af5 100644 --- a/examples_all/html-editor-drawing-hook/index.html +++ b/examples_all/html-editor-drawing-hook/index.html @@ -2,7 +2,7 @@ - + - + diff --git a/examples_all/jigsaw/index.html b/examples_all/jigsaw/index.html index dd86e690..6030ca53 100644 --- a/examples_all/jigsaw/index.html +++ b/examples_all/jigsaw/index.html @@ -17,7 +17,7 @@ - + diff --git a/examples_all/monaco/index.html b/examples_all/monaco/index.html index 5a11c216..c4ef9e71 100644 --- a/examples_all/monaco/index.html +++ b/examples_all/monaco/index.html @@ -14,7 +14,7 @@ } - + diff --git a/examples_all/notes/index.js b/examples_all/notes/index.js index 56f19ffd..74f31c6e 100644 --- a/examples_all/notes/index.js +++ b/examples_all/notes/index.js @@ -1,9 +1,9 @@ /* eslint-env browser */ -import { createYdbClient } from '../../YdbClient/index.mjs' -import Y from '../../src/Y.dist.mjs' -import * as ydb from '../../YdbClient/YdbClient.mjs' -import DomBinding from '../../bindings/DomBinding/DomBinding.mjs' +import { createYdbClient } from '../../YdbClient/index.js' +import Y from '../../src/Y.dist.js' +import * as ydb from '../../YdbClient/YdbClient.js' +import DomBinding from '../../bindings/DomBinding/DomBinding.js' const uuidv4 = () => 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { const r = Math.random() * 16 | 0 diff --git a/index.js b/index.js new file mode 100644 index 00000000..b3248df2 --- /dev/null +++ b/index.js @@ -0,0 +1,50 @@ + +import { Delete } from './structs/Delete.js' +import { ItemJSON } from './structs/ItemJSON.js' +import { ItemString } from './structs/ItemString.js' +import { ItemFormat } from './structs/ItemFormat.js' +import { ItemEmbed } from './structs/ItemEmbed.js' +import { GC } from './structs/GC.js' + +import { YArray } from './types/YArray.js' +import { YMap } from './types/YMap.js' +import { YText } from './types/YText.js' +import { YXmlText } from './types/YXmlText.js' +import { YXmlHook } from './types/YXmlHook.js' +import { YXmlElement, YXmlFragment } from './types/YXmlElement.js' + +import { registerStruct } from './utils/structReferences.js' + +export { Y } from './utils/Y.js' +export { UndoManager } from './utils/UndoManager.js' +export { Transaction } from './utils/Transaction.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 { getRelativePosition, fromRelativePosition } from './utils/relativePosition.js' +export { registerStruct } from './utils/structReferences.js' +export * from './protocols/syncProtocol.js' +export * from './protocols/awarenessProtocol.js' +export * from './lib/encoding.js' +export * from './lib/decoding.js' +export * from './lib/mutex.js' + +registerStruct(0, GC) +registerStruct(1, ItemJSON) +registerStruct(2, ItemString) +registerStruct(3, ItemFormat) +registerStruct(4, Delete) + +registerStruct(5, YArray) +registerStruct(6, YMap) +registerStruct(7, YText) +registerStruct(8, YXmlFragment) +registerStruct(9, YXmlElement) +registerStruct(10, YXmlText) +registerStruct(11, YXmlHook) +registerStruct(12, ItemEmbed) diff --git a/index.mjs b/index.mjs deleted file mode 100644 index fefcc1e3..00000000 --- a/index.mjs +++ /dev/null @@ -1,50 +0,0 @@ - -import { Delete } from './structs/Delete.mjs' -import { ItemJSON } from './structs/ItemJSON.mjs' -import { ItemString } from './structs/ItemString.mjs' -import { ItemFormat } from './structs/ItemFormat.mjs' -import { ItemEmbed } from './structs/ItemEmbed.mjs' -import { GC } from './structs/GC.mjs' - -import { YArray } from './types/YArray.mjs' -import { YMap } from './types/YMap.mjs' -import { YText } from './types/YText.mjs' -import { YXmlText } from './types/YXmlText.mjs' -import { YXmlHook } from './types/YXmlHook.mjs' -import { YXmlElement, YXmlFragment } from './types/YXmlElement.mjs' - -import { registerStruct } from './utils/structReferences.mjs' - -export { Y } from './utils/Y.mjs' -export { UndoManager } from './utils/UndoManager.mjs' -export { Transaction } from './utils/Transaction.mjs' - -export { YArray as Array } from './types/YArray.mjs' -export { YMap as Map } from './types/YMap.mjs' -export { YText as Text } from './types/YText.mjs' -export { YXmlText as XmlText } from './types/YXmlText.mjs' -export { YXmlHook as XmlHook } from './types/YXmlHook.mjs' -export { YXmlElement as XmlElement, YXmlFragment as XmlFragment } from './types/YXmlElement.mjs' - -export { getRelativePosition, fromRelativePosition } from './utils/relativePosition.mjs' -export { registerStruct } from './utils/structReferences.mjs' -export * from './protocols/syncProtocol.mjs' -export * from './protocols/awarenessProtocol.mjs' -export * from './lib/encoding.mjs' -export * from './lib/decoding.mjs' -export * from './lib/mutex.mjs' - -registerStruct(0, GC) -registerStruct(1, ItemJSON) -registerStruct(2, ItemString) -registerStruct(3, ItemFormat) -registerStruct(4, Delete) - -registerStruct(5, YArray) -registerStruct(6, YMap) -registerStruct(7, YText) -registerStruct(8, YXmlFragment) -registerStruct(9, YXmlElement) -registerStruct(10, YXmlText) -registerStruct(11, YXmlHook) -registerStruct(12, ItemEmbed) diff --git a/lib/NamedEventHandler.mjs b/lib/NamedEventHandler.js similarity index 100% rename from lib/NamedEventHandler.mjs rename to lib/NamedEventHandler.js diff --git a/lib/Tree.mjs b/lib/Tree.js similarity index 100% rename from lib/Tree.mjs rename to lib/Tree.js diff --git a/lib/binary.mjs b/lib/binary.js similarity index 100% rename from lib/binary.mjs rename to lib/binary.js diff --git a/lib/decoding.mjs b/lib/decoding.js similarity index 99% rename from lib/decoding.mjs rename to lib/decoding.js index 0d9a47d3..384577cb 100644 --- a/lib/decoding.mjs +++ b/lib/decoding.js @@ -4,7 +4,7 @@ /* global Buffer */ -import * as globals from './globals.mjs' +import * as globals from './globals.js' /** * A Decoder handles the decoding of an ArrayBuffer. diff --git a/lib/diff.mjs b/lib/diff.js similarity index 100% rename from lib/diff.mjs rename to lib/diff.js diff --git a/lib/encoding.mjs b/lib/encoding.js similarity index 99% rename from lib/encoding.mjs rename to lib/encoding.js index 758ac881..5de8d260 100644 --- a/lib/encoding.mjs +++ b/lib/encoding.js @@ -1,7 +1,7 @@ /** * @module encoding */ -import * as globals from './globals.mjs' +import * as globals from './globals.js' const bits7 = 0b1111111 const bits8 = 0b11111111 diff --git a/lib/encoding.test.mjs b/lib/encoding.test.js similarity index 97% rename from lib/encoding.test.mjs rename to lib/encoding.test.js index b74a4163..b957707b 100644 --- a/lib/encoding.test.mjs +++ b/lib/encoding.test.js @@ -1,4 +1,4 @@ -import * as encoding from './encoding.mjs' +import * as encoding from './encoding.js' /** * Check if binary encoding is compatible with golang binary encoding - binary.PutVarUint. diff --git a/lib/globals.mjs b/lib/globals.js similarity index 100% rename from lib/globals.mjs rename to lib/globals.js diff --git a/lib/idb.mjs b/lib/idb.js similarity index 98% rename from lib/idb.mjs rename to lib/idb.js index 95e839f9..d1a1cc4f 100644 --- a/lib/idb.mjs +++ b/lib/idb.js @@ -1,10 +1,10 @@ /** - * @module idb + * @module lib/idb */ /* eslint-env browser */ -import * as globals from './globals.mjs' +import * as globals from './globals.js' /* * IDB Request to Promise transformer diff --git a/lib/idb.test.mjs b/lib/idb.test.js similarity index 90% rename from lib/idb.test.mjs rename to lib/idb.test.js index 6f2b9af3..e96a1352 100644 --- a/lib/idb.test.mjs +++ b/lib/idb.test.js @@ -1,6 +1,6 @@ -import * as test from './testing.mjs' -import * as idb from './idb.mjs' -import * as logging from './logging.mjs' +import * as test from './testing.js' +import * as idb from './idb.js' +import * as logging from './logging.js' const initTestDB = db => idb.createStores(db, [['test']]) const testDBName = 'idb-test' diff --git a/lib/logging.mjs b/lib/logging.js similarity index 93% rename from lib/logging.mjs rename to lib/logging.js index f6c56ca0..6af7e49b 100644 --- a/lib/logging.mjs +++ b/lib/logging.js @@ -2,7 +2,7 @@ * @module logging */ -import * as globals from './globals.mjs' +import * as globals from './globals.js' let date = new Date().getTime() diff --git a/lib/math.mjs b/lib/math.js similarity index 100% rename from lib/math.mjs rename to lib/math.js diff --git a/lib/mutex.mjs b/lib/mutex.js similarity index 100% rename from lib/mutex.mjs rename to lib/mutex.js diff --git a/lib/number.mjs b/lib/number.js similarity index 100% rename from lib/number.mjs rename to lib/number.js diff --git a/lib/prng/PRNG/Mt19937.mjs b/lib/prng/PRNG/Mt19937.js similarity index 100% rename from lib/prng/PRNG/Mt19937.mjs rename to lib/prng/PRNG/Mt19937.js diff --git a/lib/prng/PRNG/PRNG.tests.mjs b/lib/prng/PRNG/PRNG.tests.js similarity index 87% rename from lib/prng/PRNG/PRNG.tests.mjs rename to lib/prng/PRNG/PRNG.tests.js index c680c347..f524edd3 100644 --- a/lib/prng/PRNG/PRNG.tests.mjs +++ b/lib/prng/PRNG/PRNG.tests.js @@ -2,10 +2,10 @@ * @module prng */ -import { Mt19937 } from './Mt19937.mjs' -import { Xoroshiro128plus } from './Xoroshiro128plus.mjs' -import { Xorshift32 } from './Xorshift32.mjs' -import * as time from '../../time.mjs' +import { Mt19937 } from './Mt19937.js' +import { Xoroshiro128plus } from './Xoroshiro128plus.js' +import { Xorshift32 } from './Xorshift32.js' +import * as time from '../../time.js' const DIAMETER = 300 const NUMBERS = 10000 diff --git a/lib/prng/PRNG/Xoroshiro128plus.mjs b/lib/prng/PRNG/Xoroshiro128plus.js similarity index 98% rename from lib/prng/PRNG/Xoroshiro128plus.mjs rename to lib/prng/PRNG/Xoroshiro128plus.js index ceea0169..13b97156 100644 --- a/lib/prng/PRNG/Xoroshiro128plus.mjs +++ b/lib/prng/PRNG/Xoroshiro128plus.js @@ -2,7 +2,7 @@ * @module prng */ -import { Xorshift32 } from './Xorshift32.mjs' +import { Xorshift32 } from './Xorshift32.js' /** * This is a variant of xoroshiro128plus - the fastest full-period generator passing BigCrush without systematic failures. diff --git a/lib/prng/PRNG/Xorshift32.mjs b/lib/prng/PRNG/Xorshift32.js similarity index 100% rename from lib/prng/PRNG/Xorshift32.mjs rename to lib/prng/PRNG/Xorshift32.js diff --git a/lib/prng/prng.js b/lib/prng/prng.js index c9c2e33b..ae9e898e 100644 --- a/lib/prng/prng.js +++ b/lib/prng/prng.js @@ -2,12 +2,12 @@ * @module prng */ -import * as binary from '../binary.mjs' -import { fromCharCode, fromCodePoint } from '../string.mjs' -import { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } from '../number.mjs' -import * as math from '../math.mjs' +import * as binary from '../binary.js' +import { fromCharCode, fromCodePoint } from '../string.js' +import { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } from '../number.js' +import * as math from '../math.js' -import { Xoroshiro128plus as DefaultPRNG } from './PRNG/Xoroshiro128plus.mjs' +import { Xoroshiro128plus as DefaultPRNG } from './PRNG/Xoroshiro128plus.js' /** * Description of the function diff --git a/lib/prng/prng.mjs b/lib/prng/prng.mjs deleted file mode 100644 index c9c2e33b..00000000 --- a/lib/prng/prng.mjs +++ /dev/null @@ -1,134 +0,0 @@ -/** - * @module prng - */ - -import * as binary from '../binary.mjs' -import { fromCharCode, fromCodePoint } from '../string.mjs' -import { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } from '../number.mjs' -import * as math from '../math.mjs' - -import { Xoroshiro128plus as DefaultPRNG } from './PRNG/Xoroshiro128plus.mjs' - -/** - * Description of the function - * @callback generatorNext - * @return {number} A 32bit integer - */ - -/** - * A random type generator. - * - * @typedef {Object} PRNG - * @property {generatorNext} next Generate new number - */ - -/** - * Create a Xoroshiro128plus Pseudo-Random-Number-Generator. - * This is the fastest full-period generator passing BigCrush without systematic failures. - * But there are more PRNGs available in ./PRNG/. - * - * @param {number} seed A positive 32bit integer. Do not use negative numbers. - * @return {PRNG} - */ -export const createPRNG = seed => new DefaultPRNG(Math.floor(seed < 1 ? seed * binary.BITS32 : seed)) - -/** - * Generates a single random bool. - * - * @param {PRNG} gen A random number generator. - * @return {Boolean} A random boolean - */ -export const bool = gen => (gen.next() & 2) === 2 // brackets are non-optional! - -/** - * Generates a random integer with 53 bit resolution. - * - * @param {PRNG} gen A random number generator. - * @param {Number} [min = MIN_SAFE_INTEGER] The lower bound of the allowed return values (inclusive). - * @param {Number} [max = MAX_SAFE_INTEGER] The upper bound of the allowed return values (inclusive). - * @return {Number} A random integer on [min, max] - */ -export const int53 = (gen, min = MIN_SAFE_INTEGER, max = MAX_SAFE_INTEGER) => math.floor(real53(gen) * (max + 1 - min) + min) - -/** - * Generates a random integer with 32 bit resolution. - * - * @param {PRNG} gen A random number generator. - * @param {Number} [min = MIN_SAFE_INTEGER] The lower bound of the allowed return values (inclusive). - * @param {Number} [max = MAX_SAFE_INTEGER] The upper bound of the allowed return values (inclusive). - * @return {Number} A random integer on [min, max] - */ -export const int32 = (gen, min = MIN_SAFE_INTEGER, max = MAX_SAFE_INTEGER) => min + ((gen.next() >>> 0) % (max + 1 - min)) - -/** - * Generates a random real on [0, 1) with 32 bit resolution. - * - * @param {PRNG} gen A random number generator. - * @return {Number} A random real number on [0, 1). - */ -export const real32 = gen => (gen.next() >>> 0) / binary.BITS32 - -/** - * Generates a random real on [0, 1) with 53 bit resolution. - * - * @param {PRNG} gen A random number generator. - * @return {Number} A random real number on [0, 1). - */ -export const real53 = gen => (((gen.next() >>> 5) * binary.BIT26) + (gen.next() >>> 6)) / MAX_SAFE_INTEGER - -/** - * Generates a random character from char code 32 - 126. I.e. Characters, Numbers, special characters, and Space: - * - * (Space)!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[/]^_`abcdefghijklmnopqrstuvwxyz{|}~ - */ -export const char = gen => fromCharCode(int32(gen, 32, 126)) - -/** - * @param {PRNG} gen - * @return {string} A single letter (a-z) - */ -export const letter = gen => fromCharCode(int32(gen, 97, 122)) - -/** - * @param {PRNG} gen - * @return {string} A random word without spaces consisting of letters (a-z) - */ -export const word = gen => { - const len = int32(gen, 0, 20) - let str = '' - for (let i = 0; i < len; i++) { - str += letter(gen) - } - return str -} - -/** - * TODO: this function produces invalid runes. Does not cover all of utf16!! - */ -export const utf16Rune = gen => { - const codepoint = int32(gen, 0, 256) - return fromCodePoint(codepoint) -} - -/** - * @param {PRNG} gen - * @param {number} [maxlen = 20] - */ -export const utf16String = (gen, maxlen = 20) => { - const len = int32(gen, 0, maxlen) - let str = '' - for (let i = 0; i < len; i++) { - str += utf16Rune(gen) - } - return str -} - -/** - * Returns one element of a given array. - * - * @param {PRNG} gen A random number generator. - * @param {Array} array Non empty Array of possible values. - * @return {T} One of the values of the supplied Array. - * @template T - */ -export const oneOf = (gen, array) => array[int32(gen, 0, array.length - 1)] diff --git a/lib/prng/prng.test.mjs b/lib/prng/prng.test.js similarity index 88% rename from lib/prng/prng.test.mjs rename to lib/prng/prng.test.js index d56e0b49..f6917f06 100644 --- a/lib/prng/prng.test.mjs +++ b/lib/prng/prng.test.js @@ -4,14 +4,14 @@ /** *TODO: enable tests -import * as rt from '../rich-text/formatters.mjs'' -import { test } from '../test/test.mjs'' -import Xoroshiro128plus from './PRNG/Xoroshiro128plus.mjs'' -import Xorshift32 from './PRNG/Xorshift32.mjs'' -import MT19937 from './PRNG/Mt19937.mjs'' -import { generateBool, generateInt, generateInt32, generateReal, generateChar } from './random.mjs'' -import { MAX_SAFE_INTEGER } from '../number/constants.mjs'' -import { BIT32 } from '../binary/constants.mjs'' +import * as rt from '../rich-text/formatters.js'' +import { test } from '../test/test.js'' +import Xoroshiro128plus from './PRNG/Xoroshiro128plus.js'' +import Xorshift32 from './PRNG/Xorshift32.js'' +import MT19937 from './PRNG/Mt19937.js'' +import { generateBool, generateInt, generateInt32, generateReal, generateChar } from './random.js'' +import { MAX_SAFE_INTEGER } from '../number/constants.js'' +import { BIT32 } from '../binary/constants.js'' function init (Gen) { return { diff --git a/lib/random.mjs b/lib/random.js similarity index 100% rename from lib/random.mjs rename to lib/random.js diff --git a/lib/string.mjs b/lib/string.js similarity index 100% rename from lib/string.mjs rename to lib/string.js diff --git a/lib/testing.mjs b/lib/testing.js similarity index 92% rename from lib/testing.mjs rename to lib/testing.js index 72da7864..43c85a2a 100644 --- a/lib/testing.mjs +++ b/lib/testing.js @@ -2,8 +2,8 @@ * @module testing */ -import * as logging from './logging.mjs' -import { simpleDiff } from './diff.mjs' +import * as logging from './logging.js' +import { simpleDiff } from './diff.js' export const run = async (name, f) => { console.log(`%cStart:%c ${name}`, 'color:blue;', '') diff --git a/lib/time.mjs b/lib/time.js similarity index 100% rename from lib/time.mjs rename to lib/time.js diff --git a/package-lock.json b/package-lock.json index d6229122..f04aa8b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3413,12 +3413,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3433,17 +3435,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -3560,7 +3565,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -3572,6 +3578,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3586,6 +3593,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3593,12 +3601,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -3617,6 +3627,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -3697,7 +3708,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -3709,6 +3721,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -3830,6 +3843,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/package.json b/package.json index 3d460297..45b69a7b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "name": "yjs", "version": "13.0.0-73", "description": "A ", - "module": "./index.mjs'", + "main": "./build/yjs.js", + "module": "./index.js'", "sideEffects": false, "scripts": { "test": "npm run lint", @@ -13,7 +14,7 @@ "docs": "rm -rf docs; jsdoc --configure ./.jsdoc.json --verbose --readme ./README.v13.md --package ./package.json || true", "serve-docs": "npm run docs && serve ./docs/", "postversion": "npm run build", - "websocket-server": "node --experimental-modules ./provider/websocket/server.mjs", + "websocket-server": "node ./provider/websocket/server.js", "now-start": "npm run websocket-server" }, "files": [ diff --git a/persistences/FilePersistence.mjs b/persistences/FilePersistence.js similarity index 92% rename from persistences/FilePersistence.mjs rename to persistences/FilePersistence.js index f08a61bf..0c22ed43 100644 --- a/persistences/FilePersistence.mjs +++ b/persistences/FilePersistence.js @@ -1,10 +1,10 @@ /* import fs from 'fs' import path from 'path' -import * as encoding from '../lib/encoding.mjs' -import * as decoding from '../lib/decoding.mjs' -import { createMutex } from '../lib/mutex.mjs' -import { encodeUpdate, encodeStructsDS, decodePersisted } from './decodePersisted.mjs' +import * as encoding from '../lib/encoding.js' +import * as decoding from '../lib/decoding.js' +import { createMutex } from '../lib/mutex.js' +import { encodeUpdate, encodeStructsDS, decodePersisted } from './decodePersisted.js' function createFilePath (persistence, roomName) { // TODO: filename checking! diff --git a/persistences/IndexedDBPersistence.js b/persistences/IndexedDBPersistence.js new file mode 100644 index 00000000..6c4cc950 --- /dev/null +++ b/persistences/IndexedDBPersistence.js @@ -0,0 +1,553 @@ +/* +import { Y } from '../utils/Y.js' +import { createMutex } from '../lib/mutex.js' +import { decodePersisted, encodeStructsDS, encodeUpdate, PERSIST_STRUCTS_DS, PERSIST_UPDATE } from './decodePersisted.js' + +function rtop (request) { + return new Promise(function (resolve, reject) { + request.onerror = function (event) { + reject(new Error(event.target.error)) + } + request.onblocked = function () { + location.reload() + } + request.onsuccess = function (event) { + resolve(event.target.result) + } + }) +} + +function openDB (room) { + return new Promise(function (resolve, reject) { + let request = indexedDB.open(room) + request.onupgradeneeded = function (event) { + const db = event.target.result + if (db.objectStoreNames.contains('updates')) { + db.deleteObjectStore('updates') + } + db.createObjectStore('updates', {autoIncrement: true}) + } + request.onerror = function (event) { + reject(new Error(event.target.error)) + } + request.onblocked = function () { + location.reload() + } + request.onsuccess = function (event) { + const db = event.target.result + db.onversionchange = function () { db.close() } + resolve(db) + } + }) +} + +function persist (room) { + let t = room.db.transaction(['updates'], 'readwrite') + let updatesStore = t.objectStore('updates') + return rtop(updatesStore.getAll()) + .then(updates => { + // apply all previous updates before deleting them + room.mutex(() => { + updates.forEach(update => { + decodePersisted(y, new BinaryDecoder(update)) + }) + }) + const encoder = new BinaryEncoder() + encodeStructsDS(y, encoder) + // delete all pending updates + rtop(updatesStore.clear()).then(() => { + // write current model + updatesStore.put(encoder.createBuffer()) + }) + }) +} + +function saveUpdate (room, updateBuffer) { + const db = room.db + if (db !== null) { + const t = db.transaction(['updates'], 'readwrite') + const updatesStore = t.objectStore('updates') + const updatePut = rtop(updatesStore.put(updateBuffer)) + rtop(updatesStore.count()).then(cnt => { + if (cnt >= PREFERRED_TRIM_SIZE) { + persist(room) + } + }) + return updatePut + } +} + +function registerRoomInPersistence (documentsDB, roomName) { + return documentsDB.then( + db => Promise.all([ + db, + rtop(db.transaction(['documents'], 'readonly').objectStore('documents').get(roomName)) + ]) + ).then( + ([db, doc]) => { + if (doc === undefined) { + return rtop(db.transaction(['documents'], 'readwrite').objectStore('documents').add({ roomName, serverUpdateCounter: 0 })) + } + } + ) +} + +const PREFERRED_TRIM_SIZE = 400 + +export class IndexedDBPersistence { + constructor () { + this._rooms = new Map() + this._documentsDB = new Promise(function (resolve, reject) { + let request = indexedDB.open('_yjs_documents') + request.onupgradeneeded = function (event) { + const db = event.target.result + if (db.objectStoreNames.contains('documents')) { + db.deleteObjectStore('documents') + } + db.createObjectStore('documents', { keyPath: "roomName" }) + } + request.onerror = function (event) { + reject(new Error(event.target.error)) + } + request.onblocked = function () { + location.reload() + } + request.onsuccess = function (event) { + const db = event.target.result + db.onversionchange = function () { db.close() } + resolve(db) + } + }) + addEventListener('unload', () => { + // close everything when page unloads + this._rooms.forEach(room => { + if (room.db !== null) { + room.db.close() + } else { + room.dbPromise.then(db => db.close()) + } + }) + this._documentsDB.then(db => db.close()) + }) + } + getAllDocuments () { + return this._documentsDB.then( + db => rtop(db.transaction(['documents'], 'readonly').objectStore('documents').getAll()) + ) + } + setRemoteUpdateCounter (roomName, remoteUpdateCounter) { + this._documentsDB.then( + db => rtop(db.transaction(['documents'], 'readwrite').objectStore('documents').put({ roomName, remoteUpdateCounter })) + ) + } + + _createYInstance (roomName) { + const room = this._rooms.get(roomName) + if (room !== undefined) { + return room.y + } + const y = new Y() + return openDB(roomName).then( + db => rtop(db.transaction(['updates'], 'readonly').objectStore('updates').getAll()) + ).then( + updates => + y.transact(() => { + updates.forEach(update => { + decodePersisted(y, new BinaryDecoder(update)) + }) + }, true) + ).then(() => Promise.resolve(y)) + } + + _persistStructsDS (roomName, structsDS) { + const encoder = new BinaryEncoder() + encoder.writeVarUint(PERSIST_STRUCTS_DS) + encoder.writeArrayBuffer(structsDS) + return openDB(roomName).then(db => { + const t = db.transaction(['updates'], 'readwrite') + const updatesStore = t.objectStore('updates') + return rtop(updatesStore.put(encoder.createBuffer())) + }) + } + + _persistStructs (roomName, structs) { + const encoder = new BinaryEncoder() + encoder.writeVarUint(PERSIST_UPDATE) + encoder.writeArrayBuffer(structs) + return openDB(roomName).then(db => { + const t = db.transaction(['updates'], 'readwrite') + const updatesStore = t.objectStore('updates') + return rtop(updatesStore.put(encoder.createBuffer())) + }) + } + + connectY (roomName, y) { + if (this._rooms.has(roomName)) { + throw new Error('A Y instance is already bound to this room!') + } + let room = { + db: null, + dbPromise: null, + channel: null, + mutex: createMutex(), + y + } + if (typeof BroadcastChannel !== 'undefined') { + room.channel = new BroadcastChannel('__yjs__' + roomName) + room.channel.addEventListener('message', e => { + room.mutex(function () { + decodePersisted(y, new BinaryDecoder(e.data)) + }) + }) + } + y.on('destroyed', () => { + this.disconnectY(roomName, y) + }) + y.on('afterTransaction', (y, transaction) => { + room.mutex(() => { + if (transaction.encodedStructsLen > 0) { + const encoder = new BinaryEncoder() + const update = new BinaryEncoder() + encodeUpdate(y, transaction.encodedStructs, update) + const updateBuffer = update.createBuffer() + if (room.channel !== null) { + room.channel.postMessage(updateBuffer) + } + if (transaction.encodedStructsLen > 0 + import { Y } from '../utils/Y.js' + import { createMutex } from '../lib/mutex.js' + import { decodePersisted, encodeStructsDS, encodeUpdate, PERSIST_STRUCTS_DS, PERSIST_UPDATE } from './decodePersisted.js' + + function rtop (request) { + return new Promise(function (resolve, reject) { + request.onerror = function (event) { + reject(new Error(event.target.error)) + } + request.onblocked = function () { + location.reload() + } + request.onsuccess = function (event) { + resolve(event.target.result) + } + }) + } + + function openDB (room) { + return new Promise(function (resolve, reject) { + let request = indexedDB.open(room) + request.onupgradeneeded = function (event) { + const db = event.target.result + if (db.objectStoreNames.contains('updates')) { + db.deleteObjectStore('updates') + } + db.createObjectStore('updates', {autoIncrement: true}) + } + request.onerror = function (event) { + reject(new Error(event.target.error)) + } + request.onblocked = function () { + location.reload() + } + request.onsuccess = function (event) { + const db = event.target.result + db.onversionchange = function () { db.close() } + resolve(db) + } + }) + } + + function persist (room) { + let t = room.db.transaction(['updates'], 'readwrite') + let updatesStore = t.objectStore('updates') + return rtop(updatesStore.getAll()) + .then(updates => { + // apply all previous updates before deleting them + room.mutex(() => { + updates.forEach(update => { + decodePersisted(y, new BinaryDecoder(update)) + }) + }) + const encoder = new BinaryEncoder() + encodeStructsDS(y, encoder) + // delete all pending updates + rtop(updatesStore.clear()).then(() => { + // write current model + updatesStore.put(encoder.createBuffer()) + }) + }) + } + + function saveUpdate (room, updateBuffer) { + const db = room.db + if (db !== null) { + const t = db.transaction(['updates'], 'readwrite') + const updatesStore = t.objectStore('updates') + const updatePut = rtop(updatesStore.put(updateBuffer)) + rtop(updatesStore.count()).then(cnt => { + if (cnt >= PREFERRED_TRIM_SIZE) { + persist(room) + } + }) + return updatePut + } + } + + function registerRoomInPersistence (documentsDB, roomName) { + return documentsDB.then( + db => Promise.all([ + db, + rtop(db.transaction(['documents'], 'readonly').objectStore('documents').get(roomName)) + ]) + ).then( + ([db, doc]) => { + if (doc === undefined) { + return rtop(db.transaction(['documents'], 'readwrite').objectStore('documents').add({ roomName, serverUpdateCounter: 0 })) + } + } + ) + } + + const PREFERRED_TRIM_SIZE = 400 + + export class IndexedDBPersistence { + constructor () { + this._rooms = new Map() + this._documentsDB = new Promise(function (resolve, reject) { + let request = indexedDB.open('_yjs_documents') + request.onupgradeneeded = function (event) { + const db = event.target.result + if (db.objectStoreNames.contains('documents')) { + db.deleteObjectStore('documents') + } + db.createObjectStore('documents', { keyPath: "roomName" }) + } + request.onerror = function (event) { + reject(new Error(event.target.error)) + } + request.onblocked = function () { + location.reload() + } + request.onsuccess = function (event) { + const db = event.target.result + db.onversionchange = function () { db.close() } + resolve(db) + } + }) + addEventListener('unload', () => { + // close everything when page unloads + this._rooms.forEach(room => { + if (room.db !== null) { + room.db.close() + } else { + room.dbPromise.then(db => db.close()) + } + }) + this._documentsDB.then(db => db.close()) + }) + } + getAllDocuments () { + return this._documentsDB.then( + db => rtop(db.transaction(['documents'], 'readonly').objectStore('documents').getAll()) + ) + } + setRemoteUpdateCounter (roomName, remoteUpdateCounter) { + this._documentsDB.then( + db => rtop(db.transaction(['documents'], 'readwrite').objectStore('documents').put({ roomName, remoteUpdateCounter })) + ) + } + + _createYInstance (roomName) { + const room = this._rooms.get(roomName) + if (room !== undefined) { + return room.y + } + const y = new Y() + return openDB(roomName).then( + db => rtop(db.transaction(['updates'], 'readonly').objectStore('updates').getAll()) + ).then( + updates => + y.transact(() => { + updates.forEach(update => { + decodePersisted(y, new BinaryDecoder(update)) + }) + }, true) + ).then(() => Promise.resolve(y)) + } + + _persistStructsDS (roomName, structsDS) { + const encoder = new BinaryEncoder() + encoder.writeVarUint(PERSIST_STRUCTS_DS) + encoder.writeArrayBuffer(structsDS) + return openDB(roomName).then(db => { + const t = db.transaction(['updates'], 'readwrite') + const updatesStore = t.objectStore('updates') + return rtop(updatesStore.put(encoder.createBuffer())) + }) + } + + _persistStructs (roomName, structs) { + const encoder = new BinaryEncoder() + encoder.writeVarUint(PERSIST_UPDATE) + encoder.writeArrayBuffer(structs) + return openDB(roomName).then(db => { + const t = db.transaction(['updates'], 'readwrite') + const updatesStore = t.objectStore('updates') + return rtop(updatesStore.put(encoder.createBuffer())) + }) + } + + connectY (roomName, y) { + if (this._rooms.has(roomName)) { + throw new Error('A Y instance is already bound to this room!') + } + let room = { + db: null, + dbPromise: null, + channel: null, + mutex: createMutex(), + y + } + if (typeof BroadcastChannel !== 'undefined') { + room.channel = new BroadcastChannel('__yjs__' + roomName) + room.channel.addEventListener('message', e => { + room.mutex(function () { + decodePersisted(y, new BinaryDecoder(e.data)) + }) + }) + } + y.on('destroyed', () => { + this.disconnectY(roomName, y) + }) + y.on('afterTransaction', (y, transaction) => { + room.mutex(() => { + if (transaction.encodedStructsLen > 0) { + const encoder = new BinaryEncoder() + const update = new BinaryEncoder() + encodeUpdate(y, transaction.encodedStructs, update) + const updateBuffer = update.createBuffer() + if (room.channel !== null) { + room.channel.postMessage(updateBuffer) + } + if (transaction.encodedStructsLen > 0) { + if (room.db !== null) { + saveUpdate(room, updateBuffer) + } + } + } + }) + }) + // register document in documentsDB + this._documentsDB.then( + db => + rtop(db.transaction(['documents'], 'readonly').objectStore('documents').get(roomName)) + .then( + doc => doc === undefined && rtop(db.transaction(['documents'], 'readwrite').objectStore('documents').add({ roomName, serverUpdateCounter: -1 })) + ) + ) + // open room db and read existing data + return room.dbPromise = openDB(roomName) + .then(db => { + room.db = db + const t = room.db.transaction(['updates'], 'readwrite') + const updatesStore = t.objectStore('updates') + // write current state as update + const encoder = new BinaryEncoder() + encodeStructsDS(y, encoder) + return rtop(updatesStore.put(encoder.createBuffer())).then(() => { + // read persisted state + return rtop(updatesStore.getAll()).then(updates => { + room.mutex(() => { + y.transact(() => { + updates.forEach(update => { + decodePersisted(y, new BinaryDecoder(update)) + }) + }, true) + }) + }) + }) + }) + } + disconnectY (roomName) { + const { + db, channel + } = this._rooms.get(roomName) + db.close() + if (channel !== null) { + channel.close() + } + this._rooms.delete(roomName) + } + + /** + * Remove all persisted data that belongs to a room. + * Automatically destroys all Yjs all Yjs instances that persist to + * the room. If `destroyYjsInstances = false` the persistence functionality + * will be removed from the Yjs instances. + * + removePersistedData (roomName, destroyYjsInstances = true) { + this.disconnectY(roomName) + return rtop(indexedDB.deleteDatabase(roomName)) + } + } + { + if (room.db !== null) { + saveUpdate(room, updateBuffer) + } + } + } + }) + }) + // register document in documentsDB + this._documentsDB.then( + db => + rtop(db.transaction(['documents'], 'readonly').objectStore('documents').get(roomName)) + .then( + doc => doc === undefined && rtop(db.transaction(['documents'], 'readwrite').objectStore('documents').add({ roomName, serverUpdateCounter: -1 })) + ) + ) + // open room db and read existing data + return room.dbPromise = openDB(roomName) + .then(db => { + room.db = db + const t = room.db.transaction(['updates'], 'readwrite') + const updatesStore = t.objectStore('updates') + // write current state as update + const encoder = new BinaryEncoder() + encodeStructsDS(y, encoder) + return rtop(updatesStore.put(encoder.createBuffer())).then(() => { + // read persisted state + return rtop(updatesStore.getAll()).then(updates => { + room.mutex(() => { + y.transact(() => { + updates.forEach(update => { + decodePersisted(y, new BinaryDecoder(update)) + }) + }, true) + }) + }) + }) + }) + } + disconnectY (roomName) { + const { + db, channel + } = this._rooms.get(roomName) + db.close() + if (channel !== null) { + channel.close() + } + this._rooms.delete(roomName) + } + + /** + * Remove all persisted data that belongs to a room. + * Automatically destroys all Yjs all Yjs instances that persist to + * the room. If `destroyYjsInstances = false` the persistence functionality + * will be removed from the Yjs instances. + * + removePersistedData (roomName, destroyYjsInstances = true) { + this.disconnectY(roomName) + return rtop(indexedDB.deleteDatabase(roomName)) + } +} +*/ diff --git a/persistences/IndexedDBPersistence.mjs b/persistences/IndexedDBPersistence.mjs deleted file mode 100644 index b804211b..00000000 --- a/persistences/IndexedDBPersistence.mjs +++ /dev/null @@ -1,288 +0,0 @@ - -/* -import { Y } from '../utils/Y.mjs' -import { createMutex } from '../lib/mutex.mjs' -import { decodePersisted, encodeStructsDS, encodeUpdate, PERSIST_STRUCTS_DS, PERSIST_UPDATE } from './decodePersisted.mjs' - -function rtop (request) { - return new Promise(function (resolve, reject) { - request.onerror = function (event) { - reject(new Error(event.target.error)) - } - request.onblocked = function () { - location.reload() - } - request.onsuccess = function (event) { - resolve(event.target.result) - } - }) -} - -function openDB (room) { - return new Promise(function (resolve, reject) { - let request = indexedDB.open(room) - request.onupgradeneeded = function (event) { - const db = event.target.result - if (db.objectStoreNames.contains('updates')) { - db.deleteObjectStore('updates') - } - db.createObjectStore('updates', {autoIncrement: true}) - } - request.onerror = function (event) { - reject(new Error(event.target.error)) - } - request.onblocked = function () { - location.reload() - } - request.onsuccess = function (event) { - const db = event.target.result - db.onversionchange = function () { db.close() } - resolve(db) - } - }) -} - -function persist (room) { - let t = room.db.transaction(['updates'], 'readwrite') - let updatesStore = t.objectStore('updates') - return rtop(updatesStore.getAll()) - .then(updates => { - // apply all previous updates before deleting them - room.mutex(() => { - updates.forEach(update => { - decodePersisted(y, new BinaryDecoder(update)) - }) - }) - const encoder = new BinaryEncoder() - encodeStructsDS(y, encoder) - // delete all pending updates - rtop(updatesStore.clear()).then(() => { - // write current model - updatesStore.put(encoder.createBuffer()) - }) - }) -} - -function saveUpdate (room, updateBuffer) { - const db = room.db - if (db !== null) { - const t = db.transaction(['updates'], 'readwrite') - const updatesStore = t.objectStore('updates') - const updatePut = rtop(updatesStore.put(updateBuffer)) - rtop(updatesStore.count()).then(cnt => { - if (cnt >= PREFERRED_TRIM_SIZE) { - persist(room) - } - }) - return updatePut - } -} - -function registerRoomInPersistence (documentsDB, roomName) { - return documentsDB.then( - db => Promise.all([ - db, - rtop(db.transaction(['documents'], 'readonly').objectStore('documents').get(roomName)) - ]) - ).then( - ([db, doc]) => { - if (doc === undefined) { - return rtop(db.transaction(['documents'], 'readwrite').objectStore('documents').add({ roomName, serverUpdateCounter: 0 })) - } - } - ) -} - -const PREFERRED_TRIM_SIZE = 400 - -export class IndexedDBPersistence { - constructor () { - this._rooms = new Map() - this._documentsDB = new Promise(function (resolve, reject) { - let request = indexedDB.open('_yjs_documents') - request.onupgradeneeded = function (event) { - const db = event.target.result - if (db.objectStoreNames.contains('documents')) { - db.deleteObjectStore('documents') - } - db.createObjectStore('documents', { keyPath: "roomName" }) - } - request.onerror = function (event) { - reject(new Error(event.target.error)) - } - request.onblocked = function () { - location.reload()EventListener' is not defined. - /home/dmonad/go/src/github.com/y-js/yjs/persistences/IndexedDBPersistence.js:160:36: 'BinaryDecoder' is not defined. - /home/dmonad/go/src/github.com/y-js/yjs/persistences/IndexedDBPersistence.js:167:25: 'BinaryEncoder' is not defined. - /home/dmonad/go/src/github.com/y-js/yjs/persistences/IndexedDBPersistence.js:178:25: 'BinaryEncoder' is not defined. - /home/dmonad/go/src/github.com/y-js/yjs/persistences/IndexedDBPersistence.js:203:34: 'BinaryDecoder' is not defined. - /home/dmonad/go/src/github.com/y-js/yjs/persistences/IndexedDBPersistence.js:213:17: 'encoder' is assigned a value but never used. - /home/dmonad/go/src/github.com/y-js/yjs/persistences/IndexedDBPersistence.js:213:31: 'BinaryEncoder' is not defined. - /home/dmonad/go/src/github.com/y-js/yjs/persistences/IndexedDBPersistence.js:214:30: 'BinaryEncoder' is not defined. - /home/dmonad/go/src/github.com/y-js/yjs/persistences/IndexedDBPersistence.js:230:12: Trailing spaces not allowed. - /home/dmonad/go/src/github.com/y-js/yjs/persistences/IndexedDBPersistence.js:237:5: Return statement should not contain assignment. - /home/dmonad/go/src/github.com/y-js/yjs/persistences/IndexedDBPersistence.js:243:29: 'BinaryEncoder' i - } - request.onsuccess = function (event) { - const db = event.target.result - db.onversionchange = function () { db.close() } - resolve(db) - } - }) - addEventListener('unload', () => { - // close everything when page unloads - this._rooms.forEach(room => { - if (room.db !== null) { - room.db.close() - } else { - room.dbPromise.then(db => db.close()) - } - }) - this._documentsDB.then(db => db.close()) - }) - } - getAllDocuments () { - return this._documentsDB.then( - db => rtop(db.transaction(['documents'], 'readonly').objectStore('documents').getAll()) - ) - } - setRemoteUpdateCounter (roomName, remoteUpdateCounter) { - this._documentsDB.then( - db => rtop(db.transaction(['documents'], 'readwrite').objectStore('documents').put({ roomName, remoteUpdateCounter })) - ) - } - - _createYInstance (roomName) { - const room = this._rooms.get(roomName) - if (room !== undefined) { - return room.y - } - const y = new Y() - return openDB(roomName).then( - db => rtop(db.transaction(['updates'], 'readonly').objectStore('updates').getAll()) - ).then( - updates => - y.transact(() => { - updates.forEach(update => { - decodePersisted(y, new BinaryDecoder(update)) - }) - }, true) - ).then(() => Promise.resolve(y)) - } - - _persistStructsDS (roomName, structsDS) { - const encoder = new BinaryEncoder() - encoder.writeVarUint(PERSIST_STRUCTS_DS) - encoder.writeArrayBuffer(structsDS) - return openDB(roomName).then(db => { - const t = db.transaction(['updates'], 'readwrite') - const updatesStore = t.objectStore('updates') - return rtop(updatesStore.put(encoder.createBuffer())) - }) - } - - _persistStructs (roomName, structs) { - const encoder = new BinaryEncoder() - encoder.writeVarUint(PERSIST_UPDATE) - encoder.writeArrayBuffer(structs) - return openDB(roomName).then(db => { - const t = db.transaction(['updates'], 'readwrite') - const updatesStore = t.objectStore('updates') - return rtop(updatesStore.put(encoder.createBuffer())) - }) - } - - connectY (roomName, y) { - if (this._rooms.has(roomName)) { - throw new Error('A Y instance is already bound to this room!') - } - let room = { - db: null, - dbPromise: null, - channel: null, - mutex: createMutex(), - y - } - if (typeof BroadcastChannel !== 'undefined') { - room.channel = new BroadcastChannel('__yjs__' + roomName) - room.channel.addEventListener('message', e => { - room.mutex(function () { - decodePersisted(y, new BinaryDecoder(e.data)) - }) - }) - } - y.on('destroyed', () => { - this.disconnectY(roomName, y) - }) - y.on('afterTransaction', (y, transaction) => { - room.mutex(() => { - if (transaction.encodedStructsLen > 0) { - const encoder = new BinaryEncoder() - const update = new BinaryEncoder() - encodeUpdate(y, transaction.encodedStructs, update) - const updateBuffer = update.createBuffer() - if (room.channel !== null) { - room.channel.postMessage(updateBuffer) - } - if (transaction.encodedStructsLen > 0) { - if (room.db !== null) { - saveUpdate(room, updateBuffer) - } - } - } - }) - }) - // register document in documentsDB - this._documentsDB.then( - db => - rtop(db.transaction(['documents'], 'readonly').objectStore('documents').get(roomName)) - .then( - doc => doc === undefined && rtop(db.transaction(['documents'], 'readwrite').objectStore('documents').add({ roomName, serverUpdateCounter: -1 })) - ) - ) - // open room db and read existing data - return room.dbPromise = openDB(roomName) - .then(db => { - room.db = db - const t = room.db.transaction(['updates'], 'readwrite') - const updatesStore = t.objectStore('updates') - // write current state as update - const encoder = new BinaryEncoder() - encodeStructsDS(y, encoder) - return rtop(updatesStore.put(encoder.createBuffer())).then(() => { - // read persisted state - return rtop(updatesStore.getAll()).then(updates => { - room.mutex(() => { - y.transact(() => { - updates.forEach(update => { - decodePersisted(y, new BinaryDecoder(update)) - }) - }, true) - }) - }) - }) - }) - } - disconnectY (roomName) { - const { - db, channel - } = this._rooms.get(roomName) - db.close() - if (channel !== null) { - channel.close() - } - this._rooms.delete(roomName) - } - - /** - * Remove all persisted data that belongs to a room. - * Automatically destroys all Yjs all Yjs instances that persist to - * the room. If `destroyYjsInstances = false` the persistence functionality - * will be removed from the Yjs instances. - * - removePersistedData (roomName, destroyYjsInstances = true) { - this.disconnectY(roomName) - return rtop(indexedDB.deleteDatabase(roomName)) - } -} -*/ diff --git a/persistences/decodePersisted.mjs b/persistences/decodePersisted.js similarity index 93% rename from persistences/decodePersisted.mjs rename to persistences/decodePersisted.js index 080ab36b..20d92320 100644 --- a/persistences/decodePersisted.mjs +++ b/persistences/decodePersisted.js @@ -1,7 +1,7 @@ /* -import { integrateRemoteStructs } from '../MessageHandler/integrateRemoteStructs.mjs' -import { writeStructs } from '../MessageHandler/syncStep1.mjs' -import { writeDeleteSet, readDeleteSet } from '../MessageHandler/deleteSet.mjs' +import { integrateRemoteStructs } from '../MessageHandler/integrateRemoteStructs.js' +import { writeStructs } from '../MessageHandler/syncStep1.js' +import { writeDeleteSet, readDeleteSet } from '../MessageHandler/deleteSet.js' export const PERSIST_UPDATE = 0 /** diff --git a/persistences/indexeddb.js b/persistences/indexeddb.js new file mode 100644 index 00000000..5b40c481 --- /dev/null +++ b/persistences/indexeddb.js @@ -0,0 +1 @@ +import * as idb from '../lib/idb.js' diff --git a/protocols/awarenessProtocol.mjs b/protocols/awarenessProtocol.js similarity index 94% rename from protocols/awarenessProtocol.mjs rename to protocols/awarenessProtocol.js index e0a2887a..a2ca0c80 100644 --- a/protocols/awarenessProtocol.mjs +++ b/protocols/awarenessProtocol.js @@ -2,9 +2,9 @@ * @module awareness-protocol */ -import * as encoding from '../lib/encoding.mjs' -import * as decoding from '../lib/decoding.mjs' -import { Y } from '../utils/Y.mjs' // eslint-disable-line +import * as encoding from '../lib/encoding.js' +import * as decoding from '../lib/decoding.js' +import { Y } from '../utils/Y.js' // eslint-disable-line const messageUsersStateChanged = 0 diff --git a/protocols/syncProtocol.mjs b/protocols/syncProtocol.js similarity index 97% rename from protocols/syncProtocol.mjs rename to protocols/syncProtocol.js index 49888b39..4fade2ae 100644 --- a/protocols/syncProtocol.mjs +++ b/protocols/syncProtocol.js @@ -2,14 +2,14 @@ * @module sync-protocol */ -import * as encoding from '../lib/encoding.mjs' -import * as decoding from '../lib/decoding.mjs' -import * as ID from '../utils/ID.mjs' -import { getStruct } from '../utils/structReferences.mjs' -import { deleteItemRange } from '../utils/structManipulation.mjs' -import { integrateRemoteStruct } from '../utils/integrateRemoteStructs.mjs' -import { Y } from '../utils/Y.mjs' // eslint-disable-line -import { Item } from '../structs/Item.mjs' +import * as encoding from '../lib/encoding.js' +import * as decoding from '../lib/decoding.js' +import * as ID from '../utils/ID.js' +import { getStruct } from '../utils/structReferences.js' +import { deleteItemRange } from '../utils/structManipulation.js' +import { integrateRemoteStruct } from '../utils/integrateRemoteStructs.js' +import { Y } from '../utils/Y.js' // eslint-disable-line +import { Item } from '../structs/Item.js' /** * @typedef {Map} StateSet @@ -83,7 +83,7 @@ export const writeDeleteSet = (encoder, y) => { const gc = n.gc if (currentUser !== user) { numberOfUsers++ - // a new user was foundimport { StateSet } from '../Store/StateStore.mjs' // eslint-disable-line + // a new user was foundimport { StateSet } from '../Store/StateStore.js' // eslint-disable-line if (currentUser !== null) { // happens on first iteration encoding.setUint32(encoder, lastLenPos, currentLength) diff --git a/provider/websocket.js b/provider/websocket.js new file mode 100644 index 00000000..03a23052 --- /dev/null +++ b/provider/websocket.js @@ -0,0 +1,5 @@ +/** + * @module provider/websocket + */ + +export * from './websocket/WebSocketProvider.js' diff --git a/provider/websocket.mjs b/provider/websocket.mjs deleted file mode 100644 index c4684770..00000000 --- a/provider/websocket.mjs +++ /dev/null @@ -1,5 +0,0 @@ -/** - * @module provider/websocket - */ - -export * from './websocket/WebSocketProvider.mjs' diff --git a/provider/websocket/WebSocketProvider.mjs b/provider/websocket/WebSocketProvider.js similarity index 97% rename from provider/websocket/WebSocketProvider.mjs rename to provider/websocket/WebSocketProvider.js index 2283a1b4..68f94e7a 100644 --- a/provider/websocket/WebSocketProvider.mjs +++ b/provider/websocket/WebSocketProvider.js @@ -4,8 +4,8 @@ /* eslint-env browser */ -import * as Y from '../../index.mjs' -export * from '../../index.mjs' +import * as Y from '../../index.js' +export * from '../../index.js' const messageSync = 0 const messageAwareness = 1 diff --git a/provider/websocket/server.mjs b/provider/websocket/server.js similarity index 96% rename from provider/websocket/server.mjs rename to provider/websocket/server.js index 8f28210f..aa088c07 100644 --- a/provider/websocket/server.mjs +++ b/provider/websocket/server.js @@ -1,10 +1,10 @@ /** - * @module provider/websocket + * @module provider/websocket/server */ -import * as Y from '../../index.mjs' -import WebSocket from 'ws' -import http from 'http' +const Y = require('../../build/yjs.js') +const WebSocket = require('ws') +const http = require('http') const port = process.env.PORT || 1234 diff --git a/provider/ydb/NamedEventHandler.mjs b/provider/ydb/NamedEventHandler.js similarity index 91% rename from provider/ydb/NamedEventHandler.mjs rename to provider/ydb/NamedEventHandler.js index 75460d68..7474dfad 100644 --- a/provider/ydb/NamedEventHandler.mjs +++ b/provider/ydb/NamedEventHandler.js @@ -2,7 +2,7 @@ * @module provider/ydb */ -import * as globals from './globals.mjs' +import * as globals from './globals.js' export const Class = class NamedEventHandler { constructor () { diff --git a/provider/ydb/YdbClient.mjs b/provider/ydb/YdbClient.js similarity index 92% rename from provider/ydb/YdbClient.mjs rename to provider/ydb/YdbClient.js index 1660cd18..39da5cf6 100644 --- a/provider/ydb/YdbClient.mjs +++ b/provider/ydb/YdbClient.js @@ -3,19 +3,19 @@ */ /* eslint-env browser */ -import * as idbactions from './idbactions.mjs' -import * as globals from '../../lib/globals.mjs' -import * as message from './message.mjs' -import * as bc from './broadcastchannel.mjs' -import * as encoding from '../../lib/encoding.mjs' -import * as logging from '../../lib/logging.mjs' -import * as idb from '../../lib/idb.mjs' -import * as decoding from '../../lib/decoding.mjs' -import { Y } from '../../utils/Y.mjs' -import { integrateRemoteStruct } from '../MessageHandler/integrateRemoteStructs.mjs' -import { createMutualExclude } from '../../lib/mutualExclude.mjs' +import * as idbactions from './idbactions.js' +import * as globals from '../../lib/globals.js' +import * as message from './message.js' +import * as bc from './broadcastchannel.js' +import * as encoding from '../../lib/encoding.js' +import * as logging from '../../lib/logging.js' +import * as idb from '../../lib/idb.js' +import * as decoding from '../../lib/decoding.js' +import { Y } from '../../utils/Y.js' +import { integrateRemoteStruct } from '../MessageHandler/integrateRemoteStructs.js' +import { createMutualExclude } from '../../lib/mutualExclude.js' -import * as NamedEventHandler from './NamedEventHandler.mjs' +import * as NamedEventHandler from './NamedEventHandler.js' /** * @typedef RoomState diff --git a/provider/ydb/YdbClient.test.mjs b/provider/ydb/YdbClient.test.js similarity index 92% rename from provider/ydb/YdbClient.test.mjs rename to provider/ydb/YdbClient.test.js index 327945cd..9468e811 100644 --- a/provider/ydb/YdbClient.test.mjs +++ b/provider/ydb/YdbClient.test.js @@ -4,11 +4,11 @@ /* eslint-env browser */ -import * as test from './test.mjs' -import * as ydbClient from './YdbClient.mjs' -import * as globals from './globals.mjs' -import * as idbactions from './idbactions.mjs' -import * as logging from './logging.mjs' +import * as test from './test.js' +import * as ydbClient from './YdbClient.js' +import * as globals from './globals.js' +import * as idbactions from './idbactions.js' +import * as logging from './logging.js' const wsUrl = 'ws://127.0.0.1:8899/ws' const testRoom = 'testroom' diff --git a/provider/ydb/broadcastchannel.mjs b/provider/ydb/broadcastchannel.js similarity index 97% rename from provider/ydb/broadcastchannel.mjs rename to provider/ydb/broadcastchannel.js index 61fb429d..f25354e4 100644 --- a/provider/ydb/broadcastchannel.mjs +++ b/provider/ydb/broadcastchannel.js @@ -4,10 +4,10 @@ /* eslint-env browser */ -import * as decoding from '../../lib/decoding.mjs' -import * as encoding from '../../lib/encoding.mjs' -import * as globals from '../../lib/globals.mjs' -import * as NamedEventHandler from './NamedEventHandler.mjs' +import * as decoding from '../../lib/decoding.js' +import * as encoding from '../../lib/encoding.js' +import * as globals from '../../lib/globals.js' +import * as NamedEventHandler from './NamedEventHandler.js' const bc = new BroadcastChannel('ydb-client') /** diff --git a/provider/ydb/idbactions.mjs b/provider/ydb/idbactions.js similarity index 98% rename from provider/ydb/idbactions.mjs rename to provider/ydb/idbactions.js index 7c4111d2..a768f249 100644 --- a/provider/ydb/idbactions.mjs +++ b/provider/ydb/idbactions.js @@ -33,11 +33,11 @@ * - A client may update a room when the room is in either US or Co */ -import * as encoding from '../../lib/encoding.mjs' -import * as decoding from '../../lib/decoding.mjs' -import * as idb from '../../lib/idb.mjs' -import * as globals from '../../lib/globals.mjs' -import * as message from './message.mjs' +import * as encoding from '../../lib/encoding.js' +import * as decoding from '../../lib/decoding.js' +import * as idb from '../../lib/idb.js' +import * as globals from '../../lib/globals.js' +import * as message from './message.js' /** * Get 'client-unconfirmed' store from transaction diff --git a/provider/ydb/idbactions.test.mjs b/provider/ydb/idbactions.test.js similarity index 86% rename from provider/ydb/idbactions.test.mjs rename to provider/ydb/idbactions.test.js index 50d0ce0f..41cf61c3 100644 --- a/provider/ydb/idbactions.test.mjs +++ b/provider/ydb/idbactions.test.js @@ -1,6 +1,6 @@ -import * as globals from '../../lib/globals.mjs' -import * as idbactions from './idbactions.mjs' -import * as test from '../../lib/testing.mjs' +import * as globals from '../../lib/globals.js' +import * as idbactions from './idbactions.js' +import * as test from '../../lib/testing.js' idbactions.deleteDB().then(() => idbactions.openDB()).then(db => { test.run('update lifetime 1', async (testname) => { diff --git a/provider/ydb/index.mjs b/provider/ydb/index.js similarity index 78% rename from provider/ydb/index.mjs rename to provider/ydb/index.js index d8361b70..12cb6b17 100644 --- a/provider/ydb/index.mjs +++ b/provider/ydb/index.js @@ -2,7 +2,7 @@ * @module provider/ydb */ -import * as ydbclient from './YdbClient.mjs' +import * as ydbclient from './YdbClient.js' /** * @param {string} url diff --git a/provider/ydb/message.mjs b/provider/ydb/message.js similarity index 94% rename from provider/ydb/message.mjs rename to provider/ydb/message.js index 8467924a..86af478b 100644 --- a/provider/ydb/message.mjs +++ b/provider/ydb/message.js @@ -2,11 +2,11 @@ * @module provider/ydb */ -import * as encoding from './encoding.mjs' -import * as decoding from './decoding.mjs' -import * as idbactions from './idbactions.mjs' -import * as logging from './logging.mjs' -import * as bc from './broadcastchannel.mjs' +import * as encoding from './encoding.js' +import * as decoding from './decoding.js' +import * as idbactions from './idbactions.js' +import * as logging from './logging.js' +import * as bc from './broadcastchannel.js' /* make sure to update message.go in ydb when updating these values.. */ export const MESSAGE_UPDATE = 0 // TODO: rename host_unconfirmed? diff --git a/rollup.config.js b/rollup.config.js index 68a9354c..a6d3cba8 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -4,7 +4,7 @@ import babel from 'rollup-plugin-babel' import uglify from 'rollup-plugin-uglify-es' export default [{ - input: './index.mjs', + input: './index.js', output: [{ name: 'Y', file: 'build/yjs.js', @@ -12,9 +12,9 @@ export default [{ sourcemap: true }] }, { - input: 'tests/index.mjs', + input: 'tests/index.js', output: { - file: 'build/y.test.mjs', + file: 'build/y.test.js', format: 'iife', name: 'ytests', sourcemap: true @@ -27,7 +27,7 @@ export default [{ commonjs() ] }, { - input: './examples/prosemirror.mjs', + input: './examples/prosemirror.js', output: { name: 'prosemirror', file: 'examples/build/prosemirror.js', @@ -44,7 +44,7 @@ export default [{ uglify() ] }, { - input: './examples/dom.mjs', + input: './examples/dom.js', output: { name: 'dom', file: 'examples/build/dom.js', @@ -56,7 +56,7 @@ export default [{ uglify() ] }, { - input: './examples/textarea.mjs', + input: './examples/textarea.js', output: { name: 'textarea', file: 'examples/build/textarea.js', @@ -68,7 +68,7 @@ export default [{ uglify() ] }, { - input: './examples/quill.mjs', + input: './examples/quill.js', output: { name: 'textarea', file: 'examples/build/quill.js', diff --git a/structs/Delete.mjs b/structs/Delete.js similarity index 83% rename from structs/Delete.mjs rename to structs/Delete.js index bf93c3c8..3e6d9a3f 100644 --- a/structs/Delete.mjs +++ b/structs/Delete.js @@ -2,15 +2,15 @@ * @module structs */ -import { getStructReference } from '../utils/structReferences.mjs' -import * as ID from '../utils/ID.mjs' -import { stringifyID } from '../protocols/syncProtocol.mjs' -import { writeStructToTransaction } from '../utils/Transaction.mjs' -import * as decoding from '../lib/decoding.mjs' -import * as encoding from '../lib/encoding.mjs' -import { Item } from './Item.mjs' // eslint-disable-line -import { Y } from '../utils/Y.mjs' // eslint-disable-line -import { deleteItemRange } from '../utils/structManipulation.mjs' +import { getStructReference } from '../utils/structReferences.js' +import * as ID from '../utils/ID.js' +import { stringifyID } from '../protocols/syncProtocol.js' +import { writeStructToTransaction } from '../utils/Transaction.js' +import * as decoding from '../lib/decoding.js' +import * as encoding from '../lib/encoding.js' +import { Item } from './Item.js' // eslint-disable-line +import { Y } from '../utils/Y.js' // eslint-disable-line +import { deleteItemRange } from '../utils/structManipulation.js' /** * @private diff --git a/structs/GC.mjs b/structs/GC.js similarity index 88% rename from structs/GC.mjs rename to structs/GC.js index 1d0f8797..55c94db7 100644 --- a/structs/GC.mjs +++ b/structs/GC.js @@ -2,12 +2,12 @@ * @module structs */ -import { getStructReference } from '../utils/structReferences.mjs' -import * as ID from '../utils/ID.mjs' -import { writeStructToTransaction } from '../utils/Transaction.mjs' -import * as decoding from '../lib/decoding.mjs' -import * as encoding from '../lib/encoding.mjs' -import { Y } from '../utils/Y.mjs' // eslint-disable-line +import { getStructReference } from '../utils/structReferences.js' +import * as ID from '../utils/ID.js' +import { writeStructToTransaction } from '../utils/Transaction.js' +import * as decoding from '../lib/decoding.js' +import * as encoding from '../lib/encoding.js' +import { Y } from '../utils/Y.js' // eslint-disable-line // TODO should have the same base class as Item export class GC { diff --git a/structs/Item.mjs b/structs/Item.js similarity index 97% rename from structs/Item.mjs rename to structs/Item.js index d50bccc4..7ea72def 100644 --- a/structs/Item.mjs +++ b/structs/Item.js @@ -2,15 +2,15 @@ * @module structs */ -import { getStructReference } from '../utils/structReferences.mjs' -import * as ID from '../utils/ID.mjs' -import { Delete } from './Delete.mjs' -import { transactionTypeChanged, writeStructToTransaction } from '../utils/Transaction.mjs' -import { GC } from './GC.mjs' -import * as encoding from '../lib/encoding.mjs' -import * as decoding from '../lib/decoding.mjs' -import { Y } from '../utils/Y.mjs' -import { Type } from './Type.mjs' // eslint-disable-line +import { getStructReference } from '../utils/structReferences.js' +import * as ID from '../utils/ID.js' +import { Delete } from './Delete.js' +import { transactionTypeChanged, writeStructToTransaction } from '../utils/Transaction.js' +import { GC } from './GC.js' +import * as encoding from '../lib/encoding.js' +import * as decoding from '../lib/decoding.js' +import { Y } from '../utils/Y.js' +import { Type } from './Type.js' // eslint-disable-line /** * @private diff --git a/structs/ItemEmbed.mjs b/structs/ItemEmbed.js similarity index 79% rename from structs/ItemEmbed.mjs rename to structs/ItemEmbed.js index 04dd9290..52974acd 100644 --- a/structs/ItemEmbed.mjs +++ b/structs/ItemEmbed.js @@ -2,11 +2,11 @@ * @module structs */ -import { Item } from './Item.mjs' -import { logItemHelper } from '../protocols/syncProtocol.mjs' -import * as encoding from '../lib/encoding.mjs' -import * as decoding from '../lib/decoding.mjs' -import { Y } from '../utils/Y.mjs' // eslint-disable-line +import { Item } from './Item.js' +import { logItemHelper } from '../protocols/syncProtocol.js' +import * as encoding from '../lib/encoding.js' +import * as decoding from '../lib/decoding.js' +import { Y } from '../utils/Y.js' // eslint-disable-line export class ItemEmbed extends Item { constructor () { diff --git a/structs/ItemFormat.mjs b/structs/ItemFormat.js similarity index 82% rename from structs/ItemFormat.mjs rename to structs/ItemFormat.js index 074bdd2a..f002c7bb 100644 --- a/structs/ItemFormat.mjs +++ b/structs/ItemFormat.js @@ -2,11 +2,11 @@ * @module structs */ -import { Item } from './Item.mjs' -import { logItemHelper } from '../protocols/syncProtocol.mjs' -import * as encoding from '../lib/encoding.mjs' -import * as decoding from '../lib/decoding.mjs' -import { Y } from '../utils/Y.mjs' // eslint-disable-line +import { Item } from './Item.js' +import { logItemHelper } from '../protocols/syncProtocol.js' +import * as encoding from '../lib/encoding.js' +import * as decoding from '../lib/decoding.js' +import { Y } from '../utils/Y.js' // eslint-disable-line export class ItemFormat extends Item { constructor () { diff --git a/structs/ItemJSON.mjs b/structs/ItemJSON.js similarity index 87% rename from structs/ItemJSON.mjs rename to structs/ItemJSON.js index 78062273..1d5036a8 100644 --- a/structs/ItemJSON.mjs +++ b/structs/ItemJSON.js @@ -2,11 +2,11 @@ * @module structs */ -import { Item, splitHelper } from './Item.mjs' -import { logItemHelper } from '../protocols/syncProtocol.mjs' -import * as encoding from '../lib/encoding.mjs' -import * as decoding from '../lib/decoding.mjs' -import { Y } from '../utils/Y.mjs' // eslint-disable-line +import { Item, splitHelper } from './Item.js' +import { logItemHelper } from '../protocols/syncProtocol.js' +import * as encoding from '../lib/encoding.js' +import * as decoding from '../lib/decoding.js' +import { Y } from '../utils/Y.js' // eslint-disable-line export class ItemJSON extends Item { constructor () { diff --git a/structs/ItemString.mjs b/structs/ItemString.js similarity index 82% rename from structs/ItemString.mjs rename to structs/ItemString.js index 43fa558c..ed6a0b1f 100644 --- a/structs/ItemString.mjs +++ b/structs/ItemString.js @@ -2,11 +2,11 @@ * @module structs */ -import { Item, splitHelper } from './Item.mjs' -import { logItemHelper } from '../protocols/syncProtocol.mjs' -import * as encoding from '../lib/encoding.mjs' -import * as decoding from '../lib/decoding.mjs' -import { Y } from '../utils/Y.mjs' // eslint-disable-line +import { Item, splitHelper } from './Item.js' +import { logItemHelper } from '../protocols/syncProtocol.js' +import * as encoding from '../lib/encoding.js' +import * as decoding from '../lib/decoding.js' +import { Y } from '../utils/Y.js' // eslint-disable-line export class ItemString extends Item { constructor () { diff --git a/structs/Type.mjs b/structs/Type.js similarity index 96% rename from structs/Type.mjs rename to structs/Type.js index fff8d407..7e8fe15d 100644 --- a/structs/Type.mjs +++ b/structs/Type.js @@ -2,11 +2,11 @@ * @module structs */ -import { Item } from './Item.mjs' -import { EventHandler } from '../utils/EventHandler.mjs' -import { createID } from '../utils/ID.mjs' -import { YEvent } from '../utils/YEvent.mjs' -import { Y } from '../utils/Y.mjs' // eslint-disable-line +import { Item } from './Item.js' +import { EventHandler } from '../utils/EventHandler.js' +import { createID } from '../utils/ID.js' +import { YEvent } from '../utils/YEvent.js' +import { Y } from '../utils/Y.js' // eslint-disable-line // restructure children as if they were inserted one after another const integrateChildren = (y, start) => { diff --git a/tests/DeleteStore.tests.mjs b/tests/DeleteStore.tests.js similarity index 94% rename from tests/DeleteStore.tests.mjs rename to tests/DeleteStore.tests.js index 406c469f..2317587e 100644 --- a/tests/DeleteStore.tests.mjs +++ b/tests/DeleteStore.tests.js @@ -1,7 +1,7 @@ import { test } from 'cutest' -import * as random from '../lib/prng/prng.mjs' -import { DeleteStore } from '../utils/DeleteStore.mjs' -import * as ID from '../utils/ID.mjs' +import * as random from '../lib/prng/prng.js' +import { DeleteStore } from '../utils/DeleteStore.js' +import * as ID from '../utils/ID.js' /** * Converts a DS to an array of length 10. diff --git a/tests/diff.tests.mjs b/tests/diff.tests.js similarity index 92% rename from tests/diff.tests.mjs rename to tests/diff.tests.js index 60a0067c..f8e91f6b 100644 --- a/tests/diff.tests.mjs +++ b/tests/diff.tests.js @@ -1,6 +1,6 @@ import { test } from 'cutest' -import { simpleDiff } from '../lib/diff.mjs' -import * as random from '../lib/prng/prng.mjs' +import { simpleDiff } from '../lib/diff.js' +import * as random from '../lib/prng/prng.js' function runDiffTest (t, a, b, expected) { let result = simpleDiff(a, b) diff --git a/tests/encode-decode.tests.mjs b/tests/encode-decode.tests.js similarity index 94% rename from tests/encode-decode.tests.mjs rename to tests/encode-decode.tests.js index 740472ff..e6fc7b17 100644 --- a/tests/encode-decode.tests.mjs +++ b/tests/encode-decode.tests.js @@ -1,8 +1,8 @@ import { test } from 'cutest' -import { generateRandomUint32 } from '../utils/generateRandomUint32.mjs' -import * as encoding from '../lib/encoding.mjs' -import * as decoding from '../lib/decoding.mjs' -import * as random from '../lib/prng/prng.mjs' +import { generateRandomUint32 } from '../utils/generateRandomUint32.js' +import * as encoding from '../lib/encoding.js' +import * as decoding from '../lib/decoding.js' +import * as random from '../lib/prng/prng.js' function testEncoding (t, write, read, val) { let encoder = encoding.createEncoder() diff --git a/tests/helper.mjs b/tests/helper.js similarity index 95% rename from tests/helper.mjs rename to tests/helper.js index a8a18073..6e3d35ed 100644 --- a/tests/helper.mjs +++ b/tests/helper.js @@ -1,19 +1,19 @@ -import * as Y from '../index.mjs' -import { ItemJSON } from '../structs/ItemJSON.mjs' -import { ItemString } from '../structs/ItemString.mjs' -import { defragmentItemContent } from '../utils/defragmentItemContent.mjs' +import * as Y from '../index.js' +import { ItemJSON } from '../structs/ItemJSON.js' +import { ItemString } from '../structs/ItemString.js' +import { defragmentItemContent } from '../utils/defragmentItemContent.js' import Quill from 'quill' -import { GC } from '../structs/GC.mjs' -import * as random from '../lib/prng/prng.mjs' -import * as syncProtocol from '../protocols/syncProtocol.mjs' -import * as encoding from '../lib/encoding.mjs' -import * as decoding from '../lib/decoding.mjs' -import { createMutex } from '../lib/mutex.mjs' -import { QuillBinding } from '../bindings/quill.mjs' -import { DomBinding } from '../bindings/dom/DomBinding.mjs' +import { GC } from '../structs/GC.js' +import * as random from '../lib/prng/prng.js' +import * as syncProtocol from '../protocols/syncProtocol.js' +import * as encoding from '../lib/encoding.js' +import * as decoding from '../lib/decoding.js' +import { createMutex } from '../lib/mutex.js' +import { QuillBinding } from '../bindings/quill.js' +import { DomBinding } from '../bindings/dom/DomBinding.js' -export * from '../index.mjs' +export * from '../index.js' /** * @param {TestYInstance} y diff --git a/tests/index.js b/tests/index.js new file mode 100644 index 00000000..8f30d9ae --- /dev/null +++ b/tests/index.js @@ -0,0 +1,9 @@ +// TODO: include all tests +import './red-black-tree.js' +import './y-array.tests.js' +import './y-text.tests.js' +import './y-map.tests.js' +import './y-xml.tests.js' +import './encode-decode.tests.js' +import './diff.tests.js' +import './prosemirror.test.js' diff --git a/tests/index.mjs b/tests/index.mjs deleted file mode 100644 index a9058701..00000000 --- a/tests/index.mjs +++ /dev/null @@ -1,9 +0,0 @@ -// TODO: include all tests -import './red-black-tree.mjs' -import './y-array.tests.mjs' -import './y-text.tests.mjs' -import './y-map.tests.mjs' -import './y-xml.tests.mjs' -import './encode-decode.tests.mjs' -import './diff.tests.mjs' -import './prosemirror.test.mjs' diff --git a/tests/prosemirror.test.mjs b/tests/prosemirror.test.js similarity index 88% rename from tests/prosemirror.test.mjs rename to tests/prosemirror.test.js index f24a2b59..7a005207 100644 --- a/tests/prosemirror.test.mjs +++ b/tests/prosemirror.test.js @@ -1,8 +1,8 @@ import { test } from 'cutest' -import * as random from '../lib/prng/prng.mjs' -import * as Y from '../index.mjs' +import * as random from '../lib/prng/prng.js' +import * as Y from '../index.js' -import { prosemirrorPlugin } from '../bindings/prosemirror.mjs' +import { prosemirrorPlugin } from '../bindings/prosemirror.js' import {EditorState} from 'prosemirror-state' import {EditorView} from 'prosemirror-view' import {schema} from 'prosemirror-schema-basic' diff --git a/tests/red-black-tree.mjs b/tests/red-black-tree.js similarity index 97% rename from tests/red-black-tree.mjs rename to tests/red-black-tree.js index e46c7694..857550f0 100644 --- a/tests/red-black-tree.mjs +++ b/tests/red-black-tree.js @@ -1,7 +1,7 @@ -import { Tree as RedBlackTree } from '../lib/Tree.mjs' -import * as ID from '../utils/ID.mjs' +import { Tree as RedBlackTree } from '../lib/Tree.js' +import * as ID from '../utils/ID.js' import { test, proxyConsole } from 'cutest' -import * as random from '../lib/prng/prng.mjs' +import * as random from '../lib/prng/prng.js' proxyConsole() diff --git a/tests/y-array.tests.mjs b/tests/y-array.tests.js similarity index 99% rename from tests/y-array.tests.mjs rename to tests/y-array.tests.js index 199f2591..b59d96f8 100644 --- a/tests/y-array.tests.mjs +++ b/tests/y-array.tests.js @@ -1,7 +1,7 @@ -import { initArrays, compareUsers, applyRandomTests } from './helper.mjs' -import * as Y from '../index.mjs' +import { initArrays, compareUsers, applyRandomTests } from './helper.js' +import * as Y from '../index.js' import { test, proxyConsole } from 'cutest' -import * as random from '../lib/prng/prng.mjs' +import * as random from '../lib/prng/prng.js' proxyConsole() test('basic spec', async function array0 (t) { diff --git a/tests/y-map.tests.mjs b/tests/y-map.tests.js similarity index 99% rename from tests/y-map.tests.mjs rename to tests/y-map.tests.js index 65230f96..3e9fefb5 100644 --- a/tests/y-map.tests.mjs +++ b/tests/y-map.tests.js @@ -1,7 +1,7 @@ -import { initArrays, compareUsers, applyRandomTests } from './helper.mjs' -import * as Y from '../index.mjs' +import { initArrays, compareUsers, applyRandomTests } from './helper.js' +import * as Y from '../index.js' import { test, proxyConsole } from 'cutest' -import * as random from '../lib/prng/prng.mjs' +import * as random from '../lib/prng/prng.js' proxyConsole() diff --git a/tests/y-text.tests.mjs b/tests/y-text.tests.js similarity index 98% rename from tests/y-text.tests.mjs rename to tests/y-text.tests.js index c1f8a8f7..118c8087 100644 --- a/tests/y-text.tests.mjs +++ b/tests/y-text.tests.js @@ -1,4 +1,4 @@ -import { initArrays, compareUsers } from './helper.mjs' +import { initArrays, compareUsers } from './helper.js' import { test, proxyConsole } from 'cutest' proxyConsole() diff --git a/tests/y-xml.tests.mjs b/tests/y-xml.tests.js similarity index 99% rename from tests/y-xml.tests.mjs rename to tests/y-xml.tests.js index 4193bc5b..f963cd6a 100644 --- a/tests/y-xml.tests.mjs +++ b/tests/y-xml.tests.js @@ -1,7 +1,7 @@ -import { initArrays, compareUsers, applyRandomTests } from './helper.mjs' +import { initArrays, compareUsers, applyRandomTests } from './helper.js' import { test } from 'cutest' -import * as Y from '../index.mjs' -import * as random from '../lib/prng/prng.mjs' +import * as Y from '../index.js' +import * as random from '../lib/prng/prng.js' test('set property', async function xml0 (t) { var { testConnector, users, xml0, xml1 } = await initArrays(t, { users: 2 }) diff --git a/types/YArray.mjs b/types/YArray.js similarity index 96% rename from types/YArray.mjs rename to types/YArray.js index 3cfdae59..9aa45a89 100644 --- a/types/YArray.mjs +++ b/types/YArray.js @@ -2,13 +2,13 @@ * @module types */ -import { Type } from '../structs/Type.mjs' -import { ItemJSON } from '../structs/ItemJSON.mjs' -import { ItemString } from '../structs/ItemString.mjs' -import { stringifyItemID, logItemHelper } from '../protocols/syncProtocol.mjs' -import { YEvent } from '../utils/YEvent.mjs' -import { Transaction } from '../utils/Transaction.mjs' // eslint-disable-line -import { Item } from '../structs/Item.mjs' // eslint-disable-line +import { Type } from '../structs/Type.js' +import { ItemJSON } from '../structs/ItemJSON.js' +import { ItemString } from '../structs/ItemString.js' +import { stringifyItemID, logItemHelper } from '../protocols/syncProtocol.js' +import { YEvent } from '../utils/YEvent.js' +import { Transaction } from '../utils/Transaction.js' // eslint-disable-line +import { Item } from '../structs/Item.js' // eslint-disable-line /** * Event that describes the changes on a YArray diff --git a/types/YMap.mjs b/types/YMap.js similarity index 94% rename from types/YMap.mjs rename to types/YMap.js index 1ef79f53..50aaa41e 100644 --- a/types/YMap.mjs +++ b/types/YMap.js @@ -2,11 +2,11 @@ * @module types */ -import { Item } from '../structs/Item.mjs' -import { Type } from '../structs/Type.mjs' -import { ItemJSON } from '../structs/ItemJSON.mjs' -import { logItemHelper } from '../protocols/syncProtocol.mjs' -import { YEvent } from '../utils/YEvent.mjs' +import { Item } from '../structs/Item.js' +import { Type } from '../structs/Type.js' +import { ItemJSON } from '../structs/ItemJSON.js' +import { logItemHelper } from '../protocols/syncProtocol.js' +import { YEvent } from '../utils/YEvent.js' /** * Event that describes the changes on a YMap. diff --git a/types/YText.mjs b/types/YText.js similarity index 98% rename from types/YText.mjs rename to types/YText.js index 7283e305..a3cc6aec 100644 --- a/types/YText.mjs +++ b/types/YText.js @@ -2,11 +2,11 @@ * @module types */ -import { ItemEmbed } from '../structs/ItemEmbed.mjs' -import { ItemString } from '../structs/ItemString.mjs' -import { ItemFormat } from '../structs/ItemFormat.mjs' -import { logItemHelper } from '../protocols/syncProtocol.mjs' -import { YArrayEvent, YArray } from './YArray.mjs' +import { ItemEmbed } from '../structs/ItemEmbed.js' +import { ItemString } from '../structs/ItemString.js' +import { ItemFormat } from '../structs/ItemFormat.js' +import { logItemHelper } from '../protocols/syncProtocol.js' +import { YArrayEvent, YArray } from './YArray.js' /** * @private diff --git a/types/YXmlElement.mjs b/types/YXmlElement.js similarity index 94% rename from types/YXmlElement.mjs rename to types/YXmlElement.js index 4b6a8535..ad8de404 100644 --- a/types/YXmlElement.mjs +++ b/types/YXmlElement.js @@ -2,16 +2,16 @@ * @module types */ -import { YMap } from './YMap.mjs' -import { createAssociation } from '../bindings/dom/util.mjs' -import * as encoding from '../lib/encoding.mjs' -import * as decoding from '../lib/decoding.mjs' -import { Y } from '../utils/Y.mjs' // eslint-disable-line -import { DomBinding } from '../bindings/dom/DomBinding.mjs' // eslint-disable-line -import { YXmlTreeWalker } from './YXmlTreeWalker.mjs' -import { YArray } from './YArray.mjs' -import { YXmlEvent } from './YXmlEvent.mjs' -import { logItemHelper } from '../protocols/syncProtocol.mjs' +import { YMap } from './YMap.js' +import { createAssociation } from '../bindings/dom/util.js' +import * as encoding from '../lib/encoding.js' +import * as decoding from '../lib/decoding.js' +import { Y } from '../utils/Y.js' // eslint-disable-line +import { DomBinding } from '../bindings/dom/DomBinding.js' // eslint-disable-line +import { YXmlTreeWalker } from './YXmlTreeWalker.js' +import { YArray } from './YArray.js' +import { YXmlEvent } from './YXmlEvent.js' +import { logItemHelper } from '../protocols/syncProtocol.js' /** * Dom filter function. diff --git a/types/YXmlEvent.mjs b/types/YXmlEvent.js similarity index 87% rename from types/YXmlEvent.mjs rename to types/YXmlEvent.js index e8bb46b4..e41d9f26 100644 --- a/types/YXmlEvent.mjs +++ b/types/YXmlEvent.js @@ -2,10 +2,10 @@ * @module types */ -import { YEvent } from '../utils/YEvent.mjs' +import { YEvent } from '../utils/YEvent.js' -import { Type } from '../structs/Type.mjs' // eslint-disable-line -import { Transaction } from '../utils/Transaction.mjs' // eslint-disable-line +import { Type } from '../structs/Type.js' // eslint-disable-line +import { Transaction } from '../utils/Transaction.js' // eslint-disable-line /** * An Event that describes changes on a YXml Element or Yxml Fragment diff --git a/types/YXmlHook.mjs b/types/YXmlHook.js similarity index 89% rename from types/YXmlHook.mjs rename to types/YXmlHook.js index 5b259960..ad45f1eb 100644 --- a/types/YXmlHook.mjs +++ b/types/YXmlHook.js @@ -2,13 +2,13 @@ * @module types */ -import { YMap } from './YMap.mjs' -import { createAssociation } from '../bindings/dom/util.mjs' -import * as encoding from '../lib/encoding.mjs' -import * as decoding from '../lib/decoding.mjs' +import { YMap } from './YMap.js' +import { createAssociation } from '../bindings/dom/util.js' +import * as encoding from '../lib/encoding.js' +import * as decoding from '../lib/decoding.js' -import { DomBinding } from '../bindings/dom/DomBinding.mjs' // eslint-disable-line -import { Y } from '../utils/Y.mjs' // eslint-disable-line +import { DomBinding } from '../bindings/dom/DomBinding.js' // eslint-disable-line +import { Y } from '../utils/Y.js' // eslint-disable-line /** * You can manage binding to a custom type with YXmlHook. diff --git a/types/YXmlText.mjs b/types/YXmlText.js similarity index 87% rename from types/YXmlText.mjs rename to types/YXmlText.js index efce5573..9a7f8f6f 100644 --- a/types/YXmlText.mjs +++ b/types/YXmlText.js @@ -2,10 +2,10 @@ * @module types */ -import { YText } from './YText.mjs' -import { createAssociation } from '../bindings/dom/util.mjs' -import { Y } from '../utils/Y.mjs' // eslint-disable-line -import { DomBinding } from '../bindings/dom/DomBinding.mjs' // eslint-disable-line +import { YText } from './YText.js' +import { createAssociation } from '../bindings/dom/util.js' +import { Y } from '../utils/Y.js' // eslint-disable-line +import { DomBinding } from '../bindings/dom/DomBinding.js' // eslint-disable-line /** * Represents text in a Dom Element. In the future this type will also handle diff --git a/types/YXmlTreeWalker.mjs b/types/YXmlTreeWalker.js similarity index 95% rename from types/YXmlTreeWalker.mjs rename to types/YXmlTreeWalker.js index 848fa18d..605266c7 100644 --- a/types/YXmlTreeWalker.mjs +++ b/types/YXmlTreeWalker.js @@ -2,7 +2,7 @@ * @module types */ -import { YXmlElement, YXmlFragment } from './YXmlElement.mjs' // eslint-disable-line +import { YXmlElement, YXmlFragment } from './YXmlElement.js' // eslint-disable-line /** * Define the elements to which a set of CSS queries apply. diff --git a/utils/BindMapping.mjs b/utils/BindMapping.js similarity index 100% rename from utils/BindMapping.mjs rename to utils/BindMapping.js diff --git a/utils/DeleteStore.mjs b/utils/DeleteStore.js similarity index 97% rename from utils/DeleteStore.mjs rename to utils/DeleteStore.js index 864b52b2..00329b89 100644 --- a/utils/DeleteStore.mjs +++ b/utils/DeleteStore.js @@ -2,8 +2,8 @@ * @module utils */ -import { Tree } from '../lib/Tree.mjs' -import * as ID from './ID.mjs' +import { Tree } from '../lib/Tree.js' +import * as ID from './ID.js' class DSNode { constructor (id, len, gc) { diff --git a/utils/EventHandler.mjs b/utils/EventHandler.js similarity index 100% rename from utils/EventHandler.mjs rename to utils/EventHandler.js diff --git a/utils/ID.mjs b/utils/ID.js similarity index 93% rename from utils/ID.mjs rename to utils/ID.js index 1bc1a658..cd421309 100644 --- a/utils/ID.mjs +++ b/utils/ID.js @@ -2,9 +2,9 @@ * @module utils */ -import { getStructReference } from './structReferences.mjs' -import * as decoding from '../lib/decoding.mjs' -import * as encoding from '../lib/encoding.mjs' +import { getStructReference } from './structReferences.js' +import * as decoding from '../lib/decoding.js' +import * as encoding from '../lib/encoding.js' export class ID { constructor (user, clock) { diff --git a/utils/OperationStore.mjs b/utils/OperationStore.js similarity index 93% rename from utils/OperationStore.mjs rename to utils/OperationStore.js index 45b1e6e3..d473dd19 100644 --- a/utils/OperationStore.mjs +++ b/utils/OperationStore.js @@ -2,11 +2,11 @@ * @module utils */ -import { Tree } from '../lib/Tree.mjs' -import * as ID from '../utils/ID.mjs' -import { getStruct } from '../utils/structReferences.mjs' -import { stringifyID, stringifyItemID } from '../protocols/syncProtocol.mjs' -import { GC } from '../structs/GC.mjs' +import { Tree } from '../lib/Tree.js' +import * as ID from '../utils/ID.js' +import { getStruct } from '../utils/structReferences.js' +import { stringifyID, stringifyItemID } from '../protocols/syncProtocol.js' +import { GC } from '../structs/GC.js' export class OperationStore extends Tree { constructor (y) { diff --git a/utils/StateStore.mjs b/utils/StateStore.js similarity index 96% rename from utils/StateStore.mjs rename to utils/StateStore.js index b6024483..f739b5f5 100644 --- a/utils/StateStore.mjs +++ b/utils/StateStore.js @@ -2,7 +2,7 @@ * @module utils */ -import * as ID from '../utils/ID.mjs' +import * as ID from '../utils/ID.js' /** * @typedef {Map} StateSet diff --git a/utils/Transaction.mjs b/utils/Transaction.js similarity index 89% rename from utils/Transaction.mjs rename to utils/Transaction.js index 67b2b793..ce34d5f0 100644 --- a/utils/Transaction.mjs +++ b/utils/Transaction.js @@ -2,11 +2,11 @@ * @module utils */ -import * as encoding from '../lib/encoding.mjs' -import { Y } from '../utils/Y.mjs' // eslint-disable-line -import { Type } from '../structs/Type.mjs' // eslint-disable-line -import { Item } from '../structs/Item.mjs' // eslint-disable-line -import { YEvent } from './YEvent.mjs' // eslint-disable-line +import * as encoding from '../lib/encoding.js' +import { Y } from '../utils/Y.js' // eslint-disable-line +import { Type } from '../structs/Type.js' // eslint-disable-line +import { Item } from '../structs/Item.js' // eslint-disable-line +import { YEvent } from './YEvent.js' // eslint-disable-line /** * A transaction is created for every change on the Yjs model. It is possible * to bundle changes on the Yjs model in a single transaction to diff --git a/utils/UndoManager.mjs b/utils/UndoManager.js similarity index 98% rename from utils/UndoManager.mjs rename to utils/UndoManager.js index 8a9c73e7..4eae011c 100644 --- a/utils/UndoManager.mjs +++ b/utils/UndoManager.js @@ -1,6 +1,6 @@ -import * as ID from './ID.mjs' -import { isParentOf } from './isParentOf.mjs' +import * as ID from './ID.js' +import { isParentOf } from './isParentOf.js' class ReverseOperation { constructor (y, transaction, bindingInfos) { diff --git a/utils/Y.mjs b/utils/Y.js similarity index 90% rename from utils/Y.mjs rename to utils/Y.js index 7e6e96e9..17ff70ba 100644 --- a/utils/Y.mjs +++ b/utils/Y.js @@ -1,15 +1,15 @@ -import { DeleteStore } from './DeleteStore.mjs' -import { OperationStore } from './OperationStore.mjs' -import { StateStore } from './StateStore.mjs' -import { generateRandomUint32 } from './generateRandomUint32.mjs' -import { createRootID } from './ID.mjs' -import { NamedEventHandler } from '../lib/NamedEventHandler.mjs' -import { Transaction } from './Transaction.mjs' -import * as encoding from '../lib/encoding.mjs' -import * as message from '../protocols/syncProtocol.mjs' -import { integrateRemoteStructs } from './integrateRemoteStructs.mjs' -import { Type } from '../structs/Type.mjs' // eslint-disable-line -import { Decoder } from '../lib/decoding.mjs' // eslint-disable-line +import { DeleteStore } from './DeleteStore.js' +import { OperationStore } from './OperationStore.js' +import { StateStore } from './StateStore.js' +import { generateRandomUint32 } from './generateRandomUint32.js' +import { createRootID } from './ID.js' +import { NamedEventHandler } from '../lib/NamedEventHandler.js' +import { Transaction } from './Transaction.js' +import * as encoding from '../lib/encoding.js' +import * as message from '../protocols/syncProtocol.js' +import { integrateRemoteStructs } from './integrateRemoteStructs.js' +import { Type } from '../structs/Type.js' // eslint-disable-line +import { Decoder } from '../lib/decoding.js' // eslint-disable-line /** * Anything that can be encoded with `JSON.stringify` and can be decoded with diff --git a/utils/YEvent.mjs b/utils/YEvent.js similarity index 92% rename from utils/YEvent.mjs rename to utils/YEvent.js index dc8c65dd..78bccb26 100644 --- a/utils/YEvent.mjs +++ b/utils/YEvent.js @@ -2,7 +2,7 @@ * @module utils */ -import { Type } from '../structs/Type.mjs' // eslint-disable-line +import { Type } from '../structs/Type.js' // eslint-disable-line /** * YEvent describes the changes on a YType. diff --git a/utils/defragmentItemContent.mjs b/utils/defragmentItemContent.js similarity index 91% rename from utils/defragmentItemContent.mjs rename to utils/defragmentItemContent.js index d4240fd7..19c57b84 100644 --- a/utils/defragmentItemContent.mjs +++ b/utils/defragmentItemContent.js @@ -3,9 +3,9 @@ * @module utils */ -import * as ID from '../utils/ID.mjs' -import { ItemJSON } from '../structs/ItemJSON.mjs' -import { ItemString } from '../structs/ItemString.mjs' +import * as ID from '../utils/ID.js' +import { ItemJSON } from '../structs/ItemJSON.js' +import { ItemString } from '../structs/ItemString.js' /** * Try to merge all items in os with their successors. diff --git a/utils/generateRandomUint32.mjs b/utils/generateRandomUint32.js similarity index 100% rename from utils/generateRandomUint32.mjs rename to utils/generateRandomUint32.js diff --git a/utils/integrateRemoteStructs.mjs b/utils/integrateRemoteStructs.js similarity index 93% rename from utils/integrateRemoteStructs.mjs rename to utils/integrateRemoteStructs.js index 77a0fb44..265cad2f 100644 --- a/utils/integrateRemoteStructs.mjs +++ b/utils/integrateRemoteStructs.js @@ -2,11 +2,11 @@ * @module utils */ -import { getStruct } from '../utils/structReferences.mjs' -import * as decoding from '../lib/decoding.mjs' -import { GC } from '../structs/GC.mjs' -import { Y } from '../utils/Y.mjs' // eslint-disable-line -import { Item } from '../structs/Item.mjs' // eslint-disable-line +import { getStruct } from '../utils/structReferences.js' +import * as decoding from '../lib/decoding.js' +import { GC } from '../structs/GC.js' +import { Y } from '../utils/Y.js' // eslint-disable-line +import { Item } from '../structs/Item.js' // eslint-disable-line class MissingEntry { constructor (decoder, missing, struct) { diff --git a/utils/isParentOf.mjs b/utils/isParentOf.js similarity index 76% rename from utils/isParentOf.mjs rename to utils/isParentOf.js index 1357d66d..d4833209 100644 --- a/utils/isParentOf.mjs +++ b/utils/isParentOf.js @@ -2,8 +2,8 @@ * @module utils */ -import { Y } from '../utils/Y.mjs' // eslint-disable-line -import { Type } from '../structs/Type.mjs' // eslint-disable-line +import { Y } from '../utils/Y.js' // eslint-disable-line +import { Type } from '../structs/Type.js' // eslint-disable-line /** * Check if `parent` is a parent of `child`. diff --git a/utils/relativePosition.mjs b/utils/relativePosition.js similarity index 97% rename from utils/relativePosition.mjs rename to utils/relativePosition.js index 51d2ccbd..8f15b2e1 100644 --- a/utils/relativePosition.mjs +++ b/utils/relativePosition.js @@ -2,8 +2,8 @@ * @module utils */ -import * as ID from './ID.mjs' -import { GC } from '../structs/GC.mjs' +import * as ID from './ID.js' +import { GC } from '../structs/GC.js' // TODO: Implement function to describe ranges diff --git a/utils/structManipulation.mjs b/utils/structManipulation.js similarity index 96% rename from utils/structManipulation.mjs rename to utils/structManipulation.js index bff1e477..2ab26e36 100644 --- a/utils/structManipulation.mjs +++ b/utils/structManipulation.js @@ -1,5 +1,5 @@ -import * as ID from '../utils/ID.mjs' +import * as ID from '../utils/ID.js' /** * @private diff --git a/utils/structReferences.mjs b/utils/structReferences.js similarity index 100% rename from utils/structReferences.mjs rename to utils/structReferences.js