@fluid-topics/ft-reader-context 1.1.26 → 1.1.28

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/models.d.ts CHANGED
@@ -37,3 +37,6 @@ export declare class NotFoundErrorEvent extends Event {
37
37
  export declare class UnauthorizedErrorEvent extends Event {
38
38
  constructor();
39
39
  }
40
+ export declare class TopicRelativeNotFoundEvent extends Event {
41
+ constructor();
42
+ }
package/build/models.js CHANGED
@@ -28,3 +28,8 @@ export class UnauthorizedErrorEvent extends Event {
28
28
  super("ft-reader-map-unauthorized");
29
29
  }
30
30
  }
31
+ export class TopicRelativeNotFoundEvent extends Event {
32
+ constructor() {
33
+ super("ft-reader-topic-relative-not-found", { bubbles: true, composed: true });
34
+ }
35
+ }
@@ -1,8 +1,12 @@
1
+ import { ClusteringHelper } from "@fluid-topics/ft-wc-utils";
1
2
  import { FtReaderReduxStore } from "./redux";
2
3
  import type { FtReaderService } from "./utils/FtReaderService";
4
+ import { FtMetadata } from "@fluid-topics/public-api";
3
5
  export declare class FtReaderStateManager {
4
6
  store: FtReaderReduxStore;
5
7
  static build(id: string, serviceProvider?: () => Promise<FtReaderService>): FtReaderStateManager;
8
+ metadataForSwitchToRelatives: Set<string>;
9
+ clusteringHelper?: ClusteringHelper;
6
10
  service?: FtReaderService;
7
11
  errorHandler?: (e: Error) => void;
8
12
  constructor(store: FtReaderReduxStore, serviceProvider: () => Promise<FtReaderService>);
@@ -19,5 +23,10 @@ export declare class FtReaderStateManager {
19
23
  clear(): void;
20
24
  reload(): Promise<void>;
21
25
  private fetchData;
26
+ private fetchRelatives;
27
+ private createClusteringHelper;
28
+ navigateToRelativeTopicIfFound(mapId?: string, topicPivotMetadataValue?: FtMetadata): Promise<void>;
22
29
  setSearchInDocumentQuery(query: string): void;
30
+ registerMetadataForSwitchToRelatives(id: string): void;
31
+ unregisterMetadataForSwitchToRelatives(id: string): void;
23
32
  }
@@ -1,12 +1,15 @@
1
- import { CanceledPromiseError, Debouncer, waitFor } from "@fluid-topics/ft-wc-utils";
1
+ import { CanceledPromiseError, ClusteringHelper, Debouncer, waitFor } from "@fluid-topics/ft-wc-utils";
2
2
  import { createReaderStore } from "./redux";
3
3
  import { FtOfficialReaderService } from "./utils/FtOfficialReaderService";
4
+ import { ftAppInfoStore } from "@fluid-topics/ft-app-context";
5
+ import { TopicRelativeNotFoundEvent } from "../models";
4
6
  export class FtReaderStateManager {
5
7
  static build(id, serviceProvider) {
6
8
  return new FtReaderStateManager(createReaderStore(id.trim() || "context"), serviceProvider !== null && serviceProvider !== void 0 ? serviceProvider : FtOfficialReaderService.build);
7
9
  }
8
10
  constructor(store, serviceProvider) {
9
11
  this.store = store;
12
+ this.metadataForSwitchToRelatives = new Set();
10
13
  this.loadDebouncer = new Debouncer(10);
11
14
  this.initService(serviceProvider);
12
15
  }
@@ -69,7 +72,10 @@ export class FtReaderStateManager {
69
72
  this.store.actions.pagesToc(undefined);
70
73
  this.store.actions.currentPage(undefined);
71
74
  this.store.actions.searchInDocumentQuery("");
75
+ this.store.actions.relatives(undefined);
72
76
  (_a = this.service) === null || _a === void 0 ? void 0 : _a.clear();
77
+ this.metadataForSwitchToRelatives = new Set();
78
+ this.clusteringHelper = undefined;
73
79
  }
74
80
  reload() {
75
81
  this.clear();
@@ -84,7 +90,11 @@ export class FtReaderStateManager {
84
90
  (_c = this.service) === null || _c === void 0 ? void 0 : _c.getToc().then(toc => this.store.actions.toc(toc)),
85
91
  (_d = this.service) === null || _d === void 0 ? void 0 : _d.getPagesToc().then(pagesToc => this.store.actions.pagesToc(pagesToc)),
86
92
  (_e = this.service) === null || _e === void 0 ? void 0 : _e.getPaginationConfiguration().then(conf => this.store.actions.paginationConfiguration(conf)),
87
- ]);
93
+ ]).then(() => {
94
+ if (this.metadataForSwitchToRelatives.size > 0) {
95
+ this.fetchRelatives();
96
+ }
97
+ });
88
98
  }
89
99
  catch (e) {
90
100
  if (this.errorHandler && !(e instanceof CanceledPromiseError)) {
@@ -92,7 +102,54 @@ export class FtReaderStateManager {
92
102
  }
93
103
  }
94
104
  }
105
+ fetchRelatives() {
106
+ var _a, _b, _c;
107
+ const relativeMetadataValues = (_a = this.store.getState().map) === null || _a === void 0 ? void 0 : _a.metadata.filter((metadata) => { var _a; return metadata.key == ((_a = this.store.getState().configuration) === null || _a === void 0 ? void 0 : _a.relativePivotMetadata); }).flatMap((metadata) => metadata.values);
108
+ if (relativeMetadataValues !== undefined && relativeMetadataValues.length > 0) {
109
+ (_b = this.service) === null || _b === void 0 ? void 0 : _b.getRelativesForDocument((_c = this.store.getState().configuration) === null || _c === void 0 ? void 0 : _c.relativePivotMetadata, relativeMetadataValues).then((searchResults) => {
110
+ const relatives = searchResults.results.flatMap((result) => result.entries);
111
+ this.store.actions.relatives(relatives);
112
+ this.createClusteringHelper();
113
+ });
114
+ }
115
+ }
116
+ createClusteringHelper() {
117
+ var _a, _b;
118
+ if (this.store.getState().relatives) {
119
+ this.clusteringHelper = new ClusteringHelper(this.store.getState().relatives, this.store.getState().relatives.find((relative) => { var _a; return ((_a = relative.map) === null || _a === void 0 ? void 0 : _a.mapId) == this.store.getState().mapId; }), this.metadataForSwitchToRelatives, (_b = (_a = ftAppInfoStore.getState().metadataConfiguration) === null || _a === void 0 ? void 0 : _a.descriptors) !== null && _b !== void 0 ? _b : []);
120
+ this.store.eventBus.dispatchEvent(new CustomEvent("clustering-helper-created"));
121
+ }
122
+ }
123
+ async navigateToRelativeTopicIfFound(mapId, topicPivotMetadataValue) {
124
+ var _a, _b, _c;
125
+ if (mapId && topicPivotMetadataValue) {
126
+ const relativeTopicPivotMetadata = this.store.getState().configuration.relativeTopicPivotMetadata;
127
+ const service = await this.awaitService();
128
+ const searchResults = await service.getRelativesForTopicInMap(mapId, relativeTopicPivotMetadata, topicPivotMetadataValue.values);
129
+ await this.setMapId(mapId);
130
+ if ((_c = (_b = (_a = searchResults === null || searchResults === void 0 ? void 0 : searchResults.results) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.entries) === null || _c === void 0 ? void 0 : _c[0]) {
131
+ const targetTocId = searchResults.results[0].entries[0].topic.tocId;
132
+ await this.navigateToTopic(targetTocId);
133
+ }
134
+ else {
135
+ this.store.eventBus.dispatchEvent(new TopicRelativeNotFoundEvent());
136
+ }
137
+ }
138
+ }
95
139
  setSearchInDocumentQuery(query) {
96
140
  this.store.actions.searchInDocumentQuery(query);
97
141
  }
142
+ registerMetadataForSwitchToRelatives(id) {
143
+ this.metadataForSwitchToRelatives.add(id);
144
+ if (this.store.getState().relatives == undefined) {
145
+ this.fetchRelatives();
146
+ }
147
+ else {
148
+ this.createClusteringHelper();
149
+ }
150
+ }
151
+ unregisterMetadataForSwitchToRelatives(id) {
152
+ this.metadataForSwitchToRelatives.delete(id);
153
+ this.createClusteringHelper();
154
+ }
98
155
  }
@@ -1,4 +1,4 @@
1
- import { FtMap, FtPaginationConfiguration, FtRatingType, FtRatingTypeKeys, FtReaderConfiguration, FtSession, FtTocNode, FtTopic, FtTopicRating } from "@fluid-topics/public-api";
1
+ import { FtMap, FtPaginationConfiguration, FtRatingType, FtRatingTypeKeys, FtReaderConfiguration, FtSearchResultClusterEntry, FtSession, FtTocNode, FtTopic, FtTopicRating } from "@fluid-topics/public-api";
2
2
  import { Optional } from "@fluid-topics/ft-wc-utils";
3
3
  export interface FtPagesTocNode {
4
4
  depth: number;
@@ -38,6 +38,7 @@ export interface FtReaderState {
38
38
  visibleTopics: string[];
39
39
  configuration: Optional<FtReaderConfiguration>;
40
40
  searchInDocumentQuery: Optional<string>;
41
+ relatives: Optional<Array<FtSearchResultClusterEntry>>;
41
42
  }
42
43
  export interface FtReaderNavigationData {
43
44
  mapId: string;
@@ -12,5 +12,6 @@ export const createReaderStore = (id) => FtReduxStore.get({
12
12
  scrollTarget: undefined,
13
13
  configuration: undefined,
14
14
  searchInDocumentQuery: undefined,
15
+ relatives: undefined,
15
16
  }
16
17
  });
@@ -1,4 +1,5 @@
1
1
  import type { FtMap, FtMapAttachment, FtPaginatedToc, FtRatingSummary, FtRatingType, FtRatingTypeKeys, FtTocNode, FtTopic } from "@fluid-topics/public-api";
2
+ import { FtSearchResults } from "@fluid-topics/public-api";
2
3
  import { FtReaderService } from "./FtReaderService";
3
4
  import { FtReaderFeatures } from "../model";
4
5
  export declare class FtOfficialReaderService extends FtReaderService {
@@ -11,6 +12,8 @@ export declare class FtOfficialReaderService extends FtReaderService {
11
12
  protected fetchTopicHTMLContent(tocNode: FtTocNode): Promise<string>;
12
13
  protected fetchTopicMetadata(tocNode: FtTocNode): Promise<FtTopic>;
13
14
  protected fetchAttachments(): Promise<Array<FtMapAttachment>>;
15
+ protected fetchRelativesForDocument(metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
16
+ protected fetchRelativesForTopicInMap(mapId: string, metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
14
17
  protected makeMapFeedbackRequest(message: string, from?: string): Promise<void>;
15
18
  protected makeRateMapRequest(type: FtRatingType | FtRatingTypeKeys, value: number): Promise<void>;
16
19
  protected makeRateTopicRequest(tocId: string, type: FtRatingType | FtRatingTypeKeys, value: number): Promise<void>;
@@ -31,6 +31,43 @@ export class FtOfficialReaderService extends FtReaderService {
31
31
  fetchAttachments() {
32
32
  return this.api.getMapAttachments(this.mapId).catch(() => []);
33
33
  }
34
+ fetchRelativesForDocument(metadataPivotKey, metadataPivotValues) {
35
+ return this.api.search({
36
+ query: "",
37
+ paging: { page: 1, perPage: -1 },
38
+ scope: "DOCUMENTS",
39
+ filters: [
40
+ {
41
+ negative: false,
42
+ values: metadataPivotValues,
43
+ key: metadataPivotKey
44
+ }
45
+ ],
46
+ sort: [],
47
+ facets: []
48
+ });
49
+ }
50
+ fetchRelativesForTopicInMap(mapId, metadataPivotKey, metadataPivotValues) {
51
+ return this.api.search({
52
+ query: "",
53
+ paging: { page: 1, perPage: 1 },
54
+ scope: "ALL_TOPICS",
55
+ filters: [
56
+ {
57
+ negative: false,
58
+ values: metadataPivotValues,
59
+ key: metadataPivotKey
60
+ },
61
+ {
62
+ negative: false,
63
+ values: [mapId],
64
+ key: "ft:publicationId",
65
+ }
66
+ ],
67
+ sort: [],
68
+ facets: []
69
+ });
70
+ }
34
71
  makeMapFeedbackRequest(message, from) {
35
72
  return this.api.sendMapFeedback(this.mapId, message, from);
36
73
  }
@@ -1,5 +1,5 @@
1
1
  import type { FluidTopicsApi, FtMap, FtMapAttachment, FtPaginatedToc, FtPaginationConfiguration, FtPublicationRatingSummary, FtRatingSummary, FtRatingTypeKeys, FtReaderConfiguration, FtTocNode, FtTopic } from "@fluid-topics/public-api";
2
- import { FtRatingType } from "@fluid-topics/public-api";
2
+ import { FtRatingType, FtSearchResults } from "@fluid-topics/public-api";
3
3
  import { CacheRegistry } from "@fluid-topics/ft-wc-utils";
4
4
  import { FtPagesTocNode, FtReaderFeatureAccessData, FtReaderFeatures, FtReaderNavigationData, FtReaderPage, FtReaderTocNode, FtTopicRatingSummary } from "../model";
5
5
  import { EnrichedToc, FtReaderConverter } from "./FtReaderConverter";
@@ -14,6 +14,8 @@ export declare abstract class FtReaderService {
14
14
  protected abstract fetchTopicMetadata(tocNode: FtTocNode): Promise<FtTopic>;
15
15
  protected abstract fetchTopicHTMLContent(tocNode: FtTocNode): Promise<string>;
16
16
  protected abstract fetchAttachments(): Promise<Array<FtMapAttachment>>;
17
+ protected abstract fetchRelativesForDocument(metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
18
+ protected abstract fetchRelativesForTopicInMap(mapId: string, metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
17
19
  protected abstract makeRateMapRequest(type: FtRatingType | FtRatingTypeKeys, value: number): Promise<void>;
18
20
  protected abstract makeUnrateMapRequest(): Promise<void>;
19
21
  protected abstract makeMapFeedbackRequest(message: string, from?: string): Promise<void>;
@@ -43,6 +45,8 @@ export declare abstract class FtReaderService {
43
45
  getTopicInfo(tocNode: FtTocNode): Promise<FtTopic>;
44
46
  getTopicContent(tocNode: FtTocNode): Promise<string>;
45
47
  getAttachments(): Promise<Array<FtMapAttachment>>;
48
+ getRelativesForDocument(metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
49
+ getRelativesForTopicInMap(mapId: string, metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
46
50
  getAttachmentDownloadLink(id: string): string;
47
51
  getLink(tocId?: string, pageNumber?: number, section?: string): string;
48
52
  getNavigationData(tocId?: string, pageNumber?: number, section?: string): FtReaderNavigationData;
@@ -83,6 +83,12 @@ export class FtReaderService {
83
83
  getAttachments() {
84
84
  return this.cache.get("map-attachments", () => this.fetchAttachments());
85
85
  }
86
+ getRelativesForDocument(metadataPivotKey, metadataPivotValues) {
87
+ return this.cache.get("document-relatives-" + metadataPivotKey + "-" + metadataPivotValues.join("-"), () => this.fetchRelativesForDocument(metadataPivotKey, metadataPivotValues));
88
+ }
89
+ getRelativesForTopicInMap(mapId, metadataPivotKey, metadataPivotValues) {
90
+ return this.cache.get("topic-relatives-" + [mapId, metadataPivotKey, ...metadataPivotValues].join("-"), () => this.fetchRelativesForTopicInMap(mapId, metadataPivotKey, metadataPivotValues));
91
+ }
86
92
  getAttachmentDownloadLink(id) {
87
93
  return this.makeAbsolute(`${this.api.endpoints.khub.maps.mapId(this.mapId).attachments.attachmentId(id).content}?download=true`);
88
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-reader-context",
3
- "version": "1.1.26",
3
+ "version": "1.1.28",
4
4
  "description": "Context block for integrated reader components",
5
5
  "keywords": [
6
6
  "Lit"
@@ -19,13 +19,13 @@
19
19
  "url": "ssh://git@scm.mrs.antidot.net:2222/fluidtopics/ft-web-components.git"
20
20
  },
21
21
  "dependencies": {
22
- "@fluid-topics/ft-app-context": "1.1.26",
23
- "@fluid-topics/ft-wc-utils": "1.1.26",
22
+ "@fluid-topics/ft-app-context": "1.1.28",
23
+ "@fluid-topics/ft-wc-utils": "1.1.28",
24
24
  "@reduxjs/toolkit": "^1.6.2",
25
25
  "lit": "3.1.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@fluid-topics/public-api": "1.0.56"
28
+ "@fluid-topics/public-api": "1.0.57"
29
29
  },
30
- "gitHead": "6734976f5a7f6b986917a085be0c38ca3ae562a0"
30
+ "gitHead": "8c1055ddd23e83efa3833f033a507aa1ab32fecc"
31
31
  }