@legalplace/prerenderx 3.2.0 → 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 +28 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +11 -0
- 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 -26
- package/dist/libs/Prerender.js +30 -23
- 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/dist/types/types.d.ts +17 -0
- package/dist/types/types.js +2 -0
- package/package.json +14 -18
- package/src/index.ts +4 -2
- 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 +120 -98
- package/src/libs/SectionRender.ts +57 -38
- package/src/libs/misc/FillPdfFormBase.ts +71 -39
- package/src/types/types.ts +22 -0
- 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/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;
|
|
@@ -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;
|