From 12bb5346e893187e51476979e970f371e1d52707 Mon Sep 17 00:00:00 2001 From: metacryst Date: Fri, 26 Dec 2025 05:54:27 -0600 Subject: [PATCH] stack state working (when top-level parent) --- Test/state/state.test.js | 16 ++++---- index.js | 79 +++++++++++++++++----------------------- 2 files changed, 42 insertions(+), 53 deletions(-) diff --git a/Test/state/state.test.js b/Test/state/state.test.js index f124ab7..abaa5fc 100644 --- a/Test/state/state.test.js +++ b/Test/state/state.test.js @@ -52,20 +52,22 @@ window.testSuites.push( class testState { render() { VStack(() => { - let asd = this.state.logs.length * 2 - p("hi") - .fontSize(asd, vw) + this.state.logs.forEach((log) => { + p(log) + }) }) .onAppear(() => { - this.state.logs = ["one", "two"] + this.state.logs.push("one") + this.state.logs.push("two") }) } } register(Home, randomName("home")) window.Home() - - if(!($("p").style.fontSize === "4vw")) return "state did not update!" - } + if(!$("p")) return "no p's rendered" + if($$("p")[0].innerText !== "one") return "state did not update!" + if($$("p")[1].innerText !== "two") return "state did not update!" + } }) \ No newline at end of file diff --git a/index.js b/index.js index e089540..6628098 100644 --- a/index.js +++ b/index.js @@ -553,12 +553,6 @@ HTMLElement.prototype.fontSize = StyleFunction(function(value, unit = "px") { return this }) -function checkPositionType(el) { - let computed = window.getComputedStyle(el).position - if(!(computed === "absolute" || computed === "fixed")) { - el.style.position = "absolute" - } -} HTMLElement.prototype.width = function(value, unit = "px") { if ((typeof value !== 'number' && value !== "auto") || Number.isNaN(value)) @@ -580,6 +574,13 @@ HTMLElement.prototype.height = function(value, unit = "px") { return this } +function checkPositionType(el) { + let computed = window.getComputedStyle(el).position + if(!(computed === "absolute" || computed === "fixed")) { + el.style.position = "absolute" + } +} + HTMLElement.prototype.x = function(value, unit = "px") { if (typeof value !== 'number' || isNaN(value)) throw new Error(`Invalid value: ${value}. Expected a number.`); @@ -821,61 +822,47 @@ window.textarea = function(placeholder = "") { /* STACKS */ -window.VStack = function (cb = () => {}) { - let styles = ` - display: flex; - flex-direction: column; - ` +handleStack = function(cb, name, styles="") { let nowRendering = quill.rendering[quill.rendering.length-1] if (nowRendering.innerHTML.trim() === "" && !quill.isStack(nowRendering)) { nowRendering.style.cssText += styles - nowRendering.classList.add("VStack") + nowRendering.classList.add(name) cb() + if(quill.lastState) { + nowRendering.addStateWatcher(quill.lastState, () => { + nowRendering.innerHTML = "" + cb() + }) + } return nowRendering + } else { + let div = document.createElement("div") + div.classList.add(name) + div.style.cssText += styles + div.render = cb + quill.render(div) + return div } +} - let div = document.createElement("div") - div.classList.add("VStack") - div.style.cssText += styles - div.render = cb - quill.render(div) - return div +window.VStack = function (cb = () => {}) { + let styles = ` + display: flex; + flex-direction: column; + ` + return handleStack(cb, "VStack", styles) } window.HStack = function (cb = () => {}) { let styles = ` - display: flex; - flex-direction: row; + display: flex; + flex-direction: row; `; - let nowRendering = quill.rendering[quill.rendering.length - 1]; - if (nowRendering.innerHTML.trim() === "" && !quill.isStack(nowRendering)) { - nowRendering.style.cssText += styles; - nowRendering.classList.add("HStack") - cb(); - return nowRendering; - } - - let div = document.createElement("div"); - div.classList.add("HStack"); - div.style.cssText += styles; - div.render = cb; - quill.render(div); - return div; + return handleStack(cb, "HStack", styles) }; window.ZStack = function (cb = () => {}) { - let nowRendering = quill.rendering[quill.rendering.length - 1]; - if (nowRendering.innerHTML.trim() === "" && !quill.isStack(nowRendering)) { - nowRendering.classList.add("ZStack") - cb(); - return nowRendering; - } - - let div = document.createElement("div"); - div.classList.add("ZStack"); - div.render = cb; - quill.render(div); - return div; + return handleStack(cb, "ZStack") }; /* SHAPES */