Skip to content

Commit

Permalink
Merge pull request #103 from pboivin/feat/internal-preview-url-config
Browse files Browse the repository at this point in the history
[2.x] feat: Update internalPreviewUrl config entry and route
  • Loading branch information
pboivin committed Oct 10, 2023
2 parents fae5e3a + 2be130e commit 9c9fd79
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 16 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 → routes/preview.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
2 changes: 1 addition & 1 deletion src/FilamentPeekServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public function configurePackage(Package $package): void
->hasTranslations()
->hasConfigFile()
->hasViews()
->hasRoute('web');
->hasRoute('preview');
}
}
7 changes: 2 additions & 5 deletions src/Livewire/BuilderEditor.php
Original file line number Diff line number Diff line change
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 9c9fd79

Please sign in to comment.