Skip to content

Commit cb41e5d

Browse files
committed
Add fallback if locale is not found + limit event listeners to form instead of window
1 parent 3373a9f commit cb41e5d

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

resources/dist/filament-live-preview.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/live-preview/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ document.addEventListener('peek:modal-initialized', (event) => {
128128
if (livePreviewForm) {
129129
const refreshPreviewEvent = () => $modal.refreshPreview()
130130

131-
window.addEventListener('input', refreshPreviewEvent)
132-
window.addEventListener('change', refreshPreviewEvent)
131+
livePreviewForm.addEventListener('input', refreshPreviewEvent)
132+
livePreviewForm.addEventListener('change', refreshPreviewEvent)
133133
window.addEventListener('submit', refreshPreviewEvent)
134-
window.addEventListener('pointerout', refreshPreviewEvent)
134+
livePreviewForm.addEventListener('mouseup', refreshPreviewEvent)
135+
livePreviewForm.addEventListener('keyup', refreshPreviewEvent)
135136
}
136137
})

src/Filament/Traits/HasLivePreviewComponent.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Pboivin\FilamentPeek\Support\Cache;
1212
use Wotz\FilamentLivePreview\CachedPreview;
1313
use Wotz\FilamentLivePreview\Events\RefreshLivePreview;
14+
use Wotz\LocaleCollection\Facades\LocaleCollection;
1415

1516
trait HasLivePreviewComponent
1617
{
@@ -119,6 +120,10 @@ public function openPreview(): void
119120

120121
$locale = $request->query('locale');
121122

123+
if (! LocaleCollection::firstLocale($locale)) {
124+
$locale = LocaleCollection::first()->locale();
125+
}
126+
122127
CachedPreview::make(static::class, $view, $this->previewModalData, $locale)
123128
->put($this->token, config('filament-peek.internalPreviewUrl.cacheDuration', 60));
124129

0 commit comments

Comments
 (0)