@qualcomm-ui/mdx-vite 2.1.2 → 2.2.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.
@@ -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,CA2qCxC"}
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";
@@ -5698,6 +5701,7 @@ async function scanPages(routesFolder, verbose, excludePatterns = [], baseUrl) {
5698
5701
  const url = getPathnameFromPathSegments(segments);
5699
5702
  components.push({
5700
5703
  demosFolder: demosFolderPath,
5704
+ id: segments.join("-"),
5701
5705
  mdxFile: join3(dirPath, mdxFile.name),
5702
5706
  name: segments.at(-1),
5703
5707
  path: dirPath,
@@ -5871,98 +5875,168 @@ var replaceNpmInstallTabs = () => {
5871
5875
  done();
5872
5876
  };
5873
5877
  };
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);
5878
+ function replaceTypeDocProps(docProps, verbose) {
5879
+ return () => (tree, _file, done) => {
5880
+ visit7(
5881
+ tree,
5882
+ "mdxJsxFlowElement",
5883
+ (node, index, parent) => {
5884
+ if (node?.name !== "TypeDocProps") {
5885
+ return;
5886
+ }
5887
+ const nameAttr = node.attributes?.find(
5888
+ (attr) => attr.type === "mdxJsxAttribute" && attr.name === "name"
5889
+ );
5890
+ const isPartial = node.attributes?.some(
5891
+ (attr) => attr.type === "mdxJsxAttribute" && attr.name === "partial"
5892
+ );
5893
+ if (!docProps || !nameAttr) {
5894
+ if (parent && index !== void 0) {
5895
+ parent.children.splice(index, 1);
5896
+ }
5897
+ return;
5898
+ }
5899
+ const propsNames = extractNamesFromAttribute(nameAttr);
5900
+ if (propsNames.length === 0) {
5901
+ if (parent && index !== void 0) {
5902
+ parent.children.splice(index, 1);
5903
+ }
5904
+ return;
5905
+ }
5906
+ const propsName = propsNames[0];
5892
5907
  const componentProps = docProps.props[propsName];
5893
5908
  if (!componentProps) {
5894
5909
  if (verbose) {
5895
5910
  console.log(` TypeDocProps not found: ${propsName}`);
5896
5911
  }
5897
- return "";
5912
+ if (parent && index !== void 0) {
5913
+ parent.children.splice(index, 1);
5914
+ }
5915
+ return;
5898
5916
  }
5899
- const propsDoc = extractProps(componentProps, isPartial);
5917
+ const propsDoc = extractProps(componentProps, Boolean(isPartial));
5900
5918
  if (verbose) {
5901
5919
  console.log(
5902
5920
  ` Replaced TypeDocProps ${propsName} with API documentation`
5903
5921
  );
5904
5922
  }
5905
- return `**Component Props:**
5906
- \`\`\`json
5907
- ${JSON.stringify(propsDoc, null, 2)}
5908
- \`\`\`
5909
- `;
5923
+ Object.assign(node, {
5924
+ lang: "json",
5925
+ meta: null,
5926
+ type: "code",
5927
+ value: JSON.stringify(propsDoc, null, 2)
5928
+ });
5910
5929
  }
5911
5930
  );
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: "" };
5931
+ done();
5932
+ };
5933
+ }
5934
+ function replaceDemos(demosFolder, verbose, demoFiles) {
5935
+ return () => async (tree) => {
5936
+ const promises = [];
5937
+ visit7(
5938
+ tree,
5939
+ "mdxJsxFlowElement",
5940
+ (node, index, parent) => {
5941
+ if (!node?.name || !["QdsDemo", "CodeDemo", "Demo"].includes(node.name)) {
5942
+ return;
5943
5943
  }
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`);
5944
+ const nameAttr = node.attributes?.find(
5945
+ (attr) => attr.type === "mdxJsxAttribute" && attr.name === "name"
5946
+ );
5947
+ const nodeAttr = node.attributes?.find(
5948
+ (attr) => attr.type === "mdxJsxAttribute" && attr.name === "node"
5949
+ );
5950
+ let demoName;
5951
+ if (nameAttr && typeof nameAttr.value === "string") {
5952
+ demoName = nameAttr.value;
5953
+ } else if (nodeAttr?.value && typeof nodeAttr.value !== "string") {
5954
+ const estree = nodeAttr.value.data?.estree;
5955
+ if (estree?.body?.[0]?.type === "ExpressionStatement") {
5956
+ const expression = estree.body[0].expression;
5957
+ if (expression.type === "MemberExpression" && expression.object.type === "Identifier" && expression.object.name === "Demo" && expression.property.type === "Identifier") {
5958
+ demoName = expression.property.name;
5959
+ }
5960
+ }
5952
5961
  }
5953
- demoFiles.push(demoFilePath);
5954
- return { match: fullMatch, replacement: codeBlock };
5955
- } catch (error) {
5956
- if (verbose) {
5957
- console.log(` Error reading demo ${demoName}: ${error}`);
5962
+ if (!demoName) {
5963
+ if (parent && index !== void 0) {
5964
+ parent.children.splice(index, 1);
5965
+ }
5966
+ return;
5958
5967
  }
5959
- return { match: fullMatch, replacement: "" };
5968
+ promises.push(
5969
+ (async () => {
5970
+ const kebabName = kebabCase(demoName);
5971
+ let filePath = `${kebabName}.tsx`;
5972
+ if (!demosFolder) {
5973
+ if (verbose) {
5974
+ console.log(` No demos folder for ${demoName}`);
5975
+ }
5976
+ if (parent && index !== void 0) {
5977
+ parent.children.splice(index, 1);
5978
+ }
5979
+ return;
5980
+ }
5981
+ let demoFilePath = join3(demosFolder, filePath);
5982
+ let isAngularDemo = false;
5983
+ if (!await exists(demoFilePath)) {
5984
+ demoFilePath = join3(demosFolder, `${kebabName}.ts`);
5985
+ if (await exists(demoFilePath)) {
5986
+ isAngularDemo = true;
5987
+ filePath = `${kebabCase(demoName).replace("-component", ".component")}.ts`;
5988
+ demoFilePath = join3(demosFolder, filePath);
5989
+ } else {
5990
+ console.log(` Demo not found ${demoName}`);
5991
+ if (parent && index !== void 0) {
5992
+ parent.children.splice(index, 1);
5993
+ }
5994
+ return;
5995
+ }
5996
+ }
5997
+ try {
5998
+ const demoCode = await readFile(demoFilePath, "utf-8");
5999
+ const cleanedCode = removePreviewLines(demoCode);
6000
+ if (verbose) {
6001
+ console.log(` Replaced demo ${demoName} with source code`);
6002
+ }
6003
+ demoFiles.push(demoFilePath);
6004
+ Object.assign(node, {
6005
+ lang: isAngularDemo ? "angular-ts" : "tsx",
6006
+ meta: null,
6007
+ type: "code",
6008
+ value: cleanedCode
6009
+ });
6010
+ } catch (error) {
6011
+ if (verbose) {
6012
+ console.log(` Error reading demo ${demoName}: ${error}`);
6013
+ }
6014
+ if (parent && index !== void 0) {
6015
+ parent.children.splice(index, 1);
6016
+ }
6017
+ }
6018
+ })()
6019
+ );
5960
6020
  }
5961
- })
5962
- );
5963
- for (const { match, replacement } of replacements) {
5964
- processedContent = processedContent.replace(match, replacement);
6021
+ );
6022
+ await Promise.all(promises);
6023
+ };
6024
+ }
6025
+ async function processMdxContent(mdxContent, pageUrl, demosFolder, docProps, verbose) {
6026
+ const demoFiles = [];
6027
+ let processedContent = mdxContent;
6028
+ const lines = processedContent.split("\n");
6029
+ const titleLine = lines.findIndex((line) => line.startsWith("# "));
6030
+ processedContent = titleLine >= 0 ? lines.slice(titleLine + 1).join("\n") : processedContent;
6031
+ if (pageUrl) {
6032
+ processedContent = processedContent.replace(
6033
+ /\[([^\]]+)\]\(\.\/#([^)]+)\)/g,
6034
+ (_, text, anchor) => `[${text}](${pageUrl}#${anchor})`
6035
+ );
5965
6036
  }
6037
+ const processor = unified4().use(remarkParse4).use(remarkMdx3).use(replaceTypeDocProps(docProps, verbose)).use(replaceDemos(demosFolder, verbose, demoFiles)).use(remarkStringify3);
6038
+ const processed = await processor.process(processedContent);
6039
+ processedContent = String(processed);
5966
6040
  processedContent = processedContent.replace(/\n\s*\n\s*\n/g, "\n\n");
5967
6041
  return { content: processedContent, demoFiles };
5968
6042
  }
@@ -6083,7 +6157,7 @@ async function generatePerPageExports({
6083
6157
  }
6084
6158
  }
6085
6159
  }
6086
- const outfile = `${resolve5(outputPath)}/${kebabCase(page.name)}.md`;
6160
+ const outfile = `${resolve5(outputPath)}/${kebabCase(page.id)}.md`;
6087
6161
  await writeFile3(outfile, lines.join("\n"), "utf-8");
6088
6162
  const stats = await stat(outfile);
6089
6163
  totalSize += stats.size / 1024;
@@ -6365,7 +6439,7 @@ import { glob as glob3 } from "glob";
6365
6439
  import { uniqBy } from "lodash-es";
6366
6440
  import { writeFile as writeFile5 } from "node:fs/promises";
6367
6441
  import { resolve as resolve8 } from "node:path";
6368
- import { dedent } from "@qualcomm-ui/utils/dedent";
6442
+ import { dedent as dedent2 } from "@qualcomm-ui/utils/dedent";
6369
6443
 
6370
6444
  // src/react-demo-plugin/demo-plugin-utils.ts
6371
6445
  import chalk4 from "chalk";
@@ -6409,7 +6483,7 @@ function generateLazyDemoLoader(demoPages) {
6409
6483
  return ` "${routePath}": () =>
6410
6484
  import("virtual:qui-demo-scope/page:${pageId}")`;
6411
6485
  }).sort().join(",\n");
6412
- return dedent`
6486
+ return dedent2`
6413
6487
  /* eslint-disable */
6414
6488
 
6415
6489
  // This file is generated automatically. Don't edit it directly.