Fix editor file uploads on Livewire 3/4 and migrate remaining Livewire 2 event APIs
Closes #36 (closed)
What changed
| File | Before (Livewire 2) | After (Livewire 3/4) |
|---|---|---|
src/Traits/WithEditorFileUploads.php |
$this->dispatchBrowserEvent($eventName, ['url' => …, 'href' => …]) |
$this->dispatch($eventName, url: $url, href: $url) |
src/Traits/InteractsWithSlideOver.php (refreshParent()) |
$this->emitTo("$namespace.$parentName", $event, ...$params) |
$this->dispatch($event, ...$params)->to("$namespace.$parentName") |
resources/views/components/action-button/stack.blade.php |
Livewire.emitTo(component, method, params) |
Livewire.dispatchTo(component, method, params ? [params] : []) |
completeEditorFileUpload($uploadedUrl, $eventName)keeps its name and arguments.- Trix listener (
input/editor/trix.blade.php) needed no change: Livewire 3/4 dispatches named parameters as a browser event that bubbles towindow, withevent.detail = { url, href }— exactly whatattachment.setAttributes(event.detail)already reads. - Action buttons:
actionButtonParamsis wrapped in a one-element array so it still reaches the listener (e.g.createEdit(Model $model)) as a single positional argument, asemitTodid in Livewire 2. Without params the method is called with no arguments, as before. - Searched the package for other leftovers (
dispatchBrowserEvent,emit*,window.livewire,Livewire.emit,$wire.emit,wire:model.defer,livewire:load): none left. Stubs already use the Livewire 3$listeners/$this->js()APIs. composer.json: now requires"livewire/livewire": "^3.0|^4.0"(decision by Jannis: all consuming projects run Livewire 3.5–3.8 or 4.1–4.4). Composer refuses to install this version into a Livewire 2 app instead of breaking it silently. No other constraint changed.CHANGELOG.md(created on main by !15 (merged)): a Changed block added to the shared## 1.1.0section, and a requirement note in the README installation section.
Tests
- New
tests/EditorFileUploadCompletionTest.php: a stand-in component that uses the trait recordsdispatch()calls. It checks that completing an upload stores the file on theimagesdisk, dispatches the given event name with namedurl/hrefparameters, and clearseditorFiles. A second test checks that an unknown upload dispatches nothing. Against the old trait the test fails withCall to undefined method …::dispatchBrowserEvent(). vendor/bin/phpunitwith the new requirement: Livewire 3.8.10 — 15 tests, 45 assertions, OK; Livewire 4.4.7 — 15 tests, 45 assertions, OK (final run on d0157e37). The only notice is the existing phpunit.xml schema deprecation (also present on main). The package has noartisan, sophp artisan test --paralleldoes not apply.
Manual check (not done here — needs a Livewire 4 app)
The JS side cannot be tested in this package. Before tagging, please check in a consuming app:
- Drag an image into an
<x-bbs-input.editor.trix file-uploads wire:model="…" />in a component that usesWithEditorFileUploads. The progress bar should finish and the image should appear in the editor. - Click an action button from a slide-over with and without
actionButtonParams. The slide-over should open. - Save a slide-over that calls
refreshParent(). The listing should refresh.
Release / version bump
Not merged and not tagged, as requested.
Recommendation: MINOR release v1.1.0 (not v1.0.86). The package now declares a new hard requirement (livewire/livewire ^3.0|^4.0) and officially drops Livewire 2, so this is more than a bug fix. All consuming projects already run Livewire 3 or 4, so they can update without code changes; editor image uploads, action-button stack clicks and refreshParent() then work instead of failing with method-not-found errors. 1.1.0 also ships the editor upload route protection from !13 (merged)/!15 (merged) (#37), listed in the changelog.
Note for the related berlin-bird-studios/oekofilmtour-platform#364: its own copy of the trait stays compatible with this Trix listener if it dispatches url/href as named parameters ($this->dispatch($eventName, url: $url, href: $url)).
Prepared by BBS Copilot