@builttocreate/engine-utils 2.8.0-beta.6 → 2.8.0-beta.9
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/dist/joyDocHelper.js +86 -31
- package/package.json +1 -1
package/dist/joyDocHelper.js
CHANGED
|
@@ -161,42 +161,97 @@ var getCleanedJoyDoc = exports.getCleanedJoyDoc = function getCleanedJoyDoc(doc)
|
|
|
161
161
|
* Remove orphaned fields from doc
|
|
162
162
|
*/
|
|
163
163
|
|
|
164
|
-
|
|
165
|
-
var nextDoc = _objectSpread({}, doc);
|
|
164
|
+
// export const removeOrphanedFieldsFromJoydoc = (doc) => {
|
|
166
165
|
|
|
167
|
-
|
|
168
|
-
* Logic below removes orphaned fields (ie fields without fieldPositions)
|
|
169
|
-
*/
|
|
166
|
+
// const nextDoc = { ...doc };
|
|
170
167
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
var _file$views$find;
|
|
175
|
-
var primaryViewPages = file.pages;
|
|
168
|
+
// /**
|
|
169
|
+
// * Logic below removes orphaned fields (ie fields without fieldPositions)
|
|
170
|
+
// */
|
|
176
171
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
172
|
+
// nextDoc.fields = nextDoc.fields.filter((field) => {
|
|
173
|
+
|
|
174
|
+
// let isOrphanedField = true;
|
|
175
|
+
|
|
176
|
+
// nextDoc.files.forEach((file) => {
|
|
177
|
+
|
|
178
|
+
// const primaryViewPages = file.pages;
|
|
179
|
+
|
|
180
|
+
// // Check if field is associated with any field positions in primary view pages
|
|
181
|
+
// const isFieldAssociatedWithPrimaryView = primaryViewPages.some((page) => {
|
|
182
|
+
// return page.fieldPositions.some((fieldPosition) => fieldPosition.field === field._id);
|
|
183
|
+
// });
|
|
184
|
+
|
|
185
|
+
// // Check if field is associated with other views
|
|
186
|
+
// let isFieldAssociatedWithAnotherView;
|
|
187
|
+
|
|
188
|
+
// if (file.views && file.views.length > 0) {
|
|
189
|
+
|
|
190
|
+
// isFieldAssociatedWithAnotherView = file.views.some((view) => {
|
|
191
|
+
// return view.pages.some((page) => {
|
|
192
|
+
// return page.fieldPositions.some((fieldPosition) => fieldPosition.field === field._id);
|
|
193
|
+
// });
|
|
194
|
+
// });
|
|
195
|
+
|
|
196
|
+
// }
|
|
197
|
+
|
|
198
|
+
// if (isFieldAssociatedWithPrimaryView || isFieldAssociatedWithAnotherView) {
|
|
199
|
+
// isOrphanedField = false;
|
|
200
|
+
// }
|
|
201
|
+
|
|
202
|
+
// });
|
|
203
|
+
|
|
204
|
+
// if (!isOrphanedField) return field;
|
|
205
|
+
|
|
206
|
+
// return null;
|
|
207
|
+
|
|
208
|
+
// });
|
|
209
|
+
|
|
210
|
+
// return nextDoc;
|
|
211
|
+
|
|
212
|
+
// };
|
|
213
|
+
|
|
214
|
+
var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = function removeOrphanedFieldsFromJoydoc(doc) {
|
|
215
|
+
var _nextDoc$files;
|
|
216
|
+
var nextDoc = _objectSpread({}, doc);
|
|
217
|
+
var associatedFieldIdLookup = {};
|
|
218
|
+
nextDoc === null || nextDoc === void 0 ? void 0 : (_nextDoc$files = nextDoc.files) === null || _nextDoc$files === void 0 ? void 0 : _nextDoc$files.forEach(function (file) {
|
|
219
|
+
var _file$views;
|
|
220
|
+
/**
|
|
221
|
+
* Primary view
|
|
222
|
+
*/
|
|
223
|
+
file.pages.forEach(function (page) {
|
|
224
|
+
page.fieldPositions.forEach(function (fieldPosition) {
|
|
225
|
+
return associatedFieldIdLookup[fieldPosition.field] = true;
|
|
182
226
|
});
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Alternative view
|
|
231
|
+
*/
|
|
232
|
+
(_file$views = file.views) === null || _file$views === void 0 ? void 0 : _file$views.forEach(function (view) {
|
|
233
|
+
var _view$pages;
|
|
234
|
+
view === null || view === void 0 ? void 0 : (_view$pages = view.pages) === null || _view$pages === void 0 ? void 0 : _view$pages.forEach(function (page) {
|
|
235
|
+
page === null || page === void 0 ? void 0 : page.fieldPositions.forEach(function (fieldPosition) {
|
|
236
|
+
return associatedFieldIdLookup[fieldPosition.field] = true;
|
|
191
237
|
});
|
|
192
|
-
})
|
|
193
|
-
if (isFieldAssociatedWithPrimaryView || isFieldAssociatedWithMobileView) {
|
|
194
|
-
isOrphanedField = false;
|
|
195
|
-
}
|
|
238
|
+
});
|
|
196
239
|
});
|
|
197
|
-
if (!isOrphanedField) return field;
|
|
198
240
|
});
|
|
199
|
-
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Logic below removes orphaned fields (ie fields without fieldPositions)
|
|
244
|
+
*/
|
|
245
|
+
var validFields = [];
|
|
246
|
+
var deletedFields = [];
|
|
247
|
+
nextDoc.fields.forEach(function (field) {
|
|
248
|
+
if (associatedFieldIdLookup[field._id]) validFields.push(field);else deletedFields.push(field);
|
|
249
|
+
});
|
|
250
|
+
nextDoc.fields = validFields;
|
|
251
|
+
return {
|
|
252
|
+
doc: nextDoc,
|
|
253
|
+
deletedFields: deletedFields
|
|
254
|
+
};
|
|
200
255
|
};
|
|
201
256
|
|
|
202
257
|
/**
|
|
@@ -588,8 +643,8 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
|
|
|
588
643
|
* @returns {Object}
|
|
589
644
|
*/
|
|
590
645
|
var getMobileViewFromFile = exports.getMobileViewFromFile = function getMobileViewFromFile(file) {
|
|
591
|
-
var _file$
|
|
592
|
-
var mobileViewIndex = file !== null && file !== void 0 && file.views && (file === null || file === void 0 ? void 0 : (_file$
|
|
646
|
+
var _file$views2;
|
|
647
|
+
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) {
|
|
593
648
|
return view.type === _FileViews["default"].mobile;
|
|
594
649
|
}) : -1;
|
|
595
650
|
if (mobileViewIndex !== -1) {
|