@legalplace/prerenderx 3.2.1 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +3 -47
- package/CHANGELOG.md +21 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/libs/DocumentRender.d.ts +4 -4
- package/dist/libs/DocumentRender.js +2 -2
- package/dist/libs/FillPdfForm.d.ts +1 -1
- package/dist/libs/FillPdfForm.js +30 -24
- package/dist/libs/InputsInitiator.d.ts +1 -1
- package/dist/libs/InputsInitiator.js +35 -11
- package/dist/libs/NumAuto.js +1 -1
- package/dist/libs/OptionRender.d.ts +4 -4
- package/dist/libs/OptionRender.js +30 -18
- package/dist/libs/OutputParser.d.ts +2 -2
- package/dist/libs/OutputParser.js +34 -25
- package/dist/libs/Prerender.d.ts +8 -8
- package/dist/libs/Prerender.js +29 -22
- package/dist/libs/SectionRender.d.ts +4 -4
- package/dist/libs/SectionRender.js +22 -13
- package/dist/libs/misc/FillPdfFormBase.d.ts +3 -3
- package/dist/libs/misc/FillPdfFormBase.js +25 -17
- package/package.json +14 -18
- package/src/index.ts +3 -3
- package/src/libs/DocumentRender.ts +27 -22
- package/src/libs/FillPdfForm.ts +72 -59
- package/src/libs/InputsInitiator.ts +91 -53
- package/src/libs/NumAuto.ts +16 -14
- package/src/libs/OptionRender.ts +85 -45
- package/src/libs/OutputParser.ts +112 -58
- package/src/libs/Prerender.ts +119 -75
- package/src/libs/SectionRender.ts +57 -38
- package/src/libs/misc/FillPdfFormBase.ts +71 -39
- package/src/types/types.ts +17 -14
- package/tsconfig.json +3 -1
- package/.gitlab-ci.yml +0 -43
- package/.prettierrc.js +0 -10
- package/.vscode/settings.json +0 -17
- package/.vscode/tasks.json +0 -24
- package/tsconfig.eslint.json +0 -12
package/dist/libs/Prerender.js
CHANGED
|
@@ -16,10 +16,13 @@ var Prerender = (function () {
|
|
|
16
16
|
function Prerender(model, ovc) {
|
|
17
17
|
this.documentsIndex = {};
|
|
18
18
|
this.renderedDocuments = {};
|
|
19
|
-
this.model = model;
|
|
20
19
|
this.NumAuto = new NumAuto_1.default();
|
|
21
|
-
this.references =
|
|
22
|
-
|
|
20
|
+
this.references = referencesparser_1.ReferencesParser.isReferences(model)
|
|
21
|
+
? model
|
|
22
|
+
: new referencesparser_1.ReferencesParser(model).getReferences();
|
|
23
|
+
this.ovc = ovc_converter_1.default.isOvc(ovc)
|
|
24
|
+
? ovc_converter_1.default.convertToOptionsVariables(ovc, this.references)
|
|
25
|
+
: ovc;
|
|
23
26
|
var inputs = new InputsInitiator_1.default(this.references, this.ovc).getInputs();
|
|
24
27
|
this.conditions = new conditions_runner_1.default(this.references, inputs);
|
|
25
28
|
this.documentRender = new DocumentRender_1.default(this.references, this.conditions, inputs, this.NumAuto);
|
|
@@ -39,39 +42,42 @@ var Prerender = (function () {
|
|
|
39
42
|
return this.renderedDocuments[documentNameHash];
|
|
40
43
|
}
|
|
41
44
|
var index = this.documentsIndex[documentNameHash];
|
|
42
|
-
this.renderedDocuments[documentNameHash] = Prerender.isPdfForm(index)
|
|
45
|
+
this.renderedDocuments[documentNameHash] = Prerender.isPdfForm(index)
|
|
46
|
+
? this.pdfFiller.fillDocument(index.slug)
|
|
47
|
+
: this.documentRender.renderDocument(index.slug);
|
|
43
48
|
return this.renderedDocuments[documentNameHash];
|
|
44
49
|
};
|
|
45
50
|
Prerender.prototype.generateDocumentNamesHash = function () {
|
|
46
51
|
var _this = this;
|
|
47
|
-
Object.keys(this.
|
|
52
|
+
Object.keys(this.references.documents).forEach(function (slug) {
|
|
48
53
|
var _a, _b;
|
|
49
|
-
var document = _this.
|
|
50
|
-
var documentParams = _this.
|
|
54
|
+
var document = _this.references.documents[slug];
|
|
55
|
+
var documentParams = _this.references.documents[slug].params;
|
|
51
56
|
var conditionObject = _this.references.conditions.documents[slug];
|
|
52
|
-
var condition = conditionObject === undefined
|
|
57
|
+
var condition = conditionObject === undefined
|
|
58
|
+
? true
|
|
59
|
+
: _this.conditions.executeCondition(conditionObject, 0, 0, "documents");
|
|
53
60
|
if (condition === true) {
|
|
54
|
-
var hash = crypto_1.default
|
|
55
|
-
|
|
56
|
-
.
|
|
57
|
-
.
|
|
58
|
-
if (typeof document.pdf === 'object' && typeof document.pdf.id === 'string' && typeof document.pdf.form === 'object') {
|
|
61
|
+
var hash = crypto_1.default.createHash("sha1").update(slug).digest("hex");
|
|
62
|
+
if (typeof document.pdf === "object" &&
|
|
63
|
+
typeof document.pdf.id === "string" &&
|
|
64
|
+
typeof document.pdf.form === "object") {
|
|
59
65
|
_this.documentsIndex[hash] = {
|
|
60
|
-
name: OutputParser_1.parseDocumentNameWithVariables(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
66
|
+
name: (0, OutputParser_1.parseDocumentNameWithVariables)(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
61
67
|
slug: slug,
|
|
62
68
|
form: true,
|
|
63
69
|
fdf: {
|
|
64
|
-
id:
|
|
65
|
-
fields: {}
|
|
66
|
-
}
|
|
70
|
+
id: "",
|
|
71
|
+
fields: {},
|
|
72
|
+
},
|
|
67
73
|
};
|
|
68
74
|
}
|
|
69
75
|
else {
|
|
70
76
|
_this.documentsIndex[hash] = {
|
|
71
|
-
name: OutputParser_1.parseDocumentNameWithVariables(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
77
|
+
name: (0, OutputParser_1.parseDocumentNameWithVariables)(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
72
78
|
slug: slug,
|
|
73
79
|
pdf: ((_a = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _a === void 0 ? void 0 : _a.pdf) !== false,
|
|
74
|
-
docx: ((_b = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _b === void 0 ? void 0 : _b.docx) !== false
|
|
80
|
+
docx: ((_b = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _b === void 0 ? void 0 : _b.docx) !== false,
|
|
75
81
|
};
|
|
76
82
|
}
|
|
77
83
|
}
|
|
@@ -94,15 +100,16 @@ var Prerender = (function () {
|
|
|
94
100
|
_this.renderedDocuments[documentNameHash] = _this.pdfFiller.fillDocument(_this.documentsIndex[documentNameHash].slug);
|
|
95
101
|
}
|
|
96
102
|
else {
|
|
97
|
-
_this.renderedDocuments[documentNameHash] =
|
|
103
|
+
_this.renderedDocuments[documentNameHash] =
|
|
104
|
+
_this.documentRender.renderDocument(_this.documentsIndex[documentNameHash].slug);
|
|
98
105
|
}
|
|
99
106
|
});
|
|
100
107
|
};
|
|
101
108
|
Prerender.isPdfForm = function (index) {
|
|
102
|
-
return Object.prototype.hasOwnProperty.call(index,
|
|
109
|
+
return Object.prototype.hasOwnProperty.call(index, "form");
|
|
103
110
|
};
|
|
104
111
|
Prerender.isOutput = function (index) {
|
|
105
|
-
return !Object.prototype.hasOwnProperty.call(index,
|
|
112
|
+
return !Object.prototype.hasOwnProperty.call(index, "form");
|
|
106
113
|
};
|
|
107
114
|
return Prerender;
|
|
108
115
|
}());
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Types } from
|
|
2
|
-
import ConditionsRunner from
|
|
3
|
-
import InputsType from
|
|
4
|
-
import NumAuto from
|
|
1
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import type ConditionsRunner from "@legalplace/conditions-runner";
|
|
3
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
|
+
import type NumAuto from "./NumAuto";
|
|
5
5
|
declare class SectionRender {
|
|
6
6
|
outputs: string[];
|
|
7
7
|
references: Types.ReferencesType;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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));
|
|
8
10
|
};
|
|
9
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -29,28 +31,35 @@ var SectionRender = (function () {
|
|
|
29
31
|
var _this = this;
|
|
30
32
|
var section = this.references.sections[this.documentName][this.currentSection];
|
|
31
33
|
var conditionObject = this.references.conditions.sections[this.documentName][this.currentSection];
|
|
32
|
-
var condition = conditionObject === undefined
|
|
34
|
+
var condition = conditionObject === undefined
|
|
35
|
+
? true
|
|
36
|
+
: this.conditions.executeCondition(conditionObject, 0, 0, "sections");
|
|
33
37
|
if (condition === true) {
|
|
34
38
|
section.options.forEach(function (optionId) {
|
|
35
39
|
var option = _this.references.options[optionId];
|
|
36
40
|
var repeatOption = optionId;
|
|
37
|
-
if (option.meta.type ===
|
|
41
|
+
if (option.meta.type === "repeated") {
|
|
38
42
|
if (option.meta.repeatOption === undefined)
|
|
39
43
|
return;
|
|
40
|
-
repeatOption =
|
|
44
|
+
repeatOption =
|
|
45
|
+
typeof option.meta.repeatOption === "number"
|
|
46
|
+
? option.meta.repeatOption
|
|
47
|
+
: parseInt(option.meta.repeatOption, 10);
|
|
41
48
|
}
|
|
42
|
-
var inputs = _this.ovc.options[repeatOption] || [
|
|
49
|
+
var inputs = _this.ovc.options[repeatOption] || [
|
|
50
|
+
!["radio", "checkbox"].includes(option.meta.type),
|
|
51
|
+
];
|
|
43
52
|
inputs.forEach(function (value, index) {
|
|
44
53
|
if (value !== true)
|
|
45
54
|
return;
|
|
46
|
-
_this.outputs =
|
|
55
|
+
_this.outputs = __spreadArray(__spreadArray([], _this.outputs, true), new OptionRender_1.default({
|
|
47
56
|
references: _this.references,
|
|
48
57
|
id: optionId,
|
|
49
58
|
ovc: _this.ovc,
|
|
50
59
|
index: index,
|
|
51
60
|
conditions: _this.conditions,
|
|
52
|
-
numauto: _this.NumAuto
|
|
53
|
-
}).getOutputs());
|
|
61
|
+
numauto: _this.NumAuto,
|
|
62
|
+
}).getOutputs(), true);
|
|
54
63
|
});
|
|
55
64
|
});
|
|
56
65
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Types } from
|
|
2
|
-
import ConditionsRunner from
|
|
3
|
-
import InputsType from
|
|
1
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import type ConditionsRunner from "@legalplace/conditions-runner";
|
|
3
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
4
|
declare class FillPdfFormBase {
|
|
5
5
|
references: Types.ReferencesType;
|
|
6
6
|
conditions: ConditionsRunner;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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));
|
|
8
10
|
};
|
|
9
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
12
|
var FillPdfFormBase = (function () {
|
|
@@ -18,34 +20,40 @@ var FillPdfFormBase = (function () {
|
|
|
18
20
|
var variableCondition = this.getVariableCondition(id, index);
|
|
19
21
|
var variableParents = ((_a = this.references.relations.variables[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
|
|
20
22
|
var parentOptionIsDisplayed = this.isOptionDisplayed(variableParents[0], index);
|
|
21
|
-
return [variableCondition, parentOptionIsDisplayed].filter(function (c) { return c !== true; })
|
|
23
|
+
return ([variableCondition, parentOptionIsDisplayed].filter(function (c) { return c !== true; })
|
|
24
|
+
.length === 0);
|
|
22
25
|
};
|
|
23
26
|
FillPdfFormBase.prototype.isOptionDisplayed = function (id, index) {
|
|
24
27
|
var _this = this;
|
|
25
28
|
var _a;
|
|
26
29
|
var optionCondition = this.getOptionCondition(id, index);
|
|
27
30
|
var optionParents = ((_a = this.references.relations.options[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
|
|
28
|
-
var parentsConditions = optionParents.map(function (optionId) {
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
var parentsInputs = optionParents.map(function (optionId) {
|
|
32
|
-
return _this.ovc.options[optionId][index];
|
|
33
|
-
});
|
|
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]; });
|
|
34
33
|
var parentSectionId = this.getOptionParentSection(id);
|
|
35
34
|
var parentSectionCondition = this.getSectionCondition(parentSectionId) !== false;
|
|
36
|
-
return
|
|
35
|
+
return (__spreadArray(__spreadArray([
|
|
36
|
+
optionCondition,
|
|
37
|
+
parentSectionCondition
|
|
38
|
+
], parentsConditions, true), parentsInputs, true).filter(function (c) { return c !== true; }).length === 0);
|
|
37
39
|
};
|
|
38
40
|
FillPdfFormBase.prototype.getVariableCondition = function (id, index) {
|
|
39
41
|
var conditionObject = this.references.conditions.variables[id];
|
|
40
|
-
return conditionObject === undefined
|
|
42
|
+
return conditionObject === undefined
|
|
43
|
+
? true
|
|
44
|
+
: this.conditions.executeCondition(conditionObject, id, index, "variables");
|
|
41
45
|
};
|
|
42
46
|
FillPdfFormBase.prototype.getOptionCondition = function (id, index) {
|
|
43
47
|
var conditionObject = this.references.conditions.options[id];
|
|
44
|
-
return conditionObject === undefined
|
|
48
|
+
return conditionObject === undefined
|
|
49
|
+
? true
|
|
50
|
+
: this.conditions.executeCondition(conditionObject, id, index, "options");
|
|
45
51
|
};
|
|
46
52
|
FillPdfFormBase.prototype.getSectionCondition = function (id) {
|
|
47
53
|
var conditionObject = this.references.conditions.sections.main[id];
|
|
48
|
-
return conditionObject === undefined
|
|
54
|
+
return conditionObject === undefined
|
|
55
|
+
? true
|
|
56
|
+
: this.conditions.executeCondition(conditionObject, id, 0, "sections");
|
|
49
57
|
};
|
|
50
58
|
FillPdfFormBase.prototype.getOptionParentSection = function (id) {
|
|
51
59
|
var parents = this.references.relations.options[id].parents;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legalplace/prerenderx",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "PrerenderX",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": "https://git.legalplace.eu/legalplace/prerenderx",
|
|
@@ -12,35 +12,31 @@
|
|
|
12
12
|
"lint:fix": "tsc && eslint 'src/**/*.{js,jsx,ts,tsx}' --fix",
|
|
13
13
|
"test": "jest",
|
|
14
14
|
"build": "tsc",
|
|
15
|
+
"build:ci": "tsc",
|
|
15
16
|
"release": "standard-version -a --no-verify"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@legalplace/conditions-runner": "
|
|
19
|
+
"@legalplace/conditions-runner": "^2.0.3",
|
|
20
|
+
"@legalplace/eslint-config-base": "^1.1.1",
|
|
19
21
|
"@legalplace/lplogic": "2.1.6",
|
|
20
|
-
"@legalplace/models-v3-types": "
|
|
21
|
-
"@legalplace/ovc-converter": "
|
|
22
|
-
"@legalplace/
|
|
22
|
+
"@legalplace/models-v3-types": "^5.1.16",
|
|
23
|
+
"@legalplace/ovc-converter": "^2.0.3",
|
|
24
|
+
"@legalplace/prettier-config": "^2.1.3",
|
|
25
|
+
"@legalplace/referencesparser": "^3.0.3",
|
|
23
26
|
"crypto": "^1.0.1",
|
|
24
27
|
"standard-version": "^9.3.1",
|
|
25
|
-
"typescript": "
|
|
28
|
+
"typescript": "4.4.3"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
31
|
"@babel/core": "^7.7.2",
|
|
29
32
|
"@babel/preset-typescript": "^7.7.2",
|
|
30
|
-
"@legalplace/types": "
|
|
33
|
+
"@legalplace/types": "^2.0.17",
|
|
31
34
|
"@types/jest": "^24.0.15",
|
|
32
|
-
"@types/node": "^
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "^2.6.1",
|
|
34
|
-
"@typescript-eslint/parser": "^2.6.1",
|
|
35
|
-
"airbnb-standard": "^1.0.0",
|
|
36
|
-
"eslint": "^6.6.0",
|
|
37
|
-
"eslint-config-airbnb-base": "^14.0.0",
|
|
38
|
-
"eslint-config-prettier": "^6.5.0",
|
|
39
|
-
"eslint-plugin-import": "^2.18.2",
|
|
40
|
-
"eslint-plugin-prettier": "^3.1.1",
|
|
35
|
+
"@types/node": "^20.8.10",
|
|
41
36
|
"jest": "^24.8.0",
|
|
42
|
-
"prettier": "1.19.1",
|
|
43
37
|
"redux-mock-store": "^1.5.3",
|
|
44
38
|
"ts-jest": "^24.0.2"
|
|
45
|
-
}
|
|
39
|
+
},
|
|
40
|
+
"prettier": "@legalplace/prettier-config",
|
|
41
|
+
"gitHead": "51ad188d81ea4168bcd0f5922f1b19d730deacfe"
|
|
46
42
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
import { Types } from
|
|
2
|
-
import ConditionsRunner from
|
|
3
|
-
import InputsType from
|
|
4
|
-
import SectionRender from
|
|
5
|
-
import NumAuto from
|
|
1
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import type ConditionsRunner from "@legalplace/conditions-runner";
|
|
3
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
|
+
import SectionRender from "./SectionRender";
|
|
5
|
+
import type NumAuto from "./NumAuto";
|
|
6
6
|
|
|
7
7
|
class DocumentRender {
|
|
8
|
-
references: Types.ReferencesType
|
|
8
|
+
references: Types.ReferencesType;
|
|
9
9
|
|
|
10
|
-
conditions: ConditionsRunner
|
|
10
|
+
conditions: ConditionsRunner;
|
|
11
11
|
|
|
12
|
-
ovc: InputsType
|
|
12
|
+
ovc: InputsType;
|
|
13
13
|
|
|
14
|
-
private NumAuto: NumAuto
|
|
14
|
+
private NumAuto: NumAuto;
|
|
15
15
|
|
|
16
|
-
constructor(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
constructor(
|
|
17
|
+
references: Types.ReferencesType,
|
|
18
|
+
conditions: ConditionsRunner,
|
|
19
|
+
ovc: InputsType,
|
|
20
|
+
numauto: NumAuto
|
|
21
|
+
) {
|
|
22
|
+
this.references = references;
|
|
23
|
+
this.conditions = conditions;
|
|
24
|
+
this.ovc = ovc;
|
|
25
|
+
this.NumAuto = numauto;
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
public renderDocument(documentName: string) {
|
|
24
|
-
const documentOutputs: string[] = []
|
|
25
|
-
this.NumAuto.resetIndexes()
|
|
26
|
-
Object.keys(this.references.sections[documentName]).forEach(sectionId => {
|
|
29
|
+
const documentOutputs: string[] = [];
|
|
30
|
+
this.NumAuto.resetIndexes();
|
|
31
|
+
Object.keys(this.references.sections[documentName]).forEach((sectionId) => {
|
|
27
32
|
documentOutputs.push(
|
|
28
33
|
...new SectionRender({
|
|
29
34
|
references: this.references,
|
|
@@ -31,13 +36,13 @@ class DocumentRender {
|
|
|
31
36
|
documentName,
|
|
32
37
|
ovc: this.ovc,
|
|
33
38
|
currentSection: parseInt(sectionId, 10),
|
|
34
|
-
numauto: this.NumAuto
|
|
39
|
+
numauto: this.NumAuto,
|
|
35
40
|
}).getOutputs()
|
|
36
|
-
)
|
|
37
|
-
})
|
|
41
|
+
);
|
|
42
|
+
});
|
|
38
43
|
|
|
39
|
-
return documentOutputs.join(
|
|
44
|
+
return documentOutputs.join("");
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
47
|
|
|
43
|
-
export default DocumentRender
|
|
48
|
+
export default DocumentRender;
|
package/src/libs/FillPdfForm.ts
CHANGED
|
@@ -1,40 +1,46 @@
|
|
|
1
|
-
import { FDFBoxesV3, FDFInputsV3 } from
|
|
2
|
-
import FillPdfFormBase from
|
|
1
|
+
import type { FDFBoxesV3, FDFInputsV3 } from "@legalplace/models-v3-types";
|
|
2
|
+
import FillPdfFormBase from "./misc/FillPdfFormBase";
|
|
3
3
|
|
|
4
4
|
type FDFType = {
|
|
5
|
-
id: string
|
|
6
|
-
fields: Record<string, string
|
|
7
|
-
}
|
|
5
|
+
id: string;
|
|
6
|
+
fields: Record<string, string>;
|
|
7
|
+
};
|
|
8
8
|
class FillPdfForm extends FillPdfFormBase {
|
|
9
9
|
public fillDocument(documentName: string) {
|
|
10
10
|
const result: FDFType = {
|
|
11
|
-
id:
|
|
12
|
-
fields: {}
|
|
13
|
-
}
|
|
11
|
+
id: "",
|
|
12
|
+
fields: {},
|
|
13
|
+
};
|
|
14
14
|
|
|
15
15
|
// Getting document
|
|
16
|
-
const document = this.references.documents[documentName]
|
|
17
|
-
const { pdf } = document
|
|
18
|
-
if (typeof pdf ===
|
|
19
|
-
const { form } = pdf
|
|
16
|
+
const document = this.references.documents[documentName];
|
|
17
|
+
const { pdf } = document;
|
|
18
|
+
if (typeof pdf === "undefined") return result;
|
|
19
|
+
const { form } = pdf;
|
|
20
20
|
|
|
21
21
|
// Setting pdf ID
|
|
22
|
-
result.id = pdf.id
|
|
22
|
+
result.id = pdf.id;
|
|
23
23
|
|
|
24
24
|
// Filling inputs
|
|
25
|
-
form.inputs.forEach(input => {
|
|
26
|
-
const id = `${input.name}
|
|
27
|
-
result.fields[id] = this.getInputValue(input)
|
|
28
|
-
})
|
|
25
|
+
form.inputs.forEach((input) => {
|
|
26
|
+
const id = `${input.name}`;
|
|
27
|
+
result.fields[id] = this.getInputValue(input);
|
|
28
|
+
});
|
|
29
29
|
|
|
30
30
|
// Filling boxes
|
|
31
|
-
form.boxes.forEach(box => {
|
|
32
|
-
const id = `${box.name}
|
|
33
|
-
const value = this.getBoxValue(box)
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
form.boxes.forEach((box) => {
|
|
32
|
+
const id = `${box.name}`;
|
|
33
|
+
const value = this.getBoxValue(box);
|
|
34
|
+
if (
|
|
35
|
+
!(
|
|
36
|
+
value === "" &&
|
|
37
|
+
Object.prototype.hasOwnProperty.call(result.fields, id)
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
result.fields[id] = value;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return result;
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
/**
|
|
@@ -43,60 +49,64 @@ class FillPdfForm extends FillPdfFormBase {
|
|
|
43
49
|
*/
|
|
44
50
|
private getInputValue(input: FDFInputsV3): string {
|
|
45
51
|
for (let i = 0; i < input.variables.length; i += 1) {
|
|
46
|
-
const variable = input.variables[i]
|
|
47
|
-
const currentValue = this.getVariableValue(variable.id)
|
|
52
|
+
const variable = input.variables[i];
|
|
53
|
+
const currentValue = this.getVariableValue(variable.id);
|
|
48
54
|
|
|
49
55
|
if (currentValue !== false) {
|
|
50
56
|
// Date values
|
|
51
|
-
const dateRegex = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})
|
|
57
|
+
const dateRegex = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
|
|
52
58
|
if (variable.date && dateRegex.test(currentValue)) {
|
|
53
59
|
switch (variable.date) {
|
|
54
|
-
case
|
|
55
|
-
return currentValue.replace(dateRegex,
|
|
56
|
-
case
|
|
57
|
-
return currentValue.replace(dateRegex,
|
|
58
|
-
case
|
|
59
|
-
return currentValue.replace(dateRegex,
|
|
60
|
+
case "DD":
|
|
61
|
+
return currentValue.replace(dateRegex, "$1");
|
|
62
|
+
case "MM":
|
|
63
|
+
return currentValue.replace(dateRegex, "$2");
|
|
64
|
+
case "YYYY":
|
|
65
|
+
return currentValue.replace(dateRegex, "$3");
|
|
60
66
|
default:
|
|
61
67
|
}
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
// Hour values
|
|
65
|
-
const hourRegex = /^([0-9]{2}:[0-9]{2})
|
|
71
|
+
const hourRegex = /^([0-9]{2}:[0-9]{2})$/;
|
|
66
72
|
if (variable.hour && hourRegex.test(currentValue)) {
|
|
67
73
|
switch (variable.hour) {
|
|
68
|
-
case
|
|
69
|
-
return currentValue.replace(hourRegex,
|
|
70
|
-
case
|
|
71
|
-
return currentValue.replace(hourRegex,
|
|
74
|
+
case "HH":
|
|
75
|
+
return currentValue.replace(hourRegex, "$1");
|
|
76
|
+
case "MM":
|
|
77
|
+
return currentValue.replace(hourRegex, "$2");
|
|
72
78
|
default:
|
|
73
79
|
}
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
// Email values
|
|
77
|
-
const emailRegex = /^(.*)@(.*)
|
|
83
|
+
const emailRegex = /^(.*)@(.*)$/;
|
|
78
84
|
if (variable.email && emailRegex.test(currentValue)) {
|
|
79
85
|
switch (variable.email) {
|
|
80
|
-
case
|
|
81
|
-
return currentValue.split(
|
|
82
|
-
case
|
|
83
|
-
return currentValue.split(
|
|
86
|
+
case "ADDRESS":
|
|
87
|
+
return currentValue.split("@")[0];
|
|
88
|
+
case "PROVIDER":
|
|
89
|
+
return currentValue.split("@")[1];
|
|
84
90
|
default:
|
|
85
91
|
}
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
// Fragment values
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
if (
|
|
96
|
+
variable.fragment &&
|
|
97
|
+
typeof variable.fragment.from === "number" &&
|
|
98
|
+
typeof variable.fragment.to === "number"
|
|
99
|
+
) {
|
|
100
|
+
const { from, to } = variable.fragment;
|
|
101
|
+
return currentValue.slice(from, to);
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
// Return value
|
|
95
|
-
return currentValue
|
|
105
|
+
return currentValue;
|
|
96
106
|
}
|
|
97
107
|
}
|
|
98
108
|
|
|
99
|
-
return
|
|
109
|
+
return "";
|
|
100
110
|
}
|
|
101
111
|
|
|
102
112
|
/**
|
|
@@ -105,17 +115,20 @@ class FillPdfForm extends FillPdfFormBase {
|
|
|
105
115
|
*/
|
|
106
116
|
private getBoxValue(box: FDFBoxesV3): string {
|
|
107
117
|
for (let i = 0; i < box.options.length; i += 1) {
|
|
108
|
-
const option = box.options[i]
|
|
109
|
-
const currentValue = this.getOptionValue(option.id)
|
|
118
|
+
const option = box.options[i];
|
|
119
|
+
const currentValue = this.getOptionValue(option.id);
|
|
110
120
|
|
|
111
121
|
if (currentValue === true) {
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
|
|
122
|
+
if (
|
|
123
|
+
this.references.options[option.id].meta.type === "checkbox" &&
|
|
124
|
+
box.value === "Off"
|
|
125
|
+
)
|
|
126
|
+
return "On";
|
|
127
|
+
return box.value;
|
|
115
128
|
}
|
|
116
129
|
}
|
|
117
130
|
|
|
118
|
-
return
|
|
131
|
+
return "";
|
|
119
132
|
}
|
|
120
133
|
|
|
121
134
|
/**
|
|
@@ -123,10 +136,10 @@ class FillPdfForm extends FillPdfFormBase {
|
|
|
123
136
|
*/
|
|
124
137
|
private getVariableValue(variableId: number) {
|
|
125
138
|
// Checking if variable is displayed
|
|
126
|
-
if (this.isVariableDisplayed(variableId, 0) === false) return false
|
|
139
|
+
if (this.isVariableDisplayed(variableId, 0) === false) return false;
|
|
127
140
|
|
|
128
141
|
// Returning variable's value
|
|
129
|
-
return (this.ovc.variables[variableId]?.[0] ||
|
|
142
|
+
return (this.ovc.variables[variableId]?.[0] || "").toString();
|
|
130
143
|
}
|
|
131
144
|
|
|
132
145
|
/**
|
|
@@ -134,11 +147,11 @@ class FillPdfForm extends FillPdfFormBase {
|
|
|
134
147
|
*/
|
|
135
148
|
private getOptionValue(optionId: number) {
|
|
136
149
|
// Checking if option is displayed
|
|
137
|
-
if (this.isOptionDisplayed(optionId, 0) === false) return false
|
|
150
|
+
if (this.isOptionDisplayed(optionId, 0) === false) return false;
|
|
138
151
|
|
|
139
152
|
// Returning option's value
|
|
140
|
-
return this.ovc.options[optionId]?.[0] === true
|
|
153
|
+
return this.ovc.options[optionId]?.[0] === true;
|
|
141
154
|
}
|
|
142
155
|
}
|
|
143
156
|
|
|
144
|
-
export default FillPdfForm
|
|
157
|
+
export default FillPdfForm;
|