@mintlify/common 1.0.398 → 1.0.400

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.
Files changed (26) hide show
  1. package/dist/divisions/generatePathToLanguageDict.js +6 -0
  2. package/dist/divisions/generatePathToVersionDict.js +3 -0
  3. package/dist/divisions/generatePathToVersionDictForDocsConfig.js +6 -0
  4. package/dist/mdx/lib/remark-utils.d.ts +8 -8
  5. package/dist/mdx/lib/remark-utils.js +23 -25
  6. package/dist/mdx/plugins/rehype/rehypeCodeBlocks.js +1 -2
  7. package/dist/mdx/plugins/rehype/rehypeMdxExtractEndpoint/parsers.d.ts +1 -1
  8. package/dist/mdx/plugins/rehype/rehypeMdxExtractEndpoint/parsers.js +10 -4
  9. package/dist/mdx/plugins/rehype/rehypeRawComponents.d.ts +2 -1
  10. package/dist/mdx/plugins/rehype/rehypeRawComponents.js +6 -3
  11. package/dist/mdx/plugins/rehype/rehypeUnicodeIds.d.ts +2 -1
  12. package/dist/mdx/plugins/rehype/rehypeUnicodeIds.js +9 -7
  13. package/dist/mdx/plugins/remark/remarkExtractChangelogFilters.d.ts +3 -1
  14. package/dist/mdx/plugins/remark/remarkExtractChangelogFilters.js +29 -32
  15. package/dist/mdx/plugins/remark/remarkExtractTableOfContents.d.ts +3 -1
  16. package/dist/mdx/plugins/remark/remarkExtractTableOfContents.js +71 -55
  17. package/dist/mdx/plugins/remark/remarkFrames.d.ts +2 -1
  18. package/dist/mdx/plugins/remark/remarkFrames.js +0 -27
  19. package/dist/mdx/plugins/remark/remarkHeadingIds.d.ts +2 -1
  20. package/dist/mdx/plugins/remark/remarkHeadingIds.js +4 -3
  21. package/dist/mdx/snippets/resolveImport/index.js +5 -1
  22. package/dist/navigation/getAllPathsInDocsNav.js +6 -0
  23. package/dist/navigation/getFirstPageFromNavigation.js +7 -0
  24. package/dist/openapi/parseOpenApiString.js +4 -2
  25. package/dist/tsconfig.build.tsbuildinfo +1 -1
  26. package/package.json +4 -4
@@ -8,6 +8,9 @@ export function generatePathToLanguageDict(nav) {
8
8
  function traverseNavigation(pathToLanguageDict, nav, nearestLanguage) {
9
9
  const currentLanguage = 'language' in nav ? nav.language : nearestLanguage;
10
10
  if ('pages' in nav) {
11
+ if ('root' in nav && typeof nav.root === 'object') {
12
+ traverseGroup(pathToLanguageDict, nav.root, currentLanguage);
13
+ }
11
14
  nav.pages.forEach((page) => traverseGroup(pathToLanguageDict, page, currentLanguage));
12
15
  return;
13
16
  }
@@ -20,6 +23,9 @@ function traverseNavigation(pathToLanguageDict, nav, nearestLanguage) {
20
23
  }
21
24
  function traverseGroup(pathToLanguageDict, entry, nearestLanguage) {
22
25
  if ('pages' in entry) {
26
+ if ('root' in entry && typeof entry.root === 'object') {
27
+ traverseGroup(pathToLanguageDict, entry.root, nearestLanguage);
28
+ }
23
29
  entry.pages.forEach((page) => traverseGroup(pathToLanguageDict, page, nearestLanguage));
24
30
  }
25
31
  else if ('href' in entry) {
@@ -24,6 +24,9 @@ function generatePathToVersionDictRecursive(pathToVersionDict, nav, nearestVersi
24
24
  }
25
25
  }
26
26
  if ('pages' in nav) {
27
+ if ('root' in nav && typeof nav.root === 'object') {
28
+ generatePathToVersionDictRecursive(pathToVersionDict, nav.root, nearestVersion);
29
+ }
27
30
  for (const page of nav.pages) {
28
31
  if (typeof page === 'object') {
29
32
  generatePathToVersionDictRecursive(pathToVersionDict, page, nearestVersion);
@@ -8,6 +8,9 @@ export function generatePathToVersionDictForDocsConfig(nav) {
8
8
  function traverseNavigation(pathToVersionDict, nav, nearestVersion) {
9
9
  const currentVersion = 'version' in nav ? nav.version : nearestVersion;
10
10
  if ('pages' in nav) {
11
+ if ('root' in nav && typeof nav.root === 'object') {
12
+ traverseGroup(pathToVersionDict, nav.root, currentVersion);
13
+ }
11
14
  nav.pages.forEach((page) => traverseGroup(pathToVersionDict, page, currentVersion));
12
15
  return;
13
16
  }
@@ -21,6 +24,9 @@ function traverseNavigation(pathToVersionDict, nav, nearestVersion) {
21
24
  function traverseGroup(pathToVersionDict, entry, nearestVersion) {
22
25
  if ('pages' in entry) {
23
26
  const currentVersion = 'version' in entry ? entry.version : nearestVersion;
27
+ if ('root' in entry && typeof entry.root === 'object') {
28
+ traverseGroup(pathToVersionDict, entry.root, currentVersion);
29
+ }
24
30
  entry.pages.forEach((page) => traverseGroup(pathToVersionDict, page, currentVersion));
25
31
  }
26
32
  else if ('href' in entry) {
@@ -1,8 +1,8 @@
1
- export function createMdxJsxAttribute(key: any, value: any): {
2
- type: string;
3
- name: any;
4
- value: any;
5
- };
6
- export function toMdxJsxFlowElement(input: any): import("mdast").RootContent | undefined;
7
- export function getUnicodeId(title: any): string;
8
- export function getTOCTitle(node: any, i?: number, a?: any[]): any;
1
+ import type { RootContent as HastRootContent } from 'hast';
2
+ import type { RootContent as MdastRootContent } from 'mdast';
3
+ import type { MdxJsxAttribute, MdxJsxAttributeValueExpression } from 'mdast-util-mdx-jsx';
4
+ type RootContent = MdastRootContent | HastRootContent;
5
+ export declare const createMdxJsxAttribute: (key: string, value: MdxJsxAttributeValueExpression | string | null | undefined | number | boolean) => MdxJsxAttribute;
6
+ export declare function getUnicodeId(title: string): string;
7
+ export declare const getTableOfContentsTitle: (node: RootContent, index?: number, children?: RootContent[]) => string;
8
+ export {};
@@ -1,39 +1,37 @@
1
- import * as acorn from 'acorn';
2
- import { fromMarkdown } from 'mdast-util-from-markdown';
3
- import { mdxJsxFromMarkdown } from 'mdast-util-mdx-jsx';
4
- import { mdxJsx } from 'micromark-extension-mdx-jsx';
5
1
  export const createMdxJsxAttribute = (key, value) => {
6
2
  return {
7
3
  type: 'mdxJsxAttribute',
8
4
  name: key,
9
- value,
5
+ // we want to cast here to avoid the type checker failing on number/boolean values
6
+ // which will get serialized properly, but just aren't added to the type
7
+ value: value,
10
8
  };
11
9
  };
12
- export const toMdxJsxFlowElement = (input) => {
13
- const tree = fromMarkdown(input, {
14
- extensions: [mdxJsx({ acorn: acorn, addResult: true })],
15
- mdastExtensions: [mdxJsxFromMarkdown()],
16
- });
17
- return tree.children[0];
18
- };
19
- export const getUnicodeId = (title) => {
10
+ export function getUnicodeId(title) {
20
11
  return encodeURIComponent(title.toLowerCase().trim().replace(/\s+/g, '-'));
21
- };
22
- export const getTOCTitle = (node, i = 1, a = []) => {
23
- var _a, _b, _c;
24
- if (node.name === 'Update') {
25
- const labelAttr = node.attributes.find((attr) => attr.name === 'label');
26
- return labelAttr.value;
12
+ }
13
+ const EMPTY_CHILDREN = [];
14
+ export const getTableOfContentsTitle = (node, index = 1, children = EMPTY_CHILDREN) => {
15
+ var _a;
16
+ if ('name' in node && node.name === 'Update') {
17
+ const labelAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'label' && typeof attr.value === 'string');
18
+ return (_a = labelAttr === null || labelAttr === void 0 ? void 0 : labelAttr.value) !== null && _a !== void 0 ? _a : '';
27
19
  }
28
- if ((node.type === 'text' &&
29
- (((_a = a[i - 1]) === null || _a === void 0 ? void 0 : _a.type) !== 'mdxJsxFlowElement' || !((_c = (_b = a[i - 1]) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.startsWith('<small')))) ||
30
- node.type === 'inlineCode') {
20
+ const lastChild = children[index - 1];
21
+ const isText = node.type === 'text';
22
+ const isInlineCode = node.type === 'inlineCode';
23
+ const isLastChildMdx = (lastChild === null || lastChild === void 0 ? void 0 : lastChild.type) !== 'mdxJsxFlowElement';
24
+ const isLastChildSmall = lastChild &&
25
+ 'value' in lastChild &&
26
+ typeof lastChild.value === 'string' &&
27
+ !lastChild.value.startsWith('<small');
28
+ if (isInlineCode || (isText && (isLastChildMdx || isLastChildSmall))) {
31
29
  return node.value;
32
30
  }
33
- if (node.children) {
31
+ if ('children' in node && Array.isArray(node.children)) {
34
32
  let title = '';
35
- node.children.forEach((node, i, a) => {
36
- title += getTOCTitle(node, i, a);
33
+ node.children.forEach((subNode, index, children) => {
34
+ title += getTableOfContentsTitle(subNode, index, children);
37
35
  });
38
36
  return title;
39
37
  }
@@ -5,7 +5,6 @@ function isElement(node, key = 'type', element = 'element') {
5
5
  return node != undefined && node[key] === element;
6
6
  }
7
7
  function addCodeBlocks(tree) {
8
- const preTree = { children: [] };
9
8
  visit(tree, (node, i, parent) => {
10
9
  var _a, _b;
11
10
  if (parent == null || i == null || !isElement(node) || !isElement(node, 'tagName', 'pre')) {
@@ -53,7 +52,7 @@ function addCodeBlocks(tree) {
53
52
  wrap.children = [node];
54
53
  parent.children[i] = wrap;
55
54
  });
56
- tree.children = [...preTree.children, ...tree.children];
55
+ tree.children = [...tree.children];
57
56
  }
58
57
  export function rehypeCodeBlocks() {
59
58
  return addCodeBlocks;
@@ -1,6 +1,6 @@
1
1
  import { MintConfig } from '@mintlify/models';
2
2
  import { DataSchema, DocsConfig, HttpMethod, SecurityOption, Server } from '@mintlify/validation';
3
- import { MdxJsxFlowElementHast } from 'mdast-util-mdx-jsx';
3
+ import type { MdxJsxFlowElementHast } from 'mdast-util-mdx-jsx';
4
4
  import type { FieldLocation } from '../../../lib/mdx-utils.js';
5
5
  export declare const parseApiString: (apiString: string, config?: MintConfig | DocsConfig) => {
6
6
  servers?: Server[];
@@ -1,15 +1,18 @@
1
+ import { OpenAPIV3 } from 'openapi-types';
1
2
  import { getSecurityOptionsForAuthMethod } from '../../../../index.js';
2
3
  import { isAbsoluteUrl } from '../../../../isAbsoluteUrl.js';
3
4
  import { isDocsConfig } from '../../../../isDocsConfig.js';
4
5
  import { isMdxJsxAttribute, isParamFieldLocation } from '../../../lib/mdx-utils.js';
6
+ const VALID_METHODS = Object.values(OpenAPIV3.HttpMethods);
5
7
  export const parseApiString = (apiString, config) => {
6
8
  const components = apiString.trim().split(/\s+/);
7
9
  if (!components[0] || !components[1] || components.length > 2) {
8
10
  throw new Error('improperly formatted api string');
9
11
  }
10
- const [upperMethod, endpointStr] = components;
12
+ const upperMethod = components[0];
13
+ const endpointStr = components[1];
11
14
  const method = upperMethod.toLowerCase();
12
- if (!['get', 'put', 'post', 'delete', 'patch', 'options', 'head', 'trace'].includes(method)) {
15
+ if (!VALID_METHODS.includes(method)) {
13
16
  throw new Error('invalid http method');
14
17
  }
15
18
  const { origin, path } = parseEndpoint(endpointStr);
@@ -204,7 +207,9 @@ export const parseTypeString = (typeString) => {
204
207
  const lowerTypeString = typeString.toLowerCase();
205
208
  const simpleSchemaType = typeStringToSchemaType[lowerTypeString];
206
209
  if (lowerTypeString.includes('|')) {
207
- const [left, right] = lowerTypeString.split('|');
210
+ const splitLowerTypeString = lowerTypeString.split('|');
211
+ const left = splitLowerTypeString[0];
212
+ const right = splitLowerTypeString[1];
208
213
  if (left && right) {
209
214
  const leftSchema = parseTypeString(left.trim());
210
215
  const rightSchema = parseTypeString(right.trim());
@@ -238,7 +243,8 @@ export const parseTypeString = (typeString) => {
238
243
  const regexMatch = genericStringRegex.exec(lowerTypeString);
239
244
  if (regexMatch !== null) {
240
245
  // unpack capture group 1 (foo) and 2 (bar)
241
- const [_, superType, subType] = regexMatch;
246
+ const superType = regexMatch[1];
247
+ const subType = regexMatch[2];
242
248
  if (superType && subType && typeStringToSchemaType[superType] === 'array') {
243
249
  // catches type strings like array<bar>
244
250
  // recursively determine the type of everything within the angle brackets
@@ -1 +1,2 @@
1
- export function rehypeRawComponents(): (tree: any) => void;
1
+ import type { Pluggable } from 'unified';
2
+ export declare const rehypeRawComponents: Pluggable;
@@ -2,10 +2,13 @@ import { fromHtml } from 'hast-util-from-html';
2
2
  import { visit } from 'unist-util-visit';
3
3
  export const rehypeRawComponents = () => {
4
4
  return (tree) => {
5
- visit(tree, 'raw', (raw, i, parent) => {
5
+ visit(tree, 'raw', (raw, index, parent) => {
6
6
  const rawAst = fromHtml(raw.value, { fragment: true });
7
- if (parent && i) {
8
- parent.children[i] = rawAst;
7
+ if (parent && index !== undefined) {
8
+ // @ts-expect-error we're passing a component of type Root to parent.children which
9
+ // is fine even though parent.children should only take RootContent, bc `remark`
10
+ // will flatten out Roots into single nodes of type RootContent when serializing
11
+ parent.children[index] = rawAst;
9
12
  }
10
13
  });
11
14
  };
@@ -1 +1,2 @@
1
- export function rehypeUnicodeIds(): (tree: any) => void;
1
+ import type { Pluggable } from 'unified';
2
+ export declare const rehypeUnicodeIds: Pluggable;
@@ -1,17 +1,19 @@
1
1
  import { visit } from 'unist-util-visit';
2
- import { getUnicodeId, getTOCTitle } from '../../lib/remark-utils.js';
2
+ import { getUnicodeId, getTableOfContentsTitle } from '../../lib/remark-utils.js';
3
3
  const DEEPLINKABLE_COMPONENTS = ['Heading', 'Update', 'Accordion'];
4
- export function rehypeUnicodeIds() {
4
+ export const rehypeUnicodeIds = () => {
5
5
  return (tree) => {
6
6
  visit(tree, 'mdxJsxFlowElement', (node) => {
7
- if (node && node.name && DEEPLINKABLE_COMPONENTS.includes(node.name)) {
8
- const title = getTOCTitle(node);
7
+ if (node.name && DEEPLINKABLE_COMPONENTS.includes(node.name)) {
8
+ const title = getTableOfContentsTitle(node);
9
9
  const encodedId = getUnicodeId(title);
10
- const existingIdIndex = node.attributes.findIndex((attr) => attr.name === 'id');
11
- if (existingIdIndex !== -1 && !node.attributes[existingIdIndex].value) {
10
+ const existingIdIndex = node.attributes.findIndex((attr) => 'name' in attr && attr.name === 'id');
11
+ if (existingIdIndex !== -1 &&
12
+ node.attributes[existingIdIndex] &&
13
+ !node.attributes[existingIdIndex].value) {
12
14
  node.attributes[existingIdIndex].value = encodedId;
13
15
  }
14
16
  }
15
17
  });
16
18
  };
17
- }
19
+ };
@@ -1 +1,3 @@
1
- export function remarkExtractChangelogFilters(mdxExtracts: any): (tree: any) => void;
1
+ import type { Root } from 'mdast';
2
+ import type { MdxExtracts } from '../../../types/index.js';
3
+ export declare function remarkExtractChangelogFilters(mdxExtracts?: MdxExtracts): (tree: Root) => void;
@@ -1,43 +1,40 @@
1
1
  export function remarkExtractChangelogFilters(mdxExtracts) {
2
2
  return (tree) => {
3
+ var _a, _b;
3
4
  const tagCounts = new Map();
4
5
  for (let nodeIndex = 0; nodeIndex < tree.children.length; nodeIndex++) {
5
6
  const node = tree.children[nodeIndex];
6
- if (node.type === 'mdxJsxFlowElement' && node.name === 'Update') {
7
- const tagsAttribute = node.attributes.find((attr) => attr.name === 'tags');
8
- if (tagsAttribute &&
9
- tagsAttribute.value &&
10
- tagsAttribute.value.type === 'mdxJsxAttributeValueExpression') {
11
- let tags = [];
12
- try {
13
- tags = JSON.parse(tagsAttribute.value.value);
14
- }
15
- catch (_a) {
16
- const isProgram = tagsAttribute.value.data.estree.type === 'Program';
17
- if (isProgram && tagsAttribute.value.data.estree.body.length === 1) {
18
- const body = tagsAttribute.value.data.estree.body[0];
19
- if (body.type === 'ExpressionStatement' &&
20
- body.expression.type === 'ArrayExpression') {
21
- tags = body.expression.elements
22
- .map((element) => {
23
- if (element.type === 'Literal') {
24
- return element.value;
25
- }
26
- return null;
27
- })
28
- .filter(Boolean);
29
- }
30
- }
31
- }
32
- if (Array.isArray(tags)) {
33
- tags.forEach((tag) => {
34
- if (!!tag.trim()) {
35
- tagCounts.set(tag, (tagCounts.get(tag) || 0) + 1);
36
- }
37
- });
7
+ if (!node || node.type !== 'mdxJsxFlowElement' || node.name !== 'Update') {
8
+ continue;
9
+ }
10
+ const tagsAttribute = node.attributes.find((attr) => 'name' in attr && attr.name === 'tags');
11
+ if (!tagsAttribute || !tagsAttribute.value || typeof tagsAttribute.value !== 'object') {
12
+ continue;
13
+ }
14
+ let tags = [];
15
+ try {
16
+ tags = JSON.parse(tagsAttribute.value.value);
17
+ }
18
+ catch (_c) {
19
+ if (((_b = (_a = tagsAttribute.value.data) === null || _a === void 0 ? void 0 : _a.estree) === null || _b === void 0 ? void 0 : _b.body.length) === 1) {
20
+ const body = tagsAttribute.value.data.estree.body[0];
21
+ if ((body === null || body === void 0 ? void 0 : body.type) === 'ExpressionStatement' && body.expression.type === 'ArrayExpression') {
22
+ tags = body.expression.elements
23
+ .map((element) => {
24
+ return (element === null || element === void 0 ? void 0 : element.type) === 'Literal' ? element.value : null;
25
+ })
26
+ .filter(Boolean);
38
27
  }
39
28
  }
40
29
  }
30
+ if (!Array.isArray(tags)) {
31
+ continue;
32
+ }
33
+ tags.forEach((tag) => {
34
+ if (!!tag.trim()) {
35
+ tagCounts.set(tag, (tagCounts.get(tag) || 0) + 1);
36
+ }
37
+ });
41
38
  }
42
39
  const filters = Array.from(tagCounts.entries())
43
40
  .map(([tag, count]) => ({
@@ -1 +1,3 @@
1
- export function remarkExtractTableOfContents(mdxExtracts: any): (tree: any) => void;
1
+ import type { Root } from 'mdast';
2
+ import type { MdxExtracts } from '../../../types/index.js';
3
+ export declare const remarkExtractTableOfContents: (mdxExtracts?: MdxExtracts) => (tree: Root) => void;
@@ -1,68 +1,84 @@
1
1
  import { slugifyWithCounter } from '@sindresorhus/slugify';
2
- import { createMdxJsxAttribute, getTOCTitle, getUnicodeId } from '../../lib/remark-utils.js';
2
+ import { createMdxJsxAttribute, getTableOfContentsTitle, getUnicodeId, } from '../../lib/remark-utils.js';
3
+ import { HEADING_LEVELS } from './remarkHeadingIds.js';
4
+ const HEADING_NAMES = ['h1', 'h2', 'h3', 'h4'];
3
5
  export const remarkExtractTableOfContents = (mdxExtracts) => {
4
6
  // slugifyWithCounter adds a counter (eg. slug, slug-2, slug-3) to the end of the slug if the header
5
7
  // already exists. No counter is added for the first occurence.
6
8
  const slugify = slugifyWithCounter();
7
9
  return (tree) => {
10
+ var _a, _b, _c, _d;
8
11
  const contents = [];
9
12
  let hasTopLayer = false;
10
13
  for (let nodeIndex = 0; nodeIndex < tree.children.length; nodeIndex++) {
11
- let node = tree.children[nodeIndex];
12
- if ((node.type === 'heading' && [1, 2, 3, 4].includes(node.depth)) ||
13
- (node.type === 'mdxJsxFlowElement' && ['h1', 'h2', 'h3', 'h4'].includes(node.name)) ||
14
- (node.name === 'Update' &&
15
- node.attributes.some((attr) => node.type === 'mdxJsxFlowElement' && attr.name === 'label'))) {
16
- let level;
17
- if (node.name === 'Update') {
18
- level = 1;
19
- node.depth = 1;
20
- }
21
- else {
22
- level = node.depth ? node.depth : node.name.split('')[1];
23
- }
24
- let title = getTOCTitle(node);
25
- const encodedTitle = getUnicodeId(title);
26
- let slug;
27
- // if encoded title is already percent-encoded, return it as is
28
- // slugify doesn't support percent-encoded characters, like Chinese, Korean, etc.
29
- if (/%[0-9A-F]{2}/.test(encodedTitle)) {
30
- slug = slugify(encodedTitle, {
31
- decamelize: false,
32
- preserveCharacters: ['%'],
33
- lowercase: false,
34
- });
35
- }
36
- else {
37
- slug = slugify(encodedTitle, { decamelize: false });
38
- }
39
- let mdxJsxAttributes;
40
- if (node.name === 'Update') {
41
- mdxJsxAttributes = [...node.attributes, createMdxJsxAttribute('id', slug)];
42
- }
43
- else {
44
- mdxJsxAttributes = [
45
- createMdxJsxAttribute('level', level),
46
- createMdxJsxAttribute('id', slug),
47
- createMdxJsxAttribute('isAtRootLevel', true),
48
- ];
49
- }
50
- node.attributes = mdxJsxAttributes;
51
- node.type = 'mdxJsxFlowElement';
52
- node.name = node.name === 'Update' ? 'Update' : 'Heading';
53
- const depth = node.depth;
54
- if (level <= 2) {
55
- hasTopLayer = true;
56
- contents.push({ title, slug, depth, children: [] });
57
- }
58
- else {
59
- // Account if there is no first layer
60
- let arrToPushInto = contents;
61
- if (hasTopLayer) {
62
- arrToPushInto = contents[contents.length - 1].children;
63
- }
64
- arrToPushInto.push({ title, slug, depth, children: [] });
14
+ const node = tree.children[nodeIndex];
15
+ if (!node)
16
+ continue;
17
+ const isValidHeading = node.type === 'heading' && HEADING_LEVELS.includes(node.depth);
18
+ const isValidMdxHeading = node.type === 'mdxJsxFlowElement' && HEADING_NAMES.includes((_a = node.name) !== null && _a !== void 0 ? _a : '');
19
+ const isValidUpdate = node.type === 'mdxJsxFlowElement' &&
20
+ node.name === 'Update' &&
21
+ node.attributes.some((attr) => 'name' in attr && attr.name === 'label');
22
+ if (!isValidHeading && !isValidMdxHeading && !isValidUpdate) {
23
+ continue;
24
+ }
25
+ let level;
26
+ if ('name' in node && node.name === 'Update') {
27
+ level = 1;
28
+ // @ts-expect-error we're assigning to depth despite the node not containing depth in the type
29
+ node.depth = 1;
30
+ }
31
+ else if ('depth' in node) {
32
+ level = node.depth;
33
+ }
34
+ else if ('name' in node && ((_b = node.name) === null || _b === void 0 ? void 0 : _b[1])) {
35
+ const num = Number(node.name[1]);
36
+ level = !isNaN(num) ? num : undefined;
37
+ }
38
+ const title = getTableOfContentsTitle(node);
39
+ const encodedTitle = getUnicodeId(title);
40
+ let slug;
41
+ // if encoded title is already percent-encoded, return it as is
42
+ // slugify doesn't support percent-encoded characters, like Chinese, Korean, etc.
43
+ if (/%[0-9A-F]{2}/.test(encodedTitle)) {
44
+ slug = slugify(encodedTitle, {
45
+ decamelize: false,
46
+ preserveCharacters: ['%'],
47
+ lowercase: false,
48
+ });
49
+ }
50
+ else {
51
+ slug = slugify(encodedTitle, { decamelize: false });
52
+ }
53
+ let mdxJsxAttributes;
54
+ if ('name' in node && node.name === 'Update') {
55
+ mdxJsxAttributes = [...node.attributes, createMdxJsxAttribute('id', slug)];
56
+ }
57
+ else if (level !== undefined) {
58
+ mdxJsxAttributes = [
59
+ createMdxJsxAttribute('level', level),
60
+ createMdxJsxAttribute('id', slug),
61
+ createMdxJsxAttribute('isAtRootLevel', true),
62
+ ];
63
+ }
64
+ // @ts-expect-error we're assigning over 'attributes' if it doesn't exist
65
+ node.attributes = mdxJsxAttributes;
66
+ node.type = 'mdxJsxFlowElement';
67
+ // @ts-expect-error we're assigning over 'name' if it doesn't exist
68
+ node.name = node.name === 'Update' ? 'Update' : 'Heading';
69
+ // @ts-expect-error we've already written to 'depth' and so this should be safe
70
+ const depth = node.depth;
71
+ if (level !== undefined && Number(level) <= 2) {
72
+ hasTopLayer = true;
73
+ contents.push({ title, slug, depth, children: [] });
74
+ }
75
+ else {
76
+ // Account if there is no first layer
77
+ let arrToPushInto = contents;
78
+ if (hasTopLayer) {
79
+ arrToPushInto = (_d = (_c = contents.at(-1)) === null || _c === void 0 ? void 0 : _c.children) !== null && _d !== void 0 ? _d : [];
65
80
  }
81
+ arrToPushInto.push({ title, slug, depth, children: [] });
66
82
  }
67
83
  }
68
84
  if (mdxExtracts) {
@@ -1 +1,2 @@
1
- export function remarkFrames(): (tree: any) => void;
1
+ import type { Root } from 'mdast';
2
+ export declare const remarkFrames: () => (tree: Root) => void;
@@ -1,37 +1,10 @@
1
- import { toMdxJsxFlowElement } from '../../lib/remark-utils.js';
2
1
  export const remarkFrames = () => {
3
2
  return (tree) => {
4
- let preTree = { children: [] };
5
3
  tree.children = tree.children.map((node) => {
6
- // Start of horizontal block: -- block
7
- if (node.type === 'paragraph' &&
8
- node.children.length === 1 &&
9
- node.children[0].value === '-- block') {
10
- node.type = 'jsx';
11
- node.value = `<div className='grid md:grid-cols-2 md:gap-8'><div>`;
12
- }
13
- // Start a new column: -- column
14
- if (node.type === 'paragraph' &&
15
- node.children.length === 1 &&
16
- node.children[0].value === '-- column') {
17
- node.type = 'jsx';
18
- node.value = `</div><div>`;
19
- }
20
- // End of horizontal block: -- /block
21
- if (node.type === 'paragraph' &&
22
- node.children.length === 1 &&
23
- node.children[0].value === '-- /block') {
24
- node.type = 'jsx';
25
- node.value = `</div></div>`;
26
- }
27
4
  if (node.type === 'mdxJsxFlowElement' && (node.name === 'Example' || node.name === 'Frame')) {
28
5
  node.name = 'Frame';
29
6
  }
30
- if (node.type === 'jsx') {
31
- node = toMdxJsxFlowElement(node.value);
32
- }
33
7
  return node;
34
8
  });
35
- tree.children = [...preTree.children, ...tree.children];
36
9
  };
37
10
  };
@@ -1,2 +1,3 @@
1
- import { Root } from 'mdast';
1
+ import type { Root } from 'mdast';
2
+ export declare const HEADING_LEVELS: number[];
2
3
  export declare const remarkHeadingIds: () => (tree: Root) => void;
@@ -1,12 +1,13 @@
1
1
  import { slugifyWithCounter } from '@sindresorhus/slugify';
2
2
  import { visit } from 'unist-util-visit';
3
3
  import { createMdxJsxAttribute, getUnicodeId } from '../../lib/remark-utils.js';
4
- import { getTOCTitle } from '../../lib/remark-utils.js';
4
+ import { getTableOfContentsTitle } from '../../lib/remark-utils.js';
5
+ export const HEADING_LEVELS = [1, 2, 3, 4];
5
6
  export const remarkHeadingIds = () => (tree) => {
6
7
  const slugify = slugifyWithCounter();
7
8
  visit(tree, 'heading', (node, _, parent) => {
8
- if ([1, 2, 3, 4].includes(node.depth)) {
9
- const title = getTOCTitle(node);
9
+ if (HEADING_LEVELS.includes(node.depth)) {
10
+ const title = getTableOfContentsTitle(node);
10
11
  const encodedTitle = getUnicodeId(title);
11
12
  let slug;
12
13
  // if encoded title is already percent-encoded, return it as is
@@ -12,6 +12,10 @@ import { getAST } from '../../remark.js';
12
12
  import { findExport } from './findExport.js';
13
13
  import { injectToTopOfFileOfTree } from './injectToTopOfFile.js';
14
14
  import { resolveComponentWithContent } from './resolveComponentWithContent.js';
15
+ const VALID_SPECIFIERS = [
16
+ MdxImportSpecifier.ImportSpecifier,
17
+ MdxImportSpecifier.RenamedImportSpecifier,
18
+ ];
15
19
  /**
16
20
  *
17
21
  * @param importSpecifier The name of the imported component we want to replace
@@ -20,7 +24,7 @@ import { resolveComponentWithContent } from './resolveComponentWithContent.js';
20
24
  * @returns
21
25
  */
22
26
  export const resolveImport = (importSpecifier, destinationPageContent, importedFileContent, exportMap) => __awaiter(void 0, void 0, void 0, function* () {
23
- if ([MdxImportSpecifier.ImportSpecifier, MdxImportSpecifier.RenamedImportSpecifier].includes(importSpecifier.type)) {
27
+ if (VALID_SPECIFIERS.includes(importSpecifier.type)) {
24
28
  // normal import: import { Component } from '/snippets/Component.mdx'
25
29
  if ((importSpecifier.renamedName && exportMap[importSpecifier.renamedName]) ||
26
30
  exportMap[importSpecifier.name]) {
@@ -1,6 +1,9 @@
1
1
  import { divisions } from '@mintlify/validation';
2
2
  export function getAllPathsInDocsNav(nav, paths = []) {
3
3
  if ('pages' in nav) {
4
+ if ('root' in nav) {
5
+ getPaths(nav.root, paths);
6
+ }
4
7
  nav.pages.forEach((page) => getPaths(page, paths));
5
8
  return paths;
6
9
  }
@@ -18,6 +21,9 @@ function getPaths(entry, paths) {
18
21
  return;
19
22
  }
20
23
  if ('pages' in entry) {
24
+ if ('root' in entry && typeof entry.root === 'object') {
25
+ getPaths(entry.root, paths);
26
+ }
21
27
  entry.pages.forEach((page) => {
22
28
  getPaths(page, paths);
23
29
  });
@@ -9,6 +9,13 @@ export function getFirstPageFromNavigation(node) {
9
9
  return node;
10
10
  }
11
11
  if ('pages' in node) {
12
+ if ('root' in node && typeof node.root === 'object') {
13
+ const page = getFirstPageFromNavigation(node.root);
14
+ if (page) {
15
+ page.href = replaceSlashIndex(page.href);
16
+ return page;
17
+ }
18
+ }
12
19
  for (const page of node.pages) {
13
20
  if (typeof page === 'object') {
14
21
  const pagePath = getFirstPageFromNavigation(page);