@telia-ace/knowledge-widget-components-search 1.1.8 → 1.2.2

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,987 @@
1
+ import { jsxs as F, jsx as y, Fragment as xe } from "react/jsx-runtime";
2
+ import { css as j } from "@emotion/react";
3
+ import z from "@emotion/styled";
4
+ import { borderTabStyle as J, Text as se, Link as ie, SymbolBadge as X, useProperties as K, useDispatch as M, useRouteData as ae, useEventListener as U, useKeyPress as Q, Tooltip as $e, ItemTree as we, contentBox as ce, useScroll as Ce, useContainer as le, Loader as Ae, useDebounce as Se, usePrevious as ee, useChildren as ve, useWidgetEvent as Ie, useTransitionEnd as Ee, convertToStringAttributes as qe, Input as ze, Button as de } from "@telia-ace/knowledge-widget-ui";
5
+ import { Component as Le } from "@telia-ace/widget-types-grid";
6
+ import { appendClassNames as Y, deepClone as De, categoryTrail as Fe } from "@telia-ace/widget-utilities";
7
+ import { useRef as Z, useState as B, useCallback as I, useEffect as O, useMemo as Be } from "react";
8
+ const Ne = ({
9
+ text: e,
10
+ className: t,
11
+ filterType: n,
12
+ handleClick: a,
13
+ deleteAriaLabel: u = "",
14
+ ...c
15
+ }) => {
16
+ const r = Z(), [$, k] = B(
17
+ document.activeElement === r.current
18
+ );
19
+ return /* @__PURE__ */ F(
20
+ se,
21
+ {
22
+ className: Y(
23
+ t,
24
+ "humany-filter-badge",
25
+ $ ? "humany-filter-badge-focused" : ""
26
+ ),
27
+ onKeyDown: (p) => {
28
+ p.key === "Enter" && a(p, n);
29
+ },
30
+ children: [
31
+ e,
32
+ /* @__PURE__ */ y(
33
+ ie,
34
+ {
35
+ ...c,
36
+ ref: r,
37
+ tabIndex: 0,
38
+ onFocus: () => {
39
+ k(!0);
40
+ },
41
+ onBlur: () => {
42
+ k(!1);
43
+ },
44
+ role: "button",
45
+ "aria-label": u.replace("{{item}}", e),
46
+ onClick: (p) => a(p, n),
47
+ children: /* @__PURE__ */ y(X, { size: 13, symbol: { type: "Svg", content: "close" } })
48
+ }
49
+ )
50
+ ]
51
+ }
52
+ );
53
+ }, Te = ({
54
+ inputHasFocus: e,
55
+ searchContainerRef: t,
56
+ showTag: n,
57
+ showGuideCategory: a,
58
+ position: u
59
+ }) => {
60
+ const { activeFilterBadges: c, deleteFilterBadgeAriaLabel: r = "" } = K(), $ = M(), { name: k, params: p } = ae(), [E, m] = B(!1), C = I((s) => {
61
+ const { key: d } = s;
62
+ ["ArrowLeft", "ArrowRight"].indexOf(d) === -1 && m(!1);
63
+ }, []);
64
+ U("keydown", C, window), U("click", C, window);
65
+ const { guideCategory: A, tag: h, tooltip: q } = c || {}, l = (s) => {
66
+ const d = s.querySelectorAll(
67
+ ".humany-filter-badge > a"
68
+ );
69
+ return {
70
+ badges: d,
71
+ index: Array.from(d).findIndex((g) => document.activeElement === g)
72
+ };
73
+ }, o = I(
74
+ (s, d, g) => {
75
+ s.preventDefault(), $("quick-filter:remove", { types: [d], ids: [g] });
76
+ },
77
+ [$]
78
+ ), i = (s, d) => {
79
+ if (!t)
80
+ return;
81
+ const { badges: g, index: b } = l(t);
82
+ if (g.length) {
83
+ let v = null;
84
+ s === "left" ? b === -1 ? v = g.item(g.length - 1) : b > 0 && (v = g.item(b - 1)) : s === "right" && (b === g.length - 1 ? d && d.focus() : g.item(b + 1) && (v = g.item(b + 1))), v && (v.focus(), m(!0));
85
+ }
86
+ };
87
+ Q(
88
+ "ArrowLeft",
89
+ I(() => {
90
+ if (!t)
91
+ return;
92
+ const { index: s } = l(t);
93
+ if (e || s > -1) {
94
+ const d = t.querySelector('[data-type="search"]'), g = d && d.selectionStart !== null && d.selectionStart <= 0, b = s > -1;
95
+ (g || b) && i("left", d);
96
+ }
97
+ }, [e, t])
98
+ ), Q(
99
+ "ArrowRight",
100
+ I(() => {
101
+ if (!t)
102
+ return;
103
+ const { index: s } = l(t);
104
+ if (s > -1) {
105
+ const d = t.querySelector('[data-type="search"]');
106
+ s > -1 && i("right", d);
107
+ }
108
+ }, [t])
109
+ ), Q(
110
+ "Backspace",
111
+ I(
112
+ (s) => {
113
+ if (!t)
114
+ return;
115
+ let d = [];
116
+ const { index: g } = l(t), b = t.querySelector('[data-type="search"]');
117
+ if (g > -1)
118
+ g === 0 ? a ? d = ["guideCategory"] : n && (d = ["tag"]) : g === 1 && (d = ["tag"]);
119
+ else {
120
+ const x = document.activeElement === b;
121
+ b && b.selectionStart !== null && b.selectionStart <= 0 && x && (c != null && c.tag.length ? d = ["tag"] : c != null && c.guideCategory && (d = ["guideCategory"]));
122
+ }
123
+ if (d.length > 0) {
124
+ s.preventDefault();
125
+ let x;
126
+ if (d.includes("tag")) {
127
+ const L = c == null ? void 0 : c.tag.at(-1);
128
+ x = L == null ? void 0 : L.id;
129
+ }
130
+ $("quick-filter:remove", {
131
+ types: d,
132
+ ids: [x]
133
+ });
134
+ }
135
+ },
136
+ [
137
+ t,
138
+ c,
139
+ n,
140
+ a,
141
+ $
142
+ ]
143
+ )
144
+ );
145
+ const f = I(
146
+ (s) => s === "guideCategory" && A && a ? /* @__PURE__ */ y(
147
+ te,
148
+ {
149
+ text: `@${A.title}`,
150
+ routeName: k,
151
+ filterType: "guideCategory",
152
+ handleClick: o,
153
+ deleteAriaLabel: r,
154
+ params: {
155
+ ...p,
156
+ guideCategory: void 0
157
+ }
158
+ }
159
+ ) : s === "tag" && (h != null && h.length) && n ? h.map((d) => {
160
+ const g = h.reduce((b, v) => (v.id !== d.id && b.push(v.id), b), []);
161
+ return /* @__PURE__ */ y(
162
+ te,
163
+ {
164
+ className: "humany-filter-badge",
165
+ text: `#${d.title}`,
166
+ routeName: k,
167
+ filterType: "tag",
168
+ handleClick: (b) => o(b, "tag", d.id),
169
+ deleteAriaLabel: r,
170
+ params: {
171
+ ...p,
172
+ tag: g
173
+ }
174
+ },
175
+ d.id
176
+ );
177
+ }) : null,
178
+ // eslint-disable-next-line react-hooks/exhaustive-deps
179
+ [
180
+ A,
181
+ h,
182
+ k,
183
+ p,
184
+ a,
185
+ n,
186
+ E,
187
+ o
188
+ ]
189
+ );
190
+ return !A && !h ? null : /* @__PURE__ */ F(Oe, { className: "humany-filter-badges", position: u, children: [
191
+ A && q ? (
192
+ // eslint-disable-next-line react/jsx-no-useless-fragment
193
+ /* @__PURE__ */ y($e, { content: /* @__PURE__ */ y(xe, { children: q }), sticky: !1, children: f("guideCategory") })
194
+ ) : f("guideCategory"),
195
+ h && f("tag")
196
+ ] });
197
+ }, Oe = z.div`
198
+ display: flex;
199
+ align-items: center;
200
+ flex-wrap: wrap;
201
+
202
+ ${(e) => {
203
+ var t, n;
204
+ return e.position === "inside" ? j`
205
+ &:not(:first-child) {
206
+ margin: 0 0 0 ${(t = e.theme.sizes) == null ? void 0 : t.normal};
207
+ }
208
+ ` : j`
209
+ margin: ${(n = e.theme.sizes) == null ? void 0 : n.small} 0 0 0;
210
+ span:first-child {
211
+ margin-left: 0;
212
+ }
213
+ `;
214
+ }}
215
+ `, te = z(Ne)`
216
+ display: flex;
217
+ align-items: center;
218
+ padding: ${(e) => {
219
+ var t, n;
220
+ return `${(t = e.theme.sizes) == null ? void 0 : t.small} calc(${(n = e.theme.sizes) == null ? void 0 : n.normal}/2) `;
221
+ }};
222
+ background-color: ${(e) => {
223
+ var t;
224
+ return (t = e.theme.colors) == null ? void 0 : t.primary;
225
+ }};
226
+ border-radius: ${(e) => e.theme.borderRadius};
227
+ font-weight: 300;
228
+ font-size: ${(e) => {
229
+ var t;
230
+ return (t = e.theme.fonts) == null ? void 0 : t.normal;
231
+ }};
232
+ font-style: italic;
233
+ color: #ffffff;
234
+ text-decoration: none;
235
+ white-space: nowrap;
236
+
237
+ margin: calc(${(e) => {
238
+ var t;
239
+ return (t = e.theme.sizes) == null ? void 0 : t.small;
240
+ }} / 2);
241
+
242
+ &.humany-filter-badge-focused:focus-within {
243
+ ${J}
244
+ background-color: transparent;
245
+
246
+ svg {
247
+ path {
248
+ stroke: ${(e) => {
249
+ var t;
250
+ return (t = e.theme.colors) == null ? void 0 : t.primary;
251
+ }};
252
+ }
253
+ }
254
+ a {
255
+ outline: none;
256
+ }
257
+ }
258
+
259
+ svg {
260
+ width: 17px;
261
+ height: 11px;
262
+ margin: 1px 0 0 ${(e) => {
263
+ var t;
264
+ return (t = e.theme.sizes) == null ? void 0 : t.small;
265
+ }};
266
+ path {
267
+ stroke: #ffffff;
268
+ stroke-width: 2px;
269
+ }
270
+ order: 1;
271
+ }
272
+ `, T = (e, t) => !t || !e ? !0 : e.toLowerCase().indexOf(t.toLowerCase()) > -1, je = (e = [], t, n) => {
273
+ if (!n)
274
+ return e;
275
+ const a = De(e);
276
+ if (t === "tag")
277
+ return a.filter((r) => T(r.title, n));
278
+ const u = Ke(a, n);
279
+ return ue(
280
+ a,
281
+ (r) => u.indexOf(r.id) > -1
282
+ );
283
+ }, ue = (e, t) => e.filter((n) => (n.items && n.items.length && (n.items = ue(n.items, t)), t(n))), Ke = (e, t) => {
284
+ const a = fe(e).filter((c) => T(c.title, t)).map((c) => c.id);
285
+ let u = [];
286
+ return a.forEach((c) => {
287
+ const r = Fe(c, e);
288
+ u = u.concat(r);
289
+ }), u;
290
+ }, fe = (e) => {
291
+ let t = [];
292
+ return e.forEach((n) => {
293
+ t.push(n), Array.isArray(n.items) && (t = t.concat(fe(n.items)));
294
+ }), t;
295
+ }, G = (e) => {
296
+ const t = Array.from((e == null ? void 0 : e.getElementsByTagName("A")) || []).filter(
297
+ (n) => n.getAttribute("disabled") === null
298
+ );
299
+ return {
300
+ anchors: t,
301
+ focusedIndex: t.findIndex((n) => document.activeElement === n)
302
+ };
303
+ }, Pe = (e) => e ? e.querySelector(
304
+ '[data-type="search"], input[type="search"]'
305
+ ) : null, H = (e) => {
306
+ if (!e)
307
+ return;
308
+ const t = Pe(e);
309
+ t && t.focus();
310
+ }, We = ({
311
+ filterPhrase: e,
312
+ items: t,
313
+ filterType: n,
314
+ filterContainer: a,
315
+ searchContainer: u,
316
+ inputHasFocus: c
317
+ }) => {
318
+ const [r, $] = B(t || []), [k, p] = B(null), E = M(), { activeFilterBadges: m, quickFilters: C } = K(), A = typeof C == "object" && !!C.autoSelect || typeof C == "boolean" && !!C;
319
+ O(() => {
320
+ $(je(t, n, e));
321
+ }, [e, n, t]), O(() => {
322
+ var l;
323
+ if (a) {
324
+ const { anchors: o } = G(a), i = (l = o[0]) == null ? void 0 : l.getAttribute("data-id");
325
+ i && p(i);
326
+ }
327
+ }, [r, a]);
328
+ const h = I(
329
+ (l, o) => {
330
+ let i = ((m == null ? void 0 : m.tag) || []).map((s) => s.id);
331
+ o === "tag" && l.id && (i = i.includes(l.id) ? i.filter((s) => s !== l.id) : [...i, l.id]);
332
+ const f = {
333
+ category: m != null && m.guideCategory ? m.guideCategory.id : void 0,
334
+ tagIds: i
335
+ };
336
+ o === "guideCategory" && (f.category = l.id), E("quick-filter:add", f);
337
+ },
338
+ [m, E]
339
+ ), q = (l) => l === "guideCategory" ? {
340
+ renderItem: (o, i) => /* @__PURE__ */ y(
341
+ re,
342
+ {
343
+ autoSelect: A && c && o.id === k,
344
+ disabled: !T(o.title, e),
345
+ tabIndex: T(o.title, e) ? 0 : -1,
346
+ onKeyDown: (f) => {
347
+ f.key === "Enter" && h(o, l);
348
+ },
349
+ "data-level": i,
350
+ onClick: () => {
351
+ h(o, l);
352
+ },
353
+ "data-id": o.id,
354
+ children: /* @__PURE__ */ y(
355
+ ne,
356
+ {
357
+ title: o.title,
358
+ phrase: e,
359
+ matches: T(o.title, e)
360
+ }
361
+ )
362
+ }
363
+ )
364
+ } : {
365
+ renderLi: !0,
366
+ renderItem: (o) => /* @__PURE__ */ y(
367
+ re,
368
+ {
369
+ autoSelect: A && c && o.id === k,
370
+ onKeyDown: (i) => {
371
+ i.key === "Enter" && h(o, l);
372
+ },
373
+ onClick: () => {
374
+ h(o, l);
375
+ },
376
+ "data-id": o.id,
377
+ children: /* @__PURE__ */ y(
378
+ ne,
379
+ {
380
+ symbol: "#",
381
+ title: o.title,
382
+ phrase: e,
383
+ matches: T(o.title, e)
384
+ }
385
+ )
386
+ }
387
+ )
388
+ };
389
+ return U(
390
+ "keydown",
391
+ (l) => {
392
+ var v;
393
+ const { key: o } = l;
394
+ if (!a || !(o === "ArrowDown" || o === "ArrowUp" || o === "Enter"))
395
+ return;
396
+ const { anchors: i, focusedIndex: f } = G(a);
397
+ if (o === "Enter") {
398
+ if (c && A) {
399
+ const x = (v = i[0]) == null ? void 0 : v.getAttribute("data-id");
400
+ x && h({ id: x }, n);
401
+ }
402
+ return;
403
+ }
404
+ const s = () => {
405
+ var x;
406
+ return (x = i[0]) == null ? void 0 : x.focus();
407
+ }, d = () => {
408
+ var x;
409
+ return (x = i[i.length - 1]) == null ? void 0 : x.focus();
410
+ }, g = () => {
411
+ var x;
412
+ return (x = i[f + 1]) == null ? void 0 : x.focus();
413
+ }, b = () => {
414
+ var x;
415
+ return (x = i[f - 1]) == null ? void 0 : x.focus();
416
+ };
417
+ c ? (l.preventDefault(), o === "ArrowDown" ? s() : d()) : f > -1 && (l.preventDefault(), o === "ArrowDown" ? i.length > f + 1 ? g() : H(u) : f - 1 < 0 ? H(u) : b());
418
+ },
419
+ window
420
+ ), /* @__PURE__ */ y(
421
+ we,
422
+ {
423
+ tree: r,
424
+ renderEmpty: !1,
425
+ ulProps: { role: "listbox" },
426
+ liProps: { role: "option" },
427
+ ...q(n)
428
+ }
429
+ );
430
+ }, ne = ({
431
+ title: e,
432
+ phrase: t,
433
+ matches: n,
434
+ symbol: a = ""
435
+ }) => {
436
+ const u = () => {
437
+ if (!n || !t)
438
+ return [e];
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
+ return [p, E, m];
441
+ }, [c, r, $] = u();
442
+ return /* @__PURE__ */ F(se, { children: [
443
+ a,
444
+ c,
445
+ r ? /* @__PURE__ */ y("strong", { children: r }) : null,
446
+ $ || null
447
+ ] });
448
+ }, Me = j`
449
+ opacity: 0.5;
450
+ pointer-events: none;
451
+ `, oe = (e) => {
452
+ var t, n;
453
+ return j`
454
+ background-color: ${(t = e.theme.colors) == null ? void 0 : t.text};
455
+ color: #ffffff;
456
+ outline: none;
457
+
458
+ span:first-child {
459
+ border-color: ${(n = e.theme.colors) == null ? void 0 : n.text};
460
+ }
461
+ `;
462
+ }, re = z(ie)`
463
+ display: block;
464
+ text-decoration: none;
465
+ font-size: ${(e) => {
466
+ var t;
467
+ return (t = e.theme.fonts) == null ? void 0 : t.normal;
468
+ }};
469
+
470
+ ${(e) => e.disabled && Me}
471
+ color: ${(e) => {
472
+ var t;
473
+ return (t = e.theme.colors) == null ? void 0 : t.text;
474
+ }};
475
+ background-color: transparent;
476
+
477
+ span {
478
+ display: block;
479
+ ${(e) => {
480
+ var t, n, a, u;
481
+ return e["data-level"] ? `padding: calc(${(t = e.theme.sizes) == null ? void 0 : t.normal} / 2) ${(n = e.theme.sizes) == null ? void 0 : n.normal};` : `padding: calc(${(a = e.theme.sizes) == null ? void 0 : a.normal} / 2) ${(u = e.theme.sizes) == null ? void 0 : u.medium}; `;
482
+ }}
483
+ ${(e) => e["data-level"] && "border-left: 2px solid"}
484
+ }
485
+
486
+ span:first-child {
487
+ border-color: #e7e7e7;
488
+ }
489
+
490
+ ${(e) => {
491
+ var t;
492
+ return e["data-level"] && `padding: 0 calc(${(t = e.theme.sizes) == null ? void 0 : t.medium} * ${e["data-level"]});`;
493
+ }}
494
+
495
+ ${(e) => e.autoSelect && oe}
496
+
497
+ &:hover,
498
+ &:focus {
499
+ ${oe}
500
+ }
501
+ `, Qe = ({ phrase: e = "", inputHasFocus: t, searchContainerRef: n }) => {
502
+ const {
503
+ quickFilter: a = {
504
+ open: !1,
505
+ loading: !1,
506
+ symbol: "",
507
+ type: "",
508
+ items: []
509
+ },
510
+ activeFilterBadges: u,
511
+ noMatchesLabel: c = "No matching items"
512
+ } = K(), [r, $] = Ce(!0), k = le(), { events: p } = k.get("$widget"), E = Z(), m = I(
513
+ (f) => (f && f.addEventListener(
514
+ "keydown",
515
+ () => {
516
+ G(f).focusedIndex > -1 && p.subscribeOnce("router:changed", () => {
517
+ H(n);
518
+ });
519
+ },
520
+ !0
521
+ ), E.current = f, f),
522
+ // eslint-disable-next-line react-hooks/exhaustive-deps
523
+ [n]
524
+ ), { items: C = [], symbol: A, type: h, open: q, loading: l } = a, o = Be(() => {
525
+ const f = ((u == null ? void 0 : u.tag) || []).map((s) => s.id);
526
+ return C.filter((s) => !f.includes(s.id));
527
+ }, [C, u]);
528
+ if (!q || !A)
529
+ return null;
530
+ const i = e.slice(e.indexOf(A) + 1);
531
+ return /* @__PURE__ */ F(
532
+ Xe,
533
+ {
534
+ ref: m,
535
+ "data-loading": l,
536
+ className: Y(
537
+ "humany-quick-filter-dropdown",
538
+ [h === "guideCategory", "humany-quick-filter-guide-categories"],
539
+ [h === "tag", "humany-quick-filter-tags"]
540
+ ),
541
+ children: [
542
+ /* @__PURE__ */ y(Ue, { className: "humany-quick-filter-dropdown-inner", css: r, ref: $, children: o.length > 0 ? /* @__PURE__ */ y(
543
+ We,
544
+ {
545
+ filterType: h,
546
+ items: o,
547
+ filterPhrase: i,
548
+ filterContainer: $.current,
549
+ searchContainer: n,
550
+ inputHasFocus: t
551
+ }
552
+ ) : /* @__PURE__ */ y(Ge, { children: c }) }),
553
+ /* @__PURE__ */ y(Ae, { loading: l })
554
+ ]
555
+ }
556
+ );
557
+ }, Xe = z.div`
558
+ ${(e) => ce(e)};
559
+ position: absolute;
560
+ top: calc(100% + ${(e) => {
561
+ var t;
562
+ return (t = e.theme.sizes) == null ? void 0 : t.normal;
563
+ }});
564
+ left: 0;
565
+ right: 0;
566
+ z-index: 1;
567
+ overflow: hidden;
568
+ `, Ue = z.div`
569
+ max-height: 300px;
570
+ overflow: auto;
571
+ padding: ${(e) => {
572
+ var t;
573
+ return (t = e.theme.sizes) == null ? void 0 : t.medium;
574
+ }} 0;
575
+ ${(e) => e.css}
576
+ ul {
577
+ list-style: none;
578
+ padding: 0;
579
+ margin: 0;
580
+ }
581
+ li div {
582
+ ${(e) => {
583
+ var t;
584
+ return `margin: ${(t = e.theme.sizes) == null ? void 0 : t.normal} 0;`;
585
+ }}
586
+ }
587
+ `, Ge = z.p`
588
+ margin: 0 ${(e) => {
589
+ var t;
590
+ return (t = e.theme.sizes) == null ? void 0 : t.normal;
591
+ }};
592
+ color: ${(e) => {
593
+ var t;
594
+ return (t = e.theme.colors) == null ? void 0 : t.text;
595
+ }};
596
+ `, W = (e, t) => {
597
+ if (e && !t || !e && t)
598
+ return !0;
599
+ if (e && t) {
600
+ if (!Array.isArray(e) && !Array.isArray(t)) {
601
+ if (e.id !== t.id)
602
+ return !0;
603
+ } else if (!((a, u) => a.length === u.length ? a.every((c, r) => c === u[r]) : !1)(e, t))
604
+ return !0;
605
+ }
606
+ return !1;
607
+ }, He = (e, t = {}, n = !0) => {
608
+ const a = M(), {
609
+ quickFilters: u = !1,
610
+ quickFilter: c = { open: !1 },
611
+ activeFilterBadges: r,
612
+ filterBadges: $ = !1,
613
+ incremental: k = 600
614
+ } = K(), p = Se(
615
+ e,
616
+ typeof k == "boolean" ? 600 : k
617
+ ), E = ee(p), m = ee(r), C = Z(null), A = I(
618
+ (o = "") => {
619
+ var i;
620
+ if ($) {
621
+ const f = W(
622
+ r == null ? void 0 : r.guideCategory,
623
+ m == null ? void 0 : m.guideCategory
624
+ ) || W(r == null ? void 0 : r.tag, m == null ? void 0 : m.tag);
625
+ return a("search", {
626
+ value: o,
627
+ filtersChanged: f,
628
+ filters: {
629
+ tagIds: ((r == null ? void 0 : r.tag) || []).map((s) => s.id),
630
+ guideCategoryId: ((i = r == null ? void 0 : r.guideCategory) == null ? void 0 : i.id) || null
631
+ }
632
+ });
633
+ }
634
+ return a("search", { value: o });
635
+ },
636
+ [a, r]
637
+ ), h = I(
638
+ (o) => {
639
+ a("clear", { navigateToHome: o });
640
+ },
641
+ [a]
642
+ ), q = (o) => u ? o.replace(/([@#].*)/g, "") : o, l = I(
643
+ (o) => {
644
+ if (c.open && o.preventDefault) {
645
+ o.preventDefault();
646
+ return;
647
+ }
648
+ const i = document.activeElement, f = C.current && typeof C.current.contains == "function" ? C.current.contains(i) : !1, s = q(e);
649
+ typeof o == "boolean" && o || s.length && f || r != null && r.guideCategory || r != null && r.tag.length && f ? A(s) : h(f);
650
+ },
651
+ [
652
+ C,
653
+ e,
654
+ c,
655
+ h,
656
+ r,
657
+ A
658
+ ]
659
+ );
660
+ return O(() => {
661
+ const o = W(
662
+ r == null ? void 0 : r.guideCategory,
663
+ m == null ? void 0 : m.guideCategory
664
+ ) || W(r == null ? void 0 : r.tag, m == null ? void 0 : m.tag), i = p && q(p), f = E && q(E);
665
+ typeof f < "u" && f !== i && i !== t.phrase && n && !c.open && l(o);
666
+ }, [p, c.open, r, l]), O(() => {
667
+ if (e && u) {
668
+ const o = typeof u == "boolean" && !!u || typeof u == "object" && !!u.guideCategory, i = typeof u == "boolean" && !!u || typeof u == "object" && !!u.tag;
669
+ o && e.indexOf("@") === e.length - 1 && a("quick-filter:open", { type: "guideCategory", symbol: "@" }), i && e.indexOf("#") === e.length - 1 && a("quick-filter:open", { type: "tag", symbol: "#" });
670
+ }
671
+ c.open && e.indexOf("@") === -1 && e.indexOf("#") === -1 && a("quick-filter:close");
672
+ }, [e]), [l, h, C];
673
+ }, st = ({ className: e, ...t }) => {
674
+ const {
675
+ showSearchButton: n,
676
+ showClearButton: a,
677
+ role: u = "search",
678
+ autoFocus: c,
679
+ placeholder: r,
680
+ searchButtonLabel: $,
681
+ searchButtonText: k,
682
+ clearButtonLabel: p,
683
+ ariaLabel: E,
684
+ route: m = "search",
685
+ incremental: C = !0,
686
+ showChildren: A = !1,
687
+ quickFilter: h,
688
+ quickFilters: q,
689
+ filterBadges: l
690
+ } = K(), { params: o } = ae(), [i, f] = B(!1), [s, d] = B(o.phrase || ""), [g, b] = B({
691
+ guideCategory: !1,
692
+ tag: !1
693
+ }), v = le(), x = ve(), L = M(), { position: ge = "inside" } = typeof l == "object" ? l : {};
694
+ O(() => {
695
+ const { guideCategory: w, tag: S } = o, D = typeof l == "object" ? !!l.guideCategory : !!l, ke = typeof l == "object" ? !!l.tag : !!l;
696
+ b({
697
+ guideCategory: D && !!w,
698
+ tag: ke && !!S
699
+ });
700
+ }, [l, o]), Ie(
701
+ "router:changed",
702
+ () => {
703
+ if (h) {
704
+ const { open: w, symbol: S } = h;
705
+ if (w) {
706
+ if (S) {
707
+ const D = s.replace(
708
+ s.slice(s.indexOf(S)),
709
+ ""
710
+ );
711
+ d(D);
712
+ }
713
+ L("quick-filter:close");
714
+ }
715
+ }
716
+ },
717
+ [h, s, d, L]
718
+ );
719
+ const [_, P, N] = He(s, o, !!C);
720
+ O(() => {
721
+ d(o.phrase || "");
722
+ }, [o.phrase]);
723
+ const me = I(
724
+ (w) => {
725
+ d(w);
726
+ },
727
+ [d]
728
+ ), he = I(() => {
729
+ L("quick-filter:close").then(() => P(!0));
730
+ }, [L, P]), pe = I(() => {
731
+ var w, S;
732
+ c && !i && ((S = (w = N.current) == null ? void 0 : w.getElementsByTagName("input")[0]) == null || S.focus());
733
+ }, [c, i, N]), ye = I(() => {
734
+ v.getAsync("router").then((w) => {
735
+ const S = w.getInitialRoute(), D = w.getRouteData();
736
+ (S == null ? void 0 : S.name) === D.name && (S == null ? void 0 : S.name) !== m ? d("") : P(!0);
737
+ });
738
+ }, [v, d, P]), R = (w) => {
739
+ if (w !== ge)
740
+ return null;
741
+ if (g.guideCategory || g.tag)
742
+ return /* @__PURE__ */ y(
743
+ Te,
744
+ {
745
+ position: w,
746
+ inputHasFocus: i,
747
+ showGuideCategory: g.guideCategory,
748
+ showTag: g.tag,
749
+ searchContainerRef: N.current
750
+ }
751
+ );
752
+ };
753
+ Ee(pe);
754
+ const V = a && (g.guideCategory || g.tag || s), be = q ? qe({
755
+ role: "combobox",
756
+ "aria-autocomplete": "list",
757
+ autoComplete: "off",
758
+ "aria-haspopup": "listbox"
759
+ }) : {};
760
+ return /* @__PURE__ */ F(
761
+ Je,
762
+ {
763
+ ...t,
764
+ ref: N,
765
+ role: u,
766
+ className: Y(e, "humany-search"),
767
+ "data-has-phrase": !!s,
768
+ "data-has-focus": i,
769
+ "data-has-search-symbol": n ? "true" : "false",
770
+ children: [
771
+ /* @__PURE__ */ F(
772
+ Ye,
773
+ {
774
+ action: ".",
775
+ onSubmit: (w) => {
776
+ var S, D;
777
+ w.preventDefault(), (D = (S = N.current) == null ? void 0 : S.getElementsByTagName("input")[0]) == null || D.blur();
778
+ },
779
+ "data-has-focus": i,
780
+ children: [
781
+ n && /* @__PURE__ */ F(
782
+ Ze,
783
+ {
784
+ "aria-label": $,
785
+ type: "submit",
786
+ title: $,
787
+ disabled: !s,
788
+ onClick: _,
789
+ "data-has-phrase": !!s,
790
+ "data-has-focus": i,
791
+ children: [
792
+ /* @__PURE__ */ y(
793
+ X,
794
+ {
795
+ size: 32,
796
+ symbol: { type: "Svg", content: "search" }
797
+ }
798
+ ),
799
+ k
800
+ ]
801
+ }
802
+ ),
803
+ R("inside"),
804
+ /* @__PURE__ */ y(
805
+ ze,
806
+ {
807
+ crossOrigin: void 0,
808
+ type: "search",
809
+ "aria-label": E,
810
+ ...be,
811
+ placeholder: g.guideCategory || g.tag ? "" : r,
812
+ onFocusChange: f,
813
+ onEscape: he,
814
+ onEnter: _,
815
+ onChange: me,
816
+ value: s
817
+ }
818
+ ),
819
+ V && /* @__PURE__ */ y(
820
+ _e,
821
+ {
822
+ "aria-label": p,
823
+ type: "reset",
824
+ hasFocus: i,
825
+ title: p,
826
+ onClick: ye,
827
+ children: /* @__PURE__ */ y(X, { size: 27, symbol: { type: "Svg", content: "clear" } })
828
+ }
829
+ ),
830
+ A && !V && x.map((w) => /* @__PURE__ */ y(Le, { id: w.id, branch: "default" }, w.id)),
831
+ /* @__PURE__ */ y(
832
+ Qe,
833
+ {
834
+ inputHasFocus: i,
835
+ phrase: s,
836
+ searchContainerRef: N.current
837
+ }
838
+ )
839
+ ]
840
+ }
841
+ ),
842
+ R("below")
843
+ ]
844
+ }
845
+ );
846
+ }, Je = z.div`
847
+ ${ce};
848
+ width: 100%;
849
+ padding: ${(e) => {
850
+ var t;
851
+ return (t = e.theme.sizes) == null ? void 0 : t.large;
852
+ }};
853
+
854
+ input {
855
+ background-color: transparent;
856
+ border: none;
857
+ outline: none;
858
+ min-width: 25%;
859
+ flex: 1;
860
+ font-size: ${(e) => {
861
+ var t;
862
+ return (t = e.theme.fonts) == null ? void 0 : t.normal;
863
+ }};
864
+ font-weight: 300;
865
+ font-style: italic;
866
+ padding: 1em 0;
867
+ color: ${(e) => {
868
+ var t;
869
+ return (t = e.theme.colors) == null ? void 0 : t.text;
870
+ }};
871
+ -webkit-appearance: none;
872
+
873
+ ${(e) => {
874
+ var t;
875
+ return e["data-has-search-symbol"] === "true" && `text-indent: ${(t = e.theme.sizes) == null ? void 0 : t.normal};`;
876
+ }}
877
+
878
+ ::placeholder {
879
+ color: ${(e) => {
880
+ var t;
881
+ return (t = e.theme.colors) == null ? void 0 : t.text;
882
+ }};
883
+ }
884
+ /* removes the 'X' from IE */
885
+ &[type='search']::-ms-clear {
886
+ display: none;
887
+ width: 0;
888
+ height: 0;
889
+ }
890
+ &[type='search']::-ms-reveal {
891
+ display: none;
892
+ width: 0;
893
+ height: 0;
894
+ }
895
+
896
+ /* removes the 'X' from Chrome */
897
+ &[type='search']::-webkit-search-decoration,
898
+ &[type='search']::-webkit-search-cancel-button,
899
+ &[type='search']::-webkit-search-results-button,
900
+ &[type='search']::-webkit-search-results-decoration {
901
+ display: none;
902
+ }
903
+
904
+ &:focus {
905
+ outline: none;
906
+ }
907
+ }
908
+
909
+ button {
910
+ background: transparent;
911
+ border: none;
912
+ padding: 0;
913
+ display: inline-flex;
914
+ align-items: center;
915
+ font-size: ${(e) => {
916
+ var t;
917
+ return (t = e.theme.fonts) == null ? void 0 : t.large;
918
+ }};
919
+ transition: color 200ms ease-out;
920
+ color: ${(e) => {
921
+ var t;
922
+ return e["data-has-focus"] || e["data-has-phrase"] ? (t = e.theme.colors) == null ? void 0 : t.primary : "#000000";
923
+ }};
924
+ cursor: pointer;
925
+ > svg {
926
+ height: 100%;
927
+ }
928
+ }
929
+ `, Ye = z.form`
930
+ display: flex;
931
+ flex-wrap: nowrap;
932
+ align-items: center;
933
+ border: ${(e) => e.theme.inputBorder};
934
+ border-radius: ${(e) => e.theme.borderRadius};
935
+ background-color: #ffffff;
936
+ position: relative;
937
+ padding: 0 ${(e) => {
938
+ var t;
939
+ return (t = e.theme.sizes) == null ? void 0 : t.normal;
940
+ }};
941
+
942
+ ${(e) => {
943
+ var t, n;
944
+ return e["data-has-focus"] && j`
945
+ ${(t = e.theme.accessibility) != null && t.isTabbing ? J(e) : `
946
+ border-color: ${(n = e.theme.colors) == null ? void 0 : n.primary};
947
+ outline: none;
948
+ input {
949
+ outline: none;
950
+ }
951
+ `}
952
+ `;
953
+ }};
954
+ `, Ze = z(de)`
955
+ padding: 0;
956
+ height: 2em;
957
+
958
+ svg {
959
+ circle,
960
+ line {
961
+ stroke: ${(e) => {
962
+ var t;
963
+ return e["data-has-focus"] ? (t = e.theme.colors) == null ? void 0 : t.primary : "#000000";
964
+ }};
965
+ }
966
+ }
967
+ `, _e = z(de)`
968
+ &:focus-visible svg {
969
+ ${J}
970
+ }
971
+
972
+ svg {
973
+ vertical-align: top;
974
+
975
+ circle,
976
+ line,
977
+ path {
978
+ stroke: ${(e) => {
979
+ var t, n;
980
+ return e.hasFocus ? (t = e.theme.colors) == null ? void 0 : t.primary : (n = e.theme.colors) == null ? void 0 : n.text;
981
+ }};
982
+ }
983
+ }
984
+ `;
985
+ export {
986
+ st as default
987
+ };