{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "data-table",
  "type": "registry:item",
  "title": "Data Table",
  "description": "A table of records you can sort, filter and select from. Click a column's heading to sort by it (again to reverse; announced with `aria-sort`), type in the box to filter every column, and with `selectable` tick rows (the heading's box selects every shown row). `columns` is `[{ key, label, sortable?, align?, format? }]` (`format`: \"number\", \"currency\", \"date\"); `rows` is an array of objects with an `id`. `selected` (an array of ids) is two-way. Long tables page by `pageSize`.",
  "dependencies": [
    "@zubra/runtime@^5.13.1"
  ],
  "categories": [
    "data"
  ],
  "registryDependencies": [
    "https://zubra-js.github.io/zubra-ui/r/theme.json"
  ],
  "files": [
    {
      "path": "components/data-table.js",
      "type": "registry:file",
      "target": "~/src/components/zubra/data-table.js",
      "content": "// Generated by zubra from data-table.zb. Do not edit.\nimport { $define, $r, $t } from \"@zubra/runtime\";\nimport { effect, emit } from '@zubra/runtime';\nimport { state as __zubraState, computed as __zubraComputed } from \"@zubra/runtime\";\n\nexport const tag = \"data-table\";\n\nexport default $define(tag, {\n  props: {\n    \"columns\": { attribute: \"columns\", default: [], required: false },\n    \"rows\": { attribute: \"rows\", default: [], required: false },\n    \"selected\": { attribute: \"selected\", default: [], required: false, model: true },\n    \"selectable\": { attribute: \"selectable\", default: false, required: false },\n    \"filterable\": { attribute: \"filterable\", default: true, required: false },\n    \"pageSize\": { attribute: \"page-size\", default: 0, required: false },\n    \"currency\": { attribute: \"currency\", default: \"USD\", required: false },\n    \"label\": { attribute: \"label\", default: \"Records\", required: false },\n  },\n  abi: 3,\n  shadow: false,\n  form: false,\n  slots: [],\n  events: [\"selectedchange\", \"sortchange\"],\n  styled: true,\n  styles: \"@layer theme, base, components, utilities;\\n@layer components {\\n@scope (data-table) to ([data-zb-slotted=\\\"data-table\\\"]) {\\n  :scope { display: block; }\\n  .table-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.75rem; }\\n  .table-filter { width: min(18rem, 100%); padding: 0.5rem 0.75rem; border: 1px solid var(--input, #e4e4e7); border-radius: calc(var(--radius, 0.625rem) * 0.8); background: var(--background, #fff); color: var(--foreground, #18181b); font: inherit; font-size: 0.9rem; }\\n  .table-filter:focus-visible { outline: none; border-color: var(--ring, #a1a1aa); box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring, #a1a1aa) 40%, transparent); }\\n  .table-count { font-size: 0.85rem; color: color-mix(in oklab, var(--muted-foreground, #71717a) 75%, var(--foreground, #18181b)); }\\n  .table-scroll { overflow-x: auto; border: 1px solid var(--border, #e4e4e7); border-radius: var(--radius, 0.625rem); }\\n  table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }\\n  th, td { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border, #e4e4e7); text-align: left; white-space: nowrap; }\\n  tbody tr:last-child td { border-bottom: 0; }\\n  th { font-weight: 600; background: color-mix(in oklab, var(--muted, #f4f4f5) 55%, var(--background, #fff)); }\\n  .table-end { text-align: right; font-variant-numeric: tabular-nums; }\\n  .table-check { width: 2.5rem; }\\n  tbody tr:hover { background: color-mix(in oklab, var(--muted, #f4f4f5) 45%, transparent); }\\n  tbody tr.table-selected { background: color-mix(in oklab, var(--primary, #18181b) 7%, var(--background, #fff)); }\\n  .table-sort { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0; border: 0; background: none; color: inherit; font: inherit; font-weight: 600; cursor: pointer; }\\n  .table-sort::after { content: \\\"↕\\\"; font-size: 0.75em; opacity: 0.45; }\\n  [aria-sort=ascending] .table-sort::after { content: \\\"↑\\\"; opacity: 1; }\\n  [aria-sort=descending] .table-sort::after { content: \\\"↓\\\"; opacity: 1; }\\n  button:focus-visible, input:focus-visible { outline: 2px solid var(--ring, #a1a1aa); outline-offset: 2px; }\\n  input[type=checkbox] { width: 1rem; height: 1rem; accent-color: var(--primary, #18181b); cursor: pointer; }\\n  .table-empty { padding: 2rem 1rem; text-align: center; color: color-mix(in oklab, var(--muted-foreground, #71717a) 75%, var(--foreground, #18181b)); }\\n  .table-pages { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; margin-top: 0.75rem; font-size: 0.85rem; }\\n  .table-pages button { height: 2rem; padding: 0 0.75rem; border: 1px solid var(--border, #e4e4e7); border-radius: calc(var(--radius, 0.625rem) * 0.7); background: var(--background, #fff); color: var(--foreground, #18181b); font: inherit; cursor: pointer; }\\n  .table-pages button:disabled { opacity: 0.45; cursor: not-allowed; }\\n  @media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; animation-iteration-count: 1 !important; } }\\n}\\n}\\n\",\n  template: \"\\n  <div class=\\\"table-tools\\\">\\n    <!--[--><!--]-->\\n    <span class=\\\"table-count\\\" role=\\\"status\\\"></span>\\n  </div>\\n  <div class=\\\"table-scroll\\\" role=\\\"region\\\" tabindex=\\\"0\\\">\\n    <table><thead><tr><!--[--><!--]--><!--[--><!--]--></tr></thead><tbody><!--[--><!--]--><!--[--><!--]--></tbody></table>\\n  </div>\\n  <!--[--><!--]-->\\n\",\n  setup($p, $emit) {\n    const emit = $emit;\nfunction __zubraAssign(signal, value) { signal.set(value); return value }\nfunction __zubraUpdate(signal, delta, prefix) { const old = signal.get(); signal.set(old + delta); return prefix ? old + delta : old }\n                                               \n\n  const all = __zubraState(null)\n\n  const sortKey = __zubraState(\"\")\n  const direction = __zubraState(\"ascending\")\n  const query = __zubraState(\"\")\n  const pageIndex = __zubraState(0)\n\n  // A function given what it reads, so the derived rows follow every one of them.\n  function arrange(list, cols, text, key, order) {\n    const words = text.toLowerCase().split(/\\s+/).filter(Boolean)\n    const filtered = list.filter((row) => words.every((word) => cols.some((column) => String(row[column.key] ?? \"\").toLowerCase().includes(word))))\n    if (!key) return filtered\n    const sign = order === \"ascending\" ? 1 : -1\n    return [...filtered].sort((a, b) => {\n      const x = a[key]\n      const y = b[key]\n      return (typeof x === \"number\" && typeof y === \"number\" ? x - y : String(x ?? \"\").localeCompare(String(y ?? \"\"), undefined, { numeric: true })) * sign\n    })\n  }\n  const shown = __zubraComputed(() => (arrange($p.rows, $p.columns, query.get(), sortKey.get(), direction.get())))\n  const pageCount = __zubraComputed(() => ($p.pageSize > 0 ? Math.max(1, Math.ceil(shown.get().length / $p.pageSize)) : 1))\n  const page = __zubraComputed(() => (Math.min(pageIndex.get(), pageCount.get() - 1)))\n  const visible = __zubraComputed(() => ($p.pageSize > 0 ? shown.get().slice(page.get() * $p.pageSize, page.get() * $p.pageSize + $p.pageSize) : shown.get()))\n  const allSelected = __zubraComputed(() => (visible.get().length > 0 && visible.get().every((row) => $p.selected.includes(row.id))))\n  const someSelected = __zubraComputed(() => (!allSelected.get() && visible.get().some((row) => $p.selected.includes(row.id))))\n\n  const cell = (row, column) => {\n    const value = row[column.key]\n    if (value == null) return \"\"\n    if (column.format === \"number\" && typeof value === \"number\") return value.toLocaleString()\n    if (column.format === \"currency\" && typeof value === \"number\") return value.toLocaleString(undefined, { style: \"currency\", currency: $p.currency })\n    if (column.format === \"date\") { const date = new Date(value); return Number.isNaN(date.getTime()) ? String(value) : date.toLocaleDateString() }\n    return String(value)\n  }\n  // `indeterminate` is a property of the input, never an attribute.\n  effect(() => {\n    if (all.get()) all.get().indeterminate = someSelected.get()\n  })\n  function sort(column) {\n    if (!column.sortable) return\n    __zubraAssign(direction, sortKey.get() === column.key && direction.get() === \"ascending\" ? \"descending\" : \"ascending\")\n    __zubraAssign(sortKey, column.key)\n    emit('sortchange', { key: sortKey.get(), direction: direction.get() })\n  }\n  function toggle(row) {\n    $p.selected = $p.selected.includes(row.id) ? $p.selected.filter((id) => id !== row.id) : [...$p.selected, row.id]\n  }\n  function toggleAll() {\n    const ids = visible.get().map((row) => row.id)\n    $p.selected = allSelected.get() ? $p.selected.filter((id) => !ids.includes(id)) : [...new Set([...$p.selected, ...ids])]\n  }\n  function filter(event) {\n    __zubraAssign(query, event.target.value)\n    __zubraAssign(pageIndex, 0)\n  }\n    return [\n      { path: [0, 0], when: () => $p.filterable, blocks: [{ template: \"<input class=\\\"table-filter\\\" type=\\\"search\\\" placeholder=\\\"Filter…\\\">\", parts: () => [{ path: [0], attribute: \"aria-label\", value: () => (`Filter ${$p.label}`) }, { path: [0], attribute: \"value\", value: () => $r(query) }, { path: [0], on: \"input\", handler: () => $r(filter) }] }, null] },\n      { path: [0, 1], text: () => $t(($p.selectable && $p.selected.length ? `${$p.selected.length} selected · ` : \"\")) + $t($r(shown).length) + \" \" + $t((($r(shown).length === 1) ? \"row\" : \"rows\")) },\n      { path: [1], attribute: \"aria-label\", value: () => $p.label },\n      { path: [1, 0], attribute: \"aria-label\", value: () => $p.label },\n      { path: [1, 0, 0, 0, 0], when: () => $p.selectable, blocks: [{ template: \"<th class=\\\"table-check\\\" scope=\\\"col\\\"><input type=\\\"checkbox\\\" aria-label=\\\"Select all shown rows\\\"></th>\", parts: () => [{ path: [0, 0], ref: () => (($el) => (__zubraAssign(all, $el))) }, { path: [0, 0], attribute: \"checked\", boolean: true, value: () => $r(allSelected) }, { path: [0, 0], on: \"change\", handler: () => $r(toggleAll) }] }, null] },\n      { path: [1, 0, 0, 0, 1], each: () => $p.columns, key: (column, $index) => $r(column).key, block: { template: \"<th scope=\\\"col\\\">\\n              <!--[--><!--]-->\\n            </th>\", parts: (column, $index) => [{ path: [0], toggle: \"table-end\", value: () => ((($r(column).align === \"end\") || ($r(column).format === \"number\")) || ($r(column).format === \"currency\")) }, { path: [0], attribute: \"aria-sort\", value: () => (($r(sortKey) === $r(column).key) ? $r(direction) : null) }, { path: [0, 0], when: () => $r(column).sortable, blocks: [{ template: \"<button type=\\\"button\\\" class=\\\"table-sort\\\"></button>\", parts: () => [{ path: [0], on: \"click\", handler: () => (() => sort($r(column))) }, { path: [0], text: () => $t($r(column).label) }] }, { template: \"<span></span>\", parts: () => [{ path: [0], text: () => $t($r(column).label) }] }] }] } },\n      { path: [1, 0, 1, 0], each: () => $r(visible), key: (row, $index) => $r(row).id, block: { template: \"<tr><!--[--><!--]--><!--[--><!--]--></tr>\", parts: (row, $index) => [{ path: [0], toggle: \"table-selected\", value: () => ($p.selectable && $p.selected.includes($r(row).id)) }, { path: [0, 0], when: () => $p.selectable, blocks: [{ template: \"<td class=\\\"table-check\\\"><input type=\\\"checkbox\\\"></td>\", parts: () => [{ path: [0, 0], attribute: \"aria-label\", value: () => (`Select ${$r(row)[$p.columns[0]?.key] ?? $r(row).id}`) }, { path: [0, 0], attribute: \"checked\", boolean: true, value: () => ($p.selected.includes($r(row).id)) }, { path: [0, 0], on: \"change\", handler: () => (() => toggle($r(row))) }] }, null] }, { path: [0, 1], each: () => $p.columns, key: (column, $index) => $r(column).key, block: { template: \"<td></td>\", parts: (column, $index) => [{ path: [0], toggle: \"table-end\", value: () => ((($r(column).align === \"end\") || ($r(column).format === \"number\")) || ($r(column).format === \"currency\")) }, { path: [0], text: () => $t((cell($r(row), $r(column)))) }] } }] } },\n      { path: [1, 0, 1, 1], when: () => !($r(visible).length), blocks: [{ template: \"<tr><td class=\\\"table-empty\\\"></td></tr>\", parts: () => [{ path: [0, 0], attribute: \"colspan\", value: () => ($p.columns.length + ($p.selectable ? 1 : 0)) }, { path: [0, 0], text: () => $t((query.get() ? `Nothing matches \"${query.get()}\".` : \"No records yet.\")) }] }, null] },\n      { path: [2], when: () => ($r(pageCount) > 1), blocks: [{ template: \"<div class=\\\"table-pages\\\">\\n    <button type=\\\"button\\\">Previous</button>\\n    <span></span>\\n    <button type=\\\"button\\\">Next</button>\\n  </div>\", parts: () => [{ path: [0, 0], attribute: \"disabled\", boolean: true, value: () => ($r(page) === 0) }, { path: [0, 0], on: \"click\", handler: () => (() => (__zubraAssign(pageIndex, page.get() - 1))) }, { path: [0, 1], text: () => \"Page \" + $t(($r(page) + 1)) + \" of \" + $t($r(pageCount)) }, { path: [0, 2], attribute: \"disabled\", boolean: true, value: () => ($r(page) >= ($r(pageCount) - 1)) }, { path: [0, 2], on: \"click\", handler: () => (() => (__zubraAssign(pageIndex, page.get() + 1))) }] }, null] },\n    ];\n  },\n});\n"
    }
  ]
}
