Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ Default value:
]
```

### afterUpdatingBlocks

After sorting/editing/adding/deleting a block this closure will be called, you can pass the usual Filament component variables to it.

```php
ArchitectInput::make('body')
->afterUpdatingBlocks(fn (Component $livewire) => $livewire->dispatch('refreshPreview')),
```

### enableDuplicateButton

Enables or disables (disabled by default) the "duplicate" action for the Architect, allowing the user to duplicate rows easily.
Expand Down
23 changes: 23 additions & 0 deletions src/Filament/Fields/ArchitectInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class ArchitectInput extends Field
public Closure|bool $hasTemplates = true;
public Closure|bool $hasPreview = true;

public null|Closure $afterUpdatingBlocksCall = null;

protected function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -107,6 +109,20 @@ function (self $component, string $statePath, array $data): void {
]);
}

public function state(mixed $state): static
{
$return = parent::state($state);

$this->callAfterUpdatingBlocks();

return $return;
}

public function callAfterUpdatingBlocks(): void
{
$this->evaluate($this->afterUpdatingBlocksCall);
}

public function getArchitectPreviewAction(): Action
{
return Action::make('architectPreview')
Expand Down Expand Up @@ -410,6 +426,13 @@ public function getHasPreview(): bool
return $this->evaluate($this->hasPreview);
}

public function afterUpdatingBlocks(null|Closure $afterUpdatingBlocksCall): static
{
$this->afterUpdatingBlocksCall = $afterUpdatingBlocksCall;

return $this;
}

private function newBlock(array $data)
{
return [
Expand Down