@telia-ace/knowledge-widget-components-search 1.3.41-rc.1 → 1.3.41
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/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +7 -7
- package/{search-9b2fdf13.mjs → search-BIaoCGAR.mjs} +39 -40
- package/{search-9f532628.js → search-CiXXcOpq.js} +1 -1
- package/utils.d.ts +1 -1
package/index.js
CHANGED
|
@@ -1 +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-
|
|
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-CiXXcOpq.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
CHANGED
|
@@ -16,7 +16,7 @@ const x = (g) => !!g.guideCategoryId || g.tagIds.length > 0, F = (g, r) => {
|
|
|
16
16
|
}, U = (g) => q(
|
|
17
17
|
g,
|
|
18
18
|
"search",
|
|
19
|
-
import("./search-
|
|
19
|
+
import("./search-BIaoCGAR.mjs"),
|
|
20
20
|
(r) => {
|
|
21
21
|
const { events: c } = g.get("$widget"), [d, C] = k(c), f = async (a) => {
|
|
22
22
|
const e = a.tag ? a.tag.split(",") : [], t = a.guideCategory, s = a.phrase || "", { activeFilterBadges: n } = r.properties(), o = await v({}), i = await I({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/knowledge-widget-components-search",
|
|
3
|
-
"version": "1.3.41
|
|
3
|
+
"version": "1.3.41",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@telia-ace/knowledge-widget-core": "^1.3.41
|
|
14
|
-
"@telia-ace/knowledge-widget-ui": "^1.3.41
|
|
15
|
-
"@telia-ace/widget-utilities": "^1.3.41
|
|
16
|
-
"@telia-ace/knowledge-data-client": "^1.3.41
|
|
17
|
-
"@telia-ace/widget-routing": "^1.3.41
|
|
18
|
-
"@telia-ace/widget-types-grid": "^1.3.41
|
|
13
|
+
"@telia-ace/knowledge-widget-core": "^1.3.41",
|
|
14
|
+
"@telia-ace/knowledge-widget-ui": "^1.3.41",
|
|
15
|
+
"@telia-ace/widget-utilities": "^1.3.41",
|
|
16
|
+
"@telia-ace/knowledge-data-client": "^1.3.41",
|
|
17
|
+
"@telia-ace/widget-routing": "^1.3.41",
|
|
18
|
+
"@telia-ace/widget-types-grid": "^1.3.41",
|
|
19
19
|
"@webprovisions/platform": "^1.1.4"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as y, jsxs as F, Fragment as xe } from "react/jsx-runtime";
|
|
2
2
|
import { css as j } from "@emotion/react";
|
|
3
3
|
import z from "@emotion/styled";
|
|
4
|
-
import {
|
|
4
|
+
import { useProperties as K, useDispatch as M, useRouteData as se, useEventListener as X, useKeyPress as Q, Tooltip as $e, borderTabStyle as J, Text as ie, Link as ae, SymbolBadge as U, ItemTree as we, useScroll as Ce, useContainer as ce, Loader as Ae, contentBox as le, useDebounce as Se, usePrevious as ee, useChildren as Ie, useWidgetEvent as ve, useTransitionEnd as Ee, convertToStringAttributes as qe, Input as ze, Button as de } from "@telia-ace/knowledge-widget-ui";
|
|
5
5
|
import { Component as Le } from "@telia-ace/widget-types-grid";
|
|
6
6
|
import { appendClassNames as Y, deepClone as De, categoryTrail as Fe } from "@telia-ace/widget-utilities";
|
|
7
|
-
import {
|
|
7
|
+
import { useState as B, useCallback as v, useRef as Z, useEffect as O, useMemo as Be } from "react";
|
|
8
8
|
const Ne = ({
|
|
9
9
|
text: e,
|
|
10
10
|
className: t,
|
|
@@ -17,7 +17,7 @@ const Ne = ({
|
|
|
17
17
|
document.activeElement === r.current
|
|
18
18
|
);
|
|
19
19
|
return /* @__PURE__ */ F(
|
|
20
|
-
|
|
20
|
+
ie,
|
|
21
21
|
{
|
|
22
22
|
className: Y(
|
|
23
23
|
t,
|
|
@@ -30,7 +30,7 @@ const Ne = ({
|
|
|
30
30
|
children: [
|
|
31
31
|
e,
|
|
32
32
|
/* @__PURE__ */ y(
|
|
33
|
-
|
|
33
|
+
ae,
|
|
34
34
|
{
|
|
35
35
|
...c,
|
|
36
36
|
ref: r,
|
|
@@ -44,7 +44,7 @@ const Ne = ({
|
|
|
44
44
|
role: "button",
|
|
45
45
|
"aria-label": u.replace("{{item}}", e),
|
|
46
46
|
onClick: (p) => a(p, n),
|
|
47
|
-
children: /* @__PURE__ */ y(
|
|
47
|
+
children: /* @__PURE__ */ y(U, { size: 13, symbol: { type: "Svg", content: "close" } })
|
|
48
48
|
}
|
|
49
49
|
)
|
|
50
50
|
]
|
|
@@ -57,11 +57,11 @@ const Ne = ({
|
|
|
57
57
|
showGuideCategory: a,
|
|
58
58
|
position: u
|
|
59
59
|
}) => {
|
|
60
|
-
const { activeFilterBadges: c, deleteFilterBadgeAriaLabel: r = "" } = K(), $ = M(), { name: k, params: p } =
|
|
60
|
+
const { activeFilterBadges: c, deleteFilterBadgeAriaLabel: r = "" } = K(), $ = M(), { name: k, params: p } = se(), [E, m] = B(!1), C = v((s) => {
|
|
61
61
|
const { key: d } = s;
|
|
62
62
|
["ArrowLeft", "ArrowRight"].indexOf(d) === -1 && m(!1);
|
|
63
63
|
}, []);
|
|
64
|
-
|
|
64
|
+
X("keydown", C, window), X("click", C, window);
|
|
65
65
|
const { guideCategory: A, tag: h, tooltip: q } = c || {}, l = (s) => {
|
|
66
66
|
const d = s.querySelectorAll(
|
|
67
67
|
".humany-filter-badge > a"
|
|
@@ -70,7 +70,7 @@ const Ne = ({
|
|
|
70
70
|
badges: d,
|
|
71
71
|
index: Array.from(d).findIndex((g) => document.activeElement === g)
|
|
72
72
|
};
|
|
73
|
-
}, o =
|
|
73
|
+
}, o = v(
|
|
74
74
|
(s, d, g) => {
|
|
75
75
|
s.preventDefault(), $("quick-filter:remove", { types: [d], ids: [g] });
|
|
76
76
|
},
|
|
@@ -80,13 +80,13 @@ const Ne = ({
|
|
|
80
80
|
return;
|
|
81
81
|
const { badges: g, index: b } = l(t);
|
|
82
82
|
if (g.length) {
|
|
83
|
-
let
|
|
84
|
-
s === "left" ? b === -1 ?
|
|
83
|
+
let I = null;
|
|
84
|
+
s === "left" ? b === -1 ? I = g.item(g.length - 1) : b > 0 && (I = g.item(b - 1)) : s === "right" && (b === g.length - 1 ? d && d.focus() : g.item(b + 1) && (I = g.item(b + 1))), I && (I.focus(), m(!0));
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
87
|
Q(
|
|
88
88
|
"ArrowLeft",
|
|
89
|
-
|
|
89
|
+
v(() => {
|
|
90
90
|
if (!t)
|
|
91
91
|
return;
|
|
92
92
|
const { index: s } = l(t);
|
|
@@ -97,7 +97,7 @@ const Ne = ({
|
|
|
97
97
|
}, [e, t])
|
|
98
98
|
), Q(
|
|
99
99
|
"ArrowRight",
|
|
100
|
-
|
|
100
|
+
v(() => {
|
|
101
101
|
if (!t)
|
|
102
102
|
return;
|
|
103
103
|
const { index: s } = l(t);
|
|
@@ -108,7 +108,7 @@ const Ne = ({
|
|
|
108
108
|
}, [t])
|
|
109
109
|
), Q(
|
|
110
110
|
"Backspace",
|
|
111
|
-
|
|
111
|
+
v(
|
|
112
112
|
(s) => {
|
|
113
113
|
if (!t)
|
|
114
114
|
return;
|
|
@@ -142,7 +142,7 @@ const Ne = ({
|
|
|
142
142
|
]
|
|
143
143
|
)
|
|
144
144
|
);
|
|
145
|
-
const f =
|
|
145
|
+
const f = v(
|
|
146
146
|
(s) => s === "guideCategory" && A && a ? /* @__PURE__ */ y(
|
|
147
147
|
te,
|
|
148
148
|
{
|
|
@@ -157,7 +157,7 @@ const Ne = ({
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
) : s === "tag" && (h != null && h.length) && n ? h.map((d) => {
|
|
160
|
-
const g = h.reduce((b,
|
|
160
|
+
const g = h.reduce((b, I) => (I.id !== d.id && b.push(I.id), b), []);
|
|
161
161
|
return /* @__PURE__ */ y(
|
|
162
162
|
te,
|
|
163
163
|
{
|
|
@@ -325,7 +325,7 @@ const Ne = ({
|
|
|
325
325
|
i && p(i);
|
|
326
326
|
}
|
|
327
327
|
}, [r, a]);
|
|
328
|
-
const h =
|
|
328
|
+
const h = v(
|
|
329
329
|
(l, o) => {
|
|
330
330
|
let i = ((m == null ? void 0 : m.tag) || []).map((s) => s.id);
|
|
331
331
|
o === "tag" && l.id && (i = i.includes(l.id) ? i.filter((s) => s !== l.id) : [...i, l.id]);
|
|
@@ -386,17 +386,17 @@ const Ne = ({
|
|
|
386
386
|
}
|
|
387
387
|
)
|
|
388
388
|
};
|
|
389
|
-
return
|
|
389
|
+
return X(
|
|
390
390
|
"keydown",
|
|
391
391
|
(l) => {
|
|
392
|
-
var
|
|
392
|
+
var I;
|
|
393
393
|
const { key: o } = l;
|
|
394
394
|
if (!a || !(o === "ArrowDown" || o === "ArrowUp" || o === "Enter"))
|
|
395
395
|
return;
|
|
396
396
|
const { anchors: i, focusedIndex: f } = G(a);
|
|
397
397
|
if (o === "Enter") {
|
|
398
398
|
if (c && A) {
|
|
399
|
-
const x = (
|
|
399
|
+
const x = (I = i[0]) == null ? void 0 : I.getAttribute("data-id");
|
|
400
400
|
x && h({ id: x }, n);
|
|
401
401
|
}
|
|
402
402
|
return;
|
|
@@ -439,7 +439,7 @@ const Ne = ({
|
|
|
439
439
|
const k = e.toLowerCase().indexOf(t.toLowerCase()), p = e.substr(0, k), E = e.slice(k, k + t.length), m = e.substr(k + t.length);
|
|
440
440
|
return [p, E, m];
|
|
441
441
|
}, [c, r, $] = u();
|
|
442
|
-
return /* @__PURE__ */ F(
|
|
442
|
+
return /* @__PURE__ */ F(ie, { children: [
|
|
443
443
|
a,
|
|
444
444
|
c,
|
|
445
445
|
r ? /* @__PURE__ */ y("strong", { children: r }) : null,
|
|
@@ -459,7 +459,7 @@ const Ne = ({
|
|
|
459
459
|
border-color: ${(n = e.theme.colors) == null ? void 0 : n.text};
|
|
460
460
|
}
|
|
461
461
|
`;
|
|
462
|
-
}, re = z(
|
|
462
|
+
}, re = z(ae)`
|
|
463
463
|
display: block;
|
|
464
464
|
text-decoration: none;
|
|
465
465
|
font-size: ${(e) => {
|
|
@@ -509,7 +509,7 @@ const Ne = ({
|
|
|
509
509
|
},
|
|
510
510
|
activeFilterBadges: u,
|
|
511
511
|
noMatchesLabel: c = "No matching items"
|
|
512
|
-
} = K(), [r, $] = Ce(!0), k =
|
|
512
|
+
} = K(), [r, $] = Ce(!0), k = ce(), { events: p } = k.get("$widget"), E = Z(), m = v(
|
|
513
513
|
(f) => (f && f.addEventListener(
|
|
514
514
|
"keydown",
|
|
515
515
|
() => {
|
|
@@ -555,7 +555,7 @@ const Ne = ({
|
|
|
555
555
|
}
|
|
556
556
|
);
|
|
557
557
|
}, Xe = z.div`
|
|
558
|
-
${(e) =>
|
|
558
|
+
${(e) => le(e)};
|
|
559
559
|
position: absolute;
|
|
560
560
|
top: calc(100% + ${(e) => {
|
|
561
561
|
var t;
|
|
@@ -614,7 +614,7 @@ const Ne = ({
|
|
|
614
614
|
} = K(), p = Se(
|
|
615
615
|
e,
|
|
616
616
|
typeof k == "boolean" ? 600 : k
|
|
617
|
-
), E = ee(p), m = ee(r), C = Z(null), A =
|
|
617
|
+
), E = ee(p), m = ee(r), C = Z(null), A = v(
|
|
618
618
|
(o = "") => {
|
|
619
619
|
var i;
|
|
620
620
|
if ($) {
|
|
@@ -634,12 +634,12 @@ const Ne = ({
|
|
|
634
634
|
return a("search", { value: o });
|
|
635
635
|
},
|
|
636
636
|
[a, r]
|
|
637
|
-
), h =
|
|
637
|
+
), h = v(
|
|
638
638
|
(o) => {
|
|
639
639
|
a("clear", { navigateToHome: o });
|
|
640
640
|
},
|
|
641
641
|
[a]
|
|
642
|
-
), q = (o) => u ? o.replace(/([@#].*)/g, "") : o, l =
|
|
642
|
+
), q = (o) => u ? o.replace(/([@#].*)/g, "") : o, l = v(
|
|
643
643
|
(o) => {
|
|
644
644
|
if (c.open && o.preventDefault) {
|
|
645
645
|
o.preventDefault();
|
|
@@ -687,17 +687,17 @@ const Ne = ({
|
|
|
687
687
|
quickFilter: h,
|
|
688
688
|
quickFilters: q,
|
|
689
689
|
filterBadges: l
|
|
690
|
-
} = K(), { params: o } =
|
|
690
|
+
} = K(), { params: o } = se(), [i, f] = B(!1), [s, d] = B(o.phrase || ""), [g, b] = B({
|
|
691
691
|
guideCategory: !1,
|
|
692
692
|
tag: !1
|
|
693
|
-
}),
|
|
693
|
+
}), I = ce(), x = Ie(), L = M(), { position: ge = "inside" } = typeof l == "object" ? l : {};
|
|
694
694
|
O(() => {
|
|
695
695
|
const { guideCategory: w, tag: S } = o, D = typeof l == "object" ? !!l.guideCategory : !!l, ke = typeof l == "object" ? !!l.tag : !!l;
|
|
696
696
|
b({
|
|
697
697
|
guideCategory: D && !!w,
|
|
698
698
|
tag: ke && !!S
|
|
699
699
|
});
|
|
700
|
-
}, [l, o]),
|
|
700
|
+
}, [l, o]), ve(
|
|
701
701
|
"router:changed",
|
|
702
702
|
() => {
|
|
703
703
|
if (h) {
|
|
@@ -720,22 +720,22 @@ const Ne = ({
|
|
|
720
720
|
O(() => {
|
|
721
721
|
d(o.phrase || "");
|
|
722
722
|
}, [o.phrase]);
|
|
723
|
-
const me =
|
|
723
|
+
const me = v(
|
|
724
724
|
(w) => {
|
|
725
725
|
d(w);
|
|
726
726
|
},
|
|
727
727
|
[d]
|
|
728
|
-
), he =
|
|
728
|
+
), he = v(() => {
|
|
729
729
|
L("quick-filter:close").then(() => P(!0));
|
|
730
|
-
}, [L, P]), pe =
|
|
730
|
+
}, [L, P]), pe = v(() => {
|
|
731
731
|
var w, S;
|
|
732
732
|
c && !i && ((S = (w = N.current) == null ? void 0 : w.getElementsByTagName("input")[0]) == null || S.focus());
|
|
733
|
-
}, [c, i, N]), ye =
|
|
734
|
-
|
|
733
|
+
}, [c, i, N]), ye = v(() => {
|
|
734
|
+
I.getAsync("router").then((w) => {
|
|
735
735
|
const S = w.getInitialRoute(), D = w.getRouteData();
|
|
736
736
|
(S == null ? void 0 : S.name) === D.name && (S == null ? void 0 : S.name) !== m ? d("") : P(!0);
|
|
737
737
|
});
|
|
738
|
-
}, [
|
|
738
|
+
}, [I, d, P]), R = (w) => {
|
|
739
739
|
if (w !== ge)
|
|
740
740
|
return null;
|
|
741
741
|
if (g.guideCategory || g.tag)
|
|
@@ -790,7 +790,7 @@ const Ne = ({
|
|
|
790
790
|
"data-has-focus": i,
|
|
791
791
|
children: [
|
|
792
792
|
/* @__PURE__ */ y(
|
|
793
|
-
|
|
793
|
+
U,
|
|
794
794
|
{
|
|
795
795
|
size: 32,
|
|
796
796
|
symbol: { type: "Svg", content: "search" }
|
|
@@ -804,7 +804,6 @@ const Ne = ({
|
|
|
804
804
|
/* @__PURE__ */ y(
|
|
805
805
|
ze,
|
|
806
806
|
{
|
|
807
|
-
crossOrigin: void 0,
|
|
808
807
|
type: "search",
|
|
809
808
|
"aria-label": E,
|
|
810
809
|
...be,
|
|
@@ -824,7 +823,7 @@ const Ne = ({
|
|
|
824
823
|
hasFocus: i,
|
|
825
824
|
title: p,
|
|
826
825
|
onClick: ye,
|
|
827
|
-
children: /* @__PURE__ */ y(
|
|
826
|
+
children: /* @__PURE__ */ y(U, { size: 27, symbol: { type: "Svg", content: "clear" } })
|
|
828
827
|
}
|
|
829
828
|
),
|
|
830
829
|
A && !V && x.map((w) => /* @__PURE__ */ y(Le, { id: w.id, branch: "default" }, w.id)),
|
|
@@ -844,7 +843,7 @@ const Ne = ({
|
|
|
844
843
|
}
|
|
845
844
|
);
|
|
846
845
|
}, Je = z.div`
|
|
847
|
-
${
|
|
846
|
+
${le};
|
|
848
847
|
width: 100%;
|
|
849
848
|
padding: ${(e) => {
|
|
850
849
|
var t;
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
`,pe=z.p`
|
|
115
115
|
margin: 0 ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.normal}};
|
|
116
116
|
color: ${e=>{var t;return(t=e.theme.colors)==null?void 0:t.text}};
|
|
117
|
-
`,
|
|
117
|
+
`,O=(e,t)=>{if(e&&!t||!e&&t)return!0;if(e&&t){if(!Array.isArray(e)&&!Array.isArray(t)){if(e.id!==t.id)return!0}else if(!((c,f)=>c.length===f.length?c.every((l,o)=>l===f[o]):!1)(e,t))return!0}return!1},ye=(e,t={},s=!0)=>{const c=i.useDispatch(),{quickFilters:f=!1,quickFilter:l={open:!1},activeFilterBadges:o,filterBadges:w=!1,incremental:C=600}=i.useProperties(),x=i.useDebounce(e,typeof C=="boolean"?600:C),A=i.usePrevious(x),y=i.usePrevious(o),E=h.useRef(null),j=h.useCallback((n="")=>{var a;if(w){const g=O(o==null?void 0:o.guideCategory,y==null?void 0:y.guideCategory)||O(o==null?void 0:o.tag,y==null?void 0:y.tag);return c("search",{value:n,filtersChanged:g,filters:{tagIds:((o==null?void 0:o.tag)||[]).map(r=>r.id),guideCategoryId:((a=o==null?void 0:o.guideCategory)==null?void 0:a.id)||null}})}return c("search",{value:n})},[c,o]),b=h.useCallback(n=>{c("clear",{navigateToHome:n})},[c]),I=n=>f?n.replace(/([@#].*)/g,""):n,u=h.useCallback(n=>{if(l.open&&n.preventDefault){n.preventDefault();return}const a=document.activeElement,g=E.current&&typeof E.current.contains=="function"?E.current.contains(a):!1,r=I(e);typeof n=="boolean"&&n||r.length&&g||o!=null&&o.guideCategory||o!=null&&o.tag.length&&g?j(r):b(g)},[E,e,l,b,o,j]);return h.useEffect(()=>{const n=O(o==null?void 0:o.guideCategory,y==null?void 0:y.guideCategory)||O(o==null?void 0:o.tag,y==null?void 0:y.tag),a=x&&I(x),g=A&&I(A);typeof g<"u"&&g!==a&&a!==t.phrase&&s&&!l.open&&u(n)},[x,l.open,o,u]),h.useEffect(()=>{if(e&&f){const n=typeof f=="boolean"&&!!f||typeof f=="object"&&!!f.guideCategory,a=typeof f=="boolean"&&!!f||typeof f=="object"&&!!f.tag;n&&e.indexOf("@")===e.length-1&&c("quick-filter:open",{type:"guideCategory",symbol:"@"}),a&&e.indexOf("#")===e.length-1&&c("quick-filter:open",{type:"tag",symbol:"#"})}l.open&&e.indexOf("@")===-1&&e.indexOf("#")===-1&&c("quick-filter:close")},[e]),[u,b,E]},be=({className:e,...t})=>{const{showSearchButton:s,showClearButton:c,role:f="search",autoFocus:l,placeholder:o,searchButtonLabel:w,searchButtonText:C,clearButtonLabel:x,ariaLabel:A,route:y="search",incremental:E=!0,showChildren:j=!1,quickFilter:b,quickFilters:I,filterBadges:u}=i.useProperties(),{params:n}=i.useRouteData(),[a,g]=h.useState(!1),[r,d]=h.useState(n.phrase||""),[m,k]=h.useState({guideCategory:!1,tag:!1}),q=i.useContainer(),$=i.useChildren(),L=i.useDispatch(),{position:_="inside"}=typeof u=="object"?u:{};h.useEffect(()=>{const{guideCategory:S,tag:v}=n,D=typeof u=="object"?!!u.guideCategory:!!u,ne=typeof u=="object"?!!u.tag:!!u;k({guideCategory:D&&!!S,tag:ne&&!!v})},[u,n]),i.useWidgetEvent("router:changed",()=>{if(b){const{open:S,symbol:v}=b;if(S){if(v){const D=r.replace(r.slice(r.indexOf(v)),"");d(D)}L("quick-filter:close")}}},[b,r,d,L]);const[M,P,B]=ye(r,n,!!E);h.useEffect(()=>{d(n.phrase||"")},[n.phrase]);const R=h.useCallback(S=>{d(S)},[d]),V=h.useCallback(()=>{L("quick-filter:close").then(()=>P(!0))},[L,P]),ee=h.useCallback(()=>{var S,v;l&&!a&&((v=(S=B.current)==null?void 0:S.getElementsByTagName("input")[0])==null||v.focus())},[l,a,B]),te=h.useCallback(()=>{q.getAsync("router").then(S=>{const v=S.getInitialRoute(),D=S.getRouteData();(v==null?void 0:v.name)===D.name&&(v==null?void 0:v.name)!==y?d(""):P(!0)})},[q,d,P]),U=S=>{if(S!==_)return null;if(m.guideCategory||m.tag)return p.jsx(ie,{position:S,inputHasFocus:a,showGuideCategory:m.guideCategory,showTag:m.tag,searchContainerRef:B.current})};i.useTransitionEnd(ee);const Q=c&&(m.guideCategory||m.tag||r),se=I?i.convertToStringAttributes({role:"combobox","aria-autocomplete":"list",autoComplete:"off","aria-haspopup":"listbox"}):{};return p.jsxs(xe,{...t,ref:B,role:f,className:F.appendClassNames(e,"humany-search"),"data-has-phrase":!!r,"data-has-focus":a,"data-has-search-symbol":s?"true":"false",children:[p.jsxs(ke,{action:".",onSubmit:S=>{var v,D;S.preventDefault(),(D=(v=B.current)==null?void 0:v.getElementsByTagName("input")[0])==null||D.blur()},"data-has-focus":a,children:[s&&p.jsxs(Ce,{"aria-label":w,type:"submit",title:w,disabled:!r,onClick:M,"data-has-phrase":!!r,"data-has-focus":a,children:[p.jsx(i.SymbolBadge,{size:32,symbol:{type:"Svg",content:"search"}}),C]}),U("inside"),p.jsx(i.Input,{type:"search","aria-label":A,...se,placeholder:m.guideCategory||m.tag?"":o,onFocusChange:g,onEscape:V,onEnter:M,onChange:R,value:r}),Q&&p.jsx($e,{"aria-label":x,type:"reset",hasFocus:a,title:x,onClick:te,children:p.jsx(i.SymbolBadge,{size:27,symbol:{type:"Svg",content:"clear"}})}),j&&!Q&&$.map(S=>p.jsx(oe.Component,{id:S.id,branch:"default"},S.id)),p.jsx(ge,{inputHasFocus:a,phrase:r,searchContainerRef:B.current})]}),U("below")]})},xe=z.div`
|
|
118
118
|
${i.contentBox};
|
|
119
119
|
width: 100%;
|
|
120
120
|
padding: ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.large}};
|
package/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Category, Tag } from '../../../knowledge/core/src/index.ts';
|
|
2
2
|
|
|
3
3
|
export declare const match: (title: string, phrase: string) => boolean;
|
|
4
|
-
export declare const filterItems: (items: (Tag | Category)[] | undefined, type:
|
|
4
|
+
export declare const filterItems: (items: (Tag | Category)[] | undefined, type: "tag" | "guideCategory", phrase: string) => any[];
|