Skip to content

Commit 156d0db

Browse files
committed
various cleanup and add entry
1 parent 44b26a9 commit 156d0db

16 files changed

+94
-145
lines changed

composer.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@
7777
"laravel": {
7878
"providers": [
7979
"Awcodes\\Mason\\MasonServiceProvider"
80-
],
81-
"aliases": {
82-
"Mason": "Awcodes\\Mason\\Facades\\Mason"
83-
}
80+
]
8481
}
8582
},
8683
"minimum-stability": "dev",

resources/views/bricks/section.blade.php

+4-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
@props([
2-
'id' => null,
32
'background_color' => 'white',
43
'image_position' => null,
54
'image_alignment' => null,
65
'image_rounded' => false,
76
'image_shadow' => false,
87
'text' => null,
98
'image' => null,
10-
'actions' => [],
11-
'actions_alignment' => null,
129
])
1310

1411
<section
@@ -48,9 +45,10 @@
4845
src="{{ \Illuminate\Support\Facades\Storage::url($image) }}"
4946
alt=""
5047
@class([
51-
'rounded-lg' => $image_rounded,
52-
'shadow-md' => $image_shadow,
53-
]) />
48+
'rounded-lg' => $image_rounded,
49+
'shadow-md' => $image_shadow,
50+
])
51+
/>
5452
</div>
5553
@endif
5654

@@ -65,13 +63,6 @@
6563
{!! $text !!}
6664
</div>
6765
@endif
68-
69-
{{-- @if ($actions)--}}
70-
{{-- <x-blocks.actions--}}
71-
{{-- :actions="$actions"--}}
72-
{{-- :actions_alignment="$actions_alignment"--}}
73-
{{-- />--}}
74-
{{-- @endif--}}
7566
</div>
7667
</div>
7768
</div>

resources/views/mason-entry.blade.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<x-dynamic-component :component="$getEntryWrapperView()" :entry="$entry">
2+
<div
3+
{{
4+
\Filament\Support\prepare_inherited_attributes($getExtraAttributeBag())
5+
->class([
6+
'mason-entry',
7+
])
8+
}}
9+
>
10+
<div class="mason">
11+
{!! mason($getState())->bricks($getBricks())->toHtml() !!}
12+
</div>
13+
</div>
14+
</x-dynamic-component>

src/Actions/InsertBrick.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use Awcodes\Mason\Mason;
66
use Filament\Forms\Components\Actions\Action;
7+
use Filament\Forms\Components\Radio;
78
use Filament\Forms\Components\Select;
8-
use Filament\Forms\Components\ToggleButtons;
9+
use Filament\Support\Enums\Alignment;
10+
use Filament\Support\Enums\MaxWidth;
911
use Livewire\Component;
1012

1113
class InsertBrick
@@ -14,6 +16,8 @@ public static function make(): Action
1416
{
1517
return Action::make('insertBrick')
1618
->label(fn (): string => trans('mason::mason.insert_brick'))
19+
->modalWidth(MaxWidth::Small)
20+
->modalFooterActionsAlignment(Alignment::Center)
1721
->form(function (Mason $component) {
1822
return [
1923
Select::make('name')
@@ -26,15 +30,16 @@ public static function make(): Action
2630
})
2731
->searchable()
2832
->rules('required'),
29-
ToggleButtons::make('position')
33+
Radio::make('position')
3034
->label('Position')
3135
->options([
3236
'before' => 'Before',
3337
'after' => 'After',
3438
])
35-
->grouped()
39+
->inline()
3640
->default('after')
37-
->rules('required'),
41+
->rules('required')
42+
->extraAttributes(['style' => 'margin-bottom: 1rem;']),
3843
];
3944
})
4045
->action(function (Mason $component, Component $livewire, array $data, array $arguments) {

src/Brick.php

+4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
namespace Awcodes\Mason;
44

5+
use Exception;
56
use Filament\Forms\Components\Actions\Action;
67
use Illuminate\Support\Js;
78

89
class Brick extends Action
910
{
11+
/**
12+
* @throws Exception
13+
*/
1014
public function getAlpineClickHandler(): ?string
1115
{
1216
return $this->evaluate($this->alpineClickHandler) ?? '$wire.mountFormComponentAction(\'' . $this->component->getStatePath() . '\', \'' . $this->getName() . '\', { ...getEditor().getAttributes(\'' . $this->getName() . '\'), editorSelection }, ' . Js::from(['schemaComponent' => $this->component->getKey()]) . ')';

src/Bricks/Section.php

-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ public static function make(): Brick
3030
'image_shadow' => $arguments['image_shadow'] ?? null,
3131
'text' => $arguments['text'] ?? null,
3232
'image' => $arguments['image'] ?? null,
33-
'actions' => [],
34-
'actions_alignment' => null,
3533
])
3634
->form([
3735
Radio::make('background_color')

src/Concerns/HasBricks.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Awcodes\Mason\Concerns;
4+
5+
use Awcodes\Mason\Bricks\Section;
6+
use Closure;
7+
8+
trait HasBricks
9+
{
10+
protected array | Closure | null $bricks = null;
11+
12+
public function bricks(array | Closure $bricks): static
13+
{
14+
$this->bricks = $bricks;
15+
16+
return $this;
17+
}
18+
19+
public function getBricks(): array
20+
{
21+
return $this->evaluate($this->bricks) ?? [
22+
Section::make(),
23+
];
24+
}
25+
}

src/Concerns/HasSidebar.php

-14
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ trait HasSidebar
1010
{
1111
protected array | Closure | null $sidebarActions = null;
1212

13-
protected bool | Closure | null $isSidebarHidden = null;
14-
1513
protected SidebarPosition | Closure | null $sidebarPosition = null;
1614

1715
/**
@@ -24,13 +22,6 @@ public function sidebar(array | Closure $actions): static
2422
return $this;
2523
}
2624

27-
public function hiddenSidebar(bool | Closure $condition = true): static
28-
{
29-
$this->isSidebarHidden = $condition;
30-
31-
return $this;
32-
}
33-
3425
public function sidebarPosition(SidebarPosition | Closure | null $position = null): static
3526
{
3627
$this->sidebarPosition = $position;
@@ -50,9 +41,4 @@ public function getSidebarPosition(): SidebarPosition
5041
{
5142
return $this->evaluate($this->sidebarPosition) ?? SidebarPosition::End;
5243
}
53-
54-
public function isSidebarHidden(): bool
55-
{
56-
return $this->evaluate($this->isSidebarHidden) ?? false;
57-
}
5844
}

src/Facades/Mason.php

-16
This file was deleted.

src/Mason.php

+2-32
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
namespace Awcodes\Mason;
44

55
use Awcodes\Mason\Actions\InsertBrick;
6-
use Awcodes\Mason\Bricks\Section;
6+
use Awcodes\Mason\Concerns\HasBricks;
77
use Awcodes\Mason\Concerns\HasSidebar;
88
use Awcodes\Mason\Support\Helpers;
9-
use Closure;
109
use Filament\Forms\Components\Concerns\HasExtraInputAttributes;
1110
use Filament\Forms\Components\Contracts\CanBeLengthConstrained;
1211
use Filament\Forms\Components\Field;
@@ -21,13 +20,10 @@ class Mason extends Field implements CanBeLengthConstrained
2120
use HasExtraInputAttributes;
2221
use HasPlaceholder;
2322
use HasSidebar;
23+
use HasBricks;
2424

2525
protected string $view = 'mason::mason';
2626

27-
protected bool | Closure $isJson = false;
28-
29-
protected array | Closure | null $bricks = null;
30-
3127
protected function setUp(): void
3228
{
3329
parent::setUp();
@@ -78,30 +74,4 @@ public function runCommands(array $commands, array $editorSelection): void
7874
commands: array_map(fn (EditorCommand $command): array => $command->toArray(), $commands),
7975
);
8076
}
81-
82-
public function json(bool | Closure $condition = true): static
83-
{
84-
$this->isJson = $condition;
85-
86-
return $this;
87-
}
88-
89-
public function isJson(): bool
90-
{
91-
return (bool) $this->evaluate($this->isJson);
92-
}
93-
94-
public function bricks(array | Closure $bricks): static
95-
{
96-
$this->bricks = $bricks;
97-
98-
return $this;
99-
}
100-
101-
public function getBricks(): array
102-
{
103-
return $this->evaluate($this->bricks) ?? [
104-
Section::make(),
105-
];
106-
}
10777
}

src/MasonEntry.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Awcodes\Mason;
4+
5+
use Awcodes\Mason\Concerns\HasBricks;
6+
use Filament\Infolists\Components\Entry;
7+
8+
class MasonEntry extends Entry
9+
{
10+
use HasBricks;
11+
12+
protected string $view = 'mason::mason-entry';
13+
}

src/MasonPlugin.php

-37
This file was deleted.

src/MasonServiceProvider.php

+16-11
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
use Filament\Support\Assets\Asset;
1111
use Filament\Support\Facades\FilamentAsset;
1212
use Filament\Support\Facades\FilamentView;
13+
use Filament\View\PanelsRenderHook;
1314
use Illuminate\Filesystem\Filesystem;
1415
use Illuminate\Support\Facades\Blade;
1516
use Livewire\Features\SupportTesting\Testable;
1617
use Livewire\Livewire;
18+
use ReflectionException;
1719
use Spatie\LaravelPackageTools\Package;
1820
use Spatie\LaravelPackageTools\PackageServiceProvider;
1921

@@ -34,35 +36,38 @@ public function configurePackage(Package $package): void
3436

3537
public function packageRegistered(): void {}
3638

39+
/**
40+
* @throws ReflectionException
41+
*/
3742
public function packageBooted(): void
3843
{
39-
// Asset Registration
4044
FilamentAsset::register(
4145
$this->getAssets(),
4246
$this->getAssetPackageName()
4347
);
4448

45-
// Handle Stubs
4649
if (app()->runningInConsole()) {
47-
foreach (app(Filesystem::class)->files(__DIR__ . '/../stubs/') as $file) {
50+
foreach (app(abstract: Filesystem::class)->files(directory: __DIR__ . '/../stubs/') as $file) {
4851
$this->publishes([
49-
$file->getRealPath() => base_path("stubs/mason/{$file->getFilename()}"),
50-
], 'mason-stubs');
52+
$file->getRealPath() => base_path(path: "stubs/mason/{$file->getFilename()}"),
53+
], groups: 'mason-stubs');
5154
}
5255
}
5356

54-
Blade::directive('mason', fn ($expression) => "<?php echo (new Awcodes\Mason\Support\Converter({$expression}))->toHtml(); ?>");
57+
Blade::directive(
58+
name: 'mason',
59+
handler: fn ($expression) => "<?php echo (new Awcodes\Mason\Support\Converter({$expression}))->toHtml(); ?>"
60+
);
5561

56-
Livewire::component('mason.renderer', Renderer::class);
62+
Livewire::component(name: 'mason.renderer', class: Renderer::class);
5763

5864
if (! Helpers::isAuthRoute()) {
5965
FilamentView::registerRenderHook(
60-
name: 'panels::body.end',
61-
hook: fn (): string => Blade::render('@livewire("mason.renderer")')
66+
name: PanelsRenderHook::BODY_END,
67+
hook: fn (): string => Blade::render(string: '@livewire("mason.renderer")')
6268
);
6369
}
6470

65-
// Testing
6671
Testable::mixin(new TestsMason);
6772
}
6873

@@ -77,7 +82,7 @@ protected function getAssetPackageName(): ?string
7782
protected function getAssets(): array
7883
{
7984
return [
80-
AlpineComponent::make('mason', __DIR__ . '/../resources/dist/mason.js'),
85+
AlpineComponent::make(id: 'mason', path: __DIR__ . '/../resources/dist/mason.js'),
8186
];
8287
}
8388
}

0 commit comments

Comments
 (0)