@salesforcedevs/docs-components 0.57.1-callout-fix → 0.61.0

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,15 +8,26 @@ import {
8
8
  TreeNode,
9
9
  Header,
10
10
  HistoryState,
11
- PageReference
11
+ PageReference,
12
+ TocMap
12
13
  } from "./types";
13
14
  import { SearchSyncer } from "docUtils/SearchSyncer";
14
15
  import { LightningElementWithState } from "docBaseElements/lightningElementWithState";
15
- import { Language } from "typings/custom";
16
+ import { Breadcrumb, Language } from "typings/custom";
16
17
 
17
18
  // TODO: Imitating from actual implementation as doc-content use it like this. We should refactor it later.
18
19
  const handleContentError = (error): void => console.log(error);
19
20
 
21
+ const FIRST_CRUMB = {
22
+ href: "/docs",
23
+ label: "Documentation"
24
+ };
25
+
26
+ const PIXEL_PER_CHARACTER_MAP: { [key: string]: number } = {
27
+ default: 7.7,
28
+ "ja-jp": 12.5
29
+ };
30
+
20
31
  export default class DocXmlContent extends LightningElementWithState<{
21
32
  isFetchingDocument: boolean;
22
33
  isFetchingContent: boolean;
@@ -53,7 +64,7 @@ export default class DocXmlContent extends LightningElementWithState<{
53
64
  private language: DocLanguage = null;
54
65
  private loaded = false;
55
66
  private pdfUrl = "";
56
- private tocMap = null;
67
+ private tocMap: TocMap = {};
57
68
  private sidebarContent: Array<TreeNode> = null;
58
69
  private version: DocVersion = null;
59
70
  private docTitle = "";
@@ -102,6 +113,7 @@ export default class DocXmlContent extends LightningElementWithState<{
102
113
  private _allLanguages: Array<Language> = [];
103
114
 
104
115
  @track private pageReference: PageReference = {};
116
+ @track breadcrumbs: Array<Breadcrumb> = [];
105
117
 
106
118
  constructor() {
107
119
  super();
@@ -267,6 +279,13 @@ export default class DocXmlContent extends LightningElementWithState<{
267
279
  }));
268
280
  }
269
281
 
282
+ private get breadcrumbPixelPerCharacter() {
283
+ return (
284
+ PIXEL_PER_CHARACTER_MAP[this.language.id] ||
285
+ PIXEL_PER_CHARACTER_MAP.default
286
+ );
287
+ }
288
+
270
289
  private handlePopState = (): void =>
271
290
  this.updatePageReference(this.getReferenceFromUrl());
272
291
 
@@ -280,15 +299,15 @@ export default class DocXmlContent extends LightningElementWithState<{
280
299
 
281
300
  if (name) {
282
301
  const hashIndex = name.indexOf("#");
283
- this.pageReference.hash =
284
- hashIndex > -1 ? name.slice(hashIndex) : "";
285
-
286
- const contentId = hashIndex > -1 ? name.slice(0, hashIndex) : name;
287
- if (this.pageReference.contentDocumentId !== contentId) {
288
- this.pageReference.contentDocumentId = contentId;
289
- this.fetchContent().catch(handleContentError);
290
- }
291
-
302
+ const hash = hashIndex > -1 ? name.slice(hashIndex) : "";
303
+
304
+ const contentDocumentId =
305
+ hashIndex > -1 ? name.slice(0, hashIndex) : name;
306
+ this.updatePageReference({
307
+ ...this.pageReference,
308
+ contentDocumentId,
309
+ hash
310
+ });
292
311
  this.updateUrl();
293
312
  }
294
313
  }
@@ -321,15 +340,17 @@ export default class DocXmlContent extends LightningElementWithState<{
321
340
  return;
322
341
  }
323
342
 
324
- const isSameDocId = this.pageReference.docId !== newPageReference.docId;
343
+ const isSameDocId = this.pageReference.docId === newPageReference.docId;
325
344
  this.pageReference = newPageReference;
326
345
 
327
- if (isSameDocId) {
346
+ if (!isSameDocId) {
328
347
  this.fetchDocument();
329
348
  return;
330
349
  }
331
350
 
332
- this.fetchContent().catch(handleContentError);
351
+ this.fetchContent()
352
+ .then(() => this.buildBreadcrumbs())
353
+ .catch(handleContentError);
333
354
  }
334
355
 
335
356
  getReferenceFromUrl(): PageReference {
@@ -386,6 +407,8 @@ export default class DocXmlContent extends LightningElementWithState<{
386
407
 
387
408
  this.updateHeader();
388
409
 
410
+ this.buildBreadcrumbs();
411
+
389
412
  if (this.pageReference.deliverable !== data.deliverable) {
390
413
  this.pageReference.deliverable = data.deliverable;
391
414
  this.updateUrl(HistoryState.REPLACE_STATE);
@@ -558,6 +581,32 @@ export default class DocXmlContent extends LightningElementWithState<{
558
581
  );
559
582
  }
560
583
 
584
+ private buildBreadcrumbs(): void {
585
+ const { contentDocumentId } = this.pageReference;
586
+ if (!contentDocumentId) {
587
+ return;
588
+ }
589
+
590
+ const currentNode = this.tocMap[contentDocumentId];
591
+ this.breadcrumbs = this.nodeToBreadcrumb(currentNode);
592
+ }
593
+
594
+ private nodeToBreadcrumb(node?: TreeNode): Breadcrumb[] {
595
+ if (!node) {
596
+ return [FIRST_CRUMB];
597
+ }
598
+ return [
599
+ ...this.nodeToBreadcrumb(node.parent),
600
+ {
601
+ href: this.pageReferenceToString({
602
+ ...this.pageReference,
603
+ contentDocumentId: node.name
604
+ }),
605
+ label: node.label
606
+ }
607
+ ];
608
+ }
609
+
561
610
  addMetatags(): void {
562
611
  const div = document.createElement("div");
563
612
  div.innerHTML = this.docContent;
@@ -1,22 +0,0 @@
1
- /**
2
- * Represents the URL reference meta on Reference page.
3
- * Contains information on selected Reference ID, Topic ID, and Topic Type
4
- * separated by ":"
5
- */
6
- export class RouteMeta {
7
- meta: string;
8
- referenceId = "";
9
- topicId = "";
10
- type = "";
11
-
12
- constructor(meta: string) {
13
- this.meta = meta;
14
-
15
- if (meta && meta.includes(":")) {
16
- const [referenceId, type, topicId] = meta.split(":");
17
- this.referenceId = referenceId;
18
- this.topicId = topicId || type;
19
- this.type = type;
20
- }
21
- }
22
- }