@mintlify/common 1.0.41 → 1.0.43

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 (66) hide show
  1. package/dist/index.d.ts +3 -2
  2. package/dist/index.js +3 -2
  3. package/dist/mdx/getMDXOptions.d.ts +3 -0
  4. package/dist/mdx/getMDXOptions.js +32 -0
  5. package/dist/mdx/index.d.ts +3 -0
  6. package/dist/mdx/index.js +3 -0
  7. package/dist/mdx/lib/findExportedNode.d.ts +2 -0
  8. package/dist/mdx/lib/findExportedNode.js +30 -0
  9. package/dist/mdx/lib/index.d.ts +3 -0
  10. package/dist/mdx/lib/index.js +3 -0
  11. package/dist/mdx/lib/mdx-utils.d.ts +8 -0
  12. package/dist/mdx/lib/mdx-utils.js +8 -0
  13. package/dist/mdx/lib/remark-utils.d.ts +13 -0
  14. package/dist/mdx/lib/remark-utils.js +136 -0
  15. package/dist/mdx/plugins/index.d.ts +2 -0
  16. package/dist/mdx/plugins/index.js +2 -0
  17. package/dist/mdx/plugins/rehype/index.d.ts +8 -0
  18. package/dist/mdx/plugins/rehype/index.js +8 -0
  19. package/dist/mdx/plugins/rehype/rehypeCodeBlocks.d.ts +4 -0
  20. package/dist/mdx/plugins/rehype/rehypeCodeBlocks.js +44 -0
  21. package/dist/mdx/plugins/rehype/rehypeLayouts.d.ts +1 -0
  22. package/dist/mdx/plugins/rehype/rehypeLayouts.js +133 -0
  23. package/dist/mdx/plugins/rehype/rehypeListRoles.d.ts +1 -0
  24. package/dist/mdx/plugins/rehype/rehypeListRoles.js +10 -0
  25. package/dist/mdx/plugins/rehype/rehypeMdxExtractExamples.d.ts +2 -0
  26. package/dist/mdx/plugins/rehype/rehypeMdxExtractExamples.js +64 -0
  27. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/findParentSchema.d.ts +3 -0
  28. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/findParentSchema.js +9 -0
  29. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/index.d.ts +3 -0
  30. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/index.js +93 -0
  31. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/insertSchema.d.ts +17 -0
  32. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/insertSchema.js +83 -0
  33. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/parsers.d.ts +24 -0
  34. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/parsers.js +251 -0
  35. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/createCommentNode.d.ts +15 -0
  36. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/createCommentNode.js +20 -0
  37. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/index.d.ts +5 -0
  38. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/index.js +18 -0
  39. package/dist/mdx/plugins/rehype/rehypeRawComponents.d.ts +1 -0
  40. package/dist/mdx/plugins/rehype/rehypeRawComponents.js +12 -0
  41. package/dist/mdx/plugins/rehype/rehypeZoomImages.d.ts +2 -0
  42. package/dist/mdx/plugins/rehype/rehypeZoomImages.js +15 -0
  43. package/dist/mdx/plugins/remark/index.d.ts +7 -0
  44. package/dist/mdx/plugins/remark/index.js +7 -0
  45. package/dist/mdx/plugins/remark/remarkFrames.d.ts +1 -0
  46. package/dist/mdx/plugins/remark/remarkFrames.js +37 -0
  47. package/dist/mdx/plugins/remark/remarkMdxInjectRequire.d.ts +3 -0
  48. package/dist/mdx/plugins/remark/remarkMdxInjectRequire.js +23 -0
  49. package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.d.ts +3 -0
  50. package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.js +26 -0
  51. package/dist/mdx/plugins/remark/remarkMdxRemoveJs/index.d.ts +2 -0
  52. package/dist/mdx/plugins/remark/remarkMdxRemoveJs/index.js +20 -0
  53. package/dist/mdx/plugins/remark/remarkMdxWrapDangerouslySetInnerHtml.d.ts +2 -0
  54. package/dist/mdx/plugins/remark/remarkMdxWrapDangerouslySetInnerHtml.js +28 -0
  55. package/dist/mdx/plugins/remark/remarkRemoveImports.d.ts +2 -0
  56. package/dist/mdx/plugins/remark/remarkRemoveImports.js +11 -0
  57. package/dist/mdx/plugins/remark/remarkTableOfContents.d.ts +1 -0
  58. package/dist/mdx/plugins/remark/remarkTableOfContents.js +57 -0
  59. package/dist/topologicalSort.d.ts +4 -0
  60. package/dist/topologicalSort.js +19 -0
  61. package/dist/tsconfig.build.tsbuildinfo +1 -1
  62. package/dist/types/mdx/UserDefinedExampleData.d.ts +15 -0
  63. package/dist/types/mdx/UserDefinedExampleData.js +1 -0
  64. package/dist/types/mdx/index.d.ts +1 -0
  65. package/dist/types/mdx/index.js +1 -0
  66. package/package.json +23 -3
@@ -0,0 +1,93 @@
1
+ import { generateExampleFromSchema } from '@mintlify/validation';
2
+ import { visitParents } from 'unist-util-visit-parents';
3
+ import { isMdxJsxFlowElementHast } from '../../../lib/mdx-utils.js';
4
+ import { addExport } from '../../../lib/remark-utils.js';
5
+ import { findParentSchema } from './findParentSchema.js';
6
+ import { insertSchema } from './insertSchema.js';
7
+ import { parseApiString, parseAuthMethod, parseField } from './parsers.js';
8
+ export const rehypeMdxInjectEndpoint = (metadata, config) => {
9
+ return (tree) => {
10
+ var _a;
11
+ if (!(metadata &&
12
+ typeof metadata === 'object' &&
13
+ 'api' in metadata &&
14
+ typeof metadata.api === 'string')) {
15
+ addExport(tree, 'endpoint', undefined);
16
+ return;
17
+ }
18
+ let parseResult = undefined;
19
+ try {
20
+ parseResult = parseApiString(metadata.api, config);
21
+ }
22
+ catch (_b) {
23
+ console.error(`error parsing api string: "${metadata.api}"`);
24
+ addExport(tree, 'endpoint', undefined);
25
+ return;
26
+ }
27
+ const { servers, path, method } = parseResult;
28
+ const authMethodString = 'authMethod' in metadata && typeof metadata.authMethod === 'string'
29
+ ? metadata.authMethod
30
+ : undefined;
31
+ const security = parseAuthMethod(authMethodString, config);
32
+ const endpoint = {
33
+ path,
34
+ servers,
35
+ method,
36
+ request: {
37
+ security,
38
+ parameters: {
39
+ query: {},
40
+ header: {},
41
+ cookie: {},
42
+ path: {},
43
+ },
44
+ body: {},
45
+ },
46
+ response: {},
47
+ deprecated: false,
48
+ };
49
+ const requestContentType = 'contentType' in metadata && typeof metadata.contentType === 'string'
50
+ ? metadata.contentType
51
+ : 'application/json';
52
+ const nodeToSchema = new Map();
53
+ visitParents(tree, isMdxJsxFlowElementHast, (node, parents) => {
54
+ if (node.name === 'Param' || node.name === 'ParamField' || node.name === 'ResponseField') {
55
+ const parentSchema = findParentSchema(node.name, parents, nodeToSchema);
56
+ // we only want ParamFields/ResponseFields that are nested in others of the same type, or at the top level
57
+ if (parentSchema === undefined && parents.length > 1) {
58
+ console.error(`${node.name} tags must occur at the top level or inside another ${node.name} tag`);
59
+ return 'skip';
60
+ }
61
+ const parsedParamField = parseField(node);
62
+ if (parsedParamField === undefined) {
63
+ console.error('param field conversion failed');
64
+ return 'skip';
65
+ }
66
+ const insertSuccessful = insertSchema({
67
+ name: parsedParamField.name,
68
+ location: parsedParamField.location,
69
+ schema: parsedParamField.schema,
70
+ deepestSchema: parsedParamField.deepestSchema,
71
+ endpoint,
72
+ node,
73
+ parentSchema,
74
+ nodeToSchema,
75
+ requestContentType,
76
+ });
77
+ if (!insertSuccessful) {
78
+ return 'skip';
79
+ }
80
+ }
81
+ });
82
+ const content = endpoint.request.body[requestContentType];
83
+ if (content) {
84
+ content.examples['example'] = { value: generateExampleFromSchema(content.schemaArray[0]) };
85
+ }
86
+ const response = (_a = endpoint.response['200']) === null || _a === void 0 ? void 0 : _a['application/json'];
87
+ if (response) {
88
+ response.examples['example'] = { value: generateExampleFromSchema(response.schemaArray[0]) };
89
+ }
90
+ addExport(tree, 'endpoint', endpoint);
91
+ return tree;
92
+ };
93
+ };
@@ -0,0 +1,17 @@
1
+ import { DataSchema, Endpoint } from '@mintlify/validation';
2
+ import { MdxJsxFlowElementHast } from 'mdast-util-mdx-jsx';
3
+ import type { Node } from 'unist';
4
+ import { FieldLocation } from '../../../lib/mdx-utils.js';
5
+ type InsertSchemaParams = {
6
+ location: FieldLocation;
7
+ name: string;
8
+ node: MdxJsxFlowElementHast;
9
+ schema: DataSchema;
10
+ deepestSchema: DataSchema;
11
+ parentSchema: DataSchema | undefined;
12
+ nodeToSchema: Map<Node, DataSchema>;
13
+ endpoint: Endpoint;
14
+ requestContentType: string;
15
+ };
16
+ export declare const insertSchema: ({ location, name, node, schema, deepestSchema, parentSchema, nodeToSchema, endpoint, requestContentType, }: InsertSchemaParams) => boolean;
17
+ export {};
@@ -0,0 +1,83 @@
1
+ export const insertSchema = ({ location, name, node, schema, deepestSchema, parentSchema, nodeToSchema, endpoint, requestContentType, }) => {
2
+ var _a, _b, _c;
3
+ if (parentSchema === undefined) {
4
+ switch (location) {
5
+ case 'body':
6
+ const bodyObjectSchema = (_a = endpoint.request.body[requestContentType]) === null || _a === void 0 ? void 0 : _a.schemaArray[0];
7
+ if (bodyObjectSchema) {
8
+ bodyObjectSchema.properties[name] = [schema];
9
+ }
10
+ else {
11
+ endpoint.request.body[requestContentType] = {
12
+ schemaArray: [
13
+ {
14
+ type: 'object',
15
+ properties: {
16
+ [name]: [schema],
17
+ },
18
+ },
19
+ ],
20
+ examples: {},
21
+ };
22
+ }
23
+ break;
24
+ case 'response':
25
+ const responseObjectSchema = (_c = (_b = endpoint.response['200']) === null || _b === void 0 ? void 0 : _b['application/json']) === null || _c === void 0 ? void 0 : _c.schemaArray[0];
26
+ if (responseObjectSchema) {
27
+ responseObjectSchema.properties[name] = [schema];
28
+ }
29
+ else {
30
+ endpoint.response['200'] = {
31
+ 'application/json': {
32
+ schemaArray: [
33
+ {
34
+ type: 'object',
35
+ properties: {
36
+ [name]: [schema],
37
+ },
38
+ },
39
+ ],
40
+ examples: {},
41
+ },
42
+ };
43
+ }
44
+ break;
45
+ case 'auth':
46
+ if (!endpoint.request.security[0]) {
47
+ endpoint.request.security = [
48
+ {
49
+ title: 'Security',
50
+ parameters: {
51
+ cookie: {},
52
+ header: { [name]: { type: 'apiKey' } },
53
+ query: {},
54
+ },
55
+ },
56
+ ];
57
+ }
58
+ else {
59
+ endpoint.request.security[0].parameters.header[name] = { type: 'apiKey' };
60
+ }
61
+ break;
62
+ case 'cookie':
63
+ case 'header':
64
+ case 'path':
65
+ case 'query':
66
+ endpoint.request.parameters[location][name] = { schema: [schema] };
67
+ break;
68
+ }
69
+ }
70
+ else {
71
+ if (location === 'auth') {
72
+ console.error('complex types are not allowed in the auth section');
73
+ return false;
74
+ }
75
+ if (parentSchema.type !== 'object') {
76
+ console.error(`cannot add property "${name}" to non-object`);
77
+ return false;
78
+ }
79
+ parentSchema.properties[name] = [schema];
80
+ }
81
+ nodeToSchema.set(node, deepestSchema);
82
+ return true;
83
+ };
@@ -0,0 +1,24 @@
1
+ import { MintConfig } from '@mintlify/models';
2
+ import { DataSchema, HttpMethod, SecurityOption, Server } from '@mintlify/validation';
3
+ import { MdxJsxFlowElementHast } from 'mdast-util-mdx-jsx';
4
+ import type { FieldLocation } from '../../../lib/mdx-utils.js';
5
+ export declare const parseApiString: (apiString: string, config?: MintConfig) => {
6
+ servers?: Server[] | undefined;
7
+ path: string;
8
+ method: HttpMethod;
9
+ };
10
+ export declare const parseAuthMethod: (authMethodString: string | undefined, config?: MintConfig) => SecurityOption[];
11
+ type ParseFieldType = {
12
+ location: FieldLocation;
13
+ name: string;
14
+ schema: DataSchema;
15
+ deepestSchema: DataSchema;
16
+ };
17
+ export declare const parseField: (node: MdxJsxFlowElementHast) => ParseFieldType | undefined;
18
+ export declare const parseDescription: (node: MdxJsxFlowElementHast) => string | undefined;
19
+ type ParseTypeStringType = {
20
+ schema: DataSchema;
21
+ deepestSchema: DataSchema;
22
+ };
23
+ export declare const parseTypeString: (typeString: string) => ParseTypeStringType;
24
+ export {};
@@ -0,0 +1,251 @@
1
+ import isAbsoluteUrl from 'is-absolute-url';
2
+ import { getSecurityOptionsForAuthMethod } from '../../../../index.js';
3
+ import { isMdxJsxAttribute, isParamFieldLocation } from '../../../lib/mdx-utils.js';
4
+ export const parseApiString = (apiString, config) => {
5
+ const components = apiString.trim().split(/\s+/);
6
+ if (!components[0] || !components[1] || components.length > 2) {
7
+ throw new Error('improperly formatted api string');
8
+ }
9
+ const [upperMethod, endpointStr] = components;
10
+ const method = upperMethod.toLowerCase();
11
+ if (!['get', 'put', 'post', 'delete', 'patch', 'options', 'head', 'trace'].includes(method)) {
12
+ throw new Error('invalid http method');
13
+ }
14
+ const { origin, path } = parseEndpoint(endpointStr);
15
+ const servers = origin ? [{ url: origin }] : parseServers(config);
16
+ return {
17
+ path,
18
+ method: method,
19
+ servers,
20
+ };
21
+ };
22
+ const parseEndpoint = (endpoint) => {
23
+ if (!isAbsoluteUrl(endpoint)) {
24
+ return {
25
+ origin: undefined,
26
+ path: endpoint,
27
+ };
28
+ }
29
+ const url = new URL(endpoint);
30
+ return {
31
+ origin: decodeURI(url.origin),
32
+ path: decodeURI(url.pathname),
33
+ };
34
+ };
35
+ const parseServers = (config) => {
36
+ var _a;
37
+ const baseUrl = (_a = config === null || config === void 0 ? void 0 : config.api) === null || _a === void 0 ? void 0 : _a.baseUrl;
38
+ if (!baseUrl) {
39
+ return undefined;
40
+ }
41
+ if (typeof baseUrl === 'string') {
42
+ return [{ url: baseUrl }];
43
+ }
44
+ const servers = baseUrl.filter(Boolean).map((url) => ({ url }));
45
+ return servers.length > 0 ? servers : undefined;
46
+ };
47
+ export const parseAuthMethod = (authMethodString, config) => {
48
+ var _a, _b, _c, _d;
49
+ const method = authMethodString !== null && authMethodString !== void 0 ? authMethodString : (_b = (_a = config === null || config === void 0 ? void 0 : config.api) === null || _a === void 0 ? void 0 : _a.auth) === null || _b === void 0 ? void 0 : _b.method;
50
+ const name = (_d = (_c = config === null || config === void 0 ? void 0 : config.api) === null || _c === void 0 ? void 0 : _c.auth) === null || _d === void 0 ? void 0 : _d.name;
51
+ return getSecurityOptionsForAuthMethod(method, name);
52
+ };
53
+ export const parseField = (node) => {
54
+ let locationAndName;
55
+ let schemaInfo;
56
+ let required = undefined;
57
+ for (const { name: attrName, value } of node.attributes.filter(isMdxJsxAttribute)) {
58
+ if (node.name !== 'ResponseField' && isParamFieldLocation(attrName)) {
59
+ // if ParamField or Param, parameter name comes from the `body`, `header`, etc attribute
60
+ if (locationAndName) {
61
+ console.error('multiple location/name pairs specified');
62
+ return;
63
+ }
64
+ if (typeof value !== 'string') {
65
+ console.error(`invalid parameter name: "${value}"`);
66
+ return;
67
+ }
68
+ locationAndName = {
69
+ location: attrName,
70
+ name: value,
71
+ };
72
+ }
73
+ else if (node.name === 'ResponseField' && attrName === 'name') {
74
+ // if ResponseField, parameter name comes from the `name` attribute
75
+ if (locationAndName) {
76
+ console.error('multiple names specified');
77
+ return;
78
+ }
79
+ if (typeof value !== 'string') {
80
+ console.error(`invalid response field name: "${value}"`);
81
+ return;
82
+ }
83
+ locationAndName = {
84
+ location: 'response',
85
+ name: value,
86
+ };
87
+ }
88
+ else if (attrName === 'type') {
89
+ if (typeof value !== 'string') {
90
+ console.error(`invalid type string: "${value}"`);
91
+ return;
92
+ }
93
+ schemaInfo = parseTypeString(value);
94
+ }
95
+ else if (attrName === 'required') {
96
+ if (value === null || (typeof value === 'object' && value.value.trim() === 'true')) {
97
+ required = true;
98
+ }
99
+ }
100
+ }
101
+ if (locationAndName === undefined) {
102
+ console.error('no parameter name specified');
103
+ return;
104
+ }
105
+ if (schemaInfo === undefined) {
106
+ console.error(`no type specified for parameter "${locationAndName.name}"`);
107
+ return;
108
+ }
109
+ schemaInfo.schema.description = parseDescription(node);
110
+ schemaInfo.schema.required = required;
111
+ return Object.assign(Object.assign({}, locationAndName), schemaInfo);
112
+ };
113
+ export const parseDescription = (node) => {
114
+ const descriptionFragments = node.children.flatMap((child) => {
115
+ var _a;
116
+ if (child.type === 'text') {
117
+ return [child.value];
118
+ }
119
+ else if (child.type === 'element' &&
120
+ child.tagName === 'p' &&
121
+ ((_a = child.children[0]) === null || _a === void 0 ? void 0 : _a.type) === 'text') {
122
+ return [child.children[0].value];
123
+ }
124
+ return [];
125
+ });
126
+ return descriptionFragments.length > 0 ? descriptionFragments.join('\n') : undefined;
127
+ };
128
+ const typeStringToSchemaType = {
129
+ // string
130
+ str: 'string',
131
+ string: 'string',
132
+ date: 'string',
133
+ text: 'string',
134
+ url: 'string',
135
+ uuid: 'string',
136
+ hash: 'string',
137
+ bytes: 'string',
138
+ // integer
139
+ int: 'integer',
140
+ integer: 'integer',
141
+ // number
142
+ num: 'number',
143
+ number: 'number',
144
+ float: 'number',
145
+ decimal: 'number',
146
+ long: 'number',
147
+ double: 'number',
148
+ // boolean
149
+ bool: 'boolean',
150
+ boolean: 'boolean',
151
+ // object
152
+ obj: 'object',
153
+ object: 'object',
154
+ record: 'object',
155
+ dict: 'object',
156
+ dictionary: 'object',
157
+ map: 'object',
158
+ // array
159
+ arr: 'array',
160
+ array: 'array',
161
+ list: 'array',
162
+ // file
163
+ file: 'file',
164
+ // any
165
+ any: 'any',
166
+ json: 'any',
167
+ // null
168
+ null: 'null',
169
+ };
170
+ const genericStringRegex = /^(\w+)<(.*)>$/;
171
+ export const parseTypeString = (typeString) => {
172
+ const lowerTypeString = typeString.toLowerCase();
173
+ const simpleSchemaType = typeStringToSchemaType[lowerTypeString];
174
+ // catch all standard type strings
175
+ if (simpleSchemaType) {
176
+ return generateSchemaWithTypeString(simpleSchemaType);
177
+ }
178
+ // catch type strings that end with []
179
+ if (lowerTypeString.endsWith('[]')) {
180
+ // recursively determine the type of the rest of the string
181
+ const subschemaInfo = parseTypeString(lowerTypeString.slice(0, lowerTypeString.length - 2));
182
+ return {
183
+ schema: {
184
+ type: 'array',
185
+ items: [subschemaInfo.schema],
186
+ },
187
+ deepestSchema: subschemaInfo.deepestSchema,
188
+ };
189
+ }
190
+ // catch type strings like foo<bar>
191
+ const regexMatch = genericStringRegex.exec(lowerTypeString);
192
+ if (regexMatch !== null) {
193
+ // unpack capture group 1 (foo) and 2 (bar)
194
+ const [_, superType, subType] = regexMatch;
195
+ if (superType && subType && typeStringToSchemaType[superType] === 'array') {
196
+ // catches type strings like array<bar>
197
+ // recursively determine the type of everything within the angle brackets
198
+ const subschemaInfo = parseTypeString(subType);
199
+ return {
200
+ schema: {
201
+ type: 'array',
202
+ items: [subschemaInfo.schema],
203
+ },
204
+ deepestSchema: subschemaInfo.deepestSchema,
205
+ };
206
+ }
207
+ }
208
+ // for any unrecognized typestring, default to object
209
+ return generateSchemaWithTypeString('object');
210
+ };
211
+ const generateSchemaWithTypeString = (type) => {
212
+ switch (type) {
213
+ case 'string':
214
+ case 'number':
215
+ case 'integer':
216
+ case 'boolean':
217
+ case 'file':
218
+ case 'null':
219
+ case 'any': {
220
+ const schema = { type };
221
+ return {
222
+ schema,
223
+ deepestSchema: schema,
224
+ };
225
+ }
226
+ case 'object': {
227
+ const schema = {
228
+ type: 'object',
229
+ properties: {},
230
+ };
231
+ return {
232
+ schema,
233
+ deepestSchema: schema,
234
+ };
235
+ }
236
+ case 'array': {
237
+ const itemsSchema = {
238
+ type: 'object',
239
+ properties: {},
240
+ };
241
+ const schema = {
242
+ type: 'array',
243
+ items: [itemsSchema],
244
+ };
245
+ return {
246
+ schema,
247
+ deepestSchema: itemsSchema,
248
+ };
249
+ }
250
+ }
251
+ };
@@ -0,0 +1,15 @@
1
+ export declare const createCommentNode: (componentName: string) => {
2
+ type: string;
3
+ value: string;
4
+ data: {
5
+ estree: {
6
+ type: string;
7
+ body: never[];
8
+ comments: {
9
+ type: string;
10
+ value: string;
11
+ }[];
12
+ sourceType: string;
13
+ };
14
+ };
15
+ };
@@ -0,0 +1,20 @@
1
+ export const createCommentNode = (componentName) => {
2
+ const comment = ` Component ${componentName} does not exist. `;
3
+ return {
4
+ type: 'mdxFlowExpression',
5
+ value: `/* ${comment} */`,
6
+ data: {
7
+ estree: {
8
+ type: 'Program',
9
+ body: [],
10
+ comments: [
11
+ {
12
+ type: 'Block',
13
+ value: comment,
14
+ },
15
+ ],
16
+ sourceType: 'module',
17
+ },
18
+ },
19
+ };
20
+ };
@@ -0,0 +1,5 @@
1
+ import type { Node } from 'unist';
2
+ declare const rehypeMdxRemoveUnknownJsx: (options: {
3
+ allowedComponents?: string[];
4
+ }) => (tree: Node) => Node<import("unist").Data>;
5
+ export default rehypeMdxRemoveUnknownJsx;
@@ -0,0 +1,18 @@
1
+ import { map } from 'unist-util-map';
2
+ import { findExportedNodes, isMdxJsxFlowElementHast } from '../../../lib/index.js';
3
+ import { createCommentNode } from './createCommentNode.js';
4
+ const rehypeMdxRemoveUnknownJsx = (options) => (tree) => {
5
+ const exportedComponentNames = findExportedNodes(tree, 'ArrowFunctionExpression');
6
+ return map(tree, (node) => {
7
+ var _a;
8
+ if (isMdxJsxFlowElementHast(node)) {
9
+ if (node.name &&
10
+ !((_a = options.allowedComponents) === null || _a === void 0 ? void 0 : _a.includes(node.name)) &&
11
+ !exportedComponentNames.includes(node.name)) {
12
+ return createCommentNode(node.name);
13
+ }
14
+ }
15
+ return node;
16
+ });
17
+ };
18
+ export default rehypeMdxRemoveUnknownJsx;
@@ -0,0 +1 @@
1
+ export function rehypeRawComponents(): (tree: any) => void;
@@ -0,0 +1,12 @@
1
+ import { fromHtml } from 'hast-util-from-html';
2
+ import { visit } from 'unist-util-visit';
3
+ export const rehypeRawComponents = () => {
4
+ return (tree) => {
5
+ visit(tree, 'raw', (raw, i, parent) => {
6
+ const rawAst = fromHtml(raw.value, { fragment: true });
7
+ if (parent && i) {
8
+ parent.children[i] = rawAst;
9
+ }
10
+ });
11
+ };
12
+ };
@@ -0,0 +1,2 @@
1
+ import { Node } from 'unist';
2
+ export declare const rehypeZoomImages: () => <T extends Node<import("unist").Data>>(tree: T) => void;
@@ -0,0 +1,15 @@
1
+ import { u } from 'unist-builder';
2
+ import { visit } from 'unist-util-visit';
3
+ export const rehypeZoomImages = () => (tree) => {
4
+ visit(tree, 'mdxJsxFlowElement', (node, index, parent) => {
5
+ const element = node;
6
+ if (element.name === 'img' || element.name === 'picture' || element.name === 'figure') {
7
+ const noZoom = element.attributes.find((attr) => 'name' in attr && attr.name === 'noZoom');
8
+ if (!noZoom && parent && index != null) {
9
+ parent.children.splice(index, 1, u('element', {
10
+ tagName: 'ZoomImage',
11
+ }, [node]));
12
+ }
13
+ }
14
+ });
15
+ };
@@ -0,0 +1,7 @@
1
+ export * from './remarkMdxInjectRequire.js';
2
+ export * from './remarkMdxInjectSnippets.js';
3
+ export * from './remarkMdxWrapDangerouslySetInnerHtml.js';
4
+ export * from './remarkFrames.js';
5
+ export * from './remarkRemoveImports.js';
6
+ export * from './remarkTableOfContents.js';
7
+ export * from './remarkMdxRemoveJs/index.js';
@@ -0,0 +1,7 @@
1
+ export * from './remarkMdxInjectRequire.js';
2
+ export * from './remarkMdxInjectSnippets.js';
3
+ export * from './remarkMdxWrapDangerouslySetInnerHtml.js';
4
+ export * from './remarkFrames.js';
5
+ export * from './remarkRemoveImports.js';
6
+ export * from './remarkTableOfContents.js';
7
+ export * from './remarkMdxRemoveJs/index.js';
@@ -0,0 +1 @@
1
+ export function remarkFrames(): (tree: any) => void;
@@ -0,0 +1,37 @@
1
+ import { toMdxJsxFlowElement } from '../../lib/remark-utils.js';
2
+ export const remarkFrames = () => {
3
+ return (tree) => {
4
+ let preTree = { children: [] };
5
+ 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
+ if (node.type === 'mdxJsxFlowElement' && (node.name === 'Example' || node.name === 'Frame')) {
28
+ node.name = 'Frame';
29
+ }
30
+ if (node.type === 'jsx') {
31
+ node = toMdxJsxFlowElement(node.value);
32
+ }
33
+ return node;
34
+ });
35
+ tree.children = [...preTree.children, ...tree.children];
36
+ };
37
+ };
@@ -0,0 +1,3 @@
1
+ import type { MdxJsxFlowElement } from 'mdast-util-mdx';
2
+ import type { Parent } from 'unist';
3
+ export declare const remarkMdxInjectRequire: (subdomain: string) => (tree: Parent<MdxJsxFlowElement>) => void;
@@ -0,0 +1,23 @@
1
+ // TODO - this is a hack to inject requirejs into the docs to generate Nixtla's graphs.
2
+ // Create a more sustainable solution for this.
3
+ export const remarkMdxInjectRequire = (subdomain) => {
4
+ return (tree) => {
5
+ if (subdomain === 'nixtla-docs' || subdomain === 'nixtla') {
6
+ tree.children.push({
7
+ type: 'mdxJsxFlowElement',
8
+ name: 'script',
9
+ children: [],
10
+ data: {
11
+ _mdxExplicitJsx: true,
12
+ },
13
+ attributes: [
14
+ {
15
+ type: 'mdxJsxAttribute',
16
+ name: 'src',
17
+ value: 'https://requirejs.org/docs/release/2.3.6/minified/require.js',
18
+ },
19
+ ],
20
+ });
21
+ }
22
+ };
23
+ };
@@ -0,0 +1,3 @@
1
+ import { Parent } from 'unist';
2
+ import { VFile } from 'vfile';
3
+ export declare const remarkMdxInjectSnippets: <T extends Parent<import("unist").Node<import("unist").Data>, import("unist").Data>>(snippetTreeMap: Record<string, T>) => (tree: Parent, file: VFile) => void;