Fix collection manager JavaScript errors after attribute naming changes
- Update collection manager to use data-collection-id instead of data-content-id - Add safety checks to prevent undefined Map access in addItemControls - Add validation in editor to only initialize collections with valid collection IDs - Resolves TypeError and missing attribute errors in frontend collection management
This commit is contained in:
1
lib/package-lock.json
generated
1
lib/package-lock.json
generated
@@ -311,6 +311,7 @@
|
||||
"integrity": "sha512-GVsDdsbJzzy4S/v3dqWPJ7EfvZJfCHiDqe80IyrF59LYuP+e6U1LJoUqeuqRbwAWoMNoXivMNeNAOf5E22VA1w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"rollup": "dist/bin/rollup"
|
||||
},
|
||||
|
||||
@@ -79,7 +79,9 @@ export class InsertrEditor {
|
||||
|
||||
initializeCollection(meta) {
|
||||
const collectionManager = new CollectionManager(meta, this.apiClient, this.auth);
|
||||
collectionManager.initialize();
|
||||
if (collectionManager.collectionId) {
|
||||
collectionManager.initialize();
|
||||
}
|
||||
}
|
||||
|
||||
addClickHandler(element, meta) {
|
||||
|
||||
@@ -18,9 +18,9 @@ export class CollectionManager {
|
||||
this.auth = auth;
|
||||
|
||||
// Extract collection ID from container
|
||||
this.collectionId = this.container.getAttribute('data-content-id');
|
||||
this.collectionId = this.container.getAttribute('data-collection-id');
|
||||
if (!this.collectionId) {
|
||||
console.error('❌ Collection container missing data-content-id attribute');
|
||||
console.error('❌ Collection container missing data-collection-id attribute');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ export class CollectionManager {
|
||||
* Add management controls to an item (remove, reorder)
|
||||
*/
|
||||
addItemControls(itemElement, index) {
|
||||
if (this.itemControls.has(itemElement)) return; // Already has controls
|
||||
if (!this.itemControls || this.itemControls.has(itemElement)) return; // Already has controls or not initialized
|
||||
|
||||
const controls = document.createElement('div');
|
||||
controls.className = 'insertr-item-controls';
|
||||
|
||||
Reference in New Issue
Block a user