diff --git a/src/Core/src/Traits/WithAssets.php b/src/Core/src/Traits/WithAssets.php index 5f870d1c3..63b62e8f3 100644 --- a/src/Core/src/Traits/WithAssets.php +++ b/src/Core/src/Traits/WithAssets.php @@ -4,6 +4,7 @@ namespace MoonShine\Core\Traits; +use MoonShine\Contracts\AssetManager\AssetElementContract; use MoonShine\Contracts\AssetManager\AssetManagerContract; /** @@ -21,20 +22,27 @@ public function getAssetManager(): AssetManagerContract return $this->getCore()->getContainer(AssetManagerContract::class); } + /** + * @return list + */ + protected function assets(): array + { + return []; + } + + /** + * @return list + */ public function getAssets(): array { if (! $this->shouldUseAssets()) { return []; } - return $this->assets; - } - - public function addAssets(array $assets): static - { - $this->getAssetManager()->add($assets); - - return $this; + return array_merge( + $this->assets, + $this->assets(), + ); } protected function shouldUseAssets(): bool @@ -42,7 +50,10 @@ protected function shouldUseAssets(): bool return true; } - public function pushAssets(array $assets): static + /** + * @param list $assets + */ + public function addAssets(array $assets): static { $this->assets = array_merge($this->assets, $assets); diff --git a/src/UI/src/Components/Layout/Favicon.php b/src/UI/src/Components/Layout/Favicon.php index 694467aad..8b1882777 100644 --- a/src/UI/src/Components/Layout/Favicon.php +++ b/src/UI/src/Components/Layout/Favicon.php @@ -26,7 +26,7 @@ public function __construct( * web-manifest: string, * } $assets */ - public function assets(array $assets): self + public function customAssets(array $assets): self { $this->customAssets = $assets; diff --git a/src/UI/src/Components/MoonShineComponent.php b/src/UI/src/Components/MoonShineComponent.php index 3c845080b..a9489f5b3 100644 --- a/src/UI/src/Components/MoonShineComponent.php +++ b/src/UI/src/Components/MoonShineComponent.php @@ -38,6 +38,13 @@ public function __construct( if (! $this->isConsoleMode()) { $this->resolveAssets(); } + + $this->booted(); + } + + protected function booted(): void + { + // } public static function consoleMode(bool $enable = true): void @@ -71,7 +78,7 @@ public function withAttributes(array $attributes): static /** @phpstan-ignore-next-line */ $this->attributes = $this->attributes ?: $this->newAttributeBag(); $this->attributes->setAttributes( - array_merge($this->attributes->jsonSerialize(), $attributes) + array_merge($this->attributes->jsonSerialize(), $attributes), ); return $this; diff --git a/tests/Feature/ComponentsEqualsTest.php b/tests/Feature/ComponentsEqualsTest.php index 8d0f12077..41c39a9fc 100644 --- a/tests/Feature/ComponentsEqualsTest.php +++ b/tests/Feature/ComponentsEqualsTest.php @@ -165,7 +165,7 @@ function renderBlade(string $alias, array $parameters = [], array $attributes = it('favicon', function () { compare( - Favicon::make()->assets(['test.js'])->bodyColor('#fff'), + Favicon::make()->customAssets(['test.js'])->bodyColor('#fff'), ['custom-assets' => ['test.js'], 'body-color' => '#fff'] ); });