@telia-ace/knowledge-widget-components-search 1.0.43 → 1.0.44-next.0

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