Skip to content

Commit

Permalink
pint codestyle fixes / rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-sevendays-be committed Sep 29, 2023
1 parent 870950b commit 3436de8
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 66 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to `filament-page-builder` will be documented in this file.

## 3.0.0 Initial filament v3 update
- support Filamentphp v3 / Livewire v3
- disable validation for preview
- visual fixes for preview

Please note there is a bug, preventing you from saving blocks, in filament `Builder` in combination with the `filament/spatie-laravel-translatable-plugin`
https://github.com/filamentphp/filament/issues/8656

## 1.0.0 - 202X-XX-XX

- initial release
21 changes: 14 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
{
"name": "haringsrob/filament-page-builder",
"name": "sevendays/filament-page-builder",
"description": "A visual page builder for Filament",
"keywords": [
"Sevendays",
"haringsrob",
"laravel",
"filamentphp",
"filament-page-builder"
],
"homepage": "https://github.com/haringsrob/filament-page-builder",
"homepage": "https://github.com/sevendays-digital/filament-page-builder",
"license": "MIT",
"authors": [
{
"name": "Harings Rob",
"email": "[email protected]",
"role": "Developer"
},
{
"name": "Michael Metdepenningen",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
Expand All @@ -37,13 +44,13 @@
},
"autoload": {
"psr-4": {
"Haringsrob\\FilamentPageBuilder\\": "src",
"Haringsrob\\FilamentPageBuilder\\Database\\Factories\\": "database/factories"
"Sevendays\\FilamentPageBuilder\\": "src",
"Sevendays\\FilamentPageBuilder\\Database\\Factories\\": "database/factories"
}
},
"autoload-dev": {
"psr-4": {
"Haringsrob\\FilamentPageBuilder\\Tests\\": "tests"
"Sevendays\\FilamentPageBuilder\\Tests\\": "tests"
}
},
"scripts": {
Expand All @@ -66,10 +73,10 @@
"extra": {
"laravel": {
"providers": [
"Haringsrob\\FilamentPageBuilder\\FilamentPageBuilderServiceProvider"
"Sevendays\\FilamentPageBuilder\\FilamentPageBuilderServiceProvider"
],
"aliases": {
"FilamentPageBuilder": "Haringsrob\\FilamentPageBuilder\\Facades\\FilamentPageBuilder"
"FilamentPageBuilder": "Sevendays\\FilamentPageBuilder\\Facades\\FilamentPageBuilder"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion config/filament-page-builder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// config for Haringsrob/FilamentPageBuilder
// config for Sevendays/FilamentPageBuilder
return [

];
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
return new class extends Migration
{
public function up(): void
{
Schema::table('blocks', function (Blueprint $table) {
Expand Down
6 changes: 3 additions & 3 deletions src/BlockRenderer.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace Haringsrob\FilamentPageBuilder;
namespace Sevendays\FilamentPageBuilder;

use Haringsrob\FilamentPageBuilder\Blocks\BlockEditorBlock;
use Haringsrob\FilamentPageBuilder\Models\Block;
use Illuminate\Contracts\View\View;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Sevendays\FilamentPageBuilder\Blocks\BlockEditorBlock;
use Sevendays\FilamentPageBuilder\Models\Block;
use SplFileInfo;

class BlockRenderer
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BlockEditorBlock.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Haringsrob\FilamentPageBuilder\Blocks;
namespace Sevendays\FilamentPageBuilder\Blocks;

use Filament\Forms\Components\Builder\Block;
use Filament\Forms\Components\Field;
Expand Down
10 changes: 6 additions & 4 deletions src/Commands/MakePageBuilderBlock.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Haringsrob\FilamentPageBuilder\Commands;
namespace Sevendays\FilamentPageBuilder\Commands;

use Closure;
use Illuminate\Console\GeneratorCommand;
Expand Down Expand Up @@ -32,13 +32,15 @@ class MakePageBuilderBlock extends GeneratorCommand
/**
* Execute the console command.
*/
public function handle()
public function handle(): bool
{
if (parent::handle() === false && ! $this->option('force')) {
return false;
}

return $this->writeView();
$this->writeView();

return true;
}

/**
Expand Down Expand Up @@ -67,7 +69,7 @@ protected function qualifyClass($name)
/**
* Write the view for the component.
*/
protected function writeView(?Closure $onSuccess = null): void
protected function writeView(Closure $onSuccess = null): void
{
$path = $this->viewPath(
str_replace('.', '/', 'filament.blocks.'.$this->getView()).'.blade.php'
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/stubs/block.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace {{ namespace }};

use Filament\Forms\Components\TextInput;
use Haringsrob\FilamentPageBuilder\Blocks\BlockEditorBlock;
use Sevendays\FilamentPageBuilder\Blocks\BlockEditorBlock;
use Illuminate\Contracts\View\View;

class {{ class }} extends BlockEditorBlock {
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/BlockRenderer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Haringsrob\FilamentPageBuilder\Facades;
namespace Sevendays\FilamentPageBuilder\Facades;

use Illuminate\Support\Facades\Facade;

Expand Down
8 changes: 4 additions & 4 deletions src/FilamentPageBuilderServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Haringsrob\FilamentPageBuilder;
namespace Sevendays\FilamentPageBuilder;

use Filament\Support\Assets\Css;
use Filament\Support\Facades\FilamentAsset;
use Haringsrob\FilamentPageBuilder\Commands\MakePageBuilderBlock;
use Illuminate\Filesystem\Filesystem;
use Sevendays\FilamentPageBuilder\Commands\MakePageBuilderBlock;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

Expand All @@ -26,8 +26,8 @@ public function configurePackage(Package $package): void
public function packageBooted(): void
{
FilamentAsset::register([
Css::make('plugin-filament-page-builder', __DIR__ . '/../resources/dist/filament-page-builder.css'),
], 'haringsrob/filament-page-builder');
Css::make('plugin-filament-page-builder', __DIR__.'/../resources/dist/filament-page-builder.css'),
], 'sevendays/filament-page-builder');
}

public function register(): void
Expand Down
66 changes: 33 additions & 33 deletions src/Forms/Components/BlockEditor.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php

namespace Haringsrob\FilamentPageBuilder\Forms\Components;
namespace Sevendays\FilamentPageBuilder\Forms\Components;

use Closure;
use ErrorException;
use Filament\Forms\ComponentContainer;
use Filament\Forms\Components\Builder;
use Filament\Forms\Contracts\HasForms;
use Haringsrob\FilamentPageBuilder\Blocks\BlockEditorBlock;
use Haringsrob\FilamentPageBuilder\Models\Block;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

use Livewire\Component;
use Sevendays\FilamentPageBuilder\Blocks\BlockEditorBlock;
use Sevendays\FilamentPageBuilder\Models\Block;

class BlockEditor extends Builder
{
Expand Down Expand Up @@ -78,9 +78,9 @@ public function getChildComponentContainers(bool $withHidden = false): array
$records = $relationship ? $this->getCachedExistingRecords() : null;

$container = collect($this->getState())
->filter(fn(array $itemData): bool => $this->hasBlock($itemData['type']))
->filter(fn (array $itemData): bool => $this->hasBlock($itemData['type']))
->map(
fn(array $itemData, $itemIndex): ComponentContainer => $this
fn (array $itemData, $itemIndex): ComponentContainer => $this
->getBlock($itemData['type'])
->getChildComponentContainer()
->model($relationship ? $records[$itemIndex] ?? $this->getRelatedModel() : null)
Expand All @@ -90,10 +90,10 @@ public function getChildComponentContainers(bool $withHidden = false): array
)
->all();

return $container;
return $container;
}

public function relationship(string|Closure|null $name = null, ?Closure $callback = null): static
public function relationship(string|Closure $name = null, Closure $callback = null): static
{
$this->relationship = $name ?? $this->getName();
$this->modifyRelationshipQueryUsing = $callback;
Expand All @@ -107,7 +107,7 @@ public function relationship(string|Closure|null $name = null, ?Closure $callbac
});

$this->saveRelationshipsUsing(static function (BlockEditor $component, HasForms $livewire, ?array $state) {
if (!is_array($state)) {
if (! is_array($state)) {
$state = [];
}

Expand All @@ -130,7 +130,7 @@ public function relationship(string|Closure|null $name = null, ?Closure $callbac
//->whereIn($relationship->getRelated()->getQualifiedKeyName(), $recordsToDelete)
->whereKey($recordsToDelete)
->get()
->each(static fn(Model $record) => $record->delete());
->each(static fn (Model $record) => $record->delete());

$childComponentContainers = $component->getChildComponentContainers();

Expand Down Expand Up @@ -161,20 +161,20 @@ public function relationship(string|Closure|null $name = null, ?Closure $callbac

continue;

// if ($activeLocale && $record instanceof Block) {
// // Handle locale saving.
// $record->fill(Arr::except($itemData, $record->getTranslatableAttributes()));
//
// foreach (Arr::only($itemData, $record->getTranslatableAttributes()) as $key => $value) {
// $record->setTranslation($key, $activeLocale, $value);
// }
//
// $record->save();
// } else {
// $record->fill($itemData)->save();
// }
//
// continue;
// if ($activeLocale && $record instanceof Block) {
// // Handle locale saving.
// $record->fill(Arr::except($itemData, $record->getTranslatableAttributes()));
//
// foreach (Arr::only($itemData, $record->getTranslatableAttributes()) as $key => $value) {
// $record->setTranslation($key, $activeLocale, $value);
// }
//
// $record->save();
// } else {
// $record->fill($itemData)->save();
// }
//
// continue;
}

$relatedModel = $component->getRelatedModel();
Expand Down Expand Up @@ -248,13 +248,13 @@ public function getCachedExistingRecords(): Collection
$relatedKeyName = $relationship->getRelated()->getKeyName();

return $this->cachedExistingRecords = $relationshipQuery->get()->mapWithKeys(
fn(Model $item): array => ["record-{$item[$relatedKeyName]}" => $item],
fn (Model $item): array => ["record-{$item[$relatedKeyName]}" => $item],
);
}

public function getRelationship(): HasOneOrMany|BelongsToMany|null
{
if (!$this->hasRelationship()) {
if (! $this->hasRelationship()) {
return null;
}

Expand All @@ -273,7 +273,7 @@ public function getRelationshipName(): ?string

protected function getStateFromRelatedRecords(Collection $records): array
{
if (!$records->count()) {
if (! $records->count()) {
return [];
}

Expand All @@ -292,7 +292,7 @@ protected function getStateFromRelatedRecords(Collection $records): array
return $state;
}

public function mutateRelationshipDataBeforeCreate(array $data, BlockEditorBlock $item): array
public function mutateRelationshipDataBeforeCreate(array $data, Component|null|BlockEditorBlock $item): array
{
if ($this->mutateRelationshipDataBeforeCreateUsing instanceof Closure) {
$data = $this->evaluate($this->mutateRelationshipDataBeforeCreateUsing, [
Expand Down Expand Up @@ -352,12 +352,12 @@ public function mutateRelationshipDataBeforeFill(array $data): array

if (is_array($data['content'])) {
foreach ($data['content'] as $field => $value) {
if (!in_array($field, $this->coreFields, true)) {
if (! in_array($field, $this->coreFields, true)) {
$data['data'][$field] = $value;
}
}
foreach ($data['shared'] ?? [] as $field => $value) {
if (!in_array($field, $this->coreFields, true)) {
if (! in_array($field, $this->coreFields, true)) {
$data['data'][$field] = $value;
}
}
Expand All @@ -382,16 +382,16 @@ public function renderInView(string|Closure $string): static

public function preview(ComponentContainer $container): View|string
{
if (!$view = $this->evaluate($this->renderInView)) {
if (! $view = $this->evaluate($this->renderInView)) {
return __('renderInView not set or null');
}

try {
$state = [];
try{
try {
$state = $container->getState(false);
} catch (\Illuminate\Validation\ValidationException $e) {
}
catch (\Illuminate\Validation\ValidationException $e){}

return view(
$view,
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Block.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Haringsrob\FilamentPageBuilder\Models;
namespace Sevendays\FilamentPageBuilder\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
Expand All @@ -21,7 +21,7 @@ class Block extends Model

protected $casts = [
'content' => 'array',
'shared' => 'array'
'shared' => 'array',
];

public function blockable(): MorphTo
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Contracts/Blockable.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Haringsrob\FilamentPageBuilder\Models\Contracts;
namespace Sevendays\FilamentPageBuilder\Models\Contracts;

use Illuminate\Database\Eloquent\Relations\MorphMany;

Expand Down
Loading

0 comments on commit 3436de8

Please sign in to comment.