@fluid-topics/ft-search-result-metadata 1.1.12 → 1.1.13
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/build/SearchResultMetadataMessages.d.ts +1 -0
- package/build/ft-search-result-metadata.css.js +11 -0
- package/build/ft-search-result-metadata.d.ts +16 -1
- package/build/ft-search-result-metadata.js +127 -10
- package/build/ft-search-result-metadata.light.js +405 -248
- package/build/ft-search-result-metadata.min.js +457 -284
- package/build/ft-search-result-metadata.properties.d.ts +2 -0
- package/package.json +7 -6
|
@@ -2,5 +2,6 @@ import { I18nMessageContext, I18nMessages } from "@fluid-topics/ft-i18n";
|
|
|
2
2
|
export interface SearchResultMetadataMessages extends I18nMessages {
|
|
3
3
|
noKeySelected(): string;
|
|
4
4
|
noValuePresent(key: string): string;
|
|
5
|
+
noValueInCluster(): string;
|
|
5
6
|
}
|
|
6
7
|
export declare const searchResultMetadataContext: I18nMessageContext<SearchResultMetadataMessages>;
|
|
@@ -2,4 +2,15 @@ import { css } from "lit";
|
|
|
2
2
|
export const FtSearchResultMetadataCssVariables = {};
|
|
3
3
|
// language=CSS
|
|
4
4
|
export const styles = css `
|
|
5
|
+
.ft-search-result-metadata--container {
|
|
6
|
+
position: relative;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.ft-search-result-metadata--container ft-chip {
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
a {
|
|
14
|
+
all: unset;
|
|
15
|
+
}
|
|
5
16
|
`;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PropertyValues } from "lit";
|
|
2
2
|
import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
|
|
3
3
|
import { FtSearchResultMetadataProperties } from "./ft-search-result-metadata.properties";
|
|
4
|
+
import type { FtSearchResultStateManager } from "@fluid-topics/ft-search-result-context/build/registration";
|
|
4
5
|
import { FtSearchResultComponent } from "@fluid-topics/ft-search-result-context/build/registration";
|
|
5
6
|
declare const FtSearchResultMetadata_base: typeof FtSearchResultComponent & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>;
|
|
6
7
|
export declare class FtSearchResultMetadata extends FtSearchResultMetadata_base implements FtSearchResultMetadataProperties {
|
|
@@ -8,19 +9,33 @@ export declare class FtSearchResultMetadata extends FtSearchResultMetadata_base
|
|
|
8
9
|
static styles: import("lit").CSSResult;
|
|
9
10
|
key?: string;
|
|
10
11
|
useChip?: boolean;
|
|
12
|
+
useAsClusterSwitch?: boolean;
|
|
13
|
+
goToDocumentOnSwitch?: boolean;
|
|
11
14
|
/**
|
|
12
15
|
* @deprecated Use CSS
|
|
13
16
|
*/
|
|
14
17
|
maxLength?: number;
|
|
15
18
|
private editorMode;
|
|
16
|
-
private
|
|
19
|
+
private resultMetadata?;
|
|
20
|
+
private metadataLabel?;
|
|
21
|
+
private computedClusters;
|
|
17
22
|
constructor();
|
|
23
|
+
setResultStateManager(resultStateManager: FtSearchResultStateManager): void;
|
|
18
24
|
protected render(): import("lit").TemplateResult<1>;
|
|
25
|
+
private renderClusterList;
|
|
26
|
+
private onClusterSelected;
|
|
27
|
+
private computeClusters;
|
|
28
|
+
private renderClusterItem;
|
|
29
|
+
private renderClusterItemValue;
|
|
30
|
+
private onResultClick;
|
|
31
|
+
private renderChip;
|
|
19
32
|
private renderContent;
|
|
33
|
+
private get displayCluster();
|
|
20
34
|
private getEllipsis;
|
|
21
35
|
protected update(props: PropertyValues): void;
|
|
22
36
|
private get resultData();
|
|
23
37
|
private get valueText();
|
|
24
38
|
private get tooltipText();
|
|
39
|
+
private findClusterMetadataLabel;
|
|
25
40
|
}
|
|
26
41
|
export {};
|
|
@@ -14,30 +14,96 @@ import { withI18n } from "@fluid-topics/ft-i18n";
|
|
|
14
14
|
import { searchResultMetadataContext } from "./SearchResultMetadataMessages";
|
|
15
15
|
import { FtTooltip } from "@fluid-topics/ft-tooltip";
|
|
16
16
|
import { FtChip } from "@fluid-topics/ft-chip";
|
|
17
|
+
import { FtFloatingMenu, FtFloatingMenuItem, FtFloatingMenuLabel } from "@fluid-topics/ft-floating-menu";
|
|
18
|
+
import { getResultUrl, SearchResultClickEvent } from "@fluid-topics/ft-search-result-context/build/utils";
|
|
19
|
+
import { ClusteringHelper } from "@fluid-topics/ft-search-result-context/build/ClusteringHelper";
|
|
20
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
17
21
|
class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
|
|
18
22
|
constructor() {
|
|
19
23
|
super();
|
|
20
24
|
this.useChip = false;
|
|
25
|
+
this.useAsClusterSwitch = false;
|
|
26
|
+
this.goToDocumentOnSwitch = false;
|
|
21
27
|
this.editorMode = false;
|
|
28
|
+
this.computedClusters = {};
|
|
22
29
|
this.addStore(ftAppInfoStore);
|
|
23
30
|
this.addI18nContext(searchResultMetadataContext);
|
|
24
31
|
}
|
|
32
|
+
setResultStateManager(resultStateManager) {
|
|
33
|
+
super.setResultStateManager(resultStateManager);
|
|
34
|
+
if (this.key && this.useAsClusterSwitch) {
|
|
35
|
+
resultStateManager.registerMetadata(this.key);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
25
38
|
render() {
|
|
39
|
+
return this.displayCluster ? this.renderClusterList() : this.renderChip();
|
|
40
|
+
}
|
|
41
|
+
renderClusterList() {
|
|
42
|
+
return html `
|
|
43
|
+
<div class="ft-search-result-metadata--container">
|
|
44
|
+
<ft-floating-menu icon="THIN_ARROW"
|
|
45
|
+
@select=${this.onClusterSelected}
|
|
46
|
+
slot="button">
|
|
47
|
+
${this.renderChip("toggle")}
|
|
48
|
+
<ft-floating-menu-label>${this.metadataLabel}</ft-floating-menu-label>
|
|
49
|
+
${repeat(Object.entries(this.computedClusters), ([value, _]) => value, ([value, item]) => this.renderClusterItem(item.result, item.metadata))}
|
|
50
|
+
</ft-floating-menu>
|
|
51
|
+
</div>
|
|
52
|
+
`;
|
|
53
|
+
}
|
|
54
|
+
onClusterSelected(e) {
|
|
55
|
+
var _a;
|
|
56
|
+
(_a = this.resultStateManager) === null || _a === void 0 ? void 0 : _a.selectResult(this.computedClusters[e.detail].result);
|
|
57
|
+
}
|
|
58
|
+
computeClusters() {
|
|
59
|
+
const newClusters = {};
|
|
60
|
+
const clusteringHelper = new ClusteringHelper(this.cluster, this.result, this.resultStateManager.registeredMetadata);
|
|
61
|
+
clusteringHelper.computeClustersItemsForMetadata(this.key)
|
|
62
|
+
.forEach(item => {
|
|
63
|
+
newClusters[item.metadata.value] = item;
|
|
64
|
+
});
|
|
65
|
+
this.computedClusters = newClusters;
|
|
66
|
+
}
|
|
67
|
+
renderClusterItem(result, metadata) {
|
|
68
|
+
if (this.goToDocumentOnSwitch) {
|
|
69
|
+
return html `
|
|
70
|
+
<a href="${getResultUrl(result)}" @click=${() => this.onResultClick(result)}>
|
|
71
|
+
<ft-floating-menu-item value="${metadata.value}">${this.renderClusterItemValue(metadata.value, metadata.displayValue)}
|
|
72
|
+
</ft-floating-menu-item>
|
|
73
|
+
</a>
|
|
74
|
+
`;
|
|
75
|
+
}
|
|
76
|
+
return html `
|
|
77
|
+
<ft-floating-menu-item value="${metadata.value}">${this.renderClusterItemValue(metadata.value, metadata.displayValue)}</ft-floating-menu-item>
|
|
78
|
+
`;
|
|
79
|
+
}
|
|
80
|
+
renderClusterItemValue(value, displayValue) {
|
|
81
|
+
return value === displayValue ? html `${value}` : html `
|
|
82
|
+
<ft-tooltip text="${value}">${displayValue}</ft-tooltip>
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
onResultClick(result) {
|
|
86
|
+
this.dispatchEvent(new SearchResultClickEvent(result, this.rank));
|
|
87
|
+
}
|
|
88
|
+
renderChip(slot) {
|
|
26
89
|
if (this.useChip) {
|
|
27
90
|
return html `
|
|
28
|
-
<ft-tooltip text="${this.tooltipText}">
|
|
29
|
-
<ft-chip>${this.renderContent()}</ft-chip>
|
|
91
|
+
<ft-tooltip text="${this.tooltipText}" slot="${slot}">
|
|
92
|
+
<ft-chip icon="${this.displayCluster ? "THIN_ARROW" : ""}" trailingIcon>${this.renderContent()}</ft-chip>
|
|
30
93
|
</ft-tooltip>
|
|
31
94
|
`;
|
|
32
95
|
}
|
|
33
96
|
else {
|
|
34
|
-
return html
|
|
97
|
+
return html `<span slot=${slot}>${this.renderContent()}</span>`;
|
|
35
98
|
}
|
|
36
99
|
}
|
|
37
100
|
renderContent() {
|
|
38
|
-
if (this.
|
|
101
|
+
if (this.resultMetadata) {
|
|
39
102
|
return html `${this.getEllipsis(this.valueText)}`;
|
|
40
103
|
}
|
|
104
|
+
if (this.useAsClusterSwitch && Object.keys(this.computedClusters).length > 0) {
|
|
105
|
+
return html `${searchResultMetadataContext.messages.noValueInCluster()}`;
|
|
106
|
+
}
|
|
41
107
|
if (this.editorMode) {
|
|
42
108
|
if (this.key) {
|
|
43
109
|
return html `${searchResultMetadataContext.messages.noValuePresent(this.key)}`;
|
|
@@ -54,15 +120,41 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
|
|
|
54
120
|
</style>
|
|
55
121
|
`;
|
|
56
122
|
}
|
|
123
|
+
get displayCluster() {
|
|
124
|
+
var _a, _b;
|
|
125
|
+
return this.useAsClusterSwitch
|
|
126
|
+
&& ((_b = (_a = this.cluster) === null || _a === void 0 ? void 0 : _a.entries.length) !== null && _b !== void 0 ? _b : 0) > 1;
|
|
127
|
+
}
|
|
57
128
|
getEllipsis(text) {
|
|
58
129
|
let cutText = this.maxLength ? text.substring(0, this.maxLength) : text;
|
|
59
130
|
return cutText + (cutText.length < text.length ? "…" : "");
|
|
60
131
|
}
|
|
61
132
|
update(props) {
|
|
62
|
-
var _a;
|
|
133
|
+
var _a, _b, _c, _d, _e;
|
|
63
134
|
super.update(props);
|
|
64
135
|
if ((props.has("result") || props.has("key")) && this.result) {
|
|
65
|
-
this.
|
|
136
|
+
this.resultMetadata = (_a = this.resultData) === null || _a === void 0 ? void 0 : _a.metadata.find(m => m.key == this.key);
|
|
137
|
+
this.metadataLabel = this.findClusterMetadataLabel();
|
|
138
|
+
}
|
|
139
|
+
if (props.has("key") && this.useAsClusterSwitch) {
|
|
140
|
+
if (props.get("key")) {
|
|
141
|
+
(_b = this.resultStateManager) === null || _b === void 0 ? void 0 : _b.unregisterMetadata(props.get("key"));
|
|
142
|
+
}
|
|
143
|
+
if (this.key) {
|
|
144
|
+
(_c = this.resultStateManager) === null || _c === void 0 ? void 0 : _c.registerMetadata(this.key);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (props.has("useAsCluster") && this.key) {
|
|
148
|
+
if (this.useAsClusterSwitch) {
|
|
149
|
+
(_d = this.resultStateManager) === null || _d === void 0 ? void 0 : _d.registerMetadata(this.key);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
(_e = this.resultStateManager) === null || _e === void 0 ? void 0 : _e.unregisterMetadata(this.key);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if ((props.has("cluster") || props.has("result") || props.has("key") || props.has("useAsCluster"))
|
|
156
|
+
&& this.cluster && this.result && this.key && this.useAsClusterSwitch) {
|
|
157
|
+
this.computeClusters();
|
|
66
158
|
}
|
|
67
159
|
}
|
|
68
160
|
get resultData() {
|
|
@@ -71,16 +163,29 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
|
|
|
71
163
|
}
|
|
72
164
|
get valueText() {
|
|
73
165
|
var _a, _b;
|
|
74
|
-
return (_b = (_a = this.
|
|
166
|
+
return (_b = (_a = this.resultMetadata) === null || _a === void 0 ? void 0 : _a.values.join(", ")) !== null && _b !== void 0 ? _b : "";
|
|
75
167
|
}
|
|
76
168
|
get tooltipText() {
|
|
77
|
-
|
|
78
|
-
|
|
169
|
+
if (this.resultMetadata) {
|
|
170
|
+
return `${this.metadataLabel}: ${this.valueText}`;
|
|
171
|
+
}
|
|
172
|
+
if (this.useAsClusterSwitch) {
|
|
173
|
+
return `${this.metadataLabel}: ${searchResultMetadataContext.messages.noValueInCluster()}`;
|
|
174
|
+
}
|
|
175
|
+
return "";
|
|
176
|
+
}
|
|
177
|
+
findClusterMetadataLabel() {
|
|
178
|
+
var _a;
|
|
179
|
+
const metadata = (_a = this.cluster) === null || _a === void 0 ? void 0 : _a.entries.flatMap(result => { var _a, _b; return ((_b = (_a = result === null || result === void 0 ? void 0 : result.map) !== null && _a !== void 0 ? _a : result === null || result === void 0 ? void 0 : result.document) !== null && _b !== void 0 ? _b : result === null || result === void 0 ? void 0 : result.topic).metadata.filter(m => m.key == this.key); })[0];
|
|
180
|
+
return metadata === null || metadata === void 0 ? void 0 : metadata.label;
|
|
79
181
|
}
|
|
80
182
|
}
|
|
81
183
|
FtSearchResultMetadata.elementDefinitions = {
|
|
82
184
|
"ft-tooltip": FtTooltip,
|
|
83
185
|
"ft-chip": FtChip,
|
|
186
|
+
"ft-floating-menu": FtFloatingMenu,
|
|
187
|
+
"ft-floating-menu-item": FtFloatingMenuItem,
|
|
188
|
+
"ft-floating-menu-label": FtFloatingMenuLabel,
|
|
84
189
|
};
|
|
85
190
|
FtSearchResultMetadata.styles = styles;
|
|
86
191
|
__decorate([
|
|
@@ -89,6 +194,12 @@ __decorate([
|
|
|
89
194
|
__decorate([
|
|
90
195
|
property({ type: Boolean })
|
|
91
196
|
], FtSearchResultMetadata.prototype, "useChip", void 0);
|
|
197
|
+
__decorate([
|
|
198
|
+
property({ type: Boolean })
|
|
199
|
+
], FtSearchResultMetadata.prototype, "useAsClusterSwitch", void 0);
|
|
200
|
+
__decorate([
|
|
201
|
+
property({ type: Boolean })
|
|
202
|
+
], FtSearchResultMetadata.prototype, "goToDocumentOnSwitch", void 0);
|
|
92
203
|
__decorate([
|
|
93
204
|
property({ type: Number, attribute: "max-length" })
|
|
94
205
|
], FtSearchResultMetadata.prototype, "maxLength", void 0);
|
|
@@ -97,5 +208,11 @@ __decorate([
|
|
|
97
208
|
], FtSearchResultMetadata.prototype, "editorMode", void 0);
|
|
98
209
|
__decorate([
|
|
99
210
|
state()
|
|
100
|
-
], FtSearchResultMetadata.prototype, "
|
|
211
|
+
], FtSearchResultMetadata.prototype, "resultMetadata", void 0);
|
|
212
|
+
__decorate([
|
|
213
|
+
state()
|
|
214
|
+
], FtSearchResultMetadata.prototype, "metadataLabel", void 0);
|
|
215
|
+
__decorate([
|
|
216
|
+
state()
|
|
217
|
+
], FtSearchResultMetadata.prototype, "computedClusters", void 0);
|
|
101
218
|
export { FtSearchResultMetadata };
|