@mintlify/common 1.0.688 → 1.0.689
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,3 +1,6 @@
|
|
|
1
|
+
import type { Program, Property } from 'estree-jsx';
|
|
1
2
|
import type { Root } from 'mdast';
|
|
2
3
|
export declare function isStringSafe(value: string): boolean;
|
|
3
|
-
export declare
|
|
4
|
+
export declare function filterStyleProperties(estree: Program): Program | null;
|
|
5
|
+
export declare function rebuildStyleValue(properties: Property[]): string;
|
|
6
|
+
export declare function remarkMdxRemoveJs(): (tree: Root) => void;
|
|
@@ -114,7 +114,10 @@ const DEFAULT_PROP_EXPRESSIONS = {
|
|
|
114
114
|
securitySchemes: { value: '{}', estree: objectEstree },
|
|
115
115
|
security: { value: '{}', estree: objectEstree },
|
|
116
116
|
authMethod: { value: '"bearer"', estree: createStringEstree('bearer') },
|
|
117
|
-
playground: {
|
|
117
|
+
playground: {
|
|
118
|
+
value: '"interactive"',
|
|
119
|
+
estree: createStringEstree('interactive'),
|
|
120
|
+
},
|
|
118
121
|
server: { value: '""', estree: createStringEstree('') },
|
|
119
122
|
metadata: { value: '{}', estree: objectEstree },
|
|
120
123
|
content: { value: '""', estree: createStringEstree('') },
|
|
@@ -174,41 +177,60 @@ export function isStringSafe(value) {
|
|
|
174
177
|
return false;
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
180
|
+
function isStylePropertyValueSafe(property) {
|
|
181
|
+
if (property.computed)
|
|
182
|
+
return false;
|
|
183
|
+
const value = property.value;
|
|
184
|
+
if (value.type === 'Literal')
|
|
185
|
+
return true;
|
|
186
|
+
if (value.type === 'UnaryExpression' &&
|
|
187
|
+
value.operator === '-' &&
|
|
188
|
+
value.argument.type === 'Literal' &&
|
|
189
|
+
typeof value.argument.value === 'number') {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
export function filterStyleProperties(estree) {
|
|
195
|
+
if (!estree.body.length)
|
|
196
|
+
return null;
|
|
197
|
+
const stmt = estree.body[0];
|
|
198
|
+
if ((stmt === null || stmt === void 0 ? void 0 : stmt.type) !== 'ExpressionStatement')
|
|
199
|
+
return null;
|
|
200
|
+
const expr = stmt.expression;
|
|
201
|
+
if (expr.type !== 'ObjectExpression')
|
|
202
|
+
return null;
|
|
203
|
+
const safeProperties = expr.properties.filter((prop) => prop.type === 'Property' && isStylePropertyValueSafe(prop));
|
|
204
|
+
if (safeProperties.length === 0)
|
|
205
|
+
return null;
|
|
206
|
+
const newExpr = Object.assign(Object.assign({}, expr), { properties: safeProperties });
|
|
207
|
+
return Object.assign(Object.assign({}, estree), { body: [
|
|
208
|
+
Object.assign(Object.assign({}, stmt), { expression: newExpr }),
|
|
209
|
+
] });
|
|
210
|
+
}
|
|
211
|
+
export function rebuildStyleValue(properties) {
|
|
212
|
+
const parts = properties.map((prop) => {
|
|
213
|
+
const key = prop.key.type === 'Identifier'
|
|
214
|
+
? prop.key.name
|
|
215
|
+
: prop.key.type === 'Literal'
|
|
216
|
+
? `'${String(prop.key.value).replace(/'/g, "\\'")}'`
|
|
217
|
+
: '';
|
|
218
|
+
let val = '';
|
|
219
|
+
if (prop.value.type === 'Literal') {
|
|
220
|
+
val =
|
|
221
|
+
typeof prop.value.value === 'string'
|
|
222
|
+
? `'${String(prop.value.value).replace(/'/g, "\\'")}'`
|
|
223
|
+
: String(prop.value.value);
|
|
224
|
+
}
|
|
225
|
+
else if (prop.value.type === 'UnaryExpression' &&
|
|
226
|
+
prop.value.operator === '-' &&
|
|
227
|
+
prop.value.argument.type === 'Literal') {
|
|
228
|
+
val = `-${prop.value.argument.value}`;
|
|
229
|
+
}
|
|
230
|
+
return `${key}: ${val}`;
|
|
210
231
|
});
|
|
211
|
-
}
|
|
232
|
+
return `{ ${parts.join(', ')} }`;
|
|
233
|
+
}
|
|
212
234
|
function isFunction(estree) {
|
|
213
235
|
if (!estree.body.length)
|
|
214
236
|
return false;
|
|
@@ -239,3 +261,55 @@ function isFunction(estree) {
|
|
|
239
261
|
});
|
|
240
262
|
return hasFunctionDeclaration;
|
|
241
263
|
}
|
|
264
|
+
export function remarkMdxRemoveJs() {
|
|
265
|
+
return (tree) => {
|
|
266
|
+
remove(tree, ['mdxTextExpression', 'mdxFlowExpression']);
|
|
267
|
+
remove(tree, (node) => {
|
|
268
|
+
var _a;
|
|
269
|
+
if (!isMdxJsEsm(node))
|
|
270
|
+
return false;
|
|
271
|
+
if (((_a = node.data) === null || _a === void 0 ? void 0 : _a.estree) && !isFunction(node.data.estree))
|
|
272
|
+
return false;
|
|
273
|
+
const value = node.value;
|
|
274
|
+
const containsReact = REACT_HOOKS.some((hook) => value.includes(hook) || value.includes('React.' + hook.toLowerCase()));
|
|
275
|
+
return containsReact;
|
|
276
|
+
});
|
|
277
|
+
visit(tree, (node) => {
|
|
278
|
+
if (!('attributes' in node))
|
|
279
|
+
return CONTINUE;
|
|
280
|
+
const newAttributes = node.attributes.map((attr) => {
|
|
281
|
+
var _a, _b, _c, _d, _e;
|
|
282
|
+
if (attr.type === 'mdxJsxAttribute' && !(attr.value instanceof Object))
|
|
283
|
+
return attr;
|
|
284
|
+
if (typeof attr.value === 'string' && isStringSafe(attr.value))
|
|
285
|
+
return attr;
|
|
286
|
+
if (attr.type === 'mdxJsxAttribute' && attr.value instanceof Object) {
|
|
287
|
+
if (isStringSafe(attr.value.value))
|
|
288
|
+
return attr;
|
|
289
|
+
if (attr.name === 'style' && ((_a = attr.value.data) === null || _a === void 0 ? void 0 : _a.estree)) {
|
|
290
|
+
const filteredEstree = filterStyleProperties(attr.value.data.estree);
|
|
291
|
+
if (filteredEstree) {
|
|
292
|
+
const stmt = filteredEstree.body[0];
|
|
293
|
+
if ((stmt === null || stmt === void 0 ? void 0 : stmt.type) === 'ExpressionStatement' &&
|
|
294
|
+
stmt.expression.type === 'ObjectExpression') {
|
|
295
|
+
attr.value.value = rebuildStyleValue(stmt.expression.properties);
|
|
296
|
+
attr.value.data.estree = filteredEstree;
|
|
297
|
+
return attr;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
if (Object.keys(DEFAULT_PROP_EXPRESSIONS).includes(attr.name)) {
|
|
303
|
+
attr.value.value = (_c = (_b = DEFAULT_PROP_EXPRESSIONS[attr.name]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : '{}';
|
|
304
|
+
attr.value.data = {
|
|
305
|
+
estree: (_e = (_d = DEFAULT_PROP_EXPRESSIONS[attr.name]) === null || _d === void 0 ? void 0 : _d.estree) !== null && _e !== void 0 ? _e : objectEstree,
|
|
306
|
+
};
|
|
307
|
+
return attr;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return undefined;
|
|
311
|
+
});
|
|
312
|
+
node.attributes = newAttributes.filter((attr) => attr !== undefined);
|
|
313
|
+
});
|
|
314
|
+
};
|
|
315
|
+
}
|