@telia-ace/knowledge-widget-components-search 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.
- package/filter-badges.d.ts +11 -0
- package/index.d.ts +3 -0
- package/index.js +1 -0
- package/index.mjs +163 -0
- package/package.json +26 -0
- package/quick-filter-item-list.d.ts +18 -0
- package/quick-filter.d.ts +7 -0
- package/search-9b2fdf13.mjs +987 -0
- package/search-9f532628.js +222 -0
- package/search-component.d.ts +45 -0
- package/search.d.ts +8 -0
- package/use-search.d.ts +9 -0
- package/utils.d.ts +4 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
|
|
3
|
+
type Props = {
|
|
4
|
+
inputHasFocus: boolean;
|
|
5
|
+
searchContainerRef: HTMLElement | null;
|
|
6
|
+
showGuideCategory: boolean;
|
|
7
|
+
showTag: boolean;
|
|
8
|
+
position: 'inside' | 'below';
|
|
9
|
+
};
|
|
10
|
+
declare const FilterBadges: React.FC<Props>;
|
|
11
|
+
export default FilterBadges;
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const p=require("@telia-ace/knowledge-data-client"),T=require("@telia-ace/knowledge-widget-core"),R=require("@telia-ace/knowledge-widget-ui"),d=require("@telia-ace/widget-utilities"),b=n=>!!n.guideCategoryId||n.tagIds.length>0,A=(n,r)=>{const c=d.categoryTrail(n,r),l=d.getCategoryTrailAsObjects(c,r);return c.map(C=>{var h;return((h=l.get(C))==null?void 0:h.title)||""}).join(" / ")},y=n=>{const r=d.deepClone(n);return r.sort((c,l)=>c.title>l.title?1:-1),r.forEach(c=>{c.items&&(c.items=y(c.items))}),r},m=n=>R.createReactComponent(n,"search",Promise.resolve().then(()=>require("./search-9f532628.js")),r=>{const{events:c}=n.get("$widget"),[l,I]=T.createEventSubscriber(c),C=async a=>{const t=a.tag?a.tag.split(","):[],e=a.guideCategory,s=a.phrase||"",{activeFilterBadges:g}=r.properties(),o=await v({}),i=await w({tagId:a.tag,searchPhrase:s}),f=e?d.findCategoryById(e,i):null,u=t.reduce((P,k)=>{const q=o.find(D=>D.id===k);return q&&P.push(q),P},[]);r.writeProperties({activeFilterBadges:{...g,tag:u,guideCategory:f,tooltip:A(e,i)||null}})};r.actions.create("search",async a=>{const{route:t="search",patchParams:e=!1}=r.properties(),{filters:s,filtersChanged:g,value:o}=a;if(o.length>0||(b(s)||g)&&!s.initial){const i=await n.getAsync("router"),{params:f}=i.getRouteData();let u={guide:void 0,id:void 0,accordion:void 0,contactMethod:void 0};u.phrase=o.length>0?encodeURIComponent(o):"",e&&(u={...f,...u}),(s!=null&&s.guideCategoryId||g)&&(u.guideCategory=s.guideCategoryId||void 0),((s==null?void 0:s.tagIds.length)>0||g)&&(s.tagIds.length>0?u.tag=s.tagIds.join(","):u.tag=void 0),i.navigate(t,d.createParams(u))}}),r.actions.create("clear",(a,t)=>{a.navigateToHome&&n.getAsync("router").then(e=>{const{name:s}=e.getInitialRoute();e.navigate(s)})});const h=()=>n.getAsync("router").then(a=>a.getRouteData().params);r.actions.create("quick-filter:add",async a=>{const{category:t,tagIds:e=[],initial:s}=a,g=await n.getAsync("router"),{params:o}=g.getRouteData(),i=o.tag?o.tag.split(","):[];r.actions.dispatch("search",{filtersChanged:!0,filters:{guideCategoryId:t,tagIds:[...new Set([...i,...e])]},value:o.phrase||""})}),r.actions.create("quick-filter:remove",({types:a,ids:t=[]})=>{const{activeFilterBadges:e}=r.properties();n.getAsync("router").then(s=>{var o;const{params:g}=s.getRouteData();r.actions.dispatch("search",{filtersChanged:!0,filters:{guideCategoryId:a.indexOf("guideCategory")>-1?null:(o=e==null?void 0:e.guideCategory)==null?void 0:o.id,tagIds:a.indexOf("tag")>-1?((e==null?void 0:e.tag)||[]).filter(i=>!(t!=null&&t.includes(i.id))).map(i=>i.id):(e==null?void 0:e.tag.map(i=>i.id))||[]},value:g.phrase||""})})}),r.actions.create("quick-filter:close",()=>r.writeProperties({quickFilter:{items:[],loading:!1,open:!1}})),r.actions.create("quick-filter:open",({symbol:a,type:t})=>(r.writeProperties({quickFilter:{type:t,symbol:a,items:[],loading:!0,open:!0}}),h().then(({tag:e,guideCategory:s,phrase:g})=>{if(t==="guideCategory")return w({tagId:e,searchPhrase:g}).then(o=>{const i=d.deepClone(o);r.writeProperties({quickFilter:{items:y(i),loading:!1}})});if(t==="tag")return v({categories:s,searchPhrase:g}).then(o=>{const i=d.deepClone(o);r.writeProperties({quickFilter:{items:y(i),loading:!1}})})})));const w=a=>p.DataClient.getInstance(n).then(t=>t.fetch(p.DataType.GuideCategories,a)).then(t=>t.categories||[]),v=a=>p.DataClient.getInstance(n).then(t=>t.fetch(p.DataType.TagsOnGuides,a)).then((t=[])=>t);return h().then(a=>{C(a)}),l("router:changed",(a,{current:t})=>{const{routeData:{params:e}}=t;C(e)}),l("data-client:fetched",(a,t)=>{const{filterBadges:e}=r.properties(),s=typeof e=="object"?!!e.tag:!!e;t.type==="match"&&s&&h().then(({tag:g})=>{const{tags:o=[]}=t.response,i=o.find(f=>f.id===g)||null;r.writeProperties({filters:{tag:i}})})}),()=>{I()}});module.exports=m;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { DataClient as P, DataType as R } from "@telia-ace/knowledge-data-client";
|
|
2
|
+
import { createEventSubscriber as k } from "@telia-ace/knowledge-widget-core";
|
|
3
|
+
import { createReactComponent as q } from "@telia-ace/knowledge-widget-ui";
|
|
4
|
+
import { createParams as A, deepClone as p, findCategoryById as D, categoryTrail as j, getCategoryTrailAsObjects as O } from "@telia-ace/widget-utilities";
|
|
5
|
+
const x = (g) => !!g.guideCategoryId || g.tagIds.length > 0, F = (g, r) => {
|
|
6
|
+
const c = j(g, r), d = O(c, r);
|
|
7
|
+
return c.map((f) => {
|
|
8
|
+
var l;
|
|
9
|
+
return ((l = d.get(f)) == null ? void 0 : l.title) || "";
|
|
10
|
+
}).join(" / ");
|
|
11
|
+
}, y = (g) => {
|
|
12
|
+
const r = p(g);
|
|
13
|
+
return r.sort((c, d) => c.title > d.title ? 1 : -1), r.forEach((c) => {
|
|
14
|
+
c.items && (c.items = y(c.items));
|
|
15
|
+
}), r;
|
|
16
|
+
}, U = (g) => q(
|
|
17
|
+
g,
|
|
18
|
+
"search",
|
|
19
|
+
import("./search-9b2fdf13.mjs"),
|
|
20
|
+
(r) => {
|
|
21
|
+
const { events: c } = g.get("$widget"), [d, C] = k(c), f = async (a) => {
|
|
22
|
+
const e = a.tag ? a.tag.split(",") : [], t = a.guideCategory, s = a.phrase || "", { activeFilterBadges: n } = r.properties(), o = await v({}), i = await I({
|
|
23
|
+
tagId: a.tag,
|
|
24
|
+
searchPhrase: s
|
|
25
|
+
}), h = t ? D(
|
|
26
|
+
t,
|
|
27
|
+
i
|
|
28
|
+
) : null, u = e.reduce((m, T) => {
|
|
29
|
+
const w = o.find((b) => b.id === T);
|
|
30
|
+
return w && m.push(w), m;
|
|
31
|
+
}, []);
|
|
32
|
+
r.writeProperties({
|
|
33
|
+
activeFilterBadges: {
|
|
34
|
+
...n,
|
|
35
|
+
tag: u,
|
|
36
|
+
guideCategory: h,
|
|
37
|
+
tooltip: F(t, i) || null
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
r.actions.create(
|
|
42
|
+
"search",
|
|
43
|
+
async (a) => {
|
|
44
|
+
const { route: e = "search", patchParams: t = !1 } = r.properties(), { filters: s, filtersChanged: n, value: o } = a;
|
|
45
|
+
if (o.length > 0 || (x(s) || n) && !s.initial) {
|
|
46
|
+
const i = await g.getAsync("router"), { params: h } = i.getRouteData();
|
|
47
|
+
let u = {
|
|
48
|
+
guide: void 0,
|
|
49
|
+
id: void 0,
|
|
50
|
+
accordion: void 0,
|
|
51
|
+
contactMethod: void 0
|
|
52
|
+
};
|
|
53
|
+
u.phrase = o.length > 0 ? encodeURIComponent(o) : "", t && (u = {
|
|
54
|
+
...h,
|
|
55
|
+
...u
|
|
56
|
+
}), (s != null && s.guideCategoryId || n) && (u.guideCategory = s.guideCategoryId || void 0), ((s == null ? void 0 : s.tagIds.length) > 0 || n) && (s.tagIds.length > 0 ? u.tag = s.tagIds.join(",") : u.tag = void 0), i.navigate(e, A(u));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
), r.actions.create("clear", (a, e) => {
|
|
60
|
+
a.navigateToHome && g.getAsync("router").then((t) => {
|
|
61
|
+
const { name: s } = t.getInitialRoute();
|
|
62
|
+
t.navigate(s);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
const l = () => g.getAsync("router").then((a) => a.getRouteData().params);
|
|
66
|
+
r.actions.create(
|
|
67
|
+
"quick-filter:add",
|
|
68
|
+
async (a) => {
|
|
69
|
+
const { category: e, tagIds: t = [], initial: s } = a, n = await g.getAsync("router"), { params: o } = n.getRouteData(), i = o.tag ? o.tag.split(",") : [];
|
|
70
|
+
r.actions.dispatch("search", {
|
|
71
|
+
filtersChanged: !0,
|
|
72
|
+
filters: {
|
|
73
|
+
guideCategoryId: e,
|
|
74
|
+
tagIds: [.../* @__PURE__ */ new Set([...i, ...t])]
|
|
75
|
+
},
|
|
76
|
+
value: o.phrase || ""
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
), r.actions.create(
|
|
80
|
+
"quick-filter:remove",
|
|
81
|
+
({ types: a, ids: e = [] }) => {
|
|
82
|
+
const { activeFilterBadges: t } = r.properties();
|
|
83
|
+
g.getAsync("router").then((s) => {
|
|
84
|
+
var o;
|
|
85
|
+
const { params: n } = s.getRouteData();
|
|
86
|
+
r.actions.dispatch("search", {
|
|
87
|
+
filtersChanged: !0,
|
|
88
|
+
filters: {
|
|
89
|
+
guideCategoryId: a.indexOf("guideCategory") > -1 ? null : (o = t == null ? void 0 : t.guideCategory) == null ? void 0 : o.id,
|
|
90
|
+
tagIds: a.indexOf("tag") > -1 ? ((t == null ? void 0 : t.tag) || []).filter((i) => !(e != null && e.includes(i.id))).map((i) => i.id) : (t == null ? void 0 : t.tag.map((i) => i.id)) || []
|
|
91
|
+
},
|
|
92
|
+
value: n.phrase || ""
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
), r.actions.create("quick-filter:close", () => r.writeProperties({
|
|
97
|
+
quickFilter: {
|
|
98
|
+
items: [],
|
|
99
|
+
loading: !1,
|
|
100
|
+
open: !1
|
|
101
|
+
}
|
|
102
|
+
})), r.actions.create("quick-filter:open", ({ symbol: a, type: e }) => (r.writeProperties({
|
|
103
|
+
quickFilter: {
|
|
104
|
+
type: e,
|
|
105
|
+
symbol: a,
|
|
106
|
+
items: [],
|
|
107
|
+
loading: !0,
|
|
108
|
+
open: !0
|
|
109
|
+
}
|
|
110
|
+
}), l().then(({ tag: t, guideCategory: s, phrase: n }) => {
|
|
111
|
+
if (e === "guideCategory")
|
|
112
|
+
return I({
|
|
113
|
+
tagId: t,
|
|
114
|
+
searchPhrase: n
|
|
115
|
+
}).then((o) => {
|
|
116
|
+
const i = p(o);
|
|
117
|
+
r.writeProperties({
|
|
118
|
+
quickFilter: {
|
|
119
|
+
items: y(i),
|
|
120
|
+
loading: !1
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
if (e === "tag")
|
|
125
|
+
return v({
|
|
126
|
+
categories: s,
|
|
127
|
+
searchPhrase: n
|
|
128
|
+
}).then((o) => {
|
|
129
|
+
const i = p(o);
|
|
130
|
+
r.writeProperties({
|
|
131
|
+
quickFilter: {
|
|
132
|
+
items: y(i),
|
|
133
|
+
loading: !1
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
})));
|
|
138
|
+
const I = (a) => P.getInstance(g).then(
|
|
139
|
+
(e) => e.fetch(R.GuideCategories, a)
|
|
140
|
+
).then(
|
|
141
|
+
(e) => e.categories || []
|
|
142
|
+
), v = (a) => P.getInstance(g).then((e) => e.fetch(R.TagsOnGuides, a)).then((e = []) => e);
|
|
143
|
+
return l().then((a) => {
|
|
144
|
+
f(a);
|
|
145
|
+
}), d("router:changed", (a, { current: e }) => {
|
|
146
|
+
const {
|
|
147
|
+
routeData: { params: t }
|
|
148
|
+
} = e;
|
|
149
|
+
f(t);
|
|
150
|
+
}), d("data-client:fetched", (a, e) => {
|
|
151
|
+
const { filterBadges: t } = r.properties(), s = typeof t == "object" ? !!t.tag : !!t;
|
|
152
|
+
e.type === "match" && s && l().then(({ tag: n }) => {
|
|
153
|
+
const { tags: o = [] } = e.response, i = o.find((h) => h.id === n) || null;
|
|
154
|
+
r.writeProperties({ filters: { tag: i } });
|
|
155
|
+
});
|
|
156
|
+
}), () => {
|
|
157
|
+
C();
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
export {
|
|
162
|
+
U as default
|
|
163
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@telia-ace/knowledge-widget-components-search",
|
|
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-core": "*",
|
|
14
|
+
"@telia-ace/knowledge-widget-ui": "*",
|
|
15
|
+
"@telia-ace/widget-utilities": "*",
|
|
16
|
+
"@telia-ace/knowledge-data-client": "*",
|
|
17
|
+
"@telia-ace/widget-routing": "*",
|
|
18
|
+
"@telia-ace/widget-types-grid": "*",
|
|
19
|
+
"@webprovisions/platform": "^1.1.4"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@emotion/react": "11.11.1",
|
|
23
|
+
"@emotion/styled": "11.11.0",
|
|
24
|
+
"react": "18.2.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Category, Tag } from '../../../knowledge/core/src/index.ts';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
|
|
4
|
+
type Props = {
|
|
5
|
+
filterPhrase: string;
|
|
6
|
+
items: Category[] | Tag[];
|
|
7
|
+
filterType: 'guideCategory' | 'tag';
|
|
8
|
+
searchContainer: HTMLElement | null;
|
|
9
|
+
filterContainer: HTMLElement | null;
|
|
10
|
+
inputHasFocus: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const getFocusedIndex: (elem: HTMLElement) => {
|
|
13
|
+
anchors: HTMLAnchorElement[];
|
|
14
|
+
focusedIndex: number;
|
|
15
|
+
};
|
|
16
|
+
export declare const focusInput: (searchContainerRef: HTMLElement | null) => void;
|
|
17
|
+
declare const QuickFilterItemList: React.FC<Props>;
|
|
18
|
+
export default QuickFilterItemList;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
phrase: string;
|
|
3
|
+
inputHasFocus: boolean;
|
|
4
|
+
searchContainerRef: HTMLElement | null;
|
|
5
|
+
};
|
|
6
|
+
declare const _default: ({ phrase, inputHasFocus, searchContainerRef }: Props) => import("@emotion/react/types/jsx-namespace").EmotionJSX.Element | null;
|
|
7
|
+
export default _default;
|