mjs nodejs support

This commit is contained in:
Kevin Jahns 2018-11-25 22:39:30 +01:00
parent e4a5f2caec
commit c12d00b227
122 changed files with 669 additions and 503 deletions

2
.gitignore vendored
View File

@ -2,7 +2,7 @@ node_modules
bower_components
docs
/y.*
/examples/*/index.dist.*
/examples_all/*/index.dist.*
.vscode
.yjsPersisted
build

View File

@ -5,7 +5,7 @@
"dictionaries": ["jsdoc"]
},
"source": {
"include": ["./types", "./utils/UndoManager.js", "./utils/Y.js", "./provider", "./bindings"],
"include": ["./types", "./utils/UndoManager.mjs", "./utils/Y.mjs", "./provider", "./bindings"],
"includePattern": ".js$"
},
"plugins": [

14
README.new.md Normal file
View File

@ -0,0 +1,14 @@
### Typescript Declarations
Until [this](https://github.com/Microsoft/TypeScript/issues/7546) is fixed, the only way to get type declarations is by adding Yjs to the list of checked files:
```json
{
"checkJs": true,
"include": [
"./node_modules/yjs/"
]
..
}
```

View File

@ -1 +0,0 @@
export * from './dom/DomBinding.js'

1
bindings/dom.mjs Normal file
View File

@ -0,0 +1 @@
export * from './dom/DomBinding.mjs'

View File

@ -4,14 +4,14 @@
/* global MutationObserver, getSelection */
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
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
/**
* @callback DomFilter

View File

@ -2,13 +2,13 @@
* @module bindings/dom
*/
import { YXmlHook } from '../../types/YXmlHook.js'
import { YXmlHook } from '../../types/YXmlHook.mjs'
import {
iterateUntilUndeleted,
removeAssociation,
insertNodeHelper } from './util.js'
import { simpleDiff } from '../../lib/diff.js'
import { YXmlFragment } from '../../types/YXmlElement.js'
insertNodeHelper } from './util.mjs'
import { simpleDiff } from '../../lib/diff.mjs'
import { YXmlFragment } from '../../types/YXmlElement.mjs'
/**
* 1. Check if any of the nodes was deleted

View File

@ -3,12 +3,12 @@
*/
/* eslint-env browser */
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
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
/**
* @callback DomFilter

View File

@ -2,9 +2,10 @@
* @module bindings/dom
*/
import { isParentOf } from '../../utils/isParentOf.js'
import * as Y from '../../index.js'
import { DomBinding } from './DomBinding.js' // eslint-disable-line
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
/**
* Default filter method (does nothing).
@ -34,14 +35,14 @@ export const filterDomAttributes = (dom, filter) => {
/**
* Applies a filter on a type.
*
* @param {Y.Y} y The Yjs instance.
* @param {Y} y The Yjs instance.
* @param {DomBinding} binding The DOM binding instance that has the dom filter.
* @param {Y.XmlElement | Y.XmlFragment } type The type to apply the filter to.
* @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 Y.XmlElement) {
if (isParentOf(binding.type, type) && type instanceof YXmlElement) {
const nodeName = type.nodeName
let attributes = new Map()
if (type.getAttributes !== undefined) {

View File

@ -4,7 +4,7 @@
/* globals getSelection */
import { getRelativePosition } from '../../utils/relativePosition.js'
import { getRelativePosition } from '../../utils/relativePosition.mjs'
let relativeSelection = null

View File

@ -5,9 +5,9 @@
/* eslint-env browser */
/* global getSelection */
import { YXmlText } from '../../types/YXmlText.js'
import { YXmlHook } from '../../types/YXmlHook.js'
import { removeDomChildrenUntilElementFound } from './util.js'
import { YXmlText } from '../../types/YXmlText.mjs'
import { YXmlHook } from '../../types/YXmlHook.mjs'
import { removeDomChildrenUntilElementFound } from './util.mjs'
const findScrollReference = scrollingElement => {
if (scrollingElement !== null) {

View File

@ -2,11 +2,8 @@
* @module bindings/dom
*/
import { domToType } from './domToType.js'
import { DomBinding } from './DomBinding.js' // eslint-disable-line
import { YXmlHook } from '../../types/YXmlHook.js' // eslint-disable-line
import { YXmlText } from '../../types/YXmlText.js' // eslint-disable-line
import { YXmlElement, YXmlFragment } from '../../types/YXmlElement.js' // eslint-disable-line
import { domToType } from './domToType.mjs'
import { DomBinding } from './DomBinding.mjs' // eslint-disable-line
/**
* Iterates items until an undeleted item is found.

View File

@ -2,17 +2,16 @@
* @module bindings/prosemirror
*/
import { BindMapping } from '../utils/BindMapping.js'
import * as Y from '../index.js'
import { createMutex } from '../lib/mutex.js'
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 * as PModel from 'prosemirror-model'
import { Plugin, PluginKey } from 'prosemirror-state'
import { Decoration, DecorationSet } from 'prosemirror-view'
import { EditorView, Decoration, DecorationSet } from 'prosemirror-view' // eslint-disable-line
import { Plugin, PluginKey, EditorState } from 'prosemirror-state' // eslint-disable-line
/**
* @typedef {import('prosemirror-view').EditorView} EditorView
* @typedef {import('prosemirror-state').EditorState} EditorState
* @typedef {BindMapping<Y.Text | Y.XmlElement, PModel.Node>} ProsemirrorMapping
* @typedef {BindMapping<YText | YXmlElement, PModel.Node>} ProsemirrorMapping
*/
/**
@ -26,7 +25,7 @@ export const prosemirrorPluginKey = new PluginKey('yjs')
* This plugin listens to changes in prosemirror view and keeps yXmlState and view in sync.
*
* This plugin also keeps references to the type and the shared document so other plugins can access it.
* @param {Y.XmlFragment} yXmlFragment
* @param {YXmlFragment} yXmlFragment
* @return {Plugin} Returns a prosemirror plugin that binds to this type
*/
export const prosemirrorPlugin = yXmlFragment => {
@ -132,7 +131,7 @@ export const cursorPlugin = new Plugin({
*/
export class ProsemirrorBinding {
/**
* @param {Y.XmlFragment} yXmlFragment The bind source
* @param {YXmlFragment} yXmlFragment The bind source
* @param {EditorView} prosemirrorView The target binding
*/
constructor (yXmlFragment, prosemirrorView) {
@ -157,7 +156,7 @@ export class ProsemirrorBinding {
let target = event.target
if (target !== this.type) {
do {
if (target.constructor === Y.XmlElement) {
if (target.constructor === YXmlElement) {
createNodeFromYElement(target, this.prosemirrorView.state.schema, this.mapping)
}
target = target._parent
@ -204,7 +203,7 @@ export const createNodeIfNotExists = (el, schema, mapping) => {
export const createNodeFromYElement = (el, schema, mapping) => {
const children = []
el.toArray().forEach(type => {
if (type.constructor === Y.XmlElement) {
if (type.constructor === YXmlElement) {
children.push(createNodeIfNotExists(type, schema, mapping))
} else {
children.concat(createTextNodesFromYText(type, schema, mapping)).forEach(textchild => children.push(textchild))
@ -243,17 +242,17 @@ export const createTextNodesFromYText = (text, schema, mapping) => {
* @private
* @param {PModel.Node} node
* @param {ProsemirrorMapping} mapping
* @return {Y.XmlElement | Y.Text}
* @return {YXmlElement | YText}
*/
export const createTypeFromNode = (node, mapping) => {
let type
if (node.isText) {
type = new Y.Text()
type = new YText()
const attrs = {}
node.marks.forEach(mark => { attrs[mark.type.name] = mark.attrs })
type.insert(0, node.text, attrs)
} else {
type = new Y.XmlElement(node.type.name)
type = new YXmlElement(node.type.name)
for (let key in node.attrs) {
type.setAttribute(key, node.attrs[key])
}
@ -265,7 +264,7 @@ export const createTypeFromNode = (node, mapping) => {
/**
* @private
* @param {Y.XmlFragment} yDomFragment
* @param {YXmlFragment} yDomFragment
* @param {EditorState} state
* @param {BindMapping} mapping
*/

View File

@ -2,7 +2,7 @@
* @module bindings/quill
*/
import { createMutex } from '../lib/mutex.js'
import { createMutex } from '../lib/mutex.mjs'
const typeObserver = function (event) {
const quill = this.target

View File

@ -2,9 +2,9 @@
* @module bindings/textarea
*/
import { simpleDiff } from '../lib/diff.js'
import { getRelativePosition, fromRelativePosition } from '../utils/relativePosition.js'
import { createMutex } from '../lib/mutex.js'
import { simpleDiff } from '../lib/diff.mjs'
import { getRelativePosition, fromRelativePosition } from '../utils/relativePosition.mjs'
import { createMutex } from '../lib/mutex.mjs'
function typeObserver () {
this._mutualExclude(() => {

View File

@ -51,8 +51,6 @@
</div>
<script class="code-js" src="./build/prosemirror.js">
import * as Y from 'yjs'
import { prosemirrorPlugin, cursorPlugin } from 'yjs/bindings/prosemirror.js'
import { WebsocketProvider } from 'yjs/provider/websocket.js'
import { EditorState } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
@ -60,14 +58,14 @@ import { DOMParser } from 'prosemirror-model'
import { schema } from 'prosemirror-schema-basic'
import { exampleSetup } from 'prosemirror-example-setup'
const provider = new WebsocketProvider('ws://localhost:1234/')
const provider = new Y.WebsocketProvider('ws://localhost:1234/')
const ydocument = provider.get('prosemirror')
const type = ydocument.define('prosemirror', Y.XmlFragment)
window.prosemirrorView = new EditorView(document.querySelector('#editor'), {
state: EditorState.create({
doc: DOMParser.fromSchema(schema).parse(document.querySelector('#content')),
plugins: exampleSetup({schema}).concat([prosemirrorPlugin(type), cursorPlugin])
plugins: exampleSetup({schema}).concat([Y.prosemirrorPlugin(type), Y.cursorPlugin])
})
})
</script>

View File

@ -1,6 +1,6 @@
import * as Y from '../index.js'
import { prosemirrorPlugin, cursorPlugin } from '../bindings/prosemirror.js'
import { WebsocketProvider } from '../provider/websocket.js'
import * as Y from '../index.mjs'
import { WebsocketProvider } from '../provider/websocket.mjs'
import { prosemirrorPlugin, cursorPlugin } from '../bindings/prosemirror.mjs'
import { EditorState } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'

View File

@ -1,6 +1,7 @@
import * as Y from '../index.js'
import { QuillBinding } from '../bindings/quill.js'
import { WebsocketProvider } from '../provider/websocket.js'
import * as Y from '../index.mjs'
import { WebsocketProvider } from '../provider/websocket.mjs'
import { QuillBinding } from '../bindings/quill.mjs'
import Quill from 'quill'
const provider = new WebsocketProvider('ws://localhost:1234/')

View File

@ -46,15 +46,13 @@
<textarea style="width:80%;" rows=40 autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
</div>
<script class="code-js" src="./build/textarea.js">
import * as Y from '../index.js'
import { TextareaBinding } from '../bindings/textarea.js'
import { WebsocketProvider } from '../provider/websocket.js'
import * as Y from 'yjs'
const provider = new WebsocketProvider('ws://localhost:1234/')
const provider = new Y.WebsocketProvider('ws://localhost:1234/')
const ydocument = provider.get('textarea')
const type = ydocument.define('textarea', Y.Text)
const textarea = document.querySelector('textarea')
const binding = new TextareaBinding(type, textarea)
const binding = new Y.TextareaBinding(type, textarea)
window.textareaExample = {
provider, ydocument, type, textarea, binding

View File

@ -1,6 +1,6 @@
import * as Y from '../index.js'
import { TextareaBinding } from '../bindings/textarea.js'
import { WebsocketProvider } from '../provider/websocket.js'
import * as Y from '../index.mjs'
import { WebsocketProvider } from '../provider/websocket.mjs'
import { TextareaBinding } from '../bindings/textarea.mjs'
const provider = new WebsocketProvider('ws://localhost:1234/')
const ydocument = provider.get('textarea')

View File

@ -25,7 +25,7 @@
<div id="aceContainer"></div>
<script src="../../y.js"></script>
<script src='../../../y-websockets-client/y-websockets-client.js'></script>
<script src='../../../y-websockets-client/y-websockets-client.mjs'></script>
<script src="../bower_components/ace-builds/src/ace.js"></script>
<script src="./index.js"></script>

View File

@ -13,7 +13,7 @@
<input type="submit" value="Send">
</form>
<script src="../../y.js"></script>
<script src='../../../y-websockets-client/y-websockets-client.js'></script>
<script src='../../../y-websockets-client/y-websockets-client.mjs'></script>
<script src="./index.js"></script>
</body>
</html>

View File

@ -6,7 +6,7 @@
<div id="codeMirrorContainer"></div>
<script src="../../y.js"></script>
<script src='../../../y-websockets-client/y-websockets-client.js'></script>
<script src='../../../y-websockets-client/y-websockets-client.mjs'></script>
<script src="../bower_components/codemirror/lib/codemirror.js"></script>
<script src="../bower_components/codemirror/mode/javascript/javascript.js"></script>
<link rel="stylesheet" href="../bower_components/codemirror/lib/codemirror.css">

View File

@ -13,7 +13,7 @@
<button type="button" id="clearDrawingCanvas">Clear Drawing</button>
<svg id="drawingCanvas" viewbox="0 0 100 100" width="100%"></svg>
<script src="../../y.js"></script>
<script src='../../../y-websockets-client/y-websockets-client.js'></script>
<script src='../../../y-websockets-client/y-websockets-client.mjs'></script>
<script src="../bower_components/d3/d3.min.js"></script>
<script src="./index.js"></script>
</body>

View File

@ -2,7 +2,7 @@
<html>
</head>
<script src="../../y.js"></script>
<script src='../../../y-websockets-client/y-websockets-client.js'></script>
<script src='../../../y-websockets-client/y-websockets-client.mjs'></script>
<script src="../bower_components/d3/d3.min.js"></script>
<script src="./index.js"></script>
<style>

View File

@ -1,12 +1,12 @@
import YWebsocketsConnector from '../../src/Connectors/WebsocketsConnector/WebsocketsConnector.js'
import Y from '../../src/Y.js'
import DomBinding from '../../bindings/DomBinding/DomBinding.js'
import UndoManager from '../../src/Util/UndoManager.js'
import YXmlFragment from '../../src/Types/YXml/YXmlFragment.js'
import YXmlText from '../../src/Types/YXml/YXmlText.js'
import YXmlElement from '../../src/Types/YXml/YXmlElement.js'
import YIndexdDBPersistence from '../../src/Persistences/IndexedDBPersistence.js'
import YWebsocketsConnector from '../../src/Connectors/WebsocketsConnector/WebsocketsConnector.mjs'
import Y from '../../src/Y.mjs'
import DomBinding from '../../bindings/DomBinding/DomBinding.mjs'
import UndoManager from '../../src/Util/UndoManager.mjs'
import YXmlFragment from '../../src/Types/YXml/YXmlFragment.mjs'
import YXmlText from '../../src/Types/YXml/YXmlText.mjs'
import YXmlElement from '../../src/Types/YXml/YXmlElement.mjs'
import YIndexdDBPersistence from '../../src/Persistences/IndexedDBPersistence.mjs'
const connector = new YWebsocketsConnector()
const persistence = new YIndexdDBPersistence()

View File

@ -17,7 +17,7 @@
}
</style>
<script src="../../y.js"></script>
<script src='../../../y-websockets-client/y-websockets-client.js'></script>
<script src='../../../y-websockets-client/y-websockets-client.mjs'></script>
<script src="./index.js"></script>
</body>
</html>

View File

@ -17,7 +17,7 @@
</g>
</svg>
<script src="../../y.js"></script>
<script src='../../../y-websockets-client/y-websockets-client.js'></script>
<script src='../../../y-websockets-client/y-websockets-client.mjs'></script>
<script src="../bower_components/d3/d3.js"></script>
<script src="./index.js"></script>
</body>

View File

@ -14,7 +14,7 @@
}
</style>
<script src="../../y.js"></script>
<script src='../../../y-websockets-client/y-websockets-client.js'></script>
<script src='../../../y-websockets-client/y-websockets-client.mjs'></script>
<script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
<script src="./index.js"></script>
</body>

View File

@ -1,9 +1,9 @@
/* eslint-env browser */
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'
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'
const uuidv4 = () => 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
const r = Math.random() * 16 | 0

View File

@ -1,52 +0,0 @@
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'
export { WebsocketProvider } from './provider/websocket/WebSocketProvider.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)

50
index.mjs Normal file
View File

@ -0,0 +1,50 @@
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)

View File

@ -4,7 +4,7 @@
/* global Buffer */
import * as globals from './globals.js'
import * as globals from './globals.mjs'
/**
* A Decoder handles the decoding of an ArrayBuffer.

View File

@ -1,7 +1,7 @@
/**
* @module encoding
*/
import * as globals from './globals.js'
import * as globals from './globals.mjs'
const bits7 = 0b1111111
const bits8 = 0b11111111

View File

@ -1,4 +1,4 @@
import * as encoding from './encoding.js'
import * as encoding from './encoding.mjs'
/**
* Check if binary encoding is compatible with golang binary encoding - binary.PutVarUint.

View File

@ -4,7 +4,7 @@
/* eslint-env browser */
import * as globals from './globals.js'
import * as globals from './globals.mjs'
/*
* IDB Request to Promise transformer
@ -16,6 +16,8 @@ export const rtop = request => globals.createPromise((resolve, reject) => {
})
/**
* @param {string} name
* @param {Function} initDB Called when the database is first created
* @return {Promise<IDBDatabase>}
*/
export const openDB = (name, initDB) => globals.createPromise((resolve, reject) => {

View File

@ -1,6 +1,6 @@
import * as test from './testing.js'
import * as idb from './idb.js'
import * as logging from './logging.js'
import * as test from './testing.mjs'
import * as idb from './idb.mjs'
import * as logging from './logging.mjs'
const initTestDB = db => idb.createStores(db, [['test']])
const testDBName = 'idb-test'

View File

@ -2,7 +2,7 @@
* @module logging
*/
import * as globals from './globals.js'
import * as globals from './globals.mjs'
let date = new Date().getTime()

View File

@ -2,10 +2,10 @@
* @module prng
*/
import { Mt19937 } from './Mt19937.js'
import { Xoroshiro128plus } from './Xoroshiro128plus.js'
import { Xorshift32 } from './Xorshift32.js'
import * as time from '../../time.js'
import { Mt19937 } from './Mt19937.mjs'
import { Xoroshiro128plus } from './Xoroshiro128plus.mjs'
import { Xorshift32 } from './Xorshift32.mjs'
import * as time from '../../time.mjs'
const DIAMETER = 300
const NUMBERS = 10000

View File

@ -2,7 +2,7 @@
* @module prng
*/
import { Xorshift32 } from './Xorshift32.js'
import { Xorshift32 } from './Xorshift32.mjs'
/**
* This is a variant of xoroshiro128plus - the fastest full-period generator passing BigCrush without systematic failures.

View File

@ -2,12 +2,12 @@
* @module prng
*/
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 * 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.js'
import { Xoroshiro128plus as DefaultPRNG } from './PRNG/Xoroshiro128plus.mjs'
/**
* Description of the function

134
lib/prng/prng.mjs Normal file
View File

@ -0,0 +1,134 @@
/**
* @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<T>} 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)]

View File

@ -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.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''
function init (Gen) {
return {

View File

@ -2,8 +2,8 @@
* @module testing
*/
import * as logging from './logging.js'
import { simpleDiff } from './diff.js'
import * as logging from './logging.mjs'
import { simpleDiff } from './diff.mjs'
export const run = async (name, f) => {
console.log(`%cStart:%c ${name}`, 'color:blue;', '')

7
now.json Normal file
View File

@ -0,0 +1,7 @@
{
"name": "yjs-v13-72",
"engines": {
"node": "10.13.0"
},
"start": "npm run ws-server"
}

View File

@ -1,29 +1,43 @@
{
"name": "yjs",
"version": "13.0.0-72",
"description": "A framework for real-time p2p shared editing on any data",
"main": "./build/yjs.js",
"module": "./index.js",
"description": "A ",
"module": "./index.mjs'",
"sideEffects": false,
"scripts": {
"test": "npm run lint",
"build": "rollup -c",
"build": "rm -rf build && rollup -c",
"watch": "rollup -wc",
"debug": "concurrently 'rollup -wc' 'cutest-serve build/y.test.js -o'",
"lint": "standard **/*.js",
"docs": "rm -rf docs; ! jsdoc --configure ./.jsdoc.json --verbose --readme ./README.md --package ./package.json",
"docs": "rm -rf docs; jsdoc --configure ./.jsdoc.json --verbose --readme ./README.md --package ./package.json || true",
"serve-docs": "npm run docs && serve ./docs/",
"postversion": "npm run build"
"postversion": "npm run build",
"websocket-server": "node --experimental-modules ./provider/websocket/server.mjs"
},
"files": [
"src/*",
".esdoc.json",
".jsdoc.json",
"bindings/*",
"docs/*",
"build/*",
"examples/*",
"lib/*",
"persistences/*",
"protocols/*",
"provider/*",
"bindings/*"
"bindings/*",
"structs/*",
"tests/*",
"types/*",
"utils/*",
"index.js",
"README.md",
"LICENSE"
],
"dictionaries": {
"doc": "docs",
"example": "examples",
"test": "tests",
"lib": "./"
},
"bin": {
"y-websockets": "provider/websocket/server.js"
},
@ -40,13 +54,7 @@
"url": "https://github.com/y-js/yjs.git"
},
"keywords": [
"Yjs",
"OT",
"Collaboration",
"Synchronization",
"ShareJS",
"Coweb",
"Concurrency"
"crdt"
],
"author": "Kevin Jahns",
"email": "kevin.jahns@rwth-aachen.de",

View File

@ -1,10 +1,10 @@
/*
import fs from 'fs'
import path from 'path'
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'
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'
function createFilePath (persistence, roomName) {
// TODO: filename checking!

View File

@ -1,8 +1,8 @@
/*
import { Y } from '../utils/Y.js'
import { createMutex } from '../lib/mutex.js'
import { decodePersisted, encodeStructsDS, encodeUpdate, PERSIST_STRUCTS_DS, PERSIST_UPDATE } from './decodePersisted.js'
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) {

View File

@ -1,7 +1,7 @@
/*
import { integrateRemoteStructs } from '../MessageHandler/integrateRemoteStructs.js'
import { writeStructs } from '../MessageHandler/syncStep1.js'
import { writeDeleteSet, readDeleteSet } from '../MessageHandler/deleteSet.js'
import { integrateRemoteStructs } from '../MessageHandler/integrateRemoteStructs.mjs'
import { writeStructs } from '../MessageHandler/syncStep1.mjs'
import { writeDeleteSet, readDeleteSet } from '../MessageHandler/deleteSet.mjs'
export const PERSIST_UPDATE = 0
/**

View File

@ -2,9 +2,9 @@
* @module awareness-protocol
*/
import * as encoding from '../lib/encoding.js'
import * as decoding from '../lib/decoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line
import * as encoding from '../lib/encoding.mjs'
import * as decoding from '../lib/decoding.mjs'
import { Y } from '../utils/Y.mjs' // eslint-disable-line
const messageUsersStateChanged = 0

View File

@ -2,14 +2,14 @@
* @module sync-protocol
*/
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 '../structs/Delete.js'
import { integrateRemoteStruct } from '../utils/integrateRemoteStructs.js'
import { Y } from '../utils/Y.js' // eslint-disable-line
import { Item } from '../structs/Item.js'
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'
/**
* @typedef {Map<number, number>} 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.js' // eslint-disable-line
// a new user was foundimport { StateSet } from '../Store/StateStore.mjs' // eslint-disable-line
if (currentUser !== null) { // happens on first iteration
encoding.setUint32(encoder, lastLenPos, currentLength)

View File

@ -1,5 +0,0 @@
/**
* @module provider/websocket
*/
export * from './websocket/WebSocketProvider.js'

5
provider/websocket.mjs Normal file
View File

@ -0,0 +1,5 @@
/**
* @module provider/websocket
*/
export * from './websocket/WebSocketProvider.mjs'

View File

@ -4,8 +4,8 @@
/* eslint-env browser */
import * as Y from '../../index.js'
export * from '../../index.js'
import * as Y from '../../index.mjs'
export * from '../../index.mjs'
const messageSync = 0
const messageAwareness = 1

View File

@ -2,8 +2,9 @@
* @module provider/websocket
*/
const Y = require('../../build/yjs.umd.js')
const WebSocket = require('ws')
import * as Y from '../../index.mjs'
import WebSocket from 'ws'
const wss = new WebSocket.Server({ port: 1234 })
const docs = new Map()

View File

@ -2,7 +2,7 @@
* @module provider/ydb
*/
import * as globals from './globals.js'
import * as globals from './globals.mjs'
export const Class = class NamedEventHandler {
constructor () {

View File

@ -3,19 +3,19 @@
*/
/* eslint-env browser */
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 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 NamedEventHandler from './NamedEventHandler.js'
import * as NamedEventHandler from './NamedEventHandler.mjs'
/**
* @typedef RoomState

View File

@ -4,11 +4,11 @@
/* eslint-env browser */
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'
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'
const wsUrl = 'ws://127.0.0.1:8899/ws'
const testRoom = 'testroom'

View File

@ -4,10 +4,10 @@
/* eslint-env browser */
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'
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'
const bc = new BroadcastChannel('ydb-client')
/**
@ -15,7 +15,8 @@ const bc = new BroadcastChannel('ydb-client')
*/
const datasubs = globals.createMap()
/**
* @type {Set<any>} Set of Ydb instances
* Set of Ydb instances
* @type {Set<any>}
*/
const ydbinstances = globals.createSet()

View File

@ -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.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'
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'
/**
* Get 'client-unconfirmed' store from transaction
@ -68,10 +68,16 @@ const getStoreUS = t => idb.getStore(t, STORE_US)
/**
* @param {string} room
* @param {number} offset
* @return {[string, number]}
* @return {HUTableKey}
*/
const encodeHUKey = (room, offset) => [room, offset]
/**
* Array of length 2: [string, number]
* @typedef HUTableKey
* @type {any}
*/
/**
* @typedef RoomAndOffset
* @type {Object}
@ -80,7 +86,7 @@ const encodeHUKey = (room, offset) => [room, offset]
*/
/**
* @param {[string, number]} key
* @param {HUTableKey} key
* @return {RoomAndOffset}
*/
const decodeHUKey = key => {

View File

@ -1,6 +1,6 @@
import * as globals from '../../lib/globals.js'
import * as idbactions from './idbactions.js'
import * as test from '../../lib/testing.js'
import * as globals from '../../lib/globals.mjs'
import * as idbactions from './idbactions.mjs'
import * as test from '../../lib/testing.mjs'
idbactions.deleteDB().then(() => idbactions.openDB()).then(db => {
test.run('update lifetime 1', async (testname) => {

View File

@ -2,7 +2,7 @@
* @module provider/ydb
*/
import * as ydbclient from './YdbClient.js'
import * as ydbclient from './YdbClient.mjs'
/**
* @param {string} url

View File

@ -2,11 +2,11 @@
* @module provider/ydb
*/
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'
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'
/* make sure to update message.go in ydb when updating these values.. */
export const MESSAGE_UPDATE = 0 // TODO: rename host_unconfirmed?

View File

@ -4,17 +4,17 @@ import babel from 'rollup-plugin-babel'
import uglify from 'rollup-plugin-uglify-es'
export default [{
input: './index.js',
output: {
input: './index.mjs',
output: [{
name: 'Y',
file: 'build/yjs.umd.js',
format: 'umd',
file: 'build/yjs.js',
format: 'cjs',
sourcemap: true
}
}]
}, {
input: 'tests/index.js',
input: 'tests/index.mjs',
output: {
file: 'build/y.test.js',
file: 'build/y.test.mjs',
format: 'iife',
name: 'ytests',
sourcemap: true
@ -27,7 +27,7 @@ export default [{
commonjs()
]
}, {
input: './examples/prosemirror.js',
input: './examples/prosemirror.mjs',
output: {
name: 'prosemirror',
file: 'examples/build/prosemirror.js',
@ -44,7 +44,7 @@ export default [{
uglify()
]
}, {
input: './examples/textarea.js',
input: './examples/textarea.mjs',
output: {
name: 'textarea',
file: 'examples/build/textarea.js',
@ -52,16 +52,10 @@ export default [{
sourcemap: true
},
plugins: [
nodeResolve({
sourcemap: true,
module: true
}),
commonjs(),
babel(),
uglify()
]
}, {
input: './examples/quill.js',
input: './examples/quill.mjs',
output: {
name: 'textarea',
file: 'examples/build/quill.js',

View File

@ -2,47 +2,15 @@
* @module structs
*/
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
/**
* @private
* Delete all items in an ID-range.
* Does not create delete operations!
* TODO: implement getItemCleanStartNode for better performance (only one lookup).
*/
export const deleteItemRange = (y, user, clock, range, gcChildren) => {
let item = y.os.getItemCleanStart(ID.createID(user, clock))
if (item !== null) {
if (!item._deleted) {
item._splitAt(y, range)
item._delete(y, false, true)
}
let itemLen = item._length
range -= itemLen
clock += itemLen
if (range > 0) {
let node = y.os.findNode(ID.createID(user, clock))
while (node !== null && node.val !== null && range > 0 && node.val._id.equals(ID.createID(user, clock))) {
const nodeVal = node.val
if (!nodeVal._deleted) {
nodeVal._splitAt(y, range)
nodeVal._delete(y, false, gcChildren)
}
const nodeLen = nodeVal._length
range -= nodeLen
clock += nodeLen
node = node.next()
}
}
}
}
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'
/**
* @private

View File

@ -2,12 +2,12 @@
* @module structs
*/
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
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
// TODO should have the same base class as Item
export class GC {

View File

@ -2,15 +2,15 @@
* @module structs
*/
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
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
/**
* @private

View File

@ -2,11 +2,11 @@
* @module structs
*/
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
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
export class ItemEmbed extends Item {
constructor () {

View File

@ -2,11 +2,11 @@
* @module structs
*/
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
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
export class ItemFormat extends Item {
constructor () {

View File

@ -2,11 +2,11 @@
* @module structs
*/
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
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
export class ItemJSON extends Item {
constructor () {

View File

@ -2,11 +2,11 @@
* @module structs
*/
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
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
export class ItemString extends Item {
constructor () {

View File

@ -2,11 +2,11 @@
* @module structs
*/
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
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
// restructure children as if they were inserted one after another
const integrateChildren = (y, start) => {

View File

@ -1,7 +1,7 @@
import { test } from 'cutest'
import * as random from '../lib/prng/prng.js'
import { DeleteStore } from '../utils/DeleteStore.js'
import * as ID from '../utils/ID.js'
import * as random from '../lib/prng/prng.mjs'
import { DeleteStore } from '../utils/DeleteStore.mjs'
import * as ID from '../utils/ID.mjs'
/**
* Converts a DS to an array of length 10.

View File

@ -1,6 +1,6 @@
import { test } from 'cutest'
import { simpleDiff } from '../lib/diff.js'
import * as random from '../lib/prng/prng.js'
import { simpleDiff } from '../lib/diff.mjs'
import * as random from '../lib/prng/prng.mjs'
function runDiffTest (t, a, b, expected) {
let result = simpleDiff(a, b)

View File

@ -1,8 +1,8 @@
import { test } from 'cutest'
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'
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'
function testEncoding (t, write, read, val) {
let encoder = encoding.createEncoder()

View File

@ -1,19 +1,19 @@
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 * as Y from '../index.mjs'
import { ItemJSON } from '../structs/ItemJSON.mjs'
import { ItemString } from '../structs/ItemString.mjs'
import { defragmentItemContent } from '../utils/defragmentItemContent.mjs'
import Quill from 'quill'
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'
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'
export * from '../index.js'
export * from '../index.mjs'
/**
* @param {TestYInstance} y

View File

@ -1,9 +0,0 @@
// 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'

9
tests/index.mjs Normal file
View File

@ -0,0 +1,9 @@
// 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'

View File

@ -1,8 +1,8 @@
import { test } from 'cutest'
import * as random from '../lib/prng/prng.js'
import * as Y from '../index.js'
import * as random from '../lib/prng/prng.mjs'
import * as Y from '../index.mjs'
import { prosemirrorPlugin } from '../bindings/prosemirror.js'
import { prosemirrorPlugin } from '../bindings/prosemirror.mjs'
import {EditorState} from 'prosemirror-state'
import {EditorView} from 'prosemirror-view'
import {schema} from 'prosemirror-schema-basic'

View File

@ -1,7 +1,7 @@
import { Tree as RedBlackTree } from '../lib/Tree.js'
import * as ID from '../utils/ID.js'
import { Tree as RedBlackTree } from '../lib/Tree.mjs'
import * as ID from '../utils/ID.mjs'
import { test, proxyConsole } from 'cutest'
import * as random from '../lib/prng/prng.js'
import * as random from '../lib/prng/prng.mjs'
proxyConsole()

View File

@ -1,7 +1,7 @@
import { initArrays, compareUsers, applyRandomTests } from './helper.js'
import * as Y from '../index.js'
import { initArrays, compareUsers, applyRandomTests } from './helper.mjs'
import * as Y from '../index.mjs'
import { test, proxyConsole } from 'cutest'
import * as random from '../lib/prng/prng.js'
import * as random from '../lib/prng/prng.mjs'
proxyConsole()
test('basic spec', async function array0 (t) {

View File

@ -1,7 +1,7 @@
import { initArrays, compareUsers, applyRandomTests } from './helper.js'
import * as Y from '../index.js'
import { initArrays, compareUsers, applyRandomTests } from './helper.mjs'
import * as Y from '../index.mjs'
import { test, proxyConsole } from 'cutest'
import * as random from '../lib/prng/prng.js'
import * as random from '../lib/prng/prng.mjs'
proxyConsole()

View File

@ -1,4 +1,4 @@
import { initArrays, compareUsers } from './helper.js'
import { initArrays, compareUsers } from './helper.mjs'
import { test, proxyConsole } from 'cutest'
proxyConsole()

View File

@ -1,7 +1,7 @@
import { initArrays, compareUsers, applyRandomTests } from './helper.js'
import { initArrays, compareUsers, applyRandomTests } from './helper.mjs'
import { test } from 'cutest'
import * as Y from '../index.js'
import * as random from '../lib/prng/prng.js'
import * as Y from '../index.mjs'
import * as random from '../lib/prng/prng.mjs'
test('set property', async function xml0 (t) {
var { testConnector, users, xml0, xml1 } = await initArrays(t, { users: 2 })

View File

@ -2,13 +2,13 @@
* @module types
*/
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
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
/**
* Event that describes the changes on a YArray
@ -73,8 +73,9 @@ export class YArrayEvent extends YEvent {
*/
export class YArray extends Type {
/**
* @private
* Creates YArray Event and calls observers.
*
* @private
*/
_callObserver (transaction, parentSubs, remote) {
this._callEventHandler(transaction, new YArrayEvent(this, remote, transaction))
@ -243,9 +244,9 @@ export class YArray extends Type {
}
/**
* @private
* Inserts content after an element container.
*
* @private
* @param {Item} left The element container to use as a reference.
* @param {Array} content The Array of content to insert (see {@see insert})
*/

View File

@ -2,11 +2,11 @@
* @module types
*/
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'
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'
/**
* Event that describes the changes on a YMap.
@ -29,8 +29,9 @@ export class YMapEvent extends YEvent {
*/
export class YMap extends Type {
/**
* @private
* Creates YMap Event and calls observers.
*
* @private
*/
_callObserver (transaction, parentSubs, remote) {
this._callEventHandler(transaction, new YMapEvent(this, parentSubs, remote))

View File

@ -2,11 +2,11 @@
* @module types
*/
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'
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'
/**
* @private
@ -464,7 +464,7 @@ class YTextEvent extends YArrayEvent {
*/
export class YText extends YArray {
/**
* @param {String} string The initial value of the YText.
* @param {String} [string] The initial value of the YText.
*/
constructor (string) {
super()
@ -477,8 +477,9 @@ export class YText extends YArray {
}
/**
* @private
* Creates YMap Event and calls observers.
*
* @private
*/
_callObserver (transaction, parentSubs, remote) {
this._callEventHandler(transaction, new YTextEvent(this, remote, transaction))

Some files were not shown because too many files have changed in this diff Show More