Skip to content

Commit ecb18d7

Browse files
Merge pull request #310 from N1ebieski/Support-for-vendor-components-#10
Support for vendor components
2 parents e1f00dd + 9fb5315 commit ecb18d7

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

php-templates/blade-components.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function all()
1919
$this->getAnonymousNamespaced(),
2020
$this->getAnonymous(),
2121
$this->getAliases(),
22+
$this->getVendorComponents(),
2223
))->groupBy('key')->map(fn($items) => [
2324
'isVendor' => $items->first()['isVendor'],
2425
'paths' => $items->pluck('path')->values(),
@@ -194,6 +195,40 @@ protected function getAnonymous()
194195
return $components;
195196
}
196197

198+
protected function getVendorComponents(): array
199+
{
200+
$components = [];
201+
202+
/** @var \Illuminate\View\Factory $view */
203+
$view = \Illuminate\Support\Facades\App::make('view');
204+
205+
/** @var \Illuminate\View\FileViewFinder $finder */
206+
$finder = $view->getFinder();
207+
208+
/** @var array<string, array<int, string>> $views */
209+
$views = $finder->getHints();
210+
211+
foreach ($views as $key => $paths) {
212+
// First is always optional override in the resources/views folder
213+
$path = $paths[0] . '/components';
214+
215+
if (!is_dir($path)) {
216+
continue;
217+
}
218+
219+
array_push(
220+
$components,
221+
...$this->findFiles(
222+
$path,
223+
'blade.php',
224+
fn (\Illuminate\Support\Stringable $k) => $k->kebab()->prepend($key.'::'),
225+
)
226+
);
227+
}
228+
229+
return $components;
230+
}
231+
197232
protected function handleIndexComponents($str)
198233
{
199234
if ($str->endsWith('.index')) {

src/templates/blade-components.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ $components = new class {
1919
$this->getAnonymousNamespaced(),
2020
$this->getAnonymous(),
2121
$this->getAliases(),
22+
$this->getVendorComponents(),
2223
))->groupBy('key')->map(fn($items) => [
2324
'isVendor' => $items->first()['isVendor'],
2425
'paths' => $items->pluck('path')->values(),
@@ -194,6 +195,40 @@ $components = new class {
194195
return $components;
195196
}
196197
198+
protected function getVendorComponents(): array
199+
{
200+
$components = [];
201+
202+
/** @var \\Illuminate\\View\\Factory $view */
203+
$view = \\Illuminate\\Support\\Facades\\App::make('view');
204+
205+
/** @var \\Illuminate\\View\\FileViewFinder $finder */
206+
$finder = $view->getFinder();
207+
208+
/** @var array<string, array<int, string>> $views */
209+
$views = $finder->getHints();
210+
211+
foreach ($views as $key => $paths) {
212+
// First is always optional override in the resources/views folder
213+
$path = $paths[0] . '/components';
214+
215+
if (!is_dir($path)) {
216+
continue;
217+
}
218+
219+
array_push(
220+
$components,
221+
...$this->findFiles(
222+
$path,
223+
'blade.php',
224+
fn (\\Illuminate\\Support\\Stringable $k) => $k->kebab()->prepend($key.'::'),
225+
)
226+
);
227+
}
228+
229+
return $components;
230+
}
231+
197232
protected function handleIndexComponents($str)
198233
{
199234
if ($str->endsWith('.index')) {

0 commit comments

Comments
 (0)