{"version":3,"sources":["../../src/cell/index.ts","../../src/cell/table-cell.ts","../../src/utilities/parseAlign.ts"],"sourcesContent":["export * from './table-cell.js'\n","import '../types.js'\n\nimport { mergeAttributes, Node } from '@tiptap/core'\n\nimport { createAlignAttribute } from '../utilities/parseAlign.js'\n\nexport interface TableCellOptions {\n  /**\n   * The HTML attributes for a table cell node.\n   * @default {}\n   * @example { class: 'foo' }\n   */\n  HTMLAttributes: Record<string, any>\n}\n\n/**\n * This extension allows you to create table cells.\n * @see https://www.tiptap.dev/api/nodes/table-cell\n */\nexport const TableCell = Node.create<TableCellOptions>({\n  name: 'tableCell',\n\n  addOptions() {\n    return {\n      HTMLAttributes: {},\n    }\n  },\n\n  content: 'block+',\n\n  addAttributes() {\n    return {\n      colspan: {\n        default: 1,\n      },\n      rowspan: {\n        default: 1,\n      },\n      colwidth: {\n        default: null,\n        parseHTML: element => {\n          const colwidth = element.getAttribute('colwidth')\n          const value = colwidth ? colwidth.split(',').map(width => parseInt(width, 10)) : null\n\n          // if there is no colwidth attribute on the cell, try to get it from the colgroup\n          if (!value) {\n            const cols = element.closest('table')?.querySelectorAll('colgroup > col')\n            const cellIndex = Array.from(element.parentElement?.children || []).indexOf(element)\n\n            if (cellIndex && cellIndex > -1 && cols && cols[cellIndex]) {\n              const colWidth = cols[cellIndex].getAttribute('width')\n              return colWidth ? [parseInt(colWidth, 10)] : null\n            }\n          }\n\n          return value\n        },\n      },\n      align: createAlignAttribute(),\n    }\n  },\n\n  tableRole: 'cell',\n\n  isolating: true,\n\n  parseHTML() {\n    return [{ tag: 'td' }]\n  },\n\n  renderHTML({ HTMLAttributes }) {\n    return ['td', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n  },\n})\n","import type { Attribute } from '@tiptap/core'\n\n/**\n * Supported table cell alignment values\n */\nexport enum TableCellAlign {\n  Left = 'left',\n  Right = 'right',\n  Center = 'center',\n}\n\n/**\n * Normalize unknown input into a supported table alignment\n *\n * @param value - A potential alignment value\n * @returns A valid TableCellAlign value or null\n */\nexport function normalizeTableCellAlign(value: unknown): TableCellAlign | null {\n  if (value === TableCellAlign.Left || value === TableCellAlign.Right || value === TableCellAlign.Center) {\n    return value\n  }\n\n  return null\n}\n\n/**\n * Parse table cell alignment from an HTML element\n *\n * Prefers inline style (${\"`\"}text-align${\"`\"}) and falls back to the legacy\n * ${\"`\"}align${\"`\"} attribute.\n *\n * @param element - The table cell/header DOM element\n * @returns A valid TableCellAlign value or null\n */\nexport function parseAlign(element: HTMLElement): TableCellAlign | null {\n  const styleAlign = (element.style.textAlign || '').trim().toLowerCase()\n  const attrAlign = (element.getAttribute('align') || '').trim().toLowerCase()\n  const align = styleAlign || attrAlign\n\n  return normalizeTableCellAlign(align)\n}\n\n/**\n * Normalize alignment from a generic attrs object that may include an align field\n *\n * @param attributes - A node attrs-like object with an optional align field\n * @returns A valid TableCellAlign value or null.\n */\nexport function normalizeTableCellAlignFromAttributes(\n  attributes: { align?: TableCellAlign } | null | undefined,\n): TableCellAlign | null {\n  return normalizeTableCellAlign(attributes?.align)\n}\n\n/**\n * Create a reusable Tiptap attribute config for table alignment\n *\n * @returns A Tiptap Attribute definition that parses and renders table alignment\n */\nexport function createAlignAttribute(): Attribute {\n  return {\n    default: null,\n    parseHTML: (element: HTMLElement) => parseAlign(element),\n    renderHTML: (attributes: { align?: TableCellAlign | null }) => {\n      if (!attributes.align) {\n        return {}\n      }\n\n      return {\n        style: `text-align: ${attributes.align}`,\n      }\n    },\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,kBAAsC;;;ACe/B,SAAS,wBAAwB,OAAuC;AAC7E,MAAI,UAAU,qBAAuB,UAAU,uBAAwB,UAAU,uBAAuB;AACtG,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAWO,SAAS,WAAW,SAA6C;AACtE,QAAM,cAAc,QAAQ,MAAM,aAAa,IAAI,KAAK,EAAE,YAAY;AACtE,QAAM,aA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