diff --git a/.changeset/37521-rich-text-cell-docs-select-first.md b/.changeset/37521-rich-text-cell-docs-select-first.md new file mode 100644 index 00000000000..e9b757d22b8 --- /dev/null +++ b/.changeset/37521-rich-text-cell-docs-select-first.md @@ -0,0 +1,18 @@ +--- +'@object-ui/fields': patch +'@object-ui/components': patch +'@object-ui/types': patch +--- + +fix(ui): the rich-text cell text, the read-only `data-table` warning and the `onBatchSave` refusal describe the one editing model the grid has + +Clause-②: no +Metadata-protocol: none + +The list grid has one way to edit: select-first, each committed cell saved at once. Three shipped texts still described the retired staged model or named the wrong thing to mount. + +- **`@object-ui/fields`.** The README's "grid cell editor's face" section and the `FieldEditWidget` comment on the rich-content cell panel no longer say that a grid without `cellSelection` opens the `markdown`, `html` or `richtext` box over the cell and keeps its text for the grid's save buttons. The grid edits only in its select-first model, and it opens the box in a panel under the cell: Enter is a new line, Ctrl/Cmd+Enter or a click outside saves, Esc discards. +- **`@object-ui/components`.** The console warning for an editable `data-table` that renders read-only now tells the host to mount `GridCellSelectionProvider`. It named `GridCellSelection`, which is the context's value type and cannot be mounted. The table's host-injected cell editor no longer checks for the select-first model on each key, because an editor only opens inside that model. Tab and Ctrl/Cmd+Enter behave as before. +- **`@object-ui/types`.** The `data-table` schema's refusal of `onBatchSave` names its successor: `onBatchSave` → `onRowSave` on `object-grid`. Render an `object-grid`, which writes each committed cell through its data source, or pass `onRowSave` inside a `GridCellSelectionProvider` from a React host, and delete the key. It used to point the author at a toast or an `action:button` node. The key is refused exactly as before. + +Nothing to migrate. diff --git a/ui/packages/components/src/__tests__/data-table-autosave-35685.test.tsx b/ui/packages/components/src/__tests__/data-table-autosave-35685.test.tsx index 5aaf9b659b3..d32c463977d 100644 --- a/ui/packages/components/src/__tests__/data-table-autosave-35685.test.tsx +++ b/ui/packages/components/src/__tests__/data-table-autosave-35685.test.tsx @@ -8,7 +8,7 @@ /** * `data-table`'s per-cell save in the select-first model (objectstack#35685), - * behind the `GridCellSelection` a host mounts. + * behind the `GridCellSelectionProvider` a host mounts. * * 1. A committed cell sends its record's update at once: one call, that * cell only; no save bar, no row Save/Cancel column, no amber row; the @@ -115,7 +115,7 @@ function deferredSave() { } describe('data-table autosave — a committed cell saves at once (objectstack#35685)', () => { - it('sends one update with that cell only, draws no save bar, no edit column and no amber row', async () => { + it('sends one update with that cell only, draws no save bar, no row Save button and no amber row', async () => { const { onRowSave, calls } = deferredSave(); const t = renderTable(onRowSave); t.typeAndEnter(0, 0, 'Alpha 2'); @@ -127,7 +127,6 @@ describe('data-table autosave — a committed cell saves at once (objectstack#35 expect(screen.queryByText(/Save All/)).toBeNull(); expect(screen.queryByText(/row modified/)).toBeNull(); expect(t.container.querySelector('button[title="Save row"]')).toBeNull(); - expect(t.container.querySelector('[data-testid="data-table-edit-column-header"]')).toBeNull(); const firstRow = t.container.querySelectorAll('tbody tr')[0] as HTMLElement; expect(firstRow.className).not.toContain('bg-amber-50'); expect(t.cell(0, 0).className).not.toContain('text-amber-700'); @@ -291,7 +290,10 @@ describe('data-table autosave — no staged fallback: a table that cannot save r expect(onRowSave).not.toHaveBeenCalled(); const lines = warn.mock.calls.map((c) => String(c[0])).filter((m) => m.startsWith('[ObjectUI] DataTable editable:')); expect(lines).toHaveLength(1); - expect(lines[0]).toMatch(/GridCellSelection/); + // The component a host mounts is the provider; `GridCellSelection` is the + // context's value type, which cannot be mounted. + expect(lines[0].match(/`GridCellSelectionProvider`/g)).toHaveLength(2); + expect(lines[0]).not.toContain('`GridCellSelection`'); }); it('under the provider with no onRowSave: no editor opens, no save bar, one console warning naming onRowSave', () => { diff --git a/ui/packages/components/src/__tests__/data-table-select-first-35684.test.tsx b/ui/packages/components/src/__tests__/data-table-select-first-35684.test.tsx index 72ef227b2e4..f075238e2b8 100644 --- a/ui/packages/components/src/__tests__/data-table-select-first-35684.test.tsx +++ b/ui/packages/components/src/__tests__/data-table-select-first-35684.test.tsx @@ -8,7 +8,7 @@ /** * `data-table`'s select-first cell model (objectstack#35684), behind the - * `GridCellSelection` a host mounts. The list page mounts it through + * `GridCellSelectionProvider` a host mounts. The list page mounts it through * `ObjectGrid`'s `cellSelection`; its keys while selected and while editing * are `data-table-keys-35687.test.tsx`. * @@ -336,7 +336,6 @@ describe('data-table select-first — a cell that opens no editor says why', () }); describe('data-table select-first — no edit-only column, ever (objectstack#35554, objectstack#35685)', () => { - const editHeader = (c: HTMLElement) => c.querySelector('[data-testid="data-table-edit-column-header"]'); const lastHeader = (c: HTMLElement) => [...c.querySelectorAll('thead th')].pop()!; // The shape `ObjectGrid` hands the list page: a save path and no row menu. const EDIT_ONLY = { rowActions: true, onRowSave: () => Promise.resolve() }; @@ -344,12 +343,10 @@ describe('data-table select-first — no edit-only column, ever (objectstack#355 it('none at rest and none after a commit: the commit saves itself', () => { const onRowSave = vi.fn(() => Promise.resolve()); const t = renderTable({ extra: { ...EDIT_ONLY, onRowSave } }); - expect(editHeader(t.container)).toBeNull(); expect(lastHeader(t.container)).toHaveTextContent('Site'); fireEvent.click(t.cell(0, 0)); fireEvent.change(t.catcher()!, { target: { value: 'A' } }); fireEvent.keyDown(t.editor()!, { key: 'Enter' }); - expect(editHeader(t.container)).toBeNull(); expect(lastHeader(t.container)).toHaveTextContent('Site'); expect(t.container.querySelector('button[title="Save row"]')).toBeNull(); expect(onRowSave).toHaveBeenCalledTimes(1); @@ -627,3 +624,38 @@ describe('data-table select-first — a read-only cell says so in the grid (obje expect(t.container.querySelector('[aria-readonly]')).toBeNull(); }); }); + +describe('data-table select-first — an injected editor keeps the model\'s keys (objectstack#35687)', () => { + // An editor opens only inside the select-first model (an `editable` table + // with no select-first host is read-only), so a host-injected editor's Tab + // and Ctrl/Cmd+Enter always follow that model. + const renderCellEditor = (ctx: { value: unknown; stage: (v: unknown) => void }) => ( +