@legalplace/prerenderx 3.8.17 → 3.8.18-staging.2

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.
@@ -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, 0, "sections");
37
- if (condition === true) {
38
- section.options.forEach(function (optionId) {
39
- var option = _this.references.options[optionId];
40
- var repeatOption = optionId;
41
- if (option.meta.type === "repeated") {
42
- if (option.meta.repeatOption === undefined)
43
- return;
44
- repeatOption =
45
- typeof option.meta.repeatOption === "number"
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: optionId,
59
+ id: childId,
58
60
  ovc: _this.ovc,
59
- index: 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
- var _a;
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
- var _this = this;
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,16 @@
1
+ import type { OptionV3 } from "@legalplace/models-v3-types";
2
+ export type OutputTableCellStyle = Record<string, string>;
3
+ export type OutputTableStyle = {
4
+ columnWidths?: number[];
5
+ width?: number;
6
+ borderStyle?: string;
7
+ borderColor?: string;
8
+ borderWidth?: number;
9
+ };
10
+ export declare const expandOutputTableCellStyle: (styles: OutputTableCellStyle) => OutputTableCellStyle;
11
+ export declare const serializeInlineStyle: (styles: OutputTableCellStyle) => string;
12
+ export declare const buildOutputTableStyleAttr: (tableStyle?: OutputTableStyle) => string;
13
+ export declare const buildOutputTableCellStyleAttr: (cellStyle?: OutputTableCellStyle | null) => string;
14
+ export declare const getOutputTableCellStyle: (option: OptionV3) => OutputTableCellStyle | undefined;
15
+ export declare const replaceOutputTableMarkers: (html: string, renderTable: (tableId: number) => string) => string;
16
+ export declare const stripOutputTableMarkers: (html: string) => string;
@@ -0,0 +1,130 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.stripOutputTableMarkers = exports.replaceOutputTableMarkers = exports.getOutputTableCellStyle = exports.buildOutputTableCellStyleAttr = exports.buildOutputTableStyleAttr = exports.serializeInlineStyle = exports.expandOutputTableCellStyle = void 0;
15
+ var DEFAULT_OUTPUT_TABLE_CELL_STYLE = {
16
+ paddingTop: "4px",
17
+ paddingRight: "4px",
18
+ paddingBottom: "4px",
19
+ paddingLeft: "4px",
20
+ borderTopWidth: "1px",
21
+ borderTopStyle: "solid",
22
+ borderTopColor: "#000000",
23
+ borderRightWidth: "1px",
24
+ borderRightStyle: "solid",
25
+ borderRightColor: "#000000",
26
+ borderBottomWidth: "1px",
27
+ borderBottomStyle: "solid",
28
+ borderBottomColor: "#000000",
29
+ borderLeftWidth: "1px",
30
+ borderLeftStyle: "solid",
31
+ borderLeftColor: "#000000",
32
+ };
33
+ var BORDER_SIDES = ["Top", "Right", "Bottom", "Left"];
34
+ var parseBoxShorthand = function (parts) {
35
+ var first = parts[0], second = parts[1], third = parts[2], fourth = parts[3];
36
+ if (parts.length === 1) {
37
+ return [first, first, first, first];
38
+ }
39
+ if (parts.length === 2) {
40
+ return [first, second, first, second];
41
+ }
42
+ if (parts.length === 3) {
43
+ return [first, second, third, second];
44
+ }
45
+ return [first, second, third, fourth];
46
+ };
47
+ var parseBorderShorthand = function (border) {
48
+ var parts = border.trim().split(/\s+/);
49
+ var width = parts.find(function (part) { return /^[0-9.]+(px|pt|em|rem|%)?$/i.test(part); }) || "1px";
50
+ var style = parts.find(function (part) {
51
+ return ["solid", "dashed", "dotted", "double", "none"].includes(part.toLowerCase());
52
+ }) || "solid";
53
+ var color = parts.find(function (part) { return part.startsWith("#") || part.startsWith("rgb"); }) ||
54
+ "#000000";
55
+ return { width: width, style: style, color: color };
56
+ };
57
+ var expandOutputTableCellStyle = function (styles) {
58
+ var expanded = __assign({}, styles);
59
+ if (expanded.padding) {
60
+ var _a = parseBoxShorthand(expanded.padding.trim().split(/\s+/)), top_1 = _a[0], right = _a[1], bottom = _a[2], left = _a[3];
61
+ delete expanded.padding;
62
+ expanded.paddingTop = expanded.paddingTop || top_1;
63
+ expanded.paddingRight = expanded.paddingRight || right;
64
+ expanded.paddingBottom = expanded.paddingBottom || bottom;
65
+ expanded.paddingLeft = expanded.paddingLeft || left;
66
+ }
67
+ if (expanded.border) {
68
+ var _b = parseBorderShorthand(expanded.border), width_1 = _b.width, style_1 = _b.style, color_1 = _b.color;
69
+ delete expanded.border;
70
+ BORDER_SIDES.forEach(function (side) {
71
+ var widthKey = "border".concat(side, "Width");
72
+ var styleKey = "border".concat(side, "Style");
73
+ var colorKey = "border".concat(side, "Color");
74
+ expanded[widthKey] = expanded[widthKey] || width_1;
75
+ expanded[styleKey] = expanded[styleKey] || style_1;
76
+ expanded[colorKey] = expanded[colorKey] || color_1;
77
+ });
78
+ }
79
+ return expanded;
80
+ };
81
+ exports.expandOutputTableCellStyle = expandOutputTableCellStyle;
82
+ var camelToKebab = function (property) {
83
+ return property.replace(/[A-Z]/g, function (match) { return "-".concat(match.toLowerCase()); });
84
+ };
85
+ var serializeInlineStyle = function (styles) {
86
+ return Object.entries(styles)
87
+ .filter(function (_a) {
88
+ var value = _a[1];
89
+ return value !== undefined && value !== "";
90
+ })
91
+ .map(function (_a) {
92
+ var property = _a[0], value = _a[1];
93
+ return "".concat(camelToKebab(property), ":").concat(value);
94
+ })
95
+ .join(";");
96
+ };
97
+ exports.serializeInlineStyle = serializeInlineStyle;
98
+ var buildOutputTableStyleAttr = function (tableStyle) {
99
+ var styles = [
100
+ "table-layout:fixed",
101
+ "border-spacing:0",
102
+ "border-collapse:collapse",
103
+ ];
104
+ if (typeof (tableStyle === null || tableStyle === void 0 ? void 0 : tableStyle.width) === "number") {
105
+ styles.push("width:".concat(tableStyle.width, "%"));
106
+ }
107
+ return " style=\"".concat(styles.join(";"), "\"");
108
+ };
109
+ exports.buildOutputTableStyleAttr = buildOutputTableStyleAttr;
110
+ var buildOutputTableCellStyleAttr = function (cellStyle) {
111
+ var styles = (0, exports.expandOutputTableCellStyle)(__assign(__assign({}, DEFAULT_OUTPUT_TABLE_CELL_STYLE), (cellStyle || {})));
112
+ var serialized = (0, exports.serializeInlineStyle)(styles);
113
+ return serialized.length > 0 ? " style=\"".concat(serialized, "\"") : "";
114
+ };
115
+ exports.buildOutputTableCellStyleAttr = buildOutputTableCellStyleAttr;
116
+ var getOutputTableCellStyle = function (option) {
117
+ return option.meta.cellStyle;
118
+ };
119
+ exports.getOutputTableCellStyle = getOutputTableCellStyle;
120
+ var OUTPUT_TABLE_MARKER_REGEX = /<output-table\s+data-id="(\d+)"\s*><\/output-table>/gi;
121
+ var replaceOutputTableMarkers = function (html, renderTable) {
122
+ return html.replace(OUTPUT_TABLE_MARKER_REGEX, function (_match, tableId) {
123
+ return renderTable(parseInt(tableId, 10));
124
+ });
125
+ };
126
+ exports.replaceOutputTableMarkers = replaceOutputTableMarkers;
127
+ var stripOutputTableMarkers = function (html) {
128
+ return html.replace(OUTPUT_TABLE_MARKER_REGEX, "");
129
+ };
130
+ exports.stripOutputTableMarkers = stripOutputTableMarkers;
@@ -0,0 +1,5 @@
1
+ import type { SectionRoleV3, SectionV3 } from "@legalplace/models-v3-types";
2
+ export type OutputRegionRole = SectionRoleV3;
3
+ export declare const isBodySection: (section: SectionV3) => boolean;
4
+ export declare const isRegionSection: (section: SectionV3, role: OutputRegionRole) => boolean;
5
+ export declare const getSectionIdsForRole: (sections: Record<string, SectionV3>, role: OutputRegionRole) => number[];
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSectionIdsForRole = exports.isRegionSection = exports.isBodySection = void 0;
4
+ var isBodySection = function (section) {
5
+ return !section.role || section.role === "body";
6
+ };
7
+ exports.isBodySection = isBodySection;
8
+ var isRegionSection = function (section, role) {
9
+ if (role === "body")
10
+ return (0, exports.isBodySection)(section);
11
+ return section.role === role;
12
+ };
13
+ exports.isRegionSection = isRegionSection;
14
+ var getSectionIdsForRole = function (sections, role) {
15
+ return Object.keys(sections)
16
+ .map(function (sectionId) { return parseInt(sectionId, 10); })
17
+ .filter(function (sectionId) {
18
+ var section = sections[sectionId];
19
+ return section && (0, exports.isRegionSection)(section, role);
20
+ });
21
+ };
22
+ exports.getSectionIdsForRole = getSectionIdsForRole;
@@ -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;
@@ -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.8.17",
3
+ "version": "3.8.18-staging.2",
4
4
  "description": "PrerenderX",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/prerenderx",
@@ -16,13 +16,13 @@
16
16
  "release": "standard-version -a --no-verify"
17
17
  },
18
18
  "dependencies": {
19
- "@legalplace/conditions-runner": "^2.2.14",
19
+ "@legalplace/conditions-runner": "2.2.15-staging.1",
20
20
  "@legalplace/eslint-config-base": "^1.2.0",
21
- "@legalplace/lplogic": "2.3.1",
22
- "@legalplace/models-v3-types": "^5.17.11",
23
- "@legalplace/ovc-converter": "^2.2.14",
21
+ "@legalplace/lplogic": "2.3.2-staging.0",
22
+ "@legalplace/models-v3-types": "5.17.17-staging.1",
23
+ "@legalplace/ovc-converter": "2.2.15-staging.1",
24
24
  "@legalplace/prettier-config": "^2.1.3",
25
- "@legalplace/referencesparser": "^3.2.31",
25
+ "@legalplace/referencesparser": "3.2.34-staging.1",
26
26
  "@legalplace/yousign": "^0.9.13",
27
27
  "crypto": "^1.0.1",
28
28
  "standard-version": "^9.3.1"
@@ -36,6 +36,5 @@
36
36
  "redux-mock-store": "^1.5.3",
37
37
  "ts-jest": "^24.0.2"
38
38
  },
39
- "prettier": "@legalplace/prettier-config",
40
- "gitHead": "66abb0a38764d6b5a41392eba66939a45cafc9ae"
39
+ "prettier": "@legalplace/prettier-config"
41
40
  }
@@ -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
- public renderDocument(documentName: string) {
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
- Object.keys(this.references.sections[documentName]).forEach((sectionId) => {
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: parseInt(sectionId, 10),
65
+ currentSection: sectionId,
39
66
  numauto: this.NumAuto,
67
+ baseIndex,
40
68
  }).getOutputs()
41
69
  );
42
70
  });