Hide menu submenus when none of their children are visible

Static submenus and links now inherit visibility from their descendants,
so hardware sections like Touchpad Haptics disappear on machines without
the hardware instead of opening empty. Laptop Display and Mirror Display
are guarded by omarchy-hw-laptop.

The guard evaluator brace-wraps every when/checked condition before
silencing it, so conditions in the jsonc no longer need their own
>/dev/null plumbing, and parents no longer need to repeat their
children's guards.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
David Heinemeier Hansson
2026-07-21 16:30:36 -07:00
co-authored by Claude Fable 5
parent 9d3cb70ee7
commit 2bf4f4a9fb
4 changed files with 68 additions and 25 deletions
+20
View File
@@ -173,6 +173,25 @@ function childCount(items, itemOrder, id) {
return count
}
function isVisible(items, itemOrder, whenResults, entry, depth) {
if (!entry) return false
if (entry.when && whenResults && whenResults[entry.id] === false) return false
if (entry.kind !== "menu" && entry.kind !== "link") return true
if (entry.provider) return true
var guard = depth || 0
if (guard >= 32) return false
var target = entry.kind === "link" ? entry.target : entry.id
var order = Array.isArray(itemOrder) ? itemOrder : []
for (var i = 0; i < order.length; i++) {
var child = item(items, order[i])
if (child && child.parent === target && isVisible(items, itemOrder, whenResults, child, guard + 1)) return true
}
return false
}
function labelFor(entry, checkedResults) {
if (!entry) return ""
if (entry.checked && checkedResults && checkedResults[entry.id]) return entry.label + " ✓"
@@ -282,6 +301,7 @@ if (typeof module !== "undefined") {
parentPathFor: parentPathFor,
isDescendantOf: isDescendantOf,
childCount: childCount,
isVisible: isVisible,
labelFor: labelFor,
searchableToken: searchableToken,
leafIdFor: leafIdFor,