host: block editor renders ANY composition node (no more "(unknown block)")

The block editor assumed cards-as-objects leaves (ref/alt-with-refs/each-with-ref), so a
hand-authored composition (the compose-demo: text/row/alt-with-text/each-with-inline) fell
through to "(unknown block)" for every text/row node. Now every node kind gets a labelled row
+ preview + move/remove controls: card (✎ chip), text (its content), layout (row/grid + item
count), field, group, and a graceful "other". Conditionals/repeaters display each branch via
host/blog--node-display (a ref → ✎ chip, else the inline text/summary) instead of assuming a
ref. host/blog--node-kind extended (text/layout/field/group); +node-display/+branch-display.

TEST-FIRST: a mixed body (text + alt-with-text + row + each-with-inline) asserts the editor
has NO "unknown block" and labels text/layout/for-each. RED before, GREEN after. blog 171/171.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-01 10:15:30 +00:00
parent 39c3def2e7
commit b056469be1
2 changed files with 50 additions and 10 deletions

View File

@@ -776,8 +776,31 @@
(fn (node)
(if (= (type-of node) "list")
(let ((h (str (first node))))
(cond ((= h "ref") "card") ((= h "alt") "cond") ((= h "each") "each") (else "other")))
(cond
((= h "ref") "card") ((= h "alt") "cond") ((= h "each") "each")
((= h "text") "text")
((or (= h "row") (= h "grid")) "layout")
((or (= h "field") (= h "val")) "field")
((= h "seq") "group")
(else "other")))
"other")))
;; a short human display of ANY composition node — for the editor rows. A ref becomes a
;; ✎ edit-chip; text/field/val show their content; a container shows its item count.
(define host/blog--node-display
(fn (slug node)
(if (= (type-of node) "list")
(let ((h (str (first node))))
(cond
((= h "ref") (host/blog--ref-chip slug (str (first (rest node)))))
((= h "text") (let ((t (str (first (rest node))))) (if (> (len t) 50) (str (substr t 0 50) "…") t)))
((or (= h "field") (= h "val")) (str h " " (str (first (rest node)))))
((or (= h "seq") (= h "row") (= h "grid")) (str h " (" (len (rest node)) ")"))
(else h)))
(str node))))
;; the display of a conditional/repeater BRANCH — its last element (a ref, text, or group).
(define host/blog--branch-display
(fn (slug branch)
(host/blog--node-display slug (host/blog--nth branch (- (len branch) 1)))))
;; every ref slug a node (transitively) contains — for `contains`-edge cleanup on remove.
(define host/blog--node-refs
(fn (node)
@@ -1587,27 +1610,29 @@
(let ((kind (host/blog--node-kind node))
(rs "display:flex;gap:0.5em;align-items:center;border:1px solid #ddd;padding:0.4em;margin:0.2em 0"))
(cond
((= kind "card")
(quasiquote (li :style (unquote rs)
(b :style "min-width:5em" "card")
(span :style "flex:1" (unquote (host/blog--ref-chip slug (str (first (rest node))))))
(unquote (host/blog--block-ctrls slug idx)))))
;; CONDITIONAL: the condition <select> + a display of each branch (ref chip OR inline).
((= kind "cond")
(quasiquote (li :style (unquote rs)
(b :style "min-width:5em" "if")
(span :style "flex:1"
(unquote (host/blog--cond-form slug idx (host/blog--pred->ckey (host/blog--node-pred node))))
" → " (unquote (host/blog--ref-chip slug (host/blog--cond-then node)))
" · else → " (unquote (host/blog--ref-chip slug (host/blog--cond-else node))))
" → " (unquote (host/blog--branch-display slug (first (rest node))))
" · else → " (unquote (host/blog--branch-display slug (first (rest (rest node))))))
(unquote (host/blog--block-ctrls slug idx)))))
;; REPEATER: the query type + a display of the per-item template (ref OR inline).
((= kind "each")
(quasiquote (li :style (unquote rs)
(b :style "min-width:5em" "for each")
(span :style "flex:1"
(code (unquote (host/blog--node-each-type node)))
" → " (unquote (host/blog--ref-chip slug (host/blog--each-tmpl node))))
" → " (unquote (host/blog--node-display slug (host/blog--nth node (- (len node) 1)))))
(unquote (host/blog--block-ctrls slug idx)))))
(else (quasiquote (li :style (unquote rs) "(unknown block)")))))))
;; every other kind (card / text / layout / field / group / other) — a labelled row
;; with a preview + controls. No composition node falls through to "unknown".
(else (quasiquote (li :style (unquote rs)
(b :style "min-width:5em" (unquote kind))
(span :style "flex:1;color:#555;overflow:hidden" (unquote (host/blog--node-display slug node)))
(unquote (host/blog--block-ctrls slug idx)))))))))
(define host/blog--block-editor
(fn (slug)
(let ((nodes (host/blog-body-nodes slug)))