@fluid-topics/ft-reader-context 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.
- package/build/ft-reader-context.d.ts +1 -0
- package/build/ft-reader-context.js +19 -7
- package/build/ft-reader-context.light.js +5 -5
- package/build/ft-reader-context.min.js +20 -20
- package/build/models.d.ts +6 -0
- package/build/models.js +10 -0
- package/build/store/FtReaderStateManager.d.ts +8 -0
- package/build/store/FtReaderStateManager.js +58 -2
- package/build/store/model.d.ts +2 -1
- package/build/store/redux.js +1 -0
- package/build/store/utils/FtOfficialReaderService.d.ts +3 -0
- package/build/store/utils/FtOfficialReaderService.js +37 -0
- package/build/store/utils/FtReaderService.d.ts +5 -1
- package/build/store/utils/FtReaderService.js +6 -0
- package/package.json +5 -5
package/build/models.d.ts
CHANGED
|
@@ -37,3 +37,9 @@ export declare class NotFoundErrorEvent extends Event {
|
|
|
37
37
|
export declare class UnauthorizedErrorEvent extends Event {
|
|
38
38
|
constructor();
|
|
39
39
|
}
|
|
40
|
+
export declare class ForbiddenErrorEvent extends Event {
|
|
41
|
+
constructor();
|
|
42
|
+
}
|
|
43
|
+
export declare class TopicRelativeNotFoundEvent extends Event {
|
|
44
|
+
constructor();
|
|
45
|
+
}
|
package/build/models.js
CHANGED
|
@@ -28,3 +28,13 @@ export class UnauthorizedErrorEvent extends Event {
|
|
|
28
28
|
super("ft-reader-map-unauthorized");
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
export class ForbiddenErrorEvent extends Event {
|
|
32
|
+
constructor() {
|
|
33
|
+
super("ft-reader-map-forbidden");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export class TopicRelativeNotFoundEvent extends Event {
|
|
37
|
+
constructor() {
|
|
38
|
+
super("ft-reader-topic-relative-not-found", { bubbles: true, composed: true });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { ClusteringHelper } from "@fluid-topics/ft-wc-utils";
|
|
1
2
|
import { FtReaderReduxStore } from "./redux";
|
|
2
3
|
import type { FtReaderService } from "./utils/FtReaderService";
|
|
3
4
|
export declare class FtReaderStateManager {
|
|
4
5
|
store: FtReaderReduxStore;
|
|
5
6
|
static build(id: string, serviceProvider?: () => Promise<FtReaderService>): FtReaderStateManager;
|
|
7
|
+
metadataForSwitchToRelatives: Set<string>;
|
|
8
|
+
clusteringHelper?: ClusteringHelper;
|
|
6
9
|
service?: FtReaderService;
|
|
7
10
|
errorHandler?: (e: Error) => void;
|
|
8
11
|
constructor(store: FtReaderReduxStore, serviceProvider: () => Promise<FtReaderService>);
|
|
@@ -19,5 +22,10 @@ export declare class FtReaderStateManager {
|
|
|
19
22
|
clear(): void;
|
|
20
23
|
reload(): Promise<void>;
|
|
21
24
|
private fetchData;
|
|
25
|
+
private fetchRelatives;
|
|
26
|
+
private createClusteringHelper;
|
|
27
|
+
navigateToRelativeTopicIfFound(topicPivotMetadataValue: string): Promise<boolean>;
|
|
22
28
|
setSearchInDocumentQuery(query: string): void;
|
|
29
|
+
registerMetadataForSwitchToRelatives(id: string): void;
|
|
30
|
+
unregisterMetadataForSwitchToRelatives(id: string): void;
|
|
23
31
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
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";
|
|
4
5
|
export class FtReaderStateManager {
|
|
5
6
|
static build(id, serviceProvider) {
|
|
6
7
|
return new FtReaderStateManager(createReaderStore(id.trim() || "context"), serviceProvider !== null && serviceProvider !== void 0 ? serviceProvider : FtOfficialReaderService.build);
|
|
7
8
|
}
|
|
8
9
|
constructor(store, serviceProvider) {
|
|
9
10
|
this.store = store;
|
|
11
|
+
this.metadataForSwitchToRelatives = new Set();
|
|
10
12
|
this.loadDebouncer = new Debouncer(10);
|
|
11
13
|
this.initService(serviceProvider);
|
|
12
14
|
}
|
|
@@ -69,7 +71,10 @@ export class FtReaderStateManager {
|
|
|
69
71
|
this.store.actions.pagesToc(undefined);
|
|
70
72
|
this.store.actions.currentPage(undefined);
|
|
71
73
|
this.store.actions.searchInDocumentQuery("");
|
|
74
|
+
this.store.actions.relatives(undefined);
|
|
72
75
|
(_a = this.service) === null || _a === void 0 ? void 0 : _a.clear();
|
|
76
|
+
this.metadataForSwitchToRelatives = new Set();
|
|
77
|
+
this.clusteringHelper = undefined;
|
|
73
78
|
}
|
|
74
79
|
reload() {
|
|
75
80
|
this.clear();
|
|
@@ -84,7 +89,11 @@ export class FtReaderStateManager {
|
|
|
84
89
|
(_c = this.service) === null || _c === void 0 ? void 0 : _c.getToc().then(toc => this.store.actions.toc(toc)),
|
|
85
90
|
(_d = this.service) === null || _d === void 0 ? void 0 : _d.getPagesToc().then(pagesToc => this.store.actions.pagesToc(pagesToc)),
|
|
86
91
|
(_e = this.service) === null || _e === void 0 ? void 0 : _e.getPaginationConfiguration().then(conf => this.store.actions.paginationConfiguration(conf)),
|
|
87
|
-
])
|
|
92
|
+
]).then(() => {
|
|
93
|
+
if (this.metadataForSwitchToRelatives.size > 0) {
|
|
94
|
+
this.fetchRelatives();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
88
97
|
}
|
|
89
98
|
catch (e) {
|
|
90
99
|
if (this.errorHandler && !(e instanceof CanceledPromiseError)) {
|
|
@@ -92,7 +101,54 @@ export class FtReaderStateManager {
|
|
|
92
101
|
}
|
|
93
102
|
}
|
|
94
103
|
}
|
|
104
|
+
fetchRelatives() {
|
|
105
|
+
var _a, _b, _c;
|
|
106
|
+
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);
|
|
107
|
+
if (relativeMetadataValues !== undefined && relativeMetadataValues.length > 0) {
|
|
108
|
+
(_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) => {
|
|
109
|
+
const relatives = searchResults.results.flatMap((result) => result.entries);
|
|
110
|
+
this.store.actions.relatives(relatives);
|
|
111
|
+
this.createClusteringHelper();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
createClusteringHelper() {
|
|
116
|
+
var _a, _b;
|
|
117
|
+
if (this.store.getState().relatives) {
|
|
118
|
+
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 : []);
|
|
119
|
+
this.store.eventBus.dispatchEvent(new CustomEvent("clustering-helper-created"));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async navigateToRelativeTopicIfFound(topicPivotMetadataValue) {
|
|
123
|
+
var _a, _b, _c;
|
|
124
|
+
const relativeTopicPivotMetadata = await waitFor(() => { var _a; return (_a = this.store.getState().configuration) === null || _a === void 0 ? void 0 : _a.relativeTopicPivotMetadata; });
|
|
125
|
+
const mapId = this.store.getState().mapId;
|
|
126
|
+
const service = await this.awaitService();
|
|
127
|
+
const searchResults = await service.getRelativesForTopicInMap(mapId, relativeTopicPivotMetadata, [topicPivotMetadataValue]);
|
|
128
|
+
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]) {
|
|
129
|
+
const targetTocId = searchResults.results[0].entries[0].topic.tocId;
|
|
130
|
+
await this.navigateToTopic(targetTocId);
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
await this.navigateToTopic("root");
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
95
138
|
setSearchInDocumentQuery(query) {
|
|
96
139
|
this.store.actions.searchInDocumentQuery(query);
|
|
97
140
|
}
|
|
141
|
+
registerMetadataForSwitchToRelatives(id) {
|
|
142
|
+
this.metadataForSwitchToRelatives.add(id);
|
|
143
|
+
if (this.store.getState().relatives == undefined) {
|
|
144
|
+
this.fetchRelatives();
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
this.createClusteringHelper();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
unregisterMetadataForSwitchToRelatives(id) {
|
|
151
|
+
this.metadataForSwitchToRelatives.delete(id);
|
|
152
|
+
this.createClusteringHelper();
|
|
153
|
+
}
|
|
98
154
|
}
|
package/build/store/model.d.ts
CHANGED
|
@@ -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;
|
package/build/store/redux.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "1.1.29",
|
|
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.
|
|
23
|
-
"@fluid-topics/ft-wc-utils": "1.1.
|
|
22
|
+
"@fluid-topics/ft-app-context": "1.1.29",
|
|
23
|
+
"@fluid-topics/ft-wc-utils": "1.1.29",
|
|
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.57"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "0d8f67879e2608a03b96d18ba7b3ad25e065178b"
|
|
31
31
|
}
|