{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "spreadsheet",
  "type": "registry:ui",
  "title": "Spreadsheet",
  "description": "Spreadsheet is a dense grid of cells that people read, compare and work through one cell at a time.",
  "dependencies": [
    "@radix-ui/react-compose-refs@^1.1.3",
    "@remixicon/react@^4.9.0",
    "class-variance-authority@^0.7.1"
  ],
  "registryDependencies": [
    "https://wideset.co/r/icon-types.json",
    "https://wideset.co/r/styles.json",
    "https://wideset.co/r/utils.json"
  ],
  "files": [
    {
      "path": "src/components/spreadsheet/Spreadsheet.context.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/Spreadsheet.context.tsx",
      "content": "'use client';\n\nimport { createContext, useContext } from 'react';\n\nimport type { ActiveCellStore } from './Spreadsheet.hooks';\nimport type { SpreadsheetSize } from './Spreadsheet.types';\n\nexport type SpreadsheetContextValue = {\n  size: SpreadsheetSize;\n  store: ActiveCellStore;\n};\n\nexport const SpreadsheetContext = createContext<SpreadsheetContextValue | undefined>(undefined);\n\nexport const useSpreadsheetContext = () => {\n  const context = useContext(SpreadsheetContext);\n\n  if (context === undefined) {\n    throw new Error('useSpreadsheetContext must be used within a <Spreadsheet>');\n  }\n\n  return context;\n};\n"
    },
    {
      "path": "src/components/spreadsheet/Spreadsheet.hooks.ts",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/Spreadsheet.hooks.ts",
      "content": "'use client';\n\nimport {\n  type FocusEvent,\n  type KeyboardEvent,\n  type RefObject,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useRef,\n  useSyncExternalStore,\n} from 'react';\n\nimport { useSpreadsheetContext } from './Spreadsheet.context';\nimport {\n  CELL_ATTRIBUTE,\n  CELL_SELECTOR,\n  cellAt,\n  cellFor,\n  columnOf,\n  focusFirstControl,\n  rowsPerPage,\n  tabbables,\n  usesArrowKeys,\n} from './Spreadsheet.logic';\n\ntype ActiveCell = { id: string | null; selected: boolean };\n\n/**\n * Which cell is the grid's one tab stop, and whether the user has selected it yet (the first tab\n * stop is not selected until the user reaches it). A store rather than state: each cell reads its\n * own slice, so moving the active cell re-renders two cells instead of the whole grid.\n */\nexport const createActiveCellStore = () => {\n  let active: ActiveCell = { id: null, selected: false };\n  const listeners = new Set<() => void>();\n\n  return {\n    get: () => active,\n    set: (id: string | null, selected: boolean) => {\n      if (id === active.id && selected === active.selected) return;\n      active = { id, selected };\n      listeners.forEach((listener) => listener());\n    },\n    subscribe: (listener: () => void) => {\n      listeners.add(listener);\n      return () => {\n        listeners.delete(listener);\n      };\n    },\n  };\n};\n\nexport type ActiveCellStore = ReturnType<typeof createActiveCellStore>;\n\nconst findCell = (table: HTMLTableElement, id: string | null) =>\n  id === null ? null : table.querySelector<HTMLElement>(`[${CELL_ATTRIBUTE}=\"${id}\"]`);\n\n/** The roving tabindex and the selected state of one cell part. */\nexport const useSpreadsheetCell = () => {\n  const { store } = useSpreadsheetContext();\n  const id = useId();\n  // 0: another cell is active, 1: this cell is the tab stop, 2: … and it is selected.\n  const state = useSyncExternalStore(\n    store.subscribe,\n    () => {\n      const active = store.get();\n      return active.id !== id ? 0 : active.selected ? 2 : 1;\n    },\n    () => 0,\n  );\n\n  return { [CELL_ATTRIBUTE]: id, tabIndex: state > 0 ? 0 : -1, 'aria-selected': state === 2 };\n};\n\n/**\n * Keeps the grid in step with its rows as they come and go: one cell is always the tab stop (when\n * the active cell's row or cell goes away, the cell now in its place takes over, and takes focus\n * if the removed one had it), the first `stickyColumns` cells of every row stay pinned (each at\n * the width of the pinned cells before it, measured on the first row), and `focus()` scrolls a\n * cell clear of the pinned header and columns.\n */\nexport const useSpreadsheetLayout = (\n  scrollerRef: RefObject<HTMLDivElement | null>,\n  tableRef: RefObject<HTMLTableElement | null>,\n  stickyColumns: number,\n  store: ActiveCellStore,\n  focusWithin: RefObject<boolean>,\n) => {\n  useLayoutEffect(() => {\n    const scroller = scrollerRef.current;\n    const table = tableRef.current;\n    if (!scroller || !table) return;\n\n    // Where the active cell sits, so that the cell taking its place can be found once it is gone.\n    let place: { row: number; column: number } | null = null;\n    const remember = () => {\n      const cell = findCell(table, store.get().id);\n      const row = cell?.parentElement;\n      if (cell && row instanceof HTMLTableRowElement)\n        place = { row: row.rowIndex, column: columnOf(cell as HTMLTableCellElement) };\n    };\n    const successor = () => {\n      const { rows } = table;\n      if (place && rows.length) {\n        const row = rows[Math.min(place.row, rows.length - 1)];\n        const cell = cellAt(row, place.column) ?? row.cells[row.cells.length - 1];\n        if (cell?.hasAttribute(CELL_ATTRIBUTE)) return cell;\n      }\n      return table.querySelector<HTMLElement>(CELL_SELECTOR);\n    };\n\n    const sync = () => {\n      const active = store.get();\n      if (!findCell(table, active.id)) {\n        const next = successor();\n        const { activeElement, body } = table.ownerDocument;\n        // The removed cell (or a control in it) had focus, which the browser dropped on the body.\n        const lostFocus = focusWithin.current && (!activeElement || activeElement === body);\n        store.set(next?.getAttribute(CELL_ATTRIBUTE) ?? null, active.selected);\n        if (lostFocus) next?.focus();\n      }\n\n      // Where each pinned column starts. Every cell over the leading columns says how far apart\n      // the column edges it spans are; edges follow from the first one (0) until every pinned\n      // column's start is known, rows read only as far as needed. An edge no cell pins down is\n      // spread evenly between the known ones around it.\n      const edges: (number | undefined)[] = [0];\n      // One measured cell per distinct span: rows repeat the same few, so a long grid costs a\n      // walk over its leading cells, not a measurement or a propagation per row.\n      const spans = new Map<string, { start: number; end: number; width: number }>();\n      const measured: HTMLTableCellElement[] = [];\n      const known = () => {\n        for (let column = 1; column <= stickyColumns; column++)\n          if (edges[column] === undefined) return false;\n        return true;\n      };\n      for (const row of Array.from(table.rows)) {\n        if (known()) break;\n        let column = 0;\n        let added = false;\n        for (const cell of Array.from(row.cells)) {\n          if (column >= stickyColumns) break;\n          const key = `${column}:${cell.colSpan}`;\n          if (!spans.has(key)) {\n            spans.set(key, {\n              start: column,\n              end: column + cell.colSpan,\n              width: cell.getBoundingClientRect().width,\n            });\n            measured.push(cell);\n            added = true;\n          }\n          column += cell.colSpan;\n        }\n        for (let changed = added; changed;) {\n          changed = false;\n          for (const { start, end, width } of spans.values()) {\n            const [from, to] = [edges[start], edges[end]];\n            if (from !== undefined && to === undefined) edges[end] = from + width;\n            else if (to !== undefined && from === undefined) edges[start] = to - width;\n            else continue;\n            changed = true;\n          }\n        }\n      }\n      for (let column = 1; column <= stickyColumns; column++) {\n        if (edges[column] !== undefined) continue;\n        const before = column - 1;\n        let after = column + 1;\n        while (after < edges.length && edges[after] === undefined) after++;\n        const [from, to] = [edges[before] ?? 0, edges[after]];\n        edges[column] = to === undefined ? from : from + (to - from) / (after - before);\n      }\n      const offset = (column: number) => edges[column] ?? 0;\n\n      for (const row of Array.from(table.rows)) {\n        let column = 0;\n        for (const cell of Array.from(row.cells)) {\n          if (column < stickyColumns) {\n            cell.setAttribute('data-sticky', '');\n            cell.style.left = `${offset(column)}px`;\n          } else if (cell.hasAttribute('data-sticky')) {\n            cell.removeAttribute('data-sticky');\n            cell.style.left = '';\n          }\n          column += cell.colSpan;\n        }\n      }\n      // A pinned column can change width without the table changing size (a class on its header).\n      measured.forEach((cell) => resizeObserver.observe(cell));\n\n      scroller.style.scrollPaddingTop = `${table.tHead?.offsetHeight ?? 0}px`;\n      scroller.style.scrollPaddingLeft = `${offset(stickyColumns)}px`;\n      remember();\n    };\n\n    const resizeObserver = new ResizeObserver(() => sync());\n    resizeObserver.observe(table);\n    sync();\n    const unsubscribe = store.subscribe(remember);\n    // Rows and cells added or removed; what changes inside a cell does not move the grid.\n    const mutationObserver = new MutationObserver((records) => {\n      if (\n        records.some(\n          ({ target }) =>\n            target === table || target.parentNode === table || target.nodeName === 'TR',\n        )\n      )\n        sync();\n    });\n    mutationObserver.observe(table, { childList: true, subtree: true });\n\n    return () => {\n      unsubscribe();\n      resizeObserver.disconnect();\n      mutationObserver.disconnect();\n    };\n  }, [scrollerRef, tableRef, stickyColumns, store, focusWithin]);\n};\n\n/**\n * Keyboard and focus for the grid (the APG grid pattern). Arrows, Home and End, Ctrl/Cmd+Home and\n * End, Page Up and Page Down move the active cell, which takes focus. Enter or F2 moves focus to\n * the first control in the cell, Tab between the cell's controls; Escape or F2 brings it back.\n * The grid is one tab stop: past the cell's controls Tab leaves it whatever the other cells hold,\n * and tabbing back returns to the cell the user left.\n */\nexport const useSpreadsheetKeyboard = (\n  scrollerRef: RefObject<HTMLDivElement | null>,\n  store: ActiveCellStore,\n) => {\n  // Whether the focus now arriving comes from a Tab press. Read on the document, which hears the\n  // key before the browser moves focus.\n  const tabbing = useRef(false);\n  // True while the grid hands focus to its first or last control, so that the browser's own Tab\n  // continues from there out of the grid.\n  const leaving = useRef(false);\n  // Whether focus is in the grid (portals included), for the layout to hand focus on when the\n  // focused cell is removed.\n  const focusWithin = useRef(false);\n  const blurTimer = useRef<ReturnType<typeof setTimeout>>(undefined);\n\n  useEffect(() => {\n    const onKey = (event: globalThis.KeyboardEvent) => {\n      tabbing.current = event.key === 'Tab';\n    };\n    const onPointer = () => {\n      tabbing.current = false;\n    };\n    document.addEventListener('keydown', onKey, true);\n    document.addEventListener('pointerdown', onPointer, true);\n    return () => {\n      document.removeEventListener('keydown', onKey, true);\n      document.removeEventListener('pointerdown', onPointer, true);\n      clearTimeout(blurTimer.current);\n    };\n  }, []);\n\n  const onBlur = (event: FocusEvent<HTMLTableElement>) => {\n    const target = event.target as Node;\n    clearTimeout(blurTimer.current);\n    if (event.relatedTarget) {\n      // Focus moves on; if it stays in the grid, onFocus sets the flag again.\n      focusWithin.current = false;\n      return;\n    }\n    // Focus that goes with its element (the row was removed) is still the grid's to hand on;\n    // focus lost to nothing (a click on the page, another window) leaves the element in place.\n    blurTimer.current = setTimeout(() => {\n      if (target.isConnected) focusWithin.current = false;\n    });\n  };\n\n  const onFocus = (event: FocusEvent<HTMLTableElement>) => {\n    focusWithin.current = true;\n    const table = event.currentTarget;\n    const target = event.target as HTMLElement;\n    // Focus from a portal (an open menu) reaches the table through React; it is not in a cell.\n    const cell = table.contains(target) ? target.closest<HTMLElement>(CELL_SELECTOR) : null;\n    if (leaving.current || !cell) return;\n\n    if (tabbing.current && !table.contains(event.relatedTarget as Node | null)) {\n      const active = findCell(table, store.get().id);\n      if (active && !active.contains(target)) {\n        active.focus();\n        return;\n      }\n    }\n    store.set(cell.getAttribute(CELL_ATTRIBUTE), true);\n  };\n\n  const onKeyDown = (event: KeyboardEvent<HTMLTableElement>) => {\n    const table = event.currentTarget;\n    const target = event.target as HTMLElement;\n    if (event.defaultPrevented || !table.contains(target)) return;\n    const cell = target.closest<HTMLTableCellElement>(CELL_SELECTOR);\n    if (!cell) return;\n\n    if (event.key === 'Tab') {\n      // From a control, Tab and Shift+Tab first move between the controls of the same cell,\n      // skipping those that do not take focus (hidden ones).\n      if (target !== cell) {\n        const controls = tabbables(cell);\n        const index = controls.indexOf(target);\n        const after = event.shiftKey\n          ? controls.slice(0, Math.max(index, 0)).reverse()\n          : controls.slice(index + 1);\n        if (index !== -1) {\n          for (const control of after) {\n            control.focus();\n            if (table.ownerDocument.activeElement === control) {\n              event.preventDefault();\n              return;\n            }\n          }\n        }\n      }\n      // Hand focus to the grid's last (first) control that takes it, skipping hidden ones, so\n      // the browser's Tab continues from there out of the grid.\n      const stops = tabbables(table);\n      if (!event.shiftKey) stops.reverse();\n      leaving.current = true;\n      for (const stop of stops) {\n        if (stop === target) break;\n        stop.focus({ preventScroll: true });\n        if (table.ownerDocument.activeElement === stop) break;\n      }\n      leaving.current = false;\n      return;\n    }\n\n    if (target !== cell) {\n      // Focus is on a control inside the cell.\n      if (event.key === 'Escape' || event.key === 'F2') {\n        event.preventDefault();\n        cell.focus();\n        return;\n      }\n      if (usesArrowKeys(target)) return;\n    } else if (event.key === 'Enter' || event.key === 'F2') {\n      if (focusFirstControl(cell)) event.preventDefault();\n      return;\n    } else if (event.key === ' ') {\n      // Space would scroll the grid.\n      event.preventDefault();\n      return;\n    }\n\n    // Alt with an arrow is the browser's history shortcut on some systems.\n    if (event.altKey) return;\n    const next = cellFor(table, cell, event, rowsPerPage(scrollerRef.current, table, cell));\n    if (!next) return;\n    event.preventDefault();\n    next.focus();\n  };\n\n  return { focusWithin, onBlur, onFocus, onKeyDown };\n};\n"
    },
    {
      "path": "src/components/spreadsheet/Spreadsheet.logic.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/Spreadsheet.logic.tsx",
      "content": "'use client';\n\nimport { Children, type ReactNode } from 'react';\n\nimport type { SpreadsheetAlign } from './Spreadsheet.types';\nimport { spreadsheetCellContentVariants } from './Spreadsheet.variants';\n\n/** Every cell part marks its element with this attribute; its value is the cell's id. */\nexport const CELL_ATTRIBUTE = 'data-spreadsheet-cell';\nexport const CELL_SELECTOR = `[${CELL_ATTRIBUTE}]`;\n\n/** What a click or `focus()` can reach: the cells, and the links and controls inside them. */\nconst FOCUSABLE =\n  'a[href], button:not(:disabled), input:not(:disabled):not([type=\"hidden\"]), select:not(:disabled), textarea:not(:disabled), [contenteditable=\"true\"], [tabindex]';\n\n/**\n * Controls that do not use the arrow keys themselves: with focus on one, the arrows still move\n * through the grid. Text fields, selects and any other widget keep their keys.\n */\nconst ARROW_FREE =\n  'a[href], button, input[type=\"checkbox\"], [role=\"button\"], [role=\"checkbox\"], [role=\"link\"], [role=\"switch\"]';\n\n/** What `root` holds that can take focus, in document order (some engines group a selector list). */\nconst focusables = (root: HTMLElement) =>\n  Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE)).sort((a, b) =>\n    a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1,\n  );\n\n/**\n * Focuses the first control in `cell` that takes focus (a hidden one ignores `focus()`), and\n * returns it, or `null` when none does.\n */\nexport const focusFirstControl = (cell: HTMLElement) => {\n  for (const control of focusables(cell)) {\n    control.focus();\n    if (cell.ownerDocument.activeElement === control) return control;\n  }\n  return null;\n};\n\n/** What Tab would stop on inside `root`, in document order. */\nexport const tabbables = (root: HTMLElement) => focusables(root).filter((el) => el.tabIndex >= 0);\n\nexport const usesArrowKeys = (element: HTMLElement) => !element.matches(ARROW_FREE);\n\n/** The column a cell starts in, counting the spans before it. */\nexport const columnOf = (cell: HTMLTableCellElement) => {\n  let column = 0;\n  for (let prev = cell.previousElementSibling; prev; prev = prev.previousElementSibling)\n    column += (prev as HTMLTableCellElement).colSpan;\n  return column;\n};\n\n/** The cell of a row that covers a column, or `null` past the row's end. */\nexport const cellAt = (row: HTMLTableRowElement, column: number) => {\n  let end = 0;\n  for (const cell of Array.from(row.cells)) {\n    end += cell.colSpan;\n    if (column < end) return cell;\n  }\n  return null;\n};\n\ntype NavigationKey = Pick<KeyboardEvent, 'key' | 'ctrlKey' | 'metaKey'>;\n\n/**\n * The cell a navigation key moves to from `cell`, or `null` for any other key. Arrows move one\n * cell and stop at the edges; Home and End go to the ends of the row, and with Ctrl or Cmd to the\n * first and last cell of the grid; Page Up and Page Down move by `pageRows`. The header rows are\n * rows like any other. Row spans are not followed.\n */\nexport const cellFor = (\n  table: HTMLTableElement,\n  cell: HTMLTableCellElement,\n  { key, ctrlKey, metaKey }: NavigationKey,\n  pageRows: number,\n): HTMLTableCellElement | null => {\n  const { rows } = table;\n  const row = cell.parentElement as HTMLTableRowElement;\n  const column = columnOf(cell);\n  const inRow = (index: number) => {\n    const target = rows[Math.min(Math.max(index, 0), rows.length - 1)];\n    return cellAt(target, column) ?? target.cells[target.cells.length - 1] ?? null;\n  };\n  const wholeGrid = ctrlKey || metaKey;\n\n  switch (key) {\n    case 'ArrowLeft':\n      return column > 0 ? cellAt(row, column - 1) : null;\n    case 'ArrowRight':\n      return cellAt(row, column + cell.colSpan);\n    case 'ArrowUp':\n      return inRow(row.rowIndex - 1);\n    case 'ArrowDown':\n      return inRow(row.rowIndex + 1);\n    case 'PageUp':\n      return inRow(row.rowIndex - pageRows);\n    case 'PageDown':\n      return inRow(row.rowIndex + pageRows);\n    case 'Home':\n      return (wholeGrid ? rows[0] : row).cells[0] ?? null;\n    case 'End': {\n      const target = wholeGrid ? rows[rows.length - 1] : row;\n      return target.cells[target.cells.length - 1] ?? null;\n    }\n    default:\n      return null;\n  }\n};\n\n/** How many rows fit under the sticky header: the step of Page Up and Page Down. */\nexport const rowsPerPage = (\n  scroller: HTMLElement | null,\n  table: HTMLTableElement,\n  cell: HTMLElement,\n) => {\n  const rows = Math.floor(\n    ((scroller?.clientHeight ?? 0) - (table.tHead?.offsetHeight ?? 0)) / cell.offsetHeight,\n  );\n  return Number.isFinite(rows) && rows > 0 ? rows : 1;\n};\n\nconst isText = (node: ReactNode) => typeof node === 'string' || typeof node === 'number';\n\n/**\n * A cell's content, and the title that shows its full text. Plain text stays a text node, so the\n * cell truncates it itself, and becomes the title. Anything else is laid out in one centred row,\n * 4px apart, as Figma's cell is, with each run of text in a span that can truncate: `<Avatar />\n * Adam Smith` keeps the avatar and shortens the name.\n */\nexport const cellContent = (children: ReactNode, align: SpreadsheetAlign) => {\n  const nodes = Children.toArray(children);\n  if (nodes.every(isText)) return { content: children, title: nodes.join('') || undefined };\n\n  const parts: ReactNode[] = [];\n  let text: ReactNode[] = [];\n  const endText = () => {\n    if (!text.length) return;\n    parts.push(\n      <span key={`text-${parts.length}`} className=\"truncate\">\n        {text.join('')}\n      </span>,\n    );\n    text = [];\n  };\n  for (const node of nodes) {\n    if (isText(node)) text.push(node);\n    else {\n      endText();\n      parts.push(node);\n    }\n  }\n  endText();\n\n  return {\n    content: <div className={spreadsheetCellContentVariants({ align })}>{parts}</div>,\n    title: undefined,\n  };\n};\n"
    },
    {
      "path": "src/components/spreadsheet/Spreadsheet.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/Spreadsheet.tsx",
      "content": "'use client';\n\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport * as React from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport { SpreadsheetContext } from './Spreadsheet.context';\nimport {\n  createActiveCellStore,\n  useSpreadsheetKeyboard,\n  useSpreadsheetLayout,\n} from './Spreadsheet.hooks';\nimport type { SpreadsheetProps, SpreadsheetWithSubComponents } from './Spreadsheet.types';\nimport { SPREADSHEET_CLASS, SPREADSHEET_TABLE_CLASS } from './Spreadsheet.variants';\nimport { SpreadsheetBody } from './SpreadsheetBody';\nimport { SpreadsheetCell } from './SpreadsheetCell';\nimport { SpreadsheetColumnHeader } from './SpreadsheetColumnHeader';\nimport { SpreadsheetColumnHeaderIcon } from './SpreadsheetColumnHeaderIcon';\nimport { SpreadsheetColumnHeaderTrigger } from './SpreadsheetColumnHeaderTrigger';\nimport { SpreadsheetHead } from './SpreadsheetHead';\nimport { SpreadsheetRow } from './SpreadsheetRow';\nimport { SpreadsheetRowHeader } from './SpreadsheetRowHeader';\n\nexport const Spreadsheet = React.forwardRef<HTMLDivElement, SpreadsheetProps>(\n  (\n    {\n      size = 'sm',\n      stickyColumns = 1,\n      className,\n      children,\n      'aria-label': ariaLabel,\n      'aria-labelledby': ariaLabelledBy,\n      'aria-describedby': ariaDescribedBy,\n      ...props\n    },\n    ref,\n  ) => {\n    const [store] = React.useState(createActiveCellStore);\n    const scrollerRef = React.useRef<HTMLDivElement>(null);\n    const tableRef = React.useRef<HTMLTableElement>(null);\n    const composedRef = useComposedRefs(ref, scrollerRef);\n    const context = React.useMemo(() => ({ size: size ?? 'sm', store }), [size, store]);\n    const { focusWithin, onBlur, onFocus, onKeyDown } = useSpreadsheetKeyboard(scrollerRef, store);\n\n    useSpreadsheetLayout(scrollerRef, tableRef, stickyColumns, store, focusWithin);\n\n    return (\n      <SpreadsheetContext.Provider value={context}>\n        <div\n          ref={composedRef}\n          data-slot=\"spreadsheet\"\n          {...props}\n          className={cn(SPREADSHEET_CLASS, className)}\n        >\n          <table\n            ref={tableRef}\n            role=\"grid\"\n            data-slot=\"spreadsheet-grid\"\n            aria-label={ariaLabel}\n            aria-labelledby={ariaLabelledBy}\n            aria-describedby={ariaDescribedBy}\n            className={SPREADSHEET_TABLE_CLASS}\n            onBlur={onBlur}\n            onFocus={onFocus}\n            onKeyDown={onKeyDown}\n          >\n            {children}\n          </table>\n        </div>\n      </SpreadsheetContext.Provider>\n    );\n  },\n) as SpreadsheetWithSubComponents;\n\nSpreadsheet.displayName = 'Spreadsheet';\n\nSpreadsheet.Head = SpreadsheetHead;\nSpreadsheet.Body = SpreadsheetBody;\nSpreadsheet.Row = SpreadsheetRow;\nSpreadsheet.ColumnHeader = SpreadsheetColumnHeader;\nSpreadsheet.ColumnHeaderIcon = SpreadsheetColumnHeaderIcon;\nSpreadsheet.ColumnHeaderTrigger = SpreadsheetColumnHeaderTrigger;\nSpreadsheet.RowHeader = SpreadsheetRowHeader;\nSpreadsheet.Cell = SpreadsheetCell;\n"
    },
    {
      "path": "src/components/spreadsheet/Spreadsheet.types.ts",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/Spreadsheet.types.ts",
      "content": "import type { RemixiconComponentType } from '@remixicon/react';\nimport type { VariantProps } from 'class-variance-authority';\nimport type {\n  ButtonHTMLAttributes,\n  ForwardRefExoticComponent,\n  HTMLAttributes,\n  RefAttributes,\n  TdHTMLAttributes,\n  ThHTMLAttributes,\n} from 'react';\n\nimport type { RemixiconProps } from '@/lib/wideset/icon.types';\nimport type { spreadsheetCellVariants } from './Spreadsheet.variants';\nimport type { SpreadsheetBody } from './SpreadsheetBody';\nimport type { SpreadsheetCell } from './SpreadsheetCell';\nimport type { SpreadsheetColumnHeader } from './SpreadsheetColumnHeader';\nimport type { SpreadsheetColumnHeaderIcon } from './SpreadsheetColumnHeaderIcon';\nimport type { SpreadsheetColumnHeaderTrigger } from './SpreadsheetColumnHeaderTrigger';\nimport type { SpreadsheetHead } from './SpreadsheetHead';\nimport type { SpreadsheetRow } from './SpreadsheetRow';\nimport type { SpreadsheetRowHeader } from './SpreadsheetRowHeader';\n\nexport type SpreadsheetSize = NonNullable<VariantProps<typeof spreadsheetCellVariants>['size']>;\n\n/** Horizontal alignment of a cell's content. */\nexport type SpreadsheetAlign = NonNullable<VariantProps<typeof spreadsheetCellVariants>['align']>;\n\n/**\n * A dense grid of cells the user moves through one cell at a time, as in a spreadsheet.\n *\n * Attributes and `ref` go to the scroll container (size it with `className`); `aria-label`,\n * `aria-labelledby` and `aria-describedby` name the grid itself, the inner `<table role=\"grid\">`.\n */\nexport type SpreadsheetProps = HTMLAttributes<HTMLDivElement> &\n  Pick<VariantProps<typeof spreadsheetCellVariants>, 'size'> & {\n    /**\n     * How many leading columns stay in place while the grid scrolls sideways. `1` pins the row\n     * header column; raise it to keep a name column in view too, `0` pins none. The header row\n     * always stays in place while the grid scrolls down.\n     * @default 1\n     */\n    stickyColumns?: number;\n  };\n\n/** The head of the grid: the column header row, and any row you add under it. */\nexport type SpreadsheetHeadProps = HTMLAttributes<HTMLTableSectionElement>;\n\n/** The body of the grid: one `Spreadsheet.Row` per record. */\nexport type SpreadsheetBodyProps = HTMLAttributes<HTMLTableSectionElement>;\n\n/** A row of cells. */\nexport type SpreadsheetRowProps = HTMLAttributes<HTMLTableRowElement>;\n\n/** A column header cell (`<th scope=\"col\">`): type icon, label and column menu trigger. */\nexport type SpreadsheetColumnHeaderProps = ThHTMLAttributes<HTMLTableCellElement> & {\n  /**\n   * Horizontal alignment of the header content.\n   * @default 'left'\n   */\n  align?: SpreadsheetAlign;\n  /**\n   * The direction the grid is sorted by this column; sets `aria-sort`. `null` marks a column\n   * that can be sorted but is not; leave it out on columns that cannot be sorted. The grid\n   * does not sort: change the order of your rows.\n   */\n  sortDirection?: 'asc' | 'desc' | null;\n};\n\n/** The type icon before a column header's label. */\nexport type SpreadsheetColumnHeaderIconProps = RemixiconProps & {\n  /** Icon component from `@remixicon/react` that names the column's data type. */\n  icon: RemixiconComponentType;\n};\n\n/**\n * The chevron after a column header's label: a button that opens the column's menu. Wrap it in\n * `DropdownMenu.Trigger asChild`.\n */\nexport type SpreadsheetColumnHeaderTriggerProps = ButtonHTMLAttributes<HTMLButtonElement> & {\n  /** Names the button for screen readers, e.g. \"Customers options\". */\n  'aria-label': string;\n};\n\n/** A row header cell (`<th scope=\"row\">`), the row's number. */\nexport type SpreadsheetRowHeaderProps = ThHTMLAttributes<HTMLTableCellElement> & {\n  /**\n   * Horizontal alignment of the content.\n   * @default 'center'\n   */\n  align?: SpreadsheetAlign;\n};\n\n/**\n * A data cell. Its content is composition: text, or a library component (`Tag`, `StatusBadge`,\n * `Checkbox`, `Avatar` and a name …) sized for the grid. Text and mixed content stay on one line\n * and end in an ellipsis when the column is narrower.\n */\nexport type SpreadsheetCellProps = TdHTMLAttributes<HTMLTableCellElement> & {\n  /**\n   * Horizontal alignment of the content. Right-align numbers and amounts.\n   * @default 'left'\n   */\n  align?: SpreadsheetAlign;\n};\n\nexport type SpreadsheetWithSubComponents = ForwardRefExoticComponent<\n  SpreadsheetProps & RefAttributes<HTMLDivElement>\n> & {\n  Body: typeof SpreadsheetBody;\n  Cell: typeof SpreadsheetCell;\n  ColumnHeader: typeof SpreadsheetColumnHeader;\n  ColumnHeaderIcon: typeof SpreadsheetColumnHeaderIcon;\n  ColumnHeaderTrigger: typeof SpreadsheetColumnHeaderTrigger;\n  Head: typeof SpreadsheetHead;\n  Row: typeof SpreadsheetRow;\n  RowHeader: typeof SpreadsheetRowHeader;\n};\n"
    },
    {
      "path": "src/components/spreadsheet/Spreadsheet.variants.ts",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/Spreadsheet.variants.ts",
      "content": "import { cva } from 'class-variance-authority';\nimport { cn } from '@/lib/wideset/utils';\n\n/**\n * The scroll container. It takes the width it is given (`w-full`: a scroll container has no\n * width of its own to shrink to, so in a centring flex parent it would collapse). Its background\n * is the grid's surface: rows inherit it, and frozen cells repaint it so nothing shows through\n * them while the grid scrolls. `isolate` keeps the sticky layers' z-index inside the grid.\n */\nexport const SPREADSHEET_CLASS = 'bg-ws-static-container isolate w-full ws-scrollbar overflow-auto';\n\n/**\n * `table-fixed` + `w-full`: columns keep the widths set on their column headers, a column\n * without one takes the rest, and the table grows past the container (and scrolls) when the\n * widths add up to more.\n */\nexport const SPREADSHEET_TABLE_CLASS =\n  'w-full table-fixed border-separate border-spacing-0 bg-inherit tabular-nums';\n\nconst CLEAR_TINT = cn(\n  '[--spreadsheet-tint:var(--ws-dynamic-fill-secondary-alpha-default)]',\n  'hover:[--spreadsheet-tint:var(--ws-dynamic-fill-secondary-alpha-hover)]',\n  'active:[--spreadsheet-tint:var(--ws-dynamic-fill-secondary-alpha-pressed)]',\n);\n\n/* Figma: Spreadsheet Cell (10590:65934). Every type shares one frame: Size=Small is 32px high\n   with 8px sides, Size=Medium 40px with 12px, Body/Small text, a 1px Static/Stroke/Subtle line\n   on the right and bottom. The fill is a translucent tint per State, held in\n   `--spreadsheet-tint` so frozen cells can lay it over an opaque surface (an image layer)\n   while the rest paint it as their background colour. */\nexport const spreadsheetCellVariants = cva(\n  cn(\n    'typography-body-sm text-ws-static-base truncate align-middle',\n    // Grid lines: every cell draws its right and bottom edge, the first cell of a row its\n    // left edge and the first head row its top edge, so every cell is boxed.\n    'border-ws-static-subtle border-r border-b first:border-l [thead>tr:first-child>&]:border-t',\n    'bg-(--spreadsheet-tint)',\n    // Set by Spreadsheet on the cells of its pinned columns, with their `left` offset.\n    'data-sticky:z-ws-mask data-sticky:sticky data-sticky:bg-inherit data-sticky:bg-[linear-gradient(var(--spreadsheet-tint),var(--spreadsheet-tint))]',\n    // Selected=True: the active cell, in every state.\n    'aria-selected:[--spreadsheet-tint:var(--ws-dynamic-fill-primary-alpha-strong-default)]',\n    'aria-selected:hover:[--spreadsheet-tint:var(--ws-dynamic-fill-primary-alpha-strong-hover)]',\n    'aria-selected:active:[--spreadsheet-tint:var(--ws-dynamic-fill-primary-alpha-strong-pressed)]',\n    // Keyboard focus adds an inset ring to the selected tint (Figma draws no focus state).\n    'outline-ws-dynamic-primary-strong-default focus-visible:outline-2 focus-visible:-outline-offset-2',\n  ),\n  {\n    variants: {\n      size: {\n        sm: 'h-ws-14 px-ws-5',\n        md: 'h-ws-16 px-ws-7',\n      },\n      /* Column headers sit on a 4% tint (Clients screen 13501:3173 sets the header row to\n         Static/Fill/Alpha/Subtle; Tertiary/Alpha/Strong is the same value in light and dark),\n         so their hover and pressed steps start from it. Every other cell is clear at rest; the\n         row header (the row number) is a Text cell in Static/Text/Subtle. */\n      part: {\n        cell: CLEAR_TINT,\n        columnHeader: cn(\n          '[--spreadsheet-tint:var(--ws-dynamic-fill-tertiary-alpha-strong-default)]',\n          'hover:[--spreadsheet-tint:var(--ws-dynamic-fill-tertiary-alpha-strong-hover)]',\n          'active:[--spreadsheet-tint:var(--ws-dynamic-fill-tertiary-alpha-strong-pressed)]',\n        ),\n        rowHeader: cn(CLEAR_TINT, 'text-ws-static-subtle'),\n      },\n      align: {\n        left: 'text-left',\n        center: 'text-center',\n        right: 'text-right',\n      },\n    },\n    defaultVariants: {\n      size: 'sm',\n      part: 'cell',\n      align: 'left',\n    },\n  },\n);\n\n/** The row a cell lays out mixed content in: Figma's auto layout, centred, 4px apart. */\nexport const spreadsheetCellContentVariants = cva('gap-ws-3 flex min-w-0 items-center', {\n  variants: {\n    align: {\n      left: 'justify-start',\n      center: 'justify-center',\n      right: 'justify-end',\n    },\n  },\n  defaultVariants: {\n    align: 'left',\n  },\n});\n"
    },
    {
      "path": "src/components/spreadsheet/SpreadsheetBody.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/SpreadsheetBody.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport type { SpreadsheetBodyProps } from './Spreadsheet.types';\n\nexport const SpreadsheetBody = React.forwardRef<HTMLTableSectionElement, SpreadsheetBodyProps>(\n  ({ className, ...props }, ref) => (\n    <tbody\n      ref={ref}\n      data-slot=\"spreadsheet-body\"\n      {...props}\n      className={cn('bg-inherit', className)}\n    />\n  ),\n);\n\nSpreadsheetBody.displayName = 'Spreadsheet.Body';\n"
    },
    {
      "path": "src/components/spreadsheet/SpreadsheetCell.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/SpreadsheetCell.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport { useSpreadsheetContext } from './Spreadsheet.context';\nimport { useSpreadsheetCell } from './Spreadsheet.hooks';\nimport { cellContent } from './Spreadsheet.logic';\nimport type { SpreadsheetCellProps } from './Spreadsheet.types';\nimport { spreadsheetCellVariants } from './Spreadsheet.variants';\n\n/**\n * There is no `type` prop: Figma's cell types (Text, Number, Checkbox, Status Badge, Tags, Switch,\n * Progress, Icon, Person, Thumbnail, Payment Method) differ only in what the cell holds, so the\n * content is the library component itself. The cell gives every type the same frame: height,\n * padding, grid lines, state tints and one line of content.\n */\nexport const SpreadsheetCell = React.forwardRef<HTMLTableCellElement, SpreadsheetCellProps>(\n  ({ align = 'left', className, children, ...props }, ref) => {\n    const { size } = useSpreadsheetContext();\n    const cell = useSpreadsheetCell();\n    const { content, title } = cellContent(children, align);\n\n    return (\n      <td\n        ref={ref}\n        // A td in a grid is a gridcell to browsers already; the role says so to every tool.\n        role=\"gridcell\"\n        data-slot=\"spreadsheet-cell\"\n        title={title}\n        {...props}\n        {...cell}\n        className={cn(spreadsheetCellVariants({ size, align }), className)}\n      >\n        {content}\n      </td>\n    );\n  },\n);\n\nSpreadsheetCell.displayName = 'Spreadsheet.Cell';\n"
    },
    {
      "path": "src/components/spreadsheet/SpreadsheetColumnHeader.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/SpreadsheetColumnHeader.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport { useSpreadsheetContext } from './Spreadsheet.context';\nimport { useSpreadsheetCell } from './Spreadsheet.hooks';\nimport { cellContent } from './Spreadsheet.logic';\nimport type { SpreadsheetColumnHeaderProps } from './Spreadsheet.types';\nimport { spreadsheetCellVariants } from './Spreadsheet.variants';\n\nconst ARIA_SORT = { asc: 'ascending', desc: 'descending' } as const;\n\nconst ariaSort = (direction: SpreadsheetColumnHeaderProps['sortDirection']) =>\n  direction === undefined ? undefined : direction === null ? 'none' : ARIA_SORT[direction];\n\n/** Figma: the Header cell type (icon, Body/Small label, chevron) on the header row's tint. */\nexport const SpreadsheetColumnHeader = React.forwardRef<\n  HTMLTableCellElement,\n  SpreadsheetColumnHeaderProps\n>(({ align = 'left', sortDirection, className, children, ...props }, ref) => {\n  const { size } = useSpreadsheetContext();\n  const cell = useSpreadsheetCell();\n  const { content, title } = cellContent(children, align);\n\n  return (\n    <th\n      ref={ref}\n      scope=\"col\"\n      data-slot=\"spreadsheet-column-header\"\n      title={title}\n      {...props}\n      {...cell}\n      aria-sort={ariaSort(sortDirection)}\n      className={cn(spreadsheetCellVariants({ size, align, part: 'columnHeader' }), className)}\n    >\n      {content}\n    </th>\n  );\n});\n\nSpreadsheetColumnHeader.displayName = 'Spreadsheet.ColumnHeader';\n"
    },
    {
      "path": "src/components/spreadsheet/SpreadsheetColumnHeaderIcon.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/SpreadsheetColumnHeaderIcon.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport type { SpreadsheetColumnHeaderIconProps } from './Spreadsheet.types';\n\n/** Figma: 14px (Size/8) in Static/Text/Subtle. */\nexport const SpreadsheetColumnHeaderIcon = React.forwardRef<\n  SVGSVGElement,\n  SpreadsheetColumnHeaderIconProps\n>(({ icon: Icon, className, ...props }, ref) => (\n  <Icon\n    ref={ref}\n    aria-hidden=\"true\"\n    focusable=\"false\"\n    className={cn('size-ws-8 text-ws-static-subtle shrink-0', className)}\n    data-slot=\"spreadsheet-column-header-icon\"\n    {...props}\n  />\n));\n\nSpreadsheetColumnHeaderIcon.displayName = 'Spreadsheet.ColumnHeaderIcon';\n"
    },
    {
      "path": "src/components/spreadsheet/SpreadsheetColumnHeaderTrigger.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/SpreadsheetColumnHeaderTrigger.tsx",
      "content": "'use client';\n\nimport { RiArrowDropDownFill } from '@remixicon/react';\nimport * as React from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport type { SpreadsheetColumnHeaderTriggerProps } from './Spreadsheet.types';\n\n/**\n * Figma: the Chevron of the Header cell, a 16px (Size/9) arrow-drop-down-fill in\n * Static/Text/Subtle right after the label. It takes no hover of its own: the header cell's\n * tint is the hover.\n */\nexport const SpreadsheetColumnHeaderTrigger = React.forwardRef<\n  HTMLButtonElement,\n  SpreadsheetColumnHeaderTriggerProps\n>(({ className, type = 'button', ...props }, ref) => (\n  <button\n    ref={ref}\n    type={type}\n    data-slot=\"spreadsheet-column-header-trigger\"\n    {...props}\n    className={cn(\n      'text-ws-static-subtle rounded-ws-control-sm p-ws-0 inline-flex shrink-0 cursor-pointer items-center justify-center border-0 bg-transparent',\n      'focus-visible:wds-focus-visible outline-ws-dynamic-primary-strong-default',\n      className,\n    )}\n  >\n    <RiArrowDropDownFill aria-hidden=\"true\" focusable=\"false\" className=\"size-ws-9\" />\n  </button>\n));\n\nSpreadsheetColumnHeaderTrigger.displayName = 'Spreadsheet.ColumnHeaderTrigger';\n"
    },
    {
      "path": "src/components/spreadsheet/SpreadsheetHead.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/SpreadsheetHead.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport type { SpreadsheetHeadProps } from './Spreadsheet.types';\n\n/** Sticks to the top of the grid; its background is the grid's surface. */\nexport const SpreadsheetHead = React.forwardRef<HTMLTableSectionElement, SpreadsheetHeadProps>(\n  ({ className, ...props }, ref) => (\n    <thead\n      ref={ref}\n      data-slot=\"spreadsheet-head\"\n      {...props}\n      className={cn('z-ws-sticky sticky top-0 bg-inherit', className)}\n    />\n  ),\n);\n\nSpreadsheetHead.displayName = 'Spreadsheet.Head';\n"
    },
    {
      "path": "src/components/spreadsheet/SpreadsheetRow.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/SpreadsheetRow.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport type { SpreadsheetRowProps } from './Spreadsheet.types';\n\n/** Passes the grid's surface on to its pinned cells, which paint it over what scrolls under. */\nexport const SpreadsheetRow = React.forwardRef<HTMLTableRowElement, SpreadsheetRowProps>(\n  ({ className, ...props }, ref) => (\n    <tr ref={ref} data-slot=\"spreadsheet-row\" {...props} className={cn('bg-inherit', className)} />\n  ),\n);\n\nSpreadsheetRow.displayName = 'Spreadsheet.Row';\n"
    },
    {
      "path": "src/components/spreadsheet/SpreadsheetRowHeader.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/spreadsheet/SpreadsheetRowHeader.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport { useSpreadsheetContext } from './Spreadsheet.context';\nimport { useSpreadsheetCell } from './Spreadsheet.hooks';\nimport { cellContent } from './Spreadsheet.logic';\nimport type { SpreadsheetRowHeaderProps } from './Spreadsheet.types';\nimport { spreadsheetCellVariants } from './Spreadsheet.variants';\n\n/** Figma (Clients screen): the row number column, a Text cell centred in Static/Text/Subtle. */\nexport const SpreadsheetRowHeader = React.forwardRef<\n  HTMLTableCellElement,\n  SpreadsheetRowHeaderProps\n>(({ align = 'center', className, children, ...props }, ref) => {\n  const { size } = useSpreadsheetContext();\n  const cell = useSpreadsheetCell();\n  // No title: a row number never needs its full text spelled out.\n  const { content } = cellContent(children, align);\n\n  return (\n    <th\n      ref={ref}\n      scope=\"row\"\n      data-slot=\"spreadsheet-row-header\"\n      {...props}\n      {...cell}\n      className={cn(spreadsheetCellVariants({ size, align, part: 'rowHeader' }), className)}\n    >\n      {content}\n    </th>\n  );\n});\n\nSpreadsheetRowHeader.displayName = 'Spreadsheet.RowHeader';\n"
    }
  ],
  "meta": {
    "version": "1.1.0",
    "commit": "a734f9f0"
  }
}
