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

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.
@@ -20,11 +20,11 @@ var _FormStyleOptions = _interopRequireDefault(require("./constants/FormStyleOpt
20
20
  var _tableHelper = require("./tableHelper");
21
21
  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; }
22
22
  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; }
23
- /**
24
- * Create default page
25
- *
26
- * @param {Object} defaults
27
- * @return {Object}
23
+ /**
24
+ * Create default page
25
+ *
26
+ * @param {Object} defaults
27
+ * @return {Object}
28
28
  */
29
29
  var getDefaultJoyDocPage = exports.getDefaultJoyDocPage = function getDefaultJoyDocPage() {
30
30
  var defaults = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -42,12 +42,12 @@ var getDefaultJoyDocPage = exports.getDefaultJoyDocPage = function getDefaultJoy
42
42
  }, defaults);
43
43
  };
44
44
 
45
- /**
46
- * Create default file
47
- *
48
- * @param {Object} defaults
49
- * @param {Object} pageDefaults
50
- * @return {Object}
45
+ /**
46
+ * Create default file
47
+ *
48
+ * @param {Object} defaults
49
+ * @param {Object} pageDefaults
50
+ * @return {Object}
51
51
  */
52
52
  var getDefaultJoyDocFile = exports.getDefaultJoyDocFile = function getDefaultJoyDocFile() {
53
53
  var defaults = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -64,12 +64,12 @@ var getDefaultJoyDocFile = exports.getDefaultJoyDocFile = function getDefaultJoy
64
64
  }, defaults);
65
65
  };
66
66
 
67
- /**
68
- * Create default document
69
- *
70
- * @param {Object} defaults
71
- * @param {Object} pageDefaults
72
- * @return {Object}
67
+ /**
68
+ * Create default document
69
+ *
70
+ * @param {Object} defaults
71
+ * @param {Object} pageDefaults
72
+ * @return {Object}
73
73
  */
74
74
  var getDefaultJoyDoc = exports.getDefaultJoyDoc = function getDefaultJoyDoc() {
75
75
  var defaults = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -85,27 +85,27 @@ var getDefaultJoyDoc = exports.getDefaultJoyDoc = function getDefaultJoyDoc() {
85
85
  }, defaults);
86
86
  };
87
87
 
88
- /**
89
- * Get Clean JoyDoc Format
90
- *
91
- * Solves Issue: https://app.zenhub.com/workspaces/joyfill-platform-5f07262b507391001f56c7f9/issues/gh/zionlabs/issues/2105
92
- *
93
- * This selector ensures a couple of things:
94
- * 1. Valid file inside the document.
95
- * 2. Valid page inside document file.
96
- * 3. All _id's (page, file, page, fieldPosition, field) are in a valid format
97
- * 4. Row order of table field is free from duplicate/deletedRow Ids
98
- *
99
- * @param {Object} doc
100
- * @returns {Object}
88
+ /**
89
+ * Get Clean JoyDoc Format
90
+ *
91
+ * Solves Issue: https://app.zenhub.com/workspaces/joyfill-platform-5f07262b507391001f56c7f9/issues/gh/zionlabs/issues/2105
92
+ *
93
+ * This selector ensures a couple of things:
94
+ * 1. Valid file inside the document.
95
+ * 2. Valid page inside document file.
96
+ * 3. All _id's (page, file, page, fieldPosition, field) are in a valid format
97
+ * 4. Row order of table field is free from duplicate/deletedRow Ids
98
+ *
99
+ * @param {Object} doc
100
+ * @returns {Object}
101
101
  */
102
102
  var getCleanedJoyDoc = exports.getCleanedJoyDoc = function getCleanedJoyDoc(doc) {
103
103
  if (!doc) return getDefaultJoyDoc();
104
104
  var _removeOrphanedFields = removeOrphanedFieldsFromJoydoc(doc),
105
105
  nextDoc = _removeOrphanedFields.nextDoc;
106
106
 
107
- /**
108
- * Step 1.1: Replace doc._id if it is not valid
107
+ /**
108
+ * Step 1.1: Replace doc._id if it is not valid
109
109
  */
110
110
  if (nextDoc._id && !(0, _validateObjectId["default"])(nextDoc._id)) nextDoc._id = (0, _generateObjectId["default"])();
111
111
  if (nextDoc.files && nextDoc.files.length > 0) {
@@ -113,21 +113,21 @@ var getCleanedJoyDoc = exports.getCleanedJoyDoc = function getCleanedJoyDoc(doc)
113
113
  var _nextFile$views;
114
114
  var nextFile = _objectSpread({}, file);
115
115
 
116
- /**
117
- * Step 1.2: Replace files[x]._id if it is not valid
116
+ /**
117
+ * Step 1.2: Replace files[x]._id if it is not valid
118
118
  */
119
119
  if (nextFile._id && !(0, _validateObjectId["default"])(nextFile._id)) nextFile._id = (0, _generateObjectId["default"])();
120
120
 
121
- /**
122
- * Step 1.3: Replace page ids and field ids if they are not valid
121
+ /**
122
+ * Step 1.3: Replace page ids and field ids if they are not valid
123
123
  */
124
124
  nextFile.pages = getCleanedJoyDocPages(nextFile.pages);
125
125
  nextFile.pageOrder = cleanPageOrder(getPageOrder(nextFile.pageOrder, nextFile.pages), nextFile.pages);
126
126
 
127
- /**
128
- * Step 1.4: Replace view page ids and field ids if they are not valid
127
+ /**
128
+ * Step 1.4: Replace view page ids and field ids if they are not valid
129
129
  */
130
- if ((nextFile === null || nextFile === void 0 ? void 0 : (_nextFile$views = nextFile.views) === null || _nextFile$views === void 0 ? void 0 : _nextFile$views.length) > 0) {
130
+ if ((nextFile === null || nextFile === void 0 || (_nextFile$views = nextFile.views) === null || _nextFile$views === void 0 ? void 0 : _nextFile$views.length) > 0) {
131
131
  nextFile.views = nextFile.views.map(function (view) {
132
132
  var nextView = _objectSpread({}, view);
133
133
  nextView.pages = getCleanedJoyDocPages(nextView.pages);
@@ -141,9 +141,9 @@ var getCleanedJoyDoc = exports.getCleanedJoyDoc = function getCleanedJoyDoc(doc)
141
141
  nextDoc.files = [getDefaultJoyDocFile()];
142
142
  }
143
143
 
144
- /**
145
- * Logic below is used to clean the table field rowOrder by removing the
146
- * deletedRowIds / duplicateRowIds from the rowOrder.
144
+ /**
145
+ * Logic below is used to clean the table field rowOrder by removing the
146
+ * deletedRowIds / duplicateRowIds from the rowOrder.
147
147
  **/
148
148
  if (nextDoc.fields && nextDoc.fields.length > 0) {
149
149
  nextDoc.fields = nextDoc.fields.map(function (field) {
@@ -158,8 +158,8 @@ var getCleanedJoyDoc = exports.getCleanedJoyDoc = function getCleanedJoyDoc(doc)
158
158
  return nextDoc;
159
159
  };
160
160
 
161
- /**
162
- * Remove orphaned fields from doc
161
+ /**
162
+ * Remove orphaned fields from doc
163
163
  */
164
164
 
165
165
  var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = function removeOrphanedFieldsFromJoydoc(doc) {
@@ -167,32 +167,32 @@ var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = fu
167
167
  if (!doc) return getDefaultJoyDoc();
168
168
  var nextDoc = _objectSpread({}, doc);
169
169
  var associatedFieldIdLookup = {};
170
- nextDoc === null || nextDoc === void 0 ? void 0 : (_nextDoc$files = nextDoc.files) === null || _nextDoc$files === void 0 ? void 0 : _nextDoc$files.forEach(function (file) {
170
+ nextDoc === null || nextDoc === void 0 || (_nextDoc$files = nextDoc.files) === null || _nextDoc$files === void 0 || _nextDoc$files.forEach(function (file) {
171
171
  var _file$views;
172
- /**
173
- * Primary view
172
+ /**
173
+ * Primary view
174
174
  */
175
175
  file.pages.forEach(function (page) {
176
- page === null || page === void 0 ? void 0 : page.fieldPositions.forEach(function (fieldPosition) {
176
+ page === null || page === void 0 || page.fieldPositions.forEach(function (fieldPosition) {
177
177
  return associatedFieldIdLookup[fieldPosition.field] = true;
178
178
  });
179
179
  });
180
180
 
181
- /**
182
- * Alternative view
181
+ /**
182
+ * Alternative view
183
183
  */
184
- (_file$views = file.views) === null || _file$views === void 0 ? void 0 : _file$views.forEach(function (view) {
184
+ (_file$views = file.views) === null || _file$views === void 0 || _file$views.forEach(function (view) {
185
185
  var _view$pages;
186
- view === null || view === void 0 ? void 0 : (_view$pages = view.pages) === null || _view$pages === void 0 ? void 0 : _view$pages.forEach(function (page) {
187
- page === null || page === void 0 ? void 0 : page.fieldPositions.forEach(function (fieldPosition) {
186
+ view === null || view === void 0 || (_view$pages = view.pages) === null || _view$pages === void 0 || _view$pages.forEach(function (page) {
187
+ page === null || page === void 0 || page.fieldPositions.forEach(function (fieldPosition) {
188
188
  return associatedFieldIdLookup[fieldPosition.field] = true;
189
189
  });
190
190
  });
191
191
  });
192
192
  });
193
193
 
194
- /**
195
- * Logic below removes orphaned fields (ie fields without fieldPositions)
194
+ /**
195
+ * Logic below removes orphaned fields (ie fields without fieldPositions)
196
196
  */
197
197
  var validFields = [];
198
198
  var deletedFields = [];
@@ -206,30 +206,30 @@ var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = fu
206
206
  };
207
207
  };
208
208
 
209
- /**
210
- * Get Cleaned JoyDoc Pages
211
- *
212
- * Solves Issue: https://app.zenhub.com/workspaces/joyfill-platform-5f07262b507391001f56c7f9/issues/gh/zionlabs/issues/2105
213
- *
214
- * This selector ensures a couple of things:
215
- * 1. Valid page inside document file.pages array.
216
- * 2. All id's in pages and fieldPositions are valid format
217
- *
218
- * @param {Object} doc
219
- * @returns {Object}
209
+ /**
210
+ * Get Cleaned JoyDoc Pages
211
+ *
212
+ * Solves Issue: https://app.zenhub.com/workspaces/joyfill-platform-5f07262b507391001f56c7f9/issues/gh/zionlabs/issues/2105
213
+ *
214
+ * This selector ensures a couple of things:
215
+ * 1. Valid page inside document file.pages array.
216
+ * 2. All id's in pages and fieldPositions are valid format
217
+ *
218
+ * @param {Object} doc
219
+ * @returns {Object}
220
220
  */
221
221
  var getCleanedJoyDocPages = exports.getCleanedJoyDocPages = function getCleanedJoyDocPages(pages) {
222
222
  if ((pages === null || pages === void 0 ? void 0 : pages.length) > 0) {
223
223
  return pages.map(function (page) {
224
- /**
225
- * Step 1: Replace pages[x]._id if it is not valid
224
+ /**
225
+ * Step 1: Replace pages[x]._id if it is not valid
226
226
  */
227
227
  var nextPage = _objectSpread({}, page);
228
228
  if (nextPage._id && !(0, _validateObjectId["default"])(nextPage._id)) nextPage._id = (0, _generateObjectId["default"])();
229
229
  if (nextPage.fieldPositions && nextPage.fieldPositions.length > 0) {
230
230
  nextPage.fieldPositions = nextPage.fieldPositions.map(function (fieldPosition) {
231
- /**
232
- * Step 1.2: Replace fieldPosition _id and field reference if they are not valid
231
+ /**
232
+ * Step 1.2: Replace fieldPosition _id and field reference if they are not valid
233
233
  */
234
234
  var nextFieldPosition = _objectSpread({}, fieldPosition);
235
235
  if (nextFieldPosition._id && !(0, _validateObjectId["default"])(nextFieldPosition._id)) nextFieldPosition._id = (0, _generateObjectId["default"])();
@@ -246,12 +246,12 @@ var getCleanedJoyDocPages = exports.getCleanedJoyDocPages = function getCleanedJ
246
246
  }
247
247
  };
248
248
 
249
- /**
250
- * Get page order
251
- *
252
- * @param {Array} pages
253
- * @param {Array} pageOrder
254
- * @return {Array}
249
+ /**
250
+ * Get page order
251
+ *
252
+ * @param {Array} pages
253
+ * @param {Array} pageOrder
254
+ * @return {Array}
255
255
  */
256
256
  var getPageOrder = exports.getPageOrder = function getPageOrder(pageOrder, pages) {
257
257
  return pageOrder || pages.map(function (page) {
@@ -259,17 +259,17 @@ var getPageOrder = exports.getPageOrder = function getPageOrder(pageOrder, pages
259
259
  });
260
260
  };
261
261
 
262
- /**
263
- *
264
- * Clean pageOrder
265
- *
266
- * 1. Remove any pageIds associated with a missing page.
267
- * 2. Remove any underfined or invalid pageIds
268
- * 3. Remove any duplicate pageIds
269
- *
270
- * @param {Array} pageOrder //[string, string, ...]
271
- * @param {Array} pages //[object, object, ...]
272
- * @returns {Array}
262
+ /**
263
+ *
264
+ * Clean pageOrder
265
+ *
266
+ * 1. Remove any pageIds associated with a missing page.
267
+ * 2. Remove any underfined or invalid pageIds
268
+ * 3. Remove any duplicate pageIds
269
+ *
270
+ * @param {Array} pageOrder //[string, string, ...]
271
+ * @param {Array} pages //[object, object, ...]
272
+ * @returns {Array}
273
273
  */
274
274
  var cleanPageOrder = exports.cleanPageOrder = function cleanPageOrder(pageOrder, pages) {
275
275
  var pageLookup = {};
@@ -281,8 +281,8 @@ var cleanPageOrder = exports.cleanPageOrder = function cleanPageOrder(pageOrder,
281
281
  });
282
282
  };
283
283
 
284
- /**
285
- * Sort pages based on pageOrder
284
+ /**
285
+ * Sort pages based on pageOrder
286
286
  */
287
287
  var sortPages = exports.sortPages = function sortPages(pages, pageOrder) {
288
288
  if (!pageOrder) return pages;
@@ -297,10 +297,10 @@ var sortPages = exports.sortPages = function sortPages(pages, pageOrder) {
297
297
  return sortedPages;
298
298
  };
299
299
 
300
- /**
301
- * Get a properly formatted Document JoyDoc
302
- *
303
- * @returns {Object}
300
+ /**
301
+ * Get a properly formatted Document JoyDoc
302
+ *
303
+ * @returns {Object}
304
304
  */
305
305
  var getDefaultDocument = exports.getDefaultDocument = function getDefaultDocument() {
306
306
  var type = _DocumentTypes["default"].document;
@@ -315,10 +315,10 @@ var getDefaultDocument = exports.getDefaultDocument = function getDefaultDocumen
315
315
  });
316
316
  };
317
317
 
318
- /**
319
- * Get a properly formatted Template JoyDoc
320
- *
321
- * @returns {Object}
318
+ /**
319
+ * Get a properly formatted Template JoyDoc
320
+ *
321
+ * @returns {Object}
322
322
  */
323
323
  var getDefaultTemplate = exports.getDefaultTemplate = function getDefaultTemplate() {
324
324
  var type = _DocumentTypes["default"].template;
@@ -333,10 +333,10 @@ var getDefaultTemplate = exports.getDefaultTemplate = function getDefaultTemplat
333
333
  });
334
334
  };
335
335
 
336
- /**
337
- * Get a properly formatted duplicate of a Template or Document
338
- *
339
- * @returns {Object}
336
+ /**
337
+ * Get a properly formatted duplicate of a Template or Document
338
+ *
339
+ * @returns {Object}
340
340
  */
341
341
  var duplicate = exports.duplicate = function duplicate(original, defaults) {
342
342
  //Remove all references to original template object
@@ -351,11 +351,11 @@ var duplicate = exports.duplicate = function duplicate(original, defaults) {
351
351
  }, defaults);
352
352
  };
353
353
 
354
- /**
355
- * Get a properly formatted Document JoyDoc from Template JoyDoc
356
- *
357
- * @param {Object} template
358
- * @returns {Object}
354
+ /**
355
+ * Get a properly formatted Document JoyDoc from Template JoyDoc
356
+ *
357
+ * @param {Object} template
358
+ * @returns {Object}
359
359
  */
360
360
  var getDocumentFromTemplate = exports.getDocumentFromTemplate = function getDocumentFromTemplate(template) {
361
361
  var _id = (0, _generateObjectId["default"])();
@@ -375,14 +375,14 @@ var getDocumentFromTemplate = exports.getDocumentFromTemplate = function getDocu
375
375
  };
376
376
  };
377
377
 
378
- /**
379
- * Handle Page Duplication for JoyDoc
380
- *
381
- * @param {Object} doc //Full JoyDoc Payload for Template or Document
382
- * @param {String} fileId //File ID that contains the page we are duplicating
383
- * @param {String} pageId
384
- * @param {Object} pageDefaults
385
- * @returns {Object}
378
+ /**
379
+ * Handle Page Duplication for JoyDoc
380
+ *
381
+ * @param {Object} doc //Full JoyDoc Payload for Template or Document
382
+ * @param {String} fileId //File ID that contains the page we are duplicating
383
+ * @param {String} pageId
384
+ * @param {Object} pageDefaults
385
+ * @returns {Object}
386
386
  */
387
387
  var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDocumentPage(doc, fileId, pageId) {
388
388
  var _nextDoc$fields;
@@ -401,12 +401,12 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
401
401
  });
402
402
  var newPageId = (0, _generateObjectId["default"])();
403
403
  var fieldLookup = {};
404
- (_nextDoc$fields = nextDoc.fields) === null || _nextDoc$fields === void 0 ? void 0 : _nextDoc$fields.forEach(function (field) {
404
+ (_nextDoc$fields = nextDoc.fields) === null || _nextDoc$fields === void 0 || _nextDoc$fields.forEach(function (field) {
405
405
  if (field.file === fileId) fieldLookup[field._id] = field;
406
406
  });
407
407
 
408
- /**
409
- * Step 1: Duplicate fields associated with target page
408
+ /**
409
+ * Step 1: Duplicate fields associated with target page
410
410
  */
411
411
  var fieldIdsToDuplicate = [];
412
412
 
@@ -434,13 +434,13 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
434
434
  var newFieldsLookupByOldId = {};
435
435
  var duplicatedFields = [];
436
436
  fieldIdsToDuplicate.forEach(function (fieldId) {
437
- /**
438
- * Why do we check if a new field has already been created?
439
- *
440
- * That is because multiple field positions can be associated with the same
441
- * field. If a field has already been created by a previous field position
442
- * that is linked to the same field as the current target then do not create
443
- * again.
437
+ /**
438
+ * Why do we check if a new field has already been created?
439
+ *
440
+ * That is because multiple field positions can be associated with the same
441
+ * field. If a field has already been created by a previous field position
442
+ * that is linked to the same field as the current target then do not create
443
+ * again.
444
444
  */
445
445
  if (newFieldsLookupByOldId[fieldId]) return;
446
446
  var field = fieldLookup[fieldId];
@@ -449,20 +449,20 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
449
449
  });
450
450
  duplicatedFields.push(duplicateField);
451
451
 
452
- /**
453
- * Add to lookup so it can be used with other associated field positions
452
+ /**
453
+ * Add to lookup so it can be used with other associated field positions
454
454
  */
455
455
  newFieldsLookupByOldId[field._id] = duplicateField;
456
456
  });
457
457
 
458
- /**
459
- * Step 2: Update newly duplicated fields logic properties
460
- *
461
- * This step can only be done after all fields have been properly duplicated.
462
- *
463
- * We only need to update logic conditions that referenced the target page
464
- * that we are duplicating. We do this by checking the logic.condition[x].page
465
- * property of the condition.
458
+ /**
459
+ * Step 2: Update newly duplicated fields logic properties
460
+ *
461
+ * This step can only be done after all fields have been properly duplicated.
462
+ *
463
+ * We only need to update logic conditions that referenced the target page
464
+ * that we are duplicating. We do this by checking the logic.condition[x].page
465
+ * property of the condition.
466
466
  */
467
467
  duplicatedFields = duplicatedFields.map(function (duplicatedField) {
468
468
  if (!duplicatedField.logic || !duplicatedField.logic.conditions || duplicatedField.logic.conditions.length < 1) return duplicatedField;
@@ -470,9 +470,9 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
470
470
  logic: _objectSpread({}, duplicatedField.logic)
471
471
  });
472
472
  nextField.logic.conditions = nextField.logic.conditions.map(function (condition) {
473
- /**
474
- * 1. Only update conditions associated with the current page being duplicated.
475
- * 2. Only update conditions associated with a field that was duplicated.
473
+ /**
474
+ * 1. Only update conditions associated with the current page being duplicated.
475
+ * 2. Only update conditions associated with a field that was duplicated.
476
476
  */
477
477
  if (condition.page === pageId && newFieldsLookupByOldId[condition.field]) {
478
478
  return _objectSpread(_objectSpread({}, condition), {}, {
@@ -486,18 +486,18 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
486
486
  return nextField;
487
487
  });
488
488
 
489
- /**
490
- * Step 3: Add newly duplicated fields changelogs and update doucment
489
+ /**
490
+ * Step 3: Add newly duplicated fields changelogs and update doucment
491
491
  */
492
492
  duplicatedFields.forEach(function (duplicateField) {
493
493
  changelogInfo.fields.push(duplicateField);
494
494
  nextDoc.fields.push(duplicateField);
495
495
  });
496
496
 
497
- /**
498
- * Step 4: Update Primary View Page Order
499
- *
500
- * IMPORTANT NOTE: Page order update must go before page object creation.
497
+ /**
498
+ * Step 4: Update Primary View Page Order
499
+ *
500
+ * IMPORTANT NOTE: Page order update must go before page object creation.
501
501
  */
502
502
  var pageOrder = getPageOrder(nextDoc.files[fileIndex].pageOrder, nextDoc.files[fileIndex].pages);
503
503
  var primaryPageOrderIndex = pageOrder.findIndex(function (id) {
@@ -507,8 +507,8 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
507
507
  nextDoc.files[fileIndex].pageOrder = pageOrder;
508
508
  nextDoc.files[fileIndex].pageOrder.splice(primaryPageOrderTargetIndex, 0, newPageId);
509
509
 
510
- /**
511
- * Step 5: Generate Primary View Page
510
+ /**
511
+ * Step 5: Generate Primary View Page
512
512
  */
513
513
  var primaryPageIndex = nextDoc.files[fileIndex].pages.findIndex(function (page) {
514
514
  return page._id === pageId;
@@ -525,14 +525,14 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
525
525
  });
526
526
  nextDoc.files[fileIndex].pages.splice(primaryPageIndex + 1, 0, newPrimaryPage);
527
527
 
528
- /**
529
- * Step 6: Update Primary Page Changelog
528
+ /**
529
+ * Step 6: Update Primary Page Changelog
530
530
  */
531
531
  changelogInfo.primaryPages.targetIndex = primaryPageOrderTargetIndex;
532
532
  changelogInfo.primaryPages.page = newPrimaryPage;
533
533
 
534
- /**
535
- * Step 7: Update Views
534
+ /**
535
+ * Step 7: Update Views
536
536
  */
537
537
  if (nextDoc.files[fileIndex].views && nextDoc.files[fileIndex].views.length > 0) {
538
538
  nextDoc.files[fileIndex].views = nextDoc.files[fileIndex].views.map(function (view) {
@@ -542,10 +542,10 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
542
542
  });
543
543
  if (viewPageIndex === -1) return view;
544
544
 
545
- /**
546
- * Step 7.1 Update View Page Order.
547
- *
548
- * IMPORTANT NOTE: Page order update must go before page object creation.
545
+ /**
546
+ * Step 7.1 Update View Page Order.
547
+ *
548
+ * IMPORTANT NOTE: Page order update must go before page object creation.
549
549
  */
550
550
  var nextViewPageOrder = getPageOrder(nextView.pageOrder, nextView.pages);
551
551
  var nextViewPageOrderIndex = nextViewPageOrder.findIndex(function (id) {
@@ -555,8 +555,8 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
555
555
  nextView.pageOrder = nextViewPageOrder;
556
556
  nextView.pageOrder.splice(nextViewTargetPageOrderIndex, 0, newPageId);
557
557
 
558
- /**
559
- * Step 7.2 Update View Pages
558
+ /**
559
+ * Step 7.2 Update View Pages
560
560
  */
561
561
  var newViewPage = _objectSpread(_objectSpread({}, nextView.pages[viewPageIndex]), {}, {
562
562
  _id: newPageId,
@@ -570,8 +570,8 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
570
570
  });
571
571
  nextView.pages.splice(viewPageIndex + 1, 0, newViewPage);
572
572
 
573
- /**
574
- * Step 7.3 Add View Page Changelog Info
573
+ /**
574
+ * Step 7.3 Add View Page Changelog Info
575
575
  */
576
576
  changelogInfo.viewPages.push({
577
577
  viewId: view._id,
@@ -588,21 +588,21 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
588
588
  };
589
589
  };
590
590
 
591
- /**
592
- * Generate the mobile view and add specific mobile view properties
593
- *
594
- * @param {Object} file //Full file object
595
- * @returns {Object}
591
+ /**
592
+ * Generate the mobile view and add specific mobile view properties
593
+ *
594
+ * @param {Object} file //Full file object
595
+ * @returns {Object}
596
596
  */
597
597
  var getMobileViewFromFile = exports.getMobileViewFromFile = function getMobileViewFromFile(file) {
598
598
  var _file$views2;
599
- var mobileViewIndex = file !== null && file !== void 0 && file.views && (file === null || file === void 0 ? void 0 : (_file$views2 = file.views) === null || _file$views2 === void 0 ? void 0 : _file$views2.length) > 0 ? file.views.findIndex(function (view) {
599
+ var mobileViewIndex = file !== null && file !== void 0 && file.views && (file === null || file === void 0 || (_file$views2 = file.views) === null || _file$views2 === void 0 ? void 0 : _file$views2.length) > 0 ? file.views.findIndex(function (view) {
600
600
  return view.type === _FileViews["default"].mobile;
601
601
  }) : -1;
602
602
  if (mobileViewIndex !== -1) {
603
- /**
604
- * Why do we do this? Early versions of alternative views did not contain pageOrder so
605
- * we ensure it's populated here.
603
+ /**
604
+ * Why do we do this? Early versions of alternative views did not contain pageOrder so
605
+ * we ensure it's populated here.
606
606
  */
607
607
  var mobileView = file.views[mobileViewIndex];
608
608
  var mobileViewPageOrder = cleanPageOrder(getPageOrder(mobileView.pageOrder, mobileView.pages), mobileView.pages);
@@ -614,11 +614,11 @@ var getMobileViewFromFile = exports.getMobileViewFromFile = function getMobileVi
614
614
  }
615
615
  };
616
616
 
617
- /**
618
- * Generates the alternative mobile view from the default file view.
619
- *
620
- * @param {Object} file //Full file object
621
- * @returns {Object}
617
+ /**
618
+ * Generates the alternative mobile view from the default file view.
619
+ *
620
+ * @param {Object} file //Full file object
621
+ * @returns {Object}
622
622
  */
623
623
  var generateMobileViewFromFile = exports.generateMobileViewFromFile = function generateMobileViewFromFile(file) {
624
624
  var pages = file.pages || [];
@@ -644,11 +644,11 @@ var generateMobileViewFromFile = exports.generateMobileViewFromFile = function g
644
644
  };
645
645
  };
646
646
 
647
- /**
648
- * Apply the pr
649
- *
650
- * @param {Object} page
651
- * @returns {Objectg}
647
+ /**
648
+ * Apply the pr
649
+ *
650
+ * @param {Object} page
651
+ * @returns {Objectg}
652
652
  */
653
653
  var generateMobilePage = exports.generateMobilePage = function generateMobilePage(page) {
654
654
  return _objectSpread(_objectSpread({}, page), {}, {
@@ -666,8 +666,8 @@ var generateMobilePage = exports.generateMobilePage = function generateMobilePag
666
666
  var generateMobilePageFieldPositions = exports.generateMobilePageFieldPositions = function generateMobilePageFieldPositions(fieldPositions, originalRowHeight) {
667
667
  var mobileFieldPositions = [];
668
668
 
669
- /**
670
- * Step 1: Sort fieldPositions
669
+ /**
670
+ * Step 1: Sort fieldPositions
671
671
  */
672
672
  var sortedFieldPositions = sortFieldPositionsByXAndYCoordinates(fieldPositions);
673
673
  sortedFieldPositions.forEach(function (joySpecFieldPosition) {
@@ -679,8 +679,8 @@ var generateMobilePageFieldPositions = exports.generateMobilePageFieldPositions
679
679
  x: 0
680
680
  });
681
681
 
682
- /**
683
- * Step 1.2 Hide chart lines on mobile
682
+ /**
683
+ * Step 1.2 Hide chart lines on mobile
684
684
  */
685
685
  if (joySpecFieldPosition.type === _FieldTypes["default"].chart) mobileFieldPositionData.primaryDisplayOnly = true;
686
686
  mobileFieldPositions.push(mobileFieldPositionData);
@@ -688,26 +688,26 @@ var generateMobilePageFieldPositions = exports.generateMobilePageFieldPositions
688
688
  return mergeAssoicatedFieldPositionsForMobilePage(mobileFieldPositions);
689
689
  };
690
690
 
691
- /**
692
- * Merge Field Positions assoicated with the same Field.
693
- *
694
- * Why do duplicate fields get created from fieldPositions
695
- *
696
- * The same field can get added twice because we may have multiple fieldPositions belonging
697
- * to the same field. This can happen with dropdown, multiSelect, and table fields.
698
- *
699
- * Since the fields get generated by looping over the fieldPositions and not regular fields
700
- * we may encounter the the same field multiple times because it has multiple fieldPositions.
701
- *
702
- * @param {Array} fields
703
- * @returns {Array}
691
+ /**
692
+ * Merge Field Positions assoicated with the same Field.
693
+ *
694
+ * Why do duplicate fields get created from fieldPositions
695
+ *
696
+ * The same field can get added twice because we may have multiple fieldPositions belonging
697
+ * to the same field. This can happen with dropdown, multiSelect, and table fields.
698
+ *
699
+ * Since the fields get generated by looping over the fieldPositions and not regular fields
700
+ * we may encounter the the same field multiple times because it has multiple fieldPositions.
701
+ *
702
+ * @param {Array} fields
703
+ * @returns {Array}
704
704
  */
705
705
  var mergeAssoicatedFieldPositionsForMobilePage = exports.mergeAssoicatedFieldPositionsForMobilePage = function mergeAssoicatedFieldPositionsForMobilePage(fieldPositions) {
706
706
  var filteredFieldPositions = [];
707
- fieldPositions === null || fieldPositions === void 0 ? void 0 : fieldPositions.forEach(function (fieldPosition) {
707
+ fieldPositions === null || fieldPositions === void 0 || fieldPositions.forEach(function (fieldPosition) {
708
708
  var fieldPositionIndex = filteredFieldPositions.findIndex(function (filtered) {
709
709
  var _filtered$field, _fieldPosition$field;
710
- return (filtered === null || filtered === void 0 ? void 0 : (_filtered$field = filtered.field) === null || _filtered$field === void 0 ? void 0 : _filtered$field.toString()) === (fieldPosition === null || fieldPosition === void 0 ? void 0 : (_fieldPosition$field = fieldPosition.field) === null || _fieldPosition$field === void 0 ? void 0 : _fieldPosition$field.toString());
710
+ return (filtered === null || filtered === void 0 || (_filtered$field = filtered.field) === null || _filtered$field === void 0 ? void 0 : _filtered$field.toString()) === (fieldPosition === null || fieldPosition === void 0 || (_fieldPosition$field = fieldPosition.field) === null || _fieldPosition$field === void 0 ? void 0 : _fieldPosition$field.toString());
711
711
  });
712
712
 
713
713
  //Only add field to the list if it hasn't already been added
@@ -716,30 +716,30 @@ var mergeAssoicatedFieldPositionsForMobilePage = exports.mergeAssoicatedFieldPos
716
716
  return filteredFieldPositions;
717
717
  };
718
718
 
719
- /**
720
- * Sort fields by their y and x coordinates
721
- *
722
- * For example:
723
- * [
724
- * { "y": 3, "x": 4 },
725
- * { "y": 3, "x": 1 },
726
- * { "y": 2, "x": 0 },
727
- * { "y": 1, "x": 5.22 },
728
- * { "y": 1, "x": 10 },
729
- * { "y": 1, "x": 0 },
730
- * ]
731
- * will become the following after sort
732
- * [
733
- * { "y": 1, "x": 0 },
734
- * { "y": 1, "x": 5.22 },
735
- * { "y": 1, "x": 10 },
736
- * { "y": 2, "x": 0 },
737
- * { "y": 3, "x": 1 },
738
- * { "y": 3, "x": 4 }
739
- * ];
740
- *
741
- * @param {Array} fieldPositions
742
- * @returns {Array}
719
+ /**
720
+ * Sort fields by their y and x coordinates
721
+ *
722
+ * For example:
723
+ * [
724
+ * { "y": 3, "x": 4 },
725
+ * { "y": 3, "x": 1 },
726
+ * { "y": 2, "x": 0 },
727
+ * { "y": 1, "x": 5.22 },
728
+ * { "y": 1, "x": 10 },
729
+ * { "y": 1, "x": 0 },
730
+ * ]
731
+ * will become the following after sort
732
+ * [
733
+ * { "y": 1, "x": 0 },
734
+ * { "y": 1, "x": 5.22 },
735
+ * { "y": 1, "x": 10 },
736
+ * { "y": 2, "x": 0 },
737
+ * { "y": 3, "x": 1 },
738
+ * { "y": 3, "x": 4 }
739
+ * ];
740
+ *
741
+ * @param {Array} fieldPositions
742
+ * @returns {Array}
743
743
  */
744
744
  var sortFieldPositionsByXAndYCoordinates = exports.sortFieldPositionsByXAndYCoordinates = function sortFieldPositionsByXAndYCoordinates(fieldPositions) {
745
745
  var sortedFieldPositions = (0, _toConsumableArray2["default"])(fieldPositions);
@@ -757,20 +757,20 @@ var sortFieldPositionsByXAndYCoordinates = exports.sortFieldPositionsByXAndYCoor
757
757
  return sortedFieldPositions;
758
758
  };
759
759
 
760
- /**
761
- * Formats individual table cell field positions that have already been merged with their associated field.
762
- * This additional information is added and used for rendering the fieldPositions on the form.
763
- *
764
- * For instance, adds properties like columnType, calculatedCellValue, options, etc.
765
- *
766
- * @param {Array} fieldPositions
767
- * @returns {Array}
760
+ /**
761
+ * Formats individual table cell field positions that have already been merged with their associated field.
762
+ * This additional information is added and used for rendering the fieldPositions on the form.
763
+ *
764
+ * For instance, adds properties like columnType, calculatedCellValue, options, etc.
765
+ *
766
+ * @param {Array} fieldPositions
767
+ * @returns {Array}
768
768
  */
769
769
  var formatTableFieldPositions = exports.formatTableFieldPositions = function formatTableFieldPositions(fieldPositions) {
770
- /**
771
- * We only want to generate the table value calculated lookup for each table field once.
772
- * We use these lookups because multiple table fieldPositions belonging to the same table
773
- * field will all use the same table value calculated lookup.
770
+ /**
771
+ * We only want to generate the table value calculated lookup for each table field once.
772
+ * We use these lookups because multiple table fieldPositions belonging to the same table
773
+ * field will all use the same table value calculated lookup.
774
774
  */
775
775
  var tableFieldLookup = {};
776
776
  var nextFieldPositions = [];
@@ -785,21 +785,21 @@ var formatTableFieldPositions = exports.formatTableFieldPositions = function for
785
785
  rowOrder = fieldPosition.rowOrder,
786
786
  tableColumnOrder = fieldPosition.tableColumnOrder;
787
787
 
788
- /**
789
- * Step 1: Generate rows, rowOrder, tableColumns, etc. lookups for associated field. We only have to
790
- * do this once per-field. This increases performance if there are multiple form positions associated
791
- * with the same form.
788
+ /**
789
+ * Step 1: Generate rows, rowOrder, tableColumns, etc. lookups for associated field. We only have to
790
+ * do this once per-field. This increases performance if there are multiple form positions associated
791
+ * with the same form.
792
792
  */
793
793
  if (!tableFieldLookup[field]) {
794
- /**
795
- * Step 1.1 Handle rows
794
+ /**
795
+ * Step 1.1 Handle rows
796
796
  */
797
797
  var nextRows = (0, _tableHelper.getRows)(value);
798
798
  var nextRowOrder = (0, _tableHelper.getCleanedRowOrder)(rowOrder, nextRows);
799
799
  var nextSortedRows = (0, _tableHelper.sortRows)(nextRows, nextRowOrder);
800
800
 
801
- /**
802
- * Step 1.2 Handle columns
801
+ /**
802
+ * Step 1.2 Handle columns
803
803
  */
804
804
  var nextTableColumnOrder = (0, _tableHelper.getCleanedColumnOrder)(tableColumnOrder, tableColumns);
805
805
  var nextSortedTableColumns = (0, _tableHelper.sortColumns)(tableColumns, nextTableColumnOrder);
@@ -809,8 +809,8 @@ var formatTableFieldPositions = exports.formatTableFieldPositions = function for
809
809
  return nextTableColumnLookup[column._id] = column;
810
810
  });
811
811
 
812
- /**
813
- * Step 1.3 Handle cell calculations
812
+ /**
813
+ * Step 1.3 Handle cell calculations
814
814
  */
815
815
  var calculatedValue = (0, _tableHelper.generateTableLookup)(nextSortedRows, nextSortedTableColumns);
816
816
  tableFieldLookup[field] = {
@@ -823,51 +823,51 @@ var formatTableFieldPositions = exports.formatTableFieldPositions = function for
823
823
  };
824
824
  }
825
825
 
826
- /**
827
- * Ensure each table field has a properly formatted properties
826
+ /**
827
+ * Ensure each table field has a properly formatted properties
828
828
  */
829
829
  nextFieldPosition.value = tableFieldLookup[field].value;
830
830
  nextFieldPosition.rowOrder = tableFieldLookup[field].rowOrder;
831
831
  nextFieldPosition.tableColumns = tableFieldLookup[field].tableColumns;
832
832
  nextFieldPosition.tableColumnOrder = tableFieldLookup[field].tableColumnOrder;
833
833
 
834
- /**
835
- * Add calculated value lookup. For instance, { A1: '', B1: '', C1: '', ... }
834
+ /**
835
+ * Add calculated value lookup. For instance, { A1: '', B1: '', C1: '', ... }
836
836
  */
837
837
  nextFieldPosition.calculatedValue = tableFieldLookup[field].calculatedValue;
838
838
 
839
- /**
840
- * Individual Table Cell vs Entire Table
841
- *
842
- * Only add cellValue, calculatedCellValue, columnType, and column options to
843
- * individually mapped table cell fieldPositions. Regular table fields (entire table)
844
- * just simply use the fieldPositions.value parameter so we don't need the calculated
845
- * values, etc.
846
- *
847
- * We determine an individual table cell fieldPosition vs an entire table
848
- * fieldPosition by checking for column and rowIndex. Individual cells have
849
- * column and rowIndex but regular tables do not.
850
- *
851
- * Note:
852
- * rowIndex + 1 is used while calculating cell value since column operands
853
- * start from 1 instead of zero in the table lookups
854
- * (ie: [A1:{}, B1:{}] instead of [A0:{}, B0:{}])
855
- *
856
- * If tableRowIndex associated with a cell doesn't have a table row associated
857
- * with it (ie rows[rowIndex] is undefined) it means that particular row is deleted
839
+ /**
840
+ * Individual Table Cell vs Entire Table
841
+ *
842
+ * Only add cellValue, calculatedCellValue, columnType, and column options to
843
+ * individually mapped table cell fieldPositions. Regular table fields (entire table)
844
+ * just simply use the fieldPositions.value parameter so we don't need the calculated
845
+ * values, etc.
846
+ *
847
+ * We determine an individual table cell fieldPosition vs an entire table
848
+ * fieldPosition by checking for column and rowIndex. Individual cells have
849
+ * column and rowIndex but regular tables do not.
850
+ *
851
+ * Note:
852
+ * rowIndex + 1 is used while calculating cell value since column operands
853
+ * start from 1 instead of zero in the table lookups
854
+ * (ie: [A1:{}, B1:{}] instead of [A0:{}, B0:{}])
855
+ *
856
+ * If tableRowIndex associated with a cell doesn't have a table row associated
857
+ * with it (ie rows[rowIndex] is undefined) it means that particular row is deleted
858
858
  */
859
859
  if (tableFieldLookup[field] && column && typeof rowIndex === 'number') {
860
860
  var _tableFieldLookup$fie;
861
- /**
862
- * What is the difference between rowIndex and targetRowIndex?
863
- *
864
- * - The rowIndex on the fieldPosition is the saved index of where the rowId lives inside of the rowOrder.
865
- * - The targetRowIndex is the actual index of the row object inside the value (array of row data) of the field.
866
- *
867
- * We use the fieldPosition.rowIndex to get the rowId from the rowOrder. Then we use the rowId to locate
868
- * the assoicated row object data in the value property. The rowOrder and value (rows) do not follow the same
869
- * order. The rowOrder is updated when users insert rows, move rows up or down, etc. it manages where rows
870
- * are at in the list and how they should be rendered. This is why the rowIndex uses the rowOrder.
861
+ /**
862
+ * What is the difference between rowIndex and targetRowIndex?
863
+ *
864
+ * - The rowIndex on the fieldPosition is the saved index of where the rowId lives inside of the rowOrder.
865
+ * - The targetRowIndex is the actual index of the row object inside the value (array of row data) of the field.
866
+ *
867
+ * We use the fieldPosition.rowIndex to get the rowId from the rowOrder. Then we use the rowId to locate
868
+ * the assoicated row object data in the value property. The rowOrder and value (rows) do not follow the same
869
+ * order. The rowOrder is updated when users insert rows, move rows up or down, etc. it manages where rows
870
+ * are at in the list and how they should be rendered. This is why the rowIndex uses the rowOrder.
871
871
  */
872
872
  var targetColumn = tableFieldLookup[field].tableColumnLookup[column];
873
873
  var targetRowId = tableFieldLookup[field].rowOrder[rowIndex];
@@ -875,21 +875,21 @@ var formatTableFieldPositions = exports.formatTableFieldPositions = function for
875
875
  return (row === null || row === void 0 ? void 0 : row._id) === targetRowId;
876
876
  });
877
877
 
878
- /**
879
- * Add proper rowId to the field position so that it can be used
880
- * inside the element for change handlers;
878
+ /**
879
+ * Add proper rowId to the field position so that it can be used
880
+ * inside the element for change handlers;
881
881
  */
882
882
  nextFieldPosition.rowId = targetRowId;
883
883
 
884
- /**
885
- * If rows[rowIndex] is undefined, it means the row that was present
886
- * at the particular rowIndex was deleted
884
+ /**
885
+ * If rows[rowIndex] is undefined, it means the row that was present
886
+ * at the particular rowIndex was deleted
887
887
  */
888
888
  nextFieldPosition.cellValue = ((_tableFieldLookup$fie = tableFieldLookup[field].value[targetRowIndex]) === null || _tableFieldLookup$fie === void 0 ? void 0 : _tableFieldLookup$fie.cells[column]) || '';
889
889
 
890
- /**
891
- * Skip any individual field position that is associated with a deleted column.
892
- * targetColumn will appear as undefined if a column is deleted
890
+ /**
891
+ * Skip any individual field position that is associated with a deleted column.
892
+ * targetColumn will appear as undefined if a column is deleted
893
893
  */
894
894
  if (targetColumn) {
895
895
  nextFieldPosition.calculatedCellValue = tableFieldLookup[field].calculatedValue["".concat(targetColumn.operand).concat(targetRowIndex + 1)];
@@ -897,9 +897,9 @@ var formatTableFieldPositions = exports.formatTableFieldPositions = function for
897
897
  nextFieldPosition.options = targetColumn.options;
898
898
  nextFieldPosition.columnIdentifier = targetColumn.identifier;
899
899
 
900
- /**
901
- * IMPORTANT NOTE: We only add individual table cell field position into
902
- * the fieldPosition list if the associated column is not deleted.
900
+ /**
901
+ * IMPORTANT NOTE: We only add individual table cell field position into
902
+ * the fieldPosition list if the associated column is not deleted.
903
903
  */
904
904
  nextFieldPositions.push(nextFieldPosition);
905
905
  }