@builttocreate/engine-utils 2.10.1-beta.v593.9 → 2.11.0-beta.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.
- package/dist/fieldHelper.js +40 -1
- package/dist/generateReadableId.js +39 -62
- package/dist/index.js +1 -2
- package/dist/joyDocHelper.js +20 -18
- package/dist/tableHelper.js +4 -8
- package/dist/validateReadableId.js +30 -4
- package/package.json +1 -1
package/dist/fieldHelper.js
CHANGED
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.isTargetOptionDeleted = exports.isFieldEmpty = exports.handleMultiSelectOptionToggle = exports.getTemplateWithLookups = exports.getMultiSelectFieldValue = exports.getImportFieldValues = exports.getDefaultOption = exports.getDefaultFieldValuesFromTemplate = exports.getChartFieldValue = exports["default"] = void 0;
|
|
7
|
+
exports.isTargetOptionDeleted = exports.isFieldEmpty = exports.handleMultiSelectOptionToggle = exports.getTemplateWithLookups = exports.getMultiSelectFieldValue = exports.getImportFieldValues = exports.getDefaultOption = exports.getDefaultFieldValuesFromTemplate = exports.getChartFieldValue = exports.flattenSchemaTree = exports["default"] = void 0;
|
|
8
8
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
@@ -298,6 +298,45 @@ var isTargetOptionDeleted = exports.isTargetOptionDeleted = function isTargetOpt
|
|
|
298
298
|
var result = !(undeletedOptions.length > 0);
|
|
299
299
|
return result;
|
|
300
300
|
};
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
*
|
|
304
|
+
* Flattens a nested schema tree into an array of objects and adds a depth property to each object.
|
|
305
|
+
*
|
|
306
|
+
* @param {Object} schemaObj
|
|
307
|
+
* @returns {Array} // An array of objects with the schema's id, depth, and other properties.
|
|
308
|
+
*/
|
|
309
|
+
var flattenSchemaTree = exports.flattenSchemaTree = function flattenSchemaTree(schemaObj) {
|
|
310
|
+
var flattened = [];
|
|
311
|
+
|
|
312
|
+
// Recursive function to traverse the tree.
|
|
313
|
+
function traverse(schemaId, depth, parentId) {
|
|
314
|
+
var node = schemaObj[schemaId];
|
|
315
|
+
if (!node) return;
|
|
316
|
+
|
|
317
|
+
// Create a new object that includes the schema's id and its depth.
|
|
318
|
+
flattened.push(_objectSpread({
|
|
319
|
+
id: schemaId,
|
|
320
|
+
parentId: parentId,
|
|
321
|
+
depth: depth
|
|
322
|
+
}, node));
|
|
323
|
+
|
|
324
|
+
// If the node has children, traverse them with increased depth.
|
|
325
|
+
if (node.children && node.children.length > 0) {
|
|
326
|
+
node.children.forEach(function (childId) {
|
|
327
|
+
return traverse(childId, depth + 1, schemaId);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Find and traverse each root node.
|
|
333
|
+
Object.keys(schemaObj).forEach(function (schemaId) {
|
|
334
|
+
if (schemaObj[schemaId].root) {
|
|
335
|
+
traverse(schemaId, 0);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
return flattened;
|
|
339
|
+
};
|
|
301
340
|
var _default = exports["default"] = {
|
|
302
341
|
getDefaultOption: getDefaultOption,
|
|
303
342
|
getChartFieldValue: getChartFieldValue,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -9,13 +8,9 @@ exports.generateReadableTableColumnId = generateReadableTableColumnId;
|
|
|
9
8
|
exports.getFieldPositionsCount = getFieldPositionsCount;
|
|
10
9
|
exports.getFieldsCount = getFieldsCount;
|
|
11
10
|
exports.getViewsFieldPositionsCount = getViewsFieldPositionsCount;
|
|
12
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
13
|
-
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
14
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
15
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) { n[e] = r[e]; } return n; }
|
|
16
11
|
/**
|
|
17
12
|
* Counts fields of a specific type in an array of fields
|
|
18
|
-
*
|
|
13
|
+
*
|
|
19
14
|
* @param {Array} fields - Array of fields that have a .type property
|
|
20
15
|
* @param {String} type - The field type to count
|
|
21
16
|
* @returns {Number} - Count of fields matching the type
|
|
@@ -26,11 +21,10 @@ function countFieldsByType(fields, type) {
|
|
|
26
21
|
return field && field.type === type;
|
|
27
22
|
}).length;
|
|
28
23
|
}
|
|
29
|
-
;
|
|
30
24
|
|
|
31
25
|
/**
|
|
32
26
|
* Counts field positions of a specific type in document fields
|
|
33
|
-
*
|
|
27
|
+
*
|
|
34
28
|
* @param {Array} fields - Array of fields
|
|
35
29
|
* @param {String} type - Field type to count
|
|
36
30
|
* @returns {Number} - Count of fields matching the type
|
|
@@ -42,11 +36,10 @@ function getFieldsCount(fields, type) {
|
|
|
42
36
|
}
|
|
43
37
|
return countFieldsByType(fields, type);
|
|
44
38
|
}
|
|
45
|
-
;
|
|
46
39
|
|
|
47
40
|
/**
|
|
48
41
|
* Counts field positions of a specific type in an array of pages
|
|
49
|
-
*
|
|
42
|
+
*
|
|
50
43
|
* @param {Array} pages - Array of pages with fieldPositions
|
|
51
44
|
* @param {String} type - Field type to count
|
|
52
45
|
* @returns {Number} - Count of fieldPositions matching the type
|
|
@@ -64,11 +57,10 @@ function getFieldPositionsCount(pages, type) {
|
|
|
64
57
|
});
|
|
65
58
|
return count;
|
|
66
59
|
}
|
|
67
|
-
;
|
|
68
60
|
|
|
69
61
|
/**
|
|
70
62
|
* Counts field positions in views
|
|
71
|
-
*
|
|
63
|
+
*
|
|
72
64
|
* @param {Array} views - Array of views with pages with fieldPositions
|
|
73
65
|
* @param {String} type - Field type to count
|
|
74
66
|
* @returns {Number} - Count of fieldPositions in views matching the type
|
|
@@ -86,20 +78,19 @@ function getViewsFieldPositionsCount(views, type) {
|
|
|
86
78
|
});
|
|
87
79
|
return count;
|
|
88
80
|
}
|
|
89
|
-
;
|
|
90
81
|
|
|
91
82
|
/**
|
|
92
83
|
* Gets the next field ID for a specific type by counting existing fields
|
|
93
84
|
* and incrementing. It is built to support any combination of the parameters.
|
|
94
|
-
*
|
|
85
|
+
*
|
|
95
86
|
* But it is recommended to use it with all 3 parts if possible.
|
|
96
|
-
*
|
|
87
|
+
*
|
|
97
88
|
* @param {Object} parts - Object containing fields, pages, and views
|
|
98
89
|
* @param {Array} parts.fields - Array of fields
|
|
99
90
|
* @param {Array} parts.pages - Array of pages with fieldPositions
|
|
100
91
|
* @param {Array} parts.views - Array of views with pages
|
|
101
92
|
* @param {String} type - The field type to count
|
|
102
|
-
* @param {String} prefix - An optional prefix to add to the ID
|
|
93
|
+
* @param {String} prefix - An optional prefix to add to the ID
|
|
103
94
|
* @returns {String} - An ID in the format "prefix{type}{count+1}" (e.g. "text3")
|
|
104
95
|
*/
|
|
105
96
|
function generateReadableId(parts, type) {
|
|
@@ -114,35 +105,34 @@ function generateReadableId(parts, type) {
|
|
|
114
105
|
throw new Error('generateReadableId: at least one of fields, pages, or views is required');
|
|
115
106
|
}
|
|
116
107
|
if (!fields) console.warn('generateReadableId: fields parameter is missing');
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// Note: leaving for now until we allow targeting fieldPositions
|
|
108
|
+
|
|
109
|
+
// Note: leaving for now until we allow targeting fieldPositions
|
|
120
110
|
// if (pages) count += getFieldPositionsCount(pages, type);
|
|
121
|
-
// if (views && views.length > 1) count += getViewsFieldPositionsCount(views, type);
|
|
111
|
+
// if (views && views.length > 1) count += getViewsFieldPositionsCount(views, type);
|
|
122
112
|
|
|
113
|
+
var count = fields.length ? getFieldsCount(fields, type) : 0;
|
|
123
114
|
var readableId = "".concat(type).concat(splitterId).concat(count + 1);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
* */
|
|
129
|
-
|
|
130
|
-
fields.forEach(function (field) {
|
|
131
|
-
if (field._id === readableId) readableId = "".concat(type).concat(splitterId).concat(count + 2);
|
|
132
|
-
});
|
|
115
|
+
while (hasDuplicateId(fields, readableId)) {
|
|
116
|
+
count++;
|
|
117
|
+
readableId = "".concat(type).concat(splitterId).concat(count + 1);
|
|
118
|
+
}
|
|
133
119
|
return readableId;
|
|
134
120
|
}
|
|
135
|
-
|
|
121
|
+
function hasDuplicateId(items, targetId) {
|
|
122
|
+
return items.some(function (item) {
|
|
123
|
+
return item._id === targetId;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
136
126
|
|
|
137
127
|
/**
|
|
138
128
|
* Generates a readable table column ID by counting existing columns
|
|
139
|
-
*
|
|
129
|
+
*
|
|
140
130
|
* @param {String} tableId - The ID of the table (used as prefix)
|
|
141
131
|
* @param {Array} tableColumns - Array of table column objects
|
|
142
132
|
* @returns {String} - An ID in the format "{tableId}Column{count+1}" (e.g. "table1Column1")
|
|
143
133
|
*/
|
|
144
134
|
function generateReadableTableColumnId(tableId, tableColumns, columnId) {
|
|
145
|
-
//Add logic that ensures that created Id is not a duplicate
|
|
135
|
+
//Add logic that ensures that created Id is not a duplicate
|
|
146
136
|
if (!tableId) throw new Error('generateReadableTableColumnId: tableId is required');
|
|
147
137
|
if (!columnId) throw new Error('generateReadableTableColumnId: columnId is required');
|
|
148
138
|
if (!tableColumns || !Array.isArray(tableColumns)) {
|
|
@@ -150,41 +140,28 @@ function generateReadableTableColumnId(tableId, tableColumns, columnId) {
|
|
|
150
140
|
return "".concat(tableId, "Column1");
|
|
151
141
|
}
|
|
152
142
|
var counts = {};
|
|
143
|
+
var generatedId = null;
|
|
153
144
|
|
|
154
145
|
//Filter out undefined and null values from tableColumns
|
|
155
146
|
var validColumns = tableColumns.filter(function (column) {
|
|
156
147
|
return column !== undefined && column !== null;
|
|
157
148
|
});
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
var
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
tableColumns.forEach(function (column) {
|
|
172
|
-
if (column._id === readableId) {
|
|
173
|
-
readableId = "".concat(type).concat(counts[type] + 2);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
return {
|
|
177
|
-
v: readableId
|
|
178
|
-
};
|
|
149
|
+
validColumns.forEach(function (col) {
|
|
150
|
+
var type = (col.type || 'unknown').toLowerCase();
|
|
151
|
+
counts[type] = (counts[type] || 0) + 1;
|
|
152
|
+
var readableId = "".concat(type).concat(counts[type]);
|
|
153
|
+
if (col._id === columnId) {
|
|
154
|
+
/**
|
|
155
|
+
* If the generatedReadableId is already present in the tableColumns,
|
|
156
|
+
* we need to increment the count until we find a unique ID.
|
|
157
|
+
* This ensures that the new column ID is unique.
|
|
158
|
+
*/
|
|
159
|
+
while (hasDuplicateId(validColumns, readableId)) {
|
|
160
|
+
counts[type]++;
|
|
161
|
+
readableId = "".concat(type).concat(counts[type]);
|
|
179
162
|
}
|
|
180
|
-
|
|
181
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
182
|
-
var _ret = _loop();
|
|
183
|
-
if ((0, _typeof2["default"])(_ret) === "object") return _ret.v;
|
|
163
|
+
generatedId = readableId;
|
|
184
164
|
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
} finally {
|
|
188
|
-
_iterator.f();
|
|
189
|
-
}
|
|
165
|
+
});
|
|
166
|
+
return generatedId;
|
|
190
167
|
}
|
package/dist/index.js
CHANGED
|
@@ -86,8 +86,7 @@ var _generateObjectId = _interopRequireDefault(require("./generateObjectId"));
|
|
|
86
86
|
var _validateObjectId = _interopRequireDefault(require("./validateObjectId"));
|
|
87
87
|
var _generateReadableId = require("./generateReadableId");
|
|
88
88
|
var _validateReadableId = _interopRequireDefault(require("./validateReadableId"));
|
|
89
|
-
function
|
|
90
|
-
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; }
|
|
89
|
+
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); }
|
|
91
90
|
var _default = exports["default"] = {
|
|
92
91
|
fileHelper: fileHelper,
|
|
93
92
|
tableHelper: tableHelper,
|
package/dist/joyDocHelper.js
CHANGED
|
@@ -10,7 +10,6 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
10
10
|
var _generateObjectId = _interopRequireDefault(require("./generateObjectId"));
|
|
11
11
|
var _validateObjectId = _interopRequireDefault(require("./validateObjectId"));
|
|
12
12
|
var _generateReadableId = require("./generateReadableId");
|
|
13
|
-
var _validateReadableId = _interopRequireDefault(require("./validateReadableId"));
|
|
14
13
|
var _PageLayoutModes = _interopRequireDefault(require("./constants/PageLayoutModes"));
|
|
15
14
|
var _FieldPresentationModes = _interopRequireDefault(require("./constants/FieldPresentationModes"));
|
|
16
15
|
var _DocumentTypes = _interopRequireDefault(require("./constants/DocumentTypes"));
|
|
@@ -20,6 +19,7 @@ var _FieldDisplayTypes = _interopRequireDefault(require("./constants/FieldDispla
|
|
|
20
19
|
var _FileViews = _interopRequireDefault(require("./constants/FileViews"));
|
|
21
20
|
var _FormStyleOptions = _interopRequireDefault(require("./constants/FormStyleOptions"));
|
|
22
21
|
var _tableHelper = require("./tableHelper");
|
|
22
|
+
var _validateReadableId = _interopRequireDefault(require("./validateReadableId"));
|
|
23
23
|
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; }
|
|
24
24
|
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; }
|
|
25
25
|
/**
|
|
@@ -91,7 +91,7 @@ var getDefaultJoyDoc = exports.getDefaultJoyDoc = function getDefaultJoyDoc() {
|
|
|
91
91
|
* If existing _id is a valid ObjectId, keep it
|
|
92
92
|
* Otherwise, generate a readable ID using the field type
|
|
93
93
|
* with as much data as we are given to determine the proper count.
|
|
94
|
-
*
|
|
94
|
+
*
|
|
95
95
|
* @param {String} existingId - The existing ID to check
|
|
96
96
|
* @param {String} type - The field type for generating readable IDs
|
|
97
97
|
* @param {Object} doc - The document context for readable ID generation
|
|
@@ -100,11 +100,12 @@ var getDefaultJoyDoc = exports.getDefaultJoyDoc = function getDefaultJoyDoc() {
|
|
|
100
100
|
*/
|
|
101
101
|
var getFieldId = function getFieldId(existingId, type, doc) {
|
|
102
102
|
// If existing ID is a valid ObjectId or readableId, maintain it
|
|
103
|
+
//Note: readableId validation is already done when it's being generated
|
|
104
|
+
|
|
103
105
|
if (existingId && (0, _validateObjectId["default"])(existingId)) {
|
|
104
106
|
return existingId;
|
|
105
|
-
} else if (existingId && (0, _validateReadableId["default"])(existingId)) {
|
|
106
|
-
return existingId;
|
|
107
107
|
}
|
|
108
|
+
if (existingId) return existingId;
|
|
108
109
|
|
|
109
110
|
// Otherwise, generate a readable ID
|
|
110
111
|
if (type) {
|
|
@@ -112,7 +113,7 @@ var getFieldId = function getFieldId(existingId, type, doc) {
|
|
|
112
113
|
var baseCount = 0;
|
|
113
114
|
if (doc.fields) baseCount += (0, _generateReadableId.getFieldsCount)(doc.fields, type);
|
|
114
115
|
|
|
115
|
-
// Note: leaving for now until we allow targeting fieldPositions
|
|
116
|
+
// Note: leaving for now until we allow targeting fieldPositions
|
|
116
117
|
// if (doc.pages) baseCount += getFieldPositionsCount(getAllPages(doc), type);
|
|
117
118
|
// if (doc.views && doc.views.length > 1) baseCount += getViewsFieldPositionsCount(getAllViews(doc), type);
|
|
118
119
|
|
|
@@ -171,9 +172,10 @@ var getCleanedJoyDoc = exports.getCleanedJoyDoc = function getCleanedJoyDoc(doc)
|
|
|
171
172
|
var nextFile = _objectSpread({}, file);
|
|
172
173
|
|
|
173
174
|
/**
|
|
174
|
-
* Step 1.3: Replace files[x]._id if it is not valid
|
|
175
|
+
* Step 1.3: Replace files[x]._id if it is not a valid ObjectId or valid readable ID
|
|
175
176
|
*/
|
|
176
|
-
|
|
177
|
+
|
|
178
|
+
if (nextFile._id && !(0, _validateObjectId["default"])(nextFile._id) && !(0, _validateReadableId["default"])(nextFile._id)) nextFile._id = (0, _generateObjectId["default"])();
|
|
177
179
|
|
|
178
180
|
/**
|
|
179
181
|
* Step 1.4: Replace page ids and field ids if they are not valid
|
|
@@ -184,7 +186,7 @@ var getCleanedJoyDoc = exports.getCleanedJoyDoc = function getCleanedJoyDoc(doc)
|
|
|
184
186
|
/**
|
|
185
187
|
* Step 1.5: Replace view page ids and field ids if they are not valid
|
|
186
188
|
*/
|
|
187
|
-
if ((nextFile === null || nextFile === void 0
|
|
189
|
+
if ((nextFile === null || nextFile === void 0 || (_nextFile$views = nextFile.views) === null || _nextFile$views === void 0 ? void 0 : _nextFile$views.length) > 0) {
|
|
188
190
|
nextFile.views = nextFile.views.map(function (view) {
|
|
189
191
|
var nextView = _objectSpread({}, view);
|
|
190
192
|
nextView.pages = getCleanedJoyDocPages(nextView.pages, nextDoc);
|
|
@@ -209,13 +211,13 @@ var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = fu
|
|
|
209
211
|
if (!doc) return getDefaultJoyDoc();
|
|
210
212
|
var nextDoc = _objectSpread({}, doc);
|
|
211
213
|
var associatedFieldIdLookup = {};
|
|
212
|
-
nextDoc === null || nextDoc === void 0
|
|
214
|
+
nextDoc === null || nextDoc === void 0 || (_nextDoc$files = nextDoc.files) === null || _nextDoc$files === void 0 || _nextDoc$files.forEach(function (file) {
|
|
213
215
|
var _file$views;
|
|
214
216
|
/**
|
|
215
217
|
* Primary view
|
|
216
218
|
*/
|
|
217
219
|
file.pages.forEach(function (page) {
|
|
218
|
-
page === null || page === void 0
|
|
220
|
+
page === null || page === void 0 || page.fieldPositions.forEach(function (fieldPosition) {
|
|
219
221
|
return associatedFieldIdLookup[fieldPosition.field] = true;
|
|
220
222
|
});
|
|
221
223
|
});
|
|
@@ -223,10 +225,10 @@ var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = fu
|
|
|
223
225
|
/**
|
|
224
226
|
* Alternative view
|
|
225
227
|
*/
|
|
226
|
-
(_file$views = file.views) === null || _file$views === void 0
|
|
228
|
+
(_file$views = file.views) === null || _file$views === void 0 || _file$views.forEach(function (view) {
|
|
227
229
|
var _view$pages;
|
|
228
|
-
view === null || view === void 0
|
|
229
|
-
page === null || page === void 0
|
|
230
|
+
view === null || view === void 0 || (_view$pages = view.pages) === null || _view$pages === void 0 || _view$pages.forEach(function (page) {
|
|
231
|
+
page === null || page === void 0 || page.fieldPositions.forEach(function (fieldPosition) {
|
|
230
232
|
return associatedFieldIdLookup[fieldPosition.field] = true;
|
|
231
233
|
});
|
|
232
234
|
});
|
|
@@ -280,7 +282,7 @@ var getCleanedJoyDocPages = exports.getCleanedJoyDocPages = function getCleanedJ
|
|
|
280
282
|
// Clean fieldPosition _id
|
|
281
283
|
nextFieldPosition._id = nextFieldPosition._id && (0, _validateObjectId["default"])(nextFieldPosition._id) ? nextFieldPosition._id : (0, _generateObjectId["default"])();
|
|
282
284
|
|
|
283
|
-
// Clean fieldPosition.field reference
|
|
285
|
+
// Clean fieldPosition.field reference
|
|
284
286
|
nextFieldPosition.field = getFieldId(nextFieldPosition.field, fieldPosition.type, doc);
|
|
285
287
|
return nextFieldPosition;
|
|
286
288
|
});
|
|
@@ -449,7 +451,7 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
|
|
|
449
451
|
});
|
|
450
452
|
var newPageId = (0, _generateObjectId["default"])();
|
|
451
453
|
var fieldLookup = {};
|
|
452
|
-
(_nextDoc$fields = nextDoc.fields) === null || _nextDoc$fields === void 0
|
|
454
|
+
(_nextDoc$fields = nextDoc.fields) === null || _nextDoc$fields === void 0 || _nextDoc$fields.forEach(function (field) {
|
|
453
455
|
if (field.file === fileId) fieldLookup[field._id] = field;
|
|
454
456
|
});
|
|
455
457
|
|
|
@@ -644,7 +646,7 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
|
|
|
644
646
|
*/
|
|
645
647
|
var getMobileViewFromFile = exports.getMobileViewFromFile = function getMobileViewFromFile(file) {
|
|
646
648
|
var _file$views2;
|
|
647
|
-
var mobileViewIndex = file !== null && file !== void 0 && file.views && (file === null || file === void 0
|
|
649
|
+
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) {
|
|
648
650
|
return view.type === _FileViews["default"].mobile;
|
|
649
651
|
}) : -1;
|
|
650
652
|
if (mobileViewIndex !== -1) {
|
|
@@ -752,10 +754,10 @@ var generateMobilePageFieldPositions = exports.generateMobilePageFieldPositions
|
|
|
752
754
|
*/
|
|
753
755
|
var mergeAssoicatedFieldPositionsForMobilePage = exports.mergeAssoicatedFieldPositionsForMobilePage = function mergeAssoicatedFieldPositionsForMobilePage(fieldPositions) {
|
|
754
756
|
var filteredFieldPositions = [];
|
|
755
|
-
fieldPositions === null || fieldPositions === void 0
|
|
757
|
+
fieldPositions === null || fieldPositions === void 0 || fieldPositions.forEach(function (fieldPosition) {
|
|
756
758
|
var fieldPositionIndex = filteredFieldPositions.findIndex(function (filtered) {
|
|
757
759
|
var _filtered$field, _fieldPosition$field;
|
|
758
|
-
return (filtered === null || filtered === void 0
|
|
760
|
+
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());
|
|
759
761
|
});
|
|
760
762
|
|
|
761
763
|
//Only add field to the list if it hasn't already been added
|
package/dist/tableHelper.js
CHANGED
|
@@ -15,8 +15,7 @@ var _Table = _interopRequireWildcard(require("./constants/Table"));
|
|
|
15
15
|
var _FieldTypes = _interopRequireDefault(require("./constants/FieldTypes"));
|
|
16
16
|
var _FieldTableColumnTypes = _interopRequireDefault(require("./constants/FieldTableColumnTypes"));
|
|
17
17
|
var _FieldTableCustomColumnIds = _interopRequireDefault(require("./constants/FieldTableCustomColumnIds"));
|
|
18
|
-
function
|
|
19
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(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; }
|
|
18
|
+
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" != _typeof3(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); }
|
|
20
19
|
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; }
|
|
21
20
|
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; }
|
|
22
21
|
var parser = new _hotFormulaParser.Parser();
|
|
@@ -257,14 +256,10 @@ var handleMoveColumnRight = exports.handleMoveColumnRight = function handleMoveC
|
|
|
257
256
|
* @return {Object}
|
|
258
257
|
*/
|
|
259
258
|
var getDefaultColumnOption = exports.getDefaultColumnOption = function getDefaultColumnOption(value) {
|
|
260
|
-
var color = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
261
259
|
return {
|
|
262
260
|
_id: (0, _generateObjectId["default"])(),
|
|
263
261
|
value: value || 'Option',
|
|
264
|
-
deleted: false
|
|
265
|
-
styles: {
|
|
266
|
-
backgroundColor: color
|
|
267
|
-
}
|
|
262
|
+
deleted: false
|
|
268
263
|
};
|
|
269
264
|
};
|
|
270
265
|
|
|
@@ -423,7 +418,7 @@ var getDefaultDropdownColumn = exports.getDefaultDropdownColumn = function getDe
|
|
|
423
418
|
*/
|
|
424
419
|
var getDefaultMultiSelectColumn = exports.getDefaultMultiSelectColumn = function getDefaultMultiSelectColumn() {
|
|
425
420
|
var defaults = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
426
|
-
var options = defaults.options || [getDefaultColumnOption('Option 1'
|
|
421
|
+
var options = defaults.options || [getDefaultColumnOption('Option 1'), getDefaultColumnOption('Option 2'), getDefaultColumnOption('Option 3')];
|
|
427
422
|
return _objectSpread({
|
|
428
423
|
_id: (0, _generateObjectId["default"])(),
|
|
429
424
|
type: _FieldTableColumnTypes["default"].multiSelect,
|
|
@@ -762,6 +757,7 @@ var generateTableLookup = exports.generateTableLookup = function generateTableLo
|
|
|
762
757
|
if (!(row !== null && row !== void 0 && row.cells)) console.warn("Missing 'cells' in row: ".concat(row._id));
|
|
763
758
|
tableColumns.forEach(function (column) {
|
|
764
759
|
if (!column.operand) return;
|
|
760
|
+
// eslint-disable-next-line no-console
|
|
765
761
|
if (!row) console.warn("Row via column ".concat(column === null || column === void 0 ? void 0 : column._id, " is undefined."));
|
|
766
762
|
var cellKey = "".concat(column.operand).concat(rowIndex + 1);
|
|
767
763
|
var cellRawValue = row && row !== null && row !== void 0 && row.cells && row.cells[column._id] ? row.cells[column._id] : undefined;
|
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
10
|
+
var _fieldHelper = require("./fieldHelper");
|
|
11
|
+
var _FieldTypes = _interopRequireDefault(require("./constants/FieldTypes"));
|
|
10
12
|
// Check if value follows a valid readableId pattern for use in JavaScript formulas
|
|
11
13
|
// Note to test this please run npm test src/validateReadableId.test.js
|
|
12
14
|
|
|
@@ -77,11 +79,11 @@ var JOYDOC_PROPERTIES = new Set(['_id', 'identifier', 'name', 'type', 'files', '
|
|
|
77
79
|
/**
|
|
78
80
|
* Validates if a string can be used as a JavaScript identifier
|
|
79
81
|
* and doesn't conflict with reserved words
|
|
80
|
-
*
|
|
82
|
+
*
|
|
81
83
|
* @param {*} readableId - The ID to validate
|
|
82
84
|
* @returns {boolean} - True if valid, false otherwise
|
|
83
85
|
*/
|
|
84
|
-
var _default = exports["default"] = function _default(readableId, fields, tableColumns) {
|
|
86
|
+
var _default = exports["default"] = function _default(readableId, fields, tableColumns, fieldId) {
|
|
85
87
|
// Must be a non-empty string
|
|
86
88
|
if (typeof readableId !== 'string' || readableId.length === 0) {
|
|
87
89
|
console.warn("validateReadableId: Invalid input - expected non-empty string, got ".concat(typeof readableId === 'string' ? 'empty string' : (0, _typeof2["default"])(readableId)));
|
|
@@ -143,8 +145,10 @@ var _default = exports["default"] = function _default(readableId, fields, tableC
|
|
|
143
145
|
return false;
|
|
144
146
|
}
|
|
145
147
|
|
|
146
|
-
//6. Check for
|
|
147
|
-
|
|
148
|
+
//6. Check for duplicates in readableIds
|
|
149
|
+
|
|
150
|
+
if (Array.isArray(fields)) {
|
|
151
|
+
//DuplicateId check for fieldIds
|
|
148
152
|
var duplicateField = fields.find(function (field) {
|
|
149
153
|
return field._id === readableId;
|
|
150
154
|
});
|
|
@@ -152,7 +156,29 @@ var _default = exports["default"] = function _default(readableId, fields, tableC
|
|
|
152
156
|
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it already exists in fields"));
|
|
153
157
|
return false;
|
|
154
158
|
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* DuplicateId check for nested tables of collection fields
|
|
162
|
+
* When readableIds for nestedTables are passed in, we need the fieldId to retrieve the collection fields that houses the nestedTable
|
|
163
|
+
*/
|
|
164
|
+
if (fieldId) {
|
|
165
|
+
var targetField = fields.find(function (field) {
|
|
166
|
+
return field._id === fieldId;
|
|
167
|
+
});
|
|
168
|
+
if ((targetField === null || targetField === void 0 ? void 0 : targetField.type) === _FieldTypes["default"].collection) {
|
|
169
|
+
var flattenedSchema = (0, _fieldHelper.flattenSchemaTree)(targetField.schema);
|
|
170
|
+
var readableIdExists = flattenedSchema.some(function (schema) {
|
|
171
|
+
return schema.id === readableId;
|
|
172
|
+
});
|
|
173
|
+
if (readableIdExists) {
|
|
174
|
+
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it already exists in fields"));
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
155
179
|
}
|
|
180
|
+
|
|
181
|
+
//DuplicateId check for columnIds
|
|
156
182
|
if (tableColumns && Array.isArray(tableColumns)) {
|
|
157
183
|
var duplicateColumnId = tableColumns.find(function (column) {
|
|
158
184
|
return column._id === readableId;
|