@builttocreate/engine-utils 2.10.1-beta.v593.26 → 2.10.1-beta.v593.27

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.
@@ -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,10 +8,6 @@ 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
  *
@@ -115,28 +110,9 @@ function generateReadableId(parts, type) {
115
110
  }
116
111
  if (!fields) console.warn('generateReadableId: fields parameter is missing');
117
112
 
118
- // let count = 0;
119
-
120
- // if (fields) count += getFieldsCount(fields, type);
121
- // // Note: leaving for now until we allow targeting fieldPositions
122
- // // if (pages) count += getFieldPositionsCount(pages, type);
123
- // // if (views && views.length > 1) count += getViewsFieldPositionsCount(views, type);
124
-
125
- // let readableId = `${type}${splitterId}${count + 1}`
126
- // count++;
127
-
128
- // /**
129
- // * If the user drags one text field and renames it to text 2, we need to ensure
130
- // * the newly generatedId is different than text2
131
- // * */
132
-
133
- // fields.forEach((field ) => {
134
-
135
- // if(field._id === readableId) readableId = `${type}${splitterId}${count + 1}`
136
-
137
- // })
138
-
139
- // return readableId;
113
+ // Note: leaving for now until we allow targeting fieldPositions
114
+ // if (pages) count += getFieldPositionsCount(pages, type);
115
+ // if (views && views.length > 1) count += getViewsFieldPositionsCount(views, type);
140
116
 
141
117
  var count = fields.length ? getFieldsCount(fields, type) : 0;
142
118
  var readableId = "".concat(type).concat(splitterId).concat(count + 1);
@@ -165,43 +141,53 @@ function generateReadableTableColumnId(tableId, tableColumns, columnId) {
165
141
  console.warn('generateReadableTableColumnId: tableColumns parameter is missing or not an array');
166
142
  return "".concat(tableId, "Column1");
167
143
  }
168
- var counts = {};
169
144
 
170
- //Filter out undefined and null values from tableColumns
171
- var validColumns = tableColumns.filter(function (column) {
172
- return column !== undefined && column !== null;
145
+ // const counts = {};
146
+
147
+ // //Filter out undefined and null values from tableColumns
148
+ // const validColumns = tableColumns.filter(column => column !== undefined && column !== null);
149
+
150
+ // for (const col of validColumns) {
151
+
152
+ // const type = (col.type || 'unknown').toLowerCase();
153
+
154
+ // counts[type] = (counts[type] || 0) + 1;
155
+
156
+ // let readableId = `${type}${counts[type]}`
157
+
158
+ // if (col._id === columnId) {
159
+
160
+ // /**
161
+ // * If the generatedReadableId is already present in the tableColumns,
162
+ // * we need to increment the count until we find a unique ID.
163
+ // * This ensures that the new column ID is unique.
164
+ // */
165
+ // validColumns.forEach((column) => {
166
+ // if (column._id === readableId) {
167
+ // readableId = `${type}${counts[type] + 1}`;
168
+ // }
169
+ // });
170
+
171
+ // return readableId;
172
+
173
+ // }
174
+ // }
175
+
176
+ var validColumns = tableColumns.filter(Boolean);
177
+ var targetColumn = validColumns.find(function (col) {
178
+ return col._id === columnId;
173
179
  });
174
- var _iterator = _createForOfIteratorHelper(validColumns),
175
- _step;
176
- try {
177
- var _loop = function _loop() {
178
- var col = _step.value;
179
- var type = (col.type || 'unknown').toLowerCase();
180
- counts[type] = (counts[type] || 0) + 1;
181
- var readableId = "".concat(type).concat(counts[type]);
182
- if (col._id === columnId) {
183
- /**
184
- * If the generatedReadableId is already present in the tableColumns,
185
- * we need to increment the count until we find a unique ID.
186
- * This ensures that the new column ID is unique.
187
- */
188
- validColumns.forEach(function (column) {
189
- if (column._id === readableId) {
190
- readableId = "".concat(type).concat(counts[type] + 1);
191
- }
192
- });
193
- return {
194
- v: readableId
195
- };
196
- }
197
- };
198
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
199
- var _ret = _loop();
200
- if ((0, _typeof2["default"])(_ret) === "object") return _ret.v;
201
- }
202
- } catch (err) {
203
- _iterator.e(err);
204
- } finally {
205
- _iterator.f();
180
+ var type = ((targetColumn === null || targetColumn === void 0 ? void 0 : targetColumn.type) || 'unknown').toLowerCase();
181
+ var count = validColumns.filter(function (col) {
182
+ return (col.type || 'unknown').toLowerCase() === type;
183
+ }).length;
184
+ var readableId = "".concat(type).concat(count + 1);
185
+ var existingIds = new Set(validColumns.map(function (col) {
186
+ return col._id;
187
+ }));
188
+ while (existingIds.has(readableId)) {
189
+ count++;
190
+ readableId = "".concat(type).concat(count + 1);
206
191
  }
192
+ return readableId;
207
193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builttocreate/engine-utils",
3
- "version": "2.10.1-beta.v593.26",
3
+ "version": "2.10.1-beta.v593.27",
4
4
  "description": "Utility library for common logic shared across web and mobile",
5
5
  "main": "dist/index.js",
6
6
  "files": [