@dotcms/react 1.5.4 → 1.5.6
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.
- package/lib/next/components/DotCMSBlockEditorRenderer/components/BlockEditorBlock.esm.js +1 -0
- package/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Table.esm.js +38 -25
- package/package.json +1 -1
- package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Table.d.ts +14 -3
|
@@ -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
|
|
4
|
+
* Renders a table block for the Block Editor.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
|
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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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:
|
|
43
|
-
rowSpan:
|
|
44
|
-
children:
|
|
45
|
-
},
|
|
55
|
+
colSpan: colSpan,
|
|
56
|
+
rowSpan: rowSpan,
|
|
57
|
+
children: renderCellContent(cellNode)
|
|
58
|
+
}, `cell-${cellIndex}`);
|
|
46
59
|
})
|
|
47
|
-
},
|
|
60
|
+
}, `row-${rowIndex}`);
|
|
48
61
|
})
|
|
49
62
|
})]
|
|
50
63
|
});
|
package/package.json
CHANGED
|
@@ -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
|
|
15
|
+
* Renders a table block for the Block Editor.
|
|
11
16
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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 {};
|