@lynx-js/web-core 0.9.0 → 0.9.1
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 +13 -0
- package/dist/apis/LynxView.d.ts +0 -13
- package/dist/apis/LynxView.js +9 -95
- package/dist/apis/createLynxView.d.ts +1 -1
- package/dist/apis/createLynxView.js +2 -2
- package/dist/uiThread/crossThreadHandlers/bootTimingSystem.d.ts +1 -1
- package/dist/uiThread/crossThreadHandlers/bootTimingSystem.js +2 -2
- package/dist/uiThread/crossThreadHandlers/createExposureService.d.ts +1 -1
- package/dist/uiThread/crossThreadHandlers/createExposureService.js +5 -3
- package/dist/uiThread/crossThreadHandlers/queryNodes.d.ts +1 -1
- package/dist/uiThread/crossThreadHandlers/queryNodes.js +4 -4
- package/dist/uiThread/crossThreadHandlers/registerFlushElementTreeHandler.d.ts +1 -1
- package/dist/uiThread/crossThreadHandlers/registerFlushElementTreeHandler.js +5 -5
- package/dist/uiThread/crossThreadHandlers/registerInvokeUIMethodHandler.d.ts +1 -1
- package/dist/uiThread/crossThreadHandlers/registerInvokeUIMethodHandler.js +2 -2
- package/dist/uiThread/crossThreadHandlers/registerSelectComponentHandler.d.ts +1 -1
- package/dist/uiThread/crossThreadHandlers/registerSelectComponentHandler.js +2 -2
- package/dist/uiThread/crossThreadHandlers/registerSetNativePropsHandler.d.ts +1 -1
- package/dist/uiThread/crossThreadHandlers/registerSetNativePropsHandler.js +2 -2
- package/dist/uiThread/crossThreadHandlers/registerTriggerComponentEventHandler.d.ts +1 -1
- package/dist/uiThread/crossThreadHandlers/registerTriggerComponentEventHandler.js +2 -2
- package/dist/uiThread/startUIThread.d.ts +1 -1
- package/dist/uiThread/startUIThread.js +8 -8
- package/dist/utils/createCrossThreadEvent.js +1 -1
- package/index.css +2 -39
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @lynx-js/web-core
|
|
2
2
|
|
|
3
|
+
## 0.9.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: remove extra div #lynx-view-root ([#311](https://github.com/lynx-family/lynx-stack/pull/311))
|
|
8
|
+
|
|
9
|
+
In this commit we've re-implemented the lynx-view's auto-size. Now we use the `contain:content` instead of `resizeObserver`.
|
|
10
|
+
|
|
11
|
+
- Updated dependencies []:
|
|
12
|
+
- @lynx-js/web-constants@0.9.1
|
|
13
|
+
- @lynx-js/web-worker-rpc@0.9.1
|
|
14
|
+
- @lynx-js/web-worker-runtime@0.9.1
|
|
15
|
+
|
|
3
16
|
## 0.9.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/dist/apis/LynxView.d.ts
CHANGED
|
@@ -96,18 +96,6 @@ export declare class LynxView extends HTMLElement {
|
|
|
96
96
|
*/
|
|
97
97
|
get onNapiModulesCall(): NapiModulesCall | undefined;
|
|
98
98
|
set onNapiModulesCall(handler: NapiModulesCall);
|
|
99
|
-
/**
|
|
100
|
-
* @public
|
|
101
|
-
* "auto" for auto calculated height
|
|
102
|
-
*/
|
|
103
|
-
get height(): string | null;
|
|
104
|
-
/**
|
|
105
|
-
* @public
|
|
106
|
-
* "auto" for auto calculated width
|
|
107
|
-
*/
|
|
108
|
-
get width(): string | null;
|
|
109
|
-
set height(val: string | null);
|
|
110
|
-
set width(val: string | null);
|
|
111
99
|
/**
|
|
112
100
|
* @public
|
|
113
101
|
* @method
|
|
@@ -145,5 +133,4 @@ export declare class LynxView extends HTMLElement {
|
|
|
145
133
|
* @private
|
|
146
134
|
*/
|
|
147
135
|
connectedCallback(): void;
|
|
148
|
-
private cleanupResizeObserver;
|
|
149
136
|
}
|
package/dist/apis/LynxView.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { createLynxView, } from './createLynxView.js';
|
|
5
|
-
import {
|
|
5
|
+
import {} from '@lynx-js/web-constants';
|
|
6
6
|
import { inShadowRootStyles } from './inShadowRootStyles.js';
|
|
7
7
|
/**
|
|
8
8
|
* Based on our experiences, these elements are almost used in all lynx cards.
|
|
@@ -169,81 +169,13 @@ export class LynxView extends HTMLElement {
|
|
|
169
169
|
set onNapiModulesCall(handler) {
|
|
170
170
|
this.#onNapiModulesCall = handler;
|
|
171
171
|
}
|
|
172
|
-
#autoHeight = false;
|
|
173
|
-
#autoWidth = false;
|
|
174
|
-
#currentWidth = 0;
|
|
175
|
-
#currentHeight = 0;
|
|
176
|
-
/**
|
|
177
|
-
* @public
|
|
178
|
-
* "auto" for auto calculated height
|
|
179
|
-
*/
|
|
180
|
-
get height() {
|
|
181
|
-
return this.#autoHeight ? 'auto' : null;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* @public
|
|
185
|
-
* "auto" for auto calculated width
|
|
186
|
-
*/
|
|
187
|
-
get width() {
|
|
188
|
-
return this.#autoWidth ? 'auto' : null;
|
|
189
|
-
}
|
|
190
|
-
set height(val) {
|
|
191
|
-
this.#handleAutoSize();
|
|
192
|
-
this.#autoHeight = val === 'auto' ? true : false;
|
|
193
|
-
}
|
|
194
|
-
set width(val) {
|
|
195
|
-
this.#handleAutoSize();
|
|
196
|
-
this.#autoWidth = val === 'auto' ? true : false;
|
|
197
|
-
}
|
|
198
|
-
#handleAutoSize() {
|
|
199
|
-
if (this.#autoHeight || this.#autoWidth) {
|
|
200
|
-
if (this.#instance && !this.#instance.resizeObserver) {
|
|
201
|
-
this.#instance.resizeObserver = new ResizeObserver((sizes) => {
|
|
202
|
-
const size = sizes[0];
|
|
203
|
-
if (size) {
|
|
204
|
-
const { width, height } = size.contentRect;
|
|
205
|
-
if (this.#autoWidth) {
|
|
206
|
-
if (this.#currentWidth !== width) {
|
|
207
|
-
this.#currentWidth = width;
|
|
208
|
-
this.style.setProperty('--lynx-view-width', `${width}px`);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
if (this.#autoHeight) {
|
|
212
|
-
if (this.#currentHeight !== height) {
|
|
213
|
-
this.#currentHeight = height;
|
|
214
|
-
this.style.setProperty('--lynx-view-height', `${height}px`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
this.#instance.resizeObserver.observe(this.#instance.rootDom);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
if (this.#instance?.resizeObserver) {
|
|
224
|
-
this.#instance.resizeObserver.disconnect();
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (this.#autoHeight) {
|
|
228
|
-
this.setAttribute('height', 'auto');
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
this.removeAttribute('height');
|
|
232
|
-
}
|
|
233
|
-
if (this.#autoWidth) {
|
|
234
|
-
this.setAttribute('width', 'auto');
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
this.removeAttribute('width');
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
172
|
/**
|
|
241
173
|
* @public
|
|
242
174
|
* @method
|
|
243
175
|
* update the `__initData` and trigger essential flow
|
|
244
176
|
*/
|
|
245
177
|
updateData(data, updateDataType, callback) {
|
|
246
|
-
this.#instance?.
|
|
178
|
+
this.#instance?.updateData(data, updateDataType, callback);
|
|
247
179
|
}
|
|
248
180
|
/**
|
|
249
181
|
* @public
|
|
@@ -251,7 +183,7 @@ export class LynxView extends HTMLElement {
|
|
|
251
183
|
* send global events, which can be listened to using the GlobalEventEmitter
|
|
252
184
|
*/
|
|
253
185
|
sendGlobalEvent(eventName, params) {
|
|
254
|
-
this.#instance?.
|
|
186
|
+
this.#instance?.sendGlobalEvent(eventName, params);
|
|
255
187
|
}
|
|
256
188
|
/**
|
|
257
189
|
* @public
|
|
@@ -291,11 +223,7 @@ export class LynxView extends HTMLElement {
|
|
|
291
223
|
* @private
|
|
292
224
|
*/
|
|
293
225
|
disconnectedCallback() {
|
|
294
|
-
this
|
|
295
|
-
if (this.#instance) {
|
|
296
|
-
this.#instance.lynxView.dispose();
|
|
297
|
-
this.#instance.rootDom.remove();
|
|
298
|
-
}
|
|
226
|
+
this.#instance?.dispose();
|
|
299
227
|
this.#instance = undefined;
|
|
300
228
|
if (this.shadowRoot) {
|
|
301
229
|
this.shadowRoot.innerHTML = '';
|
|
@@ -317,9 +245,6 @@ export class LynxView extends HTMLElement {
|
|
|
317
245
|
this.disconnectedCallback();
|
|
318
246
|
}
|
|
319
247
|
if (this.#url) {
|
|
320
|
-
const rootDom = document.createElement('div');
|
|
321
|
-
rootDom.id = lynxViewRootDomId;
|
|
322
|
-
rootDom.setAttribute('part', lynxViewRootDomId);
|
|
323
248
|
const tagMap = {
|
|
324
249
|
'page': 'div',
|
|
325
250
|
'view': 'x-view',
|
|
@@ -329,9 +254,12 @@ export class LynxView extends HTMLElement {
|
|
|
329
254
|
'svg': 'x-svg',
|
|
330
255
|
...this.overrideLynxTagToHTMLTagMap,
|
|
331
256
|
};
|
|
257
|
+
if (!this.shadowRoot) {
|
|
258
|
+
this.attachShadow({ mode: 'open' });
|
|
259
|
+
}
|
|
332
260
|
const lynxView = createLynxView({
|
|
333
261
|
tagMap,
|
|
334
|
-
|
|
262
|
+
shadowRoot: this.shadowRoot,
|
|
335
263
|
templateUrl: this.#url,
|
|
336
264
|
globalProps: this.#globalProps,
|
|
337
265
|
initData: this.#initData,
|
|
@@ -357,14 +285,7 @@ export class LynxView extends HTMLElement {
|
|
|
357
285
|
},
|
|
358
286
|
},
|
|
359
287
|
});
|
|
360
|
-
this.#instance =
|
|
361
|
-
lynxView,
|
|
362
|
-
rootDom,
|
|
363
|
-
};
|
|
364
|
-
this.#handleAutoSize();
|
|
365
|
-
if (!this.shadowRoot) {
|
|
366
|
-
this.attachShadow({ mode: 'open' });
|
|
367
|
-
}
|
|
288
|
+
this.#instance = lynxView;
|
|
368
289
|
const styleElement = document.createElement('style');
|
|
369
290
|
this.shadowRoot.append(styleElement);
|
|
370
291
|
const styleSheet = styleElement.sheet;
|
|
@@ -376,7 +297,6 @@ export class LynxView extends HTMLElement {
|
|
|
376
297
|
styleSheet.insertRule(`@import url("${href}");`);
|
|
377
298
|
});
|
|
378
299
|
}
|
|
379
|
-
this.shadowRoot.append(rootDom);
|
|
380
300
|
}
|
|
381
301
|
});
|
|
382
302
|
}
|
|
@@ -387,12 +307,6 @@ export class LynxView extends HTMLElement {
|
|
|
387
307
|
connectedCallback() {
|
|
388
308
|
this.#render();
|
|
389
309
|
}
|
|
390
|
-
cleanupResizeObserver() {
|
|
391
|
-
if (this.#instance?.resizeObserver) {
|
|
392
|
-
this.#instance.resizeObserver.disconnect();
|
|
393
|
-
this.#instance.resizeObserver = undefined;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
310
|
}
|
|
397
311
|
if (customElements.get(LynxView.tag)) {
|
|
398
312
|
console.warn(`[${LynxView.tag}] has already been defined`);
|
|
@@ -5,7 +5,7 @@ export interface LynxViewConfigs {
|
|
|
5
5
|
templateUrl: string;
|
|
6
6
|
initData: Cloneable;
|
|
7
7
|
globalProps: Cloneable;
|
|
8
|
-
|
|
8
|
+
shadowRoot: ShadowRoot;
|
|
9
9
|
callbacks: Parameters<typeof startUIThread>[3];
|
|
10
10
|
nativeModulesMap: NativeModulesMap;
|
|
11
11
|
napiModulesMap: NapiModulesMap;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { startUIThread } from '../uiThread/startUIThread.js';
|
|
5
5
|
export function createLynxView(configs) {
|
|
6
|
-
const {
|
|
6
|
+
const { shadowRoot, callbacks, templateUrl, globalProps, initData, nativeModulesMap, napiModulesMap, tagMap, } = configs;
|
|
7
7
|
return startUIThread(templateUrl, {
|
|
8
8
|
tagMap,
|
|
9
9
|
initData,
|
|
@@ -11,6 +11,6 @@ export function createLynxView(configs) {
|
|
|
11
11
|
nativeModulesMap,
|
|
12
12
|
napiModulesMap,
|
|
13
13
|
browserConfig: {},
|
|
14
|
-
},
|
|
14
|
+
}, shadowRoot, callbacks);
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=createLynxView.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
|
-
export declare function bootTimingSystem(mainThreadRpc: Rpc, backgroundThreadRpc: Rpc,
|
|
2
|
+
export declare function bootTimingSystem(mainThreadRpc: Rpc, backgroundThreadRpc: Rpc, shadowRoot: ShadowRoot): {
|
|
3
3
|
markTimingInternal: (timingKey: string, pipelineId?: string, timeStamp?: number) => void;
|
|
4
4
|
sendTimingResult: (pipelineId: string | undefined, timingFlags: string[], isFp: boolean) => void;
|
|
5
5
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { postTimingInfoFromBackgroundThread, postTimingInfoFromMainThread, postTimingResult, } from '@lynx-js/web-constants';
|
|
5
|
-
export function bootTimingSystem(mainThreadRpc, backgroundThreadRpc,
|
|
5
|
+
export function bootTimingSystem(mainThreadRpc, backgroundThreadRpc, shadowRoot) {
|
|
6
6
|
const setupTiming = {};
|
|
7
7
|
const pipelineIdToTiming = new Map();
|
|
8
8
|
let commonTimingFlags = [];
|
|
@@ -31,7 +31,7 @@ export function bootTimingSystem(mainThreadRpc, backgroundThreadRpc, rootDom) {
|
|
|
31
31
|
timingFlags,
|
|
32
32
|
isFp ? setupTiming : undefined,
|
|
33
33
|
]);
|
|
34
|
-
|
|
34
|
+
shadowRoot.dispatchEvent(new CustomEvent('timing', {
|
|
35
35
|
detail: isFp ? setupTiming : timingInfo,
|
|
36
36
|
bubbles: true,
|
|
37
37
|
cancelable: true,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
|
-
export declare function createExposureService(rpc: Rpc,
|
|
2
|
+
export declare function createExposureService(rpc: Rpc, shadowRoot: ShadowRoot): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { lynxUniqueIdAttribute, postExposureEndpoint, switchExposureService, } from '@lynx-js/web-constants';
|
|
2
2
|
import { createCrossThreadEvent } from '../../utils/createCrossThreadEvent.js';
|
|
3
|
-
export function createExposureService(rpc,
|
|
3
|
+
export function createExposureService(rpc, shadowRoot) {
|
|
4
4
|
let working = true;
|
|
5
5
|
let exposureCache = [];
|
|
6
6
|
let disexposureCache = [];
|
|
@@ -30,8 +30,10 @@ export function createExposureService(rpc, rootDom) {
|
|
|
30
30
|
}]);
|
|
31
31
|
}
|
|
32
32
|
}, 1000 / 20);
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
shadowRoot.addEventListener('exposure', exposureEventHandler, {
|
|
34
|
+
passive: true,
|
|
35
|
+
});
|
|
36
|
+
shadowRoot.addEventListener('disexposure', exposureEventHandler, {
|
|
35
37
|
passive: true,
|
|
36
38
|
});
|
|
37
39
|
rpc.registerHandler(switchExposureService, async (enable, sendEvent) => {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ErrorCode, IdentifierType } from '@lynx-js/web-constants';
|
|
2
|
-
export declare function queryNodes(
|
|
2
|
+
export declare function queryNodes(shadowRoot: ShadowRoot, type: IdentifierType, identifier: string, component_id: string, first_only: boolean, root_unique_id: number | undefined, callback: (dom: Element) => void, error?: (code: ErrorCode) => void): void;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { componentIdAttribute, ErrorCode, IdentifierType, lynxUniqueIdAttribute, } from '@lynx-js/web-constants';
|
|
5
|
-
export function queryNodes(
|
|
6
|
-
let queryRoot =
|
|
5
|
+
export function queryNodes(shadowRoot, type, identifier, component_id, first_only, root_unique_id, callback, error) {
|
|
6
|
+
let queryRoot = shadowRoot;
|
|
7
7
|
if (root_unique_id) {
|
|
8
|
-
const root =
|
|
8
|
+
const root = shadowRoot.querySelector(`[${lynxUniqueIdAttribute}="${root_unique_id}"]`);
|
|
9
9
|
if (root) {
|
|
10
10
|
queryRoot = root;
|
|
11
11
|
}
|
|
@@ -16,7 +16,7 @@ export function queryNodes(rootDom, type, identifier, component_id, first_only,
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
else if (component_id) {
|
|
19
|
-
const root =
|
|
19
|
+
const root = shadowRoot.querySelector(`[${componentIdAttribute}="${component_id}"]`);
|
|
20
20
|
if (root) {
|
|
21
21
|
queryRoot = root;
|
|
22
22
|
}
|
|
@@ -4,7 +4,7 @@ import type { RuntimePropertyOnElement } from '../../types/RuntimePropertyOnElem
|
|
|
4
4
|
export declare function registerFlushElementTreeHandler(mainThreadRpc: Rpc, endpoint: typeof flushElementTreeEndpoint, options: {
|
|
5
5
|
pageConfig: PageConfig;
|
|
6
6
|
backgroundRpc: Rpc;
|
|
7
|
-
|
|
7
|
+
shadowRoot: ShadowRoot;
|
|
8
8
|
}, onCommit: (info: {
|
|
9
9
|
pipelineId: string | undefined;
|
|
10
10
|
timingFlags: string[];
|
|
@@ -10,12 +10,12 @@ function applyPageAttributes(page, pageConfig) {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
export function registerFlushElementTreeHandler(mainThreadRpc, endpoint, options, onCommit, markTimingInternal) {
|
|
13
|
-
const { pageConfig, backgroundRpc,
|
|
13
|
+
const { pageConfig, backgroundRpc, shadowRoot, } = options;
|
|
14
14
|
const uniqueIdToElement = [];
|
|
15
15
|
const uniqueIdToCssInJsRule = [];
|
|
16
16
|
const rootStyleElementForCssInJs = document.createElement('style');
|
|
17
17
|
if (!pageConfig.enableCSSSelector) {
|
|
18
|
-
|
|
18
|
+
shadowRoot.append(rootStyleElementForCssInJs);
|
|
19
19
|
}
|
|
20
20
|
const createElementImpl = (tag) => {
|
|
21
21
|
const element = document.createElement(tag);
|
|
@@ -38,7 +38,7 @@ export function registerFlushElementTreeHandler(mainThreadRpc, endpoint, options
|
|
|
38
38
|
const crossThreadEvent = createCrossThreadEvent(event);
|
|
39
39
|
const currentTarget = event.currentTarget;
|
|
40
40
|
const parentComponentUniqueId = currentTarget.getAttribute(parentComponentUniqueIdAttribute) ?? '0';
|
|
41
|
-
const componentTargetDom =
|
|
41
|
+
const componentTargetDom = shadowRoot.querySelector(`[${lynxUniqueIdAttribute}="${parentComponentUniqueId}"]`);
|
|
42
42
|
const componentId = componentTargetDom?.getAttribute(lynxTagAttribute) !== 'page'
|
|
43
43
|
? componentTargetDom?.getAttribute(componentIdAttribute) ?? undefined
|
|
44
44
|
: undefined;
|
|
@@ -80,8 +80,8 @@ export function registerFlushElementTreeHandler(mainThreadRpc, endpoint, options
|
|
|
80
80
|
// on FP
|
|
81
81
|
const styleElement = document.createElement('style');
|
|
82
82
|
styleElement.innerHTML = cardCss;
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
shadowRoot.append(styleElement);
|
|
84
|
+
shadowRoot.append(page);
|
|
85
85
|
applyPageAttributes(page, pageConfig);
|
|
86
86
|
}
|
|
87
87
|
markTimingInternal('layout_end', pipelineId);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
|
-
export declare function registerInvokeUIMethodHandler(rpc: Rpc,
|
|
2
|
+
export declare function registerInvokeUIMethodHandler(rpc: Rpc, shadowRoot: ShadowRoot): void;
|
|
@@ -17,11 +17,11 @@ const methodAlias = {
|
|
|
17
17
|
};
|
|
18
18
|
},
|
|
19
19
|
};
|
|
20
|
-
export function registerInvokeUIMethodHandler(rpc,
|
|
20
|
+
export function registerInvokeUIMethodHandler(rpc, shadowRoot) {
|
|
21
21
|
let code = ErrorCode.UNKNOWN;
|
|
22
22
|
let data = undefined;
|
|
23
23
|
rpc.registerHandler(invokeUIMethodEndpoint, (type, identifier, component_id, method, params, root_unique_id) => {
|
|
24
|
-
queryNodes(
|
|
24
|
+
queryNodes(shadowRoot, type, identifier, component_id, true, root_unique_id, (element) => {
|
|
25
25
|
try {
|
|
26
26
|
const aliasMethod = methodAlias[method];
|
|
27
27
|
const hasDomMethod = typeof element[method] === 'function';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
|
-
export declare function registerSelectComponentHandler(rpc: Rpc,
|
|
2
|
+
export declare function registerSelectComponentHandler(rpc: Rpc, shadowRoot: ShadowRoot): void;
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { componentIdAttribute, IdentifierType, selectComponentEndpoint, } from '@lynx-js/web-constants';
|
|
5
5
|
import { queryNodes } from './queryNodes.js';
|
|
6
|
-
export function registerSelectComponentHandler(rpc,
|
|
6
|
+
export function registerSelectComponentHandler(rpc, shadowRoot) {
|
|
7
7
|
let element;
|
|
8
8
|
rpc.registerHandler(selectComponentEndpoint, (componentId, idSelector, single) => {
|
|
9
|
-
queryNodes(
|
|
9
|
+
queryNodes(shadowRoot, IdentifierType.ID_SELECTOR, idSelector, componentId === 'card' ? '0' : componentId, single, undefined, (ele) => {
|
|
10
10
|
element = ele;
|
|
11
11
|
});
|
|
12
12
|
return [element?.getAttribute(componentIdAttribute) ?? undefined];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
|
-
export declare function registerNativePropsHandler(rpc: Rpc,
|
|
2
|
+
export declare function registerNativePropsHandler(rpc: Rpc, shadowRoot: ShadowRoot): void;
|
|
@@ -22,9 +22,9 @@ function applyNativeProps(element, nativeProps) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
export function registerNativePropsHandler(rpc,
|
|
25
|
+
export function registerNativePropsHandler(rpc, shadowRoot) {
|
|
26
26
|
rpc.registerHandler(setNativePropsEndpoint, (type, identifier, component_id, first_only, native_props, root_unique_id) => {
|
|
27
|
-
queryNodes(
|
|
27
|
+
queryNodes(shadowRoot, type, identifier, component_id, first_only, root_unique_id, (element) => {
|
|
28
28
|
applyNativeProps(element, native_props);
|
|
29
29
|
});
|
|
30
30
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
|
-
export declare function registerTriggerComponentEventHandler(rpc: Rpc,
|
|
2
|
+
export declare function registerTriggerComponentEventHandler(rpc: Rpc, shadowRoot: ShadowRoot): void;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { componentIdAttribute, triggerComponentEventEndpoint, } from '@lynx-js/web-constants';
|
|
5
|
-
export function registerTriggerComponentEventHandler(rpc,
|
|
5
|
+
export function registerTriggerComponentEventHandler(rpc, shadowRoot) {
|
|
6
6
|
rpc.registerHandler(triggerComponentEventEndpoint, (id, params) => {
|
|
7
|
-
const componentDom =
|
|
7
|
+
const componentDom = shadowRoot.querySelector(`[${componentIdAttribute}="${params.componentId}"]`);
|
|
8
8
|
componentDom?.dispatchEvent(new CustomEvent(id, {
|
|
9
9
|
...params.eventOption,
|
|
10
10
|
detail: params.eventDetail,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LynxView } from '../apis/createLynxView.js';
|
|
2
2
|
import { type MainThreadStartConfigs, type NapiModulesCall, type NativeModulesCall } from '@lynx-js/web-constants';
|
|
3
|
-
export declare function startUIThread(templateUrl: string, configs: Omit<MainThreadStartConfigs, 'template'>,
|
|
3
|
+
export declare function startUIThread(templateUrl: string, configs: Omit<MainThreadStartConfigs, 'template'>, shadowRoot: ShadowRoot, callbacks: {
|
|
4
4
|
nativeModulesCall: NativeModulesCall;
|
|
5
5
|
napiModulesCall: NapiModulesCall;
|
|
6
6
|
onError?: () => void;
|
|
@@ -16,14 +16,14 @@ import { flushElementTreeEndpoint, mainThreadChunkReadyEndpoint, mainThreadStart
|
|
|
16
16
|
import { loadTemplate } from '../utils/loadTemplate.js';
|
|
17
17
|
import { createUpdateData } from './crossThreadHandlers/createUpdateData.js';
|
|
18
18
|
import { registerNapiModulesCallHandler } from './crossThreadHandlers/registerNapiModulesCallHandler.js';
|
|
19
|
-
export function startUIThread(templateUrl, configs,
|
|
19
|
+
export function startUIThread(templateUrl, configs, shadowRoot, callbacks) {
|
|
20
20
|
const createLynxStartTiming = performance.now() + performance.timeOrigin;
|
|
21
21
|
const { nativeModulesMap, napiModulesMap } = configs;
|
|
22
22
|
const { mainThreadRpc, backgroundRpc, terminateWorkers, } = bootWorkers();
|
|
23
23
|
const sendGlobalEvent = backgroundRpc.createCall(sendGlobalEventEndpoint);
|
|
24
24
|
const uiThreadFpReady = backgroundRpc.createCall(uiThreadFpReadyEndpoint);
|
|
25
25
|
const mainThreadStart = mainThreadRpc.createCall(mainThreadStartEndpoint);
|
|
26
|
-
const { markTimingInternal, sendTimingResult } = bootTimingSystem(mainThreadRpc, backgroundRpc,
|
|
26
|
+
const { markTimingInternal, sendTimingResult } = bootTimingSystem(mainThreadRpc, backgroundRpc, shadowRoot);
|
|
27
27
|
markTimingInternal('create_lynx_start', undefined, createLynxStartTiming);
|
|
28
28
|
markTimingInternal('load_template_start');
|
|
29
29
|
loadTemplate(templateUrl).then((template) => {
|
|
@@ -41,15 +41,15 @@ export function startUIThread(templateUrl, configs, rootDom, callbacks) {
|
|
|
41
41
|
registerFlushElementTreeHandler(mainThreadRpc, flushElementTreeEndpoint, {
|
|
42
42
|
pageConfig,
|
|
43
43
|
backgroundRpc,
|
|
44
|
-
|
|
44
|
+
shadowRoot,
|
|
45
45
|
}, (info) => {
|
|
46
46
|
const { pipelineId, timingFlags, isFP } = info;
|
|
47
47
|
if (isFP) {
|
|
48
|
-
registerInvokeUIMethodHandler(backgroundRpc,
|
|
49
|
-
registerNativePropsHandler(backgroundRpc,
|
|
50
|
-
registerTriggerComponentEventHandler(backgroundRpc,
|
|
51
|
-
registerSelectComponentHandler(backgroundRpc,
|
|
52
|
-
createExposureService(backgroundRpc,
|
|
48
|
+
registerInvokeUIMethodHandler(backgroundRpc, shadowRoot);
|
|
49
|
+
registerNativePropsHandler(backgroundRpc, shadowRoot);
|
|
50
|
+
registerTriggerComponentEventHandler(backgroundRpc, shadowRoot);
|
|
51
|
+
registerSelectComponentHandler(backgroundRpc, shadowRoot);
|
|
52
|
+
createExposureService(backgroundRpc, shadowRoot);
|
|
53
53
|
uiThreadFpReady();
|
|
54
54
|
}
|
|
55
55
|
sendTimingResult(pipelineId, timingFlags, isFP);
|
|
@@ -33,7 +33,7 @@ export function createCrossThreadEvent(domEvent) {
|
|
|
33
33
|
currentTarget: {
|
|
34
34
|
id: currentTargetElement.id,
|
|
35
35
|
dataset: currentTargetElement[lynxRuntimeValue]?.dataset ?? {},
|
|
36
|
-
uniqueId: parseFloat(currentTargetElement.getAttribute(lynxUniqueIdAttribute)),
|
|
36
|
+
uniqueId: parseFloat(currentTargetElement.getAttribute?.(lynxUniqueIdAttribute)),
|
|
37
37
|
},
|
|
38
38
|
// @ts-expect-error
|
|
39
39
|
detail: domEvent.detail ?? {},
|
package/index.css
CHANGED
|
@@ -9,54 +9,17 @@ lynx-view {
|
|
|
9
9
|
display: flex;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
lynx-view::part(lynx-view-root) {
|
|
13
|
-
display: contents;
|
|
14
|
-
width: 100%;
|
|
15
|
-
height: 100%;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
lynx-view[height="auto"] {
|
|
19
|
-
--lynx-view-height: 100%;
|
|
20
|
-
height: var(--lynx-view-height);
|
|
21
|
-
block-size: var(--lynx-view-height);
|
|
22
|
-
}
|
|
23
|
-
lynx-view[height="auto"]::part(lynx-view-root) {
|
|
24
|
-
height: unset;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
12
|
lynx-view[width="auto"] {
|
|
28
13
|
--lynx-view-width: 100%;
|
|
29
14
|
width: var(--lynx-view-width);
|
|
30
15
|
inline-size: var(--lynx-view-width);
|
|
31
16
|
}
|
|
32
|
-
lynx-view[width="auto"]::part(lynx-view-root) {
|
|
33
|
-
width: unset;
|
|
34
|
-
}
|
|
35
17
|
|
|
36
18
|
lynx-view[height="auto"], lynx-view[width="auto"] {
|
|
37
|
-
contain
|
|
38
|
-
}
|
|
39
|
-
lynx-view[height="auto"]::part(lynx-view-root),
|
|
40
|
-
lynx-view[width="auto"]::part(lynx-view-root) {
|
|
41
|
-
display: unset;
|
|
42
|
-
position: fixed;
|
|
43
|
-
top: 0;
|
|
44
|
-
left: 0;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@property --lynx-view-width {
|
|
48
|
-
syntax: "<length> | <percentage>";
|
|
49
|
-
inherits: false;
|
|
50
|
-
initial-value: 100%;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
@property --lynx-view-height {
|
|
54
|
-
syntax: "<length> | <percentage>";
|
|
55
|
-
inherits: false;
|
|
56
|
-
initial-value: 100%;
|
|
19
|
+
contain: content;
|
|
57
20
|
}
|
|
58
21
|
|
|
59
|
-
lynx-view
|
|
22
|
+
lynx-view::part(page) {
|
|
60
23
|
height: 100%;
|
|
61
24
|
width: 100%;
|
|
62
25
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"**/*.css"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@lynx-js/web-constants": "0.9.
|
|
28
|
-
"@lynx-js/web-worker-rpc": "0.9.
|
|
29
|
-
"@lynx-js/web-worker-runtime": "0.9.
|
|
27
|
+
"@lynx-js/web-constants": "0.9.1",
|
|
28
|
+
"@lynx-js/web-worker-rpc": "0.9.1",
|
|
29
|
+
"@lynx-js/web-worker-runtime": "0.9.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@lynx-js/lynx-core": "0.1.0",
|
|
33
|
-
"@lynx-js/web-elements": "0.5.
|
|
33
|
+
"@lynx-js/web-elements": "0.5.1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@lynx-js/lynx-core": "0.1.0",
|