@fluid-topics/ft-search-selected-facets 1.3.31 → 1.3.32
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,9 +1,10 @@
|
|
|
1
|
-
import { nothing } from "lit";
|
|
2
|
-
import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
|
|
1
|
+
import { nothing, PropertyValues } from "lit";
|
|
2
|
+
import { Debouncer, ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
|
|
3
3
|
import { FtSearchSelectedFacetsProperties } from "./ft-search-selected-facets.properties";
|
|
4
4
|
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
5
5
|
import { FtMetadataFilter, FtSearchFacet, FtSearchScopeKeys } from "@fluid-topics/public-api";
|
|
6
|
-
|
|
6
|
+
import { I18nAttributeValue } from "@fluid-topics/ft-i18n/build/decorators/i18nAttribute";
|
|
7
|
+
declare const FtSearchSelectedFacets_base: typeof FtSearchComponent & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface> & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-app-context").FtLitElementWithDateFormatInterface> & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-wc-utils").FtLitElementWithAriaNotificationInterface>;
|
|
7
8
|
export declare class FtSearchSelectedFacets extends FtSearchSelectedFacets_base implements FtSearchSelectedFacetsProperties {
|
|
8
9
|
static elementDefinitions: ElementDefinitionsMap;
|
|
9
10
|
static styles: import("lit").CSSResult;
|
|
@@ -15,7 +16,10 @@ export declare class FtSearchSelectedFacets extends FtSearchSelectedFacets_base
|
|
|
15
16
|
searchInDocumentTitlesOnly?: boolean;
|
|
16
17
|
filters?: FtMetadataFilter[];
|
|
17
18
|
scope?: FtSearchScopeKeys;
|
|
19
|
+
selectedFacetsAriaNotification: I18nAttributeValue;
|
|
20
|
+
protected ariaNotificationDebouncer: Debouncer;
|
|
18
21
|
get hasSomethingToDisplay(): boolean | undefined;
|
|
22
|
+
get numberOfChips(): number;
|
|
19
23
|
constructor();
|
|
20
24
|
protected render(): typeof nothing | import("lit-html").TemplateResult<1>;
|
|
21
25
|
private renderFacet;
|
|
@@ -30,5 +34,7 @@ export declare class FtSearchSelectedFacets extends FtSearchSelectedFacets_base
|
|
|
30
34
|
private renderPeriodFilter;
|
|
31
35
|
private renderDateFilter;
|
|
32
36
|
private renderRangeFilter;
|
|
37
|
+
updated(props: PropertyValues): void;
|
|
38
|
+
private announceFilters;
|
|
33
39
|
}
|
|
34
40
|
export {};
|
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { html, nothing } from "lit";
|
|
8
8
|
import { property } from "lit/decorators.js";
|
|
9
9
|
import { repeat } from "lit/directives/repeat.js";
|
|
10
|
-
import { flatDeep, FocusMainContentEvent, formatHierarchicalValues, redux, shadowQuerySelectorAll } from "@fluid-topics/ft-wc-utils";
|
|
10
|
+
import { Debouncer, flatDeep, FocusMainContentEvent, formatHierarchicalValues, jsonProperty, numberProperty, redux, shadowQuerySelectorAll, withAriaNotification } from "@fluid-topics/ft-wc-utils";
|
|
11
11
|
import { styles } from "./ft-search-selected-facets.styles";
|
|
12
12
|
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
13
13
|
import { FtChip } from "@fluid-topics/ft-chip";
|
|
@@ -18,12 +18,15 @@ import { searchTypeContext, searchTypeDefaultMessages } from "@fluid-topics/ft-s
|
|
|
18
18
|
import { periodFilterContext, periodFilterDefaultMessages } from "@fluid-topics/ft-search-period-filter";
|
|
19
19
|
import { searchSelectedFacets, searchSelectedFacetsDefaultMessages } from "./FtSearchSelectedFacetsMessages";
|
|
20
20
|
import { withDateFormat } from "@fluid-topics/ft-app-context";
|
|
21
|
-
class FtSearchSelectedFacets extends withDateFormat(withI18n(FtSearchComponent)) {
|
|
21
|
+
class FtSearchSelectedFacets extends withAriaNotification(withDateFormat(withI18n(FtSearchComponent))) {
|
|
22
22
|
get hasSomethingToDisplay() {
|
|
23
23
|
var _a, _b;
|
|
24
24
|
return this.searchInDocumentTitlesOnly
|
|
25
|
-
|| ((_a = this.facets) === null || _a === void 0 ? void 0 : _a.some(facet => this.getSelectedValues(facet).length > 0))
|
|
26
|
-
|| ((_b = this.filters) === null || _b === void 0 ? void 0 : _b.some(f => f.dateFilter || f.rangeFilter));
|
|
25
|
+
|| ((_a = this.facets) === null || _a === void 0 ? void 0 : _a.some((facet) => this.getSelectedValues(facet).length > 0))
|
|
26
|
+
|| ((_b = this.filters) === null || _b === void 0 ? void 0 : _b.some((f) => f.dateFilter || f.rangeFilter));
|
|
27
|
+
}
|
|
28
|
+
get numberOfChips() {
|
|
29
|
+
return shadowQuerySelectorAll(this.shadowRoot, "ft-chip").length;
|
|
27
30
|
}
|
|
28
31
|
constructor() {
|
|
29
32
|
super();
|
|
@@ -31,6 +34,12 @@ class FtSearchSelectedFacets extends withDateFormat(withI18n(FtSearchComponent))
|
|
|
31
34
|
this.forceTooltip = false;
|
|
32
35
|
this.multiLine = false;
|
|
33
36
|
this.hierarchicalValueTruncatingLevel = 3;
|
|
37
|
+
this.selectedFacetsAriaNotification = {
|
|
38
|
+
context: "officialContext",
|
|
39
|
+
key: "searchSelectedFacetsAriaNotification",
|
|
40
|
+
message: "",
|
|
41
|
+
};
|
|
42
|
+
this.ariaNotificationDebouncer = new Debouncer(100);
|
|
34
43
|
this.addI18nContext(searchTypeContext, searchTypeDefaultMessages);
|
|
35
44
|
this.addI18nContext(searchSelectedFacets, searchSelectedFacetsDefaultMessages);
|
|
36
45
|
this.addI18nContext(periodFilterContext, periodFilterDefaultMessages);
|
|
@@ -42,12 +51,12 @@ class FtSearchSelectedFacets extends withDateFormat(withI18n(FtSearchComponent))
|
|
|
42
51
|
}
|
|
43
52
|
return html `
|
|
44
53
|
<div role="group" class="ft-search-selected-facets--container" aria-label="${searchSelectedFacets.messages.filterGroupLabel()}">
|
|
45
|
-
${repeat(this.facets || [], facet => facet.key, facet => {
|
|
54
|
+
${repeat(this.facets || [], (facet) => facet.key, (facet) => {
|
|
46
55
|
const values = this.getSelectedValues(facet);
|
|
47
|
-
return repeat(values, value => facet.key + "-" + value, value => this.renderFacet(facet.key, facet.label, values, value));
|
|
56
|
+
return repeat(values, (value) => facet.key + "-" + value, (value) => this.renderFacet(facet.key, facet.label, values, value));
|
|
48
57
|
})}
|
|
49
58
|
${this.renderSearchInDocumentTitlesOnly()}
|
|
50
|
-
${repeat((_b = (_a = this.filters) === null || _a === void 0 ? void 0 : _a.filter(f => f.dateFilter || f.rangeFilter)) !== null && _b !== void 0 ? _b : [], f => f.key, f => this.renderPeriodFilter(f))}
|
|
59
|
+
${repeat((_b = (_a = this.filters) === null || _a === void 0 ? void 0 : _a.filter((f) => f.dateFilter || f.rangeFilter)) !== null && _b !== void 0 ? _b : [], (f) => f.key, (f) => this.renderPeriodFilter(f))}
|
|
51
60
|
</div>
|
|
52
61
|
`;
|
|
53
62
|
}
|
|
@@ -68,10 +77,10 @@ class FtSearchSelectedFacets extends withDateFormat(withI18n(FtSearchComponent))
|
|
|
68
77
|
label="${label}"
|
|
69
78
|
@icon-click=${(e) => {
|
|
70
79
|
var _a;
|
|
71
|
-
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setValueFilter(facetKey, selectedValues.filter(v => v !== value));
|
|
80
|
+
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setValueFilter(facetKey, selectedValues.filter((v) => v !== value));
|
|
72
81
|
this.determineAndApplyFocus(e);
|
|
73
82
|
}}
|
|
74
|
-
?multiLine
|
|
83
|
+
?multiLine=${this.multiLine}
|
|
75
84
|
data-key="${facetKey}"
|
|
76
85
|
data-value="${value}">
|
|
77
86
|
${this.displayLabel ? html `
|
|
@@ -105,7 +114,7 @@ class FtSearchSelectedFacets extends withDateFormat(withI18n(FtSearchComponent))
|
|
|
105
114
|
const elementToFocus = this.getNextChipToFocusOn(chipElement);
|
|
106
115
|
if (elementToFocus) {
|
|
107
116
|
elementToFocus.elementToFocus = {
|
|
108
|
-
selector: `ft-button
|
|
117
|
+
selector: `ft-button`,
|
|
109
118
|
};
|
|
110
119
|
}
|
|
111
120
|
else {
|
|
@@ -114,9 +123,9 @@ class FtSearchSelectedFacets extends withDateFormat(withI18n(FtSearchComponent))
|
|
|
114
123
|
}
|
|
115
124
|
}
|
|
116
125
|
getSelectedValues(facet) {
|
|
117
|
-
return flatDeep(facet.rootNodes, n => n.selected ? [] : n.childNodes)
|
|
118
|
-
.filter(n => n.selected)
|
|
119
|
-
.map(n => n.value);
|
|
126
|
+
return flatDeep(facet.rootNodes, (n) => n.selected ? [] : n.childNodes)
|
|
127
|
+
.filter((n) => n.selected)
|
|
128
|
+
.map((n) => n.value);
|
|
120
129
|
}
|
|
121
130
|
getLabelFromValue(key, value) {
|
|
122
131
|
return this.readAndFormatValueFromFacet(key, value, this.hierarchicalValueTruncatingLevel);
|
|
@@ -154,7 +163,7 @@ class FtSearchSelectedFacets extends withDateFormat(withI18n(FtSearchComponent))
|
|
|
154
163
|
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setSearchInDocumentTitlesOnly(false);
|
|
155
164
|
this.determineAndApplyFocus(e);
|
|
156
165
|
}}
|
|
157
|
-
?multiLine
|
|
166
|
+
?multiLine=${this.multiLine}>
|
|
158
167
|
<span part="values">
|
|
159
168
|
${label}
|
|
160
169
|
</span>
|
|
@@ -190,7 +199,7 @@ class FtSearchSelectedFacets extends withDateFormat(withI18n(FtSearchComponent))
|
|
|
190
199
|
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.removeDateFilter(key);
|
|
191
200
|
this.determineAndApplyFocus(e);
|
|
192
201
|
}}
|
|
193
|
-
?multiLine
|
|
202
|
+
?multiLine=${this.multiLine}>
|
|
194
203
|
<span part="values">
|
|
195
204
|
${periodFilterContext.messages[dateFilter.type]()}
|
|
196
205
|
</span>
|
|
@@ -212,13 +221,43 @@ class FtSearchSelectedFacets extends withDateFormat(withI18n(FtSearchComponent))
|
|
|
212
221
|
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.removeRangeFilter(key);
|
|
213
222
|
this.determineAndApplyFocus(e);
|
|
214
223
|
}}
|
|
215
|
-
?multiLine
|
|
224
|
+
?multiLine=${this.multiLine}>
|
|
216
225
|
<span part="values">
|
|
217
226
|
${periodFilterContext.messages["CUSTOM"]()}
|
|
218
227
|
</span>
|
|
219
228
|
</ft-chip>
|
|
220
229
|
</ft-tooltip>`;
|
|
221
230
|
}
|
|
231
|
+
updated(props) {
|
|
232
|
+
var _a, _b, _c, _d;
|
|
233
|
+
super.updated(props);
|
|
234
|
+
if (props.get("filters")) {
|
|
235
|
+
const visibleFiltersNumber = (_b = (_a = this.filters) === null || _a === void 0 ? void 0 : _a.filter((f) => f.dateFilter || f.rangeFilter).length) !== null && _b !== void 0 ? _b : 0;
|
|
236
|
+
const oldFiltersNumber = props.get("filters").filter((f) => f.dateFilter || f.rangeFilter).length;
|
|
237
|
+
if ((visibleFiltersNumber - oldFiltersNumber == 1) || (oldFiltersNumber > 0 && !this.hasSomethingToDisplay)) {
|
|
238
|
+
this.announceFilters();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (props.get("facets")) {
|
|
242
|
+
const visibleFacetsNumber = (_d = (_c = this.facets) === null || _c === void 0 ? void 0 : _c.filter((facet) => this.getSelectedValues(facet).length > 0).length) !== null && _d !== void 0 ? _d : 0;
|
|
243
|
+
const oldFacetsNumber = props.get("facets").filter((facet) => this.getSelectedValues(facet).length > 0).length;
|
|
244
|
+
if ((visibleFacetsNumber - oldFacetsNumber == 1) || (oldFacetsNumber > 0 && !this.hasSomethingToDisplay)) {
|
|
245
|
+
this.announceFilters();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (props.has("searchInDocumentTitlesOnly")) {
|
|
249
|
+
const oldSearchInDocOnly = props.get("searchInDocumentTitlesOnly");
|
|
250
|
+
if ((!oldSearchInDocOnly && this.searchInDocumentTitlesOnly) || (oldSearchInDocOnly && !this.hasSomethingToDisplay)) {
|
|
251
|
+
this.announceFilters();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
announceFilters() {
|
|
256
|
+
this.ariaNotificationDebouncer.run(async () => {
|
|
257
|
+
const notification = await this.awaitI18n({ ...this.selectedFacetsAriaNotification, args: [this.numberOfChips] });
|
|
258
|
+
this.sendAriaNotification(notification, { checkVisibility: this.numberOfChips != 0 });
|
|
259
|
+
});
|
|
260
|
+
}
|
|
222
261
|
}
|
|
223
262
|
FtSearchSelectedFacets.elementDefinitions = {
|
|
224
263
|
"ft-chip": FtChip,
|
|
@@ -235,7 +274,7 @@ __decorate([
|
|
|
235
274
|
property({ type: Boolean })
|
|
236
275
|
], FtSearchSelectedFacets.prototype, "multiLine", void 0);
|
|
237
276
|
__decorate([
|
|
238
|
-
|
|
277
|
+
numberProperty()
|
|
239
278
|
], FtSearchSelectedFacets.prototype, "hierarchicalValueTruncatingLevel", void 0);
|
|
240
279
|
__decorate([
|
|
241
280
|
redux({ store: "search" })
|
|
@@ -249,4 +288,7 @@ __decorate([
|
|
|
249
288
|
__decorate([
|
|
250
289
|
redux({ store: "search", selector: (state) => state.request.scope })
|
|
251
290
|
], FtSearchSelectedFacets.prototype, "scope", void 0);
|
|
291
|
+
__decorate([
|
|
292
|
+
jsonProperty({ context: "officialContext", key: "searchSelectedFacetsAriaNotification" })
|
|
293
|
+
], FtSearchSelectedFacets.prototype, "selectedFacetsAriaNotification", void 0);
|
|
252
294
|
export { FtSearchSelectedFacets };
|