diff --git a/src/Facades/SpladePlugin.php b/src/Facades/SpladePlugin.php index 70f0451..fab2bcf 100644 --- a/src/Facades/SpladePlugin.php +++ b/src/Facades/SpladePlugin.php @@ -10,6 +10,7 @@ /** * @method static void registerPluginProvider(SpladePluginProvider $provider) * @method static void putComponentsOnWorkbench(array $components) + * @method static void putPluginOnWorkbench(SpladePluginProvider $provider) * @method static bool componentIsOnWorkbench(string|Component $components) * @method static bool bladeComponentIsProvidedByPlugin(string|Component $component) * @method static void dontGenerateVueComponentForPath(string $path) diff --git a/src/SpladePluginRepository.php b/src/SpladePluginRepository.php index 88d047f..ac015ac 100644 --- a/src/SpladePluginRepository.php +++ b/src/SpladePluginRepository.php @@ -17,6 +17,11 @@ class SpladePluginRepository */ private array $bladeComponents = []; + /** + * @var SpladePluginProvider[] + */ + private array $pluginsOnWorkbench = []; + /** * @var string[] */ @@ -49,6 +54,16 @@ public function bladeComponentIsProvidedByPlugin(string|Component $component): b return array_key_exists($componentClass, $this->bladeComponents); } + /** + * Put the given plugin on the workbench. + */ + public function putPluginOnWorkbench(SpladePluginProvider $provider): void + { + $this->pluginsOnWorkbench[get_class($provider)] = $provider; + + $this->putComponentsOnWorkbench($provider->getComponents()); + } + /** * Put the given components on the workbench. * @@ -89,13 +104,16 @@ public function shouldGenerateVueComponentForPath(string $path): bool private function getJavascriptImports(): Collection { - return collect($this->plugins)->mapWithKeys(function (SpladePluginProvider $provider) { - $hash = 'S'.md5($provider->getLibraryBuildFilename()); + return collect($this->plugins) + ->reject(fn (SpladePluginProvider $provider) => array_key_exists(get_class($provider), $this->pluginsOnWorkbench)) + ->mapWithKeys(function (SpladePluginProvider $provider) { + + $hash = 'S'.md5($provider->getLibraryBuildFilename()); - $path = base_path('vendor/'.$provider->getComposerPackageName().'/dist/'.$provider->getLibraryBuildFilename()); + $path = base_path('vendor/'.$provider->getComposerPackageName().'/dist/'.$provider->getLibraryBuildFilename()); - return [$hash => "import {$hash} from '{$path}'"]; - }); + return [$hash => "import {$hash} from '{$path}'"]; + }); } /**