@legalplace/prerenderx 3.8.24 → 3.9.1
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/CHANGELOG.md +28 -0
- package/dist/libs/DocumentRender.d.ts +3 -2
- package/dist/libs/DocumentRender.js +13 -4
- package/dist/libs/FillPdfForm.d.ts +1 -1
- package/dist/libs/FillPdfForm.js +25 -15
- package/dist/libs/OptionRender.d.ts +4 -0
- package/dist/libs/OptionRender.js +125 -29
- package/dist/libs/OutputParser.d.ts +1 -1
- package/dist/libs/OutputParser.js +18 -6
- package/dist/libs/Prerender.d.ts +5 -2
- package/dist/libs/Prerender.js +100 -27
- package/dist/libs/SectionRender.d.ts +3 -0
- package/dist/libs/SectionRender.js +64 -22
- package/dist/libs/misc/FillPdfFormBase.d.ts +1 -1
- package/dist/libs/misc/FillPdfFormBase.js +11 -37
- package/dist/libs/tableOutputExpansion.d.ts +20 -0
- package/dist/libs/tableOutputExpansion.js +68 -0
- package/dist/types/types.d.ts +13 -0
- package/package.json +8 -8
- package/src/libs/DocumentRender.ts +33 -5
- package/src/libs/FillPdfForm.ts +39 -22
- package/src/libs/OptionRender.ts +218 -63
- package/src/libs/OutputParser.ts +40 -9
- package/src/libs/Prerender.ts +157 -38
- package/src/libs/SectionRender.ts +111 -28
- package/src/libs/misc/FillPdfFormBase.ts +34 -67
- package/src/libs/tableOutputExpansion.ts +145 -0
- package/src/types/types.ts +27 -0
- package/tests/Prerender.documentMultiple.test.ts +278 -0
- package/tests/Prerender.repeated.test.ts +115 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,34 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.9.1](https://git.legalplace.eu/legalplace/prerenderx/compare/@legalplace/prerenderx@3.9.0...@legalplace/prerenderx@3.9.1) (2026-09-01)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @legalplace/prerenderx
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [3.9.0](https://git.legalplace.eu/legalplace/prerenderx/compare/@legalplace/prerenderx@3.8.24...@legalplace/prerenderx@3.9.0) (2026-09-01)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* fix conditions on multiples and repeated outputs ([d77efbe](https://git.legalplace.eu/legalplace/prerenderx/commits/d77efbe706da435c6e853176432f64954217d046))
|
|
20
|
+
* fix repeated outputs ([ef05090](https://git.legalplace.eu/legalplace/prerenderx/commits/ef0509091348e7ff15a3dc751aec56bb1d7f74e1))
|
|
21
|
+
* **prerenderx,wizardx-core:** omit rendering empty table cells for hidden options api[#86](https://git.legalplace.eu/legalplace/prerenderx/issues/86)cb0r3d0 ([cc15192](https://git.legalplace.eu/legalplace/prerenderx/commits/cc151921ddedcc24966a202e931a051cb5ed0fd6)), closes [api#86cb0r3d0](https://git.legalplace.eu/api/issues/86cb0r3d0) [api#86cb0r3d0](https://git.legalplace.eu/api/issues/86cb0r3d0)
|
|
22
|
+
* **prerenderx:** merge duplicate referencesparser imports api[#86](https://git.legalplace.eu/legalplace/prerenderx/issues/86)cb0r3d0 ([27c269c](https://git.legalplace.eu/legalplace/prerenderx/commits/27c269cfccb73ef53ecd2381b279e12216b65b31)), closes [api#86cb0r3d0](https://git.legalplace.eu/api/issues/86cb0r3d0)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* output image assets, documentStyle font sizes and table column widths ([8dfb115](https://git.legalplace.eu/legalplace/prerenderx/commits/8dfb115d74cd3e5acbb11dd798efa749a8098001))
|
|
28
|
+
* **prerenderx:** table outputs, document multiples and layout regions api[#86](https://git.legalplace.eu/legalplace/prerenderx/issues/86)cb0r3d0 ([c12e552](https://git.legalplace.eu/legalplace/prerenderx/commits/c12e552fcba62ddf802a708fe79470d2134afc4c)), closes [api#86cb0r3d0](https://git.legalplace.eu/api/issues/86cb0r3d0)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
6
34
|
## [3.8.24](https://git.legalplace.eu/legalplace/prerenderx/compare/@legalplace/prerenderx@3.8.23...@legalplace/prerenderx@3.8.24) (2026-08-27)
|
|
7
35
|
|
|
8
36
|
**Note:** Version bump only for package @legalplace/prerenderx
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Types } from "@legalplace/referencesparser";
|
|
2
1
|
import type ConditionsRunner from "@legalplace/conditions-runner";
|
|
2
|
+
import { type OutputRegionRole, type Types } from "@legalplace/referencesparser";
|
|
3
3
|
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
4
|
import type NumAuto from "./NumAuto";
|
|
5
5
|
declare class DocumentRender {
|
|
@@ -8,6 +8,7 @@ declare class DocumentRender {
|
|
|
8
8
|
ovc: InputsType;
|
|
9
9
|
private NumAuto;
|
|
10
10
|
constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: InputsType, numauto: NumAuto);
|
|
11
|
-
renderDocument(documentName: string): string;
|
|
11
|
+
renderDocument(documentName: string, baseIndex?: number): string;
|
|
12
|
+
renderRegion(documentName: string, role: OutputRegionRole, baseIndex?: number): string;
|
|
12
13
|
}
|
|
13
14
|
export default DocumentRender;
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var referencesparser_1 = require("@legalplace/referencesparser");
|
|
6
7
|
var SectionRender_1 = __importDefault(require("./SectionRender"));
|
|
7
8
|
var DocumentRender = (function () {
|
|
8
9
|
function DocumentRender(references, conditions, ovc, numauto) {
|
|
@@ -11,18 +12,26 @@ var DocumentRender = (function () {
|
|
|
11
12
|
this.ovc = ovc;
|
|
12
13
|
this.NumAuto = numauto;
|
|
13
14
|
}
|
|
14
|
-
DocumentRender.prototype.renderDocument = function (documentName) {
|
|
15
|
+
DocumentRender.prototype.renderDocument = function (documentName, baseIndex) {
|
|
16
|
+
if (baseIndex === void 0) { baseIndex = 0; }
|
|
17
|
+
return this.renderRegion(documentName, "body", baseIndex);
|
|
18
|
+
};
|
|
19
|
+
DocumentRender.prototype.renderRegion = function (documentName, role, baseIndex) {
|
|
15
20
|
var _this = this;
|
|
21
|
+
if (baseIndex === void 0) { baseIndex = 0; }
|
|
16
22
|
var documentOutputs = [];
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
if (role === "body")
|
|
24
|
+
this.NumAuto.resetIndexes();
|
|
25
|
+
var sectionIds = (0, referencesparser_1.getSectionIdsForRole)(this.references.sections[documentName], role);
|
|
26
|
+
sectionIds.forEach(function (sectionId) {
|
|
19
27
|
documentOutputs.push.apply(documentOutputs, new SectionRender_1.default({
|
|
20
28
|
references: _this.references,
|
|
21
29
|
conditions: _this.conditions,
|
|
22
30
|
documentName: documentName,
|
|
23
31
|
ovc: _this.ovc,
|
|
24
|
-
currentSection:
|
|
32
|
+
currentSection: sectionId,
|
|
25
33
|
numauto: _this.NumAuto,
|
|
34
|
+
baseIndex: baseIndex,
|
|
26
35
|
}).getOutputs());
|
|
27
36
|
});
|
|
28
37
|
return documentOutputs.join("");
|
|
@@ -4,7 +4,7 @@ type FDFType = {
|
|
|
4
4
|
fields: Record<string, string>;
|
|
5
5
|
};
|
|
6
6
|
declare class FillPdfForm extends FillPdfFormBase {
|
|
7
|
-
fillDocument(documentName: string): FDFType;
|
|
7
|
+
fillDocument(documentName: string, baseIndex?: number): FDFType;
|
|
8
8
|
private getInputValue;
|
|
9
9
|
private getBoxValue;
|
|
10
10
|
private getVariableValue;
|
package/dist/libs/FillPdfForm.js
CHANGED
|
@@ -24,8 +24,9 @@ var FillPdfForm = (function (_super) {
|
|
|
24
24
|
function FillPdfForm() {
|
|
25
25
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
26
26
|
}
|
|
27
|
-
FillPdfForm.prototype.fillDocument = function (documentName) {
|
|
27
|
+
FillPdfForm.prototype.fillDocument = function (documentName, baseIndex) {
|
|
28
28
|
var _this = this;
|
|
29
|
+
if (baseIndex === void 0) { baseIndex = 0; }
|
|
29
30
|
var result = {
|
|
30
31
|
id: "",
|
|
31
32
|
fields: {},
|
|
@@ -38,21 +39,22 @@ var FillPdfForm = (function (_super) {
|
|
|
38
39
|
result.id = pdf.id;
|
|
39
40
|
form.inputs.forEach(function (input) {
|
|
40
41
|
var id = "".concat(input.name);
|
|
41
|
-
result.fields[id] = _this.getInputValue(input);
|
|
42
|
+
result.fields[id] = _this.getInputValue(input, baseIndex);
|
|
42
43
|
});
|
|
43
44
|
form.boxes.forEach(function (box) {
|
|
44
45
|
var id = "".concat(box.name);
|
|
45
|
-
var value = _this.getBoxValue(box);
|
|
46
|
+
var value = _this.getBoxValue(box, baseIndex);
|
|
46
47
|
if (!(value === "" &&
|
|
47
48
|
Object.prototype.hasOwnProperty.call(result.fields, id)))
|
|
48
49
|
result.fields[id] = value;
|
|
49
50
|
});
|
|
50
51
|
return result;
|
|
51
52
|
};
|
|
52
|
-
FillPdfForm.prototype.getInputValue = function (input) {
|
|
53
|
+
FillPdfForm.prototype.getInputValue = function (input, index) {
|
|
54
|
+
if (index === void 0) { index = 0; }
|
|
53
55
|
for (var i = 0; i < input.variables.length; i += 1) {
|
|
54
56
|
var variable = input.variables[i];
|
|
55
|
-
var currentValue = this.getVariableValue(variable.id);
|
|
57
|
+
var currentValue = this.getVariableValue(variable.id, index);
|
|
56
58
|
if (currentValue !== false) {
|
|
57
59
|
var dateRegex = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
|
|
58
60
|
if (variable.date && dateRegex.test(currentValue)) {
|
|
@@ -97,10 +99,11 @@ var FillPdfForm = (function (_super) {
|
|
|
97
99
|
}
|
|
98
100
|
return "";
|
|
99
101
|
};
|
|
100
|
-
FillPdfForm.prototype.getBoxValue = function (box) {
|
|
102
|
+
FillPdfForm.prototype.getBoxValue = function (box, index) {
|
|
103
|
+
if (index === void 0) { index = 0; }
|
|
101
104
|
for (var i = 0; i < box.options.length; i += 1) {
|
|
102
105
|
var option = box.options[i];
|
|
103
|
-
var currentValue = this.getOptionValue(option.id);
|
|
106
|
+
var currentValue = this.getOptionValue(option.id, index);
|
|
104
107
|
if (currentValue === true) {
|
|
105
108
|
if (this.references.options[option.id].meta.type === "checkbox" &&
|
|
106
109
|
box.value === "Off")
|
|
@@ -110,17 +113,24 @@ var FillPdfForm = (function (_super) {
|
|
|
110
113
|
}
|
|
111
114
|
return "";
|
|
112
115
|
};
|
|
113
|
-
FillPdfForm.prototype.getVariableValue = function (variableId) {
|
|
114
|
-
|
|
115
|
-
if (this.isVariableDisplayed(variableId,
|
|
116
|
+
FillPdfForm.prototype.getVariableValue = function (variableId, index) {
|
|
117
|
+
if (index === void 0) { index = 0; }
|
|
118
|
+
if (this.isVariableDisplayed(variableId, index) === false)
|
|
116
119
|
return false;
|
|
117
|
-
|
|
120
|
+
var variableValues = this.ovc.variables[variableId];
|
|
121
|
+
var value = (variableValues === null || variableValues === void 0 ? void 0 : variableValues[index]) !== undefined
|
|
122
|
+
? variableValues[index]
|
|
123
|
+
: (variableValues === null || variableValues === void 0 ? void 0 : variableValues[0]) || "";
|
|
124
|
+
return (value !== null && value !== void 0 ? value : "").toString();
|
|
118
125
|
};
|
|
119
|
-
FillPdfForm.prototype.getOptionValue = function (optionId) {
|
|
120
|
-
|
|
121
|
-
if (this.isOptionDisplayed(optionId,
|
|
126
|
+
FillPdfForm.prototype.getOptionValue = function (optionId, index) {
|
|
127
|
+
if (index === void 0) { index = 0; }
|
|
128
|
+
if (this.isOptionDisplayed(optionId, index) === false)
|
|
122
129
|
return false;
|
|
123
|
-
|
|
130
|
+
var optionValues = this.ovc.options[optionId];
|
|
131
|
+
return (optionValues === null || optionValues === void 0 ? void 0 : optionValues[index]) !== undefined
|
|
132
|
+
? optionValues[index] === true
|
|
133
|
+
: (optionValues === null || optionValues === void 0 ? void 0 : optionValues[0]) === true;
|
|
124
134
|
};
|
|
125
135
|
return FillPdfForm;
|
|
126
136
|
}(FillPdfFormBase_1.default));
|
|
@@ -19,6 +19,10 @@ declare class OptionRender {
|
|
|
19
19
|
numauto: NumAuto;
|
|
20
20
|
});
|
|
21
21
|
getOutputs(): string[];
|
|
22
|
+
private isDisplayed;
|
|
23
|
+
private renderOutputTableCell;
|
|
24
|
+
private renderOutputTableRow;
|
|
25
|
+
private renderOutputTable;
|
|
22
26
|
private renderOption;
|
|
23
27
|
private renderChildren;
|
|
24
28
|
}
|
|
@@ -9,7 +9,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
9
9
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
var referencesparser_1 = require("@legalplace/referencesparser");
|
|
12
13
|
var OutputParser_1 = require("./OutputParser");
|
|
14
|
+
var tableOutputExpansion_1 = require("./tableOutputExpansion");
|
|
13
15
|
var OptionRender = (function () {
|
|
14
16
|
function OptionRender(options) {
|
|
15
17
|
this.outputs = [];
|
|
@@ -24,45 +26,139 @@ var OptionRender = (function () {
|
|
|
24
26
|
OptionRender.prototype.getOutputs = function () {
|
|
25
27
|
return this.outputs;
|
|
26
28
|
};
|
|
29
|
+
OptionRender.prototype.isDisplayed = function (optionId) {
|
|
30
|
+
var _this = this;
|
|
31
|
+
if (optionId === void 0) { optionId = this.id; }
|
|
32
|
+
return (0, referencesparser_1.isOptionDisplayed)(this.references, this.ovc, function (type, entityId, entityIndex) {
|
|
33
|
+
if (type === "options") {
|
|
34
|
+
var conditionObject = _this.references.conditions.options[entityId];
|
|
35
|
+
return conditionObject === undefined
|
|
36
|
+
? true
|
|
37
|
+
: _this.conditions.executeCondition(conditionObject, entityId, entityIndex, "options");
|
|
38
|
+
}
|
|
39
|
+
if (type === "sections") {
|
|
40
|
+
var conditionObject = _this.references.conditions.sections.main[entityId];
|
|
41
|
+
return conditionObject === undefined
|
|
42
|
+
? true
|
|
43
|
+
: _this.conditions.executeCondition(conditionObject, entityId, entityIndex, "sections");
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}, optionId, this.index);
|
|
47
|
+
};
|
|
48
|
+
OptionRender.prototype.renderOutputTableCell = function (cellId) {
|
|
49
|
+
var _this = this;
|
|
50
|
+
var cellOption = this.references.options[cellId];
|
|
51
|
+
if ((cellOption === null || cellOption === void 0 ? void 0 : cellOption.meta.tableRole) !== "cell")
|
|
52
|
+
return "";
|
|
53
|
+
var styleAttr = (0, referencesparser_1.buildOutputTableCellStyleAttr)((0, referencesparser_1.getOutputTableCellStyle)(cellOption));
|
|
54
|
+
if (!this.isDisplayed(cellId)) {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
var outputReference = this.references.outputs[cellId];
|
|
58
|
+
if (outputReference === undefined) {
|
|
59
|
+
return "<td".concat(styleAttr, "></td>");
|
|
60
|
+
}
|
|
61
|
+
var autonums = outputReference.autonums.map(function (currentAn) {
|
|
62
|
+
var fn = currentAn[0] === "numauto-pre"
|
|
63
|
+
? _this.NumAuto.getNumPre
|
|
64
|
+
: _this.NumAuto.getNum;
|
|
65
|
+
return [
|
|
66
|
+
currentAn[0],
|
|
67
|
+
currentAn[1],
|
|
68
|
+
fn(currentAn[1], currentAn[2]),
|
|
69
|
+
currentAn[2],
|
|
70
|
+
];
|
|
71
|
+
});
|
|
72
|
+
var variables = (0, OutputParser_1.getRelatedVariablesValues)(cellId, this.index, outputReference.variables, this.ovc, this.references);
|
|
73
|
+
var content = (0, OutputParser_1.parseOutputWithVariables)(outputReference.raw, this.index, variables, autonums);
|
|
74
|
+
return "<td".concat(styleAttr, ">").concat(content, "</td>");
|
|
75
|
+
};
|
|
76
|
+
OptionRender.prototype.renderOutputTableRow = function (rowId) {
|
|
77
|
+
var _this = this;
|
|
78
|
+
var rowOption = this.references.options[rowId];
|
|
79
|
+
if ((rowOption === null || rowOption === void 0 ? void 0 : rowOption.meta.tableRole) !== "row")
|
|
80
|
+
return "";
|
|
81
|
+
if (!this.isDisplayed(rowId))
|
|
82
|
+
return "";
|
|
83
|
+
var cells = rowOption.options
|
|
84
|
+
.map(function (cellId) { return _this.renderOutputTableCell(cellId); })
|
|
85
|
+
.join("");
|
|
86
|
+
if (cells.length === 0)
|
|
87
|
+
return "";
|
|
88
|
+
return "<tr>".concat(cells, "</tr>");
|
|
89
|
+
};
|
|
90
|
+
OptionRender.prototype.renderOutputTable = function (option) {
|
|
91
|
+
var _this = this;
|
|
92
|
+
var rows = option.options
|
|
93
|
+
.map(function (rowId) { return _this.renderOutputTableRow(rowId); })
|
|
94
|
+
.filter(function (row) { return row.length > 0; })
|
|
95
|
+
.join("");
|
|
96
|
+
if (rows.length === 0)
|
|
97
|
+
return "";
|
|
98
|
+
var styleAttr = (0, referencesparser_1.buildOutputTableStyleAttr)(option.meta.tableStyle);
|
|
99
|
+
return "<table".concat(styleAttr, "><tbody>").concat(rows, "</tbody></table>");
|
|
100
|
+
};
|
|
27
101
|
OptionRender.prototype.renderOption = function () {
|
|
28
102
|
var _this = this;
|
|
29
103
|
var option = this.references.options[this.id];
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
autonums = outputReference.autonums.map(function (currentAn) {
|
|
41
|
-
var fn = currentAn[0] === "numauto-pre"
|
|
42
|
-
? _this.NumAuto.getNumPre
|
|
43
|
-
: _this.NumAuto.getNum;
|
|
44
|
-
return [
|
|
45
|
-
currentAn[0],
|
|
46
|
-
currentAn[1],
|
|
47
|
-
fn(currentAn[1], currentAn[2]),
|
|
48
|
-
currentAn[2],
|
|
49
|
-
];
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
var variables = (0, OutputParser_1.getRelatedVariablesValues)(this.id, this.index, outputReference.variables, this.ovc, this.references);
|
|
53
|
-
var output = (0, OutputParser_1.parseOutputWithVariables)(option.meta.output, this.index, variables, autonums);
|
|
54
|
-
output = output.replace(/<\/([a-z]+)>([\n\s]+)</gi, "</$1><");
|
|
55
|
-
output = output.replace(/\n/g, "<br />");
|
|
56
|
-
output = output.replace(/\xA0/g, " ");
|
|
57
|
-
this.outputs.push(output);
|
|
104
|
+
var tableRole = option.meta.tableRole;
|
|
105
|
+
if (tableRole === "row" || tableRole === "cell") {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (!this.isDisplayed())
|
|
109
|
+
return;
|
|
110
|
+
if (tableRole === "table") {
|
|
111
|
+
var tableHtml = this.renderOutputTable(option);
|
|
112
|
+
if (tableHtml.length > 0) {
|
|
113
|
+
this.outputs.push((0, tableOutputExpansion_1.cleanupRenderedOutputHtml)(tableHtml));
|
|
58
114
|
}
|
|
59
|
-
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (typeof option.meta.output === "string" &&
|
|
118
|
+
option.meta.output.trim().length > 0) {
|
|
119
|
+
var outputReference = this.references.outputs[this.id];
|
|
120
|
+
var autonums = outputReference.autonums.map(function (currentAn) {
|
|
121
|
+
var fn = currentAn[0] === "numauto-pre"
|
|
122
|
+
? _this.NumAuto.getNumPre
|
|
123
|
+
: _this.NumAuto.getNum;
|
|
124
|
+
return [
|
|
125
|
+
currentAn[0],
|
|
126
|
+
currentAn[1],
|
|
127
|
+
fn(currentAn[1], currentAn[2]),
|
|
128
|
+
currentAn[2],
|
|
129
|
+
];
|
|
130
|
+
});
|
|
131
|
+
var variables = (0, OutputParser_1.getRelatedVariablesValues)(this.id, this.index, outputReference.variables, this.ovc, this.references);
|
|
132
|
+
var output = (0, tableOutputExpansion_1.expandOutputTableMarkup)({
|
|
133
|
+
output: option.meta.output,
|
|
134
|
+
references: this.references,
|
|
135
|
+
ovc: this.ovc,
|
|
136
|
+
conditions: this.conditions,
|
|
137
|
+
contextOptionId: this.id,
|
|
138
|
+
defaultOccurrenceIndex: this.index,
|
|
139
|
+
});
|
|
140
|
+
output = (0, OutputParser_1.parseOutputWithVariables)(output, this.index, variables, autonums);
|
|
141
|
+
output = (0, referencesparser_1.replaceOutputTableMarkers)(output, function (tableId) {
|
|
142
|
+
var childOption = _this.references.options[tableId];
|
|
143
|
+
if (!childOption || childOption.meta.tableRole !== "table")
|
|
144
|
+
return "";
|
|
145
|
+
if (!_this.isDisplayed(tableId))
|
|
146
|
+
return "";
|
|
147
|
+
return _this.renderOutputTable(childOption);
|
|
148
|
+
});
|
|
149
|
+
output = (0, referencesparser_1.stripOutputTableMarkers)(output);
|
|
150
|
+
output = (0, tableOutputExpansion_1.cleanupRenderedOutputHtml)(output);
|
|
151
|
+
this.outputs.push(output);
|
|
60
152
|
}
|
|
153
|
+
this.renderChildren();
|
|
61
154
|
};
|
|
62
155
|
OptionRender.prototype.renderChildren = function () {
|
|
63
156
|
var _this = this;
|
|
64
157
|
var option = this.references.options[this.id];
|
|
65
158
|
option.options.forEach(function (optionId) {
|
|
159
|
+
var childOption = _this.references.options[optionId];
|
|
160
|
+
if ((childOption === null || childOption === void 0 ? void 0 : childOption.meta.tableRole) === "table")
|
|
161
|
+
return;
|
|
66
162
|
_this.outputs = __spreadArray(__spreadArray([], _this.outputs, true), new OptionRender({
|
|
67
163
|
references: _this.references,
|
|
68
164
|
id: optionId,
|
|
@@ -6,6 +6,6 @@ export declare const getRelatedVariablesValues: getRelatedVarsT;
|
|
|
6
6
|
type autonumsType = [string, string, number, string | null][];
|
|
7
7
|
type parseOutputT = (output: string, index: number, variables: relVarsValsT, autonums: autonumsType) => string;
|
|
8
8
|
export declare const parseOutputWithVariables: parseOutputT;
|
|
9
|
-
type TParseDocumentNameWithVariables = (text: string, ovc: InputsType, references: Types.ReferencesType, fallback?: string) => string;
|
|
9
|
+
type TParseDocumentNameWithVariables = (text: string, ovc: InputsType, references: Types.ReferencesType, fallback?: string, index?: number, contextOptionId?: number) => string;
|
|
10
10
|
export declare const parseDocumentNameWithVariables: TParseDocumentNameWithVariables;
|
|
11
11
|
export {};
|
|
@@ -98,7 +98,8 @@ var parseOutputWithVariables = function (output, index, variables, autonums) {
|
|
|
98
98
|
return parsedOutput;
|
|
99
99
|
};
|
|
100
100
|
exports.parseOutputWithVariables = parseOutputWithVariables;
|
|
101
|
-
var parseDocumentNameWithVariables = function (text, ovc, references, fallback) {
|
|
101
|
+
var parseDocumentNameWithVariables = function (text, ovc, references, fallback, index, contextOptionId) {
|
|
102
|
+
if (index === void 0) { index = 0; }
|
|
102
103
|
var tagsMatch = text.match(/\[var:([0-9]+)\]/gi);
|
|
103
104
|
var variables = [];
|
|
104
105
|
if (tagsMatch !== null) {
|
|
@@ -113,11 +114,22 @@ var parseDocumentNameWithVariables = function (text, ovc, references, fallback)
|
|
|
113
114
|
variables = variables.filter(function (c, i) { return variables.indexOf(c) === i; });
|
|
114
115
|
variables = variables.filter(function (c) { return ovc !== undefined || references.variables[c] !== undefined; });
|
|
115
116
|
var variablesValues = {};
|
|
116
|
-
|
|
117
|
-
var
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
if (typeof contextOptionId === "number") {
|
|
118
|
+
var relatedValues_1 = (0, exports.getRelatedVariablesValues)(contextOptionId, index, variables, ovc, references);
|
|
119
|
+
variables.forEach(function (variableId) {
|
|
120
|
+
var _a;
|
|
121
|
+
variablesValues[variableId] = ((_a = relatedValues_1[variableId]) !== null && _a !== void 0 ? _a : "").toString();
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
variables.forEach(function (variableId) {
|
|
126
|
+
var variableValues = ovc.variables[variableId];
|
|
127
|
+
var valueAtIndex = (variableValues === null || variableValues === void 0 ? void 0 : variableValues[index]) !== undefined
|
|
128
|
+
? variableValues[index]
|
|
129
|
+
: (variableValues === null || variableValues === void 0 ? void 0 : variableValues[0]) || "";
|
|
130
|
+
variablesValues[variableId] = (valueAtIndex !== null && valueAtIndex !== void 0 ? valueAtIndex : "").toString();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
121
133
|
var parsedText = "".concat(text);
|
|
122
134
|
variables.forEach(function (variableId) {
|
|
123
135
|
var value = variablesValues[variableId];
|
package/dist/libs/Prerender.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ModelV3 } from "@legalplace/models-v3-types";
|
|
2
|
-
import type
|
|
2
|
+
import { type Types } from "@legalplace/referencesparser";
|
|
3
3
|
import type OvcType from "@legalplace/types/dist/ovc";
|
|
4
4
|
import type InputsType from "@legalplace/types/dist/inputs";
|
|
5
|
-
import type { FDFType, DocumentIndex, DocumentOutputIndex, DocumentPdfFormIndex } from "../types/types";
|
|
5
|
+
import type { FDFType, DocumentIndex, DocumentOutputIndex, DocumentPdfFormIndex, DocumentLayout } from "../types/types";
|
|
6
6
|
declare class Prerender {
|
|
7
7
|
private references;
|
|
8
8
|
private ovc;
|
|
@@ -16,6 +16,9 @@ declare class Prerender {
|
|
|
16
16
|
getDocumentsIndexWithoutFdf(): DocumentIndex;
|
|
17
17
|
getDocumentsIndex(): DocumentIndex;
|
|
18
18
|
getDocument(documentNameHash: string): string | FDFType;
|
|
19
|
+
getDocumentLayout(documentNameHash: string): DocumentLayout;
|
|
20
|
+
private resolveDocumentOccurrenceName;
|
|
21
|
+
private getDocumentOccurrences;
|
|
19
22
|
private generateDocumentNamesHash;
|
|
20
23
|
private fillPdfForms;
|
|
21
24
|
private generateAllDocuments;
|
package/dist/libs/Prerender.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var referencesparser_1 = require("@legalplace/referencesparser");
|
|
7
17
|
var conditions_runner_1 = __importDefault(require("@legalplace/conditions-runner"));
|
|
8
18
|
var ovc_converter_1 = __importDefault(require("@legalplace/ovc-converter"));
|
|
19
|
+
var referencesparser_1 = require("@legalplace/referencesparser");
|
|
9
20
|
var crypto_1 = __importDefault(require("crypto"));
|
|
10
21
|
var DocumentRender_1 = __importDefault(require("./DocumentRender"));
|
|
11
22
|
var NumAuto_1 = __importDefault(require("./NumAuto"));
|
|
@@ -38,49 +49,109 @@ var Prerender = (function () {
|
|
|
38
49
|
return this.documentsIndex;
|
|
39
50
|
};
|
|
40
51
|
Prerender.prototype.getDocument = function (documentNameHash) {
|
|
52
|
+
var _a;
|
|
41
53
|
if (this.renderedDocuments[documentNameHash]) {
|
|
42
54
|
return this.renderedDocuments[documentNameHash];
|
|
43
55
|
}
|
|
44
56
|
var index = this.documentsIndex[documentNameHash];
|
|
57
|
+
var occurrenceIndex = (_a = index.occurrenceIndex) !== null && _a !== void 0 ? _a : 0;
|
|
45
58
|
this.renderedDocuments[documentNameHash] = Prerender.isPdfForm(index)
|
|
46
|
-
? this.pdfFiller.fillDocument(index.slug)
|
|
47
|
-
: this.documentRender.renderDocument(index.slug);
|
|
59
|
+
? this.pdfFiller.fillDocument(index.slug, occurrenceIndex)
|
|
60
|
+
: this.documentRender.renderDocument(index.slug, occurrenceIndex);
|
|
48
61
|
return this.renderedDocuments[documentNameHash];
|
|
49
62
|
};
|
|
63
|
+
Prerender.prototype.getDocumentLayout = function (documentNameHash) {
|
|
64
|
+
var _this = this;
|
|
65
|
+
var _a, _b;
|
|
66
|
+
var index = this.documentsIndex[documentNameHash];
|
|
67
|
+
var occurrenceIndex = (_a = index.occurrenceIndex) !== null && _a !== void 0 ? _a : 0;
|
|
68
|
+
var document = this.references.documents[index.slug];
|
|
69
|
+
var layoutParams = (_b = document.params) === null || _b === void 0 ? void 0 : _b.layout;
|
|
70
|
+
var renderRegion = function (role) {
|
|
71
|
+
var html = _this.documentRender.renderRegion(index.slug, role, occurrenceIndex);
|
|
72
|
+
return html.trim().length > 0 ? html : undefined;
|
|
73
|
+
};
|
|
74
|
+
var header = renderRegion("header");
|
|
75
|
+
var footer = renderRegion("footer");
|
|
76
|
+
var differentFirstPage = (layoutParams === null || layoutParams === void 0 ? void 0 : layoutParams.differentFirstPage) === true;
|
|
77
|
+
return {
|
|
78
|
+
header: header,
|
|
79
|
+
footer: footer,
|
|
80
|
+
firstPageHeader: differentFirstPage
|
|
81
|
+
? renderRegion("firstPageHeader")
|
|
82
|
+
: undefined,
|
|
83
|
+
firstPageFooter: differentFirstPage
|
|
84
|
+
? renderRegion("firstPageFooter")
|
|
85
|
+
: undefined,
|
|
86
|
+
differentFirstPage: differentFirstPage,
|
|
87
|
+
margins: layoutParams === null || layoutParams === void 0 ? void 0 : layoutParams.margins,
|
|
88
|
+
headerDistance: layoutParams === null || layoutParams === void 0 ? void 0 : layoutParams.headerDistance,
|
|
89
|
+
footerDistance: layoutParams === null || layoutParams === void 0 ? void 0 : layoutParams.footerDistance,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
Prerender.prototype.resolveDocumentOccurrenceName = function (document, docMultiple, occurrenceIndex) {
|
|
93
|
+
var baseName = (0, OutputParser_1.parseDocumentNameWithVariables)(document.name, this.ovc, this.references, document.fallbackName, occurrenceIndex, docMultiple.repeatOption);
|
|
94
|
+
var template = docMultiple.filenameTemplate;
|
|
95
|
+
if (typeof template !== "string" || template.trim().length === 0) {
|
|
96
|
+
return baseName;
|
|
97
|
+
}
|
|
98
|
+
var resolved = (0, OutputParser_1.parseDocumentNameWithVariables)(template, this.ovc, this.references, undefined, occurrenceIndex, docMultiple.repeatOption);
|
|
99
|
+
if (resolved.trim().length === 0)
|
|
100
|
+
return baseName;
|
|
101
|
+
return resolved;
|
|
102
|
+
};
|
|
103
|
+
Prerender.prototype.getDocumentOccurrences = function (slug) {
|
|
104
|
+
var _a;
|
|
105
|
+
var document = this.references.documents[slug];
|
|
106
|
+
var docMultiple = (_a = document.params) === null || _a === void 0 ? void 0 : _a.multiple;
|
|
107
|
+
if ((docMultiple === null || docMultiple === void 0 ? void 0 : docMultiple.enabled) !== true)
|
|
108
|
+
return [true];
|
|
109
|
+
var repeatOption = docMultiple.repeatOption;
|
|
110
|
+
if (typeof repeatOption !== "number")
|
|
111
|
+
return [true];
|
|
112
|
+
var inputs = this.ovc.options[String(repeatOption)];
|
|
113
|
+
if (!Array.isArray(inputs) || inputs.length === 0)
|
|
114
|
+
return [true];
|
|
115
|
+
return inputs;
|
|
116
|
+
};
|
|
50
117
|
Prerender.prototype.generateDocumentNamesHash = function () {
|
|
51
118
|
var _this = this;
|
|
52
119
|
Object.keys(this.references.documents).forEach(function (slug) {
|
|
53
|
-
var _a, _b;
|
|
54
120
|
var document = _this.references.documents[slug];
|
|
55
|
-
var documentParams =
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
121
|
+
var documentParams = document.params;
|
|
122
|
+
var docMultiple = documentParams === null || documentParams === void 0 ? void 0 : documentParams.multiple;
|
|
123
|
+
var isMultipleDocument = (docMultiple === null || docMultiple === void 0 ? void 0 : docMultiple.enabled) === true;
|
|
124
|
+
var occurrences = _this.getDocumentOccurrences(slug);
|
|
125
|
+
occurrences.forEach(function (occurrenceValue, occurrenceIndex) {
|
|
126
|
+
var _a, _b;
|
|
127
|
+
if (occurrenceValue !== true)
|
|
128
|
+
return;
|
|
129
|
+
var conditionObject = _this.references.conditions.documents[slug];
|
|
130
|
+
var documentSourceId = isMultipleDocument && typeof docMultiple.repeatOption === "number"
|
|
131
|
+
? docMultiple.repeatOption
|
|
132
|
+
: 0;
|
|
133
|
+
var condition = conditionObject === undefined
|
|
134
|
+
? true
|
|
135
|
+
: _this.conditions.executeCondition(conditionObject, documentSourceId, occurrenceIndex, "documents");
|
|
136
|
+
if (condition !== true)
|
|
137
|
+
return;
|
|
138
|
+
var seed = isMultipleDocument ? "".concat(slug, ":").concat(occurrenceIndex) : slug;
|
|
139
|
+
var hash = crypto_1.default.createHash("sha1").update(seed).digest("hex");
|
|
140
|
+
var name = isMultipleDocument && docMultiple
|
|
141
|
+
? _this.resolveDocumentOccurrenceName(document, docMultiple, occurrenceIndex)
|
|
142
|
+
: (0, OutputParser_1.parseDocumentNameWithVariables)(document.name, _this.ovc, _this.references, document.fallbackName);
|
|
62
143
|
if (typeof document.pdf === "object" &&
|
|
63
144
|
typeof document.pdf.id === "string" &&
|
|
64
145
|
typeof document.pdf.form === "object") {
|
|
65
|
-
_this.documentsIndex[hash] = {
|
|
66
|
-
name: (0, OutputParser_1.parseDocumentNameWithVariables)(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
67
|
-
slug: slug,
|
|
68
|
-
form: true,
|
|
69
|
-
fdf: {
|
|
146
|
+
_this.documentsIndex[hash] = __assign({ name: name, slug: slug, form: true, fdf: {
|
|
70
147
|
id: "",
|
|
71
148
|
fields: {},
|
|
72
|
-
},
|
|
73
|
-
};
|
|
149
|
+
} }, (isMultipleDocument ? { occurrenceIndex: occurrenceIndex } : {}));
|
|
74
150
|
}
|
|
75
151
|
else {
|
|
76
|
-
_this.documentsIndex[hash] = {
|
|
77
|
-
name: (0, OutputParser_1.parseDocumentNameWithVariables)(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
78
|
-
slug: slug,
|
|
79
|
-
pdf: ((_a = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _a === void 0 ? void 0 : _a.pdf) !== false,
|
|
80
|
-
docx: ((_b = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _b === void 0 ? void 0 : _b.docx) !== false,
|
|
81
|
-
};
|
|
152
|
+
_this.documentsIndex[hash] = __assign({ name: name, slug: slug, pdf: ((_a = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _a === void 0 ? void 0 : _a.pdf) !== false, docx: ((_b = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _b === void 0 ? void 0 : _b.docx) !== false }, (isMultipleDocument ? { occurrenceIndex: occurrenceIndex } : {}));
|
|
82
153
|
}
|
|
83
|
-
}
|
|
154
|
+
});
|
|
84
155
|
});
|
|
85
156
|
};
|
|
86
157
|
Prerender.prototype.fillPdfForms = function () {
|
|
@@ -95,13 +166,15 @@ var Prerender = (function () {
|
|
|
95
166
|
Prerender.prototype.generateAllDocuments = function () {
|
|
96
167
|
var _this = this;
|
|
97
168
|
Object.keys(this.documentsIndex).forEach(function (documentNameHash) {
|
|
169
|
+
var _a;
|
|
98
170
|
var index = _this.documentsIndex[documentNameHash];
|
|
171
|
+
var occurrenceIndex = (_a = index.occurrenceIndex) !== null && _a !== void 0 ? _a : 0;
|
|
99
172
|
if (Prerender.isPdfForm(index)) {
|
|
100
|
-
_this.renderedDocuments[documentNameHash] = _this.pdfFiller.fillDocument(
|
|
173
|
+
_this.renderedDocuments[documentNameHash] = _this.pdfFiller.fillDocument(index.slug, occurrenceIndex);
|
|
101
174
|
}
|
|
102
175
|
else {
|
|
103
176
|
_this.renderedDocuments[documentNameHash] =
|
|
104
|
-
_this.documentRender.renderDocument(
|
|
177
|
+
_this.documentRender.renderDocument(index.slug, occurrenceIndex);
|
|
105
178
|
}
|
|
106
179
|
});
|
|
107
180
|
};
|
|
@@ -9,6 +9,7 @@ declare class SectionRender {
|
|
|
9
9
|
documentName: string;
|
|
10
10
|
conditions: ConditionsRunner;
|
|
11
11
|
ovc: InputsType;
|
|
12
|
+
baseIndex: number;
|
|
12
13
|
private NumAuto;
|
|
13
14
|
constructor(options: {
|
|
14
15
|
references: Types.ReferencesType;
|
|
@@ -17,8 +18,10 @@ declare class SectionRender {
|
|
|
17
18
|
documentName: string;
|
|
18
19
|
currentSection: number;
|
|
19
20
|
numauto: NumAuto;
|
|
21
|
+
baseIndex?: number;
|
|
20
22
|
});
|
|
21
23
|
getOutputs(): string[];
|
|
24
|
+
private getDocumentMultipleSource;
|
|
22
25
|
private renderSection;
|
|
23
26
|
}
|
|
24
27
|
export default SectionRender;
|