function __cfHardenFn(fn: Function) { Object.freeze(fn); const prototype = fn.prototype; if (prototype && typeof prototype === "object") { Object.freeze(prototype); } return fn; } import { __cfHelpers } from "commonfabric"; import { Cell, pattern, UI } from "commonfabric"; const define = undefined; const runtimeDeps = undefined; const __cfAmdHooks = undefined; interface State { items: Array<{ name: string; }>; } const __cfPattern_1 = __cfHelpers.pattern(__cf_pattern_input => { const item = __cf_pattern_input.key("element"); const counter = __cf_pattern_input.key("params", "counter"); return ({item.key("name")} #{counter}); }, { type: "object", properties: { element: { type: "object", properties: { name: { type: "string" } }, required: ["name"] }, params: { type: "object", properties: { counter: { type: "number", asCell: ["readonly"] } }, required: ["counter"] } }, required: ["element", "params"] } as const satisfies __cfHelpers.JSONSchema, { anyOf: [{ $ref: "https://commonfabric.org/schemas/vnode.json" }, { $ref: "#/$defs/UIRenderable" }, { type: "object", properties: {} }], $defs: { UIRenderable: { type: "object", properties: { $UI: { $ref: "https://commonfabric.org/schemas/vnode.json" } }, required: ["$UI"] } } } as const satisfies __cfHelpers.JSONSchema); // FIXTURE: map-capture-cell-of // Verifies: new Cell() variable closed over in .map() is captured with asCell schema annotation // .map(fn) → .mapWithPattern(pattern(...), { counter: counter }) // new Cell(0) capture → params.counter with { type: "number", asCell: true } export default pattern((state) => { const counter = new Cell(0, { type: "number" } as const satisfies __cfHelpers.JSONSchema).for("counter", true); return { [UI]: (
{state.key("items").mapWithPattern(__cfPattern_1, { counter: counter })}
), }; }, { type: "object", properties: { items: { type: "array", items: { type: "object", properties: { name: { type: "string" } }, required: ["name"] } } }, required: ["items"] } as const satisfies __cfHelpers.JSONSchema, { type: "object", properties: { $UI: { $ref: "#/$defs/JSXElement" } }, required: ["$UI"], $defs: { JSXElement: { anyOf: [{ $ref: "https://commonfabric.org/schemas/vnode.json" }, { $ref: "#/$defs/UIRenderable" }, { type: "object", properties: {} }] }, UIRenderable: { type: "object", properties: { $UI: { $ref: "https://commonfabric.org/schemas/vnode.json" } }, required: ["$UI"] } } } as const satisfies __cfHelpers.JSONSchema); // @ts-ignore: Internals function h(...args: any[]) { return __cfHelpers.h.apply(null, args); } __cfHardenFn(h); __cfReg({ __cfPattern_1 });