@qualcomm-ui/mdx-vite 2.1.3 → 2.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"angular-demo-plugin.d.ts","sourceRoot":"","sources":["../../src/angular-demo-plugin/angular-demo-plugin.ts"],"names":[],"mappings":"AAUA,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC/B,MAAM,OAAO,CAAA;AAEd,OAAO,KAAK,EAAC,MAAM,EAAgB,MAAM,MAAM,CAAA;AAU/C,MAAM,WAAW,wBAAwB;IACvC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC/B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE;QACN,IAAI,EACA,oBAAoB,GACpB,iBAAiB,GACjB,yBAAyB,GACzB,MAAM,CAAA;QACV,KAAK,EACD,oBAAoB,GACpB,iBAAiB,GACjB,yBAAyB,GACzB,MAAM,CAAA;KACX,CAAA;CACF;AAqCD,wBAAgB,iBAAiB,CAAC,EAChC,WAAwC,EACxC,WAAW,EACX,SAAwB,EACxB,KAGC,GACF,GAAE,wBAA6B,GAAG,MAAM,CA8pCxC"}
1
+ {"version":3,"file":"angular-demo-plugin.d.ts","sourceRoot":"","sources":["../../src/angular-demo-plugin/angular-demo-plugin.ts"],"names":[],"mappings":"AAQA,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC/B,MAAM,OAAO,CAAA;AAEd,OAAO,KAAK,EAAC,MAAM,EAAgB,MAAM,MAAM,CAAA;AAe/C,MAAM,WAAW,wBAAwB;IACvC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC/B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE;QACN,IAAI,EACA,oBAAoB,GACpB,iBAAiB,GACjB,yBAAyB,GACzB,MAAM,CAAA;QACV,KAAK,EACD,oBAAoB,GACpB,iBAAiB,GACjB,yBAAyB,GACzB,MAAM,CAAA;KACX,CAAA;CACF;AA8BD,wBAAgB,iBAAiB,CAAC,EAChC,WAAwC,EACxC,WAAW,EACX,SAAwB,EACxB,KAGC,GACF,GAAE,wBAA6B,GAAG,MAAM,CAo6BxC"}
package/dist/cli.js CHANGED
@@ -5526,6 +5526,9 @@ function remarkSelfLinkHeadings(baseUrl = "", options) {
5526
5526
  // src/docs-plugin/remark/remark-spoilers.ts
5527
5527
  import { visit as visit6 } from "unist-util-visit";
5528
5528
 
5529
+ // src/docs-plugin/shiki/shiki-transformer-preview-block.ts
5530
+ import { dedent } from "@qualcomm-ui/utils/dedent";
5531
+
5529
5532
  // src/open-web-ui-knowledge/load-config-from-env.ts
5530
5533
  import { existsSync } from "node:fs";
5531
5534
  import { join as join2, resolve as resolve4 } from "node:path";
@@ -5669,8 +5672,8 @@ function cleanDefaultValue(defaultValue) {
5669
5672
  }
5670
5673
  async function scanPages(routesFolder, verbose, excludePatterns = [], baseUrl) {
5671
5674
  const components = [];
5672
- function shouldExclude(dirPath) {
5673
- const dirName = basename(dirPath);
5675
+ function shouldExclude(fileOrDir) {
5676
+ const dirName = basename(fileOrDir);
5674
5677
  return excludePatterns.some((pattern) => {
5675
5678
  if (pattern.includes("*")) {
5676
5679
  const regex = new RegExp(`^${pattern.replace(/\*/g, ".*")}$`);
@@ -5687,7 +5690,9 @@ async function scanPages(routesFolder, verbose, excludePatterns = [], baseUrl) {
5687
5690
  return;
5688
5691
  }
5689
5692
  const entries = await readdir(dirPath, { withFileTypes: true });
5690
- const mdxFiles = entries.filter((f) => f.name.endsWith(".mdx")) ?? [];
5693
+ const mdxFiles = entries.filter(
5694
+ (f) => f.name.endsWith(".mdx") && !shouldExclude(f.name)
5695
+ ) ?? [];
5691
5696
  for (const mdxFile of mdxFiles) {
5692
5697
  const demosFolder = entries.find((f) => f.name === "demos");
5693
5698
  const demosFolderPath = demosFolder ? join3(dirPath, demosFolder.name) : void 0;
@@ -5698,6 +5703,7 @@ async function scanPages(routesFolder, verbose, excludePatterns = [], baseUrl) {
5698
5703
  const url = getPathnameFromPathSegments(segments);
5699
5704
  components.push({
5700
5705
  demosFolder: demosFolderPath,
5706
+ id: segments.join("-").trim(),
5701
5707
  mdxFile: join3(dirPath, mdxFile.name),
5702
5708
  name: segments.at(-1),
5703
5709
  path: dirPath,
@@ -5871,98 +5877,168 @@ var replaceNpmInstallTabs = () => {
5871
5877
  done();
5872
5878
  };
5873
5879
  };
5874
- async function processMdxContent(mdxContent, pageUrl, demosFolder, docProps, verbose) {
5875
- let processedContent = mdxContent;
5876
- const demoFiles = [];
5877
- const lines = processedContent.split("\n");
5878
- const titleLine = lines.findIndex((line) => line.startsWith("# "));
5879
- processedContent = titleLine >= 0 ? lines.slice(titleLine + 1).join("\n") : processedContent;
5880
- if (pageUrl) {
5881
- processedContent = processedContent.replace(
5882
- /\[([^\]]+)\]\(\.\/#([^)]+)\)/g,
5883
- (_, text, anchor) => `[${text}](${pageUrl}#${anchor})`
5884
- );
5885
- }
5886
- if (docProps) {
5887
- const typeDocRegex = /<TypeDocProps\s+name=["']([^"']+)["'](?:\s+partial)?[^>]*\/>/g;
5888
- processedContent = processedContent.replace(
5889
- typeDocRegex,
5890
- (match, propsName) => {
5891
- const isPartial = /\spartial(?:\s|\/|>)/.test(match);
5880
+ function replaceTypeDocProps(docProps, verbose) {
5881
+ return () => (tree, _file, done) => {
5882
+ visit7(
5883
+ tree,
5884
+ "mdxJsxFlowElement",
5885
+ (node, index, parent) => {
5886
+ if (node?.name !== "TypeDocProps") {
5887
+ return;
5888
+ }
5889
+ const nameAttr = node.attributes?.find(
5890
+ (attr) => attr.type === "mdxJsxAttribute" && attr.name === "name"
5891
+ );
5892
+ const isPartial = node.attributes?.some(
5893
+ (attr) => attr.type === "mdxJsxAttribute" && attr.name === "partial"
5894
+ );
5895
+ if (!docProps || !nameAttr) {
5896
+ if (parent && index !== void 0) {
5897
+ parent.children.splice(index, 1);
5898
+ }
5899
+ return;
5900
+ }
5901
+ const propsNames = extractNamesFromAttribute(nameAttr);
5902
+ if (propsNames.length === 0) {
5903
+ if (parent && index !== void 0) {
5904
+ parent.children.splice(index, 1);
5905
+ }
5906
+ return;
5907
+ }
5908
+ const propsName = propsNames[0];
5892
5909
  const componentProps = docProps.props[propsName];
5893
5910
  if (!componentProps) {
5894
5911
  if (verbose) {
5895
5912
  console.log(` TypeDocProps not found: ${propsName}`);
5896
5913
  }
5897
- return "";
5914
+ if (parent && index !== void 0) {
5915
+ parent.children.splice(index, 1);
5916
+ }
5917
+ return;
5898
5918
  }
5899
- const propsDoc = extractProps(componentProps, isPartial);
5919
+ const propsDoc = extractProps(componentProps, Boolean(isPartial));
5900
5920
  if (verbose) {
5901
5921
  console.log(
5902
5922
  ` Replaced TypeDocProps ${propsName} with API documentation`
5903
5923
  );
5904
5924
  }
5905
- return `**Component Props:**
5906
- \`\`\`json
5907
- ${JSON.stringify(propsDoc, null, 2)}
5908
- \`\`\`
5909
- `;
5925
+ Object.assign(node, {
5926
+ lang: "json",
5927
+ meta: null,
5928
+ type: "code",
5929
+ value: JSON.stringify(propsDoc, null, 2)
5930
+ });
5910
5931
  }
5911
5932
  );
5912
- } else {
5913
- processedContent = processedContent.replace(/<TypeDocProps\s+[^>]*\/>/g, "");
5914
- }
5915
- let demoRegex = /<(?:QdsDemo|CodeDemo|Demo)\s+[^>]*name="(\w+)"[^>]*\/>/g;
5916
- let demoMatches = Array.from(processedContent.matchAll(demoRegex));
5917
- if (!demoMatches.length) {
5918
- demoRegex = /<(?:QdsDemo|CodeDemo|Demo)\s+[^>]*node=\{Demo\.(\w+)\}[^>]*\/>/g;
5919
- demoMatches = Array.from(processedContent.matchAll(demoRegex));
5920
- }
5921
- const replacements = await Promise.all(
5922
- demoMatches.map(async (match) => {
5923
- const [fullMatch, demoName] = match;
5924
- const kebabName = kebabCase(demoName);
5925
- let filePath = `${kebabName}.tsx`;
5926
- if (!demosFolder) {
5927
- if (verbose) {
5928
- console.log(` No demos folder for ${demoName}`);
5929
- }
5930
- return { match: fullMatch, replacement: "" };
5931
- }
5932
- let demoFilePath = join3(demosFolder, filePath);
5933
- let isAngularDemo = false;
5934
- if (!await exists(demoFilePath)) {
5935
- demoFilePath = join3(demosFolder, `${kebabName}.ts`);
5936
- if (await exists(demoFilePath)) {
5937
- isAngularDemo = true;
5938
- filePath = `${kebabCase(demoName).replace("-component", ".component")}.ts`;
5939
- demoFilePath = join3(demosFolder, filePath);
5940
- } else {
5941
- console.log(` Demo not found ${demoName}`);
5942
- return { match: fullMatch, replacement: "" };
5933
+ done();
5934
+ };
5935
+ }
5936
+ function replaceDemos(demosFolder, verbose, demoFiles) {
5937
+ return () => async (tree) => {
5938
+ const promises = [];
5939
+ visit7(
5940
+ tree,
5941
+ "mdxJsxFlowElement",
5942
+ (node, index, parent) => {
5943
+ if (!node?.name || !["QdsDemo", "CodeDemo", "Demo"].includes(node.name)) {
5944
+ return;
5943
5945
  }
5944
- }
5945
- try {
5946
- const demoCode = await readFile(demoFilePath, "utf-8");
5947
- const cleanedCode = removePreviewLines(demoCode);
5948
- const codeBlock = `\`\`\`${isAngularDemo ? "angular-ts" : "tsx"}
5949
- ${cleanedCode}\`\`\``;
5950
- if (verbose) {
5951
- console.log(` Replaced demo ${demoName} with source code`);
5946
+ const nameAttr = node.attributes?.find(
5947
+ (attr) => attr.type === "mdxJsxAttribute" && attr.name === "name"
5948
+ );
5949
+ const nodeAttr = node.attributes?.find(
5950
+ (attr) => attr.type === "mdxJsxAttribute" && attr.name === "node"
5951
+ );
5952
+ let demoName;
5953
+ if (nameAttr && typeof nameAttr.value === "string") {
5954
+ demoName = nameAttr.value;
5955
+ } else if (nodeAttr?.value && typeof nodeAttr.value !== "string") {
5956
+ const estree = nodeAttr.value.data?.estree;
5957
+ if (estree?.body?.[0]?.type === "ExpressionStatement") {
5958
+ const expression = estree.body[0].expression;
5959
+ if (expression.type === "MemberExpression" && expression.object.type === "Identifier" && expression.object.name === "Demo" && expression.property.type === "Identifier") {
5960
+ demoName = expression.property.name;
5961
+ }
5962
+ }
5952
5963
  }
5953
- demoFiles.push(demoFilePath);
5954
- return { match: fullMatch, replacement: codeBlock };
5955
- } catch (error) {
5956
- if (verbose) {
5957
- console.log(` Error reading demo ${demoName}: ${error}`);
5964
+ if (!demoName) {
5965
+ if (parent && index !== void 0) {
5966
+ parent.children.splice(index, 1);
5967
+ }
5968
+ return;
5958
5969
  }
5959
- return { match: fullMatch, replacement: "" };
5970
+ promises.push(
5971
+ (async () => {
5972
+ const kebabName = kebabCase(demoName);
5973
+ let filePath = `${kebabName}.tsx`;
5974
+ if (!demosFolder) {
5975
+ if (verbose) {
5976
+ console.log(` No demos folder for ${demoName}`);
5977
+ }
5978
+ if (parent && index !== void 0) {
5979
+ parent.children.splice(index, 1);
5980
+ }
5981
+ return;
5982
+ }
5983
+ let demoFilePath = join3(demosFolder, filePath);
5984
+ let isAngularDemo = false;
5985
+ if (!await exists(demoFilePath)) {
5986
+ demoFilePath = join3(demosFolder, `${kebabName}.ts`);
5987
+ if (await exists(demoFilePath)) {
5988
+ isAngularDemo = true;
5989
+ filePath = `${kebabCase(demoName).replace("-component", ".component")}.ts`;
5990
+ demoFilePath = join3(demosFolder, filePath);
5991
+ } else {
5992
+ console.log(` Demo not found ${demoName}`);
5993
+ if (parent && index !== void 0) {
5994
+ parent.children.splice(index, 1);
5995
+ }
5996
+ return;
5997
+ }
5998
+ }
5999
+ try {
6000
+ const demoCode = await readFile(demoFilePath, "utf-8");
6001
+ const cleanedCode = removePreviewLines(demoCode);
6002
+ if (verbose) {
6003
+ console.log(` Replaced demo ${demoName} with source code`);
6004
+ }
6005
+ demoFiles.push(demoFilePath);
6006
+ Object.assign(node, {
6007
+ lang: isAngularDemo ? "angular-ts" : "tsx",
6008
+ meta: null,
6009
+ type: "code",
6010
+ value: cleanedCode
6011
+ });
6012
+ } catch (error) {
6013
+ if (verbose) {
6014
+ console.log(` Error reading demo ${demoName}: ${error}`);
6015
+ }
6016
+ if (parent && index !== void 0) {
6017
+ parent.children.splice(index, 1);
6018
+ }
6019
+ }
6020
+ })()
6021
+ );
5960
6022
  }
5961
- })
5962
- );
5963
- for (const { match, replacement } of replacements) {
5964
- processedContent = processedContent.replace(match, replacement);
6023
+ );
6024
+ await Promise.all(promises);
6025
+ };
6026
+ }
6027
+ async function processMdxContent(mdxContent, pageUrl, demosFolder, docProps, verbose) {
6028
+ const demoFiles = [];
6029
+ let processedContent = mdxContent;
6030
+ const lines = processedContent.split("\n");
6031
+ const titleLine = lines.findIndex((line) => line.startsWith("# "));
6032
+ processedContent = titleLine >= 0 ? lines.slice(titleLine + 1).join("\n") : processedContent;
6033
+ if (pageUrl) {
6034
+ processedContent = processedContent.replace(
6035
+ /\[([^\]]+)\]\(\.\/#([^)]+)\)/g,
6036
+ (_, text, anchor) => `[${text}](${pageUrl}#${anchor})`
6037
+ );
5965
6038
  }
6039
+ const processor = unified4().use(remarkParse4).use(remarkMdx3).use(replaceTypeDocProps(docProps, verbose)).use(replaceDemos(demosFolder, verbose, demoFiles)).use(remarkStringify3);
6040
+ const processed = await processor.process(processedContent);
6041
+ processedContent = String(processed);
5966
6042
  processedContent = processedContent.replace(/\n\s*\n\s*\n/g, "\n\n");
5967
6043
  return { content: processedContent, demoFiles };
5968
6044
  }
@@ -6083,7 +6159,7 @@ async function generatePerPageExports({
6083
6159
  }
6084
6160
  }
6085
6161
  }
6086
- const outfile = `${resolve5(outputPath)}/${kebabCase(page.name)}.md`;
6162
+ const outfile = `${resolve5(outputPath)}/${kebabCase(page.id || page.name)}.md`;
6087
6163
  await writeFile3(outfile, lines.join("\n"), "utf-8");
6088
6164
  const stats = await stat(outfile);
6089
6165
  totalSize += stats.size / 1024;
@@ -6178,7 +6254,7 @@ function addGenerateKnowledgeCommand() {
6178
6254
  "Project description for llms.txt"
6179
6255
  ).option("-v, --verbose", "Enable verbose logging", false).option(
6180
6256
  "--exclude <patterns...>",
6181
- "Exclude folder patterns (supports * wildcards)",
6257
+ "Exclude file or folder patterns (supports * wildcards)",
6182
6258
  []
6183
6259
  ).option("--base-url <url>", "Base URL for component documentation links").option("--metadata <pairs...>", "metadata key-value pairs").option("--clean", "Clean the output path before generating").option("--include-imports", "Include relative import source files", true).action(async (options) => {
6184
6260
  loadEnv();
@@ -6365,7 +6441,7 @@ import { glob as glob3 } from "glob";
6365
6441
  import { uniqBy } from "lodash-es";
6366
6442
  import { writeFile as writeFile5 } from "node:fs/promises";
6367
6443
  import { resolve as resolve8 } from "node:path";
6368
- import { dedent } from "@qualcomm-ui/utils/dedent";
6444
+ import { dedent as dedent2 } from "@qualcomm-ui/utils/dedent";
6369
6445
 
6370
6446
  // src/react-demo-plugin/demo-plugin-utils.ts
6371
6447
  import chalk4 from "chalk";
@@ -6409,7 +6485,7 @@ function generateLazyDemoLoader(demoPages) {
6409
6485
  return ` "${routePath}": () =>
6410
6486
  import("virtual:qui-demo-scope/page:${pageId}")`;
6411
6487
  }).sort().join(",\n");
6412
- return dedent`
6488
+ return dedent2`
6413
6489
  /* eslint-disable */
6414
6490
 
6415
6491
  // This file is generated automatically. Don't edit it directly.