@legalplace/prerenderx 3.8.24-staging.0 → 3.8.24

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/libs/DocumentRender.d.ts +2 -3
  3. package/dist/libs/DocumentRender.js +4 -13
  4. package/dist/libs/FillPdfForm.d.ts +1 -1
  5. package/dist/libs/FillPdfForm.js +15 -25
  6. package/dist/libs/OptionRender.d.ts +0 -4
  7. package/dist/libs/OptionRender.js +29 -125
  8. package/dist/libs/OutputParser.d.ts +1 -1
  9. package/dist/libs/OutputParser.js +6 -18
  10. package/dist/libs/Prerender.d.ts +2 -5
  11. package/dist/libs/Prerender.js +27 -100
  12. package/dist/libs/SectionRender.d.ts +0 -3
  13. package/dist/libs/SectionRender.js +22 -64
  14. package/dist/libs/misc/FillPdfFormBase.d.ts +1 -1
  15. package/dist/libs/misc/FillPdfFormBase.js +37 -11
  16. package/dist/types/types.d.ts +0 -13
  17. package/package.json +10 -9
  18. package/src/libs/DocumentRender.ts +5 -33
  19. package/src/libs/FillPdfForm.ts +22 -39
  20. package/src/libs/OptionRender.ts +63 -218
  21. package/src/libs/OutputParser.ts +9 -40
  22. package/src/libs/Prerender.ts +38 -157
  23. package/src/libs/SectionRender.ts +28 -111
  24. package/src/libs/misc/FillPdfFormBase.ts +67 -34
  25. package/src/types/types.ts +0 -27
  26. package/.yalc/@legalplace/models-v3-types/.eslintrc +0 -3
  27. package/.yalc/@legalplace/models-v3-types/.gitlab-ci.yml +0 -30
  28. package/.yalc/@legalplace/models-v3-types/CHANGELOG.md +0 -1503
  29. package/.yalc/@legalplace/models-v3-types/README +0 -6
  30. package/.yalc/@legalplace/models-v3-types/index.ts +0 -915
  31. package/.yalc/@legalplace/models-v3-types/package.json +0 -16
  32. package/.yalc/@legalplace/models-v3-types/schema.json +0 -2918
  33. package/.yalc/@legalplace/models-v3-types/tsconfig.json +0 -22
  34. package/.yalc/@legalplace/models-v3-types/yalc.sig +0 -1
  35. package/dist/libs/outputTableRendering.d.ts +0 -16
  36. package/dist/libs/outputTableRendering.js +0 -130
  37. package/dist/libs/regionHelpers.d.ts +0 -5
  38. package/dist/libs/regionHelpers.js +0 -22
  39. package/dist/libs/tableOutputExpansion.d.ts +0 -20
  40. package/dist/libs/tableOutputExpansion.js +0 -68
  41. package/src/libs/tableOutputExpansion.ts +0 -145
  42. package/tests/Prerender.documentMultiple.test.ts +0 -276
  43. package/tests/Prerender.repeated.test.ts +0 -115
  44. package/yalc.lock +0 -10
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
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.8.24](https://git.legalplace.eu/legalplace/prerenderx/compare/@legalplace/prerenderx@3.8.23...@legalplace/prerenderx@3.8.24) (2026-08-27)
7
+
8
+ **Note:** Version bump only for package @legalplace/prerenderx
9
+
10
+
11
+
12
+
13
+
6
14
  ## [3.8.23](https://git.legalplace.eu/legalplace/prerenderx/compare/@legalplace/prerenderx@3.8.22...@legalplace/prerenderx@3.8.23) (2026-08-26)
7
15
 
8
16
  **Note:** Version bump only for package @legalplace/prerenderx
@@ -1,5 +1,5 @@
1
+ import type { Types } from "@legalplace/referencesparser";
1
2
  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,7 +8,6 @@ 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, baseIndex?: number): string;
12
- renderRegion(documentName: string, role: OutputRegionRole, baseIndex?: number): string;
11
+ renderDocument(documentName: string): string;
13
12
  }
14
13
  export default DocumentRender;
@@ -3,7 +3,6 @@ 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");
7
6
  var SectionRender_1 = __importDefault(require("./SectionRender"));
8
7
  var DocumentRender = (function () {
9
8
  function DocumentRender(references, conditions, ovc, numauto) {
@@ -12,26 +11,18 @@ var DocumentRender = (function () {
12
11
  this.ovc = ovc;
13
12
  this.NumAuto = numauto;
14
13
  }
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) {
14
+ DocumentRender.prototype.renderDocument = function (documentName) {
20
15
  var _this = this;
21
- if (baseIndex === void 0) { baseIndex = 0; }
22
16
  var documentOutputs = [];
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) {
17
+ this.NumAuto.resetIndexes();
18
+ Object.keys(this.references.sections[documentName]).forEach(function (sectionId) {
27
19
  documentOutputs.push.apply(documentOutputs, new SectionRender_1.default({
28
20
  references: _this.references,
29
21
  conditions: _this.conditions,
30
22
  documentName: documentName,
31
23
  ovc: _this.ovc,
32
- currentSection: sectionId,
24
+ currentSection: parseInt(sectionId, 10),
33
25
  numauto: _this.NumAuto,
34
- baseIndex: baseIndex,
35
26
  }).getOutputs());
36
27
  });
37
28
  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, baseIndex?: number): FDFType;
7
+ fillDocument(documentName: string): FDFType;
8
8
  private getInputValue;
9
9
  private getBoxValue;
10
10
  private getVariableValue;
@@ -24,9 +24,8 @@ 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, baseIndex) {
27
+ FillPdfForm.prototype.fillDocument = function (documentName) {
28
28
  var _this = this;
29
- if (baseIndex === void 0) { baseIndex = 0; }
30
29
  var result = {
31
30
  id: "",
32
31
  fields: {},
@@ -39,22 +38,21 @@ var FillPdfForm = (function (_super) {
39
38
  result.id = pdf.id;
40
39
  form.inputs.forEach(function (input) {
41
40
  var id = "".concat(input.name);
42
- result.fields[id] = _this.getInputValue(input, baseIndex);
41
+ result.fields[id] = _this.getInputValue(input);
43
42
  });
44
43
  form.boxes.forEach(function (box) {
45
44
  var id = "".concat(box.name);
46
- var value = _this.getBoxValue(box, baseIndex);
45
+ var value = _this.getBoxValue(box);
47
46
  if (!(value === "" &&
48
47
  Object.prototype.hasOwnProperty.call(result.fields, id)))
49
48
  result.fields[id] = value;
50
49
  });
51
50
  return result;
52
51
  };
53
- FillPdfForm.prototype.getInputValue = function (input, index) {
54
- if (index === void 0) { index = 0; }
52
+ FillPdfForm.prototype.getInputValue = function (input) {
55
53
  for (var i = 0; i < input.variables.length; i += 1) {
56
54
  var variable = input.variables[i];
57
- var currentValue = this.getVariableValue(variable.id, index);
55
+ var currentValue = this.getVariableValue(variable.id);
58
56
  if (currentValue !== false) {
59
57
  var dateRegex = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
60
58
  if (variable.date && dateRegex.test(currentValue)) {
@@ -99,11 +97,10 @@ var FillPdfForm = (function (_super) {
99
97
  }
100
98
  return "";
101
99
  };
102
- FillPdfForm.prototype.getBoxValue = function (box, index) {
103
- if (index === void 0) { index = 0; }
100
+ FillPdfForm.prototype.getBoxValue = function (box) {
104
101
  for (var i = 0; i < box.options.length; i += 1) {
105
102
  var option = box.options[i];
106
- var currentValue = this.getOptionValue(option.id, index);
103
+ var currentValue = this.getOptionValue(option.id);
107
104
  if (currentValue === true) {
108
105
  if (this.references.options[option.id].meta.type === "checkbox" &&
109
106
  box.value === "Off")
@@ -113,24 +110,17 @@ var FillPdfForm = (function (_super) {
113
110
  }
114
111
  return "";
115
112
  };
116
- FillPdfForm.prototype.getVariableValue = function (variableId, index) {
117
- if (index === void 0) { index = 0; }
118
- if (this.isVariableDisplayed(variableId, index) === false)
113
+ FillPdfForm.prototype.getVariableValue = function (variableId) {
114
+ var _a;
115
+ if (this.isVariableDisplayed(variableId, 0) === false)
119
116
  return false;
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();
117
+ return (((_a = this.ovc.variables[variableId]) === null || _a === void 0 ? void 0 : _a[0]) || "").toString();
125
118
  };
126
- FillPdfForm.prototype.getOptionValue = function (optionId, index) {
127
- if (index === void 0) { index = 0; }
128
- if (this.isOptionDisplayed(optionId, index) === false)
119
+ FillPdfForm.prototype.getOptionValue = function (optionId) {
120
+ var _a;
121
+ if (this.isOptionDisplayed(optionId, 0) === false)
129
122
  return false;
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;
123
+ return ((_a = this.ovc.options[optionId]) === null || _a === void 0 ? void 0 : _a[0]) === true;
134
124
  };
135
125
  return FillPdfForm;
136
126
  }(FillPdfFormBase_1.default));
@@ -19,10 +19,6 @@ 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;
26
22
  private renderOption;
27
23
  private renderChildren;
28
24
  }
@@ -9,9 +9,7 @@ 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");
13
12
  var OutputParser_1 = require("./OutputParser");
14
- var tableOutputExpansion_1 = require("./tableOutputExpansion");
15
13
  var OptionRender = (function () {
16
14
  function OptionRender(options) {
17
15
  this.outputs = [];
@@ -26,139 +24,45 @@ var OptionRender = (function () {
26
24
  OptionRender.prototype.getOutputs = function () {
27
25
  return this.outputs;
28
26
  };
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
- };
101
27
  OptionRender.prototype.renderOption = function () {
102
28
  var _this = this;
103
29
  var option = this.references.options[this.id];
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));
30
+ var conditionObject = this.references.conditions.options[this.id];
31
+ var condition = conditionObject === undefined
32
+ ? true
33
+ : this.conditions.executeCondition(conditionObject, this.id, this.index, "options");
34
+ if (condition === true) {
35
+ if (typeof option.meta.output === "string" &&
36
+ option.meta.output.trim().length > 0) {
37
+ var outputReference = this.references.outputs[this.id];
38
+ var autonums = [];
39
+ if (condition !== false) {
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);
114
58
  }
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);
59
+ this.renderChildren();
152
60
  }
153
- this.renderChildren();
154
61
  };
155
62
  OptionRender.prototype.renderChildren = function () {
156
63
  var _this = this;
157
64
  var option = this.references.options[this.id];
158
65
  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;
162
66
  _this.outputs = __spreadArray(__spreadArray([], _this.outputs, true), new OptionRender({
163
67
  references: _this.references,
164
68
  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, index?: number, contextOptionId?: number) => string;
9
+ type TParseDocumentNameWithVariables = (text: string, ovc: InputsType, references: Types.ReferencesType, fallback?: string) => string;
10
10
  export declare const parseDocumentNameWithVariables: TParseDocumentNameWithVariables;
11
11
  export {};
@@ -98,8 +98,7 @@ 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, index, contextOptionId) {
102
- if (index === void 0) { index = 0; }
101
+ var parseDocumentNameWithVariables = function (text, ovc, references, fallback) {
103
102
  var tagsMatch = text.match(/\[var:([0-9]+)\]/gi);
104
103
  var variables = [];
105
104
  if (tagsMatch !== null) {
@@ -114,22 +113,11 @@ var parseDocumentNameWithVariables = function (text, ovc, references, fallback,
114
113
  variables = variables.filter(function (c, i) { return variables.indexOf(c) === i; });
115
114
  variables = variables.filter(function (c) { return ovc !== undefined || references.variables[c] !== undefined; });
116
115
  var variablesValues = {};
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
- }
116
+ variables.forEach(function (variableId) {
117
+ var _a;
118
+ var value = ((_a = ovc.variables[variableId]) === null || _a === void 0 ? void 0 : _a[0]) || "";
119
+ variablesValues[variableId] = value.toString();
120
+ });
133
121
  var parsedText = "".concat(text);
134
122
  variables.forEach(function (variableId) {
135
123
  var value = variablesValues[variableId];
@@ -1,8 +1,8 @@
1
1
  import type { ModelV3 } from "@legalplace/models-v3-types";
2
- import { type Types } from "@legalplace/referencesparser";
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, DocumentLayout } from "../types/types";
5
+ import type { FDFType, DocumentIndex, DocumentOutputIndex, DocumentPdfFormIndex } from "../types/types";
6
6
  declare class Prerender {
7
7
  private references;
8
8
  private ovc;
@@ -16,9 +16,6 @@ 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;
22
19
  private generateDocumentNamesHash;
23
20
  private fillPdfForms;
24
21
  private generateAllDocuments;
@@ -1,22 +1,11 @@
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
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ var referencesparser_1 = require("@legalplace/referencesparser");
17
7
  var conditions_runner_1 = __importDefault(require("@legalplace/conditions-runner"));
18
8
  var ovc_converter_1 = __importDefault(require("@legalplace/ovc-converter"));
19
- var referencesparser_1 = require("@legalplace/referencesparser");
20
9
  var crypto_1 = __importDefault(require("crypto"));
21
10
  var DocumentRender_1 = __importDefault(require("./DocumentRender"));
22
11
  var NumAuto_1 = __importDefault(require("./NumAuto"));
@@ -49,109 +38,49 @@ var Prerender = (function () {
49
38
  return this.documentsIndex;
50
39
  };
51
40
  Prerender.prototype.getDocument = function (documentNameHash) {
52
- var _a;
53
41
  if (this.renderedDocuments[documentNameHash]) {
54
42
  return this.renderedDocuments[documentNameHash];
55
43
  }
56
44
  var index = this.documentsIndex[documentNameHash];
57
- var occurrenceIndex = (_a = index.occurrenceIndex) !== null && _a !== void 0 ? _a : 0;
58
45
  this.renderedDocuments[documentNameHash] = Prerender.isPdfForm(index)
59
- ? this.pdfFiller.fillDocument(index.slug, occurrenceIndex)
60
- : this.documentRender.renderDocument(index.slug, occurrenceIndex);
46
+ ? this.pdfFiller.fillDocument(index.slug)
47
+ : this.documentRender.renderDocument(index.slug);
61
48
  return this.renderedDocuments[documentNameHash];
62
49
  };
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
- };
117
50
  Prerender.prototype.generateDocumentNamesHash = function () {
118
51
  var _this = this;
119
52
  Object.keys(this.references.documents).forEach(function (slug) {
53
+ var _a, _b;
120
54
  var document = _this.references.documents[slug];
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);
55
+ var documentParams = _this.references.documents[slug].params;
56
+ var conditionObject = _this.references.conditions.documents[slug];
57
+ var condition = conditionObject === undefined
58
+ ? true
59
+ : _this.conditions.executeCondition(conditionObject, 0, 0, "documents");
60
+ if (condition === true) {
61
+ var hash = crypto_1.default.createHash("sha1").update(slug).digest("hex");
143
62
  if (typeof document.pdf === "object" &&
144
63
  typeof document.pdf.id === "string" &&
145
64
  typeof document.pdf.form === "object") {
146
- _this.documentsIndex[hash] = __assign({ name: name, slug: slug, form: true, fdf: {
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: {
147
70
  id: "",
148
71
  fields: {},
149
- } }, (isMultipleDocument ? { occurrenceIndex: occurrenceIndex } : {}));
72
+ },
73
+ };
150
74
  }
151
75
  else {
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 } : {}));
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
+ };
153
82
  }
154
- });
83
+ }
155
84
  });
156
85
  };
157
86
  Prerender.prototype.fillPdfForms = function () {
@@ -166,15 +95,13 @@ var Prerender = (function () {
166
95
  Prerender.prototype.generateAllDocuments = function () {
167
96
  var _this = this;
168
97
  Object.keys(this.documentsIndex).forEach(function (documentNameHash) {
169
- var _a;
170
98
  var index = _this.documentsIndex[documentNameHash];
171
- var occurrenceIndex = (_a = index.occurrenceIndex) !== null && _a !== void 0 ? _a : 0;
172
99
  if (Prerender.isPdfForm(index)) {
173
- _this.renderedDocuments[documentNameHash] = _this.pdfFiller.fillDocument(index.slug, occurrenceIndex);
100
+ _this.renderedDocuments[documentNameHash] = _this.pdfFiller.fillDocument(_this.documentsIndex[documentNameHash].slug);
174
101
  }
175
102
  else {
176
103
  _this.renderedDocuments[documentNameHash] =
177
- _this.documentRender.renderDocument(index.slug, occurrenceIndex);
104
+ _this.documentRender.renderDocument(_this.documentsIndex[documentNameHash].slug);
178
105
  }
179
106
  });
180
107
  };
@@ -9,7 +9,6 @@ declare class SectionRender {
9
9
  documentName: string;
10
10
  conditions: ConditionsRunner;
11
11
  ovc: InputsType;
12
- baseIndex: number;
13
12
  private NumAuto;
14
13
  constructor(options: {
15
14
  references: Types.ReferencesType;
@@ -18,10 +17,8 @@ declare class SectionRender {
18
17
  documentName: string;
19
18
  currentSection: number;
20
19
  numauto: NumAuto;
21
- baseIndex?: number;
22
20
  });
23
21
  getOutputs(): string[];
24
- private getDocumentMultipleSource;
25
22
  private renderSection;
26
23
  }
27
24
  export default SectionRender;