@conloca/mdx 0.1.1 → 0.1.2
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.
- package/package.json +1 -1
- package/dist/blocks.d.ts +0 -37
- package/dist/blocks.d.ts.map +0 -1
- package/dist/hooks/useMDXEvaluation.d.ts +0 -46
- package/dist/hooks/useMDXEvaluation.d.ts.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/mdx/compile.d.ts +0 -37
- package/dist/mdx/compile.d.ts.map +0 -1
- package/dist/mdx/evaluate.d.ts +0 -44
- package/dist/mdx/evaluate.d.ts.map +0 -1
- package/dist/mdx-editor.d.ts +0 -21
- package/dist/mdx-editor.d.ts.map +0 -1
- package/dist/node.d.ts +0 -17
- package/dist/node.d.ts.map +0 -1
- package/dist/types.d.ts +0 -12
- package/dist/types.d.ts.map +0 -1
package/package.json
CHANGED
package/dist/blocks.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { ContentAPI } from '@conloca/content-api';
|
|
2
|
-
import type { ComponentType } from 'react';
|
|
3
|
-
/**
|
|
4
|
-
* Evaluate all MDX blocks from Content API into React components.
|
|
5
|
-
*
|
|
6
|
-
* High-level helper function for Astro pages that handles:
|
|
7
|
-
* - Fetching all blocks from Content API
|
|
8
|
-
* - Evaluating MDX content to React components
|
|
9
|
-
* - Error handling with fallback error components
|
|
10
|
-
* - Empty content handling with fallback components
|
|
11
|
-
*
|
|
12
|
-
* Returns data in the format expected by `createPageRendererWithBlocks`.
|
|
13
|
-
*
|
|
14
|
-
* @param api - ContentAPI instance
|
|
15
|
-
* @param locale - Locale code to fetch (e.g., 'en', 'es')
|
|
16
|
-
* @returns Array of blocks with evaluated React components
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```astro
|
|
20
|
-
* ---
|
|
21
|
-
* import { createPageRendererWithBlocks } from '@conloca/astro-cms/components';
|
|
22
|
-
* import { createContentAPI } from '@conloca/content-api/node';
|
|
23
|
-
* import config from '../puck.config';
|
|
24
|
-
*
|
|
25
|
-
* const api = await createContentAPI({ contentRoot: './content' });
|
|
26
|
-
* const mdxComponents = await evaluateMDXBlocks(api, 'en');
|
|
27
|
-
* const PageRenderer = createPageRendererWithBlocks(config, puckData, mdxComponents);
|
|
28
|
-
* ---
|
|
29
|
-
* <PageRenderer />
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export declare function evaluateMDXBlocks(api: ContentAPI, locale: string): Promise<Array<{
|
|
33
|
-
id: string;
|
|
34
|
-
title: string;
|
|
35
|
-
Component: ComponentType;
|
|
36
|
-
}>>;
|
|
37
|
-
//# sourceMappingURL=blocks.d.ts.map
|
package/dist/blocks.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAmB,MAAM,sBAAsB,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,UAAU,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CACR,KAAK,CAAC;IACJ,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,aAAa,CAAC;CAC1B,CAAC,CACH,CAiFA"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
interface UseMDXEvaluationOptions {
|
|
3
|
-
mdxContent: string | null;
|
|
4
|
-
cacheKey?: string;
|
|
5
|
-
}
|
|
6
|
-
interface UseMDXEvaluationResult {
|
|
7
|
-
Component: React.ComponentType | null;
|
|
8
|
-
error: Error | null;
|
|
9
|
-
isLoading: boolean;
|
|
10
|
-
retry: () => void;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Hook for evaluating MDX content into React components.
|
|
14
|
-
*
|
|
15
|
-
* Features:
|
|
16
|
-
* - Evaluates MDX strings into renderable React components using @mdx-js/mdx
|
|
17
|
-
* - Caches compiled components to avoid re-evaluation of unchanged content
|
|
18
|
-
* - Handles both development (jsx-dev-runtime) and production (jsx-runtime) environments
|
|
19
|
-
* - Provides retry mechanism to clear cache and re-evaluate failed compilations
|
|
20
|
-
* - Returns loading and error states for UI feedback
|
|
21
|
-
*
|
|
22
|
-
* @param options - Configuration options
|
|
23
|
-
* @param options.mdxContent - The MDX string to evaluate. If null, returns null component
|
|
24
|
-
* @param options.cacheKey - Optional cache key. If not provided, uses first 100 chars of content
|
|
25
|
-
*
|
|
26
|
-
* @returns Object containing:
|
|
27
|
-
* - Component: The compiled React component (null if not yet compiled or error occurred)
|
|
28
|
-
* - error: Error object if evaluation failed (null otherwise)
|
|
29
|
-
* - isLoading: Boolean indicating if evaluation is in progress
|
|
30
|
-
* - retry: Function to clear cache and retry evaluation
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```tsx
|
|
34
|
-
* const { Component, error, isLoading, retry } = useMDXEvaluation({
|
|
35
|
-
* mdxContent: '# Hello\n\nThis is **MDX** content',
|
|
36
|
-
* cacheKey: 'my-unique-key'
|
|
37
|
-
* });
|
|
38
|
-
*
|
|
39
|
-
* if (isLoading) return <Spinner />;
|
|
40
|
-
* if (error) return <Error message={error.message} onRetry={retry} />;
|
|
41
|
-
* if (Component) return <Component />;
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export declare function useMDXEvaluation({ mdxContent, cacheKey }: UseMDXEvaluationOptions): UseMDXEvaluationResult;
|
|
45
|
-
export {};
|
|
46
|
-
//# sourceMappingURL=useMDXEvaluation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMDXEvaluation.d.ts","sourceRoot":"","sources":["../../src/hooks/useMDXEvaluation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA+C/B,UAAU,uBAAuB;IAC/B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,sBAAsB;IAC9B,SAAS,EAAE,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC;IACtC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,uBAAuB,GAAG,sBAAsB,CA0D1G"}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,cAAc,iBAAiB,CAAC"}
|
package/dist/mdx/compile.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { MDXCompileResult, MDXCompiler } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Compile MDX content to executable JavaScript
|
|
4
|
-
*
|
|
5
|
-
* We use BOTH gray-matter and remark-frontmatter plugins:
|
|
6
|
-
* 1. gray-matter extracts frontmatter data for returning as separate metadata
|
|
7
|
-
* 2. remark-frontmatter + remark-mdx-frontmatter allow using frontmatter values as {variables} in MDX
|
|
8
|
-
*
|
|
9
|
-
* This dual approach gives us:
|
|
10
|
-
* - Separate metadata object for the API response
|
|
11
|
-
* - Ability to use frontmatter variables like {title} directly in MDX content
|
|
12
|
-
*
|
|
13
|
-
* @param content - MDX content string (may include frontmatter)
|
|
14
|
-
* @param components - Component scope to inject
|
|
15
|
-
* @returns Compiled code and extracted metadata
|
|
16
|
-
*/
|
|
17
|
-
export declare function compileMDX(content: string, components: Record<string, any>): Promise<MDXCompileResult>;
|
|
18
|
-
/**
|
|
19
|
-
* Create an MDX compiler with a fixed component scope
|
|
20
|
-
*
|
|
21
|
-
* @param componentScope - Components available to all MDX files
|
|
22
|
-
* @returns Compiler instance
|
|
23
|
-
*/
|
|
24
|
-
export declare function createMDXCompiler(componentScope: Record<string, any>): MDXCompiler;
|
|
25
|
-
/**
|
|
26
|
-
* Default component scope for MDX files in the CMS
|
|
27
|
-
* This can be extended with project-specific components
|
|
28
|
-
*/
|
|
29
|
-
export declare const defaultMDXComponents: {};
|
|
30
|
-
/**
|
|
31
|
-
* Create a component scope by merging defaults with custom components
|
|
32
|
-
*
|
|
33
|
-
* @param customComponents - Project-specific components
|
|
34
|
-
* @returns Merged component scope
|
|
35
|
-
*/
|
|
36
|
-
export declare function createComponentScope(customComponents?: Record<string, any>): {};
|
|
37
|
-
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/mdx/compile.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEjE;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAgC5G;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,WAAW,CAkBlF;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,IAOhC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,gBAAgB,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,MAK9E"}
|
package/dist/mdx/evaluate.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { ComponentType } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Evaluate MDX content string to a React component.
|
|
4
|
-
*
|
|
5
|
-
* This is a framework-agnostic utility for converting MDX strings into
|
|
6
|
-
* executable React components. Works in any Node.js environment (Astro,
|
|
7
|
-
* Next.js, Remix, etc.) at build time or server-side.
|
|
8
|
-
*
|
|
9
|
-
* **When to use:**
|
|
10
|
-
* - Building static sites with MDX content
|
|
11
|
-
* - Server-side rendering MDX as React components
|
|
12
|
-
* - Need React components (not HTML strings)
|
|
13
|
-
*
|
|
14
|
-
* @param mdxContent - The MDX string to evaluate
|
|
15
|
-
* @param options - Optional configuration
|
|
16
|
-
* @param options.development - Whether to use development mode (default: false)
|
|
17
|
-
* @returns Object containing Component (or null) and optional error
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { evaluateMDXToComponent } from '@conloca/mdx/node';
|
|
22
|
-
*
|
|
23
|
-
* const { Component, error } = await evaluateMDXToComponent('# Hello\n\nThis is **MDX**');
|
|
24
|
-
* if (error) {
|
|
25
|
-
* console.error('Failed to evaluate:', error);
|
|
26
|
-
* } else if (Component) {
|
|
27
|
-
* // Render <Component /> in your React app
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* // In Astro pages
|
|
34
|
-
* const { Component } = await evaluateMDXToComponent(mdxContent);
|
|
35
|
-
* // Then render in JSX: <Component />
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare function evaluateMDXToComponent(mdxContent: string, options?: {
|
|
39
|
-
development?: boolean;
|
|
40
|
-
}): Promise<{
|
|
41
|
-
Component: ComponentType | null;
|
|
42
|
-
error?: Error;
|
|
43
|
-
}>;
|
|
44
|
-
//# sourceMappingURL=evaluate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/mdx/evaluate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAM3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,GAClC,OAAO,CAAC;IAAE,SAAS,EAAE,aAAa,GAAG,IAAI,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC,CAgB7D"}
|
package/dist/mdx-editor.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type MDXEditorMethods } from '@mdxeditor/editor';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import '@mdxeditor/editor/style.css';
|
|
4
|
-
export interface MDXEditorProps {
|
|
5
|
-
value: string;
|
|
6
|
-
onChange: (value: string) => void;
|
|
7
|
-
onSave?: (value: string) => void;
|
|
8
|
-
readOnly?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare const MDXEditor: React.ForwardRefExoticComponent<MDXEditorProps & React.RefAttributes<MDXEditorMethods>>;
|
|
11
|
-
export interface MDXEditorModalProps {
|
|
12
|
-
isOpen: boolean;
|
|
13
|
-
onClose: () => void;
|
|
14
|
-
filePath?: string;
|
|
15
|
-
initialContent: string;
|
|
16
|
-
onSave: (content: string) => void | Promise<void>;
|
|
17
|
-
headerExtra?: React.ReactNode;
|
|
18
|
-
onBeforeClose?: () => boolean;
|
|
19
|
-
}
|
|
20
|
-
export declare const MDXEditorModal: React.FC<MDXEditorModalProps>;
|
|
21
|
-
//# sourceMappingURL=mdx-editor.d.ts.map
|
package/dist/mdx-editor.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mdx-editor.d.ts","sourceRoot":"","sources":["../src/mdx-editor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAqBL,KAAK,gBAAgB,EAQtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,6BAA6B,CAAC;AA2CrC,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,eAAO,MAAM,SAAS,yFA+ErB,CAAC;AAoHF,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC;CAC/B;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAuGxD,CAAC"}
|
package/dist/node.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node.js-specific exports for @conloca/mdx
|
|
3
|
-
*
|
|
4
|
-
* These exports require Node.js runtime APIs and should not be imported in browser environments.
|
|
5
|
-
* Import from '@conloca/mdx/node' for server-side MDX operations.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // Server-side code (Astro, Next.js, etc.)
|
|
10
|
-
* import { evaluateMDXToComponent, evaluateMDXBlocks } from '@conloca/mdx/node';
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export { evaluateMDXBlocks } from './blocks.js';
|
|
14
|
-
export { compileMDX, createComponentScope, createMDXCompiler } from './mdx/compile.js';
|
|
15
|
-
export { evaluateMDXToComponent } from './mdx/evaluate.js';
|
|
16
|
-
export type { MDXCompileResult, MDXCompiler } from './types.js';
|
|
17
|
-
//# sourceMappingURL=node.d.ts.map
|
package/dist/node.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MDX compilation types
|
|
3
|
-
*/
|
|
4
|
-
export interface MDXCompileResult {
|
|
5
|
-
code: string;
|
|
6
|
-
metadata: Record<string, any>;
|
|
7
|
-
}
|
|
8
|
-
export interface MDXCompiler {
|
|
9
|
-
compile: (content: string) => Promise<MDXCompileResult>;
|
|
10
|
-
compileFile: (filePath: string) => Promise<MDXCompileResult>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACxD,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC9D"}
|