@telia-ace/knowledge-widget-adapters 1.0.44-experimental.8 → 1.0.44

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.
@@ -0,0 +1,581 @@
1
+ var J = Object.defineProperty, Q = Object.defineProperties;
2
+ var X = Object.getOwnPropertyDescriptors;
3
+ var P = Object.getOwnPropertySymbols;
4
+ var L = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable;
5
+ var M = (n, e, t) => e in n ? J(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, h = (n, e) => {
6
+ for (var t in e || (e = {}))
7
+ L.call(e, t) && M(n, t, e[t]);
8
+ if (P)
9
+ for (var t of P(e))
10
+ T.call(e, t) && M(n, t, e[t]);
11
+ return n;
12
+ }, y = (n, e) => Q(n, X(e));
13
+ var C = (n, e) => {
14
+ var t = {};
15
+ for (var o in n)
16
+ L.call(n, o) && e.indexOf(o) < 0 && (t[o] = n[o]);
17
+ if (n != null && P)
18
+ for (var o of P(n))
19
+ e.indexOf(o) < 0 && T.call(n, o) && (t[o] = n[o]);
20
+ return t;
21
+ };
22
+ var S = (n, e, t) => (M(n, typeof e != "symbol" ? e + "" : e, t), t);
23
+ var b = (n, e, t) => new Promise((o, a) => {
24
+ var c = (r) => {
25
+ try {
26
+ i(t.next(r));
27
+ } catch (l) {
28
+ a(l);
29
+ }
30
+ }, s = (r) => {
31
+ try {
32
+ i(t.throw(r));
33
+ } catch (l) {
34
+ a(l);
35
+ }
36
+ }, i = (r) => r.done ? o(r.value) : Promise.resolve(r.value).then(c, s);
37
+ i((t = t.apply(n, e)).next());
38
+ });
39
+ import { FormBuilder as Y, FormReader as I, FormComponent as Z } from "@telia-ace/widget-forms";
40
+ import { ComponentPlatform as F, Plugin as _ } from "@telia-ace/knowledge-widget-core";
41
+ import { css as x } from "@emotion/react";
42
+ import $ from "@emotion/styled";
43
+ import { Html as ee, genericHtml as te, borderTabStyle as O, linkTabStyle as ne, useComponent as oe, useRouteData as ae, Typography as re, StyledText as se, Link as ie, SymbolBadge as ce, itemList as le, headingElement as de, ItemList as me, useContainer as ue } from "@telia-ace/knowledge-widget-ui";
44
+ import { lock as he, createParams as pe, formatUrl as fe, appendClassNames as ge } from "@telia-ace/widget-utilities";
45
+ import m, { lazy as ye, Suspense as be, useState as ve, useEffect as Ce } from "react";
46
+ const A = (n, e, t = !1) => n.getManyAsync("matchingClient", "router").then((o) => {
47
+ const { formData: a } = new I(e.body.form).export(t), { router: c, matchingClient: s } = o, { params: i } = c.getRouteData();
48
+ return s.customRequest(
49
+ `contactmethods/${e.id}${t ? "/validatedwithpayload" : ""}`,
50
+ "POST",
51
+ {
52
+ body: a,
53
+ configuration: {
54
+ guideId: e.body.guideId || i.guideId
55
+ }
56
+ }
57
+ );
58
+ }), H = (n, e, t) => A(n, e).then((o) => t ? t(o) : o).then(({ ConfirmationText: o }) => o), k = (n, e) => A(n, e, !0).then((t) => ({
59
+ valid: t.Validation.IsValid,
60
+ errors: t.Validation.Errors,
61
+ errorTypes: t.Validation.ErrorTypes
62
+ })), q = (n, e) => A(n, e, !0).then(
63
+ (t) => Y.fromLegacyForm(e.id, t.ContactMethod.Form).get()
64
+ ), w = (n, e) => n.getAsync("matchingClient").then((t) => {
65
+ t.completeContactMethod(e.id);
66
+ });
67
+ function $e(n) {
68
+ n.getAsync("contactMethods").then((e) => {
69
+ e.create({
70
+ clientName: "email.form",
71
+ render: import("./email-form-component.c12f6804.js"),
72
+ onEvaluate: (t) => q(n, t),
73
+ onValidate: (t) => k(n, t),
74
+ onSubmit: (t) => H(n, t),
75
+ onComplete: (t) => w(n, t)
76
+ });
77
+ });
78
+ }
79
+ const z = (n, e, t) => {
80
+ const { url: o, width: a, height: c } = e, s = t || {}, i = document.createElement("a");
81
+ return i.href = o, i.search.replace("?", "").split("&").forEach((r) => {
82
+ const [l, d] = r.split("=");
83
+ typeof d != "undefined" && (s[l] = d);
84
+ }), i.search = Object.keys(s).map((r) => `${r}=${s[r]}`).join("&"), window.open(i.href, n, `width=${a},height=${c}`), "";
85
+ };
86
+ function ke(n) {
87
+ n.getAsync("contactMethods").then((e) => {
88
+ e.create({
89
+ clientName: "chat.popup",
90
+ render: "email.form",
91
+ handleClick: (t) => {
92
+ const { title: o, body: a } = t, l = a, { form: c, guideId: s, confirmationFallback: i } = l, r = C(l, ["form", "guideId", "confirmationFallback"]);
93
+ return c ? () => {
94
+ } : (d) => {
95
+ d.preventDefault(), z(o, r);
96
+ };
97
+ },
98
+ onValidate: (t) => k(n, t),
99
+ onComplete: (t) => w(n, t),
100
+ onSubmit: (t) => {
101
+ const { title: o, body: a } = t, d = a, { form: c, guideId: s, confirmationFallback: i } = d, r = C(d, ["form", "guideId", "confirmationFallback"]), l = new I(c).export().values;
102
+ return z(o, r, l), i;
103
+ }
104
+ });
105
+ });
106
+ }
107
+ function we(n) {
108
+ n.getAsync("contactMethods").then((e) => {
109
+ e.create({
110
+ clientName: "custom.freetext",
111
+ render: import("./free-text-component.c06abc12.js")
112
+ });
113
+ });
114
+ }
115
+ function Pe(n) {
116
+ n.getAsync("contactMethods").then((e) => {
117
+ e.create({
118
+ clientName: "custom.link",
119
+ render: import("./link-component.484bbcf2.js")
120
+ });
121
+ });
122
+ }
123
+ function Ee(n) {
124
+ n.getAsync("contactMethods").then((e) => {
125
+ e.create({
126
+ clientName: "phone.text",
127
+ render: import("./phone-component.0c878514.js")
128
+ });
129
+ });
130
+ }
131
+ const E = (n, e) => b(void 0, null, function* () {
132
+ const t = n.get(e.clientName);
133
+ let { description: o, disabled: a, onClick: c } = e;
134
+ if (t) {
135
+ const { handleClick: s, handleDescription: i, handleDisabled: r } = t;
136
+ typeof s == "function" && (c = yield Promise.resolve(s(e))), typeof i == "function" && (o = yield Promise.resolve(i(e))), typeof r == "function" && (a = yield Promise.resolve(r(e)));
137
+ }
138
+ return Promise.resolve(y(h({}, e), {
139
+ description: o,
140
+ disabled: a,
141
+ onClick: c
142
+ }));
143
+ });
144
+ class N {
145
+ constructor(e, t) {
146
+ S(this, "adapters", /* @__PURE__ */ new Map());
147
+ S(this, "subs", []);
148
+ if (this.container = e, this.componentPlatform = t, t) {
149
+ t.components().ofType("contact-list").select().actions.watch("contact-list.fetched", (s, i) => b(this, null, function* () {
150
+ const { contactMethods: r } = s;
151
+ if (r) {
152
+ const l = Promise.all(
153
+ r.map(
154
+ (d) => E(this.adapters, d)
155
+ )
156
+ );
157
+ yield Promise.resolve(l).then((d) => {
158
+ s.contactMethods = d;
159
+ });
160
+ }
161
+ return i(s);
162
+ }));
163
+ const a = t.components().ofType("guide").select();
164
+ a.actions.watch("guide.fetched", (s, i) => b(this, null, function* () {
165
+ const { contactMethods: r } = s;
166
+ if (r) {
167
+ const l = Promise.all(
168
+ r.map(
169
+ (d) => E(this.adapters, d)
170
+ )
171
+ );
172
+ yield Promise.resolve(l).then((d) => {
173
+ s.contactMethods = d;
174
+ });
175
+ }
176
+ return i(s);
177
+ })), a.actions.watch("guide.handover", (s, i) => b(this, null, function* () {
178
+ const { handoverContactMethods: r } = s;
179
+ if (r) {
180
+ const l = Promise.all(
181
+ r.map(
182
+ (d) => E(this.adapters, d)
183
+ )
184
+ );
185
+ yield Promise.resolve(l).then((d) => {
186
+ s.handoverContactMethods = d;
187
+ });
188
+ }
189
+ return i(s);
190
+ })), t.components().ofType("contact-method").select().actions.watch("contact-method.fetched", (s, i) => b(this, null, function* () {
191
+ const { contactMethod: r } = s;
192
+ return r ? E(this.adapters, r).then(
193
+ (l) => i(y(h({}, s), { contactMethod: l }))
194
+ ) : i(s);
195
+ }));
196
+ }
197
+ }
198
+ static create(e) {
199
+ return F.getInstance(e).then((t) => new N(e, t));
200
+ }
201
+ static getInstance(e, t = "contactMethods") {
202
+ return he(e)(() => e.getAsync(t).then((o) => {
203
+ let a = o;
204
+ return a || F.getInstance(e).then((c) => (a = new N(e, c), e.registerAsync(t, () => a), a));
205
+ }));
206
+ }
207
+ track(e = {}, t) {
208
+ const { events: o } = this.container.get("$widget");
209
+ o.dispatch("tracking:service-client-response", {
210
+ type: t,
211
+ data: e
212
+ });
213
+ }
214
+ complete(e) {
215
+ const { id: t, title: o, clientName: a, expanded: c, body: s } = e;
216
+ this.track(
217
+ { contactMethod: { id: t, title: o, expanded: c, type: a }, hasGuide: !!s.guideId },
218
+ "contact-method-complete"
219
+ );
220
+ const i = this.adapters.get(a);
221
+ if (i && i.onComplete)
222
+ return i.onComplete(e);
223
+ }
224
+ evaluate(e) {
225
+ const { clientName: t } = e, o = this.adapters.get(t);
226
+ return o && o.onEvaluate ? Promise.resolve(o.onEvaluate(e)) : Promise.resolve(e.body.form);
227
+ }
228
+ validate(e) {
229
+ const { id: t, title: o, clientName: a } = e, c = this.adapters.get(a);
230
+ return c && c.onValidate ? Promise.resolve(c.onValidate(e)).then((s) => {
231
+ this.track(
232
+ { contactMethod: { id: t, title: o, type: a }, isValid: s.valid },
233
+ "contact-method-validate"
234
+ );
235
+ const { events: i } = this.container.get("$widget");
236
+ return i.dispatch("form:validated", { isValid: s.valid }), s;
237
+ }) : Promise.resolve({ valid: !0 });
238
+ }
239
+ submit(e) {
240
+ const { clientName: t } = e, o = this.adapters.get(t);
241
+ return o && o.onSubmit ? Promise.resolve(o.onSubmit(e)).then((a) => (this.complete(e), a)) : Promise.resolve("");
242
+ }
243
+ create(e) {
244
+ const { clientName: t, render: o } = e;
245
+ return this.adapters.set(t, h({
246
+ onValidate: (a) => k(this.container, a),
247
+ onEvaluate: (a) => q(this.container, a),
248
+ onComplete: (a) => w(this.container, a)
249
+ }, e)), this.container.getAsync("componentResolver").then((a) => {
250
+ typeof o == "string" ? this.subs.push(a.registerAlias(t, o)) : this.subs.push(
251
+ a.registerComponent(
252
+ t,
253
+ ye(() => o)
254
+ )
255
+ );
256
+ });
257
+ }
258
+ dispose() {
259
+ this.subs.forEach((e) => e());
260
+ }
261
+ }
262
+ const Ue = N, Ne = $(ee)`
263
+ ${te}
264
+ font-weight: 300;
265
+ line-height: 1.5em;
266
+ button:focus-visible {
267
+ ${O};
268
+ }
269
+
270
+ a:focus-visible {
271
+ ${ne};
272
+ }
273
+ `, Me = (n) => {
274
+ const e = oe(n.clientName), {
275
+ params: { contactCategory: t, guideCategory: o, phrase: a }
276
+ } = ae();
277
+ if (typeof e == "undefined")
278
+ return null;
279
+ if (e === null)
280
+ return process.env.NODE_ENV !== "production" ? /* @__PURE__ */ m.createElement(
281
+ Ae,
282
+ {
283
+ title: `client-name: ${n.clientName}, id: ${n.id}`,
284
+ className: "humany-non-resolved-contact-method"
285
+ },
286
+ /* @__PURE__ */ m.createElement(re, { variant: "h5" }, "Non resolved Contact Method type")
287
+ ) : null;
288
+ const c = (s = {}) => {
289
+ const i = h(h({}, n), s), {
290
+ id: r,
291
+ title: l,
292
+ clientName: d,
293
+ symbol: u,
294
+ inline: g,
295
+ onClick: v = () => {
296
+ },
297
+ description: f,
298
+ htmlParseInstruction: R,
299
+ className: K,
300
+ disabled: G,
301
+ guideId: U,
302
+ dispatch: V = () => {
303
+ },
304
+ expanded: D
305
+ } = i, W = g ? {
306
+ onKeyDown: (p) => {
307
+ p.key && p.key === "Enter" && (v(p, i), p.defaultPrevented || !D && V("expand", r));
308
+ },
309
+ onClick: (p) => {
310
+ v(p, i), p.defaultPrevented || !D && V("expand", r);
311
+ }
312
+ } : {
313
+ onClick: (p) => v(p, i),
314
+ routeName: "contact-method",
315
+ params: pe({
316
+ contactCategory: t,
317
+ guideId: U,
318
+ guideCategory: o,
319
+ phrase: a,
320
+ contactMethod: r,
321
+ uriName: fe(l)
322
+ })
323
+ };
324
+ return /* @__PURE__ */ m.createElement(
325
+ Ie,
326
+ h(h({
327
+ title: l,
328
+ "aria-label": l,
329
+ className: K,
330
+ disabled: G,
331
+ description: f,
332
+ "data-client-name": d
333
+ }, s), W),
334
+ u && /* @__PURE__ */ m.createElement(ce, { symbol: u }),
335
+ f ? /* @__PURE__ */ m.createElement("div", { className: "humany-contact-link-rich-content" }, /* @__PURE__ */ m.createElement(j, null, l), /* @__PURE__ */ m.createElement(
336
+ Ne,
337
+ {
338
+ html: f,
339
+ htmlParseInstruction: R
340
+ }
341
+ )) : /* @__PURE__ */ m.createElement(j, null, l)
342
+ );
343
+ };
344
+ return n.expanded ? /* @__PURE__ */ m.createElement(be, { fallback: null }, /* @__PURE__ */ m.createElement(e, y(h({}, n), { renderDefault: c }))) : c();
345
+ }, Se = Me, xe = (n) => {
346
+ var e, t, o, a, c, s, i, r;
347
+ return x`
348
+ display: flex;
349
+ padding: ${(e = n.theme.sizes) == null ? void 0 : e.large};
350
+ ${n.description ? "" : "align-items: center;"}
351
+ text-decoration: none;
352
+ span {
353
+ display: inline-block;
354
+ color: ${(t = n.theme.colors) == null ? void 0 : t.text};
355
+ }
356
+ i {
357
+ font-size: ${(o = n.theme.fonts) == null ? void 0 : o.large};
358
+ margin: 0 ${(a = n.theme.sizes) == null ? void 0 : a.large} 0 0;
359
+ min-height: ${(c = n.theme.fonts) == null ? void 0 : c.large};
360
+ min-width: ${(s = n.theme.fonts) == null ? void 0 : s.large};
361
+ line-height: ${(i = n.theme.fonts) == null ? void 0 : i.large};
362
+ display: inline-block;
363
+ vertical-align: bottom;
364
+ color: ${(r = n.theme.colors) == null ? void 0 : r.text};
365
+ }
366
+ `;
367
+ }, j = $(se)`
368
+ line-height: ${(n) => {
369
+ var e;
370
+ return (e = n.theme.fonts) == null ? void 0 : e.large;
371
+ }};
372
+ `, Ie = $(ie)`
373
+ ${(n) => xe(n)}
374
+
375
+ &:focus-visible {
376
+ ${O};
377
+ }
378
+ `, Ae = $.div`
379
+ text-align: center;
380
+ display: block;
381
+ ${(n) => {
382
+ var e, t;
383
+ return typeof ((e = n.theme.colors) == null ? void 0 : e.warning) != "undefined" && `color: ${(t = n.theme.colors) == null ? void 0 : t.warning};`;
384
+ }}
385
+ `, Re = (n) => {
386
+ var e, t, o;
387
+ return x`
388
+ ${le(n)}
389
+
390
+ > div {
391
+ padding: ${(e = n.theme.sizes) == null ? void 0 : e.large};
392
+
393
+ ${de(n)(
394
+ "h1",
395
+ x`
396
+ margin: 0;
397
+ `
398
+ )}
399
+ }
400
+
401
+ > ul {
402
+ &:not(:first-child) {
403
+ border-top: ${n.theme.border};
404
+ }
405
+
406
+ > li {
407
+ margin: 0;
408
+ white-space: normal;
409
+
410
+ > a {
411
+ overflow: hidden;
412
+ }
413
+
414
+ &:first-child > a {
415
+ border-radius: ${`${n.theme.borderRadius} ${n.theme.borderRadius} 0 0`};
416
+ }
417
+
418
+ &:last-child:not(:first-child) > a {
419
+ border-radius: ${`0 0 ${n.theme.borderRadius} ${n.theme.borderRadius}`};
420
+ }
421
+
422
+ &:not(:last-child) {
423
+ border-bottom: ${n.theme.border};
424
+ }
425
+
426
+ > div {
427
+ padding: ${(t = n.theme.sizes) == null ? void 0 : t.large};
428
+ }
429
+ }
430
+ }
431
+
432
+ @media (hover: hover) {
433
+ a:hover {
434
+ background-color: ${(o = n.theme.colors) == null ? void 0 : o.accent};
435
+ }
436
+ }
437
+ `;
438
+ }, Ve = $(me)`
439
+ ${(n) => Re(n)}
440
+ `, De = ({
441
+ contactMethods: n,
442
+ children: e,
443
+ guideId: t,
444
+ dispatch: o,
445
+ className: a = "",
446
+ itemRenderer: c,
447
+ action: s = () => {
448
+ },
449
+ header: i = ""
450
+ }) => n.length ? /* @__PURE__ */ m.createElement(
451
+ Ve,
452
+ {
453
+ header: i,
454
+ className: ge(a, "humany-contact-list"),
455
+ items: n,
456
+ renderItem: c ? (r) => /* @__PURE__ */ m.createElement("li", { key: r.id, "data-contact-method": r.id }, c(r, { action: s, dispatch: o, guideId: t })) : (r) => /* @__PURE__ */ m.createElement("li", { key: r.id, "data-contact-method": r.id }, /* @__PURE__ */ m.createElement(
457
+ Se,
458
+ y(h({}, r), {
459
+ action: s,
460
+ dispatch: o,
461
+ guideId: t
462
+ })
463
+ ))
464
+ },
465
+ e
466
+ ) : null, We = De, B = (n, e) => {
467
+ if (n.actionKey === e)
468
+ return n;
469
+ if (!n.properties)
470
+ return null;
471
+ const t = Object.keys(n.properties);
472
+ let o;
473
+ for (let a = 0; a < t.length; a++)
474
+ if (o = B(n.properties[t[a]], e), o)
475
+ return o;
476
+ return !1;
477
+ }, Le = ({
478
+ className: n,
479
+ body: { form: e },
480
+ id: t,
481
+ action: o,
482
+ dispatch: a,
483
+ disabled: c,
484
+ autoFocus: s
485
+ }) => {
486
+ if (e && !c) {
487
+ const { schema: i, layout: r, data: l, meta: d } = e, u = a || o || (() => {
488
+ });
489
+ return /* @__PURE__ */ m.createElement(
490
+ Z,
491
+ {
492
+ className: n,
493
+ schema: i,
494
+ layout: r,
495
+ data: l,
496
+ autoFocus: s,
497
+ onChange: (g, v) => {
498
+ const f = { schema: i, layout: r, data: v, meta: d };
499
+ g.toString() === "submit" ? u("submit", { id: t, form: f }) : B(i, g).evaluate ? u("evaluate", { id: t, form: f }) : u("validate", { id: t, form: f });
500
+ }
501
+ }
502
+ );
503
+ }
504
+ return null;
505
+ }, Je = Le, Te = (n) => {
506
+ const [e, t] = ve(null), o = ue();
507
+ return Ce(() => {
508
+ let a;
509
+ return o.getAsync("componentResolver").then((c) => {
510
+ a = c.registerResolver(
511
+ n,
512
+ (s) => t(s)
513
+ );
514
+ }), () => {
515
+ a && a();
516
+ };
517
+ }, [n]), e;
518
+ }, Qe = Te;
519
+ function Fe(n) {
520
+ n.getAsync("contactMethods").then((e) => {
521
+ e.create({
522
+ clientName: "custom.webservice",
523
+ render: "email.form",
524
+ onValidate: (t) => k(n, t),
525
+ onComplete: (t) => w(n, t),
526
+ onSubmit: (t) => H(n, t, (o) => y(h({}, o), {
527
+ ConfirmationText: o.ResponseHtml
528
+ }))
529
+ });
530
+ });
531
+ }
532
+ const Xe = (n, e, t) => n.getAsync("contactMethods").then((o) => {
533
+ o.create({
534
+ clientName: e,
535
+ render: "email.form",
536
+ handleClick: () => (a, c) => {
537
+ const {
538
+ body: d
539
+ } = c, u = d, { form: s, guideId: i, confirmationFallback: r } = u, l = C(u, ["form", "guideId", "confirmationFallback"]);
540
+ s || (a.preventDefault(), t(l));
541
+ },
542
+ onValidate: (a) => k(n, a),
543
+ onComplete: (a) => w(n, a),
544
+ onSubmit: (a) => {
545
+ const {
546
+ body: d
547
+ } = a, u = d, { form: c, guideId: s, confirmationFallback: i } = u, r = C(u, ["form", "guideId", "confirmationFallback"]), { values: l } = new I(c).export();
548
+ return Promise.resolve(t(r, l)).then((g) => g || i);
549
+ }
550
+ });
551
+ });
552
+ class Ye extends _ {
553
+ constructor(e, t) {
554
+ super(e, t), this.widget.implementation.configure((a) => {
555
+ a.plugin($e).plugin(ke).plugin(we).plugin(Ee).plugin(Fe).plugin(Pe);
556
+ });
557
+ }
558
+ }
559
+ export {
560
+ We as C,
561
+ Ne as D,
562
+ Je as F,
563
+ Re as a,
564
+ xe as b,
565
+ ke as c,
566
+ Se as d,
567
+ Ue as e,
568
+ w as f,
569
+ q as g,
570
+ $e as h,
571
+ we as i,
572
+ Xe as j,
573
+ Ye as k,
574
+ Pe as l,
575
+ Ee as p,
576
+ H as s,
577
+ Qe as u,
578
+ k as v,
579
+ Fe as w
580
+ };
581
+ //# sourceMappingURL=index.c1d1bd5b.js.map