feat(ui): ludic.ui grows toward HTML, CSS and React (Phase 0.U1-U4)
- Natives: ui_native(tag, measure, draw) makes an element the program draws itself; ui_fire runs its on-<event> with event.value. input, select and textarea have simple defaults. - React: - keyed <each>, <let>, <provide> context through components, <fragment>; - named slots, default props on <component>; - on-mount / on-unmount; - inline text inside text elements. - CSS: - custom properties and var(); - position relative/absolute/fixed with insets and z-index; - em/rem/vw/vh and @media; - wrapping text and ellipsis, overflow; - + and ~ combinators, :nth-child(an+b), :checked, :active. - Developing: errors with file:line, ui_errors(), ui_reload() keeping state, and an inspector-style ui_dump. - view fields infer the type of a literal or a named function's result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
66a2bc2214
commit
637d07400e
39 changed files with 42012 additions and 40795 deletions
41
packages/ludic.ui/build_more.ludic
Normal file
41
packages/ludic.ui/build_more.ludic
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# build_more.ludic - <let name="{value}"/> names a value for the siblings after it, and
|
||||
# <provide name="{value}"> gives it to everything inside, components included (React's context)
|
||||
function bd_let(k: UiTpl, e: UiEnv) -> UiEnv {
|
||||
let le = env_new(e)
|
||||
for i in 0 .. len(k.keys) { env_bind(le, k.keys[i], ui_eval(k.vals[i], e)) }
|
||||
return le
|
||||
}
|
||||
function bd_provide(k: UiTpl, e: UiEnv, key: string, out: []UiNode) -> void {
|
||||
let cx = env_new(e.ctx)
|
||||
for i in 0 .. len(k.keys) { env_bind(cx, k.keys[i], ui_eval(k.vals[i], e)) }
|
||||
let pe = env_new(e)
|
||||
pe.ctx = cx
|
||||
bd_kids(k.kids, pe, key, out)
|
||||
}
|
||||
# a fragment's (or a template's) content: its elements, or its words as a text of their own
|
||||
function bd_group(k: UiTpl, e: UiEnv, key: string, out: []UiNode) -> void {
|
||||
if k.text == null {
|
||||
bd_kids(k.kids, e, key, out)
|
||||
return
|
||||
}
|
||||
let t = new UiNode
|
||||
t.kind = UI_TEXT
|
||||
t.key = key
|
||||
t.text = ui_eval_text(k.text, e)
|
||||
t.env = e
|
||||
t.children = new []UiNode
|
||||
push(out, t)
|
||||
}
|
||||
# text inside text - <p>Hi <b>there</b></p>, <h3><slot/></h3> - reads as one line of it
|
||||
function el_inline(n: UiNode) -> void {
|
||||
if n.kind != UI_TEXT or len(n.children) == 0 { return }
|
||||
var s = n.text
|
||||
for i in 0 .. len(n.children) {
|
||||
let c = n.children[i]
|
||||
el_inline(c)
|
||||
if len(s) > 0 and len(c.text) > 0 { s = s + " " }
|
||||
s = s + c.text
|
||||
}
|
||||
n.text = s
|
||||
n.children = new []UiNode
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue