@conloca/mdx 0.1.15 → 0.1.16
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 +15 -5
- package/dist/blocks.d.ts +37 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +51 -0
- package/dist/code-block-frame.d.ts +41 -0
- package/dist/code-block-frame.d.ts.map +1 -0
- package/dist/code-block-frame.js +186 -0
- package/dist/editor-core.d.ts +58 -0
- package/dist/editor-core.d.ts.map +1 -0
- package/dist/editor-core.js +181 -0
- package/dist/hooks/useMDXEvaluation.d.ts +28 -0
- package/dist/hooks/useMDXEvaluation.d.ts.map +1 -0
- package/dist/hooks/useMDXEvaluation.js +117 -0
- package/dist/index.d.mts +74 -43
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.mjs +328 -237
- package/dist/index.mjs.map +1 -1
- package/dist/markdown-options.d.ts +3 -0
- package/dist/markdown-options.d.ts.map +1 -0
- package/dist/markdown-options.js +19 -0
- package/dist/mdx/compile.d.ts +3 -0
- package/dist/mdx/compile.d.ts.map +1 -0
- package/dist/mdx/compile.js +27 -0
- package/dist/mdx/evaluate.d.ts +44 -0
- package/dist/mdx/evaluate.d.ts.map +1 -0
- package/dist/mdx/evaluate.js +57 -0
- package/dist/mdx-editor.d.ts +7 -0
- package/dist/mdx-editor.d.ts.map +1 -0
- package/dist/mdx-editor.js +7 -0
- package/dist/node.d.mts +0 -5
- package/dist/node.d.mts.map +1 -1
- package/dist/node.d.ts +17 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +16 -0
- package/dist/node.mjs +26 -11
- package/dist/node.mjs.map +1 -1
- package/dist/style.css +88 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +54 -15
package/README.md
CHANGED
|
@@ -6,12 +6,18 @@ Universal MDX package for both browser and Node.js environments.
|
|
|
6
6
|
|
|
7
7
|
### Browser-safe exports (`@conloca/mdx`)
|
|
8
8
|
|
|
9
|
-
- **
|
|
9
|
+
- **MDXEditor** - Embeddable MDX editor component (the page-route editor in the CMS SPA uses this directly)
|
|
10
|
+
- **BaseMDXEditor** - Lower-level editor primitive that accepts the image-dialog hook used by the CMS SPA's
|
|
11
|
+
media-library integration
|
|
10
12
|
- **useMDXEvaluation** - Hook for running pre-compiled MDX code in the browser
|
|
11
13
|
|
|
12
|
-
If you are building inside `@conloca/cms-spa`, prefer `
|
|
14
|
+
If you are building inside `@conloca/cms-spa`, prefer `CMSMDXEditor` there for the integrated media-library image
|
|
13
15
|
picker.
|
|
14
16
|
|
|
17
|
+
> **Note:** The legacy `MDXEditorModal` / `BaseMDXEditorModal` exports were removed when the CMS SPA standardized on the
|
|
18
|
+
> page-route editor (`/blocks/:id`, `/pages/:id`). Mount `MDXEditor` directly inside your own layout instead of nesting
|
|
19
|
+
> it in a fullscreen modal.
|
|
20
|
+
|
|
15
21
|
### Node.js-only exports (`@conloca/mdx/node`)
|
|
16
22
|
|
|
17
23
|
- **compileMDX** - Compile MDX strings to JavaScript
|
|
@@ -24,7 +30,7 @@ picker.
|
|
|
24
30
|
|
|
25
31
|
```typescript
|
|
26
32
|
// In admin/CMS interface
|
|
27
|
-
import {
|
|
33
|
+
import { MDXEditor } from '@conloca/mdx';
|
|
28
34
|
|
|
29
35
|
// For rendering MDX content
|
|
30
36
|
import { useMDXEvaluation } from '@conloca/mdx';
|
|
@@ -61,10 +67,14 @@ This package was renamed from `@conloca/mdx-client` to `@conloca/mdx` and consol
|
|
|
61
67
|
// Before
|
|
62
68
|
import { MDXEditorModal } from '@conloca/mdx-client';
|
|
63
69
|
|
|
64
|
-
// After
|
|
65
|
-
|
|
70
|
+
// After — mount the editor inline (the fullscreen-modal variant was removed
|
|
71
|
+
// when the CMS standardized on page-route editing at `/blocks/:id` / `/pages/:id`).
|
|
72
|
+
import { MDXEditor } from '@conloca/mdx';
|
|
66
73
|
```
|
|
67
74
|
|
|
75
|
+
The new `MDXEditor` is a component, not a modal — host it inside your own page layout (header, toolbar, save button) and
|
|
76
|
+
pass `value` / `onChange` directly. See the **Browser: MDX Editor** usage example above for the shape.
|
|
77
|
+
|
|
68
78
|
**Server-side functions moved here:**
|
|
69
79
|
|
|
70
80
|
```typescript
|
package/dist/blocks.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { MDXBlockEvaluationResult } from './types.js';
|
|
2
|
+
interface BlockLocaleSummary {
|
|
3
|
+
meta?: {
|
|
4
|
+
title?: string;
|
|
5
|
+
};
|
|
6
|
+
name?: string;
|
|
7
|
+
}
|
|
8
|
+
interface BlockManifest {
|
|
9
|
+
id: string;
|
|
10
|
+
locales: Record<string, BlockLocaleSummary | undefined>;
|
|
11
|
+
}
|
|
12
|
+
interface BlockLocalizedEntry {
|
|
13
|
+
localized?: {
|
|
14
|
+
meta?: {
|
|
15
|
+
title?: string;
|
|
16
|
+
};
|
|
17
|
+
name?: string;
|
|
18
|
+
content?: {
|
|
19
|
+
mdx?: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
interface BlockAPI {
|
|
24
|
+
listAllContent(filters: {
|
|
25
|
+
kind: 'block';
|
|
26
|
+
}): Iterable<BlockManifest>;
|
|
27
|
+
getLocalized(id: string, locale: string): Promise<BlockLocalizedEntry | null>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Evaluate all MDX blocks from a compatible content API.
|
|
31
|
+
*
|
|
32
|
+
* Returns structured success/error results so callers can decide how to
|
|
33
|
+
* surface broken blocks instead of hardcoding fallback UI in this package.
|
|
34
|
+
*/
|
|
35
|
+
export declare function evaluateMDXBlocks(api: BlockAPI, locale: string): Promise<MDXBlockEvaluationResult[]>;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=blocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE3D,UAAU,kBAAkB;IAC1B,IAAI,CAAC,EAAE;QACL,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,UAAU,aAAa;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,CAAC,CAAC;CACzD;AAED,UAAU,mBAAmB;IAC3B,SAAS,CAAC,EAAE;QACV,IAAI,CAAC,EAAE;YACL,KAAK,CAAC,EAAE,MAAM,CAAC;SAChB,CAAC;QACF,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE;YACR,GAAG,CAAC,EAAE,MAAM,CAAC;SACd,CAAC;KACH,CAAC;CACH;AAED,UAAU,QAAQ;IAChB,cAAc,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,CAAC;IACpE,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;CAC/E;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAkD1G"}
|
package/dist/blocks.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { evaluateMDXToComponent } from './mdx/evaluate.js';
|
|
2
|
+
/**
|
|
3
|
+
* Evaluate all MDX blocks from a compatible content API.
|
|
4
|
+
*
|
|
5
|
+
* Returns structured success/error results so callers can decide how to
|
|
6
|
+
* surface broken blocks instead of hardcoding fallback UI in this package.
|
|
7
|
+
*/
|
|
8
|
+
export async function evaluateMDXBlocks(api, locale) {
|
|
9
|
+
const blocks = Array.from(api.listAllContent({ kind: 'block' }));
|
|
10
|
+
return Promise.all(blocks.map(async (block) => {
|
|
11
|
+
const locales = Object.keys(block.locales);
|
|
12
|
+
const firstLocale = locales.length > 0 ? block.locales[locales[0]] : null;
|
|
13
|
+
const manifestTitle = firstLocale?.meta?.title || firstLocale?.name || block.id;
|
|
14
|
+
try {
|
|
15
|
+
const blockLocalized = await api.getLocalized(block.id, locale);
|
|
16
|
+
const blockTitle = blockLocalized?.localized?.meta?.title || blockLocalized?.localized?.name || manifestTitle;
|
|
17
|
+
const mdxContent = blockLocalized?.localized?.content?.mdx;
|
|
18
|
+
if (!mdxContent) {
|
|
19
|
+
return {
|
|
20
|
+
ok: false,
|
|
21
|
+
id: block.id,
|
|
22
|
+
title: blockTitle,
|
|
23
|
+
error: new Error(`No MDX content found for block: ${block.id}`),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const { Component: EvaluatedComponent, error } = await evaluateMDXToComponent(mdxContent);
|
|
27
|
+
if (error || !EvaluatedComponent) {
|
|
28
|
+
return {
|
|
29
|
+
ok: false,
|
|
30
|
+
id: block.id,
|
|
31
|
+
title: blockTitle,
|
|
32
|
+
error: error || new Error(`MDX evaluation failed for block: ${block.id}`),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
ok: true,
|
|
37
|
+
id: block.id,
|
|
38
|
+
title: blockTitle,
|
|
39
|
+
Component: EvaluatedComponent,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return {
|
|
44
|
+
ok: false,
|
|
45
|
+
id: block.id,
|
|
46
|
+
title: manifestTitle,
|
|
47
|
+
error: error instanceof Error ? error : new Error(`Failed to evaluate block: ${block.id}`),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type CodeBlockEditorDescriptor } from '@mdxeditor/editor';
|
|
2
|
+
/**
|
|
3
|
+
* Frame chrome around the editor's fenced code blocks — header bar with
|
|
4
|
+
* filename, language tag, and a copy button. The outer wrapper picks up
|
|
5
|
+
* the host's code-block classes (published via `codeBlockWrapperInfo$`
|
|
6
|
+
* by the host-wrapper plugin in cms-spa), so the host's actual code-
|
|
7
|
+
* block CSS (Starlight's expressive-code, Tailwind's pre styling, etc.)
|
|
8
|
+
* reaches the editor's frame through the cascade — no shipped mirror.
|
|
9
|
+
*
|
|
10
|
+
* Host-agnostic: no Shiki / Starlight / ExpressiveCode imports. Class
|
|
11
|
+
* names are discovered at runtime from the host's live HTML.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Realm-published cell carrying the host's code-block wrapper chain,
|
|
15
|
+
* outermost first. For Starlight's expressive-code:
|
|
16
|
+
*
|
|
17
|
+
* [
|
|
18
|
+
* { tagName: 'div', className: 'expressive-code' },
|
|
19
|
+
* { tagName: 'figure', className: 'frame has-title not-content' },
|
|
20
|
+
* ]
|
|
21
|
+
*
|
|
22
|
+
* The cms-spa `hostWrapperPlugin` writes to this whenever the fetched
|
|
23
|
+
* wrapper info changes; the code-block frame reads from it to render
|
|
24
|
+
* each chain link as a nested element with the host's expected tag
|
|
25
|
+
* name. Same publish-pattern as the content-wrapper plugin in cms-spa.
|
|
26
|
+
*
|
|
27
|
+
* Null when the host has no code-block chrome (or the fetch is in
|
|
28
|
+
* flight). The frame then falls back to its base `.conloca-code-block`
|
|
29
|
+
* wrapper with no host inheritance — "looks plain but not broken."
|
|
30
|
+
*/
|
|
31
|
+
export declare const codeBlockWrapperInfo$: import("@mdxeditor/editor").NodeRef<{
|
|
32
|
+
tagName: string;
|
|
33
|
+
className: string;
|
|
34
|
+
}[] | null>;
|
|
35
|
+
/**
|
|
36
|
+
* Catch-all descriptor — `priority: 100`, `match: () => true` — registered
|
|
37
|
+
* via `codeBlockPlugin({ codeBlockEditorDescriptors: [conlocaCodeBlockDescriptor] })`.
|
|
38
|
+
* Wraps the upstream `CodeMirrorEditor` with the host-themed frame.
|
|
39
|
+
*/
|
|
40
|
+
export declare const conlocaCodeBlockDescriptor: CodeBlockEditorDescriptor;
|
|
41
|
+
//# sourceMappingURL=code-block-frame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-block-frame.d.ts","sourceRoot":"","sources":["../src/code-block-frame.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,yBAAyB,EAK/B,MAAM,mBAAmB,CAAC;AAI3B;;;;;;;;;;GAUG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,qBAAqB;aAAmB,MAAM;eAAa,MAAM;WAAkB,CAAC;AAmNjG;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,yBAIxC,CAAC"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Cell, CodeMirrorEditor, useCellValue, useCodeBlockEditorContext, } from '@mdxeditor/editor';
|
|
3
|
+
import { Check, Copy } from 'lucide-react';
|
|
4
|
+
import { createElement, useCallback, useEffect, useMemo, useState } from 'react';
|
|
5
|
+
/**
|
|
6
|
+
* Frame chrome around the editor's fenced code blocks — header bar with
|
|
7
|
+
* filename, language tag, and a copy button. The outer wrapper picks up
|
|
8
|
+
* the host's code-block classes (published via `codeBlockWrapperInfo$`
|
|
9
|
+
* by the host-wrapper plugin in cms-spa), so the host's actual code-
|
|
10
|
+
* block CSS (Starlight's expressive-code, Tailwind's pre styling, etc.)
|
|
11
|
+
* reaches the editor's frame through the cascade — no shipped mirror.
|
|
12
|
+
*
|
|
13
|
+
* Host-agnostic: no Shiki / Starlight / ExpressiveCode imports. Class
|
|
14
|
+
* names are discovered at runtime from the host's live HTML.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Realm-published cell carrying the host's code-block wrapper chain,
|
|
18
|
+
* outermost first. For Starlight's expressive-code:
|
|
19
|
+
*
|
|
20
|
+
* [
|
|
21
|
+
* { tagName: 'div', className: 'expressive-code' },
|
|
22
|
+
* { tagName: 'figure', className: 'frame has-title not-content' },
|
|
23
|
+
* ]
|
|
24
|
+
*
|
|
25
|
+
* The cms-spa `hostWrapperPlugin` writes to this whenever the fetched
|
|
26
|
+
* wrapper info changes; the code-block frame reads from it to render
|
|
27
|
+
* each chain link as a nested element with the host's expected tag
|
|
28
|
+
* name. Same publish-pattern as the content-wrapper plugin in cms-spa.
|
|
29
|
+
*
|
|
30
|
+
* Null when the host has no code-block chrome (or the fetch is in
|
|
31
|
+
* flight). The frame then falls back to its base `.conloca-code-block`
|
|
32
|
+
* wrapper with no host inheritance — "looks plain but not broken."
|
|
33
|
+
*/
|
|
34
|
+
export const codeBlockWrapperInfo$ = Cell(null);
|
|
35
|
+
const TITLE_META_RE = /\btitle=(?:"([^"]*)"|'([^']*)'|(\S+))/;
|
|
36
|
+
// First-line filename comment, the convention ExpressiveCode's frames
|
|
37
|
+
// plugin recognizes when no explicit `title=` is set on the fence —
|
|
38
|
+
// `// foo.ts`, `# foo.py`, `<!-- foo.html -->`, `/* foo.css */`,
|
|
39
|
+
// `; foo.ini`, `-- foo.sql`. Requires a dot-extension so plain prose
|
|
40
|
+
// comments don't get mistaken for filenames.
|
|
41
|
+
const FILENAME_COMMENT_RE = /^\s*(?:\/\/|#|;|--|<!--|\/\*)\s*([\w.\-/@]+\.[\w.-]+)\s*(?:-->|\*\/)?\s*$/;
|
|
42
|
+
function parseMeta(meta) {
|
|
43
|
+
const match = meta.match(TITLE_META_RE);
|
|
44
|
+
if (!match)
|
|
45
|
+
return { title: '', rest: meta.trim() };
|
|
46
|
+
const value = match[1] ?? match[2] ?? match[3] ?? '';
|
|
47
|
+
const rest = (meta.slice(0, match.index) + meta.slice(match.index + match[0].length)).replace(/\s+/g, ' ').trim();
|
|
48
|
+
return { title: value, rest };
|
|
49
|
+
}
|
|
50
|
+
/** Reassemble a meta string with `title` set (or stripped when empty). */
|
|
51
|
+
function buildMeta(title, rest) {
|
|
52
|
+
const trimmedTitle = title.trim();
|
|
53
|
+
const titleFragment = trimmedTitle ? `title="${trimmedTitle.replace(/"/g, '\\"')}"` : '';
|
|
54
|
+
if (titleFragment && rest)
|
|
55
|
+
return `${titleFragment} ${rest}`;
|
|
56
|
+
return titleFragment || rest;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Detect a leading filename comment, the convention EC's frames plugin
|
|
60
|
+
* uses on the published page when no explicit `title=` is set. Returns
|
|
61
|
+
* the filename when line 1 of the code is a single-line comment ending
|
|
62
|
+
* in a dot-extension; empty string otherwise.
|
|
63
|
+
*
|
|
64
|
+
* Used to pre-fill the editor's filename input on legacy fences so
|
|
65
|
+
* authors see the same value the reader sees in the rendered tab. Pure
|
|
66
|
+
* read — the underlying code/comment is never touched.
|
|
67
|
+
*/
|
|
68
|
+
function detectFilenameComment(code) {
|
|
69
|
+
const firstLine = code.split('\n', 1)[0] ?? '';
|
|
70
|
+
const match = firstLine.match(FILENAME_COMMENT_RE);
|
|
71
|
+
return match ? (match[1] ?? '') : '';
|
|
72
|
+
}
|
|
73
|
+
function CopyButton({ code }) {
|
|
74
|
+
const [copied, setCopied] = useState(false);
|
|
75
|
+
const onClick = useCallback(() => {
|
|
76
|
+
void navigator.clipboard.writeText(code).then(() => {
|
|
77
|
+
setCopied(true);
|
|
78
|
+
window.setTimeout(() => setCopied(false), 1200);
|
|
79
|
+
});
|
|
80
|
+
}, [code]);
|
|
81
|
+
return (_jsx("button", { type: "button", onClick: onClick, className: "conloca-code-copy", "aria-label": copied ? 'Copied' : 'Copy code', title: copied ? 'Copied' : 'Copy code', children: copied ? _jsx(Check, { size: 14, "aria-hidden": "true" }) : _jsx(Copy, { size: 14, "aria-hidden": "true" }) }));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Editable filename slot. Rewrites the code block's meta string via
|
|
85
|
+
* `setMeta` from `useCodeBlockEditorContext` so authors can author the
|
|
86
|
+
* frame title (`\`\`\`ts title="src/foo.ts"`) directly from the editor —
|
|
87
|
+
* the meta string round-trips through MDXEditor's markdown serializer
|
|
88
|
+
* and ExpressiveCode picks it up as the frame header on the published
|
|
89
|
+
* page. Other meta fragments (ins/del/mark/wrap) are preserved.
|
|
90
|
+
*
|
|
91
|
+
* Legacy fences with a filename comment on line 1 (`// foo.ts`) — EC's
|
|
92
|
+
* pre-meta convention for tab titles — are detected and pre-filled in
|
|
93
|
+
* the input as a read-only display. Opening such a fence does NOT
|
|
94
|
+
* mutate the source. Editing the field is an explicit author intent:
|
|
95
|
+
* the new value is written as `title=` meta AND the original comment
|
|
96
|
+
* line is stripped, so the editor's input becomes the single source of
|
|
97
|
+
* truth without breaking the published render.
|
|
98
|
+
*/
|
|
99
|
+
function FilenameInput({ meta, code }) {
|
|
100
|
+
const { setMeta, setCode } = useCodeBlockEditorContext();
|
|
101
|
+
const parsed = useMemo(() => parseMeta(meta), [meta]);
|
|
102
|
+
const detectedFromComment = useMemo(() => (parsed.title ? '' : detectFilenameComment(code)), [parsed.title, code]);
|
|
103
|
+
const displayed = parsed.title || detectedFromComment;
|
|
104
|
+
const [title, setTitle] = useState(displayed);
|
|
105
|
+
const [interacted, setInteracted] = useState(false);
|
|
106
|
+
// External updates (HMR, language change, sibling code edits) reset
|
|
107
|
+
// the local view to the canonical value and clear the "user edited"
|
|
108
|
+
// flag — so the next blur after an external update doesn't write
|
|
109
|
+
// anything until the author actively types again.
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
setTitle(displayed);
|
|
112
|
+
setInteracted(false);
|
|
113
|
+
}, [displayed]);
|
|
114
|
+
const commit = useCallback((next) => {
|
|
115
|
+
if (!interacted)
|
|
116
|
+
return;
|
|
117
|
+
if (next === parsed.title)
|
|
118
|
+
return;
|
|
119
|
+
setMeta(buildMeta(next, parsed.rest));
|
|
120
|
+
// If the pre-fill came from a leading filename comment and the
|
|
121
|
+
// author has now committed an explicit title, strip the comment
|
|
122
|
+
// so EC doesn't render the title twice (once as the tab, once as
|
|
123
|
+
// a stray code comment) on the published page.
|
|
124
|
+
if (detectedFromComment) {
|
|
125
|
+
const lines = code.split('\n');
|
|
126
|
+
if (lines[0] && FILENAME_COMMENT_RE.test(lines[0])) {
|
|
127
|
+
setCode(lines.slice(1).join('\n').replace(/^\n+/, ''));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}, [interacted, parsed.title, parsed.rest, detectedFromComment, code, setMeta, setCode]);
|
|
131
|
+
const onChange = (e) => {
|
|
132
|
+
setInteracted(true);
|
|
133
|
+
setTitle(e.target.value);
|
|
134
|
+
};
|
|
135
|
+
const onBlur = () => commit(title);
|
|
136
|
+
return (_jsx("input", { type: "text", className: "conloca-code-block__filename", value: title, placeholder: "filename", spellCheck: false, onChange: onChange, onBlur: onBlur, "aria-label": "Code block filename" }));
|
|
137
|
+
}
|
|
138
|
+
function ConlocaCodeBlockEditor(props) {
|
|
139
|
+
// Materialise the host's discovered code-block chain as nested
|
|
140
|
+
// elements. The INNERMOST link in the chain becomes the "frame"
|
|
141
|
+
// element that directly holds the filename header, the code body,
|
|
142
|
+
// and the copy slot — matching ExpressiveCode's authoring shape:
|
|
143
|
+
//
|
|
144
|
+
// <div class="expressive-code"> ← outer link
|
|
145
|
+
// <figure class="frame has-title …"> ← inner link (frame)
|
|
146
|
+
// <figcaption class="header">
|
|
147
|
+
// <span class="title"><FilenameInput /></span>
|
|
148
|
+
// </figcaption>
|
|
149
|
+
// <pre><CodeMirror /></pre>
|
|
150
|
+
// <div class="copy"><CopyButton /></div>
|
|
151
|
+
// </figure>
|
|
152
|
+
// </div>
|
|
153
|
+
//
|
|
154
|
+
// Rendering with the host's expected tags (figure / figcaption / pre)
|
|
155
|
+
// and nesting depth lets descendant CSS selectors land — both single-
|
|
156
|
+
// class (`.frame { ... }`) and descendant (`.expressive-code .frame
|
|
157
|
+
// .header > .title { ... }`) rules paint without us shipping a
|
|
158
|
+
// parallel copy.
|
|
159
|
+
//
|
|
160
|
+
// When chain is null/empty (host has no code-block chrome, or the
|
|
161
|
+
// wrapper fetch hasn't resolved yet) we fall back to a bare
|
|
162
|
+
// `<div class="conloca-code-block">` containing the same inner
|
|
163
|
+
// shape — "looks plain but not broken."
|
|
164
|
+
const chain = useCellValue(codeBlockWrapperInfo$) ?? [];
|
|
165
|
+
const frameLink = chain.length > 0 ? chain[chain.length - 1] : null;
|
|
166
|
+
const outerLinks = frameLink ? chain.slice(0, -1) : [];
|
|
167
|
+
const frameInner = (_jsxs(_Fragment, { children: [_jsx("figcaption", { className: "conloca-code-block__header header", children: _jsx("span", { className: "title", children: _jsx(FilenameInput, { meta: props.meta, code: props.code }) }) }), _jsx("pre", { className: "conloca-code-block__pre", children: _jsx(CodeMirrorEditor, { ...props }) }), _jsx("div", { className: "conloca-code-block__copy copy", children: _jsx(CopyButton, { code: props.code }) })] }));
|
|
168
|
+
// The frame element carries `conloca-code-block` (our own targeting
|
|
169
|
+
// hook) alongside the host's discovered classes. When the host has
|
|
170
|
+
// no chain, we still wrap in a plain `<div>` so the inner shape is
|
|
171
|
+
// consistent for our utility selectors.
|
|
172
|
+
const frame = frameLink ? (createElement(frameLink.tagName, { className: `conloca-code-block ${frameLink.className}` }, frameInner)) : (_jsx("div", { className: "conloca-code-block", children: frameInner }));
|
|
173
|
+
// Wrap outer links from inside out. `reduceRight` so the first
|
|
174
|
+
// chain link ends up as the outermost rendered element.
|
|
175
|
+
return outerLinks.reduceRight((kids, link) => createElement(link.tagName, { className: link.className }, kids), frame);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Catch-all descriptor — `priority: 100`, `match: () => true` — registered
|
|
179
|
+
* via `codeBlockPlugin({ codeBlockEditorDescriptors: [conlocaCodeBlockDescriptor] })`.
|
|
180
|
+
* Wraps the upstream `CodeMirrorEditor` with the host-themed frame.
|
|
181
|
+
*/
|
|
182
|
+
export const conlocaCodeBlockDescriptor = {
|
|
183
|
+
priority: 100,
|
|
184
|
+
match: () => true,
|
|
185
|
+
Editor: ConlocaCodeBlockEditor,
|
|
186
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type JsxComponentDescriptor, type MDXEditorMethods, type RealmPlugin } from '@mdxeditor/editor';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import '@mdxeditor/editor/style.css';
|
|
4
|
+
import './editor-styles.css';
|
|
5
|
+
export interface BaseMDXEditorProps {
|
|
6
|
+
value: string;
|
|
7
|
+
/**
|
|
8
|
+
* Called whenever the editor content changes. The second argument is `true`
|
|
9
|
+
* the first time the library normalizes the parsed markdown back to its
|
|
10
|
+
* canonical form (bullet style, trailing newline, etc.) — consumers tracking
|
|
11
|
+
* dirty state should treat that call as a re-baseline rather than a user
|
|
12
|
+
* edit, otherwise the editor looks dirty the moment the page loads.
|
|
13
|
+
*/
|
|
14
|
+
onChange: (value: string, initialMarkdownNormalize?: boolean) => void;
|
|
15
|
+
onSave?: (value: string) => void;
|
|
16
|
+
readOnly?: boolean;
|
|
17
|
+
imageDialog?: React.FC | null;
|
|
18
|
+
disableImageSettingsButton?: boolean;
|
|
19
|
+
onImageShortcut?: () => void;
|
|
20
|
+
imageButtonRef?: React.Ref<HTMLButtonElement>;
|
|
21
|
+
/**
|
|
22
|
+
* Upload handler for images pasted or dropped directly into the editor. When
|
|
23
|
+
* provided, the underlying imagePlugin will route those events through this
|
|
24
|
+
* function and insert the returned URL as the image src. Independent of the
|
|
25
|
+
* library/picker `imageDialog` flow — both can be active simultaneously.
|
|
26
|
+
*/
|
|
27
|
+
imageUploadHandler?: (file: File) => Promise<string>;
|
|
28
|
+
jsxComponentDescriptors?: JsxComponentDescriptor[];
|
|
29
|
+
/**
|
|
30
|
+
* Additional @mdxeditor/editor RealmPlugins appended to the built-in
|
|
31
|
+
* plugin list. Used by the SPA shell to register the MDX components
|
|
32
|
+
* registry-driven slash menu without coupling @conloca/mdx to
|
|
33
|
+
* @conloca/cms-spa.
|
|
34
|
+
*/
|
|
35
|
+
extraPlugins?: RealmPlugin[];
|
|
36
|
+
/**
|
|
37
|
+
* Extra toolbar buttons inserted between `<InsertAdmonition />` and the
|
|
38
|
+
* separator preceding focus mode. Pass `null` (default) to keep the
|
|
39
|
+
* stock toolbar.
|
|
40
|
+
*/
|
|
41
|
+
extraToolbarItems?: React.ReactNode;
|
|
42
|
+
/**
|
|
43
|
+
* Class applied to the MDXEditor root element (library forwards it to the
|
|
44
|
+
* toolbar and portaled popups too). Pass `"dark-theme"` to activate the
|
|
45
|
+
* library's built-in Radix dark palette.
|
|
46
|
+
* See https://mdxeditor.dev/editor/docs/theming
|
|
47
|
+
*/
|
|
48
|
+
className?: string;
|
|
49
|
+
/** Placeholder shown when the editor is empty. Forwarded to MDXEditorLib. */
|
|
50
|
+
placeholder?: React.ReactNode;
|
|
51
|
+
/** Auto-focus the editor on mount. Forwarded to MDXEditorLib. */
|
|
52
|
+
autoFocus?: boolean | {
|
|
53
|
+
defaultSelection?: 'rootStart' | 'rootEnd';
|
|
54
|
+
preventScroll?: boolean;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export declare const BaseMDXEditor: React.ForwardRefExoticComponent<BaseMDXEditorProps & React.RefAttributes<MDXEditorMethods>>;
|
|
58
|
+
//# sourceMappingURL=editor-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor-core.d.ts","sourceRoot":"","sources":["../src/editor-core.tsx"],"names":[],"mappings":"AAAA,OAAO,EAmBL,KAAK,sBAAsB,EAO3B,KAAK,gBAAgB,EAGrB,KAAK,WAAW,EAOjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAuD,MAAM,OAAO,CAAC;AAC5E,OAAO,6BAA6B,CAAC;AACrC,OAAO,qBAAqB,CAAC;AAuD7B,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,wBAAwB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACtE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC;IAC9B,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,eAAe,CAAC,EAAE,MAAM,IAAI,CAAC;IAC7B,cAAc,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC9C;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACrD,uBAAuB,CAAC,EAAE,sBAAsB,EAAE,CAAC;IACnD;;;;;OAKG;IACH,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC;IAC7B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACpC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,iEAAiE;IACjE,SAAS,CAAC,EAAE,OAAO,GAAG;QAAE,gBAAgB,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;QAAC,aAAa,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAC/F;AA8DD,eAAO,MAAM,aAAa,6FA0IzB,CAAC"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { BlockTypeSelect, BoldItalicUnderlineToggles, ButtonWithTooltip, ChangeCodeMirrorLanguage, ConditionalContents, CreateLink, codeBlockPlugin, codeMirrorPlugin, DiffSourceToggleWrapper, diffSourcePlugin, GenericJsxEditor, HighlightToggle, headingsPlugin, InsertCodeBlock, InsertImage, InsertTable, InsertThematicBreak, imagePlugin, jsxPlugin, ListsToggle, linkDialogPlugin, linkPlugin, listsPlugin, MDXEditor as MDXEditorLib, markdownShortcutPlugin, quotePlugin, Separator, StrikeThroughSupSubToggles, tablePlugin, thematicBreakPlugin, toolbarPlugin, UndoRedo, } from '@mdxeditor/editor';
|
|
3
|
+
import { Maximize2, Minimize2 } from 'lucide-react';
|
|
4
|
+
import React, { useCallback, useEffect, useSyncExternalStore } from 'react';
|
|
5
|
+
import '@mdxeditor/editor/style.css';
|
|
6
|
+
import './editor-styles.css';
|
|
7
|
+
import { conlocaCodeBlockDescriptor } from './code-block-frame';
|
|
8
|
+
import { TO_MARKDOWN_OPTIONS } from './markdown-options';
|
|
9
|
+
const FOCUS_MODE_STORAGE_KEY = 'conloca.mdxeditor.focusMode';
|
|
10
|
+
const FOCUS_MODE_BODY_CLASS = 'mdxeditor-focus-mode';
|
|
11
|
+
/**
|
|
12
|
+
* Toggle focus-mode by writing the class on `document.body`. Direct DOM
|
|
13
|
+
* mutation (vs. piping a boolean through React state into the editor's
|
|
14
|
+
* `className` prop) avoids re-rendering Lexical on every toggle — the
|
|
15
|
+
* editor's prop is the only entry point and changing it forces a parse
|
|
16
|
+
* round-trip. Persisted in localStorage so the preference survives reloads.
|
|
17
|
+
*/
|
|
18
|
+
function readFocusMode() {
|
|
19
|
+
if (typeof document === 'undefined')
|
|
20
|
+
return false;
|
|
21
|
+
return document.body.classList.contains(FOCUS_MODE_BODY_CLASS);
|
|
22
|
+
}
|
|
23
|
+
function subscribeFocusMode(callback) {
|
|
24
|
+
if (typeof window === 'undefined')
|
|
25
|
+
return () => { };
|
|
26
|
+
const handler = () => callback();
|
|
27
|
+
window.addEventListener('conloca:focusModeChange', handler);
|
|
28
|
+
return () => window.removeEventListener('conloca:focusModeChange', handler);
|
|
29
|
+
}
|
|
30
|
+
function setFocusMode(next) {
|
|
31
|
+
if (typeof document === 'undefined')
|
|
32
|
+
return;
|
|
33
|
+
document.body.classList.toggle(FOCUS_MODE_BODY_CLASS, next);
|
|
34
|
+
try {
|
|
35
|
+
if (next) {
|
|
36
|
+
window.localStorage.setItem(FOCUS_MODE_STORAGE_KEY, '1');
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
window.localStorage.removeItem(FOCUS_MODE_STORAGE_KEY);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// localStorage may be unavailable (private mode, SSR) — ignore.
|
|
44
|
+
}
|
|
45
|
+
window.dispatchEvent(new Event('conloca:focusModeChange'));
|
|
46
|
+
}
|
|
47
|
+
function FocusModeToggle() {
|
|
48
|
+
const focusMode = useSyncExternalStore(subscribeFocusMode, readFocusMode, () => false);
|
|
49
|
+
const onClick = useCallback(() => setFocusMode(!focusMode), [focusMode]);
|
|
50
|
+
const Icon = focusMode ? Minimize2 : Maximize2;
|
|
51
|
+
return (_jsx(ButtonWithTooltip, { title: focusMode ? 'Exit focus mode (wider column)' : 'Enter focus mode (narrow column)', onClick: onClick, children: _jsx(Icon, { size: 16, "aria-hidden": true }) }));
|
|
52
|
+
}
|
|
53
|
+
// The empty-string entry is the documented escape hatch for code blocks
|
|
54
|
+
// authored without a language hint. Without it, fences like ```\nfoo\n``` (which
|
|
55
|
+
// the parser tags as language `null` / meta `'N/A'`) trip a hard error in
|
|
56
|
+
// older versions and emit a noisy warning even on v3.55+. See mdx-editor/editor
|
|
57
|
+
// issues #370, #423, #463, #885, #886, #901.
|
|
58
|
+
const codeBlockLanguages = {
|
|
59
|
+
'': 'Plain text',
|
|
60
|
+
text: 'Plain Text',
|
|
61
|
+
js: 'JavaScript',
|
|
62
|
+
jsx: 'JavaScript (React)',
|
|
63
|
+
ts: 'TypeScript',
|
|
64
|
+
tsx: 'TypeScript (React)',
|
|
65
|
+
css: 'CSS',
|
|
66
|
+
html: 'HTML',
|
|
67
|
+
json: 'JSON',
|
|
68
|
+
md: 'Markdown',
|
|
69
|
+
mdx: 'MDX',
|
|
70
|
+
bash: 'Bash',
|
|
71
|
+
python: 'Python',
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Wildcard fallback so any unknown JSX tag round-trips through GenericJsxEditor
|
|
75
|
+
* instead of crashing the importer with "Parsing of the following markdown
|
|
76
|
+
* structure failed". Two entries because the upstream visitor dispatches by
|
|
77
|
+
* `kind` (block vs inline JSX) — without the inline one, an inline `<Badge>`
|
|
78
|
+
* mid-paragraph would be matched by the flow wildcard and lifted out of its
|
|
79
|
+
* paragraph in Lexical. Consumers passing typed descriptors win via the
|
|
80
|
+
* exact-name match in the visitor; the wildcard only handles the leftovers.
|
|
81
|
+
*/
|
|
82
|
+
const wildcardJsxDescriptors = [
|
|
83
|
+
{ name: '*', kind: 'flow', props: [], hasChildren: true, Editor: GenericJsxEditor },
|
|
84
|
+
{ name: '*', kind: 'text', props: [], hasChildren: true, Editor: GenericJsxEditor },
|
|
85
|
+
];
|
|
86
|
+
function renderInsertImageButton(imageButtonRef) {
|
|
87
|
+
if (!imageButtonRef) {
|
|
88
|
+
return _jsx(InsertImage, {});
|
|
89
|
+
}
|
|
90
|
+
return React.createElement(InsertImage, {
|
|
91
|
+
ref: imageButtonRef,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Restore the persisted focus-mode preference on first import. Runs once at
|
|
96
|
+
* module load so the class is in place before any editor mounts — avoids a
|
|
97
|
+
* flash of wide column when the user previously selected focus mode.
|
|
98
|
+
*/
|
|
99
|
+
if (typeof window !== 'undefined') {
|
|
100
|
+
try {
|
|
101
|
+
if (window.localStorage.getItem(FOCUS_MODE_STORAGE_KEY) === '1') {
|
|
102
|
+
document.body.classList.add(FOCUS_MODE_BODY_CLASS);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// ignore
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export const BaseMDXEditor = React.forwardRef(({ value, onChange, onSave, readOnly = false, imageDialog, disableImageSettingsButton = false, onImageShortcut, imageButtonRef, imageUploadHandler, jsxComponentDescriptors, extraPlugins, extraToolbarItems, className, placeholder, autoFocus, }, ref) => {
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
const handleKeyDown = (event) => {
|
|
112
|
+
if ((event.ctrlKey || event.metaKey) && event.key === 's') {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
onSave?.(value);
|
|
115
|
+
}
|
|
116
|
+
if ((event.ctrlKey || event.metaKey) && event.shiftKey && event.key.toLowerCase() === 'i') {
|
|
117
|
+
if (!onImageShortcut) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
onImageShortcut();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
125
|
+
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
126
|
+
}, [onImageShortcut, onSave, value]);
|
|
127
|
+
return (_jsx(MDXEditorLib, { ref: ref, markdown: value, toMarkdownOptions: TO_MARKDOWN_OPTIONS, onChange: onChange, onError: ({ error, source }) => {
|
|
128
|
+
// Library invokes this synchronously inside a gurx signal, so don't
|
|
129
|
+
// setState here — that triggers a render-phase warning (#872).
|
|
130
|
+
// Logging only is enough; the React error boundary still catches
|
|
131
|
+
// anything that escapes from rendering.
|
|
132
|
+
console.error('[MDXEditor] parse error:', error, '\nsource:', source);
|
|
133
|
+
}, readOnly: readOnly, className: className, placeholder: placeholder, autoFocus: autoFocus, contentEditableClassName: "conloca-prose conloca-prose--editor", plugins: [
|
|
134
|
+
headingsPlugin(),
|
|
135
|
+
listsPlugin(),
|
|
136
|
+
quotePlugin(),
|
|
137
|
+
linkPlugin(),
|
|
138
|
+
linkDialogPlugin(),
|
|
139
|
+
tablePlugin(),
|
|
140
|
+
thematicBreakPlugin(),
|
|
141
|
+
// frontmatterPlugin intentionally omitted: metadata (title,
|
|
142
|
+
// description, id, created, modified) is server-owned and stripped
|
|
143
|
+
// from `content.mdx` on load. Re-introducing the plugin would let
|
|
144
|
+
// the editor round-trip a YAML block as body text, corrupting the
|
|
145
|
+
// file when content is inserted above it.
|
|
146
|
+
codeBlockPlugin({
|
|
147
|
+
defaultCodeBlockLanguage: 'ts',
|
|
148
|
+
codeBlockEditorDescriptors: [conlocaCodeBlockDescriptor],
|
|
149
|
+
}),
|
|
150
|
+
codeMirrorPlugin({ codeBlockLanguages }),
|
|
151
|
+
diffSourcePlugin({ viewMode: 'rich-text' }),
|
|
152
|
+
markdownShortcutPlugin(),
|
|
153
|
+
jsxPlugin({
|
|
154
|
+
jsxComponentDescriptors: [...(jsxComponentDescriptors ?? []), ...wildcardJsxDescriptors],
|
|
155
|
+
}),
|
|
156
|
+
imagePlugin({
|
|
157
|
+
...(imageDialog ? { ImageDialog: imageDialog, disableImageSettingsButton } : {}),
|
|
158
|
+
...(imageUploadHandler ? { imageUploadHandler } : {}),
|
|
159
|
+
}),
|
|
160
|
+
...(extraPlugins ?? []),
|
|
161
|
+
toolbarPlugin({
|
|
162
|
+
// flex-wrap so the toolbar reflows on narrow viewports instead of
|
|
163
|
+
// overflowing horizontally — workaround documented in
|
|
164
|
+
// mdx-editor/editor#908.
|
|
165
|
+
toolbarClassName: 'mdxeditor-toolbar-wrap',
|
|
166
|
+
toolbarContents: () => (_jsx(DiffSourceToggleWrapper, { children: _jsx(ConditionalContents, { options: [
|
|
167
|
+
{
|
|
168
|
+
// When the user clicks into a code block, swap most of
|
|
169
|
+
// the rich-text toolbar for the language picker — those
|
|
170
|
+
// controls are no-ops inside CodeMirror anyway.
|
|
171
|
+
when: (editor) => editor?.editorType === 'codeblock',
|
|
172
|
+
contents: () => _jsx(ChangeCodeMirrorLanguage, {}),
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
fallback: () => (_jsxs(_Fragment, { children: [_jsx(UndoRedo, {}), _jsx(Separator, {}), _jsx(BoldItalicUnderlineToggles, {}), _jsx(StrikeThroughSupSubToggles, {}), _jsx(HighlightToggle, {}), _jsx(Separator, {}), _jsx(ListsToggle, {}), _jsx(Separator, {}), _jsx(BlockTypeSelect, {}), _jsx(Separator, {}), _jsx(CreateLink, {}), renderInsertImageButton(imageButtonRef), _jsx(InsertTable, {}), _jsx(InsertThematicBreak, {}), _jsx(Separator, {}), _jsx(InsertCodeBlock, {}), extraToolbarItems, _jsx(Separator, {}), _jsx(FocusModeToggle, {})] })),
|
|
176
|
+
},
|
|
177
|
+
] }) })),
|
|
178
|
+
}),
|
|
179
|
+
] }));
|
|
180
|
+
});
|
|
181
|
+
BaseMDXEditor.displayName = 'BaseMDXEditor';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
export interface UseMDXEvaluationOptions {
|
|
3
|
+
compiledCode: string | null;
|
|
4
|
+
cacheKey?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface UseMDXEvaluationResult {
|
|
7
|
+
Component: React.ComponentType | null;
|
|
8
|
+
error: Error | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
retry: () => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Hook for evaluating pre-compiled MDX code into React components.
|
|
14
|
+
*
|
|
15
|
+
* Uses the browser-side half of a server-compile + browser-run pattern:
|
|
16
|
+
* 1. The server compiles MDX → JavaScript function body
|
|
17
|
+
* 2. The browser executes the pre-compiled code with run() (zero compiler dependencies)
|
|
18
|
+
*
|
|
19
|
+
* This keeps the full MDX compilation pipeline on the server and only ships
|
|
20
|
+
* a tiny runtime helper to the browser.
|
|
21
|
+
*
|
|
22
|
+
* @param options.compiledCode - The pre-compiled MDX function body. If null, returns null component
|
|
23
|
+
* @param options.cacheKey - Optional cache key. If not provided, uses hash of code
|
|
24
|
+
*
|
|
25
|
+
* @returns Object containing Component, error, isLoading, retry
|
|
26
|
+
*/
|
|
27
|
+
export declare function useMDXEvaluation({ compiledCode, cacheKey }: UseMDXEvaluationOptions): UseMDXEvaluationResult;
|
|
28
|
+
//# sourceMappingURL=useMDXEvaluation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMDXEvaluation.d.ts","sourceRoot":"","sources":["../../src/hooks/useMDXEvaluation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA6C/B,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,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;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,uBAAuB,GAAG,sBAAsB,CAsE5G"}
|