@@ -40,11 +40,9 @@ $app->webview->html = '<my-element>Example</my-element>';
4040```
4141
4242For more convenient component management, you can use inheritance from the
43- ` Boson\WebView\Api\WebComponentsApi \WebComponent ` class.
43+ ` Boson\WebView\Api\WebComponents \WebComponent ` class.
4444
4545``` php
46- use Boson\WebView\Api\WebComponentsApi\WebComponent;
47-
4846class MyExampleComponent extends WebComponent
4947{
5048 // do something
@@ -56,12 +54,10 @@ class MyExampleComponent extends WebComponent
5654By default, the component does not contain any HTML content (it uses the
5755default body one passed to it). If you want to decorate it somehow or define
5856custom content, you should add the
59- ` Boson\WebView\Api\WebComponentsApi \HasTemplateInterface ` interface and
57+ ` Boson\WebView\Api\WebComponents\Component \HasTemplateInterface ` interface and
6058implement ` render() ` method.
6159
6260``` php
63- use Boson\WebView\Api\WebComponentsApi\HasTemplateInterface;
64-
6561class MyExampleComponent implements HasTemplateInterface
6662{
6763 public function render(): string
@@ -76,7 +72,7 @@ class MyExampleComponent implements HasTemplateInterface
7672## Shadow DOM
7773
7874In order to switch to shadow house rendering mode, you should implement
79- the ` Boson\WebView\Api\WebComponentsApi \HasShadowDomInterface ` interface.
75+ the ` Boson\WebView\Api\WebComponents\Component \HasShadowDomInterface ` interface.
8076
8177The shadow DOM is similar to the regular renderer, but isolates its behavior
8278from global styles and supports slots.
@@ -90,8 +86,6 @@ See more information about templates and slots in
9086</note >
9187
9288``` php
93- use Boson\WebView\Api\WebComponentsApi\HasShadowDomInterface;
94-
9589class MyExampleComponent implements HasShadowDomInterface
9690{
9791 public function render(): string
@@ -135,12 +129,10 @@ const component = document.createElement('my-element');
135129
136130In order to accurately determine that an element is connected to any physical
137131node of the DOM document, the
138- ` Boson\WebView\Api\WebComponentsApi \HasLifecycleCallbacksInterface `
132+ ` Boson\WebView\Api\WebComponents\Component \HasLifecycleCallbacksInterface `
139133interface should be implemented.
140134
141135``` php
142- use Boson\WebView\Api\WebComponentsApi\HasLifecycleCallbacksInterface;
143-
144136class MyExampleComponent implements HasLifecycleCallbacksInterface
145137{
146138 public function onConnect(): void
@@ -167,7 +159,7 @@ If you leave the code as is, then when you click on the element,
167159a JS error will be thrown: ` Uncaught TypeError: this.update is not a function ` .
168160
169161To implement a method (for example, "` update() ` "), you should implement the
170- ` Boson\WebView\Api\WebComponentsApi \HasMethodsInterface ` interface.
162+ ` Boson\WebView\Api\WebComponents\Component \HasMethodsInterface ` interface.
171163
172164``` php
173165class MyExampleComponent implements HasMethodsInterface
@@ -256,12 +248,10 @@ try {
256248
257249In addition to methods, each HTML element has attributes. You can subscribe
258250to change, add or remove an attribute by implementing the
259- ` Boson\WebView\Api\WebComponentsApi\HasObservedAttributesInterface ` interface.
251+ ` Boson\WebView\Api\WebComponents\Component\HasAttributesInterface ` interface.
260252
261253``` php
262- use Boson\WebView\Api\WebComponentsApi\HasObservedAttributesInterface;
263-
264- class MyExampleComponent implements HasObservedAttributesInterface
254+ class MyExampleComponent implements HasAttributesInterface
265255{
266256 public function onAttributeChanged(
267257 string $attribute,
@@ -271,14 +261,14 @@ class MyExampleComponent implements HasObservedAttributesInterface
271261 // ...
272262 }
273263
274- public static function getObservedAttributeNames (): array
264+ public static function getAttributeNames (): array
275265 {
276266 // ...
277267 }
278268}
279269```
280270
281- Method ` getObservedAttributeNames ()` must return a list of attributes
271+ Method ` getAttributeNames ()` must return a list of attributes
282272(strings) to be processed.
283273
284274Method ` onAttributeChanged() ` contains a callback that is called when
@@ -290,6 +280,79 @@ the attribute value changes.
290280| ` string ` | ` string ` | Attribute value has been changed |
291281| ` null ` | ` string ` | Attribute has been removed |
292282
283+
284+ ## Component Events
285+
286+ Each web component supports the ability to listen several component events
287+ and process them.
288+
289+ To implement an event listener (for example, "[ ` click ` ] ( https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent ) "),
290+ you should implement the ` Boson\WebView\Api\WebComponents\Component\HasEventListenersInterface ` interface.
291+
292+ ``` php
293+ class MyExampleComponent implements HasEventListenersInterface
294+ {
295+ public function onEventFired(string $event, array $args = []): void
296+ {
297+ // ...
298+ }
299+
300+ public static function getEventListeners(): array
301+ {
302+ // ...
303+ }
304+ }
305+ ```
306+
307+ If you want to listen ` click ` event, then ` getEventListeners() ` method
308+ must return the corresponding name.
309+
310+ ``` php
311+ public static function getEventListeners(): array
312+ {
313+ return [
314+ 'click' => [],
315+ ];
316+ }
317+ ```
318+
319+ If you require any specific information related to an event, then the list
320+ of event fields should be passed as an array value.
321+
322+ For example, ` click ` event contain readonly properties such as ` clientX `
323+ and ` clientY ` .
324+
325+ ``` php
326+ public static function getEventListeners(): array
327+ {
328+ return [
329+ 'click' => [
330+ // "clientX" property from "click" event
331+ 'clientX',
332+ // "clientY" property from "click" event
333+ 'clientY',
334+ ],
335+ ];
336+ }
337+ ```
338+
339+ If specific PHP array key names are required for these properties,
340+ they should be specified as keys.
341+
342+ ``` php
343+ public static function getEventListeners(): array
344+ {
345+ return [
346+ 'click' => [
347+ // "clientX" property from "click" event passed as "x"
348+ 'x' => 'clientX',
349+ // "clientX" property from "click" event passed as "y"
350+ 'y' => 'clientY',
351+ ],
352+ ];
353+ }
354+ ```
355+
293356## Reactive Context
294357
295358The reactive context allows you to modify and retrieve values from a
@@ -298,7 +361,7 @@ component programmatically.
298361By default, it is passed to the constructor as the first argument.
299362
300363``` php
301- use Boson\WebView\Api\WebComponentsApi \ReactiveContext;
364+ use Boson\WebView\Api\WebComponents \ReactiveContext;
302365use Boson\WebView\WebView;
303366
304367class MyExampleComponent
0 commit comments