@adobe/helix-importer 2.1.1 → 2.2.0
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/utils/DOMUtils.js +11 -0
- package/test/utils/Blocks.spec.js +2 -2
- package/test/utils/DOMUtils.spec.js +22 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [2.2.0](https://github.com/adobe/helix-importer/compare/v2.1.1...v2.2.0) (2022-11-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* createTable handles colspans ([#33](https://github.com/adobe/helix-importer/issues/33)) ([06c48cf](https://github.com/adobe/helix-importer/commit/06c48cfdab04c0190f43bae12893ac560d5b3daf))
|
|
7
|
+
|
|
1
8
|
## [2.1.1](https://github.com/adobe/helix-importer/compare/v2.1.0...v2.1.1) (2022-09-29)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/utils/DOMUtils.js
CHANGED
|
@@ -168,9 +168,11 @@ export default class DOMUtils {
|
|
|
168
168
|
static createTable(data, document) {
|
|
169
169
|
const table = document.createElement('table');
|
|
170
170
|
|
|
171
|
+
let maxColumns = 0;
|
|
171
172
|
data.forEach((row, index) => {
|
|
172
173
|
const tr = document.createElement('tr');
|
|
173
174
|
|
|
175
|
+
maxColumns = Math.max(maxColumns, row.length);
|
|
174
176
|
row.forEach((cell) => {
|
|
175
177
|
const t = document.createElement(index === 0 ? 'th' : 'td');
|
|
176
178
|
if (typeof cell === 'string') {
|
|
@@ -187,6 +189,15 @@ export default class DOMUtils {
|
|
|
187
189
|
table.appendChild(tr);
|
|
188
190
|
});
|
|
189
191
|
|
|
192
|
+
// adjust the colspans
|
|
193
|
+
table.querySelectorAll('tr').forEach((tr) => {
|
|
194
|
+
const cells = Array.from(tr.querySelectorAll('td, th'));
|
|
195
|
+
if (cells.length < maxColumns) {
|
|
196
|
+
const lastCell = cells[cells.length - 1];
|
|
197
|
+
lastCell.setAttribute('colspan', maxColumns - cells.length + 1);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
190
201
|
return table;
|
|
191
202
|
}
|
|
192
203
|
|
|
@@ -82,7 +82,7 @@ describe('Blocks#convertBlocksToTables tests', () => {
|
|
|
82
82
|
`<main>${div}${div}${div}
|
|
83
83
|
<div>
|
|
84
84
|
<table>
|
|
85
|
-
<tr><th>Another Block</th></tr>
|
|
85
|
+
<tr><th colspan="2">Another Block</th></tr>
|
|
86
86
|
<tr><td>cell11</td><td>cell12</td></tr>
|
|
87
87
|
<tr><td>cell21</td><td>cell22</td></tr>
|
|
88
88
|
<tr><td><img src="https://www.sample.com/image.jpeg"></td><td><a href="https://www.sample.com/">A link</a></td></tr>
|
|
@@ -103,7 +103,7 @@ describe('Blocks#convertBlocksToTables tests', () => {
|
|
|
103
103
|
`<main>${div}${div}${div}
|
|
104
104
|
<div>
|
|
105
105
|
<table>
|
|
106
|
-
<tr><th>Promotion</th></tr>
|
|
106
|
+
<tr><th colspan="2">Promotion</th></tr>
|
|
107
107
|
<tr>
|
|
108
108
|
<td><a href="https://blog.adobe.com/en/promotions/doc-cloud-education.html">https://blog.adobe.com/en/promotions/doc-cloud-education.html</a></td>
|
|
109
109
|
<td><span>with content</span></td>
|
|
@@ -297,10 +297,28 @@ describe('DOM#createTable tests', () => {
|
|
|
297
297
|
[['header1', 'header2'], ['cell11', 'cell12'], ['cell21', 'cell22']],
|
|
298
298
|
'<table><tr><th>header1</th><th>header2</th></tr><tr><td>cell11</td><td>cell12</td></tr><tr><td>cell21</td><td>cell22</td></tr></table>',
|
|
299
299
|
);
|
|
300
|
-
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('createTable - handles colspans', () => {
|
|
301
303
|
test(
|
|
302
304
|
[['header1'], ['cell11', 'cell12'], ['cell21', 'cell22']],
|
|
303
|
-
'<table><tr><th>header1</th></tr><tr><td>cell11</td><td>cell12</td></tr><tr><td>cell21</td><td>cell22</td></tr></table>',
|
|
305
|
+
'<table><tr><th colspan="2">header1</th></tr><tr><td>cell11</td><td>cell12</td></tr><tr><td>cell21</td><td>cell22</td></tr></table>',
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
test(
|
|
309
|
+
[['header1'], ['cell11', 'cell12', 'cell13', 'cell14']],
|
|
310
|
+
'<table><tr><th colspan="4">header1</th></tr><tr><td>cell11</td><td>cell12</td><td>cell13</td><td>cell14</td></tr></table>',
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
test(
|
|
314
|
+
[['header1', 'header2'], ['cell11', 'cell12', 'cell13', 'cell14']],
|
|
315
|
+
'<table><tr><th>header1</th><th colspan="3">header2</th></tr><tr><td>cell11</td><td>cell12</td><td>cell13</td><td>cell14</td></tr></table>',
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
// messy table
|
|
319
|
+
test(
|
|
320
|
+
[['header1', 'header2'], ['cell11', 'cell12', 'cell13', 'cell14'], ['cell22'], ['cell31', 'cell32', 'cell33']],
|
|
321
|
+
'<table><tr><th>header1</th><th colspan="3">header2</th></tr><tr><td>cell11</td><td>cell12</td><td>cell13</td><td>cell14</td></tr><tr><td colspan="4">cell22</td></tr><tr><td>cell31</td><td>cell32</td><td colspan="2">cell33</td></tr></table>',
|
|
304
322
|
);
|
|
305
323
|
});
|
|
306
324
|
|
|
@@ -318,8 +336,8 @@ describe('DOM#createTable tests', () => {
|
|
|
318
336
|
'<table><tr><th>header</th></tr><tr><td><img src="https://www.sample.com/image.jpeg"></td></tr></table>',
|
|
319
337
|
);
|
|
320
338
|
test(
|
|
321
|
-
[['
|
|
322
|
-
'<table><tr><th>
|
|
339
|
+
[['header1', 'header2', 'header3'], [img, a, 'some text']],
|
|
340
|
+
'<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><img src="https://www.sample.com/image.jpeg"></td><td><a href="https://www.sample.com/"></a></td><td>some text</td></tr></table>',
|
|
323
341
|
);
|
|
324
342
|
test(
|
|
325
343
|
[['header'], [[img, a, 'some text']]],
|