diff --git a/bootstrap.js b/bootstrap.js index 108541a3bc4e10b60952147dcf27e5945df0fd91..38d9a7eb8801bd28c8920602dfc0434994e5dd66 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -48,6 +48,7 @@ window.onload = () => { // gotta git this view = vw $('#wrapper').get(0).append(view.dom) + // itself view.onload() view.makeTopLevel() console.log("MTL'd") diff --git a/hunks/view.js b/hunks/view.js index 0b9ba4cc84dd1d85c800002d5554438c7638b617..815c38ffd98b906dfeb49e8c0782e70d7aa45658 100644 --- a/hunks/view.js +++ b/hunks/view.js @@ -74,6 +74,16 @@ function View() { let patchset = new PatchSet(this, msgbox) this.patchset = patchset + // here ... at this point, + /* + an init order, etc, for each view to have top-level access ... + for tls stuff + for contextmenu , do (tlv.oncontext(this, event)) + ... aaaand ? + */ + // the toplevel view, + this.tls = 1 + /* --------------------------- ---------------------------- */ /* -------------------- INIT, LISTENERS ---------------------- */ /* --------------------------- ---------------------------- */ @@ -88,6 +98,7 @@ function View() { // then cf will drop it wherever we plan ... console.log(`${this.name} INIT`) this.dom = $('<div>').addClass('view').get(0) + this.dom.hunk = this } // END INIT CODE @@ -104,8 +115,6 @@ function View() { }) // to log, type, etc msgbox.init() - // get the context menu on righ click - this.dom.addEventListener('contextmenu', onContextMenu) // append $(this.dom).append(this.plane) // more space @@ -160,8 +169,7 @@ function View() { /* --------------------------- ---------------------------- */ this.isTopLevel = false - // this will bite you later, - this.tls = 1 + // the top level view, gifted to this hunk by omniscience this.makeTopLevel = () => { console.log(`${this.name} MAKE TOP LEVEL`) @@ -365,6 +373,122 @@ function View() { this.onresize() } + // get the context menu on righ click + this.dom.addEventListener('contextmenu', (evt) => { + // exit if we're not on target + if (!$(evt.target).is('.view')) return false + // global contextemenu rm (we are toplevel) + $(this.dom).find('.contextmenu').remove() + // one only, + evt.preventDefault() + evt.stopPropagation() + // the view we would issue from, + console.log(`contextmenu for ${evt.target.hunk.name}`) + let vw = evt.target.hunk + // make the menu, + let menu = $('<div>').addClass('contextmenu').get(0) + // lay it down in screen-space + dt.writeTransform(menu, { + s: 1, + x: evt.clientX, // (pt.s + -0.1 * (pt.s-1))), + y: evt.clientY // + -0.1 * (pt.s-1))) + }) + $(this.dom).append(menu) + // hmmm + this.changeContextTitle('you can... ') + // on of the options will ... + + // LOCAL: + // req a new hunk, + this.addContextOption('add a hunk', (evt) => { + vw.msgbox.write('requested a list of hunks...') + $(evt.target).text('requesting a list of hunks...') + vw.requestListAvail().then((stringlist) => { + this.changeContextTitle('available hunks:') + for (let item of stringlist) { + this.addContextOption(item, (evt) => { + $(evt.target).append(' > requested ... ') + vw.msgbox.write(`requested one new ${item}`) + vw.requestAddHunk(item).then((def) => { + //console.log('one hunk as promised', def) + }).catch((err) => { + this.changeContextTitle('error, see consoles') + setTimeout(() => { + $(this.dom).find('.contextmenu').fadeOut(400, function() { + $(this).remove() + }) + }, 1000) + }) + }) + } + }) + }) + + // GLOBAL: + // load patches, + this.addContextOption('restore a system', (evt) => { + $(evt.target).append(' > loading a list ...') + patchset.findPatches(evt).then((list) => { + // title, and options + this.changeContextTitle('available system patches:') + for (let item of list) { + this.addContextOption(item, (evt) => { + try { + patchset.mergePatch(item).then((defs) => { + msgbox.write(`great success merging patches, going to organize`) + this.globalOrganize() + }).catch((errmsg) => { + console.error(errmsg) + console.error('here, write failure-at-this-point and fade') + }) + } catch (err) { + msgbox.write('caught an error while starting program load') + } + }) + } + }) + }) + + // save patches + this.addContextOption('save this patch', (evt) => { + let ptch = patchset.writeCurrent(defs, true) + $(evt.target).text('') + let tinput = $('<input>').attr('type', 'text').attr('size', 24).attr('value', 'patchName').get(0) + $(evt.target).append(tinput) // etc + $(tinput).focus() + $(tinput).select() + $(tinput).on('keyup', (evt) => { + if (evt.keyCode == 13) { + let bleb = JSON.stringify(ptch) + let url = URL.createObjectURL(new Blob([JSON.stringify(ptch, null, 2)], { + type: "application/json" + })) + // hack to trigger the download, + let anchor = $('<a>ok</a>').attr('href', url).attr('download', tinput.value + '.json').get(0) + $(evt.target).append(anchor) + anchor.click() + // finally, rip + $(this.dom).find('.contextmenu').remove() + //saveAs(bleb, 'file.json') + } + }) + }) + }) // end contextmenu + + // takes 'under' argument + this.addContextOption = (text, click) => { + $(this.dom).find('.contextmenu').get(0).append($('<li>' + text + '</li>').click((click)).get(0)) + } + + this.changeContextTitle = (text) => { + // clear, + $(this.dom).find('.contextmenu').children().remove() + // overkill, but fun + let menu = $(this.dom).find('.contextmenu').get(0) + let title = $(`<div>${text}</div>`).addClass('contextTitle').get(0) + $(this.dom).find('.contextmenu').append(title) + } + /* QUEEN RECEPIES */ let trace = (output) => { @@ -375,6 +499,10 @@ function View() { console.log('next', next) if (next.parent.type === 'view') { return next.parent + } else if (next.parent.type === 'link') { + // liiike ... link.iswrapped ?? find it's view ?? find the recip links + // inside that def ... etc etc ... + throw new Error('time to write trace thru links') } else { return false } @@ -423,8 +551,8 @@ function View() { } for (let df of view.defs) { if (df.type === 'view' && df.name !== 'tlview') { - lvl ++ - if(lvl % 2 === 0){ + lvl++ + if (lvl % 2 === 0) { // } else { $(df.deg.native).children('.view').css('background-color', '#d6d6d6') @@ -437,7 +565,6 @@ function View() { // walk views, make diff. colorrs } - this.expandLink = (linkDef) => { return new Promise((resolve, reject) => { // i.e. requestAddHunk isn't necessarily hooked to this @@ -489,118 +616,11 @@ function View() { console.log('err during link expansion', err) }) } // end expand recipe - } // end makeTopLevel - // CONTEXT MENU - let onContextMenu = (evt) => { - $(this.dom).find('.contextmenu').remove() - evt.preventDefault() - evt.stopPropagation() - // exit if we're not on target - if (!$(evt.target).is('.view')) return false - // make the menu, - let menu = $('<div>').addClass('contextmenu').get(0) - // (and there's compounding scale issues on dragging the canvas) - dt.writeTransform(menu, { - s: 1, - x: evt.layerX, // (pt.s + -0.1 * (pt.s-1))), - y: evt.layerY // + -0.1 * (pt.s-1))) - }) - // - $(this.dom).append(menu) - // hmmm - this.changeContextTitle('you can... ') - // on of the options will ... - - // req a new hunk, - this.addContextOption('add a hunk', (evt) => { - msgbox.write('requested a list of hunks...') - $(evt.target).text('requesting a list of hunks...') - this.requestListAvail().then((stringlist) => { - this.changeContextTitle('available hunks:') - for (let item of stringlist) { - this.addContextOption(item, (evt) => { - $(evt.target).append(' > requested ... ') - msgbox.write(`requested one new ${item}`) - this.requestAddHunk(item).then((def) => { - //console.log('one hunk as promised', def) - }).catch((err) => { - this.changeContextTitle('error, see consoles') - setTimeout(() => { - $(this.dom).find('.contextmenu').fadeOut(400, function() { - $(this).remove() - }) - }, 1000) - }) - }) - } - }) - }) - - // load patches, - this.addContextOption('restore a system', (evt) => { - $(evt.target).append(' > loading a list ...') - patchset.findPatches(evt).then((list) => { - // title, and options - this.changeContextTitle('available system patches:') - for (let item of list) { - this.addContextOption(item, (evt) => { - try { - patchset.mergePatch(item).then((defs) => { - msgbox.write(`great success merging patches, going to organize`) - this.globalOrganize() - }).catch((errmsg) => { - console.error(errmsg) - console.error('here, write failure-at-this-point and fade') - }) - } catch (err) { - msgbox.write('caught an error while starting program load') - } - }) - } - }) - }) - - // save patches - this.addContextOption('save this patch', (evt) => { - let ptch = patchset.writeCurrent(defs, true) - $(evt.target).text('') - let tinput = $('<input>').attr('type', 'text').attr('size', 24).attr('value', 'patchName').get(0) - $(evt.target).append(tinput) // etc - $(tinput).focus() - $(tinput).select() - $(tinput).on('keyup', (evt) => { - if (evt.keyCode == 13) { - let bleb = JSON.stringify(ptch) - let url = URL.createObjectURL(new Blob([JSON.stringify(ptch, null, 2)], { - type: "application/json" - })) - // hack to trigger the download, - let anchor = $('<a>ok</a>').attr('href', url).attr('download', tinput.value + '.json').get(0) - $(evt.target).append(anchor) - anchor.click() - // finally, rip - $(this.dom).find('.contextmenu').remove() - //saveAs(bleb, 'file.json') - } - }) - }) - } // end onContextMenu - - // takes 'under' argument - this.addContextOption = (text, click) => { - $(this.dom).find('.contextmenu').get(0).append($('<li>' + text + '</li>').click((click)).get(0)) - } - - this.changeContextTitle = (text) => { - // clear, - $(this.dom).find('.contextmenu').children().remove() - // overkill, but fun - let menu = $(this.dom).find('.contextmenu').get(0) - let title = $(`<div>${text}</div>`).addClass('contextTitle').get(0) - $(this.dom).find('.contextmenu').append(title) - } + /* --------------------------- ---------------------------- */ + /* ------------------- END MAKETOPLEVEL ---------------------- */ + /* --------------------------- ---------------------------- */ /* --------------------------- ---------------------------- */ /* ----------------------- REDRAWING ------------------------- */ @@ -628,17 +648,14 @@ function View() { } } + // kick: topology changes this.kick = () => { - // global checks, - // (1) from the top level, look for views inside of other views - // check out msgbox (?) msgbox.checkHeight() - // floop stuff... this.floop.reset() - // also a likely redraw this.drawLinks() } + // tick: size / position changes this.tick = () => { this.floop.sim.alpha(1) this.floop.sim.restart() diff --git a/style.css b/style.css index 9cef8bfffc65fe6cd499e3d4e0e84629851ce1c5..5dcc90a8a9c56622a1189a633f00de7c104cc309 100644 --- a/style.css +++ b/style.css @@ -341,9 +341,8 @@ li:active{ position: absolute; overflow: hidden; width: 245px; - padding: 10px; - background-color: #303030; - color: #eee; + background-color: #303030; + color: #eee; } .contextmenu input {