// sheet/CellActionBar.tsx — the non-modal bar that appears beside a selected cell (W49-T05, R11). // // ⭐⭐ NON-MODAL IS THE RULING, AND IT DICTATES THREE THINGS THIS COMPONENT DOES NOT DO. R11 says a // cell click SELECTS and the bar carries Edit / View data. W56-T23 (owner instruction 16) retired // the Refresh entry because the ribbon already carries one. So it does NOT trap focus, it does NOT // render a backdrop, and it does NOT autofocus anything: the grid keeps the keyboard the whole time, // which is what lets someone arrow to the next cell without dismissing anything. That is the opposite // discipline from `LinkGridModal`, which is modal and traps focus deliberately. // // ⚠ `onMouseDown` PREVENTS DEFAULT ON THE BAR ITSELF. Without it, pressing a button blurs the grid // canvas, glide-data-grid drops its selection, and the bar unmounts before the click lands. The // button then does nothing and it looks like a dead control. // // ⚠ DESIGN CONTRACT. Sentence case; quiet buttons are muted ink with a hover wash; icons are inline // SVG on `currentColor`; motion is 150 ms ease-out on opacity and transform only; no emoji; no em // dash or en dash in any string; z-order rides a `--cg-z-*` token, never a literal. import { useEffect, useState } from "react"; import type { CSSProperties } from "react"; import { fetchWorkspace } from "../customer-grid/apiBridge"; import type { SurfaceScope } from "../customer-grid/apiBridge"; import { cellHasLimits, cellLimitSummary } from "./cellLimits"; import type { CellLimitField } from "./cellLimits"; import type { Cell } from "./types"; export interface CellActionBarProps { /** Viewport rect of the selected cell. The bar sits just above it, clamped to the viewport. */ anchor: { x: number; y: number; width: number; height: number }; /** R17: a formula cell cannot drill, and the reason is named on hover. */ drill: { enabled: boolean; reason: string }; canEdit: boolean; busy?: boolean; cell?: Cell | null; limitFields?: readonly CellLimitField[]; onEdit: () => void; onViewRows: () => void; /** W56-T23 retired the button; kept only so sibling SheetGrid compiles. Drop once that file is free. */ onRefresh?: () => void; } function IconEdit() { return ( ); } function IconRows() { return ( ); } export default function CellActionBar({ anchor, drill, canEdit, busy = false, cell, limitFields, onEdit, onViewRows, }: CellActionBarProps) { const database = cellHasLimits(cell) && typeof cell?.binding?.database === "string" ? cell.binding.database : ""; const [schema, setSchema] = useState<{ database: string; fields: CellLimitField[] } | null>(null); useEffect(() => { if (limitFields || !database) return; let live = true; const scope = database === "customer_data" ? "customer" : database === "product_data" ? "product" : database.startsWith("ut_") ? database as SurfaceScope : null; if (!scope) return; void fetchWorkspace(scope, { fieldsOnly: true, allowCached: true }).then(workspace => { if (live) setSchema({ database, fields: workspace?.fields ?? [] }); }).catch(() => { if (live) setSchema({ database, fields: [] }); }); return () => { live = false; }; }, [database, limitFields]); const limitNote = cellLimitSummary(cell, limitFields ?? (schema?.database === database ? schema.fields : [])); const width = Math.min(520, Math.max(0, window.innerWidth - 16)); // Clamped so a cell at the very top or the right edge still shows its bar on screen. const style: CSSProperties = { left: Math.max(8, Math.min(anchor.x, window.innerWidth - (limitNote ? width : 232) - 8)), top: Math.max(8, anchor.y - (limitNote ? 64 : 40)), ...(limitNote ? { width, flexWrap: "wrap", boxSizing: "border-box" } : {}), }; return (