This commit is contained in:
biglyderv 2024-11-29 21:30:51 -05:00
parent e62e897d8d
commit 5e81cc5e2e

View file

@ -1,10 +1,10 @@
import { unparser } from "./unparser.mjs"; import { unparser } from "./unparser.mjs";
import { parser, runner, openers } from "./parser.mjs"; import { parser, runner, openers } from "./parser.mjs";
import objs from "./objs.mjs"; import objsI from "./objs.mjs";
let data = parser(` let data = parser(`
on( on(
[start] [compile]
{ {
echo(add([2][3])) echo(add([2][3]))
echo([Hello World!]) 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); await runner(data, objs);
let ev = new Event('start'); // TODO: more events let ev = new Event('compile'); // TODO: more events
objs.events.dispatchEvent(ev); objs.events.dispatchEvent(ev);
}
createBlocks(data); let clickedBlock = false;
})() let clickedArea = false;
async function createBlocks(dat) { 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 = [dat.args];
if (!args || !args[0]) args = []; if (!args || !args[0]) args = [];
for (let i in args) { for (let i in args) {
@ -44,5 +47,33 @@ async function createBlocks(dat) {
if (arg) div.appendChild(arg); 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; return div;
} }
runWrap();
createBlocks(data);