From 6c72529b1a5395ce3850a1e1926c13abd0bdfe4e Mon Sep 17 00:00:00 2001 From: marco Date: Mon, 3 Jun 2024 12:53:13 +0200 Subject: [PATCH 1/7] up --- Filament/Blocks/SpatieImage.php | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Filament/Blocks/SpatieImage.php diff --git a/Filament/Blocks/SpatieImage.php b/Filament/Blocks/SpatieImage.php new file mode 100644 index 00000000..f3abe8d3 --- /dev/null +++ b/Filament/Blocks/SpatieImage.php @@ -0,0 +1,63 @@ +schema( + [ + SpatieMediaLibraryFileUpload::make('image') + ->label('Image upload') + ->beforeStateDehydrated(function ($state) { + dddx($state); + }), + + TextInput::make('url') + ->label('or Image URL'), + + Select::make('ratio') + ->options(static::getRatios()) + ->afterStateHydrated(static fn ($state, $set) => $state || $set('ratio', '4-3')), + + TextInput::make('alt') + ->columnSpanFull(), + + TextInput::make('caption') + ->columnSpanFull(), + ] + ) + ->columns('form' === $context ? 2 : 1); + } + + public static function getRatios(): array + { + return [ + '4-3' => '4/3', + '3-4' => '3/4', + 'free' => 'free', + ]; + } + + public static function getRatioClass(string $ratio): string + { + return match ($ratio) { + '4-3' => 'aspect-[4/3]', + '3-4' => 'aspect-[3/4]', + default => '', + }; + } +} From 08d67e26a33feab61227c4c35f8f3c0560ba47fb Mon Sep 17 00:00:00 2001 From: marco76tv Date: Mon, 3 Jun 2024 10:53:38 +0000 Subject: [PATCH 2/7] Dusting --- Filament/Blocks/Image.php | 2 +- Filament/Blocks/Slider.php | 2 +- Filament/Blocks/SpatieImage.php | 8 ++++---- Filament/Blocks/Title.php | 2 +- Filament/Forms/Components/AddressField.php | 4 ++-- View/Components/Render/Block.php | 6 +++--- View/Composers/ThemeComposer.php | 3 +-- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Filament/Blocks/Image.php b/Filament/Blocks/Image.php index aab08505..94e32dd4 100755 --- a/Filament/Blocks/Image.php +++ b/Filament/Blocks/Image.php @@ -35,7 +35,7 @@ public static function make( ->columnSpanFull(), ] ) - ->columns('form' === $context ? 2 : 1); + ->columns($context === 'form' ? 2 : 1); } public static function getRatios(): array diff --git a/Filament/Blocks/Slider.php b/Filament/Blocks/Slider.php index 638223f0..84b1b122 100755 --- a/Filament/Blocks/Slider.php +++ b/Filament/Blocks/Slider.php @@ -32,6 +32,6 @@ public static function make( // ->afterStateHydrated(static fn ($state, $set) => $state || $set('level', 'h2')), ] ) - ->columns('form' === $context ? 2 : 1); + ->columns($context === 'form' ? 2 : 1); } } diff --git a/Filament/Blocks/SpatieImage.php b/Filament/Blocks/SpatieImage.php index f3abe8d3..65036804 100644 --- a/Filament/Blocks/SpatieImage.php +++ b/Filament/Blocks/SpatieImage.php @@ -22,9 +22,9 @@ public static function make( [ SpatieMediaLibraryFileUpload::make('image') ->label('Image upload') - ->beforeStateDehydrated(function ($state) { - dddx($state); - }), + ->beforeStateDehydrated(function ($state) { + dddx($state); + }), TextInput::make('url') ->label('or Image URL'), @@ -40,7 +40,7 @@ public static function make( ->columnSpanFull(), ] ) - ->columns('form' === $context ? 2 : 1); + ->columns($context === 'form' ? 2 : 1); } public static function getRatios(): array diff --git a/Filament/Blocks/Title.php b/Filament/Blocks/Title.php index f37e1ba8..15d6726a 100755 --- a/Filament/Blocks/Title.php +++ b/Filament/Blocks/Title.php @@ -39,6 +39,6 @@ public static function make( ->options($views), ] ) - ->columns('form' === $context ? 2 : 1); + ->columns($context === 'form' ? 2 : 1); } } diff --git a/Filament/Forms/Components/AddressField.php b/Filament/Forms/Components/AddressField.php index 507b8211..f9fa13bd 100755 --- a/Filament/Forms/Components/AddressField.php +++ b/Filament/Forms/Components/AddressField.php @@ -29,7 +29,7 @@ public function saveRelationships(): void $record = $this->getRecord(); $relationship = $record?->{$this->getRelationship()}(); - if (null === $relationship) { + if ($relationship === null) { return; } elseif ($address = $relationship->first()) { $address->update($state); @@ -80,7 +80,7 @@ protected function setUp(): void 'zip' => null, ]; $address = $record?->getRelationValue($this->getRelationship()); - if (null != $address && is_object($address) && method_exists($address, 'toArray')) { + if ($address != null && is_object($address) && method_exists($address, 'toArray')) { $data = $address->toArray(); } diff --git a/View/Components/Render/Block.php b/View/Components/Render/Block.php index 062664bc..8fd9bb6e 100755 --- a/View/Components/Render/Block.php +++ b/View/Components/Render/Block.php @@ -33,14 +33,14 @@ public function render(): ViewFactory|View return view('ui::empty'); } - if ('v1' === $this->tpl) { + if ($this->tpl === 'v1') { $this->tpl = $this->block['type']; } else { $this->tpl = $this->block['type'].'.'.$this->tpl; } $views = ['ui::components.blocks.'.$this->tpl]; - if (null !== $this->model) { + if ($this->model !== null) { $module = app(GetModuleNameFromModelAction::class)->execute($this->model); $views[] = strtolower($module).'::components.blocks.'.$this->tpl; } @@ -53,7 +53,7 @@ public function render(): ViewFactory|View * @phpstan-var view-string|null */ $view = Arr::first($views, $callback); - if (null === $view) { + if ($view === null) { throw new \Exception('none of these views exists ['.implode(', '.\chr(13), $views).']'); } $view_params = $this->block['data'] ?? []; diff --git a/View/Composers/ThemeComposer.php b/View/Composers/ThemeComposer.php index 67779871..bdf97619 100755 --- a/View/Composers/ThemeComposer.php +++ b/View/Composers/ThemeComposer.php @@ -17,8 +17,7 @@ public function metatags(): \Illuminate\View\View } /** - * @param string $index - * + * @param string $index * @return \Illuminate\Config\Repository|\Illuminate\Contracts\Foundation\Application|mixed */ public function metatag($index) From 379cdf6046e2fb4acc33be150cae2a7785dc832b Mon Sep 17 00:00:00 2001 From: marco Date: Mon, 3 Jun 2024 14:49:53 +0200 Subject: [PATCH 3/7] up --- Filament/Blocks/SpatieImage.php | 58 ++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/Filament/Blocks/SpatieImage.php b/Filament/Blocks/SpatieImage.php index 65036804..e4d65f66 100644 --- a/Filament/Blocks/SpatieImage.php +++ b/Filament/Blocks/SpatieImage.php @@ -4,43 +4,49 @@ namespace Modules\UI\Filament\Blocks; +use Filament\Forms; use Filament\Forms\Components\Builder\Block; use Filament\Forms\Components\Select; use Filament\Forms\Components\SpatieMediaLibraryFileUpload; use Filament\Forms\Components\TextInput; +use Illuminate\Support\Str; class SpatieImage { public static function make( - string $name = 'image', + string $name = 'image_spatie', string $context = 'form', ): Block { - // dddx(get_class_methods(SpatieMediaLibraryFileUpload::class)); - return Block::make($name) - ->schema( - [ - SpatieMediaLibraryFileUpload::make('image') - ->label('Image upload') - ->beforeStateDehydrated(function ($state) { - dddx($state); - }), - - TextInput::make('url') - ->label('or Image URL'), - - Select::make('ratio') - ->options(static::getRatios()) - ->afterStateHydrated(static fn ($state, $set) => $state || $set('ratio', '4-3')), - - TextInput::make('alt') - ->columnSpanFull(), - - TextInput::make('caption') - ->columnSpanFull(), - ] - ) - ->columns($context === 'form' ? 2 : 1); + ->schema([ + Forms\Components\Hidden::make('img_uuid') + ->default(fn () => Str::uuid()->toString()) + ->formatStateUsing(fn ($state) => $state ?? Str::uuid()->toString()) + ->live(), + // ->required(), + + SpatieMediaLibraryFileUpload::make('image') + ->columnSpanFull() + ->collection(fn (Forms\Get $get) => $get('img_uuid')), + + Select::make('ratio') + ->options(static::getRatios()) + ->afterStateHydrated(static fn ($state, $set) => $state || $set('ratio', '4-3')), + + TextInput::make('alt') + ->columnSpanFull(), + + TextInput::make('caption') + ->columnSpanFull(), + + // Filament\Forms\Components\SpatieMediaLibraryFileUpload::whereCustomProperties does not exist. + // ->whereCustomProperties(fn(Forms\Get $get) => ['gallery_id' => $get('gallery_id')]) + + // ->customProperties(fn(Forms\Get $get) => ['gallery_id' => $get('gallery_id')]), + + // Forms\Components\SpatieMediaLibraryFileUpload::make('media_id') + ]) + ->columns('form' === $context ? 2 : 1); } public static function getRatios(): array From 7071e55b239426dfc80ce75771691248a2ba8cb6 Mon Sep 17 00:00:00 2001 From: marco76tv Date: Mon, 3 Jun 2024 12:50:21 +0000 Subject: [PATCH 4/7] Lint --- Filament/Blocks/Image.php | 2 +- Filament/Blocks/Slider.php | 2 +- Filament/Blocks/Title.php | 2 +- Filament/Forms/Components/AddressField.php | 4 ++-- View/Components/Render/Block.php | 6 +++--- View/Composers/ThemeComposer.php | 3 ++- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Filament/Blocks/Image.php b/Filament/Blocks/Image.php index 94e32dd4..aab08505 100755 --- a/Filament/Blocks/Image.php +++ b/Filament/Blocks/Image.php @@ -35,7 +35,7 @@ public static function make( ->columnSpanFull(), ] ) - ->columns($context === 'form' ? 2 : 1); + ->columns('form' === $context ? 2 : 1); } public static function getRatios(): array diff --git a/Filament/Blocks/Slider.php b/Filament/Blocks/Slider.php index 84b1b122..638223f0 100755 --- a/Filament/Blocks/Slider.php +++ b/Filament/Blocks/Slider.php @@ -32,6 +32,6 @@ public static function make( // ->afterStateHydrated(static fn ($state, $set) => $state || $set('level', 'h2')), ] ) - ->columns($context === 'form' ? 2 : 1); + ->columns('form' === $context ? 2 : 1); } } diff --git a/Filament/Blocks/Title.php b/Filament/Blocks/Title.php index 15d6726a..f37e1ba8 100755 --- a/Filament/Blocks/Title.php +++ b/Filament/Blocks/Title.php @@ -39,6 +39,6 @@ public static function make( ->options($views), ] ) - ->columns($context === 'form' ? 2 : 1); + ->columns('form' === $context ? 2 : 1); } } diff --git a/Filament/Forms/Components/AddressField.php b/Filament/Forms/Components/AddressField.php index f9fa13bd..507b8211 100755 --- a/Filament/Forms/Components/AddressField.php +++ b/Filament/Forms/Components/AddressField.php @@ -29,7 +29,7 @@ public function saveRelationships(): void $record = $this->getRecord(); $relationship = $record?->{$this->getRelationship()}(); - if ($relationship === null) { + if (null === $relationship) { return; } elseif ($address = $relationship->first()) { $address->update($state); @@ -80,7 +80,7 @@ protected function setUp(): void 'zip' => null, ]; $address = $record?->getRelationValue($this->getRelationship()); - if ($address != null && is_object($address) && method_exists($address, 'toArray')) { + if (null != $address && is_object($address) && method_exists($address, 'toArray')) { $data = $address->toArray(); } diff --git a/View/Components/Render/Block.php b/View/Components/Render/Block.php index 8fd9bb6e..062664bc 100755 --- a/View/Components/Render/Block.php +++ b/View/Components/Render/Block.php @@ -33,14 +33,14 @@ public function render(): ViewFactory|View return view('ui::empty'); } - if ($this->tpl === 'v1') { + if ('v1' === $this->tpl) { $this->tpl = $this->block['type']; } else { $this->tpl = $this->block['type'].'.'.$this->tpl; } $views = ['ui::components.blocks.'.$this->tpl]; - if ($this->model !== null) { + if (null !== $this->model) { $module = app(GetModuleNameFromModelAction::class)->execute($this->model); $views[] = strtolower($module).'::components.blocks.'.$this->tpl; } @@ -53,7 +53,7 @@ public function render(): ViewFactory|View * @phpstan-var view-string|null */ $view = Arr::first($views, $callback); - if ($view === null) { + if (null === $view) { throw new \Exception('none of these views exists ['.implode(', '.\chr(13), $views).']'); } $view_params = $this->block['data'] ?? []; diff --git a/View/Composers/ThemeComposer.php b/View/Composers/ThemeComposer.php index bdf97619..67779871 100755 --- a/View/Composers/ThemeComposer.php +++ b/View/Composers/ThemeComposer.php @@ -17,7 +17,8 @@ public function metatags(): \Illuminate\View\View } /** - * @param string $index + * @param string $index + * * @return \Illuminate\Config\Repository|\Illuminate\Contracts\Foundation\Application|mixed */ public function metatag($index) From 27434513009ae8685e08691c72aa54c981d6e2b5 Mon Sep 17 00:00:00 2001 From: marco Date: Mon, 3 Jun 2024 14:51:22 +0200 Subject: [PATCH 5/7] up --- Filament/Blocks/SpatieImage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Filament/Blocks/SpatieImage.php b/Filament/Blocks/SpatieImage.php index e4d65f66..5205fa9b 100644 --- a/Filament/Blocks/SpatieImage.php +++ b/Filament/Blocks/SpatieImage.php @@ -11,7 +11,7 @@ use Filament\Forms\Components\TextInput; use Illuminate\Support\Str; -class SpatieImage +class ImageSpatie { public static function make( string $name = 'image_spatie', From f5702a1a363e0e6e8d71eda5796f97779f55d71c Mon Sep 17 00:00:00 2001 From: marco Date: Mon, 3 Jun 2024 17:03:13 +0200 Subject: [PATCH 6/7] up --- Filament/Blocks/{SpatieImage.php => ImageSpatie.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Filament/Blocks/{SpatieImage.php => ImageSpatie.php} (100%) diff --git a/Filament/Blocks/SpatieImage.php b/Filament/Blocks/ImageSpatie.php similarity index 100% rename from Filament/Blocks/SpatieImage.php rename to Filament/Blocks/ImageSpatie.php From 84631a5166a71ff9404f3104c7bcb3ff9b9cd2ff Mon Sep 17 00:00:00 2001 From: marco76tv Date: Mon, 3 Jun 2024 15:03:40 +0000 Subject: [PATCH 7/7] Dusting --- Filament/Blocks/Image.php | 2 +- Filament/Blocks/ImageSpatie.php | 2 +- Filament/Blocks/Slider.php | 2 +- Filament/Blocks/Title.php | 2 +- Filament/Forms/Components/AddressField.php | 4 ++-- View/Components/Render/Block.php | 6 +++--- View/Composers/ThemeComposer.php | 3 +-- 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Filament/Blocks/Image.php b/Filament/Blocks/Image.php index aab08505..94e32dd4 100755 --- a/Filament/Blocks/Image.php +++ b/Filament/Blocks/Image.php @@ -35,7 +35,7 @@ public static function make( ->columnSpanFull(), ] ) - ->columns('form' === $context ? 2 : 1); + ->columns($context === 'form' ? 2 : 1); } public static function getRatios(): array diff --git a/Filament/Blocks/ImageSpatie.php b/Filament/Blocks/ImageSpatie.php index 5205fa9b..8b7c93c6 100644 --- a/Filament/Blocks/ImageSpatie.php +++ b/Filament/Blocks/ImageSpatie.php @@ -46,7 +46,7 @@ public static function make( // Forms\Components\SpatieMediaLibraryFileUpload::make('media_id') ]) - ->columns('form' === $context ? 2 : 1); + ->columns($context === 'form' ? 2 : 1); } public static function getRatios(): array diff --git a/Filament/Blocks/Slider.php b/Filament/Blocks/Slider.php index 638223f0..84b1b122 100755 --- a/Filament/Blocks/Slider.php +++ b/Filament/Blocks/Slider.php @@ -32,6 +32,6 @@ public static function make( // ->afterStateHydrated(static fn ($state, $set) => $state || $set('level', 'h2')), ] ) - ->columns('form' === $context ? 2 : 1); + ->columns($context === 'form' ? 2 : 1); } } diff --git a/Filament/Blocks/Title.php b/Filament/Blocks/Title.php index f37e1ba8..15d6726a 100755 --- a/Filament/Blocks/Title.php +++ b/Filament/Blocks/Title.php @@ -39,6 +39,6 @@ public static function make( ->options($views), ] ) - ->columns('form' === $context ? 2 : 1); + ->columns($context === 'form' ? 2 : 1); } } diff --git a/Filament/Forms/Components/AddressField.php b/Filament/Forms/Components/AddressField.php index 507b8211..f9fa13bd 100755 --- a/Filament/Forms/Components/AddressField.php +++ b/Filament/Forms/Components/AddressField.php @@ -29,7 +29,7 @@ public function saveRelationships(): void $record = $this->getRecord(); $relationship = $record?->{$this->getRelationship()}(); - if (null === $relationship) { + if ($relationship === null) { return; } elseif ($address = $relationship->first()) { $address->update($state); @@ -80,7 +80,7 @@ protected function setUp(): void 'zip' => null, ]; $address = $record?->getRelationValue($this->getRelationship()); - if (null != $address && is_object($address) && method_exists($address, 'toArray')) { + if ($address != null && is_object($address) && method_exists($address, 'toArray')) { $data = $address->toArray(); } diff --git a/View/Components/Render/Block.php b/View/Components/Render/Block.php index 062664bc..8fd9bb6e 100755 --- a/View/Components/Render/Block.php +++ b/View/Components/Render/Block.php @@ -33,14 +33,14 @@ public function render(): ViewFactory|View return view('ui::empty'); } - if ('v1' === $this->tpl) { + if ($this->tpl === 'v1') { $this->tpl = $this->block['type']; } else { $this->tpl = $this->block['type'].'.'.$this->tpl; } $views = ['ui::components.blocks.'.$this->tpl]; - if (null !== $this->model) { + if ($this->model !== null) { $module = app(GetModuleNameFromModelAction::class)->execute($this->model); $views[] = strtolower($module).'::components.blocks.'.$this->tpl; } @@ -53,7 +53,7 @@ public function render(): ViewFactory|View * @phpstan-var view-string|null */ $view = Arr::first($views, $callback); - if (null === $view) { + if ($view === null) { throw new \Exception('none of these views exists ['.implode(', '.\chr(13), $views).']'); } $view_params = $this->block['data'] ?? []; diff --git a/View/Composers/ThemeComposer.php b/View/Composers/ThemeComposer.php index 67779871..bdf97619 100755 --- a/View/Composers/ThemeComposer.php +++ b/View/Composers/ThemeComposer.php @@ -17,8 +17,7 @@ public function metatags(): \Illuminate\View\View } /** - * @param string $index - * + * @param string $index * @return \Illuminate\Config\Repository|\Illuminate\Contracts\Foundation\Application|mixed */ public function metatag($index)