@mintlify/common 1.0.923 → 1.0.925

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.
@@ -36,18 +36,51 @@ export const remarkComponentIds = (pageMetadata) => (tree) => {
36
36
  });
37
37
  const tabSlugs = new Map();
38
38
  const headingSlugs = new Map();
39
+ // Ids already claimed by an explicit `id` prop. Title-derived slugs must
40
+ // avoid these: the slug counter keys on the base slug, so it can otherwise
41
+ // regenerate a value (e.g. `tab-2`) that an explicit id already used. Seed
42
+ // up front so the result doesn't depend on document order.
43
+ const usedTabIds = new Set();
44
+ visit(tree, 'mdxJsxFlowElement', (node) => {
45
+ var _a;
46
+ if (node.name !== 'Tab')
47
+ return;
48
+ const explicitId = (_a = node.attributes.find((attr) => 'name' in attr && attr.name === 'id')) === null || _a === void 0 ? void 0 : _a.value;
49
+ // Expression-valued ids (e.g. id={someVar}) can't be statically resolved, so
50
+ // they aren't seeded here; collectDirectChildIds falls back to the
51
+ // title-derived slug for such tabs, which may diverge from the runtime value.
52
+ if (explicitId && typeof explicitId === 'string')
53
+ usedTabIds.add(explicitId);
54
+ });
39
55
  const precomputeTabSlugs = (node) => {
40
- var _a, _b, _c;
56
+ var _a, _b, _c, _d;
41
57
  if (node.type === 'mdxJsxFlowElement' && node.name === 'Tab') {
42
- const title = (_a = node.attributes.find((attr) => 'name' in attr && attr.name === 'title')) === null || _a === void 0 ? void 0 : _a.value;
43
- if (title && typeof title === 'string') {
44
- const slug = slugify(title, tabSlugifyFn);
45
- tabSlugs.set(node, slug);
58
+ // Respect an explicit `id` prop rather than overwriting it with the
59
+ // slugified title (same as Accordion/View below). This keeps the URL
60
+ // hash and any child-id references pointing at the author-provided id.
61
+ const explicitId = (_a = node.attributes.find((attr) => 'name' in attr && attr.name === 'id')) === null || _a === void 0 ? void 0 : _a.value;
62
+ if (explicitId && typeof explicitId === 'string') {
63
+ tabSlugs.set(node, explicitId);
64
+ }
65
+ else {
66
+ const title = (_b = node.attributes.find((attr) => 'name' in attr && attr.name === 'title')) === null || _b === void 0 ? void 0 : _b.value;
67
+ if (title && typeof title === 'string') {
68
+ // Re-slug (bumping the counter) past any id an explicit prop claimed.
69
+ // usedTabIds only guards against explicit ids; uniqueness among
70
+ // title-derived slugs is owned by tabSlugifyFn, which monotonically
71
+ // advances and never repeats a value, so the slots burned by this
72
+ // loop don't need to be tracked here.
73
+ let slug = slugify(title, tabSlugifyFn);
74
+ while (usedTabIds.has(slug))
75
+ slug = slugify(title, tabSlugifyFn);
76
+ usedTabIds.add(slug);
77
+ tabSlugs.set(node, slug);
78
+ }
46
79
  }
47
80
  }
48
81
  else if (node.type === 'mdxJsxFlowElement' &&
49
- (node.name === 'Heading' || ['h1', 'h2', 'h3', 'h4'].includes((_b = node.name) !== null && _b !== void 0 ? _b : ''))) {
50
- const id = (_c = node.attributes.find((attr) => 'name' in attr && attr.name === 'id')) === null || _c === void 0 ? void 0 : _c.value;
82
+ (node.name === 'Heading' || ['h1', 'h2', 'h3', 'h4'].includes((_c = node.name) !== null && _c !== void 0 ? _c : ''))) {
83
+ const id = (_d = node.attributes.find((attr) => 'name' in attr && attr.name === 'id')) === null || _d === void 0 ? void 0 : _d.value;
51
84
  if (id && typeof id === 'string')
52
85
  headingSlugs.set(node, id);
53
86
  }
@@ -62,7 +95,12 @@ export const remarkComponentIds = (pageMetadata) => (tree) => {
62
95
  const slug = tabSlugs.get(node);
63
96
  if (!slug)
64
97
  return;
65
- node.attributes.push(createMdxJsxAttribute('id', slug));
98
+ // `slug` already equals the explicit `id` when one was provided, so only
99
+ // add the attribute when the Tab doesn't already have one.
100
+ const hasId = node.attributes.some((attr) => 'name' in attr && attr.name === 'id');
101
+ if (!hasId) {
102
+ node.attributes.push(createMdxJsxAttribute('id', slug));
103
+ }
66
104
  const childTabIds = [];
67
105
  for (const child of node.children) {
68
106
  const childIds = collectDirectChildIds(child, 'Tab');