@mintlify/common 1.0.1119 → 1.0.1121

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.
@@ -122,21 +122,61 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
122
122
  });
123
123
  }
124
124
  });
125
+ const pushEntry = (entry, level) => {
126
+ if (level !== undefined && Number(level) <= 2) {
127
+ hasTopLayer = true;
128
+ contents.push(entry);
129
+ return;
130
+ }
131
+ // Account if there is no first layer
132
+ let arrToPushInto = contents;
133
+ if (hasTopLayer) {
134
+ const lastTopLevel = contents.at(-1);
135
+ if (lastTopLevel &&
136
+ (lastTopLevel.tabId === undefined || lastTopLevel.tabId === entry.tabId) &&
137
+ (lastTopLevel.viewId === undefined || lastTopLevel.viewId === entry.viewId) &&
138
+ (lastTopLevel.variationIds === undefined ||
139
+ (entry.variationIds !== undefined &&
140
+ entry.variationIds.every((id) => { var _a; return (_a = lastTopLevel.variationIds) === null || _a === void 0 ? void 0 : _a.includes(id); })))) {
141
+ arrToPushInto = lastTopLevel.children;
142
+ }
143
+ }
144
+ arrToPushInto.push(entry);
145
+ };
125
146
  visit(tree, (node) => {
126
- var _a, _b, _c, _d, _e, _f;
147
+ var _a, _b, _c, _d, _e, _f, _g;
127
148
  if (excludedNodes.has(node))
128
149
  return;
129
150
  const currentTabId = tabContentMap.get(node);
130
151
  const currentViewId = viewContentMap.get(node);
131
152
  const currentVariationIds = variationContentMap.get(node);
153
+ if (node.type === 'mdxFlowExpression' || node.type === 'mdxTextExpression') {
154
+ const fragmentHeadings = (_a = node.data) === null || _a === void 0 ? void 0 : _a.tableOfContents;
155
+ if (!(fragmentHeadings === null || fragmentHeadings === void 0 ? void 0 : fragmentHeadings.length))
156
+ return;
157
+ // headings compiled inside an <MDX> fragment (see remarkMdxExpandExpressions); merged in
158
+ // document order, slugs registered so later page headings do not reuse them
159
+ const register = (entries) => {
160
+ var _a;
161
+ for (const entry of entries) {
162
+ seenSlugs.set(entry.slug, ((_a = seenSlugs.get(entry.slug)) !== null && _a !== void 0 ? _a : 0) + 1);
163
+ register(entry.children);
164
+ }
165
+ };
166
+ register(fragmentHeadings);
167
+ for (const heading of fragmentHeadings) {
168
+ pushEntry(Object.assign(Object.assign({}, heading), { tabId: currentTabId, viewId: currentViewId, variationIds: currentVariationIds }), heading.depth);
169
+ }
170
+ return;
171
+ }
132
172
  const isValidHeading = node.type === 'heading' && HEADING_LEVELS.includes(node.depth);
133
- const isValidMdxHeading = node.type === 'mdxJsxFlowElement' && HEADING_NAMES.includes((_a = node.name) !== null && _a !== void 0 ? _a : '');
173
+ const isValidMdxHeading = node.type === 'mdxJsxFlowElement' && HEADING_NAMES.includes((_b = node.name) !== null && _b !== void 0 ? _b : '');
134
174
  const isTransformedHeading = node.type === 'mdxJsxFlowElement' && node.name === 'Heading';
135
175
  const isValidUpdate = node.type === 'mdxJsxFlowElement' &&
136
176
  node.name === 'Update' &&
137
177
  node.attributes.some((attr) => 'name' in attr && attr.name === 'label');
138
178
  const stepTitleSize = node.type === 'mdxJsxFlowElement' && node.name === 'Step'
139
- ? ((_b = getStringAttribute(node.attributes, 'titleSize')) !== null && _b !== void 0 ? _b : inheritedStepTitleSizeMap.get(node))
179
+ ? ((_c = getStringAttribute(node.attributes, 'titleSize')) !== null && _c !== void 0 ? _c : inheritedStepTitleSizeMap.get(node))
140
180
  : undefined;
141
181
  const hasNoAnchor = node.type === 'mdxJsxFlowElement' &&
142
182
  node.attributes.some((attr) => 'name' in attr &&
@@ -145,7 +185,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
145
185
  attr.value === 'true' ||
146
186
  (typeof attr.value === 'object' && attr.value.value === 'true')));
147
187
  const stepTitle = node.type === 'mdxJsxFlowElement' && node.name === 'Step'
148
- ? getTitleMarkdownText(node, (_c = getStringAttribute(node.attributes, 'title')) !== null && _c !== void 0 ? _c : '')
188
+ ? getTitleMarkdownText(node, (_d = getStringAttribute(node.attributes, 'title')) !== null && _d !== void 0 ? _d : '')
149
189
  : undefined;
150
190
  const isValidStep = node.type === 'mdxJsxFlowElement' &&
151
191
  node.name === 'Step' &&
@@ -154,7 +194,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
154
194
  (stepTitle === null || stepTitle === void 0 ? void 0 : stepTitle.trim()) !== '';
155
195
  const hasIdAttribute = node.type === 'mdxJsxFlowElement' &&
156
196
  node.attributes.some((attr) => 'name' in attr && attr.name === 'id');
157
- const isAvoidedPageMode = AVOIDED_PAGE_MODES.includes((_d = pageMetadata === null || pageMetadata === void 0 ? void 0 : pageMetadata.mode) !== null && _d !== void 0 ? _d : '');
197
+ const isAvoidedPageMode = AVOIDED_PAGE_MODES.includes((_e = pageMetadata === null || pageMetadata === void 0 ? void 0 : pageMetadata.mode) !== null && _e !== void 0 ? _e : '');
158
198
  if (!isValidHeading &&
159
199
  !isValidMdxHeading &&
160
200
  !isTransformedHeading &&
@@ -172,7 +212,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
172
212
  }
173
213
  else if ('name' in node && node.name === 'Step') {
174
214
  const titleSizeToLevel = { h2: 2, h3: 3, h4: 4 };
175
- level = (_e = titleSizeToLevel[stepTitleSize !== null && stepTitleSize !== void 0 ? stepTitleSize : '']) !== null && _e !== void 0 ? _e : 3;
215
+ level = (_f = titleSizeToLevel[stepTitleSize !== null && stepTitleSize !== void 0 ? stepTitleSize : '']) !== null && _f !== void 0 ? _f : 3;
176
216
  // @ts-expect-error we're assigning to depth despite the node not containing depth in the type
177
217
  node.depth = level;
178
218
  }
@@ -185,7 +225,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
185
225
  level = levelAttr.value;
186
226
  }
187
227
  }
188
- else if ('name' in node && ((_f = node.name) === null || _f === void 0 ? void 0 : _f[1])) {
228
+ else if ('name' in node && ((_g = node.name) === null || _g === void 0 ? void 0 : _g[1])) {
189
229
  const num = Number(node.name[1]);
190
230
  level = !isNaN(num) ? num : undefined;
191
231
  if (level !== undefined) {
@@ -252,42 +292,15 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
252
292
  node.name = node.name === 'Update' ? 'Update' : node.name === 'Step' ? 'Step' : 'Heading';
253
293
  // @ts-expect-error we've already written to 'depth' and so this should be safe
254
294
  const depth = node.depth;
255
- if (level !== undefined && Number(level) <= 2) {
256
- hasTopLayer = true;
257
- contents.push({
258
- title,
259
- slug,
260
- depth,
261
- children: [],
262
- tabId: currentTabId,
263
- viewId: currentViewId,
264
- variationIds: currentVariationIds,
265
- });
266
- }
267
- else {
268
- // Account if there is no first layer
269
- let arrToPushInto = contents;
270
- if (hasTopLayer) {
271
- const lastTopLevel = contents.at(-1);
272
- if (lastTopLevel &&
273
- (lastTopLevel.tabId === undefined || lastTopLevel.tabId === currentTabId) &&
274
- (lastTopLevel.viewId === undefined || lastTopLevel.viewId === currentViewId) &&
275
- (lastTopLevel.variationIds === undefined ||
276
- (currentVariationIds !== undefined &&
277
- currentVariationIds.every((id) => { var _a; return (_a = lastTopLevel.variationIds) === null || _a === void 0 ? void 0 : _a.includes(id); })))) {
278
- arrToPushInto = lastTopLevel.children;
279
- }
280
- }
281
- arrToPushInto.push({
282
- title,
283
- slug,
284
- depth,
285
- children: [],
286
- tabId: currentTabId,
287
- viewId: currentViewId,
288
- variationIds: currentVariationIds,
289
- });
290
- }
295
+ pushEntry({
296
+ title,
297
+ slug,
298
+ depth,
299
+ children: [],
300
+ tabId: currentTabId,
301
+ viewId: currentViewId,
302
+ variationIds: currentVariationIds,
303
+ }, level);
291
304
  });
292
305
  if (mdxExtracts) {
293
306
  mdxExtracts.tableOfContents = contents;
@@ -87,9 +87,11 @@ export declare const MAX_MDX_FRAGMENTS_PER_PAGE = 500;
87
87
  * feeds the side panel / sticky examples.
88
88
  *
89
89
  * Table of contents: the fragment pipeline runs `remarkExtractTableOfContents` (it also rewrites
90
- * headings to `<Heading>`, so it cannot be skipped) into a fragment-scoped extracts object that is
91
- * discarded, so headings inside an expression fragment get ids but are not listed in the page's
92
- * table of contents yet — that merge is a follow-up PR.
90
+ * headings to `<Heading>`, so it cannot be skipped) into a fragment-scoped extracts object; the
91
+ * headings are stored on the expression node as `data.tableOfContents` and merged into the page
92
+ * TOC in document order by the page-level run. Headings of a branch that never renders are still
93
+ * listed, and a fragment heading that repeats a page heading's title keeps its own id — a
94
+ * render-time reconcile is the planned follow-up.
93
95
  */
94
96
  export declare const remarkMdxExpandExpressions: (options: RemarkMdxExpandExpressionsOptions) => (tree: Root) => Promise<void>;
95
97
  export declare const dedent: (text: string) => string;
@@ -77,9 +77,11 @@ export const MAX_MDX_FRAGMENTS_PER_PAGE = 500;
77
77
  * feeds the side panel / sticky examples.
78
78
  *
79
79
  * Table of contents: the fragment pipeline runs `remarkExtractTableOfContents` (it also rewrites
80
- * headings to `<Heading>`, so it cannot be skipped) into a fragment-scoped extracts object that is
81
- * discarded, so headings inside an expression fragment get ids but are not listed in the page's
82
- * table of contents yet — that merge is a follow-up PR.
80
+ * headings to `<Heading>`, so it cannot be skipped) into a fragment-scoped extracts object; the
81
+ * headings are stored on the expression node as `data.tableOfContents` and merged into the page
82
+ * TOC in document order by the page-level run. Headings of a branch that never renders are still
83
+ * listed, and a fragment heading that repeats a page heading's title keeps its own id — a
84
+ * render-time reconcile is the planned follow-up.
83
85
  */
84
86
  export const remarkMdxExpandExpressions = (options) => (tree) => __awaiter(void 0, void 0, void 0, function* () {
85
87
  var _a, _b, _c;
@@ -125,6 +127,7 @@ const expandExpression = (node_1, options_1, _a) => __awaiter(void 0, [node_1, o
125
127
  const elements = collectMdxElements(expression);
126
128
  if (elements.length === 0)
127
129
  return;
130
+ const headings = [];
128
131
  let changed = false;
129
132
  for (const element of elements) {
130
133
  const opening = element.openingElement;
@@ -173,6 +176,9 @@ const expandExpression = (node_1, options_1, _a) => __awaiter(void 0, [node_1, o
173
176
  ? compiled.children
174
177
  : [compiled];
175
178
  changed = true;
179
+ if (fragmentExtracts.tableOfContents) {
180
+ headings.push(...fragmentExtracts.tableOfContents);
181
+ }
176
182
  }
177
183
  if (!changed)
178
184
  return;
@@ -184,6 +190,9 @@ const expandExpression = (node_1, options_1, _a) => __awaiter(void 0, [node_1, o
184
190
  };
185
191
  node.value = toJs(program, { handlers: jsxHandlers }).value.replace(/;\s*$/, '');
186
192
  node.data = Object.assign(Object.assign({}, node.data), { estree: program });
193
+ if (headings.length > 0) {
194
+ node.data.tableOfContents = headings;
195
+ }
187
196
  });
188
197
  const collectMdxElements = (expression) => {
189
198
  const elements = [];