diff --git a/.changeset/37677-repeater-auto-span.md b/.changeset/37677-repeater-auto-span.md new file mode 100644 index 00000000000..4dc0baedf39 --- /dev/null +++ b/.changeset/37677-repeater-auto-span.md @@ -0,0 +1,13 @@ +--- +'@object-ui/plugin-form': patch +'@object-ui/console': patch +'@object-ui/app-shell': patch +'@objectstack/spec': patch +--- + +fix(plugin-form): a `repeater` field on `span: 'auto'` takes the whole row again, on the record form and on `/forms/NAME` + +Clause-②: no (layout only; an author could already set `span: 'full'`) +Metadata-protocol: none + +The spec's form field `span` docblock lists `repeater` among the types that take the whole row by default. A repeater used to get there through the wide line-items widget it mapped to; since it moved to the JSON editor that `json`, `composite` and `record` also use, both form renderers gave it one cell. The default width now reads the object field's own type, so a repeater is wide and those three types stay one cell. The Studio form designer's canvas asks the same rule, so it lays a repeater out as the form does. An authored `colSpan` still wins. The named-form page passes the object field's type to the shared resolver, as it already passed `multiple`. The spec docblock's stale "through the `field:grid` widget" clause now says how the width is decided. diff --git a/content/docs/references/ui/view.mdx b/content/docs/references/ui/view.mdx index e2dac206a6b..ce296fbf671 100644 --- a/content/docs/references/ui/view.mdx +++ b/content/docs/references/ui/view.mdx @@ -224,7 +224,7 @@ Column footer summary configuration | **required** | `boolean` | optional | Required override | | **hidden** | `boolean` | optional | Hidden override | | **colSpan** | `integer` | optional | Absolute column span (1-4). The renderer clamps it to the form grid's current column count, so the cell starts at a real column boundary at every surface width and never overflows (`colSpan: 4` in a 3-column grid renders as 3); a `colSpan` within the column count renders as authored, and `colSpan: 1` emits no span class at all. | -| **span** | `Enum<'auto' \| 'full'>` | optional (default: `"auto"`) | Relative field width. 'auto' (default — omit it): the renderer sizes the field from its widget type × the current column count — only textarea, markdown, html, richtext and repeater, plus a file or image field whose object field declares `multiple: true`, resolve to the full column count (repeater reaches it through the wide `field:grid` widget it maps to); an authored `colSpan` still wins over that default (`colSpan: 1` keeps such a field in one cell). 'full': resolves to the form grid's full column count. How far down the container-query tiers that span is emitted is the renderer's, not this key's: the renderer emits one clamped col-span class per multi-column tier (`@md:col-span-2 @2xl:col-span-3` for a 3-column grid), so the field takes the whole row at every multi-column tier, not just the widest. | +| **span** | `Enum<'auto' \| 'full'>` | optional (default: `"auto"`) | Relative field width. 'auto' (default — omit it): the renderer sizes the field from its widget type × the current column count — only textarea, markdown, html, richtext and repeater, plus a file or image field whose object field declares `multiple: true`, resolve to the full column count (repeater by its object-field type: the JSON editor it maps to is shared with json, composite and record, which stay one cell); an authored `colSpan` still wins over that default (`colSpan: 1` keeps such a field in one cell). 'full': resolves to the form grid's full column count. How far down the container-query tiers that span is emitted is the renderer's, not this key's: the renderer emits one clamped col-span class per multi-column tier (`@md:col-span-2 @2xl:col-span-3` for a 3-column grid), so the field takes the whole row at every multi-column tier, not just the widest. | | **widget** | `string` | optional | Custom widget/component name (overrides type-based inference) | | **language** | `string` | optional | Code editor language (for type=code) | | **keyField** | `{ field?: string; label?: string \| Record; placeholder?: string \| Record; helpText?: string \| Record; … }` | optional | Key column config for record-typed fields | @@ -354,7 +354,7 @@ Form-view select option — the object-field option shape minus the per-option ` | **required** | `boolean` | optional | Required override | | **hidden** | `boolean` | optional | Hidden override | | **colSpan** | `integer` | optional | Absolute column span (1-4). The renderer clamps it to the form grid's current column count, so the cell starts at a real column boundary at every surface width and never overflows (`colSpan: 4` in a 3-column grid renders as 3); a `colSpan` within the column count renders as authored, and `colSpan: 1` emits no span class at all. | -| **span** | `Enum<'auto' \| 'full'>` | optional (default: `"auto"`) | Relative field width. 'auto' (default — omit it): the renderer sizes the field from its widget type × the current column count — only textarea, markdown, html, richtext and repeater, plus a file or image field whose object field declares `multiple: true`, resolve to the full column count (repeater reaches it through the wide `field:grid` widget it maps to); an authored `colSpan` still wins over that default (`colSpan: 1` keeps such a field in one cell). 'full': resolves to the form grid's full column count. How far down the container-query tiers that span is emitted is the renderer's, not this key's: the renderer emits one clamped col-span class per multi-column tier (`@md:col-span-2 @2xl:col-span-3` for a 3-column grid), so the field takes the whole row at every multi-column tier, not just the widest. | +| **span** | `Enum<'auto' \| 'full'>` | optional (default: `"auto"`) | Relative field width. 'auto' (default — omit it): the renderer sizes the field from its widget type × the current column count — only textarea, markdown, html, richtext and repeater, plus a file or image field whose object field declares `multiple: true`, resolve to the full column count (repeater by its object-field type: the JSON editor it maps to is shared with json, composite and record, which stay one cell); an authored `colSpan` still wins over that default (`colSpan: 1` keeps such a field in one cell). 'full': resolves to the form grid's full column count. How far down the container-query tiers that span is emitted is the renderer's, not this key's: the renderer emits one clamped col-span class per multi-column tier (`@md:col-span-2 @2xl:col-span-3` for a 3-column grid), so the field takes the whole row at every multi-column tier, not just the widest. | | **widget** | `string` | optional | Custom widget/component name (overrides type-based inference) | | **language** | `string` | optional | Code editor language (for type=code) | | **keyField** | `{ field?: string; label?: string \| Record; placeholder?: string \| Record; helpText?: string \| Record; … }` | optional | Key column config for record-typed fields | diff --git a/packages/spec/liveness/view.json b/packages/spec/liveness/view.json index f3d084c406e..c768261ea62 100644 --- a/packages/spec/liveness/view.json +++ b/packages/spec/liveness/view.json @@ -365,7 +365,7 @@ "verifiedAt": "2026-08-11", "evidenceScope": "cross-repo", "evidence": "objectui: form renderers + spec-bridge form-view.ts:169 (audit L17); packages/rest/src/form-routes.ts registerFormEndpoints (the two /forms/:slug routes walk sections: resolve strips every lookup/master_detail/user field from the anonymous rendering, submit builds allowedFields from them)", - "note": "This row carries the blanket verdict for the whole FormField subtree beneath it (undrilled inheritance). [#7467] had added the anonymous public-form picker block to that subtree, read only by the anonymous lookup route; [#21180] REMOVED it 2026-10-01 (ADR-0087 D2, ruling E on #21079): the key is now a retiredKey() tombstone in FormFieldBaseSchema carrying the prescription, the route is deleted, and the resolve route strips lookup/master_detail/user fields from the anonymous rendering unconditionally. The subtree has no per-key rows, so the tombstone adds none; the retirement is registered as ui/FormField:publicPicker in RETIRED_KEYS_BY_MAJOR[18]. [#12174] drills the six FormField constraint keys out of the blanket verdict — maxLength/minLength/min/max/precision/scale are all LIVE, measured at objectui@f7c52e2 (2026-08-26): two independent spec-to-runtime routes copy all six onto the runtime field (packages/react/src/spec-bridge/bridges/form-view.ts mapField, objectui#5898; packages/plugin-form/src/sectionFields.ts normalizeSectionField), the console FormPage merges override.maxLength ?? def.maxLength onto the rendered input (apps/console/src/components/FormPage.tsx:548, objectui#5595), packages/fields buildValidationRules turns minLength/maxLength/min/max into react-hook-form rules, ObjectForm.tsx:691 derives the number input step from precision, and NumberField.tsx:21 reads scale; server-side, GET /forms/:slug (packages/rest/src/rest-server.ts) serves the rows verbatim to anonymous renderers (a conduit, no key-level read). On that measurement the four count-shaped keys tightened to the #11566/#11949/#8321 value shapes (lengths int>=1, precision/scale int>=0; min/max stay bare numbers — they are values, not counts). Form-row `span` / `scale` read points (FormFieldBaseSchema in packages/spec/src/ui/view.zod.ts; moved out of spec source, #23434), re-read at objectui @b9814b334 on 2026-10-14: objectui @b9814b334 packages/plugin-form/src/autoLayout.ts#resolveColSpan resolves 'full' to the grid's full column count and sizes 'auto' from the widget type, objectui @b9814b334 packages/plugin-form/src/autoLayout.ts#WIDE_FIELD_TYPES makes textarea, markdown, html, richtext and repeater (via the wide `field:grid` widget) span the full count, and objectui @b9814b334 packages/components/src/renderers/form/form.tsx#spanLadderFor emits one clamped col-span class per multi-column tier (`@md:col-span-2 @2xl:col-span-3` for a 3-column grid; the widest-tier-only under-span of #17328 ended with objectui#9244 / objectui#9253). A form row's `scale` reaches `Intl.NumberFormat` through plugin-form (see field.json row `scale`). [#27155] The section key `pane` (split-pane placement) is REMOVED 2026-10-28 with `type: 'split'` (ADR-0050): a retiredKey() tombstone in FormSectionSchema carrying the prescription, stripped by the protocol-18 form-view-presentation-types-removed conversion. The subtree has no per-key rows, so the tombstone adds none; the retirement is registered as ui/FormSection:pane in RETIRED_KEYS_BY_MAJOR[18]." + "note": "This row carries the blanket verdict for the whole FormField subtree beneath it (undrilled inheritance). [#7467] had added the anonymous public-form picker block to that subtree, read only by the anonymous lookup route; [#21180] REMOVED it 2026-10-01 (ADR-0087 D2, ruling E on #21079): the key is now a retiredKey() tombstone in FormFieldBaseSchema carrying the prescription, the route is deleted, and the resolve route strips lookup/master_detail/user fields from the anonymous rendering unconditionally. The subtree has no per-key rows, so the tombstone adds none; the retirement is registered as ui/FormField:publicPicker in RETIRED_KEYS_BY_MAJOR[18]. [#12174] drills the six FormField constraint keys out of the blanket verdict — maxLength/minLength/min/max/precision/scale are all LIVE, measured at objectui@f7c52e2 (2026-08-26): two independent spec-to-runtime routes copy all six onto the runtime field (packages/react/src/spec-bridge/bridges/form-view.ts mapField, objectui#5898; packages/plugin-form/src/sectionFields.ts normalizeSectionField), the console FormPage merges override.maxLength ?? def.maxLength onto the rendered input (apps/console/src/components/FormPage.tsx:548, objectui#5595), packages/fields buildValidationRules turns minLength/maxLength/min/max into react-hook-form rules, ObjectForm.tsx:691 derives the number input step from precision, and NumberField.tsx:21 reads scale; server-side, GET /forms/:slug (packages/rest/src/rest-server.ts) serves the rows verbatim to anonymous renderers (a conduit, no key-level read). On that measurement the four count-shaped keys tightened to the #11566/#11949/#8321 value shapes (lengths int>=1, precision/scale int>=0; min/max stay bare numbers — they are values, not counts). Form-row `span` / `scale` read points (FormFieldBaseSchema in packages/spec/src/ui/view.zod.ts; moved out of spec source, #23434), re-read at objectui @b9814b334 on 2026-10-14: objectui @b9814b334 packages/plugin-form/src/autoLayout.ts#resolveColSpan resolves 'full' to the grid's full column count and sizes 'auto' from the widget type, objectui @b9814b334 packages/plugin-form/src/autoLayout.ts#WIDE_FIELD_TYPES makes textarea, markdown, html, richtext and repeater (via the wide `field:grid` widget) span the full count (re-read 2026-11-27, #37677: since objectui#11448 repeater maps to the shared `field:object` JSON editor, so autoLayout.ts#WIDE_DECLARED_FIELD_TYPES widens it by its object-field type, read in both form renderers), and objectui @b9814b334 packages/components/src/renderers/form/form.tsx#spanLadderFor emits one clamped col-span class per multi-column tier (`@md:col-span-2 @2xl:col-span-3` for a 3-column grid; the widest-tier-only under-span of #17328 ended with objectui#9244 / objectui#9253). A form row's `scale` reaches `Intl.NumberFormat` through plugin-form (see field.json row `scale`). [#27155] The section key `pane` (split-pane placement) is REMOVED 2026-10-28 with `type: 'split'` (ADR-0050): a retiredKey() tombstone in FormSectionSchema carrying the prescription, stripped by the protocol-18 form-view-presentation-types-removed conversion. The subtree has no per-key rows, so the tombstone adds none; the retirement is registered as ui/FormSection:pane in RETIRED_KEYS_BY_MAJOR[18]." }, "groups": { "status": "live", diff --git a/packages/spec/src/ui/view.zod.ts b/packages/spec/src/ui/view.zod.ts index bb2182267fc..14d0af65371 100644 --- a/packages/spec/src/ui/view.zod.ts +++ b/packages/spec/src/ui/view.zod.ts @@ -4354,7 +4354,7 @@ const FormFieldBaseSchema = lazySchema(() => { * The read points (`resolveColSpan`, the wide-type list, the span ladder) * are recorded in `packages/spec/liveness/view.json`, row `form.sections`. */ - span: z.enum(['auto', 'full']).default('auto').describe("Relative field width. 'auto' (default — omit it): the renderer sizes the field from its widget type × the current column count — only textarea, markdown, html, richtext and repeater, plus a file or image field whose object field declares `multiple: true`, resolve to the full column count (repeater reaches it through the wide `field:grid` widget it maps to); an authored `colSpan` still wins over that default (`colSpan: 1` keeps such a field in one cell). 'full': resolves to the form grid's full column count. How far down the container-query tiers that span is emitted is the renderer's, not this key's: the renderer emits one clamped col-span class per multi-column tier (`@md:col-span-2 @2xl:col-span-3` for a 3-column grid), so the field takes the whole row at every multi-column tier, not just the widest."), + span: z.enum(['auto', 'full']).default('auto').describe("Relative field width. 'auto' (default — omit it): the renderer sizes the field from its widget type × the current column count — only textarea, markdown, html, richtext and repeater, plus a file or image field whose object field declares `multiple: true`, resolve to the full column count (repeater by its object-field type: the JSON editor it maps to is shared with json, composite and record, which stay one cell); an authored `colSpan` still wins over that default (`colSpan: 1` keeps such a field in one cell). 'full': resolves to the form grid's full column count. How far down the container-query tiers that span is emitted is the renderer's, not this key's: the renderer emits one clamped col-span class per multi-column tier (`@md:col-span-2 @2xl:col-span-3` for a 3-column grid), so the field takes the whole row at every multi-column tier, not just the widest."), /** Custom widget override — only needed when auto-inference is insufficient */ widget: z.string().optional().describe('Custom widget/component name (overrides type-based inference)'), diff --git a/ui/apps/console/src/components/FormPage.fieldSpan-37559.test.tsx b/ui/apps/console/src/components/FormPage.fieldSpan-37559.test.tsx index 44e53e31bbb..31afb8e56fa 100644 --- a/ui/apps/console/src/components/FormPage.fieldSpan-37559.test.tsx +++ b/ui/apps/console/src/components/FormPage.fieldSpan-37559.test.tsx @@ -36,6 +36,8 @@ const OBJECT_SCHEMA = { owner: { type: 'text', label: 'Owner' }, attachments: { type: 'file', label: 'Attachments', multiple: true }, receipt: { type: 'file', label: 'Receipt' }, + lines: { type: 'repeater', label: 'Lines' }, + payload: { type: 'json', label: 'Payload' }, }, }; @@ -142,4 +144,22 @@ describe('objectstack#37559 — /forms/:name honours a form field span', () => { renderForm(['title', { field: 'receipt', multiple: true }]); expect(cellsOf(await rowOf('Receipt'))).toBe(1); }); + + // objectstack#37677: the spec lists repeater as wide; the widget id it maps to + // (`field:object`) is shared with json, so the width is read off the OBJECT + // field's type. The record form's twin is plugin-form `repeaterAutoSpan-37677`. + it("a repeater field takes the whole row on `span: 'auto'`", async () => { + renderForm(['title', 'lines']); + expect(cellsOf(await rowOf('Lines'))).toBe(2); + }); + + it('CONTROL — a json field, on the same JSON editor, stays one cell', async () => { + renderForm(['title', 'payload']); + expect(cellsOf(await rowOf('Payload'))).toBe(1); + }); + + it('CONTROL — an authored colSpan wins over the repeater default', async () => { + renderForm([{ field: 'lines', colSpan: 1 }, 'title']); + expect(cellsOf(await rowOf('Lines'))).toBe(1); + }); }); diff --git a/ui/apps/console/src/components/FormPage.tsx b/ui/apps/console/src/components/FormPage.tsx index 03e79b6ec5c..9b116902d44 100644 --- a/ui/apps/console/src/components/FormPage.tsx +++ b/ui/apps/console/src/components/FormPage.tsx @@ -954,8 +954,10 @@ export function buildSections( span: (override as { span?: 'auto' | 'full' }).span, // The wide default reads the OBJECT field's own `multiple`, as the // spec and the record form (`sectionFields.ts`) do; a form-level - // `multiple` changes the widget above, not the default width. - field: { multiple: def.multiple }, + // `multiple` changes the widget above, not the default width. Its + // `type` too: a `repeater` is wide by its declaration, since the + // widget id it maps to (`field:object`) is shared (#37677). + field: { type: def.type, multiple: def.multiple }, }, cols, ) as 1 | 2 | 3 | 4, diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.test.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.test.tsx index b814f5dd3d7..61c0b7fe418 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.test.tsx @@ -248,7 +248,7 @@ describe('ObjectFormDesigner — object translations (objectui#3134)', () => { describe('ObjectFormDesigner — emits the one legal `FormField.type` spelling (objectui#4838)', () => { // Maintainer ruling 2026-08-19: a bare spec-type name is NOT a legal // `FormField.type`. The canvas is a PRODUCER of that vocabulary (it hands a - // type to `isWideFieldType`), so it is the producer that was fixed — the + // type to `resolveColSpan`, once `isWideFieldType`), so it is the producer that was fixed — the // tolerant `field:`-prefix fallback in `renderFieldComponent` and the // dual-spelling `WIDE_FIELD_TYPES` set are deliberately untouched. @@ -283,13 +283,13 @@ describe('ObjectFormDesigner — emits the one legal `FormField.type` spelling ( }); it('lays a `repeater` field out the way the runtime form resolves it', () => { - // The canvas asks the width question through `mapFieldTypeToFormType`, the - // runtime form's own resolution, so the two cannot drift. `repeater` is an - // untyped JSON array in the spec and resolves to the JSON editor - // (`field:object`) beside `composite` and `record`; that widget is not - // wide, so the canvas lays it out at normal width, as the form does. (It - // resolved to the WIDE line-items grid until that grid was found drawing - // bare rows for a column-less repeater.) + // The canvas asks the width question through the runtime form's own + // `span: 'auto'` default (`resolveColSpan`), so the two cannot drift. + // `repeater` is an untyped JSON array in the spec and resolves to the JSON + // editor (`field:object`) beside `composite` and `record`; that widget is + // not wide, but the spec `span` docblock lists repeater as wide, and the + // form widens it by its declared type (objectstack#37677). So the canvas + // gives it the whole row, as the record form and `/forms/NAME` do. expect(toFormFieldType('repeater')).toBe('field:object'); render( { + expect(toFormFieldType('json')).toBe('field:object'); + render( + , + ); + const card = screen.getByText('Payload').closest('.cursor-grab') as HTMLElement; + expect(card).toBeTruthy(); expect(card.className).not.toContain('col-span-full'); }); diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.tsx index 63a7b779e23..678de60d0a2 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.tsx @@ -44,7 +44,7 @@ import { SortableContext, verticalListSortingStrategy, useSortable, arrayMove } import { CSS } from '@dnd-kit/utilities'; import { GripVertical, Plus, Trash2, ChevronUp, ChevronDown, ChevronsUpDown, PanelTop, Settings2 } from 'lucide-react'; import { cn } from '@object-ui/components'; -import { inferColumns, containerGridColsFor, isWideFieldType } from '@object-ui/plugin-form/core'; +import { inferColumns, containerGridColsFor, resolveColSpan } from '@object-ui/plugin-form/core'; import { toFormFieldType } from './formFieldType.js'; import { resolveBooleanControl } from '@object-ui/fields'; import { @@ -524,13 +524,19 @@ function SortableField({ }); const type = String(entry.def.type ?? 'text'); const required = !!entry.def.required; - // Mirror the real form: wide widgets (textarea/markdown/html/…) take the whole - // row. `col-span-full` (grid-column: 1/-1) spans every column at ANY container - // width, so it stays correct as the responsive grid collapses to one column. - // `isWideFieldType` reads FORM vocabulary, so the raw object type is - // normalized to its widget id first (see `toFormFieldType`). `type` itself + // Mirror the real form: wide widgets (textarea/markdown/html/…) and a + // repeater take the whole row. `col-span-full` (grid-column: 1/-1) spans every + // column at ANY container width, so it stays correct as the responsive grid + // collapses to one column. The question goes through the runtime form's own + // `span: 'auto'` default (`resolveColSpan`): its widget-id rule reads FORM + // vocabulary, so the raw object type is normalized to its widget id first + // (see `toFormFieldType`), and its declaration rule reads the raw type off the + // stash, as the record form's object-field stash carries it (objectstack#37677: + // a repeater maps to the shared JSON editor, which is not wide). `type` itself // stays the spec spelling — that is what `FieldControlPreview` switches on. - const spanFull = columns > 1 && isWideFieldType(toFormFieldType(type)); + const spanFull = + columns > 1 && + resolveColSpan({ name: entry.name, type: toFormFieldType(type), field: { type } }, columns) >= columns; // objectui#13148 — the type tag names the type the way the type picker and // the inspector do (`select` reads "Picklist"), never by its spec id. const typeName = fieldTypeName(type, locale); diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.typeName-13148.test.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.typeName-13148.test.tsx index 371f988ca96..64e399d9ba0 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.typeName-13148.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.typeName-13148.test.tsx @@ -128,8 +128,11 @@ describe('form designer field card type tag (objectui#13148)', () => { expect(name, `no en-US row for ${id}`).not.toBe(`engine.fieldType.${id}`); const c = card(`Field ${id}`); expect(within(c).getByText(name)).toBeInTheDocument(); - // CONTROL — the wide-widget span reads the spec id, not the name. - expect(c.className.split(/\s+/).includes('col-span-full'), id).toBe(isWideFieldType(toFormFieldType(id))); + // CONTROL — the wide-widget span reads the spec id, not the name: a wide + // widget, or a repeater, which the form widens by its declared type + // because the JSON editor it maps to is shared (objectstack#37677). + const wide = isWideFieldType(toFormFieldType(id)) || id === 'repeater'; + expect(c.className.split(/\s+/).includes('col-span-full'), id).toBe(wide); } }); diff --git a/ui/packages/plugin-form/src/__tests__/repeaterAutoSpan-37677.test.tsx b/ui/packages/plugin-form/src/__tests__/repeaterAutoSpan-37677.test.tsx new file mode 100644 index 00000000000..c8cc0efdb37 --- /dev/null +++ b/ui/packages/plugin-form/src/__tests__/repeaterAutoSpan-37677.test.tsx @@ -0,0 +1,106 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * objectstack-ai/objectstack#37677 — a `repeater` field on `span: 'auto'` + * takes the whole row of a multi-column record form. + * + * `FormFieldSchema.span` (`packages/spec/src/ui/view.zod.ts`) lists repeater + * among the types that resolve to the full column count. It reached it through + * the wide `field:grid` widget it used to map to; since objectui#11448 it maps + * to `field:object`, the JSON editor `json`, `object`, `composite` and `record` + * share, so the type-only rule gave it one cell. The width is now read off the + * OBJECT field's type, and the shared widget id stays narrow. + * + * The named-form page's twin pin is + * `apps/console/src/components/FormPage.fieldSpan-37559.test.tsx`. + */ +import { describe, it, expect, vi } from 'vitest'; +import { render, waitFor } from '@testing-library/react'; +import React from 'react'; +import type { FormField } from '@object-ui/types'; +import { registerAllFields, preloadGridField, mapFieldTypeToFormType } from '@object-ui/fields'; +import { ModalForm } from '../ModalForm'; +import { isWideFieldType, resolveColSpan } from '../autoLayout'; + +await preloadGridField(); +registerAllFields(); + +const OBJECT_FIELDS = { + name: { type: 'text', label: 'Name' }, + notes: { type: 'textarea', label: 'Notes' }, + lines: { type: 'repeater', label: 'Lines' }, + payload: { type: 'json', label: 'Payload' }, +}; + +function openEditDialog() { + const ds = { + getObjectSchema: vi.fn().mockResolvedValue({ name: 'zoo', fields: OBJECT_FIELDS }), + findOne: vi.fn().mockResolvedValue({ id: 'z1', name: 'x', lines: [{ a: 1 }], payload: { b: 2 } }), + find: vi.fn().mockResolvedValue({ data: [] }), + create: vi.fn(), + update: vi.fn(), + }; + render( + , + ); +} + +/** The col-span classes on one rendered row. */ +async function spanOf(name: string): Promise { + const row = await waitFor(() => { + const el = document.querySelector(`[data-field="${name}"]`); + if (!el) throw new Error(`${name} not rendered`); + return el; + }); + return (row.getAttribute('class') || '').split(/\s+/).filter((t) => /(^|:)col-span-/.test(t)); +} + +describe("objectstack#37677 — a repeater on span 'auto' takes the whole row", () => { + it('record Edit dialog, 2 columns: the repeater row spans both cells, as the textarea does', async () => { + openEditDialog(); + expect(await spanOf('lines')).toEqual(['@md:col-span-2']); + expect(await spanOf('notes')).toEqual(['@md:col-span-2']); + }); + + it('CONTROL — a json field, on the same JSON editor widget, stays one cell; so does a text field', async () => { + openEditDialog(); + expect(await spanOf('payload')).toEqual([]); + expect(await spanOf('name')).toEqual([]); + }); + + it('the shared widget id alone is not wide: the width comes from the object-field type', () => { + expect(mapFieldTypeToFormType('repeater')).toBe('field:object'); + expect(isWideFieldType('field:object')).toBe(false); + const asWidget = { name: 'lines', type: 'field:object' } as FormField; + expect(resolveColSpan(asWidget, 3)).toBe(1); + expect(resolveColSpan({ ...asWidget, field: { type: 'repeater' } }, 3)).toBe(3); + expect(resolveColSpan({ ...asWidget, field: { type: 'json' } }, 3)).toBe(1); + }); + + it('a raw object-field type (the form designer passes one) is wide on its name', () => { + expect(resolveColSpan({ name: 'lines', type: 'repeater' } as FormField, 2)).toBe(2); + // …through the declaration rule, not the type-only answer app-shell's + // `richtextSurfaceParity` holds equal to plugin-detail's. + expect(isWideFieldType('repeater')).toBe(false); + }); + + it('CONTROL — an authored colSpan still wins over the repeater default', () => { + const f = { name: 'lines', type: 'field:object', field: { type: 'repeater' }, colSpan: 1 } as FormField; + expect(resolveColSpan(f, 3)).toBe(1); + }); +}); diff --git a/ui/packages/plugin-form/src/autoLayout.ts b/ui/packages/plugin-form/src/autoLayout.ts index 329baca52db..aa5a3d44926 100644 --- a/ui/packages/plugin-form/src/autoLayout.ts +++ b/ui/packages/plugin-form/src/autoLayout.ts @@ -112,17 +112,43 @@ export function isWideFieldType(type: string): boolean { */ const MULTI_FILE_FIELD_TYPES = new Set(['file', 'image', 'field:file', 'field:image']); +/** + * The object field type that takes the whole row on its declaration alone, + * whatever widget id it maps to: `repeater`, an embedded array of rows + * (objectstack-ai/objectstack#37677). + * + * Read off the OBJECT field, not the resolved `FormField.type`, because the + * widget id it maps to is shared: `mapFieldTypeToFormType` maps `repeater` to + * `field:object`, the JSON editor that `json`, `object`, `composite` and + * `record` take too (objectui#11448). Putting `field:object` on + * {@link WIDE_FIELD_TYPES} would widen all five. `repeater` used to reach the + * full row through the wide `field:grid` widget it mapped to, and lost it when + * the alias moved, while the spec `span` docblock still lists it as wide. + * + * The bare name is matched on `FormField.type` as well, for a caller that + * passes a raw object-field type: app-shell's `ObjectFormDesigner` canvas asks + * {@link resolveColSpan} with the raw type in the stash, so it lays a repeater + * out the way the runtime form does. It is kept + * OFF {@link WIDE_FIELD_TYPES} on purpose: {@link isWideFieldType} is the + * type-only answer app-shell's `richtextSurfaceParity` test holds equal to + * plugin-detail's, and the detail view's width is not this rule's to change. + */ +const WIDE_DECLARED_FIELD_TYPES = new Set(['repeater']); + /** * Does this form field take the whole row by default (the `span: 'auto'` rule)? * - * A wide type (see {@link isWideFieldType}), or a `file` / `image` field whose - * OBJECT field declares `multiple: true` — the rule plugin-detail's - * `isWideDetailField` applies to the detail view, so a multi-file field reads - * wide on both surfaces. - * - * `multiple` is read off the object-field definition the object-bound form - * paths stash on the FormField (`FormField.field`), and nothing else, as the - * detail rule reads it off the object schema: it is the field's declaration. + * A wide type (see {@link isWideFieldType}), a `repeater` (see + * {@link WIDE_DECLARED_FIELD_TYPES}), or a `file` / `image` field whose OBJECT + * field declares `multiple: true`. The first and the last are the rule + * plugin-detail's `isWideDetailField` applies to the detail view, so a + * multi-file field reads wide on both surfaces; the repeater rule is the + * form's alone (the spec `span` key is a form-field key). + * + * `type` and `multiple` are read off the object-field definition the + * object-bound form paths stash on the FormField (`FormField.field`), and + * nothing else, as the detail rule reads `multiple` off the object schema: + * they are the field's declaration. * A field with no stashed object field (an inline member, a form mounted * without an object) keeps the type-only answer. * @@ -132,6 +158,8 @@ const MULTI_FILE_FIELD_TYPES = new Set(['file', 'image', 'field:file', 'field:im function isWideFormField(field: FormField): boolean { if (!field.type) return false; if (isWideFieldType(field.type)) return true; + if (WIDE_DECLARED_FIELD_TYPES.has(field.type)) return true; + if (WIDE_DECLARED_FIELD_TYPES.has(field.field?.type)) return true; return MULTI_FILE_FIELD_TYPES.has(field.type) && field.field?.multiple === true; } @@ -188,7 +216,8 @@ function clampGrid(n: number | undefined): number { * * 2. legacy `colSpan` → honoured but CLAMPED to the grid (never overflows). * 3. wide widget type → whole row (textarea/markdown/… — the `span:'auto'` default), - * and a `file` / `image` field whose object field declares `multiple: true`. + * a `repeater` (by its type or its object field's type), and a `file` / + * `image` field whose object field declares `multiple: true`. * 4. section density → grid / sectionColumns, so `sectionColumns` fields fill a row. * * `sectionColumns` defaults to the grid width, i.e. one field per cell (the flat @@ -211,7 +240,7 @@ export function resolveColSpan( return Math.min(Math.max(1, Math.floor(field.colSpan)), grid); } - // `span: 'auto'` (or unset): wide widgets, and multi-file uploads, take the whole row. + // `span: 'auto'` (or unset): wide widgets, repeaters and multi-file uploads take the whole row. if (isWideFormField(field)) return grid; // Otherwise fill the section's density: N per row → grid/N cells each. @@ -489,7 +518,8 @@ export interface SectionedGridLayout { * row, and a `columns: 3` section on a 4-wide grid spanned 1 cell, FOUR per * row (`Math.round(grid / sectionColumns)`). The grid becomes * {@link TWELVE_TRACK_GRID_COLS} and each field spans twelfths of the row: - * 1. `span: 'full'`, or a wide widget type or multi-file upload → 12, the whole row; + * 1. `span: 'full'`, or a wide widget type, a repeater or a multi-file + * upload → 12, the whole row; * 2. an authored `colSpan` → that many of its SECTION's columns, clamped * to them (it keeps winning over the density); * 3. otherwise → 12 / the section's columns.