@mintlify/common 1.0.1050 → 1.0.1051
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/mdx/componentIds.js +1 -0
- package/dist/mdx/plugins/remark/remarkExtractTableOfContents.js +20 -1
- package/dist/mdx/plugins/remark/variation.d.ts +15 -0
- package/dist/mdx/plugins/remark/variation.js +48 -0
- package/dist/mdx/utils.js +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/mdx/TableOfContentsSectionType.d.ts +1 -0
- package/package.json +3 -3
package/dist/mdx/componentIds.js
CHANGED
|
@@ -3,6 +3,7 @@ import { safeCleanHeadingId, slugify } from '../../../slugify.js';
|
|
|
3
3
|
import { createMdxJsxAttribute, getTableOfContentsTitle } from '../../lib/remark-utils.js';
|
|
4
4
|
import { isMdxJsxFragment } from '../../utils.js';
|
|
5
5
|
import { AVOIDED_PAGE_MODES, HEADING_LEVELS } from './remarkComponentIds.js';
|
|
6
|
+
import { isVariationElement, resolveVariationIds } from './variation.js';
|
|
6
7
|
export const HEADING_NAMES = ['h1', 'h2', 'h3', 'h4'];
|
|
7
8
|
const COMPONENTS_TO_EXCLUDE_HEADINGS = [
|
|
8
9
|
'Accordion',
|
|
@@ -43,6 +44,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
|
|
|
43
44
|
// the key is the node in unist
|
|
44
45
|
const tabContentMap = new Map();
|
|
45
46
|
const viewContentMap = new Map();
|
|
47
|
+
const variationContentMap = new Map();
|
|
46
48
|
// Maps a Step node to the titleSize inherited from its parent <Steps>.
|
|
47
49
|
// At render time <Steps titleSize> is forwarded to each child <Step> that
|
|
48
50
|
// doesn't set its own titleSize, so the TOC must honor the same fallback.
|
|
@@ -99,6 +101,17 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
|
|
|
99
101
|
});
|
|
100
102
|
}
|
|
101
103
|
}
|
|
104
|
+
const variationNode = node;
|
|
105
|
+
if (isVariationElement(variationNode)) {
|
|
106
|
+
const resolution = resolveVariationIds(variationNode);
|
|
107
|
+
const variationIds = resolution.kind === 'valid' ? resolution.ids : [];
|
|
108
|
+
visit(node, (childNode) => {
|
|
109
|
+
const inheritedVariationIds = variationContentMap.get(childNode);
|
|
110
|
+
variationContentMap.set(childNode, inheritedVariationIds
|
|
111
|
+
? inheritedVariationIds.filter((id) => variationIds.includes(id))
|
|
112
|
+
: variationIds);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
102
115
|
});
|
|
103
116
|
visit(tree, (node) => {
|
|
104
117
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
@@ -106,6 +119,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
|
|
|
106
119
|
return;
|
|
107
120
|
const currentTabId = tabContentMap.get(node);
|
|
108
121
|
const currentViewId = viewContentMap.get(node);
|
|
122
|
+
const currentVariationIds = variationContentMap.get(node);
|
|
109
123
|
const isValidHeading = node.type === 'heading' && HEADING_LEVELS.includes(node.depth);
|
|
110
124
|
const isValidMdxHeading = node.type === 'mdxJsxFlowElement' && HEADING_NAMES.includes((_a = node.name) !== null && _a !== void 0 ? _a : '');
|
|
111
125
|
const isTransformedHeading = node.type === 'mdxJsxFlowElement' && node.name === 'Heading';
|
|
@@ -241,6 +255,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
|
|
|
241
255
|
children: [],
|
|
242
256
|
tabId: currentTabId,
|
|
243
257
|
viewId: currentViewId,
|
|
258
|
+
variationIds: currentVariationIds,
|
|
244
259
|
});
|
|
245
260
|
}
|
|
246
261
|
else {
|
|
@@ -250,7 +265,10 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
|
|
|
250
265
|
const lastTopLevel = contents.at(-1);
|
|
251
266
|
if (lastTopLevel &&
|
|
252
267
|
(lastTopLevel.tabId === undefined || lastTopLevel.tabId === currentTabId) &&
|
|
253
|
-
(lastTopLevel.viewId === undefined || lastTopLevel.viewId === currentViewId)
|
|
268
|
+
(lastTopLevel.viewId === undefined || lastTopLevel.viewId === currentViewId) &&
|
|
269
|
+
(lastTopLevel.variationIds === undefined ||
|
|
270
|
+
(currentVariationIds !== undefined &&
|
|
271
|
+
currentVariationIds.every((id) => { var _a; return (_a = lastTopLevel.variationIds) === null || _a === void 0 ? void 0 : _a.includes(id); })))) {
|
|
254
272
|
arrToPushInto = lastTopLevel.children;
|
|
255
273
|
}
|
|
256
274
|
}
|
|
@@ -261,6 +279,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
|
|
|
261
279
|
children: [],
|
|
262
280
|
tabId: currentTabId,
|
|
263
281
|
viewId: currentViewId,
|
|
282
|
+
variationIds: currentVariationIds,
|
|
264
283
|
});
|
|
265
284
|
}
|
|
266
285
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx-jsx';
|
|
2
|
+
export type VariationElement = MdxJsxFlowElement | MdxJsxTextElement;
|
|
3
|
+
export type VariationResolution = {
|
|
4
|
+
kind: 'valid';
|
|
5
|
+
ids: string[];
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'missing';
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'invalid';
|
|
10
|
+
};
|
|
11
|
+
export declare function isVariationElement(node: {
|
|
12
|
+
type: string;
|
|
13
|
+
name?: string | null;
|
|
14
|
+
}): node is VariationElement;
|
|
15
|
+
export declare function resolveVariationIds(node: VariationElement): VariationResolution;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export function isVariationElement(node) {
|
|
2
|
+
return ((node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement') &&
|
|
3
|
+
node.name === 'Variation');
|
|
4
|
+
}
|
|
5
|
+
export function resolveVariationIds(node) {
|
|
6
|
+
var _a, _b, _c, _d;
|
|
7
|
+
const attribute = node.attributes.find((candidate) => candidate.type === 'mdxJsxAttribute' && candidate.name === 'is');
|
|
8
|
+
if (!attribute)
|
|
9
|
+
return { kind: 'missing' };
|
|
10
|
+
if (typeof attribute.value === 'string') {
|
|
11
|
+
const id = attribute.value.trim();
|
|
12
|
+
return id ? { kind: 'valid', ids: [id] } : { kind: 'invalid' };
|
|
13
|
+
}
|
|
14
|
+
if (!attribute.value)
|
|
15
|
+
return { kind: 'invalid' };
|
|
16
|
+
const estree = (_a = attribute.value.data) === null || _a === void 0 ? void 0 : _a.estree;
|
|
17
|
+
const statement = estree === null || estree === void 0 ? void 0 : estree.body[0];
|
|
18
|
+
const expression = (statement === null || statement === void 0 ? void 0 : statement.type) === 'ExpressionStatement' ? statement.expression : undefined;
|
|
19
|
+
if ((expression === null || expression === void 0 ? void 0 : expression.type) === 'Literal' && typeof expression.value === 'string') {
|
|
20
|
+
const id = expression.value.trim();
|
|
21
|
+
return id ? { kind: 'valid', ids: [id] } : { kind: 'invalid' };
|
|
22
|
+
}
|
|
23
|
+
if ((expression === null || expression === void 0 ? void 0 : expression.type) === 'TemplateLiteral' && expression.expressions.length === 0) {
|
|
24
|
+
const id = (_c = (_b = expression.quasis[0]) === null || _b === void 0 ? void 0 : _b.value.cooked) === null || _c === void 0 ? void 0 : _c.trim();
|
|
25
|
+
return id ? { kind: 'valid', ids: [id] } : { kind: 'invalid' };
|
|
26
|
+
}
|
|
27
|
+
if ((expression === null || expression === void 0 ? void 0 : expression.type) === 'ArrayExpression') {
|
|
28
|
+
const ids = [];
|
|
29
|
+
for (const element of expression.elements) {
|
|
30
|
+
if ((element === null || element === void 0 ? void 0 : element.type) !== 'Literal' || typeof element.value !== 'string') {
|
|
31
|
+
return { kind: 'invalid' };
|
|
32
|
+
}
|
|
33
|
+
const id = element.value.trim();
|
|
34
|
+
if (!id)
|
|
35
|
+
return { kind: 'invalid' };
|
|
36
|
+
ids.push(id);
|
|
37
|
+
}
|
|
38
|
+
return ids.length > 0 ? { kind: 'valid', ids: [...new Set(ids)] } : { kind: 'invalid' };
|
|
39
|
+
}
|
|
40
|
+
if (estree)
|
|
41
|
+
return { kind: 'invalid' };
|
|
42
|
+
const raw = attribute.value.value.trim();
|
|
43
|
+
const quotedString = raw.match(/^(["'`])([\s\S]*)\1$/);
|
|
44
|
+
if ((_d = quotedString === null || quotedString === void 0 ? void 0 : quotedString[2]) === null || _d === void 0 ? void 0 : _d.trim()) {
|
|
45
|
+
return { kind: 'valid', ids: [quotedString[2].trim()] };
|
|
46
|
+
}
|
|
47
|
+
return { kind: 'invalid' };
|
|
48
|
+
}
|