@legalplace/prerenderx 2.3.54 → 2.4.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.
@@ -38,7 +38,7 @@ var OptionRender = (function () {
38
38
  });
39
39
  }
40
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, variables, autonums);
41
+ var output = OutputParser_1.parseOutputWithVariables(option.meta.output, this.index, variables, autonums);
42
42
  output = output.replace(/>([\n\s]+)</g, '><');
43
43
  output = output.replace(/\n/g, '<br />');
44
44
  output = output.replace(/\xA0/g, ' ');
@@ -4,6 +4,6 @@ declare type relVarsValsT = Record<string, string | number>;
4
4
  declare type getRelatedVarsT = (optionId: number, index: number, variables: number[], ovc: OVC_TYPE, references: Types.ReferencesType) => relVarsValsT;
5
5
  export declare const getRelatedVariablesValues: getRelatedVarsT;
6
6
  declare type autonumsType = [string, string, number, string | null][];
7
- declare type parseOutputT = (output: string, variables: relVarsValsT, autonums: autonumsType) => string;
7
+ declare type parseOutputT = (output: string, index: number, variables: relVarsValsT, autonums: autonumsType) => string;
8
8
  export declare const parseOutputWithVariables: parseOutputT;
9
9
  export {};
@@ -28,7 +28,7 @@ exports.getRelatedVariablesValues = function (optionId, index, variables, ovc, r
28
28
  });
29
29
  return variablesValues;
30
30
  };
31
- exports.parseOutputWithVariables = function (output, variables, autonums) {
31
+ exports.parseOutputWithVariables = function (output, index, variables, autonums) {
32
32
  var parsedOutput = "" + output;
33
33
  Object.keys(variables).forEach(function (variableId) {
34
34
  var value = variables[variableId].toString();
@@ -40,6 +40,7 @@ exports.parseOutputWithVariables = function (output, variables, autonums) {
40
40
  });
41
41
  parsedOutput = parsedOutput.replace(/\[\[PAGE_BREAK\]\]/gi, '<div style="page-break-after:always"></div>');
42
42
  parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi, '');
43
+ parsedOutput = parsedOutput.replace(/\[signature:([0-9]+)\]/g, function (v, signatureId) { return "<span data-signature-id=\"" + signatureId + "\" data-signer-index=\"" + index + "\"></span>"; });
43
44
  autonums.forEach(function (currentAn) {
44
45
  if (currentAn[3] === null)
45
46
  parsedOutput = parsedOutput.replace("[" + currentAn[0] + ":" + currentAn[1] + "]", "<span class=\"" + currentAn[0] + "\">" + currentAn[2] + "</span>");
@@ -1,4 +1,5 @@
1
1
  import OVC_TYPE from './ovc.type';
2
+ import { Types } from '@legalplace/referencesparser';
2
3
  export interface OldOVC {
3
4
  o: {
4
5
  [k: string]: string | number | (string | number)[];
@@ -11,9 +12,10 @@ export interface OldOVC {
11
12
  };
12
13
  }
13
14
  declare class OvcConverter {
14
- convertToOptionsVariables(ovc: OldOVC): OVC_TYPE;
15
+ convertToOptionsVariables(ovc: OldOVC, references: Types.ReferencesType): OVC_TYPE;
15
16
  isOvc(_obj: OVC_TYPE | OldOVC): _obj is OldOVC;
16
17
  isOptionsVariables(_obj: OVC_TYPE | OldOVC): boolean;
18
+ private pushStaticChildren;
17
19
  }
18
20
  declare const _default: OvcConverter;
19
21
  export default _default;
@@ -1,9 +1,28 @@
1
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
+ };
2
20
  Object.defineProperty(exports, "__esModule", { value: true });
3
21
  var OvcConverter = (function () {
4
22
  function OvcConverter() {
5
23
  }
6
- OvcConverter.prototype.convertToOptionsVariables = function (ovc) {
24
+ OvcConverter.prototype.convertToOptionsVariables = function (ovc, references) {
25
+ var _this = this;
7
26
  var inputs = {
8
27
  options: {},
9
28
  variables: {}
@@ -15,37 +34,33 @@ var OvcConverter = (function () {
15
34
  var currentOption = ovc.o[id];
16
35
  if (Array.isArray(currentOption)) {
17
36
  var occurences_1 = currentOption.length;
37
+ inputs.options = __assign(__assign({}, inputs.options), _this.pushStaticChildren(inputs.options, id, occurences_1, references));
18
38
  currentOption.forEach(function (childId, index) {
19
- if (typeof childId === 'string' && childId.trim().length === 0) {
20
- if (!Object.prototype.hasOwnProperty.call(inputs.options, childId)) {
21
- inputs.options[id] = new Array(occurences_1).fill(false);
22
- }
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) {
23
47
  return;
24
48
  }
25
- if (!Object.prototype.hasOwnProperty.call(inputs.options, childId)) {
26
- inputs.options[childId] = new Array(occurences_1).fill(false);
49
+ if (!Object.prototype.hasOwnProperty.call(inputs.options, sanitizedId)) {
50
+ inputs.options[sanitizedId] = new Array(occurences_1).fill(false);
27
51
  }
28
- inputs.options[childId][index] = true;
52
+ inputs.options = __assign(__assign({}, inputs.options), _this.pushStaticChildren(inputs.options, sanitizedId, occurences_1, references));
53
+ inputs.options[sanitizedId][index] = true;
29
54
  });
30
55
  }
31
56
  else {
32
- if (typeof currentOption === 'string' && currentOption.trim().length === 0)
57
+ if (typeof currentOption === 'string' &&
58
+ currentOption.trim().length === 0)
33
59
  return;
34
60
  inputs.options[currentOption] = [true];
35
61
  }
36
62
  });
37
63
  }
38
- if (typeof ovc.v === 'object') {
39
- Object.keys(ovc.v).forEach(function (id) {
40
- var currentVariable = ovc.v[id];
41
- if (Array.isArray(currentVariable)) {
42
- inputs.variables[id] = currentVariable;
43
- }
44
- else {
45
- inputs.variables[id] = [currentVariable];
46
- }
47
- });
48
- }
49
64
  if (typeof ovc.c === 'object') {
50
65
  Object.keys(ovc.c).forEach(function (id) {
51
66
  var currentCheckbox = ovc.c[id];
@@ -59,6 +74,25 @@ var OvcConverter = (function () {
59
74
  }
60
75
  });
61
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
+ }
62
96
  return inputs;
63
97
  };
64
98
  OvcConverter.prototype.isOvc = function (_obj) {
@@ -79,6 +113,20 @@ var OvcConverter = (function () {
79
113
  .reduce(function (a, b) { return a + b; }, 0);
80
114
  return foundKeys === 2;
81
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
+ };
82
130
  return OvcConverter;
83
131
  }());
84
132
  exports.default = new OvcConverter();
@@ -16,9 +16,11 @@ var Prerender = (function () {
16
16
  this.documentsIndex = {};
17
17
  this.renderedDocuments = {};
18
18
  this.model = model;
19
- this.ovc = OvcConverter_1.default.isOvc(ovc) ? OvcConverter_1.default.convertToOptionsVariables(ovc) : ovc;
20
19
  this.NumAuto = new NumAuto_1.default();
21
20
  this.references = new referencesparser_1.ReferencesParser(model).getReferences();
21
+ this.ovc = OvcConverter_1.default.isOvc(ovc)
22
+ ? OvcConverter_1.default.convertToOptionsVariables(ovc, this.references)
23
+ : ovc;
22
24
  var inputs = new InputsInitiator_1.default(this.references, this.ovc).getInputs();
23
25
  this.conditions = new ConditionsRunner_1.default(this.references, inputs);
24
26
  this.documentRender = new DocumentRender_1.default(this.references, this.conditions, inputs, this.NumAuto);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/prerenderx",
3
- "version": "2.3.54",
3
+ "version": "2.4.0",
4
4
  "description": "PrerenderX",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/prerenderx",
@@ -56,7 +56,7 @@ class OptionRender {
56
56
 
57
57
  // variables
58
58
  const variables = getRelatedVariablesValues(this.id, this.index, outputReference.variables, this.ovc, this.references)
59
- let output = parseOutputWithVariables(option.meta.output, variables, autonums)
59
+ let output = parseOutputWithVariables(option.meta.output, this.index, variables, autonums)
60
60
 
61
61
  // Removing spaces between tags
62
62
  output = output.replace(/>([\n\s]+)</g, '><');
@@ -55,8 +55,8 @@ export const getRelatedVariablesValues: getRelatedVarsT = (optionId, index, vari
55
55
  * @param autonums Autonums values
56
56
  */
57
57
  type autonumsType = [string, string, number, string | null][]
58
- type parseOutputT = (output: string, variables: relVarsValsT, autonums: autonumsType) => string
59
- export const parseOutputWithVariables: parseOutputT = (output, variables, autonums) => {
58
+ type parseOutputT = (output: string, index: number, variables: relVarsValsT, autonums: autonumsType) => string
59
+ export const parseOutputWithVariables: parseOutputT = (output, index, variables, autonums) => {
60
60
  // Inserting values
61
61
  let parsedOutput = `${output}`
62
62
  Object.keys(variables).forEach(variableId => {
@@ -76,6 +76,9 @@ export const parseOutputWithVariables: parseOutputT = (output, variables, autonu
76
76
  // Cleaning BLURS
77
77
  parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi, '')
78
78
 
79
+ // Parsing Signatures
80
+ parsedOutput = parsedOutput.replace(/\[signature:([0-9]+)\]/g, (v, signatureId) => `<span data-signature-id="${signatureId}" data-signer-index="${index}"></span>`)
81
+
79
82
  // Inserting autonums
80
83
  autonums.forEach(currentAn => {
81
84
  if (currentAn[3] === null) parsedOutput = parsedOutput.replace(`[${currentAn[0]}:${currentAn[1]}]`, `<span class="${currentAn[0]}">${currentAn[2]}</span>`)
@@ -1,4 +1,5 @@
1
1
  import OVC_TYPE from './ovc.type'
2
+ import { Types } from '@legalplace/referencesparser'
2
3
 
3
4
  export interface OldOVC {
4
5
  o: {
@@ -13,75 +14,128 @@ export interface OldOVC {
13
14
  }
14
15
 
15
16
  class OvcConverter {
16
- public convertToOptionsVariables(ovc: OldOVC) {
17
+ public convertToOptionsVariables(
18
+ ovc: OldOVC,
19
+ references: Types.ReferencesType
20
+ ) {
17
21
  const inputs: OVC_TYPE = {
18
22
  options: {},
19
23
  variables: {}
20
24
  }
21
25
 
22
- if (typeof ovc !== 'object') return inputs
26
+ if (typeof ovc !== 'object') return inputs;
23
27
 
24
28
  // Reading options
25
29
  if (typeof ovc.o === 'object') {
26
30
  Object.keys(ovc.o).forEach(id => {
27
- const currentOption = ovc.o[id]
31
+ const currentOption = ovc.o[id];
28
32
 
29
33
  // If it's a multiple
30
34
  if (Array.isArray(currentOption)) {
31
- const occurences = currentOption.length
35
+ const occurences = currentOption.length;
36
+ // Adding static childrens
37
+ inputs.options = {
38
+ ...inputs.options,
39
+ ...this.pushStaticChildren(
40
+ inputs.options,
41
+ id,
42
+ occurences,
43
+ references
44
+ )
45
+ };
32
46
  currentOption.forEach((childId, index) => {
33
- if (typeof childId === 'string' && childId.trim().length === 0) {
34
- // Creating input if it doesn't exist
35
- if (!Object.prototype.hasOwnProperty.call(inputs.options, childId)) {
36
- inputs.options[id] = new Array(occurences).fill(false)
37
- }
38
- return
47
+ const sanitizedId =
48
+ typeof childId === 'string' && childId.split('_').length > 0
49
+ ? childId.split('_')[0]
50
+ : childId;
51
+
52
+ // Making sure the input exist
53
+ if (!Object.prototype.hasOwnProperty.call(inputs.options, id)) {
54
+ inputs.options[id] = new Array(occurences).fill(false);
55
+ }
56
+
57
+ // Making sure the childId is not empty
58
+ if (
59
+ typeof sanitizedId === 'string' &&
60
+ sanitizedId.trim().length === 0
61
+ ) {
62
+ return;
39
63
  }
40
64
 
41
65
  // Creating input if it doesn't exist
42
- if (!Object.prototype.hasOwnProperty.call(inputs.options, childId)) {
43
- inputs.options[childId] = new Array(occurences).fill(false)
66
+ if (
67
+ !Object.prototype.hasOwnProperty.call(inputs.options, sanitizedId)
68
+ ) {
69
+ inputs.options[sanitizedId] = new Array(occurences).fill(false);
44
70
  }
45
71
 
72
+ // Adding static childrens
73
+ inputs.options = {
74
+ ...inputs.options,
75
+ ...this.pushStaticChildren(
76
+ inputs.options,
77
+ sanitizedId,
78
+ occurences,
79
+ references
80
+ )
81
+ };
82
+
46
83
  // Setting current index to true
47
- inputs.options[childId][index] = true
48
- })
84
+ inputs.options[sanitizedId][index] = true;
85
+ });
49
86
  } else {
50
- if (typeof currentOption === 'string' && currentOption.trim().length === 0) return
51
- inputs.options[currentOption] = [true]
87
+ if (
88
+ typeof currentOption === 'string' &&
89
+ currentOption.trim().length === 0
90
+ )
91
+ return;
92
+ inputs.options[currentOption] = [true];
52
93
  }
53
- })
94
+ });
54
95
  }
55
96
 
56
- // Reading variables
57
- if (typeof ovc.v === 'object') {
58
- Object.keys(ovc.v).forEach(id => {
59
- const currentVariable = ovc.v[id]
60
-
97
+ // Reading checkboxes
98
+ if (typeof ovc.c === 'object') {
99
+ Object.keys(ovc.c).forEach(id => {
100
+ const currentCheckbox = ovc.c[id];
101
+ if (typeof id === 'string' && id.trim().length === 0) return;
61
102
  // If it's a multiple
62
- if (Array.isArray(currentVariable)) {
63
- inputs.variables[id] = currentVariable
103
+ if (Array.isArray(currentCheckbox)) {
104
+ inputs.options[id] = currentCheckbox;
64
105
  } else {
65
- inputs.variables[id] = [currentVariable]
106
+ inputs.options[id] = [currentCheckbox];
66
107
  }
67
- })
108
+ });
68
109
  }
69
110
 
70
- // Reading checkboxes
71
- if (typeof ovc.c === 'object') {
72
- Object.keys(ovc.c).forEach(id => {
73
- const currentCheckbox = ovc.c[id]
74
- if (typeof id === 'string' && id.trim().length === 0) return
111
+ // Reading variables
112
+ if (typeof ovc.v === 'object') {
113
+ Object.keys(ovc.v).forEach(id => {
114
+ const currentVariable = ovc.v[id];
115
+
75
116
  // If it's a multiple
76
- if (Array.isArray(currentCheckbox)) {
77
- inputs.options[id] = currentCheckbox
117
+ if (Array.isArray(currentVariable)) {
118
+ inputs.variables[id] = currentVariable;
119
+ // Getting parentsTree & parent id
120
+ const parentsTree = references.relations.variables[id].parents;
121
+ const parentOption =
122
+ inputs.options[`${parentsTree[parentsTree.length - 1]}`];
123
+ if (Array.isArray(parentOption)) {
124
+ const occurences = parentOption.length;
125
+ if (currentVariable.length < occurences) {
126
+ inputs.variables[id] = [
127
+ ...currentVariable,
128
+ ...Array(occurences - currentVariable.length).fill('')
129
+ ];
130
+ }
131
+ }
78
132
  } else {
79
- inputs.options[id] = [currentCheckbox]
133
+ inputs.variables[id] = [currentVariable];
80
134
  }
81
- })
135
+ });
82
136
  }
83
137
 
84
- return inputs
138
+ return inputs;
85
139
  }
86
140
 
87
141
  public isOvc(_obj: OVC_TYPE | OldOVC): _obj is OldOVC {
@@ -101,6 +155,33 @@ class OvcConverter {
101
155
  .reduce((a, b) => a + b, 0)
102
156
  return foundKeys === 2
103
157
  }
158
+
159
+ private pushStaticChildren(
160
+ inputOptions: OVC_TYPE['options'],
161
+ id: number | string,
162
+ occurences: number,
163
+ references: Types.ReferencesType
164
+ ) {
165
+ const result = { ...inputOptions };
166
+ const intId = typeof id === 'number' ? id : parseInt(id, 10);
167
+
168
+ // Getting children options and variables
169
+ const { options } = references.relations.options[intId].children;
170
+
171
+ // Getting static children
172
+ const staticOptions = options.filter(childId => {
173
+ return references.options[childId].meta.type === 'static';
174
+ });
175
+
176
+ staticOptions.forEach(childId => {
177
+ // Creating input if it doesn't exist
178
+ if (!Object.prototype.hasOwnProperty.call(result, childId)) {
179
+ result[childId] = new Array(occurences).fill(false);
180
+ }
181
+ });
182
+
183
+ return result;
184
+ }
104
185
  }
105
186
 
106
187
  export default new OvcConverter()
@@ -56,15 +56,17 @@ class Prerender {
56
56
  constructor(model: ModelV3, ovc: OVC_TYPE | OldOVC) {
57
57
  this.model = model
58
58
 
59
- // Converting OVC if needed
60
- this.ovc = OvcConverter.isOvc(ovc) ? OvcConverter.convertToOptionsVariables(ovc) : ovc
61
-
62
59
  // Initiating num auto
63
60
  this.NumAuto = new NumAuto()
64
61
 
65
62
  // Parsing references
66
63
  this.references = new ReferencesParser(model).getReferences()
67
64
 
65
+ // Converting OVC if needed
66
+ this.ovc = OvcConverter.isOvc(ovc)
67
+ ? OvcConverter.convertToOptionsVariables(ovc, this.references)
68
+ : ovc
69
+
68
70
  // Initiating inputs
69
71
  const inputs = new IntputsInitiator(this.references, this.ovc).getInputs()
70
72