@lynx-js/web-core-server 0.13.4 → 0.14.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 +63 -0
- package/dist/createLynxView.d.ts +2 -1
- package/dist/createLynxView.js +15 -7
- package/dist/dumpHTMLString.js +2 -1
- package/dist/utils/escapeHtml.d.ts +1 -0
- package/dist/utils/escapeHtml.js +67 -0
- package/dist/utils/loadTemplate.js +3 -0
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
# @lynx-js/web-core-server
|
|
2
2
|
|
|
3
|
+
## 0.14.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: add `_SetSourceMapRelease(errInfo)` MTS API. ([#1118](https://github.com/lynx-family/lynx-stack/pull/1118))
|
|
8
|
+
|
|
9
|
+
You can get `errInfo.release` through `e.detail.release` in the error event callback of lynx-view.
|
|
10
|
+
|
|
11
|
+
The `_SetSourceMapRelease` function is not complete yet, because it is currently limited by the Web platform and some functions and some props such as `err.stack` do not need to be supported for the time being.
|
|
12
|
+
|
|
13
|
+
- feat: add `_I18nResourceTranslation` api in mts && `init-i18n-resources` attr, `i18nResourceMissed` event of lynx-view. ([#1065](https://github.com/lynx-family/lynx-stack/pull/1065))
|
|
14
|
+
|
|
15
|
+
`init-i18n-resource` is the complete set of i18nResources that need to be maintained on the container side. Note: You need to pass this value when lynx-view is initialized.
|
|
16
|
+
|
|
17
|
+
You can use `_I18nResourceTranslation` in MTS to get the corresponding i18nResource from `init-i18n-resources`. If it is undefined, the `i18nResourceMissed` event will be dispatched.
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
// ui thread
|
|
21
|
+
lynxView.initI18nResources = [
|
|
22
|
+
{
|
|
23
|
+
options: {
|
|
24
|
+
locale: 'en',
|
|
25
|
+
channel: '1',
|
|
26
|
+
fallback_url: '',
|
|
27
|
+
},
|
|
28
|
+
resource: {
|
|
29
|
+
hello: 'hello',
|
|
30
|
+
lynx: 'lynx web platform1',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
lynxView.addEventListener('i18nResourceMissed', (e) => {
|
|
35
|
+
console.log(e);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// mts
|
|
39
|
+
_I18nResourceTranslation({
|
|
40
|
+
locale: 'en',
|
|
41
|
+
channel: '1',
|
|
42
|
+
fallback_url: '',
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 0.13.5
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- refactor: move some internal status to dom's attribute ([#945](https://github.com/lynx-family/lynx-stack/pull/945))
|
|
51
|
+
|
|
52
|
+
It's essential for SSR
|
|
53
|
+
|
|
54
|
+
- refactor: move component config info to attribute ([#984](https://github.com/lynx-family/lynx-stack/pull/984))
|
|
55
|
+
|
|
56
|
+
- refactor: save dataset on an attribute ([#981](https://github.com/lynx-family/lynx-stack/pull/981))
|
|
57
|
+
|
|
58
|
+
On lynx, the `data-*` attributes have different behaviors than the HTMLElement has.
|
|
59
|
+
|
|
60
|
+
The dataset will be treated as properties, the key will not be applied the camel-case <-> hyphenate name transformation.
|
|
61
|
+
|
|
62
|
+
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.
|
|
63
|
+
|
|
64
|
+
- fix: dump encode data in comment ([#989](https://github.com/lynx-family/lynx-stack/pull/989))
|
|
65
|
+
|
|
3
66
|
## 0.13.4
|
|
4
67
|
|
|
5
68
|
### Patch Changes
|
package/dist/createLynxView.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type StartMainThreadContextConfig } from '@lynx-js/web-constants';
|
|
2
|
-
interface LynxViewConfig extends Pick<StartMainThreadContextConfig, 'browserConfig' | 'tagMap' | 'initData' | 'globalProps' | 'template'> {
|
|
2
|
+
interface LynxViewConfig extends Pick<StartMainThreadContextConfig, 'browserConfig' | 'tagMap' | 'initData' | 'globalProps' | 'template' | 'initI18nResources'> {
|
|
3
3
|
templateName?: string;
|
|
4
4
|
hydrateUrl: string;
|
|
5
5
|
injectStyles: string;
|
|
6
6
|
overrideElementTemplates?: Record<string, ((attributes: Record<string, string>) => string) | string>;
|
|
7
7
|
autoSize?: boolean;
|
|
8
8
|
lynxViewStyle?: string;
|
|
9
|
+
threadStrategy?: 'all-on-ui';
|
|
9
10
|
}
|
|
10
11
|
export declare function createLynxView(config: LynxViewConfig): Promise<{
|
|
11
12
|
renderToString: () => Promise<string>;
|
package/dist/createLynxView.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inShadowRootStyles, lynxUniqueIdAttribute, } from '@lynx-js/web-constants';
|
|
1
|
+
import { I18nResources, inShadowRootStyles, lynxUniqueIdAttribute, } from '@lynx-js/web-constants';
|
|
2
2
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
3
3
|
import { prepareMainThreadAPIs } from '@lynx-js/web-mainthread-apis';
|
|
4
4
|
import { loadTemplate } from './utils/loadTemplate.js';
|
|
@@ -35,7 +35,7 @@ OffscreenElement.prototype.toJSON = function toJSON() {
|
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
37
|
export async function createLynxView(config) {
|
|
38
|
-
const { template: rawTemplate, browserConfig, tagMap, initData, globalProps, overrideElementTemplates = {}, hydrateUrl, autoSize, injectStyles, lynxViewStyle, } = config;
|
|
38
|
+
const { template: rawTemplate, browserConfig, tagMap, initData, globalProps, overrideElementTemplates = {}, hydrateUrl, autoSize, injectStyles, lynxViewStyle, threadStrategy = 'all-on-ui', initI18nResources, } = config;
|
|
39
39
|
const template = await loadTemplate(rawTemplate, config.templateName);
|
|
40
40
|
const { promise: firstPaintReadyPromise, resolve: firstPaintReady } = Promise
|
|
41
41
|
.withResolvers();
|
|
@@ -45,12 +45,18 @@ export async function createLynxView(config) {
|
|
|
45
45
|
onCommit: () => {
|
|
46
46
|
},
|
|
47
47
|
});
|
|
48
|
+
const i18nResources = new I18nResources();
|
|
48
49
|
const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, offscreenDocument, offscreenDocument.createElement.bind(offscreenDocument), () => {
|
|
49
50
|
firstPaintReady();
|
|
50
51
|
}, () => {
|
|
51
52
|
// mark timing
|
|
52
53
|
}, () => {
|
|
53
54
|
// report error
|
|
55
|
+
}, () => {
|
|
56
|
+
// trigger i18n resource fallback
|
|
57
|
+
}, (initI18nResources) => {
|
|
58
|
+
i18nResources.setData(initI18nResources);
|
|
59
|
+
return i18nResources;
|
|
54
60
|
});
|
|
55
61
|
const runtime = await startMainThread({
|
|
56
62
|
template,
|
|
@@ -63,6 +69,7 @@ export async function createLynxView(config) {
|
|
|
63
69
|
...builtinTagTransformMap,
|
|
64
70
|
...tagMap,
|
|
65
71
|
},
|
|
72
|
+
initI18nResources,
|
|
66
73
|
});
|
|
67
74
|
const elementTemplates = {
|
|
68
75
|
...builtinElementTemplates,
|
|
@@ -72,20 +79,21 @@ export async function createLynxView(config) {
|
|
|
72
79
|
await firstPaintReadyPromise;
|
|
73
80
|
const ssrEncodeData = runtime?.ssrEncode?.();
|
|
74
81
|
const buffer = [];
|
|
75
|
-
buffer.push('<lynx-view url="', hydrateUrl, '" ssr');
|
|
82
|
+
buffer.push('<lynx-view url="', hydrateUrl, '" ssr ', 'thread-strategy="', threadStrategy, '"');
|
|
76
83
|
if (autoSize) {
|
|
77
84
|
buffer.push(' height="auto" width="auto"');
|
|
78
85
|
}
|
|
79
86
|
if (lynxViewStyle) {
|
|
80
87
|
buffer.push(' style="', lynxViewStyle, '"');
|
|
81
88
|
}
|
|
89
|
+
buffer.push('><template shadowrootmode="open">', '<style>', injectStyles, '\n', inShadowRootStyles.join('\n'), '</style>');
|
|
90
|
+
dumpHTMLString(buffer, offscreenDocument, elementTemplates);
|
|
91
|
+
buffer.push('</template>');
|
|
82
92
|
if (ssrEncodeData) {
|
|
83
93
|
const encodeDataEncoded = ssrEncodeData ? encodeURI(ssrEncodeData) : ''; // to avoid XSS
|
|
84
|
-
buffer.push('
|
|
94
|
+
buffer.push('<!--', encodeDataEncoded, '-->');
|
|
85
95
|
}
|
|
86
|
-
buffer.push('
|
|
87
|
-
dumpHTMLString(buffer, offscreenDocument, elementTemplates);
|
|
88
|
-
buffer.push('</template>', '</lynx-view>');
|
|
96
|
+
buffer.push('</lynx-view>');
|
|
89
97
|
return buffer.join('');
|
|
90
98
|
}
|
|
91
99
|
return {
|
package/dist/dumpHTMLString.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _attributes, _children, innerHTML, } from '@lynx-js/offscreen-document/webworker';
|
|
2
|
+
import { escapeHtml } from './utils/escapeHtml.js';
|
|
2
3
|
function getInnerHTMLImpl(buffer, element, shadowrootTemplates) {
|
|
3
4
|
const localName = element.localName;
|
|
4
5
|
buffer.push('<');
|
|
@@ -7,7 +8,7 @@ function getInnerHTMLImpl(buffer, element, shadowrootTemplates) {
|
|
|
7
8
|
buffer.push(' ');
|
|
8
9
|
buffer.push(key);
|
|
9
10
|
buffer.push('="');
|
|
10
|
-
buffer.push(value);
|
|
11
|
+
buffer.push(escapeHtml(value));
|
|
11
12
|
buffer.push('"');
|
|
12
13
|
}
|
|
13
14
|
buffer.push('>');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function escapeHtml(string: string): string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
*
|
|
25
|
+
*
|
|
26
|
+
* forked from facebook/react
|
|
27
|
+
*/
|
|
28
|
+
const matchHtmlRegExp = /["'&<>]/;
|
|
29
|
+
export function escapeHtml(string) {
|
|
30
|
+
const str = '' + string;
|
|
31
|
+
const match = matchHtmlRegExp.exec(str);
|
|
32
|
+
if (!match) {
|
|
33
|
+
return str;
|
|
34
|
+
}
|
|
35
|
+
let escape;
|
|
36
|
+
let html = '';
|
|
37
|
+
let index;
|
|
38
|
+
let lastIndex = 0;
|
|
39
|
+
for (index = match.index; index < str.length; index++) {
|
|
40
|
+
switch (str.charCodeAt(index)) {
|
|
41
|
+
case 34: // "
|
|
42
|
+
escape = '"';
|
|
43
|
+
break;
|
|
44
|
+
case 38: // &
|
|
45
|
+
escape = '&';
|
|
46
|
+
break;
|
|
47
|
+
case 39: // '
|
|
48
|
+
escape = '''; // modified from escape-html; used to be '''
|
|
49
|
+
break;
|
|
50
|
+
case 60: // <
|
|
51
|
+
escape = '<';
|
|
52
|
+
break;
|
|
53
|
+
case 62: // >
|
|
54
|
+
escape = '>';
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (lastIndex !== index) {
|
|
60
|
+
html += str.substring(lastIndex, index);
|
|
61
|
+
}
|
|
62
|
+
lastIndex = index + 1;
|
|
63
|
+
html += escape;
|
|
64
|
+
}
|
|
65
|
+
return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=escapeHtml.js.map
|
|
@@ -40,6 +40,7 @@ const mainThreadInjectVars = [
|
|
|
40
40
|
'lynx',
|
|
41
41
|
'globalThis',
|
|
42
42
|
'_ReportError',
|
|
43
|
+
'_SetSourceMapRelease',
|
|
43
44
|
'__AddConfig',
|
|
44
45
|
'__AddDataset',
|
|
45
46
|
'__GetAttributes',
|
|
@@ -93,6 +94,8 @@ const mainThreadInjectVars = [
|
|
|
93
94
|
'__FlushElementTree',
|
|
94
95
|
'__LoadLepusChunk',
|
|
95
96
|
'SystemInfo',
|
|
97
|
+
'_I18nResourceTranslation',
|
|
98
|
+
'_AddEventListener',
|
|
96
99
|
];
|
|
97
100
|
const backgroundInjectVars = [
|
|
98
101
|
'NativeModules',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-core-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@lynx-js/offscreen-document": "0.1.
|
|
26
|
-
"@lynx-js/web-constants": "0.
|
|
27
|
-
"@lynx-js/web-elements-template": "0.7.
|
|
28
|
-
"@lynx-js/web-mainthread-apis": "0.
|
|
29
|
-
"@lynx-js/web-worker-rpc": "0.
|
|
25
|
+
"@lynx-js/offscreen-document": "0.1.2",
|
|
26
|
+
"@lynx-js/web-constants": "0.14.0",
|
|
27
|
+
"@lynx-js/web-elements-template": "0.7.6",
|
|
28
|
+
"@lynx-js/web-mainthread-apis": "0.14.0",
|
|
29
|
+
"@lynx-js/web-worker-rpc": "0.14.0"
|
|
30
30
|
}
|
|
31
31
|
}
|