@salesforcedevs/dx-components 1.3.352 → 1.3.353-tabbed-codeblock1

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/lwc.config.json CHANGED
@@ -91,6 +91,7 @@
91
91
  "dx/stepSequenceStep",
92
92
  "dx/tabPanel",
93
93
  "dx/tabPanelList",
94
+ "dx/tabbedCodeBlock",
94
95
  "dx/tbidAvatarButton",
95
96
  "dx/toast",
96
97
  "dx/toc",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.3.352",
3
+ "version": "1.3.353-tabbed-codeblock1",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -45,6 +45,5 @@
45
45
  },
46
46
  "volta": {
47
47
  "node": "18.18.0"
48
- },
49
- "gitHead": "336de44c52a7dca8b05119cfb36a94273b222f80"
48
+ }
50
49
  }
@@ -9,6 +9,7 @@
9
9
 
10
10
  pre {
11
11
  margin: 0 !important;
12
+ height: var(--dx-code-block-height, unset);
12
13
  }
13
14
 
14
15
  .copyta {
@@ -19,7 +20,7 @@ pre {
19
20
  }
20
21
 
21
22
  .toolbar {
22
- border-radius: 0.3em 0.3em 0 0;
23
+ border-radius: var(--dx-code-block-toolbar-border-radius, 0.3em 0.3em 0 0);
23
24
  opacity: 1;
24
25
  display: flex;
25
26
  align-items: center;
@@ -39,14 +39,14 @@ prism.languages.sql_docs_template = sqlDocsTemplate;
39
39
  // Used for remove enclosing <pre> tag's (if occurs)
40
40
  const preTagRegexp: RegExp = /^<pre.*?>(.*)<\/pre>$/is;
41
41
 
42
- const LIGHT = "light";
43
- const DARK = "dark";
42
+ export const LIGHT = "light";
43
+ export const DARK = "dark";
44
44
  const themes: CodeBlockTheme[] = [LIGHT, DARK];
45
45
  const LOCAL_STORAGE_KEY = "dx-codeblock-theme";
46
46
 
47
47
  export default class CodeBlock extends LightningElement {
48
48
  @api defaultTheme: CodeBlockTheme = LIGHT;
49
- @api header: string = "title";
49
+ @api header: string = "";
50
50
  @api sourceLink: string = "";
51
51
  @api language: string = "";
52
52
  // if it is true, it renders code as is coming instead of wrapping it into html/xml comments tags.
@@ -6,7 +6,7 @@
6
6
  font-size: var(--dx-g-text-base);
7
7
  font-weight: var(--dx-g-font-normal);
8
8
  line-height: var(--dx-g-spacing-lg);
9
- padding: var(--dx-g-spacing-smd) var(--dx-g-spacing-lg);
9
+ padding: var(--dx-g-spacing-sm) var(--dx-g-spacing-lg);
10
10
  border-top-left-radius: var(--dx-g-spacing-sm);
11
11
  border-top-right-radius: var(--dx-g-spacing-sm);
12
12
  border-bottom: var(--dx-g-spacing-xs) solid transparent;
@@ -0,0 +1,8 @@
1
+ dx-code-block {
2
+ --dx-code-block-height: 320px;
3
+ --dx-code-block-toolbar-border-radius: 0;
4
+ }
5
+
6
+ dx-tab-panel-list {
7
+ --dx-c-tab-panel-list-horizontal-padding: 0;
8
+ }
@@ -0,0 +1,16 @@
1
+ <template>
2
+ <dx-tab-panel-list tabs={tabs}>
3
+ <template for:each={_codeBlocks} for:item="codeBlockItem">
4
+ <dx-tab-panel key={codeBlockItem.header}>
5
+ <!-- The header attribute is not passed intentionally because the tab title uses the header value. -->
6
+ <dx-code-block
7
+ default-theme={defaultTheme}
8
+ code-block={codeBlockItem.codeBlock}
9
+ language={codeBlockItem.language}
10
+ source-link={codeBlockItem.sourceLink}
11
+ is-encoded={codeBlockItem.isEncoded}
12
+ ></dx-code-block>
13
+ </dx-tab-panel>
14
+ </template>
15
+ </dx-tab-panel-list>
16
+ </template>
@@ -0,0 +1,44 @@
1
+ import { LightningElement, api } from "lwc";
2
+ import { CodeBlockItem } from "typings/custom";
3
+ import { safeDecodeURI, toJson } from "dxUtils/normalizers";
4
+ import { DARK } from "dx/codeBlock";
5
+
6
+ export default class TabbedCodeBlock extends LightningElement {
7
+ _codeBlocks: CodeBlockItem[] = [];
8
+
9
+ // 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
+ @api defaultTheme = DARK;
11
+
12
+ get tabs(): string {
13
+ // Use the code block headers to create a tabs array as a JSON string
14
+ return JSON.stringify(
15
+ this._codeBlocks.map((codeBlock) => ({ label: codeBlock.header }))
16
+ );
17
+ }
18
+
19
+ // We need to pass the attribute as decodedURI(JSON.stringify(codeBlocksArray)) to avoid issues with single and double quotes in the code block content.
20
+ @api
21
+ set codeBlocks(value: string) {
22
+ if (value) {
23
+ // Decode the encoded code block JSON string
24
+ const decodeCodeBlockJson = safeDecodeURI(value);
25
+ try {
26
+ const codeBlockItems = toJson(decodeCodeBlockJson);
27
+ this._codeBlocks = codeBlockItems.map(
28
+ (codeBlock: CodeBlockItem) => {
29
+ return {
30
+ ...codeBlock,
31
+ defaultTheme: this.defaultTheme
32
+ };
33
+ }
34
+ );
35
+ } catch (exception) {
36
+ console.log("Invalid codeblock items json", exception);
37
+ }
38
+ }
39
+ }
40
+
41
+ get codeBlocks(): CodeBlockItem[] {
42
+ return this._codeBlocks;
43
+ }
44
+ }
@@ -76,3 +76,15 @@ export const normalizeBoolean = (
76
76
  export const normalizeDomId = (id: string): string => {
77
77
  return id.replace(/^[^a-z]+|[^\w.-]+/gi, "");
78
78
  };
79
+
80
+ export const safeDecodeURI = (value: string): string => {
81
+ try {
82
+ // Check if the value contains URI encoding patterns
83
+ return typeof value === "string" && value.includes("%")
84
+ ? decodeURIComponent(value)
85
+ : value;
86
+ } catch (error) {
87
+ // In case of any errors, return the original value
88
+ return value;
89
+ }
90
+ };
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.