@fluid-topics/ft-search-result-metadata 1.1.38 → 1.1.40
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.
|
@@ -21,12 +21,11 @@ export declare class FtSearchResultMetadata extends FtSearchResultMetadata_base
|
|
|
21
21
|
private resultMetadata?;
|
|
22
22
|
private metadataLabel?;
|
|
23
23
|
private clustersByValue;
|
|
24
|
-
private
|
|
24
|
+
private clusterItems?;
|
|
25
25
|
constructor();
|
|
26
26
|
setResultStateManager(resultStateManager: FtSearchResultStateManager): void;
|
|
27
27
|
protected render(): import("lit").TemplateResult<1>;
|
|
28
28
|
private renderClusterList;
|
|
29
|
-
private hideIfEmpty;
|
|
30
29
|
private onClusterSelected;
|
|
31
30
|
private computeClusters;
|
|
32
31
|
private renderClusterItem;
|
|
@@ -38,7 +37,7 @@ export declare class FtSearchResultMetadata extends FtSearchResultMetadata_base
|
|
|
38
37
|
private get clusterHasMultipleValues();
|
|
39
38
|
private getEllipsis;
|
|
40
39
|
protected update(props: PropertyValues): void;
|
|
41
|
-
private
|
|
40
|
+
private resultData;
|
|
42
41
|
private get valueText();
|
|
43
42
|
private get tooltipText();
|
|
44
43
|
private findClusterMetadataLabel;
|
|
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { html
|
|
7
|
+
import { html } from "lit";
|
|
8
8
|
import { property, state } from "lit/decorators.js";
|
|
9
9
|
import { ClusteringHelper, redux } from "@fluid-topics/ft-wc-utils";
|
|
10
10
|
import { styles } from "./ft-search-result-metadata.css";
|
|
@@ -26,7 +26,6 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
|
|
|
26
26
|
this.editorMode = false;
|
|
27
27
|
this.metadataDescriptors = [];
|
|
28
28
|
this.clustersByValue = {};
|
|
29
|
-
this.clusters = [];
|
|
30
29
|
this.addStore(ftAppInfoStore);
|
|
31
30
|
this.addI18nContext(searchResultMetadataContext);
|
|
32
31
|
}
|
|
@@ -37,12 +36,20 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
|
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
render() {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
var _a;
|
|
40
|
+
if (this.valueText.length == 0 && ((_a = this.clusterItems) === null || _a === void 0 ? void 0 : _a.length) == 0 && !this.editorMode) {
|
|
41
|
+
return html `
|
|
42
|
+
<style>
|
|
43
|
+
:host {
|
|
44
|
+
display: none !important;
|
|
45
|
+
}
|
|
46
|
+
</style>
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
return this.displayCluster ? this.renderClusterList() : this.renderChip();
|
|
44
50
|
}
|
|
45
51
|
renderClusterList() {
|
|
52
|
+
var _a;
|
|
46
53
|
return html `
|
|
47
54
|
<div class="ft-search-result-metadata--container">
|
|
48
55
|
<ft-floating-menu icon="THIN_ARROW"
|
|
@@ -50,23 +57,11 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
|
|
|
50
57
|
slot="button">
|
|
51
58
|
${this.renderChip("toggle")}
|
|
52
59
|
<ft-floating-menu-label>${this.metadataLabel}</ft-floating-menu-label>
|
|
53
|
-
${repeat(this.
|
|
60
|
+
${repeat((_a = this.clusterItems) !== null && _a !== void 0 ? _a : [], item => item.metadata.value, item => this.renderClusterItem(item.result, item.metadata))}
|
|
54
61
|
</ft-floating-menu>
|
|
55
62
|
</div>
|
|
56
63
|
`;
|
|
57
64
|
}
|
|
58
|
-
hideIfEmpty() {
|
|
59
|
-
if (this.valueText.length == 0 && this.clusters.length == 0 && !this.editorMode) {
|
|
60
|
-
return html `
|
|
61
|
-
<style>
|
|
62
|
-
:host {
|
|
63
|
-
display: none !important;
|
|
64
|
-
}
|
|
65
|
-
</style>
|
|
66
|
-
`;
|
|
67
|
-
}
|
|
68
|
-
return nothing;
|
|
69
|
-
}
|
|
70
65
|
onClusterSelected(e) {
|
|
71
66
|
var _a;
|
|
72
67
|
(_a = this.resultStateManager) === null || _a === void 0 ? void 0 : _a.selectResult(this.clustersByValue[e.detail].result);
|
|
@@ -75,8 +70,8 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
|
|
|
75
70
|
var _a, _b;
|
|
76
71
|
const clustersByValue = {};
|
|
77
72
|
const clusteringHelper = new ClusteringHelper((_a = this.cluster) === null || _a === void 0 ? void 0 : _a.entries, this.result, this.resultStateManager.registeredMetadata, this.metadataDescriptors);
|
|
78
|
-
this.
|
|
79
|
-
this.
|
|
73
|
+
this.clusterItems = clusteringHelper.computeClustersItemsForMetadata(this.key, ((_b = this.request) === null || _b === void 0 ? void 0 : _b.contentLocale) || "en");
|
|
74
|
+
this.clusterItems.forEach(item => {
|
|
80
75
|
clustersByValue[item.metadata.value] = item;
|
|
81
76
|
});
|
|
82
77
|
this.clustersByValue = clustersByValue;
|
|
@@ -156,7 +151,7 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
|
|
|
156
151
|
var _a, _b, _c, _d, _e;
|
|
157
152
|
super.update(props);
|
|
158
153
|
if ((props.has("result") || props.has("key")) && this.result) {
|
|
159
|
-
this.resultMetadata = (_a = this.resultData) === null || _a === void 0 ? void 0 : _a.metadata.find(m => m.key == this.key);
|
|
154
|
+
this.resultMetadata = (_a = this.resultData()) === null || _a === void 0 ? void 0 : _a.metadata.find(m => m.key == this.key);
|
|
160
155
|
this.metadataLabel = this.findClusterMetadataLabel();
|
|
161
156
|
}
|
|
162
157
|
if (props.has("key") && this.useAsClusterSwitch) {
|
|
@@ -180,9 +175,10 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
|
|
|
180
175
|
this.computeClusters();
|
|
181
176
|
}
|
|
182
177
|
}
|
|
183
|
-
|
|
184
|
-
var _a, _b
|
|
185
|
-
|
|
178
|
+
resultData(result) {
|
|
179
|
+
var _a, _b;
|
|
180
|
+
result = result !== null && result !== void 0 ? result : this.result;
|
|
181
|
+
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.topic) !== null && _b !== void 0 ? _b : result === null || result === void 0 ? void 0 : result.document;
|
|
186
182
|
}
|
|
187
183
|
get valueText() {
|
|
188
184
|
var _a, _b;
|
|
@@ -199,7 +195,7 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
|
|
|
199
195
|
}
|
|
200
196
|
findClusterMetadataLabel() {
|
|
201
197
|
var _a;
|
|
202
|
-
const metadata = (_a = this.cluster) === null || _a === void 0 ? void 0 : _a.entries.flatMap(result =>
|
|
198
|
+
const metadata = (_a = this.cluster) === null || _a === void 0 ? void 0 : _a.entries.flatMap(result => this.resultData(result).metadata.filter(m => m.key == this.key))[0];
|
|
203
199
|
return metadata === null || metadata === void 0 ? void 0 : metadata.label;
|
|
204
200
|
}
|
|
205
201
|
}
|
|
@@ -246,5 +242,5 @@ __decorate([
|
|
|
246
242
|
], FtSearchResultMetadata.prototype, "clustersByValue", void 0);
|
|
247
243
|
__decorate([
|
|
248
244
|
state()
|
|
249
|
-
], FtSearchResultMetadata.prototype, "
|
|
245
|
+
], FtSearchResultMetadata.prototype, "clusterItems", void 0);
|
|
250
246
|
export { FtSearchResultMetadata };
|
|
@@ -1105,26 +1105,23 @@ const Pt=Symbol.for(""),Mt=t=>{if(t?.r===Pt)return t?._$litStatic$},jt=t=>({_$li
|
|
|
1105
1105
|
<slot></slot>
|
|
1106
1106
|
</ft-typography>
|
|
1107
1107
|
</div>
|
|
1108
|
-
`}}function Fn(t){var o,e,i,n,r;if(function(t){var o,e,i,n,r;return(null!==(n=null!==(e=null===(o=t.map)||void 0===o?void 0:o.openMode)&&void 0!==e?e:null===(i=t.topic)||void 0===i?void 0:i.openMode)&&void 0!==n?n:null===(r=t.document)||void 0===r?void 0:r.openMode)===v.EXTERNAL}(t))return null!==(n=null!==(e=null===(o=t.map)||void 0===o?void 0:o.originUrl)&&void 0!==e?e:null===(i=t.topic)||void 0===i?void 0:i.originUrl)&&void 0!==n?n:null===(r=t.document)||void 0===r?void 0:r.originUrl;switch(t.type){case N.MAP:return t.map.readerUrl;case N.DOCUMENT:return t.document.viewerUrl;case N.TOPIC:return t.topic.readerUrl}return""}Bn.elementDefinitions={"ft-typography":ue},Bn.styles=Dn,o.customElement("ft-floating-menu")(An),o.customElement("ftds-floating-menu")(zn),o.customElement("ft-floating-menu-item")(Ln),o.customElement("ft-floating-menu-label")(Bn);class Tn extends CustomEvent{constructor(t,o){super("ft-search-result-click",{detail:{result:t,rank:o},bubbles:!0,composed:!0})}}var Hn=function(t,o,e,i){for(var n,r=arguments.length,a=r<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i,l=t.length-1;l>=0;l--)(n=t[l])&&(a=(r<3?n(a):r>3?n(o,e,a):n(o,e))||a);return r>3&&a&&Object.defineProperty(o,e,a),a};class Pn extends(tt(V)){constructor(){super(),this.useChip=!1,this.useAsClusterSwitch=!1,this.goToDocumentOnSwitch=!1,this.editorMode=!1,this.metadataDescriptors=[],this.clustersByValue={},this.
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1108
|
+
`}}function Fn(t){var o,e,i,n,r;if(function(t){var o,e,i,n,r;return(null!==(n=null!==(e=null===(o=t.map)||void 0===o?void 0:o.openMode)&&void 0!==e?e:null===(i=t.topic)||void 0===i?void 0:i.openMode)&&void 0!==n?n:null===(r=t.document)||void 0===r?void 0:r.openMode)===v.EXTERNAL}(t))return null!==(n=null!==(e=null===(o=t.map)||void 0===o?void 0:o.originUrl)&&void 0!==e?e:null===(i=t.topic)||void 0===i?void 0:i.originUrl)&&void 0!==n?n:null===(r=t.document)||void 0===r?void 0:r.originUrl;switch(t.type){case N.MAP:return t.map.readerUrl;case N.DOCUMENT:return t.document.viewerUrl;case N.TOPIC:return t.topic.readerUrl}return""}Bn.elementDefinitions={"ft-typography":ue},Bn.styles=Dn,o.customElement("ft-floating-menu")(An),o.customElement("ftds-floating-menu")(zn),o.customElement("ft-floating-menu-item")(Ln),o.customElement("ft-floating-menu-label")(Bn);class Tn extends CustomEvent{constructor(t,o){super("ft-search-result-click",{detail:{result:t,rank:o},bubbles:!0,composed:!0})}}var Hn=function(t,o,e,i){for(var n,r=arguments.length,a=r<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i,l=t.length-1;l>=0;l--)(n=t[l])&&(a=(r<3?n(a):r>3?n(o,e,a):n(o,e))||a);return r>3&&a&&Object.defineProperty(o,e,a),a};class Pn extends(tt(V)){constructor(){super(),this.useChip=!1,this.useAsClusterSwitch=!1,this.goToDocumentOnSwitch=!1,this.editorMode=!1,this.metadataDescriptors=[],this.clustersByValue={},this.addStore(I),this.addI18nContext(at)}setResultStateManager(t){super.setResultStateManager(t),this.key&&this.useAsClusterSwitch&&t.registerMetadata(this.key)}render(){var t;return 0!=this.valueText.length||0!=(null===(t=this.clusterItems)||void 0===t?void 0:t.length)||this.editorMode?this.displayCluster?this.renderClusterList():this.renderChip():e.html`
|
|
1109
|
+
<style>
|
|
1110
|
+
:host {
|
|
1111
|
+
display: none !important;
|
|
1112
|
+
}
|
|
1113
|
+
</style>
|
|
1114
|
+
`}renderClusterList(){var t;return e.html`
|
|
1112
1115
|
<div class="ft-search-result-metadata--container">
|
|
1113
1116
|
<ft-floating-menu icon="THIN_ARROW"
|
|
1114
1117
|
@select=${this.onClusterSelected}
|
|
1115
1118
|
slot="button">
|
|
1116
1119
|
${this.renderChip("toggle")}
|
|
1117
1120
|
<ft-floating-menu-label>${this.metadataLabel}</ft-floating-menu-label>
|
|
1118
|
-
${a.repeat(this.
|
|
1121
|
+
${a.repeat(null!==(t=this.clusterItems)&&void 0!==t?t:[],(t=>t.metadata.value),(t=>this.renderClusterItem(t.result,t.metadata)))}
|
|
1119
1122
|
</ft-floating-menu>
|
|
1120
1123
|
</div>
|
|
1121
|
-
`}
|
|
1122
|
-
<style>
|
|
1123
|
-
:host {
|
|
1124
|
-
display: none !important;
|
|
1125
|
-
}
|
|
1126
|
-
</style>
|
|
1127
|
-
`}onClusterSelected(t){var o;null===(o=this.resultStateManager)||void 0===o||o.selectResult(this.clustersByValue[t.detail].result)}computeClusters(){var t,e;const i={},n=new o.ClusteringHelper(null===(t=this.cluster)||void 0===t?void 0:t.entries,this.result,this.resultStateManager.registeredMetadata,this.metadataDescriptors);this.clusters=n.computeClustersItemsForMetadata(this.key,(null===(e=this.request)||void 0===e?void 0:e.contentLocale)||"en"),this.clusters.forEach((t=>{i[t.metadata.value]=t})),this.clustersByValue=i}renderClusterItem(t,o){return this.goToDocumentOnSwitch?e.html`
|
|
1124
|
+
`}onClusterSelected(t){var o;null===(o=this.resultStateManager)||void 0===o||o.selectResult(this.clustersByValue[t.detail].result)}computeClusters(){var t,e;const i={},n=new o.ClusteringHelper(null===(t=this.cluster)||void 0===t?void 0:t.entries,this.result,this.resultStateManager.registeredMetadata,this.metadataDescriptors);this.clusterItems=n.computeClustersItemsForMetadata(this.key,(null===(e=this.request)||void 0===e?void 0:e.contentLocale)||"en"),this.clusterItems.forEach((t=>{i[t.metadata.value]=t})),this.clustersByValue=i}renderClusterItem(t,o){return this.goToDocumentOnSwitch?e.html`
|
|
1128
1125
|
<a href="${Fn(t)}" @click=${()=>this.onResultClick(t)}>
|
|
1129
1126
|
<ft-floating-menu-item value="${o.value}">${this.renderClusterItemValue(o.value,o.displayValue)}
|
|
1130
1127
|
</ft-floating-menu-item>
|
|
@@ -1143,4 +1140,4 @@ const Pt=Symbol.for(""),Mt=t=>{if(t?.r===Pt)return t?._$litStatic$},jt=t=>({_$li
|
|
|
1143
1140
|
display: none !important;
|
|
1144
1141
|
}
|
|
1145
1142
|
</style>
|
|
1146
|
-
`}get displayCluster(){var t,o;return this.useAsClusterSwitch&&(null!==(o=null===(t=this.cluster)||void 0===t?void 0:t.entries.length)&&void 0!==o?o:0)>1&&this.clusterHasMultipleValues}get clusterHasMultipleValues(){var t,e,i;let n=null===(i=null===(e=null===(t=this.cluster)||void 0===t?void 0:t.entries)||void 0===e?void 0:e.map((t=>o.ClusteringHelper.extractResultMetadata(t))))||void 0===i?void 0:i.map((t=>{var o;return null===(o=t.find((t=>t.key==this.key)))||void 0===o?void 0:o.value}));return new Set(n).size>1}getEllipsis(t){let o=this.maxLength?t.substring(0,this.maxLength):t;return o+(o.length<t.length?"…":"")}update(t){var o,e,i,n,r;super.update(t),(t.has("result")||t.has("key"))&&this.result&&(this.resultMetadata=null===(o=this.resultData)||void 0===o?void 0:o.metadata.find((t=>t.key==this.key)),this.metadataLabel=this.findClusterMetadataLabel()),t.has("key")&&this.useAsClusterSwitch&&(t.get("key")&&(null===(e=this.resultStateManager)||void 0===e||e.unregisterMetadata(t.get("key"))),this.key&&(null===(i=this.resultStateManager)||void 0===i||i.registerMetadata(this.key))),t.has("useAsClusterSwitch")&&this.key&&(this.useAsClusterSwitch?null===(n=this.resultStateManager)||void 0===n||n.registerMetadata(this.key):null===(r=this.resultStateManager)||void 0===r||r.unregisterMetadata(this.key)),(t.has("cluster")||t.has("result")||t.has("key")||t.has("useAsClusterSwitch"))&&this.cluster&&this.result&&this.key&&this.useAsClusterSwitch&&this.computeClusters()}
|
|
1143
|
+
`}get displayCluster(){var t,o;return this.useAsClusterSwitch&&(null!==(o=null===(t=this.cluster)||void 0===t?void 0:t.entries.length)&&void 0!==o?o:0)>1&&this.clusterHasMultipleValues}get clusterHasMultipleValues(){var t,e,i;let n=null===(i=null===(e=null===(t=this.cluster)||void 0===t?void 0:t.entries)||void 0===e?void 0:e.map((t=>o.ClusteringHelper.extractResultMetadata(t))))||void 0===i?void 0:i.map((t=>{var o;return null===(o=t.find((t=>t.key==this.key)))||void 0===o?void 0:o.value}));return new Set(n).size>1}getEllipsis(t){let o=this.maxLength?t.substring(0,this.maxLength):t;return o+(o.length<t.length?"…":"")}update(t){var o,e,i,n,r;super.update(t),(t.has("result")||t.has("key"))&&this.result&&(this.resultMetadata=null===(o=this.resultData())||void 0===o?void 0:o.metadata.find((t=>t.key==this.key)),this.metadataLabel=this.findClusterMetadataLabel()),t.has("key")&&this.useAsClusterSwitch&&(t.get("key")&&(null===(e=this.resultStateManager)||void 0===e||e.unregisterMetadata(t.get("key"))),this.key&&(null===(i=this.resultStateManager)||void 0===i||i.registerMetadata(this.key))),t.has("useAsClusterSwitch")&&this.key&&(this.useAsClusterSwitch?null===(n=this.resultStateManager)||void 0===n||n.registerMetadata(this.key):null===(r=this.resultStateManager)||void 0===r||r.unregisterMetadata(this.key)),(t.has("cluster")||t.has("result")||t.has("key")||t.has("useAsClusterSwitch"))&&this.cluster&&this.result&&this.key&&this.useAsClusterSwitch&&this.computeClusters()}resultData(t){var o,e;return null!==(e=null!==(o=null==(t=null!=t?t:this.result)?void 0:t.map)&&void 0!==o?o:null==t?void 0:t.topic)&&void 0!==e?e:null==t?void 0:t.document}get valueText(){var t,o;return null!==(o=null===(t=this.resultMetadata)||void 0===t?void 0:t.values.join(", "))&&void 0!==o?o:""}get tooltipText(){return this.resultMetadata?`${this.metadataLabel}: ${this.valueText}`:this.useAsClusterSwitch?`${this.metadataLabel}: ${at.messages.noValueInCluster()}`:""}findClusterMetadataLabel(){var t;const o=null===(t=this.cluster)||void 0===t?void 0:t.entries.flatMap((t=>this.resultData(t).metadata.filter((t=>t.key==this.key))))[0];return null==o?void 0:o.label}}Pn.elementDefinitions={"ft-tooltip":Ci,"ft-chip":xn,"ft-floating-menu":An,"ft-floating-menu-item":Ln,"ft-floating-menu-label":Bn},Pn.styles=l,Hn([i.property()],Pn.prototype,"key",void 0),Hn([i.property({type:Boolean})],Pn.prototype,"useChip",void 0),Hn([i.property({type:Boolean})],Pn.prototype,"useAsClusterSwitch",void 0),Hn([i.property({type:Boolean})],Pn.prototype,"goToDocumentOnSwitch",void 0),Hn([i.property({type:Number,attribute:"max-length"})],Pn.prototype,"maxLength",void 0),Hn([o.redux({store:I.name})],Pn.prototype,"editorMode",void 0),Hn([o.redux({store:I.name,selector:t=>{var o,e;return null!==(e=null===(o=t.metadataConfiguration)||void 0===o?void 0:o.descriptors)&&void 0!==e?e:[]}})],Pn.prototype,"metadataDescriptors",void 0),Hn([o.redux({store:"search"})],Pn.prototype,"request",void 0),Hn([i.state()],Pn.prototype,"resultMetadata",void 0),Hn([i.state()],Pn.prototype,"metadataLabel",void 0),Hn([i.state()],Pn.prototype,"clustersByValue",void 0),Hn([i.state()],Pn.prototype,"clusterItems",void 0),o.customElement("ft-search-result-metadata")(Pn),t.FtSearchResultMetadata=Pn,t.FtSearchResultMetadataCssVariables={},t.styles=l}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators,ftGlobals.litClassMap,ftGlobals.litUnsafeHTML,ftGlobals.litRepeat);
|