diff --git a/js/main.js b/js/main.js index f85c3c1..937904f 100644 --- a/js/main.js +++ b/js/main.js @@ -4,9 +4,10 @@ import { renderOutput } from './render.js'; import { renderPageMeta } from './page-settings.js'; -import './section-types.js'; +import { applyDefaultSkeleton } from './section-types.js'; import './tabs.js'; import './storage.js'; +applyDefaultSkeleton(); // Esqueleto de secciones de partida en vez de un panel en blanco. renderPageMeta(); -renderOutput(); // Pinta el mensaje de "sin secciones" nada más cargar la página. +renderOutput(); diff --git a/js/section-types.js b/js/section-types.js index a7a6c85..292b170 100644 --- a/js/section-types.js +++ b/js/section-types.js @@ -350,6 +350,36 @@ export function buildSectionsFrom(sectionsData, container = sectionsContainer) { sectionsData.forEach(sectionData => addSectionFromData(sectionData, container)); } +// Esqueleto de secciones con el que arranca la página (en el mismo formato +// que genera serializeSections()), a modo de plantilla de partida en vez +// de dejar el panel en blanco. Los grupos anidados salen "gratis": se +// reconstruyen recorriendo `children` a través de buildSectionsFrom(), el +// mismo mecanismo que restaura un patrón guardado. +const DEFAULT_SECTIONS = [ + { type: 'image', dataUrl: '' }, + { type: 'title', text: {} }, + { type: 'materials', materials: [] }, + { + type: 'group', + children: [ + { type: 'title', text: {} }, + { + type: 'group', + children: [ + { type: 'subtitle', text: {} }, + { type: 'dnd', items: [] }, + ], + }, + ], + }, +]; + +// Se llama una vez al arrancar (ver main.js); si ya hay secciones (p.ej. +// porque se ha cargado un patrón guardado antes de esto) no sustituye nada. +export function applyDefaultSkeleton() { + if (sectionsContainer.children.length === 0) buildSectionsFrom(DEFAULT_SECTIONS); +} + // Duplica `section`: la serializa (incluido su contenido si es un "Grupo") // y reconstruye una copia a partir de esos datos, insertándola justo // debajo de la original dentro del mismo contenedor (nivel superior, o el