From c096bef675686c0d7eebbc59511b2cd4135458bd Mon Sep 17 00:00:00 2001 From: biglyderv Date: Sat, 30 Nov 2024 01:21:03 -0500 Subject: [PATCH] push and pop --- css/main.css | 8 ++++++++ js/index.mjs | 41 ++++++++++++++++++++++++++++++++++++----- js/objs.mjs | 2 ++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/css/main.css b/css/main.css index a050a20..1eef52b 100644 --- a/css/main.css +++ b/css/main.css @@ -31,4 +31,12 @@ font-family: monospace; background: rgb(255,255,255); max-width: none; +} + +.block-push { + background: rgb(135, 250, 154); +} + +.block-pop { + background: rgb(250, 135, 135); } \ No newline at end of file diff --git a/js/index.mjs b/js/index.mjs index a47aacf..ddcea25 100644 --- a/js/index.mjs +++ b/js/index.mjs @@ -15,7 +15,7 @@ let data = parser(` `); async function runWrap() { - let objs = Object.assign({},objsI); + let objs = Object.assign({}, objsI); objs.events = new EventTarget(); await runner(data, objs); let ev = new Event('compile'); // TODO: more events @@ -25,8 +25,9 @@ async function runWrap() { let clickedBlock = false; let clickedArea = false; +let bodyThing = document.body; -async function createBlocks(dat) { +async function createBlocks(dat, parent = bodyThing) { let args = Object.assign([], dat.args); if (!args || !args[0]) args = [dat.args]; if (!args || !args[0]) args = []; @@ -41,7 +42,37 @@ async function createBlocks(dat) { div.classList.add(`block-${dat.context}`) div.classList.add(`block`) div.textContent = dat.str || dat.context; - document.body.appendChild(div); + parent.appendChild(div); + + if (dat.op == '{') { + //todo: clean + let button = document.createElement('div'); + button.classList.add(`block`) + button.classList.add(`block-push`) + button.textContent = 'push a block'; + div.appendChild(button) + + button.onclick = function() { + dat.args.push(parser(`comment([placeholder])`)); + bodyThing.innerHTML = ''; + + createBlocks(data); + } + + button = document.createElement('div'); + button.classList.add(`block`) + button.classList.add(`block-pop`) + button.textContent = 'pop a block'; + div.appendChild(button) + + button.onclick = function() { + dat.args.pop(); + + bodyThing.innerHTML = ''; + + createBlocks(data); + } + } for (let arg of args) { if (arg) div.appendChild(arg); @@ -54,8 +85,8 @@ async function createBlocks(dat) { let next2 = div.nextSibling; let p = clickedBlock.parentElement; - div.parentElement.insertBefore(clickedBlock,next2); - p.insertBefore(div,next1); + div.parentElement.insertBefore(clickedBlock, next2); + p.insertBefore(div, next1); let swap = {}; console.log(clickedArea, dat) diff --git a/js/objs.mjs b/js/objs.mjs index f1f8669..e59d9f9 100644 --- a/js/objs.mjs +++ b/js/objs.mjs @@ -11,6 +11,8 @@ let add = async function (input, objects) { return input[0] * 1 + input[1] * 1; } +let comment = async function() { } + let events = new EventTarget(); export default {