@lynx-js/web-mainthread-apis 0.10.0 → 0.11.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,23 @@
1
1
  # @lynx-js/web-mainthread-apis
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: support mts event handler (1/n) ([#495](https://github.com/lynx-family/lynx-stack/pull/495))
8
+
9
+ now the main-thread:bind handler could be invoked. The params of the handler will be implemented later.
10
+
11
+ - Updated dependencies [[`ea42e62`](https://github.com/lynx-family/lynx-stack/commit/ea42e62fbcd5c743132c3e6e7c4851770742d544), [`a0f5ca4`](https://github.com/lynx-family/lynx-stack/commit/a0f5ca4ea0895ccbaa6aa63f449f53a677a1cf73)]:
12
+ - @lynx-js/web-constants@0.11.0
13
+
14
+ ## 0.10.1
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [[`1af3b60`](https://github.com/lynx-family/lynx-stack/commit/1af3b6052ab27f98bf0e4d1b0ec9f7d9e88e0afc)]:
19
+ - @lynx-js/web-constants@0.10.1
20
+
3
21
  ## 0.10.0
4
22
 
5
23
  ### Minor Changes
@@ -1,5 +1,6 @@
1
1
  import { type MainThreadConfig, MainThreadRuntime } from './MainThreadRuntime.js';
2
2
  export declare function createMainThreadLynx(config: MainThreadConfig, lepusRuntime: MainThreadRuntime): {
3
+ getJSContext(): EventTarget;
3
4
  requestAnimationFrame(cb: FrameRequestCallback): number;
4
5
  cancelAnimationFrame(handler: number): void;
5
6
  __globalProps: unknown;
@@ -1,6 +1,10 @@
1
1
  import { MainThreadRuntime, } from './MainThreadRuntime.js';
2
2
  export function createMainThreadLynx(config, lepusRuntime) {
3
3
  return {
4
+ getJSContext() {
5
+ // TODO: implement this
6
+ return new EventTarget();
7
+ },
4
8
  requestAnimationFrame(cb) {
5
9
  return requestAnimationFrame(cb);
6
10
  },
@@ -11,9 +15,9 @@ export function createMainThreadLynx(config, lepusRuntime) {
11
15
  requireModule(path) {
12
16
  // @ts-expect-error
13
17
  if (self.WorkerGlobalScope) {
14
- const mainfestUrl = config.lepusCode[`/${path}`];
15
- if (mainfestUrl)
16
- path = mainfestUrl;
18
+ const lepusChunkUrl = config.lepusCode[`${path}`];
19
+ if (lepusChunkUrl)
20
+ path = lepusChunkUrl;
17
21
  // @ts-expect-error
18
22
  importScripts(path);
19
23
  const entry = globalThis.module.exports;
@@ -24,9 +28,9 @@ export function createMainThreadLynx(config, lepusRuntime) {
24
28
  }
25
29
  },
26
30
  requireModuleAsync(path, callback) {
27
- const mainfestUrl = config.lepusCode[`/${path}`];
28
- if (mainfestUrl)
29
- path = mainfestUrl;
31
+ const lepusChunkUrl = config.lepusCode[`${path}`];
32
+ if (lepusChunkUrl)
33
+ path = lepusChunkUrl;
30
34
  import(
31
35
  /* webpackIgnore: true */
32
36
  path).catch(callback).then(() => {
@@ -1,11 +1,11 @@
1
- import { type LynxTemplate, type PageConfig, type ProcessDataCallback, type StyleInfo, type FlushElementTreeOptions, type Cloneable, type BrowserConfig, type publishEventEndpoint, type publicComponentEventEndpoint, type reportErrorEndpoint, type onLifecycleEventEndpoint, type RpcCallType, type postExposureEndpoint } from '@lynx-js/web-constants';
1
+ import { type LynxTemplate, type PageConfig, type ProcessDataCallback, type StyleInfo, type FlushElementTreeOptions, type Cloneable, type BrowserConfig, type publishEventEndpoint, type publicComponentEventEndpoint, type reportErrorEndpoint, type RpcCallType, type postExposureEndpoint } from '@lynx-js/web-constants';
2
2
  import { type MainThreadLynx } from './MainThreadLynx.js';
3
3
  import type { LynxRuntimeInfo } from './elementAPI/ElementThreadElement.js';
4
4
  export interface MainThreadRuntimeCallbacks {
5
5
  mainChunkReady: () => void;
6
6
  flushElementTree: (options: FlushElementTreeOptions, timingFlags: string[]) => void;
7
7
  _ReportError: RpcCallType<typeof reportErrorEndpoint>;
8
- __OnLifecycleEvent: RpcCallType<typeof onLifecycleEventEndpoint>;
8
+ __OnLifecycleEvent: (lifeCycleEvent: Cloneable) => void;
9
9
  markTiming: (pipelineId: string, timingKey: string) => void;
10
10
  publishEvent: RpcCallType<typeof publishEventEndpoint>;
11
11
  publicComponentEvent: RpcCallType<typeof publicComponentEventEndpoint>;
@@ -74,9 +74,11 @@ export declare class MainThreadRuntime {
74
74
  processData?: ProcessDataCallback;
75
75
  renderPage: (data: unknown) => void;
76
76
  _ReportError: RpcCallType<typeof reportErrorEndpoint>;
77
- __OnLifecycleEvent: RpcCallType<typeof onLifecycleEventEndpoint>;
77
+ __OnLifecycleEvent: (lifeCycleEvent: Cloneable) => void;
78
78
  __LoadLepusChunk: (path: string) => boolean;
79
79
  __FlushElementTree: (_subTree: unknown, options: FlushElementTreeOptions) => void;
80
80
  updatePage?: (data: Cloneable, options?: Record<string, string>) => void;
81
- _updateVars?: () => void;
81
+ runWorklet?: (obj: unknown, event: unknown) => void;
82
+ private __varsUpdateHandlers;
83
+ set _updateVars(handler: () => void);
82
84
  }
@@ -98,7 +98,9 @@ export class MainThreadRuntime {
98
98
  },
99
99
  set: (v) => {
100
100
  this.__lynxGlobalBindingValues[nm] = v;
101
- this._updateVars?.();
101
+ for (const handler of this.__varsUpdateHandlers) {
102
+ handler();
103
+ }
102
104
  },
103
105
  });
104
106
  }
@@ -150,6 +152,10 @@ export class MainThreadRuntime {
150
152
  this.config.callbacks.flushElementTree(options, timingFlags);
151
153
  };
152
154
  updatePage;
153
- _updateVars;
155
+ runWorklet;
156
+ __varsUpdateHandlers = [];
157
+ set _updateVars(handler) {
158
+ this.__varsUpdateHandlers.push(handler);
159
+ }
154
160
  }
155
161
  //# sourceMappingURL=MainThreadRuntime.js.map
@@ -7,11 +7,17 @@ export interface LynxRuntimeInfo {
7
7
  eventHandlerMap: Record<string, {
8
8
  capture: {
9
9
  type: LynxEventType;
10
- handler: string;
10
+ handler: string | {
11
+ type: 'worklet';
12
+ value: unknown;
13
+ };
11
14
  } | undefined;
12
15
  bind: {
13
16
  type: LynxEventType;
14
- handler: string;
17
+ handler: string | {
18
+ type: 'worklet';
19
+ value: unknown;
20
+ };
15
21
  } | undefined;
16
22
  }>;
17
23
  componentAtIndex?: ComponentAtIndexCallback;
@@ -1,12 +1,21 @@
1
- import { type LynxCrossThreadEvent, type LynxEventType } from '@lynx-js/web-constants';
1
+ import { type LynxEventType } from '@lynx-js/web-constants';
2
2
  import { type MainThreadRuntime } from '../../MainThreadRuntime.js';
3
3
  export declare function createEventFunctions(runtime: MainThreadRuntime): {
4
- __AddEvent: (element: HTMLElement, eventType: LynxEventType, eventName: string, newEventHandler: string | undefined) => void;
5
- __GetEvent: (element: HTMLElement, eventName: string, eventType: LynxEventType) => string | ((ev: LynxCrossThreadEvent) => void) | undefined;
4
+ __AddEvent: (element: HTMLElement, eventType: LynxEventType, eventName: string, newEventHandler: string | {
5
+ type: "worklet";
6
+ value: unknown;
7
+ } | undefined) => void;
8
+ __GetEvent: (element: HTMLElement, eventName: string, eventType: LynxEventType) => string | {
9
+ type: "worklet";
10
+ value: unknown;
11
+ } | undefined;
6
12
  __GetEvents: (element: HTMLElement) => {
7
13
  type: LynxEventType;
8
14
  name: string;
9
- function: string | ((ev: Event) => void) | undefined;
15
+ function: string | {
16
+ type: "worklet";
17
+ value: unknown;
18
+ } | undefined;
10
19
  }[];
11
20
  __SetEvents: (element: HTMLElement, listeners: {
12
21
  type: LynxEventType;
@@ -18,7 +18,7 @@ export function createEventFunctions(runtime) {
18
18
  ?.handler
19
19
  : runtimeInfo.eventHandlerMap[lynxEventName]?.bind
20
20
  ?.handler;
21
- if (hname) {
21
+ if (typeof hname === 'string') {
22
22
  const crossThreadEvent = createCrossThreadEvent(runtime, event, lynxEventName);
23
23
  const parentComponentUniqueId = runtimeInfo.parentComponentUniqueId;
24
24
  const parentComponent = runtime[getElementByUniqueId](Number(parentComponentUniqueId));
@@ -33,6 +33,9 @@ export function createEventFunctions(runtime) {
33
33
  }
34
34
  return true;
35
35
  }
36
+ else if (hname) {
37
+ runtime.runWorklet?.(hname.value, []);
38
+ }
36
39
  return false;
37
40
  };
38
41
  const btsCatchHandler = (event) => {
@@ -40,8 +43,7 @@ export function createEventFunctions(runtime) {
40
43
  if (handlerTriggered)
41
44
  event.stopPropagation();
42
45
  };
43
- function __AddEvent(element, eventType, eventName, newEventHandler // | ((ev: LynxCrossThreadEvent) => void) | undefined,
44
- ) {
46
+ function __AddEvent(element, eventType, eventName, newEventHandler) {
45
47
  eventName = eventName.toLowerCase();
46
48
  const isCatch = eventType === 'catchEvent' || eventType === 'capture-catch';
47
49
  const isCapture = eventType.startsWith('capture');
@@ -106,14 +108,13 @@ export function createEventFunctions(runtime) {
106
108
  for (const [lynxEventName, info] of Object.entries(eventHandlerMap)) {
107
109
  for (const atomInfo of [info.bind, info.capture]) {
108
110
  if (atomInfo) {
109
- for (const [type, handler] of Object.values(atomInfo)) {
110
- if (handler) {
111
- eventInfos.push({
112
- type: type,
113
- name: lynxEventName,
114
- function: handler,
115
- });
116
- }
111
+ const { type, handler } = atomInfo;
112
+ if (handler) {
113
+ eventInfos.push({
114
+ type: type,
115
+ name: lynxEventName,
116
+ function: handler,
117
+ });
117
118
  }
118
119
  }
119
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-mainthread-apis",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "css-tree": "^3.1.0",
27
27
  "hyphenate-style-name": "^1.1.0",
28
- "@lynx-js/web-constants": "0.10.0",
28
+ "@lynx-js/web-constants": "0.11.0",
29
29
  "@lynx-js/web-style-transformer": "0.2.3"
30
30
  }
31
31
  }