@oscarpalmer/abydon 0.6.0 → 0.7.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/dist/index.js +12 -3
- package/package.json +1 -1
- package/src/html.ts +1 -1
- package/src/node/event.ts +18 -4
package/dist/index.js
CHANGED
|
@@ -182,10 +182,19 @@ function setReactiveNode(comment, reactive3) {
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
// src/node/event.ts
|
|
185
|
+
var getOptions = function(options) {
|
|
186
|
+
const parts = options.split(":");
|
|
187
|
+
return {
|
|
188
|
+
capture: parts.includes("c") || parts.includes("capture"),
|
|
189
|
+
once: parts.includes("o") || parts.includes("once"),
|
|
190
|
+
passive: !parts.includes("a") && !parts.includes("active")
|
|
191
|
+
};
|
|
192
|
+
};
|
|
185
193
|
function mapEvent(element, name, value10) {
|
|
186
194
|
element.removeAttribute(name);
|
|
187
|
-
|
|
188
|
-
|
|
195
|
+
const [, type, options] = /^@(\w+)(?::([a-z:]+))?$/.exec(name) ?? [];
|
|
196
|
+
if (typeof value10 === "function" && type != null) {
|
|
197
|
+
element.addEventListener(type, value10, getOptions(options ?? ""));
|
|
189
198
|
}
|
|
190
199
|
}
|
|
191
200
|
|
|
@@ -480,7 +489,7 @@ var handleExpression = function(data2, prefix, expression) {
|
|
|
480
489
|
}
|
|
481
490
|
return `${prefix}${expressions}`;
|
|
482
491
|
}
|
|
483
|
-
if (typeof expression === "object") {
|
|
492
|
+
if (typeof expression === "function" || typeof expression === "object") {
|
|
484
493
|
const index = data2.values.push(expression) - 1;
|
|
485
494
|
return `${prefix}<!--abydon.${index}-->`;
|
|
486
495
|
}
|
package/package.json
CHANGED
package/src/html.ts
CHANGED
|
@@ -23,7 +23,7 @@ function handleExpression(
|
|
|
23
23
|
return `${prefix}${expressions}`;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
if (typeof expression === 'object') {
|
|
26
|
+
if (typeof expression === 'function' || typeof expression === 'object') {
|
|
27
27
|
const index = data.values.push(expression) - 1;
|
|
28
28
|
|
|
29
29
|
return `${prefix}<!--abydon.${index}-->`;
|
package/src/node/event.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import type {FragmentElement} from '../models';
|
|
2
2
|
|
|
3
|
+
function getOptions(options: string): AddEventListenerOptions {
|
|
4
|
+
const parts = options.split(':');
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
capture: parts.includes('c') || parts.includes('capture'),
|
|
8
|
+
once: parts.includes('o') || parts.includes('once'),
|
|
9
|
+
passive: !parts.includes('a') && !parts.includes('active'),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
3
13
|
export function mapEvent(
|
|
4
14
|
element: FragmentElement,
|
|
5
15
|
name: string,
|
|
@@ -7,9 +17,13 @@ export function mapEvent(
|
|
|
7
17
|
): void {
|
|
8
18
|
element.removeAttribute(name);
|
|
9
19
|
|
|
10
|
-
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
20
|
+
const [, type, options] = /^@(\w+)(?::([a-z:]+))?$/.exec(name) ?? [];
|
|
13
21
|
|
|
14
|
-
|
|
22
|
+
if (typeof value === 'function' && type != null) {
|
|
23
|
+
element.addEventListener(
|
|
24
|
+
type,
|
|
25
|
+
value as EventListener,
|
|
26
|
+
getOptions(options ?? ''),
|
|
27
|
+
);
|
|
28
|
+
}
|
|
15
29
|
}
|