@lynx-js/web-core 0.10.0 → 0.10.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,24 @@
1
1
  # @lynx-js/web-core
2
2
 
3
+ ## 0.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - docs: fix documents about lynx-view's properties ([#412](https://github.com/lynx-family/lynx-stack/pull/412))
8
+
9
+ Attributes should be hyphen-name: 'init-data', 'global-props'.
10
+
11
+ now all properties has corresponding attributes.
12
+
13
+ - feat: onNapiModulesCall function add new param: `dispatchNapiModules`, napiModulesMap val add new param: `handleDispatch`. ([#414](https://github.com/lynx-family/lynx-stack/pull/414))
14
+
15
+ Now you can use them to actively communicate to napiModules (background thread) in onNapiModulesCall (ui thread).
16
+
17
+ - Updated dependencies [[`1af3b60`](https://github.com/lynx-family/lynx-stack/commit/1af3b6052ab27f98bf0e4d1b0ec9f7d9e88e0afc)]:
18
+ - @lynx-js/web-constants@0.10.1
19
+ - @lynx-js/web-worker-runtime@0.10.1
20
+ - @lynx-js/web-worker-rpc@0.10.1
21
+
3
22
  ## 0.10.0
4
23
 
5
24
  ### Minor Changes
@@ -1,5 +1,5 @@
1
1
  import { type Cloneable, type NapiModulesCall, type NapiModulesMap, type NativeModulesCall, type NativeModulesMap, type UpdateDataType } from '@lynx-js/web-constants';
2
- export type INapiModulesCall = (name: string, data: any, moduleName: string, lynxView: LynxView) => Promise<{
2
+ export type INapiModulesCall = (name: string, data: any, moduleName: string, lynxView: LynxView, dispatchNapiModules: (data: Cloneable) => void) => Promise<{
3
3
  data: unknown;
4
4
  transfer?: Transferable[];
5
5
  }> | {
@@ -10,17 +10,17 @@ export type INapiModulesCall = (name: string, data: any, moduleName: string, lyn
10
10
  * Based on our experiences, these elements are almost used in all lynx cards.
11
11
  */
12
12
  /**
13
- * @param {string} url [required] The url of the entry of your Lynx card
14
- * @param {Cloneable} globalProps [optional] The globalProps value of this Lynx card
15
- * @param {Cloneable} initData [oprional] The initial data of this Lynx card
16
- * @param {Record<string,string>} overrideLynxTagToHTMLTagMap [optional] use this property/attribute to override the lynx tag -> html tag map
17
- * @param {NativeModulesMap} nativeModulesMap [optional] use to customize NativeModules. key is module-name, value is esm url.
18
- * @param {NativeModulesCall} onNativeModulesCall [optional] the NativeModules value handler. Arguments will be cached before this property is assigned.
19
- * @param {"auto" | null} height [optional] set it to "auto" for height auto-sizing
20
- * @param {"auto" | null} width [optional] set it to "auto" for width auto-sizing
21
- * @param {NapiModulesMap} napiModulesMap [optional] the napiModule which is called in lynx-core. key is module-name, value is esm url.
22
- * @param {INapiModulesCall} onNapiModulesCall [optional] the NapiModule value handler.
23
- * @param {"false" | "true" | null} injectHeadLinks [optional] @default true set it to "false" to disable injecting the <link href="" ref="stylesheet"> styles into shadowroot
13
+ * @property {string} url [required] (attribute: "url") The url of the entry of your Lynx card
14
+ * @property {Cloneable} globalProps [optional] (attribute: "global-props") The globalProps value of this Lynx card
15
+ * @property {Cloneable} initData [oprional] (attribute: "init-data") The initial data of this Lynx card
16
+ * @property {Record<string,string>} overrideLynxTagToHTMLTagMap [optional] use this property/attribute to override the lynx tag -> html tag map
17
+ * @property {NativeModulesMap} nativeModulesMap [optional] use to customize NativeModules. key is module-name, value is esm url.
18
+ * @property {NativeModulesCall} onNativeModulesCall [optional] the NativeModules value handler. Arguments will be cached before this property is assigned.
19
+ * @property {"auto" | null} height [optional] (attribute: "height") set it to "auto" for height auto-sizing
20
+ * @property {"auto" | null} width [optional] (attribute: "width") set it to "auto" for width auto-sizing
21
+ * @property {NapiModulesMap} napiModulesMap [optional] the napiModule which is called in lynx-core. key is module-name, value is esm url.
22
+ * @property {INapiModulesCall} onNapiModulesCall [optional] the NapiModule value handler.
23
+ * @property {"false" | "true" | null} injectHeadLinks [optional] @default true set it to "false" to disable injecting the <link href="" ref="stylesheet"> styles into shadowroot
24
24
  *
25
25
  * @event error lynx card fired an error
26
26
  *
@@ -30,7 +30,7 @@ export type INapiModulesCall = (name: string, data: any, moduleName: string, lyn
30
30
  * Note that you should declarae the size of lynx-view
31
31
  *
32
32
  * ```html
33
- * <lynx-view url="https://path/to/main-thread.js" rawData="{}" globalProps="{}" style="height:300px;width:300px">
33
+ * <lynx-view url="https://path/to/main-thread.js" raw-data="{}" global-props="{}" style="height:300px;width:300px">
34
34
  * </lynx-view>
35
35
  * ```
36
36
  *
@@ -45,7 +45,6 @@ export declare class LynxView extends HTMLElement {
45
45
  static lynxViewCount: number;
46
46
  static tag: "lynx-view";
47
47
  private static observedAttributeAsProperties;
48
- private static attributeCamelCaseMap;
49
48
  /**
50
49
  * @private
51
50
  */
@@ -8,17 +8,17 @@ import { inShadowRootStyles } from './inShadowRootStyles.js';
8
8
  * Based on our experiences, these elements are almost used in all lynx cards.
9
9
  */
10
10
  /**
11
- * @param {string} url [required] The url of the entry of your Lynx card
12
- * @param {Cloneable} globalProps [optional] The globalProps value of this Lynx card
13
- * @param {Cloneable} initData [oprional] The initial data of this Lynx card
14
- * @param {Record<string,string>} overrideLynxTagToHTMLTagMap [optional] use this property/attribute to override the lynx tag -> html tag map
15
- * @param {NativeModulesMap} nativeModulesMap [optional] use to customize NativeModules. key is module-name, value is esm url.
16
- * @param {NativeModulesCall} onNativeModulesCall [optional] the NativeModules value handler. Arguments will be cached before this property is assigned.
17
- * @param {"auto" | null} height [optional] set it to "auto" for height auto-sizing
18
- * @param {"auto" | null} width [optional] set it to "auto" for width auto-sizing
19
- * @param {NapiModulesMap} napiModulesMap [optional] the napiModule which is called in lynx-core. key is module-name, value is esm url.
20
- * @param {INapiModulesCall} onNapiModulesCall [optional] the NapiModule value handler.
21
- * @param {"false" | "true" | null} injectHeadLinks [optional] @default true set it to "false" to disable injecting the <link href="" ref="stylesheet"> styles into shadowroot
11
+ * @property {string} url [required] (attribute: "url") The url of the entry of your Lynx card
12
+ * @property {Cloneable} globalProps [optional] (attribute: "global-props") The globalProps value of this Lynx card
13
+ * @property {Cloneable} initData [oprional] (attribute: "init-data") The initial data of this Lynx card
14
+ * @property {Record<string,string>} overrideLynxTagToHTMLTagMap [optional] use this property/attribute to override the lynx tag -> html tag map
15
+ * @property {NativeModulesMap} nativeModulesMap [optional] use to customize NativeModules. key is module-name, value is esm url.
16
+ * @property {NativeModulesCall} onNativeModulesCall [optional] the NativeModules value handler. Arguments will be cached before this property is assigned.
17
+ * @property {"auto" | null} height [optional] (attribute: "height") set it to "auto" for height auto-sizing
18
+ * @property {"auto" | null} width [optional] (attribute: "width") set it to "auto" for width auto-sizing
19
+ * @property {NapiModulesMap} napiModulesMap [optional] the napiModule which is called in lynx-core. key is module-name, value is esm url.
20
+ * @property {INapiModulesCall} onNapiModulesCall [optional] the NapiModule value handler.
21
+ * @property {"false" | "true" | null} injectHeadLinks [optional] @default true set it to "false" to disable injecting the <link href="" ref="stylesheet"> styles into shadowroot
22
22
  *
23
23
  * @event error lynx card fired an error
24
24
  *
@@ -28,7 +28,7 @@ import { inShadowRootStyles } from './inShadowRootStyles.js';
28
28
  * Note that you should declarae the size of lynx-view
29
29
  *
30
30
  * ```html
31
- * <lynx-view url="https://path/to/main-thread.js" rawData="{}" globalProps="{}" style="height:300px;width:300px">
31
+ * <lynx-view url="https://path/to/main-thread.js" raw-data="{}" global-props="{}" style="height:300px;width:300px">
32
32
  * </lynx-view>
33
33
  * ```
34
34
  *
@@ -43,12 +43,9 @@ export class LynxView extends HTMLElement {
43
43
  static tag = 'lynx-view';
44
44
  static observedAttributeAsProperties = [
45
45
  'url',
46
- 'globalProps',
47
- 'initData',
48
- 'overrideLynxTagToHTMLTagMap',
49
- 'nativeModulesMap',
46
+ 'global-props',
47
+ 'init-data',
50
48
  ];
51
- static attributeCamelCaseMap = Object.fromEntries(this.observedAttributeAsProperties.map((nm) => [nm.toLocaleLowerCase(), nm]));
52
49
  /**
53
50
  * @private
54
51
  */
@@ -167,8 +164,8 @@ export class LynxView extends HTMLElement {
167
164
  return this.#onNapiModulesCall;
168
165
  }
169
166
  set onNapiModulesCall(handler) {
170
- this.#onNapiModulesCall = (name, data, moduleName) => {
171
- return handler(name, data, moduleName, this);
167
+ this.#onNapiModulesCall = (name, data, moduleName, dispatchNapiModules) => {
168
+ return handler(name, data, moduleName, this, dispatchNapiModules);
172
169
  };
173
170
  }
174
171
  /**
@@ -214,10 +211,16 @@ export class LynxView extends HTMLElement {
214
211
  */
215
212
  attributeChangedCallback(name, oldValue, newValue) {
216
213
  if (oldValue !== newValue) {
217
- name = LynxView.attributeCamelCaseMap[name] ?? name;
218
- if (name in this) {
219
- // @ts-expect-error
220
- this[name] = newValue;
214
+ switch (name) {
215
+ case 'url':
216
+ this.#url = newValue;
217
+ break;
218
+ case 'global-props':
219
+ this.#globalProps = JSON.parse(newValue);
220
+ break;
221
+ case 'init-data':
222
+ this.#initData = JSON.parse(newValue);
223
+ break;
221
224
  }
222
225
  }
223
226
  }
@@ -1,5 +1,8 @@
1
- import { napiModulesCallEndpoint, } from '@lynx-js/web-constants';
1
+ import { dispatchNapiModuleEndpoint, napiModulesCallEndpoint, } from '@lynx-js/web-constants';
2
2
  export function registerNapiModulesCallHandler(rpc, napiModulesCall) {
3
- rpc.registerHandler(napiModulesCallEndpoint, napiModulesCall);
3
+ const dispatchNapiModules = rpc.createCall(dispatchNapiModuleEndpoint);
4
+ rpc.registerHandler(napiModulesCallEndpoint, (name, data, moduleName) => {
5
+ return napiModulesCall(name, data, moduleName, dispatchNapiModules);
6
+ });
4
7
  }
5
8
  //# sourceMappingURL=registerNapiModulesCallHandler.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -25,13 +25,13 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "@lynx-js/offscreen-document": "0.0.0",
28
- "@lynx-js/web-constants": "0.10.0",
29
- "@lynx-js/web-worker-rpc": "0.10.0",
30
- "@lynx-js/web-worker-runtime": "0.10.0"
28
+ "@lynx-js/web-constants": "0.10.1",
29
+ "@lynx-js/web-worker-rpc": "0.10.1",
30
+ "@lynx-js/web-worker-runtime": "0.10.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@lynx-js/lynx-core": "0.1.0",
34
- "@lynx-js/web-elements": "0.5.2"
34
+ "@lynx-js/web-elements": "0.5.3"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@lynx-js/lynx-core": "0.1.0",