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 { action, computed, pattern, UI, VNode, Writable } from "commonfabric"; const define = undefined; const runtimeDeps = undefined; const __cfAmdHooks = undefined; interface View { value: unknown; label: string; } interface Item { name: string; value: Record | null; } interface State { view: View; items: Item[]; log: Writable; title: string; } function propOf(view: View): unknown { return view.value; } __cfHardenFn(propOf); function labeledBase(label: string) { return class { label = label; }; } __cfHardenFn(labeledBase); function formatterFor(name: string): (value: T) => string { return (value) => `${name}: ${String(value)}`; } __cfHardenFn(formatterFor); const __cfHandler_1 = __cfHelpers.handler(false as const satisfies __cfHelpers.JSONSchema, { type: "object", properties: { view: { $ref: "#/$defs/View" }, log: { type: "string", asCell: ["writeonly"] } }, required: ["view", "log"], $defs: { View: { type: "object", properties: { value: { type: "unknown" }, label: { type: "string" } }, required: ["value", "label"] } } } as const satisfies __cfHelpers.JSONSchema, (_, { view, log }) => { const value = propOf(view); if (typeof value === "object" && value !== null && "set" in value) { (value as { set: (next: string) => void; }).set("x"); } log.set(view.label); }); const __cfHandler_2 = __cfHelpers.handler(false as const satisfies __cfHelpers.JSONSchema, { type: "object", properties: { view: { $ref: "#/$defs/View" } }, required: ["view"], $defs: { View: { type: "object", properties: { value: { type: "unknown" }, label: { type: "string" } }, required: ["value", "label"] } } } as const satisfies __cfHelpers.JSONSchema, (_, { view }) => { interface Setter { set(next: string): void; (event: string): void; } interface Local extends Tagged { label: string; } class Label implements Tagged { tag = "label"; } const setter = propOf(view) as Setter | null; const local: Local = { tag: new Label().tag, label: view.label }; if (setter) setter.set(local.label); }); const __cfHandler_3 = __cfHelpers.handler(false as const satisfies __cfHelpers.JSONSchema, { type: "object", properties: { title: { type: "string" }, log: { type: "string", asCell: ["writeonly"] } }, required: ["title", "log"] } as const satisfies __cfHelpers.JSONSchema, (_, { title, log }) => { class Named extends labeledBase(title) { } log.set(new Named().label); }); const __cfHandler_4 = __cfHelpers.handler(false as const satisfies __cfHelpers.JSONSchema, { type: "object", properties: { title: { type: "string" }, view: { type: "object", properties: { label: { type: "string" } }, required: ["label"] }, log: { type: "string", asCell: ["writeonly"] } }, required: ["title", "view", "log"] } as const satisfies __cfHelpers.JSONSchema, (_, { title, log, view }) => { const format = formatterFor(title); log.set(format(view.label)); }); const __cfHandler_5 = __cfHelpers.handler(false as const satisfies __cfHelpers.JSONSchema, { type: "object", properties: { Kind: { type: "object", properties: { Beta: { type: "string" } }, required: ["Beta"] }, log: { type: "string", asCell: ["writeonly"] } }, required: ["Kind", "log"] } as const satisfies __cfHelpers.JSONSchema, (_, { log, Kind }) => { log.set(`${Mode.Alpha}:${Kind.Beta}`); }); const __cfLift_1 = __cfHelpers.lift<{ view: View; }, string>(({ view }) => { const copy: typeof view = view; const value = copy.value; return typeof value === "object" && value !== null && "send" in value ? String((value as { send: (event: Record) => void; })) : copy.label; }, { type: "object", properties: { view: { $ref: "#/$defs/View" } }, required: ["view"], $defs: { View: { type: "object", properties: { value: { type: "unknown" }, label: { type: "string" } }, required: ["value", "label"] } } } as const satisfies __cfHelpers.JSONSchema, { type: "string" } as const satisfies __cfHelpers.JSONSchema, { completeSchedulerScopeSummary: true }); const __cfLift_2 = __cfHelpers.lift<{ item: { value: Record | null; }; }, boolean>(({ item }) => typeof item.value === "object", { type: "object", properties: { item: { type: "object", properties: { value: { anyOf: [{ type: "object", properties: {}, additionalProperties: { type: "unknown" } }, { type: "null" }] } }, required: ["value"] } }, required: ["item"] } as const satisfies __cfHelpers.JSONSchema, { type: "boolean" } as const satisfies __cfHelpers.JSONSchema); const __cfLift_3 = __cfHelpers.lift<{ item: { value: Record | null; }; }, boolean>(({ item }) => item.value !== null, { type: "object", properties: { item: { type: "object", properties: { value: { anyOf: [{ type: "object", properties: {}, additionalProperties: { type: "unknown" } }, { type: "null" }] } }, required: ["value"] } }, required: ["item"] } as const satisfies __cfHelpers.JSONSchema, { type: "boolean" } as const satisfies __cfHelpers.JSONSchema); const __cfLift_4 = __cfHelpers.lift<{ item: { value: Record; }; }, string>(({ item }) => String((item.value as { get: (key: string) => unknown; })), { type: "object", properties: { item: { type: "object", properties: { value: { type: "object", properties: {}, additionalProperties: { type: "unknown" } } }, required: ["value"] } }, required: ["item"] } as const satisfies __cfHelpers.JSONSchema, { type: "string" } as const satisfies __cfHelpers.JSONSchema); const __cfLift_5 = __cfHelpers.lift<{ item: { name: string; }; Kind: typeof Kind; }, string>(({ item, Kind }) => item.name + Mode.Alpha + Kind.Beta, { type: "object", properties: { item: { type: "object", properties: { name: { type: "string" } }, required: ["name"] }, Kind: { type: "object", properties: { Beta: { type: "string", "enum": ["beta"] } }, required: ["Beta"] } }, required: ["item", "Kind"] } as const satisfies __cfHelpers.JSONSchema, { type: "string" } as const satisfies __cfHelpers.JSONSchema); const __cfPattern_1 = __cfHelpers.pattern(__cf_pattern_input => { const item = __cf_pattern_input.key("element"); const Kind = __cf_pattern_input.params.Kind; return ( {__cfHelpers.ifElse({ type: "boolean" } as const satisfies __cfHelpers.JSONSchema, { type: "string" } as const satisfies __cfHelpers.JSONSchema, { type: "string" } as const satisfies __cfHelpers.JSONSchema, { type: "string" } as const satisfies __cfHelpers.JSONSchema, __cfHelpers.when({ type: "boolean" } as const satisfies __cfHelpers.JSONSchema, { type: "boolean" } as const satisfies __cfHelpers.JSONSchema, { type: "boolean" } as const satisfies __cfHelpers.JSONSchema, __cfLift_2({ item: { value: item.key("value") } }), __cfLift_3({ item: { value: item.key("value") } })), __cfLift_4({ item: { value: item.key("value") } }), item.key("name"))} {__cfLift_5({ item: { name: item.key("name") }, Kind: Kind })} ); }, { type: "object", properties: { element: { $ref: "#/$defs/Item" }, params: { type: "object", properties: { Kind: { type: "object", properties: { Beta: { type: "string" } }, required: ["Beta"] } }, required: ["Kind"] } }, required: ["element", "params"], $defs: { Item: { type: "object", properties: { name: { type: "string" }, value: { anyOf: [{ type: "object", properties: {}, additionalProperties: { type: "unknown" } }, { type: "null" }] } }, required: ["name", "value"] } } } 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: captures-skip-type-positions // Verifies: a name that appears only in erased syntax is not captured // (value as { set: (next: string) => void }) → no `next` capture // (stream as { send: (event: …) => void }) → no `event` capture // const copy: typeof view = view → `view` captured for the // value, not for the type // (item.value as { get: (key: string) => … }) → neither `get` nor `key` // interface Setter { set(next: string): void } → no `next` capture // interface Local extends Tagged / implements → no `Tagged` capture // Mode.Alpha (a `const enum`, inlined) → no `Mode` capture, in a // callback and in a JSX // expression; the regular // `enum` Kind is captured // and that a value inside a type-shaped node is still captured: // class extends labeledBase(title) → `title` captured // formatterFor(title) → `title` captured // Context: the same capture collector serves actions, computeds and array // callbacks, and none of them may bind an erased name as an input: with no // such binding in scope, an unshrunk state would require it and the callback // would never run. export default pattern((__cf_pattern_input) => { const view = __cf_pattern_input.key("view"); const items = __cf_pattern_input.key("items"); const log = __cf_pattern_input.key("log"); const title = __cf_pattern_input.key("title"); interface Tagged { tag: string; } const enum Mode { Alpha = "alpha" } enum Kind { Beta = "beta" } const setIt = __cfHandler_1({ view: view, log: log }).for({ stream: "setIt" }, true); const viaDeclarations = __cfHandler_2({ view: view }).for({ stream: "viaDeclarations" }, true); const viaClassExtends = __cfHandler_3({ title: title, log: log }).for({ stream: "viaClassExtends" }, true); const viaInstantiation = __cfHandler_4({ title: title, log: log, view: { label: view.key("label") } }).for({ stream: "viaInstantiation" }, true); const viaEnums = __cfHandler_5({ log: log, Kind: { Beta: Kind.Beta } }).for({ stream: "viaEnums" }, true); const summary = __cfLift_1({ view: view }).for("summary", true); return { [UI]: (
{items.mapWithPattern(__cfPattern_1, { Kind: { Beta: Kind.Beta } })}
), }; }, { type: "object", properties: { view: { $ref: "#/$defs/View" }, items: { type: "array", items: { $ref: "#/$defs/Item" } }, log: { type: "string", asCell: ["cell"] }, title: { type: "string" } }, required: ["view", "items", "log", "title"], $defs: { Item: { type: "object", properties: { name: { type: "string" }, value: { anyOf: [{ type: "object", properties: {}, additionalProperties: { type: "unknown" } }, { type: "null" }] } }, required: ["name", "value"] }, View: { type: "object", properties: { value: { type: "unknown" }, label: { type: "string" } }, required: ["value", "label"] } } } as const satisfies __cfHelpers.JSONSchema, { 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({ __cfHandler_1, __cfHandler_2, __cfHandler_3, __cfHandler_4, __cfHandler_5, __cfLift_1, __cfLift_2, __cfLift_3, __cfLift_4, __cfLift_5, __cfPattern_1 });