@prismicio/api-renderer
Advanced tools
Comparing version 6.2.0-alpha.1 to 6.2.0-alpha.2
@@ -34,15 +34,17 @@ "use strict"; | ||
function renderTable(table, renderStructuredText) { | ||
const [firstRow, ...remainingRows] = table.content; | ||
const firstRow = table.content[0]; | ||
if (!firstRow) | ||
return renderDefaultTable(); | ||
const isFirstRowHeader = firstRow.content.every((cell) => cell.type === "tableHeader"); | ||
const headRow = isFirstRowHeader ? firstRow : undefined; | ||
const bodyRows = isFirstRowHeader ? table.content.slice(1) : table.content; | ||
return { | ||
// TO_DISCUSS: Should we not return head at all when there is no header row? | ||
head: renderHead(firstRow, renderStructuredText), | ||
body: renderBody(remainingRows, renderStructuredText), | ||
head: renderHead(headRow, renderStructuredText), | ||
body: renderBody(bodyRows, renderStructuredText), | ||
}; | ||
} | ||
function renderHead(row, renderStructuredText) { | ||
const isHeaderRow = row.content.every((cell) => cell.type === "tableHeader"); | ||
return { | ||
rows: isHeaderRow ? [renderRow(row, renderStructuredText)] : [], | ||
rows: row ? [renderRow(row, renderStructuredText)] : [], | ||
}; | ||
@@ -49,0 +51,0 @@ } |
{ | ||
"name": "@prismicio/api-renderer", | ||
"version": "6.2.0-alpha.1", | ||
"version": "6.2.0-alpha.2", | ||
"description": "Prismic renderers for the content API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -53,18 +53,20 @@ import type { | ||
function renderTable(table: TableContent, renderStructuredText: (cellContent: RichTextContent) => unknown) { | ||
const [firstRow, ...remainingRows] = table.content | ||
const firstRow = table.content[0] | ||
if (!firstRow) return renderDefaultTable() | ||
const isFirstRowHeader = firstRow.content.every((cell) => cell.type === "tableHeader") | ||
const headRow = isFirstRowHeader ? firstRow : undefined | ||
const bodyRows = isFirstRowHeader ? table.content.slice(1) : table.content | ||
return { | ||
// TO_DISCUSS: Should we not return head at all when there is no header row? | ||
head: renderHead(firstRow, renderStructuredText), | ||
body: renderBody(remainingRows, renderStructuredText), | ||
head: renderHead(headRow, renderStructuredText), | ||
body: renderBody(bodyRows, renderStructuredText), | ||
} | ||
} | ||
function renderHead(row: TableRow, renderStructuredText: (cellContent: RichTextContent) => unknown) { | ||
const isHeaderRow = row.content.every((cell) => cell.type === "tableHeader") | ||
function renderHead(row: TableRow | undefined, renderStructuredText: (cellContent: RichTextContent) => unknown) { | ||
return { | ||
rows: isHeaderRow ? [renderRow(row, renderStructuredText)] : [], | ||
rows: row ? [renderRow(row, renderStructuredText)] : [], | ||
} | ||
@@ -71,0 +73,0 @@ } |
1173159
27939