@mintlify/common 1.0.905 → 1.0.906
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.
|
@@ -62,6 +62,8 @@ export const resolveComponentWithContent = (tree, componentName, snippet, export
|
|
|
62
62
|
const replaceVariablesWithProps = (node, treeToInject, exportMap, snippetExportMap) => {
|
|
63
63
|
const variableNameMap = {};
|
|
64
64
|
const variablesMap = {};
|
|
65
|
+
const propValues = getSnippetPropValues(node);
|
|
66
|
+
replaceCodePlaceholdersWithProps(treeToInject, propValues);
|
|
65
67
|
visit(treeToInject, (node) => {
|
|
66
68
|
var _a;
|
|
67
69
|
if ((node.type === 'mdxTextExpression' || node.type === 'mdxFlowExpression') &&
|
|
@@ -107,6 +109,30 @@ const replaceVariablesWithProps = (node, treeToInject, exportMap, snippetExportM
|
|
|
107
109
|
snippetNodesToInject: treeToInject.children,
|
|
108
110
|
};
|
|
109
111
|
};
|
|
112
|
+
const getSnippetPropValues = (node) => {
|
|
113
|
+
const propValues = {};
|
|
114
|
+
node.attributes.forEach((attribute) => {
|
|
115
|
+
if (attribute.type !== 'mdxJsxAttribute' ||
|
|
116
|
+
!attribute.value ||
|
|
117
|
+
typeof attribute.value !== 'string')
|
|
118
|
+
return;
|
|
119
|
+
propValues[attribute.name] = attribute.value;
|
|
120
|
+
});
|
|
121
|
+
return propValues;
|
|
122
|
+
};
|
|
123
|
+
const replaceCodePlaceholdersWithProps = (tree, propValues) => {
|
|
124
|
+
visit(tree, (node) => {
|
|
125
|
+
if (node.type !== 'code' || typeof node.value !== 'string') {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
node.value = node.value.replace(/\{\s*([A-Za-z_$][\w$]*)\s*\}/g, (match, prop) => {
|
|
129
|
+
var _a;
|
|
130
|
+
if (!(prop in propValues))
|
|
131
|
+
return match;
|
|
132
|
+
return (_a = propValues[prop]) !== null && _a !== void 0 ? _a : match;
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
110
136
|
const reinsertExports = (content, exportMap, snippetExportMap) => {
|
|
111
137
|
const nodesToInject = [];
|
|
112
138
|
for (const [key, value] of Object.entries(snippetExportMap)) {
|