@salesforcedevs/dx-components 1.31.9-alpha7 → 1.31.9-alpha9
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 +4 -1
- package/src/modules/dx/codeBlock/codeBlock.ts +1 -0
- package/src/modules/dxUtils/shiki/__mocks__/shiki.ts +6 -2
- package/src/modules/dxUtils/shiki/__mocks__/shikiLang.ts +6 -0
- package/src/modules/dxUtils/shiki/__mocks__/shikiTheme.ts +5 -0
- package/src/modules/dxUtils/shikiCore/shikiCore.ts +6 -6
- package/src/modules/dxUtils/shikiStatic/shikiStatic.ts +56 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dx-components",
|
|
3
|
-
"version": "1.31.9-
|
|
3
|
+
"version": "1.31.9-alpha9",
|
|
4
4
|
"description": "DX Lightning web components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -43,5 +43,8 @@
|
|
|
43
43
|
"eventsourcemock": "2.0.0",
|
|
44
44
|
"luxon": "3.4.4",
|
|
45
45
|
"msw": "^2.12.4"
|
|
46
|
+
},
|
|
47
|
+
"volta": {
|
|
48
|
+
"node": "20.20.2"
|
|
46
49
|
}
|
|
47
50
|
}
|
|
@@ -35,7 +35,9 @@ export const createHighlighter = jest.fn().mockImplementation(() => {
|
|
|
35
35
|
"text",
|
|
36
36
|
"handlebars"
|
|
37
37
|
]),
|
|
38
|
-
|
|
38
|
+
getLoadedThemes: jest.fn().mockReturnValue(["light-plus", "material-theme-darker"]),
|
|
39
|
+
loadLanguage: jest.fn().mockResolvedValue(undefined),
|
|
40
|
+
loadTheme: jest.fn().mockResolvedValue(undefined)
|
|
39
41
|
});
|
|
40
42
|
});
|
|
41
43
|
|
|
@@ -92,7 +94,9 @@ export const createHighlighterCore = jest.fn().mockImplementation(() => {
|
|
|
92
94
|
"text",
|
|
93
95
|
"handlebars"
|
|
94
96
|
]),
|
|
95
|
-
|
|
97
|
+
getLoadedThemes: jest.fn().mockReturnValue(["light-plus", "material-theme-darker"]),
|
|
98
|
+
loadLanguage: jest.fn().mockResolvedValue(undefined),
|
|
99
|
+
loadTheme: jest.fn().mockResolvedValue(undefined)
|
|
96
100
|
});
|
|
97
101
|
});
|
|
98
102
|
|
|
@@ -100,7 +100,7 @@ const themeLoadPromises = new WeakMap<
|
|
|
100
100
|
Map<string, Promise<void>>
|
|
101
101
|
>();
|
|
102
102
|
|
|
103
|
-
async function loadThemeIfNeeded(
|
|
103
|
+
export async function loadThemeIfNeeded(
|
|
104
104
|
highlighter: HighlighterCore,
|
|
105
105
|
themeName: BundledTheme
|
|
106
106
|
): Promise<void> {
|
|
@@ -197,7 +197,9 @@ export function createShikiState(): ShikiState {
|
|
|
197
197
|
export async function initializeHighlighter(
|
|
198
198
|
shikiState: ShikiState,
|
|
199
199
|
shikiModule: ShikiModule,
|
|
200
|
-
engine: any
|
|
200
|
+
engine: any,
|
|
201
|
+
langs?: any[],
|
|
202
|
+
themes?: any[]
|
|
201
203
|
): Promise<HighlighterCore> {
|
|
202
204
|
if (shikiState.highlighter) {
|
|
203
205
|
return shikiState.highlighter;
|
|
@@ -208,11 +210,9 @@ export async function initializeHighlighter(
|
|
|
208
210
|
}
|
|
209
211
|
|
|
210
212
|
shikiState.initPromise = (async () => {
|
|
211
|
-
// Only load the default light theme upfront; dark theme is lazy-loaded
|
|
212
|
-
// on first dark-mode request via loadThemeIfNeeded().
|
|
213
213
|
const highlighter = await shikiModule.createHighlighterCore({
|
|
214
|
-
themes: [THEME_MAP.light],
|
|
215
|
-
langs: CORE_LANGUAGES,
|
|
214
|
+
themes: themes ?? [THEME_MAP.light],
|
|
215
|
+
langs: langs ?? CORE_LANGUAGES,
|
|
216
216
|
engine
|
|
217
217
|
});
|
|
218
218
|
shikiState.highlighter = highlighter;
|
|
@@ -1,6 +1,34 @@
|
|
|
1
|
-
import type { HighlighterCore } from "shiki";
|
|
2
|
-
import { createHighlighterCore
|
|
1
|
+
import type { HighlighterCore } from "shiki/core";
|
|
2
|
+
import { createHighlighterCore } from "shiki/core";
|
|
3
|
+
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
|
|
3
4
|
import { transformerColorizedBrackets } from "@shikijs/colorized-brackets";
|
|
5
|
+
|
|
6
|
+
// Individual language grammars — the bundler only processes these ~19 files
|
|
7
|
+
// instead of shiki's bundle-full.mjs which contains all 638 language factories.
|
|
8
|
+
import apex from "shiki/langs/apex.mjs";
|
|
9
|
+
import javascript from "shiki/langs/javascript.mjs";
|
|
10
|
+
import html from "shiki/langs/html.mjs";
|
|
11
|
+
import css from "shiki/langs/css.mjs";
|
|
12
|
+
import json from "shiki/langs/json.mjs";
|
|
13
|
+
import sql from "shiki/langs/sql.mjs";
|
|
14
|
+
import bash from "shiki/langs/bash.mjs";
|
|
15
|
+
import xml from "shiki/langs/xml.mjs";
|
|
16
|
+
import graphql from "shiki/langs/graphql.mjs";
|
|
17
|
+
import jsx from "shiki/langs/jsx.mjs";
|
|
18
|
+
import typescript from "shiki/langs/typescript.mjs";
|
|
19
|
+
import markdown from "shiki/langs/markdown.mjs";
|
|
20
|
+
import python from "shiki/langs/python.mjs";
|
|
21
|
+
import java from "shiki/langs/java.mjs";
|
|
22
|
+
import yaml from "shiki/langs/yaml.mjs";
|
|
23
|
+
import php from "shiki/langs/php.mjs";
|
|
24
|
+
import swift from "shiki/langs/swift.mjs";
|
|
25
|
+
import kotlin from "shiki/langs/kotlin.mjs";
|
|
26
|
+
import handlebars from "shiki/langs/handlebars.mjs";
|
|
27
|
+
|
|
28
|
+
// Individual themes — avoids loading all bundled themes.
|
|
29
|
+
import lightPlusTheme from "shiki/themes/light-plus.mjs";
|
|
30
|
+
import darkTheme from "shiki/themes/material-theme-darker.mjs";
|
|
31
|
+
|
|
4
32
|
import {
|
|
5
33
|
createShikiState,
|
|
6
34
|
initializeHighlighter,
|
|
@@ -8,30 +36,41 @@ import {
|
|
|
8
36
|
escapeHtml as coreEscapeHtml,
|
|
9
37
|
ShikiState
|
|
10
38
|
} from "dxUtils/shikiCore";
|
|
39
|
+
import { getCustomLanguageGrammars } from "dxUtils/shikiGrammars";
|
|
11
40
|
|
|
12
41
|
/**
|
|
13
|
-
* Static loading version of Shiki.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
42
|
+
* Static loading version of Shiki for SSG.
|
|
43
|
+
* Imports from shiki/core + individual language/theme files so the bundler
|
|
44
|
+
* only processes what is actually used, instead of shiki's bundle-full.mjs
|
|
45
|
+
* (638 language factories).
|
|
16
46
|
*/
|
|
17
47
|
|
|
48
|
+
// All languages loaded upfront — custom grammars are grammar objects already.
|
|
49
|
+
const ALL_LANGUAGES = [
|
|
50
|
+
apex, javascript, html, css, json, sql, bash, xml, graphql, jsx,
|
|
51
|
+
typescript, markdown, python, java, yaml, php, swift, kotlin, handlebars,
|
|
52
|
+
getCustomLanguageGrammars().ampscript,
|
|
53
|
+
getCustomLanguageGrammars().dataweave,
|
|
54
|
+
getCustomLanguageGrammars().agentscript
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
// Both themes loaded upfront so theme switching has no cold-start cost.
|
|
58
|
+
const ALL_THEMES = [lightPlusTheme, darkTheme];
|
|
59
|
+
|
|
18
60
|
const shikiState: ShikiState = createShikiState();
|
|
19
61
|
|
|
20
62
|
async function initializeShiki(): Promise<HighlighterCore> {
|
|
21
|
-
return initializeHighlighter(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
export async function preloadShiki(): Promise<void> {
|
|
29
|
-
await initializeShiki();
|
|
63
|
+
return initializeHighlighter(
|
|
64
|
+
shikiState,
|
|
65
|
+
{ createHighlighterCore },
|
|
66
|
+
createJavaScriptRegexEngine(),
|
|
67
|
+
ALL_LANGUAGES,
|
|
68
|
+
ALL_THEMES
|
|
69
|
+
);
|
|
30
70
|
}
|
|
31
71
|
|
|
32
|
-
// Eagerly kick off initialization at module import time
|
|
33
|
-
//
|
|
34
|
-
// the first code block renders, the highlighter will already be ready.
|
|
72
|
+
// Eagerly kick off initialization at module import time so Shiki is ready
|
|
73
|
+
// before the first code block renders.
|
|
35
74
|
initializeShiki().catch((err) => {
|
|
36
75
|
console.error("Shiki pre-warming failed:", err);
|
|
37
76
|
});
|