Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion blocks/fragment/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ export default async function decorate(block) {
if (fragment) {
const fragmentSection = fragment.querySelector(':scope .section');
if (fragmentSection) {
block.closest('.section').classList.add(...fragmentSection.classList);
const mainSection = block.closest('.section');
mainSection.classList.add(...fragmentSection.classList);
// destination file metadata overrides the fragment metadata in case of conflicts
Comment thread
rofe marked this conversation as resolved.
Outdated
const mergedDataset = { ...fragmentSection.dataset, ...mainSection.dataset };
Object.keys(mergedDataset).forEach((key) => {
mainSection.dataset[key] = mergedDataset[key];
});
block.closest('.fragment-wrapper').replaceWith(...fragmentSection.childNodes);
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/blocks/fragment/fragment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ describe('Fragment block', () => {
await sectionLoaded(section);
expect(section.textContent.trim()).to.equal('Hello world!');
expect(section.classList.contains('example-container')).to.be.true;
expect(section.classList.contains('example-style')).to.be.true;
expect(section.dataset.exampleData).to.equals('Example Value');
expect(document.querySelectorAll('.fragment').length).to.equal(1);
});
});
10 changes: 10 additions & 0 deletions test/blocks/fragment/test.plain.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@
</div>
</div>
</div>
<div class="section-metadata">
<div>
<div>Style</div>
<div>Example Style</div>
</div>
<div>
<div>Example Data</div>
<div>Example Value</div>
</div>
</div>
</div>