Implement live collection preview system with contextual template selection

Replace isolated template previews with live collection reconstruction:
- Frontend now reconstructs collection container with all template variants
- Users click directly on rendered templates in proper CSS context
- Perfect preservation of grid/flex layouts and responsive behavior
- Simplified API: preview endpoint returns container_html + templates for frontend reconstruction
- Enhanced UX: WYSIWYG template selection shows exactly what will be added
- Removed redundant templates endpoint in favor of unified preview approach

Backend changes:
- Add GET /api/collections/{id}/preview endpoint
- Remove GET /api/collections/{id}/templates endpoint
- Return container HTML + templates for frontend reconstruction

Frontend changes:
- Replace isolated template modal with live collection preview
- Add generateLivePreview() method for container reconstruction
- Update CollectionManager to use preview API
- Add interactive CSS styling for template selection

This provides true contextual template selection where CSS inheritance,
grid layouts, and responsive design work perfectly in preview mode.
This commit is contained in:
2025-10-31 22:41:12 +01:00
parent 81ec8edf36
commit 163cbf7eea
4 changed files with 273 additions and 106 deletions

View File

@@ -243,25 +243,25 @@ export class ApiClient {
}
/**
* Get available templates for a collection
* Get collection preview data (container + templates for frontend reconstruction)
* @param {string} collectionId - Collection ID
* @returns {Promise<Array>} Array of collection templates
* @returns {Promise<Object>} Object with collection_id, container_html, and templates
*/
async getCollectionTemplates(collectionId) {
async getCollectionPreview(collectionId) {
try {
const collectionsUrl = this.getCollectionsUrl();
const response = await fetch(`${collectionsUrl}/${collectionId}/templates?site_id=${this.siteId}`);
const response = await fetch(`${collectionsUrl}/${collectionId}/preview?site_id=${this.siteId}`);
if (response.ok) {
const result = await response.json();
return result.templates || [];
return result;
} else {
console.warn(`⚠️ Failed to fetch collection templates (${response.status}): ${collectionId}`);
return [];
console.warn(`⚠️ Failed to fetch collection preview (${response.status}): ${collectionId}`);
return null;
}
} catch (error) {
console.error('Failed to fetch collection templates:', collectionId, error);
return [];
console.error('Failed to fetch collection preview:', collectionId, error);
return null;
}
}