@asd20/ui-next 2.0.28 → 2.0.29
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
CHANGED
package/package.json
CHANGED
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
import Asd20BodyAccordion from '../../molecules/Asd20BodyAccordion'
|
|
40
40
|
import Asd20TableauEmbed from '../../molecules/Asd20TableauEmbed'
|
|
41
41
|
import { navigateInternalHref } from '../../../helpers/linkPolicy'
|
|
42
|
+
import { applyRichListColumnExceptions } from '../../../helpers/richBodyListColumns'
|
|
42
43
|
|
|
43
44
|
const BODY_BLOCK_PLACEHOLDER_PATTERN =
|
|
44
45
|
/<div\b(?=[^>]*\bdata-cc-block=(['"])([^'"]+)\1)(?=[^>]*\bdata-block-id=(['"])([^'"]+)\3)[^>]*><\/div>/gi
|
|
@@ -146,9 +147,17 @@ export default {
|
|
|
146
147
|
|
|
147
148
|
mounted() {
|
|
148
149
|
this.hasMounted = true
|
|
150
|
+
this.applyListColumnExceptions()
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
updated() {
|
|
154
|
+
this.applyListColumnExceptions()
|
|
149
155
|
},
|
|
150
156
|
|
|
151
157
|
methods: {
|
|
158
|
+
applyListColumnExceptions() {
|
|
159
|
+
applyRichListColumnExceptions(this.$el)
|
|
160
|
+
},
|
|
152
161
|
onContentClick(event) {
|
|
153
162
|
const anchor = event.target?.closest?.('a')
|
|
154
163
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export const SINGLE_COLUMN_RICH_LIST_CLASS = 'asd20-rich-list--single-column'
|
|
2
|
+
export const MULTI_COLUMN_LIST_ITEM_THRESHOLD = 20
|
|
3
|
+
export const SIGNIFICANT_LIST_ITEM_TEXT_THRESHOLD = 120
|
|
4
|
+
|
|
5
|
+
const COMPLEX_DIRECT_CHILD_SELECTOR =
|
|
6
|
+
'ul, ol, dl, blockquote, pre, table, figure, h1, h2, h3, h4, h5, h6'
|
|
7
|
+
|
|
8
|
+
function isDomElement(value) {
|
|
9
|
+
return typeof Element !== 'undefined' && value instanceof Element
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function normalizeTextContent(value) {
|
|
13
|
+
return value.replace(/\s+/g, ' ').trim()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function isSignificantRichListItem(listItem) {
|
|
17
|
+
if (!isDomElement(listItem)) return false
|
|
18
|
+
|
|
19
|
+
if (listItem.querySelector(COMPLEX_DIRECT_CHILD_SELECTOR)) return true
|
|
20
|
+
if (listItem.children.length > 1) return true
|
|
21
|
+
if (listItem.querySelectorAll('br').length >= 2) return true
|
|
22
|
+
|
|
23
|
+
const textContent = normalizeTextContent(listItem.textContent || '')
|
|
24
|
+
return textContent.length >= SIGNIFICANT_LIST_ITEM_TEXT_THRESHOLD
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function shouldPreventRichListColumns(listElement) {
|
|
28
|
+
if (!isDomElement(listElement)) return false
|
|
29
|
+
|
|
30
|
+
const listItems = Array.from(listElement.children).filter(
|
|
31
|
+
child => child.tagName === 'LI'
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
if (listItems.length < MULTI_COLUMN_LIST_ITEM_THRESHOLD) return false
|
|
35
|
+
|
|
36
|
+
return listItems.some(isSignificantRichListItem)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function applyRichListColumnExceptions(rootElement) {
|
|
40
|
+
if (!isDomElement(rootElement)) return
|
|
41
|
+
|
|
42
|
+
rootElement.querySelectorAll('ul, ol').forEach(list => {
|
|
43
|
+
list.classList.toggle(
|
|
44
|
+
SINGLE_COLUMN_RICH_LIST_CLASS,
|
|
45
|
+
shouldPreventRichListColumns(list)
|
|
46
|
+
)
|
|
47
|
+
})
|
|
48
|
+
}
|