@lynx-js/web-mainthread-apis 0.10.1 → 0.12.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 +34 -0
- package/dist/MainThreadLynx.d.ts +1 -0
- package/dist/MainThreadLynx.js +9 -6
- package/dist/MainThreadRuntime.d.ts +7 -4
- package/dist/MainThreadRuntime.js +8 -2
- package/dist/elementAPI/ElementThreadElement.d.ts +8 -2
- package/dist/elementAPI/attributeAndProperty/attributeAndPropertyFunctions.d.ts +1 -1
- package/dist/elementAPI/attributeAndProperty/attributeAndPropertyFunctions.js +6 -1
- package/dist/elementAPI/event/eventFunctions.d.ts +13 -4
- package/dist/elementAPI/event/eventFunctions.js +19 -12
- package/dist/elementAPI/style/styleFunctions.js +9 -3
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @lynx-js/web-mainthread-apis
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: fully support MTS ([#569](https://github.com/lynx-family/lynx-stack/pull/569))
|
|
8
|
+
|
|
9
|
+
Now use support the following usage
|
|
10
|
+
|
|
11
|
+
- mainthread event
|
|
12
|
+
- mainthread ref
|
|
13
|
+
- runOnMainThread/runOnBackground
|
|
14
|
+
- ref.current.xx
|
|
15
|
+
|
|
16
|
+
- feat: support mts event with target methods ([#564](https://github.com/lynx-family/lynx-stack/pull/564))
|
|
17
|
+
|
|
18
|
+
After this commit, developers are allowed to invoke `event.target.setStyleProperty` in mts handler
|
|
19
|
+
|
|
20
|
+
- fix: crash on removing a id attribute ([#582](https://github.com/lynx-family/lynx-stack/pull/582))
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`f1ca29b`](https://github.com/lynx-family/lynx-stack/commit/f1ca29bd766377dd46583f15e1e75bca447699cd), [`7edf478`](https://github.com/lynx-family/lynx-stack/commit/7edf478410cb57eeedc18aac6f5d3950b16c7fa8)]:
|
|
23
|
+
- @lynx-js/web-constants@0.12.0
|
|
24
|
+
- @lynx-js/web-style-transformer@0.3.0
|
|
25
|
+
|
|
26
|
+
## 0.11.0
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- feat: support mts event handler (1/n) ([#495](https://github.com/lynx-family/lynx-stack/pull/495))
|
|
31
|
+
|
|
32
|
+
now the main-thread:bind handler could be invoked. The params of the handler will be implemented later.
|
|
33
|
+
|
|
34
|
+
- Updated dependencies [[`ea42e62`](https://github.com/lynx-family/lynx-stack/commit/ea42e62fbcd5c743132c3e6e7c4851770742d544), [`a0f5ca4`](https://github.com/lynx-family/lynx-stack/commit/a0f5ca4ea0895ccbaa6aa63f449f53a677a1cf73)]:
|
|
35
|
+
- @lynx-js/web-constants@0.11.0
|
|
36
|
+
|
|
3
37
|
## 0.10.1
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
package/dist/MainThreadLynx.d.ts
CHANGED
|
@@ -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(): import("@lynx-js/web-constants").LynxContextEventTarget;
|
|
3
4
|
requestAnimationFrame(cb: FrameRequestCallback): number;
|
|
4
5
|
cancelAnimationFrame(handler: number): void;
|
|
5
6
|
__globalProps: unknown;
|
package/dist/MainThreadLynx.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { MainThreadRuntime, } from './MainThreadRuntime.js';
|
|
2
2
|
export function createMainThreadLynx(config, lepusRuntime) {
|
|
3
3
|
return {
|
|
4
|
+
getJSContext() {
|
|
5
|
+
return config.jsContext;
|
|
6
|
+
},
|
|
4
7
|
requestAnimationFrame(cb) {
|
|
5
8
|
return requestAnimationFrame(cb);
|
|
6
9
|
},
|
|
@@ -11,9 +14,9 @@ export function createMainThreadLynx(config, lepusRuntime) {
|
|
|
11
14
|
requireModule(path) {
|
|
12
15
|
// @ts-expect-error
|
|
13
16
|
if (self.WorkerGlobalScope) {
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
path =
|
|
17
|
+
const lepusChunkUrl = config.lepusCode[`${path}`];
|
|
18
|
+
if (lepusChunkUrl)
|
|
19
|
+
path = lepusChunkUrl;
|
|
17
20
|
// @ts-expect-error
|
|
18
21
|
importScripts(path);
|
|
19
22
|
const entry = globalThis.module.exports;
|
|
@@ -24,9 +27,9 @@ export function createMainThreadLynx(config, lepusRuntime) {
|
|
|
24
27
|
}
|
|
25
28
|
},
|
|
26
29
|
requireModuleAsync(path, callback) {
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
path =
|
|
30
|
+
const lepusChunkUrl = config.lepusCode[`${path}`];
|
|
31
|
+
if (lepusChunkUrl)
|
|
32
|
+
path = lepusChunkUrl;
|
|
30
33
|
import(
|
|
31
34
|
/* webpackIgnore: true */
|
|
32
35
|
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
|
|
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, type LynxContextEventTarget } 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:
|
|
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>;
|
|
@@ -21,6 +21,7 @@ export interface MainThreadConfig {
|
|
|
21
21
|
browserConfig: BrowserConfig;
|
|
22
22
|
tagMap: Record<string, string>;
|
|
23
23
|
docu: Pick<Document, 'append' | 'createElement' | 'addEventListener'>;
|
|
24
|
+
jsContext: LynxContextEventTarget;
|
|
24
25
|
}
|
|
25
26
|
export declare const elementToRuntimeInfoMap: unique symbol;
|
|
26
27
|
export declare const getElementByUniqueId: unique symbol;
|
|
@@ -74,9 +75,11 @@ export declare class MainThreadRuntime {
|
|
|
74
75
|
processData?: ProcessDataCallback;
|
|
75
76
|
renderPage: (data: unknown) => void;
|
|
76
77
|
_ReportError: RpcCallType<typeof reportErrorEndpoint>;
|
|
77
|
-
__OnLifecycleEvent:
|
|
78
|
+
__OnLifecycleEvent: (lifeCycleEvent: Cloneable) => void;
|
|
78
79
|
__LoadLepusChunk: (path: string) => boolean;
|
|
79
80
|
__FlushElementTree: (_subTree: unknown, options: FlushElementTreeOptions) => void;
|
|
80
81
|
updatePage?: (data: Cloneable, options?: Record<string, string>) => void;
|
|
81
|
-
|
|
82
|
+
runWorklet?: (obj: unknown, event: unknown) => void;
|
|
83
|
+
private __varsUpdateHandlers;
|
|
84
|
+
set _updateVars(handler: () => void);
|
|
82
85
|
}
|
|
@@ -98,7 +98,9 @@ export class MainThreadRuntime {
|
|
|
98
98
|
},
|
|
99
99
|
set: (v) => {
|
|
100
100
|
this.__lynxGlobalBindingValues[nm] = v;
|
|
101
|
-
this.
|
|
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
|
-
|
|
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;
|
|
@@ -21,7 +21,7 @@ export declare function createAttributeAndPropertyFunctions(runtime: MainThreadR
|
|
|
21
21
|
__GetTag: (element: HTMLElement) => string;
|
|
22
22
|
__SetConfig: (element: HTMLElement, config: Record<string, any>) => void;
|
|
23
23
|
__SetDataset: (element: HTMLElement, dataset: Record<string, any>) => void;
|
|
24
|
-
__SetID: (element: HTMLElement, id: string) => void;
|
|
24
|
+
__SetID: (element: HTMLElement, id: string | null) => void;
|
|
25
25
|
__UpdateComponentID: (element: HTMLElement, componentID: string) => void;
|
|
26
26
|
__UpdateListCallbacks: (element: HTMLElement, componentAtIndex: ComponentAtIndexCallback, enqueueComponent: EnqueueComponentCallback) => void;
|
|
27
27
|
__GetConfig: (element: HTMLElement) => Record<string, import("@lynx-js/web-constants").Cloneable>;
|
|
@@ -57,7 +57,12 @@ export function createAttributeAndPropertyFunctions(runtime) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
function __SetID(element, id) {
|
|
60
|
-
|
|
60
|
+
if (typeof id === 'string') {
|
|
61
|
+
element.id = id;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
element.removeAttribute('id');
|
|
65
|
+
}
|
|
61
66
|
}
|
|
62
67
|
function __UpdateComponentID(element, componentID) {
|
|
63
68
|
element.setAttribute(componentIdAttribute, componentID);
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import { type
|
|
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 |
|
|
5
|
-
|
|
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 |
|
|
15
|
+
function: string | {
|
|
16
|
+
type: "worklet";
|
|
17
|
+
value: unknown;
|
|
18
|
+
} | undefined;
|
|
10
19
|
}[];
|
|
11
20
|
__SetEvents: (element: HTMLElement, listeners: {
|
|
12
21
|
type: LynxEventType;
|
|
@@ -18,8 +18,8 @@ export function createEventFunctions(runtime) {
|
|
|
18
18
|
?.handler
|
|
19
19
|
: runtimeInfo.eventHandlerMap[lynxEventName]?.bind
|
|
20
20
|
?.handler;
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const crossThreadEvent = createCrossThreadEvent(runtime, event, lynxEventName);
|
|
22
|
+
if (typeof hname === 'string') {
|
|
23
23
|
const parentComponentUniqueId = runtimeInfo.parentComponentUniqueId;
|
|
24
24
|
const parentComponent = runtime[getElementByUniqueId](Number(parentComponentUniqueId));
|
|
25
25
|
const componentId = parentComponent?.getAttribute(lynxTagAttribute) !== 'page'
|
|
@@ -33,6 +33,15 @@ export function createEventFunctions(runtime) {
|
|
|
33
33
|
}
|
|
34
34
|
return true;
|
|
35
35
|
}
|
|
36
|
+
else if (hname) {
|
|
37
|
+
crossThreadEvent.target.elementRefptr =
|
|
38
|
+
event.target;
|
|
39
|
+
if (crossThreadEvent.currentTarget) {
|
|
40
|
+
crossThreadEvent.currentTarget
|
|
41
|
+
.elementRefptr = event.currentTarget;
|
|
42
|
+
}
|
|
43
|
+
runtime.runWorklet?.(hname.value, [crossThreadEvent]);
|
|
44
|
+
}
|
|
36
45
|
return false;
|
|
37
46
|
};
|
|
38
47
|
const btsCatchHandler = (event) => {
|
|
@@ -40,8 +49,7 @@ export function createEventFunctions(runtime) {
|
|
|
40
49
|
if (handlerTriggered)
|
|
41
50
|
event.stopPropagation();
|
|
42
51
|
};
|
|
43
|
-
function __AddEvent(element, eventType, eventName, newEventHandler
|
|
44
|
-
) {
|
|
52
|
+
function __AddEvent(element, eventType, eventName, newEventHandler) {
|
|
45
53
|
eventName = eventName.toLowerCase();
|
|
46
54
|
const isCatch = eventType === 'catchEvent' || eventType === 'capture-catch';
|
|
47
55
|
const isCapture = eventType.startsWith('capture');
|
|
@@ -106,14 +114,13 @@ export function createEventFunctions(runtime) {
|
|
|
106
114
|
for (const [lynxEventName, info] of Object.entries(eventHandlerMap)) {
|
|
107
115
|
for (const atomInfo of [info.bind, info.capture]) {
|
|
108
116
|
if (atomInfo) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
+
const { type, handler } = atomInfo;
|
|
118
|
+
if (handler) {
|
|
119
|
+
eventInfos.push({
|
|
120
|
+
type: type,
|
|
121
|
+
name: lynxEventName,
|
|
122
|
+
function: handler,
|
|
123
|
+
});
|
|
117
124
|
}
|
|
118
125
|
}
|
|
119
126
|
}
|
|
@@ -30,14 +30,20 @@ export function createStyleFunctions(runtime, cssInJsInfo) {
|
|
|
30
30
|
return (element.className ?? '').split(' ').filter(e => e);
|
|
31
31
|
}
|
|
32
32
|
function __AddInlineStyle(element, key, value) {
|
|
33
|
-
|
|
33
|
+
let dashName;
|
|
34
|
+
if (typeof key === 'number') {
|
|
35
|
+
dashName = queryCSSProperty(key).dashName;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
dashName = key;
|
|
39
|
+
}
|
|
34
40
|
const valueStr = typeof value === 'number' ? value.toString() : value;
|
|
35
41
|
if (!valueStr) { // null or undefined
|
|
36
|
-
element.style.removeProperty(
|
|
42
|
+
element.style.removeProperty(dashName);
|
|
37
43
|
}
|
|
38
44
|
else {
|
|
39
45
|
const { transformedStyle } = transfromParsedStyles([[
|
|
40
|
-
|
|
46
|
+
dashName,
|
|
41
47
|
valueStr,
|
|
42
48
|
]]);
|
|
43
49
|
for (const [property, value] of transformedStyle) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-mainthread-apis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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.
|
|
29
|
-
"@lynx-js/web-style-transformer": "0.
|
|
28
|
+
"@lynx-js/web-constants": "0.12.0",
|
|
29
|
+
"@lynx-js/web-style-transformer": "0.3.0"
|
|
30
30
|
}
|
|
31
31
|
}
|