@fluid-topics/ft-reader-context 1.2.34 → 1.2.36

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
@@ -10,6 +10,7 @@ export declare class MapLoadedEvent extends CustomEvent<MapLoadedEventDetail> {
10
10
  export interface FtReaderBreadcrumb {
11
11
  tocId: string;
12
12
  title: string;
13
+ untranslatedTitle?: string;
13
14
  }
14
15
  export interface FtReaderVisibleTopic {
15
16
  tocId: string;
@@ -1,6 +1,8 @@
1
+ import { FtReaderPage, FtReaderScrollTarget, FtReaderTocNode } from "./model";
1
2
  import { ClusteringHelper } from "@fluid-topics/ft-wc-utils";
2
3
  import { FtReaderReduxStore } from "./redux";
3
4
  import type { FtReaderService } from "./utils/FtReaderService";
5
+ import { FtTranslationLocale, FtTranslationSettings } from "@fluid-topics/public-api";
4
6
  export declare class FtReaderStateManager {
5
7
  store: FtReaderReduxStore;
6
8
  private clusteringHelperProvider?;
@@ -31,6 +33,17 @@ export declare class FtReaderStateManager {
31
33
  private createClusteringHelper;
32
34
  navigateToRelativeTopicIfFound(topicPivotMetadataValue: string): Promise<boolean>;
33
35
  setSearchInDocumentQuery(query: string): void;
36
+ setTranslationDestinationLanguage(destinationLanguage?: FtTranslationLocale): Promise<void>;
37
+ setTranslationSourceLanguage(sourceLanguage?: FtTranslationLocale): Promise<void>;
38
+ setTranslationProfileId(profileId?: string): Promise<void>;
39
+ setTranslationLoading(isLoading: boolean): Promise<void>;
40
+ setTranslationError(isError: boolean): Promise<void>;
41
+ getTranslationSettings(): FtTranslationSettings | undefined;
34
42
  registerMetadataForSwitchToRelatives(id: string): void;
35
43
  unregisterMetadataForSwitchToRelatives(id: string): void;
44
+ getAccurateNavigationData(tocId?: string, currentPage?: FtReaderPage, oldScrollTarget?: FtReaderScrollTarget): Promise<import("./model").FtReaderNavigationData>;
45
+ buildBreadcrumb(tocId: string): import("..").FtReaderBreadcrumb[] | undefined;
46
+ fetchTopicContent(tocNode: FtReaderTocNode): Promise<string> | undefined;
47
+ getTocNode(tocId: string): Promise<FtReaderTocNode>;
48
+ getPage(targetPageNumber: number): Promise<FtReaderPage>;
36
49
  }
@@ -43,12 +43,15 @@ export class FtReaderStateManager {
43
43
  async navigateToTopic(tocId, section, pageNumber) {
44
44
  await this.loaded();
45
45
  const service = await this.awaitService();
46
- const page = await (pageNumber != null ? service.getPage(pageNumber) : service.getPageByTocId(tocId !== null && tocId !== void 0 ? tocId : "root"));
46
+ const page = await (pageNumber != null
47
+ ? service.getPage(pageNumber, this.getTranslationSettings())
48
+ : service.getPageByTocId(tocId !== null && tocId !== void 0 ? tocId : "root", this.getTranslationSettings()));
47
49
  this.store.actions.currentPage(page);
48
- this.store.actions.scrollTarget({
49
- tocId: this.resolveValidNonRootTocId(tocId, page),
50
- section
51
- });
50
+ const nonRootTocId = this.resolveValidNonRootTocId(tocId, page);
51
+ this.store.actions.scrollTarget({ tocId: nonRootTocId, section });
52
+ if (this.store.getState().visibleTopics[0] !== nonRootTocId) {
53
+ this.store.actions.visibleTopics([]);
54
+ }
52
55
  }
53
56
  resolveValidNonRootTocId(tocId, page) {
54
57
  var _a, _b, _c;
@@ -61,7 +64,7 @@ export class FtReaderStateManager {
61
64
  async navigateToPage(pageNumber) {
62
65
  await this.loaded();
63
66
  const service = await this.awaitService();
64
- let page = await service.getPage(pageNumber);
67
+ let page = await service.getPage(pageNumber, this.getTranslationSettings());
65
68
  this.store.actions.currentPage(page);
66
69
  }
67
70
  scrollDone() {
@@ -70,7 +73,7 @@ export class FtReaderStateManager {
70
73
  async load() {
71
74
  var _a;
72
75
  if (((_a = this.service) === null || _a === void 0 ? void 0 : _a.mapId) && this.store.getState().map == null) {
73
- await this.loadDebouncer.run(() => this.fetchData());
76
+ await this.loadDebouncer.run(() => this.fetchData(this.getTranslationSettings()));
74
77
  }
75
78
  }
76
79
  clear() {
@@ -85,6 +88,13 @@ export class FtReaderStateManager {
85
88
  this.store.actions.relatives(undefined);
86
89
  this.store.actions.renderedTopics([]);
87
90
  this.store.actions.visibleTopics([]);
91
+ this.store.actions.translation({
92
+ sourceLanguage: undefined,
93
+ destinationLanguage: undefined,
94
+ profileId: undefined,
95
+ isLoading: false,
96
+ isError: false
97
+ });
88
98
  (_a = this.service) === null || _a === void 0 ? void 0 : _a.clear();
89
99
  this.clusteringHelper = undefined;
90
100
  }
@@ -92,20 +102,33 @@ export class FtReaderStateManager {
92
102
  this.clear();
93
103
  return this.load();
94
104
  }
95
- async fetchData() {
96
- var _a, _b, _c, _d, _e;
105
+ async fetchData(translationSettings) {
106
+ var _a, _b, _c, _d, _e, _f;
97
107
  try {
108
+ if (translationSettings) {
109
+ this.setTranslationLoading(true);
110
+ }
111
+ const handleTranslationError = (e) => {
112
+ if (translationSettings) {
113
+ this.setTranslationError(true);
114
+ }
115
+ throw e;
116
+ };
98
117
  await Promise.all([
99
118
  (_a = this.service) === null || _a === void 0 ? void 0 : _a.getConfiguration().then(conf => this.store.actions.configuration(conf)),
100
- (_b = this.service) === null || _b === void 0 ? void 0 : _b.getMap().then(map => this.store.actions.map(map)),
101
- (_c = this.service) === null || _c === void 0 ? void 0 : _c.getToc().then(toc => this.store.actions.toc(toc)),
102
- (_d = this.service) === null || _d === void 0 ? void 0 : _d.getPagesToc().then(pagesToc => this.store.actions.pagesToc(pagesToc)),
103
- (_e = this.service) === null || _e === void 0 ? void 0 : _e.getPaginationConfiguration().then(conf => this.store.actions.paginationConfiguration(conf)),
119
+ (_b = this.service) === null || _b === void 0 ? void 0 : _b.getMap(translationSettings).then(map => this.store.actions.map(map)).catch(handleTranslationError),
120
+ (_c = this.service) === null || _c === void 0 ? void 0 : _c.getToc(translationSettings).then(toc => this.store.actions.toc(toc)).catch(handleTranslationError),
121
+ (_d = this.service) === null || _d === void 0 ? void 0 : _d.getPagesToc(translationSettings).then(pagesToc => this.store.actions.pagesToc(pagesToc)).catch(handleTranslationError),
122
+ (_e = this.service) === null || _e === void 0 ? void 0 : _e.getPaginationConfiguration().then(conf => this.store.actions.paginationConfiguration(conf)).catch(handleTranslationError),
123
+ (_f = this.service) === null || _f === void 0 ? void 0 : _f.getTranslationError(translationSettings).then(translationError => this.setTranslationError(translationError))
104
124
  ]);
105
125
  if (this.metadataForSwitchToRelatives.size > 0) {
106
126
  this.fetchRelatives();
107
127
  }
108
128
  this._loaded = true;
129
+ if (translationSettings) {
130
+ this.setTranslationLoading(false);
131
+ }
109
132
  }
110
133
  catch (e) {
111
134
  if (this.errorHandler && !(e instanceof CanceledPromiseError)) {
@@ -166,6 +189,32 @@ export class FtReaderStateManager {
166
189
  setSearchInDocumentQuery(query) {
167
190
  this.store.actions.searchInDocumentQuery(query);
168
191
  }
192
+ async setTranslationDestinationLanguage(destinationLanguage) {
193
+ this.store.actions.setTranslationDestinationLanguage(destinationLanguage);
194
+ await this.loadDebouncer.run(() => this.fetchData(this.getTranslationSettings()));
195
+ }
196
+ async setTranslationSourceLanguage(sourceLanguage) {
197
+ this.store.actions.setTranslationSourceLanguage(sourceLanguage);
198
+ await this.loadDebouncer.run(() => this.fetchData(this.getTranslationSettings()));
199
+ }
200
+ async setTranslationProfileId(profileId) {
201
+ this.store.actions.setTranslationProfileId(profileId);
202
+ }
203
+ async setTranslationLoading(isLoading) {
204
+ this.store.actions.setTranslationLoading(isLoading);
205
+ }
206
+ async setTranslationError(isError) {
207
+ this.store.actions.setTranslationError(isError);
208
+ }
209
+ getTranslationSettings() {
210
+ var _a;
211
+ const state = this.store.getState();
212
+ return (state.translation.profileId && state.translation.destinationLanguage) ? {
213
+ profileId: state.translation.profileId,
214
+ destinationLanguage: state.translation.destinationLanguage.code,
215
+ sourceLanguage: (_a = state.map) === null || _a === void 0 ? void 0 : _a.lang
216
+ } : undefined;
217
+ }
169
218
  registerMetadataForSwitchToRelatives(id) {
170
219
  this.metadataForSwitchToRelatives.add(id);
171
220
  if (this.store.getState().relatives == undefined) {
@@ -179,4 +228,34 @@ export class FtReaderStateManager {
179
228
  this.metadataForSwitchToRelatives.delete(id);
180
229
  this.updateClusteringHelper();
181
230
  }
231
+ getAccurateNavigationData(tocId, currentPage, oldScrollTarget) {
232
+ return this.service.getAccurateNavigationData(tocId, currentPage === null || currentPage === void 0 ? void 0 : currentPage.number, oldScrollTarget === null || oldScrollTarget === void 0 ? void 0 : oldScrollTarget.section, this.getTranslationSettings());
233
+ }
234
+ buildBreadcrumb(tocId) {
235
+ var _a;
236
+ return (_a = this.service) === null || _a === void 0 ? void 0 : _a.buildBreadcrumb(tocId, this.getTranslationSettings());
237
+ }
238
+ fetchTopicContent(tocNode) {
239
+ var _a, _b;
240
+ var translationSettings = this.getTranslationSettings();
241
+ if (translationSettings) {
242
+ return (_a = this.service) === null || _a === void 0 ? void 0 : _a.getTranslatedTopicContent(tocNode, translationSettings).then(translationContent => {
243
+ if (translationContent.isTranslationError) {
244
+ this.setTranslationError(true);
245
+ }
246
+ return translationContent.content;
247
+ });
248
+ }
249
+ else {
250
+ return (_b = this.service) === null || _b === void 0 ? void 0 : _b.getTopicContent(tocNode);
251
+ }
252
+ }
253
+ getTocNode(tocId) {
254
+ var _a;
255
+ return (_a = this.service) === null || _a === void 0 ? void 0 : _a.getTocNode(tocId, this.getTranslationSettings());
256
+ }
257
+ getPage(targetPageNumber) {
258
+ var _a;
259
+ return (_a = this.service) === null || _a === void 0 ? void 0 : _a.getPage(targetPageNumber, this.getTranslationSettings());
260
+ }
182
261
  }
@@ -1,9 +1,10 @@
1
- import { FtMap, FtPaginationConfiguration, FtRatingType, FtRatingTypeKeys, FtReaderConfiguration, FtSearchResultClusterEntry, FtSession, FtTocNode, FtTopic, FtTopicRating } from "@fluid-topics/public-api";
1
+ import { FtMap, FtPaginationConfiguration, FtRatingType, FtRatingTypeKeys, FtReaderConfiguration, FtSearchResultClusterEntry, FtSession, FtTocNode, FtTopic, FtTopicRating, FtTranslationLocale } from "@fluid-topics/public-api";
2
2
  import { Optional } from "@fluid-topics/ft-wc-utils";
3
3
  export interface FtPagesTocNode {
4
4
  depth: number;
5
5
  tocId: string;
6
6
  title: string;
7
+ translatedTitle?: string;
7
8
  children: Array<FtPagesTocNode>;
8
9
  }
9
10
  export interface FtReaderTocNode extends FtTocNode {
@@ -14,6 +15,7 @@ export interface FtReaderTocNode extends FtTocNode {
14
15
  export interface FtReaderPage {
15
16
  number: number;
16
17
  title: string;
18
+ untranslatedTitle?: string;
17
19
  rootTocId: string;
18
20
  toc: Array<FtReaderTocNode>;
19
21
  topics: Array<string>;
@@ -40,11 +42,19 @@ export interface FtReaderState {
40
42
  configuration: Optional<FtReaderConfiguration>;
41
43
  searchInDocumentQuery: Optional<string>;
42
44
  relatives: Optional<Array<FtSearchResultClusterEntry>>;
45
+ translation: {
46
+ sourceLanguage: Optional<FtTranslationLocale>;
47
+ destinationLanguage: Optional<FtTranslationLocale>;
48
+ profileId: Optional<string>;
49
+ isLoading: boolean;
50
+ isError: boolean;
51
+ };
43
52
  }
44
53
  export interface FtReaderNavigationData {
45
54
  mapId: string;
46
55
  tocId: string;
47
56
  topicTitle: string;
57
+ untranslatedTopicTitle?: string;
48
58
  section?: string;
49
59
  page?: number;
50
60
  prettyUrl?: string;
@@ -1,4 +1,20 @@
1
1
  import { FtReaderState } from "./model";
2
- import { EmptyReducers, FtReduxStore } from "@fluid-topics/ft-wc-utils";
3
- export type FtReaderReduxStore = FtReduxStore<FtReaderState, EmptyReducers>;
4
- export declare const createReaderStore: (id: string) => FtReduxStore<FtReaderState, {}, import("redux").AnyAction>;
2
+ import { FtReduxStore } from "@fluid-topics/ft-wc-utils";
3
+ import { PayloadAction } from "@reduxjs/toolkit";
4
+ declare const readerStoreStateReducers: {
5
+ setTranslationDestinationLanguage: (state: FtReaderState, action: PayloadAction<FtReaderState["translation"]["destinationLanguage"]>) => void;
6
+ setTranslationSourceLanguage: (state: FtReaderState, action: PayloadAction<FtReaderState["translation"]["sourceLanguage"]>) => void;
7
+ setTranslationProfileId: (state: FtReaderState, action: PayloadAction<FtReaderState["translation"]["profileId"]>) => void;
8
+ setTranslationLoading: (state: FtReaderState, action: PayloadAction<FtReaderState["translation"]["isLoading"]>) => void;
9
+ setTranslationError: (state: FtReaderState, action: PayloadAction<FtReaderState["translation"]["isError"]>) => void;
10
+ };
11
+ export type FtReaderStateReducers = typeof readerStoreStateReducers;
12
+ export type FtReaderReduxStore = FtReduxStore<FtReaderState, FtReaderStateReducers>;
13
+ export declare const createReaderStore: (id: string) => FtReduxStore<FtReaderState, {
14
+ setTranslationDestinationLanguage: (state: FtReaderState, action: PayloadAction<FtReaderState["translation"]["destinationLanguage"]>) => void;
15
+ setTranslationSourceLanguage: (state: FtReaderState, action: PayloadAction<FtReaderState["translation"]["sourceLanguage"]>) => void;
16
+ setTranslationProfileId: (state: FtReaderState, action: PayloadAction<FtReaderState["translation"]["profileId"]>) => void;
17
+ setTranslationLoading: (state: FtReaderState, action: PayloadAction<FtReaderState["translation"]["isLoading"]>) => void;
18
+ setTranslationError: (state: FtReaderState, action: PayloadAction<FtReaderState["translation"]["isError"]>) => void;
19
+ }, import("redux").AnyAction>;
20
+ export {};
@@ -1,4 +1,21 @@
1
1
  import { FtReduxStore } from "@fluid-topics/ft-wc-utils";
2
+ const readerStoreStateReducers = {
3
+ setTranslationDestinationLanguage: (state, action) => {
4
+ state.translation.destinationLanguage = action.payload;
5
+ },
6
+ setTranslationSourceLanguage: (state, action) => {
7
+ state.translation.sourceLanguage = action.payload;
8
+ },
9
+ setTranslationProfileId: (state, action) => {
10
+ state.translation.profileId = action.payload;
11
+ },
12
+ setTranslationLoading: (state, action) => {
13
+ state.translation.isLoading = action.payload;
14
+ },
15
+ setTranslationError: (state, action) => {
16
+ state.translation.isError = action.payload;
17
+ },
18
+ };
2
19
  export const createReaderStore = (id) => FtReduxStore.get({
3
20
  name: "ft-reader-" + id,
4
21
  initialState: {
@@ -14,5 +31,13 @@ export const createReaderStore = (id) => FtReduxStore.get({
14
31
  configuration: undefined,
15
32
  searchInDocumentQuery: undefined,
16
33
  relatives: undefined,
17
- }
34
+ translation: {
35
+ sourceLanguage: undefined,
36
+ destinationLanguage: undefined,
37
+ profileId: undefined,
38
+ isLoading: false,
39
+ isError: false
40
+ }
41
+ },
42
+ reducers: readerStoreStateReducers
18
43
  });
@@ -1,14 +1,15 @@
1
- import type { FtMap, FtMapAttachment, FtPaginatedToc, FtRatingSummary, FtRatingType, FtRatingTypeKeys, FtSearchResults, FtTocNode, FtTopic } from "@fluid-topics/public-api";
1
+ import type { FtMap, FtMapAttachment, FtPaginatedToc, FtRatingSummary, FtRatingType, FtRatingTypeKeys, FtSearchResults, FtTocNode, FtTopic, FtTranslationContent, FtTranslationSettings } from "@fluid-topics/public-api";
2
2
  import { FtReaderService } from "./FtReaderService";
3
3
  import { FtReaderFeatures } from "../model";
4
4
  export declare class FtOfficialReaderService extends FtReaderService {
5
5
  protected fingerprint?: string;
6
6
  static build(mapId?: string): Promise<FtOfficialReaderService>;
7
7
  clear(): void;
8
- protected fetchMap(mapId: string): Promise<FtMap>;
8
+ protected fetchMap(mapId: string, translationSettings?: FtTranslationSettings): Promise<FtMap>;
9
9
  protected fetchMapRating(mapId: string): Promise<FtRatingSummary>;
10
- protected fetchPages(mapId: string): Promise<FtPaginatedToc>;
10
+ protected fetchPages(mapId: string, translationSettings?: FtTranslationSettings): Promise<FtPaginatedToc>;
11
11
  protected fetchTopicHTMLContent(tocNode: FtTocNode): Promise<string>;
12
+ protected fetchTranslatedTopicHTMLContent(tocNode: FtTocNode, translationSettings: FtTranslationSettings): Promise<FtTranslationContent>;
12
13
  protected fetchTopicMetadata(tocNode: FtTocNode): Promise<FtTopic>;
13
14
  protected fetchAttachments(): Promise<Array<FtMapAttachment>>;
14
15
  protected fetchRelativesForDocument(metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
@@ -8,21 +8,24 @@ export class FtOfficialReaderService extends FtReaderService {
8
8
  super.clear();
9
9
  this.fingerprint = undefined;
10
10
  }
11
- async fetchMap(mapId) {
12
- const map = await this.api.getMap(mapId);
11
+ async fetchMap(mapId, translationSettings) {
12
+ const map = await this.api.getMap(mapId, translationSettings);
13
13
  this.fingerprint = map.fingerprint;
14
14
  return map;
15
15
  }
16
16
  fetchMapRating(mapId) {
17
17
  return this.api.getMapRating(mapId);
18
18
  }
19
- async fetchPages(mapId) {
20
- await this.getMap();
21
- return this.api.getPages(mapId, this.fingerprint);
19
+ async fetchPages(mapId, translationSettings) {
20
+ await this.getMap(translationSettings);
21
+ return this.api.getPages(mapId, this.fingerprint, translationSettings);
22
22
  }
23
23
  fetchTopicHTMLContent(tocNode) {
24
24
  return this.api.getTopicHTMLContent(this.mapId, tocNode.contentId, "DESIGNED_READER", this.fingerprint);
25
25
  }
26
+ fetchTranslatedTopicHTMLContent(tocNode, translationSettings) {
27
+ return this.api.getTranslatedTopicHTMLContent(this.mapId, tocNode.contentId, "DESIGNED_READER", this.fingerprint, translationSettings);
28
+ }
26
29
  fetchTopicMetadata(tocNode) {
27
30
  return this.api.getTopic(this.mapId, tocNode.contentId, this.fingerprint);
28
31
  }
@@ -9,6 +9,7 @@ export type EnrichedToc = {
9
9
  duplicatedPrettyUrls: Set<string>;
10
10
  pages: Array<FtReaderPage>;
11
11
  pageByTocId: Record<string, FtReaderPage>;
12
+ translationError: boolean;
12
13
  };
13
14
  export declare class FtReaderConverter {
14
15
  convertPaginatedToc(mapId: string, paginatedToc: FtPaginatedToc): EnrichedToc;
@@ -18,10 +18,12 @@ class EnrichedTocBuilder {
18
18
  duplicatedPrettyUrls: this.duplicatedPrettyUrls,
19
19
  pages: this.pages,
20
20
  pageByTocId: this.pageByTocId,
21
+ translationError: this.paginatedToc.translationError
21
22
  };
22
23
  }
23
24
  extractPagesToc(nodes, depth, parentTocId) {
24
25
  return nodes.flatMap(node => {
26
+ var _a;
25
27
  if (node.pageConfiguration) {
26
28
  this.registerPage(this.buildPage(node, parentTocId));
27
29
  }
@@ -31,7 +33,8 @@ class EnrichedTocBuilder {
31
33
  return [
32
34
  {
33
35
  tocId: node.tocId,
34
- title: node.title,
36
+ title: (_a = node.title) !== null && _a !== void 0 ? _a : "",
37
+ untranslatedTitle: node.untranslatedTitle,
35
38
  depth,
36
39
  children: this.extractPagesToc(node.children, depth + 1, node.tocId)
37
40
  }
@@ -52,6 +55,7 @@ class EnrichedTocBuilder {
52
55
  tocId: node.tocId,
53
56
  contentId: node.contentId,
54
57
  title: node.title,
58
+ untranslatedTitle: node.untranslatedTitle,
55
59
  hasRating: node.hasRating,
56
60
  origin: node.origin,
57
61
  prettyUrl,
@@ -90,6 +94,7 @@ class EnrichedTocBuilder {
90
94
  const page = {
91
95
  number: this.pages.length + 1,
92
96
  title: (_a = node.title) !== null && _a !== void 0 ? _a : "",
97
+ untranslatedTitle: node.untranslatedTitle,
93
98
  rootTocId: (_b = node.tocId) !== null && _b !== void 0 ? _b : "root",
94
99
  toc: ((_c = node.pageToc) !== null && _c !== void 0 ? _c : []).map((n) => this.nodeByTocId[n.tocId]),
95
100
  topics: [],
@@ -1,16 +1,17 @@
1
- import type { FluidTopicsApi, FtMap, FtMapAttachment, FtPaginatedToc, FtPaginationConfiguration, FtPublicationRatingSummary, FtRatingSummary, FtRatingTypeKeys, FtReaderConfiguration, FtTocNode, FtTopic } from "@fluid-topics/public-api";
1
+ import type { FluidTopicsApi, FtMap, FtMapAttachment, FtPaginatedToc, FtPaginationConfiguration, FtPublicationRatingSummary, FtRatingSummary, FtRatingTypeKeys, FtReaderConfiguration, FtTocNode, FtTopic, FtTranslationContent, FtTranslationSettings } from "@fluid-topics/public-api";
2
2
  import { FtRatingType, FtSearchResults } from "@fluid-topics/public-api";
3
3
  import { FtPagesTocNode, FtReaderFeatureAccessData, FtReaderFeatures, FtReaderNavigationData, FtReaderPage, FtReaderTocNode, FtTopicRatingSummary } from "../model";
4
- import { EnrichedToc, FtReaderConverter } from "./FtReaderConverter";
4
+ import { FtReaderConverter } from "./FtReaderConverter";
5
5
  import { FtServiceWithCache } from "@fluid-topics/ft-app-context";
6
6
  import { FtReaderBreadcrumb } from "../../models";
7
7
  export declare abstract class FtReaderService extends FtServiceWithCache {
8
8
  protected converter: FtReaderConverter;
9
- protected abstract fetchMap(mapId: string): Promise<FtMap>;
10
- protected abstract fetchPages(mapId: string): Promise<FtPaginatedToc>;
9
+ protected abstract fetchMap(mapId: string, translationSettings?: FtTranslationSettings): Promise<FtMap>;
10
+ protected abstract fetchPages(mapId: string, translationSettings?: FtTranslationSettings): Promise<FtPaginatedToc>;
11
11
  protected abstract fetchMapRating(mapId: string): Promise<FtRatingSummary>;
12
12
  protected abstract fetchTopicMetadata(tocNode: FtTocNode): Promise<FtTopic>;
13
13
  protected abstract fetchTopicHTMLContent(tocNode: FtTocNode): Promise<string>;
14
+ protected abstract fetchTranslatedTopicHTMLContent(tocNode: FtTocNode, translationSettings: FtTranslationSettings): Promise<FtTranslationContent>;
14
15
  protected abstract fetchAttachments(): Promise<Array<FtMapAttachment>>;
15
16
  protected abstract fetchRelativesForDocument(metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
16
17
  protected abstract fetchRelativesForTopicInMap(mapId: string, metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
@@ -29,28 +30,31 @@ export declare abstract class FtReaderService extends FtServiceWithCache {
29
30
  private withMapId;
30
31
  private initCache;
31
32
  clear(): void;
32
- getMap(): Promise<FtMap>;
33
- getMapNow(): FtMap | undefined;
33
+ private makeCacheKey;
34
+ getMap(translationSettings?: FtTranslationSettings): Promise<FtMap>;
35
+ getMapNow(translationSettings?: FtTranslationSettings): FtMap | undefined;
34
36
  getConfiguration(): Promise<FtReaderConfiguration>;
35
37
  private getEnrichedToc;
36
- get enrichedToc(): EnrichedToc | undefined;
38
+ private getEnrichedTocNow;
37
39
  getPaginationConfiguration(): Promise<FtPaginationConfiguration>;
38
- getToc(): Promise<Array<FtReaderTocNode>>;
39
- getPagesToc(): Promise<Array<FtPagesTocNode>>;
40
- getTocNode(tocId: string): Promise<FtReaderTocNode>;
41
- getTocNodeNow(tocId: string): FtReaderTocNode | undefined;
42
- getTocNodeNowByUrl(prettyUrlOrMapIdTocId: string): FtReaderTocNode | undefined;
43
- getPage(number: number): Promise<FtReaderPage>;
44
- getPageByTocId(tocId: string): Promise<FtReaderPage>;
40
+ getToc(translationSettings?: FtTranslationSettings): Promise<Array<FtReaderTocNode>>;
41
+ getPagesToc(translationSettings?: FtTranslationSettings): Promise<Array<FtPagesTocNode>>;
42
+ getTranslationError(translationSettings?: FtTranslationSettings): Promise<boolean>;
43
+ getTocNode(tocId: string, translationSettings?: FtTranslationSettings): Promise<FtReaderTocNode>;
44
+ getTocNodeNow(tocId: string, translationInput?: FtTranslationSettings): FtReaderTocNode | undefined;
45
+ getTocNodeNowByUrl(prettyUrlOrMapIdTocId: string, translationInput?: FtTranslationSettings): FtReaderTocNode | undefined;
46
+ getPage(number: number, translationInput?: FtTranslationSettings): Promise<FtReaderPage>;
47
+ getPageByTocId(tocId: string, translationInput?: FtTranslationSettings): Promise<FtReaderPage>;
45
48
  getTopicInfo(tocNode: FtTocNode): Promise<FtTopic>;
46
49
  getTopicContent(tocNode: FtTocNode): Promise<string>;
50
+ getTranslatedTopicContent(tocNode: FtTocNode, translationInput: FtTranslationSettings): Promise<FtTranslationContent>;
47
51
  getAttachments(): Promise<Array<FtMapAttachment>>;
48
52
  getRelativesForDocument(metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
49
53
  getRelativesForTopicInMap(mapId: string, metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
50
54
  getAttachmentDownloadLink(id: string): string;
51
55
  getLink(tocId?: string, pageNumber?: number, section?: string): string;
52
- getNavigationData(tocId?: string, pageNumber?: number, section?: string): FtReaderNavigationData;
53
- getAccurateNavigationData(tocId?: string, pageNumber?: number, section?: string): Promise<FtReaderNavigationData>;
56
+ getNavigationData(tocId?: string, pageNumber?: number, section?: string, translationInput?: FtTranslationSettings): FtReaderNavigationData;
57
+ getAccurateNavigationData(tocId?: string, pageNumber?: number, section?: string, translationInput?: FtTranslationSettings): Promise<FtReaderNavigationData>;
54
58
  private getRatingSummary;
55
59
  reloadRating(): Promise<FtRatingSummary>;
56
60
  getMapRating(): Promise<FtPublicationRatingSummary | undefined>;
@@ -64,7 +68,7 @@ export declare abstract class FtReaderService extends FtServiceWithCache {
64
68
  sendTopicFeedback(tocId: string, message: string, from?: string): Promise<void>;
65
69
  fontsStylesheet(): string;
66
70
  themeStylesheet(): string;
67
- buildBreadcrumb(tocId: string): Array<FtReaderBreadcrumb>;
71
+ buildBreadcrumb(tocId: string, translationInput?: FtTranslationSettings): Array<FtReaderBreadcrumb>;
68
72
  isFeatureAccessible(feature: FtReaderFeatures, { session }: FtReaderFeatureAccessData): boolean;
69
73
  makeAbsolute(endpoint: string): string;
70
74
  }
@@ -33,55 +33,62 @@ export class FtReaderService extends FtServiceWithCache {
33
33
  clear() {
34
34
  this.cache.clearAll();
35
35
  }
36
- getMap() {
37
- return this.cache.get("map");
36
+ makeCacheKey(base, translationSettings) {
37
+ return base + (translationSettings ? "-destinationLanguage-" + (translationSettings === null || translationSettings === void 0 ? void 0 : translationSettings.destinationLanguage) : "");
38
38
  }
39
- getMapNow() {
40
- return this.cache.getNow("map");
39
+ getMap(translationSettings) {
40
+ return this.cache.get(this.makeCacheKey("map", translationSettings), () => this.fetchMap(this.mapId, translationSettings));
41
+ }
42
+ getMapNow(translationSettings) {
43
+ return this.cache.getNow(this.makeCacheKey("map", translationSettings));
41
44
  }
42
45
  getConfiguration() {
43
46
  return this.cache.get("configuration");
44
47
  }
45
- getEnrichedToc() {
46
- return this.cache.get("enrichedToc");
48
+ getEnrichedToc(translationSettings) {
49
+ return this.cache.get(this.makeCacheKey("enrichedToc", translationSettings), () => this.fetchPages(this.mapId, translationSettings).then(toc => this.converter.convertPaginatedToc(this.mapId, toc)));
47
50
  }
48
- get enrichedToc() {
49
- return this.cache.getNow("enrichedToc");
51
+ getEnrichedTocNow(translationSettings) {
52
+ return this.cache.getNow(this.makeCacheKey("enrichedToc", translationSettings));
50
53
  }
51
54
  async getPaginationConfiguration() {
52
55
  const enrichedToc = await this.getEnrichedToc();
53
56
  return enrichedToc.paginationConfiguration;
54
57
  }
55
- async getToc() {
56
- const enrichedToc = await this.getEnrichedToc();
58
+ async getToc(translationSettings) {
59
+ const enrichedToc = await this.getEnrichedToc(translationSettings);
57
60
  return enrichedToc.toc;
58
61
  }
59
- async getPagesToc() {
60
- const enrichedToc = await this.getEnrichedToc();
62
+ async getPagesToc(translationSettings) {
63
+ const enrichedToc = await this.getEnrichedToc(translationSettings);
61
64
  return enrichedToc.pagesToc;
62
65
  }
63
- async getTocNode(tocId) {
64
- const enrichedToc = await this.getEnrichedToc();
66
+ async getTranslationError(translationSettings) {
67
+ const enrichedToc = await this.getEnrichedToc(translationSettings);
68
+ return enrichedToc.translationError;
69
+ }
70
+ async getTocNode(tocId, translationSettings) {
71
+ const enrichedToc = await this.getEnrichedToc(translationSettings);
65
72
  return enrichedToc.nodeByTocId[tocId];
66
73
  }
67
- getTocNodeNow(tocId) {
74
+ getTocNodeNow(tocId, translationInput) {
68
75
  var _a;
69
- return (_a = this.enrichedToc) === null || _a === void 0 ? void 0 : _a.nodeByTocId[tocId];
76
+ return (_a = this.getEnrichedTocNow(translationInput)) === null || _a === void 0 ? void 0 : _a.nodeByTocId[tocId];
70
77
  }
71
- getTocNodeNowByUrl(prettyUrlOrMapIdTocId) {
78
+ getTocNodeNowByUrl(prettyUrlOrMapIdTocId, translationInput) {
72
79
  var _a, _b;
73
- let map = this.getMapNow();
80
+ let map = this.getMapNow(translationInput);
74
81
  if ((map === null || map === void 0 ? void 0 : map.prettyUrl) == prettyUrlOrMapIdTocId || `${map === null || map === void 0 ? void 0 : map.id}/root` === prettyUrlOrMapIdTocId) {
75
- return (_a = this.enrichedToc) === null || _a === void 0 ? void 0 : _a.toc[0];
82
+ return (_a = this.getEnrichedTocNow(translationInput)) === null || _a === void 0 ? void 0 : _a.toc[0];
76
83
  }
77
- return (_b = this.enrichedToc) === null || _b === void 0 ? void 0 : _b.nodeByUrl[prettyUrlOrMapIdTocId];
84
+ return (_b = this.getEnrichedTocNow(translationInput)) === null || _b === void 0 ? void 0 : _b.nodeByUrl[prettyUrlOrMapIdTocId];
78
85
  }
79
- async getPage(number) {
80
- const enrichedToc = await this.getEnrichedToc();
86
+ async getPage(number, translationInput) {
87
+ const enrichedToc = await this.getEnrichedToc(translationInput);
81
88
  return enrichedToc.pages[number - 1] || enrichedToc.pages[0];
82
89
  }
83
- async getPageByTocId(tocId) {
84
- const enrichedToc = await this.getEnrichedToc();
90
+ async getPageByTocId(tocId, translationInput) {
91
+ const enrichedToc = await this.getEnrichedToc(translationInput);
85
92
  return enrichedToc.pageByTocId[tocId] || enrichedToc.pages[0];
86
93
  }
87
94
  getTopicInfo(tocNode) {
@@ -90,6 +97,9 @@ export class FtReaderService extends FtServiceWithCache {
90
97
  getTopicContent(tocNode) {
91
98
  return this.cache.get("topic-content-" + tocNode.tocId, () => this.fetchTopicHTMLContent(tocNode));
92
99
  }
100
+ getTranslatedTopicContent(tocNode, translationInput) {
101
+ return this.cache.get(this.makeCacheKey("translated-topic-content-" + tocNode.tocId, translationInput), () => this.fetchTranslatedTopicHTMLContent(tocNode, translationInput));
102
+ }
93
103
  getAttachments() {
94
104
  return this.cache.get("map-attachments", () => this.fetchAttachments());
95
105
  }
@@ -117,10 +127,10 @@ export class FtReaderService extends FtServiceWithCache {
117
127
  }
118
128
  return url.href;
119
129
  }
120
- getNavigationData(tocId, pageNumber, section) {
130
+ getNavigationData(tocId, pageNumber, section, translationInput) {
121
131
  var _a, _b;
122
132
  tocId = tocId || "root";
123
- const enrichedToc = this.enrichedToc;
133
+ const enrichedToc = this.getEnrichedTocNow(translationInput);
124
134
  const page = enrichedToc === null || enrichedToc === void 0 ? void 0 : enrichedToc.pageByTocId[tocId];
125
135
  const node = enrichedToc === null || enrichedToc === void 0 ? void 0 : enrichedToc.nodeByTocId[tocId];
126
136
  const prettyUrl = node === null || node === void 0 ? void 0 : node.prettyUrl;
@@ -128,15 +138,16 @@ export class FtReaderService extends FtServiceWithCache {
128
138
  mapId: this.mapId,
129
139
  tocId,
130
140
  topicTitle: (_a = node === null || node === void 0 ? void 0 : node.title) !== null && _a !== void 0 ? _a : "",
141
+ untranslatedTopicTitle: node === null || node === void 0 ? void 0 : node.untranslatedTitle,
131
142
  page: pageNumber && page && page.number !== pageNumber ? pageNumber : undefined,
132
143
  prettyUrl: prettyUrl != null ? prettyUrl.replace(/^r\//, "") : undefined,
133
144
  prettyUrlDuplicated: (_b = enrichedToc === null || enrichedToc === void 0 ? void 0 : enrichedToc.duplicatedPrettyUrls.has(prettyUrl !== null && prettyUrl !== void 0 ? prettyUrl : "")) !== null && _b !== void 0 ? _b : false,
134
145
  section: section
135
146
  };
136
147
  }
137
- async getAccurateNavigationData(tocId, pageNumber, section) {
138
- await this.getEnrichedToc();
139
- return this.getNavigationData(tocId, pageNumber, section);
148
+ async getAccurateNavigationData(tocId, pageNumber, section, translationInput) {
149
+ await this.getEnrichedToc(translationInput);
150
+ return this.getNavigationData(tocId, pageNumber, section, translationInput);
140
151
  }
141
152
  getRatingSummary() {
142
153
  return this.cache.get("ratingSummary");
@@ -187,13 +198,13 @@ export class FtReaderService extends FtServiceWithCache {
187
198
  themeStylesheet() {
188
199
  return this.api.makeAbsolute(this.api.endpoints.stylesheets.theme);
189
200
  }
190
- buildBreadcrumb(tocId) {
191
- let target = this.getTocNodeNow(tocId);
192
- let breadcrumb = [{ tocId: target.tocId, title: target.title }];
193
- let parent = this.getTocNodeNow(target.parentTocId);
201
+ buildBreadcrumb(tocId, translationInput) {
202
+ let target = this.getTocNodeNow(tocId, translationInput);
203
+ let breadcrumb = [{ tocId: target.tocId, title: target.title, untranslatedTitle: target.untranslatedTitle }];
204
+ let parent = this.getTocNodeNow(target.parentTocId, translationInput);
194
205
  while (parent) {
195
- breadcrumb.unshift({ tocId: parent.tocId, title: parent.title });
196
- parent = this.getTocNodeNow(parent.parentTocId);
206
+ breadcrumb.unshift({ tocId: parent.tocId, title: parent.title, untranslatedTitle: parent.untranslatedTitle });
207
+ parent = this.getTocNodeNow(parent.parentTocId, translationInput);
197
208
  }
198
209
  return breadcrumb;
199
210
  }