@contrail/document-generation 2.0.51 → 2.0.52
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.
|
@@ -15,7 +15,7 @@ class ComponentGridGenerator {
|
|
|
15
15
|
return [];
|
|
16
16
|
}
|
|
17
17
|
if (!template.componentTemplate) {
|
|
18
|
-
console.warn('WARN: component template is null generateComponentGrid');
|
|
18
|
+
console.warn('WARN: component template is null in generateComponentGrid');
|
|
19
19
|
return [];
|
|
20
20
|
}
|
|
21
21
|
const elements = [];
|
|
@@ -26,27 +26,37 @@ class ComponentGridGenerator {
|
|
|
26
26
|
gridTemplate = this.adjustComponentTemplate(data, idealSize, template);
|
|
27
27
|
}
|
|
28
28
|
const componentTemplate = gridTemplate.componentTemplate;
|
|
29
|
-
const componentPosition = util_1.ObjectUtil.cloneDeep(startingPosition);
|
|
30
29
|
const componentSize = this.getComponentSize(data, gridTemplate);
|
|
31
30
|
const componentPadding = gridTemplate.componentPadding || 20;
|
|
31
|
+
const alignment = template.alignment || 'center';
|
|
32
32
|
const maxComponentHeight = (idealSize.height - template.gridDimensions.rows * componentPadding * 2) / template.gridDimensions.rows;
|
|
33
|
-
componentPosition.x += componentPadding;
|
|
34
|
-
componentPosition.y += componentPadding;
|
|
35
33
|
for (let row = 0; row < gridTemplate.gridDimensions.rows; row++) {
|
|
34
|
+
const remainingItems = data.length - dataIndex;
|
|
35
|
+
const itemsInRow = Math.min(remainingItems, gridTemplate.gridDimensions.cols);
|
|
36
|
+
const rowWidth = itemsInRow * (componentSize.width + componentPadding * 2) - componentPadding * 2;
|
|
37
|
+
let rowStartX = startingPosition.x + componentPadding;
|
|
38
|
+
if (alignment === 'center') {
|
|
39
|
+
rowStartX += (idealSize.width - rowWidth) / 2;
|
|
40
|
+
}
|
|
41
|
+
else if (alignment === 'right') {
|
|
42
|
+
rowStartX += idealSize.width - rowWidth - componentPadding;
|
|
43
|
+
}
|
|
44
|
+
let componentPosition = {
|
|
45
|
+
x: rowStartX,
|
|
46
|
+
y: startingPosition.y + row * (maxComponentHeight + componentPadding * 2),
|
|
47
|
+
};
|
|
36
48
|
for (let col = 0; col < gridTemplate.gridDimensions.cols; col++) {
|
|
37
49
|
if (dataIndex >= data.length) {
|
|
38
50
|
continue;
|
|
39
51
|
}
|
|
40
|
-
|
|
52
|
+
const dataObj = data[dataIndex];
|
|
41
53
|
dataObj.viewable = dataObj.item;
|
|
42
54
|
const position = util_1.ObjectUtil.cloneDeep(componentPosition);
|
|
43
|
-
|
|
55
|
+
const component = component_generator_1.ComponentGenerator.generateComponent(dataObj, { position }, componentTemplate);
|
|
44
56
|
elements.push(component);
|
|
45
57
|
dataIndex++;
|
|
46
58
|
componentPosition.x += componentSize.width + componentPadding * 2;
|
|
47
59
|
}
|
|
48
|
-
componentPosition.y += Math.min(componentSize.height, maxComponentHeight) + componentPadding * 2;
|
|
49
|
-
componentPosition.x = startingPosition.x + componentPadding;
|
|
50
60
|
}
|
|
51
61
|
return elements;
|
|
52
62
|
}
|
package/lib/interfaces.d.ts
CHANGED