@fluid-topics/ft-reader-metadata 1.1.54 → 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 -66
- package/build/ft-reader-metadata.light.js +94 -90
- package/build/ft-reader-metadata.min.js +313 -309
- 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,80 +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
|
-
|
|
46
|
-
</ft-chip>
|
|
47
|
-
`}
|
|
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>
|
|
48
77
|
</ft-tooltip>
|
|
49
|
-
${this.hideIfEmpty()}
|
|
50
78
|
`;
|
|
51
79
|
}
|
|
52
|
-
|
|
80
|
+
renderChipContent() {
|
|
81
|
+
var _a, _b;
|
|
53
82
|
if (this.metadata && this.metadata.values.length > 0) {
|
|
54
|
-
return
|
|
83
|
+
return (_b = (_a = this.flatMetadata) === null || _a === void 0 ? void 0 : _a.displayValue) !== null && _b !== void 0 ? _b : this.noValueMessage;
|
|
55
84
|
}
|
|
56
85
|
if (this.editorMode) {
|
|
57
86
|
if (this.key) {
|
|
58
|
-
return
|
|
87
|
+
return `no value for ${this.key}`;
|
|
59
88
|
}
|
|
60
89
|
else {
|
|
61
|
-
return
|
|
90
|
+
return `no metadata selected`;
|
|
62
91
|
}
|
|
63
92
|
}
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
renderSwitchToRelatives() {
|
|
67
|
-
return html `
|
|
68
|
-
<div part="floating-menu-container" class="ft-reader-metadata--container">
|
|
69
|
-
<ft-floating-menu part="floating-menu" text="Toggle collapsible" trailingIcon>
|
|
70
|
-
<ft-chip part="chip"
|
|
71
|
-
exportpartsPrefix="chip"
|
|
72
|
-
?multiLine=${this.multiLine}
|
|
73
|
-
trailingIcon icon="thin_arrow"
|
|
74
|
-
slot="toggle"
|
|
75
|
-
clickable>
|
|
76
|
-
${this.renderContent()}
|
|
77
|
-
</ft-chip>
|
|
78
|
-
|
|
79
|
-
${repeat(this.relatives, relative => relative.metadata.value, relative => this.renderRelativeItem(relative.result, relative.metadata))}
|
|
80
|
-
</ft-floating-menu>
|
|
81
|
-
</div>
|
|
82
|
-
`;
|
|
93
|
+
return this.noValueMessage;
|
|
83
94
|
}
|
|
84
95
|
renderRelativeItem(result, metadata) {
|
|
85
96
|
return html `
|
|
@@ -88,18 +99,17 @@ class FtReaderMetadata extends FtReaderComponent {
|
|
|
88
99
|
@click=${(e) => this.addTopicPivotParam(e, result)}>
|
|
89
100
|
<ft-ripple part="relative-item-ripple"></ft-ripple>
|
|
90
101
|
<ft-floating-menu-item part="relative-item" value="${metadata.value}" notFocusable>
|
|
91
|
-
${
|
|
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
|
+
`}
|
|
92
105
|
</ft-floating-menu-item>
|
|
93
106
|
</a>
|
|
94
107
|
`;
|
|
95
108
|
}
|
|
96
|
-
renderRelativeItemValue(value, displayValue) {
|
|
97
|
-
return value === displayValue ? value : html `
|
|
98
|
-
<ft-tooltip part="relative-item-tooltip" text="${value}">${displayValue}</ft-tooltip>
|
|
99
|
-
`;
|
|
100
|
-
}
|
|
101
109
|
hideIfEmpty() {
|
|
102
|
-
|
|
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) {
|
|
103
113
|
return html `
|
|
104
114
|
<style>
|
|
105
115
|
:host {
|
|
@@ -110,14 +120,6 @@ class FtReaderMetadata extends FtReaderComponent {
|
|
|
110
120
|
}
|
|
111
121
|
return nothing;
|
|
112
122
|
}
|
|
113
|
-
get valueText() {
|
|
114
|
-
var _a, _b;
|
|
115
|
-
return (_b = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.values.join(", ")) !== null && _b !== void 0 ? _b : "";
|
|
116
|
-
}
|
|
117
|
-
get tooltipText() {
|
|
118
|
-
var _a, _b;
|
|
119
|
-
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}` : "";
|
|
120
|
-
}
|
|
121
123
|
addTopicPivotParam(e, result) {
|
|
122
124
|
var _a, _b;
|
|
123
125
|
const currentTocId = this.stateManager.store.getState().visibleTopics[0];
|
|
@@ -141,18 +143,9 @@ class FtReaderMetadata extends FtReaderComponent {
|
|
|
141
143
|
});
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
|
-
setRelatives() {
|
|
145
|
-
var _a;
|
|
146
|
-
if (this.metadata && this.mapRelatives) {
|
|
147
|
-
this.relatives = this.stateManager.clusteringHelper.computeClustersItemsForMetadata(this.key, ((_a = this.map) === null || _a === void 0 ? void 0 : _a.lang) || "en");
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
146
|
update(props) {
|
|
151
147
|
var _a, _b, _c, _d;
|
|
152
148
|
super.update(props);
|
|
153
|
-
if ((props.has("metadata") || props.has("mapRelatives"))) {
|
|
154
|
-
this.setRelatives();
|
|
155
|
-
}
|
|
156
149
|
if (props.has("key") && this.useForSwitchingToRelatives) {
|
|
157
150
|
if (props.get("key")) {
|
|
158
151
|
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.unregisterMetadataForSwitchToRelatives(props.get("key"));
|
|
@@ -169,12 +162,28 @@ class FtReaderMetadata extends FtReaderComponent {
|
|
|
169
162
|
(_d = this.stateManager) === null || _d === void 0 ? void 0 : _d.unregisterMetadataForSwitchToRelatives(this.key);
|
|
170
163
|
}
|
|
171
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;
|
|
172
180
|
}
|
|
173
181
|
}
|
|
174
182
|
FtReaderMetadata.elementDefinitions = {
|
|
175
183
|
"ft-chip": FtChip,
|
|
176
184
|
"ft-floating-menu": FtFloatingMenu,
|
|
177
185
|
"ft-floating-menu-item": FtFloatingMenuItem,
|
|
186
|
+
"ft-floating-menu-label": FtFloatingMenuLabel,
|
|
178
187
|
"ft-ripple": FtRipple,
|
|
179
188
|
"ft-tooltip": FtTooltip,
|
|
180
189
|
};
|
|
@@ -196,8 +205,8 @@ __decorate([
|
|
|
196
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); } })
|
|
197
206
|
], FtReaderMetadata.prototype, "metadata", void 0);
|
|
198
207
|
__decorate([
|
|
199
|
-
|
|
200
|
-
], FtReaderMetadata.prototype, "
|
|
208
|
+
state()
|
|
209
|
+
], FtReaderMetadata.prototype, "flatMetadata", void 0);
|
|
201
210
|
__decorate([
|
|
202
211
|
redux()
|
|
203
212
|
], FtReaderMetadata.prototype, "map", void 0);
|
|
@@ -207,4 +216,10 @@ __decorate([
|
|
|
207
216
|
__decorate([
|
|
208
217
|
state()
|
|
209
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);
|
|
210
225
|
export { FtReaderMetadata };
|