1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
import {stitchArrays} from '#sugar';
export default {
contentDependencies: ['generateGridActionLinks'],
extraDependencies: ['html', 'language'],
relations(relation) {
return {
actionLinks: relation('generateGridActionLinks'),
};
},
slots: {
images: {validate: v => v.strictArrayOf(v.isHTML)},
links: {validate: v => v.strictArrayOf(v.isHTML)},
names: {validate: v => v.strictArrayOf(v.isHTML)},
info: {validate: v => v.strictArrayOf(v.isHTML)},
// Differentiating from sparseArrayOf here - this list of classes should
// have the same length as the items above, i.e. nulls aren't going to be
// filtered out of it, but it is okay to *include* null (standing in for
// no classes for this grid item).
classes: {
validate: v =>
v.strictArrayOf(
v.optional(
v.oneOf(
v.isArray,
v.isString))),
},
lazy: {validate: v => v.oneOf(v.isWholeNumber, v.isBoolean)},
actionLinks: {validate: v => v.sparseArrayOf(v.isHTML)},
},
generate(relations, slots, {html, language}) {
return (
html.tag('div', {class: 'grid-listing'}, [
stitchArrays({
classOrClasses: slots.classes,
image: slots.images,
link: slots.links,
name: slots.names,
info: slots.info,
}).map(({classOrClasses, image, link, name, info}, index) =>
link.slots({
attributes: {
class: [
'grid-item',
'box',
...
(Array.isArray(classOrClasses)
? classOrClasses
: typeof classOrClasses === 'string'
? [classOrClasses]
: []),
],
},
content: [
image.slots({
thumb: 'medium',
square: true,
lazy:
(typeof slots.lazy === 'number'
? index >= slots.lazy
: typeof slots.lazy === 'boolean'
? slots.lazy
: false),
}),
html.tag('span', {[html.onlyIfContent]: true},
language.sanitize(name)),
html.tag('span', {[html.onlyIfContent]: true},
language.sanitize(info)),
],
})),
relations.actionLinks
.slot('actionLinks', slots.actionLinks),
]));
},
};
|