Loheide-eu-mitarbeiterplatt.../resources/js/pagebuilder/editor/tree.js
Friederich Loheide f3987e8386
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
Phase 4: Seiten mit Pagebuilder, Redaktion und Freigaben
- Seiten-Plugin: Seitenbaum mit Adressen, Seitennavigation, Brotkrumen und
  optional Hauptnavigation; Sichtbarkeit vererbt sich auf Unterseiten
- Pagebuilder (Block-Registry im Kern, Plugins tragen Blöcke bei): Abschnitt,
  Spalten, Tabs, Akkordeon, Box, Überschrift, Text (TipTap), Zitat,
  Schaltflächen, Symbolliste, Tabelle, Trennlinie, Abstand, Bild, Galerie,
  Video (erst nach Klick), Titelbild, Ansprechpartner, Downloads, Unterseiten,
  Neuigkeiten, Termine; Sichtbarkeit je Block; Bereinigung beim Speichern
- Editor im Portal: Ziehen und Ablegen, Autospeichern als Entwurf,
  Rückgängig, Gerätevorschau, Versionen, Zeitsteuerung, Bearbeitungssperre,
  Freigabe anfordern
- Rechte „inkl. Unterseiten“ werden im Rechte-Cache aufgelöst
- Neuigkeiten: Schreiben im Portal, Freigabe-Workflow mit Benachrichtigungen
- Bereich „Redaktion“, Benachrichtigungen im Portal
- storage/.migrations-fingerprint nicht mehr ausliefern

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 08:52:19 +00:00

86 lines
2.4 KiB
JavaScript

/**
* Hilfsfunktionen für den Blockbaum im Editor.
*/
export function uid() {
return Math.random().toString(36).slice(2, 8) + Date.now().toString(36).slice(-6);
}
export function clone(value) {
return JSON.parse(JSON.stringify(value));
}
function itemCount(type, data) {
if (!type.container) return 0;
if (type.key === 'columns') return (data.layout ?? '1-1').split('-').length;
if (type.key === 'tabs') return 2;
if (type.key === 'accordion') return 3;
return type.container.min;
}
export function createBlock(type) {
const data = clone(type.defaults ?? {});
const block = { id: uid(), type: type.key, data };
if (type.container) {
block.items = Array.from({ length: itemCount(type, data) }, (_, index) => ({
id: uid(),
title: type.container.titled ? `${type.container.label} ${index + 1}` : undefined,
blocks: [],
}));
}
return block;
}
/** Kopie mit neuen IDs (Duplizieren, Vorlagen). */
export function duplicate(block) {
const copy = clone(block);
const renew = (b) => {
b.id = uid();
(b.items ?? []).forEach((item) => {
item.id = uid();
item.blocks.forEach(renew);
});
};
renew(copy);
return copy;
}
/** Block im Baum finden: liefert Block, Liste und Position. */
export function locate(blocks, id, parent = null) {
for (let index = 0; index < blocks.length; index++) {
const block = blocks[index];
if (block.id === id) return { block, list: blocks, index, parent };
for (const item of block.items ?? []) {
const found = locate(item.blocks, id, block);
if (found) return found;
}
}
return null;
}
export function walk(blocks, callback) {
for (const block of blocks) {
callback(block);
(block.items ?? []).forEach((item) => walk(item.blocks, callback));
}
}
/** Anzahl der Spalten an die Aufteilung anpassen, ohne Inhalte zu verlieren. */
export function syncColumns(block) {
const count = (block.data.layout ?? '1-1').split('-').length;
while (block.items.length < count) {
block.items.push({ id: uid(), blocks: [] });
}
if (block.items.length > count) {
const overflow = block.items.splice(count).flatMap((item) => item.blocks);
block.items[count - 1].blocks.push(...overflow);
}
}