import * as __ctHelpers from "commontools";
import { pattern, UI } from "commontools";
// Module-level constant - should NOT be captured
const TAX_RATE = 0.08;
// Module-level function - should NOT be captured
function formatPrice(price: number): string {
return `$${price.toFixed(2)}`;
}
interface Item {
id: number;
price: number;
}
interface State {
items: Item[];
}
export default pattern((state) => {
return {
[UI]: (
{/* Should NOT capture module-level constant or function */}
{state.items.mapWithPattern(__ctHelpers.pattern(({ element: item, params: {} }) => (
Item: {__ctHelpers.derive({
type: "object",
properties: {
item: {
type: "object",
properties: {
price: {
type: "number",
asOpaque: true
}
},
required: ["price"]
}
},
required: ["item"]
} as const satisfies __ctHelpers.JSONSchema, {
type: "string"
} as const satisfies __ctHelpers.JSONSchema, { item: {
price: item.price
} }, ({ item }) => formatPrice(item.price * (1 + TAX_RATE)))}
), {
type: "object",
properties: {
element: {
$ref: "#/$defs/Item"
},
params: {
type: "object",
properties: {}
}
},
required: ["element", "params"],
$defs: {
Item: {
type: "object",
properties: {
id: {
type: "number"
},
price: {
type: "number"
}
},
required: ["id", "price"]
}
}
} 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: {
items: {
type: "array",
items: {
$ref: "#/$defs/Item"
}
}
},
required: ["items"],
$defs: {
Item: {
type: "object",
properties: {
id: {
type: "number"
},
price: {
type: "number"
}
},
required: ["id", "price"]
}
}
} 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;