@contrail/document-generation 2.1.19 → 2.1.21
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/lib/board-document-generator.d.ts +23 -0
- package/lib/board-document-generator.js +241 -0
- package/lib/components/component-generator.d.ts +6 -0
- package/lib/components/component-generator.js +55 -0
- package/lib/components/component-grid-generator.d.ts +7 -0
- package/lib/components/component-grid-generator.js +102 -0
- package/lib/components/component-util.d.ts +5 -0
- package/lib/components/component-util.js +43 -0
- package/lib/document-generator.d.ts +6 -0
- package/lib/document-generator.js +11 -0
- package/lib/frames/frame-generator.d.ts +12 -0
- package/lib/frames/frame-generator.js +160 -0
- package/lib/frames/frame.d.ts +18 -0
- package/lib/frames/frame.js +71 -0
- package/lib/frames/index.d.ts +2 -0
- package/lib/frames/index.js +18 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +22 -0
- package/lib/info-panel/info-panel-generator.d.ts +6 -0
- package/lib/info-panel/info-panel-generator.js +56 -0
- package/lib/interfaces.d.ts +73 -0
- package/lib/interfaces.js +8 -0
- package/lib/scripts/test-board.d.ts +1 -0
- package/lib/scripts/test-board.js +230 -0
- package/lib/scripts/test-showcase.d.ts +1 -0
- package/lib/scripts/test-showcase.js +257 -0
- package/lib/showcase-frame-generator.d.ts +8 -0
- package/lib/showcase-frame-generator.js +44 -0
- package/lib/test-data.d.ts +72 -0
- package/lib/test-data.js +187 -0
- package/lib/util/document-dynamic-text-element-util.d.ts +9 -0
- package/lib/util/document-dynamic-text-element-util.js +61 -0
- package/lib/util/document-property-util.d.ts +9 -0
- package/lib/util/document-property-util.js +103 -0
- package/lib/util/document-text-element-util.d.ts +12 -0
- package/lib/util/document-text-element-util.js +148 -0
- package/lib/util/document-util.d.ts +8 -0
- package/lib/util/document-util.js +22 -0
- package/lib/util/index.d.ts +2 -0
- package/lib/util/index.js +18 -0
- package/lib/util/text-util.d.ts +4 -0
- package/lib/util/text-util.js +28 -0
- package/package.json +1 -1
- package/mocks/test-type-data.ts +0 -146
- package/testdocument.json +0 -25972
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DocumentElement, PositionDefinition } from '@contrail/documents';
|
|
2
|
+
import { DocumentGenerationOptions, DocumentTemplate, FrameDocumentTemplate } from './interfaces';
|
|
3
|
+
import { DataGroup } from '@contrail/data-grouping';
|
|
4
|
+
export declare class BoardDocumentGenerator {
|
|
5
|
+
static secondaryGroupPadding: number;
|
|
6
|
+
constructor();
|
|
7
|
+
static generateDocumentElements(options: DocumentGenerationOptions, typeMap: any): Array<DocumentElement>;
|
|
8
|
+
static adjustPositionBasedGroupHeaderSpan(currentPosition: PositionDefinition, template: DocumentTemplate, subGroup: DataGroup, totalDepth: number, currentDepth: number, containsSecondaryGroup: any): {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
};
|
|
12
|
+
static adjustPositionBasedOnGroupHeaderSize(currentPosition: PositionDefinition, template: DocumentTemplate): {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
};
|
|
16
|
+
static generateBoardGroupHeaders(group: DataGroup, template: DocumentTemplate, startingPosition: PositionDefinition, totalDepth: number, currentDepth: number, containsSecondaryGroup?: boolean): any[];
|
|
17
|
+
static generateBoardFrames(group: DataGroup, template: DocumentTemplate, frameTemplate: FrameDocumentTemplate, startingPosition: PositionDefinition, totalDepth: number, currentDepth: number, containsSecondaryGroup: boolean, frameTitle: string): any[];
|
|
18
|
+
static getGroupSpan(group: DataGroup, totalDepth: any, currentDepth: any, stopAtSecondary: any): number;
|
|
19
|
+
private static findDeepestSubgroups;
|
|
20
|
+
static generateFrameGroup(dataGroup: DataGroup, template: DocumentTemplate, frameTemplate: any, position: PositionDefinition, frameTitle: string): Array<DocumentElement>;
|
|
21
|
+
static generateBoardGroupHeader(dataGroup: DataGroup, template: DocumentTemplate, position: PositionDefinition, span: any, containsSecondaryGroup?: boolean): any[];
|
|
22
|
+
static generateSecondaryGroupHeader(dataGroup: any, template: any, position: any, span: any): any[];
|
|
23
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BoardDocumentGenerator = void 0;
|
|
4
|
+
const documents_1 = require("@contrail/documents");
|
|
5
|
+
const interfaces_1 = require("./interfaces");
|
|
6
|
+
const util_1 = require("@contrail/util");
|
|
7
|
+
const frame_generator_1 = require("./frames/frame-generator");
|
|
8
|
+
const document_util_1 = require("./util/document-util");
|
|
9
|
+
const document_dynamic_text_element_util_1 = require("./util/document-dynamic-text-element-util");
|
|
10
|
+
class BoardDocumentGenerator {
|
|
11
|
+
constructor() { }
|
|
12
|
+
static generateDocumentElements(options, typeMap) {
|
|
13
|
+
if (typeMap && document_dynamic_text_element_util_1.DocumentDynamicTextElementUtil.typeMap === undefined) {
|
|
14
|
+
document_dynamic_text_element_util_1.DocumentDynamicTextElementUtil.setTypeMap(typeMap);
|
|
15
|
+
}
|
|
16
|
+
const elements = [];
|
|
17
|
+
const structure = options.data.dataGroup;
|
|
18
|
+
const template = options.documentTemplateDefinition;
|
|
19
|
+
const frameTemplate = options.frameTemplate;
|
|
20
|
+
if (frameTemplate) {
|
|
21
|
+
template.frameSize = frameTemplate.document.size;
|
|
22
|
+
}
|
|
23
|
+
console.log('generateDocumentElements: ', structure.depth, structure.groupingProperties.length);
|
|
24
|
+
let position = options.startingCoordinates || { x: 0, y: 0 };
|
|
25
|
+
const group = structure.rootGroup;
|
|
26
|
+
const deepestSubgroups = [];
|
|
27
|
+
this.findDeepestSubgroups(group, deepestSubgroups, structure.depth, 0, true);
|
|
28
|
+
let containsSecondaryGroup = deepestSubgroups.length > 0 && deepestSubgroups[0].isSecondaryGroup;
|
|
29
|
+
elements.push(...this.generateBoardGroupHeaders(group, template, position, structure.depth, 0, containsSecondaryGroup));
|
|
30
|
+
elements.push(...this.generateBoardFrames(group, template, frameTemplate, position, structure.depth, 0, containsSecondaryGroup, null));
|
|
31
|
+
return elements;
|
|
32
|
+
}
|
|
33
|
+
static adjustPositionBasedGroupHeaderSpan(currentPosition, template, subGroup, totalDepth, currentDepth, containsSecondaryGroup) {
|
|
34
|
+
let frameSetMultiple = this.getGroupSpan(subGroup, totalDepth, currentDepth + 1, !subGroup.isSecondaryGroup);
|
|
35
|
+
let paddingMultiple = 1;
|
|
36
|
+
if (currentDepth < totalDepth) {
|
|
37
|
+
paddingMultiple = frameSetMultiple;
|
|
38
|
+
}
|
|
39
|
+
let adjustment = 0;
|
|
40
|
+
if (!subGroup.isSecondaryGroup && containsSecondaryGroup) {
|
|
41
|
+
adjustment = this.secondaryGroupPadding * paddingMultiple;
|
|
42
|
+
}
|
|
43
|
+
if ((template.frameOrientation === interfaces_1.Orientation.HORIZONTAL && !subGroup.isSecondaryGroup) ||
|
|
44
|
+
(template.frameOrientation === interfaces_1.Orientation.VERTICAL && subGroup.isSecondaryGroup)) {
|
|
45
|
+
return {
|
|
46
|
+
x: currentPosition.x,
|
|
47
|
+
y: currentPosition.y +
|
|
48
|
+
template.frameSize.height * frameSetMultiple +
|
|
49
|
+
template.framePadding * paddingMultiple +
|
|
50
|
+
adjustment,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
else if ((template.frameOrientation === interfaces_1.Orientation.HORIZONTAL && subGroup.isSecondaryGroup) ||
|
|
54
|
+
(template.frameOrientation === interfaces_1.Orientation.VERTICAL && !subGroup.isSecondaryGroup)) {
|
|
55
|
+
return {
|
|
56
|
+
x: currentPosition.x +
|
|
57
|
+
template.frameSize.width * frameSetMultiple +
|
|
58
|
+
template.framePadding * paddingMultiple +
|
|
59
|
+
adjustment,
|
|
60
|
+
y: currentPosition.y,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static adjustPositionBasedOnGroupHeaderSize(currentPosition, template) {
|
|
65
|
+
let groupHeaderDimensions = {
|
|
66
|
+
width: template.frameSize.width,
|
|
67
|
+
height: template.frameGroupHeaderTemplate.size.height,
|
|
68
|
+
};
|
|
69
|
+
if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
|
|
70
|
+
return { x: currentPosition.x + groupHeaderDimensions.height + template.framePadding, y: currentPosition.y };
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return { x: currentPosition.x, y: currentPosition.y + groupHeaderDimensions.height + template.framePadding };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
static generateBoardGroupHeaders(group, template, startingPosition, totalDepth, currentDepth, containsSecondaryGroup = false) {
|
|
77
|
+
const elements = [];
|
|
78
|
+
let position = {
|
|
79
|
+
x: startingPosition.x,
|
|
80
|
+
y: startingPosition.y,
|
|
81
|
+
};
|
|
82
|
+
if (currentDepth > 0) {
|
|
83
|
+
let groupHeaderPosition = { x: position.x + template.framePadding, y: position.y + template.framePadding };
|
|
84
|
+
let span = this.getGroupSpan(group, totalDepth, currentDepth, true);
|
|
85
|
+
elements.push(...this.generateBoardGroupHeader(group, template, groupHeaderPosition, span, containsSecondaryGroup));
|
|
86
|
+
position = this.adjustPositionBasedOnGroupHeaderSize(position, template);
|
|
87
|
+
}
|
|
88
|
+
if (currentDepth < totalDepth) {
|
|
89
|
+
for (let subGroup of group.subGroups) {
|
|
90
|
+
if (!subGroup.isSecondaryGroup) {
|
|
91
|
+
elements.push(...this.generateBoardGroupHeaders(subGroup, template, position, totalDepth, currentDepth + 1, containsSecondaryGroup));
|
|
92
|
+
const adjustedPosition = this.adjustPositionBasedGroupHeaderSpan(position, template, subGroup, totalDepth, currentDepth, containsSecondaryGroup);
|
|
93
|
+
position = {
|
|
94
|
+
x: adjustedPosition.x,
|
|
95
|
+
y: adjustedPosition.y,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return elements;
|
|
101
|
+
}
|
|
102
|
+
static generateBoardFrames(group, template, frameTemplate, startingPosition, totalDepth, currentDepth, containsSecondaryGroup, frameTitle) {
|
|
103
|
+
if (currentDepth > 0) {
|
|
104
|
+
frameTitle = !frameTitle ? group.name : frameTitle + ' / ' + group.name;
|
|
105
|
+
}
|
|
106
|
+
const elements = [];
|
|
107
|
+
let position = {
|
|
108
|
+
x: startingPosition.x,
|
|
109
|
+
y: startingPosition.y,
|
|
110
|
+
};
|
|
111
|
+
if (currentDepth > 0 && !group.isSecondaryGroup) {
|
|
112
|
+
position = this.adjustPositionBasedOnGroupHeaderSize(position, template);
|
|
113
|
+
}
|
|
114
|
+
if (currentDepth === totalDepth) {
|
|
115
|
+
elements.push(...this.generateFrameGroup(group, template, frameTemplate, position, frameTitle));
|
|
116
|
+
}
|
|
117
|
+
if (currentDepth < totalDepth) {
|
|
118
|
+
for (let subGroup of group.subGroups) {
|
|
119
|
+
elements.push(...this.generateBoardFrames(subGroup, template, frameTemplate, position, totalDepth, currentDepth + 1, containsSecondaryGroup, frameTitle));
|
|
120
|
+
const adjustedPosition = this.adjustPositionBasedGroupHeaderSpan(position, template, subGroup, totalDepth, currentDepth, containsSecondaryGroup);
|
|
121
|
+
position = {
|
|
122
|
+
x: adjustedPosition.x,
|
|
123
|
+
y: adjustedPosition.y,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return elements;
|
|
128
|
+
}
|
|
129
|
+
static getGroupSpan(group, totalDepth, currentDepth, stopAtSecondary) {
|
|
130
|
+
const deepestSubgroups = [];
|
|
131
|
+
this.findDeepestSubgroups(group, deepestSubgroups, totalDepth, currentDepth, stopAtSecondary);
|
|
132
|
+
return deepestSubgroups.length;
|
|
133
|
+
}
|
|
134
|
+
static findDeepestSubgroups(group, subgroups, totalDepth, currentDepth, stopAtSecondary) {
|
|
135
|
+
if (currentDepth === totalDepth && group.subGroups.length > 0) {
|
|
136
|
+
if (!group.isSecondaryGroup &&
|
|
137
|
+
group.subGroups.filter((subgroup) => subgroup.name === group.subGroups[0].name).length > 1) {
|
|
138
|
+
subgroups.push(group.subGroups[0]);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
subgroups.push(...group.subGroups);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (let i = 0; i < group.subGroups.length; i++) {
|
|
145
|
+
if (group.subGroups[i].isSecondaryGroup && stopAtSecondary) {
|
|
146
|
+
subgroups.push(group.subGroups[0]);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
this.findDeepestSubgroups(group.subGroups[i], subgroups, totalDepth, currentDepth + 1, stopAtSecondary);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
static generateFrameGroup(dataGroup, template, frameTemplate, position, frameTitle) {
|
|
153
|
+
const elements = [];
|
|
154
|
+
let framePosition = { x: position.x + template.framePadding, y: position.y + template.framePadding };
|
|
155
|
+
if (dataGroup.isSecondaryGroup) {
|
|
156
|
+
elements.push(...this.generateSecondaryGroupHeader(dataGroup, template, util_1.ObjectUtil.cloneDeep(framePosition), dataGroup.subGroups.length));
|
|
157
|
+
if (template.frameOrientation === interfaces_1.Orientation.VERTICAL) {
|
|
158
|
+
framePosition.x = framePosition.x + template.frameGroupHeaderTemplate.size.height + 20;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
framePosition.y = framePosition.y + template.frameGroupHeaderTemplate.size.height + 20;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
for (let group of dataGroup.subGroups) {
|
|
165
|
+
let frame = frame_generator_1.FrameGenerator.generateBoardFrameForDataGroup(group, framePosition, template, frameTemplate, frameTitle);
|
|
166
|
+
elements.push(...frame.toDocumentElements());
|
|
167
|
+
if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
|
|
168
|
+
framePosition.x = framePosition.x + template.frameSize.width + template.framePadding || 10;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
framePosition.y = framePosition.y + template.frameSize.height + template.framePadding || 10;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return elements;
|
|
175
|
+
}
|
|
176
|
+
static generateBoardGroupHeader(dataGroup, template, position, span, containsSecondaryGroup = false) {
|
|
177
|
+
const elements = [];
|
|
178
|
+
const heading = documents_1.DocumentElementFactory.createTextElement('Placeholder', {});
|
|
179
|
+
heading.style = {
|
|
180
|
+
border: { width: 1, color: 'rgba(0,0,0,0)' },
|
|
181
|
+
color: '#000000',
|
|
182
|
+
backgroundColor: template.frameGroupHeaderTemplate.style.backgroundColor || 'black',
|
|
183
|
+
};
|
|
184
|
+
heading.text = `<p><span style=\"font-size: ${template.frameGroupHeaderTemplate.style.font.size}pt;\"><strong><span style=\"color: ${template.frameGroupHeaderTemplate.style.color};\">${document_util_1.DocumentUtil.sanitizeHTML(dataGroup.name)}</span></strong></span></p>`;
|
|
185
|
+
heading.position = position;
|
|
186
|
+
let adjustment = containsSecondaryGroup ? this.secondaryGroupPadding : 0;
|
|
187
|
+
if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
|
|
188
|
+
let sizeDim = (template.frameSize.height + adjustment) * span;
|
|
189
|
+
if (span > 1) {
|
|
190
|
+
sizeDim += (span - 1) * template.framePadding;
|
|
191
|
+
}
|
|
192
|
+
heading.size = { width: sizeDim, height: template.frameGroupHeaderTemplate.size.height };
|
|
193
|
+
heading.rotate = { angle: 270 };
|
|
194
|
+
heading.position.x = heading.position.x - heading.size.width / 2 + heading.size.height / 2;
|
|
195
|
+
heading.position.y = heading.position.y + heading.size.width / 2 - heading.size.height / 2;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
let sizeDim = (template.frameSize.width + adjustment) * span;
|
|
199
|
+
if (span > 1) {
|
|
200
|
+
sizeDim += (span - 1) * template.framePadding;
|
|
201
|
+
}
|
|
202
|
+
heading.rotate = { angle: 0 };
|
|
203
|
+
heading.size = { width: sizeDim, height: template.frameGroupHeaderTemplate.size.height };
|
|
204
|
+
}
|
|
205
|
+
elements.push(heading);
|
|
206
|
+
return elements;
|
|
207
|
+
}
|
|
208
|
+
static generateSecondaryGroupHeader(dataGroup, template, position, span) {
|
|
209
|
+
const elements = [];
|
|
210
|
+
const heading = documents_1.DocumentElementFactory.createTextElement('Placeholder', {});
|
|
211
|
+
heading.style = {
|
|
212
|
+
border: { width: 1, color: 'rgba(0,0,0,0)' },
|
|
213
|
+
color: '#000000',
|
|
214
|
+
backgroundColor: template.secondaryFrameGroupHeaderTemplate.style.backgroundColor || 'black',
|
|
215
|
+
};
|
|
216
|
+
heading.text = `<p><span style=\"font-size: ${template.secondaryFrameGroupHeaderTemplate.style.font.size}pt;\"><strong><span style=\"color: ${template.secondaryFrameGroupHeaderTemplate.style.color};\">${document_util_1.DocumentUtil.sanitizeHTML(dataGroup.name)}</span></strong></span></p>`;
|
|
217
|
+
heading.position = position;
|
|
218
|
+
if (template.frameOrientation === interfaces_1.Orientation.VERTICAL) {
|
|
219
|
+
let sizeDim = template.frameSize.height * span;
|
|
220
|
+
if (span > 1) {
|
|
221
|
+
sizeDim += (span - 1) * template.framePadding;
|
|
222
|
+
}
|
|
223
|
+
heading.size = { width: sizeDim, height: template.secondaryFrameGroupHeaderTemplate.size.height };
|
|
224
|
+
heading.rotate = { angle: 270 };
|
|
225
|
+
heading.position.x = heading.position.x - heading.size.width / 2 + heading.size.height / 2;
|
|
226
|
+
heading.position.y = heading.position.y + heading.size.width / 2 - heading.size.height / 2;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
let sizeDim = template.frameSize.width * span;
|
|
230
|
+
if (span > 1) {
|
|
231
|
+
sizeDim += (span - 1) * template.framePadding;
|
|
232
|
+
}
|
|
233
|
+
heading.rotate = { angle: 0 };
|
|
234
|
+
heading.size = { width: sizeDim, height: template.secondaryFrameGroupHeaderTemplate.size.height };
|
|
235
|
+
}
|
|
236
|
+
elements.push(heading);
|
|
237
|
+
return elements;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
exports.BoardDocumentGenerator = BoardDocumentGenerator;
|
|
241
|
+
BoardDocumentGenerator.secondaryGroupPadding = 80;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DocumentElement } from '@contrail/documents';
|
|
2
|
+
import { ComponentPropertyTemplate, ComponentTemplate } from '../interfaces';
|
|
3
|
+
export declare class ComponentGenerator {
|
|
4
|
+
static generateComponent(data: any, options: DocumentElement, template: ComponentTemplate): any;
|
|
5
|
+
static generateComponentFromPropertyTemplate(data: any, options: DocumentElement, template: ComponentPropertyTemplate): DocumentElement;
|
|
6
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentGenerator = void 0;
|
|
4
|
+
const documents_1 = require("@contrail/documents");
|
|
5
|
+
const nanoid_1 = require("nanoid");
|
|
6
|
+
const document_property_util_1 = require("../util/document-property-util");
|
|
7
|
+
const component_util_1 = require("./component-util");
|
|
8
|
+
class ComponentGenerator {
|
|
9
|
+
static generateComponent(data, options, template) {
|
|
10
|
+
let component;
|
|
11
|
+
if (template.propertyTemplate) {
|
|
12
|
+
component = this.generateComponentFromPropertyTemplate(data, options, template.propertyTemplate);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
throw Error('No component property template defined');
|
|
16
|
+
}
|
|
17
|
+
return component;
|
|
18
|
+
}
|
|
19
|
+
static generateComponentFromPropertyTemplate(data, options, template) {
|
|
20
|
+
var _a;
|
|
21
|
+
let componentElement = documents_1.DocumentElementFactory.initNewElement('component');
|
|
22
|
+
if (options) {
|
|
23
|
+
componentElement = Object.assign(componentElement, options);
|
|
24
|
+
}
|
|
25
|
+
let yPosition = 0;
|
|
26
|
+
const imageDimension = template.imageDimension || {};
|
|
27
|
+
const imageWidth = imageDimension.width || 125;
|
|
28
|
+
const elements = [];
|
|
29
|
+
const textOptions = {
|
|
30
|
+
style: {
|
|
31
|
+
text: {
|
|
32
|
+
align: template.textHorizontalAlignment,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
size: {
|
|
36
|
+
width: imageWidth,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
elements.push(...document_property_util_1.DocumentPropertyUtil.generatePropertyElements(data, template.properties, textOptions, { y: yPosition }, imageDimension, true));
|
|
40
|
+
const modelBindings = component_util_1.ComponentUtil.generatedModelBindings(data);
|
|
41
|
+
componentElement.elements = elements;
|
|
42
|
+
componentElement.modelBindings = modelBindings;
|
|
43
|
+
componentElement.propertyBindings = {
|
|
44
|
+
'entityData.roles': 'item.roles',
|
|
45
|
+
};
|
|
46
|
+
if (((_a = componentElement === null || componentElement === void 0 ? void 0 : componentElement.elements) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
47
|
+
componentElement.elements = componentElement.elements.map((e) => {
|
|
48
|
+
e.id = (0, nanoid_1.nanoid)(16);
|
|
49
|
+
return e;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return componentElement;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.ComponentGenerator = ComponentGenerator;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DocumentElement, PositionDefinition, SizeDefinition } from '@contrail/documents';
|
|
2
|
+
import { ComponentGridTemplate } from '../interfaces';
|
|
3
|
+
export declare class ComponentGridGenerator {
|
|
4
|
+
static generateComponentGrid(data: any, startingPosition: PositionDefinition, template: ComponentGridTemplate, idealSize: SizeDefinition): Array<DocumentElement>;
|
|
5
|
+
private static getComponentSize;
|
|
6
|
+
private static adjustComponentTemplate;
|
|
7
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentGridGenerator = void 0;
|
|
4
|
+
const util_1 = require("@contrail/util");
|
|
5
|
+
const component_generator_1 = require("./component-generator");
|
|
6
|
+
const component_util_1 = require("./component-util");
|
|
7
|
+
class ComponentGridGenerator {
|
|
8
|
+
static generateComponentGrid(data, startingPosition = { x: 0, y: 0 }, template, idealSize) {
|
|
9
|
+
if (!data) {
|
|
10
|
+
console.warn('WARN: data null in generateComponentGrid');
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
if (!template) {
|
|
14
|
+
console.warn('WARN: template null in generateComponentGrid');
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
if (!template.componentTemplate) {
|
|
18
|
+
console.warn('WARN: component template is null in generateComponentGrid');
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
const elements = [];
|
|
22
|
+
let dataIndex = 0;
|
|
23
|
+
let gridTemplate = template;
|
|
24
|
+
const optimizeTemplate = true;
|
|
25
|
+
if (optimizeTemplate) {
|
|
26
|
+
gridTemplate = this.adjustComponentTemplate(data, idealSize, template);
|
|
27
|
+
}
|
|
28
|
+
const componentTemplate = gridTemplate.componentTemplate;
|
|
29
|
+
const componentPosition = util_1.ObjectUtil.cloneDeep(startingPosition);
|
|
30
|
+
const componentSize = this.getComponentSize(data, gridTemplate);
|
|
31
|
+
const componentPadding = gridTemplate.componentPadding || 20;
|
|
32
|
+
const alignment = template.alignment || 'left';
|
|
33
|
+
let startingY = componentPosition.y + componentPadding;
|
|
34
|
+
const rowGap = componentPadding * 3;
|
|
35
|
+
const colGap = componentPadding * 2;
|
|
36
|
+
const maxComponentHeight = (idealSize.height - template.gridDimensions.rows * colGap) / template.gridDimensions.rows;
|
|
37
|
+
for (let row = 0; row < gridTemplate.gridDimensions.rows; row++) {
|
|
38
|
+
const remainingItems = data.length - dataIndex;
|
|
39
|
+
const itemsInRow = Math.min(remainingItems, gridTemplate.gridDimensions.cols);
|
|
40
|
+
const rowWidth = itemsInRow * (componentSize.width + colGap) - colGap;
|
|
41
|
+
let rowStartX = startingPosition.x;
|
|
42
|
+
if (alignment === 'center') {
|
|
43
|
+
rowStartX += (idealSize.width - rowWidth) / 2;
|
|
44
|
+
}
|
|
45
|
+
else if (alignment === 'right') {
|
|
46
|
+
rowStartX += idealSize.width - rowWidth - componentPadding;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
rowStartX += componentPadding;
|
|
50
|
+
}
|
|
51
|
+
rowStartX = Math.round(rowStartX);
|
|
52
|
+
let componentPosition = {
|
|
53
|
+
x: rowStartX,
|
|
54
|
+
y: startingY + row * (Math.min(componentSize.height, maxComponentHeight) + (row > 0 ? rowGap : 0)),
|
|
55
|
+
};
|
|
56
|
+
for (let col = 0; col < gridTemplate.gridDimensions.cols; col++) {
|
|
57
|
+
if (dataIndex >= data.length) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const dataObj = data[dataIndex];
|
|
61
|
+
dataObj.viewable = dataObj.item;
|
|
62
|
+
const position = util_1.ObjectUtil.cloneDeep(componentPosition);
|
|
63
|
+
const component = component_generator_1.ComponentGenerator.generateComponent(dataObj, { position }, componentTemplate);
|
|
64
|
+
elements.push(component);
|
|
65
|
+
dataIndex++;
|
|
66
|
+
componentPosition.x += componentSize.width + colGap;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return elements;
|
|
70
|
+
}
|
|
71
|
+
static getComponentSize(data, template) {
|
|
72
|
+
if (!(data === null || data === void 0 ? void 0 : data.length)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const firstData = data[0];
|
|
76
|
+
const element = component_generator_1.ComponentGenerator.generateComponent(firstData, {}, template.componentTemplate);
|
|
77
|
+
return component_util_1.ComponentUtil.getComponentSize(element);
|
|
78
|
+
}
|
|
79
|
+
static adjustComponentTemplate(data, idealSize, template) {
|
|
80
|
+
const componentSize = this.getComponentSize(data, template);
|
|
81
|
+
const adjustedTemplate = util_1.ObjectUtil.cloneDeep(template);
|
|
82
|
+
const horizontalPadding = template.gridDimensions.cols * 2 * template.componentPadding || 20;
|
|
83
|
+
const verticalPadding = template.gridDimensions.rows * 2 * template.componentPadding || 20;
|
|
84
|
+
const requiredSize = {
|
|
85
|
+
width: componentSize.width * template.gridDimensions.cols + horizontalPadding,
|
|
86
|
+
height: componentSize.height * template.gridDimensions.rows + verticalPadding,
|
|
87
|
+
};
|
|
88
|
+
const requiredHeightAdjustment = (idealSize.height - requiredSize.height) / template.gridDimensions.rows;
|
|
89
|
+
const requiredWidthAdjustment = (idealSize.width - requiredSize.width) / template.gridDimensions.cols;
|
|
90
|
+
if (requiredHeightAdjustment < 0 && requiredHeightAdjustment < requiredWidthAdjustment) {
|
|
91
|
+
adjustedTemplate.componentTemplate.propertyTemplate.imageDimension.width += requiredHeightAdjustment;
|
|
92
|
+
}
|
|
93
|
+
if (requiredWidthAdjustment < 0 && requiredWidthAdjustment < requiredHeightAdjustment) {
|
|
94
|
+
adjustedTemplate.componentTemplate.propertyTemplate.imageDimension.width += requiredWidthAdjustment;
|
|
95
|
+
}
|
|
96
|
+
if (adjustedTemplate.componentTemplate.propertyTemplate.imageDimension.width < 25) {
|
|
97
|
+
adjustedTemplate.componentTemplate.propertyTemplate.imageDimension.width = 25;
|
|
98
|
+
}
|
|
99
|
+
return adjustedTemplate;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.ComponentGridGenerator = ComponentGridGenerator;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentUtil = void 0;
|
|
4
|
+
class ComponentUtil {
|
|
5
|
+
static generatedModelBindings(data) {
|
|
6
|
+
const model = {};
|
|
7
|
+
if (data.item) {
|
|
8
|
+
model.item = `item:${data.item.id}`;
|
|
9
|
+
model.viewable = `item:${data.item.id}`;
|
|
10
|
+
}
|
|
11
|
+
if (data.projectItem) {
|
|
12
|
+
model.projectItem = `project-item:${data.projectItem.id}`;
|
|
13
|
+
}
|
|
14
|
+
if (data.assortmentItem) {
|
|
15
|
+
model.assortmentItem = `assortment-item:${data.assortmentItem.id}`;
|
|
16
|
+
}
|
|
17
|
+
if (data.assortment) {
|
|
18
|
+
model.assortment = `assortment:${data.assortment.id}`;
|
|
19
|
+
}
|
|
20
|
+
return model;
|
|
21
|
+
}
|
|
22
|
+
static getComponentSize(element) {
|
|
23
|
+
var _a, _b, _c, _d, _e;
|
|
24
|
+
const sizeDefinition = {
|
|
25
|
+
width: 0,
|
|
26
|
+
height: 0,
|
|
27
|
+
};
|
|
28
|
+
const imageElement = ((_a = element.elements) === null || _a === void 0 ? void 0 : _a.find((el) => el.type === 'image')) || {};
|
|
29
|
+
sizeDefinition.width = (_b = imageElement.size) === null || _b === void 0 ? void 0 : _b.width;
|
|
30
|
+
const LINE_PADDING = 8;
|
|
31
|
+
const textElements = (_c = element.elements) === null || _c === void 0 ? void 0 : _c.filter((el) => el.type === 'text');
|
|
32
|
+
let textHeight = 0;
|
|
33
|
+
textElements.forEach((el) => {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
let fontSize = ((_b = (_a = el.style) === null || _a === void 0 ? void 0 : _a.font) === null || _b === void 0 ? void 0 : _b.size) || 12;
|
|
36
|
+
textHeight += fontSize + LINE_PADDING;
|
|
37
|
+
});
|
|
38
|
+
const imageHeight = ((_d = imageElement.size) === null || _d === void 0 ? void 0 : _d.height) || ((_e = imageElement.size) === null || _e === void 0 ? void 0 : _e.width) || 150;
|
|
39
|
+
sizeDefinition.height = imageHeight + textHeight;
|
|
40
|
+
return sizeDefinition;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.ComponentUtil = ComponentUtil;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DocumentElement } from '@contrail/documents';
|
|
2
|
+
import { DocumentGenerationOptions } from './interfaces';
|
|
3
|
+
export declare class DocumentGenerator {
|
|
4
|
+
constructor();
|
|
5
|
+
static generateDocumentElements(options: DocumentGenerationOptions, typeMap: any): Array<DocumentElement>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentGenerator = void 0;
|
|
4
|
+
const board_document_generator_1 = require("./board-document-generator");
|
|
5
|
+
class DocumentGenerator {
|
|
6
|
+
constructor() { }
|
|
7
|
+
static generateDocumentElements(options, typeMap) {
|
|
8
|
+
return board_document_generator_1.BoardDocumentGenerator.generateDocumentElements(options, typeMap);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.DocumentGenerator = DocumentGenerator;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DocumentElement, PositionDefinition, SizeDefinition } from '@contrail/documents';
|
|
2
|
+
import { DataGroup } from '@contrail/data-grouping';
|
|
3
|
+
import { DocumentTemplate, FrameDocumentTemplate } from '../interfaces';
|
|
4
|
+
import { DocumentFrame } from './frame';
|
|
5
|
+
export declare class FrameGenerator {
|
|
6
|
+
static generateBoardFrameForDataGroup(dataGroup: DataGroup, framePosition: PositionDefinition, template: DocumentTemplate, frameTemplate: FrameDocumentTemplate, frameTitle: string): DocumentFrame;
|
|
7
|
+
static generateFrameContentForGroup(frame: DocumentFrame, dataGroup: DataGroup, template: DocumentTemplate, frameTemplate?: FrameDocumentTemplate, frameTitle?: string): DocumentFrame;
|
|
8
|
+
static generateFrameHeaderForDataGroup(dataGroup: DataGroup, position: PositionDefinition, template: DocumentTemplate, headerSize: SizeDefinition, frameTitle?: string): DocumentElement[];
|
|
9
|
+
static generateFrameInfoPanelForDataGroup(dataGroup: DataGroup, position: PositionDefinition, template: DocumentTemplate, panelSize: SizeDefinition): DocumentElement[];
|
|
10
|
+
static generateFrame(options: DocumentElement): DocumentElement;
|
|
11
|
+
static generateFrameTemplateElements(frameTemplate: FrameDocumentTemplate, dataGroup: DataGroup, frameTitle?: string): DocumentElement[];
|
|
12
|
+
}
|