@legalplace/prerenderx 2.6.3 → 3.0.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.
@@ -0,0 +1,25 @@
1
+ import { Types } from '@legalplace/referencesparser';
2
+ import ConditionsRunner from './ConditionsRunner';
3
+ import OVC_TYPE from './ovc.type';
4
+ import NumAuto from './NumAuto';
5
+ declare class OptionRender {
6
+ outputs: string[];
7
+ references: Types.ReferencesType;
8
+ index: number;
9
+ id: number;
10
+ conditions: ConditionsRunner;
11
+ ovc: OVC_TYPE;
12
+ private NumAuto;
13
+ constructor(options: {
14
+ references: Types.ReferencesType;
15
+ conditions: ConditionsRunner;
16
+ ovc: OVC_TYPE;
17
+ index: number;
18
+ id: number;
19
+ numauto: NumAuto;
20
+ });
21
+ getOutputs(): string[];
22
+ private renderOption;
23
+ private renderChildren;
24
+ }
25
+ export default OptionRender;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
3
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
5
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6
+ r[k] = a[j];
7
+ return r;
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ var OutputParser_1 = require("./OutputParser");
11
+ var OptionRender = (function () {
12
+ function OptionRender(options) {
13
+ this.outputs = [];
14
+ this.references = options.references;
15
+ this.conditions = options.conditions;
16
+ this.index = options.index;
17
+ this.id = options.id;
18
+ this.ovc = options.ovc;
19
+ this.NumAuto = options.numauto;
20
+ this.renderOption();
21
+ }
22
+ OptionRender.prototype.getOutputs = function () {
23
+ return this.outputs;
24
+ };
25
+ OptionRender.prototype.renderOption = function () {
26
+ var _this = this;
27
+ var option = this.references.options[this.id];
28
+ var conditionObject = this.references.conditions.options[this.id];
29
+ var condition = conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, this.id, this.index, 'options');
30
+ if (condition === true) {
31
+ if (typeof option.meta.output === 'string' && option.meta.output.trim().length > 0) {
32
+ var outputReference = this.references.outputs[this.id];
33
+ var autonums = [];
34
+ if (condition !== false) {
35
+ autonums = outputReference.autonums.map(function (currentAn) {
36
+ var fn = currentAn[0] === 'numauto-pre' ? _this.NumAuto.getNumPre : _this.NumAuto.getNum;
37
+ return [currentAn[0], currentAn[1], fn(currentAn[1], currentAn[2]), currentAn[2]];
38
+ });
39
+ }
40
+ var variables = OutputParser_1.getRelatedVariablesValues(this.id, this.index, outputReference.variables, this.ovc, this.references);
41
+ var output = OutputParser_1.parseOutputWithVariables(option.meta.output, this.index, variables, autonums);
42
+ output = output.replace(/<\/([a-z]+)>([\n\s]+)</gi, '</$1><');
43
+ output = output.replace(/\n/g, '<br />');
44
+ output = output.replace(/\xA0/g, ' ');
45
+ this.outputs.push(output);
46
+ }
47
+ this.renderChildren();
48
+ }
49
+ };
50
+ OptionRender.prototype.renderChildren = function () {
51
+ var _this = this;
52
+ var option = this.references.options[this.id];
53
+ option.options.forEach(function (optionId) {
54
+ _this.outputs = __spreadArrays(_this.outputs, new OptionRender({
55
+ references: _this.references,
56
+ id: optionId,
57
+ ovc: _this.ovc,
58
+ index: _this.index,
59
+ conditions: _this.conditions,
60
+ numauto: _this.NumAuto
61
+ }).getOutputs());
62
+ });
63
+ };
64
+ return OptionRender;
65
+ }());
66
+ exports.default = OptionRender;
@@ -0,0 +1,11 @@
1
+ import { Types } from '@legalplace/referencesparser';
2
+ import OVC_TYPE from './ovc.type';
3
+ declare type relVarsValsT = Record<string, string | number>;
4
+ declare type getRelatedVarsT = (optionId: number, index: number, variables: number[], ovc: OVC_TYPE, references: Types.ReferencesType) => relVarsValsT;
5
+ export declare const getRelatedVariablesValues: getRelatedVarsT;
6
+ declare type autonumsType = [string, string, number, string | null][];
7
+ declare type parseOutputT = (output: string, index: number, variables: relVarsValsT, autonums: autonumsType) => string;
8
+ export declare const parseOutputWithVariables: parseOutputT;
9
+ declare type TParseDocumentNameWithVariables = (text: string, ovc: OVC_TYPE, references: Types.ReferencesType, fallback?: string) => string;
10
+ export declare const parseDocumentNameWithVariables: TParseDocumentNameWithVariables;
11
+ export {};
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
3
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
5
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6
+ r[k] = a[j];
7
+ return r;
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.parseDocumentNameWithVariables = exports.parseOutputWithVariables = exports.getRelatedVariablesValues = void 0;
11
+ var frenchNumber = function (value) {
12
+ var result = typeof value === 'number' ? value.toString() : value;
13
+ if (/^([0-9]+)\.([0-9]+)$/.test(result.trim()))
14
+ result = result.trim().replace('.', ',');
15
+ return result;
16
+ };
17
+ exports.getRelatedVariablesValues = function (optionId, index, variables, ovc, references) {
18
+ var variablesValues = {};
19
+ variables.forEach(function (currentVariableId) {
20
+ var value = ovc.variables[currentVariableId] || [''];
21
+ var variableParents = references.relations.variables[currentVariableId].parents;
22
+ if (variableParents === undefined)
23
+ throw new Error("Variable " + currentVariableId + " parents object does not exist");
24
+ var rootVariableParentId = variableParents[variableParents.length - 1];
25
+ var rootVariableParentRelations = references.relations.options[rootVariableParentId];
26
+ if (rootVariableParentRelations === undefined)
27
+ throw new Error("Option " + rootVariableParentId + " does not exist");
28
+ if (typeof variableParents === 'undefined')
29
+ return;
30
+ if (rootVariableParentRelations.children.options.includes(optionId) || rootVariableParentRelations.dependants.includes(optionId) || optionId === rootVariableParentId)
31
+ value = [value[index]];
32
+ var cleanValues = value.map(function (currentValue) {
33
+ if (['number', 'string'].includes(typeof currentValue))
34
+ return frenchNumber(currentValue);
35
+ return '';
36
+ });
37
+ var currentVariableValue = cleanValues.length === 1 ? cleanValues[0] : cleanValues.join(', ');
38
+ variablesValues[currentVariableId] = currentVariableValue;
39
+ });
40
+ return variablesValues;
41
+ };
42
+ exports.parseOutputWithVariables = function (output, index, variables, autonums) {
43
+ var parsedOutput = "" + output;
44
+ Object.keys(variables).forEach(function (variableId) {
45
+ var value = variables[variableId].toString();
46
+ if (value.trim().length === 0) {
47
+ value = new Array(16).join('_');
48
+ }
49
+ value = value.replace(/\n/g, '<br />');
50
+ parsedOutput = parsedOutput.replace(new RegExp("\\[var:" + variableId + "\\]", 'g'), value);
51
+ });
52
+ parsedOutput = parsedOutput.replace(/\[\[PAGE_BREAK\]\]/gi, '<div style="page-break-after:always"></div>');
53
+ parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi, '');
54
+ parsedOutput = parsedOutput.replace(/\[signature:([0-9]+)\]/g, function (v, signatureId) { return "<span data-signature-id=\"" + signatureId + "\" data-signer-index=\"" + index + "\"></span>"; });
55
+ autonums.forEach(function (currentAn) {
56
+ if (currentAn[3] === null)
57
+ parsedOutput = parsedOutput.replace("[" + currentAn[0] + ":" + currentAn[1] + "]", "<span class=\"" + currentAn[0] + "\">" + currentAn[2] + "</span>");
58
+ else
59
+ parsedOutput = parsedOutput.replace("[" + currentAn[0] + ":" + currentAn[1] + "](" + currentAn[3] + ")", "<span class=\"" + currentAn[0] + "\">" + currentAn[2] + "</span>");
60
+ });
61
+ return parsedOutput;
62
+ };
63
+ exports.parseDocumentNameWithVariables = function (text, ovc, references, fallback) {
64
+ var tagsMatch = text.match(/\[var:([0-9]+)\]/gi);
65
+ var variables = [];
66
+ if (tagsMatch !== null) {
67
+ var variablesTags = __spreadArrays(tagsMatch);
68
+ variables = variablesTags.map(function (current) {
69
+ var outputVariableMatch = current.match(/([0-9]+)/);
70
+ if (outputVariableMatch === null)
71
+ return 0;
72
+ return parseInt(outputVariableMatch[0], 10);
73
+ });
74
+ }
75
+ variables = variables.filter(function (c, i) { return variables.indexOf(c) === i; });
76
+ variables = variables.filter(function (c) { return ovc !== undefined || references.variables[c] !== undefined; });
77
+ var variablesValues = {};
78
+ variables.forEach(function (variableId) {
79
+ var _a;
80
+ var value = ((_a = ovc.variables[variableId]) === null || _a === void 0 ? void 0 : _a[0]) || '';
81
+ variablesValues[variableId] = value.toString();
82
+ });
83
+ var parsedText = "" + text;
84
+ variables.forEach(function (variableId) {
85
+ var value = variablesValues[variableId];
86
+ if (value.trim().length === 0 && fallback)
87
+ parsedText = fallback;
88
+ if (parsedText === fallback && fallback)
89
+ return;
90
+ parsedText = parsedText.replace(new RegExp("\\[var:" + variableId + "\\]", 'gi'), value);
91
+ });
92
+ return parsedText;
93
+ };
@@ -0,0 +1,21 @@
1
+ import OVC_TYPE from './ovc.type';
2
+ import { Types } from '@legalplace/referencesparser';
3
+ export interface OldOVC {
4
+ o: {
5
+ [k: string]: string | number | (string | number)[];
6
+ };
7
+ v: {
8
+ [k: string]: string | number | (string | number)[];
9
+ };
10
+ c: {
11
+ [k: string]: boolean | boolean[];
12
+ };
13
+ }
14
+ declare class OvcConverter {
15
+ convertToOptionsVariables(ovc: OldOVC, references: Types.ReferencesType): OVC_TYPE;
16
+ isOvc(_obj: OVC_TYPE | OldOVC): _obj is OldOVC;
17
+ isOptionsVariables(_obj: OVC_TYPE | OldOVC): boolean;
18
+ private pushStaticChildren;
19
+ }
20
+ declare const _default: OvcConverter;
21
+ export default _default;
@@ -0,0 +1,132 @@
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
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
14
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
15
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
16
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
17
+ r[k] = a[j];
18
+ return r;
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ var OvcConverter = (function () {
22
+ function OvcConverter() {
23
+ }
24
+ OvcConverter.prototype.convertToOptionsVariables = function (ovc, references) {
25
+ var _this = this;
26
+ var inputs = {
27
+ options: {},
28
+ variables: {}
29
+ };
30
+ if (typeof ovc !== 'object')
31
+ return inputs;
32
+ if (typeof ovc.o === 'object') {
33
+ Object.keys(ovc.o).forEach(function (id) {
34
+ var currentOption = ovc.o[id];
35
+ if (Array.isArray(currentOption)) {
36
+ var occurences_1 = currentOption.length;
37
+ inputs.options = __assign(__assign({}, inputs.options), _this.pushStaticChildren(inputs.options, id, occurences_1, references));
38
+ currentOption.forEach(function (childId, index) {
39
+ var sanitizedId = typeof childId === 'string' && childId.split('_').length > 0
40
+ ? childId.split('_')[0]
41
+ : childId;
42
+ if (!Object.prototype.hasOwnProperty.call(inputs.options, id)) {
43
+ inputs.options[id] = new Array(occurences_1).fill(false);
44
+ }
45
+ if (typeof sanitizedId === 'string' &&
46
+ sanitizedId.trim().length === 0) {
47
+ return;
48
+ }
49
+ if (!Object.prototype.hasOwnProperty.call(inputs.options, sanitizedId)) {
50
+ inputs.options[sanitizedId] = new Array(occurences_1).fill(false);
51
+ }
52
+ inputs.options = __assign(__assign({}, inputs.options), _this.pushStaticChildren(inputs.options, sanitizedId, occurences_1, references));
53
+ inputs.options[sanitizedId][index] = true;
54
+ });
55
+ }
56
+ else {
57
+ if (typeof currentOption === 'string' &&
58
+ currentOption.trim().length === 0)
59
+ return;
60
+ inputs.options[currentOption] = [true];
61
+ }
62
+ });
63
+ }
64
+ if (typeof ovc.c === 'object') {
65
+ Object.keys(ovc.c).forEach(function (id) {
66
+ var currentCheckbox = ovc.c[id];
67
+ if (typeof id === 'string' && id.trim().length === 0)
68
+ return;
69
+ if (Array.isArray(currentCheckbox)) {
70
+ inputs.options[id] = currentCheckbox;
71
+ }
72
+ else {
73
+ inputs.options[id] = [currentCheckbox];
74
+ }
75
+ });
76
+ }
77
+ if (typeof ovc.v === 'object') {
78
+ Object.keys(ovc.v).forEach(function (id) {
79
+ var currentVariable = ovc.v[id];
80
+ if (Array.isArray(currentVariable)) {
81
+ inputs.variables[id] = currentVariable;
82
+ var parentsTree = references.relations.variables[id].parents;
83
+ var parentOption = inputs.options["" + parentsTree[parentsTree.length - 1]];
84
+ if (Array.isArray(parentOption)) {
85
+ var occurences = parentOption.length;
86
+ if (currentVariable.length < occurences) {
87
+ inputs.variables[id] = __spreadArrays(currentVariable, Array(occurences - currentVariable.length).fill(''));
88
+ }
89
+ }
90
+ }
91
+ else {
92
+ inputs.variables[id] = [currentVariable];
93
+ }
94
+ });
95
+ }
96
+ return inputs;
97
+ };
98
+ OvcConverter.prototype.isOvc = function (_obj) {
99
+ if (typeof _obj !== 'object' || _obj === null)
100
+ return false;
101
+ var ovcKeys = ['o', 'v', 'c'];
102
+ var foundKeys = Object.keys(_obj)
103
+ .map(function (key) { return (ovcKeys.includes(key) ? 1 : 0); })
104
+ .reduce(function (a, b) { return a + b; }, 0);
105
+ return foundKeys > 1;
106
+ };
107
+ OvcConverter.prototype.isOptionsVariables = function (_obj) {
108
+ if (typeof _obj !== 'object' || _obj === null)
109
+ return false;
110
+ var optionsVariablesKeys = ['options', 'variables'];
111
+ var foundKeys = Object.keys(_obj)
112
+ .map(function (key) { return (optionsVariablesKeys.includes(key) ? 1 : 0); })
113
+ .reduce(function (a, b) { return a + b; }, 0);
114
+ return foundKeys === 2;
115
+ };
116
+ OvcConverter.prototype.pushStaticChildren = function (inputOptions, id, occurences, references) {
117
+ var result = __assign({}, inputOptions);
118
+ var intId = typeof id === 'number' ? id : parseInt(id, 10);
119
+ var options = references.relations.options[intId].children.options;
120
+ var staticOptions = options.filter(function (childId) {
121
+ return references.options[childId].meta.type === 'static';
122
+ });
123
+ staticOptions.forEach(function (childId) {
124
+ if (!Object.prototype.hasOwnProperty.call(result, childId)) {
125
+ result[childId] = new Array(occurences).fill(false);
126
+ }
127
+ });
128
+ return result;
129
+ };
130
+ return OvcConverter;
131
+ }());
132
+ exports.default = new OvcConverter();
@@ -0,0 +1,42 @@
1
+ import { ModelV3 } from '@legalplace/models-v3-types';
2
+ import OVC_TYPE from './ovc.type';
3
+ import { OldOVC } from './OvcConverter';
4
+ declare type DocumentOutputIndex = {
5
+ name: string;
6
+ slug: string;
7
+ pdf: boolean;
8
+ docx: boolean;
9
+ };
10
+ declare type DocumentPdfFormIndex = {
11
+ name: string;
12
+ slug: string;
13
+ form: boolean;
14
+ fdf: {
15
+ id: string;
16
+ fields: Record<string, string>;
17
+ };
18
+ };
19
+ declare type FDFType = {
20
+ id: string;
21
+ fields: Record<string, string>;
22
+ };
23
+ declare class Prerender {
24
+ private model;
25
+ private references;
26
+ private ovc;
27
+ private conditions;
28
+ private documentRender;
29
+ private pdfFiller;
30
+ private NumAuto;
31
+ private documentsIndex;
32
+ private renderedDocuments;
33
+ constructor(model: ModelV3, ovc: OVC_TYPE | OldOVC);
34
+ getDocumentsIndex(): Record<string, DocumentOutputIndex | DocumentPdfFormIndex>;
35
+ getDocument(documentNameHash: string): string | FDFType;
36
+ private generateDocumentNamesHash;
37
+ private fillPdfForms;
38
+ private generateAllDocuments;
39
+ static isPdfForm(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentPdfFormIndex;
40
+ static isOutput(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentOutputIndex;
41
+ }
42
+ export default Prerender;
@@ -0,0 +1,103 @@
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
+ var referencesparser_1 = require("@legalplace/referencesparser");
7
+ var crypto_1 = __importDefault(require("crypto"));
8
+ var DocumentRender_1 = __importDefault(require("./DocumentRender"));
9
+ var ConditionsRunner_1 = __importDefault(require("./ConditionsRunner"));
10
+ var OvcConverter_1 = __importDefault(require("./OvcConverter"));
11
+ var NumAuto_1 = __importDefault(require("./NumAuto"));
12
+ var InputsInitiator_1 = __importDefault(require("./InputsInitiator"));
13
+ var FillPdfForm_1 = __importDefault(require("./FillPdfForm"));
14
+ var OutputParser_1 = require("./OutputParser");
15
+ var Prerender = (function () {
16
+ function Prerender(model, ovc) {
17
+ this.documentsIndex = {};
18
+ this.renderedDocuments = {};
19
+ this.model = model;
20
+ this.NumAuto = new NumAuto_1.default();
21
+ this.references = new referencesparser_1.ReferencesParser(model).getReferences();
22
+ this.ovc = OvcConverter_1.default.isOvc(ovc)
23
+ ? OvcConverter_1.default.convertToOptionsVariables(ovc, this.references)
24
+ : ovc;
25
+ var inputs = new InputsInitiator_1.default(this.references, this.ovc).getInputs();
26
+ this.conditions = new ConditionsRunner_1.default(this.references, inputs);
27
+ this.documentRender = new DocumentRender_1.default(this.references, this.conditions, inputs, this.NumAuto);
28
+ this.pdfFiller = new FillPdfForm_1.default(this.references, this.conditions, inputs);
29
+ this.generateDocumentNamesHash();
30
+ this.generateAllDocuments();
31
+ this.fillPdfForms();
32
+ }
33
+ Prerender.prototype.getDocumentsIndex = function () {
34
+ return this.documentsIndex;
35
+ };
36
+ Prerender.prototype.getDocument = function (documentNameHash) {
37
+ return this.renderedDocuments[documentNameHash];
38
+ };
39
+ Prerender.prototype.generateDocumentNamesHash = function () {
40
+ var _this = this;
41
+ Object.keys(this.model.documents).forEach(function (slug) {
42
+ var _a, _b;
43
+ var document = _this.model.documents[slug];
44
+ var documentParams = _this.model.documents[slug].params;
45
+ var conditionObject = _this.references.conditions.documents[slug];
46
+ var condition = conditionObject === undefined ? true : _this.conditions.executeCondition(conditionObject, 0, 0, 'documents');
47
+ if (condition === true) {
48
+ var hash = crypto_1.default
49
+ .createHash('sha1')
50
+ .update(slug)
51
+ .digest('hex');
52
+ if (typeof document.pdf === 'object' && typeof document.pdf.id === 'string' && typeof document.pdf.form === 'object') {
53
+ _this.documentsIndex[hash] = {
54
+ name: OutputParser_1.parseDocumentNameWithVariables(document.name, _this.ovc, _this.references, document.fallbackName),
55
+ slug: slug,
56
+ form: true,
57
+ fdf: {
58
+ id: '',
59
+ fields: {}
60
+ }
61
+ };
62
+ }
63
+ else {
64
+ _this.documentsIndex[hash] = {
65
+ name: OutputParser_1.parseDocumentNameWithVariables(document.name, _this.ovc, _this.references, document.fallbackName),
66
+ slug: slug,
67
+ pdf: ((_a = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _a === void 0 ? void 0 : _a.pdf) === undefined ? true : documentParams.formats.pdf,
68
+ docx: ((_b = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _b === void 0 ? void 0 : _b.docx) === undefined ? true : documentParams.formats.docx
69
+ };
70
+ }
71
+ }
72
+ });
73
+ };
74
+ Prerender.prototype.fillPdfForms = function () {
75
+ var _this = this;
76
+ Object.keys(this.documentsIndex).forEach(function (documentNameHash) {
77
+ var index = _this.documentsIndex[documentNameHash];
78
+ if (Prerender.isPdfForm(index)) {
79
+ index.fdf = _this.getDocument(documentNameHash);
80
+ }
81
+ });
82
+ };
83
+ Prerender.prototype.generateAllDocuments = function () {
84
+ var _this = this;
85
+ Object.keys(this.documentsIndex).forEach(function (documentNameHash) {
86
+ var index = _this.documentsIndex[documentNameHash];
87
+ if (Prerender.isPdfForm(index)) {
88
+ _this.renderedDocuments[documentNameHash] = _this.pdfFiller.fillDocument(_this.documentsIndex[documentNameHash].slug);
89
+ }
90
+ else {
91
+ _this.renderedDocuments[documentNameHash] = _this.documentRender.renderDocument(_this.documentsIndex[documentNameHash].slug);
92
+ }
93
+ });
94
+ };
95
+ Prerender.isPdfForm = function (index) {
96
+ return Object.prototype.hasOwnProperty.call(index, 'form');
97
+ };
98
+ Prerender.isOutput = function (index) {
99
+ return !Object.prototype.hasOwnProperty.call(index, 'form');
100
+ };
101
+ return Prerender;
102
+ }());
103
+ exports.default = Prerender;
@@ -0,0 +1,24 @@
1
+ import { Types } from '@legalplace/referencesparser';
2
+ import ConditionsRunner from './ConditionsRunner';
3
+ import OVC_TYPE from './ovc.type';
4
+ import NumAuto from './NumAuto';
5
+ declare class SectionRender {
6
+ outputs: string[];
7
+ references: Types.ReferencesType;
8
+ currentSection: number;
9
+ documentName: string;
10
+ conditions: ConditionsRunner;
11
+ ovc: OVC_TYPE;
12
+ private NumAuto;
13
+ constructor(options: {
14
+ references: Types.ReferencesType;
15
+ conditions: ConditionsRunner;
16
+ ovc: OVC_TYPE;
17
+ documentName: string;
18
+ currentSection: number;
19
+ numauto: NumAuto;
20
+ });
21
+ getOutputs(): string[];
22
+ private renderSection;
23
+ }
24
+ export default SectionRender;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
3
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
5
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6
+ r[k] = a[j];
7
+ return r;
8
+ };
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ var OptionRender_1 = __importDefault(require("./OptionRender"));
14
+ var SectionRender = (function () {
15
+ function SectionRender(options) {
16
+ this.outputs = [];
17
+ this.references = options.references;
18
+ this.conditions = options.conditions;
19
+ this.documentName = options.documentName;
20
+ this.currentSection = options.currentSection;
21
+ this.ovc = options.ovc;
22
+ this.NumAuto = options.numauto;
23
+ this.renderSection();
24
+ }
25
+ SectionRender.prototype.getOutputs = function () {
26
+ return this.outputs;
27
+ };
28
+ SectionRender.prototype.renderSection = function () {
29
+ var _this = this;
30
+ var section = this.references.sections[this.documentName][this.currentSection];
31
+ var conditionObject = this.references.conditions.sections[this.documentName][this.currentSection];
32
+ var condition = conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, 0, 0, 'sections');
33
+ if (condition === true) {
34
+ section.options.forEach(function (optionId) {
35
+ var option = _this.references.options[optionId];
36
+ var repeatOption = optionId;
37
+ if (option.meta.type === 'repeated') {
38
+ if (option.meta.repeatOption === undefined)
39
+ return;
40
+ repeatOption = typeof option.meta.repeatOption === 'number' ? option.meta.repeatOption : parseInt(option.meta.repeatOption, 10);
41
+ }
42
+ var inputs = _this.ovc.options[repeatOption] || [!['radio', 'checkbox'].includes(option.meta.type)];
43
+ inputs.forEach(function (value, index) {
44
+ if (value !== true)
45
+ return;
46
+ _this.outputs = __spreadArrays(_this.outputs, new OptionRender_1.default({
47
+ references: _this.references,
48
+ id: optionId,
49
+ ovc: _this.ovc,
50
+ index: index,
51
+ conditions: _this.conditions,
52
+ numauto: _this.NumAuto
53
+ }).getOutputs());
54
+ });
55
+ });
56
+ }
57
+ };
58
+ return SectionRender;
59
+ }());
60
+ exports.default = SectionRender;
@@ -0,0 +1,16 @@
1
+ import { Types } from '@legalplace/referencesparser';
2
+ import ConditionsRunner from '../ConditionsRunner';
3
+ import OVC_TYPE from '../ovc.type';
4
+ declare class FillPdfFormBase {
5
+ references: Types.ReferencesType;
6
+ conditions: ConditionsRunner;
7
+ ovc: OVC_TYPE;
8
+ constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: OVC_TYPE);
9
+ isVariableDisplayed(id: number, index: number): boolean;
10
+ isOptionDisplayed(id: number, index: number): boolean;
11
+ private getVariableCondition;
12
+ private getOptionCondition;
13
+ private getSectionCondition;
14
+ private getOptionParentSection;
15
+ }
16
+ export default FillPdfFormBase;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
3
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
5
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6
+ r[k] = a[j];
7
+ return r;
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ var FillPdfFormBase = (function () {
11
+ function FillPdfFormBase(references, conditions, ovc) {
12
+ this.references = references;
13
+ this.conditions = conditions;
14
+ this.ovc = ovc;
15
+ }
16
+ FillPdfFormBase.prototype.isVariableDisplayed = function (id, index) {
17
+ var _a;
18
+ var variableCondition = this.getVariableCondition(id, index);
19
+ var variableParents = ((_a = this.references.relations.variables[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
20
+ var parentOptionIsDisplayed = this.isOptionDisplayed(variableParents[0], index);
21
+ return [variableCondition, parentOptionIsDisplayed].filter(function (c) { return c !== true; }).length === 0;
22
+ };
23
+ FillPdfFormBase.prototype.isOptionDisplayed = function (id, index) {
24
+ var _this = this;
25
+ var _a;
26
+ var optionCondition = this.getOptionCondition(id, index);
27
+ var optionParents = ((_a = this.references.relations.options[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
28
+ var parentsConditions = optionParents.map(function (optionId) {
29
+ return _this.getOptionCondition(optionId, index) !== false;
30
+ });
31
+ var parentsInputs = optionParents.map(function (optionId) {
32
+ return _this.ovc.options[optionId][index];
33
+ });
34
+ var parentSectionId = this.getOptionParentSection(id);
35
+ var parentSectionCondition = this.getSectionCondition(parentSectionId) !== false;
36
+ return __spreadArrays([optionCondition, parentSectionCondition], parentsConditions, parentsInputs).filter(function (c) { return c !== true; }).length === 0;
37
+ };
38
+ FillPdfFormBase.prototype.getVariableCondition = function (id, index) {
39
+ var conditionObject = this.references.conditions.variables[id];
40
+ return conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, id, index, 'variables');
41
+ };
42
+ FillPdfFormBase.prototype.getOptionCondition = function (id, index) {
43
+ var conditionObject = this.references.conditions.options[id];
44
+ return conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, id, index, 'options');
45
+ };
46
+ FillPdfFormBase.prototype.getSectionCondition = function (id) {
47
+ var conditionObject = this.references.conditions.sections.main[id];
48
+ return conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, id, 0, 'sections');
49
+ };
50
+ FillPdfFormBase.prototype.getOptionParentSection = function (id) {
51
+ var parents = this.references.relations.options[id].parents;
52
+ var rootId = parents.length > 0 ? parents[parents.length - 1] : id;
53
+ var sections = Object.values(this.references.sections.main);
54
+ for (var i = 0; i < sections.length; i += 1) {
55
+ if (sections[i].options.includes(rootId))
56
+ return sections[i].id;
57
+ }
58
+ throw new Error("Cannot find parent section for option " + id + " (Root option id: " + rootId + ")");
59
+ };
60
+ return FillPdfFormBase;
61
+ }());
62
+ exports.default = FillPdfFormBase;