@builttocreate/engine-utils 2.10.1-beta.593v2 → 2.10.1-beta.v593.10
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 +54 -5
- package/dist/validateReadableId.js +21 -1
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
@@ -8,6 +9,10 @@ exports.generateReadableTableColumnId = generateReadableTableColumnId;
|
|
|
8
9
|
exports.getFieldPositionsCount = getFieldPositionsCount;
|
|
9
10
|
exports.getFieldsCount = getFieldsCount;
|
|
10
11
|
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; }
|
|
11
16
|
/**
|
|
12
17
|
* Counts fields of a specific type in an array of fields
|
|
13
18
|
*
|
|
@@ -115,7 +120,17 @@ function generateReadableId(parts, type) {
|
|
|
115
120
|
// if (pages) count += getFieldPositionsCount(pages, type);
|
|
116
121
|
// if (views && views.length > 1) count += getViewsFieldPositionsCount(views, type);
|
|
117
122
|
|
|
118
|
-
|
|
123
|
+
var readableId = "".concat(type).concat(splitterId).concat(count + 1);
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* If the user drags one text field and renames it to text 2, we need to ensure
|
|
127
|
+
* the newly generatedId is different than text2
|
|
128
|
+
* */
|
|
129
|
+
|
|
130
|
+
fields.forEach(function (field) {
|
|
131
|
+
if (field._id === readableId) readableId = "".concat(type).concat(splitterId).concat(count + 2);
|
|
132
|
+
});
|
|
133
|
+
return readableId;
|
|
119
134
|
}
|
|
120
135
|
;
|
|
121
136
|
|
|
@@ -126,16 +141,50 @@ function generateReadableId(parts, type) {
|
|
|
126
141
|
* @param {Array} tableColumns - Array of table column objects
|
|
127
142
|
* @returns {String} - An ID in the format "{tableId}Column{count+1}" (e.g. "table1Column1")
|
|
128
143
|
*/
|
|
129
|
-
function generateReadableTableColumnId(tableId, tableColumns) {
|
|
144
|
+
function generateReadableTableColumnId(tableId, tableColumns, columnId) {
|
|
145
|
+
//Add logic that ensures that created Id is not a duplicate
|
|
130
146
|
if (!tableId) throw new Error('generateReadableTableColumnId: tableId is required');
|
|
147
|
+
if (!columnId) throw new Error('generateReadableTableColumnId: columnId is required');
|
|
131
148
|
if (!tableColumns || !Array.isArray(tableColumns)) {
|
|
149
|
+
console.warn('generateReadableTableColumnId: tableColumns parameter is missing or not an array');
|
|
132
150
|
return "".concat(tableId, "Column1");
|
|
133
151
|
}
|
|
152
|
+
var counts = {};
|
|
134
153
|
|
|
135
|
-
//
|
|
154
|
+
//Filter out undefined and null values from tableColumns
|
|
136
155
|
var validColumns = tableColumns.filter(function (column) {
|
|
137
156
|
return column !== undefined && column !== null;
|
|
138
157
|
});
|
|
139
|
-
var
|
|
140
|
-
|
|
158
|
+
var _iterator = _createForOfIteratorHelper(validColumns),
|
|
159
|
+
_step;
|
|
160
|
+
try {
|
|
161
|
+
var _loop = function _loop() {
|
|
162
|
+
var col = _step.value;
|
|
163
|
+
var type = (col.type || 'unknown').toLowerCase();
|
|
164
|
+
counts[type] = (counts[type] || 0) + 1;
|
|
165
|
+
var readableId = "".concat(type).concat(counts[type]);
|
|
166
|
+
if (col._id === columnId) {
|
|
167
|
+
/**
|
|
168
|
+
* If the user drags one text column it would have text1 as the id. If he renames it to text2, we
|
|
169
|
+
* need to esnure the newly generatedId is different than text2
|
|
170
|
+
*/
|
|
171
|
+
tableColumns.forEach(function (column) {
|
|
172
|
+
if (column._id === readableId) {
|
|
173
|
+
readableId = "".concat(type).concat(counts[type] + 1);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
return {
|
|
177
|
+
v: readableId
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
182
|
+
var _ret = _loop();
|
|
183
|
+
if ((0, _typeof2["default"])(_ret) === "object") return _ret.v;
|
|
184
|
+
}
|
|
185
|
+
} catch (err) {
|
|
186
|
+
_iterator.e(err);
|
|
187
|
+
} finally {
|
|
188
|
+
_iterator.f();
|
|
189
|
+
}
|
|
141
190
|
}
|
|
@@ -81,7 +81,7 @@ var JOYDOC_PROPERTIES = new Set(['_id', 'identifier', 'name', 'type', 'files', '
|
|
|
81
81
|
* @param {*} readableId - The ID to validate
|
|
82
82
|
* @returns {boolean} - True if valid, false otherwise
|
|
83
83
|
*/
|
|
84
|
-
var _default = exports["default"] = function _default(readableId) {
|
|
84
|
+
var _default = exports["default"] = function _default(readableId, fields, tableColumns) {
|
|
85
85
|
// Must be a non-empty string
|
|
86
86
|
if (typeof readableId !== 'string' || readableId.length === 0) {
|
|
87
87
|
console.warn("validateReadableId: Invalid input - expected non-empty string, got ".concat(typeof readableId === 'string' ? 'empty string' : (0, _typeof2["default"])(readableId)));
|
|
@@ -142,5 +142,25 @@ var _default = exports["default"] = function _default(readableId) {
|
|
|
142
142
|
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it's an Excel function name"));
|
|
143
143
|
return false;
|
|
144
144
|
}
|
|
145
|
+
|
|
146
|
+
//6. Check for duplicateIds
|
|
147
|
+
if (fields && Array.isArray(fields)) {
|
|
148
|
+
var duplicateField = fields.find(function (field) {
|
|
149
|
+
return field._id === readableId;
|
|
150
|
+
});
|
|
151
|
+
if (duplicateField) {
|
|
152
|
+
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it already exists in fields"));
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (tableColumns && Array.isArray(tableColumns)) {
|
|
157
|
+
var duplicateColumnId = tableColumns.find(function (column) {
|
|
158
|
+
return column._id === readableId;
|
|
159
|
+
});
|
|
160
|
+
if (duplicateColumnId) {
|
|
161
|
+
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it already exists in fields"));
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
145
165
|
return true;
|
|
146
166
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builttocreate/engine-utils",
|
|
3
|
-
"version": "2.10.1-beta.
|
|
3
|
+
"version": "2.10.1-beta.v593.10",
|
|
4
4
|
"description": "Utility library for common logic shared across web and mobile",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/zionlabs/engine-utils#readme",
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@babel/cli": "^7.
|
|
33
|
+
"@babel/cli": "^7.27.2",
|
|
34
34
|
"@babel/core": "^7.12.10",
|
|
35
35
|
"@babel/plugin-proposal-class-properties": "^7.12.1",
|
|
36
36
|
"@babel/plugin-transform-regenerator": "^7.12.1",
|