@genesislcap/foundation-shell 14.131.0 → 14.133.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/MODULE_FEDERATION.md +11 -0
- package/README.md +19 -31
- package/dist/{13.13.60f90061d33208d1354b.js → 13.13.cc8f282b2fd08bdaa429.js} +2 -2
- package/dist/{13.4d4d342ba791da63d597e22d6d61f90f.js.map → 13.18ce90986215931e094ef572bdb883d6.js.map} +1 -1
- package/dist/InjectManifest.e1f16063b12a45e391ae7b4f95241ab2.js.map +1 -0
- package/dist/dts/app/app.d.ts +159 -0
- package/dist/dts/app/app.d.ts.map +1 -0
- package/dist/dts/app/behaviors.d.ts +53 -0
- package/dist/dts/app/behaviors.d.ts.map +1 -0
- package/dist/dts/app/config.d.ts +25 -0
- package/dist/dts/app/config.d.ts.map +1 -0
- package/dist/dts/app/index.d.ts +5 -0
- package/dist/dts/app/index.d.ts.map +1 -0
- package/dist/dts/app/types.d.ts +700 -0
- package/dist/dts/app/types.d.ts.map +1 -0
- package/dist/dts/app/utils.d.ts +61 -0
- package/dist/dts/app/utils.d.ts.map +1 -0
- package/dist/dts/index.docs.d.ts +8 -0
- package/dist/dts/index.docs.d.ts.map +1 -0
- package/dist/dts/layouts/default/layout.d.ts.map +1 -1
- package/dist/dts/layouts/formatsExample/layout.d.ts.map +1 -1
- package/dist/dts/main/main.d.ts +3 -0
- package/dist/dts/main/main.d.ts.map +1 -1
- package/dist/dts/main/main.styles.d.ts +3 -0
- package/dist/dts/main/main.styles.d.ts.map +1 -1
- package/dist/dts/main/main.template.d.ts +9 -0
- package/dist/dts/main/main.template.d.ts.map +1 -1
- package/dist/dts/pbc/index.d.ts +2 -0
- package/dist/dts/pbc/index.d.ts.map +1 -0
- package/dist/dts/pbc/pbc.d.ts +68 -0
- package/dist/dts/pbc/pbc.d.ts.map +1 -0
- package/dist/dts/pbc/vite/exports.d.ts +26 -0
- package/dist/dts/pbc/vite/exports.d.ts.map +1 -0
- package/dist/dts/pbc/vite/index.d.ts +2 -0
- package/dist/dts/pbc/vite/index.d.ts.map +1 -0
- package/dist/dts/pbc/vite/utils.d.ts +8 -0
- package/dist/dts/pbc/vite/utils.d.ts.map +1 -0
- package/dist/dts/pbc/webpack/exports.d.ts +26 -0
- package/dist/dts/pbc/webpack/exports.d.ts.map +1 -0
- package/dist/dts/pbc/webpack/index.d.ts +2 -0
- package/dist/dts/pbc/webpack/index.d.ts.map +1 -0
- package/dist/dts/pbc/webpack/utils.d.ts +9 -0
- package/dist/dts/pbc/webpack/utils.d.ts.map +1 -0
- package/dist/dts/serviceWorker/serviceWorker.d.ts +5 -0
- package/dist/dts/serviceWorker/serviceWorker.d.ts.map +1 -1
- package/dist/dts/tsdoc-metadata.json +11 -0
- package/dist/esm/app/app.js +190 -0
- package/dist/esm/app/behaviors.js +126 -0
- package/dist/esm/app/config.js +28 -0
- package/dist/esm/app/index.js +4 -0
- package/dist/esm/app/types.js +1 -0
- package/dist/esm/app/utils.js +102 -0
- package/dist/esm/index.docs.js +7 -0
- package/dist/esm/layouts/default/layout.js +3 -0
- package/dist/esm/layouts/formatsExample/layout.js +3 -0
- package/dist/esm/main/main.js +3 -0
- package/dist/esm/main/main.styles.js +3 -0
- package/dist/esm/main/main.template.js +9 -0
- package/dist/esm/pbc/index.js +1 -0
- package/dist/esm/pbc/pbc.js +82 -0
- package/dist/esm/pbc/vite/exports.js +38 -0
- package/dist/esm/pbc/vite/index.js +1 -0
- package/dist/esm/pbc/vite/utils.js +16 -0
- package/dist/esm/pbc/webpack/exports.js +26 -0
- package/dist/esm/pbc/webpack/index.js +1 -0
- package/dist/esm/pbc/webpack/utils.js +16 -0
- package/dist/esm/serviceWorker/serviceWorker.js +2 -0
- package/dist/foundation-shell.api.json +4415 -0
- package/dist/foundation-shell.d.ts +1098 -0
- package/dist/{foundationShell.36a3b143a4ba39b4f032455d8eb5e502.js.map → foundationShell.fadec38bfa479afb70fbd232cd79236c.js.map} +1 -1
- package/dist/index.html +2 -2
- package/dist/main.3083ee4d28f46e8a3506.js +2 -0
- package/dist/{main.6f018458fb996d9110cc5fd4557cc7b2.js.map → main.4eedb5ca7f0017cbc616ee79b8e61731.js.map} +1 -1
- package/dist/remoteEntry.js +2 -2
- package/dist/sw.js +2 -2
- package/dist/{swRegistration.5825d13b9d973891da34.js → swRegistration.48635f3caa94cdf4bcb2.js} +2 -2
- package/dist/{swRegistration.de691080ebb6f93ca0a423137ad2c19a.js.map → swRegistration.a93f46a92fddad87f178ead7e088ee54.js.map} +1 -1
- package/docs/.gitattributes +2 -0
- package/docs/api/foundation-shell.app.config.md +13 -0
- package/docs/api/foundation-shell.app.deregisterassets.md +17 -0
- package/docs/api/foundation-shell.app.hasassets.md +17 -0
- package/docs/api/foundation-shell.app.md +49 -0
- package/docs/api/foundation-shell.app.registerassets.md +52 -0
- package/docs/api/foundation-shell.appassets.elements.md +13 -0
- package/docs/api/foundation-shell.appassets.md +25 -0
- package/docs/api/foundation-shell.appassets.metadata.md +13 -0
- package/docs/api/foundation-shell.appassets.registrations.md +13 -0
- package/docs/api/foundation-shell.appassets.routes.md +13 -0
- package/docs/api/foundation-shell.appassets.stores.md +13 -0
- package/docs/api/foundation-shell.appassets.styles.md +13 -0
- package/docs/api/foundation-shell.appconfig.context.md +11 -0
- package/docs/api/foundation-shell.appconfig.defaultelementrepeatoptions.md +11 -0
- package/docs/api/foundation-shell.appconfig.md +21 -0
- package/docs/api/foundation-shell.appcontext.md +19 -0
- package/docs/api/foundation-shell.appdependencies.md +15 -0
- package/docs/api/foundation-shell.appdependencyprerequisites.md +15 -0
- package/docs/api/foundation-shell.appelement.md +55 -0
- package/docs/api/foundation-shell.appelementpredicate.md +17 -0
- package/docs/api/foundation-shell.appmetadata.md +45 -0
- package/docs/api/foundation-shell.appregister.deregisterelement.md +31 -0
- package/docs/api/foundation-shell.appregister.deregisterroute.md +31 -0
- package/docs/api/foundation-shell.appregister.deregisterstore.md +31 -0
- package/docs/api/foundation-shell.appregister.deregisterstyle.md +31 -0
- package/docs/api/foundation-shell.appregister.md +37 -0
- package/docs/api/foundation-shell.appregister.registercomponents.md +13 -0
- package/docs/api/foundation-shell.appregister.registerelement.md +31 -0
- package/docs/api/foundation-shell.appregister.registerelementstarget.md +13 -0
- package/docs/api/foundation-shell.appregister.registerroute.md +31 -0
- package/docs/api/foundation-shell.appregister.registerroutecollection.md +13 -0
- package/docs/api/foundation-shell.appregister.registerstore.md +31 -0
- package/docs/api/foundation-shell.appregister.registerstoreroot.md +13 -0
- package/docs/api/foundation-shell.appregister.registerstyle.md +31 -0
- package/docs/api/foundation-shell.appregister.registerstylestarget.md +13 -0
- package/docs/api/foundation-shell.appregistration.md +57 -0
- package/docs/api/foundation-shell.appregistrationcontext.md +15 -0
- package/docs/api/foundation-shell.approute.md +49 -0
- package/docs/api/foundation-shell.approutepredicate.md +17 -0
- package/docs/api/foundation-shell.appstore.md +45 -0
- package/docs/api/foundation-shell.appstorepredicate.md +17 -0
- package/docs/api/foundation-shell.appstyle.md +48 -0
- package/docs/api/foundation-shell.appstylepredicate.md +17 -0
- package/docs/api/foundation-shell.apptargetid.md +43 -0
- package/docs/api/foundation-shell.apptokentypepredicate.md +13 -0
- package/docs/api/foundation-shell.appvalidity.isvalid.md +26 -0
- package/docs/api/foundation-shell.appvalidity.md +20 -0
- package/docs/api/foundation-shell.appvaliditycontext.md +18 -0
- package/docs/api/foundation-shell.assetpredicate.md +12 -0
- package/docs/api/foundation-shell.defaultapp.deregisterassets.md +17 -0
- package/docs/api/foundation-shell.defaultapp.deregisterelement.md +24 -0
- package/docs/api/foundation-shell.defaultapp.deregisterroute.md +24 -0
- package/docs/api/foundation-shell.defaultapp.deregisterstore.md +24 -0
- package/docs/api/foundation-shell.defaultapp.deregisterstyle.md +24 -0
- package/docs/api/foundation-shell.defaultapp.elements.md +13 -0
- package/docs/api/foundation-shell.defaultapp.hasassets.md +17 -0
- package/docs/api/foundation-shell.defaultapp.isvalid.md +26 -0
- package/docs/api/foundation-shell.defaultapp.md +48 -0
- package/docs/api/foundation-shell.defaultapp.metadata.md +13 -0
- package/docs/api/foundation-shell.defaultapp.registerassets.md +24 -0
- package/docs/api/foundation-shell.defaultapp.registercomponents.md +24 -0
- package/docs/api/foundation-shell.defaultapp.registerelement.md +24 -0
- package/docs/api/foundation-shell.defaultapp.registerelementstarget.md +28 -0
- package/docs/api/foundation-shell.defaultapp.registerroute.md +24 -0
- package/docs/api/foundation-shell.defaultapp.registerroutecollection.md +25 -0
- package/docs/api/foundation-shell.defaultapp.registerstore.md +24 -0
- package/docs/api/foundation-shell.defaultapp.registerstoreroot.md +25 -0
- package/docs/api/foundation-shell.defaultapp.registerstyle.md +24 -0
- package/docs/api/foundation-shell.defaultapp.registerstylestarget.md +27 -0
- package/docs/api/foundation-shell.defaultapp.registrations.md +13 -0
- package/docs/api/foundation-shell.defaultapp.routes.md +13 -0
- package/docs/api/foundation-shell.defaultapp.stores.md +13 -0
- package/docs/api/foundation-shell.defaultapp.styles.md +13 -0
- package/docs/api/foundation-shell.defaultappconfig.md +13 -0
- package/docs/api/foundation-shell.dynamictemplate.md +12 -0
- package/docs/api/foundation-shell.getapp.md +30 -0
- package/docs/api/foundation-shell.getqualifiedmoduletokens.md +11 -0
- package/docs/api/foundation-shell.haspredicate.md +17 -0
- package/docs/api/foundation-shell.hastarget.md +15 -0
- package/docs/api/foundation-shell.importpbcassets.md +75 -0
- package/docs/api/foundation-shell.isappelement.md +22 -0
- package/docs/api/foundation-shell.isappmetadata.md +22 -0
- package/docs/api/foundation-shell.isappregistration.md +22 -0
- package/docs/api/foundation-shell.isapproute.md +22 -0
- package/docs/api/foundation-shell.isappstore.md +22 -0
- package/docs/api/foundation-shell.isappstyle.md +22 -0
- package/docs/api/foundation-shell.iscomposablestyles.md +22 -0
- package/docs/api/foundation-shell.isviewtemplate.md +22 -0
- package/docs/api/foundation-shell.loadingtemplate.md +12 -0
- package/docs/api/foundation-shell.mainapplication.connectedcallback.md +15 -0
- package/docs/api/foundation-shell.mainapplication.md +27 -0
- package/docs/api/foundation-shell.mainapplication.ready.md +11 -0
- package/docs/api/foundation-shell.mainapplication.selecttemplate.md +15 -0
- package/docs/api/foundation-shell.maintemplate.md +12 -0
- package/docs/api/foundation-shell.md +81 -0
- package/docs/api/foundation-shell.registercomponents.md +34 -0
- package/docs/api/foundation-shell.registerelementstarget.md +39 -0
- package/docs/api/foundation-shell.registerroutecollection.md +24 -0
- package/docs/api/foundation-shell.registerstoreroot.md +33 -0
- package/docs/api/foundation-shell.registerstylestarget.md +27 -0
- package/docs/api/foundation-shell.registrationpredicate.md +12 -0
- package/docs/api/foundation-shell.targetidpredicate.md +12 -0
- package/docs/api/index.md +12 -0
- package/docs/api-report.md +293 -0
- package/package.json +50 -9
- package/dist/InjectManifest.44b41759e967dfc682a50ab3e02bfaba.js.map +0 -1
- package/dist/main.21fe80be0d6102e2dccf.js +0 -2
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { toElementStyles } from '@genesislcap/foundation-utils';
|
|
2
|
+
import { Observable } from '@microsoft/fast-element';
|
|
3
|
+
import { assetPredicate, registrationPredicate, targetIdPredicate } from './utils';
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export class AppStylesTargetBehavior {
|
|
8
|
+
constructor(app, targetId, predicate) {
|
|
9
|
+
this.app = app;
|
|
10
|
+
this.targetId = targetId;
|
|
11
|
+
this.predicate = predicate;
|
|
12
|
+
}
|
|
13
|
+
bind(elementInstance) {
|
|
14
|
+
this.targetElement = elementInstance;
|
|
15
|
+
Observable.getNotifier(this.app).subscribe(this, 'styles');
|
|
16
|
+
this.handleChange();
|
|
17
|
+
}
|
|
18
|
+
unbind() {
|
|
19
|
+
var _a;
|
|
20
|
+
Observable.getNotifier(this.app).unsubscribe(this, 'styles');
|
|
21
|
+
(_a = this.targetElement) === null || _a === void 0 ? void 0 : _a.$fastController.removeStyles(this.prevTargetStyles);
|
|
22
|
+
}
|
|
23
|
+
handleChange() {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
this.updateTargetStyles();
|
|
26
|
+
if (this.prevTargetStyles && this.prevTargetStyles !== this.nextTargetStyles) {
|
|
27
|
+
(_a = this.targetElement) === null || _a === void 0 ? void 0 : _a.$fastController.removeStyles(this.prevTargetStyles);
|
|
28
|
+
}
|
|
29
|
+
(_b = this.targetElement) === null || _b === void 0 ? void 0 : _b.$fastController.addStyles(this.nextTargetStyles);
|
|
30
|
+
}
|
|
31
|
+
updateTargetStyles() {
|
|
32
|
+
this.prevTargetStyles = this.nextTargetStyles;
|
|
33
|
+
this.nextTargetStyles = toElementStyles(this.app.styles
|
|
34
|
+
.filter((asset) => targetIdPredicate(asset, this.targetId) &&
|
|
35
|
+
assetPredicate(asset, this.app.config.context) &&
|
|
36
|
+
registrationPredicate(asset, this.predicate, this.app.config.context))
|
|
37
|
+
.map((token) => token.styles)
|
|
38
|
+
.flat());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
const matchingFilterResult = (prev, next) => prev.length === next.length && prev.every((element, index) => element === next[index]);
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export class AppRoutesBehavior {
|
|
49
|
+
constructor(app, routeCollection, predicate) {
|
|
50
|
+
this.app = app;
|
|
51
|
+
this.routeCollection = routeCollection;
|
|
52
|
+
this.predicate = predicate;
|
|
53
|
+
this.prevRoutes = [];
|
|
54
|
+
this.nextRoutes = [];
|
|
55
|
+
}
|
|
56
|
+
bind() {
|
|
57
|
+
Observable.getNotifier(this.app).subscribe(this, 'routes');
|
|
58
|
+
this.handleChange();
|
|
59
|
+
}
|
|
60
|
+
unbind() {
|
|
61
|
+
Observable.getNotifier(this.app).unsubscribe(this, 'routes');
|
|
62
|
+
}
|
|
63
|
+
handleChange() {
|
|
64
|
+
this.updateTargetRoutes();
|
|
65
|
+
/**
|
|
66
|
+
* There is no remove or unmap api on the router to do something like this:
|
|
67
|
+
*
|
|
68
|
+
* if (this.prevRoutes?.length) {
|
|
69
|
+
* this.routeCollection.unmap(...this.prevRoutes);
|
|
70
|
+
* }
|
|
71
|
+
*
|
|
72
|
+
* ...but maybe we can add that eventually.
|
|
73
|
+
*/
|
|
74
|
+
if (matchingFilterResult(this.prevRoutes, this.nextRoutes)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const newRoutes = this.nextRoutes.filter((route) => !this.prevRoutes.includes(route));
|
|
78
|
+
if (newRoutes.length) {
|
|
79
|
+
this.routeCollection.map(...newRoutes);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
updateTargetRoutes() {
|
|
83
|
+
this.prevRoutes = this.nextRoutes;
|
|
84
|
+
this.nextRoutes = this.app.routes.filter((asset) => assetPredicate(asset, this.app.config.context) &&
|
|
85
|
+
registrationPredicate(asset, this.predicate, this.app.config.context));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
export class AppStoresBehavior {
|
|
92
|
+
constructor(app, storeRoot, predicate) {
|
|
93
|
+
this.app = app;
|
|
94
|
+
this.storeRoot = storeRoot;
|
|
95
|
+
this.predicate = predicate;
|
|
96
|
+
this.prevStores = [];
|
|
97
|
+
this.nextStores = [];
|
|
98
|
+
}
|
|
99
|
+
bind() {
|
|
100
|
+
Observable.getNotifier(this.app).subscribe(this, 'stores');
|
|
101
|
+
this.handleChange();
|
|
102
|
+
}
|
|
103
|
+
unbind() {
|
|
104
|
+
Observable.getNotifier(this.app).unsubscribe(this, 'stores');
|
|
105
|
+
}
|
|
106
|
+
handleChange() {
|
|
107
|
+
var _a, _b;
|
|
108
|
+
this.updateTargetStores();
|
|
109
|
+
if (matchingFilterResult(this.prevStores, this.nextStores)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if ((_a = this.prevStores) === null || _a === void 0 ? void 0 : _a.length) {
|
|
113
|
+
const oldFragments = this.prevStores.map((appStore) => appStore.store);
|
|
114
|
+
this.storeRoot.removeStoreFragments(...oldFragments);
|
|
115
|
+
}
|
|
116
|
+
if ((_b = this.nextStores) === null || _b === void 0 ? void 0 : _b.length) {
|
|
117
|
+
const newFragments = this.nextStores.map((appStore) => appStore.store);
|
|
118
|
+
this.storeRoot.addStoreFragments(...newFragments);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
updateTargetStores() {
|
|
122
|
+
this.prevStores = this.nextStores;
|
|
123
|
+
this.nextStores = this.app.stores.filter((asset) => assetPredicate(asset, this.app.config.context) &&
|
|
124
|
+
registrationPredicate(asset, this.predicate, this.app.config.context));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DI } from '@microsoft/fast-foundation';
|
|
2
|
+
/**
|
|
3
|
+
* Default AppConfig DI implementation.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export const defaultAppConfig = {
|
|
7
|
+
/**
|
|
8
|
+
* TODO: Assignment of context.
|
|
9
|
+
*/
|
|
10
|
+
context: {
|
|
11
|
+
env: 'development',
|
|
12
|
+
domain: location.hostname,
|
|
13
|
+
user: {},
|
|
14
|
+
answers: {},
|
|
15
|
+
featureFlags: {},
|
|
16
|
+
},
|
|
17
|
+
defaultElementRepeatOptions: {
|
|
18
|
+
positioning: true,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* AppConfig DI key.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
* @privateRemarks
|
|
26
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
|
27
|
+
*/
|
|
28
|
+
export const AppConfig = DI.createInterface((x) => x.instance(defaultAppConfig));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ElementStyles, ViewTemplate } from '@microsoft/fast-element';
|
|
2
|
+
/**
|
|
3
|
+
* @param token - A module export token.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export function isAppMetadata(token) {
|
|
7
|
+
const metadata = token;
|
|
8
|
+
return metadata && !!metadata.name && !!metadata.version;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @param token - A module export token.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export function isAppRegistration(token) {
|
|
15
|
+
return typeof token === 'function'; // && token.length === 1; // < could enforce context arg
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @param token - A module export token.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export function isAppRoute(token) {
|
|
22
|
+
const route = token;
|
|
23
|
+
return route && !!route.path && !!route.element;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @param token - A module export token.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export function isAppStore(token) {
|
|
30
|
+
const store = token;
|
|
31
|
+
return store && !!store.store;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @param token - A module export token.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export function isAppElement(token) {
|
|
38
|
+
const pbcElements = token;
|
|
39
|
+
return (pbcElements &&
|
|
40
|
+
!!pbcElements.targetId &&
|
|
41
|
+
!!pbcElements.elements &&
|
|
42
|
+
isViewTemplate(pbcElements.elements));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @param token - A module export token / element candidate.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export function isViewTemplate(token) {
|
|
49
|
+
return token instanceof ViewTemplate;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @param token - A module export token.
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
export function isAppStyle(token) {
|
|
56
|
+
const pbcStyles = token;
|
|
57
|
+
return (pbcStyles && !!pbcStyles.targetId && !!pbcStyles.styles && isComposableStyles(pbcStyles.styles));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @param token - A module export token / styles candidate.
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export function isComposableStyles(token) {
|
|
64
|
+
return (typeof token === 'string' || token instanceof ElementStyles || token instanceof CSSStyleSheet);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export const registrationPredicate = (asset, predicate, context) => (typeof predicate === 'function' ? predicate(asset, context) : true);
|
|
70
|
+
/**
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
export const targetIdPredicate = (asset, targetId) => Array.isArray(targetId) ? targetId.includes(asset.targetId) : asset.targetId === targetId;
|
|
74
|
+
/**
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
export const assetPredicate = (asset, context) => typeof asset.predicate === 'function' ? asset.predicate(context) : true;
|
|
78
|
+
/**
|
|
79
|
+
* @param module - An imported module.
|
|
80
|
+
* @param predicate - Token type predicate.
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export const getQualifiedModuleTokens = (module, predicate) => {
|
|
84
|
+
const tokenArray = [];
|
|
85
|
+
Object.keys(module).forEach((token) => {
|
|
86
|
+
/**
|
|
87
|
+
* Guard against `export default` tokens that can cause duplicates
|
|
88
|
+
*/
|
|
89
|
+
if (tokenArray.includes(module[token])) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Guard against tokens of unexpected types
|
|
94
|
+
*/
|
|
95
|
+
if (predicate && !predicate(module[token])) {
|
|
96
|
+
console.log(`The module export ${token} is not of the expected type.`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
tokenArray.push(module[token]);
|
|
100
|
+
});
|
|
101
|
+
return tokenArray;
|
|
102
|
+
};
|
package/dist/esm/main/main.js
CHANGED
|
@@ -4,6 +4,9 @@ import { logger } from '../utils';
|
|
|
4
4
|
import { MainStyles as styles } from './main.styles';
|
|
5
5
|
import { DynamicTemplate as template, LoadingTemplate, MainTemplate } from './main.template';
|
|
6
6
|
const name = 'foundation-shell';
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
7
10
|
let MainApplication = class MainApplication extends FASTElement {
|
|
8
11
|
constructor() {
|
|
9
12
|
super(...arguments);
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { html } from '@microsoft/fast-element';
|
|
2
|
+
/**
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
2
5
|
export const DynamicTemplate = html `
|
|
3
6
|
<div id="app-shell" class="dynamic-template">${(x) => x.selectTemplate()}</div>
|
|
4
7
|
`;
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
5
11
|
export const LoadingTemplate = html `
|
|
6
12
|
...
|
|
7
13
|
`;
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
8
17
|
export const MainTemplate = html `
|
|
9
18
|
<h1>Genesis App Shell / Registry</h1>
|
|
10
19
|
<slot></slot>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pbc';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { logger } from '../utils';
|
|
3
|
+
/**
|
|
4
|
+
* A utility for importing PBC assets that have been added to the application's src/pbc directory via genx add.
|
|
5
|
+
*
|
|
6
|
+
* The `genx` builder (webpack or vite) will attempt to dynamically load all PBC assets from the application's `src/pbc`
|
|
7
|
+
* directory by default. The returned AppAssets can then be applied to the App. Please note that `app.registerAssets`
|
|
8
|
+
* is a one-time operation, intended for upfront bulk registration. After this point, you must use the single asset
|
|
9
|
+
* APIs of the `App` for lazy asset registration or deregistration.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { importPBCAssets } from '@genesislcap/foundation-shell/pbc';
|
|
14
|
+
* ...
|
|
15
|
+
* const assets = await importPBCAssets();
|
|
16
|
+
* ...
|
|
17
|
+
* app.registerAssets(assets);
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* A typical app setup that makes use of PBC imports might look like this.
|
|
22
|
+
* ```ts
|
|
23
|
+
* // src/main/main.ts
|
|
24
|
+
*
|
|
25
|
+
* @App app: App;
|
|
26
|
+
*
|
|
27
|
+
* async connectedCallback() {
|
|
28
|
+
* ...
|
|
29
|
+
* await this.loadPBCs();
|
|
30
|
+
* ...
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* async loadPBCs() {
|
|
34
|
+
* // Import PBC assets that may have been added to the ./pbc directory by genx or by hand
|
|
35
|
+
* const pbcAssets = await importPBCAssets();
|
|
36
|
+
*
|
|
37
|
+
* // Register bulk assets
|
|
38
|
+
* this.app.registerAssets(pbcAssets);
|
|
39
|
+
*
|
|
40
|
+
* // Register the top-level route collection
|
|
41
|
+
* this.app.registerRouteCollection(this.config.routes);
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* The rest of the PBC setup is handled by the system automatically, however, you will still need to register
|
|
46
|
+
* application asset integration points.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* A typical PBC directory structure may look like this.
|
|
50
|
+
* ```markdown
|
|
51
|
+
* ├── reporting
|
|
52
|
+
* │ ├── elements.ts
|
|
53
|
+
* │ ├── metadata.ts
|
|
54
|
+
* │ ├── registrations.ts
|
|
55
|
+
* │ ├── routes.ts
|
|
56
|
+
* │ ├── stores.ts
|
|
57
|
+
* │ └── styles.ts
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* Each file is dynamically loaded and processed as part of the overall PBC set the application contains. PBCs do not
|
|
61
|
+
* need to include `index.ts` files, and export token naming does not matter within any of these files. For example,
|
|
62
|
+
* `foo` here `export const foo: AppElement = {...}` has no impact on PBC integration.
|
|
63
|
+
*
|
|
64
|
+
* The answers generated from the `genx add` cli flows can be used to tailor what PBC assets are included at build-time.
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
export function importPBCAssets() {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
let assets;
|
|
71
|
+
if (BUILDER === 'webpack') {
|
|
72
|
+
assets = yield import('./webpack');
|
|
73
|
+
}
|
|
74
|
+
else if (BUILDER === 'vite') {
|
|
75
|
+
assets = yield import('./vite');
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
logger.error('importPBCAssets error. Unable to determine the BUILDER in use.');
|
|
79
|
+
}
|
|
80
|
+
return assets;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isAppElement, isAppMetadata, isAppRegistration, isAppRoute, isAppStore, isAppStyle, } from '../../app/utils';
|
|
2
|
+
import { importAll } from './utils';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export const metadata = importAll(import.meta.glob('pbc/**/metadata.ts', {
|
|
7
|
+
eager: true,
|
|
8
|
+
}), isAppMetadata);
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export const registrations = importAll(import.meta.glob('pbc/**/registrations.ts', {
|
|
13
|
+
eager: true,
|
|
14
|
+
}), isAppRegistration);
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export const routes = importAll(import.meta.glob('pbc/**/routes.ts', {
|
|
19
|
+
eager: true,
|
|
20
|
+
}), isAppRoute);
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export const elements = importAll(import.meta.glob('pbc/**/elements.ts', {
|
|
25
|
+
eager: true,
|
|
26
|
+
}), isAppElement);
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export const styles = importAll(import.meta.glob('pbc/**/styles.ts', {
|
|
31
|
+
eager: true,
|
|
32
|
+
}), isAppStyle);
|
|
33
|
+
/**
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export const stores = importAll(import.meta.glob('pbc/**/stores.ts', {
|
|
37
|
+
eager: true,
|
|
38
|
+
}), isAppStore);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './exports';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getQualifiedModuleTokens } from '../../app/utils';
|
|
2
|
+
import { logger } from '../../utils';
|
|
3
|
+
/**
|
|
4
|
+
* @param modules - Vite import glob modules.
|
|
5
|
+
* @param predicate - Optional token type predicate.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export function importAll(modules, predicate) {
|
|
9
|
+
const imports = Object.keys(modules).reduce((acc, key) => {
|
|
10
|
+
const module = modules[key];
|
|
11
|
+
const tokenArray = getQualifiedModuleTokens(module, predicate);
|
|
12
|
+
return [...acc, ...tokenArray];
|
|
13
|
+
}, []);
|
|
14
|
+
logger.debug('importAll result', imports);
|
|
15
|
+
return imports;
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isAppElement, isAppMetadata, isAppRegistration, isAppRoute, isAppStore, isAppStyle, } from '../../app/utils';
|
|
2
|
+
import { importAll } from './utils';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export const metadata = importAll(require.context('pbc', true, /metadata\.ts$/), isAppMetadata);
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export const registrations = importAll(require.context('pbc', true, /registrations\.ts$/), isAppRegistration);
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export const routes = importAll(require.context('pbc', true, /routes\.ts$/), isAppRoute);
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export const elements = importAll(require.context('pbc', true, /elements\.ts$/), isAppElement);
|
|
19
|
+
/**
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export const styles = importAll(require.context('pbc', true, /styles\.ts$/), isAppStyle);
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export const stores = importAll(require.context('pbc', true, /stores\.ts$/), isAppStore);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './exports';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getQualifiedModuleTokens } from '../../app/utils';
|
|
2
|
+
import { logger } from '../../utils';
|
|
3
|
+
/**
|
|
4
|
+
* @param context - Webpack require context.
|
|
5
|
+
* @param predicate - Optional token type predicate.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export function importAll(context, predicate) {
|
|
9
|
+
const imports = context.keys().reduce((acc, key) => {
|
|
10
|
+
const module = context(key);
|
|
11
|
+
const tokenArray = getQualifiedModuleTokens(module, predicate);
|
|
12
|
+
return [...acc, ...tokenArray];
|
|
13
|
+
}, []);
|
|
14
|
+
logger.debug('importAll result', imports);
|
|
15
|
+
return imports;
|
|
16
|
+
}
|