From 82378761293f1473dd1f6bf6b771489cfa55c77c Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 04:03:15 +0000 Subject: [PATCH 1/6] =?UTF-8?q?wip(#35688):=20prototype=20=E2=80=94=20the?= =?UTF-8?q?=20cell=20editor=20and=20a=20cut-off=20cell's=20full=20content?= =?UTF-8?q?=20draw=20on=20a=20layer=20over=20the=20cell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01L6bhgVyFBp1oC6H2XfBmrm Co-authored-by: Claude --- .../src/renderers/complex/data-table.tsx | 45 +++++- .../complex/dataTableCellOverlay.tsx | 129 ++++++++++++++++++ ui/packages/plugin-grid/src/ObjectGrid.tsx | 35 +++++ 3 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 ui/packages/components/src/renderers/complex/dataTableCellOverlay.tsx diff --git a/ui/packages/components/src/renderers/complex/data-table.tsx b/ui/packages/components/src/renderers/complex/data-table.tsx index 19b0f7649e4..aa887bc11e5 100644 --- a/ui/packages/components/src/renderers/complex/data-table.tsx +++ b/ui/packages/components/src/renderers/complex/data-table.tsx @@ -19,6 +19,7 @@ import { caretToEnd, defaultTyping, defaultValueFromText, firstEditorControl, is import { useHorizontalOverflow, HOVER_SCROLLBAR_CLASSES } from '../../custom/use-horizontal-overflow'; import { ActiveListRow, listRecordIdOf } from '../../custom/record-list-face'; import { describeIgnoredBind, describeNonArrayData } from './dataTableBindDiagnostic'; +import { CellOverlay, CELL_OVERLAY_HOST_CLASS, isCellContentTruncated } from './dataTableCellOverlay'; import { ComponentRegistry, compareSortValues, csvBlob, evalRowPredicate, formatDate, hasDeclaredPredicate, isActionSwitchedOff, formatDateTime, fromDateTimeInputValue, getSortValue, isEmptyValue, isImpossibleStoredDay, toDateInputValue, toDateTimeInputValue } from '@object-ui/core'; import type { DataTableSchema, TableColumn, TableSortItem, TableColumnType } from '@object-ui/types'; import type { SortDirection } from '@objectstack/spec/shared'; @@ -96,6 +97,23 @@ import { // emit seam (`normalizeTableColumnType`), so an undeclared spelling can no // longer reach this set. Typed as `TableColumnType` so re-adding one is a tsc // error rather than a silent re-opening of the undeclared dialect. +/** + * objectstack#35688 — what a cell's layer undoes so its content wraps instead + * of truncating, and how wide a type's editor starts. + */ +const PREVIEW_UNCLIP_CLASS = '[&_*]:whitespace-normal! [&_*]:overflow-visible! [&_*]:text-clip! [&_.flex]:flex-wrap max-h-64'; +function editorOverlayClass(type: TableColumnType | undefined): string | undefined { + switch (type) { + case 'date': + case 'datetime': + return 'min-w-56'; + case 'text': + return 'max-w-[min(28rem,var(--radix-popper-available-width))]'; + default: + return undefined; + } +} + const NUMERIC_EDIT_TYPES = new Set(['number', 'currency', 'percent']); /** @@ -3537,6 +3555,15 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { : null; const setSelectedCell = (pos: { rowIndex: number; colIndex: number } | null) => setSelectedCellKey(pos ? { rowKey: pendingRowKeyOf(paginatedData[pos.rowIndex]), columnKey: columns[pos.colIndex].accessorKey } : null); + // objectstack#35688 — a selected cell whose content is cut off shows it in + // full on a layer over the cell. Measured after the selection draws. + const [previewKey, setPreviewKey] = useState(null); + const selectedPosKey = selectedPos ? `${selectedPos.rowIndex}:${selectedPos.colIndex}` : null; + useLayoutEffect(() => { + if (!selectedPosKey || editingCell) { setPreviewKey(null); return; } + const display = tableRef.current?.querySelector('[data-selected-cell] [data-slot="cell-display"]'); + setPreviewKey(isCellContentTruncated(display ?? null) ? selectedPosKey : null); + }, [selectedPosKey, editingCell]); const focusSelectionRef = useRef(false); useEffect(() => { if (!focusSelectionRef.current || editingCell) return; @@ -4849,6 +4876,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { const isFrozen = frozenColumns > 0 && colIndex < frozenColumns; // objectstack#35684 — the selected cell of the select-first model. const isSelectedCell = selectFirst && selectedPos?.rowIndex === rowIndex && selectedPos.colIndex === colIndex; + const showsPreview = isSelectedCell && !isEditing && previewKey === `${rowIndex}:${colIndex}`; const frozenOffset = isFrozen ? measuredStickyLefts?.[leadingCellCount + colIndex] ?? columns.slice(0, colIndex).reduce((sum, c, i) => { @@ -4880,6 +4908,10 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { cellError !== undefined && "ring-2 ring-inset ring-destructive", isFrozen && ['sticky z-10 bg-background', STICKY_ROW_TINT], isFrozen && colIndex === frozenColumns - 1 && scrolledX && FROZEN_EDGE_SHADOW, + // objectstack#35688 — the cell under an open layer paints above + // the sticky header and the frozen columns. + (isEditing || showsPreview) && !isFrozen && 'relative', + (isEditing || showsPreview) && CELL_OVERLAY_HOST_CLASS, )} style={{ width: columnWidth, @@ -5036,7 +5068,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { ); })()} {isEditing ? ( - (() => { + {(() => { // Type-aware inline editor. `col.type` is forwarded // from a producer's column inference, folded onto the // DECLARED vocabulary at that producer's emit seam @@ -5250,7 +5282,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { className="h-8 px-2 py-1" /> ); - })() + })()} ) : (
{ // The cell half of the drawn-size read the // auto width is estimated from (objectui#11682). data-auto-width-key={autoWidthKey(col)} + data-slot="cell-display" > {typeof col.cell === 'function' ? col.cell(cellValue, row) : (cellValue != null && typeof cellValue === 'object' ? String(cellValue) : formatCellValue(cellValue) as any)}
)} + {showsPreview && ( + // objectstack#35688 — the whole content of a cut-off cell, in place. + + {typeof col.cell === 'function' + ? col.cell(cellValue, row) + : (cellValue != null && typeof cellValue === 'object' ? String(cellValue) : formatCellValue(cellValue) as any)} + + )} ); })} diff --git a/ui/packages/components/src/renderers/complex/dataTableCellOverlay.tsx b/ui/packages/components/src/renderers/complex/dataTableCellOverlay.tsx new file mode 100644 index 00000000000..01fe2bd9bb7 --- /dev/null +++ b/ui/packages/components/src/renderers/complex/dataTableCellOverlay.tsx @@ -0,0 +1,129 @@ +/** + * 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. + */ + +import * as React from 'react'; +import * as PopoverPrimitive from '@radix-ui/react-popover'; +import { cn } from '../../lib/utils'; +import { caretToEnd, firstEditorControl } from './dataTableCellSelection'; + +/** + * A layer drawn over one grid cell, top-left on the cell's own corner, at least + * as wide as the cell, free to grow wider and taller (objectstack#35688). + * + * Invariants: + * - The table's layout never moves: the layer is `position: fixed` (Radix + * Popper), so neither the row height nor any column width changes. + * - The layer stays in the cell's DOM subtree (no portal). Every `contains` + * read the grid already makes — click-outside, focus, keydown routing — + * keeps seeing the editor as inside its cell. + * - Near the viewport's bottom it flips so its bottom edge sits on the cell's + * bottom edge; near the right edge it shifts left. Its height is capped at + * the space available and scrolls inside. + * - The host cell is raised above the sticky header and frozen columns while + * the layer is open (`CELL_OVERLAY_HOST_CLASS`), because a fixed descendant + * still paints inside its nearest stacking context. + */ +export function CellOverlay({ + children, + className, + kind, + layerRef, + onKeyDown, +}: { + children: React.ReactNode; + className?: string; + /** `preview` = the read-only full-content view of a selected cell; `editor` = the editor. */ + kind: 'preview' | 'editor'; + layerRef?: (node: HTMLDivElement | null) => void; + onKeyDown?: React.KeyboardEventHandler; +}) { + const markerRef = React.useRef(null); + const [cell, setCell] = React.useState(null); + const [cellHeight, setCellHeight] = React.useState(0); + + React.useLayoutEffect(() => { + const td = markerRef.current?.closest('td,[role="gridcell"]') as HTMLElement | null; + setCell(td); + if (td) setCellHeight(td.getBoundingClientRect().height); + }, []); + + // The editor takes the caret once the layer is placed: Radix keeps an + // unplaced layer hidden, and a hidden control refuses focus. + const contentRef = React.useRef(null); + React.useEffect(() => { + if (kind !== 'editor' || !cell) return undefined; + let frame = 0; + let frames = 0; + const place = () => { + const host = contentRef.current; + if (host?.contains(document.activeElement)) return; + const control = host ? firstEditorControl(host) : null; + if (control) { + control.focus({ preventScroll: true }); + caretToEnd(control); + if (host?.contains(document.activeElement)) return; + } + if (++frames < 30) frame = requestAnimationFrame(place); + }; + place(); + return () => cancelAnimationFrame(frame); + }, [kind, cell]); + + const virtualRef = React.useMemo( + () => ({ current: { getBoundingClientRect: () => (cell ?? markerRef.current!).getBoundingClientRect() } }), + [cell], + ); + + return ( + <> +