Skip to content

Commit

Permalink
feat: Update internalPreviewUrl config entry
Browse files Browse the repository at this point in the history
  • Loading branch information
pboivin committed Oct 3, 2023
1 parent cf9905d commit dbe4740
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
12 changes: 7 additions & 5 deletions config/filament-peek.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,19 @@

/*
|--------------------------------------------------------------------------
| Use Internal Preview URL
| Internal Preview URL
|--------------------------------------------------------------------------
|
| Set this to `true` to render all Blade previews through an internal URL.
| Enable this option to render all Blade previews through an internal URL.
| This improves the isolation of the iframe in the context of the page.
| Add additional middleware for this URL in the `middleware` array.
|
*/

'useInternalPreviewUrl' => false,

'internalPreviewUrlMiddleWare' => [],
'internalPreviewUrl' => [
'enabled' => false,
'middleware' => [],
],

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Here are the main options you can configure:
| `allowIframeOverflow` | `bool` | Allow the iframe dimensions to go beyond the capacity of the available preview modal area. |
| `allowIframePointerEvents` | `bool` | Allow all pointer events within the iframe. By default, only scrolling is allowed. (Does not apply when using a preview URL. See [Pointer Events](./page-previews.md#preview-pointer-events)) |
| `closeModalWithEscapeKey` | `bool` | Close the preview modal by pressing the Escape key. (Does not apply to Builder previews.) |
| `useInternalPreviewUrl` | `bool` | Render Blade previews through an internal URL. |
| `internalPreviewUrl` | `array` | Render Blade previews through an internal URL. |
| `builderEditor` | `array` | Options related to the Editor sidebar in [Builder Previews](./builder-previews.md). |

Builder Editor options:
Expand Down
4 changes: 2 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
use Illuminate\Support\Facades\Route;
use Pboivin\FilamentPeek\CachedPreview;

if (config('filament-peek.useInternalPreviewUrl', false)) {
if (config('filament-peek.internalPreviewUrl.enabled', false)) {
Route::prefix('filament-peek')
->middleware(config('filament-peek.internalPreviewUrlMiddleWare', []))
->middleware(config('filament-peek.internalPreviewUrl.middleware', []))
->group(function () {
Route::get('preview', function () {
abort_unless($token = Request::query('token'), 404);
Expand Down
17 changes: 7 additions & 10 deletions src/Livewire/BuilderEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ public function openBuilderEditor(

public function refreshBuilderPreview(): void
{
if (! $this->pageClass || ! $this->builderName) {
if (!$this->pageClass || !$this->builderName) {
return;
}

if (! $this->previewUrl && ! $this->previewView) {
if (!$this->previewUrl && !$this->previewView) {
throw new InvalidArgumentException('Missing preview modal URL or Blade view.');
}

Expand Down Expand Up @@ -177,7 +177,7 @@ public function submit(): void

protected function getFormSchema(): array
{
if (! $this->pageClass || ! $this->builderName) {
if (!$this->pageClass || !$this->builderName) {
return [];
}

Expand All @@ -195,11 +195,11 @@ protected function getFormStatePath(): ?string

protected function getPreviewData(): array
{
if (! $this->pageClass || ! $this->builderName) {
if (!$this->pageClass || !$this->builderName) {
return [];
}

if (! $this->previewData) {
if (!$this->previewData) {
$formState = $this->form->getState();

$this->previewData = $this->pageClass::mutateBuilderPreviewData(
Expand Down Expand Up @@ -255,10 +255,7 @@ protected function getPreviewModalHtmlContent(): ?string

protected function shouldUseInternalPreviewUrl()
{
if (! is_null($config = config('filament-peek.builderEditor.useInternalPreviewUrl'))) {
return $config;
}

return config('filament-peek.useInternalPreviewUrl', false);
return config('filament-peek.builderEditor.useInternalPreviewUrl', true)
&& config('filament-peek.internalPreviewUrl.enabled', false);
}
}
2 changes: 1 addition & 1 deletion src/Pages/Concerns/HasPreviewModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function openPreviewModal(): void
if ($previewModalUrl = $this->getPreviewModalUrl()) {
// pass
} elseif ($view = $this->getPreviewModalView()) {
if (config('filament-peek.useInternalPreviewUrl', false)) {
if (config('filament-peek.internalPreviewUrl.enabled', false)) {
$token = app(Support\Cache::class)->createPreviewToken();

CachedPreview::make(static::class, $view, $this->previewModalData)->put($token);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/TestCaseWithPreviewUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TestCaseWithPreviewUrl extends TestCase
{
protected function configurePackageProviders($app)
{
Config::set('filament-peek.useInternalPreviewUrl', true);
Config::set('filament-peek.internalPreviewUrl.enabled', true);

TestPanelProvider::$should_load_plugin_assets = false;
}
Expand Down

0 comments on commit dbe4740

Please sign in to comment.