@qualcomm-ui/mdx-vite 2.0.0 → 2.1.1
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 +127 -55
- package/dist/cli.js.map +4 -4
- package/dist/docs-plugin/docs-plugin.d.ts.map +1 -1
- package/dist/docs-plugin/internal/search-indexer.d.ts +2 -2
- package/dist/docs-plugin/internal/search-indexer.d.ts.map +1 -1
- package/dist/docs-plugin/internal/services/doc-props/doc-props-indexer.d.ts +0 -1
- package/dist/docs-plugin/internal/services/doc-props/doc-props-indexer.d.ts.map +1 -1
- package/dist/docs-plugin/internal/services/markdown/markdown-file-reader.d.ts +1 -0
- package/dist/docs-plugin/internal/services/markdown/markdown-file-reader.d.ts.map +1 -1
- package/dist/docs-plugin/internal/services/markdown/markdown.types.d.ts +17 -1
- package/dist/docs-plugin/internal/services/markdown/markdown.types.d.ts.map +1 -1
- package/dist/docs-plugin/internal/services/mdx-utils.d.ts +3 -0
- package/dist/docs-plugin/internal/services/mdx-utils.d.ts.map +1 -0
- package/dist/docs-plugin/internal/services/nav-builder/nav-builder.d.ts.map +1 -1
- package/dist/docs-plugin/internal/services/nav-builder/page-map.d.ts.map +1 -1
- package/dist/docs-plugin/mdx-plugins.d.ts +2 -0
- package/dist/docs-plugin/mdx-plugins.d.ts.map +1 -1
- package/dist/docs-plugin/remark/remark-code-tabs.d.ts +16 -0
- package/dist/docs-plugin/remark/remark-code-tabs.d.ts.map +1 -1
- package/dist/docs-plugin/shiki/index.d.ts +3 -0
- package/dist/docs-plugin/shiki/index.d.ts.map +1 -0
- package/dist/docs-plugin/shiki/shiki-transformer-code-attribute.d.ts +20 -0
- package/dist/docs-plugin/shiki/shiki-transformer-code-attribute.d.ts.map +1 -0
- package/dist/docs-plugin/shiki/shiki-transformer-preview-block.d.ts +7 -0
- package/dist/docs-plugin/shiki/shiki-transformer-preview-block.d.ts.map +1 -0
- package/dist/docs-plugin/shiki/utils.d.ts +2 -0
- package/dist/docs-plugin/shiki/utils.d.ts.map +1 -0
- package/dist/index.js +188 -65
- package/dist/index.js.map +4 -4
- package/dist/open-web-ui-knowledge/generate-knowledge.d.ts.map +1 -1
- package/dist/react-demo-plugin/react-demo-plugin.d.ts.map +1 -1
- package/dist/tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1252,6 +1252,38 @@ import { visit } from "unist-util-visit";
|
|
|
1252
1252
|
import {
|
|
1253
1253
|
UniqueIdService
|
|
1254
1254
|
} from "@qualcomm-ui/mdx-common";
|
|
1255
|
+
|
|
1256
|
+
// src/docs-plugin/internal/services/mdx-utils.ts
|
|
1257
|
+
function extractNamesFromAttribute(attr) {
|
|
1258
|
+
if (!attr.value) {
|
|
1259
|
+
return [];
|
|
1260
|
+
}
|
|
1261
|
+
if (typeof attr.value === "string") {
|
|
1262
|
+
return [attr.value];
|
|
1263
|
+
}
|
|
1264
|
+
if (attr.value.type === "mdxJsxAttributeValueExpression") {
|
|
1265
|
+
const estree = attr.value.data?.estree;
|
|
1266
|
+
if (!estree?.body?.[0] || estree.body[0].type !== "ExpressionStatement") {
|
|
1267
|
+
return [];
|
|
1268
|
+
}
|
|
1269
|
+
const expression = estree.body[0].expression;
|
|
1270
|
+
if (expression.type === "ArrayExpression") {
|
|
1271
|
+
const names = [];
|
|
1272
|
+
for (const element of expression.elements) {
|
|
1273
|
+
if (element?.type === "Literal" && typeof element.value === "string") {
|
|
1274
|
+
names.push(element.value);
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
return names;
|
|
1278
|
+
}
|
|
1279
|
+
if (expression.type === "Literal" && typeof expression.value === "string") {
|
|
1280
|
+
return [expression.value];
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
return [];
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
// src/docs-plugin/internal/services/doc-props/doc-props-indexer.ts
|
|
1255
1287
|
function extractPickPropsRecord(node) {
|
|
1256
1288
|
if (node.name !== "unionWithPick" || !node.value || typeof node.value === "string") {
|
|
1257
1289
|
return null;
|
|
@@ -1300,34 +1332,6 @@ var DocPropsIndexer = class {
|
|
|
1300
1332
|
this.idService.reset();
|
|
1301
1333
|
this.docPropsEntries = [];
|
|
1302
1334
|
}
|
|
1303
|
-
extractNamesFromAttribute(attr) {
|
|
1304
|
-
if (!attr.value) {
|
|
1305
|
-
return [];
|
|
1306
|
-
}
|
|
1307
|
-
if (typeof attr.value === "string") {
|
|
1308
|
-
return [attr.value];
|
|
1309
|
-
}
|
|
1310
|
-
if (attr.value.type === "mdxJsxAttributeValueExpression") {
|
|
1311
|
-
const estree = attr.value.data?.estree;
|
|
1312
|
-
if (!estree?.body?.[0] || estree.body[0].type !== "ExpressionStatement") {
|
|
1313
|
-
return [];
|
|
1314
|
-
}
|
|
1315
|
-
const expression = estree.body[0].expression;
|
|
1316
|
-
if (expression.type === "ArrayExpression") {
|
|
1317
|
-
const names = [];
|
|
1318
|
-
for (const element of expression.elements) {
|
|
1319
|
-
if (element?.type === "Literal" && typeof element.value === "string") {
|
|
1320
|
-
names.push(element.value);
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
return names;
|
|
1324
|
-
}
|
|
1325
|
-
if (expression.type === "Literal" && typeof expression.value === "string") {
|
|
1326
|
-
return [expression.value];
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
return [];
|
|
1330
|
-
}
|
|
1331
1335
|
/**
|
|
1332
1336
|
* Finds all JSX `<TypeDocProps />` nodes on the current page and adds their names
|
|
1333
1337
|
* to an array. Once all nodes have been collected, we process them into
|
|
@@ -1343,9 +1347,9 @@ var DocPropsIndexer = class {
|
|
|
1343
1347
|
const omitFromAttr = node.attributes?.find(
|
|
1344
1348
|
(attr) => attr.name === "omitFrom"
|
|
1345
1349
|
);
|
|
1346
|
-
const omitFrom = omitFromAttr ?
|
|
1350
|
+
const omitFrom = omitFromAttr ? extractNamesFromAttribute(omitFromAttr) : void 0;
|
|
1347
1351
|
if (nameAttr) {
|
|
1348
|
-
const names =
|
|
1352
|
+
const names = extractNamesFromAttribute(nameAttr);
|
|
1349
1353
|
for (const name of names) {
|
|
1350
1354
|
this.docPropsEntries.push({ name, omitFrom });
|
|
1351
1355
|
if (name.endsWith("Props")) {
|
|
@@ -1486,12 +1490,15 @@ var MarkdownFileReader = class {
|
|
|
1486
1490
|
reset() {
|
|
1487
1491
|
this.cachedFileCount = 0;
|
|
1488
1492
|
}
|
|
1489
|
-
|
|
1493
|
+
readCache(filePath) {
|
|
1494
|
+
return this.mdxCache[filePath] || null;
|
|
1495
|
+
}
|
|
1496
|
+
checkCache(filePath, fileContents) {
|
|
1490
1497
|
if (!this.enabled) {
|
|
1491
1498
|
return;
|
|
1492
1499
|
}
|
|
1493
1500
|
const fileMd5 = this.hash(fileContents);
|
|
1494
|
-
const cached = this.mdxCache[
|
|
1501
|
+
const cached = this.mdxCache[filePath];
|
|
1495
1502
|
if (cached?.md5 !== fileMd5) {
|
|
1496
1503
|
return;
|
|
1497
1504
|
}
|
|
@@ -2012,9 +2019,9 @@ function getRouteMeta(pathSegments, metaJson) {
|
|
|
2012
2019
|
}
|
|
2013
2020
|
|
|
2014
2021
|
// src/docs-plugin/internal/services/nav-builder/nav-builder.ts
|
|
2015
|
-
import { capitalCase } from "change-case";
|
|
2016
2022
|
import { sortBy } from "lodash-es";
|
|
2017
2023
|
import { v4 as uuidv4 } from "uuid";
|
|
2024
|
+
import { capitalCase } from "@qualcomm-ui/utils/change-case";
|
|
2018
2025
|
var NavBuilder = class {
|
|
2019
2026
|
initialRoutes = [];
|
|
2020
2027
|
flatNavItems = [];
|
|
@@ -2299,8 +2306,8 @@ var NavBuilder = class {
|
|
|
2299
2306
|
};
|
|
2300
2307
|
|
|
2301
2308
|
// src/docs-plugin/internal/services/nav-builder/page-map.ts
|
|
2302
|
-
import { capitalCase as capitalCase2 } from "change-case";
|
|
2303
2309
|
import { join as join2 } from "node:path";
|
|
2310
|
+
import { capitalCase as capitalCase2 } from "@qualcomm-ui/utils/change-case";
|
|
2304
2311
|
function getPathnameFromPathSegments(segments) {
|
|
2305
2312
|
return `/${segments.join("/")}`;
|
|
2306
2313
|
}
|
|
@@ -2570,11 +2577,25 @@ var SearchIndexer = class {
|
|
|
2570
2577
|
* Parses an MDX file to extract the site data for the nav items, doc props,
|
|
2571
2578
|
* breadcrumbs, and search index.
|
|
2572
2579
|
*/
|
|
2573
|
-
compileMdxFile(
|
|
2574
|
-
const { cached, fileContents, frontmatter } = this.fileCache.readFile(
|
|
2580
|
+
compileMdxFile(filePath) {
|
|
2581
|
+
const { cached, fileContents, frontmatter } = this.fileCache.readFile(filePath);
|
|
2582
|
+
const metadata = {
|
|
2583
|
+
changed: {},
|
|
2584
|
+
filePath
|
|
2585
|
+
};
|
|
2586
|
+
if (!cached) {
|
|
2587
|
+
const previousData = this.fileCache.readCache(filePath);
|
|
2588
|
+
if (previousData) {
|
|
2589
|
+
const cachedFm = JSON.stringify(previousData.frontmatter);
|
|
2590
|
+
const currentFm = JSON.stringify(frontmatter);
|
|
2591
|
+
if (cachedFm !== currentFm) {
|
|
2592
|
+
metadata.changed.frontmatter = true;
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2575
2596
|
this.docPropsIndexer.reset();
|
|
2576
2597
|
this.markdownIndexer.reset();
|
|
2577
|
-
const defaultSection = this.getPageEntry(
|
|
2598
|
+
const defaultSection = this.getPageEntry(filePath, frontmatter);
|
|
2578
2599
|
if (!defaultSection.categories.length && defaultSection.title) {
|
|
2579
2600
|
defaultSection.categories = [defaultSection.title];
|
|
2580
2601
|
}
|
|
@@ -2589,9 +2610,9 @@ var SearchIndexer = class {
|
|
|
2589
2610
|
console.debug(
|
|
2590
2611
|
`${chalk3.yellowBright.bold(
|
|
2591
2612
|
"Failed to parse mdx page content."
|
|
2592
|
-
)} ${chalk3.blueBright.bold(
|
|
2613
|
+
)} ${chalk3.blueBright.bold(filePath)}`
|
|
2593
2614
|
);
|
|
2594
|
-
return [defaultSection];
|
|
2615
|
+
return { metadata, pageSections: [defaultSection] };
|
|
2595
2616
|
}
|
|
2596
2617
|
const { sections, toc } = indexedPage;
|
|
2597
2618
|
if (toc.length) {
|
|
@@ -2606,17 +2627,17 @@ var SearchIndexer = class {
|
|
|
2606
2627
|
if (docPropSections.length) {
|
|
2607
2628
|
this._pageDocProps[defaultSection.pathname] = docProps;
|
|
2608
2629
|
}
|
|
2609
|
-
this.fileCache.updateCache(
|
|
2630
|
+
this.fileCache.updateCache(filePath, fileContents, {
|
|
2610
2631
|
frontmatter,
|
|
2611
2632
|
page: indexedPage,
|
|
2612
2633
|
pageDocProps: docProps,
|
|
2613
2634
|
pageDocPropSections: docPropSections
|
|
2614
2635
|
});
|
|
2615
2636
|
if (frontmatter.hideFromSearch) {
|
|
2616
|
-
return [defaultSection];
|
|
2637
|
+
return { metadata, pageSections: [defaultSection] };
|
|
2617
2638
|
}
|
|
2618
2639
|
if (!sections.length && !docPropSections.length) {
|
|
2619
|
-
return [defaultSection];
|
|
2640
|
+
return { metadata, pageSections: [defaultSection] };
|
|
2620
2641
|
}
|
|
2621
2642
|
const sectionReturn = [
|
|
2622
2643
|
...this.formatSections(sections, defaultSection, false)
|
|
@@ -2626,7 +2647,7 @@ var SearchIndexer = class {
|
|
|
2626
2647
|
...this.formatSections(docPropSections, defaultSection, true)
|
|
2627
2648
|
);
|
|
2628
2649
|
}
|
|
2629
|
-
return sectionReturn;
|
|
2650
|
+
return { metadata, pageSections: sectionReturn };
|
|
2630
2651
|
}
|
|
2631
2652
|
formatSections(sections, { toc: _toc, ...defaultSection }, isDocProp) {
|
|
2632
2653
|
return sections.map((section, index) => {
|
|
@@ -2671,7 +2692,8 @@ var SearchIndexer = class {
|
|
|
2671
2692
|
this.config.routingStrategy
|
|
2672
2693
|
);
|
|
2673
2694
|
this._mdxFileCount = mdxFileGlob.length;
|
|
2674
|
-
const
|
|
2695
|
+
const compiledFiles = mdxFileGlob.map((file) => this.compileMdxFile(file));
|
|
2696
|
+
const mdxIndex = compiledFiles.map((fileData) => fileData.pageSections).flat();
|
|
2675
2697
|
filterFileGlob(
|
|
2676
2698
|
fileGlob,
|
|
2677
2699
|
"tsx",
|
|
@@ -2680,6 +2702,7 @@ var SearchIndexer = class {
|
|
|
2680
2702
|
).map((file) => this.compileTsxFile(file));
|
|
2681
2703
|
this._searchIndex.push(...mdxIndex.filter((entry) => !entry.hideFromSearch));
|
|
2682
2704
|
this.navBuilder.build();
|
|
2705
|
+
return compiledFiles;
|
|
2683
2706
|
}
|
|
2684
2707
|
};
|
|
2685
2708
|
|
|
@@ -2709,6 +2732,14 @@ var PluginState = class {
|
|
|
2709
2732
|
this.docPropsFilePath.lastIndexOf("/")
|
|
2710
2733
|
);
|
|
2711
2734
|
}
|
|
2735
|
+
get siteData() {
|
|
2736
|
+
return {
|
|
2737
|
+
navItems: state.indexer.navItems,
|
|
2738
|
+
pageDocProps: state.indexer.pageDocProps,
|
|
2739
|
+
pageMap: state.indexer.pageMap,
|
|
2740
|
+
searchIndex: state.indexer.searchIndex
|
|
2741
|
+
};
|
|
2742
|
+
}
|
|
2712
2743
|
resolveDocProps() {
|
|
2713
2744
|
if (!this.docPropsFilePath) {
|
|
2714
2745
|
return {};
|
|
@@ -2741,15 +2772,16 @@ var PluginState = class {
|
|
|
2741
2772
|
}
|
|
2742
2773
|
);
|
|
2743
2774
|
if (!files.length) {
|
|
2744
|
-
return;
|
|
2775
|
+
return [];
|
|
2745
2776
|
}
|
|
2746
2777
|
const startTime = Date.now();
|
|
2747
|
-
this.indexer.buildIndex(files, shouldLog);
|
|
2778
|
+
const compiledMdxFiles = this.indexer.buildIndex(files, shouldLog);
|
|
2748
2779
|
if (isDev && shouldLog) {
|
|
2749
2780
|
console.debug(
|
|
2750
2781
|
`${chalk4.magenta.bold(`@qualcomm-ui/mdx-vite/docs-plugin:`)} Compiled search index in: ${chalk4.blueBright.bold(prettyMilliseconds(Date.now() - startTime))}${state.indexer.cachedFileCount ? chalk4.greenBright.bold(` (${state.indexer.cachedFileCount}/${state.indexer.mdxFileCount} files cached)`) : ""}`
|
|
2751
2782
|
);
|
|
2752
2783
|
}
|
|
2784
|
+
return compiledMdxFiles;
|
|
2753
2785
|
}
|
|
2754
2786
|
/**
|
|
2755
2787
|
* When the user adds or removes mdx files, we re-index the site. This function
|
|
@@ -2793,7 +2825,13 @@ var PluginState = class {
|
|
|
2793
2825
|
const resolvedConfig = this.configLoader.loadConfig();
|
|
2794
2826
|
this.configFilePath = resolvedConfig.filePath;
|
|
2795
2827
|
this.createIndexer(resolvedConfig);
|
|
2796
|
-
this.handleChange(
|
|
2828
|
+
this.handleChange({
|
|
2829
|
+
onComplete: () => {
|
|
2830
|
+
this.servers.forEach(
|
|
2831
|
+
(server) => server.ws.send({ type: "full-reload" })
|
|
2832
|
+
);
|
|
2833
|
+
}
|
|
2834
|
+
});
|
|
2797
2835
|
});
|
|
2798
2836
|
}
|
|
2799
2837
|
};
|
|
@@ -2804,6 +2842,9 @@ function quiDocsPlugin(opts) {
|
|
|
2804
2842
|
const config = configLoader.loadConfig();
|
|
2805
2843
|
state.createIndexer(config);
|
|
2806
2844
|
return {
|
|
2845
|
+
apply(config2, env) {
|
|
2846
|
+
return env.mode === "development" && env.command === "serve" || env.mode === "production" && env.command === "build";
|
|
2847
|
+
},
|
|
2807
2848
|
buildStart: async () => {
|
|
2808
2849
|
state.buildIndex(state.buildCount > 0);
|
|
2809
2850
|
state.buildCount++;
|
|
@@ -2833,26 +2874,45 @@ function quiDocsPlugin(opts) {
|
|
|
2833
2874
|
});
|
|
2834
2875
|
state.servers.push(server);
|
|
2835
2876
|
},
|
|
2836
|
-
handleHotUpdate: async ({ file: updateFile,
|
|
2877
|
+
handleHotUpdate: async ({ file: updateFile, server }) => {
|
|
2837
2878
|
const file = fixPath(updateFile);
|
|
2838
2879
|
if ((!config.hotUpdateIgnore || !config.hotUpdateIgnore.test(file)) && // ignore watched files. We watch for these separately.
|
|
2839
2880
|
file !== state.configFilePath) {
|
|
2840
2881
|
if (state.docPropsDirectory && file.startsWith(state.docPropsFilePath)) {
|
|
2841
2882
|
return [];
|
|
2842
2883
|
}
|
|
2843
|
-
state.buildIndex(true);
|
|
2844
2884
|
if (updateFile.endsWith(".mdx")) {
|
|
2885
|
+
const mods = [];
|
|
2886
|
+
const files = state.buildIndex(true);
|
|
2887
|
+
const moduleByFile = server.moduleGraph.getModulesByFile(updateFile);
|
|
2888
|
+
if (!moduleByFile?.size) {
|
|
2889
|
+
console.debug("no module found for file, returning", updateFile);
|
|
2890
|
+
return [];
|
|
2891
|
+
}
|
|
2845
2892
|
const virtualModule = server.moduleGraph.getModuleById(VIRTUAL_MODULE_ID2);
|
|
2846
2893
|
if (virtualModule) {
|
|
2847
2894
|
server.moduleGraph.invalidateModule(virtualModule);
|
|
2895
|
+
server.ws.send({
|
|
2896
|
+
data: state.siteData,
|
|
2897
|
+
event: "qui-docs-plugin:refresh-site-data",
|
|
2898
|
+
type: "custom"
|
|
2899
|
+
});
|
|
2900
|
+
}
|
|
2901
|
+
if (files.some((file2) => file2.metadata.changed.frontmatter)) {
|
|
2902
|
+
console.debug(
|
|
2903
|
+
"Frontmatter changed, reloading plugin to reflect changes in the page configuration"
|
|
2904
|
+
);
|
|
2905
|
+
server.ws.send({ type: "full-reload" });
|
|
2906
|
+
return [];
|
|
2848
2907
|
}
|
|
2908
|
+
return mods;
|
|
2849
2909
|
}
|
|
2850
2910
|
}
|
|
2851
|
-
return
|
|
2911
|
+
return [];
|
|
2852
2912
|
},
|
|
2853
2913
|
load: (id) => {
|
|
2854
2914
|
if (id === VIRTUAL_MODULE_ID2) {
|
|
2855
|
-
return `export const siteData = ${JSON.stringify(
|
|
2915
|
+
return `export const siteData = ${JSON.stringify(state.siteData)}`;
|
|
2856
2916
|
}
|
|
2857
2917
|
return void 0;
|
|
2858
2918
|
},
|
|
@@ -2868,6 +2928,16 @@ function quiDocsPlugin(opts) {
|
|
|
2868
2928
|
|
|
2869
2929
|
// src/docs-plugin/mdx-plugins.ts
|
|
2870
2930
|
import rehypeShiki from "@shikijs/rehype";
|
|
2931
|
+
import {
|
|
2932
|
+
transformerNotationDiff,
|
|
2933
|
+
transformerNotationErrorLevel,
|
|
2934
|
+
transformerNotationFocus,
|
|
2935
|
+
transformerNotationHighlight,
|
|
2936
|
+
transformerNotationWordHighlight,
|
|
2937
|
+
transformerRemoveNotationEscape,
|
|
2938
|
+
transformerRenderIndentGuides as transformerRenderIndentGuides2
|
|
2939
|
+
} from "@shikijs/transformers";
|
|
2940
|
+
import { merge } from "lodash-es";
|
|
2871
2941
|
import { quiCustomDarkTheme as quiCustomDarkTheme2 } from "@qualcomm-ui/mdx-common";
|
|
2872
2942
|
|
|
2873
2943
|
// src/exports.ts
|
|
@@ -3218,12 +3288,43 @@ var remarkSpoilers = (options = {}) => {
|
|
|
3218
3288
|
};
|
|
3219
3289
|
};
|
|
3220
3290
|
|
|
3291
|
+
// src/docs-plugin/shiki/utils.ts
|
|
3292
|
+
function removeCodeAnnotations(code) {
|
|
3293
|
+
const annotationRegex = /\/\/\s*\[!code\s*(?:\S.*)?\]/;
|
|
3294
|
+
return code.split("\n").map((line) => {
|
|
3295
|
+
return line.replace(/(?:\/\/\s*)?\[!code \+\+\]/, "");
|
|
3296
|
+
}).filter((line) => !annotationRegex.test(line)).join("\n");
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
// src/docs-plugin/shiki/shiki-transformer-code-attribute.ts
|
|
3300
|
+
function transformerCodeAttribute(opts = {}) {
|
|
3301
|
+
return {
|
|
3302
|
+
enforce: "post",
|
|
3303
|
+
name: "shiki-transformer-code-attribute",
|
|
3304
|
+
pre(node) {
|
|
3305
|
+
const strippedSource = removeCodeAnnotations(this.source);
|
|
3306
|
+
node.properties[opts.attributeName ?? "data-code"] = opts.formatter?.(strippedSource) ?? strippedSource;
|
|
3307
|
+
}
|
|
3308
|
+
};
|
|
3309
|
+
}
|
|
3310
|
+
|
|
3221
3311
|
// src/docs-plugin/mdx-plugins.ts
|
|
3222
3312
|
var quiRehypePlugins = [rehypeSectionize, rehypeSlug];
|
|
3313
|
+
function getShikiTransformers() {
|
|
3314
|
+
return [
|
|
3315
|
+
transformerNotationDiff(),
|
|
3316
|
+
transformerNotationFocus(),
|
|
3317
|
+
transformerNotationHighlight(),
|
|
3318
|
+
transformerNotationWordHighlight(),
|
|
3319
|
+
transformerNotationErrorLevel(),
|
|
3320
|
+
transformerRenderIndentGuides2(),
|
|
3321
|
+
transformerRemoveNotationEscape()
|
|
3322
|
+
];
|
|
3323
|
+
}
|
|
3223
3324
|
function getRehypePlugins(options = {}) {
|
|
3224
3325
|
const config = new ConfigLoader(options).loadConfig();
|
|
3225
3326
|
return [
|
|
3226
|
-
rehypeMdxCodeProps,
|
|
3327
|
+
[rehypeMdxCodeProps, { enforce: "pre" }],
|
|
3227
3328
|
[
|
|
3228
3329
|
rehypeSlug,
|
|
3229
3330
|
{ allowedHeadings: config.headings }
|
|
@@ -3231,14 +3332,17 @@ function getRehypePlugins(options = {}) {
|
|
|
3231
3332
|
rehypeSectionize,
|
|
3232
3333
|
[
|
|
3233
3334
|
rehypeShiki,
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3335
|
+
merge(
|
|
3336
|
+
{
|
|
3337
|
+
defaultColor: "light-dark()",
|
|
3338
|
+
themes: {
|
|
3339
|
+
dark: quiCustomDarkTheme2,
|
|
3340
|
+
light: "github-light-high-contrast"
|
|
3341
|
+
},
|
|
3342
|
+
transformers: [...getShikiTransformers(), transformerCodeAttribute()]
|
|
3239
3343
|
},
|
|
3240
|
-
|
|
3241
|
-
|
|
3344
|
+
options.rehypeShikiOptions
|
|
3345
|
+
)
|
|
3242
3346
|
]
|
|
3243
3347
|
];
|
|
3244
3348
|
}
|
|
@@ -3585,7 +3689,6 @@ function isDemoFile(filePath) {
|
|
|
3585
3689
|
}
|
|
3586
3690
|
|
|
3587
3691
|
// src/react-demo-plugin/react-demo-plugin.ts
|
|
3588
|
-
import { transformerRenderIndentGuides as transformerRenderIndentGuides2 } from "@shikijs/transformers";
|
|
3589
3692
|
import chalk6 from "chalk";
|
|
3590
3693
|
import { glob as glob3 } from "glob";
|
|
3591
3694
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
@@ -3595,6 +3698,7 @@ import * as ts3 from "typescript";
|
|
|
3595
3698
|
import { quiCustomDarkTheme as quiCustomDarkTheme3 } from "@qualcomm-ui/mdx-common";
|
|
3596
3699
|
import { dedent } from "@qualcomm-ui/utils/dedent";
|
|
3597
3700
|
var highlighter2 = null;
|
|
3701
|
+
var initializingHighlighter = false;
|
|
3598
3702
|
var demoRegistry2 = /* @__PURE__ */ new Map();
|
|
3599
3703
|
var pageFiles = /* @__PURE__ */ new Map();
|
|
3600
3704
|
var relativeImportDependents = /* @__PURE__ */ new Map();
|
|
@@ -3609,12 +3713,18 @@ function reactDemoPlugin({
|
|
|
3609
3713
|
transformLine
|
|
3610
3714
|
} = {}) {
|
|
3611
3715
|
return {
|
|
3716
|
+
apply(config, env) {
|
|
3717
|
+
return env.mode === "development" && env.command === "serve" || env.mode === "production" && env.command === "build";
|
|
3718
|
+
},
|
|
3612
3719
|
async buildStart() {
|
|
3613
|
-
if (!highlighter2) {
|
|
3720
|
+
if (!highlighter2 && !initializingHighlighter) {
|
|
3721
|
+
initializingHighlighter = true;
|
|
3614
3722
|
try {
|
|
3615
3723
|
highlighter2 = await createHighlighter2({
|
|
3616
3724
|
langs: ["tsx", "typescript"],
|
|
3617
3725
|
themes: [theme.dark, theme.light]
|
|
3726
|
+
}).finally(() => {
|
|
3727
|
+
initializingHighlighter = false;
|
|
3618
3728
|
});
|
|
3619
3729
|
console.log(
|
|
3620
3730
|
`${chalk6.magenta.bold(LOG_PREFIX2)} Shiki highlighter initialized`
|
|
@@ -3628,18 +3738,20 @@ function reactDemoPlugin({
|
|
|
3628
3738
|
}
|
|
3629
3739
|
await collectReactDemos();
|
|
3630
3740
|
},
|
|
3631
|
-
enforce: "pre",
|
|
3632
3741
|
async handleHotUpdate({ file, modules, server }) {
|
|
3633
3742
|
if (isCssAsset(file)) {
|
|
3634
3743
|
return modules;
|
|
3635
3744
|
}
|
|
3745
|
+
if (file.endsWith(".mdx")) {
|
|
3746
|
+
return [];
|
|
3747
|
+
}
|
|
3636
3748
|
if (isDemoFile(file)) {
|
|
3637
3749
|
await handleDemoAdditionOrUpdate({ filePath: file });
|
|
3638
3750
|
} else {
|
|
3639
3751
|
const normalizedFile = resolve4(file);
|
|
3640
3752
|
const dependentDemos = relativeImportDependents.get(normalizedFile);
|
|
3641
3753
|
if (!dependentDemos?.size) {
|
|
3642
|
-
return
|
|
3754
|
+
return [];
|
|
3643
3755
|
}
|
|
3644
3756
|
for (const demoName of Array.from(dependentDemos)) {
|
|
3645
3757
|
const demo = demoRegistry2.get(demoName);
|
|
@@ -3657,7 +3769,7 @@ function reactDemoPlugin({
|
|
|
3657
3769
|
server.moduleGraph.invalidateModule(autoModule);
|
|
3658
3770
|
await server.reloadModule(autoModule);
|
|
3659
3771
|
}
|
|
3660
|
-
return
|
|
3772
|
+
return [];
|
|
3661
3773
|
},
|
|
3662
3774
|
async load(id) {
|
|
3663
3775
|
if (id === VIRTUAL_MODULE_IDS.AUTO) {
|
|
@@ -3751,7 +3863,17 @@ function reactDemoPlugin({
|
|
|
3751
3863
|
dark: theme.dark,
|
|
3752
3864
|
light: theme.light
|
|
3753
3865
|
},
|
|
3754
|
-
transformers: [
|
|
3866
|
+
transformers: [
|
|
3867
|
+
...getShikiTransformers(),
|
|
3868
|
+
{
|
|
3869
|
+
enforce: "post",
|
|
3870
|
+
name: "shiki-transformer-trim",
|
|
3871
|
+
preprocess(code2) {
|
|
3872
|
+
return code2.trim();
|
|
3873
|
+
}
|
|
3874
|
+
},
|
|
3875
|
+
...transformers
|
|
3876
|
+
]
|
|
3755
3877
|
});
|
|
3756
3878
|
} catch (error) {
|
|
3757
3879
|
console.warn(
|
|
@@ -4029,6 +4151,7 @@ export {
|
|
|
4029
4151
|
getRehypePlugins,
|
|
4030
4152
|
getRemarkPlugins,
|
|
4031
4153
|
getScriptKind,
|
|
4154
|
+
getShikiTransformers,
|
|
4032
4155
|
isCssAsset,
|
|
4033
4156
|
isDemoFile,
|
|
4034
4157
|
quiDocsPlugin,
|