Skip to content

Commit ee4a8e1

Browse files
committed
Merge branch 'v14/feature/allow-dynamic-import-of-icon' into v14/chore/bundle-core-package
2 parents e64f572 + e1a319a commit ee4a8e1

File tree

631 files changed

+2524
-2523
lines changed

Some content is hidden

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

631 files changed

+2524
-2523
lines changed

devops/icons/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const collectDictionaryIcons = async () => {
4646
legacy: iconDef.legacy,
4747
fileName: iconFileName,
4848
svg,
49-
output: `${iconsOutputDirectory}/${iconFileName}.js`,
49+
output: `${iconsOutputDirectory}/${iconFileName}.ts`,
5050
};
5151

5252
icons.push(icon);
@@ -77,7 +77,7 @@ const collectDictionaryIcons = async () => {
7777
legacy: iconDef.legacy,
7878
fileName: iconFileName,
7979
svg,
80-
output: `${iconsOutputDirectory}/${iconFileName}.js`,
80+
output: `${iconsOutputDirectory}/${iconFileName}.ts`,
8181
};
8282

8383
icons.push(icon);
@@ -102,7 +102,7 @@ const collectDictionaryIcons = async () => {
102102
legacy: iconDef.legacy,
103103
fileName: iconFileName,
104104
svg,
105-
output: `${iconsOutputDirectory}/${iconFileName}.js`,
105+
output: `${iconsOutputDirectory}/${iconFileName}.ts`,
106106
};
107107

108108
icons.push(icon);
@@ -141,7 +141,7 @@ const collectDiskIcons = async (icons) => {
141141
legacy: true,
142142
fileName: iconFileName,
143143
svg,
144-
output: `${iconsOutputDirectory}/${iconFileName}.js`,
144+
output: `${iconsOutputDirectory}/${iconFileName}.ts`,
145145
};
146146

147147
icons.push(icon);
@@ -168,13 +168,13 @@ const writeIconsToDisk = (icons) => {
168168
};
169169

170170
const generateJS = (icons) => {
171-
const JSPath = `${iconsOutputDirectory}/icons.ts`;
171+
const JSPath = `${moduleDirectory}/icons.ts`;
172172

173173
const iconDescriptors = icons.map((icon) => {
174174
return `{
175175
name: "${icon.name}",
176176
${icon.legacy ? 'legacy: true,' : ''}
177-
path: "./icons/${icon.fileName}.js",
177+
path: () => import("./icons/${icon.fileName}.js"),
178178
}`.replace(/\t/g, ''); // Regex removes white space [NL]
179179
});
180180

src/libs/extension-api/functions/load-manifest-plain-js.function.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import type { JsLoaderProperty } from '../types/utils.js';
22

3-
export async function loadManifestPlainJs<JsType extends object>(
4-
property: JsLoaderProperty<JsType>,
5-
): Promise<JsType | undefined> {
3+
export async function loadManifestPlainJs<JsType>(property: JsLoaderProperty<JsType>): Promise<JsType | undefined> {
64
const propType = typeof property;
75
if (propType === 'function') {
86
// Promise function

src/packages/core/icon-registry/icon.registry.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1+
import type { UmbIconDefinition, UmbIconModule } from './types.js';
2+
import { loadManifestPlainJs } from '@umbraco-cms/backoffice/extension-api';
13
import { type UUIIconHost, UUIIconRegistry } from '@umbraco-cms/backoffice/external/uui';
24

3-
interface UmbIconDescriptor {
4-
name: string;
5-
path: string;
6-
}
7-
85
/**
96
* @export
107
* @class UmbIconRegistry
@@ -17,10 +14,10 @@ export class UmbIconRegistry extends UUIIconRegistry {
1714
this.#initResolve = resolve;
1815
});
1916

20-
#icons: UmbIconDescriptor[] = [];
17+
#icons: UmbIconDefinition[] = [];
2118
#unhandledProviders: Map<string, UUIIconHost> = new Map();
2219

23-
setIcons(icons: UmbIconDescriptor[]) {
20+
setIcons(icons: UmbIconDefinition[]) {
2421
const oldIcons = this.#icons;
2522
this.#icons = icons;
2623
if (this.#initResolve) {
@@ -39,7 +36,7 @@ export class UmbIconRegistry extends UUIIconRegistry {
3936
}
4037
});
4138
}
42-
appendIcons(icons: UmbIconDescriptor[]) {
39+
appendIcons(icons: UmbIconDefinition[]) {
4340
this.#icons = [...this.#icons, ...icons];
4441
}
4542
/**
@@ -56,22 +53,22 @@ export class UmbIconRegistry extends UUIIconRegistry {
5653

5754
async #loadIcon(iconName: string, iconProvider: UUIIconHost): Promise<boolean> {
5855
await this.#init;
59-
const iconManifest = this.#icons.find((i: UmbIconDescriptor) => i.name === iconName);
56+
const iconManifest = this.#icons.find((i: UmbIconDefinition) => i.name === iconName);
6057
// Icon not found, so lets add it to a list of unhandled requests.
6158
if (!iconManifest) {
6259
this.#unhandledProviders.set(iconName, iconProvider);
6360
return false;
6461
}
6562

66-
const iconPath = iconManifest.path;
63+
try {
64+
const iconModule = await loadManifestPlainJs<UmbIconModule>(iconManifest.path);
65+
if (!iconModule) throw new Error(`Failed to load icon ${iconName}`);
66+
if (!iconModule.default) throw new Error(`Icon ${iconName} is missing a default export`);
67+
iconProvider.svg = iconModule.default;
68+
} catch (error: any) {
69+
console.error(`Failed to load icon ${iconName}`, error.message);
70+
}
6771

68-
import(/* @vite-ignore */ iconPath)
69-
.then((iconModule) => {
70-
iconProvider.svg = iconModule.default;
71-
})
72-
.catch((err) => {
73-
console.error(`Failed to load icon ${iconName} on path ${iconPath}`, err.message);
74-
});
7572
return true;
7673
}
7774
}

src/packages/core/icon-registry/icon.stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Meta, Story } from '@storybook/web-components';
2-
import icons from './icons/icons.js';
2+
import icons from './icons.js';
33
import { html, repeat } from '@umbraco-cms/backoffice/external/lit';
44

55
export default {

0 commit comments

Comments
 (0)