Skip to content

Commit

Permalink
Merge pull request #390 from awcodes/chore/better-support-for-curator
Browse files Browse the repository at this point in the history
Chore: better suppor for curator and uploads
  • Loading branch information
awcodes committed May 26, 2024
2 parents aa678fa + fa27075 commit a50308f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 9 deletions.
1 change: 1 addition & 0 deletions config/filament-tiptap-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
'visibility' => 'public',
'preserve_file_names' => false,
'max_file_size' => 2042,
'min_file_size' => 0,
'image_resize_mode' => null,
'image_crop_aspect_ratio' => null,
'image_resize_target_width' => null,
Expand Down
15 changes: 8 additions & 7 deletions src/Actions/MediaAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ protected function setUp(): void
->label(trans('filament-tiptap-editor::media-modal.labels.file'))
->disk($component->getDisk())
->directory($component->getDirectory())
->visibility(config('filament-tiptap-editor.visibility'))
->preserveFilenames(config('filament-tiptap-editor.preserve_file_names'))
->visibility($component->getVisibility())
->preserveFilenames($component->shouldPreserveFileNames())
->acceptedFileTypes($component->getAcceptedFileTypes())
->maxFiles(1)
->maxSize($component->getMaxFileSize())
->imageResizeMode(config('filament-tiptap-editor.image_resize_mode'))
->imageCropAspectRatio(config('filament-tiptap-editor.image_crop_aspect_ratio'))
->imageResizeTargetWidth(config('filament-tiptap-editor.image_resize_target_width'))
->imageResizeTargetHeight(config('filament-tiptap-editor.image_resize_target_height'))
->maxSize($component->getMaxSize())
->minSize($component->getMinSize())
->imageResizeMode($component->getImageResizeMode())
->imageCropAspectRatio($component->getImageCropAspectRatio())
->imageResizeTargetWidth($component->getImageResizeTargetWidth())
->imageResizeTargetHeight($component->getImageResizeTargetHeight())
->required()
->live()
->afterStateUpdated(function (TemporaryUploadedFile $state, callable $set) {
Expand Down
93 changes: 93 additions & 0 deletions src/Concerns/InteractsWithMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,23 @@ trait InteractsWithMedia

protected string | Closure | null $disk = null;

/**
* @deprecated Use `$maxSize` instead
*/
protected ?int $maxFileSize = null;

protected string | Closure | null $imageCropAspectRatio = null;

protected string | Closure | null $imageResizeMode = null;

protected string | Closure | null $imageResizeTargetHeight = null;

protected string | Closure | null $imageResizeTargetWidth = null;

protected int | Closure | null $maxSize = null;

protected int | Closure | null $minSize = null;

protected bool | Closure | null $shouldPreserveFileNames = null;

protected string | Closure | null $visibility = null;
Expand All @@ -39,13 +54,58 @@ public function disk(string | Closure $disk): static
return $this;
}

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

return $this;
}

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

return $this;
}

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

return $this;
}

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

return $this;
}

/**
* @deprecated Use `maxSize()` instead
*/
public function maxFileSize(int $maxFileSize): static
{
$this->maxFileSize = $maxFileSize;

return $this;
}

public function maxSize(int | Closure $size): static
{
$this->maxSize = $size;

return $this;
}

public function minSize(int | Closure $size): static
{
$this->minSize = $size;

return $this;
}

public function preserveFileNames(bool | Closure $shouldPreserveFileNames): static
{
$this->shouldPreserveFileNames = $shouldPreserveFileNames;
Expand Down Expand Up @@ -75,11 +135,44 @@ public function getDisk(): string
return $this->disk ? $this->evaluate($this->disk) : config('filament-tiptap-editor.disk');
}

public function getImageCropAspectRatio(): ?string
{
return $this->evaluate($this->imageCropAspectRatio) ?? config('filament-tiptap-editor.image_crop_aspect_ratio');
}

public function getImageResizeMode(): ?string
{
return $this->evaluate($this->imageResizeMode) ?? config('filament-tiptap-editor.image_resize_mode');
}

public function getImageResizeTargetHeight(): ?string
{
return $this->evaluate($this->imageResizeTargetHeight) ?? config('filament-tiptap-editor.image_resize_target_height');
}

public function getImageResizeTargetWidth(): ?string
{
return $this->evaluate($this->imageResizeTargetWidth) ?? config('filament-tiptap-editor.image_resize_target_width');
}

/**
* @deprecated Use `getMaxSize()` instead
*/
public function getMaxFileSize(): int
{
return $this->maxFileSize ?? config('filament-tiptap-editor.max_file_size');
}

public function getMaxSize(): int
{
return $this->evaluate($this->maxSize) ?? config('filament-tiptap-editor.max_file_size');
}

public function getMinSize(): int
{
return $this->evaluate($this->minSize) ?? config('filament-tiptap-editor.min_file_size');
}

public function getVisibility(): string
{
return $this->visibility ? $this->evaluate($this->visibility) : config('filament-tiptap-editor.visibility');
Expand Down
4 changes: 2 additions & 2 deletions src/TiptapBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public function getFormSchema(): array
/**
* @throws Throwable
*/
public function getPreview(?array $data = null, Component | null $component = null): string
public function getPreview(?array $data = null, ?Component $component = null): string
{
$data = $data ?? [];

return view($this->preview, [
...$data,
'component' => $component
'component' => $component,
])->render();
}

Expand Down

0 comments on commit a50308f

Please sign in to comment.