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