@luigi-project/container 0.0.1 → 0.0.3
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/README.md +4 -0
- package/bundle.d.ts +1050 -0
- package/bundle.d.ts.map +1 -0
- package/bundle.js +2 -1472
- package/bundle.js.map +1 -1
- package/package.json +2 -1
package/bundle.d.ts
ADDED
|
@@ -0,0 +1,1050 @@
|
|
|
1
|
+
import { SvelteElement, init, attribute_to_object, safe_not_equal, insert, flush, empty, detach, element, noop, attr, get_current_component, src_url_equal, binding_callbacks } from 'svelte/internal';
|
|
2
|
+
import { onMount, onDestroy } from 'svelte';
|
|
3
|
+
|
|
4
|
+
var ContainerService = /** @class */ (function () {
|
|
5
|
+
function ContainerService() {
|
|
6
|
+
}
|
|
7
|
+
ContainerService.prototype.isVisible = function (component) {
|
|
8
|
+
return !!(component.offsetWidth || component.offsetHeight || component.getClientRects().length);
|
|
9
|
+
};
|
|
10
|
+
ContainerService.prototype.dispatch = function (msg, targetCnt, data, callback) {
|
|
11
|
+
var ev = new CustomEvent(msg, { detail: data });
|
|
12
|
+
ev.luigiCallback = function (data) {
|
|
13
|
+
if (callback) {
|
|
14
|
+
callback(data);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
targetCnt.dispatchEvent(ev);
|
|
18
|
+
console.log('Dispatch WC event:', msg, targetCnt, data);
|
|
19
|
+
};
|
|
20
|
+
ContainerService.prototype.getTargetContainer = function (event) {
|
|
21
|
+
var cnt;
|
|
22
|
+
globalThis.__luigi_container_manager.container.forEach(function (element) {
|
|
23
|
+
var _a;
|
|
24
|
+
if (((_a = element.iframeHandle) === null || _a === void 0 ? void 0 : _a.iframe) && element.iframeHandle.iframe.contentWindow === event.source) {
|
|
25
|
+
cnt = element;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return cnt;
|
|
29
|
+
};
|
|
30
|
+
ContainerService.prototype.getContainerManager = function () {
|
|
31
|
+
var _this = this;
|
|
32
|
+
if (!globalThis.__luigi_container_manager) {
|
|
33
|
+
globalThis.__luigi_container_manager = {
|
|
34
|
+
container: [],
|
|
35
|
+
messageListener: function (event) {
|
|
36
|
+
var _a, _b, _c, _d;
|
|
37
|
+
var targetCnt = _this.getTargetContainer(event);
|
|
38
|
+
var target = (_b = (_a = targetCnt === null || targetCnt === void 0 ? void 0 : targetCnt.iframeHandle) === null || _a === void 0 ? void 0 : _a.iframe) === null || _b === void 0 ? void 0 : _b.contentWindow;
|
|
39
|
+
console.log('Container event', event, targetCnt);
|
|
40
|
+
if (target === event.source && ((_d = (_c = event.data) === null || _c === void 0 ? void 0 : _c.msg) === null || _d === void 0 ? void 0 : _d.indexOf('luigi.')) === 0) {
|
|
41
|
+
var msg = event.data.msg;
|
|
42
|
+
switch (msg) {
|
|
43
|
+
case 'luigi.get-context':
|
|
44
|
+
target.postMessage({ msg: 'luigi.init', context: targetCnt.context, internal: {} }, '*');
|
|
45
|
+
break;
|
|
46
|
+
case 'luigi.navigation.open':
|
|
47
|
+
_this.dispatch('navigation-request', targetCnt, event.data.params);
|
|
48
|
+
break;
|
|
49
|
+
case 'luigi.ux.alert.show':
|
|
50
|
+
_this.dispatch('alert-request', targetCnt, event.data.params);
|
|
51
|
+
break;
|
|
52
|
+
default:
|
|
53
|
+
console.warn('Functionality not yet implemented: ', msg);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
window.addEventListener('message', globalThis.__luigi_container_manager.messageListener);
|
|
60
|
+
}
|
|
61
|
+
return globalThis.__luigi_container_manager;
|
|
62
|
+
};
|
|
63
|
+
ContainerService.prototype.registerContainer = function (container) {
|
|
64
|
+
this.getContainerManager().container.push(container);
|
|
65
|
+
};
|
|
66
|
+
return ContainerService;
|
|
67
|
+
}());
|
|
68
|
+
|
|
69
|
+
/*! *****************************************************************************
|
|
70
|
+
Copyright (c) Microsoft Corporation.
|
|
71
|
+
|
|
72
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
73
|
+
purpose with or without fee is hereby granted.
|
|
74
|
+
|
|
75
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
76
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
77
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
78
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
79
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
80
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
81
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
82
|
+
***************************************************************************** */
|
|
83
|
+
/* global Reflect, Promise */
|
|
84
|
+
|
|
85
|
+
var extendStatics = function(d, b) {
|
|
86
|
+
extendStatics = Object.setPrototypeOf ||
|
|
87
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
88
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
89
|
+
return extendStatics(d, b);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
function __extends(d, b) {
|
|
93
|
+
if (typeof b !== "function" && b !== null)
|
|
94
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
95
|
+
extendStatics(d, b);
|
|
96
|
+
function __() { this.constructor = d; }
|
|
97
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
var __assign = function() {
|
|
101
|
+
__assign = Object.assign || function __assign(t) {
|
|
102
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
103
|
+
s = arguments[i];
|
|
104
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
105
|
+
}
|
|
106
|
+
return t;
|
|
107
|
+
};
|
|
108
|
+
return __assign.apply(this, arguments);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
112
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
113
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
114
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
115
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
116
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
117
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function __generator(thisArg, body) {
|
|
122
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
123
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
124
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
125
|
+
function step(op) {
|
|
126
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
127
|
+
while (_) try {
|
|
128
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
129
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
130
|
+
switch (op[0]) {
|
|
131
|
+
case 0: case 1: t = op; break;
|
|
132
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
133
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
134
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
135
|
+
default:
|
|
136
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
137
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
138
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
139
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
140
|
+
if (t[2]) _.ops.pop();
|
|
141
|
+
_.trys.pop(); continue;
|
|
142
|
+
}
|
|
143
|
+
op = body.call(thisArg, _);
|
|
144
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
145
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Default compound renderer.
|
|
151
|
+
*/
|
|
152
|
+
var DefaultCompoundRenderer = /** @class */ (function () {
|
|
153
|
+
function DefaultCompoundRenderer(rendererObj) {
|
|
154
|
+
if (rendererObj) {
|
|
155
|
+
this.rendererObject = rendererObj;
|
|
156
|
+
this.config = rendererObj.config || {};
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
this.config = {};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
DefaultCompoundRenderer.prototype.createCompoundContainer = function () {
|
|
163
|
+
return document.createElement('div');
|
|
164
|
+
};
|
|
165
|
+
DefaultCompoundRenderer.prototype.createCompoundItemContainer = function (layoutConfig) {
|
|
166
|
+
return document.createElement('div');
|
|
167
|
+
};
|
|
168
|
+
DefaultCompoundRenderer.prototype.attachCompoundItem = function (compoundCnt, compoundItemCnt) {
|
|
169
|
+
compoundCnt.appendChild(compoundItemCnt);
|
|
170
|
+
};
|
|
171
|
+
return DefaultCompoundRenderer;
|
|
172
|
+
}());
|
|
173
|
+
/**
|
|
174
|
+
* Compound Renderer for custom rendering as defined in luigi config.
|
|
175
|
+
*/
|
|
176
|
+
var CustomCompoundRenderer = /** @class */ (function (_super) {
|
|
177
|
+
__extends(CustomCompoundRenderer, _super);
|
|
178
|
+
function CustomCompoundRenderer(rendererObj) {
|
|
179
|
+
var _this = _super.call(this, rendererObj || { use: {} }) || this;
|
|
180
|
+
if (rendererObj && rendererObj.use && rendererObj.use.extends) {
|
|
181
|
+
_this.superRenderer = resolveRenderer({
|
|
182
|
+
use: rendererObj.use.extends,
|
|
183
|
+
config: rendererObj.config
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return _this;
|
|
187
|
+
}
|
|
188
|
+
CustomCompoundRenderer.prototype.createCompoundContainer = function () {
|
|
189
|
+
if (this.rendererObject.use.createCompoundContainer) {
|
|
190
|
+
return this.rendererObject.use.createCompoundContainer(this.config, this.superRenderer);
|
|
191
|
+
}
|
|
192
|
+
else if (this.superRenderer) {
|
|
193
|
+
return this.superRenderer.createCompoundContainer();
|
|
194
|
+
}
|
|
195
|
+
return _super.prototype.createCompoundContainer.call(this);
|
|
196
|
+
};
|
|
197
|
+
CustomCompoundRenderer.prototype.createCompoundItemContainer = function (layoutConfig) {
|
|
198
|
+
if (this.rendererObject.use.createCompoundItemContainer) {
|
|
199
|
+
return this.rendererObject.use.createCompoundItemContainer(layoutConfig, this.config, this.superRenderer);
|
|
200
|
+
}
|
|
201
|
+
else if (this.superRenderer) {
|
|
202
|
+
return this.superRenderer.createCompoundItemContainer(layoutConfig);
|
|
203
|
+
}
|
|
204
|
+
return _super.prototype.createCompoundItemContainer.call(this, layoutConfig);
|
|
205
|
+
};
|
|
206
|
+
CustomCompoundRenderer.prototype.attachCompoundItem = function (compoundCnt, compoundItemCnt) {
|
|
207
|
+
if (this.rendererObject.use.attachCompoundItem) {
|
|
208
|
+
this.rendererObject.use.attachCompoundItem(compoundCnt, compoundItemCnt, this.superRenderer);
|
|
209
|
+
}
|
|
210
|
+
else if (this.superRenderer) {
|
|
211
|
+
this.superRenderer.attachCompoundItem(compoundCnt, compoundItemCnt);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
_super.prototype.attachCompoundItem.call(this, compoundCnt, compoundItemCnt);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
return CustomCompoundRenderer;
|
|
218
|
+
}(DefaultCompoundRenderer));
|
|
219
|
+
/**
|
|
220
|
+
* Compound Renderer for a css grid compound view.
|
|
221
|
+
*/
|
|
222
|
+
var GridCompoundRenderer = /** @class */ (function (_super) {
|
|
223
|
+
__extends(GridCompoundRenderer, _super);
|
|
224
|
+
function GridCompoundRenderer() {
|
|
225
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
226
|
+
}
|
|
227
|
+
GridCompoundRenderer.prototype.createCompoundContainer = function () {
|
|
228
|
+
var containerClass = '__lui_compound_' + new Date().getTime();
|
|
229
|
+
var compoundCnt = document.createElement('div');
|
|
230
|
+
compoundCnt.classList.add(containerClass);
|
|
231
|
+
var mediaQueries = '';
|
|
232
|
+
if (this.config.layouts) {
|
|
233
|
+
this.config.layouts.forEach(function (el) {
|
|
234
|
+
if (el.minWidth || el.maxWidth) {
|
|
235
|
+
var mq = '@media only screen ';
|
|
236
|
+
if (el.minWidth != null) {
|
|
237
|
+
mq += "and (min-width: ".concat(el.minWidth, "px) ");
|
|
238
|
+
}
|
|
239
|
+
if (el.maxWidth != null) {
|
|
240
|
+
mq += "and (max-width: ".concat(el.maxWidth, "px) ");
|
|
241
|
+
}
|
|
242
|
+
mq += "{\n .".concat(containerClass, " {\n grid-template-columns: ").concat(el.columns || 'auto', ";\n grid-template-rows: ").concat(el.rows || 'auto', ";\n grid-gap: ").concat(el.gap || '0', ";\n }\n }\n ");
|
|
243
|
+
mediaQueries += mq;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
compoundCnt.innerHTML = /*html*/ "\n <style scoped>\n .".concat(containerClass, " {\n display: grid;\n grid-template-columns: ").concat(this.config.columns || 'auto', ";\n grid-template-rows: ").concat(this.config.rows || 'auto', ";\n grid-gap: ").concat(this.config.gap || '0', ";\n min-height: ").concat(this.config.minHeight || 'auto', ";\n }\n ").concat(mediaQueries, "\n </style>\n ");
|
|
248
|
+
return compoundCnt;
|
|
249
|
+
};
|
|
250
|
+
GridCompoundRenderer.prototype.createCompoundItemContainer = function (layoutConfig) {
|
|
251
|
+
var config = layoutConfig || {};
|
|
252
|
+
var compoundItemCnt = document.createElement('div');
|
|
253
|
+
compoundItemCnt.setAttribute('style', "grid-row: ".concat(config.row || 'auto', "; grid-column: ").concat(config.column || 'auto'));
|
|
254
|
+
return compoundItemCnt;
|
|
255
|
+
};
|
|
256
|
+
return GridCompoundRenderer;
|
|
257
|
+
}(DefaultCompoundRenderer));
|
|
258
|
+
/**
|
|
259
|
+
* Returns the compound renderer class for a given config.
|
|
260
|
+
* If no specific one is found, {DefaultCompoundRenderer} is returned.
|
|
261
|
+
*
|
|
262
|
+
* @param {*} rendererConfig the renderer config object defined in luigi config
|
|
263
|
+
*/
|
|
264
|
+
var resolveRenderer = function (rendererConfig) {
|
|
265
|
+
var rendererDef = rendererConfig.use;
|
|
266
|
+
if (!rendererDef) {
|
|
267
|
+
return new DefaultCompoundRenderer(rendererConfig);
|
|
268
|
+
}
|
|
269
|
+
else if (rendererDef === 'grid') {
|
|
270
|
+
return new GridCompoundRenderer(rendererConfig);
|
|
271
|
+
}
|
|
272
|
+
else if (rendererDef.createCompoundContainer ||
|
|
273
|
+
rendererDef.createCompoundItemContainer ||
|
|
274
|
+
rendererDef.attachCompoundItem) {
|
|
275
|
+
return new CustomCompoundRenderer(rendererConfig);
|
|
276
|
+
}
|
|
277
|
+
return new DefaultCompoundRenderer(rendererConfig);
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* Registers event listeners defined at the navNode.
|
|
281
|
+
*
|
|
282
|
+
* @param {*} eventbusListeners a map of event listener arrays with event id as key
|
|
283
|
+
* @param {*} navNode the web component node configuration object
|
|
284
|
+
* @param {*} nodeId the web component node id
|
|
285
|
+
* @param {*} wcElement the web component element - optional
|
|
286
|
+
*/
|
|
287
|
+
var registerEventListeners = function (eventbusListeners, navNode, nodeId, wcElement) {
|
|
288
|
+
if (navNode === null || navNode === void 0 ? void 0 : navNode.eventListeners) {
|
|
289
|
+
navNode.eventListeners.forEach(function (el) {
|
|
290
|
+
var evID = el.source + '.' + el.name;
|
|
291
|
+
var listenerList = eventbusListeners[evID];
|
|
292
|
+
var listenerInfo = {
|
|
293
|
+
wcElementId: nodeId,
|
|
294
|
+
wcElement: wcElement,
|
|
295
|
+
action: el.action,
|
|
296
|
+
converter: el.dataConverter
|
|
297
|
+
};
|
|
298
|
+
if (listenerList) {
|
|
299
|
+
listenerList.push(listenerInfo);
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
eventbusListeners[evID] = [listenerInfo];
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
/** Methods for dealing with web components based micro frontend handling */
|
|
309
|
+
var WebComponentService = /** @class */ (function () {
|
|
310
|
+
function WebComponentService() {
|
|
311
|
+
this.containerService = new ContainerService();
|
|
312
|
+
}
|
|
313
|
+
WebComponentService.prototype.dynamicImport = function (viewUrl) {
|
|
314
|
+
return import(viewUrl);
|
|
315
|
+
};
|
|
316
|
+
WebComponentService.prototype.processViewUrl = function (viewUrl, data) {
|
|
317
|
+
return viewUrl;
|
|
318
|
+
};
|
|
319
|
+
/** Creates a web component with tagname wc_id and adds it to wcItemContainer,
|
|
320
|
+
* if attached to wc_container
|
|
321
|
+
*/
|
|
322
|
+
WebComponentService.prototype.attachWC = function (wc_id, wcItemPlaceholder, wc_container, ctx, viewUrl, nodeId) {
|
|
323
|
+
if (wc_container && wc_container.contains(wcItemPlaceholder)) {
|
|
324
|
+
var wc = document.createElement(wc_id);
|
|
325
|
+
if (nodeId) {
|
|
326
|
+
wc.setAttribute('nodeId', nodeId);
|
|
327
|
+
}
|
|
328
|
+
this.initWC(wc, wc_id, wc_container, viewUrl, ctx, nodeId);
|
|
329
|
+
wc_container.replaceChild(wc, wcItemPlaceholder);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
WebComponentService.prototype.createClientAPI = function (eventBusElement, nodeId, wc_id) {
|
|
333
|
+
var _this = this;
|
|
334
|
+
return {
|
|
335
|
+
linkManager: function () { },
|
|
336
|
+
uxManager: function () {
|
|
337
|
+
return {
|
|
338
|
+
showAlert: function (alertSettings) { },
|
|
339
|
+
showConfirmationModal: function (settings) { return __awaiter(_this, void 0, void 0, function () {
|
|
340
|
+
return __generator(this, function (_a) {
|
|
341
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
342
|
+
resolve(true);
|
|
343
|
+
})];
|
|
344
|
+
});
|
|
345
|
+
}); }
|
|
346
|
+
};
|
|
347
|
+
},
|
|
348
|
+
getCurrentLocale: function () { },
|
|
349
|
+
publishEvent: function (ev) {
|
|
350
|
+
// if (eventBusElement.eventBus) {
|
|
351
|
+
// eventBusElement.eventBus.onPublishEvent(ev, nodeId, wc_id);
|
|
352
|
+
// }
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
WebComponentService.prototype.initWC = function (wc, wc_id, eventBusElement, viewUrl, ctx, nodeId) {
|
|
357
|
+
var clientAPI = this.createClientAPI(eventBusElement, nodeId, wc_id);
|
|
358
|
+
if (wc.__postProcess) {
|
|
359
|
+
var url = new URL(document.baseURI).origin === new URL(viewUrl, document.baseURI).origin // TODO: check if needed
|
|
360
|
+
? new URL('./', new URL(viewUrl, document.baseURI))
|
|
361
|
+
: new URL('./', viewUrl);
|
|
362
|
+
wc.__postProcess(ctx, clientAPI, url.origin + url.pathname);
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
wc.context = ctx;
|
|
366
|
+
wc.LuigiClient = clientAPI;
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
/** Generates a unique web component id (tagname) based on the viewUrl
|
|
370
|
+
* returns a string that can be used as part of a tagname, only alphanumeric
|
|
371
|
+
* characters and no whitespaces.
|
|
372
|
+
*/
|
|
373
|
+
WebComponentService.prototype.generateWCId = function (viewUrl) {
|
|
374
|
+
var charRep = '';
|
|
375
|
+
for (var i = 0; i < viewUrl.length; i++) {
|
|
376
|
+
charRep += viewUrl.charCodeAt(i).toString(16);
|
|
377
|
+
}
|
|
378
|
+
return 'luigi-wc-' + charRep;
|
|
379
|
+
};
|
|
380
|
+
/** Does a module import from viewUrl and defines a new web component
|
|
381
|
+
* with the default export of the module or the first export extending HTMLElement if no default is
|
|
382
|
+
* specified.
|
|
383
|
+
* @returns a promise that gets resolved after successfull import */
|
|
384
|
+
WebComponentService.prototype.registerWCFromUrl = function (viewUrl, wc_id) {
|
|
385
|
+
var _this = this;
|
|
386
|
+
var i18nViewUrl = this.processViewUrl(viewUrl);
|
|
387
|
+
return new Promise(function (resolve, reject) {
|
|
388
|
+
if (_this.checkWCUrl(i18nViewUrl)) {
|
|
389
|
+
_this.dynamicImport(i18nViewUrl)
|
|
390
|
+
.then(function (module) {
|
|
391
|
+
try {
|
|
392
|
+
if (!window.customElements.get(wc_id)) {
|
|
393
|
+
var cmpClazz = module.default;
|
|
394
|
+
if (!HTMLElement.isPrototypeOf(cmpClazz)) {
|
|
395
|
+
var props = Object.keys(module);
|
|
396
|
+
for (var i = 0; i < props.length; i++) {
|
|
397
|
+
cmpClazz = module[props[i]];
|
|
398
|
+
if (HTMLElement.isPrototypeOf(cmpClazz)) {
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
window.customElements.define(wc_id, cmpClazz);
|
|
404
|
+
}
|
|
405
|
+
resolve(1);
|
|
406
|
+
}
|
|
407
|
+
catch (e) {
|
|
408
|
+
reject(e);
|
|
409
|
+
}
|
|
410
|
+
})
|
|
411
|
+
.catch(function (err) { return reject(err); });
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
console.warn("View URL '".concat(i18nViewUrl, "' not allowed to be included"));
|
|
415
|
+
reject("View URL '".concat(i18nViewUrl, "' not allowed"));
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* Handles the import of self registered web component bundles, i.e. the web component
|
|
421
|
+
* is added to the customElements registry by the bundle code rather than by luigi.
|
|
422
|
+
*
|
|
423
|
+
* @param {*} node the corresponding navigation node
|
|
424
|
+
* @param {*} viewUrl the source of the wc bundle
|
|
425
|
+
* @param {*} onload callback function executed after script attached and loaded
|
|
426
|
+
*/
|
|
427
|
+
WebComponentService.prototype.includeSelfRegisteredWCFromUrl = function (node, viewUrl, onload) {
|
|
428
|
+
var _this = this;
|
|
429
|
+
if (this.checkWCUrl(viewUrl)) {
|
|
430
|
+
/** Append reg function to luigi object if not present */
|
|
431
|
+
if (!this.containerService.getContainerManager()._registerWebcomponent) {
|
|
432
|
+
this.containerService.getContainerManager()._registerWebcomponent = function (srcString, el) {
|
|
433
|
+
window.customElements.define(_this.generateWCId(srcString), el);
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
var scriptTag = document.createElement('script');
|
|
437
|
+
scriptTag.setAttribute('src', viewUrl);
|
|
438
|
+
if (node.webcomponent.type === 'module') {
|
|
439
|
+
scriptTag.setAttribute('type', 'module');
|
|
440
|
+
}
|
|
441
|
+
scriptTag.setAttribute('defer', 'true');
|
|
442
|
+
scriptTag.addEventListener('load', function () {
|
|
443
|
+
onload();
|
|
444
|
+
});
|
|
445
|
+
document.body.appendChild(scriptTag);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
console.warn("View URL '".concat(viewUrl, "' not allowed to be included"));
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
/**
|
|
452
|
+
* Checks if a url is allowed to be included, based on 'navigation.validWebcomponentUrls' in luigi config.
|
|
453
|
+
* Returns true, if allowed.
|
|
454
|
+
*
|
|
455
|
+
* @param {*} url the url string to check
|
|
456
|
+
*/
|
|
457
|
+
WebComponentService.prototype.checkWCUrl = function (url) {
|
|
458
|
+
// if (url.indexOf('://') > 0 || url.trim().indexOf('//') === 0) {
|
|
459
|
+
// const ur = new URL(url);
|
|
460
|
+
// if (ur.host === window.location.host) {
|
|
461
|
+
// return true; // same host is okay
|
|
462
|
+
// }
|
|
463
|
+
// const valids = LuigiConfig.getConfigValue('navigation.validWebcomponentUrls');
|
|
464
|
+
// if (valids && valids.length > 0) {
|
|
465
|
+
// for (let el of valids) {
|
|
466
|
+
// try {
|
|
467
|
+
// if (new RegExp(el).test(url)) {
|
|
468
|
+
// return true;
|
|
469
|
+
// }
|
|
470
|
+
// } catch (e) {
|
|
471
|
+
// console.error(e);
|
|
472
|
+
// }
|
|
473
|
+
// }
|
|
474
|
+
// }
|
|
475
|
+
// return false;
|
|
476
|
+
// }
|
|
477
|
+
// relative URL is okay
|
|
478
|
+
return true;
|
|
479
|
+
};
|
|
480
|
+
/** Adds a web component defined by viewUrl to the wc_container and sets the node context.
|
|
481
|
+
* If the web component is not defined yet, it gets imported.
|
|
482
|
+
*/
|
|
483
|
+
WebComponentService.prototype.renderWebComponent = function (viewUrl, wc_container, context, node, nodeId) {
|
|
484
|
+
var _this = this;
|
|
485
|
+
var i18nViewUrl = this.processViewUrl(viewUrl, { context: context });
|
|
486
|
+
var wc_id = node.webcomponent && node.webcomponent.tagName ? node.webcomponent.tagName : this.generateWCId(i18nViewUrl);
|
|
487
|
+
var wcItemPlaceholder = document.createElement('div');
|
|
488
|
+
wc_container.appendChild(wcItemPlaceholder);
|
|
489
|
+
wc_container._luigi_node = node;
|
|
490
|
+
if (window.customElements.get(wc_id)) {
|
|
491
|
+
this.attachWC(wc_id, wcItemPlaceholder, wc_container, context, i18nViewUrl, nodeId);
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
/** Custom import function, if defined */
|
|
495
|
+
if (window.luigiWCFn) {
|
|
496
|
+
window.luigiWCFn(i18nViewUrl, wc_id, wcItemPlaceholder, function () {
|
|
497
|
+
_this.attachWC(wc_id, wcItemPlaceholder, wc_container, context, i18nViewUrl, nodeId);
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
else if (node.webcomponent && node.webcomponent.selfRegistered) {
|
|
501
|
+
this.includeSelfRegisteredWCFromUrl(node, i18nViewUrl, function () {
|
|
502
|
+
_this.attachWC(wc_id, wcItemPlaceholder, wc_container, context, i18nViewUrl, nodeId);
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
this.registerWCFromUrl(i18nViewUrl, wc_id).then(function () {
|
|
507
|
+
_this.attachWC(wc_id, wcItemPlaceholder, wc_container, context, i18nViewUrl, nodeId);
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* Creates a compound container according to the given renderer.
|
|
514
|
+
* Returns a promise that gets resolved with the created container DOM element.
|
|
515
|
+
*
|
|
516
|
+
* @param {DefaultCompoundRenderer} renderer
|
|
517
|
+
*/
|
|
518
|
+
WebComponentService.prototype.createCompoundContainerAsync = function (renderer, ctx) {
|
|
519
|
+
var _this = this;
|
|
520
|
+
return new Promise(function (resolve, reject) {
|
|
521
|
+
if (renderer.viewUrl) {
|
|
522
|
+
try {
|
|
523
|
+
var wc_id_1 = _this.generateWCId(renderer.viewUrl);
|
|
524
|
+
_this.registerWCFromUrl(renderer.viewUrl, wc_id_1).then(function () {
|
|
525
|
+
var wc = document.createElement(wc_id_1);
|
|
526
|
+
_this.initWC(wc, wc_id_1, wc, renderer.viewUrl, ctx, '_root');
|
|
527
|
+
resolve(wc);
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
catch (e) {
|
|
531
|
+
reject(e);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
resolve(renderer.createCompoundContainer());
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
};
|
|
539
|
+
/**
|
|
540
|
+
* Responsible for rendering web component compounds based on a renderer or a nesting
|
|
541
|
+
* micro frontend.
|
|
542
|
+
*
|
|
543
|
+
* @param {*} navNode the navigation node defining the compound
|
|
544
|
+
* @param {*} wc_container the web component container dom element
|
|
545
|
+
* @param {*} context the luigi node context
|
|
546
|
+
*/
|
|
547
|
+
WebComponentService.prototype.renderWebComponentCompound = function (navNode, wc_container, context) {
|
|
548
|
+
var _this = this;
|
|
549
|
+
var _a;
|
|
550
|
+
var renderer;
|
|
551
|
+
if (navNode.webcomponent && navNode.viewUrl) {
|
|
552
|
+
renderer = new DefaultCompoundRenderer();
|
|
553
|
+
renderer.viewUrl = this.processViewUrl(navNode.viewUrl, { context: context });
|
|
554
|
+
renderer.createCompoundItemContainer = function (layoutConfig) {
|
|
555
|
+
var cnt = document.createElement('div');
|
|
556
|
+
if (layoutConfig && layoutConfig.slot) {
|
|
557
|
+
cnt.setAttribute('slot', layoutConfig.slot);
|
|
558
|
+
}
|
|
559
|
+
return cnt;
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
else if ((_a = navNode.compound) === null || _a === void 0 ? void 0 : _a.renderer) {
|
|
563
|
+
renderer = resolveRenderer(navNode.compound.renderer);
|
|
564
|
+
}
|
|
565
|
+
renderer = renderer || new DefaultCompoundRenderer();
|
|
566
|
+
return new Promise(function (resolve) {
|
|
567
|
+
_this.createCompoundContainerAsync(renderer, context).then(function (compoundCnt) {
|
|
568
|
+
var _a;
|
|
569
|
+
var ebListeners = {};
|
|
570
|
+
compoundCnt.eventBus = {
|
|
571
|
+
listeners: ebListeners,
|
|
572
|
+
onPublishEvent: function (event, srcNodeId, wcId) {
|
|
573
|
+
var listeners = ebListeners[srcNodeId + '.' + event.type] || [];
|
|
574
|
+
listeners.push.apply(listeners, (ebListeners['*.' + event.type] || []));
|
|
575
|
+
listeners.forEach(function (listenerInfo) {
|
|
576
|
+
var target = listenerInfo.wcElement || compoundCnt.querySelector('[nodeId=' + listenerInfo.wcElementId + ']');
|
|
577
|
+
if (target) {
|
|
578
|
+
target.dispatchEvent(new CustomEvent(listenerInfo.action, {
|
|
579
|
+
detail: listenerInfo.converter ? listenerInfo.converter(event.detail) : event.detail
|
|
580
|
+
}));
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
console.debug('Could not find event target', listenerInfo);
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
(_a = navNode.compound) === null || _a === void 0 ? void 0 : _a.children.forEach(function (wc, index) {
|
|
589
|
+
var ctx = __assign(__assign({}, context), wc.context);
|
|
590
|
+
var compoundItemCnt = renderer.createCompoundItemContainer(wc.layoutConfig);
|
|
591
|
+
compoundItemCnt.eventBus = compoundCnt.eventBus;
|
|
592
|
+
renderer.attachCompoundItem(compoundCnt, compoundItemCnt);
|
|
593
|
+
var nodeId = wc.id || 'gen_' + index;
|
|
594
|
+
_this.renderWebComponent(wc.viewUrl, compoundItemCnt, ctx, wc, nodeId);
|
|
595
|
+
registerEventListeners(ebListeners, wc, nodeId);
|
|
596
|
+
});
|
|
597
|
+
wc_container.appendChild(compoundCnt);
|
|
598
|
+
// listener for nesting wc
|
|
599
|
+
registerEventListeners(ebListeners, navNode.compound, '_root', compoundCnt);
|
|
600
|
+
resolve(compoundCnt);
|
|
601
|
+
});
|
|
602
|
+
});
|
|
603
|
+
};
|
|
604
|
+
return WebComponentService;
|
|
605
|
+
}());
|
|
606
|
+
|
|
607
|
+
/* src/LuigiContainer.svelte generated by Svelte v3.46.4 */
|
|
608
|
+
|
|
609
|
+
function create_if_block(ctx) {
|
|
610
|
+
let show_if = !/*isWebComponent*/ ctx[5]();
|
|
611
|
+
let if_block_anchor;
|
|
612
|
+
let if_block = show_if && create_if_block_1(ctx);
|
|
613
|
+
|
|
614
|
+
return {
|
|
615
|
+
c() {
|
|
616
|
+
if (if_block) if_block.c();
|
|
617
|
+
if_block_anchor = empty();
|
|
618
|
+
},
|
|
619
|
+
m(target, anchor) {
|
|
620
|
+
if (if_block) if_block.m(target, anchor);
|
|
621
|
+
insert(target, if_block_anchor, anchor);
|
|
622
|
+
},
|
|
623
|
+
p(ctx, dirty) {
|
|
624
|
+
if (show_if) if_block.p(ctx, dirty);
|
|
625
|
+
},
|
|
626
|
+
d(detaching) {
|
|
627
|
+
if (if_block) if_block.d(detaching);
|
|
628
|
+
if (detaching) detach(if_block_anchor);
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// (88:2) {#if !isWebComponent()}
|
|
634
|
+
function create_if_block_1(ctx) {
|
|
635
|
+
let iframe;
|
|
636
|
+
let iframe_src_value;
|
|
637
|
+
|
|
638
|
+
return {
|
|
639
|
+
c() {
|
|
640
|
+
iframe = element("iframe");
|
|
641
|
+
if (!src_url_equal(iframe.src, iframe_src_value = /*viewurl*/ ctx[0])) attr(iframe, "src", iframe_src_value);
|
|
642
|
+
attr(iframe, "title", /*label*/ ctx[1]);
|
|
643
|
+
},
|
|
644
|
+
m(target, anchor) {
|
|
645
|
+
insert(target, iframe, anchor);
|
|
646
|
+
/*iframe_binding*/ ctx[8](iframe);
|
|
647
|
+
},
|
|
648
|
+
p(ctx, dirty) {
|
|
649
|
+
if (dirty & /*viewurl*/ 1 && !src_url_equal(iframe.src, iframe_src_value = /*viewurl*/ ctx[0])) {
|
|
650
|
+
attr(iframe, "src", iframe_src_value);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
if (dirty & /*label*/ 2) {
|
|
654
|
+
attr(iframe, "title", /*label*/ ctx[1]);
|
|
655
|
+
}
|
|
656
|
+
},
|
|
657
|
+
d(detaching) {
|
|
658
|
+
if (detaching) detach(iframe);
|
|
659
|
+
/*iframe_binding*/ ctx[8](null);
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
function create_fragment$1(ctx) {
|
|
665
|
+
let main;
|
|
666
|
+
let if_block = !/*deferInit*/ ctx[4] && create_if_block(ctx);
|
|
667
|
+
|
|
668
|
+
return {
|
|
669
|
+
c() {
|
|
670
|
+
main = element("main");
|
|
671
|
+
if (if_block) if_block.c();
|
|
672
|
+
this.c = noop;
|
|
673
|
+
attr(main, "class", /*isWebComponent*/ ctx[5]() ? undefined : 'lui-isolated');
|
|
674
|
+
},
|
|
675
|
+
m(target, anchor) {
|
|
676
|
+
insert(target, main, anchor);
|
|
677
|
+
if (if_block) if_block.m(main, null);
|
|
678
|
+
/*main_binding*/ ctx[9](main);
|
|
679
|
+
},
|
|
680
|
+
p(ctx, [dirty]) {
|
|
681
|
+
if (!/*deferInit*/ ctx[4]) {
|
|
682
|
+
if (if_block) {
|
|
683
|
+
if_block.p(ctx, dirty);
|
|
684
|
+
} else {
|
|
685
|
+
if_block = create_if_block(ctx);
|
|
686
|
+
if_block.c();
|
|
687
|
+
if_block.m(main, null);
|
|
688
|
+
}
|
|
689
|
+
} else if (if_block) {
|
|
690
|
+
if_block.d(1);
|
|
691
|
+
if_block = null;
|
|
692
|
+
}
|
|
693
|
+
},
|
|
694
|
+
i: noop,
|
|
695
|
+
o: noop,
|
|
696
|
+
d(detaching) {
|
|
697
|
+
if (detaching) detach(main);
|
|
698
|
+
if (if_block) if_block.d();
|
|
699
|
+
/*main_binding*/ ctx[9](null);
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
function instance$1($$self, $$props, $$invalidate) {
|
|
705
|
+
let { viewurl } = $$props;
|
|
706
|
+
let { context } = $$props;
|
|
707
|
+
let { label } = $$props;
|
|
708
|
+
let { webcomponent } = $$props;
|
|
709
|
+
let iframeHandle = {};
|
|
710
|
+
let mainComponent;
|
|
711
|
+
const containerService = new ContainerService();
|
|
712
|
+
const webcomponentService = new WebComponentService();
|
|
713
|
+
|
|
714
|
+
webcomponentService.createClientAPI = (eventBusElement, nodeId, wc_id) => {
|
|
715
|
+
return {
|
|
716
|
+
linkManager: () => {
|
|
717
|
+
return {
|
|
718
|
+
navigate: route => {
|
|
719
|
+
dispatchLuigiEvent('navigation-request', { link: route });
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
},
|
|
723
|
+
uxManager: () => {
|
|
724
|
+
return {
|
|
725
|
+
showAlert: alertSettings => {
|
|
726
|
+
dispatchLuigiEvent('alert-request', alertSettings);
|
|
727
|
+
},
|
|
728
|
+
showConfirmationModal: async settings => {
|
|
729
|
+
return new Promise((resolve, reject) => {
|
|
730
|
+
dispatchLuigiEvent('confirmation-request', settings, data => {
|
|
731
|
+
if (data) {
|
|
732
|
+
resolve(data);
|
|
733
|
+
} else {
|
|
734
|
+
reject();
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
}, //window.Luigi.ux,
|
|
741
|
+
getCurrentLocale: () => {
|
|
742
|
+
|
|
743
|
+
}, //() => window.Luigi.i18n().getCurrentLocale(),
|
|
744
|
+
publishEvent: ev => {
|
|
745
|
+
|
|
746
|
+
}, // if (eventBusElement.eventBus) {
|
|
747
|
+
// eventBusElement.eventBus.onPublishEvent(ev, nodeId, wc_id);
|
|
748
|
+
// }
|
|
749
|
+
|
|
750
|
+
};
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
const thisComponent = get_current_component();
|
|
754
|
+
thisComponent.iframeHandle = iframeHandle;
|
|
755
|
+
let deferInit = !!thisComponent.attributes['defer-init'];
|
|
756
|
+
|
|
757
|
+
thisComponent.init = () => {
|
|
758
|
+
$$invalidate(4, deferInit = false);
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
containerService.registerContainer(thisComponent);
|
|
762
|
+
|
|
763
|
+
function dispatchLuigiEvent(msg, data, callback) {
|
|
764
|
+
containerService.dispatch(msg, thisComponent, data, callback);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
function isWebComponent() {
|
|
768
|
+
return !!webcomponent;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
onMount(async () => {
|
|
772
|
+
const ctx = context ? JSON.parse(context) : undefined;
|
|
773
|
+
console.log(ctx);
|
|
774
|
+
|
|
775
|
+
if (isWebComponent()) {
|
|
776
|
+
$$invalidate(3, mainComponent.innerHTML = '', mainComponent);
|
|
777
|
+
webcomponentService.renderWebComponent(viewurl, mainComponent, ctx, {});
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
onDestroy(async () => {
|
|
782
|
+
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
function iframe_binding($$value) {
|
|
786
|
+
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
|
|
787
|
+
iframeHandle.iframe = $$value;
|
|
788
|
+
$$invalidate(2, iframeHandle);
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
function main_binding($$value) {
|
|
793
|
+
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
|
|
794
|
+
mainComponent = $$value;
|
|
795
|
+
$$invalidate(3, mainComponent);
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
$$self.$$set = $$props => {
|
|
800
|
+
if ('viewurl' in $$props) $$invalidate(0, viewurl = $$props.viewurl);
|
|
801
|
+
if ('context' in $$props) $$invalidate(6, context = $$props.context);
|
|
802
|
+
if ('label' in $$props) $$invalidate(1, label = $$props.label);
|
|
803
|
+
if ('webcomponent' in $$props) $$invalidate(7, webcomponent = $$props.webcomponent);
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
return [
|
|
807
|
+
viewurl,
|
|
808
|
+
label,
|
|
809
|
+
iframeHandle,
|
|
810
|
+
mainComponent,
|
|
811
|
+
deferInit,
|
|
812
|
+
isWebComponent,
|
|
813
|
+
context,
|
|
814
|
+
webcomponent,
|
|
815
|
+
iframe_binding,
|
|
816
|
+
main_binding
|
|
817
|
+
];
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
class LuigiContainer extends SvelteElement {
|
|
821
|
+
constructor(options) {
|
|
822
|
+
super();
|
|
823
|
+
this.shadowRoot.innerHTML = `<style>main,iframe{width:100%;height:100%;border:none}main.lui-isolated{line-height:0}</style>`;
|
|
824
|
+
|
|
825
|
+
init(
|
|
826
|
+
this,
|
|
827
|
+
{
|
|
828
|
+
target: this.shadowRoot,
|
|
829
|
+
props: attribute_to_object(this.attributes),
|
|
830
|
+
customElement: true
|
|
831
|
+
},
|
|
832
|
+
instance$1,
|
|
833
|
+
create_fragment$1,
|
|
834
|
+
safe_not_equal,
|
|
835
|
+
{
|
|
836
|
+
viewurl: 0,
|
|
837
|
+
context: 6,
|
|
838
|
+
label: 1,
|
|
839
|
+
webcomponent: 7
|
|
840
|
+
},
|
|
841
|
+
null
|
|
842
|
+
);
|
|
843
|
+
|
|
844
|
+
if (options) {
|
|
845
|
+
if (options.target) {
|
|
846
|
+
insert(options.target, this, options.anchor);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
if (options.props) {
|
|
850
|
+
this.$set(options.props);
|
|
851
|
+
flush();
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
static get observedAttributes() {
|
|
857
|
+
return ["viewurl", "context", "label", "webcomponent"];
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
get viewurl() {
|
|
861
|
+
return this.$$.ctx[0];
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
set viewurl(viewurl) {
|
|
865
|
+
this.$$set({ viewurl });
|
|
866
|
+
flush();
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
get context() {
|
|
870
|
+
return this.$$.ctx[6];
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
set context(context) {
|
|
874
|
+
this.$$set({ context });
|
|
875
|
+
flush();
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
get label() {
|
|
879
|
+
return this.$$.ctx[1];
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
set label(label) {
|
|
883
|
+
this.$$set({ label });
|
|
884
|
+
flush();
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
get webcomponent() {
|
|
888
|
+
return this.$$.ctx[7];
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
set webcomponent(webcomponent) {
|
|
892
|
+
this.$$set({ webcomponent });
|
|
893
|
+
flush();
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/* src/LuigiCompoundContainer.svelte generated by Svelte v3.46.4 */
|
|
898
|
+
|
|
899
|
+
function create_fragment(ctx) {
|
|
900
|
+
let main;
|
|
901
|
+
|
|
902
|
+
return {
|
|
903
|
+
c() {
|
|
904
|
+
main = element("main");
|
|
905
|
+
this.c = noop;
|
|
906
|
+
},
|
|
907
|
+
m(target, anchor) {
|
|
908
|
+
insert(target, main, anchor);
|
|
909
|
+
/*main_binding*/ ctx[2](main);
|
|
910
|
+
},
|
|
911
|
+
p: noop,
|
|
912
|
+
i: noop,
|
|
913
|
+
o: noop,
|
|
914
|
+
d(detaching) {
|
|
915
|
+
if (detaching) detach(main);
|
|
916
|
+
/*main_binding*/ ctx[2](null);
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
function instance($$self, $$props, $$invalidate) {
|
|
922
|
+
let { context } = $$props;
|
|
923
|
+
|
|
924
|
+
let initialized = false;
|
|
925
|
+
let mainComponent;
|
|
926
|
+
const containerService = new ContainerService();
|
|
927
|
+
const webcomponentService = new WebComponentService();
|
|
928
|
+
|
|
929
|
+
webcomponentService.createClientAPI = (eventBusElement, nodeId, wc_id) => {
|
|
930
|
+
return {
|
|
931
|
+
linkManager: () => {
|
|
932
|
+
|
|
933
|
+
}, //window.Luigi.navigation,
|
|
934
|
+
uxManager: () => {
|
|
935
|
+
return {
|
|
936
|
+
showAlert: alertSettings => {
|
|
937
|
+
dispatchLuigiEvent('alert-request', alertSettings);
|
|
938
|
+
},
|
|
939
|
+
showConfirmationModal: async settings => {
|
|
940
|
+
return new Promise((resolve, reject) => {
|
|
941
|
+
dispatchLuigiEvent('confirmation-request', settings, data => {
|
|
942
|
+
if (data) {
|
|
943
|
+
resolve(data);
|
|
944
|
+
} else {
|
|
945
|
+
reject();
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
}, //window.Luigi.ux,
|
|
952
|
+
getCurrentLocale: () => {
|
|
953
|
+
|
|
954
|
+
}, //() => window.Luigi.i18n().getCurrentLocale(),
|
|
955
|
+
publishEvent: ev => {
|
|
956
|
+
console.log('pub', ev);
|
|
957
|
+
|
|
958
|
+
if (eventBusElement && eventBusElement.eventBus) {
|
|
959
|
+
eventBusElement.eventBus.onPublishEvent(ev, nodeId, wc_id);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
const thisComponent = get_current_component();
|
|
966
|
+
!!thisComponent.attributes['defer-init'];
|
|
967
|
+
|
|
968
|
+
thisComponent.init = () => {
|
|
969
|
+
if (!thisComponent.compoundConfig || initialized) return;
|
|
970
|
+
console.log('init compound');
|
|
971
|
+
const node = { compound: thisComponent.compoundConfig }; // TODO: fill with sth
|
|
972
|
+
|
|
973
|
+
webcomponentService.renderWebComponentCompound(node, mainComponent, context).then(compCnt => {
|
|
974
|
+
});
|
|
975
|
+
|
|
976
|
+
initialized = true;
|
|
977
|
+
};
|
|
978
|
+
|
|
979
|
+
containerService.registerContainer(thisComponent);
|
|
980
|
+
|
|
981
|
+
function dispatchLuigiEvent(msg, data, callback) {
|
|
982
|
+
containerService.dispatch(msg, thisComponent, data, callback);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
onMount(async () => {
|
|
986
|
+
const ctx = context ? JSON.parse(context) : undefined;
|
|
987
|
+
console.log(ctx);
|
|
988
|
+
});
|
|
989
|
+
|
|
990
|
+
function main_binding($$value) {
|
|
991
|
+
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
|
|
992
|
+
mainComponent = $$value;
|
|
993
|
+
$$invalidate(0, mainComponent);
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
$$self.$$set = $$props => {
|
|
998
|
+
if ('context' in $$props) $$invalidate(1, context = $$props.context);
|
|
999
|
+
};
|
|
1000
|
+
|
|
1001
|
+
return [mainComponent, context, main_binding];
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
class LuigiCompoundContainer extends SvelteElement {
|
|
1005
|
+
constructor(options) {
|
|
1006
|
+
super();
|
|
1007
|
+
this.shadowRoot.innerHTML = `<style>main{width:100%;height:100%;border:none}</style>`;
|
|
1008
|
+
|
|
1009
|
+
init(
|
|
1010
|
+
this,
|
|
1011
|
+
{
|
|
1012
|
+
target: this.shadowRoot,
|
|
1013
|
+
props: attribute_to_object(this.attributes),
|
|
1014
|
+
customElement: true
|
|
1015
|
+
},
|
|
1016
|
+
instance,
|
|
1017
|
+
create_fragment,
|
|
1018
|
+
safe_not_equal,
|
|
1019
|
+
{ context: 1 },
|
|
1020
|
+
null
|
|
1021
|
+
);
|
|
1022
|
+
|
|
1023
|
+
if (options) {
|
|
1024
|
+
if (options.target) {
|
|
1025
|
+
insert(options.target, this, options.anchor);
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
if (options.props) {
|
|
1029
|
+
this.$set(options.props);
|
|
1030
|
+
flush();
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
static get observedAttributes() {
|
|
1036
|
+
return ["context"];
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
get context() {
|
|
1040
|
+
return this.$$.ctx[1];
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
set context(context) {
|
|
1044
|
+
this.$$set({ context });
|
|
1045
|
+
flush();
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
export { LuigiCompoundContainer, LuigiContainer };
|
|
1050
|
+
//# sourceMappingURL=bundle.d.ts.map
|