Skip to content

Let UI plugins register custom Blade @event names - #432

Merged
simonhamp merged 3 commits into
NativePHP:mainfrom
thelemon2020:feat/plugin-custom-element-events
Oct 2, 2026
Merged

simonhamp merged 3 commits into
NativePHP:mainfrom
thelemon2020:feat/plugin-custom-element-events

Conversation

@thelemon2020

Copy link
Copy Markdown
Contributor

Summary

  • UI plugins can declare first-class Blade handlers (@link, @scan, @signed, …) instead of hijacking @change.
  • Names are opt-in via components[].element_events in nativephp.json and/or Element::elementEvents(). Unregistered @foo still compiles as a child-component _event-foo binding ($this->emit()).
  • The collector wires _link → onLink(), _scan → onScan(), including hyphenated names (@link-tapped → onLinkTapped()). Native renderers can keep sending the payload with sendTextChangeEvent; PHP already routes by callback id.

Registered names are global at compile time, same as @change. If a plugin registers link, @link on a nested child component is no longer $this->emit('link').

Site docs at plugins/ui-components still show _change="updateLabel" — that page lives in nativephp.com and can follow once this lands.

Test plan

  • vendor/bin/pest tests/Unit/Edge/ComponentEventBindingPrecompilerTest.php tests/Unit/Edge/NativeElementCollectorTest.php tests/Unit/Edge/UiPluginComponentBootTest.php tests/Unit/Plugins/PluginManifestValidationTest.php
  • Confirm <native:markdown @link="open"> compiles to _link after registering link, and that unregistered @order-shipped still becomes _event-order-shipped
  • Confirm @if / @endif are untouched
  • Confirm _event-* attrs are still stripped from plain elements
  • Confirm a plugin Element with onScan() receives the handler when @scan is declared
  • Confirm nativephp.json element_events are registered at boot via registerUiPluginComponents()

Made with Cursor

thelemon2020 and others added 3 commits September 10, 2026 09:59
Unknown @foo was rewritten as a child-component binding, so plugin
authors had to hijack @change. Declared names now compile like @press
and wire to matching onX() methods.

Co-authored-by: Cursor <cursoragent@cursor.com>
Only registered names are wired at apply time, and registerUiPluginComponents
is tested so nativephp.json element_events actually reach the precompiler.

Co-authored-by: Cursor <cursoragent@cursor.com>
@simonhamp

Copy link
Copy Markdown
Member

This is great! Mind adding the docs for it over on the nativephp.com repo when you get the chance?

@simonhamp
simonhamp merged commit ee03682 into NativePHP:main Oct 2, 2026
5 checks passed
@thelemon2020

Copy link
Copy Markdown
Contributor Author

@simonhamp Docs are up here: NativePHP/nativephp.com#552

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants