@fluid-topics/ft-reader-metadata 1.1.53 → 1.1.55
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/ReaderMetadataMessages.d.ts +5 -0
- package/build/ReaderMetadataMessages.js +2 -0
- package/build/ft-reader-metadata.d.ts +10 -7
- package/build/ft-reader-metadata.js +81 -63
- package/build/ft-reader-metadata.light.js +101 -92
- package/build/ft-reader-metadata.min.js +319 -310
- package/package.json +8 -8
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { I18nMessageContext, I18nMessages } from "@fluid-topics/ft-i18n";
|
|
2
|
+
export interface ReaderMetadataMessages extends I18nMessages {
|
|
3
|
+
itemWithNoValueForSwitchToRelatives(): string;
|
|
4
|
+
}
|
|
5
|
+
export declare const readerMetadataContext: I18nMessageContext<ReaderMetadataMessages>;
|
|
@@ -2,7 +2,8 @@ import { PropertyValues } from "lit";
|
|
|
2
2
|
import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
|
|
3
3
|
import { FtReaderMetadataProperties } from "./ft-reader-metadata.properties";
|
|
4
4
|
import { FtReaderComponent, FtReaderStateManager } from "@fluid-topics/ft-reader-context/build/registration";
|
|
5
|
-
|
|
5
|
+
declare const FtReaderMetadata_base: typeof FtReaderComponent & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>;
|
|
6
|
+
export declare class FtReaderMetadata extends FtReaderMetadata_base implements FtReaderMetadataProperties {
|
|
6
7
|
static elementDefinitions: ElementDefinitionsMap;
|
|
7
8
|
static styles: import("lit").CSSResult;
|
|
8
9
|
key?: string;
|
|
@@ -10,20 +11,22 @@ export declare class FtReaderMetadata extends FtReaderComponent implements FtRea
|
|
|
10
11
|
useForSwitchingToRelatives: boolean;
|
|
11
12
|
editorMode: boolean;
|
|
12
13
|
private metadata?;
|
|
13
|
-
private
|
|
14
|
+
private flatMetadata?;
|
|
14
15
|
private map?;
|
|
15
16
|
private relativeTopicPivotMetadata?;
|
|
16
17
|
private relatives;
|
|
18
|
+
private noValueMessage;
|
|
19
|
+
constructor();
|
|
17
20
|
setReaderStateManager(readerStateManager: FtReaderStateManager): void;
|
|
21
|
+
private updateRelatives;
|
|
18
22
|
protected render(): import("lit").TemplateResult<1>;
|
|
19
|
-
private renderContent;
|
|
20
23
|
private renderSwitchToRelatives;
|
|
24
|
+
private renderChip;
|
|
25
|
+
private renderChipContent;
|
|
21
26
|
private renderRelativeItem;
|
|
22
|
-
private renderRelativeItemValue;
|
|
23
27
|
private hideIfEmpty;
|
|
24
|
-
private get valueText();
|
|
25
|
-
private get tooltipText();
|
|
26
28
|
private addTopicPivotParam;
|
|
27
|
-
private setRelatives;
|
|
28
29
|
protected update(props: PropertyValues): void;
|
|
30
|
+
get metadataLabel(): string | undefined;
|
|
29
31
|
}
|
|
32
|
+
export {};
|
|
@@ -6,77 +6,91 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { html, nothing } from "lit";
|
|
8
8
|
import { property, state } from "lit/decorators.js";
|
|
9
|
-
import { redux, reduxReactive } from "@fluid-topics/ft-wc-utils";
|
|
9
|
+
import { ClusteringHelper, redux, reduxEventListener, reduxReactive } from "@fluid-topics/ft-wc-utils";
|
|
10
10
|
import { styles } from "./ft-reader-metadata.styles";
|
|
11
11
|
import { FtReaderComponent } from "@fluid-topics/ft-reader-context/build/registration";
|
|
12
12
|
import { FtTooltip } from "@fluid-topics/ft-tooltip";
|
|
13
13
|
import { FtChip } from "@fluid-topics/ft-chip";
|
|
14
|
-
import { FtFloatingMenu, FtFloatingMenuItem } from "@fluid-topics/ft-floating-menu";
|
|
14
|
+
import { FtFloatingMenu, FtFloatingMenuItem, FtFloatingMenuLabel } from "@fluid-topics/ft-floating-menu";
|
|
15
15
|
import { getResultUrl } from "@fluid-topics/ft-search-result-context/build/utils";
|
|
16
16
|
import { repeat } from "lit/directives/repeat.js";
|
|
17
17
|
import { FtRipple } from "@fluid-topics/ft-ripple";
|
|
18
|
-
|
|
18
|
+
import { withI18n } from "@fluid-topics/ft-i18n/build/lit/i18n";
|
|
19
|
+
import { readerMetadataContext } from "./ReaderMetadataMessages";
|
|
20
|
+
import { i18n } from "@fluid-topics/ft-i18n";
|
|
21
|
+
class FtReaderMetadata extends withI18n(FtReaderComponent) {
|
|
19
22
|
constructor() {
|
|
20
|
-
super(
|
|
23
|
+
super();
|
|
21
24
|
this.multiLine = false;
|
|
22
25
|
this.useForSwitchingToRelatives = false;
|
|
23
26
|
this.editorMode = false;
|
|
24
27
|
this.relatives = [];
|
|
28
|
+
this.noValueMessage = "No value";
|
|
29
|
+
this.addI18nContext(readerMetadataContext);
|
|
25
30
|
}
|
|
26
31
|
setReaderStateManager(readerStateManager) {
|
|
27
|
-
var _a;
|
|
28
32
|
super.setReaderStateManager(readerStateManager);
|
|
29
33
|
if (this.key && this.useForSwitchingToRelatives) {
|
|
30
34
|
readerStateManager.registerMetadataForSwitchToRelatives(this.key);
|
|
31
35
|
}
|
|
32
|
-
|
|
36
|
+
}
|
|
37
|
+
updateRelatives() {
|
|
38
|
+
var _a, _b, _c, _d;
|
|
39
|
+
if (this.useForSwitchingToRelatives && this.key) {
|
|
40
|
+
this.relatives = (_d = (_b = (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.clusteringHelper) === null || _b === void 0 ? void 0 : _b.computeClustersItemsForMetadata(this.key, ((_c = this.map) === null || _c === void 0 ? void 0 : _c.lang) || "en", this.noValueMessage)) !== null && _d !== void 0 ? _d : [];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.relatives = [];
|
|
44
|
+
}
|
|
33
45
|
}
|
|
34
46
|
render() {
|
|
47
|
+
return html `
|
|
48
|
+
${this.useForSwitchingToRelatives && this.relatives.length > 0 ? this.renderSwitchToRelatives() : this.renderChip()}
|
|
49
|
+
${this.hideIfEmpty()}
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
renderSwitchToRelatives() {
|
|
53
|
+
return html `
|
|
54
|
+
<div part="floating-menu-container" class="ft-reader-metadata--container">
|
|
55
|
+
<ft-floating-menu part="floating-menu" text="Toggle collapsible" trailingIcon>
|
|
56
|
+
${this.renderChip(true)}
|
|
57
|
+
<ft-floating-menu-label>${this.metadataLabel}</ft-floating-menu-label>
|
|
58
|
+
${repeat(this.relatives, relative => relative.metadata.value, relative => this.renderRelativeItem(relative.result, relative.metadata))}
|
|
59
|
+
</ft-floating-menu>
|
|
60
|
+
</div>
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
63
|
+
renderChip(inFloatingMenu = false) {
|
|
64
|
+
var _a, _b;
|
|
35
65
|
return html `
|
|
36
66
|
<ft-tooltip part="tooltip"
|
|
67
|
+
slot="${inFloatingMenu ? "toggle" : ""}"
|
|
37
68
|
class="${this.multiLine ? "ft-reader-metadata-multi-line" : ""}"
|
|
38
|
-
text="${this.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
69
|
+
text="${`${this.metadataLabel}: ${(_b = (_a = this.flatMetadata) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : this.noValueMessage}`}">
|
|
70
|
+
<ft-chip part="chip"
|
|
71
|
+
exportpartsPrefix="chip"
|
|
72
|
+
trailingIcon icon="${inFloatingMenu ? "thin_arrow" : ""}"
|
|
73
|
+
?clickable=${inFloatingMenu}
|
|
74
|
+
?multiLine=${this.multiLine}>
|
|
75
|
+
${this.renderChipContent()}
|
|
76
|
+
</ft-chip>
|
|
46
77
|
</ft-tooltip>
|
|
47
|
-
${this.hideIfEmpty()}
|
|
48
78
|
`;
|
|
49
79
|
}
|
|
50
|
-
|
|
80
|
+
renderChipContent() {
|
|
81
|
+
var _a, _b;
|
|
51
82
|
if (this.metadata && this.metadata.values.length > 0) {
|
|
52
|
-
return
|
|
83
|
+
return (_b = (_a = this.flatMetadata) === null || _a === void 0 ? void 0 : _a.displayValue) !== null && _b !== void 0 ? _b : this.noValueMessage;
|
|
53
84
|
}
|
|
54
85
|
if (this.editorMode) {
|
|
55
86
|
if (this.key) {
|
|
56
|
-
return
|
|
87
|
+
return `no value for ${this.key}`;
|
|
57
88
|
}
|
|
58
89
|
else {
|
|
59
|
-
return
|
|
90
|
+
return `no metadata selected`;
|
|
60
91
|
}
|
|
61
92
|
}
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
renderSwitchToRelatives() {
|
|
65
|
-
return html `
|
|
66
|
-
<div part="floating-menu-container" class="ft-reader-metadata--container">
|
|
67
|
-
<ft-floating-menu part="floating-menu" text="Toggle collapsible" trailingIcon>
|
|
68
|
-
<ft-chip part="chip"
|
|
69
|
-
?multiLine=${this.multiLine}
|
|
70
|
-
trailingIcon icon="thin_arrow"
|
|
71
|
-
slot="toggle"
|
|
72
|
-
clickable>
|
|
73
|
-
${this.renderContent()}
|
|
74
|
-
</ft-chip>
|
|
75
|
-
|
|
76
|
-
${repeat(this.relatives, relative => relative.metadata.value, relative => this.renderRelativeItem(relative.result, relative.metadata))}
|
|
77
|
-
</ft-floating-menu>
|
|
78
|
-
</div>
|
|
79
|
-
`;
|
|
93
|
+
return this.noValueMessage;
|
|
80
94
|
}
|
|
81
95
|
renderRelativeItem(result, metadata) {
|
|
82
96
|
return html `
|
|
@@ -85,18 +99,17 @@ class FtReaderMetadata extends FtReaderComponent {
|
|
|
85
99
|
@click=${(e) => this.addTopicPivotParam(e, result)}>
|
|
86
100
|
<ft-ripple part="relative-item-ripple"></ft-ripple>
|
|
87
101
|
<ft-floating-menu-item part="relative-item" value="${metadata.value}" notFocusable>
|
|
88
|
-
${
|
|
102
|
+
${metadata.value == null || metadata.value === metadata.displayValue ? metadata.displayValue : html `
|
|
103
|
+
<ft-tooltip part="relative-item-tooltip" text="${(metadata.value)}">${metadata.displayValue}</ft-tooltip>
|
|
104
|
+
`}
|
|
89
105
|
</ft-floating-menu-item>
|
|
90
106
|
</a>
|
|
91
107
|
`;
|
|
92
108
|
}
|
|
93
|
-
renderRelativeItemValue(value, displayValue) {
|
|
94
|
-
return value === displayValue ? value : html `
|
|
95
|
-
<ft-tooltip part="relative-item-tooltip" text="${value}">${displayValue}</ft-tooltip>
|
|
96
|
-
`;
|
|
97
|
-
}
|
|
98
109
|
hideIfEmpty() {
|
|
99
|
-
|
|
110
|
+
const theresNoMetadata = !this.metadata || this.metadata.values.length == 0;
|
|
111
|
+
const shouldHide = this.useForSwitchingToRelatives ? theresNoMetadata && this.relatives.length === 0 : theresNoMetadata;
|
|
112
|
+
if (!this.editorMode && shouldHide) {
|
|
100
113
|
return html `
|
|
101
114
|
<style>
|
|
102
115
|
:host {
|
|
@@ -107,14 +120,6 @@ class FtReaderMetadata extends FtReaderComponent {
|
|
|
107
120
|
}
|
|
108
121
|
return nothing;
|
|
109
122
|
}
|
|
110
|
-
get valueText() {
|
|
111
|
-
var _a, _b;
|
|
112
|
-
return (_b = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.values.join(", ")) !== null && _b !== void 0 ? _b : "";
|
|
113
|
-
}
|
|
114
|
-
get tooltipText() {
|
|
115
|
-
var _a, _b;
|
|
116
|
-
return this.metadata ? `${(_b = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : this.metadata.key}: ${this.valueText}` : "";
|
|
117
|
-
}
|
|
118
123
|
addTopicPivotParam(e, result) {
|
|
119
124
|
var _a, _b;
|
|
120
125
|
const currentTocId = this.stateManager.store.getState().visibleTopics[0];
|
|
@@ -138,18 +143,9 @@ class FtReaderMetadata extends FtReaderComponent {
|
|
|
138
143
|
});
|
|
139
144
|
}
|
|
140
145
|
}
|
|
141
|
-
setRelatives() {
|
|
142
|
-
var _a;
|
|
143
|
-
if (this.metadata && this.mapRelatives) {
|
|
144
|
-
this.relatives = this.stateManager.clusteringHelper.computeClustersItemsForMetadata(this.key, ((_a = this.map) === null || _a === void 0 ? void 0 : _a.lang) || "en");
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
146
|
update(props) {
|
|
148
147
|
var _a, _b, _c, _d;
|
|
149
148
|
super.update(props);
|
|
150
|
-
if ((props.has("metadata") || props.has("mapRelatives"))) {
|
|
151
|
-
this.setRelatives();
|
|
152
|
-
}
|
|
153
149
|
if (props.has("key") && this.useForSwitchingToRelatives) {
|
|
154
150
|
if (props.get("key")) {
|
|
155
151
|
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.unregisterMetadataForSwitchToRelatives(props.get("key"));
|
|
@@ -166,12 +162,28 @@ class FtReaderMetadata extends FtReaderComponent {
|
|
|
166
162
|
(_d = this.stateManager) === null || _d === void 0 ? void 0 : _d.unregisterMetadataForSwitchToRelatives(this.key);
|
|
167
163
|
}
|
|
168
164
|
}
|
|
165
|
+
if (props.has("metadata")) {
|
|
166
|
+
this.flatMetadata = this.metadata && this.metadata.values.length > 0 ? ClusteringHelper.flattenMetadata(this.metadata) : ({
|
|
167
|
+
key: this.key,
|
|
168
|
+
label: this.key,
|
|
169
|
+
value: undefined,
|
|
170
|
+
displayValue: undefined,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
get metadataLabel() {
|
|
175
|
+
var _a, _b, _c, _d, _e, _f;
|
|
176
|
+
if (this.metadata) {
|
|
177
|
+
return this.metadata.label;
|
|
178
|
+
}
|
|
179
|
+
return (_f = (_d = (_c = (_b = (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.clusteringHelper) === null || _b === void 0 ? void 0 : _b.getMetadataDescriptor(this.key)) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : (_e = this.relatives.find(item => item.metadata.value)) === null || _e === void 0 ? void 0 : _e.metadata.label) !== null && _f !== void 0 ? _f : this.key;
|
|
169
180
|
}
|
|
170
181
|
}
|
|
171
182
|
FtReaderMetadata.elementDefinitions = {
|
|
172
183
|
"ft-chip": FtChip,
|
|
173
184
|
"ft-floating-menu": FtFloatingMenu,
|
|
174
185
|
"ft-floating-menu-item": FtFloatingMenuItem,
|
|
186
|
+
"ft-floating-menu-label": FtFloatingMenuLabel,
|
|
175
187
|
"ft-ripple": FtRipple,
|
|
176
188
|
"ft-tooltip": FtTooltip,
|
|
177
189
|
};
|
|
@@ -193,8 +205,8 @@ __decorate([
|
|
|
193
205
|
redux({ selector: (s, e) => { var _a, _b; return (_b = (_a = s.map) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.find(m => m.key === e.key); } })
|
|
194
206
|
], FtReaderMetadata.prototype, "metadata", void 0);
|
|
195
207
|
__decorate([
|
|
196
|
-
|
|
197
|
-
], FtReaderMetadata.prototype, "
|
|
208
|
+
state()
|
|
209
|
+
], FtReaderMetadata.prototype, "flatMetadata", void 0);
|
|
198
210
|
__decorate([
|
|
199
211
|
redux()
|
|
200
212
|
], FtReaderMetadata.prototype, "map", void 0);
|
|
@@ -204,4 +216,10 @@ __decorate([
|
|
|
204
216
|
__decorate([
|
|
205
217
|
state()
|
|
206
218
|
], FtReaderMetadata.prototype, "relatives", void 0);
|
|
219
|
+
__decorate([
|
|
220
|
+
i18n(readerMetadataContext.properties.itemWithNoValueForSwitchToRelatives())
|
|
221
|
+
], FtReaderMetadata.prototype, "noValueMessage", void 0);
|
|
222
|
+
__decorate([
|
|
223
|
+
reduxEventListener({ eventName: "clustering-helper-created" })
|
|
224
|
+
], FtReaderMetadata.prototype, "updateRelatives", null);
|
|
207
225
|
export { FtReaderMetadata };
|