@mintlify/common 1.0.591 → 1.0.593

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.
@@ -0,0 +1,13 @@
1
+ import { PageMetaTags } from '@mintlify/models';
2
+ import { parseAsyncApiString } from '../asyncapi/parseAsyncApiString.js';
3
+ import { parseOpenApiSchemaString, parseOpenApiString } from '../openapi/parseOpenApiString.js';
4
+ export type SchemaTargetType = {
5
+ type: 'schema';
6
+ } & ReturnType<typeof parseOpenApiSchemaString>;
7
+ export type OperationTargetType = {
8
+ type: 'operation';
9
+ } & ReturnType<typeof parseOpenApiString>;
10
+ export type AsyncApiTargetType = {
11
+ type: 'asyncapi';
12
+ } & ReturnType<typeof parseAsyncApiString>;
13
+ export declare const parseApiTargetFromMetadata: (metadata: PageMetaTags) => SchemaTargetType | OperationTargetType | AsyncApiTargetType | undefined;
@@ -0,0 +1,25 @@
1
+ import { parseAsyncApiString } from '../asyncapi/parseAsyncApiString.js';
2
+ import { parseOpenApiSchemaString, parseOpenApiString } from '../openapi/parseOpenApiString.js';
3
+ export const parseApiTargetFromMetadata = (metadata) => {
4
+ const openapiSchema = metadata['openapi-schema'];
5
+ if (typeof openapiSchema === 'string' && openapiSchema.length > 0) {
6
+ return Object.assign({ type: 'schema' }, parseOpenApiSchemaString(openapiSchema));
7
+ }
8
+ const openapi = metadata.openapi;
9
+ if (typeof openapi === 'string' && openapi.length > 0) {
10
+ try {
11
+ return Object.assign({ type: 'operation' }, parseOpenApiString(openapi));
12
+ }
13
+ catch (error) {
14
+ console.error(`unable to parse value "${openapi}" for field "openapi":`, error);
15
+ return undefined;
16
+ }
17
+ }
18
+ const asyncapi = metadata.asyncapi;
19
+ if (typeof asyncapi === 'string' && asyncapi.length > 0) {
20
+ const asyncApiMetadata = parseAsyncApiString(asyncapi);
21
+ return asyncApiMetadata
22
+ ? Object.assign({ type: 'asyncapi' }, asyncApiMetadata) : undefined;
23
+ }
24
+ return undefined;
25
+ };
package/dist/index.d.ts CHANGED
@@ -23,3 +23,4 @@ export * from './services/aws.js';
23
23
  export * from './slugify.js';
24
24
  export * from './services/aws.js';
25
25
  export * from './truncateAtWordBoundary.js';
26
+ export * from './api-reference/parseApiTargetFromMetadata.js';
package/dist/index.js CHANGED
@@ -23,3 +23,4 @@ export * from './services/aws.js';
23
23
  export * from './slugify.js';
24
24
  export * from './services/aws.js';
25
25
  export * from './truncateAtWordBoundary.js';
26
+ export * from './api-reference/parseApiTargetFromMetadata.js';
@@ -1,4 +1,4 @@
1
- import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, remarkVideo, } from './plugins/index.js';
1
+ import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, remarkVideo, remarkExtractMultiView, } from './plugins/index.js';
2
2
  import { remarkMdxRemoveUnknownJsx } from './plugins/remark/remarkMdxRemoveUnknownJsx/index.js';
3
3
  import { remarkMermaid } from './plugins/remark/remarkMermaid.js';
4
4
  // avoid running extractors unnecessarily
@@ -18,6 +18,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
18
18
  [remarkExtractTableOfContents, mdxExtracts, data.pageMetadata], // modifies tree so cannot be excluded
19
19
  [remarkExtractChangelogFilters, mdxExtracts],
20
20
  [remarkMdxExtractPanel, mdxExtracts],
21
+ [remarkExtractMultiView, mdxExtracts],
21
22
  remarkMdxRemoveUnusedVariables,
22
23
  remarkFrames,
23
24
  remarkRemoveImports,
@@ -15,3 +15,4 @@ export * from './remarkMdxExtractPanel.js';
15
15
  export * from './remarkValidateSteps.js';
16
16
  export * from './remarkValidateTabs.js';
17
17
  export * from './remarkVideo.js';
18
+ export * from './remarkExtractMultiView.js';
@@ -15,3 +15,4 @@ export * from './remarkMdxExtractPanel.js';
15
15
  export * from './remarkValidateSteps.js';
16
16
  export * from './remarkValidateTabs.js';
17
17
  export * from './remarkVideo.js';
18
+ export * from './remarkExtractMultiView.js';
@@ -0,0 +1,3 @@
1
+ import type { Root } from 'mdast';
2
+ import type { MdxExtracts } from '../../../types/index.js';
3
+ export declare const remarkExtractMultiView: (mdxExtracts?: MdxExtracts) => (tree: Root) => Root;
@@ -0,0 +1,76 @@
1
+ import remarkStringify from 'remark-stringify';
2
+ import { unified } from 'unified';
3
+ import { visit } from 'unist-util-visit';
4
+ import { coreRemarkMdxPlugins } from '../../remark.js';
5
+ export const remarkExtractMultiView = (mdxExtracts) => {
6
+ return (tree) => {
7
+ const multiViews = [];
8
+ const sanitizeNode = (node) => {
9
+ const sanitized = Object.assign({}, node);
10
+ if ('attributes' in sanitized && Array.isArray(sanitized.attributes)) {
11
+ sanitized.attributes = sanitized.attributes.map((attr) => {
12
+ if (attr.value != null && typeof attr.value !== 'string') {
13
+ return Object.assign(Object.assign({}, attr), { value: String(attr.value) });
14
+ }
15
+ return attr;
16
+ });
17
+ }
18
+ if ('children' in sanitized && Array.isArray(sanitized.children)) {
19
+ sanitized.children = sanitized.children.map(sanitizeNode);
20
+ }
21
+ return sanitized;
22
+ };
23
+ const stringifyNode = (node) => {
24
+ try {
25
+ return unified()
26
+ .use(coreRemarkMdxPlugins)
27
+ .use(remarkStringify)
28
+ .stringify(sanitizeNode(node));
29
+ }
30
+ catch (error) {
31
+ console.error('Error converting MDX content to markdown:', error);
32
+ return '';
33
+ }
34
+ };
35
+ const getStringValue = (attribute) => {
36
+ if (!(attribute === null || attribute === void 0 ? void 0 : attribute.value)) {
37
+ return undefined;
38
+ }
39
+ if (typeof attribute.value === 'string') {
40
+ return attribute.value;
41
+ }
42
+ if (typeof attribute.value === 'object' && 'value' in attribute.value) {
43
+ return String(attribute.value.value);
44
+ }
45
+ return undefined;
46
+ };
47
+ visit(tree, 'mdxJsxFlowElement', (node) => {
48
+ if (node.name === 'View') {
49
+ const title = getStringValue(node.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'title'));
50
+ const icon = getStringValue(node.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'icon'));
51
+ const iconType = getStringValue(node.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'iconType'));
52
+ const content = stringifyNode({
53
+ type: 'root',
54
+ children: node.children,
55
+ });
56
+ if (title) {
57
+ const viewItem = {
58
+ title,
59
+ content,
60
+ };
61
+ if (icon) {
62
+ viewItem.icon = icon;
63
+ }
64
+ if (iconType) {
65
+ viewItem.iconType = iconType;
66
+ }
67
+ multiViews.push(viewItem);
68
+ }
69
+ }
70
+ });
71
+ if (mdxExtracts && multiViews.length) {
72
+ mdxExtracts.multiViewItems = multiViews;
73
+ }
74
+ return tree;
75
+ };
76
+ };
@@ -54,6 +54,10 @@ export function getMdx(_a) {
54
54
  // so we need to restore the original mdxExtracts
55
55
  mdxExtracts = Object.assign(Object.assign({}, originalMdxExtracts), { codeExamples: mdxExtracts.codeExamples });
56
56
  }
57
+ // to avoid flash on initial load, we set the first view as active
58
+ if (mdxExtracts.multiViewItems) {
59
+ mdxExtracts.multiViewItems = mdxExtracts.multiViewItems.map((item, index) => (Object.assign(Object.assign({}, item), { active: index === 0 })));
60
+ }
57
61
  return {
58
62
  mdxExtracts,
59
63
  mdxSource,
package/dist/mdx/utils.js CHANGED
@@ -129,6 +129,7 @@ export const allowedComponents = [
129
129
  'pre',
130
130
  'ZoomImage',
131
131
  'Mermaid',
132
+ 'View',
132
133
  // Custom tags
133
134
  'zapier-zap-templates',
134
135
  ];