@salesforcedevs/dx-components 1.20.16 → 1.20.17-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 +77 -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.17-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": "07815cdf681065e2c2f967ab36c2482ed4819662"
|
|
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-loader {
|
|
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-loader {
|
|
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-loader" if:true={showLoaderUI}>
|
|
77
|
+
<dx-spinner size="medium" 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
|
|
@@ -31,6 +32,8 @@ export default class CodeBlock extends LightningElement {
|
|
|
31
32
|
@api isEncoded = false;
|
|
32
33
|
|
|
33
34
|
private _codeBlockRendered: boolean = false;
|
|
35
|
+
private _showLoadingIndicator: boolean = false;
|
|
36
|
+
private _isCbHeightCalculated: boolean = false;
|
|
34
37
|
private markupLangs = ["visualforce", "html", "xml"];
|
|
35
38
|
private componentLoaded: boolean = false;
|
|
36
39
|
private showLanguageDropdown: boolean = false;
|
|
@@ -82,6 +85,7 @@ export default class CodeBlock extends LightningElement {
|
|
|
82
85
|
}
|
|
83
86
|
set codeBlock(value: string) {
|
|
84
87
|
this._codeBlockRendered = false;
|
|
88
|
+
this._isCbHeightCalculated = false;
|
|
85
89
|
let match;
|
|
86
90
|
this._codeBlock = (
|
|
87
91
|
(match = preTagRegexp.exec(value.trim())) === null
|
|
@@ -90,6 +94,15 @@ export default class CodeBlock extends LightningElement {
|
|
|
90
94
|
).trim();
|
|
91
95
|
}
|
|
92
96
|
|
|
97
|
+
@api
|
|
98
|
+
get showLoadingIndicator() {
|
|
99
|
+
return this._showLoadingIndicator;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
set showLoadingIndicator(value) {
|
|
103
|
+
this._showLoadingIndicator = normalizeBoolean(value);
|
|
104
|
+
}
|
|
105
|
+
|
|
93
106
|
get updateThemeBtnText(): string {
|
|
94
107
|
return `Switch to ${this.theme === DARK ? "Light" : "Dark"} mode`;
|
|
95
108
|
}
|
|
@@ -102,6 +115,66 @@ 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._isCbHeightCalculated &&
|
|
122
|
+
!this._codeBlockRendered
|
|
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
|
+
|
|
145
|
+
const textSmValue =
|
|
146
|
+
parseFloat(computedStyle.getPropertyValue("--dx-g-text-sm")) ||
|
|
147
|
+
14;
|
|
148
|
+
const spacingMlgValue =
|
|
149
|
+
parseFloat(
|
|
150
|
+
computedStyle.getPropertyValue("--dx-g-spacing-mlg")
|
|
151
|
+
) || 20;
|
|
152
|
+
|
|
153
|
+
const codeLineHeight = spacingMlgValue;
|
|
154
|
+
const codeVerticalPadding = textSmValue * 2;
|
|
155
|
+
|
|
156
|
+
return lines * codeLineHeight + codeVerticalPadding;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private setupLoadingIndicator(): void {
|
|
163
|
+
if (!this.showLoadingIndicator) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const containerHeight = this.calculateContainerHeight();
|
|
167
|
+
if (containerHeight) {
|
|
168
|
+
const contentContainer = this.template.querySelector(
|
|
169
|
+
".code-block-content"
|
|
170
|
+
) as HTMLElement;
|
|
171
|
+
if (contentContainer) {
|
|
172
|
+
contentContainer.style.height = `${containerHeight}px`;
|
|
173
|
+
}
|
|
174
|
+
this._isCbHeightCalculated = true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
105
178
|
private initializeTheme() {
|
|
106
179
|
window.addEventListener(EVENT_NAME, this.toggleTheme);
|
|
107
180
|
const darkModeSetting = localStorage.getItem(
|
|
@@ -119,6 +192,9 @@ export default class CodeBlock extends LightningElement {
|
|
|
119
192
|
}
|
|
120
193
|
|
|
121
194
|
async formatCodeBlock() {
|
|
195
|
+
// Show loading indicator immediately
|
|
196
|
+
this.setupLoadingIndicator();
|
|
197
|
+
|
|
122
198
|
const divEl = this.template.querySelector("div.code-block-content");
|
|
123
199
|
const templateEl = document.createElement("template");
|
|
124
200
|
|
|
@@ -217,6 +293,7 @@ export default class CodeBlock extends LightningElement {
|
|
|
217
293
|
}
|
|
218
294
|
}
|
|
219
295
|
}
|
|
296
|
+
this._codeBlockRendered = true;
|
|
220
297
|
}
|
|
221
298
|
|
|
222
299
|
onLanguageChange(newLang: any) {
|
|
@@ -304,7 +381,6 @@ export default class CodeBlock extends LightningElement {
|
|
|
304
381
|
this.selectedLanguageLabel = this.selectedLanguage.label;
|
|
305
382
|
this.selectedLanguageId = this.selectedLanguage.id;
|
|
306
383
|
this.formatCodeBlock();
|
|
307
|
-
this._codeBlockRendered = true;
|
|
308
384
|
}
|
|
309
385
|
|
|
310
386
|
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.
|