@alwatr/action 9.26.0 → 9.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -208
- package/dist/action-service.d.ts +178 -0
- package/dist/action-service.d.ts.map +1 -0
- package/dist/main.d.ts +92 -69
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +3 -3
- package/dist/main.js.map +5 -7
- package/package.json +2 -2
- package/src/action-service.ts +397 -0
- package/src/main.ts +116 -69
- package/dist/delegate.d.ts +0 -126
- package/dist/delegate.d.ts.map +0 -1
- package/dist/lib_.d.ts +0 -24
- package/dist/lib_.d.ts.map +0 -1
- package/dist/method.d.ts +0 -169
- package/dist/method.d.ts.map +0 -1
- package/dist/registry_.d.ts +0 -24
- package/dist/registry_.d.ts.map +0 -1
- package/src/delegate.ts +0 -359
- package/src/lib_.ts +0 -27
- package/src/method.ts +0 -219
- package/src/registry_.ts +0 -109
package/src/registry_.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import type {ModifierHandler, PayloadResolver} from './type.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Registry of all named modifier handlers.
|
|
5
|
-
*
|
|
6
|
-
* Keys are modifier names used in the `on-<eventType>` attribute syntax
|
|
7
|
-
* (e.g. `on-click="action-id; prevent"`). Values are `ModifierHandler` functions.
|
|
8
|
-
* Populated at module load with built-in modifiers; extended at runtime via
|
|
9
|
-
* `registerModifier`.
|
|
10
|
-
*
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export const modifierRegistry = new Map<string, ModifierHandler>();
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Registry of all named payload resolvers.
|
|
17
|
-
*
|
|
18
|
-
* Keys are resolver tokens used in the `on-<eventType>` attribute syntax
|
|
19
|
-
* (e.g. `on-input="ui_search_query:$value"`). Values are `PayloadResolver` functions.
|
|
20
|
-
* Populated at module load with built-in resolvers; extended at runtime via
|
|
21
|
-
* `registerPayloadResolver`.
|
|
22
|
-
*
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
export const payloadRegistry = new Map<string, PayloadResolver>();
|
|
26
|
-
|
|
27
|
-
// ─── Built-in Modifiers ───────────────────────────────────────────────────────
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* `prevent` — calls `event.preventDefault()` before dispatching.
|
|
31
|
-
*
|
|
32
|
-
* Use it to suppress the browser's default behaviour (e.g. form submission,
|
|
33
|
-
* link navigation, context menu).
|
|
34
|
-
*
|
|
35
|
-
* @example `<form on-submit="ui_submit-form; prevent">`
|
|
36
|
-
*/
|
|
37
|
-
modifierRegistry.set('prevent', (event) => {
|
|
38
|
-
event.preventDefault();
|
|
39
|
-
return true;
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* `validate` — cancels the dispatch if the nearest `<form>` fails validation.
|
|
44
|
-
*
|
|
45
|
-
* Looks for a `<form>` ancestor (or the element itself if it is a form) and
|
|
46
|
-
* calls `checkValidity()`. If the form is invalid the action is not dispatched,
|
|
47
|
-
* allowing native constraint-validation UI to surface errors. If no form is
|
|
48
|
-
* found the dispatch is also cancelled.
|
|
49
|
-
*
|
|
50
|
-
* Pair with `prevent` on `submit` events to avoid page reloads:
|
|
51
|
-
*
|
|
52
|
-
* @example `<form on-submit="ui_submit_form:$formdata; prevent,validate" novalidate>`
|
|
53
|
-
*/
|
|
54
|
-
modifierRegistry.set('validate', (_event, element) => {
|
|
55
|
-
const form = element instanceof HTMLFormElement ? element : element.closest('form');
|
|
56
|
-
if (!form) return false;
|
|
57
|
-
return form.checkValidity();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// ─── Built-in Payload Resolvers ───────────────────────────────────────────────
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* `$value` — resolves to the element's `.value` property at dispatch time.
|
|
64
|
-
*
|
|
65
|
-
* Works with any element that exposes a `value` property: `<input>`,
|
|
66
|
-
* `<textarea>`, `<select>`. Returns `null` for elements without `.value`.
|
|
67
|
-
*
|
|
68
|
-
* @example `<input on-input="ui_search_query:$value" />`
|
|
69
|
-
*/
|
|
70
|
-
payloadRegistry.set('$value', (_event, element) => {
|
|
71
|
-
return 'value' in element ? (element as {value: unknown}).value : null;
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* `$formdata` — resolves to a plain object of all fields in the nearest `<form>`.
|
|
76
|
-
*
|
|
77
|
-
* Collects entries via `FormData` and converts them to a `Record<string, FormDataEntryValue>`.
|
|
78
|
-
* Looks for a `<form>` ancestor (or the element itself). Returns `null` when no
|
|
79
|
-
* form is found.
|
|
80
|
-
*
|
|
81
|
-
* @example `<form on-submit="ui_submit_form:$formdata; prevent,validate">`
|
|
82
|
-
* ```ts
|
|
83
|
-
* onAction('ui_submit_form', (action) => {
|
|
84
|
-
* console.log(action.payload); // {username: 'ali', password: '…'}
|
|
85
|
-
* });
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
payloadRegistry.set('$formdata', (_event, element) => {
|
|
89
|
-
const form = element instanceof HTMLFormElement ? element : element.closest('form');
|
|
90
|
-
return form ? Object.fromEntries(new FormData(form)) : null;
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* `$checked` — resolves to the `.checked` boolean property of a checkbox or radio input.
|
|
95
|
-
*
|
|
96
|
-
* Works with `<input type="checkbox">` and `<input type="radio">`.
|
|
97
|
-
* Returns `null` for elements that do not have a `checked` property.
|
|
98
|
-
*
|
|
99
|
-
* @example `<input type="checkbox" on-change="ui_toggle_feature:$checked" />`
|
|
100
|
-
* ```ts
|
|
101
|
-
* onAction('ui_toggle_feature', (action) => {
|
|
102
|
-
* console.log(action.payload); // true or false
|
|
103
|
-
* featureSignal.set(action.payload);
|
|
104
|
-
* });
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
payloadRegistry.set('$checked', (_event, element) => {
|
|
108
|
-
return 'checked' in element ? (element as HTMLInputElement).checked : null;
|
|
109
|
-
});
|