@dotcms/react 1.5.3-next.2118 → 1.5.3-next.2120

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -116,6 +116,7 @@ const BlockEditorBlock = ({
116
116
  case BlockEditorDefaultBlocks.TABLE:
117
117
  return jsx(TableRenderer, {
118
118
  content: (_node$content = node.content) != null ? _node$content : [],
119
+ attrs: node.attrs,
119
120
  blockEditorItem: BlockEditorBlock
120
121
  }, key);
121
122
  case BlockEditorDefaultBlocks.GRID_BLOCK:
@@ -1,50 +1,63 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
2
 
3
3
  /**
4
- * Renders a table component for the Block Editor.
4
+ * Renders a table block for the Block Editor.
5
5
  *
6
- * @param content - The content of the table.
7
- * @param blockEditorItem - The Block Editor item component.
6
+ * **Cell-type-aware**: each cell is emitted as `<th>` or `<td>` based on the node's
7
+ * `type` (`tableHeader` vs `tableCell`) rather than its row position — so column-header
8
+ * cells in any row (the result of "Toggle column header" in the editor) keep their
9
+ * semantic `<th>` wrapper and the `scope` attribute reaches headless consumers.
10
+ *
11
+ * @param content - The table's child rows.
12
+ * @param attrs - Optional table-level attributes (`caption`, `ariaLabel`, `ariaLabelledby`).
13
+ * @param blockEditorItem - The Block Editor item component for nested content.
8
14
  */
9
15
  const TableRenderer = ({
10
16
  content,
17
+ attrs,
11
18
  blockEditorItem
12
19
  }) => {
13
20
  const BlockEditorItemComponent = blockEditorItem;
14
- const renderTableContent = node => {
21
+ const renderCellContent = node => {
15
22
  var _node$content;
16
23
  return jsx(BlockEditorItemComponent, {
17
24
  content: (_node$content = node.content) != null ? _node$content : []
18
25
  });
19
26
  };
27
+ const caption = (attrs == null ? void 0 : attrs.caption) || undefined;
28
+ const ariaLabel = (attrs == null ? void 0 : attrs.ariaLabel) || undefined;
29
+ const ariaLabelledBy = (attrs == null ? void 0 : attrs.ariaLabelledby) || undefined;
20
30
  return jsxs("table", {
21
- children: [jsx("thead", {
22
- children: content.slice(0, 1).map((rowNode, rowIndex) => {
31
+ "aria-label": ariaLabel,
32
+ "aria-labelledby": ariaLabelledBy,
33
+ children: [caption ? jsx("caption", {
34
+ children: caption
35
+ }) : null, jsx("tbody", {
36
+ children: content.map((rowNode, rowIndex) => {
23
37
  var _rowNode$content;
24
38
  return jsx("tr", {
25
39
  children: (_rowNode$content = rowNode.content) == null ? void 0 : _rowNode$content.map((cellNode, cellIndex) => {
26
40
  var _cellNode$attrs, _cellNode$attrs2;
27
- return jsx("th", {
28
- colSpan: Number(((_cellNode$attrs = cellNode.attrs) == null ? void 0 : _cellNode$attrs.colspan) || 1),
29
- rowSpan: Number(((_cellNode$attrs2 = cellNode.attrs) == null ? void 0 : _cellNode$attrs2.rowspan) || 1),
30
- children: renderTableContent(cellNode)
31
- }, `${cellNode.type}-${cellIndex}`);
32
- })
33
- }, `${rowNode.type}-${rowIndex}`);
34
- })
35
- }), jsx("tbody", {
36
- children: content.slice(1).map((rowNode, rowIndex) => {
37
- var _rowNode$content2;
38
- return jsx("tr", {
39
- children: (_rowNode$content2 = rowNode.content) == null ? void 0 : _rowNode$content2.map((cellNode, cellIndex) => {
40
- var _cellNode$attrs3, _cellNode$attrs4;
41
+ const colSpan = Number(((_cellNode$attrs = cellNode.attrs) == null ? void 0 : _cellNode$attrs.colspan) || 1);
42
+ const rowSpan = Number(((_cellNode$attrs2 = cellNode.attrs) == null ? void 0 : _cellNode$attrs2.rowspan) || 1);
43
+ // Cell type not row index decides th vs td. Matches the
44
+ // VTL renderer (storyblock/render.vtl).
45
+ if (cellNode.type === 'tableHeader') {
46
+ var _cellNode$attrs3;
47
+ return jsx("th", {
48
+ colSpan: colSpan,
49
+ rowSpan: rowSpan,
50
+ scope: ((_cellNode$attrs3 = cellNode.attrs) == null ? void 0 : _cellNode$attrs3.scope) || undefined,
51
+ children: renderCellContent(cellNode)
52
+ }, `cell-${cellIndex}`);
53
+ }
41
54
  return jsx("td", {
42
- colSpan: Number(((_cellNode$attrs3 = cellNode.attrs) == null ? void 0 : _cellNode$attrs3.colspan) || 1),
43
- rowSpan: Number(((_cellNode$attrs4 = cellNode.attrs) == null ? void 0 : _cellNode$attrs4.rowspan) || 1),
44
- children: renderTableContent(cellNode)
45
- }, `${cellNode.type}-${cellIndex}`);
55
+ colSpan: colSpan,
56
+ rowSpan: rowSpan,
57
+ children: renderCellContent(cellNode)
58
+ }, `cell-${cellIndex}`);
46
59
  })
47
- }, `${rowNode.type}-${rowIndex}`);
60
+ }, `row-${rowIndex}`);
48
61
  })
49
62
  })]
50
63
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/react",
3
- "version": "1.5.3-next.2118",
3
+ "version": "1.5.3-next.2120",
4
4
  "peerDependencies": {
5
5
  "react": ">=18",
6
6
  "react-dom": ">=18"
@@ -2,15 +2,26 @@ import React from 'react';
2
2
  import { BlockEditorNode } from '@dotcms/types';
3
3
  interface TableRendererProps {
4
4
  content: BlockEditorNode[];
5
+ /**
6
+ * Table-node attributes (`caption`, `ariaLabel`, `ariaLabelledby`). Optional for
7
+ * back-compat with older payloads that don't carry these.
8
+ */
9
+ attrs?: BlockEditorNode['attrs'];
5
10
  blockEditorItem: React.FC<{
6
11
  content: BlockEditorNode[];
7
12
  }>;
8
13
  }
9
14
  /**
10
- * Renders a table component for the Block Editor.
15
+ * Renders a table block for the Block Editor.
11
16
  *
12
- * @param content - The content of the table.
13
- * @param blockEditorItem - The Block Editor item component.
17
+ * **Cell-type-aware**: each cell is emitted as `<th>` or `<td>` based on the node's
18
+ * `type` (`tableHeader` vs `tableCell`) rather than its row position — so column-header
19
+ * cells in any row (the result of "Toggle column header" in the editor) keep their
20
+ * semantic `<th>` wrapper and the `scope` attribute reaches headless consumers.
21
+ *
22
+ * @param content - The table's child rows.
23
+ * @param attrs - Optional table-level attributes (`caption`, `ariaLabel`, `ariaLabelledby`).
24
+ * @param blockEditorItem - The Block Editor item component for nested content.
14
25
  */
15
26
  export declare const TableRenderer: React.FC<TableRendererProps>;
16
27
  export {};