@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.31.9-alpha7",
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
  }
@@ -406,6 +406,7 @@ export default class CodeBlock extends LightningElement {
406
406
  ) || this.allLanguages[0];
407
407
  this.selectedLanguageLabel = this.selectedLanguage.label;
408
408
  this.selectedLanguageId = this.selectedLanguage.id;
409
+
409
410
  this.formatCodeBlock();
410
411
  }
411
412
 
@@ -35,7 +35,9 @@ export const createHighlighter = jest.fn().mockImplementation(() => {
35
35
  "text",
36
36
  "handlebars"
37
37
  ]),
38
- loadLanguage: jest.fn().mockResolvedValue(undefined)
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
- loadLanguage: jest.fn().mockResolvedValue(undefined)
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
 
@@ -0,0 +1,6 @@
1
+ // Mock default export for individual shiki language grammar files (shiki/langs/*)
2
+ export default {
3
+ name: "mock-lang",
4
+ scopeName: "source.mock",
5
+ patterns: []
6
+ };
@@ -0,0 +1,5 @@
1
+ // Mock default export for individual shiki theme files (shiki/themes/*)
2
+ export default {
3
+ name: "mock-theme",
4
+ type: "light" as const
5
+ };
@@ -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, createJavaScriptRegexEngine } from "shiki";
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
- * Uses static imports - shiki is bundled with this module.
15
- * Use this for SSG compatibility and it is very specific to SSG generated components using LWR.
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(shikiState, { createHighlighterCore }, createJavaScriptRegexEngine());
22
- }
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();
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
- // In SSG, this module is imported during LWR startup — by the time
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
  });