@fluid-topics/ft-reader-metadata 1.3.4 → 1.3.6

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.
@@ -2,7 +2,7 @@ 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
- declare const FtReaderMetadata_base: typeof FtReaderComponent & 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/build/mixins/withDateFormat").FtLitElementWithDateFormatInterface>;
5
+ declare const FtReaderMetadata_base: typeof FtReaderComponent & 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>;
6
6
  export declare class FtReaderMetadata extends FtReaderMetadata_base implements FtReaderMetadataProperties {
7
7
  static elementDefinitions: ElementDefinitionsMap;
8
8
  static styles: import("lit").CSSResult;
@@ -13,11 +13,13 @@ export declare class FtReaderMetadata extends FtReaderMetadata_base implements F
13
13
  hierarchicalValueTruncatingLevel?: number;
14
14
  forceTooltip: boolean;
15
15
  editorMode: boolean;
16
+ translateValues: boolean;
16
17
  private metadata?;
17
18
  private flatMetadata?;
18
19
  private map?;
19
20
  private relativeTopicPivotMetadata?;
20
21
  private relatives;
22
+ private availableContentLocales?;
21
23
  private noValueMessage;
22
24
  constructor();
23
25
  setReaderStateManager(readerStateManager: FtReaderStateManager): void;
@@ -29,7 +31,7 @@ export declare class FtReaderMetadata extends FtReaderMetadata_base implements F
29
31
  private renderRelativeItem;
30
32
  private hideIfEmpty;
31
33
  private addTopicPivotParam;
32
- protected update(props: PropertyValues): void;
34
+ protected willUpdate(props: PropertyValues): void;
33
35
  get metadataLabel(): string | undefined;
34
36
  }
35
37
  export {};
@@ -20,6 +20,8 @@ import { readerMetadataContext } from "./ReaderMetadataMessages";
20
20
  import { withDateFormat } from "@fluid-topics/ft-app-context/build/mixins/withDateFormat";
21
21
  import { i18n } from "@fluid-topics/ft-i18n";
22
22
  import { FtReaderStoreEvents } from "@fluid-topics/ft-reader-context";
23
+ import { FtAppInfoStoreName } from "@fluid-topics/ft-app-context";
24
+ import { MetadataValueLocalizer } from "./utils/MetadataValueLocalizer";
23
25
  class FtReaderMetadata extends withDateFormat(withI18n(FtReaderComponent)) {
24
26
  constructor() {
25
27
  super();
@@ -29,6 +31,7 @@ class FtReaderMetadata extends withDateFormat(withI18n(FtReaderComponent)) {
29
31
  this.hierarchicalValueTruncatingLevel = 3;
30
32
  this.forceTooltip = false;
31
33
  this.editorMode = false;
34
+ this.translateValues = false;
32
35
  this.relatives = [];
33
36
  this.noValueMessage = "No value";
34
37
  this.addI18nContext(readerMetadataContext);
@@ -67,9 +70,9 @@ class FtReaderMetadata extends withDateFormat(withI18n(FtReaderComponent)) {
67
70
  }
68
71
  renderChip(inFloatingMenu = false) {
69
72
  var _a, _b, _c, _d, _e, _f;
70
- let noTooltip = !this.forceTooltip && this.displayLabel && ((_a = this.flatMetadata) === null || _a === void 0 ? void 0 : _a.displayTooltipValue) == ((_b = this.flatMetadata) === null || _b === void 0 ? void 0 : _b.displayValue);
71
- let tooltipLabel = `${this.metadataLabel}: ${(_d = (_c = this.flatMetadata) === null || _c === void 0 ? void 0 : _c.displayTooltipValue) !== null && _d !== void 0 ? _d : this.noValueMessage}`;
72
- let chip = html `
73
+ const noTooltip = !this.forceTooltip && this.displayLabel && ((_a = this.flatMetadata) === null || _a === void 0 ? void 0 : _a.displayTooltipValue) == ((_b = this.flatMetadata) === null || _b === void 0 ? void 0 : _b.displayValue);
74
+ const tooltipLabel = `${this.metadataLabel}: ${(_d = (_c = this.flatMetadata) === null || _c === void 0 ? void 0 : _c.displayTooltipValue) !== null && _d !== void 0 ? _d : this.noValueMessage}`;
75
+ const chip = html `
73
76
  <ft-chip part="chip"
74
77
  exportpartsPrefix="chip"
75
78
  label="${tooltipLabel}"
@@ -108,15 +111,21 @@ class FtReaderMetadata extends withDateFormat(withI18n(FtReaderComponent)) {
108
111
  return this.noValueMessage;
109
112
  }
110
113
  renderRelativeItem(result, metadata) {
114
+ var _a, _b;
115
+ const translatedMetadata = this.translateValues
116
+ ? (_b = new MetadataValueLocalizer((_a = this.availableContentLocales) !== null && _a !== void 0 ? _a : []).localize(metadata)) !== null && _b !== void 0 ? _b : metadata
117
+ : metadata;
111
118
  return html `
112
119
  <a part="relative-item-link"
113
120
  href="${getResultUrl(result)}"
114
121
  @click=${(e) => this.addTopicPivotParam(e, result)}>
115
122
  <ft-ripple part="relative-item-ripple"></ft-ripple>
116
- <ft-floating-menu-item part="relative-item" value="${metadata.value}" notFocusable>
117
- ${metadata.value == null || metadata.value === metadata.displayValue ? metadata.displayValue : html `
118
- <ft-tooltip part="relative-item-tooltip" text="${(metadata.value)}">${metadata.displayValue}</ft-tooltip>
119
- `}
123
+ <ft-floating-menu-item part="relative-item" value="${translatedMetadata.value}" notFocusable>
124
+ ${translatedMetadata.value == null || translatedMetadata.value === translatedMetadata.displayValue
125
+ ? translatedMetadata.displayValue
126
+ : html `
127
+ <ft-tooltip part="relative-item-tooltip" text="${(translatedMetadata.value)}">${translatedMetadata.displayValue}</ft-tooltip>
128
+ `}
120
129
  </ft-floating-menu-item>
121
130
  </a>
122
131
  `;
@@ -135,15 +144,14 @@ class FtReaderMetadata extends withDateFormat(withI18n(FtReaderComponent)) {
135
144
  return nothing;
136
145
  }
137
146
  addTopicPivotParam(e, result) {
138
- var _a, _b;
139
147
  const currentTocId = this.stateManager.store.getState().visibleTopics[0];
140
148
  if (currentTocId && result.type == "MAP") {
141
149
  e.stopPropagation();
142
150
  e.preventDefault();
143
- const tocNode = (_a = this.service) === null || _a === void 0 ? void 0 : _a.getTocNodeNow(currentTocId);
144
- (_b = this.service) === null || _b === void 0 ? void 0 : _b.getTopicInfo(tocNode).then((topicInfo) => {
145
- const topicPivotMetadataValue = topicInfo === null || topicInfo === void 0 ? void 0 : topicInfo.metadata.find((metadata) => metadata.key == this.relativeTopicPivotMetadata);
146
- let url = new URL(getResultUrl(result));
151
+ const tocNode = this.service.getTocNodeNow(currentTocId);
152
+ this.service.getTopicInfo(tocNode).then(topicInfo => {
153
+ const topicPivotMetadataValue = topicInfo === null || topicInfo === void 0 ? void 0 : topicInfo.metadata.find(metadata => metadata.key == this.relativeTopicPivotMetadata);
154
+ const url = new URL(getResultUrl(result));
147
155
  if (topicPivotMetadataValue) {
148
156
  topicPivotMetadataValue.values.forEach(value => url.searchParams.append("topicPivot", value));
149
157
  }
@@ -157,9 +165,9 @@ class FtReaderMetadata extends withDateFormat(withI18n(FtReaderComponent)) {
157
165
  });
158
166
  }
159
167
  }
160
- update(props) {
161
- var _a, _b, _c, _d;
162
- super.update(props);
168
+ willUpdate(props) {
169
+ var _a, _b, _c, _d, _e;
170
+ super.willUpdate(props);
163
171
  if (props.has("key") && this.useForSwitchingToRelatives) {
164
172
  if (props.get("key")) {
165
173
  (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.unregisterMetadataForSwitchToRelatives(props.get("key"));
@@ -176,10 +184,13 @@ class FtReaderMetadata extends withDateFormat(withI18n(FtReaderComponent)) {
176
184
  (_d = this.stateManager) === null || _d === void 0 ? void 0 : _d.unregisterMetadataForSwitchToRelatives(this.key);
177
185
  }
178
186
  }
179
- if (props.has("metadata") || props.has("hierarchicalValueTruncatingLevel") || this.dateFormatOptionsChanged(props)) {
187
+ if (props.has("translateValues") || props.has("metadata") || props.has("hierarchicalValueTruncatingLevel") || this.dateFormatOptionsChanged(props)) {
180
188
  this.flatMetadata = this.metadata
181
189
  ? ClusteringHelper.flattenMetadata(this.metadata, this.hierarchicalValueTruncatingLevel, this.getDateFormatter(this.metadata.key))
182
190
  : undefined;
191
+ if (this.translateValues) {
192
+ this.flatMetadata = new MetadataValueLocalizer((_e = this.availableContentLocales) !== null && _e !== void 0 ? _e : []).localize(this.flatMetadata);
193
+ }
183
194
  }
184
195
  }
185
196
  get metadataLabel() {
@@ -221,6 +232,9 @@ __decorate([
221
232
  __decorate([
222
233
  property({ attribute: false })
223
234
  ], FtReaderMetadata.prototype, "editorMode", void 0);
235
+ __decorate([
236
+ property({ type: Boolean })
237
+ ], FtReaderMetadata.prototype, "translateValues", void 0);
224
238
  __decorate([
225
239
  redux({ store: "reader", 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); } })
226
240
  ], FtReaderMetadata.prototype, "metadata", void 0);
@@ -236,6 +250,9 @@ __decorate([
236
250
  __decorate([
237
251
  state()
238
252
  ], FtReaderMetadata.prototype, "relatives", void 0);
253
+ __decorate([
254
+ redux({ store: FtAppInfoStoreName })
255
+ ], FtReaderMetadata.prototype, "availableContentLocales", void 0);
239
256
  __decorate([
240
257
  i18n(readerMetadataContext.properties.itemWithNoValueForSwitchToRelatives())
241
258
  ], FtReaderMetadata.prototype, "noValueMessage", void 0);