Biete im Fließtext Schriftgröße, Schriftfarbe und Ausrichtung an
Deploy Test / test (push) Successful in 6m28s
CI Feature / test (push) Successful in 6m8s
Deploy Test / deploy (push) Successful in 41s

Das Webprofil von FormattedText kennt zusätzlich Ausrichtung (zentriert,
rechtsbündig), Schriftgröße (klein, groß, sehr groß) und Schriftfarbe
(Marine, Grün, Rot, Grau) aus festen Werten. Verwaltung, Dokumente und PDF
lassen sie weg. Der Editor des Fließtexts bekommt die Werkzeuge dafür
(eigene Erweiterung für die Größe); auf der Seite werden Klassen und
Tokens statt Inline-Stilen ausgegeben, Farben passen sich dunklen und
grünen Flächen an.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-26 14:41:41 +01:00
1 parent 28bd5590bc
commit 57f3a18b82
18 files changed
+565 -34

No files matched your search

+77
View File
@@ -0,0 +1,77 @@
<?php
namespace App\Filament\Support;
use App\Domain\Catalog\FormattedText;
use App\Filament\Support\TipTap\FontSizeExtension;
use Filament\Actions\Action;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\RichEditor\EditorCommand;
use Filament\Forms\Components\RichEditor\Plugins\Contracts\RichContentPlugin;
use Filament\Forms\Components\RichEditor\RichEditorTool;
use Filament\Forms\Components\Select;
use Filament\Support\Enums\Width;
/**
* Schriftgröße für die Texte der Website: ein Werkzeug „Schriftgröße“ mit festen Stufen (kein freies Maß), dazu das
* PHP-Modell und die JS-Erweiterung der Auszeichnung. Nur über {@see RichField::make()} mit `website: true`.
*/
final class FontSizePlugin implements RichContentPlugin
{
private const SCRIPT = 'js/rich-font-size.js';
public function getTipTapPhpExtensions(): array
{
return [new FontSizeExtension];
}
public function getTipTapJsExtensions(): array
{
$file = public_path(self::SCRIPT);
// Die Prüfsumme in der Adresse lässt den Browser eine geänderte Fassung sofort laden.
return [asset(self::SCRIPT).(is_file($file) ? '?v='.substr((string) md5_file($file), 0, 10) : '')];
}
public function getEditorTools(): array
{
return [
RichEditorTool::make('fontSize')
->label('Schriftgröße')
->action(arguments: '{ size: $getEditor().getAttributes(\'fontSize\')[\'data-size\'] ?? null }')
->toggle()
->icon('fi-o-lead'),
];
}
public function getEditorActions(): array
{
return [
Action::make('fontSize')
->label('Schriftgröße')
->modalHeading('Schriftgröße')
->modalWidth(Width::Large)
->fillForm(fn (array $arguments): array => ['size' => array_key_exists((string) ($arguments['size'] ?? ''), FormattedText::SITE_SIZES) ? $arguments['size'] : 'normal'])
->schema([
Select::make('size')
->label('Größe')
->options(['normal' => 'Normal', ...FormattedText::SITE_SIZES])
->native(false)
->required()
->helperText('Gilt für den markierten Text. „Normal“ nimmt die Auszeichnung zurück.'),
])
->action(function (array $arguments, array $data, RichEditor $component): void {
$collapsed = ($arguments['editorSelection']['head'] ?? null) === ($arguments['editorSelection']['anchor'] ?? null);
$size = (string) ($data['size'] ?? 'normal');
$extend = $collapsed ? [EditorCommand::make('extendMarkRange', arguments: ['fontSize'])] : [];
$component->runCommands(
array_key_exists($size, FormattedText::SITE_SIZES)
? [...$extend, EditorCommand::make('setFontSize', arguments: [['size' => $size]])]
: [...$extend, EditorCommand::make('unsetFontSize')],
editorSelection: $arguments['editorSelection'],
);
}),
];
}
}