@telia-ace/knowledge-widget-components-contact-list 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),m=require("@emotion/styled"),q=require("@telia-ace/knowledge-widget-adapters"),e=require("@telia-ace/knowledge-widget-ui"),a=require("@telia-ace/widget-utilities"),D=require("@telia-ace/widget-types-grid"),k=require("react"),w=({className:n,guides:s,header:L,accordion:c,loading:g,route:S="guide",categoryTitle:x,...l})=>{const{name:p,params:{contactCategory:I=0,guide:C}}=e.useRouteData(),{name:r}=e.useComponentDescriptor(),$=e.useContainer(),f=e.useChildren(),b=e.useDispatch(),N=k.useCallback((o,i,y,u)=>{const{id:h,title:j}=o;return c&&C===h?t.jsx(e.AccordionListItem,{id:h,title:j,route:p,collapseUri:x&&a.formatUrl(x),children:f.map(d=>t.jsx(D.Component,{id:d.id,branch:"default",accordion:c},d.id))},h):u?u(o,i,y,u):null},[c,f,C]);return!s.length&&!g?e.createEmptyComponent($,{...l,className:a.appendClassNames(n,"humany-deflection-list")}):t.jsx(T,{...l,"data-loading":g,className:a.appendClassNames(n,"humany-deflection-list"),items:s,header:L,expandable:!!c,renderItem:N,dispatch:b,routing:{guide:S},paramMappers:{guide:({id:o,title:i})=>a.createParams({contactCategory:I,guide:o,accordion:c?r:void 0,uriName:a.formatUrl(i)})},children:t.jsx(e.Loader,{loading:g})})},T=m(e.GuideList)`
2
+ ${e.contentBox}
3
+ ${e.loadingOpacity}
4
+ `,U=m(q.ContactList)`
5
+ ${e.loadingOpacity}
6
+ ${e.contentBox}
7
+ `,B=m(e.ItemList)`
8
+ ${n=>e.loadingOpacity(n)}
9
+ ${e.contentBox}
10
+ ${q.contactItemList}
11
+
12
+ && {
13
+ i {
14
+ font-size: 25px;
15
+ width: 1.28571429em;
16
+ text-align: center;
17
+ }
18
+ }
19
+ `,v=m(e.Link)`
20
+ &:focus-visible {
21
+ ${e.borderTabStyle};
22
+ }
23
+
24
+ ${q.contactLink}
25
+ `,G=m.div`
26
+ display: flex;
27
+ flex-direction: column;
28
+ gap: ${n=>{var s;return(s=n.theme.sizes)==null?void 0:s.normal}};
29
+ `,O=m(e.StyledText)`
30
+ font-weight: bold;
31
+ `,P=({className:n,...s})=>{const L=e.useDispatch(),c=e.useContainer(),g=e.useRouteData(),{deflectionHeader:S="",routes:x={},contactMethods:l=[],categories:p=[],guides:I=[],deflectionAccordion:C=!1,loading:r=!1}=e.useProperties(),{contactCategory:$,guide:f="guide"}=x;if(!p.length&&!l.length&&!r)return e.createEmptyComponent(c,{...s,className:a.appendClassNames(n,"humany-contact-category-list")});const{name:b,params:{contactCategory:N}}=g,o=a.findCategoryById(N,p);return l.length?t.jsxs(t.Fragment,{children:[t.jsx(w,{className:n,guides:I,categoryTitle:o&&o.title,header:S,route:f,accordion:C,loading:r}),t.jsx(U,{"data-loading":r,className:n,contactMethods:l,dispatch:L,children:t.jsx(e.Loader,{loading:r})})]}):t.jsx(B,{...s,"data-loading":r,className:a.appendClassNames(n,"humany-contact-category-list"),items:o&&o.items||p,renderItem:({id:i,title:y,symbol:u,matches:h,items:j,description:d})=>h||j&&j.length?t.jsx("li",{"data-contact-category":i,children:t.jsxs(v,{routeName:$||b,params:a.createParams({contactCategory:i,uriName:a.formatUrl(y)}),children:[u&&t.jsx(e.SymbolBadge,{symbol:u}),d!=null&&d.length?t.jsxs(G,{children:[t.jsx(O,{children:y}),t.jsx(e.StyledText,{children:d})]}):t.jsx(e.StyledText,{children:y})]})},i):null,children:t.jsx(e.Loader,{loading:r})})};exports.default=P;
@@ -0,0 +1,190 @@
1
+ import { jsx as t, jsxs as D, Fragment as P } from "react/jsx-runtime";
2
+ import d from "@emotion/styled";
3
+ import { ContactList as T, contactItemList as U, contactLink as E } from "@telia-ace/knowledge-widget-adapters";
4
+ import { GuideList as F, contentBox as G, loadingOpacity as j, useRouteData as w, useComponentDescriptor as O, useContainer as z, useChildren as R, useDispatch as A, AccordionListItem as q, createEmptyComponent as H, Loader as k, ItemList as J, Link as K, borderTabStyle as Q, StyledText as v, useProperties as V, SymbolBadge as W } from "@telia-ace/knowledge-widget-ui";
5
+ import { formatUrl as B, appendClassNames as L, createParams as M, findCategoryById as X } from "@telia-ace/widget-utilities";
6
+ import { Component as Y } from "@telia-ace/widget-types-grid";
7
+ import { useCallback as Z } from "react";
8
+ const _ = ({
9
+ className: e,
10
+ guides: o,
11
+ header: $,
12
+ accordion: r,
13
+ loading: m,
14
+ route: x = "guide",
15
+ categoryTitle: p,
16
+ ...s
17
+ }) => {
18
+ const {
19
+ name: u,
20
+ params: { contactCategory: I = 0, guide: y }
21
+ } = w(), { name: a } = O(), b = z(), f = R(), S = A(), N = Z(
22
+ (n, c, g, l) => {
23
+ const { id: h, title: C } = n;
24
+ return r && y === h ? /* @__PURE__ */ t(
25
+ q,
26
+ {
27
+ id: h,
28
+ title: C,
29
+ route: u,
30
+ collapseUri: p && B(p),
31
+ children: f.map((i) => /* @__PURE__ */ t(
32
+ Y,
33
+ {
34
+ id: i.id,
35
+ branch: "default",
36
+ accordion: r
37
+ },
38
+ i.id
39
+ ))
40
+ },
41
+ h
42
+ ) : l ? l(n, c, g, l) : null;
43
+ },
44
+ // eslint-disable-next-line react-hooks/exhaustive-deps
45
+ [r, f, y]
46
+ );
47
+ return !o.length && !m ? H(b, {
48
+ ...s,
49
+ className: L(e, "humany-deflection-list")
50
+ }) : /* @__PURE__ */ t(
51
+ tt,
52
+ {
53
+ ...s,
54
+ "data-loading": m,
55
+ className: L(e, "humany-deflection-list"),
56
+ items: o,
57
+ header: $,
58
+ expandable: !!r,
59
+ renderItem: N,
60
+ dispatch: S,
61
+ routing: {
62
+ guide: x
63
+ },
64
+ paramMappers: {
65
+ guide: ({ id: n, title: c }) => M({
66
+ contactCategory: I,
67
+ guide: n,
68
+ accordion: r ? a : void 0,
69
+ uriName: B(c)
70
+ })
71
+ },
72
+ children: /* @__PURE__ */ t(k, { loading: m })
73
+ }
74
+ );
75
+ }, tt = d(F)`
76
+ ${G}
77
+ ${j}
78
+ `, et = d(T)`
79
+ ${j}
80
+ ${G}
81
+ `, nt = d(J)`
82
+ ${(e) => j(e)}
83
+ ${G}
84
+ ${U}
85
+
86
+ && {
87
+ i {
88
+ font-size: 25px;
89
+ width: 1.28571429em;
90
+ text-align: center;
91
+ }
92
+ }
93
+ `, ot = d(K)`
94
+ &:focus-visible {
95
+ ${Q};
96
+ }
97
+
98
+ ${E}
99
+ `, at = d.div`
100
+ display: flex;
101
+ flex-direction: column;
102
+ gap: ${(e) => {
103
+ var o;
104
+ return (o = e.theme.sizes) == null ? void 0 : o.normal;
105
+ }};
106
+ `, rt = d(v)`
107
+ font-weight: bold;
108
+ `, gt = ({ className: e, ...o }) => {
109
+ const $ = A(), r = z(), m = w(), {
110
+ deflectionHeader: x = "",
111
+ routes: p = {},
112
+ contactMethods: s = [],
113
+ categories: u = [],
114
+ guides: I = [],
115
+ deflectionAccordion: y = !1,
116
+ loading: a = !1
117
+ } = V(), { contactCategory: b, guide: f = "guide" } = p;
118
+ if (!u.length && !s.length && !a)
119
+ return H(r, {
120
+ ...o,
121
+ className: L(e, "humany-contact-category-list")
122
+ });
123
+ const {
124
+ name: S,
125
+ params: { contactCategory: N }
126
+ } = m, n = X(
127
+ N,
128
+ u
129
+ );
130
+ return s.length ? /* @__PURE__ */ D(P, { children: [
131
+ /* @__PURE__ */ t(
132
+ _,
133
+ {
134
+ className: e,
135
+ guides: I,
136
+ categoryTitle: n && n.title,
137
+ header: x,
138
+ route: f,
139
+ accordion: y,
140
+ loading: a
141
+ }
142
+ ),
143
+ /* @__PURE__ */ t(
144
+ et,
145
+ {
146
+ "data-loading": a,
147
+ className: e,
148
+ contactMethods: s,
149
+ dispatch: $,
150
+ children: /* @__PURE__ */ t(k, { loading: a })
151
+ }
152
+ )
153
+ ] }) : /* @__PURE__ */ t(
154
+ nt,
155
+ {
156
+ ...o,
157
+ "data-loading": a,
158
+ className: L(e, "humany-contact-category-list"),
159
+ items: n && n.items || u,
160
+ renderItem: ({
161
+ id: c,
162
+ title: g,
163
+ symbol: l,
164
+ matches: h,
165
+ items: C,
166
+ description: i
167
+ }) => h || C && C.length ? /* @__PURE__ */ t("li", { "data-contact-category": c, children: /* @__PURE__ */ D(
168
+ ot,
169
+ {
170
+ routeName: b || S,
171
+ params: M({
172
+ contactCategory: c,
173
+ uriName: B(g)
174
+ }),
175
+ children: [
176
+ l && /* @__PURE__ */ t(W, { symbol: l }),
177
+ i != null && i.length ? /* @__PURE__ */ D(at, { children: [
178
+ /* @__PURE__ */ t(rt, { children: g }),
179
+ /* @__PURE__ */ t(v, { children: i })
180
+ ] }) : /* @__PURE__ */ t(v, { children: g })
181
+ ]
182
+ }
183
+ ) }, c) : null,
184
+ children: /* @__PURE__ */ t(k, { loading: a })
185
+ }
186
+ );
187
+ };
188
+ export {
189
+ gt as default
190
+ };
@@ -0,0 +1,23 @@
1
+ import { ContactMethodType } from '../../../knowledge/adapters/src/index.ts';
2
+ import { Category, Guide } from '../../../knowledge/core/src/index.ts';
3
+ import { FormComponentInstanceProperties } from '../../../forms/src/index.ts';
4
+ import { Container } from '@webprovisions/platform';
5
+
6
+ export type ContactListComponentProps = {
7
+ deflectionHeader?: string;
8
+ deflectionHeaderTag?: string;
9
+ deflection?: {
10
+ [contactCategoryId: string]: string[];
11
+ };
12
+ deflectionPageSize?: number;
13
+ routes?: {
14
+ contactCategory?: string;
15
+ guide?: string;
16
+ };
17
+ categories?: Category[];
18
+ contactMethods?: ContactMethodType[];
19
+ guides?: Guide[];
20
+ deflectionAccordion?: boolean;
21
+ } & FormComponentInstanceProperties;
22
+ export declare const ContactListComponent: (container: Container) => Promise<void>;
23
+ export default ContactListComponent;
@@ -0,0 +1,7 @@
1
+ import { default as React } from 'react';
2
+
3
+ type Props = {
4
+ className: string;
5
+ };
6
+ declare const ContactList: React.FC<Props>;
7
+ export default ContactList;
@@ -0,0 +1,14 @@
1
+ import { Guide } from '../../../knowledge/core/src/index.ts';
2
+ import { default as React } from 'react';
3
+
4
+ type Props = {
5
+ className: string;
6
+ guides: Guide[];
7
+ header: string;
8
+ accordion?: boolean;
9
+ route?: string;
10
+ loading: boolean;
11
+ categoryTitle?: string;
12
+ };
13
+ declare const DeflectionList: React.FC<Props>;
14
+ export default DeflectionList;
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { default as ContactListComponent } from './contact-list-component';
2
+
3
+ export default ContactListComponent;
package/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";const h=require("@telia-ace/knowledge-data-client"),a=require("@telia-ace/knowledge-widget-component-utilities"),y=require("@telia-ace/knowledge-widget-core"),q=require("@telia-ace/knowledge-widget-ui"),M=s=>{const{events:m}=s.get("$widget"),[P,k]=y.createEventSubscriber(m);return q.createReactComponent(s,"contact-list",Promise.resolve().then(()=>require("./contact-list-05301ab8.js")),e=>{const i=t=>{e.writeProperties({loading:!0,contactMethods:[],categories:[]}),e.actions.dispatch("fetch",{params:t})};e.actions.create("fetch",t=>{const{submitButtonLabel:r="Submit",deflectionHeaderTag:o=void 0}=e.properties();o!==void 0&&(window.humany.deflectionHeaderTag=o);const d=(t.contactMethods||[]).map(c=>({...c,body:a.updateForm(c,{submit:r})}));return e.actions.dispatch("fetched",{...t,contactMethods:d,loading:!0})}),e.actions.create("fetched",t=>e.writeProperties({...t,guides:t.guides||[],loading:!1})),s.getAsync("router").then(t=>{const{params:r}=t.getRouteData();i(r)}),P("router:changed",(t,{current:r})=>{i(r.routeData.params)}),a.useForm(s,e),a.useExpand(e)}).then(()=>y.extendComponent(s,"contact-list",e=>{e.actions.watch("contact-list.fetch",(i,t)=>{const{deflection:r={},deflectionPageSize:o=5,deflectionAccordion:d}=e.properties(),{params:c={}}=i,{contactCategory:u,guide:l,accordion:v}=c;return h.DataClient.getInstance(s).then(g=>g.fetch(h.DataType.ContactMethodCategories,{contactMethodCategoryId:u}).then(({contactMethods:f,categories:b})=>{var p;const w=Object.keys(r),C=w.length===1&&!u?w[0]:u;return(p=r[C])!=null&&p.length?g.fetch(h.DataType.Guides,{categories:r[C],take:o}).then(n=>d&&l&&v===e.node.name?a.fetchAccordionGuideIfMissing(n,g,{guide:l}):new Promise(D=>D(n))).then(({guides:n})=>t({guides:n,contactMethods:f,categories:b})):t({contactMethods:f,categories:b})}))})})).then(()=>{k()})};module.exports=M;
package/index.mjs ADDED
@@ -0,0 +1,83 @@
1
+ import { DataClient as M, DataType as b } from "@telia-ace/knowledge-data-client";
2
+ import { updateForm as D, useForm as A, useExpand as I, fetchAccordionGuideIfMissing as S } from "@telia-ace/knowledge-widget-component-utilities";
3
+ import { createEventSubscriber as T, extendComponent as k } from "@telia-ace/knowledge-widget-core";
4
+ import { createReactComponent as x } from "@telia-ace/knowledge-widget-ui";
5
+ const L = (o) => {
6
+ const { events: y } = o.get("$widget"), [C, w] = T(y);
7
+ return x(
8
+ o,
9
+ "contact-list",
10
+ import("./contact-list-300090b9.mjs"),
11
+ (t) => {
12
+ const c = (e) => {
13
+ t.writeProperties({
14
+ loading: !0,
15
+ contactMethods: [],
16
+ categories: []
17
+ }), t.actions.dispatch("fetch", { params: e });
18
+ };
19
+ t.actions.create("fetch", (e) => {
20
+ const {
21
+ submitButtonLabel: r = "Submit",
22
+ deflectionHeaderTag: s = void 0
23
+ } = t.properties();
24
+ s !== void 0 && (window.humany.deflectionHeaderTag = s);
25
+ const n = (e.contactMethods || []).map(
26
+ (a) => ({
27
+ ...a,
28
+ body: D(a, { submit: r })
29
+ })
30
+ );
31
+ return t.actions.dispatch("fetched", {
32
+ ...e,
33
+ contactMethods: n,
34
+ loading: !0
35
+ });
36
+ }), t.actions.create("fetched", (e) => t.writeProperties({
37
+ ...e,
38
+ guides: e.guides || [],
39
+ loading: !1
40
+ })), o.getAsync("router").then((e) => {
41
+ const { params: r } = e.getRouteData();
42
+ c(r);
43
+ }), C("router:changed", (e, { current: r }) => {
44
+ c(r.routeData.params);
45
+ }), A(o, t), I(t);
46
+ }
47
+ ).then(() => k(o, "contact-list", (t) => {
48
+ t.actions.watch("contact-list.fetch", (c, e) => {
49
+ const {
50
+ deflection: r = {},
51
+ deflectionPageSize: s = 5,
52
+ deflectionAccordion: n
53
+ } = t.properties(), { params: a = {} } = c, {
54
+ contactCategory: d,
55
+ guide: h,
56
+ accordion: P
57
+ } = a;
58
+ return M.getInstance(o).then(
59
+ (u) => u.fetch(b.ContactMethodCategories, {
60
+ contactMethodCategoryId: d
61
+ }).then(({ contactMethods: f, categories: g }) => {
62
+ var p;
63
+ const l = Object.keys(r), m = l.length === 1 && !d ? l[0] : d;
64
+ return (p = r[m]) != null && p.length ? u.fetch(b.Guides, {
65
+ categories: r[m],
66
+ take: s
67
+ }).then((i) => n && h && P === t.node.name ? S(
68
+ i,
69
+ u,
70
+ { guide: h }
71
+ ) : new Promise(
72
+ (v) => v(i)
73
+ )).then(({ guides: i }) => e({ guides: i, contactMethods: f, categories: g })) : e({ contactMethods: f, categories: g });
74
+ })
75
+ );
76
+ });
77
+ })).then(() => {
78
+ w();
79
+ });
80
+ };
81
+ export {
82
+ L as default
83
+ };
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@telia-ace/knowledge-widget-components-contact-list",
3
+ "version": "0.0.1",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./index.mjs",
9
+ "require": "./index.js"
10
+ }
11
+ },
12
+ "dependencies": {
13
+ "@telia-ace/knowledge-widget-adapters": "*",
14
+ "@telia-ace/knowledge-widget-component-utilities": "*",
15
+ "@telia-ace/knowledge-widget-core": "*",
16
+ "@telia-ace/knowledge-widget-ui": "*",
17
+ "@telia-ace/widget-forms": "*",
18
+ "@telia-ace/widget-utilities": "*",
19
+ "@telia-ace/widget-types-grid": "*",
20
+ "@telia-ace/knowledge-data-client": "*",
21
+ "@webprovisions/platform": "^1.1.4"
22
+ },
23
+ "peerDependencies": {
24
+ "@emotion/styled": "11.11.0",
25
+ "react": "18.2.0",
26
+ "@emotion/react": "11.11.1"
27
+ }
28
+ }