@fluid-topics/ft-reader-context 1.1.82 → 1.1.83

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.
@@ -5,10 +5,11 @@ export type EnrichedToc = {
5
5
  toc: Array<FtReaderTocNode>;
6
6
  pagesToc: Array<FtPagesTocNode>;
7
7
  nodeByTocId: Record<string, FtReaderTocNode>;
8
+ nodeByUrl: Record<string, FtReaderTocNode>;
8
9
  duplicatedPrettyUrls: Set<string>;
9
10
  pages: Array<FtReaderPage>;
10
11
  pageByTocId: Record<string, FtReaderPage>;
11
12
  };
12
13
  export declare class FtReaderConverter {
13
- convertPaginatedToc(paginatedToc: FtPaginatedToc): EnrichedToc;
14
+ convertPaginatedToc(mapId: string, paginatedToc: FtPaginatedToc): EnrichedToc;
14
15
  }
@@ -1,8 +1,9 @@
1
1
  class EnrichedTocBuilder {
2
- constructor(paginatedToc) {
2
+ constructor(mapId, paginatedToc) {
3
+ this.mapId = mapId;
3
4
  this.paginatedToc = paginatedToc;
4
5
  this.nodeByTocId = {};
5
- this.knownPrettyUrls = new Set();
6
+ this.nodeByUrl = {};
6
7
  this.duplicatedPrettyUrls = new Set();
7
8
  this.pages = [];
8
9
  this.pageByTocId = {};
@@ -13,6 +14,7 @@ class EnrichedTocBuilder {
13
14
  toc: this.convertNodes(this.paginatedToc.paginatedToc, 1),
14
15
  pagesToc: this.extractPagesToc(this.paginatedToc.paginatedToc, 1),
15
16
  nodeByTocId: this.nodeByTocId,
17
+ nodeByUrl: this.nodeByUrl,
16
18
  duplicatedPrettyUrls: this.duplicatedPrettyUrls,
17
19
  pages: this.pages,
18
20
  pageByTocId: this.pageByTocId,
@@ -126,16 +128,19 @@ class EnrichedTocBuilder {
126
128
  }
127
129
  register(enrichedNode) {
128
130
  if (enrichedNode.prettyUrl) {
129
- if (this.knownPrettyUrls.has(enrichedNode.prettyUrl)) {
131
+ if (this.nodeByUrl[enrichedNode.prettyUrl] == null) {
132
+ this.nodeByUrl[enrichedNode.prettyUrl] = enrichedNode;
133
+ }
134
+ else {
130
135
  this.duplicatedPrettyUrls.add(enrichedNode.prettyUrl);
131
136
  }
132
- this.knownPrettyUrls.add(enrichedNode.prettyUrl);
133
137
  }
138
+ this.nodeByUrl[`${this.mapId}/${enrichedNode.tocId}`] = enrichedNode;
134
139
  this.nodeByTocId[enrichedNode.tocId] = enrichedNode;
135
140
  }
136
141
  }
137
142
  export class FtReaderConverter {
138
- convertPaginatedToc(paginatedToc) {
139
- return new EnrichedTocBuilder(paginatedToc).build();
143
+ convertPaginatedToc(mapId, paginatedToc) {
144
+ return new EnrichedTocBuilder(mapId, paginatedToc).build();
140
145
  }
141
146
  }
@@ -39,6 +39,7 @@ export declare abstract class FtReaderService extends FtServiceWithCache {
39
39
  getPagesToc(): Promise<Array<FtPagesTocNode>>;
40
40
  getTocNode(tocId: string): Promise<FtReaderTocNode>;
41
41
  getTocNodeNow(tocId: string): FtReaderTocNode | undefined;
42
+ getTocNodeNowByUrl(prettyUrlOrMapIdTocId: string): FtReaderTocNode | undefined;
42
43
  getPage(number: number): Promise<FtReaderPage>;
43
44
  getPageByTocId(tocId: string): Promise<FtReaderPage>;
44
45
  getTopicInfo(tocNode: FtTocNode): Promise<FtTopic>;
@@ -23,7 +23,7 @@ export class FtReaderService extends FtServiceWithCache {
23
23
  initCache() {
24
24
  this.cache.registerFinal("configuration", () => this.api.getReaderConfiguration());
25
25
  this.cache.register("map", () => this.withMapId(mapId => this.fetchMap(mapId)));
26
- this.cache.register("enrichedToc", () => this.withMapId(mapId => this.fetchPages(mapId).then(toc => this.converter.convertPaginatedToc(toc))));
26
+ this.cache.register("enrichedToc", () => this.withMapId(mapId => this.fetchPages(mapId).then(toc => this.converter.convertPaginatedToc(mapId, toc))));
27
27
  this.cache.register("ratingSummary", () => {
28
28
  var _a, _b;
29
29
  const userHaveRatingRole = userHasRole((_b = (_a = ftAppInfoStore.getState().session) === null || _a === void 0 ? void 0 : _a.profile.roles) !== null && _b !== void 0 ? _b : [], "RATING_USER");
@@ -68,6 +68,14 @@ export class FtReaderService extends FtServiceWithCache {
68
68
  var _a;
69
69
  return (_a = this.enrichedToc) === null || _a === void 0 ? void 0 : _a.nodeByTocId[tocId];
70
70
  }
71
+ getTocNodeNowByUrl(prettyUrlOrMapIdTocId) {
72
+ var _a, _b;
73
+ let map = this.getMapNow();
74
+ 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];
76
+ }
77
+ return (_b = this.enrichedToc) === null || _b === void 0 ? void 0 : _b.nodeByUrl[prettyUrlOrMapIdTocId];
78
+ }
71
79
  async getPage(number) {
72
80
  const enrichedToc = await this.getEnrichedToc();
73
81
  return enrichedToc.pages[number - 1] || enrichedToc.pages[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-reader-context",
3
- "version": "1.1.82",
3
+ "version": "1.1.83",
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.82",
23
- "@fluid-topics/ft-wc-utils": "1.1.82",
22
+ "@fluid-topics/ft-app-context": "1.1.83",
23
+ "@fluid-topics/ft-wc-utils": "1.1.83",
24
24
  "@reduxjs/toolkit": "^1.6.2",
25
25
  "lit": "3.1.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@fluid-topics/public-api": "1.0.71"
29
29
  },
30
- "gitHead": "2fd30a90406265aa7cc0714cafe53090343c0086"
30
+ "gitHead": "2ca7449aa6df93b0b6ba0794e695aa3f605f38bf"
31
31
  }