diff --git a/composer.json b/composer.json index 357425f..6044762 100644 --- a/composer.json +++ b/composer.json @@ -23,12 +23,8 @@ "illuminate/view": "^10.0|^11.0", "laravel/scout": "^10.0|^11.0", "livewire/livewire": "^3.4", - "spatie/laravel-package-tools": "^1.16.3", - "spatie/php-structure-discoverer": "^2.1", - "spatie/laravel-html": "^3.11", - "spatie/laravel-model-states": "^2.7", - "artesaos/seotools": "^1.3", - "blade-ui-kit/blade-icons": "^1.6.0" + "spatie/laravel-package-tools": "^1.16.4", + "artesaos/seotools": "^1.3" }, "require-dev": { "larastan/larastan": "^2.9", diff --git a/config/wireuse.php b/config/wireuse.php index 74e8c89..b1bf958 100644 --- a/config/wireuse.php +++ b/config/wireuse.php @@ -1,14 +1,23 @@ [ + // \Foxws\WireUse\Support\Livewire\StateObjects\SupportStateObjects::class, + // \Foxws\WireUse\Support\Livewire\ModelStateObjects\SupportModelStateObjects::class, + ], + /* |-------------------------------------------------------------------------- | Laravel HTML @@ -16,16 +25,13 @@ | | This extends Laravel HTML. | + | @doc https://foxws.nl/posts/wireuse/laravel-html | @doc https://spatie.be/docs/laravel-html/v3 | */ 'html' => [ - 'mixins' => [ - Html::class => HtmlExtendedMixin::class, - BaseElement::class => BaseElementMixin::class, - Elements\A::class => LinkElementMixin::class, - ], + 'mixins' => false, ], /* @@ -35,11 +41,14 @@ | | This controls structure discovery. | + | @doc https://foxws.nl/posts/wireuse/structure-scout | @doc https://github.com/spatie/php-structure-discoverer | */ 'scout' => [ + 'enabled' => false, + 'cache_store' => null, 'cache_lifetime' => 60 * 60 * 24 * 7, diff --git a/src/Support/Discover/ComponentStructureScout.php b/src/Support/Discover/ComponentStructureScout.php index b451943..5252272 100644 --- a/src/Support/Discover/ComponentStructureScout.php +++ b/src/Support/Discover/ComponentStructureScout.php @@ -23,14 +23,14 @@ protected function definition(): Discover ->full(); } - public function prefix(string $prefix): static + public function prefix(?string $prefix = null): static { $this->prefix = trim($prefix, '-'); return $this; } - public function path(string $path): static + public function path(?string $path = null): static { $this->path = $path; @@ -39,7 +39,7 @@ public function path(string $path): static public function identifier(): string { - return $this->prefix ?? static::class; + return $this->prefix ?? class_basename(static::class); } public function cacheStore(): ?string diff --git a/src/WireUseServiceProvider.php b/src/WireUseServiceProvider.php index 3d5d27f..004df4a 100644 --- a/src/WireUseServiceProvider.php +++ b/src/WireUseServiceProvider.php @@ -2,8 +2,12 @@ namespace Foxws\WireUse; +use Composer\InstalledVersions; use Foxws\WireUse\Scout\ComponentScout; use Foxws\WireUse\Scout\LivewireScout; +use Foxws\WireUse\Support\Html\Mixins\BaseElementMixin; +use Foxws\WireUse\Support\Html\Mixins\HtmlExtendedMixin; +use Foxws\WireUse\Support\Html\Mixins\LinkElementMixin; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -18,8 +22,9 @@ public function configurePackage(Package $package): void public function packageRegistered(): void { - $this->app->singleton(ComponentScout::class, fn () => new ComponentScout); - $this->app->singleton(LivewireScout::class, fn () => new LivewireScout); + if (config('wireuse.scout.enabled', false)) { + $this->registerStructureDiscovery(); + } } public function packageBooted(): void @@ -31,9 +36,9 @@ public function packageBooted(): void protected function registerFeatures(): static { - foreach ([ - \Foxws\WireUse\Support\Livewire\StateObjects\SupportStateObjects::class, - ] as $feature) { + $features = config('wireuse.features', []); + + foreach ($features as $feature) { app('livewire')->componentHook($feature); } @@ -42,7 +47,38 @@ protected function registerFeatures(): static protected function registerMixins(): static { - foreach (config('wireuse.html.mixins', []) as $element => $mixin) { + if (config('wireuse.html.mixins', false)) { + $this->registerHtmlMixins(); + } + + return $this; + } + + protected function registerStructureDiscovery(): static + { + if (! InstalledVersions::isInstalled('spatie/php-structure-discoverer')) { + abort(500, 'The spatie/php-structure-discoverer package is required to use the Strucute Scout.'); + } + + $this->app->singleton(ComponentScout::class, fn () => new ComponentScout); + $this->app->singleton(LivewireScout::class, fn () => new LivewireScout); + + return $this; + } + + protected function registerHtmlMixins(): static + { + if (! InstalledVersions::isInstalled('spatie/laravel-html')) { + abort(500, 'The spatie/laravel-html package is required to use the HTML mixins.'); + } + + $mixins = [ + \Spatie\Html\Html::class => HtmlExtendedMixin::class, + \Spatie\Html\BaseElement::class => BaseElementMixin::class, + \Spatie\Html\Elements\A::class => LinkElementMixin::class, + ]; + + foreach ($mixins as $element => $mixin) { $element::mixin(new $mixin); }