@legalplace/prerenderx 3.8.18-staging.2 → 3.8.18

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.
@@ -17,13 +17,6 @@ class SectionRender {
17
17
 
18
18
  ovc: InputsType;
19
19
 
20
- /**
21
- * Occurrence index injected by the parent DocumentRender when the document
22
- * is multiple (`params.multiple.enabled === true`). For non-multiple
23
- * documents this is always 0.
24
- */
25
- baseIndex: number;
26
-
27
20
  private NumAuto: NumAuto;
28
21
 
29
22
  constructor(options: {
@@ -33,7 +26,6 @@ class SectionRender {
33
26
  documentName: string;
34
27
  currentSection: number;
35
28
  numauto: NumAuto;
36
- baseIndex?: number;
37
29
  }) {
38
30
  this.references = options.references;
39
31
  this.conditions = options.conditions;
@@ -41,7 +33,6 @@ class SectionRender {
41
33
  this.currentSection = options.currentSection;
42
34
  this.ovc = options.ovc;
43
35
  this.NumAuto = options.numauto;
44
- this.baseIndex = options.baseIndex ?? 0;
45
36
 
46
37
  this.renderSection();
47
38
  }
@@ -50,19 +41,6 @@ class SectionRender {
50
41
  return this.outputs;
51
42
  }
52
43
 
53
- /**
54
- * Returns the multiple source option id for the current document if any.
55
- * Returns `undefined` for non-multiple documents.
56
- */
57
- private getDocumentMultipleSource(): number | undefined {
58
- const docMultiple =
59
- this.references.documents[this.documentName]?.params?.multiple;
60
- if (docMultiple?.enabled !== true) return undefined;
61
- return typeof docMultiple.repeatOption === "number"
62
- ? docMultiple.repeatOption
63
- : undefined;
64
- }
65
-
66
44
  private renderSection() {
67
45
  const section =
68
46
  this.references.sections[this.documentName][this.currentSection];
@@ -73,106 +51,45 @@ class SectionRender {
73
51
  const condition =
74
52
  conditionObject === undefined
75
53
  ? true
76
- : this.conditions.executeCondition(
77
- conditionObject,
78
- 0,
79
- this.baseIndex,
80
- "sections"
81
- );
82
-
83
- if (condition !== true) return;
84
-
85
- const documentMultipleSource = this.getDocumentMultipleSource();
86
-
87
- section.options.forEach((optionId) => {
88
- const option = this.references.options[optionId];
89
-
90
- // Detect a `repeated` wrapper that points to the same source as the
91
- // document multiple. In that case, iterating over `repeatOption` here
92
- // would double the loop (the document is already rendered N times by
93
- // Prerender). Instead, render the wrapper's children once at the
94
- // document's current occurrence index.
95
- if (
96
- option.meta.type === "repeated" &&
97
- documentMultipleSource !== undefined &&
98
- option.meta.repeatOption === documentMultipleSource
99
- ) {
100
- option.options.forEach((childId) => {
54
+ : this.conditions.executeCondition(conditionObject, 0, 0, "sections");
55
+
56
+ // Rendering documents sections
57
+ if (condition === true) {
58
+ section.options.forEach((optionId) => {
59
+ const option = this.references.options[optionId];
60
+ let repeatOption = optionId;
61
+ if (option.meta.type === "repeated") {
62
+ if (option.meta.repeatOption === undefined) return;
63
+ repeatOption =
64
+ typeof option.meta.repeatOption === "number"
65
+ ? option.meta.repeatOption
66
+ : parseInt(option.meta.repeatOption, 10);
67
+ }
68
+
69
+ // Option inputs
70
+ const inputs = this.ovc.options[repeatOption] || [
71
+ !["radio", "checkbox"].includes(option.meta.type),
72
+ ]; // Falling back on a single value array if option doesn't exist in ovc
73
+
74
+ // Looping through inputs
75
+ inputs.forEach((value, index) => {
76
+ // If value is false we stop here
77
+ if (value !== true) return;
78
+
101
79
  this.outputs = [
102
80
  ...this.outputs,
103
81
  ...new OptionRender({
104
82
  references: this.references,
105
- id: childId,
83
+ id: optionId,
106
84
  ovc: this.ovc,
107
- index: this.baseIndex,
85
+ index,
108
86
  conditions: this.conditions,
109
87
  numauto: this.NumAuto,
110
88
  }).getOutputs(),
111
89
  ];
112
90
  });
113
- return;
114
- }
115
-
116
- let repeatOption = optionId;
117
- if (option.meta.type === "repeated") {
118
- if (option.meta.repeatOption === undefined) return;
119
- repeatOption =
120
- typeof option.meta.repeatOption === "number"
121
- ? option.meta.repeatOption
122
- : parseInt(option.meta.repeatOption, 10);
123
- }
124
-
125
- // Option inputs
126
- const inputs = this.ovc.options[repeatOption] || [
127
- !["radio", "checkbox"].includes(option.meta.type),
128
- ]; // Falling back on a single value array if option doesn't exist in ovc
129
-
130
- // Inside a multiple document, every non-`repeated` root option is
131
- // rendered at the document's occurrence index instead of looping
132
- // through every input slot. We pick the value at `baseIndex` (or
133
- // fall back to slot 0 for non-multiplied options whose inputs are
134
- // a single-element array).
135
- if (
136
- documentMultipleSource !== undefined &&
137
- option.meta.type !== "repeated"
138
- ) {
139
- const valueAtIndex =
140
- this.baseIndex < inputs.length ? inputs[this.baseIndex] : inputs[0];
141
- if (valueAtIndex !== true) return;
142
-
143
- this.outputs = [
144
- ...this.outputs,
145
- ...new OptionRender({
146
- references: this.references,
147
- id: optionId,
148
- ovc: this.ovc,
149
- index: this.baseIndex,
150
- conditions: this.conditions,
151
- numauto: this.NumAuto,
152
- }).getOutputs(),
153
- ];
154
- return;
155
- }
156
-
157
- // Looping through inputs (default behaviour, also used for `repeated`
158
- // wrappers whose source differs from the document multiple source).
159
- inputs.forEach((value, index) => {
160
- // If value is false we stop here
161
- if (value !== true) return;
162
-
163
- this.outputs = [
164
- ...this.outputs,
165
- ...new OptionRender({
166
- references: this.references,
167
- id: optionId,
168
- ovc: this.ovc,
169
- index,
170
- conditions: this.conditions,
171
- numauto: this.NumAuto,
172
- }).getOutputs(),
173
- ];
174
91
  });
175
- });
92
+ }
176
93
  }
177
94
  }
178
95
 
@@ -1,11 +1,6 @@
1
1
  import type { Types } from "@legalplace/referencesparser";
2
2
  import type ConditionsRunner from "@legalplace/conditions-runner";
3
3
  import type InputsType from "@legalplace/types/dist/inputs";
4
- import {
5
- isOptionDisplayed as sharedIsOptionDisplayed,
6
- isVariableDisplayed as sharedIsVariableDisplayed,
7
- type ConditionEvaluator,
8
- } from "@legalplace/referencesparser";
9
4
 
10
5
  class FillPdfFormBase {
11
6
  references: Types.ReferencesType;
@@ -25,46 +20,59 @@ class FillPdfFormBase {
25
20
  }
26
21
 
27
22
  /**
28
- * Evaluates a stored condition for options, variables or sections.
29
- */
30
- private readonly conditionEvaluator: ConditionEvaluator = (
31
- type,
32
- id,
33
- index
34
- ) => {
35
- if (type === "options") return this.getOptionCondition(id, index);
36
- if (type === "variables") return this.getVariableCondition(id, index);
37
- return this.getSectionCondition(id);
38
- };
39
-
40
- /**
41
- * Checks whether a variable is displayed at a given index.
23
+ * Checks whether a variable is displayed at a given index
24
+ * @param id Variable's ID
25
+ * @param index Index
42
26
  */
43
27
  isVariableDisplayed(id: number, index: number) {
44
- return sharedIsVariableDisplayed(
45
- this.references,
46
- this.ovc,
47
- this.conditionEvaluator,
48
- id,
28
+ // Getting variable's conditions & executing it if any
29
+ const variableCondition = this.getVariableCondition(id, index);
30
+ const variableParents =
31
+ this.references.relations.variables[id]?.parents || [];
32
+ const parentOptionIsDisplayed = this.isOptionDisplayed(
33
+ variableParents[0],
49
34
  index
50
35
  );
36
+
37
+ return (
38
+ [variableCondition, parentOptionIsDisplayed].filter((c) => c !== true)
39
+ .length === 0
40
+ );
51
41
  }
52
42
 
53
43
  /**
54
- * Checks whether an option is displayed at a given index.
44
+ * Checks whether an option is displayed at a given index
45
+ * @param id Option's ID
46
+ * @param index Index
55
47
  */
56
48
  isOptionDisplayed(id: number, index: number) {
57
- return sharedIsOptionDisplayed(
58
- this.references,
59
- this.ovc,
60
- this.conditionEvaluator,
61
- id,
62
- index
49
+ // Getting variable's conditions & executing it if any
50
+ const optionCondition = this.getOptionCondition(id, index);
51
+ const optionParents = this.references.relations.options[id]?.parents || [];
52
+ const parentsConditions = optionParents.map(
53
+ (optionId) => this.getOptionCondition(optionId, index) !== false
54
+ );
55
+ const parentsInputs = optionParents.map(
56
+ (optionId) => this.ovc.options[optionId][index]
57
+ );
58
+ const parentSectionId = this.getOptionParentSection(id);
59
+ const parentSectionCondition =
60
+ this.getSectionCondition(parentSectionId) !== false;
61
+
62
+ return (
63
+ [
64
+ optionCondition,
65
+ parentSectionCondition,
66
+ ...parentsConditions,
67
+ ...parentsInputs,
68
+ ].filter((c) => c !== true).length === 0
63
69
  );
64
70
  }
65
71
 
66
72
  /**
67
- * Returns a variable's conditions.
73
+ * Returns a variable's conditions
74
+ * @param id Variable's id
75
+ * @param index Variable's index
68
76
  */
69
77
  private getVariableCondition(id: number, index: number) {
70
78
  const conditionObject = this.references.conditions.variables[id];
@@ -79,7 +87,9 @@ class FillPdfFormBase {
79
87
  }
80
88
 
81
89
  /**
82
- * Returns an option's conditions.
90
+ * Returns an option's conditions
91
+ * @param id Option's id
92
+ * @param index Option's index
83
93
  */
84
94
  private getOptionCondition(id: number, index: number) {
85
95
  const conditionObject = this.references.conditions.options[id];
@@ -89,7 +99,8 @@ class FillPdfFormBase {
89
99
  }
90
100
 
91
101
  /**
92
- * Returns a section's conditions.
102
+ * Returns a section's conditions
103
+ * @param id Section's id
93
104
  */
94
105
  private getSectionCondition(id: number) {
95
106
  const conditionObject = this.references.conditions.sections.main[id];
@@ -97,6 +108,28 @@ class FillPdfFormBase {
97
108
  ? true
98
109
  : this.conditions.executeCondition(conditionObject, id, 0, "sections");
99
110
  }
111
+
112
+ /**
113
+ * Returns option's parent section
114
+ * @param id Option's id
115
+ */
116
+ private getOptionParentSection(id: number) {
117
+ const { parents } = this.references.relations.options[id];
118
+
119
+ // Getting root option id
120
+ const rootId = parents.length > 0 ? parents[parents.length - 1] : id;
121
+
122
+ // Looking for section
123
+ const sections = Object.values(this.references.sections.main);
124
+
125
+ for (let i = 0; i < sections.length; i += 1) {
126
+ if (sections[i].options.includes(rootId)) return sections[i].id;
127
+ }
128
+
129
+ throw new Error(
130
+ `Cannot find parent section for option ${id} (Root option id: ${rootId})`
131
+ );
132
+ }
100
133
  }
101
134
 
102
135
  export default FillPdfFormBase;
@@ -1,27 +1,14 @@
1
- import type { DocumentLayoutV3 } from "@legalplace/models-v3-types";
2
-
3
1
  export type DocumentOutputIndex = {
4
2
  name: string;
5
3
  slug: string;
6
4
  pdf: boolean;
7
5
  docx: boolean;
8
- /**
9
- * Occurrence index of the document when the document is multiple
10
- * (`params.multiple.enabled === true`). `undefined` for non-multiple
11
- * documents (treated as 0 internally).
12
- */
13
- occurrenceIndex?: number;
14
6
  };
15
-
16
7
  export type DocumentPdfFormIndex = {
17
8
  name: string;
18
9
  slug: string;
19
10
  form: boolean;
20
11
  fdf: FDFType;
21
- /**
22
- * Occurrence index of the document when the document is multiple.
23
- */
24
- occurrenceIndex?: number;
25
12
  };
26
13
 
27
14
  export type DocumentIndex = Record<
@@ -33,17 +20,3 @@ export type FDFType = {
33
20
  id: string;
34
21
  fields: Record<string, string>;
35
22
  };
36
-
37
- /**
38
- * Rendered header/footer regions and page layout for DOCX generation.
39
- */
40
- export type DocumentLayout = {
41
- header?: string;
42
- footer?: string;
43
- firstPageHeader?: string;
44
- firstPageFooter?: string;
45
- differentFirstPage: boolean;
46
- margins?: DocumentLayoutV3["margins"];
47
- headerDistance?: number;
48
- footerDistance?: number;
49
- };
@@ -1,16 +0,0 @@
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;
@@ -1,130 +0,0 @@
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;
@@ -1,5 +0,0 @@
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[];
@@ -1,22 +0,0 @@
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;
@@ -1,20 +0,0 @@
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 {};
@@ -1,68 +0,0 @@
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;