@mintlify/common 1.0.485 → 1.0.486

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.
@@ -14,6 +14,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
14
14
  return {
15
15
  remarkPlugins: [
16
16
  [remarkMdxInjectSnippets, data.snippetTreeMap],
17
+ remarkComponentIds,
17
18
  [remarkExtractTableOfContents, mdxExtracts], // modifies tree so cannot be excluded
18
19
  [remarkExtractChangelogFilters, mdxExtracts],
19
20
  [remarkMdxExtractPanel, mdxExtracts],
@@ -21,7 +22,6 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
21
22
  remarkFrames,
22
23
  remarkRemoveImports,
23
24
  remarkMermaid,
24
- remarkComponentIds,
25
25
  ...remarkPlugins,
26
26
  remarkMdxRemoveUnknownJsx,
27
27
  ],
@@ -7,14 +7,13 @@ export const HEADING_LEVELS = [1, 2, 3, 4];
7
7
  export const remarkComponentIds = () => (tree) => {
8
8
  const slugifyFn = slugifyWithCounter();
9
9
  const tabSlugifyFn = slugifyWithCounter();
10
- visit(tree, 'heading', (node, _, parent) => {
10
+ visit(tree, 'heading', (node) => {
11
11
  if (HEADING_LEVELS.includes(node.depth)) {
12
12
  const title = getTableOfContentsTitle(node);
13
13
  const slug = slugify(title, slugifyFn);
14
14
  const mdxJsxAttributes = [
15
15
  createMdxJsxAttribute('level', node.depth),
16
16
  createMdxJsxAttribute('id', slug),
17
- createMdxJsxAttribute('isAtRootLevel', (parent === null || parent === void 0 ? void 0 : parent.type) === 'root'),
18
17
  ];
19
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
19
  node.attributes = mdxJsxAttributes;
@@ -1,4 +1,5 @@
1
1
  import { slugifyWithCounter } from '@sindresorhus/slugify';
2
+ import { visit } from 'unist-util-visit';
2
3
  import { slugify } from '../../../slugify.js';
3
4
  import { createMdxJsxAttribute, getTableOfContentsTitle } from '../../lib/remark-utils.js';
4
5
  import { HEADING_LEVELS } from './remarkComponentIds.js';
@@ -8,20 +9,41 @@ export const remarkExtractTableOfContents = (mdxExtracts) => {
8
9
  // already exists. No counter is added for the first occurence.
9
10
  const slugifyFn = slugifyWithCounter();
10
11
  return (tree) => {
11
- var _a, _b, _c, _d;
12
12
  const contents = [];
13
13
  let hasTopLayer = false;
14
- for (let nodeIndex = 0; nodeIndex < tree.children.length; nodeIndex++) {
15
- const node = tree.children[nodeIndex];
16
- if (!node)
17
- continue;
14
+ // the key is the node in unist
15
+ const tabContentMap = new Map();
16
+ visit(tree, (node) => {
17
+ if (node.type === 'mdxJsxFlowElement' && node.name === 'Tab') {
18
+ const idAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'id');
19
+ const titleAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'title');
20
+ let tabId;
21
+ if (idAttr && 'value' in idAttr && typeof idAttr.value === 'string') {
22
+ tabId = idAttr.value;
23
+ }
24
+ else if (titleAttr && 'value' in titleAttr && typeof titleAttr.value === 'string') {
25
+ tabId = slugify(titleAttr.value);
26
+ }
27
+ if (tabId) {
28
+ visit(node, (childNode) => {
29
+ tabContentMap.set(childNode, tabId);
30
+ });
31
+ }
32
+ }
33
+ });
34
+ visit(tree, (node) => {
35
+ var _a, _b, _c, _d;
36
+ const currentTabId = tabContentMap.get(node);
18
37
  const isValidHeading = node.type === 'heading' && HEADING_LEVELS.includes(node.depth);
19
38
  const isValidMdxHeading = node.type === 'mdxJsxFlowElement' && HEADING_NAMES.includes((_a = node.name) !== null && _a !== void 0 ? _a : '');
39
+ const isTransformedHeading = node.type === 'mdxJsxFlowElement' && node.name === 'Heading';
20
40
  const isValidUpdate = node.type === 'mdxJsxFlowElement' &&
21
41
  node.name === 'Update' &&
22
42
  node.attributes.some((attr) => 'name' in attr && attr.name === 'label');
23
- if (!isValidHeading && !isValidMdxHeading && !isValidUpdate) {
24
- continue;
43
+ const hasIdAttribute = node.type === 'mdxJsxFlowElement' &&
44
+ node.attributes.some((attr) => 'name' in attr && attr.name === 'id');
45
+ if (!isValidHeading && !isValidMdxHeading && !isTransformedHeading && !isValidUpdate) {
46
+ return;
25
47
  }
26
48
  let level;
27
49
  if ('name' in node && node.name === 'Update') {
@@ -32,21 +54,41 @@ export const remarkExtractTableOfContents = (mdxExtracts) => {
32
54
  else if ('depth' in node) {
33
55
  level = node.depth;
34
56
  }
57
+ else if ('name' in node && node.name === 'Heading') {
58
+ const levelAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'level');
59
+ if (levelAttr && 'value' in levelAttr && typeof levelAttr.value === 'number') {
60
+ level = levelAttr.value;
61
+ }
62
+ }
35
63
  else if ('name' in node && ((_b = node.name) === null || _b === void 0 ? void 0 : _b[1])) {
36
64
  const num = Number(node.name[1]);
37
65
  level = !isNaN(num) ? num : undefined;
38
66
  }
39
67
  const title = getTableOfContentsTitle(node);
40
- const slug = slugify(title, slugifyFn);
68
+ let slug;
69
+ if ('name' in node && node.name === 'Heading') {
70
+ const idAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'id');
71
+ if (idAttr && 'value' in idAttr && typeof idAttr.value === 'string') {
72
+ slug = idAttr.value;
73
+ }
74
+ else {
75
+ slug = slugify(title, slugifyFn);
76
+ }
77
+ }
78
+ else {
79
+ slug = slugify(title, slugifyFn);
80
+ }
41
81
  let mdxJsxAttributes;
42
82
  if ('name' in node && node.name === 'Update') {
43
83
  mdxJsxAttributes = [...node.attributes, createMdxJsxAttribute('id', slug)];
44
84
  }
45
- else if (level !== undefined) {
85
+ else if ('name' in node && node.name === 'Heading') {
86
+ mdxJsxAttributes = node.attributes;
87
+ }
88
+ else if (level !== undefined && !hasIdAttribute) {
46
89
  mdxJsxAttributes = [
47
90
  createMdxJsxAttribute('level', level),
48
91
  createMdxJsxAttribute('id', slug),
49
- createMdxJsxAttribute('isAtRootLevel', true),
50
92
  ];
51
93
  }
52
94
  // @ts-expect-error we're assigning over 'attributes' if it doesn't exist
@@ -58,7 +100,7 @@ export const remarkExtractTableOfContents = (mdxExtracts) => {
58
100
  const depth = node.depth;
59
101
  if (level !== undefined && Number(level) <= 2) {
60
102
  hasTopLayer = true;
61
- contents.push({ title, slug, depth, children: [] });
103
+ contents.push({ title, slug, depth, children: [], tabId: currentTabId });
62
104
  }
63
105
  else {
64
106
  // Account if there is no first layer
@@ -66,9 +108,9 @@ export const remarkExtractTableOfContents = (mdxExtracts) => {
66
108
  if (hasTopLayer) {
67
109
  arrToPushInto = (_d = (_c = contents.at(-1)) === null || _c === void 0 ? void 0 : _c.children) !== null && _d !== void 0 ? _d : [];
68
110
  }
69
- arrToPushInto.push({ title, slug, depth, children: [] });
111
+ arrToPushInto.push({ title, slug, depth, children: [], tabId: currentTabId });
70
112
  }
71
- }
113
+ });
72
114
  if (mdxExtracts) {
73
115
  mdxExtracts.tableOfContents = contents;
74
116
  }