@lynx-js/web-mainthread-apis 0.17.2 → 0.18.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 CHANGED
@@ -1,5 +1,39 @@
1
1
  # @lynx-js/web-mainthread-apis
2
2
 
3
+ ## 0.18.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: mts freeze after reload() ([#1892](https://github.com/lynx-family/lynx-stack/pull/1892))
8
+
9
+ The mts may be freezed after reload() called.
10
+
11
+ We fixed it by waiting until the all-on-ui Javascript realm implementation, an iframe, to be fully loaded.
12
+
13
+ - Updated dependencies []:
14
+ - @lynx-js/web-constants@0.18.1
15
+ - @lynx-js/web-style-transformer@0.18.1
16
+
17
+ ## 0.18.0
18
+
19
+ ### Patch Changes
20
+
21
+ - fix: ([#1837](https://github.com/lynx-family/lynx-stack/pull/1837))
22
+
23
+ 1. `LynxView.updateData()` cannot trigger `dataProcessor`.
24
+
25
+ 2. **This is a break change:** The second parameter of `LynxView.updateData()` has been changed from `UpdateDataType` to `string`, which is the `processorName` (default is `default` which will use `defaultDataProcessor`). This change is to better align with Native. The current complete type is as follows:
26
+
27
+ ```ts
28
+ LynxView.updateData(data: Cloneable, processorName?: string | undefined, callback?: (() => void) | undefined): void
29
+ ```
30
+
31
+ - feat: mouse event output structures remain aligned ([#1820](https://github.com/lynx-family/lynx-stack/pull/1820))
32
+
33
+ - Updated dependencies [[`77397fd`](https://github.com/lynx-family/lynx-stack/commit/77397fd535cf60556f8f82f7ef8dae8a623d1625)]:
34
+ - @lynx-js/web-constants@0.18.0
35
+ - @lynx-js/web-style-transformer@0.18.0
36
+
3
37
  ## 0.17.2
4
38
 
5
39
  ### Patch Changes
@@ -1,4 +1,5 @@
1
- import { type Rpc, type StartMainThreadContextConfig, type RpcCallType, type reportErrorEndpoint, type I18nResourceTranslationOptions, type InitI18nResources, type I18nResources, type SSRHydrateInfo, type SSRDehydrateHooks, type JSRealm, type TemplateLoader } from '@lynx-js/web-constants';
2
- export declare function prepareMainThreadAPIs(backgroundThreadRpc: Rpc, rootDom: Document | ShadowRoot, document: Document, mtsRealm: JSRealm, commitDocument: (exposureChangedElements: HTMLElement[]) => Promise<void> | void, markTimingInternal: (timingKey: string, pipelineId?: string) => void, flushMarkTimingInternal: () => void, reportError: RpcCallType<typeof reportErrorEndpoint>, triggerI18nResourceFallback: (options: I18nResourceTranslationOptions) => void, initialI18nResources: (data: InitI18nResources) => I18nResources, loadTemplate: TemplateLoader, ssrHooks?: SSRDehydrateHooks): {
1
+ import { type Rpc, type StartMainThreadContextConfig, type RpcCallType, type reportErrorEndpoint, type I18nResourceTranslationOptions, type InitI18nResources, type I18nResources, type Cloneable, type SSRHydrateInfo, type SSRDehydrateHooks, type JSRealm, type TemplateLoader, type UpdateDataOptions } from '@lynx-js/web-constants';
2
+ export declare function prepareMainThreadAPIs(backgroundThreadRpc: Rpc, rootDom: Document | ShadowRoot, document: Document, mtsRealmPromise: JSRealm | Promise<JSRealm>, commitDocument: (exposureChangedElements: HTMLElement[]) => Promise<void> | void, markTimingInternal: (timingKey: string, pipelineId?: string) => void, flushMarkTimingInternal: () => void, reportError: RpcCallType<typeof reportErrorEndpoint>, triggerI18nResourceFallback: (options: I18nResourceTranslationOptions) => void, initialI18nResources: (data: InitI18nResources) => I18nResources, loadTemplate: TemplateLoader, ssrHooks?: SSRDehydrateHooks): {
3
3
  startMainThread: (config: StartMainThreadContextConfig, ssrHydrateInfo?: SSRHydrateInfo) => Promise<void>;
4
+ handleUpdatedData: (newData: Cloneable, options: UpdateDataOptions | undefined) => Promise<void>;
4
5
  };
@@ -1,7 +1,7 @@
1
1
  // Copyright 2023 The Lynx Authors. All rights reserved.
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
- import { BackgroundThreadStartEndpoint, publishEventEndpoint, publicComponentEventEndpoint, postExposureEndpoint, postTimingFlagsEndpoint, dispatchCoreContextOnBackgroundEndpoint, dispatchJSContextOnMainThreadEndpoint, LynxCrossThreadContext, switchExposureServiceEndpoint, getCacheI18nResourcesKey, dispatchI18nResourceEndpoint, } from '@lynx-js/web-constants';
4
+ import { BackgroundThreadStartEndpoint, publishEventEndpoint, publicComponentEventEndpoint, postExposureEndpoint, postTimingFlagsEndpoint, dispatchCoreContextOnBackgroundEndpoint, dispatchJSContextOnMainThreadEndpoint, LynxCrossThreadContext, switchExposureServiceEndpoint, getCacheI18nResourcesKey, dispatchI18nResourceEndpoint, updateDataEndpoint, } from '@lynx-js/web-constants';
5
5
  import { registerCallLepusMethodHandler } from './crossThreadHandlers/registerCallLepusMethodHandler.js';
6
6
  import { registerGetCustomSectionHandler } from './crossThreadHandlers/registerGetCustomSectionHandler.js';
7
7
  import { createMainThreadGlobalThis } from './createMainThreadGlobalThis.js';
@@ -10,18 +10,20 @@ import { initWasm } from '@lynx-js/web-style-transformer';
10
10
  import { appendStyleElement } from './utils/processStyleInfo.js';
11
11
  import { createQueryComponent } from './crossThreadHandlers/createQueryComponent.js';
12
12
  const initWasmPromise = initWasm();
13
- export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealm, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, loadTemplate, ssrHooks) {
13
+ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealmPromise, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, loadTemplate, ssrHooks) {
14
14
  const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
15
15
  const backgroundStart = backgroundThreadRpc.createCall(BackgroundThreadStartEndpoint);
16
16
  const publishEvent = backgroundThreadRpc.createCall(publishEventEndpoint);
17
17
  const publicComponentEvent = backgroundThreadRpc.createCall(publicComponentEventEndpoint);
18
18
  const postExposure = backgroundThreadRpc.createCall(postExposureEndpoint);
19
19
  const dispatchI18nResource = backgroundThreadRpc.createCall(dispatchI18nResourceEndpoint);
20
+ const updateDataBackground = backgroundThreadRpc.createCall(updateDataEndpoint);
20
21
  markTimingInternal('lepus_execute_start');
21
22
  async function startMainThread(config, ssrHydrateInfo) {
22
23
  let isFp = true;
23
24
  const { globalProps, template, browserConfig, nativeModulesMap, napiModulesMap, tagMap, initI18nResources, } = config;
24
25
  const { styleInfo, pageConfig, customSections, cardType, } = template;
26
+ const mtsRealm = await mtsRealmPromise;
25
27
  markTimingInternal('decode_start');
26
28
  await initWasmPromise;
27
29
  const jsContext = new LynxCrossThreadContext({
@@ -140,6 +142,15 @@ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mt
140
142
  await mtsRealm.loadScript(template.lepusCode.root);
141
143
  jsContext.__start(); // start the jsContext after the runtime is created
142
144
  }
143
- return { startMainThread };
145
+ async function handleUpdatedData(newData, options) {
146
+ const mtsRealm = await mtsRealmPromise;
147
+ const runtime = mtsRealm.globalWindow;
148
+ const processedData = runtime.processData
149
+ ? runtime.processData(newData, options?.processorName)
150
+ : newData;
151
+ runtime.updatePage?.(processedData, options);
152
+ return updateDataBackground(processedData, options);
153
+ }
154
+ return { startMainThread, handleUpdatedData };
144
155
  }
145
156
  //# sourceMappingURL=prepareMainThreadAPIs.js.map
@@ -52,6 +52,19 @@ export function createCrossThreadEvent(domEvent, eventName) {
52
52
  : changedTouches,
53
53
  });
54
54
  }
55
+ else if (type.startsWith('mouse')) {
56
+ const mouseEvent = domEvent;
57
+ Object.assign(otherProperties, {
58
+ button: mouseEvent.button,
59
+ buttons: mouseEvent.buttons,
60
+ x: mouseEvent.x,
61
+ y: mouseEvent.y,
62
+ pageX: mouseEvent.pageX,
63
+ pageY: mouseEvent.pageY,
64
+ clientX: mouseEvent.clientX,
65
+ clientY: mouseEvent.clientY,
66
+ });
67
+ }
55
68
  const currentTargetDatasetString = currentTargetElement?.getAttribute(lynxDatasetAttribute);
56
69
  const currentTargetDataset = currentTargetDatasetString
57
70
  ? JSON.parse(decodeURIComponent(currentTargetDatasetString))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-mainthread-apis",
3
- "version": "0.17.2",
3
+ "version": "0.18.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -25,7 +25,7 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "hyphenate-style-name": "^1.1.0",
28
- "@lynx-js/web-constants": "0.17.2",
29
- "@lynx-js/web-style-transformer": "0.17.2"
28
+ "@lynx-js/web-constants": "0.18.1",
29
+ "@lynx-js/web-style-transformer": "0.18.1"
30
30
  }
31
31
  }