@domql/event 2.5.168 → 2.5.169

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.
Files changed (3) hide show
  1. package/dist/cjs/on.js +13 -8
  2. package/on.js +13 -5
  3. package/package.json +3 -3
package/dist/cjs/on.js CHANGED
@@ -27,24 +27,30 @@ __export(on_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(on_exports);
29
29
  var import_utils = require("@domql/utils");
30
+ const getOnOrPropsEvent = (param, element) => {
31
+ var _a, _b;
32
+ const onEvent = (_a = element.on) == null ? void 0 : _a[param];
33
+ const onPropEvent = (_b = element.props) == null ? void 0 : _b["on" + param.slice(0, 1).toUpperCase() + param.slice(1)];
34
+ return onEvent || onPropEvent;
35
+ };
30
36
  const applyEvent = (param, element, state, context, options) => {
31
37
  return param.call(element, element, state || element.state, context || element.context, options);
32
38
  };
33
39
  const triggerEventOn = (param, element, options) => {
34
- var _a;
35
- if (element.on && (0, import_utils.isFunction)(element.on[param])) {
40
+ const appliedFunction = getOnOrPropsEvent(param, element);
41
+ if (appliedFunction) {
36
42
  const { state, context } = element;
37
- return applyEvent(element.on[param] || ((_a = element.props) == null ? void 0 : _a[param]), element, state, context, options);
43
+ return applyEvent(appliedFunction, element, state, context, options);
38
44
  }
39
45
  };
40
46
  const applyEventUpdate = (param, updatedObj, element, state, context, options) => {
41
47
  return param.call(element, updatedObj, element, state || element.state, context || element.context, options);
42
48
  };
43
49
  const triggerEventOnUpdate = (param, updatedObj, element, options) => {
44
- var _a;
45
- if (element.on && (0, import_utils.isFunction)(element.on[param])) {
50
+ const appliedFunction = getOnOrPropsEvent(param, element);
51
+ if (appliedFunction) {
46
52
  const { state, context } = element;
47
- return applyEventUpdate(element.on[param] || ((_a = element.props) == null ? void 0 : _a[param]), updatedObj, element, state, context, options);
53
+ return applyEventUpdate(appliedFunction, updatedObj, element, state, context, options);
48
54
  }
49
55
  };
50
56
  const applyAnimationFrame = (element, options) => {
@@ -57,12 +63,11 @@ const applyAnimationFrame = (element, options) => {
57
63
  }
58
64
  };
59
65
  const applyEventsOnNode = (element, options) => {
60
- var _a;
61
66
  const { node, on } = element;
62
67
  for (const param in on) {
63
68
  if (param === "init" || param === "beforeClassAssign" || param === "render" || param === "renderRouter" || param === "attachNode" || param === "stateInit" || param === "stateCreated" || param === "beforeStateUpdate" || param === "stateUpdate" || param === "beforeUpdate" || param === "done" || param === "create" || param === "complete" || param === "frame" || param === "update")
64
69
  continue;
65
- const appliedFunction = element.on[param] || ((_a = element.props) == null ? void 0 : _a[param]);
70
+ const appliedFunction = getOnOrPropsEvent(param, element);
66
71
  if ((0, import_utils.isFunction)(appliedFunction)) {
67
72
  node.addEventListener(param, (event) => {
68
73
  const { state, context } = element;
package/on.js CHANGED
@@ -2,14 +2,21 @@
2
2
 
3
3
  import { isFunction } from '@domql/utils'
4
4
 
5
+ const getOnOrPropsEvent = (param, element) => {
6
+ const onEvent = element.on?.[param]
7
+ const onPropEvent = element.props?.['on' + param.slice(0, 1).toUpperCase() + param.slice(1)]
8
+ return onEvent || onPropEvent
9
+ }
10
+
5
11
  export const applyEvent = (param, element, state, context, options) => {
6
12
  return param.call(element, element, state || element.state, context || element.context, options)
7
13
  }
8
14
 
9
15
  export const triggerEventOn = (param, element, options) => {
10
- if (element.on && isFunction(element.on[param])) {
16
+ const appliedFunction = getOnOrPropsEvent(param, element)
17
+ if (appliedFunction) {
11
18
  const { state, context } = element
12
- return applyEvent(element.on[param] || element.props?.[param], element, state, context, options)
19
+ return applyEvent(appliedFunction, element, state, context, options)
13
20
  }
14
21
  }
15
22
 
@@ -18,9 +25,10 @@ export const applyEventUpdate = (param, updatedObj, element, state, context, opt
18
25
  }
19
26
 
20
27
  export const triggerEventOnUpdate = (param, updatedObj, element, options) => {
21
- if (element.on && isFunction(element.on[param])) {
28
+ const appliedFunction = getOnOrPropsEvent(param, element)
29
+ if (appliedFunction) {
22
30
  const { state, context } = element
23
- return applyEventUpdate(element.on[param] || element.props?.[param], updatedObj, element, state, context, options)
31
+ return applyEventUpdate(appliedFunction, updatedObj, element, state, context, options)
24
32
  }
25
33
  }
26
34
 
@@ -54,7 +62,7 @@ export const applyEventsOnNode = (element, options) => {
54
62
  param === 'update'
55
63
  ) continue
56
64
 
57
- const appliedFunction = element.on[param] || element.props?.[param]
65
+ const appliedFunction = getOnOrPropsEvent(param, element)
58
66
  if (isFunction(appliedFunction)) {
59
67
  node.addEventListener(param, event => {
60
68
  const { state, context } = element
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/event",
3
- "version": "2.5.168",
3
+ "version": "2.5.169",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/esm/index.js",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@domql/report": "^2.5.162",
31
- "@domql/utils": "^2.5.168"
31
+ "@domql/utils": "^2.5.169"
32
32
  },
33
- "gitHead": "6c935c3d1ff70096bb532e9c5426ffc5af0677dc"
33
+ "gitHead": "ae523f95551eac614ee00baf3c425cb6c4271a2c"
34
34
  }