@builttocreate/engine-utils 2.10.0 → 2.10.1-beta.1286

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # engine-utils
2
-
3
- Node: v18
4
- Package Manager: NPM
5
-
6
- Utility library for common logic shared across web and mobile
1
+ # engine-utils
2
+
3
+ Node: v18
4
+ Package Manager: NPM
5
+
6
+ Utility library for common logic shared across web and mobile
@@ -57,9 +57,9 @@ var getFormattedActivity = exports.getFormattedActivity = function getFormattedA
57
57
  return activity;
58
58
  };
59
59
 
60
- /**
61
- *
62
- * Template should be a template that is using the new getTemplateWithLookups
60
+ /**
61
+ *
62
+ * Template should be a template that is using the new getTemplateWithLookups
63
63
  */
64
64
  var addDocumentDataToActivities = exports.addDocumentDataToActivities = function addDocumentDataToActivities(activities, doc, template) {
65
65
  var templateFieldLookup = {};
@@ -83,38 +83,38 @@ var addDocumentDataToActivities = exports.addDocumentDataToActivities = function
83
83
  nextActivity.document.type = templateField.type;
84
84
  nextActivity.document.columns = templateField.tableColumns;
85
85
  if (docFieldValue && templateField.type === _FieldTypes["default"].table) {
86
- /**
87
- * Table Step 1: create an easy way to lookup a row with the dropdown cells populated.
88
- *
89
- * We only need to generate the row lookup once per field to help increase performance,
90
- * just incase we have other deficiencies that reference the same table field.
86
+ /**
87
+ * Table Step 1: create an easy way to lookup a row with the dropdown cells populated.
88
+ *
89
+ * We only need to generate the row lookup once per field to help increase performance,
90
+ * just incase we have other deficiencies that reference the same table field.
91
91
  */
92
92
 
93
- /**
94
- * Removing deleted rows from doc field value
95
- * Added as a fix for table bug that did not display proper output for formula cells
96
- * as rowIndex was messy
93
+ /**
94
+ * Removing deleted rows from doc field value
95
+ * Added as a fix for table bug that did not display proper output for formula cells
96
+ * as rowIndex was messy
97
97
  */
98
98
  var nextDocFieldValue = (0, _tableHelper.getRows)(docFieldValue);
99
99
  if (!fieldRowsLookup[templateField._id]) {
100
100
  fieldRowsLookup[templateField._id] = (0, _tableHelper.getTableRowLookupWithPopulatedDropdownCells)(templateField.tableColumns, nextDocFieldValue);
101
101
  }
102
102
 
103
- /**
104
- * Table Step 2: create an easy way to lookup a row index so we can use it in our row
105
- * display component.
106
- *
107
- * We only need to generate the row index lookup once per field to help increase performance,
108
- * just incase we have other deficiencies that reference the same table field.
103
+ /**
104
+ * Table Step 2: create an easy way to lookup a row index so we can use it in our row
105
+ * display component.
106
+ *
107
+ * We only need to generate the row index lookup once per field to help increase performance,
108
+ * just incase we have other deficiencies that reference the same table field.
109
109
  */
110
110
  if (!fieldRowIndexLookup[templateField._id]) {
111
111
  fieldRowIndexLookup[templateField._id] = (0, _tableHelper.getRowIndexLookup)(templateField._id, fieldSettings, docFieldValue);
112
112
  }
113
113
 
114
- /**
115
- * Table Step 3: Add row and rowIndex to the activity.document object for easy reference.
116
- *
117
- * nextActivity.document.value will now contain the single row object with all cell values populated ready to be displayed
114
+ /**
115
+ * Table Step 3: Add row and rowIndex to the activity.document object for easy reference.
116
+ *
117
+ * nextActivity.document.value will now contain the single row object with all cell values populated ready to be displayed
118
118
  */
119
119
 
120
120
  if (fieldRowsLookup[activity.document.field] && fieldRowIndexLookup[activity.document.field]) {
@@ -122,17 +122,17 @@ var addDocumentDataToActivities = exports.addDocumentDataToActivities = function
122
122
  nextActivity.document.rowIndex = fieldRowIndexLookup[activity.document.field][activity.document.row];
123
123
  }
124
124
  } else if (docFieldValue && templateField.type === _FieldTypes["default"].inputGroup) {
125
- /**
126
- * Input Group Step 1: create an easy way to lookup a row with the dropdown cells populated.
127
- *
128
- * We only need to generate the row lookup once per field (since input groups are just rows)
129
- * to help increase performance, just incase we have other deficiencies that reference the same table field.
125
+ /**
126
+ * Input Group Step 1: create an easy way to lookup a row with the dropdown cells populated.
127
+ *
128
+ * We only need to generate the row lookup once per field (since input groups are just rows)
129
+ * to help increase performance, just incase we have other deficiencies that reference the same table field.
130
130
  */
131
131
  if (!fieldRowsLookup[templateField._id]) fieldRowsLookup[templateField._id] = (0, _tableHelper.getInputGroupRowLookupWithPopulatedDropdownCells)(templateField.tableColumns, docFieldValue);
132
132
 
133
- /**
134
- * Input Group Step 2: Add invidual row.cell value. We only add the invidual cell value and not the
135
- * whole row because input group display components are treated like regular field and not like table rows.
133
+ /**
134
+ * Input Group Step 2: Add invidual row.cell value. We only add the invidual cell value and not the
135
+ * whole row because input group display components are treated like regular field and not like table rows.
136
136
  */
137
137
 
138
138
  if (fieldRowsLookup[activity.document.field] && fieldRowsLookup[activity.document.field][activity.document.row] && fieldRowsLookup[activity.document.field][activity.document.row].cells[activity.document.column]) {
@@ -4,16 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- /**
8
- * See what keys have changed between two objects.
9
- *
10
- * Used primarily right now to compare what props have changed for
11
- * a react component.
12
- *
13
- * @param {Object} o1
14
- * @param {Object} o2
15
- *
16
- * @returns {Array}
7
+ /**
8
+ * See what keys have changed between two objects.
9
+ *
10
+ * Used primarily right now to compare what props have changed for
11
+ * a react component.
12
+ *
13
+ * @param {Object} o1
14
+ * @param {Object} o2
15
+ *
16
+ * @returns {Array}
17
17
  */
18
18
  var changedKeys = function changedKeys() {
19
19
  var o1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -7,11 +7,11 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.getDefaultLinePoint = exports.getDefaultLine = exports["default"] = void 0;
8
8
  var _generateObjectId = _interopRequireDefault(require("./generateObjectId"));
9
9
  var getDefaultLine = exports.getDefaultLine = function getDefaultLine() {
10
- /**
11
- * Why do we add more than 1 points by default to the new line?
12
- *
13
- * There is bug with victory-native that will throw an error if
14
- * there aren't two data points in the array.
10
+ /**
11
+ * Why do we add more than 1 points by default to the new line?
12
+ *
13
+ * There is bug with victory-native that will throw an error if
14
+ * there aren't two data points in the array.
15
15
  */
16
16
  return {
17
17
  _id: (0, _generateObjectId["default"])(),
@@ -4,20 +4,20 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- /**
8
- * Are we displaying the entire original field
9
- *
10
- * For instance, if displayType is original for a table field then we are
11
- * displaying the entire component. If it is text,
12
- * circle, square, etc. then that means we are
13
- * only displaying an invidiual mapped cell from
14
- * the table or input group. Same is true for dropdown and multi-select fields.
7
+ /**
8
+ * Are we displaying the entire original field
9
+ *
10
+ * For instance, if displayType is original for a table field then we are
11
+ * displaying the entire component. If it is text,
12
+ * circle, square, etc. then that means we are
13
+ * only displaying an invidiual mapped cell from
14
+ * the table or input group. Same is true for dropdown and multi-select fields.
15
15
  */
16
16
  var original = 'original';
17
17
 
18
- /**
19
- * Meant to be used as original display type but horizontal.
20
- * Primarily used for multi-select field right now.
18
+ /**
19
+ * Meant to be used as original display type but horizontal.
20
+ * Primarily used for multi-select field right now.
21
21
  */
22
22
  var horizontal = 'horizontal';
23
23
 
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.transparent = exports.normal = exports["default"] = void 0;
7
- /**
8
- * Page field style modes
9
- *
10
- * Used to to determine how a field
11
- * should be presented on the form.
7
+ /**
8
+ * Page field style modes
9
+ *
10
+ * Used to to determine how a field
11
+ * should be presented on the form.
12
12
  */
13
13
  var normal = exports.normal = 'normal';
14
14
  var transparent = exports.transparent = 'transparent';
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- /**
8
- * Page layout modes
7
+ /**
8
+ * Page layout modes
9
9
  */
10
10
  var grid = 'grid';
11
11
  var _float = 'float';
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- /**
8
- * Page Types
7
+ /**
8
+ * Page Types
9
9
  */
10
10
  var PageTypes = {
11
11
  desktop: 'desktop',
@@ -4,13 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- /**
8
- * Role Types:
9
- *
10
- * admin - They can do everything
11
- * contributor - They can do everything, except modify users or templates
12
- * readyOnly - They can see all but can't do anything.
13
- * restricted - They can only see the stuff they authored. They don't have access to any other users stuff.
7
+ /**
8
+ * Role Types:
9
+ *
10
+ * admin - They can do everything
11
+ * contributor - They can do everything, except modify users or templates
12
+ * readyOnly - They can see all but can't do anything.
13
+ * restricted - They can only see the stuff they authored. They don't have access to any other users stuff.
14
14
  */
15
15
  var roles = {
16
16
  admin: {
@@ -14,10 +14,10 @@ var _generateObjectId = _interopRequireDefault(require("./generateObjectId"));
14
14
  var _FieldTypes = _interopRequireDefault(require("./constants/FieldTypes"));
15
15
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
16
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
- /**
18
- * Get chart field line data
19
- *
20
- * @param (String|Object) value
17
+ /**
18
+ * Get chart field line data
19
+ *
20
+ * @param (String|Object) value
21
21
  */
22
22
  var getChartFieldValue = exports.getChartFieldValue = function getChartFieldValue(value) {
23
23
  var parsedData = value || [];
@@ -32,13 +32,13 @@ var getChartFieldValue = exports.getChartFieldValue = function getChartFieldValu
32
32
  return (0, _toConsumableArray2["default"])(parsedData);
33
33
  };
34
34
 
35
- /**
36
- * Get default option
37
- *
38
- * These options are primarily used by dropdown and selection fields
39
- *
40
- * @param {String} value
41
- * @return {Object}
35
+ /**
36
+ * Get default option
37
+ *
38
+ * These options are primarily used by dropdown and selection fields
39
+ *
40
+ * @param {String} value
41
+ * @return {Object}
42
42
  */
43
43
  var getDefaultOption = exports.getDefaultOption = function getDefaultOption(value) {
44
44
  return {
@@ -48,11 +48,11 @@ var getDefaultOption = exports.getDefaultOption = function getDefaultOption(valu
48
48
  };
49
49
  };
50
50
 
51
- /**
52
- * Get multiselect field value
53
- *
54
- * @param (String|Array) value
55
- * @return Array
51
+ /**
52
+ * Get multiselect field value
53
+ *
54
+ * @param (String|Array) value
55
+ * @return Array
56
56
  */
57
57
  var getMultiSelectFieldValue = exports.getMultiSelectFieldValue = function getMultiSelectFieldValue(value) {
58
58
  if (value && typeof value === 'string') {
@@ -64,12 +64,12 @@ var getMultiSelectFieldValue = exports.getMultiSelectFieldValue = function getMu
64
64
  }
65
65
  };
66
66
 
67
- /**
68
- * Update the selected options.
69
- *
70
- * @param (Bool) multi
71
- * @param (Array) selectedOptions //[optionId, optionId, ...]
72
- * @param (String) optionId //Option that is being toggled
67
+ /**
68
+ * Update the selected options.
69
+ *
70
+ * @param (Bool) multi
71
+ * @param (Array) selectedOptions //[optionId, optionId, ...]
72
+ * @param (String) optionId //Option that is being toggled
73
73
  */
74
74
  var handleMultiSelectOptionToggle = exports.handleMultiSelectOptionToggle = function handleMultiSelectOptionToggle(multi) {
75
75
  var selectedOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
@@ -93,11 +93,11 @@ var handleMultiSelectOptionToggle = exports.handleMultiSelectOptionToggle = func
93
93
  return nextSelection;
94
94
  };
95
95
 
96
- /**
97
- * Get default field values from template
98
- *
99
- * @param {Object} template
100
- * @param {String} defaultUserId
96
+ /**
97
+ * Get default field values from template
98
+ *
99
+ * @param {Object} template
100
+ * @param {String} defaultUserId
101
101
  */
102
102
  var getDefaultFieldValuesFromTemplate = exports.getDefaultFieldValuesFromTemplate = function getDefaultFieldValuesFromTemplate(template, defaultUserId) {
103
103
  var fields = {};
@@ -134,12 +134,12 @@ var getDefaultFieldValuesFromTemplate = exports.getDefaultFieldValuesFromTemplat
134
134
  return fields;
135
135
  };
136
136
 
137
- /**
138
- * Get import field values from source document for target document
139
- *
140
- * @param {Object} template
141
- * @param {Object} importSource //Document source you're importing
142
- * @param {Object} importTarget //Document that is having it's fields overwritten by import source
137
+ /**
138
+ * Get import field values from source document for target document
139
+ *
140
+ * @param {Object} template
141
+ * @param {Object} importSource //Document source you're importing
142
+ * @param {Object} importTarget //Document that is having it's fields overwritten by import source
143
143
  */
144
144
  var getImportFieldValues = exports.getImportFieldValues = function getImportFieldValues(template, importSource, importTarget) {
145
145
  var fields = {};
@@ -160,20 +160,20 @@ var getImportFieldValues = exports.getImportFieldValues = function getImportFiel
160
160
  cells: {}
161
161
  });
162
162
  field.tableColumns.forEach(function (column) {
163
- /**
164
- * Option 1: Add cell value from source document
163
+ /**
164
+ * Option 1: Add cell value from source document
165
165
  */
166
166
  if (!column.blockImport) {
167
167
  newRow.cells[column._id] = row.cells[column._id] || '';
168
168
  }
169
- /**
170
- * Option 2: If column has block import enabled then maintain any values
171
- * already set in the importTarget document.
169
+ /**
170
+ * Option 2: If column has block import enabled then maintain any values
171
+ * already set in the importTarget document.
172
172
  */else if (column.blockImport && currentDocRows[i] && currentDocRows[i].cells[column._id]) {
173
173
  newRow.cells[column._id] = currentDocRows[i].cells[column._id];
174
174
  }
175
- /**
176
- * Option 3: If column has block import enabled then add default column value
175
+ /**
176
+ * Option 3: If column has block import enabled then add default column value
177
177
  */else if (column.blockImport && column.value) {
178
178
  newRow.cells[column._id] = column.value;
179
179
  }
@@ -192,12 +192,12 @@ var getImportFieldValues = exports.getImportFieldValues = function getImportFiel
192
192
  return fields;
193
193
  };
194
194
 
195
- /**
196
- * Generate optionsLookup and fieldLookup for template fields
197
- * Note: Options lookup will be used by dropdown, mutliSelect, table and inputGroup fields
198
- * to display value in dropdowns
199
- * @param {} template
200
- * @returns template
195
+ /**
196
+ * Generate optionsLookup and fieldLookup for template fields
197
+ * Note: Options lookup will be used by dropdown, mutliSelect, table and inputGroup fields
198
+ * to display value in dropdowns
199
+ * @param {} template
200
+ * @returns template
201
201
  */
202
202
 
203
203
  var getTemplateWithLookups = exports.getTemplateWithLookups = function getTemplateWithLookups(template) {
@@ -232,11 +232,11 @@ var getTemplateWithLookups = exports.getTemplateWithLookups = function getTempla
232
232
  return nextTemplate;
233
233
  };
234
234
 
235
- /**
236
- * This method checks if the field passed via input is empty by checking
237
- * the field.value.
238
- * @param {*} fieldProps
239
- * @returns
235
+ /**
236
+ * This method checks if the field passed via input is empty by checking
237
+ * the field.value.
238
+ * @param {*} fieldProps
239
+ * @returns
240
240
  */
241
241
 
242
242
  var isFieldEmpty = exports.isFieldEmpty = function isFieldEmpty(fieldType, fieldValue, fieldOptions) {
@@ -273,18 +273,18 @@ var isFieldEmpty = exports.isFieldEmpty = function isFieldEmpty(fieldType, field
273
273
  return isEmpty;
274
274
  };
275
275
 
276
- /**
277
- * This function checks whether an option associated with multiselect or dropdown
278
- * field is deleted.
279
- * @param {*} value // value
280
- * @param {*} options
276
+ /**
277
+ * This function checks whether an option associated with multiselect or dropdown
278
+ * field is deleted.
279
+ * @param {*} value // value
280
+ * @param {*} options
281
281
  */
282
282
  var isTargetOptionDeleted = exports.isTargetOptionDeleted = function isTargetOptionDeleted(value, options) {
283
- /***
284
- * We are converting the value that is passed in to array since
285
- * this method is used by dropdown field and multiSelect field
286
- * Dropdown passes the value as a string whereas mutliselect passes
287
- * the value as an array
283
+ /***
284
+ * We are converting the value that is passed in to array since
285
+ * this method is used by dropdown field and multiSelect field
286
+ * Dropdown passes the value as a string whereas mutliselect passes
287
+ * the value as an array
288
288
  */
289
289
  var nextValue = Array.isArray(value) ? value : [value];
290
290
  if (!nextValue || nextValue.length === 0) return true;
package/dist/index.js CHANGED
@@ -66,7 +66,8 @@ var _changedKeys = _interopRequireDefault(require("./changedKeys"));
66
66
  var _Roles = _interopRequireDefault(require("./constants/Roles"));
67
67
  var _generateObjectId = _interopRequireDefault(require("./generateObjectId"));
68
68
  var _validateObjectId = _interopRequireDefault(require("./validateObjectId"));
69
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
69
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
70
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) { if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } } return n["default"] = e, t && t.set(e, n), n; }
70
71
  var _default = exports["default"] = {
71
72
  fileHelper: fileHelper,
72
73
  tableHelper: tableHelper,