@fluid-topics/ft-reader-context 2.0.14 → 2.0.15
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/ft-reader-context.light.js +7 -7
- package/build/ft-reader-context.min.js +21 -21
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/store/FtReaderStateManager.d.ts +1 -0
- package/build/store/FtReaderStateManager.js +27 -13
- package/build/store/utils/FtReaderService.d.ts +2 -1
- package/build/store/utils/FtReaderService.js +8 -0
- package/build/utils.d.ts +2 -0
- package/build/utils.js +8 -0
- package/package.json +5 -5
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -57,6 +57,7 @@ export declare class FtReaderStateManager {
|
|
|
57
57
|
getTocNode(tocId: string): Promise<FtReaderTocNode>;
|
|
58
58
|
getPage(targetPageNumber: number): Promise<FtReaderPage>;
|
|
59
59
|
onMapAttachmentsUpdate(): void;
|
|
60
|
+
getRelativeDocumentUrlForLocale(uiLocale: string): Promise<string | undefined>;
|
|
60
61
|
private sendDocumentOnDemandTranslateEvent;
|
|
61
62
|
private parseLanguageToAnalyticsFormat;
|
|
62
63
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { FtReaderStoreEvents } from "./model";
|
|
2
|
-
import { CanceledPromiseError, ClusteringHelper, Debouncer, waitFor, waitUntil } from "@fluid-topics/ft-wc-utils";
|
|
3
|
-
import { createReaderStore } from "./redux";
|
|
1
|
+
import { FtReaderStoreEvents, } from "./model";
|
|
2
|
+
import { accessResultUrl, CanceledPromiseError, ClusteringHelper, Debouncer, waitFor, waitUntil, } from "@fluid-topics/ft-wc-utils";
|
|
3
|
+
import { createReaderStore, } from "./redux";
|
|
4
4
|
import { FtOfficialReaderService } from "./utils/FtOfficialReaderService";
|
|
5
|
-
import {
|
|
5
|
+
import { FtAnalyticsEventsService, ftAppInfoStore, } from "@fluid-topics/ft-app-context";
|
|
6
6
|
import { FtAnalyticsTranslationOrigin, } from "@fluid-topics/public-api";
|
|
7
|
+
import { addPivotQueryParam } from "../utils";
|
|
7
8
|
export class FtReaderStateManager {
|
|
8
9
|
static build(id, serviceProvider) {
|
|
9
10
|
return new FtReaderStateManager(createReaderStore(id.trim() || "context"), serviceProvider !== null && serviceProvider !== void 0 ? serviceProvider : FtOfficialReaderService.build);
|
|
@@ -149,19 +150,15 @@ export class FtReaderStateManager {
|
|
|
149
150
|
(_a = this.service) === null || _a === void 0 ? void 0 : _a.clearConfiguration();
|
|
150
151
|
return this.loadConfiguration();
|
|
151
152
|
}
|
|
152
|
-
fetchRelatives() {
|
|
153
|
+
async fetchRelatives() {
|
|
153
154
|
var _a, _b;
|
|
154
155
|
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);
|
|
155
156
|
if (relativeMetadataValues !== undefined && relativeMetadataValues.length > 0) {
|
|
156
|
-
(_b = this.service) === null || _b === void 0 ? void 0 : _b.getRelativesForDocument(this.store.getState().configuration.relativePivotMetadata, relativeMetadataValues)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
this.updateClusteringHelper();
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
this.updateClusteringHelper();
|
|
157
|
+
const searchResults = await ((_b = this.service) === null || _b === void 0 ? void 0 : _b.getRelativesForDocument(this.store.getState().configuration.relativePivotMetadata, relativeMetadataValues));
|
|
158
|
+
const relatives = searchResults === null || searchResults === void 0 ? void 0 : searchResults.results.flatMap((result) => result.entries);
|
|
159
|
+
this.store.actions.relatives(relatives);
|
|
164
160
|
}
|
|
161
|
+
this.updateClusteringHelper();
|
|
165
162
|
}
|
|
166
163
|
updateClusteringHelper() {
|
|
167
164
|
this.clusteringHelper = this.createClusteringHelper();
|
|
@@ -291,6 +288,23 @@ export class FtReaderStateManager {
|
|
|
291
288
|
(_a = this.service) === null || _a === void 0 ? void 0 : _a.clearMapAttachments();
|
|
292
289
|
this.store.dispatchEvent(new Event(FtReaderStoreEvents.mapAttachmentsUpdate));
|
|
293
290
|
}
|
|
291
|
+
async getRelativeDocumentUrlForLocale(uiLocale) {
|
|
292
|
+
var _a, _b, _c;
|
|
293
|
+
if (this.store.getState().relatives == undefined) {
|
|
294
|
+
await this.fetchRelatives();
|
|
295
|
+
}
|
|
296
|
+
const maybeRelativeResultMap = ClusteringHelper.findResultWithMetadataValue((_a = this.store.getState().relatives) !== null && _a !== void 0 ? _a : [], "ft:locale", uiLocale);
|
|
297
|
+
let targetUrl = accessResultUrl(maybeRelativeResultMap);
|
|
298
|
+
if (targetUrl) {
|
|
299
|
+
const currentTocId = this.store.getState().visibleTopics[0];
|
|
300
|
+
const metadataKey = (_b = this.store.getState().configuration) === null || _b === void 0 ? void 0 : _b.relativeTopicPivotMetadata;
|
|
301
|
+
if (metadataKey && currentTocId) {
|
|
302
|
+
const maybePivot = await ((_c = this.service) === null || _c === void 0 ? void 0 : _c.getTopicMetadataValue(currentTocId, metadataKey));
|
|
303
|
+
targetUrl = addPivotQueryParam(targetUrl, maybePivot);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return targetUrl;
|
|
307
|
+
}
|
|
294
308
|
sendDocumentOnDemandTranslateEvent(destinationLanguage) {
|
|
295
309
|
const { editorMode, apiIntegrationIdentifier, apiIntegrationAppVersion } = ftAppInfoStore.getState();
|
|
296
310
|
const state = this.store.getState();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FluidTopicsApi, FtMap, FtMapAttachment, FtPaginatedToc, FtPaginationConfiguration, FtPublicationRatingSummary, FtRatingSummary, FtRatingTypeKeys, FtReaderConfiguration, FtTocNode, FtTopic, FtTranslationContent, FtTranslationSettings } from "@fluid-topics/public-api";
|
|
1
|
+
import type { FluidTopicsApi, FtMap, FtMapAttachment, FtMetadata, 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
4
|
import { FtReaderConverter } from "./FtReaderConverter";
|
|
@@ -49,6 +49,7 @@ export declare abstract class FtReaderService extends FtServiceWithCache {
|
|
|
49
49
|
getTopicInfo(tocNode: FtTocNode): Promise<FtTopic>;
|
|
50
50
|
getTopicContent(tocNode: FtTocNode): Promise<string>;
|
|
51
51
|
getTranslatedTopicContent(tocNode: FtTocNode, translationInput: FtTranslationSettings): Promise<FtTranslationContent>;
|
|
52
|
+
getTopicMetadataValue(tocId: string, metadataKey: string): Promise<FtMetadata | undefined>;
|
|
52
53
|
getAttachments(): Promise<Array<FtMapAttachment>>;
|
|
53
54
|
clearMapAttachments(): void;
|
|
54
55
|
getRelativesForDocument(metadataPivotKey: string, metadataPivotValues: string[]): Promise<FtSearchResults>;
|
|
@@ -103,6 +103,14 @@ export class FtReaderService extends FtServiceWithCache {
|
|
|
103
103
|
getTranslatedTopicContent(tocNode, translationInput) {
|
|
104
104
|
return this.cache.get(this.makeCacheKey("translated-topic-content-" + tocNode.tocId, translationInput), () => this.fetchTranslatedTopicHTMLContent(tocNode, translationInput));
|
|
105
105
|
}
|
|
106
|
+
async getTopicMetadataValue(tocId, metadataKey) {
|
|
107
|
+
const tocNode = this.getTocNodeNow(tocId);
|
|
108
|
+
if (!tocNode) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
const topicInfo = await this.getTopicInfo(tocNode);
|
|
112
|
+
return topicInfo === null || topicInfo === void 0 ? void 0 : topicInfo.metadata.find((metadata) => metadata.key == metadataKey);
|
|
113
|
+
}
|
|
106
114
|
getAttachments() {
|
|
107
115
|
return this.cache.get("map-attachments", () => this.fetchAttachments());
|
|
108
116
|
}
|
package/build/utils.d.ts
ADDED
package/build/utils.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const TOPIC_PIVOT_QUERY_PARAM_KEY = "topicPivot";
|
|
2
|
+
export function addPivotQueryParam(url, metadata) {
|
|
3
|
+
const updated = new URL(url);
|
|
4
|
+
metadata === null || metadata === void 0 ? void 0 : metadata.values.forEach((v) => {
|
|
5
|
+
updated.searchParams.append(TOPIC_PIVOT_QUERY_PARAM_KEY, v);
|
|
6
|
+
});
|
|
7
|
+
return updated.href;
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-topics/ft-reader-context",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.15",
|
|
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": "2.0.
|
|
23
|
-
"@fluid-topics/ft-wc-utils": "2.0.
|
|
22
|
+
"@fluid-topics/ft-app-context": "2.0.15",
|
|
23
|
+
"@fluid-topics/ft-wc-utils": "2.0.15",
|
|
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.
|
|
28
|
+
"@fluid-topics/public-api": "1.0.120"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "4ccf89e835f22f2689fc0fe3f97c46671debe98d"
|
|
31
31
|
}
|