@fluid-topics/ft-reader-context 2.2.36 → 2.2.38

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.
@@ -8,6 +8,7 @@ export declare class FtReaderStateManager {
8
8
  store: FtReaderReduxStore;
9
9
  private clusteringHelperProvider?;
10
10
  static build(id: string, serviceProvider?: () => Promise<FtReaderService>): FtReaderStateManager;
11
+ private readonly stickyFiltersIdWatcher;
11
12
  metadataForSwitchToRelatives: Set<string>;
12
13
  clusteringHelper?: ClusteringHelper;
13
14
  service?: FtReaderService;
@@ -17,9 +18,11 @@ export declare class FtReaderStateManager {
17
18
  loaded(): Promise<void>;
18
19
  constructor(store: FtReaderReduxStore, serviceProvider: () => Promise<FtReaderService>, clusteringHelperProvider?: (() => ClusteringHelper) | undefined, analyticsEventsService?: FtAnalyticsEventsService);
19
20
  initService(serviceProvider: () => Promise<FtReaderService>): Promise<void>;
21
+ removeListeners(): void;
20
22
  setMapId(mapId?: string): Promise<void>;
21
23
  setRenderedTopics(tocIds: string[]): void;
22
24
  setVisibleTopics(tocIds: string[]): void;
25
+ setApplyStickyFilters(apply: boolean): Promise<void>;
23
26
  setFilters(filters: FtMetadataFilter[]): Promise<void>;
24
27
  awaitService(): Promise<FtReaderService>;
25
28
  navigateToTopic(tocId?: string, section?: string, pageNumber?: number): Promise<void>;
@@ -32,6 +35,7 @@ export declare class FtReaderStateManager {
32
35
  clear(): void;
33
36
  reload(): Promise<void>;
34
37
  clearFromFilter(): void;
38
+ private reloadFromSticky;
35
39
  reloadFromFilter(section?: string, page?: number): Promise<void>;
36
40
  private fetchDataFromFilter;
37
41
  private fetchData;
@@ -1,5 +1,5 @@
1
1
  import { FtReaderStoreEvents, FtRequestedTopicFilteredEvent, } from "./model";
2
- import { accessResultUrl, CanceledPromiseError, ClusteringHelper, Debouncer, deepEqual, waitFor, waitUntil, } from "@fluid-topics/ft-wc-utils";
2
+ import { accessResultUrl, CanceledPromiseError, ClusteringHelper, Debouncer, deepEqual, ReduxWatcher, waitFor, waitUntil, } from "@fluid-topics/ft-wc-utils";
3
3
  import { createReaderStore, } from "./redux";
4
4
  import { FtOfficialReaderService } from "./utils/FtOfficialReaderService";
5
5
  import { FtAnalyticsEventsService, ftAppInfoStore, } from "@fluid-topics/ft-app-context";
@@ -20,14 +20,20 @@ export class FtReaderStateManager {
20
20
  this.loadDebouncer = new Debouncer(10);
21
21
  this.analyticsEventsService = analyticsEventsService !== null && analyticsEventsService !== void 0 ? analyticsEventsService : new FtAnalyticsEventsService();
22
22
  this.initService(serviceProvider);
23
+ this.stickyFiltersIdWatcher = new ReduxWatcher(ftAppInfoStore, (store) => { var _a; return (_a = store.stickyFilters) === null || _a === void 0 ? void 0 : _a.id; }, () => this.reloadFromSticky());
23
24
  }
24
25
  async initService(serviceProvider) {
26
+ var _a;
25
27
  this.service = await serviceProvider();
26
- const { mapId, metadataFilters } = this.store.getState();
28
+ const { mapId, metadataFilters, applyStickyFilters } = this.store.getState();
27
29
  this.service.mapId = mapId;
28
30
  this.service.metadataFilters = metadataFilters;
31
+ this.service.stickyFiltersId = applyStickyFilters ? (_a = ftAppInfoStore.getState().stickyFilters) === null || _a === void 0 ? void 0 : _a.id : undefined;
29
32
  return this.reload();
30
33
  }
34
+ removeListeners() {
35
+ this.stickyFiltersIdWatcher.stop();
36
+ }
31
37
  async setMapId(mapId) {
32
38
  if (mapId !== this.store.getState().mapId) {
33
39
  this.store.actions.mapId(mapId);
@@ -43,6 +49,18 @@ export class FtReaderStateManager {
43
49
  setVisibleTopics(tocIds) {
44
50
  this.store.actions.visibleTopics(tocIds);
45
51
  }
52
+ async setApplyStickyFilters(apply) {
53
+ if (apply) {
54
+ this.stickyFiltersIdWatcher.watch();
55
+ }
56
+ else {
57
+ this.stickyFiltersIdWatcher.stop();
58
+ }
59
+ if (apply != this.store.getState().applyStickyFilters) {
60
+ this.store.actions.applyStickyFilters(apply);
61
+ await this.reloadFromSticky();
62
+ }
63
+ }
46
64
  async setFilters(filters) {
47
65
  if (!deepEqual(filters, this.store.getState().metadataFilters)) {
48
66
  this.store.actions.metadataFilters(filters);
@@ -158,6 +176,15 @@ export class FtReaderStateManager {
158
176
  this.store.actions.toc(undefined);
159
177
  this.store.actions.pagesToc(undefined);
160
178
  }
179
+ async reloadFromSticky() {
180
+ var _a;
181
+ const { scrollTarget, applyStickyFilters, currentPage } = this.store.getState();
182
+ const newStickyFiltersId = applyStickyFilters ? (_a = ftAppInfoStore.getState().stickyFilters) === null || _a === void 0 ? void 0 : _a.id : undefined;
183
+ if (this.service && (this.service.stickyFiltersId != newStickyFiltersId)) {
184
+ this.service.stickyFiltersId = newStickyFiltersId;
185
+ await this.reloadFromFilter(scrollTarget === null || scrollTarget === void 0 ? void 0 : scrollTarget.section, currentPage === null || currentPage === void 0 ? void 0 : currentPage.number);
186
+ }
187
+ }
161
188
  async reloadFromFilter(section, page) {
162
189
  var _a, _b, _c;
163
190
  this.clearFromFilter();
@@ -69,6 +69,7 @@ export interface FtReaderState {
69
69
  };
70
70
  linkPreviewDialogId: Optional<string>;
71
71
  metadataFilters: Array<FtMetadataFilter>;
72
+ applyStickyFilters: boolean;
72
73
  }
73
74
  export interface FtReaderNavigationData {
74
75
  mapId: string;
@@ -48,6 +48,7 @@ export const createReaderStore = (id) => FtReduxStore.get({
48
48
  },
49
49
  linkPreviewDialogId: undefined,
50
50
  metadataFilters: [],
51
+ applyStickyFilters: false,
51
52
  },
52
53
  reducers: readerStoreStateReducers,
53
54
  });
@@ -7,7 +7,7 @@ export declare class FtOfficialReaderService extends FtReaderService {
7
7
  clear(): void;
8
8
  protected fetchMap(mapId: string, translationSettings?: FtTranslationSettings): Promise<FtMap>;
9
9
  protected fetchMapRating(mapId: string): Promise<FtRatingSummary>;
10
- protected fetchPages(mapId: string, metadataFilters?: FtMetadataFilter[], translationSettings?: FtTranslationSettings): Promise<FtPaginatedToc>;
10
+ protected fetchPages(mapId: string, metadataFilters?: FtMetadataFilter[], stickyFiltersId?: string, translationSettings?: FtTranslationSettings): Promise<FtPaginatedToc>;
11
11
  protected fetchTopicHTMLContent(tocNode: FtTocNode): Promise<string>;
12
12
  protected fetchTranslatedTopicHTMLContent(tocNode: FtTocNode, translationSettings: FtTranslationSettings): Promise<FtTranslationContent>;
13
13
  protected fetchTopicMetadata(tocNode: FtTocNode): Promise<FtTopic>;
@@ -17,7 +17,7 @@ export declare class FtOfficialReaderService extends FtReaderService {
17
17
  protected makeMapFeedbackRequest(message: string, from?: string): Promise<void>;
18
18
  protected makeRateMapRequest(type: FtRatingType | FtRatingTypeKeys, value: number): Promise<void>;
19
19
  protected makeRateTopicRequest(tocId: string, type: FtRatingType | FtRatingTypeKeys, value: number): Promise<void>;
20
- protected makeTopicFeedbackRequest(tocId: string, message: string, from?: string, metadataFilters?: FtMetadataFilter[]): Promise<void>;
20
+ protected makeTopicFeedbackRequest(tocId: string, message: string, from?: string, metadataFilters?: FtMetadataFilter[], stickyFiltersId?: string): Promise<void>;
21
21
  protected makeUnrateMapRequest(): Promise<void>;
22
22
  protected makeUnrateTopicRequest(tocId: string): Promise<void>;
23
23
  protected getReaderLinkPrefix(): string;
@@ -16,10 +16,10 @@ export class FtOfficialReaderService extends FtReaderService {
16
16
  fetchMapRating(mapId) {
17
17
  return this.api.getMapRating(mapId);
18
18
  }
19
- async fetchPages(mapId, metadataFilters, translationSettings) {
19
+ async fetchPages(mapId, metadataFilters, stickyFiltersId, translationSettings) {
20
20
  await this.getMap(translationSettings);
21
- return (metadataFilters === null || metadataFilters === void 0 ? void 0 : metadataFilters.length)
22
- ? this.api.getFilteredPages(mapId, translationSettings, metadataFilters)
21
+ return ((metadataFilters === null || metadataFilters === void 0 ? void 0 : metadataFilters.length) || stickyFiltersId)
22
+ ? this.api.getFilteredPages(mapId, translationSettings, metadataFilters, stickyFiltersId)
23
23
  : this.api.getPages(mapId, this.fingerprint, translationSettings);
24
24
  }
25
25
  fetchTopicHTMLContent(tocNode) {
@@ -88,8 +88,8 @@ export class FtOfficialReaderService extends FtReaderService {
88
88
  makeRateTopicRequest(tocId, type, value) {
89
89
  return this.api.rateTopic(this.mapId, tocId, type, value);
90
90
  }
91
- makeTopicFeedbackRequest(tocId, message, from, metadataFilters) {
92
- return this.api.sendTopicFeedback(this.mapId, tocId, message, from, metadataFilters);
91
+ makeTopicFeedbackRequest(tocId, message, from, metadataFilters, stickyFiltersId) {
92
+ return this.api.sendTopicFeedback(this.mapId, tocId, message, from, metadataFilters, stickyFiltersId);
93
93
  }
94
94
  makeUnrateMapRequest() {
95
95
  return this.api.unrateMap(this.mapId);
@@ -4,10 +4,17 @@ import { FtPagesTocNode, FtReaderFeatureAccessData, FtReaderFeatures, FtReaderNa
4
4
  import { FtReaderConverter } from "./FtReaderConverter";
5
5
  import { FtServiceWithCache } from "@fluid-topics/ft-app-context";
6
6
  import { FtReaderBreadcrumb } from "../../models";
7
+ export type ReaderLinkParameters = {
8
+ tocId?: string;
9
+ pageNumber?: number;
10
+ section?: string;
11
+ withMetadataFilter?: boolean;
12
+ withStickyFilters?: boolean;
13
+ };
7
14
  export declare abstract class FtReaderService extends FtServiceWithCache {
8
15
  protected converter: FtReaderConverter;
9
16
  protected abstract fetchMap(mapId: string, translationSettings?: FtTranslationSettings): Promise<FtMap>;
10
- protected abstract fetchPages(mapId: string, metadataFilters?: FtMetadataFilter[], translationSettings?: FtTranslationSettings): Promise<FtPaginatedToc>;
17
+ protected abstract fetchPages(mapId: string, metadataFilters?: FtMetadataFilter[], stickyFilterId?: string, translationSettings?: FtTranslationSettings): Promise<FtPaginatedToc>;
11
18
  protected abstract fetchMapRating(mapId: string): Promise<FtRatingSummary>;
12
19
  protected abstract fetchTopicMetadata(tocNode: FtTocNode): Promise<FtTopic>;
13
20
  protected abstract fetchTopicHTMLContent(tocNode: FtTocNode): Promise<string>;
@@ -20,11 +27,12 @@ export declare abstract class FtReaderService extends FtServiceWithCache {
20
27
  protected abstract makeMapFeedbackRequest(message: string, from?: string): Promise<void>;
21
28
  protected abstract makeRateTopicRequest(tocId: string, type: FtRatingType | FtRatingTypeKeys, value: number): Promise<void>;
22
29
  protected abstract makeUnrateTopicRequest(tocId: string): Promise<void>;
23
- protected abstract makeTopicFeedbackRequest(tocId: string, message: string, from?: string, metadataFilters?: FtMetadataFilter[]): Promise<void>;
30
+ protected abstract makeTopicFeedbackRequest(tocId: string, message: string, from?: string, metadataFilters?: FtMetadataFilter[], stickyFiltersId?: string): Promise<void>;
24
31
  protected abstract getReaderLinkPrefix(): string;
25
32
  protected abstract isFeatureAvailable(feature: FtReaderFeatures): boolean;
26
33
  private _mapId;
27
34
  private _metadataFilters;
35
+ stickyFiltersId?: string;
28
36
  get metadataFilters(): FtMetadataFilter[];
29
37
  set metadataFilters(value: FtMetadataFilter[] | undefined);
30
38
  get mapId(): string;
@@ -59,7 +67,8 @@ export declare abstract class FtReaderService extends FtServiceWithCache {
59
67
  getRelativesForDocument(metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
60
68
  getRelativesForTopicInMap(mapId: string, metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
61
69
  getAttachmentDownloadLink(id: string): string;
62
- getLink(tocId?: string, pageNumber?: number, section?: string, withMetadataFilter?: boolean): string;
70
+ getLink(tocId?: string, pageNumber?: number, section?: string, withMetadataFilter?: boolean, withStickyFilters?: boolean): string;
71
+ getLink(linkParams: ReaderLinkParameters): string;
63
72
  getLinkWithFilter(tocId?: string, pageNumber?: number, section?: string): string;
64
73
  getNavigationData(tocId?: string, pageNumber?: number, section?: string, translationInput?: FtTranslationSettings): FtReaderNavigationData;
65
74
  getAccurateNavigationData(tocId?: string, pageNumber?: number, section?: string, translationInput?: FtTranslationSettings): Promise<FtReaderNavigationData>;
@@ -73,7 +82,7 @@ export declare abstract class FtReaderService extends FtServiceWithCache {
73
82
  rateTopic(tocId: string, type: FtRatingType | FtRatingTypeKeys, value: number): Promise<void>;
74
83
  unrateTopic(tocId: string): Promise<void>;
75
84
  private clearRatingIfNecessary;
76
- sendTopicFeedback(tocId: string, message: string, from?: string, metadataFilters?: FtMetadataFilter[]): Promise<void>;
85
+ sendTopicFeedback(tocId: string, message: string, from?: string, metadataFilters?: FtMetadataFilter[], stickyFiltersId?: string): Promise<void>;
77
86
  fontsStylesheet(): string;
78
87
  themeStylesheet(): string;
79
88
  buildBreadcrumb(tocId: string, translationInput?: FtTranslationSettings): Array<FtReaderBreadcrumb>;
@@ -31,7 +31,8 @@ export class FtReaderService extends FtServiceWithCache {
31
31
  initCache() {
32
32
  this.cache.register("configuration", () => this.api.getReaderConfiguration());
33
33
  this.cache.register("map", () => this.withMapId((mapId) => this.fetchMap(mapId)));
34
- this.cache.register(this.makeCacheKey("enrichedToc", undefined, this.metadataFilters), () => this.withMapId((mapId) => this.fetchPages(mapId, this._metadataFilters).then((toc) => this.converter.convertPaginatedToc(mapId, toc))));
34
+ this.cache.register(this.makeCacheKey("enrichedToc", undefined, this.metadataFilters, this.stickyFiltersId), () => this.withMapId((mapId) => this.fetchPages(mapId, this._metadataFilters, this.stickyFiltersId)
35
+ .then((toc) => this.converter.convertPaginatedToc(mapId, toc))));
35
36
  this.cache.register("ratingSummary", () => {
36
37
  var _a;
37
38
  var _b;
@@ -42,10 +43,11 @@ export class FtReaderService extends FtServiceWithCache {
42
43
  clear() {
43
44
  this.cache.clearMatching((key) => key !== "configuration");
44
45
  }
45
- makeCacheKey(base, translationSettings, metadataFilters) {
46
+ makeCacheKey(base, translationSettings, metadataFilters, stickyFiltersId) {
46
47
  return base
47
48
  + (translationSettings ? "-destinationLanguage-" + (translationSettings === null || translationSettings === void 0 ? void 0 : translationSettings.destinationLanguage) : "")
48
- + (!metadataFilters || metadataFilters.length == 0 ? "" : "-metadataFilters-" + this.hash(metadataFilters));
49
+ + (!metadataFilters || metadataFilters.length == 0 ? "" : "-metadataFilters-" + this.hash(metadataFilters))
50
+ + (stickyFiltersId ? "-stickyFilters-" + stickyFiltersId : "");
49
51
  }
50
52
  getMap(translationSettings) {
51
53
  return this.cache.get(this.makeCacheKey("map", translationSettings), () => this.fetchMap(this.mapId, translationSettings));
@@ -60,10 +62,10 @@ export class FtReaderService extends FtServiceWithCache {
60
62
  this.cache.clear("configuration");
61
63
  }
62
64
  getEnrichedToc(translationSettings) {
63
- return this.cache.get(this.makeCacheKey("enrichedToc", translationSettings, this.metadataFilters), () => this.fetchPages(this.mapId, this.metadataFilters, translationSettings).then((toc) => this.converter.convertPaginatedToc(this.mapId, toc)));
65
+ return this.cache.get(this.makeCacheKey("enrichedToc", translationSettings, this.metadataFilters, this.stickyFiltersId), () => this.fetchPages(this.mapId, this.metadataFilters, this.stickyFiltersId, translationSettings).then((toc) => this.converter.convertPaginatedToc(this.mapId, toc)));
64
66
  }
65
67
  getEnrichedTocNow(translationSettings) {
66
- return this.cache.getNow(this.makeCacheKey("enrichedToc", translationSettings, this.metadataFilters));
68
+ return this.cache.getNow(this.makeCacheKey("enrichedToc", translationSettings, this.metadataFilters, this.stickyFiltersId));
67
69
  }
68
70
  async getPaginationConfiguration() {
69
71
  const enrichedToc = await this.getEnrichedToc();
@@ -142,7 +144,18 @@ export class FtReaderService extends FtServiceWithCache {
142
144
  getAttachmentDownloadLink(id) {
143
145
  return this.makeAbsolute(`${this.api.endpoints.khub.maps.mapId(this.mapId).attachments.attachmentId(id).content}?download=true&locationValue=reader`);
144
146
  }
145
- getLink(tocId, pageNumber, section, withMetadataFilter) {
147
+ getLink(tocIdOrParams, pageNumber, section, withMetadataFilter, withStickyFilters) {
148
+ let tocId;
149
+ if (typeof tocIdOrParams === "object") {
150
+ tocId = tocIdOrParams.tocId;
151
+ pageNumber = tocIdOrParams.pageNumber;
152
+ section = tocIdOrParams.section;
153
+ withMetadataFilter = tocIdOrParams.withMetadataFilter;
154
+ withStickyFilters = tocIdOrParams.withStickyFilters;
155
+ }
156
+ else {
157
+ tocId = tocIdOrParams;
158
+ }
146
159
  const navigationData = this.getNavigationData(tocId, pageNumber, section);
147
160
  const path = this.getReaderLinkPrefix() + (navigationData.prettyUrl ? navigationData.prettyUrl : `${navigationData.mapId}/${navigationData.tocId}`);
148
161
  const url = new URL(path, this.api.tenantBaseUrl);
@@ -161,6 +174,9 @@ export class FtReaderService extends FtServiceWithCache {
161
174
  url.searchParams.set(SearchPlaceQueryParams.VALUE_FILTERS, serializeFilters);
162
175
  }
163
176
  }
177
+ if (withStickyFilters && this.stickyFiltersId) {
178
+ url.searchParams.set(SearchPlaceQueryParams.STICKY_FILTER, this.stickyFiltersId);
179
+ }
164
180
  return url.href;
165
181
  }
166
182
  getLinkWithFilter(tocId, pageNumber, section) {
@@ -226,8 +242,8 @@ export class FtReaderService extends FtServiceWithCache {
226
242
  this.cache.clear("ratingSummary");
227
243
  }
228
244
  }
229
- sendTopicFeedback(tocId, message, from, metadataFilters) {
230
- return this.makeTopicFeedbackRequest(tocId, message, from, metadataFilters);
245
+ sendTopicFeedback(tocId, message, from, metadataFilters, stickyFiltersId) {
246
+ return this.makeTopicFeedbackRequest(tocId, message, from, metadataFilters, stickyFiltersId);
231
247
  }
232
248
  fontsStylesheet() {
233
249
  return this.api.makeAbsolute(this.api.endpoints.stylesheets.fonts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-reader-context",
3
- "version": "2.2.36",
3
+ "version": "2.2.38",
4
4
  "description": "Context block for integrated reader components",
5
5
  "keywords": [
6
6
  "Lit"
@@ -19,14 +19,14 @@
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": "2.2.36",
23
- "@fluid-topics/ft-search-context": "2.2.36",
24
- "@fluid-topics/ft-wc-utils": "2.2.36",
22
+ "@fluid-topics/ft-app-context": "2.2.38",
23
+ "@fluid-topics/ft-search-context": "2.2.38",
24
+ "@fluid-topics/ft-wc-utils": "2.2.38",
25
25
  "@reduxjs/toolkit": "2.13.0",
26
26
  "lit": "3.3.3"
27
27
  },
28
28
  "devDependencies": {
29
- "@fluid-topics/public-api": "1.0.148"
29
+ "@fluid-topics/public-api": "1.0.149"
30
30
  },
31
- "gitHead": "c3f0f16c05ce7b487f0b262fb8db45b9c2f69405"
31
+ "gitHead": "e28bf4c90c0be695d1bea56d97aba4295e17ee7b"
32
32
  }