/** * 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 // Note: Container expansion is handled at build-time by the backend enhancer // Frontend should only find elements that already have .insertr class findEnhancedElements() { return document.querySelectorAll('.insertr'); } // Note: All container expansion logic removed - handled by backend enhancer // Frontend only works with elements that already have .insertr class // Get element metadata getElementMetadata(element) { const existingId = element.getAttribute('data-content-id'); // HTML-first approach: no content type needed, just HTML markup for ID generation return { contentId: existingId, // null if new content, existing ID if updating element: element, htmlMarkup: element.outerHTML // Server will generate ID from this }; } // 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 // Note: Container expansion handled by backend - frontend finds enhanced elements only getAllElements() { const elements = this.findEnhancedElements(); return Array.from(elements).map(el => this.getElementMetadata(el)); } }