@conloca/mdx 0.1.15 → 0.2.0
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 +62 -18
- 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 +187 -0
- package/dist/code-block-frame.js.map +1 -0
- package/dist/editor-core.d.ts +56 -0
- package/dist/editor-core.d.ts.map +1 -0
- package/dist/editor-core.js +225 -0
- package/dist/editor-core.js.map +1 -0
- package/dist/esm-passthrough.d.ts +36 -0
- package/dist/esm-passthrough.d.ts.map +1 -0
- package/dist/esm-passthrough.js +237 -0
- package/dist/esm-passthrough.js.map +1 -0
- package/dist/fragments.d.ts +37 -0
- package/dist/fragments.d.ts.map +1 -0
- package/dist/fragments.js +53 -0
- package/dist/fragments.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown-options.d.ts +3 -0
- package/dist/markdown-options.d.ts.map +1 -0
- package/dist/markdown-options.js +20 -0
- package/dist/markdown-options.js.map +1 -0
- package/dist/mdx/compile-request.d.ts +5 -0
- package/dist/mdx/compile-request.d.ts.map +1 -0
- package/dist/mdx/compile-request.js +40 -0
- package/dist/mdx/compile-request.js.map +1 -0
- package/dist/mdx/compile.d.ts +3 -0
- package/dist/mdx/compile.d.ts.map +1 -0
- package/dist/mdx/compile.js +47 -0
- package/dist/mdx/compile.js.map +1 -0
- package/dist/mdx/evaluate.d.ts +39 -0
- package/dist/mdx/evaluate.d.ts.map +1 -0
- package/dist/mdx/evaluate.js +131 -0
- package/dist/mdx/evaluate.js.map +1 -0
- package/dist/mdx/heading-outline.d.ts +46 -0
- package/dist/mdx/heading-outline.d.ts.map +1 -0
- package/dist/mdx/heading-outline.js +114 -0
- package/dist/mdx/heading-outline.js.map +1 -0
- package/dist/mdx/restrict-expressions.d.ts +43 -0
- package/dist/mdx/restrict-expressions.d.ts.map +1 -0
- package/dist/mdx/restrict-expressions.js +160 -0
- package/dist/mdx/restrict-expressions.js.map +1 -0
- package/dist/mdx-editor.d.ts +7 -0
- package/dist/mdx-editor.d.ts.map +1 -0
- package/dist/mdx-editor.js +8 -0
- package/dist/mdx-editor.js.map +1 -0
- package/dist/node.d.ts +18 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +18 -0
- package/dist/node.js.map +1 -0
- package/dist/sandbox-frame.d.ts +114 -0
- package/dist/sandbox-frame.d.ts.map +1 -0
- package/dist/sandbox-frame.js +234 -0
- package/dist/sandbox-frame.js.map +1 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +82 -26
- package/src/code-block-frame.tsx +262 -0
- package/src/editor-core.tsx +403 -0
- package/src/editor-styles.css +282 -0
- package/src/esm-passthrough.ts +269 -0
- package/src/fragments.ts +91 -0
- package/src/index.ts +5 -0
- package/src/markdown-options.ts +21 -0
- package/src/mdx/compile-request.ts +53 -0
- package/src/mdx/compile.ts +51 -0
- package/src/mdx/evaluate.ts +144 -0
- package/src/mdx/heading-outline.ts +153 -0
- package/src/mdx/restrict-expressions.ts +173 -0
- package/src/mdx-editor.tsx +15 -0
- package/src/node.ts +25 -0
- package/src/sandbox-frame.ts +277 -0
- package/src/types.ts +23 -0
- package/dist/index.d.mts +0 -96
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -425
- package/dist/index.mjs.map +0 -1
- package/dist/node.d.mts +0 -107
- package/dist/node.d.mts.map +0 -1
- package/dist/node.mjs +0 -125
- package/dist/node.mjs.map +0 -1
package/dist/index.d.mts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { JsxComponentDescriptor, MDXEditorMethods, MDXEditorMethods as MDXEditorMethods$1 } from "@mdxeditor/editor";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
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
|
|
58
|
-
//#region src/hooks/useMDXEvaluation.d.ts
|
|
59
|
-
interface UseMDXEvaluationOptions {
|
|
60
|
-
compiledCode: string | null;
|
|
61
|
-
cacheKey?: string;
|
|
62
|
-
}
|
|
63
|
-
interface UseMDXEvaluationResult {
|
|
64
|
-
Component: React.ComponentType | null;
|
|
65
|
-
error: Error | null;
|
|
66
|
-
isLoading: boolean;
|
|
67
|
-
retry: () => void;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Hook for evaluating pre-compiled MDX code into React components.
|
|
71
|
-
*
|
|
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)
|
|
75
|
-
*
|
|
76
|
-
* This keeps the full MDX compilation pipeline on the server and only ships
|
|
77
|
-
* a tiny runtime helper to the browser.
|
|
78
|
-
*
|
|
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
|
|
81
|
-
*
|
|
82
|
-
* @returns Object containing Component, error, isLoading, retry
|
|
83
|
-
*/
|
|
84
|
-
declare function useMDXEvaluation({
|
|
85
|
-
compiledCode,
|
|
86
|
-
cacheKey
|
|
87
|
-
}: UseMDXEvaluationOptions): UseMDXEvaluationResult;
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/mdx-editor.d.ts
|
|
90
|
-
interface MDXEditorProps extends Omit<BaseMDXEditorProps, 'disableImageSettingsButton' | 'imageButtonRef' | 'imageDialog' | 'onImageShortcut'> {}
|
|
91
|
-
declare const MDXEditor: React.ForwardRefExoticComponent<MDXEditorProps & React.RefAttributes<MDXEditorMethods$1>>;
|
|
92
|
-
interface MDXEditorModalProps extends Omit<BaseMDXEditorModalProps, 'EditorComponent'> {}
|
|
93
|
-
declare function MDXEditorModal(props: MDXEditorModalProps): react_jsx_runtime0.JSX.Element;
|
|
94
|
-
//#endregion
|
|
95
|
-
export { BaseMDXEditor, BaseMDXEditorModal, type BaseMDXEditorModalProps, type BaseMDXEditorProps, MDXEditor, type MDXEditorMethods, MDXEditorModal, MDXEditorModalProps, MDXEditorProps, type UseMDXEvaluationOptions, type UseMDXEvaluationResult, useMDXEvaluation };
|
|
96
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/editor-core.tsx","../src/hooks/useMDXEvaluation.ts","../src/mdx-editor.tsx"],"mappings":";;;;;UAkCiB,kBAAA;EACf,KAAA;EACA,QAAA,GAAW,KAAA;EACX,MAAA,IAAU,KAAA;EACV,QAAA;EACA,WAAA,GAAc,KAAA,CAAM,EAAA;EACpB,0BAAA;EACA,eAAA;EACA,cAAA,GAAiB,KAAA,CAAM,GAAA,CAAI,iBAAA;EAC3B,uBAAA,GAA0B,sBAAA;EAAsB;;;;;;EAOhD,SAAA;AAAA;AAAA,UAGe,uBAAA;EACf,MAAA;EACA,OAAA;EACA,QAAA;EACA,cAAA;EACA,MAAA,GAAS,OAAA,oBAA2B,OAAA;EACpC,WAAA,GAAc,KAAA,CAAM,SAAA;EACpB,WAAA,IAAe,KAAA;IACb,OAAA;IACA,UAAA,EAAY,KAAA,CAAM,QAAA,CAAS,KAAA,CAAM,cAAA;IACjC,SAAA,EAAW,KAAA,CAAM,SAAA,CAAU,kBAAA;EAAA,MACvB,KAAA,CAAM,SAAA;EACZ,aAAA;EACA,eAAA,EAAiB,KAAA,CAAM,yBAAA,CAA0B,kBAAA,GAAqB,KAAA,CAAM,aAAA,CAAc,kBAAA;EAb3E;;;;EAkBf,eAAA;AAAA;AAAA,cAiEW,aAAA,EAAa,KAAA,CAAA,yBAAA,CAAA,kBAAA,GAAA,KAAA,CAAA,aAAA,CAAA,kBAAA;AAAA,iBA+JV,kBAAA,CAAA;EACd,MAAA;EACA,OAAA;EACA,QAAA;EACA,cAAA;EACA,MAAA;EACA,WAAA;EACA,WAAA;EACA,aAAA;EACA,eAAA;EACA;AAAA,GACC,uBAAA,GAAuB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;UCrQT,uBAAA;EACf,YAAA;EACA,QAAA;AAAA;AAAA,UAGe,sBAAA;EACf,SAAA,EAAW,KAAA,CAAM,aAAA;EACjB,KAAA,EAAO,KAAA;EACP,SAAA;EACA,KAAA;AAAA;;;;;;;;;;;;;;;;iBAkBc,gBAAA,CAAA;EAAmB,YAAA;EAAc;AAAA,GAAY,uBAAA,GAA0B,sBAAA;;;UC/DtE,cAAA,SACP,IAAA,CACN,kBAAA;AAAA,cAIS,SAAA,EAAS,KAAA,CAAA,yBAAA,CAAA,cAAA,GAAA,KAAA,CAAA,aAAA,CAAA,kBAAA;AAAA,UAML,mBAAA,SAA4B,IAAA,CAAK,uBAAA;AAAA,iBAElC,cAAA,CAAe,KAAA,EAAO,mBAAA,GAAmB,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
package/dist/index.mjs
DELETED
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
import { BlockTypeSelect, BoldItalicUnderlineToggles, CreateLink, DiffSourceToggleWrapper, InsertCodeBlock, InsertImage, InsertTable, InsertThematicBreak, ListsToggle, MDXEditor as MDXEditor$1, Separator, UndoRedo, codeBlockPlugin, codeMirrorPlugin, diffSourcePlugin, frontmatterPlugin, headingsPlugin, imagePlugin, jsxPlugin, linkDialogPlugin, linkPlugin, listsPlugin, markdownShortcutPlugin, quotePlugin, tablePlugin, thematicBreakPlugin, toolbarPlugin } from "@mdxeditor/editor";
|
|
2
|
-
import React, { useEffect, useState } from "react";
|
|
3
|
-
import "@mdxeditor/editor/style.css";
|
|
4
|
-
import * as runtime from "react/jsx-runtime";
|
|
5
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import * as devRuntime from "react/jsx-dev-runtime";
|
|
7
|
-
|
|
8
|
-
//#region src/editor-core.tsx
|
|
9
|
-
const codeBlockLanguages = {
|
|
10
|
-
text: "Plain Text",
|
|
11
|
-
js: "JavaScript",
|
|
12
|
-
jsx: "JavaScript (React)",
|
|
13
|
-
ts: "TypeScript",
|
|
14
|
-
tsx: "TypeScript (React)",
|
|
15
|
-
css: "CSS",
|
|
16
|
-
html: "HTML",
|
|
17
|
-
json: "JSON",
|
|
18
|
-
md: "Markdown",
|
|
19
|
-
mdx: "MDX",
|
|
20
|
-
bash: "Bash",
|
|
21
|
-
python: "Python"
|
|
22
|
-
};
|
|
23
|
-
function renderInsertImageButton(imageButtonRef) {
|
|
24
|
-
if (!imageButtonRef) return /* @__PURE__ */ jsx(InsertImage, {});
|
|
25
|
-
return React.createElement(InsertImage, { ref: imageButtonRef });
|
|
26
|
-
}
|
|
27
|
-
var MDXEditorErrorBoundary = class extends React.Component {
|
|
28
|
-
constructor(props) {
|
|
29
|
-
super(props);
|
|
30
|
-
this.state = { hasError: false };
|
|
31
|
-
}
|
|
32
|
-
static getDerivedStateFromError(error) {
|
|
33
|
-
return {
|
|
34
|
-
hasError: true,
|
|
35
|
-
error
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
componentDidCatch(error, errorInfo) {
|
|
39
|
-
console.error(`${this.props.logPrefix} Error boundary caught:`, error, errorInfo);
|
|
40
|
-
}
|
|
41
|
-
render() {
|
|
42
|
-
if (this.state.hasError) return /* @__PURE__ */ jsxs("div", {
|
|
43
|
-
className: "p-4 bg-red-50 border border-red-200 rounded text-red-600",
|
|
44
|
-
children: [
|
|
45
|
-
/* @__PURE__ */ jsx("p", {
|
|
46
|
-
className: "font-semibold mb-2",
|
|
47
|
-
children: "MDXEditor Error"
|
|
48
|
-
}),
|
|
49
|
-
/* @__PURE__ */ jsx("p", {
|
|
50
|
-
className: "text-sm mb-2",
|
|
51
|
-
children: this.state.error?.message || "Unknown error occurred"
|
|
52
|
-
}),
|
|
53
|
-
/* @__PURE__ */ jsxs("details", {
|
|
54
|
-
className: "text-xs",
|
|
55
|
-
children: [/* @__PURE__ */ jsx("summary", {
|
|
56
|
-
className: "cursor-pointer font-medium",
|
|
57
|
-
children: "Stack Trace"
|
|
58
|
-
}), /* @__PURE__ */ jsx("pre", {
|
|
59
|
-
className: "mt-2 p-2 bg-red-100 rounded overflow-auto whitespace-pre-wrap",
|
|
60
|
-
children: this.state.error?.stack
|
|
61
|
-
})]
|
|
62
|
-
})
|
|
63
|
-
]
|
|
64
|
-
});
|
|
65
|
-
return this.props.children;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const BaseMDXEditor = React.forwardRef(({ value, onChange, onSave, readOnly = false, imageDialog, disableImageSettingsButton = false, onImageShortcut, imageButtonRef, jsxComponentDescriptors, className }, ref) => {
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
const handleKeyDown = (event) => {
|
|
71
|
-
if ((event.ctrlKey || event.metaKey) && event.key === "s") {
|
|
72
|
-
event.preventDefault();
|
|
73
|
-
onSave?.(value);
|
|
74
|
-
}
|
|
75
|
-
if ((event.ctrlKey || event.metaKey) && event.shiftKey && event.key.toLowerCase() === "i") {
|
|
76
|
-
if (!onImageShortcut) return;
|
|
77
|
-
event.preventDefault();
|
|
78
|
-
onImageShortcut();
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
82
|
-
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
83
|
-
}, [
|
|
84
|
-
onImageShortcut,
|
|
85
|
-
onSave,
|
|
86
|
-
value
|
|
87
|
-
]);
|
|
88
|
-
return /* @__PURE__ */ jsx(MDXEditor$1, {
|
|
89
|
-
ref,
|
|
90
|
-
markdown: value,
|
|
91
|
-
onChange,
|
|
92
|
-
readOnly,
|
|
93
|
-
className,
|
|
94
|
-
contentEditableClassName: "conloca-prose conloca-prose--editor max-w-none",
|
|
95
|
-
plugins: [
|
|
96
|
-
headingsPlugin(),
|
|
97
|
-
listsPlugin(),
|
|
98
|
-
quotePlugin(),
|
|
99
|
-
linkPlugin(),
|
|
100
|
-
linkDialogPlugin(),
|
|
101
|
-
tablePlugin(),
|
|
102
|
-
thematicBreakPlugin(),
|
|
103
|
-
frontmatterPlugin(),
|
|
104
|
-
codeBlockPlugin({ defaultCodeBlockLanguage: "ts" }),
|
|
105
|
-
codeMirrorPlugin({ codeBlockLanguages }),
|
|
106
|
-
diffSourcePlugin({ viewMode: "rich-text" }),
|
|
107
|
-
markdownShortcutPlugin(),
|
|
108
|
-
jsxPlugin({ jsxComponentDescriptors: jsxComponentDescriptors ?? [] }),
|
|
109
|
-
imagePlugin(imageDialog ? {
|
|
110
|
-
ImageDialog: imageDialog,
|
|
111
|
-
disableImageSettingsButton
|
|
112
|
-
} : void 0),
|
|
113
|
-
toolbarPlugin({ toolbarContents: () => /* @__PURE__ */ jsxs(DiffSourceToggleWrapper, { children: [
|
|
114
|
-
/* @__PURE__ */ jsx(UndoRedo, {}),
|
|
115
|
-
/* @__PURE__ */ jsx(Separator, {}),
|
|
116
|
-
/* @__PURE__ */ jsx(BoldItalicUnderlineToggles, {}),
|
|
117
|
-
/* @__PURE__ */ jsx(Separator, {}),
|
|
118
|
-
/* @__PURE__ */ jsx(ListsToggle, {}),
|
|
119
|
-
/* @__PURE__ */ jsx(Separator, {}),
|
|
120
|
-
/* @__PURE__ */ jsx(BlockTypeSelect, {}),
|
|
121
|
-
/* @__PURE__ */ jsx(Separator, {}),
|
|
122
|
-
/* @__PURE__ */ jsx(CreateLink, {}),
|
|
123
|
-
renderInsertImageButton(imageButtonRef),
|
|
124
|
-
/* @__PURE__ */ jsx(InsertTable, {}),
|
|
125
|
-
/* @__PURE__ */ jsx(InsertThematicBreak, {}),
|
|
126
|
-
/* @__PURE__ */ jsx(Separator, {}),
|
|
127
|
-
/* @__PURE__ */ jsx(InsertCodeBlock, {})
|
|
128
|
-
] }) })
|
|
129
|
-
]
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
BaseMDXEditor.displayName = "BaseMDXEditor";
|
|
133
|
-
function DeferredMDXEditor({ EditorComponent, editorRef, ...props }) {
|
|
134
|
-
const [isReady, setIsReady] = useState(false);
|
|
135
|
-
useEffect(() => {
|
|
136
|
-
const timer = setTimeout(() => {
|
|
137
|
-
setIsReady(true);
|
|
138
|
-
}, 10);
|
|
139
|
-
return () => clearTimeout(timer);
|
|
140
|
-
}, []);
|
|
141
|
-
if (!isReady) return /* @__PURE__ */ jsx("div", {
|
|
142
|
-
className: "flex items-center justify-center h-full text-gray-500",
|
|
143
|
-
"data-testid": "deferred-editor-loading",
|
|
144
|
-
children: "Initializing editor..."
|
|
145
|
-
});
|
|
146
|
-
return /* @__PURE__ */ jsx("div", {
|
|
147
|
-
"data-testid": "deferred-editor-ready",
|
|
148
|
-
children: /* @__PURE__ */ jsx(EditorComponent, {
|
|
149
|
-
ref: editorRef,
|
|
150
|
-
...props
|
|
151
|
-
})
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
function Dialog({ open, onOpenChange, children }) {
|
|
155
|
-
if (!open) return null;
|
|
156
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
157
|
-
className: "fixed inset-0 z-50 flex items-center justify-center",
|
|
158
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
159
|
-
role: "presentation",
|
|
160
|
-
className: "fixed inset-0 bg-black/50",
|
|
161
|
-
onClick: () => onOpenChange(false)
|
|
162
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
163
|
-
className: "relative z-50 bg-white dark:bg-grey-03 rounded-lg shadow-lg max-w-[90vw] max-h-[90vh] overflow-hidden",
|
|
164
|
-
children
|
|
165
|
-
})]
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
function DialogContent({ children, className = "" }) {
|
|
169
|
-
return /* @__PURE__ */ jsx("div", {
|
|
170
|
-
className: `p-6 ${className}`,
|
|
171
|
-
children
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
function DialogHeader({ children }) {
|
|
175
|
-
return /* @__PURE__ */ jsx("div", {
|
|
176
|
-
className: "mb-4",
|
|
177
|
-
children
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
function DialogTitle({ children }) {
|
|
181
|
-
return /* @__PURE__ */ jsx("h2", {
|
|
182
|
-
className: "text-xl font-semibold text-grey-01 dark:text-grey-12",
|
|
183
|
-
children
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
function BaseMDXEditorModal({ isOpen, onClose, filePath, initialContent, onSave, headerExtra, headerTools, onBeforeClose, EditorComponent, editorClassName }) {
|
|
187
|
-
const editorRef = React.useRef(null);
|
|
188
|
-
const [content, setContent] = useState(initialContent);
|
|
189
|
-
const [isEditorReady, setIsEditorReady] = useState(false);
|
|
190
|
-
const [isSaving, setIsSaving] = useState(false);
|
|
191
|
-
useEffect(() => {
|
|
192
|
-
setContent(initialContent);
|
|
193
|
-
}, [initialContent]);
|
|
194
|
-
const handleClose = () => {
|
|
195
|
-
if (onBeforeClose && !onBeforeClose()) return;
|
|
196
|
-
onClose();
|
|
197
|
-
};
|
|
198
|
-
useEffect(() => {
|
|
199
|
-
if (isOpen) {
|
|
200
|
-
const timer = setTimeout(() => {
|
|
201
|
-
setIsEditorReady(true);
|
|
202
|
-
}, 0);
|
|
203
|
-
return () => clearTimeout(timer);
|
|
204
|
-
}
|
|
205
|
-
setIsEditorReady(false);
|
|
206
|
-
}, [isOpen]);
|
|
207
|
-
const handleSave = async () => {
|
|
208
|
-
setIsSaving(true);
|
|
209
|
-
try {
|
|
210
|
-
await onSave(content);
|
|
211
|
-
handleClose();
|
|
212
|
-
} catch (error) {
|
|
213
|
-
console.error("Save failed:", error);
|
|
214
|
-
} finally {
|
|
215
|
-
setIsSaving(false);
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
if (!isOpen) return null;
|
|
219
|
-
return /* @__PURE__ */ jsx(Dialog, {
|
|
220
|
-
open: isOpen,
|
|
221
|
-
onOpenChange: handleClose,
|
|
222
|
-
children: /* @__PURE__ */ jsxs(DialogContent, {
|
|
223
|
-
className: "w-[90vw] h-[90vh] flex flex-col",
|
|
224
|
-
"data-testid": "mdx-editor-modal",
|
|
225
|
-
children: [
|
|
226
|
-
/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsxs("div", {
|
|
227
|
-
className: "flex items-center justify-between gap-4",
|
|
228
|
-
children: [
|
|
229
|
-
/* @__PURE__ */ jsx(DialogTitle, { children: filePath ? `Edit: ${filePath}` : "New MDX File" }),
|
|
230
|
-
(headerExtra || headerTools) && /* @__PURE__ */ jsxs("div", {
|
|
231
|
-
className: "flex items-center gap-2",
|
|
232
|
-
children: [headerExtra, headerTools?.({
|
|
233
|
-
content,
|
|
234
|
-
setContent,
|
|
235
|
-
editorRef
|
|
236
|
-
})]
|
|
237
|
-
}),
|
|
238
|
-
/* @__PURE__ */ jsx("button", {
|
|
239
|
-
type: "button",
|
|
240
|
-
onClick: handleClose,
|
|
241
|
-
className: "p-2 rounded text-grey-04 dark:text-grey-07 hover:bg-gray-100 dark:hover:bg-grey-04 hover:text-grey-01 dark:hover:text-grey-12",
|
|
242
|
-
"aria-label": "Close",
|
|
243
|
-
children: "✕"
|
|
244
|
-
})
|
|
245
|
-
]
|
|
246
|
-
}) }),
|
|
247
|
-
/* @__PURE__ */ jsx("div", {
|
|
248
|
-
className: "flex-1 overflow-hidden",
|
|
249
|
-
children: isEditorReady ? /* @__PURE__ */ jsx(MDXEditorErrorBoundary, {
|
|
250
|
-
logPrefix: "[MDXEditor]",
|
|
251
|
-
children: /* @__PURE__ */ jsx(DeferredMDXEditor, {
|
|
252
|
-
EditorComponent,
|
|
253
|
-
editorRef,
|
|
254
|
-
value: content,
|
|
255
|
-
onChange: setContent,
|
|
256
|
-
onSave: handleSave,
|
|
257
|
-
className: editorClassName
|
|
258
|
-
})
|
|
259
|
-
}) : /* @__PURE__ */ jsx("div", {
|
|
260
|
-
className: "flex items-center justify-center h-full",
|
|
261
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
262
|
-
className: "text-gray-500 dark:text-grey-07",
|
|
263
|
-
"data-testid": "modal-editor-loading",
|
|
264
|
-
children: "Loading editor..."
|
|
265
|
-
})
|
|
266
|
-
})
|
|
267
|
-
}),
|
|
268
|
-
/* @__PURE__ */ jsxs("div", {
|
|
269
|
-
className: "flex justify-end gap-2 mt-4",
|
|
270
|
-
children: [/* @__PURE__ */ jsx("button", {
|
|
271
|
-
type: "button",
|
|
272
|
-
onClick: handleClose,
|
|
273
|
-
className: "px-4 py-2 border border-gray-300 dark:border-grey-04 rounded text-grey-01 dark:text-grey-12 hover:bg-gray-50 dark:hover:bg-grey-04",
|
|
274
|
-
disabled: isSaving,
|
|
275
|
-
children: "Cancel"
|
|
276
|
-
}), /* @__PURE__ */ jsx("button", {
|
|
277
|
-
type: "button",
|
|
278
|
-
onClick: handleSave,
|
|
279
|
-
className: "px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed",
|
|
280
|
-
disabled: isSaving,
|
|
281
|
-
children: isSaving ? "Saving..." : "Save"
|
|
282
|
-
})]
|
|
283
|
-
})
|
|
284
|
-
]
|
|
285
|
-
})
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
//#endregion
|
|
290
|
-
//#region src/hooks/useMDXEvaluation.ts
|
|
291
|
-
const compiledCache = /* @__PURE__ */ new Map();
|
|
292
|
-
/**
|
|
293
|
-
* Execute pre-compiled MDX code (compiled with outputFormat: 'function-body').
|
|
294
|
-
* This is the same as @mdx-js/mdx's run() — inlined here to avoid importing
|
|
295
|
-
* the full @mdx-js/mdx package (which pulls acorn + remark + unified into the browser).
|
|
296
|
-
*
|
|
297
|
-
* Note: Uses AsyncFunction constructor which requires CSP `unsafe-eval`.
|
|
298
|
-
* This is acceptable since the CMS admin UI runs in a trusted environment.
|
|
299
|
-
*/
|
|
300
|
-
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;
|
|
301
|
-
async function runMDX(code, options) {
|
|
302
|
-
return new AsyncFunction(String(code))(options);
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Create the JSX runtime options for runMDX().
|
|
306
|
-
* Checked once at module load to avoid repeated environment checks.
|
|
307
|
-
*/
|
|
308
|
-
function createRunOptions() {
|
|
309
|
-
return process.env.NODE_ENV === "development" ? {
|
|
310
|
-
...devRuntime,
|
|
311
|
-
development: true
|
|
312
|
-
} : { ...runtime };
|
|
313
|
-
}
|
|
314
|
-
const runOptions = createRunOptions();
|
|
315
|
-
/**
|
|
316
|
-
* Simple hash function for generating cache keys from MDX content.
|
|
317
|
-
*/
|
|
318
|
-
function hashString(str) {
|
|
319
|
-
let hash = 0;
|
|
320
|
-
for (let i = 0; i < str.length; i++) {
|
|
321
|
-
const char = str.charCodeAt(i);
|
|
322
|
-
hash = (hash << 5) - hash + char;
|
|
323
|
-
hash = hash & hash;
|
|
324
|
-
}
|
|
325
|
-
return hash.toString(36);
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Hook for evaluating pre-compiled MDX code into React components.
|
|
329
|
-
*
|
|
330
|
-
* Uses the browser-side half of a server-compile + browser-run pattern:
|
|
331
|
-
* 1. The server compiles MDX → JavaScript function body
|
|
332
|
-
* 2. The browser executes the pre-compiled code with run() (zero compiler dependencies)
|
|
333
|
-
*
|
|
334
|
-
* This keeps the full MDX compilation pipeline on the server and only ships
|
|
335
|
-
* a tiny runtime helper to the browser.
|
|
336
|
-
*
|
|
337
|
-
* @param options.compiledCode - The pre-compiled MDX function body. If null, returns null component
|
|
338
|
-
* @param options.cacheKey - Optional cache key. If not provided, uses hash of code
|
|
339
|
-
*
|
|
340
|
-
* @returns Object containing Component, error, isLoading, retry
|
|
341
|
-
*/
|
|
342
|
-
function useMDXEvaluation({ compiledCode, cacheKey }) {
|
|
343
|
-
const [Component, setComponent] = useState(null);
|
|
344
|
-
const [error, setError] = useState(null);
|
|
345
|
-
const [isLoading, setIsLoading] = useState(() => {
|
|
346
|
-
if (!compiledCode) return false;
|
|
347
|
-
const key = cacheKey || `mdx-${hashString(compiledCode)}`;
|
|
348
|
-
return !compiledCache.has(key);
|
|
349
|
-
});
|
|
350
|
-
const [retryCount, setRetryCount] = useState(0);
|
|
351
|
-
const retry = () => {
|
|
352
|
-
if (compiledCode) {
|
|
353
|
-
const key = cacheKey || `mdx-${hashString(compiledCode)}`;
|
|
354
|
-
compiledCache.delete(key);
|
|
355
|
-
}
|
|
356
|
-
setRetryCount((prev) => prev + 1);
|
|
357
|
-
};
|
|
358
|
-
useEffect(() => {
|
|
359
|
-
if (!compiledCode) {
|
|
360
|
-
setComponent(null);
|
|
361
|
-
setError(null);
|
|
362
|
-
setIsLoading(false);
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
const key = cacheKey || `mdx-${hashString(compiledCode)}`;
|
|
366
|
-
const cached = compiledCache.get(key);
|
|
367
|
-
if (cached) {
|
|
368
|
-
setComponent(() => cached);
|
|
369
|
-
setError(null);
|
|
370
|
-
setIsLoading(false);
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
let cancelled = false;
|
|
374
|
-
const compileAndRun = async () => {
|
|
375
|
-
try {
|
|
376
|
-
setError(null);
|
|
377
|
-
setIsLoading(true);
|
|
378
|
-
const { default: MDXComponent } = await runMDX(compiledCode, runOptions);
|
|
379
|
-
if (cancelled) return;
|
|
380
|
-
compiledCache.set(key, MDXComponent);
|
|
381
|
-
setComponent(() => MDXComponent);
|
|
382
|
-
} catch (err) {
|
|
383
|
-
if (cancelled) return;
|
|
384
|
-
setError(err instanceof Error ? err : /* @__PURE__ */ new Error("MDX evaluation failed"));
|
|
385
|
-
setComponent(null);
|
|
386
|
-
} finally {
|
|
387
|
-
if (!cancelled) setIsLoading(false);
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
compileAndRun();
|
|
391
|
-
return () => {
|
|
392
|
-
cancelled = true;
|
|
393
|
-
};
|
|
394
|
-
}, [
|
|
395
|
-
compiledCode,
|
|
396
|
-
cacheKey,
|
|
397
|
-
retryCount
|
|
398
|
-
]);
|
|
399
|
-
return {
|
|
400
|
-
Component,
|
|
401
|
-
error,
|
|
402
|
-
isLoading,
|
|
403
|
-
retry
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
//#endregion
|
|
408
|
-
//#region src/mdx-editor.tsx
|
|
409
|
-
const MDXEditor = React.forwardRef((props, ref) => {
|
|
410
|
-
return /* @__PURE__ */ jsx(BaseMDXEditor, {
|
|
411
|
-
ref,
|
|
412
|
-
...props
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
MDXEditor.displayName = "MDXEditor";
|
|
416
|
-
function MDXEditorModal(props) {
|
|
417
|
-
return /* @__PURE__ */ jsx(BaseMDXEditorModal, {
|
|
418
|
-
...props,
|
|
419
|
-
EditorComponent: MDXEditor
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
//#endregion
|
|
424
|
-
export { BaseMDXEditor, BaseMDXEditorModal, MDXEditor, MDXEditorModal, useMDXEvaluation };
|
|
425
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["MDXEditorLib"],"sources":["../src/editor-core.tsx","../src/hooks/useMDXEvaluation.ts","../src/mdx-editor.tsx"],"sourcesContent":["import {\n BlockTypeSelect,\n BoldItalicUnderlineToggles,\n CreateLink,\n codeBlockPlugin,\n codeMirrorPlugin,\n DiffSourceToggleWrapper,\n diffSourcePlugin,\n frontmatterPlugin,\n headingsPlugin,\n InsertCodeBlock,\n InsertImage,\n InsertTable,\n InsertThematicBreak,\n imagePlugin,\n type JsxComponentDescriptor,\n jsxPlugin,\n ListsToggle,\n linkDialogPlugin,\n linkPlugin,\n listsPlugin,\n MDXEditor as MDXEditorLib,\n type MDXEditorMethods,\n markdownShortcutPlugin,\n quotePlugin,\n Separator,\n tablePlugin,\n thematicBreakPlugin,\n toolbarPlugin,\n UndoRedo,\n} from '@mdxeditor/editor';\nimport React, { useEffect, useState } from 'react';\nimport '@mdxeditor/editor/style.css';\n\nexport interface BaseMDXEditorProps {\n value: string;\n onChange: (value: string) => void;\n onSave?: (value: string) => void;\n readOnly?: boolean;\n imageDialog?: React.FC | null;\n disableImageSettingsButton?: boolean;\n onImageShortcut?: () => void;\n imageButtonRef?: React.Ref<HTMLButtonElement>;\n jsxComponentDescriptors?: JsxComponentDescriptor[];\n /**\n * Class applied to the MDXEditor root element (library forwards it to the\n * toolbar and portaled popups too). Pass `\"dark-theme\"` to activate the\n * library's built-in Radix dark palette.\n * See https://mdxeditor.dev/editor/docs/theming\n */\n className?: string;\n}\n\nexport interface BaseMDXEditorModalProps {\n isOpen: boolean;\n onClose: () => void;\n filePath?: string;\n initialContent: string;\n onSave: (content: string) => void | Promise<void>;\n headerExtra?: React.ReactNode;\n headerTools?: (tools: {\n content: string;\n setContent: React.Dispatch<React.SetStateAction<string>>;\n editorRef: React.RefObject<MDXEditorMethods | null>;\n }) => React.ReactNode;\n onBeforeClose?: () => boolean;\n EditorComponent: React.ForwardRefExoticComponent<BaseMDXEditorProps & React.RefAttributes<MDXEditorMethods>>;\n /**\n * Forwarded to the MDXEditor root. Typically `\"dark-theme\"` when the host\n * app is in dark mode — see BaseMDXEditorProps.className.\n */\n editorClassName?: string;\n}\n\nconst codeBlockLanguages = {\n text: 'Plain Text',\n js: 'JavaScript',\n jsx: 'JavaScript (React)',\n ts: 'TypeScript',\n tsx: 'TypeScript (React)',\n css: 'CSS',\n html: 'HTML',\n json: 'JSON',\n md: 'Markdown',\n mdx: 'MDX',\n bash: 'Bash',\n python: 'Python',\n};\n\nfunction renderInsertImageButton(imageButtonRef?: React.Ref<HTMLButtonElement>) {\n if (!imageButtonRef) {\n return <InsertImage />;\n }\n\n return React.createElement(InsertImage as unknown as React.FC<{ ref: React.Ref<HTMLButtonElement> }>, {\n ref: imageButtonRef,\n });\n}\n\nclass MDXEditorErrorBoundary extends React.Component<\n { children: React.ReactNode; logPrefix: string },\n { hasError: boolean; error?: Error }\n> {\n constructor(props: { children: React.ReactNode; logPrefix: string }) {\n super(props);\n this.state = { hasError: false };\n }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, error };\n }\n\n override componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {\n console.error(`${this.props.logPrefix} Error boundary caught:`, error, errorInfo);\n }\n\n override render() {\n if (this.state.hasError) {\n return (\n <div className=\"p-4 bg-red-50 border border-red-200 rounded text-red-600\">\n <p className=\"font-semibold mb-2\">MDXEditor Error</p>\n <p className=\"text-sm mb-2\">{this.state.error?.message || 'Unknown error occurred'}</p>\n <details className=\"text-xs\">\n <summary className=\"cursor-pointer font-medium\">Stack Trace</summary>\n <pre className=\"mt-2 p-2 bg-red-100 rounded overflow-auto whitespace-pre-wrap\">\n {this.state.error?.stack}\n </pre>\n </details>\n </div>\n );\n }\n\n return this.props.children;\n }\n}\n\nexport const BaseMDXEditor = React.forwardRef<MDXEditorMethods, BaseMDXEditorProps>(\n (\n {\n value,\n onChange,\n onSave,\n readOnly = false,\n imageDialog,\n disableImageSettingsButton = false,\n onImageShortcut,\n imageButtonRef,\n jsxComponentDescriptors,\n className,\n },\n ref,\n ) => {\n useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n if ((event.ctrlKey || event.metaKey) && event.key === 's') {\n event.preventDefault();\n onSave?.(value);\n }\n\n if ((event.ctrlKey || event.metaKey) && event.shiftKey && event.key.toLowerCase() === 'i') {\n if (!onImageShortcut) {\n return;\n }\n\n event.preventDefault();\n onImageShortcut();\n }\n };\n\n document.addEventListener('keydown', handleKeyDown);\n return () => document.removeEventListener('keydown', handleKeyDown);\n }, [onImageShortcut, onSave, value]);\n\n return (\n <MDXEditorLib\n ref={ref}\n markdown={value}\n onChange={onChange}\n readOnly={readOnly}\n className={className}\n contentEditableClassName=\"conloca-prose conloca-prose--editor max-w-none\"\n plugins={[\n headingsPlugin(),\n listsPlugin(),\n quotePlugin(),\n linkPlugin(),\n linkDialogPlugin(),\n tablePlugin(),\n thematicBreakPlugin(),\n frontmatterPlugin(),\n codeBlockPlugin({ defaultCodeBlockLanguage: 'ts' }),\n codeMirrorPlugin({ codeBlockLanguages }),\n diffSourcePlugin({ viewMode: 'rich-text' }),\n markdownShortcutPlugin(),\n jsxPlugin({ jsxComponentDescriptors: jsxComponentDescriptors ?? [] }),\n imagePlugin(\n imageDialog\n ? {\n ImageDialog: imageDialog,\n disableImageSettingsButton,\n }\n : undefined,\n ),\n toolbarPlugin({\n toolbarContents: () => (\n <DiffSourceToggleWrapper>\n <UndoRedo />\n <Separator />\n <BoldItalicUnderlineToggles />\n <Separator />\n <ListsToggle />\n <Separator />\n <BlockTypeSelect />\n <Separator />\n <CreateLink />\n {renderInsertImageButton(imageButtonRef)}\n <InsertTable />\n <InsertThematicBreak />\n <Separator />\n <InsertCodeBlock />\n </DiffSourceToggleWrapper>\n ),\n }),\n ]}\n />\n );\n },\n);\n\nBaseMDXEditor.displayName = 'BaseMDXEditor';\n\nfunction DeferredMDXEditor({\n EditorComponent,\n editorRef,\n ...props\n}: BaseMDXEditorProps & {\n EditorComponent: React.ForwardRefExoticComponent<BaseMDXEditorProps & React.RefAttributes<MDXEditorMethods>>;\n editorRef: React.RefObject<MDXEditorMethods | null>;\n}) {\n const [isReady, setIsReady] = useState(false);\n\n useEffect(() => {\n const timer = setTimeout(() => {\n setIsReady(true);\n }, 10);\n\n return () => clearTimeout(timer);\n }, []);\n\n if (!isReady) {\n return (\n <div className=\"flex items-center justify-center h-full text-gray-500\" data-testid=\"deferred-editor-loading\">\n Initializing editor...\n </div>\n );\n }\n\n return (\n <div data-testid=\"deferred-editor-ready\">\n <EditorComponent ref={editorRef} {...props} />\n </div>\n );\n}\n\ninterface DialogProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n children: React.ReactNode;\n}\n\nfunction Dialog({ open, onOpenChange, children }: DialogProps) {\n if (!open) return null;\n\n return (\n <div className=\"fixed inset-0 z-50 flex items-center justify-center\">\n <div role=\"presentation\" className=\"fixed inset-0 bg-black/50\" onClick={() => onOpenChange(false)} />\n <div className=\"relative z-50 bg-white dark:bg-grey-03 rounded-lg shadow-lg max-w-[90vw] max-h-[90vh] overflow-hidden\">\n {children}\n </div>\n </div>\n );\n}\n\nfunction DialogContent({ children, className = '' }: { children: React.ReactNode; className?: string }) {\n return <div className={`p-6 ${className}`}>{children}</div>;\n}\n\nfunction DialogHeader({ children }: { children: React.ReactNode }) {\n return <div className=\"mb-4\">{children}</div>;\n}\n\nfunction DialogTitle({ children }: { children: React.ReactNode }) {\n return <h2 className=\"text-xl font-semibold text-grey-01 dark:text-grey-12\">{children}</h2>;\n}\n\nexport function BaseMDXEditorModal({\n isOpen,\n onClose,\n filePath,\n initialContent,\n onSave,\n headerExtra,\n headerTools,\n onBeforeClose,\n EditorComponent,\n editorClassName,\n}: BaseMDXEditorModalProps) {\n const editorRef = React.useRef<MDXEditorMethods>(null);\n const [content, setContent] = useState(initialContent);\n const [isEditorReady, setIsEditorReady] = useState(false);\n const [isSaving, setIsSaving] = useState(false);\n\n useEffect(() => {\n setContent(initialContent);\n }, [initialContent]);\n\n const handleClose = () => {\n if (onBeforeClose && !onBeforeClose()) {\n return;\n }\n\n onClose();\n };\n\n useEffect(() => {\n if (isOpen) {\n const timer = setTimeout(() => {\n setIsEditorReady(true);\n }, 0);\n\n return () => clearTimeout(timer);\n }\n\n setIsEditorReady(false);\n return undefined;\n }, [isOpen]);\n\n const handleSave = async () => {\n setIsSaving(true);\n\n try {\n await onSave(content);\n handleClose();\n } catch (error) {\n console.error('Save failed:', error);\n } finally {\n setIsSaving(false);\n }\n };\n\n if (!isOpen) {\n return null;\n }\n\n return (\n <Dialog open={isOpen} onOpenChange={handleClose}>\n <DialogContent className=\"w-[90vw] h-[90vh] flex flex-col\" data-testid=\"mdx-editor-modal\">\n <DialogHeader>\n <div className=\"flex items-center justify-between gap-4\">\n <DialogTitle>{filePath ? `Edit: ${filePath}` : 'New MDX File'}</DialogTitle>\n {(headerExtra || headerTools) && (\n <div className=\"flex items-center gap-2\">\n {headerExtra}\n {headerTools?.({ content, setContent, editorRef })}\n </div>\n )}\n <button\n type=\"button\"\n onClick={handleClose}\n className=\"p-2 rounded text-grey-04 dark:text-grey-07 hover:bg-gray-100 dark:hover:bg-grey-04 hover:text-grey-01 dark:hover:text-grey-12\"\n aria-label=\"Close\"\n >\n ✕\n </button>\n </div>\n </DialogHeader>\n <div className=\"flex-1 overflow-hidden\">\n {isEditorReady ? (\n <MDXEditorErrorBoundary logPrefix=\"[MDXEditor]\">\n <DeferredMDXEditor\n EditorComponent={EditorComponent}\n editorRef={editorRef}\n value={content}\n onChange={setContent}\n onSave={handleSave}\n className={editorClassName}\n />\n </MDXEditorErrorBoundary>\n ) : (\n <div className=\"flex items-center justify-center h-full\">\n <div className=\"text-gray-500 dark:text-grey-07\" data-testid=\"modal-editor-loading\">\n Loading editor...\n </div>\n </div>\n )}\n </div>\n <div className=\"flex justify-end gap-2 mt-4\">\n <button\n type=\"button\"\n onClick={handleClose}\n className=\"px-4 py-2 border border-gray-300 dark:border-grey-04 rounded text-grey-01 dark:text-grey-12 hover:bg-gray-50 dark:hover:bg-grey-04\"\n disabled={isSaving}\n >\n Cancel\n </button>\n <button\n type=\"button\"\n onClick={handleSave}\n className=\"px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed\"\n disabled={isSaving}\n >\n {isSaving ? 'Saving...' : 'Save'}\n </button>\n </div>\n </DialogContent>\n </Dialog>\n );\n}\n","import type React from 'react';\nimport { useEffect, useState } from 'react';\nimport * as devRuntime from 'react/jsx-dev-runtime';\nimport * as runtime from 'react/jsx-runtime';\n\n// Cache for compiled MDX components\nconst compiledCache = new Map<string, React.ComponentType>();\n\n/**\n * Execute pre-compiled MDX code (compiled with outputFormat: 'function-body').\n * This is the same as @mdx-js/mdx's run() — inlined here to avoid importing\n * the full @mdx-js/mdx package (which pulls acorn + remark + unified into the browser).\n *\n * Note: Uses AsyncFunction constructor which requires CSP `unsafe-eval`.\n * This is acceptable since the CMS admin UI runs in a trusted environment.\n */\nconst AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;\nasync function runMDX(code: string, options: Record<string, unknown>): Promise<{ default: React.ComponentType }> {\n return new AsyncFunction(String(code))(options);\n}\n\n/**\n * Create the JSX runtime options for runMDX().\n * Checked once at module load to avoid repeated environment checks.\n */\nfunction createRunOptions() {\n const isDevelopment = process.env.NODE_ENV === 'development';\n return isDevelopment ? { ...devRuntime, development: true } : { ...runtime };\n}\n\nconst runOptions = createRunOptions();\n\n/**\n * Simple hash function for generating cache keys from MDX content.\n */\nfunction hashString(str: string): string {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n const char = str.charCodeAt(i);\n hash = (hash << 5) - hash + char;\n hash = hash & hash;\n }\n return hash.toString(36);\n}\n\nexport interface UseMDXEvaluationOptions {\n compiledCode: string | null;\n cacheKey?: string;\n}\n\nexport interface UseMDXEvaluationResult {\n Component: React.ComponentType | null;\n error: Error | null;\n isLoading: boolean;\n retry: () => void;\n}\n\n/**\n * Hook for evaluating pre-compiled MDX code into React components.\n *\n * Uses the browser-side half of a server-compile + browser-run pattern:\n * 1. The server compiles MDX → JavaScript function body\n * 2. The browser executes the pre-compiled code with run() (zero compiler dependencies)\n *\n * This keeps the full MDX compilation pipeline on the server and only ships\n * a tiny runtime helper to the browser.\n *\n * @param options.compiledCode - The pre-compiled MDX function body. If null, returns null component\n * @param options.cacheKey - Optional cache key. If not provided, uses hash of code\n *\n * @returns Object containing Component, error, isLoading, retry\n */\nexport function useMDXEvaluation({ compiledCode, cacheKey }: UseMDXEvaluationOptions): UseMDXEvaluationResult {\n const [Component, setComponent] = useState<React.ComponentType | null>(null);\n const [error, setError] = useState<Error | null>(null);\n const [isLoading, setIsLoading] = useState(() => {\n if (!compiledCode) return false;\n const key = cacheKey || `mdx-${hashString(compiledCode)}`;\n return !compiledCache.has(key);\n });\n const [retryCount, setRetryCount] = useState(0);\n\n const retry = () => {\n if (compiledCode) {\n const key = cacheKey || `mdx-${hashString(compiledCode)}`;\n compiledCache.delete(key);\n }\n setRetryCount((prev) => prev + 1);\n };\n\n useEffect(() => {\n void retryCount;\n\n if (!compiledCode) {\n setComponent(null);\n setError(null);\n setIsLoading(false);\n return;\n }\n\n const key = cacheKey || `mdx-${hashString(compiledCode)}`;\n const cached = compiledCache.get(key);\n if (cached) {\n setComponent(() => cached);\n setError(null);\n setIsLoading(false);\n return;\n }\n\n let cancelled = false;\n\n const compileAndRun = async () => {\n try {\n setError(null);\n setIsLoading(true);\n\n const { default: MDXComponent } = await runMDX(compiledCode, runOptions);\n\n if (cancelled) return;\n\n compiledCache.set(key, MDXComponent);\n setComponent(() => MDXComponent);\n } catch (err) {\n if (cancelled) return;\n const evaluationError = err instanceof Error ? err : new Error('MDX evaluation failed');\n setError(evaluationError);\n setComponent(null);\n } finally {\n if (!cancelled) {\n setIsLoading(false);\n }\n }\n };\n\n compileAndRun();\n\n return () => {\n cancelled = true;\n };\n }, [compiledCode, cacheKey, retryCount]);\n\n return { Component, error, isLoading, retry };\n}\n","import type { MDXEditorMethods } from '@mdxeditor/editor';\nimport React from 'react';\nimport {\n BaseMDXEditor,\n BaseMDXEditorModal,\n type BaseMDXEditorModalProps,\n type BaseMDXEditorProps,\n} from './editor-core.js';\n\nexport interface MDXEditorProps\n extends Omit<\n BaseMDXEditorProps,\n 'disableImageSettingsButton' | 'imageButtonRef' | 'imageDialog' | 'onImageShortcut'\n > {}\n\nexport const MDXEditor = React.forwardRef<MDXEditorMethods, MDXEditorProps>((props, ref) => {\n return <BaseMDXEditor ref={ref} {...props} />;\n});\n\nMDXEditor.displayName = 'MDXEditor';\n\nexport interface MDXEditorModalProps extends Omit<BaseMDXEditorModalProps, 'EditorComponent'> {}\n\nexport function MDXEditorModal(props: MDXEditorModalProps) {\n return <BaseMDXEditorModal {...props} EditorComponent={MDXEditor} />;\n}\n"],"mappings":";;;;;;;;AA0EA,MAAM,qBAAqB;CACzB,MAAM;CACN,IAAI;CACJ,KAAK;CACL,IAAI;CACJ,KAAK;CACL,KAAK;CACL,MAAM;CACN,MAAM;CACN,IAAI;CACJ,KAAK;CACL,MAAM;CACN,QAAQ;CACT;AAED,SAAS,wBAAwB,gBAA+C;AAC9E,KAAI,CAAC,eACH,QAAO,oBAAC,gBAAc;AAGxB,QAAO,MAAM,cAAc,aAA2E,EACpG,KAAK,gBACN,CAAC;;AAGJ,IAAM,yBAAN,cAAqC,MAAM,UAGzC;CACA,YAAY,OAAyD;AACnE,QAAM,MAAM;AACZ,OAAK,QAAQ,EAAE,UAAU,OAAO;;CAGlC,OAAO,yBAAyB,OAAc;AAC5C,SAAO;GAAE,UAAU;GAAM;GAAO;;CAGlC,AAAS,kBAAkB,OAAc,WAA4B;AACnE,UAAQ,MAAM,GAAG,KAAK,MAAM,UAAU,0BAA0B,OAAO,UAAU;;CAGnF,AAAS,SAAS;AAChB,MAAI,KAAK,MAAM,SACb,QACE,qBAAC;GAAI,WAAU;;IACb,oBAAC;KAAE,WAAU;eAAqB;MAAmB;IACrD,oBAAC;KAAE,WAAU;eAAgB,KAAK,MAAM,OAAO,WAAW;MAA6B;IACvF,qBAAC;KAAQ,WAAU;gBACjB,oBAAC;MAAQ,WAAU;gBAA6B;OAAq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MAAI,QAAQ;AACV,sBAAmB,OAAO;AAC1B,YAAS,KAAK;AACd,gBAAa,MAAM;AACnB;;EAGF,IAAI,YAAY;EAEhB,MAAM,gBAAgB,YAAY;AAChC,OAAI;AACF,aAAS,KAAK;AACd,iBAAa,KAAK;IAElB,MAAM,EAAE,SAAS,iBAAiB,MAAM,OAAO,cAAc,WAAW;AAExE,QAAI,UAAW;AAEf,kBAAc,IAAI,KAAK,aAAa;AACpC,uBAAmB,aAAa;YACzB,KAAK;AACZ,QAAI,UAAW;AAEf,aADwB,eAAe,QAAQ,sBAAM,IAAI,MAAM,wBAAwB,CAC9D;AACzB,iBAAa,KAAK;aACV;AACR,QAAI,CAAC,UACH,cAAa,MAAM;;;AAKzB,iBAAe;AAEf,eAAa;AACX,eAAY;;IAEb;EAAC;EAAc;EAAU;EAAW,CAAC;AAExC,QAAO;EAAE;EAAW;EAAO;EAAW;EAAO;;;;;AC9H/C,MAAa,YAAY,MAAM,YAA8C,OAAO,QAAQ;AAC1F,QAAO,oBAAC;EAAmB;EAAK,GAAI;GAAS;EAC7C;AAEF,UAAU,cAAc;AAIxB,SAAgB,eAAe,OAA4B;AACzD,QAAO,oBAAC;EAAmB,GAAI;EAAO,iBAAiB;GAAa"}
|
package/dist/node.d.mts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { ComponentType } from "react";
|
|
2
|
-
import { MDXCompileResponse as MDXCompileResult } from "@conloca/content-api";
|
|
3
|
-
|
|
4
|
-
//#region src/types.d.ts
|
|
5
|
-
interface EvaluatedMDXBlock {
|
|
6
|
-
ok: true;
|
|
7
|
-
id: string;
|
|
8
|
-
title: string;
|
|
9
|
-
Component: ComponentType;
|
|
10
|
-
}
|
|
11
|
-
interface FailedMDXBlockEvaluation {
|
|
12
|
-
ok: false;
|
|
13
|
-
id: string;
|
|
14
|
-
title: string;
|
|
15
|
-
error: Error;
|
|
16
|
-
}
|
|
17
|
-
type MDXBlockEvaluationResult = EvaluatedMDXBlock | FailedMDXBlockEvaluation;
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/blocks.d.ts
|
|
20
|
-
interface BlockLocaleSummary {
|
|
21
|
-
meta?: {
|
|
22
|
-
title?: string;
|
|
23
|
-
};
|
|
24
|
-
name?: string;
|
|
25
|
-
}
|
|
26
|
-
interface BlockManifest {
|
|
27
|
-
id: string;
|
|
28
|
-
locales: Record<string, BlockLocaleSummary | undefined>;
|
|
29
|
-
}
|
|
30
|
-
interface BlockLocalizedEntry {
|
|
31
|
-
localized?: {
|
|
32
|
-
meta?: {
|
|
33
|
-
title?: string;
|
|
34
|
-
};
|
|
35
|
-
name?: string;
|
|
36
|
-
content?: {
|
|
37
|
-
mdx?: string;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
interface BlockAPI {
|
|
42
|
-
listAllContent(filters: {
|
|
43
|
-
kind: 'block';
|
|
44
|
-
}): Iterable<BlockManifest>;
|
|
45
|
-
getLocalized(id: string, locale: string): Promise<BlockLocalizedEntry | null>;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Evaluate all MDX blocks from a compatible content API.
|
|
49
|
-
*
|
|
50
|
-
* Returns structured success/error results so callers can decide how to
|
|
51
|
-
* surface broken blocks instead of hardcoding fallback UI in this package.
|
|
52
|
-
*/
|
|
53
|
-
declare function evaluateMDXBlocks(api: BlockAPI, locale: string): Promise<MDXBlockEvaluationResult[]>;
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region src/mdx/compile.d.ts
|
|
56
|
-
/**
|
|
57
|
-
* Compile MDX content to executable JavaScript.
|
|
58
|
-
* Delegates to the shared compiler in @conloca/content-api.
|
|
59
|
-
*/
|
|
60
|
-
declare function compileMDX(content: string): Promise<MDXCompileResult>;
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/mdx/evaluate.d.ts
|
|
63
|
-
/**
|
|
64
|
-
* Evaluate MDX content string to a React component.
|
|
65
|
-
*
|
|
66
|
-
* This is a framework-agnostic utility for converting MDX strings into
|
|
67
|
-
* executable React components. Works in any Node.js environment (Astro,
|
|
68
|
-
* Next.js, Remix, etc.) at build time or server-side.
|
|
69
|
-
*
|
|
70
|
-
* **When to use:**
|
|
71
|
-
* - Building static sites with MDX content
|
|
72
|
-
* - Server-side rendering MDX as React components
|
|
73
|
-
* - Need React components (not HTML strings)
|
|
74
|
-
*
|
|
75
|
-
* @param mdxContent - The MDX string to evaluate
|
|
76
|
-
* @param options - Optional configuration
|
|
77
|
-
* @param options.development - Whether to use development mode (default: false)
|
|
78
|
-
* @returns Object containing Component (or null) and optional error
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```typescript
|
|
82
|
-
* import { evaluateMDXToComponent } from '@conloca/mdx/node';
|
|
83
|
-
*
|
|
84
|
-
* const { Component, error } = await evaluateMDXToComponent('# Hello\n\nThis is **MDX**');
|
|
85
|
-
* if (error) {
|
|
86
|
-
* console.error('Failed to evaluate:', error);
|
|
87
|
-
* } else if (Component) {
|
|
88
|
-
* // Render <Component /> in your React app
|
|
89
|
-
* }
|
|
90
|
-
* ```
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```typescript
|
|
94
|
-
* // In Astro pages
|
|
95
|
-
* const { Component } = await evaluateMDXToComponent(mdxContent);
|
|
96
|
-
* // Then render in JSX: <Component />
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
declare function evaluateMDXToComponent(mdxContent: string, options?: {
|
|
100
|
-
development?: boolean;
|
|
101
|
-
}): Promise<{
|
|
102
|
-
Component: ComponentType | null;
|
|
103
|
-
error?: Error;
|
|
104
|
-
}>;
|
|
105
|
-
//#endregion
|
|
106
|
-
export { type EvaluatedMDXBlock, type FailedMDXBlockEvaluation, type MDXBlockEvaluationResult, type MDXCompileResult, compileMDX, evaluateMDXBlocks, evaluateMDXToComponent };
|
|
107
|
-
//# sourceMappingURL=node.d.mts.map
|