Compare commits

..

3 Commits

Author SHA1 Message Date
Kevin Jahns
f9a75ff948 v13.0.0-28 -- distribution files 2017-11-10 18:41:49 -08:00
Kevin Jahns
16f84c67d5 13.0.0-28 2017-11-10 18:41:39 -08:00
Kevin Jahns
290d3c8ffe support undefined as an attribute value 2017-11-10 18:41:10 -08:00
11 changed files with 267 additions and 45 deletions

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "yjs",
"version": "13.0.0-27",
"version": "13.0.0-28",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

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

View File

@@ -20,7 +20,13 @@ export default class ItemJSON extends Item {
this._content = new Array(len)
for (let i = 0; i < len; i++) {
const ctnt = decoder.readVarString()
this._content[i] = JSON.parse(ctnt)
let parsed
if (ctnt === 'undefined') {
parsed = undefined
} else {
parsed = JSON.parse(ctnt)
}
this._content[i] = parsed
}
return missing
}
@@ -29,7 +35,14 @@ export default class ItemJSON extends Item {
let len = this._content.length
encoder.writeVarUint(len)
for (let i = 0; i < len; i++) {
encoder.writeVarString(JSON.stringify(this._content[i]))
let encoded
let content = this._content[i]
if (content === undefined) {
encoded = 'undefined'
} else {
encoded = JSON.stringify(content)
}
encoder.writeVarString(encoded)
}
}
_logString () {

View File

@@ -136,6 +136,26 @@ export function applyChangesFromDom (dom) {
}
export function reflectChangesOnDom (events) {
// Make sure that no filtered attributes are applied to the structure
// if they were, delete them
events.forEach(event => {
const target = event.target
const keys = this._domFilter(target.nodeName, Array.from(event.keysChanged))
if (keys === null) {
target._delete()
} else {
const removeKeys = new Set() // is a copy of event.keysChanged
event.keysChanged.forEach(key => { removeKeys.add(key) })
keys.forEach(key => {
// remove all accepted keys from removeKeys
removeKeys.delete(key)
})
// remove the filtered attribute
removeKeys.forEach(key => {
target.removeAttribute(key)
})
}
})
this._mutualExclude(() => {
events.forEach(event => {
const yxml = event.target

View File

@@ -41,6 +41,8 @@ test('basic map tests', async function map0 (t) {
test('Basic get&set of Map property (converge via sync)', async function map1 (t) {
let { users, map0 } = await initArrays(t, { users: 2 })
map0.set('stuff', 'stuffy')
map0.set('undefined', undefined)
map0.set('null', null)
t.compare(map0.get('stuff'), 'stuffy')
await flushAll(t, users)
@@ -48,6 +50,8 @@ test('Basic get&set of Map property (converge via sync)', async function map1 (t
for (let user of users) {
var u = user.get('map', Y.Map)
t.compare(u.get('stuff'), 'stuffy')
t.assert(u.get('undefined') === undefined, 'undefined')
t.compare(u.get('null'), null, 'null')
}
await compareUsers(t, users)
})

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-27
* @version v13.0.0-28
* @license MIT
*/
@@ -2091,7 +2091,13 @@ class ItemJSON extends Item {
this._content = new Array(len);
for (let i = 0; i < len; i++) {
const ctnt = decoder.readVarString();
this._content[i] = JSON.parse(ctnt);
let parsed;
if (ctnt === 'undefined') {
parsed = undefined;
} else {
parsed = JSON.parse(ctnt);
}
this._content[i] = parsed;
}
return missing
}
@@ -2100,7 +2106,14 @@ class ItemJSON extends Item {
let len = this._content.length;
encoder.writeVarUint(len);
for (let i = 0; i < len; i++) {
encoder.writeVarString(JSON.stringify(this._content[i]));
let encoded;
let content = this._content[i];
if (content === undefined) {
encoded = 'undefined';
} else {
encoded = JSON.stringify(content);
}
encoder.writeVarString(encoded);
}
}
_logString () {
@@ -2764,6 +2777,26 @@ function applyChangesFromDom (dom) {
}
function reflectChangesOnDom (events) {
// Make sure that no filtered attributes are applied to the structure
// if they were, delete them
events.forEach(event => {
const target = event.target;
const keys = this._domFilter(target.nodeName, Array.from(event.keysChanged));
if (keys === null) {
target._delete();
} else {
const removeKeys = new Set(); // is a copy of event.keysChanged
event.keysChanged.forEach(key => { removeKeys.add(key); });
keys.forEach(key => {
// remove all accepted keys from removeKeys
removeKeys.delete(key);
});
// remove the filtered attribute
removeKeys.forEach(key => {
target.removeAttribute(key);
});
}
});
this._mutualExclude(() => {
events.forEach(event => {
const yxml = event.target;

File diff suppressed because one or more lines are too long

214
y.test.js
View File

@@ -1,8 +1,8 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, (function () { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global['y-tests'] = {})));
}(this, (function (exports) { 'use strict';
class N {
// A created node is always red!
@@ -1448,6 +1448,10 @@ function logID (id) {
}
}
/**
* Delete all items in an ID-range
* TODO: implement getItemCleanStartNode for better performance (only one lookup)
*/
function deleteItemRange (y, user, clock, range) {
const createDelete = y.connector._forwardAppliedStructs;
let item = y.os.getItemCleanStart(new ID(user, clock));
@@ -1552,6 +1556,13 @@ function transactionTypeChanged (y, type, sub) {
}
}
/**
* Helper utility to split an Item (see _splitAt)
* - copy all properties from a to b
* - connect a to b
* - assigns the correct _id
* - save b to os
*/
function splitHelper (y, a, b, diff) {
const aID = a._id;
b._id = new ID(aID.user, aID.clock + diff);
@@ -1902,6 +1913,7 @@ class EventHandler {
}
}
// restructure children as if they were inserted one after another
function integrateChildren (y, start) {
let right;
do {
@@ -2076,7 +2088,13 @@ class ItemJSON extends Item {
this._content = new Array(len);
for (let i = 0; i < len; i++) {
const ctnt = decoder.readVarString();
this._content[i] = JSON.parse(ctnt);
let parsed;
if (ctnt === 'undefined') {
parsed = undefined;
} else {
parsed = JSON.parse(ctnt);
}
this._content[i] = parsed;
}
return missing
}
@@ -2085,7 +2103,14 @@ class ItemJSON extends Item {
let len = this._content.length;
encoder.writeVarUint(len);
for (let i = 0; i < len; i++) {
encoder.writeVarString(JSON.stringify(this._content[i]));
let encoded;
let content = this._content[i];
if (content === undefined) {
encoded = 'undefined';
} else {
encoded = JSON.stringify(content);
}
encoder.writeVarString(encoded);
}
}
_logString () {
@@ -2749,6 +2774,26 @@ function applyChangesFromDom (dom) {
}
function reflectChangesOnDom (events) {
// Make sure that no filtered attributes are applied to the structure
// if they were, delete them
events.forEach(event => {
const target = event.target;
const keys = this._domFilter(target.nodeName, Array.from(event.keysChanged));
if (keys === null) {
target._delete();
} else {
const removeKeys = new Set(); // is a copy of event.keysChanged
event.keysChanged.forEach(key => { removeKeys.add(key); });
keys.forEach(key => {
// remove all accepted keys from removeKeys
removeKeys.delete(key);
});
// remove the filtered attribute
removeKeys.forEach(key => {
target.removeAttribute(key);
});
}
});
this._mutualExclude(() => {
events.forEach(event => {
const yxml = event.target;
@@ -4483,7 +4528,7 @@ var y = d * 365.25;
* @api public
*/
var index = function(val, options) {
var ms = function(val, options) {
options = options || {};
var type = typeof val;
if (type === 'string' && val.length > 0) {
@@ -4625,7 +4670,7 @@ exports.coerce = coerce;
exports.disable = disable;
exports.enable = enable;
exports.enabled = enabled;
exports.humanize = index;
exports.humanize = ms;
/**
* The currently active debug mode names, and names to skip.
@@ -4684,8 +4729,8 @@ function createDebug(namespace) {
// set `diff` timestamp
var curr = +new Date();
var ms = curr - (prevTime || curr);
self.diff = ms;
var ms$$1 = curr - (prevTime || curr);
self.diff = ms$$1;
self.prev = prevTime;
self.curr = curr;
prevTime = curr;
@@ -4704,19 +4749,19 @@ function createDebug(namespace) {
}
// apply any `formatters` transformations
var index$$1 = 0;
var index = 0;
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 (match === '%%') return match;
index$$1++;
index++;
var formatter = exports.formatters[format];
if ('function' === typeof formatter) {
var val = args[index$$1];
var val = args[index];
match = formatter.call(self, val);
// now we need to remove `args[index]` since it's inlined in the `format`
args.splice(index$$1, 1);
index$$1--;
args.splice(index, 1);
index--;
}
return match;
});
@@ -5682,7 +5727,7 @@ if (typeof Y !== 'undefined') {
}
var chance_1 = createCommonjsModule(function (module, exports) {
// Chance.js 1.0.10
// Chance.js 1.0.12
// http://chancejs.com
// (c) 2013 Victor Quinn
// Chance may be freely distributed or modified under the MIT license.
@@ -5747,7 +5792,7 @@ var chance_1 = createCommonjsModule(function (module, exports) {
return this;
}
Chance.prototype.VERSION = "1.0.10";
Chance.prototype.VERSION = "1.0.12";
// Random helper functions
function initOptions(options, defaults) {
@@ -5966,6 +6011,16 @@ var chance_1 = createCommonjsModule(function (module, exports) {
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
*
@@ -6908,8 +6963,25 @@ var chance_1 = createCommonjsModule(function (module, exports) {
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 () {
return parseInt('10000' + this.natural({max: 100000000000}), 10);
return '10000' + this.string({pool: "1234567890", length: 11});
};
Chance.prototype.google_analytics = function () {
@@ -7750,8 +7822,72 @@ var chance_1 = createCommonjsModule(function (module, exports) {
// -- 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 --
// 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 ;)
function diceFn (range) {
return function () {
@@ -12941,6 +13077,19 @@ var chance_1 = createCommonjsModule(function (module, exports) {
var chance_2 = chance_1.Chance;
/**
* Try to merge all items in os with their successors.
*
* Some transformations (like delete) fragment items.
* Item(c: 'ab') + Delete(1,1) + Delete(0, 1) -> Item(c: 'a',deleted);Item(c: 'b',deleted)
*
* This functions merges the fragmented nodes together:
* Item(c: 'a',deleted);Item(c: 'b',deleted) -> Item(c: 'ab', deleted)
*
* TODO: The Tree implementation does not support deletions in-spot.
* This is why all deletions must be performed after the traversal.
*
*/
function defragmentItemContent (y) {
const os = y.os;
if (os.length < 2) {
@@ -13219,7 +13368,7 @@ async function applyRandomTests (t, mods, iterations) {
return initInformation
}
var index$1$1 = function (str) {
var index$1 = function (str) {
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
return '%' + c.charCodeAt(0).toString(16).toUpperCase();
});
@@ -13405,7 +13554,7 @@ function parserForArrayFormat(opts) {
function encode(value, opts) {
if (opts.encode) {
return opts.strict ? index$1$1(value) : encodeURIComponent(value);
return opts.strict ? index$1(value) : encodeURIComponent(value);
}
return value;
@@ -13517,7 +13666,7 @@ var stringify = function (obj, opts) {
}).join('&') : '';
};
var index$2 = {
var index = {
extract: extract,
parse: parse$1,
stringify: stringify
@@ -13532,7 +13681,7 @@ const browserSupport =
function createTestLink (params) {
if (typeof location !== 'undefined') {
var query = index$2.parse(location.search);
var query = index.parse(location.search);
delete query.test;
delete query.seed;
delete query.args;
@@ -13542,7 +13691,7 @@ function createTestLink (params) {
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
}
}
@@ -13553,7 +13702,7 @@ class TestHandler {
this.repeatingRun = 0;
this.tests = {};
if (typeof location !== 'undefined') {
this.opts = index$2.parse(location.search);
this.opts = index.parse(location.search);
if (this.opts.case != null) {
this.opts.case = Number(this.opts.case);
}
@@ -13694,7 +13843,7 @@ function createCommonjsModule$1(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var isBrowser = typeof index$2 !== 'undefined';
var isBrowser = typeof index !== 'undefined';
var environment = {
isBrowser: isBrowser
@@ -18243,8 +18392,8 @@ var stacktraceGps = createCommonjsModule$1(function (module, exports) {
* @returns {String} original representation of the base64-encoded string.
*/
function _atob(b64str) {
if (typeof index$2 !== 'undefined' && index$2.atob) {
return index$2.atob(b64str);
if (typeof index !== 'undefined' && index.atob) {
return index.atob(b64str);
} else {
throw new Error('You must supply a polyfill for window.atob in this environment');
}
@@ -18776,7 +18925,7 @@ function proxyConsole () {
['log', 'error', 'assert'].map(createProxy);
}
index$2.stacktrace = stacktrace;
index.stacktrace = stacktrace;
function test (testDescription, ...args) {
let location = stacktrace.getSync()[1];
@@ -18785,9 +18934,6 @@ function test (testDescription, ...args) {
testHandler.register(testCase);
}
//# sourceMappingURL=cutest.mjs.map
proxyConsole();
test('basic map tests', async function map0 (t) {
@@ -18828,6 +18974,8 @@ test('basic map tests', async function map0 (t) {
test('Basic get&set of Map property (converge via sync)', async function map1 (t) {
let { users, map0 } = await initArrays(t, { users: 2 });
map0.set('stuff', 'stuffy');
map0.set('undefined', undefined);
map0.set('null', null);
t.compare(map0.get('stuff'), 'stuffy');
await flushAll(t, users);
@@ -18835,6 +18983,8 @@ test('Basic get&set of Map property (converge via sync)', async function map1 (t
for (let user of users) {
var u = user.get('map', Y$1.Map);
t.compare(u.get('stuff'), 'stuffy');
t.assert(u.get('undefined') === undefined, 'undefined');
t.compare(u.get('null'), null, 'null');
}
await compareUsers(t, users);
});
@@ -19148,5 +19298,7 @@ test('y-map: Random tests (1800)', async function randomMap1800 (t) {
await applyRandomTests(t, mapTransactions, 1800);
});
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=y.test.js.map

File diff suppressed because one or more lines are too long