Compare commits
7 Commits
v13.0.0-32
...
v13.0.0-35
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a282c340b3 | ||
|
|
7808b143da | ||
|
|
b35092928e | ||
|
|
b7dbcf69d3 | ||
|
|
377df18788 | ||
|
|
26a323733d | ||
|
|
d0d1015074 |
@@ -14,10 +14,7 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script src="../bower_components/yjs/y.js"></script>
|
<script src="../bower_components/yjs/y.js"></script>
|
||||||
<script src="../bower_components/y-array/y-array.js"></script>
|
|
||||||
<script src="../bower_components/y-text/y-text.js"></script>
|
|
||||||
<script src="../bower_components/y-websockets-client/y-websockets-client.js"></script>
|
<script src="../bower_components/y-websockets-client/y-websockets-client.js"></script>
|
||||||
<script src="../bower_components/y-memory/y-memory.js"></script>
|
|
||||||
<script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
|
<script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
|
||||||
<script src="./index.js"></script>
|
<script src="./index.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.0.0-32",
|
"version": "13.0.0-35",
|
||||||
"description": "A framework for real-time p2p shared editing on any data",
|
"description": "A framework for real-time p2p shared editing on any data",
|
||||||
"main": "./y.node.js",
|
"main": "./y.node.js",
|
||||||
"browser": "./y.js",
|
"browser": "./y.js",
|
||||||
@@ -15,7 +15,8 @@
|
|||||||
"postpublish": "tag-dist-files --overwrite-existing-tag"
|
"postpublish": "tag-dist-files --overwrite-existing-tag"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"y.*"
|
"y.*",
|
||||||
|
"src/*"
|
||||||
],
|
],
|
||||||
"standard": {
|
"standard": {
|
||||||
"ignore": [
|
"ignore": [
|
||||||
|
|||||||
@@ -34,16 +34,15 @@ export default class YXmlElement extends YXmlFragment {
|
|||||||
} else {
|
} else {
|
||||||
// tag is already set in constructor
|
// tag is already set in constructor
|
||||||
// set attributes
|
// set attributes
|
||||||
let attrNames = []
|
let attributes = new Map()
|
||||||
for (let i = 0; i < dom.attributes.length; i++) {
|
for (let i = 0; i < dom.attributes.length; i++) {
|
||||||
attrNames.push(dom.attributes[i].name)
|
let attr = dom.attributes[i]
|
||||||
}
|
attributes.set(attr.name, attr.value)
|
||||||
attrNames = this._domFilter(dom, attrNames)
|
|
||||||
for (let i = 0; i < attrNames.length; i++) {
|
|
||||||
let attrName = attrNames[i]
|
|
||||||
let attrValue = dom.getAttribute(attrName)
|
|
||||||
this.setAttribute(attrName, attrValue)
|
|
||||||
}
|
}
|
||||||
|
attributes = this._domFilter(dom, attributes)
|
||||||
|
attributes.forEach((value, name) => {
|
||||||
|
this.setAttribute(name, value)
|
||||||
|
})
|
||||||
this.insertDomElements(0, Array.prototype.slice.call(dom.childNodes), _document)
|
this.insertDomElements(0, Array.prototype.slice.call(dom.childNodes), _document)
|
||||||
this._bindToDom(dom, _document)
|
this._bindToDom(dom, _document)
|
||||||
return dom
|
return dom
|
||||||
@@ -104,7 +103,9 @@ export default class YXmlElement extends YXmlFragment {
|
|||||||
getAttributes () {
|
getAttributes () {
|
||||||
const obj = {}
|
const obj = {}
|
||||||
for (let [key, value] of this._map) {
|
for (let [key, value] of this._map) {
|
||||||
obj[key] = value._content[0]
|
if (!value._deleted) {
|
||||||
|
obj[key] = value._content[0]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ function domToYXml (parent, doms, _document) {
|
|||||||
if (d._yxml != null && d._yxml !== false) {
|
if (d._yxml != null && d._yxml !== false) {
|
||||||
d._yxml._unbindFromDom()
|
d._yxml._unbindFromDom()
|
||||||
}
|
}
|
||||||
if (parent._domFilter(d, []) !== null) {
|
if (parent._domFilter(d.nodeName, new Map()) !== null) {
|
||||||
let type
|
let type
|
||||||
if (d.nodeType === d.TEXT_NODE) {
|
if (d.nodeType === d.TEXT_NODE) {
|
||||||
type = new YXmlText(d)
|
type = new YXmlText(d)
|
||||||
@@ -203,6 +203,52 @@ export default class YXmlFragment extends YArray {
|
|||||||
}
|
}
|
||||||
this._y.on('beforeTransaction', beforeTransactionSelectionFixer)
|
this._y.on('beforeTransaction', beforeTransactionSelectionFixer)
|
||||||
this._y.on('afterTransaction', afterTransactionSelectionFixer)
|
this._y.on('afterTransaction', afterTransactionSelectionFixer)
|
||||||
|
const applyFilter = (type) => {
|
||||||
|
if (type._deleted) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// check if type is a child of this
|
||||||
|
let isChild = false
|
||||||
|
let p = type
|
||||||
|
while (p !== this._y) {
|
||||||
|
if (p === this) {
|
||||||
|
isChild = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
p = p._parent
|
||||||
|
}
|
||||||
|
if (!isChild) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// filter attributes
|
||||||
|
let attributes = new Map()
|
||||||
|
if (type.getAttributes !== undefined) {
|
||||||
|
let attrs = type.getAttributes()
|
||||||
|
for (let key in attrs) {
|
||||||
|
attributes.set(key, attrs[key])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let result = this._domFilter(type.nodeName, new Map(attributes))
|
||||||
|
if (result === null) {
|
||||||
|
type._delete(this._y)
|
||||||
|
} else {
|
||||||
|
attributes.forEach((value, key) => {
|
||||||
|
if (!result.has(key)) {
|
||||||
|
type.removeAttribute(key)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._y.on('beforeObserverCalls', function (y, transaction) {
|
||||||
|
// apply dom filter to new and changed types
|
||||||
|
transaction.changedTypes.forEach(function (subs, type) {
|
||||||
|
if (subs.size > 1 || !subs.has(null)) {
|
||||||
|
// only apply changes on attributes
|
||||||
|
applyFilter(type)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
transaction.newTypes.forEach(applyFilter)
|
||||||
|
})
|
||||||
// Apply Y.Xml events to dom
|
// Apply Y.Xml events to dom
|
||||||
this.observeDeep(events => {
|
this.observeDeep(events => {
|
||||||
reflectChangesOnDom.call(this, events, _document)
|
reflectChangesOnDom.call(this, events, _document)
|
||||||
@@ -240,10 +286,15 @@ export default class YXmlFragment extends YArray {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'attributes':
|
case 'attributes':
|
||||||
|
if (yxml.constructor === YXmlFragment) {
|
||||||
|
break
|
||||||
|
}
|
||||||
let name = mutation.attributeName
|
let name = mutation.attributeName
|
||||||
|
let val = dom.getAttribute(name)
|
||||||
// check if filter accepts attribute
|
// check if filter accepts attribute
|
||||||
if (this._domFilter(dom, [name]).length > 0 && yxml.constructor !== YXmlFragment) {
|
let attributes = new Map()
|
||||||
var val = dom.getAttribute(name)
|
attributes.set(name, val)
|
||||||
|
if (this._domFilter(dom.nodeName, attributes).size > 0 && yxml.constructor !== YXmlFragment) {
|
||||||
if (yxml.getAttribute(name) !== val) {
|
if (yxml.getAttribute(name) !== val) {
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
yxml.removeAttribute(name)
|
yxml.removeAttribute(name)
|
||||||
|
|||||||
51
src/Type/y-xml/domFilter.js
Normal file
51
src/Type/y-xml/domFilter.js
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
|
||||||
|
const filterMap = new Map()
|
||||||
|
|
||||||
|
export function addFilter (type, filter) {
|
||||||
|
if (!filterMap.has(type)) {
|
||||||
|
filterMap.set(type, new Set())
|
||||||
|
}
|
||||||
|
const filters = filterMap.get(type)
|
||||||
|
filters.add(filter)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function executeFilter (type) {
|
||||||
|
const y = type._y
|
||||||
|
let parent = type
|
||||||
|
const nodeName = type.nodeName
|
||||||
|
let attributes = new Map()
|
||||||
|
if (type.getAttributes !== undefined) {
|
||||||
|
let attrs = type.getAttributes()
|
||||||
|
for (let key in attrs) {
|
||||||
|
attributes.set(key, attrs[key])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let filteredAttributes = new Map(attributes)
|
||||||
|
// is not y, supports dom filtering
|
||||||
|
while (parent !== y && parent.setDomFilter != null) {
|
||||||
|
const filters = filterMap.get(parent)
|
||||||
|
if (filters !== undefined) {
|
||||||
|
for (let f of filters) {
|
||||||
|
filteredAttributes = f(nodeName, filteredAttributes)
|
||||||
|
if (filteredAttributes === null) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (filteredAttributes === null) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parent = parent._parent
|
||||||
|
}
|
||||||
|
if (filteredAttributes === null) {
|
||||||
|
type._delete(y)
|
||||||
|
} else {
|
||||||
|
// iterate original attributes
|
||||||
|
attributes.forEach((value, key) => {
|
||||||
|
// delete all attributes that are not in filteredAttributes
|
||||||
|
if (!filteredAttributes.has(key)) {
|
||||||
|
type.removeAttribute(key)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,20 +46,29 @@ export function afterTransactionSelectionFixer (y, transaction, remote) {
|
|||||||
if (from !== null) {
|
if (from !== null) {
|
||||||
let sel = fromRelativePosition(fromY, from)
|
let sel = fromRelativePosition(fromY, from)
|
||||||
if (sel !== null) {
|
if (sel !== null) {
|
||||||
shouldUpdate = true
|
let node = sel.type.getDom()
|
||||||
anchorNode = sel.type.getDom()
|
let offset = sel.offset
|
||||||
anchorOffset = sel.offset
|
if (node !== anchorNode || offset !== anchorOffset) {
|
||||||
|
anchorNode = node
|
||||||
|
anchorOffset = offset
|
||||||
|
shouldUpdate = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (to !== null) {
|
if (to !== null) {
|
||||||
let sel = fromRelativePosition(toY, to)
|
let sel = fromRelativePosition(toY, to)
|
||||||
if (sel !== null) {
|
if (sel !== null) {
|
||||||
focusNode = sel.type.getDom()
|
let node = sel.type.getDom()
|
||||||
focusOffset = sel.offset
|
let offset = sel.offset
|
||||||
shouldUpdate = true
|
if (node !== focusNode || offset !== focusOffset) {
|
||||||
|
focusNode = node
|
||||||
|
focusOffset = offset
|
||||||
|
shouldUpdate = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (shouldUpdate) {
|
if (shouldUpdate) {
|
||||||
|
console.info('updating selection!!')
|
||||||
browserSelection.setBaseAndExtent(
|
browserSelection.setBaseAndExtent(
|
||||||
anchorNode,
|
anchorNode,
|
||||||
anchorOffset,
|
anchorOffset,
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ export function getRelativePosition (type, offset) {
|
|||||||
} else {
|
} else {
|
||||||
let t = type._start
|
let t = type._start
|
||||||
while (t !== null) {
|
while (t !== null) {
|
||||||
if (t._length >= offset) {
|
if (t._deleted === false) {
|
||||||
return [t._id.user, t._id.clock + offset - 1]
|
if (t._length >= offset) {
|
||||||
}
|
return [t._id.user, t._id.clock + offset - 1]
|
||||||
if (t._right === null) {
|
}
|
||||||
return [t._id.user, t._id.clock + t._length - 1]
|
if (t._right === null) {
|
||||||
}
|
return [t._id.user, t._id.clock + t._length - 1]
|
||||||
if (!t._deleted) {
|
}
|
||||||
offset -= t._length
|
offset -= t._length
|
||||||
}
|
}
|
||||||
t = t._right
|
t = t._right
|
||||||
|
|||||||
12
src/Y.js
12
src/Y.js
@@ -54,6 +54,7 @@ export default class Y extends NamedEventHandler {
|
|||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
if (initialCall) {
|
if (initialCall) {
|
||||||
|
this.emit('beforeObserverCalls', this, this._transaction, remote)
|
||||||
const transaction = this._transaction
|
const transaction = this._transaction
|
||||||
this._transaction = null
|
this._transaction = null
|
||||||
// emit change events on changed types
|
// emit change events on changed types
|
||||||
@@ -94,17 +95,10 @@ export default class Y extends NamedEventHandler {
|
|||||||
define (name, TypeConstructor) {
|
define (name, TypeConstructor) {
|
||||||
let id = new RootID(name, TypeConstructor)
|
let id = new RootID(name, TypeConstructor)
|
||||||
let type = this.os.get(id)
|
let type = this.os.get(id)
|
||||||
if (type === null) {
|
|
||||||
type = new TypeConstructor()
|
|
||||||
type._id = id
|
|
||||||
type._parent = this
|
|
||||||
type._integrate(this)
|
|
||||||
if (this.share[name] !== undefined) {
|
|
||||||
throw new Error('Type is already defined with a different constructor!')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.share[name] === undefined) {
|
if (this.share[name] === undefined) {
|
||||||
this.share[name] = type
|
this.share[name] = type
|
||||||
|
} else if (this.share[name] !== type) {
|
||||||
|
throw new Error('Type is already defined with a different constructor')
|
||||||
}
|
}
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,8 +230,8 @@ test('filter node', async function xml14 (t) {
|
|||||||
var { users, xml0, xml1 } = await initArrays(t, { users: 3 })
|
var { users, xml0, xml1 } = await initArrays(t, { users: 3 })
|
||||||
let dom0 = xml0.getDom()
|
let dom0 = xml0.getDom()
|
||||||
let dom1 = xml1.getDom()
|
let dom1 = xml1.getDom()
|
||||||
let domFilter = (node, attrs) => {
|
let domFilter = (nodeName, attrs) => {
|
||||||
if (node.nodeName === 'H1') {
|
if (nodeName === 'H1') {
|
||||||
return null
|
return null
|
||||||
} else {
|
} else {
|
||||||
return attrs
|
return attrs
|
||||||
@@ -251,8 +251,9 @@ test('filter attribute', async function xml15 (t) {
|
|||||||
var { users, xml0, xml1 } = await initArrays(t, { users: 3 })
|
var { users, xml0, xml1 } = await initArrays(t, { users: 3 })
|
||||||
let dom0 = xml0.getDom()
|
let dom0 = xml0.getDom()
|
||||||
let dom1 = xml1.getDom()
|
let dom1 = xml1.getDom()
|
||||||
let domFilter = (node, attrs) => {
|
let domFilter = (nodeName, attrs) => {
|
||||||
return attrs.filter(name => name !== 'hidden')
|
attrs.delete('hidden')
|
||||||
|
return attrs
|
||||||
}
|
}
|
||||||
xml0.setDomFilter(domFilter)
|
xml0.setDomFilter(domFilter)
|
||||||
xml1.setDomFilter(domFilter)
|
xml1.setDomFilter(domFilter)
|
||||||
@@ -303,6 +304,51 @@ test('treeWalker', async function xml17 (t) {
|
|||||||
await compareUsers(t, users)
|
await compareUsers(t, users)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The expected behavior is that changes on your own dom (e.g. malicious attributes) persist.
|
||||||
|
* Yjs should just ignore them, never propagate those attributes.
|
||||||
|
* Incoming changes that contain malicious attributes should be deleted.
|
||||||
|
*/
|
||||||
|
test('Filtering remote changes', async function xmlFilteringRemote (t) {
|
||||||
|
var { users, xml0, xml1 } = await initArrays(t, { users: 3 })
|
||||||
|
xml0.setDomFilter(function (nodeName, attributes) {
|
||||||
|
attributes.delete('malicious')
|
||||||
|
if (nodeName === 'HIDEME') {
|
||||||
|
return null
|
||||||
|
} else if (attributes.has('isHidden')) {
|
||||||
|
return null
|
||||||
|
} else {
|
||||||
|
return attributes
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// make sure that dom filters are active
|
||||||
|
// TODO: do not rely on .getDom for domFilters
|
||||||
|
xml0.getDom()
|
||||||
|
xml1.getDom()
|
||||||
|
let paragraph = new Y.XmlElement('p')
|
||||||
|
let hideMe = new Y.XmlElement('hideMe')
|
||||||
|
let span = new Y.XmlElement('span')
|
||||||
|
span.setAttribute('malicious', 'alert("give me money")')
|
||||||
|
let tag = new Y.XmlElement('tag')
|
||||||
|
tag.setAttribute('isHidden', 'true')
|
||||||
|
paragraph.insert(0, [hideMe, span, tag])
|
||||||
|
xml0.insert(0, [paragraph])
|
||||||
|
let tag2 = new Y.XmlElement('tag')
|
||||||
|
tag2.setAttribute('isHidden', 'true')
|
||||||
|
paragraph.insert(0, [tag2])
|
||||||
|
await flushAll(t, users)
|
||||||
|
// check dom
|
||||||
|
paragraph.getDom().setAttribute('malicious', 'true')
|
||||||
|
span.getDom().setAttribute('malicious', 'true')
|
||||||
|
console.log(xml0.toString())
|
||||||
|
// check incoming attributes
|
||||||
|
xml1.get(0).get(0).setAttribute('malicious', 'true')
|
||||||
|
xml1.insert(0, [new Y.XmlElement('hideMe')])
|
||||||
|
await flushAll(t, users)
|
||||||
|
|
||||||
|
await compareUsers(t, users)
|
||||||
|
})
|
||||||
|
|
||||||
// TODO: move elements
|
// TODO: move elements
|
||||||
var xmlTransactions = [
|
var xmlTransactions = [
|
||||||
function attributeChange (t, user, chance) {
|
function attributeChange (t, user, chance) {
|
||||||
|
|||||||
@@ -153,12 +153,12 @@ export async function initArrays (t, opts) {
|
|||||||
result['array' + i] = y.define('array', Y.Array)
|
result['array' + i] = y.define('array', Y.Array)
|
||||||
result['map' + i] = y.define('map', Y.Map)
|
result['map' + i] = y.define('map', Y.Map)
|
||||||
result['xml' + i] = y.define('xml', Y.XmlElement)
|
result['xml' + i] = y.define('xml', Y.XmlElement)
|
||||||
y.get('xml').setDomFilter(function (d, attrs) {
|
y.get('xml').setDomFilter(function (nodeName, attrs) {
|
||||||
if (d.nodeName === 'HIDDEN') {
|
if (nodeName === 'HIDDEN') {
|
||||||
return null
|
return null
|
||||||
} else {
|
|
||||||
return attrs.filter(a => a !== 'hidden')
|
|
||||||
}
|
}
|
||||||
|
attrs.delete('hidden')
|
||||||
|
return attrs
|
||||||
})
|
})
|
||||||
y.on('afterTransaction', function () {
|
y.on('afterTransaction', function () {
|
||||||
for (let missing of y._missingStructs.values()) {
|
for (let missing of y._missingStructs.values()) {
|
||||||
|
|||||||
125
y.node.js
125
y.node.js
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* yjs - A framework for real-time p2p shared editing on any data
|
* yjs - A framework for real-time p2p shared editing on any data
|
||||||
* @version v13.0.0-32
|
* @version v13.0.0-35
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -2898,13 +2898,13 @@ function getRelativePosition (type, offset) {
|
|||||||
} else {
|
} else {
|
||||||
let t = type._start;
|
let t = type._start;
|
||||||
while (t !== null) {
|
while (t !== null) {
|
||||||
if (t._length >= offset) {
|
if (t._deleted === false) {
|
||||||
return [t._id.user, t._id.clock + offset - 1]
|
if (t._length >= offset) {
|
||||||
}
|
return [t._id.user, t._id.clock + offset - 1]
|
||||||
if (t._right === null) {
|
}
|
||||||
return [t._id.user, t._id.clock + t._length - 1]
|
if (t._right === null) {
|
||||||
}
|
return [t._id.user, t._id.clock + t._length - 1]
|
||||||
if (!t._deleted) {
|
}
|
||||||
offset -= t._length;
|
offset -= t._length;
|
||||||
}
|
}
|
||||||
t = t._right;
|
t = t._right;
|
||||||
@@ -2995,20 +2995,29 @@ function afterTransactionSelectionFixer (y, transaction, remote) {
|
|||||||
if (from !== null) {
|
if (from !== null) {
|
||||||
let sel = fromRelativePosition(fromY, from);
|
let sel = fromRelativePosition(fromY, from);
|
||||||
if (sel !== null) {
|
if (sel !== null) {
|
||||||
shouldUpdate = true;
|
let node = sel.type.getDom();
|
||||||
anchorNode = sel.type.getDom();
|
let offset = sel.offset;
|
||||||
anchorOffset = sel.offset;
|
if (node !== anchorNode || offset !== anchorOffset) {
|
||||||
|
anchorNode = node;
|
||||||
|
anchorOffset = offset;
|
||||||
|
shouldUpdate = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (to !== null) {
|
if (to !== null) {
|
||||||
let sel = fromRelativePosition(toY, to);
|
let sel = fromRelativePosition(toY, to);
|
||||||
if (sel !== null) {
|
if (sel !== null) {
|
||||||
focusNode = sel.type.getDom();
|
let node = sel.type.getDom();
|
||||||
focusOffset = sel.offset;
|
let offset = sel.offset;
|
||||||
shouldUpdate = true;
|
if (node !== focusNode || offset !== focusOffset) {
|
||||||
|
focusNode = node;
|
||||||
|
focusOffset = offset;
|
||||||
|
shouldUpdate = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (shouldUpdate) {
|
if (shouldUpdate) {
|
||||||
|
console.info('updating selection!!');
|
||||||
browserSelection.setBaseAndExtent(
|
browserSelection.setBaseAndExtent(
|
||||||
anchorNode,
|
anchorNode,
|
||||||
anchorOffset,
|
anchorOffset,
|
||||||
@@ -3784,7 +3793,7 @@ function domToYXml (parent, doms, _document) {
|
|||||||
if (d._yxml != null && d._yxml !== false) {
|
if (d._yxml != null && d._yxml !== false) {
|
||||||
d._yxml._unbindFromDom();
|
d._yxml._unbindFromDom();
|
||||||
}
|
}
|
||||||
if (parent._domFilter(d, []) !== null) {
|
if (parent._domFilter(d.nodeName, new Map()) !== null) {
|
||||||
let type;
|
let type;
|
||||||
if (d.nodeType === d.TEXT_NODE) {
|
if (d.nodeType === d.TEXT_NODE) {
|
||||||
type = new YXmlText(d);
|
type = new YXmlText(d);
|
||||||
@@ -3972,6 +3981,52 @@ class YXmlFragment extends YArray {
|
|||||||
}
|
}
|
||||||
this._y.on('beforeTransaction', beforeTransactionSelectionFixer);
|
this._y.on('beforeTransaction', beforeTransactionSelectionFixer);
|
||||||
this._y.on('afterTransaction', afterTransactionSelectionFixer);
|
this._y.on('afterTransaction', afterTransactionSelectionFixer);
|
||||||
|
const applyFilter = (type) => {
|
||||||
|
if (type._deleted) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// check if type is a child of this
|
||||||
|
let isChild = false;
|
||||||
|
let p = type;
|
||||||
|
while (p !== this._y) {
|
||||||
|
if (p === this) {
|
||||||
|
isChild = true;
|
||||||
|
break
|
||||||
|
}
|
||||||
|
p = p._parent;
|
||||||
|
}
|
||||||
|
if (!isChild) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// filter attributes
|
||||||
|
let attributes = new Map();
|
||||||
|
if (type.getAttributes !== undefined) {
|
||||||
|
let attrs = type.getAttributes();
|
||||||
|
for (let key in attrs) {
|
||||||
|
attributes.set(key, attrs[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let result = this._domFilter(type.nodeName, new Map(attributes));
|
||||||
|
if (result === null) {
|
||||||
|
type._delete(this._y);
|
||||||
|
} else {
|
||||||
|
attributes.forEach((value, key) => {
|
||||||
|
if (!result.has(key)) {
|
||||||
|
type.removeAttribute(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this._y.on('beforeObserverCalls', function (y, transaction) {
|
||||||
|
// apply dom filter to new and changed types
|
||||||
|
transaction.changedTypes.forEach(function (subs, type) {
|
||||||
|
if (subs.size > 1 || !subs.has(null)) {
|
||||||
|
// only apply changes on attributes
|
||||||
|
applyFilter(type);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
transaction.newTypes.forEach(applyFilter);
|
||||||
|
});
|
||||||
// Apply Y.Xml events to dom
|
// Apply Y.Xml events to dom
|
||||||
this.observeDeep(events => {
|
this.observeDeep(events => {
|
||||||
reflectChangesOnDom.call(this, events, _document);
|
reflectChangesOnDom.call(this, events, _document);
|
||||||
@@ -4009,10 +4064,15 @@ class YXmlFragment extends YArray {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'attributes':
|
case 'attributes':
|
||||||
|
if (yxml.constructor === YXmlFragment) {
|
||||||
|
break
|
||||||
|
}
|
||||||
let name = mutation.attributeName;
|
let name = mutation.attributeName;
|
||||||
|
let val = dom.getAttribute(name);
|
||||||
// check if filter accepts attribute
|
// check if filter accepts attribute
|
||||||
if (this._domFilter(dom, [name]).length > 0 && yxml.constructor !== YXmlFragment) {
|
let attributes = new Map();
|
||||||
var val = dom.getAttribute(name);
|
attributes.set(name, val);
|
||||||
|
if (this._domFilter(dom.nodeName, attributes).size > 0 && yxml.constructor !== YXmlFragment) {
|
||||||
if (yxml.getAttribute(name) !== val) {
|
if (yxml.getAttribute(name) !== val) {
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
yxml.removeAttribute(name);
|
yxml.removeAttribute(name);
|
||||||
@@ -4083,16 +4143,15 @@ class YXmlElement extends YXmlFragment {
|
|||||||
} else {
|
} else {
|
||||||
// tag is already set in constructor
|
// tag is already set in constructor
|
||||||
// set attributes
|
// set attributes
|
||||||
let attrNames = [];
|
let attributes = new Map();
|
||||||
for (let i = 0; i < dom.attributes.length; i++) {
|
for (let i = 0; i < dom.attributes.length; i++) {
|
||||||
attrNames.push(dom.attributes[i].name);
|
let attr = dom.attributes[i];
|
||||||
}
|
attributes.set(attr.name, attr.value);
|
||||||
attrNames = this._domFilter(dom, attrNames);
|
|
||||||
for (let i = 0; i < attrNames.length; i++) {
|
|
||||||
let attrName = attrNames[i];
|
|
||||||
let attrValue = dom.getAttribute(attrName);
|
|
||||||
this.setAttribute(attrName, attrValue);
|
|
||||||
}
|
}
|
||||||
|
attributes = this._domFilter(dom, attributes);
|
||||||
|
attributes.forEach((value, name) => {
|
||||||
|
this.setAttribute(name, value);
|
||||||
|
});
|
||||||
this.insertDomElements(0, Array.prototype.slice.call(dom.childNodes), _document);
|
this.insertDomElements(0, Array.prototype.slice.call(dom.childNodes), _document);
|
||||||
this._bindToDom(dom, _document);
|
this._bindToDom(dom, _document);
|
||||||
return dom
|
return dom
|
||||||
@@ -4153,7 +4212,9 @@ class YXmlElement extends YXmlFragment {
|
|||||||
getAttributes () {
|
getAttributes () {
|
||||||
const obj = {};
|
const obj = {};
|
||||||
for (let [key, value] of this._map) {
|
for (let [key, value] of this._map) {
|
||||||
obj[key] = value._content[0];
|
if (!value._deleted) {
|
||||||
|
obj[key] = value._content[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
@@ -5447,6 +5508,7 @@ class Y$1 extends NamedEventHandler {
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
if (initialCall) {
|
if (initialCall) {
|
||||||
|
this.emit('beforeObserverCalls', this, this._transaction, remote);
|
||||||
const transaction = this._transaction;
|
const transaction = this._transaction;
|
||||||
this._transaction = null;
|
this._transaction = null;
|
||||||
// emit change events on changed types
|
// emit change events on changed types
|
||||||
@@ -5487,17 +5549,10 @@ class Y$1 extends NamedEventHandler {
|
|||||||
define (name, TypeConstructor) {
|
define (name, TypeConstructor) {
|
||||||
let id = new RootID(name, TypeConstructor);
|
let id = new RootID(name, TypeConstructor);
|
||||||
let type = this.os.get(id);
|
let type = this.os.get(id);
|
||||||
if (type === null) {
|
|
||||||
type = new TypeConstructor();
|
|
||||||
type._id = id;
|
|
||||||
type._parent = this;
|
|
||||||
type._integrate(this);
|
|
||||||
if (this.share[name] !== undefined) {
|
|
||||||
throw new Error('Type is already defined with a different constructor!')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.share[name] === undefined) {
|
if (this.share[name] === undefined) {
|
||||||
this.share[name] = type;
|
this.share[name] = type;
|
||||||
|
} else if (this.share[name] !== type) {
|
||||||
|
throw new Error('Type is already defined with a different constructor')
|
||||||
}
|
}
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
295
y.test.js
295
y.test.js
@@ -1,8 +1,8 @@
|
|||||||
(function (global, factory) {
|
(function (global, factory) {
|
||||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||||
typeof define === 'function' && define.amd ? define(factory) :
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||||
(factory());
|
(factory((global['y-tests'] = {})));
|
||||||
}(this, (function () { 'use strict';
|
}(this, (function (exports) { 'use strict';
|
||||||
|
|
||||||
class N {
|
class N {
|
||||||
// A created node is always red!
|
// A created node is always red!
|
||||||
@@ -3769,7 +3769,7 @@ function domToYXml (parent, doms, _document) {
|
|||||||
if (d._yxml != null && d._yxml !== false) {
|
if (d._yxml != null && d._yxml !== false) {
|
||||||
d._yxml._unbindFromDom();
|
d._yxml._unbindFromDom();
|
||||||
}
|
}
|
||||||
if (parent._domFilter(d, []) !== null) {
|
if (parent._domFilter(d.nodeName, new Map()) !== null) {
|
||||||
let type;
|
let type;
|
||||||
if (d.nodeType === d.TEXT_NODE) {
|
if (d.nodeType === d.TEXT_NODE) {
|
||||||
type = new YXmlText(d);
|
type = new YXmlText(d);
|
||||||
@@ -3957,6 +3957,52 @@ class YXmlFragment extends YArray {
|
|||||||
}
|
}
|
||||||
this._y.on('beforeTransaction', beforeTransactionSelectionFixer);
|
this._y.on('beforeTransaction', beforeTransactionSelectionFixer);
|
||||||
this._y.on('afterTransaction', afterTransactionSelectionFixer);
|
this._y.on('afterTransaction', afterTransactionSelectionFixer);
|
||||||
|
const applyFilter = (type) => {
|
||||||
|
if (type._deleted) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// check if type is a child of this
|
||||||
|
let isChild = false;
|
||||||
|
let p = type;
|
||||||
|
while (p !== this._y) {
|
||||||
|
if (p === this) {
|
||||||
|
isChild = true;
|
||||||
|
break
|
||||||
|
}
|
||||||
|
p = p._parent;
|
||||||
|
}
|
||||||
|
if (!isChild) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// filter attributes
|
||||||
|
let attributes = new Map();
|
||||||
|
if (type.getAttributes !== undefined) {
|
||||||
|
let attrs = type.getAttributes();
|
||||||
|
for (let key in attrs) {
|
||||||
|
attributes.set(key, attrs[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let result = this._domFilter(type.nodeName, new Map(attributes));
|
||||||
|
if (result === null) {
|
||||||
|
type._delete(this._y);
|
||||||
|
} else {
|
||||||
|
attributes.forEach((value, key) => {
|
||||||
|
if (!result.has(key)) {
|
||||||
|
type.removeAttribute(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this._y.on('beforeObserverCalls', function (y, transaction) {
|
||||||
|
// apply dom filter to new and changed types
|
||||||
|
transaction.changedTypes.forEach(function (subs, type) {
|
||||||
|
if (subs.size > 1 || !subs.has(null)) {
|
||||||
|
// only apply changes on attributes
|
||||||
|
applyFilter(type);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
transaction.newTypes.forEach(applyFilter);
|
||||||
|
});
|
||||||
// Apply Y.Xml events to dom
|
// Apply Y.Xml events to dom
|
||||||
this.observeDeep(events => {
|
this.observeDeep(events => {
|
||||||
reflectChangesOnDom.call(this, events, _document);
|
reflectChangesOnDom.call(this, events, _document);
|
||||||
@@ -3994,10 +4040,15 @@ class YXmlFragment extends YArray {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'attributes':
|
case 'attributes':
|
||||||
|
if (yxml.constructor === YXmlFragment) {
|
||||||
|
break
|
||||||
|
}
|
||||||
let name = mutation.attributeName;
|
let name = mutation.attributeName;
|
||||||
|
let val = dom.getAttribute(name);
|
||||||
// check if filter accepts attribute
|
// check if filter accepts attribute
|
||||||
if (this._domFilter(dom, [name]).length > 0 && this.constructor !== YXmlFragment) {
|
let attributes = new Map();
|
||||||
var val = dom.getAttribute(name);
|
attributes.set(name, val);
|
||||||
|
if (this._domFilter(dom.nodeName, attributes).size > 0 && yxml.constructor !== YXmlFragment) {
|
||||||
if (yxml.getAttribute(name) !== val) {
|
if (yxml.getAttribute(name) !== val) {
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
yxml.removeAttribute(name);
|
yxml.removeAttribute(name);
|
||||||
@@ -4068,16 +4119,15 @@ class YXmlElement extends YXmlFragment {
|
|||||||
} else {
|
} else {
|
||||||
// tag is already set in constructor
|
// tag is already set in constructor
|
||||||
// set attributes
|
// set attributes
|
||||||
let attrNames = [];
|
let attributes = new Map();
|
||||||
for (let i = 0; i < dom.attributes.length; i++) {
|
for (let i = 0; i < dom.attributes.length; i++) {
|
||||||
attrNames.push(dom.attributes[i].name);
|
let attr = dom.attributes[i];
|
||||||
}
|
attributes.set(attr.name, attr.value);
|
||||||
attrNames = this._domFilter(dom, attrNames);
|
|
||||||
for (let i = 0; i < attrNames.length; i++) {
|
|
||||||
let attrName = attrNames[i];
|
|
||||||
let attrValue = dom.getAttribute(attrName);
|
|
||||||
this.setAttribute(attrName, attrValue);
|
|
||||||
}
|
}
|
||||||
|
attributes = this._domFilter(dom, attributes);
|
||||||
|
attributes.forEach((value, name) => {
|
||||||
|
this.setAttribute(name, value);
|
||||||
|
});
|
||||||
this.insertDomElements(0, Array.prototype.slice.call(dom.childNodes), _document);
|
this.insertDomElements(0, Array.prototype.slice.call(dom.childNodes), _document);
|
||||||
this._bindToDom(dom, _document);
|
this._bindToDom(dom, _document);
|
||||||
return dom
|
return dom
|
||||||
@@ -4138,7 +4188,9 @@ class YXmlElement extends YXmlFragment {
|
|||||||
getAttributes () {
|
getAttributes () {
|
||||||
const obj = {};
|
const obj = {};
|
||||||
for (let [key, value] of this._map) {
|
for (let [key, value] of this._map) {
|
||||||
obj[key] = value._content[0];
|
if (!value._deleted) {
|
||||||
|
obj[key] = value._content[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
@@ -4524,7 +4576,7 @@ var y = d * 365.25;
|
|||||||
* @api public
|
* @api public
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var index = function(val, options) {
|
var ms = function(val, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var type = typeof val;
|
var type = typeof val;
|
||||||
if (type === 'string' && val.length > 0) {
|
if (type === 'string' && val.length > 0) {
|
||||||
@@ -4666,7 +4718,7 @@ exports.coerce = coerce;
|
|||||||
exports.disable = disable;
|
exports.disable = disable;
|
||||||
exports.enable = enable;
|
exports.enable = enable;
|
||||||
exports.enabled = enabled;
|
exports.enabled = enabled;
|
||||||
exports.humanize = index;
|
exports.humanize = ms;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The currently active debug mode names, and names to skip.
|
* The currently active debug mode names, and names to skip.
|
||||||
@@ -4725,8 +4777,8 @@ function createDebug(namespace) {
|
|||||||
|
|
||||||
// set `diff` timestamp
|
// set `diff` timestamp
|
||||||
var curr = +new Date();
|
var curr = +new Date();
|
||||||
var ms = curr - (prevTime || curr);
|
var ms$$1 = curr - (prevTime || curr);
|
||||||
self.diff = ms;
|
self.diff = ms$$1;
|
||||||
self.prev = prevTime;
|
self.prev = prevTime;
|
||||||
self.curr = curr;
|
self.curr = curr;
|
||||||
prevTime = curr;
|
prevTime = curr;
|
||||||
@@ -4745,19 +4797,19 @@ function createDebug(namespace) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// apply any `formatters` transformations
|
// apply any `formatters` transformations
|
||||||
var index$$1 = 0;
|
var index = 0;
|
||||||
args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
|
args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
|
||||||
// if we encounter an escaped % then don't increase the array index
|
// if we encounter an escaped % then don't increase the array index
|
||||||
if (match === '%%') return match;
|
if (match === '%%') return match;
|
||||||
index$$1++;
|
index++;
|
||||||
var formatter = exports.formatters[format];
|
var formatter = exports.formatters[format];
|
||||||
if ('function' === typeof formatter) {
|
if ('function' === typeof formatter) {
|
||||||
var val = args[index$$1];
|
var val = args[index];
|
||||||
match = formatter.call(self, val);
|
match = formatter.call(self, val);
|
||||||
|
|
||||||
// now we need to remove `args[index]` since it's inlined in the `format`
|
// now we need to remove `args[index]` since it's inlined in the `format`
|
||||||
args.splice(index$$1, 1);
|
args.splice(index, 1);
|
||||||
index$$1--;
|
index--;
|
||||||
}
|
}
|
||||||
return match;
|
return match;
|
||||||
});
|
});
|
||||||
@@ -5432,6 +5484,7 @@ class Y$2 extends NamedEventHandler {
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
if (initialCall) {
|
if (initialCall) {
|
||||||
|
this.emit('beforeObserverCalls', this, this._transaction, remote);
|
||||||
const transaction = this._transaction;
|
const transaction = this._transaction;
|
||||||
this._transaction = null;
|
this._transaction = null;
|
||||||
// emit change events on changed types
|
// emit change events on changed types
|
||||||
@@ -5472,17 +5525,10 @@ class Y$2 extends NamedEventHandler {
|
|||||||
define (name, TypeConstructor) {
|
define (name, TypeConstructor) {
|
||||||
let id = new RootID(name, TypeConstructor);
|
let id = new RootID(name, TypeConstructor);
|
||||||
let type = this.os.get(id);
|
let type = this.os.get(id);
|
||||||
if (type === null) {
|
|
||||||
type = new TypeConstructor();
|
|
||||||
type._id = id;
|
|
||||||
type._parent = this;
|
|
||||||
type._integrate(this);
|
|
||||||
if (this.share[name] !== undefined) {
|
|
||||||
throw new Error('Type is already defined with a different constructor!')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.share[name] === undefined) {
|
if (this.share[name] === undefined) {
|
||||||
this.share[name] = type;
|
this.share[name] = type;
|
||||||
|
} else if (this.share[name] !== type) {
|
||||||
|
throw new Error('Type is already defined with a different constructor')
|
||||||
}
|
}
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
@@ -5726,7 +5772,7 @@ if (typeof Y !== 'undefined') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var chance_1 = createCommonjsModule(function (module, exports) {
|
var chance_1 = createCommonjsModule(function (module, exports) {
|
||||||
// Chance.js 1.0.10
|
// Chance.js 1.0.12
|
||||||
// http://chancejs.com
|
// http://chancejs.com
|
||||||
// (c) 2013 Victor Quinn
|
// (c) 2013 Victor Quinn
|
||||||
// Chance may be freely distributed or modified under the MIT license.
|
// Chance may be freely distributed or modified under the MIT license.
|
||||||
@@ -5791,7 +5837,7 @@ var chance_1 = createCommonjsModule(function (module, exports) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Chance.prototype.VERSION = "1.0.10";
|
Chance.prototype.VERSION = "1.0.12";
|
||||||
|
|
||||||
// Random helper functions
|
// Random helper functions
|
||||||
function initOptions(options, defaults) {
|
function initOptions(options, defaults) {
|
||||||
@@ -6010,6 +6056,16 @@ var chance_1 = createCommonjsModule(function (module, exports) {
|
|||||||
return integer.toString(16);
|
return integer.toString(16);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Chance.prototype.letter = function(options) {
|
||||||
|
options = initOptions(options, {casing: 'lower'});
|
||||||
|
var pool = "abcdefghijklmnopqrstuvwxyz";
|
||||||
|
var letter = this.character({pool: pool});
|
||||||
|
if (options.casing === 'upper') {
|
||||||
|
letter = letter.toUpperCase();
|
||||||
|
}
|
||||||
|
return letter;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a random string
|
* Return a random string
|
||||||
*
|
*
|
||||||
@@ -6952,8 +7008,25 @@ var chance_1 = createCommonjsModule(function (module, exports) {
|
|||||||
return this.word({length: options.length}) + '@' + (options.domain || this.domain());
|
return this.word({length: options.length}) + '@' + (options.domain || this.domain());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* #Description:
|
||||||
|
* ===============================================
|
||||||
|
* Generate a random Facebook id, aka fbid.
|
||||||
|
*
|
||||||
|
* NOTE: At the moment (Sep 2017), Facebook ids are
|
||||||
|
* "numeric strings" of length 16.
|
||||||
|
* However, Facebook Graph API documentation states that
|
||||||
|
* "it is extremely likely to change over time".
|
||||||
|
* @see https://developers.facebook.com/docs/graph-api/overview/
|
||||||
|
*
|
||||||
|
* #Examples:
|
||||||
|
* ===============================================
|
||||||
|
* chance.fbid() => '1000035231661304'
|
||||||
|
*
|
||||||
|
* @return [string] facebook id
|
||||||
|
*/
|
||||||
Chance.prototype.fbid = function () {
|
Chance.prototype.fbid = function () {
|
||||||
return parseInt('10000' + this.natural({max: 100000000000}), 10);
|
return '10000' + this.string({pool: "1234567890", length: 11});
|
||||||
};
|
};
|
||||||
|
|
||||||
Chance.prototype.google_analytics = function () {
|
Chance.prototype.google_analytics = function () {
|
||||||
@@ -7794,8 +7867,72 @@ var chance_1 = createCommonjsModule(function (module, exports) {
|
|||||||
|
|
||||||
// -- End Regional
|
// -- End Regional
|
||||||
|
|
||||||
|
// -- Music --
|
||||||
|
|
||||||
|
Chance.prototype.note = function(options) {
|
||||||
|
// choices for 'notes' option:
|
||||||
|
// flatKey - chromatic scale with flat notes (default)
|
||||||
|
// sharpKey - chromatic scale with sharp notes
|
||||||
|
// flats - just flat notes
|
||||||
|
// sharps - just sharp notes
|
||||||
|
// naturals - just natural notes
|
||||||
|
// all - naturals, sharps and flats
|
||||||
|
options = initOptions(options, { notes : 'flatKey'});
|
||||||
|
var scales = {
|
||||||
|
naturals: ['C', 'D', 'E', 'F', 'G', 'A', 'B'],
|
||||||
|
flats: ['D♭', 'E♭', 'G♭', 'A♭', 'B♭'],
|
||||||
|
sharps: ['C♯', 'D♯', 'F♯', 'G♯', 'A♯']
|
||||||
|
};
|
||||||
|
scales.all = scales.naturals.concat(scales.flats.concat(scales.sharps));
|
||||||
|
scales.flatKey = scales.naturals.concat(scales.flats);
|
||||||
|
scales.sharpKey = scales.naturals.concat(scales.sharps);
|
||||||
|
return this.pickone(scales[options.notes]);
|
||||||
|
};
|
||||||
|
|
||||||
|
Chance.prototype.midi_note = function(options) {
|
||||||
|
var min = 0;
|
||||||
|
var max = 127;
|
||||||
|
options = initOptions(options, { min : min, max : max });
|
||||||
|
return this.integer({min: options.min, max: options.max});
|
||||||
|
};
|
||||||
|
|
||||||
|
Chance.prototype.chord_quality = function(options) {
|
||||||
|
options = initOptions(options, { jazz: true });
|
||||||
|
var chord_qualities = ['maj', 'min', 'aug', 'dim'];
|
||||||
|
if (options.jazz){
|
||||||
|
chord_qualities = [
|
||||||
|
'maj7',
|
||||||
|
'min7',
|
||||||
|
'7',
|
||||||
|
'sus',
|
||||||
|
'dim',
|
||||||
|
'ø'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return this.pickone(chord_qualities);
|
||||||
|
};
|
||||||
|
|
||||||
|
Chance.prototype.chord = function (options) {
|
||||||
|
options = initOptions(options);
|
||||||
|
return this.note(options) + this.chord_quality(options);
|
||||||
|
};
|
||||||
|
|
||||||
|
Chance.prototype.tempo = function (options) {
|
||||||
|
var min = 40;
|
||||||
|
var max = 320;
|
||||||
|
options = initOptions(options, {min: min, max: max});
|
||||||
|
return this.integer({min: options.min, max: options.max});
|
||||||
|
};
|
||||||
|
|
||||||
|
// -- End Music
|
||||||
|
|
||||||
// -- Miscellaneous --
|
// -- Miscellaneous --
|
||||||
|
|
||||||
|
// Coin - Flip, flip, flipadelphia
|
||||||
|
Chance.prototype.coin = function(options) {
|
||||||
|
return this.bool() ? "heads" : "tails";
|
||||||
|
};
|
||||||
|
|
||||||
// Dice - For all the board game geeks out there, myself included ;)
|
// Dice - For all the board game geeks out there, myself included ;)
|
||||||
function diceFn (range) {
|
function diceFn (range) {
|
||||||
return function () {
|
return function () {
|
||||||
@@ -13142,12 +13279,12 @@ async function initArrays (t, opts) {
|
|||||||
result['array' + i] = y.define('array', Y$1.Array);
|
result['array' + i] = y.define('array', Y$1.Array);
|
||||||
result['map' + i] = y.define('map', Y$1.Map);
|
result['map' + i] = y.define('map', Y$1.Map);
|
||||||
result['xml' + i] = y.define('xml', Y$1.XmlElement);
|
result['xml' + i] = y.define('xml', Y$1.XmlElement);
|
||||||
y.get('xml').setDomFilter(function (d, attrs) {
|
y.get('xml').setDomFilter(function (nodeName, attrs) {
|
||||||
if (d.nodeName === 'HIDDEN') {
|
if (nodeName === 'HIDDEN') {
|
||||||
return null
|
return null
|
||||||
} else {
|
|
||||||
return attrs.filter(a => a !== 'hidden')
|
|
||||||
}
|
}
|
||||||
|
attrs.delete('hidden');
|
||||||
|
return attrs
|
||||||
});
|
});
|
||||||
y.on('afterTransaction', function () {
|
y.on('afterTransaction', function () {
|
||||||
for (let missing of y._missingStructs.values()) {
|
for (let missing of y._missingStructs.values()) {
|
||||||
@@ -13263,7 +13400,7 @@ async function applyRandomTests (t, mods, iterations) {
|
|||||||
return initInformation
|
return initInformation
|
||||||
}
|
}
|
||||||
|
|
||||||
var index$1$1 = function (str) {
|
var index$1 = function (str) {
|
||||||
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
|
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
|
||||||
return '%' + c.charCodeAt(0).toString(16).toUpperCase();
|
return '%' + c.charCodeAt(0).toString(16).toUpperCase();
|
||||||
});
|
});
|
||||||
@@ -13449,7 +13586,7 @@ function parserForArrayFormat(opts) {
|
|||||||
|
|
||||||
function encode(value, opts) {
|
function encode(value, opts) {
|
||||||
if (opts.encode) {
|
if (opts.encode) {
|
||||||
return opts.strict ? index$1$1(value) : encodeURIComponent(value);
|
return opts.strict ? index$1(value) : encodeURIComponent(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
@@ -13561,7 +13698,7 @@ var stringify = function (obj, opts) {
|
|||||||
}).join('&') : '';
|
}).join('&') : '';
|
||||||
};
|
};
|
||||||
|
|
||||||
var index$2 = {
|
var index = {
|
||||||
extract: extract,
|
extract: extract,
|
||||||
parse: parse$1,
|
parse: parse$1,
|
||||||
stringify: stringify
|
stringify: stringify
|
||||||
@@ -13576,7 +13713,7 @@ const browserSupport =
|
|||||||
|
|
||||||
function createTestLink (params) {
|
function createTestLink (params) {
|
||||||
if (typeof location !== 'undefined') {
|
if (typeof location !== 'undefined') {
|
||||||
var query = index$2.parse(location.search);
|
var query = index.parse(location.search);
|
||||||
delete query.test;
|
delete query.test;
|
||||||
delete query.seed;
|
delete query.seed;
|
||||||
delete query.args;
|
delete query.args;
|
||||||
@@ -13586,7 +13723,7 @@ function createTestLink (params) {
|
|||||||
query[name] = params[name];
|
query[name] = params[name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return location.protocol + '//' + location.host + location.pathname + '?' + index$2.stringify(query) + location.hash
|
return location.protocol + '//' + location.host + location.pathname + '?' + index.stringify(query) + location.hash
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13597,7 +13734,7 @@ class TestHandler {
|
|||||||
this.repeatingRun = 0;
|
this.repeatingRun = 0;
|
||||||
this.tests = {};
|
this.tests = {};
|
||||||
if (typeof location !== 'undefined') {
|
if (typeof location !== 'undefined') {
|
||||||
this.opts = index$2.parse(location.search);
|
this.opts = index.parse(location.search);
|
||||||
if (this.opts.case != null) {
|
if (this.opts.case != null) {
|
||||||
this.opts.case = Number(this.opts.case);
|
this.opts.case = Number(this.opts.case);
|
||||||
}
|
}
|
||||||
@@ -13738,7 +13875,7 @@ function createCommonjsModule$1(fn, module) {
|
|||||||
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
var isBrowser = typeof index$2 !== 'undefined';
|
var isBrowser = typeof index !== 'undefined';
|
||||||
|
|
||||||
var environment = {
|
var environment = {
|
||||||
isBrowser: isBrowser
|
isBrowser: isBrowser
|
||||||
@@ -18287,8 +18424,8 @@ var stacktraceGps = createCommonjsModule$1(function (module, exports) {
|
|||||||
* @returns {String} original representation of the base64-encoded string.
|
* @returns {String} original representation of the base64-encoded string.
|
||||||
*/
|
*/
|
||||||
function _atob(b64str) {
|
function _atob(b64str) {
|
||||||
if (typeof index$2 !== 'undefined' && index$2.atob) {
|
if (typeof index !== 'undefined' && index.atob) {
|
||||||
return index$2.atob(b64str);
|
return index.atob(b64str);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('You must supply a polyfill for window.atob in this environment');
|
throw new Error('You must supply a polyfill for window.atob in this environment');
|
||||||
}
|
}
|
||||||
@@ -18798,7 +18935,7 @@ var stacktrace = createCommonjsModule$1(function (module, exports) {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
index$2.stacktrace = stacktrace;
|
index.stacktrace = stacktrace;
|
||||||
|
|
||||||
function test (testDescription, ...args) {
|
function test (testDescription, ...args) {
|
||||||
let location = stacktrace.getSync()[1];
|
let location = stacktrace.getSync()[1];
|
||||||
@@ -19039,8 +19176,8 @@ test('filter node', async function xml14 (t) {
|
|||||||
var { users, xml0, xml1 } = await initArrays(t, { users: 3 });
|
var { users, xml0, xml1 } = await initArrays(t, { users: 3 });
|
||||||
let dom0 = xml0.getDom();
|
let dom0 = xml0.getDom();
|
||||||
let dom1 = xml1.getDom();
|
let dom1 = xml1.getDom();
|
||||||
let domFilter = (node, attrs) => {
|
let domFilter = (nodeName, attrs) => {
|
||||||
if (node.nodeName === 'H1') {
|
if (nodeName === 'H1') {
|
||||||
return null
|
return null
|
||||||
} else {
|
} else {
|
||||||
return attrs
|
return attrs
|
||||||
@@ -19060,8 +19197,9 @@ test('filter attribute', async function xml15 (t) {
|
|||||||
var { users, xml0, xml1 } = await initArrays(t, { users: 3 });
|
var { users, xml0, xml1 } = await initArrays(t, { users: 3 });
|
||||||
let dom0 = xml0.getDom();
|
let dom0 = xml0.getDom();
|
||||||
let dom1 = xml1.getDom();
|
let dom1 = xml1.getDom();
|
||||||
let domFilter = (node, attrs) => {
|
let domFilter = (nodeName, attrs) => {
|
||||||
return attrs.filter(name => name !== 'hidden')
|
attrs.delete('hidden');
|
||||||
|
return attrs
|
||||||
};
|
};
|
||||||
xml0.setDomFilter(domFilter);
|
xml0.setDomFilter(domFilter);
|
||||||
xml1.setDomFilter(domFilter);
|
xml1.setDomFilter(domFilter);
|
||||||
@@ -19112,6 +19250,51 @@ test('treeWalker', async function xml17 (t) {
|
|||||||
await compareUsers(t, users);
|
await compareUsers(t, users);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The expected behavior is that changes on your own dom (e.g. malicious attributes) persist.
|
||||||
|
* Yjs should just ignore them, never propagate those attributes.
|
||||||
|
* Incoming changes that contain malicious attributes should be deleted.
|
||||||
|
*/
|
||||||
|
test('Filtering remote changes', async function xmlFilteringRemote (t) {
|
||||||
|
var { users, xml0, xml1 } = await initArrays(t, { users: 3 });
|
||||||
|
xml0.setDomFilter(function (nodeName, attributes) {
|
||||||
|
attributes.delete('malicious');
|
||||||
|
if (nodeName === 'HIDEME') {
|
||||||
|
return null
|
||||||
|
} else if (attributes.has('isHidden')) {
|
||||||
|
return null
|
||||||
|
} else {
|
||||||
|
return attributes
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// make sure that dom filters are active
|
||||||
|
// TODO: do not rely on .getDom for domFilters
|
||||||
|
xml0.getDom();
|
||||||
|
xml1.getDom();
|
||||||
|
let paragraph = new Y$1.XmlElement('p');
|
||||||
|
let hideMe = new Y$1.XmlElement('hideMe');
|
||||||
|
let span = new Y$1.XmlElement('span');
|
||||||
|
span.setAttribute('malicious', 'alert("give me money")');
|
||||||
|
let tag = new Y$1.XmlElement('tag');
|
||||||
|
tag.setAttribute('isHidden', 'true');
|
||||||
|
paragraph.insert(0, [hideMe, span, tag]);
|
||||||
|
xml0.insert(0, [paragraph]);
|
||||||
|
let tag2 = new Y$1.XmlElement('tag');
|
||||||
|
tag2.setAttribute('isHidden', 'true');
|
||||||
|
paragraph.insert(0, [tag2]);
|
||||||
|
await flushAll(t, users);
|
||||||
|
// check dom
|
||||||
|
paragraph.getDom().setAttribute('malicious', 'true');
|
||||||
|
span.getDom().setAttribute('malicious', 'true');
|
||||||
|
console.log(xml0.toString());
|
||||||
|
// check incoming attributes
|
||||||
|
xml1.get(0).get(0).setAttribute('malicious', 'true');
|
||||||
|
xml1.insert(0, [new Y$1.XmlElement('hideMe')]);
|
||||||
|
await flushAll(t, users);
|
||||||
|
|
||||||
|
await compareUsers(t, users);
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: move elements
|
// TODO: move elements
|
||||||
var xmlTransactions = [
|
var xmlTransactions = [
|
||||||
function attributeChange (t, user, chance) {
|
function attributeChange (t, user, chance) {
|
||||||
@@ -19214,5 +19397,7 @@ test('y-xml: Random tests (1000)', async function xmlRandom1000 (t) {
|
|||||||
await applyRandomTests(t, xmlTransactions, 1000);
|
await applyRandomTests(t, xmlTransactions, 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
|
||||||
})));
|
})));
|
||||||
//# sourceMappingURL=y.test.js.map
|
//# sourceMappingURL=y.test.js.map
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user