stack state working (when top-level parent)

This commit is contained in:
metacryst
2025-12-26 05:54:27 -06:00
parent eb6975c7de
commit 12bb5346e8
2 changed files with 42 additions and 53 deletions

View File

@@ -52,20 +52,22 @@ window.testSuites.push( class testState {
render() { render() {
VStack(() => { VStack(() => {
let asd = this.state.logs.length * 2 this.state.logs.forEach((log) => {
p("hi") p(log)
.fontSize(asd, vw) })
}) })
.onAppear(() => { .onAppear(() => {
this.state.logs = ["one", "two"] this.state.logs.push("one")
this.state.logs.push("two")
}) })
} }
} }
register(Home, randomName("home")) register(Home, randomName("home"))
window.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!"
}
}) })

View File

@@ -553,12 +553,6 @@ HTMLElement.prototype.fontSize = StyleFunction(function(value, unit = "px") {
return this 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") { HTMLElement.prototype.width = function(value, unit = "px") {
if ((typeof value !== 'number' && value !== "auto") || Number.isNaN(value)) if ((typeof value !== 'number' && value !== "auto") || Number.isNaN(value))
@@ -580,6 +574,13 @@ HTMLElement.prototype.height = function(value, unit = "px") {
return this 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") { HTMLElement.prototype.x = function(value, unit = "px") {
if (typeof value !== 'number' || isNaN(value)) if (typeof value !== 'number' || isNaN(value))
throw new Error(`Invalid value: ${value}. Expected a number.`); throw new Error(`Invalid value: ${value}. Expected a number.`);
@@ -821,61 +822,47 @@ window.textarea = function(placeholder = "") {
/* STACKS */ /* STACKS */
window.VStack = function (cb = () => {}) { handleStack = function(cb, name, styles="") {
let styles = `
display: flex;
flex-direction: column;
`
let nowRendering = quill.rendering[quill.rendering.length-1] let nowRendering = quill.rendering[quill.rendering.length-1]
if (nowRendering.innerHTML.trim() === "" && !quill.isStack(nowRendering)) { if (nowRendering.innerHTML.trim() === "" && !quill.isStack(nowRendering)) {
nowRendering.style.cssText += styles nowRendering.style.cssText += styles
nowRendering.classList.add("VStack") nowRendering.classList.add(name)
cb() cb()
if(quill.lastState) {
nowRendering.addStateWatcher(quill.lastState, () => {
nowRendering.innerHTML = ""
cb()
})
}
return nowRendering 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") window.VStack = function (cb = () => {}) {
div.classList.add("VStack") let styles = `
div.style.cssText += styles display: flex;
div.render = cb flex-direction: column;
quill.render(div) `
return div return handleStack(cb, "VStack", styles)
} }
window.HStack = function (cb = () => {}) { window.HStack = function (cb = () => {}) {
let styles = ` let styles = `
display: flex; display: flex;
flex-direction: row; flex-direction: row;
`; `;
let nowRendering = quill.rendering[quill.rendering.length - 1]; return handleStack(cb, "HStack", styles)
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;
}; };
window.ZStack = function (cb = () => {}) { window.ZStack = function (cb = () => {}) {
let nowRendering = quill.rendering[quill.rendering.length - 1]; return handleStack(cb, "ZStack")
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;
}; };
/* SHAPES */ /* SHAPES */