gun/lib/meta.js
Mark Nadal 087704ec6b
Begin 1 Years worth of Merges... (#1116)
* tmp for hn issue

* log top to stats

* test for guntest peer

* try big messages

* parse time?

* what bin/node is 11ms?

* be normal for hnoon

* tolerate 0.5s

* try 3s for hnoon?

* stop empty gets

* tmp for guntest

* back to normal

* check hash time

* back to normal in hear

* screen / upload / play / pause

* merge latest npm release into manhattan

* merge master 0.2020.421 into manhattan manually

* WIP

* manually merge from master

* gatling

* Update upload.html

* work in progress...

* yson panic chat basic

* after `.put(` walk

* restructure acks

* messy but 2 units passing!

* put recursive once on map

* basics

* have NTS use DAM + fix other utils

* Rewrote nts

* Allow passing test cli args.

Before, no CLI args would be passed when running `npm test`. Keeping the `mocha` at the end of the test script allows passing CLI args to Mocha.

* put back scan & once tweak

* PANIC user paste OK

* manhattan sea

* stub out nts for now

* AXE tweak

* tweak for quick first prod testing

* tweak for first in-prod testing

* tweak

* tweak

* sketchy in-prod debug attempt

* caught it? maybe? now restore

* Create download-log.html

* stub out yson test prod?

* ugh, gotta see what is going on

* move dl

* gonna stop doing commit messages for in-prod test/tweaks/debugging

* a

* p

* squelch

* console stats

* stats

* stop travis

* restore yson

* ahhh no file access without sudo

* mem

* no stub

* fix axe

* bump

* back to in-prod testing, isolate/stub out code

* stub all out for 17K ? CPU ? test

* stub dup gc

* ugh main stub

* does this stop url format blocking?

* re-add dup

* no top :(

* will this work?

* get ack stats?

* a map chain may ask for data not a root soul chain

* move proper logic into .get(

* how 2019 compat?

* a couple more!

* more tests passing! :D :)

* even more! SO EXCITING :D

* Am I alive?

* wow I can't believe it works like this

* THANK YOU @rogowski !!!!!!

* Create trace.html

Adding tracing to debuging.

* @rogowski is a super star :) :) :)

* Update trace.js

Change `Gun.logs` to `Gun.traces` and `Gun._log` to `Gun._trace`.

* Update trace.html

Change `Gun.logs` to `Gun.traces` and `Gun._log` to `Gun._trace`.
Overload get,put,on,map

* @rogowski approved of these trace changes :)

* Update trace.html

More decoupled.

* Update trace.js

More decoupled

* 2 steps backwards, 1 step forward?

* back where we ( @rogowski ) started :P

* YAYAYAYAYAYAYAY past where we started at!

* safer to have it here

* slight tweak? Let's see how long it lasts.

* merge checks we left out during consolidation

* ugly common.js for @rogowski

* slightly better

* amazing map discovery + don't clear on not found if data exists

* onto next test...

* all caught up!!! Now update tests from graphify to statedisk

* Update common.js

Tests updated from graphify to statedisk.

* easy to debug & fix thanks to @rogowski 's test upgrades & trace!

* hmm, IDK if we should support this anymore?

* support once chaining?

* check if listener order is earlier than write

* in-process message passing needs to clean itself of flags for now

* ack to chains that can't be reached

* call sub chains on clear/empty WIP

* call sub chains clear/empty OK!

* into unlink. Clean/refactor later.

* oh that was nice

* self check not needed?

* test was poorly constructed?

* refactor unlink to cleaner logic

* Will you blame me for this? Special case, maybe later move to cleaner place?

* use stun's run id instead.

* cleaner unlink logic

* better map, link, and unlink logic.

* unstub relay

* refactor unlink

* invert

* if prev value would have caused unlink, do not unlink again.

* w000h00! Best unlink so far.

* woops, fix unlinking nested

* unsubscribe nested maps (working, tho possible perf regression? check)

* put check soul

* add default uuid

* improved browser peer retry logic, let devices sleep, etc.

* Chaining API unit tests passing!

* merge new panic tests into here to test

* add panic utils

* fix long streaming timeout/expiry issue, update examples

* yield generating test data

* yeah, adapter errors (like out of storage) should not affect sync/networking logic, that was a bad experiment

* git glitch?

* some mid debugging fixes but maybe scary changes, hopefully safe to revert here except dub

* SEA unit tests passing!!! Needed quite a few fixes on async write queue stuff.

* optionally make auth async

* revise/correct set

* Fix reverse boundary check

* Add extra tests, catch bad guy, obliterate bug.

* chat app with emoji examples

* handle empty string keyed objects

* starting lex support

* tweak for lex

* woops! lexical alphabetical oopsies. That was bad.

* upload either way

* debug

* start

* fix

* fix

* clean + feature

* update dependencies in package.json (#1086)

* rad lex once map once

* axe polyfill for now

* oops log

* oops maybe without this it crashed the peer

* what on earth happened to my browser/OS? "unplug & plug it back in" restart seemed to fix it.

* oh, don't memory leak req/res asks. :/ duh!

* no accidental #soul.""

* ugh, still have to sort :(, really should polyfill weakmap then

* oops, pluck needs new object to go into

* oops, make sure soul is passed

* updating deprecated functions

* begin AXE. Next: load balance!

* Update sea.js

* keys are dangerous!

* AXE round robin load balance

* better ash hash checking

* lS reuse in-mem reply chunking

* state machine!!!

* RAD needs to pass cache misses.

* updating deprecated functions (#1088)

* update dependencies in package.json

* updating deprecated functions

* remove where.gundb.io

* Bring SEA.certify into manhattan branch (#1092)

Co-authored-by: Radu Cioienaru <radu@projectmanager.com>

* fix rad, make get() hookable

* rad browser tests seem to be passing!

* reverse user random side, add err, update styles, + more

* fix pack/max, update dom

* paste!

* of course it'll dedup cause it just called track on hear, fix

* 📦 Adding the hub feature to this branch & improvements. (#1102)

* 📦 Adding the hub feature to this branch.

* 🗑 Removed the container for speed improvement !

* 📝 I added some comments to the code.

Co-authored-by: Hector <fairfairytotor@gmail.com>
Co-authored-by: Hector <pro.hector.kub@gmail.com>

* Update axe.js

* 🦅 Wrap everything in a try & catch for error handling…  (#1105)

* 🦅 Wrap everything in a try & catch for error handling & speed improvement.

* 📦 Finally here : opt.file for the hub feature !

* 📦 Finally here : opt.file for the hub feature !

And also : fixed indentation 😋

Co-authored-by: noctisatrae <pro.hector.kub@gmail.com>

* probs better this way, safer

* moved test/axe tests to test/panic/axe.

* New test: axe load balance.

* axe test: webrtc data balance(fix paths and file renamed).

* test axe: renaming webrtc file.

* axe test: separating webrtc test for data_balance.

* axe test: test only with the relay(without webrtc).

* Update sea.js

Same as https://github.com/amark/gun/pull/1062

* Update gun.js

var tmp

* Update upload.js

* merge, update stun

* SEA.certify wire logic + unit tests (#1110)

* SEA.certify wire logic + unit tests

* picking white hair

* ack err

* axe tests using puppeteer.

* change stun system

* ~20lines

* put use parent soul link if need

* handle errors

* finally seems fixed

* cb not to

* relay

* nasty bug! Don't crash, tho need to find what causes it

* undo local changes/notes to self

* deprecation warnings

* "old" data to test against

* oops, forgot I played with ascii

* debug

* in-prod check: sites

* in-prod isolate

* gotta find this, by stubbing out

* where?

* will this work?

* clearly not, lol what's the point then? maybe like this

* and again

* must we?

* USE THIS MANHATTAN VERSION

* clean

* better panic hints

Co-authored-by: Robin Bron <finwo@pm.me>
Co-authored-by: Pavel Diatchenko <diatche@users.noreply.github.com>
Co-authored-by: rogowski <163828+rogowski@users.noreply.github.com>
Co-authored-by: I001962 <i001962@gmail.com>
Co-authored-by: Adriano Rogowski <rogowski.adriano@gmail.com>
Co-authored-by: Radu <cetatuie@gmail.com>
Co-authored-by: Radu Cioienaru <radu@projectmanager.com>
Co-authored-by: Hector <46224745+noctisatrae@users.noreply.github.com>
Co-authored-by: Hector <fairfairytotor@gmail.com>
Co-authored-by: Hector <pro.hector.kub@gmail.com>
Co-authored-by: Martti Malmi <sirius@iki.fi>
Co-authored-by: mimiza <dev@mimiza.com>
2021-08-21 21:19:29 -07:00

298 lines
9.1 KiB
JavaScript

;(function(){
function USE(arg, req){
return req? require(arg) : arg.slice? USE[R(arg)] : function(mod, path){
arg(mod = {exports: {}});
USE[R(path)] = mod.exports;
}
function R(p){
return p.split('/').slice(-1).toString().replace('.js','');
}
}
if(typeof module !== "undefined"){ var MODULE = module }
/* UNBUILD */
;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, 18: 17}; // ALT added
function withMeta(eve){ return eve.metaKey || eve.ctrlKey || eve.altKey } // ALT added
k.down = function(eve){
var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
if(eve.repeat){ return }
if(!k.meta[key] && withMeta(eve) && !k.at[key]) {
return m.flip(false)
} // cancel and close when no action and "meta key" held down (e.g. ctrl+c)
if(!eve.fake && key === k.last){ return }; k.last = key; // jussi: polyfilling eve.repeat?
if(!eve.fake && $(eve.target).closest('input, textarea, [contenteditable=true]').length/* && !$(eve.target).closest('#meta').get().length*/){
return;
//if(meta.flip.is() && !withMeta(eve)) eve.preventDefault()
}
m.check('on', key, k.at || (k.at = m.edit));
if(k.meta[key]){ m.flip() }
}
k.down.keys = {} // currently pressed keys
k.up = function(eve){ var tmp;
var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
k.last = null;
m.check('up', key);
if(k.meta[key] && m.check.fired){
m.close()
}
}
m.flip = function(tmp){
m.flip.active = true;
((tmp === false) || (!tmp && m.ui.board.is(':visible')))?
m.close() : m.open();
m.flip.active = false;
}
m.open = function(){
m.check.fired = null;
m.ui.board.removeClass('meta-none');
}
m.close = function(){
Object.keys(k.down.keys).forEach((keyDown) => {
m.check('up', keyDown);
})
m.ui.board.addClass('meta-none')
}
m.flip.is = function(){
return m.ui.board.is(':visible');
}
m.flip.wait = 500;
m.check = function(how, key, at){
if(!m.flip.is() && !k.meta[key]){ return } // TEMP: cancel non-open events when closed TODO make optional
at = k.at || m.edit;
var next = at[key];
if(!next){ return }
var tmp = k.eve || noop;
if(tmp.preventDefault){ tmp.preventDefault()} // prevent typing (etc) when action found
if(next[how]){
next[how](m.eve);
meta.ui.blink();
m.check.fired = true;
if(how == 'up') delete k.down.keys[key]
else k.down.keys[key] = 1;
}
if('up' == how){ return }
if(at != next && !next.back){ next.back = at }
(k.combo || (k.combo = [])).push(key);
m.list(next, true);
}
function defaultSort(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;
}
m.list = function(at, opt){
if(!at){ return m.flip(false) }
var l = [];
$.each(at, function(i,k){ 'back' != i && k && k.combo && k.name && l.push(k) });
if(!l.length){ return }
k.at = at;
if(at.sort !== null){ l = l.sort(at.sort || defaultSort) }
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){
var $li = $('<li>').text(k.name).data(k)
$ul.append($li);
if(k.styles) meta.ui.iniline($li[0], k.styles);
});
if(opt){ m.flip(true) }
$ul.append($('<li>').html('&larr;').on('click', back));
}
m.ask = function(help, cb, opt){
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();
});
if(opt){
$form.on('keyup', function(eve){ cb($put.val()) })
}
var $li = $('<li>').append($form);
$ul.append($li);
m.flip(true);
$put.focus();
}
k.wipe = function(opt){
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(e){
var path = [];
$.each(e.combo || (e.combo = []), function(i,k){
if(!k || !k.length){ if('number' == typeof k){ path.push(k) } return }
path.push(k.toUpperCase().charCodeAt(0));
});
var at = meta.edit, l = e.combo.length;
$.each(path, function(i,k){ at = at[k] = at[k] || Object.create(defaults) });
$.extend(at, e) // fixes overwriting when sub action is defined before parent
e.combow = path.join(','); // deprecate?
m.list(k.at || meta.edit);
}
function back(){ // close root or go back on submenu
k.at == m.edit ? m.flip(false) : m.check('down', 'back')
}
var defaults = {
8: { on: back }, // backspace
27: { up: k.wipe } // esc: close and reset menu
}
$.extend(meta.edit, defaults)
})(USE, './metaCore');
;USE(function(module){
/* UI */
meta.ui = {
blink: function(){ // hint visually that action has happened
$('#meta').css('transition', 'none').css('background', 'none')
setTimeout(function(){
$('#meta')[0].style.transition = null
$('#meta')[0].style.background = null
})
},
depth: function(n){
if (n) {
$('#meta').css('background', 'hsl(60, 100%,'+(85-(n*10))+'%)');
} else {
$('#meta')[0].style.background = null
}
}
}
var $m = $('<div>').attr('id', 'meta');
//$m.append($('<span>').html('&#9776;').addClass('meta-start'));
$m.append($('<span>').html('+').addClass('meta-start'));
$m.append($('<div>').addClass('meta-menu meta-none').append('<ul>'));
$m.on('mouseenter', function(){
if (meta.flip.active || meta.flip.is()) return;
meta.flip();
})
$m.on('mouseleave', function(){
if (meta.flip.active || !meta.flip.is()) return;
meta.flip(false);
})
$(document.body).append($m);
meta.ui.board = $('.meta-menu', $m);
css({
'#meta': {
display: 'block',
position: 'fixed',
bottom: '2em',
right: '2em',
'font-size': '18pt',
'font-family': 'Tahoma, arial',
'border-radius': '1em',
'text-align': 'center',
'z-index': 999999,
margin: 0,
padding: 0,
width: '2em',
height: '2em',
outline: 'none',
overflow: 'visible',
background: 'rgba(0,0,0,0.5)', color: 'white',
transition: 'all 0.2s ease-in'
},
'#meta *': {outline: 'none'},
'#meta .meta-none': {display: 'none'},
'#meta span': {'line-height': '2em'},
'#meta .meta-menu': {
background: 'rgba(0,0,0,0.2)',
width: '12em',
right: '-2em',
bottom: '-2em',
overflow: 'visible',
position: 'absolute',
'overflow-y': 'scroll',
'text-align': 'right',
'min-height': '20em',
height: '100vh'
},
'#meta .meta-menu ul': {
padding: 0,
margin: '1em 1em 2em 0',
'list-style-type': 'none'
},
'#meta .meta-menu ul li': {
display: 'block',
'float': 'right',
padding: '0.5em 1em',
'border-radius': '1em',
'margin-left': '0.25em',
'margin-top': '0.25em',
background: 'rgba(0,0,0,0.2)', 'backdrop-filter': 'blur(10px)', color: 'white',
'cursor': 'pointer'
},
'#meta .meta-menu ul li:hover': {
background: 'rgba(0,0,0,0.5)'
},
'#meta a': {color: 'black'},
'#meta:hover': {opacity: 1},
'#meta:hover .meta-menu': {display: 'block'},
'#meta .meta-menu ul:before': {
content: "' '",
display: 'block',
'min-height': '15em',
height: '50vh'
},
'#meta .meta-start': {
cursor: 'pointer'
}
});
function css(css){
var tmp = '';
$.each(css, function(c,r){
tmp += c + ' {\n';
$.each(r, function(k,v){
tmp += '\t'+ k +': '+ v +';\n';
});
tmp += '}\n';
});
var tag = document.createElement('style');
tag.innerHTML = tmp;
$m.append(tag)
}
meta.ui.iniline = function(el, cssObj){
for(var k in cssObj) { el.style[k] = cssObj[k]; }
}
})(USE, './metaUI');
;USE(function(module){
var m = meta, k = m.key;
//$(window).on('focus', k.wipe.bind(null, false)); // .on('blur', k.wipe.bind(null, false))
$(document).on('mousedown mousemove mouseup', function(eve){
m.tap.eve = eve;
m.tap.x = eve.pageX||0;
m.tap.y = eve.pageY||0;
m.tap.on = $(eve.target);
})
var [start, end] = 'ontouchstart' in window
? ['touchstart', 'touchend']
: ['mousedown', 'mouseup']
$(document).on(start, '#meta .meta-menu li', function(eve){
var combo = $(this).data().combo;
eve.fake = eve.which = combo && combo.slice(-1)[0].toUpperCase().charCodeAt(0);
eve.tap = true;
k.down(eve);
$(document).one(end, () => k.up(eve))
return;
});
$(document).on('keydown', k.down).on('keyup', k.up);
$('#meta').on(start, function(ev) {
if (ev.target.tagName == 'LI' || ev.target.tagName == 'UL') return
meta.flip()
})
})(USE, './metaEvents');
}());