From 67a4deddf75ad8b2ebcc413e4681b0fdcd02b224 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Fri, 4 Dec 2026 18:47:47 -0500 Subject: [PATCH 01/12] feat(codegen-ts): UI catalog v0, component maps and a record-admin screen The catalog (runtime-web) types what the TypeScript form and grid generators already emit, plus Page and Panel for a screen. formFile() and tanstackGrid() take a componentMap option and render through the app's map; without it their output is byte-identical. react ships defaultComponents, tanstack ships defaultDataGrid. The new ejectable recordAdmin() generator writes .admin.tsx (list, create, edit) derived from the generated form, grid and hooks, and falls back to the default map. TypeScript only; no metamodel vocabulary. Tests: golden output with and without a map, and a strict typecheck of the generated client tier against the runtime packages' source. --- changelog.d/ts-ui-catalog-v0.md | 13 + client/web/packages/react/src/index.ts | 7 + .../web/packages/react/src/ui-components.tsx | 210 +++++++ .../packages/react/src/use-entity-form.tsx | 24 +- .../react/test/ui-components.test.tsx | 102 ++++ client/web/packages/runtime-web/src/index.ts | 9 + .../packages/runtime-web/src/ui-catalog.ts | 276 +++++++++ .../web/packages/tanstack/src/entity-grid.tsx | 10 +- client/web/packages/tanstack/src/index.ts | 1 + .../packages/tanstack/src/ui-data-grid.tsx | 27 + .../tanstack/test/ui-data-grid.test.tsx | 39 ++ docs/README.md | 2 + docs/features/ui-catalog.md | 126 +++++ docs/ports/typescript-client.md | 20 +- .../registry.json | 8 + .../codegen-ts-react/src/form-file.ts | 8 +- .../src/generator-registry.ts | 2 +- .../packages/codegen-ts-react/src/index.ts | 4 +- .../codegen-ts-react/src/reference/form.ts | 8 +- .../src/templates/form-file.ts | 160 +++++- .../src/generator-registry.ts | 21 +- .../packages/codegen-ts-tanstack/src/index.ts | 6 +- .../src/record-admin-gate.ts | 22 + .../codegen-ts-tanstack/src/record-admin.ts | 52 ++ .../src/reference-templates.ts | 2 +- .../codegen-ts-tanstack/src/reference/grid.ts | 9 +- .../src/reference/record-admin.ts | 79 +++ .../codegen-ts-tanstack/src/tanstack-grid.ts | 9 +- .../src/templates/admin-screen-file.ts | 175 ++++++ .../src/templates/columns-file.ts | 47 +- .../__snapshots__/ui-catalog.test.ts.snap | 534 ++++++++++++++++++ .../test/fixtures/ui-catalog-entity.json | 35 ++ .../test/reference-byte-identical.test.ts | 3 + .../test/reference-templates.test.ts | 12 +- .../test/ui-catalog.test.ts | 235 ++++++++ .../packages/codegen-ts/src/engine-surface.ts | 1 + 36 files changed, 2252 insertions(+), 46 deletions(-) create mode 100644 changelog.d/ts-ui-catalog-v0.md create mode 100644 client/web/packages/react/src/ui-components.tsx create mode 100644 client/web/packages/react/test/ui-components.test.tsx create mode 100644 client/web/packages/runtime-web/src/ui-catalog.ts create mode 100644 client/web/packages/tanstack/src/ui-data-grid.tsx create mode 100644 client/web/packages/tanstack/test/ui-data-grid.test.tsx create mode 100644 docs/features/ui-catalog.md create mode 100644 server/typescript/packages/codegen-ts-tanstack/src/record-admin-gate.ts create mode 100644 server/typescript/packages/codegen-ts-tanstack/src/record-admin.ts create mode 100644 server/typescript/packages/codegen-ts-tanstack/src/reference/record-admin.ts create mode 100644 server/typescript/packages/codegen-ts-tanstack/src/templates/admin-screen-file.ts create mode 100644 server/typescript/packages/codegen-ts-tanstack/test/__snapshots__/ui-catalog.test.ts.snap create mode 100644 server/typescript/packages/codegen-ts-tanstack/test/fixtures/ui-catalog-entity.json create mode 100644 server/typescript/packages/codegen-ts-tanstack/test/ui-catalog.test.ts diff --git a/changelog.d/ts-ui-catalog-v0.md b/changelog.d/ts-ui-catalog-v0.md new file mode 100644 index 0000000000..759eb0aece --- /dev/null +++ b/changelog.d/ts-ui-catalog-v0.md @@ -0,0 +1,13 @@ +- **TypeScript client tier: UI catalog v0, component maps and a record-admin screen.** The + catalog types (`UI_CATALOG_COMPONENTS`, `UiCatalogProps` and one `UiProps` per name in + `@metaobjectsdev/runtime-web`) describe what the form and grid generators already emit: form, + field shell, five controls, nested and repeatable groups, button and data grid, plus `Page` + and `Panel` for a screen. `formFile()` and `tanstackGrid()` take a `componentMap` option. When + it is set, the form renders through the app's map, and the columns module exports an + `DataGrid` component. Without it, their output is byte-identical to before. + `@metaobjectsdev/react` ships `defaultComponents` and `UiComponentMap`, and + `@metaobjectsdev/tanstack` ships `defaultDataGrid`. The new ejectable `recordAdmin()` generator + (`meta eject record-admin`) writes `.admin.tsx`, a list, create and edit screen + derived from the generated form, grid and hooks. With no map configured, it renders through + the default components. TypeScript only, and no metamodel vocabulary. See + `docs/features/ui-catalog.md`. diff --git a/client/web/packages/react/src/index.ts b/client/web/packages/react/src/index.ts index 96a819004f..7be8ac2480 100644 --- a/client/web/packages/react/src/index.ts +++ b/client/web/packages/react/src/index.ts @@ -8,6 +8,13 @@ export { type UseEntityFormOptions, type UseEntityFormReturn, } from "./use-entity-form.js"; +export { + defaultComponents, + type UiComponentMap, + type UiFormComponentMap, + type ReactUiCatalogProps, + type UiControlRef, +} from "./ui-components.js"; export { CurrencyInput, type CurrencyInputProps } from "./currency-input.js"; export { ImageUploadAdapterProvider, diff --git a/client/web/packages/react/src/ui-components.tsx b/client/web/packages/react/src/ui-components.tsx new file mode 100644 index 0000000000..ea22289e68 --- /dev/null +++ b/client/web/packages/react/src/ui-components.tsx @@ -0,0 +1,210 @@ +// The UI catalog (v0) instantiated for React, and the default component map. +// +// `UiComponentMap` is what an application's component map module exports as `components` +// and what the generators' `componentMap` option points at: one React component per +// catalog name. `defaultComponents` is that map rendered as the plain markup the form +// generator writes when no map is configured (the same `metaobjects-*` classes, so +// `@metaobjectsdev/react/form.css` styles both). It carries no look of its own. +// +// An app keeps the defaults it likes and replaces the rest: +// +// import { defaultComponents } from "@metaobjectsdev/react"; +// import { defaultDataGrid } from "@metaobjectsdev/tanstack"; +// export const components = { ...defaultComponents, DataGrid: defaultDataGrid, TextInput: MyInput }; +// +// Bound controls receive the form library's `ref` and must attach it to their native +// element. These defaults use `forwardRef`, which works on React 18 and 19; a React 19 +// component may take `ref` as an ordinary prop instead. + +import { forwardRef, type ComponentType, type ReactElement, type ReactNode, type Ref, type SyntheticEvent } from "react"; +import type { + UiOption, + UiCatalogName, + UiCatalogFormName, + UiCatalogProps, + UiFormProps, + UiFormActionsProps, + UiFieldProps, + UiFormSectionProps, + UiFieldArrayProps, + UiTextInputProps, + UiTextAreaProps, + UiSelectProps, + UiCheckboxProps, + UiRadioGroupProps, + UiButtonProps, + UiPageProps, + UiPanelProps, +} from "@metaobjectsdev/runtime-web"; + +/** The ref a bound control receives. `never` because the element type is the control's own choice. */ +export type UiControlRef = Ref; + +/** The catalog's props for React: children are `ReactNode`, handlers take a synthetic event. */ +export type ReactUiCatalogProps = UiCatalogProps; + +/** One React component per catalog name: what a component map module exports as `components`. */ +export type UiComponentMap = { readonly [K in UiCatalogName]: ComponentType }; + +/** The part of a map a generated form uses. */ +export type UiFormComponentMap = Pick; + +type Native

= Omit; + +function Form(props: UiFormProps): ReactElement { + return ( +

+ {props.children} +
+ ); +} + +function FormActions(props: UiFormActionsProps): ReactElement { + return
{props.children}
; +} + +function Field(props: UiFieldProps): ReactElement { + return ( +
+ + {props.children} + {props.error !== undefined && ( + {props.error} + )} +
+ ); +} + +function FormSection(props: UiFormSectionProps): ReactElement { + return ( +
+ {props.legend} + {props.children} + {props.onRemove !== undefined && ( + + )} +
+ ); +} + +function FieldArray(props: UiFieldArrayProps): ReactElement { + return ( +
+ {props.label} + {props.children} + +
+ ); +} + +const TextInput = forwardRef>>( + function TextInput(props, ref) { + return ; + }, +); + +const TextArea = forwardRef>>( + function TextArea(props, ref) { + return