Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/36023-rich-text-cell-panel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@object-ui/fields': patch
'@object-ui/plugin-grid': patch
---

feat(grid): a markdown, HTML or rich text cell opens a text box in a panel under the cell

Clause-②: yes (widening)
Metadata-protocol: none

**The list grid edits the rich-content field types in place** (objectstack#36023). On a select-first grid, selecting a `markdown`, `html` or `richtext` cell and pressing Enter, F2, typing or double-clicking opens the record form's own text box over the stored source in a panel under the cell, at least as wide as the column; the cell keeps showing its value and the row keeps its height. Enter in the panel is a new line; on a select-first grid Ctrl/Cmd+Enter saves and keeps the cell selected, Esc discards, and a click outside saves. Backspace or Delete on the selected cell of a select-first grid clears it as for any other editable cell. On a grid without the select-first cell model (an `ObjectGrid` or `object-grid` mounted without `cellSelection`), one click opens the text box over the cell, not in a panel under it: Enter is a new line, Ctrl/Cmd+Enter does nothing, Esc discards, and a click outside keeps the text as a pending change for the grid's save buttons. Before, these cells opened no editor and said "This field can't be edited in a list". The related tab on the record page draws the same grid and behaves the same way.

**Only the grid's cell changes.** The three types stay in `INLINE_EXCLUDED_FIELD_TYPES`, and `hasFieldEditWidget` and `isInlineExcludedFieldType` answer as before, so the record page's field editor, the required-fields dialogs, the kanban and timesheet editors keep them out. `@object-ui/fields` exports `hasInCellPanelEditWidget(type)`, true for the three types, and `FieldEditWidget` draws their editor only when the host asks for the cell face (`inCell`); the editor loads lazily. `html` is edited as text; what the cell then draws goes through the sanitizing HTML renderer, as on every other read surface.
5 changes: 5 additions & 0 deletions content/docs/frontend/plugins/plugin-grid.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ through the host's data source (`dataSource.update`) with no callback to wire.
definition**, not by a column key — a field marked `readonly`, and
computed/binary field types (formula, autonumber, file, …), never open an
editor. There is no `editable` key on `ListColumn`.
- **Rich text edits in a panel** (objectstack#36023): a `markdown`, `html` or
`richtext` cell opens the record form's text box over the stored source in a
panel under the cell, at least as wide as the column, while the cell keeps
showing its value. Enter there is a new line; on a select-first grid
Ctrl/Cmd+Enter saves, Esc discards and a click outside saves.
- **Visual feedback**: editable cells show a hover state, and the input is
focused and selected when editing begins
- **The editor floats over its cell** (objectstack#35688): it opens on a layer
Expand Down
8 changes: 8 additions & 0 deletions ui/packages/fields/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ pick and the in-cell colour face after a swatch.
A host that passes neither gets the form faces unchanged; `ObjectGrid` passes
both.

`inCell` also unlocks the rich-content types (`markdown`, `html`, `richtext`):
they stay in `INLINE_EXCLUDED_FIELD_TYPES` and `hasFieldEditWidget` answers
`false` for them, so every other host keeps them out, while
`hasInCellPanelEditWidget(type)` answers `true` and `FieldEditWidget` draws the
form's rich-text box for them (loaded lazily) when the host asks for the cell
face. The list grid opens it in a panel under the cell, where Enter is a new
line.

### Resolving declared action params

An action param is declared either inline (`name` + `type`) or field-backed
Expand Down
55 changes: 53 additions & 2 deletions ui/packages/fields/src/FieldEditWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ import {
isRetiredFieldType,
reportRetiredFieldType,
} from './field-type-alias.js';
// The rich-content types' one list (the keys `RichTextField` serves); its
// module is already in the eager closure through `getCellRenderer`.
import { RICH_TEXT_FIELD_TYPES } from './widgets/richTextDisplay.js';

/**
* The platform date picker (objectui#12622, objectui#12642), the face the
Expand Down Expand Up @@ -96,10 +99,21 @@ const DateTimePickerEditWidget = React.lazy(() =>
import('./widgets/date-picker/DatePickerField.js').then((m) => ({ default: m.DateTimePickerField })),
);

/** The {@link EDIT_WIDGETS} entries that load lazily and need a `Suspense` boundary. */
/**
* The rich-content editor (`RichTextField`, a text box over the stored
* markdown or HTML source), LAZY through the same `import()` `fieldWidgetMap`
* uses for these three types, for the list grid's cell panel
* ({@link IN_CELL_PANEL_EDIT_WIDGETS}).
*/
const RichTextPanelEditWidget = React.lazy(() =>
import('./widgets/RichTextField.js').then((m) => ({ default: m.RichTextField })),
);

/** The edit widgets that load lazily and need a `Suspense` boundary. */
const LAZY_EDIT_WIDGETS: ReadonlySet<unknown> = new Set([
DatePickerEditWidget,
DateTimePickerEditWidget,
RichTextPanelEditWidget,
]);

/**
Expand Down Expand Up @@ -193,6 +207,29 @@ export const INLINE_EXCLUDED_FIELD_TYPES = new Set<string>([
'notification-topic', 'notification-channel', 'quiet-hours',
]);

/**
* Members of {@link INLINE_EXCLUDED_FIELD_TYPES} that the LIST GRID's cell
* nevertheless edits, in a panel opened under the cell (objectstack#36023):
* the rich-content types, whose panel is the form's own text box over the
* stored source. Enter in it is a new line; the grid saves on Ctrl/Cmd+Enter
* or a click outside and discards on Esc.
*
* Only a host that asks for the cell face (`inCell`) gets them, so the record
* page's field editor, the required-fields dialogs and every other host of
* {@link FieldEditWidget} keep these types out, exactly as before: they ask
* {@link hasFieldEditWidget}, which still answers `false` for them. The
* exclusion set keeps them too, so `isInlineExcludedFieldType` answers as
* before for every host; the grid asks {@link hasInCellPanelEditWidget}.
*
* `html` is safe to edit as text here because what the cell then draws is
* the sanitizing renderer's output (`./widgets/sanitizedHtml.tsx`), as on
* every other read surface.
*/
const IN_CELL_PANEL_EDIT_WIDGETS: Readonly<Record<string, React.ComponentType<FieldWidgetComponentProps<any>>>> =
// Derived from the one list of the keys `RichTextField` serves, so a type
// added to the display table gets its cell panel with no second spelling.
Object.fromEntries(RICH_TEXT_FIELD_TYPES.map((type) => [type, RichTextPanelEditWidget]));

/** Field types whose value is chosen in one discrete gesture (no free typing). */
export const DISCRETE_EDIT_TYPES = new Set<string>([
'boolean', 'toggle', 'select', 'status', 'radio', 'rating',
Expand Down Expand Up @@ -239,6 +276,17 @@ export function hasFieldEditWidget(type: string | undefined): boolean {
return resolveInlineEditType(type) in EDIT_WIDGETS;
}

/**
* True when a field type has no in-place widget but the list grid's cell edits
* it in a panel under the cell (`inCell`, {@link IN_CELL_PANEL_EDIT_WIDGETS}).
* A retired spelling answers `false`, as {@link hasFieldEditWidget} does.
*/
export function hasInCellPanelEditWidget(type: string | undefined): boolean {
if (!type) return false;
if (isRetiredFieldType(type)) return false;
return Object.prototype.hasOwnProperty.call(IN_CELL_PANEL_EDIT_WIDGETS, resolveInlineEditType(type));
}

/**
* True when a field type is deliberately NOT inline-editable (alias-aware:
* `composite` resolves to the excluded `object`, `video` to `file`, …).
Expand Down Expand Up @@ -377,7 +425,10 @@ export function FieldEditWidget(
return null;
}
const resolved = field?.type ? resolveInlineEditType(field.type) : undefined;
const Widget = resolved ? EDIT_WIDGETS[resolved] : undefined;
// The cell panel's widgets answer only the host that asks for the cell face.
const Widget = resolved
? EDIT_WIDGETS[resolved] ?? (props.inCell && hasInCellPanelEditWidget(resolved) ? IN_CELL_PANEL_EDIT_WIDGETS[resolved] : undefined)
: undefined;
if (!Widget) return null;
// `compact` is a declared widget prop (objectui#3221 closed this type), so
// the spread no longer needs an `any` escape hatch to get past it.
Expand Down
46 changes: 45 additions & 1 deletion ui/packages/fields/src/__tests__/inCellFaces-35688.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import { TagsField } from '../widgets/TagsField';
import { ColorField } from '../widgets/ColorField';
import { TimeField } from '../widgets/TimeField';
import { DatePickerField, DateTimePickerField } from '../widgets/date-picker/DatePickerField';
import { FieldEditWidget } from '../FieldEditWidget';
import { FieldEditWidget, hasFieldEditWidget, hasInCellPanelEditWidget, isInlineExcludedFieldType } from '../FieldEditWidget';
// The rich-content panel's widget sits behind `React.lazy` in `FieldEditWidget`;
// imported here so its factory resolves at once (ui/AGENTS.md, flaky tests).
import '../widgets/RichTextField';
import { TextField } from '../widgets/TextField';
import { EmailField } from '../widgets/EmailField';
import { PhoneField } from '../widgets/PhoneField';
Expand Down Expand Up @@ -458,3 +461,44 @@ describe('in-cell record picker (objectstack#35688)', () => {
expect(screen.queryByRole('listbox')).toBeNull();
});
});

describe('in-cell rich-content panel (objectstack#36023)', () => {
it('markdown, html and rich text get the text box only when the cell face is asked for', () => {
for (const type of ['markdown', 'html', 'richtext']) {
expect(hasInCellPanelEditWidget(type), type).toBe(true);
// Every other host keeps them out, exactly as before.
expect(hasFieldEditWidget(type), type).toBe(false);
expect(isInlineExcludedFieldType(type), type).toBe(true);
}
// CONTROL: no other type, excluded or in-place, is a panel text box.
for (const type of ['text', 'textarea', 'address', 'password', 'secret', 'object', 'file', undefined]) {
expect(hasInCellPanelEditWidget(type), String(type)).toBe(false);
}
});

it('draws the stored source in a text box; typing stages it; Enter is left to the text box (a new line)', async () => {
const onChange = vi.fn();
const onGridKey = vi.fn();
render(
<GridEditor onGridKey={onGridKey}>
<FieldEditWidget field={{ name: 'notes', type: 'richtext' } as unknown as Field} value="<p>Hello</p>" onChange={onChange} inCell />
</GridEditor>,
);
const box = (await screen.findByRole('textbox')) as HTMLTextAreaElement;
expect(box.tagName).toBe('TEXTAREA');
expect(box.value).toBe('<p>Hello</p>');
fireEvent.change(box, { target: { value: '<p>Hello</p>\n<p>World</p>' } });
expect(onChange).toHaveBeenLastCalledWith('<p>Hello</p>\n<p>World</p>');
// The widget does not take Enter: it reaches the grid's wrapper with its
// default intact, and the wrapper commits a text box only on Ctrl/Cmd+Enter.
expect(fireEvent.keyDown(box, { key: 'Enter' })).toBe(true);
expect(onGridKey).toHaveBeenCalledWith('Enter');
});

it('CONTROL: without the cell face the same field gets no editor', () => {
const { container } = render(
<FieldEditWidget field={{ name: 'notes', type: 'markdown' } as unknown as Field} value="# Hi" onChange={() => {}} />,
);
expect(container.innerHTML).toBe('');
});
});
6 changes: 5 additions & 1 deletion ui/packages/plugin-grid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,12 @@ the host's data source (`dataSource.update`) with no callback to wire.
- **Per-field read-only**: which cells open is decided by the **field definition**,
not by a column key — a field marked `readonly`, and computed/binary field types
(formula, autonumber, file, …), never open an editor
(`isFieldInlineEditable`, `src/inline-edit-options.ts:82`). There is no
(`isFieldInlineEditable` in `src/inline-edit-options.ts`). There is no
`editable` key on `ListColumn`.
- **Rich text edits in a panel**: a `markdown`, `html` or `richtext` cell opens
the record form's text box in a panel under the cell (Enter is a new line,
Ctrl/Cmd+Enter saves, Escape discards, a click outside saves); the cell keeps
showing its value and the row its height.
- **Visual feedback**: editable cells show a hover state
- **Automatic focus**: the input is focused and selected when editing begins

Expand Down
8 changes: 5 additions & 3 deletions ui/packages/plugin-grid/src/ObjectGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { SchemaRenderer, isPermissionError, useDataScope, useNavigationOverlay,
// what stops a seventh site picking a convention of its own.
import { resolveGridCellRendering } from './cellRendererResolution';
import { isMaskedGridColumn } from './maskedColumn';
import { formatCurrency, formatDate, getBadgeColorClasses, getBadgeHexAppearance, FieldEditWidget, hasFieldEditWidget, DISCRETE_EDIT_TYPES, coerceToSafeValue, MaskedCellRenderer, withKnownObjects, RICH_TEXT_FIELD_TYPES } from '@object-ui/fields';
import { formatCurrency, formatDate, getBadgeColorClasses, getBadgeHexAppearance, FieldEditWidget, hasFieldEditWidget, hasInCellPanelEditWidget, DISCRETE_EDIT_TYPES, coerceToSafeValue, MaskedCellRenderer, withKnownObjects, RICH_TEXT_FIELD_TYPES } from '@object-ui/fields';
import { useLocalization, useDisplayLocale } from '@object-ui/i18n';
// Two resolvers, two vocabularies — the repo spells the distinction into the
// NAMES (objectui#4167). `resolveInlineI18nLabel` is the spec's own
Expand Down Expand Up @@ -803,12 +803,13 @@ function opensReferenceInPlace(fieldDef: { type?: unknown; reference?: unknown }
* is never narrower than its cell and grows to fit this; the editor fills it.
*/
function cellEditorWidthClass(type: string): string {
// objectstack#36023 — a rich-content field's text box, as wide as a textarea's.
if ((RICH_TEXT_FIELD_TYPES as readonly string[]).includes(type)) return 'w-full min-w-80';
switch (type) {
case 'address':
case 'location':
return 'w-full min-w-[22rem]';
case 'textarea':
case 'markdown':
case 'code':
case 'json':
return 'w-full min-w-80';
Expand Down Expand Up @@ -3614,7 +3615,8 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
renderCellEditor: inlineEditable
? (ctx: { column: any; row: any; pendingRow: any; value: any; stage: (v: any) => void; commit: (v?: any) => void }) => {
const fieldDef = (objectSchema as any)?.fields?.[ctx.column?.accessorKey];
if (!fieldDef || !hasFieldEditWidget(fieldDef.type)) return null;
// objectstack#36023 — a rich-content field edits in a panel under the cell.
if (!fieldDef || !(hasFieldEditWidget(fieldDef.type) || hasInCellPanelEditWidget(fieldDef.type))) return null;
// objectstack#35688 — a `select` declared `multiple` draws the multi-select
// check list (`SelectField` hands it to `MultiSelectField`): each check
// stages, and the edit is saved when the user moves on.
Expand Down
Loading
Loading