@node-projects/web-component-designer 0.0.289 → 0.0.290
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.
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@shoelace-style/shoelace": {
|
|
3
|
+
"html": "<link rel=\"stylesheet\" media=\"(prefers-color-scheme:light)\" href=\"${baseUrl}dist/themes/light.css\">\n<link rel=\"stylesheet\" media=\"(prefers-color-scheme:dark)\" href=\"${baseUrl}dist/themes/dark.css\" onload=\"document.documentElement.classList.add('sl-theme-dark');\">"
|
|
4
|
+
},
|
|
5
|
+
"@microsoft/fast-components": {
|
|
6
|
+
"script": "let res = await import('@microsoft/fast-components');\nres.provideFASTDesignSystem().register(res.allComponents);"
|
|
7
|
+
},
|
|
8
|
+
"@material/web": {
|
|
9
|
+
"import": "@material/web/all.js"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -6,7 +6,9 @@ export declare class NpmPackageLoader {
|
|
|
6
6
|
private _dependecies;
|
|
7
7
|
constructor(packageSource?: string);
|
|
8
8
|
static patchCustomElementsRegistryToHandleErrors(): void;
|
|
9
|
-
loadNpmPackage(pkg: string, serviceContainer?: ServiceContainer, paletteTree?: PaletteTreeView, loadAllImports?: boolean, reportState?: (state: string) => void): Promise<
|
|
9
|
+
loadNpmPackage(pkg: string, serviceContainer?: ServiceContainer, paletteTree?: PaletteTreeView, loadAllImports?: boolean, reportState?: (state: string) => void): Promise<{
|
|
10
|
+
html: string;
|
|
11
|
+
}>;
|
|
10
12
|
loadDependency(dependency: string, version?: string, reportState?: (state: string) => void): Promise<void>;
|
|
11
13
|
addToImportmap(baseUrl: string, packageJsonObj: {
|
|
12
14
|
name?: string;
|
|
@@ -2,6 +2,19 @@ import { PreDefinedElementsService } from "../services/elementsService/PreDefine
|
|
|
2
2
|
import { WebcomponentManifestElementsService } from "../services/elementsService/WebcomponentManifestElementsService.js";
|
|
3
3
|
import { WebcomponentManifestPropertiesService } from "../services/propertiesService/services/WebcomponentManifestPropertiesService.js";
|
|
4
4
|
import { removeLeading, removeTrailing } from "./Helper.js";
|
|
5
|
+
//TODO: remove this code when import asserts are supported
|
|
6
|
+
let packageHacks;
|
|
7
|
+
//@ts-ignore
|
|
8
|
+
if (window.importShim) {
|
|
9
|
+
const packageHacksUrl = import.meta.resolve('./NpmPackageHacks.json');
|
|
10
|
+
//@ts-ignore
|
|
11
|
+
packageHacks = await importShim(packageHacksUrl, { assert: { type: 'json' } });
|
|
12
|
+
}
|
|
13
|
+
else
|
|
14
|
+
//@ts-ignore
|
|
15
|
+
packageHacks = await import("./NpmPackageHacks.json", { assert: { type: 'json' } });
|
|
16
|
+
if (packageHacks.default)
|
|
17
|
+
packageHacks = packageHacks.default;
|
|
5
18
|
export class NpmPackageLoader {
|
|
6
19
|
static registryPatchedTohandleErrors;
|
|
7
20
|
//packageSource = '//unpkg.com/';
|
|
@@ -121,24 +134,32 @@ export class NpmPackageLoader {
|
|
|
121
134
|
//todo: should be retriggered by service container, or changeing list in container
|
|
122
135
|
paletteTree.loadControls(serviceContainer, serviceContainer.elementsServices);
|
|
123
136
|
}
|
|
137
|
+
/* Package Hacks */
|
|
138
|
+
if (packageHacks[pkg]?.import) {
|
|
139
|
+
import(packageHacks[pkg]?.import);
|
|
140
|
+
}
|
|
141
|
+
if (packageHacks[pkg]?.script) {
|
|
142
|
+
const scriptUrl = URL.createObjectURL(new Blob([packageHacks[pkg]?.script], { type: 'application/javascript' }));
|
|
143
|
+
import(scriptUrl);
|
|
144
|
+
}
|
|
124
145
|
}
|
|
125
146
|
else {
|
|
126
147
|
console.warn('npm package: ' + pkg + ' - no custom-elements.json found, only loading javascript module');
|
|
127
|
-
let
|
|
148
|
+
let originalCustomElementsRegistry = window.customElements;
|
|
128
149
|
const registry = {};
|
|
129
150
|
const newElements = [];
|
|
130
151
|
registry.define = function (name, constructor, options) {
|
|
131
152
|
newElements.push(name);
|
|
132
|
-
|
|
153
|
+
originalCustomElementsRegistry.define(name, constructor, options);
|
|
133
154
|
};
|
|
134
155
|
registry.get = function (name) {
|
|
135
|
-
return
|
|
156
|
+
return originalCustomElementsRegistry.get(name);
|
|
136
157
|
};
|
|
137
158
|
registry.upgrade = function (node) {
|
|
138
|
-
return
|
|
159
|
+
return originalCustomElementsRegistry.upgrade(node);
|
|
139
160
|
};
|
|
140
161
|
registry.whenDefined = function (name) {
|
|
141
|
-
return
|
|
162
|
+
return originalCustomElementsRegistry.whenDefined(name);
|
|
142
163
|
};
|
|
143
164
|
Object.defineProperty(window, "customElements", {
|
|
144
165
|
get() {
|
|
@@ -160,6 +181,14 @@ export class NpmPackageLoader {
|
|
|
160
181
|
else {
|
|
161
182
|
console.warn('npm package: ' + pkg + ' - no entry point in package found.');
|
|
162
183
|
}
|
|
184
|
+
/* Package Hacks */
|
|
185
|
+
if (packageHacks[pkg]?.import) {
|
|
186
|
+
await import(packageHacks[pkg]?.import);
|
|
187
|
+
}
|
|
188
|
+
if (packageHacks[pkg]?.script) {
|
|
189
|
+
const scriptUrl = URL.createObjectURL(new Blob([packageHacks[pkg]?.script], { type: 'application/javascript' }));
|
|
190
|
+
await import(scriptUrl);
|
|
191
|
+
}
|
|
163
192
|
if (newElements.length > 0 && serviceContainer && paletteTree) {
|
|
164
193
|
const elementsCfg = {
|
|
165
194
|
elements: newElements
|
|
@@ -170,12 +199,17 @@ export class NpmPackageLoader {
|
|
|
170
199
|
}
|
|
171
200
|
Object.defineProperty(window, "customElements", {
|
|
172
201
|
get() {
|
|
173
|
-
return
|
|
202
|
+
return originalCustomElementsRegistry;
|
|
174
203
|
}
|
|
175
204
|
});
|
|
176
205
|
}
|
|
177
206
|
if (reportState)
|
|
178
207
|
reportState(pkg + ": done");
|
|
208
|
+
let retVal = {};
|
|
209
|
+
if (packageHacks[pkg]?.html) {
|
|
210
|
+
retVal.html = (packageHacks[pkg]?.html).replaceAll("${baseUrl}", baseUrl);
|
|
211
|
+
}
|
|
212
|
+
return retVal;
|
|
179
213
|
}
|
|
180
214
|
async loadDependency(dependency, version, reportState) {
|
|
181
215
|
if (this._dependecies.has(dependency))
|
|
@@ -295,10 +329,10 @@ export class NpmPackageLoader {
|
|
|
295
329
|
//Names to use: browser, import, default, node
|
|
296
330
|
let imp = getImportFlat(packageJsonObj.exports);
|
|
297
331
|
if (imp) {
|
|
298
|
-
importMap.imports[packageJsonObj.name] = baseUrl + removeLeading(
|
|
332
|
+
importMap.imports[packageJsonObj.name] = baseUrl + removeLeading(removeLeading(imp, '.'), '/');
|
|
299
333
|
}
|
|
300
334
|
else if (imp = getImportFlat(packageJsonObj.exports?.['.'])) {
|
|
301
|
-
importMap.imports[packageJsonObj.name] = baseUrl + removeLeading(
|
|
335
|
+
importMap.imports[packageJsonObj.name] = baseUrl + removeLeading(removeLeading(imp, '.'), '/');
|
|
302
336
|
}
|
|
303
337
|
}
|
|
304
338
|
let mainImport = packageJsonObj.main;
|
|
@@ -308,7 +342,7 @@ export class NpmPackageLoader {
|
|
|
308
342
|
mainImport = packageJsonObj.unpkg;
|
|
309
343
|
if (!importMap.imports[packageJsonObj.name]) {
|
|
310
344
|
if (mainImport)
|
|
311
|
-
importMap.imports[packageJsonObj.name] = baseUrl +
|
|
345
|
+
importMap.imports[packageJsonObj.name] = baseUrl + removeLeading(removeLeading(mainImport, '.'), '/');
|
|
312
346
|
else
|
|
313
347
|
console.warn('package: ' + baseUrl + 'no main import found');
|
|
314
348
|
}
|