import * as __ctHelpers from "commontools"; /** * Test case for unless() with a reactive array map as the fallback. * * unless(condition, fallback) returns condition if truthy, else fallback. * When fallback is items.map(...), the map gets transformed to mapWithPattern. * Schema injection needs to know the type of the mapWithPattern result. */ import { Cell, Default, pattern, UI } from "commontools"; interface Item { label: string; } interface PatternInput { customContent: Cell; items: Cell>; } export default pattern(({ customContent, items }) => { return { [UI]: (
{/* unless(condition, fallback) where fallback is a reactive map */} {__ctHelpers.unless({ asCell: true } as const satisfies __ctHelpers.JSONSchema, { type: "array", items: { $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, { asCell: true } as const satisfies __ctHelpers.JSONSchema, customContent, items.mapWithPattern(__ctHelpers.pattern(({ element: item, params: {} }) =>
  • {item.label}
  • , { type: "object", properties: { element: { $ref: "#/$defs/Item" }, params: { type: "object", properties: {} } }, required: ["element", "params"], $defs: { Item: { type: "object", properties: { label: { type: "string" } }, required: ["label"] } } } 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), {}))}
    ), }; }, { type: "object", properties: { customContent: { asCell: true }, items: { type: "array", items: { $ref: "#/$defs/Item" }, "default": [], asCell: true } }, required: ["customContent", "items"], $defs: { Item: { type: "object", properties: { label: { type: "string" } }, required: ["label"] } } } as const satisfies __ctHelpers.JSONSchema, { type: "object", properties: { $UI: { $ref: "#/$defs/JSXElement" } }, required: ["$UI"], $defs: { 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;