@mintlify/common 1.0.691 → 1.0.693

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.
@@ -15,6 +15,7 @@ export function generatePathToHiddenDict(decoratedNav) {
15
15
  return pathToHiddenDict;
16
16
  }
17
17
  function generatePathToHiddenDictRecursive(pathToHiddenDict, nav, parentHidden) {
18
+ var _a;
18
19
  if (typeof nav !== 'object')
19
20
  return;
20
21
  // Determine the effective hidden status for this level (from group/tab hidden property)
@@ -22,7 +23,7 @@ function generatePathToHiddenDictRecursive(pathToHiddenDict, nav, parentHidden)
22
23
  if (isPage(nav)) {
23
24
  const key = optionallyRemoveLeadingSlash(nav.href);
24
25
  // A page is hidden if parent has hidden: true OR page has noindex: true in frontmatter
25
- const pageNoindex = nav.noindex;
26
+ const pageNoindex = (_a = nav.noindex) !== null && _a !== void 0 ? _a : nav.hidden;
26
27
  const isHidden = pageNoindex !== null && pageNoindex !== void 0 ? pageNoindex : effectiveHidden;
27
28
  // Only add hidden pages to the dictionary (more efficient)
28
29
  // We keep the first value encountered to handle duplicate paths
@@ -5,6 +5,13 @@ import { createMdxJsxAttribute, getTableOfContentsTitle } from '../../lib/remark
5
5
  import { AVOIDED_PAGE_MODES, HEADING_LEVELS } from './remarkComponentIds.js';
6
6
  const HEADING_NAMES = ['h1', 'h2', 'h3', 'h4'];
7
7
  const COMPONENTS_TO_EXCLUDE_HEADINGS = ['Accordion', 'AccordionGroup', 'Expandable', 'Update'];
8
+ function getStringAttribute(attributes, name) {
9
+ const attr = attributes.find((a) => 'name' in a && a.name === name);
10
+ if (attr && 'value' in attr && typeof attr.value === 'string') {
11
+ return attr.value;
12
+ }
13
+ return undefined;
14
+ }
8
15
  export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
9
16
  // slugifyWithCounter adds a counter (eg. slug, slug-2, slug-3) to the end of the slug if the header
10
17
  // already exists. No counter is added for the first occurence.
@@ -26,15 +33,9 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
26
33
  });
27
34
  }
28
35
  if (node.type === 'mdxJsxFlowElement' && node.name === 'Tab') {
29
- const idAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'id');
30
- const titleAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'title');
31
- let tabId;
32
- if (idAttr && 'value' in idAttr && typeof idAttr.value === 'string') {
33
- tabId = idAttr.value;
34
- }
35
- else if (titleAttr && 'value' in titleAttr && typeof titleAttr.value === 'string') {
36
- tabId = slugify(titleAttr.value);
37
- }
36
+ const idValue = getStringAttribute(node.attributes, 'id');
37
+ const titleValue = getStringAttribute(node.attributes, 'title');
38
+ const tabId = idValue !== null && idValue !== void 0 ? idValue : (titleValue ? slugify(titleValue) : undefined);
38
39
  if (tabId) {
39
40
  visit(node, (childNode) => {
40
41
  tabContentMap.set(childNode, tabId);
@@ -42,11 +43,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
42
43
  }
43
44
  }
44
45
  if (node.type === 'mdxJsxFlowElement' && node.name === 'View') {
45
- const titleAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'title');
46
- let viewId;
47
- if (titleAttr && 'value' in titleAttr && typeof titleAttr.value === 'string') {
48
- viewId = titleAttr.value;
49
- }
46
+ const viewId = getStringAttribute(node.attributes, 'title');
50
47
  if (viewId) {
51
48
  visit(node, (childNode) => {
52
49
  viewContentMap.set(childNode, viewId);
@@ -55,7 +52,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
55
52
  }
56
53
  });
57
54
  visit(tree, (node) => {
58
- var _a, _b, _c;
55
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
59
56
  if (excludedNodes.has(node))
60
57
  return;
61
58
  const currentTabId = tabContentMap.get(node);
@@ -66,10 +63,18 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
66
63
  const isValidUpdate = node.type === 'mdxJsxFlowElement' &&
67
64
  node.name === 'Update' &&
68
65
  node.attributes.some((attr) => 'name' in attr && attr.name === 'label');
66
+ const isValidStep = node.type === 'mdxJsxFlowElement' &&
67
+ node.name === 'Step' &&
68
+ ['h2', 'h3'].includes((_b = getStringAttribute(node.attributes, 'titleSize')) !== null && _b !== void 0 ? _b : '') &&
69
+ ((_d = (_c = getStringAttribute(node.attributes, 'title')) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : '') !== '';
69
70
  const hasIdAttribute = node.type === 'mdxJsxFlowElement' &&
70
71
  node.attributes.some((attr) => 'name' in attr && attr.name === 'id');
71
- const isAvoidedPageMode = AVOIDED_PAGE_MODES.includes((_b = pageMetadata === null || pageMetadata === void 0 ? void 0 : pageMetadata.mode) !== null && _b !== void 0 ? _b : '');
72
- if (!isValidHeading && !isValidMdxHeading && !isTransformedHeading && !isValidUpdate) {
72
+ const isAvoidedPageMode = AVOIDED_PAGE_MODES.includes((_e = pageMetadata === null || pageMetadata === void 0 ? void 0 : pageMetadata.mode) !== null && _e !== void 0 ? _e : '');
73
+ if (!isValidHeading &&
74
+ !isValidMdxHeading &&
75
+ !isTransformedHeading &&
76
+ !isValidUpdate &&
77
+ !isValidStep) {
73
78
  return;
74
79
  }
75
80
  if (isAvoidedPageMode && (isValidHeading || isValidMdxHeading))
@@ -80,6 +85,13 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
80
85
  // @ts-expect-error we're assigning to depth despite the node not containing depth in the type
81
86
  node.depth = 1;
82
87
  }
88
+ else if ('name' in node && node.name === 'Step') {
89
+ const titleSize = getStringAttribute(node.attributes, 'titleSize');
90
+ const titleSizeToLevel = { h2: 2, h3: 3, h4: 4 };
91
+ level = (_f = titleSizeToLevel[titleSize !== null && titleSize !== void 0 ? titleSize : '']) !== null && _f !== void 0 ? _f : 3;
92
+ // @ts-expect-error we're assigning to depth despite the node not containing depth in the type
93
+ node.depth = level;
94
+ }
83
95
  else if ('depth' in node) {
84
96
  level = node.depth;
85
97
  }
@@ -89,27 +101,37 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
89
101
  level = levelAttr.value;
90
102
  }
91
103
  }
92
- else if ('name' in node && ((_c = node.name) === null || _c === void 0 ? void 0 : _c[1])) {
104
+ else if ('name' in node && ((_g = node.name) === null || _g === void 0 ? void 0 : _g[1])) {
93
105
  const num = Number(node.name[1]);
94
106
  level = !isNaN(num) ? num : undefined;
95
107
  }
96
- const title = getTableOfContentsTitle(node);
108
+ let title;
109
+ if ('name' in node && node.name === 'Step') {
110
+ title = (_h = getStringAttribute(node.attributes, 'title')) !== null && _h !== void 0 ? _h : getTableOfContentsTitle(node);
111
+ }
112
+ else {
113
+ title = getTableOfContentsTitle(node);
114
+ }
97
115
  let slug;
98
- if ('name' in node && node.name === 'Heading') {
99
- const idAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'id');
100
- if (idAttr && 'value' in idAttr && typeof idAttr.value === 'string') {
101
- slug = idAttr.value;
102
- }
103
- else {
104
- slug = slugify(title, slugifyFn);
105
- }
116
+ if ('name' in node &&
117
+ (node.name === 'Heading' || node.name === 'Step' || node.name === 'Update')) {
118
+ slug = (_j = getStringAttribute(node.attributes, 'id')) !== null && _j !== void 0 ? _j : slugify(title, slugifyFn);
106
119
  }
107
120
  else {
108
121
  slug = slugify(title, slugifyFn);
109
122
  }
110
123
  let mdxJsxAttributes;
111
124
  if ('name' in node && node.name === 'Update') {
112
- mdxJsxAttributes = [...node.attributes, createMdxJsxAttribute('id', slug)];
125
+ const existingId = getStringAttribute(node.attributes, 'id');
126
+ mdxJsxAttributes = existingId
127
+ ? node.attributes
128
+ : [...node.attributes, createMdxJsxAttribute('id', slug)];
129
+ }
130
+ else if ('name' in node && node.name === 'Step') {
131
+ const existingId = getStringAttribute(node.attributes, 'id');
132
+ mdxJsxAttributes = existingId
133
+ ? node.attributes
134
+ : [...node.attributes, createMdxJsxAttribute('id', slug)];
113
135
  }
114
136
  else if ('name' in node && node.name === 'Heading') {
115
137
  mdxJsxAttributes = node.attributes;
@@ -127,7 +149,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
127
149
  node.attributes = mdxJsxAttributes;
128
150
  node.type = 'mdxJsxFlowElement';
129
151
  // @ts-expect-error we're assigning over 'name' if it doesn't exist
130
- node.name = node.name === 'Update' ? 'Update' : 'Heading';
152
+ node.name = node.name === 'Update' ? 'Update' : node.name === 'Step' ? 'Step' : 'Heading';
131
153
  // @ts-expect-error we've already written to 'depth' and so this should be safe
132
154
  const depth = node.depth;
133
155
  if (level !== undefined && Number(level) <= 2) {
@@ -146,7 +168,9 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
146
168
  let arrToPushInto = contents;
147
169
  if (hasTopLayer) {
148
170
  const lastTopLevel = contents.at(-1);
149
- if (lastTopLevel && lastTopLevel.tabId === currentTabId) {
171
+ if (lastTopLevel &&
172
+ lastTopLevel.tabId === currentTabId &&
173
+ lastTopLevel.viewId === currentViewId) {
150
174
  arrToPushInto = lastTopLevel.children;
151
175
  }
152
176
  }
@@ -1,2 +1,2 @@
1
1
  import type { DecoratedNavigationPage } from '@mintlify/models';
2
- export declare function checkNavAccess(page: DecoratedNavigationPage, userGroups: Set<string>, isPreview?: boolean): boolean;
2
+ export declare function checkNavAccess(page: DecoratedNavigationPage, userGroups: Set<string>, isPreview?: boolean, checkHidden?: boolean): boolean;
@@ -1,6 +1,8 @@
1
- export function checkNavAccess(page, userGroups, isPreview = false) {
1
+ export function checkNavAccess(page, userGroups, isPreview = false, checkHidden = true) {
2
2
  if (isPreview)
3
3
  return true;
4
+ if (checkHidden && page.hidden)
5
+ return false;
4
6
  const pageGroups = Array.isArray(page.groups) && page.groups.every((pageGroup) => typeof pageGroup === 'string')
5
7
  ? page.groups
6
8
  : undefined;