Merge branch 'dev' of http://github.com/amark/gun into dev

This commit is contained in:
Mark Nadal 2019-11-20 03:50:09 -08:00
commit 21fcdf8693

View File

@ -14,43 +14,57 @@
} }
} }
if(typeof module !== "undefined"){ var common = module } if(typeof module !== "undefined"){ var common = module }
/* UNBUILD */ /* UNBUILD */
;USE(function(module){ ;USE(function(module){
var noop = function(){}, u; var noop = function(){}, u;
$.fn.or = function(s){ return this.length ? this : $(s||'body') }; $.fn.or = function(s){ return this.length ? this : $(s||'body') };
var m = window.meta = {edit:[]}; var m = window.meta = {edit:[]};
var k = m.key = {}; var k = m.key = {};
k.meta = {17:17, 91:17, 93:17, 224:17}; k.meta = {17:17, 91:17, 93:17, 224:17}; // ctrl met
function withMeta(eve){ return eve.metaKey || eve.ctrlKey }
k.down = function(eve){ k.down = function(eve){
if(eve.repeat){ return } if(eve.repeat){ return }
var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode; var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
if(!eve.fake && key === k.last){ return } k.last = key;
// ADDED
if(!m.flip.is() && !k.meta[key]){ return } // cancel non-open events when closed TODO make optional
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){ if(!eve.fake && $(eve.target).closest('input, textarea, [contenteditable=true]').length){
if(k.meta[key]){ k.down.meta = key = -1 } // if(k.meta[key]){ k.down.meta = key = -1 }
if(!k.down.meta){ return } // if(!k.down.meta){ return }
// prevent typing with meta open
if(meta.flip.is() && !withMeta(eve)) eve.preventDefault()
// hmmm?
// if(!k.meta[key] && !meta.flip.is()) return // aserwed
} }
(k.combo || (k.combo = [])).push(key);
m.check('on', key, k.at || (k.at = m.edit)); m.check('on', key, k.at || (k.at = m.edit));
if(k.meta[key]){ if(k.meta[key]){
m.list(k.at.back || m.edit); // m.list(k.at.back || m.edit);
if(k.at && !k.at.back){ m.flip() } // if(k.at){ m.flip() } // && !k.at.back
m.flip()
} }
} }
k.up = function(eve){ var tmp; k.up = function(eve){ var tmp;
var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode; 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(!m.flip.is() && !k.meta[key]){ return } // ADDED cancel non-open events when closed TODO make optional
if(k.meta[key]){ // if(!eve.fake && $(eve.target).closest('input, textarea, [contenteditable=true]').length){
k.down.meta = null; // if(k.meta[key]){
key = -1; // k.down.meta = null;
} else // key = -1;
if(!k.down.meta){ return } // } else
} // if(!k.down.meta){ return }
// }
k.last = null; k.last = null;
if($(':focus').closest('#meta').length){ return } // if($(':focus').closest('#meta').length){ return }
m.check('up', key); m.check('up', key);
if(-1 === key || 27 === eve.which){ k.wipe() } if(27 === eve.which){ k.wipe() } // -1 === key ||
} }
m.flip = function(tmp){ m.flip = function(tmp){
var board = $('#meta .meta-menu'); var board = $('#meta .meta-menu');
@ -64,27 +78,30 @@
m.flip.wait = 500; m.flip.wait = 500;
m.check = function(how, key, at){ m.check = function(how, key, at){
at = k.at || m.edit; at = k.at || m.edit;
var edit = at[key]; var next = at[key];
if(!edit){ return } if(!next){ return }
var tmp = k.eve || noop; var tmp = k.eve || noop;
if(tmp.preventDefault){ tmp.preventDefault() } if(tmp.preventDefault){ tmp.preventDefault()} // prevent typing (etc) when action found
if(edit[how]){ if(next[how]){
//if(tmp.fake && !edit.fake){ //if(tmp.fake && !next.fake){
//m.tap.edit = edit; //m.tap.next = next;
//} else { //} else {
edit[how](m.eve); next[how](m.eve);
/*if(k.at !== m.edit && 'up' === how){ meta.ui.blink()
if(k.down.meta){ m.list(k.at = m.edit) } /*if(k.at !== m.next && 'up' === how){
if(k.down.meta){ m.list(k.at = m.next) }
else { k.wipe() } else { k.wipe() }
}*/ }*/
//} //}
} }
if('up' != how){ return } if('up' == how){ return }
if(at != edit){ edit.back = at } if(at != next){ next.back = at }
m.list(edit, true); (k.combo || (k.combo = [])).push(key);
m.list(next, true);
} }
m.list = function(at, opt){ m.list = function(at, opt){
if(!at){ return m.flip(false) } if(!at){ return m.flip(false) }
// m.ui.depth(m.key.combo ? m.key.combo.length : 0)
var l = []; var l = [];
$.each(at, function(i,k){ 'back' != i && k.combo && k.name && l.push(k) }); $.each(at, function(i,k){ 'back' != i && k.combo && k.name && l.push(k) });
if(!l.length){ return } if(!l.length){ return }
@ -102,8 +119,9 @@
$ul.append($('<li>').text(k.name).data(k)); $ul.append($('<li>').text(k.name).data(k));
}); });
if(opt){ m.flip(true) } if(opt){ m.flip(true) }
$ul.append($('<li>').html('&larr;').one('click', function(){ $ul.append($('<li>').html('&larr;').on('click', function(){
m.list(k.at = at.back); // m.key.combo.pop()
m.list(at.back);
})); }));
} }
m.ask = function(help, cb){ m.ask = function(help, cb){
@ -121,7 +139,7 @@
$put.focus(); $put.focus();
} }
k.wipe = function(opt){ k.wipe = function(opt){
k.down.meta = false; // k.down.meta = false;
k.combo = []; k.combo = [];
if(!opt){ m.flip(false) } if(!opt){ m.flip(false) }
m.list(k.at = m.edit); m.list(k.at = m.edit);
@ -141,14 +159,29 @@
var at = meta.edit, l = edit.combo.length; var at = meta.edit, l = edit.combo.length;
$.each(tmp, function(i,k){ at = at[k] = (++i >= l)? edit : at[k] || {} }); $.each(tmp, function(i,k){ at = at[k] = (++i >= l)? edit : at[k] || {} });
edit.combow = edit.combow.join(','); edit.combow = edit.combow.join(',');
m.list(meta.edit); m.list(k.at || meta.edit);
} }
})(USE, './metaCore'); })(USE, './metaCore');
;USE(function(module){ ;USE(function(module){
try{
/* UI */ /* 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'); var $m = $('<div>').attr('id', 'meta');
$m.append($('<span>').html('&#9776;').addClass('meta-start')); $m.append($('<span>').html('&#9776;').addClass('meta-start'));
$m.append($('<div>').addClass('meta-menu meta-none').append('<ul>')); $m.append($('<div>').addClass('meta-menu meta-none').append('<ul>'));
@ -206,22 +239,22 @@
'float': 'right' 'float': 'right'
}, },
'#meta a': {color: 'black'}, '#meta a': {color: 'black'},
'#meta:hover': {opacity: 1}, // '#meta:hover': {opacity: 1},
'#meta .meta-menu ul:before': { '#meta .meta-menu ul:before': {
content: "' '", content: "' '",
display: 'block', display: 'block',
'min-height': '15em', 'min-height': '15em',
height: '50vh' height: '50vh'
}, },
'#meta li': { // '#meta li': {
background: 'white', // background: 'white',
padding: '0.5em 1em', // padding: '0.5em 1em',
'border-radius': '1em', // 'border-radius': '1em',
'margin-left': '0.25em', // 'margin-left': '0.25em',
'margin-top': '0.25em', // 'margin-top': '0.25em',
'float': 'right' // 'float': 'right'
}, // },
'#meta:hover .meta-menu': {display: 'block'} // '#meta:hover .meta-menu': {display: 'block'}
}); });
function css(css){ function css(css){
var tmp = ''; var tmp = '';
@ -236,9 +269,9 @@
tag.innerHTML = tmp; tag.innerHTML = tmp;
$m.append(tag) $m.append(tag)
} }
}catch(e){} //}catch(e){}
})(USE, './metaUI'); })(USE, './metaUI');
;USE(function(module){ ;USE(function(module){
// include basic text editing by default. // include basic text editing by default.
@ -269,7 +302,7 @@
r.restore(); r.restore();
if(document.execCommand(cmd, null, as||null)){ if(document.execCommand(cmd, null, as||null)){
if(m.text.range){ m.text.range = monotype() } if(m.text.range){ m.text.range = monotype() }
return; return meta.flip(false); // ADDED meta.flip
} }
} }
if(!opt.tag){ return } if(!opt.tag){ return }
@ -382,39 +415,44 @@
on: function(eve){ meta.text.editor('fontSize', 7) }, on: function(eve){ meta.text.editor('fontSize', 7) },
up: function(){} up: function(){}
}); });
})(USE, './metaText'); })(USE, './metaText');
;USE(function(module){ ;USE(function(module){
var m = meta, k = m.key; var m = meta, k = m.key;
$(window).on('blur', k.wipe).on('focus', k.wipe); $(window).on('blur', k.wipe.bind(null, false)).on('focus', k.wipe.bind(null, false));
$(document).on('mousedown mousemove mouseup', function(eve){ //$(document).on('mousedown mousemove mouseup', function(eve){
m.tap.eve = eve; // m.tap.eve = eve;
m.tap.x = eve.pageX||0; // m.tap.x = eve.pageX||0;
m.tap.y = eve.pageY||0; // m.tap.y = eve.pageY||0;
m.tap.on = $(eve.target); // m.tap.on = $(eve.target);
}).on('mousedown touchstart', function(eve){ //})
var tmp = m.tap.edit; // Setting m.tap.edit has been commented, so should never end up here?
if(!tmp || !tmp.on){ return } //.on('mousedown touchstart', function(eve){
tmp.on(eve); // var tmp = m.tap.edit;
m.tap.edit = null; // if(!tmp || !tmp.on){ return }
}); // tmp.on(eve);
$(document).on('touchstart', '#meta .meta-start', function(eve){ m.tap.stun = true }); // m.tap.edit = null;
//});
//$(document).on('touchstart', '#meta .meta-start', function(eve){ m.tap.stun = true });
$(document).on('click', '#meta .meta-menu li', function(eve){ $(document).on('click', '#meta .meta-menu li', function(eve){
var combo = $(this).data().combo; var combo = $(this).data().combo;
eve.fake = eve.which = combo && combo.slice(-1)[0].charCodeAt(0); eve.fake = eve.which = combo && combo.slice(-1)[0].charCodeAt(0);
eve.tap = true; eve.tap = true;
k.down(eve); k.up(eve); k.down(eve); k.up(eve);
return; return;
if(m.tap.stun){ return m.tap.stun = false } // if(m.tap.stun){ return m.tap.stun = false }
if(!(eve.fake = eve.which = (($(this).text().match(/[A-Z]/)||{})[0]||'').toUpperCase().charCodeAt(0))){ return } // if(!(eve.fake = eve.which = (($(this).text().match(/[A-Z]/)||{})[0]||'').toUpperCase().charCodeAt(0))){ return }
eve.tap = true; // eve.tap = true;
k.down(eve); // k.down(eve);
k.up(eve); // k.up(eve);
}); });
$(document).on('keydown', k.down).on('keyup', k.up); $(document).on('keydown', k.down).on('keyup', k.up);
$(document).on('select contextmenu keyup mouseup', '[contenteditable=true]', m.text.on);
//$(document).on('select contextmenu keyup mouseup', '[contenteditable=true]', m.text.on);
})(USE, './metaEvents'); })(USE, './metaEvents');
}()); }());