feat: added default section skeleton
This commit is contained in:
+3
-2
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user