@legalplace/prerenderx 3.8.24 → 3.9.0
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 +20 -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
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
var OptionRender_1 = __importDefault(require("./OptionRender"));
|
|
16
16
|
var SectionRender = (function () {
|
|
17
17
|
function SectionRender(options) {
|
|
18
|
+
var _a;
|
|
18
19
|
this.outputs = [];
|
|
19
20
|
this.references = options.references;
|
|
20
21
|
this.conditions = options.conditions;
|
|
@@ -22,47 +23,88 @@ var SectionRender = (function () {
|
|
|
22
23
|
this.currentSection = options.currentSection;
|
|
23
24
|
this.ovc = options.ovc;
|
|
24
25
|
this.NumAuto = options.numauto;
|
|
26
|
+
this.baseIndex = (_a = options.baseIndex) !== null && _a !== void 0 ? _a : 0;
|
|
25
27
|
this.renderSection();
|
|
26
28
|
}
|
|
27
29
|
SectionRender.prototype.getOutputs = function () {
|
|
28
30
|
return this.outputs;
|
|
29
31
|
};
|
|
32
|
+
SectionRender.prototype.getDocumentMultipleSource = function () {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
var docMultiple = (_b = (_a = this.references.documents[this.documentName]) === null || _a === void 0 ? void 0 : _a.params) === null || _b === void 0 ? void 0 : _b.multiple;
|
|
35
|
+
if ((docMultiple === null || docMultiple === void 0 ? void 0 : docMultiple.enabled) !== true)
|
|
36
|
+
return undefined;
|
|
37
|
+
return typeof docMultiple.repeatOption === "number"
|
|
38
|
+
? docMultiple.repeatOption
|
|
39
|
+
: undefined;
|
|
40
|
+
};
|
|
30
41
|
SectionRender.prototype.renderSection = function () {
|
|
31
42
|
var _this = this;
|
|
32
43
|
var section = this.references.sections[this.documentName][this.currentSection];
|
|
33
44
|
var conditionObject = this.references.conditions.sections[this.documentName][this.currentSection];
|
|
34
45
|
var condition = conditionObject === undefined
|
|
35
46
|
? true
|
|
36
|
-
: this.conditions.executeCondition(conditionObject, 0,
|
|
37
|
-
if (condition
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
? option.meta.repeatOption
|
|
47
|
-
: parseInt(option.meta.repeatOption, 10);
|
|
48
|
-
}
|
|
49
|
-
var inputs = _this.ovc.options[repeatOption] || [
|
|
50
|
-
!["radio", "checkbox"].includes(option.meta.type),
|
|
51
|
-
];
|
|
52
|
-
inputs.forEach(function (value, index) {
|
|
53
|
-
if (value !== true)
|
|
54
|
-
return;
|
|
47
|
+
: this.conditions.executeCondition(conditionObject, 0, this.baseIndex, "sections");
|
|
48
|
+
if (condition !== true)
|
|
49
|
+
return;
|
|
50
|
+
var documentMultipleSource = this.getDocumentMultipleSource();
|
|
51
|
+
section.options.forEach(function (optionId) {
|
|
52
|
+
var option = _this.references.options[optionId];
|
|
53
|
+
if (option.meta.type === "repeated" &&
|
|
54
|
+
documentMultipleSource !== undefined &&
|
|
55
|
+
option.meta.repeatOption === documentMultipleSource) {
|
|
56
|
+
option.options.forEach(function (childId) {
|
|
55
57
|
_this.outputs = __spreadArray(__spreadArray([], _this.outputs, true), new OptionRender_1.default({
|
|
56
58
|
references: _this.references,
|
|
57
|
-
id:
|
|
59
|
+
id: childId,
|
|
58
60
|
ovc: _this.ovc,
|
|
59
|
-
index:
|
|
61
|
+
index: _this.baseIndex,
|
|
60
62
|
conditions: _this.conditions,
|
|
61
63
|
numauto: _this.NumAuto,
|
|
62
64
|
}).getOutputs(), true);
|
|
63
65
|
});
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
var repeatOption = optionId;
|
|
69
|
+
if (option.meta.type === "repeated") {
|
|
70
|
+
if (option.meta.repeatOption === undefined)
|
|
71
|
+
return;
|
|
72
|
+
repeatOption =
|
|
73
|
+
typeof option.meta.repeatOption === "number"
|
|
74
|
+
? option.meta.repeatOption
|
|
75
|
+
: parseInt(option.meta.repeatOption, 10);
|
|
76
|
+
}
|
|
77
|
+
var inputs = _this.ovc.options[repeatOption] || [
|
|
78
|
+
!["radio", "checkbox"].includes(option.meta.type),
|
|
79
|
+
];
|
|
80
|
+
if (documentMultipleSource !== undefined &&
|
|
81
|
+
option.meta.type !== "repeated") {
|
|
82
|
+
var valueAtIndex = _this.baseIndex < inputs.length ? inputs[_this.baseIndex] : inputs[0];
|
|
83
|
+
if (valueAtIndex !== true)
|
|
84
|
+
return;
|
|
85
|
+
_this.outputs = __spreadArray(__spreadArray([], _this.outputs, true), new OptionRender_1.default({
|
|
86
|
+
references: _this.references,
|
|
87
|
+
id: optionId,
|
|
88
|
+
ovc: _this.ovc,
|
|
89
|
+
index: _this.baseIndex,
|
|
90
|
+
conditions: _this.conditions,
|
|
91
|
+
numauto: _this.NumAuto,
|
|
92
|
+
}).getOutputs(), true);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
inputs.forEach(function (value, index) {
|
|
96
|
+
if (value !== true)
|
|
97
|
+
return;
|
|
98
|
+
_this.outputs = __spreadArray(__spreadArray([], _this.outputs, true), new OptionRender_1.default({
|
|
99
|
+
references: _this.references,
|
|
100
|
+
id: optionId,
|
|
101
|
+
ovc: _this.ovc,
|
|
102
|
+
index: index,
|
|
103
|
+
conditions: _this.conditions,
|
|
104
|
+
numauto: _this.NumAuto,
|
|
105
|
+
}).getOutputs(), true);
|
|
64
106
|
});
|
|
65
|
-
}
|
|
107
|
+
});
|
|
66
108
|
};
|
|
67
109
|
return SectionRender;
|
|
68
110
|
}());
|
|
@@ -6,11 +6,11 @@ declare class FillPdfFormBase {
|
|
|
6
6
|
conditions: ConditionsRunner;
|
|
7
7
|
ovc: InputsType;
|
|
8
8
|
constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: InputsType);
|
|
9
|
+
private readonly conditionEvaluator;
|
|
9
10
|
isVariableDisplayed(id: number, index: number): boolean;
|
|
10
11
|
isOptionDisplayed(id: number, index: number): boolean;
|
|
11
12
|
private getVariableCondition;
|
|
12
13
|
private getOptionCondition;
|
|
13
14
|
private getSectionCondition;
|
|
14
|
-
private getOptionParentSection;
|
|
15
15
|
}
|
|
16
16
|
export default FillPdfFormBase;
|
|
@@ -1,41 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var referencesparser_1 = require("@legalplace/referencesparser");
|
|
12
4
|
var FillPdfFormBase = (function () {
|
|
13
5
|
function FillPdfFormBase(references, conditions, ovc) {
|
|
6
|
+
var _this = this;
|
|
7
|
+
this.conditionEvaluator = function (type, id, index) {
|
|
8
|
+
if (type === "options")
|
|
9
|
+
return _this.getOptionCondition(id, index);
|
|
10
|
+
if (type === "variables")
|
|
11
|
+
return _this.getVariableCondition(id, index);
|
|
12
|
+
return _this.getSectionCondition(id);
|
|
13
|
+
};
|
|
14
14
|
this.references = references;
|
|
15
15
|
this.conditions = conditions;
|
|
16
16
|
this.ovc = ovc;
|
|
17
17
|
}
|
|
18
18
|
FillPdfFormBase.prototype.isVariableDisplayed = function (id, index) {
|
|
19
|
-
|
|
20
|
-
var variableCondition = this.getVariableCondition(id, index);
|
|
21
|
-
var variableParents = ((_a = this.references.relations.variables[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
|
|
22
|
-
var parentOptionIsDisplayed = this.isOptionDisplayed(variableParents[0], index);
|
|
23
|
-
return ([variableCondition, parentOptionIsDisplayed].filter(function (c) { return c !== true; })
|
|
24
|
-
.length === 0);
|
|
19
|
+
return (0, referencesparser_1.isVariableDisplayed)(this.references, this.ovc, this.conditionEvaluator, id, index);
|
|
25
20
|
};
|
|
26
21
|
FillPdfFormBase.prototype.isOptionDisplayed = function (id, index) {
|
|
27
|
-
|
|
28
|
-
var _a;
|
|
29
|
-
var optionCondition = this.getOptionCondition(id, index);
|
|
30
|
-
var optionParents = ((_a = this.references.relations.options[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
|
|
31
|
-
var parentsConditions = optionParents.map(function (optionId) { return _this.getOptionCondition(optionId, index) !== false; });
|
|
32
|
-
var parentsInputs = optionParents.map(function (optionId) { return _this.ovc.options[optionId][index]; });
|
|
33
|
-
var parentSectionId = this.getOptionParentSection(id);
|
|
34
|
-
var parentSectionCondition = this.getSectionCondition(parentSectionId) !== false;
|
|
35
|
-
return (__spreadArray(__spreadArray([
|
|
36
|
-
optionCondition,
|
|
37
|
-
parentSectionCondition
|
|
38
|
-
], parentsConditions, true), parentsInputs, true).filter(function (c) { return c !== true; }).length === 0);
|
|
22
|
+
return (0, referencesparser_1.isOptionDisplayed)(this.references, this.ovc, this.conditionEvaluator, id, index);
|
|
39
23
|
};
|
|
40
24
|
FillPdfFormBase.prototype.getVariableCondition = function (id, index) {
|
|
41
25
|
var conditionObject = this.references.conditions.variables[id];
|
|
@@ -55,16 +39,6 @@ var FillPdfFormBase = (function () {
|
|
|
55
39
|
? true
|
|
56
40
|
: this.conditions.executeCondition(conditionObject, id, 0, "sections");
|
|
57
41
|
};
|
|
58
|
-
FillPdfFormBase.prototype.getOptionParentSection = function (id) {
|
|
59
|
-
var parents = this.references.relations.options[id].parents;
|
|
60
|
-
var rootId = parents.length > 0 ? parents[parents.length - 1] : id;
|
|
61
|
-
var sections = Object.values(this.references.sections.main);
|
|
62
|
-
for (var i = 0; i < sections.length; i += 1) {
|
|
63
|
-
if (sections[i].options.includes(rootId))
|
|
64
|
-
return sections[i].id;
|
|
65
|
-
}
|
|
66
|
-
throw new Error("Cannot find parent section for option ".concat(id, " (Root option id: ").concat(rootId, ")"));
|
|
67
|
-
};
|
|
68
42
|
return FillPdfFormBase;
|
|
69
43
|
}());
|
|
70
44
|
exports.default = FillPdfFormBase;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ConditionV3 } from "@legalplace/models-v3-types";
|
|
2
|
+
import type ConditionsRunner from "@legalplace/conditions-runner";
|
|
3
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
4
|
+
import { type ExpandTableMarkupContext } from "@legalplace/referencesparser";
|
|
5
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
6
|
+
export declare const evaluateInlineTableCondition: (condition: ConditionV3, contextOptionId: number, occurrenceIndex: number, conditionsRunner: ConditionsRunner, references: Types.ReferencesType, ovc: InputsType) => boolean;
|
|
7
|
+
type CreateTableMarkupContextParams = {
|
|
8
|
+
references: Types.ReferencesType;
|
|
9
|
+
ovc: InputsType;
|
|
10
|
+
conditions: ConditionsRunner;
|
|
11
|
+
contextOptionId: number;
|
|
12
|
+
defaultOccurrenceIndex: number;
|
|
13
|
+
};
|
|
14
|
+
export declare const createTableMarkupContext: ({ references, ovc, conditions, contextOptionId, defaultOccurrenceIndex, }: CreateTableMarkupContextParams) => ExpandTableMarkupContext;
|
|
15
|
+
type ExpandOutputTableMarkupParams = CreateTableMarkupContextParams & {
|
|
16
|
+
output: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const expandOutputTableMarkup: ({ output, references, ovc, conditions, contextOptionId, defaultOccurrenceIndex, }: ExpandOutputTableMarkupParams) => string;
|
|
19
|
+
export declare const cleanupRenderedOutputHtml: (output: string) => string;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cleanupRenderedOutputHtml = exports.expandOutputTableMarkup = exports.createTableMarkupContext = exports.evaluateInlineTableCondition = void 0;
|
|
7
|
+
var lplogic_1 = __importDefault(require("@legalplace/lplogic"));
|
|
8
|
+
var DataPopulator_1 = __importDefault(require("@legalplace/conditions-runner/dist/DataPopulator"));
|
|
9
|
+
var referencesparser_1 = require("@legalplace/referencesparser");
|
|
10
|
+
var OutputParser_1 = require("./OutputParser");
|
|
11
|
+
var extractVariableIds = function (html) {
|
|
12
|
+
var matches = html.match(/\[var:([0-9]+)\]/gi);
|
|
13
|
+
if (matches === null)
|
|
14
|
+
return [];
|
|
15
|
+
return Array.from(new Set(matches.map(function (tag) {
|
|
16
|
+
var idMatch = tag.match(/([0-9]+)/);
|
|
17
|
+
return idMatch ? parseInt(idMatch[1], 10) : 0;
|
|
18
|
+
}))).filter(function (id) { return id > 0; });
|
|
19
|
+
};
|
|
20
|
+
var evaluateInlineTableCondition = function (condition, contextOptionId, occurrenceIndex, conditionsRunner, references, ovc) {
|
|
21
|
+
var dataMap = (0, referencesparser_1.extractConditionDataMap)(condition);
|
|
22
|
+
var currentData = new DataPopulator_1.default(conditionsRunner, references, ovc, dataMap, contextOptionId, occurrenceIndex).getData();
|
|
23
|
+
var result = (0, lplogic_1.default)((0, referencesparser_1.stripConditionUiMetadata)(condition), currentData);
|
|
24
|
+
return result !== false;
|
|
25
|
+
};
|
|
26
|
+
exports.evaluateInlineTableCondition = evaluateInlineTableCondition;
|
|
27
|
+
var createTableMarkupContext = function (_a) {
|
|
28
|
+
var references = _a.references, ovc = _a.ovc, conditions = _a.conditions, contextOptionId = _a.contextOptionId, defaultOccurrenceIndex = _a.defaultOccurrenceIndex;
|
|
29
|
+
return ({
|
|
30
|
+
defaultContextOptionId: contextOptionId,
|
|
31
|
+
defaultOccurrenceIndex: defaultOccurrenceIndex,
|
|
32
|
+
getOccurrenceInputs: function (multipleOptionId) {
|
|
33
|
+
return ovc.options[String(multipleOptionId)] || [];
|
|
34
|
+
},
|
|
35
|
+
evaluateCondition: function (condition, multipleOptionId, occurrenceIndex) {
|
|
36
|
+
return (0, exports.evaluateInlineTableCondition)(condition, multipleOptionId, occurrenceIndex, conditions, references, ovc);
|
|
37
|
+
},
|
|
38
|
+
substituteVariables: function (html, multipleOptionId, occurrenceIndex) {
|
|
39
|
+
var variableIds = extractVariableIds(html);
|
|
40
|
+
var variables = (0, OutputParser_1.getRelatedVariablesValues)(multipleOptionId, occurrenceIndex, variableIds, ovc, references);
|
|
41
|
+
return (0, OutputParser_1.parseOutputWithVariables)(html, occurrenceIndex, variables, []);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
exports.createTableMarkupContext = createTableMarkupContext;
|
|
46
|
+
var expandOutputTableMarkup = function (_a) {
|
|
47
|
+
var output = _a.output, references = _a.references, ovc = _a.ovc, conditions = _a.conditions, contextOptionId = _a.contextOptionId, defaultOccurrenceIndex = _a.defaultOccurrenceIndex;
|
|
48
|
+
if (!(0, referencesparser_1.hasTableDynamicMarkup)(output))
|
|
49
|
+
return output;
|
|
50
|
+
return (0, referencesparser_1.expandTableMarkup)(output, (0, exports.createTableMarkupContext)({
|
|
51
|
+
references: references,
|
|
52
|
+
ovc: ovc,
|
|
53
|
+
conditions: conditions,
|
|
54
|
+
contextOptionId: contextOptionId,
|
|
55
|
+
defaultOccurrenceIndex: defaultOccurrenceIndex,
|
|
56
|
+
}));
|
|
57
|
+
};
|
|
58
|
+
exports.expandOutputTableMarkup = expandOutputTableMarkup;
|
|
59
|
+
var cleanupRenderedOutputHtml = function (output) {
|
|
60
|
+
if (output.includes("<table")) {
|
|
61
|
+
return output.replace(/\xA0/g, " ");
|
|
62
|
+
}
|
|
63
|
+
return output
|
|
64
|
+
.replace(/<\/([a-z]+)>([\n\s]+)</gi, "</$1><")
|
|
65
|
+
.replace(/\n/g, "<br />")
|
|
66
|
+
.replace(/\xA0/g, " ");
|
|
67
|
+
};
|
|
68
|
+
exports.cleanupRenderedOutputHtml = cleanupRenderedOutputHtml;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
|
+
import type { DocumentLayoutV3 } from "@legalplace/models-v3-types";
|
|
1
2
|
export type DocumentOutputIndex = {
|
|
2
3
|
name: string;
|
|
3
4
|
slug: string;
|
|
4
5
|
pdf: boolean;
|
|
5
6
|
docx: boolean;
|
|
7
|
+
occurrenceIndex?: number;
|
|
6
8
|
};
|
|
7
9
|
export type DocumentPdfFormIndex = {
|
|
8
10
|
name: string;
|
|
9
11
|
slug: string;
|
|
10
12
|
form: boolean;
|
|
11
13
|
fdf: FDFType;
|
|
14
|
+
occurrenceIndex?: number;
|
|
12
15
|
};
|
|
13
16
|
export type DocumentIndex = Record<string, DocumentOutputIndex | DocumentPdfFormIndex>;
|
|
14
17
|
export type FDFType = {
|
|
15
18
|
id: string;
|
|
16
19
|
fields: Record<string, string>;
|
|
17
20
|
};
|
|
21
|
+
export type DocumentLayout = {
|
|
22
|
+
header?: string;
|
|
23
|
+
footer?: string;
|
|
24
|
+
firstPageHeader?: string;
|
|
25
|
+
firstPageFooter?: string;
|
|
26
|
+
differentFirstPage: boolean;
|
|
27
|
+
margins?: DocumentLayoutV3["margins"];
|
|
28
|
+
headerDistance?: number;
|
|
29
|
+
footerDistance?: number;
|
|
30
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legalplace/prerenderx",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "PrerenderX",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": "https://git.legalplace.eu/legalplace/prerenderx",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"release": "standard-version -a --no-verify"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@legalplace/conditions-runner": "^2.
|
|
20
|
-
"@legalplace/lplogic": "2.3.
|
|
21
|
-
"@legalplace/models-v3-types": "^5.
|
|
22
|
-
"@legalplace/ovc-converter": "^2.2.
|
|
23
|
-
"@legalplace/referencesparser": "^3.
|
|
19
|
+
"@legalplace/conditions-runner": "^2.3.0",
|
|
20
|
+
"@legalplace/lplogic": "2.3.3",
|
|
21
|
+
"@legalplace/models-v3-types": "^5.18.0",
|
|
22
|
+
"@legalplace/ovc-converter": "^2.2.21",
|
|
23
|
+
"@legalplace/referencesparser": "^3.3.0",
|
|
24
24
|
"@legalplace/yousign": "^0.9.23",
|
|
25
25
|
"crypto": "^1.0.1"
|
|
26
26
|
},
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@babel/preset-typescript": "^7.7.2",
|
|
30
30
|
"@legalplace/eslint-config-base": "^1.2.0",
|
|
31
31
|
"@legalplace/prettier-config": "^2.1.3",
|
|
32
|
-
"@legalplace/types": "^2.22.
|
|
32
|
+
"@legalplace/types": "^2.22.13",
|
|
33
33
|
"@types/jest": "^24.0.15",
|
|
34
34
|
"jest": "^24.8.0",
|
|
35
35
|
"redux-mock-store": "^1.5.3",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"ts-jest": "^24.0.2"
|
|
38
38
|
},
|
|
39
39
|
"prettier": "@legalplace/prettier-config",
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "5b5eed67e9a7815f5fa77492782158fa6af0ca13"
|
|
41
41
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import type { Types } from "@legalplace/referencesparser";
|
|
2
1
|
import type ConditionsRunner from "@legalplace/conditions-runner";
|
|
2
|
+
import {
|
|
3
|
+
getSectionIdsForRole,
|
|
4
|
+
type OutputRegionRole,
|
|
5
|
+
type Types,
|
|
6
|
+
} from "@legalplace/referencesparser";
|
|
3
7
|
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
8
|
import SectionRender from "./SectionRender";
|
|
5
9
|
import type NumAuto from "./NumAuto";
|
|
@@ -25,18 +29,42 @@ class DocumentRender {
|
|
|
25
29
|
this.NumAuto = numauto;
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Renders a document body. When `baseIndex` is provided (document multiple),
|
|
34
|
+
* the index is propagated through the section/option render pipeline
|
|
35
|
+
* so that variables referenced anywhere in the document resolve at the
|
|
36
|
+
* correct occurrence.
|
|
37
|
+
*/
|
|
38
|
+
public renderDocument(documentName: string, baseIndex = 0) {
|
|
39
|
+
return this.renderRegion(documentName, "body", baseIndex);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Renders a document output region (body, header, footer, first page variants).
|
|
44
|
+
*/
|
|
45
|
+
public renderRegion(
|
|
46
|
+
documentName: string,
|
|
47
|
+
role: OutputRegionRole,
|
|
48
|
+
baseIndex = 0
|
|
49
|
+
) {
|
|
29
50
|
const documentOutputs: string[] = [];
|
|
30
|
-
this.NumAuto.resetIndexes();
|
|
31
|
-
|
|
51
|
+
if (role === "body") this.NumAuto.resetIndexes();
|
|
52
|
+
|
|
53
|
+
const sectionIds = getSectionIdsForRole(
|
|
54
|
+
this.references.sections[documentName],
|
|
55
|
+
role
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
sectionIds.forEach((sectionId) => {
|
|
32
59
|
documentOutputs.push(
|
|
33
60
|
...new SectionRender({
|
|
34
61
|
references: this.references,
|
|
35
62
|
conditions: this.conditions,
|
|
36
63
|
documentName,
|
|
37
64
|
ovc: this.ovc,
|
|
38
|
-
currentSection:
|
|
65
|
+
currentSection: sectionId,
|
|
39
66
|
numauto: this.NumAuto,
|
|
67
|
+
baseIndex,
|
|
40
68
|
}).getOutputs()
|
|
41
69
|
);
|
|
42
70
|
});
|
package/src/libs/FillPdfForm.ts
CHANGED
|
@@ -6,7 +6,13 @@ type FDFType = {
|
|
|
6
6
|
fields: Record<string, string>;
|
|
7
7
|
};
|
|
8
8
|
class FillPdfForm extends FillPdfFormBase {
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Fills a PDF form template with values from `ovc`. When `baseIndex` is
|
|
11
|
+
* provided (document multiple), variables and options are read at that
|
|
12
|
+
* occurrence index instead of always reading slot 0. Each occurrence of
|
|
13
|
+
* a multiple PDF form document yields its own filled FDF.
|
|
14
|
+
*/
|
|
15
|
+
public fillDocument(documentName: string, baseIndex = 0) {
|
|
10
16
|
const result: FDFType = {
|
|
11
17
|
id: "",
|
|
12
18
|
fields: {},
|
|
@@ -24,13 +30,13 @@ class FillPdfForm extends FillPdfFormBase {
|
|
|
24
30
|
// Filling inputs
|
|
25
31
|
form.inputs.forEach((input) => {
|
|
26
32
|
const id = `${input.name}`;
|
|
27
|
-
result.fields[id] = this.getInputValue(input);
|
|
33
|
+
result.fields[id] = this.getInputValue(input, baseIndex);
|
|
28
34
|
});
|
|
29
35
|
|
|
30
36
|
// Filling boxes
|
|
31
37
|
form.boxes.forEach((box) => {
|
|
32
38
|
const id = `${box.name}`;
|
|
33
|
-
const value = this.getBoxValue(box);
|
|
39
|
+
const value = this.getBoxValue(box, baseIndex);
|
|
34
40
|
if (
|
|
35
41
|
!(
|
|
36
42
|
value === "" &&
|
|
@@ -44,13 +50,14 @@ class FillPdfForm extends FillPdfFormBase {
|
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
/**
|
|
47
|
-
* Returns an input value
|
|
53
|
+
* Returns an input value at the given occurrence `index`.
|
|
48
54
|
* @param input Input
|
|
55
|
+
* @param index Occurrence index (defaults to 0)
|
|
49
56
|
*/
|
|
50
|
-
private getInputValue(input: FDFInputsV3): string {
|
|
57
|
+
private getInputValue(input: FDFInputsV3, index = 0): string {
|
|
51
58
|
for (let i = 0; i < input.variables.length; i += 1) {
|
|
52
59
|
const variable = input.variables[i];
|
|
53
|
-
const currentValue = this.getVariableValue(variable.id);
|
|
60
|
+
const currentValue = this.getVariableValue(variable.id, index);
|
|
54
61
|
|
|
55
62
|
if (currentValue !== false) {
|
|
56
63
|
// Date values
|
|
@@ -110,13 +117,14 @@ class FillPdfForm extends FillPdfFormBase {
|
|
|
110
117
|
}
|
|
111
118
|
|
|
112
119
|
/**
|
|
113
|
-
* Return a box value
|
|
120
|
+
* Return a box value at the given occurrence `index`.
|
|
114
121
|
* @param box Box
|
|
122
|
+
* @param index Occurrence index (defaults to 0)
|
|
115
123
|
*/
|
|
116
|
-
private getBoxValue(box: FDFBoxesV3): string {
|
|
124
|
+
private getBoxValue(box: FDFBoxesV3, index = 0): string {
|
|
117
125
|
for (let i = 0; i < box.options.length; i += 1) {
|
|
118
126
|
const option = box.options[i];
|
|
119
|
-
const currentValue = this.getOptionValue(option.id);
|
|
127
|
+
const currentValue = this.getOptionValue(option.id, index);
|
|
120
128
|
|
|
121
129
|
if (currentValue === true) {
|
|
122
130
|
if (
|
|
@@ -132,25 +140,34 @@ class FillPdfForm extends FillPdfFormBase {
|
|
|
132
140
|
}
|
|
133
141
|
|
|
134
142
|
/**
|
|
135
|
-
* Returns a variable's value
|
|
143
|
+
* Returns a variable's value at the given occurrence `index`. Falls back
|
|
144
|
+
* to slot 0 when the requested index is missing (e.g. a non-multiple
|
|
145
|
+
* variable inside a multiple document).
|
|
136
146
|
*/
|
|
137
|
-
private getVariableValue(variableId: number) {
|
|
138
|
-
// Checking if variable is displayed
|
|
139
|
-
if (this.isVariableDisplayed(variableId,
|
|
147
|
+
private getVariableValue(variableId: number, index = 0) {
|
|
148
|
+
// Checking if variable is displayed at the given occurrence
|
|
149
|
+
if (this.isVariableDisplayed(variableId, index) === false) return false;
|
|
140
150
|
|
|
141
|
-
|
|
142
|
-
|
|
151
|
+
const variableValues = this.ovc.variables[variableId];
|
|
152
|
+
const value =
|
|
153
|
+
variableValues?.[index] !== undefined
|
|
154
|
+
? variableValues[index]
|
|
155
|
+
: variableValues?.[0] || "";
|
|
156
|
+
|
|
157
|
+
return (value ?? "").toString();
|
|
143
158
|
}
|
|
144
159
|
|
|
145
160
|
/**
|
|
146
|
-
* Returns
|
|
161
|
+
* Returns an option's boolean value at the given occurrence `index`.
|
|
147
162
|
*/
|
|
148
|
-
private getOptionValue(optionId: number) {
|
|
149
|
-
// Checking if option is displayed
|
|
150
|
-
if (this.isOptionDisplayed(optionId,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return
|
|
163
|
+
private getOptionValue(optionId: number, index = 0) {
|
|
164
|
+
// Checking if option is displayed at the given occurrence
|
|
165
|
+
if (this.isOptionDisplayed(optionId, index) === false) return false;
|
|
166
|
+
|
|
167
|
+
const optionValues = this.ovc.options[optionId];
|
|
168
|
+
return optionValues?.[index] !== undefined
|
|
169
|
+
? optionValues[index] === true
|
|
170
|
+
: optionValues?.[0] === true;
|
|
154
171
|
}
|
|
155
172
|
}
|
|
156
173
|
|