@telia-ace/knowledge-widget-adapters 1.0.30-next.5 → 1.0.30-next.7

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,575 @@
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.2e371b74.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.90a22252.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(Ae, {
281
+ title: `client-name: ${n.clientName}, id: ${n.id}`,
282
+ className: "humany-non-resolved-contact-method"
283
+ }, /* @__PURE__ */ m.createElement(re, {
284
+ variant: "h5"
285
+ }, "Non resolved Contact Method type")) : null;
286
+ const c = (s = {}) => {
287
+ const i = h(h({}, n), s), {
288
+ id: r,
289
+ title: l,
290
+ clientName: d,
291
+ symbol: u,
292
+ inline: g,
293
+ onClick: v = () => {
294
+ },
295
+ description: f,
296
+ htmlParseInstruction: R,
297
+ className: K,
298
+ disabled: G,
299
+ guideId: U,
300
+ dispatch: V = () => {
301
+ },
302
+ expanded: D
303
+ } = i, W = g ? {
304
+ onKeyDown: (p) => {
305
+ p.key && p.key === "Enter" && (v(p, i), p.defaultPrevented || !D && V("expand", r));
306
+ },
307
+ onClick: (p) => {
308
+ v(p, i), p.defaultPrevented || !D && V("expand", r);
309
+ }
310
+ } : {
311
+ onClick: (p) => v(p, i),
312
+ routeName: "contact-method",
313
+ params: pe({
314
+ contactCategory: t,
315
+ guideId: U,
316
+ guideCategory: o,
317
+ phrase: a,
318
+ contactMethod: r,
319
+ uriName: fe(l)
320
+ })
321
+ };
322
+ return /* @__PURE__ */ m.createElement(Ie, h(h({
323
+ title: l,
324
+ "aria-label": l,
325
+ className: K,
326
+ disabled: G,
327
+ description: f,
328
+ "data-client-name": d
329
+ }, s), W), u && /* @__PURE__ */ m.createElement(ce, {
330
+ symbol: u
331
+ }), f ? /* @__PURE__ */ m.createElement("div", {
332
+ className: "humany-contact-link-rich-content"
333
+ }, /* @__PURE__ */ m.createElement(j, null, l), /* @__PURE__ */ m.createElement(Ne, {
334
+ html: f,
335
+ htmlParseInstruction: R
336
+ })) : /* @__PURE__ */ m.createElement(j, null, l));
337
+ };
338
+ return n.expanded ? /* @__PURE__ */ m.createElement(be, {
339
+ fallback: null
340
+ }, /* @__PURE__ */ m.createElement(e, y(h({}, n), {
341
+ renderDefault: c
342
+ }))) : c();
343
+ }, Se = Me, xe = (n) => {
344
+ var e, t, o, a, c, s, i, r;
345
+ return x`
346
+ display: flex;
347
+ padding: ${(e = n.theme.sizes) == null ? void 0 : e.large};
348
+ ${n.description ? "" : "align-items: center;"}
349
+ text-decoration: none;
350
+ span {
351
+ display: inline-block;
352
+ color: ${(t = n.theme.colors) == null ? void 0 : t.text};
353
+ }
354
+ i {
355
+ font-size: ${(o = n.theme.fonts) == null ? void 0 : o.large};
356
+ margin: 0 ${(a = n.theme.sizes) == null ? void 0 : a.large} 0 0;
357
+ min-height: ${(c = n.theme.fonts) == null ? void 0 : c.large};
358
+ min-width: ${(s = n.theme.fonts) == null ? void 0 : s.large};
359
+ line-height: ${(i = n.theme.fonts) == null ? void 0 : i.large};
360
+ display: inline-block;
361
+ vertical-align: bottom;
362
+ color: ${(r = n.theme.colors) == null ? void 0 : r.text};
363
+ }
364
+ `;
365
+ }, j = $(se)`
366
+ line-height: ${(n) => {
367
+ var e;
368
+ return (e = n.theme.fonts) == null ? void 0 : e.large;
369
+ }};
370
+ `, Ie = $(ie)`
371
+ ${(n) => xe(n)}
372
+
373
+ &:focus-visible {
374
+ ${O};
375
+ }
376
+ `, Ae = $.div`
377
+ text-align: center;
378
+ display: block;
379
+ ${(n) => {
380
+ var e, t;
381
+ return typeof ((e = n.theme.colors) == null ? void 0 : e.warning) != "undefined" && `color: ${(t = n.theme.colors) == null ? void 0 : t.warning};`;
382
+ }}
383
+ `, Re = (n) => {
384
+ var e, t, o;
385
+ return x`
386
+ ${le(n)}
387
+
388
+ > div {
389
+ padding: ${(e = n.theme.sizes) == null ? void 0 : e.large};
390
+
391
+ ${de(n)(
392
+ "h1",
393
+ x`
394
+ margin: 0;
395
+ `
396
+ )}
397
+ }
398
+
399
+ > ul {
400
+ &:not(:first-child) {
401
+ border-top: ${n.theme.border};
402
+ }
403
+
404
+ > li {
405
+ margin: 0;
406
+ white-space: normal;
407
+
408
+ > a {
409
+ overflow: hidden;
410
+ }
411
+
412
+ &:first-child > a {
413
+ border-radius: ${`${n.theme.borderRadius} ${n.theme.borderRadius} 0 0`};
414
+ }
415
+
416
+ &:last-child:not(:first-child) > a {
417
+ border-radius: ${`0 0 ${n.theme.borderRadius} ${n.theme.borderRadius}`};
418
+ }
419
+
420
+ &:not(:last-child) {
421
+ border-bottom: ${n.theme.border};
422
+ }
423
+
424
+ > div {
425
+ padding: ${(t = n.theme.sizes) == null ? void 0 : t.large};
426
+ }
427
+ }
428
+ }
429
+
430
+ @media (hover: hover) {
431
+ a:hover {
432
+ background-color: ${(o = n.theme.colors) == null ? void 0 : o.accent};
433
+ }
434
+ }
435
+ `;
436
+ }, Ve = $(me)`
437
+ ${(n) => Re(n)}
438
+ `, De = ({
439
+ contactMethods: n,
440
+ children: e,
441
+ guideId: t,
442
+ dispatch: o,
443
+ className: a = "",
444
+ itemRenderer: c,
445
+ action: s = () => {
446
+ },
447
+ header: i = ""
448
+ }) => n.length ? /* @__PURE__ */ m.createElement(Ve, {
449
+ header: i,
450
+ className: ge(a, "humany-contact-list"),
451
+ items: n,
452
+ renderItem: c ? (r) => /* @__PURE__ */ m.createElement("li", {
453
+ key: r.id,
454
+ "data-contact-method": r.id
455
+ }, c(r, { action: s, dispatch: o, guideId: t })) : (r) => /* @__PURE__ */ m.createElement("li", {
456
+ key: r.id,
457
+ "data-contact-method": r.id
458
+ }, /* @__PURE__ */ m.createElement(Se, y(h({}, r), {
459
+ action: s,
460
+ dispatch: o,
461
+ guideId: t
462
+ })))
463
+ }, e) : null, We = De, B = (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 = B(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, u = a || o || (() => {
485
+ });
486
+ return /* @__PURE__ */ m.createElement(Z, {
487
+ className: n,
488
+ schema: i,
489
+ layout: r,
490
+ data: l,
491
+ autoFocus: s,
492
+ onChange: (g, v) => {
493
+ const f = { schema: i, layout: r, data: v, meta: d };
494
+ 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 });
495
+ }
496
+ });
497
+ }
498
+ return null;
499
+ }, Je = Le, Te = (n) => {
500
+ const [e, t] = ve(null), o = ue();
501
+ return Ce(() => {
502
+ let a;
503
+ return o.getAsync("componentResolver").then((c) => {
504
+ a = c.registerResolver(
505
+ n,
506
+ (s) => t(s)
507
+ );
508
+ }), () => {
509
+ a && a();
510
+ };
511
+ }, [n]), e;
512
+ }, Qe = Te;
513
+ function Fe(n) {
514
+ n.getAsync("contactMethods").then((e) => {
515
+ e.create({
516
+ clientName: "custom.webservice",
517
+ render: "email.form",
518
+ onValidate: (t) => k(n, t),
519
+ onComplete: (t) => w(n, t),
520
+ onSubmit: (t) => H(n, t, (o) => y(h({}, o), {
521
+ ConfirmationText: o.ResponseHtml
522
+ }))
523
+ });
524
+ });
525
+ }
526
+ const Xe = (n, e, t) => n.getAsync("contactMethods").then((o) => {
527
+ o.create({
528
+ clientName: e,
529
+ render: "email.form",
530
+ handleClick: () => (a, c) => {
531
+ const {
532
+ body: d
533
+ } = c, u = d, { form: s, guideId: i, confirmationFallback: r } = u, l = C(u, ["form", "guideId", "confirmationFallback"]);
534
+ s || (a.preventDefault(), t(l));
535
+ },
536
+ onValidate: (a) => k(n, a),
537
+ onComplete: (a) => w(n, a),
538
+ onSubmit: (a) => {
539
+ const {
540
+ body: d
541
+ } = a, u = d, { form: c, guideId: s, confirmationFallback: i } = u, r = C(u, ["form", "guideId", "confirmationFallback"]), { values: l } = new I(c).export();
542
+ return Promise.resolve(t(r, l)).then((g) => g || i);
543
+ }
544
+ });
545
+ });
546
+ class Ye extends _ {
547
+ constructor(e, t) {
548
+ super(e, t), this.widget.implementation.configure((a) => {
549
+ a.plugin($e).plugin(ke).plugin(we).plugin(Ee).plugin(Fe).plugin(Pe);
550
+ });
551
+ }
552
+ }
553
+ export {
554
+ We as C,
555
+ Ne as D,
556
+ Je as F,
557
+ Re as a,
558
+ xe as b,
559
+ ke as c,
560
+ Se as d,
561
+ Ue as e,
562
+ w as f,
563
+ q as g,
564
+ $e as h,
565
+ we as i,
566
+ Xe as j,
567
+ Ye as k,
568
+ Pe as l,
569
+ Ee as p,
570
+ H as s,
571
+ Qe as u,
572
+ k as v,
573
+ Fe as w
574
+ };
575
+ //# sourceMappingURL=index.9dafde18.js.map