This commit is contained in:
Mark Nadal 2019-11-08 08:51:17 -08:00
parent 8dc043c44f
commit fa724b5abb
5 changed files with 238 additions and 437 deletions

View File

@ -27,11 +27,13 @@
<div class="hold full hue2">
<div id="page" class="max focus gap" style="padding-top: 9%;">
<p class="loud crack">Docs</p>
<p id="p1">The contemporary tendency in our society is to base our distribution on scarcity, which has vanished, and to compress our abundance into the overfed mouths of the middle and upper classes until they gag with superfluity. If democracy is to have breadth of meaning, it is necessary to adjust this inequity. It is not only moral, but it is also intelligent. We are wasting and degrading human life by clinging to archaic thinking.</p>
<p>The contemporary tendency in our society is to base our distribution on scarcity, which has vanished, and to compress our abundance into the overfed mouths of the middle and upper classes until they gag with superfluity. If democracy is to have breadth of meaning, it is necessary to adjust this inequity. It is not only moral, but it is also intelligent. We are wasting and degrading human life by clinging to archaic thinking.</p>
</div>
</div>
<script src="../../gun/gun.js"></script>
<script src="../../gun/lib/monotype.js"></script>
<script src="../../gun/lib/meta.js"></script>
<script src="../../gun/lib/normalize.js"></script>
<script>
var gun = Gun('https://guntest.herokuapp.com/gun');
@ -40,25 +42,49 @@ var gun = Gun('https://guntest.herokuapp.com/gun');
var S = +new Date;
gun.get('test/gun/docs/'+file).get('what').once(function(data){
console.log(+new Date - S, 'ms load');
$('#p1').text(data);
$('#page').html($.normalize(data));
});
})();
document.execCommand('defaultParagraphSeparator', false, 'p');
meta.edit({
name: "Edit",
combo: ['E'],
on: function(eve){
console.log("TRIGGERED!!!!");
meta.tap.on.attr('contenteditable', 'true');
use: function(eve){
console.log('on');
}, on: function(eve){
meta.flip(false);
console.log('use');
console.log("TRIGGERED!!!!???");
//meta.tap.on.attr('contenteditable', 'true');
$('#page').attr('contenteditable', 'true');
$(document).on('keyup.tmp', '[contenteditable]', function(eve){
if(eve.which != 13){ return true }
console.log(eve.which, $(this).text());
return false;
}).on('keyup.tmp', '[contenteditable]', function(eve){
return;
var p = $(window.getSelection().anchorNode).closest('p');
var r = monotype(p);
var html = p.html() || '';
var safe = $.normalize(html);
console.log("BEFORE:", html);
console.log("AFTER:", safe);
p.html(safe);
r.restore()
});
},
up: function(){}
up: function(){
console.log("UP");
$('[contenteditable=true]').off('.tmp');
}
});
meta.edit({
name: "Save",
combo: ['S'], fake: -1,
on: function(eve){
meta.tap.on.attr('contenteditable', 'false');
var what = $('#p1').text();
var what = $.normalize($('#page').html());
var file = (location.hash||'').slice(1);
gun.get('test/gun/docs/'+file).put({what: what});
},

View File

@ -1,164 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./style.css">
</head>
<body>
<style>
body {
font-family: helvetica;
background-color: rgb(25,25,25);
color: rgb(80,135,25) !important;
font-size: 44px;
text-shadow: 1px 1px 20px rgb(80,150,25);
}
.label {
font-size: 22px;
}
.input {
width: 250px;
height: 30px;
padding:10px;
margin: 5px;
background-color: rgb(50,50,50);
color: rgb(250,50,50);
}
</style>
<input id="url" class="input" placeholder="enter peer stats source url">
<br>
<span class="label">OVERVIEW</span> <br>
<canvas id="overview" width="800" height="200"></canvas>
<br>
<span class="label">TIME ITEMS</span> <br>
<canvas id="timed" width="800" height="200"></canvas>
<br>
<span class="label">MEMORY ITEMS</span> <br>
<canvas id="memed" width="800" height="200"></canvas>
<br>
<span class="label">QTY ITEMS</span> <br>
<canvas id="qtyd" width="800" height="200"></canvas>
<script src="./jquery.js"></script>
<script src="./smoothie.js" charset="utf-8"></script>
<script>
var fetchData = async function() {
// fetch the data from server
var data = await (await fetch(url.value||(location.origin+'/gun/stats.radata'), {method: 'GET',mode: 'cors'})).json();
// test data
/*var writes = [];
var write = [];
write.push(Date.now());
write.push(Math.random()*8);
writes.push(write);
var write = [];
write.push(Date.now());
write.push(Math.random()*8);
writes.push(write);
var mems = [];
var mem = [Date.now(), Math.random()*100];
mems.push(mem);
var data = {
"all":
{
"ms rad write": writes,
"mb rad mem": mems,
}
}*/
// log for user to look at
console.log('data',data.all);
//fetch keys in all, these may be dynamically changing
var keys = Object.keys(data.all);
//for each key, check if we already have created a time series, if not, create it and add it
// to the chart corredsponding to the unit of measure
for(var key of keys) {
// if we have already created, get data and append it.
if(datalines.has(key)){
var line = datalines.get(key);
// and if not
} else {
console.log('creating new series for ', key);
// create a new Series for this key
var line = new TimeSeries();
// add it into the map
datalines.set(key, line);
// add it into overview
overview.addTimeSeries(line,{ strokeStyle:'rgb('+Math.random()*255+', '+Math.random()*255+','+Math.random()*255+')', lineWidth:3 });
// check first two characters of key to determine other charts to add this in
// tbd later
}
// get data and append to line
// get the arrays inside the key
var arr = data.all[key];
//for each array append the data to the line
for(var index in arr) {
// append data [timestamp], [data]
line.append(arr[index][0],arr[index][1]);
}
}
}
var datalines = new Map();
//intialize smoothieCharts
var overview = new SmoothieChart({
tooltip: true,
grid: { strokeStyle:'rgb(69, 100, 8)', fillStyle:'rgb(20, 20, 20)',
lineWidth: 1, millisPerLine: 1000, verticalSections: 6,},
labels: { fillStyle:'rgb(100, 100, 100)' },
timestampFormatter:SmoothieChart.timeFormatter,
minValue: -0.2,
});
overview.streamTo(document.getElementById("overview"), 15 * 1000);
var timed = new SmoothieChart({
tooltip: true,
grid: { strokeStyle:'rgb(69, 100, 8)', fillStyle:'rgb(20, 20, 20)',
lineWidth: 1, millisPerLine: 1000, verticalSections: 6,},
labels: { fillStyle:'rgb(100, 100, 100)' },
timestampFormatter:SmoothieChart.timeFormatter,
minValue: 0,
});
timed.streamTo(document.getElementById("timed"), 15 * 1000);
var memed = new SmoothieChart({
tooltip: true,
grid: { strokeStyle:'rgb(69, 100, 8)', fillStyle:'rgb(20, 20, 20)',
lineWidth: 1, millisPerLine: 1000, verticalSections: 6,},
labels: { fillStyle:'rgb(100, 100, 100)' },
timestampFormatter:SmoothieChart.timeFormatter,
minValue: -1,
});
memed.streamTo(document.getElementById("memed"), 15 * 1000);
var qtyd = new SmoothieChart({
tooltip: true,
grid: { strokeStyle:'rgb(69, 100, 8)', fillStyle:'rgb(20, 20, 20)',
lineWidth: 1, millisPerLine: 1000, verticalSections: 6,},
labels: { fillStyle:'rgb(100, 100, 100)' },
timestampFormatter:SmoothieChart.timeFormatter,
minValue: 0,
});
qtyd.streamTo(document.getElementById("qtyd"), 15 * 1000);
// Add a random value to each line every second
setInterval(fetchData, 15 * 1000);
fetchData();
</script>
</body>
</html>

View File

@ -2,161 +2,93 @@
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./style.css">
<link rel="stylesheet" href="./style.css">
</head>
<body>
<style>
@import url('https://fonts.googleapis.com/css?family=Oxygen');
html, body {
font-family: "Oxygen", sans-serif;
}
svg, .ct-chart * {
overflow: visible;
}
.ct-series-a .ct-line,
.ct-series-a .ct-point {
str-oke: blue !important;
body {
font-family: helvetica;
background-color: rgb(25,25,25);
color: rgb(80,135,25) !important;
text-shadow: 1px 1px 20px rgb(80,150,25);
}
.ct-series-b .ct-line,
.ct-series-b .ct-point {
stroke: green !important;
}
.label {
position: absolute;
left: 0.5em;
top: 1.75em;
}
.tall { height: 10em; }
.input {
height: 30px;
padding:10px;
background-color: rgb(50,50,50);
color: rgb(250,50,50);
}
.tall { height: 5em; }
</style>
<input id="url" class="center none" placeholder="enter peer stats source url">
<div class="center"><span class="shout" id="peers">0</span> peers <span class="shout" id="time">0</span> min <span class="shout" id="nodes">0</span> nodes <span class="shout" id="hours">0</span> hours</div>
<div class="leak" style="padding: 0 2em;">
<div class="leak ct-mem ct-chart ct-perfect-fourth tall"></div>
<input id="url" class="center input crack" placeholder="enter peer stats source url">
<div class="center row charts">
</div>
<div class="center leak" style="padding: 0 2em;">
<div class="unit col leak ct-damc ct-chart tall" style="width: 49%;"></div>
<div class="unit col leak ct-damd ct-chart tall" style="width: 49%;"></div>
<div class="model none">
<div class="chart"><span class="label"></span><canvas class="tall row"></canvas></div>
</div>
<div class="center leak" style="padding: 0 2em;">
<div class="unit col leak ct-radc ct-chart tall" style="width: 49%;"></div>
<div class="unit col leak ct-radt ct-chart tall" style="width: 49%;"></div>
</div>
<div class="center"><span id="rerr"></span></div>
<div class="center leak" style="padding: 0 2em;">
<div class="leak ct-daml ct-chart tall"></div>
</div>
<div class="center leak" style="padding: 0 2em;">
<div class="leak ct-cpu ct-chart ct-perfect-fourth tall"></div>
</div>
<script src="./jquery.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">
<script src="https://cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>
<script src="./smoothie.js" charset="utf-8"></script>
<script>
var stats = {slide: [0,0,0,0,0], din: [0,0,0,0,0], dout: [0,0,0,0,0], dind: [0,0,0,0,0], doutd: [0,0,0,0,0], rgetc: [0,0,0,0,0], rputc: [0,0,0,0,0]};
setInterval(function(){
stats.show();
}, 1000 * 15);
stats.show = async function(data){ //$.getJSON(url.value||(location.origin+'/gun/stats.radata'), function(data){ console.log(data);
data = await (await fetch(url.value||(location.origin+'/gun/stats.radata'), {method: 'GET',mode: 'cors'})).json();
console.log(data);
$('#peers').text(data.peers.count);
$('#time').text((data.peers.time / 1000 / 60).toFixed(0));
$('#nodes').text(data.node.count);
$('#hours').text((data.up.time / 60 / 60).toFixed(0));
var fetchData = async function(){
// fetch the data from server
var data = await (await fetch(url.value||(location.origin+'/gun/stats.radata'), {method: 'GET',mode: 'cors'})).json();
$('#peers').text(data.peers.count);
$('#time').text((data.peers.time / 1000 / 60).toFixed(0));
$('#nodes').text(data.node.count);
$('#hours').text((data.up.time / 60 / 60).toFixed(0));
$('#dinc').text(data.dam.in.count);
$('#dind').text((data.dam.in.done / 1024 / 1024).toFixed(1));
$('#doutc').text(data.dam.out.count);
$('#doutd').text((data.dam.out.done / 1024 / 1024).toFixed(1));
Stats('memory').line.append(+new Date, data.memory.heapTotal / 1024 / 1024);
stats.slide.push(data.memory.heapTotal / 1024 / 1024); stats.slide = stats.slide.slice(1);
new Chartist.Line('.ct-mem', {
// A labels array that can contain any sort of values
labels: ['-1min', '-45s', '-30s', '-15s', '0'],
// Our series array that contains series objects or in this case series data arrays
series: [stats.slide]
}, {fullWidth: true, low: 0, axisY: {
labelInterpolationFnc: function(v) { return v+'MB' }
}});
console.log('data',data);
//fetch keys in all, these may be dynamically changing
//for each key, check if we already have created a time series, if not, create it and add it
// to the chart corredsponding to the unit of measure
$.each(data.all, function(key, arr){
var chart = Stats(key);
// get data and append to line
// get the arrays inside the key
//for each array append the data to the line
for(var i in arr) {
// append data [timestamp], [data]
chart.line.append(arr[i][0], arr[i][1]);
}
})
}
setInterval(fetchData, 15 * 1000);
fetchData();
stats.din.push(data.dam['in'].count); stats.din = stats.din.slice(1);
stats.dout.push(data.dam.out.count); stats.dout = stats.dout.slice(1);
new Chartist.Line('.ct-damc', {
// A labels array that can contain any sort of values
labels: ['-1min', '-45s', '-30s', '-15s', '0'],
// Our series array that contains series objects or in this case series data arrays
series: [stats.dout, stats.din]
}, {fullWidth: true, axisY: {
labelInterpolationFnc: function(v) { return v+'msgs' }
}});
stats.dind.push(data.dam['in'].done / 1024 / 1024); stats.dind = stats.dind.slice(1);
stats.doutd.push(data.dam.out.done / 1024 / 1024); stats.doutd = stats.doutd.slice(1);
new Chartist.Line('.ct-damd', {
// A labels array that can contain any sort of values
labels: ['-1min', '-45s', '-30s', '-15s', '0'],
// Our series array that contains series objects or in this case series data arrays
series: [stats.doutd, stats.dind]
}, {fullWidth: true, axisY: {
labelInterpolationFnc: function(v) { return v+'MB' }
}});
try{ $('#rerr').text(data.rad.put.err || data.rad.get.err) }catch(e){}
try{
stats.rgetc.push(data.rad.get.count); stats.rgetc = stats.rgetc.slice(1);
stats.rputc.push(data.rad.put.count); stats.rputc = stats.rputc.slice(1);
new Chartist.Line('.ct-radc', {
// A labels array that can contain any sort of values
labels: ['-1min', '-45s', '-30s', '-15s', '0'],
// Our series array that contains series objects or in this case series data arrays
series: [stats.rputc, stats.rgetc]
}, {fullWidth: true, axisY: {
labelInterpolationFnc: function(v) { return v+'io' }
}});
}catch(e){}
try{
stats.radgt = Object.values(data.rad.get.time).map(function(n){ return n/1000 });
stats.radpt = Object.values(data.rad.put.time).map(function(n){ return n/1000 });
new Chartist.Line('.ct-radt', {
// A labels array that can contain any sort of values
//labels: ['-1min', '-45s', '-30s', '-15s', '0'],
// Our series array that contains series objects or in this case series data arrays
series: [stats.radpt, stats.radgt]
}, {fullWidth: true, axisY: {
labelInterpolationFnc: function(v) { return v+'sec' }
}});
}catch(e){}
try{
stats.daml = Object.values(data.dam['in'].long).map(function(n){ return n });
new Chartist.Line('.ct-daml', {
// A labels array that can contain any sort of values
//labels: ['-1min', '-45s', '-30s', '-15s', '0'],
// Our series array that contains series objects or in this case series data arrays
series: [stats.daml]
}, {fullWidth: true, axisY: {
labelInterpolationFnc: function(v) { return v+'ms' }
}});
}catch(e){}
new Chartist.Line('.ct-cpu', {
// A labels array that can contain any sort of values
labels: ['-15min', '-5min', '1min'],
// Our series array that contains series objects or in this case series data arrays
series: [data.cpu.loadavg.reverse()]
}, {fullWidth: true, low: 0, axisY: {
labelInterpolationFnc: function(v) { return v+'cpu' }
}});
//})
}
stats.show();
function Stats(key, chart){
// if we have already created, get data to append to it.
if(chart = Stats[key]){
return chart;
}
// create a new Series for this key
// add it into the map
chart = Stats[key] = new SmoothieChart({responsive: true, minValue: 0, grid:{strokeStyle:'rgba(100%,100%,100%,0.2)'},labels:{fontSize:20}});
chart.line = new TimeSeries();
chart.addTimeSeries(chart.line,{ strokeStyle:'rgb('+Math.random()*255+', '+Math.random()*255+','+Math.random()*255+')', lineWidth:5 });
chart.canvas = $('.model').find('.chart').clone(true).appendTo('.charts');
chart.canvas.find('span').text(key);
chart.streamTo(chart.canvas.find('canvas').get(0), 15 * 1000);
// check first two characters of key to determine other charts to add this in
// tbd later
return chart;
}
</script>
</body>
</html>

View File

@ -16,133 +16,131 @@
if(typeof module !== "undefined"){ var common = module }
;USE(function(module){
var noop = function(){}, u;
$.fn.or = function(s){ return this.length ? this : $(s||'body') };
var m = window.meta = {edit:[]};
var k = m.key = {};
k.meta = {17:17, 91:17, 93:17, 224:17};
k.down = function(eve){
if(eve.repeat){ return }
var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
if(!eve.fake && key === k.last){ return } k.last = key;
if(!eve.fake && $(eve.target).closest('input, textarea, [contenteditable=true]').length){
if(k.meta[key]){ k.down.meta = key = -1 }
if(!k.down.meta){ return }
}
(k.combo || (k.combo = [])).push(key);
m.check('on', key, k.at || (k.at = m.edit));
if(k.meta[key]){
m.list(k.at.back || m.edit);
if(k.at && !k.at.back){ m.flip() }
}
var noop = function(){}, u;
$.fn.or = function(s){ return this.length ? this : $(s||'body') };
var m = window.meta = {edit:[]};
var k = m.key = {};
k.meta = {17:17, 91:17, 93:17, 224:17};
k.down = function(eve){
if(eve.repeat){ return }
var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
if(!eve.fake && key === k.last){ return } k.last = key;
if(!eve.fake && $(eve.target).closest('input, textarea, [contenteditable=true]').length){
if(k.meta[key]){ k.down.meta = key = -1 }
if(!k.down.meta){ return }
}
k.up = function(eve){ var tmp;
var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
if(!eve.fake && $(eve.target).closest('input, textarea, [contenteditable=true]').length){
(k.combo || (k.combo = [])).push(key);
m.check('on', key, k.at || (k.at = m.edit));
if(k.meta[key]){
k.down.meta = null;
key = -1;
} else
if(!k.down.meta){ return }
}
k.last = null;
if($(':focus').closest('#meta').length){ return }
m.check('up', key);
if(-1 === key || 27 === eve.which){ k.wipe() }
}
m.flip = function(tmp){
var board = $('#meta .meta-menu');
((tmp === false) || (!tmp && board.is(':visible')))?
board.addClass('meta-none')
: board.removeClass('meta-none');
}
m.flip.is = function(){
return $('#meta .meta-menu').is(':visible');
}
m.flip.wait = 500;
m.check = function(how, key, at){
at = k.at || m.edit;
var edit = at[key];
if(!edit){ return }
var tmp = k.eve || noop;
if(tmp.preventDefault){ tmp.preventDefault() }
if(edit[how]){
if(tmp.fake && !edit.fake){
m.tap.edit = edit;
} else {
edit[how](m.eve);
/*if(k.at !== m.edit && 'up' === how){
if(k.down.meta){ m.list(k.at = m.edit) }
else { k.wipe() }
}*/
m.list(k.at.back || m.edit);
if(k.at && !k.at.back){ m.flip() }
}
}
if('up' != how){ return }
if(at != edit){ edit.back = at }
m.list(edit, true);
k.up = function(eve){ var tmp;
var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
if(!eve.fake && $(eve.target).closest('input, textarea, [contenteditable=true]').length){
if(k.meta[key]){
k.down.meta = null;
key = -1;
} else
if(!k.down.meta){ return }
}
m.list = function(at, opt){
if(!at){ return m.flip(false) }
var l = [];
$.each(at, function(i,k){ 'back' != i && k.combo && k.name && l.push(k) });
if(!l.length){ return }
k.at = at;
l = l.sort(function(a,b){
a = a.combo.slice(-1)[0] || 0;
if(a.length){ a = a.toUpperCase().charCodeAt(0) }
b = b.combo.slice(-1)[0] || 0;
if(b.length){ b = b.toUpperCase().charCodeAt(0) }
return (a < b)? -1 : 1;
});
var $ul = $('#meta .meta-menu ul')
$ul.children('li').addClass('meta-none').hide(); setTimeout(function(){ $ul.children('.meta-none').remove() },250); // necessary fix for weird bug glitch
$.each(l, function(i, k){
$ul.append($('<li>').text(k.name));
});
if(opt){ m.flip(true) }
$ul.append($('<li>').html('&larr;').one('click', function(){
m.list(k.at = at.back);
}));
k.last = null;
if($(':focus').closest('#meta').length){ return }
m.check('up', key);
if(-1 === key || 27 === eve.which){ k.wipe() }
}
m.flip = function(tmp){
var board = $('#meta .meta-menu');
((tmp === false) || (!tmp && board.is(':visible')))?
board.addClass('meta-none')
: board.removeClass('meta-none');
}
m.flip.is = function(){
return $('#meta .meta-menu').is(':visible');
}
m.flip.wait = 500;
m.check = function(how, key, at){
at = k.at || m.edit;
var edit = at[key];
if(!edit){ return }
var tmp = k.eve || noop;
if(tmp.preventDefault){ tmp.preventDefault() }
if(edit[how]){
//if(tmp.fake && !edit.fake){
//m.tap.edit = edit;
//} else {
edit[how](m.eve);
/*if(k.at !== m.edit && 'up' === how){
if(k.down.meta){ m.list(k.at = m.edit) }
else { k.wipe() }
}*/
//}
}
m.ask = function(help, cb){
var $ul = $('#meta .meta-menu ul').empty();
var $put = $('<input>').attr('id', 'meta-ask').attr('placeholder', help);
var $form = $('<form>').append($put).on('submit', function(eve){
eve.preventDefault();
cb($put.val());
$li.remove();
k.wipe();
});
var $li = $('<li>').append($form);
$ul.append($li);
m.flip(true);
$put.focus();
}
k.wipe = function(opt){
k.down.meta = false;
k.combo = [];
if(!opt){ m.flip(false) }
m.list(k.at = m.edit);
};
m.tap = function(){
var on = $('.meta-on')
.or($($(document.querySelectorAll(':hover')).get().reverse()).first())
.or($(document.elementFromPoint(meta.tap.x, meta.tap.y)));
return on;
}
meta.edit = function(edit){
var tmp = edit.combow = [];
$.each(edit.combo || (edit.combo = []), function(i,k){
if(!k || !k.length){ if('number' == typeof k){ tmp.push(k) } return }
tmp.push(k.toUpperCase().charCodeAt(0));
});
var at = meta.edit, l = edit.combo.length;
$.each(tmp, function(i,k){ at = at[k] = (++i >= l)? edit : at[k] || {} });
edit.combow = edit.combow.join(',');
m.list(meta.edit);
}
if('up' != how){ return }
if(at != edit){ edit.back = at }
m.list(edit, true);
}
m.list = function(at, opt){
if(!at){ return m.flip(false) }
var l = [];
$.each(at, function(i,k){ 'back' != i && k.combo && k.name && l.push(k) });
if(!l.length){ return }
k.at = at;
l = l.sort(function(a,b){
a = a.combo.slice(-1)[0] || 0;
if(a.length){ a = a.toUpperCase().charCodeAt(0) }
b = b.combo.slice(-1)[0] || 0;
if(b.length){ b = b.toUpperCase().charCodeAt(0) }
return (a < b)? -1 : 1;
});
var $ul = $('#meta .meta-menu ul')
$ul.children('li').addClass('meta-none').hide(); setTimeout(function(){ $ul.children('.meta-none').remove() },250); // necessary fix for weird bug glitch
$.each(l, function(i, k){
$ul.append($('<li>').text(k.name).data(k));
});
if(opt){ m.flip(true) }
$ul.append($('<li>').html('&larr;').one('click', function(){
m.list(k.at = at.back);
}));
}
m.ask = function(help, cb){
var $ul = $('#meta .meta-menu ul').empty();
var $put = $('<input>').attr('id', 'meta-ask').attr('placeholder', help);
var $form = $('<form>').append($put).on('submit', function(eve){
eve.preventDefault();
cb($put.val());
$li.remove();
k.wipe();
});
var $li = $('<li>').append($form);
$ul.append($li);
m.flip(true);
$put.focus();
}
k.wipe = function(opt){
k.down.meta = false;
k.combo = [];
if(!opt){ m.flip(false) }
m.list(k.at = m.edit);
};
m.tap = function(){
var on = $('.meta-on')
.or($($(document.querySelectorAll(':hover')).get().reverse()).first())
.or($(document.elementFromPoint(meta.tap.x, meta.tap.y)));
return on;
}
meta.edit = function(edit){
var tmp = edit.combow = [];
$.each(edit.combo || (edit.combo = []), function(i,k){
if(!k || !k.length){ if('number' == typeof k){ tmp.push(k) } return }
tmp.push(k.toUpperCase().charCodeAt(0));
});
var at = meta.edit, l = edit.combo.length;
$.each(tmp, function(i,k){ at = at[k] = (++i >= l)? edit : at[k] || {} });
edit.combow = edit.combow.join(',');
m.list(meta.edit);
}
})(USE, './metaCore');
;USE(function(module){
try{
@ -235,8 +233,7 @@
tag.innerHTML = tmp;
document.body.appendChild(tag);
}
}catch(e){}
}catch(e){}
})(USE, './metaUI');
;USE(function(module){
// include basic text editing by default.
@ -380,8 +377,6 @@
on: function(eve){ meta.text.editor('fontSize', 7) },
up: function(){}
});
})(USE, './metaText');
;USE(function(module){
var m = meta, k = m.key;
@ -399,6 +394,11 @@
});
$(document).on('touchstart', '#meta .meta-start', function(eve){ m.tap.stun = true });
$(document).on('click', '#meta .meta-menu li', function(eve){
eve.fake = eve.which = $(this).data().combo.slice(-1)[0].charCodeAt(0);
eve.tap = true;
k.down(eve);
//k.up(eve);
return;
if(m.tap.stun){ return m.tap.stun = false }
if(!(eve.fake = eve.which = (($(this).text().match(/[A-Z]/)||{})[0]||'').toUpperCase().charCodeAt(0))){ return }
eve.tap = true;
@ -407,7 +407,5 @@
});
$(document).on('keydown', k.down).on('keyup', k.up);
$(document).on('select contextmenu keyup mouseup', '[contenteditable=true]', m.text.on);
})(USE, './metaEvents');
}());

17
sea.js
View File

@ -964,6 +964,7 @@
}
// If authenticated user wants to delete his/her account, let's support it!
User.prototype.delete = async function(alias, pass, cb){
console.log("user.delete() IS DEPRECATED AND WILL BE MOVED TO A MODULE!!!");
var gun = this, root = gun.back(-1), user = gun.back('user');
try {
user.auth(alias, pass, function(ack){
@ -1005,6 +1006,7 @@
return gun;
}
User.prototype.alive = async function(){
console.log("user.alive() IS DEPRECATED!!!");
const gunRoot = this.back(-1)
try {
// All is good. Should we do something more with actual recalled data?
@ -1024,25 +1026,32 @@
console.log(ctx, ev)
})
}
user.get('trust').get(path).put(theirPubkey);
// do a lookup on this gun chain directly (that gets bob's copy of the data)
// do a lookup on the metadata trust table for this path (that gets all the pubkeys allowed to write on this path)
// do a lookup on each of those pubKeys ON the path (to get the collab data "layers")
// THEN you perform Jachen's mix operation
// and return the result of that to...
}
User.prototype.grant = function(to, cb){
console.log("`.grant` API MAY BE DELETED OR CHANGED OR RENAMED, DO NOT USE!");
var gun = this, user = gun.back(-1).user(), pair = user.pair(), path = '';
var gun = this, user = gun.back(-1).user(), pair = user._.sea, path = '';
gun.back(function(at){ if(at.is){ return } path += (at.get||'') });
(async function(){
var enc, sec = await user.get('trust').get(pair.pub).get(path).then();
var enc, sec = await user.get('grant').get(pair.pub).get(path).then();
sec = await SEA.decrypt(sec, pair);
if(!sec){
sec = SEA.random(16).toString();
enc = await SEA.encrypt(sec, pair);
user.get('trust').get(pair.pub).get(path).put(enc);
user.get('grant').get(pair.pub).get(path).put(enc);
}
var pub = to.get('pub').then();
var epub = to.get('epub').then();
pub = await pub; epub = await epub;
var dh = await SEA.secret(epub, pair);
enc = await SEA.encrypt(sec, dh);
user.get('trust').get(pub).get(path).put(enc, cb);
user.get('grant').get(pub).get(path).put(enc, cb);
}());
return gun;
}