@contrail/document-generation
Advanced tools
Comparing version 2.0.51 to 2.0.52
@@ -18,3 +18,3 @@ "use strict"; | ||
if (!template.componentTemplate) { | ||
console.warn('WARN: component template is null generateComponentGrid'); | ||
console.warn('WARN: component template is null in generateComponentGrid'); | ||
return []; | ||
@@ -30,9 +30,21 @@ } | ||
const componentTemplate = gridTemplate.componentTemplate; | ||
const componentPosition = util_1.ObjectUtil.cloneDeep(startingPosition); | ||
const componentSize = this.getComponentSize(data, gridTemplate); | ||
const componentPadding = gridTemplate.componentPadding || 20; | ||
const alignment = template.alignment || 'center'; | ||
const maxComponentHeight = (idealSize.height - template.gridDimensions.rows * componentPadding * 2) / template.gridDimensions.rows; | ||
componentPosition.x += componentPadding; | ||
componentPosition.y += componentPadding; | ||
for (let row = 0; row < gridTemplate.gridDimensions.rows; row++) { | ||
const remainingItems = data.length - dataIndex; | ||
const itemsInRow = Math.min(remainingItems, gridTemplate.gridDimensions.cols); | ||
const rowWidth = itemsInRow * (componentSize.width + componentPadding * 2) - componentPadding * 2; | ||
let rowStartX = startingPosition.x + componentPadding; | ||
if (alignment === 'center') { | ||
rowStartX += (idealSize.width - rowWidth) / 2; | ||
} | ||
else if (alignment === 'right') { | ||
rowStartX += idealSize.width - rowWidth - componentPadding; | ||
} | ||
let componentPosition = { | ||
x: rowStartX, | ||
y: startingPosition.y + row * (maxComponentHeight + componentPadding * 2), | ||
}; | ||
for (let col = 0; col < gridTemplate.gridDimensions.cols; col++) { | ||
@@ -42,6 +54,6 @@ if (dataIndex >= data.length) { | ||
} | ||
let dataObj = data[dataIndex]; | ||
const dataObj = data[dataIndex]; | ||
dataObj.viewable = dataObj.item; | ||
const position = util_1.ObjectUtil.cloneDeep(componentPosition); | ||
let component = component_generator_1.ComponentGenerator.generateComponent(dataObj, { position }, componentTemplate); | ||
const component = component_generator_1.ComponentGenerator.generateComponent(dataObj, { position }, componentTemplate); | ||
elements.push(component); | ||
@@ -51,4 +63,2 @@ dataIndex++; | ||
} | ||
componentPosition.y += Math.min(componentSize.height, maxComponentHeight) + componentPadding * 2; | ||
componentPosition.x = startingPosition.x + componentPadding; | ||
} | ||
@@ -55,0 +65,0 @@ return elements; |
@@ -54,2 +54,3 @@ import { DataGroupStructure } from '@contrail/data-grouping'; | ||
}; | ||
alignment?: 'left' | 'center' | 'right'; | ||
} | ||
@@ -56,0 +57,0 @@ export interface ComponentTemplate { |
{ | ||
"name": "@contrail/document-generation", | ||
"version": "2.0.51", | ||
"version": "2.0.52", | ||
"description": "Utilities for automatic generation of documents.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1107241
28137
3