@builttocreate/engine-utils 2.10.0 → 2.10.1-beta.593v2
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/generateReadableId.js +141 -0
- package/dist/index.js +26 -2
- package/dist/joyDocHelper.js +84 -36
- package/dist/tableHelper.js +3 -4
- package/dist/validateReadableId.js +146 -0
- package/package.json +1 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateReadableId = generateReadableId;
|
|
7
|
+
exports.generateReadableTableColumnId = generateReadableTableColumnId;
|
|
8
|
+
exports.getFieldPositionsCount = getFieldPositionsCount;
|
|
9
|
+
exports.getFieldsCount = getFieldsCount;
|
|
10
|
+
exports.getViewsFieldPositionsCount = getViewsFieldPositionsCount;
|
|
11
|
+
/**
|
|
12
|
+
* Counts fields of a specific type in an array of fields
|
|
13
|
+
*
|
|
14
|
+
* @param {Array} fields - Array of fields that have a .type property
|
|
15
|
+
* @param {String} type - The field type to count
|
|
16
|
+
* @returns {Number} - Count of fields matching the type
|
|
17
|
+
*/
|
|
18
|
+
function countFieldsByType(fields, type) {
|
|
19
|
+
if (!fields || !Array.isArray(fields)) return 0;
|
|
20
|
+
return fields.filter(function (field) {
|
|
21
|
+
return field && field.type === type;
|
|
22
|
+
}).length;
|
|
23
|
+
}
|
|
24
|
+
;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Counts field positions of a specific type in document fields
|
|
28
|
+
*
|
|
29
|
+
* @param {Array} fields - Array of fields
|
|
30
|
+
* @param {String} type - Field type to count
|
|
31
|
+
* @returns {Number} - Count of fields matching the type
|
|
32
|
+
*/
|
|
33
|
+
function getFieldsCount(fields, type) {
|
|
34
|
+
if (!fields || !Array.isArray(fields)) {
|
|
35
|
+
console.warn('getFieldsCount: fields parameter is missing or not an array');
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
return countFieldsByType(fields, type);
|
|
39
|
+
}
|
|
40
|
+
;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Counts field positions of a specific type in an array of pages
|
|
44
|
+
*
|
|
45
|
+
* @param {Array} pages - Array of pages with fieldPositions
|
|
46
|
+
* @param {String} type - Field type to count
|
|
47
|
+
* @returns {Number} - Count of fieldPositions matching the type
|
|
48
|
+
*/
|
|
49
|
+
function getFieldPositionsCount(pages, type) {
|
|
50
|
+
if (!pages || !Array.isArray(pages)) {
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
if (!pages.length) return 0;
|
|
54
|
+
var count = 0;
|
|
55
|
+
pages.forEach(function (page) {
|
|
56
|
+
if (page && page.fieldPositions) {
|
|
57
|
+
count += countFieldsByType(page.fieldPositions, type);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return count;
|
|
61
|
+
}
|
|
62
|
+
;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Counts field positions in views
|
|
66
|
+
*
|
|
67
|
+
* @param {Array} views - Array of views with pages with fieldPositions
|
|
68
|
+
* @param {String} type - Field type to count
|
|
69
|
+
* @returns {Number} - Count of fieldPositions in views matching the type
|
|
70
|
+
*/
|
|
71
|
+
function getViewsFieldPositionsCount(views, type) {
|
|
72
|
+
if (!views || !Array.isArray(views)) {
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
if (!views.length) return 0;
|
|
76
|
+
var count = 0;
|
|
77
|
+
views.forEach(function (view) {
|
|
78
|
+
if (view && view.pages && view.pages.length) {
|
|
79
|
+
count += getFieldPositionsCount(view.pages, type);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return count;
|
|
83
|
+
}
|
|
84
|
+
;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Gets the next field ID for a specific type by counting existing fields
|
|
88
|
+
* and incrementing. It is built to support any combination of the parameters.
|
|
89
|
+
*
|
|
90
|
+
* But it is recommended to use it with all 3 parts if possible.
|
|
91
|
+
*
|
|
92
|
+
* @param {Object} parts - Object containing fields, pages, and views
|
|
93
|
+
* @param {Array} parts.fields - Array of fields
|
|
94
|
+
* @param {Array} parts.pages - Array of pages with fieldPositions
|
|
95
|
+
* @param {Array} parts.views - Array of views with pages
|
|
96
|
+
* @param {String} type - The field type to count
|
|
97
|
+
* @param {String} prefix - An optional prefix to add to the ID
|
|
98
|
+
* @returns {String} - An ID in the format "prefix{type}{count+1}" (e.g. "text3")
|
|
99
|
+
*/
|
|
100
|
+
function generateReadableId(parts, type) {
|
|
101
|
+
var splitterId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
102
|
+
var fields = parts === null || parts === void 0 ? void 0 : parts.fields;
|
|
103
|
+
var pages = parts === null || parts === void 0 ? void 0 : parts.pages;
|
|
104
|
+
var views = parts === null || parts === void 0 ? void 0 : parts.views;
|
|
105
|
+
if (!type) throw new Error('generateReadableId: type is required');
|
|
106
|
+
|
|
107
|
+
// Check if all three parameters are missing
|
|
108
|
+
if (!fields && !pages && !views) {
|
|
109
|
+
throw new Error('generateReadableId: at least one of fields, pages, or views is required');
|
|
110
|
+
}
|
|
111
|
+
if (!fields) console.warn('generateReadableId: fields parameter is missing');
|
|
112
|
+
var count = 0;
|
|
113
|
+
if (fields) count += getFieldsCount(fields, type);
|
|
114
|
+
// Note: leaving for now until we allow targeting fieldPositions
|
|
115
|
+
// if (pages) count += getFieldPositionsCount(pages, type);
|
|
116
|
+
// if (views && views.length > 1) count += getViewsFieldPositionsCount(views, type);
|
|
117
|
+
|
|
118
|
+
return "".concat(type).concat(splitterId).concat(count + 1);
|
|
119
|
+
}
|
|
120
|
+
;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Generates a readable table column ID by counting existing columns
|
|
124
|
+
*
|
|
125
|
+
* @param {String} tableId - The ID of the table (used as prefix)
|
|
126
|
+
* @param {Array} tableColumns - Array of table column objects
|
|
127
|
+
* @returns {String} - An ID in the format "{tableId}Column{count+1}" (e.g. "table1Column1")
|
|
128
|
+
*/
|
|
129
|
+
function generateReadableTableColumnId(tableId, tableColumns) {
|
|
130
|
+
if (!tableId) throw new Error('generateReadableTableColumnId: tableId is required');
|
|
131
|
+
if (!tableColumns || !Array.isArray(tableColumns)) {
|
|
132
|
+
return "".concat(tableId, "Column1");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Filter out undefined and null values from tableColumns
|
|
136
|
+
var validColumns = tableColumns.filter(function (column) {
|
|
137
|
+
return column !== undefined && column !== null;
|
|
138
|
+
});
|
|
139
|
+
var count = validColumns.length;
|
|
140
|
+
return "".concat(tableId, "Column").concat(count + 1);
|
|
141
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,18 @@ Object.defineProperty(exports, "generateObjectId", {
|
|
|
31
31
|
return _generateObjectId["default"];
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
|
+
Object.defineProperty(exports, "generateReadableId", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function get() {
|
|
37
|
+
return _generateReadableId.generateReadableId;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "generateReadableTableColumnId", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function get() {
|
|
43
|
+
return _generateReadableId.generateReadableTableColumnId;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
34
46
|
exports.paginationHelper = exports.joyDocHelper = void 0;
|
|
35
47
|
Object.defineProperty(exports, "reduxApiMiddleware", {
|
|
36
48
|
enumerable: true,
|
|
@@ -45,6 +57,12 @@ Object.defineProperty(exports, "validateObjectId", {
|
|
|
45
57
|
return _validateObjectId["default"];
|
|
46
58
|
}
|
|
47
59
|
});
|
|
60
|
+
Object.defineProperty(exports, "validateReadableId", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function get() {
|
|
63
|
+
return _validateReadableId["default"];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
48
66
|
var tableHelper = _interopRequireWildcard(require("./tableHelper"));
|
|
49
67
|
exports.tableHelper = tableHelper;
|
|
50
68
|
var chartHelper = _interopRequireWildcard(require("./chartHelper"));
|
|
@@ -66,7 +84,10 @@ var _changedKeys = _interopRequireDefault(require("./changedKeys"));
|
|
|
66
84
|
var _Roles = _interopRequireDefault(require("./constants/Roles"));
|
|
67
85
|
var _generateObjectId = _interopRequireDefault(require("./generateObjectId"));
|
|
68
86
|
var _validateObjectId = _interopRequireDefault(require("./validateObjectId"));
|
|
69
|
-
|
|
87
|
+
var _generateReadableId = require("./generateReadableId");
|
|
88
|
+
var _validateReadableId = _interopRequireDefault(require("./validateReadableId"));
|
|
89
|
+
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); }
|
|
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; }
|
|
70
91
|
var _default = exports["default"] = {
|
|
71
92
|
fileHelper: fileHelper,
|
|
72
93
|
tableHelper: tableHelper,
|
|
@@ -81,5 +102,8 @@ var _default = exports["default"] = {
|
|
|
81
102
|
roleHelper: roleHelper,
|
|
82
103
|
Roles: _Roles["default"],
|
|
83
104
|
generateObjectId: _generateObjectId["default"],
|
|
84
|
-
validateObjectId: _validateObjectId["default"]
|
|
105
|
+
validateObjectId: _validateObjectId["default"],
|
|
106
|
+
generateReadableId: _generateReadableId.generateReadableId,
|
|
107
|
+
generateReadableTableColumnId: _generateReadableId.generateReadableTableColumnId,
|
|
108
|
+
validateReadableId: _validateReadableId["default"]
|
|
85
109
|
};
|
package/dist/joyDocHelper.js
CHANGED
|
@@ -9,6 +9,8 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
10
|
var _generateObjectId = _interopRequireDefault(require("./generateObjectId"));
|
|
11
11
|
var _validateObjectId = _interopRequireDefault(require("./validateObjectId"));
|
|
12
|
+
var _generateReadableId = require("./generateReadableId");
|
|
13
|
+
var _validateReadableId = _interopRequireDefault(require("./validateReadableId"));
|
|
12
14
|
var _PageLayoutModes = _interopRequireDefault(require("./constants/PageLayoutModes"));
|
|
13
15
|
var _FieldPresentationModes = _interopRequireDefault(require("./constants/FieldPresentationModes"));
|
|
14
16
|
var _DocumentTypes = _interopRequireDefault(require("./constants/DocumentTypes"));
|
|
@@ -85,6 +87,42 @@ var getDefaultJoyDoc = exports.getDefaultJoyDoc = function getDefaultJoyDoc() {
|
|
|
85
87
|
}, defaults);
|
|
86
88
|
};
|
|
87
89
|
|
|
90
|
+
/**
|
|
91
|
+
* If existing _id is a valid ObjectId, keep it
|
|
92
|
+
* Otherwise, generate a readable ID using the field type
|
|
93
|
+
* with as much data as we are given to determine the proper count.
|
|
94
|
+
*
|
|
95
|
+
* @param {String} existingId - The existing ID to check
|
|
96
|
+
* @param {String} type - The field type for generating readable IDs
|
|
97
|
+
* @param {Object} doc - The document context for readable ID generation
|
|
98
|
+
* @param {Object} generatedIdCounts - Object to track generated ID counts within this operation
|
|
99
|
+
* @returns {String} - Either the existing ObjectId or a new readable ID
|
|
100
|
+
*/
|
|
101
|
+
var getFieldId = function getFieldId(existingId, type, doc) {
|
|
102
|
+
// If existing ID is a valid ObjectId or readableId, maintain it
|
|
103
|
+
if (existingId && (0, _validateObjectId["default"])(existingId)) {
|
|
104
|
+
return existingId;
|
|
105
|
+
} else if (existingId && (0, _validateReadableId["default"])(existingId)) {
|
|
106
|
+
return existingId;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Otherwise, generate a readable ID
|
|
110
|
+
if (type) {
|
|
111
|
+
// Get the base count from existing fields
|
|
112
|
+
var baseCount = 0;
|
|
113
|
+
if (doc.fields) baseCount += (0, _generateReadableId.getFieldsCount)(doc.fields, type);
|
|
114
|
+
|
|
115
|
+
// Note: leaving for now until we allow targeting fieldPositions
|
|
116
|
+
// if (doc.pages) baseCount += getFieldPositionsCount(getAllPages(doc), type);
|
|
117
|
+
// if (doc.views && doc.views.length > 1) baseCount += getViewsFieldPositionsCount(getAllViews(doc), type);
|
|
118
|
+
|
|
119
|
+
return "".concat(type).concat(baseCount + 1);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Fallback to ObjectId if we can't generate readable ID
|
|
123
|
+
return (0, _generateObjectId["default"])();
|
|
124
|
+
};
|
|
125
|
+
|
|
88
126
|
/**
|
|
89
127
|
* Get Clean JoyDoc Format
|
|
90
128
|
*
|
|
@@ -105,32 +143,51 @@ var getCleanedJoyDoc = exports.getCleanedJoyDoc = function getCleanedJoyDoc(doc)
|
|
|
105
143
|
nextDoc = _removeOrphanedFields.nextDoc;
|
|
106
144
|
|
|
107
145
|
/**
|
|
108
|
-
* Step 1.1: Replace doc._id if it is not valid
|
|
146
|
+
* Step 1.1: Replace doc._id if it is not valid (always use objectId for documents)
|
|
109
147
|
*/
|
|
110
148
|
if (nextDoc._id && !(0, _validateObjectId["default"])(nextDoc._id)) nextDoc._id = (0, _generateObjectId["default"])();
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Step 1.2: Clean field IDs using simplified approach
|
|
152
|
+
*/
|
|
153
|
+
if (nextDoc.fields && nextDoc.fields.length > 0) {
|
|
154
|
+
nextDoc.fields = nextDoc.fields.map(function (field) {
|
|
155
|
+
var nextField = _objectSpread({}, field);
|
|
156
|
+
|
|
157
|
+
// Clean field _id using simplified approach
|
|
158
|
+
nextField._id = getFieldId(field._id, field.type, nextDoc);
|
|
159
|
+
|
|
160
|
+
// Clean table field rowOrder
|
|
161
|
+
if (field.type === _FieldTypes["default"].table) {
|
|
162
|
+
var cleanedRoworder = (0, _tableHelper.getCleanedRowOrder)(field.rowOrder, field.value);
|
|
163
|
+
nextField.rowOrder = cleanedRoworder;
|
|
164
|
+
}
|
|
165
|
+
return nextField;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
111
168
|
if (nextDoc.files && nextDoc.files.length > 0) {
|
|
112
169
|
nextDoc.files = nextDoc.files.map(function (file) {
|
|
113
170
|
var _nextFile$views;
|
|
114
171
|
var nextFile = _objectSpread({}, file);
|
|
115
172
|
|
|
116
173
|
/**
|
|
117
|
-
* Step 1.
|
|
174
|
+
* Step 1.3: Replace files[x]._id if it is not valid (always use objectId for files)
|
|
118
175
|
*/
|
|
119
176
|
if (nextFile._id && !(0, _validateObjectId["default"])(nextFile._id)) nextFile._id = (0, _generateObjectId["default"])();
|
|
120
177
|
|
|
121
178
|
/**
|
|
122
|
-
* Step 1.
|
|
179
|
+
* Step 1.4: Replace page ids and field ids if they are not valid
|
|
123
180
|
*/
|
|
124
|
-
nextFile.pages = getCleanedJoyDocPages(nextFile.pages);
|
|
181
|
+
nextFile.pages = getCleanedJoyDocPages(nextFile.pages, nextDoc);
|
|
125
182
|
nextFile.pageOrder = cleanPageOrder(getPageOrder(nextFile.pageOrder, nextFile.pages), nextFile.pages);
|
|
126
183
|
|
|
127
184
|
/**
|
|
128
|
-
* Step 1.
|
|
185
|
+
* Step 1.5: Replace view page ids and field ids if they are not valid
|
|
129
186
|
*/
|
|
130
|
-
if ((nextFile === null || nextFile === void 0
|
|
187
|
+
if ((nextFile === null || nextFile === void 0 ? void 0 : (_nextFile$views = nextFile.views) === null || _nextFile$views === void 0 ? void 0 : _nextFile$views.length) > 0) {
|
|
131
188
|
nextFile.views = nextFile.views.map(function (view) {
|
|
132
189
|
var nextView = _objectSpread({}, view);
|
|
133
|
-
nextView.pages = getCleanedJoyDocPages(nextView.pages);
|
|
190
|
+
nextView.pages = getCleanedJoyDocPages(nextView.pages, nextDoc);
|
|
134
191
|
nextView.pageOrder = cleanPageOrder(getPageOrder(nextView.pageOrder, nextView.pages), nextView.pages);
|
|
135
192
|
return nextView;
|
|
136
193
|
});
|
|
@@ -140,21 +197,6 @@ var getCleanedJoyDoc = exports.getCleanedJoyDoc = function getCleanedJoyDoc(doc)
|
|
|
140
197
|
} else {
|
|
141
198
|
nextDoc.files = [getDefaultJoyDocFile()];
|
|
142
199
|
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Logic below is used to clean the table field rowOrder by removing the
|
|
146
|
-
* deletedRowIds / duplicateRowIds from the rowOrder.
|
|
147
|
-
**/
|
|
148
|
-
if (nextDoc.fields && nextDoc.fields.length > 0) {
|
|
149
|
-
nextDoc.fields = nextDoc.fields.map(function (field) {
|
|
150
|
-
var nextField = _objectSpread({}, field);
|
|
151
|
-
if (field.type === _FieldTypes["default"].table) {
|
|
152
|
-
var cleanedRoworder = (0, _tableHelper.getCleanedRowOrder)(field.rowOrder, field.value);
|
|
153
|
-
nextField.rowOrder = cleanedRoworder;
|
|
154
|
-
}
|
|
155
|
-
return nextField;
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
200
|
return nextDoc;
|
|
159
201
|
};
|
|
160
202
|
|
|
@@ -167,13 +209,13 @@ var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = fu
|
|
|
167
209
|
if (!doc) return getDefaultJoyDoc();
|
|
168
210
|
var nextDoc = _objectSpread({}, doc);
|
|
169
211
|
var associatedFieldIdLookup = {};
|
|
170
|
-
nextDoc === null || nextDoc === void 0
|
|
212
|
+
nextDoc === null || nextDoc === void 0 ? void 0 : (_nextDoc$files = nextDoc.files) === null || _nextDoc$files === void 0 ? void 0 : _nextDoc$files.forEach(function (file) {
|
|
171
213
|
var _file$views;
|
|
172
214
|
/**
|
|
173
215
|
* Primary view
|
|
174
216
|
*/
|
|
175
217
|
file.pages.forEach(function (page) {
|
|
176
|
-
page === null || page === void 0
|
|
218
|
+
page === null || page === void 0 ? void 0 : page.fieldPositions.forEach(function (fieldPosition) {
|
|
177
219
|
return associatedFieldIdLookup[fieldPosition.field] = true;
|
|
178
220
|
});
|
|
179
221
|
});
|
|
@@ -181,10 +223,10 @@ var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = fu
|
|
|
181
223
|
/**
|
|
182
224
|
* Alternative view
|
|
183
225
|
*/
|
|
184
|
-
(_file$views = file.views) === null || _file$views === void 0
|
|
226
|
+
(_file$views = file.views) === null || _file$views === void 0 ? void 0 : _file$views.forEach(function (view) {
|
|
185
227
|
var _view$pages;
|
|
186
|
-
view === null || view === void 0
|
|
187
|
-
page === null || page === void 0
|
|
228
|
+
view === null || view === void 0 ? void 0 : (_view$pages = view.pages) === null || _view$pages === void 0 ? void 0 : _view$pages.forEach(function (page) {
|
|
229
|
+
page === null || page === void 0 ? void 0 : page.fieldPositions.forEach(function (fieldPosition) {
|
|
188
230
|
return associatedFieldIdLookup[fieldPosition.field] = true;
|
|
189
231
|
});
|
|
190
232
|
});
|
|
@@ -215,14 +257,15 @@ var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = fu
|
|
|
215
257
|
* 1. Valid page inside document file.pages array.
|
|
216
258
|
* 2. All id's in pages and fieldPositions are valid format
|
|
217
259
|
*
|
|
218
|
-
* @param {
|
|
260
|
+
* @param {Array} pages
|
|
261
|
+
* @param {Object} doc - The full document (needed for readableId generation)
|
|
219
262
|
* @returns {Object}
|
|
220
263
|
*/
|
|
221
|
-
var getCleanedJoyDocPages = exports.getCleanedJoyDocPages = function getCleanedJoyDocPages(pages) {
|
|
264
|
+
var getCleanedJoyDocPages = exports.getCleanedJoyDocPages = function getCleanedJoyDocPages(pages, doc) {
|
|
222
265
|
if ((pages === null || pages === void 0 ? void 0 : pages.length) > 0) {
|
|
223
266
|
return pages.map(function (page) {
|
|
224
267
|
/**
|
|
225
|
-
* Step 1: Replace pages[x]._id if it is not valid
|
|
268
|
+
* Step 1: Replace pages[x]._id if it is not valid (always use objectId for pages)
|
|
226
269
|
*/
|
|
227
270
|
var nextPage = _objectSpread({}, page);
|
|
228
271
|
if (nextPage._id && !(0, _validateObjectId["default"])(nextPage._id)) nextPage._id = (0, _generateObjectId["default"])();
|
|
@@ -230,10 +273,15 @@ var getCleanedJoyDocPages = exports.getCleanedJoyDocPages = function getCleanedJ
|
|
|
230
273
|
nextPage.fieldPositions = nextPage.fieldPositions.map(function (fieldPosition) {
|
|
231
274
|
/**
|
|
232
275
|
* Step 1.2: Replace fieldPosition _id and field reference if they are not valid
|
|
276
|
+
* Use simplified approach: respect ObjectIds, otherwise generate readable IDs
|
|
233
277
|
*/
|
|
234
278
|
var nextFieldPosition = _objectSpread({}, fieldPosition);
|
|
235
|
-
|
|
236
|
-
|
|
279
|
+
|
|
280
|
+
// Clean fieldPosition _id
|
|
281
|
+
nextFieldPosition._id = nextFieldPosition._id && (0, _validateObjectId["default"])(nextFieldPosition._id) ? nextFieldPosition._id : (0, _generateObjectId["default"])();
|
|
282
|
+
|
|
283
|
+
// Clean fieldPosition.field reference
|
|
284
|
+
nextFieldPosition.field = getFieldId(nextFieldPosition.field, fieldPosition.type, doc);
|
|
237
285
|
return nextFieldPosition;
|
|
238
286
|
});
|
|
239
287
|
} else {
|
|
@@ -401,7 +449,7 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
|
|
|
401
449
|
});
|
|
402
450
|
var newPageId = (0, _generateObjectId["default"])();
|
|
403
451
|
var fieldLookup = {};
|
|
404
|
-
(_nextDoc$fields = nextDoc.fields) === null || _nextDoc$fields === void 0
|
|
452
|
+
(_nextDoc$fields = nextDoc.fields) === null || _nextDoc$fields === void 0 ? void 0 : _nextDoc$fields.forEach(function (field) {
|
|
405
453
|
if (field.file === fileId) fieldLookup[field._id] = field;
|
|
406
454
|
});
|
|
407
455
|
|
|
@@ -596,7 +644,7 @@ var duplicateDocumentPage = exports.duplicateDocumentPage = function duplicateDo
|
|
|
596
644
|
*/
|
|
597
645
|
var getMobileViewFromFile = exports.getMobileViewFromFile = function getMobileViewFromFile(file) {
|
|
598
646
|
var _file$views2;
|
|
599
|
-
var mobileViewIndex = file !== null && file !== void 0 && file.views && (file === null || file === void 0
|
|
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) {
|
|
600
648
|
return view.type === _FileViews["default"].mobile;
|
|
601
649
|
}) : -1;
|
|
602
650
|
if (mobileViewIndex !== -1) {
|
|
@@ -704,10 +752,10 @@ var generateMobilePageFieldPositions = exports.generateMobilePageFieldPositions
|
|
|
704
752
|
*/
|
|
705
753
|
var mergeAssoicatedFieldPositionsForMobilePage = exports.mergeAssoicatedFieldPositionsForMobilePage = function mergeAssoicatedFieldPositionsForMobilePage(fieldPositions) {
|
|
706
754
|
var filteredFieldPositions = [];
|
|
707
|
-
fieldPositions === null || fieldPositions === void 0
|
|
755
|
+
fieldPositions === null || fieldPositions === void 0 ? void 0 : fieldPositions.forEach(function (fieldPosition) {
|
|
708
756
|
var fieldPositionIndex = filteredFieldPositions.findIndex(function (filtered) {
|
|
709
757
|
var _filtered$field, _fieldPosition$field;
|
|
710
|
-
return (filtered === null || filtered === void 0
|
|
758
|
+
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());
|
|
711
759
|
});
|
|
712
760
|
|
|
713
761
|
//Only add field to the list if it hasn't already been added
|
package/dist/tableHelper.js
CHANGED
|
@@ -15,7 +15,8 @@ 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
|
|
18
|
+
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); }
|
|
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; }
|
|
19
20
|
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; }
|
|
20
21
|
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; }
|
|
21
22
|
var parser = new _hotFormulaParser.Parser();
|
|
@@ -389,9 +390,7 @@ var getDefaultImageColumn = exports.getDefaultImageColumn = function getDefaultI
|
|
|
389
390
|
type: _FieldTableColumnTypes["default"].image,
|
|
390
391
|
title: 'Image Column',
|
|
391
392
|
deleted: false,
|
|
392
|
-
width: 200
|
|
393
|
-
maxImageWidth: 190,
|
|
394
|
-
maxImageHeight: 120
|
|
393
|
+
width: 200
|
|
395
394
|
}, defaults);
|
|
396
395
|
};
|
|
397
396
|
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
10
|
+
// Check if value follows a valid readableId pattern for use in JavaScript formulas
|
|
11
|
+
// Note to test this please run npm test src/validateReadableId.test.js
|
|
12
|
+
|
|
13
|
+
// JavaScript reserved words and future reserved words
|
|
14
|
+
var JS_RESERVED_WORDS = new Set([
|
|
15
|
+
// ES6 Keywords
|
|
16
|
+
'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'else', 'export', 'extends', 'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof', 'new', 'return', 'super', 'switch', 'this', 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with', 'yield',
|
|
17
|
+
// ES6 Future Reserved Words
|
|
18
|
+
'enum', 'implements', 'interface', 'let', 'package', 'private', 'protected', 'public', 'static', 'await', 'async',
|
|
19
|
+
// Literals
|
|
20
|
+
'null', 'true', 'false', 'undefined', 'NaN', 'Infinity']);
|
|
21
|
+
|
|
22
|
+
// Common Excel function names (subset of most commonly used)
|
|
23
|
+
var EXCEL_FUNCTIONS = new Set([
|
|
24
|
+
// Math functions
|
|
25
|
+
'sum', 'average', 'count', 'max', 'min', 'round', 'roundup', 'rounddown', 'ceiling', 'floor', 'abs', 'sign', 'sqrt', 'power', 'exp', 'ln', 'log', 'log10', 'mod', 'quotient', 'product', 'sumif', 'countif', 'averageif', 'sumifs', 'countifs', 'averageifs', 'maxifs', 'minifs', 'subtotal', 'aggregate', 'rand', 'randbetween', 'pi', 'degrees', 'radians', 'fact', 'combin', 'permut', 'gcd', 'lcm', 'mround', 'multinomial', 'seriessum', 'sqrtpi', 'sumproduct', 'sumsq', 'sumx2my2', 'sumx2py2', 'sumxmy2',
|
|
26
|
+
// Text functions
|
|
27
|
+
'concatenate', 'concat', 'left', 'right', 'mid', 'len', 'lower', 'upper', 'proper', 'trim', 'substitute', 'replace', 'find', 'search', 'text', 'value', 'clean', 'code', 'char', 'exact', 'rept', 'fixed', 'dollar', 'textjoin', 'textbefore', 'textafter', 'textsplit', 'unichar', 'unicode',
|
|
28
|
+
// Date functions
|
|
29
|
+
'date', 'today', 'now', 'year', 'month', 'day', 'hour', 'minute', 'second', 'weekday', 'weeknum', 'datedif', 'datevalue', 'timevalue', 'days', 'days360', 'edate', 'eomonth', 'networkdays', 'workday', 'isoweeknum', 'yearfrac',
|
|
30
|
+
// Logical functions
|
|
31
|
+
'if', 'and', 'or', 'not', 'xor', 'iferror', 'ifna', 'ifs', 'switch', 'true', 'false',
|
|
32
|
+
// Lookup functions
|
|
33
|
+
'vlookup', 'hlookup', 'lookup', 'match', 'index', 'choose', 'offset', 'indirect', 'row', 'column', 'rows', 'columns', 'transpose', 'unique', 'filter', 'sort', 'sortby', 'xlookup', 'xmatch',
|
|
34
|
+
// Statistical functions
|
|
35
|
+
'median', 'mode', 'stdev', 'var', 'correl', 'forecast', 'trend', 'growth', 'linest', 'logest', 'slope', 'intercept', 'pearson', 'rsq', 'steyx', 'kurt', 'skew', 'rank', 'percentile', 'quartile', 'percentrank', 'large', 'small', 'standardize', 'ztest', 'ttest', 'ftest', 'chisq', 'norm', 'lognorm', 'expon', 'gamma', 'beta', 'binom', 'poisson', 'weibull', 'hypgeom', 'negbinom', 'geomean', 'harmean', 'devsq', 'avedev', 'confidence',
|
|
36
|
+
// Financial functions
|
|
37
|
+
'pv', 'fv', 'pmt', 'rate', 'nper', 'irr', 'npv', 'mirr', 'xirr', 'xnpv', 'sln', 'syd', 'ddb', 'vdb', 'ipmt', 'ppmt', 'cumipmt', 'cumprinc', 'price', 'yield', 'duration', 'mduration', 'disc', 'intrate', 'received', 'accrint', 'accrintm', 'coupdaybs', 'coupdays', 'coupdaysnc', 'coupncd', 'coupnum', 'couppcd', 'tbilleq', 'tbillprice', 'tbillyield',
|
|
38
|
+
// Information functions
|
|
39
|
+
'isblank', 'iserror', 'isna', 'isnumber', 'istext', 'islogical', 'isref', 'isformula', 'cell', 'info', 'type', 'na', 'error', 'iseven', 'isodd', 'n', 'sheet', 'sheets',
|
|
40
|
+
// Database functions
|
|
41
|
+
'dsum', 'daverage', 'dcount', 'dcounta', 'dmax', 'dmin', 'dproduct', 'dstdev', 'dstdevp', 'dvar', 'dvarp', 'dget',
|
|
42
|
+
// Engineering functions
|
|
43
|
+
'convert', 'bin2dec', 'bin2hex', 'bin2oct', 'dec2bin', 'dec2hex', 'dec2oct', 'hex2bin', 'hex2dec', 'hex2oct', 'oct2bin', 'oct2dec', 'oct2hex', 'complex', 'imabs', 'imaginary', 'imargument', 'imconjugate', 'imcos', 'imdiv', 'imexp', 'imln', 'imlog10', 'imlog2', 'impower', 'improduct', 'imreal', 'imsin', 'imsqrt', 'imsub', 'imsum', 'delta', 'erf', 'erfc', 'gestep', 'besseli', 'besselj', 'besselk', 'bessely',
|
|
44
|
+
// Array functions (newer)
|
|
45
|
+
'sequence', 'randarray', 'tocol', 'torow', 'wrapcols', 'wraprows', 'take', 'drop', 'expand', 'choosecols', 'chooserows', 'vstack', 'hstack']);
|
|
46
|
+
|
|
47
|
+
// JavaScript built-in object methods and properties
|
|
48
|
+
var JS_BUILTIN_NAMES = new Set([
|
|
49
|
+
// Number methods
|
|
50
|
+
'parseFloat', 'parseInt', 'isFinite', 'isInteger', 'isNaN', 'isSafeInteger', 'toExponential', 'toFixed', 'toPrecision', 'toString', 'valueOf',
|
|
51
|
+
// String methods
|
|
52
|
+
'charAt', 'charCodeAt', 'codePointAt', 'concat', 'endsWith', 'includes', 'indexOf', 'lastIndexOf', 'localeCompare', 'match', 'matchAll', 'normalize', 'padEnd', 'padStart', 'repeat', 'replace', 'replaceAll', 'search', 'slice', 'split', 'startsWith', 'substring', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimEnd', 'trimStart', 'length',
|
|
53
|
+
// Array methods
|
|
54
|
+
'from', 'isArray', 'of', 'concat', 'copyWithin', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'unshift', 'values',
|
|
55
|
+
// Object methods
|
|
56
|
+
'assign', 'create', 'defineProperties', 'defineProperty', 'entries', 'freeze', 'fromEntries', 'getOwnPropertyDescriptor', 'getOwnPropertyDescriptors', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'hasOwnProperty', 'is', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'preventExtensions', 'propertyIsEnumerable', 'seal', 'setPrototypeOf', 'values',
|
|
57
|
+
// Global properties
|
|
58
|
+
'constructor', 'prototype', '__proto__']);
|
|
59
|
+
|
|
60
|
+
// Custom reserved words from the spec
|
|
61
|
+
var CUSTOM_RESERVED_WORDS = new Set([
|
|
62
|
+
// Booleans
|
|
63
|
+
'checked', 'unchecked', 'enabled', 'disabled', 'on', 'off', 'yes', 'no',
|
|
64
|
+
// Self referencing
|
|
65
|
+
'current', 'self'
|
|
66
|
+
|
|
67
|
+
// Note: 'index' is already in EXCEL_FUNCTIONS, so it's not included here to avoid duplicate warnings
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
// Common JoyDoc properties (based on the codebase analysis)
|
|
71
|
+
var JOYDOC_PROPERTIES = new Set(['_id', 'identifier', 'name', 'type', 'files', 'fields', 'pages', 'pageOrder', 'fieldPositions', 'value', 'file', 'field', 'views', 'source', 'template', 'createdOn', 'updatedOn', 'deleted', 'width', 'height', 'rowHeight', 'cols', 'layout', 'presentation', 'padding', 'styles', 'margin', 'rowOrder', 'columnOrder', 'columns', 'rows', 'options', 'required', 'readOnly', 'disabled', 'hidden', 'validation', 'formula', 'format', 'placeholder', 'defaultValue', 'minValue', 'maxValue', 'minLength', 'maxLength', 'pattern', 'title', 'description', 'displayType', 'x', 'y', 'w', 'h']);
|
|
72
|
+
|
|
73
|
+
// Field types from FieldTypes.js
|
|
74
|
+
// Note: These are removed from validation because generateReadableId uses them as prefixes
|
|
75
|
+
// e.g., "text1", "number1", etc. The bare field type names should be allowed.
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Validates if a string can be used as a JavaScript identifier
|
|
79
|
+
* and doesn't conflict with reserved words
|
|
80
|
+
*
|
|
81
|
+
* @param {*} readableId - The ID to validate
|
|
82
|
+
* @returns {boolean} - True if valid, false otherwise
|
|
83
|
+
*/
|
|
84
|
+
var _default = exports["default"] = function _default(readableId) {
|
|
85
|
+
// Must be a non-empty string
|
|
86
|
+
if (typeof readableId !== 'string' || readableId.length === 0) {
|
|
87
|
+
console.warn("validateReadableId: Invalid input - expected non-empty string, got ".concat(typeof readableId === 'string' ? 'empty string' : (0, _typeof2["default"])(readableId)));
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Must not be parseable as a number (but check for Infinity as a special case)
|
|
92
|
+
if (readableId !== 'Infinity' && !isNaN(readableId)) {
|
|
93
|
+
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - cannot be a numeric value"));
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Must match the pattern: start with letter or underscore, followed by letters, numbers, or underscores
|
|
98
|
+
var identifierPattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
99
|
+
if (!identifierPattern.test(readableId)) {
|
|
100
|
+
if (/^[0-9]/.test(readableId)) {
|
|
101
|
+
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - identifiers cannot start with a number"));
|
|
102
|
+
} else if (/[^a-zA-Z0-9_]/.test(readableId)) {
|
|
103
|
+
var invalidChars = readableId.match(/[^a-zA-Z0-9_]/g);
|
|
104
|
+
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - contains invalid characters: ").concat((0, _toConsumableArray2["default"])(new Set(invalidChars)).join(', ')));
|
|
105
|
+
} else {
|
|
106
|
+
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - must start with a letter or underscore and contain only letters, numbers, and underscores"));
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Convert to lowercase for case-insensitive checking
|
|
112
|
+
var lowercaseId = readableId.toLowerCase();
|
|
113
|
+
|
|
114
|
+
// Check in order of precedence:
|
|
115
|
+
|
|
116
|
+
// 1. JavaScript reserved words (highest priority)
|
|
117
|
+
if (JS_RESERVED_WORDS.has(readableId) || JS_RESERVED_WORDS.has(lowercaseId)) {
|
|
118
|
+
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it's a JavaScript reserved word"));
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 2. JavaScript built-in names
|
|
123
|
+
if (JS_BUILTIN_NAMES.has(readableId)) {
|
|
124
|
+
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it's a JavaScript built-in method or property"));
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 3. JoyDoc properties
|
|
129
|
+
if (JOYDOC_PROPERTIES.has(readableId)) {
|
|
130
|
+
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it's a JoyDoc property name"));
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 4. Custom reserved words (lower priority than JoyDoc since 'index' can be more specific)
|
|
135
|
+
if (CUSTOM_RESERVED_WORDS.has(lowercaseId)) {
|
|
136
|
+
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it's a reserved word (boolean/self-referencing term)"));
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// 5. Excel functions (lowest priority since it has many general terms)
|
|
141
|
+
if (EXCEL_FUNCTIONS.has(lowercaseId)) {
|
|
142
|
+
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it's an Excel function name"));
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
return true;
|
|
146
|
+
};
|