@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
|
@@ -1,68 +1,71 @@
|
|
|
1
|
-
import { Types } from
|
|
1
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
2
2
|
|
|
3
|
-
type References = Types.ReferencesType
|
|
3
|
+
type References = Types.ReferencesType;
|
|
4
4
|
|
|
5
5
|
type OVC_TYPE = {
|
|
6
6
|
options: {
|
|
7
|
-
[key: string]: boolean[]
|
|
8
|
-
}
|
|
7
|
+
[key: string]: boolean[];
|
|
8
|
+
};
|
|
9
9
|
variables: {
|
|
10
|
-
[key: string]: (number | string)[]
|
|
11
|
-
}
|
|
12
|
-
}
|
|
10
|
+
[key: string]: (number | string)[];
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
13
|
|
|
14
14
|
class IntputsInitiator {
|
|
15
15
|
private inputs: OVC_TYPE = {
|
|
16
16
|
options: {},
|
|
17
|
-
variables: {}
|
|
18
|
-
}
|
|
17
|
+
variables: {},
|
|
18
|
+
};
|
|
19
19
|
|
|
20
|
-
private references: References
|
|
20
|
+
private references: References;
|
|
21
21
|
|
|
22
|
-
private ovc: OVC_TYPE | null
|
|
22
|
+
private ovc: OVC_TYPE | null;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* InitalConditions Constructor
|
|
26
26
|
* @param references References object
|
|
27
27
|
*/
|
|
28
28
|
constructor(references: References, ovc: OVC_TYPE | null) {
|
|
29
|
-
this.references = references
|
|
30
|
-
this.ovc = ovc
|
|
29
|
+
this.references = references;
|
|
30
|
+
this.ovc = ovc;
|
|
31
31
|
|
|
32
32
|
// Setting multiples
|
|
33
|
-
this.setMultiples()
|
|
33
|
+
this.setMultiples();
|
|
34
34
|
|
|
35
35
|
// Initiating inputs
|
|
36
|
-
this.initOptionsInputs()
|
|
37
|
-
this.initVariablesInputs()
|
|
36
|
+
this.initOptionsInputs();
|
|
37
|
+
this.initVariablesInputs();
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
public getInputs() {
|
|
41
|
-
return this.inputs
|
|
41
|
+
return this.inputs;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
private setMultiples() {
|
|
45
|
-
if (this.ovc === null) return
|
|
46
|
-
Object.keys(this.ovc.options).forEach(id => {
|
|
47
|
-
if (this.ovc === null) return
|
|
48
|
-
const inputs = this.ovc.options[id]
|
|
45
|
+
if (this.ovc === null) return;
|
|
46
|
+
Object.keys(this.ovc.options).forEach((id) => {
|
|
47
|
+
if (this.ovc === null) return;
|
|
48
|
+
const inputs = this.ovc.options[id];
|
|
49
49
|
|
|
50
50
|
if (inputs.length > 1) {
|
|
51
51
|
// Getting parents
|
|
52
|
-
const parentsTree = this.references.relations.options[id].parents
|
|
52
|
+
const parentsTree = this.references.relations.options[id].parents;
|
|
53
53
|
|
|
54
54
|
// root parent
|
|
55
|
-
const rootOptionId =
|
|
55
|
+
const rootOptionId =
|
|
56
|
+
parentsTree.length > 0 ? parentsTree[parentsTree.length - 1] : id;
|
|
56
57
|
|
|
57
58
|
if (!this.ovc.options[rootOptionId]) {
|
|
58
59
|
// root Option reference
|
|
59
|
-
const rootReference = this.references.options[rootOptionId]
|
|
60
|
-
if (rootReference.meta.type ===
|
|
61
|
-
this.ovc.options[rootOptionId] = new Array(inputs.length).fill(
|
|
60
|
+
const rootReference = this.references.options[rootOptionId];
|
|
61
|
+
if (rootReference.meta.type === "static") {
|
|
62
|
+
this.ovc.options[rootOptionId] = new Array(inputs.length).fill(
|
|
63
|
+
true
|
|
64
|
+
);
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
|
-
})
|
|
68
|
+
});
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
/**
|
|
@@ -70,23 +73,44 @@ class IntputsInitiator {
|
|
|
70
73
|
*/
|
|
71
74
|
private initOptionsInputs() {
|
|
72
75
|
// Options
|
|
73
|
-
const optionsIds = Object.keys(this.references.options)
|
|
76
|
+
const optionsIds = Object.keys(this.references.options);
|
|
74
77
|
for (let i = 0; i < optionsIds.length; i += 1) {
|
|
75
|
-
const optionId = optionsIds[i]
|
|
76
|
-
const option = this.references.options[optionId]
|
|
77
|
-
|
|
78
|
-
let values = [false]
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
const optionId = optionsIds[i];
|
|
79
|
+
const option = this.references.options[optionId];
|
|
80
|
+
|
|
81
|
+
let values = [false];
|
|
82
|
+
if (
|
|
83
|
+
this.ovc &&
|
|
84
|
+
Object.prototype.hasOwnProperty.call(this.ovc.options, optionId)
|
|
85
|
+
) {
|
|
86
|
+
if (
|
|
87
|
+
[
|
|
88
|
+
"static",
|
|
89
|
+
"hidden",
|
|
90
|
+
"brut-text",
|
|
91
|
+
"repeated",
|
|
92
|
+
"box",
|
|
93
|
+
"separator",
|
|
94
|
+
].includes(option.meta.type)
|
|
95
|
+
) {
|
|
96
|
+
values = new Array(this.ovc.options[optionId].length).fill(true);
|
|
82
97
|
} else {
|
|
83
|
-
values = this.ovc.options[optionId]
|
|
98
|
+
values = this.ovc.options[optionId];
|
|
84
99
|
}
|
|
85
|
-
} else if (
|
|
86
|
-
|
|
100
|
+
} else if (
|
|
101
|
+
[
|
|
102
|
+
"static",
|
|
103
|
+
"hidden",
|
|
104
|
+
"brut-text",
|
|
105
|
+
"repeated",
|
|
106
|
+
"box",
|
|
107
|
+
"separator",
|
|
108
|
+
].includes(option.meta.type)
|
|
109
|
+
) {
|
|
110
|
+
values = [true];
|
|
87
111
|
}
|
|
88
112
|
|
|
89
|
-
this.inputs.options[optionId] = values
|
|
113
|
+
this.inputs.options[optionId] = values;
|
|
90
114
|
}
|
|
91
115
|
}
|
|
92
116
|
|
|
@@ -94,28 +118,42 @@ class IntputsInitiator {
|
|
|
94
118
|
* Initates variables inputs
|
|
95
119
|
*/
|
|
96
120
|
private initVariablesInputs() {
|
|
97
|
-
const variablesIds = Object.keys(this.references.variables)
|
|
121
|
+
const variablesIds = Object.keys(this.references.variables);
|
|
98
122
|
for (let i = 0; i < variablesIds.length; i += 1) {
|
|
99
|
-
const variableId = variablesIds[i]
|
|
100
|
-
|
|
101
|
-
let values: (string | number)[] = [
|
|
102
|
-
if (
|
|
103
|
-
|
|
123
|
+
const variableId = variablesIds[i];
|
|
124
|
+
|
|
125
|
+
let values: (string | number)[] = [""];
|
|
126
|
+
if (
|
|
127
|
+
this.ovc &&
|
|
128
|
+
Object.prototype.hasOwnProperty.call(this.ovc.variables, variableId)
|
|
129
|
+
) {
|
|
130
|
+
values = this.ovc.variables[variableId];
|
|
104
131
|
} else {
|
|
105
|
-
let defaultValue =
|
|
132
|
+
let defaultValue = "";
|
|
106
133
|
|
|
107
134
|
// Checking for first prefill without condition
|
|
108
|
-
const { prefillings } = this.references.variables[variableId]
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
135
|
+
const { prefillings } = this.references.variables[variableId];
|
|
136
|
+
if (
|
|
137
|
+
prefillings &&
|
|
138
|
+
Array.isArray(prefillings) &&
|
|
139
|
+
prefillings.length > 0
|
|
140
|
+
) {
|
|
141
|
+
const noConditionsPrefills = prefillings.filter(
|
|
142
|
+
(prefill) =>
|
|
143
|
+
typeof prefill.conditions === "undefined" ||
|
|
144
|
+
Object.keys(prefill.conditions).length === 0
|
|
145
|
+
);
|
|
146
|
+
defaultValue =
|
|
147
|
+
noConditionsPrefills.length > 0
|
|
148
|
+
? noConditionsPrefills[0].value
|
|
149
|
+
: "";
|
|
112
150
|
}
|
|
113
|
-
values = [defaultValue]
|
|
151
|
+
values = [defaultValue];
|
|
114
152
|
}
|
|
115
153
|
|
|
116
|
-
this.inputs.variables[variableId] = values
|
|
154
|
+
this.inputs.variables[variableId] = values;
|
|
117
155
|
}
|
|
118
156
|
}
|
|
119
157
|
}
|
|
120
158
|
|
|
121
|
-
export default IntputsInitiator
|
|
159
|
+
export default IntputsInitiator;
|
package/src/libs/NumAuto.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class NumAuto {
|
|
2
|
-
indexesList: Record<string, any> = {}
|
|
2
|
+
indexesList: Record<string, any> = {};
|
|
3
3
|
|
|
4
|
-
tagsIndex: Record<string, number> = {}
|
|
4
|
+
tagsIndex: Record<string, number> = {};
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Increments the given index by 1 and
|
|
@@ -12,18 +12,19 @@ class NumAuto {
|
|
|
12
12
|
// In case the index doesn't exist
|
|
13
13
|
if (!Object.prototype.hasOwnProperty.call(this.indexesList, index)) {
|
|
14
14
|
// Let's first make sure it's not a tag and return it if it is
|
|
15
|
-
if (Object.prototype.hasOwnProperty.call(this.tagsIndex, index))
|
|
15
|
+
if (Object.prototype.hasOwnProperty.call(this.tagsIndex, index))
|
|
16
|
+
return this.tagsIndex[index];
|
|
16
17
|
|
|
17
18
|
// Otherwise we set a new index
|
|
18
|
-
this.indexesList[index] = 0
|
|
19
|
+
this.indexesList[index] = 0;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
this.indexesList[index] += 1
|
|
22
|
+
this.indexesList[index] += 1;
|
|
22
23
|
|
|
23
|
-
if (typeof tag ===
|
|
24
|
+
if (typeof tag === "string") this.tagsIndex[tag] = this.indexesList[index];
|
|
24
25
|
|
|
25
|
-
return this.indexesList[index]
|
|
26
|
-
}
|
|
26
|
+
return this.indexesList[index];
|
|
27
|
+
};
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Returns the current count of the given index
|
|
@@ -33,14 +34,15 @@ class NumAuto {
|
|
|
33
34
|
// In case the index doesn't exist
|
|
34
35
|
if (!Object.prototype.hasOwnProperty.call(this.indexesList, index)) {
|
|
35
36
|
// Let's first make sure it's not a tag and return it if it is
|
|
36
|
-
if (Object.prototype.hasOwnProperty.call(this.tagsIndex, index))
|
|
37
|
+
if (Object.prototype.hasOwnProperty.call(this.tagsIndex, index))
|
|
38
|
+
return this.tagsIndex[index];
|
|
37
39
|
}
|
|
38
|
-
return this.indexesList[index]
|
|
39
|
-
}
|
|
40
|
+
return this.indexesList[index];
|
|
41
|
+
};
|
|
40
42
|
|
|
41
43
|
resetIndexes = () => {
|
|
42
|
-
this.indexesList = {}
|
|
43
|
-
}
|
|
44
|
+
this.indexesList = {};
|
|
45
|
+
};
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
export default NumAuto
|
|
48
|
+
export default NumAuto;
|
package/src/libs/OptionRender.ts
CHANGED
|
@@ -1,82 +1,122 @@
|
|
|
1
|
-
import { Types } from
|
|
2
|
-
import ConditionsRunner from
|
|
3
|
-
import InputsType from
|
|
4
|
-
import {
|
|
5
|
-
|
|
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 {
|
|
5
|
+
parseOutputWithVariables,
|
|
6
|
+
getRelatedVariablesValues,
|
|
7
|
+
} from "./OutputParser";
|
|
8
|
+
import type NumAuto from "./NumAuto";
|
|
6
9
|
|
|
7
10
|
class OptionRender {
|
|
8
|
-
outputs: string[] = []
|
|
11
|
+
outputs: string[] = [];
|
|
9
12
|
|
|
10
|
-
references: Types.ReferencesType
|
|
13
|
+
references: Types.ReferencesType;
|
|
11
14
|
|
|
12
|
-
index: number
|
|
15
|
+
index: number;
|
|
13
16
|
|
|
14
|
-
id: number
|
|
17
|
+
id: number;
|
|
15
18
|
|
|
16
|
-
conditions: ConditionsRunner
|
|
19
|
+
conditions: ConditionsRunner;
|
|
17
20
|
|
|
18
|
-
ovc: InputsType
|
|
21
|
+
ovc: InputsType;
|
|
19
22
|
|
|
20
|
-
private NumAuto: NumAuto
|
|
23
|
+
private NumAuto: NumAuto;
|
|
21
24
|
|
|
22
|
-
constructor(options: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
constructor(options: {
|
|
26
|
+
references: Types.ReferencesType;
|
|
27
|
+
conditions: ConditionsRunner;
|
|
28
|
+
ovc: InputsType;
|
|
29
|
+
index: number;
|
|
30
|
+
id: number;
|
|
31
|
+
numauto: NumAuto;
|
|
32
|
+
}) {
|
|
33
|
+
this.references = options.references;
|
|
34
|
+
this.conditions = options.conditions;
|
|
35
|
+
this.index = options.index;
|
|
36
|
+
this.id = options.id;
|
|
37
|
+
this.ovc = options.ovc;
|
|
38
|
+
this.NumAuto = options.numauto;
|
|
29
39
|
|
|
30
|
-
this.renderOption()
|
|
40
|
+
this.renderOption();
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
getOutputs() {
|
|
34
|
-
return this.outputs
|
|
44
|
+
return this.outputs;
|
|
35
45
|
}
|
|
36
46
|
|
|
37
47
|
private renderOption() {
|
|
38
|
-
const option = this.references.options[this.id]
|
|
39
|
-
const conditionObject = this.references.conditions.options[this.id]
|
|
40
|
-
const condition =
|
|
48
|
+
const option = this.references.options[this.id];
|
|
49
|
+
const conditionObject = this.references.conditions.options[this.id];
|
|
50
|
+
const condition =
|
|
51
|
+
conditionObject === undefined
|
|
52
|
+
? true
|
|
53
|
+
: this.conditions.executeCondition(
|
|
54
|
+
conditionObject,
|
|
55
|
+
this.id,
|
|
56
|
+
this.index,
|
|
57
|
+
"options"
|
|
58
|
+
);
|
|
41
59
|
|
|
42
60
|
// Rendering documents sections
|
|
43
61
|
if (condition === true) {
|
|
44
|
-
if (
|
|
62
|
+
if (
|
|
63
|
+
typeof option.meta.output === "string" &&
|
|
64
|
+
option.meta.output.trim().length > 0
|
|
65
|
+
) {
|
|
45
66
|
// output Reference
|
|
46
|
-
const outputReference = this.references.outputs[this.id]
|
|
67
|
+
const outputReference = this.references.outputs[this.id];
|
|
47
68
|
|
|
48
69
|
// Autonums
|
|
49
|
-
let autonums: [string, string, number, string | null][] = []
|
|
70
|
+
let autonums: [string, string, number, string | null][] = [];
|
|
50
71
|
if (condition !== false) {
|
|
51
|
-
autonums = outputReference.autonums.map(currentAn => {
|
|
52
|
-
const fn =
|
|
53
|
-
|
|
54
|
-
|
|
72
|
+
autonums = outputReference.autonums.map((currentAn) => {
|
|
73
|
+
const fn =
|
|
74
|
+
currentAn[0] === "numauto-pre"
|
|
75
|
+
? this.NumAuto.getNumPre
|
|
76
|
+
: this.NumAuto.getNum;
|
|
77
|
+
return [
|
|
78
|
+
currentAn[0],
|
|
79
|
+
currentAn[1],
|
|
80
|
+
fn(currentAn[1], currentAn[2]),
|
|
81
|
+
currentAn[2],
|
|
82
|
+
];
|
|
83
|
+
});
|
|
55
84
|
}
|
|
56
85
|
|
|
57
86
|
// variables
|
|
58
|
-
const variables = getRelatedVariablesValues(
|
|
59
|
-
|
|
87
|
+
const variables = getRelatedVariablesValues(
|
|
88
|
+
this.id,
|
|
89
|
+
this.index,
|
|
90
|
+
outputReference.variables,
|
|
91
|
+
this.ovc,
|
|
92
|
+
this.references
|
|
93
|
+
);
|
|
94
|
+
let output = parseOutputWithVariables(
|
|
95
|
+
option.meta.output,
|
|
96
|
+
this.index,
|
|
97
|
+
variables,
|
|
98
|
+
autonums
|
|
99
|
+
);
|
|
60
100
|
|
|
61
101
|
// Removing spaces between tags
|
|
62
|
-
output = output.replace(/<\/([a-z]+)>([\n\s]+)</gi,
|
|
102
|
+
output = output.replace(/<\/([a-z]+)>([\n\s]+)</gi, "</$1><");
|
|
63
103
|
|
|
64
104
|
// Replacing \n with line-break
|
|
65
|
-
output = output.replace(/\n/g,
|
|
105
|
+
output = output.replace(/\n/g, "<br />");
|
|
66
106
|
|
|
67
107
|
// Cleaning \xA0
|
|
68
|
-
output = output.replace(/\xA0/g,
|
|
108
|
+
output = output.replace(/\xA0/g, " ");
|
|
69
109
|
|
|
70
110
|
// Pushing output
|
|
71
|
-
this.outputs.push(output)
|
|
111
|
+
this.outputs.push(output);
|
|
72
112
|
}
|
|
73
|
-
this.renderChildren()
|
|
113
|
+
this.renderChildren();
|
|
74
114
|
}
|
|
75
115
|
}
|
|
76
116
|
|
|
77
117
|
private renderChildren() {
|
|
78
|
-
const option = this.references.options[this.id]
|
|
79
|
-
option.options.forEach(optionId => {
|
|
118
|
+
const option = this.references.options[this.id];
|
|
119
|
+
option.options.forEach((optionId) => {
|
|
80
120
|
this.outputs = [
|
|
81
121
|
...this.outputs,
|
|
82
122
|
...new OptionRender({
|
|
@@ -85,11 +125,11 @@ class OptionRender {
|
|
|
85
125
|
ovc: this.ovc,
|
|
86
126
|
index: this.index,
|
|
87
127
|
conditions: this.conditions,
|
|
88
|
-
numauto: this.NumAuto
|
|
89
|
-
}).getOutputs()
|
|
90
|
-
]
|
|
91
|
-
})
|
|
128
|
+
numauto: this.NumAuto,
|
|
129
|
+
}).getOutputs(),
|
|
130
|
+
];
|
|
131
|
+
});
|
|
92
132
|
}
|
|
93
133
|
}
|
|
94
134
|
|
|
95
|
-
export default OptionRender
|
|
135
|
+
export default OptionRender;
|