diff --git a/.prettierignore b/.prettierignore index d81a8c5e92..55c3e867f7 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,3 +3,4 @@ node_modules coverage .next build +*.hbs \ No newline at end of file diff --git a/plop-templates/machine-template/index.ts.hbs b/plop-templates/machine-template/index.ts.hbs index 37dbb79d73..d35810df8c 100644 --- a/plop-templates/machine-template/index.ts.hbs +++ b/plop-templates/machine-template/index.ts.hbs @@ -1,2 +1,9 @@ -export * from "./{{machine}}.connect" -export * from "./{{machine}}.machine" \ No newline at end of file +import { {{machine}}Connect } from "./{{machine}}.connect" +import { {{machine}}Machine } from "./{{machine}}.machine" + +export const {{machine}} = { + machine: {{machine}}Machine, + connect: {{machine}}Connect, +} + +export type { {{capitalize machine}}MachineContext, {{capitalize machine}}MachineState } from "./{{machine}}.types" \ No newline at end of file diff --git a/plop-templates/machine-template/{{machine}}.connect.ts.hbs b/plop-templates/machine-template/{{machine}}.connect.ts.hbs index 43864cd5db..e54ed123c3 100644 --- a/plop-templates/machine-template/{{machine}}.connect.ts.hbs +++ b/plop-templates/machine-template/{{machine}}.connect.ts.hbs @@ -1,20 +1,13 @@ -import { - defaultPropNormalizer, - PropNormalizer, - StateMachine as S, -} from "@ui-machines/core" -import { Props } from "../type-utils" +import { defaultPropNormalizer, getEventKey } from "../utils" +import type { DOM, Props } from "../utils" import { getIds, getElements } from "./{{machine}}.dom" -import { {{capitalize machine}}MachineContext, {{capitalize machine}}MachineState } from "./{{machine}}.machine" -export function connect{{capitalize machine}}Machine( - state: S.State<{{capitalize machine}}MachineContext, {{capitalize machine}}MachineState>, - send: (event: S.Event) => void, +export function connect{{capitalize machine}}( + state: {{capitalize machine}}State, + send: {{capitalize machine}}Send, normalize = defaultPropNormalizer, ) { const { context: ctx } = state - const ids = getIds(ctx.uid) - return { elProps: normalize({ }), diff --git a/plop-templates/machine-template/{{machine}}.dom.ts.hbs b/plop-templates/machine-template/{{machine}}.dom.ts.hbs index bc7002a23b..a9e438c326 100644 --- a/plop-templates/machine-template/{{machine}}.dom.ts.hbs +++ b/plop-templates/machine-template/{{machine}}.dom.ts.hbs @@ -1,4 +1,6 @@ -import { -{{capitalize machine}}MachineContext } from "./{{machine}}.machine" export function getIds(uid: string) { return { } } -export function getElements(ctx: -{{capitalize machine}}MachineContext) { const doc = ctx.doc ?? document const ids = getIds(ctx.uid) return { } } \ No newline at end of file +import type { {{capitalize machine}}MachineContext as Ctx } from "./{{machine}}.types" + +export const dom = { + getDoc: (ctx: Ctx) => ctx.doc ?? document, + getRootId: (ctx: Ctx) => `{{machine}}-${ctx.uid}`, +} diff --git a/plop-templates/machine-template/{{machine}}.machine.ts.hbs b/plop-templates/machine-template/{{machine}}.machine.ts.hbs index 61c5611cd9..84a186624a 100644 --- a/plop-templates/machine-template/{{machine}}.machine.ts.hbs +++ b/plop-templates/machine-template/{{machine}}.machine.ts.hbs @@ -1,5 +1,6 @@ import { createMachine, preserve } from "@ui-machines/core" import { Context } from "../type-utils" +import { {{capitalize machine}}MachineContext, {{capitalize machine}}MachineState } from "./{{machine}}.types" export type {{capitalize machine}}MachineContext = Context<{}> diff --git a/plop-templates/machine-template/{{machine}}.types.ts.hbs b/plop-templates/machine-template/{{machine}}.types.ts.hbs new file mode 100644 index 0000000000..8acbed6551 --- /dev/null +++ b/plop-templates/machine-template/{{machine}}.types.ts.hbs @@ -0,0 +1,18 @@ +import type { StateMachine as S } from "@ui-machines/core" +import type { Context } from "../utils" + +export type {{capitalize machine}}MachineContext = Context<{ +}> + +export type {{capitalize machine}}MachineState = { + value: "unknown" | "idle" | "focused" +} + +export type {{capitalize machine}}State = S.State<{{capitalize machine}}MachineContext, {{capitalize machine}}MachineState> + +export type {{capitalize machine}}Send = S.Send + +export type {{capitalize machine}}ItemProps = { + value: string + disabled?: boolean +}