Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Added putPluginOnWorkbench method to Plugin Repository
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Jan 31, 2024
1 parent cb0cddb commit 4849f3e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Facades/SpladePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 23 additions & 5 deletions src/SpladePluginRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class SpladePluginRepository
*/
private array $bladeComponents = [];

/**
* @var SpladePluginProvider[]
*/
private array $pluginsOnWorkbench = [];

/**
* @var string[]
*/
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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}'"];
});
}

/**
Expand Down

0 comments on commit 4849f3e

Please sign in to comment.