Skip to content

Commit

Permalink
Merge branch '3.x' into 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Oct 9, 2024
2 parents ab5a1dc + 1987b84 commit 661e080
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 13 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/actions/src/Concerns/CanExportRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ protected function setUp(): void
);

$export->file_disk = $action->getFileDisk() ?? $exporter->getFileDisk();
// Temporary save to obtain the sequence number of the export file.
$export->save();

$export->file_name = $action->getFileName($export) ?? $exporter->getFileName($export);
$export->save();

Expand Down
11 changes: 11 additions & 0 deletions packages/actions/src/Exports/Jobs/PrepareCsvExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,22 @@ public function handle(): void
->reject(fn (array $order): bool => in_array($order['column'] ?? null, [$keyName, $qualifiedKeyName]))
->unique('column');

/** @var array<string, mixed> $originalBindings */
$originalBindings = $query->getRawBindings();

$query->reorder($qualifiedKeyName);

foreach ($originalOrders as $order) {
$query->orderBy($order['column'], $order['direction']);
}

$newBindings = $query->getRawBindings();

foreach ($originalBindings as $key => $value) {
if ($binding = array_diff($value, $newBindings[$key])) {
$query->addBinding($binding, $key);
}
}
}

$exportCsvJob = $this->getExportCsvJob();
Expand Down
11 changes: 11 additions & 0 deletions packages/forms/docs/02-fields/10-rich-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ RichEditor::make('content')
->fileAttachmentsDirectory('attachments')
->fileAttachmentsVisibility('private')
```

## Disabling Grammarly checks

If the user has Grammarly installed and you would like to prevent it from analyzing the contents of the editor, you can use the `disableGrammarly()` method:

```php
use Filament\Forms\Components\RichEditor;

RichEditor::make('content')
->disableGrammarly()
```
15 changes: 15 additions & 0 deletions packages/forms/docs/02-fields/12-repeater.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ Repeater::make('members')
->addActionLabel('Add member')
```

### Aligning the add action button

By default, the add action is aligned in the center. You may adjust this using the `addActionAlignment()` method, passing an `Alignment` option of `Alignment::Start` or `Alignment::End`:

```php
use Filament\Forms\Components\Repeater;
use Filament\Support\Enums\Alignment;

Repeater::make('members')
->schema([
// ...
])
->addActionAlignment(Alignment::Start)
```

### Preventing the user from adding items

You may prevent the user from adding items to the repeater using the `addable(false)` method:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@php
use Filament\Actions\Action;
use Filament\Support\Enums\Alignment;
$containers = $getChildComponentContainers();
Expand Down Expand Up @@ -238,7 +239,17 @@ class="absolute -top-3 left-3 px-1 text-sm font-medium"
@endif

@if ($isAddable && $addAction->isVisible())
<div class="flex justify-center">
<div
@class([
'flex',
match ($getAddActionAlignment()) {
Alignment::Start, Alignment::Left => 'justify-start',
Alignment::Center, null => 'justify-center',
Alignment::End, Alignment::Right => 'justify-end',
default => $alignment,
},
])
>
{{ $addAction }}
</div>
@endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,11 @@ class="trix-button trix-button--dialog"
@endif
x-ref="trix"
wire:ignore
@if ($isGrammarlyDisabled())
data-gramm="false"
data-gramm_editor="false"
data-enable-grammarly="false"
@endif
{{
$getExtraInputAttributeBag()->class([
'prose min-h-[theme(spacing.48)] max-w-none !border-none px-3 py-1.5 text-base text-gray-950 dark:prose-invert focus-visible:outline-none dark:text-white sm:text-sm sm:leading-6',
Expand Down
22 changes: 22 additions & 0 deletions packages/forms/src/Components/Concerns/CanDisableGrammarly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Filament\Forms\Components\Concerns;

use Closure;

trait CanDisableGrammarly
{
protected bool | Closure $isGrammarlyDisabled = false;

public function disableGrammarly(bool | Closure $condition = true): static
{
$this->isGrammarlyDisabled = $condition;

return $this;
}

public function isGrammarlyDisabled(): bool
{
return (bool) $this->evaluate($this->isGrammarlyDisabled);
}
}
1 change: 1 addition & 0 deletions packages/forms/src/Components/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Field extends Component implements Contracts\HasValidationRules
use Concerns\CanBeAutofocused;
use Concerns\CanBeMarkedAsRequired;
use Concerns\CanBeValidated;
use Concerns\CanDisableGrammarly;
use Concerns\HasEnum;
use Concerns\HasExtraFieldWrapperAttributes;
use Concerns\HasHelperText;
Expand Down
25 changes: 24 additions & 1 deletion packages/forms/src/Components/Repeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Filament\Schema\Schema;
use Filament\Support\Concerns\HasReorderAnimationDuration;
use Filament\Support\Enums\ActionSize;
use Filament\Support\Enums\Alignment;
use Filament\Support\Facades\FilamentIcon;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Collection;
Expand Down Expand Up @@ -58,6 +59,8 @@ class Repeater extends Field implements CanConcealComponents, HasExtraItemAction

protected Field | Closure | null $simpleField = null;

protected Alignment | string | Closure | null $addActionAlignment = null;

protected ?Closure $modifyRelationshipQueryUsing = null;

protected ?Closure $modifyAddActionUsing = null;
Expand Down Expand Up @@ -201,6 +204,24 @@ public function getAddAction(): Action
return $action;
}

public function addActionAlignment(Alignment | string | Closure | null $addActionAlignment): static
{
$this->addActionAlignment = $addActionAlignment;

return $this;
}

public function getAddActionAlignment(): Alignment | string | null
{
$alignment = $this->evaluate($this->addActionAlignment);

if (is_string($alignment)) {
$alignment = Alignment::tryFrom($alignment) ?? $alignment;
}

return $alignment;
}

public function addAction(?Closure $callback): static
{
$this->modifyAddActionUsing = $callback;
Expand Down Expand Up @@ -919,7 +940,9 @@ public function relationship(string | Closure | null $name = null, ?Closure $mod
->get()
->each(static fn (Model $record) => $record->delete());

$childComponentContainers = $component->getChildComponentContainers();
$childComponentContainers = $component->getChildComponentContainers(
withHidden: $component->shouldSaveRelationshipsWhenHidden(),
);

$itemOrder = 1;
$orderColumn = $component->getOrderColumn();
Expand Down
8 changes: 4 additions & 4 deletions packages/schema/src/Components/Concerns/HasState.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ public function dehydrateState(array &$state, bool $isDehydrated = true): void
}
}

foreach ($this->getChildComponentContainers() as $container) {
if ($container->isHidden()) {
continue;
}
if ($this->isHiddenAndNotDehydrated()) {
return;
}

foreach ($this->getChildComponentContainers(withHidden: true) as $container) {
$container->dehydrateState($state, $isDehydrated);
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/src/Forms/StateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,25 @@

expect($container)
->dehydrateState()->not()->toBe([]);

$container = ComponentContainer::make(Livewire::make())
->statePath('data')
->components([
(new Component)
->id('parent')
->hidden()
->dehydratedWhenHidden()
->childComponents([
(new Component)
->id('child')
->statePath(Str::random())
->default(Str::random()),
]),
])
->fill();

expect($container)
->dehydrateState()->not()->toBe([]);
});

test('disabled components are excluded from state dehydration', function () {
Expand Down

0 comments on commit 661e080

Please sign in to comment.