content: tree reparent — move-into section + promote (812/812)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 41s

insert/move were top-level only; a block could never move into/out of a
section. content/move-into (relocate to a section child at index, tree-wide)
+ content/promote (lift nested block to top level, subtree intact). Pure
tree transforms like the rest of move.sx; cycle-safe (rejects moving a block
into its own descendant). +13 tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-07 18:28:36 +00:00
parent 29954689bc
commit e9316b37c2
5 changed files with 166 additions and 11 deletions

View File

@@ -1,7 +1,8 @@
;; Extension — relative block reorder.
;; Extension — relative block reorder + tree reparent.
(st-bootstrap-classes!)
(content/bootstrap!)
(content-bootstrap-section!)
(define
d
@@ -61,3 +62,84 @@
"render after move"
(asHTML (content/move-after d "a" "c"))
"<p>B</p><p>C</p><p>A</p>")
;; ── reparent: move a top-level block INTO a section ──
(define
nd
(doc-append
(doc-append (doc-empty "d") (mk-text "p" "P"))
(mk-section "s" (list (mk-text "x" "X")))))
(content-test
"move-into: block leaves top level"
(doc-ids (content/move-into nd "p" "s" 1))
(list "s"))
(content-test
"move-into: block lands in section at index"
(doc-tree-ids (content/move-into nd "p" "s" 1))
(list "s" "x" "p"))
(content-test
"move-into at front of section"
(doc-tree-ids (content/move-into nd "p" "s" 0))
(list "s" "p" "x"))
(content-test "move-into immutable" (doc-tree-ids nd) (list "p" "s" "x"))
;; ── reparent: move a NESTED block to a different section ──
(define
two
(doc-append
(doc-append (doc-empty "d") (mk-section "s1" (list (mk-text "n" "N"))))
(mk-section "s2" (list (mk-text "y" "Y")))))
(content-test
"move-into across sections"
(doc-tree-ids (content/move-into two "n" "s2" 1))
(list "s1" "s2" "y" "n"))
;; ── promote: nested block out to top level (appended last) ──
(content-test
"promote nested to top level"
(doc-tree-ids (content/promote two "n"))
(list "s1" "s2" "y" "n"))
(content-test
"promote leaves section empty shell"
(doc-ids (content/promote two "n"))
(list "s1" "s2" "n"))
(content-test
"promote a whole section keeps its subtree"
(doc-tree-ids
(content/promote
(doc-append
(doc-empty "d")
(mk-section "o" (list (mk-section "i" (list (mk-text "z" "Z"))))))
"i"))
(list "o" "i" "z"))
;; ── cycle guard: cannot move a section into its own descendant ──
(define
nest
(doc-append
(doc-empty "d")
(mk-section
"outer"
(list (mk-section "inner" (list (mk-text "t" "T")))))))
(content-test
"move section into its own child is a no-op"
(doc-tree-ids (content/move-into nest "outer" "inner" 0))
(list "outer" "inner" "t"))
(content-test
"move block into itself is a no-op"
(doc-tree-ids (content/move-into nest "inner" "inner" 0))
(list "outer" "inner" "t"))
;; ── reparent no-ops on missing ids ──
(content-test
"move-into missing block no-op"
(doc-tree-ids (content/move-into nd "zzz" "s" 0))
(list "p" "s" "x"))
(content-test
"move-into missing section no-op"
(doc-tree-ids (content/move-into nd "p" "zzz" 0))
(list "p" "s" "x"))
(content-test
"promote missing no-op"
(doc-tree-ids (content/promote nd "zzz"))
(list "p" "s" "x"))