@luigi-project/client 2.28.1-dev.202603190049 → 2.28.1-dev.202603191108

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.js CHANGED
@@ -1 +1,158 @@
1
- export class LuigiElement extends HTMLElement{constructor(t){super();const e=!!t&&t.openShadow;this._shadowRoot=this.attachShadow({mode:e?"open":"closed",delegatesFocus:!1}),this.__initialized=!1,this.deferLuigiClientWCInit=!!t&&t.deferLuigiClientWCInit}__postProcess(t,e,i){this.LuigiClient=e,this.context=t;const o=document.createElement("template");o.innerHTML=this.render(t);const s=()=>{if(!this.__initialized){this._shadowRoot.appendChild(o.content.cloneNode(!0)),Reflect.ownKeys(Reflect.getPrototypeOf(this)).forEach(t=>{t.startsWith("$_")&&(this._shadowRoot[t]=this[t].bind(this))});const e=this._shadowRoot.querySelectorAll("[id]");e&&e.forEach(t=>{this["$"+t.getAttribute("id")]=t}),this.afterInit(t),this.__initialized=!0}};if(this.luigiConfig&&this.luigiConfig.styleSources&&this.luigiConfig.styleSources.length>0){let t=this.luigiConfig.styleSources.length;const e=this.luigiConfig.loadStylesSync,o=()=>{t--,t<1&&s()};this.luigiConfig.styleSources.forEach((t,s)=>{const n=document.createElement("link");n.setAttribute("rel","stylesheet"),n.setAttribute("href",i+t),e&&(n.addEventListener("load",o),n.addEventListener("error",o)),this._shadowRoot.appendChild(n)}),e||s()}else s()}afterInit(t){}render(t){return""}update(){}onContextUpdate(t){}querySelector(t){return this._shadowRoot.querySelector(t)}set context(t){this.__lui_ctx=t,this.__initialized&&(this.onContextUpdate(t),this.attributeChangedCallback())}get context(){return this.__lui_ctx}attributeChangedCallback(t,e,i){this.update()}}export function html(t,...e){let i="";return t.forEach((t,o)=>{i+=t,o<e.length&&void 0!==e[o]&&null!==e[o]&&(i+=e[o])}),i.replace(/\$\_/gi,"this.getRootNode().$_")}
1
+ /**
2
+ * @module luigi-element
3
+ */
4
+
5
+ /**
6
+ * Base class for Luigi web component micro frontends.
7
+ * @augments HTMLElement
8
+ * @class
9
+ */
10
+ export class LuigiElement extends HTMLElement {
11
+ constructor(options) {
12
+ super();
13
+ const openShadow = options ? options.openShadow : false;
14
+ this._shadowRoot = this.attachShadow({
15
+ mode: openShadow ? 'open' : 'closed',
16
+ delegatesFocus: false
17
+ });
18
+ this.__initialized = false;
19
+ this.deferLuigiClientWCInit = options ? options.deferLuigiClientWCInit : false;
20
+ }
21
+
22
+ /**
23
+ * Invoked by luigi core if present, internal, don't override.
24
+ * @private
25
+ */
26
+ __postProcess(ctx, luigiClient, module_location_path) {
27
+ this.LuigiClient = luigiClient;
28
+ this.context = ctx;
29
+ const template = document.createElement('template');
30
+ template.innerHTML = this.render(ctx);
31
+ const attCnt = () => {
32
+ if (!this.__initialized) {
33
+ this._shadowRoot.appendChild(template.content.cloneNode(true));
34
+ Reflect.ownKeys(Reflect.getPrototypeOf(this)).forEach((el) => {
35
+ if (el.startsWith('$_')) {
36
+ this._shadowRoot[el] = this[el].bind(this);
37
+ }
38
+ });
39
+ const elementsWithIds = this._shadowRoot.querySelectorAll('[id]');
40
+ if (elementsWithIds) {
41
+ elementsWithIds.forEach((el) => {
42
+ this['$' + el.getAttribute('id')] = el;
43
+ });
44
+ }
45
+ this.afterInit(ctx);
46
+ this.__initialized = true;
47
+ }
48
+ };
49
+ if (this.luigiConfig && this.luigiConfig.styleSources && this.luigiConfig.styleSources.length > 0) {
50
+ let nr_styles = this.luigiConfig.styleSources.length;
51
+ const loadStylesSync = this.luigiConfig.loadStylesSync;
52
+ const afterLoadOrError = () => {
53
+ nr_styles--;
54
+ if (nr_styles < 1) {
55
+ attCnt();
56
+ }
57
+ };
58
+
59
+ this.luigiConfig.styleSources.forEach((element, index) => {
60
+ const link = document.createElement('link');
61
+ link.setAttribute('rel', 'stylesheet');
62
+ link.setAttribute('href', module_location_path + element);
63
+ if (loadStylesSync) {
64
+ link.addEventListener('load', afterLoadOrError);
65
+ link.addEventListener('error', afterLoadOrError);
66
+ }
67
+ this._shadowRoot.appendChild(link);
68
+ });
69
+ if (!loadStylesSync) {
70
+ attCnt();
71
+ }
72
+ } else {
73
+ attCnt();
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Override to execute logic after initialization of the web component, i.e.
79
+ * after internal rendering and all context data set.
80
+ * @param {any} ctx - the context object passed by luigi core
81
+ */
82
+ afterInit(ctx) {
83
+ return;
84
+ }
85
+
86
+ /**
87
+ * Override to return the html template string defining the web component view.
88
+ * @param {any} ctx - the context object passed by luigi core
89
+ */
90
+ render(ctx) {
91
+ return '';
92
+ }
93
+
94
+ /**
95
+ * Override to execute logic after an attribute of this web component has changed.
96
+ */
97
+ update() {
98
+ return;
99
+ }
100
+
101
+ /**
102
+ * Override to execute logic when a new context object is set.
103
+ * @param {any} ctx - the new context object passed by luigi core
104
+ */
105
+ onContextUpdate(ctx) {
106
+ return;
107
+ }
108
+
109
+ /**
110
+ * Query selector operating on shadow root.
111
+ * @see ParentNode.querySelector
112
+ */
113
+ querySelector(selector) {
114
+ return this._shadowRoot.querySelector(selector);
115
+ }
116
+
117
+ /**
118
+ * Handles changes on the context property.
119
+ * @private
120
+ */
121
+ set context(ctx) {
122
+ this.__lui_ctx = ctx;
123
+ if (this.__initialized) {
124
+ this.onContextUpdate(ctx);
125
+ this.attributeChangedCallback();
126
+ }
127
+ }
128
+
129
+ get context() {
130
+ return this.__lui_ctx;
131
+ }
132
+
133
+ /**
134
+ * Handles changes on attributes.
135
+ * @private
136
+ */
137
+ attributeChangedCallback(name, oldVal, newVal) {
138
+ this.update();
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Html string processing according to luigi functionality.
144
+ * Also useful in combination with LitElement VS Code plugins.
145
+ * @param {string} literal - the literal to process
146
+ * @param {unknown[]} keys - the array of keys to process
147
+ * @returns {string} the processed literal
148
+ */
149
+ export function html(literal, ...keys) {
150
+ let html = '';
151
+ literal.forEach((el, index) => {
152
+ html += el;
153
+ if (index < keys.length && keys[index] !== undefined && keys[index] !== null) {
154
+ html += keys[index];
155
+ }
156
+ });
157
+ return html.replace(/\$\_/gi, 'this.getRootNode().$_');
158
+ }
package/package.json CHANGED
@@ -2,7 +2,27 @@
2
2
  "name": "@luigi-project/client",
3
3
  "description": "Javascript library supporting consumers of the Luigi framework",
4
4
  "license": "Apache-2.0",
5
- "main": "luigi-client.js",
5
+ "main": "./luigi-client.js",
6
+ "exports": {
7
+ ".": {
8
+ "types": {
9
+ "import": "./esm/luigi-client.d.mts",
10
+ "require": "./luigi-client.d.ts"
11
+ },
12
+ "import": "./esm/luigi-client.mjs",
13
+ "require": "./luigi-client.js"
14
+ },
15
+ "./luigi-client": {
16
+ "types": {
17
+ "import": "./esm/luigi-client.d.mts",
18
+ "require": "./luigi-client.d.ts"
19
+ },
20
+ "import": "./esm/luigi-client.mjs",
21
+ "require": "./luigi-client.js"
22
+ },
23
+ "./luigi-element": "./luigi-element.js",
24
+ "./*": "./*"
25
+ },
6
26
  "repository": {
7
27
  "type": "git",
8
28
  "url": "ssh://github.com/luigi-project/luigi.git"
@@ -17,5 +37,5 @@
17
37
  "micro-frontends",
18
38
  "microfrontends"
19
39
  ],
20
- "version": "2.28.1-dev.202603190049"
40
+ "version": "2.28.1-dev.202603191108"
21
41
  }