@lynx-js/web-core 0.13.3 → 0.13.5

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,53 @@
1
1
  # @lynx-js/web-core
2
2
 
3
+ ## 0.13.5
4
+
5
+ ### Patch Changes
6
+
7
+ - refactor: move some internal status to dom's attribute ([#945](https://github.com/lynx-family/lynx-stack/pull/945))
8
+
9
+ It's essential for SSR
10
+
11
+ - refactor: avoid to create many style element for cssog ([#1026](https://github.com/lynx-family/lynx-stack/pull/1026))
12
+
13
+ - refactor: move component config info to attribute ([#984](https://github.com/lynx-family/lynx-stack/pull/984))
14
+
15
+ - fix: ensure render starts after dom connected ([#1020](https://github.com/lynx-family/lynx-stack/pull/1020))
16
+
17
+ - refactor: save dataset on an attribute ([#981](https://github.com/lynx-family/lynx-stack/pull/981))
18
+
19
+ On lynx, the `data-*` attributes have different behaviors than the HTMLElement has.
20
+
21
+ The dataset will be treated as properties, the key will not be applied the camel-case <-> hyphenate name transformation.
22
+
23
+ Before this commit we use it as a runtime data, but after this commit we will use encodeURI(JSON.stringify(dataset)) to encode it as a string.
24
+
25
+ - refactor: implement mts apis in closure pattern ([#1004](https://github.com/lynx-family/lynx-stack/pull/1004))
26
+
27
+ - Updated dependencies [[`70b82d2`](https://github.com/lynx-family/lynx-stack/commit/70b82d23744d6b6ec945dff9f8895ab3488ba4c8), [`5651e24`](https://github.com/lynx-family/lynx-stack/commit/5651e24827358963c3261252bcc53c2ad981c13e), [`9499ea9`](https://github.com/lynx-family/lynx-stack/commit/9499ea91debdf73b2d31af0b31bcbc216135543b), [`50f0193`](https://github.com/lynx-family/lynx-stack/commit/50f01933942268b697bf5abe790da86c932f1dfc), [`57bf0ef`](https://github.com/lynx-family/lynx-stack/commit/57bf0ef19f1d79bc52ab6a4f0cd2939e7901d98b), [`5651e24`](https://github.com/lynx-family/lynx-stack/commit/5651e24827358963c3261252bcc53c2ad981c13e), [`0525fbf`](https://github.com/lynx-family/lynx-stack/commit/0525fbf38baa7a977a7a8c66e8a4d8bf34cc3b68), [`b6b87fd`](https://github.com/lynx-family/lynx-stack/commit/b6b87fd11dbc76c28f3b5022aa8c6afeb773d90f), [`c014327`](https://github.com/lynx-family/lynx-stack/commit/c014327ad0cf599b32d4182d95116b46c35f5fa5)]:
28
+ - @lynx-js/web-mainthread-apis@0.13.5
29
+ - @lynx-js/web-constants@0.13.5
30
+ - @lynx-js/offscreen-document@0.1.1
31
+ - @lynx-js/web-worker-runtime@0.13.5
32
+ - @lynx-js/web-worker-rpc@0.13.5
33
+
34
+ ## 0.13.4
35
+
36
+ ### Patch Changes
37
+
38
+ - feat: lynx-view supports `updateGlobalProps` method, which can be used to update lynx.\_\_globalProps ([#918](https://github.com/lynx-family/lynx-stack/pull/918))
39
+
40
+ - feat: supports `lynx.getElementById()` && `animate()`. ([#912](https://github.com/lynx-family/lynx-stack/pull/912))
41
+
42
+ After this commit, you can use `lynx.getElementById()` to get the element by id, and use `element.animate()` to animate the element.
43
+
44
+ - Updated dependencies [[`96d3133`](https://github.com/lynx-family/lynx-stack/commit/96d3133b149b61af01c5478f4dc7b0a071137d98), [`75e5b2f`](https://github.com/lynx-family/lynx-stack/commit/75e5b2ff16ecf5f7072a45cd130e653dee747461), [`569618d`](https://github.com/lynx-family/lynx-stack/commit/569618d8e2665f5c9e1672f7ee5900ec2a5179a2), [`f9f88d6`](https://github.com/lynx-family/lynx-stack/commit/f9f88d6fb9c42d3370a6622d9d799d671ffcf1a7)]:
45
+ - @lynx-js/web-mainthread-apis@0.13.4
46
+ - @lynx-js/offscreen-document@0.1.0
47
+ - @lynx-js/web-worker-runtime@0.13.4
48
+ - @lynx-js/web-constants@0.13.4
49
+ - @lynx-js/web-worker-rpc@0.13.4
50
+
3
51
  ## 0.13.3
4
52
 
5
53
  ### Patch Changes
@@ -29,7 +29,7 @@ export type INapiModulesCall = (name: string, data: any, moduleName: string, lyn
29
29
  * @event error lynx card fired an error
30
30
  *
31
31
  * @example
32
- * HTML Exmaple
32
+ * HTML Example
33
33
  *
34
34
  * Note that you should declarae the size of lynx-view
35
35
  *
@@ -41,7 +41,7 @@ export type INapiModulesCall = (name: string, data: any, moduleName: string, lyn
41
41
  * React 19 Example
42
42
  * ```jsx
43
43
  * <lynx-view url={myLynxCardUrl} rawData={{}} globalProps={{}} style={{height:'300px', width:'300px'}}>
44
- * </lynx-vew>
44
+ * </lynx-view>
45
45
  * ```
46
46
  */
47
47
  export declare class LynxView extends HTMLElement {
@@ -118,6 +118,12 @@ export declare class LynxView extends HTMLElement {
118
118
  * update the `__initData` and trigger essential flow
119
119
  */
120
120
  updateData(data: Cloneable, updateDataType: UpdateDataType, callback?: () => void): void;
121
+ /**
122
+ * @public
123
+ * @method
124
+ * update the `__globalProps`
125
+ */
126
+ updateGlobalProps(data: Cloneable): void;
121
127
  /**
122
128
  * @public
123
129
  * @method
@@ -26,7 +26,7 @@ import { inShadowRootStyles, } from '@lynx-js/web-constants';
26
26
  * @event error lynx card fired an error
27
27
  *
28
28
  * @example
29
- * HTML Exmaple
29
+ * HTML Example
30
30
  *
31
31
  * Note that you should declarae the size of lynx-view
32
32
  *
@@ -38,7 +38,7 @@ import { inShadowRootStyles, } from '@lynx-js/web-constants';
38
38
  * React 19 Example
39
39
  * ```jsx
40
40
  * <lynx-view url={myLynxCardUrl} rawData={{}} globalProps={{}} style={{height:'300px', width:'300px'}}>
41
- * </lynx-vew>
41
+ * </lynx-view>
42
42
  * ```
43
43
  */
44
44
  export class LynxView extends HTMLElement {
@@ -54,6 +54,7 @@ export class LynxView extends HTMLElement {
54
54
  */
55
55
  static observedAttributes = LynxView.observedAttributeAsProperties.map(nm => nm.toLowerCase());
56
56
  #instance;
57
+ #connected = false;
57
58
  #url;
58
59
  /**
59
60
  * @public
@@ -196,6 +197,14 @@ export class LynxView extends HTMLElement {
196
197
  updateData(data, updateDataType, callback) {
197
198
  this.#instance?.updateData(data, updateDataType, callback);
198
199
  }
200
+ /**
201
+ * @public
202
+ * @method
203
+ * update the `__globalProps`
204
+ */
205
+ updateGlobalProps(data) {
206
+ this.#instance?.updateGlobalProps(data);
207
+ }
199
208
  /**
200
209
  * @public
201
210
  * @method
@@ -296,7 +305,7 @@ export class LynxView extends HTMLElement {
296
305
  * @private
297
306
  */
298
307
  #render() {
299
- if (!this.#rendering) {
308
+ if (!this.#rendering && this.#connected) {
300
309
  this.#rendering = true;
301
310
  queueMicrotask(() => {
302
311
  this.#rendering = false;
@@ -374,6 +383,7 @@ export class LynxView extends HTMLElement {
374
383
  * @private
375
384
  */
376
385
  connectedCallback() {
386
+ this.#connected = true;
377
387
  this.#render();
378
388
  }
379
389
  }
@@ -17,5 +17,6 @@ export interface LynxView {
17
17
  updateData(data: Cloneable, updateDataType: UpdateDataType, callback?: () => void): void;
18
18
  dispose(): Promise<void>;
19
19
  sendGlobalEvent: RpcCallType<typeof sendGlobalEventEndpoint>;
20
+ updateGlobalProps: (data: Cloneable) => void;
20
21
  }
21
22
  export declare function createLynxView(configs: LynxViewConfigs): LynxView;
@@ -7,13 +7,13 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingI
7
7
  const { startMainThread } = prepareMainThreadAPIs(mainToBackgroundRpc, shadowRoot, document.createElement.bind(document), () => { }, markTimingInternal, () => {
8
8
  callbacks.onError?.();
9
9
  });
10
- let runtime;
10
+ let mtsGlobalThis;
11
11
  const start = async (configs) => {
12
12
  const mainThreadRuntime = startMainThread(configs);
13
- runtime = await mainThreadRuntime;
13
+ mtsGlobalThis = await mainThreadRuntime;
14
14
  };
15
15
  const updateDataMainThread = async (...args) => {
16
- runtime.updatePage?.(...args);
16
+ mtsGlobalThis.updatePage?.(...args);
17
17
  };
18
18
  return {
19
19
  start,
@@ -40,7 +40,7 @@ export function registerInvokeUIMethodHandler(rpc, shadowRoot) {
40
40
  }
41
41
  }
42
42
  catch (e) {
43
- console.error(`[lynx-web] invokeUIMethod: apply method faild with`, e, element);
43
+ console.error(`[lynx-web] invokeUIMethod: apply method failed with`, e, element);
44
44
  code = ErrorCode.PARAM_INVALID;
45
45
  }
46
46
  }, (error) => {
@@ -0,0 +1,2 @@
1
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
2
+ export declare function registerTriggerElementMethodEndpointHandler(rpc: Rpc, shadowRoot: ShadowRoot): void;
@@ -0,0 +1,32 @@
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 {
5
+ // componentIdAttribute,
6
+ triggerElementMethodEndpoint, } from '@lynx-js/web-constants';
7
+ import { AnimationOperation, } from '@lynx-js/web-constants';
8
+ export function registerTriggerElementMethodEndpointHandler(rpc, shadowRoot) {
9
+ const animationMap = new Map();
10
+ rpc.registerHandler(triggerElementMethodEndpoint, (method, id, options) => {
11
+ if (method === 'animate') {
12
+ switch (options.operation) {
13
+ case AnimationOperation.START:
14
+ animationMap.set(options.id, shadowRoot.querySelector(id)?.animate(options.keyframes, options.timingOptions));
15
+ break;
16
+ case AnimationOperation.PLAY:
17
+ animationMap.get(options.id)?.play();
18
+ break;
19
+ case AnimationOperation.PAUSE:
20
+ animationMap.get(options.id)?.pause();
21
+ break;
22
+ case AnimationOperation.CANCEL:
23
+ animationMap.get(options.id)?.cancel();
24
+ break;
25
+ case AnimationOperation.FINISH:
26
+ animationMap.get(options.id)?.finish();
27
+ break;
28
+ }
29
+ }
30
+ });
31
+ }
32
+ //# sourceMappingURL=registerTriggerElementMethodEndpointHandler.js.map
@@ -6,6 +6,7 @@ import { registerTriggerComponentEventHandler } from './crossThreadHandlers/regi
6
6
  import { registerSelectComponentHandler } from './crossThreadHandlers/registerSelectComponentHandler.js';
7
7
  import { registerNapiModulesCallHandler } from './crossThreadHandlers/registerNapiModulesCallHandler.js';
8
8
  import { registerDispatchLynxViewEventHandler } from './crossThreadHandlers/registerDispatchLynxViewEventHandler.js';
9
+ import { registerTriggerElementMethodEndpointHandler } from './crossThreadHandlers/registerTriggerElementMethodEndpointHandler.js';
9
10
  export function startBackground(backgroundRpc, shadowRoot, callbacks) {
10
11
  registerInvokeUIMethodHandler(backgroundRpc, shadowRoot);
11
12
  registerNativePropsHandler(backgroundRpc, shadowRoot);
@@ -14,6 +15,7 @@ export function startBackground(backgroundRpc, shadowRoot, callbacks) {
14
15
  registerNativeModulesCallHandler(backgroundRpc, callbacks.nativeModulesCall);
15
16
  registerNapiModulesCallHandler(backgroundRpc, callbacks.napiModulesCall);
16
17
  registerDispatchLynxViewEventHandler(backgroundRpc, shadowRoot);
18
+ registerTriggerElementMethodEndpointHandler(backgroundRpc, shadowRoot);
17
19
  const sendGlobalEvent = backgroundRpc.createCall(sendGlobalEventEndpoint);
18
20
  const markTiming = backgroundRpc.createCall(markTimingEndpoint);
19
21
  const updateDataBackground = backgroundRpc.createCall(updateDataEndpoint);
@@ -3,7 +3,7 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { bootWorkers } from './bootWorkers.js';
5
5
  import { createDispose } from './crossThreadHandlers/createDispose.js';
6
- import {} from '@lynx-js/web-constants';
6
+ import { updateGlobalPropsEndpoint, } from '@lynx-js/web-constants';
7
7
  import { loadTemplate } from '../utils/loadTemplate.js';
8
8
  import { createUpdateData } from './crossThreadHandlers/createUpdateData.js';
9
9
  import { startBackground } from './startBackground.js';
@@ -37,6 +37,7 @@ export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, thr
37
37
  updateData: createUpdateData(updateDataMainThread, updateDataBackground),
38
38
  dispose: createDispose(backgroundRpc, terminateWorkers),
39
39
  sendGlobalEvent,
40
+ updateGlobalProps: backgroundRpc.createCall(updateGlobalPropsEndpoint),
40
41
  };
41
42
  }
42
43
  //# sourceMappingURL=startUIThread.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core",
3
- "version": "0.13.3",
3
+ "version": "0.13.5",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -24,15 +24,15 @@
24
24
  "**/*.css"
25
25
  ],
26
26
  "dependencies": {
27
- "@lynx-js/offscreen-document": "0.0.4",
28
- "@lynx-js/web-constants": "0.13.3",
29
- "@lynx-js/web-mainthread-apis": "0.13.3",
30
- "@lynx-js/web-worker-rpc": "0.13.3",
31
- "@lynx-js/web-worker-runtime": "0.13.3"
27
+ "@lynx-js/offscreen-document": "0.1.1",
28
+ "@lynx-js/web-constants": "0.13.5",
29
+ "@lynx-js/web-mainthread-apis": "0.13.5",
30
+ "@lynx-js/web-worker-rpc": "0.13.5",
31
+ "@lynx-js/web-worker-runtime": "0.13.5"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@lynx-js/lynx-core": "0.1.2",
35
- "@lynx-js/web-elements": "0.7.3"
35
+ "@lynx-js/web-elements": "0.7.5"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@lynx-js/lynx-core": "0.1.2",