Compare commits

..

1 Commits

Author SHA1 Message Date
Kevin Jahns
0fdf4b307b v13.0.0-17 -- distribution files 2017-09-11 17:40:04 +02:00
13 changed files with 23964 additions and 112 deletions

View File

@@ -4,7 +4,8 @@
<textarea style="width:80%;" rows=40 id="textfield" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
<script src="../../y.js"></script>
<script src="../../../y-array/y-array.js"></script>
<script src="../../../y-text/y-text.js"></script>
<script src="../../../y-text/dist/y-text.js"></script>
<script src="../../../y-memory/y-memory.js"></script>
<script src="../../../y-websockets-client/y-websockets-client.js"></script>
<script src="./index.js"></script>
</body>

View File

@@ -1,5 +1,8 @@
/* global Y */
// eslint-disable-next-line
let search = new URLSearchParams(location.search)
// initialize a shared object. This function call returns a promise!
Y({
db: {
@@ -7,9 +10,10 @@ Y({
},
connector: {
name: 'websockets-client',
room: 'Textarea-example2',
room: 'Textarea-example',
// url: '//localhost:1234',
url: 'https://yjs-v13.herokuapp.com/'
// options: { transports: ['websocket'], upgrade: false }
},
share: {
textarea: 'Text'
@@ -20,4 +24,7 @@ Y({
// bind the textarea to a shared text element
y.share.textarea.bind(document.getElementById('textfield'))
// thats it..
}).catch(() => {
console.log('Something went wrong while creating the instance..')
})

View File

@@ -1,6 +1,6 @@
{
"name": "yjs",
"version": "13.0.0-18",
"version": "13.0.0-17",
"description": "A framework for real-time p2p shared editing on any data",
"main": "./y.node.js",
"browser": "./y.js",

View File

@@ -67,11 +67,7 @@ export default function Utils (Y) {
this._eventListener[name] = listener.filter(e => e !== f)
}
emit (name, value) {
let listener = this._eventListener[name] || []
if (name === 'error' && listener.length === 0) {
console.error(value)
}
listener.forEach(l => l(value))
(this._eventListener[name] || []).forEach(l => l(value))
}
destroy () {
this._eventListener = null

View File

@@ -1,3 +1,4 @@
import extendRBTree from './RedBlackTree'
export default function extend (Y) {
@@ -47,13 +48,9 @@ export default function extend (Y) {
}
transact (makeGen) {
const t = new Transaction(this)
try {
while (makeGen != null) {
makeGen.call(t)
makeGen = this.getNextRequest()
}
} catch (e) {
this.y.emit('error', e)
while (makeGen != null) {
makeGen.call(t)
makeGen = this.getNextRequest()
}
}
destroy () {

View File

@@ -224,65 +224,16 @@ test('move element to a different position', async function xml13 (t) {
await compareUsers(t, users)
})
test('filter node', async function xml14 (t) {
var { users, xml0, xml1 } = await initArrays(t, { users: 3 })
let dom0 = xml0.getDom()
let dom1 = xml1.getDom()
let domFilter = (node, attrs) => {
if (node.nodeName === 'H1') {
return null
} else {
return attrs
}
}
xml0.setDomFilter(domFilter)
xml1.setDomFilter(domFilter)
dom0.append(document.createElement('div'))
dom0.append(document.createElement('h1'))
await flushAll(t, users)
t.assert(dom1.childNodes.length === 1, 'Only one node was not transmitted')
t.assert(dom1.childNodes[0].nodeName === 'DIV', 'div node was transmitted')
await compareUsers(t, users)
})
test('filter attribute', async function xml15 (t) {
var { users, xml0, xml1 } = await initArrays(t, { users: 3 })
let dom0 = xml0.getDom()
let dom1 = xml1.getDom()
let domFilter = (node, attrs) => {
return attrs.filter(name => name !== 'hidden')
}
xml0.setDomFilter(domFilter)
xml1.setDomFilter(domFilter)
dom0.setAttribute('hidden', 'true')
dom0.setAttribute('style', 'height: 30px')
dom0.setAttribute('data-me', '77')
await flushAll(t, users)
t.assert(dom0.getAttribute('hidden') === 'true', 'User 0 still has the attribute')
t.assert(dom1.getAttribute('hidden') == null, 'User 1 did not receive update')
t.assert(dom1.getAttribute('style') === 'height: 30px', 'User 1 received style update')
t.assert(dom1.getAttribute('data-me') === '77', 'User 1 received data update')
await compareUsers(t, users)
})
// TODO: move elements
var xmlTransactions = [
function attributeChange (t, user, chance) {
user.share.xml.getDom().setAttribute(chance.word(), chance.word())
},
function attributeChangeHidden (t, user, chance) {
user.share.xml.getDom().setAttribute('hidden', chance.word())
},
function insertText (t, user, chance) {
let dom = user.share.xml.getDom()
var succ = dom.children.length > 0 ? chance.pickone(dom.children) : null
dom.insertBefore(document.createTextNode(chance.word()), succ)
},
function insertHiddenDom (t, user, chance) {
let dom = user.share.xml.getDom()
var succ = dom.children.length > 0 ? chance.pickone(dom.children) : null
dom.insertBefore(document.createElement('hidden'), succ)
},
function insertDom (t, user, chance) {
let dom = user.share.xml.getDom()
var succ = dom.children.length > 0 ? chance.pickone(dom.children) : null
@@ -323,30 +274,30 @@ var xmlTransactions = [
}
]
test('y-xml: Random tests (10)', async function xmlRandom10 (t) {
test('y-xml: Random tests (10)', async function randomXml10 (t) {
await applyRandomTests(t, xmlTransactions, 10)
})
test('y-xml: Random tests (42)', async function xmlRandom42 (t) {
test('y-xml: Random tests (42)', async function randomXml42 (t) {
await applyRandomTests(t, xmlTransactions, 42)
})
test('y-xml: Random tests (43)', async function xmlRandom43 (t) {
test('y-xml: Random tests (43)', async function randomXml43 (t) {
await applyRandomTests(t, xmlTransactions, 43)
})
test('y-xml: Random tests (44)', async function xmlRandom44 (t) {
test('y-xml: Random tests (44)', async function randomXml44 (t) {
await applyRandomTests(t, xmlTransactions, 44)
})
test('y-xml: Random tests (45)', async function xmlRandom45 (t) {
test('y-xml: Random tests (45)', async function randomXml45 (t) {
await applyRandomTests(t, xmlTransactions, 45)
})
test('y-xml: Random tests (46)', async function xmlRandom46 (t) {
test('y-xml: Random tests (46)', async function randomXml46 (t) {
await applyRandomTests(t, xmlTransactions, 46)
})
test('y-xml: Random tests (47)', async function xmlRandom47 (t) {
test('y-xml: Random tests (47)', async function randomXml47 (t) {
await applyRandomTests(t, xmlTransactions, 47)
})

View File

@@ -2,7 +2,7 @@
import _Y from '../../yjs/src/y.js'
import yArray from '../../y-array/src/y-array.js'
import yText from '../../y-text/src/y-text.js'
import yText from '../../y-text/src/Text.js'
import yMap from '../../y-map/src/y-map.js'
import yXml from '../../y-xml/src/y-xml.js'
import yTest from './test-connector.js'
@@ -48,17 +48,11 @@ export async function garbageCollectUsers (t, users) {
await Promise.all(users.map(u => u.db.emptyGarbageCollector()))
}
export function attrsObject (dom) {
let keys = []
let yxml = dom.__yxml
for (let i = 0; i < dom.attributes.length; i++) {
keys.push(dom.attributes[i].name)
}
keys = yxml._domFilter(dom, keys)
export function attrsToObject (attrs) {
let obj = {}
for (let i = 0; i < keys.length; i++) {
let key = keys[i]
obj[key] = dom.getAttribute(key)
for (var i = 0; i < attrs.length; i++) {
let attr = attrs[i]
obj[attr.name] = attr.value
}
return obj
}
@@ -67,10 +61,8 @@ export function domToJson (dom) {
if (dom.nodeType === document.TEXT_NODE) {
return dom.textContent
} else if (dom.nodeType === document.ELEMENT_NODE) {
let attributes = attrsObject(dom, dom.__yxml)
let children = Array.from(dom.childNodes.values())
.filter(d => d.__yxml !== false)
.map(domToJson)
let attributes = attrsToObject(dom.attributes)
let children = Array.from(dom.childNodes.values()).map(domToJson)
return {
name: dom.nodeName,
children: children,
@@ -206,13 +198,6 @@ export async function initArrays (t, opts) {
for (let name in share) {
result[name + i] = y.share[name]
}
y.share.xml.setDomFilter(function (d, attrs) {
if (d.nodeName === 'HIDDEN') {
return null
} else {
return attrs.filter(a => a !== 'hidden')
}
})
}
result.array0.delete(0, result.array0.length)
if (result.users[0].connector.testRoom != null) {

8
y.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
/**
* yjs - A framework for real-time p2p shared editing on any data
* @version v13.0.0-18
* @version v13.0.0-17
* @license MIT
*/
@@ -3452,11 +3452,7 @@ function Utils (Y) {
this._eventListener[name] = listener.filter(e => e !== f);
}
emit (name, value) {
let listener = this._eventListener[name] || [];
if (name === 'error' && listener.length === 0) {
console.error(value);
}
listener.forEach(l => l(value));
(this._eventListener[name] || []).forEach(l => l(value));
}
destroy () {
this._eventListener = null;
@@ -4797,13 +4793,9 @@ function extend (Y) {
}
transact (makeGen) {
const t = new Transaction(this);
try {
while (makeGen != null) {
makeGen.call(t);
makeGen = this.getNextRequest();
}
} catch (e) {
this.y.emit('error', e);
while (makeGen != null) {
makeGen.call(t);
makeGen = this.getNextRequest();
}
}
destroy () {

File diff suppressed because one or more lines are too long

23922
y.test.js Normal file

File diff suppressed because one or more lines are too long

1
y.test.js.map Normal file

File diff suppressed because one or more lines are too long