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

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