import { computed, handler, ifElse, pattern, UI, Writable } from "commonfabric"; const openNoteEditor = handler((_event, state) => state); const openSettings = handler((_event, state) => state); const toggleExpanded = handler((_event, state) => state); const trashSubPiece = handler((_event, state) => state); interface Item { note?: string; collapsed?: boolean; pinned?: boolean; allowMultiple: boolean; } // FIXTURE: branch-lowered-capture-preservation // Verifies: branch-lowered UI chunks inside a computed-array map preserve captured // params needed by nested ifElse branches, inline computed() attributes, and handlers // allEntries.map(...) -> mapWithPattern(...) // ifElse(computed(() => !entry.collapsed), ...) -> branch lowering keeps entry/index ownership // openNoteEditor/openSettings/toggleExpanded/trashSubPiece handlers // -> params captures survive inside lowered branches // computed(() => entry?.note ? "700" : "400") / title computed(...) // -> authored compute wrappers still coexist with the preserved captures export default pattern<{ items: Item[]; subPieces: string[]; trashedSubPieces: string[]; }>(({ items, subPieces, trashedSubPieces }) => { const editingNoteIndex = new Writable(); const editingNoteText = new Writable(""); const expandedIndex = new Writable(); const settingsModuleIndex = new Writable(); const allEntries = computed(() => items.map((entry, index) => ({ entry, index, isExpanded: index === 0, isPinned: entry.pinned || false, allowMultiple: entry.allowMultiple, })) ); return { [UI]: (
{allEntries.map(({ entry, index, isExpanded, isPinned, allowMultiple }) => ifElse( computed(() => !entry.collapsed),
{ifElse( allowMultiple, , null, )} {!isExpanded && ifElse( true, , null, )} {!isExpanded && ( )}
, null, ) )}
), }; });