diff --git a/js/index.mjs b/js/index.mjs index 6874e25..f053f55 100644 --- a/js/index.mjs +++ b/js/index.mjs @@ -1,10 +1,10 @@ import { unparser } from "./unparser.mjs"; import { parser, runner, openers } from "./parser.mjs"; -import objs from "./objs.mjs"; +import objsI from "./objs.mjs"; let data = parser(` on( - [start] + [compile] { echo(add([2][3])) echo([Hello World!]) @@ -14,17 +14,20 @@ let data = parser(` ) `); -(async function () { +async function runWrap() { + let objs = Object.assign({},objsI); + objs.events = new EventTarget(); await runner(data, objs); - let ev = new Event('start'); // TODO: more events - - objs.events.dispatchEvent(ev); + let ev = new Event('compile'); // TODO: more events - createBlocks(data); -})() + objs.events.dispatchEvent(ev); +} + +let clickedBlock = false; +let clickedArea = false; async function createBlocks(dat) { - let args = dat.args; + let args = Object.assign([], dat.args); if (!args || !args[0]) args = [dat.args]; if (!args || !args[0]) args = []; for (let i in args) { @@ -44,5 +47,33 @@ async function createBlocks(dat) { if (arg) div.appendChild(arg); } + div.onclick = function (e) { + if (clickedBlock) { + if (clickedArea != dat) { + let p = clickedBlock.parentElement; + div.parentElement.appendChild(clickedBlock); + p.appendChild(div); + + let swap = {}; + console.log(clickedArea, dat) + Object.assign(swap, clickedArea); + Object.assign(clickedArea, dat); + Object.assign(dat, swap); + } + + runWrap(); + + clickedBlock = false; + clickedArea = false; + } else { + clickedBlock = div; + clickedArea = dat; + } + e.stopPropagation(); + } + return div; } + +runWrap(); +createBlocks(data); \ No newline at end of file