Skip to content

Commit 6b52dbd

Browse files
authored
fix(ui5-illustrated-message): support collection based illustration loading (#7318)
* fix(ui5-illustrated-message): support map based illustration loading * chore: add assets * fix: provide default collection and fix paths * fix: procide fallback collection when registering assets
1 parent 3b7c711 commit 6b52dbd

File tree

279 files changed

+6587
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

279 files changed

+6587
-87
lines changed

packages/base/src/asset-registries/Illustrations.ts

Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import getSharedResource from "../getSharedResource.js";
22
import type { I18nText } from "../i18nBundle.js";
3+
import { getTheme } from "../config/Theme.js";
34

45
type IllustrationLoader = (illustrationName: string) => Promise<IllustrationData>;
56

@@ -13,14 +14,69 @@ type IllustrationProperties = {
1314

1415
type IllustrationData = IllustrationProperties & {
1516
set: string,
17+
collection: string,
1618
};
1719

20+
enum IllustrationCollections {
21+
"sap_horizon" = "V5",
22+
"sap_horizon_dark" = "V5",
23+
"sap_horizon_hcb" = "V5/HC",
24+
"sap_horizon_hcw" = "V5/HC",
25+
}
26+
27+
const FALLBACK_COLLECTION = "V4";
28+
1829
const loaders = new Map<string, IllustrationLoader>();
1930
const registry = getSharedResource<Map<string, IllustrationProperties>>("SVGIllustration.registry", new Map());
2031
const illustrationPromises = getSharedResource<Map<string, Promise<IllustrationData>>>("SVGIllustration.promises", new Map());
2132

33+
const getCollection = () => {
34+
const theme = getTheme() as keyof typeof IllustrationCollections;
35+
36+
if (IllustrationCollections[theme]) {
37+
return IllustrationCollections[theme];
38+
}
39+
40+
return FALLBACK_COLLECTION;
41+
};
42+
43+
/**
44+
* Processes the name of the illustration
45+
* The name is used to generate the registry key and the loader key
46+
* The registry key is used to store and get the illustration data from the registry
47+
* The loader key is used to store and get the illustration loader from the loaders map
48+
* The function generates the correct registry key and loader key based on whether an loader exists for the illustration
49+
* If there is no loader registered for the collection, it falls back to the default collection
50+
*/
51+
const processName = (name: string) => {
52+
let collection = getCollection();
53+
const isTnt = name.startsWith("Tnt");
54+
const set = isTnt ? "tnt" : "fiori";
55+
56+
let registryKey = `${set}/${collection}/${name}`;
57+
let loaderKey = `${collection}/${name}`;
58+
59+
if (!loaders.has(loaderKey) && collection !== FALLBACK_COLLECTION) {
60+
collection = FALLBACK_COLLECTION;
61+
loaderKey = `${collection}/${name}`;
62+
registryKey = `${set}/${collection}/${name}`;
63+
}
64+
65+
if (isTnt) {
66+
name = name.replace(/^Tnt/, "");
67+
registryKey = `${set}/${collection}/${name}`;
68+
}
69+
70+
return {
71+
registryKey,
72+
loaderKey,
73+
collection,
74+
};
75+
};
76+
2277
const registerIllustration = (name: string, data: IllustrationData) => {
23-
registry.set(`${data.set}/${name}`, {
78+
const collection = data.collection || FALLBACK_COLLECTION;
79+
registry.set(`${data.set}/${collection}/${name}`, {
2480
dialogSvg: data.dialogSvg,
2581
sceneSvg: data.sceneSvg,
2682
spotSvg: data.spotSvg,
@@ -33,38 +89,31 @@ const registerIllustrationLoader = (illustrationName: string, loader: Illustrati
3389
loaders.set(illustrationName, loader);
3490
};
3591

36-
const _loadIllustrationOnce = async (illustrationName: string) => {
37-
if (!illustrationPromises.has(illustrationName)) {
38-
if (!loaders.has(illustrationName)) {
92+
const _loadIllustrationOnce = (illustrationName: string) => {
93+
const { loaderKey } = processName(illustrationName);
94+
95+
if (!illustrationPromises.has(loaderKey)) {
96+
if (!loaders.has(loaderKey)) {
3997
const illustrationPath = illustrationName.startsWith("Tnt") ? `tnt/${illustrationName.replace(/^Tnt/, "")}` : illustrationName;
4098
throw new Error(`No loader registered for the ${illustrationName} illustration. Probably you forgot to import the "@ui5/webcomponents-fiori/dist/illustrations/${illustrationPath}.js" module. Or you can import the "@ui5/webcomponents-fiori/dist/illustrations/AllIllustrations.js" module that will make all illustrations available, but fetch only the ones used.`);
4199
}
42100

43-
const loadIllustrations = loaders.get(illustrationName)!;
44-
illustrationPromises.set(illustrationName, loadIllustrations(illustrationName));
101+
const loadIllustrations = loaders.get(loaderKey)!;
102+
illustrationPromises.set(loaderKey, loadIllustrations(loaderKey));
45103
}
46-
return illustrationPromises.get(illustrationName);
104+
return illustrationPromises.get(loaderKey);
47105
};
48106

49107
const getIllustrationDataSync = (illustrationName: string) => {
50-
let set = "fiori";
51-
52-
if (illustrationName.startsWith("Tnt")) {
53-
set = "tnt";
54-
illustrationName = illustrationName.replace(/^Tnt/, "");
55-
}
56-
return registry.get(`${set}/${illustrationName}`);
108+
const { registryKey } = processName(illustrationName);
109+
return registry.get(registryKey);
57110
};
58111

59112
const getIllustrationData = async (illustrationName: string) => {
60-
let set = "fiori";
113+
const { registryKey } = processName(illustrationName);
61114

62115
await _loadIllustrationOnce(illustrationName);
63-
if (illustrationName.startsWith("Tnt")) {
64-
set = "tnt";
65-
illustrationName = illustrationName.replace(/^Tnt/, "");
66-
}
67-
return registry.get(`${set}/${illustrationName}`);
116+
return registry.get(registryKey);
68117
};
69118

70119
export {

packages/fiori/package-scripts.cjs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
const getScripts = require("@ui5/webcomponents-tools/components-package/nps.js");
22

3+
const filterOut = [
4+
"sapIllus-Dot",
5+
"sapIllus-Dialog",
6+
"sapIllus-Scene",
7+
"sapIllus-Spot",
8+
"tnt-Dot",
9+
"tnt-Dialog",
10+
"tnt-Scene",
11+
"tnt-Spot",
12+
"AllIllustrations",
13+
];
14+
315
const options = {
416
port: 8081,
517
portStep: 2,
@@ -11,14 +23,56 @@ const options = {
1123
defaultText: true,
1224
illustrationsPrefix: "sapIllus",
1325
set: "fiori",
26+
collection: "V4",
1427
destinationPath: "dist/illustrations",
28+
dynamicImports: {
29+
outputFile: "dist/generated/js-imports/Illustrations.js",
30+
location: '../../illustrations',
31+
prefix: "",
32+
filterOut
33+
}
1534
},
1635
{
1736
path: "src/illustrations/tnt",
1837
defaultText: false,
1938
illustrationsPrefix: "tnt",
2039
set: "tnt",
40+
collection: "V4",
2141
destinationPath: "dist/illustrations/tnt",
42+
dynamicImports: {
43+
outputFile: "dist/generated/js-imports/IllustrationsTNT.js",
44+
location: '../../illustrations/tnt',
45+
prefix: "Tnt",
46+
filterOut
47+
}
48+
},
49+
{
50+
path: "src/illustrations-v5/tnt",
51+
defaultText: false,
52+
illustrationsPrefix: "tnt",
53+
set: "tnt",
54+
collection: "V5",
55+
destinationPath: "dist/illustrations-v5/tnt",
56+
dynamicImports: {
57+
outputFile: "dist/generated/js-imports/IllustrationsV5TNT.js",
58+
location: '../../illustrations-v5/tnt',
59+
prefix: "Tnt",
60+
filterOut
61+
}
62+
},
63+
{
64+
path: "src/illustrations-v5/tnt/hc",
65+
defaultText: false,
66+
illustrationsPrefix: "tnt",
67+
set: "tnt",
68+
collection: "V5/HC",
69+
destinationPath: "dist/illustrations-v5/tnt/hc",
70+
dynamicImports: {
71+
outputFile: "dist/generated/js-imports/IllustrationsV5TNTHC.js",
72+
location: '../../illustrations-v5/tnt/hc',
73+
prefix: "Tnt",
74+
filterOut
75+
}
2276
},
2377
]
2478
};

packages/fiori/src/IllustratedMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import IllustratedMessageTemplate from "./generated/templates/IllustratedMessage
7171
@customElement({
7272
tag: "ui5-illustrated-message",
7373
languageAware: true,
74+
themeAware: true,
7475
renderer: litRender,
7576
styles: IllustratedMessageCss,
7677
template: IllustratedMessageTemplate,
Lines changed: 14 additions & 0 deletions
Loading
Lines changed: 13 additions & 0 deletions
Loading
Lines changed: 21 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)