@contrail/document-generation 2.1.14 → 2.1.16
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.
|
@@ -2,6 +2,8 @@ import { DataGroup } from '@contrail/data-grouping';
|
|
|
2
2
|
import { DocumentElement } from '@contrail/documents';
|
|
3
3
|
export declare class DocumentDynamicTextElementUtil {
|
|
4
4
|
static typeMap: any;
|
|
5
|
+
static propertyMapByType: any;
|
|
5
6
|
static isDynamicText(element: any): any;
|
|
6
7
|
static handleDynamicText(element: DocumentElement, dataGroup: DataGroup, frameTitle?: any): void;
|
|
8
|
+
static setTypeMap(typeMap: any): void;
|
|
7
9
|
}
|
|
@@ -2,29 +2,60 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DocumentDynamicTextElementUtil = void 0;
|
|
4
4
|
const documents_1 = require("@contrail/documents");
|
|
5
|
+
const types_1 = require("@contrail/types");
|
|
5
6
|
const document_text_element_util_1 = require("./document-text-element-util");
|
|
6
7
|
class DocumentDynamicTextElementUtil {
|
|
7
8
|
static isDynamicText(element) {
|
|
8
9
|
return element.type === 'text' && element.propertyBindings && element.propertyBindingsMetaData;
|
|
9
10
|
}
|
|
10
11
|
static handleDynamicText(element, dataGroup, frameTitle = null) {
|
|
11
|
-
var _a;
|
|
12
|
+
var _a, _b, _c;
|
|
12
13
|
const propertyBindingsText = element.propertyBindings.text;
|
|
14
|
+
let propertyLevel = (_a = element.propertyBindingsMetaData) === null || _a === void 0 ? void 0 : _a.propertyLevel;
|
|
15
|
+
let property = null;
|
|
16
|
+
let componentModels = dataGroup.data;
|
|
13
17
|
const frame = {
|
|
14
18
|
name: frameTitle || dataGroup.name,
|
|
15
19
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
if (propertyBindingsText) {
|
|
21
|
+
const [entityType, propertySlug] = propertyBindingsText === null || propertyBindingsText === void 0 ? void 0 : propertyBindingsText.split('.');
|
|
22
|
+
property = (_b = this.propertyMapByType[entityType]) === null || _b === void 0 ? void 0 : _b.properties[propertySlug];
|
|
23
|
+
if (!propertyLevel &&
|
|
24
|
+
(property === null || property === void 0 ? void 0 : property.propertyLevel) &&
|
|
25
|
+
[types_1.PropertyLevel.OPTION, types_1.PropertyLevel.FAMILY].includes(property.propertyLevel)) {
|
|
26
|
+
propertyLevel = property.propertyLevel;
|
|
27
|
+
}
|
|
28
|
+
if (propertyLevel && propertyLevel === types_1.PropertyLevel.FAMILY) {
|
|
29
|
+
componentModels = JSON.parse(JSON.stringify(dataGroup.data));
|
|
30
|
+
componentModels.forEach(componentModel => {
|
|
31
|
+
var _a;
|
|
32
|
+
const entity = componentModel[entityType];
|
|
33
|
+
const isOption = (_a = entity === null || entity === void 0 ? void 0 : entity.roles) === null || _a === void 0 ? void 0 : _a.includes('option');
|
|
34
|
+
if (isOption && entityType === 'item' && entity.itemFamily) {
|
|
35
|
+
componentModel[entityType] = entity.itemFamily;
|
|
36
|
+
}
|
|
37
|
+
if (isOption && entityType === 'project-item' && entity.familyProjectItem) {
|
|
38
|
+
componentModel[entityType] = entity.familyProjectItem;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
21
42
|
}
|
|
22
|
-
let text = documents_1.DynamicTextUtil.getDynamicTextValue(element, property, frame,
|
|
23
|
-
if (((
|
|
43
|
+
let text = documents_1.DynamicTextUtil.getDynamicTextValue(element, property, propertyLevel, frame, componentModels);
|
|
44
|
+
if (((_c = element.text) === null || _c === void 0 ? void 0 : _c.toString().indexOf('</')) > -1) {
|
|
24
45
|
const styleDefinition = document_text_element_util_1.DocumentTextElementUtil.extractStyleFromInline(element.text);
|
|
25
46
|
text = document_text_element_util_1.DocumentTextElementUtil.applyInLineStyling(text, styleDefinition);
|
|
26
47
|
}
|
|
27
48
|
element.text = text;
|
|
28
49
|
}
|
|
50
|
+
static setTypeMap(typeMap) {
|
|
51
|
+
DocumentDynamicTextElementUtil.typeMap = typeMap;
|
|
52
|
+
Object.keys(DocumentDynamicTextElementUtil.typeMap).forEach(type => {
|
|
53
|
+
DocumentDynamicTextElementUtil.propertyMapByType[type] = { properties: {} };
|
|
54
|
+
typeMap[type].typeProperties.forEach(p => {
|
|
55
|
+
DocumentDynamicTextElementUtil.propertyMapByType[type].properties[p.slug] = p;
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
29
59
|
}
|
|
30
60
|
exports.DocumentDynamicTextElementUtil = DocumentDynamicTextElementUtil;
|
|
61
|
+
DocumentDynamicTextElementUtil.propertyMapByType = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/document-generation",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.16",
|
|
4
4
|
"description": "Utilities for automatic generation of documents.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@contrail/data-grouping": "^1.0.24",
|
|
46
46
|
"@contrail/document-table": "^1.0.4",
|
|
47
|
-
"@contrail/documents": "^1.
|
|
47
|
+
"@contrail/documents": "^1.2.3",
|
|
48
48
|
"@contrail/types": "^3.0.95",
|
|
49
49
|
"@contrail/util": "^1.1.0"
|
|
50
50
|
}
|