@salesforcedevs/docs-components 1.3.344-spage → 1.3.345-spPage-alpha

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.3.344-spage",
3
+ "version": "1.3.345-spPage-alpha",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -124,8 +124,14 @@ export default class ContentLayout extends LightningElement {
124
124
  const headingElements = this.getHeadingElements();
125
125
  headingElements.forEach((headingElement: any) => {
126
126
  // Sometimes elements hash and header is not being set when slot content is wrapped with div
127
- headingElement.hash = headingElement.attributes.hash?.nodeValue;
128
- headingElement.header = headingElement.attributes.header?.nodeValue;
127
+ if (!headingElement.hash) {
128
+ headingElement.hash = headingElement.attributes.hash?.nodeValue;
129
+ }
130
+
131
+ if (!headingElement.header) {
132
+ headingElement.header =
133
+ headingElement.attributes.header?.nodeValue;
134
+ }
129
135
  });
130
136
  this.updateTocItems(headingElements);
131
137
  };
@@ -138,8 +144,19 @@ export default class ContentLayout extends LightningElement {
138
144
  tabPanelListItem?.querySelectorAll("dx-tab-panel");
139
145
  for (const tabPanelItem of tabPanels) {
140
146
  if (tabPanelItem.active) {
141
- headingElements =
142
- tabPanelItem.querySelectorAll(TOC_HEADER_TAG);
147
+ // This is needed for Specification tab content
148
+ const specificationElement = tabPanelItem.querySelector(
149
+ "doc-specification-content"
150
+ );
151
+ if (specificationElement) {
152
+ headingElements =
153
+ specificationElement.shadowRoot.querySelectorAll(
154
+ TOC_HEADER_TAG
155
+ );
156
+ } else {
157
+ headingElements =
158
+ tabPanelItem.querySelectorAll(TOC_HEADER_TAG);
159
+ }
143
160
  break;
144
161
  }
145
162
  }
@@ -0,0 +1,3 @@
1
+ @import "dxHelpers/reset";
2
+ @import "dxHelpers/text";
3
+ @import "dxHelpers/table";
@@ -1,46 +1,102 @@
1
1
  <template>
2
- <lightning-card title="Fetched Data">
3
- <!-- Display Attributes if they exist -->
2
+ <div class="specification-properties">
4
3
  <template if:true={hasAttributes}>
5
- <h3>Attributes</h3>
6
- <ul>
7
- <template for:each={data.attribute} for:item="attr">
8
- <li key={attr.name}>
9
- <strong>{attr.name}:</strong>
10
- {attr.desc}
11
- </li>
12
- </template>
13
- </ul>
4
+ <doc-heading
5
+ header="Attributes"
6
+ hash="attributes"
7
+ aria-level="2"
8
+ id="attributes"
9
+ ></doc-heading>
10
+ <table>
11
+ <thead>
12
+ <tr>
13
+ <th>Name</th>
14
+ <th>Description</th>
15
+ </tr>
16
+ </thead>
17
+ <tbody>
18
+ <template for:each={attributes} for:item="attribute">
19
+ <tr key={attribute.name}>
20
+ <td>{attribute.nameInKebabCase}</td>
21
+ <td>{attribute.description}</td>
22
+ </tr>
23
+ </template>
24
+ </tbody>
25
+ </table>
14
26
  </template>
15
27
 
16
- <!-- Display Methods if they exist -->
17
28
  <template if:true={hasMethods}>
18
- <h3>Methods</h3>
19
- <ul>
20
- <template for:each={data.method} for:item="method">
21
- <li key={method.name}>
22
- <strong>{method.name}:</strong>
23
- {method.desc}
24
- </li>
25
- </template>
26
- </ul>
29
+ <doc-heading
30
+ header="Methods"
31
+ hash="methods"
32
+ aria-level="2"
33
+ id="methods"
34
+ ></doc-heading>
35
+ <table>
36
+ <thead>
37
+ <tr>
38
+ <th>Name</th>
39
+ <th>Description</th>
40
+ </tr>
41
+ </thead>
42
+ <tbody>
43
+ <template for:each={methods} for:item="method">
44
+ <tr key={method.name}>
45
+ <td>{method.nameInKebabCase}</td>
46
+ <td>{method.description}</td>
47
+ </tr>
48
+ </template>
49
+ </tbody>
50
+ </table>
27
51
  </template>
28
52
 
29
- <!-- Display Slots if they exist -->
30
53
  <template if:true={hasSlots}>
31
- <h3>Slots</h3>
32
- <ul>
33
- <template for:each={data.slots} for:item="slot">
34
- <li key={slot.name}>
35
- <strong>{slot.name}:</strong>
36
- {slot.desc}
37
- </li>
38
- </template>
39
- </ul>
54
+ <doc-heading
55
+ header="Slots"
56
+ hash="slots"
57
+ aria-level="2"
58
+ id="slots"
59
+ ></doc-heading>
60
+ <table>
61
+ <thead>
62
+ <tr>
63
+ <th>Name</th>
64
+ <th>Description</th>
65
+ </tr>
66
+ </thead>
67
+ <tbody>
68
+ <template for:each={slots} for:item="slot">
69
+ <tr key={slot.name}>
70
+ <td>{slot.nameInKebabCase}</td>
71
+ <td>{slot.description}</td>
72
+ </tr>
73
+ </template>
74
+ </tbody>
75
+ </table>
40
76
  </template>
41
77
 
42
- <template if:true={error}>
43
- <p>Error fetching data: {error}</p>
78
+ <template if:true={hasEvents}>
79
+ <doc-heading
80
+ header="Events"
81
+ hash="events"
82
+ aria-level="2"
83
+ ></doc-heading>
84
+ <table>
85
+ <thead>
86
+ <tr>
87
+ <th>Name</th>
88
+ <th>Description</th>
89
+ </tr>
90
+ </thead>
91
+ <tbody>
92
+ <template for:each={events} for:item="event">
93
+ <tr key={event.name}>
94
+ <td>{event.nameInKebabCase}</td>
95
+ <td>{event.description}</td>
96
+ </tr>
97
+ </template>
98
+ </tbody>
99
+ </table>
44
100
  </template>
45
- </lightning-card>
101
+ </div>
46
102
  </template>
@@ -1,41 +1,64 @@
1
- import { LightningElement, track } from "lwc";
2
- import { toJson } from "dxUtils/normalizers";
1
+ import { LightningElement, track, api } from "lwc";
3
2
 
4
- export default class specificationContent extends LightningElement {
5
- @track data: any; // Reactive property to store fetched data
6
- @track error: any; // To track any errors
3
+ /* The actual URL is as follows:
4
+ * http://api.salesforce.com/doc-platform/developer/v1-alpha/components/{type}/{component-name}
5
+ * Until the API integration is ready, we will go ahead with localhost.
6
+ */
7
+ const localURL: string = "https://cx-mock-router-f02597c1b3da.herokuapp.com";
8
+ const ROUTER_URL: string =
9
+ localURL || "https://api.salesforce.com/doc-platform/developer/v1";
10
+
11
+ export default class SpecificationContent extends LightningElement {
12
+ @track data: any;
13
+ @api component: string = "button";
14
+ @api type: string = "lightning";
15
+
16
+ private attributes = [];
17
+ private methods = [];
18
+ private slots = [];
19
+ private events = [];
7
20
 
8
- // Lifecycle method to fetch data when the component is inserted into the DOM
9
21
  connectedCallback() {
10
- this.loadData();
22
+ this.fetchComponentMetadata();
11
23
  }
12
24
 
13
- // Method to make the API call
14
- loadData() {
15
- fetch("http://localhost:3002/card") // Sample API URL
16
- .then((response) => response.json()) // Convert response to JSON
17
- .then((result) => {
18
- this.data = toJson(result); // Store data to update UI
19
- this.error = undefined; // Clear any previous errors
20
- })
21
- .catch((error) => {
22
- this.error = error; // Capture any errors
23
- this.data = {}; // Clear data on error
24
- });
25
+ async fetchComponentMetadata() {
26
+ const url = `${ROUTER_URL}/components/${this.type}/${this.component}`;
27
+
28
+ try {
29
+ const response = await fetch(url);
30
+
31
+ if (!response.ok) {
32
+ throw new Error(`Failed to fetch: ${response.statusText}`);
33
+ }
34
+
35
+ const result = await response.json();
36
+ this.data = result;
37
+ ({
38
+ attributes: this.attributes,
39
+ methods: this.methods,
40
+ slots: this.slots,
41
+ events: this.events
42
+ } = this.data);
43
+ } catch (error) {
44
+ this.data = {};
45
+ console.error("fetchComponentMetadata() failed for:" + url);
46
+ }
25
47
  }
26
48
 
27
- // Helper to check if attributes exist
28
49
  get hasAttributes() {
29
- return this.data?.attribute;
50
+ return this.attributes?.length > 0;
30
51
  }
31
52
 
32
- // Helper to check if methods exist
33
53
  get hasMethods() {
34
- return this.data?.method;
54
+ return this.methods?.length > 0;
35
55
  }
36
56
 
37
- // Helper to check if slots exist
38
57
  get hasSlots() {
39
- return this.data?.slots;
58
+ return this.slots?.length > 0;
59
+ }
60
+
61
+ get hasEvents() {
62
+ return this.events?.length > 0;
40
63
  }
41
64
  }