@lynx-js/web-core 0.7.0 → 0.7.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,40 @@
1
1
  # @lynx-js/web-core
2
2
 
3
+ ## 0.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Support NPM provenance. ([#30](https://github.com/lynx-family/lynx-stack/pull/30))
8
+
9
+ - fix: some valus should be updateable by global scope ([#130](https://github.com/lynx-family/lynx-stack/pull/130))
10
+
11
+ Now we add an allowlist to allow some identifiers could be updated by globalThis.
12
+
13
+ For those values in the allowlist:
14
+
15
+ ```
16
+ globalThis.foo = 'xx';
17
+ console.log(foo); //'xx'
18
+ ```
19
+
20
+ - refactor: isolate the globalThis in mts ([#90](https://github.com/lynx-family/lynx-stack/pull/90))
21
+
22
+ After this commit, developers' mts code won't be able to access the globalThis
23
+
24
+ The following usage will NOT work
25
+
26
+ ```
27
+ globalThis.foo = () =>{};
28
+ foo();//crash
29
+ ```
30
+
31
+ - refractor: improve some internal logic for element creating in MTS ([#71](https://github.com/lynx-family/lynx-stack/pull/71))
32
+
33
+ - Updated dependencies [[`c617453`](https://github.com/lynx-family/lynx-stack/commit/c617453aea967aba702967deb2916b5c883f03bb), [`2044571`](https://github.com/lynx-family/lynx-stack/commit/204457166531dae6e9f653db56b14187553b7666), [`7da7601`](https://github.com/lynx-family/lynx-stack/commit/7da7601f00407970c485046ad73eeb8534aaa4f6)]:
34
+ - @lynx-js/web-worker-runtime@0.7.1
35
+ - @lynx-js/web-worker-rpc@0.7.1
36
+ - @lynx-js/web-constants@0.7.1
37
+
3
38
  ## 0.7.0
4
39
 
5
40
  ### Minor Changes
@@ -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 { cssIdAttribute, lynxTagAttribute, lynxUniqueIdAttribute, OperationType, lynxRuntimeValue, LynxEventNameToW3cByTagName, LynxEventNameToW3cCommon, W3cEventNameToLynx, parentComponentUniqueIdAttribute, __lynx_timing_flag, } from '@lynx-js/web-constants';
4
+ import { cssIdAttribute, lynxTagAttribute, lynxUniqueIdAttribute, OperationType, lynxRuntimeValue, LynxEventNameToW3cByTagName, LynxEventNameToW3cCommon, W3cEventNameToLynx, __lynx_timing_flag, } from '@lynx-js/web-constants';
5
5
  function getElement(uniqueId, uniqueIdToElement) {
6
6
  const element = uniqueIdToElement[uniqueId]?.deref();
7
7
  if (element) {
@@ -47,9 +47,6 @@ export function decodeElementOperation(operations, options) {
47
47
  if (typeof op.cssId === 'number') {
48
48
  element.setAttribute(cssIdAttribute, op.cssId.toString());
49
49
  }
50
- if (op.puid) {
51
- element.setAttribute(parentComponentUniqueIdAttribute, op.puid);
52
- }
53
50
  if (op.tag === 'page')
54
51
  pageElement = element;
55
52
  }
@@ -1,2 +1,2 @@
1
- import type { LynxTemplate } from '@lynx-js/web-constants';
1
+ import { type LynxTemplate } from '@lynx-js/web-constants';
2
2
  export declare function loadTemplate(url: string): Promise<LynxTemplate>;
@@ -1,25 +1,85 @@
1
+ import { globalMuteableVars } from '@lynx-js/web-constants';
1
2
  const TemplateCache = {};
2
3
  function createJsModuleUrl(content) {
3
4
  return URL.createObjectURL(new Blob([content], { type: 'text/javascript' }));
4
5
  }
5
- function generateJavascriptUrl(obj, injectVars, injectWithBind) {
6
+ function generateJavascriptUrl(obj, injectVars, injectWithBind, muteableVars) {
7
+ injectVars = injectVars.concat(muteableVars);
6
8
  return Object.fromEntries(Object.entries(obj).map(([name, content]) => {
7
9
  return [
8
10
  name,
9
- createJsModuleUrl(`globalThis.module.exports = function(lynx_runtime) {
10
- const module= {exports:{}};let exports = module.exports;
11
- var {${injectVars.join(',')}} = lynx_runtime;
12
- ${injectWithBind.map((nm) => `const ${nm} = lynx_runtime.${nm}?.bind(lynx_runtime)`).join(';')}
13
- var globDynamicComponentEntry = '__Card__';
14
- var {__globalProps} = lynx;
15
- ${content}
16
- return module.exports;}`),
11
+ createJsModuleUrl([
12
+ 'globalThis.module.exports = function(lynx_runtime) {',
13
+ 'const module= {exports:{}};let exports = module.exports;',
14
+ 'var {',
15
+ injectVars.join(','),
16
+ '} = lynx_runtime;',
17
+ ...injectWithBind.map((nm) => `const ${nm} = lynx_runtime.${nm}?.bind(lynx_runtime);`),
18
+ ';var globDynamicComponentEntry = \'__Card__\';',
19
+ 'var {__globalProps} = lynx;',
20
+ 'lynx_runtime._updateVars=()=>{',
21
+ ...muteableVars.map((nm) => `${nm} = lynx_runtime.__lynxGlobalBindingValues.${nm};`),
22
+ '};\n',
23
+ content,
24
+ '\n return module.exports;}',
25
+ ].join('')),
17
26
  ];
18
27
  }));
19
28
  }
20
29
  const mainThreadInjectVars = [
21
30
  'lynx',
22
31
  'globalThis',
32
+ '__AddConfig',
33
+ '__AddDataset',
34
+ '__GetAttributes',
35
+ '__GetComponentID',
36
+ '__GetDataByKey',
37
+ '__GetDataset',
38
+ '__GetElementConfig',
39
+ '__GetElementUniqueID',
40
+ '__GetID',
41
+ '__GetTag',
42
+ '__SetAttribute',
43
+ '__SetConfig',
44
+ '__SetDataset',
45
+ '__SetID',
46
+ '__UpdateComponentID',
47
+ '__GetConfig',
48
+ '__UpdateListCallbacks',
49
+ '__AppendElement',
50
+ '__ElementIsEqual',
51
+ '__FirstElement',
52
+ '__GetChildren',
53
+ '__GetParent',
54
+ '__InsertElementBefore',
55
+ '__LastElement',
56
+ '__NextElement',
57
+ '__RemoveElement',
58
+ '__ReplaceElement',
59
+ '__ReplaceElements',
60
+ '__SwapElement',
61
+ '__CreateComponent',
62
+ '__CreateElement',
63
+ '__CreatePage',
64
+ '__CreateView',
65
+ '__CreateText',
66
+ '__CreateRawText',
67
+ '__CreateImage',
68
+ '__CreateScrollView',
69
+ '__CreateWrapperElement',
70
+ '__CreateList',
71
+ '__AddEvent',
72
+ '__GetEvent',
73
+ '__GetEvents',
74
+ '__SetEvents',
75
+ '__AddClass',
76
+ '__SetClasses',
77
+ '__GetClasses',
78
+ '__AddInlineStyle',
79
+ '__SetInlineStyles',
80
+ '__SetCSSId',
81
+ '__OnLifecycleEvent',
82
+ '__FlushElementTree',
23
83
  ];
24
84
  const backgroundInjectVars = [
25
85
  'NativeModules',
@@ -40,8 +100,8 @@ export async function loadTemplate(url) {
40
100
  })).json());
41
101
  const decodedTemplate = {
42
102
  ...template,
43
- lepusCode: generateJavascriptUrl(template.lepusCode, mainThreadInjectVars, []),
44
- manifest: generateJavascriptUrl(template.manifest, backgroundInjectVars, backgroundInjectWithBind),
103
+ lepusCode: generateJavascriptUrl(template.lepusCode, mainThreadInjectVars, [], globalMuteableVars),
104
+ manifest: generateJavascriptUrl(template.manifest, backgroundInjectVars, backgroundInjectWithBind, []),
45
105
  };
46
106
  TemplateCache[url] = decodedTemplate;
47
107
  /**
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/lynx-family/lynx-stack.git",
10
+ "directory": "packages/web-platform/web-core"
11
+ },
7
12
  "license": "Apache-2.0",
8
13
  "type": "module",
9
14
  "main": "dist/index.js",
@@ -19,13 +24,13 @@
19
24
  "**/*.css"
20
25
  ],
21
26
  "dependencies": {
22
- "@lynx-js/web-constants": "0.7.0",
23
- "@lynx-js/web-worker-rpc": "0.7.0",
24
- "@lynx-js/web-worker-runtime": "0.7.0"
27
+ "@lynx-js/web-constants": "0.7.1",
28
+ "@lynx-js/web-worker-rpc": "0.7.1",
29
+ "@lynx-js/web-worker-runtime": "0.7.1"
25
30
  },
26
31
  "devDependencies": {
27
32
  "@lynx-js/lynx-core": "0.1.0",
28
- "@lynx-js/web-elements": "0.2.4"
33
+ "@lynx-js/web-elements": "0.3.0"
29
34
  },
30
35
  "peerDependencies": {
31
36
  "@lynx-js/lynx-core": "0.1.0",