import * as __ctHelpers from "commontools"; /** * Regression test: action() result used in same ternary branch as computed() * * When a ternary branch contains both a computed() value and an action() reference, * the action must be captured in the derive wrapper along with the computed value. * Previously, action() results were incorrectly classified as "function declarations" * and skipped by CaptureCollector. */ import { action, Cell, computed, pattern, UI } from "commontools"; interface Card { title: string; description: string; } interface Input { card: Card; } export default pattern(({ card }) => { const isEditing = Cell.of(false, { type: "boolean" } as const satisfies __ctHelpers.JSONSchema); const startEditing = __ctHelpers.handler(false as const satisfies __ctHelpers.JSONSchema, { type: "object", properties: { isEditing: { type: "boolean", asCell: true } }, required: ["isEditing"] } as const satisfies __ctHelpers.JSONSchema, (_, { isEditing }) => { isEditing.set(true); })({ isEditing: isEditing }); const hasDescription = __ctHelpers.derive({ type: "object", properties: { card: { type: "object", properties: { description: { type: "string", asOpaque: true } }, required: ["description"] } }, required: ["card"] } as const satisfies __ctHelpers.JSONSchema, { type: "boolean" } as const satisfies __ctHelpers.JSONSchema, { card: { description: card.description } }, ({ card }) => { const desc = card.description; return desc && desc.length > 0; }); return { [UI]: ( {__ctHelpers.ifElse({ type: "boolean", asCell: true } as const satisfies __ctHelpers.JSONSchema, { anyOf: [{}, { type: "object", properties: {} }] } as const satisfies __ctHelpers.JSONSchema, { anyOf: [{}, { type: "object", properties: {} }] } as const satisfies __ctHelpers.JSONSchema, { anyOf: [{}, { type: "object", properties: {} }] } as const satisfies __ctHelpers.JSONSchema, isEditing,
Editing
, __ctHelpers.derive({ type: "object", properties: { card: { type: "object", properties: { title: { type: "string", asOpaque: true }, description: { type: "string", asOpaque: true } }, required: ["title", "description"] }, hasDescription: { type: "boolean", asOpaque: true }, startEditing: { asStream: true } }, required: ["card", "hasDescription", "startEditing"] } as const satisfies __ctHelpers.JSONSchema, { anyOf: [{ $ref: "https://commonfabric.org/schemas/vnode.json" }, { type: "object", properties: {} }, { $ref: "#/$defs/UIRenderable", asOpaque: true }], $defs: { UIRenderable: { type: "object", properties: { $UI: { $ref: "https://commonfabric.org/schemas/vnode.json" } }, required: ["$UI"] } } } as const satisfies __ctHelpers.JSONSchema, { card: { title: card.title, description: card.description }, hasDescription: hasDescription, startEditing: startEditing }, ({ card, hasDescription, startEditing }) => (
{card.title} {/* Nested ternary with computed - triggers derive wrapper */} {__ctHelpers.ifElse({ type: "boolean" } as const satisfies __ctHelpers.JSONSchema, { anyOf: [{}, { type: "object", properties: {} }] } as const satisfies __ctHelpers.JSONSchema, { type: "null" } as const satisfies __ctHelpers.JSONSchema, { anyOf: [{ type: "null" }, { $ref: "https://commonfabric.org/schemas/vnode.json" }, { type: "object", properties: {} }] } as const satisfies __ctHelpers.JSONSchema, hasDescription, {card.description}, null)} {/* Action in SAME branch - must be captured by the derive! */} Edit
)))}
), card, }; }, { type: "object", properties: { card: { $ref: "#/$defs/Card" } }, required: ["card"], $defs: { Card: { type: "object", properties: { title: { type: "string" }, description: { type: "string" } }, required: ["title", "description"] } } } as const satisfies __ctHelpers.JSONSchema, { type: "object", properties: { $UI: { $ref: "#/$defs/JSXElement" }, card: { $ref: "#/$defs/Card", asOpaque: true } }, required: ["$UI", "card"], $defs: { Card: { type: "object", properties: { title: { type: "string" }, description: { type: "string" } }, required: ["title", "description"] }, JSXElement: { anyOf: [{ $ref: "https://commonfabric.org/schemas/vnode.json" }, { type: "object", properties: {} }, { $ref: "#/$defs/UIRenderable", asOpaque: true }] }, UIRenderable: { type: "object", properties: { $UI: { $ref: "https://commonfabric.org/schemas/vnode.json" } }, required: ["$UI"] } } } as const satisfies __ctHelpers.JSONSchema); // @ts-ignore: Internals function h(...args: any[]) { return __ctHelpers.h.apply(null, args); } // @ts-ignore: Internals h.fragment = __ctHelpers.h.fragment;