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

Commit

Permalink
WIP component registration
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Nov 27, 2023
1 parent 0e015ec commit 9d30fae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/AddSpladeToComponentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\View\AnonymousComponent;
use Illuminate\View\Component;
use Illuminate\View\View;
use ProtoneMedia\SpladeCore\Facades\SpladePlugin;

class AddSpladeToComponentData
{
Expand All @@ -29,6 +30,7 @@ public function __invoke(Component $component, array &$data, string $hash, mixed
$key = 'spladeBridge';

$data[$key] = ComponentSerializer::make($component)->toArray([
'is_registered' => SpladePlugin::bladeComponentIsRegistered($component),
'template_hash' => $hash,
'original_url' => url()->current(),
'original_verb' => request()->method(),
Expand Down
6 changes: 4 additions & 2 deletions src/Facades/SpladePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
namespace ProtoneMedia\SpladeCore\Facades;

use Illuminate\Support\Facades\Facade;
use Illuminate\View\Component;
use ProtoneMedia\SpladeCore\SpladePluginProvider;
use ProtoneMedia\SpladeCore\SpladePluginRepository;

/**
* @method static bool isRefreshingComponent()
* @method static void register(SpladePluginProvider $provider)
* @method static array all()
* @method static void registerPluginProvider(SpladePluginProvider $provider)
* @method static void registerBladeComponent(string|Component $component)
* @method static bool bladeComponentIsRegistered(string|Component $component)
*
* @see \ProtoneMedia\SpladeCore\SpladePluginRepository
*/
Expand Down
28 changes: 25 additions & 3 deletions src/SpladePluginRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,52 @@

namespace ProtoneMedia\SpladeCore;

use Illuminate\View\Component;

class SpladePluginRepository
{
/**
* @var SpladePluginProvider[]
*/
private array $plugins = [];

public function register(SpladePluginProvider $provider): void
/**
* @var Component[]
*/
private array $bladeComponents = [];

public function registerPluginProvider(SpladePluginProvider $provider): void
{
$this->plugins[] = $provider;
}

public function registerBladeComponent(string|Component $component): void
{
$this->bladeComponents[] = is_string($component) ? $component : get_class($component);
}

/**
* @return SpladePluginProvider[]
*/
public function all(): array
public function allPlugins(): array
{
return $this->plugins;
}

/**
* @return Component[]
*/
public function bladeComponentIsRegistered(string|Component $component): bool
{
$componentClass = is_string($component) ? $component : get_class($component);

return in_array($componentClass, $this->bladeComponents);
}

public function generateManifest(): void
{

$imports = collect($this->all())->mapWithKeys(function (SpladePluginProvider $provider) {
$imports = collect($this->allPlugins())->mapWithKeys(function (SpladePluginProvider $provider) {
$hash = 'S'.md5($provider->getLibraryBuildFilename());

$import = base_path('vendor/'.$provider->getComposerPackageName().'/dist/'.$provider->getLibraryBuildFilename());
Expand Down

0 comments on commit 9d30fae

Please sign in to comment.