/** * InsertrCore - Core functionality for content management */ export class InsertrCore { constructor(options = {}) { this.options = { apiEndpoint: options.apiEndpoint || '/api/content', siteId: options.siteId || 'default', ...options }; } // Find all enhanced elements on the page findEnhancedElements() { return document.querySelectorAll('.insertr, .insertr-add'); } // Get element metadata getElementMetadata(element) { const existingId = element.getAttribute('data-content-id'); const isCollection = element.classList.contains('insertr-add'); return { contentId: existingId, element: element, htmlMarkup: element.outerHTML, // Server will generate ID from this editorType: isCollection ? 'collection' : 'element' }; } // Get current file path from URL for consistent ID generation getCurrentFilePath() { const path = window.location.pathname; if (path === '/' || path === '') { return 'index.html'; } // Remove leading slash: "/about.html" → "about.html" return path.replace(/^\//, ''); } // Get all elements with their metadata getAllElements() { const elements = this.findEnhancedElements(); return Array.from(elements).map(el => this.getElementMetadata(el)); } }