@telia-ace/knowledge-widget-core 1.1.1-rc.2 → 1.1.1-rc.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.
Files changed (3) hide show
  1. package/index.js +1 -3
  2. package/index.mjs +19 -2072
  3. package/package.json +2 -2
package/index.mjs CHANGED
@@ -1,2077 +1,24 @@
1
- class Se {
2
- constructor(t) {
3
- const { events: e } = t.get("$widget");
4
- this.events = e.createChild(this);
5
- }
6
- action(t, e, n) {
7
- this.events.dispatch("data:action", { action: e, value: n, target: t }, { bubbles: !0 });
8
- }
9
- subscribe(t, e) {
10
- return this.events.subscribe(
11
- "data:action",
12
- (n, { action: i, value: r, target: o }) => t === o && e(t, i, r)
13
- );
14
- }
15
- }
16
- const j = (s, t, e, ...n) => {
17
- const i = `[${s.get("$environment").name || "webprovisions"}] ${e}`;
18
- switch (t) {
19
- case "info":
20
- console.info(i, ...n);
21
- break;
22
- case "warning":
23
- console.warn(i, ...n);
24
- break;
25
- case "error":
26
- console.error(i, ...n);
27
- break;
28
- }
29
- }, wt = (s) => {
30
- const t = s.container || s;
31
- return {
32
- info: (e, ...n) => j(t, "info", e, ...n),
33
- warn: (e, ...n) => j(t, "warning", e, ...n),
34
- error: (e, ...n) => j(t, "error", e, ...n)
35
- };
36
- }, ct = (s, t) => {
37
- if (!t)
38
- return !0;
39
- if (typeof t == "string") {
40
- const e = t.split(",");
41
- for (let n = 0, i = e.length; n < i; n++) {
42
- const r = e[n].trim();
43
- if (r === s || r === "*")
44
- return !0;
45
- }
46
- }
47
- return t instanceof Array ? t.indexOf(s) > -1 : !1;
48
- }, Mt = (s, t) => {
49
- if (typeof t == "function")
50
- return t(s);
51
- const e = typeof t == "string" ? St(t) : t;
52
- return !(!ct(s.tenant || "", e.tenant || "") || !ct(s.name, e.implementation || ""));
53
- }, zt = (s) => (t) => Mt(t, s), W = (s) => s instanceof Array && s.length === 1 ? s[0] : s, St = (s) => {
54
- const t = {}, e = s.split(":");
55
- return e.length === 1 ? t.implementation = W(e[0].split(",")) : (t.tenant = W(e[0].split(",")), t.implementation = W(e[1].split(","))), t;
56
- };
57
- var R = /* @__PURE__ */ ((s) => (s.Implementation = "implementation", s.Widget = "widget", s))(R || {}), k = /* @__PURE__ */ ((s) => (s.Pre = "pre", s.Post = "post", s))(k || {});
58
- const Tt = (s, t, e, n) => {
59
- try {
60
- const i = new t(e, n);
61
- return {
62
- name: s,
63
- invoke: (r, o) => {
64
- let c;
65
- return i[r] && (c = i[r].call(i, o)), Promise.resolve(c);
66
- },
67
- getInstance: () => i
68
- };
69
- } catch (i) {
70
- if (i.message && i.message.indexOf("is not a constructor") >= 0)
71
- return {
72
- name: s,
73
- invoke: (r) => {
74
- let o;
75
- return r === "initialize" && (o = t(e, n)), Promise.resolve(o);
76
- },
77
- getInstance: () => t
78
- };
79
- throw i;
80
- }
81
- };
82
- function at(s, t) {
83
- return typeof s > "u" ? t : s;
84
- }
85
- let Vt = class {
86
- constructor(t = {}) {
87
- this.part = t;
88
- }
89
- createCommand(t, e, n) {
90
- let i;
91
- typeof e == "function" ? i = {
92
- scope: R.Widget,
93
- stage: k.Post,
94
- defaultArgs: void 0,
95
- handlerResolver: e
96
- } : i = {
97
- scope: at(e.scope, R.Widget),
98
- stage: at(e.stage, k.Post),
99
- defaultArgs: e.defaultArgs,
100
- handlerResolver: n
101
- };
102
- let r = this.part;
103
- const o = t.split(".");
104
- return o.forEach((c, l) => {
105
- l === o.length - 1 ? r[c] || (r[c] = () => i) : r = this.part[c] = this.part[c] || {};
106
- }), this;
107
- }
108
- get() {
109
- return this.part;
110
- }
111
- };
112
- const xt = (s) => {
113
- const t = new Vt({});
114
- return s(t), t.get();
115
- };
116
- xt((s) => {
117
- s.createCommand(
118
- "types.register",
119
- { scope: R.Implementation, stage: k.Pre },
120
- (t) => (e, n) => {
121
- t.container.get("$types")[e] = n;
122
- }
123
- ).createCommand(
124
- "type",
125
- { stage: k.Pre },
126
- (t) => (e) => {
127
- t.container.register("$type", e);
128
- }
129
- ).createCommand(
130
- "settings",
131
- { stage: k.Pre, defaultArgs: [null] },
132
- (t) => (e) => {
133
- t.events.dispatch(
134
- "settings:change",
135
- e,
136
- { bubbles: !0 }
137
- ), t.container.register("$settings", e);
138
- }
139
- ).createCommand(
140
- "plugin",
141
- { stage: k.Pre },
142
- (t) => (e, n, i) => {
143
- const { container: r } = t;
144
- let o = null, c = e, l = n;
145
- typeof e == "string" && (o = e, c = n, l = i);
146
- const h = (a) => {
147
- const { transformPluginSettings: u } = t.container.get("$environmentOptions"), p = u ? u(
148
- l || {},
149
- o,
150
- t.container,
151
- c
152
- ) : n;
153
- try {
154
- const d = Tt(
155
- o,
156
- c,
157
- r,
158
- p
159
- );
160
- r.get("$plugins").push(d), a && d.invoke("initialize", null);
161
- } catch (d) {
162
- wt(t).warn("Error when initializing plugin", d);
163
- }
164
- };
165
- t.container.get("$instance") ? h(!0) : t.events.subscribeOnce("widget:instance-created", () => h(!1));
166
- }
167
- ).createCommand(
168
- "container.register",
169
- (t) => (e, n) => {
170
- t.container.register(e, n);
171
- }
172
- ).createCommand(
173
- "container.registerAsync",
174
- (t) => (e, n) => {
175
- t.container.registerAsync(e, n);
176
- }
177
- ).createCommand(
178
- "container.registerFactory",
179
- (t) => (e, n) => {
180
- t.container.registerFactory(e, n);
181
- }
182
- ).createCommand(
183
- "container.touch",
184
- (t) => (e, n) => {
185
- t.container.touch(e, n);
186
- }
187
- ).createCommand(
188
- "csp",
189
- {},
190
- (t) => (e) => {
191
- t.container.register("csp", e);
192
- }
193
- );
194
- });
195
- function jt(s, t, e) {
196
- return Array.from(s.querySelectorAll(
197
- `div[id^="${t}_"], div[id^="${t}:"]`
198
- )).map((n) => {
199
- if (n.id.substr(0, 7) === `${t}_`)
200
- return { widgetName: n.id.substr(7), element: n };
201
- const { 3: i } = n.id.split(":");
202
- return { widgetName: i, element: n };
203
- });
204
- }
205
- const Wt = (s) => {
206
- const t = s.map((e) => e.replace(/\./g, "\\.")).join("|");
207
- return new RegExp("^((http[s]?:)?//)?(" + t + ")/([^\\s]+)");
208
- }, Ht = (s) => s.href;
209
- function qt(s, t) {
210
- const e = Wt(t), n = (i) => {
211
- const r = e.exec(Ht(i));
212
- return r ? {
213
- element: i,
214
- widget: r[4]
215
- } : null;
216
- };
217
- return Array.from(s.querySelectorAll("a")).map((i) => n(i)).filter((i) => !!i).map((i) => ({
218
- element: i.element,
219
- widgetName: i.widget
220
- }));
221
- }
222
- function $t(s) {
223
- return s.filter((t, e, n) => n.indexOf(t) === e);
224
- }
225
- let Ft = class {
226
- constructor(t) {
227
- this.container = t.container, this.events = t.events;
228
- }
229
- watch(t) {
230
- const e = this.container.get("triggerElements") || [], n = $t(e.concat(t));
231
- this.container.register("triggerElements", n), this.events.dispatch(
232
- "bootstrap:trigger-elements-updated",
233
- { triggerElements: n },
234
- { bubbles: !0 }
235
- );
236
- }
237
- };
238
- function Ct(s, ...t) {
239
- return s.implementation.events.subscribe("widget:create-instance", (e, n) => {
240
- if (e.target === s) {
241
- let i = s.container.get("bootstrapping.monitor");
242
- i || (i = new Ft(s), s.container.register("bootstrapping.monitor", i)), i.watch(t);
243
- }
244
- }), s.load();
245
- }
246
- function Et(s, t = document) {
247
- var e;
248
- const n = s.bindings, i = [].concat(
249
- qt(t, n),
250
- jt(t, ((e = s.environment) == null ? void 0 : e.name) || "")
251
- ), r = $t(i.map(({ widgetName: o }) => o)).reduce((o, c) => {
252
- const l = s.widgets.get(c);
253
- if (!l)
254
- return process.env.NODE_ENV !== "production" && wt(s).warn(`A trigger element for "${c}" was found but no widget with that name is available on the implementation ("${s.name}"). Make sure this is not a mistake.`), o;
255
- const h = i.filter((a) => a.widgetName === c).map((a) => a.element);
256
- return o.push(Ct(l, ...h)), o;
257
- }, []);
258
- return Promise.all(r);
259
- }
260
- function Bt() {
261
- return new Promise((s) => {
262
- document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", () => s()) : s();
263
- });
264
- }
265
- const Qt = (s, t) => {
266
- const e = s;
267
- e.scan = (i) => Et(e, i), e.bindings = t, e.attach = (i, ...r) => Ct(i, ...r);
268
- const { environment: n } = e;
269
- return typeof n.configure > "u" && (n.configure = (i, r) => {
270
- let o, c;
271
- r ? (o = i, c = r) : (o = "*", c = i), n.implementations.query(o).forEach((l) => l.configure(c)), n.events.subscribe("implementation:created", (l, h) => {
272
- const { implementation: a } = h;
273
- zt(o)(a) && a.configure(c);
274
- });
275
- }), e;
276
- };
277
- function Ut(s, t, e = () => [], n) {
278
- const i = { ready: !1 };
279
- s.container.register("bootstrapping", i);
280
- const r = Qt(s, t);
281
- return Bt().then(() => {
282
- s.configure((...o) => {
283
- e().forEach((c) => c(...o));
284
- });
285
- }).then(() => Et(r, n())).then(() => (i.ready = !0, s.events.dispatch("bootstrap:ready", {}), r));
286
- }
287
- function Yt(s) {
288
- const t = {};
289
- return [].filter.call(s.attributes, (e) => /^data-/.test(e.name)).map((e) => e.name).forEach((e) => t[e.substr(5)] = s.getAttribute(e)), t;
290
- }
291
- const ht = (s, t, e) => {
292
- const n = Yt(s);
293
- e({
294
- sourceDOMElement: s,
295
- eventType: t,
296
- data: n
297
- });
298
- };
299
- function ut(s, t, e) {
300
- s.forEach((n) => {
301
- n.dataset.attached !== "true" && (t === "load" ? ht(n, t, e) : n.addEventListener(t, (i) => {
302
- i.preventDefault(), ht(n, t, e);
303
- }), n.dataset.monitored = "true");
304
- });
305
- }
306
- function je(s, t, e) {
307
- const n = s.container.get("bootstrapping.monitor");
308
- n && n.events.subscribe("bootstrap:trigger-elements-updated", (r, o) => {
309
- ut(
310
- o.triggerElements,
311
- t,
312
- e
313
- );
314
- });
315
- const i = s.container.get("triggerElements");
316
- i && ut(
317
- i,
318
- t,
319
- e
320
- );
321
- }
322
- const Gt = xt((s) => {
323
- s.createCommand(
324
- "ready",
325
- { scope: R.Implementation, stage: k.Pre },
326
- (t) => (e) => {
327
- const { container: n } = t, i = n.owner;
328
- n.get("bootstrapping").ready ? e(i) : i.events.subscribeOnce("bootstrap:ready", () => {
329
- e(i);
330
- });
331
- }
332
- );
333
- }), H = /* @__PURE__ */ new WeakMap();
334
- function A() {
335
- return (s) => (H.has(s) || H.set(s, {}), H.get(s));
336
- }
337
- const q = (s, t, e, ...n) => {
338
- const i = `[${s.get("$environment").name || "webprovisions"}] ${e}`;
339
- switch (t) {
340
- case "info":
341
- console.info(i, ...n);
342
- break;
343
- case "warning":
344
- console.warn(i, ...n);
345
- break;
346
- case "error":
347
- console.error(i, ...n);
348
- break;
349
- }
350
- }, g = (s) => {
351
- const t = s.container || s;
352
- return {
353
- info: (e, ...n) => q(t, "info", e, ...n),
354
- warn: (e, ...n) => q(t, "warning", e, ...n),
355
- error: (e, ...n) => q(t, "error", e, ...n)
356
- };
357
- }, m = A(), Y = (() => {
358
- let s = 0;
359
- return () => ++s;
360
- })(), G = (s, t, e) => {
361
- const n = m(s).touchQueue.get(t);
362
- n && n.forEach((i) => {
363
- i(e, s);
364
- });
365
- };
366
- class Kt {
367
- constructor(t, e, n, i) {
368
- this.key = t, this.factory = e, this.parent = n, this.container = i, this.id = Y(), this.resolved = !1, this.constructed = !1, this.async = !0;
369
- }
370
- resolve() {
371
- if (!this.constructed) {
372
- const t = this.factory(this.parent, this.container);
373
- return this.constructed = !0, this.value = Promise.resolve(t).then((e) => (this.resolved = !0, G(this.container, this.key, e), e));
374
- }
375
- return this.value;
376
- }
377
- }
378
- class Jt {
379
- constructor(t, e, n, i) {
380
- this.key = t, this.value = e, this.parent = n, this.container = i, this.id = Y(), this.async = !1, this.resolved = !1, this.constructed = !0, this.resolve = () => (this.resolved = !0, G(this.container, this.key, this.value), this.value);
381
- }
382
- }
383
- class Xt {
384
- constructor(t, e, n, i) {
385
- this.key = t, this.value = e, this.parent = n, this.container = i, this.id = Y(), this.async = !1, this.resolved = !1, this.constructed = !1, this.resolve = () => {
386
- this.resolved = !0, this.constructed = !0;
387
- const r = this.value(this.parent, this.container);
388
- return G(this.container, this.key, this.value), r;
389
- };
390
- }
391
- }
392
- class K {
393
- /**
394
- * Creates a new instance of `Container`.
395
- * @param owner The object owning this inctance.
396
- * @param name Optional name for the container.
397
- * @param parent Parent container this should be a child of.
398
- */
399
- constructor(t, e, n) {
400
- this.owner = t, this.name = e, this.parent = n, m(this).resolvers = /* @__PURE__ */ new Map(), m(this).touchQueue = /* @__PURE__ */ new Map(), m(this).children = [];
401
- }
402
- /**
403
- * Deletes an existing resolver by its unique id.
404
- * @param id Resolver id.
405
- */
406
- delete(t) {
407
- const e = m(this).resolvers, n = Array.from(e.values()).find((i) => i.id === t);
408
- return n ? (m(this).touchQueue.delete(n.key), Promise.resolve(e.delete(n.key))) : this.parent ? this.parent.delete(t) : Promise.resolve(!1);
409
- }
410
- /**
411
- * Clears the `Container` and any child containers by deleteing all registered resolvers.
412
- */
413
- clear() {
414
- const t = m(this).resolvers, e = Array.from(t.values());
415
- return Promise.all(e.map((n) => {
416
- if (n.constructed)
417
- return Promise.resolve(n.resolve()).then((i) => {
418
- if (i !== null && typeof i == "object" && typeof i.dispose == "function")
419
- return i.dispose.call(i, this, n);
420
- });
421
- })).then(() => {
422
- e.forEach((n) => this.delete(n.id)), m(this).children.forEach((n) => n.clear());
423
- });
424
- }
425
- /**
426
- * Detaches this `Container` instance from its parent, allowing it to be garbage-collected.
427
- */
428
- detach() {
429
- if (this.parent) {
430
- const t = m(this.parent).children, e = t.indexOf(this);
431
- e > -1 && (t.splice(e, 1), delete this.parent);
432
- }
433
- }
434
- /**
435
- * Provides a way of touching a value in the `Container` without forcing it to be resolved.
436
- * @param key Key of the resolved value to touch.
437
- * @param handler Handler function for touching the resolved value.
438
- */
439
- touch(t, e) {
440
- const n = m(this).resolvers.get(t);
441
- if (n && n.constructed)
442
- Promise.resolve(n.resolve()).then((i) => {
443
- e(i, this);
444
- });
445
- else {
446
- const i = m(this).touchQueue;
447
- let r = i.get(t);
448
- r || (r = [], i.set(t, r)), r.push(e);
449
- }
450
- return this.parent && !n ? this.parent.touch(t, e) : Promise.resolve();
451
- }
452
- /**
453
- * Registers an asynchronous resolver.
454
- * @param key Key of the resolver.
455
- * @param factory Value factory.
456
- */
457
- registerAsync(t, e) {
458
- const n = m(this).resolvers.get(t);
459
- n && !n.async && process.env.NODE_ENV !== "production" && g(this).warn(`Mismatching resolver type. You are registering an async resolver with a key ('${t}') previously used by a non-async resolver.`);
460
- const i = new Kt(t, e, n, this);
461
- return m(this).resolvers.set(t, i), i.id;
462
- }
463
- /**
464
- * Registers a factory resolver for constructing the value to be resolved.
465
- * @param key Key of the resolver.
466
- * @param factory Value factory.
467
- */
468
- registerFactory(t, e) {
469
- const n = m(this).resolvers.get(t);
470
- n && n.async && process.env.NODE_ENV !== "production" && g(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${t}') previously used by an async resolver.`);
471
- const i = new Xt(t, e, n, this);
472
- return m(this).resolvers.set(t, i), i.id;
473
- }
474
- /**
475
- * Registers an synchronous resolver.
476
- * @param key Key of the resolver.
477
- * @param value Value.
478
- */
479
- register(t, e) {
480
- const n = m(this).resolvers.get(t);
481
- n && n.async && process.env.NODE_ENV !== "production" && g(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${t}') previously used by an async resolver.`);
482
- const i = new Jt(t, e, n, this);
483
- return m(this).resolvers.set(t, i), i.id;
484
- }
485
- /**
486
- * Gets the value for a synchronous resolver.
487
- * @param key Key of resolver to get.
488
- */
489
- get(t) {
490
- const e = m(this).resolvers.get(t);
491
- if (e)
492
- return e.async && process.env.NODE_ENV !== "production" && g(this).warn(`You are retrieving an async value (with key '${t}') by the non-async function 'container.get(key)'. This will not be supported in future versions. Use 'container.getAsync(key) instead.'`), e.resolve();
493
- if (this.parent)
494
- return this.parent.get(t);
495
- }
496
- /**
497
- * Gets the value for a asynchronous resolver.
498
- * @param key Key of resolver to get.
499
- */
500
- getAsync(t) {
501
- const e = m(this).resolvers.get(t);
502
- if (e) {
503
- if (!e.async)
504
- throw process.env.NODE_ENV !== "production" && g(this).warn(`You are retrieving a non-async value (with key '${t}') by the async function 'container.getAsync(key)'.Use 'container.get(key) instead.'`), "Mismatching resolver type";
505
- return e.resolve();
506
- }
507
- return this.parent ? this.parent.getAsync(t) : Promise.resolve(void 0);
508
- }
509
- getMany(...t) {
510
- const e = {};
511
- return t.forEach((n) => e[n] = this.get(n)), e;
512
- }
513
- getManyAsync(...t) {
514
- const e = {};
515
- return Promise.all(t.map((n) => this.getAsync(n).then((i) => e[n] = i))).then(() => e);
516
- }
517
- createChild(t, e) {
518
- const n = new K(t, e, this);
519
- return m(this).children.push(n), n;
520
- }
521
- }
522
- class lt {
523
- /**
524
- *
525
- * @param type Type of event.
526
- * @param target The target of the event, which will handle the default behavour.
527
- * @param cancelable Whether the event is cancelable by calling preventDefault().
528
- * @param bubbles Whether the event will bubble up the parent hierarchy.
529
- */
530
- constructor(t, e, n = !1, i = !1) {
531
- this.type = t, this.target = e, this.cancelable = !!n, this.bubbles = !!i, this.defaultPrevented = !1;
532
- }
533
- /**
534
- * Cancels the default behaviour (if the event is cancelable).
535
- */
536
- preventDefault() {
537
- this.cancelable && (this.defaultPrevented = !0);
538
- }
539
- }
540
- const b = A(), pt = (s, t) => [].concat(
541
- b(s).listenerLookup.get(t.toLowerCase()) || [],
542
- b(s).listenerLookup.get("*") || []
543
- ), dt = (s, t, e, n) => {
544
- let i, r;
545
- return t instanceof lt ? (i = t, r = t.type) : (i = new lt(t, s.target, !!e.cancelable, !!e.bubbles), r = t), { event: i, type: r, async: n };
546
- };
547
- class J {
548
- /**
549
- * Creates a new Event Manager instance.
550
- * @param target The target of events dispatched from this Event Manager instance.
551
- * @param parent Parent Event Manager instance.
552
- */
553
- constructor(t, e) {
554
- this.target = t, this.parent = e, b(this).listenerLookup = /* @__PURE__ */ new Map(), b(this).children = [];
555
- }
556
- /**
557
- * Clears registered event listeners in this `EventManager` as well as in any children.
558
- */
559
- clear() {
560
- b(this).listenerLookup.clear(), b(this).children.forEach((t) => t.clear());
561
- }
562
- /**
563
- * Detaches this `EventManager` instance from its parent, allowing it to be garbage-collected.
564
- */
565
- detach() {
566
- if (this.parent) {
567
- const t = b(this.parent).children, e = t.indexOf(this);
568
- e > -1 && t.splice(e, 1);
569
- }
570
- }
571
- /**
572
- * Creates an event subscription by registering an listener for an event type.
573
- * @param type Event type to subscribe to.
574
- * @param listener Listener for the event.
575
- */
576
- subscribe(t, e, n) {
577
- const i = b(this).listenerLookup, r = t.toLowerCase();
578
- return i.has(r) || i.set(r, []), i.get(r).push(e), () => this.unsubscribe(t, e);
579
- }
580
- /**
581
- * Similar to `subscribe()` but immediately removes the subscription after the first call.
582
- * @param type Event type to subscribe to.
583
- * @param listener Listener for the event.
584
- */
585
- subscribeOnce(t, e) {
586
- const n = this.subscribe(t, (i, r) => (n(), e(i, r)));
587
- }
588
- /**
589
- * Removes a listener for the specified event type.
590
- * @param type Event type to remove subscription for.
591
- * @param listener Event listener to remove.
592
- */
593
- unsubscribe(t, e) {
594
- const n = b(this).listenerLookup.get(t.toLowerCase());
595
- if (n) {
596
- const i = n.indexOf(e);
597
- i > -1 && n.splice(i, 1);
598
- }
599
- }
600
- /**
601
- * Dispatches an asynchonous event to registered event listeners.
602
- * @param eventOrType Event type or Event object to dispatch.
603
- * @param data Optional data to be passed to event listeners.
604
- * @param options Optional event options used if first parameter is an event type.
605
- */
606
- dispatchAsync(t, e, n = {}) {
607
- const { event: i, type: r } = dt(this, t, n, !0), o = pt(this, r);
608
- let c = 0;
609
- const l = o.length;
610
- let h = Promise.resolve();
611
- for (c = 0; c < l; c++)
612
- ((a) => {
613
- h = h.then((u) => u ? Promise.resolve(!0) : Promise.resolve(a(i, e)).then(() => i.defaultPrevented));
614
- })(o[c]);
615
- return h.then((a) => !a && i.bubbles && this.parent ? this.parent.dispatchAsync(i, e) : a);
616
- }
617
- /**
618
- * Dispatches an event to registered event listeners.
619
- * @param eventOrType Event type or Event object to dispatch.
620
- * @param data Optional data to be passed to event listeners.
621
- * @param options Optional event options used if first parameter is an event type.
622
- */
623
- dispatch(t, e, n = {}) {
624
- const { event: i, type: r } = dt(this, t, n, !1), o = pt(this, r);
625
- let c = 0;
626
- const l = o.length;
627
- let h = !1;
628
- for (c = 0; c < l; c++)
629
- if (o[c](i, e), i.defaultPrevented) {
630
- h = !0;
631
- break;
632
- }
633
- return !h && i.bubbles && this.parent && (h = this.parent.dispatch(i, e)), h;
634
- }
635
- /**
636
- * Creates a child instance to the current Event manager.
637
- */
638
- createChild(t) {
639
- const e = new J(t, this);
640
- return b(this).children.push(e), e;
641
- }
642
- }
643
- const L = (s, t, e) => {
644
- const n = s.get("$plugins").map((i) => {
645
- try {
646
- return i.invoke(t, e);
647
- } catch (r) {
648
- g(s).error("An error occured when invoking a plugin.", i, r);
649
- }
650
- });
651
- return Promise.all(n);
652
- };
653
- class Zt {
654
- constructor(t) {
655
- this.widget = t.get("$widget"), this.events = this.widget.events, this.container = this.widget.container, this.initialized = null, this.activated = null, this.initialize = this.initialize.bind(this), this.activate = this.activate.bind(this), this.deactivate = this.deactivate.bind(this), this.invoke = this.invoke.bind(this), this.createInstance();
656
- }
657
- createInstance() {
658
- if (!this.widget.container.get("$instance")) {
659
- const t = this.widget.container.get("$types"), e = this.widget.container.get("$type");
660
- !e && g(this).error("Unable to create widget. No type is specified.");
661
- const n = t[e];
662
- !n && g(this).error(`Unable to create widget. Type '${e}' is not registered.`), this.widget.events.dispatch("widget:create-instance", {}, { bubbles: !0 });
663
- try {
664
- this.widget.container.register(
665
- "$instance",
666
- new n(this.container)
667
- );
668
- } catch (i) {
669
- g(this).error("Unable to create widget type.", i);
670
- }
671
- this.widget.events.dispatch("widget:instance-created", {}, { bubbles: !0 });
672
- }
673
- }
674
- /**
675
- * The initialization is performed before the widget is activated but after it's configured
676
- * and thus all required services are available. This hook is a good place to bind events that
677
- * should trigger activation (e.g. click on "trigger links" or routing events)
678
- * @param {object} data Custom initialization data passed to the widget.
679
- */
680
- initialize(t) {
681
- return this.initialized = this.initialized || (() => {
682
- const e = this.container.get("$instance"), n = e.initialize || (() => {
683
- });
684
- return this.initialized = Promise.resolve(n.call(e, t)).then(() => L(this.container, "initialize", t)).then(() => {
685
- });
686
- })();
687
- }
688
- /**
689
- * The activation is where the widget is actually created and rendered.
690
- * Activation can be initialized from the outside or from an event originated
691
- * in the "initialize" hook.
692
- * @param {object} data Custom activation data passed to the widget.
693
- */
694
- activate(t) {
695
- return (this.initialized || this.initialize()).then(() => {
696
- this.activated = this.activated || (() => L(this.container, "activate").then(() => {
697
- const e = this.container.get("$instance");
698
- return this.activated = e.activate(t);
699
- }))();
700
- });
701
- }
702
- deactivate() {
703
- const t = this.container.get("$instance"), e = t.deactivate || (() => {
704
- });
705
- return L(this.container, "deactivate").then(() => Promise.resolve(e.call(t))).then(() => {
706
- this.initialized = null, this.activated = null;
707
- }).then(() => {
708
- });
709
- }
710
- /**
711
- * Invokes a command on the widget component.
712
- * @param command Name of command
713
- * @param args Command arguments
714
- */
715
- invoke(t, ...e) {
716
- return L(this.container, "invoke", { command: t, args: e }).then(() => {
717
- const n = this.container.get("$instance");
718
- if (n[t])
719
- return n[t].apply(n, e);
720
- const i = n.invoke;
721
- if (i)
722
- return i.call(n, t, ...e);
723
- });
724
- }
725
- }
726
- const O = (s, t) => {
727
- if (!t)
728
- return !0;
729
- if (typeof t == "string") {
730
- const e = t.split(",");
731
- for (let n = 0, i = e.length; n < i; n++) {
732
- const r = e[n].trim();
733
- if (r === s || r === "*")
734
- return !0;
735
- }
736
- }
737
- return t instanceof Array ? t.indexOf(s) > -1 : !1;
738
- }, te = (s, t) => {
739
- if (typeof t == "function")
740
- return t(s);
741
- const e = typeof t == "string" ? se(t) : t;
742
- return !(!O(s.implementation.tenant || "", e.tenant || "") || !O(s.implementation.name, e.implementation || "") || !O(s.name, e.widget || "") || !O(s.container.get("$type"), e.type || ""));
743
- }, ee = (s, t) => {
744
- if (typeof t == "function")
745
- return t(s);
746
- const e = typeof t == "string" ? ne(t) : t;
747
- return !(!O(s.tenant || "", e.tenant || "") || !O(s.name, e.implementation || ""));
748
- }, kt = (s) => (t) => te(t, s), Pt = (s) => (t) => ee(t, s), x = (s) => s instanceof Array && s.length === 1 ? s[0] : s, se = (s) => {
749
- const t = {}, e = s.split(":");
750
- return e.length === 1 ? t.widget = x(e[0].split(",")) : e.length === 2 ? (t.implementation = x(e[0].split(",")), t.widget = x(e[1].split(","))) : (t.tenant = x(e[0].split(",")), t.implementation = x(e[1].split(",")), t.widget = x(e[2].split(","))), t;
751
- }, ne = (s) => {
752
- const t = {}, e = s.split(":");
753
- return e.length === 1 ? t.implementation = x(e[0].split(",")) : (t.tenant = x(e[0].split(",")), t.implementation = x(e[1].split(","))), t;
754
- }, M = A(), mt = (s, t, e) => s.filter((n) => n.stage === t && kt(n.selector)(e));
755
- function ie(s) {
756
- const t = s.container.get("$environment");
757
- let e = M(t).configurationCache;
758
- e && (e = e.filter((n) => n[0] !== s), M(t).configurationCache = e);
759
- }
760
- var z = /* @__PURE__ */ ((s) => (s.Implementation = "implementation", s.Widget = "widget", s))(z || {}), $ = /* @__PURE__ */ ((s) => (s.Pre = "pre", s.Post = "post", s))($ || {});
761
- const Ot = (s, t, e) => (Object.keys(t).forEach((n) => {
762
- const i = t[n];
763
- if (typeof i == "function") {
764
- const r = i();
765
- typeof r.defaultArgs < "u" && e(r, ...r.defaultArgs), s[n] = (...o) => {
766
- const c = Object.assign(
767
- {},
768
- r,
769
- { handlerResolver: r.handlerResolver.bind({}) }
770
- );
771
- return e(c, ...o), s;
772
- };
773
- } else
774
- s[n] = Ot(
775
- {},
776
- i,
777
- e
778
- );
779
- }), s), re = (s, t) => {
780
- switch (t) {
781
- case "implementation":
782
- return s.implementation;
783
- case "widget":
784
- return s;
785
- }
786
- }, gt = (s, t, e, n) => (n.forEach((i) => {
787
- Ot(
788
- s,
789
- i,
790
- (r, ...o) => {
791
- const c = {
792
- selector: t,
793
- stage: r.stage,
794
- handler: (l) => {
795
- const h = re(l, r.scope), a = { container: h.container, events: h.events }, u = r.handlerResolver, p = u(a);
796
- let d = M(e.environment).configurationCache;
797
- return d || (d = M(e.environment).configurationCache = []), d.find((C) => C.indexOf(h) > -1 && C.indexOf(u) > -1) ? Promise.resolve() : (d.push([h, u]), Promise.resolve(p(...o)));
798
- }
799
- };
800
- e.instructions.push(c);
801
- }
802
- );
803
- }), s);
804
- function oe(s, t) {
805
- function e(n) {
806
- return gt(
807
- {},
808
- n,
809
- s,
810
- t
811
- );
812
- }
813
- return gt(
814
- e,
815
- "*",
816
- s,
817
- t
818
- );
819
- }
820
- class ce {
821
- constructor(t, e) {
822
- this.container = t, this.settings = e, this.widget = t.get("$widget"), this.events = this.widget.events;
823
- }
824
- }
825
- const ae = (s, t, e, n) => {
826
- try {
827
- const i = new t(e, n);
828
- return {
829
- name: s,
830
- invoke: (r, o) => {
831
- let c;
832
- return i[r] && (c = i[r].call(i, o)), Promise.resolve(c);
833
- },
834
- getInstance: () => i
835
- };
836
- } catch (i) {
837
- if (i.message && i.message.indexOf("is not a constructor") >= 0)
838
- return {
839
- name: s,
840
- invoke: (r) => {
841
- let o;
842
- return r === "initialize" && (o = t(e, n)), Promise.resolve(o);
843
- },
844
- getInstance: () => t
845
- };
846
- throw i;
847
- }
848
- };
849
- function ft(s, t) {
850
- return typeof s > "u" ? t : s;
851
- }
852
- class he {
853
- constructor(t = {}) {
854
- this.part = t;
855
- }
856
- createCommand(t, e, n) {
857
- let i;
858
- typeof e == "function" ? i = {
859
- scope: z.Widget,
860
- stage: $.Post,
861
- defaultArgs: void 0,
862
- handlerResolver: e
863
- } : i = {
864
- scope: ft(e.scope, z.Widget),
865
- stage: ft(e.stage, $.Post),
866
- defaultArgs: e.defaultArgs,
867
- handlerResolver: n
868
- };
869
- let r = this.part;
870
- const o = t.split(".");
871
- return o.forEach((c, l) => {
872
- l === o.length - 1 ? r[c] || (r[c] = () => i) : r = this.part[c] = this.part[c] || {};
873
- }), this;
874
- }
875
- get() {
876
- return this.part;
877
- }
878
- }
879
- const At = (s) => {
880
- const t = new he({});
881
- return s(t), t.get();
882
- }, ue = At((s) => {
883
- s.createCommand(
884
- "types.register",
885
- { scope: z.Implementation, stage: $.Pre },
886
- (t) => (e, n) => {
887
- t.container.get("$types")[e] = n;
888
- }
889
- ).createCommand(
890
- "type",
891
- { stage: $.Pre },
892
- (t) => (e) => {
893
- t.container.register("$type", e);
894
- }
895
- ).createCommand(
896
- "settings",
897
- { stage: $.Pre, defaultArgs: [null] },
898
- (t) => (e) => {
899
- t.events.dispatch(
900
- "settings:change",
901
- e,
902
- { bubbles: !0 }
903
- ), t.container.register("$settings", e);
904
- }
905
- ).createCommand(
906
- "plugin",
907
- { stage: $.Pre },
908
- (t) => (e, n, i) => {
909
- const { container: r } = t;
910
- let o = null, c = e, l = n;
911
- typeof e == "string" && (o = e, c = n, l = i);
912
- const h = (a) => {
913
- const { transformPluginSettings: u } = t.container.get("$environmentOptions"), p = u ? u(
914
- l || {},
915
- o,
916
- t.container,
917
- c
918
- ) : n;
919
- try {
920
- const d = ae(
921
- o,
922
- c,
923
- r,
924
- p
925
- );
926
- r.get("$plugins").push(d), a && d.invoke("initialize", null);
927
- } catch (d) {
928
- g(t).warn("Error when initializing plugin", d);
929
- }
930
- };
931
- t.container.get("$instance") ? h(!0) : t.events.subscribeOnce("widget:instance-created", () => h(!1));
932
- }
933
- ).createCommand(
934
- "container.register",
935
- (t) => (e, n) => {
936
- t.container.register(e, n);
937
- }
938
- ).createCommand(
939
- "container.registerAsync",
940
- (t) => (e, n) => {
941
- t.container.registerAsync(e, n);
942
- }
943
- ).createCommand(
944
- "container.registerFactory",
945
- (t) => (e, n) => {
946
- t.container.registerFactory(e, n);
947
- }
948
- ).createCommand(
949
- "container.touch",
950
- (t) => (e, n) => {
951
- t.container.touch(e, n);
952
- }
953
- ).createCommand(
954
- "csp",
955
- {},
956
- (t) => (e) => {
957
- t.container.register("csp", e);
958
- }
959
- );
960
- }), le = ue;
961
- function pe(s, t, e = []) {
962
- const n = [le].concat(e), i = oe(
963
- t,
964
- n
965
- );
966
- s(i, t);
967
- }
968
- class de {
969
- constructor() {
970
- this.tasks = [], this.current = Promise.resolve(), this.next = this.next.bind(this);
971
- }
972
- add(t, e, n, i) {
973
- this.tasks.push({ task: t, resolve: e, reject: n, done: i }), this.next();
974
- }
975
- next() {
976
- this.current = this.current.then(() => {
977
- const t = this.tasks.shift();
978
- if (t) {
979
- const e = Promise.resolve(t.task());
980
- return Promise.resolve(e).then(this.next).then(() => e.then((n) => {
981
- t.done(), t.resolve(n);
982
- })).catch((n) => (t.done(), t.reject(n), this.next()));
983
- }
984
- return Promise.resolve();
985
- });
986
- }
987
- }
988
- const I = /* @__PURE__ */ new WeakMap();
989
- function me(s) {
990
- return I.has(s) || I.set(s, new de()), (t) => new Promise((e, n) => {
991
- const i = I.get(s);
992
- i.add(t, e, n, () => {
993
- i.tasks.length || I.delete(s);
994
- });
995
- });
996
- }
997
- const vt = (s) => typeof s < "u", _ = (s, t) => {
998
- s.events.dispatch("widget:state-change", { state: t }, { bubbles: !0 }), s.state = t, s.events.dispatch("widget:state-changed", {}, { bubbles: !0 });
999
- }, v = A(), ge = (s) => {
1000
- const { container: t, events: e } = s;
1001
- t.get("$controller") || (t.register("$controller", new Zt(t)), e.dispatch("widget:controller-created", {}, { bubbles: !0 }));
1002
- };
1003
- class fe {
1004
- /**
1005
- * Creates a new `Widget` instance.
1006
- * @param name Name of widget.
1007
- * @param implementation The implementation this instance belongs to.
1008
- * @param configuration Configuration for the widget.
1009
- */
1010
- constructor(t, e, n) {
1011
- this.state = "deactivated", this.name = t, this.implementation = e, this.container = e.container.createChild(this, t), this.events = e.events.createChild(this), v(this).subscriptions = [], n && e.configure((i) => {
1012
- const r = i(t);
1013
- vt(n.type) && r.type(n.type), vt(n.settings) && r.settings(n.settings), n.plugins && Object.keys(n.plugins).forEach((o) => {
1014
- var c;
1015
- const l = (c = n.plugins) == null ? void 0 : c[o];
1016
- r.plugin(o, l);
1017
- });
1018
- }), this.load = this.load.bind(this), this.activate = this.activate.bind(this), this.invoke = this.invoke.bind(this), this.deactivate = this.deactivate.bind(this);
1019
- }
1020
- /**
1021
- * Initializes the widget, if not already initialized, and applies any
1022
- * pending configuration.
1023
- */
1024
- load() {
1025
- return me(this)(() => {
1026
- v(this).deactivatedPromise = null;
1027
- const t = this.state === "deactivated";
1028
- t && (_(
1029
- this,
1030
- "activating"
1031
- /* Activating */
1032
- ), this.container.register("$widget", this), this.container.register("$controller", null), this.container.register("$plugins", []), this.container.register("$type", null), this.container.register("$instance", null)), _(
1033
- this,
1034
- "loading"
1035
- /* Loading */
1036
- );
1037
- const e = this.implementation.instructions, n = mt(e, $.Pre, this);
1038
- return Promise.all(n.map((i) => i.handler(this))).then(() => {
1039
- ge(this);
1040
- const i = mt(e, $.Post, this);
1041
- return Promise.all(i.map((r) => r.handler(this))).then(() => {
1042
- t && this.container.get("$controller").initialize();
1043
- });
1044
- }).then(() => (_(
1045
- this,
1046
- "activated"
1047
- /* Activated */
1048
- ), this));
1049
- });
1050
- }
1051
- /**
1052
- * Activates the widget and makes it ready for receiving commands.
1053
- * @param data Activation data
1054
- */
1055
- activate(t) {
1056
- v(this).subscriptions.push(
1057
- this.implementation.events.subscribe("implementation:configured", () => {
1058
- [
1059
- "activated",
1060
- "activating",
1061
- "loading"
1062
- /* Loading */
1063
- ].indexOf(this.state) > -1 && this.load();
1064
- })
1065
- );
1066
- const e = v(this).activatedPromise;
1067
- return e ? (process.env.NODE_ENV !== "production" && g(this).warn(`Widget '${this.name}' has already been activated. The passed arguments for this activation will be discarded.`, t), e) : v(this).activatedPromise = this.load().then(() => this.container.get("$controller").activate(t));
1068
- }
1069
- /**
1070
- * Invokes a command on a widget. If the widget isn't activate the invocation
1071
- * will be suspended until activation.
1072
- * @param command Command to invoke.
1073
- * @param args Command arguments.
1074
- */
1075
- invoke(t, ...e) {
1076
- const n = v(this).activatedPromise, i = (r, ...o) => n.then(this.load).then(() => this.container.get("$controller").invoke(r, ...o));
1077
- return n ? i(t, ...e) : (process.env.NODE_ENV !== "production" && g(this).warn("You are invoking a command on a deactivated widget. The invocation will be queued until the widget is activated.", this), new Promise((r) => {
1078
- const o = this.events.subscribe("widget:state-changed", () => {
1079
- this.state === "activated" && (o(), r(i(t, ...e)));
1080
- });
1081
- }));
1082
- }
1083
- /**
1084
- * Deactivates the widget by clearing the `Container` and removing any event subscriptions in the
1085
- * `EventManager`.
1086
- */
1087
- deactivate() {
1088
- return v(this).deactivatedPromise || (this.state === "deactivated" ? Promise.resolve() : (_(
1089
- this,
1090
- "deactivating"
1091
- /* Deactivating */
1092
- ), v(this).deactivatedPromise = this.container.get("$controller").deactivate().then(() => (v(this).activatedPromise = null, v(this).subscriptions.forEach((e) => e()), v(this).subscriptions = [], this.container.clear().then(() => {
1093
- this.events.clear(), ie(this), _(
1094
- this,
1095
- "deactivated"
1096
- /* Deactivated */
1097
- );
1098
- })))));
1099
- }
1100
- }
1101
- const We = (s) => s.deactivate().then(() => {
1102
- s.events.detach(), s.container.detach(), s.implementation.widgets.delete(s.name);
1103
- });
1104
- class ve {
1105
- /**
1106
- * Creates a new `Widget` instance.
1107
- * @param container The `Container` instance to base the widget upon.
1108
- */
1109
- constructor(t) {
1110
- this.container = t, this.widget = t.get("$widget"), this.settings = t.get("$settings"), this.events = this.widget.events, this.widget.events.subscribe("settings:change", (e, n) => {
1111
- this.settings = n;
1112
- });
1113
- }
1114
- }
1115
- const bt = A();
1116
- class Nt {
1117
- /**
1118
- * Creates a new Implementation instance.
1119
- * @param configuration Configuration for the implementation.
1120
- * @param environment The parent environment.
1121
- * @param configurationApiExtensions Optional configuration API extensions.
1122
- */
1123
- constructor(t, e, n = []) {
1124
- this.instructions = [], this.widgets = /* @__PURE__ */ new Map(), this.name = t.name, this.tenant = t.tenant, this.environment = e, this.container = e.container.createChild(this, this.name), this.events = e.events.createChild(this), this.container.register("$types", {}), bt(this).configurationApiExtensions = n;
1125
- }
1126
- /**
1127
- * Loads all widgets in the implementation.
1128
- */
1129
- load() {
1130
- const t = Array.from(this.widgets.values());
1131
- return Promise.all(t.map((e) => e.load())).then(() => t);
1132
- }
1133
- /**
1134
- * Configures the implementation by adding a configuration callback.
1135
- * @param configFn Callback function for configuration.
1136
- */
1137
- configure(t) {
1138
- return pe(t, this, bt(this).configurationApiExtensions), this.events.dispatch(
1139
- "implementation:configured",
1140
- { implementation: this },
1141
- { bubbles: !0 }
1142
- ), this;
1143
- }
1144
- /**
1145
- * Creates a widget on the implementation and returns its `WidgetData`.
1146
- * @param name Widget name.
1147
- * @param configuration Widget configuration.
1148
- */
1149
- createWidget(t, e) {
1150
- const n = new fe(t, this, e);
1151
- return this.widgets.set(n.name, n), n;
1152
- }
1153
- }
1154
- function be(s, t, e) {
1155
- const n = new Nt(s, t, e);
1156
- return s.widgets && Object.keys(s.widgets).forEach((i) => {
1157
- var r;
1158
- const o = (r = s.widgets) == null ? void 0 : r[i];
1159
- n.createWidget(i, o);
1160
- }), n;
1161
- }
1162
- class S {
1163
- constructor(t, e) {
1164
- this.selectorFactory = e, typeof t == "function" ? this.resolver = t : this.resolver = () => t;
1165
- }
1166
- append(t) {
1167
- const e = typeof t == "function" ? t : () => t;
1168
- return new S(
1169
- () => this.all().concat(e()),
1170
- this.selectorFactory
1171
- );
1172
- }
1173
- all() {
1174
- return this.resolver().concat([]);
1175
- }
1176
- query(t) {
1177
- return this.all().filter(this.selectorFactory(t));
1178
- }
1179
- find(t) {
1180
- const e = this.query(t);
1181
- if (e.length)
1182
- return e[0];
1183
- }
1184
- }
1185
- const X = "#____version____#", F = A(), ye = (s) => s.tenant ? `${s.name}:${s.tenant}` : s.name, _t = class {
1186
- constructor(s, t = [], e = {}) {
1187
- this.widgets = new S(
1188
- () => {
1189
- let n = [];
1190
- return this.implementations.all().forEach((i) => {
1191
- n = n.concat(Array.from(i.widgets.values()));
1192
- }), n;
1193
- },
1194
- kt
1195
- ), this.implementations = new S([], Pt), this.name = s, this.container = new K(this, s), this.events = new J(this), this.container.register("$version", X), this.container.register("$environment", this), this.container.register("$environmentOptions", e), F(this).configurationApiExtensions = t;
1196
- }
1197
- /**
1198
- * Creates an implementation based on the provided configuration.
1199
- * @param config Implementation configuration.
1200
- */
1201
- createImplementation(s) {
1202
- const t = ye(s);
1203
- let e = this.implementations.find(t);
1204
- if (e)
1205
- return process.env.NODE_ENV !== "production" && g(e).warn(`Implementation "${t}" already exist on current environment.`), e;
1206
- const n = F(this).configurationApiExtensions;
1207
- return e = be(
1208
- s,
1209
- this,
1210
- n
1211
- ), this.implementations = this.implementations.append([e]), this.events.dispatch("implementation:created", { implementation: e }), e;
1212
- }
1213
- /**
1214
- * Patches the Environment instance configuration.
1215
- * @param configuration Environment configuration.
1216
- */
1217
- patch(s = {}) {
1218
- const { name: t, configurationApiExtensions: e } = s;
1219
- typeof t < "u" && t !== null && (this.name = t), e && e.forEach(
1220
- (n) => {
1221
- F(this).configurationApiExtensions.push(n);
1222
- }
1223
- );
1224
- }
1225
- /**
1226
- * Creates a new Environment instance based on the provided configuration.
1227
- * @param configuration Environment configuration.
1228
- */
1229
- static create(s = {}) {
1230
- return new _t(
1231
- s.name || "",
1232
- s.configurationApiExtensions,
1233
- s.options
1234
- );
1235
- }
1236
- };
1237
- let Dt = _t;
1238
- Dt.version = X;
1239
- const He = (s, t, e = {}) => Ut(
1240
- s,
1241
- s.bindings,
1242
- () => {
1243
- const n = s.container.get("$runtimecfg").map((i) => {
1244
- const r = i[0];
1245
- if (typeof r == "function")
1246
- return r;
1247
- if (Pt(r)(s))
1248
- return i[1];
1249
- }).filter((i) => !!i);
1250
- return (t ? [t] : []).concat(n);
1251
- },
1252
- e.rootElementResolver || (() => document.body)
1253
- ), we = (s) => {
1254
- const t = [];
1255
- return [
1256
- (n, i) => {
1257
- t.push(s.subscribe(n, i));
1258
- },
1259
- () => {
1260
- t.forEach((n) => {
1261
- n();
1262
- });
1263
- }
1264
- ];
1265
- };
1266
- class Z {
1267
- constructor(t, e = []) {
1268
- this.platform = t, this.rules = e;
1269
- }
1270
- match(t) {
1271
- return this.rules.every((e) => !(e.id && e.id !== t.id || e.type && e.type !== t.type));
1272
- }
1273
- ofType(t) {
1274
- return this.rules.push({ type: t }), this;
1275
- }
1276
- withId(t) {
1277
- return this.rules.push({ id: t }), this;
1278
- }
1279
- select() {
1280
- return new xe(this.platform, this);
1281
- }
1282
- }
1283
- class Rt {
1284
- constructor(t, e, n) {
1285
- this.platform = t, this.node = e, this.actions = new tt(
1286
- t,
1287
- new Z(t).withId(e.id),
1288
- n
1289
- );
1290
- const [i, r] = we(this.platform.events);
1291
- this.subscribe = i, this.unsubscribe = r;
1292
- }
1293
- properties(t) {
1294
- return t && this.node.touchProperties((e) => t(e)), this.node.attributes.properties;
1295
- }
1296
- context(t) {
1297
- return t && this.subscribe("components:context-changed", (e, { node: n }) => {
1298
- n === this.node && t(this.node.attributes.context);
1299
- }), this.node.attributes.context;
1300
- }
1301
- layout(t) {
1302
- return t && this.subscribe("components:layout-changed", (e, { node: n }) => {
1303
- n === this.node && t(this.node.attributes.layout);
1304
- }), this.node.attributes.layout;
1305
- }
1306
- writeProperties(t, e) {
1307
- this.node.writeProperties(t, e);
1308
- }
1309
- writeContext(t, e) {
1310
- this.node.writeProperties(t, e);
1311
- }
1312
- writeLayout(t, e) {
1313
- this.node.writeLayout(t, e);
1314
- }
1315
- dispose() {
1316
- this.unsubscribe(), this.actions.dispose();
1317
- }
1318
- }
1319
- class xe {
1320
- constructor(t, e, n = !0) {
1321
- this.platform = t, this.target = e, this.clearOnDispose = n, this.removes = [], this.actions = new tt(this.platform, this.target);
1322
- }
1323
- writeProperties(t, e) {
1324
- this.removes.push(
1325
- this.platform.write({
1326
- options: e,
1327
- attributes: { properties: t },
1328
- target: this.target,
1329
- removable: this.clearOnDispose
1330
- })
1331
- );
1332
- }
1333
- writeContext(t, e) {
1334
- this.removes.push(
1335
- this.platform.write({
1336
- options: e,
1337
- attributes: { context: t },
1338
- target: this.target,
1339
- removable: this.clearOnDispose
1340
- })
1341
- );
1342
- }
1343
- writeLayout(t, e) {
1344
- this.removes.push(
1345
- this.platform.write({
1346
- options: e,
1347
- attributes: { layout: t },
1348
- target: this.target,
1349
- removable: this.clearOnDispose
1350
- })
1351
- );
1352
- }
1353
- dispose() {
1354
- this.removes.forEach((t) => {
1355
- t();
1356
- }), this.actions.dispose();
1357
- }
1358
- }
1359
- const $e = (s, t, e) => {
1360
- const n = s.concat(), i = (r, o, c) => {
1361
- let l = !0;
1362
- if (n.length) {
1363
- const h = n.shift(), a = (u, p) => (l = !1, i(u, Object.assign({}, o, p), c));
1364
- return Promise.resolve(h(r, a, c)).then((u) => ({
1365
- ...u,
1366
- cancelled: l
1367
- }));
1368
- }
1369
- return Promise.resolve({ data: r, cancelled: !1, options: o });
1370
- };
1371
- return i(t, {}, e);
1372
- };
1373
- class tt {
1374
- constructor(t, e, n) {
1375
- this.platform = t, this.target = e, this.ns = n, this.subscriptions = [], this.create = this.create.bind(this);
1376
- }
1377
- create(t, e = () => {
1378
- }) {
1379
- const n = {
1380
- key: t,
1381
- fn: e,
1382
- target: this.target,
1383
- ns: this.ns
1384
- };
1385
- this.platform.actionsState.handlers.push(n);
1386
- const i = () => {
1387
- const r = this.platform.actionsState.handlers.indexOf(n);
1388
- r > -1 && this.platform.actionsState.handlers.splice(r, 1);
1389
- };
1390
- return this.subscriptions.push(i), i;
1391
- }
1392
- dispatch(t, e) {
1393
- const n = this.platform.nodes.all.concat(
1394
- this.platform.nodes.detached
1395
- ), i = {}, r = this.platform.actionsState.handlers.filter(
1396
- (o) => o.key === t && (!o.ns || !this.ns || o.ns === this.ns)
1397
- );
1398
- return Promise.all(
1399
- r.map((o) => {
1400
- const c = n.filter(
1401
- (h) => o.target.match(h) && this.target.match(h)
1402
- ), l = this.platform.actionsState.watchers.filter((h) => h.key === t && (!h.ns || !this.ns || h.ns === this.ns) && c.some((a) => h.target.match(a))).map((h) => h.fn);
1403
- return Promise.all(
1404
- c.map((h) => {
1405
- const a = new Rt(
1406
- this.platform,
1407
- h,
1408
- this.ns
1409
- );
1410
- return $e(l, e, a).then((u) => {
1411
- const { data: p = {}, options: d, cancelled: C } = u;
1412
- return Promise.resolve(
1413
- C ? {} : o.fn(p, d, a)
1414
- ).then((N) => {
1415
- i[h.id] = N;
1416
- });
1417
- });
1418
- })
1419
- );
1420
- })
1421
- ).then(() => i);
1422
- }
1423
- watch(t, e) {
1424
- let n = t, i = this.ns;
1425
- const r = t.split(".");
1426
- r.length > 1 && (i = r[0], n = r.splice(1).join("."));
1427
- const o = {
1428
- fn: e,
1429
- target: this.target,
1430
- key: n,
1431
- ns: i
1432
- };
1433
- this.platform.actionsState.watchers.push(o);
1434
- const c = () => {
1435
- const l = this.platform.actionsState.watchers.indexOf(o);
1436
- l > -1 && this.platform.actionsState.watchers.splice(l, 1);
1437
- };
1438
- return this.subscriptions.push(c), c;
1439
- }
1440
- dispose() {
1441
- this.subscriptions.forEach((t) => t());
1442
- }
1443
- }
1444
- const qe = At((s) => {
1445
- s.createCommand("components", (t) => (e) => {
1446
- t.events.subscribeOnce("components:platform-created", (n, { platform: i }) => {
1447
- e.handlers && e.handlers.forEach(([r, o]) => {
1448
- i.addComponentHandler(r, o);
1449
- });
1450
- });
1451
- });
1452
- }), T = (s, t, ...e) => typeof t == "string" ? s(`[humany] ${t}`, ...e) : s(t, ...e), D = class {
1453
- constructor() {
1454
- this.keys = [], this.log = (s, ...t) => this.lookup(s, () => D.log(...t)), this.warn = (s, ...t) => this.lookup(s, () => D.warn(...t)), this.error = (s, ...t) => this.lookup(s, () => D.error(...t)), this.info = (s, ...t) => this.lookup(s, () => D.info(...t));
1455
- }
1456
- lookup(s, t) {
1457
- this.keys.indexOf(s) === -1 && (this.keys.push(s), t());
1458
- }
1459
- };
1460
- let P = D;
1461
- P.log = (...s) => T(console.log, ...s);
1462
- P.warn = (...s) => T(console.warn, ...s);
1463
- P.error = (...s) => T(console.error, ...s);
1464
- P.info = (...s) => T(console.info, ...s);
1465
- const E = () => Math.floor((1 + Math.random()) * 65536).toString(16).substring(1);
1466
- function et() {
1467
- return E() + E() + "-" + E() + "-" + E() + "-" + E() + "-" + E() + E() + E();
1468
- }
1469
- class yt {
1470
- constructor(t, e) {
1471
- this.events = t, this.tags = [], this.children = {}, this.changesets = [], this.mountCount = 0, this.id = et(), this.type = e, this.attributes = {
1472
- context: {},
1473
- properties: {},
1474
- layout: {},
1475
- tags: []
1476
- }, this.writeLayout({ size: "full", indent: 0 });
1477
- }
1478
- mount(t, e) {
1479
- let n = t.get("mounted-nodes");
1480
- return n || (n = /* @__PURE__ */ new Map(), t.register("mounted-nodes", n)), n.has(this) ? (process.env.NODE_ENV !== "production" && P.error(
1481
- "Trying to mount an already mounted component node.",
1482
- this
1483
- ), () => {
1484
- }) : (this.events.dispatch("components:node-mounted", { node: this }), this.mountCount === 0 && (this.mountCount = this.mountCount + 1, this.events.dispatch("components:node-enter", { node: this })), () => {
1485
- n.delete(this), this.events.dispatch("components:node-unmounted", { node: this }), this.mountCount = this.mountCount - 1, this.mountCount === 0 && this.events.dispatch("components:node-exit", { node: this });
1486
- });
1487
- }
1488
- appendChild(t, e = "default") {
1489
- if (t.parent) {
1490
- if (t.parent === this)
1491
- return;
1492
- t.parent.removeChild(t);
1493
- }
1494
- t.parent = this, this.children[e] || (this.children[e] = []), this.children[e].push(t), this.events.dispatch("components:node-appended", { node: t });
1495
- }
1496
- prependChild(t, e = "default") {
1497
- if (t.parent) {
1498
- if (t.parent === this)
1499
- return;
1500
- t.parent.removeChild(t);
1501
- }
1502
- t.parent = this, this.children[e] || (this.children[e] = []), this.children[e].unshift(t), this.events.dispatch("components:node-appended", { node: t });
1503
- }
1504
- touchProperties(t, e = {}, n) {
1505
- const r = [{ properties: t }, e];
1506
- return this.changesets.push(r), this.events.dispatch("components:set-properties", { node: this }), () => {
1507
- if (n) {
1508
- const o = this.changesets.indexOf(r);
1509
- o > -1 && (this.changesets.splice(o, 1), this.events.dispatch("components:set-properties", { node: this }));
1510
- }
1511
- };
1512
- }
1513
- writeProperties(t, e = {}, n) {
1514
- const r = [{ properties: t }, e];
1515
- return this.changesets.push(r), this.events.dispatch("components:set-properties", { node: this }), () => {
1516
- if (n) {
1517
- const o = this.changesets.indexOf(r);
1518
- o > -1 && (this.changesets.splice(o, 1), this.events.dispatch("components:set-properties", { node: this }));
1519
- }
1520
- };
1521
- }
1522
- writeLayout(t, e = {}, n) {
1523
- const r = [{ layout: t }, e];
1524
- return this.changesets.push(r), this.events.dispatch("components:set-layout", { node: this }), () => {
1525
- if (!n)
1526
- return;
1527
- const o = this.changesets.indexOf(r);
1528
- o > -1 && (this.changesets.splice(o, 1), this.events.dispatch("components:set-layout", { node: this }));
1529
- };
1530
- }
1531
- writeContext(t, e = {}, n) {
1532
- const r = [{ context: t }, e];
1533
- return this.changesets.push(r), this.events.dispatch("components:set-context", { node: this }), () => {
1534
- if (!n)
1535
- return;
1536
- const o = this.changesets.indexOf(r);
1537
- o > -1 && (this.changesets.splice(o, 1), this.events.dispatch("components:set-context", { node: this }));
1538
- };
1539
- }
1540
- getChildren(t = "default") {
1541
- const e = this.children[t] || [];
1542
- return e.reduce((n, i, r) => {
1543
- const { order: o = r } = i.attributes.layout;
1544
- return n[o] ? n.splice(o, 0, i) : n[o] = i, n;
1545
- }, Array(e.length));
1546
- }
1547
- remove() {
1548
- this.parent && this.parent.removeChild(this);
1549
- }
1550
- removeChild(t) {
1551
- Object.keys(this.children).forEach((e) => {
1552
- const n = this.children[e], i = n.indexOf(t);
1553
- i > -1 && (n.splice(i, 1), this.events.dispatch("components:node-removed", {
1554
- node: t,
1555
- parentNode: this
1556
- }));
1557
- }), delete t.parent;
1558
- }
1559
- }
1560
- const Lt = (s, t, e) => {
1561
- for (let n = 0, i = s.length; n < i && e(s[n]) !== !0; n++) {
1562
- const r = t[s[n].id] || "default", o = s[n].getChildren(r);
1563
- Lt(o, t, e);
1564
- }
1565
- }, st = (s, t, e) => {
1566
- if (e(s) !== !0) {
1567
- const n = t[s.id] || "default", i = s.children[n];
1568
- Lt(i, t, e);
1569
- }
1570
- }, B = (s, t) => {
1571
- const e = [];
1572
- return st(s, t, (n) => {
1573
- e.push(n);
1574
- }), e;
1575
- }, Ce = (s, t, e) => {
1576
- let n;
1577
- return st(s, t, (i) => {
1578
- if (e(i))
1579
- return n = i, !0;
1580
- }), n;
1581
- };
1582
- class Ee {
1583
- constructor(t, e, n) {
1584
- this.root = t, this.switches = e, this.all = [], this.visible = [], this.detached = [], n.subscribe("components:node-appended", (i, r) => {
1585
- this.all.push(r.node), this.visible = B(t, e);
1586
- }), n.subscribe("components:node-removed", (i, r) => {
1587
- let o = this.all.indexOf(r.node);
1588
- o > -1 && this.all.splice(o, 1), o = this.visible.indexOf(r.node), o > -1 && this.visible.splice(o, 1), this.visible = B(t, e);
1589
- }), n.subscribe("components:node-switched", (i, r) => {
1590
- this.visible = B(t, e);
1591
- });
1592
- }
1593
- query(t = {}) {
1594
- const e = [];
1595
- return st(this.root, this.switches, (n) => {
1596
- Object.keys(t).every((r) => t[r] === n[r]) && e.push(n);
1597
- }), e;
1598
- }
1599
- get(t) {
1600
- return Ce(this.root, this.switches, (e) => e.id === t) || this.detached.find((e) => e.id === t);
1601
- }
1602
- }
1603
- class ke {
1604
- constructor() {
1605
- this.handlers = /* @__PURE__ */ new Map();
1606
- }
1607
- add(t, e) {
1608
- this.handlers.set(t, e);
1609
- }
1610
- get(t) {
1611
- return this.handlers.get(t);
1612
- }
1613
- }
1614
- const Pe = (s) => {
1615
- let t = s, e = 0;
1616
- for (; t.parent; )
1617
- e = e + 1, t = t.parent;
1618
- return e;
1619
- }, Oe = (s) => s.map(([e, n]) => [Pe(e), e, n]).sort(([e], [n]) => e - n).map(([, e, n]) => [e, n]), Q = (s) => s instanceof Date ? !1 : s && typeof s == "object" && !Array.isArray(s), w = (s, ...t) => {
1620
- if (!t.length)
1621
- return s;
1622
- const e = t.shift();
1623
- if (Q(s) && Q(e))
1624
- for (const n in e)
1625
- Q(e[n]) ? (s[n] || Object.assign(s, { [n]: {} }), w(s[n], e[n])) : Object.assign(s, { [n]: e[n] });
1626
- return w(s, ...t);
1627
- }, Ae = (s, t) => !s || s === "all" ? !0 : s.some((e) => t.indexOf(e) > -1), Ne = (s, t) => {
1628
- let e = [], n = [], i;
1629
- const r = () => {
1630
- process.env.NODE_ENV !== "production" && console.time("state-processor.flush");
1631
- const c = /* @__PURE__ */ new Map(), l = Oe(e.map((a, u) => [a, n[u]])), h = (a, u) => {
1632
- var ot;
1633
- const p = c.get(a) || {}, d = u.context && !p.context, C = u.properties && !p.properties, N = u.layout && !p.layout;
1634
- c.set(a, {
1635
- context: p.context || d,
1636
- properties: p.properties || C,
1637
- layout: p.layout || N
1638
- }), C && (a.attributes.properties = {}), N && (a.attributes.layout = {}), d && (a.attributes.context = w({}, (ot = a.parent) == null ? void 0 : ot.attributes.context));
1639
- const nt = [], it = [], rt = [];
1640
- if (a.changesets.forEach((y) => {
1641
- const [f, V] = y;
1642
- Ae(V.breakpoints, s.breakpoints) && (C && (typeof f.properties == "function" ? nt.push(
1643
- f.properties
1644
- ) : w(a.attributes.properties, f.properties)), N && (typeof f.layout == "function" ? it.push(f.layout) : w(a.attributes.layout, f.layout)), d && (typeof f.context == "function" ? rt.push(f.context) : w(a.attributes.context, f.context)));
1645
- }), nt.forEach((y) => {
1646
- w(a.attributes.properties, y(a.attributes.properties));
1647
- }), it.forEach((y) => {
1648
- w(a.attributes.layout, y(a.attributes.layout));
1649
- }), rt.forEach((y) => {
1650
- w(a.attributes.context, y(a.attributes.context));
1651
- }), d || u.recursive) {
1652
- const y = s.getBranch(a), f = u.recursive ? u : {
1653
- context: !!d
1654
- };
1655
- a.getChildren(y).forEach((V) => {
1656
- h(V, f);
1657
- });
1658
- }
1659
- };
1660
- process.env.NODE_ENV !== "production" && console.timeEnd("state-processor.flush"), l.forEach(([a, u]) => {
1661
- h(a, u);
1662
- }), e = [], n = [], t(c);
1663
- }, o = () => {
1664
- clearTimeout(i), i = setTimeout(r, 0);
1665
- };
1666
- return (c, l) => {
1667
- const h = e.indexOf(c);
1668
- if (h > -1) {
1669
- const a = n[h];
1670
- return l.context && (a.context = !0), l.properties && (a.properties = !0), l.layout && (a.layout = !0), l.recursive && (a.recursive = !0), o();
1671
- }
1672
- return e.push(c), n.push(l), o();
1673
- };
1674
- };
1675
- class _e {
1676
- constructor(t, e = {}) {
1677
- this.providers = e, this.breakpoints = [], this.actionsState = { handlers: [], watchers: [] }, this.switches = {}, this.changesets = [], this.subscriptions = [], this.customComponentHandler = new ke(), this.events = t.events.createChild(this);
1678
- const n = new yt(this.events, "root");
1679
- n.name = `root-${t.name}`, this.nodes = new Ee(n, this.switches, this.events);
1680
- const i = this.processNode = Ne(this, (r) => {
1681
- const o = Array.from(r.keys());
1682
- process.env.NODE_ENV !== "production" && console.info(`STATE PROCESSOR: ${o.length} node(s) processed:
1683
- ${o.map(
1684
- (c) => `${c.name || "<no name>"} (${c.id})
1685
- `
1686
- )}`), o.forEach((c) => {
1687
- const l = r.get(c);
1688
- c.parent && c.parent.type === "root" && this.events.dispatch("components:root-children-changed", { node: c }), l != null && l.context && this.events.dispatch("components:context-changed", { node: c }), l != null && l.properties && this.events.dispatch("components:properties-changed", { node: c }), l != null && l.layout && this.events.dispatch("components:layout-changed", { node: c });
1689
- }), this.events.dispatch("components:component-model-initialized", {}, { bubbles: !0 });
1690
- });
1691
- Promise.all(
1692
- Object.keys(e).map((r) => e[r].load(this))
1693
- ), this.subscriptions.push(
1694
- this.events.subscribe(
1695
- "components:node-appended",
1696
- (r, o) => {
1697
- const { node: c } = o;
1698
- this.changesets.forEach((l) => {
1699
- const { changeset: h, target: a, removes: u } = l, [p, d] = h;
1700
- a.match(o.node) && (p.properties && u.push(c.writeProperties(p.properties, d)), p.context && u.push(c.writeContext(p.context, d)), p.layout && u.push(c.writeLayout(p.layout, d)));
1701
- });
1702
- }
1703
- )
1704
- ), this.subscriptions.push(
1705
- this.events.subscribe(
1706
- "components:node-appended",
1707
- (r, o) => {
1708
- i(o.node, { properties: !0, context: !0 });
1709
- }
1710
- )
1711
- ), this.subscriptions.push(
1712
- this.events.subscribe(
1713
- "components:set-properties",
1714
- (r, o) => {
1715
- i(o.node, { properties: !0 });
1716
- }
1717
- )
1718
- ), this.subscriptions.push(
1719
- this.events.subscribe(
1720
- "components:set-context",
1721
- (r, o) => {
1722
- i(o.node, { properties: !0, context: !0 });
1723
- }
1724
- )
1725
- ), this.subscriptions.push(
1726
- this.events.subscribe(
1727
- "components:set-indent",
1728
- (r, o) => {
1729
- i(o.node, { layout: !0 });
1730
- }
1731
- )
1732
- ), this.subscriptions.push(
1733
- this.events.subscribe(
1734
- "components:set-layout",
1735
- (r, o) => {
1736
- i(o.node, { layout: !0 });
1737
- }
1738
- )
1739
- ), this.subscriptions.push(
1740
- this.events.subscribe("components:node-switched", (r, { node: o, branch: c }) => {
1741
- i(o, {
1742
- layout: !0,
1743
- recursive: !0,
1744
- properties: !0,
1745
- context: !0
1746
- });
1747
- })
1748
- ), this.subscriptions.push(
1749
- this.events.subscribe("components:node-removed", (r, { parentNode: o }) => {
1750
- i(o, { properties: !0 });
1751
- })
1752
- ), this.events.parent && this.events.parent.dispatch("components:platform-created", { platform: this });
1753
- }
1754
- static getInstance(t) {
1755
- return t.getAsync("components");
1756
- }
1757
- addBreakpoint(t) {
1758
- this.breakpoints.indexOf(t) === -1 && (this.breakpoints.push(t), this.processNode(this.nodes.root, {
1759
- context: !0,
1760
- properties: !0,
1761
- layout: !0,
1762
- recursive: !0
1763
- }));
1764
- }
1765
- removeBreakpoint(t) {
1766
- const e = this.breakpoints.indexOf(t);
1767
- e > -1 && (this.breakpoints.splice(e, 1), this.processNode(this.nodes.root, {
1768
- context: !0,
1769
- properties: !0,
1770
- layout: !0,
1771
- recursive: !0
1772
- }));
1773
- }
1774
- setSwitch(t, e) {
1775
- this.switches[t.id] = e, this.events.dispatch("components:node-switched", { node: t, branch: e });
1776
- }
1777
- getBranch(t) {
1778
- return this.switches[t.id];
1779
- }
1780
- /**
1781
- * Creates a `ComponentNode` of the specified type.
1782
- * @param type Type of node.
1783
- */
1784
- createNode(t, e = {}) {
1785
- const n = new yt(this.events, t);
1786
- return e.detached && this.nodes.detached.push(n), n;
1787
- }
1788
- components() {
1789
- return new Z(this);
1790
- }
1791
- actions(t, e) {
1792
- return new tt(this, t, e);
1793
- }
1794
- write(t) {
1795
- const { provider: e, target: n, attributes: i, options: r = {}, removable: o } = t, c = t.key || et(), h = { changeset: [i, r], target: n, removes: [] };
1796
- if (e) {
1797
- const a = this.providers[e];
1798
- a.write(c, n, i, r), h.removes.push(() => {
1799
- a.remove(c);
1800
- });
1801
- }
1802
- return this.changesets.push(h), this.nodes.all.forEach((a) => {
1803
- if (n.match(a)) {
1804
- let u = () => {
1805
- };
1806
- i.properties && (u = a.writeProperties(i.properties, r, o)), i.context && (u = a.writeContext(i.context, r, o)), i.layout && (u = a.writeContext(i.layout, r, o)), h.removes.push(u);
1807
- }
1808
- }), () => {
1809
- if (o) {
1810
- h.removes.forEach((u) => u());
1811
- const a = this.changesets.indexOf(h);
1812
- a > -1 && this.changesets.splice(a, 1);
1813
- }
1814
- };
1815
- }
1816
- addComponentHandler(t, e) {
1817
- this.customComponentHandler.add(t, e);
1818
- }
1819
- getComponentHandler(t) {
1820
- return this.customComponentHandler.get(t);
1821
- }
1822
- dispose() {
1823
- this.subscriptions.forEach((t) => t());
1824
- }
1825
- }
1826
- const De = (s) => {
1827
- if (Array.isArray(s)) {
1828
- const [t, ...e] = s;
1829
- return {
1830
- definitionId: t,
1831
- overrides: e
1832
- };
1833
- }
1834
- return {
1835
- definitionId: s,
1836
- overrides: []
1837
- };
1838
- }, U = (s, t, e, n, i, r) => {
1839
- e.forEach((o) => {
1840
- const c = De(o), l = n[c.definitionId];
1841
- if (c.definitionId === "view") {
1842
- const h = s.createNode("view");
1843
- h.name = "view", Object.keys(i).forEach((a) => {
1844
- const u = i[a];
1845
- U(s, h, [u.entry], n, i, a);
1846
- }), t.appendChild(h), c.overrides.forEach((a) => {
1847
- a.properties && h.writeProperties(a.properties, {
1848
- breakpoints: a.breakpoints
1849
- }), a.context && h.writeContext(a.context, { breakpoints: a.breakpoints }), a.layout && h.writeLayout(a.layout, { breakpoints: a.breakpoints });
1850
- });
1851
- } else if (s.getComponentHandler(l.type)) {
1852
- const h = s.getComponentHandler(l.type);
1853
- h && h(c, {
1854
- platform: s,
1855
- node: t,
1856
- references: e,
1857
- definitions: n,
1858
- views: i,
1859
- branch: r
1860
- });
1861
- } else {
1862
- const h = n[c.definitionId];
1863
- if (process.env.NODE_ENV !== "production" && !h) {
1864
- P.error(
1865
- `No definition found for component type '${c.definitionId}'.`
1866
- );
1867
- return;
1868
- }
1869
- const a = s.createNode(h.type);
1870
- a.name = c.definitionId, a.tags = h.tags || [], h.properties && a.writeProperties(h.properties), h.context && a.writeContext(h.context), h.layout && a.writeLayout(h.layout), t.appendChild(a, r), c.overrides.forEach((u) => {
1871
- const p = { breakpoints: u.breakpoints };
1872
- u.properties && a.writeProperties(u.properties, p), u.context && a.writeContext(u.context, p), u.layout && a.writeLayout(u.layout, p);
1873
- }), h.children && U(s, a, h.children, n, i);
1874
- }
1875
- });
1876
- }, Fe = (s, t) => {
1877
- const { entry: e, components: n, breakpoints: i, views: r } = t, o = [];
1878
- return Object.keys(i).forEach((c) => {
1879
- const l = i[c], h = window.matchMedia(l);
1880
- h.matches && s.breakpoints.push(c);
1881
- const a = (u) => {
1882
- u.matches ? s.addBreakpoint(c) : s.removeBreakpoint(c);
1883
- };
1884
- h.addListener(a), o.push(() => h.removeListener(a));
1885
- }), U(s, s.nodes.root, [e], n, r), () => o.forEach((c) => {
1886
- c();
1887
- });
1888
- }, Be = (s, t) => ({
1889
- id: s.id,
1890
- type: s.type,
1891
- name: s.name,
1892
- branch: t || "default"
1893
- }), Qe = (s, t, e, n = et(), i = {}) => s.getAsync("components").then((r) => {
1894
- let o;
1895
- if (typeof t == "string") {
1896
- const h = new Z(r);
1897
- h.ofType(t), o = h;
1898
- } else
1899
- o = t;
1900
- const c = {}, l = (h) => {
1901
- const a = c[h.id];
1902
- return a ? Promise.resolve(a.controller) : _e.getInstance(s).then((u) => new Rt(u, h, n));
1903
- };
1904
- r.events.subscribe(
1905
- "components:node-enter",
1906
- (h, { node: a }) => {
1907
- o.match(a) && l(a).then((u) => {
1908
- Promise.resolve(e(u)).then((p) => {
1909
- c[a.id] = {
1910
- dispose: p,
1911
- controller: u
1912
- };
1913
- });
1914
- });
1915
- }
1916
- ), r.events.subscribe(
1917
- "components:node-exit",
1918
- (h, { node: a }) => {
1919
- const u = c[a.id];
1920
- u && (u.dispose && u.dispose(), i.reuseController || (u.controller.dispose(), delete c[a.id]));
1921
- }
1922
- );
1923
- });
1924
- class Ue {
1925
- constructor(t) {
1926
- this.aliases = /* @__PURE__ */ new Map(), this.components = /* @__PURE__ */ new Map(), this.logger = new P();
1927
- const { events: e } = t.get("$widget");
1928
- this.events = e;
1929
- }
1930
- getComponent(t) {
1931
- const e = this.aliases.get(t), n = this.components.get(e || t) || null;
1932
- return process.env.NODE_ENV !== "production" && (n || this.logger.warn(
1933
- e || t,
1934
- `Unable to resolve component: "${e || t}". You most likely forgot to register the required plugin for: ${e || t}.`
1935
- )), n;
1936
- }
1937
- registerComponent(t, e) {
1938
- return this.components.set(t, e), this.events.dispatch("component-resolver:resolve", t), () => {
1939
- this.components.delete(t);
1940
- };
1941
- }
1942
- registerResolver(t, e) {
1943
- return this.events.subscribe("component-resolver:resolve", (n, i) => {
1944
- if (i === t) {
1945
- const r = this.getComponent(t);
1946
- e(r);
1947
- }
1948
- });
1949
- }
1950
- registerAlias(t, e) {
1951
- return this.aliases.set(t, e), this.events.dispatch("component-resolver:resolve", t), () => {
1952
- this.aliases.delete(t);
1953
- };
1954
- }
1955
- }
1956
- const Re = "#____version____#", It = class extends Dt {
1957
- constructor(s, t = []) {
1958
- super(s, t, {
1959
- transformPluginSettings: (e, n, i) => {
1960
- const r = i.get("$settings");
1961
- return {
1962
- ...r.plugins && n ? r.plugins[n] || {} : {},
1963
- ...e
1964
- };
1965
- }
1966
- });
1967
- }
1968
- createImplementation(s) {
1969
- const t = super.createImplementation(s);
1970
- return t.bindings = s.bindings, t;
1971
- }
1972
- /**
1973
- * Performs navigation for widgets matching the specified selector by invoking a
1974
- * 'navigate' command.
1975
- * @param selector Widget selector matching the widget(s) to perform navigation on.
1976
- * @param route Route name.
1977
- * @param params Route params.
1978
- */
1979
- navigate(s, t, e) {
1980
- this.widgets.query(s).forEach((n) => n.invoke("navigate", { route: t, params: e }));
1981
- }
1982
- /**
1983
- * Creates a runtime based on provided configuration.
1984
- * @param configuration Runtime configuration.
1985
- */
1986
- static create(s = {}) {
1987
- const t = [Gt].concat(
1988
- s.configurationApiExtensions || []
1989
- );
1990
- return new It("humany", t);
1991
- }
1992
- /**
1993
- * Creates a widget runtime based on provided configuration and retains configuration handlers
1994
- * registered on global context. Use this factory to fully support the default embed script.
1995
- * Will return any existing widget runtime if available.
1996
- * @param configuration Runtime configuration.
1997
- * @param global Object to read configuration handlers from (default: window).
1998
- */
1999
- static createFromGlobal(s, t = {}) {
2000
- if (this.isRuntime(s))
2001
- return s.patch(t), s;
2002
- const e = [], n = s && s._c;
2003
- n && n.forEach(
2004
- (r) => e.push(r)
2005
- );
2006
- const i = this.create(t);
2007
- return i.container.register("$runtimecfg", e), i;
2008
- }
2009
- /**
2010
- * Determines whether the specified object is a valid widget runtime.
2011
- * @param obj Object to compare.
2012
- */
2013
- static isRuntime(s) {
2014
- return !!(s && typeof s == "object" && s.container && typeof s.container.get == "function" && s.container.get("$environment") === s && s.container.owner === s);
2015
- }
2016
- };
2017
- let Le = It;
2018
- Le.version = `${Re} (${X})`;
2019
- class Ye extends Nt {
2020
- constructor() {
2021
- super(...arguments), this.bindings = [];
2022
- }
2023
- }
2024
- class Ge extends ce {
2025
- constructor(t, e) {
2026
- super(t, e);
2027
- }
2028
- }
2029
- var Ie = /* @__PURE__ */ ((s) => (s.open = "open", s.closed = "closed", s.hidden = "hidden", s))(Ie || {});
2030
- class Ke extends ve {
2031
- constructor(t) {
2032
- super(t);
2033
- }
2034
- }
2035
- var Me = /* @__PURE__ */ ((s) => (s.guide = "guide", s.link = "link", s.default = "default", s))(Me || {}), ze = /* @__PURE__ */ ((s) => (s.MODAL = "modal", s.DRAWER = "drawer", s.DROPDOWN = "dropdown", s.NONE = "none", s))(ze || {});
2036
- const Je = (s, t) => fetch(t + "/config.json").then((e) => e.json()).then((e) => e.implementation).then(
2037
- (e) => s.createImplementation(e)
2038
- ), Xe = (s, t) => {
2039
- const e = `${s}${t}/interfaceauthorized`;
2040
- return fetch(e, {
1
+ export * from "@telia-ace/widget-core";
2
+ import { Environment as l } from "@telia-ace/widget-core";
3
+ import { supportBootstrapping as s } from "@webprovisions/bootstrapping";
4
+ import { Widget as p, destroyWidget as x } from "@webprovisions/platform";
5
+ var r = /* @__PURE__ */ ((t) => (t.guide = "guide", t.link = "link", t.default = "default", t))(r || {}), a = /* @__PURE__ */ ((t) => (t.MODAL = "modal", t.DRAWER = "drawer", t.DROPDOWN = "dropdown", t.NONE = "none", t))(a || {});
6
+ const d = (t, e) => fetch(e + "/config.json").then((n) => n.json()).then((n) => n.implementation).then(
7
+ (n) => t.createImplementation(n)
8
+ ), u = (t, e) => {
9
+ const n = `${t}${e}/interfaceauthorized`;
10
+ return fetch(n, {
2041
11
  method: "GET",
2042
12
  credentials: "include"
2043
- }).then((n) => n.status === 200 && n.ok);
13
+ }).then((o) => o.status === 200 && o.ok);
2044
14
  };
2045
15
  export {
2046
- Se as ActionResolver,
2047
- tt as ActionsController,
2048
- yt as ComponentNode,
2049
- Rt as ComponentNodeController,
2050
- _e as ComponentPlatform,
2051
- Z as ComponentQuery,
2052
- Ue as ComponentResolver,
2053
- Me as DialogItemType,
2054
- Le as Environment,
2055
- Le as Humany,
2056
- Ye as Implementation,
2057
- ze as PickerTypes,
2058
- Ge as Plugin,
2059
- fe as Widget,
2060
- Ie as WidgetRenderState,
2061
- Ke as WidgetType,
2062
- Be as asDescriptor,
2063
- He as bootstrap,
2064
- qe as componentConfigurationApi,
2065
- U as createChildren,
2066
- Fe as createComponentModel,
2067
- we as createEventSubscriber,
2068
- We as destroy,
2069
- Qe as extendComponent,
2070
- Ce as findComponent,
2071
- B as findVisibleComponents,
2072
- Je as loadImplementation,
2073
- je as supportBootstrapping,
2074
- st as traverseComponents,
2075
- Xe as verifyAuth,
2076
- Re as version
16
+ r as DialogItemType,
17
+ l as Humany,
18
+ a as PickerTypes,
19
+ p as Widget,
20
+ x as destroy,
21
+ d as loadImplementation,
22
+ s as supportBootstrapping,
23
+ u as verifyAuth
2077
24
  };