From 03ebcde85a19fb04d6d7ae300cdc718e4a57918d Mon Sep 17 00:00:00 2001 From: Jyrki De Neve Date: Fri, 30 May 2025 13:41:56 +0300 Subject: [PATCH 1/4] Start with Filament v4 upgrade, but some todos still need to be checked --- composer.json | 12 +- phpstan-baseline.neon | 10 +- src/Filament/Architect/CardBlock.php | 4 +- src/Filament/Architect/MediaBlock.php | 2 +- src/Filament/Architect/MediaTextBlock.php | 4 +- src/Filament/Architect/TableBlock.php | 5 +- src/Filament/Architect/TextBlock.php | 8 +- src/Filament/Architect/VideoTextBlock.php | 4 +- src/Filament/Components/ButtonComponent.php | 18 +- src/Filament/Components/TrackingComponent.php | 4 +- src/Filament/Fields/ArchitectInput.php | 207 +++++++++++------- .../Fields/Traits/HasDuplicateAction.php | 6 +- .../Fields/Traits/HasToggleButton.php | 8 +- src/Filament/Pages/ArchitectTest.php | 16 +- .../Resources/ArchitectTemplateResource.php | 16 +- src/Livewire/EditModal.php | 8 +- .../Filament/Architect/MediaTextBlockTest.php | 3 +- .../Filament/Architect/TableBlockTest.php | 4 +- .../Filament/Architect/TextBlockTest.php | 3 +- .../Filament/Architect/VideoBlockTest.php | 3 +- .../Filament/Architect/VideoTextBlockTest.php | 8 +- tests/TestCase.php | 5 - 22 files changed, 191 insertions(+), 167 deletions(-) diff --git a/composer.json b/composer.json index e872d08..3260e98 100644 --- a/composer.json +++ b/composer.json @@ -10,18 +10,18 @@ "license": "MIT", "require": { "php": "^8.2", - "awcodes/filament-tiptap-editor": "^3.2", - "codedor/filament-image-or-video": "^1.1", - "codedor/filament-link-picker": "^1.6", - "codedor/filament-media-library": "^2.0|^3.0", - "filament/filament": "^3.1", + "codedor/filament-image-or-video": "dev-feature/filament-v4", + "codedor/filament-link-picker": "dev-feature/filament-v4", + "codedor/filament-media-library": "dev-feature/filament-v4", + "filament/filament": "^4.0", "illuminate/contracts": "^10.0|^11.0|^12.0", "spatie/laravel-package-tools": "^1.12" }, "require-dev": { + "filament/upgrade": "^4.0", + "larastan/larastan": "^2.0|^3.0", "laravel/pint": "^1.0", "nunomaduro/collision": "^7.0|^8.0", - "larastan/larastan": "^2.0|^3.0", "orchestra/testbench": "^8.0|^9.0|^10.0", "pestphp/pest": "^2.0|^3.0", "pestphp/pest-plugin-laravel": "^2.0|^3.0", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 758941c..8b3707e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4,10 +4,6 @@ parameters: message: "#^Access to an undefined property Codedor\\\\FilamentArchitect\\\\Livewire\\\\EditModal\\:\\:\\$form.$#" count: 3 path: src/Livewire/EditModal.php - - - message: "#^Access to an undefined property Filament\\\\Forms\\\\Contracts\\\\HasForms\\:\\:\\$mountedFormComponentActionsArguments.$#" - count: 1 - path: src/Filament/Fields/ArchitectInput.php - message: "#^Unsafe usage of new static\\(\\).$#" count: 1 @@ -17,7 +13,7 @@ parameters: count: 1 path: src/Filament/Architect/BaseBlock.php - - message: "#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\Collection\\\\:\\:map\\(\\) expects callable\\(int, int\\)\\: FilamentTiptapEditor\\\\TiptapEditor, Closure\\(string\\)\\: FilamentTiptapEditor\\\\TiptapEditor given.$#" + message: "#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\Collection\\\\:\\:map\\(\\) expects callable\\(int, int\\)\\: Filament\\\\Forms\\\\Components\\\\RichEditor, Closure\\(string\\)\\: Filament\\\\Forms\\\\Components\\\\RichEditor given.$#" count: 1 path: src/Filament/Architect/TextBlock.php - @@ -32,10 +28,6 @@ parameters: message: "#^Parameter \\#1 \\$view of function view expects view-string\\|null, string given.$#" count: 1 path: src/Filament/Fields/ArchitectInput.php - - - message: "#^Property Codedor\\\\FilamentArchitect\\\\Filament\\\\Fields\\\\ArchitectInput\\:\\:\\$view \\(view-string\\) does not accept default value of type string.$#" - count: 1 - path: src/Filament/Fields/ArchitectInput.php - message: "#^Parameter \\#1 \\$view of method Filament\\\\Support\\\\Components\\\\ViewComponent\\:\\:view\\(\\) expects view-string\\|null, string given.$#" count: 1 diff --git a/src/Filament/Architect/CardBlock.php b/src/Filament/Architect/CardBlock.php index 6c48e82..bbf8296 100644 --- a/src/Filament/Architect/CardBlock.php +++ b/src/Filament/Architect/CardBlock.php @@ -7,8 +7,8 @@ use Codedor\MediaLibrary\Filament\AttachmentInput; use Codedor\MediaLibrary\Models\Attachment; use Filament\Forms\Components\Repeater; +use Filament\Forms\Components\RichEditor; use Filament\Forms\Components\TextInput; -use FilamentTiptapEditor\TiptapEditor; use Illuminate\View\View; class CardBlock extends BaseBlock @@ -35,7 +35,7 @@ public function schema(): array TextInput::make('title') ->required(), - TiptapEditor::make('description'), + RichEditor::make('description'), AttachmentInput::make('image') ->allowedFormats(ArchitectFormats::get()), diff --git a/src/Filament/Architect/MediaBlock.php b/src/Filament/Architect/MediaBlock.php index ce2caca..b66eed1 100644 --- a/src/Filament/Architect/MediaBlock.php +++ b/src/Filament/Architect/MediaBlock.php @@ -29,7 +29,7 @@ public function schema(): array Radio::make('width') ->visible((bool) ArchitectConfig::getWidthOptionsEnum()) ->required() - ->options(function (Get $get) { + ->options(function (\Filament\Schemas\Components\Utilities\Get $get) { $enum = ArchitectConfig::getWidthOptionsEnum(); if (! $enum) { diff --git a/src/Filament/Architect/MediaTextBlock.php b/src/Filament/Architect/MediaTextBlock.php index aeb414c..1517f73 100644 --- a/src/Filament/Architect/MediaTextBlock.php +++ b/src/Filament/Architect/MediaTextBlock.php @@ -6,7 +6,7 @@ use Codedor\MediaLibrary\Filament\AttachmentInput; use Codedor\MediaLibrary\Models\Attachment; use Filament\Forms\Components\Radio; -use FilamentTiptapEditor\TiptapEditor; +use Filament\Forms\Components\RichEditor; use Illuminate\View\View; class MediaTextBlock extends BaseBlock @@ -36,7 +36,7 @@ public function schema(): array ->allowedFormats(ArchitectFormats::get()) ->required(), - TiptapEditor::make('description') + RichEditor::make('description') ->label('Text to display'), ]; } diff --git a/src/Filament/Architect/TableBlock.php b/src/Filament/Architect/TableBlock.php index 6353389..f1aa947 100644 --- a/src/Filament/Architect/TableBlock.php +++ b/src/Filament/Architect/TableBlock.php @@ -2,7 +2,7 @@ namespace Codedor\FilamentArchitect\Filament\Architect; -use FilamentTiptapEditor\TiptapEditor; +use Filament\Forms\Components\RichEditor; use Illuminate\View\View; class TableBlock extends BaseBlock @@ -17,8 +17,7 @@ public function render(array $data): ?View public function schema(): array { return [ - TiptapEditor::make('table') - ->disableBubbleMenus(false) + RichEditor::make('table') ->required(), ]; } diff --git a/src/Filament/Architect/TextBlock.php b/src/Filament/Architect/TextBlock.php index cb87eba..25a7e08 100644 --- a/src/Filament/Architect/TextBlock.php +++ b/src/Filament/Architect/TextBlock.php @@ -2,10 +2,8 @@ namespace Codedor\FilamentArchitect\Filament\Architect; -use Filament\Forms\Components\Grid; +use Filament\Forms\Components\RichEditor; use Filament\Forms\Components\TextInput; -use Filament\Forms\Get; -use FilamentTiptapEditor\TiptapEditor; use Illuminate\Support\HtmlString; use Illuminate\View\View; @@ -34,12 +32,12 @@ public function schema(): array ->maxValue(3) ->extraInputAttributes(['min' => 1, 'max' => 3]), - Grid::make(1)->schema(function (Get $get) { + \Filament\Schemas\Components\Grid::make(1)->schema(function (\Filament\Schemas\Components\Utilities\Get $get) { return collect() ->pad($get('columns') ?? 1, null) ->keys() ->map(function (string $key) { - return TiptapEditor::make("text.{$key}") + return RichEditor::make("text.{$key}") ->label('Text'); }) ->toArray(); diff --git a/src/Filament/Architect/VideoTextBlock.php b/src/Filament/Architect/VideoTextBlock.php index 4984c4e..5e16bba 100644 --- a/src/Filament/Architect/VideoTextBlock.php +++ b/src/Filament/Architect/VideoTextBlock.php @@ -4,7 +4,7 @@ use Codedor\FilamentImageOrVideo\Filament\Components\VideoEmbed; use Filament\Forms\Components\Radio; -use FilamentTiptapEditor\TiptapEditor; +use Filament\Forms\Components\RichEditor; use Illuminate\View\View; class VideoTextBlock extends BaseBlock @@ -30,7 +30,7 @@ public function schema(): array VideoEmbed::make('video'), - TiptapEditor::make('description') + RichEditor::make('description') ->label('Text') ->required(), ]; diff --git a/src/Filament/Components/ButtonComponent.php b/src/Filament/Components/ButtonComponent.php index 0ae0215..b22bbfd 100644 --- a/src/Filament/Components/ButtonComponent.php +++ b/src/Filament/Components/ButtonComponent.php @@ -14,24 +14,24 @@ class ButtonComponent { - public static function make(string $statePath): Component + public static function make(string $statePath): \Filament\Schemas\Components\Component { return ViewField::make($statePath) ->view('filament-architect::components.button-field') ->registerActions([ - Action::make('addButton') - ->label(function (Get $get) use ($statePath) { + \Filament\Actions\Action::make('addButton') + ->label(function (\Filament\Schemas\Components\Utilities\Get $get) use ($statePath) { $currentText = $get("{$statePath}.text"); return $currentText ? $currentText : 'Button'; }) - ->icon(function (Get $get) use ($statePath) { + ->icon(function (\Filament\Schemas\Components\Utilities\Get $get) use ($statePath) { $currentText = $get("{$statePath}.text"); return $currentText ? 'heroicon-o-pencil' : 'heroicon-o-plus'; }) - ->fillForm(fn (Get $get) => $get($statePath)) - ->form([ + ->fillForm(fn (\Filament\Schemas\Components\Utilities\Get $get) => $get($statePath)) + ->schema([ TextInput::make('text') ->label('Text on the button') ->required(), @@ -48,14 +48,14 @@ public static function make(string $statePath): Component TrackingComponent::make(), ]) - ->action(function ($data, Set $set) use ($statePath) { + ->action(function ($data, \Filament\Schemas\Components\Utilities\Set $set) use ($statePath) { $set($statePath, $data); }), - Action::make('removeButton') + \Filament\Actions\Action::make('removeButton') ->color('danger') ->label(__('Remove button')) ->icon('heroicon-o-trash') - ->action(fn ($data, Set $set) => $set($statePath, [])), + ->action(fn ($data, \Filament\Schemas\Components\Utilities\Set $set) => $set($statePath, [])), ]); } } diff --git a/src/Filament/Components/TrackingComponent.php b/src/Filament/Components/TrackingComponent.php index bc33a39..2492f8d 100644 --- a/src/Filament/Components/TrackingComponent.php +++ b/src/Filament/Components/TrackingComponent.php @@ -11,9 +11,9 @@ class TrackingComponent { - public static function make(): Component + public static function make(): \Filament\Schemas\Components\Component { - return Section::make('Tracking information') + return \Filament\Schemas\Components\Section::make('Tracking information') ->statePath('tracking') ->collapsed() ->columns(2) diff --git a/src/Filament/Fields/ArchitectInput.php b/src/Filament/Fields/ArchitectInput.php index 77ebad7..571b6df 100644 --- a/src/Filament/Fields/ArchitectInput.php +++ b/src/Filament/Fields/ArchitectInput.php @@ -9,14 +9,14 @@ use Codedor\FilamentArchitect\Filament\Fields\Traits\HasToggleButton; use Codedor\FilamentArchitect\Models\ArchitectTemplate; use Codedor\LocaleCollection\Facades\LocaleCollection; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; use Filament\Forms\Components\Field; use Filament\Forms\Components\Radio; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Forms\Get; use Filament\Notifications\Notification; -use Filament\Support\Enums\ActionSize; +use Filament\Support\Components\Attributes\ExposedLivewireMethod; use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Str; @@ -29,7 +29,9 @@ class ArchitectInput extends Field protected string $view = 'filament-architect::architect-input'; public null|Closure|iterable $blocks = null; + public Closure|iterable $excludedBlocks = []; + public Closure|iterable $extraBlocks = []; public null|Closure|iterable $locales = null; @@ -37,6 +39,7 @@ class ArchitectInput extends Field public null|int|Closure $maxFieldsPerRow = 1; public Closure|bool $hasTemplates = true; + public Closure|bool $hasPreview = true; protected function setUp(): void @@ -49,71 +52,72 @@ protected function setUp(): void $this->default([]); $this->registerActions([ - fn (self $component): Action => $component->getArchitectPreviewAction(), - fn (self $component): Action => $component->getStartFromTemplateAction(), - fn (self $component): Action => $component->getSaveAsTemplateAction(), - fn (self $component): Action => $component->getAddBlockAction(), - fn (self $component): Action => $component->getAddBlockBetweenAction(), - fn (self $component): Action => $component->getDuplicateAction(), - fn (self $component): Action => $component->getDisableBlockAction(), - fn (self $component): Action => $component->getEnableBlockAction(), - fn (self $component): Action => $component->getEditBlockAction(), - fn (self $component): Action => $component->getDeleteBlockAction(), + fn (self $component): \Filament\Actions\Action => $component->getArchitectPreviewAction(), + fn (self $component): \Filament\Actions\Action => $component->getStartFromTemplateAction(), + fn (self $component): \Filament\Actions\Action => $component->getSaveAsTemplateAction(), + fn (self $component): \Filament\Actions\Action => $component->getAddBlockAction(), + fn (self $component): \Filament\Actions\Action => $component->getAddBlockBetweenAction(), + fn (self $component): \Filament\Actions\Action => $component->getDuplicateAction(), + fn (self $component): \Filament\Actions\Action => $component->getDisableBlockAction(), + fn (self $component): \Filament\Actions\Action => $component->getEnableBlockAction(), + fn (self $component): \Filament\Actions\Action => $component->getEditBlockAction(), + fn (self $component): \Filament\Actions\Action => $component->getDeleteBlockAction(), ]); - $this->registerListeners([ - 'filament-architect::editedBlock' => [ - function (self $component, string $statePath, array $arguments): void { - if ($statePath !== $component->getStatePath()) { - return; - } - - $items = $component->getState(); - $items[$arguments['row']][$arguments['uuid']]['data'] = $arguments['form']['state']; - $component->state($items); - }, - ], - 'reorder-row' => [ - function (self $component, string $statePath, array $data): void { - if ($statePath !== $component->getStatePath()) { - return; - } - - $items = $component->getState(); - - $items = collect($items) - ->sortBy(fn ($item, $key) => array_search($key, $data['newKeys'])) - ->values() - ->toArray(); - - $component->state($items); - }, - ], - 'reorder-column' => [ - function (self $component, string $statePath, array $data): void { - if ($statePath !== $component->getStatePath()) { - return; - } - - $items = $component->getState(); - - $items[$data['row']] = collect($items[$data['row']]) - ->sortBy(fn ($item, $key) => array_search($key, $data['newKeys'])) - ->toArray(); - - $component->state($items); - }, - ], - ]); + // TODO: moved to dedicated method, but still to check how we have to dispatch these events in the blade files + // $this->registerListeners([ + // 'filament-architect::editedBlock' => [ + // function (self $component, string $statePath, array $arguments): void { + // if ($statePath !== $component->getStatePath()) { + // return; + // } + // + // $items = $component->getState(); + // $items[$arguments['row']][$arguments['uuid']]['data'] = $arguments['form']['state']; + // $component->state($items); + // }, + // ], + // 'reorder-row' => [ + // function (self $component, string $statePath, array $data): void { + // if ($statePath !== $component->getStatePath()) { + // return; + // } + // + // $items = $component->getState(); + // + // $items = collect($items) + // ->sortBy(fn ($item, $key) => array_search($key, $data['newKeys'])) + // ->values() + // ->toArray(); + // + // $component->state($items); + // }, + // ], + // 'reorder-column' => [ + // function (self $component, string $statePath, array $data): void { + // if ($statePath !== $component->getStatePath()) { + // return; + // } + // + // $items = $component->getState(); + // + // $items[$data['row']] = collect($items[$data['row']]) + // ->sortBy(fn ($item, $key) => array_search($key, $data['newKeys'])) + // ->toArray(); + // + // $component->state($items); + // }, + // ], + // ]); } - public function getArchitectPreviewAction(): Action + public function getArchitectPreviewAction(): \Filament\Actions\Action { - return Action::make('architectPreview') + return \Filament\Actions\Action::make('architectPreview') ->icon('heroicon-o-eye') ->label("Preview {$this->getName()}") ->color('gray') - ->size(ActionSize::Small) + ->size(\Filament\Support\Enums\Size::Small) ->extraAttributes([ 'target' => '_blank', 'class' => 'dark:hover:!bg-gray-700/100 dark:!bg-gray-800' . (! ArchitectConfig::getPreviewAction() ? 'hidden' : ''), @@ -121,16 +125,16 @@ public function getArchitectPreviewAction(): Action ->url(ArchitectConfig::getPreviewAction()); } - public function getStartFromTemplateAction(): Action + public function getStartFromTemplateAction(): \Filament\Actions\Action { - return Action::make('startFromTemplate') + return \Filament\Actions\Action::make('startFromTemplate') ->icon('heroicon-o-document-duplicate') ->label('Start from template') ->color('gray') - ->size(ActionSize::Small) + ->size(\Filament\Support\Enums\Size::Small) ->closeModalByClickingAway(false) ->hidden(fn () => ! ((bool) ArchitectTemplate::count())) - ->form(fn () => [ + ->schema(fn () => [ Select::make('block') ->options(fn () => ArchitectTemplate::orderBy('name')->pluck('name', 'id')) ->hiddenLabel() @@ -151,17 +155,17 @@ public function getStartFromTemplateAction(): Action ]); } - public function getSaveAsTemplateAction(): Action + public function getSaveAsTemplateAction(): \Filament\Actions\Action { - return Action::make('saveAsTemplate') + return \Filament\Actions\Action::make('saveAsTemplate') ->icon('heroicon-o-document-duplicate') - ->label("Save as template") + ->label('Save as template') ->color('gray') - ->size(ActionSize::Small) + ->size(\Filament\Support\Enums\Size::Small) ->extraAttributes([ - 'class' => 'dark:hover:!bg-gray-700/100 dark:!bg-gray-800' + 'class' => 'dark:hover:!bg-gray-700/100 dark:!bg-gray-800', ]) - ->form(fn () => [ + ->schema(fn () => [ Radio::make('new_overwrite') ->hiddenLabel() ->default('new') @@ -174,13 +178,13 @@ public function getSaveAsTemplateAction(): Action TextInput::make('name') ->label('Template name') ->helperText('Make sure the name is unique and descriptive') - ->hidden(fn (Get $get) => $get('new_overwrite') === 'overwrite') + ->hidden(fn (\Filament\Schemas\Components\Utilities\Get $get) => $get('new_overwrite') === 'overwrite') ->required(), Select::make('template') ->label('Template to overwrite') ->options(fn () => ArchitectTemplate::orderBy('name')->pluck('name', 'id')) - ->hidden(fn (Get $get) => $get('new_overwrite') === 'new') + ->hidden(fn (\Filament\Schemas\Components\Utilities\Get $get) => $get('new_overwrite') === 'new') ->required(), ]) ->action(function (array $data) { @@ -202,13 +206,13 @@ public function getSaveAsTemplateAction(): Action }); } - public function getDeleteBlockAction(): Action + public function getDeleteBlockAction(): \Filament\Actions\Action { - return Action::make('deleteBlock') + return \Filament\Actions\Action::make('deleteBlock') ->icon('heroicon-o-trash') ->hiddenLabel() ->color('danger') - ->size(ActionSize::Small) + ->size(\Filament\Support\Enums\Size::Small) ->closeModalByClickingAway(false) ->requiresConfirmation() ->action(function (self $component, array $arguments) { @@ -226,36 +230,36 @@ public function getDeleteBlockAction(): Action }); } - public function getEditBlockAction(): Action + public function getEditBlockAction(): \Filament\Actions\Action { - return Action::make('editBlock') + return \Filament\Actions\Action::make('editBlock') ->icon('heroicon-o-pencil') ->hiddenLabel() ->color('gray') - ->size(ActionSize::Small) + ->size(\Filament\Support\Enums\Size::Small) ->closeModalByClickingAway(false) ->modalSubmitAction(false) ->modalCancelAction(false) - ->modalContent(fn (self $component) => view( + ->modalContent(fn (self $component, Action $action) => view( 'filament-architect::edit-modal', [ // TODO: This is a hack to get the arguments to the modal // https://github.com/filamentphp/filament/issues/8763 - 'arguments' => Arr::last($this->getLivewire()->mountedFormComponentActionsArguments), + 'arguments' => $action->getArguments(), // TODO: since fix does not apply anymore for Filament v4 'statePath' => $component->getStatePath(), ] )); } - public function getBaseAddBlockAction(string $name): Action + public function getBaseAddBlockAction(string $name): \Filament\Actions\Action { - return Action::make($name) + return \Filament\Actions\Action::make($name) ->icon('heroicon-o-plus') ->hiddenLabel() ->color('gray') - ->size(ActionSize::Small) + ->size(\Filament\Support\Enums\Size::Small) ->closeModalByClickingAway(false) - ->form(fn () => [ + ->schema(fn () => [ Select::make('block') ->options(fn () => collect($this->getBlocks())->map(fn ($b) => $b->getName())) ->hiddenLabel() @@ -263,7 +267,7 @@ public function getBaseAddBlockAction(string $name): Action ]); } - public function getAddBlockAction(): Action + public function getAddBlockAction(): \Filament\Actions\Action { return $this->getBaseAddBlockAction('addBlock')->action(function (self $component, array $arguments, array $data) { $newUuid = (string) Str::uuid(); @@ -290,7 +294,7 @@ public function getAddBlockAction(): Action }); } - public function getAddBlockBetweenAction(): Action + public function getAddBlockBetweenAction(): \Filament\Actions\Action { return $this->getBaseAddBlockAction('addBlockBetween')->action(function (self $component, array $arguments, array $data) { $newUuid = (string) Str::uuid(); @@ -435,4 +439,37 @@ private function normalizeWidth(array $items) return $items; } + + #[ExposedLivewireMethod] + public function editedBlock(array $arguments): void + { + $items = $this->getState(); + $items[$arguments['row']][$arguments['uuid']]['data'] = $arguments['form']['state']; + $this->state($items); + } + + #[ExposedLivewireMethod] + public function reorderRow(array $data): void + { + $items = $this->getState(); + + $items = collect($items) + ->sortBy(fn ($item, $key) => array_search($key, $data['newKeys'])) + ->values() + ->toArray(); + + $this->state($items); + } + + #[ExposedLivewireMethod] + public function reorderColumn(array $data): void + { + $items = $this->getState(); + + $items[$data['row']] = collect($items[$data['row']]) + ->sortBy(fn ($item, $key) => array_search($key, $data['newKeys'])) + ->toArray(); + + $this->state($items); + } } diff --git a/src/Filament/Fields/Traits/HasDuplicateAction.php b/src/Filament/Fields/Traits/HasDuplicateAction.php index 7e297d3..5c58ef3 100644 --- a/src/Filament/Fields/Traits/HasDuplicateAction.php +++ b/src/Filament/Fields/Traits/HasDuplicateAction.php @@ -10,13 +10,13 @@ trait HasDuplicateAction { public Closure|bool $hasDuplicateAction = false; - public function getDuplicateAction(): Action + public function getDuplicateAction(): \Filament\Actions\Action { - return Action::make('duplicateBlock') + return \Filament\Actions\Action::make('duplicateBlock') ->icon('heroicon-o-document-duplicate') ->hiddenLabel() ->color('gray') - ->size(ActionSize::Small) + ->size(\Filament\Support\Enums\Size::Small) ->requiresConfirmation() ->action(function (array $arguments, self $component) { $items = $component->getState(); diff --git a/src/Filament/Fields/Traits/HasToggleButton.php b/src/Filament/Fields/Traits/HasToggleButton.php index d32b2d3..31789ed 100644 --- a/src/Filament/Fields/Traits/HasToggleButton.php +++ b/src/Filament/Fields/Traits/HasToggleButton.php @@ -10,13 +10,13 @@ trait HasToggleButton { public Closure|bool $enableShownButton = false; - public function getEnableBlockAction(string $name = 'enableBlock'): Action + public function getEnableBlockAction(string $name = 'enableBlock'): \Filament\Actions\Action { - return Action::make($name) + return \Filament\Actions\Action::make($name) ->icon('heroicon-o-eye-slash') ->hiddenLabel() ->color('gray') - ->size(ActionSize::Small) + ->size(\Filament\Support\Enums\Size::Small) ->action(function (self $component, array $arguments) { $items = $component->getState(); $items[$arguments['row']][$arguments['uuid']]['shown'] = ! ($items[$arguments['row']][$arguments['uuid']]['shown'] ?? true); @@ -24,7 +24,7 @@ public function getEnableBlockAction(string $name = 'enableBlock'): Action }); } - public function getDisableBlockAction(): Action + public function getDisableBlockAction(): \Filament\Actions\Action { return $this->getEnableBlockAction('disableBlock') ->icon('heroicon-o-eye'); diff --git a/src/Filament/Pages/ArchitectTest.php b/src/Filament/Pages/ArchitectTest.php index 937dec4..1d8312c 100644 --- a/src/Filament/Pages/ArchitectTest.php +++ b/src/Filament/Pages/ArchitectTest.php @@ -10,17 +10,17 @@ use Illuminate\Support\Str; /** - * @property Form $form + * @property \Filament\Schemas\Schema $form */ class ArchitectTest extends Page implements HasForms { use InteractsWithForms; - protected static ?string $navigationGroup = 'Architect'; + protected static string | \UnitEnum | null $navigationGroup = 'Architect'; - protected static ?string $navigationIcon = 'heroicon-o-document-text'; + protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-document-text'; - protected static string $view = 'filament-architect::filament.architect-test'; + protected string $view = 'filament-architect::filament.architect-test'; public ?array $data = []; @@ -34,10 +34,10 @@ public function mount(): void $this->form->fill(); } - public function form(Form $form): Form + public function form(\Filament\Schemas\Schema $schema): \Filament\Schemas\Schema { - return $form - ->schema([ + return $schema + ->components([ ArchitectInput::make('body') ->required() ->afterStateHydrated(static function (ArchitectInput $component, ?array $state): void { @@ -52,7 +52,7 @@ public function form(Form $form): Form ]; $component->state($items); - $component->getChildComponentContainers()[$newUuid]->fill(); + $component->getChildSchemas()[$newUuid]->fill(); } }), ]) diff --git a/src/Filament/Resources/ArchitectTemplateResource.php b/src/Filament/Resources/ArchitectTemplateResource.php index b1d97f9..c702678 100644 --- a/src/Filament/Resources/ArchitectTemplateResource.php +++ b/src/Filament/Resources/ArchitectTemplateResource.php @@ -16,14 +16,14 @@ class ArchitectTemplateResource extends Resource { protected static ?string $model = ArchitectTemplate::class; - protected static ?string $navigationGroup = 'Architect'; + protected static string | \UnitEnum | null $navigationGroup = 'Architect'; - protected static ?string $navigationIcon = 'heroicon-o-clipboard-document-list'; + protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-clipboard-document-list'; - public static function form(Form $form): Form + public static function form(\Filament\Schemas\Schema $schema): \Filament\Schemas\Schema { - return $form->schema([ - Forms\Components\Section::make()->schema([ + return $schema->components([ + \Filament\Schemas\Components\Section::make()->schema([ Forms\Components\TextInput::make('name') ->required() ->unique(ignoreRecord: true), @@ -40,11 +40,11 @@ public static function table(Table $table): Table Tables\Columns\TextColumn::make('name'), ]) ->actions([ - Tables\Actions\EditAction::make(), + \Filament\Actions\EditAction::make(), ]) ->bulkActions([ - Tables\Actions\BulkActionGroup::make([ - Tables\Actions\DeleteBulkAction::make(), + \Filament\Actions\BulkActionGroup::make([ + \Filament\Actions\DeleteBulkAction::make(), ]), ]); } diff --git a/src/Livewire/EditModal.php b/src/Livewire/EditModal.php index b710fb1..cd5baee 100644 --- a/src/Livewire/EditModal.php +++ b/src/Livewire/EditModal.php @@ -32,17 +32,17 @@ public function mount(array $arguments) $this->form->fill($this->state); } - public function form(Form $form): Form + public function form(\Filament\Schemas\Schema $schema): \Filament\Schemas\Schema { - return $form->schema([ - Group::make() + return $schema->components([ + \Filament\Schemas\Components\Group::make() ->statePath('state') ->schema([ TextInput::make('working_title') ->helperText('This is purely to help you identify the block in the list of blocks.') ->required(config('filament-architect.enable-slug-in-block')) ->live(onBlur: true) - ->afterStateUpdated(fn (Set $set, ?string $state, Get $get) => $get('slug') || $set('slug', Str::slug($state))), + ->afterStateUpdated(fn (\Filament\Schemas\Components\Utilities\Set $set, ?string $state, \Filament\Schemas\Components\Utilities\Get $get) => $get('slug') || $set('slug', Str::slug($state))), TextInput::make('slug') ->hidden(! config('filament-architect.enable-slug-in-block')) diff --git a/tests/Feature/Filament/Architect/MediaTextBlockTest.php b/tests/Feature/Filament/Architect/MediaTextBlockTest.php index b047488..887854f 100644 --- a/tests/Feature/Filament/Architect/MediaTextBlockTest.php +++ b/tests/Feature/Filament/Architect/MediaTextBlockTest.php @@ -1,6 +1,7 @@ $field ->toBeInstanceOf(\Codedor\MediaLibrary\Filament\AttachmentInput::class), fn ($field) => $field - ->toBeInstanceOf(\FilamentTiptapEditor\TiptapEditor::class), + ->toBeInstanceOf(RichEditor::class), ); }); diff --git a/tests/Feature/Filament/Architect/TableBlockTest.php b/tests/Feature/Filament/Architect/TableBlockTest.php index 883eeb4..e3e7996 100644 --- a/tests/Feature/Filament/Architect/TableBlockTest.php +++ b/tests/Feature/Filament/Architect/TableBlockTest.php @@ -1,7 +1,7 @@ tableBlock = new TableBlock(); @@ -11,6 +11,6 @@ expect($this->tableBlock) ->schema()->sequence( fn ($component) => $component - ->toBeInstanceOf(TiptapEditor::class), + ->toBeInstanceOf(RichEditor::class), ); }); diff --git a/tests/Feature/Filament/Architect/TextBlockTest.php b/tests/Feature/Filament/Architect/TextBlockTest.php index 918b855..3979af8 100644 --- a/tests/Feature/Filament/Architect/TextBlockTest.php +++ b/tests/Feature/Filament/Architect/TextBlockTest.php @@ -3,6 +3,7 @@ use Codedor\FilamentArchitect\Filament\Architect\TextBlock; use Filament\Forms\Components\Tabs; use Filament\Forms\Components\Tabs\Tab; +use Filament\Schemas\Components\Grid; beforeEach(function () { $this->textBlock = new TextBlock(); @@ -14,6 +15,6 @@ fn ($field) => $field ->toBeInstanceOf(\Filament\Forms\Components\TextInput::class), fn ($field) => $field - ->toBeInstanceOf(\Filament\Forms\Components\Grid::class), + ->toBeInstanceOf(Grid::class), ); }); diff --git a/tests/Feature/Filament/Architect/VideoBlockTest.php b/tests/Feature/Filament/Architect/VideoBlockTest.php index 6ee4389..df97041 100644 --- a/tests/Feature/Filament/Architect/VideoBlockTest.php +++ b/tests/Feature/Filament/Architect/VideoBlockTest.php @@ -1,6 +1,7 @@ videoBlock = new VideoBlock(); @@ -10,6 +11,6 @@ expect($this->videoBlock) ->schema()->sequence( fn ($component) => $component - ->toBeInstanceOf(\Filament\Forms\Components\Fieldset::class), + ->toBeInstanceOf(Fieldset::class), ); }); diff --git a/tests/Feature/Filament/Architect/VideoTextBlockTest.php b/tests/Feature/Filament/Architect/VideoTextBlockTest.php index 785d7d6..e4cae8d 100644 --- a/tests/Feature/Filament/Architect/VideoTextBlockTest.php +++ b/tests/Feature/Filament/Architect/VideoTextBlockTest.php @@ -1,8 +1,8 @@ videoTextBlock = new VideoTextBlock(); @@ -14,8 +14,8 @@ fn ($field) => $field ->toBeInstanceOf(\Filament\Forms\Components\Radio::class), fn ($field) => $field - ->toBeInstanceOf(\Filament\Forms\Components\Fieldset::class), + ->toBeInstanceOf(Fieldset::class), fn ($field) => $field - ->toBeInstanceOf(\FilamentTiptapEditor\TiptapEditor::class), + ->toBeInstanceOf(RichEditor::class), ); }); diff --git a/tests/TestCase.php b/tests/TestCase.php index d46350a..ec04b64 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,8 +3,6 @@ namespace Codedor\FilamentArchitect\Tests; use Codedor\FilamentArchitect\Providers\FilamentArchitectServiceProvider; -use FilamentTiptapEditor\Actions\LinkAction; -use FilamentTiptapEditor\Enums\TiptapOutput; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Facades\File; use Livewire\LivewireServiceProvider; @@ -40,9 +38,6 @@ public function getEnvironmentSetUp($app) { config()->set('database.default', 'testing'); - config()->set('filament-tiptap-editor.output', TiptapOutput::Html); - config()->set('filament-tiptap-editor.link_action', LinkAction::class); - config()->set('view.paths', [ resource_path('views'), __DIR__ . '/views', From 6f04b32af76f24bc53b8020f0a98622db2fecff8 Mon Sep 17 00:00:00 2001 From: Sander Van Damme Date: Tue, 1 Jul 2025 09:47:17 +0000 Subject: [PATCH 2/4] Fix actions & basic functionality --- resources/views/architect-input.blade.php | 9 +-- .../views/components/icon-button.blade.php | 7 ++- .../views/components/input-row.blade.php | 6 +- resources/views/edit-modal.blade.php | 1 + resources/views/livewire/edit-modal.blade.php | 8 +-- src/Filament/Fields/ArchitectInput.php | 63 +++---------------- .../Fields/Traits/HasDuplicateAction.php | 2 +- .../Fields/Traits/HasToggleButton.php | 2 +- src/Livewire/EditModal.php | 7 +-- 9 files changed, 28 insertions(+), 77 deletions(-) diff --git a/resources/views/architect-input.blade.php b/resources/views/architect-input.blade.php index beb8d35..3750dff 100644 --- a/resources/views/architect-input.blade.php +++ b/resources/views/architect-input.blade.php @@ -1,10 +1,11 @@ @php - use Filament\Support\Enums\ActionSize; + use Filament\Support\Enums\Size; use Filament\Support\Enums\IconSize; $state = $getState() ?? []; $statePath = $getStatePath(); $locales = $getLocales(); + $key = $getKey(); @endphp @@ -27,7 +28,7 @@
@@ -52,7 +53,7 @@ class="w-full flex gap-2 px-2 items-center" color="gray" icon="heroicon-o-arrows-up-down" class="border-2 dark:bg-white/5 dark:hover:bg-white/10 dark:border-gray-700 cursor-move m-0" - :size="ActionSize::Small" + :size="Size::Small" :icon-size="IconSize::Small" x-sortable-handle /> @@ -62,7 +63,7 @@ class="border-2 dark:bg-white/5 dark:hover:bg-white/10 dark:border-gray-700 curs
str_replace('data.', 'form.', $statePath)]); + $wireClickAction = "mountAction('{$action->getName()}', {$wireClickActionArguments}, {$wireClickActionMeta})" @endphp @@ -72,7 +72,7 @@ class="dark:bg-gray-800/100 dark:hover:bg-gray-700/100 dark:text-gray-100 dark:h 'uuid' => $uuid, 'row' => $rowKey, ]" - tooltip="{{ $shown ? 'Hide' : 'Show' }}" + tooltip="Duplicate" /> @endif diff --git a/resources/views/edit-modal.blade.php b/resources/views/edit-modal.blade.php index e16574f..2926a88 100644 --- a/resources/views/edit-modal.blade.php +++ b/resources/views/edit-modal.blade.php @@ -1,4 +1,5 @@ diff --git a/resources/views/livewire/edit-modal.blade.php b/resources/views/livewire/edit-modal.blade.php index 703a719..808d1d4 100644 --- a/resources/views/livewire/edit-modal.blade.php +++ b/resources/views/livewire/edit-modal.blade.php @@ -4,10 +4,10 @@ if (! validated) { return } - - this.$wire.$parent.dispatchFormEvent( - 'filament-architect::editedBlock', - '{{ $statePath }}', + + this.$wire.$parent.callSchemaComponentMethod( + @js($formKey), + 'editedBlock', { row: '{{ $arguments['row'] }}', uuid: '{{ $arguments['uuid'] }}', diff --git a/src/Filament/Fields/ArchitectInput.php b/src/Filament/Fields/ArchitectInput.php index 571b6df..c0bed11 100644 --- a/src/Filament/Fields/ArchitectInput.php +++ b/src/Filament/Fields/ArchitectInput.php @@ -14,10 +14,8 @@ use Filament\Forms\Components\Radio; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; -use Filament\Forms\Get; use Filament\Notifications\Notification; use Filament\Support\Components\Attributes\ExposedLivewireMethod; -use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Str; @@ -63,52 +61,6 @@ protected function setUp(): void fn (self $component): \Filament\Actions\Action => $component->getEditBlockAction(), fn (self $component): \Filament\Actions\Action => $component->getDeleteBlockAction(), ]); - - // TODO: moved to dedicated method, but still to check how we have to dispatch these events in the blade files - // $this->registerListeners([ - // 'filament-architect::editedBlock' => [ - // function (self $component, string $statePath, array $arguments): void { - // if ($statePath !== $component->getStatePath()) { - // return; - // } - // - // $items = $component->getState(); - // $items[$arguments['row']][$arguments['uuid']]['data'] = $arguments['form']['state']; - // $component->state($items); - // }, - // ], - // 'reorder-row' => [ - // function (self $component, string $statePath, array $data): void { - // if ($statePath !== $component->getStatePath()) { - // return; - // } - // - // $items = $component->getState(); - // - // $items = collect($items) - // ->sortBy(fn ($item, $key) => array_search($key, $data['newKeys'])) - // ->values() - // ->toArray(); - // - // $component->state($items); - // }, - // ], - // 'reorder-column' => [ - // function (self $component, string $statePath, array $data): void { - // if ($statePath !== $component->getStatePath()) { - // return; - // } - // - // $items = $component->getState(); - // - // $items[$data['row']] = collect($items[$data['row']]) - // ->sortBy(fn ($item, $key) => array_search($key, $data['newKeys'])) - // ->toArray(); - // - // $component->state($items); - // }, - // ], - // ]); } public function getArchitectPreviewAction(): \Filament\Actions\Action @@ -247,6 +199,7 @@ public function getEditBlockAction(): \Filament\Actions\Action // https://github.com/filamentphp/filament/issues/8763 'arguments' => $action->getArguments(), // TODO: since fix does not apply anymore for Filament v4 'statePath' => $component->getStatePath(), + 'key' => $component->getKey(), ] )); } @@ -441,20 +394,20 @@ private function normalizeWidth(array $items) } #[ExposedLivewireMethod] - public function editedBlock(array $arguments): void + public function editedBlock(string $row, string $uuid, array $form): void { $items = $this->getState(); - $items[$arguments['row']][$arguments['uuid']]['data'] = $arguments['form']['state']; + $items[$row][$uuid]['data'] = $form['state']; $this->state($items); } #[ExposedLivewireMethod] - public function reorderRow(array $data): void + public function reorderRow(array $newKeys): void { $items = $this->getState(); $items = collect($items) - ->sortBy(fn ($item, $key) => array_search($key, $data['newKeys'])) + ->sortBy(fn ($item, $key) => array_search($key, $newKeys)) ->values() ->toArray(); @@ -462,12 +415,12 @@ public function reorderRow(array $data): void } #[ExposedLivewireMethod] - public function reorderColumn(array $data): void + public function reorderColumn(array $newKeys, string $row): void { $items = $this->getState(); - $items[$data['row']] = collect($items[$data['row']]) - ->sortBy(fn ($item, $key) => array_search($key, $data['newKeys'])) + $items[$row] = collect($items[$row]) + ->sortBy(fn ($item, $key) => array_search($key, $newKeys)) ->toArray(); $this->state($items); diff --git a/src/Filament/Fields/Traits/HasDuplicateAction.php b/src/Filament/Fields/Traits/HasDuplicateAction.php index 5c58ef3..2752089 100644 --- a/src/Filament/Fields/Traits/HasDuplicateAction.php +++ b/src/Filament/Fields/Traits/HasDuplicateAction.php @@ -4,7 +4,7 @@ use Closure; use Filament\Forms\Components\Actions\Action; -use Filament\Support\Enums\ActionSize; +use Filament\Support\Enums\Size; trait HasDuplicateAction { diff --git a/src/Filament/Fields/Traits/HasToggleButton.php b/src/Filament/Fields/Traits/HasToggleButton.php index 31789ed..4dfe738 100644 --- a/src/Filament/Fields/Traits/HasToggleButton.php +++ b/src/Filament/Fields/Traits/HasToggleButton.php @@ -4,7 +4,7 @@ use Closure; use Filament\Forms\Components\Actions\Action; -use Filament\Support\Enums\ActionSize; +use Filament\Support\Enums\Size; trait HasToggleButton { diff --git a/src/Livewire/EditModal.php b/src/Livewire/EditModal.php index cd5baee..c165a0e 100644 --- a/src/Livewire/EditModal.php +++ b/src/Livewire/EditModal.php @@ -4,13 +4,9 @@ use Filament\Actions\Concerns\InteractsWithActions; use Filament\Actions\Contracts\HasActions; -use Filament\Forms\Components\Group; use Filament\Forms\Components\TextInput; use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Contracts\HasForms; -use Filament\Forms\Form; -use Filament\Forms\Get; -use Filament\Forms\Set; use Illuminate\Support\Str; use Livewire\Component; @@ -19,7 +15,7 @@ class EditModal extends Component implements HasForms, HasActions use InteractsWithActions; use InteractsWithForms; - public string $statePath; + public string $formKey; public array $state; @@ -41,7 +37,6 @@ public function form(\Filament\Schemas\Schema $schema): \Filament\Schemas\Schema TextInput::make('working_title') ->helperText('This is purely to help you identify the block in the list of blocks.') ->required(config('filament-architect.enable-slug-in-block')) - ->live(onBlur: true) ->afterStateUpdated(fn (\Filament\Schemas\Components\Utilities\Set $set, ?string $state, \Filament\Schemas\Components\Utilities\Get $get) => $get('slug') || $set('slug', Str::slug($state))), TextInput::make('slug') From 6214904263be7bfd77b6055925ec0c09ca3ef2d3 Mon Sep 17 00:00:00 2001 From: Sander Van Damme Date: Tue, 1 Jul 2025 12:20:29 +0000 Subject: [PATCH 3/4] Remove TODO --- src/Filament/Fields/ArchitectInput.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Filament/Fields/ArchitectInput.php b/src/Filament/Fields/ArchitectInput.php index c0bed11..42164fd 100644 --- a/src/Filament/Fields/ArchitectInput.php +++ b/src/Filament/Fields/ArchitectInput.php @@ -192,16 +192,11 @@ public function getEditBlockAction(): \Filament\Actions\Action ->closeModalByClickingAway(false) ->modalSubmitAction(false) ->modalCancelAction(false) - ->modalContent(fn (self $component, Action $action) => view( - 'filament-architect::edit-modal', - [ - // TODO: This is a hack to get the arguments to the modal - // https://github.com/filamentphp/filament/issues/8763 - 'arguments' => $action->getArguments(), // TODO: since fix does not apply anymore for Filament v4 - 'statePath' => $component->getStatePath(), - 'key' => $component->getKey(), - ] - )); + ->modalContent(fn (self $component, Action $action) => view('filament-architect::edit-modal', [ + 'arguments' => $action->getArguments(), + 'statePath' => $component->getStatePath(), + 'key' => $component->getKey(), + ])); } public function getBaseAddBlockAction(string $name): \Filament\Actions\Action From 1e7520e4b98ce63c0442a847ce584ee9a2619804 Mon Sep 17 00:00:00 2001 From: Sander Van Damme Date: Fri, 4 Jul 2025 07:31:25 +0000 Subject: [PATCH 4/4] Remove the editmodal livewire component --- resources/views/livewire/edit-modal.blade.php | 36 ---------- src/Filament/Fields/ArchitectInput.php | 41 ++++++----- src/Livewire/EditModal.php | 72 ------------------- 3 files changed, 25 insertions(+), 124 deletions(-) delete mode 100644 resources/views/livewire/edit-modal.blade.php delete mode 100644 src/Livewire/EditModal.php diff --git a/resources/views/livewire/edit-modal.blade.php b/resources/views/livewire/edit-modal.blade.php deleted file mode 100644 index 808d1d4..0000000 --- a/resources/views/livewire/edit-modal.blade.php +++ /dev/null @@ -1,36 +0,0 @@ -
- {{ $this->form }} - - - - -
diff --git a/src/Filament/Fields/ArchitectInput.php b/src/Filament/Fields/ArchitectInput.php index 42164fd..b3acffb 100644 --- a/src/Filament/Fields/ArchitectInput.php +++ b/src/Filament/Fields/ArchitectInput.php @@ -9,12 +9,13 @@ use Codedor\FilamentArchitect\Filament\Fields\Traits\HasToggleButton; use Codedor\FilamentArchitect\Models\ArchitectTemplate; use Codedor\LocaleCollection\Facades\LocaleCollection; -use Filament\Actions\Action; use Filament\Forms\Components\Field; use Filament\Forms\Components\Radio; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Notifications\Notification; +use Filament\Schemas\Components\Utilities\Get; +use Filament\Schemas\Components\Utilities\Set; use Filament\Support\Components\Attributes\ExposedLivewireMethod; use Illuminate\Support\Collection; use Illuminate\Support\Str; @@ -190,13 +191,29 @@ public function getEditBlockAction(): \Filament\Actions\Action ->color('gray') ->size(\Filament\Support\Enums\Size::Small) ->closeModalByClickingAway(false) - ->modalSubmitAction(false) - ->modalCancelAction(false) - ->modalContent(fn (self $component, Action $action) => view('filament-architect::edit-modal', [ - 'arguments' => $action->getArguments(), - 'statePath' => $component->getStatePath(), - 'key' => $component->getKey(), - ])); + ->fillForm(fn (array $arguments) => $arguments['block']['data'] ?? []) + ->schema(fn (array $arguments) => [ + TextInput::make('working_title') + ->helperText('This is purely to help you identify the block in the list of blocks.') + ->required(config('filament-architect.enable-slug-in-block')) + ->afterStateUpdated(fn (Set $set, ?string $state, Get $get) => $get('slug') || $set('slug', Str::slug($state))), + + TextInput::make('slug') + ->hidden(! config('filament-architect.enable-slug-in-block')) + ->helperText('This slug will be used to make anchor links. Modifying this field will break existing anchor links to this block'), + + ...$arguments['blockClassName']::make() + ->locales($arguments['locales']) + ->schema(), + ]) + ->action(function (array $arguments, array $data, self $component) { + $items = $component->getState(); + $row = $arguments['row']; + $uuid = $arguments['uuid']; + + $items[$row][$uuid]['data'] = $data; + $component->state($items); + }); } public function getBaseAddBlockAction(string $name): \Filament\Actions\Action @@ -388,14 +405,6 @@ private function normalizeWidth(array $items) return $items; } - #[ExposedLivewireMethod] - public function editedBlock(string $row, string $uuid, array $form): void - { - $items = $this->getState(); - $items[$row][$uuid]['data'] = $form['state']; - $this->state($items); - } - #[ExposedLivewireMethod] public function reorderRow(array $newKeys): void { diff --git a/src/Livewire/EditModal.php b/src/Livewire/EditModal.php deleted file mode 100644 index c165a0e..0000000 --- a/src/Livewire/EditModal.php +++ /dev/null @@ -1,72 +0,0 @@ -arguments = $arguments; - $this->state = $arguments['block']['data'] ?? []; - $this->form->fill($this->state); - } - - public function form(\Filament\Schemas\Schema $schema): \Filament\Schemas\Schema - { - return $schema->components([ - \Filament\Schemas\Components\Group::make() - ->statePath('state') - ->schema([ - TextInput::make('working_title') - ->helperText('This is purely to help you identify the block in the list of blocks.') - ->required(config('filament-architect.enable-slug-in-block')) - ->afterStateUpdated(fn (\Filament\Schemas\Components\Utilities\Set $set, ?string $state, \Filament\Schemas\Components\Utilities\Get $get) => $get('slug') || $set('slug', Str::slug($state))), - - TextInput::make('slug') - ->hidden(! config('filament-architect.enable-slug-in-block')) - ->helperText('This slug will be used to make anchor links. Modifying this field will break existing anchor links to this block'), - - ...$this->arguments['blockClassName']::make() - ->locales($this->arguments['locales']) - ->schema(), - ]), - ]); - } - - public function validates() - { - return $this->form->validate(); - } - - public function getFormData() - { - return $this->form->getState(); - } - - public function render() - { - return view('filament-architect::livewire.edit-modal'); - } - - public function isCachingForms(): bool - { - return false; - } -}