@telia-ace/knowledge-widget-components-search 1.0.4 → 1.0.9

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.
@@ -1,200 +0,0 @@
1
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
- return cooked;
4
- };
5
- var __assign = (this && this.__assign) || function () {
6
- __assign = Object.assign || function(t) {
7
- for (var s, i = 1, n = arguments.length; i < n; i++) {
8
- s = arguments[i];
9
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
- t[p] = s[p];
11
- }
12
- return t;
13
- };
14
- return __assign.apply(this, arguments);
15
- };
16
- var __read = (this && this.__read) || function (o, n) {
17
- var m = typeof Symbol === "function" && o[Symbol.iterator];
18
- if (!m) return o;
19
- var i = m.call(o), r, ar = [], e;
20
- try {
21
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
22
- }
23
- catch (error) { e = { error: error }; }
24
- finally {
25
- try {
26
- if (r && !r.done && (m = i["return"])) m.call(i);
27
- }
28
- finally { if (e) throw e.error; }
29
- }
30
- return ar;
31
- };
32
- import { ItemTree, Link, Text, useDispatch, useEventListener, useProperties, } from '@telia-ace/knowledge-widget-ui';
33
- import React, { useCallback, useEffect, useState } from 'react';
34
- import styled, { css } from 'styled-components';
35
- import { filterItems, match } from './utils';
36
- export var getFocusedIndex = function (elem) {
37
- var anchors = Array.from((elem === null || elem === void 0 ? void 0 : elem.getElementsByTagName('A')) || []).filter(function (a) { return a.getAttribute('disabled') === null; });
38
- return {
39
- anchors: anchors,
40
- focusedIndex: anchors.findIndex(function (e) { return document.activeElement === e; }),
41
- };
42
- };
43
- var getInputElem = function (searchContainerRef) {
44
- return searchContainerRef
45
- ? searchContainerRef.querySelector('[data-type="search"], input[type="search"]')
46
- : null;
47
- };
48
- export var focusInput = function (searchContainerRef) {
49
- if (!searchContainerRef) {
50
- return;
51
- }
52
- var inputElem = getInputElem(searchContainerRef);
53
- if (inputElem) {
54
- inputElem.focus();
55
- }
56
- };
57
- var QuickFilterItemList = function (_a) {
58
- var filterPhrase = _a.filterPhrase, rawItems = _a.items, filterType = _a.filterType, filterContainer = _a.filterContainer, searchContainer = _a.searchContainer, inputHasFocus = _a.inputHasFocus;
59
- var _b = __read(useState(rawItems || []), 2), items = _b[0], setItems = _b[1];
60
- var _c = __read(useState(null), 2), first = _c[0], setFirst = _c[1];
61
- var dispatch = useDispatch();
62
- var _d = useProperties(), activeFilterBadges = _d.activeFilterBadges, quickFilters = _d.quickFilters;
63
- var autoSelect = (typeof quickFilters === 'object' && !!quickFilters.autoSelect) ||
64
- (typeof quickFilters === 'boolean' && !!quickFilters);
65
- useEffect(function () {
66
- setItems(filterItems(rawItems, filterType, filterPhrase));
67
- }, [filterPhrase, filterType, rawItems]);
68
- useEffect(function () {
69
- var _a;
70
- if (filterContainer) {
71
- var anchors = getFocusedIndex(filterContainer).anchors;
72
- var id = (_a = anchors[0]) === null || _a === void 0 ? void 0 : _a.getAttribute('data-id');
73
- if (id) {
74
- setFirst(id);
75
- }
76
- }
77
- }, [items, filterContainer]);
78
- var handleItemClicked = useCallback(function (item, type) {
79
- var data = {
80
- category: (activeFilterBadges === null || activeFilterBadges === void 0 ? void 0 : activeFilterBadges.guideCategory)
81
- ? activeFilterBadges.guideCategory.id
82
- : undefined,
83
- tag: (activeFilterBadges === null || activeFilterBadges === void 0 ? void 0 : activeFilterBadges.tag) ? activeFilterBadges.tag.id : undefined,
84
- };
85
- if (type === 'guideCategory') {
86
- data.category = item.id;
87
- }
88
- else if (type === 'tag') {
89
- data.tag = item.id;
90
- }
91
- dispatch('quick-filter:add', data);
92
- }, [activeFilterBadges, dispatch]);
93
- var buildListProps = function (type) {
94
- if (type === 'guideCategory') {
95
- return {
96
- renderItem: function (item, level) { return (React.createElement(StyledLink, { autoSelect: autoSelect && inputHasFocus && item.id === first, disabled: !match(item.title, filterPhrase), tabIndex: !match(item.title, filterPhrase) ? -1 : 0, onKeyDown: function (e) {
97
- if (e.key === 'Enter') {
98
- handleItemClicked(item, type);
99
- }
100
- }, "data-level": level, onClick: function () {
101
- handleItemClicked(item, type);
102
- }, "data-id": item.id },
103
- React.createElement(Title, { title: item.title, phrase: filterPhrase, matches: match(item.title, filterPhrase) }))); },
104
- };
105
- }
106
- return {
107
- renderLi: true,
108
- renderItem: function (item) { return (React.createElement(StyledLink, { autoSelect: autoSelect && inputHasFocus && item.id === first, onKeyDown: function (e) {
109
- if (e.key === 'Enter') {
110
- handleItemClicked(item, type);
111
- }
112
- }, onClick: function () {
113
- handleItemClicked(item, type);
114
- }, "data-id": item.id },
115
- React.createElement(Title, { symbol: "#", title: item.title, phrase: filterPhrase, matches: match(item.title, filterPhrase) }))); },
116
- };
117
- };
118
- useEventListener('keydown', function (e) {
119
- var _a;
120
- var key = e.key;
121
- if (!filterContainer ||
122
- !(key === 'ArrowDown' || key === 'ArrowUp' || key === 'Enter')) {
123
- return;
124
- }
125
- var _b = getFocusedIndex(filterContainer), anchors = _b.anchors, focusedIndex = _b.focusedIndex;
126
- if (key === 'Enter') {
127
- if (inputHasFocus && autoSelect) {
128
- var id = (_a = anchors[0]) === null || _a === void 0 ? void 0 : _a.getAttribute('data-id');
129
- if (id) {
130
- handleItemClicked({ id: id }, filterType);
131
- }
132
- }
133
- return;
134
- }
135
- var focusFirst = function () { var _a; return (_a = anchors[0]) === null || _a === void 0 ? void 0 : _a.focus(); };
136
- var focusLast = function () { var _a; return (_a = anchors[anchors.length - 1]) === null || _a === void 0 ? void 0 : _a.focus(); };
137
- var focusNext = function () { var _a; return (_a = anchors[focusedIndex + 1]) === null || _a === void 0 ? void 0 : _a.focus(); };
138
- var focusPrev = function () { var _a; return (_a = anchors[focusedIndex - 1]) === null || _a === void 0 ? void 0 : _a.focus(); };
139
- if (inputHasFocus) {
140
- // Input is focused
141
- e.preventDefault();
142
- if (key === 'ArrowDown') {
143
- focusFirst();
144
- }
145
- else {
146
- focusLast();
147
- }
148
- }
149
- else if (focusedIndex > -1) {
150
- // A quick-filter-item is focused
151
- e.preventDefault();
152
- if (key === 'ArrowDown') {
153
- if (anchors.length > focusedIndex + 1) {
154
- focusNext();
155
- }
156
- else {
157
- focusInput(searchContainer);
158
- }
159
- }
160
- else {
161
- if (focusedIndex - 1 < 0) {
162
- focusInput(searchContainer);
163
- }
164
- else {
165
- focusPrev();
166
- }
167
- }
168
- }
169
- }, window);
170
- return (React.createElement(ItemTree, __assign({ tree: items, renderEmpty: false, ulProps: { role: 'listbox' }, liProps: { role: 'option' } }, buildListProps(filterType))));
171
- };
172
- export default QuickFilterItemList;
173
- var Title = function (_a) {
174
- var title = _a.title, phrase = _a.phrase, matches = _a.matches, _b = _a.symbol, symbol = _b === void 0 ? '' : _b;
175
- var createTitle = function () {
176
- if (!matches || !phrase) {
177
- return [title];
178
- }
179
- var index = title.toLowerCase().indexOf(phrase.toLowerCase());
180
- var start = title.substr(0, index);
181
- var bold = title.slice(index, index + phrase.length);
182
- var end = title.substr(index + phrase.length);
183
- return [start, bold, end];
184
- };
185
- var _c = __read(createTitle(), 3), start = _c[0], bold = _c[1], end = _c[2];
186
- return (React.createElement(Text, null,
187
- symbol,
188
- start,
189
- bold ? React.createElement("strong", null, bold) : null,
190
- end ? end : null));
191
- };
192
- var disabledCss = css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n opacity: 0.5;\n pointer-events: none;\n"], ["\n opacity: 0.5;\n pointer-events: none;\n"])));
193
- var focused = css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n background-color: ", ";\n color: #ffffff;\n outline: none;\n\n span:first-child {\n border-color: ", ";\n }\n"], ["\n background-color: ", ";\n color: #ffffff;\n outline: none;\n\n span:first-child {\n border-color: ", ";\n }\n"])), function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.text; }, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.text; });
194
- var StyledLink = styled(Link)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n display: block;\n text-decoration: none;\n font-size: ", ";\n\n ", "\n color: ", ";\n background-color: transparent;\n\n span {\n display: block;\n ", "\n ", "\n }\n\n span:first-child {\n border-color: #e7e7e7;\n }\n\n ", "\n\n ", "\n\n &:hover,\n &:focus {\n ", "\n }\n"], ["\n display: block;\n text-decoration: none;\n font-size: ", ";\n\n ", "\n color: ", ";\n background-color: transparent;\n\n span {\n display: block;\n ", "\n ", "\n }\n\n span:first-child {\n border-color: #e7e7e7;\n }\n\n ", "\n\n ", "\n\n &:hover,\n &:focus {\n ", "\n }\n"])), function (p) { var _a; return (_a = p.theme.fonts) === null || _a === void 0 ? void 0 : _a.normal; }, function (p) { return p.disabled && disabledCss; }, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.text; }, function (p) {
195
- var _a, _b, _c, _d;
196
- return p['data-level']
197
- ? "padding: calc(".concat((_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.normal, " / 2) ").concat((_b = p.theme.sizes) === null || _b === void 0 ? void 0 : _b.normal, ";")
198
- : "padding: calc(".concat((_c = p.theme.sizes) === null || _c === void 0 ? void 0 : _c.normal, " / 2) ").concat((_d = p.theme.sizes) === null || _d === void 0 ? void 0 : _d.medium, "; ");
199
- }, function (p) { return p['data-level'] && 'border-left: 2px solid'; }, function (p) { var _a; return p['data-level'] && "padding: 0 calc(".concat((_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium, " * ").concat(p['data-level'], ");"); }, function (p) { return p.autoSelect && focused; }, focused);
200
- var templateObject_1, templateObject_2, templateObject_3;
@@ -1,65 +0,0 @@
1
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
- return cooked;
4
- };
5
- var __read = (this && this.__read) || function (o, n) {
6
- var m = typeof Symbol === "function" && o[Symbol.iterator];
7
- if (!m) return o;
8
- var i = m.call(o), r, ar = [], e;
9
- try {
10
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
11
- }
12
- catch (error) { e = { error: error }; }
13
- finally {
14
- try {
15
- if (r && !r.done && (m = i["return"])) m.call(i);
16
- }
17
- finally { if (e) throw e.error; }
18
- }
19
- return ar;
20
- };
21
- import { contentBox, Loader, useContainer, useProperties, useScroll, } from '@telia-ace/knowledge-widget-ui';
22
- import { appendClassNames } from '@telia-ace/widget-utilities';
23
- import React, { useCallback, useRef } from 'react';
24
- import styled from 'styled-components';
25
- import QuickFilterItemList, { focusInput, getFocusedIndex } from './quick-filter-item-list';
26
- export default (function (_a) {
27
- var _b = _a.phrase, phrase = _b === void 0 ? '' : _b, inputHasFocus = _a.inputHasFocus, searchContainerRef = _a.searchContainerRef;
28
- var _c = useProperties().quickFilter, quickFilter = _c === void 0 ? {
29
- open: false,
30
- loading: false,
31
- symbol: '',
32
- type: '',
33
- items: [],
34
- } : _c;
35
- var _d = __read(useScroll(true), 2), css = _d[0], ref = _d[1];
36
- var container = useContainer();
37
- var events = container.get('$widget').events;
38
- var wrapperRef = useRef();
39
- var setWrapperRef = useCallback(function (node) {
40
- if (node) {
41
- node.addEventListener('keydown', function () {
42
- var listItemFocused = getFocusedIndex(node).focusedIndex > -1;
43
- if (listItemFocused) {
44
- events.subscribeOnce('router:changed', function () {
45
- focusInput(searchContainerRef);
46
- });
47
- }
48
- }, true);
49
- }
50
- wrapperRef.current = node;
51
- return node;
52
- }, [searchContainerRef]);
53
- var _e = quickFilter.items, items = _e === void 0 ? [] : _e, symbol = quickFilter.symbol, type = quickFilter.type, open = quickFilter.open, loading = quickFilter.loading;
54
- if (!open || !symbol) {
55
- return null;
56
- }
57
- var filterPhrase = phrase.slice(phrase.indexOf(symbol) + 1);
58
- return (React.createElement(Wrapper, { ref: setWrapperRef, "data-loading": loading, className: appendClassNames('humany-quick-filter-dropdown', [type === 'guideCategory', 'humany-quick-filter-guide-categories'], [type === 'tag', 'humany-quick-filter-tags']) },
59
- React.createElement(Inner, { className: "humany-quick-filter-dropdown-inner", css: css, ref: ref },
60
- React.createElement(QuickFilterItemList, { filterType: type, items: items, filterPhrase: filterPhrase, filterContainer: ref.current, searchContainer: searchContainerRef, inputHasFocus: inputHasFocus })),
61
- React.createElement(Loader, { loading: loading })));
62
- });
63
- var Wrapper = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", ";\n position: absolute;\n top: calc(100% + ", ");\n left: 0;\n right: 0;\n z-index: 1;\n overflow: hidden;\n"], ["\n ", ";\n position: absolute;\n top: calc(100% + ", ");\n left: 0;\n right: 0;\n z-index: 1;\n overflow: hidden;\n"])), contentBox, function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.normal; });
64
- var Inner = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n max-height: 300px;\n overflow: auto;\n padding: ", " 0;\n ", "\n ul {\n list-style: none;\n padding: 0;\n margin: 0;\n }\n li div {\n ", "\n }\n"], ["\n max-height: 300px;\n overflow: auto;\n padding: ", " 0;\n ", "\n ul {\n list-style: none;\n padding: 0;\n margin: 0;\n }\n li div {\n ", "\n }\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; }, function (p) { return p.css; }, function (p) { var _a; return "margin: ".concat((_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.normal, " 0;"); });
65
- var templateObject_1, templateObject_2;
@@ -1,249 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __read = (this && this.__read) || function (o, n) {
13
- var m = typeof Symbol === "function" && o[Symbol.iterator];
14
- if (!m) return o;
15
- var i = m.call(o), r, ar = [], e;
16
- try {
17
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
- }
19
- catch (error) { e = { error: error }; }
20
- finally {
21
- try {
22
- if (r && !r.done && (m = i["return"])) m.call(i);
23
- }
24
- finally { if (e) throw e.error; }
25
- }
26
- return ar;
27
- };
28
- import { createEventSubscriber } from '@telia-ace/knowledge-widget-core';
29
- import { DataType, } from '@telia-ace/knowledge-widget-types-grid';
30
- import { createReactComponent } from '@telia-ace/knowledge-widget-ui';
31
- import { categoryTrail, createParams, deepClone, findCategoryById, getCategoryTrailAsObjects, } from '@telia-ace/widget-utilities';
32
- var hasActiveFilterBadge = function (filters) {
33
- return !!filters.guideCategory || !!filters.tag;
34
- };
35
- var getTooltip = function (categoryId, categories) {
36
- var trailIds = categoryTrail(categoryId, categories);
37
- var categoryMap = getCategoryTrailAsObjects(trailIds, categories);
38
- var trail = trailIds.map(function (id) { var _a; return ((_a = categoryMap.get(id)) === null || _a === void 0 ? void 0 : _a.title) || ''; }).join(' / ');
39
- return trail;
40
- };
41
- var sortRecursive = function (items) {
42
- var clone = deepClone(items);
43
- clone.sort(function (a, b) {
44
- if (a.title > b.title) {
45
- return 1;
46
- }
47
- return -1;
48
- });
49
- clone.forEach(function (item) {
50
- if (item.items) {
51
- item.items = sortRecursive(item.items);
52
- }
53
- });
54
- return clone;
55
- };
56
- var SearchComponent = function (container) {
57
- return createReactComponent(container, 'search', import('./search'), function (component) {
58
- var events = container.get('$widget').events;
59
- var _a = __read(createEventSubscriber(events), 2), subscribe = _a[0], unsubscribe = _a[1];
60
- var load = function (params) {
61
- var _a, _b;
62
- var activeFilterBadges = component.properties().activeFilterBadges;
63
- if (((_a = activeFilterBadges === null || activeFilterBadges === void 0 ? void 0 : activeFilterBadges.guideCategory) === null || _a === void 0 ? void 0 : _a.id) !== params.guideCategory ||
64
- ((_b = activeFilterBadges === null || activeFilterBadges === void 0 ? void 0 : activeFilterBadges.tag) === null || _b === void 0 ? void 0 : _b.id) !== params.tag) {
65
- component.actions.dispatch('quick-filter:add', {
66
- tag: params.tag,
67
- category: params.guideCategory,
68
- initial: true,
69
- });
70
- }
71
- };
72
- component.actions.create('search', function (data) {
73
- var value = data.value, filters = data.filters, filtersChanged = data.filtersChanged;
74
- var _a = component.properties(), _b = _a.route, route = _b === void 0 ? 'search' : _b, _c = _a.patchParams, patchParams = _c === void 0 ? false : _c;
75
- if (value.length > 0 ||
76
- ((hasActiveFilterBadge(filters) || filtersChanged) && !(filters === null || filters === void 0 ? void 0 : filters.initial))) {
77
- container.getAsync('router').then(function (router) {
78
- var _a, _b;
79
- var params = router.getRouteData().params;
80
- var searchParams = {
81
- guide: undefined,
82
- id: undefined,
83
- accordion: undefined,
84
- contactMethod: undefined,
85
- };
86
- searchParams.phrase = value.length > 0 ? encodeURIComponent(value) : '';
87
- if (patchParams) {
88
- searchParams = __assign(__assign({}, params), searchParams);
89
- }
90
- if ((filters === null || filters === void 0 ? void 0 : filters.guideCategory) || filtersChanged) {
91
- searchParams.guideCategory = ((_a = filters.guideCategory) === null || _a === void 0 ? void 0 : _a.id) || undefined;
92
- }
93
- if ((filters === null || filters === void 0 ? void 0 : filters.tag) || filtersChanged) {
94
- searchParams.tag = ((_b = filters.tag) === null || _b === void 0 ? void 0 : _b.id) || undefined;
95
- }
96
- router.navigate(route, createParams(searchParams));
97
- });
98
- }
99
- });
100
- component.actions.create('clear', function (data, options) {
101
- if (data.navigateToHome) {
102
- container.getAsync('router').then(function (router) {
103
- var name = router.getInitialRoute().name;
104
- router.navigate(name);
105
- });
106
- }
107
- });
108
- var getRouterParams = function () {
109
- return container
110
- .getAsync('router')
111
- .then(function (router) { return router.getRouteData().params; });
112
- };
113
- component.actions.create('quick-filter:add', function (data) {
114
- var category = data.category, tag = data.tag, initial = data.initial;
115
- var previous = component.properties().activeFilterBadges;
116
- var activeFilterBadges = previous || {
117
- initial: initial,
118
- guideCategory: null,
119
- tag: null,
120
- tooltip: null,
121
- };
122
- return Promise.resolve()
123
- .then(function () {
124
- if (category) {
125
- return fetchCategories({}).then(function (categories) {
126
- var categoryItem = findCategoryById(category, categories) || null;
127
- return __assign(__assign({}, activeFilterBadges), { guideCategory: categoryItem, tooltip: getTooltip(category, categories) || null });
128
- });
129
- }
130
- return __assign(__assign({}, activeFilterBadges), { guideCategory: null, tooltip: null });
131
- })
132
- .then(function (next) {
133
- if (tag) {
134
- return fetchTags({}).then(function (tags) {
135
- return __assign(__assign({}, next), { tag: tags.find(function (t) { return t.id === tag; }) || null });
136
- });
137
- }
138
- return __assign(__assign({}, next), { tag: null });
139
- })
140
- .then(function (next) {
141
- return component.writeProperties({
142
- activeFilterBadges: __assign(__assign({}, next), { initial: !!initial }),
143
- });
144
- });
145
- });
146
- component.actions.create('quick-filter:remove', function (_a) {
147
- var types = _a.types;
148
- var activeFilterBadges = component.properties().activeFilterBadges;
149
- component.writeProperties({
150
- activeFilterBadges: __assign(__assign({}, activeFilterBadges), { initial: false, guideCategory: types.indexOf('guideCategory') > -1
151
- ? null
152
- : activeFilterBadges === null || activeFilterBadges === void 0 ? void 0 : activeFilterBadges.guideCategory, tag: types.indexOf('tag') > -1 ? null : activeFilterBadges === null || activeFilterBadges === void 0 ? void 0 : activeFilterBadges.tag }),
153
- });
154
- });
155
- component.actions.create('quick-filter:close', function () {
156
- return component.writeProperties({
157
- quickFilter: {
158
- items: [],
159
- loading: false,
160
- open: false,
161
- },
162
- });
163
- });
164
- component.actions.create('quick-filter:open', function (_a) {
165
- var symbol = _a.symbol, type = _a.type;
166
- component.writeProperties({
167
- quickFilter: {
168
- type: type,
169
- symbol: symbol,
170
- items: [],
171
- loading: true,
172
- open: true,
173
- },
174
- });
175
- return getRouterParams().then(function (_a) {
176
- var tag = _a.tag, guideCategory = _a.guideCategory, phrase = _a.phrase;
177
- if (type === 'guideCategory') {
178
- return fetchCategories({
179
- tagId: tag,
180
- searchPhrase: phrase,
181
- }).then(function (items) {
182
- var clone = deepClone(items);
183
- component.writeProperties({
184
- quickFilter: {
185
- items: sortRecursive(clone),
186
- loading: false,
187
- },
188
- });
189
- });
190
- }
191
- if (type === 'tag') {
192
- return fetchTags({
193
- categories: guideCategory,
194
- searchPhrase: phrase,
195
- }).then(function (items) {
196
- var clone = deepClone(items);
197
- component.writeProperties({
198
- quickFilter: {
199
- items: sortRecursive(clone),
200
- loading: false,
201
- },
202
- });
203
- });
204
- }
205
- });
206
- });
207
- var fetchCategories = function (params) {
208
- return container
209
- .getAsync('dataClient')
210
- .then(function (dataClient) {
211
- return dataClient.fetch(DataType.GuideCategories, params);
212
- })
213
- .then(function (categoriesResult) { return categoriesResult.categories || []; });
214
- };
215
- var fetchTags = function (params) {
216
- return container
217
- .getAsync('dataClient')
218
- .then(function (dataClient) { return dataClient.fetch(DataType.TagsOnGuides, params); })
219
- .then(function (tags) {
220
- if (tags === void 0) { tags = []; }
221
- return tags;
222
- });
223
- };
224
- getRouterParams().then(function (params) {
225
- load(params);
226
- });
227
- subscribe('router:changed', function (_, _a) {
228
- var current = _a.current;
229
- var params = current.routeData.params;
230
- load(params);
231
- });
232
- subscribe('data-client:fetched', function (event, data) {
233
- var filterBadges = component.properties().filterBadges;
234
- var showTag = typeof filterBadges === 'object' ? !!filterBadges.tag : !!filterBadges;
235
- if (data.type === 'match' && showTag) {
236
- getRouterParams().then(function (_a) {
237
- var tagId = _a.tag;
238
- var _b = data.response.tags, tags = _b === void 0 ? [] : _b;
239
- var tag = tags.find(function (t) { return t.id === tagId; }) || null;
240
- component.writeProperties({ filters: { tag: tag } });
241
- });
242
- }
243
- });
244
- return function () {
245
- unsubscribe();
246
- };
247
- });
248
- };
249
- export default SearchComponent;