@salesforcedevs/dx-components 1.31.8 → 1.31.9-alpha3

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.31.8",
3
+ "version": "1.31.9-alpha3",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -43,6 +43,5 @@
43
43
  "eventsourcemock": "2.0.0",
44
44
  "luxon": "3.4.4",
45
45
  "msw": "^2.12.4"
46
- },
47
- "gitHead": "3433c3870460a19b28ec23cbd97db1ddfe38ee05"
46
+ }
48
47
  }
@@ -143,6 +143,13 @@ code[class*="shiki"] {
143
143
  padding: 0 var(--dx-g-spacing-md) 0 var(--dx-g-spacing-sm);
144
144
  text-align: right;
145
145
  user-select: none;
146
+ }
147
+
148
+ .dx-theme-light .code-line-number {
149
+ color: var(--dx-g-gray-40);
150
+ }
151
+
152
+ .dx-theme-dark .code-line-number {
146
153
  color: var(--dx-g-gray-60);
147
154
  }
148
155
 
@@ -89,26 +89,51 @@ export const OPTIONAL_LANGUAGES: Record<string, any> = {
89
89
  agentscript: getCustomLanguageGrammars().agentscript
90
90
  };
91
91
 
92
+ const languageLoadPromises = new WeakMap<
93
+ HighlighterCore,
94
+ Map<string, Promise<void>>
95
+ >();
96
+
92
97
  export async function loadLanguageIfNeeded(
93
98
  highlighter: HighlighterCore,
94
99
  language: string
95
100
  ): Promise<void> {
96
- const loadedLanguages = highlighter.getLoadedLanguages();
101
+ // Fast path: already loaded
102
+ if (highlighter.getLoadedLanguages().includes(language as BundledLanguage)) {
103
+ return;
104
+ }
97
105
 
98
- if (!loadedLanguages.includes(language as BundledLanguage)) {
99
- const languageLoader = OPTIONAL_LANGUAGES[language];
100
-
101
- if (languageLoader) {
102
- try {
103
- await highlighter.loadLanguage(languageLoader);
104
- } catch (error) {
105
- console.warn(
106
- `Failed to load optional language ${language}:`,
107
- error
108
- );
109
- }
110
- }
106
+ const languageLoader = OPTIONAL_LANGUAGES[language];
107
+ if (!languageLoader) {
108
+ return;
109
+ }
110
+
111
+ // Get or create the promise map for this highlighter instance
112
+ if (!languageLoadPromises.has(highlighter)) {
113
+ languageLoadPromises.set(highlighter, new Map());
111
114
  }
115
+ const promiseMap = languageLoadPromises.get(highlighter)!;
116
+
117
+ // Reuse in-flight promise — prevents duplicate loadLanguage() calls
118
+ // when multiple code blocks request the same optional language concurrently
119
+ if (promiseMap.has(language)) {
120
+ return promiseMap.get(language);
121
+ }
122
+
123
+ const loadPromise = (async () => {
124
+ try {
125
+ await highlighter.loadLanguage(languageLoader);
126
+ } catch (error) {
127
+ promiseMap.delete(language); // allow retry on next call
128
+ console.warn(
129
+ `Failed to load optional language ${language}:`,
130
+ error
131
+ );
132
+ }
133
+ })();
134
+
135
+ promiseMap.set(language, loadPromise);
136
+ return loadPromise;
112
137
  }
113
138
 
114
139
  export function getMappedLanguage(language: string): BundledLanguage {
@@ -118,10 +143,11 @@ export function getMappedLanguage(language: string): BundledLanguage {
118
143
  }
119
144
 
120
145
  export function escapeHtml(text: string): string {
121
- const div = document.createElement("div");
122
- div.textContent = text;
123
- // eslint-disable-next-line @lwc/lwc/no-inner-html
124
- return div.innerHTML;
146
+ return text
147
+ .replace(/&/g, "&amp;")
148
+ .replace(/</g, "&lt;")
149
+ .replace(/>/g, "&gt;")
150
+ .replace(/"/g, "&quot;");
125
151
  }
126
152
 
127
153
  export function createShikiState(): ShikiState {
@@ -21,6 +21,21 @@ async function initializeShiki(): Promise<HighlighterCore> {
21
21
  return initializeHighlighter(shikiState, shikiModule);
22
22
  }
23
23
 
24
+ /**
25
+ * Pre-warms the Shiki highlighter. Call once at SSG startup (before pages
26
+ * render) so code blocks don't pay the cold-start cost on first render.
27
+ */
28
+ export async function preloadShiki(): Promise<void> {
29
+ await initializeShiki();
30
+ }
31
+
32
+ // Eagerly kick off initialization at module import time.
33
+ // In SSG, this module is imported during LWR startup — by the time
34
+ // the first code block renders, the highlighter will already be ready.
35
+ initializeShiki().catch((err) => {
36
+ console.error("Shiki pre-warming failed:", err);
37
+ });
38
+
24
39
  export async function highlightCode(
25
40
  code: string,
26
41
  language: string,
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.