@lynx-js/web-constants 0.17.1 → 0.18.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,36 @@
1
1
  # @lynx-js/web-constants
2
2
 
3
+ ## 0.18.0
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: ([#1837](https://github.com/lynx-family/lynx-stack/pull/1837))
8
+
9
+ 1. `LynxView.updateData()` cannot trigger `dataProcessor`.
10
+
11
+ 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:
12
+
13
+ ```ts
14
+ LynxView.updateData(data: Cloneable, processorName?: string | undefined, callback?: (() => void) | undefined): void
15
+ ```
16
+
17
+ - Updated dependencies []:
18
+ - @lynx-js/web-worker-rpc@0.18.0
19
+
20
+ ## 0.17.2
21
+
22
+ ### Patch Changes
23
+
24
+ - feat: support load bts chunk from remote address ([#1834](https://github.com/lynx-family/lynx-stack/pull/1834))
25
+
26
+ - re-support chunk splitting
27
+ - support lynx.requireModule with a json file
28
+ - support lynx.requireModule, lynx.requireModuleAsync with a remote url
29
+ - support to add a breakpoint in chrome after reloading the web page
30
+
31
+ - Updated dependencies []:
32
+ - @lynx-js/web-worker-rpc@0.17.2
33
+
3
34
  ## 0.17.1
4
35
 
5
36
  ### Patch Changes
@@ -4,6 +4,7 @@ import type { StartMainThreadContextConfig } from './types/MainThreadStartConfig
4
4
  import type { IdentifierType, InvokeCallbackRes } from './types/NativeApp.js';
5
5
  import type { ElementAnimationOptions } from './types/Element.js';
6
6
  import type { BackMainThreadContextConfig, LynxTemplate, MarkTiming } from './types/index.js';
7
+ import type { UpdateDataOptions } from './types/UpdateDataOptions.js';
7
8
  export declare const postExposureEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[{
8
9
  exposures: ExposureWorkerEvent[];
9
10
  disExposures: ExposureWorkerEvent[];
@@ -17,7 +18,7 @@ export declare const publishEventEndpoint: import("@lynx-js/web-worker-rpc/dist/
17
18
  export declare const postOffscreenEventEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[eventType: string, targetUniqueId: number, bubbles: boolean, unknown]>;
18
19
  export declare const switchExposureServiceEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[boolean, boolean]>;
19
20
  export declare const mainThreadStartEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[StartMainThreadContextConfig]>;
20
- export declare const updateDataEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsync<[Cloneable, Record<string, string>], void>;
21
+ export declare const updateDataEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsync<[Cloneable, UpdateDataOptions | undefined], void>;
21
22
  export declare const sendGlobalEventEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[string, Cloneable[] | undefined]>;
22
23
  export declare const disposeEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsync<[], void>;
23
24
  export declare const BackgroundThreadStartEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsync<[BackMainThreadContextConfig], void>;
@@ -39,6 +39,9 @@ export interface LynxTemplate {
39
39
  version?: number;
40
40
  appType: 'card' | 'lazy';
41
41
  }
42
+ export type BTSChunkEntry = (postMessage: undefined, module: {
43
+ exports: unknown;
44
+ }, exports: unknown, lynxCoreInject: unknown, Card: unknown, setTimeout: unknown, setInterval: unknown, clearInterval: unknown, clearTimeout: unknown, NativeModules: unknown, Component: unknown, ReactLynx: unknown, nativeAppId: unknown, Behavior: unknown, LynxJSBI: unknown, lynx: unknown, window: unknown, document: unknown, frames: unknown, location: unknown, navigator: unknown, localStorage: unknown, history: unknown, Caches: unknown, screen: unknown, alert: unknown, confirm: unknown, prompt: unknown, fetch: unknown, XMLHttpRequest: unknown, webkit: unknown, Reporter: unknown, print: unknown, global: unknown, requestAnimationFrame: unknown, cancelAnimationFrame: unknown) => unknown;
42
45
  export interface LynxJSModule {
43
46
  exports?: (lynx_runtime: any) => unknown;
44
47
  }
@@ -6,6 +6,7 @@ import type { FlushElementTreeOptions } from './FlushElementTreeOptions.js';
6
6
  import type { I18nResourceTranslationOptions } from './index.js';
7
7
  import type { MainThreadLynx } from './MainThreadLynx.js';
8
8
  import type { ProcessDataCallback } from './ProcessDataCallback.js';
9
+ import type { UpdateDataOptions } from './UpdateDataOptions.js';
9
10
  type ElementPAPIEventHandler = string | {
10
11
  type: 'worklet';
11
12
  value: unknown;
@@ -171,7 +172,7 @@ export interface MainThreadGlobalThis {
171
172
  __QueryComponent: QueryComponentPAPI;
172
173
  processEvalResult?: (exports: unknown, schema: string) => unknown;
173
174
  renderPage: ((data: unknown) => void) | undefined;
174
- updatePage?: (data: Cloneable, options?: Record<string, string>) => void;
175
+ updatePage?: (data: Cloneable, options?: UpdateDataOptions) => void;
175
176
  runWorklet?: (obj: unknown, event: unknown) => void;
176
177
  }
177
178
  export {};
@@ -82,8 +82,9 @@ export interface NativeApp {
82
82
  clearInterval: typeof clearInterval;
83
83
  requestAnimationFrame: (cb: () => void) => void;
84
84
  cancelAnimationFrame: (id: number) => void;
85
+ readScript: (sourceURL: string, entryName?: string) => string;
85
86
  loadScript: (sourceURL: string, entryName?: string) => BundleInitReturnObj;
86
- loadScriptAsync(sourceURL: string, callback: (message: string | null, exports?: BundleInitReturnObj) => void): void;
87
+ loadScriptAsync(sourceURL: string, callback: (message: string | null, exports?: BundleInitReturnObj) => void, entryName?: string): void;
87
88
  nativeModuleProxy: Record<string, any>;
88
89
  setNativeProps: (type: IdentifierType, identifier: string, component_id: string, first_only: boolean, native_props: Record<string, unknown>, root_unique_id: number | undefined) => void;
89
90
  invokeUIMethod: (type: IdentifierType, identifier: string, component_id: string, method: string, params: object, callback: (ret: InvokeCallbackRes) => void, root_unique_id: number) => void;
@@ -2,13 +2,7 @@ export declare const enum NativeUpdateDataType {
2
2
  UPDATE = 0,
3
3
  RESET = 1
4
4
  }
5
- export declare const enum UpdateDataType {
6
- Unknown = 0,
7
- UpdateExplicitByUser = 1,
8
- UpdateByKernelFromCtor = 2,
9
- UpdateByKernelFromRender = 4,
10
- UpdateByKernelFromHydrate = 8,
11
- UpdateByKernelFromGetDerived = 16,
12
- UpdateByKernelFromConflict = 32,
13
- UpdateByKernelFromHMR = 64
5
+ export interface UpdateDataOptions {
6
+ type?: NativeUpdateDataType;
7
+ processorName?: string;
14
8
  }
@@ -3,23 +3,4 @@ export var NativeUpdateDataType;
3
3
  NativeUpdateDataType[NativeUpdateDataType["UPDATE"] = 0] = "UPDATE";
4
4
  NativeUpdateDataType[NativeUpdateDataType["RESET"] = 1] = "RESET";
5
5
  })(NativeUpdateDataType || (NativeUpdateDataType = {}));
6
- export var UpdateDataType;
7
- (function (UpdateDataType) {
8
- // default
9
- UpdateDataType[UpdateDataType["Unknown"] = 0] = "Unknown";
10
- // update by `setState` or `setData`
11
- UpdateDataType[UpdateDataType["UpdateExplicitByUser"] = 1] = "UpdateExplicitByUser";
12
- // update by lynx_core from ctor
13
- UpdateDataType[UpdateDataType["UpdateByKernelFromCtor"] = 2] = "UpdateByKernelFromCtor";
14
- // update by lynx_core from render
15
- UpdateDataType[UpdateDataType["UpdateByKernelFromRender"] = 4] = "UpdateByKernelFromRender";
16
- // update by hydrate
17
- UpdateDataType[UpdateDataType["UpdateByKernelFromHydrate"] = 8] = "UpdateByKernelFromHydrate";
18
- // update by `getDerivedStateFromProps`
19
- UpdateDataType[UpdateDataType["UpdateByKernelFromGetDerived"] = 16] = "UpdateByKernelFromGetDerived";
20
- // update by conflict detected
21
- UpdateDataType[UpdateDataType["UpdateByKernelFromConflict"] = 32] = "UpdateByKernelFromConflict";
22
- // update by HMR
23
- UpdateDataType[UpdateDataType["UpdateByKernelFromHMR"] = 64] = "UpdateByKernelFromHMR";
24
- })(UpdateDataType || (UpdateDataType = {}));
25
6
  //# sourceMappingURL=UpdateDataOptions.js.map
@@ -1,2 +1,2 @@
1
1
  import type { LynxTemplate } from '../types/LynxModule.js';
2
- export declare function generateTemplate(template: LynxTemplate, createJsModuleUrl: ((content: string, name: string) => Promise<string>) | ((content: string) => string), templateName?: string): Promise<LynxTemplate>;
2
+ export declare function generateTemplate(template: LynxTemplate, createJsModuleUrl: ((content: string, name: string) => Promise<string>) | ((content: string) => string), templateName: string): Promise<LynxTemplate>;
@@ -2,61 +2,18 @@
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
  const currentSupportedTemplateVersion = 2;
5
- const globalDisallowedVars = ['navigator', 'postMessage'];
5
+ const globalDisallowedVars = ['navigator', 'postMessage', 'window'];
6
6
  const templateUpgraders = [
7
7
  (template) => {
8
- const defaultInjectStr = [
9
- 'Card',
10
- 'setTimeout',
11
- 'setInterval',
12
- 'clearInterval',
13
- 'clearTimeout',
14
- 'NativeModules',
15
- 'Component',
16
- 'ReactLynx',
17
- 'nativeAppId',
18
- 'Behavior',
19
- 'LynxJSBI',
20
- 'lynx',
21
- // BOM API
22
- 'window',
23
- 'document',
24
- 'frames',
25
- 'location',
26
- 'navigator',
27
- 'localStorage',
28
- 'history',
29
- 'Caches',
30
- 'screen',
31
- 'alert',
32
- 'confirm',
33
- 'prompt',
34
- 'fetch',
35
- 'XMLHttpRequest',
36
- '__WebSocket__', // We would provide `WebSocket` using `ProvidePlugin`
37
- 'webkit',
38
- 'Reporter',
39
- 'print',
40
- 'global',
41
- // Lynx API
42
- 'requestAnimationFrame',
43
- 'cancelAnimationFrame',
44
- ].join(',');
45
8
  template.appType = template.appType ?? (template.lepusCode.root.startsWith('(function (globDynamicComponentEntry')
46
9
  ? 'lazy'
47
10
  : 'card');
48
- /**
49
- * The template version 1 has no module wrapper for bts code
50
- */
51
- template.manifest = Object.fromEntries(Object.entries(template.manifest).map(([key, value]) => [
52
- key,
53
- `module.exports={init: (lynxCoreInject) => { var {${defaultInjectStr}} = lynxCoreInject.tt; var module = {exports:{}}; var exports=module.exports; ${value}\n return module.exports; } }`,
54
- ]));
55
11
  template.version = 2;
12
+ template.lepusCode = Object.fromEntries(Object.entries(template.lepusCode).filter(([_, content]) => typeof content === 'string'));
56
13
  return template;
57
14
  },
58
15
  ];
59
- const generateModuleContent = (content, eager, appType) =>
16
+ const generateModuleContent = (fileName, content, eager, appType) =>
60
17
  /**
61
18
  * About the `allFunctionsCalledOnLoad` directive:
62
19
  * https://v8.dev/blog/preparser#pife
@@ -75,13 +32,16 @@ const generateModuleContent = (content, eager, appType) =>
75
32
  appType !== 'card' ? 'module.exports=\n' : '',
76
33
  content,
77
34
  '\n})()',
35
+ '\n//# sourceURL=',
36
+ fileName,
78
37
  ].join('');
79
38
  async function generateJavascriptUrl(obj, createJsModuleUrl, eager, appType, templateName) {
80
- const processEntry = async ([name, content]) => [
81
- name,
82
- await createJsModuleUrl(generateModuleContent(content, eager, appType), `${templateName}-${name.replaceAll('/', '')}.js`),
83
- ];
84
- return Promise.all(Object.entries(obj).filter(([_, content]) => typeof content === 'string').map(processEntry)).then(Object.fromEntries);
39
+ return Promise.all(Object.entries(obj).filter(([_, content]) => typeof content === 'string').map(async ([name, content]) => {
40
+ return [
41
+ name,
42
+ await createJsModuleUrl(generateModuleContent(`${templateName}/${name.replaceAll('/', '_')}.js`, content, eager, appType), `${templateName}-${name.replaceAll('/', '_')}.js`),
43
+ ];
44
+ })).then(Object.fromEntries);
85
45
  }
86
46
  export async function generateTemplate(template, createJsModuleUrl, templateName) {
87
47
  template.version = template.version ?? 1;
@@ -96,7 +56,6 @@ export async function generateTemplate(template, createJsModuleUrl, templateName
96
56
  return {
97
57
  ...template,
98
58
  lepusCode: await generateJavascriptUrl(template.lepusCode, createJsModuleUrl, true, template.appType, templateName),
99
- manifest: await generateJavascriptUrl(template.manifest, createJsModuleUrl, false, template.appType, templateName),
100
59
  };
101
60
  }
102
61
  //# sourceMappingURL=generateTemplate.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-constants",
3
- "version": "0.17.1",
3
+ "version": "0.18.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -23,7 +23,7 @@
23
23
  "**/*.css"
24
24
  ],
25
25
  "dependencies": {
26
- "@lynx-js/web-worker-rpc": "0.17.1"
26
+ "@lynx-js/web-worker-rpc": "0.18.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@lynx-js/offscreen-document": "0.1.4"