Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
SpriteandClaude Sonnet 5.5 committed 2026-11-23 01:08:53 +00:00
1 parent dccbfd7d86
commit 17f81c60c8
20 files changed
+636 -447

No files matched your search

+1
View File
@@ -0,0 +1 @@
+23 -12
View File
@@ -25,7 +25,14 @@ pub(all) struct Handlers[M] {
///|
pub fn[M] Handlers::none() -> Handlers[M] {
{ down: None, tap: None, press: None, enter: None, escape: None, input: None }
{
down: None,
tap: None,
press: None,
enter: None,
escape: None,
input: None,
}
}
///|
@@ -48,7 +55,7 @@ pub(all) enum Node[M] {
pub(all) struct Element[M] {
tag : String
/// Identity among siblings for the keyed diff (0: none).
key : Int
key : Int32
classes : Array[String]
attrs : Array[(String, String)]
/// DOM properties (not attributes), e.g. an input's `value`.
@@ -62,15 +69,15 @@ pub(all) struct Element[M] {
/// An element builder: `el("div", classes=["a"], children=[...])`.
pub fn[M] el(
tag : String,
key? : Int = 0,
classes? : Array[String] = [],
attrs? : Array[(String, String)] = [],
props? : Array[(String, String)] = [],
style? : String = "",
handlers? : Handlers[M] = Handlers::none(),
children? : Array[Node[M]] = [],
key~ : Int32 = 0,
classes~ : Array[String] = [],
attrs~ : Array[(String, String)] = [],
props~ : Array[(String, String)] = [],
style~ : String = "",
handlers~ : Handlers[M] = Handlers::none(),
children~ : Array[Node[M]] = [],
) -> Node[M] {
El({ tag, key, classes, attrs, props, style, handlers, children })
El({ tag, key, classes, attrs, props, style, handlers, children, })
}
///|
@@ -81,7 +88,11 @@ pub fn[M] text(s : String) -> Node[M] {
///|
/// `cls("a", on=false)` is the empty class, so callers can build lists with `filter`.
pub fn cls_if(name : String, on : Bool) -> String {
if on { name } else { "" }
if on {
name
} else {
""
}
}
///|
@@ -126,7 +137,7 @@ fn[M] handler_names(h : Handlers[M]) -> String {
///|
/// Render a node as HTML text, one element per line (children indented), for tests.
/// Handlers show as an `on="tap press"` attribute.
pub fn[M] to_html(node : Node[M], indent? : Int = 0) -> String {
pub fn[M] to_html(node : Node[M], indent~ : Int32 = 0) -> String {
let pad = " ".repeat(indent)
match node {
Text(s) => pad + escape_html(s)
+2 -2
View File
@@ -1,9 +1,9 @@
///|
test "to_html" {
let n : Node[Int] = el(
let n : Node[Int32] = el(
"div",
classes=["a", cls_if("b", false), cls_if("c", true)],
handlers={ ..Handlers::none(), tap: Some(1) },
handlers={ ..Handlers::none(), tap: Some(1), },
children=[el("span", children=[text("x < y")]), text("tail")],
)
inspect(