@telia-ace/knowledge-widget-adapters 1.0.44-experimental.9 → 1.0.45-next.0

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