From ba29e8ac5457edd47408ad341622d49cb3867149 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 14 Oct 2024 10:04:38 -0600 Subject: [PATCH 01/19] style wrappers when no nested elements --- libs/utils/decorate.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 0482e40505..4117c3d3b1 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -77,13 +77,19 @@ export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { decorateIconArea(el); } } + const bodyDefault = `body-${config[1]}`; const emptyEls = el.querySelectorAll('p:not([class]), ul:not([class]), ol:not([class])'); if (emptyEls.length) { - emptyEls.forEach((p) => p.classList.add(`body-${config[1]}`)); + emptyEls.forEach((p) => p.classList.add(bodyDefault)); } else { - [...el.querySelectorAll('div:not([class])')] - .filter((emptyDivs) => emptyDivs.textContent.trim() !== '') - .forEach((text) => text.classList.add(`body-${config[1]}`)); + const emptyDivs = el.querySelectorAll('div:not([class])'); + if (emptyDivs.length) { + [...emptyDivs].filter((div) => div.textContent.trim() !== '').forEach((text) => { + text.classList.add(bodyDefault); + }); + } else if (!el.classList.length) { + el.classList.add(bodyDefault); + } } } const buttonSize = config.length > 3 ? `button-${config[3]}` : ''; From 382b372f0463ed2758dc4b4402171a63ef4f740d Mon Sep 17 00:00:00 2001 From: Sartxi Date: Thu, 17 Oct 2024 16:31:00 -0600 Subject: [PATCH 02/19] better logic and check for text nodes in elements --- libs/utils/decorate.js | 19 ++++++------------- libs/utils/utils.js | 8 ++++++++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 4117c3d3b1..e0acdac87f 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -1,4 +1,4 @@ -import { createTag, loadStyle, getConfig, createIntersectionObserver } from './utils.js'; +import { createTag, loadStyle, getConfig, createIntersectionObserver, elementHasText } from './utils.js'; const { miloLibs, codeRoot } = getConfig(); @@ -77,19 +77,12 @@ export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { decorateIconArea(el); } } - const bodyDefault = `body-${config[1]}`; - const emptyEls = el.querySelectorAll('p:not([class]), ul:not([class]), ol:not([class])'); + const bodyStyle = `body-${config[1]}`; + const emptyEls = el.querySelectorAll('p:not([class]), ul:not([class]), ol:not([class], div:not([class]))'); if (emptyEls.length) { - emptyEls.forEach((p) => p.classList.add(bodyDefault)); - } else { - const emptyDivs = el.querySelectorAll('div:not([class])'); - if (emptyDivs.length) { - [...emptyDivs].filter((div) => div.textContent.trim() !== '').forEach((text) => { - text.classList.add(bodyDefault); - }); - } else if (!el.classList.length) { - el.classList.add(bodyDefault); - } + [...emptyEls].filter(elementHasText).forEach((e) => e.classList.add(bodyStyle)); + } else if (!el.classList.length && elementHasText(el)) { + el.classList.add(bodyStyle); } } const buttonSize = config.length > 3 ? `button-${config[3]}` : ''; diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 11e4548bd5..81ce767420 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -260,6 +260,14 @@ export function isInTextNode(node) { return node.parentElement.firstChild.nodeType === Node.TEXT_NODE; } +export function elementHasText(el) { + return !![...el.childNodes].filter((node) => { + const { nodeType, textContent, innerText } = node; + if (nodeType === Node.ELEMENT_NODE) return innerText.trim() !== ''; + return nodeType === Node.TEXT_NODE && textContent.trim() !== ''; + }).length; +} + export function createTag(tag, attributes, html, options = {}) { const el = document.createElement(tag); if (html) { From 3d83484a1ee44bddb8d32fd1b18d9d727d6f97e0 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Fri, 18 Oct 2024 10:16:58 -0600 Subject: [PATCH 03/19] dialing in util --- libs/utils/decorate.js | 6 +++--- libs/utils/utils.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index e0acdac87f..16bf5508b2 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -1,4 +1,4 @@ -import { createTag, loadStyle, getConfig, createIntersectionObserver, elementHasText } from './utils.js'; +import { createTag, loadStyle, getConfig, createIntersectionObserver, elContainsText } from './utils.js'; const { miloLibs, codeRoot } = getConfig(); @@ -80,8 +80,8 @@ export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { const bodyStyle = `body-${config[1]}`; const emptyEls = el.querySelectorAll('p:not([class]), ul:not([class]), ol:not([class], div:not([class]))'); if (emptyEls.length) { - [...emptyEls].filter(elementHasText).forEach((e) => e.classList.add(bodyStyle)); - } else if (!el.classList.length && elementHasText(el)) { + [...emptyEls].filter(elContainsText).forEach((e) => e.classList.add(bodyStyle)); + } else if (!el.classList.length && elContainsText(el)) { el.classList.add(bodyStyle); } } diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 81ce767420..02f78f83c0 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -260,9 +260,9 @@ export function isInTextNode(node) { return node.parentElement.firstChild.nodeType === Node.TEXT_NODE; } -export function elementHasText(el) { - return !![...el.childNodes].filter((node) => { - const { nodeType, textContent, innerText } = node; +export function elContainsText(el) { + return !![...el.childNodes].filter((childNode) => { + const { innerText, nodeType, textContent } = childNode; if (nodeType === Node.ELEMENT_NODE) return innerText.trim() !== ''; return nodeType === Node.TEXT_NODE && textContent.trim() !== ''; }).length; From 3db81be90953fafaa67712270f0e0130e1c4d044 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 28 Oct 2024 09:46:13 -0600 Subject: [PATCH 04/19] keep contains text function in decorate js --- libs/utils/decorate.js | 10 +++++++++- libs/utils/utils.js | 8 -------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 16bf5508b2..c225e38a80 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -1,4 +1,4 @@ -import { createTag, loadStyle, getConfig, createIntersectionObserver, elContainsText } from './utils.js'; +import { createTag, loadStyle, getConfig, createIntersectionObserver } from './utils.js'; const { miloLibs, codeRoot } = getConfig(); @@ -65,6 +65,14 @@ export function decorateIconArea(el) { }); } +function elContainsText(el) { + return !![...el.childNodes].filter((childNode) => { + const { innerText, nodeType, textContent } = childNode; + if (nodeType === Node.ELEMENT_NODE) return innerText.trim() !== ''; + return nodeType === Node.TEXT_NODE && textContent.trim() !== ''; + }).length; +} + export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { let headings = el.querySelectorAll('h1, h2, h3, h4, h5, h6'); if (!el.classList.contains('default')) { diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 02f78f83c0..11e4548bd5 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -260,14 +260,6 @@ export function isInTextNode(node) { return node.parentElement.firstChild.nodeType === Node.TEXT_NODE; } -export function elContainsText(el) { - return !![...el.childNodes].filter((childNode) => { - const { innerText, nodeType, textContent } = childNode; - if (nodeType === Node.ELEMENT_NODE) return innerText.trim() !== ''; - return nodeType === Node.TEXT_NODE && textContent.trim() !== ''; - }).length; -} - export function createTag(tag, attributes, html, options = {}) { const el = document.createElement(tag); if (html) { From bd03de972a327c5d33b125bb931d1e2a22860bdf Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 28 Oct 2024 11:09:06 -0600 Subject: [PATCH 05/19] use is magic in emtpy elements selector --- libs/utils/decorate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 4ba35aaf55..a9a6947786 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -86,7 +86,7 @@ export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { } } const bodyStyle = `body-${config[1]}`; - const emptyEls = el.querySelectorAll('p:not([class]), ul:not([class]), ol:not([class], div:not([class]))'); + const emptyEls = el.querySelectorAll(':is(p, ul, ol, div):not([class])'); if (emptyEls.length) { [...emptyEls].filter(elContainsText).forEach((e) => e.classList.add(bodyStyle)); } else if (!el.classList.length && elContainsText(el)) { From 971bfc00559ed09e8ec9ae53e0ae046476ea561f Mon Sep 17 00:00:00 2001 From: Sartxi Date: Tue, 29 Oct 2024 09:30:09 -0600 Subject: [PATCH 06/19] simplify el contains text function --- libs/utils/decorate.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index a9a6947786..ef5fae2a3f 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -66,11 +66,10 @@ export function decorateIconArea(el) { } function elContainsText(el) { - return !![...el.childNodes].filter((childNode) => { - const { innerText, nodeType, textContent } = childNode; - if (nodeType === Node.ELEMENT_NODE) return innerText.trim() !== ''; - return nodeType === Node.TEXT_NODE && textContent.trim() !== ''; - }).length; + return [...el.childNodes].some(({ nodeType, innerText, textContent }) => ( + (nodeType === Node.ELEMENT_NODE && innerText.trim() !== '') + || (nodeType === Node.TEXT_NODE && textContent.trim() !== '') + )); } export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { From 4cd0f18408a27b6b983e21bd7ef0eab7b5ed0b62 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 4 Nov 2024 11:47:15 -0700 Subject: [PATCH 07/19] early return in block text decorator --- libs/utils/decorate.js | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index ef5fae2a3f..1dbc3f667f 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -73,6 +73,7 @@ function elContainsText(el) { } export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { + if (!el) return; let headings = el.querySelectorAll('h1, h2, h3, h4, h5, h6'); if (!el.classList.contains('default')) { if (headings) { From 49261eea95bfa30daaa4a34278a84d48d2a8f895 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 4 Nov 2024 11:59:26 -0700 Subject: [PATCH 08/19] codecov on decorate block text --- test/blocks/text/mocks/body.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/blocks/text/mocks/body.html b/test/blocks/text/mocks/body.html index bfb7a5a52f..3c338727ab 100644 --- a/test/blocks/text/mocks/body.html +++ b/test/blocks/text/mocks/body.html @@ -334,3 +334,16 @@

Text – Full-Width, Medium

+
+
+
+
XXS Body - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+
+
+ +
From 8e62a11814a1759011270abf4f0c02d6ac7bb061 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 4 Nov 2024 17:31:06 -0700 Subject: [PATCH 09/19] adjust decorate and marquee anchors to hopefully pass tests --- libs/blocks/marquee-anchors/marquee-anchors.js | 2 +- libs/utils/decorate.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/libs/blocks/marquee-anchors/marquee-anchors.js b/libs/blocks/marquee-anchors/marquee-anchors.js index 7594d1b02b..0edd6eaa0d 100644 --- a/libs/blocks/marquee-anchors/marquee-anchors.js +++ b/libs/blocks/marquee-anchors/marquee-anchors.js @@ -78,7 +78,7 @@ export default function init(el) { const emptyLinkRows = links.querySelectorAll(':scope > div:not([class])'); if (emptyLinkRows[0]) emptyLinkRows[0].classList.add('links-header'); if (emptyLinkRows[1]) emptyLinkRows[1].classList.add('links-footer', 'body-s'); - decorateBlockText(emptyLinkRows[0], blockTypeSizes.default.xsmall); + if (emptyLinkRows[0]) decorateBlockText(emptyLinkRows[0], blockTypeSizes.default.xsmall); const anchors = el.querySelectorAll('.anchor-link'); if (anchors.length) decorateAnchors(anchors); diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 1dbc3f667f..36e23dd055 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -73,9 +73,8 @@ function elContainsText(el) { } export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { - if (!el) return; - let headings = el.querySelectorAll('h1, h2, h3, h4, h5, h6'); if (!el.classList.contains('default')) { + let headings = el?.querySelectorAll('h1, h2, h3, h4, h5, h6'); if (headings) { if (type === 'hasDetailHeading' && headings.length > 1) headings = [...headings].splice(1); headings.forEach((h) => h.classList.add(`heading-${config[0]}`)); @@ -86,7 +85,7 @@ export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { } } const bodyStyle = `body-${config[1]}`; - const emptyEls = el.querySelectorAll(':is(p, ul, ol, div):not([class])'); + const emptyEls = el?.querySelectorAll(':is(p, ul, ol, div):not([class])'); if (emptyEls.length) { [...emptyEls].filter(elContainsText).forEach((e) => e.classList.add(bodyStyle)); } else if (!el.classList.length && elContainsText(el)) { From 46dad6cd8cfe1361b25c075f1fbf945e194a9905 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 14 Oct 2024 10:04:38 -0600 Subject: [PATCH 10/19] style wrappers when no nested elements --- libs/utils/decorate.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index d794ba14e9..54a1a6e4d0 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -77,13 +77,19 @@ export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { decorateIconArea(el); } } + const bodyDefault = `body-${config[1]}`; const emptyEls = el.querySelectorAll('p:not([class]), ul:not([class]), ol:not([class])'); if (emptyEls.length) { - emptyEls.forEach((p) => p.classList.add(`body-${config[1]}`)); + emptyEls.forEach((p) => p.classList.add(bodyDefault)); } else { - [...el.querySelectorAll('div:not([class])')] - .filter((emptyDivs) => emptyDivs.textContent.trim() !== '') - .forEach((text) => text.classList.add(`body-${config[1]}`)); + const emptyDivs = el.querySelectorAll('div:not([class])'); + if (emptyDivs.length) { + [...emptyDivs].filter((div) => div.textContent.trim() !== '').forEach((text) => { + text.classList.add(bodyDefault); + }); + } else if (!el.classList.length) { + el.classList.add(bodyDefault); + } } } const buttonSize = config.length > 3 ? `button-${config[3]}` : ''; From d6219489a1956a7db9c58c099c4edac44982e7f7 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Thu, 17 Oct 2024 16:31:00 -0600 Subject: [PATCH 11/19] better logic and check for text nodes in elements --- libs/utils/decorate.js | 19 ++++++------------- libs/utils/utils.js | 8 ++++++++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 54a1a6e4d0..9529981ea0 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -1,4 +1,4 @@ -import { createTag, loadStyle, getConfig, createIntersectionObserver } from './utils.js'; +import { createTag, loadStyle, getConfig, createIntersectionObserver, elementHasText } from './utils.js'; const { miloLibs, codeRoot } = getConfig(); @@ -77,19 +77,12 @@ export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { decorateIconArea(el); } } - const bodyDefault = `body-${config[1]}`; - const emptyEls = el.querySelectorAll('p:not([class]), ul:not([class]), ol:not([class])'); + const bodyStyle = `body-${config[1]}`; + const emptyEls = el.querySelectorAll('p:not([class]), ul:not([class]), ol:not([class], div:not([class]))'); if (emptyEls.length) { - emptyEls.forEach((p) => p.classList.add(bodyDefault)); - } else { - const emptyDivs = el.querySelectorAll('div:not([class])'); - if (emptyDivs.length) { - [...emptyDivs].filter((div) => div.textContent.trim() !== '').forEach((text) => { - text.classList.add(bodyDefault); - }); - } else if (!el.classList.length) { - el.classList.add(bodyDefault); - } + [...emptyEls].filter(elementHasText).forEach((e) => e.classList.add(bodyStyle)); + } else if (!el.classList.length && elementHasText(el)) { + el.classList.add(bodyStyle); } } const buttonSize = config.length > 3 ? `button-${config[3]}` : ''; diff --git a/libs/utils/utils.js b/libs/utils/utils.js index bfa70f2e7d..238a801110 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -261,6 +261,14 @@ export function isInTextNode(node) { return node.parentElement.firstChild.nodeType === Node.TEXT_NODE; } +export function elementHasText(el) { + return !![...el.childNodes].filter((node) => { + const { nodeType, textContent, innerText } = node; + if (nodeType === Node.ELEMENT_NODE) return innerText.trim() !== ''; + return nodeType === Node.TEXT_NODE && textContent.trim() !== ''; + }).length; +} + export function createTag(tag, attributes, html, options = {}) { const el = document.createElement(tag); if (html) { From 405a9a8b8f191ff316694ccce9fa2a5a8fc61ed2 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Fri, 18 Oct 2024 10:16:58 -0600 Subject: [PATCH 12/19] dialing in util --- libs/utils/decorate.js | 6 +++--- libs/utils/utils.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 9529981ea0..92ea44ddd6 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -1,4 +1,4 @@ -import { createTag, loadStyle, getConfig, createIntersectionObserver, elementHasText } from './utils.js'; +import { createTag, loadStyle, getConfig, createIntersectionObserver, elContainsText } from './utils.js'; const { miloLibs, codeRoot } = getConfig(); @@ -80,8 +80,8 @@ export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { const bodyStyle = `body-${config[1]}`; const emptyEls = el.querySelectorAll('p:not([class]), ul:not([class]), ol:not([class], div:not([class]))'); if (emptyEls.length) { - [...emptyEls].filter(elementHasText).forEach((e) => e.classList.add(bodyStyle)); - } else if (!el.classList.length && elementHasText(el)) { + [...emptyEls].filter(elContainsText).forEach((e) => e.classList.add(bodyStyle)); + } else if (!el.classList.length && elContainsText(el)) { el.classList.add(bodyStyle); } } diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 238a801110..6a7968fa34 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -261,9 +261,9 @@ export function isInTextNode(node) { return node.parentElement.firstChild.nodeType === Node.TEXT_NODE; } -export function elementHasText(el) { - return !![...el.childNodes].filter((node) => { - const { nodeType, textContent, innerText } = node; +export function elContainsText(el) { + return !![...el.childNodes].filter((childNode) => { + const { innerText, nodeType, textContent } = childNode; if (nodeType === Node.ELEMENT_NODE) return innerText.trim() !== ''; return nodeType === Node.TEXT_NODE && textContent.trim() !== ''; }).length; From c649b973d28f52c15845774974a2822143f79d4c Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 28 Oct 2024 09:46:13 -0600 Subject: [PATCH 13/19] keep contains text function in decorate js --- libs/utils/decorate.js | 10 +++++++++- libs/utils/utils.js | 8 -------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 92ea44ddd6..4ba35aaf55 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -1,4 +1,4 @@ -import { createTag, loadStyle, getConfig, createIntersectionObserver, elContainsText } from './utils.js'; +import { createTag, loadStyle, getConfig, createIntersectionObserver } from './utils.js'; const { miloLibs, codeRoot } = getConfig(); @@ -65,6 +65,14 @@ export function decorateIconArea(el) { }); } +function elContainsText(el) { + return !![...el.childNodes].filter((childNode) => { + const { innerText, nodeType, textContent } = childNode; + if (nodeType === Node.ELEMENT_NODE) return innerText.trim() !== ''; + return nodeType === Node.TEXT_NODE && textContent.trim() !== ''; + }).length; +} + export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { let headings = el.querySelectorAll('h1, h2, h3, h4, h5, h6'); if (!el.classList.contains('default')) { diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 6a7968fa34..bfa70f2e7d 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -261,14 +261,6 @@ export function isInTextNode(node) { return node.parentElement.firstChild.nodeType === Node.TEXT_NODE; } -export function elContainsText(el) { - return !![...el.childNodes].filter((childNode) => { - const { innerText, nodeType, textContent } = childNode; - if (nodeType === Node.ELEMENT_NODE) return innerText.trim() !== ''; - return nodeType === Node.TEXT_NODE && textContent.trim() !== ''; - }).length; -} - export function createTag(tag, attributes, html, options = {}) { const el = document.createElement(tag); if (html) { From 3f268ef18859ebfdea467b2386f80860187d3808 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 28 Oct 2024 11:09:06 -0600 Subject: [PATCH 14/19] use is magic in emtpy elements selector --- libs/utils/decorate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 4ba35aaf55..a9a6947786 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -86,7 +86,7 @@ export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { } } const bodyStyle = `body-${config[1]}`; - const emptyEls = el.querySelectorAll('p:not([class]), ul:not([class]), ol:not([class], div:not([class]))'); + const emptyEls = el.querySelectorAll(':is(p, ul, ol, div):not([class])'); if (emptyEls.length) { [...emptyEls].filter(elContainsText).forEach((e) => e.classList.add(bodyStyle)); } else if (!el.classList.length && elContainsText(el)) { From b95e1cc866a993581bbd191c943b62132e4be161 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Tue, 29 Oct 2024 09:30:09 -0600 Subject: [PATCH 15/19] simplify el contains text function --- libs/utils/decorate.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index a9a6947786..ef5fae2a3f 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -66,11 +66,10 @@ export function decorateIconArea(el) { } function elContainsText(el) { - return !![...el.childNodes].filter((childNode) => { - const { innerText, nodeType, textContent } = childNode; - if (nodeType === Node.ELEMENT_NODE) return innerText.trim() !== ''; - return nodeType === Node.TEXT_NODE && textContent.trim() !== ''; - }).length; + return [...el.childNodes].some(({ nodeType, innerText, textContent }) => ( + (nodeType === Node.ELEMENT_NODE && innerText.trim() !== '') + || (nodeType === Node.TEXT_NODE && textContent.trim() !== '') + )); } export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { From 603fd46967f61232a3fa96653135f7f986cfd6c0 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 4 Nov 2024 11:47:15 -0700 Subject: [PATCH 16/19] early return in block text decorator --- libs/utils/decorate.js | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index ef5fae2a3f..1dbc3f667f 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -73,6 +73,7 @@ function elContainsText(el) { } export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { + if (!el) return; let headings = el.querySelectorAll('h1, h2, h3, h4, h5, h6'); if (!el.classList.contains('default')) { if (headings) { From a8061bc68e69ea19514e9643d5ddac096759bd33 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 4 Nov 2024 11:59:26 -0700 Subject: [PATCH 17/19] codecov on decorate block text --- test/blocks/text/mocks/body.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/blocks/text/mocks/body.html b/test/blocks/text/mocks/body.html index bfb7a5a52f..3c338727ab 100644 --- a/test/blocks/text/mocks/body.html +++ b/test/blocks/text/mocks/body.html @@ -334,3 +334,16 @@

Text – Full-Width, Medium

+
+
+
+
XXS Body - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+
+
+ +
From 2cbb145678e9d075ee5efaf675eec925d03cd529 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 4 Nov 2024 17:31:06 -0700 Subject: [PATCH 18/19] adjust decorate and marquee anchors to hopefully pass tests --- libs/blocks/marquee-anchors/marquee-anchors.js | 2 +- libs/utils/decorate.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/libs/blocks/marquee-anchors/marquee-anchors.js b/libs/blocks/marquee-anchors/marquee-anchors.js index 7594d1b02b..0edd6eaa0d 100644 --- a/libs/blocks/marquee-anchors/marquee-anchors.js +++ b/libs/blocks/marquee-anchors/marquee-anchors.js @@ -78,7 +78,7 @@ export default function init(el) { const emptyLinkRows = links.querySelectorAll(':scope > div:not([class])'); if (emptyLinkRows[0]) emptyLinkRows[0].classList.add('links-header'); if (emptyLinkRows[1]) emptyLinkRows[1].classList.add('links-footer', 'body-s'); - decorateBlockText(emptyLinkRows[0], blockTypeSizes.default.xsmall); + if (emptyLinkRows[0]) decorateBlockText(emptyLinkRows[0], blockTypeSizes.default.xsmall); const anchors = el.querySelectorAll('.anchor-link'); if (anchors.length) decorateAnchors(anchors); diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 1dbc3f667f..36e23dd055 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -73,9 +73,8 @@ function elContainsText(el) { } export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { - if (!el) return; - let headings = el.querySelectorAll('h1, h2, h3, h4, h5, h6'); if (!el.classList.contains('default')) { + let headings = el?.querySelectorAll('h1, h2, h3, h4, h5, h6'); if (headings) { if (type === 'hasDetailHeading' && headings.length > 1) headings = [...headings].splice(1); headings.forEach((h) => h.classList.add(`heading-${config[0]}`)); @@ -86,7 +85,7 @@ export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) { } } const bodyStyle = `body-${config[1]}`; - const emptyEls = el.querySelectorAll(':is(p, ul, ol, div):not([class])'); + const emptyEls = el?.querySelectorAll(':is(p, ul, ol, div):not([class])'); if (emptyEls.length) { [...emptyEls].filter(elContainsText).forEach((e) => e.classList.add(bodyStyle)); } else if (!el.classList.length && elContainsText(el)) { From 6bfb3ce85cd466e66e1f03cf9c9b9da846fe5a06 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Wed, 6 Nov 2024 10:14:32 -0700 Subject: [PATCH 19/19] fix marquee anchors for nala --- libs/blocks/marquee-anchors/marquee-anchors.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libs/blocks/marquee-anchors/marquee-anchors.js b/libs/blocks/marquee-anchors/marquee-anchors.js index 0edd6eaa0d..8f66bc7817 100644 --- a/libs/blocks/marquee-anchors/marquee-anchors.js +++ b/libs/blocks/marquee-anchors/marquee-anchors.js @@ -54,11 +54,11 @@ export default function init(el) { decorateBlockText(copy, blockTypeSizes.default[size]); const links = createTag('div', { class: 'links' }, list); const foreground = createTag('div', { class: 'foreground' }, copy); - decorateBlockText(links, blockTypeSizes.default.xsmall); foreground.append(links); el.append(foreground); - [...list].forEach((i) => { + [...list].forEach((i, index) => { + decorateBlockText(i, blockTypeSizes.default.xsmall); const aTag = i.querySelector('a'); if (aTag?.textContent.charAt(0) === '#') { const content = i.querySelector(':scope > div'); @@ -73,12 +73,10 @@ export default function init(el) { } else { aTag.classList.add('external'); } + } else { + i.classList.add(`links-${index === 0 ? 'header' : 'footer'}`); } }); - const emptyLinkRows = links.querySelectorAll(':scope > div:not([class])'); - if (emptyLinkRows[0]) emptyLinkRows[0].classList.add('links-header'); - if (emptyLinkRows[1]) emptyLinkRows[1].classList.add('links-footer', 'body-s'); - if (emptyLinkRows[0]) decorateBlockText(emptyLinkRows[0], blockTypeSizes.default.xsmall); const anchors = el.querySelectorAll('.anchor-link'); if (anchors.length) decorateAnchors(anchors);