@worktile/planet 17.0.0-next.2 → 17.0.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 +18 -0
- package/application/planet-application-loader.d.ts +5 -0
- package/application/planet-application-loader.d.ts.map +1 -1
- package/assets-loader.d.ts +13 -6
- package/assets-loader.d.ts.map +1 -1
- package/esm2022/application/planet-application-loader.mjs +10 -5
- package/esm2022/assets-loader.mjs +71 -17
- package/esm2022/helpers.mjs +44 -44
- package/esm2022/inner-types.mjs +2 -0
- package/esm2022/planet.mjs +7 -1
- package/fesm2022/worktile-planet.mjs +127 -62
- package/fesm2022/worktile-planet.mjs.map +1 -1
- package/helpers.d.ts +7 -13
- package/helpers.d.ts.map +1 -1
- package/inner-types.d.ts +12 -0
- package/inner-types.d.ts.map +1 -0
- package/package.json +1 -1
- package/planet.d.ts +4 -0
- package/planet.d.ts.map +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, Injectable, NgZone, NgModuleRef, Inject, Optional, Component, ChangeDetectionStrategy, Injector, createComponent, reflectComponentType, EventEmitter, Directive, Input, Output, inject, NgModule } from '@angular/core';
|
|
2
|
+
import { InjectionToken, Injectable, NgZone, NgModuleRef, signal, Inject, Optional, Component, ChangeDetectionStrategy, Injector, createComponent, reflectComponentType, EventEmitter, Directive, Input, Output, inject, NgModule } from '@angular/core';
|
|
3
3
|
import * as i3 from '@angular/router';
|
|
4
4
|
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router';
|
|
5
5
|
import * as i1 from '@angular/common/http';
|
|
@@ -106,7 +106,7 @@ function getExtName(name) {
|
|
|
106
106
|
function buildResourceFilePath(resourceFilePath, manifestResult) {
|
|
107
107
|
const fileName = getResourceFileName(resourceFilePath);
|
|
108
108
|
if (manifestResult[fileName]) {
|
|
109
|
-
return resourceFilePath.replace(fileName, manifestResult[fileName]);
|
|
109
|
+
return resourceFilePath.replace(fileName, manifestResult[fileName].src);
|
|
110
110
|
}
|
|
111
111
|
else {
|
|
112
112
|
return resourceFilePath;
|
|
@@ -148,56 +148,56 @@ function getAssetsBasePath(app) {
|
|
|
148
148
|
}
|
|
149
149
|
return basePath || app.resourcePathPrefix;
|
|
150
150
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
function getAssetsByDefined(definedPaths, manifest, ext) {
|
|
152
|
+
if (definedPaths) {
|
|
153
|
+
return definedPaths.map(definedPath => {
|
|
154
|
+
const fileName = getResourceFileName(definedPath);
|
|
155
|
+
const assetsTagItem = manifest[fileName];
|
|
156
|
+
return {
|
|
157
|
+
...assetsTagItem,
|
|
158
|
+
src: definedPath.replace(fileName, assetsTagItem.src)
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
return Object.keys(manifest)
|
|
164
|
+
.filter(key => {
|
|
165
|
+
return getExtName(key) === ext;
|
|
166
|
+
})
|
|
167
|
+
.map(key => {
|
|
168
|
+
return manifest[key];
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function toAssetsTagItem(src) {
|
|
173
|
+
return {
|
|
174
|
+
src: src
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function toAssetsTagItems(src) {
|
|
178
|
+
return src.map(item => toAssetsTagItem(item));
|
|
179
|
+
}
|
|
180
|
+
function getScriptsAndStylesAssets(app, basePath, manifestResult) {
|
|
181
|
+
const result = { scripts: [], styles: [] };
|
|
157
182
|
let { scripts, styles } = getDefinedAssets(app);
|
|
158
183
|
// combine resource path by manifest
|
|
159
184
|
if (manifestResult) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
scripts = Object.keys(manifestResult)
|
|
167
|
-
.filter(key => {
|
|
168
|
-
return getExtName(key) === 'js';
|
|
169
|
-
})
|
|
170
|
-
.map(key => {
|
|
171
|
-
return manifestResult[key];
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
if (styles) {
|
|
175
|
-
styles = styles.map(style => {
|
|
176
|
-
return buildResourceFilePath(style, manifestResult);
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
styles = Object.keys(manifestResult)
|
|
181
|
-
.filter(key => {
|
|
182
|
-
return getExtName(key) === 'css';
|
|
183
|
-
})
|
|
184
|
-
.map(key => {
|
|
185
|
-
return manifestResult[key];
|
|
186
|
-
});
|
|
187
|
-
}
|
|
185
|
+
result.scripts = getAssetsByDefined(scripts, manifestResult, 'js');
|
|
186
|
+
result.styles = getAssetsByDefined(styles, manifestResult, 'css');
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
result.scripts = toAssetsTagItems(scripts);
|
|
190
|
+
result.styles = toAssetsTagItems(styles);
|
|
188
191
|
}
|
|
189
192
|
if (basePath) {
|
|
190
|
-
scripts
|
|
191
|
-
|
|
193
|
+
result.scripts.forEach(item => {
|
|
194
|
+
item.src = buildFullPath(item.src, basePath);
|
|
192
195
|
});
|
|
193
|
-
styles
|
|
194
|
-
|
|
196
|
+
result.styles.forEach(item => {
|
|
197
|
+
item.src = buildFullPath(item.src, basePath);
|
|
195
198
|
});
|
|
196
199
|
}
|
|
197
|
-
return
|
|
198
|
-
scripts: scripts || [],
|
|
199
|
-
styles: styles || []
|
|
200
|
-
};
|
|
200
|
+
return result;
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
const PLANET_SANDBOX_WINDOW_WHITELIST = window['___PLANET_SANDBOX_WINDOW_WHITELIST___'];
|
|
@@ -852,12 +852,13 @@ function getSandboxInstance() {
|
|
|
852
852
|
|
|
853
853
|
const STYLE_LINK_OR_SCRIPT_REG = /<[script|link].*?>/gi;
|
|
854
854
|
const LINK_OR_SRC_REG = /(src|href)=["'](.*?[\.js|\.css])["']/i;
|
|
855
|
+
const TAG_ATTRS_REG = /(type|defer|async)((=["'].*?["'])|\s|\>)/gi;
|
|
855
856
|
class AssetsLoader {
|
|
856
857
|
constructor(http) {
|
|
857
858
|
this.http = http;
|
|
858
859
|
this.loadedSources = [];
|
|
859
860
|
}
|
|
860
|
-
loadScript(src) {
|
|
861
|
+
loadScript(src, tagAttributes) {
|
|
861
862
|
const id = hashCode(src);
|
|
862
863
|
if (this.loadedSources.includes(id)) {
|
|
863
864
|
return of({
|
|
@@ -869,9 +870,14 @@ class AssetsLoader {
|
|
|
869
870
|
}
|
|
870
871
|
return new Observable((observer) => {
|
|
871
872
|
const script = document.createElement('script');
|
|
872
|
-
script.type = 'text/javascript';
|
|
873
|
+
script.type = tagAttributes?.type || 'text/javascript';
|
|
873
874
|
script.src = src;
|
|
874
|
-
|
|
875
|
+
if (!tagAttributes?.defer || tagAttributes?.defer !== 'false') {
|
|
876
|
+
script.defer = true;
|
|
877
|
+
}
|
|
878
|
+
if (!tagAttributes?.async && tagAttributes?.async === 'false') {
|
|
879
|
+
script.async = true;
|
|
880
|
+
}
|
|
875
881
|
if (script['readyState']) {
|
|
876
882
|
// IE
|
|
877
883
|
script['onreadystatechange'] = () => {
|
|
@@ -995,13 +1001,13 @@ class AssetsLoader {
|
|
|
995
1001
|
if (isEmpty(sources)) {
|
|
996
1002
|
return of(null);
|
|
997
1003
|
}
|
|
998
|
-
const observables = sources.map(
|
|
1004
|
+
const observables = sources.map(source => {
|
|
999
1005
|
// TODO: 暂时只支持Proxy沙箱
|
|
1000
1006
|
if (options.sandbox && window.Proxy) {
|
|
1001
|
-
return this.loadScriptWithSandbox(options.app, src);
|
|
1007
|
+
return this.loadScriptWithSandbox(options.app, source.src);
|
|
1002
1008
|
}
|
|
1003
1009
|
else {
|
|
1004
|
-
return this.loadScript(src);
|
|
1010
|
+
return this.loadScript(source.src, source.attributes);
|
|
1005
1011
|
}
|
|
1006
1012
|
});
|
|
1007
1013
|
if (options.serial) {
|
|
@@ -1018,13 +1024,40 @@ class AssetsLoader {
|
|
|
1018
1024
|
if (isEmpty(sources)) {
|
|
1019
1025
|
return of(null);
|
|
1020
1026
|
}
|
|
1021
|
-
return forkJoin(sources.map(
|
|
1022
|
-
return this.loadStyle(src);
|
|
1027
|
+
return forkJoin(sources.map(source => {
|
|
1028
|
+
return this.loadStyle(source.src);
|
|
1023
1029
|
}));
|
|
1024
1030
|
}
|
|
1025
1031
|
loadScriptsAndStyles(scripts = [], styles = [], options) {
|
|
1026
1032
|
return forkJoin([this.loadScripts(scripts, options), this.loadStyles(styles)]);
|
|
1027
1033
|
}
|
|
1034
|
+
/**
|
|
1035
|
+
* <script type="module" src="http://127.0.0.1:3001/main.js" async defer></script>
|
|
1036
|
+
* => [`type="module"`, "async ", "defer>"] as attributeStrMatchArr
|
|
1037
|
+
* => { type: "module", async: "async", defer: "defer" } as attributes
|
|
1038
|
+
*/
|
|
1039
|
+
parseTagAttributes(tag) {
|
|
1040
|
+
const attributeStrMatchArr = tag.match(TAG_ATTRS_REG);
|
|
1041
|
+
if (attributeStrMatchArr) {
|
|
1042
|
+
const attributes = {};
|
|
1043
|
+
attributeStrMatchArr.forEach(item => {
|
|
1044
|
+
const equalSignIndex = item.indexOf('=');
|
|
1045
|
+
if (equalSignIndex > 0) {
|
|
1046
|
+
// 'type="module"' => { type: "module" }
|
|
1047
|
+
const key = item.slice(0, equalSignIndex);
|
|
1048
|
+
attributes[key] = item.slice(equalSignIndex + 2, item.length - 1);
|
|
1049
|
+
}
|
|
1050
|
+
else {
|
|
1051
|
+
// 'async ' => 'async'
|
|
1052
|
+
// 'defer>' => 'defer'
|
|
1053
|
+
const key = item.slice(0, item.length - 1);
|
|
1054
|
+
attributes[key] = key;
|
|
1055
|
+
}
|
|
1056
|
+
});
|
|
1057
|
+
return attributes;
|
|
1058
|
+
}
|
|
1059
|
+
return undefined;
|
|
1060
|
+
}
|
|
1028
1061
|
parseManifestFromHTML(html) {
|
|
1029
1062
|
const result = {};
|
|
1030
1063
|
const matchResult = html.match(STYLE_LINK_OR_SCRIPT_REG);
|
|
@@ -1039,7 +1072,20 @@ class AssetsLoader {
|
|
|
1039
1072
|
if (splitIndex > -1) {
|
|
1040
1073
|
const name = hashName.slice(0, splitIndex);
|
|
1041
1074
|
const ext = getExtName(hashName);
|
|
1042
|
-
|
|
1075
|
+
const assetsTag = {
|
|
1076
|
+
src: src
|
|
1077
|
+
};
|
|
1078
|
+
result[ext ? `${name}.${ext}` : name] = assetsTag;
|
|
1079
|
+
const attributes = this.parseTagAttributes(item);
|
|
1080
|
+
if (attributes) {
|
|
1081
|
+
assetsTag.attributes = attributes;
|
|
1082
|
+
}
|
|
1083
|
+
// const typeTagResult = item.match(TAG_TYPE_REG);
|
|
1084
|
+
// if (typeTagResult && typeTagResult[1]) {
|
|
1085
|
+
// assetsTag.attributes = {
|
|
1086
|
+
// type: typeTagResult[1]
|
|
1087
|
+
// };
|
|
1088
|
+
// }
|
|
1043
1089
|
}
|
|
1044
1090
|
}
|
|
1045
1091
|
});
|
|
@@ -1053,10 +1099,7 @@ class AssetsLoader {
|
|
|
1053
1099
|
const isHtml = manifestExt === 'html';
|
|
1054
1100
|
const responseType = isHtml ? 'text' : 'json';
|
|
1055
1101
|
return this.loadManifest(`${manifest}?t=${new Date().getTime()}`, responseType).pipe(switchMap(manifestResult => {
|
|
1056
|
-
|
|
1057
|
-
manifestResult = this.parseManifestFromHTML(manifestResult);
|
|
1058
|
-
}
|
|
1059
|
-
const { scripts, styles } = getScriptsAndStylesFullPaths(app, basePath, manifestResult);
|
|
1102
|
+
const { scripts, styles } = getScriptsAndStylesAssets(app, basePath, manifestResult);
|
|
1060
1103
|
return this.loadScriptsAndStyles(scripts, styles, {
|
|
1061
1104
|
app: app.name,
|
|
1062
1105
|
sandbox: app.sandbox,
|
|
@@ -1065,7 +1108,7 @@ class AssetsLoader {
|
|
|
1065
1108
|
}));
|
|
1066
1109
|
}
|
|
1067
1110
|
else {
|
|
1068
|
-
const { scripts, styles } =
|
|
1111
|
+
const { scripts, styles } = getScriptsAndStylesAssets(app, basePath);
|
|
1069
1112
|
return this.loadScriptsAndStyles(scripts, styles, {
|
|
1070
1113
|
app: app.name,
|
|
1071
1114
|
sandbox: app.sandbox,
|
|
@@ -1079,7 +1122,18 @@ class AssetsLoader {
|
|
|
1079
1122
|
responseType: responseType
|
|
1080
1123
|
})
|
|
1081
1124
|
.pipe(map((response) => {
|
|
1082
|
-
|
|
1125
|
+
if (responseType === 'text') {
|
|
1126
|
+
return this.parseManifestFromHTML(response);
|
|
1127
|
+
}
|
|
1128
|
+
else {
|
|
1129
|
+
const result = {};
|
|
1130
|
+
Object.keys(response).forEach(key => {
|
|
1131
|
+
result[key] = {
|
|
1132
|
+
src: response[key]
|
|
1133
|
+
};
|
|
1134
|
+
});
|
|
1135
|
+
return result;
|
|
1136
|
+
}
|
|
1083
1137
|
}));
|
|
1084
1138
|
}
|
|
1085
1139
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.3", ngImport: i0, type: AssetsLoader, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
@@ -1473,7 +1527,12 @@ class PlanetApplicationLoader {
|
|
|
1473
1527
|
this.routeChange$ = new Subject();
|
|
1474
1528
|
this.appStatusChange$ = new Subject();
|
|
1475
1529
|
this.appsLoadingStart$ = new Subject();
|
|
1530
|
+
this.innerLoading = signal(false);
|
|
1531
|
+
/**
|
|
1532
|
+
* @deprecated please use loading signal
|
|
1533
|
+
*/
|
|
1476
1534
|
this.loadingDone = false;
|
|
1535
|
+
this.loading = this.innerLoading.asReadonly();
|
|
1477
1536
|
if (getApplicationLoader()) {
|
|
1478
1537
|
throw new Error('PlanetApplicationLoader has been injected in the portal, repeated injection is not allowed');
|
|
1479
1538
|
}
|
|
@@ -1525,6 +1584,7 @@ class PlanetApplicationLoader {
|
|
|
1525
1584
|
setLoadingDone() {
|
|
1526
1585
|
this.ngZone.run(() => {
|
|
1527
1586
|
this.loadingDone = true;
|
|
1587
|
+
this.innerLoading.set(false);
|
|
1528
1588
|
});
|
|
1529
1589
|
}
|
|
1530
1590
|
getAppNames(apps) {
|
|
@@ -1579,6 +1639,7 @@ class PlanetApplicationLoader {
|
|
|
1579
1639
|
});
|
|
1580
1640
|
if (hasAppsNeedLoadingAssets) {
|
|
1581
1641
|
this.loadingDone = false;
|
|
1642
|
+
this.innerLoading.set(true);
|
|
1582
1643
|
}
|
|
1583
1644
|
return loadApps$.length > 0 ? forkJoin(loadApps$) : of([]);
|
|
1584
1645
|
}),
|
|
@@ -1609,9 +1670,7 @@ class PlanetApplicationLoader {
|
|
|
1609
1670
|
debug(`[routeChange] app(${app.name}) is active, do nothings`);
|
|
1610
1671
|
const appRef = getPlanetApplicationRef(app.name);
|
|
1611
1672
|
// Backwards compatibility sub app use old version which has not getCurrentRouterStateUrl
|
|
1612
|
-
const currentUrl = appRef?.getCurrentRouterStateUrl
|
|
1613
|
-
? appRef.getCurrentRouterStateUrl()
|
|
1614
|
-
: '';
|
|
1673
|
+
const currentUrl = appRef?.getCurrentRouterStateUrl ? appRef.getCurrentRouterStateUrl() : '';
|
|
1615
1674
|
if (currentUrl !== event.url) {
|
|
1616
1675
|
appRef?.navigateByUrl(event.url);
|
|
1617
1676
|
}
|
|
@@ -1890,9 +1949,15 @@ class Planet {
|
|
|
1890
1949
|
get planetApplicationService() {
|
|
1891
1950
|
return getApplicationService();
|
|
1892
1951
|
}
|
|
1952
|
+
/**
|
|
1953
|
+
* @deprecated please use loading signal
|
|
1954
|
+
*/
|
|
1893
1955
|
get loadingDone() {
|
|
1894
1956
|
return this.planetApplicationLoader.loadingDone;
|
|
1895
1957
|
}
|
|
1958
|
+
get loading() {
|
|
1959
|
+
return this.planetApplicationLoader.loading;
|
|
1960
|
+
}
|
|
1896
1961
|
get appStatusChange() {
|
|
1897
1962
|
return this.planetApplicationLoader.appStatusChange;
|
|
1898
1963
|
}
|