@luigi-project/container 0.0.1 → 0.0.4

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/bundle.js CHANGED
@@ -1,1472 +1,2 @@
1
- (function(l, r) {
2
- if (!l || l.getElementById('livereloadscript')) return;
3
- r = l.createElement('script');
4
- r.async = 1;
5
- r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1';
6
- r.id = 'livereloadscript';
7
- l.getElementsByTagName('head')[0].appendChild(r);
8
- })(self.document);
9
- function noop() {}
10
- function add_location(element, file, line, column, char) {
11
- element.__svelte_meta = {
12
- loc: { file, line, column, char }
13
- };
14
- }
15
- function run(fn) {
16
- return fn();
17
- }
18
- function blank_object() {
19
- return Object.create(null);
20
- }
21
- function run_all(fns) {
22
- fns.forEach(run);
23
- }
24
- function is_function(thing) {
25
- return typeof thing === 'function';
26
- }
27
- function safe_not_equal(a, b) {
28
- return a != a ? b == b : a !== b || (a && typeof a === 'object') || typeof a === 'function';
29
- }
30
- let src_url_equal_anchor;
31
- function src_url_equal(element_src, url) {
32
- if (!src_url_equal_anchor) {
33
- src_url_equal_anchor = document.createElement('a');
34
- }
35
- src_url_equal_anchor.href = url;
36
- return element_src === src_url_equal_anchor.href;
37
- }
38
- function is_empty(obj) {
39
- return Object.keys(obj).length === 0;
40
- }
41
- function insert(target, node, anchor) {
42
- target.insertBefore(node, anchor || null);
43
- }
44
- function detach(node) {
45
- node.parentNode.removeChild(node);
46
- }
47
- function element(name) {
48
- return document.createElement(name);
49
- }
50
- function text(data) {
51
- return document.createTextNode(data);
52
- }
53
- function empty() {
54
- return text('');
55
- }
56
- function attr(node, attribute, value) {
57
- if (value == null) node.removeAttribute(attribute);
58
- else if (node.getAttribute(attribute) !== value) node.setAttribute(attribute, value);
59
- }
60
- function children(element) {
61
- return Array.from(element.childNodes);
62
- }
63
- function custom_event(type, detail, bubbles = false) {
64
- const e = document.createEvent('CustomEvent');
65
- e.initCustomEvent(type, bubbles, false, detail);
66
- return e;
67
- }
68
- function attribute_to_object(attributes) {
69
- const result = {};
70
- for (const attribute of attributes) {
71
- result[attribute.name] = attribute.value;
72
- }
73
- return result;
74
- }
75
-
76
- let current_component;
77
- function set_current_component(component) {
78
- current_component = component;
79
- }
80
- function get_current_component() {
81
- if (!current_component) throw new Error('Function called outside component initialization');
82
- return current_component;
83
- }
84
- function onMount(fn) {
85
- get_current_component().$$.on_mount.push(fn);
86
- }
87
- function onDestroy(fn) {
88
- get_current_component().$$.on_destroy.push(fn);
89
- }
90
-
91
- const dirty_components = [];
92
- const binding_callbacks = [];
93
- const render_callbacks = [];
94
- const flush_callbacks = [];
95
- const resolved_promise = Promise.resolve();
96
- let update_scheduled = false;
97
- function schedule_update() {
98
- if (!update_scheduled) {
99
- update_scheduled = true;
100
- resolved_promise.then(flush);
101
- }
102
- }
103
- function add_render_callback(fn) {
104
- render_callbacks.push(fn);
105
- }
106
- // flush() calls callbacks in this order:
107
- // 1. All beforeUpdate callbacks, in order: parents before children
108
- // 2. All bind:this callbacks, in reverse order: children before parents.
109
- // 3. All afterUpdate callbacks, in order: parents before children. EXCEPT
110
- // for afterUpdates called during the initial onMount, which are called in
111
- // reverse order: children before parents.
112
- // Since callbacks might update component values, which could trigger another
113
- // call to flush(), the following steps guard against this:
114
- // 1. During beforeUpdate, any updated components will be added to the
115
- // dirty_components array and will cause a reentrant call to flush(). Because
116
- // the flush index is kept outside the function, the reentrant call will pick
117
- // up where the earlier call left off and go through all dirty components. The
118
- // current_component value is saved and restored so that the reentrant call will
119
- // not interfere with the "parent" flush() call.
120
- // 2. bind:this callbacks cannot trigger new flush() calls.
121
- // 3. During afterUpdate, any updated components will NOT have their afterUpdate
122
- // callback called a second time; the seen_callbacks set, outside the flush()
123
- // function, guarantees this behavior.
124
- const seen_callbacks = new Set();
125
- let flushidx = 0; // Do *not* move this inside the flush() function
126
- function flush() {
127
- const saved_component = current_component;
128
- do {
129
- // first, call beforeUpdate functions
130
- // and update components
131
- while (flushidx < dirty_components.length) {
132
- const component = dirty_components[flushidx];
133
- flushidx++;
134
- set_current_component(component);
135
- update(component.$$);
136
- }
137
- set_current_component(null);
138
- dirty_components.length = 0;
139
- flushidx = 0;
140
- while (binding_callbacks.length) binding_callbacks.pop()();
141
- // then, once components are updated, call
142
- // afterUpdate functions. This may cause
143
- // subsequent updates...
144
- for (let i = 0; i < render_callbacks.length; i += 1) {
145
- const callback = render_callbacks[i];
146
- if (!seen_callbacks.has(callback)) {
147
- // ...so guard against infinite loops
148
- seen_callbacks.add(callback);
149
- callback();
150
- }
151
- }
152
- render_callbacks.length = 0;
153
- } while (dirty_components.length);
154
- while (flush_callbacks.length) {
155
- flush_callbacks.pop()();
156
- }
157
- update_scheduled = false;
158
- seen_callbacks.clear();
159
- set_current_component(saved_component);
160
- }
161
- function update($$) {
162
- if ($$.fragment !== null) {
163
- $$.update();
164
- run_all($$.before_update);
165
- const dirty = $$.dirty;
166
- $$.dirty = [-1];
167
- $$.fragment && $$.fragment.p($$.ctx, dirty);
168
- $$.after_update.forEach(add_render_callback);
169
- }
170
- }
171
- const outroing = new Set();
172
- function transition_in(block, local) {
173
- if (block && block.i) {
174
- outroing.delete(block);
175
- block.i(local);
176
- }
177
- }
178
-
179
- const globals = typeof window !== 'undefined' ? window : typeof globalThis !== 'undefined' ? globalThis : global;
180
- function mount_component(component, target, anchor, customElement) {
181
- const { fragment, on_mount, on_destroy, after_update } = component.$$;
182
- fragment && fragment.m(target, anchor);
183
- if (!customElement) {
184
- // onMount happens before the initial afterUpdate
185
- add_render_callback(() => {
186
- const new_on_destroy = on_mount.map(run).filter(is_function);
187
- if (on_destroy) {
188
- on_destroy.push(...new_on_destroy);
189
- } else {
190
- // Edge case - component was destroyed immediately,
191
- // most likely as a result of a binding initialising
192
- run_all(new_on_destroy);
193
- }
194
- component.$$.on_mount = [];
195
- });
196
- }
197
- after_update.forEach(add_render_callback);
198
- }
199
- function destroy_component(component, detaching) {
200
- const $$ = component.$$;
201
- if ($$.fragment !== null) {
202
- run_all($$.on_destroy);
203
- $$.fragment && $$.fragment.d(detaching);
204
- // TODO null out other refs, including component.$$ (but need to
205
- // preserve final state?)
206
- $$.on_destroy = $$.fragment = null;
207
- $$.ctx = [];
208
- }
209
- }
210
- function make_dirty(component, i) {
211
- if (component.$$.dirty[0] === -1) {
212
- dirty_components.push(component);
213
- schedule_update();
214
- component.$$.dirty.fill(0);
215
- }
216
- component.$$.dirty[(i / 31) | 0] |= 1 << i % 31;
217
- }
218
- function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) {
219
- const parent_component = current_component;
220
- set_current_component(component);
221
- const $$ = (component.$$ = {
222
- fragment: null,
223
- ctx: null,
224
- // state
225
- props,
226
- update: noop,
227
- not_equal,
228
- bound: blank_object(),
229
- // lifecycle
230
- on_mount: [],
231
- on_destroy: [],
232
- on_disconnect: [],
233
- before_update: [],
234
- after_update: [],
235
- context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
236
- // everything else
237
- callbacks: blank_object(),
238
- dirty,
239
- skip_bound: false,
240
- root: options.target || parent_component.$$.root
241
- });
242
- append_styles && append_styles($$.root);
243
- let ready = false;
244
- $$.ctx = instance
245
- ? instance(component, options.props || {}, (i, ret, ...rest) => {
246
- const value = rest.length ? rest[0] : ret;
247
- if ($$.ctx && not_equal($$.ctx[i], ($$.ctx[i] = value))) {
248
- if (!$$.skip_bound && $$.bound[i]) $$.bound[i](value);
249
- if (ready) make_dirty(component, i);
250
- }
251
- return ret;
252
- })
253
- : [];
254
- $$.update();
255
- ready = true;
256
- run_all($$.before_update);
257
- // `false` as a special case of no DOM component
258
- $$.fragment = create_fragment ? create_fragment($$.ctx) : false;
259
- if (options.target) {
260
- if (options.hydrate) {
261
- const nodes = children(options.target);
262
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
263
- $$.fragment && $$.fragment.l(nodes);
264
- nodes.forEach(detach);
265
- } else {
266
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
267
- $$.fragment && $$.fragment.c();
268
- }
269
- if (options.intro) transition_in(component.$$.fragment);
270
- mount_component(component, options.target, options.anchor, options.customElement);
271
- flush();
272
- }
273
- set_current_component(parent_component);
274
- }
275
- let SvelteElement;
276
- if (typeof HTMLElement === 'function') {
277
- SvelteElement = class extends HTMLElement {
278
- constructor() {
279
- super();
280
- this.attachShadow({ mode: 'open' });
281
- }
282
- connectedCallback() {
283
- const { on_mount } = this.$$;
284
- this.$$.on_disconnect = on_mount.map(run).filter(is_function);
285
- // @ts-ignore todo: improve typings
286
- for (const key in this.$$.slotted) {
287
- // @ts-ignore todo: improve typings
288
- this.appendChild(this.$$.slotted[key]);
289
- }
290
- }
291
- attributeChangedCallback(attr, _oldValue, newValue) {
292
- this[attr] = newValue;
293
- }
294
- disconnectedCallback() {
295
- run_all(this.$$.on_disconnect);
296
- }
297
- $destroy() {
298
- destroy_component(this, 1);
299
- this.$destroy = noop;
300
- }
301
- $on(type, callback) {
302
- // TODO should this delegate to addEventListener?
303
- const callbacks = this.$$.callbacks[type] || (this.$$.callbacks[type] = []);
304
- callbacks.push(callback);
305
- return () => {
306
- const index = callbacks.indexOf(callback);
307
- if (index !== -1) callbacks.splice(index, 1);
308
- };
309
- }
310
- $set($$props) {
311
- if (this.$$set && !is_empty($$props)) {
312
- this.$$.skip_bound = true;
313
- this.$$set($$props);
314
- this.$$.skip_bound = false;
315
- }
316
- }
317
- };
318
- }
319
-
320
- function dispatch_dev(type, detail) {
321
- document.dispatchEvent(custom_event(type, Object.assign({ version: '3.46.4' }, detail), true));
322
- }
323
- function insert_dev(target, node, anchor) {
324
- dispatch_dev('SvelteDOMInsert', { target, node, anchor });
325
- insert(target, node, anchor);
326
- }
327
- function detach_dev(node) {
328
- dispatch_dev('SvelteDOMRemove', { node });
329
- detach(node);
330
- }
331
- function attr_dev(node, attribute, value) {
332
- attr(node, attribute, value);
333
- if (value == null) dispatch_dev('SvelteDOMRemoveAttribute', { node, attribute });
334
- else dispatch_dev('SvelteDOMSetAttribute', { node, attribute, value });
335
- }
336
- function validate_slots(name, slot, keys) {
337
- for (const slot_key of Object.keys(slot)) {
338
- if (!~keys.indexOf(slot_key)) {
339
- console.warn(`<${name}> received an unexpected slot "${slot_key}".`);
340
- }
341
- }
342
- }
343
-
344
- class ContainerService {
345
- constructor() {}
346
- isVisible(component) {
347
- return !!(component.offsetWidth || component.offsetHeight || component.getClientRects().length);
348
- }
349
- dispatch(msg, targetCnt, data, callback) {
350
- let ev = new CustomEvent(msg, { detail: data });
351
- ev.luigiCallback = data => {
352
- if (callback) {
353
- callback(data);
354
- }
355
- };
356
- targetCnt.dispatchEvent(ev);
357
- console.log('Dispatch WC event:', msg, targetCnt, data);
358
- }
359
- getTargetContainer(event) {
360
- let cnt;
361
- globalThis.__luigi_container_manager.container.forEach(element => {
362
- var _a;
363
- if (
364
- ((_a = element.iframeHandle) === null || _a === void 0 ? void 0 : _a.iframe) &&
365
- element.iframeHandle.iframe.contentWindow === event.source
366
- ) {
367
- cnt = element;
368
- }
369
- });
370
- return cnt;
371
- }
372
- getContainerManager() {
373
- if (!globalThis.__luigi_container_manager) {
374
- globalThis.__luigi_container_manager = {
375
- container: [],
376
- messageListener: event => {
377
- var _a, _b, _c, _d;
378
- const targetCnt = this.getTargetContainer(event);
379
- const target =
380
- (_b =
381
- (_a = targetCnt === null || targetCnt === void 0 ? void 0 : targetCnt.iframeHandle) === null ||
382
- _a === void 0
383
- ? void 0
384
- : _a.iframe) === null || _b === void 0
385
- ? void 0
386
- : _b.contentWindow;
387
- console.log('Container event', event, targetCnt);
388
- if (
389
- target === event.source &&
390
- ((_d = (_c = event.data) === null || _c === void 0 ? void 0 : _c.msg) === null || _d === void 0
391
- ? void 0
392
- : _d.indexOf('luigi.')) === 0
393
- ) {
394
- const msg = event.data.msg;
395
- switch (msg) {
396
- case 'luigi.get-context':
397
- target.postMessage({ msg: 'luigi.init', context: targetCnt.context, internal: {} }, '*');
398
- break;
399
- case 'luigi.navigation.open':
400
- this.dispatch('navigation-request', targetCnt, event.data.params);
401
- break;
402
- case 'luigi.ux.alert.show':
403
- this.dispatch('alert-request', targetCnt, event.data.params);
404
- break;
405
- default:
406
- console.warn('Functionality not yet implemented: ', msg);
407
- break;
408
- }
409
- }
410
- }
411
- };
412
- window.addEventListener('message', globalThis.__luigi_container_manager.messageListener);
413
- }
414
- return globalThis.__luigi_container_manager;
415
- }
416
- registerContainer(container) {
417
- this.getContainerManager().container.push(container);
418
- }
419
- }
420
-
421
- /**
422
- * Default compound renderer.
423
- */
424
- class DefaultCompoundRenderer {
425
- constructor(rendererObj) {
426
- if (rendererObj) {
427
- this.rendererObject = rendererObj;
428
- this.config = rendererObj.config || {};
429
- } else {
430
- this.config = {};
431
- }
432
- }
433
- createCompoundContainer() {
434
- return document.createElement('div');
435
- }
436
- createCompoundItemContainer(layoutConfig) {
437
- return document.createElement('div');
438
- }
439
- attachCompoundItem(compoundCnt, compoundItemCnt) {
440
- compoundCnt.appendChild(compoundItemCnt);
441
- }
442
- }
443
- /**
444
- * Compound Renderer for custom rendering as defined in luigi config.
445
- */
446
- class CustomCompoundRenderer extends DefaultCompoundRenderer {
447
- constructor(rendererObj) {
448
- super(rendererObj || { use: {} });
449
- if (rendererObj && rendererObj.use && rendererObj.use.extends) {
450
- this.superRenderer = resolveRenderer({
451
- use: rendererObj.use.extends,
452
- config: rendererObj.config
453
- });
454
- }
455
- }
456
- createCompoundContainer() {
457
- if (this.rendererObject.use.createCompoundContainer) {
458
- return this.rendererObject.use.createCompoundContainer(this.config, this.superRenderer);
459
- } else if (this.superRenderer) {
460
- return this.superRenderer.createCompoundContainer();
461
- }
462
- return super.createCompoundContainer();
463
- }
464
- createCompoundItemContainer(layoutConfig) {
465
- if (this.rendererObject.use.createCompoundItemContainer) {
466
- return this.rendererObject.use.createCompoundItemContainer(layoutConfig, this.config, this.superRenderer);
467
- } else if (this.superRenderer) {
468
- return this.superRenderer.createCompoundItemContainer(layoutConfig);
469
- }
470
- return super.createCompoundItemContainer(layoutConfig);
471
- }
472
- attachCompoundItem(compoundCnt, compoundItemCnt) {
473
- if (this.rendererObject.use.attachCompoundItem) {
474
- this.rendererObject.use.attachCompoundItem(compoundCnt, compoundItemCnt, this.superRenderer);
475
- } else if (this.superRenderer) {
476
- this.superRenderer.attachCompoundItem(compoundCnt, compoundItemCnt);
477
- } else {
478
- super.attachCompoundItem(compoundCnt, compoundItemCnt);
479
- }
480
- }
481
- }
482
- /**
483
- * Compound Renderer for a css grid compound view.
484
- */
485
- class GridCompoundRenderer extends DefaultCompoundRenderer {
486
- createCompoundContainer() {
487
- const containerClass = '__lui_compound_' + new Date().getTime();
488
- const compoundCnt = document.createElement('div');
489
- compoundCnt.classList.add(containerClass);
490
- let mediaQueries = '';
491
- if (this.config.layouts) {
492
- this.config.layouts.forEach(el => {
493
- if (el.minWidth || el.maxWidth) {
494
- let mq = '@media only screen ';
495
- if (el.minWidth != null) {
496
- mq += `and (min-width: ${el.minWidth}px) `;
497
- }
498
- if (el.maxWidth != null) {
499
- mq += `and (max-width: ${el.maxWidth}px) `;
500
- }
501
- mq += `{
502
- .${containerClass} {
503
- grid-template-columns: ${el.columns || 'auto'};
504
- grid-template-rows: ${el.rows || 'auto'};
505
- grid-gap: ${el.gap || '0'};
506
- }
507
- }
508
- `;
509
- mediaQueries += mq;
510
- }
511
- });
512
- }
513
- compoundCnt.innerHTML = /*html*/ `
514
- <style scoped>
515
- .${containerClass} {
516
- display: grid;
517
- grid-template-columns: ${this.config.columns || 'auto'};
518
- grid-template-rows: ${this.config.rows || 'auto'};
519
- grid-gap: ${this.config.gap || '0'};
520
- min-height: ${this.config.minHeight || 'auto'};
521
- }
522
- ${mediaQueries}
523
- </style>
524
- `;
525
- return compoundCnt;
526
- }
527
- createCompoundItemContainer(layoutConfig) {
528
- const config = layoutConfig || {};
529
- const compoundItemCnt = document.createElement('div');
530
- compoundItemCnt.setAttribute('style', `grid-row: ${config.row || 'auto'}; grid-column: ${config.column || 'auto'}`);
531
- return compoundItemCnt;
532
- }
533
- }
534
- /**
535
- * Returns the compound renderer class for a given config.
536
- * If no specific one is found, {DefaultCompoundRenderer} is returned.
537
- *
538
- * @param {*} rendererConfig the renderer config object defined in luigi config
539
- */
540
- const resolveRenderer = rendererConfig => {
541
- const rendererDef = rendererConfig.use;
542
- if (!rendererDef) {
543
- return new DefaultCompoundRenderer(rendererConfig);
544
- } else if (rendererDef === 'grid') {
545
- return new GridCompoundRenderer(rendererConfig);
546
- } else if (
547
- rendererDef.createCompoundContainer ||
548
- rendererDef.createCompoundItemContainer ||
549
- rendererDef.attachCompoundItem
550
- ) {
551
- return new CustomCompoundRenderer(rendererConfig);
552
- }
553
- return new DefaultCompoundRenderer(rendererConfig);
554
- };
555
- /**
556
- * Registers event listeners defined at the navNode.
557
- *
558
- * @param {*} eventbusListeners a map of event listener arrays with event id as key
559
- * @param {*} navNode the web component node configuration object
560
- * @param {*} nodeId the web component node id
561
- * @param {*} wcElement the web component element - optional
562
- */
563
- const registerEventListeners = (eventbusListeners, navNode, nodeId, wcElement) => {
564
- if (navNode === null || navNode === void 0 ? void 0 : navNode.eventListeners) {
565
- navNode.eventListeners.forEach(el => {
566
- const evID = el.source + '.' + el.name;
567
- const listenerList = eventbusListeners[evID];
568
- const listenerInfo = {
569
- wcElementId: nodeId,
570
- wcElement: wcElement,
571
- action: el.action,
572
- converter: el.dataConverter
573
- };
574
- if (listenerList) {
575
- listenerList.push(listenerInfo);
576
- } else {
577
- eventbusListeners[evID] = [listenerInfo];
578
- }
579
- });
580
- }
581
- };
582
-
583
- /** Methods for dealing with web components based micro frontend handling */
584
- class WebComponentService {
585
- constructor() {
586
- this.containerService = new ContainerService();
587
- }
588
- dynamicImport(viewUrl) {
589
- return import(viewUrl);
590
- }
591
- processViewUrl(viewUrl, data) {
592
- return viewUrl;
593
- }
594
- /** Creates a web component with tagname wc_id and adds it to wcItemContainer,
595
- * if attached to wc_container
596
- */
597
- attachWC(wc_id, wcItemPlaceholder, wc_container, ctx, viewUrl, nodeId) {
598
- if (wc_container && wc_container.contains(wcItemPlaceholder)) {
599
- const wc = document.createElement(wc_id);
600
- if (nodeId) {
601
- wc.setAttribute('nodeId', nodeId);
602
- }
603
- this.initWC(wc, wc_id, wc_container, viewUrl, ctx, nodeId);
604
- wc_container.replaceChild(wc, wcItemPlaceholder);
605
- }
606
- }
607
- createClientAPI(eventBusElement, nodeId, wc_id) {
608
- return {
609
- linkManager: () => {},
610
- uxManager: () => {
611
- return {
612
- showAlert: alertSettings => {},
613
- showConfirmationModal: async settings => {
614
- return new Promise((resolve, reject) => {
615
- resolve(true);
616
- });
617
- }
618
- };
619
- },
620
- getCurrentLocale: () => {},
621
- publishEvent: ev => {
622
- // if (eventBusElement.eventBus) {
623
- // eventBusElement.eventBus.onPublishEvent(ev, nodeId, wc_id);
624
- // }
625
- }
626
- };
627
- }
628
- initWC(wc, wc_id, eventBusElement, viewUrl, ctx, nodeId) {
629
- const clientAPI = this.createClientAPI(eventBusElement, nodeId, wc_id);
630
- if (wc.__postProcess) {
631
- const url =
632
- new URL(document.baseURI).origin === new URL(viewUrl, document.baseURI).origin // TODO: check if needed
633
- ? new URL('./', new URL(viewUrl, document.baseURI))
634
- : new URL('./', viewUrl);
635
- wc.__postProcess(ctx, clientAPI, url.origin + url.pathname);
636
- } else {
637
- wc.context = ctx;
638
- wc.LuigiClient = clientAPI;
639
- }
640
- }
641
- /** Generates a unique web component id (tagname) based on the viewUrl
642
- * returns a string that can be used as part of a tagname, only alphanumeric
643
- * characters and no whitespaces.
644
- */
645
- generateWCId(viewUrl) {
646
- let charRep = '';
647
- for (let i = 0; i < viewUrl.length; i++) {
648
- charRep += viewUrl.charCodeAt(i).toString(16);
649
- }
650
- return 'luigi-wc-' + charRep;
651
- }
652
- /** Does a module import from viewUrl and defines a new web component
653
- * with the default export of the module or the first export extending HTMLElement if no default is
654
- * specified.
655
- * @returns a promise that gets resolved after successfull import */
656
- registerWCFromUrl(viewUrl, wc_id) {
657
- const i18nViewUrl = this.processViewUrl(viewUrl);
658
- return new Promise((resolve, reject) => {
659
- if (this.checkWCUrl(i18nViewUrl)) {
660
- this.dynamicImport(i18nViewUrl)
661
- .then(module => {
662
- try {
663
- if (!window.customElements.get(wc_id)) {
664
- let cmpClazz = module.default;
665
- if (!HTMLElement.isPrototypeOf(cmpClazz)) {
666
- let props = Object.keys(module);
667
- for (let i = 0; i < props.length; i++) {
668
- cmpClazz = module[props[i]];
669
- if (HTMLElement.isPrototypeOf(cmpClazz)) {
670
- break;
671
- }
672
- }
673
- }
674
- window.customElements.define(wc_id, cmpClazz);
675
- }
676
- resolve(1);
677
- } catch (e) {
678
- reject(e);
679
- }
680
- })
681
- .catch(err => reject(err));
682
- } else {
683
- console.warn(`View URL '${i18nViewUrl}' not allowed to be included`);
684
- reject(`View URL '${i18nViewUrl}' not allowed`);
685
- }
686
- });
687
- }
688
- /**
689
- * Handles the import of self registered web component bundles, i.e. the web component
690
- * is added to the customElements registry by the bundle code rather than by luigi.
691
- *
692
- * @param {*} node the corresponding navigation node
693
- * @param {*} viewUrl the source of the wc bundle
694
- * @param {*} onload callback function executed after script attached and loaded
695
- */
696
- includeSelfRegisteredWCFromUrl(node, viewUrl, onload) {
697
- if (this.checkWCUrl(viewUrl)) {
698
- /** Append reg function to luigi object if not present */
699
- if (!this.containerService.getContainerManager()._registerWebcomponent) {
700
- this.containerService.getContainerManager()._registerWebcomponent = (srcString, el) => {
701
- window.customElements.define(this.generateWCId(srcString), el);
702
- };
703
- }
704
- let scriptTag = document.createElement('script');
705
- scriptTag.setAttribute('src', viewUrl);
706
- if (node.webcomponent.type === 'module') {
707
- scriptTag.setAttribute('type', 'module');
708
- }
709
- scriptTag.setAttribute('defer', 'true');
710
- scriptTag.addEventListener('load', () => {
711
- onload();
712
- });
713
- document.body.appendChild(scriptTag);
714
- } else {
715
- console.warn(`View URL '${viewUrl}' not allowed to be included`);
716
- }
717
- }
718
- /**
719
- * Checks if a url is allowed to be included, based on 'navigation.validWebcomponentUrls' in luigi config.
720
- * Returns true, if allowed.
721
- *
722
- * @param {*} url the url string to check
723
- */
724
- checkWCUrl(url) {
725
- // if (url.indexOf('://') > 0 || url.trim().indexOf('//') === 0) {
726
- // const ur = new URL(url);
727
- // if (ur.host === window.location.host) {
728
- // return true; // same host is okay
729
- // }
730
- // const valids = LuigiConfig.getConfigValue('navigation.validWebcomponentUrls');
731
- // if (valids && valids.length > 0) {
732
- // for (let el of valids) {
733
- // try {
734
- // if (new RegExp(el).test(url)) {
735
- // return true;
736
- // }
737
- // } catch (e) {
738
- // console.error(e);
739
- // }
740
- // }
741
- // }
742
- // return false;
743
- // }
744
- // relative URL is okay
745
- return true;
746
- }
747
- /** Adds a web component defined by viewUrl to the wc_container and sets the node context.
748
- * If the web component is not defined yet, it gets imported.
749
- */
750
- renderWebComponent(viewUrl, wc_container, context, node, nodeId) {
751
- const i18nViewUrl = this.processViewUrl(viewUrl, { context });
752
- const wc_id =
753
- node.webcomponent && node.webcomponent.tagName ? node.webcomponent.tagName : this.generateWCId(i18nViewUrl);
754
- const wcItemPlaceholder = document.createElement('div');
755
- wc_container.appendChild(wcItemPlaceholder);
756
- wc_container._luigi_node = node;
757
- if (window.customElements.get(wc_id)) {
758
- this.attachWC(wc_id, wcItemPlaceholder, wc_container, context, i18nViewUrl, nodeId);
759
- } else {
760
- /** Custom import function, if defined */
761
- if (window.luigiWCFn) {
762
- window.luigiWCFn(i18nViewUrl, wc_id, wcItemPlaceholder, () => {
763
- this.attachWC(wc_id, wcItemPlaceholder, wc_container, context, i18nViewUrl, nodeId);
764
- });
765
- } else if (node.webcomponent && node.webcomponent.selfRegistered) {
766
- this.includeSelfRegisteredWCFromUrl(node, i18nViewUrl, () => {
767
- this.attachWC(wc_id, wcItemPlaceholder, wc_container, context, i18nViewUrl, nodeId);
768
- });
769
- } else {
770
- this.registerWCFromUrl(i18nViewUrl, wc_id).then(() => {
771
- this.attachWC(wc_id, wcItemPlaceholder, wc_container, context, i18nViewUrl, nodeId);
772
- });
773
- }
774
- }
775
- }
776
- /**
777
- * Creates a compound container according to the given renderer.
778
- * Returns a promise that gets resolved with the created container DOM element.
779
- *
780
- * @param {DefaultCompoundRenderer} renderer
781
- */
782
- createCompoundContainerAsync(renderer, ctx) {
783
- return new Promise((resolve, reject) => {
784
- if (renderer.viewUrl) {
785
- try {
786
- const wc_id = this.generateWCId(renderer.viewUrl);
787
- this.registerWCFromUrl(renderer.viewUrl, wc_id).then(() => {
788
- const wc = document.createElement(wc_id);
789
- this.initWC(wc, wc_id, wc, renderer.viewUrl, ctx, '_root');
790
- resolve(wc);
791
- });
792
- } catch (e) {
793
- reject(e);
794
- }
795
- } else {
796
- resolve(renderer.createCompoundContainer());
797
- }
798
- });
799
- }
800
- /**
801
- * Responsible for rendering web component compounds based on a renderer or a nesting
802
- * micro frontend.
803
- *
804
- * @param {*} navNode the navigation node defining the compound
805
- * @param {*} wc_container the web component container dom element
806
- * @param {*} context the luigi node context
807
- */
808
- renderWebComponentCompound(navNode, wc_container, context) {
809
- var _a;
810
- let renderer;
811
- if (navNode.webcomponent && navNode.viewUrl) {
812
- renderer = new DefaultCompoundRenderer();
813
- renderer.viewUrl = this.processViewUrl(navNode.viewUrl, { context });
814
- renderer.createCompoundItemContainer = layoutConfig => {
815
- var cnt = document.createElement('div');
816
- if (layoutConfig && layoutConfig.slot) {
817
- cnt.setAttribute('slot', layoutConfig.slot);
818
- }
819
- return cnt;
820
- };
821
- } else if ((_a = navNode.compound) === null || _a === void 0 ? void 0 : _a.renderer) {
822
- renderer = resolveRenderer(navNode.compound.renderer);
823
- }
824
- renderer = renderer || new DefaultCompoundRenderer();
825
- return new Promise(resolve => {
826
- this.createCompoundContainerAsync(renderer, context).then(compoundCnt => {
827
- var _a;
828
- const ebListeners = {};
829
- compoundCnt.eventBus = {
830
- listeners: ebListeners,
831
- onPublishEvent: (event, srcNodeId, wcId) => {
832
- const listeners = ebListeners[srcNodeId + '.' + event.type] || [];
833
- listeners.push(...(ebListeners['*.' + event.type] || []));
834
- listeners.forEach(listenerInfo => {
835
- const target =
836
- listenerInfo.wcElement || compoundCnt.querySelector('[nodeId=' + listenerInfo.wcElementId + ']');
837
- if (target) {
838
- target.dispatchEvent(
839
- new CustomEvent(listenerInfo.action, {
840
- detail: listenerInfo.converter ? listenerInfo.converter(event.detail) : event.detail
841
- })
842
- );
843
- } else {
844
- console.debug('Could not find event target', listenerInfo);
845
- }
846
- });
847
- }
848
- };
849
- (_a = navNode.compound) === null || _a === void 0
850
- ? void 0
851
- : _a.children.forEach((wc, index) => {
852
- const ctx = Object.assign(Object.assign({}, context), wc.context);
853
- const compoundItemCnt = renderer.createCompoundItemContainer(wc.layoutConfig);
854
- compoundItemCnt.eventBus = compoundCnt.eventBus;
855
- renderer.attachCompoundItem(compoundCnt, compoundItemCnt);
856
- const nodeId = wc.id || 'gen_' + index;
857
- this.renderWebComponent(wc.viewUrl, compoundItemCnt, ctx, wc, nodeId);
858
- registerEventListeners(ebListeners, wc, nodeId);
859
- });
860
- wc_container.appendChild(compoundCnt);
861
- // listener for nesting wc
862
- registerEventListeners(ebListeners, navNode.compound, '_root', compoundCnt);
863
- resolve(compoundCnt);
864
- });
865
- });
866
- }
867
- }
868
-
869
- /* src/LuigiContainer.svelte generated by Svelte v3.46.4 */
870
-
871
- const { console: console_1$1 } = globals;
872
- const file$1 = 'src/LuigiContainer.svelte';
873
-
874
- // (87:1) {#if !deferInit}
875
- function create_if_block(ctx) {
876
- let show_if = !(/*isWebComponent*/ ctx[5]());
877
- let if_block_anchor;
878
- let if_block = show_if && create_if_block_1(ctx);
879
-
880
- const block = {
881
- c: function create() {
882
- if (if_block) if_block.c();
883
- if_block_anchor = empty();
884
- },
885
- m: function mount(target, anchor) {
886
- if (if_block) if_block.m(target, anchor);
887
- insert_dev(target, if_block_anchor, anchor);
888
- },
889
- p: function update(ctx, dirty) {
890
- if (show_if) if_block.p(ctx, dirty);
891
- },
892
- d: function destroy(detaching) {
893
- if (if_block) if_block.d(detaching);
894
- if (detaching) detach_dev(if_block_anchor);
895
- }
896
- };
897
-
898
- dispatch_dev('SvelteRegisterBlock', {
899
- block,
900
- id: create_if_block.name,
901
- type: 'if',
902
- source: '(87:1) {#if !deferInit}',
903
- ctx
904
- });
905
-
906
- return block;
907
- }
908
-
909
- // (88:2) {#if !isWebComponent()}
910
- function create_if_block_1(ctx) {
911
- let iframe;
912
- let iframe_src_value;
913
-
914
- const block = {
915
- c: function create() {
916
- iframe = element('iframe');
917
- if (!src_url_equal(iframe.src, (iframe_src_value = /*viewurl*/ ctx[0])))
918
- attr_dev(iframe, 'src', iframe_src_value);
919
- attr_dev(iframe, 'title', /*label*/ ctx[1]);
920
- add_location(iframe, file$1, 88, 3, 2288);
921
- },
922
- m: function mount(target, anchor) {
923
- insert_dev(target, iframe, anchor);
924
- /*iframe_binding*/ ctx[8](iframe);
925
- },
926
- p: function update(ctx, dirty) {
927
- if (dirty & /*viewurl*/ 1 && !src_url_equal(iframe.src, (iframe_src_value = /*viewurl*/ ctx[0]))) {
928
- attr_dev(iframe, 'src', iframe_src_value);
929
- }
930
-
931
- if (dirty & /*label*/ 2) {
932
- attr_dev(iframe, 'title', /*label*/ ctx[1]);
933
- }
934
- },
935
- d: function destroy(detaching) {
936
- if (detaching) detach_dev(iframe);
937
- /*iframe_binding*/ ctx[8](null);
938
- }
939
- };
940
-
941
- dispatch_dev('SvelteRegisterBlock', {
942
- block,
943
- id: create_if_block_1.name,
944
- type: 'if',
945
- source: '(88:2) {#if !isWebComponent()}',
946
- ctx
947
- });
948
-
949
- return block;
950
- }
951
-
952
- function create_fragment$1(ctx) {
953
- let main;
954
- let if_block = !(/*deferInit*/ ctx[4]) && create_if_block(ctx);
955
-
956
- const block = {
957
- c: function create() {
958
- main = element('main');
959
- if (if_block) if_block.c();
960
- this.c = noop;
961
- attr_dev(main, 'class', /*isWebComponent*/ ctx[5]() ? undefined : 'lui-isolated');
962
- add_location(main, file$1, 85, 0, 2154);
963
- },
964
- l: function claim(nodes) {
965
- throw new Error('options.hydrate only works if the component was compiled with the `hydratable: true` option');
966
- },
967
- m: function mount(target, anchor) {
968
- insert_dev(target, main, anchor);
969
- if (if_block) if_block.m(main, null);
970
- /*main_binding*/ ctx[9](main);
971
- },
972
- p: function update(ctx, [dirty]) {
973
- if (!(/*deferInit*/ ctx[4])) {
974
- if (if_block) {
975
- if_block.p(ctx, dirty);
976
- } else {
977
- if_block = create_if_block(ctx);
978
- if_block.c();
979
- if_block.m(main, null);
980
- }
981
- } else if (if_block) {
982
- if_block.d(1);
983
- if_block = null;
984
- }
985
- },
986
- i: noop,
987
- o: noop,
988
- d: function destroy(detaching) {
989
- if (detaching) detach_dev(main);
990
- if (if_block) if_block.d();
991
- /*main_binding*/ ctx[9](null);
992
- }
993
- };
994
-
995
- dispatch_dev('SvelteRegisterBlock', {
996
- block,
997
- id: create_fragment$1.name,
998
- type: 'component',
999
- source: '',
1000
- ctx
1001
- });
1002
-
1003
- return block;
1004
- }
1005
-
1006
- function instance$1($$self, $$props, $$invalidate) {
1007
- let { $$slots: slots = {}, $$scope } = $$props;
1008
- validate_slots('undefined', slots, []);
1009
- let { viewurl } = $$props;
1010
- let { context } = $$props;
1011
- let { label } = $$props;
1012
- let { webcomponent } = $$props;
1013
- let iframeHandle = {};
1014
- let mainComponent;
1015
- const containerService = new ContainerService();
1016
- const webcomponentService = new WebComponentService();
1017
-
1018
- webcomponentService.createClientAPI = (eventBusElement, nodeId, wc_id) => {
1019
- return {
1020
- linkManager: () => {
1021
- return {
1022
- navigate: route => {
1023
- dispatchLuigiEvent('navigation-request', { link: route });
1024
- }
1025
- };
1026
- },
1027
- uxManager: () => {
1028
- return {
1029
- showAlert: alertSettings => {
1030
- dispatchLuigiEvent('alert-request', alertSettings);
1031
- },
1032
- showConfirmationModal: async settings => {
1033
- return new Promise((resolve, reject) => {
1034
- dispatchLuigiEvent('confirmation-request', settings, data => {
1035
- if (data) {
1036
- resolve(data);
1037
- } else {
1038
- reject();
1039
- }
1040
- });
1041
- });
1042
- }
1043
- };
1044
- }, //window.Luigi.ux,
1045
- getCurrentLocale: () => {}, //() => window.Luigi.i18n().getCurrentLocale(),
1046
- publishEvent: ev => {} // if (eventBusElement.eventBus) {
1047
- // eventBusElement.eventBus.onPublishEvent(ev, nodeId, wc_id);
1048
- // }
1049
- };
1050
- };
1051
-
1052
- const thisComponent = get_current_component();
1053
- thisComponent.iframeHandle = iframeHandle;
1054
- let deferInit = !!thisComponent.attributes['defer-init'];
1055
-
1056
- thisComponent.init = () => {
1057
- $$invalidate(4, (deferInit = false));
1058
- };
1059
-
1060
- containerService.registerContainer(thisComponent);
1061
-
1062
- function dispatchLuigiEvent(msg, data, callback) {
1063
- containerService.dispatch(msg, thisComponent, data, callback);
1064
- }
1065
-
1066
- function isWebComponent() {
1067
- return !!webcomponent;
1068
- }
1069
-
1070
- onMount(async () => {
1071
- const ctx = context ? JSON.parse(context) : undefined;
1072
- console.log(ctx);
1073
-
1074
- if (isWebComponent()) {
1075
- $$invalidate(3, (mainComponent.innerHTML = ''), mainComponent);
1076
- webcomponentService.renderWebComponent(viewurl, mainComponent, ctx, {});
1077
- }
1078
- });
1079
-
1080
- onDestroy(async () => {});
1081
-
1082
- const writable_props = ['viewurl', 'context', 'label', 'webcomponent'];
1083
-
1084
- Object.keys($$props).forEach(key => {
1085
- if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot')
1086
- console_1$1.warn(`<undefined> was created with unknown prop '${key}'`);
1087
- });
1088
-
1089
- function iframe_binding($$value) {
1090
- binding_callbacks[$$value ? 'unshift' : 'push'](() => {
1091
- iframeHandle.iframe = $$value;
1092
- $$invalidate(2, iframeHandle);
1093
- });
1094
- }
1095
-
1096
- function main_binding($$value) {
1097
- binding_callbacks[$$value ? 'unshift' : 'push'](() => {
1098
- mainComponent = $$value;
1099
- $$invalidate(3, mainComponent);
1100
- });
1101
- }
1102
-
1103
- $$self.$$set = $$props => {
1104
- if ('viewurl' in $$props) $$invalidate(0, (viewurl = $$props.viewurl));
1105
- if ('context' in $$props) $$invalidate(6, (context = $$props.context));
1106
- if ('label' in $$props) $$invalidate(1, (label = $$props.label));
1107
- if ('webcomponent' in $$props) $$invalidate(7, (webcomponent = $$props.webcomponent));
1108
- };
1109
-
1110
- $$self.$capture_state = () => ({
1111
- viewurl,
1112
- context,
1113
- label,
1114
- webcomponent,
1115
- iframeHandle,
1116
- mainComponent,
1117
- onMount,
1118
- onDestroy,
1119
- get_current_component,
1120
- ContainerService,
1121
- WebComponentService,
1122
- containerService,
1123
- webcomponentService,
1124
- thisComponent,
1125
- deferInit,
1126
- dispatchLuigiEvent,
1127
- isWebComponent
1128
- });
1129
-
1130
- $$self.$inject_state = $$props => {
1131
- if ('viewurl' in $$props) $$invalidate(0, (viewurl = $$props.viewurl));
1132
- if ('context' in $$props) $$invalidate(6, (context = $$props.context));
1133
- if ('label' in $$props) $$invalidate(1, (label = $$props.label));
1134
- if ('webcomponent' in $$props) $$invalidate(7, (webcomponent = $$props.webcomponent));
1135
- if ('iframeHandle' in $$props) $$invalidate(2, (iframeHandle = $$props.iframeHandle));
1136
- if ('mainComponent' in $$props) $$invalidate(3, (mainComponent = $$props.mainComponent));
1137
- if ('deferInit' in $$props) $$invalidate(4, (deferInit = $$props.deferInit));
1138
- };
1139
-
1140
- if ($$props && '$$inject' in $$props) {
1141
- $$self.$inject_state($$props.$$inject);
1142
- }
1143
-
1144
- return [
1145
- viewurl,
1146
- label,
1147
- iframeHandle,
1148
- mainComponent,
1149
- deferInit,
1150
- isWebComponent,
1151
- context,
1152
- webcomponent,
1153
- iframe_binding,
1154
- main_binding
1155
- ];
1156
- }
1157
-
1158
- class LuigiContainer extends SvelteElement {
1159
- constructor(options) {
1160
- super();
1161
- this.shadowRoot.innerHTML = `<style>main,iframe{width:100%;height:100%;border:none}main.lui-isolated{line-height:0}</style>`;
1162
-
1163
- init(
1164
- this,
1165
- {
1166
- target: this.shadowRoot,
1167
- props: attribute_to_object(this.attributes),
1168
- customElement: true
1169
- },
1170
- instance$1,
1171
- create_fragment$1,
1172
- safe_not_equal,
1173
- {
1174
- viewurl: 0,
1175
- context: 6,
1176
- label: 1,
1177
- webcomponent: 7
1178
- },
1179
- null
1180
- );
1181
-
1182
- const { ctx } = this.$$;
1183
- const props = this.attributes;
1184
-
1185
- if (/*viewurl*/ ctx[0] === undefined && !('viewurl' in props)) {
1186
- console_1$1.warn("<undefined> was created without expected prop 'viewurl'");
1187
- }
1188
-
1189
- if (/*context*/ ctx[6] === undefined && !('context' in props)) {
1190
- console_1$1.warn("<undefined> was created without expected prop 'context'");
1191
- }
1192
-
1193
- if (/*label*/ ctx[1] === undefined && !('label' in props)) {
1194
- console_1$1.warn("<undefined> was created without expected prop 'label'");
1195
- }
1196
-
1197
- if (/*webcomponent*/ ctx[7] === undefined && !('webcomponent' in props)) {
1198
- console_1$1.warn("<undefined> was created without expected prop 'webcomponent'");
1199
- }
1200
-
1201
- if (options) {
1202
- if (options.target) {
1203
- insert_dev(options.target, this, options.anchor);
1204
- }
1205
-
1206
- if (options.props) {
1207
- this.$set(options.props);
1208
- flush();
1209
- }
1210
- }
1211
- }
1212
-
1213
- static get observedAttributes() {
1214
- return ['viewurl', 'context', 'label', 'webcomponent'];
1215
- }
1216
-
1217
- get viewurl() {
1218
- return this.$$.ctx[0];
1219
- }
1220
-
1221
- set viewurl(viewurl) {
1222
- this.$$set({ viewurl });
1223
- flush();
1224
- }
1225
-
1226
- get context() {
1227
- return this.$$.ctx[6];
1228
- }
1229
-
1230
- set context(context) {
1231
- this.$$set({ context });
1232
- flush();
1233
- }
1234
-
1235
- get label() {
1236
- return this.$$.ctx[1];
1237
- }
1238
-
1239
- set label(label) {
1240
- this.$$set({ label });
1241
- flush();
1242
- }
1243
-
1244
- get webcomponent() {
1245
- return this.$$.ctx[7];
1246
- }
1247
-
1248
- set webcomponent(webcomponent) {
1249
- this.$$set({ webcomponent });
1250
- flush();
1251
- }
1252
- }
1253
-
1254
- /* src/LuigiCompoundContainer.svelte generated by Svelte v3.46.4 */
1255
-
1256
- const { console: console_1 } = globals;
1257
- const file = 'src/LuigiCompoundContainer.svelte';
1258
-
1259
- function create_fragment(ctx) {
1260
- let main;
1261
-
1262
- const block = {
1263
- c: function create() {
1264
- main = element('main');
1265
- this.c = noop;
1266
- add_location(main, file, 77, 0, 2189);
1267
- },
1268
- l: function claim(nodes) {
1269
- throw new Error('options.hydrate only works if the component was compiled with the `hydratable: true` option');
1270
- },
1271
- m: function mount(target, anchor) {
1272
- insert_dev(target, main, anchor);
1273
- /*main_binding*/ ctx[2](main);
1274
- },
1275
- p: noop,
1276
- i: noop,
1277
- o: noop,
1278
- d: function destroy(detaching) {
1279
- if (detaching) detach_dev(main);
1280
- /*main_binding*/ ctx[2](null);
1281
- }
1282
- };
1283
-
1284
- dispatch_dev('SvelteRegisterBlock', {
1285
- block,
1286
- id: create_fragment.name,
1287
- type: 'component',
1288
- source: '',
1289
- ctx
1290
- });
1291
-
1292
- return block;
1293
- }
1294
-
1295
- function instance($$self, $$props, $$invalidate) {
1296
- let { $$slots: slots = {}, $$scope } = $$props;
1297
- validate_slots('undefined', slots, []);
1298
- let { context } = $$props;
1299
-
1300
- // export let label;
1301
- let compoundConfig;
1302
-
1303
- let initialized = false;
1304
- let mainComponent;
1305
- let eventBusElement;
1306
- const containerService = new ContainerService();
1307
- const webcomponentService = new WebComponentService();
1308
-
1309
- webcomponentService.createClientAPI = (eventBusElement, nodeId, wc_id) => {
1310
- return {
1311
- linkManager: () => {}, //window.Luigi.navigation,
1312
- uxManager: () => {
1313
- return {
1314
- showAlert: alertSettings => {
1315
- dispatchLuigiEvent('alert-request', alertSettings);
1316
- },
1317
- showConfirmationModal: async settings => {
1318
- return new Promise((resolve, reject) => {
1319
- dispatchLuigiEvent('confirmation-request', settings, data => {
1320
- if (data) {
1321
- resolve(data);
1322
- } else {
1323
- reject();
1324
- }
1325
- });
1326
- });
1327
- }
1328
- };
1329
- }, //window.Luigi.ux,
1330
- getCurrentLocale: () => {}, //() => window.Luigi.i18n().getCurrentLocale(),
1331
- publishEvent: ev => {
1332
- console.log('pub', ev);
1333
-
1334
- if (eventBusElement && eventBusElement.eventBus) {
1335
- eventBusElement.eventBus.onPublishEvent(ev, nodeId, wc_id);
1336
- }
1337
- }
1338
- };
1339
- };
1340
-
1341
- const thisComponent = get_current_component();
1342
- let deferInit = !!thisComponent.attributes['defer-init'];
1343
-
1344
- thisComponent.init = () => {
1345
- if (!thisComponent.compoundConfig || initialized) return;
1346
- deferInit = false;
1347
- console.log('init compound');
1348
- const node = { compound: thisComponent.compoundConfig }; // TODO: fill with sth
1349
-
1350
- webcomponentService.renderWebComponentCompound(node, mainComponent, context).then(compCnt => {
1351
- eventBusElement = compCnt;
1352
- });
1353
-
1354
- initialized = true;
1355
- };
1356
-
1357
- containerService.registerContainer(thisComponent);
1358
-
1359
- function dispatchLuigiEvent(msg, data, callback) {
1360
- containerService.dispatch(msg, thisComponent, data, callback);
1361
- }
1362
-
1363
- onMount(async () => {
1364
- const ctx = context ? JSON.parse(context) : undefined;
1365
- console.log(ctx);
1366
- });
1367
-
1368
- const writable_props = ['context'];
1369
-
1370
- Object.keys($$props).forEach(key => {
1371
- if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot')
1372
- console_1.warn(`<undefined> was created with unknown prop '${key}'`);
1373
- });
1374
-
1375
- function main_binding($$value) {
1376
- binding_callbacks[$$value ? 'unshift' : 'push'](() => {
1377
- mainComponent = $$value;
1378
- $$invalidate(0, mainComponent);
1379
- });
1380
- }
1381
-
1382
- $$self.$$set = $$props => {
1383
- if ('context' in $$props) $$invalidate(1, (context = $$props.context));
1384
- };
1385
-
1386
- $$self.$capture_state = () => ({
1387
- context,
1388
- compoundConfig,
1389
- initialized,
1390
- mainComponent,
1391
- eventBusElement,
1392
- onMount,
1393
- get_current_component,
1394
- ContainerService,
1395
- WebComponentService,
1396
- containerService,
1397
- webcomponentService,
1398
- thisComponent,
1399
- deferInit,
1400
- dispatchLuigiEvent
1401
- });
1402
-
1403
- $$self.$inject_state = $$props => {
1404
- if ('context' in $$props) $$invalidate(1, (context = $$props.context));
1405
- if ('compoundConfig' in $$props) compoundConfig = $$props.compoundConfig;
1406
- if ('initialized' in $$props) initialized = $$props.initialized;
1407
- if ('mainComponent' in $$props) $$invalidate(0, (mainComponent = $$props.mainComponent));
1408
- if ('eventBusElement' in $$props) eventBusElement = $$props.eventBusElement;
1409
- if ('deferInit' in $$props) deferInit = $$props.deferInit;
1410
- };
1411
-
1412
- if ($$props && '$$inject' in $$props) {
1413
- $$self.$inject_state($$props.$$inject);
1414
- }
1415
-
1416
- return [mainComponent, context, main_binding];
1417
- }
1418
-
1419
- class LuigiCompoundContainer extends SvelteElement {
1420
- constructor(options) {
1421
- super();
1422
- this.shadowRoot.innerHTML = `<style>main{width:100%;height:100%;border:none}</style>`;
1423
-
1424
- init(
1425
- this,
1426
- {
1427
- target: this.shadowRoot,
1428
- props: attribute_to_object(this.attributes),
1429
- customElement: true
1430
- },
1431
- instance,
1432
- create_fragment,
1433
- safe_not_equal,
1434
- { context: 1 },
1435
- null
1436
- );
1437
-
1438
- const { ctx } = this.$$;
1439
- const props = this.attributes;
1440
-
1441
- if (/*context*/ ctx[1] === undefined && !('context' in props)) {
1442
- console_1.warn("<undefined> was created without expected prop 'context'");
1443
- }
1444
-
1445
- if (options) {
1446
- if (options.target) {
1447
- insert_dev(options.target, this, options.anchor);
1448
- }
1449
-
1450
- if (options.props) {
1451
- this.$set(options.props);
1452
- flush();
1453
- }
1454
- }
1455
- }
1456
-
1457
- static get observedAttributes() {
1458
- return ['context'];
1459
- }
1460
-
1461
- get context() {
1462
- return this.$$.ctx[1];
1463
- }
1464
-
1465
- set context(context) {
1466
- this.$$set({ context });
1467
- flush();
1468
- }
1469
- }
1470
-
1471
- export { LuigiCompoundContainer, LuigiContainer };
1472
- //# sourceMappingURL=bundle.js.map
1
+ function e(){}function t(e){return e()}function n(){return Object.create(null)}function o(e){e.forEach(t)}function r(e){return"function"==typeof e}function i(e,t){return e!=e?t==t:e!==t||e&&"object"==typeof e||"function"==typeof e}let s,c;function a(e,t){return s||(s=document.createElement("a")),s.href=t,e===s.href}function l(e,t,n){e.insertBefore(t,n||null)}function u(e){e.parentNode.removeChild(e)}function d(e){return document.createElement(e)}function m(){return e="",document.createTextNode(e);var e}function h(e,t,n){null==n?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function p(e){const t={};for(const n of e)t[n.name]=n.value;return t}function g(e){c=e}function f(){if(!c)throw new Error("Function called outside component initialization");return c}function C(e){f().$$.on_mount.push(e)}const w=[],b=[],$=[],v=[],x=Promise.resolve();let _=!1;function y(e){$.push(e)}const E=new Set;let W=0;function I(){const e=c;do{for(;W<w.length;){const e=w[W];W++,g(e),U(e.$$)}for(g(null),w.length=0,W=0;b.length;)b.pop()();for(let e=0;e<$.length;e+=1){const t=$[e];E.has(t)||(E.add(t),t())}$.length=0}while(w.length);for(;v.length;)v.pop()();_=!1,E.clear(),g(e)}function U(e){if(null!==e.fragment){e.update(),o(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(y)}}const R=new Set;function L(e,t){-1===e.$$.dirty[0]&&(w.push(e),_||(_=!0,x.then(I)),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function k(i,s,a,l,d,m,h,p=[-1]){const f=c;g(i);const C=i.$$={fragment:null,ctx:null,props:m,update:e,not_equal:d,bound:n(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(s.context||(f?f.$$.context:[])),callbacks:n(),dirty:p,skip_bound:!1,root:s.target||f.$$.root};h&&h(C.root);let w=!1;if(C.ctx=a?a(i,s.props||{},((e,t,...n)=>{const o=n.length?n[0]:t;return C.ctx&&d(C.ctx[e],C.ctx[e]=o)&&(!C.skip_bound&&C.bound[e]&&C.bound[e](o),w&&L(i,e)),t})):[],C.update(),w=!0,o(C.before_update),C.fragment=!!l&&l(C.ctx),s.target){if(s.hydrate){const e=function(e){return Array.from(e.childNodes)}(s.target);C.fragment&&C.fragment.l(e),e.forEach(u)}else C.fragment&&C.fragment.c();s.intro&&((b=i.$$.fragment)&&b.i&&(R.delete(b),b.i($))),function(e,n,i,s){const{fragment:c,on_mount:a,on_destroy:l,after_update:u}=e.$$;c&&c.m(n,i),s||y((()=>{const n=a.map(t).filter(r);l?l.push(...n):o(n),e.$$.on_mount=[]})),u.forEach(y)}(i,s.target,s.anchor,s.customElement),I()}var b,$;g(f)}let M;"function"==typeof HTMLElement&&(M=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}connectedCallback(){const{on_mount:e}=this.$$;this.$$.on_disconnect=e.map(t).filter(r);for(const e in this.$$.slotted)this.appendChild(this.$$.slotted[e])}attributeChangedCallback(e,t,n){this[e]=n}disconnectedCallback(){o(this.$$.on_disconnect)}$destroy(){!function(e,t){const n=e.$$;null!==n.fragment&&(o(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}(this,1),this.$destroy=e}$on(e,t){const n=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return n.push(t),()=>{const e=n.indexOf(t);-1!==e&&n.splice(e,1)}}$set(e){var t;this.$$set&&(t=e,0!==Object.keys(t).length)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}});class A{constructor(){}isVisible(e){return!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)}dispatch(e,t,n,o){let r=new CustomEvent(e,{detail:n});r.luigiCallback=e=>{o&&o(e)},t.dispatchEvent(r),console.log("Dispatch WC event:",e,t,n)}getTargetContainer(e){let t;return globalThis.__luigi_container_manager.container.forEach((n=>{var o;(null===(o=n.iframeHandle)||void 0===o?void 0:o.iframe)&&n.iframeHandle.iframe.contentWindow===e.source&&(t=n)})),t}getContainerManager(){return globalThis.__luigi_container_manager||(globalThis.__luigi_container_manager={container:[],messageListener:e=>{var t,n,o,r;const i=this.getTargetContainer(e),s=null===(n=null===(t=null==i?void 0:i.iframeHandle)||void 0===t?void 0:t.iframe)||void 0===n?void 0:n.contentWindow;if(console.log("Container event",e,i),s===e.source&&0===(null===(r=null===(o=e.data)||void 0===o?void 0:o.msg)||void 0===r?void 0:r.indexOf("luigi."))){const t=e.data.msg;switch(t){case"luigi.get-context":s.postMessage({msg:"luigi.init",context:i.context,internal:{}},"*");break;case"luigi.navigation.open":this.dispatch("navigation-request",i,e.data.params);break;case"luigi.ux.alert.show":this.dispatch("alert-request",i,e.data.params);break;default:console.warn("Functionality not yet implemented: ",t)}}}},window.addEventListener("message",globalThis.__luigi_container_manager.messageListener)),globalThis.__luigi_container_manager}registerContainer(e){this.getContainerManager().container.push(e)}}class O{constructor(e){e?(this.rendererObject=e,this.config=e.config||{}):this.config={}}createCompoundContainer(){return document.createElement("div")}createCompoundItemContainer(e){return document.createElement("div")}attachCompoundItem(e,t){e.appendChild(t)}}class P extends O{constructor(e){super(e||{use:{}}),e&&e.use&&e.use.extends&&(this.superRenderer=H({use:e.use.extends,config:e.config}))}createCompoundContainer(){return this.rendererObject.use.createCompoundContainer?this.rendererObject.use.createCompoundContainer(this.config,this.superRenderer):this.superRenderer?this.superRenderer.createCompoundContainer():super.createCompoundContainer()}createCompoundItemContainer(e){return this.rendererObject.use.createCompoundItemContainer?this.rendererObject.use.createCompoundItemContainer(e,this.config,this.superRenderer):this.superRenderer?this.superRenderer.createCompoundItemContainer(e):super.createCompoundItemContainer(e)}attachCompoundItem(e,t){this.rendererObject.use.attachCompoundItem?this.rendererObject.use.attachCompoundItem(e,t,this.superRenderer):this.superRenderer?this.superRenderer.attachCompoundItem(e,t):super.attachCompoundItem(e,t)}}class T extends O{createCompoundContainer(){const e="__lui_compound_"+(new Date).getTime(),t=document.createElement("div");t.classList.add(e);let n="";return this.config.layouts&&this.config.layouts.forEach((t=>{if(t.minWidth||t.maxWidth){let o="@media only screen ";null!=t.minWidth&&(o+=`and (min-width: ${t.minWidth}px) `),null!=t.maxWidth&&(o+=`and (max-width: ${t.maxWidth}px) `),o+=`{\n .${e} {\n grid-template-columns: ${t.columns||"auto"};\n grid-template-rows: ${t.rows||"auto"};\n grid-gap: ${t.gap||"0"};\n }\n }\n `,n+=o}})),t.innerHTML=`\n <style scoped>\n .${e} {\n display: grid;\n grid-template-columns: ${this.config.columns||"auto"};\n grid-template-rows: ${this.config.rows||"auto"};\n grid-gap: ${this.config.gap||"0"};\n min-height: ${this.config.minHeight||"auto"};\n }\n ${n}\n </style>\n `,t}createCompoundItemContainer(e){const t=e||{},n=document.createElement("div");return n.setAttribute("style",`grid-row: ${t.row||"auto"}; grid-column: ${t.column||"auto"}`),n}}const H=e=>{const t=e.use;return t?"grid"===t?new T(e):t.createCompoundContainer||t.createCompoundItemContainer||t.attachCompoundItem?new P(e):new O(e):new O(e)},j=(e,t,n,o)=>{(null==t?void 0:t.eventListeners)&&t.eventListeners.forEach((t=>{const r=t.source+"."+t.name,i=e[r],s={wcElementId:n,wcElement:o,action:t.action,converter:t.dataConverter};i?i.push(s):e[r]=[s]}))};class S{constructor(){this.containerService=new A}dynamicImport(e){return import(e)}processViewUrl(e,t){return e}attachWC(e,t,n,o,r,i){if(n&&n.contains(t)){const s=document.createElement(e);i&&s.setAttribute("nodeId",i),this.initWC(s,e,n,r,o,i),n.replaceChild(s,t)}}createClientAPI(e,t,n){return{linkManager:()=>{},uxManager:()=>({showAlert:e=>{},showConfirmationModal:async e=>new Promise(((e,t)=>{e(!0)}))}),getCurrentLocale:()=>{},publishEvent:e=>{}}}initWC(e,t,n,o,r,i){const s=this.createClientAPI(n,i,t);if(e.__postProcess){const t=new URL(document.baseURI).origin===new URL(o,document.baseURI).origin?new URL("./",new URL(o,document.baseURI)):new URL("./",o);e.__postProcess(r,s,t.origin+t.pathname)}else e.context=r,e.LuigiClient=s}generateWCId(e){let t="";for(let n=0;n<e.length;n++)t+=e.charCodeAt(n).toString(16);return"luigi-wc-"+t}registerWCFromUrl(e,t){const n=this.processViewUrl(e);return new Promise(((e,o)=>{this.checkWCUrl(n)?this.dynamicImport(n).then((n=>{try{if(!window.customElements.get(t)){let e=n.default;if(!HTMLElement.isPrototypeOf(e)){let t=Object.keys(n);for(let o=0;o<t.length&&(e=n[t[o]],!HTMLElement.isPrototypeOf(e));o++);}window.customElements.define(t,e)}e(1)}catch(e){o(e)}})).catch((e=>o(e))):(console.warn(`View URL '${n}' not allowed to be included`),o(`View URL '${n}' not allowed`))}))}includeSelfRegisteredWCFromUrl(e,t,n){if(this.checkWCUrl(t)){this.containerService.getContainerManager()._registerWebcomponent||(this.containerService.getContainerManager()._registerWebcomponent=(e,t)=>{window.customElements.define(this.generateWCId(e),t)});let o=document.createElement("script");o.setAttribute("src",t),"module"===e.webcomponent.type&&o.setAttribute("type","module"),o.setAttribute("defer","true"),o.addEventListener("load",(()=>{n()})),document.body.appendChild(o)}else console.warn(`View URL '${t}' not allowed to be included`)}checkWCUrl(e){return!0}renderWebComponent(e,t,n,o,r){const i=this.processViewUrl(e,{context:n}),s=o.webcomponent&&o.webcomponent.tagName?o.webcomponent.tagName:this.generateWCId(i),c=document.createElement("div");t.appendChild(c),t._luigi_node=o,window.customElements.get(s)?this.attachWC(s,c,t,n,i,r):window.luigiWCFn?window.luigiWCFn(i,s,c,(()=>{this.attachWC(s,c,t,n,i,r)})):o.webcomponent&&o.webcomponent.selfRegistered?this.includeSelfRegisteredWCFromUrl(o,i,(()=>{this.attachWC(s,c,t,n,i,r)})):this.registerWCFromUrl(i,s).then((()=>{this.attachWC(s,c,t,n,i,r)}))}createCompoundContainerAsync(e,t){return new Promise(((n,o)=>{if(e.viewUrl)try{const o=this.generateWCId(e.viewUrl);this.registerWCFromUrl(e.viewUrl,o).then((()=>{const r=document.createElement(o);this.initWC(r,o,r,e.viewUrl,t,"_root"),n(r)}))}catch(e){o(e)}else n(e.createCompoundContainer())}))}renderWebComponentCompound(e,t,n){var o;let r;return e.webcomponent&&e.viewUrl?(r=new O,r.viewUrl=this.processViewUrl(e.viewUrl,{context:n}),r.createCompoundItemContainer=e=>{var t=document.createElement("div");return e&&e.slot&&t.setAttribute("slot",e.slot),t}):(null===(o=e.compound)||void 0===o?void 0:o.renderer)&&(r=H(e.compound.renderer)),r=r||new O,new Promise((o=>{this.createCompoundContainerAsync(r,n).then((i=>{var s;const c={};i.eventBus={listeners:c,onPublishEvent:(e,t,n)=>{const o=c[t+"."+e.type]||[];o.push(...c["*."+e.type]||[]),o.forEach((t=>{const n=t.wcElement||i.querySelector("[nodeId="+t.wcElementId+"]");n?n.dispatchEvent(new CustomEvent(t.action,{detail:t.converter?t.converter(e.detail):e.detail})):console.debug("Could not find event target",t)}))}},null===(s=e.compound)||void 0===s||s.children.forEach(((e,t)=>{const o=Object.assign(Object.assign({},n),e.context),s=r.createCompoundItemContainer(e.layoutConfig);s.eventBus=i.eventBus,r.attachCompoundItem(i,s);const a=e.id||"gen_"+t;this.renderWebComponent(e.viewUrl,s,o,e,a),j(c,e,a)})),t.appendChild(i),j(c,e.compound,"_root",i),o(i)}))}))}}function q(e){let t,n=!e[5](),o=n&&function(e){let t,n;return{c(){t=d("iframe"),a(t.src,n=e[0])||h(t,"src",n),h(t,"title",e[1])},m(n,o){l(n,t,o),e[8](t)},p(e,o){1&o&&!a(t.src,n=e[0])&&h(t,"src",n),2&o&&h(t,"title",e[1])},d(n){n&&u(t),e[8](null)}}}(e);return{c(){o&&o.c(),t=m()},m(e,n){o&&o.m(e,n),l(e,t,n)},p(e,t){n&&o.p(e,t)},d(e){o&&o.d(e),e&&u(t)}}}function F(t){let n,o=!t[4]&&q(t);return{c(){n=d("main"),o&&o.c(),this.c=e,h(n,"class",t[5]()?void 0:"lui-isolated")},m(e,r){l(e,n,r),o&&o.m(n,null),t[9](n)},p(e,[t]){e[4]?o&&(o.d(1),o=null):o?o.p(e,t):(o=q(e),o.c(),o.m(n,null))},i:e,o:e,d(e){e&&u(n),o&&o.d(),t[9](null)}}}function V(e,t,n){let o,{viewurl:r}=t,{context:i}=t,{label:s}=t,{webcomponent:c}=t,a={};const l=new A,u=new S;u.createClientAPI=(e,t,n)=>({linkManager:()=>({navigate:e=>{h("navigation-request",{link:e},{})}}),uxManager:()=>({showAlert:e=>{h("alert-request",e,{})},showConfirmationModal:async e=>new Promise(((t,n)=>{h("confirmation-request",e,(e=>{e?t(e):n()}))}))}),getCurrentLocale:()=>{},publishEvent:e=>{}});const d=f();console.log(d.iframeHandle),d.iframeHandle=a,console.log(d.iframeHandle);let m=!!d.attributes["defer-init"];function h(e,t,n){l.dispatch(e,d,t,n)}function p(){return!!c}var g;return d.init=()=>{n(4,m=!1)},l.registerContainer(d),C((async()=>{const e=i?JSON.parse(i):void 0;console.log(e),p()&&(n(3,o.innerHTML="",o),u.renderWebComponent(r,o,e,{},{}))})),g=async()=>{},f().$$.on_destroy.push(g),e.$$set=e=>{"viewurl"in e&&n(0,r=e.viewurl),"context"in e&&n(6,i=e.context),"label"in e&&n(1,s=e.label),"webcomponent"in e&&n(7,c=e.webcomponent)},[r,s,a,o,m,p,i,c,function(e){b[e?"unshift":"push"]((()=>{a.iframe=e,n(2,a)}))},function(e){b[e?"unshift":"push"]((()=>{o=e,n(3,o)}))}]}class N extends M{constructor(e){super(),this.shadowRoot.innerHTML="<style>main,iframe{width:100%;height:100%;border:none}main.lui-isolated{line-height:0}</style>",k(this,{target:this.shadowRoot,props:p(this.attributes),customElement:!0},V,F,i,{viewurl:0,context:6,label:1,webcomponent:7},null),e&&(e.target&&l(e.target,this,e.anchor),e.props&&(this.$set(e.props),I()))}static get observedAttributes(){return["viewurl","context","label","webcomponent"]}get viewurl(){return this.$$.ctx[0]}set viewurl(e){this.$$set({viewurl:e}),I()}get context(){return this.$$.ctx[6]}set context(e){this.$$set({context:e}),I()}get label(){return this.$$.ctx[1]}set label(e){this.$$set({label:e}),I()}get webcomponent(){return this.$$.ctx[7]}set webcomponent(e){this.$$set({webcomponent:e}),I()}}function B(t){let n;return{c(){n=d("main"),this.c=e},m(e,o){l(e,n,o),t[2](n)},p:e,i:e,o:e,d(e){e&&u(n),t[2](null)}}}function D(e,t,n){let o,{context:r}=t,i=!1;const s=new A,c=new S;c.createClientAPI=(e,t,n)=>({linkManager:()=>{},uxManager:()=>({showAlert:e=>{l("alert-request",e,{})},showConfirmationModal:async e=>new Promise(((t,n)=>{l("confirmation-request",e,(e=>{e?t(e):n()}))}))}),getCurrentLocale:()=>{},publishEvent:o=>{console.log("pub",o),e&&e.eventBus&&e.eventBus.onPublishEvent(o,t,n)}});const a=f();function l(e,t,n){s.dispatch(e,a,t,n)}return a.attributes["defer-init"],a.init=()=>{if(!a.compoundConfig||i)return;console.log("init compound");const e={compound:a.compoundConfig};c.renderWebComponentCompound(e,o,r).then((e=>{})),i=!0},s.registerContainer(a),C((async()=>{const e=r?JSON.parse(r):void 0;console.log(e)})),e.$$set=e=>{"context"in e&&n(1,r=e.context)},[o,r,function(e){b[e?"unshift":"push"]((()=>{o=e,n(0,o)}))}]}class J extends M{constructor(e){super(),this.shadowRoot.innerHTML="<style>main{width:100%;height:100%;border:none}</style>",k(this,{target:this.shadowRoot,props:p(this.attributes),customElement:!0},D,B,i,{context:1},null),e&&(e.target&&l(e.target,this,e.anchor),e.props&&(this.$set(e.props),I()))}static get observedAttributes(){return["context"]}get context(){return this.$$.ctx[1]}set context(e){this.$$set({context:e}),I()}}export{J as LuigiCompoundContainer,N as LuigiContainer};
2
+ //# sourceMappingURL=bundle.js.map