@qualcomm-ui/mdx-vite 2.1.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 +63 -35
- package/dist/cli.js.map +4 -4
- 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/mdx-utils.d.ts +3 -0
- package/dist/docs-plugin/internal/services/mdx-utils.d.ts.map +1 -0
- package/dist/index.js +34 -30
- package/dist/index.js.map +3 -3
- package/dist/open-web-ui-knowledge/generate-knowledge.d.ts.map +1 -1
- package/dist/tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3648,6 +3648,38 @@ import { visit } from "unist-util-visit";
|
|
|
3648
3648
|
import {
|
|
3649
3649
|
UniqueIdService
|
|
3650
3650
|
} from "@qualcomm-ui/mdx-common";
|
|
3651
|
+
|
|
3652
|
+
// src/docs-plugin/internal/services/mdx-utils.ts
|
|
3653
|
+
function extractNamesFromAttribute(attr) {
|
|
3654
|
+
if (!attr.value) {
|
|
3655
|
+
return [];
|
|
3656
|
+
}
|
|
3657
|
+
if (typeof attr.value === "string") {
|
|
3658
|
+
return [attr.value];
|
|
3659
|
+
}
|
|
3660
|
+
if (attr.value.type === "mdxJsxAttributeValueExpression") {
|
|
3661
|
+
const estree = attr.value.data?.estree;
|
|
3662
|
+
if (!estree?.body?.[0] || estree.body[0].type !== "ExpressionStatement") {
|
|
3663
|
+
return [];
|
|
3664
|
+
}
|
|
3665
|
+
const expression = estree.body[0].expression;
|
|
3666
|
+
if (expression.type === "ArrayExpression") {
|
|
3667
|
+
const names = [];
|
|
3668
|
+
for (const element of expression.elements) {
|
|
3669
|
+
if (element?.type === "Literal" && typeof element.value === "string") {
|
|
3670
|
+
names.push(element.value);
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
return names;
|
|
3674
|
+
}
|
|
3675
|
+
if (expression.type === "Literal" && typeof expression.value === "string") {
|
|
3676
|
+
return [expression.value];
|
|
3677
|
+
}
|
|
3678
|
+
}
|
|
3679
|
+
return [];
|
|
3680
|
+
}
|
|
3681
|
+
|
|
3682
|
+
// src/docs-plugin/internal/services/doc-props/doc-props-indexer.ts
|
|
3651
3683
|
function extractPickPropsRecord(node) {
|
|
3652
3684
|
if (node.name !== "unionWithPick" || !node.value || typeof node.value === "string") {
|
|
3653
3685
|
return null;
|
|
@@ -3696,34 +3728,6 @@ var DocPropsIndexer = class {
|
|
|
3696
3728
|
this.idService.reset();
|
|
3697
3729
|
this.docPropsEntries = [];
|
|
3698
3730
|
}
|
|
3699
|
-
extractNamesFromAttribute(attr) {
|
|
3700
|
-
if (!attr.value) {
|
|
3701
|
-
return [];
|
|
3702
|
-
}
|
|
3703
|
-
if (typeof attr.value === "string") {
|
|
3704
|
-
return [attr.value];
|
|
3705
|
-
}
|
|
3706
|
-
if (attr.value.type === "mdxJsxAttributeValueExpression") {
|
|
3707
|
-
const estree = attr.value.data?.estree;
|
|
3708
|
-
if (!estree?.body?.[0] || estree.body[0].type !== "ExpressionStatement") {
|
|
3709
|
-
return [];
|
|
3710
|
-
}
|
|
3711
|
-
const expression = estree.body[0].expression;
|
|
3712
|
-
if (expression.type === "ArrayExpression") {
|
|
3713
|
-
const names = [];
|
|
3714
|
-
for (const element of expression.elements) {
|
|
3715
|
-
if (element?.type === "Literal" && typeof element.value === "string") {
|
|
3716
|
-
names.push(element.value);
|
|
3717
|
-
}
|
|
3718
|
-
}
|
|
3719
|
-
return names;
|
|
3720
|
-
}
|
|
3721
|
-
if (expression.type === "Literal" && typeof expression.value === "string") {
|
|
3722
|
-
return [expression.value];
|
|
3723
|
-
}
|
|
3724
|
-
}
|
|
3725
|
-
return [];
|
|
3726
|
-
}
|
|
3727
3731
|
/**
|
|
3728
3732
|
* Finds all JSX `<TypeDocProps />` nodes on the current page and adds their names
|
|
3729
3733
|
* to an array. Once all nodes have been collected, we process them into
|
|
@@ -3739,9 +3743,9 @@ var DocPropsIndexer = class {
|
|
|
3739
3743
|
const omitFromAttr = node.attributes?.find(
|
|
3740
3744
|
(attr) => attr.name === "omitFrom"
|
|
3741
3745
|
);
|
|
3742
|
-
const omitFrom = omitFromAttr ?
|
|
3746
|
+
const omitFrom = omitFromAttr ? extractNamesFromAttribute(omitFromAttr) : void 0;
|
|
3743
3747
|
if (nameAttr) {
|
|
3744
|
-
const names =
|
|
3748
|
+
const names = extractNamesFromAttribute(nameAttr);
|
|
3745
3749
|
for (const name of names) {
|
|
3746
3750
|
this.docPropsEntries.push({ name, omitFrom });
|
|
3747
3751
|
if (name.endsWith("Props")) {
|
|
@@ -5301,10 +5305,12 @@ import {
|
|
|
5301
5305
|
} from "node:fs/promises";
|
|
5302
5306
|
import { basename, dirname, extname, join as join3, resolve as resolve5 } from "node:path";
|
|
5303
5307
|
import remarkFrontmatter3 from "remark-frontmatter";
|
|
5308
|
+
import remarkMdx3 from "remark-mdx";
|
|
5304
5309
|
import remarkParse4 from "remark-parse";
|
|
5305
5310
|
import remarkParseFrontmatter2 from "remark-parse-frontmatter";
|
|
5306
5311
|
import remarkStringify3 from "remark-stringify";
|
|
5307
5312
|
import { unified as unified4 } from "unified";
|
|
5313
|
+
import { visit as visit7 } from "unist-util-visit";
|
|
5308
5314
|
import { kebabCase } from "@qualcomm-ui/utils/change-case";
|
|
5309
5315
|
|
|
5310
5316
|
// src/docs-plugin/docs-plugin.ts
|
|
@@ -5681,9 +5687,8 @@ async function scanPages(routesFolder, verbose, excludePatterns = [], baseUrl) {
|
|
|
5681
5687
|
return;
|
|
5682
5688
|
}
|
|
5683
5689
|
const entries = await readdir(dirPath, { withFileTypes: true });
|
|
5684
|
-
const mdxFiles = entries.filter((f) => f.name.endsWith(".mdx"));
|
|
5685
|
-
|
|
5686
|
-
const mdxFile = mdxFiles[0];
|
|
5690
|
+
const mdxFiles = entries.filter((f) => f.name.endsWith(".mdx")) ?? [];
|
|
5691
|
+
for (const mdxFile of mdxFiles) {
|
|
5687
5692
|
const demosFolder = entries.find((f) => f.name === "demos");
|
|
5688
5693
|
const demosFolderPath = demosFolder ? join3(dirPath, demosFolder.name) : void 0;
|
|
5689
5694
|
const segments = getPathSegmentsFromFileName(
|
|
@@ -5847,6 +5852,25 @@ async function collectRelativeImports(filePath, visited = /* @__PURE__ */ new Se
|
|
|
5847
5852
|
}
|
|
5848
5853
|
return modules;
|
|
5849
5854
|
}
|
|
5855
|
+
var replaceNpmInstallTabs = () => {
|
|
5856
|
+
return (tree, _file, done) => {
|
|
5857
|
+
visit7(tree, "mdxJsxFlowElement", (node) => {
|
|
5858
|
+
if (node?.name === "NpmInstallTabs") {
|
|
5859
|
+
const packages = node.attributes?.find(
|
|
5860
|
+
(attr) => attr.type === "mdxJsxAttribute" && attr.name === "packages"
|
|
5861
|
+
);
|
|
5862
|
+
const packageNames = packages ? extractNamesFromAttribute(packages) : [];
|
|
5863
|
+
Object.assign(node, {
|
|
5864
|
+
lang: "shell",
|
|
5865
|
+
meta: null,
|
|
5866
|
+
type: "code",
|
|
5867
|
+
value: `npm install ${packageNames.join(" ")}`
|
|
5868
|
+
});
|
|
5869
|
+
}
|
|
5870
|
+
});
|
|
5871
|
+
done();
|
|
5872
|
+
};
|
|
5873
|
+
};
|
|
5850
5874
|
async function processMdxContent(mdxContent, pageUrl, demosFolder, docProps, verbose) {
|
|
5851
5875
|
let processedContent = mdxContent;
|
|
5852
5876
|
const demoFiles = [];
|
|
@@ -5948,7 +5972,7 @@ async function processComponent(component, docProps, verbose) {
|
|
|
5948
5972
|
if (verbose) {
|
|
5949
5973
|
console.log(`Processing page: ${component.name}`);
|
|
5950
5974
|
}
|
|
5951
|
-
const processor = unified4().use(remarkParse4).use(remarkFrontmatter3, ["yaml"]).use(remarkParseFrontmatter2).use(remarkSelfLinkHeadings(component.url)).use(remarkStringify3);
|
|
5975
|
+
const processor = unified4().use(remarkParse4).use(remarkMdx3).use(replaceNpmInstallTabs).use(remarkFrontmatter3, ["yaml"]).use(remarkParseFrontmatter2).use(remarkSelfLinkHeadings(component.url)).use(remarkStringify3);
|
|
5952
5976
|
const parsed = await processor.process(mdxContent);
|
|
5953
5977
|
const frontmatter = parsed.data?.frontmatter || {};
|
|
5954
5978
|
const { content: processedContent, demoFiles } = await processMdxContent(
|
|
@@ -5958,7 +5982,11 @@ async function processComponent(component, docProps, verbose) {
|
|
|
5958
5982
|
docProps,
|
|
5959
5983
|
verbose
|
|
5960
5984
|
);
|
|
5961
|
-
const
|
|
5985
|
+
const removeJsxProcessor = unified4().use(remarkParse4).use(remarkMdx3).use(remarkRemoveJsx).use(remarkStringify3);
|
|
5986
|
+
const removedJsx = String(
|
|
5987
|
+
await removeJsxProcessor.process(processedContent)
|
|
5988
|
+
);
|
|
5989
|
+
const contentWithoutFrontmatter = removedJsx.replace(
|
|
5962
5990
|
/^---[\s\S]*?---\n/,
|
|
5963
5991
|
""
|
|
5964
5992
|
);
|