modularizes meta.js

This commit is contained in:
Jussi Rytkönen 2019-10-29 01:32:55 +02:00
parent d69c315023
commit e92bf7b940
3 changed files with 52 additions and 30 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ yarn.lock
.esm-cache
.sessionStorage
.localStorage
lib/meta

View File

@ -1,5 +1,18 @@
;(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','');
}
}
/* 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};
@ -34,7 +47,7 @@
}
m.flip = function(tmp){
var board = $('#meta .meta-menu');
((tmp === false) || (!tmp && board.is(':visible')))?
((tmp === false) || (!tmp && board.is(':visible')))?
board.addClass('meta-none')
: board.removeClass('meta-none');
}
@ -89,7 +102,7 @@
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){
var $form = $('<form>').append($put).on('submit', function(eve){
eve.preventDefault();
cb($put.val());
$li.remove();
@ -112,27 +125,6 @@
.or($(document.elementFromPoint(meta.tap.x, meta.tap.y)));
return on;
}
$(window).on('blur', k.wipe).on('focus', k.wipe);
$(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);
}).on('mousedown touchstart', function(eve){
var tmp = m.tap.edit;
if(!tmp || !tmp.on){ return }
tmp.on(eve);
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){
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;
k.down(eve);
k.up(eve);
});
$(document).on('keydown', k.down).on('keyup', k.up);
meta.edit = function(edit){
var tmp = edit.combow = [];
$.each(edit.combo || (edit.combo = []), function(i,k){
@ -144,8 +136,9 @@
edit.combow = edit.combow.join(',');
m.list(meta.edit);
}
$.fn.or = function(s){ return this.length ? this : $(s||'body') };
;(function(){try{
})(USE, './metaCore');
;USE(function(module){try{
/* UI */
if(meta.css){ return }
var $m = $('<div>').attr('id', 'meta');
@ -235,8 +228,9 @@
tag.innerHTML = tmp;
document.body.appendChild(tag);
}
}catch(e){}}());
;(function(){
}catch(e){}})(USE, './metaUI');
;USE(function(module){
// include basic text editing by default.
var monotype = window.monotype || function(){console.log("monotype needed")};
var m = meta;
@ -256,7 +250,6 @@
return ((tmp = window.getSelection) && tmp().toString()) ||
((tmp = document.selection) && tmp.createRange().text) || '';
}
$(document).on('select contextmenu keyup mouseup', '[contenteditable=true]', m.text.on);
m.text.editor = function(opt, as){ var tmp;
if(!opt){ return }
opt = (typeof opt == 'string')? {edit: opt} : opt.tag? opt : {tag: opt};
@ -379,5 +372,32 @@
on: function(eve){ meta.text.editor('fontSize', 7) },
up: function(){}
});
}());
})(USE, './metaText');
;USE(function(module){
$(window).on('blur', k.wipe).on('focus', k.wipe);
$(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);
}).on('mousedown touchstart', function(eve){
var tmp = m.tap.edit;
if(!tmp || !tmp.on){ return }
tmp.on(eve);
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){
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;
k.down(eve);
k.up(eve);
});
$(document).on('keydown', k.down).on('keyup', k.up);
$(document).on('select contextmenu keyup mouseup', '[contenteditable=true]', m.text.on);
})(USE, './metaEvents');
}());

View File

@ -14,7 +14,8 @@
"e2e": "mocha e2e/distributed.js",
"docker": "hooks/build",
"minify": "uglifyjs gun.js -o gun.min.js -c -m",
"unbuild": "node lib/unbuild.js & npm run minify"
"unbuild": "node lib/unbuild.js & npm run minify",
"unbuildMeta": "node lib/unbuild.js lib/meta"
},
"repository": {
"type": "git",