@qualcomm-ui/mdx-vite 1.0.3 → 2.0.0
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/dist/cli.js +266 -215
- package/dist/cli.js.map +4 -4
- package/dist/docs-plugin/docs-plugin.d.ts.map +1 -1
- package/dist/docs-plugin/generate-page-map.d.ts +2 -0
- package/dist/docs-plugin/generate-page-map.d.ts.map +1 -0
- package/dist/docs-plugin/internal/search-indexer.d.ts.map +1 -1
- package/dist/docs-plugin/internal/services/markdown/markdown-indexer.d.ts.map +1 -1
- package/dist/docs-plugin/internal/services/markdown/markdown.types.d.ts +2 -1
- package/dist/docs-plugin/internal/services/markdown/markdown.types.d.ts.map +1 -1
- package/dist/docs-plugin/internal/zod.d.ts +1 -1
- package/dist/index.js +67 -650
- package/dist/index.js.map +3 -3
- package/dist/react-demo-plugin/demo-plugin-utils.d.ts +0 -21
- package/dist/react-demo-plugin/demo-plugin-utils.d.ts.map +1 -1
- package/dist/react-demo-plugin/react-demo-plugin.d.ts +5 -1
- package/dist/react-demo-plugin/react-demo-plugin.d.ts.map +1 -1
- package/dist/react-demo-plugin/virtual.d.ts +0 -12
- package/dist/tsbuildinfo +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1452,7 +1452,7 @@ var DocPropsIndexer = class {
|
|
|
1452
1452
|
};
|
|
1453
1453
|
const comment = prop.comment;
|
|
1454
1454
|
if (!comment) {
|
|
1455
|
-
return { content: [], heading: heading2 };
|
|
1455
|
+
return { content: [], heading: heading2, richContent: [] };
|
|
1456
1456
|
}
|
|
1457
1457
|
const content = {
|
|
1458
1458
|
tagName: "p",
|
|
@@ -1460,7 +1460,7 @@ var DocPropsIndexer = class {
|
|
|
1460
1460
|
comment.summary.map((entry) => entry.text.replaceAll("\n", " ")).join("")
|
|
1461
1461
|
]
|
|
1462
1462
|
};
|
|
1463
|
-
return { content: [content], heading: heading2 };
|
|
1463
|
+
return { content: [content], heading: heading2, richContent: [] };
|
|
1464
1464
|
}
|
|
1465
1465
|
};
|
|
1466
1466
|
|
|
@@ -1903,7 +1903,8 @@ var MarkdownIndexer = class {
|
|
|
1903
1903
|
resetSection() {
|
|
1904
1904
|
this.currentSection = {
|
|
1905
1905
|
content: [],
|
|
1906
|
-
heading: null
|
|
1906
|
+
heading: null,
|
|
1907
|
+
richContent: []
|
|
1907
1908
|
};
|
|
1908
1909
|
}
|
|
1909
1910
|
get toc() {
|
|
@@ -1957,6 +1958,7 @@ var MarkdownIndexer = class {
|
|
|
1957
1958
|
this.currentSection.heading = heading2;
|
|
1958
1959
|
return;
|
|
1959
1960
|
}
|
|
1961
|
+
this.currentSection.richContent.push(element);
|
|
1960
1962
|
const text = toText(element, { whitespace: "pre-wrap" }).replaceAll("\n", " ").split(" ").filter(size);
|
|
1961
1963
|
if (text.length) {
|
|
1962
1964
|
this.currentSection.content.push({
|
|
@@ -2636,7 +2638,8 @@ var SearchIndexer = class {
|
|
|
2636
2638
|
headingLevel: section.heading?.headingLevel,
|
|
2637
2639
|
href: section.heading && (this.allowedHeadings.has(section.heading.tagName) || isDocProp) ? `${defaultSection.pathname}#${section.heading.id}` : defaultSection.pathname,
|
|
2638
2640
|
id: `${defaultSection.id}-${index}${isDocProp ? "-prop" : ""}`,
|
|
2639
|
-
isDocProp: isDocProp || void 0
|
|
2641
|
+
isDocProp: isDocProp || void 0,
|
|
2642
|
+
richContent: section.richContent
|
|
2640
2643
|
};
|
|
2641
2644
|
});
|
|
2642
2645
|
}
|
|
@@ -2682,6 +2685,7 @@ var SearchIndexer = class {
|
|
|
2682
2685
|
|
|
2683
2686
|
// src/docs-plugin/docs-plugin.ts
|
|
2684
2687
|
var isDev = process.env.NODE_ENV === "development";
|
|
2688
|
+
var VIRTUAL_MODULE_ID2 = "\0@qualcomm-ui/mdx-vite-plugin";
|
|
2685
2689
|
var PluginState = class {
|
|
2686
2690
|
buildCount = 0;
|
|
2687
2691
|
configFilePath = "";
|
|
@@ -2692,12 +2696,7 @@ var PluginState = class {
|
|
|
2692
2696
|
servers = [];
|
|
2693
2697
|
timeout = void 0;
|
|
2694
2698
|
watching = false;
|
|
2695
|
-
resolvedVirtualModuleId;
|
|
2696
|
-
virtualModuleId = "@qualcomm-ui/mdx-vite-plugin";
|
|
2697
2699
|
cwd;
|
|
2698
|
-
constructor() {
|
|
2699
|
-
this.resolvedVirtualModuleId = `\0${this.virtualModuleId}`;
|
|
2700
|
-
}
|
|
2701
2700
|
init(cwd) {
|
|
2702
2701
|
this.cwd = cwd;
|
|
2703
2702
|
}
|
|
@@ -2753,27 +2752,25 @@ var PluginState = class {
|
|
|
2753
2752
|
}
|
|
2754
2753
|
}
|
|
2755
2754
|
/**
|
|
2756
|
-
* When the user
|
|
2757
|
-
*
|
|
2758
|
-
*
|
|
2755
|
+
* When the user adds or removes mdx files, we re-index the site. This function
|
|
2756
|
+
* handles module invalidation so that virtual file imports are refreshed as
|
|
2757
|
+
* expected by the consumer's dev server.
|
|
2759
2758
|
*/
|
|
2760
2759
|
sendUpdate() {
|
|
2761
2760
|
for (const server of this.servers) {
|
|
2762
|
-
const virtualModule = server.moduleGraph.getModuleById(
|
|
2763
|
-
this.resolvedVirtualModuleId
|
|
2764
|
-
);
|
|
2761
|
+
const virtualModule = server.moduleGraph.getModuleById(VIRTUAL_MODULE_ID2);
|
|
2765
2762
|
if (virtualModule) {
|
|
2766
2763
|
server.moduleGraph.invalidateModule(virtualModule);
|
|
2767
2764
|
server.reloadModule(virtualModule);
|
|
2768
2765
|
}
|
|
2769
2766
|
}
|
|
2770
2767
|
}
|
|
2771
|
-
handleChange(
|
|
2768
|
+
handleChange(opts = {}) {
|
|
2772
2769
|
clearTimeout(this.timeout);
|
|
2773
2770
|
this.timeout = setTimeout(() => {
|
|
2774
2771
|
this.buildIndex(true);
|
|
2775
2772
|
this.sendUpdate();
|
|
2776
|
-
|
|
2773
|
+
opts?.onComplete?.();
|
|
2777
2774
|
}, 300);
|
|
2778
2775
|
}
|
|
2779
2776
|
initWatchers(configFile) {
|
|
@@ -2818,41 +2815,51 @@ function quiDocsPlugin(opts) {
|
|
|
2818
2815
|
state.initWatchers(opts?.configFile);
|
|
2819
2816
|
server.watcher.on("add", (path) => {
|
|
2820
2817
|
if (path.endsWith(".mdx")) {
|
|
2821
|
-
state.handleChange(
|
|
2822
|
-
|
|
2818
|
+
state.handleChange({
|
|
2819
|
+
onComplete: () => {
|
|
2820
|
+
server.ws.send({ type: "full-reload" });
|
|
2821
|
+
}
|
|
2823
2822
|
});
|
|
2824
2823
|
}
|
|
2825
2824
|
});
|
|
2826
2825
|
server.watcher.on("unlink", (path) => {
|
|
2827
2826
|
if (path.endsWith(".mdx")) {
|
|
2828
|
-
state.handleChange(
|
|
2829
|
-
|
|
2827
|
+
state.handleChange({
|
|
2828
|
+
onComplete: () => {
|
|
2829
|
+
server.ws.send({ type: "full-reload" });
|
|
2830
|
+
}
|
|
2830
2831
|
});
|
|
2831
2832
|
}
|
|
2832
2833
|
});
|
|
2833
2834
|
state.servers.push(server);
|
|
2834
2835
|
},
|
|
2835
|
-
handleHotUpdate: async ({ file: updateFile }) => {
|
|
2836
|
+
handleHotUpdate: async ({ file: updateFile, modules, server }) => {
|
|
2836
2837
|
const file = fixPath(updateFile);
|
|
2837
2838
|
if ((!config.hotUpdateIgnore || !config.hotUpdateIgnore.test(file)) && // ignore watched files. We watch for these separately.
|
|
2838
2839
|
file !== state.configFilePath) {
|
|
2839
2840
|
if (state.docPropsDirectory && file.startsWith(state.docPropsFilePath)) {
|
|
2840
2841
|
return [];
|
|
2841
2842
|
}
|
|
2842
|
-
state.
|
|
2843
|
+
state.buildIndex(true);
|
|
2844
|
+
if (updateFile.endsWith(".mdx")) {
|
|
2845
|
+
const virtualModule = server.moduleGraph.getModuleById(VIRTUAL_MODULE_ID2);
|
|
2846
|
+
if (virtualModule) {
|
|
2847
|
+
server.moduleGraph.invalidateModule(virtualModule);
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2843
2850
|
}
|
|
2844
|
-
return
|
|
2851
|
+
return modules;
|
|
2845
2852
|
},
|
|
2846
2853
|
load: (id) => {
|
|
2847
|
-
if (id ===
|
|
2854
|
+
if (id === VIRTUAL_MODULE_ID2) {
|
|
2848
2855
|
return `export const siteData = ${JSON.stringify({ navItems: state.indexer.navItems, pageDocProps: state.indexer.pageDocProps, pageMap: state.indexer.pageMap, searchIndex: state.indexer.searchIndex })}`;
|
|
2849
2856
|
}
|
|
2850
2857
|
return void 0;
|
|
2851
2858
|
},
|
|
2852
2859
|
name: "qui-mdx-vite-plugin",
|
|
2853
2860
|
resolveId: (id) => {
|
|
2854
|
-
if (id ===
|
|
2855
|
-
return
|
|
2861
|
+
if (id === "@qualcomm-ui/mdx-vite-plugin") {
|
|
2862
|
+
return VIRTUAL_MODULE_ID2;
|
|
2856
2863
|
}
|
|
2857
2864
|
return void 0;
|
|
2858
2865
|
}
|
|
@@ -3282,7 +3289,6 @@ var NODE_BUILTINS = [
|
|
|
3282
3289
|
|
|
3283
3290
|
// src/react-demo-plugin/demo-plugin-utils.ts
|
|
3284
3291
|
import chalk5 from "chalk";
|
|
3285
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
3286
3292
|
import { existsSync as existsSync2, readFileSync as readFileSync3 } from "node:fs";
|
|
3287
3293
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
3288
3294
|
import { dirname as dirname2, join as join3, relative as relative2, resolve as resolve3, sep } from "node:path";
|
|
@@ -3311,21 +3317,6 @@ async function extractFileImports(filePath) {
|
|
|
3311
3317
|
return null;
|
|
3312
3318
|
}
|
|
3313
3319
|
}
|
|
3314
|
-
function mergeImports(importMap, imports) {
|
|
3315
|
-
for (const { source, specifiers } of imports) {
|
|
3316
|
-
if (isNodeBuiltin(source)) {
|
|
3317
|
-
continue;
|
|
3318
|
-
}
|
|
3319
|
-
let sourceSpecifiers = importMap.get(source);
|
|
3320
|
-
if (!sourceSpecifiers) {
|
|
3321
|
-
sourceSpecifiers = /* @__PURE__ */ new Set();
|
|
3322
|
-
importMap.set(source, sourceSpecifiers);
|
|
3323
|
-
}
|
|
3324
|
-
for (const spec of specifiers) {
|
|
3325
|
-
sourceSpecifiers.add(spec);
|
|
3326
|
-
}
|
|
3327
|
-
}
|
|
3328
|
-
}
|
|
3329
3320
|
function extractImports(code, fileName) {
|
|
3330
3321
|
const sourceFile = ts2.createSourceFile(
|
|
3331
3322
|
fileName,
|
|
@@ -3439,18 +3430,6 @@ function resolveRelativeImport(source, fromFile) {
|
|
|
3439
3430
|
}
|
|
3440
3431
|
return resolved;
|
|
3441
3432
|
}
|
|
3442
|
-
async function extractAllImports(files) {
|
|
3443
|
-
const importMap = /* @__PURE__ */ new Map();
|
|
3444
|
-
const relativeImports = [];
|
|
3445
|
-
for (const filePath of files) {
|
|
3446
|
-
const result = await extractFileImports(filePath);
|
|
3447
|
-
if (result) {
|
|
3448
|
-
mergeImports(importMap, result.thirdPartyImports);
|
|
3449
|
-
relativeImports.push(...result.relativeImports);
|
|
3450
|
-
}
|
|
3451
|
-
}
|
|
3452
|
-
return { importMap, relativeImports };
|
|
3453
|
-
}
|
|
3454
3433
|
function isRelativeImport(source) {
|
|
3455
3434
|
return source.startsWith("./") || source.startsWith("../");
|
|
3456
3435
|
}
|
|
@@ -3585,90 +3564,6 @@ function resolvePathAlias2(source, pathAliases) {
|
|
|
3585
3564
|
}
|
|
3586
3565
|
return null;
|
|
3587
3566
|
}
|
|
3588
|
-
function sanitizeSourceName(source) {
|
|
3589
|
-
return source.replace(/@/g, "at_").replace(/\//g, "_").replace(/[^a-zA-Z0-9_]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
|
|
3590
|
-
}
|
|
3591
|
-
function sanitizeIdentifier(str) {
|
|
3592
|
-
return str.replace(/[^a-zA-Z0-9]/g, "_");
|
|
3593
|
-
}
|
|
3594
|
-
function createUniqueModuleName(source) {
|
|
3595
|
-
const hash = createHash2("sha256").update(source).digest("hex").substring(0, 8);
|
|
3596
|
-
const baseName = source.split("/").pop()?.replace(/[^a-zA-Z0-9]/g, "_")?.replace(/^_+|_+$/g, "")?.replace(/^(\d)/, "_$1") || "module";
|
|
3597
|
-
return `mod_${baseName}_${hash}`;
|
|
3598
|
-
}
|
|
3599
|
-
function addReactImports(imports, scopeEntries) {
|
|
3600
|
-
imports.push(`import React from "react"`);
|
|
3601
|
-
imports.push(`import {
|
|
3602
|
-
${REACT_IMPORTS.join(", ")}
|
|
3603
|
-
} from "react"`);
|
|
3604
|
-
scopeEntries.push("React", ...REACT_IMPORTS);
|
|
3605
|
-
}
|
|
3606
|
-
function addThirdPartyImports(importMap, imports, scopeEntries) {
|
|
3607
|
-
const sortedImports = Array.from(importMap.entries()).sort(
|
|
3608
|
-
([a], [b]) => a.localeCompare(b)
|
|
3609
|
-
);
|
|
3610
|
-
const usedNames = /* @__PURE__ */ new Set(["React", ...REACT_IMPORTS]);
|
|
3611
|
-
for (const [source, specifiers] of sortedImports) {
|
|
3612
|
-
const moduleName = createUniqueModuleName(source);
|
|
3613
|
-
imports.push(`import * as ${moduleName} from "${source}"`);
|
|
3614
|
-
addModuleToScope(source, specifiers, moduleName, scopeEntries, usedNames);
|
|
3615
|
-
}
|
|
3616
|
-
}
|
|
3617
|
-
function addThirdPartyImportsNamespaced(importMap, imports, scopeEntries, demoName) {
|
|
3618
|
-
const sortedImports = Array.from(importMap.entries()).sort(
|
|
3619
|
-
([a], [b]) => a.localeCompare(b)
|
|
3620
|
-
);
|
|
3621
|
-
const usedNames = /* @__PURE__ */ new Set(["React", ...REACT_IMPORTS]);
|
|
3622
|
-
for (const [source, specifiers] of sortedImports) {
|
|
3623
|
-
const moduleName = `${sanitizeIdentifier(demoName)}_${createUniqueModuleName(source)}`;
|
|
3624
|
-
imports.push(`import * as ${moduleName} from "${source}"`);
|
|
3625
|
-
addModuleToScope(source, specifiers, moduleName, scopeEntries, usedNames);
|
|
3626
|
-
}
|
|
3627
|
-
}
|
|
3628
|
-
function addRelativeImportsNamespaced(relativeImports, imports, scopeEntries, demoName) {
|
|
3629
|
-
const processedPaths = /* @__PURE__ */ new Set();
|
|
3630
|
-
for (const { resolvedPath, specifiers } of relativeImports) {
|
|
3631
|
-
if (processedPaths.has(resolvedPath)) {
|
|
3632
|
-
continue;
|
|
3633
|
-
}
|
|
3634
|
-
processedPaths.add(resolvedPath);
|
|
3635
|
-
const moduleName = `${sanitizeIdentifier(demoName)}_${createUniqueModuleName(resolvedPath)}`;
|
|
3636
|
-
imports.push(`import * as ${moduleName} from "${resolvedPath}"`);
|
|
3637
|
-
for (const { imported, local } of specifiers) {
|
|
3638
|
-
if (imported === "default") {
|
|
3639
|
-
scopeEntries.push(`${local}: ${moduleName}.default`);
|
|
3640
|
-
} else if (imported === "*") {
|
|
3641
|
-
scopeEntries.push(`...${moduleName}`);
|
|
3642
|
-
} else {
|
|
3643
|
-
scopeEntries.push(`${local}: ${moduleName}.${imported}`);
|
|
3644
|
-
}
|
|
3645
|
-
}
|
|
3646
|
-
}
|
|
3647
|
-
}
|
|
3648
|
-
function addModuleToScope(source, specifiers, moduleName, scopeEntries, usedNames) {
|
|
3649
|
-
const specArray = Array.from(specifiers);
|
|
3650
|
-
const hasDefault = specArray.some((spec) => spec.imported === "default");
|
|
3651
|
-
const hasNamespace = specArray.some((spec) => spec.imported === "*");
|
|
3652
|
-
const namedImports = specArray.filter(
|
|
3653
|
-
(spec) => spec.imported !== "default" && spec.imported !== "*"
|
|
3654
|
-
);
|
|
3655
|
-
if (hasNamespace) {
|
|
3656
|
-
scopeEntries.push(`...${moduleName}`);
|
|
3657
|
-
return;
|
|
3658
|
-
}
|
|
3659
|
-
const sanitizedSource = sanitizeSourceName(source);
|
|
3660
|
-
if (hasDefault) {
|
|
3661
|
-
scopeEntries.push(`"${sanitizedSource}__default": ${moduleName}.default`);
|
|
3662
|
-
}
|
|
3663
|
-
for (const { imported, local } of namedImports) {
|
|
3664
|
-
const sanitizedKey = `${sanitizedSource}__${imported}`;
|
|
3665
|
-
scopeEntries.push(`"${sanitizedKey}": ${moduleName}.${imported}`);
|
|
3666
|
-
if (!usedNames.has(local)) {
|
|
3667
|
-
scopeEntries.push(`${local}: ${moduleName}.${imported}`);
|
|
3668
|
-
usedNames.add(local);
|
|
3669
|
-
}
|
|
3670
|
-
}
|
|
3671
|
-
}
|
|
3672
3567
|
function extractPageId(filePath, routesDir) {
|
|
3673
3568
|
const relativePath = relative2(routesDir, filePath);
|
|
3674
3569
|
const pathParts = relativePath.split(sep);
|
|
@@ -3683,20 +3578,15 @@ function isCssAsset(filePath) {
|
|
|
3683
3578
|
}
|
|
3684
3579
|
function isDemoFile(filePath) {
|
|
3685
3580
|
try {
|
|
3686
|
-
return filePath.includes("/demos/") && filePath.endsWith(".tsx") &&
|
|
3687
|
-
readFileSync3(filePath, "utf-8").includes("export default");
|
|
3581
|
+
return filePath.includes("/demos/") && filePath.endsWith(".tsx") && !readFileSync3(filePath).includes("export default");
|
|
3688
3582
|
} catch (error) {
|
|
3689
3583
|
return false;
|
|
3690
3584
|
}
|
|
3691
3585
|
}
|
|
3692
|
-
function createEmptyScopeModule() {
|
|
3693
|
-
return "export const createDemoScope = () => ({})";
|
|
3694
|
-
}
|
|
3695
3586
|
|
|
3696
3587
|
// src/react-demo-plugin/react-demo-plugin.ts
|
|
3697
3588
|
import { transformerRenderIndentGuides as transformerRenderIndentGuides2 } from "@shikijs/transformers";
|
|
3698
3589
|
import chalk6 from "chalk";
|
|
3699
|
-
import { watch as watch2 } from "chokidar";
|
|
3700
3590
|
import { glob as glob3 } from "glob";
|
|
3701
3591
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
3702
3592
|
import { basename as basename2, resolve as resolve4 } from "node:path";
|
|
@@ -3704,27 +3594,12 @@ import { createHighlighter as createHighlighter2 } from "shiki";
|
|
|
3704
3594
|
import * as ts3 from "typescript";
|
|
3705
3595
|
import { quiCustomDarkTheme as quiCustomDarkTheme3 } from "@qualcomm-ui/mdx-common";
|
|
3706
3596
|
import { dedent } from "@qualcomm-ui/utils/dedent";
|
|
3707
|
-
import { debounce } from "@qualcomm-ui/utils/functions";
|
|
3708
|
-
var isDev2 = process.env.NODE_ENV === "development";
|
|
3709
3597
|
var highlighter2 = null;
|
|
3710
|
-
var initCount2 = 0;
|
|
3711
|
-
var hmrState = {
|
|
3712
|
-
windowScrollY: 0
|
|
3713
|
-
};
|
|
3714
3598
|
var demoRegistry2 = /* @__PURE__ */ new Map();
|
|
3715
|
-
var pageScopes = /* @__PURE__ */ new Map();
|
|
3716
3599
|
var pageFiles = /* @__PURE__ */ new Map();
|
|
3717
3600
|
var relativeImportDependents = /* @__PURE__ */ new Map();
|
|
3718
|
-
var hasWatcherInitialized2 = false;
|
|
3719
|
-
function logDev2(...args) {
|
|
3720
|
-
if (!hasWatcherInitialized2) {
|
|
3721
|
-
return;
|
|
3722
|
-
}
|
|
3723
|
-
console.log(...args);
|
|
3724
|
-
}
|
|
3725
3601
|
function reactDemoPlugin({
|
|
3726
3602
|
demoPattern = "src/routes/**/demos/*.tsx",
|
|
3727
|
-
lazyLoadDevModules = true,
|
|
3728
3603
|
routesDir = "src/routes",
|
|
3729
3604
|
theme = {
|
|
3730
3605
|
dark: quiCustomDarkTheme3,
|
|
@@ -3733,20 +3608,8 @@ function reactDemoPlugin({
|
|
|
3733
3608
|
transformers = [],
|
|
3734
3609
|
transformLine
|
|
3735
3610
|
} = {}) {
|
|
3736
|
-
let watcher = null;
|
|
3737
3611
|
return {
|
|
3738
|
-
async buildEnd() {
|
|
3739
|
-
if (watcher) {
|
|
3740
|
-
await watcher.close();
|
|
3741
|
-
watcher = null;
|
|
3742
|
-
hasWatcherInitialized2 = false;
|
|
3743
|
-
}
|
|
3744
|
-
},
|
|
3745
3612
|
async buildStart() {
|
|
3746
|
-
if (initCount2 === 0) {
|
|
3747
|
-
initCount2++;
|
|
3748
|
-
return;
|
|
3749
|
-
}
|
|
3750
3613
|
if (!highlighter2) {
|
|
3751
3614
|
try {
|
|
3752
3615
|
highlighter2 = await createHighlighter2({
|
|
@@ -3763,135 +3626,49 @@ function reactDemoPlugin({
|
|
|
3763
3626
|
);
|
|
3764
3627
|
}
|
|
3765
3628
|
}
|
|
3766
|
-
|
|
3767
|
-
await collectReactDemos();
|
|
3768
|
-
if (isDev2 && !hasWatcherInitialized2) {
|
|
3769
|
-
hasWatcherInitialized2 = true;
|
|
3770
|
-
await setupFileWatcher();
|
|
3771
|
-
} else if (isDev2) {
|
|
3772
|
-
logDev2(
|
|
3773
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} skipping watch: watcher already initialized by another instance`
|
|
3774
|
-
);
|
|
3775
|
-
}
|
|
3776
|
-
} catch (error) {
|
|
3777
|
-
if (watcher) {
|
|
3778
|
-
await watcher.close();
|
|
3779
|
-
watcher = null;
|
|
3780
|
-
hasWatcherInitialized2 = false;
|
|
3781
|
-
}
|
|
3782
|
-
throw error;
|
|
3783
|
-
}
|
|
3784
|
-
},
|
|
3785
|
-
configureServer(server) {
|
|
3786
|
-
const debouncedRestore = debounce((data) => {
|
|
3787
|
-
hmrState.windowScrollY = data.scrollY;
|
|
3788
|
-
}, 100);
|
|
3789
|
-
server.ws.on("custom:store-scroll-position", debouncedRestore);
|
|
3790
|
-
server.ws.on("custom:request-scroll-position", () => {
|
|
3791
|
-
server.ws.send({
|
|
3792
|
-
data: hmrState.windowScrollY,
|
|
3793
|
-
event: "custom:restore-scroll-position",
|
|
3794
|
-
type: "custom"
|
|
3795
|
-
});
|
|
3796
|
-
});
|
|
3629
|
+
await collectReactDemos();
|
|
3797
3630
|
},
|
|
3798
|
-
|
|
3631
|
+
enforce: "pre",
|
|
3632
|
+
async handleHotUpdate({ file, modules, server }) {
|
|
3799
3633
|
if (isCssAsset(file)) {
|
|
3800
|
-
return
|
|
3801
|
-
}
|
|
3802
|
-
if (!lazyLoadDevModules) {
|
|
3803
|
-
let shouldUpdate = false;
|
|
3804
|
-
if (isDemoFile(file)) {
|
|
3805
|
-
await handleFileAdditionOrUpdate(file, false);
|
|
3806
|
-
shouldUpdate = true;
|
|
3807
|
-
}
|
|
3808
|
-
const normalizedFile = resolve4(file);
|
|
3809
|
-
const dependents = relativeImportDependents.get(normalizedFile);
|
|
3810
|
-
if (dependents) {
|
|
3811
|
-
shouldUpdate = true;
|
|
3812
|
-
}
|
|
3813
|
-
if (shouldUpdate) {
|
|
3814
|
-
const autoModule = server.moduleGraph.getModuleById(
|
|
3815
|
-
VIRTUAL_MODULE_IDS.AUTO
|
|
3816
|
-
);
|
|
3817
|
-
if (autoModule) {
|
|
3818
|
-
server.moduleGraph.invalidateModule(autoModule);
|
|
3819
|
-
await server.reloadModule(autoModule);
|
|
3820
|
-
}
|
|
3821
|
-
return [];
|
|
3822
|
-
}
|
|
3634
|
+
return modules;
|
|
3823
3635
|
}
|
|
3824
3636
|
if (isDemoFile(file)) {
|
|
3825
|
-
|
|
3826
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} Processing change: ${chalk6.blueBright.bold(file)}`
|
|
3827
|
-
);
|
|
3828
|
-
const pageId = extractPageId(file, routesDir);
|
|
3829
|
-
const demoName = createDemoName(file);
|
|
3830
|
-
const wasNew = !demoRegistry2.has(demoName);
|
|
3831
|
-
await handleFileAdditionOrUpdate(file, false);
|
|
3832
|
-
const pageModule = server.moduleGraph.getModuleById(
|
|
3833
|
-
`${VIRTUAL_MODULE_IDS.PAGE_PREFIX}${pageId}`
|
|
3834
|
-
);
|
|
3835
|
-
if (pageModule) {
|
|
3836
|
-
console.debug(
|
|
3837
|
-
"invalidating:",
|
|
3838
|
-
`virtual:qui-demo-scope/page:${pageId}`
|
|
3839
|
-
);
|
|
3840
|
-
server.moduleGraph.invalidateModule(pageModule);
|
|
3841
|
-
await server.reloadModule(pageModule);
|
|
3842
|
-
}
|
|
3843
|
-
if (wasNew) {
|
|
3844
|
-
const autoModule = server.moduleGraph.getModuleById(
|
|
3845
|
-
VIRTUAL_MODULE_IDS.AUTO
|
|
3846
|
-
);
|
|
3847
|
-
if (autoModule) {
|
|
3848
|
-
server.moduleGraph.invalidateModule(autoModule);
|
|
3849
|
-
await server.reloadModule(autoModule);
|
|
3850
|
-
}
|
|
3851
|
-
}
|
|
3852
|
-
server.ws.send({
|
|
3853
|
-
data: demoRegistry2.get(createDemoName(file)),
|
|
3854
|
-
event: "qui-demo-update",
|
|
3855
|
-
type: "custom"
|
|
3856
|
-
});
|
|
3637
|
+
await handleDemoAdditionOrUpdate({ filePath: file });
|
|
3857
3638
|
} else {
|
|
3858
3639
|
const normalizedFile = resolve4(file);
|
|
3859
|
-
const
|
|
3860
|
-
if (
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3640
|
+
const dependentDemos = relativeImportDependents.get(normalizedFile);
|
|
3641
|
+
if (!dependentDemos?.size) {
|
|
3642
|
+
return modules;
|
|
3643
|
+
}
|
|
3644
|
+
for (const demoName of Array.from(dependentDemos)) {
|
|
3645
|
+
const demo = demoRegistry2.get(demoName);
|
|
3646
|
+
if (demo) {
|
|
3647
|
+
await handleDemoAdditionOrUpdate({
|
|
3648
|
+
filePath: demo.filePath
|
|
3866
3649
|
});
|
|
3867
3650
|
}
|
|
3868
3651
|
}
|
|
3869
3652
|
}
|
|
3870
|
-
|
|
3653
|
+
const autoModule = server.moduleGraph.getModuleById(
|
|
3654
|
+
VIRTUAL_MODULE_IDS.AUTO
|
|
3655
|
+
);
|
|
3656
|
+
if (autoModule) {
|
|
3657
|
+
server.moduleGraph.invalidateModule(autoModule);
|
|
3658
|
+
await server.reloadModule(autoModule);
|
|
3659
|
+
}
|
|
3660
|
+
return modules;
|
|
3871
3661
|
},
|
|
3872
3662
|
async load(id) {
|
|
3873
3663
|
if (id === VIRTUAL_MODULE_IDS.AUTO) {
|
|
3874
3664
|
return generateAutoScopeModule();
|
|
3875
3665
|
}
|
|
3876
|
-
if (id.startsWith(VIRTUAL_MODULE_IDS.PAGE_PREFIX)) {
|
|
3877
|
-
const pageId = id.replace(VIRTUAL_MODULE_IDS.PAGE_PREFIX, "");
|
|
3878
|
-
return pageScopes.get(pageId) || createEmptyScopeModule();
|
|
3879
|
-
}
|
|
3880
|
-
if (id === VIRTUAL_MODULE_IDS.CONFIG) {
|
|
3881
|
-
return generateConfigModule();
|
|
3882
|
-
}
|
|
3883
3666
|
},
|
|
3884
3667
|
name: "auto-demo-scope",
|
|
3885
3668
|
resolveId(id) {
|
|
3886
3669
|
if (id === "virtual:qui-demo-scope/auto") {
|
|
3887
3670
|
return VIRTUAL_MODULE_IDS.AUTO;
|
|
3888
3671
|
}
|
|
3889
|
-
if (id.startsWith("virtual:qui-demo-scope/page:")) {
|
|
3890
|
-
return `\0${id}`;
|
|
3891
|
-
}
|
|
3892
|
-
if (id === "virtual:qui-demo-scope/config") {
|
|
3893
|
-
return VIRTUAL_MODULE_IDS.CONFIG;
|
|
3894
|
-
}
|
|
3895
3672
|
},
|
|
3896
3673
|
writeBundle() {
|
|
3897
3674
|
console.log(
|
|
@@ -3899,43 +3676,9 @@ function reactDemoPlugin({
|
|
|
3899
3676
|
);
|
|
3900
3677
|
}
|
|
3901
3678
|
};
|
|
3902
|
-
async function
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
persistent: true
|
|
3906
|
-
});
|
|
3907
|
-
watcher.on("ready", () => {
|
|
3908
|
-
logDev2(
|
|
3909
|
-
`${chalk6.blue.bold(LOG_PREFIX2)} Registered ${chalk6.green(demoRegistry2.size)} demo files. Watching for file changes...`
|
|
3910
|
-
);
|
|
3911
|
-
});
|
|
3912
|
-
watcher.on("addDir", (dirPath) => {
|
|
3913
|
-
if (dirPath.endsWith("/demos")) {
|
|
3914
|
-
logDev2(
|
|
3915
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.greenBright("New demo directory detected:")} ${chalk6.blueBright.bold(dirPath)}`
|
|
3916
|
-
);
|
|
3917
|
-
}
|
|
3918
|
-
});
|
|
3919
|
-
watcher.on("unlink", async (filePath) => {
|
|
3920
|
-
if (isDemoFile(filePath)) {
|
|
3921
|
-
logDev2(
|
|
3922
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.redBright("Demo file deleted:")} ${chalk6.blueBright.bold(filePath)}`
|
|
3923
|
-
);
|
|
3924
|
-
await handleFileDeletion(filePath);
|
|
3925
|
-
}
|
|
3926
|
-
});
|
|
3927
|
-
watcher.on("add", async (filePath) => {
|
|
3928
|
-
if (isDemoFile(filePath)) {
|
|
3929
|
-
logDev2(
|
|
3930
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.greenBright("Demo file added:")} ${chalk6.blueBright.bold(filePath)}`
|
|
3931
|
-
);
|
|
3932
|
-
await handleFileAdditionOrUpdate(filePath, true).catch(() => {
|
|
3933
|
-
console.debug("failed to add file", filePath);
|
|
3934
|
-
});
|
|
3935
|
-
}
|
|
3936
|
-
});
|
|
3937
|
-
}
|
|
3938
|
-
async function handleFileAdditionOrUpdate(filePath, isAdd) {
|
|
3679
|
+
async function handleDemoAdditionOrUpdate({
|
|
3680
|
+
filePath
|
|
3681
|
+
}) {
|
|
3939
3682
|
const pageId = extractPageId(filePath, routesDir);
|
|
3940
3683
|
const demoName = createDemoName(filePath);
|
|
3941
3684
|
const existingFiles = pageFiles.get(pageId) ?? [];
|
|
@@ -3959,43 +3702,6 @@ function reactDemoPlugin({
|
|
|
3959
3702
|
}
|
|
3960
3703
|
}
|
|
3961
3704
|
}
|
|
3962
|
-
const previousScope = pageScopes.get(pageId);
|
|
3963
|
-
const allPageFiles = pageFiles.get(pageId);
|
|
3964
|
-
const scope = await generateScopeForPage(pageId, allPageFiles);
|
|
3965
|
-
pageScopes.set(pageId, scope);
|
|
3966
|
-
logDev2(
|
|
3967
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.greenBright(isAdd ? "Added demo:" : "Updated demo:")} ${chalk6.greenBright.bold(demoName)}`
|
|
3968
|
-
);
|
|
3969
|
-
return previousScope !== scope;
|
|
3970
|
-
}
|
|
3971
|
-
async function handleFileDeletion(deletedFile) {
|
|
3972
|
-
const demoName = createDemoName(deletedFile);
|
|
3973
|
-
const pageId = extractPageId(deletedFile, routesDir);
|
|
3974
|
-
demoRegistry2.delete(demoName);
|
|
3975
|
-
for (const [importPath, dependents] of relativeImportDependents.entries()) {
|
|
3976
|
-
dependents.delete(demoName);
|
|
3977
|
-
if (dependents.size === 0) {
|
|
3978
|
-
relativeImportDependents.delete(importPath);
|
|
3979
|
-
}
|
|
3980
|
-
}
|
|
3981
|
-
const files = pageFiles.get(pageId);
|
|
3982
|
-
if (files) {
|
|
3983
|
-
const updatedFiles = files.filter((f) => f !== deletedFile);
|
|
3984
|
-
if (updatedFiles.length === 0) {
|
|
3985
|
-
pageFiles.delete(pageId);
|
|
3986
|
-
pageScopes.delete(pageId);
|
|
3987
|
-
logDev2(
|
|
3988
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.redBright("Removed empty page:")} ${chalk6.blueBright.bold(pageId)}`
|
|
3989
|
-
);
|
|
3990
|
-
} else {
|
|
3991
|
-
pageFiles.set(pageId, updatedFiles);
|
|
3992
|
-
const scope = await generateScopeForPage(pageId, updatedFiles);
|
|
3993
|
-
pageScopes.set(pageId, scope);
|
|
3994
|
-
}
|
|
3995
|
-
}
|
|
3996
|
-
logDev2(
|
|
3997
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.redBright("Cleaned up deleted file:")} ${chalk6.blueBright.bold(deletedFile)}`
|
|
3998
|
-
);
|
|
3999
3705
|
}
|
|
4000
3706
|
function isPreviewLine(trimmedLine) {
|
|
4001
3707
|
return trimmedLine === "// preview" || /^\{\s*\/\*\s*preview\s*\*\/\s*\}$/.test(trimmedLine);
|
|
@@ -4056,10 +3762,7 @@ function reactDemoPlugin({
|
|
|
4056
3762
|
}
|
|
4057
3763
|
}
|
|
4058
3764
|
async function collectReactDemos() {
|
|
4059
|
-
if (demoRegistry2.size
|
|
4060
|
-
logDev2(
|
|
4061
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} Using cached ${chalk6.cyanBright.bold(demoRegistry2.size)} demos`
|
|
4062
|
-
);
|
|
3765
|
+
if (demoRegistry2.size) {
|
|
4063
3766
|
return;
|
|
4064
3767
|
}
|
|
4065
3768
|
const demoFiles = (await glob3(demoPattern)).filter(isDemoFile);
|
|
@@ -4086,243 +3789,15 @@ function reactDemoPlugin({
|
|
|
4086
3789
|
}
|
|
4087
3790
|
}
|
|
4088
3791
|
}
|
|
4089
|
-
for (const [pageId, files] of pageFiles.entries()) {
|
|
4090
|
-
const scope = await generateScopeForPage(pageId, files);
|
|
4091
|
-
pageScopes.set(pageId, scope);
|
|
4092
|
-
}
|
|
4093
|
-
}
|
|
4094
|
-
async function generateScopeForPage(pageId, files) {
|
|
4095
|
-
const demosData = [];
|
|
4096
|
-
const allThirdPartyImports = /* @__PURE__ */ new Map();
|
|
4097
|
-
const allRelativeImports = [];
|
|
4098
|
-
const demoImportData = /* @__PURE__ */ new Map();
|
|
4099
|
-
for (const file of files) {
|
|
4100
|
-
const demoName = createDemoName(file);
|
|
4101
|
-
const demo = demoRegistry2.get(demoName);
|
|
4102
|
-
if (!demo) {
|
|
4103
|
-
continue;
|
|
4104
|
-
}
|
|
4105
|
-
demosData.push({
|
|
4106
|
-
demoName,
|
|
4107
|
-
fileName: demo.fileName,
|
|
4108
|
-
imports: demo.imports,
|
|
4109
|
-
pageId: demo.pageId,
|
|
4110
|
-
sourceCode: demo.sourceCode
|
|
4111
|
-
});
|
|
4112
|
-
const { importMap, relativeImports } = await extractAllImports([file]);
|
|
4113
|
-
demoImportData.set(demoName, {
|
|
4114
|
-
relative: relativeImports.map((r) => ({
|
|
4115
|
-
resolvedPath: r.resolvedPath,
|
|
4116
|
-
specifiers: r.specifiers
|
|
4117
|
-
})),
|
|
4118
|
-
thirdParty: Array.from(importMap.entries()).map(([source, specs]) => ({
|
|
4119
|
-
source,
|
|
4120
|
-
specifiers: Array.from(specs)
|
|
4121
|
-
}))
|
|
4122
|
-
});
|
|
4123
|
-
for (const [source, specifiers] of importMap) {
|
|
4124
|
-
if (!allThirdPartyImports.has(source)) {
|
|
4125
|
-
allThirdPartyImports.set(source, /* @__PURE__ */ new Set());
|
|
4126
|
-
}
|
|
4127
|
-
for (const spec of specifiers) {
|
|
4128
|
-
allThirdPartyImports.get(source).add(spec);
|
|
4129
|
-
}
|
|
4130
|
-
}
|
|
4131
|
-
for (const relImport of relativeImports) {
|
|
4132
|
-
if (!allRelativeImports.some(
|
|
4133
|
-
(r) => r.resolvedPath === relImport.resolvedPath
|
|
4134
|
-
)) {
|
|
4135
|
-
allRelativeImports.push(relImport);
|
|
4136
|
-
}
|
|
4137
|
-
}
|
|
4138
|
-
}
|
|
4139
|
-
const pageImports = [];
|
|
4140
|
-
const reactScopeEntries = [];
|
|
4141
|
-
addReactImports(pageImports, reactScopeEntries);
|
|
4142
|
-
const moduleNames = /* @__PURE__ */ new Map();
|
|
4143
|
-
const moduleRegistryEntries = [];
|
|
4144
|
-
for (const [source] of Array.from(allThirdPartyImports.entries()).sort(
|
|
4145
|
-
([a], [b]) => a.localeCompare(b)
|
|
4146
|
-
)) {
|
|
4147
|
-
const moduleName = createUniqueModuleName(source);
|
|
4148
|
-
moduleNames.set(source, moduleName);
|
|
4149
|
-
pageImports.push(`import * as ${moduleName} from "${source}"`);
|
|
4150
|
-
moduleRegistryEntries.push(` "${source}": ${moduleName}`);
|
|
4151
|
-
}
|
|
4152
|
-
for (const { resolvedPath } of allRelativeImports) {
|
|
4153
|
-
const moduleName = createUniqueModuleName(resolvedPath);
|
|
4154
|
-
moduleNames.set(resolvedPath, moduleName);
|
|
4155
|
-
pageImports.push(`import * as ${moduleName} from "${resolvedPath}"`);
|
|
4156
|
-
moduleRegistryEntries.push(` "${resolvedPath}": ${moduleName}`);
|
|
4157
|
-
}
|
|
4158
|
-
const demosJson = JSON.stringify(demosData);
|
|
4159
|
-
const demoImportDataJson = JSON.stringify(
|
|
4160
|
-
Array.from(demoImportData.entries())
|
|
4161
|
-
);
|
|
4162
|
-
const reactScopeEntriesCode = reactScopeEntries.map((e) => ` ${e}`).join(",\n");
|
|
4163
|
-
return `// Auto-generated page scope for ${pageId}
|
|
4164
|
-
${pageImports.join("\n")}
|
|
4165
|
-
|
|
4166
|
-
const modules = {
|
|
4167
|
-
${moduleRegistryEntries.join(",\n")}
|
|
4168
|
-
}
|
|
4169
|
-
|
|
4170
|
-
const demosData = ${demosJson}
|
|
4171
|
-
const demoImportData = new Map(${demoImportDataJson})
|
|
4172
|
-
|
|
4173
|
-
const reactScope = {
|
|
4174
|
-
${reactScopeEntriesCode}
|
|
4175
|
-
}
|
|
4176
|
-
|
|
4177
|
-
const scopeCache = new Map()
|
|
4178
|
-
|
|
4179
|
-
function createScope(demoName) {
|
|
4180
|
-
if (scopeCache.has(demoName)) {
|
|
4181
|
-
return scopeCache.get(demoName)
|
|
4182
|
-
}
|
|
4183
|
-
|
|
4184
|
-
const imports = demoImportData.get(demoName)
|
|
4185
|
-
if (!imports) return {}
|
|
4186
|
-
|
|
4187
|
-
const scope = {...reactScope}
|
|
4188
|
-
|
|
4189
|
-
for (const {source, specifiers} of imports.thirdParty) {
|
|
4190
|
-
const mod = modules[source]
|
|
4191
|
-
if (!mod) continue
|
|
4192
|
-
|
|
4193
|
-
for (const {imported, local} of specifiers) {
|
|
4194
|
-
if (imported === 'default') {
|
|
4195
|
-
scope[local] = mod.default
|
|
4196
|
-
} else if (imported === '*') {
|
|
4197
|
-
Object.assign(scope, mod)
|
|
4198
|
-
} else {
|
|
4199
|
-
scope[local] = mod[imported]
|
|
4200
|
-
}
|
|
4201
|
-
}
|
|
4202
|
-
}
|
|
4203
|
-
|
|
4204
|
-
for (const {resolvedPath, specifiers} of imports.relative) {
|
|
4205
|
-
const mod = modules[resolvedPath]
|
|
4206
|
-
if (!mod) continue
|
|
4207
|
-
|
|
4208
|
-
for (const {imported, local} of specifiers) {
|
|
4209
|
-
if (imported === 'default') {
|
|
4210
|
-
scope[local] = mod.default
|
|
4211
|
-
} else if (imported === '*') {
|
|
4212
|
-
Object.assign(scope, mod)
|
|
4213
|
-
} else {
|
|
4214
|
-
scope[local] = mod[imported]
|
|
4215
|
-
}
|
|
4216
|
-
}
|
|
4217
|
-
}
|
|
4218
|
-
|
|
4219
|
-
scopeCache.set(demoName, scope)
|
|
4220
|
-
return scope
|
|
4221
|
-
}
|
|
4222
|
-
|
|
4223
|
-
export function getDemo(demoName) {
|
|
4224
|
-
const demo = demosData.find(d => d.demoName === demoName)
|
|
4225
|
-
if (!demo) return null
|
|
4226
|
-
return {
|
|
4227
|
-
...demo,
|
|
4228
|
-
scope: createScope(demoName)
|
|
4229
|
-
}
|
|
4230
|
-
}
|
|
4231
|
-
|
|
4232
|
-
export function getDemos() {
|
|
4233
|
-
return demosData.map(demo => ({
|
|
4234
|
-
...demo,
|
|
4235
|
-
scope: createScope(demo.demoName)
|
|
4236
|
-
}))
|
|
4237
|
-
}
|
|
4238
|
-
`;
|
|
4239
3792
|
}
|
|
4240
|
-
|
|
4241
|
-
if (isDev2 && lazyLoadDevModules) {
|
|
4242
|
-
return [
|
|
4243
|
-
"// Auto-generated demo scope resolver (DEV MODE - Lazy by Page)",
|
|
4244
|
-
generateLazyPageLoaders(),
|
|
4245
|
-
generateDemoToPageMap(),
|
|
4246
|
-
generateDevGetDemo()
|
|
4247
|
-
].join("\n\n");
|
|
4248
|
-
}
|
|
3793
|
+
function generateAutoScopeModule() {
|
|
4249
3794
|
const registryCode = generateDemoRegistry(demoRegistry2);
|
|
4250
3795
|
return [
|
|
4251
3796
|
"// Auto-generated demo scope resolver (PROD MODE)",
|
|
4252
|
-
generatePageImports(),
|
|
4253
|
-
generateScopeMap(),
|
|
4254
3797
|
registryCode,
|
|
4255
3798
|
generateExportedFunctions()
|
|
4256
3799
|
].join("\n\n");
|
|
4257
3800
|
}
|
|
4258
|
-
function generateConfigModule() {
|
|
4259
|
-
return dedent`
|
|
4260
|
-
export function getReactDemoConfig() {
|
|
4261
|
-
return {lazyLoadDevModules: ${lazyLoadDevModules}}
|
|
4262
|
-
}
|
|
4263
|
-
`;
|
|
4264
|
-
}
|
|
4265
|
-
function generateLazyPageLoaders() {
|
|
4266
|
-
const pageIds = Array.from(pageFiles.keys()).sort();
|
|
4267
|
-
if (pageIds.length === 0) {
|
|
4268
|
-
return "export const lazyDemoLoader = {}";
|
|
4269
|
-
}
|
|
4270
|
-
const entries = pageIds.map((pageId) => {
|
|
4271
|
-
return ` "${pageId}": () => import("virtual:qui-demo-scope/page:${pageId}")`;
|
|
4272
|
-
}).join(",\n");
|
|
4273
|
-
return `export const lazyDemoLoader = {
|
|
4274
|
-
${entries}
|
|
4275
|
-
}`;
|
|
4276
|
-
}
|
|
4277
|
-
function generateDemoToPageMap() {
|
|
4278
|
-
const entries = Array.from(demoRegistry2.entries()).map(([demoName, { pageId }]) => {
|
|
4279
|
-
return ` "${demoName}": "${pageId}"`;
|
|
4280
|
-
}).join(",\n");
|
|
4281
|
-
return `const demoToPageMap = {
|
|
4282
|
-
${entries}
|
|
4283
|
-
}`;
|
|
4284
|
-
}
|
|
4285
|
-
function generateDevGetDemo() {
|
|
4286
|
-
return dedent`
|
|
4287
|
-
export async function getDemo(demoName) {
|
|
4288
|
-
const pageId = demoToPageMap[demoName]
|
|
4289
|
-
if (!pageId) {
|
|
4290
|
-
return {
|
|
4291
|
-
fileName: "",
|
|
4292
|
-
imports: [],
|
|
4293
|
-
errorMessage: \`Demo "\${demoName}" not found.\`,
|
|
4294
|
-
scope: {},
|
|
4295
|
-
pageId: "",
|
|
4296
|
-
sourceCode: [],
|
|
4297
|
-
}
|
|
4298
|
-
}
|
|
4299
|
-
|
|
4300
|
-
const loader = lazyDemoLoader[pageId]
|
|
4301
|
-
if (!loader) {
|
|
4302
|
-
return {
|
|
4303
|
-
fileName: "",
|
|
4304
|
-
imports: [],
|
|
4305
|
-
errorMessage: \`Page "\${pageId}" not found.\`,
|
|
4306
|
-
scope: {},
|
|
4307
|
-
pageId: "",
|
|
4308
|
-
sourceCode: [],
|
|
4309
|
-
}
|
|
4310
|
-
}
|
|
4311
|
-
|
|
4312
|
-
const pageModule = await loader()
|
|
4313
|
-
const demo = pageModule.getDemo(demoName)
|
|
4314
|
-
|
|
4315
|
-
return demo || {
|
|
4316
|
-
fileName: "",
|
|
4317
|
-
imports: [],
|
|
4318
|
-
errorMessage: \`Demo "\${demoName}" not found in page.\`,
|
|
4319
|
-
scope: {},
|
|
4320
|
-
pageId: "",
|
|
4321
|
-
sourceCode: [],
|
|
4322
|
-
}
|
|
4323
|
-
}
|
|
4324
|
-
`;
|
|
4325
|
-
}
|
|
4326
3801
|
function extractHighlightedVariants(highlightedHtml) {
|
|
4327
3802
|
const preMatch = highlightedHtml.match(/^<pre[^>]*><code>/)?.[0] || "";
|
|
4328
3803
|
const postMatch = highlightedHtml.match(/<\/code><\/pre>$/)?.[0] || "";
|
|
@@ -4451,23 +3926,18 @@ ${entries}
|
|
|
4451
3926
|
withoutImports: importedCodeWithoutImports
|
|
4452
3927
|
}
|
|
4453
3928
|
});
|
|
4454
|
-
} catch
|
|
4455
|
-
logDev2(
|
|
4456
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.yellowBright("Failed to process relative import:")} ${chalk6.blueBright.bold(relativeImport.resolvedPath)}`
|
|
4457
|
-
);
|
|
3929
|
+
} catch {
|
|
4458
3930
|
}
|
|
4459
3931
|
}
|
|
4460
3932
|
}
|
|
4461
3933
|
return {
|
|
4462
3934
|
demoName: createDemoName(filePath),
|
|
4463
3935
|
fileName,
|
|
3936
|
+
filePath,
|
|
4464
3937
|
imports,
|
|
4465
3938
|
sourceCode
|
|
4466
3939
|
};
|
|
4467
|
-
} catch
|
|
4468
|
-
logDev2(
|
|
4469
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.yellowBright("Failed to parse")} ${chalk6.blueBright.bold(filePath)}. ${chalk6.yellowBright("Removing from registry")}`
|
|
4470
|
-
);
|
|
3940
|
+
} catch {
|
|
4471
3941
|
return null;
|
|
4472
3942
|
}
|
|
4473
3943
|
}
|
|
@@ -4514,36 +3984,12 @@ ${entries}
|
|
|
4514
3984
|
strippedCode: strippedCode.replace(/^\n+/, "")
|
|
4515
3985
|
};
|
|
4516
3986
|
} catch (error) {
|
|
4517
|
-
logDev2(
|
|
4518
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.redBright("Failed to strip imports from")} ${chalk6.blueBright.bold(fileName)}:`,
|
|
4519
|
-
error
|
|
4520
|
-
);
|
|
4521
3987
|
return {
|
|
4522
3988
|
imports: [],
|
|
4523
3989
|
strippedCode: code
|
|
4524
3990
|
};
|
|
4525
3991
|
}
|
|
4526
3992
|
}
|
|
4527
|
-
function generatePageImports() {
|
|
4528
|
-
const pageIds = Array.from(pageScopes.keys());
|
|
4529
|
-
return pageIds.map((pageId) => {
|
|
4530
|
-
const safeName = sanitizeIdentifier(pageId);
|
|
4531
|
-
return `import * as page_${safeName} from "virtual:qui-demo-scope/page:${pageId}"`;
|
|
4532
|
-
}).join("\n");
|
|
4533
|
-
}
|
|
4534
|
-
function generateScopeMap() {
|
|
4535
|
-
const pageIds = Array.from(pageScopes.keys());
|
|
4536
|
-
if (pageIds.length === 0) {
|
|
4537
|
-
return "const pageModules = {}";
|
|
4538
|
-
}
|
|
4539
|
-
const entries = pageIds.map((pageId) => {
|
|
4540
|
-
const safeName = sanitizeIdentifier(pageId);
|
|
4541
|
-
return ` "${pageId}": page_${safeName}`;
|
|
4542
|
-
}).join(",\n");
|
|
4543
|
-
return `const pageModules = {
|
|
4544
|
-
${entries}
|
|
4545
|
-
}`;
|
|
4546
|
-
}
|
|
4547
3993
|
function generateDemoRegistry(registry) {
|
|
4548
3994
|
const entries = Array.from(registry.entries()).map(([demoName, { fileName, imports, pageId, sourceCode }]) => {
|
|
4549
3995
|
return ` ["${demoName}", { fileName: "${fileName}", imports: ${JSON.stringify(imports)}, pageId: "${pageId}", sourceCode: ${JSON.stringify(sourceCode)}, demoName: "${demoName}" }]`;
|
|
@@ -4561,31 +4007,11 @@ ${entries}
|
|
|
4561
4007
|
fileName: "",
|
|
4562
4008
|
imports: [],
|
|
4563
4009
|
errorMessage: \`Demo "\${demoName}" not found.\`,
|
|
4564
|
-
scope: {},
|
|
4565
4010
|
pageId: "",
|
|
4566
4011
|
sourceCode: [],
|
|
4567
4012
|
}
|
|
4568
4013
|
}
|
|
4569
|
-
|
|
4570
|
-
const pageModule = pageModules[demo.pageId]
|
|
4571
|
-
if (!pageModule) {
|
|
4572
|
-
return {
|
|
4573
|
-
fileName: "",
|
|
4574
|
-
imports: [],
|
|
4575
|
-
errorMessage: \`Page module not found.\`,
|
|
4576
|
-
scope: {},
|
|
4577
|
-
pageId: demo.pageId,
|
|
4578
|
-
sourceCode: [],
|
|
4579
|
-
}
|
|
4580
|
-
}
|
|
4581
|
-
|
|
4582
|
-
return pageModule.getDemo(demoName) || {
|
|
4583
|
-
fileName: demo.fileName,
|
|
4584
|
-
imports: demo.imports,
|
|
4585
|
-
scope: {},
|
|
4586
|
-
pageId: demo.pageId,
|
|
4587
|
-
sourceCode: demo.sourceCode,
|
|
4588
|
-
}
|
|
4014
|
+
return demo
|
|
4589
4015
|
}
|
|
4590
4016
|
`;
|
|
4591
4017
|
}
|
|
@@ -4595,15 +4021,8 @@ export {
|
|
|
4595
4021
|
NODE_BUILTINS,
|
|
4596
4022
|
REACT_IMPORTS,
|
|
4597
4023
|
VIRTUAL_MODULE_IDS,
|
|
4598
|
-
addReactImports,
|
|
4599
|
-
addRelativeImportsNamespaced,
|
|
4600
|
-
addThirdPartyImports,
|
|
4601
|
-
addThirdPartyImportsNamespaced,
|
|
4602
4024
|
angularDemoPlugin,
|
|
4603
4025
|
createDemoName,
|
|
4604
|
-
createEmptyScopeModule,
|
|
4605
|
-
createUniqueModuleName,
|
|
4606
|
-
extractAllImports,
|
|
4607
4026
|
extractFileImports,
|
|
4608
4027
|
extractPageId,
|
|
4609
4028
|
getAlertIcon,
|
|
@@ -4625,8 +4044,6 @@ export {
|
|
|
4625
4044
|
remarkGfm2 as remarkGfm,
|
|
4626
4045
|
remarkMdxFrontmatter,
|
|
4627
4046
|
remarkSelfLinkHeadings,
|
|
4628
|
-
remarkSpoilers
|
|
4629
|
-
sanitizeIdentifier,
|
|
4630
|
-
sanitizeSourceName
|
|
4047
|
+
remarkSpoilers
|
|
4631
4048
|
};
|
|
4632
4049
|
//# sourceMappingURL=index.js.map
|