@mintlify/common 1.0.1049 → 1.0.1051

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.
@@ -7,3 +7,7 @@ export declare const LIVE_PREVIEW_COMPILED_CONTENT_UPDATE_MESSAGE_TYPE = "livePr
7
7
  export declare const LIVE_PREVIEW_NAVIGATION_UPDATE_MESSAGE_TYPE = "livePreviewNavigationUpdate";
8
8
  export declare const LIVE_PREVIEW_REQUEST_CONTENT_MESSAGE_TYPE = "livePreviewRequestContent";
9
9
  export declare const LIVE_PREVIEW_CONTENT_UNAVAILABLE_MESSAGE_TYPE = "livePreviewContentUnavailable";
10
+ export declare const LIVE_PREVIEW_CSS_SNAPSHOT_MESSAGE_TYPE = "livePreviewCssSnapshot";
11
+ export declare function normalizeLivePreviewPath(path: string): string;
12
+ export declare function normalizeLivePreviewBasePath(basePath: string | undefined): string;
13
+ export declare function stripLivePreviewBasePath(path: string, basePath: string | undefined): string;
@@ -7,3 +7,27 @@ export const LIVE_PREVIEW_COMPILED_CONTENT_UPDATE_MESSAGE_TYPE = 'livePreviewCom
7
7
  export const LIVE_PREVIEW_NAVIGATION_UPDATE_MESSAGE_TYPE = 'livePreviewNavigationUpdate';
8
8
  export const LIVE_PREVIEW_REQUEST_CONTENT_MESSAGE_TYPE = 'livePreviewRequestContent';
9
9
  export const LIVE_PREVIEW_CONTENT_UNAVAILABLE_MESSAGE_TYPE = 'livePreviewContentUnavailable';
10
+ export const LIVE_PREVIEW_CSS_SNAPSHOT_MESSAGE_TYPE = 'livePreviewCssSnapshot';
11
+ function normalizeLivePreviewHref(path) {
12
+ return path.replace(/^\/+|\/+$/g, '').replace(/\.mdx?$/, '');
13
+ }
14
+ export function normalizeLivePreviewPath(path) {
15
+ const href = normalizeLivePreviewHref(path);
16
+ return href ? `/${href}` : '/';
17
+ }
18
+ export function normalizeLivePreviewBasePath(basePath) {
19
+ var _a;
20
+ const normalized = (_a = basePath === null || basePath === void 0 ? void 0 : basePath.replace(/^\/+|\/+$/g, '')) !== null && _a !== void 0 ? _a : '';
21
+ return normalized ? `/${normalized}` : '';
22
+ }
23
+ export function stripLivePreviewBasePath(path, basePath) {
24
+ const normalizedPath = normalizeLivePreviewPath(path);
25
+ const normalizedBasePath = normalizeLivePreviewBasePath(basePath);
26
+ if (!normalizedBasePath)
27
+ return normalizedPath;
28
+ if (normalizedPath === normalizedBasePath)
29
+ return '/';
30
+ return normalizedPath.startsWith(`${normalizedBasePath}/`)
31
+ ? normalizedPath.slice(normalizedBasePath.length)
32
+ : normalizedPath;
33
+ }
@@ -39,6 +39,7 @@ export const COMPONENTS_WITHOUT_ID = new Set([
39
39
  'Tooltip',
40
40
  'Tree',
41
41
  'FileTree',
42
+ 'Variation',
42
43
  'Visibility',
43
44
  'Badge',
44
45
  'Color',
@@ -3,6 +3,7 @@ import { safeCleanHeadingId, slugify } from '../../../slugify.js';
3
3
  import { createMdxJsxAttribute, getTableOfContentsTitle } from '../../lib/remark-utils.js';
4
4
  import { isMdxJsxFragment } from '../../utils.js';
5
5
  import { AVOIDED_PAGE_MODES, HEADING_LEVELS } from './remarkComponentIds.js';
6
+ import { isVariationElement, resolveVariationIds } from './variation.js';
6
7
  export const HEADING_NAMES = ['h1', 'h2', 'h3', 'h4'];
7
8
  const COMPONENTS_TO_EXCLUDE_HEADINGS = [
8
9
  'Accordion',
@@ -43,6 +44,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
43
44
  // the key is the node in unist
44
45
  const tabContentMap = new Map();
45
46
  const viewContentMap = new Map();
47
+ const variationContentMap = new Map();
46
48
  // Maps a Step node to the titleSize inherited from its parent <Steps>.
47
49
  // At render time <Steps titleSize> is forwarded to each child <Step> that
48
50
  // doesn't set its own titleSize, so the TOC must honor the same fallback.
@@ -99,6 +101,17 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
99
101
  });
100
102
  }
101
103
  }
104
+ const variationNode = node;
105
+ if (isVariationElement(variationNode)) {
106
+ const resolution = resolveVariationIds(variationNode);
107
+ const variationIds = resolution.kind === 'valid' ? resolution.ids : [];
108
+ visit(node, (childNode) => {
109
+ const inheritedVariationIds = variationContentMap.get(childNode);
110
+ variationContentMap.set(childNode, inheritedVariationIds
111
+ ? inheritedVariationIds.filter((id) => variationIds.includes(id))
112
+ : variationIds);
113
+ });
114
+ }
102
115
  });
103
116
  visit(tree, (node) => {
104
117
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -106,6 +119,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
106
119
  return;
107
120
  const currentTabId = tabContentMap.get(node);
108
121
  const currentViewId = viewContentMap.get(node);
122
+ const currentVariationIds = variationContentMap.get(node);
109
123
  const isValidHeading = node.type === 'heading' && HEADING_LEVELS.includes(node.depth);
110
124
  const isValidMdxHeading = node.type === 'mdxJsxFlowElement' && HEADING_NAMES.includes((_a = node.name) !== null && _a !== void 0 ? _a : '');
111
125
  const isTransformedHeading = node.type === 'mdxJsxFlowElement' && node.name === 'Heading';
@@ -241,6 +255,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
241
255
  children: [],
242
256
  tabId: currentTabId,
243
257
  viewId: currentViewId,
258
+ variationIds: currentVariationIds,
244
259
  });
245
260
  }
246
261
  else {
@@ -250,7 +265,10 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
250
265
  const lastTopLevel = contents.at(-1);
251
266
  if (lastTopLevel &&
252
267
  (lastTopLevel.tabId === undefined || lastTopLevel.tabId === currentTabId) &&
253
- (lastTopLevel.viewId === undefined || lastTopLevel.viewId === currentViewId)) {
268
+ (lastTopLevel.viewId === undefined || lastTopLevel.viewId === currentViewId) &&
269
+ (lastTopLevel.variationIds === undefined ||
270
+ (currentVariationIds !== undefined &&
271
+ currentVariationIds.every((id) => { var _a; return (_a = lastTopLevel.variationIds) === null || _a === void 0 ? void 0 : _a.includes(id); })))) {
254
272
  arrToPushInto = lastTopLevel.children;
255
273
  }
256
274
  }
@@ -261,6 +279,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
261
279
  children: [],
262
280
  tabId: currentTabId,
263
281
  viewId: currentViewId,
282
+ variationIds: currentVariationIds,
264
283
  });
265
284
  }
266
285
  });
@@ -0,0 +1,15 @@
1
+ import type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx-jsx';
2
+ export type VariationElement = MdxJsxFlowElement | MdxJsxTextElement;
3
+ export type VariationResolution = {
4
+ kind: 'valid';
5
+ ids: string[];
6
+ } | {
7
+ kind: 'missing';
8
+ } | {
9
+ kind: 'invalid';
10
+ };
11
+ export declare function isVariationElement(node: {
12
+ type: string;
13
+ name?: string | null;
14
+ }): node is VariationElement;
15
+ export declare function resolveVariationIds(node: VariationElement): VariationResolution;
@@ -0,0 +1,48 @@
1
+ export function isVariationElement(node) {
2
+ return ((node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement') &&
3
+ node.name === 'Variation');
4
+ }
5
+ export function resolveVariationIds(node) {
6
+ var _a, _b, _c, _d;
7
+ const attribute = node.attributes.find((candidate) => candidate.type === 'mdxJsxAttribute' && candidate.name === 'is');
8
+ if (!attribute)
9
+ return { kind: 'missing' };
10
+ if (typeof attribute.value === 'string') {
11
+ const id = attribute.value.trim();
12
+ return id ? { kind: 'valid', ids: [id] } : { kind: 'invalid' };
13
+ }
14
+ if (!attribute.value)
15
+ return { kind: 'invalid' };
16
+ const estree = (_a = attribute.value.data) === null || _a === void 0 ? void 0 : _a.estree;
17
+ const statement = estree === null || estree === void 0 ? void 0 : estree.body[0];
18
+ const expression = (statement === null || statement === void 0 ? void 0 : statement.type) === 'ExpressionStatement' ? statement.expression : undefined;
19
+ if ((expression === null || expression === void 0 ? void 0 : expression.type) === 'Literal' && typeof expression.value === 'string') {
20
+ const id = expression.value.trim();
21
+ return id ? { kind: 'valid', ids: [id] } : { kind: 'invalid' };
22
+ }
23
+ if ((expression === null || expression === void 0 ? void 0 : expression.type) === 'TemplateLiteral' && expression.expressions.length === 0) {
24
+ const id = (_c = (_b = expression.quasis[0]) === null || _b === void 0 ? void 0 : _b.value.cooked) === null || _c === void 0 ? void 0 : _c.trim();
25
+ return id ? { kind: 'valid', ids: [id] } : { kind: 'invalid' };
26
+ }
27
+ if ((expression === null || expression === void 0 ? void 0 : expression.type) === 'ArrayExpression') {
28
+ const ids = [];
29
+ for (const element of expression.elements) {
30
+ if ((element === null || element === void 0 ? void 0 : element.type) !== 'Literal' || typeof element.value !== 'string') {
31
+ return { kind: 'invalid' };
32
+ }
33
+ const id = element.value.trim();
34
+ if (!id)
35
+ return { kind: 'invalid' };
36
+ ids.push(id);
37
+ }
38
+ return ids.length > 0 ? { kind: 'valid', ids: [...new Set(ids)] } : { kind: 'invalid' };
39
+ }
40
+ if (estree)
41
+ return { kind: 'invalid' };
42
+ const raw = attribute.value.value.trim();
43
+ const quotedString = raw.match(/^(["'`])([\s\S]*)\1$/);
44
+ if ((_d = quotedString === null || quotedString === void 0 ? void 0 : quotedString[2]) === null || _d === void 0 ? void 0 : _d.trim()) {
45
+ return { kind: 'valid', ids: [quotedString[2].trim()] };
46
+ }
47
+ return { kind: 'invalid' };
48
+ }
package/dist/mdx/utils.js CHANGED
@@ -144,6 +144,7 @@ export const allowedComponents = [
144
144
  'ZoomImage',
145
145
  'OptimizedVideo',
146
146
  'Mermaid',
147
+ 'Variation',
147
148
  'Visibility',
148
149
  'View',
149
150
  // Custom tags