Skip to content

Commit bbc7e03

Browse files
feat(grid): a list cell's right-click menu copies, pastes and clears that cell (#36790)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8TkiiiqHvFYXaB2vYtLWWEC)_ Fixes #36289 Clause-②: yes (widening) — an optional `cell` member on the context `data-table` hands a host's `renderRowContextMenu`, and five new `table.*` language-pack keys in every locale Metadata-protocol: none ## 维护者速读 - 列表里在格子上点右键,菜单上半段多了这个格子的「复制、粘贴、清空」,后面接着已有的「修改历史」;一条分隔线下面还是原来整行的「打开、在新标签页打开、编辑、删除」,内容和顺序都没动。 - 属于「列表专题」里对照 Attio 定的第 2 条:右键菜单放格子自己的动作,同时保留整行的动作。 - 出错时最多是菜单项该灰没灰、或格子上的提示不对;粘贴和在格子里直接输入走同一套检查和保存(邮箱格粘贴非邮箱文字、清空必填格都会被拒并说明原因),不会存进不合规的值,可以整体撤回。 - 无 ## What changes **The table** (`@object-ui/components`, `data-table`) - `renderRowContextMenu` now also receives `context.cell` whenever it receives `context.column`: `copy`, `paste`, `clear` for that data cell, each absent where the table would refuse it. `copy` is the Ctrl/Cmd+C path (one function now, `copyCellValue`; a masked cell copies nothing, so `copy` is absent there). `paste` reads `navigator.clipboard.readText()` inside the click that chose it and writes the text through `pasteIntoCell`, the selected-cell paste path. `clear` is `clearCell`, the Backspace path. `paste` and `clear` are absent on a cell `readOnlyReasonOf` refuses; `clear` also on a two-state cell and on a cell whose facts carry a `clearRefusal` (required). - `pasteIntoCell` now holds the converted value to the cell editor's own check (`GridCellFacts.validate`: required, length, range, email / URL shape) before it writes, and says on the cell why when the check refuses or the text stands for no value of the column (`table.pasteNotValue`). Before, a paste into an email cell sent any text to be saved, and text a number or lookup cell cannot read was dropped without a word. - A clipboard the browser will not hand over (no API, permission declined) puts `table.pasteUnavailable` on the cell, which names Ctrl/Cmd+V. - A cell item's write waits until the menu has closed and focus is back on the cell (`whenRowContextMenuClosed`); otherwise that focus move dismisses the note the write puts on the cell. **The list** (`@object-ui/plugin-grid`) - `RowContextMenuItems` draws two sections: the cell's **Copy**, **Paste**, **Clear**, then **Change history** (moved up from the row's items), a separator, then the row's items in their existing order (Open, Open in new tab, the row's actions). Unavailable items are drawn disabled. - `ObjectGrid` passes the table's `cell` through, and draws Paste unavailable on a field type pasted text cannot stand for (`pastesFromText` in `objectGridCellFacts.ts`: text, textarea, email, url, phone, number, currency, percent, date, datetime, select, radio). A lookup, a person, a multi-choice and other types: Paste unavailable. - A grid with no row action and no selection still keeps the browser's menu unless the cell can be changed (Paste or Clear available) or has a change history; Copy alone does not take the browser's menu away. **Language packs** — `table.copyCell`, `table.pasteCell`, `table.clearCell`, `table.pasteNotValue`, `table.pasteUnavailable` in all 11 locales (`zh-Hant` regenerated from `zh-Hans` by `gen:zh-hant`); the two notes are mirrored in the table's English defaults. **Docs** — "A cell's own menu items" in `content/docs/frontend/plugins/plugin-grid.mdx` and the plugin-grid README. ## Tests - New `ui/packages/plugin-grid/src/__tests__/cellContextMenu-36289.test.tsx` (12), through the real `ObjectGrid` → `data-table` chain with a data source recording each `update`: the section order (cell items, separator, `row-context-open` below it); a right-click on the selection cell opens the row's section only; Copy writes the cell's text; Paste writes and saves (`update('account', 'r2', { notes })`); Paste of `not an address` into an email cell saves nothing and shows `Please enter a valid email address`; Ctrl+V on the selected cell refuses the same text the same way (CONTROL: a real address saves); a refused clipboard read says so on the cell; Clear saves `null`; Clear disabled on a required field (CONTROL: enabled on an optional one); a read-only field has Copy only; a lookup and a multi-select have Paste disabled and Clear enabled; a grid that is not editable has Copy only. - `data-table-row-context-menu-28434.test.tsx`: the host context now carries `cell` (`{ copy }` on a table the reader cannot edit), plus two cases: an editable cell hands `copy`, `paste`, `clear` and `copy` writes the value; a masked, non-editable cell hands none. - `rowContextMenu-28434.test.tsx` and `phoneCardRowActions-29150.test.tsx` compare the row's section only: a menu opened on a data cell now lists the cell's items first. <details><summary>Runs</summary> ``` # affected packages, under scripts/pm/os-verify-lock.sh, at 3a524f3 # (plugin-grid, i18n, types, components, app-shell defaults-maps-mirror-en-pack) os-verify-lock: VERDICT command-exit 1 Test Files 2 failed | 1312 passed | 1 skipped (1315) Tests 2 failed | 20219 passed | 37 skipped (20258) # the two reds: zh-hant-generated (zh-Hant hand-written instead of generated) and # phoneCardRowActions-29150 (compared the whole menu); both fixed at 2f73214, re-run: os-verify-lock: VERDICT command-exit 0 Test Files 2 passed (2) Tests 15 passed (15) # the touched context-menu and cell-editing pins at 3a524f3 Test Files 6 passed (6) Tests 78 passed (78) # type-check at 2f73214, the four packages joined with && under the lock # (types, i18n, components, plugin-grid: tsc --noEmit && tsc -p tsconfig.test.json each) os-verify-lock: VERDICT command-exit 0 # derived gates at 2f73214: node scripts/pm/dispatch-gates.mjs --commands, each run with its exit code recorded, then --ran Run reconciliation — 73 derived, 72 run, 1 NOT-MEASURED, 0 UNRUN. # 72 exited 0. NOT MEASURED: check:skill-examples, reason: exit 3 PREREQUISITE NOT MET # (it reads packages/client-react's built .d.ts, which this card does not touch and the container had not built); # CI's Lint suites ran it on this head and passed. # CI at 2f73214: every check suite completed with no failure; mergeable_state clean ``` </details> ## Acceptance notes - Agreed with the seat before code: Ctrl/Cmd+V on the selected cell reads the same `pasteIntoCell`, so it now refuses what the editor refuses and says why when the text stands for no value, where it used to save or drop silently. Keyboard bindings are unchanged. - Change history moved from the row's items to the cell's section, as the card's layout asks; the row's own items keep their content and order (the queued row-order card is not touched). - The card's unverified point on pasting into a reference, person or multi-choice field: Paste is drawn unavailable there, as the card proposed. Ctrl+V on a multi-choice cell still matches options by name as before. - An unsaved view draft is unaffected by a paste: a paste writes the record through the same per-cell save as typing, which never reads or writes the view draft. Checked in the browser (frames 8a/8b): with an unsaved draft sort by Company showing its Discard / Save bar, a paste into a contact's Company cell sent only `PATCH /api/v1/data/showcase_contact/RECORD_ID {"company":…}`; the draft bar, the draft sort and the row order were unchanged after it. ## Verification Checked in a browser on the showcase app (`examples/app-showcase`, local dev stack, this branch's head). GitHub takes image uploads from a browser only, so the twelve frames are attached in the project's card thread; what each one shows: | Frame | What it shows | |---|---| | `1-cell-menu` | Right-click on a contact's Company cell (en): Copy, Paste, Clear, Change history, a separator, then Open, Open in new tab, Edit, Delete | | `zh-1-cell-menu`, `zh-2-contact-cell-menu` | The same menu in zh-CN on a project's Name cell and a contact's Company cell: 复制 / 粘贴 / 清空 / 修改历史, separator, 打开 / 在新标签页打开 / 编辑 / 删除 | | `2-required-clear-grey` | Full name (required): Clear disabled, Copy and Paste enabled | | `3a-before-paste`, `3b-pasted-saved` | Company copied from one contact and pasted into another's: the cell shows the new value and the request is `PATCH /api/v1/data/showcase_contact/RECORD_ID {"company":"华宁科技"}` | | `4-email-refused` | Pasting `not an address` into an Email cell: the cell's note says "Please enter a valid email address" and no request is sent | | `5-checkbox-row-only` | Right-click on the selection checkbox: the row's section only (Open, Open in new tab, Edit, Delete) | | `6-lookup-paste-grey` | A project's Account (a required lookup): Paste and Clear disabled, Copy enabled | | `7-formula-readonly` | A project's Remaining budget (a formula): Paste and Clear disabled, Copy enabled | | `8a-draft-sort-before-paste`, `8b-draft-sort-after-paste` | An unsaved draft sort with its Discard / Save bar, before and after a paste: draft and row order unchanged, only the record PATCH sent | Two-minute check: on any list, right-click a text cell. Expect Copy, Paste, Clear (and Change history) above a line and Open, Open in new tab, Edit, Delete below it; on a required field Clear is grey. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (no formatter ran; lint read from CI: `Lint UI` and `Lint · ESLint` success at 2f73214) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (not touched) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbXwSwKtFLjfawUUTVG)_ <!-- signed: repo:objectstack#1 · os-warren · session_01JQwxbXwSwKtFLjfawUUTVG --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9f84e5f commit bbc7e03

23 files changed

Lines changed: 720 additions & 48 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@object-ui/plugin-grid': patch
3+
'@object-ui/components': patch
4+
'@object-ui/types': patch
5+
'@object-ui/i18n': patch
6+
---
7+
8+
feat(grid): a list cell's right-click menu copies, pastes and clears that cell
9+
10+
Clause-②: yes (widening) — an optional `cell` member (`copy`, `paste`, `clear`) on the context `data-table` hands a host's `renderRowContextMenu`; five new `table.*` language-pack keys in every locale `@object-ui/i18n` ships (`copyCell`, `pasteCell`, `clearCell`, `pasteNotValue`, `pasteUnavailable`); nothing is removed or renamed
11+
Metadata-protocol: none
12+
13+
Right-clicking a cell in a list now offers what can be done to that cell, above the row's own items.
14+
15+
- The menu has two sections. Above a line: **Copy**, **Paste**, **Clear** and, where it was already offered, **Change history**. Below it: the row's items as before (Open, Open in new tab, the row's actions). A right-click off a data cell opens the row's section only.
16+
- **Copy** copies the cell's value, as Ctrl/Cmd+C does.
17+
- **Paste** writes the clipboard's text into the cell and saves it, through the same checks as typing into the cell: text that is not an email address in an email cell, a value over a field's length, an empty required field are refused and the cell says why. If the browser will not let the list read the clipboard, the cell says so and names Ctrl/Cmd+V. Paste is offered on text, numbers, dates and single-choice fields (an option by its value or label); on a record reference, a person, a multi-choice and other types it is unavailable.
18+
- **Clear** empties the cell and saves it, as Backspace does; it is unavailable on a required field.
19+
- On a read-only field, a calculated field, a grid that is not editable or a record the reader may not change, Paste and Clear are unavailable and Copy still works.
20+
- A paste into the selected cell with Ctrl/Cmd+V now goes through the same checks: text the cell's editor would refuse is no longer sent to be saved, and text the column cannot read (letters in a number cell, a name in a lookup cell) says why instead of doing nothing.

‎content/docs/frontend/plugins/plugin-grid.mdx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,37 @@ authored `navigation: { mode: 'none' }` or `navigation.preventNavigation: true`
332332
(whatever its mode, objectstack#33549) and for an object whose data API serves
333333
no single-record read (objectstack#33317).
334334

335+
### A cell's own menu items
336+
337+
Right-clicking a data cell opens the row's context menu in two sections
338+
(objectstack#36289). Above a separator, the cell's own items: **Copy**,
339+
**Paste**, **Clear**, then **Change history** (below). Under it, the row's
340+
items, unchanged: Open, Open in new tab and the row's actions. A right-click
341+
off a data cell (the selection cell, the row's "⋮" cell) opens the row's
342+
section only.
343+
344+
- **Copy** writes the cell's value to the clipboard, as Ctrl/Cmd+C on the
345+
selected cell does. A masked cell copies nothing, so it is unavailable there.
346+
- **Paste** reads the clipboard and writes it into the cell as a paste on the
347+
selected cell does: the same conversion, the checks the cell's editor makes
348+
(required, length, range, the email and URL shape) and the same save. Text
349+
the column cannot read, or a value the checks refuse, is not saved and the
350+
cell says why. When the browser will not hand the clipboard over, the cell
351+
says so and names Ctrl/Cmd+V. It is offered on text, number, currency,
352+
percent, email, URL, phone, date and single-choice fields (an option is
353+
matched by value or label), and is unavailable on any other type.
354+
- **Clear** empties the cell and saves it, as Backspace on the selected cell
355+
does. It is unavailable on a required field and on a yes/no field.
356+
- Paste and Clear are unavailable on a cell the reader may not edit: a
357+
read-only or calculated field, a grid that is not editable, a record the
358+
reader may not update.
359+
360+
`data-table` hands these to the host's `renderRowContextMenu` as
361+
`context.cell` (`copy`, `paste`, `clear`, each absent where the table refuses
362+
it), beside `context.column`. A grid that offers no row action and no
363+
selection opens the menu for a cell only when the cell can be changed or has a
364+
change history; otherwise the browser's own menu stays.
365+
335366
### A cell's change history
336367

337368
Right-clicking a cell of a field the object declares adds **Change history**

‎ui/packages/components/src/renderers/complex/__tests__/data-table-row-context-menu-28434.test.tsx‎

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,13 @@ describe('objectstack#28434 · a host renderer decides alone', () => {
129129
// The host's items only — the table's own are not mixed in.
130130
expect(itemIds(menu)).toEqual(['host-item']);
131131
expect(menu).toHaveTextContent('Host item for r2');
132-
// objectstack#36290 — the context also names the data cell's column.
133-
expect(renderRowContextMenu).toHaveBeenCalledWith(expect.objectContaining({ id: 'r2' }), { selected: false, column: 'name' });
132+
// objectstack#36290 — the context also names the data cell's column, and
133+
// objectstack#36289 what the table does with that cell (a table the reader
134+
// cannot edit: Copy only).
135+
expect(renderRowContextMenu).toHaveBeenCalledWith(
136+
expect.objectContaining({ id: 'r2' }),
137+
{ selected: false, column: 'name', cell: { copy: expect.any(Function) } },
138+
);
134139
});
135140

136141
it('objectstack#36290 · names the column of the data cell it opened on, and none off a data cell', async () => {
@@ -143,7 +148,10 @@ describe('objectstack#28434 · a host renderer decides alone', () => {
143148
});
144149
act(() => { rightClick(cellOf('C-r1')); });
145150
await screen.findByTestId('row-context-menu');
146-
expect(renderRowContextMenu).toHaveBeenLastCalledWith(expect.objectContaining({ id: 'r1' }), { selected: false, column: 'code' });
151+
expect(renderRowContextMenu).toHaveBeenLastCalledWith(
152+
expect.objectContaining({ id: 'r1' }),
153+
{ selected: false, column: 'code', cell: { copy: expect.any(Function) } },
154+
);
147155
await userEvent.keyboard('{Escape}');
148156
await waitFor(() => expect(contextMenu()).toBeNull());
149157
// The row's own "⋮" cell is not a data cell: no column.
@@ -171,3 +179,33 @@ describe('objectstack#28434 · a host renderer decides alone', () => {
171179
expect(cell).toHaveFocus();
172180
});
173181
});
182+
183+
describe('objectstack#36289 · what the table does with the data cell a host menu opened on', () => {
184+
const lastCell = (fn: ReturnType<typeof vi.fn>) => (fn.mock.calls.at(-1) as any[])[1].cell;
185+
186+
it('an editable cell offers Copy, Paste and Clear; Copy writes the value as Ctrl/Cmd+C does', async () => {
187+
const writeText = vi.fn(async () => {});
188+
Object.defineProperty(navigator, 'clipboard', { configurable: true, value: { writeText, readText: vi.fn(async () => '') } });
189+
const renderRowContextMenu = vi.fn(() => <DropdownMenuItem data-testid="host-item">Host item</DropdownMenuItem>);
190+
renderTable({ editable: true, renderRowContextMenu });
191+
act(() => { rightClick(cellOf('Open contract')); });
192+
await screen.findByTestId('row-context-menu');
193+
const cell = lastCell(renderRowContextMenu);
194+
expect(Object.keys(cell).sort()).toEqual(['clear', 'copy', 'paste']);
195+
cell.copy();
196+
expect(writeText).toHaveBeenCalledWith('Open contract');
197+
});
198+
199+
it('a masked cell offers no Copy; a cell the table will not edit offers no Paste or Clear', async () => {
200+
const renderRowContextMenu = vi.fn(() => <DropdownMenuItem data-testid="host-item">Host item</DropdownMenuItem>);
201+
renderTable({
202+
editable: true,
203+
columns: [{ header: 'Name', accessorKey: 'name' }, { header: 'Code', accessorKey: 'code', masked: true, editable: false }],
204+
data: ROWS.map((row) => ({ ...row, code: `C-${row.id}` })),
205+
renderRowContextMenu,
206+
});
207+
act(() => { rightClick(cellOf('Open contract').closest('tr')!.querySelector('td[data-cell-column="code"]') as HTMLElement); });
208+
await screen.findByTestId('row-context-menu');
209+
expect(lastCell(renderRowContextMenu)).toEqual({});
210+
});
211+
});

‎ui/packages/components/src/renderers/complex/data-table.tsx‎

Lines changed: 120 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ const TABLE_DEFAULT_TRANSLATIONS: Record<string, string> = {
368368
// objectstack#36023 — why a list cell's typed value was not saved, said under the editor.
369369
'table.cellNotNumber': 'Enter a number.',
370370
'table.cellInvalid': 'This value isn\'t valid.',
371+
// objectstack#36289 — why a cell menu's Paste left the cell as it was.
372+
'table.pasteNotValue': 'The copied text can\'t go in this cell.',
373+
'table.pasteUnavailable': 'The browser didn\'t let the list read the clipboard. Select the cell and press Ctrl+V (⌘V) to paste.',
371374
'validation.email': 'Please enter a valid email address',
372375
'validation.url': 'Please enter a valid URL',
373376
// objectstack#35685 — a list cell's own save state, and the way out of a
@@ -2246,6 +2249,15 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
22462249
// Set when the menu closes because the pointer went elsewhere: focus then
22472250
// stays where that press put it instead of jumping back to the row.
22482251
const rowContextMenuClosedOutsideRef = useRef(false);
2252+
// objectstack#36289 — while the menu is open or closing, what a cell item
2253+
// chose waits here and runs once focus has gone back: a note it puts on the
2254+
// cell would otherwise be dismissed by that very focus move.
2255+
const rowContextMenuShownRef = useRef(false);
2256+
const afterRowContextMenuRef = useRef<Array<() => void>>([]);
2257+
const whenRowContextMenuClosed = (run: () => void) => {
2258+
if (rowContextMenuShownRef.current) afterRowContextMenuRef.current.push(run);
2259+
else run();
2260+
};
22492261
// The built-in row menu's verdicts are asked at open time, so the open
22502262
// decision and the items it opens read one answer (see `rowContextMenuItems`).
22512263
const rowMenuScope = usePredicateScope();
@@ -3998,11 +4010,61 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
39984010
}
39994011
return null;
40004012
});
4013+
/**
4014+
* Pasted text written into a cell: converted as the column reads text, then
4015+
* held to the checks the cell's editor holds a committed value to
4016+
* (`GridCellFacts.validate`), so a paste never saves what typing the same
4017+
* text would refuse (objectstack#36289). Text that stands for no value of
4018+
* the column, or a value the checks refuse, leaves the cell as it is and
4019+
* says why on it.
4020+
*/
40014021
const pasteIntoCell = (rowIndex: number, colIndex: number, text: string) => writeCell(rowIndex, colIndex, (row, col) => {
4002-
const fromText = factsOf(row, col)?.fromText;
4003-
return fromText ? fromText(text) : defaultValueFromText(col, text);
4022+
const facts = factsOf(row, col);
4023+
const value = facts?.fromText ? facts.fromText(text) : defaultValueFromText(col, text);
4024+
const refusal = value === undefined ? t('table.pasteNotValue') : facts?.validate?.(value) || null;
4025+
if (refusal) {
4026+
setCellNotice({ rowIndex, colIndex, text: refusal });
4027+
return undefined;
4028+
}
4029+
return value;
40044030
});
40054031

4032+
/** Where a row and a column are drawn on this page, or `null` when either is not. */
4033+
const cellIndexOf = (rowKey: PendingRowKey, columnKey: string): { rowIndex: number; colIndex: number } | null => {
4034+
const rowIndex = paginatedData.findIndex((r) => pendingRowKeyOf(r) === rowKey);
4035+
const colIndex = columns.findIndex((c) => c.accessorKey === columnKey);
4036+
return rowIndex < 0 || colIndex < 0 ? null : { rowIndex, colIndex };
4037+
};
4038+
4039+
/**
4040+
* The clipboard's text pasted into a cell, as a paste on the selected cell
4041+
* is (objectstack#36289). The browser may refuse to hand the text over (no
4042+
* clipboard API, the reader declined, the page lacks focus); the cell then
4043+
* says so and names the keyboard paste, which needs no permission.
4044+
*/
4045+
const pasteClipboardInto = (row: any, columnKey: string) => {
4046+
const rowKey = pendingRowKeyOf(row);
4047+
const sayUnavailable = () => {
4048+
const at = cellIndexOf(rowKey, columnKey);
4049+
if (at) setCellNotice({ ...at, text: t('table.pasteUnavailable') });
4050+
};
4051+
const clipboard = typeof navigator !== 'undefined' ? navigator.clipboard : undefined;
4052+
if (typeof clipboard?.readText !== 'function') {
4053+
whenRowContextMenuClosed(sayUnavailable);
4054+
return;
4055+
}
4056+
// Asked at once, inside the click that chose Paste (a browser may grant the
4057+
// read only then); written once the menu has closed.
4058+
clipboard.readText().then(
4059+
(text) => whenRowContextMenuClosed(() => {
4060+
// Read where the cell is once the text arrives: the rows may have moved.
4061+
const at = cellIndexOf(rowKey, columnKey);
4062+
if (at && text !== '') pasteIntoCell(at.rowIndex, at.colIndex, text);
4063+
}),
4064+
() => whenRowContextMenuClosed(sayUnavailable),
4065+
);
4066+
};
4067+
40064068
/** Text typed or composed on the selected cell. */
40074069
const typeIntoCell = (rowIndex: number, colIndex: number, text: string) => {
40084070
const row = paginatedData[rowIndex];
@@ -4122,6 +4184,21 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
41224184
// A printable key lands in the catcher, which reads it (`typeIntoCell`).
41234185
};
41244186

4187+
/**
4188+
* A cell's value to the clipboard: Ctrl/Cmd+C on the selected cell, and the
4189+
* cell menu's Copy (objectstack#36289). A MASKED column copies NOTHING
4190+
* (objectui#10583): the producer drew a mask, so no copy hands out what the
4191+
* cell hides.
4192+
*/
4193+
const copyCellValue = (row: any, columnKey: string) => {
4194+
if (columns.find((col) => col.accessorKey === columnKey)?.masked) return;
4195+
const value = row[columnKey];
4196+
const text = value != null ? String(value) : '';
4197+
navigator.clipboard?.writeText(text).catch(() => {
4198+
// Fallback for environments without clipboard API
4199+
});
4200+
};
4201+
41254202
const handleCellKeyDown = (e: React.KeyboardEvent, rowIndex: number, colIndex: number, columnKey: string) => {
41264203
if (selectFirst) {
41274204
if (!isCommandLetter(e, 'c')) {
@@ -4161,18 +4238,11 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
41614238
// detail page's house shape (objectui#8440, option A): no copy at all,
41624239
// ⛔ not the bullets — which is also why `preventDefault()` above stays:
41634240
// measured in Chromium, letting the default run copies a selected mask
4164-
// as `••••••`, the payload that ruling refused. Unmasked cells are
4165-
// untouched below.
4166-
if (columns.find((col) => col.accessorKey === columnKey)?.masked) return;
4241+
// as `••••••`, the payload that ruling refused. `copyCellValue` then
4242+
// copies nothing of a masked cell.
41674243
const globalIdx = (effectivePage - 1) * pageSize + rowIndex;
41684244
const row = sortedData[manualPagination ? rowIndex : globalIdx];
4169-
if (row) {
4170-
const value = row[columnKey];
4171-
const text = value != null ? String(value) : '';
4172-
navigator.clipboard.writeText(text).catch(() => {
4173-
// Fallback for environments without clipboard API
4174-
});
4175-
}
4245+
if (row) copyCellValue(row, columnKey);
41764246
return;
41774247
}
41784248

@@ -4416,6 +4486,36 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
44164486
&& !(autosaves && rowActionsColumnIsEditOnly)
44174487
&& !(selectFirst && !autosaves && rowActionsColumnIsEditOnly && !hasPendingChanges);
44184488

4489+
/**
4490+
* objectstack#36289 — what the table does with the data cell a row context
4491+
* menu opened on, for the host to draw as that cell's items: Copy as
4492+
* Ctrl/Cmd+C does, Paste as a paste on the selected cell does, Clear as
4493+
* Backspace does. Each is left out where the table would refuse it, so a
4494+
* host draws it unavailable rather than offering what does nothing.
4495+
*/
4496+
const cellMenuOf = (
4497+
row: any,
4498+
columnKey: string,
4499+
): { copy?: () => void; paste?: () => void; clear?: () => void } | undefined => {
4500+
const col = columns.find((c) => c.accessorKey === columnKey);
4501+
if (!col) return undefined;
4502+
const rowKey = pendingRowKeyOf(row);
4503+
const writable = readOnlyReasonOf(row, col) === null;
4504+
const clearable = writable && !togglesCell(row, col) && !factsOf(row, col)?.clearRefusal;
4505+
return {
4506+
...(col.masked ? {} : { copy: () => copyCellValue(row, columnKey) }),
4507+
...(writable ? { paste: () => pasteClipboardInto(row, columnKey) } : {}),
4508+
...(clearable
4509+
? {
4510+
clear: () => whenRowContextMenuClosed(() => {
4511+
const at = cellIndexOf(rowKey, columnKey);
4512+
if (at) clearCell(at.rowIndex, at.colIndex);
4513+
}),
4514+
}
4515+
: {}),
4516+
};
4517+
};
4518+
44194519
/**
44204520
* objectstack#28434 — the items ONE row's context menu opens with, or `null`
44214521
* for the browser's own menu.
@@ -4428,7 +4528,8 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
44284528
*/
44294529
const rowContextMenuItems = (row: any, selected: boolean, column?: string): React.ReactNode => {
44304530
if (schema.renderRowContextMenu) {
4431-
const items = schema.renderRowContextMenu(row, column !== undefined ? { selected, column } : { selected });
4531+
const cell = column !== undefined ? cellMenuOf(row, column) : undefined;
4532+
const items = schema.renderRowContextMenu(row, cell ? { selected, column, cell } : { selected });
44324533
return items === false || items === undefined ? null : items;
44334534
}
44344535
if (!rowActions || rowActionsColumnIsEditOnly) return null;
@@ -4494,6 +4595,8 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
44944595
const focusable = fromKeyboard ? target : target.closest<HTMLElement>('[tabindex]');
44954596
rowContextMenuReturnFocusRef.current = focusable && rowEl.contains(focusable) ? focusable : null;
44964597
rowContextMenuClosedOutsideRef.current = false;
4598+
rowContextMenuShownRef.current = true;
4599+
afterRowContextMenuRef.current = [];
44974600
setRowContextMenu({ row, selected, column, x, y });
44984601
};
44994602
// The open menu's items, re-asked each render so they follow the row.
@@ -6077,6 +6180,10 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
60776180
e.preventDefault();
60786181
if (!rowContextMenuClosedOutsideRef.current) rowContextMenuReturnFocusRef.current?.focus();
60796182
rowContextMenuClosedOutsideRef.current = false;
6183+
rowContextMenuShownRef.current = false;
6184+
const after = afterRowContextMenuRef.current;
6185+
afterRowContextMenuRef.current = [];
6186+
for (const run of after) run();
60806187
}}
60816188
>
60826189
{openRowContextMenuItems}

‎ui/packages/i18n/src/locales/ar.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,12 @@ const ar = {
589589
// objectstack#36023 — why a list cell's typed value was not saved, under the editor.
590590
cellNotNumber: "أدخل رقمًا.",
591591
cellInvalid: "هذه القيمة غير صالحة.",
592+
// objectstack#36289 — a list cell's menu, and why its Paste left the cell as it was.
593+
copyCell: "نسخ",
594+
pasteCell: "لصق",
595+
clearCell: "مسح",
596+
pasteNotValue: "لا يمكن وضع النص المنسوخ في هذه الخلية.",
597+
pasteUnavailable: "لم يسمح المتصفح بقراءة الحافظة. حدّد الخلية واضغط Ctrl+V (⌘V) للصق.",
592598
// objectstack#35685 — a list cell's own save state, and the way out of a rule the list cannot complete.
593599
cellSaving: "جارٍ الحفظ…",
594600
cellSaved: "تم الحفظ",

‎ui/packages/i18n/src/locales/de.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,12 @@ const de = {
555555
// objectstack#36023 — why a list cell's typed value was not saved, under the editor.
556556
cellNotNumber: "Geben Sie eine Zahl ein.",
557557
cellInvalid: "Dieser Wert ist ungültig.",
558+
// objectstack#36289 — a list cell's menu, and why its Paste left the cell as it was.
559+
copyCell: "Kopieren",
560+
pasteCell: "Einfügen",
561+
clearCell: "Leeren",
562+
pasteNotValue: "Der kopierte Text passt nicht in diese Zelle.",
563+
pasteUnavailable: "Der Browser hat das Lesen der Zwischenablage nicht erlaubt. Wählen Sie die Zelle aus und drücken Sie Strg+V (⌘V), um einzufügen.",
558564
// objectstack#35685 — a list cell's own save state, and the way out of a rule the list cannot complete.
559565
cellSaving: "Wird gespeichert…",
560566
cellSaved: "Gespeichert",

0 commit comments

Comments
 (0)