import type { JSONContent } from '@tiptap/core' import { DEFAULT_CONTENT_EDITOR_TABLE_COLS } from '@admin/utils/editor/default-content-editor-table-cols' import { DEFAULT_CONTENT_EDITOR_TABLE_ROWS } from '@admin/utils/editor/default-content-editor-table-rows' export function createContentEditorTableNode( rows: number = DEFAULT_CONTENT_EDITOR_TABLE_ROWS, cols: number = DEFAULT_CONTENT_EDITOR_TABLE_COLS ): JSONContent { const rowCount = Math.max(2, Math.floor(rows)) const colCount = Math.max(1, Math.floor(cols)) return { type: 'table', content: Array.from({ length: rowCount }, (_, rowIndex) => ({ type: 'tableRow', content: Array.from({ length: colCount }, (_, colIndex) => ({ type: rowIndex === 0 ? 'tableHeader' : 'tableCell', content: [ { type: 'paragraph', content: rowIndex === 0 ? [{ type: 'text', text: `Header ${colIndex + 1}` }] : [] } ] })) })) } }