@telia-ace/knowledge-widget-adapters 1.0.13 → 1.0.14

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 (125) hide show
  1. package/{lib-esm → dist}/contact-methods/chat-popup/chat-popup-plugin.d.ts +0 -0
  2. package/{lib-esm → dist}/contact-methods/chat-popup/index.d.ts +0 -0
  3. package/{lib-esm → dist}/contact-methods/email/email-form-component.d.ts +0 -0
  4. package/{lib-esm → dist}/contact-methods/email/email-plugin.d.ts +0 -0
  5. package/{lib-esm → dist}/contact-methods/email/index.d.ts +0 -0
  6. package/{lib-esm → dist}/contact-methods/free-text/free-text-component.d.ts +0 -0
  7. package/{lib-esm → dist}/contact-methods/free-text/free-text-plugin.d.ts +0 -0
  8. package/{lib-esm → dist}/contact-methods/free-text/index.d.ts +0 -0
  9. package/{lib-esm → dist}/contact-methods/index.d.ts +0 -0
  10. package/{lib-esm → dist}/contact-methods/link/index.d.ts +0 -0
  11. package/{lib-esm → dist}/contact-methods/link/link-component.d.ts +0 -0
  12. package/{lib-esm → dist}/contact-methods/link/link-plugin.d.ts +0 -0
  13. package/{lib-esm → dist}/contact-methods/phone/index.d.ts +0 -0
  14. package/{lib-esm → dist}/contact-methods/phone/phone-component.d.ts +0 -0
  15. package/{lib-esm → dist}/contact-methods/phone/phone-plugin.d.ts +0 -0
  16. package/{lib-esm → dist}/contact-methods/platform.d.ts +0 -0
  17. package/{lib-esm → dist}/contact-methods/ui/confirmation.d.ts +0 -0
  18. package/{lib-esm → dist}/contact-methods/ui/contact-list.d.ts +0 -0
  19. package/{lib-esm → dist}/contact-methods/ui/contact-method.d.ts +0 -0
  20. package/{lib-esm → dist}/contact-methods/ui/description.d.ts +0 -0
  21. package/{lib-esm → dist}/contact-methods/ui/form.d.ts +0 -0
  22. package/{lib-esm → dist}/contact-methods/ui/index.d.ts +0 -0
  23. package/{lib-esm → dist}/contact-methods/ui/use-contact-method.d.ts +0 -0
  24. package/{lib-esm → dist}/contact-methods/web-service/index.d.ts +0 -0
  25. package/{lib-esm → dist}/contact-methods/web-service/web-service-plugin.d.ts +0 -0
  26. package/{lib-esm → dist}/create-adapter.d.ts +0 -0
  27. package/{lib-esm → dist}/default-contact-methods-plugin.d.ts +0 -0
  28. package/dist/email-form-component.js +63 -0
  29. package/dist/email-form-component.js.map +1 -0
  30. package/dist/free-text-component.js +31 -0
  31. package/dist/free-text-component.js.map +1 -0
  32. package/{lib-esm → dist}/index.d.ts +0 -0
  33. package/dist/index.js +8 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/index2.js +699 -0
  36. package/dist/index2.js.map +1 -0
  37. package/dist/link-component.js +16 -0
  38. package/dist/link-component.js.map +1 -0
  39. package/dist/phone-component.js +15 -0
  40. package/dist/phone-component.js.map +1 -0
  41. package/package.json +12 -13
  42. package/lib/contact-methods/chat-popup/chat-popup-plugin.d.ts +0 -2
  43. package/lib/contact-methods/chat-popup/chat-popup-plugin.js +0 -79
  44. package/lib/contact-methods/chat-popup/index.d.ts +0 -1
  45. package/lib/contact-methods/chat-popup/index.js +0 -8
  46. package/lib/contact-methods/email/email-form-component.d.ts +0 -4
  47. package/lib/contact-methods/email/email-form-component.js +0 -58
  48. package/lib/contact-methods/email/email-plugin.d.ts +0 -16
  49. package/lib/contact-methods/email/email-plugin.js +0 -83
  50. package/lib/contact-methods/email/index.d.ts +0 -1
  51. package/lib/contact-methods/email/index.js +0 -12
  52. package/lib/contact-methods/free-text/free-text-component.d.ts +0 -4
  53. package/lib/contact-methods/free-text/free-text-component.js +0 -49
  54. package/lib/contact-methods/free-text/free-text-plugin.d.ts +0 -2
  55. package/lib/contact-methods/free-text/free-text-plugin.js +0 -34
  56. package/lib/contact-methods/free-text/index.d.ts +0 -1
  57. package/lib/contact-methods/free-text/index.js +0 -8
  58. package/lib/contact-methods/index.d.ts +0 -10
  59. package/lib/contact-methods/index.js +0 -31
  60. package/lib/contact-methods/link/index.d.ts +0 -1
  61. package/lib/contact-methods/link/index.js +0 -8
  62. package/lib/contact-methods/link/link-component.d.ts +0 -4
  63. package/lib/contact-methods/link/link-component.js +0 -13
  64. package/lib/contact-methods/link/link-plugin.d.ts +0 -2
  65. package/lib/contact-methods/link/link-plugin.js +0 -34
  66. package/lib/contact-methods/phone/index.d.ts +0 -1
  67. package/lib/contact-methods/phone/index.js +0 -8
  68. package/lib/contact-methods/phone/phone-component.d.ts +0 -4
  69. package/lib/contact-methods/phone/phone-component.js +0 -12
  70. package/lib/contact-methods/phone/phone-plugin.d.ts +0 -2
  71. package/lib/contact-methods/phone/phone-plugin.js +0 -34
  72. package/lib/contact-methods/platform.d.ts +0 -50
  73. package/lib/contact-methods/platform.js +0 -273
  74. package/lib/contact-methods/ui/confirmation.d.ts +0 -6
  75. package/lib/contact-methods/ui/confirmation.js +0 -47
  76. package/lib/contact-methods/ui/contact-list.d.ts +0 -15
  77. package/lib/contact-methods/ui/contact-list.js +0 -61
  78. package/lib/contact-methods/ui/contact-method.d.ts +0 -39
  79. package/lib/contact-methods/ui/contact-method.js +0 -110
  80. package/lib/contact-methods/ui/description.d.ts +0 -2
  81. package/lib/contact-methods/ui/description.js +0 -13
  82. package/lib/contact-methods/ui/form.d.ts +0 -4
  83. package/lib/contact-methods/ui/form.js +0 -54
  84. package/lib/contact-methods/ui/index.d.ts +0 -7
  85. package/lib/contact-methods/ui/index.js +0 -20
  86. package/lib/contact-methods/ui/use-contact-method.d.ts +0 -2
  87. package/lib/contact-methods/ui/use-contact-method.js +0 -39
  88. package/lib/contact-methods/web-service/index.d.ts +0 -1
  89. package/lib/contact-methods/web-service/index.js +0 -8
  90. package/lib/contact-methods/web-service/web-service-plugin.d.ts +0 -2
  91. package/lib/contact-methods/web-service/web-service-plugin.js +0 -30
  92. package/lib/create-adapter.d.ts +0 -7
  93. package/lib/create-adapter.js +0 -43
  94. package/lib/default-contact-methods-plugin.d.ts +0 -8
  95. package/lib/default-contact-methods-plugin.js +0 -42
  96. package/lib/index.d.ts +0 -5
  97. package/lib/index.js +0 -25
  98. package/lib-esm/contact-methods/chat-popup/chat-popup-plugin.js +0 -76
  99. package/lib-esm/contact-methods/chat-popup/index.js +0 -1
  100. package/lib-esm/contact-methods/email/email-form-component.js +0 -33
  101. package/lib-esm/contact-methods/email/email-plugin.js +0 -52
  102. package/lib-esm/contact-methods/email/index.js +0 -1
  103. package/lib-esm/contact-methods/free-text/free-text-component.js +0 -21
  104. package/lib-esm/contact-methods/free-text/free-text-plugin.js +0 -8
  105. package/lib-esm/contact-methods/free-text/index.js +0 -1
  106. package/lib-esm/contact-methods/index.js +0 -8
  107. package/lib-esm/contact-methods/link/index.js +0 -1
  108. package/lib-esm/contact-methods/link/link-component.js +0 -11
  109. package/lib-esm/contact-methods/link/link-plugin.js +0 -8
  110. package/lib-esm/contact-methods/phone/index.js +0 -1
  111. package/lib-esm/contact-methods/phone/phone-component.js +0 -10
  112. package/lib-esm/contact-methods/phone/phone-plugin.js +0 -8
  113. package/lib-esm/contact-methods/platform.js +0 -270
  114. package/lib-esm/contact-methods/ui/confirmation.js +0 -22
  115. package/lib-esm/contact-methods/ui/contact-list.js +0 -32
  116. package/lib-esm/contact-methods/ui/contact-method.js +0 -81
  117. package/lib-esm/contact-methods/ui/description.js +0 -8
  118. package/lib-esm/contact-methods/ui/form.js +0 -49
  119. package/lib-esm/contact-methods/ui/index.js +0 -6
  120. package/lib-esm/contact-methods/ui/use-contact-method.js +0 -37
  121. package/lib-esm/contact-methods/web-service/index.js +0 -1
  122. package/lib-esm/contact-methods/web-service/web-service-plugin.js +0 -27
  123. package/lib-esm/create-adapter.js +0 -39
  124. package/lib-esm/default-contact-methods-plugin.js +0 -39
  125. package/lib-esm/index.js +0 -3
package/dist/index2.js ADDED
@@ -0,0 +1,699 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ var __async = (__this, __arguments, generator) => {
33
+ return new Promise((resolve, reject) => {
34
+ var fulfilled = (value) => {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ };
41
+ var rejected = (value) => {
42
+ try {
43
+ step(generator.throw(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ };
48
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
+ step((generator = generator.apply(__this, __arguments)).next());
50
+ });
51
+ };
52
+ import { FormReader, FormBuilder, FormComponent } from "@telia-ace/widget-forms";
53
+ import { ComponentPlatform, Plugin } from "@telia-ace/knowledge-widget-core";
54
+ import { lock, createParams, formatUrl, appendClassNames } from "@telia-ace/widget-utilities";
55
+ import React__default, { lazy, Suspense, useState, useEffect } from "react";
56
+ import { Paragraph, headingElement, Html, genericHtml, borderTabStyle, linkTabStyle, StyledText, Link, useComponent, useRouteData, SymbolBadge, itemList, ItemList, useContainer } from "@telia-ace/knowledge-widget-ui";
57
+ import styled, { css } from "styled-components";
58
+ const post = (container, contactMethod, validate2 = false) => container.getManyAsync("matchingClient", "router").then((services) => {
59
+ const { formData } = new FormReader(contactMethod.body.form).export(validate2);
60
+ const { router, matchingClient } = services;
61
+ const { params } = router.getRouteData();
62
+ return matchingClient.customRequest(`contactmethods/${contactMethod.id}${validate2 ? "/validatedwithpayload" : ""}`, "POST", {
63
+ body: formData,
64
+ configuration: {
65
+ guideId: contactMethod.body.guideId || params.guideId
66
+ }
67
+ });
68
+ });
69
+ const submit = (container, contactMethod, transform) => post(container, contactMethod).then((response) => transform ? transform(response) : response).then(({ ConfirmationText }) => ConfirmationText);
70
+ const validate = (container, contactMethod) => post(container, contactMethod, true).then((result) => ({
71
+ valid: result.Validation.IsValid,
72
+ errors: result.Validation.Errors,
73
+ errorTypes: result.Validation.ErrorTypes
74
+ }));
75
+ const evaluate = (container, contactMethod) => post(container, contactMethod, true).then((result) => FormBuilder.fromLegacyForm(contactMethod.id, result.ContactMethod.Form).get());
76
+ const complete = (container, contactMethod) => container.getAsync("matchingClient").then((matchingClient) => {
77
+ matchingClient.completeContactMethod(contactMethod.id);
78
+ });
79
+ function emailPlugin(container) {
80
+ container.getAsync("contactMethods").then((platform) => {
81
+ platform.create({
82
+ clientName: "email.form",
83
+ render: import("./email-form-component.js"),
84
+ onEvaluate: (contactMethod) => evaluate(container, contactMethod),
85
+ onValidate: (contactMethod) => validate(container, contactMethod),
86
+ onSubmit: (contactMethod) => submit(container, contactMethod),
87
+ onComplete: (contactMethod) => complete(container, contactMethod)
88
+ });
89
+ });
90
+ }
91
+ const popup = (title, settings, formValues) => {
92
+ const { url, width, height } = settings;
93
+ const queries = formValues ? formValues : {};
94
+ const link = document.createElement("a");
95
+ link.href = url;
96
+ link.search.replace("?", "").split("&").forEach((part) => {
97
+ const [key, value] = part.split("=");
98
+ typeof value !== "undefined" && (queries[key] = value);
99
+ });
100
+ link.search = Object.keys(queries).map((key) => `${key}=${queries[key]}`).join("&");
101
+ window.open(link.href, title, `width=${width},height=${height}`);
102
+ return "";
103
+ };
104
+ function chatPopupPlugin(container) {
105
+ container.getAsync("contactMethods").then((platform) => {
106
+ platform.create({
107
+ clientName: "chat.popup",
108
+ render: "email.form",
109
+ handleClick: (contactMethod) => {
110
+ const { title, body } = contactMethod;
111
+ const _a = body, { form, guideId, confirmationFallback } = _a, rest = __objRest(_a, ["form", "guideId", "confirmationFallback"]);
112
+ if (!form) {
113
+ return (e) => {
114
+ e.preventDefault();
115
+ popup(title, rest);
116
+ };
117
+ }
118
+ return () => {
119
+ };
120
+ },
121
+ onValidate: (contactMethod) => validate(container, contactMethod),
122
+ onComplete: (contactMethod) => complete(container, contactMethod),
123
+ onSubmit: (contactMethod) => {
124
+ const { title, body } = contactMethod;
125
+ const _a = body, { form, guideId, confirmationFallback } = _a, rest = __objRest(_a, ["form", "guideId", "confirmationFallback"]);
126
+ const formValues = new FormReader(form).export().values;
127
+ popup(title, rest, formValues);
128
+ return confirmationFallback;
129
+ }
130
+ });
131
+ });
132
+ }
133
+ function freeTextPlugin(container) {
134
+ container.getAsync("contactMethods").then((platform) => {
135
+ platform.create({
136
+ clientName: "custom.freetext",
137
+ render: import("./free-text-component.js")
138
+ });
139
+ });
140
+ }
141
+ function linkPlugin(container) {
142
+ container.getAsync("contactMethods").then((platform) => {
143
+ platform.create({
144
+ clientName: "custom.link",
145
+ render: import("./link-component.js")
146
+ });
147
+ });
148
+ }
149
+ function phonePlugin(container) {
150
+ container.getAsync("contactMethods").then((platform) => {
151
+ platform.create({
152
+ clientName: "phone.text",
153
+ render: import("./phone-component.js")
154
+ });
155
+ });
156
+ }
157
+ const handleContactMethod = (adapters, contactMethod) => __async(this, null, function* () {
158
+ const adapter = adapters.get(contactMethod.clientName);
159
+ let { description, disabled, onClick } = contactMethod;
160
+ if (adapter) {
161
+ const { handleClick, handleDescription, handleDisabled } = adapter;
162
+ if (typeof handleClick === "function") {
163
+ onClick = yield Promise.resolve(handleClick(contactMethod));
164
+ }
165
+ if (typeof handleDescription === "function") {
166
+ description = yield Promise.resolve(handleDescription(contactMethod));
167
+ }
168
+ if (typeof handleDisabled === "function") {
169
+ disabled = yield Promise.resolve(handleDisabled(contactMethod));
170
+ }
171
+ }
172
+ return Promise.resolve(__spreadProps(__spreadValues({}, contactMethod), {
173
+ description,
174
+ disabled,
175
+ onClick
176
+ }));
177
+ });
178
+ class ContactMethodPlatform {
179
+ constructor(container, componentPlatform) {
180
+ this.container = container;
181
+ this.componentPlatform = componentPlatform;
182
+ this.adapters = /* @__PURE__ */ new Map();
183
+ this.subs = [];
184
+ if (componentPlatform) {
185
+ const contactListComponent = componentPlatform.components().ofType("contact-list").select();
186
+ contactListComponent.actions.watch("contact-list.fetched", (input, next) => __async(this, null, function* () {
187
+ const { contactMethods } = input;
188
+ if (contactMethods) {
189
+ const promises = Promise.all(contactMethods.map((cm) => handleContactMethod(this.adapters, cm)));
190
+ yield Promise.resolve(promises).then((contactMethods2) => {
191
+ input.contactMethods = contactMethods2;
192
+ });
193
+ }
194
+ return next(input);
195
+ }));
196
+ const guideComponent = componentPlatform.components().ofType("guide").select();
197
+ guideComponent.actions.watch("guide.fetched", (input, next) => __async(this, null, function* () {
198
+ const { contactMethods } = input;
199
+ if (contactMethods) {
200
+ const promises = Promise.all(contactMethods.map((cm) => handleContactMethod(this.adapters, cm)));
201
+ yield Promise.resolve(promises).then((contactMethods2) => {
202
+ input.contactMethods = contactMethods2;
203
+ });
204
+ }
205
+ return next(input);
206
+ }));
207
+ guideComponent.actions.watch("guide.handover", (input, next) => __async(this, null, function* () {
208
+ const { handoverContactMethods } = input;
209
+ if (handoverContactMethods) {
210
+ const promises = Promise.all(handoverContactMethods.map((cm) => handleContactMethod(this.adapters, cm)));
211
+ yield Promise.resolve(promises).then((handoverContactMethods2) => {
212
+ input.handoverContactMethods = handoverContactMethods2;
213
+ });
214
+ }
215
+ return next(input);
216
+ }));
217
+ const contactMethodComponent = componentPlatform.components().ofType("contact-method").select();
218
+ contactMethodComponent.actions.watch("contact-method.fetched", (input, next) => __async(this, null, function* () {
219
+ const { contactMethod } = input;
220
+ if (contactMethod) {
221
+ return handleContactMethod(this.adapters, contactMethod).then((contactMethod2) => {
222
+ return next(__spreadProps(__spreadValues({}, input), { contactMethod: contactMethod2 }));
223
+ });
224
+ }
225
+ return next(input);
226
+ }));
227
+ }
228
+ }
229
+ static create(container) {
230
+ return ComponentPlatform.getInstance(container).then((platform) => {
231
+ return new ContactMethodPlatform(container, platform);
232
+ });
233
+ }
234
+ static getInstance(container, key = "contactMethods") {
235
+ return lock(container)(() => {
236
+ return container.getAsync(key).then((value) => {
237
+ let contactMethodPlatform = value;
238
+ if (!contactMethodPlatform) {
239
+ return ComponentPlatform.getInstance(container).then((components) => {
240
+ contactMethodPlatform = new ContactMethodPlatform(container, components);
241
+ container.registerAsync(key, () => contactMethodPlatform);
242
+ return contactMethodPlatform;
243
+ });
244
+ }
245
+ return contactMethodPlatform;
246
+ });
247
+ });
248
+ }
249
+ track(data = {}, type) {
250
+ const { events } = this.container.get("$widget");
251
+ events.dispatch("tracking:service-client-response", {
252
+ type,
253
+ data
254
+ });
255
+ }
256
+ complete(contactMethod) {
257
+ const { id, title, clientName, expanded, body } = contactMethod;
258
+ this.track({ contactMethod: { id, title, expanded, type: clientName }, hasGuide: !!body.guideId }, "contact-method-complete");
259
+ const adapter = this.adapters.get(clientName);
260
+ if (adapter && adapter.onComplete) {
261
+ return adapter.onComplete(contactMethod);
262
+ }
263
+ }
264
+ evaluate(contactMethod) {
265
+ const { clientName } = contactMethod;
266
+ const adapter = this.adapters.get(clientName);
267
+ if (adapter && adapter.onEvaluate) {
268
+ return Promise.resolve(adapter.onEvaluate(contactMethod));
269
+ }
270
+ return Promise.resolve(contactMethod.body.form);
271
+ }
272
+ validate(contactMethod) {
273
+ const { id, title, clientName } = contactMethod;
274
+ const adapter = this.adapters.get(clientName);
275
+ if (adapter && adapter.onValidate) {
276
+ return Promise.resolve(adapter.onValidate(contactMethod)).then((result) => {
277
+ this.track({ contactMethod: { id, title, type: clientName }, isValid: result.valid }, "contact-method-validate");
278
+ const { events } = this.container.get("$widget");
279
+ events.dispatch("form:validated", { isValid: result.valid });
280
+ return result;
281
+ });
282
+ }
283
+ return Promise.resolve({ valid: true });
284
+ }
285
+ submit(contactMethod) {
286
+ const { clientName } = contactMethod;
287
+ const adapter = this.adapters.get(clientName);
288
+ if (adapter && adapter.onSubmit) {
289
+ return Promise.resolve(adapter.onSubmit(contactMethod)).then((result) => {
290
+ this.complete(contactMethod);
291
+ return result;
292
+ });
293
+ }
294
+ return Promise.resolve("");
295
+ }
296
+ create(settings) {
297
+ const { clientName, render } = settings;
298
+ this.adapters.set(clientName, __spreadValues({
299
+ onValidate: (cm) => validate(this.container, cm),
300
+ onEvaluate: (cm) => evaluate(this.container, cm),
301
+ onComplete: (cm) => complete(this.container, cm)
302
+ }, settings));
303
+ return this.container.getAsync("componentResolver").then((resolver) => {
304
+ if (typeof render === "string") {
305
+ this.subs.push(resolver.registerAlias(clientName, render));
306
+ } else {
307
+ this.subs.push(resolver.registerComponent(clientName, lazy(() => render)));
308
+ }
309
+ });
310
+ }
311
+ dispose() {
312
+ this.subs.forEach((s) => s());
313
+ }
314
+ }
315
+ styled(Paragraph)`
316
+ ${headingElement("h1", css`
317
+ font-weight: normal;
318
+ font-size: ${(p) => {
319
+ var _a;
320
+ return (_a = p.theme.fonts) == null ? void 0 : _a.medium;
321
+ }};
322
+ `)}
323
+ `;
324
+ var Description = styled(Html)`
325
+ ${genericHtml}
326
+ font-weight: 300;
327
+ line-height: 1.5em;
328
+ button:focus {
329
+ ${(p) => {
330
+ var _a;
331
+ return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && borderTabStyle;
332
+ }};
333
+ }
334
+
335
+ a:focus {
336
+ ${(p) => {
337
+ var _a;
338
+ return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && linkTabStyle;
339
+ }};
340
+ }
341
+ `;
342
+ const ContactMethod = (props) => {
343
+ const ResolvedComponent = useComponent(props.clientName);
344
+ const {
345
+ params: { contactCategory, guideCategory, phrase }
346
+ } = useRouteData();
347
+ if (typeof ResolvedComponent === "undefined") {
348
+ return null;
349
+ }
350
+ if (ResolvedComponent === null) {
351
+ return null;
352
+ }
353
+ const renderLink = (extraProps = {}) => {
354
+ const enhancedProps = __spreadValues(__spreadValues({}, props), extraProps);
355
+ const {
356
+ id,
357
+ title,
358
+ clientName,
359
+ symbol,
360
+ inline,
361
+ onClick = () => {
362
+ },
363
+ description,
364
+ htmlParseInstruction,
365
+ className,
366
+ disabled,
367
+ guideId,
368
+ dispatch = () => {
369
+ },
370
+ expanded
371
+ } = enhancedProps;
372
+ const linkProps = inline ? {
373
+ onKeyDown: (event) => {
374
+ if (event.key && event.key === "Enter") {
375
+ onClick(event, enhancedProps);
376
+ if (!event.defaultPrevented) {
377
+ !expanded && dispatch("expand", id);
378
+ }
379
+ }
380
+ },
381
+ onClick: (event) => {
382
+ onClick(event, enhancedProps);
383
+ if (!event.defaultPrevented) {
384
+ !expanded && dispatch("expand", id);
385
+ }
386
+ }
387
+ } : {
388
+ onClick: (event) => onClick(event, enhancedProps),
389
+ routeName: "contact-method",
390
+ params: createParams({
391
+ contactCategory,
392
+ guideId,
393
+ guideCategory,
394
+ phrase,
395
+ contactMethod: id,
396
+ uriName: formatUrl(title)
397
+ })
398
+ };
399
+ return /* @__PURE__ */ React__default.createElement(StyledLink, __spreadValues(__spreadValues({
400
+ title,
401
+ "aria-label": title,
402
+ className,
403
+ disabled,
404
+ description,
405
+ "data-client-name": clientName
406
+ }, extraProps), linkProps), symbol && /* @__PURE__ */ React__default.createElement(SymbolBadge, {
407
+ symbol
408
+ }), description ? /* @__PURE__ */ React__default.createElement("div", {
409
+ className: "humany-contact-link-rich-content"
410
+ }, /* @__PURE__ */ React__default.createElement(StyledTitle, null, title), /* @__PURE__ */ React__default.createElement(Description, {
411
+ html: description,
412
+ htmlParseInstruction
413
+ })) : /* @__PURE__ */ React__default.createElement(StyledTitle, null, title));
414
+ };
415
+ return props.expanded ? /* @__PURE__ */ React__default.createElement(Suspense, {
416
+ fallback: null
417
+ }, /* @__PURE__ */ React__default.createElement(ResolvedComponent, __spreadProps(__spreadValues({}, props), {
418
+ renderDefault: renderLink
419
+ }))) : renderLink();
420
+ };
421
+ const contactLink = css`
422
+ display: flex;
423
+ padding: ${(p) => {
424
+ var _a;
425
+ return (_a = p.theme.sizes) == null ? void 0 : _a.large;
426
+ }};
427
+ ${(p) => !!p.description ? "" : "align-items: center;"}
428
+ text-decoration: none;
429
+ span {
430
+ display: inline-block;
431
+ color: ${(p) => {
432
+ var _a;
433
+ return (_a = p.theme.colors) == null ? void 0 : _a.text;
434
+ }};
435
+ }
436
+ i {
437
+ font-size: ${(p) => {
438
+ var _a;
439
+ return (_a = p.theme.fonts) == null ? void 0 : _a.large;
440
+ }};
441
+ margin: 0 ${(p) => {
442
+ var _a;
443
+ return (_a = p.theme.sizes) == null ? void 0 : _a.large;
444
+ }} 0 0;
445
+ min-height: ${(p) => {
446
+ var _a;
447
+ return (_a = p.theme.fonts) == null ? void 0 : _a.large;
448
+ }};
449
+ min-width: ${(p) => {
450
+ var _a;
451
+ return (_a = p.theme.fonts) == null ? void 0 : _a.large;
452
+ }};
453
+ line-height: ${(p) => {
454
+ var _a;
455
+ return (_a = p.theme.fonts) == null ? void 0 : _a.large;
456
+ }};
457
+ display: inline-block;
458
+ vertical-align: bottom;
459
+ color: ${(p) => {
460
+ var _a;
461
+ return (_a = p.theme.colors) == null ? void 0 : _a.text;
462
+ }};
463
+ }
464
+ `;
465
+ const StyledTitle = styled(StyledText)`
466
+ line-height: ${(p) => {
467
+ var _a;
468
+ return (_a = p.theme.fonts) == null ? void 0 : _a.large;
469
+ }};
470
+ `;
471
+ const StyledLink = styled(Link)`
472
+ ${contactLink}
473
+
474
+ &:focus {
475
+ ${(p) => {
476
+ var _a;
477
+ return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && borderTabStyle;
478
+ }};
479
+ }
480
+ `;
481
+ styled.div`
482
+ text-align: center;
483
+ display: block;
484
+ ${(p) => {
485
+ var _a, _b;
486
+ return typeof ((_a = p.theme.colors) == null ? void 0 : _a.warning) !== "undefined" && `color: ${(_b = p.theme.colors) == null ? void 0 : _b.warning};`;
487
+ }}
488
+ `;
489
+ const contactItemList = css`
490
+ ${itemList}
491
+
492
+ > div {
493
+ padding: ${(p) => {
494
+ var _a;
495
+ return (_a = p.theme.sizes) == null ? void 0 : _a.large;
496
+ }};
497
+
498
+ ${headingElement("h1", css`
499
+ margin: 0;
500
+ `)}
501
+ }
502
+ > ul {
503
+ &:not(:first-child) {
504
+ border-top: ${(p) => p.theme.border};
505
+ }
506
+
507
+ > li {
508
+ margin: 0;
509
+ white-space: normal;
510
+
511
+ > a {
512
+ overflow: hidden;
513
+ }
514
+
515
+ &:first-child > a {
516
+ border-radius: ${(p) => `${p.theme.borderRadius} ${p.theme.borderRadius} 0 0`};
517
+ }
518
+
519
+ &:last-child:not(:first-child) > a {
520
+ border-radius: ${(p) => `0 0 ${p.theme.borderRadius} ${p.theme.borderRadius}`};
521
+ }
522
+
523
+ &:not(:last-child) {
524
+ border-bottom: ${(p) => p.theme.border};
525
+ }
526
+
527
+ > div {
528
+ padding: ${(p) => {
529
+ var _a;
530
+ return (_a = p.theme.sizes) == null ? void 0 : _a.large;
531
+ }};
532
+ }
533
+ }
534
+ }
535
+
536
+ @media (hover: hover) {
537
+ a:hover {
538
+ background-color: ${(p) => {
539
+ var _a;
540
+ return (_a = p.theme.colors) == null ? void 0 : _a.accent;
541
+ }};
542
+ }
543
+ }
544
+ `;
545
+ const StyledItemList = styled(ItemList)`
546
+ ${contactItemList}
547
+ `;
548
+ const ContactList = ({
549
+ contactMethods,
550
+ children,
551
+ guideId,
552
+ dispatch,
553
+ className = "",
554
+ action = () => {
555
+ },
556
+ header = ""
557
+ }) => {
558
+ if (!contactMethods.length) {
559
+ return null;
560
+ }
561
+ return /* @__PURE__ */ React__default.createElement(StyledItemList, {
562
+ header,
563
+ className: appendClassNames(className, "humany-contact-list"),
564
+ items: contactMethods,
565
+ renderItem: (cm) => /* @__PURE__ */ React__default.createElement("li", {
566
+ key: cm.id,
567
+ "data-contact-method": cm.id
568
+ }, /* @__PURE__ */ React__default.createElement(ContactMethod, __spreadProps(__spreadValues({}, cm), {
569
+ action,
570
+ dispatch,
571
+ guideId
572
+ })))
573
+ }, children);
574
+ };
575
+ const lookupComponent = (node, id) => {
576
+ if (node.actionKey === id) {
577
+ return node;
578
+ }
579
+ if (!node.properties) {
580
+ return null;
581
+ }
582
+ const keys = Object.keys(node.properties);
583
+ let result;
584
+ for (let i = 0; i < keys.length; i++) {
585
+ result = lookupComponent(node.properties[keys[i]], id);
586
+ if (result) {
587
+ return result;
588
+ }
589
+ }
590
+ return false;
591
+ };
592
+ const Form = ({
593
+ className,
594
+ body: { form },
595
+ id,
596
+ action,
597
+ dispatch,
598
+ disabled,
599
+ autoFocus
600
+ }) => {
601
+ if (form && !disabled) {
602
+ const { schema, layout, data } = form;
603
+ const trigger = dispatch || action || (() => {
604
+ });
605
+ return /* @__PURE__ */ React__default.createElement(FormComponent, {
606
+ className,
607
+ schema,
608
+ layout,
609
+ data,
610
+ autoFocus,
611
+ onChange: (event, data2) => {
612
+ const form2 = { schema, layout, data: data2 };
613
+ if (event.toString() === "submit") {
614
+ trigger("submit", { id, form: form2 });
615
+ } else {
616
+ const formComponent = lookupComponent(schema, event);
617
+ if (formComponent.evaluate) {
618
+ trigger("evaluate", { id, form: form2 });
619
+ } else {
620
+ trigger("validate", { id, form: form2 });
621
+ }
622
+ }
623
+ }
624
+ });
625
+ }
626
+ return null;
627
+ };
628
+ const useContactMethod = (clientName) => {
629
+ const [component, setComponent] = useState(null);
630
+ const container = useContainer();
631
+ useEffect(() => {
632
+ let unsubscribe;
633
+ container.getAsync("componentResolver").then((resolver) => {
634
+ unsubscribe = resolver.registerResolver(clientName, (component2) => setComponent(component2));
635
+ });
636
+ return () => {
637
+ if (unsubscribe) {
638
+ unsubscribe();
639
+ }
640
+ };
641
+ }, [clientName]);
642
+ return component;
643
+ };
644
+ function webServicePlugin(container) {
645
+ container.getAsync("contactMethods").then((platform) => {
646
+ platform.create({
647
+ clientName: "custom.webservice",
648
+ render: "email.form",
649
+ onValidate: (contactMethod) => validate(container, contactMethod),
650
+ onComplete: (contactMethod) => complete(container, contactMethod),
651
+ onSubmit: (contactMethod) => submit(container, contactMethod, (response) => {
652
+ return __spreadProps(__spreadValues({}, response), {
653
+ ConfirmationText: response.ResponseHtml
654
+ });
655
+ })
656
+ });
657
+ });
658
+ }
659
+ const createSubmitAdapter = (container, clientName, fn) => {
660
+ return container.getAsync("contactMethods").then((platform) => {
661
+ platform.create({
662
+ clientName,
663
+ render: "email.form",
664
+ handleClick: () => {
665
+ return (e, cm) => {
666
+ const {
667
+ body: _a
668
+ } = cm, _b = _a, { form, guideId, confirmationFallback } = _b, rest = __objRest(_b, ["form", "guideId", "confirmationFallback"]);
669
+ if (!form) {
670
+ e.preventDefault();
671
+ fn(rest);
672
+ }
673
+ };
674
+ },
675
+ onValidate: (cm) => validate(container, cm),
676
+ onComplete: (cm) => complete(container, cm),
677
+ onSubmit: (cm) => {
678
+ const {
679
+ body: _a
680
+ } = cm, _b = _a, { form, guideId, confirmationFallback } = _b, rest = __objRest(_b, ["form", "guideId", "confirmationFallback"]);
681
+ const { values } = new FormReader(form).export();
682
+ return Promise.resolve(fn(rest, values)).then((confirmation) => {
683
+ return confirmation || confirmationFallback;
684
+ });
685
+ }
686
+ });
687
+ });
688
+ };
689
+ class DefaultContactMethodsPlugin extends Plugin {
690
+ constructor(container, settings) {
691
+ super(container, settings);
692
+ const implementation = this.widget.implementation;
693
+ implementation.configure((config) => {
694
+ config.plugin(emailPlugin).plugin(chatPopupPlugin).plugin(freeTextPlugin).plugin(phonePlugin).plugin(webServicePlugin).plugin(linkPlugin);
695
+ });
696
+ }
697
+ }
698
+ export { ContactList as C, Description as D, Form as F, contactItemList as a, contactLink as b, chatPopupPlugin as c, ContactMethod as d, ContactMethodPlatform as e, complete as f, evaluate as g, emailPlugin as h, freeTextPlugin as i, createSubmitAdapter as j, DefaultContactMethodsPlugin as k, linkPlugin as l, phonePlugin as p, submit as s, useContactMethod as u, validate as v, webServicePlugin as w };
699
+ //# sourceMappingURL=index2.js.map