@legalplace/prerenderx 3.9.3 → 3.9.4-staging.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.
@@ -29,7 +29,9 @@ var OptionRender = (function () {
29
29
  OptionRender.prototype.isDisplayed = function (optionId) {
30
30
  var _this = this;
31
31
  if (optionId === void 0) { optionId = this.id; }
32
- return (0, referencesparser_1.isOptionDisplayed)(this.references, this.ovc, function (type, entityId, entityIndex) {
32
+ return (0, referencesparser_1.isOptionDisplayed)(this.references, this.ovc, function (type, entityId, entityIndex, documentSlug) {
33
+ var _a;
34
+ if (documentSlug === void 0) { documentSlug = "main"; }
33
35
  if (type === "options") {
34
36
  var conditionObject = _this.references.conditions.options[entityId];
35
37
  return conditionObject === undefined
@@ -37,10 +39,10 @@ var OptionRender = (function () {
37
39
  : _this.conditions.executeCondition(conditionObject, entityId, entityIndex, "options");
38
40
  }
39
41
  if (type === "sections") {
40
- var conditionObject = _this.references.conditions.sections.main[entityId];
42
+ var conditionObject = (_a = _this.references.conditions.sections[documentSlug]) === null || _a === void 0 ? void 0 : _a[entityId];
41
43
  return conditionObject === undefined
42
44
  ? true
43
- : _this.conditions.executeCondition(conditionObject, entityId, entityIndex, "sections");
45
+ : _this.conditions.executeCondition(conditionObject, entityId, entityIndex, "sections", documentSlug);
44
46
  }
45
47
  return true;
46
48
  }, optionId, this.index);
@@ -44,7 +44,7 @@ var SectionRender = (function () {
44
44
  var conditionObject = this.references.conditions.sections[this.documentName][this.currentSection];
45
45
  var condition = conditionObject === undefined
46
46
  ? true
47
- : this.conditions.executeCondition(conditionObject, 0, this.baseIndex, "sections");
47
+ : this.conditions.executeCondition(conditionObject, 0, this.baseIndex, "sections", this.documentName);
48
48
  if (condition !== true)
49
49
  return;
50
50
  var documentMultipleSource = this.getDocumentMultipleSource();
@@ -4,12 +4,12 @@ var referencesparser_1 = require("@legalplace/referencesparser");
4
4
  var FillPdfFormBase = (function () {
5
5
  function FillPdfFormBase(references, conditions, ovc) {
6
6
  var _this = this;
7
- this.conditionEvaluator = function (type, id, index) {
7
+ this.conditionEvaluator = function (type, id, index, documentSlug) {
8
8
  if (type === "options")
9
9
  return _this.getOptionCondition(id, index);
10
10
  if (type === "variables")
11
11
  return _this.getVariableCondition(id, index);
12
- return _this.getSectionCondition(id);
12
+ return _this.getSectionCondition(id, documentSlug);
13
13
  };
14
14
  this.references = references;
15
15
  this.conditions = conditions;
@@ -33,11 +33,13 @@ var FillPdfFormBase = (function () {
33
33
  ? true
34
34
  : this.conditions.executeCondition(conditionObject, id, index, "options");
35
35
  };
36
- FillPdfFormBase.prototype.getSectionCondition = function (id) {
37
- var conditionObject = this.references.conditions.sections.main[id];
36
+ FillPdfFormBase.prototype.getSectionCondition = function (id, documentSlug) {
37
+ var _a;
38
+ if (documentSlug === void 0) { documentSlug = "main"; }
39
+ var conditionObject = (_a = this.references.conditions.sections[documentSlug]) === null || _a === void 0 ? void 0 : _a[id];
38
40
  return conditionObject === undefined
39
41
  ? true
40
- : this.conditions.executeCondition(conditionObject, id, 0, "sections");
42
+ : this.conditions.executeCondition(conditionObject, id, 0, "sections", documentSlug);
41
43
  };
42
44
  return FillPdfFormBase;
43
45
  }());
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/prerenderx",
3
- "version": "3.9.3",
3
+ "version": "3.9.4-staging.0",
4
4
  "description": "PrerenderX",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/prerenderx",
@@ -16,26 +16,25 @@
16
16
  "release": "standard-version -a --no-verify"
17
17
  },
18
18
  "dependencies": {
19
- "@legalplace/conditions-runner": "^2.3.3",
19
+ "@legalplace/conditions-runner": "2.3.4-staging.0",
20
20
  "@legalplace/lplogic": "2.4.1",
21
- "@legalplace/models-v3-types": "^5.18.2",
22
- "@legalplace/ovc-converter": "^2.2.24",
23
- "@legalplace/referencesparser": "^3.3.4",
21
+ "@legalplace/models-v3-types": "5.18.3-staging.0",
22
+ "@legalplace/ovc-converter": "2.2.25-staging.0",
23
+ "@legalplace/referencesparser": "3.3.5-staging.0",
24
24
  "@legalplace/yousign": "^0.9.23",
25
25
  "crypto": "^1.0.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.7.2",
29
29
  "@babel/preset-typescript": "^7.7.2",
30
- "@legalplace/eslint-config-base": "^1.2.0",
31
- "@legalplace/prettier-config": "^2.1.3",
32
- "@legalplace/types": "^2.22.13",
30
+ "@legalplace/eslint-config-base": "1.2.1-staging.0",
31
+ "@legalplace/prettier-config": "2.1.4-staging.0",
32
+ "@legalplace/types": "2.22.15-staging.0",
33
33
  "@types/jest": "^24.0.15",
34
34
  "jest": "^24.8.0",
35
35
  "redux-mock-store": "^1.5.3",
36
36
  "standard-version": "^9.3.1",
37
37
  "ts-jest": "^24.0.2"
38
38
  },
39
- "prettier": "@legalplace/prettier-config",
40
- "gitHead": "051ddec22eba44657f3a7fbab9356209e8ab476a"
39
+ "prettier": "@legalplace/prettier-config"
41
40
  }
@@ -67,7 +67,7 @@ class OptionRender {
67
67
  return isOptionDisplayed(
68
68
  this.references,
69
69
  this.ovc,
70
- (type, entityId, entityIndex) => {
70
+ (type, entityId, entityIndex, documentSlug = "main") => {
71
71
  if (type === "options") {
72
72
  const conditionObject = this.references.conditions.options[entityId];
73
73
  return conditionObject === undefined
@@ -81,14 +81,15 @@ class OptionRender {
81
81
  }
82
82
  if (type === "sections") {
83
83
  const conditionObject =
84
- this.references.conditions.sections.main[entityId];
84
+ this.references.conditions.sections[documentSlug]?.[entityId];
85
85
  return conditionObject === undefined
86
86
  ? true
87
87
  : this.conditions.executeCondition(
88
88
  conditionObject,
89
89
  entityId,
90
90
  entityIndex,
91
- "sections"
91
+ "sections",
92
+ documentSlug
92
93
  );
93
94
  }
94
95
  return true;
@@ -77,7 +77,8 @@ class SectionRender {
77
77
  conditionObject,
78
78
  0,
79
79
  this.baseIndex,
80
- "sections"
80
+ "sections",
81
+ this.documentName
81
82
  );
82
83
 
83
84
  if (condition !== true) return;
@@ -29,11 +29,12 @@ class FillPdfFormBase {
29
29
  private readonly conditionEvaluator: ConditionEvaluator = (
30
30
  type,
31
31
  id,
32
- index
32
+ index,
33
+ documentSlug
33
34
  ) => {
34
35
  if (type === "options") return this.getOptionCondition(id, index);
35
36
  if (type === "variables") return this.getVariableCondition(id, index);
36
- return this.getSectionCondition(id);
37
+ return this.getSectionCondition(id, documentSlug);
37
38
  };
38
39
 
39
40
  /**
@@ -90,11 +91,18 @@ class FillPdfFormBase {
90
91
  /**
91
92
  * Returns a section's conditions.
92
93
  */
93
- private getSectionCondition(id: number) {
94
- const conditionObject = this.references.conditions.sections.main[id];
94
+ private getSectionCondition(id: number, documentSlug = "main") {
95
+ const conditionObject =
96
+ this.references.conditions.sections[documentSlug]?.[id];
95
97
  return conditionObject === undefined
96
98
  ? true
97
- : this.conditions.executeCondition(conditionObject, id, 0, "sections");
99
+ : this.conditions.executeCondition(
100
+ conditionObject,
101
+ id,
102
+ 0,
103
+ "sections",
104
+ documentSlug
105
+ );
98
106
  }
99
107
  }
100
108
 
@@ -6,9 +6,7 @@ import Prerender from "../src/libs/Prerender";
6
6
  * (`params.multiple.enabled = true`, source = option #2). The output
7
7
  * `[var:3]` interpolates the partner name at each occurrence.
8
8
  */
9
- const buildMultipleDocumentModel = (
10
- filenameTemplate?: string
11
- ): ModelV3 => ({
9
+ const buildMultipleDocumentModel = (filenameTemplate?: string): ModelV3 => ({
12
10
  documents: {
13
11
  main: {
14
12
  name: "Contract",
@@ -160,8 +158,8 @@ describe("Prerender — document multiple", () => {
160
158
  ((b[1].occurrenceIndex ?? 0) as number)
161
159
  );
162
160
 
163
- const rendered = entries.map(([hash]) =>
164
- prerender.getDocument(hash) as string
161
+ const rendered = entries.map(
162
+ ([hash]) => prerender.getDocument(hash) as string
165
163
  );
166
164
 
167
165
  expect(rendered[0]).toContain("Hello Alice");