@salesforcedevs/dx-components 1.20.13 → 1.20.14-cb-plain-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 +2 -3
- package/src/modules/dx/codeBlock/codeBlock.css +20 -0
- package/src/modules/dx/codeBlock/codeBlock.html +3 -0
- package/src/modules/dx/codeBlock/codeBlock.ts +72 -1
- package/src/modules/dx/tabbedCodeBlock/tabbedCodeBlock.html +1 -0
- package/src/modules/dx/tabbedCodeBlock/tabbedCodeBlock.ts +11 -1
- package/LICENSE +0 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dx-components",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.14-cb-plain-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
|
}
|
|
@@ -30,11 +30,13 @@ pre {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
div.dx-theme-dark {
|
|
33
|
+
position: relative;
|
|
33
34
|
border: var(--dx-g-dark-mode-toggle-button-border);
|
|
34
35
|
border-radius: var(--dx-code-block-toolbar-border-radius, 0.3em);
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
div.dx-theme-light {
|
|
39
|
+
position: relative;
|
|
38
40
|
border: var(--dx-g-light-mode-code-block-border);
|
|
39
41
|
border-radius: var(--dx-code-block-toolbar-border-radius, 0.3em);
|
|
40
42
|
}
|
|
@@ -130,3 +132,21 @@ pre[class*="shiki"] {
|
|
|
130
132
|
dx-button {
|
|
131
133
|
--dx-g-button-icon-color: var(--dx-g-cloud-blue-vibrant-50);
|
|
132
134
|
}
|
|
135
|
+
|
|
136
|
+
.code-block-loading-container {
|
|
137
|
+
position: absolute;
|
|
138
|
+
top: 0;
|
|
139
|
+
left: 0;
|
|
140
|
+
right: 0;
|
|
141
|
+
bottom: 0;
|
|
142
|
+
display: flex;
|
|
143
|
+
align-items: center;
|
|
144
|
+
justify-content: center;
|
|
145
|
+
background-color: rgb(255 255 255 / 90%);
|
|
146
|
+
border-radius: 0 0 0.3em 0.3em;
|
|
147
|
+
z-index: 10;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.dx-theme-dark .code-block-loading-container {
|
|
151
|
+
background-color: rgb(0 0 0 / 90%);
|
|
152
|
+
}
|
|
@@ -73,6 +73,9 @@
|
|
|
73
73
|
</div>
|
|
74
74
|
</div>
|
|
75
75
|
<div class="code-block-content" lwc:dom="manual"></div>
|
|
76
|
+
<div class="code-block-loading-container" if:true={showLoaderUI}>
|
|
77
|
+
<dx-spinner size="large" variant="brand"></dx-spinner>
|
|
78
|
+
</div>
|
|
76
79
|
</div>
|
|
77
80
|
</template>
|
|
78
81
|
<template if:false={codeBlock}>No content provided</template>
|
|
@@ -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,18 @@ 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;
|
|
45
|
+
private _loaderHeightSet: boolean = false;
|
|
34
46
|
private markupLangs = ["visualforce", "html", "xml"];
|
|
35
47
|
private componentLoaded: boolean = false;
|
|
36
48
|
private showLanguageDropdown: boolean = false;
|
|
@@ -82,6 +94,7 @@ export default class CodeBlock extends LightningElement {
|
|
|
82
94
|
}
|
|
83
95
|
set codeBlock(value: string) {
|
|
84
96
|
this._codeBlockRendered = false;
|
|
97
|
+
this._loaderHeightSet = false;
|
|
85
98
|
let match;
|
|
86
99
|
this._codeBlock = (
|
|
87
100
|
(match = preTagRegexp.exec(value.trim())) === null
|
|
@@ -102,6 +115,60 @@ export default class CodeBlock extends LightningElement {
|
|
|
102
115
|
return cx(`dx-theme-${this.theme}`);
|
|
103
116
|
}
|
|
104
117
|
|
|
118
|
+
get showLoaderUI(): boolean {
|
|
119
|
+
return (
|
|
120
|
+
this.showLoadingIndicator &&
|
|
121
|
+
!this._codeBlockRendered &&
|
|
122
|
+
this._loaderHeightSet
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private calculateContainerHeight(): number | null {
|
|
127
|
+
const computedStyle = window.getComputedStyle(this.template.host);
|
|
128
|
+
const customHeight = computedStyle.getPropertyValue(
|
|
129
|
+
"--dx-code-block-height"
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
// If custom height is set, use it
|
|
133
|
+
if (
|
|
134
|
+
customHeight &&
|
|
135
|
+
customHeight !== "unset" &&
|
|
136
|
+
!customHeight.includes("auto")
|
|
137
|
+
) {
|
|
138
|
+
return parseFloat(customHeight);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// If no custom height, calculate from number of lines + padding
|
|
142
|
+
if (this.codeBlock) {
|
|
143
|
+
const lines = this.codeBlock.split("\n").length;
|
|
144
|
+
const lineHeight = 20; // px
|
|
145
|
+
const verticalPadding = 28; // 14px top + 14px bottom
|
|
146
|
+
return lines * lineHeight + verticalPadding;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return null; // No height calculation possible
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private showPlainLoader(): void {
|
|
153
|
+
if (!this.showLoadingIndicator) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const containerHeight = this.calculateContainerHeight();
|
|
158
|
+
if (containerHeight) {
|
|
159
|
+
// Set height on the content container for proper positioning
|
|
160
|
+
const contentContainer = this.template.querySelector(
|
|
161
|
+
".code-block-content"
|
|
162
|
+
) as HTMLElement;
|
|
163
|
+
if (contentContainer) {
|
|
164
|
+
contentContainer.style.height = `${containerHeight}px`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Mark that loader height is set, which will show the loader
|
|
168
|
+
this._loaderHeightSet = true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
105
172
|
private initializeTheme() {
|
|
106
173
|
window.addEventListener(EVENT_NAME, this.toggleTheme);
|
|
107
174
|
const darkModeSetting = localStorage.getItem(
|
|
@@ -119,6 +186,9 @@ export default class CodeBlock extends LightningElement {
|
|
|
119
186
|
}
|
|
120
187
|
|
|
121
188
|
async formatCodeBlock() {
|
|
189
|
+
// Show loading indicator immediately
|
|
190
|
+
this.showPlainLoader();
|
|
191
|
+
|
|
122
192
|
const divEl = this.template.querySelector("div.code-block-content");
|
|
123
193
|
const templateEl = document.createElement("template");
|
|
124
194
|
|
|
@@ -216,6 +286,8 @@ export default class CodeBlock extends LightningElement {
|
|
|
216
286
|
);
|
|
217
287
|
}
|
|
218
288
|
}
|
|
289
|
+
// Content is now rendered, hide the loader
|
|
290
|
+
this._codeBlockRendered = true;
|
|
219
291
|
}
|
|
220
292
|
}
|
|
221
293
|
|
|
@@ -304,7 +376,6 @@ export default class CodeBlock extends LightningElement {
|
|
|
304
376
|
this.selectedLanguageLabel = this.selectedLanguage.label;
|
|
305
377
|
this.selectedLanguageId = this.selectedLanguage.id;
|
|
306
378
|
this.formatCodeBlock();
|
|
307
|
-
this._codeBlockRendered = true;
|
|
308
379
|
}
|
|
309
380
|
|
|
310
381
|
disconnectedCallback(): void {
|
|
@@ -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.
|