@salesforcedevs/dx-components 1.20.13 → 1.20.14-cb-loading-1

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/dx-components",
3
- "version": "1.20.13",
3
+ "version": "1.20.14-cb-loading-1",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -46,6 +46,5 @@
46
46
  "volta": {
47
47
  "node": "20.19.0",
48
48
  "yarn": "1.22.19"
49
- },
50
- "gitHead": "533981cf67f89f660ad584fa977baf14825f51a6"
49
+ }
51
50
  }
@@ -130,3 +130,57 @@ pre[class*="shiki"] {
130
130
  dx-button {
131
131
  --dx-g-button-icon-color: var(--dx-g-cloud-blue-vibrant-50);
132
132
  }
133
+
134
+ .code-loading-skeleton {
135
+ padding: 14px 21px;
136
+ background-color: #fff;
137
+ border-radius: 0 0 0.3em 0.3em;
138
+ overflow: hidden;
139
+ height: var(--dx-code-block-height, auto);
140
+ }
141
+
142
+ .dx-theme-dark .code-loading-skeleton {
143
+ background-color: #000;
144
+ }
145
+
146
+ .skeleton-line {
147
+ height: 16px;
148
+ background: linear-gradient(
149
+ 90deg,
150
+ var(--dx-g-gray-80) 25%,
151
+ var(--dx-g-gray-70) 50%,
152
+ var(--dx-g-gray-80) 75%
153
+ );
154
+ background-size: 200% 100%;
155
+ animation: skeleton-loading 1.5s infinite;
156
+ border-radius: 4px;
157
+ margin-bottom: 8px;
158
+ }
159
+
160
+ .dx-theme-dark .skeleton-line {
161
+ background: linear-gradient(
162
+ 90deg,
163
+ var(--dx-g-blue-natural-30) 25%,
164
+ var(--dx-g-blue-natural-40) 50%,
165
+ var(--dx-g-blue-natural-30) 75%
166
+ );
167
+ background-size: 200% 100%;
168
+ }
169
+
170
+ .skeleton-line.short {
171
+ width: 60%;
172
+ }
173
+
174
+ .skeleton-line.medium {
175
+ width: 80%;
176
+ }
177
+
178
+ @keyframes skeleton-loading {
179
+ 0% {
180
+ background-position: 200% 0;
181
+ }
182
+
183
+ 100% {
184
+ background-position: -200% 0;
185
+ }
186
+ }
@@ -3,6 +3,7 @@ import { CodeBlockTheme, CodeBlockLanguage } from "typings/custom";
3
3
  import cx from "classnames";
4
4
  import { track as gtmTrack } from "dxUtils/analytics";
5
5
  import { highlightCode } from "dxUtils/shiki";
6
+ import { normalizeBoolean } from "dxUtils/normalizers";
6
7
 
7
8
  /*
8
9
  Custom language support is handled by the Shiki wrapper module
@@ -30,7 +31,17 @@ export default class CodeBlock extends LightningElement {
30
31
  // if it is true, it renders code as is coming instead of wrapping it into html/xml comments tags.
31
32
  @api isEncoded = false;
32
33
 
34
+ @api
35
+ get showLoadingIndicator() {
36
+ return this._showLoadingIndicator;
37
+ }
38
+
39
+ set showLoadingIndicator(value) {
40
+ this._showLoadingIndicator = normalizeBoolean(value);
41
+ }
42
+
33
43
  private _codeBlockRendered: boolean = false;
44
+ private _showLoadingIndicator: boolean = false;
34
45
  private markupLangs = ["visualforce", "html", "xml"];
35
46
  private componentLoaded: boolean = false;
36
47
  private showLanguageDropdown: boolean = false;
@@ -102,6 +113,60 @@ export default class CodeBlock extends LightningElement {
102
113
  return cx(`dx-theme-${this.theme}`);
103
114
  }
104
115
 
116
+ private calculateSkeletonLines(): number {
117
+ const computedStyle = window.getComputedStyle(this.template.host);
118
+ const customHeight = computedStyle.getPropertyValue(
119
+ "--dx-code-block-height"
120
+ );
121
+
122
+ if (
123
+ customHeight &&
124
+ customHeight !== "unset" &&
125
+ !customHeight.includes("auto")
126
+ ) {
127
+ const heightValue = parseFloat(customHeight);
128
+ const lineHeight = 20;
129
+ const verticalPadding = 28;
130
+ const availableHeight = heightValue - verticalPadding;
131
+ return Math.max(1, Math.floor(availableHeight / lineHeight));
132
+ }
133
+
134
+ return 4; // Default lines
135
+ }
136
+
137
+ private generateSkeletonHTML(lines: number): string {
138
+ const skeletonLines = Array.from({ length: lines }, (_, i) => {
139
+ const widthClass =
140
+ i % 3 === 0 ? "short" : i % 3 === 1 ? "medium" : "";
141
+ return `<div class="skeleton-line ${widthClass}"></div>`;
142
+ }).join("");
143
+
144
+ return `
145
+ <div class="code-loading-skeleton">
146
+ ${skeletonLines}
147
+ </div>
148
+ `;
149
+ }
150
+
151
+ private showLoadingSkeleton(): void {
152
+ if (!this.showLoadingIndicator) {
153
+ return;
154
+ }
155
+
156
+ const codeBlockContent = this.template.querySelector(
157
+ ".code-block-content"
158
+ );
159
+ if (!codeBlockContent) {
160
+ return;
161
+ }
162
+
163
+ // Calculate lines and generate skeleton
164
+ const lines = this.calculateSkeletonLines();
165
+ const skeletonHTML = this.generateSkeletonHTML(lines);
166
+
167
+ codeBlockContent.innerHTML = skeletonHTML;
168
+ }
169
+
105
170
  private initializeTheme() {
106
171
  window.addEventListener(EVENT_NAME, this.toggleTheme);
107
172
  const darkModeSetting = localStorage.getItem(
@@ -119,6 +184,9 @@ export default class CodeBlock extends LightningElement {
119
184
  }
120
185
 
121
186
  async formatCodeBlock() {
187
+ // Show loading skeleton immediately
188
+ this.showLoadingSkeleton();
189
+
122
190
  const divEl = this.template.querySelector("div.code-block-content");
123
191
  const templateEl = document.createElement("template");
124
192
 
@@ -9,6 +9,7 @@
9
9
  language={codeBlockItem.language}
10
10
  source-link={codeBlockItem.sourceLink}
11
11
  is-encoded={codeBlockItem.isEncoded}
12
+ show-loading-indicator={showLoadingIndicator}
12
13
  ></dx-code-block>
13
14
  </dx-tab-panel>
14
15
  </template>
@@ -1,14 +1,24 @@
1
1
  import { LightningElement, api } from "lwc";
2
2
  import { CodeBlockItem } from "typings/custom";
3
- import { safeDecodeURI, toJson } from "dxUtils/normalizers";
3
+ import { safeDecodeURI, toJson, normalizeBoolean } from "dxUtils/normalizers";
4
4
  import { DARK } from "dx/codeBlock";
5
5
 
6
6
  export default class TabbedCodeBlock extends LightningElement {
7
7
  _codeBlocks: CodeBlockItem[] = [];
8
+ private _showLoadingIndicator: boolean = false;
8
9
 
9
10
  // By default, we want a dark theme for the tabbed code block; however, if the user changes the theme of any code block, it updates the same across the entire website.
10
11
  @api defaultTheme = DARK;
11
12
 
13
+ @api
14
+ get showLoadingIndicator() {
15
+ return this._showLoadingIndicator;
16
+ }
17
+
18
+ set showLoadingIndicator(value) {
19
+ this._showLoadingIndicator = normalizeBoolean(value);
20
+ }
21
+
12
22
  get tabs(): string {
13
23
  // Use the code block headers to create a tabs array as a JSON string
14
24
  return JSON.stringify(
package/LICENSE DELETED
@@ -1,12 +0,0 @@
1
- Copyright (c) 2020, Salesforce.com, Inc.
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
-
6
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
-
8
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
-
10
- * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.