@salesforcedevs/docs-components 1.14.6-loader → 1.14.8-alpha100

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.14.6-loader",
3
+ "version": "1.14.8-alpha100",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -6,6 +6,7 @@ import Button from "dx/button";
6
6
  import { highlightTerms } from "dxUtils/highlight";
7
7
  import ContentCallout from "doc/contentCallout";
8
8
  import ContentMedia from "doc/contentMedia";
9
+ import { normalizeHtmlEntities } from "docUtils/htmlEntities";
9
10
 
10
11
  const HIGHLIGHTABLE_SELECTOR = [
11
12
  "p",
@@ -36,7 +37,7 @@ export default class Content extends LightningElement {
36
37
  @api
37
38
  set docsData(value) {
38
39
  this._docRendered = false;
39
- this.docContent = (value && value.trim()) || "";
40
+ this.docContent = (value && normalizeHtmlEntities(value.trim())) || "";
40
41
  }
41
42
 
42
43
  get docsData() {
@@ -110,7 +111,7 @@ export default class Content extends LightningElement {
110
111
  const divEl = this.getCleanContainer();
111
112
 
112
113
  if (divEl) {
113
- divEl.innerHTML = docContent || this.docContent;
114
+ divEl.innerHTML = normalizeHtmlEntities(docContent || this.docContent);
114
115
 
115
116
  // Query the code blocks and create a dx-code-block component that contains the code
116
117
  const codeBlockEls = divEl.querySelectorAll(".codeSection");
@@ -29,3 +29,8 @@ table {
29
29
  .icon {
30
30
  display: inline-block;
31
31
  }
32
+
33
+ .loader {
34
+ pointer-events: none;
35
+ bottom: 30%;
36
+ }
@@ -3,6 +3,7 @@
3
3
  <dx-spinner
4
4
  size="large"
5
5
  variant="brand"
6
+ class="loader"
6
7
  if:true={isLoading}
7
8
  ></dx-spinner>
8
9
  <dx-error-fallback lwc:if={showError}></dx-error-fallback>
@@ -38,9 +38,11 @@ export class FetchContent {
38
38
  pdf_url,
39
39
  deliverable
40
40
  } = await this.fetchResource<ApiDocData>(
41
- `${this.apiDomain}/docs/get_document/${docId}`
41
+ `/cx-router/dsc/toc?projectId=sfdocs-asl_dev_guide&projectVersion=254-7-dev&locale=en-us`
42
42
  );
43
43
 
44
+ console.log(docId);
45
+
44
46
  const { normalizedToc, tocMap } = this.normalizeToc(toc);
45
47
  return {
46
48
  availableLanguages:
@@ -70,26 +72,24 @@ export class FetchContent {
70
72
  deliverable: string,
71
73
  contentId: string,
72
74
  options: ContentApiOptions
73
- ): Promise<ContentData> {
74
- return this.fetchResource<ContentData>(
75
- `${this.apiDomain}/docs/get_document_content/${deliverable}/${contentId}/${options.language}/${options.version}`
75
+ ): Promise<String> {
76
+ return this.fetchResource<String>(
77
+ `/cx-router/dsc/topic?projectId=sfdocs-asl_dev_guide&projectVersion=254-7-dev&locale=en-us&topic=${contentId}`
76
78
  );
77
79
  }
78
80
 
79
81
  private async fetchResource<T>(url: string): Promise<T> {
80
82
  const response = await fetch(url);
81
- if (!response.ok) {
83
+ /*if (!response.ok) {
82
84
  throw new Error(response.statusText);
83
- }
85
+ }*/
84
86
 
85
87
  const json = await response.json();
86
88
 
87
- return json;
89
+ return json.response;
88
90
  }
89
91
 
90
- private normalizeToc(
91
- apiToc: Array<ApiNavItem>
92
- ): {
92
+ private normalizeToc(apiToc: Array<ApiNavItem>): {
93
93
  tocMap: { [key: string]: TreeNode };
94
94
  normalizedToc: Array<TreeNode>;
95
95
  } {
@@ -543,7 +543,7 @@ export default class DocXmlContent extends LightningElementWithState<{
543
543
  );
544
544
 
545
545
  if (data) {
546
- this.docContent = data.content;
546
+ this.docContent = JSON.parse(data).content;
547
547
  this.addMetatags();
548
548
 
549
549
  if (!this.pageReference.hash) {
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Normalizes HTML entities in a string by first decoding any double-encoded entities
3
+ * and then properly encoding special characters
4
+ * @param str The string to normalize
5
+ * @returns The normalized string with properly encoded HTML entities
6
+ */
7
+ export const normalizeHtmlEntities = (str: string): string => {
8
+ if (typeof str !== 'string') {
9
+ return str;
10
+ }
11
+
12
+ // First decode any double-encoded entities
13
+ const tempDiv = document.createElement('div');
14
+ tempDiv.innerHTML = str;
15
+ const decoded = tempDiv.textContent || tempDiv.innerText;
16
+
17
+ // Then properly encode special characters
18
+ return decoded
19
+ .replace(/&/g, '&amp;')
20
+ .replace(/</g, '&lt;')
21
+ .replace(/>/g, '&gt;')
22
+ .replace(/"/g, '&quot;')
23
+ .replace(/'/g, '&#039;')
24
+ .replace(/\u00A0/g, '&nbsp;'); // Handle non-breaking space
25
+ };