@luigi-project/client 2.32.1-dev.202610210048 → 2.32.1-dev.202610220048
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/luigi-element.d.ts +20 -0
- package/luigi-element.js +26 -0
- package/package.json +1 -1
package/luigi-element.d.ts
CHANGED
|
@@ -499,6 +499,26 @@ export declare interface Options {
|
|
|
499
499
|
*/
|
|
500
500
|
export declare const html: (strings: TemplateStringsArray, ...keys: unknown[]) => string;
|
|
501
501
|
|
|
502
|
+
/**
|
|
503
|
+
* Registers a web component that the micro frontend bundle defines itself, making it
|
|
504
|
+
* available to Luigi as a web component micro frontend. Use this when your bundle builds
|
|
505
|
+
* and owns its own custom element class (for example Angular Elements) instead of relying
|
|
506
|
+
* on Luigi to define the element for you.
|
|
507
|
+
*
|
|
508
|
+
* The Luigi Core application must be present on the page. If it is not, an error is logged
|
|
509
|
+
* and the call is a no-op.
|
|
510
|
+
* @param {string} srcString the URL of the web component bundle, which must resolve to the same URL Luigi uses for the node (the node's `viewUrl`). Luigi hex-encodes the resolved absolute URL to derive the custom element id (`luigi-wc-<encoded-url>`) the component is registered under; if `srcString` resolves to a different URL, Luigi registers and looks the element up under different ids and the component never renders. From the bundle registering itself, pass `import.meta.url` (ES module) or `document.currentScript?.src` (classic script), depending on how the bundle is loaded.
|
|
511
|
+
* @param {HTMLElement} element the web component class (custom element constructor) to register
|
|
512
|
+
* @since NEXTRELEASE
|
|
513
|
+
* @example
|
|
514
|
+
* import { registerWebComponent } from '@luigi-project/client/luigi-element.js';
|
|
515
|
+
*
|
|
516
|
+
* export class MyComponent extends LuigiElement { \/* ... *\/ }
|
|
517
|
+
*
|
|
518
|
+
* registerWebComponent(import.meta.url, MyComponent);
|
|
519
|
+
*/
|
|
520
|
+
export declare function registerWebComponent(srcString: string, element: HTMLElement): void;
|
|
521
|
+
|
|
502
522
|
export interface LuigiClient {
|
|
503
523
|
/**
|
|
504
524
|
* @returns {Object} node parameters, where the object property name is the node parameter name without the prefix, and its value is the value of the node parameter. For example `{sort: 'asc', page: 3}`
|
package/luigi-element.js
CHANGED
|
@@ -156,3 +156,29 @@ export function html(literal, ...keys) {
|
|
|
156
156
|
});
|
|
157
157
|
return html.replace(/\$\_/gi, 'this.getRootNode().$_');
|
|
158
158
|
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Registers a web component that the micro frontend bundle defines itself, making it
|
|
162
|
+
* available to Luigi as a web component micro frontend. Use this when your bundle builds
|
|
163
|
+
* and owns its own custom element class (for example Angular Elements) instead of relying
|
|
164
|
+
* on Luigi to define the element for you.
|
|
165
|
+
*
|
|
166
|
+
* The Luigi Core application must be present on the page. If it is not, an error is logged
|
|
167
|
+
* and the call is a no-op.
|
|
168
|
+
* @param {string} srcString the URL of the web component bundle, which must resolve to the same URL Luigi uses for the node (the node's `viewUrl`). Luigi hex-encodes the resolved absolute URL to derive the custom element id (`luigi-wc-<encoded-url>`) the component is registered under; if `srcString` resolves to a different URL, Luigi registers and looks the element up under different ids and the component never renders. From the bundle registering itself, pass `import.meta.url` (ES module) or `document.currentScript?.src` (classic script), depending on how the bundle is loaded.
|
|
169
|
+
* @param {HTMLElement} element the web component class (custom element constructor) to register
|
|
170
|
+
* @since NEXTRELEASE
|
|
171
|
+
* @example
|
|
172
|
+
* import { registerWebComponent } from '@luigi-project/client/luigi-element.js';
|
|
173
|
+
*
|
|
174
|
+
* export class MyComponent extends LuigiElement { \/* ... *\/ }
|
|
175
|
+
*
|
|
176
|
+
* registerWebComponent(import.meta.url, MyComponent);
|
|
177
|
+
*/
|
|
178
|
+
export function registerWebComponent(srcString, element) {
|
|
179
|
+
if (!window.Luigi) {
|
|
180
|
+
console.error('Error registering web component, Luigi core app not present.');
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
window.Luigi._registerWebcomponent(srcString, element);
|
|
184
|
+
}
|
package/package.json
CHANGED