@telia-ace/knowledge-widget-types-grid 1.0.21 → 1.0.25

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.
package/dist/index.js CHANGED
@@ -1,173 +1,114 @@
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]);
1
+ var j = Object.defineProperty, Y = Object.defineProperties;
2
+ var z = Object.getOwnPropertyDescriptors;
3
+ var P = Object.getOwnPropertySymbols;
4
+ var J = Object.prototype.hasOwnProperty, X = Object.prototype.propertyIsEnumerable;
5
+ var H = (i, e, t) => e in i ? j(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, F = (i, e) => {
6
+ for (var t in e || (e = {}))
7
+ J.call(e, t) && H(i, t, e[t]);
8
+ if (P)
9
+ for (var t of P(e))
10
+ X.call(e, t) && H(i, t, e[t]);
11
+ return i;
12
+ }, Q = (i, e) => Y(i, z(e));
13
+ var E = (i, e, t) => new Promise((n, s) => {
14
+ var a = (d) => {
15
+ try {
16
+ o(t.next(d));
17
+ } catch (h) {
18
+ s(h);
16
19
  }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __async = (__this, __arguments, generator) => {
21
- return new Promise((resolve, reject) => {
22
- var fulfilled = (value) => {
23
- try {
24
- step(generator.next(value));
25
- } catch (e) {
26
- reject(e);
27
- }
28
- };
29
- var rejected = (value) => {
30
- try {
31
- step(generator.throw(value));
32
- } catch (e) {
33
- reject(e);
34
- }
35
- };
36
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
- step((generator = generator.apply(__this, __arguments)).next());
38
- });
39
- };
40
- import { Widget } from "@telia-ace/widget-types-grid";
41
- export { Component, DetachedComponent, NotFound, genericComponentStyling } from "@telia-ace/widget-types-grid";
42
- import { DialogItemType, WidgetRenderState } from "@telia-ace/knowledge-widget-core";
43
- import { removeNullAndUndefinedValues, shallowCompare, deepClone } from "@telia-ace/widget-utilities";
44
- import { FormBuilder } from "@telia-ace/widget-forms";
45
- const convertLegacySymbol = (symbol) => {
46
- if (symbol) {
47
- const { Type, Content } = symbol;
48
- if (Type && Content) {
49
- return { type: Type, content: Content };
20
+ }, c = (d) => {
21
+ try {
22
+ o(t.throw(d));
23
+ } catch (h) {
24
+ s(h);
50
25
  }
26
+ }, o = (d) => d.done ? n(d.value) : Promise.resolve(d.value).then(a, c);
27
+ o((t = t.apply(i, e)).next());
28
+ });
29
+ import { Widget as Z } from "@telia-ace/widget-types-grid";
30
+ import { Component as Ct, DetachedComponent as bt, NotFound as yt, genericComponentStyling as Nt } from "@telia-ace/widget-types-grid";
31
+ import { DialogItemType as R, WidgetRenderState as O } from "@telia-ace/knowledge-widget-core";
32
+ import { removeNullAndUndefinedValues as tt, shallowCompare as S, deepClone as et } from "@telia-ace/widget-utilities";
33
+ import { FormBuilder as _ } from "@telia-ace/widget-forms";
34
+ const v = (i) => {
35
+ if (i) {
36
+ const { Type: e, Content: t } = i;
37
+ if (e && t)
38
+ return { type: e, content: t };
51
39
  }
52
- };
53
- const mapLegacyCategoriesRecursively = (categories) => {
54
- return categories.map((c) => {
55
- const category = {
56
- id: c.Id.toString(),
57
- title: c.Name,
58
- symbol: convertLegacySymbol(c.DefaultIcon),
59
- activeSymbol: c.ActiveIcon && convertLegacySymbol(c.ActiveIcon),
60
- description: c.Description || c.Attributes && c.Attributes.description || "",
61
- matches: c.GuidesCount
62
- };
63
- if (c.Children && c.Children.length) {
64
- category.items = mapLegacyCategoriesRecursively(c.Children);
65
- }
66
- return category;
67
- });
68
- };
69
- const mapNotices = (source, type) => {
70
- return source.filter(({ Type }) => Type === type).map(({ Id, Title, Body }) => ({
71
- id: Id.toString(),
72
- title: Title,
73
- body: Body
74
- }));
75
- };
76
- const mapNotificationLists = (source) => {
77
- return source.map(({ Id, Title, DefaultIcon, ListNotices, Notices }) => ({
78
- id: Id.toString(),
79
- title: Title,
80
- symbol: convertLegacySymbol(DefaultIcon),
81
- defaultHeaderOptions: {
82
- visible: !!ListNotices.length
83
- },
84
- notifications: (ListNotices || []).concat(Notices || []).map(({ Id: Id2, Title: Title2, Body, Type, Modified }) => ({
85
- id: Id2.toString(),
86
- title: Title2,
87
- body: Body,
88
- modified: Modified,
89
- expandable: Type === "listNotice"
90
- }))
91
- }));
92
- };
93
- const mapContactMethodSettings = ({
94
- Id,
95
- Title,
96
- DefaultIcon,
97
- Exits: [Exit],
98
- ExitType,
99
- ConfirmationText,
100
- ExpandFormAutomatically,
101
- Form,
102
- Description
103
- }, Validation) => {
104
- const { Adapter } = Exit || { Adapter: {} };
105
- const { ClientName = "", Settings = {}, CustomClientName = "" } = Adapter;
106
- const settings = {
107
- id: Id.toString(),
108
- title: Title,
109
- description: Description,
110
- symbol: convertLegacySymbol(DefaultIcon),
111
- clientName: ClientName === "custom.adapter" ? CustomClientName : ClientName,
112
- expanded: true,
113
- inline: true,
40
+ }, D = (i) => i.map((e) => {
41
+ const t = {
42
+ id: e.Id.toString(),
43
+ title: e.Name,
44
+ symbol: v(e.DefaultIcon),
45
+ activeSymbol: e.ActiveIcon && v(e.ActiveIcon),
46
+ description: e.Description || e.Attributes && e.Attributes.description || "",
47
+ matches: e.GuidesCount
48
+ };
49
+ return e.Children && e.Children.length && (t.items = D(e.Children)), t;
50
+ }), y = (i, e) => i.filter(({ Type: t }) => t === e).map(({ Id: t, Title: n, Body: s }) => ({
51
+ id: t.toString(),
52
+ title: n,
53
+ body: s
54
+ })), G = (i) => i.map(({ Id: e, Title: t, DefaultIcon: n, ListNotices: s, Notices: a }) => ({
55
+ id: e.toString(),
56
+ title: t,
57
+ symbol: v(n),
58
+ defaultHeaderOptions: {
59
+ visible: !!s.length
60
+ },
61
+ notifications: (s || []).concat(a || []).map(({ Id: c, Title: o, Body: d, Type: h, Modified: f }) => ({
62
+ id: c.toString(),
63
+ title: o,
64
+ body: d,
65
+ modified: f,
66
+ expandable: h === "listNotice"
67
+ }))
68
+ })), q = ({
69
+ Id: i,
70
+ Title: e,
71
+ DefaultIcon: t,
72
+ Exits: [n],
73
+ ExitType: s,
74
+ ConfirmationText: a,
75
+ ExpandFormAutomatically: c,
76
+ Form: o,
77
+ Description: d
78
+ }, h) => {
79
+ const { Adapter: f } = n || { Adapter: {} }, { ClientName: g = "", Settings: C = {}, CustomClientName: I = "" } = f, u = {
80
+ id: i.toString(),
81
+ title: e,
82
+ description: d,
83
+ symbol: v(t),
84
+ clientName: g === "custom.adapter" ? I : g,
85
+ expanded: !0,
86
+ inline: !0,
114
87
  body: {}
115
88
  };
116
- if (ClientName.indexOf("phone") > -1 || ClientName.indexOf("freetext") > -1) {
117
- const { displayTextBeforeClick, textBeforeClick } = Settings;
118
- if (displayTextBeforeClick === "true") {
119
- settings.expanded = false;
120
- settings.title = textBeforeClick;
121
- }
122
- if (ClientName.indexOf("phone.text") > -1) {
123
- settings.body.phoneNumber = Settings.phoneNumber;
124
- } else {
125
- settings.body.freetext = Settings.freetext;
126
- }
127
- }
128
- if (ClientName.indexOf("chat.popup") > -1 || ClientName.indexOf("link") > -1 || ClientName === "custom.adapter" && ExitType === "custom") {
129
- settings.body = Settings;
130
- settings.body.confirmationFallback = ConfirmationText;
131
- }
132
- if (ClientName.indexOf("ace") > -1) {
133
- settings.body = Settings;
134
- }
135
- if (Form && Form.HasValueComponents) {
136
- if (Validation) {
137
- settings.body.form = FormBuilder.fromLegacyForm(Id.toString(), Form, Validation).get();
138
- } else {
139
- settings.body.form = FormBuilder.fromLegacyForm(Id.toString(), Form).get();
140
- }
141
- if (!ExpandFormAutomatically) {
142
- settings.expanded = settings.inline = false;
143
- }
89
+ if (g.indexOf("phone") > -1 || g.indexOf("freetext") > -1) {
90
+ const { displayTextBeforeClick: m, textBeforeClick: r } = C;
91
+ m === "true" && (u.expanded = !1, u.title = r), g.indexOf("phone.text") > -1 ? u.body.phoneNumber = C.phoneNumber : u.body.freetext = C.freetext;
144
92
  }
145
- return settings;
146
- };
147
- const mapTags = (tags = []) => {
148
- return tags.map(({ Id, Title, TotalMatches, Symbol: Symbol2, DefaultIcon, ActiveIcon }) => ({
149
- id: Id.toString(),
150
- title: Title,
151
- matches: TotalMatches,
152
- symbol: convertLegacySymbol(DefaultIcon || Symbol2),
153
- defaultIcon: convertLegacySymbol(DefaultIcon),
154
- activeIcon: convertLegacySymbol(ActiveIcon)
155
- }));
156
- };
157
- const mapGuides = (guides) => {
158
- return guides.map(({ Id, Title, Tags, FirstPublishedDate, Modified }) => ({
159
- id: Id.toString(),
160
- title: Title,
161
- tags: mapTags(Tags),
162
- published: FirstPublishedDate,
163
- modified: Modified
164
- }));
165
- };
166
- const formatLegacyData = (type, data) => {
167
- switch (type) {
168
- case ServiceClientQueryType.MatchByCategory:
169
- case ServiceClientQueryType.Match: {
170
- const result = {
93
+ return (g.indexOf("chat.popup") > -1 || g.indexOf("link") > -1 || g === "custom.adapter" && s === "custom") && (u.body = C, u.body.confirmationFallback = a), g.indexOf("ace") > -1 && (u.body = C), o && o.HasValueComponents && (h ? u.body.form = _.fromLegacyForm(i.toString(), o, h).get() : u.body.form = _.fromLegacyForm(i.toString(), o).get(), c || (u.expanded = u.inline = !1)), u;
94
+ }, A = (i = []) => i.map(({ Id: e, Title: t, TotalMatches: n, Symbol: s, DefaultIcon: a, ActiveIcon: c }) => ({
95
+ id: e.toString(),
96
+ title: t,
97
+ matches: n,
98
+ symbol: v(a || s),
99
+ defaultIcon: v(a),
100
+ activeIcon: v(c)
101
+ })), L = (i) => i.map(({ Id: e, Title: t, Tags: n, FirstPublishedDate: s, Modified: a }) => ({
102
+ id: e.toString(),
103
+ title: t,
104
+ tags: A(n),
105
+ published: s,
106
+ modified: a
107
+ })), it = (i, e) => {
108
+ switch (i) {
109
+ case p.MatchByCategory:
110
+ case p.Match: {
111
+ const t = {
171
112
  guides: [],
172
113
  matches: 0,
173
114
  topNotifications: [],
@@ -176,196 +117,133 @@ const formatLegacyData = (type, data) => {
176
117
  notificationLists: [],
177
118
  tags: [],
178
119
  byCategory: []
179
- };
180
- const {
181
- Matches,
182
- TotalMatches,
183
- Notices,
184
- NoticeLists,
185
- Tags,
186
- ByCategory
187
- } = data;
188
- result.guides = mapGuides(Matches);
189
- result.matches = TotalMatches;
190
- result.byCategory = (ByCategory || []).map(({ Id, Matches: Matches2, TotalMatches: TotalMatches2 }) => ({
191
- id: Id,
192
- guides: mapGuides(Matches2),
193
- matches: TotalMatches2
194
- }));
195
- result.tags = mapTags(Tags);
196
- result.notificationLists = mapNotificationLists(NoticeLists || []);
197
- result.topNotifications = mapNotices(Notices || [], "noticeRowTop");
198
- result.middleNotifications = mapNotices(Notices || [], "noticeRowMiddle");
199
- result.bottomNotifications = mapNotices(Notices || [], "footerNotice");
200
- return result;
120
+ }, {
121
+ Matches: n,
122
+ TotalMatches: s,
123
+ Notices: a,
124
+ NoticeLists: c,
125
+ Tags: o,
126
+ ByCategory: d
127
+ } = e;
128
+ return t.guides = L(n), t.matches = s, t.byCategory = (d || []).map(({ Id: h, Matches: f, TotalMatches: g }) => ({
129
+ id: h,
130
+ guides: L(f),
131
+ matches: g
132
+ })), t.tags = A(o), t.notificationLists = G(c || []), t.topNotifications = y(a || [], "noticeRowTop"), t.middleNotifications = y(a || [], "noticeRowMiddle"), t.bottomNotifications = y(a || [], "footerNotice"), t;
201
133
  }
202
- case ServiceClientQueryType.Categories: {
203
- const { Children, GuidesCountTotal } = data;
204
- const result = {
205
- categories: mapLegacyCategoriesRecursively(Children || []),
206
- matches: GuidesCountTotal
134
+ case p.Categories: {
135
+ const { Children: t, GuidesCountTotal: n } = e;
136
+ return {
137
+ categories: D(t || []),
138
+ matches: n
207
139
  };
208
- return result;
209
140
  }
210
- case ServiceClientQueryType.Guide: {
141
+ case p.Guide: {
211
142
  const {
212
- Id,
213
- Title,
214
- Body,
215
- Related,
216
- Options,
217
- ConnectionId,
218
- ContactMethods,
219
- EnableFeedback,
220
- HandoverExists,
221
- FirstPublishedDate,
222
- Modified,
223
- ModifiedByDisplayName,
224
- FirstPublishedByDisplayName,
225
- Categories,
226
- Tags,
227
- SeoMetaDescription,
228
- SeoAllowIndex,
229
- Perspectives,
230
- PerspectiveKey,
231
- Translations
232
- } = data;
233
- const perspective = PerspectiveKey || Object.values(Perspectives).find((connection) => connection === ConnectionId) || Perspectives["Default"] || null;
234
- const result = {
143
+ Id: t,
144
+ Title: n,
145
+ Body: s,
146
+ Related: a,
147
+ Options: c,
148
+ ConnectionId: o,
149
+ ContactMethods: d,
150
+ EnableFeedback: h,
151
+ HandoverExists: f,
152
+ FirstPublishedDate: g,
153
+ Modified: C,
154
+ ModifiedByDisplayName: I,
155
+ FirstPublishedByDisplayName: u,
156
+ Categories: m,
157
+ Tags: r,
158
+ SeoMetaDescription: l,
159
+ SeoAllowIndex: k,
160
+ Perspectives: w,
161
+ PerspectiveKey: B,
162
+ Translations: T
163
+ } = e, $ = B || Object.values(w).find((N) => N === o) || w.Default || null, U = {
235
164
  guide: {
236
- id: Id.toString(),
237
- title: Title,
238
- body: Body,
239
- modified: Modified,
240
- published: FirstPublishedDate,
241
- modifiedBy: ModifiedByDisplayName,
242
- publishedBy: FirstPublishedByDisplayName,
243
- connection: ConnectionId,
244
- categories: Categories,
245
- hasHandover: HandoverExists,
246
- allowFeedback: EnableFeedback,
247
- seoMetaDescription: SeoMetaDescription,
248
- seoAllowIndex: SeoAllowIndex,
249
- perspectives: Perspectives,
250
- perspective,
251
- translations: Object.keys(Translations || {}).reduce((acc, key) => {
252
- acc[key] = Translations[key].toString();
253
- return acc;
254
- }, {})
165
+ id: t.toString(),
166
+ title: n,
167
+ body: s,
168
+ modified: C,
169
+ published: g,
170
+ modifiedBy: I,
171
+ publishedBy: u,
172
+ connection: o,
173
+ categories: m,
174
+ hasHandover: f,
175
+ allowFeedback: h,
176
+ seoMetaDescription: l,
177
+ seoAllowIndex: k,
178
+ perspectives: w,
179
+ perspective: $,
180
+ translations: Object.keys(T || {}).reduce((N, x) => (N[x] = T[x].toString(), N), {})
255
181
  },
256
- related: mapGuides(Related || []),
182
+ related: L(a || []),
257
183
  dialog: [],
258
- contactMethods: (ContactMethods || []).map((cm) => mapContactMethodSettings(cm)),
259
- tags: mapTags(Tags)
184
+ contactMethods: (d || []).map((N) => q(N)),
185
+ tags: A(r)
260
186
  };
261
- (Options || []).forEach(({ CanAccess, Description, ConnectionId: ConnectionId2, Properties }) => {
262
- if (!CanAccess) {
187
+ return (c || []).forEach(({ CanAccess: N, Description: x, ConnectionId: V, Properties: b }) => {
188
+ if (!N)
263
189
  return;
264
- }
265
- const item = {
266
- id: Id.toString(),
267
- title: Description,
268
- connection: ConnectionId2,
269
- type: DialogItemType.default,
190
+ const M = {
191
+ id: t.toString(),
192
+ title: x,
193
+ connection: V,
194
+ type: R.default,
270
195
  parent: {
271
- id: Id.toString(),
272
- title: Title,
273
- tags: mapTags(Tags)
196
+ id: t.toString(),
197
+ title: n,
198
+ tags: A(r)
274
199
  }
275
200
  };
276
- if (Properties.Type === "Guide" || Properties.Type === "Link") {
277
- Properties.Id && (item.id = Properties.Id.toString());
278
- Properties.Uri && (item.href = Properties.Uri);
279
- Properties.Target && (item.target = Properties.Target);
280
- switch (Properties.Type) {
201
+ if (b.Type === "Guide" || b.Type === "Link")
202
+ switch (b.Id && (M.id = b.Id.toString()), b.Uri && (M.href = b.Uri), b.Target && (M.target = b.Target), b.Type) {
281
203
  case "Guide":
282
- item.type = DialogItemType.guide;
204
+ M.type = R.guide;
283
205
  break;
284
206
  case "Link":
285
- item.type = DialogItemType.link;
207
+ M.type = R.link;
286
208
  break;
287
209
  }
288
- }
289
- result.dialog.push(item);
290
- });
291
- return result;
210
+ U.dialog.push(M);
211
+ }), U;
292
212
  }
293
- case ServiceClientQueryType.Contacts: {
294
- const { Children, Matches, Notices, NoticeLists } = data;
295
- const result = {
296
- contactMethods: (Matches || []).map((cm) => mapContactMethodSettings(cm)),
297
- categories: mapLegacyCategoriesRecursively(Children || []),
298
- topNotifications: mapNotices(Notices || [], "noticeRowTop"),
299
- middleNotifications: mapNotices(Notices || [], "noticeRowMiddle"),
300
- bottomNotifications: mapNotices(Notices || [], "footerNotice"),
301
- notificationLists: mapNotificationLists(NoticeLists || [])
213
+ case p.Contacts: {
214
+ const { Children: t, Matches: n, Notices: s, NoticeLists: a } = e;
215
+ return {
216
+ contactMethods: (n || []).map((o) => q(o)),
217
+ categories: D(t || []),
218
+ topNotifications: y(s || [], "noticeRowTop"),
219
+ middleNotifications: y(s || [], "noticeRowMiddle"),
220
+ bottomNotifications: y(s || [], "footerNotice"),
221
+ notificationLists: G(a || [])
302
222
  };
303
- return result;
304
- }
305
- case ServiceClientQueryType.ContactMethod: {
306
- const { ContactMethod: ContactMethod2 } = data;
307
- return mapContactMethodSettings(ContactMethod2 || {});
308
223
  }
309
- case ServiceClientQueryType.Tags:
310
- case ServiceClientQueryType.TagsOnGuides: {
311
- return mapTags(data || []);
224
+ case p.ContactMethod: {
225
+ const { ContactMethod: t } = e;
226
+ return q(t || {});
312
227
  }
313
- case ServiceClientQueryType.Notifications: {
314
- const { Notices, NoticeLists } = data;
228
+ case p.Tags:
229
+ case p.TagsOnGuides:
230
+ return A(e || []);
231
+ case p.Notifications: {
232
+ const { Notices: t, NoticeLists: n } = e;
315
233
  return {
316
- topNotifications: mapNotices(Notices || [], "noticeRowTop"),
317
- middleNotifications: mapNotices(Notices || [], "noticeRowMiddle"),
318
- bottomNotifications: mapNotices(Notices || [], "footerNotice"),
319
- notificationLists: mapNotificationLists(NoticeLists || [])
234
+ topNotifications: y(t || [], "noticeRowTop"),
235
+ middleNotifications: y(t || [], "noticeRowMiddle"),
236
+ bottomNotifications: y(t || [], "footerNotice"),
237
+ notificationLists: G(n || [])
320
238
  };
321
239
  }
322
240
  default:
323
241
  return {};
324
242
  }
325
243
  };
326
- var DataType = /* @__PURE__ */ ((DataType2) => {
327
- DataType2["Guide"] = "guide";
328
- DataType2["Guides"] = "guides";
329
- DataType2["GuidesByCategory"] = "guides-by-category";
330
- DataType2["RowNotifications"] = "row-notices";
331
- DataType2["NotificationLists"] = "notification-lists";
332
- DataType2["GuideCategories"] = "guide-categories";
333
- DataType2["ContactMethodCategories"] = "contact-method-categories";
334
- DataType2["ContactMethod"] = "contact-method";
335
- DataType2["ContactMethods"] = "contact-methods";
336
- DataType2["Tags"] = "tags";
337
- DataType2["TagsOnGuides"] = "tagsonguides";
338
- return DataType2;
339
- })(DataType || {});
340
- var ServiceClientQueryType = /* @__PURE__ */ ((ServiceClientQueryType2) => {
341
- ServiceClientQueryType2["Match"] = "match";
342
- ServiceClientQueryType2["Categories"] = "categories";
343
- ServiceClientQueryType2["Guide"] = "guide";
344
- ServiceClientQueryType2["Contacts"] = "contacts";
345
- ServiceClientQueryType2["ContactMethod"] = "contact-method";
346
- ServiceClientQueryType2["MatchByCategory"] = "match-by-category";
347
- ServiceClientQueryType2["Tags"] = "tags";
348
- ServiceClientQueryType2["TagsOnGuides"] = "tagsonguides";
349
- ServiceClientQueryType2["Notifications"] = "notifications";
350
- return ServiceClientQueryType2;
351
- })(ServiceClientQueryType || {});
352
- var FeedbackType = /* @__PURE__ */ ((FeedbackType2) => {
353
- FeedbackType2["Positive"] = "Positive";
354
- FeedbackType2["Negative"] = "Negative";
355
- return FeedbackType2;
356
- })(FeedbackType || {});
357
- var SortingType = /* @__PURE__ */ ((SortingType2) => {
358
- SortingType2["POPULARITY_DESCENDING"] = "popularity-descending";
359
- SortingType2["ALPHABETIC_ASCENDING"] = "alphabetic-ascending";
360
- SortingType2["ALPHABETIC_DESCENDING"] = "alphabetic-descending";
361
- SortingType2["MODIFIED_ASCENDING"] = "modified-ascending";
362
- SortingType2["MODIFIED_DESCENDING"] = "modified-descending";
363
- SortingType2["PUBLISHED_ASCENDING"] = "published-ascending";
364
- SortingType2["PUBLISHED_DESCENDING"] = "published-descending";
365
- return SortingType2;
366
- })(SortingType || {});
367
- const determineServiceClientQueryType = (type) => {
368
- switch (type) {
244
+ var st = /* @__PURE__ */ ((i) => (i.Guide = "guide", i.Guides = "guides", i.GuidesByCategory = "guides-by-category", i.RowNotifications = "row-notices", i.NotificationLists = "notification-lists", i.GuideCategories = "guide-categories", i.ContactMethodCategories = "contact-method-categories", i.ContactMethod = "contact-method", i.ContactMethods = "contact-methods", i.Tags = "tags", i.TagsOnGuides = "tagsonguides", i))(st || {}), p = /* @__PURE__ */ ((i) => (i.Match = "match", i.Categories = "categories", i.Guide = "guide", i.Contacts = "contacts", i.ContactMethod = "contact-method", i.MatchByCategory = "match-by-category", i.Tags = "tags", i.TagsOnGuides = "tagsonguides", i.Notifications = "notifications", i))(p || {}), nt = /* @__PURE__ */ ((i) => (i.Positive = "Positive", i.Negative = "Negative", i))(nt || {}), ot = /* @__PURE__ */ ((i) => (i.POPULARITY_DESCENDING = "popularity-descending", i.ALPHABETIC_ASCENDING = "alphabetic-ascending", i.ALPHABETIC_DESCENDING = "alphabetic-descending", i.MODIFIED_ASCENDING = "modified-ascending", i.MODIFIED_DESCENDING = "modified-descending", i.PUBLISHED_ASCENDING = "published-ascending", i.PUBLISHED_DESCENDING = "published-descending", i))(ot || {});
245
+ const W = (i) => {
246
+ switch (i) {
369
247
  case "guides":
370
248
  return "match";
371
249
  case "guides-by-category":
@@ -389,298 +267,211 @@ const determineServiceClientQueryType = (type) => {
389
267
  default:
390
268
  throw "error";
391
269
  }
392
- };
393
- const widgetIsHidden = (container) => __async(this, null, function* () {
394
- const { invoke } = container.get("$widget");
395
- const renderState = yield invoke("renderState");
396
- return renderState === WidgetRenderState.hidden;
270
+ }, at = (i) => E(void 0, null, function* () {
271
+ const { invoke: e } = i.get("$widget");
272
+ return (yield e("renderState")) === O.hidden;
397
273
  });
398
- class DataClient {
399
- constructor(container, matchingClient) {
400
- this.container = container;
401
- this.matchingClient = matchingClient;
402
- this.queries = /* @__PURE__ */ new Map();
403
- this.lastTake = 0;
404
- this.getUnresolvedQueries = () => {
405
- let unresolvedCount = 0;
406
- this.queries.forEach((queries, type) => {
407
- const hasUnresolved = queries.some((query) => !query.resolved);
408
- if (hasUnresolved) {
409
- unresolvedCount = 1;
410
- }
411
- });
412
- return unresolvedCount;
413
- };
414
- this.events = container.get("$widget").events;
415
- this.events.subscribe("widget:settings-updated", () => this.queries = /* @__PURE__ */ new Map());
416
- this.events.subscribe("widget:render-state-changed", (event, { next, previous }) => {
417
- if (previous === WidgetRenderState.hidden && next === WidgetRenderState.open) {
418
- this.fetchAllUnresolvedQueries();
419
- }
274
+ class K {
275
+ constructor(e, t) {
276
+ this.container = e, this.matchingClient = t, this.queries = /* @__PURE__ */ new Map(), this.lastTake = 0, this.getUnresolvedQueries = () => {
277
+ let n = 0;
278
+ return this.queries.forEach((s, a) => {
279
+ s.some((o) => !o.resolved) && (n = 1);
280
+ }), n;
281
+ }, this.events = e.get("$widget").events, this.events.subscribe("widget:settings-updated", () => this.queries = /* @__PURE__ */ new Map()), this.events.subscribe("widget:render-state-changed", (n, { next: s, previous: a }) => {
282
+ a === O.hidden && s === O.open && this.fetchAllUnresolvedQueries();
420
283
  });
421
284
  }
422
- static getInstance(container) {
423
- return container.getAsync("dataClient");
285
+ static getInstance(e) {
286
+ return e.getAsync("dataClient");
424
287
  }
425
- fetch(type, params) {
426
- return new Promise((resolve, reject) => {
427
- if (params.take) {
428
- this.lastTake = +(params.take || 0);
429
- }
430
- removeNullAndUndefinedValues(params);
431
- const serviceClientQueryType = determineServiceClientQueryType(type);
432
- const queries = this.queries.get(serviceClientQueryType) || [];
433
- const query = queries.find((q) => shallowCompare(q.params, params));
434
- if (query) {
435
- const index = queries.indexOf(query);
436
- if (query.resolved) {
437
- this.events.dispatch("data-client:fetched", {
438
- params,
439
- type: serviceClientQueryType,
440
- response: query.data,
441
- unresolvedQueries: this.getUnresolvedQueries()
442
- });
443
- this.track(query.data, serviceClientQueryType, query.error);
444
- if (query.data && query.error) {
445
- reject({ error: query.error });
446
- } else {
447
- resolve(query.data);
448
- }
449
- } else {
450
- query.resolvers.push({ resolve, reject });
451
- }
452
- queries.splice(index, 1);
453
- queries.push(query);
454
- this.queries.set(serviceClientQueryType, queries);
455
- if (!query.loading && !query.resolved) {
456
- return this.runQuery(serviceClientQueryType, params);
457
- }
458
- } else {
459
- queries.push({
460
- params,
461
- resolved: false,
462
- loading: true,
288
+ fetch(e, t) {
289
+ return new Promise((n, s) => {
290
+ t.take && (this.lastTake = +(t.take || 0)), tt(t);
291
+ const a = W(e), c = this.queries.get(a) || [], o = c.find((d) => S(d.params, t));
292
+ if (o) {
293
+ const d = c.indexOf(o);
294
+ if (o.resolved ? (this.events.dispatch("data-client:fetched", {
295
+ params: t,
296
+ type: a,
297
+ response: o.data,
298
+ unresolvedQueries: this.getUnresolvedQueries()
299
+ }), this.track(o.data, a, o.error), o.data && o.error ? s({ error: o.error }) : n(o.data)) : o.resolvers.push({ resolve: n, reject: s }), c.splice(d, 1), c.push(o), this.queries.set(a, c), !o.loading && !o.resolved)
300
+ return this.runQuery(a, t);
301
+ } else
302
+ return c.push({
303
+ params: t,
304
+ resolved: !1,
305
+ loading: !0,
463
306
  data: {},
464
- resolvers: [{ resolve, reject }]
465
- });
466
- this.queries.set(serviceClientQueryType, queries);
467
- return this.runQuery(serviceClientQueryType, params);
468
- }
469
- }).then((res) => deepClone(res));
307
+ resolvers: [{ resolve: n, reject: s }]
308
+ }), this.queries.set(a, c), this.runQuery(a, t);
309
+ }).then((n) => et(n));
470
310
  }
471
- read(type, options) {
472
- const { select } = options;
473
- const serviceClientQueryType = determineServiceClientQueryType(type);
474
- const queries = this.queries.get(serviceClientQueryType) || [];
475
- const result = queries.reduce((acc, query) => {
476
- if (typeof select === "function") {
477
- const match = select(query.data);
478
- if (match) {
479
- acc.push(match);
480
- }
481
- } else {
482
- acc.push(query.data);
483
- }
484
- return acc;
311
+ read(e, t) {
312
+ const { select: n } = t, s = W(e);
313
+ return (this.queries.get(s) || []).reduce((o, d) => {
314
+ if (typeof n == "function") {
315
+ const h = n(d.data);
316
+ h && o.push(h);
317
+ } else
318
+ o.push(d.data);
319
+ return o;
485
320
  }, []);
486
- return result;
487
321
  }
488
- feedback(id, connection, feedback) {
489
- return this.matchingClient.giveFeedback(id, connection, feedback);
322
+ feedback(e, t, n) {
323
+ return this.matchingClient.giveFeedback(e, t, n);
490
324
  }
491
- setLoadingStatus(type, params, loading) {
492
- const queries = this.queries.get(type) || [];
493
- const query = queries.find((q) => shallowCompare(q.params, params));
494
- if (query) {
495
- query.loading = loading;
496
- }
497
- this.queries.set(type, queries);
325
+ setLoadingStatus(e, t, n) {
326
+ const s = this.queries.get(e) || [], a = s.find((c) => S(c.params, t));
327
+ a && (a.loading = n), this.queries.set(e, s);
498
328
  }
499
- runQuery(type, params) {
500
- return __async(this, null, function* () {
329
+ runQuery(e, t) {
330
+ return E(this, null, function* () {
501
331
  const {
502
- searchPhrase = "",
503
- categories = "0",
504
- contactMethodCategoryId = "0",
505
- contactMethodId = "0",
506
- tagId = void 0,
507
- take = 5,
508
- connection = "",
509
- guideId,
510
- expandCategories = "descendants",
511
- currentCategory,
512
- sorting = "popularity-descending",
513
- guideIds = []
514
- } = params;
515
- const trimmedPhrase = searchPhrase.toString().trim();
516
- if (yield widgetIsHidden(this.container)) {
332
+ searchPhrase: n = "",
333
+ categories: s = "0",
334
+ contactMethodCategoryId: a = "0",
335
+ contactMethodId: c = "0",
336
+ tagId: o = void 0,
337
+ take: d = 5,
338
+ connection: h = "",
339
+ guideId: f,
340
+ expandCategories: g = "descendants",
341
+ currentCategory: C,
342
+ sorting: I = "popularity-descending",
343
+ guideIds: u = []
344
+ } = t, m = n.toString().trim();
345
+ if (yield at(this.container))
517
346
  return Promise.resolve();
518
- }
519
- switch (type) {
347
+ switch (e) {
520
348
  case "match": {
521
- const formatSortingValues = (sorting2) => {
522
- const [type2, direction] = sorting2.split("-");
523
- const sortKeysMap = /* @__PURE__ */ new Map([
524
- ["popularity", "popularity"],
525
- ["alphabetic", "title"],
526
- ["modified", "lastModified"],
527
- ["published", "firstPublished"]
528
- ]);
349
+ const r = (l) => {
350
+ const [k, w] = l.split("-");
529
351
  return {
530
- type: sortKeysMap.get(type2),
531
- direction
352
+ type: (/* @__PURE__ */ new Map([
353
+ ["popularity", "popularity"],
354
+ ["alphabetic", "title"],
355
+ ["modified", "lastModified"],
356
+ ["published", "firstPublished"]
357
+ ])).get(k),
358
+ direction: w
532
359
  };
533
360
  };
534
- if (guideIds.length) {
535
- return this.matchingClient.customRequest("guides", "POST", {
536
- configuration: { ids: guideIds, take: +take }
537
- }).then((matches) => matches && this.handleResponse(matches, type, params));
538
- }
539
- return this.matchingClient.match(trimmedPhrase, {
540
- categories: categories === "0" ? [] : Array.isArray(categories) ? categories : [+categories],
541
- take: +take,
542
- tags: tagId,
543
- sorting: formatSortingValues(sorting),
544
- ids: guideIds
545
- }).then((matches) => matches && this.handleResponse(matches, type, params));
546
- }
547
- case "match-by-category": {
548
- return this.matchingClient.match(trimmedPhrase, {
549
- groupByCategory: true,
550
- categories: categories === "0" ? [] : Array.isArray(categories) ? categories : [+categories],
551
- take: +take,
552
- tags: tagId
553
- }).then((matches) => matches && this.handleResponse(matches, type, params));
361
+ return u.length ? this.matchingClient.customRequest("guides", "POST", {
362
+ configuration: { ids: u, take: +d }
363
+ }).then((l) => l && this.handleResponse(l, e, t)) : this.matchingClient.match(m, {
364
+ categories: s === "0" ? [] : Array.isArray(s) ? s : [+s],
365
+ take: +d,
366
+ tags: o,
367
+ sorting: r(I),
368
+ ids: u
369
+ }).then((l) => l && this.handleResponse(l, e, t));
554
370
  }
555
- case "guide": {
556
- return this.matchingClient.getGuide(guideId, { connectionId: connection }).then((guide) => {
557
- if (guide) {
558
- this.handleResponse(guide, type, params);
559
- }
560
- }).catch((e) => {
561
- const error = {
371
+ case "match-by-category":
372
+ return this.matchingClient.match(m, {
373
+ groupByCategory: !0,
374
+ categories: s === "0" ? [] : Array.isArray(s) ? s : [+s],
375
+ take: +d,
376
+ tags: o
377
+ }).then((r) => r && this.handleResponse(r, e, t));
378
+ case "guide":
379
+ return this.matchingClient.getGuide(f, { connectionId: h }).then((r) => {
380
+ r && this.handleResponse(r, e, t);
381
+ }).catch((r) => {
382
+ const l = {
562
383
  message: "Something went wrong.",
563
- status: e.status || 400
384
+ status: r.status || 400
564
385
  };
565
- if (error.status === 404) {
566
- error.message = "The guide could not be found.";
567
- }
568
- this.handleResponse({}, type, params, error);
386
+ l.status === 404 && (l.message = "The guide could not be found."), this.handleResponse({}, e, t, l);
569
387
  });
570
- }
571
- case "categories": {
572
- return this.matchingClient.getCategories({ phrase: trimmedPhrase, expand: expandCategories, tags: tagId }).then((categories2) => categories2 && this.handleResponse(categories2, type, params));
573
- }
574
- case "contacts": {
575
- if (guideId) {
576
- return this.matchingClient.contactMethods(+guideId, { phrase: trimmedPhrase }).then((result) => result && this.handleResponse(result, type, params));
577
- }
578
- return this.matchingClient.contacts(+contactMethodCategoryId, { phrase: trimmedPhrase }).then((result) => result && this.handleResponse(result, type, params));
579
- }
580
- case "contact-method": {
581
- return this.matchingClient.getContactMethod(+contactMethodId, { guideId, currentCategory }).then((result) => result && this.handleResponse(result, type, params));
582
- }
583
- case "tags": {
388
+ case "categories":
389
+ return this.matchingClient.getCategories({ phrase: m, expand: g, tags: o }).then((r) => r && this.handleResponse(r, e, t));
390
+ case "contacts":
391
+ return f ? this.matchingClient.contactMethods(+f, { phrase: m }).then((r) => r && this.handleResponse(r, e, t)) : this.matchingClient.contacts(+a, { phrase: m }).then((r) => r && this.handleResponse(r, e, t));
392
+ case "contact-method":
393
+ return this.matchingClient.getContactMethod(+c, { guideId: f, currentCategory: C }).then((r) => r && this.handleResponse(r, e, t));
394
+ case "tags":
584
395
  return this.matchingClient.customRequest("tags", "GET", {
585
396
  configuration: {
586
397
  take: 999999,
587
- phrase: trimmedPhrase,
588
- categories: categories === "0" ? [] : Array.isArray(categories) ? categories : [+categories]
398
+ phrase: m,
399
+ categories: s === "0" ? [] : Array.isArray(s) ? s : [+s]
589
400
  }
590
- }).then((result) => result && this.handleResponse(result, type, params));
591
- }
592
- case "tagsonguides": {
401
+ }).then((r) => r && this.handleResponse(r, e, t));
402
+ case "tagsonguides":
593
403
  return this.matchingClient.customRequest("tagsonguides", "GET", {
594
404
  configuration: {
595
405
  take: 999999,
596
- phrase: trimmedPhrase,
597
- categories: categories === "0" ? [] : Array.isArray(categories) ? categories : [+categories],
598
- tags: tagId
406
+ phrase: m,
407
+ categories: s === "0" ? [] : Array.isArray(s) ? s : [+s],
408
+ tags: o
599
409
  }
600
- }).then((result) => result && this.handleResponse(result, type, params));
601
- }
602
- case "notifications": {
410
+ }).then((r) => r && this.handleResponse(r, e, t));
411
+ case "notifications":
603
412
  return this.matchingClient.customRequest("notices", "GET", {
604
413
  configuration: {
605
- phrase: trimmedPhrase,
606
- categories: categories === "0" ? [] : Array.isArray(categories) ? categories : [+categories]
414
+ phrase: m,
415
+ categories: s === "0" ? [] : Array.isArray(s) ? s : [+s]
607
416
  }
608
- }).then((result) => result && this.handleResponse(result, type, params));
609
- }
417
+ }).then((r) => r && this.handleResponse(r, e, t));
610
418
  }
611
419
  });
612
420
  }
613
- handleResponse(data = {}, type, params, error) {
614
- const queries = this.queries.get(type) || [];
615
- const existing = queries.find((q) => shallowCompare(q.params, params));
616
- if (existing) {
617
- const formatted = error ? error : formatLegacyData(type, data);
618
- this.track(formatted, type, error);
619
- existing.resolvers.forEach((r) => {
620
- if (error) {
621
- r.reject({ error: formatted });
622
- } else {
623
- r.resolve(formatted);
624
- }
421
+ handleResponse(e = {}, t, n, s) {
422
+ const a = this.queries.get(t) || [], c = a.find((o) => S(o.params, n));
423
+ if (c) {
424
+ const o = s || it(t, e);
425
+ this.track(o, t, s), c.resolvers.forEach((h) => {
426
+ s ? h.reject({ error: o }) : h.resolve(o);
427
+ });
428
+ const d = a.indexOf(c);
429
+ d > -1 && a.splice(d, 1), a.push(Q(F({}, c), { error: s, resolvers: [], data: o, resolved: !0 })), this.setLoadingStatus(t, n, !1), this.queries.set(t, a), s || this.events.dispatch("data-client:fetched", {
430
+ type: t,
431
+ params: n,
432
+ response: o,
433
+ unresolvedQueries: this.getUnresolvedQueries()
625
434
  });
626
- const index = queries.indexOf(existing);
627
- if (index > -1) {
628
- queries.splice(index, 1);
629
- }
630
- queries.push(__spreadProps(__spreadValues({}, existing), { error, resolvers: [], data: formatted, resolved: true }));
631
- this.setLoadingStatus(type, params, false);
632
- this.queries.set(type, queries);
633
- if (!error) {
634
- this.events.dispatch("data-client:fetched", {
635
- type,
636
- params,
637
- response: formatted,
638
- unresolvedQueries: this.getUnresolvedQueries()
639
- });
640
- }
641
435
  }
642
436
  }
643
437
  fetchAllUnresolvedQueries() {
644
- for (const [queryType, queries] of this.queries) {
645
- queries.filter((query) => !query.resolved).forEach((query) => {
646
- this.runQuery(queryType, query.params);
438
+ for (const [e, t] of this.queries)
439
+ t.filter((n) => !n.resolved).forEach((n) => {
440
+ this.runQuery(e, n.params);
647
441
  });
648
- }
649
442
  }
650
- track(data = {}, type, error) {
651
- const widget = this.container.get("$widget");
652
- if (widget && !error) {
653
- widget.events.dispatch("tracking:service-client-response", {
654
- type,
655
- data
656
- });
657
- } else if (widget) {
658
- widget.events.dispatch("tracking:service-client-error", {
659
- type,
660
- error
661
- });
662
- }
443
+ track(e = {}, t, n) {
444
+ const s = this.container.get("$widget");
445
+ s && !n ? s.events.dispatch("tracking:service-client-response", {
446
+ type: t,
447
+ data: e
448
+ }) : s && s.events.dispatch("tracking:service-client-error", {
449
+ type: t,
450
+ error: n
451
+ });
663
452
  }
664
- static create(container) {
665
- return container.getAsync("matchingClient").then((matchingClient) => new DataClient(container, matchingClient));
453
+ static create(e) {
454
+ return e.getAsync("matchingClient").then((t) => new K(e, t));
666
455
  }
667
456
  }
668
- const createContactMethodPlatform = (container) => {
669
- return import("@telia-ace/knowledge-widget-adapters").then(({ ContactMethodPlatform }) => {
670
- return ContactMethodPlatform.create(container);
671
- });
672
- };
673
- const createDataClient = (container) => {
674
- return import("./index2.js").then(({ DataClient: DataClient2 }) => {
675
- return DataClient2.create(container);
676
- });
677
- };
678
- class ExtendedWidget extends Widget {
679
- constructor(container) {
680
- super(container);
681
- this.container.registerAsync("contactMethods", () => createContactMethodPlatform(this.container));
682
- this.container.registerAsync("dataClient", () => createDataClient(this.container));
457
+ const rt = (i) => import("@telia-ace/knowledge-widget-adapters").then(({ ContactMethodPlatform: e }) => e.create(i)), ct = (i) => import("./index.a2cdbc37.js").then(({ DataClient: e }) => e.create(i));
458
+ class ft extends Z {
459
+ constructor(e) {
460
+ super(e), this.container.registerAsync("contactMethods", () => rt(this.container)), this.container.registerAsync("dataClient", () => ct(this.container));
683
461
  }
684
462
  }
685
- export { DataClient, DataType, FeedbackType, ExtendedWidget as GridWidget, ServiceClientQueryType, SortingType, determineServiceClientQueryType, formatLegacyData };
463
+ export {
464
+ Ct as Component,
465
+ K as DataClient,
466
+ st as DataType,
467
+ bt as DetachedComponent,
468
+ nt as FeedbackType,
469
+ ft as GridWidget,
470
+ yt as NotFound,
471
+ p as ServiceClientQueryType,
472
+ ot as SortingType,
473
+ W as determineServiceClientQueryType,
474
+ it as formatLegacyData,
475
+ Nt as genericComponentStyling
476
+ };
686
477
  //# sourceMappingURL=index.js.map