@lynx-js/web-mainthread-apis 0.18.4 → 0.19.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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @lynx-js/web-mainthread-apis
2
2
 
3
+ ## 0.19.0
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: capture and bind event listener should be trigger correctly ([#1972](https://github.com/lynx-family/lynx-stack/pull/1972))
8
+
9
+ - fix: the l-p-comp-uid of page should be '1' ([#1970](https://github.com/lynx-family/lynx-stack/pull/1970))
10
+
11
+ - Updated dependencies []:
12
+ - @lynx-js/web-constants@0.19.0
13
+
3
14
  ## 0.18.4
4
15
 
5
16
  ### Patch Changes
Binary file
Binary file
Binary file
@@ -27,12 +27,22 @@ export function createMainThreadGlobalThis(config) {
27
27
  ?.deref();
28
28
  let uniqueIdInc = lynxUniqueIdToElement.length || 1;
29
29
  const exposureChangedElements = new Set();
30
- const commonHandler = (event) => {
30
+ const commonHandler = (event, capture) => {
31
31
  if (!event.currentTarget) {
32
32
  return;
33
33
  }
34
+ // The `capture false` event should not be triggered during the capture-phase
35
+ // The `capture true` event should not be triggered during the bubbling phase
36
+ if ((event.eventPhase === Event.CAPTURING_PHASE && capture === false)
37
+ || (event.eventPhase === Event.BUBBLING_PHASE && capture === true)) {
38
+ return;
39
+ }
34
40
  const currentTarget = event.currentTarget;
35
- const isCapture = event.eventPhase === Event.CAPTURING_PHASE;
41
+ // When the event is triggered by the target element, `event.eventPhase` is always `target`, and the listener type is determined by the passed-in `capture`.
42
+ // When the event is triggered by a non-target element, the listener type is determined by `event.eventPhase` (1, 3).
43
+ const isCapture = event.eventPhase === Event.AT_TARGET
44
+ ? capture
45
+ : event.eventPhase === event.CAPTURING_PHASE;
36
46
  const lynxEventName = W3cEventNameToLynx[event.type] ?? event.type;
37
47
  const runtimeInfo = elementToRuntimeInfoMap.get(currentTarget);
38
48
  if (runtimeInfo) {
@@ -70,11 +80,23 @@ export function createMainThreadGlobalThis(config) {
70
80
  }
71
81
  return false;
72
82
  };
73
- const commonCatchHandler = (event) => {
74
- const handlerTriggered = commonHandler(event);
83
+ const captureHandler = (e) => {
84
+ commonHandler(e, true);
85
+ };
86
+ const defaultHandler = (e) => {
87
+ commonHandler(e, false);
88
+ };
89
+ const commonCatchHandler = (event, isCapture) => {
90
+ const handlerTriggered = commonHandler(event, isCapture);
75
91
  if (handlerTriggered)
76
92
  event.stopPropagation();
77
93
  };
94
+ const catchCaptureHandler = (e) => {
95
+ commonCatchHandler(e, true);
96
+ };
97
+ const defaultCatchHandler = (e) => {
98
+ commonCatchHandler(e, false);
99
+ };
78
100
  const __AddEvent = (element, eventType, eventName, newEventHandler) => {
79
101
  eventName = eventName.toLowerCase();
80
102
  const isCatch = eventType === 'catchEvent' || eventType === 'capture-catch';
@@ -88,8 +110,8 @@ export function createMainThreadGlobalThis(config) {
88
110
  ? runtimeInfo.eventHandlerMap[eventName]?.capture
89
111
  : runtimeInfo.eventHandlerMap[eventName]?.bind;
90
112
  const currentRegisteredHandler = isCatch
91
- ? commonCatchHandler
92
- : commonHandler;
113
+ ? (isCapture ? catchCaptureHandler : defaultCatchHandler)
114
+ : (isCapture ? captureHandler : defaultHandler);
93
115
  if (currentHandler) {
94
116
  if (!newEventHandler) {
95
117
  /**
@@ -210,7 +232,7 @@ export function createMainThreadGlobalThis(config) {
210
232
  const page = __CreateElement('page', 0);
211
233
  page.setAttribute('part', 'page');
212
234
  page.setAttribute(cssIdAttribute, cssID + '');
213
- page.setAttribute(parentComponentUniqueIdAttribute, '0');
235
+ page.setAttribute(parentComponentUniqueIdAttribute, '1');
214
236
  page.setAttribute(componentIdAttribute, componentID);
215
237
  __MarkTemplateElement(page);
216
238
  if (pageConfig.defaultDisplayLinear === false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-mainthread-apis",
3
- "version": "0.18.4",
3
+ "version": "0.19.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "hyphenate-style-name": "^1.1.0",
30
30
  "wasm-feature-detect": "^1.8.0",
31
- "@lynx-js/web-constants": "0.18.4"
31
+ "@lynx-js/web-constants": "0.19.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "binaryen": "^125.0.0",