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