@lynx-js/web-core 0.15.4 → 0.15.6

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,45 @@
1
1
  # @lynx-js/web-core
2
2
 
3
+ ## 0.15.6
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: systeminfo in mts function ([#1537](https://github.com/lynx-family/lynx-stack/pull/1537))
8
+
9
+ - refactor: use utf-8 string ([#1473](https://github.com/lynx-family/lynx-stack/pull/1473))
10
+
11
+ - Fix mtsGlobalThis race condition in createRenderAllOnUI ([#1506](https://github.com/lynx-family/lynx-stack/pull/1506))
12
+
13
+ - Updated dependencies [[`405a917`](https://github.com/lynx-family/lynx-stack/commit/405a9170442ae32603b7687549b49ab4b34aff92), [`b8f89e2`](https://github.com/lynx-family/lynx-stack/commit/b8f89e25f106a15ba9d70f2df06dfb684cbb6633), [`f76aae9`](https://github.com/lynx-family/lynx-stack/commit/f76aae9ea06abdc7022ba508d22f9f4eb00864e8), [`b8b060b`](https://github.com/lynx-family/lynx-stack/commit/b8b060b9bef722bb47bd90c33fab3922160c711d), [`d8381a5`](https://github.com/lynx-family/lynx-stack/commit/d8381a58d12af6424cab4955617251e798bdc9f1), [`214898b`](https://github.com/lynx-family/lynx-stack/commit/214898bb9c74fc9b44e68cb220a4c02485102ce2), [`ab8cee4`](https://github.com/lynx-family/lynx-stack/commit/ab8cee4bab384fa905c045c4b4b93e5d4a95d57f)]:
14
+ - @lynx-js/web-mainthread-apis@0.15.6
15
+ - @lynx-js/web-constants@0.15.6
16
+ - @lynx-js/web-worker-runtime@0.15.6
17
+ - @lynx-js/web-worker-rpc@0.15.6
18
+
19
+ ## 0.15.5
20
+
21
+ ### Patch Changes
22
+
23
+ - fix: load main-thread chunk in ESM format ([#1437](https://github.com/lynx-family/lynx-stack/pull/1437))
24
+
25
+ See [nodejs/node#59362](https://github.com/nodejs/node/issues/59362) for more details.
26
+
27
+ - feat: support path() for `createQuerySelector` ([#1456](https://github.com/lynx-family/lynx-stack/pull/1456))
28
+
29
+ - Added `getPathInfo` API to `NativeApp` and its cross-thread handler for retrieving the path from a DOM node to the root.
30
+ - Implemented endpoint and handler registration in both background and UI threads.
31
+ - Implemented `nativeApp.getPathInfo()`
32
+
33
+ - fix: when `onNativeModulesCall` is delayed in mounting, the NativeModules execution result may be undefined. ([#1457](https://github.com/lynx-family/lynx-stack/pull/1457))
34
+
35
+ - fix: `onNativeModulesCall` && `onNapiModulesCall` use getter to get. ([#1466](https://github.com/lynx-family/lynx-stack/pull/1466))
36
+
37
+ - Updated dependencies [[`29434ae`](https://github.com/lynx-family/lynx-stack/commit/29434aec853f14242f521316429cf07a93b8c371), [`fb7096b`](https://github.com/lynx-family/lynx-stack/commit/fb7096bb3c79166cd619a407095b8206eccb7918)]:
38
+ - @lynx-js/web-mainthread-apis@0.15.5
39
+ - @lynx-js/web-constants@0.15.5
40
+ - @lynx-js/web-worker-runtime@0.15.5
41
+ - @lynx-js/web-worker-rpc@0.15.5
42
+
3
43
  ## 0.15.4
4
44
 
5
45
  ### Patch Changes
@@ -156,11 +156,10 @@ export class LynxView extends HTMLElement {
156
156
  }
157
157
  set onNativeModulesCall(handler) {
158
158
  this.#onNativeModulesCall = handler;
159
- if (this.#cachedNativeModulesCall) {
160
- for (const callInfo of this.#cachedNativeModulesCall) {
161
- handler.apply(undefined, callInfo);
162
- }
159
+ for (const callInfo of this.#cachedNativeModulesCall) {
160
+ callInfo.resolve(handler.apply(undefined, callInfo.args));
163
161
  }
162
+ this.#cachedNativeModulesCall = [];
164
163
  }
165
164
  #nativeModulesMap = {};
166
165
  /**
@@ -374,18 +373,17 @@ export class LynxView extends HTMLElement {
374
373
  initI18nResources: this.#initI18nResources,
375
374
  callbacks: {
376
375
  nativeModulesCall: (...args) => {
377
- if (this.#onNativeModulesCall) {
378
- return this.#onNativeModulesCall(...args);
379
- }
380
- else if (this.#cachedNativeModulesCall) {
381
- this.#cachedNativeModulesCall.push(args);
376
+ if (this.onNativeModulesCall) {
377
+ return this.onNativeModulesCall(...args);
382
378
  }
383
379
  else {
384
- this.#cachedNativeModulesCall = [args];
380
+ return new Promise(resolve => {
381
+ this.#cachedNativeModulesCall.push({ args, resolve });
382
+ });
385
383
  }
386
384
  },
387
385
  napiModulesCall: (...args) => {
388
- return this.#onNapiModulesCall?.(...args);
386
+ return this.onNapiModulesCall?.(...args);
389
387
  },
390
388
  onError: (error, release, fileName) => {
391
389
  this.dispatchEvent(new CustomEvent('error', {
@@ -22,6 +22,7 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingI
22
22
  return i18nResources;
23
23
  });
24
24
  let mtsGlobalThis;
25
+ const pendingUpdateCalls = [];
25
26
  const start = async (configs) => {
26
27
  if (ssrDumpInfo) {
27
28
  const lynxUniqueIdToElement = [];
@@ -56,9 +57,20 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingI
56
57
  else {
57
58
  mtsGlobalThis = await startMainThread(configs);
58
59
  }
60
+ // Process any pending update calls that were queued while mtsGlobalThis was undefined
61
+ for (const args of pendingUpdateCalls) {
62
+ mtsGlobalThis.updatePage?.(...args);
63
+ }
64
+ pendingUpdateCalls.length = 0;
59
65
  };
60
66
  const updateDataMainThread = async (...args) => {
61
- mtsGlobalThis.updatePage?.(...args);
67
+ if (mtsGlobalThis) {
68
+ mtsGlobalThis.updatePage?.(...args);
69
+ }
70
+ else {
71
+ // Cache the call if mtsGlobalThis is not yet initialized
72
+ pendingUpdateCalls.push(args);
73
+ }
62
74
  };
63
75
  const updateI18nResourcesMainThread = (data) => {
64
76
  i18nResources.setData(data);
@@ -0,0 +1,2 @@
1
+ import { Rpc } from '@lynx-js/web-worker-rpc';
2
+ export declare function registerGetPathInfoHandler(rpc: Rpc, shadowRoot: ShadowRoot): void;
@@ -0,0 +1,52 @@
1
+ // Copyright 2023 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { Rpc } from '@lynx-js/web-worker-rpc';
5
+ import { ErrorCode, getPathInfoEndpoint, lynxDatasetAttribute, lynxTagAttribute, } from '@lynx-js/web-constants';
6
+ import { queryNodes } from './queryNodes.js';
7
+ export function registerGetPathInfoHandler(rpc, shadowRoot) {
8
+ rpc.registerHandler(getPathInfoEndpoint, (type, identifier, component_id, first_only, root_unique_id) => {
9
+ let code = ErrorCode.UNKNOWN;
10
+ let data;
11
+ queryNodes(shadowRoot, type, identifier, component_id, first_only, root_unique_id, (element) => {
12
+ try {
13
+ const path = [];
14
+ let currentNode = element;
15
+ while (currentNode) {
16
+ const parent = currentNode.parentElement;
17
+ const parentNodeForChildren = parent ?? shadowRoot;
18
+ const children = Array.from(parentNodeForChildren.children);
19
+ const tag = currentNode.getAttribute(lynxTagAttribute);
20
+ const index = tag === 'page' ? 0 : children.indexOf(currentNode);
21
+ const id = currentNode.getAttribute('id') || undefined;
22
+ const className = currentNode.getAttribute('class') || undefined;
23
+ const datasetString = currentNode.getAttribute(lynxDatasetAttribute);
24
+ const dataSet = datasetString
25
+ ? JSON.parse(decodeURIComponent(datasetString))
26
+ : undefined;
27
+ path.push({
28
+ tag,
29
+ id,
30
+ class: className,
31
+ dataSet,
32
+ index,
33
+ });
34
+ if (tag === 'page' || currentNode.parentNode === shadowRoot) {
35
+ break;
36
+ }
37
+ currentNode = parent;
38
+ }
39
+ data = { path };
40
+ code = ErrorCode.SUCCESS;
41
+ }
42
+ catch (e) {
43
+ console.error('[lynx-web] getPathInfo: failed with', e, element);
44
+ code = ErrorCode.UNKNOWN;
45
+ }
46
+ }, (error) => {
47
+ code = error;
48
+ });
49
+ return { code, data };
50
+ });
51
+ }
52
+ //# sourceMappingURL=registerGetPathInfoHandler.js.map
@@ -8,6 +8,7 @@ import { registerNapiModulesCallHandler } from './crossThreadHandlers/registerNa
8
8
  import { registerDispatchLynxViewEventHandler } from './crossThreadHandlers/registerDispatchLynxViewEventHandler.js';
9
9
  import { registerTriggerElementMethodEndpointHandler } from './crossThreadHandlers/registerTriggerElementMethodEndpointHandler.js';
10
10
  import { registerReportErrorHandler } from './crossThreadHandlers/registerReportErrorHandler.js';
11
+ import { registerGetPathInfoHandler } from './crossThreadHandlers/registerGetPathInfoHandler.js';
11
12
  export function startBackground(backgroundRpc, shadowRoot, callbacks) {
12
13
  registerInvokeUIMethodHandler(backgroundRpc, shadowRoot);
13
14
  registerNativePropsHandler(backgroundRpc, shadowRoot);
@@ -15,6 +16,7 @@ export function startBackground(backgroundRpc, shadowRoot, callbacks) {
15
16
  registerSelectComponentHandler(backgroundRpc, shadowRoot);
16
17
  registerNativeModulesCallHandler(backgroundRpc, callbacks.nativeModulesCall);
17
18
  registerNapiModulesCallHandler(backgroundRpc, callbacks.napiModulesCall);
19
+ registerGetPathInfoHandler(backgroundRpc, shadowRoot);
18
20
  registerDispatchLynxViewEventHandler(backgroundRpc, shadowRoot);
19
21
  registerTriggerElementMethodEndpointHandler(backgroundRpc, shadowRoot);
20
22
  registerReportErrorHandler(backgroundRpc, 'app-service.js', callbacks.onError);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core",
3
- "version": "0.15.4",
3
+ "version": "0.15.6",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -25,17 +25,17 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "@lynx-js/offscreen-document": "0.1.3",
28
- "@lynx-js/web-constants": "0.15.4",
29
- "@lynx-js/web-mainthread-apis": "0.15.4",
30
- "@lynx-js/web-worker-rpc": "0.15.4",
31
- "@lynx-js/web-worker-runtime": "0.15.4"
28
+ "@lynx-js/web-constants": "0.15.6",
29
+ "@lynx-js/web-mainthread-apis": "0.15.6",
30
+ "@lynx-js/web-worker-rpc": "0.15.6",
31
+ "@lynx-js/web-worker-runtime": "0.15.6"
32
32
  },
33
33
  "devDependencies": {
34
- "@lynx-js/lynx-core": "0.1.2",
35
- "@lynx-js/web-elements": "0.8.3"
34
+ "@lynx-js/lynx-core": "0.1.3",
35
+ "@lynx-js/web-elements": "0.8.4"
36
36
  },
37
37
  "peerDependencies": {
38
- "@lynx-js/lynx-core": "0.1.2",
38
+ "@lynx-js/lynx-core": "0.1.3",
39
39
  "@lynx-js/web-elements": ">0.7.7"
40
40
  }
41
41
  }