@fluid-topics/ft-reader-metadata 1.1.27 → 1.1.29

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.
@@ -5,4 +5,17 @@ export const styles = css `
5
5
  :host {
6
6
  display: inline-block;
7
7
  }
8
+
9
+ .ft-reader-metadata--container {
10
+ position: relative;
11
+ }
12
+
13
+ .ft-reader-metadata--container ft-chip {
14
+ cursor: pointer;
15
+ }
16
+
17
+ a {
18
+ all: unset;
19
+ position: relative;
20
+ }
8
21
  `;
@@ -1,15 +1,28 @@
1
+ import { PropertyValues } from "lit";
1
2
  import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
2
3
  import { FtReaderMetadataProperties } from "./ft-reader-metadata.properties";
3
- import { FtReaderComponent } from "@fluid-topics/ft-reader-context/build/registration";
4
+ import { FtReaderComponent, FtReaderStateManager } from "@fluid-topics/ft-reader-context/build/registration";
4
5
  export declare class FtReaderMetadata extends FtReaderComponent implements FtReaderMetadataProperties {
5
6
  static elementDefinitions: ElementDefinitionsMap;
6
7
  static styles: import("lit").CSSResult;
7
8
  key?: string;
9
+ useForSwitchingToRelatives: boolean;
8
10
  editorMode: boolean;
9
11
  private metadata?;
12
+ private mapRelatives?;
13
+ private map?;
14
+ private relativeTopicPivotMetadata?;
15
+ private relatives;
16
+ setReaderStateManager(readerStateManager: FtReaderStateManager): void;
10
17
  protected render(): import("lit").TemplateResult<1>;
11
18
  private renderContent;
19
+ private renderSwitchToRelatives;
20
+ private renderRelativeItem;
21
+ private renderRelativeItemValue;
12
22
  private hideIfEmpty;
13
23
  private get valueText();
14
24
  private get tooltipText();
25
+ private addTopicPivotParam;
26
+ private setRelatives;
27
+ protected update(props: PropertyValues): void;
15
28
  }
@@ -5,29 +5,47 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { html, nothing } from "lit";
8
- import { property } from "lit/decorators.js";
8
+ import { property, state } from "lit/decorators.js";
9
9
  import { redux, reduxReactive } from "@fluid-topics/ft-wc-utils";
10
10
  import { styles } from "./ft-reader-metadata.css";
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";
15
+ import { getResultUrl } from "@fluid-topics/ft-search-result-context/build/utils";
16
+ import { repeat } from "lit/directives/repeat.js";
17
+ import { FtRipple } from "@fluid-topics/ft-ripple";
14
18
  class FtReaderMetadata extends FtReaderComponent {
15
19
  constructor() {
16
20
  super(...arguments);
21
+ this.useForSwitchingToRelatives = false;
17
22
  this.editorMode = false;
23
+ this.relatives = [];
24
+ }
25
+ setReaderStateManager(readerStateManager) {
26
+ var _a;
27
+ super.setReaderStateManager(readerStateManager);
28
+ if (this.key && this.useForSwitchingToRelatives) {
29
+ readerStateManager.registerMetadataForSwitchToRelatives(this.key);
30
+ }
31
+ (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.store.eventBus.addEventListener("clustering-helper-created", this.setRelatives);
18
32
  }
19
33
  render() {
20
34
  return html `
21
35
  <ft-tooltip text="${this.tooltipText}">
22
- <ft-chip>
23
- ${this.renderContent()}
24
- </ft-chip>
36
+ ${this.useForSwitchingToRelatives && this.metadata && this.metadata.values.length > 0
37
+ ? this.renderSwitchToRelatives()
38
+ : html `
39
+ <ft-chip>
40
+ ${this.renderContent()}
41
+ </ft-chip>
42
+ `}
25
43
  </ft-tooltip>
26
44
  ${this.hideIfEmpty()}
27
45
  `;
28
46
  }
29
47
  renderContent() {
30
- if (this.metadata) {
48
+ if (this.metadata && this.metadata.values.length > 0) {
31
49
  return html `${this.valueText}`;
32
50
  }
33
51
  if (this.editorMode) {
@@ -40,8 +58,35 @@ class FtReaderMetadata extends FtReaderComponent {
40
58
  }
41
59
  return nothing;
42
60
  }
61
+ renderSwitchToRelatives() {
62
+ return html `
63
+ <div class="ft-reader-metadata--container">
64
+ <ft-floating-menu text="Toggle collapsible" trailingIcon>
65
+ <ft-chip trailingIcon icon="thin_arrow" slot="toggle" clickable>
66
+ ${this.renderContent()}
67
+ </ft-chip>
68
+
69
+ ${repeat(this.relatives, relative => relative.metadata.value, relative => this.renderRelativeItem(relative.result, relative.metadata))}
70
+ </ft-floating-menu>
71
+ </div>
72
+ `;
73
+ }
74
+ renderRelativeItem(result, metadata) {
75
+ return html `
76
+ <a href=${getResultUrl(result)} @click=${(e) => this.addTopicPivotParam(e, result)}>
77
+ <ft-ripple></ft-ripple>
78
+ <ft-floating-menu-item value="${metadata.value}" notFocusable>
79
+ ${this.renderRelativeItemValue(metadata.value, metadata.displayValue)}
80
+ </ft-floating-menu-item>
81
+ </a>
82
+ `;
83
+ }
84
+ renderRelativeItemValue(value, displayValue) {
85
+ return value === displayValue ? value : html `
86
+ <ft-tooltip text="${value}">${displayValue}</ft-tooltip>`;
87
+ }
43
88
  hideIfEmpty() {
44
- if (!this.editorMode && !this.metadata) {
89
+ if (!this.editorMode && (!this.metadata || this.metadata.values.length == 0)) {
45
90
  return html `
46
91
  <style>
47
92
  :host {
@@ -60,20 +105,90 @@ class FtReaderMetadata extends FtReaderComponent {
60
105
  var _a, _b;
61
106
  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}` : "";
62
107
  }
108
+ addTopicPivotParam(e, result) {
109
+ var _a, _b;
110
+ const currentTocId = this.stateManager.store.getState().visibleTopics[0];
111
+ if (currentTocId && result.type == "MAP") {
112
+ e.stopPropagation();
113
+ e.preventDefault();
114
+ const tocNode = (_a = this.service) === null || _a === void 0 ? void 0 : _a.getTocNodeNow(currentTocId);
115
+ (_b = this.service) === null || _b === void 0 ? void 0 : _b.getTopicInfo(tocNode).then((topicInfo) => {
116
+ const topicPivotMetadataValue = topicInfo === null || topicInfo === void 0 ? void 0 : topicInfo.metadata.find((metadata) => metadata.key == this.relativeTopicPivotMetadata);
117
+ let url = new URL(getResultUrl(result));
118
+ if (topicPivotMetadataValue) {
119
+ topicPivotMetadataValue.values.forEach(value => url.searchParams.append("topicPivot", value));
120
+ }
121
+ const link = document.createElement("a");
122
+ link.href = url.toString();
123
+ if (e.ctrlKey || e.metaKey) {
124
+ link.target = "_blank";
125
+ }
126
+ this.append(link);
127
+ link.click();
128
+ });
129
+ }
130
+ }
131
+ setRelatives() {
132
+ var _a;
133
+ if (this.metadata && this.mapRelatives) {
134
+ this.relatives = this.stateManager.clusteringHelper.computeClustersItemsForMetadata(this.key, ((_a = this.map) === null || _a === void 0 ? void 0 : _a.lang) || "en");
135
+ }
136
+ }
137
+ update(props) {
138
+ var _a, _b, _c, _d;
139
+ super.update(props);
140
+ if ((props.has("metadata") || props.has("mapRelatives"))) {
141
+ this.setRelatives();
142
+ }
143
+ if (props.has("key") && this.useForSwitchingToRelatives) {
144
+ if (props.get("key")) {
145
+ (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.unregisterMetadataForSwitchToRelatives(props.get("key"));
146
+ }
147
+ if (this.key) {
148
+ (_b = this.stateManager) === null || _b === void 0 ? void 0 : _b.registerMetadataForSwitchToRelatives(this.key);
149
+ }
150
+ }
151
+ if (props.has("useForSwitchingToRelatives") && this.key) {
152
+ if (this.useForSwitchingToRelatives) {
153
+ (_c = this.stateManager) === null || _c === void 0 ? void 0 : _c.registerMetadataForSwitchToRelatives(this.key);
154
+ }
155
+ else {
156
+ (_d = this.stateManager) === null || _d === void 0 ? void 0 : _d.unregisterMetadataForSwitchToRelatives(this.key);
157
+ }
158
+ }
159
+ }
63
160
  }
64
161
  FtReaderMetadata.elementDefinitions = {
65
- "ft-tooltip": FtTooltip,
66
162
  "ft-chip": FtChip,
163
+ "ft-floating-menu": FtFloatingMenu,
164
+ "ft-floating-menu-item": FtFloatingMenuItem,
165
+ "ft-ripple": FtRipple,
166
+ "ft-tooltip": FtTooltip,
67
167
  };
68
168
  FtReaderMetadata.styles = styles;
69
169
  __decorate([
70
170
  property(),
71
171
  reduxReactive()
72
172
  ], FtReaderMetadata.prototype, "key", void 0);
173
+ __decorate([
174
+ property({ type: Boolean })
175
+ ], FtReaderMetadata.prototype, "useForSwitchingToRelatives", void 0);
73
176
  __decorate([
74
177
  property({ attribute: false })
75
178
  ], FtReaderMetadata.prototype, "editorMode", void 0);
76
179
  __decorate([
77
180
  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); } })
78
181
  ], FtReaderMetadata.prototype, "metadata", void 0);
182
+ __decorate([
183
+ redux({ selector: (s) => s.relatives })
184
+ ], FtReaderMetadata.prototype, "mapRelatives", void 0);
185
+ __decorate([
186
+ redux()
187
+ ], FtReaderMetadata.prototype, "map", void 0);
188
+ __decorate([
189
+ redux({ selector: (s) => { var _a; return (_a = s.configuration) === null || _a === void 0 ? void 0 : _a.relativeTopicPivotMetadata; } })
190
+ ], FtReaderMetadata.prototype, "relativeTopicPivotMetadata", void 0);
191
+ __decorate([
192
+ state()
193
+ ], FtReaderMetadata.prototype, "relatives", void 0);
79
194
  export { FtReaderMetadata };