@conloca/mdx 0.1.13 → 0.1.15

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/README.md CHANGED
@@ -7,13 +7,16 @@ Universal MDX package for both browser and Node.js environments.
7
7
  ### Browser-safe exports (`@conloca/mdx`)
8
8
 
9
9
  - **MDXEditorModal** - Full MDX editor component with UI (for admin/CMS use)
10
- - **useMDXEvaluation** - Hook for evaluating MDX strings into React components (for rendering)
10
+ - **useMDXEvaluation** - Hook for running pre-compiled MDX code in the browser
11
+
12
+ If you are building inside `@conloca/cms-spa`, prefer `CMSMDXEditorModal` there for the integrated media-library image
13
+ picker.
11
14
 
12
15
  ### Node.js-only exports (`@conloca/mdx/node`)
13
16
 
14
17
  - **compileMDX** - Compile MDX strings to JavaScript
15
18
  - **evaluateMDXToComponent** - Evaluate MDX strings to React components (server-side)
16
- - **evaluateMDXBlocks** - High-level helper for fetching and evaluating all blocks from Content API
19
+ - **evaluateMDXBlocks** - Fetch and evaluate MDX blocks from a compatible content API
17
20
 
18
21
  ## Usage
19
22
 
@@ -31,13 +34,19 @@ import { useMDXEvaluation } from '@conloca/mdx';
31
34
 
32
35
  ```typescript
33
36
  // In Astro, Next.js, etc.
34
- import { evaluateMDXToComponent, evaluateMDXBlocks } from '@conloca/mdx/node';
37
+ import { evaluateMDXBlocks, evaluateMDXToComponent } from '@conloca/mdx/node';
35
38
  import { createContentAPI } from '@conloca/content-api/node';
36
39
 
37
40
  // Evaluate all MDX blocks for a locale
38
41
  const api = await createContentAPI({ contentRoot: './content' });
39
42
  const mdxComponents = await evaluateMDXBlocks(api, 'en');
40
43
 
44
+ for (const block of mdxComponents) {
45
+ if (!block.ok) {
46
+ console.error(`Failed to evaluate ${block.id}:`, block.error.message);
47
+ }
48
+ }
49
+
41
50
  // Or evaluate a single MDX string
42
51
  const { Component, error } = await evaluateMDXToComponent('# Hello World');
43
52
  ```
@@ -63,8 +72,11 @@ import { MDXEditorModal } from '@conloca/mdx';
63
72
  import { evaluateMDXToComponent } from '@conloca/content-api/node';
64
73
  import { evaluateMDXBlocks } from '@conloca/astro-cms/components';
65
74
 
66
- // After (all in one place)
67
- import { evaluateMDXToComponent, evaluateMDXBlocks } from '@conloca/mdx/node';
75
+ // After
76
+ import { evaluateMDXBlocks, evaluateMDXToComponent } from '@conloca/mdx/node';
77
+
78
+ // Also re-exported from Astro helpers when you are already working there
79
+ import { evaluateMDXBlocks } from '@conloca/astro-cms/components';
68
80
  ```
69
81
 
70
82
  ## Building
package/dist/index.d.mts CHANGED
@@ -1,10 +1,63 @@
1
+ import { JsxComponentDescriptor, MDXEditorMethods, MDXEditorMethods as MDXEditorMethods$1 } from "@mdxeditor/editor";
1
2
  import React from "react";
2
- import { MDXEditorMethods, MDXEditorMethods as MDXEditorMethods$1 } from "@mdxeditor/editor";
3
- import "@mdxeditor/editor/style.css";
3
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
4
4
 
5
+ //#region src/editor-core.d.ts
6
+ interface BaseMDXEditorProps {
7
+ value: string;
8
+ onChange: (value: string) => void;
9
+ onSave?: (value: string) => void;
10
+ readOnly?: boolean;
11
+ imageDialog?: React.FC | null;
12
+ disableImageSettingsButton?: boolean;
13
+ onImageShortcut?: () => void;
14
+ imageButtonRef?: React.Ref<HTMLButtonElement>;
15
+ jsxComponentDescriptors?: JsxComponentDescriptor[];
16
+ /**
17
+ * Class applied to the MDXEditor root element (library forwards it to the
18
+ * toolbar and portaled popups too). Pass `"dark-theme"` to activate the
19
+ * library's built-in Radix dark palette.
20
+ * See https://mdxeditor.dev/editor/docs/theming
21
+ */
22
+ className?: string;
23
+ }
24
+ interface BaseMDXEditorModalProps {
25
+ isOpen: boolean;
26
+ onClose: () => void;
27
+ filePath?: string;
28
+ initialContent: string;
29
+ onSave: (content: string) => void | Promise<void>;
30
+ headerExtra?: React.ReactNode;
31
+ headerTools?: (tools: {
32
+ content: string;
33
+ setContent: React.Dispatch<React.SetStateAction<string>>;
34
+ editorRef: React.RefObject<MDXEditorMethods$1 | null>;
35
+ }) => React.ReactNode;
36
+ onBeforeClose?: () => boolean;
37
+ EditorComponent: React.ForwardRefExoticComponent<BaseMDXEditorProps & React.RefAttributes<MDXEditorMethods$1>>;
38
+ /**
39
+ * Forwarded to the MDXEditor root. Typically `"dark-theme"` when the host
40
+ * app is in dark mode — see BaseMDXEditorProps.className.
41
+ */
42
+ editorClassName?: string;
43
+ }
44
+ declare const BaseMDXEditor: React.ForwardRefExoticComponent<BaseMDXEditorProps & React.RefAttributes<MDXEditorMethods$1>>;
45
+ declare function BaseMDXEditorModal({
46
+ isOpen,
47
+ onClose,
48
+ filePath,
49
+ initialContent,
50
+ onSave,
51
+ headerExtra,
52
+ headerTools,
53
+ onBeforeClose,
54
+ EditorComponent,
55
+ editorClassName
56
+ }: BaseMDXEditorModalProps): react_jsx_runtime0.JSX.Element | null;
57
+ //#endregion
5
58
  //#region src/hooks/useMDXEvaluation.d.ts
6
59
  interface UseMDXEvaluationOptions {
7
- mdxContent: string | null;
60
+ compiledCode: string | null;
8
61
  cacheKey?: string;
9
62
  }
10
63
  interface UseMDXEvaluationResult {
@@ -14,60 +67,30 @@ interface UseMDXEvaluationResult {
14
67
  retry: () => void;
15
68
  }
16
69
  /**
17
- * Hook for evaluating MDX content into React components.
70
+ * Hook for evaluating pre-compiled MDX code into React components.
18
71
  *
19
- * Features:
20
- * - Evaluates MDX strings into renderable React components using @mdx-js/mdx
21
- * - Caches compiled components to avoid re-evaluation of unchanged content
22
- * - Handles both development (jsx-dev-runtime) and production (jsx-runtime) environments
23
- * - Provides retry mechanism to clear cache and re-evaluate failed compilations
24
- * - Returns loading and error states for UI feedback
72
+ * Uses the browser-side half of a server-compile + browser-run pattern:
73
+ * 1. The server compiles MDX → JavaScript function body
74
+ * 2. The browser executes the pre-compiled code with run() (zero compiler dependencies)
25
75
  *
26
- * @param options - Configuration options
27
- * @param options.mdxContent - The MDX string to evaluate. If null, returns null component
28
- * @param options.cacheKey - Optional cache key. If not provided, uses first 100 chars of content
76
+ * This keeps the full MDX compilation pipeline on the server and only ships
77
+ * a tiny runtime helper to the browser.
29
78
  *
30
- * @returns Object containing:
31
- * - Component: The compiled React component (null if not yet compiled or error occurred)
32
- * - error: Error object if evaluation failed (null otherwise)
33
- * - isLoading: Boolean indicating if evaluation is in progress
34
- * - retry: Function to clear cache and retry evaluation
79
+ * @param options.compiledCode - The pre-compiled MDX function body. If null, returns null component
80
+ * @param options.cacheKey - Optional cache key. If not provided, uses hash of code
35
81
  *
36
- * @example
37
- * ```tsx
38
- * const { Component, error, isLoading, retry } = useMDXEvaluation({
39
- * mdxContent: '# Hello\n\nThis is **MDX** content',
40
- * cacheKey: 'my-unique-key'
41
- * });
42
- *
43
- * if (isLoading) return <Spinner />;
44
- * if (error) return <Error message={error.message} onRetry={retry} />;
45
- * if (Component) return <Component />;
46
- * ```
82
+ * @returns Object containing Component, error, isLoading, retry
47
83
  */
48
84
  declare function useMDXEvaluation({
49
- mdxContent,
85
+ compiledCode,
50
86
  cacheKey
51
87
  }: UseMDXEvaluationOptions): UseMDXEvaluationResult;
52
88
  //#endregion
53
89
  //#region src/mdx-editor.d.ts
54
- interface MDXEditorProps {
55
- value: string;
56
- onChange: (value: string) => void;
57
- onSave?: (value: string) => void;
58
- readOnly?: boolean;
59
- }
90
+ interface MDXEditorProps extends Omit<BaseMDXEditorProps, 'disableImageSettingsButton' | 'imageButtonRef' | 'imageDialog' | 'onImageShortcut'> {}
60
91
  declare const MDXEditor: React.ForwardRefExoticComponent<MDXEditorProps & React.RefAttributes<MDXEditorMethods$1>>;
61
- interface MDXEditorModalProps {
62
- isOpen: boolean;
63
- onClose: () => void;
64
- filePath?: string;
65
- initialContent: string;
66
- onSave: (content: string) => void | Promise<void>;
67
- headerExtra?: React.ReactNode;
68
- onBeforeClose?: () => boolean;
69
- }
70
- declare const MDXEditorModal: React.FC<MDXEditorModalProps>;
92
+ interface MDXEditorModalProps extends Omit<BaseMDXEditorModalProps, 'EditorComponent'> {}
93
+ declare function MDXEditorModal(props: MDXEditorModalProps): react_jsx_runtime0.JSX.Element;
71
94
  //#endregion
72
- export { MDXEditor, type MDXEditorMethods, MDXEditorModal, MDXEditorModalProps, MDXEditorProps, useMDXEvaluation };
95
+ export { BaseMDXEditor, BaseMDXEditorModal, type BaseMDXEditorModalProps, type BaseMDXEditorProps, MDXEditor, type MDXEditorMethods, MDXEditorModal, MDXEditorModalProps, MDXEditorProps, type UseMDXEvaluationOptions, type UseMDXEvaluationResult, useMDXEvaluation };
73
96
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/hooks/useMDXEvaluation.ts","../src/mdx-editor.tsx"],"mappings":";;;;;UAgDU,uBAAA;EACR,UAAA;EACA,QAAA;AAAA;AAAA,UAGQ,sBAAA;EACR,SAAA,EAAW,KAAA,CAAM,aAAA;EACjB,KAAA,EAAO,KAAA;EACP,SAAA;EACA,KAAA;AAAA;;;;;;;;;;;;;AAmCF;;;;;;;;;;;;;;;;;;;;iBAAgB,gBAAA,CAAA;EAAmB,UAAA;EAAY;AAAA,GAAY,uBAAA,GAA0B,sBAAA;;;UClBpE,cAAA;EACf,KAAA;EACA,QAAA,GAAW,KAAA;EACX,MAAA,IAAU,KAAA;EACV,QAAA;AAAA;AAAA,cAGW,SAAA,EAAS,KAAA,CAAA,yBAAA,CAAA,cAAA,GAAA,KAAA,CAAA,aAAA,CAAA,kBAAA;AAAA,UAmML,mBAAA;EACf,MAAA;EACA,OAAA;EACA,QAAA;EACA,cAAA;EACA,MAAA,GAAS,OAAA,oBAA2B,OAAA;EACpC,WAAA,GAAc,KAAA,CAAM,SAAA;EACpB,aAAA;AAAA;AAAA,cAGW,cAAA,EAAgB,KAAA,CAAM,EAAA,CAAG,mBAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/editor-core.tsx","../src/hooks/useMDXEvaluation.ts","../src/mdx-editor.tsx"],"mappings":";;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